@deepseek-ai/dsh-session 0.1.3-alpha.2 → 0.1.5-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/README.i18n.yaml +2 -2
- package/README.md +13 -9
- package/README.zh.md +13 -9
- package/lib/index.js +190 -111
- package/lib/invariant.js +3 -0
- package/lib/types/index.d.ts +3 -1
- package/lib/types/index.js +36 -12
- package/lib/types/invariant.js +4 -0
- package/lib/types/known-event-types.js +5 -2
- package/lib/types/request-header.d.ts +4 -4
- package/lib/types/request-header.js +5 -7
- package/lib/types/surface.d.ts +17 -1
- package/lib/types/surface.js +102 -18
- package/lib/types/types.d.ts +45 -40
- package/lib/types/types.js +1 -1
- package/package.json +9 -9
package/lib/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Branded, type BrandedNumber } from '@deepseek-ai/dsh-brand';
|
|
2
|
-
import type { AssistantMessage, AssistantStreamRecord, ToolCallId, LlmCallConfig, LlmCallConfigAdapterDefaults, LlmFailure, TokenUsage, ToolResultMessage, ToolSchema, UserMessage } from '@deepseek-ai/dsh-llm';
|
|
2
|
+
import type { AssistantMessage, AssistantStreamRecord, ToolCallId, LlmCallConfig, LlmCallConfigAdapterDefaults, LlmFailure, SystemMessage, SystemPromptUpdate, TokenUsage, ToolResultMessage, ToolSchema, UserMessage } from '@deepseek-ai/dsh-llm';
|
|
3
3
|
import type { JsonValue } from '@deepseek-ai/dsh-util-values';
|
|
4
4
|
/** Identifies one session in the store (and its persistence artifacts). */
|
|
5
5
|
export type SessionId = Branded<'SessionId'>;
|
|
@@ -51,7 +51,7 @@ export type OptionalSessionSeq = SessionSeq | null;
|
|
|
51
51
|
* immutable prior-generation, and current fast-path rules are recorded in
|
|
52
52
|
* `.agents/notes/implemented/architecture/2026-08-31-released-session-format-migrations.md`.
|
|
53
53
|
*/
|
|
54
|
-
export declare const SESSION_FORMAT_VERSION =
|
|
54
|
+
export declare const SESSION_FORMAT_VERSION = 3;
|
|
55
55
|
/**
|
|
56
56
|
* Immutable validated storage metadata, kept outside the conversation event log.
|
|
57
57
|
*/
|
|
@@ -102,7 +102,7 @@ export interface CreateSessionOptions {
|
|
|
102
102
|
/** Initial replay or fork history supplied at construction. */
|
|
103
103
|
readonly seed?: readonly SessionEvent[];
|
|
104
104
|
/**
|
|
105
|
-
* Exact fork-inherited prefix length when `meta.isSeeded` is true.
|
|
105
|
+
* Exact fork-inherited prefix length when `meta.isSeeded` is true. The
|
|
106
106
|
* constructor seed is exactly this inherited prefix; the constructor
|
|
107
107
|
* appends the child-owned tagged marker at the cut.
|
|
108
108
|
*/
|
|
@@ -200,8 +200,9 @@ export interface TurnEndReasonMap {
|
|
|
200
200
|
/** The union over {@link TurnEndReasonMap} — why a turn ended; plugins extend it by merging variants into the map. */
|
|
201
201
|
export type TurnEndReason = TurnEndReasonMap[keyof TurnEndReasonMap];
|
|
202
202
|
/**
|
|
203
|
-
* Logged request state outside derived history: call config
|
|
204
|
-
*
|
|
203
|
+
* Logged request state outside derived history: call config and tools. The
|
|
204
|
+
* system prompt is derived history — surface node 0, a `system/message` event.
|
|
205
|
+
* The latest full `request/header` snapshot reconstructs the header; canonical
|
|
205
206
|
* empty optional fields are absent.
|
|
206
207
|
*/
|
|
207
208
|
export interface EpochHeader {
|
|
@@ -209,8 +210,6 @@ export interface EpochHeader {
|
|
|
209
210
|
config: LlmCallConfig;
|
|
210
211
|
/** Effective config fields materialized from the exact adapter rather than proposed by a caller. */
|
|
211
212
|
adapterDefaults?: LlmCallConfigAdapterDefaults;
|
|
212
|
-
/** Rendered system prompt text; absent for a system-less request. */
|
|
213
|
-
system?: string;
|
|
214
213
|
/** Assembled tool schemas; absent for a tool-less request. */
|
|
215
214
|
tools?: ToolSchema[];
|
|
216
215
|
}
|
|
@@ -222,6 +221,8 @@ export interface RequestContext {
|
|
|
222
221
|
model: string;
|
|
223
222
|
/** Maximum combined request and response context in tokens, when advertised. */
|
|
224
223
|
contextWindow?: number;
|
|
224
|
+
/** `'in-history'` when the route reads the latest `system` message at any position as the effective system prompt. */
|
|
225
|
+
systemPromptUpdate?: SystemPromptUpdate;
|
|
225
226
|
}
|
|
226
227
|
/**
|
|
227
228
|
* Why a `request/header` snapshot was appended: `'initial'` — the log's first
|
|
@@ -278,6 +279,23 @@ export interface SessionEventMap {
|
|
|
278
279
|
* project their `content` verbatim; `source` tells them apart.
|
|
279
280
|
*/
|
|
280
281
|
'user/message': UserMessage;
|
|
282
|
+
/**
|
|
283
|
+
* The rendered system prompt on the model-visible surface. The loop appends
|
|
284
|
+
* the first one as surface node 0 before the step's first `user/message`.
|
|
285
|
+
* A prepared in-history route can append nonempty changes in a continuing
|
|
286
|
+
* series. An incapable route or new series normalizes text to the first system
|
|
287
|
+
* node. Normalization empties nonempty later nodes, then rewrites the head if
|
|
288
|
+
* needed, through logged per-node replacements. An empty rendering always
|
|
289
|
+
* clears all active system nodes, leaving no older instructions model-visible.
|
|
290
|
+
* Empty later nodes are dormant and project to no message; an empty head with
|
|
291
|
+
* no active later node records "no system prompt". Restored nonempty text follows
|
|
292
|
+
* the same route and series rule; empty nodes never restore older text.
|
|
293
|
+
*/
|
|
294
|
+
'system/message': {
|
|
295
|
+
turn: number;
|
|
296
|
+
step: number;
|
|
297
|
+
message: SystemMessage;
|
|
298
|
+
};
|
|
281
299
|
/**
|
|
282
300
|
* Assembled assistant message for one step (derived history uses this).
|
|
283
301
|
* Carries the step's `usage` when the adapter reported token accounting, so
|
|
@@ -334,6 +352,7 @@ export interface SessionEventMap {
|
|
|
334
352
|
turn: number;
|
|
335
353
|
step: number;
|
|
336
354
|
message: ToolResultMessage;
|
|
355
|
+
/** Optional failure identity; allowed only when the tool-result block has `isError: true`. */
|
|
337
356
|
error?: {
|
|
338
357
|
name: string;
|
|
339
358
|
code: string;
|
|
@@ -351,8 +370,10 @@ export interface SessionEventMap {
|
|
|
351
370
|
startsSeries?: true;
|
|
352
371
|
};
|
|
353
372
|
/**
|
|
354
|
-
* Route metadata for the next request, logged only when the route
|
|
355
|
-
* changes. It does not participate in request
|
|
373
|
+
* Route metadata for the next request, logged only when the route, capacity,
|
|
374
|
+
* or system prompt update mode changes. It does not participate in request
|
|
375
|
+
* reconstruction or header equality. Prompt admission uses the bound prepared
|
|
376
|
+
* call's capability, not this snapshot from an earlier request.
|
|
356
377
|
*/
|
|
357
378
|
'request/context': RequestContext;
|
|
358
379
|
/**
|
|
@@ -386,39 +407,29 @@ export type SessionEventType = keyof SessionEventMap;
|
|
|
386
407
|
/**
|
|
387
408
|
* The subset of {@link SessionEventType} values whose events produce LLM
|
|
388
409
|
* messages and are eligible to appear on the ordered surface. Only these
|
|
389
|
-
* event types may carry {@link SurfaceOp}; user and tool events may also cite
|
|
410
|
+
* event types may carry {@link SurfaceOp}; system, user, and tool events may also cite
|
|
390
411
|
* earlier sources through {@link SessionEvent.sourceEventSeqs}.
|
|
391
412
|
*/
|
|
392
|
-
export type SurfaceEventType = 'user/message' | 'assistant/message' | 'tool/result';
|
|
393
|
-
/**
|
|
394
|
-
|
|
395
|
-
* `surfaceOp` is guaranteed present (mandatory), narrowed from a
|
|
396
|
-
* surface-eligible {@link SessionEvent} by checking both `type` and
|
|
397
|
-
* `surfaceOp` at runtime.
|
|
398
|
-
*
|
|
399
|
-
* Use the `isSurfaceEvent` type guard (in `surface.ts`) to narrow a
|
|
400
|
-
* `SessionEvent` to this type.
|
|
401
|
-
*/
|
|
402
|
-
export type SurfaceEvent = SessionEvent<SurfaceEventType> & {
|
|
403
|
-
surfaceOp: SurfaceOp;
|
|
404
|
-
};
|
|
413
|
+
export type SurfaceEventType = 'system/message' | 'user/message' | 'assistant/message' | 'tool/result';
|
|
414
|
+
/** A message-producing event carrying its required surface operation. */
|
|
415
|
+
export type SurfaceEvent = SessionEvent<SurfaceEventType>;
|
|
405
416
|
/**
|
|
406
417
|
* How a session event entered the ordered surface. Only valid on
|
|
407
418
|
* {@link SurfaceEventType} events.
|
|
408
419
|
*
|
|
409
420
|
* - `'append'`: added to the tail — normal path for user/assistant/tool
|
|
410
421
|
* messages.
|
|
411
|
-
* - `{ op: 'replace',
|
|
412
|
-
* (inclusive) through `
|
|
413
|
-
* surface nodes in the current surface. `
|
|
422
|
+
* - `{ op: 'replace', startSeq, endSeq }`: replaces surface nodes from `startSeq`
|
|
423
|
+
* (inclusive) through `endSeq` (inclusive) with this node. Both must exist as
|
|
424
|
+
* surface nodes in the current surface. `startSeq === endSeq` replaces a single
|
|
414
425
|
* node. The node's {@link SessionEvent.sourceEventSeqs} must include every
|
|
415
426
|
* shadowed surface node. Used by compaction; any surface-replacing producer
|
|
416
427
|
* may use it.
|
|
417
428
|
*/
|
|
418
429
|
export type SurfaceOp = 'append' | {
|
|
419
430
|
op: 'replace';
|
|
420
|
-
|
|
421
|
-
|
|
431
|
+
startSeq: SessionSeq;
|
|
432
|
+
endSeq: SessionSeq;
|
|
422
433
|
};
|
|
423
434
|
/**
|
|
424
435
|
* Surface placement and cited source-event seqs for {@link Session.append}. Required on
|
|
@@ -427,7 +438,7 @@ export type SurfaceOp = 'append' | {
|
|
|
427
438
|
export type SurfaceIntent<T extends SurfaceEventType = SurfaceEventType> = {
|
|
428
439
|
surfaceOp: SurfaceOp;
|
|
429
440
|
} & (T extends 'assistant/message' ? {
|
|
430
|
-
/**
|
|
441
|
+
/** Assistant messages embed their provider stream instead of citing source events. */
|
|
431
442
|
sourceEventSeqs?: never;
|
|
432
443
|
} : {
|
|
433
444
|
/** Complete non-empty set of known earlier source-event seqs. */
|
|
@@ -440,7 +451,7 @@ export type SurfaceIntent<T extends SurfaceEventType = SurfaceEventType> = {
|
|
|
440
451
|
* unions), so `switch (event.type)` narrows `event.data` without casts.
|
|
441
452
|
*
|
|
442
453
|
* The {@link sourceEventSeqs} and {@link surfaceOp} fields are conditional:
|
|
443
|
-
* they only exist on {@link SurfaceEventType} variants (`user/message`,
|
|
454
|
+
* they only exist on {@link SurfaceEventType} variants (`system/message`, `user/message`,
|
|
444
455
|
* `assistant/message`, `tool/result`).
|
|
445
456
|
* Non-surface events (boundary markers, attempts, errors) never carry
|
|
446
457
|
* surface metadata — the compiler enforces this at `Session.append()`
|
|
@@ -465,16 +476,10 @@ export type SessionEvent<T extends SessionEventType = SessionEventType> = {
|
|
|
465
476
|
* inconvenience) rather than silently resuming a gutted session.
|
|
466
477
|
*/
|
|
467
478
|
ignorable?: true;
|
|
468
|
-
} & (K extends SurfaceEventType ? {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
* `assistant/message` embeds its provider stream and cannot carry this field.
|
|
473
|
-
*/
|
|
474
|
-
sourceEventSeqs?: SessionSeq[];
|
|
475
|
-
/** How this event entered the surface; absent for non-surface events. */
|
|
476
|
-
surfaceOp?: SurfaceOp;
|
|
477
|
-
} : object);
|
|
479
|
+
} & (K extends SurfaceEventType ? SurfaceIntent<K> : {
|
|
480
|
+
surfaceOp?: never;
|
|
481
|
+
sourceEventSeqs?: never;
|
|
482
|
+
});
|
|
478
483
|
}[T];
|
|
479
484
|
declare module '@deepseek-ai/dsh-typert-protocol' {
|
|
480
485
|
interface RemoteErrorDetailsMap {
|
package/lib/types/types.js
CHANGED
|
@@ -51,5 +51,5 @@ export function SessionLogOffset(value) {
|
|
|
51
51
|
* immutable prior-generation, and current fast-path rules are recorded in
|
|
52
52
|
* `.agents/notes/implemented/architecture/2026-08-31-released-session-format-migrations.md`.
|
|
53
53
|
*/
|
|
54
|
-
export const SESSION_FORMAT_VERSION =
|
|
54
|
+
export const SESSION_FORMAT_VERSION = 3;
|
|
55
55
|
//# sourceMappingURL=types.js.map
|
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.
|
|
4
|
+
"version": "0.1.5-alpha.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -41,19 +41,19 @@
|
|
|
41
41
|
],
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@deepseek-ai/dsh-scope": "^0.1.
|
|
44
|
+
"@deepseek-ai/dsh-scope": "^0.1.5-alpha.2",
|
|
45
45
|
"@deepseek-ai/cordis": "^4.0.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@deepseek-ai/dsh-
|
|
49
|
-
"@deepseek-ai/dsh-
|
|
50
|
-
"@deepseek-ai/dsh-
|
|
51
|
-
"@deepseek-ai/dsh-typert-
|
|
48
|
+
"@deepseek-ai/dsh-invariants": "^0.1.5-alpha.2",
|
|
49
|
+
"@deepseek-ai/dsh-scope": "^0.1.5-alpha.2",
|
|
50
|
+
"@deepseek-ai/dsh-typert-registry": "^0.1.5-alpha.2",
|
|
51
|
+
"@deepseek-ai/dsh-typert-protocol": "^0.1.5-alpha.2",
|
|
52
52
|
"@deepseek-ai/cordis": "^4.0.2"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@deepseek-ai/dsh-llm": "^0.1.
|
|
56
|
-
"@deepseek-ai/dsh-brand": "^0.1.
|
|
57
|
-
"@deepseek-ai/dsh-util-values": "^0.1.
|
|
55
|
+
"@deepseek-ai/dsh-llm": "^0.1.5-alpha.2",
|
|
56
|
+
"@deepseek-ai/dsh-brand": "^0.1.5-alpha.2",
|
|
57
|
+
"@deepseek-ai/dsh-util-values": "^0.1.5-alpha.2"
|
|
58
58
|
}
|
|
59
59
|
}
|