Files
cobble/src/utils/describe-proposal-details.ts
T
tbenandClaude Opus 5.5 fefc295d15 Let the coordinator manage skills, MCP servers and tools, behind a confirm card
- Coordinator tools in its own chat (super admin only): list_extensions,
  set_extension_access, delete_extension, and update_skill /
  update_mcp_server / update_custom_tool for what can't change where
  anything is sent (on/off, names, arguments, left-out tools)
- Adding a skill, MCP server or tool, or changing a skill's words, a
  server's URL or headers or a tool's kind or config, goes through
  propose_skill / propose_mcp_server / propose_custom_tool: stored in
  extension_proposals with the bot's background check, shown as a
  [proposal:ID] chip that opens a card with Confirm and Reject
- The card's facts are worked out by the app from what Confirm saves: the
  host, every {{env.KEY}} and whether it's saved, the config; for a skill
  its links, hosts, tool names, mentions of secrets and a diff against
  the saved runbook
- Confirming decides once and checks again; a server or tool missing a key
  is saved switched off, and the outcome is posted to the bot in chat
- Never from a bot: stdio servers, a URL whose host a template decides,
  envs in a prompt tool, a key's value

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 06:08:09 +01:00

89 lines
3.0 KiB
TypeScript

import type { SaveCustomToolRequest, SaveMcpServerRequest } from "@/src/schemas/extension-schema";
import type { ExtensionProposalDetail } from "@/src/types";
type Params = (
| { kind: "mcp"; data: SaveMcpServerRequest }
| { kind: "tool"; data: SaveCustomToolRequest }
) & {
/**
* A new one rather than a change: no bot gets it until it's given.
*/
is_new: boolean;
};
/**
* What a proposed MCP server or tool would do, line by line, read from the
* config the confirm button saves, so the card shows exactly what would
* be saved rather than the bot's account of it.
*/
export default function describeProposalDetails(params: Params): ExtensionProposalDetail[] {
const { data } = params;
const common: ExtensionProposalDetail[] = [
{ label: "Name", value: data.name },
{ label: "Description", value: data.description || "none" },
];
const reach: ExtensionProposalDetail[] = [
{ label: "Starts", value: data.enabled ? "On" : "Off" },
{
label: "Who gets it",
value: data.all_bots ? "Every bot, now and new" : params.is_new ? "No bot until it's given to some" : "As it is now",
},
];
if (params.kind == "mcp") {
return [
...common,
{ label: "URL", value: params.data.url },
{ label: "Headers", value: listMap({ map: params.data.headers }), block: true },
{ label: "Left-out tools", value: params.data.excluded_tools.join(", ") || "none" },
...reach,
];
}
const tool = params.data;
const parameters: ExtensionProposalDetail = {
label: "Arguments",
value: JSON.stringify(tool.parameters, null, 2),
block: true,
};
if (tool.kind == "http") {
return [
...common,
{ label: "Kind", value: "HTTP request, sent by the app" },
{ label: "Request", value: `${tool.config.method} ${tool.config.url}` },
{ label: "Headers", value: listMap({ map: tool.config.headers }), block: true },
{ label: "Body", value: tool.config.body || "none: the arguments go as JSON", block: Boolean(tool.config.body) },
parameters,
...reach,
];
}
if (tool.kind == "script") {
return [
...common,
{
label: "Kind",
value: `${tool.config.language} script, run on the bot's computer, where it reads every env shared with computers`,
},
{ label: "Code", value: tool.config.code, block: true },
parameters,
...reach,
];
}
return [
...common,
{ label: "Kind", value: "Prompt, one turn with the bot's models" },
{ label: "Prompt", value: tool.config.prompt, block: true },
parameters,
...reach,
];
}
function listMap({ map }: { map: Record<string, string> }) {
const entries = Object.entries(map);
return entries.length ? entries.map(([key, value]) => `${key}: ${value}`).join("\n") : "none";
}