use-assistant-chat.ts
6.74 KB
-
feat(assistant): HTML artifact PoC — 模型按需产卡片/报表,沙箱 iframe 渲染 · 46b60bec
机制 B(Claude Artifacts 式,即用即焚): - 后端加本地工具 render_artifact({title, html}),html 是 <body> 内部片段; SYSTEM_PROMPT 加"展示方式"skill:简短问答用文字;召回列表/画像卡/分析报表用 render_artifact, Tailwind + PAC teal 配色,图表用 Chart.js,禁外部网络、数据内联、手机号掩码。 - 前端 use-assistant-chat 加 artifact block(拦截 render_artifact 的 tool_call → html); assistant-chat 加 ArtifactView:沙箱 iframe 渲染。 - 安全:sandbox="allow-scripts"(无 allow-same-origin)→ 脚本在 null origin 碰不到父页 cookie/凭证;注入 CSP default-src 'none' + 只放行 Tailwind/Chart.js CDN + connect-src 'none' 堵死外传(患者数据不会被偷渡);postMessage 自适应高度;支持新窗口打开。 运行环境(iframe shell)由前端注入 Tailwind Play CDN + Chart.js,模型不写 <html>/<head>。 注:沙箱隔离,无法用父页的 Next.js/shadcn 组件;Tailwind+原生JS+Chart.js 已覆盖卡片+图表需求。 验证(deepseek):天气→纯文字不产卡;"卡片展示召回池TOP5"→ list_recall_queue→render_artifact, HTML 含 canvas 图表、teal 配色、无 fetch。两端 tsc 0。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>luoqi committed