import type { ComponentProps } from "react"; import Link from "@moduletrace/twui/layout/Link"; import { ComputerViewModes, type ComputerViewMode } from "@/src/dict/computer-dict"; import { BotRefHrefPrefix, ComputerRefHrefPrefix, TakeOverRefHrefPrefix, WorkspaceRefHrefPrefix, } from "@/src/utils/link-computer-refs"; import BotRefChip from "./bot-ref-chip"; import ComputerRefChip from "./computer-ref-chip"; import TakeOverChip from "./take-over-chip"; import WorkspaceRefChip from "./workspace-ref-chip"; /** * A link in a bot message. A computer the bot named (`linkComputerRefs`) * becomes its switch button, a take-over request a button that opens the * computer, a bot it named a link to that bot's conversation, a workspace * a link to that workspace; anything else opens in a new tab. */ export default function MarkdownLink({ href, children }: ComponentProps<"a">) { if (href?.startsWith(ComputerRefHrefPrefix)) { const computer_id = Number(href.slice(ComputerRefHrefPrefix.length)); if (computer_id) return ; } if (href?.startsWith(TakeOverRefHrefPrefix)) { const [id, mode] = href.slice(TakeOverRefHrefPrefix.length).split("-"); const computer_id = Number(id); const known = ComputerViewModes.some((m) => m.value == mode); if (computer_id) { return ( ); } } if (href?.startsWith(BotRefHrefPrefix)) { const bot_id = Number(href.slice(BotRefHrefPrefix.length)); if (bot_id) return ; } if (href?.startsWith(WorkspaceRefHrefPrefix)) { const workspace_id = Number(href.slice(WorkspaceRefHrefPrefix.length)); if (workspace_id) return ; } return ( {children} ); }