The composer now writes markdown with bold, italic, strike, code, links, quotes and lists, from shortcuts, markdown typing or a bubble over the selection. @ mentions a bot and # a workspace, shown as chips and saved as [bot:ID] / [workspace:ID]. Text selected in a message can be quoted into the composer. User messages render as markdown, and replies tell the bot who and what the user mentioned. Adds an ESM stand-in for use-sync-external-store, since bunext keeps React external in page bundles and the CommonJS original requires it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import messageRefIds from "./message-ref-ids";
|
|
|
|
/**
|
|
* What a ref stands for: a bot's name and role, or a workspace's name.
|
|
*/
|
|
export type MessageRefNames = {
|
|
bots: Map<number, { name: string; role?: string | null }>;
|
|
workspaces: Map<number, { name: string }>;
|
|
};
|
|
|
|
/**
|
|
* A line telling the bot who and what a user message mentions, e.g.
|
|
* `[Mentions: [bot:3] is Ada (Researcher); [workspace:2] is the workspace "Launch"]`.
|
|
* Refs missing from `names` (the user can't reach them) are left out;
|
|
* nothing is returned when none are known.
|
|
*/
|
|
export default function describeMessageRefs({ text, names }: { text: string; names: MessageRefNames }) {
|
|
const { bot_ids, workspace_ids } = messageRefIds({ texts: [text] });
|
|
const parts: string[] = [];
|
|
|
|
for (const id of bot_ids) {
|
|
const bot = names.bots.get(id);
|
|
|
|
if (bot) parts.push(`[bot:${id}] is ${bot.name}${bot.role ? ` (${bot.role})` : ""}`);
|
|
}
|
|
|
|
for (const id of workspace_ids) {
|
|
const workspace = names.workspaces.get(id);
|
|
|
|
if (workspace) parts.push(`[workspace:${id}] is the workspace "${workspace.name}"`);
|
|
}
|
|
|
|
return parts.length ? `[Mentions: ${parts.join("; ")}]` : "";
|
|
}
|