Bots get list_hooks, pause_hook and delete_hook, which act directly since they only take away. A new hook, or a new name, brief or filter, or switching a paused one back on, goes through propose_hook: it stores a hook_proposals row and puts a [hook-proposal:ID] card in the reply, which the user it was proposed to confirms or rejects. The card is read from what Confirm saves, with the bot's reason labelled as its own; confirming checks everything again and saves through the Hooks modal's helpers. A new hook's URL is shown on the card once, to the user only, never in the outcome the bot is told. What calls a hook, its computers and its signing are never proposed. Only chat replies propose, and a hook call's own run gets no hook tools, so a caller's payload can't reach them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
98 lines
3.9 KiB
TypeScript
98 lines
3.9 KiB
TypeScript
/**
|
|
* The link target a computer ref (`computerRef`) becomes, e.g.
|
|
* `#computer-3`. The chat's markdown renders these links as buttons that
|
|
* switch the bot to that computer.
|
|
*/
|
|
export const ComputerRefHrefPrefix = "#computer-";
|
|
|
|
/**
|
|
* The link target a take-over ref (`takeOverRef`) becomes, e.g.
|
|
* `#take-over-3-browser`. The chat renders these as buttons that open the
|
|
* computer in that mode.
|
|
*/
|
|
export const TakeOverRefHrefPrefix = "#take-over-";
|
|
|
|
/**
|
|
* The link target a bot ref (`botRef`) becomes, e.g. `#bot-3`. The chat
|
|
* renders these as links to that bot's conversation.
|
|
*/
|
|
export const BotRefHrefPrefix = "#bot-";
|
|
|
|
/**
|
|
* The link target a workspace ref (`workspaceRef`) becomes, e.g.
|
|
* `#workspace-2`. The chat renders these as links to that workspace.
|
|
*/
|
|
export const WorkspaceRefHrefPrefix = "#workspace-";
|
|
|
|
/**
|
|
* The link target a file ref (`fileRef`) becomes, e.g. `#file-12`. The
|
|
* chat renders these as a chip that opens the file.
|
|
*/
|
|
export const FileRefHrefPrefix = "#file-";
|
|
|
|
/**
|
|
* The link target a folder ref (`folderRef`) becomes, e.g.
|
|
* `#folder-computer%3A3%3Aseo%2Fraw`. The chat renders it as a chip that
|
|
* opens that folder in the files browser.
|
|
*/
|
|
export const FolderRefHrefPrefix = "#folder-";
|
|
|
|
/**
|
|
* The link target a proposal ref (`proposalRef`) becomes, e.g.
|
|
* `#proposal-7`. The chat renders it as a chip that opens the card where
|
|
* the super admin confirms or rejects the MCP server or tool.
|
|
*/
|
|
export const ProposalRefHrefPrefix = "#proposal-";
|
|
|
|
/**
|
|
* The link target a hook proposal ref (`hookProposalRef`) becomes, e.g.
|
|
* `#hook-proposal-4`. The chat renders it as a chip that opens the card
|
|
* where the user confirms or rejects the hook.
|
|
*/
|
|
export const HookProposalRefHrefPrefix = "#hook-proposal-";
|
|
|
|
/**
|
|
* Turns every computer ref (`[computer:3]`) and take-over ref
|
|
* (`[take-over:3:browser]`), bot ref (`[bot:3]`), workspace ref
|
|
* (`[workspace:2]`), file ref (`[file:12]`), folder ref
|
|
* (`[folder:computer:3:seo/raw]`), proposal ref (`[proposal:7]`) and hook
|
|
* proposal ref (`[hook-proposal:4]`) in a message into a markdown link, so it
|
|
* survives markdown rendering as a link the chat can swap for a button,
|
|
* chip or download.
|
|
*
|
|
* A file ref and a folder ref are different things and are never guessed
|
|
* from a name: `[file:12]` is a saved file (its chip downloads it),
|
|
* `[folder:...]` a folder (its chip opens the files browser there).
|
|
*/
|
|
export default function linkComputerRefs({ text }: { text: string }) {
|
|
return text
|
|
.replace(
|
|
/\[computer:(\d+)\](?!\()/g,
|
|
(_, id: string) => `[computer ${id}](${ComputerRefHrefPrefix}${id})`,
|
|
)
|
|
.replace(
|
|
/\[take-over:(\d+):([a-z]+)\](?!\()/g,
|
|
(_, id: string, mode: string) => `[take over](${TakeOverRefHrefPrefix}${id}-${mode})`,
|
|
)
|
|
.replace(/\[bot:(\d+)\](?!\()/g, (_, id: string) => `[bot ${id}](${BotRefHrefPrefix}${id})`)
|
|
.replace(
|
|
/\[workspace:(\d+)\](?!\()/g,
|
|
(_, id: string) => `[workspace ${id}](${WorkspaceRefHrefPrefix}${id})`,
|
|
)
|
|
.replace(
|
|
/\[proposal:(\d+)\](?!\()/g,
|
|
(_, id: string) => `[proposal ${id}](${ProposalRefHrefPrefix}${id})`,
|
|
)
|
|
.replace(
|
|
/\[hook-proposal:(\d+)\](?!\()/g,
|
|
(_, id: string) => `[hook proposal ${id}](${HookProposalRefHrefPrefix}${id})`,
|
|
)
|
|
.replace(/\[file:(\d+)\](?!\()/g, (_, id: string) => `[file ${id}](${FileRefHrefPrefix}${id})`)
|
|
.replace(/\[folder:([a-z]+):(\d+):([^\]\n]+)\](?!\()/g, (_, volume: string, owner: string, path: string) =>
|
|
`[${path}](${FolderRefHrefPrefix}${encodeURIComponent(`${volume}:${owner}:${path}`)})`,
|
|
)
|
|
.replace(/\[folder:([a-z]+):(\d+)\](?!\()/g, (_, volume: string, owner: string) =>
|
|
`[${volume} ${owner}](${FolderRefHrefPrefix}${encodeURIComponent(`${volume}:${owner}`)})`,
|
|
);
|
|
}
|