@xiangyixie/dsh-superagent 0.16.0 → 0.16.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 +26 -0
- package/README.en.md +3 -3
- package/README.md +3 -3
- package/README.zh.md +3 -3
- package/lib/client.js +139 -159
- package/lib/console.js +25 -0
- package/lib/index.js +14 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,32 @@ 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.16.1 — 2026-11-17
|
|
12
|
+
|
|
13
|
+
### 变化
|
|
14
|
+
|
|
15
|
+
- **运行中能停下来了。** 发送键在回合运行时变成宿主同款的 34px 圆形停止键
|
|
16
|
+
(中间 10px 圆角方块),点击后进入取消中并画转圈;后端补了真正的回合级取消:
|
|
17
|
+
新增 `POST /api/console/cancel`,走宿主的 `sessionController.cancel({ sessionId })`,
|
|
18
|
+
成功广播 `canceling` 帧,回合结束后自动复位。宿主没有取消能力时明确返回 501,
|
|
19
|
+
不会只画一个按钮。
|
|
20
|
+
- **用户气泡换成宿主的 `UserMessageBubble`。** 圆角 `radius-xl` 20、内边距
|
|
21
|
+
`10px 16px`、行高 `calc(22px + delta)`、字号跟 `--dsh-content-font-size`,浅色下
|
|
22
|
+
是宿主的 `deepseek-50` 浅蓝,不再是自造的灰色。
|
|
23
|
+
- **正文列宽按宿主公式。** 正文列改为
|
|
24
|
+
`clamp(680px, var(--dsh-chat-user-width) * .64, 920px)`,滚动区左右各留 32px;
|
|
25
|
+
审批卡和 toast 跟随同一列宽,不再贴边。
|
|
26
|
+
- **Markdown 改用宿主的 `MarkdownText`。** 自造的渲染子集整段删除,表格、引用、
|
|
27
|
+
分割线、嵌套列表、斜体、围栏语言标记和代码高亮全部由宿主组件负责,标题字号
|
|
28
|
+
走 `--dsw-font-markdown-*`。
|
|
29
|
+
- **审批卡对齐宿主。** 外框 `radius-xl` 20、`border warn-secondary`、
|
|
30
|
+
`bg input-major`、`shadow lv2`;顶部加 `warn-tertiary` 警示条(`StateDot`
|
|
31
|
+
warning + 「等待你的批准」)。按钮顺序改为 拒绝 → 允许一次 → 本会话都放行
|
|
32
|
+
(primary);请求期间 `disabled` + `aria-busy`,失败会弹出可见提示,不再
|
|
33
|
+
吞异常。
|
|
34
|
+
- 修掉拼错的 token:`--dsw-alias-state-warning-primary` → 宿主真实存在的
|
|
35
|
+
`--dsw-alias-state-warn-primary`。
|
|
36
|
+
|
|
11
37
|
## 0.16.0 — 2026-11-17
|
|
12
38
|
|
|
13
39
|
### 变化
|
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.16.
|
|
39
|
+
Desktop: **Plugins** → **Add plugin** → enter `@xiangyixie/dsh-superagent@0.16.1` → install.
|
|
40
40
|
|
|
41
41
|
CLI:
|
|
42
42
|
|
|
43
43
|
```bash
|
|
44
|
-
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.16.
|
|
44
|
+
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.16.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.16.
|
|
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.16.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.16.
|
|
39
|
+
桌面端:侧边栏 **插件** → **Add plugin** → 输入 `@xiangyixie/dsh-superagent@0.16.1` → 安装。
|
|
40
40
|
|
|
41
41
|
命令行:
|
|
42
42
|
|
|
43
43
|
```bash
|
|
44
|
-
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.16.
|
|
44
|
+
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.16.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.16.
|
|
1093
|
+
| `superagent_*` 工具不存在 | bundle 行没挂上,或者宿主拒绝加载插件。 | 跑 `--dump-config` 查 `@xiangyixie/dsh-superagent` 块;用 `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.16.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.16.
|
|
39
|
+
桌面端:侧边栏 **插件** → **Add plugin** → 输入 `@xiangyixie/dsh-superagent@0.16.1` → 安装。
|
|
40
40
|
|
|
41
41
|
命令行:
|
|
42
42
|
|
|
43
43
|
```bash
|
|
44
|
-
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.16.
|
|
44
|
+
dsh plugin --profile web add @xiangyixie/dsh-superagent@0.16.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.16.
|
|
1093
|
+
| `superagent_*` 工具不存在 | bundle 行没挂上,或者宿主拒绝加载插件。 | 跑 `--dump-config` 查 `@xiangyixie/dsh-superagent` 块;用 `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.16.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
|
@@ -54,6 +54,9 @@ window.__ModuleLoader__.load({
|
|
|
54
54
|
const h = react ? react.createElement : null
|
|
55
55
|
const Button = ui && typeof ui.Button === 'function' ? ui.Button : null
|
|
56
56
|
const FishLogo = ui && typeof ui.FishLogo === 'function' ? ui.FishLogo : null
|
|
57
|
+
const MarkdownText = ui && typeof ui.MarkdownText === 'function' ? ui.MarkdownText : null
|
|
58
|
+
const UserMessageBubble = ui && typeof ui.UserMessageBubble === 'function' ? ui.UserMessageBubble : null
|
|
59
|
+
const StateDot = ui && typeof ui.StateDot === 'function' ? ui.StateDot : null
|
|
57
60
|
const ICONS = {
|
|
58
61
|
spark: ui?.IconSparkleRegular ?? ui?.IconSparkleMedium,
|
|
59
62
|
send: ui?.IconSendOutlineRegular ?? ui?.IconSendOutlineMedium,
|
|
@@ -66,6 +69,20 @@ window.__ModuleLoader__.load({
|
|
|
66
69
|
close: ui?.IconCloseOutlineRegular ?? ui?.IconCloseOutlineMedium,
|
|
67
70
|
folder: ui?.IconFolderCloseRegular ?? ui?.IconFolderCloseMedium,
|
|
68
71
|
}
|
|
72
|
+
// MarkdownText reads `labels.code` on every fenced block, so the host
|
|
73
|
+
// component is only safe with this shape filled in.
|
|
74
|
+
const MARKDOWN_LABELS = {
|
|
75
|
+
code: {
|
|
76
|
+
copyLabel: '复制',
|
|
77
|
+
copiedLabel: '已复制',
|
|
78
|
+
toolbarLabels: {
|
|
79
|
+
codeLabel: '代码',
|
|
80
|
+
wrapLabel: '换行',
|
|
81
|
+
unwrapLabel: '取消换行',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
footnotes: '脚注',
|
|
85
|
+
}
|
|
69
86
|
|
|
70
87
|
/**
|
|
71
88
|
* One class sheet for the panel. Every value is copied from the host's own
|
|
@@ -75,7 +92,7 @@ window.__ModuleLoader__.load({
|
|
|
75
92
|
* 12px gaps, send 34px circle on button-info-fill, stats row 22px.
|
|
76
93
|
*/
|
|
77
94
|
const CSS = `
|
|
78
|
-
.dsa-root{display:flex;flex-direction:column;height:100%;min-width:0;background:var(--dsw-alias-bg-base,rgb(21,21,23));color:var(--dsw-alias-label-primary,#f9fafb);font-family:var(--dsw-font-family,inherit);font-size:14px;line-height:22px}
|
|
95
|
+
.dsa-root{--dsa-col:clamp(680px,calc(var(--dsh-chat-user-width,100%) * .64),920px);display:flex;flex-direction:column;height:100%;min-width:0;background:var(--dsw-alias-bg-base,rgb(21,21,23));color:var(--dsw-alias-label-primary,#f9fafb);font-family:var(--dsw-font-family,inherit);font-size:14px;line-height:22px}
|
|
79
96
|
.dsa-header{display:flex;align-items:center;gap:10px;flex:none;box-sizing:border-box;min-height:76px;padding:10px 28px 0 20px;border-bottom:.5px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12))}
|
|
80
97
|
.dsa-crumbs{display:flex;align-items:center;gap:4px;flex:1;min-width:0;overflow:hidden;white-space:nowrap}
|
|
81
98
|
.dsa-crumb{display:inline-block;max-width:220px;overflow:hidden;padding:4px 8px;border:0;border-radius:var(--dsw-radius-md,12px);background:transparent;color:var(--dsw-alias-label-tertiary,rgb(129,133,140));font-size:14px;line-height:20px;text-overflow:ellipsis;white-space:nowrap}
|
|
@@ -89,19 +106,19 @@ window.__ModuleLoader__.load({
|
|
|
89
106
|
.dsa-status{display:inline-flex;align-items:center;gap:6px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary,rgb(129,133,140))}
|
|
90
107
|
.dsa-dot{width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-label-caption,rgb(129,133,140))}
|
|
91
108
|
.dsa-dot[data-state=live]{background:var(--dsw-alias-state-success-primary,#22c55e)}
|
|
92
|
-
.dsa-dot[data-state=warn]{background:var(--dsw-alias-state-
|
|
109
|
+
.dsa-dot[data-state=warn]{background:var(--dsw-alias-state-warn-primary,#f59e0b)}
|
|
93
110
|
.dsa-body{display:flex;flex:1;min-height:0}
|
|
94
111
|
.dsa-main{position:relative;display:flex;flex-direction:column;flex:1;min-width:0}
|
|
95
|
-
.dsa-scroll{flex:1;min-height:0;overflow-y:auto;display:flex;flex-direction:column;margin-right:2px;scrollbar-gutter:stable}
|
|
112
|
+
.dsa-scroll{flex:1;min-height:0;overflow-y:auto;display:flex;flex-direction:column;margin-right:2px;padding:0 32px;scrollbar-gutter:stable}
|
|
96
113
|
.dsa-scroll::-webkit-scrollbar{width:10px}
|
|
97
114
|
.dsa-scroll::-webkit-scrollbar-thumb{border-radius:5px;background:var(--dsw-alias-scrollbar-bg-l1,rgba(255,255,255,.16))}
|
|
98
|
-
.dsa-flow{width:min(100%,
|
|
115
|
+
.dsa-flow{width:min(100%,var(--dsa-col));margin:0 auto;padding:16px 0 8px;box-sizing:border-box}
|
|
99
116
|
.dsa-hero{flex:1;display:flex;align-items:center;justify-content:center;min-height:0;padding:0 24px}
|
|
100
|
-
.dsa-hero-stack{display:flex;flex-direction:column;gap:12px;width:100%;max-width:calc(
|
|
117
|
+
.dsa-hero-stack{display:flex;flex-direction:column;gap:12px;width:100%;max-width:calc(var(--dsa-col) + 32px);padding-bottom:32px}
|
|
101
118
|
.dsa-hero-title{display:flex;align-items:center;justify-content:center;gap:10px;font-size:26px;line-height:32px;font-weight:500;color:var(--dsw-alias-label-primary,#f9fafb)}
|
|
102
119
|
.dsa-hero-note{text-align:center;font-size:13px;line-height:20px;color:var(--dsw-alias-label-tertiary,rgb(129,133,140))}
|
|
103
120
|
.dsa-composer{flex:none;padding:0 16px 4px;background:var(--dsw-alias-bg-base,rgb(21,21,23))}
|
|
104
|
-
.dsa-card{display:flex;flex-direction:column;gap:12px;box-sizing:border-box;width:100%;max-width:calc(
|
|
121
|
+
.dsa-card{display:flex;flex-direction:column;gap:12px;box-sizing:border-box;width:100%;max-width:calc(var(--dsa-col) + 32px);margin:0 auto;padding-top:8px;border-radius:var(--dsw-radius-panel,28px);background:var(--dsw-specific-input-major,rgb(35,35,36));box-shadow:var(--dsw-elevation-soft,0 2px 12px rgba(0,0,0,.18))}
|
|
105
122
|
.dsa-input{box-sizing:border-box;width:100%;min-height:36px;max-height:336px;padding:4px 8px 0 14px;border:0;outline:none;background:transparent;color:var(--dsw-alias-label-primary,#f9fafb);font:inherit;font-size:var(--dsh-content-font-size,14px);line-height:calc(24px + var(--dsh-content-font-delta,0px));resize:none;overflow-y:auto}
|
|
106
123
|
.dsa-input::placeholder{color:var(--dsw-alias-label-caption,rgb(129,133,140))}
|
|
107
124
|
.dsa-card[data-hero=true] .dsa-input{min-height:52px}
|
|
@@ -116,31 +133,28 @@ window.__ModuleLoader__.load({
|
|
|
116
133
|
.dsa-send:hover:not(:disabled){background:var(--dsw-alias-button-info-hover,#2f57e6)}
|
|
117
134
|
.dsa-send:disabled{opacity:.4;cursor:default}
|
|
118
135
|
.dsa-send svg{width:15px;height:15px}
|
|
136
|
+
.dsa-send[data-mode=stop] svg{width:10px;height:10px;border-radius:2px}
|
|
137
|
+
.dsa-spin{width:14px;height:14px;border-radius:50%;border:2px solid rgba(255,255,255,.35);border-top-color:var(--dsw-alias-label-on-color,#fff);animation:dsa-spin .8s linear infinite}
|
|
138
|
+
@keyframes dsa-spin{to{transform:rotate(360deg)}}
|
|
119
139
|
.dsa-stats{min-height:calc(22px + var(--dsh-content-font-delta-secondary,0px));display:flex;align-items:center;justify-content:center;gap:10px;font-size:12px;line-height:20px;color:var(--dsw-alias-label-tertiary,rgb(129,133,140))}
|
|
120
140
|
.dsa-msg{padding:0 0 4px}
|
|
121
141
|
.dsa-user{display:flex;flex-direction:column;align-items:flex-end;gap:6px;margin-bottom:16px}
|
|
122
|
-
.dsa-bubble{max-width:min(calc(
|
|
142
|
+
.dsa-bubble{max-width:min(calc(var(--dsa-col) * .702),82%);padding:10px 16px;border-radius:var(--dsw-radius-xl,20px);background:var(--dsw-specific-bubble,var(--dsw-static-deepseek-50,#eef4ff));color:var(--dsw-alias-label-primary,#f9fafb);font-size:var(--dsh-content-font-size,14px);line-height:calc(22px + var(--dsh-content-font-delta,0px));white-space:pre-wrap;overflow-wrap:anywhere}
|
|
123
143
|
.dsa-bubble[data-pending=true]{opacity:.6}
|
|
124
|
-
.dsa-assistant{display:flex;flex-direction:column;gap:6px;margin-bottom:16px;font-size:14px;line-height:24px;overflow-wrap:anywhere}
|
|
125
|
-
.dsa-md
|
|
126
|
-
.dsa-md>*:last-child{margin-bottom:0}
|
|
127
|
-
.dsa-md p{margin:0 0 8px}
|
|
128
|
-
.dsa-md ul,.dsa-md ol{margin:0 0 8px;padding-left:22px}
|
|
129
|
-
.dsa-md h1,.dsa-md h2,.dsa-md h3{margin:12px 0 8px;font-size:15px;line-height:24px;font-weight:600}
|
|
130
|
-
.dsa-md a{color:var(--dsw-alias-state-business-primary,#7aaaff);text-decoration:none}
|
|
131
|
-
.dsa-md code{padding:1px 5px;border-radius:4px;background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08));font-family:var(--ds-font-family-code,ui-monospace,monospace);font-size:13px}
|
|
132
|
-
.dsa-md pre{margin:0 0 8px;padding:12px;border-radius:var(--dsw-radius-sm,8px);background:var(--dsw-alias-bg-layer-2,rgb(35,35,36));overflow-x:auto}
|
|
133
|
-
.dsa-md pre code{padding:0;background:transparent}
|
|
144
|
+
.dsa-assistant{display:flex;flex-direction:column;gap:6px;margin-bottom:16px;font-size:var(--dsh-content-font-size,14px);line-height:calc(24px + var(--dsh-content-font-delta,0px));overflow-wrap:anywhere}
|
|
145
|
+
.dsa-md-plain{white-space:pre-wrap;overflow-wrap:anywhere}
|
|
134
146
|
.dsa-tools-row{display:flex;flex-wrap:wrap;gap:6px}
|
|
135
147
|
.dsa-tool{display:inline-flex;align-items:center;gap:6px;height:24px;padding:0 8px;border-radius:var(--dsw-radius-xs,4px);background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06));font-size:12px;line-height:16px;color:var(--dsw-alias-label-secondary,rgb(207,211,214))}
|
|
136
148
|
.dsa-tool[data-status=err]{color:var(--dsw-alias-state-error-primary,#f25a5a)}
|
|
137
149
|
.dsa-reasoning{font-size:13px;line-height:20px;color:var(--dsw-alias-label-tertiary,rgb(129,133,140));white-space:pre-wrap}
|
|
138
150
|
.dsa-typing{display:inline-flex;align-items:center;gap:8px;font-size:13px;line-height:20px;color:var(--dsw-alias-label-tertiary,rgb(129,133,140))}
|
|
139
|
-
.dsa-approvals{display:flex;flex-direction:column;gap:8px;width:min(100
|
|
140
|
-
.dsa-approval{display:flex;flex-direction:column;
|
|
151
|
+
.dsa-approvals{display:flex;flex-direction:column;gap:8px;width:min(calc(100% - 64px),var(--dsa-col));margin:0 auto;padding:0 0 8px}
|
|
152
|
+
.dsa-approval{display:flex;flex-direction:column;overflow:hidden;border:1px solid var(--dsw-alias-state-warn-secondary,var(--dsw-static-amber-400,#fbbf24));border-radius:var(--dsw-radius-xl,20px);background:var(--dsw-specific-input-major,rgb(35,35,36));box-shadow:var(--dsw-shadow-lv2,0 4px 16px rgba(0,0,0,.18))}
|
|
153
|
+
.dsa-approval-bar{display:flex;align-items:center;gap:8px;padding:8px 14px;background:var(--dsw-alias-state-warn-tertiary,var(--dsw-static-amber-100,#fef3c7));color:var(--dsw-alias-state-warn-label,var(--dsw-static-amber-600,#d97706));font-size:13px;line-height:20px;font-weight:500}
|
|
154
|
+
.dsa-approval-main{display:flex;flex-direction:column;gap:10px;padding:12px 14px}
|
|
141
155
|
.dsa-approval-title{font-size:14px;line-height:22px;font-weight:500;color:var(--dsw-alias-label-primary,#f9fafb)}
|
|
142
156
|
.dsa-approval-body{font-size:13px;line-height:20px;color:var(--dsw-alias-label-secondary,rgb(207,211,214));overflow-wrap:anywhere}
|
|
143
|
-
.dsa-approval-actions{display:flex;gap:8px;justify-content:flex-end}
|
|
157
|
+
.dsa-approval-actions{display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end}
|
|
144
158
|
.dsa-rail{display:flex;flex:none;flex-direction:column;width:260px;min-width:0;box-sizing:border-box;padding:6px 8px;border-left:.5px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12))}
|
|
145
159
|
.dsa-rail-head{display:flex;align-items:center;justify-content:space-between;gap:6px;padding:6px 8px;font-size:13px;line-height:20px;color:var(--dsw-alias-label-tertiary,rgb(129,133,140))}
|
|
146
160
|
.dsa-rail-list{display:flex;flex-direction:column;gap:2px;min-height:0;overflow-y:auto;margin-bottom:8px}
|
|
@@ -153,7 +167,7 @@ window.__ModuleLoader__.load({
|
|
|
153
167
|
.dsa-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;height:100%;padding:24px;text-align:center}
|
|
154
168
|
.dsa-note{font-size:13px;line-height:1.6;color:var(--dsw-alias-label-secondary,rgb(207,211,214))}
|
|
155
169
|
.dsa-hint{font-size:12px;line-height:18px;color:var(--dsw-alias-label-caption,rgb(129,133,140))}
|
|
156
|
-
.dsa-toast{display:flex;align-items:center;gap:8px;margin:8px auto 0;width:min(100
|
|
170
|
+
.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}
|
|
157
171
|
.dsa-toast[data-kind=err]{color:var(--dsw-alias-state-error-primary,#f25a5a)}
|
|
158
172
|
`
|
|
159
173
|
|
|
@@ -174,95 +188,6 @@ window.__ModuleLoader__.load({
|
|
|
174
188
|
return h(component, { size: props.size ?? 16, className: props.className })
|
|
175
189
|
}
|
|
176
190
|
|
|
177
|
-
/** Escape one text run before it becomes HTML. */
|
|
178
|
-
function escapeHtml(value) {
|
|
179
|
-
return String(value)
|
|
180
|
-
.replace(/&/g, '&')
|
|
181
|
-
.replace(/</g, '<')
|
|
182
|
-
.replace(/>/g, '>')
|
|
183
|
-
.replace(/"/g, '"')
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/** Inline markdown: code spans, bold, links. Everything else is escaped. */
|
|
187
|
-
function inlineHtml(text) {
|
|
188
|
-
let out = escapeHtml(text)
|
|
189
|
-
out = out.replace(/`([^`]+)`/g, (_, code) => `<code>${code}</code>`)
|
|
190
|
-
out = out.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
191
|
-
out = out.replace(/\[([^\]]+)\]\((https?:[^)\s]+)\)/g, (_, label, href) => {
|
|
192
|
-
const safe = href.replace(/"/g, '"')
|
|
193
|
-
return `<a href="${safe}" target="_blank" rel="noreferrer noopener">${label}</a>`
|
|
194
|
-
})
|
|
195
|
-
return out
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* A small markdown subset: fenced code, headings, lists, paragraphs. The
|
|
200
|
-
* panel shows the same prose the console page shows; raw HTML is never
|
|
201
|
-
* passed through.
|
|
202
|
-
*/
|
|
203
|
-
function markdownHtml(text) {
|
|
204
|
-
const source = String(text ?? '')
|
|
205
|
-
const blocks = []
|
|
206
|
-
const fence = /```([a-zA-Z0-9-]*)\n([\s\S]*?)```/g
|
|
207
|
-
let rest = source.replace(fence, (_, language, body) => {
|
|
208
|
-
blocks.push(`<pre><code>${escapeHtml(body.replace(/\n$/, ''))}</code></pre>`)
|
|
209
|
-
return `\u0000${blocks.length - 1}\u0000`
|
|
210
|
-
})
|
|
211
|
-
const lines = rest.split('\n')
|
|
212
|
-
const html = []
|
|
213
|
-
let paragraph = []
|
|
214
|
-
let list = null
|
|
215
|
-
const flushParagraph = () => {
|
|
216
|
-
if (paragraph.length === 0) return
|
|
217
|
-
html.push(`<p>${inlineHtml(paragraph.join(' '))}</p>`)
|
|
218
|
-
paragraph = []
|
|
219
|
-
}
|
|
220
|
-
const flushList = () => {
|
|
221
|
-
if (!list) return
|
|
222
|
-
html.push(`<${list.tag}>${list.items.map(item => `<li>${inlineHtml(item)}</li>`).join('')}</${list.tag}>`)
|
|
223
|
-
list = null
|
|
224
|
-
}
|
|
225
|
-
for (const line of lines) {
|
|
226
|
-
const placeholder = line.match(/^\u0000(\d+)\u0000$/)
|
|
227
|
-
if (placeholder) {
|
|
228
|
-
flushParagraph()
|
|
229
|
-
flushList()
|
|
230
|
-
html.push(blocks[Number(placeholder[1])] ?? '')
|
|
231
|
-
continue
|
|
232
|
-
}
|
|
233
|
-
if (!line.trim()) {
|
|
234
|
-
flushParagraph()
|
|
235
|
-
flushList()
|
|
236
|
-
continue
|
|
237
|
-
}
|
|
238
|
-
const heading = line.match(/^(#{1,3})\s+(.*)$/)
|
|
239
|
-
if (heading) {
|
|
240
|
-
flushParagraph()
|
|
241
|
-
flushList()
|
|
242
|
-
const level = Math.min(3, heading[1].length)
|
|
243
|
-
html.push(`<h${level}>${inlineHtml(heading[2])}</h${level}>`)
|
|
244
|
-
continue
|
|
245
|
-
}
|
|
246
|
-
const bullet = line.match(/^\s*[-*]\s+(.*)$/)
|
|
247
|
-
const ordered = line.match(/^\s*\d+[.)]\s+(.*)$/)
|
|
248
|
-
if (bullet || ordered) {
|
|
249
|
-
flushParagraph()
|
|
250
|
-
const tag = bullet ? 'ul' : 'ol'
|
|
251
|
-
if (!list || list.tag !== tag) {
|
|
252
|
-
flushList()
|
|
253
|
-
list = { tag, items: [] }
|
|
254
|
-
}
|
|
255
|
-
list.items.push((bullet ?? ordered)[1])
|
|
256
|
-
continue
|
|
257
|
-
}
|
|
258
|
-
flushList()
|
|
259
|
-
paragraph.push(line.trim())
|
|
260
|
-
}
|
|
261
|
-
flushParagraph()
|
|
262
|
-
flushList()
|
|
263
|
-
return html.join('')
|
|
264
|
-
}
|
|
265
|
-
|
|
266
191
|
/** Local echo while a sent message waits for the host to accept it. */
|
|
267
192
|
let localSeq = 0
|
|
268
193
|
|
|
@@ -341,6 +266,8 @@ window.__ModuleLoader__.load({
|
|
|
341
266
|
conn: 'connecting',
|
|
342
267
|
mode: 'queue',
|
|
343
268
|
toast: null,
|
|
269
|
+
canceling: false,
|
|
270
|
+
approvalBusy: {},
|
|
344
271
|
typing: false,
|
|
345
272
|
sending: false,
|
|
346
273
|
currentId: null,
|
|
@@ -353,6 +280,13 @@ window.__ModuleLoader__.load({
|
|
|
353
280
|
return messages.map(message => (message.id === id ? { ...message, ...patch } : message))
|
|
354
281
|
}
|
|
355
282
|
|
|
283
|
+
/** Drop one key from a busy-map without touching the rest. */
|
|
284
|
+
function omitKey(map, key) {
|
|
285
|
+
const next = { ...(map ?? {}) }
|
|
286
|
+
delete next[key]
|
|
287
|
+
return next
|
|
288
|
+
}
|
|
289
|
+
|
|
356
290
|
/** Add or update a tool chip on the streaming assistant message. */
|
|
357
291
|
function upsertTool(messages, id, tool) {
|
|
358
292
|
return messages.map(message => {
|
|
@@ -388,7 +322,7 @@ window.__ModuleLoader__.load({
|
|
|
388
322
|
case 'step/start':
|
|
389
323
|
return { ...model, typing: true }
|
|
390
324
|
case 'turn/end': {
|
|
391
|
-
let next = { ...model, typing: false }
|
|
325
|
+
let next = { ...model, typing: false, canceling: false }
|
|
392
326
|
if (next.currentId) {
|
|
393
327
|
next = { ...next, messages: patchMessage(next.messages, next.currentId, { streaming: false }), currentId: null }
|
|
394
328
|
}
|
|
@@ -502,7 +436,7 @@ window.__ModuleLoader__.load({
|
|
|
502
436
|
return { ...model, sessionId: frame.sessionId ?? model.sessionId, capabilities: frame.capabilities ?? model.capabilities, conn: 'live' }
|
|
503
437
|
case 'session':
|
|
504
438
|
if (!frame.sessionId || frame.sessionId === model.sessionId) return model
|
|
505
|
-
return { ...model, sessionId: frame.sessionId, messages: [], approvals: [], currentId: null, typing: false }
|
|
439
|
+
return { ...model, sessionId: frame.sessionId, messages: [], approvals: [], approvalBusy: {}, currentId: null, typing: false, canceling: false }
|
|
506
440
|
case 'stream.snapshot': {
|
|
507
441
|
let next = { ...model, messages: [], currentId: null }
|
|
508
442
|
if (frame.header?.id) next.sessionId = frame.header.id
|
|
@@ -534,7 +468,7 @@ window.__ModuleLoader__.load({
|
|
|
534
468
|
case 'runs':
|
|
535
469
|
return { ...model, runs: Array.isArray(frame.runs) ? frame.runs : [] }
|
|
536
470
|
case 'canceling':
|
|
537
|
-
return model
|
|
471
|
+
return { ...model, canceling: true }
|
|
538
472
|
case 'error':
|
|
539
473
|
return { ...model, conn: frame.code === 'follow-failed' || frame.code === 'state-failed' ? 'warn' : model.conn }
|
|
540
474
|
case 'closed':
|
|
@@ -562,11 +496,11 @@ window.__ModuleLoader__.load({
|
|
|
562
496
|
}
|
|
563
497
|
|
|
564
498
|
function UserMessage(props) {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
499
|
+
const pending = props.message.pending === true
|
|
500
|
+
return h('div', { className: 'dsa-user', style: pending ? { opacity: 0.6 } : undefined },
|
|
501
|
+
UserMessageBubble
|
|
502
|
+
? h(UserMessageBubble, { className: pending ? 'dsa-bubble-pending' : undefined }, props.message.text)
|
|
503
|
+
: h('div', { className: 'dsa-bubble', 'data-pending': pending ? 'true' : 'false' }, props.message.text))
|
|
570
504
|
}
|
|
571
505
|
|
|
572
506
|
function AssistantMessage(props) {
|
|
@@ -585,12 +519,14 @@ window.__ModuleLoader__.load({
|
|
|
585
519
|
}, tool.name))))
|
|
586
520
|
}
|
|
587
521
|
if (message.text) {
|
|
588
|
-
children.push(
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
522
|
+
children.push(MarkdownText
|
|
523
|
+
? h(MarkdownText, {
|
|
524
|
+
key: 'text',
|
|
525
|
+
text: message.text,
|
|
526
|
+
streaming: message.streaming === true,
|
|
527
|
+
labels: MARKDOWN_LABELS,
|
|
528
|
+
})
|
|
529
|
+
: h('div', { key: 'text', className: 'dsa-md-plain' }, message.text))
|
|
594
530
|
}
|
|
595
531
|
return h('div', { className: 'dsa-assistant' }, children)
|
|
596
532
|
}
|
|
@@ -614,31 +550,42 @@ window.__ModuleLoader__.load({
|
|
|
614
550
|
|
|
615
551
|
function Approvals(props) {
|
|
616
552
|
if (!props.approvals.length) return null
|
|
617
|
-
return h('div', { className: 'dsa-approvals' }, props.approvals.map(entry =>
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
:
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
className:
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
553
|
+
return h('div', { className: 'dsa-approvals' }, props.approvals.map(entry => {
|
|
554
|
+
const busy = props.busy?.[entry.id] === true
|
|
555
|
+
return h('div', {
|
|
556
|
+
key: entry.id,
|
|
557
|
+
className: 'dsa-approval',
|
|
558
|
+
'aria-busy': busy ? 'true' : undefined,
|
|
559
|
+
},
|
|
560
|
+
h('div', { className: 'dsa-approval-bar' },
|
|
561
|
+
StateDot ? h(StateDot, { state: 'warning', size: 10 }) : null,
|
|
562
|
+
h('span', null, '等待你的批准')),
|
|
563
|
+
h('div', { className: 'dsa-approval-main' },
|
|
564
|
+
h('div', { className: 'dsa-approval-title' }, entry.toolName ?? '工具调用'),
|
|
565
|
+
entry.callArguments || entry.reason
|
|
566
|
+
? h('div', { className: 'dsa-approval-body' }, entry.callArguments ?? entry.reason)
|
|
567
|
+
: null,
|
|
568
|
+
h('div', { className: 'dsa-approval-actions' },
|
|
569
|
+
h(Button ?? 'button', {
|
|
570
|
+
variant: Button ? 'outline' : undefined,
|
|
571
|
+
className: Button ? undefined : 'dsa-add',
|
|
572
|
+
type: Button ? undefined : 'button',
|
|
573
|
+
disabled: busy,
|
|
574
|
+
onClick: () => props.onDecide(entry.id, 'reject'),
|
|
575
|
+
}, '拒绝'),
|
|
576
|
+
h(Button ?? 'button', {
|
|
577
|
+
variant: Button ? 'primary' : undefined,
|
|
578
|
+
type: Button ? undefined : 'button',
|
|
579
|
+
disabled: busy,
|
|
580
|
+
onClick: () => props.onDecide(entry.id, 'allow'),
|
|
581
|
+
}, '允许一次'),
|
|
582
|
+
h(Button ?? 'button', {
|
|
583
|
+
variant: Button ? 'outline' : undefined,
|
|
584
|
+
type: Button ? undefined : 'button',
|
|
585
|
+
disabled: busy,
|
|
586
|
+
onClick: () => props.onDecide(entry.id, 'allow-tool'),
|
|
587
|
+
}, '本会话都放行'))))
|
|
588
|
+
}))
|
|
642
589
|
}
|
|
643
590
|
|
|
644
591
|
function Composer(props) {
|
|
@@ -736,13 +683,23 @@ window.__ModuleLoader__.load({
|
|
|
736
683
|
h('option', { value: 'queue' }, '排队'),
|
|
737
684
|
h('option', { value: 'steer' }, '插话'))),
|
|
738
685
|
h('div', { className: 'dsa-trailing' },
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
686
|
+
props.running
|
|
687
|
+
? h('button', {
|
|
688
|
+
type: 'button',
|
|
689
|
+
className: 'dsa-send',
|
|
690
|
+
'data-mode': 'stop',
|
|
691
|
+
'aria-label': '停止本轮',
|
|
692
|
+
title: '停止本轮',
|
|
693
|
+
disabled: props.canceling === true,
|
|
694
|
+
onClick: () => props.onStop?.(),
|
|
695
|
+
}, props.canceling ? h('span', { className: 'dsa-spin' }) : h(Icon, { of: 'stop', size: 10 }))
|
|
696
|
+
: h('button', {
|
|
697
|
+
type: 'button',
|
|
698
|
+
className: 'dsa-send',
|
|
699
|
+
disabled: disabled || !text.trim(),
|
|
700
|
+
title: '发送',
|
|
701
|
+
onClick: submit,
|
|
702
|
+
}, h(Icon, { of: 'send', size: 15 }))))),
|
|
746
703
|
h('div', { className: 'dsa-stats' },
|
|
747
704
|
h('span', null, props.model.sessionId ? `会话 ${shortId(props.model.sessionId)}` : '还没有会话'),
|
|
748
705
|
h('span', null, `${props.model.runs.length} 条任务线`)))
|
|
@@ -834,6 +791,9 @@ window.__ModuleLoader__.load({
|
|
|
834
791
|
model,
|
|
835
792
|
mode: model.mode,
|
|
836
793
|
disabled: model.sending,
|
|
794
|
+
running: model.typing,
|
|
795
|
+
canceling: model.canceling,
|
|
796
|
+
onStop: () => dispatch({ type: 'cancel' }),
|
|
837
797
|
onSend: text => dispatch({ type: 'send', text }),
|
|
838
798
|
onMode: mode => dispatch({ type: 'mode', mode }),
|
|
839
799
|
onError: notify,
|
|
@@ -841,12 +801,16 @@ window.__ModuleLoader__.load({
|
|
|
841
801
|
: h(Transcript, { model, scrollRef: model.scrollRef }),
|
|
842
802
|
h(Approvals, {
|
|
843
803
|
approvals: model.approvals,
|
|
804
|
+
busy: model.approvalBusy,
|
|
844
805
|
onDecide: (id, decision) => dispatch({ type: 'decide', id, decision }),
|
|
845
806
|
}),
|
|
846
807
|
empty ? null : h(Composer, {
|
|
847
808
|
model,
|
|
848
809
|
mode: model.mode,
|
|
849
810
|
disabled: model.sending || model.capabilities?.chat === false,
|
|
811
|
+
running: model.typing,
|
|
812
|
+
canceling: model.canceling,
|
|
813
|
+
onStop: () => dispatch({ type: 'cancel' }),
|
|
850
814
|
onSend: text => dispatch({ type: 'send', text }),
|
|
851
815
|
onMode: mode => dispatch({ type: 'mode', mode }),
|
|
852
816
|
onError: notify,
|
|
@@ -982,11 +946,27 @@ window.__ModuleLoader__.load({
|
|
|
982
946
|
},
|
|
983
947
|
decide: async action => {
|
|
984
948
|
const { id, decision } = action
|
|
949
|
+
patch(current => ({ ...current, approvalBusy: { ...current.approvalBusy, [id]: true } }))
|
|
985
950
|
try {
|
|
986
951
|
await call('/approval', { method: 'POST', body: JSON.stringify({ id, decision }) })
|
|
987
|
-
patch(current => ({
|
|
988
|
-
|
|
989
|
-
|
|
952
|
+
patch(current => ({
|
|
953
|
+
...current,
|
|
954
|
+
approvals: current.approvals.filter(entry => entry.id !== id),
|
|
955
|
+
approvalBusy: omitKey(current.approvalBusy, id),
|
|
956
|
+
}))
|
|
957
|
+
} catch (error) {
|
|
958
|
+
// The card stays and the failure surfaces instead of vanishing.
|
|
959
|
+
patch(current => ({ ...current, approvalBusy: omitKey(current.approvalBusy, id) }))
|
|
960
|
+
throw error
|
|
961
|
+
}
|
|
962
|
+
},
|
|
963
|
+
cancel: async () => {
|
|
964
|
+
patch(current => ({ ...current, canceling: true }))
|
|
965
|
+
try {
|
|
966
|
+
await call('/cancel', { method: 'POST', body: JSON.stringify({ sessionId: modelRef.current.sessionId }) })
|
|
967
|
+
} catch (error) {
|
|
968
|
+
patch(current => ({ ...current, canceling: false }))
|
|
969
|
+
throw error
|
|
990
970
|
}
|
|
991
971
|
},
|
|
992
972
|
switch: async action => {
|
package/lib/console.js
CHANGED
|
@@ -1239,6 +1239,31 @@ export function createConsole({
|
|
|
1239
1239
|
return
|
|
1240
1240
|
}
|
|
1241
1241
|
|
|
1242
|
+
if (leaf === 'cancel' && parts.length === 3) {
|
|
1243
|
+
if (method !== 'POST') throw new WorkbenchError(405, 'only POST is allowed here', { id: 'method-not-allowed' })
|
|
1244
|
+
const body = await readJson(req)
|
|
1245
|
+
const ensured = await ensureSession()
|
|
1246
|
+
if (typeof body.sessionId === 'string' && body.sessionId && body.sessionId !== ensured.sessionId) {
|
|
1247
|
+
throw new WorkbenchError(409, 'the cancel targets a conversation this console is not showing', {
|
|
1248
|
+
id: 'session-mismatch',
|
|
1249
|
+
hint: 'reload the page; the console keeps one active conversation at a time.',
|
|
1250
|
+
})
|
|
1251
|
+
}
|
|
1252
|
+
if (typeof host.cancelTurn !== 'function') {
|
|
1253
|
+
throw new WorkbenchError(501, 'this host cannot stop a turn', { id: 'cancel-unsupported' })
|
|
1254
|
+
}
|
|
1255
|
+
try {
|
|
1256
|
+
await host.cancelTurn(ensured.sessionId)
|
|
1257
|
+
} catch (error) {
|
|
1258
|
+
throw new WorkbenchError(502, `the host refused to stop the turn: ${messageOf(error)}`, {
|
|
1259
|
+
id: 'cancel-failed',
|
|
1260
|
+
})
|
|
1261
|
+
}
|
|
1262
|
+
broadcast({ type: 'canceling', sessionId: ensured.sessionId })
|
|
1263
|
+
send(res, 200, { ok: true, data: { canceling: true } })
|
|
1264
|
+
return
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1242
1267
|
if (leaf === 'message' && parts.length === 3) {
|
|
1243
1268
|
if (method !== 'POST') throw new WorkbenchError(405, 'only POST is allowed here', { id: 'method-not-allowed' })
|
|
1244
1269
|
const body = await readJson(req)
|
package/lib/index.js
CHANGED
|
@@ -3807,6 +3807,20 @@ export function apply(ctx, config) {
|
|
|
3807
3807
|
return { accepted: true }
|
|
3808
3808
|
},
|
|
3809
3809
|
|
|
3810
|
+
/**
|
|
3811
|
+
* Stop the turn this conversation is currently running. The session
|
|
3812
|
+
* controller owns admission, so an idle conversation simply acknowledges
|
|
3813
|
+
* that there was nothing left to cancel.
|
|
3814
|
+
*/
|
|
3815
|
+
async cancelTurn(sessionId) {
|
|
3816
|
+
await ready
|
|
3817
|
+
const session = getSessionController()
|
|
3818
|
+
if (!session) throw new Error('sessionController is not mounted')
|
|
3819
|
+
if (typeof session.cancel !== 'function') throw new Error('this session controller cannot stop a turn')
|
|
3820
|
+
const value = await session.cancel({ sessionId })
|
|
3821
|
+
return { accepted: value?.accepted !== false }
|
|
3822
|
+
},
|
|
3823
|
+
|
|
3810
3824
|
async listRuns(sessionId) {
|
|
3811
3825
|
await ready
|
|
3812
3826
|
if (stateError) throw stateError
|