@deepseek-ai/dsh-session 0.1.7-alpha.2 → 0.1.7-rc.2
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.i18n.yaml +102 -5
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/index.js +89 -0
- package/lib/types/index.d.ts +11 -0
- package/lib/types/index.js +16 -0
- package/lib/types/tool-history.d.ts +29 -0
- package/lib/types/tool-history.js +76 -0
- package/lib/types/types.d.ts +4 -4
- package/package.json +10 -10
package/README.i18n.yaml
CHANGED
|
@@ -1,6 +1,103 @@
|
|
|
1
|
-
# Bilingual-pair consistency record (docs/i18n/README.md):
|
|
2
|
-
#
|
|
3
|
-
#
|
|
1
|
+
# Bilingual-pair consistency record for README.md (docs/i18n/README.md): per heading
|
|
2
|
+
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
|
3
|
+
# After editing either side, bring the other along and re-record with:
|
|
4
4
|
# pnpm run verify-translation-pairing --write packages/core/session/README.md
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/:
|
|
6
|
+
en: 54dedea99ec5492c
|
|
7
|
+
zh: 23b29cb5d738dadb
|
|
8
|
+
/deepseek-ai-dsh-session:
|
|
9
|
+
en: c019c0e8c7f9cba0
|
|
10
|
+
zh: 151e150825fda310
|
|
11
|
+
/deepseek-ai-dsh-session/summary:
|
|
12
|
+
en: 311239677afd230a
|
|
13
|
+
zh: f2c575945baaa2a2
|
|
14
|
+
/deepseek-ai-dsh-session/table-of-contents:
|
|
15
|
+
en: d152484eb41ac6b4
|
|
16
|
+
zh: 09388d293f9be9cb
|
|
17
|
+
/deepseek-ai-dsh-session/use-this-package:
|
|
18
|
+
en: 0882d4056c45aa75
|
|
19
|
+
zh: fcee78e9845b78b3
|
|
20
|
+
/deepseek-ai-dsh-session/use-this-package/create-and-inspect-sessions:
|
|
21
|
+
en: f80dab583fa3939d
|
|
22
|
+
zh: 5a9a79ebcef86119
|
|
23
|
+
/deepseek-ai-dsh-session/use-this-package/append-and-derive:
|
|
24
|
+
en: aa5f1951ecf3ac0c
|
|
25
|
+
zh: 62a599ace8f2bf15
|
|
26
|
+
/deepseek-ai-dsh-session/use-this-package/read-the-log:
|
|
27
|
+
en: 2b29cfeac7a2baa8
|
|
28
|
+
zh: b535b04dcbc29d3d
|
|
29
|
+
/deepseek-ai-dsh-session/use-this-package/fork-a-session:
|
|
30
|
+
en: 1c40d17a786059d3
|
|
31
|
+
zh: 81320ce118977c65
|
|
32
|
+
/deepseek-ai-dsh-session/use-this-package/flush-durable-state:
|
|
33
|
+
en: 70a7673145c851ad
|
|
34
|
+
zh: 0dd1667d9518993d
|
|
35
|
+
/deepseek-ai-dsh-session/understand-the-implementation:
|
|
36
|
+
en: ce7e776e9d516bdb
|
|
37
|
+
zh: 59d2751743db7795
|
|
38
|
+
/deepseek-ai-dsh-session/understand-the-implementation/design-concept:
|
|
39
|
+
en: dabbe938e288c55a
|
|
40
|
+
zh: 31c7ac2bee2a2846
|
|
41
|
+
/deepseek-ai-dsh-session/understand-the-implementation/request-headers:
|
|
42
|
+
en: bbfb53c50100ab13
|
|
43
|
+
zh: 303a8ee47f4f656a
|
|
44
|
+
/deepseek-ai-dsh-session/understand-the-implementation/source-map:
|
|
45
|
+
en: e87f7ef34effbad2
|
|
46
|
+
zh: 774a98d23611f5f5
|
|
47
|
+
/deepseek-ai-dsh-session/understand-the-implementation/append-validation:
|
|
48
|
+
en: 5c09583bc8e1ffc6
|
|
49
|
+
zh: 3b25552de2d1f9b6
|
|
50
|
+
/deepseek-ai-dsh-session/understand-the-implementation/derived-history:
|
|
51
|
+
en: 0cc7a06f76bd7eca
|
|
52
|
+
zh: 1db25185b15cad23
|
|
53
|
+
/deepseek-ai-dsh-session/understand-the-implementation/the-request-header:
|
|
54
|
+
en: 1349f47bea4dab00
|
|
55
|
+
zh: 20cc03f2c87ec492
|
|
56
|
+
/deepseek-ai-dsh-session/further-exploration:
|
|
57
|
+
en: e23d6c8b31295044
|
|
58
|
+
zh: 5105ac9ce8c5d90d
|
|
59
|
+
/deepseek-ai-dsh-session/model-experience:
|
|
60
|
+
en: 215e7ba838619b7b
|
|
61
|
+
zh: a311da3843709f90
|
|
62
|
+
/deepseek-ai-dsh-session/model-experience/derived-message-history:
|
|
63
|
+
en: 3005f28ded3b28ea
|
|
64
|
+
zh: daaddc6df470b396
|
|
65
|
+
/deepseek-ai-dsh-session/model-experience/derived-message-history/what-the-model-sees:
|
|
66
|
+
en: 30ccd8296306b132
|
|
67
|
+
zh: 19efa5a43745585c
|
|
68
|
+
/deepseek-ai-dsh-session/model-experience/derived-message-history/token-effect:
|
|
69
|
+
en: 05e088199dac7f98
|
|
70
|
+
zh: 35868b5fb768e240
|
|
71
|
+
/deepseek-ai-dsh-session/model-experience/derived-message-history/kv-cache-effect:
|
|
72
|
+
en: 6c8079c7de029ed4
|
|
73
|
+
zh: 634d6f93ce6373c4
|
|
74
|
+
/deepseek-ai-dsh-session/model-experience/crash-repair-and-fork-results:
|
|
75
|
+
en: 4aa585f38846e017
|
|
76
|
+
zh: ef28f54125a9021d
|
|
77
|
+
/deepseek-ai-dsh-session/model-experience/crash-repair-and-fork-results/what-the-model-sees:
|
|
78
|
+
en: b2ae41b23519cdc6
|
|
79
|
+
zh: 05ce1c9a8b8c3283
|
|
80
|
+
/deepseek-ai-dsh-session/model-experience/crash-repair-and-fork-results/token-effect:
|
|
81
|
+
en: ac63e0f30175f72d
|
|
82
|
+
zh: 20f63deeffa249f2
|
|
83
|
+
/deepseek-ai-dsh-session/model-experience/crash-repair-and-fork-results/kv-cache-effect:
|
|
84
|
+
en: f5d5f97a153f7c70
|
|
85
|
+
zh: b84ef7f75f2e25d0
|
|
86
|
+
/deepseek-ai-dsh-session/model-experience/logged-request-header:
|
|
87
|
+
en: 5397f067293a55cd
|
|
88
|
+
zh: 1dcc30d0c214f175
|
|
89
|
+
/deepseek-ai-dsh-session/model-experience/logged-request-header/what-the-model-sees:
|
|
90
|
+
en: cfb4fd90e1982948
|
|
91
|
+
zh: fefc01118b2a5c07
|
|
92
|
+
/deepseek-ai-dsh-session/model-experience/logged-request-header/token-effect:
|
|
93
|
+
en: 310b8f36a86443e5
|
|
94
|
+
zh: 906c4da8d03c5966
|
|
95
|
+
/deepseek-ai-dsh-session/model-experience/logged-request-header/kv-cache-effect:
|
|
96
|
+
en: 5eb30cfb410d52c0
|
|
97
|
+
zh: da56365b8ab896da
|
|
98
|
+
/deepseek-ai-dsh-session/known-limitations-and-deferred-work:
|
|
99
|
+
en: daaf56dda2bcaff1
|
|
100
|
+
zh: 7d24de2deb1c5dc5
|
|
101
|
+
/deepseek-ai-dsh-session/known-limitations-and-deferred-work/dev-note:
|
|
102
|
+
en: e67f633dc6fe7773
|
|
103
|
+
zh: 3bb0c20c93f16f98
|
package/README.md
CHANGED
|
@@ -167,7 +167,7 @@ Append-only; newly visible content follows the reusable request prefix and does
|
|
|
167
167
|
|
|
168
168
|
#### What the model sees
|
|
169
169
|
|
|
170
|
-
The session reconstructs
|
|
170
|
+
The session reconstructs active tool schemas and call config from request headers; provider-specific deferred and retained declarations are derived at dispatch. `toolHistory()` caches a stateful fold over committed headers and developer messages, consuming only unseen events on subsequent reads. It resolves additions through their historical `headerSeq`, returns immutable snapshots, and restarts declarations on an explicit request series or a changed retained definition. Restoring a retained name with an unchanged definition continues the series; the recorded addition re-offers it. Both loop requests and compaction calls use this state. Headers lacking matching update records use complete active declarations. Same-name schema changes are allowed and invalidate prefix reuse even on `in-history` routes; registration-time rejection against historical tools is deferred ([rationale](../../../.agents/notes/implemented/architecture/2026-09-20-dynamic-tool-updates.md)). The system prompt remains part of `deriveMessages()`; header events add no message or prompt copy.
|
|
171
171
|
|
|
172
172
|
#### Token effect
|
|
173
173
|
|
package/README.zh.md
CHANGED
|
@@ -169,7 +169,7 @@ Fork 生成的结果只描述继承记录:父会话可能已经在所选事件
|
|
|
169
169
|
|
|
170
170
|
#### 模型看到什么
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
会话从请求头重建有效工具模式和调用配置;提供方专用的延迟声明与保留声明在分发时派生。`toolHistory()` 缓存对已提交请求头和 developer 消息的有状态归约,后续读取仅处理新增事件。它通过历史 `headerSeq` 解析添加定义,返回不可变快照,并在显式新请求序列或保留定义发生变化时重新建立声明。以未变化的定义恢复保留名称时序列继续,由记录的添加重新提供该工具。循环请求和压缩调用均使用此状态。 请求头缺少对应更新记录时,使用完整有效声明。 允许同名工具的 schema 变化,即使在 `in-history` 路由上也会使前缀复用失效;注册时对照历史工具进行拒绝检查留待后续实现([原因](../../../.agents/notes/implemented/architecture/2026-09-20-dynamic-tool-updates.zh.md))。系统提示词仍属于 `deriveMessages()`;请求头事件不添加消息或提示词副本。
|
|
173
173
|
|
|
174
174
|
#### Token 影响
|
|
175
175
|
|
package/lib/index.js
CHANGED
|
@@ -637,6 +637,81 @@ function foldRequestHeader(events, from) {
|
|
|
637
637
|
return state;
|
|
638
638
|
}
|
|
639
639
|
//#endregion
|
|
640
|
+
//#region lib/types/tool-history.js
|
|
641
|
+
/** Stateful reconstruction of historical tool definitions for request projection. */
|
|
642
|
+
/** Folds committed headers and developer messages independently of model capability. */
|
|
643
|
+
var ToolHistoryProjection = class {
|
|
644
|
+
/** Historical declarations indexed by the header sequence referenced by additions. */
|
|
645
|
+
headers = /* @__PURE__ */ new Map();
|
|
646
|
+
/** Definitions retained in the current declaration series, including removed tools. */
|
|
647
|
+
declared = /* @__PURE__ */ new Map();
|
|
648
|
+
/** Active definitions from the latest request header. */
|
|
649
|
+
active = [];
|
|
650
|
+
/** Active names reconstructed from the baseline and recorded updates. */
|
|
651
|
+
available = /* @__PURE__ */ new Set();
|
|
652
|
+
/** Header that starts the current declaration series; absent before the first header. */
|
|
653
|
+
baselineSeq;
|
|
654
|
+
/** Immutable request snapshot of the current baseline and resolved updates. */
|
|
655
|
+
history = deepFreeze({
|
|
656
|
+
tools: [],
|
|
657
|
+
updates: []
|
|
658
|
+
});
|
|
659
|
+
/**
|
|
660
|
+
* Consume the next committed event in log order.
|
|
661
|
+
* @param event - a session event, including inherited events during restoration.
|
|
662
|
+
*/
|
|
663
|
+
apply(event) {
|
|
664
|
+
if (event.type === "request/header") {
|
|
665
|
+
const tools = event.data.header.tools ?? [];
|
|
666
|
+
this.headers.set(event.seq, tools);
|
|
667
|
+
const redeclared = tools.some((tool) => {
|
|
668
|
+
const before = this.declared.get(tool.name);
|
|
669
|
+
return before !== void 0 && JSON.stringify(before) !== JSON.stringify(tool);
|
|
670
|
+
});
|
|
671
|
+
if (this.baselineSeq === void 0 || event.data.reason === "series" || event.data.startsSeries || redeclared) {
|
|
672
|
+
this.baselineSeq = event.seq;
|
|
673
|
+
this.declared = new Map(tools.map((tool) => [tool.name, tool]));
|
|
674
|
+
this.history = deepFreeze({
|
|
675
|
+
tools,
|
|
676
|
+
updates: []
|
|
677
|
+
});
|
|
678
|
+
this.available = new Set(tools.map((tool) => tool.name));
|
|
679
|
+
}
|
|
680
|
+
this.active = tools;
|
|
681
|
+
} else if (event.type === "developer/message") {
|
|
682
|
+
const { message, headerSeq } = event.data;
|
|
683
|
+
const definitions = headerSeq === void 0 ? [] : this.headers.get(headerSeq);
|
|
684
|
+
const additions = message.content.flatMap((block) => {
|
|
685
|
+
if (block.type !== "tool-addition") return [];
|
|
686
|
+
const tool = definitions?.find((tool) => tool.name === block.toolName);
|
|
687
|
+
if (tool === void 0) throw new Error(`tool history: missing definition for ${block.toolName}`);
|
|
688
|
+
return [tool];
|
|
689
|
+
});
|
|
690
|
+
for (const tool of additions) this.declared.set(tool.name, tool);
|
|
691
|
+
for (const block of message.content) if (block.type === "tool-addition") this.available.add(block.toolName);
|
|
692
|
+
else if (block.type === "tool-removal") this.available.delete(block.toolName);
|
|
693
|
+
this.history = deepFreeze({
|
|
694
|
+
tools: this.history.tools,
|
|
695
|
+
updates: [...this.history.updates, {
|
|
696
|
+
messageId: message.id,
|
|
697
|
+
additions
|
|
698
|
+
}]
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Read an immutable snapshot; subsequent events do not mutate it.
|
|
704
|
+
* @returns initial declarations and historically resolved additions for the current series.
|
|
705
|
+
*/
|
|
706
|
+
snapshot() {
|
|
707
|
+
if (this.active.length !== this.available.size || this.active.some((tool) => !this.available.has(tool.name))) return deepFreeze({
|
|
708
|
+
tools: this.active,
|
|
709
|
+
updates: []
|
|
710
|
+
});
|
|
711
|
+
return this.history;
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
//#endregion
|
|
640
715
|
//#region lib/types/repair.js
|
|
641
716
|
/**
|
|
642
717
|
* Synthetic closer events that balance a session log whose tail turn is open.
|
|
@@ -1398,6 +1473,20 @@ var Session = class Session {
|
|
|
1398
1473
|
}
|
|
1399
1474
|
return this.contextFold;
|
|
1400
1475
|
}
|
|
1476
|
+
/** Cached historical tool definitions and updates for request projection. */
|
|
1477
|
+
toolHistoryProjection = new ToolHistoryProjection();
|
|
1478
|
+
/** Index of the next committed event not yet consumed by the tool-history fold. */
|
|
1479
|
+
toolHistorySeq = 0;
|
|
1480
|
+
/**
|
|
1481
|
+
* Fold unseen committed events into capability-independent tool history.
|
|
1482
|
+
* Initial access reconstructs inherited history; later reads consume only new events.
|
|
1483
|
+
* @returns an immutable snapshot for LLM request projection, including historical addition definitions.
|
|
1484
|
+
*/
|
|
1485
|
+
toolHistory() {
|
|
1486
|
+
for (const event of this.log.slice(this.toolHistorySeq)) this.toolHistoryProjection.apply(event);
|
|
1487
|
+
this.toolHistorySeq = this.log.length;
|
|
1488
|
+
return this.toolHistoryProjection.snapshot();
|
|
1489
|
+
}
|
|
1401
1490
|
/** The derived-message cache: frozen projections, extended per unseen node. */
|
|
1402
1491
|
derived = [];
|
|
1403
1492
|
/** Surface position (nodes projected) the cache has reached. */
|
package/lib/types/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { SessionLogOffset, SessionSeq } from './types.ts';
|
|
|
12
12
|
import type { TypertLookup } from '@deepseek-ai/dsh-typert-protocol';
|
|
13
13
|
import type { CreateSessionOptions, EpochHeader, PrepareSessionOptions, RequestContext, SessionEvent, SessionEventMap, SessionEventType, SessionHeader, SessionId, SessionSeedEventState, SurfaceIntent, SurfaceEventType } from './types.ts';
|
|
14
14
|
import type { SessionSurface, SessionMessageProjection } from './surface.ts';
|
|
15
|
+
import type { ToolHistory } from '@deepseek-ai/dsh-llm';
|
|
15
16
|
export { buildForkSeed } from './fork.ts';
|
|
16
17
|
export * from './types.ts';
|
|
17
18
|
export { SessionPreparation } from './preparation.ts';
|
|
@@ -265,6 +266,16 @@ export declare class Session {
|
|
|
265
266
|
* @returns the latest immutable route metadata.
|
|
266
267
|
*/
|
|
267
268
|
requestContext(): RequestContext | undefined;
|
|
269
|
+
/** Cached historical tool definitions and updates for request projection. */
|
|
270
|
+
private readonly toolHistoryProjection;
|
|
271
|
+
/** Index of the next committed event not yet consumed by the tool-history fold. */
|
|
272
|
+
private toolHistorySeq;
|
|
273
|
+
/**
|
|
274
|
+
* Fold unseen committed events into capability-independent tool history.
|
|
275
|
+
* Initial access reconstructs inherited history; later reads consume only new events.
|
|
276
|
+
* @returns an immutable snapshot for LLM request projection, including historical addition definitions.
|
|
277
|
+
*/
|
|
278
|
+
toolHistory(): ToolHistory;
|
|
268
279
|
/** The derived-message cache: frozen projections, extended per unseen node. */
|
|
269
280
|
private derived;
|
|
270
281
|
/** Surface position (nodes projected) the cache has reached. */
|
package/lib/types/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import { scopeOf, scopeTarget } from '@deepseek-ai/dsh-scope';
|
|
|
13
13
|
import { SESSION_FORMAT_VERSION, SessionLogOffset, SessionSeq } from "./types.js";
|
|
14
14
|
import { SurfaceManager, validateSessionEventData, validateSurfaceMetadata } from "./surface.js";
|
|
15
15
|
import { foldRequestHeader } from "./request-header.js";
|
|
16
|
+
import { ToolHistoryProjection } from "./tool-history.js";
|
|
16
17
|
import { buildForkSeed } from "./fork.js";
|
|
17
18
|
export { buildForkSeed } from "./fork.js";
|
|
18
19
|
export * from "./types.js";
|
|
@@ -654,6 +655,21 @@ export class Session {
|
|
|
654
655
|
}
|
|
655
656
|
return this.contextFold;
|
|
656
657
|
}
|
|
658
|
+
/** Cached historical tool definitions and updates for request projection. */
|
|
659
|
+
toolHistoryProjection = new ToolHistoryProjection();
|
|
660
|
+
/** Index of the next committed event not yet consumed by the tool-history fold. */
|
|
661
|
+
toolHistorySeq = 0;
|
|
662
|
+
/**
|
|
663
|
+
* Fold unseen committed events into capability-independent tool history.
|
|
664
|
+
* Initial access reconstructs inherited history; later reads consume only new events.
|
|
665
|
+
* @returns an immutable snapshot for LLM request projection, including historical addition definitions.
|
|
666
|
+
*/
|
|
667
|
+
toolHistory() {
|
|
668
|
+
for (const event of this.log.slice(this.toolHistorySeq))
|
|
669
|
+
this.toolHistoryProjection.apply(event);
|
|
670
|
+
this.toolHistorySeq = this.log.length;
|
|
671
|
+
return this.toolHistoryProjection.snapshot();
|
|
672
|
+
}
|
|
657
673
|
/** The derived-message cache: frozen projections, extended per unseen node. */
|
|
658
674
|
derived = [];
|
|
659
675
|
/** Surface position (nodes projected) the cache has reached. */
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Stateful reconstruction of historical tool definitions for request projection. */
|
|
2
|
+
import type { ToolHistory } from '@deepseek-ai/dsh-llm';
|
|
3
|
+
import type { SessionEvent } from './types.ts';
|
|
4
|
+
/** Folds committed headers and developer messages independently of model capability. */
|
|
5
|
+
export declare class ToolHistoryProjection {
|
|
6
|
+
/** Historical declarations indexed by the header sequence referenced by additions. */
|
|
7
|
+
private readonly headers;
|
|
8
|
+
/** Definitions retained in the current declaration series, including removed tools. */
|
|
9
|
+
private declared;
|
|
10
|
+
/** Active definitions from the latest request header. */
|
|
11
|
+
private active;
|
|
12
|
+
/** Active names reconstructed from the baseline and recorded updates. */
|
|
13
|
+
private available;
|
|
14
|
+
/** Header that starts the current declaration series; absent before the first header. */
|
|
15
|
+
private baselineSeq;
|
|
16
|
+
/** Immutable request snapshot of the current baseline and resolved updates. */
|
|
17
|
+
private history;
|
|
18
|
+
/**
|
|
19
|
+
* Consume the next committed event in log order.
|
|
20
|
+
* @param event - a session event, including inherited events during restoration.
|
|
21
|
+
*/
|
|
22
|
+
apply(event: SessionEvent): void;
|
|
23
|
+
/**
|
|
24
|
+
* Read an immutable snapshot; subsequent events do not mutate it.
|
|
25
|
+
* @returns initial declarations and historically resolved additions for the current series.
|
|
26
|
+
*/
|
|
27
|
+
snapshot(): ToolHistory;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=tool-history.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Stateful reconstruction of historical tool definitions for request projection. */
|
|
2
|
+
import { deepFreeze } from '@deepseek-ai/dsh-util-values';
|
|
3
|
+
/** Folds committed headers and developer messages independently of model capability. */
|
|
4
|
+
export class ToolHistoryProjection {
|
|
5
|
+
/** Historical declarations indexed by the header sequence referenced by additions. */
|
|
6
|
+
headers = new Map();
|
|
7
|
+
/** Definitions retained in the current declaration series, including removed tools. */
|
|
8
|
+
declared = new Map();
|
|
9
|
+
/** Active definitions from the latest request header. */
|
|
10
|
+
active = [];
|
|
11
|
+
/** Active names reconstructed from the baseline and recorded updates. */
|
|
12
|
+
available = new Set();
|
|
13
|
+
/** Header that starts the current declaration series; absent before the first header. */
|
|
14
|
+
baselineSeq;
|
|
15
|
+
/** Immutable request snapshot of the current baseline and resolved updates. */
|
|
16
|
+
history = deepFreeze({ tools: [], updates: [] });
|
|
17
|
+
/**
|
|
18
|
+
* Consume the next committed event in log order.
|
|
19
|
+
* @param event - a session event, including inherited events during restoration.
|
|
20
|
+
*/
|
|
21
|
+
apply(event) {
|
|
22
|
+
if (event.type === 'request/header') {
|
|
23
|
+
const tools = event.data.header.tools ?? [];
|
|
24
|
+
this.headers.set(event.seq, tools);
|
|
25
|
+
// A retained name cannot acquire a different definition without losing
|
|
26
|
+
// prefix reuse; an unchanged restored name is re-offered by its recorded addition.
|
|
27
|
+
const redeclared = tools.some((tool) => {
|
|
28
|
+
const before = this.declared.get(tool.name);
|
|
29
|
+
return before !== undefined && JSON.stringify(before) !== JSON.stringify(tool);
|
|
30
|
+
});
|
|
31
|
+
if (this.baselineSeq === undefined || event.data.reason === 'series' || event.data.startsSeries || redeclared) {
|
|
32
|
+
this.baselineSeq = event.seq;
|
|
33
|
+
this.declared = new Map(tools.map(tool => [tool.name, tool]));
|
|
34
|
+
this.history = deepFreeze({ tools, updates: [] });
|
|
35
|
+
this.available = new Set(tools.map(tool => tool.name));
|
|
36
|
+
}
|
|
37
|
+
this.active = tools;
|
|
38
|
+
}
|
|
39
|
+
else if (event.type === 'developer/message') {
|
|
40
|
+
const { message, headerSeq } = event.data;
|
|
41
|
+
const definitions = headerSeq === undefined ? [] : this.headers.get(headerSeq);
|
|
42
|
+
const additions = message.content.flatMap((block) => {
|
|
43
|
+
if (block.type !== 'tool-addition')
|
|
44
|
+
return [];
|
|
45
|
+
const tool = definitions?.find(tool => tool.name === block.toolName);
|
|
46
|
+
if (tool === undefined)
|
|
47
|
+
throw new Error(`tool history: missing definition for ${block.toolName}`);
|
|
48
|
+
return [tool];
|
|
49
|
+
});
|
|
50
|
+
for (const tool of additions)
|
|
51
|
+
this.declared.set(tool.name, tool);
|
|
52
|
+
for (const block of message.content) {
|
|
53
|
+
if (block.type === 'tool-addition')
|
|
54
|
+
this.available.add(block.toolName);
|
|
55
|
+
else if (block.type === 'tool-removal')
|
|
56
|
+
this.available.delete(block.toolName);
|
|
57
|
+
}
|
|
58
|
+
this.history = deepFreeze({
|
|
59
|
+
tools: this.history.tools,
|
|
60
|
+
updates: [...this.history.updates, { messageId: message.id, additions }],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Read an immutable snapshot; subsequent events do not mutate it.
|
|
66
|
+
* @returns initial declarations and historically resolved additions for the current series.
|
|
67
|
+
*/
|
|
68
|
+
snapshot() {
|
|
69
|
+
// Sessions written before tool-update emission have headers without matching updates.
|
|
70
|
+
if (this.active.length !== this.available.size || this.active.some(tool => !this.available.has(tool.name))) {
|
|
71
|
+
return deepFreeze({ tools: this.active, updates: [] });
|
|
72
|
+
}
|
|
73
|
+
return this.history;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=tool-history.js.map
|
package/lib/types/types.d.ts
CHANGED
|
@@ -241,9 +241,9 @@ export interface RequestContext {
|
|
|
241
241
|
* Why a `request/header` snapshot was appended: `'initial'` — the log's first
|
|
242
242
|
* header (a new conversation); `'resume'` — a loop instance's first request
|
|
243
243
|
* over a log that already has header events (process restart, fork seed);
|
|
244
|
-
* `'change'` — a later request used a different header
|
|
245
|
-
*
|
|
246
|
-
*
|
|
244
|
+
* `'change'` — a later request used a different header; `'series'` — an unchanged
|
|
245
|
+
* header began an explicitly distinct message series or followed a surface
|
|
246
|
+
* replacement. Other reasons carry `startsSeries` when a new series coincides.
|
|
247
247
|
*/
|
|
248
248
|
export type RequestHeaderReason = 'initial' | 'resume' | 'change' | 'series';
|
|
249
249
|
/**
|
|
@@ -393,7 +393,7 @@ export interface SessionEventMap {
|
|
|
393
393
|
'request/header': {
|
|
394
394
|
header: EpochHeader;
|
|
395
395
|
reason: RequestHeaderReason;
|
|
396
|
-
/**
|
|
396
|
+
/** This request begins a distinct model-message series, independently of the header reason. */
|
|
397
397
|
startsSeries?: true;
|
|
398
398
|
};
|
|
399
399
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-session",
|
|
3
3
|
"description": "Event-sourced session store for the DeepSeek Harness",
|
|
4
|
-
"version": "0.1.7-
|
|
4
|
+
"version": "0.1.7-rc.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -45,19 +45,19 @@
|
|
|
45
45
|
],
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@deepseek-ai/
|
|
49
|
-
"@deepseek-ai/
|
|
48
|
+
"@deepseek-ai/dsh-scope": "0.1.7-rc.2",
|
|
49
|
+
"@deepseek-ai/cordis": "~4.0.4"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@deepseek-ai/dsh-invariants": "0.1.7-
|
|
53
|
-
"@deepseek-ai/dsh-
|
|
54
|
-
"@deepseek-ai/dsh-
|
|
55
|
-
"@deepseek-ai/dsh-typert-registry": "0.1.7-
|
|
52
|
+
"@deepseek-ai/dsh-invariants": "0.1.7-rc.2",
|
|
53
|
+
"@deepseek-ai/dsh-typert-protocol": "0.1.7-rc.2",
|
|
54
|
+
"@deepseek-ai/dsh-scope": "0.1.7-rc.2",
|
|
55
|
+
"@deepseek-ai/dsh-typert-registry": "0.1.7-rc.2",
|
|
56
56
|
"@deepseek-ai/cordis": "~4.0.4"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@deepseek-ai/dsh-llm": "0.1.7-
|
|
60
|
-
"@deepseek-ai/dsh-brand": "0.1.7-
|
|
61
|
-
"@deepseek-ai/dsh-util-values": "0.1.7-
|
|
59
|
+
"@deepseek-ai/dsh-llm": "0.1.7-rc.2",
|
|
60
|
+
"@deepseek-ai/dsh-brand": "0.1.7-rc.2",
|
|
61
|
+
"@deepseek-ai/dsh-util-values": "0.1.7-rc.2"
|
|
62
62
|
}
|
|
63
63
|
}
|