@xiangyixie/dsh-superagent 0.14.8 → 0.14.9

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,21 @@ 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.14.9 — 2026-11-16
12
+
13
+ ### 变化
14
+
15
+ - **文件可以直接拖进输入框,也能粘贴进来。** 拖到输入框或按 Ctrl+V 粘贴的图片、文档会
16
+ 复制到当前对话的工作区,路径自动写进消息,我拿到就能读。单个文件 8MB 以内,只收
17
+ 图片、PDF、Markdown/文本、CSV/JSON、Office 文档、压缩包和代码文件;类型或大小不
18
+ 合适时直接告诉你「不能放什么、可以放什么」,不会静默失败。文件只会落在当前对话的
19
+ 工作区里,不会写到别处,也不会覆盖上一次放的同名文件。
20
+ - **关掉页面也知道发生了什么。** 任务跑完、没走通、或者在等你批准时,页面会亮起提醒:
21
+ 标题变成「(1) Superagent 专属空间」这样的未读计数,右上角出现「提醒」入口。重新
22
+ 打开页面还能看到当时的结果——「跑完了」「没走通」「要你批准」都还在,点一条就能跳到
23
+ 对应的任务线;已经看过的提醒不会重复打扰。任务结束时的通知仍然走插件原来的通道,
24
+ 所以即使页面一直关着,回到对话里也能看到完成或需要决定的说明。
25
+
11
26
  ## 0.14.8 — 2026-11-16
12
27
 
