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,35 @@
|
||||
type Params = {
|
||||
text: string;
|
||||
/**
|
||||
* What separates a name from its value: `:` for headers, `=` for envs.
|
||||
*/
|
||||
separator: ":" | "=";
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads one `Name: value` (or `NAME=value`) per line into a map, for the
|
||||
* header and env fields of an MCP server or tool. Blank lines and lines
|
||||
* without the separator are skipped; the value is everything after the
|
||||
* first one, trimmed.
|
||||
*/
|
||||
export default function parseTemplateLines({ text, separator }: Params): Record<string, string> {
|
||||
const map: Record<string, string> = {};
|
||||
|
||||
for (const line of text.split("\n")) {
|
||||
const at = line.indexOf(separator);
|
||||
const name = at > 0 ? line.slice(0, at).trim() : "";
|
||||
|
||||
if (name) map[name] = line.slice(at + 1).trim();
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* The other way: a map as one `Name: value` (or `NAME=value`) per line.
|
||||
*/
|
||||
export function templateLines({ map, separator }: { map?: Record<string, string>; separator: ":" | "=" }) {
|
||||
return Object.entries(map || {})
|
||||
.map(([name, value]) => `${name}${separator == ":" ? ": " : "="}${value}`)
|
||||
.join("\n");
|
||||
}
|
||||
Reference in New Issue
Block a user