dsh-session-conductor 1.0.9 → 1.0.10
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/lib/repair.js +29 -1
- package/lib/session-codec.js +9 -3
- package/package.json +1 -1
package/lib/repair.js
CHANGED
|
@@ -67,12 +67,40 @@ export function validateSessionText(text) {
|
|
|
67
67
|
problems.push(`seq ${ev.seq} tool/result 缺 message.id`);
|
|
68
68
|
continue;
|
|
69
69
|
}
|
|
70
|
-
if (message.role !== "user") problems.push(`seq ${ev.seq} tool/result role 应为 user`);
|
|
71
70
|
const source = message.source;
|
|
72
71
|
if (typeof source !== "object" || source === null || source.kind !== "tool" || typeof source.callId !== "string" || source.callId === "") {
|
|
73
72
|
problems.push(`seq ${ev.seq} tool/result source 非法`);
|
|
74
73
|
continue;
|
|
75
74
|
}
|
|
75
|
+
// —— tool/result 的两种合法形态(按会话格式版本区分,此处不做版本假设,直接按 role 分派)——
|
|
76
|
+
// v3(DSH ≤0.1.x / session.v3.jsonl.zstd):message.role = "user",
|
|
77
|
+
// 结果包在 content[0] 的 {type:"tool-result"} wrapper 里,toolCallId 在 wrapper 上。
|
|
78
|
+
// v4(DSH 0.2.1 起 / session.v4.jsonl.zstd):message.role = "tool"(first-class tool-role),
|
|
79
|
+
// toolCallId 提升到 message 层,content 直接是结果块数组(**不再有** wrapper)。
|
|
80
|
+
// 官方口径见 packages/session/session-format-v3-to-v4 的 assertV4ToolResultMessage。
|
|
81
|
+
// 【bug 修复】此前只认 v3 的 role="user",DSH 升到 0.2.1 后 v4 日志一律被判
|
|
82
|
+
// 「role 应为 user」而校验失败 —— 表现为 set_member_model 等「写入前先校验」
|
|
83
|
+
// 的功能对 v4 会话必然失败(而日志本身完全正常)。
|
|
84
|
+
if (message.role === "tool") {
|
|
85
|
+
// v4 形态
|
|
86
|
+
if (message.toolCallId !== source.callId) problems.push(`seq ${ev.seq} v4 toolCallId 与 source.callId 不匹配`);
|
|
87
|
+
if (!Array.isArray(message.content)) {
|
|
88
|
+
problems.push(`seq ${ev.seq} tool/result content 非数组`);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (message.content.some((b) => typeof b === "object" && b !== null && b.type === "tool-result")) {
|
|
92
|
+
problems.push(`seq ${ev.seq} v4 content 不应再含 tool-result wrapper(v4 已把它提升为原生字段)`);
|
|
93
|
+
}
|
|
94
|
+
if (message.isError !== undefined && typeof message.isError !== "boolean") {
|
|
95
|
+
problems.push(`seq ${ev.seq} v4 isError 必须是 boolean`);
|
|
96
|
+
}
|
|
97
|
+
if (ev.data?.error !== undefined && message.isError !== true) {
|
|
98
|
+
problems.push(`seq ${ev.seq} v4 带 error 元数据但 isError 不为 true`);
|
|
99
|
+
}
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
// v3 形态(原逻辑保留)
|
|
103
|
+
if (message.role !== "user") problems.push(`seq ${ev.seq} tool/result role 应为 user(v3)或 tool(v4),实际 ${JSON.stringify(message.role)}`);
|
|
76
104
|
if (!Array.isArray(message.content)) {
|
|
77
105
|
problems.push(`seq ${ev.seq} tool/result content 非数组`);
|
|
78
106
|
continue;
|
package/lib/session-codec.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
// dsh-session-conductor —
|
|
1
|
+
// dsh-session-conductor — 会话日志记录编解码(自研)
|
|
2
2
|
//
|
|
3
3
|
// DSH 0.1.6-alpha.1(SESSION_FORMAT_VERSION = 3)已移除旧版公开 API:
|
|
4
4
|
// decodeStorageRecord / packChunkRuns(v0/v1 旧格式的 *-chunks 打包编解码器)。
|
|
5
5
|
// 本模块提供功能等价实现,供 repair.js / seq-gap-repair.js / tools/validate-session.mjs 使用:
|
|
6
6
|
// · decodeStorageRecord(record) → 事件数组
|
|
7
|
-
// v3 格式:一行一个事件 JSON(记录即事件对象,含 type 字段)→ 返回 [record];
|
|
7
|
+
// v3/v4 格式:一行一个事件 JSON(记录即事件对象,含 type 字段)→ 返回 [record];
|
|
8
8
|
// 旧格式容器({events:[...]})→ 返回 record.events;
|
|
9
9
|
// 无 type 且无 events 的未知记录 → 抛错(调用方 try/catch 判定解析失败)。
|
|
10
10
|
// · packChunkRuns(events) → 记录行数组
|
|
11
|
-
// v3 格式:一行一事件,直接返回事件数组(写回时每个事件 JSON 一行)。
|
|
11
|
+
// v3/v4 格式:一行一事件,直接返回事件数组(写回时每个事件 JSON 一行)。
|
|
12
|
+
//
|
|
13
|
+
// 【v3 → v4 说明(DSH 0.2.1 起)】记录/帧结构未变(仍是一行一事件),
|
|
14
|
+
// 变的是**事件内部的 message 结构**:tool/result 的 message.role 由 "user" 改为 "tool"
|
|
15
|
+
// (first-class tool-role),toolCallId 提升到 message 层,content 不再有 tool-result wrapper。
|
|
16
|
+
// 因此本模块无需改动;按 message 结构做校验的地方(见 repair.js 的 validateSessionText)
|
|
17
|
+
// 必须按 role 分派。官方口径:packages/session/session-format-v3-to-v4/src/tool-role.ts。
|
|
12
18
|
|
|
13
19
|
/**
|
|
14
20
|
* 把一条存储记录解码为事件数组(v3 会话格式:记录即单个事件对象)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-conductor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "DSH session management enhancement: archive/restore sessions, batch & conditional delete, AI auto-rename, interrupted-session auto-resume, release idle sessions, workspace grouping, undo last message, repair damaged session logs, value analysis, full-text search, per-member model switching (list_models / set_member_model), and plan/closing template injection (system-prompt + context).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|