@fish-under-sea/dsh-approval-guide 0.2.0 → 0.2.1
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/README.md +66 -54
- package/cordis.patch.yml +11 -11
- package/lib/client.js +272 -272
- package/lib/index.js +4 -4
- package/package.json +54 -54
package/README.md
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @fish-under-sea/dsh-approval-guide
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
**给 DSH 审批弹窗补一段中文说明:这次审批会做什么、有什么风险、依据是什么。**
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
[](https://www.npmjs.com/package/@fish-under-sea/dsh-approval-guide)
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
6
12
|
|
|
7
|
-
>
|
|
13
|
+
</div>
|
|
8
14
|
|
|
9
15
|
## 解决什么问题
|
|
10
16
|
|
|
@@ -24,22 +30,24 @@ escalate sandbox to danger-full-access: <模型填写的一句英文理由>
|
|
|
24
30
|
<原命令>
|
|
25
31
|
|
|
26
32
|
这次审批会做什么
|
|
27
|
-
把这一次 pwsh 调用的文件沙箱范围提升到「完全放开」(danger-full-access
|
|
28
|
-
|
|
33
|
+
把这一次 pwsh 调用的文件沙箱范围提升到「完全放开」(danger-full-access)。
|
|
34
|
+
只对本次调用生效:不产生长期授权,也不影响之后的命令。
|
|
29
35
|
风险
|
|
30
|
-
|
|
31
|
-
SSH
|
|
36
|
+
放开后这条命令不再受工作区边界约束:它可以读写本机任意文件,
|
|
37
|
+
包括系统目录、其它项目、SSH 密钥与凭据文件,
|
|
38
|
+
本次执行也不再逐条征求你的同意。只有在你完全信任这条命令时才应允许。
|
|
32
39
|
· 工具:pwsh
|
|
33
40
|
· 目标权限:完全放开(danger-full-access)
|
|
34
41
|
· 模型给的理由:<原文>
|
|
35
|
-
|
|
42
|
+
拿不准就先点「拒绝」:拒绝不会中断对话,之后我可以换成只读、
|
|
43
|
+
或只写工作区内的方式重试。
|
|
36
44
|
```
|
|
37
45
|
|
|
38
46
|
说明一律中文显示,不跟随界面语言——界面切到英文时,中文提示仍然在。
|
|
39
47
|
|
|
40
48
|
### 文案分级
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
中文说明由**静态规则**生成,不额外调用模型、不消耗 API 额度,也不会被请求方自己的说辞带偏。
|
|
43
51
|
|
|
44
52
|
| 目标权限 | 级别 | 风险文案要点 |
|
|
45
53
|
| --- | --- | --- |
|
|
@@ -48,92 +56,96 @@ SSH 密钥与凭据文件,本次执行也不再逐条征求你的同意。只
|
|
|
48
56
|
| 其它模式 | 注意 | 不是 DSH 内置模式,无法给出确切范围,提示按请求权限运行。 |
|
|
49
57
|
| 无沙箱参数 | 注意 | 通用兜底:工具请求以更高权限执行本次操作,仅本次有效。 |
|
|
50
58
|
|
|
51
|
-
## 覆盖范围
|
|
52
|
-
|
|
53
|
-
- 所有**带关联工具调用**的交互式审批:沙箱权限升级、hook 触发的 ask、其它插件通过审批通道发起的 ask。
|
|
54
|
-
- 说明的取值按「纵深防御」分层:先看工具调用参数 `sandbox_permissions` / `justification`,取不到再解析宿主理由句式,再取不到走通用兜底。三层都拿不到时仍然显示通用中文说明。
|
|
55
|
-
|
|
56
|
-
### 已知限制
|
|
57
|
-
|
|
58
|
-
- 审批请求若**不带关联工具调用**(`callId` 缺失),核心不会渲染详情区,本插件也就没有插入位置。这是核心插槽契约决定的,不是本插件可以绕过的。
|
|
59
|
-
- 中文说明解释的是「权限范围」这一层风险,不判断命令本身是否安全。命令原文要自己看。
|
|
60
|
-
- 宿主若调整理由句式(`escalate sandbox to <mode>: <理由>`),第一层参数取值仍然有效,只有第二层兜底会失效。
|
|
61
|
-
|
|
62
59
|
## 安装
|
|
63
60
|
|
|
64
|
-
需要 DSH 0.1.5-rc.1 或更高版本。
|
|
65
|
-
|
|
66
61
|
```sh
|
|
67
|
-
|
|
62
|
+
# 从 npm 安装(推荐)
|
|
63
|
+
dsh plugin --profile <profile> add @fish-under-sea/dsh-approval-guide
|
|
68
64
|
```
|
|
69
65
|
|
|
70
|
-
|
|
66
|
+
`--profile` 后跟本机实际的 profile 名:桌面版 `desktop`,Web 版 `web`。
|
|
67
|
+
|
|
68
|
+
要改源码时才用 `link:` 指向本目录(仓库源码即安装源,改完重启 DSH 即生效):
|
|
71
69
|
|
|
72
70
|
```sh
|
|
73
|
-
dsh plugin --profile
|
|
71
|
+
dsh plugin --profile <profile> add "link:<本目录的绝对路径>"
|
|
74
72
|
```
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
换机器复现:把本目录复制过去,改一下安装命令里的路径即可;也可以推到自己的 Git 仓库,用 GUI 的插件管理面板按 Git 地址安装(本包没有构建脚本,不需要放行 pnpm 的构建许可)。
|
|
74
|
+
安装后需要**重启 DSH 应用并刷新页面**才会生效(Web 端没有原地重启)。
|
|
79
75
|
|
|
80
76
|
### 卸载
|
|
81
77
|
|
|
82
78
|
```sh
|
|
83
|
-
dsh plugin --profile
|
|
79
|
+
dsh plugin --profile <profile> remove @fish-under-sea/dsh-approval-guide
|
|
84
80
|
```
|
|
85
81
|
|
|
86
82
|
### 安装后自检
|
|
87
83
|
|
|
88
84
|
```sh
|
|
89
|
-
dsh --profile
|
|
85
|
+
dsh --profile <profile> --dump-config
|
|
90
86
|
```
|
|
91
87
|
|
|
92
88
|
输出末尾应恰好出现一行 `- id: approval-guide` / `name: @fish-under-sea/dsh-approval-guide`。多行即重复挂载,应用会启动失败。
|
|
93
89
|
|
|
94
|
-
##
|
|
95
|
-
|
|
96
|
-
```sh
|
|
97
|
-
node test/guide.test.mjs
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
测试装载的是真正会进浏览器的 `lib/client.js`:用 `node:vm` 提供 `window.__ModuleLoader__`,抓住 bundle 注册的 factory,再用假模块表实例化,直接断言纯函数与组件产出的元素树。**零依赖**,不需要安装 React 或 vitest。
|
|
101
|
-
|
|
102
|
-
> 不要用 `node --test test/`:测试运行器会派生子进程并捕获管道输出,在受限沙箱里会以 `EPERM` 失败。直接运行测试文件即可。
|
|
90
|
+
## 使用
|
|
103
91
|
|
|
104
|
-
|
|
92
|
+
安装后无需任何操作——插件自动占用审批详情的 `conversation.approval.detail` 插槽,在每次审批弹窗里追加中文说明。
|
|
105
93
|
|
|
106
|
-
|
|
94
|
+
说明的取值按「纵深防御」分层:先看工具调用参数 `sandbox_permissions` / `justification`,取不到再解析宿主理由句式(`escalate sandbox to <mode>: <理由>`),再取不到走通用兜底。层层都拿不到时仍然显示通用中文说明。
|
|
107
95
|
|
|
108
|
-
|
|
96
|
+
覆盖范围:
|
|
109
97
|
|
|
110
|
-
|
|
98
|
+
- 所有**带关联工具调用**的交互式审批:沙箱权限升级、hook 触发的 ask、其它插件通过审批通道发起的 ask。
|
|
111
99
|
|
|
112
|
-
|
|
100
|
+
## 配置
|
|
113
101
|
|
|
114
|
-
|
|
115
|
-
- 插槽条目按优先级**升序**排列,**数字最小者渲染**。
|
|
102
|
+
**无配置文件。** 本包没有任何配置项,也不读写设置文件——所有规则硬编码在 `lib/client.js` 里。
|
|
116
103
|
|
|
117
|
-
|
|
104
|
+
## 兼容与边界
|
|
118
105
|
|
|
119
|
-
|
|
106
|
+
- 平台:纯浏览器插件(`dsh.client.platform: web`),宿主半区是空实现。
|
|
107
|
+
- 占用核心包 `@deepseek-ai/dsh-client-ui-approval` 的 `conversation.approval.detail` 子插槽。该插槽为 `single` 类型,按优先级**升序**排列、**数字最小者渲染**;官方占用者 `ApprovalCommand` 用默认优先级 0,本插件注册 `priority: -1` 覆盖它,并在组件里用同一套逻辑(`useChat` 取关联工具调用、解析 `argsRaw.command`)把命令原文重新渲染回来,不丢信息。
|
|
108
|
+
- 组件抛错时,插槽渲染器会回收该条目(abdicate),官方 `ApprovalCommand` 自动恢复渲染——审批卡不会留白,也不会卡住审批流程。
|
|
109
|
+
- 兼容 DSH 0.2.0(`useSessionStatus`)与 0.1.x(`useSessionPendingInteraction`)两代选择器。
|
|
120
110
|
|
|
121
|
-
|
|
111
|
+
数据源:
|
|
122
112
|
|
|
123
113
|
| 数据 | 来源 |
|
|
124
114
|
| --- | --- |
|
|
125
115
|
| 关联工具调用的命令与参数 | `useChat` 选择器(与官方 `ApprovalCommand` 同款) |
|
|
126
|
-
| 工具名与审批理由 | `useSessionPendingInteraction` 选择器(`kind === 'approval'` 的待办交互) |
|
|
116
|
+
| 工具名与审批理由 | `useSessionPendingInteraction` / `useSessionStatus` 选择器(`kind === 'approval'` 的待办交互) |
|
|
117
|
+
|
|
118
|
+
### 已知限制
|
|
119
|
+
|
|
120
|
+
- 审批请求若**不带关联工具调用**(`callId` 缺失),核心不会渲染详情区,本插件也就没有插入位置。这是核心插槽契约决定的,不是本插件可以绕过的。
|
|
121
|
+
- 中文说明解释的是「权限范围」这一层风险,不判断命令本身是否安全。命令原文要自己看。
|
|
122
|
+
- 宿主若调整理由句式(`escalate sandbox to <mode>: <理由>`),第一层参数取值仍然有效,只有第二层兜底会失效。
|
|
127
123
|
|
|
128
|
-
|
|
124
|
+
## 开发与测试
|
|
129
125
|
|
|
130
|
-
|
|
126
|
+
```sh
|
|
127
|
+
node packages/dsh-approval-guide/test/guide.test.mjs
|
|
128
|
+
```
|
|
131
129
|
|
|
132
|
-
|
|
130
|
+
当前 12 个用例全部通过。测试装载的是真正会进浏览器的 `lib/client.js`:用 `node:vm` 提供 `window.__ModuleLoader__`,抓住 bundle 注册的 factory,再用假模块表实例化,直接断言纯函数与组件产出的元素树。**零依赖**,不需要安装 React 或 vitest。
|
|
131
|
+
|
|
132
|
+
> 不要用 `node --test test/`:测试运行器会派生子进程并捕获管道输出,在受限沙箱里会以 `EPERM` 失败。直接运行测试文件即可。
|
|
133
|
+
|
|
134
|
+
覆盖的用例:两种沙箱模式的分级文案、理由兜底解析、未知模式、通用审批兜底、参数 JSON 损坏、空输入不抛异常、组件保留命令原文、取不到 pending 时降级、插槽注册优先级。
|
|
135
|
+
|
|
136
|
+
目录结构:
|
|
133
137
|
|
|
134
138
|
| 路径 | 作用 |
|
|
135
139
|
| --- | --- |
|
|
136
140
|
| `lib/index.js` | 宿主半区,空实现(纯浏览器插件) |
|
|
137
141
|
| `lib/client.js` | 浏览器半区:中文文案、分级逻辑、审批详情组件、插槽注册 |
|
|
138
142
|
| `cordis.patch.yml` | bundle 补丁层,把插件行插入 profile 名册 |
|
|
139
|
-
| `test/guide.test.mjs` | 零依赖测试 |
|
|
143
|
+
| `test/guide.test.mjs` | 零依赖测试 |
|
|
144
|
+
|
|
145
|
+
## 与聚合包的关系
|
|
146
|
+
|
|
147
|
+
> 本包是 [`@fish-under-sea/dsh-fish`](https://github.com/Fish-under-sea/dsh-fish) 聚合包的成员之一;单独安装只影响这一项。
|
|
148
|
+
|
|
149
|
+
## 许可
|
|
150
|
+
|
|
151
|
+
MIT © Fish-under-sea
|
package/cordis.patch.yml
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# dsh-approval-guide bundle layer —— 把插件行插入 web profile 的 roster。
|
|
2
|
-
#
|
|
3
|
-
# 唯一的一行:宿主半区是空实现(纯浏览器插件),浏览器半区占用
|
|
4
|
-
# conversation.approval.detail 插槽渲染中文说明。
|
|
5
|
-
#
|
|
6
|
-
# 安装(在任意目录执行,profile 名按需替换):
|
|
7
|
-
# dsh plugin --profile web add link:<本目录>
|
|
8
|
-
#
|
|
9
|
-
# 本插件没有任何配置项,也不读写设置文件。
|
|
10
|
-
- insert:
|
|
11
|
-
- id: approval-guide
|
|
1
|
+
# dsh-approval-guide bundle layer —— 把插件行插入 web profile 的 roster。
|
|
2
|
+
#
|
|
3
|
+
# 唯一的一行:宿主半区是空实现(纯浏览器插件),浏览器半区占用
|
|
4
|
+
# conversation.approval.detail 插槽渲染中文说明。
|
|
5
|
+
#
|
|
6
|
+
# 安装(在任意目录执行,profile 名按需替换):
|
|
7
|
+
# dsh plugin --profile web add link:<本目录>
|
|
8
|
+
#
|
|
9
|
+
# 本插件没有任何配置项,也不读写设置文件。
|
|
10
|
+
- insert:
|
|
11
|
+
- id: approval-guide
|
|
12
12
|
name: '@fish-under-sea/dsh-approval-guide'
|
package/lib/client.js
CHANGED
|
@@ -1,273 +1,273 @@
|
|
|
1
|
-
// 注册名必须严格等于 package.json 的 name:loader 按行里解析出的包名去
|
|
2
|
-
// factories 里认领 factory(@deepseek-ai/dsh-client-modules 的
|
|
3
|
-
// "loaded without registering" 校验),对不上就在浏览器侧加载失败。
|
|
4
|
-
window.__ModuleLoader__.load({
|
|
5
|
-
id: "@fish-under-sea/dsh-approval-guide",
|
|
6
|
-
factory: (require) => {
|
|
7
|
-
var module = { exports: {} };
|
|
8
|
-
var exports = module.exports;
|
|
9
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
10
|
-
const react_jsx_runtime = require("react/jsx-runtime");
|
|
11
|
-
//#region 样式:复用外壳的设计令牌,跟随明暗主题
|
|
12
|
-
const css = ".dag_root{display:flex;flex-direction:column;gap:8px}.dag_command{color:var(--dsw-alias-label-tertiary);font-family:var(--ds-font-family-code,ui-monospace,SFMono-Regular,Menlo,monospace);word-break:break-all;font-size:13px;line-height:20px}.dag_card{display:flex;flex-direction:column;gap:4px;padding:10px 12px;border-radius:12px;background:var(--dsw-alias-state-warn-tertiary);font-family:var(--dsw-font-family,inherit);word-break:normal}.dag_title{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;line-height:18px}.dag_what{color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}.dag_riskTitle{color:var(--dsw-alias-state-warn-primary);font-size:12px;font-weight:600;line-height:18px;margin-top:2px}.dag_cardDanger .dag_riskTitle{color:var(--dsw-alias-state-error-primary)}.dag_risk{color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}.dag_check{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;margin-top:2px}.dag_facts{margin:2px 0 0;padding:0;list-style:none;display:flex;flex-direction:column;gap:2px}.dag_fact{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}.dag_factLabel{color:var(--dsw-alias-label-secondary)}.dag_factValue{word-break:break-word}";
|
|
13
|
-
const tagId = "dsh-approval-guide/ApprovalGuide.module.css";
|
|
14
|
-
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
15
|
-
const tag = document.createElement("style");
|
|
16
|
-
tag.dataset.plugin = "dsh-approval-guide";
|
|
17
|
-
tag.dataset.pluginCss = tagId;
|
|
18
|
-
tag.textContent = css;
|
|
19
|
-
document.head.appendChild(tag);
|
|
20
|
-
}
|
|
21
|
-
const styles = {
|
|
22
|
-
root: "dag_root",
|
|
23
|
-
command: "dag_command",
|
|
24
|
-
card: "dag_card",
|
|
25
|
-
cardDanger: "dag_cardDanger",
|
|
26
|
-
title: "dag_title",
|
|
27
|
-
what: "dag_what",
|
|
28
|
-
riskTitle: "dag_riskTitle",
|
|
29
|
-
risk: "dag_risk",
|
|
30
|
-
check: "dag_check",
|
|
31
|
-
facts: "dag_facts",
|
|
32
|
-
fact: "dag_fact",
|
|
33
|
-
factLabel: "dag_factLabel",
|
|
34
|
-
factValue: "dag_factValue"
|
|
35
|
-
};
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region 中文文案:按沙箱目标模式分级,一律中文显示
|
|
38
|
-
/** DSH 内置沙箱模式的中文名。 */
|
|
39
|
-
const MODE_LABELS = {
|
|
40
|
-
"read-only": "只读(read-only)",
|
|
41
|
-
"workspace-write": "工作区可写(workspace-write)",
|
|
42
|
-
"danger-full-access": "完全放开(danger-full-access)"
|
|
43
|
-
};
|
|
44
|
-
/** 危险级别:只有完全放开才标红。 */
|
|
45
|
-
const DANGER_MODE = "danger-full-access";
|
|
46
|
-
/** 固定的行动建议。 */
|
|
47
|
-
const CHECK = "拿不准就先点「拒绝」:拒绝不会中断对话,之后我可以换成只读、或只写工作区内的方式重试。";
|
|
48
|
-
/** 找不到工具名时的占位。 */
|
|
49
|
-
const UNKNOWN_TOOL = "(未知工具)";
|
|
50
|
-
/** 宿主沙箱升级请求的理由句式:`escalate sandbox to <mode>: <理由>`。 */
|
|
51
|
-
const SANDBOX_REASON = /^escalate sandbox to\s+([A-Za-z0-9._-]+)\s*:\s*([\s\S]*)$/;
|
|
52
|
-
/**
|
|
53
|
-
* 解析工具调用的原始参数。
|
|
54
|
-
* @param argsRaw - 工具调用参数 JSON 文本。
|
|
55
|
-
* @returns 参数对象;缺失或非对象时返回 undefined(绝不抛异常)。
|
|
56
|
-
*/
|
|
57
|
-
function parseCallArgs(argsRaw) {
|
|
58
|
-
if (typeof argsRaw !== "string" || argsRaw === "") return void 0;
|
|
59
|
-
try {
|
|
60
|
-
const parsed = JSON.parse(argsRaw);
|
|
61
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
|
|
62
|
-
return parsed;
|
|
63
|
-
} catch {
|
|
64
|
-
return void 0;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 从宿主给的英文理由句子里解析沙箱升级信息。
|
|
69
|
-
* @param reason - 审批理由原文。
|
|
70
|
-
* @returns 目标模式与理由;不匹配时返回 undefined。
|
|
71
|
-
*/
|
|
72
|
-
function parseSandboxReason(reason) {
|
|
73
|
-
if (typeof reason !== "string") return void 0;
|
|
74
|
-
const matched = SANDBOX_REASON.exec(reason);
|
|
75
|
-
if (matched === null) return void 0;
|
|
76
|
-
const justification = matched[2].trim();
|
|
77
|
-
return {
|
|
78
|
-
mode: matched[1],
|
|
79
|
-
...justification === "" ? {} : { justification }
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/** 规整工具名。 */
|
|
83
|
-
function toolLabelOf(toolName) {
|
|
84
|
-
return typeof toolName === "string" && toolName.trim() !== "" ? toolName.trim() : UNKNOWN_TOOL;
|
|
85
|
-
}
|
|
86
|
-
/** 沙箱升级的中文说明。 */
|
|
87
|
-
function sandboxGuide(toolLabel, mode, justification, known) {
|
|
88
|
-
const danger = mode === DANGER_MODE;
|
|
89
|
-
const shared = `只对本次调用生效:不产生长期授权,也不影响之后的命令。`;
|
|
90
|
-
let what;
|
|
91
|
-
let risk;
|
|
92
|
-
if (danger) {
|
|
93
|
-
what = `把这一次 ${toolLabel} 调用的文件沙箱范围提升到「完全放开」(${mode})。${shared}`;
|
|
94
|
-
risk = "放开后这条命令不再受工作区边界约束:它可以读写本机任意文件,包括系统目录、其它项目、SSH 密钥与凭据文件,本次执行也不再逐条征求你的同意。只有在你完全信任这条命令时才应允许。";
|
|
95
|
-
} else if (mode === "workspace-write") {
|
|
96
|
-
what = `把这一次 ${toolLabel} 调用的文件沙箱范围提升到「工作区可写」(${mode})。${shared}`;
|
|
97
|
-
risk = "这条命令可以写入当前工作区目录及其子目录,以及系统临时目录;工作区之外的位置仍然不能写入。请留意命令里是否出现工作区以外的写入路径。";
|
|
98
|
-
} else if (known) {
|
|
99
|
-
what = `把这一次 ${toolLabel} 调用的权限提升到 ${mode}。${shared}`;
|
|
100
|
-
risk = "这条命令会按它请求的权限运行,范围不由工作区边界限定。请先确认命令内容确实是你想执行的操作。";
|
|
101
|
-
} else {
|
|
102
|
-
what = `把这一次 ${toolLabel} 调用的权限提升到 ${mode}。${shared}`;
|
|
103
|
-
risk = "这不是 DSH 内置的沙箱模式,无法给出确切范围。批准后该命令会按它请求的权限运行,可能影响工作区之外的内容。请先确认命令内容可信。";
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
level: danger ? "danger" : "caution",
|
|
107
|
-
scope: "sandbox-escalation",
|
|
108
|
-
what,
|
|
109
|
-
risk
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
/** 非沙箱升级的通用中文说明。 */
|
|
113
|
-
function genericGuide(toolLabel) {
|
|
114
|
-
return {
|
|
115
|
-
level: "caution",
|
|
116
|
-
scope: "generic",
|
|
117
|
-
what: `工具 ${toolLabel} 请求以更高权限执行这一次操作。批准只对本次调用生效,不会形成长期授权。`,
|
|
118
|
-
risk: "批准后该工具会按它请求的更高权限运行:可能修改工作区之外的文件、执行系统级命令,或访问本机资源。请先核对上方的理由和下面的命令,确认它确实是你想执行的内容。"
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* 为一次审批生成中文说明(纯函数,不读全局状态,不抛异常)。
|
|
123
|
-
* @param input - 工具名、审批理由、关联的工具调用参数。
|
|
124
|
-
* @returns 会做什么 / 有什么风险 / 判断依据与建议。
|
|
125
|
-
*/
|
|
126
|
-
function explainApproval(input) {
|
|
127
|
-
const source = input === undefined || input === null ? {} : input;
|
|
128
|
-
const args = source.args;
|
|
129
|
-
const toolLabel = toolLabelOf(source.toolName);
|
|
130
|
-
const parsed = parseSandboxReason(source.reason);
|
|
131
|
-
const argsMode = typeof args?.sandbox_permissions === "string" && args.sandbox_permissions !== "" ? args.sandbox_permissions : void 0;
|
|
132
|
-
const mode = argsMode ?? parsed?.mode;
|
|
133
|
-
const argsJustification = typeof args?.justification === "string" && args.justification.trim() !== "" ? args.justification.trim() : void 0;
|
|
134
|
-
const justification = argsJustification ?? parsed?.justification;
|
|
135
|
-
const command = typeof args?.command === "string" && args.command !== "" ? args.command : void 0;
|
|
136
|
-
const body = mode === void 0 ? genericGuide(toolLabel) : sandboxGuide(toolLabel, mode, justification, Object.hasOwn(MODE_LABELS, mode));
|
|
137
|
-
const facts = [{ label: "工具", value: toolLabel }];
|
|
138
|
-
if (mode !== void 0) facts.push({ label: "目标权限", value: MODE_LABELS[mode] ?? mode });
|
|
139
|
-
if (justification !== void 0) facts.push({ label: "模型给的理由", value: justification });
|
|
140
|
-
return {
|
|
141
|
-
...body,
|
|
142
|
-
check: CHECK,
|
|
143
|
-
facts,
|
|
144
|
-
...command === void 0 ? {} : { command },
|
|
145
|
-
toolName: source.toolName
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
//#endregion
|
|
149
|
-
//#region 组件:占用「审批详情」插槽,渲染原命令 + 中文说明
|
|
150
|
-
/**
|
|
151
|
-
* 在 Chat store 里找与审批关联的工具调用根节点。
|
|
152
|
-
* @param snapshot - Chat store 快照。
|
|
153
|
-
* @param callId - 审批关联的工具调用 id。
|
|
154
|
-
* @returns 工具调用根节点;找不到时返回 undefined。
|
|
155
|
-
*/
|
|
156
|
-
function findCorrelatedCall(snapshot, callId) {
|
|
157
|
-
if (snapshot === void 0 || snapshot === null || callId === void 0) return void 0;
|
|
158
|
-
const nodes = snapshot.nodes;
|
|
159
|
-
if (nodes === void 0 || nodes === null || typeof nodes.values !== "function") return void 0;
|
|
160
|
-
for (const node of nodes.values()) {
|
|
161
|
-
const root = node?.kind === "tool-call" ? node.data?.root : void 0;
|
|
162
|
-
if (root !== void 0 && root !== null && root.callId === callId && !("kind" in root)) return root;
|
|
163
|
-
}
|
|
164
|
-
return void 0;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* 审批卡片内的详情区:原文命令 + 中文风险说明。
|
|
168
|
-
* @param props - 插槽标准属性(callId、会话、chat 与待办交互选择器)。
|
|
169
|
-
* @returns 详情区元素。
|
|
170
|
-
*/
|
|
171
|
-
function ApprovalGuide(props) {
|
|
172
|
-
// 插槽标准属性在 DSH 0.2.0 改名:useSessionPendingInteraction → useSessionStatus,
|
|
173
|
-
// 且选择器形状由「会话 Map」变为「会话状态快照」。这里同时兼容两代宿主:
|
|
174
|
-
// 0.2.0 走 useSessionStatus(snapshot => snapshot.get(id)?.pendingInteraction),
|
|
175
|
-
// 0.1.x 回退 useSessionPendingInteraction(bySession => bySession.get(id))。
|
|
176
|
-
const readStatus = props.useSessionStatus;
|
|
177
|
-
const readPendingLegacy = props.useSessionPendingInteraction;
|
|
178
|
-
const pending = typeof readStatus === "function" ? readStatus((snapshot) => snapshot === void 0 || snapshot === null ? void 0 : snapshot.get(props.sessionId)?.pendingInteraction) : typeof readPendingLegacy === "function" ? readPendingLegacy((bySession) => bySession === void 0 || bySession === null ? void 0 : bySession.get(props.sessionId)) : void 0;
|
|
179
|
-
const approval = pending !== void 0 && pending !== null && pending.kind === "approval" ? pending : void 0;
|
|
180
|
-
const readChat = props.useChat;
|
|
181
|
-
const argsRaw = typeof readChat === "function" ? readChat((snapshot) => {
|
|
182
|
-
const call = findCorrelatedCall(snapshot, props.callId);
|
|
183
|
-
return call === void 0 || call === null ? void 0 : call.argsRaw;
|
|
184
|
-
}) : void 0;
|
|
185
|
-
const guide = explainApproval({
|
|
186
|
-
toolName: approval === void 0 ? void 0 : approval.toolName,
|
|
187
|
-
reason: approval === void 0 ? void 0 : approval.reason,
|
|
188
|
-
args: parseCallArgs(argsRaw)
|
|
189
|
-
});
|
|
190
|
-
const children = [];
|
|
191
|
-
if (guide.command !== void 0) children.push((0, react_jsx_runtime.jsx)("div", {
|
|
192
|
-
className: styles.command,
|
|
193
|
-
children: guide.command
|
|
194
|
-
}, "command"));
|
|
195
|
-
const card = [
|
|
196
|
-
(0, react_jsx_runtime.jsx)("div", {
|
|
197
|
-
className: styles.title,
|
|
198
|
-
children: "这次审批会做什么"
|
|
199
|
-
}, "whatTitle"),
|
|
200
|
-
(0, react_jsx_runtime.jsx)("div", {
|
|
201
|
-
className: styles.what,
|
|
202
|
-
children: guide.what
|
|
203
|
-
}, "what"),
|
|
204
|
-
(0, react_jsx_runtime.jsx)("div", {
|
|
205
|
-
className: styles.riskTitle,
|
|
206
|
-
children: "风险"
|
|
207
|
-
}, "riskTitle"),
|
|
208
|
-
(0, react_jsx_runtime.jsx)("div", {
|
|
209
|
-
className: styles.risk,
|
|
210
|
-
children: guide.risk
|
|
211
|
-
}, "risk")
|
|
212
|
-
];
|
|
213
|
-
if (guide.facts.length > 0) card.push((0, react_jsx_runtime.jsx)("ul", {
|
|
214
|
-
className: styles.facts,
|
|
215
|
-
children: guide.facts.map((fact, index) => (0, react_jsx_runtime.jsx)("li", {
|
|
216
|
-
className: styles.fact,
|
|
217
|
-
children: [(0, react_jsx_runtime.jsx)("span", {
|
|
218
|
-
className: styles.factLabel,
|
|
219
|
-
children: `${fact.label}:`
|
|
220
|
-
}, "label"), (0, react_jsx_runtime.jsx)("span", {
|
|
221
|
-
className: styles.factValue,
|
|
222
|
-
children: fact.value
|
|
223
|
-
}, "value")]
|
|
224
|
-
}, `fact-${String(index)}`))
|
|
225
|
-
}, "facts"));
|
|
226
|
-
card.push((0, react_jsx_runtime.jsx)("div", {
|
|
227
|
-
className: styles.check,
|
|
228
|
-
children: guide.check
|
|
229
|
-
}, "check"));
|
|
230
|
-
children.push((0, react_jsx_runtime.jsx)("div", {
|
|
231
|
-
className: guide.level === "danger" ? `${styles.card} ${styles.cardDanger}` : styles.card,
|
|
232
|
-
children: card
|
|
233
|
-
}, "guide"));
|
|
234
|
-
return (0, react_jsx_runtime.jsx)("div", {
|
|
235
|
-
className: styles.root,
|
|
236
|
-
"data-approval-guide": guide.scope,
|
|
237
|
-
children
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
//#endregion
|
|
241
|
-
//#region 插件挂载
|
|
242
|
-
/** 必需服务:插槽注册表。 */
|
|
243
|
-
const inject = ["slots"];
|
|
244
|
-
/**
|
|
245
|
-
* 把中文说明挂到审批详情插槽。
|
|
246
|
-
*
|
|
247
|
-
* `conversation.approval.detail` 是 single 插槽,官方占用者是
|
|
248
|
-
* `@deepseek-ai/dsh-client-ui-chat` 的 ApprovalCommand(默认优先级 0);
|
|
249
|
-
* single 插槽同级注册会直接报错,且优先级数字最小者渲染,因此这里用 -1
|
|
250
|
-
* 覆盖它,并在组件里自己把原始命令重新渲染回来。组件崩溃时条目会被
|
|
251
|
-
* 回收(abdicate),自动退回官方实现,不会留下空白审批卡。
|
|
252
|
-
*
|
|
253
|
-
* @param ctx - 客户端根上下文。
|
|
254
|
-
*/
|
|
255
|
-
function apply(ctx) {
|
|
256
|
-
ctx.slots.inject("conversation.approval.detail", () => ctx.slots.register({
|
|
257
|
-
name: "conversation.approval.detail",
|
|
258
|
-
priority: -1
|
|
259
|
-
}, ApprovalGuide));
|
|
260
|
-
}
|
|
261
|
-
//#endregion
|
|
262
|
-
exports.apply = apply;
|
|
263
|
-
exports.inject = inject;
|
|
264
|
-
exports.__internals = {
|
|
265
|
-
ApprovalGuide,
|
|
266
|
-
explainApproval,
|
|
267
|
-
parseCallArgs,
|
|
268
|
-
parseSandboxReason,
|
|
269
|
-
findCorrelatedCall
|
|
270
|
-
};
|
|
271
|
-
return module.exports;
|
|
272
|
-
}
|
|
1
|
+
// 注册名必须严格等于 package.json 的 name:loader 按行里解析出的包名去
|
|
2
|
+
// factories 里认领 factory(@deepseek-ai/dsh-client-modules 的
|
|
3
|
+
// "loaded without registering" 校验),对不上就在浏览器侧加载失败。
|
|
4
|
+
window.__ModuleLoader__.load({
|
|
5
|
+
id: "@fish-under-sea/dsh-approval-guide",
|
|
6
|
+
factory: (require) => {
|
|
7
|
+
var module = { exports: {} };
|
|
8
|
+
var exports = module.exports;
|
|
9
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
const react_jsx_runtime = require("react/jsx-runtime");
|
|
11
|
+
//#region 样式:复用外壳的设计令牌,跟随明暗主题
|
|
12
|
+
const css = ".dag_root{display:flex;flex-direction:column;gap:8px}.dag_command{color:var(--dsw-alias-label-tertiary);font-family:var(--ds-font-family-code,ui-monospace,SFMono-Regular,Menlo,monospace);word-break:break-all;font-size:13px;line-height:20px}.dag_card{display:flex;flex-direction:column;gap:4px;padding:10px 12px;border-radius:12px;background:var(--dsw-alias-state-warn-tertiary);font-family:var(--dsw-font-family,inherit);word-break:normal}.dag_title{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;line-height:18px}.dag_what{color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}.dag_riskTitle{color:var(--dsw-alias-state-warn-primary);font-size:12px;font-weight:600;line-height:18px;margin-top:2px}.dag_cardDanger .dag_riskTitle{color:var(--dsw-alias-state-error-primary)}.dag_risk{color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}.dag_check{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;margin-top:2px}.dag_facts{margin:2px 0 0;padding:0;list-style:none;display:flex;flex-direction:column;gap:2px}.dag_fact{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}.dag_factLabel{color:var(--dsw-alias-label-secondary)}.dag_factValue{word-break:break-word}";
|
|
13
|
+
const tagId = "dsh-approval-guide/ApprovalGuide.module.css";
|
|
14
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
15
|
+
const tag = document.createElement("style");
|
|
16
|
+
tag.dataset.plugin = "dsh-approval-guide";
|
|
17
|
+
tag.dataset.pluginCss = tagId;
|
|
18
|
+
tag.textContent = css;
|
|
19
|
+
document.head.appendChild(tag);
|
|
20
|
+
}
|
|
21
|
+
const styles = {
|
|
22
|
+
root: "dag_root",
|
|
23
|
+
command: "dag_command",
|
|
24
|
+
card: "dag_card",
|
|
25
|
+
cardDanger: "dag_cardDanger",
|
|
26
|
+
title: "dag_title",
|
|
27
|
+
what: "dag_what",
|
|
28
|
+
riskTitle: "dag_riskTitle",
|
|
29
|
+
risk: "dag_risk",
|
|
30
|
+
check: "dag_check",
|
|
31
|
+
facts: "dag_facts",
|
|
32
|
+
fact: "dag_fact",
|
|
33
|
+
factLabel: "dag_factLabel",
|
|
34
|
+
factValue: "dag_factValue"
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region 中文文案:按沙箱目标模式分级,一律中文显示
|
|
38
|
+
/** DSH 内置沙箱模式的中文名。 */
|
|
39
|
+
const MODE_LABELS = {
|
|
40
|
+
"read-only": "只读(read-only)",
|
|
41
|
+
"workspace-write": "工作区可写(workspace-write)",
|
|
42
|
+
"danger-full-access": "完全放开(danger-full-access)"
|
|
43
|
+
};
|
|
44
|
+
/** 危险级别:只有完全放开才标红。 */
|
|
45
|
+
const DANGER_MODE = "danger-full-access";
|
|
46
|
+
/** 固定的行动建议。 */
|
|
47
|
+
const CHECK = "拿不准就先点「拒绝」:拒绝不会中断对话,之后我可以换成只读、或只写工作区内的方式重试。";
|
|
48
|
+
/** 找不到工具名时的占位。 */
|
|
49
|
+
const UNKNOWN_TOOL = "(未知工具)";
|
|
50
|
+
/** 宿主沙箱升级请求的理由句式:`escalate sandbox to <mode>: <理由>`。 */
|
|
51
|
+
const SANDBOX_REASON = /^escalate sandbox to\s+([A-Za-z0-9._-]+)\s*:\s*([\s\S]*)$/;
|
|
52
|
+
/**
|
|
53
|
+
* 解析工具调用的原始参数。
|
|
54
|
+
* @param argsRaw - 工具调用参数 JSON 文本。
|
|
55
|
+
* @returns 参数对象;缺失或非对象时返回 undefined(绝不抛异常)。
|
|
56
|
+
*/
|
|
57
|
+
function parseCallArgs(argsRaw) {
|
|
58
|
+
if (typeof argsRaw !== "string" || argsRaw === "") return void 0;
|
|
59
|
+
try {
|
|
60
|
+
const parsed = JSON.parse(argsRaw);
|
|
61
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
|
|
62
|
+
return parsed;
|
|
63
|
+
} catch {
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 从宿主给的英文理由句子里解析沙箱升级信息。
|
|
69
|
+
* @param reason - 审批理由原文。
|
|
70
|
+
* @returns 目标模式与理由;不匹配时返回 undefined。
|
|
71
|
+
*/
|
|
72
|
+
function parseSandboxReason(reason) {
|
|
73
|
+
if (typeof reason !== "string") return void 0;
|
|
74
|
+
const matched = SANDBOX_REASON.exec(reason);
|
|
75
|
+
if (matched === null) return void 0;
|
|
76
|
+
const justification = matched[2].trim();
|
|
77
|
+
return {
|
|
78
|
+
mode: matched[1],
|
|
79
|
+
...justification === "" ? {} : { justification }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** 规整工具名。 */
|
|
83
|
+
function toolLabelOf(toolName) {
|
|
84
|
+
return typeof toolName === "string" && toolName.trim() !== "" ? toolName.trim() : UNKNOWN_TOOL;
|
|
85
|
+
}
|
|
86
|
+
/** 沙箱升级的中文说明。 */
|
|
87
|
+
function sandboxGuide(toolLabel, mode, justification, known) {
|
|
88
|
+
const danger = mode === DANGER_MODE;
|
|
89
|
+
const shared = `只对本次调用生效:不产生长期授权,也不影响之后的命令。`;
|
|
90
|
+
let what;
|
|
91
|
+
let risk;
|
|
92
|
+
if (danger) {
|
|
93
|
+
what = `把这一次 ${toolLabel} 调用的文件沙箱范围提升到「完全放开」(${mode})。${shared}`;
|
|
94
|
+
risk = "放开后这条命令不再受工作区边界约束:它可以读写本机任意文件,包括系统目录、其它项目、SSH 密钥与凭据文件,本次执行也不再逐条征求你的同意。只有在你完全信任这条命令时才应允许。";
|
|
95
|
+
} else if (mode === "workspace-write") {
|
|
96
|
+
what = `把这一次 ${toolLabel} 调用的文件沙箱范围提升到「工作区可写」(${mode})。${shared}`;
|
|
97
|
+
risk = "这条命令可以写入当前工作区目录及其子目录,以及系统临时目录;工作区之外的位置仍然不能写入。请留意命令里是否出现工作区以外的写入路径。";
|
|
98
|
+
} else if (known) {
|
|
99
|
+
what = `把这一次 ${toolLabel} 调用的权限提升到 ${mode}。${shared}`;
|
|
100
|
+
risk = "这条命令会按它请求的权限运行,范围不由工作区边界限定。请先确认命令内容确实是你想执行的操作。";
|
|
101
|
+
} else {
|
|
102
|
+
what = `把这一次 ${toolLabel} 调用的权限提升到 ${mode}。${shared}`;
|
|
103
|
+
risk = "这不是 DSH 内置的沙箱模式,无法给出确切范围。批准后该命令会按它请求的权限运行,可能影响工作区之外的内容。请先确认命令内容可信。";
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
level: danger ? "danger" : "caution",
|
|
107
|
+
scope: "sandbox-escalation",
|
|
108
|
+
what,
|
|
109
|
+
risk
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** 非沙箱升级的通用中文说明。 */
|
|
113
|
+
function genericGuide(toolLabel) {
|
|
114
|
+
return {
|
|
115
|
+
level: "caution",
|
|
116
|
+
scope: "generic",
|
|
117
|
+
what: `工具 ${toolLabel} 请求以更高权限执行这一次操作。批准只对本次调用生效,不会形成长期授权。`,
|
|
118
|
+
risk: "批准后该工具会按它请求的更高权限运行:可能修改工作区之外的文件、执行系统级命令,或访问本机资源。请先核对上方的理由和下面的命令,确认它确实是你想执行的内容。"
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 为一次审批生成中文说明(纯函数,不读全局状态,不抛异常)。
|
|
123
|
+
* @param input - 工具名、审批理由、关联的工具调用参数。
|
|
124
|
+
* @returns 会做什么 / 有什么风险 / 判断依据与建议。
|
|
125
|
+
*/
|
|
126
|
+
function explainApproval(input) {
|
|
127
|
+
const source = input === undefined || input === null ? {} : input;
|
|
128
|
+
const args = source.args;
|
|
129
|
+
const toolLabel = toolLabelOf(source.toolName);
|
|
130
|
+
const parsed = parseSandboxReason(source.reason);
|
|
131
|
+
const argsMode = typeof args?.sandbox_permissions === "string" && args.sandbox_permissions !== "" ? args.sandbox_permissions : void 0;
|
|
132
|
+
const mode = argsMode ?? parsed?.mode;
|
|
133
|
+
const argsJustification = typeof args?.justification === "string" && args.justification.trim() !== "" ? args.justification.trim() : void 0;
|
|
134
|
+
const justification = argsJustification ?? parsed?.justification;
|
|
135
|
+
const command = typeof args?.command === "string" && args.command !== "" ? args.command : void 0;
|
|
136
|
+
const body = mode === void 0 ? genericGuide(toolLabel) : sandboxGuide(toolLabel, mode, justification, Object.hasOwn(MODE_LABELS, mode));
|
|
137
|
+
const facts = [{ label: "工具", value: toolLabel }];
|
|
138
|
+
if (mode !== void 0) facts.push({ label: "目标权限", value: MODE_LABELS[mode] ?? mode });
|
|
139
|
+
if (justification !== void 0) facts.push({ label: "模型给的理由", value: justification });
|
|
140
|
+
return {
|
|
141
|
+
...body,
|
|
142
|
+
check: CHECK,
|
|
143
|
+
facts,
|
|
144
|
+
...command === void 0 ? {} : { command },
|
|
145
|
+
toolName: source.toolName
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region 组件:占用「审批详情」插槽,渲染原命令 + 中文说明
|
|
150
|
+
/**
|
|
151
|
+
* 在 Chat store 里找与审批关联的工具调用根节点。
|
|
152
|
+
* @param snapshot - Chat store 快照。
|
|
153
|
+
* @param callId - 审批关联的工具调用 id。
|
|
154
|
+
* @returns 工具调用根节点;找不到时返回 undefined。
|
|
155
|
+
*/
|
|
156
|
+
function findCorrelatedCall(snapshot, callId) {
|
|
157
|
+
if (snapshot === void 0 || snapshot === null || callId === void 0) return void 0;
|
|
158
|
+
const nodes = snapshot.nodes;
|
|
159
|
+
if (nodes === void 0 || nodes === null || typeof nodes.values !== "function") return void 0;
|
|
160
|
+
for (const node of nodes.values()) {
|
|
161
|
+
const root = node?.kind === "tool-call" ? node.data?.root : void 0;
|
|
162
|
+
if (root !== void 0 && root !== null && root.callId === callId && !("kind" in root)) return root;
|
|
163
|
+
}
|
|
164
|
+
return void 0;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 审批卡片内的详情区:原文命令 + 中文风险说明。
|
|
168
|
+
* @param props - 插槽标准属性(callId、会话、chat 与待办交互选择器)。
|
|
169
|
+
* @returns 详情区元素。
|
|
170
|
+
*/
|
|
171
|
+
function ApprovalGuide(props) {
|
|
172
|
+
// 插槽标准属性在 DSH 0.2.0 改名:useSessionPendingInteraction → useSessionStatus,
|
|
173
|
+
// 且选择器形状由「会话 Map」变为「会话状态快照」。这里同时兼容两代宿主:
|
|
174
|
+
// 0.2.0 走 useSessionStatus(snapshot => snapshot.get(id)?.pendingInteraction),
|
|
175
|
+
// 0.1.x 回退 useSessionPendingInteraction(bySession => bySession.get(id))。
|
|
176
|
+
const readStatus = props.useSessionStatus;
|
|
177
|
+
const readPendingLegacy = props.useSessionPendingInteraction;
|
|
178
|
+
const pending = typeof readStatus === "function" ? readStatus((snapshot) => snapshot === void 0 || snapshot === null ? void 0 : snapshot.get(props.sessionId)?.pendingInteraction) : typeof readPendingLegacy === "function" ? readPendingLegacy((bySession) => bySession === void 0 || bySession === null ? void 0 : bySession.get(props.sessionId)) : void 0;
|
|
179
|
+
const approval = pending !== void 0 && pending !== null && pending.kind === "approval" ? pending : void 0;
|
|
180
|
+
const readChat = props.useChat;
|
|
181
|
+
const argsRaw = typeof readChat === "function" ? readChat((snapshot) => {
|
|
182
|
+
const call = findCorrelatedCall(snapshot, props.callId);
|
|
183
|
+
return call === void 0 || call === null ? void 0 : call.argsRaw;
|
|
184
|
+
}) : void 0;
|
|
185
|
+
const guide = explainApproval({
|
|
186
|
+
toolName: approval === void 0 ? void 0 : approval.toolName,
|
|
187
|
+
reason: approval === void 0 ? void 0 : approval.reason,
|
|
188
|
+
args: parseCallArgs(argsRaw)
|
|
189
|
+
});
|
|
190
|
+
const children = [];
|
|
191
|
+
if (guide.command !== void 0) children.push((0, react_jsx_runtime.jsx)("div", {
|
|
192
|
+
className: styles.command,
|
|
193
|
+
children: guide.command
|
|
194
|
+
}, "command"));
|
|
195
|
+
const card = [
|
|
196
|
+
(0, react_jsx_runtime.jsx)("div", {
|
|
197
|
+
className: styles.title,
|
|
198
|
+
children: "这次审批会做什么"
|
|
199
|
+
}, "whatTitle"),
|
|
200
|
+
(0, react_jsx_runtime.jsx)("div", {
|
|
201
|
+
className: styles.what,
|
|
202
|
+
children: guide.what
|
|
203
|
+
}, "what"),
|
|
204
|
+
(0, react_jsx_runtime.jsx)("div", {
|
|
205
|
+
className: styles.riskTitle,
|
|
206
|
+
children: "风险"
|
|
207
|
+
}, "riskTitle"),
|
|
208
|
+
(0, react_jsx_runtime.jsx)("div", {
|
|
209
|
+
className: styles.risk,
|
|
210
|
+
children: guide.risk
|
|
211
|
+
}, "risk")
|
|
212
|
+
];
|
|
213
|
+
if (guide.facts.length > 0) card.push((0, react_jsx_runtime.jsx)("ul", {
|
|
214
|
+
className: styles.facts,
|
|
215
|
+
children: guide.facts.map((fact, index) => (0, react_jsx_runtime.jsx)("li", {
|
|
216
|
+
className: styles.fact,
|
|
217
|
+
children: [(0, react_jsx_runtime.jsx)("span", {
|
|
218
|
+
className: styles.factLabel,
|
|
219
|
+
children: `${fact.label}:`
|
|
220
|
+
}, "label"), (0, react_jsx_runtime.jsx)("span", {
|
|
221
|
+
className: styles.factValue,
|
|
222
|
+
children: fact.value
|
|
223
|
+
}, "value")]
|
|
224
|
+
}, `fact-${String(index)}`))
|
|
225
|
+
}, "facts"));
|
|
226
|
+
card.push((0, react_jsx_runtime.jsx)("div", {
|
|
227
|
+
className: styles.check,
|
|
228
|
+
children: guide.check
|
|
229
|
+
}, "check"));
|
|
230
|
+
children.push((0, react_jsx_runtime.jsx)("div", {
|
|
231
|
+
className: guide.level === "danger" ? `${styles.card} ${styles.cardDanger}` : styles.card,
|
|
232
|
+
children: card
|
|
233
|
+
}, "guide"));
|
|
234
|
+
return (0, react_jsx_runtime.jsx)("div", {
|
|
235
|
+
className: styles.root,
|
|
236
|
+
"data-approval-guide": guide.scope,
|
|
237
|
+
children
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region 插件挂载
|
|
242
|
+
/** 必需服务:插槽注册表。 */
|
|
243
|
+
const inject = ["slots"];
|
|
244
|
+
/**
|
|
245
|
+
* 把中文说明挂到审批详情插槽。
|
|
246
|
+
*
|
|
247
|
+
* `conversation.approval.detail` 是 single 插槽,官方占用者是
|
|
248
|
+
* `@deepseek-ai/dsh-client-ui-chat` 的 ApprovalCommand(默认优先级 0);
|
|
249
|
+
* single 插槽同级注册会直接报错,且优先级数字最小者渲染,因此这里用 -1
|
|
250
|
+
* 覆盖它,并在组件里自己把原始命令重新渲染回来。组件崩溃时条目会被
|
|
251
|
+
* 回收(abdicate),自动退回官方实现,不会留下空白审批卡。
|
|
252
|
+
*
|
|
253
|
+
* @param ctx - 客户端根上下文。
|
|
254
|
+
*/
|
|
255
|
+
function apply(ctx) {
|
|
256
|
+
ctx.slots.inject("conversation.approval.detail", () => ctx.slots.register({
|
|
257
|
+
name: "conversation.approval.detail",
|
|
258
|
+
priority: -1
|
|
259
|
+
}, ApprovalGuide));
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
262
|
+
exports.apply = apply;
|
|
263
|
+
exports.inject = inject;
|
|
264
|
+
exports.__internals = {
|
|
265
|
+
ApprovalGuide,
|
|
266
|
+
explainApproval,
|
|
267
|
+
parseCallArgs,
|
|
268
|
+
parseSandboxReason,
|
|
269
|
+
findCorrelatedCall
|
|
270
|
+
};
|
|
271
|
+
return module.exports;
|
|
272
|
+
}
|
|
273
273
|
});
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//#region src/index.ts
|
|
2
|
-
/** 宿主半区:本插件是纯浏览器插件,宿主侧没有任何行为。 */
|
|
3
|
-
function apply(_ctx) {}
|
|
4
|
-
//#endregion
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
/** 宿主半区:本插件是纯浏览器插件,宿主侧没有任何行为。 */
|
|
3
|
+
function apply(_ctx) {}
|
|
4
|
+
//#endregion
|
|
5
5
|
export { apply };
|
package/package.json
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@fish-under-sea/dsh-approval-guide",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "在 DSH Web GUI 的审批弹窗里追加中文说明:这次审批会做什么、有什么风险、依据是什么。原英文理由与命令原文保留显示。",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./lib/index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"default": "./lib/index.js"
|
|
10
|
-
},
|
|
11
|
-
"./client": {
|
|
12
|
-
"default": "./lib/client.js"
|
|
13
|
-
},
|
|
14
|
-
"./package.json": "./package.json"
|
|
15
|
-
},
|
|
16
|
-
"files": [
|
|
17
|
-
"lib",
|
|
18
|
-
"cordis.patch.yml",
|
|
19
|
-
"README.md"
|
|
20
|
-
],
|
|
21
|
-
"license": "MIT",
|
|
22
|
-
"publishConfig": {
|
|
23
|
-
"access": "public"
|
|
24
|
-
},
|
|
25
|
-
"engines": {
|
|
26
|
-
"node": "^22.19.0 || >=24.0.0"
|
|
27
|
-
},
|
|
28
|
-
"keywords": [
|
|
29
|
-
"dsh",
|
|
30
|
-
"dsh-plugin",
|
|
31
|
-
"approval",
|
|
32
|
-
"sandbox",
|
|
33
|
-
"chinese"
|
|
34
|
-
],
|
|
35
|
-
"scripts": {
|
|
36
|
-
"test": "node test/guide.test.mjs"
|
|
37
|
-
},
|
|
38
|
-
"repository": {
|
|
39
|
-
"type": "git",
|
|
40
|
-
"url": "https://github.com/Fish-under-sea/dsh-fish.git",
|
|
41
|
-
"directory": "packages/dsh-approval-guide"
|
|
42
|
-
},
|
|
43
|
-
"dsh": {
|
|
44
|
-
"engines": {
|
|
45
|
-
"dsh": ">=0.2.0-rc.2"
|
|
46
|
-
},
|
|
47
|
-
"bundle": {
|
|
48
|
-
"patch": "./cordis.patch.yml"
|
|
49
|
-
},
|
|
50
|
-
"client": {
|
|
51
|
-
"inject": [],
|
|
52
|
-
"platform": "web"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@fish-under-sea/dsh-approval-guide",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "在 DSH Web GUI 的审批弹窗里追加中文说明:这次审批会做什么、有什么风险、依据是什么。原英文理由与命令原文保留显示。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"default": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./client": {
|
|
12
|
+
"default": "./lib/client.js"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"lib",
|
|
18
|
+
"cordis.patch.yml",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"dsh",
|
|
30
|
+
"dsh-plugin",
|
|
31
|
+
"approval",
|
|
32
|
+
"sandbox",
|
|
33
|
+
"chinese"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "node test/guide.test.mjs"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/Fish-under-sea/dsh-fish.git",
|
|
41
|
+
"directory": "packages/dsh-approval-guide"
|
|
42
|
+
},
|
|
43
|
+
"dsh": {
|
|
44
|
+
"engines": {
|
|
45
|
+
"dsh": ">=0.2.0-rc.2"
|
|
46
|
+
},
|
|
47
|
+
"bundle": {
|
|
48
|
+
"patch": "./cordis.patch.yml"
|
|
49
|
+
},
|
|
50
|
+
"client": {
|
|
51
|
+
"inject": [],
|
|
52
|
+
"platform": "web"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
55
|
}
|