dsh-workspace-api-key 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/README.zh.md +8 -8
- package/lib/client.js +222 -16
- package/lib/index.js +143 -23
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -31,12 +31,12 @@ Host half (`lib/index.js`):
|
|
|
31
31
|
- matches that directory against `workspaceRegistry.list()` after normalizing both sides (absolute, trailing separator removed, lower-cased on Windows);
|
|
32
32
|
- derives a stable ref per level — `DEEPSEEK_API_KEY_WS_<first 16 hex chars of sha1(normalized path), upper-cased>` for a workspace and `DEEPSEEK_API_KEY_SS_<first 16 hex chars of sha1(session id), upper-cased>` for a session (a session id contains `-` and cannot be a ref name) — writes the key through the credentials service, and serves that ref's value;
|
|
33
33
|
- rewrites only refs a provider actually reads: the default ref, every adapter's configured `apiKeyEnv`, and its own generated refs. Every other ref passes through untouched;
|
|
34
|
-
- builds the session list from the `sessionController` service (`list()`), so the panel
|
|
35
|
-
- reports its own version and a session probe (`available`, `count`, `withoutCwd`, `samples`, `error`, plus sample workspace paths) in `/wsk-api/state`, so the panel can say *why* no sessions are listed: a stale host half (only a page reload instead of an app restart), a missing `sessionController`, a throwing `list()`, or a `cwd` that matches no workspace path;
|
|
34
|
+
- builds the session list from the `sessionController` service (`list()`, unwrapping its `{items: […]}` envelope) and falls back to the live `sessions` service (`ctx.get('sessions').list()`), so the panel still has sessions when the controller is missing, throws, or returns an empty list — subagent sessions are filtered out of that fallback;
|
|
35
|
+
- reports its own version and a session probe (`available`, `shape`, `source`, `count`, `withoutCwd`, `samples`, `error`, plus sample workspace paths) in `/wsk-api/state`, so the panel can say *why* no sessions are listed: a stale host half (only a page reload instead of an app restart), a missing `sessionController`, a throwing `list()`, an unexpected envelope shape, or a `cwd` that matches no workspace path;
|
|
36
36
|
- keeps its own bookkeeping (which level maps to which ref, invalid flags, the provider a key was recorded for) in `$DSH_HOME/storages/dsh-workspace-api-key.json`;
|
|
37
37
|
- observes failures through the `agent/request-error` waterfall without ever returning `{kind: 'retry'}` — it only records the verdict and calls `next()`.
|
|
38
38
|
|
|
39
|
-
The browser half (`lib/client.js`) registers into the `sidebar.panellist` slot (`order: 1`), the `main` slot (key `workspace-api-key`) and the `shell.overlay` slot (the entering-a-session warning), the same slots `dsh-skill-mcp-panel` and `dsh-429-guard` use. It is plain `React.createElement` with no build step and no bundled dependencies. The overlay asks `/wsk-api/check
|
|
39
|
+
The browser half (`lib/client.js`) registers into the `sidebar.panellist` slot (`order: 1`), the `main` slot (key `workspace-api-key`) and the `shell.overlay` slot (the entering-a-session warning), the same slots `dsh-skill-mcp-panel` and `dsh-429-guard` use. It is plain `React.createElement` with no build step and no bundled dependencies. It merges the host rows with the browser-side `sessions` store (`ctx.get('sessions').list.getSnapshot()`, which is what the sidebar itself renders), so session titles come from `displayTitle` and sessions stay visible even when the host cannot list them. The overlay asks `/wsk-api/check?sessionId=…&path=…` about the session that currently owns the main view, asks at most once per session, and its buttons only ever navigate to the panel — the panel is where a key can actually be changed.
|
|
40
40
|
|
|
41
41
|
### HTTP API (loopback only)
|
|
42
42
|
|
|
@@ -71,22 +71,22 @@ Then add `"dsh-workspace-api-key"` to `dsh.profile.bundles` in that profile's `p
|
|
|
71
71
|
## Tests
|
|
72
72
|
|
|
73
73
|
```sh
|
|
74
|
-
node test/host.test.mjs #
|
|
75
|
-
node test/client.test.mjs #
|
|
74
|
+
node test/host.test.mjs # 125 assertions
|
|
75
|
+
node test/client.test.mjs # 124 assertions
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
Neither suite needs a running DSH process. The host suite drives `apply()` against a mock context (fake `credentials`, `workspaceRegistry`, `agents`, `sessionController`, `webServer`, stubbed `fetch`) and covers ref derivation, the session → workspace → default cascade, workspace matching, redirecting a second adapter's `apiKeyEnv`, clearing back to the default, 401/402/429/5xx classification, the loopback and origin checks, and
|
|
78
|
+
Neither suite needs a running DSH process. The host suite drives `apply()` against a mock context (fake `credentials`, `workspaceRegistry`, `agents`, `sessionController`, `sessions`, `webServer`, stubbed `fetch`) and covers ref derivation, the session → workspace → default cascade, workspace matching, redirecting a second adapter's `apiKeyEnv`, clearing back to the default, 401/402/429/5xx classification, the loopback and origin checks, state persistence, and the session probe including the `{items}` envelope and the live-session fallback. The client suite loads `lib/client.js` through a minimal `window.__ModuleLoader__` plus a small React runtime, renders the panel and the overlay, and asserts slot registration, the first render, session expand/collapse, per-session saving and testing, sessions recovered from the browser-side store when the host has none (with `displayTitle` winning and subagent sessions hidden), the ungrouped-directory card, the stale and mismatch prompts, the "go configure" hand-off, graceful degradation without a session list, and back-navigation when `ctx.get('layout')` only becomes available after the plugin was applied.
|
|
79
79
|
|
|
80
80
|
## Requirements and limits
|
|
81
81
|
|
|
82
82
|
- Verified against DSH Desktop 2.0.17 with `@deepseek-ai/dsh*` 0.2.0-rc.2 and `@deepseek-ai/cordis` 4.0.4. It has no runtime dependency and imports no `@deepseek-ai/*` package — only the host services (`credentials`, `workspaceRegistry`, `agents`, `sessionController`, `webServer`, `llm`, `settings`) and Node built-ins.
|
|
83
83
|
- One key per level: a session has a single key whichever provider route reads it, and a key recorded for one provider is reported as a mismatch when the session runs on another. Model changes inside one provider are not treated as a mismatch, because a DeepSeek key is account-wide.
|
|
84
|
-
- Sessions are matched to a workspace by their directory (`cwd`).
|
|
84
|
+
- Sessions are matched to a workspace by their directory (`cwd`). The host's own `list()` skips stored sessions that never got a `cwd`, and the live-session fallback only knows sessions that are currently loaded, so the panel may show fewer sessions than the sidebar. Sessions visible only in the browser-side store carry no `cwd` of their own beyond the one the sidebar knows.
|
|
85
85
|
- The connection test speaks the Anthropic Messages shape (`POST <baseURL>/messages` with `x-api-key` and `anthropic-version: 2023-06-01`), which is what the DeepSeek route uses. A provider that speaks a different protocol can still have keys bound per level, but the test may report a failure for a key that works.
|
|
86
86
|
- Keys are stored through the credentials service in `$DSH_HOME/.credentials.yaml` under `refs:`, in plaintext, exactly like the default key. They are not written into session logs, the plugin's state file, or the plugin directory.
|
|
87
87
|
- Matching is textual after normalization. If a session's `cwd` is a symlink or junction to a registered workspace path, it will not match and the level above is used.
|
|
88
88
|
- Uninstalling the plugin leaves the generated `*_WS_*` / `*_SS_*` refs in the credentials file; remove them from the Models page.
|
|
89
|
-
- If the panel lists workspaces but no expandable sessions, read the diagnostics line at the bottom of the panel. A red "the host half is still an older version" banner means the DSH process was never restarted: the host half is loaded once at startup, so closing the window or reloading the page is not enough — fully quit DSH Desktop and open it again. Otherwise the diagnostics line shows how many sessions the host sees and
|
|
89
|
+
- If the panel lists workspaces but no expandable sessions, read the diagnostics line at the bottom of the panel. A red "the host half is still an older version" banner means the DSH process was never restarted: the host half is loaded once at startup, so closing the window or reloading the page is not enough — fully quit DSH Desktop and open it again. Otherwise the diagnostics line shows how many sessions the host sees (and from which source: `sessionController`, its live-session fallback, or the browser store), plus sample session `cwd` values next to sample workspace paths when none of them match.
|
|
90
90
|
|
|
91
91
|
## License
|
|
92
92
|
|
package/README.zh.md
CHANGED
|
@@ -31,12 +31,12 @@ DSH 只从一个全局凭据 ref(默认 `DEEPSEEK_API_KEY`)解析 DeepSeek k
|
|
|
31
31
|
- 把该目录与 `workspaceRegistry.list()` 做规范化后比对(绝对化、去掉尾部分隔符、Windows 折大小写);
|
|
32
32
|
- 由每一层派生出稳定的 ref —— 工作区是 `DEEPSEEK_API_KEY_WS_<sha1(规范化路径) 前 16 位十六进制大写>`,会话是 `DEEPSEEK_API_KEY_SS_<sha1(会话 id) 前 16 位十六进制大写>`(会话 id 含 `-`,不能直接当 ref 名)——通过凭据服务写入 key,并返回这个 ref 的值;
|
|
33
33
|
- 只改写 provider 真正会读的 ref:默认 ref、每个适配器配置的 `apiKeyEnv`,以及插件自己生成的 ref;其它 ref 原样透传;
|
|
34
|
-
- 会话列表来自 `sessionController` 服务(`list()
|
|
35
|
-
- `/wsk-api/state` 会带上插件自身版本与会话探针(`available`、`count`、`withoutCwd`、`samples`、`error`,以及工作区路径样本),面板据此说明**为什么**没有列出会话:宿主半边是旧版本(只刷新了页面而没重启应用)、没有 `sessionController`、`list()`
|
|
34
|
+
- 会话列表来自 `sessionController` 服务(`list()`,会拆开它 `{items: […]}` 的信封),控件缺失 / 抛错 / 列表为空时再退到宿主 live 会话服务(`ctx.get('sessions').list()`),所以那种情况下面板仍能列出会话(该兜底会过滤掉子代理会话);
|
|
35
|
+
- `/wsk-api/state` 会带上插件自身版本与会话探针(`available`、`shape`、`source`、`count`、`withoutCwd`、`samples`、`error`,以及工作区路径样本),面板据此说明**为什么**没有列出会话:宿主半边是旧版本(只刷新了页面而没重启应用)、没有 `sessionController`、`list()` 抛错、信封形状不认识,还是会话的 `cwd` 与任何工作区路径都对不上;
|
|
36
36
|
- 自己的账本(哪一层对应哪个 ref、失效标记、key 是给哪个服务商记的)落在 `$DSH_HOME/storages/dsh-workspace-api-key.json`;
|
|
37
37
|
- 通过 `agent/request-error` waterfall 观察失败,但**从不**返回 `{kind: 'retry'}`——只记录判定结果并 `next()` 放行。
|
|
38
38
|
|
|
39
|
-
浏览器半边(`lib/client.js`)注册到 `sidebar.panellist` 槽(`order: 1`)、`main` 槽(key 为 `workspace-api-key`)与 `shell.overlay` 槽(点进会话时的提醒),和 `dsh-skill-mcp-panel`、`dsh-429-guard` 用的是同一套槽。全部是朴素的 `React.createElement
|
|
39
|
+
浏览器半边(`lib/client.js`)注册到 `sidebar.panellist` 槽(`order: 1`)、`main` 槽(key 为 `workspace-api-key`)与 `shell.overlay` 槽(点进会话时的提醒),和 `dsh-skill-mcp-panel`、`dsh-429-guard` 用的是同一套槽。全部是朴素的 `React.createElement`,没有构建步骤,也不打包任何依赖。它会把宿主行与浏览器端 `sessions` 存储(`ctx.get('sessions').list.getSnapshot()`,也就是侧栏自己渲染的数据)合并起来,因此标题取自 `displayTitle`,宿主列不出会话时面板也照样有会话可列。覆盖层向 `/wsk-api/check?sessionId=…&path=…` 查询当前占据主视图的会话,每个会话最多问一次,它的按钮只负责把你带到面板——改 key 只能由面板里的操作完成。
|
|
40
40
|
|
|
41
41
|
### HTTP 接口(仅限回环)
|
|
42
42
|
|
|
@@ -71,22 +71,22 @@ pnpm add "dsh-workspace-api-key@github:COH2357/dsh-workspace-api-key"
|
|
|
71
71
|
## 测试
|
|
72
72
|
|
|
73
73
|
```sh
|
|
74
|
-
node test/host.test.mjs #
|
|
75
|
-
node test/client.test.mjs #
|
|
74
|
+
node test/host.test.mjs # 125 条断言
|
|
75
|
+
node test/client.test.mjs # 124 条断言
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
两个套件都不需要启动 DSH。宿主套件用一个假 ctx(假的 `credentials`、`workspaceRegistry`、`agents`、`sessionController`、`webServer`,以及打桩的 `fetch`)驱动 `apply()`,覆盖 ref 派生、会话→工作区→默认的级联、工作区匹配、把第二个适配器的 `apiKeyEnv` 一起重定向、清回默认、401/402/429/5xx
|
|
78
|
+
两个套件都不需要启动 DSH。宿主套件用一个假 ctx(假的 `credentials`、`workspaceRegistry`、`agents`、`sessionController`、`sessions`、`webServer`,以及打桩的 `fetch`)驱动 `apply()`,覆盖 ref 派生、会话→工作区→默认的级联、工作区匹配、把第二个适配器的 `apiKeyEnv` 一起重定向、清回默认、401/402/429/5xx 的判定、回环与来源校验、状态落盘,以及会话探针(含 `{items}` 信封与 live 兜底)。浏览器套件通过一个极小的 `window.__ModuleLoader__` 与自制 React 运行时加载 `lib/client.js`,渲染出面板与覆盖层,断言槽注册、首屏渲染、会话折叠/展开、会话级保存与测试、宿主列不出会话时从浏览器端存储恢复会话(标题取 `displayTitle`、隐藏子代理会话)、未分组目录卡片、失效与不匹配提醒、「去配置」的交接、没有会话列表时的降级,以及 `ctx.get('layout')` 在插件 apply 之后才可用时返回键仍然有效。
|
|
79
79
|
|
|
80
80
|
## 要求与限制
|
|
81
81
|
|
|
82
82
|
- 已在 DSH Desktop 2.0.17(`@deepseek-ai/dsh*` 0.2.0-rc.2、`@deepseek-ai/cordis` 4.0.4)上验证。插件没有运行时依赖,也不 import 任何 `@deepseek-ai/*` 包,只用宿主服务(`credentials`、`workspaceRegistry`、`agents`、`sessionController`、`webServer`、`llm`、`settings`)与 Node 内置模块。
|
|
83
83
|
- 每一层只有一把 key:一个会话无论被哪个 provider 路由读取,用的都是同一把 key;key 记下的服务商与会话当前服务商不一致时会被报为「不匹配」,但同一服务商内换模型不算不匹配,因为 DeepSeek key 是账号级的。
|
|
84
|
-
- 会话按目录(`cwd
|
|
84
|
+
- 会话按目录(`cwd`)归入工作区。宿主自己的 `list()` 会跳过从未存过 `cwd` 的历史会话,而 live 兜底只认识当前装载中的会话,所以面板列出的会话可能比侧栏少;只在浏览器端存储里可见的会话,除了侧栏知道的那个 `cwd` 之外没有别的路径信息。
|
|
85
85
|
- 「测试连接」说的是 Anthropic Messages 协议(`POST <baseURL>/messages` 带 `x-api-key` 与 `anthropic-version: 2023-06-01`),也就是 DeepSeek 路由用的协议;换了别的协议的 provider 一样可以按层绑 key,只是测试可能把有效的 key 报成失败。
|
|
86
86
|
- key 通过凭据服务存放在 `$DSH_HOME/.credentials.yaml` 的 `refs:` 里,明文,和默认 key 完全一样。它不会被写进会话日志、插件状态文件或插件目录。
|
|
87
87
|
- 匹配是规范化之后的文本比较。如果某个会话的 `cwd` 是指向已注册工作区路径的符号链接或 junction,则匹配不上,会走上层层级。
|
|
88
88
|
- 卸载插件不会删除已生成的 `*_WS_*` / `*_SS_*` ref,可在「设置 → 模型」里清掉。
|
|
89
|
-
- 如果面板列出了工作区却没有可展开的会话,请看面板底部的诊断行。出现红色「宿主端插件还是旧版本」横幅,说明 DSH 进程没有重启过:宿主半边只在启动时加载,关窗口和刷新页面都不算——请完全退出 DSH Desktop
|
|
89
|
+
- 如果面板列出了工作区却没有可展开的会话,请看面板底部的诊断行。出现红色「宿主端插件还是旧版本」横幅,说明 DSH 进程没有重启过:宿主半边只在启动时加载,关窗口和刷新页面都不算——请完全退出 DSH Desktop 再打开。其余情况诊断行会写明宿主看到多少个会话、会话列表来自哪个来源(`sessionController`、live 兜底,还是浏览器端存储);一个都对不上时,还会并排给出会话 `cwd` 样本与工作区路径样本,便于比对。
|
|
90
90
|
|
|
91
91
|
## 许可
|
|
92
92
|
|
package/lib/client.js
CHANGED
|
@@ -20,6 +20,19 @@ window.__ModuleLoader__.load({
|
|
|
20
20
|
// refresh —— 面板挂载后在这里登记自己的刷新函数
|
|
21
21
|
const bridge = { focus: null, refresh: null }
|
|
22
22
|
|
|
23
|
+
// apply 阶段拿到的 ctx。会话列表服务(browser 侧 "sessions")由
|
|
24
|
+
// dsh-api-session-controller 的客户端半边在 effect 里 provide,可能晚于
|
|
25
|
+
// 本插件注册,所以只在渲染/点击时惰性取,不在 apply 阶段捕获结果。
|
|
26
|
+
const host = { ctx: null }
|
|
27
|
+
function sessionsService(fallback) {
|
|
28
|
+
if (fallback !== undefined && fallback !== null) return fallback
|
|
29
|
+
try {
|
|
30
|
+
return host.ctx?.get?.('sessions')
|
|
31
|
+
} catch {
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
// ─────────────────────────────── 样式 ───────────────────────────────
|
|
24
37
|
|
|
25
38
|
const CSS = `
|
|
@@ -179,6 +192,173 @@ window.__ModuleLoader__.load({
|
|
|
179
192
|
return title ?? (session.blank === true ? '(空会话)' : String(session.sessionId).slice(0, 12))
|
|
180
193
|
}
|
|
181
194
|
|
|
195
|
+
// ─────────────────── 会话树:宿主行 + 浏览器端列表 ───────────────────
|
|
196
|
+
// 宿主 /state 里的会话行只有「带 cwd 的会话」才能被挂到目录下,而且不含标题
|
|
197
|
+
// (标题是浏览器端的 projection)。这里用浏览器端 sessions 服务补齐:
|
|
198
|
+
// · 标题(displayTitle)
|
|
199
|
+
// · 宿主漏掉的会话(例如 cwd 规范化差异导致的挂载失败)
|
|
200
|
+
// 合并后仍然保持宿主的 key 信息(level / configured / invalid / mismatch)。
|
|
201
|
+
|
|
202
|
+
function normKey(p) {
|
|
203
|
+
if (typeof p !== 'string' || p === '') return undefined
|
|
204
|
+
const trimmed = p.replace(/[\\/]+$/, '')
|
|
205
|
+
const base = trimmed === '' ? p : trimmed
|
|
206
|
+
return base.replace(/\//g, '\\').toLowerCase()
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function dirName(p) {
|
|
210
|
+
if (typeof p !== 'string' || p === '') return ''
|
|
211
|
+
const parts = p.replace(/[\\/]+$/, '').split(/[\\/]/)
|
|
212
|
+
return parts[parts.length - 1] ?? p
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** 会话按最近使用排序。 */
|
|
216
|
+
function sortByUpdated(rows) {
|
|
217
|
+
return rows.slice().sort((a, b) => (b?.updatedAt ?? 0) - (a?.updatedAt ?? 0))
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** 浏览器端 sessions 服务快照 → 顶层会话条目(子代理会话不算)。 */
|
|
221
|
+
function clientSessionEntries(sessions) {
|
|
222
|
+
const snap = sessions?.list?.getSnapshot?.()
|
|
223
|
+
if (snap === null || snap === undefined) return []
|
|
224
|
+
const ids = Array.isArray(snap.ids) ? snap.ids : Object.keys(snap.byId ?? {})
|
|
225
|
+
const entries = []
|
|
226
|
+
for (const id of ids) {
|
|
227
|
+
const item = snap.byId?.[id]
|
|
228
|
+
if (item === null || item === undefined) continue
|
|
229
|
+
// 子代理会话不作为可配置项列出(它们跟随父会话)。
|
|
230
|
+
if (item.parentId !== undefined || item.origin === 'subagent') continue
|
|
231
|
+
entries.push({
|
|
232
|
+
sessionId: typeof item.id === 'string' && item.id !== '' ? item.id : id,
|
|
233
|
+
cwd: typeof item.cwd === 'string' && item.cwd !== '' ? item.cwd : undefined,
|
|
234
|
+
title: typeof item.displayTitle === 'string' && item.displayTitle !== ''
|
|
235
|
+
? item.displayTitle
|
|
236
|
+
: typeof item.title === 'string' && item.title !== '' ? item.title : undefined,
|
|
237
|
+
updatedAt: typeof item.updatedAt === 'number' ? item.updatedAt : 0,
|
|
238
|
+
running: item.running === true,
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
return entries
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* 用浏览器端的会话列表补全「工作区/目录 → 会话」的树。
|
|
246
|
+
* 宿主行始终保留(不会被浏览器端列表挤掉),浏览器端额外只做两件事:
|
|
247
|
+
* 给同名会话补标题/cwd,以及把宿主漏掉的会话补进来(层级从 /state 的
|
|
248
|
+
* 覆盖记录推出)。这样宿主列表为空时面板照样有会话可列。
|
|
249
|
+
*/
|
|
250
|
+
function mergeSessions(state, sessions) {
|
|
251
|
+
const entries = clientSessionEntries(sessions)
|
|
252
|
+
if (state === null || state === undefined || entries.length === 0) return state
|
|
253
|
+
|
|
254
|
+
const hostRows = new Map()
|
|
255
|
+
for (const group of [...(state.workspaces ?? []), ...(state.ungrouped ?? [])]) {
|
|
256
|
+
for (const row of (Array.isArray(group?.sessions) ? group.sessions : [])) {
|
|
257
|
+
if (row?.sessionId !== undefined) hostRows.set(row.sessionId, row)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const overrideBySession = new Map()
|
|
261
|
+
for (const item of (Array.isArray(state.sessionOverrides) ? state.sessionOverrides : [])) {
|
|
262
|
+
if (item?.sessionId !== undefined) overrideBySession.set(item.sessionId, item)
|
|
263
|
+
}
|
|
264
|
+
const workspaceByPath = new Map()
|
|
265
|
+
for (const ws of (state.workspaces ?? [])) {
|
|
266
|
+
const key = normKey(ws?.path)
|
|
267
|
+
if (key !== undefined) workspaceByPath.set(key, ws)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// 第一遍:宿主行能补什么就补什么,宿主没有的会话合成一行。
|
|
271
|
+
const enriched = new Map()
|
|
272
|
+
const additions = []
|
|
273
|
+
for (const entry of entries) {
|
|
274
|
+
const host = hostRows.get(entry.sessionId)
|
|
275
|
+
if (host !== undefined) {
|
|
276
|
+
const patch = {}
|
|
277
|
+
if ((host.title === undefined || host.title === '') && entry.title !== undefined) patch.title = entry.title
|
|
278
|
+
if ((host.cwd === undefined || host.cwd === '') && entry.cwd !== undefined) patch.cwd = entry.cwd
|
|
279
|
+
if (Object.keys(patch).length > 0) enriched.set(entry.sessionId, { ...host, ...patch })
|
|
280
|
+
continue
|
|
281
|
+
}
|
|
282
|
+
const cwd = entry.cwd
|
|
283
|
+
const pathKey = normKey(cwd)
|
|
284
|
+
const ws = pathKey !== undefined ? workspaceByPath.get(pathKey) : undefined
|
|
285
|
+
const own = overrideBySession.get(entry.sessionId)
|
|
286
|
+
const level = own !== undefined ? 'session' : ws?.configured === true ? 'workspace' : 'default'
|
|
287
|
+
additions.push({
|
|
288
|
+
pathKey,
|
|
289
|
+
workspace: ws,
|
|
290
|
+
row: {
|
|
291
|
+
sessionId: entry.sessionId,
|
|
292
|
+
title: entry.title,
|
|
293
|
+
cwd,
|
|
294
|
+
updatedAt: entry.updatedAt,
|
|
295
|
+
running: entry.running,
|
|
296
|
+
blank: false,
|
|
297
|
+
parentSessionId: undefined,
|
|
298
|
+
provider: own?.provider ?? ws?.overrideProvider,
|
|
299
|
+
model: own?.model ?? ws?.overrideModel,
|
|
300
|
+
ref: own?.ref,
|
|
301
|
+
configured: own !== undefined,
|
|
302
|
+
keyMasked: own?.keyMasked,
|
|
303
|
+
overrideProvider: own?.provider,
|
|
304
|
+
overrideModel: own?.model,
|
|
305
|
+
level,
|
|
306
|
+
effectiveRef: level === 'session' ? own?.ref : level === 'workspace' ? ws?.ref : undefined,
|
|
307
|
+
effectiveKeyMasked: level === 'session'
|
|
308
|
+
? own?.keyMasked
|
|
309
|
+
: level === 'workspace' ? ws?.keyMasked : state.defaultRef?.keyMasked,
|
|
310
|
+
effectiveProvider: own?.provider ?? ws?.overrideProvider,
|
|
311
|
+
effectiveModel: own?.model ?? ws?.overrideModel,
|
|
312
|
+
effectiveTitle: undefined,
|
|
313
|
+
invalid: (level === 'session' ? own?.invalid : level === 'workspace' ? ws?.invalid : null) ?? null,
|
|
314
|
+
mismatch: null,
|
|
315
|
+
},
|
|
316
|
+
})
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const fill = (rows) => (Array.isArray(rows) ? rows : [])
|
|
320
|
+
.map((row) => enriched.get(row?.sessionId) ?? row)
|
|
321
|
+
|
|
322
|
+
// 第二遍:宿主结构照旧,浏览器端多出来的会话按 cwd 归档。
|
|
323
|
+
const workspaces = (state.workspaces ?? []).map((ws) => {
|
|
324
|
+
const rows = fill(ws.sessions)
|
|
325
|
+
for (const item of additions) {
|
|
326
|
+
if (item.workspace?.path === ws.path) rows.push(item.row)
|
|
327
|
+
}
|
|
328
|
+
return { ...ws, sessions: sortByUpdated(rows) }
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
const ungrouped = []
|
|
332
|
+
const extras = new Map()
|
|
333
|
+
for (const item of additions) {
|
|
334
|
+
if (item.workspace !== undefined) continue
|
|
335
|
+
const key = item.pathKey ?? ''
|
|
336
|
+
const list = extras.get(key) ?? []
|
|
337
|
+
list.push(item.row)
|
|
338
|
+
extras.set(key, list)
|
|
339
|
+
}
|
|
340
|
+
for (const group of (state.ungrouped ?? [])) {
|
|
341
|
+
const key = normKey(group?.path) ?? String(group?.path ?? '')
|
|
342
|
+
const rows = fill(group.sessions)
|
|
343
|
+
for (const row of (extras.get(key) ?? [])) rows.push(row)
|
|
344
|
+
extras.delete(key)
|
|
345
|
+
ungrouped.push({ ...group, sessions: sortByUpdated(rows) })
|
|
346
|
+
}
|
|
347
|
+
for (const [key, rows] of extras) {
|
|
348
|
+
const path = key !== '' ? key : undefined
|
|
349
|
+
ungrouped.push({
|
|
350
|
+
id: undefined,
|
|
351
|
+
path: rows[0]?.cwd ?? path,
|
|
352
|
+
title: path !== undefined && path !== '' ? dirName(path) : '(没有目录)',
|
|
353
|
+
kind: 'directory',
|
|
354
|
+
configured: false,
|
|
355
|
+
exists: true,
|
|
356
|
+
sessions: sortByUpdated(rows),
|
|
357
|
+
})
|
|
358
|
+
}
|
|
359
|
+
return { ...state, workspaces, ungrouped, sessionSource: 'client' }
|
|
360
|
+
}
|
|
361
|
+
|
|
182
362
|
function modelText(session) {
|
|
183
363
|
if (typeof session.provider !== 'string' || session.provider === '') return '模型未知'
|
|
184
364
|
return `${session.provider} / ${session.model ?? '默认模型'}`
|
|
@@ -322,6 +502,16 @@ window.__ModuleLoader__.load({
|
|
|
322
502
|
|
|
323
503
|
useEffect(() => { refresh() }, [refresh])
|
|
324
504
|
|
|
505
|
+
// 浏览器端的会话列表(含标题、cwd)会随时变化:变了就重渲染。
|
|
506
|
+
const sessionStore = sessionsService(props?.sessions)
|
|
507
|
+
const [sessionTick, setSessionTick] = useState(0)
|
|
508
|
+
useEffect(() => {
|
|
509
|
+
const store = sessionStore?.list
|
|
510
|
+
if (store === undefined || store === null || typeof store.subscribe !== 'function') return undefined
|
|
511
|
+
const off = store.subscribe(() => setSessionTick((tick) => tick + 1))
|
|
512
|
+
return () => { if (typeof off === 'function') off() }
|
|
513
|
+
}, [sessionStore])
|
|
514
|
+
|
|
325
515
|
// 让覆盖层能立刻刷新面板(点「去配置」时面板可能已经挂载着)。
|
|
326
516
|
useEffect(() => {
|
|
327
517
|
bridge.refresh = refresh
|
|
@@ -418,12 +608,15 @@ window.__ModuleLoader__.load({
|
|
|
418
608
|
}
|
|
419
609
|
}
|
|
420
610
|
|
|
421
|
-
|
|
611
|
+
// 把浏览器端的会话列表并进宿主状态:宿主列表为空时(例如 list() 信封形状
|
|
612
|
+
// 不匹配)界面仍然能列出会话,并且会话标题来自浏览器端 projection。
|
|
613
|
+
const view = mergeSessions(state, sessionStore)
|
|
614
|
+
const workspaces = view?.workspaces ?? []
|
|
422
615
|
const grouped = workspaces.filter((ws) => ws.kind === 'workspace')
|
|
423
616
|
const orphans = workspaces.filter((ws) => ws.kind !== 'workspace')
|
|
424
|
-
const ungrouped =
|
|
425
|
-
const defaultRef =
|
|
426
|
-
const providers =
|
|
617
|
+
const ungrouped = view?.ungrouped ?? []
|
|
618
|
+
const defaultRef = view?.defaultRef
|
|
619
|
+
const providers = view?.providers ?? []
|
|
427
620
|
|
|
428
621
|
// ── 诊断 ──────────────────────────────────────────────────────────────
|
|
429
622
|
// 面板里「看不到可展开的会话」有两个完全不同的原因,修法也不同:
|
|
@@ -432,6 +625,7 @@ window.__ModuleLoader__.load({
|
|
|
432
625
|
// 这里把两者都显式画出来,用户截一张图就能定位。
|
|
433
626
|
const probe = state?.sessionProbe
|
|
434
627
|
const hostIsStale = state !== null && state.storeVersion === undefined
|
|
628
|
+
const clientCount = clientSessionEntries(sessionStore).length
|
|
435
629
|
const sessionTotal = [...grouped, ...ungrouped].reduce(
|
|
436
630
|
(sum, ws) => sum + (Array.isArray(ws.sessions) ? ws.sessions.length : 0), 0)
|
|
437
631
|
|
|
@@ -444,10 +638,13 @@ window.__ModuleLoader__.load({
|
|
|
444
638
|
? '未知'
|
|
445
639
|
: probe.available !== true
|
|
446
640
|
? '不可用'
|
|
447
|
-
: `${probe.count}
|
|
641
|
+
: `${probe.count} 个${probe.shape !== undefined ? `(${probe.shape})` : ''}`
|
|
642
|
+
+ (probe.source === 'sessions' ? '(live 兜底)' : '')
|
|
448
643
|
const listError = probe?.error !== undefined ? ` · list 报错:${probe.error}` : ''
|
|
449
644
|
const noCwd = probe?.withoutCwd > 0 ? ` · ${probe.withoutCwd} 个没有 cwd` : ''
|
|
450
|
-
return `插件 v${hostVersion} · 状态存储 v${state.storeVersion ?? '—'}
|
|
645
|
+
return `插件 v${hostVersion} · 状态存储 v${state.storeVersion ?? '—'}`
|
|
646
|
+
+ ` · 宿主会话列表:${sessions}${listError}${noCwd}`
|
|
647
|
+
+ ` · 浏览器会话列表:${clientCount} 个`
|
|
451
648
|
+ ` · 工作区 ${grouped.length} + 未分组 ${ungrouped.length} · 挂在目录下的会话 ${sessionTotal}`
|
|
452
649
|
}
|
|
453
650
|
|
|
@@ -519,7 +716,9 @@ window.__ModuleLoader__.load({
|
|
|
519
716
|
type: 'button', className: 'wsk-btn',
|
|
520
717
|
onClick: () => setEditing(null),
|
|
521
718
|
}, '取消')),
|
|
522
|
-
h('div', { className: 'wsk-hint' },
|
|
719
|
+
h('div', { className: 'wsk-hint' }, target.ref === undefined || target.ref === null
|
|
720
|
+
? '凭据引用:保存时由宿主按这个会话/目录的 ID 生成,保存后这里会显示出来'
|
|
721
|
+
: `凭据引用:${target.ref}`))
|
|
523
722
|
}
|
|
524
723
|
|
|
525
724
|
const renderSession = (ws, session) => {
|
|
@@ -748,20 +947,20 @@ window.__ModuleLoader__.load({
|
|
|
748
947
|
'请「完全退出」DSH Desktop 再重新打开(关闭窗口 / 刷新页面都不够:宿主代码只在启动时加载)。'),
|
|
749
948
|
h('div', { className: 'wsk-hint' }, diagText()))
|
|
750
949
|
: null,
|
|
751
|
-
state !== null && state.sessionListAvailable === false
|
|
950
|
+
state !== null && state.sessionListAvailable === false && clientCount === 0
|
|
752
951
|
? h('div', { className: 'wsk-msg info', style: { marginBottom: 12 } },
|
|
753
952
|
'当前 DSH 版本没有提供会话列表服务,只能按工作区配置 key。',
|
|
754
953
|
h('div', { className: 'wsk-hint' }, diagText()))
|
|
755
954
|
: null,
|
|
756
|
-
!hostIsStale && probe?.available === true && probe.count === 0
|
|
955
|
+
!hostIsStale && probe?.available === true && probe.count === 0 && clientCount === 0
|
|
757
956
|
? h('div', { className: 'wsk-msg info', style: { marginBottom: 12 } },
|
|
758
|
-
'宿主报告 0
|
|
957
|
+
'宿主报告 0 个会话,浏览器端也没有拿到会话列表,所以没有可展开的列表。',
|
|
759
958
|
h('div', { className: 'wsk-hint' },
|
|
760
959
|
'只有「会话记录里带 cwd」的会话才能挂到工作区/未分组目录下。'),
|
|
761
960
|
h('div', { className: 'wsk-hint' }, diagText()),
|
|
762
961
|
diagSamples())
|
|
763
962
|
: null,
|
|
764
|
-
!hostIsStale && (probe?.count ?? 0) > 0
|
|
963
|
+
!hostIsStale && sessionTotal === 0 && clientCount === 0 && (probe?.count ?? 0) > 0
|
|
765
964
|
? h('div', { className: 'wsk-msg info', style: { marginBottom: 12 } },
|
|
766
965
|
'拿到会话了,但没有一个能对上工作区/目录(路径不匹配)。',
|
|
767
966
|
h('div', { className: 'wsk-hint' }, diagText()),
|
|
@@ -836,25 +1035,31 @@ window.__ModuleLoader__.load({
|
|
|
836
1035
|
if (sessions === undefined || sessions === null) return undefined
|
|
837
1036
|
|
|
838
1037
|
let disposed = false
|
|
839
|
-
const
|
|
1038
|
+
const currentSession = () => {
|
|
840
1039
|
try {
|
|
841
1040
|
const snapshot = sessions.list?.getSnapshot?.()
|
|
842
1041
|
const byId = snapshot?.byId ?? {}
|
|
843
1042
|
for (const [id, item] of Object.entries(byId)) {
|
|
844
|
-
if (Number(item?.retainedBy?.mainView) > 0) return id
|
|
1043
|
+
if (Number(item?.retainedBy?.mainView) > 0) return { id, cwd: item?.cwd }
|
|
845
1044
|
}
|
|
846
1045
|
} catch {
|
|
847
1046
|
/* 快照不可用时静默跳过 */
|
|
848
1047
|
}
|
|
849
1048
|
return undefined
|
|
850
1049
|
}
|
|
1050
|
+
const currentSessionId = () => currentSession()?.id
|
|
851
1051
|
|
|
852
1052
|
const evaluate = async () => {
|
|
853
|
-
const
|
|
1053
|
+
const current = currentSession()
|
|
1054
|
+
const sessionId = current?.id
|
|
854
1055
|
if (sessionId === undefined || asked.current.has(sessionId)) return
|
|
855
1056
|
asked.current.add(sessionId)
|
|
856
1057
|
try {
|
|
857
|
-
|
|
1058
|
+
// 一并带上 cwd:宿主拿到路径后,即使会话列表为空也能定位到工作区。
|
|
1059
|
+
const cwd = typeof current?.cwd === 'string' && current.cwd !== '' ? current.cwd : undefined
|
|
1060
|
+
const query = `/check?sessionId=${encodeURIComponent(sessionId)}`
|
|
1061
|
+
+ (cwd === undefined ? '' : `&path=${encodeURIComponent(cwd)}`)
|
|
1062
|
+
const res = await api(query)
|
|
858
1063
|
if (disposed) return
|
|
859
1064
|
if (res.needsAttention === true) setPrompt(res)
|
|
860
1065
|
} catch {
|
|
@@ -949,6 +1154,7 @@ window.__ModuleLoader__.load({
|
|
|
949
1154
|
ensureStyles()
|
|
950
1155
|
const slots = ctx.get('slots')
|
|
951
1156
|
if (slots === undefined || slots === null) return
|
|
1157
|
+
host.ctx = ctx
|
|
952
1158
|
|
|
953
1159
|
// 惰性取 layout:点击时才读,避免服务尚未就绪时把 undefined 缓存下来。
|
|
954
1160
|
const back = () => {
|
|
@@ -975,7 +1181,7 @@ window.__ModuleLoader__.load({
|
|
|
975
1181
|
slots.register({
|
|
976
1182
|
name: 'main',
|
|
977
1183
|
key: PANEL_ID,
|
|
978
|
-
inject: () => ({ back }),
|
|
1184
|
+
inject: () => ({ back, sessions: ctx.get('sessions') }),
|
|
979
1185
|
}, WorkspaceKeyPage)), 'workspace-api-key: main page')
|
|
980
1186
|
|
|
981
1187
|
ctx.effect(() => slots.inject('shell.overlay', () =>
|
package/lib/index.js
CHANGED
|
@@ -202,9 +202,9 @@ function effectiveOverride(ctx, state, { sessionId, cwd }) {
|
|
|
202
202
|
return { level: 'default', ref: undefined, entry: undefined }
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
// ───────────────── 会话列表(宿主 sessionController
|
|
205
|
+
// ───────────────── 会话列表(宿主 sessionController + live 兜底) ─────────────────
|
|
206
206
|
|
|
207
|
-
/** 宿主是否挂载了会话列表 API
|
|
207
|
+
/** 宿主是否挂载了会话列表 API(仅诊断用;界面看 sessionProbe.available)。 */
|
|
208
208
|
function sessionListAvailable(ctx) {
|
|
209
209
|
try {
|
|
210
210
|
const controller = ctx.get('sessionController')
|
|
@@ -221,33 +221,80 @@ function sessionListAvailable(ctx) {
|
|
|
221
221
|
*/
|
|
222
222
|
async function sessionProbe(ctx) {
|
|
223
223
|
let controller
|
|
224
|
+
let controllerError
|
|
224
225
|
try {
|
|
225
226
|
controller = ctx.get('sessionController')
|
|
226
227
|
} catch (err) {
|
|
227
|
-
|
|
228
|
+
controllerError = String(err?.message ?? err)
|
|
228
229
|
}
|
|
229
|
-
if (controller
|
|
230
|
-
|
|
231
|
-
return { available: false, rows: [], count: 0, error: 'sessionController.list is not a function' }
|
|
230
|
+
if (controller !== undefined && typeof controller.list !== 'function') {
|
|
231
|
+
controllerError = 'sessionController.list is not a function'
|
|
232
232
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
233
|
+
let list = []
|
|
234
|
+
let shape
|
|
235
|
+
let probeError = controllerError
|
|
236
|
+
if (controller !== undefined && typeof controller.list === 'function') {
|
|
237
|
+
try {
|
|
238
|
+
// 宿主 SessionController.list(request, signal) 返回的是 { items: [...] } 信封,
|
|
239
|
+
// 不是数组(远端 remote.session.list 也是同一形状)。早期版本只认数组,
|
|
240
|
+
// 于是「信封」被当成空列表 —— 界面因此看不到任何会话。
|
|
241
|
+
// 这里同时容忍裸数组与小写 value.items(不同 DSH 版本的形状差异)。
|
|
242
|
+
const raw = await controller.list()
|
|
243
|
+
shape = Array.isArray(raw)
|
|
244
|
+
? 'array'
|
|
245
|
+
: raw === null || raw === undefined
|
|
246
|
+
? String(raw)
|
|
247
|
+
: typeof raw === 'object'
|
|
248
|
+
? 'object'
|
|
249
|
+
: typeof raw
|
|
250
|
+
list = Array.isArray(raw)
|
|
251
|
+
? raw
|
|
252
|
+
: Array.isArray(raw?.items)
|
|
253
|
+
? raw.items
|
|
254
|
+
: Array.isArray(raw?.value?.items)
|
|
255
|
+
? raw.value.items
|
|
256
|
+
: []
|
|
257
|
+
if (list.length === 0 && shape === 'object') {
|
|
258
|
+
probeError = `sessionController.list() 返回了 object(keys: ${Object.keys(raw).slice(0, 8).join(',') || '—'}),既不是数组也没有 items`
|
|
243
259
|
}
|
|
244
|
-
|
|
260
|
+
} catch (err) {
|
|
261
|
+
log('sessionController.list failed:', String(err?.message ?? err))
|
|
262
|
+
probeError = String(err?.message ?? err)
|
|
263
|
+
shape = 'throw'
|
|
245
264
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
265
|
+
}
|
|
266
|
+
// sessionController 给不出任何会话时(服务缺失、list 抛错、列表为空……),
|
|
267
|
+
// 用宿主 live 会话服务兜底,让界面至少能列出「当前装载中的会话」。
|
|
268
|
+
let rows = list
|
|
269
|
+
let source = rows.length > 0 ? 'sessionController' : undefined
|
|
270
|
+
if (rows.length === 0) {
|
|
271
|
+
const live = liveSessionRows(ctx)
|
|
272
|
+
if (live.length > 0) {
|
|
273
|
+
rows = live
|
|
274
|
+
source = 'sessions'
|
|
275
|
+
log('sessionController gave no rows, falling back to sessions service:', live.length, 'rows')
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const samples = []
|
|
279
|
+
let withoutCwd = 0
|
|
280
|
+
for (const row of rows) {
|
|
281
|
+
const cwd = typeof row?.cwd === 'string' && row.cwd !== '' ? row.cwd : undefined
|
|
282
|
+
if (cwd === undefined) {
|
|
283
|
+
withoutCwd += 1
|
|
284
|
+
continue
|
|
285
|
+
}
|
|
286
|
+
if (samples.length < 5 && !samples.includes(cwd)) samples.push(cwd)
|
|
287
|
+
}
|
|
288
|
+
log('sessionProbe:', rows.length, 'rows from', source ?? 'none', ',', withoutCwd, 'without cwd, shape', shape)
|
|
289
|
+
return {
|
|
290
|
+
available: source !== undefined,
|
|
291
|
+
rows,
|
|
292
|
+
count: rows.length,
|
|
293
|
+
withoutCwd,
|
|
294
|
+
samples,
|
|
295
|
+
shape,
|
|
296
|
+
source,
|
|
297
|
+
error: probeError,
|
|
251
298
|
}
|
|
252
299
|
}
|
|
253
300
|
|
|
@@ -281,6 +328,69 @@ function titleOf(row) {
|
|
|
281
328
|
return undefined
|
|
282
329
|
}
|
|
283
330
|
|
|
331
|
+
// ───────────────── 兜底:宿主 live 会话服务(ctx.get('sessions')) ─────────────────
|
|
332
|
+
// sessionController.list() 依赖 sessionQuery / 持久化绑定,某些情况下会返回空列表;
|
|
333
|
+
// 而 dsh-session 的 sessions 服务始终有「当前装载中的会话」。用它兜底能让
|
|
334
|
+
// /check(进入会话时的提醒)与 /state 在那种情况下仍然工作。
|
|
335
|
+
|
|
336
|
+
/** 单个 live 会话的 cwd 与当前模型选择。 */
|
|
337
|
+
function liveSessionInfo(ctx, sessionId) {
|
|
338
|
+
if (sessionId === undefined) return undefined
|
|
339
|
+
try {
|
|
340
|
+
const session = ctx.get('sessions')?.get?.(sessionId)
|
|
341
|
+
if (session === undefined || session === null) return undefined
|
|
342
|
+
const cwd = typeof session.header?.cwd === 'string' && session.header.cwd !== ''
|
|
343
|
+
? session.header.cwd
|
|
344
|
+
: undefined
|
|
345
|
+
let config
|
|
346
|
+
try {
|
|
347
|
+
config = session.requestHeader?.()?.config
|
|
348
|
+
} catch {
|
|
349
|
+
config = undefined
|
|
350
|
+
}
|
|
351
|
+
const provider = typeof config?.provider === 'string' && config.provider !== '' ? config.provider : undefined
|
|
352
|
+
const model = typeof config?.model === 'string' && config.model !== '' ? config.model : undefined
|
|
353
|
+
const selection = provider === undefined && model === undefined ? undefined : { provider, model }
|
|
354
|
+
if (cwd === undefined && selection === undefined) return undefined
|
|
355
|
+
return { cwd, selection }
|
|
356
|
+
} catch {
|
|
357
|
+
return undefined
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** 用 live 会话服务凑出与 sessionController 行兼容的摘要(仅在没有其它来源时使用)。 */
|
|
362
|
+
function liveSessionRows(ctx) {
|
|
363
|
+
let sessions = []
|
|
364
|
+
try {
|
|
365
|
+
const service = ctx.get('sessions')
|
|
366
|
+
if (service === undefined || typeof service.list !== 'function') return []
|
|
367
|
+
sessions = service.list() ?? []
|
|
368
|
+
} catch {
|
|
369
|
+
return []
|
|
370
|
+
}
|
|
371
|
+
const rows = []
|
|
372
|
+
for (const session of sessions) {
|
|
373
|
+
const sessionId = session?.id ?? session?.header?.id
|
|
374
|
+
if (typeof sessionId !== 'string' || sessionId === '') continue
|
|
375
|
+
// 子代理会话不作为可配置项列出(与 sessionController 的 remote 列表不同,
|
|
376
|
+
// live 会话服务包含子代理会话)。
|
|
377
|
+
const origin = session?.header?.origin
|
|
378
|
+
if (origin === 'subagent' || session?.header?.parentSession !== undefined) continue
|
|
379
|
+
const info = liveSessionInfo(ctx, sessionId)
|
|
380
|
+
const values = {}
|
|
381
|
+
if (info?.selection !== undefined) values.modelSelection = { ...info.selection }
|
|
382
|
+
rows.push({
|
|
383
|
+
sessionId,
|
|
384
|
+
cwd: info?.cwd,
|
|
385
|
+
updatedAt: 0,
|
|
386
|
+
running: session?.getSnapshot?.()?.running === true,
|
|
387
|
+
blank: false,
|
|
388
|
+
projections: Object.keys(values).length === 0 ? undefined : { values },
|
|
389
|
+
})
|
|
390
|
+
}
|
|
391
|
+
return rows
|
|
392
|
+
}
|
|
393
|
+
|
|
284
394
|
/** 所有 provider 路由名(用于「这把 key 是给哪个 provider 的」选择项)。 */
|
|
285
395
|
function providerList(ctx) {
|
|
286
396
|
const names = new Set(['deepseek-official'])
|
|
@@ -1025,6 +1135,8 @@ async function snapshot(ctx, state) {
|
|
|
1025
1135
|
withoutCwd: probe.withoutCwd ?? 0,
|
|
1026
1136
|
error: probe.error,
|
|
1027
1137
|
samples: probe.samples ?? [],
|
|
1138
|
+
shape: probe.shape,
|
|
1139
|
+
source: probe.source,
|
|
1028
1140
|
},
|
|
1029
1141
|
workspacePathSample: workspaces.slice(0, 5).map((ws) => ws.path),
|
|
1030
1142
|
defaultRef: {
|
|
@@ -1039,7 +1151,8 @@ async function snapshot(ctx, state) {
|
|
|
1039
1151
|
interceptableRefs: [...interceptableRefs(ctx, state)],
|
|
1040
1152
|
workspaceCount: workspaceIndex(ctx).size,
|
|
1041
1153
|
credentialsAvailable: credentials !== undefined,
|
|
1042
|
-
sessionListAvailable:
|
|
1154
|
+
sessionListAvailable: probe.available,
|
|
1155
|
+
sessionControllerAvailable: sessionListAvailable(ctx),
|
|
1043
1156
|
statePath: stateFilePath(),
|
|
1044
1157
|
workspaces,
|
|
1045
1158
|
ungrouped,
|
|
@@ -1100,6 +1213,13 @@ async function checkSession(ctx, state, params) {
|
|
|
1100
1213
|
title = titleOf(row)
|
|
1101
1214
|
}
|
|
1102
1215
|
}
|
|
1216
|
+
// 会话没出现在宿主列表里时(sessionController 空列表、冷会话未装载等),
|
|
1217
|
+
// 用 live 会话服务补 cwd 与模型选择 —— 否则进入会话时的提醒会静默失效。
|
|
1218
|
+
if (sid !== undefined && (cwd === undefined || selection === undefined)) {
|
|
1219
|
+
const live = liveSessionInfo(ctx, sid)
|
|
1220
|
+
if (cwd === undefined && live?.cwd !== undefined) cwd = live.cwd
|
|
1221
|
+
if (selection === undefined && live?.selection !== undefined) selection = live.selection
|
|
1222
|
+
}
|
|
1103
1223
|
if (cwd === undefined) cwd = activeCwd(ctx)
|
|
1104
1224
|
const eff = effectiveOverride(ctx, state, { sessionId: sid, cwd })
|
|
1105
1225
|
const hit = eff.ref !== undefined ? await resolveKey(ctx, eff.ref) : await resolveKey(ctx, 'DEEPSEEK_API_KEY')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-workspace-api-key",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A DeepSeek Harness plugin that binds a separate DeepSeek API key to each workspace, or to a single session, so the spend of one key stays with the sessions you choose.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"homepage": "https://github.com/COH2357/dsh-workspace-api-key#readme",
|
|
16
16
|
"keywords": [
|
|
17
17
|
"dsh",
|
|
18
|
+
"dsh-plugin",
|
|
18
19
|
"deepseek-harness",
|
|
19
20
|
"plugin",
|
|
20
21
|
"api-key",
|