import React, { useMemo, useRef, useState } from 'react'; import { createRoot } from 'react-dom/client'; import type { ChatSnapshot } from '@deepseek-ai/dsh-client-ui-chat/client'; import { ChoreographedFlow, useFlowChat } from '../src/client/ChoreographedFlow.js'; import { presentLiveTurn } from '../src/client/live-turn.js'; import type { LiveStep } from '../src/client/live-turn.js'; import { Disclosure, StatusText, useMotionAllowed, useReadingScroll } from '../src/client/motion.js'; import { ReasoningCard } from '../src/client/ReasoningCard.js'; import { StreamMotionContext, useStreamingText } from '../src/client/streaming.js'; import css from '../src/client/Reader.module.css'; const sample = '旧内容保持原位,先完成连续收拢,再确认数字,最后继续输出。This is a real component regression fixture, not a replacement animation. '; function Text({ step }: { step: LiveStep }) { const node = useFlowChat(s => 'nodeKey' in step ? s.nodes.get(step.nodeKey) : undefined); const source = (node?.data as { text?: string })?.text ?? ''; const text = useStreamingText(source, true, { startedAt: 0, interrupted: false, selected: false }); if (step.kind === 'reasoning') return {}}>
{text.text}
; return
{step.kind === 'body' ? sample : '工具 · 读取源文件,等待下一个步骤'}
; } function Demo() { const [n, setN] = useState(1); const [tail, setTail] = useState(0); const [auto, setAuto] = useState(true); const [motionSetting, setMotion] = useState(true); const motion = useMotionAllowed(motionSetting); const [urgent, setUrgent] = useState(false); const [expanded, setExpanded] = useState(true); const [open, setOpen] = useState>({}); const root = useRef(null); const button=useRef(null); useReadingScroll(root, motion); const frame = useMemo(() => { const steps: LiveStep[] = []; const nodes = new Map(); for (let i=1; i<=n; i++) { steps.push({ kind: 'reasoning', key: `r${i}`, nodeKey:`r${i}`, start:0, blocks:[], step:i }); nodes.set(`r${i}`, { data: { text: sample.repeat(i===n && n>1 ? 3 + tail : 5) } }); if (inodes.get(key)}} as unknown as ChatSnapshot}; }, [n,tail,auto]); (window as any).fixture = { next:()=>setN(v=>v+1), burst:()=>{setN(v=>v+1); setTimeout(()=>setN(v=>v+2),100); setTimeout(()=>setTail(v=>v+2),180);}, stop:()=>setUrgent(true), reduce:()=>setMotion(false), reset:()=>{setN(1);setTail(0);setUrgent(false);setOpen({});setMotion(true);setAuto(true);} }; return <>
} />
setOpen(s=>({...s,[key]:value}))} renderStep={step=>} />
输入区位置参照 · 后台数据不会被修改
; } createRoot(document.getElementById('app')!).render();