dsh-session-ops 0.2.3 → 0.2.5
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 +25 -2
- package/README.zh.md +14 -2
- package/docs/DETAIL.md +9 -0
- package/docs/DETAIL.zh.md +9 -0
- package/lib/admin.js +152 -7
- package/lib/client.js +263 -0
- package/lib/types/admin.d.ts +102 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -44,6 +44,27 @@ new one, `header.cwd` is rewritten, and workspace membership follows. On kernel
|
|
|
44
44
|
`session.lock` moves with it (same inode); if the target already holds a lease the move is refused
|
|
45
45
|
outright rather than leaving a split lease.
|
|
46
46
|
|
|
47
|
+
## Session panel "session log" (kernel 0.2.2-rc.3+)
|
|
48
|
+
|
|
49
|
+
On kernel 0.2.2-rc.3+ the Session panel in the conversation header carries a "会话日志" section
|
|
50
|
+
registered by this plugin (slot `conversation.session.panel.section`, order 350, after
|
|
51
|
+
environment / change requests / subagents / shared tasks / background jobs). It is read-only and
|
|
52
|
+
shows the current Session's durable artifact:
|
|
53
|
+
|
|
54
|
+
- size, compression format (`zstd` / uncompressed), header format classification (current /
|
|
55
|
+
migration-required);
|
|
56
|
+
- the log file's absolute path;
|
|
57
|
+
- whether the Session is resident in the Host process and mid-turn, plus its workspace.
|
|
58
|
+
|
|
59
|
+
The data comes from one read-only `sessionPersistence.stat(sessionId)` call
|
|
60
|
+
(`/session-admin/api/health`). The route **never decompresses or reads the event log** and never
|
|
61
|
+
enumerates all sessions; the section offers a manual refresh only, and deeper checks such as
|
|
62
|
+
frame-level verification are out of scope. It renders a placeholder while loading so the panel
|
|
63
|
+
never hides the section title for lack of content, and lowers its density when shown as an overlay.
|
|
64
|
+
|
|
65
|
+
On 0.2.1 hosts the slot is not declared: the registration stays pending without an error, and the
|
|
66
|
+
tabs, header icon, context menu, model tools and both HTTP prefixes keep working.
|
|
67
|
+
|
|
47
68
|
## Configuration
|
|
48
69
|
|
|
49
70
|
The plugin row has one shared `enabled` master switch; every other key is independent:
|
|
@@ -76,12 +97,14 @@ writes back to the profile's `cordis.patch.yml`; no restart needed.
|
|
|
76
97
|
## Compatibility
|
|
77
98
|
|
|
78
99
|
- Node.js `>=24`
|
|
79
|
-
- DSH `^0.2.1-rc.2 || ^0.2.2-alpha.2`
|
|
100
|
+
- DSH `^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1`
|
|
80
101
|
|
|
81
102
|
The session context menu needs the kernel's `@deepseek-ai/dsh-client-ui-context-menu` service
|
|
82
103
|
(0.2.2+); without it only those two menu entries are missing — tabs, tools and HTTP endpoints keep
|
|
83
104
|
working. Moving `session.lock` and the boot-time fork-child repair both follow the 0.2.2+
|
|
84
|
-
persistence implementation.
|
|
105
|
+
persistence implementation. The Session panel's "会话日志" section needs 0.2.2-rc.3+ (the slot is
|
|
106
|
+
declared by `@deepseek-ai/dsh-client-ui-session-panel`); on older kernels the registration stays
|
|
107
|
+
pending without an error.
|
|
85
108
|
|
|
86
109
|
## Troubleshooting artifacts
|
|
87
110
|
|
package/README.zh.md
CHANGED
|
@@ -34,6 +34,18 @@ dsh plugin --profile <profile> add dsh-session-ops
|
|
|
34
34
|
|
|
35
35
|
搬迁不是删除:日志目录从旧 project 目录整体移到新目录,`header.cwd` 改写,工作区成员表跟着变。内核 0.2.2+ 的会话目录里有 `session.lock`,搬迁时会一起搬走(inode 不变);目标目录已有租约时直接拒绝,不会留下「锁在旧目录、日志在新目录」的半套状态。
|
|
36
36
|
|
|
37
|
+
## 会话面板「会话日志」(内核 0.2.2-rc.3+)
|
|
38
|
+
|
|
39
|
+
DSH 0.2.2-rc.3 起,会话标题栏的「会话面板」里会出现本插件的「会话日志」小节(槽 `conversation.session.panel.section`,order 350,排在环境/变更请求/子代理/共享任务/后台任务之后)。它只读,展示当前会话的落盘工件:
|
|
40
|
+
|
|
41
|
+
- 字节数、压缩格式(`zstd` / 未压缩)、头部格式分类(正常 / 需要迁移);
|
|
42
|
+
- 日志文件的绝对路径;
|
|
43
|
+
- 是否驻留在 Host 进程里、是否正在跑一轮,以及所属工作区。
|
|
44
|
+
|
|
45
|
+
数据来自宿主 `sessionPersistence.stat(sessionId)` 的一次只读调用(`/session-admin/api/health`)。这条路由**不解压、不整读会话日志**,也不做全量枚举;面板里只有「刷新」按钮,逐帧校验这类深度检查不在本次范围内。加载中先渲染占位,避免空内容连小节标题都不显示;以浮层(overlay)展示时自动降密度。
|
|
46
|
+
|
|
47
|
+
0.2.1 宿主不声明这个槽:注册会挂起且不报错,页签、标题栏图标、右键菜单、模型工具与两条 HTTP 前缀照旧工作。
|
|
48
|
+
|
|
37
49
|
## 配置
|
|
38
50
|
|
|
39
51
|
插件行只有一个 `enabled` 总开关,两个半边共用;其余键各自独立:
|
|
@@ -60,9 +72,9 @@ dsh plugin --profile <profile> add dsh-session-ops
|
|
|
60
72
|
## 兼容区间
|
|
61
73
|
|
|
62
74
|
- Node.js `>=24`
|
|
63
|
-
- DSH `^0.2.1-rc.2 || ^0.2.2-alpha.2`
|
|
75
|
+
- DSH `^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1`
|
|
64
76
|
|
|
65
|
-
会话右键菜单需要内核提供 `@deepseek-ai/dsh-client-ui-context-menu`(0.2.2+)。没有这个服务时只少两个菜单项,页签、工具与 HTTP 入口照旧。搬迁时携带 `session.lock`、启动期 fork 子会话补记账,同样以 0.2.2+
|
|
77
|
+
会话右键菜单需要内核提供 `@deepseek-ai/dsh-client-ui-context-menu`(0.2.2+)。没有这个服务时只少两个菜单项,页签、工具与 HTTP 入口照旧。搬迁时携带 `session.lock`、启动期 fork 子会话补记账,同样以 0.2.2+ 的持久化实现为准。会话面板的「会话日志」小节需要 0.2.2-rc.3+(该槽由 `@deepseek-ai/dsh-client-ui-session-panel` 声明);更早的内核上注册挂起、不报错。
|
|
66
78
|
|
|
67
79
|
## 排障产物
|
|
68
80
|
|
package/docs/DETAIL.md
CHANGED
|
@@ -12,6 +12,15 @@ between workspaces while keeping the registry consistent.
|
|
|
12
12
|
- 新建工作区… in the Move tab: pick an existing directory, register it as a workspace and select it as the move target.
|
|
13
13
|
- Model tools session_admin, session_move, workspace_create; host HTTP /session-admin/api, /session-move/api (including workspaceCreate).
|
|
14
14
|
|
|
15
|
+
## Session panel "session log" (kernel 0.2.2-rc.3+)
|
|
16
|
+
|
|
17
|
+
Registers one read-only section in the conversation header's Session panel: slot `conversation.session.panel.section`, id `dsh-session-ops:session`, order 350 (after environment 0 / change-requests 100 / subagents 200 / shared-tasks 250 / background-jobs 300).
|
|
18
|
+
|
|
19
|
+
- Data plane: `/session-admin/api/health` — one `ctx.sessionPersistence.stat(sessionId)` call returns `path` / `sizeBytes` / `compression` / `formatStatus` / `workspaceId` / `resident` / `running`.
|
|
20
|
+
- No list, no scan, no full log read (`readStoredLog` decompresses the whole frame chain); the section offers a manual refresh, and deeper checks are left for later.
|
|
21
|
+
- A missing Session, a host without `stat`, or a throwing `stat` all come back as 200 + `{found:false, reason}`; an invalid id (empty string, path separators, …) is a structured 400.
|
|
22
|
+
- A 0.2.1 host does not declare the slot: the registration stays pending without an error, and every other entry keeps working.
|
|
23
|
+
|
|
15
24
|
## Shared storage primitives
|
|
16
25
|
|
|
17
26
|
Sources live in `src/store/*.ts` and are built to `lib/store/*.js`:
|
package/docs/DETAIL.zh.md
CHANGED
|
@@ -13,6 +13,15 @@
|
|
|
13
13
|
- 「会话归位」页签的「新建工作区…」:选一个已存在的目录,登记成工作区并直接选为搬迁目标。
|
|
14
14
|
- 模型工具 session_admin、session_move、workspace_create;宿主 HTTP /session-admin/api、/session-move/api(含 workspaceCreate)。
|
|
15
15
|
|
|
16
|
+
## 会话面板「会话日志」(内核 0.2.2-rc.3+)
|
|
17
|
+
|
|
18
|
+
在会话标题栏的会话面板里注册一个只读 section:槽 `conversation.session.panel.section`、id `dsh-session-ops:session`、order 350(排在 environment 0 / change-requests 100 / subagents 200 / shared-tasks 250 / background-jobs 300 之后)。
|
|
19
|
+
|
|
20
|
+
- 数据面:`/session-admin/api/health`,一次 `ctx.sessionPersistence.stat(sessionId)` 返回 `path` / `sizeBytes` / `compression` / `formatStatus` / `workspaceId` / `resident` / `running`。
|
|
21
|
+
- 不 list、不 scan、不整读日志(`readStoredLog` 会解压整条帧链);面板里只有刷新,深度检查留给后续。
|
|
22
|
+
- 会话不存在、宿主没有 `stat`、`stat` 抛错都返回 200 + `{found:false, reason}`;非法 id(空串、路径分隔符等)返回 400 结构化错误。
|
|
23
|
+
- 0.2.1 宿主不声明该槽:注册挂起、不报错,其余入口照旧。
|
|
24
|
+
|
|
16
25
|
## 共享存储原语
|
|
17
26
|
|
|
18
27
|
源码在 `src/store/*.ts`,构建后是 `lib/store/*.js`:
|
package/lib/admin.js
CHANGED
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
* - `<home>/rewind-snapshots/<session-id>/` ← 回退快照(可有可无)
|
|
18
18
|
* 三处一起删,并顺手清掉因此变空的项目目录。
|
|
19
19
|
*
|
|
20
|
+
* 另外对外提供一条**只读**探针 `/session-admin/api/health`:一次 `sessionPersistence.stat()`
|
|
21
|
+
* 返回某条会话的日志路径、字节数、压缩格式、格式分类、工作区归属与驻留/运行状态,供
|
|
22
|
+
* 会话面板的「会话日志」section 使用。它**不整读日志**(`readStoredLog` 会把整条 zstd
|
|
23
|
+
* 帧链解压),也不做全量扫描。
|
|
24
|
+
*
|
|
20
25
|
* 刻意零 `@deepseek-ai/*` 运行时依赖:只用 Node 内置模块和一份 schemastery 配置
|
|
21
26
|
* schema。工具注册用普通对象(与 `dsh-subagent-in-process-driver` 同款),不做
|
|
22
27
|
* `defineTool` 导入——profile 的 node_modules 里未必解析得到 `@deepseek-ai/dsh-tools`。
|
|
@@ -32,7 +37,7 @@ import { readSessionHeader } from './store/frames.js';
|
|
|
32
37
|
import { dshHome } from './store/host.js';
|
|
33
38
|
import { createApiHandler } from './store/http.js';
|
|
34
39
|
import { decodeProjectKey } from './store/paths.js';
|
|
35
|
-
import { releaseSessionEverywhere, residentSessionIds, runningSessionIds, } from './store/registry.js';
|
|
40
|
+
import { releaseSessionEverywhere, residentSessionIds, runningSessionIds, workspaceOwningSession, } from './store/registry.js';
|
|
36
41
|
import { messageOf } from './store/util.js';
|
|
37
42
|
/** HTTP 路由前缀(两半各一条,合并后仍然分开)。 */
|
|
38
43
|
export const ADMIN_API_PREFIX = '/session-admin/api';
|
|
@@ -508,8 +513,127 @@ export function isTrustedRequest(req, allowHosts = []) {
|
|
|
508
513
|
return false;
|
|
509
514
|
}
|
|
510
515
|
}
|
|
516
|
+
/**
|
|
517
|
+
* 校验 `health` 的会话 id。
|
|
518
|
+
*
|
|
519
|
+
* 会话 id 是不透明标识,不允许带路径分隔符:`stat` 之后各后端会自己拼路径,这里先挡
|
|
520
|
+
* 一道目录穿越(`../../x`)与明显非法的输入,让浏览器拿到 400 + 结构化错误,而不是
|
|
521
|
+
* 一句后端抛出的裸异常。**不做 trim**——id 原样交给后端,避免"看起来一样其实不是同一条"。
|
|
522
|
+
* @param value - 请求里的 `sessionId`。
|
|
523
|
+
* @returns 合法 id。
|
|
524
|
+
* @throws 类型/长度/路径分隔符不合法时抛 `Error`(路由层会包成 400)。
|
|
525
|
+
*/
|
|
526
|
+
function requireSessionId(value) {
|
|
527
|
+
if (typeof value !== 'string')
|
|
528
|
+
throw new Error('sessionId must be a string');
|
|
529
|
+
if (value.length === 0)
|
|
530
|
+
throw new Error('sessionId must not be empty');
|
|
531
|
+
if (value.length > 512)
|
|
532
|
+
throw new Error('sessionId is too long (max 512 characters)');
|
|
533
|
+
if (value === '.' || value === '..' || value.includes('/') || value.includes('\\') || value.includes('\0')) {
|
|
534
|
+
throw new Error('sessionId must not contain a path separator');
|
|
535
|
+
}
|
|
536
|
+
return value;
|
|
537
|
+
}
|
|
538
|
+
/** 后端声明的压缩格式;拿不到就是 null(不猜一个默认值)。 */
|
|
539
|
+
function compressionOf(source) {
|
|
540
|
+
const value = source.persistence?.compression;
|
|
541
|
+
return typeof value === 'string' ? value : null;
|
|
542
|
+
}
|
|
543
|
+
/** 界面提示用的驻留查询:服务缺失/抛错一律当作「不驻留」,不让面板整块失败。 */
|
|
544
|
+
function residentOf(holds, sessionId) {
|
|
545
|
+
try {
|
|
546
|
+
return holds.resident().has(sessionId);
|
|
547
|
+
}
|
|
548
|
+
catch {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
/** 界面提示用的「在跑」查询:与 {@link residentOf} 同样的降级策略。 */
|
|
553
|
+
function runningOf(holds, sessionId) {
|
|
554
|
+
try {
|
|
555
|
+
return holds.running().has(sessionId);
|
|
556
|
+
}
|
|
557
|
+
catch {
|
|
558
|
+
return false;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/** 归属查询的安全包装:注册表缺失/抛错时按「不属于任何工作区」处理。 */
|
|
562
|
+
function workspaceIdOf(registry, sessionId) {
|
|
563
|
+
try {
|
|
564
|
+
if (registry === undefined || typeof registry.list !== 'function')
|
|
565
|
+
return null;
|
|
566
|
+
const workspaces = registry.list();
|
|
567
|
+
// 完整记账在 `workspace.record.sessionIds`;老实体没有 record 时退回过滤后的成员视图。
|
|
568
|
+
const owner = workspaceOwningSession(workspaces, sessionId);
|
|
569
|
+
if (owner !== undefined)
|
|
570
|
+
return owner.id === undefined ? null : String(owner.id);
|
|
571
|
+
for (const workspace of workspaces) {
|
|
572
|
+
if (Array.isArray(workspace.sessionIds) && workspace.sessionIds.includes(sessionId)) {
|
|
573
|
+
return workspace.id === undefined ? null : String(workspace.id);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
catch {
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* 只读地观察一条会话的日志工件。
|
|
584
|
+
*
|
|
585
|
+
* 只调用一次 `sessionPersistence.stat()`:**绝不整读日志**(`readStoredLog` 会把整个
|
|
586
|
+
* zstd 帧链解压,一条几百 MB 的会话能卡住面板)。三种失败都收敛成结构化结果,
|
|
587
|
+
* 分别给面板「没这条会话」「宿主不支持」「读取失败」三种话术。
|
|
588
|
+
* @param sessionId - 请求里的会话 id(会先校验)。
|
|
589
|
+
* @param source - 持久化后端与归属查询(见 {@link HealthSource})。
|
|
590
|
+
* @param holds - `{resident, running}`。
|
|
591
|
+
* @returns 观察结果。
|
|
592
|
+
* @throws 会话 id 不合法(交给路由层转 400)。
|
|
593
|
+
*/
|
|
594
|
+
export async function sessionHealth(sessionId, source, holds) {
|
|
595
|
+
const id = requireSessionId(sessionId);
|
|
596
|
+
const base = {
|
|
597
|
+
id,
|
|
598
|
+
found: false,
|
|
599
|
+
path: null,
|
|
600
|
+
sizeBytes: null,
|
|
601
|
+
compression: compressionOf(source),
|
|
602
|
+
formatStatus: null,
|
|
603
|
+
workspaceId: source.workspaceIdOf(id) ?? null,
|
|
604
|
+
resident: residentOf(holds, id),
|
|
605
|
+
running: runningOf(holds, id),
|
|
606
|
+
};
|
|
607
|
+
// 必须**在接收者上**调用:内核 JSONL 后端的 `stat` 是原型方法,方法体第一句读
|
|
608
|
+
// `this.ensureRootEncoding()`(还有 `this.tracker` / `this.findLog`)。摘成游离函数
|
|
609
|
+
// 再 `stat(id)` 会以 `this === undefined` 调用,抛
|
|
610
|
+
// `Cannot read properties of undefined (reading 'ensureRootEncoding')`——
|
|
611
|
+
// 0.2.4 的「会话日志」section 就是这么整块报「读取失败」的。
|
|
612
|
+
const persistence = source.persistence;
|
|
613
|
+
if (typeof persistence?.stat !== 'function') {
|
|
614
|
+
return { ...base, reason: 'persistence-unavailable' };
|
|
615
|
+
}
|
|
616
|
+
let snapshot;
|
|
617
|
+
try {
|
|
618
|
+
snapshot = await persistence.stat(id);
|
|
619
|
+
}
|
|
620
|
+
catch (error) {
|
|
621
|
+
return { ...base, reason: 'read-failed', message: messageOf(error) };
|
|
622
|
+
}
|
|
623
|
+
if (snapshot === undefined || snapshot === null)
|
|
624
|
+
return { ...base, reason: 'not-found' };
|
|
625
|
+
return {
|
|
626
|
+
...base,
|
|
627
|
+
found: true,
|
|
628
|
+
path: typeof snapshot.location?.path === 'string' ? snapshot.location.path : null,
|
|
629
|
+
sizeBytes: typeof snapshot.sizeBytes === 'number' && Number.isFinite(snapshot.sizeBytes)
|
|
630
|
+
? snapshot.sizeBytes
|
|
631
|
+
: null,
|
|
632
|
+
formatStatus: typeof snapshot.formatStatus === 'string' ? snapshot.formatStatus : null,
|
|
633
|
+
};
|
|
634
|
+
}
|
|
511
635
|
/** `GET` 与 `POST` 共用的方法表。 */
|
|
512
|
-
function buildApi(admin, config, log, holds) {
|
|
636
|
+
function buildApi(admin, config, log, holds, health) {
|
|
513
637
|
return {
|
|
514
638
|
/**
|
|
515
639
|
* 浏览器半边需要的界面开关。
|
|
@@ -526,6 +650,17 @@ function buildApi(admin, config, log, holds) {
|
|
|
526
650
|
maxBatch: config.maxBatch,
|
|
527
651
|
};
|
|
528
652
|
},
|
|
653
|
+
/**
|
|
654
|
+
* 一条会话的只读日志工件摘要(会话面板「会话日志」section 用)。
|
|
655
|
+
*
|
|
656
|
+
* 刻意不走 `list()` / `scan()`:一次 `sessionPersistence.stat()` 只碰这一条会话的
|
|
657
|
+
* 文件元数据,面板打开是 O(1) 次 stat,与这台机器上有多少条会话无关。
|
|
658
|
+
* 会话不存在 / 宿主不支持 / 读取失败都返回 200 + `{found:false, reason}`;只有非法
|
|
659
|
+
* id 会抛给路由层变成 400(结构化信封)。
|
|
660
|
+
*/
|
|
661
|
+
async health(payload) {
|
|
662
|
+
return sessionHealth(payload?.sessionId, health, holds);
|
|
663
|
+
},
|
|
529
664
|
/**
|
|
530
665
|
* 只要个数的轻量查询,供电标这类高频调用方使用。
|
|
531
666
|
*
|
|
@@ -727,10 +862,11 @@ function human(bytes) {
|
|
|
727
862
|
* @param config - 插件配置。
|
|
728
863
|
* @param log - 日志函数。
|
|
729
864
|
* @param holds - `{resident, running}`:进程仍挂着的会话集合,以及其中**正在跑**的那部分。
|
|
865
|
+
* @param health - 只读日志探针的数据源(与 HTTP `health` 方法共用)。
|
|
730
866
|
* @returns `ctx.tools.register` 接受的普通对象定义。
|
|
731
867
|
*/
|
|
732
|
-
function buildTool(admin, config, log, holds) {
|
|
733
|
-
const api = buildApi(admin, config, log, holds);
|
|
868
|
+
function buildTool(admin, config, log, holds, health) {
|
|
869
|
+
const api = buildApi(admin, config, log, holds, health);
|
|
734
870
|
return {
|
|
735
871
|
name: 'session_admin',
|
|
736
872
|
description: 'List or permanently delete persisted DSH sessions on this machine. DSH itself can only archive (hide) a session; this tool removes its durable data (session log, projection cache, rewind snapshots) and drops the session from its Workspace membership, archive set and pin set, so no dangling reference is left behind. ' +
|
|
@@ -845,7 +981,8 @@ function summarizeReasons(results) {
|
|
|
845
981
|
* - 响应带 `content-length`;
|
|
846
982
|
* - 请求体按**宽松模式**读(空白 body 走 `JSON.parse` 报错,非对象不拦)。
|
|
847
983
|
*
|
|
848
|
-
* @param ctx - Host cordis 上下文(`webServer` / `tools` / `sessions` / `workspaceRegistry
|
|
984
|
+
* @param ctx - Host cordis 上下文(`webServer` / `tools` / `sessions` / `workspaceRegistry` /
|
|
985
|
+
* `sessionPersistence`;后者只用于只读的 `health` 探针,缺失时降级为「宿主不支持」)。
|
|
849
986
|
* @param config - 已解包的**活配置对象**:身份由入口保持,volatile 更新时原地覆盖,
|
|
850
987
|
* 所以下面这些闭包自动看到最新值。
|
|
851
988
|
* @param log - `(level, message) => void`(入口传的是 admin 那套行格式的文件日志)。
|
|
@@ -886,7 +1023,15 @@ export function mountAdmin(ctx, config, log) {
|
|
|
886
1023
|
*/
|
|
887
1024
|
const runningIds = () => runningSessionIds(residentIds(), ctx.get('agents'));
|
|
888
1025
|
const holds = { resident: residentIds, running: runningIds };
|
|
889
|
-
|
|
1026
|
+
/**
|
|
1027
|
+
* 只读日志探针的数据源:「本会话日志」section 每次打开只要这一条会话的文件元数据,
|
|
1028
|
+
* 所以它走 `sessionPersistence.stat()`,而不是 `scan()`/`list()` 那种全量枚举。
|
|
1029
|
+
*/
|
|
1030
|
+
const health = {
|
|
1031
|
+
persistence: ctx.sessionPersistence,
|
|
1032
|
+
workspaceIdOf: (sessionId) => workspaceIdOf(ctx.workspaceRegistry, sessionId),
|
|
1033
|
+
};
|
|
1034
|
+
const api = buildApi(admin, config, log, holds, health);
|
|
890
1035
|
log('info', `mounted: home=${admin.home} prefix=${ADMIN_API_PREFIX} allowHosts=[${config.adminAllowHosts.join(', ')}]`);
|
|
891
1036
|
ctx.effect(() => ctx.webServer.register({
|
|
892
1037
|
kind: 'prefix',
|
|
@@ -904,6 +1049,6 @@ export function mountAdmin(ctx, config, log) {
|
|
|
904
1049
|
log,
|
|
905
1050
|
}),
|
|
906
1051
|
}), 'dsh-session-admin: api route');
|
|
907
|
-
ctx.effect(() => ctx.tools.register(buildTool(admin, config, log, holds)), 'dsh-session-admin: session_admin tool');
|
|
1052
|
+
ctx.effect(() => ctx.tools.register(buildTool(admin, config, log, holds, health)), 'dsh-session-admin: session_admin tool');
|
|
908
1053
|
}
|
|
909
1054
|
// 2026-09-25:本文件由 dsh-session-admin/lib/index.js 逐字搬入 dsh-session-ops(合并包)。
|
package/lib/client.js
CHANGED
|
@@ -52,6 +52,13 @@
|
|
|
52
52
|
* 页,不是配置菜单。卡片体一个字符都没改:这个槽不传 `form`,所以注册项的 `inject`
|
|
53
53
|
* 把 `ctx.configForms.get('session-toolbox')` 的 `{ state, mutate }` 喂给它。
|
|
54
54
|
*
|
|
55
|
+
* ## 会话面板(0.2.2-rc.3+):只读的「会话日志」section
|
|
56
|
+
*
|
|
57
|
+
* 会话标题栏的「会话面板」里注册一个只读 section(`conversation.session.panel.section`、
|
|
58
|
+
* id `dsh-session-ops:session`、order 350):一次 `/session-admin/api/health`(Host 侧
|
|
59
|
+
* `sessionPersistence.stat`)展示日志路径 / 大小 / 压缩格式 / 格式分类 / 驻留与运行状态。
|
|
60
|
+
* 不整读日志;0.2.1 宿主没有这个槽时注册挂起、不报错。
|
|
61
|
+
*
|
|
55
62
|
* @module dsh-session-ops/client
|
|
56
63
|
*/
|
|
57
64
|
;
|
|
@@ -103,6 +110,12 @@
|
|
|
103
110
|
badge: { fontSize: 10.5, padding: '0 5px', borderRadius: 999, border: '1px solid var(--dsh-border, #d0d5dd)', opacity: 0.75, whiteSpace: 'nowrap' },
|
|
104
111
|
result: { border: '1px solid var(--dsh-border-subtle, rgba(128,128,128,0.22))', borderRadius: 8, padding: '8px 10px', fontSize: 12 },
|
|
105
112
|
headerIconButton: { display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 28, height: 28, padding: 6, border: 'none', borderRadius: 28, background: 'transparent', color: 'inherit', cursor: 'pointer', flex: 'none', opacity: 0.78 },
|
|
113
|
+
// 「会话日志」section:只读的一小块元数据,没有表单与列表。
|
|
114
|
+
log: { display: 'flex', flexDirection: 'column', gap: 5, minWidth: 0 },
|
|
115
|
+
logRow: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap', minWidth: 0 },
|
|
116
|
+
logRefresh: { marginLeft: 'auto', flex: 'none' },
|
|
117
|
+
logPath: { fontFamily: 'ui-monospace, Consolas, monospace', fontSize: 11, lineHeight: 1.4, opacity: 0.62, wordBreak: 'break-all' },
|
|
118
|
+
logPathDense: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', wordBreak: 'normal' },
|
|
106
119
|
};
|
|
107
120
|
/**
|
|
108
121
|
* 面板的两种排版。
|
|
@@ -189,6 +202,237 @@
|
|
|
189
202
|
}
|
|
190
203
|
return { call };
|
|
191
204
|
}
|
|
205
|
+
// ── 「本会话日志」section(DSH 0.2.2-rc.3+ 的会话面板) ─────────────────────
|
|
206
|
+
//
|
|
207
|
+
// 数据来自 Host 的只读 `health` 方法:一次 `sessionPersistence.stat()`,不整读日志。
|
|
208
|
+
// 这一段与右栏页签、标题栏垃圾桶完全解耦——它只读,不参与删除/搬迁。
|
|
209
|
+
/**
|
|
210
|
+
* 「会话日志」section 的数据面:按 sessionId 缓存 + 同一会话单飞 + 切会话取消。
|
|
211
|
+
*
|
|
212
|
+
* 做成独立对象而不是组件里的 useState,有三个理由:
|
|
213
|
+
* - 面板每次展开都会重新挂载 section,缓存要跨挂载保留,否则每次展开都重新 stat;
|
|
214
|
+
* - 切 `sessionId` 时必须能**主动 abort** 上一条在途请求(慢会话的结果回来时界面
|
|
215
|
+
* 已经在看另一条会话了);
|
|
216
|
+
* - 注册项通过 `inject` 把它交给组件,测试可以直接拿到它验证取消行为,不用渲染 React。
|
|
217
|
+
* @param api - 删除半边的 Host API 客户端(与页面共用 `/session-admin/api` 前缀)。
|
|
218
|
+
* @returns 数据面:`entryOf` / `load` / `refresh` / `subscribe` / `abort`。
|
|
219
|
+
*/
|
|
220
|
+
function createSessionLogHealth(api) {
|
|
221
|
+
/** sessionId → `{state, value?, message?, at?}`。 */
|
|
222
|
+
const entries = new Map();
|
|
223
|
+
/** sessionId → 在途请求的 AbortController。 */
|
|
224
|
+
const controllers = new Map();
|
|
225
|
+
const listeners = new Set();
|
|
226
|
+
const notify = () => {
|
|
227
|
+
for (const listener of [...listeners]) {
|
|
228
|
+
try {
|
|
229
|
+
listener();
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
/* 单个订阅者失败不影响其它 */
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
const setEntry = (sessionId, entry) => {
|
|
237
|
+
entries.set(sessionId, entry);
|
|
238
|
+
notify();
|
|
239
|
+
};
|
|
240
|
+
const isCurrent = (sessionId, controller) => controllers.get(sessionId) === controller;
|
|
241
|
+
const dropController = (sessionId, controller) => {
|
|
242
|
+
if (isCurrent(sessionId, controller))
|
|
243
|
+
controllers.delete(sessionId);
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* 取消**其它**会话的在途请求。面板同一时刻只显示一条会话,切走之后旧请求的结果
|
|
247
|
+
* 已经没人看;只取消别的 id,不碰当前 id 自己的请求。
|
|
248
|
+
*/
|
|
249
|
+
function abortOthers(sessionId) {
|
|
250
|
+
for (const [other, controller] of [...controllers]) {
|
|
251
|
+
if (other === sessionId)
|
|
252
|
+
continue;
|
|
253
|
+
controllers.delete(other);
|
|
254
|
+
try {
|
|
255
|
+
controller.abort();
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
/* 已结束的控制器再 abort 也无害 */
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* 读一条会话的日志摘要。
|
|
264
|
+
* @param sessionId - 会话 id。
|
|
265
|
+
* @param options - `{force: true}` 跳过缓存(手动刷新);默认命中 ready 缓存直接返回。
|
|
266
|
+
* @returns 该会话的最新条目(被取消/失败时也 resolve,状态里写着原因)。
|
|
267
|
+
*/
|
|
268
|
+
async function load(sessionId, options = {}) {
|
|
269
|
+
if (typeof sessionId !== 'string' || sessionId === '')
|
|
270
|
+
return undefined;
|
|
271
|
+
const cached = entries.get(sessionId);
|
|
272
|
+
if (options.force !== true && cached !== undefined && cached.state === 'ready')
|
|
273
|
+
return cached;
|
|
274
|
+
abortOthers(sessionId);
|
|
275
|
+
if (controllers.has(sessionId))
|
|
276
|
+
return entries.get(sessionId);
|
|
277
|
+
const controller = new AbortController();
|
|
278
|
+
controllers.set(sessionId, controller);
|
|
279
|
+
// 这次 loading 的身份标记:被取消时只撤掉自己写入的那条,不覆盖后来者的条目。
|
|
280
|
+
const token = {};
|
|
281
|
+
setEntry(sessionId, { state: 'loading', value: cached?.value, at: cached?.at, token });
|
|
282
|
+
try {
|
|
283
|
+
const value = await api.call('health', { sessionId }, controller.signal);
|
|
284
|
+
dropController(sessionId, controller);
|
|
285
|
+
if (controller.signal.aborted)
|
|
286
|
+
return entries.get(sessionId);
|
|
287
|
+
setEntry(sessionId, { state: 'ready', value, at: Date.now() });
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
dropController(sessionId, controller);
|
|
291
|
+
if (controller.signal.aborted) {
|
|
292
|
+
// 取消不是失败:把这次 loading 撤掉,回到取消前的样子。
|
|
293
|
+
const current = entries.get(sessionId);
|
|
294
|
+
if (current?.token === token) {
|
|
295
|
+
if (cached === undefined) {
|
|
296
|
+
entries.delete(sessionId);
|
|
297
|
+
notify();
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
setEntry(sessionId, cached);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return entries.get(sessionId);
|
|
304
|
+
}
|
|
305
|
+
setEntry(sessionId, {
|
|
306
|
+
state: 'error',
|
|
307
|
+
message: String(error?.message ?? error),
|
|
308
|
+
value: cached?.value,
|
|
309
|
+
at: cached?.at,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
return entries.get(sessionId);
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
/** 当前已知条目;没有就是 undefined(首次加载中)。 */
|
|
316
|
+
entryOf(sessionId) {
|
|
317
|
+
return entries.get(sessionId);
|
|
318
|
+
},
|
|
319
|
+
load,
|
|
320
|
+
/** 手动刷新:绕过缓存。 */
|
|
321
|
+
refresh(sessionId) {
|
|
322
|
+
return load(sessionId, { force: true });
|
|
323
|
+
},
|
|
324
|
+
/** 订阅状态变化;返回退订函数。 */
|
|
325
|
+
subscribe(listener) {
|
|
326
|
+
listeners.add(listener);
|
|
327
|
+
return () => {
|
|
328
|
+
listeners.delete(listener);
|
|
329
|
+
};
|
|
330
|
+
},
|
|
331
|
+
/** 取消某条会话的在途请求(section 卸载时用:没人等这个结果了)。 */
|
|
332
|
+
abort(sessionId) {
|
|
333
|
+
const controller = controllers.get(sessionId);
|
|
334
|
+
if (controller === undefined)
|
|
335
|
+
return;
|
|
336
|
+
controllers.delete(sessionId);
|
|
337
|
+
try {
|
|
338
|
+
controller.abort();
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
/* 同上 */
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
/** `formatStatus` 的界面文案。 */
|
|
347
|
+
function describeFormat(status) {
|
|
348
|
+
if (status === 'current')
|
|
349
|
+
return '格式正常';
|
|
350
|
+
if (status === 'migration-required')
|
|
351
|
+
return '需要迁移';
|
|
352
|
+
return '格式未知';
|
|
353
|
+
}
|
|
354
|
+
/** 压缩格式的界面文案(`''` 是内核 jsonl 后端的「未压缩」)。 */
|
|
355
|
+
function describeCompression(compression) {
|
|
356
|
+
if (compression === 'zstd')
|
|
357
|
+
return 'zstd';
|
|
358
|
+
if (compression === '')
|
|
359
|
+
return '未压缩';
|
|
360
|
+
if (typeof compression === 'string' && compression !== '')
|
|
361
|
+
return compression;
|
|
362
|
+
return '压缩未知';
|
|
363
|
+
}
|
|
364
|
+
/** `found:false` 的一句话原因。 */
|
|
365
|
+
function describeMissingLog(entry) {
|
|
366
|
+
const reason = entry?.value?.reason;
|
|
367
|
+
if (reason === 'not-found')
|
|
368
|
+
return '宿主上没有这条会话的日志';
|
|
369
|
+
if (reason === 'persistence-unavailable')
|
|
370
|
+
return '宿主未暴露会话持久化 stat,读不到日志信息';
|
|
371
|
+
if (reason === 'read-failed')
|
|
372
|
+
return `读取失败:${entry?.value?.message ?? '未知错误'}`;
|
|
373
|
+
return '没有可显示的日志信息';
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* 「会话日志」section:只读展示本会话的落盘工件。
|
|
377
|
+
*
|
|
378
|
+
* 加载中也要渲染占位:这个槽**内容为空时连 section 标题都不画**,返回 null 会让
|
|
379
|
+
* 整个入口看起来不存在。overlay 展示时降密度(路径单行省略、格式徽章只在不正常时出现)。
|
|
380
|
+
* @param React - 外壳预置的 React。
|
|
381
|
+
* @param fallbackHealth - 数据面;注册项的 `inject` 会给同一个对象。
|
|
382
|
+
* @returns React 组件。
|
|
383
|
+
*/
|
|
384
|
+
function createSessionLogSection(React, fallbackHealth) {
|
|
385
|
+
const h = React.createElement;
|
|
386
|
+
return function SessionLogSection(props) {
|
|
387
|
+
const health = props?.health ?? fallbackHealth;
|
|
388
|
+
const sessionId = typeof props?.sessionId === 'string' ? props.sessionId : '';
|
|
389
|
+
const dense = props?.presentation === 'overlay';
|
|
390
|
+
const [, setTick] = React.useState(0);
|
|
391
|
+
React.useEffect(() => {
|
|
392
|
+
let alive = true;
|
|
393
|
+
const unsubscribe = health.subscribe(() => {
|
|
394
|
+
if (alive)
|
|
395
|
+
setTick((value) => value + 1);
|
|
396
|
+
});
|
|
397
|
+
void health.load(sessionId);
|
|
398
|
+
return () => {
|
|
399
|
+
alive = false;
|
|
400
|
+
unsubscribe();
|
|
401
|
+
health.abort(sessionId);
|
|
402
|
+
};
|
|
403
|
+
}, [sessionId]);
|
|
404
|
+
const entry = health.entryOf(sessionId);
|
|
405
|
+
const refreshButton = h('button', { type: 'button', style: S.button, onClick: () => void health.refresh(sessionId) }, '刷新');
|
|
406
|
+
if (entry === undefined || entry.state === 'error') {
|
|
407
|
+
return h('div', { style: S.log }, h('div', { style: entry === undefined ? S.muted : S.error }, entry === undefined ? '读取中…' : `读取失败:${entry.message}`), entry === undefined ? null : refreshButton);
|
|
408
|
+
}
|
|
409
|
+
const value = entry.value;
|
|
410
|
+
if (value === undefined || value?.found !== true) {
|
|
411
|
+
return h('div', { style: S.log }, h('div', { style: S.muted }, describeMissingLog(entry)), refreshButton);
|
|
412
|
+
}
|
|
413
|
+
const badges = [
|
|
414
|
+
h('span', {
|
|
415
|
+
key: 'size',
|
|
416
|
+
style: S.badge,
|
|
417
|
+
title: Number.isFinite(value.sizeBytes) ? `${value.sizeBytes} B` : undefined,
|
|
418
|
+
}, Number.isFinite(value.sizeBytes) ? human(value.sizeBytes) : '大小未知'),
|
|
419
|
+
];
|
|
420
|
+
// overlay 只保留「不正常」的格式提示:正常时不再占一行。
|
|
421
|
+
if (!dense || (value.formatStatus !== undefined && value.formatStatus !== null && value.formatStatus !== 'current')) {
|
|
422
|
+
badges.push(h('span', { key: 'format', style: S.badge }, describeFormat(value.formatStatus)));
|
|
423
|
+
badges.push(h('span', { key: 'compression', style: S.badge }, describeCompression(value.compression)));
|
|
424
|
+
}
|
|
425
|
+
if (value.running === true)
|
|
426
|
+
badges.push(h('span', { key: 'running', style: S.badge }, '运行中'));
|
|
427
|
+
if (value.resident === true)
|
|
428
|
+
badges.push(h('span', { key: 'resident', style: S.badge }, '驻留'));
|
|
429
|
+
if (entry.state === 'loading')
|
|
430
|
+
badges.push(h('span', { key: 'loading', style: S.muted }, '刷新中…'));
|
|
431
|
+
return h('div', { style: S.log }, h('div', { style: S.logRow }, badges, h('span', { style: S.logRefresh }, refreshButton)), value.path === null
|
|
432
|
+
? null
|
|
433
|
+
: h('div', { style: dense ? { ...S.logPath, ...S.logPathDense } : S.logPath, title: value.path }, value.path));
|
|
434
|
+
};
|
|
435
|
+
}
|
|
192
436
|
/**
|
|
193
437
|
* 「未分组有多少条」的角标数据源。
|
|
194
438
|
*
|
|
@@ -1143,6 +1387,25 @@
|
|
|
1143
1387
|
}
|
|
1144
1388
|
};
|
|
1145
1389
|
});
|
|
1390
|
+
// 6) 会话面板(DSH 0.2.2-rc.3+):「会话日志」section。
|
|
1391
|
+
//
|
|
1392
|
+
// 面板由内核的 `@deepseek-ai/dsh-client-ui-session-panel` 提供,槽是
|
|
1393
|
+
// `conversation.session.panel.section`(kind list、scope session)。order 350
|
|
1394
|
+
// 排在现网占位之后(environment 0 / change-requests 100 / subagents 200 /
|
|
1395
|
+
// shared-tasks 250 / background-jobs 300),是「这条会话自己」的信息,不抢前面。
|
|
1396
|
+
//
|
|
1397
|
+
// 数据来自 Host 的只读 `health`(一次 sessionPersistence.stat,不整读日志);
|
|
1398
|
+
// 数据面通过注册项的 `inject` 交给组件——同时让测试能直接拿到它验证取消行为。
|
|
1399
|
+
//
|
|
1400
|
+
// 兼容:0.2.1 宿主不声明这个槽,`ctx.slots.inject` 会一直挂着且不报错,其余入口照旧。
|
|
1401
|
+
const sessionLogHealth = createSessionLogHealth(api);
|
|
1402
|
+
ctx.slots.inject('conversation.session.panel.section', () => ctx.slots.register({
|
|
1403
|
+
name: 'conversation.session.panel.section',
|
|
1404
|
+
id: 'dsh-session-ops:session',
|
|
1405
|
+
order: 350,
|
|
1406
|
+
label: () => '会话日志',
|
|
1407
|
+
inject: () => ({ health: sessionLogHealth }),
|
|
1408
|
+
}, createSessionLogSection(React, sessionLogHealth)));
|
|
1146
1409
|
}
|
|
1147
1410
|
// `configForms`:配置卡片挂的是插件页的 `plugins.bundle.config`,那个槽不传共享
|
|
1148
1411
|
// 表单,卡片要自己从 `ctx.configForms.get(CONFIG_ENTRY_ID)` 取(见上面第 4 条)。
|
package/lib/types/admin.d.ts
CHANGED
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
* - `<home>/rewind-snapshots/<session-id>/` ← 回退快照(可有可无)
|
|
18
18
|
* 三处一起删,并顺手清掉因此变空的项目目录。
|
|
19
19
|
*
|
|
20
|
+
* 另外对外提供一条**只读**探针 `/session-admin/api/health`:一次 `sessionPersistence.stat()`
|
|
21
|
+
* 返回某条会话的日志路径、字节数、压缩格式、格式分类、工作区归属与驻留/运行状态,供
|
|
22
|
+
* 会话面板的「会话日志」section 使用。它**不整读日志**(`readStoredLog` 会把整条 zstd
|
|
23
|
+
* 帧链解压),也不做全量扫描。
|
|
24
|
+
*
|
|
20
25
|
* 刻意零 `@deepseek-ai/*` 运行时依赖:只用 Node 内置模块和一份 schemastery 配置
|
|
21
26
|
* schema。工具注册用普通对象(与 `dsh-subagent-in-process-driver` 同款),不做
|
|
22
27
|
* `defineTool` 导入——profile 的 node_modules 里未必解析得到 `@deepseek-ai/dsh-tools`。
|
|
@@ -154,6 +159,96 @@ export declare function createSessionAdmin(options?: CreateSessionAdminOptions):
|
|
|
154
159
|
* @returns 是否放行。
|
|
155
160
|
*/
|
|
156
161
|
export declare function isTrustedRequest(req: HttpRequest, allowHosts?: string[]): boolean;
|
|
162
|
+
/** 进程内会话集合的两个查询(界面提示用,不做守卫)。 */
|
|
163
|
+
interface Holds {
|
|
164
|
+
resident: () => Set<string>;
|
|
165
|
+
running: () => Set<string>;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* `ctx.sessionPersistence.stat()` 返回快照里本模块用到的部分。
|
|
169
|
+
*
|
|
170
|
+
* 形状对应内核 0.2.3 的 `SessionPersistenceSnapshot`:`sizeBytes` / `formatStatus` /
|
|
171
|
+
* `location` 都只有**落盘的实体工件**才有(尚未落盘的新会话或后端不暴露文件时为 undefined)。
|
|
172
|
+
* 刻意声明成可选字段而不是照抄内核类型:本包对 `@deepseek-ai/*` 只做最小本地接口。
|
|
173
|
+
*/
|
|
174
|
+
export interface StoredSessionSnapshotLike {
|
|
175
|
+
header?: Record<string, unknown> | undefined;
|
|
176
|
+
revision?: unknown;
|
|
177
|
+
/** 物理文件字节数(JSONL 后端)。 */
|
|
178
|
+
sizeBytes?: unknown;
|
|
179
|
+
/** 头部格式分类(`'current'` / `'migration-required'`)。 */
|
|
180
|
+
formatStatus?: unknown;
|
|
181
|
+
/** 逻辑事件数(后端能便宜给出时才有)。 */
|
|
182
|
+
eventCount?: unknown;
|
|
183
|
+
/** 物理文件位置(JSONL 后端;未落盘的新会话没有)。 */
|
|
184
|
+
location?: {
|
|
185
|
+
kind?: unknown;
|
|
186
|
+
path?: unknown;
|
|
187
|
+
} | undefined;
|
|
188
|
+
}
|
|
189
|
+
/** `health` 用到的持久化后端子集(`ctx.sessionPersistence`)。 */
|
|
190
|
+
export interface SessionPersistenceStatLike {
|
|
191
|
+
/**
|
|
192
|
+
* 只读观察一条会话:一次 stat + 一次头部读,**不解压事件日志**。
|
|
193
|
+
* 会话不存在时返回 undefined。
|
|
194
|
+
*
|
|
195
|
+
* 调用方必须写成 `persistence.stat(id)`:内核实现依赖 `this`
|
|
196
|
+
* (`this.ensureRootEncoding()` / `this.tracker` / `this.findLog`),摘成游离
|
|
197
|
+
* 函数调用会拿到 `this === undefined`,直接抛 TypeError。
|
|
198
|
+
*/
|
|
199
|
+
stat?: ((sessionId: string) => Promise<StoredSessionSnapshotLike | undefined>) | undefined;
|
|
200
|
+
/** 压缩格式(jsonl 后端为 `'zstd'`;未压缩为空字符串)。 */
|
|
201
|
+
compression?: unknown;
|
|
202
|
+
}
|
|
203
|
+
/** `health` 的数据源:持久化后端 + 工作区归属查询。 */
|
|
204
|
+
export interface HealthSource {
|
|
205
|
+
persistence?: SessionPersistenceStatLike | undefined;
|
|
206
|
+
/** 会话所属工作区 id;不属于任何工作区时 null。 */
|
|
207
|
+
workspaceIdOf: (sessionId: string) => string | null;
|
|
208
|
+
}
|
|
209
|
+
/** {@link SessionHealth} 里 `found:false` 的机器可读原因。 */
|
|
210
|
+
export type SessionHealthReason = 'not-found' | 'persistence-unavailable' | 'read-failed';
|
|
211
|
+
/**
|
|
212
|
+
* 「本会话日志」的只读观察结果(`/session-admin/api/health` 的 `value`)。
|
|
213
|
+
*
|
|
214
|
+
* 一次 `sessionPersistence.stat()` 就够:**不 list、不 scan、不整读日志**。
|
|
215
|
+
*/
|
|
216
|
+
export interface SessionHealth {
|
|
217
|
+
id: string;
|
|
218
|
+
/** 宿主上是否有这条会话的落盘工件。 */
|
|
219
|
+
found: boolean;
|
|
220
|
+
/** 会话日志的物理路径;后端没有实体文件(未落盘)时为 null。 */
|
|
221
|
+
path: string | null;
|
|
222
|
+
/** 物理文件字节数;后端给不出时为 null。 */
|
|
223
|
+
sizeBytes: number | null;
|
|
224
|
+
/** 压缩格式(`'zstd'` / `''` 未压缩);后端不暴露时为 null。 */
|
|
225
|
+
compression: string | null;
|
|
226
|
+
/** 头部格式分类(`'current'` / `'migration-required'`);后端给不出时为 null。 */
|
|
227
|
+
formatStatus: string | null;
|
|
228
|
+
/** 所属工作区 id;不属于任何工作区时为 null。 */
|
|
229
|
+
workspaceId: string | null;
|
|
230
|
+
/** Host 进程里挂着这条会话。 */
|
|
231
|
+
resident: boolean;
|
|
232
|
+
/** 这条会话正在跑一轮。 */
|
|
233
|
+
running: boolean;
|
|
234
|
+
/** `found:false` 时的原因。 */
|
|
235
|
+
reason?: SessionHealthReason;
|
|
236
|
+
/** `reason: 'read-failed'` 时的错误正文。 */
|
|
237
|
+
message?: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* 只读地观察一条会话的日志工件。
|
|
241
|
+
*
|
|
242
|
+
* 只调用一次 `sessionPersistence.stat()`:**绝不整读日志**(`readStoredLog` 会把整个
|
|
243
|
+
* zstd 帧链解压,一条几百 MB 的会话能卡住面板)。三种失败都收敛成结构化结果,
|
|
244
|
+
* 分别给面板「没这条会话」「宿主不支持」「读取失败」三种话术。
|
|
245
|
+
* @param sessionId - 请求里的会话 id(会先校验)。
|
|
246
|
+
* @param source - 持久化后端与归属查询(见 {@link HealthSource})。
|
|
247
|
+
* @param holds - `{resident, running}`。
|
|
248
|
+
* @returns 观察结果。
|
|
249
|
+
* @throws 会话 id 不合法(交给路由层转 400)。
|
|
250
|
+
*/
|
|
251
|
+
export declare function sessionHealth(sessionId: unknown, source: HealthSource, holds: Holds): Promise<SessionHealth>;
|
|
157
252
|
/**
|
|
158
253
|
* Host cordis 上下文里删除半边用到的那部分(最小本地接口,见 `src/index.ts` 的说明)。
|
|
159
254
|
*/
|
|
@@ -168,6 +263,11 @@ export interface AdminContext {
|
|
|
168
263
|
register(definition: unknown): unknown;
|
|
169
264
|
};
|
|
170
265
|
workspaceRegistry: WorkspaceRegistryLike;
|
|
266
|
+
/**
|
|
267
|
+
* 会话持久化后端(可选):只有只读的 `health` 探针用到它的 `stat` / `compression`。
|
|
268
|
+
* 缺失或没有 `stat` 时面板显示「宿主不支持」,删除/搬迁的其余入口不受影响。
|
|
269
|
+
*/
|
|
270
|
+
sessionPersistence?: SessionPersistenceStatLike | undefined;
|
|
171
271
|
}
|
|
172
272
|
/**
|
|
173
273
|
* 挂载删除半边:路由 + 工具。
|
|
@@ -178,7 +278,8 @@ export interface AdminContext {
|
|
|
178
278
|
* - 响应带 `content-length`;
|
|
179
279
|
* - 请求体按**宽松模式**读(空白 body 走 `JSON.parse` 报错,非对象不拦)。
|
|
180
280
|
*
|
|
181
|
-
* @param ctx - Host cordis 上下文(`webServer` / `tools` / `sessions` / `workspaceRegistry
|
|
281
|
+
* @param ctx - Host cordis 上下文(`webServer` / `tools` / `sessions` / `workspaceRegistry` /
|
|
282
|
+
* `sessionPersistence`;后者只用于只读的 `health` 探针,缺失时降级为「宿主不支持」)。
|
|
182
283
|
* @param config - 已解包的**活配置对象**:身份由入口保持,volatile 更新时原地覆盖,
|
|
183
284
|
* 所以下面这些闭包自动看到最新值。
|
|
184
285
|
* @param log - `(level, message) => void`(入口传的是 admin 那套行格式的文件日志)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-ops",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=24",
|
|
57
|
-
"dsh": "^0.2.1-rc.2 || ^0.2.2-alpha.2"
|
|
57
|
+
"dsh": "^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@deepseek-ai/schemastery": "^3.18.5 || ^3.18.6-alpha.1"
|
|
@@ -85,7 +85,9 @@
|
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
|
+
"@deepseek-ai/dsh-client-ui-session": "0.2.3-alpha.2",
|
|
89
|
+
"@deepseek-ai/dsh-client-ui-session-panel": "0.2.3-alpha.2",
|
|
88
90
|
"@types/node": "^26.6.5",
|
|
89
91
|
"typescript": "^7.0.2"
|
|
90
92
|
}
|
|
91
|
-
}
|
|
93
|
+
}
|