13
28
  ### 变化
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.14.9` → 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.14.9
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.14.9` 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.14.9` → 安装。
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.14.9
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.14.9` 重装,并在宿主日志里找 `[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.14.9` → 安装。
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.14.9
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.14.9` 重装,并在宿主日志里找 `[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
@@ -3721,6 +3721,28 @@ export function apply(ctx, config) {
3721
3721
  return { sessionId: created.sessionId, preset: created.preset ?? cfg.consolePreset ?? null }
3722
3722
  },
3723
3723
 
3724
+ /**
3725
+ * The directory a conversation writes into. A dropped file is stored
3726
+ * under it, so the answer comes from the session record, never from the
3727
+ * page: a page that could name its own directory could name any one.
3728
+ */
3729
+ async sessionWorkspace(sessionId) {
3730
+ const controller = getSessionController()
3731
+ if (!controller || typeof controller.list !== 'function') return consoleRoot
3732
+ try {
3733
+ const listed = await controller.list()
3734
+ const items = Array.isArray(listed) ? listed : Array.isArray(listed?.items) ? listed.items : []
3735
+ const hit = items.find(item => item
3736
+ && item.sessionId === sessionId
3737
+ && item.parentSessionId === undefined
3738
+ && typeof item.cwd === 'string'
3739
+ && item.cwd)
3740
+ return hit ? path.resolve(hit.cwd) : consoleRoot
3741
+ } catch {
3742
+ return consoleRoot
3743
+ }
3744
+ },
3745
+
3724
3746
  /**
3725
3747
  * The tools this conversation actually has, read from the live agent's
3726
3748
  * 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.14.9",
4
4
  "description": "长周期自主执行插件:一个目标拆成可并行的子任务,交付一份合并报告,重启后仍可继续。",
5
5
  "author": "Admire (LittleChenLiya)",
6
6
  "type": "module",
@@ -481,6 +481,41 @@
481
481
  }
482
482
  .toast.err { border-color: rgba(255, 123, 114, .4); color: #ffc0bb; }
483
483
  .toast.ok { border-color: rgba(99, 214, 164, .35); }
484
+ .toast.warn { border-color: rgba(246, 193, 119, .4); color: #ffd8a1; }
485
+
486
+ .notice-btn { position: relative; }
487
+ .notice-btn.has-unread { border-color: rgba(246, 193, 119, .5); color: var(--amber); }
488
+ .notice-btn .count {
489
+ display: inline-block; min-width: 16px; margin-left: 6px; padding: 0 4px;
490
+ border-radius: 8px; background: rgba(246, 193, 119, .18); color: var(--amber);
491
+ font-size: 11px; text-align: center;
492
+ }
493
+ .notice-panel {
494
+ position: fixed; top: 58px; right: 14px; z-index: 26; width: 322px; max-height: 62vh;
495
+ display: flex; flex-direction: column; padding: 10px 10px 8px;
496
+ border: 1px solid var(--line); border-radius: 12px; background: #111a1f;
497
+ box-shadow: 0 18px 44px rgba(0, 0, 0, .45);
498
+ }
499
+ .notice-panel[hidden] { display: none; }
500
+ .notice-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 8px; }
501
+ .notice-head .kicker { color: var(--accent); font: 10px var(--mono); letter-spacing: .14em; text-transform: uppercase; }
502
+ .notice-list { display: flex; flex-direction: column; gap: 6px; overflow: auto; }
503
+ .notice-item {
504
+ display: flex; gap: 8px; align-items: flex-start; padding: 8px 9px; border-radius: 9px;
505
+ border: 1px solid var(--line-soft); background: #0e1418; font-size: 12px; cursor: pointer;
506
+ }
507
+ .notice-item.unread { border-color: rgba(246, 193, 119, .35); background: rgba(246, 193, 119, .06); }
508
+ .notice-item .dot { width: 6px; height: 6px; margin-top: 5px; border-radius: 50%; background: var(--faint); flex: none; }
509
+ .notice-item.unread .dot { background: var(--amber); }
510
+ .notice-item .body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
511
+ .notice-item .title { font-weight: 600; color: var(--text); }
512
+ .notice-item .detail { color: var(--faint); line-height: 1.4; word-break: break-word; }
513
+ .notice-item .when { color: var(--faint); font-size: 11px; }
514
+ .notice-empty { padding: 14px 6px; color: var(--faint); font-size: 12px; text-align: center; }
515
+ .composer.dragover .composer-box {
516
+ border-color: rgba(94, 234, 212, .7); background: rgba(94, 234, 212, .06);
517
+ box-shadow: 0 0 0 4px rgba(94, 234, 212, .12);
518
+ }
484
519
 
485
520
  .gate {
486
521
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
@@ -682,6 +717,7 @@
682
717
  <div class="topbar-actions">
683
718
  <span id="conn" class="conn"><i></i><span id="connText">连接中</span></span>
684
719
  <button id="stopAll" class="btn danger" type="button" hidden>停止这一轮</button>
720
+ <button id="noticeOpen" class="btn notice-btn" type="button" hidden>提醒<span id="noticeCount" class="count">0</span></button>
685
721
  <button id="newChatTop" class="btn" type="button" disabled>新对话</button>
686
722
  <button id="historyOpen" class="btn" type="button">历史</button>
687
723
  <button id="advancedOpen" class="btn" type="button">高级</button>
@@ -719,6 +755,14 @@
719
755
 
720
756
  <div id="scrim" class="scrim" hidden></div>
721
757
 
758
+ <div id="noticePanel" class="notice-panel" hidden>
759
+ <div class="notice-head">
760
+ <span class="kicker">提醒</span>
761
+ <button id="noticeReadAll" class="btn tiny" type="button">全部已读</button>
762
+ </div>
763
+ <div id="noticeList" class="notice-list"></div>
764
+ </div>
765
+
722
766
  <aside id="historyDrawer" class="drawer" hidden aria-label="历史">
723
767
  <div class="drawer-head">
724
768
  <div>
@@ -846,6 +890,23 @@
846
890
  const advancedDrawerEl = $('advancedDrawer')
847
891
  const advSessionEl = $('advSession')
848
892
  const advRunsEl = $('advRuns')
893
+ const noticeOpenEl = $('noticeOpen')
894
+ const noticeCountEl = $('noticeCount')
895
+ const noticePanelEl = $('noticePanel')
896
+ const noticeListEl = $('noticeList')
897
+
898
+ // Upload rules mirror the server's: the page refuses early with a readable
899
+ // sentence, and the server refuses again because a page is not a gate.
900
+ const UPLOAD_MAX = 8 * 1024 * 1024
901
+ const UPLOAD_EXTS = new Set([
902
+ '.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.bmp',
903
+ '.pdf', '.md', '.markdown', '.txt', '.log', '.csv', '.tsv', '.json', '.yml', '.yaml', '.xml',
904
+ '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.rtf',
905
+ '.zip', '.tar', '.gz', '.7z',
906
+ '.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.py', '.css', '.html', '.htm', '.sql', '.sh',
907
+ '.ps1', '.toml', '.ini', '.ipynb',
908
+ ])
909
+ const UPLOAD_HINT = '图片、PDF、Markdown/文本、CSV/JSON、Office 文档、压缩包或代码文件'
849
910
 
850
911
  const STATE = {
851
912
  token: '',
@@ -879,6 +940,11 @@
879
940
  sessionNote: null,
880
941
  cancelRequested: new Set(),
881
942
  stopAllBusy: false,
943
+ notices: [],
944
+ readNotices: new Set(),
945
+ noticeOpen: false,
946
+ noticesPrimed: false,
947
+ dragDepth: 0,
882
948
  }
883
949
 
884
950
  const WIZ = {
@@ -1260,6 +1326,225 @@
1260
1326
  inputEl.style.height = `${Math.min(180, Math.max(46, inputEl.scrollHeight))}px`
1261
1327
  }
1262
1328
 
1329
+ // ---------- notices ----------
1330
+ //
1331
+ // A finished run, a failure and a pending decision are all durable on the
1332
+ // host. The page turns them into the same short list every time it loads, so
1333
+ // closing the tab loses nothing: reopening shows "跑完了" or "要你批准" again.
1334
+ // Only the ids a person has already read travel back to the server.
1335
+
1336
+ function noticeWhen(at) {
1337
+ const ms = typeof at === 'number' ? at : Date.parse(at)
1338
+ if (!Number.isFinite(ms)) return ''
1339
+ const diff = Date.now() - ms
1340
+ if (diff < 60_000) return '刚刚'
1341
+ if (diff < 3_600_000) return `${Math.max(1, Math.floor(diff / 60000))} 分钟前`
1342
+ return timeLabel(ms)
1343
+ }
1344
+
1345
+ function collectNotices() {
1346
+ const out = []
1347
+ for (const run of Array.isArray(STATE.runs) ? STATE.runs : []) {
1348
+ if (!run || typeof run.id !== 'string') continue
1349
+ const goal = String(run.goal || '这条任务线').replace(/\s+/g, ' ').slice(0, 64)
1350
+ const question = Array.isArray(run.attention) && run.attention.length > 0 ? run.attention[0] : null
1351
+ if (question) {
1352
+ out.push({
1353
+ id: `run:${run.id}:attention`,
1354
+ kind: 'approval',
1355
+ runId: run.id,
1356
+ title: '要你批准',
1357
+ detail: `${goal} · ${question.question || '在等一个决定'}`,
1358
+ at: question.askedAt || run.finishedAt || run.createdAt,
1359
+ })
1360
+ }
1361
+ if (!isTerminal(run.status)) continue
1362
+ const failed = run.status !== 'completed'
1363
+ out.push({
1364
+ id: `run:${run.id}:${run.status}`,
1365
+ kind: failed ? 'failed' : 'done',
1366
+ runId: run.id,
1367
+ title: failed ? (run.status === 'cancelled' ? '已取消' : '没走通') : '跑完了',
1368
+ detail: `${goal} · ${statusText(run.status)}`,
1369
+ at: run.finishedAt || run.createdAt,
1370
+ })
1371
+ }
1372
+ for (const entry of STATE.approvals.values()) {
1373
+ const approval = entry.approval || {}
1374
+ if (!approval.id) continue
1375
+ out.push({
1376
+ id: `approval:${approval.id}`,
1377
+ kind: 'approval',
1378
+ title: '要你批准',
1379
+ detail: `工具 ${approval.toolName || 'tool'} 在等你决定`,
1380
+ at: approval.askedAt,
1381
+ })
1382
+ }
1383
+ out.sort((left, right) => (Date.parse(right.at) || 0) - (Date.parse(left.at) || 0))
1384
+ return out.slice(0, 30)
1385
+ }
1386
+
1387
+ function unreadNotices() {
1388
+ return STATE.notices.filter(notice => !STATE.readNotices.has(notice.id))
1389
+ }
1390
+
1391
+ function renderNoticeBadge() {
1392
+ const unread = unreadNotices().length
1393
+ noticeOpenEl.hidden = STATE.notices.length === 0
1394
+ noticeCountEl.textContent = unread > 99 ? '99+' : String(unread)
1395
+ noticeOpenEl.classList.toggle('has-unread', unread > 0)
1396
+ noticeOpenEl.title = unread > 0 ? `${unread} 条没看过的提醒` : '提醒'
1397
+ const base = 'Superagent 专属空间'
1398
+ document.title = unread > 0 ? `(${unread}) ${base}` : base
1399
+ if (!noticePanelEl.hidden) renderNoticeList()
1400
+ }
1401
+
1402
+ function renderNoticeList() {
1403
+ noticeListEl.textContent = ''
1404
+ if (STATE.notices.length === 0) {
1405
+ noticeListEl.append(el('div', 'notice-empty', '还没有提醒。任务跑完、没走通或等你批准时会出现在这里。'))
1406
+ return
1407
+ }
1408
+ for (const notice of STATE.notices) {
1409
+ const unread = !STATE.readNotices.has(notice.id)
1410
+ const item = el('div', `notice-item${unread ? ' unread' : ''}`)
1411
+ item.dataset.id = notice.id
1412
+ item.append(el('span', 'dot'))
1413
+ const body = el('div', 'body')
1414
+ body.append(el('div', 'title', notice.title))
1415
+ body.append(el('div', 'detail', notice.detail))
1416
+ body.append(el('div', 'when', noticeWhen(notice.at)))
1417
+ item.append(body)
1418
+ item.addEventListener('click', () => {
1419
+ markNoticesRead([notice.id])
1420
+ if (notice.runId) openReport(notice.runId)
1421
+ closeNoticePanel()
1422
+ })
1423
+ noticeListEl.append(item)
1424
+ }
1425
+ }
1426
+
1427
+ function refreshNotices({ toastNew = false } = {}) {
1428
+ const previous = new Set(STATE.notices.map(notice => notice.id))
1429
+ // The first pass only paints what already happened; a toast is for a
1430
+ // change that arrives while the page is open.
1431
+ const primed = STATE.noticesPrimed === true
1432
+ STATE.notices = collectNotices()
1433
+ STATE.noticesPrimed = true
1434
+ if (toastNew && primed) {
1435
+ for (const notice of STATE.notices) {
1436
+ if (previous.has(notice.id)) continue
1437
+ if (notice.kind === 'done') pushToast(`跑完了:${notice.detail}`, 'ok')
1438
+ else if (notice.kind === 'failed') pushToast(`${notice.title}:${notice.detail}`, 'err')
1439
+ else if (notice.kind === 'approval') pushToast(`要你批准:${notice.detail}`, 'warn')
1440
+ }
1441
+ }
1442
+ renderNoticeBadge()
1443
+ }
1444
+
1445
+ function markNoticesRead(ids) {
1446
+ const fresh = (Array.isArray(ids) ? ids : []).filter(id => id && !STATE.readNotices.has(id))
1447
+ if (fresh.length === 0) return
1448
+ for (const id of fresh) STATE.readNotices.add(id)
1449
+ renderNoticeBadge()
1450
+ api('/api/console/notices/read', { method: 'POST', body: { ids: fresh } }).catch(() => {})
1451
+ }
1452
+
1453
+ function openNoticePanel() {
1454
+ STATE.noticeOpen = true
1455
+ noticePanelEl.hidden = false
1456
+ renderNoticeList()
1457
+ // Opening the list is reading it: the badge clears, the lines stay.
1458
+ markNoticesRead(STATE.notices.map(notice => notice.id))
1459
+ }
1460
+
1461
+ function closeNoticePanel() {
1462
+ STATE.noticeOpen = false
1463
+ noticePanelEl.hidden = true
1464
+ }
1465
+
1466
+ // ---------- files ----------
1467
+ //
1468
+ // A dropped or pasted file is copied into the conversation's workspace by
1469
+ // the host, and the path it returns is what the message carries. Nothing is
1470
+ // uploaded to a third party, and nothing outside the workspace is written.
1471
+
1472
+ function uploadExtOf(name) {
1473
+ const text = typeof name === 'string' ? name : ''
1474
+ const dot = text.lastIndexOf('.')
1475
+ return dot >= 0 ? text.slice(dot).toLowerCase() : ''
1476
+ }
1477
+
1478
+ function uploadSizeText(bytes) {
1479
+ const size = Number(bytes) || 0
1480
+ if (size >= 1024 * 1024) return `${(size / (1024 * 1024)).toFixed(1)}MB`
1481
+ if (size >= 1024) return `${Math.round(size / 1024)}KB`
1482
+ return `${size}B`
1483
+ }
1484
+
1485
+ function base64OfBytes(bytes) {
1486
+ let binary = ''
1487
+ const chunk = 0x8000
1488
+ for (let index = 0; index < bytes.length; index += chunk) {
1489
+ binary += String.fromCharCode.apply(null, bytes.subarray(index, index + chunk))
1490
+ }
1491
+ return btoa(binary)
1492
+ }
1493
+
1494
+ function insertUploadPath(filePath) {
1495
+ if (!filePath) return
1496
+ const current = inputEl.value
1497
+ const separator = current.length === 0 || current.endsWith('\n') ? '' : '\n'
1498
+ inputEl.value = `${current}${separator}${filePath}\n`
1499
+ autoGrow()
1500
+ updateSend()
1501
+ inputEl.focus()
1502
+ try { inputEl.setSelectionRange(inputEl.value.length, inputEl.value.length) } catch { /* not focusable yet */ }
1503
+ }
1504
+
1505
+ async function uploadFiles(files) {
1506
+ const list = Array.from(files || []).filter(Boolean)
1507
+ if (list.length === 0) return
1508
+ if (STATE.mode !== 'chat') {
1509
+ pushToast('还没连上,等对话就绪再放文件。', 'err')
1510
+ return
1511
+ }
1512
+ for (const file of list) {
1513
+ const ext = uploadExtOf(file.name)
1514
+ if (!UPLOAD_EXTS.has(ext)) {
1515
+ pushToast(`不能放 ${ext || '没有扩展名的'} 文件;可以放:${UPLOAD_HINT}。`, 'err')
1516
+ continue
1517
+ }
1518
+ if (file.size > UPLOAD_MAX) {
1519
+ pushToast(`${file.name} 有 ${uploadSizeText(file.size)},超过 ${uploadSizeText(UPLOAD_MAX)} 的上限。`, 'err')
1520
+ continue
1521
+ }
1522
+ if (file.size === 0) {
1523
+ pushToast(`${file.name} 是空文件,没有放进去。`, 'err')
1524
+ continue
1525
+ }
1526
+ try {
1527
+ const bytes = new Uint8Array(await file.arrayBuffer())
1528
+ const data = await api('/api/console/upload', {
1529
+ method: 'POST',
1530
+ body: { sessionId: STATE.sessionId, name: file.name, data: base64OfBytes(bytes) },
1531
+ })
1532
+ insertUploadPath(data.path)
1533
+ pushToast(`已放进工作区:${data.name}(路径已写进消息)。`, 'ok')
1534
+ } catch (error) {
1535
+ const hint = error.hint ? `。${error.hint}` : ''
1536
+ pushToast(`放不进去:${messageOf(error)}${hint}`, 'err')
1537
+ }
1538
+ }
1539
+ }
1540
+
1541
+ function dragHasFiles(event) {
1542
+ const transfer = event.dataTransfer
1543
+ if (!transfer) return false
1544
+ if (transfer.files && transfer.files.length > 0) return true
1545
+ return Array.from(transfer.types || []).includes('Files')
1546
+ }
1547
+
1263
1548
  // ---------- task lanes ----------
