import { useId, useState, useSyncExternalStore } from "react"; import { ChevronIcon, DecisionIcon } from "@chopin/icons"; import { MotionDisclosure, MotionDisclosureIcon } from "@chopin/editor"; import { duration, summarize, toolCopy, waitingCards, waitingPrompts, waitingText, workPhase, } from "./model"; import { motionContract } from "../motion-contract"; import { motionImmediately } from "../motion-input"; import { cardStatus } from "@chopin/dialect"; import type { Questionnaire } from "@chopin/dialect"; import type { Chat } from "@chopin/protocol"; import type { TranscriptDecisions } from "./transcript"; import type { QuestionnaireStore } from "@chopin/editor"; const NO_QUESTIONS: ReturnType = []; const noQuestions = () => () => {}; const emptyQuestions = () => NO_QUESTIONS; function isOpen(value: Questionnaire): boolean { try { let status = cardStatus(value); return status === "open" || status === "reopened"; } catch { return false; } } function ToolCall( { active, disconnected, tool }: { active: boolean; disconnected: boolean; tool: Chat.Activity }, ) { let [open, setOpen] = useState(false); let contentId = useId(); let hasDetails = tool.args !== undefined || tool.result !== undefined; let status = tool.status === "running" ? disconnected ? "Last seen running" : active ? "Running" : "Interrupted" : tool.status === "failed" ? "Failed" : "Done"; let row = ( <> {hasDetails && (