@xiangyixie/dsh-superagent 0.14.8 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,36 @@ 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.15.0 — 2026-11-16
12
+
13
+ ### 变化
14
+
15
+ - **界面上的字改成人话。** 空状态、按钮、提醒、审批卡、报错和向导都按你当下要做的事
16
+ 写一句话:具体名词代替抽象名词,不用「一键」「赋能」这类词,不排比,不客套,也不堆
17
+ 感叹号。文案分两处:页面里的固定句子在 `public/console.html`,服务端回给你的错误说明
18
+ 在 `lib/console.js`;状态词、耗时、提醒标题这些跟着 run 记录自动生成。
19
+ - **调度板:一眼看到几条线在跑。** 有任务在跑时,对话上方出现一块调度板:每一步一条
20
+ 时间条,按真实的开始、结束时间画;板头写清同时跑几条任务线、并行几步、几步在等前
21
+ 一步、几条在排队,每行的任务线标题旁是状态和耗时。数据全部读现有 run 记录(含
22
+ `subtasks` 的 `startedAt`/`finishedAt`/`waitingOn` 和 `limits.maxParallel`、
23
+ `queue.position`),没有第二套状态。窗口窄到 720px 时每一步改成上下两行,时间条
24
+ 占满宽度,不会挤在一起。
25
+
26
+ ## 0.14.9 — 2026-11-16
27
+
28
+ ### 变化
29
+
30
+ - **文件可以直接拖进输入框,也能粘贴进来。** 拖到输入框或按 Ctrl+V 粘贴的图片、文档会
31
+ 复制到当前对话的工作区,路径自动写进消息,我拿到就能读。单个文件 8MB 以内,只收
32
+ 图片、PDF、Markdown/文本、CSV/JSON、Office 文档、压缩包和代码文件;类型或大小不
33
+ 合适时直接告诉你「不能放什么、可以放什么」,不会静默失败。文件只会落在当前对话的
34
+ 工作区里,不会写到别处,也不会覆盖上一次放的同名文件。
35
+ - **关掉页面也知道发生了什么。** 任务跑完、没走通、或者在等你批准时,页面会亮起提醒:
36
+ 标题变成「(1) Superagent 专属空间」这样的未读计数,右上角出现「提醒」入口。重新
37
+ 打开页面还能看到当时的结果——「跑完了」「没走通」「要你批准」都还在,点一条就能跳到
38
+ 对应的任务线;已经看过的提醒不会重复打扰。任务结束时的通知仍然走插件原来的通道,
39
+ 所以即使页面一直关着,回到对话里也能看到完成或需要决定的说明。
40
+
11
41
  ## 0.14.8 — 2026-11-16
12
42
 
13
43
  ### 变化
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.14.8` → install.
39
+ Desktop: **Plugins** → **Add plugin** → enter `@xiangyixie/dsh-superagent@0.15.0` → install.
40
40
 
41
41
  CLI:
42
42
 
43
43
  ```bash
44
- dsh plugin --profile web add @xiangyixie/dsh-superagent@0.14.8
44
+ dsh plugin --profile web add @xiangyixie/dsh-superagent@0.15.0
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.14.8` and read the host log for `[dsh-superagent]` lines. |
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.15.0` 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.14.8` → 安装。
39
+ 桌面端:侧边栏 **插件** → **Add plugin** → 输入 `@xiangyixie/dsh-superagent@0.15.0` → 安装。
40
40
 
41
41
  命令行:
42
42
 
43
43
  ```bash