1264
1549
 
1265
1550
  const TERMINAL_STATUSES = new Set(['completed', 'failed', 'cancelled', 'interrupted', 'blocked'])
@@ -2285,6 +2570,7 @@
2285
2570
  const approval = frame.approval
2286
2571
  if (frame.action === 'asked' && approval && approval.id) {
2287
2572
  seatApproval(approval)
2573
+ refreshNotices({ toastNew: true })
2288
2574
  pushToast('有一个工具调用在等你决定。', 'warn')
2289
2575
  } else if (frame.action === 'auto') {
2290
2576
  pushToast(`已按本会话的许可放行 ${frame.toolName || '这个工具'},没有再打断你。`, 'ok')
@@ -2297,6 +2583,7 @@
2297
2583
  : frame.outcome === 'allowed-once' ? 'allow'
2298
2584
  : frame.outcome === 'rejected' ? 'reject' : 'cancelled'
2299
2585
  settleApprovalNode(entry)
2586
+ refreshNotices()
2300
2587
  }
2301
2588
  }
2302
2589
  break
@@ -2304,6 +2591,7 @@
2304
2591
  case 'runs':
2305
2592
  STATE.runs = Array.isArray(frame.runs) ? frame.runs : []
2306
2593
  renderLanes()
2594
+ refreshNotices({ toastNew: true })
2307
2595
  break
