@xiangyixie/dsh-superagent 0.16.10 → 0.17.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/CHANGELOG.md +38 -0
- package/README.en.md +3 -3
- package/README.md +3 -3
- package/README.zh.md +3 -3
- package/lib/client.js +458 -10
- package/lib/console.js +82 -30
- package/lib/guard.js +66 -8
- package/lib/index.js +66 -16
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,44 @@ along with the next code release. A doc-only version leaves `lib/` and `bin/`
|
|
|
8
8
|
byte-identical to the version before it, and the pinned install line in the
|
|
9
9
|
README is updated to the version being released.
|
|
10
10
|
|
|
11
|
+
## 0.17.1 — 2026-11-17
|
|
12
|
+
|
|
13
|
+
### 新增
|
|
14
|
+
|
|
15
|
+
- **待决策不再藏在任务详情里。** 有 run 在等你回答时,问题卡直接出现在输入框
|
|
16
|
+
上方;计划确认以选项按钮呈现,点一下就答复。标题栏「会话」带未读数,新问题
|
|
17
|
+
到达时 +1,打开会话或回答后归零。
|
|
18
|
+
- **停止键现在真的停任务。** 除了中断当前 turn,还会取消所有 `running` 的
|
|
19
|
+
run;单条任务仍可在详情里单独停止。
|
|
20
|
+
- **产物三件事都能做。** 预览、在文件夹中显示、下载;「在文件夹中显示」走
|
|
21
|
+
服务端白名单校验后调用系统文件管理器,不会变成任意路径的打开器。
|
|
22
|
+
|
|
23
|
+
### 变更
|
|
24
|
+
|
|
25
|
+
- **关闭或切走面板不再回答审批。** 待决审批会保留到自己的超时,重新打开面板
|
|
26
|
+
仍能看到问题;只有超时才按 `cancelled` 收尾。此前最后一个事件流断开就会把
|
|
27
|
+
所有待决审批判为取消。
|
|
28
|
+
|
|
29
|
+
## 0.17.0 — 2026-11-17
|
|
30
|
+
|
|
31
|
+
### 新增
|
|
32
|
+
|
|
33
|
+
- **面板终于能进控制台的能力了。** 标题栏新增「会话」:当前对话、最近 12 条
|
|
34
|
+
历史、「新对话」都在一步之内;点击历史直接切换,不再需要另开控制台页面。
|
|
35
|
+
- **任务线可点开。** 右侧「调度的会话」每一行不再是死的状态条,点开后能看到
|
|
36
|
+
这条 run 的状态、正在等你回答的问题、报告里引用的产物和执行报告;可以单独
|
|
37
|
+
停止这一条 run。
|
|
38
|
+
- **回答待决策。** 详情里直接显示 `attention` 问题,输入答案即调
|
|
39
|
+
`POST /answer`,不需要回到控制台页。
|
|
40
|
+
- **上传与产物预览。** 输入卡左侧「+」把文件收进当前对话工作区,成功后路径
|
|
41
|
+
自动落进输入框;产物点开走同源中继的 `/artifact`,不再需要手拼 token。
|
|
42
|
+
|
|
43
|
+
### 说明
|
|
44
|
+
|
|
45
|
+
- 入口复用已有的 `/superagent/api` 同源中继,没有引入 iframe,也没有把 token
|
|
46
|
+
带到浏览器;`/superagent/console-address` 仍保留给需要独立页的场景。
|
|
47
|
+
- 缺口清单与后续阶段见 `docs/GAPS-TRAEB.md`。
|
|
48
|
+
|
|
11
49
|
## 0.16.10 — 2026-11-17
|
|
12
50
|
|
|
13
51
|
### 修复
|
package/README.en.md
CHANGED
|
@@ -36,12 +36,12 @@ Three steps. The desktop app and the CLI install the same plugin; each step says
|
|
|
36
36
|
|
|
37
37
|
### 1. Install
|
|
38
38
|
|
|
39
|
-
Desktop: **Plugins** → **Add plugin** → enter `@xiangyixie/dsh-superagent@0.
|
|
39
|
+
Desktop: **Plugins** → **Add plugin** → enter `@xiangyixie/dsh-superagent@0.17.1` → install.
|
|
40
40
|
|
|
41
41
|
CLI:
|
|
42
42
|
|
|
43
43
|
```bash
|
|
44
|
-
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.
|
|
44
|
+
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.17.1
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
**Restart DSH** afterwards — plugins are loaded once at host startup. You can also add the [plugin index](https://raw.githubusercontent.com/LittleChenLiya/dsh-superagent/main/plugin-index.json) on the **Discover** page for one-click installs; upgrades are always remove-then-add.
|
|
@@ -1666,7 +1666,7 @@ appears to "hang" until the ignored-abort child returns.
|
|
|
1666
1666
|
|
|
1667
1667
|
| What you see | What it means | What to do |
|
|
1668
1668
|
| --- | --- | --- |
|
|
1669
|
-
| `superagent_*` tools do not exist | The bundle row is not mounted, or the host refused to load the plugin. | Run `--dump-config` and check for the `@xiangyixie/dsh-superagent` block; reinstall with `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.
|
|
1669
|
+
| `superagent_*` tools do not exist | The bundle row is not mounted, or the host refused to load the plugin. | Run `--dump-config` and check for the `@xiangyixie/dsh-superagent` block; reinstall with `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.17.1` and read the host log for `[dsh-superagent]` lines. |
|
|
1670
1670
|
| `Cannot find module .../lib/control.js` (or `watch.js` / `report.js` / `wizard.js`), or `[dsh-superagent] dsh-superagent failed to load because a file it imports is missing: ...` in the host log | The copy in that profile is incomplete — an `add` that was interrupted leaves a partial extraction. From 0.14.3 the entry point names the missing file itself. The published package is not the cause: every version ships all thirty-four `lib/` files. | Delete the plugin's directory under the profile's `node_modules` (scoped `@xiangyixie/dsh-superagent`, or unscoped `dsh-superagent` from an older tarball install) and run the same `add` command again, with the version number. Do not copy files in by hand. |
|
|
1671
1671
|
| `[error] the model provider rejected the API key` | The key env var is missing in the process that started the host. | Export `DEEPSEEK_API_KEY` (the default route) or the variable your route names, then restart `dsh`. |
|
|
1672
1672
|
| `MISSING_CREDENTIAL ... no API key for provider route "..."` | The profile's route has no credential in the environment. | Set the env var named for that route and restart. The error line names the route, so use that, not this page. |
|
package/README.md
CHANGED
|
@@ -36,12 +36,12 @@ dsh-superagent 把这件事接过去:你说一句目标,它负责拆、负
|
|
|
36
36
|
|
|
37
37
|
### 1. 装
|
|
38
38
|
|
|
39
|
-
桌面端:侧边栏 **插件** → **Add plugin** → 输入 `@xiangyixie/dsh-superagent@0.
|
|
39
|
+
桌面端:侧边栏 **插件** → **Add plugin** → 输入 `@xiangyixie/dsh-superagent@0.17.1` → 安装。
|
|
40
40
|
|
|
41
41
|
命令行:
|
|
42
42
|
|
|
43
43
|
```bash
|
|
44
|
-
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.
|
|
44
|
+
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.17.1
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
装完**重启 DSH**(插件只在宿主启动时加载一次)。也可以从「发现」页添加[插件索引](https://raw.githubusercontent.com/LittleChenLiya/dsh-superagent/main/plugin-index.json)一键安装;升级一律先 `remove` 再 `add`。
|
|
@@ -1090,7 +1090,7 @@ SHA-256)。`--format html` 把同样的内容写成一个自包含
|
|
|
1090
1090
|
|
|
1091
1091
|
| 你看到的 | 含义 | 怎么办 |
|
|
1092
1092
|
| --- | --- | --- |
|
|
1093
|
-
| `superagent_*` 工具不存在 | bundle 行没挂上,或者宿主拒绝加载插件。 | 跑 `--dump-config` 查 `@xiangyixie/dsh-superagent` 块;用 `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.
|
|
1093
|
+
| `superagent_*` 工具不存在 | bundle 行没挂上,或者宿主拒绝加载插件。 | 跑 `--dump-config` 查 `@xiangyixie/dsh-superagent` 块;用 `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.17.1` 重装,并在宿主日志里找 `[dsh-superagent]` 行。 |
|
|
1094
1094
|
| `Cannot find module .../lib/control.js`(或 `watch.js` / `report.js` / `wizard.js`),或宿主日志里的 `[dsh-superagent] dsh-superagent failed to load because a file it imports is missing: ...` | 那个 profile 里的副本不完整——被中断的 `add` 会留下残缺的解包结果。0.14.3 起的入口会直接点名缺哪个文件。已发布的包不是原因:每个版本都带全部三十四个 `lib/` 文件。 | 删掉 profile 的 `node_modules` 下该插件的目录(带 scope 的 `@xiangyixie/dsh-superagent`,或旧 tarball 安装留下的无 scope 的 `dsh-superagent`),再用同一条 `add` 命令重装,并带上版本号。不要手工拷贝文件进去。 |
|
|
1095
1095
|
| `[error] the model provider rejected the API key` | 启动宿主的那个进程里缺 key 环境变量。 | 导出 `DEEPSEEK_API_KEY`(默认路由)或你那条路由声明的变量,然后重启 `dsh`。 |
|
|
1096
1096
|
| `MISSING_CREDENTIAL ... no API key for provider route "..."` | profile 的路由在环境里没有凭据。 | 设置该路由对应的环境变量并重启。错误行里写了路由名,以它为准,不要照本文。 |
|
package/README.zh.md
CHANGED
|
@@ -36,12 +36,12 @@ dsh-superagent 把这件事接过去:你说一句目标,它负责拆、负
|
|
|
36
36
|
|
|
37
37
|
### 1. 装
|
|
38
38
|
|
|
39
|
-
桌面端:侧边栏 **插件** → **Add plugin** → 输入 `@xiangyixie/dsh-superagent@0.
|
|
39
|
+
桌面端:侧边栏 **插件** → **Add plugin** → 输入 `@xiangyixie/dsh-superagent@0.17.1` → 安装。
|
|
40
40
|
|
|
41
41
|
命令行:
|
|
42
42
|
|
|
43
43
|
```bash
|
|
44
|
-
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.
|
|
44
|
+
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.17.1
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
装完**重启 DSH**(插件只在宿主启动时加载一次)。也可以从「发现」页添加[插件索引](https://raw.githubusercontent.com/LittleChenLiya/dsh-superagent/main/plugin-index.json)一键安装;升级一律先 `remove` 再 `add`。
|
|
@@ -1090,7 +1090,7 @@ SHA-256)。`--format html` 把同样的内容写成一个自包含
|
|
|
1090
1090
|
|
|
1091
1091
|
| 你看到的 | 含义 | 怎么办 |
|
|
1092
1092
|
| --- | --- | --- |
|
|
1093
|
-
| `superagent_*` 工具不存在 | bundle 行没挂上,或者宿主拒绝加载插件。 | 跑 `--dump-config` 查 `@xiangyixie/dsh-superagent` 块;用 `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.
|
|
1093
|
+
| `superagent_*` 工具不存在 | bundle 行没挂上,或者宿主拒绝加载插件。 | 跑 `--dump-config` 查 `@xiangyixie/dsh-superagent` 块;用 `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.17.1` 重装,并在宿主日志里找 `[dsh-superagent]` 行。 |
|
|
1094
1094
|
| `Cannot find module .../lib/control.js`(或 `watch.js` / `report.js` / `wizard.js`),或宿主日志里的 `[dsh-superagent] dsh-superagent failed to load because a file it imports is missing: ...` | 那个 profile 里的副本不完整——被中断的 `add` 会留下残缺的解包结果。0.14.3 起的入口会直接点名缺哪个文件。已发布的包不是原因:每个版本都带全部三十四个 `lib/` 文件。 | 删掉 profile 的 `node_modules` 下该插件的目录(带 scope 的 `@xiangyixie/dsh-superagent`,或旧 tarball 安装留下的无 scope 的 `dsh-superagent`),再用同一条 `add` 命令重装,并带上版本号。不要手工拷贝文件进去。 |
|
|
1095
1095
|
| `[error] the model provider rejected the API key` | 启动宿主的那个进程里缺 key 环境变量。 | 导出 `DEEPSEEK_API_KEY`(默认路由)或你那条路由声明的变量,然后重启 `dsh`。 |
|
|
1096
1096
|
| `MISSING_CREDENTIAL ... no API key for provider route "..."` | profile 的路由在环境里没有凭据。 | 设置该路由对应的环境变量并重启。错误行里写了路由名,以它为准,不要照本文。 |
|
package/lib/client.js
CHANGED
|
@@ -167,7 +167,7 @@ window.__ModuleLoader__.load({
|
|
|
167
167
|
.dsa-crumb-current{font-weight:500;color:var(--dsw-alias-label-primary,#f9fafb)}
|
|
168
168
|
.dsa-sep{color:var(--dsw-alias-label-caption,rgb(129,133,140));font-size:14px;line-height:20px}
|
|
169
169
|
.dsa-head-actions{display:flex;flex:none;align-items:center;gap:8px;margin-left:20px}
|
|
170
|
-
.dsa-iconbtn{display:inline-flex;flex:none;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:0;border-radius:var(--dsw-radius-sm,8px);background:transparent;color:var(--dsw-alias-label-secondary,rgb(207,211,214));cursor:pointer}
|
|
170
|
+
.dsa-iconbtn{position:relative;display:inline-flex;flex:none;align-items:center;justify-content:center;width:28px;height:28px;padding:0;border:0;border-radius:var(--dsw-radius-sm,8px);background:transparent;color:var(--dsw-alias-label-secondary,rgb(207,211,214));cursor:pointer}
|
|
171
171
|
.dsa-iconbtn svg{width:15px;height:15px}
|
|
172
172
|
.dsa-iconbtn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08))}
|
|
173
173
|
.dsa-iconbtn:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-alias-state-business-primary,#7aaaff);outline-offset:-2px}
|
|
@@ -244,6 +244,37 @@ window.__ModuleLoader__.load({
|
|
|
244
244
|
.dsa-hint{font-size:12px;line-height:18px;color:var(--dsw-alias-label-caption,rgb(129,133,140))}
|
|
245
245
|
.dsa-toast{display:flex;align-items:center;gap:8px;margin:8px auto 0;width:min(calc(100% - 64px),var(--dsa-col));padding:6px 10px;border-radius:var(--dsw-radius-md,12px);background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08));color:var(--dsw-alias-label-secondary,rgb(207,211,214));font-size:12px;line-height:18px}
|
|
246
246
|
.dsa-toast[data-kind=err]{color:var(--dsw-alias-state-error-primary,#f25a5a)}
|
|
247
|
+
.dsa-sessions{position:absolute;top:64px;right:20px;z-index:30;display:flex;flex-direction:column;width:300px;max-height:min(60vh,440px);padding:8px;border:1px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12));border-radius:var(--dsw-radius-lg,16px);background:var(--dsw-alias-bg-base,rgb(21,21,23));box-shadow:var(--dsw-shadow-lv2,0 8px 28px rgba(0,0,0,.32))}
|
|
248
|
+
.dsa-sessions-head{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:4px 6px 8px;font-size:13px;line-height:20px;color:var(--dsw-alias-label-tertiary,rgb(129,133,140))}
|
|
249
|
+
.dsa-sessions-new,.dsa-linkbtn{border:0;background:transparent;color:var(--dsw-alias-state-business-primary,#7aaaff);font:inherit;font-size:12px;line-height:18px;cursor:pointer;padding:2px 6px;border-radius:var(--dsw-radius-sm,8px)}
|
|
250
|
+
.dsa-sessions-new:hover,.dsa-linkbtn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08))}
|
|
251
|
+
.dsa-sessions-list{display:flex;flex-direction:column;gap:2px;min-height:0;overflow-y:auto}
|
|
252
|
+
.dsa-session-row{height:40px;gap:8px;cursor:pointer}
|
|
253
|
+
.dsa-session-row[data-current=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08))}
|
|
254
|
+
.dsa-session-title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px}
|
|
255
|
+
.dsa-session-meta{flex:none;font-size:10px;line-height:16px;color:var(--dsw-alias-label-tertiary,rgb(129,133,140))}
|
|
256
|
+
.dsa-sessions-foot{display:flex;justify-content:flex-end;padding-top:6px}
|
|
257
|
+
.dsa-detail{position:absolute;inset:0;z-index:20;display:flex;flex-direction:column;background:var(--dsw-alias-bg-base,rgb(21,21,23))}
|
|
258
|
+
.dsa-detail-head{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:10px 16px;border-bottom:.5px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12))}
|
|
259
|
+
.dsa-detail-title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;font-weight:500}
|
|
260
|
+
.dsa-detail-body{flex:1;min-height:0;overflow-y:auto;padding:12px 16px;display:flex;flex-direction:column;gap:12px}
|
|
261
|
+
.dsa-detail-sec{display:flex;flex-direction:column;gap:6px}
|
|
262
|
+
.dsa-detail-label{font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary,rgb(129,133,140))}
|
|
263
|
+
.dsa-detail-item{display:flex;flex-direction:column;gap:4px;padding:8px 10px;border-radius:var(--dsw-radius-md,12px);background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}
|
|
264
|
+
.dsa-detail-q{font-size:13px;line-height:20px;color:var(--dsw-alias-label-primary,#f9fafb);white-space:pre-wrap}
|
|
265
|
+
.dsa-answer-row{display:flex;gap:6px}
|
|
266
|
+
.dsa-answer-input{flex:1;min-width:0;box-sizing:border-box;padding:5px 8px;border:1px solid var(--dsw-alias-border-l3,rgba(255,255,255,.16));border-radius:var(--dsw-radius-sm,8px);background:transparent;color:var(--dsw-alias-label-primary,#f9fafb);font:inherit;font-size:12px;outline:none}
|
|
267
|
+
.dsa-artifact-link{display:flex;align-items:center;gap:6px;width:100%;padding:5px 8px;border:0;border-radius:var(--dsw-radius-sm,8px);background:transparent;color:var(--dsw-alias-state-business-primary,#7aaaff);font:inherit;font-size:12px;text-align:left;cursor:pointer}
|
|
268
|
+
.dsa-artifact-link:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08))}
|
|
269
|
+
.dsa-attention{display:flex;flex-direction:column;gap:8px;margin:8px 0}
|
|
270
|
+
.dsa-attention-card{display:flex;flex-direction:column;gap:8px;padding:12px 14px;border:1px solid var(--dsw-alias-state-warning-primary,rgba(255,193,64,.45));border-radius:var(--dsw-radius-lg,16px);background:var(--dsw-alias-bg-base,rgb(21,21,23))}
|
|
271
|
+
.dsa-attention-head{display:flex;align-items:center;gap:6px;font-size:12px;line-height:18px;color:var(--dsw-alias-state-warning-primary,#ffc140)}
|
|
272
|
+
.dsa-attention-dot{width:7px;height:7px;border-radius:50%;background:var(--dsw-alias-state-warning-primary,#ffc140)}
|
|
273
|
+
.dsa-attention-options{display:flex;flex-wrap:wrap;gap:6px}
|
|
274
|
+
.dsa-artifact-row{display:flex;align-items:center;gap:4px}
|
|
275
|
+
.dsa-artifact-row .dsa-artifact-link{flex:1;min-width:0;overflow:hidden}
|
|
276
|
+
.dsa-chip{padding:3px 10px;border:1px solid var(--dsw-alias-border-l3,rgba(255,255,255,.16));border-radius:999px;background:transparent;color:var(--dsw-alias-label-primary,#f9fafb);font:inherit;font-size:12px;line-height:18px;cursor:pointer}
|
|
277
|
+
.dsa-chip:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08))}
|
|
247
278
|
`
|
|
248
279
|
|
|
249
280
|
/** Inject the sheet once; the panel is mounted once per window. */
|
|
@@ -319,6 +350,16 @@ window.__ModuleLoader__.load({
|
|
|
319
350
|
typing: false,
|
|
320
351
|
sending: false,
|
|
321
352
|
currentId: null,
|
|
353
|
+
sessions: [],
|
|
354
|
+
sessionsOpen: false,
|
|
355
|
+
sessionsBusy: false,
|
|
356
|
+
detail: null,
|
|
357
|
+
detailBusy: false,
|
|
358
|
+
answerDraft: '',
|
|
359
|
+
uploadInsert: '',
|
|
360
|
+
uploading: false,
|
|
361
|
+
unread: 0,
|
|
362
|
+
seenAttention: [],
|
|
322
363
|
}
|
|
323
364
|
}
|
|
324
365
|
|
|
@@ -495,7 +536,19 @@ window.__ModuleLoader__.load({
|
|
|
495
536
|
return { ...model, sessionId: frame.sessionId ?? model.sessionId, capabilities: frame.capabilities ?? model.capabilities }
|
|
496
537
|
case 'session':
|
|
497
538
|
if (!frame.sessionId || frame.sessionId === model.sessionId) return model
|
|
498
|
-
return {
|
|
539
|
+
return {
|
|
540
|
+
...model,
|
|
541
|
+
sessionId: frame.sessionId,
|
|
542
|
+
messages: [],
|
|
543
|
+
approvals: [],
|
|
544
|
+
approvalBusy: {},
|
|
545
|
+
currentId: null,
|
|
546
|
+
typing: false,
|
|
547
|
+
canceling: false,
|
|
548
|
+
sessionsOpen: false,
|
|
549
|
+
detail: null,
|
|
550
|
+
answerDraft: '',
|
|
551
|
+
}
|
|
499
552
|
case 'stream.snapshot': {
|
|
500
553
|
let next = { ...model, messages: [], currentId: null }
|
|
501
554
|
if (frame.header?.id) next.sessionId = frame.header.id
|
|
@@ -520,15 +573,31 @@ window.__ModuleLoader__.load({
|
|
|
520
573
|
const approval = frame.approval
|
|
521
574
|
if (frame.action === 'asked' && approval?.id) {
|
|
522
575
|
const others = model.approvals.filter(entry => entry.id !== approval.id)
|
|
523
|
-
return { ...model, approvals: [...others, approval] }
|
|
576
|
+
return { ...model, approvals: [...others, approval], unread: (model.unread ?? 0) + 1 }
|
|
524
577
|
}
|
|
525
578
|
if (frame.id) {
|
|
526
579
|
return { ...model, approvals: model.approvals.filter(entry => entry.id !== frame.id) }
|
|
527
580
|
}
|
|
528
581
|
return model
|
|
529
582
|
}
|
|
530
|
-
case 'runs':
|
|
531
|
-
|
|
583
|
+
case 'runs': {
|
|
584
|
+
const runs = Array.isArray(frame.runs) ? frame.runs : []
|
|
585
|
+
const detail = model.detail ? runs.find(run => run.id === model.detail.id) ?? model.detail : null
|
|
586
|
+
const seen = Array.isArray(model.seenAttention) ? model.seenAttention : []
|
|
587
|
+
const fresh = []
|
|
588
|
+
for (const run of runs) {
|
|
589
|
+
for (const item of Array.isArray(run.attention) ? run.attention : []) {
|
|
590
|
+
if (item?.id && !seen.includes(item.id) && !fresh.includes(item.id)) fresh.push(item.id)
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return {
|
|
594
|
+
...model,
|
|
595
|
+
runs,
|
|
596
|
+
detail,
|
|
597
|
+
unread: model.unread + fresh.length,
|
|
598
|
+
seenAttention: fresh.length > 0 ? [...seen, ...fresh].slice(-200) : seen,
|
|
599
|
+
}
|
|
600
|
+
}
|
|
532
601
|
case 'canceling':
|
|
533
602
|
return { ...model, canceling: true }
|
|
534
603
|
default:
|
|
@@ -537,12 +606,20 @@ window.__ModuleLoader__.load({
|
|
|
537
606
|
}
|
|
538
607
|
|
|
539
608
|
function Header(props) {
|
|
540
|
-
const { railOpen, runningCount, onToggleRail } = props
|
|
609
|
+
const { railOpen, runningCount, onToggleRail, onToggleSessions, sessionsOpen, unread } = props
|
|
541
610
|
const toggleLabel = railOpen ? '收起任务栏(Ctrl+Shift+B)' : '展开任务栏(Ctrl+Shift+B)'
|
|
542
611
|
return h('header', { className: 'dsa-header' },
|
|
543
612
|
h('div', { className: 'dsa-crumbs' },
|
|
544
613
|
h('span', { className: 'dsa-crumb dsa-crumb-current' }, PANEL_LABEL)),
|
|
545
614
|
h('div', { className: 'dsa-head-actions' },
|
|
615
|
+
tipped(unread > 0 ? `会话(${unread} 个新问题)` : '会话', h('button', {
|
|
616
|
+
type: 'button',
|
|
617
|
+
className: 'dsa-iconbtn',
|
|
618
|
+
'aria-label': '会话',
|
|
619
|
+
'aria-expanded': sessionsOpen ? 'true' : 'false',
|
|
620
|
+
onClick: onToggleSessions,
|
|
621
|
+
}, h(Icon, { of: 'clock' }),
|
|
622
|
+
unread > 0 ? h('span', { className: 'dsa-badge' }, unread > 9 ? '9+' : String(unread)) : null), 'bottom'),
|
|
546
623
|
tipped(toggleLabel, h('button', {
|
|
547
624
|
type: 'button',
|
|
548
625
|
className: 'dsa-iconbtn dsa-railtoggle',
|
|
@@ -662,6 +739,32 @@ window.__ModuleLoader__.load({
|
|
|
662
739
|
const { hero, disabled, onSend } = props
|
|
663
740
|
const [text, setText] = react.useState('')
|
|
664
741
|
const areaRef = react.useRef(null)
|
|
742
|
+
const fileRef = react.useRef(null)
|
|
743
|
+
|
|
744
|
+
// An uploaded file lands as a path the user can see and edit before sending.
|
|
745
|
+
react.useEffect(() => {
|
|
746
|
+
if (!props.insert) return
|
|
747
|
+
setText(current => (current ? `${current}\n${props.insert}` : props.insert))
|
|
748
|
+
props.onInserted?.()
|
|
749
|
+
}, [props.insert])
|
|
750
|
+
|
|
751
|
+
const pickFile = () => {
|
|
752
|
+
const input = fileRef.current
|
|
753
|
+
if (!input) return
|
|
754
|
+
input.value = ''
|
|
755
|
+
input.click()
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
const uploadFile = file => {
|
|
759
|
+
if (!file || !props.onUpload) return
|
|
760
|
+
const reader = new FileReader()
|
|
761
|
+
reader.onload = () => {
|
|
762
|
+
const data = String(reader.result ?? '').replace(/^data:[^,]*,/, '')
|
|
763
|
+
props.onUpload({ name: file.name, data })
|
|
764
|
+
}
|
|
765
|
+
reader.onerror = () => props.onUpload({ name: file.name, data: '', error: '文件读不出来' })
|
|
766
|
+
reader.readAsDataURL(file)
|
|
767
|
+
}
|
|
665
768
|
|
|
666
769
|
const grow = () => {
|
|
667
770
|
const area = areaRef.current
|
|
@@ -699,6 +802,19 @@ window.__ModuleLoader__.load({
|
|
|
699
802
|
},
|
|
700
803
|
}),
|
|
701
804
|
h('div', { className: 'dsa-row' },
|
|
805
|
+
h('input', {
|
|
806
|
+
ref: fileRef,
|
|
807
|
+
type: 'file',
|
|
808
|
+
style: { display: 'none' },
|
|
809
|
+
onChange: event => uploadFile(event.target.files?.[0]),
|
|
810
|
+
}),
|
|
811
|
+
tipped('添加文件到工作区', h('button', {
|
|
812
|
+
type: 'button',
|
|
813
|
+
className: 'dsa-add',
|
|
814
|
+
'aria-label': '添加文件',
|
|
815
|
+
disabled: disabled || props.uploading === true,
|
|
816
|
+
onClick: pickFile,
|
|
817
|
+
}, props.uploading === true ? h('span', { className: 'dsa-spin' }) : '+'), 'top'),
|
|
702
818
|
h('div', { className: 'dsa-trailing' },
|
|
703
819
|
props.running
|
|
704
820
|
? tipped('停止本轮', h('button', {
|
|
@@ -736,15 +852,197 @@ window.__ModuleLoader__.load({
|
|
|
736
852
|
h('div', { className: 'dsa-rail-list' },
|
|
737
853
|
runs.length === 0
|
|
738
854
|
? h('div', { className: 'dsa-hint', style: { padding: '8px' } }, '超级智能体还没有调度新的会话')
|
|
739
|
-
: runs.map(run => tipped(run.goal ?? '', h('
|
|
855
|
+
: runs.map(run => tipped(run.goal ?? '', h('button', {
|
|
740
856
|
key: run.id,
|
|
857
|
+
type: 'button',
|
|
741
858
|
className: 'dsa-rowitem',
|
|
859
|
+
title: '查看任务详情',
|
|
860
|
+
onClick: () => props.onOpen?.(run.id),
|
|
742
861
|
},
|
|
743
862
|
h('span', { className: 'dsa-rowdot', 'data-status': run.status }),
|
|
744
863
|
h('span', { className: 'dsa-rowtitle' }, run.goal ?? '调度中的会话'),
|
|
745
864
|
h('span', { className: 'dsa-rowtime' }, run.status === 'running' ? '运行中' : run.status === 'completed' ? '完成' : '已停')), 'left', run.id))))
|
|
746
865
|
}
|
|
747
866
|
|
|
867
|
+
/** Artifacts are whatever the run report links to, same rule as the console page. */
|
|
868
|
+
function artifactsOf(run) {
|
|
869
|
+
const report = typeof run?.report === 'string' ? run.report : ''
|
|
870
|
+
const found = []
|
|
871
|
+
const pattern = /\[([^\]\n]{1,80})\]\(<?([^)>\n]+)>?\)/g
|
|
872
|
+
let match = pattern.exec(report)
|
|
873
|
+
while (match) {
|
|
874
|
+
const href = match[2].trim()
|
|
875
|
+
if (href && !/^[a-z][a-z0-9+.-]*:\/\//i.test(href) && !href.startsWith('#')) {
|
|
876
|
+
if (!found.some(item => item.href === href)) found.push({ name: match[1].trim(), href, runId: run.id })
|
|
877
|
+
}
|
|
878
|
+
if (found.length >= 20) break
|
|
879
|
+
match = pattern.exec(report)
|
|
880
|
+
}
|
|
881
|
+
return found
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/** History and the "new conversation" entry, opened from the title bar. */
|
|
885
|
+
function SessionsPanel(props) {
|
|
886
|
+
const { model } = props
|
|
887
|
+
if (!model.sessionsOpen) return null
|
|
888
|
+
const sessions = Array.isArray(model.sessions) ? model.sessions : []
|
|
889
|
+
const busy = model.sessionsBusy === true
|
|
890
|
+
return h('div', { className: 'dsa-sessions', role: 'dialog', 'aria-label': '会话' },
|
|
891
|
+
h('div', { className: 'dsa-sessions-head' },
|
|
892
|
+
h('span', null, '会话'),
|
|
893
|
+
h('button', {
|
|
894
|
+
type: 'button',
|
|
895
|
+
className: 'dsa-sessions-new',
|
|
896
|
+
disabled: busy,
|
|
897
|
+
onClick: () => props.onNew?.(),
|
|
898
|
+
}, '新对话')),
|
|
899
|
+
h('div', { className: 'dsa-sessions-list' },
|
|
900
|
+
sessions.length === 0
|
|
901
|
+
? h('div', { className: 'dsa-hint', style: { padding: '8px' } }, '还没有历史会话')
|
|
902
|
+
: sessions.map(item => h('button', {
|
|
903
|
+
key: item.sessionId,
|
|
904
|
+
type: 'button',
|
|
905
|
+
className: 'dsa-rowitem dsa-session-row',
|
|
906
|
+
'data-current': item.sessionId === model.sessionId ? 'true' : 'false',
|
|
907
|
+
disabled: busy,
|
|
908
|
+
onClick: () => props.onSwitch?.(item.sessionId),
|
|
909
|
+
},
|
|
910
|
+
h('span', { className: 'dsa-session-title' }, item.title || item.first || item.sessionId.slice(0, 12)),
|
|
911
|
+
h('span', { className: 'dsa-session-meta' }, `${item.runs ?? 0} 轮`)))),
|
|
912
|
+
h('div', { className: 'dsa-sessions-foot' },
|
|
913
|
+
h('button', { type: 'button', className: 'dsa-linkbtn', onClick: () => props.onClose?.() }, '关闭')))
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/** One delegated run: status, questions waiting for the user, artifacts. */
|
|
917
|
+
function RunDetail(props) {
|
|
918
|
+
const { model } = props
|
|
919
|
+
const run = model.detail
|
|
920
|
+
if (!run) return null
|
|
921
|
+
const attention = Array.isArray(run.attention) ? run.attention : []
|
|
922
|
+
const artifacts = artifactsOf(run)
|
|
923
|
+
const busy = model.detailBusy === true
|
|
924
|
+
return h('div', { className: 'dsa-detail', role: 'dialog', 'aria-label': '任务详情' },
|
|
925
|
+
h('div', { className: 'dsa-detail-head' },
|
|
926
|
+
h('span', { className: 'dsa-detail-title' }, run.goal ?? '任务详情'),
|
|
927
|
+
h('button', {
|
|
928
|
+
type: 'button',
|
|
929
|
+
className: 'dsa-linkbtn',
|
|
930
|
+
onClick: () => props.onCancelRun?.(run.id),
|
|
931
|
+
}, run.status === 'running' ? '停止' : '已停'),
|
|
932
|
+
h('button', { type: 'button', className: 'dsa-linkbtn', onClick: () => props.onClose?.() }, '关闭')),
|
|
933
|
+
h('div', { className: 'dsa-detail-body' },
|
|
934
|
+
h('div', { className: 'dsa-detail-sec' },
|
|
935
|
+
h('div', { className: 'dsa-detail-label' }, '状态'),
|
|
936
|
+
h('div', { className: 'dsa-detail-q' }, `${run.status ?? '未知'}${run.startedAt ? ` · ${run.startedAt}` : ''}`)),
|
|
937
|
+
attention.length > 0
|
|
938
|
+
? h('div', { className: 'dsa-detail-sec' },
|
|
939
|
+
h('div', { className: 'dsa-detail-label' }, '等你决定'),
|
|
940
|
+
attention.map(item => h('div', { key: item.id, className: 'dsa-detail-item' },
|
|
941
|
+
h('div', { className: 'dsa-detail-q' }, item.question ?? '有一个问题需要你回答'),
|
|
942
|
+
h('div', { className: 'dsa-answer-row' },
|
|
943
|
+
h('input', {
|
|
944
|
+
className: 'dsa-answer-input',
|
|
945
|
+
value: model.answerDraft,
|
|
946
|
+
placeholder: '写下你的回答',
|
|
947
|
+
onInput: event => props.onDraft?.(event.target.value),
|
|
948
|
+
onKeyDown: event => {
|
|
949
|
+
if (event.key === 'Enter' && !event.nativeEvent?.isComposing) {
|
|
950
|
+
event.preventDefault()
|
|
951
|
+
props.onAnswer?.(run.id, item.id, model.answerDraft)
|
|
952
|
+
}
|
|
953
|
+
},
|
|
954
|
+
}),
|
|
955
|
+
h(Button ?? 'button', {
|
|
956
|
+
variant: Button ? 'primary' : undefined,
|
|
957
|
+
type: Button ? undefined : 'button',
|
|
958
|
+
disabled: busy || !String(model.answerDraft ?? '').trim(),
|
|
959
|
+
onClick: () => props.onAnswer?.(run.id, item.id, model.answerDraft),
|
|
960
|
+
}, '回答')))))
|
|
961
|
+
: null,
|
|
962
|
+
artifacts.length > 0
|
|
963
|
+
? h('div', { className: 'dsa-detail-sec' },
|
|
964
|
+
h('div', { className: 'dsa-detail-label' }, '产物'),
|
|
965
|
+
artifacts.map(item => h('div', { key: item.href, className: 'dsa-artifact-row' },
|
|
966
|
+
h('button', {
|
|
967
|
+
type: 'button',
|
|
968
|
+
className: 'dsa-artifact-link',
|
|
969
|
+
onClick: () => props.onArtifact?.(item),
|
|
970
|
+
}, item.name),
|
|
971
|
+
h('button', {
|
|
972
|
+
type: 'button',
|
|
973
|
+
className: 'dsa-linkbtn',
|
|
974
|
+
onClick: () => props.onReveal?.(item),
|
|
975
|
+
}, '在文件夹中显示'),
|
|
976
|
+
h('button', {
|
|
977
|
+
type: 'button',
|
|
978
|
+
className: 'dsa-linkbtn',
|
|
979
|
+
onClick: () => props.onDownload?.(item),
|
|
980
|
+
}, '下载'))))
|
|
981
|
+
: h('div', { className: 'dsa-detail-sec' },
|
|
982
|
+
h('div', { className: 'dsa-detail-label' }, '产物'),
|
|
983
|
+
h('div', { className: 'dsa-hint' }, '这条任务还没有报告产物')),
|
|
984
|
+
run.report
|
|
985
|
+
? h('div', { className: 'dsa-detail-sec' },
|
|
986
|
+
h('div', { className: 'dsa-detail-label' }, '报告'),
|
|
987
|
+
h('div', { className: 'dsa-md-plain' }, run.report))
|
|
988
|
+
: null))
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Questions that block a run, shown where the user is already typing.
|
|
993
|
+
* A plan confirmation is the same shape with options, so it renders as
|
|
994
|
+
* one-tap chips instead of a yes/no dialog of its own.
|
|
995
|
+
*/
|
|
996
|
+
function AttentionCards(props) {
|
|
997
|
+
const { model } = props
|
|
998
|
+
const entries = []
|
|
999
|
+
for (const run of Array.isArray(model.runs) ? model.runs : []) {
|
|
1000
|
+
for (const item of Array.isArray(run.attention) ? run.attention : []) {
|
|
1001
|
+
if (item?.id) entries.push({ run, item })
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
if (entries.length === 0) return null
|
|
1005
|
+
return h('div', { className: 'dsa-attention' },
|
|
1006
|
+
entries.map(({ run, item }) => {
|
|
1007
|
+
const options = Array.isArray(item.options) ? item.options : []
|
|
1008
|
+
return h('div', { key: `${run.id}:${item.id}`, className: 'dsa-attention-card' },
|
|
1009
|
+
h('div', { className: 'dsa-attention-head' },
|
|
1010
|
+
h('span', { className: 'dsa-attention-dot' }),
|
|
1011
|
+
h('span', null, item.source === 'plan' ? '计划确认' : '等你决定'),
|
|
1012
|
+
h('span', { className: 'dsa-session-meta' }, run.goal ?? '')),
|
|
1013
|
+
h('div', { className: 'dsa-detail-q' }, item.question ?? '有一个问题需要你回答'),
|
|
1014
|
+
item.reason ? h('div', { className: 'dsa-detail-label' }, item.reason) : null,
|
|
1015
|
+
h('div', { className: 'dsa-answer-row' },
|
|
1016
|
+
h('input', {
|
|
1017
|
+
className: 'dsa-answer-input',
|
|
1018
|
+
value: model.answerDraft,
|
|
1019
|
+
placeholder: options.length > 0 ? '或者直接写别的回答' : '写下你的回答',
|
|
1020
|
+
onInput: event => props.onDraft?.(event.target.value),
|
|
1021
|
+
onKeyDown: event => {
|
|
1022
|
+
if (event.key === 'Enter' && !event.nativeEvent?.isComposing) {
|
|
1023
|
+
event.preventDefault()
|
|
1024
|
+
props.onAnswer?.(run.id, item.id, model.answerDraft)
|
|
1025
|
+
}
|
|
1026
|
+
},
|
|
1027
|
+
}),
|
|
1028
|
+
h(Button ?? 'button', {
|
|
1029
|
+
variant: Button ? 'primary' : undefined,
|
|
1030
|
+
type: Button ? undefined : 'button',
|
|
1031
|
+
disabled: !String(model.answerDraft ?? '').trim(),
|
|
1032
|
+
onClick: () => props.onAnswer?.(run.id, item.id, model.answerDraft),
|
|
1033
|
+
}, '回答')),
|
|
1034
|
+
options.length > 0
|
|
1035
|
+
? h('div', { className: 'dsa-attention-options' },
|
|
1036
|
+
options.map(option => h('button', {
|
|
1037
|
+
key: option,
|
|
1038
|
+
type: 'button',
|
|
1039
|
+
className: 'dsa-chip',
|
|
1040
|
+
onClick: () => props.onAnswer?.(run.id, item.id, option),
|
|
1041
|
+
}, option)))
|
|
1042
|
+
: null)
|
|
1043
|
+
}))
|
|
1044
|
+
}
|
|
1045
|
+
|
|
748
1046
|
function Hero(props) {
|
|
749
1047
|
const ready = props.model.capabilities?.chat !== false
|
|
750
1048
|
return h('div', { className: 'dsa-hero' },
|
|
@@ -813,7 +1111,16 @@ window.__ModuleLoader__.load({
|
|
|
813
1111
|
h(Header, {
|
|
814
1112
|
railOpen,
|
|
815
1113
|
runningCount,
|
|
1114
|
+
unread: model.unread ?? 0,
|
|
1115
|
+
sessionsOpen: model.sessionsOpen === true,
|
|
816
1116
|
onToggleRail: toggleRail,
|
|
1117
|
+
onToggleSessions: () => dispatch({ type: 'sessions' }),
|
|
1118
|
+
}),
|
|
1119
|
+
h(SessionsPanel, {
|
|
1120
|
+
model,
|
|
1121
|
+
onNew: () => dispatch({ type: 'newSession' }),
|
|
1122
|
+
onSwitch: sessionId => dispatch({ type: 'switchSession', sessionId }),
|
|
1123
|
+
onClose: () => dispatch({ type: 'sessions', open: false }),
|
|
817
1124
|
}),
|
|
818
1125
|
h(Toast, { toast: model.toast }),
|
|
819
1126
|
h('div', { className: 'dsa-body', 'data-rail': railOpen ? 'open' : 'closed' },
|
|
@@ -824,6 +1131,10 @@ window.__ModuleLoader__.load({
|
|
|
824
1131
|
disabled: model.sending,
|
|
825
1132
|
running: model.typing,
|
|
826
1133
|
canceling: model.canceling,
|
|
1134
|
+
insert: model.uploadInsert,
|
|
1135
|
+
uploading: model.uploading === true,
|
|
1136
|
+
onInserted: () => dispatch({ type: 'inserted' }),
|
|
1137
|
+
onUpload: file => dispatch({ type: 'upload', file }),
|
|
827
1138
|
onStop: () => dispatch({ type: 'cancel' }),
|
|
828
1139
|
onSend: text => dispatch({ type: 'send', text }),
|
|
829
1140
|
})
|
|
@@ -833,15 +1144,34 @@ window.__ModuleLoader__.load({
|
|
|
833
1144
|
busy: model.approvalBusy,
|
|
834
1145
|
onDecide: (id, decision) => dispatch({ type: 'decide', id, decision }),
|
|
835
1146
|
}),
|
|
1147
|
+
h(AttentionCards, {
|
|
1148
|
+
model,
|
|
1149
|
+
onDraft: value => dispatch({ type: 'draft', value }),
|
|
1150
|
+
onAnswer: (runId, attentionId, answer) => dispatch({ type: 'answer', runId, attentionId, answer }),
|
|
1151
|
+
}),
|
|
836
1152
|
empty ? null : h(Composer, {
|
|
837
1153
|
model,
|
|
838
1154
|
disabled: model.sending || model.capabilities?.chat === false,
|
|
839
1155
|
running: model.typing,
|
|
840
1156
|
canceling: model.canceling,
|
|
1157
|
+
insert: model.uploadInsert,
|
|
1158
|
+
uploading: model.uploading === true,
|
|
1159
|
+
onInserted: () => dispatch({ type: 'inserted' }),
|
|
1160
|
+
onUpload: file => dispatch({ type: 'upload', file }),
|
|
841
1161
|
onStop: () => dispatch({ type: 'cancel' }),
|
|
842
1162
|
onSend: text => dispatch({ type: 'send', text }),
|
|
1163
|
+
}),
|
|
1164
|
+
h(RunDetail, {
|
|
1165
|
+
model,
|
|
1166
|
+
onClose: () => dispatch({ type: 'closeRun' }),
|
|
1167
|
+
onCancelRun: runId => dispatch({ type: 'cancelRun', runId }),
|
|
1168
|
+
onDraft: value => dispatch({ type: 'draft', value }),
|
|
1169
|
+
onAnswer: (runId, attentionId, answer) => dispatch({ type: 'answer', runId, attentionId, answer }),
|
|
1170
|
+
onArtifact: item => dispatch({ type: 'artifact', item }),
|
|
1171
|
+
onReveal: item => dispatch({ type: 'revealArtifact', item }),
|
|
1172
|
+
onDownload: item => dispatch({ type: 'downloadArtifact', item }),
|
|
843
1173
|
})),
|
|
844
|
-
h(Rail, { model })))
|
|
1174
|
+
h(Rail, { model, onOpen: runId => dispatch({ type: 'openRun', runId }) })))
|
|
845
1175
|
}
|
|
846
1176
|
|
|
847
1177
|
/** One-line status above the composer; errors stay until replaced. */
|
|
@@ -968,13 +1298,131 @@ window.__ModuleLoader__.load({
|
|
|
968
1298
|
},
|
|
969
1299
|
cancel: async () => {
|
|
970
1300
|
patch(current => ({ ...current, canceling: true }))
|
|
1301
|
+
const running = (modelRef.current.runs ?? []).filter(run => run.status === 'running')
|
|
1302
|
+
const settled = await Promise.allSettled([
|
|
1303
|
+
call('/cancel', { method: 'POST', body: JSON.stringify({ sessionId: modelRef.current.sessionId }) }),
|
|
1304
|
+
...running.map(run => call(`/runs/${encodeURIComponent(run.id)}/cancel`, { method: 'POST' })),
|
|
1305
|
+
])
|
|
1306
|
+
if (settled.every(item => item.status === 'rejected')) {
|
|
1307
|
+
patch(current => ({ ...current, canceling: false }))
|
|
1308
|
+
throw settled[0].reason
|
|
1309
|
+
}
|
|
1310
|
+
patch(current => ({ ...current, canceling: false }))
|
|
1311
|
+
},
|
|
1312
|
+
sessions: async action => {
|
|
1313
|
+
const open = typeof action.open === 'boolean' ? action.open : modelRef.current.sessionsOpen !== true
|
|
1314
|
+
if (!open) {
|
|
1315
|
+
patch(current => ({ ...current, sessionsOpen: false }))
|
|
1316
|
+
return
|
|
1317
|
+
}
|
|
1318
|
+
patch(current => ({ ...current, sessionsOpen: true, sessionsBusy: true }))
|
|
1319
|
+
call('/notices/read', { method: 'POST', body: '{}' })
|
|
1320
|
+
.then(() => patch(current => ({ ...current, unread: 0 })))
|
|
1321
|
+
.catch(() => {})
|
|
971
1322
|
try {
|
|
972
|
-
await call('/
|
|
1323
|
+
const data = await call('/sessions')
|
|
1324
|
+
patch(current => ({
|
|
1325
|
+
...current,
|
|
1326
|
+
sessionsBusy: false,
|
|
1327
|
+
sessions: Array.isArray(data?.sessions) ? data.sessions : [],
|
|
1328
|
+
}))
|
|
973
1329
|
} catch (error) {
|
|
974
|
-
patch(current => ({ ...current,
|
|
1330
|
+
patch(current => ({ ...current, sessionsBusy: false }))
|
|
1331
|
+
throw error
|
|
1332
|
+
}
|
|
1333
|
+
},
|
|
1334
|
+
newSession: async () => {
|
|
1335
|
+
patch(current => ({ ...current, sessionsBusy: true }))
|
|
1336
|
+
try {
|
|
1337
|
+
await call('/session', { method: 'POST', body: '{}' })
|
|
1338
|
+
patch(current => ({ ...current, sessionsBusy: false, sessionsOpen: false }))
|
|
1339
|
+
} catch (error) {
|
|
1340
|
+
patch(current => ({ ...current, sessionsBusy: false }))
|
|
1341
|
+
throw error
|
|
1342
|
+
}
|
|
1343
|
+
},
|
|
1344
|
+
switchSession: async action => {
|
|
1345
|
+
patch(current => ({ ...current, sessionsBusy: true }))
|
|
1346
|
+
try {
|
|
1347
|
+
await call('/session/switch', { method: 'POST', body: JSON.stringify({ sessionId: action.sessionId }) })
|
|
1348
|
+
patch(current => ({ ...current, sessionsBusy: false, sessionsOpen: false }))
|
|
1349
|
+
} catch (error) {
|
|
1350
|
+
patch(current => ({ ...current, sessionsBusy: false }))
|
|
1351
|
+
throw error
|
|
1352
|
+
}
|
|
1353
|
+
},
|
|
1354
|
+
openRun: async action => {
|
|
1355
|
+
patch(current => ({ ...current, detailBusy: true }))
|
|
1356
|
+
try {
|
|
1357
|
+
const run = await call(`/runs/${encodeURIComponent(action.runId)}`)
|
|
1358
|
+
patch(current => ({ ...current, detail: run, detailBusy: false, answerDraft: '' }))
|
|
1359
|
+
} catch (error) {
|
|
1360
|
+
patch(current => ({ ...current, detailBusy: false }))
|
|
1361
|
+
throw error
|
|
1362
|
+
}
|
|
1363
|
+
},
|
|
1364
|
+
closeRun: () => patch(current => ({ ...current, detail: null, answerDraft: '' })),
|
|
1365
|
+
cancelRun: async action => {
|
|
1366
|
+
await call(`/runs/${encodeURIComponent(action.runId)}/cancel`, { method: 'POST' })
|
|
1367
|
+
patch(current => ({
|
|
1368
|
+
...current,
|
|
1369
|
+
detail: current.detail && current.detail.id === action.runId
|
|
1370
|
+
? { ...current.detail, status: 'cancelling' }
|
|
1371
|
+
: current.detail,
|
|
1372
|
+
}))
|
|
1373
|
+
},
|
|
1374
|
+
draft: action => patch(current => ({ ...current, answerDraft: String(action.value ?? '') })),
|
|
1375
|
+
answer: async action => {
|
|
1376
|
+
const answer = String(action.answer ?? '').trim()
|
|
1377
|
+
if (!answer) return
|
|
1378
|
+
await call('/answer', {
|
|
1379
|
+
method: 'POST',
|
|
1380
|
+
body: JSON.stringify({ runId: action.runId, attentionId: action.attentionId, answer }),
|
|
1381
|
+
})
|
|
1382
|
+
patch(current => ({
|
|
1383
|
+
...current,
|
|
1384
|
+
answerDraft: '',
|
|
1385
|
+
unread: Math.max(0, (current.unread ?? 0) - 1),
|
|
1386
|
+
detail: current.detail && current.detail.id === action.runId
|
|
1387
|
+
? {
|
|
1388
|
+
...current.detail,
|
|
1389
|
+
attention: (current.detail.attention ?? []).filter(item => item.id !== action.attentionId),
|
|
1390
|
+
}
|
|
1391
|
+
: current.detail,
|
|
1392
|
+
}))
|
|
1393
|
+
},
|
|
1394
|
+
artifact: action => {
|
|
1395
|
+
const item = action.item ?? {}
|
|
1396
|
+
const url = `${API}/artifact?path=${encodeURIComponent(item.href ?? '')}&runId=${encodeURIComponent(item.runId ?? '')}`
|
|
1397
|
+
if (typeof window !== 'undefined' && typeof window.open === 'function') window.open(url, '_blank', 'noopener')
|
|
1398
|
+
},
|
|
1399
|
+
revealArtifact: async action => {
|
|
1400
|
+
const item = action.item ?? {}
|
|
1401
|
+
const query = `?path=${encodeURIComponent(item.href ?? '')}&runId=${encodeURIComponent(item.runId ?? '')}`
|
|
1402
|
+
await call(`/artifact/reveal${query}`, { method: 'POST', body: '{}' })
|
|
1403
|
+
},
|
|
1404
|
+
downloadArtifact: action => {
|
|
1405
|
+
const item = action.item ?? {}
|
|
1406
|
+
const url = `${API}/artifact?download=1&path=${encodeURIComponent(item.href ?? '')}`
|
|
1407
|
+
+ `&runId=${encodeURIComponent(item.runId ?? '')}`
|
|
1408
|
+
if (typeof window !== 'undefined' && typeof window.open === 'function') window.open(url, '_blank', 'noopener')
|
|
1409
|
+
},
|
|
1410
|
+
upload: async action => {
|
|
1411
|
+
const file = action.file ?? {}
|
|
1412
|
+
if (file.error) throw new Error(file.error)
|
|
1413
|
+
patch(current => ({ ...current, uploading: true }))
|
|
1414
|
+
try {
|
|
1415
|
+
const data = await call('/upload', {
|
|
1416
|
+
method: 'POST',
|
|
1417
|
+
body: JSON.stringify({ name: file.name, data: file.data, sessionId: modelRef.current.sessionId }),
|
|
1418
|
+
})
|
|
1419
|
+
patch(current => ({ ...current, uploading: false, uploadInsert: data?.path ?? '' }))
|
|
1420
|
+
} catch (error) {
|
|
1421
|
+
patch(current => ({ ...current, uploading: false }))
|
|
975
1422
|
throw error
|
|
976
1423
|
}
|
|
977
1424
|
},
|
|
1425
|
+
inserted: () => patch(current => ({ ...current, uploadInsert: '' })),
|
|
978
1426
|
retry: () => {
|
|
979
1427
|
patch(current => ({ ...current, phase: 'loading', reason: '' }))
|
|
980
1428
|
setAttempt(value => value + 1)
|
package/lib/console.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* @module dsh-superagent/console
|
|
11
11
|
*/
|
|
12
12
|
import { randomBytes } from 'node:crypto'
|
|
13
|
+
import { spawn } from 'node:child_process'
|
|
13
14
|
import { readFileSync } from 'node:fs'
|
|
14
15
|
import fsp from 'node:fs/promises'
|
|
15
16
|
import { createServer, request } from 'node:http'
|
|
@@ -713,6 +714,7 @@ export function createConsole({
|
|
|
713
714
|
if (typeof sessionId !== 'string' || !sessionId) {
|
|
714
715
|
throw new WorkbenchError(502, 'the host created a session but returned no id', { id: 'session-create-failed' })
|
|
715
716
|
}
|
|
717
|
+
markPanel(sessionId)
|
|
716
718
|
if (currentSessionId !== sessionId) {
|
|
717
719
|
sessionAllowedTools.clear()
|
|
718
720
|
detach()
|
|
@@ -759,6 +761,7 @@ export function createConsole({
|
|
|
759
761
|
}
|
|
760
762
|
currentSessionId = target.sessionId
|
|
761
763
|
rememberedSessionId = target.sessionId
|
|
764
|
+
markPanel(target.sessionId)
|
|
762
765
|
sessionAllowedTools.clear()
|
|
763
766
|
detach()
|
|
764
767
|
resetStore(target.sessionId)
|
|
@@ -770,10 +773,22 @@ export function createConsole({
|
|
|
770
773
|
}
|
|
771
774
|
|
|
772
775
|
async function ensureSession() {
|
|
773
|
-
if (currentSessionId)
|
|
776
|
+
if (currentSessionId) {
|
|
777
|
+
markPanel(currentSessionId)
|
|
778
|
+
return { sessionId: currentSessionId, capabilities: capabilities() }
|
|
779
|
+
}
|
|
774
780
|
return createSession()
|
|
775
781
|
}
|
|
776
782
|
|
|
783
|
+
/** Tell the node half this session is driven from the panel, so its core tools stay on. */
|
|
784
|
+
function markPanel(sessionId) {
|
|
785
|
+
try {
|
|
786
|
+
host.markPanelSession?.(sessionId)
|
|
787
|
+
} catch {
|
|
788
|
+
// A host without the hook just keeps the previous tool list.
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
777
792
|
async function state() {
|
|
778
793
|
const caps = capabilities()
|
|
779
794
|
return {
|
|
@@ -873,14 +888,11 @@ export function createConsole({
|
|
|
873
888
|
clients.delete(res)
|
|
874
889
|
// With nobody watching there is no reason to keep the follow loop alive.
|
|
875
890
|
// The transcript stays cached so a reconnect can rebuild the page.
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
// closed page or a dropped stream never approves anything.
|
|
882
|
-
for (const entry of [...approvals.values()]) entry.settle('cancelled')
|
|
883
|
-
}
|
|
891
|
+
// Pending approvals deliberately survive this: closing or switching the
|
|
892
|
+
// panel must not answer them. They stay parked for the tool call and
|
|
893
|
+
// expire on their own deadline, so reopening the page still shows the
|
|
894
|
+
// question instead of a call that failed behind the user's back.
|
|
895
|
+
if (clients.size === 0) detach()
|
|
884
896
|
}
|
|
885
897
|
req.on('close', cleanup)
|
|
886
898
|
res.on('close', cleanup)
|
|
@@ -896,6 +908,42 @@ export function createConsole({
|
|
|
896
908
|
* @param {import('node:http').ServerResponse} res - response sink.
|
|
897
909
|
*/
|
|
898
910
|
async function serveArtifact(parsed, res) {
|
|
911
|
+
const { target } = await listedArtifact(parsed)
|
|
912
|
+
const download = parsed.searchParams.get('download') === '1'
|
|
913
|
+
const type = ARTIFACT_TYPES.get(path.extname(target).toLowerCase())
|
|
914
|
+
if (!type && !download) {
|
|
915
|
+
throw new WorkbenchError(415, 'this file type is not previewable in the console', { id: 'artifact-type' })
|
|
916
|
+
}
|
|
917
|
+
let stat
|
|
918
|
+
try {
|
|
919
|
+
stat = await fsp.stat(target)
|
|
920
|
+
} catch {
|
|
921
|
+
throw new WorkbenchError(404, 'the run named this file but it is no longer on disk', { id: 'artifact-missing' })
|
|
922
|
+
}
|
|
923
|
+
if (!stat.isFile()) throw new WorkbenchError(404, 'that path is not a file', { id: 'artifact-not-file' })
|
|
924
|
+
if (stat.size > MAX_ARTIFACT_BYTES && !download) {
|
|
925
|
+
throw new WorkbenchError(413, `the file is above the ${MAX_ARTIFACT_BYTES}-byte preview limit`, {
|
|
926
|
+
id: 'artifact-too-large',
|
|
927
|
+
})
|
|
928
|
+
}
|
|
929
|
+
const body = await fsp.readFile(target)
|
|
930
|
+
const name = path.basename(target).replace(/["\\]/g, '_')
|
|
931
|
+
const headers = {
|
|
932
|
+
'content-disposition': `${download ? 'attachment' : 'inline'}; filename="${name}"`,
|
|
933
|
+
}
|
|
934
|
+
if (type?.startsWith('text/html') && !download) headers['content-security-policy'] = ARTIFACT_PAGE_CSP
|
|
935
|
+
sendText(res, 200, body, download ? 'application/octet-stream' : type, headers)
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Resolve an artifact path against the run reports that name it. Reports are
|
|
940
|
+
* the allowlist: a console client cannot ask for an arbitrary file, only one
|
|
941
|
+
* the agent already wrote about.
|
|
942
|
+
*
|
|
943
|
+
* @param {URL} parsed - request URL carrying `path` and optionally `runId`.
|
|
944
|
+
* @returns {Promise<{raw: string, target: string}>} resolved file.
|
|
945
|
+
*/
|
|
946
|
+
async function listedArtifact(parsed) {
|
|
899
947
|
const sessionId = currentSessionId
|
|
900
948
|
if (!sessionId) throw new WorkbenchError(409, 'there is no conversation yet', { id: 'no-session' })
|
|
901
949
|
const raw = (parsed.searchParams.get('path') || '').trim()
|
|
@@ -920,28 +968,24 @@ export function createConsole({
|
|
|
920
968
|
hint: 'only files a run reported can be previewed here; copy the path and open it in your editor instead.',
|
|
921
969
|
})
|
|
922
970
|
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
if (
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
})
|
|
938
|
-
}
|
|
939
|
-
const body = await fsp.readFile(target)
|
|
940
|
-
const headers = {
|
|
941
|
-
'content-disposition': `inline; filename="${path.basename(target).replace(/["\\]/g, '_')}"`,
|
|
971
|
+
return { raw, target }
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Show one artifact in the platform file manager. The same report allowlist
|
|
976
|
+
* applies, so this cannot be used as an arbitrary "open anything" oracle.
|
|
977
|
+
*
|
|
978
|
+
* @param {string} target - absolute file path already vetted by listedArtifact.
|
|
979
|
+
*/
|
|
980
|
+
function revealInFolder(target) {
|
|
981
|
+
if (process.platform === 'win32') {
|
|
982
|
+
const child = spawn('explorer.exe', ['/select,', target], { detached: true, stdio: 'ignore' })
|
|
983
|
+
child.unref()
|
|
984
|
+
return
|
|
942
985
|
}
|
|
943
|
-
|
|
944
|
-
|
|
986
|
+
const command = process.platform === 'darwin' ? ['open', ['-R', target]] : ['xdg-open', [path.dirname(target)]]
|
|
987
|
+
const child = spawn(command[0], command[1], { detached: true, stdio: 'ignore' })
|
|
988
|
+
child.unref()
|
|
945
989
|
}
|
|
946
990
|
|
|
947
991
|
/**
|
|
@@ -1123,6 +1167,14 @@ export function createConsole({
|
|
|
1123
1167
|
}
|
|
1124
1168
|
const leaf = parts[2] ?? ''
|
|
1125
1169
|
|
|
1170
|
+
if (leaf === 'artifact' && parts.length === 4 && parts[3] === 'reveal') {
|
|
1171
|
+
if (method !== 'POST') throw new WorkbenchError(405, 'only POST is allowed here', { id: 'method-not-allowed' })
|
|
1172
|
+
const { target } = await listedArtifact(parsed)
|
|
1173
|
+
revealInFolder(target)
|
|
1174
|
+
send(res, 200, { ok: true, data: { revealed: true, path: target } })
|
|
1175
|
+
return
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1126
1178
|
if (leaf === 'health' && parts.length === 3) {
|
|
1127
1179
|
if (method !== 'GET') throw new WorkbenchError(405, 'only GET is allowed here', { id: 'method-not-allowed' })
|
|
1128
1180
|
const caps = capabilities()
|
package/lib/guard.js
CHANGED
|
@@ -192,6 +192,10 @@ function resolveTarget(raw, { cwd, platform, homedir, env }) {
|
|
|
192
192
|
value = value.slice(1, -1).trim()
|
|
193
193
|
}
|
|
194
194
|
if (!value || value === '-' || /^(nul|\/dev\/null)$/i.test(value)) return null
|
|
195
|
+
// A lone shell operator (`^`, `&`, `=`, `>`) is not a path. Raw command
|
|
196
|
+
// scanning can surface one when PowerShell or a quoted script body contains
|
|
197
|
+
// it; resolving that against cwd used to produce a bogus `C:\^` target.
|
|
198
|
+
if (/^[^\w./\\~:$@%+()[\]{}'-]+$/.test(value)) return null
|
|
195
199
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) return null
|
|
196
200
|
value = expandPath(value, { platform, homedir, env })
|
|
197
201
|
// An unresolved variable is not a literal path. Treating it as one would
|
|
@@ -327,12 +331,60 @@ function destructiveTargetVerdict(policy, target, context) {
|
|
|
327
331
|
return null
|
|
328
332
|
}
|
|
329
333
|
|
|
330
|
-
/** Split a command line into independently evaluated segments. */
|
|
334
|
+
/** Split a command line into independently evaluated segments, ignoring operators inside quotes. */
|
|
331
335
|
function segmentsOf(command) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
+
const segments = []
|
|
337
|
+
let current = ''
|
|
338
|
+
let quote = null
|
|
339
|
+
for (let index = 0; index < command.length; index += 1) {
|
|
340
|
+
const char = command[index]
|
|
341
|
+
if (quote) {
|
|
342
|
+
current += char
|
|
343
|
+
if (char === quote && command[index - 1] !== '\\') quote = null
|
|
344
|
+
continue
|
|
345
|
+
}
|
|
346
|
+
if (char === '"' || char === "'") {
|
|
347
|
+
quote = char
|
|
348
|
+
current += char
|
|
349
|
+
continue
|
|
350
|
+
}
|
|
351
|
+
const pair = command.slice(index, index + 2)
|
|
352
|
+
if (pair === '&&' || pair === '||') {
|
|
353
|
+
segments.push(current)
|
|
354
|
+
current = ''
|
|
355
|
+
index += 1
|
|
356
|
+
continue
|
|
357
|
+
}
|
|
358
|
+
if (char === ';' || char === '|' || char === '\n' || char === '\r') {
|
|
359
|
+
segments.push(current)
|
|
360
|
+
current = ''
|
|
361
|
+
continue
|
|
362
|
+
}
|
|
363
|
+
current += char
|
|
364
|
+
}
|
|
365
|
+
segments.push(current)
|
|
366
|
+
return segments.map(segment => segment.trim()).filter(Boolean)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Character ranges that sit inside a single- or double-quoted run. */
|
|
370
|
+
function quotedRanges(text) {
|
|
371
|
+
const ranges = []
|
|
372
|
+
let quote = null
|
|
373
|
+
let start = 0
|
|
374
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
375
|
+
const char = text[index]
|
|
376
|
+
if (quote) {
|
|
377
|
+
if (char === quote && text[index - 1] !== '\\') {
|
|
378
|
+
ranges.push([start, index + 1])
|
|
379
|
+
quote = null
|
|
380
|
+
}
|
|
381
|
+
} else if (char === '"' || char === "'") {
|
|
382
|
+
quote = char
|
|
383
|
+
start = index
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (quote) ranges.push([start, text.length])
|
|
387
|
+
return ranges
|
|
336
388
|
}
|
|
337
389
|
|
|
338
390
|
/** Tokenize one segment, keeping quoted strings as one token. */
|
|
@@ -359,9 +411,15 @@ function writeTargetsOf(segment, platform) {
|
|
|
359
411
|
const push = value => {
|
|
360
412
|
if (value && !isFlagToken(value, platform)) targets.push(value)
|
|
361
413
|
}
|
|
362
|
-
// `> path`, `>> path`, but not `2>&1
|
|
363
|
-
|
|
364
|
-
|
|
414
|
+
// `> path`, `>> path`, but not `2>&1`, and never a `>` that lives inside a
|
|
415
|
+
// quoted script body such as `node -e "const f = a => a + 1"`.
|
|
416
|
+
const quoted = quotedRanges(segment)
|
|
417
|
+
const insideQuotes = index => quoted.some(([start, end]) => index >= start && index < end)
|
|
418
|
+
for (let index = 0; index < segment.length; index += 1) {
|
|
419
|
+
if (segment[index] !== '>' || insideQuotes(index)) continue
|
|
420
|
+
if (segment[index - 1] === '&') continue
|
|
421
|
+
const match = /^>>?\s*(?:"([^"]+)"|'([^']+)'|([^\s;&|]+))/.exec(segment.slice(index))
|
|
422
|
+
if (match) push(match[1] ?? match[2] ?? match[3])
|
|
365
423
|
}
|
|
366
424
|
for (const match of segment.matchAll(/\btee\s+(?:-a\s+)?(?:"([^"]+)"|'([^']+)'|([^\s;&|]+))/gi)) {
|
|
367
425
|
push(match[1] ?? match[2] ?? match[3])
|
package/lib/index.js
CHANGED
|
@@ -1306,6 +1306,36 @@ export function apply(ctx, config) {
|
|
|
1306
1306
|
// declarations and dispatch.
|
|
1307
1307
|
const EXTRA_TOOLS = { when: context => isExpanded(context?.agent) }
|
|
1308
1308
|
|
|
1309
|
+
// Delegated workers must not see the superagent surface at all: a worker that
|
|
1310
|
+
// could start another run would nest schedulers and double the token spend.
|
|
1311
|
+
const isWorker = agent => {
|
|
1312
|
+
const header = agent?.session?.header
|
|
1313
|
+
return (header?.delegationDepth ?? 0) > 0 || header?.origin === 'subagent'
|
|
1314
|
+
}
|
|
1315
|
+
// Sessions opened through the console are the user's own space, so the eight
|
|
1316
|
+
// core tools stay visible there. A plain host conversation sees only
|
|
1317
|
+
// `superagent_help`, which expands the rest on demand.
|
|
1318
|
+
const panelSessions = new Set()
|
|
1319
|
+
const isPanelSession = agent => {
|
|
1320
|
+
const header = agent?.session?.header
|
|
1321
|
+
return panelSessions.has(agent?.id)
|
|
1322
|
+
|| (header?.id ? panelSessions.has(header.id) : false)
|
|
1323
|
+
|| (header?.sessionId ? panelSessions.has(header.sessionId) : false)
|
|
1324
|
+
}
|
|
1325
|
+
const residentGate = definition => {
|
|
1326
|
+
const name = typeof definition?.name === 'string' ? definition.name : ''
|
|
1327
|
+
if (!name.startsWith('superagent_')) return undefined
|
|
1328
|
+
if (name === 'superagent_help') return { when: context => !isWorker(context?.agent) }
|
|
1329
|
+
return {
|
|
1330
|
+
when: context => !isWorker(context?.agent)
|
|
1331
|
+
&& (isPanelSession(context?.agent) || isExpanded(context?.agent)),
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
const registerTool = (definition, options) => ctx.tools.register(
|
|
1335
|
+
definition,
|
|
1336
|
+
options ?? residentGate(definition),
|
|
1337
|
+
)
|
|
1338
|
+
|
|
1309
1339
|
// Runtime control is opt-in. With `runtime.enabled` false nothing below is
|
|
1310
1340
|
// registered, which is why a profile that never asked for browser or desktop
|
|
1311
1341
|
// access sees exactly the same tool list as before this layer existed.
|
|
@@ -1316,7 +1346,7 @@ export function apply(ctx, config) {
|
|
|
1316
1346
|
warn: log,
|
|
1317
1347
|
})
|
|
1318
1348
|
if (runtime.tools.length > 0) {
|
|
1319
|
-
for (const spec of runtime.tools)
|
|
1349
|
+
for (const spec of runtime.tools) registerTool(defineTool(spec))
|
|
1320
1350
|
log(
|
|
1321
1351
|
`runtime control: ${runtime.tools.length} tool(s) registered; stop switch ${runtime.stopFile}; `
|
|
1322
1352
|
+ `screenshots ${runtime.shotDir}`,
|
|
@@ -1817,6 +1847,11 @@ export function apply(ctx, config) {
|
|
|
1817
1847
|
return null
|
|
1818
1848
|
}
|
|
1819
1849
|
|
|
1850
|
+
// This host build does not expose a scheduling API on the plugin context,
|
|
1851
|
+
// so plans stay in the plugin store. The tool reports that instead of
|
|
1852
|
+
// letting the user look for them in the host's automation list.
|
|
1853
|
+
const hostScheduleVisible = typeof ctx.schedule === 'function'
|
|
1854
|
+
|
|
1820
1855
|
const scheduler = createScheduler({
|
|
1821
1856
|
stateFile: path.join(store.root, 'schedules.json'),
|
|
1822
1857
|
orchestrator: {
|
|
@@ -2025,7 +2060,7 @@ export function apply(ctx, config) {
|
|
|
2025
2060
|
return agent
|
|
2026
2061
|
}
|
|
2027
2062
|
|
|
2028
|
-
|
|
2063
|
+
registerTool(defineTool({
|
|
2029
2064
|
name: 'superagent_start',
|
|
2030
2065
|
description:
|
|
2031
2066
|
'Start an autonomous run: a planner splits the goal into subtasks, independent ones run in parallel, and their '
|
|
@@ -2151,7 +2186,7 @@ export function apply(ctx, config) {
|
|
|
2151
2186
|
},
|
|
2152
2187
|
}))
|
|
2153
2188
|
|
|
2154
|
-
|
|
2189
|
+
registerTool(defineTool({
|
|
2155
2190
|
name: 'superagent_goal',
|
|
2156
2191
|
description:
|
|
2157
2192
|
'Run a long-term goal as ordered phases: each phase is its own run with planner and parallel workers, and later '
|
|
@@ -2371,7 +2406,7 @@ export function apply(ctx, config) {
|
|
|
2371
2406
|
return ''
|
|
2372
2407
|
}
|
|
2373
2408
|
|
|
2374
|
-
|
|
2409
|
+
registerTool(defineTool({
|
|
2375
2410
|
name: 'superagent_status',
|
|
2376
2411
|
description:
|
|
2377
2412
|
'Read one run: status, subtask outcomes, measured token usage, and the final report. wait_seconds blocks for a '
|
|
@@ -2394,7 +2429,7 @@ export function apply(ctx, config) {
|
|
|
2394
2429
|
},
|
|
2395
2430
|
}))
|
|
2396
2431
|
|
|
2397
|
-
|
|
2432
|
+
registerTool(defineTool({
|
|
2398
2433
|
name: 'superagent_list',
|
|
2399
2434
|
description: 'List recorded runs, newest first, with status and progress.',
|
|
2400
2435
|
properties: {
|
|
@@ -2434,7 +2469,7 @@ export function apply(ctx, config) {
|
|
|
2434
2469
|
// Every declaration is paid for on every request, so the capabilities most
|
|
2435
2470
|
// sessions never touch are registered behind a per-session activation
|
|
2436
2471
|
// condition: `superagent_help` names them and turns them on for that session.
|
|
2437
|
-
|
|
2472
|
+
registerTool(defineTool({
|
|
2438
2473
|
name: 'superagent_help',
|
|
2439
2474
|
description:
|
|
2440
2475
|
'Show the extra superagent tools and when each applies: long-term goals, cron schedules, live steering, '
|
|
@@ -2461,7 +2496,7 @@ export function apply(ctx, config) {
|
|
|
2461
2496
|
},
|
|
2462
2497
|
}))
|
|
2463
2498
|
|
|
2464
|
-
|
|
2499
|
+
registerTool(defineTool({
|
|
2465
2500
|
name: 'superagent_cancel',
|
|
2466
2501
|
description:
|
|
2467
2502
|
'Cancel a run: stops its subtasks and marks it cancelled; the state file stays inspectable.',
|
|
@@ -2489,7 +2524,7 @@ export function apply(ctx, config) {
|
|
|
2489
2524
|
},
|
|
2490
2525
|
}))
|
|
2491
2526
|
|
|
2492
|
-
|
|
2527
|
+
registerTool(defineTool({
|
|
2493
2528
|
name: 'superagent_resume',
|
|
2494
2529
|
description:
|
|
2495
2530
|
'Resume an interrupted, timed-out, or failed run: completed subtasks are kept, pending and failed ones run '
|
|
@@ -2534,7 +2569,7 @@ export function apply(ctx, config) {
|
|
|
2534
2569
|
},
|
|
2535
2570
|
}))
|
|
2536
2571
|
|
|
2537
|
-
|
|
2572
|
+
registerTool(defineTool({
|
|
2538
2573
|
name: 'superagent_followup',
|
|
2539
2574
|
description:
|
|
2540
2575
|
'Add an instruction to a run that is already executing instead of starting a second one. It is queued and '
|
|
@@ -2568,7 +2603,7 @@ export function apply(ctx, config) {
|
|
|
2568
2603
|
},
|
|
2569
2604
|
}))
|
|
2570
2605
|
|
|
2571
|
-
|
|
2606
|
+
registerTool(defineTool({
|
|
2572
2607
|
name: 'superagent_inject',
|
|
2573
2608
|
description:
|
|
2574
2609
|
'Deliver an instruction into the workers running right now: it becomes part of each child\'s next model request, '
|
|
@@ -2606,7 +2641,7 @@ export function apply(ctx, config) {
|
|
|
2606
2641
|
},
|
|
2607
2642
|
}), EXTRA_TOOLS)
|
|
2608
2643
|
|
|
2609
|
-
|
|
2644
|
+
registerTool(defineTool({
|
|
2610
2645
|
name: 'superagent_answer',
|
|
2611
2646
|
description:
|
|
2612
2647
|
'Answer the question a run asked (the qN item in superagent_status), so that run continues instead of a new one '
|
|
@@ -2651,7 +2686,7 @@ export function apply(ctx, config) {
|
|
|
2651
2686
|
},
|
|
2652
2687
|
}))
|
|
2653
2688
|
|
|
2654
|
-
|
|
2689
|
+
registerTool(defineTool({
|
|
2655
2690
|
name: 'superagent_memory',
|
|
2656
2691
|
description:
|
|
2657
2692
|
'Read or correct the cross-run notebook: short notes earlier runs left for the next one, or (layer="user") '
|
|
@@ -2883,7 +2918,7 @@ export function apply(ctx, config) {
|
|
|
2883
2918
|
return [`[error] ${error.message}`, `hint: ${hint}`].join('\n')
|
|
2884
2919
|
}
|
|
2885
2920
|
|
|
2886
|
-
|
|
2921
|
+
registerTool(defineTool({
|
|
2887
2922
|
name: 'superagent_template',
|
|
2888
2923
|
description:
|
|
2889
2924
|
'List, show, expand, save, or delete a workflow template: a fixed goal skeleton with required parameters. '
|
|
@@ -2967,7 +3002,7 @@ export function apply(ctx, config) {
|
|
|
2967
3002
|
},
|
|
2968
3003
|
}), EXTRA_TOOLS)
|
|
2969
3004
|
|
|
2970
|
-
|
|
3005
|
+
registerTool(defineTool({
|
|
2971
3006
|
name: 'superagent_schedule',
|
|
2972
3007
|
description:
|
|
2973
3008
|
'Create and manage scheduled runs that start on a cron expression or fixed interval without anyone calling '
|
|
@@ -3119,8 +3154,13 @@ export function apply(ctx, config) {
|
|
|
3119
3154
|
+ 'restart. The plan is marked as requiring a resident session; it will not silently pause, but it '
|
|
3120
3155
|
+ 'will not run while that session is closed.'
|
|
3121
3156
|
: ''
|
|
3157
|
+
const hostNotice = hostScheduleVisible
|
|
3158
|
+
? ''
|
|
3159
|
+
: '\n\nnote: this host build exposes no scheduling API to plugins, so the plan lives in this '
|
|
3160
|
+
+ "plugin's own store and will not appear under the host's automation list. It still fires "
|
|
3161
|
+
+ `every ${cfg.schedulerTickSeconds}s while the app is running.`
|
|
3122
3162
|
return `created schedule ${plan.id}. The timer is armed from now on; no further tool call is needed.\n\n`
|
|
3123
|
-
+ formatSchedule(plan) + warning
|
|
3163
|
+
+ formatSchedule(plan) + warning + hostNotice
|
|
3124
3164
|
}
|
|
3125
3165
|
if (action === 'list') {
|
|
3126
3166
|
const plans = await scheduler.list()
|
|
@@ -3159,7 +3199,7 @@ export function apply(ctx, config) {
|
|
|
3159
3199
|
// unasked. When it is on, every request goes through the same orchestrator as
|
|
3160
3200
|
// the tools, so quota, budgets, ownership, and cancel behave identically.
|
|
3161
3201
|
if (auditor) {
|
|
3162
|
-
|
|
3202
|
+
registerTool(defineTool({
|
|
3163
3203
|
name: 'superagent_audit',
|
|
3164
3204
|
description:
|
|
3165
3205
|
'Query the append-only audit trail (tool calls, path writes, commands, blocks, approvals, decisions, run '
|
|
@@ -3718,6 +3758,15 @@ export function apply(ctx, config) {
|
|
|
3718
3758
|
return wizard.trial()
|
|
3719
3759
|
},
|
|
3720
3760
|
|
|
3761
|
+
/**
|
|
3762
|
+
* Remember that a session is driven from the superagent panel, so the
|
|
3763
|
+
* eight core tools stay in its tool list. A plain host conversation is
|
|
3764
|
+
* not marked and keeps only `superagent_help`.
|
|
3765
|
+
*/
|
|
3766
|
+
markPanelSession(sessionId) {
|
|
3767
|
+
if (typeof sessionId === 'string' && sessionId) panelSessions.add(sessionId)
|
|
3768
|
+
},
|
|
3769
|
+
|
|
3721
3770
|
async createSession() {
|
|
3722
3771
|
const caps = consoleCapabilities()
|
|
3723
3772
|
if (!caps.chat) throw new Error(caps.reason)
|
|
@@ -3738,6 +3787,7 @@ export function apply(ctx, config) {
|
|
|
3738
3787
|
if (!created || typeof created.sessionId !== 'string' || !created.sessionId) {
|
|
3739
3788
|
throw new Error('sessionController.create returned no sessionId')
|
|
3740
3789
|
}
|
|
3790
|
+
panelSessions.add(created.sessionId)
|
|
3741
3791
|
return { sessionId: created.sessionId, preset: created.preset ?? cfg.consolePreset ?? null }
|
|
3742
3792
|
},
|
|
3743
3793
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiangyixie/dsh-superagent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"description": "长周期自主执行插件:一个目标拆成可并行的子任务,交付一份合并报告,重启后仍可继续。",
|
|
5
5
|
"author": "Admire (LittleChenLiya)",
|
|
6
6
|
"type": "module",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"dsh": ">=0.2.2-rc.1 <0.3.0-0"
|
|
100
100
|
},
|
|
101
101
|
"scripts": {
|
|
102
|
-
"test": "node --test test/orchestrator.test.mjs test/direct-and-queue.test.mjs test/dialog.test.mjs test/workspace.test.mjs test/store.test.mjs test/errors.test.mjs test/plugin.test.mjs test/overhead.test.mjs test/guard.test.mjs test/goal.test.mjs test/cron.test.mjs test/schedule.test.mjs test/audit.test.mjs test/inject.test.mjs test/sync.test.mjs test/workbench.test.mjs test/usage.test.mjs test/cost.test.mjs test/ledger.test.mjs test/control.test.mjs test/watch.test.mjs test/report.test.mjs test/memory.test.mjs test/user-memory.test.mjs test/notify.test.mjs test/templates.test.mjs test/archive.test.mjs test/doctor.test.mjs test/pack.test.mjs test/runtime-control.test.mjs test/console.test.mjs test/client-bundle.test.mjs test/wizard.test.mjs test/board.test.mjs test/long-goal.test.mjs",
|
|
102
|
+
"test": "node --test test/orchestrator.test.mjs test/direct-and-queue.test.mjs test/dialog.test.mjs test/workspace.test.mjs test/store.test.mjs test/errors.test.mjs test/plugin.test.mjs test/overhead.test.mjs test/guard.test.mjs test/goal.test.mjs test/cron.test.mjs test/schedule.test.mjs test/audit.test.mjs test/inject.test.mjs test/sync.test.mjs test/workbench.test.mjs test/usage.test.mjs test/cost.test.mjs test/ledger.test.mjs test/control.test.mjs test/watch.test.mjs test/report.test.mjs test/memory.test.mjs test/user-memory.test.mjs test/notify.test.mjs test/templates.test.mjs test/archive.test.mjs test/doctor.test.mjs test/pack.test.mjs test/runtime-control.test.mjs test/console.test.mjs test/client-bundle.test.mjs test/client-entries.test.mjs test/wizard.test.mjs test/board.test.mjs test/long-goal.test.mjs",
|
|
103
103
|
"check-pack": "node scripts/check-pack.mjs"
|
|
104
104
|
},
|
|
105
105
|
"keywords": [
|