import type { ExampleUsage, StoryUsage } from './types'; // Shared assistant reply used across the snippets. const REPLY = 'Figma replaced their asm.js pipeline with Wasm and saw a 3x load-time improvement; Google Earth dropped frame render time from 40ms to 12ms.'; /** * Multi-turn with Citations — two exchanges with inline citations; first without * favicons (numbered labels only), second with `showFavicon`. * * API notes: * - `` accepts sources via: * (a) `sources` JS property: `el.sources = [{ href, title, description, label?, showFavicon? }]` * (b) Declarative `` children: picked up via MutationObserver and * appended after prop sources. Use `headline` (not `title`) as the attribute * — `title` is a reserved HTML attribute that conflicts with the CE constructor. * Confirmed in src/elements/source.tsx. * - `numbered` prop: set `` / `el.numbered = true` to * auto-label each chip with its 1-based index from the merged source list. * Per-item `label` is ignored when `numbered` is active. For manual control, * omit `numbered` and set `label` per item. Confirmed in src/elements/source.tsx. * - `showFavicon` on `` sets the default for all items; per-item * `showFavicon` on a child `` overrides it. */ const def: StoryUsage = { intro: 'Answer with cited sources. `` supports two authoring approaches: **data array** — set `el.sources = [{ href, title, description, label?, showFavicon? }]` as a JS property (ideal for dynamic/streamed citations); **composition** — place `` elements as children (ideal for static/authored citations, no JS wiring needed). The two approaches can be mixed: prop sources render first, then children are appended. Add the `numbered` boolean (`` / `el.numbered = true`) to auto-label each chip with its 1-based index. Use `headline` (not `title`) as the `` attribute — `title` is a reserved HTML attribute. (The live demo composes the SolidJS `Source`/`SourceList` primitives.)', snippets: { html: ` `, react: `import { Message, Sources } from '@kitn.ai/chat/react'; export function AnswerWithSources() { return ( <> { const { messageId, action } = e.detail; console.log(messageId, action); }} /> ); }`, vue: ` `, svelte: ` `, angular: `// main.ts: import '@kitn.ai/chat/elements' before bootstrapApplication, // and add CUSTOM_ELEMENTS_SCHEMA to the component/module. import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; @Component({ selector: 'app-answer', standalone: true, schemas: [CUSTOM_ELEMENTS_SCHEMA], // Composition approach: children, no [sources] binding needed. template: \` \`, }) export class AnswerComponent { message = { id: 'm1', role: 'assistant', content: '${REPLY}', actions: ['copy', 'like', 'dislike'], }; onAction(e: CustomEvent<{ messageId: string; action: string }>) { const { messageId, action } = e.detail; console.log(messageId, action); } }`, solid: `import { ChatContainer, ChatContainerContent } from '@kitn.ai/chat'; import { Message, MessageAvatar, MessageContent, MessageActions, Source, SourceTrigger, SourceContent, SourceList, Button, } from '@kitn.ai/chat'; import { Copy, ThumbsUp, ThumbsDown } from 'lucide-solid'; export function AnswerWithSources() { return (
${REPLY} {/* Inline citations: each Source is a hover-card with a numbered trigger */}
); }`, }, }; /** * Example: Conversation with Sources — an assistant reply with inline citations * (``) and copy/like/dislike actions (``). Per-story: * the Usage tab shows the snippet for the story you're on; the example-level * fields below are the fallback. * * Key notes: * - `numbered` prop on `` auto-labels chips 1, 2, 3… from the merged list. * - `` children use `headline` not `title` (reserved HTML attr). * - `` accepts both a `sources` property AND declarative children. */ /** * "Numbered Citations (composition)" — same citation list as the data-driven * "Numbered Citations" story, but built from + * children with no JS sources property. HTML/Vue/Svelte/Angular show the composition * form; React/Solid keep the data-array form (framework components, not web elements). */ const compositionStory: StoryUsage = { intro: 'Build the same numbered-citation strip using `` children instead of a `sources` JS property — ideal for static/authored citations where markup beats data wiring. Place `` elements inside ``: the element picks them up via `MutationObserver` and auto-labels each chip 1, 2, 3…. No JS wiring needed for sources (only for message events). Use `headline` — **not** `title` — as the attribute; `title` is a reserved HTML attribute.', snippets: { html: ` `, vue: ` `, svelte: ` `, angular: `// main.ts: import '@kitn.ai/chat/elements' before bootstrapApplication, // and add CUSTOM_ELEMENTS_SCHEMA to the component/module. import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; @Component({ selector: 'app-numbered-citations', standalone: true, schemas: [CUSTOM_ELEMENTS_SCHEMA], // Composition: children, no [sources] binding needed. template: \` \`, }) export class NumberedCitationsComponent { message = { id: 'm1', role: 'assistant', content: '${REPLY}', actions: ['copy', 'like', 'dislike'], }; onAction(e: CustomEvent<{ messageId: string; action: string }>) { const { messageId, action } = e.detail; console.log(messageId, action); } }`, react: `import { Message, Sources } from '@kitn.ai/chat/react'; // React uses the data-array approach (the Sources component wraps kc-sources). export function NumberedCitations() { return ( <> { const { messageId, action } = e.detail; console.log(messageId, action); }} /> ); }`, solid: `import { ChatContainer, ChatContainerContent } from '@kitn.ai/chat'; import { Message, MessageAvatar, MessageContent, MessageActions, Source, SourceTrigger, SourceContent, SourceList, Button, } from '@kitn.ai/chat'; import { Copy, ThumbsUp, ThumbsDown } from 'lucide-solid'; // Solid uses the primitive components; numbered chips via label={index}. export function NumberedCitations() { return (
${REPLY}
); }`, }, }; const conversationWithSources: ExampleUsage = { title: 'Examples/Conversation with Sources', ...def, // example-level fallback = the "Multi-turn with Citations" story stories: { 'Multi-turn with Citations': def, 'Numbered Citations (composition)': compositionStory, }, }; export default conversationWithSources;