Add MCP servers and custom tools for bots
Two new settings pages, MCPs and Tools. Super admins define them; super
admins and admins attach them to bots, to workspaces (every bot there),
or to every bot. Bots get them in chat replies and tasks.
- Custom tools: a JSON-schema of arguments plus an HTTP request, a script
on the bot's computer, or a prompt, templated with {{args.x}} and
{{env.KEY}}, secrets redacted from results.
- MCP servers: remote (URL and headers) or stdio commands run on the host
with a setup command and an isolated env, in a per-process pool. Tools
are listed into a cache and connect on first call.
- Add, edit, access and try open in modals.
- Markdown, JSON and command fields use twui's AceEditor (CodeEditor),
its scripts loaded on demand.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import fillTemplate from "./fill-template";
|
||||
|
||||
describe("fillTemplate", () => {
|
||||
test("fills args and envs", () => {
|
||||
expect(
|
||||
fillTemplate({
|
||||
template: "https://api.test/{{args.city}}?key={{ env.API_KEY }}",
|
||||
args: { city: "Lagos" },
|
||||
envs: [{ key: "API_KEY", value: "abc" }],
|
||||
}),
|
||||
).toBe("https://api.test/Lagos?key=abc");
|
||||
});
|
||||
|
||||
test("objects become JSON, missing args empty, dotted paths reach in", () => {
|
||||
expect(
|
||||
fillTemplate({
|
||||
template: "{{args.filter}}|{{args.missing}}|{{args.filter.tag}}",
|
||||
args: { filter: { tag: "x" } },
|
||||
}),
|
||||
).toBe('{"tag":"x"}||x');
|
||||
});
|
||||
|
||||
test("encodes filled arguments only", () => {
|
||||
expect(
|
||||
fillTemplate({
|
||||
template: "{{env.BASE}}/q?s={{args.q}}&x=a b",
|
||||
args: { q: "a b&c" },
|
||||
envs: [{ key: "BASE", value: "https://x.test/v1" }],
|
||||
encode: encodeURIComponent,
|
||||
}),
|
||||
).toBe("https://x.test/v1/q?s=a%20b%26c&x=a b");
|
||||
});
|
||||
|
||||
test("an unset env throws, naming it", () => {
|
||||
expect(() => fillTemplate({ template: "{{env.NOPE}}" })).toThrow("NOPE");
|
||||
});
|
||||
|
||||
test("leaves other braces alone", () => {
|
||||
expect(fillTemplate({ template: '{"a": "{{other}}"}' })).toBe('{"a": "{{other}}"}');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user