44
- dsh plugin --profile web add @xiangyixie/dsh-superagent@0.14.8
44
+ dsh plugin --profile web add @xiangyixie/dsh-superagent@0.15.0
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.14.8` 重装,并在宿主日志里找 `[dsh-superagent]` 行。 |
1093
+ | `superagent_*` 工具不存在 | bundle 行没挂上,或者宿主拒绝加载插件。 | 跑 `--dump-config` 查 `@xiangyixie/dsh-superagent` 块;用 `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.15.0` 重装,并在宿主日志里找 `[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.14.8` → 安装。
39
+ 桌面端:侧边栏 **插件** → **Add plugin** → 输入 `@xiangyixie/dsh-superagent@0.15.0` → 安装。
40
40
 
41
41
  命令行:
42
42
 
43
43
  ```bash
44
- dsh plugin --profile web add @xiangyixie/dsh-superagent@0.14.8
44
+ dsh plugin --profile web add @xiangyixie/dsh-superagent@0.15.0
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.14.8` 重装,并在宿主日志里找 `[dsh-superagent]` 行。 |
1093
+ | `superagent_*` 工具不存在 | bundle 行没挂上,或者宿主拒绝加载插件。 | 跑 `--dump-config` 查 `@xiangyixie/dsh-superagent` 块;用 `dsh plugin --profile <p> add @xiangyixie/dsh-superagent@0.15.0` 重装,并在宿主日志里找 `[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/console.js CHANGED
@@ -14,6 +14,7 @@ import { readFileSync } from 'node:fs'
14
14
  import fsp from 'node:fs/promises'
15
15
  import { createServer } from 'node:http'
16
16
  import path from 'node:path'
17
+ import { isInside } from './memory.js'
17
18
  import {
18
19
  errorPayload,
19
20
  readJson,
@@ -47,6 +48,28 @@ const REQUEST_TIMEOUT_MS = 30_000
47
48
  const APPROVAL_TIMEOUT_MS = 10 * 60 * 1000
48
49
  const ROUTE_HINT = 'GET / serves the console; the JSON API is under /api/console.'
49
50
  const MAX_ARTIFACT_BYTES = 2 * 1024 * 1024
51
+ // A file dropped on the composer is copied into the conversation's own
52
+ // workspace. The cap is generous for a screenshot or a deck, small enough that
53
+ // a stray folder cannot fill the disk through the page.
54
+ const MAX_UPLOAD_BYTES = 8 * 1024 * 1024
55
+ // base64 inflates the payload by about a third; the JSON wrapper needs a little
56
+ // more room than the decoded file itself.
57
+ const UPLOAD_BODY_LIMIT = 12 * 1024 * 1024
58
+ const UPLOAD_DIR = '.superagent/uploads'
59
+ const UPLOAD_TYPES = new Set([
60
+ '.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.bmp',
61
+ '.pdf', '.md', '.markdown', '.txt', '.log', '.csv', '.tsv', '.json', '.yml', '.yaml', '.xml',
62
+ '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.rtf',
63
+ '.zip', '.tar', '.gz', '.7z',
64
+ '.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.py', '.css', '.html', '.htm', '.sql', '.sh',
65
+ '.ps1', '.toml', '.ini', '.ipynb',
66
+ ])
67
+ const UPLOAD_TYPES_TEXT = '图片、PDF、Markdown/文本、CSV/JSON、Office 文档、压缩包或代码文件'
68
+ // Which notices a person already read. The notices themselves are derived from
69
+ // durable runs on every load, so reopening the page after a run finished shows
70
+ // "跑完了" without this file having to hold a second copy of the run history.
71
+ const NOTICE_FILE = 'console-notices.json'
72
+ const MAX_READ_NOTICES = 200
50
73
 
51
74
  /** Types the console may preview inline; anything else is refused, not sniffed. */
52
75
  const ARTIFACT_TYPES = new Map([
@@ -147,13 +170,26 @@ function boundedSnapshot(frame) {
147
170
  * @param {object} options.host - host adapter; see README.
148
171
  * @param {string} options.version - plugin version reported by `/api/health`.
149
172
  * @param {(message: string) => void} [options.log] - diagnostics sink.
173
+ * @param {number} [options.maxUploadBytes] - per-file cap for dropped files.
150
174
  */
151
- export function createConsole({ port, stateRoot, host, version, log = () => {} }) {
175
+ export function createConsole({
176
+ port,
177
+ stateRoot,
178
+ host,
179
+ version,
180
+ log = () => {},
181
+ maxUploadBytes = MAX_UPLOAD_BYTES,
182
+ }) {
152
183
  if (!host || typeof host !== 'object') throw new Error('createConsole needs a host adapter')
153
184
  const token = randomBytes(32).toString('base64url')
154
185
  const instanceId = randomBytes(6).toString('hex')
155
186
  const discoveryPath = path.join(stateRoot, DISCOVERY_FILE)
156
187
  const timelinePath = path.join(stateRoot, TIMELINE_FILE)
188
+ const noticePath = path.join(stateRoot, NOTICE_FILE)
189
+ const uploadLimit = Number.isFinite(maxUploadBytes) && maxUploadBytes > 0
190
+ ? Math.floor(maxUploadBytes)
191
+ : MAX_UPLOAD_BYTES
192
+ const noticeRead = new Set()
157
193
  const startedAt = new Date().toISOString()
158
194
  const clients = new Set()
159
195
  // Approval questions raised inside this conversation wait here until the open
@@ -210,6 +246,7 @@ export function createConsole({ port, stateRoot, host, version, log = () => {} }
210
246
  || timeline.records.length > TIMELINE_MAX_RECORDS
211
247
  || timeline.records.reduce((sum, record) => sum + Buffer.byteLength(JSON.stringify(record)), 0) > TIMELINE_MAX_BYTES
212
248
  }
249
+ loadNoticeRead()
213
250
 
214
251
  const url = () => `http://127.0.0.1:${boundPort}`
215
252
  const allowedHosts = () => new Set([
@@ -306,12 +343,13 @@ export function createConsole({ port, stateRoot, host, version, log = () => {} }
306
343
  * the whole fix; a real filesystem error still surfaces to the caller.
307
344
  *
308
345
  * @param {string} tmp - fully written temporary file beside the target.
346
+ * @param {string} [target] - destination; the timeline file by default.
309
347
  * @returns {Promise<void>} resolves once the target holds the new bytes.
310
348
  */
311
- async function replaceTimeline(tmp) {
349
+ async function replaceTimeline(tmp, target = timelinePath) {
312
350
  for (let attempt = 0; ; attempt += 1) {
313
351
  try {
314
- await fsp.rename(tmp, timelinePath)
352
+ await fsp.rename(tmp, target)
315
353
  return
316
354
  } catch (error) {
317
355
  const transient = error?.code === 'EPERM' || error?.code === 'EACCES' || error?.code === 'EBUSY'
@@ -321,6 +359,38 @@ export function createConsole({ port, stateRoot, host, version, log = () => {} }
321
359
  }
322
360
  }
323
361
 
362
+ /** Remembered notice ids, so a badge does not come back after a reload. */
363
+ function loadNoticeRead() {
364
+ try {
365
+ const parsed = JSON.parse(readFileSync(noticePath, 'utf8'))
366
+ for (const id of Array.isArray(parsed?.read) ? parsed.read : []) {
367
+ if (typeof id === 'string' && id.trim()) noticeRead.add(id.trim())
368
+ }
369
+ } catch (error) {
370
+ if (error?.code !== 'ENOENT') log(`console: cannot read ${noticePath}: ${messageOf(error)}`)
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Persist the read set. It is bounded, so a console used for months cannot
376
+ * grow the file without limit; the oldest ids fall off first.
377
+ *
378
+ * @returns {Promise<void>} resolves once the file is replaced (or the failure logged).
379
+ */
380
+ async function saveNoticeRead() {
381
+ const ids = [...noticeRead].slice(-MAX_READ_NOTICES)
382
+ noticeRead.clear()
383
+ for (const id of ids) noticeRead.add(id)
384
+ const tmp = `${noticePath}.${process.pid}.tmp`
385
+ try {
386
+ await fsp.mkdir(path.dirname(noticePath), { recursive: true })
387
+ await fsp.writeFile(tmp, `${JSON.stringify({ version: 1, read: ids })}\n`, 'utf8')
388
+ await replaceTimeline(tmp, noticePath)
389
+ } catch (error) {
390
+ log(`console: cannot save ${noticePath}: ${messageOf(error)}`)
391
+ }
392
+ }
393
+
324
394
  function authorize(req, { allowQuery = false } = {}) {
325
395
  if (!boundPort) {
326
396
  throw new WorkbenchError(503, 'the console is not listening yet', { id: 'not-ready' })
@@ -668,6 +738,7 @@ export function createConsole({ port, stateRoot, host, version, log = () => {} }
668
738
  sessionId: currentSessionId,
669
739
  runs: currentSessionId ? lastRuns ?? [] : [],
670
740
  approvals: [...approvals.values()].map(entry => entry.payload),
741
+ readNoticeIds: [...noticeRead],
671
742
  }
672
743
  }
673
744
 
@@ -829,6 +900,146 @@ export function createConsole({ port, stateRoot, host, version, log = () => {} }
829
900
  sendText(res, 200, body, type, headers)
830
901
  }
831
902
 
903
+ /**
904
+ * A dropped or pasted file keeps its readable name but loses every path bit
905
+ * and every character Windows reserves, so it can only ever become one file
906
+ * inside the upload directory.
907
+ *
908
+ * @param {unknown} raw - name supplied by the page.
909
+ * @returns {string} a bare file name, possibly empty.
910
+ */
911
+ function safeUploadName(raw) {
912
+ const base = path.basename(String(raw ?? '').replace(/\\/g, '/'))
913
+ const cleaned = base.replace(/[\u0000-\u001f\u007f<>:"|?*]/g, '').replace(/^\.+/, '').trim()
914
+ return [...cleaned].slice(0, 80).join('')
915
+ }
916
+
917
+ /**
918
+ * Write the bytes under `dir` without ever overwriting an earlier drop.
919
+ *
920
+ * @param {string} dir - upload directory inside the workspace.
921
+ * @param {string} name - bare file name.
922
+ * @param {Buffer} bytes - decoded content.
923
+ * @returns {Promise<string>} the path actually written.
924
+ */
925
+ async function writeUpload(dir, name, bytes) {
926
+ await fsp.mkdir(dir, { recursive: true })
927
+ const ext = path.extname(name)
928
+ const stem = name.slice(0, name.length - ext.length)
929
+ for (let attempt = 0; attempt < 50; attempt += 1) {
930
+ const candidate = attempt === 0 ? name : `${stem}-${attempt}${ext}`
931
+ const target = path.join(dir, candidate)
932
+ if (!isInside(target, dir)) {
933
+ throw new WorkbenchError(400, '文件名不合法,写不进工作区', { id: 'upload-name' })
934
+ }
935
+ try {
936
+ await fsp.writeFile(target, bytes, { flag: 'wx' })
937
+ return target
938
+ } catch (error) {
939
+ if (error?.code !== 'EEXIST') throw error
940
+ }
941
+ }
942
+ throw new WorkbenchError(409, '同名文件太多了,换个名字再放一次', { id: 'upload-crowded' })
943
+ }
944
+
945
+ /** The per-file cap in words, so both size failures read the same. */
946
+ function uploadCapText() {
947
+ if (uploadLimit >= 1024 * 1024) return `${Math.round(uploadLimit / (1024 * 1024))}MB`
948
+ return `${Math.max(1, Math.round(uploadLimit / 1024))}KB`
949
+ }
950
+
951
+ /**
952
+ * Copy one dropped or pasted file into the conversation's workspace.
953
+ *
954
+ * The page sends bytes and a display name, never a destination: the host
955
+ * resolves the conversation's own workspace and this module keeps the write
956
+ * under it. Unknown extensions are refused instead of sniffed, and the path
957
+ * that would escape the workspace is refused rather than quietly renamed.
958
+ *
959
+ * @param {object} req - the upload request.
960
+ * @param {import('node:http').ServerResponse} res - response sink.
961
+ */
962
+ async function acceptUpload(req, res) {
963
+ const sessionId = currentSessionId
964
+ if (!sessionId) {
965
+ throw new WorkbenchError(409, '先在对话里说一句话,再把文件放进来', {
966
+ id: 'no-session',
967
+ hint: '文件要落在对话的工作区里,所以先有一条对话。',
968
+ })
969
+ }
970
+ let body
971
+ try {
972
+ body = await readJson(req, { limit: UPLOAD_BODY_LIMIT })
973
+ } catch (error) {
974
+ // The generic body cap speaks about editor saves; a drop deserves a
975
+ // sentence about the file the person just tried to add.
976
+ if (error?.status === 413) {
977
+ throw new WorkbenchError(413, `这个文件太大了,单个文件最多 ${uploadCapText()}`, {
978
+ id: 'upload-too-large',
979
+ hint: '压缩一下再放,或者把文件路径写进消息里让我直接读。',
980
+ })
981
+ }
982
+ throw error
983
+ }
984
+ if (typeof body.sessionId === 'string' && body.sessionId && body.sessionId !== sessionId) {
985
+ throw new WorkbenchError(409, '文件要放进当前对话的工作区', {
986
+ id: 'session-mismatch',
987
+ hint: '刷新页面后再放一次。',
988
+ })
989
+ }
990
+ const name = safeUploadName(body.name)
991
+ if (!name) throw new WorkbenchError(400, '文件名不能为空', { id: 'missing-name' })
992
+ const ext = path.extname(name).toLowerCase()
993
+ if (!UPLOAD_TYPES.has(ext)) {
994
+ throw new WorkbenchError(415, `不能放 ${ext ? `${ext} 文件` : '没有扩展名的文件'}`, {
995
+ id: 'upload-type',
996
+ hint: `可以放:${UPLOAD_TYPES_TEXT}。`,
997
+ })
998
+ }
999
+ const data = typeof body.data === 'string' ? body.data : ''
1000
+ if (!data) throw new WorkbenchError(400, '这个文件没有内容', { id: 'missing-data' })
1001
+ const bytes = Buffer.from(data, 'base64')
1002
+ if (bytes.length === 0) {
1003
+ throw new WorkbenchError(400, '这个文件是空的,或者内容读不出来', { id: 'upload-empty' })
1004
+ }
1005
+ if (bytes.length > uploadLimit) {
1006
+ const mb = (bytes.length / (1024 * 1024)).toFixed(1)
1007
+ throw new WorkbenchError(413, `${name} 有 ${mb}MB,超过单个 ${uploadCapText()} 的上限`, {
1008
+ id: 'upload-too-large',
1009
+ hint: '压缩一下再放,或者把文件路径写进消息里让我直接读。',
1010
+ })
1011
+ }
1012
+ if (typeof host.sessionWorkspace !== 'function') {
1013
+ throw new WorkbenchError(501, 'this host cannot tell the console where its workspace is', {
1014
+ id: 'workspace-unavailable',
1015
+ })
1016
+ }
1017
+ let workspace
1018
+ try {
1019
+ workspace = await host.sessionWorkspace(sessionId)
1020
+ } catch (error) {
1021
+ throw new WorkbenchError(502, `cannot resolve the conversation workspace: ${messageOf(error)}`, {
1022
+ id: 'workspace-unavailable',
1023
+ })
1024
+ }
1025
+ if (typeof workspace !== 'string' || !workspace) {
1026
+ throw new WorkbenchError(502, 'the host returned no workspace for this conversation', {
1027
+ id: 'workspace-unavailable',
1028
+ })
1029
+ }
1030
+ const root = path.resolve(workspace)
1031
+ const folder = sessionId.slice(0, 12).replace(/[^a-zA-Z0-9._-]/g, '')
1032
+ const dir = path.resolve(root, UPLOAD_DIR, folder || 'session')
1033
+ if (!isInside(dir, root) || !isInside(path.join(dir, name), dir)) {
1034
+ throw new WorkbenchError(400, '工作区路径不合法,文件没有落盘', { id: 'upload-escape' })
1035
+ }
1036
+ const target = await writeUpload(dir, name, bytes)
1037
+ send(res, 200, {
1038
+ ok: true,
1039
+ data: { path: target, name: path.basename(target), size: bytes.length, dir },
1040
+ })
1041
+ }
1042
+
832
1043
  async function handle(req, res) {
833
1044
  try {
834
1045
  const parsed = new URL(req.url ?? '/', 'http://127.0.0.1')
@@ -888,6 +1099,29 @@ export function createConsole({ port, stateRoot, host, version, log = () => {} }
888
1099
  return
889
1100
  }
890
1101
 
1102
+ // Notices are derived from durable runs on every load; only the ids a
1103
+ // person has already read need remembering.
1104
+ if (leaf === 'notices' && parts.length === 4 && parts[3] === 'read') {
1105
+ if (method !== 'POST') throw new WorkbenchError(405, 'only POST is allowed here', { id: 'method-not-allowed' })
1106
+ const body = await readJson(req)
1107
+ const ids = Array.isArray(body?.ids)
1108
+ ? body.ids
1109
+ .filter(id => typeof id === 'string' && id.trim())
1110
+ .map(id => id.trim())
1111
+ .slice(0, MAX_READ_NOTICES)
1112
+ : []
1113
+ if (ids.length === 0) throw new WorkbenchError(400, 'ids is required', { id: 'missing-ids' })
1114
+ let added = 0
1115
+ for (const id of ids) {
1116
+ if (noticeRead.has(id)) continue
1117
+ noticeRead.add(id)
1118
+ added += 1
1119
+ }
1120
+ if (added > 0) await saveNoticeRead()
1121
+ send(res, 200, { ok: true, data: { read: ids.length, added } })
1122
+ return
1123
+ }
1124
+
891
1125
  if (leaf === 'tools' && parts.length === 3) {
892
1126
  if (method !== 'GET') throw new WorkbenchError(405, 'only GET is allowed here', { id: 'method-not-allowed' })
893
1127
  const sessionId = currentSessionId
@@ -975,6 +1209,14 @@ export function createConsole({ port, stateRoot, host, version, log = () => {} }
975
1209
  return
976
1210
  }
977
1211
 
1212
+ // A file dropped on the composer is copied into this conversation's
1213
+ // workspace, then its path is what the page writes into the message.
1214
+ if (leaf === 'upload' && parts.length === 3) {
1215
+ if (method !== 'POST') throw new WorkbenchError(405, 'only POST is allowed here', { id: 'method-not-allowed' })
1216
+ await acceptUpload(req, res)
1217
+ return
1218
+ }
1219
+
978
1220
  if (leaf === 'events' && parts.length === 3) {
979
1221
  if (method !== 'GET') throw new WorkbenchError(405, 'only GET is allowed here', { id: 'method-not-allowed' })
980
1222
  openStream(req, res)
package/lib/index.js CHANGED
@@ -3546,6 +3546,7 @@ export function apply(ctx, config) {
3546
3546
  const subtasks = Array.isArray(run.subtasks)
3547
3547
  ? run.subtasks.map(subtask => ({
3548
3548
  index: subtask.index ?? null,
3549
+ key: subtask.key ?? null,
3549
3550
  title: subtask.title ?? null,
3550
3551
  status: subtask.status ?? null,
3551
3552
  childId: subtask.childId ?? null,
@@ -3553,6 +3554,11 @@ export function apply(ctx, config) {
3553
3554
  // every lane looks equally busy.
3554
3555
  startedAt: subtask.startedAt ?? null,
3555
3556
  finishedAt: subtask.finishedAt ?? null,
3557
+ // The scheduler already records why a step has not started. Passing
3558
+ // those edges through lets the page draw the same order, instead of
3559
+ // guessing a queue of its own.
3560
+ dependsOn: Array.isArray(subtask.dependsOn) ? subtask.dependsOn.slice(0, 12) : [],
3561
+ waitingOn: Array.isArray(subtask.waitingOn) ? subtask.waitingOn.slice(0, 12) : [],
3556
3562
  tool: subtask.status === 'running' ? runningToolName(subtask.childId) : null,
3557
3563
  }))
3558
3564
  : []
@@ -3562,8 +3568,22 @@ export function apply(ctx, config) {
3562
3568
  goal: run.goal,
3563
3569
  status: run.status,
3564
3570
  createdAt: run.createdAt ?? null,
3571
+ startedAt: run.startedAt ?? null,
3565
3572
  finishedAt: run.finishedAt ?? null,
3566
3573
  parentSessionId: run.parentSessionId ?? null,
3574
+ // The cap the scheduler really used, and the line it is holding in the
3575
+ // queue, are read from the run record rather than re-derived here.
3576
+ limits: run.limits
3577
+ ? { maxParallel: run.limits.maxParallel ?? null, maxSubtasks: run.limits.maxSubtasks ?? null }
3578
+ : null,
3579
+ queue: run.queue
3580
+ ? {
3581
+ waiting: run.queue.waiting === true,
3582
+ position: run.queue.position ?? null,
3583
+ of: run.queue.of ?? null,
3584
+ enqueuedAt: run.queue.enqueuedAt ?? null,
3585
+ }
3586
+ : null,
3567
3587
  cost: cost
3568
3588
  ? {
3569
3589
  totalMicros: cost.totalMicros,
@@ -3721,6 +3741,28 @@ export function apply(ctx, config) {
3721
3741
  return { sessionId: created.sessionId, preset: created.preset ?? cfg.consolePreset ?? null }
3722
3742
  },
3723
3743
 
3744
+ /**
3745
+ * The directory a conversation writes into. A dropped file is stored
3746
+ * under it, so the answer comes from the session record, never from the
3747
+ * page: a page that could name its own directory could name any one.
3748
+ */
3749
+ async sessionWorkspace(sessionId) {
3750
+ const controller = getSessionController()
3751
+ if (!controller || typeof controller.list !== 'function') return consoleRoot
3752
+ try {
3753
+ const listed = await controller.list()
3754
+ const items = Array.isArray(listed) ? listed : Array.isArray(listed?.items) ? listed.items : []
3755
+ const hit = items.find(item => item
3756
+ && item.sessionId === sessionId
3757
+ && item.parentSessionId === undefined
3758
+ && typeof item.cwd === 'string'
3759
+ && item.cwd)
3760
+ return hit ? path.resolve(hit.cwd) : consoleRoot
3761
+ } catch {
3762
+ return consoleRoot
3763
+ }
3764
+ },
3765
+
3724
3766
  /**
3725
3767
  * The tools this conversation actually has, read from the live agent's
3726
3768
  * scope rather than a list kept here. Resolving a blank session starts
package/lib/workbench.js CHANGED
@@ -152,8 +152,17 @@ function readBody(req, limit = BODY_LIMIT) {
152
152
  })
153
153
  }
154
154
 
155
- export async function readJson(req) {
156
- const text = (await readBody(req)).trim()
155
+ /**
156
+ * Parse a JSON request body.
157
+ *
158
+ * @param {import('node:http').IncomingMessage} req - request to read.
159
+ * @param {object} [options] - body cap for routes that carry a payload (an
160
+ * uploaded file is base64, so it needs more room than editor text).
161
+ * @param {number} [options.limit] - maximum body bytes; defaults to `BODY_LIMIT`.
162
+ * @returns {Promise<object>} the parsed object.
163
+ */
164
+ export async function readJson(req, { limit = BODY_LIMIT } = {}) {
165
+ const text = (await readBody(req, limit)).trim()
157
166
  if (!text) return {}
158
167
  let parsed
159
168
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiangyixie/dsh-superagent",
3
- "version": "0.14.8",
3
+ "version": "0.15.0",
4
4
  "description": "长周期自主执行插件:一个目标拆成可并行的子任务,交付一份合并报告,重启后仍可继续。",
5
5
  "author": "Admire (LittleChenLiya)",
6
6
  "type": "module",