@jetecho/dsh-csv-and-image-preview 0.1.1 → 0.1.3
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.
- package/Agent.md +45 -41
- package/LICENSE +21 -21
- package/README.en.md +81 -79
- package/README.md +85 -79
- package/cordis.patch.yml +6 -6
- package/lib/client.js +318 -190
- package/lib/index.js +380 -420
- package/lib/store.js +144 -0
- package/lib/types/index.d.ts +63 -49
- package/package.json +81 -67
package/Agent.md
CHANGED
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
# Agent.md — dsh-csv-and-image-preview 行为契约
|
|
2
|
-
|
|
3
|
-
这份文档定义当你(agent)使用 `dsh-csv-and-image-preview`
|
|
4
|
-
|
|
5
|
-
## 核心原则:先预览,后落地
|
|
6
|
-
|
|
7
|
-
凡涉及**生成或修改图片 / SVG / CSV**,默认顺序必须是:
|
|
8
|
-
|
|
9
|
-
1. **先预览** —— 调用 `preview_image`(图片 / SVG)或 `preview_csv`(CSV / TSV 表格),把结果渲染到聊天里给用户看;
|
|
10
|
-
- 读磁盘文件:`path=<绝对路径>`
|
|
11
|
-
- 内联 SVG(未落盘):`content=<svg ...> mime=image/svg+xml`
|
|
12
|
-
- 内联 CSV(未落盘):`content=<csv 文本>`;可用 `maxRows` 控制预览行数(默认 50,上限 500),`delimiter` 指定分隔符
|
|
13
|
-
- 任意图片资源:直接传 `path`
|
|
14
|
-
2. **等确认** —— 预览后停止写入,等待用户明确同意;
|
|
15
|
-
3. **用户认可**(如 `确认` / `可以` / `就这样`)后,才真正写文件 / 执行改动;
|
|
16
|
-
4. **用户否决** 时,按反馈修改并**再次预览**,直到认可为止。
|
|
17
|
-
|
|
18
|
-
## 不要做的事
|
|
19
|
-
|
|
20
|
-
- 不要在没预览的情况下,直接覆盖或新增一个图片 / SVG / CSV 文件。
|
|
21
|
-
- 不要把图片字节或 CSV
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
| `
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
# Agent.md — dsh-csv-and-image-preview 行为契约
|
|
2
|
+
|
|
3
|
+
这份文档定义当你(agent)使用 `dsh-csv-and-image-preview` 时应遵守的**预览式工作流**。可将这些规则加入会话指令。
|
|
4
|
+
|
|
5
|
+
## 核心原则:先预览,后落地
|
|
6
|
+
|
|
7
|
+
凡涉及**生成或修改图片 / SVG / CSV**,默认顺序必须是:
|
|
8
|
+
|
|
9
|
+
1. **先预览** —— 调用 `preview_image`(图片 / SVG)或 `preview_csv`(CSV / TSV 表格),把结果渲染到聊天里给用户看;
|
|
10
|
+
- 读磁盘文件:`path=<绝对路径>`
|
|
11
|
+
- 内联 SVG(未落盘):`content=<svg ...> mime=image/svg+xml`
|
|
12
|
+
- 内联 CSV(未落盘):`content=<csv 文本>`;可用 `maxRows` 控制预览行数(默认 50,上限 500),`delimiter` 指定分隔符
|
|
13
|
+
- 任意图片资源:直接传 `path`
|
|
14
|
+
2. **等确认** —— 预览后停止写入,等待用户明确同意;
|
|
15
|
+
3. **用户认可**(如 `确认` / `可以` / `就这样`)后,才真正写文件 / 执行改动;
|
|
16
|
+
4. **用户否决** 时,按反馈修改并**再次预览**,直到认可为止。
|
|
17
|
+
|
|
18
|
+
## 不要做的事
|
|
19
|
+
|
|
20
|
+
- 不要在没预览的情况下,直接覆盖或新增一个图片 / SVG / CSV 文件。
|
|
21
|
+
- 不要把图片字节或 CSV 全文/大段表格数据塞进回复文本或工具输出 —— 插件通过独立快照通道展示,你只需拿到紧凑摘要。
|
|
22
|
+
- 返回“预览数据已生成”只表示快照保存成功。如果用户报告没有显示,按失败信息排查或重新预览,不要坚持声称已经显示。
|
|
23
|
+
- 不要用 markdown `` 或 ```` ```dsh-ui ```` 的 `image` 组件来"显示图片"—— 聊天渲染器会拦截,必须走 `preview_image`;同理 CSV 必须走 `preview_csv`,不要用整段代码块充当"预览"。
|
|
24
|
+
|
|
25
|
+
## 交互话术
|
|
26
|
+
|
|
27
|
+
- 预览后:**"这是预览,请确认后再写入。"** 或列出的差异点。
|
|
28
|
+
- 等待确认时,保持在工作流里,不要擅自落地。
|
|
29
|
+
- 确认后:**"已按预览图写入 `path`。"**
|
|
30
|
+
|
|
31
|
+
## 插件能力
|
|
32
|
+
|
|
33
|
+
| 能力 | 说明 |
|
|
34
|
+
|---|---|
|
|
35
|
+
| `preview_image` 工具 | 读取文件 / 内联 SVG → data-URI → 浏览器 `<img>` 渲染 |
|
|
36
|
+
| `preview_csv` 工具 | 读取 CSV/TSV / 内联文本 → 有界解析(默认前 50 行,上限 500,列/单元格截断)→ 浏览器 `<table>` 渲染,控件限高局部滚动,表头可点击排序 |
|
|
37
|
+
| 键控 toolview | `tool.call.toolview` key=`preview_image` / `preview_csv`,渲染原生 DOM |
|
|
38
|
+
| 聊天正文预览 | 回答结束后在正文末尾直接显示已生成的预览,不需要用户点击侧栏;刷新历史时重放调用并读取快照 |
|
|
39
|
+
| 快照通道 | 按会话 ID 和调用 ID 保存快照,经 DSH 认证的 RPC 通道给浏览器读取;直接调用和 `run_code` 均支持;旧 meta 仍兼容 |
|
|
40
|
+
|
|
41
|
+
预览本身会在插件数据目录保存快照,不修改目标文件。新建目标文件仍需遵循用户的预览确认约定。
|
|
42
|
+
|
|
43
|
+
## 为什么
|
|
44
|
+
|
|
45
|
+
聊天渲染器不渲染 markdown 或 genui 里的图片(白名单里也没有 `image` 组件)。`React.createElement('img')` 生成的是浏览器原生 `<img>`,不经过那套过滤,所以能真实显示;CSV 同理,原生 `<table>` 键控 toolview 直接渲染,模型只拿行列摘要。预览式工作流让用户**先看到结果再决策**,避免"生成即覆写"的返工。
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 jetecho
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 jetecho
|
|
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.en.md
CHANGED
|
@@ -1,79 +1,81 @@
|
|
|
1
|
-
# dsh-csv-and-image-preview
|
|
2
|
-
|
|
3
|
-
English | [中文](README.md)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```sh
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
##
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1
|
+
# dsh-csv-and-image-preview
|
|
2
|
+
|
|
3
|
+
English | [中文](README.md)
|
|
4
|
+
|
|
5
|
+
Preview images, SVG and CSV/TSV in DeepSeek Harness chat using native `<img>` and `<table>` elements. Tables have sticky headers, 320px internal scrolling and sortable columns.
|
|
6
|
+
|
|
7
|
+
## 0.1.3: dedicated inline preview rows
|
|
8
|
+
|
|
9
|
+
Version 0.1.3 registers dedicated keyed Chat nodes after turn/end, outside the collapsed process interval, preserving DSH's existing file cards. Native and nested preview calls and legacy metadata are replayed. Refreshing or reopening history reloads saved snapshots. Files presented only through DSH's `present` tool are outside this feature.
|
|
10
|
+
|
|
11
|
+
Run `npm test`; set `DSH_UPSTREAM` to a DSH source checkout to include the real conversation assembler integration. `npm run preview:test` provides a browser fixture with a completion button and refresh verification.
|
|
12
|
+
|
|
13
|
+
## Install and upgrade
|
|
14
|
+
|
|
15
|
+
Version 0.1.3 is tested with **DSH 0.1.5-rc.1** and requires its Connection RPC interface or a compatible newer version.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
# Install the published version
|
|
19
|
+
dsh plugin --profile web add @jetecho/dsh-csv-and-image-preview
|
|
20
|
+
|
|
21
|
+
# Build and install this checkout without publishing to npm
|
|
22
|
+
npm ci
|
|
23
|
+
npm test
|
|
24
|
+
npm pack
|
|
25
|
+
dsh plugin --profile web add ./jetecho-dsh-csv-and-image-preview-0.1.3.tgz
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Restart `dsh web` and refresh the browser after installation. Package name, bundle row ID and tool names are unchanged.
|
|
29
|
+
|
|
30
|
+
## Compatibility fixes
|
|
31
|
+
|
|
32
|
+
The plugin registers only the exact `/api/csv-and-image-preview/get` route, preserving the shared `/api` interceptor owned by DSH's Gateway so history and plugin lists load normally. Upgrade, restart DSH and refresh the page; the fix does not modify session files.
|
|
33
|
+
|
|
34
|
+
- Explicit client dependencies on `slots` and `connection`, and host dependencies on `tools` and `connection`. Late service startup parks the plugin; unloading cleans up registrations.
|
|
35
|
+
- **Native calls and `run_code` child calls both work.** Current DSH computes `presentationMeta` only for top-level calls. New previews use a separate snapshot channel.
|
|
36
|
+
- Inputs are read and parsed once, then saved before success is returned. Both the model and code program receive only a string summary, with no additional image bytes or table body.
|
|
37
|
+
- Separate generating, loading, tool failure, missing snapshot and image decode failure states. Includes retry, reconnection refresh and cancellation of stale requests when navigating.
|
|
38
|
+
- Legacy `block.meta.src` and `block.meta.rows` still render. Old nested calls that never persisted presentation data must be previewed again.
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
preview_image {"path":"D:/assets/logo.svg","label":"Logo preview"}
|
|
44
|
+
preview_csv {"path":"D:/data/sales.csv","label":"Sales","maxRows":100}
|
|
45
|
+
preview_csv {"content":"Name,Score\nAlice,90\nBob,85"}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Inline SVG text can be supplied as `content`. Relative paths resolve against the session working directory. `path` takes precedence over `content`.
|
|
49
|
+
|
|
50
|
+
Images support SVG, PNG, JPEG, GIF, WebP, BMP, ICO and AVIF. Inline non-SVG content requires standard base64 and a `mime` value. Image and CSV inputs are capped at 8 MiB; the inline base64 limit applies to encoded input size.
|
|
51
|
+
|
|
52
|
+
CSV files require UTF-8 (BOM supported); other encodings produce an explicit conversion message. Delimiter detection supports comma, semicolon, Tab and pipe, with a `delimiter` override; `.tsv` defaults to Tab. Defaults: 50 rows; limits: 500 rows including the header, 40 columns and 200 characters plus an ellipsis per cell. Hover shows retained text only; discarded text is not recoverable. Headers cycle ascending, descending and original order, with empty values last.
|
|
53
|
+
|
|
54
|
+
## Storage and replay
|
|
55
|
+
|
|
56
|
+
Snapshots live in `$DSH_HOME/storages/csv-and-image-preview/`, defaulting to `~/.dsh/storages/csv-and-image-preview/`. Records are keyed by session ID, call ID and tool name using hashed filenames. Reads use DSH Connection's authenticated `/api` RPC channel and verify record identity.
|
|
57
|
+
|
|
58
|
+
The same session can replay the original snapshot after refreshing, restarting DSH or changing/deleting the source file. Back up this directory alongside session data. Snapshots are not automatically pruned; deleting them removes new-format historical previews. Copying/forking into another session does not automatically migrate snapshots.
|
|
59
|
+
|
|
60
|
+
The returned “preview data generated” summary acknowledges persistence, not successful browser decoding. Tool errors are reported as real failures.
|
|
61
|
+
|
|
62
|
+
## Preview-first convention
|
|
63
|
+
|
|
64
|
+
Preview generated or modified images/SVG/CSV before changing target files, then wait for user approval. Previewing itself writes a snapshot in the plugin data directory. This is an agent convention, not an enforcement mechanism against other write tools. Add [Agent.md](Agent.md) to your agent instructions if desired.
|
|
65
|
+
|
|
66
|
+
## Development
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
npm ci
|
|
70
|
+
npm test # Cordis / DSH dispatch, persistence and React regression tests
|
|
71
|
+
npm run preview:test # Local browser verification page; prints its URL
|
|
72
|
+
npm run build # lib/ is publishable JavaScript
|
|
73
|
+
npm pack --dry-run
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- `lib/index.js`: tool definitions and input parsing.
|
|
77
|
+
- `lib/store.js`: atomic snapshots, bounded reads and authenticated channel handler.
|
|
78
|
+
- `lib/client.js`: toolviews, RPC reads, status/retry and legacy metadata support.
|
|
79
|
+
- `cordis.patch.yml`: Profile Bundle insertion.
|
|
80
|
+
|
|
81
|
+
MIT © [jetecho](LICENSE).
|
package/README.md
CHANGED
|
@@ -1,79 +1,85 @@
|
|
|
1
|
-
# dsh-csv-and-image-preview
|
|
2
|
-
|
|
3
|
-
[English](README.en.md) | 中文
|
|
4
|
-
|
|
5
|
-
在 DeepSeek Harness
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1
|
+
# dsh-csv-and-image-preview
|
|
2
|
+
|
|
3
|
+
[English](README.en.md) | 中文
|
|
4
|
+
|
|
5
|
+
在 DeepSeek Harness 聊天中预览图片、SVG 和 CSV/TSV。图片使用原生 `<img>`,表格使用原生 `<table>`,支持粘性表头、320px 内部滚动和点击排序。
|
|
6
|
+
|
|
7
|
+
## 安装与升级
|
|
8
|
+
|
|
9
|
+
0.1.3 针对 DSH **0.1.5-rc.1** 验证,使用新版 Connection RPC 接口。请使用该版本或兼容接口的更新版。
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
# 安装已发布版本
|
|
13
|
+
dsh plugin --profile web add @jetecho/dsh-csv-and-image-preview
|
|
14
|
+
|
|
15
|
+
# 从当前仓库打包并安装修复版(无需发布 npm)
|
|
16
|
+
npm ci
|
|
17
|
+
npm test
|
|
18
|
+
npm pack
|
|
19
|
+
dsh plugin --profile web add ./jetecho-dsh-csv-and-image-preview-0.1.3.tgz
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
安装后重启 `dsh web` 并刷新浏览器。包名、bundle 行 ID 和工具名均保持不变。
|
|
23
|
+
|
|
24
|
+
## 0.1.3:修正正文预览的实际挂载
|
|
25
|
+
|
|
26
|
+
0.1.3 使用独立的 `conversation.chat.node` 键控内容行,在 `turn/end` 之后显示预览,避开执行过程的折叠区间。原有文件卡片继续由 DSH 渲染。
|
|
27
|
+
|
|
28
|
+
图片、SVG、CSV 支持直接调用、`run_code` 嵌套调用和旧版 meta。刷新或重新打开会话后重放已保存的预览;仅调用 DSH `present` 而没有调用本插件的文件不在此功能范围内。
|
|
29
|
+
|
|
30
|
+
验证:`npm test` 使用真实 SlotCore 校验注册。设置 `DSH_UPSTREAM` 为 DSH 源码目录后,可额外使用真实 ConversationNodeAssembler 和 ChatSnapshotBuilder 检查增量事件与历史回放。`npm run preview:test` 提供浏览器验收页;同时设置 `DSH_SESSION` 为本机会话文件时,只读回放该会话及已有快照,不修改原会话文件。
|
|
31
|
+
|
|
32
|
+
## 兼容性修复
|
|
33
|
+
|
|
34
|
+
预览只注册 `/api/csv-and-image-preview/get` 精确路由,避免占用由 DSH 系统网关独享的 `/api` 拦截器,保证历史列表和插件列表正常加载。升级后重启 DSH 并刷新页面即可重新加载,修复不修改会话文件。
|
|
35
|
+
|
|
36
|
+
- 前端声明 `slots`、`connection` 服务依赖,后端声明 `tools`、`connection`;服务稍晚就绪时会等待,卸载时清理注册。
|
|
37
|
+
- **直接调用和 `run_code` 嵌套调用均可预览。** 新版 DSH 不为嵌套调用生成 `presentationMeta`,因此本插件改用独立快照通道。
|
|
38
|
+
- 工具只读取、解析一次输入,在返回成功之前保存快照。模型和 `run_code` 程序收到的仍是字符串摘要,不额外包含图片字节或表格正文。
|
|
39
|
+
- 前端区分生成中、加载中、执行失败、快照缺失和图片解码失败,支持重试、连接恢复后重新读取,以及切换会话时取消过期请求。
|
|
40
|
+
- 旧会话已有的 `block.meta.src` / `block.meta.rows` 继续显示。旧版嵌套调用如果从未保存展示数据,需重新调用预览工具。
|
|
41
|
+
|
|
42
|
+
## 使用
|
|
43
|
+
|
|
44
|
+
让 agent 调用工具,例如:
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
preview_image {"path":"D:/assets/logo.svg","label":"Logo 预览"}
|
|
48
|
+
preview_csv {"path":"D:/data/sales.csv","label":"销售数据","maxRows":100}
|
|
49
|
+
preview_csv {"content":"姓名,分数\n张三,90\n李四,85"}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
内联 SVG 可直接传入 `content`。相对路径以当前会话工作目录为基准。`path` 与 `content` 同时存在时优先读取 `path`。
|
|
53
|
+
|
|
54
|
+
图片支持 SVG、PNG、JPEG、GIF、WebP、BMP、ICO、AVIF。内联非 SVG 内容使用标准 base64,同时指定 `mime`。图片和 CSV 输入均限制为 8 MiB;内联 base64 限制按编码后的输入大小计算。
|
|
55
|
+
|
|
56
|
+
CSV 文件必须为 UTF-8,支持 UTF-8 BOM;其他编码会明确提示转换,而不是输出乱码。自动识别逗号、分号、Tab、竖线,或用 `delimiter` 指定;`.tsv` 默认 Tab。默认显示前 50 行,最多 500 行(均含表头)、40 列,每个单元格最多保存 200 字符加省略号。悬停显示已保存的单元格内容,截断部分无法还原。点击表头循环升序、降序、原始顺序,空值始终沉底。
|
|
57
|
+
|
|
58
|
+
## 数据与历史预览
|
|
59
|
+
|
|
60
|
+
预览快照保存在 `$DSH_HOME/storages/csv-and-image-preview/`;未设置 `DSH_HOME` 时使用 `~/.dsh/storages/csv-and-image-preview/`。每条记录按会话 ID、调用 ID 和工具名定位,路径采用哈希文件名。通过 DSH Connection 的已认证 `/api` RPC 通道读取,并核对记录身份。
|
|
61
|
+
|
|
62
|
+
刷新页面、重启 DSH 或修改/删除原文件后,同一会话仍显示生成时的快照。备份会话时应同时备份此目录。当前不自动清理快照;删除目录会让新版历史预览失效。复制/分叉成新会话时不自动迁移原会话的快照。
|
|
63
|
+
|
|
64
|
+
调用返回 `预览数据已生成…` 表示快照保存成功,不代表浏览器已解码显示。工具执行错误作为真正的失败交给 DSH,避免误报成功。
|
|
65
|
+
|
|
66
|
+
## 预览优先约定
|
|
67
|
+
|
|
68
|
+
生成或修改图片、SVG、CSV 时,先预览,用户认可后再修改目标文件;预览快照本身会写入插件数据目录。此约定由 agent 遵守,插件不阻止其他写文件工具。可将 [Agent.md](Agent.md) 的说明加入 agent 指令。
|
|
69
|
+
|
|
70
|
+
## 开发
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
npm ci
|
|
74
|
+
npm test # Cordis / DSH 工具调度、持久化、React 组件回归
|
|
75
|
+
npm run preview:test # 本地浏览器验收页,终端显示地址
|
|
76
|
+
npm run build # lib/ 为可直接发布的 JavaScript
|
|
77
|
+
npm pack --dry-run # 检查发布文件
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- `lib/index.js`:工具定义、输入读取与解析。
|
|
81
|
+
- `lib/store.js`:原子快照写入、读取边界、认证通道处理函数。
|
|
82
|
+
- `lib/client.js`:工具视图、RPC 读取、状态与重试、旧 meta 兼容。
|
|
83
|
+
- `cordis.patch.yml`:标准 Profile Bundle 插入行。
|
|
84
|
+
|
|
85
|
+
MIT © [jetecho](LICENSE).
|
package/cordis.patch.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# dsh-csv-and-image-preview bundle patch: one host row over the web profile.
|
|
2
|
-
# The row name resolves from the profile's own node_modules where
|
|
3
|
-
# `dsh plugin --profile web add <path>` installed this package.
|
|
4
|
-
- insert:
|
|
5
|
-
- id: csv-and-image-preview
|
|
6
|
-
name: dsh-csv-and-image-preview
|
|
1
|
+
# dsh-csv-and-image-preview bundle patch: one host row over the web profile.
|
|
2
|
+
# The row name resolves from the profile's own node_modules where
|
|
3
|
+
# `dsh plugin --profile web add <path>` installed this package.
|
|
4
|
+
- insert:
|
|
5
|
+
- id: csv-and-image-preview
|
|
6
|
+
name: '@jetecho/dsh-csv-and-image-preview'
|