import type { ExampleUsage, StoryUsage } from './types'; // Shared reasoning steps + reply used across the snippets. const STEPS = `[ { label: 'Analyzing data size and sync limits', content: 'chrome.storage.sync caps total at 102,400 bytes / 512 items, 8,192 bytes per item. 50KB fits but nested objects need splitting.' }, { label: 'Evaluating update frequency constraints', content: '~20-30 writes/hour, well under the 1,800/hour limit even after chunking to ~7 items per update.' }, { label: 'Considering conflict resolution', content: 'storage.sync is last-write-wins; simultaneous edits from two devices can lose data. A backend could merge with CRDTs.' }, { label: 'Weighing implementation complexity', content: 'A custom backend adds servers, auth, offline + retry logic. storage.sync is free, built-in, and offline-ready.' }, ]`; const REPLY = "I'd recommend a hybrid approach: use chrome.storage.sync with a chunking + delta-sync strategy, and upgrade to a backend only if data grows past 80KB or you need real-time collaboration."; /** * Reasoning + Answer — a chain-of-thought trace above an assistant reply. * * `` renders from a flat `steps: { label, content }[]` * property. Key gotchas: * - Set `steps` as a **property** (el.steps = [...]), never as an attribute. * - The `steps` shape has no `icon` field — per-step icons (Search / * Calculator / Lightbulb in this demo) are `ChainOfThoughtTrigger leftIcon` * props, a SolidJS-only touch. Confirmed in src/elements/chain-of-thought.tsx. * - The element has no events and cannot be controlled (open/closed state). * For a controlled reasoning block with `streaming` auto-expand + `kc-open-change`, * use `` instead. * - The copy/like/dislike bar is a separate `MessageActions` composition; it is * not part of the chain-of-thought model. */ const reasoning: StoryUsage = { intro: "Show the model's reasoning above its answer. `` renders a collapsible trace from a `steps` array of `{ label, content }` — set it as a JS **property** (not an attribute). The element has no events and the `steps` shape has no icon field: per-step icons are a SolidJS-only touch via `ChainOfThoughtTrigger leftIcon` (see the Solid tab). For a single streaming reasoning block with `kc-open-change`, use `` instead.", snippets: { html: ` `, react: `import { ChainOfThought, Message } from '@kitn.ai/chat/react'; export function ReasonedReply() { const steps = ${STEPS}; return ( <> console.log(e.detail)} /> ); }`, vue: ` `, svelte: ` console.log(e.detail)} />`, angular: `// main.ts: import '@kitn.ai/chat/elements' before bootstrapApplication, // and add CUSTOM_ELEMENTS_SCHEMA to the component. import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; @Component({ selector: 'app-reasoned-reply', standalone: true, schemas: [CUSTOM_ELEMENTS_SCHEMA], template: \` \`, }) export class ReasonedReplyComponent { steps = ${STEPS}; message = { id: 'm1', role: 'assistant', content: '${REPLY}', actions: ['copy', 'like', 'dislike'], }; log(e: CustomEvent) { console.log(e.detail); } }`, solid: `import { Message, MessageAvatar, MessageContent, MessageActions, ChainOfThought, ChainOfThoughtStep, ChainOfThoughtTrigger, ChainOfThoughtContent, ChainOfThoughtItem, Button, } from '@kitn.ai/chat'; import { Search, Calculator, Lightbulb, Copy, ThumbsUp, ThumbsDown } from 'lucide-solid'; export function ReasonedReply() { return (
{/* Reasoning trace — per-step leftIcon is a Solid-only touch */} }> Analyzing data size and sync limits chrome.storage.sync caps total at 102,400 bytes / 512 items, 8,192 bytes per item. }> Evaluating update frequency constraints ~20-30 writes/hour, well under the 1,800/hour limit even after chunking. }> Weighing implementation complexity A custom backend adds servers and auth; storage.sync is free and offline-ready. ${REPLY} {/* Custom action bar — not part of the kc-chain-of-thought model */}
); }`, }, }; /** * Example: Conversation with Reasoning — a chain-of-thought trace above an * assistant reply. Per-story: the Usage tab shows the snippet for the story * you're on; the example-level fields below are the fallback. * * Two elements are available: * - `` — multi-step trace from a `steps` array; no events. * - `` — single collapsible block; `streaming` auto-expands it; * fires `kc-open-change: { open }`. */ const conversationWithReasoning: ExampleUsage = { title: 'Examples/Conversation with Reasoning', ...reasoning, // example-level fallback = the only story, "Reasoning + Answer" stories: { 'Reasoning + Answer': reasoning, }, }; export default conversationWithReasoning;