@aqian0/dsh-renderer 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -2
  3. package/cordis.patch.yml +4 -0
  4. package/icon.svg +5 -0
  5. package/lib/client.js +738 -0
  6. package/lib/config.js +92 -0
  7. package/lib/host/artifact-tool.js +141 -0
  8. package/lib/host/media-bridge.js +102 -0
  9. package/lib/index.js +101 -0
  10. package/lib/shared/config-defaults.js +88 -0
  11. package/lib/shared/content-complexity.js +748 -0
  12. package/lib/shared/media-extractor.js +154 -0
  13. package/lib/shared/sandbox-core.js +217 -0
  14. package/lib/shared/sanitize.js +539 -0
  15. package/lib/types/client/artifact-toolview.d.ts +17 -0
  16. package/lib/types/client/code-view.d.ts +22 -0
  17. package/lib/types/client/document-card.d.ts +33 -0
  18. package/lib/types/client/fence-layer.d.ts +26 -0
  19. package/lib/types/client/highlight.d.ts +24 -0
  20. package/lib/types/client/icons.d.ts +10 -0
  21. package/lib/types/client/locales.d.ts +54 -0
  22. package/lib/types/client/sandbox.d.ts +23 -0
  23. package/lib/types/client/styles.d.ts +20 -0
  24. package/lib/types/client/svg-view.d.ts +19 -0
  25. package/lib/types/client/theme.d.ts +20 -0
  26. package/lib/types/client/turn-media.d.ts +10 -0
  27. package/lib/types/client/types.d.ts +181 -0
  28. package/lib/types/client/workbench.d.ts +24 -0
  29. package/lib/types/client.d.ts +10 -0
  30. package/lib/types/config.d.ts +48 -0
  31. package/lib/types/host/artifact-tool.d.ts +53 -0
  32. package/lib/types/host/media-bridge.d.ts +47 -0
  33. package/lib/types/index.d.ts +29 -0
  34. package/lib/types/shared/config-defaults.d.ts +54 -0
  35. package/lib/types/shared/content-complexity.d.ts +88 -0
  36. package/lib/types/shared/media-extractor.d.ts +42 -0
  37. package/lib/types/shared/sandbox-core.d.ts +101 -0
  38. package/lib/types/shared/sanitize.d.ts +97 -0
  39. package/locale/en.json +6 -0
  40. package/locale/zh.json +6 -0
  41. package/package.json +91 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AQian0
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,120 @@
1
- # Temporary Holding Version
1
+ # @aqian0/dsh-renderer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 面向 [DeepSeek Harness (DSH)](https://github.com/deepseek-ai/deepseek-harness) 的可视化与交互化渲染器插件(纯 TypeScript + ESM,零运行时依赖,基于 Vite+ `vp` + `pnpm` 构建)。
4
+
5
+ ## 功能特性(Phase 1)
6
+
7
+ - **原生 `render_artifact` 工具与流式卡片视图(Host `ctx.tools` + `ctx.systemPrompt` + Client `tool.call.toolview`)**:
8
+ - 默认注册 `render_artifact` 工具与精简提示词引导:模型输出复杂交互 HTML、大型 SVG 架构图或长文档/代码时,从第 1 个 token 起就在对话流中渲染「正在生成…」的 DSH 文档卡片(基于 DSH `PartialArguments` 实时展示标题与体积进度,正文零代码刷屏);
9
+ - 产物内容持久记录在 DSH 会话日志中,刷新页面、切换或回放历史会话仍可随时点击展开至右侧边栏(默认保持点击展开,可通过 `autoOpenArtifact: true` 开启完成后自动弹出侧栏)。
10
+ - **对话流 Fence 可视化渲染与流式提前折叠(`conversation.chat.markdown.fence`)**:
11
+ - 支持 `html` 与 `svg` 代码块,并在流式输出期间对高复杂度内容提前折叠为「生成中」文档卡片,避免先刷出几百行代码再突然塌缩;轻量片段仍保持原位流式高亮与行内渲染;
12
+ - **高复杂度内容自动侧栏展开卡片(Antigravity / DSH 原生卡片风格)**:不局限于 HTML——当 HTML(完整页面、交互脚本、全屏视口布局或 Canvas/WebGL)、SVG(大型架构图、密集图元/文字节点)或任意其他语言的代码块/文档(超长代码模块、多节 Markdown 文档、大型 JSON/YAML/SQL 数据、多文件 Diff 等)复杂度过高时(或围栏元信息标注 `sidebar`/`artifact`/`document`),对话流中自动折叠为符合 DSH 原生视觉风格的整卡可点击展开卡片(按类型匹配图标、自动提取标题、行数与体积及右侧轻箭头指示),点击任意区域即可在右侧边栏工作台打开展示(围栏元信息标注 `inline` 或关闭 `complexContentToSidebar` 可强制保留行内);
13
+ - **Shiki 原生语法高亮**:内置 `@shikijs/core` + `@shikijs/engine-javascript`(纯 JS 正则引擎,无 WASM)及常用语言语法包(`html`/`css`/`js`/`ts`/`xml`/`json`/`yaml`/`markdown`/`python`/`bash`/`sql`/`go`/`rust`/`diff`),直接复用 DSH 的 `--shiki-*` 主题变量,在对话流卡片、右侧工作台与全屏弹窗中提供一致的浅/深色源码高亮;
14
+ - **HTML 交互沙箱**:直接在隔离的不透明沙箱(`Blob URL` + `<iframe sandbox="allow-scripts">`,严禁 `allow-same-origin`)中运行,具备内容高度自动贴合、宿主浅/深色主题同步与全局 LRU 休眠回收;
15
+ - **SVG 静态矢量查看器**:自动补全缺失的 `xmlns="http://www.w3.org/2000/svg"` 并剥离脚本,通过 `Blob URL` 在 `<img>` 上下文静态渲染,支持 25%–400% 缩放、适应宽度与透明棋盘格切换。
16
+ - **右侧边栏 Artifact 工作台与全屏降级**:
17
+ - 当宿主存在 `sidebarRight` / `sidebarRightTabs` 服务时,注册独立 `dsh-renderer:artifact` Tab 与自定义标签标题图标,可将任意 HTML/SVG 产物投射到右侧边栏(同内容重复点击自动聚焦复用已有标签,支持停靠、悬浮与源码对照);无侧栏服务时自动降级为 `shell.overlay` 全屏 Modal。
18
+ - **非破坏性行内富媒体补齐(`conversation.chat.turnTail`)**:
19
+ - 扫描已完成轮次的 Assistant 正文(自动跳过代码块与行内代码),提取并渲染被内置 Markdown 忽略的 `![alt](data:image/*)`、裸 `<img ...>` 与裸 `<svg>` 片段,支持灯箱查看大图。
20
+ - **Host 配置下发与可选工具图像桥接**:
21
+ - 通过 `webserver/index-inject` 将 `cordis.patch.yml` 中的插件配置安全下发至浏览器端;
22
+ - 可选开启 `bridgeToolDataImages`,通过 `tools/post-execute` 将第三方工具返回的 `data:image/*` 转为 DSH 原生持久化图片附件(`ctx.attachments.saveImage`)。
23
+
24
+ ## 配置项(`cordis.patch.yml`)
25
+
26
+ ```yaml
27
+ - insert:
28
+ - id: renderer
29
+ name: '@aqian0/dsh-renderer'
30
+ config:
31
+ enableFencePreview: true
32
+ fenceLanguages: [html, svg]
33
+ defaultView: preview # preview | code
34
+ allowExternalResources: false
35
+ enableWorkbench: true
36
+ complexContentToSidebar: true
37
+ enableArtifactTool: true
38
+ autoOpenArtifact: false
39
+ enableTurnMediaFallback: true
40
+ bridgeToolDataImages: false
41
+ maxContentBytes: 524288
42
+ inlineMaxHeight: 480
43
+ maxActiveSandboxes: 6
44
+ ```
45
+
46
+ ## 目录结构
47
+
48
+ ```text
49
+ .
50
+ ├── .github/workflows/ # CI、npm OIDC 发布与过时 issue 清理
51
+ ├── locale/ # DSH 插件展示元数据(en / zh)
52
+ ├── src/
53
+ │ ├── index.ts # Host 插件入口(webserver/index-inject 与可选图像桥接)
54
+ │ ├── config.ts # Schemastery 配置 schema 与规范化逻辑
55
+ │ ├── host/ # Host 侧辅助模块(render_artifact 工具与提示词、media-bridge)
56
+ │ ├── shared/ # Host/Client 共享纯模块(默认配置、多类型内容复杂度分析、HTML/SVG 净化、媒体提取、LRU 沙箱核心)
57
+ │ ├── client.ts # Web Client 入口(经 vite.client.config.ts 打包为单一 IIFE lib/client.js)
58
+ │ └── client/ # 浏览器渲染模块(styles/locales/theme/sandbox/svg-view/fence-layer/workbench/turn-media)
59
+ ├── test/
60
+ │ ├── build.test.ts # 构建产物、清单、工具链与客户端重执行守卫测试
61
+ │ ├── content-complexity.test.ts # HTML/SVG/Markdown/数据/代码复杂度判定与标题提取单元测试
62
+ │ ├── index.test.ts # Host 入口、配置与工具图像桥接单元测试
63
+ │ ├── sanitize.test.ts # HTML/SVG 净化与 CSP 安全单元测试
64
+ │ ├── media-extractor.test.ts # 正文媒体提取与代码块去重单元测试
65
+ │ └── sandbox.test.ts # LRU 沙箱池、postMessage 校验与 ArtifactStore 单元测试
66
+ ├── cordis.patch.yml # DSH bundle patch
67
+ ├── icon.svg # 36×36 自包含插件图标
68
+ ├── pnpm-workspace.yaml # pnpm overrides(对齐 vite-plus 内置 vite / vitest)
69
+ ├── tsconfig.json # Host ESM 构建配置
70
+ ├── tsconfig.client.json # Client 类型声明构建配置
71
+ ├── tsconfig.test.json # 全仓类型检查配置(noEmit)
72
+ ├── vite.config.ts # Oxfmt / Oxlint / Vitest 统一配置
73
+ └── vite.client.config.ts # Client 单文件 IIFE 打包配置
74
+ ```
75
+
76
+ ## 快速开始
77
+
78
+ ### 环境要求
79
+
80
+ - [Vite+ (`vp`)](https://viteplus.dev/)(自动管理 Node.js 与 `packageManager` 指定的 `pnpm`)
81
+ - Node.js 24+
82
+
83
+ ### 安装依赖与常用命令
84
+
85
+ ```bash
86
+ # 安装依赖(按 pnpm-lock.yaml 还原)
87
+ vp install
88
+
89
+ # 构建 lib/ 与 lib/types/(含 Host ESM 与 Client 单文件 IIFE)
90
+ vp run build
91
+
92
+ # 提交前完整质量门禁(Oxfmt + Oxlint + tsc typecheck + Vitest)
93
+ vp run test
94
+
95
+ # 单独运行测试或覆盖率
96
+ vp test
97
+ vp test --coverage
98
+
99
+ # 格式化 / 静态检查与自动修复
100
+ vp fmt
101
+ vp run check
102
+ vp run check:fix
103
+
104
+ # 本地干跑校验打包产物
105
+ vp pm pack --json -- --dry-run --ignore-scripts
106
+ ```
107
+
108
+ ## 本地安装到 DeepSeek Harness
109
+
110
+ DSH 加载本地目录 bundle 时不会自动执行编译,安装前请先运行一次构建:
111
+
112
+ ```bash
113
+ vp run build
114
+ ```
115
+
116
+ 然后在 DeepSeek Harness 中打开 **插件(Plugins)** → **添加插件(Add plugin)**,选择本仓库根目录即可安装并启用。
117
+
118
+ ## 许可证
119
+
120
+ [MIT](./LICENSE)
@@ -0,0 +1,4 @@
1
+ # dsh-renderer bundle patch.
2
+ - insert:
3
+ - id: renderer
4
+ name: '@aqian0/dsh-renderer'
package/icon.svg ADDED
@@ -0,0 +1,5 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36" fill="none" role="img" aria-label="dsh-renderer">
2
+ <path d="M18 7.5 28.5 13 18 18.5 7.5 13 18 7.5Z" fill="#2563EB"/>
3
+ <path d="M9.5 18.5 18 23l8.5-4.5" stroke="#0EA5E9" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
4
+ <path d="M9.5 23.5 18 28l8.5-4.5" stroke="#64748B" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/>
5
+ </svg>