import { memo } from "react" import { MessageCircle } from "lucide-react" import { Markdown } from "./Markdown" import type { ReactNode } from "react" import type { ToolExecutionChunk } from "@/lib/agents/types" interface ReplyCardProps { chunk: ToolExecutionChunk } function headerLabel( isLinear: boolean, status: ToolExecutionChunk["status"] ): string { const pending = status === "in_progress" || status === "pending" if (isLinear) return pending ? "Commenting on Linear…" : "Commented on Linear" return pending ? "Replying in Slack…" : "Replied in Slack" } const SLACK_TOKEN = /<([^>]+)>/g const LINK_CLASS = "text-[color:var(--ui-accent)] underline decoration-[color:var(--ui-accent)]/50 break-words [overflow-wrap:anywhere]" // Slack mrkdwn isn't standard Markdown — rewrite its link/mention syntax for display // rather than feeding it to the Markdown renderer (which mis-renders *bold* etc.). function renderSlackBody(text: string): Array { const nodes: Array = [] let lastIndex = 0 let key = 0 SLACK_TOKEN.lastIndex = 0 for ( let match = SLACK_TOKEN.exec(text); match; match = SLACK_TOKEN.exec(text) ) { if (match.index > lastIndex) nodes.push(text.slice(lastIndex, match.index)) const token = match[1] ?? "" const sep = token.indexOf("|") const target = sep === -1 ? token : token.slice(0, sep) const label = sep === -1 ? "" : token.slice(sep + 1) if (target.startsWith("@") || target.startsWith("#")) { const sigil = target[0] nodes.push( {sigil} {label || target.slice(1)} ) } else if (target.startsWith("!")) { nodes.push( @{label || target.slice(1)} ) } else { nodes.push( {label || target} ) } lastIndex = match.index + match[0].length } if (lastIndex < text.length) nodes.push(text.slice(lastIndex)) return nodes } export const ReplyCard = memo(function ReplyCard({ chunk }: ReplyCardProps) { const isLinear = chunk.toolKind === "linear" const body = ((isLinear ? chunk.input?.comment_body : chunk.input?.message) as string) || "" return (
{headerLabel(isLinear, chunk.status)}
{body && (
{isLinear ? ( ) : (
{renderSlackBody(body)}
)}
)}
) })