import "./components/ui/tidal.css"; import { useLayoutEffect, useRef, useState } from "react"; import { TidalToolCallCard, type TidalToolCallStatus, type TidalToolCallAction } from "./components/ui/tool-call-card"; import "./components/ui/tool-call-card.css"; import "./components/ui/status-badge.css"; import "./components/ui/collapsible-panel.css"; import "./components/ui/code-block.css"; const tidalExampleStyles = ".tidal-scope .tool-call-demo {\n width: min(100%, 640px);\n min-width: 0;\n}\n.tidal-scope .tool-call-demo-state {\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 10px;\n margin-bottom: 14px;\n color: var(--t-muted);\n font-size: 12px;\n}\n.tidal-scope .tool-call-demo-state select {\n max-width: 100%;\n min-height: 44px;\n padding: 8px 34px 8px 12px;\n border: 1px solid var(--t-border);\n border-radius: var(--t-radius-control);\n color: var(--t-ink);\n background: var(--t-surface);\n font-size: 16px;\n}"; const argumentsText = JSON.stringify( { query: "Install TidalUI in a React app", limit: 3 }, null, 2, ); const resultText = JSON.stringify( { matches: [{ title: "Installation", path: "/docs" }] }, null, 2, ); export function ToolCallCardDemo() { const [status, setStatus] = useState("needs-approval"); const [open, setOpen] = useState(true); const card = useRef(null); const firstAction = useRef(null); const restoreActionFocus = useRef<"action" | "result" | null>(null); function changeFromAction(next: TidalToolCallStatus) { restoreActionFocus.current = next === "succeeded" ? "result" : "action"; if (next === "succeeded") setOpen(true); setStatus(next); } useLayoutEffect(() => { if (!restoreActionFocus.current) return; const requested = restoreActionFocus.current; restoreActionFocus.current = null; if (document.activeElement !== document.body) return; const target = requested === "result" ? card.current : firstAction.current; target?.focus({ preventScroll: true }); }, [status]); const actions: TidalToolCallAction[] = status === "needs-approval" ? [ { actionId: "approve", label: "Approve", emphasis: "primary", onAction: () => changeFromAction("running"), }, { actionId: "decline", label: "Decline", onAction: () => changeFromAction("cancelled"), }, ] : status === "running" ? [ { actionId: "finish", label: "Complete sample", emphasis: "primary", onAction: () => changeFromAction("succeeded"), }, { actionId: "stop", label: "Stop", onAction: () => changeFromAction("cancelled"), }, ] : [ { actionId: "reset", label: "Reset sample", onAction: () => changeFromAction("needs-approval"), }, ]; return (
({ ...action, buttonRef: index === 0 ? firstAction : undefined, }))} footer="Local sample. No tool is run." />
); } export default function AgentExample() { return (
); }