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]>
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
const AceScripts = [
|
|
"https://cdnjs.cloudflare.com/ajax/libs/ace/1.22.0/ace.min.js",
|
|
"https://cdnjs.cloudflare.com/ajax/libs/ace/1.22.0/ext-language_tools.min.js",
|
|
];
|
|
|
|
let loading: Promise<void> | undefined;
|
|
|
|
/**
|
|
* Loads the ACE editor's scripts once per page, in order (the language
|
|
* tools need ACE itself), so only pages with an editor download them.
|
|
* twui's `AceEditor` waits for `window.ace` on its own.
|
|
*/
|
|
export default function loadAceScripts() {
|
|
if (typeof window == "undefined") return Promise.resolve();
|
|
|
|
loading ||= AceScripts.reduce(
|
|
(previous, src) =>
|
|
previous.then(
|
|
() =>
|
|
new Promise<void>((resolve, reject) => {
|
|
if (document.querySelector(`script[src="${src}"]`)) return resolve();
|
|
|
|
const script = document.createElement("script");
|
|
script.src = src;
|
|
script.onload = () => resolve();
|
|
script.onerror = () => reject(new Error(`Couldn't load ${src}`));
|
|
document.head.appendChild(script);
|
|
}),
|
|
),
|
|
Promise.resolve(),
|
|
).catch((error) => {
|
|
loading = undefined;
|
|
throw error;
|
|
});
|
|
|
|
return loading;
|
|
}
|