2308
2596
  case 'answered':
2309
2597
  pushToast(`已提交 ${frame.attentionId || '决定'}。`, 'ok')
@@ -2539,8 +2827,10 @@
2539
2827
  if (data.sessionId) setSession(data.sessionId)
2540
2828
  if (data.preset) STATE.preset = data.preset
2541
2829
  STATE.runs = Array.isArray(data.runs) ? data.runs : []
2830
+ STATE.readNotices = new Set(Array.isArray(data.readNoticeIds) ? data.readNoticeIds : [])
2542
2831
  renderLanes()
2543
2832
  for (const approval of Array.isArray(data.approvals) ? data.approvals : []) seatApproval(approval)
2833
+ refreshNotices()
2544
2834
  if (STATE.messages.length === 0) renderEmpty()
2545
2835
  loadTools()
2546
2836
  wizardLoad({ probe: false, auto: true })
@@ -3262,6 +3552,7 @@
3262
3552
  clearMessages()
3263
3553
  STATE.runs = []
3264
3554
  renderLanes()
3555
+ refreshNotices()
3265
3556
  renderEmpty()
3266
3557
  renderTools(null)
3267
3558
  loadTools()
@@ -3352,6 +3643,50 @@
3352
3643
  sendMessage()
3353
3644
  })
