Files
cobble/src/functions/backend/db/bots/grab-message-ref-names.ts
T
tbenandClaude Opus 5.5 1208eac6b7 Replace the composer textarea with a Tiptap markdown editor
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]>
2026-10-20 05:48:23 +01:00

34 lines
1.1 KiB
TypeScript

import type { MessageRefNames } from "@/src/utils/describe-message-refs";
import messageRefIds from "@/src/utils/message-ref-ids";
import grabUserWorkspace from "../workspaces/grab-user-workspace";
import grabUserBot from "./grab-user-bot";
type Params = {
texts: string[];
user_id: number | string;
};
/**
* The names of the bots and workspaces some messages mention, only those
* the user reaches (`grabUserBot`, `grabUserWorkspace`), so a ref to
* anything else stays unnamed.
*/
export default async function grabMessageRefNames({ texts, user_id }: Params): Promise<MessageRefNames> {
const { bot_ids, workspace_ids } = messageRefIds({ texts });
const names: MessageRefNames = { bots: new Map(), workspaces: new Map() };
for (const id of bot_ids) {
const bot = await grabUserBot({ bot_id: id, user_id });
if (bot?.name) names.bots.set(id, { name: bot.name, role: bot.role });
}
for (const id of workspace_ids) {
const workspace = await grabUserWorkspace({ workspace_id: id, user_id });
if (workspace?.name) names.workspaces.set(id, { name: workspace.name });
}
return names;
}