text stringlengths 0 1.47k |
|---|
export type TurnCardsInjected = InjectFace<{ readonly hooks: { readonly visualizeFolds: HostObservable<boolean> } }> |
const listStyle: CSSProperties = { display: 'grid', gap: 12, margin: '8px 0 4px' } |
/** |
* Turn-tail entry. A list turn tail mounts it on every turn, so it declines |
* turns without cards itself, and it stays empty whenever the host is not |
* folding — the toolview card is then already in view. |
* @param props - turn owner props plus the injected folding selector. |
* @returns the turn's cards, or null. |
*/ |
export function TurnCards({ turn, seq, useVisualizeFolds }: PropsRuntime<'conversation.chat.turnTail'> & TurnCardsInjected) { |
const folds = useVisualizeFolds(value => value) |
const cards = cardsBefore(turn, seq) |
if (!folds || cards.length === 0) return null |
return ( |
<div style={listStyle}> |
{cards.map(card => ( |
// A distinct height token: the toolview frame for the same call may be |
// mounted too (an opened fold) and reports under the bare call id. |
<Frame key={card.callId} meta={card.meta} callId={`turn-tail:${card.callId}`} /> |
))} |
</div> |
) |
} |
# ===== file: src/client/VisualizeCard.tsx ===== |
/** |
* The `visualize` toolview: renders the persisted fragment from the call's |
* durable meta inside `<iframe sandbox="allow-scripts">` with the frame's own |
* CSP. Replay-stable by construction — everything drawn derives from the |
* logged call slice, never from the fragment file. |
* |
* Theme bridge: the card resolves the host's `--dsw-alias-*` design tokens |
* (whale-blue brand accent included) at render time and injects them into the |
* frame document as `--dsh-viz-*` variables; a mutation of the root element's |
* attributes or an OS appearance flip re-resolves them, so the frame follows |
* live theme switches. The frame body stays transparent to blend with the |
* conversation surface. |
* |
* Height: a sandboxed frame's document is unreachable from the parent, so the |
* frame posts its scroll height (tagged with this call's id) and the card |
* sizes the iframe, capped per mode with internal scrolling past the cap. |
*/ |
import { useEffect, useMemo, useState, type CSSProperties } from 'react' |
import type { ToolCallViewProps } from '@deepseek-ai/dsh-client-ui-tool/client' |
import { visualizeMetaFrom, visualizeMetaFromArgs, type VisualizeMeta } from '../fragment.ts' |
import { buildFrameDoc, HEIGHT_MESSAGE_TYPE } from '../shell.ts' |
import { resolveTheme } from './theme.ts' |
/** Iframe height bounds; content beyond the cap scrolls inside the frame. */ |
const MIN_HEIGHT = 48 |
const HEIGHT_CAP: Record<'inline' | 'wide', number> = { inline: 800, wide: 1200 } |
const headerStyle: CSSProperties = { |
display: 'flex', |
alignItems: 'baseline', |
gap: 8, |
fontSize: 12, |
opacity: 0.65, |
margin: '2px 0 6px', |
overflow: 'hidden', |
whiteSpace: 'nowrap', |
} |
const frameStyle: CSSProperties = { |
display: 'block', |
width: '100%', |
border: 0, |
background: 'transparent', |
colorScheme: 'normal', |
} |
/** First text line of the durable result content, for the error row. */ |
function firstResultLine(content: readonly { type: string; text?: string }[]): string { |
for (const block of content) { |
if (block.type === 'text' && typeof block.text === 'string' && block.text.length > 0) { |
const newline = block.text.indexOf('\n') |
return newline === -1 ? block.text : block.text.slice(0, newline) |
} |
} |
return 'visualization failed' |
} |
/** The settled, well-formed card: header line plus the sandboxed frame. */ |
export function Frame({ meta, callId }: { meta: VisualizeMeta; callId: string }) { |
// Bumped by the observers below; each bump re-resolves the bridged palette. |
const [themeTick, setThemeTick] = useState(0) |
const [height, setHeight] = useState(MIN_HEIGHT) |
useEffect(() => { |
const bump = () => setThemeTick(tick => tick + 1) |
const observer = new MutationObserver(bump) |
// Both mount points: DSH toggles dark via a body attribute, other hosts |
// conventionally re-theme via root-element attributes. |
observer.observe(document.documentElement, { attributes: true }) |
observer.observe(document.body, { attributes: true }) |
const media = matchMedia('(prefers-color-scheme: dark)') |
media.addEventListener('change', bump) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.