77917203fd
server/lib/ai-tools.js loads server/data/ai-tools/*.json (38 tools, data from Orca, MIT) plus DASHBOARD_AI_TOOLS_DIR, detects each CLI by walking PATH, and keeps enable/default in <data dir>/ai-tools.json. shell-path.js merges the login shell's PATH at startup and on Refresh. /api/ai-tools lists, refreshes and toggles; /api/run/binary resolves through the catalog. Lanes accept any catalog id (EDISABLED for a disabled one on creation, ENOTOOL at start once a tool left the catalog). pty-run keeps the Claude/Codex builders and builds every other tool's argv from its catalog file, pasting an after-start prompt through a tmux buffer; every pane gets the hydrated PATH. A per-run bypass switch appends the catalog's bypass args (Codex included). POST /api/run now forwards sandbox/approval/resumeLast, which it dropped. agenthub lanes add gains --tool.
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
/**
|
|
* @file HTTP surface for the AI Tools catalog (server/lib/ai-tools.js): list
|
|
* what is known and installed, re-detect after hydrating PATH from the login
|
|
* shell, and enable/disable a tool or make it the default. Nothing here takes
|
|
* a command or an argument from the request — the catalog files are the only
|
|
* source of what a lane may run. Writes sit behind the same-origin guard.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
const express = require("express");
|
|
|
|
const aiTools = require("../lib/ai-tools");
|
|
const { hydrateShellPath } = require("../lib/shell-path");
|
|
const { sameOriginGuard } = require("../lib/same-origin");
|
|
|
|
const router = express.Router();
|
|
|
|
router.get("/", (_req, res) => {
|
|
res.json(aiTools.view());
|
|
});
|
|
|
|
router.post("/refresh", sameOriginGuard, async (_req, res) => {
|
|
await hydrateShellPath();
|
|
aiTools.refresh();
|
|
res.json(aiTools.view());
|
|
});
|
|
|
|
router.put("/:id", sameOriginGuard, (req, res) => {
|
|
const { enabled, default: makeDefault } = req.body || {};
|
|
try {
|
|
if (enabled !== undefined) {
|
|
if (typeof enabled !== "boolean") {
|
|
return res
|
|
.status(400)
|
|
.json({ error: { code: "EBADFIELD", message: "enabled must be a boolean" } });
|
|
}
|
|
aiTools.setEnabled(req.params.id, enabled);
|
|
}
|
|
if (makeDefault === true) aiTools.setDefault(req.params.id);
|
|
else if (enabled === undefined && !aiTools.has(req.params.id)) {
|
|
return res.status(404).json({ error: { code: "ENOTOOL", message: "unknown AI tool" } });
|
|
}
|
|
res.json(aiTools.view());
|
|
} catch (e) {
|
|
const status = e.code === "ENOTOOL" ? 404 : e.code === "EBADDEFAULT" ? 400 : 500;
|
|
res.status(status).json({ error: { code: e.code || "EINTERNAL", message: e.message } });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|