3354
3645
 
3646
+ // A file can be dropped anywhere on the composer, or pasted into the text
3647
+ // box; both end up copied into the conversation's workspace, with the path
3648
+ // written into the message so the agent can read it.
3649
+ for (const type of ['dragenter', 'dragover']) {
3650
+ composerEl.addEventListener(type, event => {
3651
+ if (!dragHasFiles(event)) return
3652
+ event.preventDefault()
3653
+ if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy'
3654
+ STATE.dragDepth += 1
3655
+ composerEl.classList.add('dragover')
3656
+ })
3657
+ }
3658
+ composerEl.addEventListener('dragleave', () => {
3659
+ STATE.dragDepth = Math.max(0, STATE.dragDepth - 1)
3660
+ if (STATE.dragDepth === 0) composerEl.classList.remove('dragover')
3661
+ })
3662
+ composerEl.addEventListener('drop', event => {
3663
+ if (!dragHasFiles(event)) return
3664
+ event.preventDefault()
3665
+ STATE.dragDepth = 0
3666
+ composerEl.classList.remove('dragover')
3667
+ uploadFiles(event.dataTransfer ? event.dataTransfer.files : null)
3668
+ })
3669
+ inputEl.addEventListener('paste', event => {
3670
+ const files = event.clipboardData ? event.clipboardData.files : null
3671
+ if (!files || files.length === 0) return
3672
+ event.preventDefault()
3673
+ uploadFiles(files)
3674
+ })
3675
+
3676
+ noticeOpenEl.addEventListener('click', event => {
3677
+ event.stopPropagation()
3678
+ if (STATE.noticeOpen) closeNoticePanel()
3679
+ else openNoticePanel()
3680
+ })
3681
+ $('noticeReadAll').addEventListener('click', event => {
3682
+ event.stopPropagation()
3683
+ markNoticesRead(STATE.notices.map(notice => notice.id))
3684
+ })
3685
+ noticePanelEl.addEventListener('click', event => event.stopPropagation())
3686
+ document.addEventListener('click', () => {
3687
+ if (STATE.noticeOpen) closeNoticePanel()
3688
+ })
3689
+
3355
3690
  for (const button of document.querySelectorAll('.segmented button')) {
3356
3691
  button.addEventListener('click', () => {
3357
3692
  STATE.sendMode = button.dataset.mode === 'steer' ? 'steer' : 'queue'