@deepseek-ai/dsh-session-persistence-jsonl 0.2.2-alpha.3 → 0.2.2-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/lib/types/catalog-migration.d.ts.map +1 -0
- package/lib/types/catalog-migration.js.map +1 -0
- package/lib/types/format.d.ts.map +1 -0
- package/lib/types/format.js.map +1 -0
- package/lib/types/generation.d.ts.map +1 -0
- package/lib/types/generation.js.map +1 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/lease.d.ts.map +1 -0
- package/lib/types/lease.js.map +1 -0
- package/lib/types/migration-verifier.d.ts.map +1 -0
- package/lib/types/migration-verifier.js.map +1 -0
- package/lib/types/storage.d.ts.map +1 -0
- package/lib/types/storage.js.map +1 -0
- package/lib/types/testing/generation.d.ts.map +1 -0
- package/lib/types/testing/generation.js.map +1 -0
- package/lib/types/win32.d.ts.map +1 -0
- package/lib/types/win32.js.map +1 -0
- package/lib/types/worker.d.ts.map +1 -0
- package/lib/types/worker.js.map +1 -0
- package/lib/types/zstd-private-decoder.d.ts.map +1 -0
- package/lib/types/zstd-private-decoder.js.map +1 -0
- package/lib/types/zstd-public-decoder.d.ts.map +1 -0
- package/lib/types/zstd-public-decoder.js.map +1 -0
- package/lib/types/zstd.d.ts.map +1 -0
- package/lib/types/zstd.js.map +1 -0
- package/lib/worker.cjs +300 -103
- package/package.json +17 -14
- package/src/catalog-migration.ts +92 -0
- package/src/format.ts +538 -0
- package/src/generation.ts +1059 -0
- package/src/index.ts +1839 -0
- package/src/lease.ts +135 -0
- package/src/migration-verifier.ts +198 -0
- package/src/storage.ts +571 -0
- package/src/testing/generation.ts +16 -0
- package/src/win32.ts +208 -0
- package/src/worker.ts +56 -0
- package/src/zstd-private-decoder.ts +178 -0
- package/src/zstd-public-decoder.ts +40 -0
- package/src/zstd.ts +156 -0
package/lib/worker.cjs
CHANGED
|
@@ -3229,6 +3229,7 @@ const KNOWN_SESSION_EVENT_TYPES = new Set([
|
|
|
3229
3229
|
"team/member",
|
|
3230
3230
|
"team/message/delivered",
|
|
3231
3231
|
"team/message/queued",
|
|
3232
|
+
"team/mode",
|
|
3232
3233
|
"team/task",
|
|
3233
3234
|
"todo/write",
|
|
3234
3235
|
"tool-workflow/agent-end",
|
|
@@ -3395,12 +3396,12 @@ function assertSourceEventReferences(event, shadowedSeqs) {
|
|
|
3395
3396
|
if (missing.length > 0) throw new Error(`surface replace: sourceEventSeqs must include every shadowed surface node; missing ${missing.join(", ")}`);
|
|
3396
3397
|
}
|
|
3397
3398
|
/** Resolve tool additions against their immutable historical request header. */
|
|
3398
|
-
function assertDeveloperHeader(event,
|
|
3399
|
+
function assertDeveloperHeader(event, read) {
|
|
3399
3400
|
if (event.type !== "developer/message") return;
|
|
3400
3401
|
validateSessionEventData(event, `developer/message at seq ${event.seq}`);
|
|
3401
3402
|
if (event.data.headerSeq === void 0) return;
|
|
3402
3403
|
const headerSeq = event.data.headerSeq;
|
|
3403
|
-
const headerEvent =
|
|
3404
|
+
const headerEvent = read(headerSeq);
|
|
3404
3405
|
if (headerSeq >= event.seq || headerEvent?.type !== "request/header") throw new Error("developer/message headerSeq must reference an earlier request/header");
|
|
3405
3406
|
for (const block of event.data.message.content) {
|
|
3406
3407
|
if (block.type !== "tool-addition") continue;
|
|
@@ -3455,11 +3456,11 @@ function isDeepEqualJson(a, b) {
|
|
|
3455
3456
|
return aKeys.every((key) => Object.hasOwn(b, key) && isDeepEqualJson(a[key], bRecord[key]));
|
|
3456
3457
|
}
|
|
3457
3458
|
/** Restrict a tool-result replacement to one current result's content. */
|
|
3458
|
-
function assertToolResultRewrite(event, shadowedSeqs,
|
|
3459
|
+
function assertToolResultRewrite(event, shadowedSeqs, read) {
|
|
3459
3460
|
if (event.type !== "tool/result") return;
|
|
3460
3461
|
if (shadowedSeqs.length !== 1) throw new Error("tool/result surface replacement must rewrite exactly one current node");
|
|
3461
3462
|
for (const originalSeq of shadowedSeqs) {
|
|
3462
|
-
const original =
|
|
3463
|
+
const original = read(originalSeq);
|
|
3463
3464
|
if (original?.type !== "tool/result") throw new Error("tool/result surface replacement must target a current tool/result");
|
|
3464
3465
|
const originalRest = { ...original.data };
|
|
3465
3466
|
const replacementRest = { ...event.data };
|
|
@@ -3480,27 +3481,36 @@ function assertToolResultRewrite(event, shadowedSeqs, events, baseSeq) {
|
|
|
3480
3481
|
* exactly that node; later system nodes carry no protection and a compaction
|
|
3481
3482
|
* range may shadow them.
|
|
3482
3483
|
*/
|
|
3483
|
-
function assertSystemHeadRewrite(event, state, startIdx, shadowedSeqs,
|
|
3484
|
+
function assertSystemHeadRewrite(event, state, startIdx, shadowedSeqs, read) {
|
|
3484
3485
|
if (startIdx !== 0) return;
|
|
3485
|
-
if (
|
|
3486
|
+
if (read(state.nodes[0])?.type !== "system/message") return;
|
|
3486
3487
|
if (event.type !== "system/message" || shadowedSeqs.length !== 1) throw new Error("surface replace: node 0 holds the system prompt and may be rewritten only by a system/message over exactly that node");
|
|
3487
3488
|
}
|
|
3488
3489
|
/** Validate one event at its replay boundary and prepare its atomic fold transition. */
|
|
3489
|
-
function planSurfaceEvent(state, event, expectedSeq, events, baseSeq, projections) {
|
|
3490
|
+
function planSurfaceEvent(state, event, expectedSeq, events, baseSeq, projections, candidates) {
|
|
3490
3491
|
if (event.seq !== expectedSeq) throw new Error(`session event seq ${event.seq} is not contiguous; expected ${expectedSeq}`);
|
|
3491
3492
|
const surfaceOp = validateSurfaceMetadata(event);
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
kind: "project",
|
|
3496
|
-
projection,
|
|
3497
|
-
messages: projection.project(event, {
|
|
3498
|
-
nodes: state.nodes,
|
|
3499
|
-
events,
|
|
3500
|
-
baseSeq,
|
|
3501
|
-
messages: state.projectedMessages
|
|
3502
|
-
})
|
|
3493
|
+
const read = (seq) => {
|
|
3494
|
+
const index = seq - baseSeq;
|
|
3495
|
+
return index < events.length ? events[index] : candidates?.[index - events.length];
|
|
3503
3496
|
};
|
|
3497
|
+
assertDeveloperHeader(event, read);
|
|
3498
|
+
const projection = projections.find((item) => item.type === event.type);
|
|
3499
|
+
if (projection !== void 0) {
|
|
3500
|
+
let projectionEvents;
|
|
3501
|
+
return {
|
|
3502
|
+
kind: "project",
|
|
3503
|
+
projection,
|
|
3504
|
+
messages: projection.project(event, {
|
|
3505
|
+
nodes: state.nodes,
|
|
3506
|
+
get events() {
|
|
3507
|
+
return candidates === void 0 ? events : projectionEvents ??= [...events, ...candidates];
|
|
3508
|
+
},
|
|
3509
|
+
baseSeq,
|
|
3510
|
+
messages: state.projectedMessages
|
|
3511
|
+
})
|
|
3512
|
+
};
|
|
3513
|
+
}
|
|
3504
3514
|
if (MESSAGE_PROJECTION_EVENT_TYPES.has(event.type)) throw new Error(`session event "${event.type}" requires a message projection; load its owning plugin or supply its projection definition`);
|
|
3505
3515
|
if (surfaceOp === void 0) return;
|
|
3506
3516
|
if (surfaceOp === "append") return {
|
|
@@ -3509,8 +3519,8 @@ function planSurfaceEvent(state, event, expectedSeq, events, baseSeq, projection
|
|
|
3509
3519
|
};
|
|
3510
3520
|
const range = replacementRange(state, surfaceOp);
|
|
3511
3521
|
assertSourceEventReferences(event, range.shadowedSeqs);
|
|
3512
|
-
assertToolResultRewrite(event, range.shadowedSeqs,
|
|
3513
|
-
assertSystemHeadRewrite(event, state, range.startIdx, range.shadowedSeqs,
|
|
3522
|
+
assertToolResultRewrite(event, range.shadowedSeqs, read);
|
|
3523
|
+
assertSystemHeadRewrite(event, state, range.startIdx, range.shadowedSeqs, read);
|
|
3514
3524
|
return {
|
|
3515
3525
|
kind: "replace",
|
|
3516
3526
|
seq: event.seq,
|
|
@@ -3579,6 +3589,40 @@ var SurfaceManager = class {
|
|
|
3579
3589
|
plan: planSurfaceEvent(this._state, event, expectedSeq, this.log, this.baseSeq, this.projections)
|
|
3580
3590
|
};
|
|
3581
3591
|
}
|
|
3592
|
+
/**
|
|
3593
|
+
* Validate consecutive candidates against an isolated surface fold.
|
|
3594
|
+
* @param events - candidates immediately following the committed log.
|
|
3595
|
+
* @returns a callback adopting the validated fold after all candidates enter the log.
|
|
3596
|
+
*/
|
|
3597
|
+
prepareBatch(events) {
|
|
3598
|
+
this._assertProjections();
|
|
3599
|
+
if (this._lastProcessedSeq < this.baseSeq + this.log.length - 1) this._processDelta();
|
|
3600
|
+
const lastProcessedSeq = SessionSeq(this.baseSeq + this.log.length + events.length - 1);
|
|
3601
|
+
if (events.every((event) => (event.surfaceOp === void 0 || event.surfaceOp === "append") && !this.projections.some((projection) => projection.type === event.type))) {
|
|
3602
|
+
const plans = events.map((event, index) => planSurfaceEvent(this._state, event, SessionSeq(this.baseSeq + this.log.length + index), this.log, this.baseSeq, this.projections, events));
|
|
3603
|
+
return () => {
|
|
3604
|
+
for (const plan of plans) applySurfacePlan(this._state, plan);
|
|
3605
|
+
this._lastProcessedSeq = lastProcessedSeq;
|
|
3606
|
+
this._pendingPlan = void 0;
|
|
3607
|
+
};
|
|
3608
|
+
}
|
|
3609
|
+
const state = {
|
|
3610
|
+
...this._state,
|
|
3611
|
+
nodes: [...this._state.nodes],
|
|
3612
|
+
projectedMessages: new Map(this._state.projectedMessages),
|
|
3613
|
+
projections: new Set(this._state.projections)
|
|
3614
|
+
};
|
|
3615
|
+
const plans = events.map((event, index) => {
|
|
3616
|
+
const plan = planSurfaceEvent(state, event, SessionSeq(this.baseSeq + this.log.length + index), this.log, this.baseSeq, this.projections, events);
|
|
3617
|
+
applySurfacePlan(state, plan);
|
|
3618
|
+
return plan;
|
|
3619
|
+
});
|
|
3620
|
+
return () => {
|
|
3621
|
+
for (const plan of plans) applySurfacePlan(this._state, plan);
|
|
3622
|
+
this._lastProcessedSeq = lastProcessedSeq;
|
|
3623
|
+
this._pendingPlan = void 0;
|
|
3624
|
+
};
|
|
3625
|
+
}
|
|
3582
3626
|
/** Monotonic count of folded positional replacements. */
|
|
3583
3627
|
get replaceGeneration() {
|
|
3584
3628
|
this._assertProjections();
|
|
@@ -4499,11 +4543,11 @@ defineMethod("transform", [
|
|
|
4499
4543
|
/** Largest delay Node schedules without clamping it to one millisecond. */
|
|
4500
4544
|
const MAX_TIMER_DELAY_MS = 2147483647;
|
|
4501
4545
|
//#endregion
|
|
4502
|
-
//#region ../../
|
|
4546
|
+
//#region ../../util/error/src/index.ts
|
|
4503
4547
|
/**
|
|
4504
4548
|
* Harness error base with a stable machine-routable code and chained cause.
|
|
4505
4549
|
* Package errors extend it so tool results and replay can retain failure class.
|
|
4506
|
-
* @module @deepseek-ai/dsh-
|
|
4550
|
+
* @module @deepseek-ai/dsh-error
|
|
4507
4551
|
*/
|
|
4508
4552
|
/**
|
|
4509
4553
|
* Base class for all harness errors. Carries a `code` (stable, programmatic —
|
|
@@ -4520,6 +4564,75 @@ var HarnessError = class extends Error {
|
|
|
4520
4564
|
this.name = new.target.name;
|
|
4521
4565
|
}
|
|
4522
4566
|
};
|
|
4567
|
+
//#endregion
|
|
4568
|
+
//#region ../../llm/llm/src/error.ts
|
|
4569
|
+
/**
|
|
4570
|
+
* LLM failure codes and helpers over the shared Harness error base. The base
|
|
4571
|
+
* class lives in `@deepseek-ai/dsh-error` and is re-exported here, so both
|
|
4572
|
+
* import paths name the same class.
|
|
4573
|
+
* @module @deepseek-ai/dsh-llm/error
|
|
4574
|
+
*/
|
|
4575
|
+
/**
|
|
4576
|
+
* Every failure code the built-in providers and the LLM runtime raise. An entry
|
|
4577
|
+
* marked `retryChoice` is offered as a choice for a provider retry policy's
|
|
4578
|
+
* `retryableCodes`; being a choice does not make a code retried by default.
|
|
4579
|
+
*/
|
|
4580
|
+
const LLM_FAILURE_CODES = {
|
|
4581
|
+
ABORTED: {},
|
|
4582
|
+
ACCOUNT_QUOTA: {},
|
|
4583
|
+
ACCOUNT_SIGN_IN_REQUIRED: {},
|
|
4584
|
+
ACCOUNT_TOKEN_INVALID: {},
|
|
4585
|
+
AUTH: {},
|
|
4586
|
+
CLIENT_UPGRADE_REQUIRED: {},
|
|
4587
|
+
CONTEXT_WINDOW_EXCEEDED: {},
|
|
4588
|
+
DISCOVERY_FAILED: {},
|
|
4589
|
+
DISCOVERY_UNSUPPORTED: {},
|
|
4590
|
+
DUPLICATE_ADAPTER: {},
|
|
4591
|
+
DUPLICATE_DIRECTORY: {},
|
|
4592
|
+
DUPLICATE_DISCOVERY: {},
|
|
4593
|
+
EMPTY_RESPONSE: { retryChoice: true },
|
|
4594
|
+
FILES_API: {},
|
|
4595
|
+
IMAGE_OFFLOAD_REQUIRED: {},
|
|
4596
|
+
INVALID_ADAPTER: {},
|
|
4597
|
+
INVALID_CATALOG: {},
|
|
4598
|
+
INVALID_CONFIG: {},
|
|
4599
|
+
INVALID_CREDENTIAL: {},
|
|
4600
|
+
INVALID_DIRECTORY: {},
|
|
4601
|
+
INVALID_DISCOVERY: {},
|
|
4602
|
+
INVALID_MODEL_CONTEXT: {},
|
|
4603
|
+
INVALID_MODEL_INFO: {},
|
|
4604
|
+
INVALID_MODEL_MAX_TOKENS: {},
|
|
4605
|
+
INVALID_MODEL_REASONING: {},
|
|
4606
|
+
INVALID_PREPARED_CALL: {},
|
|
4607
|
+
INVALID_REPLAY_STATE: {},
|
|
4608
|
+
INVALID_REQUEST: {},
|
|
4609
|
+
INVALID_RESPONSE: {},
|
|
4610
|
+
MALFORMED_RESPONSE: { retryChoice: true },
|
|
4611
|
+
MISSING_CREDENTIAL: {},
|
|
4612
|
+
MODEL_SWITCH_COMPACTION_FAILED: {},
|
|
4613
|
+
MODEL_UNSUPPORTED: {},
|
|
4614
|
+
NO_ADAPTER: {},
|
|
4615
|
+
NO_CREDENTIAL_STORE: {},
|
|
4616
|
+
NO_DISCOVERY: {},
|
|
4617
|
+
PI_AI_ERROR: {},
|
|
4618
|
+
QUOTA: { retryChoice: true },
|
|
4619
|
+
RATE_LIMIT: { retryChoice: true },
|
|
4620
|
+
REGISTRATION_DISPOSED: {},
|
|
4621
|
+
REQUEST_EXTENSION: {},
|
|
4622
|
+
REQUEST_HEADERS: {},
|
|
4623
|
+
SERVER: { retryChoice: true },
|
|
4624
|
+
STREAM_CLOSED: { retryChoice: true },
|
|
4625
|
+
TIMEOUT: { retryChoice: true },
|
|
4626
|
+
TRANSPORT: { retryChoice: true },
|
|
4627
|
+
UNKNOWN: {},
|
|
4628
|
+
UNKNOWN_MODEL: {},
|
|
4629
|
+
UNSTORABLE_PROVIDER_ID: {},
|
|
4630
|
+
UNSUPPORTED_CONTENT: {},
|
|
4631
|
+
UNSUPPORTED_OPTION: {},
|
|
4632
|
+
UNSUPPORTED_REASONING_EFFORT: {}
|
|
4633
|
+
};
|
|
4634
|
+
/** The {@link LLM_FAILURE_CODES} entries marked as retry-policy choices, in definition order. */
|
|
4635
|
+
const RETRY_CODE_CHOICES = Object.freeze(Object.keys(LLM_FAILURE_CODES).filter((code) => "retryChoice" in LLM_FAILURE_CODES[code]));
|
|
4523
4636
|
/**
|
|
4524
4637
|
* Canonical provider-neutral code for a response that completed normally but
|
|
4525
4638
|
* carried no content blocks at all. Providers occasionally emit a degenerate
|
|
@@ -4555,14 +4668,14 @@ const DEFAULT_RETRYABLE_CODES = Object.freeze([
|
|
|
4555
4668
|
"TRANSPORT"
|
|
4556
4669
|
]);
|
|
4557
4670
|
const backoffSchema = Schema.object({
|
|
4558
|
-
initialDelayMs: Schema.number().max(MAX_TIMER_DELAY_MS).default(DEFAULT_INITIAL_DELAY_MS),
|
|
4559
|
-
maxDelayMs: Schema.number().max(MAX_TIMER_DELAY_MS).default(DEFAULT_MAX_DELAY_MS),
|
|
4671
|
+
initialDelayMs: Schema.number().min(Number.MIN_VALUE).max(MAX_TIMER_DELAY_MS).default(DEFAULT_INITIAL_DELAY_MS),
|
|
4672
|
+
maxDelayMs: Schema.number().min(Number.MIN_VALUE).max(MAX_TIMER_DELAY_MS).default(DEFAULT_MAX_DELAY_MS),
|
|
4560
4673
|
jitterRatio: Schema.number().min(0).max(1).default(DEFAULT_JITTER_RATIO)
|
|
4561
4674
|
});
|
|
4562
4675
|
const normalPolicySchema = Schema.object({
|
|
4563
4676
|
mode: Schema.const("normal").required(),
|
|
4564
4677
|
maxRetries: Schema.number().step(1).min(0).max(Number.MAX_SAFE_INTEGER).default(DEFAULT_MAX_RETRIES),
|
|
4565
|
-
retryableCodes: Schema.array(Schema.string()).default([...DEFAULT_RETRYABLE_CODES]),
|
|
4678
|
+
retryableCodes: Schema.array(Schema.union([...RETRY_CODE_CHOICES.map((code) => Schema.const(code)), Schema.string().min(1)])).min(1).default([...DEFAULT_RETRYABLE_CODES]),
|
|
4566
4679
|
backoff: backoffSchema
|
|
4567
4680
|
});
|
|
4568
4681
|
const alwaysPolicySchema = Schema.object({
|
|
@@ -4846,27 +4959,47 @@ function withoutDeveloperMessages(messages) {
|
|
|
4846
4959
|
const retained = messages.filter((message) => message.role !== "developer");
|
|
4847
4960
|
return retained.length === messages.length ? messages : retained;
|
|
4848
4961
|
}
|
|
4849
|
-
function toolDeclarations(
|
|
4962
|
+
function toolDeclarations(history) {
|
|
4850
4963
|
const declarations = new Map(history.tools.map((tool) => [tool.name, tool]));
|
|
4851
4964
|
for (const update of history.updates) for (const tool of update.additions) if (!declarations.has(tool.name)) declarations.set(tool.name, {
|
|
4852
4965
|
...tool,
|
|
4853
4966
|
deferLoading: true
|
|
4854
4967
|
});
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4968
|
+
return declarations;
|
|
4969
|
+
}
|
|
4970
|
+
/** Rebuild declarations on removals or additions to an empty set, where the request prefix changes. */
|
|
4971
|
+
function rebaseAdditionOnlyHistory(history, messages) {
|
|
4972
|
+
const available = new Map(history.tools.map((tool) => [tool.name, tool]));
|
|
4973
|
+
let baseline = history.tools;
|
|
4974
|
+
let retainedFrom = 0;
|
|
4975
|
+
for (const [index, update] of history.updates.entries()) {
|
|
4976
|
+
const additions = new Map(update.additions.map((tool) => [tool.name, tool]));
|
|
4977
|
+
let reset = available.size === 0 && additions.size > 0;
|
|
4978
|
+
for (const block of messages.get(update.messageId)) if (block.type === "tool-addition") {
|
|
4979
|
+
const { deferLoading: _loading, ...tool } = additions.get(block.toolName);
|
|
4980
|
+
available.set(tool.name, tool);
|
|
4981
|
+
} else if (block.type === "tool-removal") {
|
|
4982
|
+
reset = true;
|
|
4983
|
+
available.delete(block.toolName);
|
|
4984
|
+
}
|
|
4985
|
+
if (reset) {
|
|
4986
|
+
baseline = [...available.values()];
|
|
4987
|
+
retainedFrom = index + 1;
|
|
4988
|
+
}
|
|
4989
|
+
}
|
|
4990
|
+
return retainedFrom === 0 ? history : {
|
|
4991
|
+
tools: baseline,
|
|
4992
|
+
updates: history.updates.slice(retainedFrom)
|
|
4993
|
+
};
|
|
4865
4994
|
}
|
|
4866
4995
|
/**
|
|
4867
4996
|
* Construct provider declarations from session-folded history without changing logged active tools.
|
|
4868
4997
|
* Unsupported routes and incomplete history use current declarations without developer updates.
|
|
4869
|
-
* Explicitly deferred
|
|
4998
|
+
* Explicitly deferred declarations require an addition to activate them.
|
|
4999
|
+
* A rebuild makes previously activated declarations immediate; unactivated declarations stay deferred.
|
|
5000
|
+
* Addition-only routes rebuild when a tool is removed or tools are added to an empty set;
|
|
5001
|
+
* deferred declarations count as existing tools.
|
|
5002
|
+
* Later additions remain deferred and superseded tool blocks are omitted without dropping other content.
|
|
4870
5003
|
* @param messages - complete request inputs, or the prefix selected for an auxiliary call.
|
|
4871
5004
|
* @param tools - currently active tool schemas.
|
|
4872
5005
|
* @param toolUpdate - the resolved route's update mode.
|
|
@@ -4886,14 +5019,16 @@ function projectToolUpdates(messages, tools, toolUpdate, history) {
|
|
|
4886
5019
|
messages: withoutDeveloperMessages(messages),
|
|
4887
5020
|
tools
|
|
4888
5021
|
};
|
|
4889
|
-
const
|
|
4890
|
-
if (history.updates.some((update) => !
|
|
5022
|
+
const updates = new Map(messages.flatMap((message) => message.role === "developer" ? [[message.id, message.content]] : []));
|
|
5023
|
+
if (history.updates.some((update) => !updates.has(update.messageId))) return {
|
|
4891
5024
|
messages: withoutDeveloperMessages(messages),
|
|
4892
5025
|
tools
|
|
4893
5026
|
};
|
|
4894
|
-
const
|
|
5027
|
+
const projectedHistory = toolUpdate === "addition-only" ? rebaseAdditionOnlyHistory(history, updates) : history;
|
|
5028
|
+
const declarations = toolDeclarations(projectedHistory);
|
|
4895
5029
|
const updateIds = new Set(history.updates.map((update) => update.messageId));
|
|
4896
|
-
const
|
|
5030
|
+
const retainedUpdateIds = new Set(projectedHistory.updates.map((update) => update.messageId));
|
|
5031
|
+
const offered = new Set(projectedHistory.tools.filter((tool) => !tool.deferLoading).map((tool) => tool.name));
|
|
4897
5032
|
const projectedMessages = [];
|
|
4898
5033
|
for (const message of messages) {
|
|
4899
5034
|
if (message.role !== "developer") {
|
|
@@ -4904,6 +5039,7 @@ function projectToolUpdates(messages, tools, toolUpdate, history) {
|
|
|
4904
5039
|
const content = message.content.filter((block) => {
|
|
4905
5040
|
switch (block.type) {
|
|
4906
5041
|
case "tool-addition":
|
|
5042
|
+
if (!retainedUpdateIds.has(message.id)) return false;
|
|
4907
5043
|
if (!declarations.has(block.toolName) || offered.has(block.toolName)) return false;
|
|
4908
5044
|
offered.add(block.toolName);
|
|
4909
5045
|
return true;
|
|
@@ -5434,13 +5570,16 @@ var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializ
|
|
|
5434
5570
|
/**
|
|
5435
5571
|
* Typed error for LLM-related failures. Extends {@link HarnessError}, so the
|
|
5436
5572
|
* `code` string (e.g. `AUTH`, `RATE_LIMIT`, `NO_ADAPTER`) is shared taxonomy.
|
|
5573
|
+
* The constructor takes only a {@link BuiltinLlmFailureCode}; a failure from
|
|
5574
|
+
* another provider, whose code may be any string, is re-raised through
|
|
5575
|
+
* {@link LlmError.fromFailure}.
|
|
5437
5576
|
*/
|
|
5438
|
-
var LlmError = class extends HarnessError {
|
|
5577
|
+
var LlmError = class LlmError extends HarnessError {
|
|
5439
5578
|
/** Serializable facts retained beside this live Error. */
|
|
5440
5579
|
failure;
|
|
5441
5580
|
/**
|
|
5442
5581
|
* @param message - non-empty human-readable failure summary.
|
|
5443
|
-
* @param code -
|
|
5582
|
+
* @param code - built-in stable provider-neutral machine code.
|
|
5444
5583
|
* @param options - optional cause and validated serializable provider facts.
|
|
5445
5584
|
*/
|
|
5446
5585
|
constructor(message, code, options) {
|
|
@@ -5460,6 +5599,18 @@ var LlmError = class extends HarnessError {
|
|
|
5460
5599
|
...options?.offloadImages === void 0 ? {} : { offloadImages: options.offloadImages }
|
|
5461
5600
|
});
|
|
5462
5601
|
}
|
|
5602
|
+
/**
|
|
5603
|
+
* Raise an observed failure again with its own code, which any provider may have chosen.
|
|
5604
|
+
* @param failure - the serializable failure, typically from a stream's terminal chunk.
|
|
5605
|
+
* @param options - optional cause.
|
|
5606
|
+
* @returns an error carrying the failure's message, code, and provider facts.
|
|
5607
|
+
*/
|
|
5608
|
+
static fromFailure(failure, options) {
|
|
5609
|
+
return new LlmError(failure.message, failure.code, {
|
|
5610
|
+
...failure,
|
|
5611
|
+
...options
|
|
5612
|
+
});
|
|
5613
|
+
}
|
|
5463
5614
|
};
|
|
5464
5615
|
(() => {
|
|
5465
5616
|
let _classSuper = TypertRemoteService;
|
|
@@ -6463,6 +6614,36 @@ function assertPluginRecordEvent(value) {
|
|
|
6463
6614
|
const { type } = value;
|
|
6464
6615
|
if (!isPluginRecordType(type)) throw new Error(`plugin record type "${type}" must be "plugin:" followed by lowercase slash-separated segments`);
|
|
6465
6616
|
}
|
|
6617
|
+
/** Copy live append inputs before sequence assignment. */
|
|
6618
|
+
function snapshotAppend(type, data, opts, subject) {
|
|
6619
|
+
const surfaceOp = opts?.surfaceOp;
|
|
6620
|
+
const sourceEventSeqs = opts?.sourceEventSeqs;
|
|
6621
|
+
const dataSnapshot = snapshotJsonValue(data);
|
|
6622
|
+
if (dataSnapshot === void 0) throw new Error(`${subject} carries non-JSON-serializable data`);
|
|
6623
|
+
const surface = snapshotJsonValue({
|
|
6624
|
+
...sourceEventSeqs === void 0 ? {} : { sourceEventSeqs },
|
|
6625
|
+
...surfaceOp === void 0 ? {} : { surfaceOp }
|
|
6626
|
+
});
|
|
6627
|
+
if (surface === void 0) throw new Error(`${subject} carries non-JSON-serializable surface metadata`);
|
|
6628
|
+
return {
|
|
6629
|
+
type,
|
|
6630
|
+
data: dataSnapshot,
|
|
6631
|
+
surface
|
|
6632
|
+
};
|
|
6633
|
+
}
|
|
6634
|
+
/** Construct and validate one live event from detached inputs. */
|
|
6635
|
+
function createAppendEvent(snapshot, seq) {
|
|
6636
|
+
const { type, data, surface } = snapshot;
|
|
6637
|
+
const event = deepFreeze({
|
|
6638
|
+
type,
|
|
6639
|
+
seq,
|
|
6640
|
+
time: Date.now(),
|
|
6641
|
+
data,
|
|
6642
|
+
...surface
|
|
6643
|
+
});
|
|
6644
|
+
validateSessionEventData(event, `session event "${type}" at seq ${seq}`);
|
|
6645
|
+
return event;
|
|
6646
|
+
}
|
|
6466
6647
|
/**
|
|
6467
6648
|
* An event-sourced session: an append-only log of {@link SessionEvent}s.
|
|
6468
6649
|
*
|
|
@@ -6473,6 +6654,7 @@ function assertPluginRecordEvent(value) {
|
|
|
6473
6654
|
*/
|
|
6474
6655
|
var Session = class Session {
|
|
6475
6656
|
log = [];
|
|
6657
|
+
batchPublication;
|
|
6476
6658
|
/** Single incremental owner of surface acceptance and projection state. */
|
|
6477
6659
|
surfaceManager;
|
|
6478
6660
|
/** The ordered surface over this session's event log. */
|
|
@@ -6627,71 +6809,68 @@ var Session = class Session {
|
|
|
6627
6809
|
get seq() {
|
|
6628
6810
|
return SessionLogOffset(this.log.length);
|
|
6629
6811
|
}
|
|
6630
|
-
/**
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
* the log, the append is committed: observer failures are logged and
|
|
6635
|
-
* contained per listener, so they do not change the return value or prevent
|
|
6636
|
-
* later listeners from observing the same accepted event.
|
|
6637
|
-
* Independent Sessions append without notifying store observers. Once a store
|
|
6638
|
-
* prepares or enters the instance, writes require a completed creation
|
|
6639
|
-
* announcement and remain disabled after removal.
|
|
6640
|
-
*
|
|
6641
|
-
* @param type - The event type (key of {@link SessionEventMap}).
|
|
6642
|
-
* @param data - The event payload; must be JSON-serializable.
|
|
6643
|
-
* @param opts - Surface metadata: `surfaceOp` controls how the event enters
|
|
6644
|
-
* the ordered surface; `sourceEventSeqs` lists the seq numbers of earlier
|
|
6645
|
-
* events this one derives from. REQUIRED for
|
|
6646
|
-
* {@link SurfaceEventType} events (every message-producing event must
|
|
6647
|
-
* declare how it joins the surface, the sole source of derived model
|
|
6648
|
-
* history) and
|
|
6649
|
-
* rejected by the compiler for non-surface types like `turn/start` or
|
|
6650
|
-
* `assistant/attempt`. Assistant messages embed their exact provider
|
|
6651
|
-
* stream and cannot cite top-level source events.
|
|
6652
|
-
* @returns the logged event — its assigned `seq`/`time` plus the SNAPSHOT of
|
|
6653
|
-
* `data` that entered the log, so reading `event.data` back sees the logged
|
|
6654
|
-
* value, never the caller's still-mutable input.
|
|
6655
|
-
* @throws if a store-owned Session is unentered or its creation announcement
|
|
6656
|
-
* has not completed, or if `data` or surface
|
|
6657
|
-
* metadata is not losslessly JSON-serializable
|
|
6658
|
-
* (BigInt, function, symbol, undefined, negative zero, non-finite number,
|
|
6659
|
-
* circular reference, sparse array, or an exotic object such as
|
|
6660
|
-
* Map/Set/Date/class instance), or when the candidate violates the
|
|
6661
|
-
* request-header empty-field or tool-error consistency rules, or the
|
|
6662
|
-
* canonical surface contract (marker shape and eligibility, unique
|
|
6663
|
-
* earlier source-event references, positional replacement validity, and complete
|
|
6664
|
-
* shadowed-node coverage). One iterative pass reads, validates, and
|
|
6665
|
-
* copies each nested value once, so a stateful getter cannot supply one value
|
|
6666
|
-
* to validation and another to storage. The event log is the durable source
|
|
6667
|
-
* of truth, so a bad event fails at the append site rather than later during
|
|
6668
|
-
* a backend flush. A synchronous internal dispatch validation failure or an
|
|
6669
|
-
* append reentered while this acceptance/publication boundary is open also
|
|
6670
|
-
* rejects before the log changes.
|
|
6671
|
-
*/
|
|
6812
|
+
/** Current event while synchronously notifying a batch's observers. */
|
|
6813
|
+
get currentBatchPublication() {
|
|
6814
|
+
return this.batchPublication;
|
|
6815
|
+
}
|
|
6672
6816
|
append(type, data, ...opts) {
|
|
6817
|
+
if (typeof type !== "string") return this.#appendEvents(type);
|
|
6673
6818
|
this.publicationEntry();
|
|
6674
|
-
const
|
|
6675
|
-
const surfaceMetadata = {
|
|
6676
|
-
...surfaceOpts?.sourceEventSeqs === void 0 ? {} : { sourceEventSeqs: surfaceOpts.sourceEventSeqs },
|
|
6677
|
-
...surfaceOpts?.surfaceOp === void 0 ? {} : { surfaceOp: surfaceOpts.surfaceOp }
|
|
6678
|
-
};
|
|
6679
|
-
const dataSnapshot = snapshotJsonValue(data);
|
|
6680
|
-
if (dataSnapshot === void 0) throw new Error(`session event "${type}" carries non-JSON-serializable data`);
|
|
6681
|
-
const surfaceMetadataSnapshot = snapshotJsonValue(surfaceMetadata);
|
|
6682
|
-
if (surfaceMetadataSnapshot === void 0) throw new Error(`session event "${type}" carries non-JSON-serializable surface metadata`);
|
|
6819
|
+
const snapshot = snapshotAppend(type, data, opts[0], `session event "${type}"`);
|
|
6683
6820
|
const entry = this.publicationEntry();
|
|
6684
|
-
const event =
|
|
6685
|
-
type,
|
|
6686
|
-
seq: SessionSeq(this.log.length),
|
|
6687
|
-
time: Date.now(),
|
|
6688
|
-
data: dataSnapshot,
|
|
6689
|
-
...surfaceMetadataSnapshot
|
|
6690
|
-
});
|
|
6691
|
-
validateSessionEventData(event, `session event "${type}" at seq ${event.seq}`);
|
|
6821
|
+
const event = createAppendEvent(snapshot, SessionSeq(this.log.length));
|
|
6692
6822
|
this.commit(event, entry);
|
|
6693
6823
|
return event;
|
|
6694
6824
|
}
|
|
6825
|
+
/**
|
|
6826
|
+
* Validate and publish consecutive events together. Observers see the complete log.
|
|
6827
|
+
* @param inputs - event payloads and surface intents in commit order.
|
|
6828
|
+
* @returns immutable committed events in the same order.
|
|
6829
|
+
* @throws before changing the log if any candidate or synchronous dispatch validation fails.
|
|
6830
|
+
*/
|
|
6831
|
+
#appendEvents(inputs) {
|
|
6832
|
+
this.publicationEntry();
|
|
6833
|
+
if (inputs.length === 0) return [];
|
|
6834
|
+
const snapshots = Array.from({ length: inputs.length }, (_, index) => {
|
|
6835
|
+
const input = inputs.at(index);
|
|
6836
|
+
if (input === void 0) throw new Error(`session batch has an empty member at index ${index}`);
|
|
6837
|
+
const [type, data, surfaceOpts] = input;
|
|
6838
|
+
return snapshotAppend(type, data, surfaceOpts, `session batch member ${index} ("${type}")`);
|
|
6839
|
+
});
|
|
6840
|
+
const entry = this.publicationEntry();
|
|
6841
|
+
const startSeq = this.log.length;
|
|
6842
|
+
const events = snapshots.map((snapshot, index) => createAppendEvent(snapshot, SessionSeq(startSeq + index)));
|
|
6843
|
+
const acceptSurface = this.surfaceManager.prepareBatch(events);
|
|
6844
|
+
if (entry !== void 0) entry.appending = true;
|
|
6845
|
+
try {
|
|
6846
|
+
const publications = entry === void 0 ? [] : events.map((event) => {
|
|
6847
|
+
const args = [this, event];
|
|
6848
|
+
return {
|
|
6849
|
+
event,
|
|
6850
|
+
args,
|
|
6851
|
+
callbacks: collectSessionCallbacks(entry.emitCtx, [
|
|
6852
|
+
entry.carrier,
|
|
6853
|
+
"session/event",
|
|
6854
|
+
...args
|
|
6855
|
+
])
|
|
6856
|
+
};
|
|
6857
|
+
});
|
|
6858
|
+
for (const event of events) this.log.push(event);
|
|
6859
|
+
this.eventsSnapshot = void 0;
|
|
6860
|
+
acceptSurface();
|
|
6861
|
+
if (entry !== void 0) for (const { event, args, callbacks } of publications) {
|
|
6862
|
+
this.batchPublication = event;
|
|
6863
|
+
invokeContainedSessionObservers(entry.emitCtx, "session/event", entry.id, args, callbacks);
|
|
6864
|
+
}
|
|
6865
|
+
} finally {
|
|
6866
|
+
this.batchPublication = void 0;
|
|
6867
|
+
if (entry !== void 0) {
|
|
6868
|
+
entry.appending = false;
|
|
6869
|
+
if (entry.detachRequested) entry.detach();
|
|
6870
|
+
}
|
|
6871
|
+
}
|
|
6872
|
+
return events;
|
|
6873
|
+
}
|
|
6695
6874
|
static {}
|
|
6696
6875
|
/**
|
|
6697
6876
|
* Commit one plugin record; {@link appendPluginRecord} is the only caller.
|
|
@@ -12545,6 +12724,7 @@ function validateDeliveryAccepted(event, currentVersion) {
|
|
|
12545
12724
|
*/
|
|
12546
12725
|
function assertReleasedV4Relationships(artifact, knownEventTypes) {
|
|
12547
12726
|
const ids = /* @__PURE__ */ new Set();
|
|
12727
|
+
const names = /* @__PURE__ */ new Set();
|
|
12548
12728
|
for (const event of artifact.events) {
|
|
12549
12729
|
if (!knownEventTypes.has(event.type)) continue;
|
|
12550
12730
|
assertV4DeveloperData(event);
|
|
@@ -12552,13 +12732,30 @@ function assertReleasedV4Relationships(artifact, knownEventTypes) {
|
|
|
12552
12732
|
const deliveryId = validateDeliveryAccepted(event, 4);
|
|
12553
12733
|
if (deliveryId !== void 0 && event.seq >= artifact.inheritedEventCount && deliveryId !== artifact.header.id) throw new SessionFormatError("current-generation delivery marker names the wrong Session");
|
|
12554
12734
|
if (event.type === "subagent/catalog" && event.seq >= artifact.inheritedEventCount) {
|
|
12555
|
-
const
|
|
12735
|
+
const fact = nativeCatalogFact(event.data);
|
|
12736
|
+
const id = fact["childId"];
|
|
12556
12737
|
if (ids.has(id)) throw new SessionFormatError(`duplicate catalog child ${id}`);
|
|
12557
12738
|
ids.add(id);
|
|
12739
|
+
if (fact["name"] === void 0) continue;
|
|
12740
|
+
const name = fact["name"];
|
|
12741
|
+
if (names.has(name)) throw new SessionFormatError(`duplicate catalog child name ${name}`);
|
|
12742
|
+
names.add(name);
|
|
12558
12743
|
}
|
|
12559
12744
|
}
|
|
12560
12745
|
assertV4LifecycleRelationships(artifact, knownEventTypes);
|
|
12561
12746
|
}
|
|
12747
|
+
/**
|
|
12748
|
+
* Validate an own native V4 catalog payload: a historical version or version 3,
|
|
12749
|
+
* which adds the child's name and is written only by native V4 creation.
|
|
12750
|
+
* @param value - native `subagent/catalog` payload.
|
|
12751
|
+
* @returns validated catalog payload.
|
|
12752
|
+
*/
|
|
12753
|
+
function nativeCatalogFact(value) {
|
|
12754
|
+
if (!isSessionFormatJsonObject(value) || value["version"] !== 3) return catalogFact(value);
|
|
12755
|
+
if (typeof value["childId"] !== "string" || value["mode"] !== "continuable" && value["mode"] !== "external" || typeof value["name"] !== "string" || !/^[a-z][a-z0-9-]{0,31}$/u.test(value["name"]) || value["name"] === "lead" || value["mode"] === "continuable" && typeof value["label"] !== "string" || value["label"] !== void 0 && typeof value["label"] !== "string") throw new SessionFormatError("subagent/catalog requires a supported versioned catalog fact");
|
|
12756
|
+
sessionFormatCount(value["childCreatedAt"], "catalog child creation time");
|
|
12757
|
+
return value;
|
|
12758
|
+
}
|
|
12562
12759
|
//#endregion
|
|
12563
12760
|
//#region ../session-format-v3-to-v4/src/codec.ts
|
|
12564
12761
|
/** V4 framing with native tool-role admission and released physical rows. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-session-persistence-jsonl",
|
|
3
3
|
"description": "JSONL durable session persistence backend for the DeepSeek Harness",
|
|
4
|
-
"version": "0.2.2-
|
|
4
|
+
"version": "0.2.2-rc.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -26,28 +26,31 @@
|
|
|
26
26
|
"locale/*.json",
|
|
27
27
|
"lib/index.js",
|
|
28
28
|
"lib/worker.cjs",
|
|
29
|
-
"lib/types/**/*.d.ts"
|
|
29
|
+
"lib/types/**/*.d.ts",
|
|
30
|
+
"lib/types/**/*.d.ts.map",
|
|
31
|
+
"lib/**/*.js.map",
|
|
32
|
+
"src"
|
|
30
33
|
],
|
|
31
34
|
"license": "MIT",
|
|
32
35
|
"peerDependencies": {
|
|
33
|
-
"@deepseek-ai/dsh-session": "0.2.2-
|
|
34
|
-
"@deepseek-ai/dsh-session-persistence": "0.2.2-
|
|
35
|
-
"@deepseek-ai/cordis": "~4.0
|
|
36
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.2",
|
|
37
|
+
"@deepseek-ai/dsh-session-persistence": "0.2.2-rc.2",
|
|
38
|
+
"@deepseek-ai/cordis": "~4.1.0"
|
|
36
39
|
},
|
|
37
40
|
"dependencies": {
|
|
38
|
-
"@deepseek-ai/dsh-llm": "0.2.2-
|
|
39
|
-
"@deepseek-ai/dsh-session-format": "0.2.2-
|
|
40
|
-
"@deepseek-ai/dsh-session-format-catalog": "0.2.2-
|
|
41
|
-
"@deepseek-ai/dsh-session-format-v3-to-v4": "0.2.2-
|
|
41
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.2",
|
|
42
|
+
"@deepseek-ai/dsh-session-format": "0.2.2-rc.2",
|
|
43
|
+
"@deepseek-ai/dsh-session-format-catalog": "0.2.2-rc.2",
|
|
44
|
+
"@deepseek-ai/dsh-session-format-v3-to-v4": "0.2.2-rc.2",
|
|
42
45
|
"@deepseek-ai/node-addon-system": "~0.1.2",
|
|
43
|
-
"@deepseek-ai/schemastery": "~3.
|
|
46
|
+
"@deepseek-ai/schemastery": "~3.19.0",
|
|
44
47
|
"koffi": "3.1.1",
|
|
45
48
|
"p-limit": "7.3.3"
|
|
46
49
|
},
|
|
47
50
|
"devDependencies": {
|
|
48
|
-
"@deepseek-ai/dsh-session": "0.2.2-
|
|
49
|
-
"@deepseek-ai/dsh-session-format-v0-to-v1": "0.2.2-
|
|
50
|
-
"@deepseek-ai/dsh-session-persistence": "0.2.2-
|
|
51
|
-
"@deepseek-ai/cordis": "~4.0
|
|
51
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.2",
|
|
52
|
+
"@deepseek-ai/dsh-session-format-v0-to-v1": "0.2.2-rc.2",
|
|
53
|
+
"@deepseek-ai/dsh-session-persistence": "0.2.2-rc.2",
|
|
54
|
+
"@deepseek-ai/cordis": "~4.1.0"
|
|
52
55
|
}
|
|
53
56
|
}
|