import { handler, NAME, pattern, UI, type VNode, Writable } from "commonfabric"; import { Controls, SwitchControl } from "../ui/controls/index.ts"; // deno-lint-ignore no-empty-interface interface ChatStoryInput {} export interface ChatStoryOutput { [NAME]: string; [UI]: VNode; controls: VNode; } const sampleMessages = [ { role: "system", content: "You are a helpful assistant with access to tools.", }, { role: "user", content: "What's the weather in San Francisco?" }, { role: "assistant", content: [ { type: "tool-call", toolCallId: "call_1", toolName: "get_weather", input: { city: "San Francisco" }, }, ], }, { role: "tool", content: [ { type: "tool-result", toolCallId: "call_1", toolName: "get_weather", output: { temp: "62°F", condition: "Partly cloudy" }, }, ], }, { role: "assistant", content: "The weather in San Francisco is 62°F and partly cloudy.", }, { role: "user", content: "Thanks! Can you also check New York?" }, { role: "assistant", content: [ { type: "tool-call", toolCallId: "call_2", toolName: "get_weather", input: { city: "New York" }, }, ], }, { role: "tool", content: [ { type: "tool-result", toolCallId: "call_2", toolName: "get_weather", output: { temp: "45°F", condition: "Rainy" }, }, ], }, { role: "assistant", content: "New York is currently 45°F and rainy." }, ]; const sampleTools = [ { name: "get_weather", description: "Get current weather for a city" }, { name: "search_web", description: "Search the web for information" }, { name: "run_code", description: "Execute a code snippet" }, ]; const sendMessage = handler< CustomEvent<{ text?: string }>, { messages: Writable } >((event, { messages }) => { const text = event?.detail?.text; if (text?.trim()) { messages.set([ ...messages.get(), { role: "user", content: text.trim() }, ]); } }); export default pattern(() => { const pending = new Writable(false); const messages = new Writable(sampleMessages); return { [NAME]: "cf-chat Story", [UI]: (
{/* Header with beads and tools chip */}
{/* Chat messages */} {/* Prompt input */}
), controls: ( ), }; });