@deepseek-ai/dsh-session-log-deepseek 0.1.2-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ # Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
2
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
+ # after editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write packages/session/session-log-deepseek/README.md
5
+ README.md: e76a4ba7d48deafb13f5dfcc1e7ea6532a4452d7
6
+ README.zh.md: f2bf91418430fee960350fa0feb6053704dad543
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ ---
2
+ description: "Incremental canonical session-log upload for deployments enabling official DeepSeek request metadata."
3
+ kind: "package-reference"
4
+ ---
5
+
6
+ # @deepseek-ai/dsh-session-log-deepseek
7
+
8
+ English | [中文](README.zh.md)
9
+
10
+ ## Summary
11
+
12
+ Incremental canonical session-log upload for official DeepSeek LLM API requests. This function plugin injects `ctx.sessions` and `ctx.deepseekLlmApiExtensions`, then owns the `dsh_session_log` request field and the durable `session-log-deepseek/delivery-accepted` event from which it derives the acceptance watermark. Enable it only when the official API should receive a Session-log suffix.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Configuration](#configuration)
17
+ - [Request field](#request-field)
18
+ - [Acceptance and retry](#acceptance-and-retry)
19
+ - [Model Experience](#model-experience)
20
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
21
+ - [Dev Note](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="configuration"></a>
26
+ ## Configuration
27
+
28
+ | Key | Default | Meaning |
29
+ |---|---:|---|
30
+ | `enabled` | `false` | Register the `dsh_session_log` contribution. Set it to `true` to opt into Session-log upload. |
31
+
32
+ Shipped profiles mount the plugin so an overlay can enable it, but the default configuration registers no request field and appends no acceptance watermark.
33
+
34
+ <a id="request-field"></a>
35
+ ## Request field
36
+
37
+ For a request carrying a live `sessionId`, the plugin folds the greatest accepted watermark for that exact Session identity, snapshots `Session.events`, and sends the contiguous suffix after the watermark. A process-local fold scans each event once and consumes later appends incrementally; restart and HMR rebuild it from the durable log. The version-1 field contains the immutable `SessionHeader`, `afterSeq`, `throughSeq`, and every complete canonical `SessionEvent` in that range as a direct array element. Forked sessions ignore inherited parent watermarks because each watermark records the Session id sent on the accepted request.
38
+
39
+ <a id="acceptance-and-retry"></a>
40
+ ## Acceptance and retry
41
+
42
+ The DeepSeek adapter calls the prepared contribution's `accept()` after HTTP 2xx, before it consumes the SSE body. Acceptance appends `session-log-deepseek/delivery-accepted` with the uploaded `throughSeq`; the next request uploads that event as part of its new suffix. Transport and non-2xx failures append no acceptance record, so later requests resend the uncertain range. Concurrent deliveries may be accepted out of order; folding the maximum matching `throughSeq` prevents cursor regression.
43
+
44
+ A crash after server acceptance but before the watermark reaches persistence can replay an accepted range after restart. This is the at-least-once failure direction: uncertainty creates duplicates, never a skipped sequence. The ordinary session checkpoint policy persists the watermark at the next semantic checkpoint; this plugin performs no independent I/O.
45
+
46
+ Direct requests without a live Session omit `dsh_session_log`. Normal agent, compaction, and session-title calls carry their live Session id.
47
+
48
+ <a id="model-experience"></a>
49
+ ## Model Experience
50
+
51
+ ### Session-log metadata
52
+
53
+ #### What the model sees
54
+
55
+ Nothing. `dsh_session_log` is a sibling of the DeepSeek request's model-input fields and is not inserted into `messages`, the system prompt, or tool schemas.
56
+
57
+ #### Token effect
58
+
59
+ Zero model-input tokens; the field only increases HTTP request bytes.
60
+
61
+ #### KV Cache effect
62
+
63
+ None; the model-visible request prefix remains unchanged.
64
+
65
+ ## Known Limitations and Deferred Work
66
+
67
+ <a id="known-limitations-and-deferred-work"></a>
68
+
69
+ - **Crash-window duplicates** — a 2xx followed by process loss before the acceptance watermark persists causes conservative replay on resume.
70
+ - **No live Session means no field** — direct or stale-session calls have no canonical log to snapshot; explicit absence semantics remain deferred.
71
+ - **No independent request-size cap** — complete delivery is fail-closed; provider rejection leaves the cursor unchanged instead of truncating the log.
72
+
73
+
74
+ <a id="dev-note"></a>
75
+ ### Dev Note
76
+
77
+ <details>
78
+ <summary>Working context for maintainers — click to expand</summary>
79
+
80
+ None.
81
+
82
+ </details>
package/README.zh.md ADDED
@@ -0,0 +1,82 @@
1
+ ---
2
+ description: "面向启用官方 DeepSeek 请求元数据的部署,说明规范会话日志的增量上传。"
3
+ kind: "package-reference"
4
+ ---
5
+
6
+ # @deepseek-ai/dsh-session-log-deepseek
7
+
8
+ [English](README.md) | 中文
9
+
10
+ ## 概述
11
+
12
+ 用于 DeepSeek 官方 LLM API 请求的增量权威会话日志上传。该函数插件注入 `ctx.sessions` 与 `ctx.deepseekLlmApiExtensions`,并拥有 `dsh_session_log` 请求字段以及用于派生接受水位的持久 `session-log-deepseek/delivery-accepted` 事件。仅当官方 API 需要接收 Session 日志后缀时才启用它。
13
+
14
+ ## 目录
15
+
16
+ - [配置](#configuration)
17
+ - [请求字段](#request-field)
18
+ - [接受与重试](#acceptance-and-retry)
19
+ - [模型体验](#model-experience)
20
+ - [已知限制与暂缓事项](#known-limitations-and-deferred-work)
21
+ - [开发备注](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="configuration"></a>
26
+ ## 配置
27
+
28
+ | 配置键 | 默认值 | 含义 |
29
+ |---|---:|---|
30
+ | `enabled` | `false` | 注册 `dsh_session_log` 贡献。将其设为 `true` 可选择启用会话日志上传。 |
31
+
32
+ 随附 profile 会挂载该插件,让 overlay 可以启用它;默认配置不会注册请求字段,也不会追加接受水位。
33
+
34
+ <a id="request-field"></a>
35
+ ## 请求字段
36
+
37
+ 对于携带存活 `sessionId` 的请求,插件会折叠该确切会话身份的最大已接受水位,对 `Session.events` 取快照,并发送水位之后的连续后缀。进程内 fold 会让每条事件只被扫描一次并增量消费后续追加;重启与 HMR 会从持久日志重建它。版本 1 字段包含不可变的 `SessionHeader`、`afterSeq`、`throughSeq`,以及作为数组直接元素的该范围内每个完整权威 `SessionEvent`。每个水位都会记录已接受请求发送的会话 id,因此 fork 会话会忽略从父会话继承的水位。
38
+
39
+ <a id="acceptance-and-retry"></a>
40
+ ## 接受与重试
41
+
42
+ DeepSeek 适配器会在 HTTP 2xx 后、消费 SSE(Server-Sent Events)正文前调用已准备贡献的 `accept()`。接受操作会追加 `session-log-deepseek/delivery-accepted` 及已上传的 `throughSeq`;下一次请求再把该事件作为新后缀的一部分上传。传输失败与非 2xx 失败不会追加接受记录,因此后续请求会重发不确定范围。并发交付可能乱序得到接受;折叠匹配记录中最大的 `throughSeq` 可以防止游标回退。
43
+
44
+ 服务端接受后、持久化水位前发生崩溃,可能让恢复后的进程重放已经接受的范围。这是至少一次交付的失败方向:不确定性会制造重复,绝不会跳过序列。普通会话检查点策略会在下一个语义检查点持久化水位;本插件不执行独立 I/O。
45
+
46
+ 缺少存活会话的直接请求会省略 `dsh_session_log`。普通 agent(智能体)、压缩(compaction)与会话标题调用都会携带存活会话 id。
47
+
48
+ <a id="model-experience"></a>
49
+ ## 模型体验
50
+
51
+ ### 会话日志元数据
52
+
53
+ #### 模型看到的内容
54
+
55
+ 无。`dsh_session_log` 是 DeepSeek 请求中模型输入字段的同级字段,不会插入 `messages`、系统提示词或工具 schema。
56
+
57
+ #### Token 影响
58
+
59
+ 模型输入 token 为零;该字段只会增加 HTTP 请求字节数。
60
+
61
+ #### KV Cache 影响
62
+
63
+ 无;模型可见请求前缀保持不变。
64
+
65
+ ## 已知限制与暂缓事项
66
+
67
+ <a id="known-limitations-and-deferred-work"></a>
68
+
69
+ - **崩溃窗口重复**——2xx 后、接受水位持久化前进程丢失,会在恢复时触发保守重放。
70
+ - **缺少存活会话就没有字段**——直接调用或陈旧会话调用没有可供快照的权威日志;显式缺失语义仍暂缓处理。
71
+ - **没有独立请求大小上限**——完整交付会快速失败;提供方拒绝会保持游标不变,而非截断日志。
72
+
73
+
74
+ <a id="dev-note"></a>
75
+ ### 开发备注
76
+
77
+ <details>
78
+ <summary>维护者工作上下文——点击展开</summary>
79
+
80
+ 无。
81
+
82
+ </details>
package/lib/index.js ADDED
@@ -0,0 +1,74 @@
1
+ import z from "@deepseek-ai/schemastery";
2
+ import { brandString } from "@deepseek-ai/dsh-brand";
3
+ //#region lib/types/index.js
4
+ /**
5
+ * Incremental session-log contribution for official DeepSeek LLM API requests.
6
+ * Accepted sequence watermarks live in the canonical log, so restart recovery
7
+ * can conservatively resend uncertain tails without maintaining another store.
8
+ * @module @deepseek-ai/dsh-session-log-deepseek
9
+ */
10
+ /** Cordis plugin name. */
11
+ const name = "session-log-deepseek";
12
+ /** Services required to resolve sessions and contribute the provider request field. */
13
+ const inject = ["deepseekLlmApiExtensions", "sessions"];
14
+ /** Validated Session-log request contribution configuration. */
15
+ const Config = z.object({ enabled: z.boolean().default(false) });
16
+ const acceptanceFolds = /* @__PURE__ */ new WeakMap();
17
+ /**
18
+ * Highest confirmed sequence for this exact session identity.
19
+ * @param session - canonical log whose matching acceptance events are folded.
20
+ * @returns greatest accepted sequence, or `-1` before any accepted request.
21
+ */
22
+ function acceptedThrough(session) {
23
+ const previous = acceptanceFolds.get(session);
24
+ let throughSeq = previous?.throughSeq ?? -1;
25
+ const events = session.events;
26
+ const start = previous?.scannedEvents ?? 0;
27
+ for (let index = start; index < events.length; index++) {
28
+ const event = events[index];
29
+ if (event.type !== "session-log-deepseek/delivery-accepted") continue;
30
+ if (typeof event.data.sessionId !== "string" || event.data.sessionId.length === 0 || !Number.isSafeInteger(event.data.throughSeq) || event.data.throughSeq < 0 || event.data.throughSeq >= event.seq) throw new Error(`session-log-deepseek: malformed acceptance watermark at seq ${event.seq}`);
31
+ if (event.data.sessionId !== session.id) continue;
32
+ throughSeq = Math.max(throughSeq, event.data.throughSeq);
33
+ }
34
+ acceptanceFolds.set(session, {
35
+ scannedEvents: events.length,
36
+ throughSeq
37
+ });
38
+ return throughSeq;
39
+ }
40
+ /**
41
+ * Register the incremental `dsh_session_log` request contribution when enabled.
42
+ * @param ctx - plugin context carrying Sessions and the DeepSeek request-extension registry.
43
+ * @param config - validated opt-in configuration.
44
+ */
45
+ function apply(ctx, config) {
46
+ if (config.enabled !== true) return;
47
+ ctx.deepseekLlmApiExtensions.register("dsh_session_log", { prepare: (request) => {
48
+ if (request.sessionId === void 0) return void 0;
49
+ const session = ctx.sessions.get(brandString(request.sessionId));
50
+ if (session === void 0) return void 0;
51
+ const afterSeq = acceptedThrough(session);
52
+ const snapshot = session.events;
53
+ const throughSeq = snapshot.length - 1;
54
+ if (throughSeq < 0) return void 0;
55
+ const suffix = snapshot.slice(afterSeq + 1);
56
+ return {
57
+ value: {
58
+ version: 1,
59
+ session: session.header,
60
+ afterSeq,
61
+ throughSeq,
62
+ events: suffix
63
+ },
64
+ accept: () => {
65
+ session.append("session-log-deepseek/delivery-accepted", {
66
+ sessionId: session.id,
67
+ throughSeq
68
+ });
69
+ }
70
+ };
71
+ } });
72
+ }
73
+ //#endregion
74
+ export { Config, acceptedThrough, apply, inject, name };
@@ -0,0 +1,42 @@
1
+ //#region lib/types/invariant.js
2
+ /** Package-owned invariants for DeepSeek session-log acceptance watermarks. */
3
+ const PACKAGE_NAME = "@deepseek-ai/dsh-session-log-deepseek";
4
+ /** Cordis companion plugin name. */
5
+ const name = "session-log-deepseek-invariant";
6
+ /** Service required before the companion can reserve package ownership. */
7
+ const inject = ["invariants"];
8
+ /** Validate one acceptance watermark against its containing event and session. */
9
+ function validateDeliveryAccepted(session, event, fail) {
10
+ const { sessionId, throughSeq } = event.data;
11
+ const inherited = session.header.parentSession !== void 0 && session.header.seedLength !== void 0 && event.seq < session.header.seedLength;
12
+ if (sessionId !== session.id && !inherited) fail("a non-inherited session-log-deepseek/delivery-accepted event must name its containing session");
13
+ if (!Number.isSafeInteger(throughSeq) || throughSeq < 0 || throughSeq >= event.seq) fail(`session-log-deepseek/delivery-accepted throughSeq must identify an earlier event, got ${throughSeq} at seq ${event.seq}`);
14
+ }
15
+ /** Validate acceptance watermarks already present in one Session. */
16
+ function validateSession(session, fail) {
17
+ for (const event of session.events) if (event.type === "session-log-deepseek/delivery-accepted") validateDeliveryAccepted(session, event, fail);
18
+ }
19
+ /** Validate one live session-event dispatch. */
20
+ function validateDispatched(args, fail) {
21
+ const [session, event] = args;
22
+ if (event.type === "session-log-deepseek/delivery-accepted") validateDeliveryAccepted(session, event, fail);
23
+ }
24
+ /** Install validation for restored, newly created, and newly appended watermarks. */
25
+ const install = Object.assign((ctx, fail) => {
26
+ const validateExisting = (session) => {
27
+ validateSession(session, fail);
28
+ };
29
+ ctx.sessions.list().forEach(validateExisting);
30
+ ctx.on("session/created", validateExisting, { global: true });
31
+ ctx.on("internal/dispatch", (_mode, eventName, args) => {
32
+ if (eventName === "session/event") validateDispatched(args, fail);
33
+ }, { global: true });
34
+ }, { inject: ["sessions"] });
35
+ /**
36
+ * Register this package's invariant companion.
37
+ * @param ctx - Cordis context carrying the invariant service.
38
+ * @returns the installed registration's disposer after setup succeeds.
39
+ */
40
+ const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
41
+ //#endregion
42
+ export { apply, inject, name };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Incremental session-log contribution for official DeepSeek LLM API requests.
3
+ * Accepted sequence watermarks live in the canonical log, so restart recovery
4
+ * can conservatively resend uncertain tails without maintaining another store.
5
+ * @module @deepseek-ai/dsh-session-log-deepseek
6
+ */
7
+ import type { Context } from '@deepseek-ai/cordis';
8
+ import z from '@deepseek-ai/schemastery';
9
+ import type { Session } from '@deepseek-ai/dsh-session';
10
+ export type * from './types.ts';
11
+ /** Cordis plugin name. */
12
+ export declare const name = "session-log-deepseek";
13
+ /** Services required to resolve sessions and contribute the provider request field. */
14
+ export declare const inject: string[];
15
+ /** Session-log request contribution configuration. */
16
+ export interface Config {
17
+ /** Contribute `dsh_session_log` to official DeepSeek requests. Defaults to `false`. */
18
+ enabled?: boolean;
19
+ }
20
+ /** Validated Session-log request contribution configuration. */
21
+ export declare const Config: z<Config>;
22
+ /**
23
+ * Highest confirmed sequence for this exact session identity.
24
+ * @param session - canonical log whose matching acceptance events are folded.
25
+ * @returns greatest accepted sequence, or `-1` before any accepted request.
26
+ */
27
+ export declare function acceptedThrough(session: Session): number;
28
+ /**
29
+ * Register the incremental `dsh_session_log` request contribution when enabled.
30
+ * @param ctx - plugin context carrying Sessions and the DeepSeek request-extension registry.
31
+ * @param config - validated opt-in configuration.
32
+ */
33
+ export declare function apply(ctx: Context, config: Config): void;
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Incremental session-log contribution for official DeepSeek LLM API requests.
3
+ * Accepted sequence watermarks live in the canonical log, so restart recovery
4
+ * can conservatively resend uncertain tails without maintaining another store.
5
+ * @module @deepseek-ai/dsh-session-log-deepseek
6
+ */
7
+ import z from '@deepseek-ai/schemastery';
8
+ import { brandString } from '@deepseek-ai/dsh-brand';
9
+ /** Cordis plugin name. */
10
+ export const name = 'session-log-deepseek';
11
+ /** Services required to resolve sessions and contribute the provider request field. */
12
+ export const inject = ['deepseekLlmApiExtensions', 'sessions'];
13
+ /** Validated Session-log request contribution configuration. */
14
+ export const Config = z.object({
15
+ enabled: z.boolean().default(false),
16
+ });
17
+ const acceptanceFolds = new WeakMap();
18
+ /**
19
+ * Highest confirmed sequence for this exact session identity.
20
+ * @param session - canonical log whose matching acceptance events are folded.
21
+ * @returns greatest accepted sequence, or `-1` before any accepted request.
22
+ */
23
+ export function acceptedThrough(session) {
24
+ const previous = acceptanceFolds.get(session);
25
+ let throughSeq = previous?.throughSeq ?? -1;
26
+ const events = session.events;
27
+ const start = previous?.scannedEvents ?? 0;
28
+ for (let index = start; index < events.length; index++) {
29
+ const event = events[index];
30
+ if (event.type !== 'session-log-deepseek/delivery-accepted')
31
+ continue;
32
+ if (typeof event.data.sessionId !== 'string' || event.data.sessionId.length === 0
33
+ || !Number.isSafeInteger(event.data.throughSeq) || event.data.throughSeq < 0
34
+ || event.data.throughSeq >= event.seq) {
35
+ throw new Error(`session-log-deepseek: malformed acceptance watermark at seq ${event.seq}`);
36
+ }
37
+ if (event.data.sessionId !== session.id)
38
+ continue;
39
+ throughSeq = Math.max(throughSeq, event.data.throughSeq);
40
+ }
41
+ acceptanceFolds.set(session, { scannedEvents: events.length, throughSeq });
42
+ return throughSeq;
43
+ }
44
+ /**
45
+ * Register the incremental `dsh_session_log` request contribution when enabled.
46
+ * @param ctx - plugin context carrying Sessions and the DeepSeek request-extension registry.
47
+ * @param config - validated opt-in configuration.
48
+ */
49
+ export function apply(ctx, config) {
50
+ if (config.enabled !== true)
51
+ return;
52
+ ctx.deepseekLlmApiExtensions.register('dsh_session_log', {
53
+ prepare: (request) => {
54
+ // TODO: Define an explicit wire result for direct or stale-session calls if they become a supported product path.
55
+ if (request.sessionId === undefined)
56
+ return undefined;
57
+ const session = ctx.sessions.get(brandString(request.sessionId));
58
+ if (session === undefined)
59
+ return undefined;
60
+ const afterSeq = acceptedThrough(session);
61
+ const snapshot = session.events;
62
+ const throughSeq = snapshot.length - 1;
63
+ if (throughSeq < 0)
64
+ return undefined;
65
+ const suffix = snapshot.slice(afterSeq + 1);
66
+ const value = {
67
+ version: 1,
68
+ session: session.header,
69
+ afterSeq,
70
+ throughSeq,
71
+ events: suffix,
72
+ };
73
+ return {
74
+ value,
75
+ accept: () => {
76
+ session.append('session-log-deepseek/delivery-accepted', { sessionId: session.id, throughSeq });
77
+ // TODO: Add an immediate lightweight checkpoint if duplicate replay after a 2xx crash window becomes unacceptable.
78
+ },
79
+ };
80
+ },
81
+ });
82
+ }
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,13 @@
1
+ /** Package-owned invariants for DeepSeek session-log acceptance watermarks. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ /** Cordis companion plugin name. */
4
+ export declare const name = "session-log-deepseek-invariant";
5
+ /** Service required before the companion can reserve package ownership. */
6
+ export declare const inject: string[];
7
+ /**
8
+ * Register this package's invariant companion.
9
+ * @param ctx - Cordis context carrying the invariant service.
10
+ * @returns the installed registration's disposer after setup succeeds.
11
+ */
12
+ export declare const apply: (ctx: Context) => Promise<() => void>;
13
+ //# sourceMappingURL=invariant.d.ts.map
@@ -0,0 +1,49 @@
1
+ /** Package-owned invariants for DeepSeek session-log acceptance watermarks. */
2
+ const PACKAGE_NAME = '@deepseek-ai/dsh-session-log-deepseek';
3
+ /** Cordis companion plugin name. */
4
+ export const name = 'session-log-deepseek-invariant';
5
+ /** Service required before the companion can reserve package ownership. */
6
+ export const inject = ['invariants'];
7
+ /** Validate one acceptance watermark against its containing event and session. */
8
+ function validateDeliveryAccepted(session, event, fail) {
9
+ const { sessionId, throughSeq } = event.data;
10
+ const inherited = session.header.parentSession !== undefined
11
+ && session.header.seedLength !== undefined
12
+ && event.seq < session.header.seedLength;
13
+ if (sessionId !== session.id && !inherited) {
14
+ fail('a non-inherited session-log-deepseek/delivery-accepted event must name its containing session');
15
+ }
16
+ if (!Number.isSafeInteger(throughSeq) || throughSeq < 0 || throughSeq >= event.seq) {
17
+ fail(`session-log-deepseek/delivery-accepted throughSeq must identify an earlier event, got ${throughSeq} at seq ${event.seq}`);
18
+ }
19
+ }
20
+ /** Validate acceptance watermarks already present in one Session. */
21
+ function validateSession(session, fail) {
22
+ for (const event of session.events) {
23
+ if (event.type === 'session-log-deepseek/delivery-accepted')
24
+ validateDeliveryAccepted(session, event, fail);
25
+ }
26
+ }
27
+ /** Validate one live session-event dispatch. */
28
+ function validateDispatched(args, fail) {
29
+ const [session, event] = args;
30
+ if (event.type === 'session-log-deepseek/delivery-accepted')
31
+ validateDeliveryAccepted(session, event, fail);
32
+ }
33
+ /** Install validation for restored, newly created, and newly appended watermarks. */
34
+ const install = Object.assign((ctx, fail) => {
35
+ const validateExisting = (session) => { validateSession(session, fail); };
36
+ ctx.sessions.list().forEach(validateExisting);
37
+ ctx.on('session/created', validateExisting, { global: true });
38
+ ctx.on('internal/dispatch', (_mode, eventName, args) => {
39
+ if (eventName === 'session/event')
40
+ validateDispatched(args, fail);
41
+ }, { global: true });
42
+ }, { inject: ['sessions'] });
43
+ /**
44
+ * Register this package's invariant companion.
45
+ * @param ctx - Cordis context carrying the invariant service.
46
+ * @returns the installed registration's disposer after setup succeeds.
47
+ */
48
+ export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
49
+ //# sourceMappingURL=invariant.js.map
@@ -0,0 +1,30 @@
1
+ /** Wire types for lossless incremental DeepSeek session-log upload. */
2
+ import type { SessionEvent, SessionHeader } from '@deepseek-ai/dsh-session';
3
+ /** Versioned incremental session-log field carried by an official DeepSeek request. */
4
+ export interface DeepSeekSessionLogExtension {
5
+ readonly version: 1;
6
+ readonly session: SessionHeader;
7
+ /** Highest sequence durably recorded as accepted before this request, or `-1`. */
8
+ readonly afterSeq: number;
9
+ /** Highest sequence represented by {@link events}. */
10
+ readonly throughSeq: number;
11
+ /** Complete canonical event envelopes for every sequence from `afterSeq + 1` through `throughSeq`. */
12
+ readonly events: readonly SessionEvent[];
13
+ }
14
+ declare module '@deepseek-ai/dsh-deepseek-llm-api-extensions/types' {
15
+ interface DeepSeekLlmApiExtensionMap {
16
+ dsh_session_log: DeepSeekSessionLogExtension;
17
+ }
18
+ }
19
+ declare module '@deepseek-ai/dsh-session/types' {
20
+ interface SessionEventMap {
21
+ /** Records that the configured endpoint accepted one delivery through `throughSeq`. */
22
+ 'session-log-deepseek/delivery-accepted': {
23
+ /** Session identity the accepted delivery carried; inherited fork markers retain the parent's id. */
24
+ sessionId: import('@deepseek-ai/dsh-session/types').SessionId;
25
+ /** Last canonical event included in the accepted request. */
26
+ throughSeq: number;
27
+ };
28
+ }
29
+ }
30
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,3 @@
1
+ /** Wire types for lossless incremental DeepSeek session-log upload. */
2
+ export {};
3
+ //# sourceMappingURL=types.js.map
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@deepseek-ai/dsh-session-log-deepseek",
3
+ "description": "Incremental lossless session-log request extension for the official DeepSeek LLM API",
4
+ "version": "0.1.2-alpha.2",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
11
+ "directory": "packages/session/session-log-deepseek"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./invariant": {
22
+ "types": "./lib/types/invariant.d.ts",
23
+ "default": "./lib/invariant.js"
24
+ },
25
+ "./types": {
26
+ "types": "./lib/types/types.d.ts",
27
+ "default": "./lib/types/types.js"
28
+ },
29
+ "./src/*": "./src/*",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "lib/index.js",
34
+ "lib/invariant.js",
35
+ "lib/types/**/*.js",
36
+ "lib/types/**/*.d.ts"
37
+ ],
38
+ "license": "MIT",
39
+ "dependencies": {
40
+ "@deepseek-ai/dsh-brand": "^0.1.2-alpha.2",
41
+ "@deepseek-ai/schemastery": "^3.18.2"
42
+ },
43
+ "peerDependencies": {
44
+ "@deepseek-ai/dsh-deepseek-llm-api-extensions": "^0.1.2-alpha.2",
45
+ "@deepseek-ai/cordis": "^4.0.2",
46
+ "@deepseek-ai/dsh-invariants": "^0.1.2-alpha.2",
47
+ "@deepseek-ai/dsh-session": "^0.1.2-alpha.2"
48
+ },
49
+ "devDependencies": {
50
+ "@deepseek-ai/cordis": "^4.0.2",
51
+ "@deepseek-ai/dsh-deepseek-llm-api-extensions": "^0.1.2-alpha.2",
52
+ "@deepseek-ai/dsh-invariants": "^0.1.2-alpha.2",
53
+ "@deepseek-ai/dsh-session": "^0.1.2-alpha.2"
54
+ }
55
+ }