@ponythewhite/base-context 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/base-context-runtime/pyproject.toml +1 -1
  3. package/dist/base-context-runtime/uv.lock +1 -1
  4. package/dist/build-info.json +1 -1
  5. package/dist/bundle/{bundled-modules-5JRM6P4T.js → bundled-modules-MX6YNAM2.js} +2 -2
  6. package/dist/bundle/{chunk-NEHLB7JV.js → chunk-CDXQNS5P.js} +100 -22
  7. package/dist/bundle/{chunk-VVI3UKGR.js → chunk-UHLGPYMI.js} +20 -40
  8. package/dist/bundle/{cli-main-YUDBEYE2.js → cli-main-D7W3WWCV.js} +2 -2
  9. package/dist/bundle/cli.js +1 -1
  10. package/dist/bundle/{main-ZLGGAAGU.js → main-5J3QBZ5Y.js} +2 -2
  11. package/dist/core/canonical-context.d.ts.map +1 -1
  12. package/dist/core/canonical-context.js +115 -30
  13. package/dist/core/canonical-context.js.map +1 -1
  14. package/dist/core/context-epoch.d.ts +14 -3
  15. package/dist/core/context-epoch.d.ts.map +1 -1
  16. package/dist/core/context-epoch.js +5 -1
  17. package/dist/core/context-epoch.js.map +1 -1
  18. package/dist/core/public-context.d.ts.map +1 -1
  19. package/dist/core/public-context.js +20 -8
  20. package/dist/core/public-context.js.map +1 -1
  21. package/dist/modes/daemon/daemon-mode.d.ts.map +1 -1
  22. package/dist/modes/daemon/daemon-mode.js +15 -30
  23. package/dist/modes/daemon/daemon-mode.js.map +1 -1
  24. package/dist/modes/daemon/daemon-socket.d.ts +5 -0
  25. package/dist/modes/daemon/daemon-socket.d.ts.map +1 -1
  26. package/dist/modes/daemon/daemon-socket.js +19 -0
  27. package/dist/modes/daemon/daemon-socket.js.map +1 -1
  28. package/dist/modes/daemon/daemon-supervisor.d.ts.map +1 -1
  29. package/dist/modes/daemon/daemon-supervisor.js +6 -7
  30. package/dist/modes/daemon/daemon-supervisor.js.map +1 -1
  31. package/dist/modes/daemon/daemon-worker-client.d.ts.map +1 -1
  32. package/dist/modes/daemon/daemon-worker-client.js +5 -5
  33. package/dist/modes/daemon/daemon-worker-client.js.map +1 -1
  34. package/package.json +4 -4
@@ -13,15 +13,26 @@ export declare const CONTEXT_TOOL_EPOCH_RENDERER = "native-canonical-epoch/6";
13
13
  export declare const CONTEXT_SKILL_EPOCH_RENDERER = "native-canonical-epoch/7";
14
14
  /** Source-backed summary with retained public tool groups, not a measured MAIN request. */
15
15
  export declare const CONTEXT_TOOL_SUMMARY_RENDERER = "native-canonical-epoch/8";
16
+ /** Public recipes may record absent admission, never a fabricated execution outcome. */
17
+ export declare const CONTEXT_INTERRUPTED_TOOL_RENDERER = "native-canonical-epoch/9";
16
18
  /** Descriptive, source-backed outcomes in the existing accepted epoch, not an execution store. */
17
19
  export interface ToolContinuationGroup {
18
20
  readonly assistantEntryId: string;
19
- readonly calls: readonly {
21
+ readonly calls: readonly ({
22
+ readonly admission?: never;
20
23
  readonly executionId: string;
21
24
  readonly intent: Pick<IndexedSourceEvent, "id" | "sequence" | "revision">;
22
25
  readonly outcome: "outcome_unknown" | "not_started" | "completed" | "failed";
23
26
  readonly result?: Pick<IndexedSourceEvent, "id" | "sequence" | "revision">;
24
- }[];
27
+ } | {
28
+ readonly admission: "absent";
29
+ /** Absence is scoped to this exact captured branch prefix, not external effects. */
30
+ readonly source: SourceSnapshotRef;
31
+ readonly executionId?: never;
32
+ readonly intent?: never;
33
+ readonly outcome?: never;
34
+ readonly result?: never;
35
+ })[];
25
36
  }
26
37
  export type ContextMode = "on" | "off";
27
38
  /** Compatibility retained from an accepted native request, not measurement or replay credit. */
@@ -51,7 +62,7 @@ export interface EpochViewReference {
51
62
  readonly rendering?: "public-history/1" | "public-tool-continuation/1";
52
63
  }
53
64
  interface ContextEpochFields {
54
- readonly renderer: "native-canonical-epoch/1" | "native-canonical-epoch/2" | "native-canonical-epoch/3" | typeof CONTEXT_EPOCH_RENDERER | typeof CONTEXT_POLICY_EPOCH_RENDERER | typeof CONTEXT_TOOL_EPOCH_RENDERER | typeof CONTEXT_SKILL_EPOCH_RENDERER | typeof CONTEXT_TOOL_SUMMARY_RENDERER;
65
+ readonly renderer: "native-canonical-epoch/1" | "native-canonical-epoch/2" | "native-canonical-epoch/3" | typeof CONTEXT_EPOCH_RENDERER | typeof CONTEXT_POLICY_EPOCH_RENDERER | typeof CONTEXT_TOOL_EPOCH_RENDERER | typeof CONTEXT_SKILL_EPOCH_RENDERER | typeof CONTEXT_TOOL_SUMMARY_RENDERER | typeof CONTEXT_INTERRUPTED_TOOL_RENDERER;
55
66
  readonly source: SourceSnapshotRef;
56
67
  readonly includeSummary?: true;
57
68
  /** Granted by an actual accepted adapter projection, never a caller profile name. */
@@ -1 +1 @@
1
- {"version":3,"file":"context-epoch.d.ts","sourceRoot":"","sources":["../../src/core/context-epoch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAGlH,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,qFAAqF;AACrF,eAAO,MAAM,kBAAkB,eAA+B,CAAC;AAC/D,eAAO,MAAM,sBAAsB,6BAA6B,CAAC;AACjE,eAAO,MAAM,6BAA6B,6BAA6B,CAAC;AACxE,eAAO,MAAM,2BAA2B,6BAA6B,CAAC;AACtE,kGAAkG;AAClG,eAAO,MAAM,4BAA4B,6BAA6B,CAAC;AACvE,2FAA2F;AAC3F,eAAO,MAAM,6BAA6B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S,EAC9C,OAAO,GAAE,WAAkB,GACzB,WAAW,CAEb;AAgBD,+EAA+E;AAC/E,wBAAgB,8BAA8B,CAC7C,UAAU,EAAE,sBAAsB,GAAG,SAAS,GAC5C,2BAA2B,GAAG,SAAS,CAezC;AAED,4FAA4F;AAC5F,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,6BAA6B,EACtC,cAAc,EAAE,qBAAqB,GACnC,2BAA2B,CAa7B;AAED,wBAAgB,4BAA4B,CAC3C,QAAQ,EAAE,2BAA2B,EACrC,OAAO,EAAE,6BAA6B,EACtC,cAAc,EAAE,qBAAqB,GACnC,IAAI,CAUN;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,sBAAsB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,CAEpG;AAED,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,sBAAsB,GAAG,SAAS,CA8GvG;AAED,6FAA6F;AAC7F,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,6BAA6B,EACtC,UAAU,EAAE,sBAAsB,GAAG,SAAS,EAC9C,QAAQ,EAAE,MAAM,EAChB,gBAAgB,UAAQ,EACxB,oBAAoB,CAAC,EAAE,MAAM,GAC3B,MAAM,CAiFR","sourcesContent":["import type { ProviderRequestRepresentation, RequestTokenAssessment, Usage } from \"@ponythewhite/base-context-ai\";\nimport { requestTokenRouteIdentity } from \"@ponythewhite/base-context-ai\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ContextRef, IndexedSourceEvent } from \"./history-index.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport { MAX_RESOURCE_REVISION_BYTES } from \"./resource-view.js\";\nimport type { SelectedSkillReference } from \"./selected-skills.js\";\nimport type { CompiledTaskFrame } from \"./task-frame.js\";\n\nexport const CONTEXT_EPOCH_DETAIL = \"baseContextEpoch\";\n/** Internal admission, not a field accepted by ordinary appendCompaction callers. */\nexport const appendContextEpoch = Symbol(\"appendContextEpoch\");\nexport const CONTEXT_EPOCH_RENDERER = \"native-canonical-epoch/4\";\nexport const CONTEXT_POLICY_EPOCH_RENDERER = \"native-canonical-epoch/5\";\nexport const CONTEXT_TOOL_EPOCH_RENDERER = \"native-canonical-epoch/6\";\n/** Selection-bearing v4/v5/v6 variants; older readers must refuse rather than drop these refs. */\nexport const CONTEXT_SKILL_EPOCH_RENDERER = \"native-canonical-epoch/7\";\n/** Source-backed summary with retained public tool groups, not a measured MAIN request. */\nexport const CONTEXT_TOOL_SUMMARY_RENDERER = \"native-canonical-epoch/8\";\n\n/** Descriptive, source-backed outcomes in the existing accepted epoch, not an execution store. */\nexport interface ToolContinuationGroup {\n\treadonly assistantEntryId: string;\n\treadonly calls: readonly {\n\t\treadonly executionId: string;\n\t\treadonly intent: Pick<IndexedSourceEvent, \"id\" | \"sequence\" | \"revision\">;\n\t\treadonly outcome: \"outcome_unknown\" | \"not_started\" | \"completed\" | \"failed\";\n\t\treadonly result?: Pick<IndexedSourceEvent, \"id\" | \"sequence\" | \"revision\">;\n\t}[];\n}\nexport type ContextMode = \"on\" | \"off\";\n\n/** Compatibility retained from an accepted native request, not measurement or replay credit. */\nexport interface ContextEpochRequestContract {\n\treadonly api: string;\n\treadonly provider: string;\n\treadonly route: string;\n\treadonly model: string;\n\treadonly replayContract: ContextReplayContract;\n}\nexport type ContextReplayContract = \"complete-context\" | \"message-groups\";\n\n/** An ordinary summary and its retained source recipes share the existing compaction ACK. */\nexport interface ContextEpochSummary {\n\treadonly summary: string;\n\treadonly details?: Record<string, unknown>;\n\treadonly fromHook?: boolean;\n\treadonly customInstructions?: string;\n\treadonly usage?: Usage;\n}\n\n/** A frozen read recipe, not a second copy of an archived message body. */\nexport interface EpochViewReference {\n\treadonly source: SourceSnapshotRef;\n\treadonly ref: ContextRef;\n\treadonly sourceRevision: string;\n\t/** Present only for an existing rendered compaction summary. */\n\treadonly retainedMessageCount?: number;\n\treadonly rendering?: \"public-history/1\" | \"public-tool-continuation/1\";\n}\n\ninterface ContextEpochFields {\n\treadonly renderer:\n\t\t| \"native-canonical-epoch/1\"\n\t\t| \"native-canonical-epoch/2\"\n\t\t| \"native-canonical-epoch/3\"\n\t\t| typeof CONTEXT_EPOCH_RENDERER\n\t\t| typeof CONTEXT_POLICY_EPOCH_RENDERER\n\t\t| typeof CONTEXT_TOOL_EPOCH_RENDERER\n\t\t| typeof CONTEXT_SKILL_EPOCH_RENDERER\n\t\t| typeof CONTEXT_TOOL_SUMMARY_RENDERER;\n\treadonly source: SourceSnapshotRef;\n\treadonly includeSummary?: true;\n\t/** Granted by an actual accepted adapter projection, never a caller profile name. */\n\treadonly replayContract?: ContextReplayContract;\n\t/** Actual adapter permission to leave completed native groups for a fresh public window. */\n\treadonly publicWindow?: true;\n\t/** Frozen public transition. Later native messages are not silently converted. */\n\treadonly continuation?: {\n\t\treadonly kind: \"harness-summary\" | \"portable-checkpoint\";\n\t\treadonly publicTailThrough: SourceSnapshotRef;\n\t};\n\treadonly views: readonly EpochViewReference[];\n\t/** Captured versions, not a body cache or authority inferred from transcript markup. */\n\treadonly selectedSkills?: readonly SelectedSkillReference[];\n\t/** v6 requests and v8 summaries retain whole public groups and their exact outcome refs. */\n\treadonly toolContinuations?: readonly ToolContinuationGroup[];\n\t/** Derived display only. The task reducer remains the authority for later changes. */\n\treadonly taskFrame?: CompiledTaskFrame;\n\t/** Accepted-state comparison only; saved metadata never establishes current resource liveness. */\n\treadonly resourceRevision?: string;\n\treadonly literalTailId: string;\n}\n\n/** v5 policy-only null is a mode ACK, not an ordinary summary or a measured request. */\nexport type ContextEpochCheckpoint = ContextEpochFields &\n\t(\n\t\t| {\n\t\t\t\treadonly version: 1 | 2 | 3 | 4 | 6;\n\t\t\t\treadonly representation: string | null;\n\t\t\t\treadonly mode?: never;\n\t\t\t\treadonly policyOnly?: never;\n\t\t\t\treadonly requestContract?: never;\n\t\t\t\treadonly pendingRequestContract?: never;\n\t\t }\n\t\t| {\n\t\t\t\treadonly version: 8;\n\t\t\t\treadonly mode: ContextMode;\n\t\t\t\treadonly representation: null;\n\t\t\t\treadonly includeSummary: true;\n\t\t\t\treadonly policyOnly?: never;\n\t\t\t\treadonly requestContract?: never;\n\t\t\t\treadonly pendingRequestContract?: never;\n\t\t }\n\t\t| {\n\t\t\t\treadonly version: 5;\n\t\t\t\treadonly mode: ContextMode;\n\t\t\t\treadonly representation: null;\n\t\t\t\treadonly policyOnly: true;\n\t\t\t\treadonly includeSummary?: never;\n\t\t\t\treadonly requestContract?: ContextEpochRequestContract;\n\t\t\t\treadonly pendingRequestContract?: true;\n\t\t }\n\t);\n\nexport function contextEpochMode(\n\tcheckpoint: ContextEpochCheckpoint | undefined,\n\tinitial: ContextMode = \"on\",\n): ContextMode {\n\treturn checkpoint ? (checkpoint.version === 5 || checkpoint.version === 8 ? checkpoint.mode : \"on\") : initial;\n}\n\nfunction isRequestContract(value: unknown): value is ContextEpochRequestContract {\n\tif (!value || typeof value !== \"object\") return false;\n\treturn (\n\t\t[\"api\", \"provider\", \"route\", \"model\"].every(\n\t\t\t(key) =>\n\t\t\t\tkey in value &&\n\t\t\t\ttypeof (value as Record<string, unknown>)[key] === \"string\" &&\n\t\t\t\t(value as Record<string, unknown>)[key] !== \"\",\n\t\t) &&\n\t\t\"replayContract\" in value &&\n\t\t(value.replayContract === \"complete-context\" || value.replayContract === \"message-groups\")\n\t);\n}\n\n/** Only call with a qualified checkpoint, never raw compaction marker data. */\nexport function retainedContextRequestContract(\n\tcheckpoint: ContextEpochCheckpoint | undefined,\n): ContextEpochRequestContract | undefined {\n\tif (!checkpoint) return;\n\tif (checkpoint.requestContract) return structuredClone(checkpoint.requestContract);\n\tif (!checkpoint.representation) return;\n\tconst accepted: unknown = JSON.parse(checkpoint.representation);\n\tif (!accepted || typeof accepted !== \"object\") throw new Error(\"Accepted context request contract is unavailable\");\n\tconst value = { ...accepted, replayContract: checkpoint.replayContract ?? \"complete-context\" };\n\tif (!isRequestContract(value)) throw new Error(\"Accepted context request contract is unavailable\");\n\treturn {\n\t\tapi: value.api,\n\t\tprovider: value.provider,\n\t\troute: value.route,\n\t\tmodel: value.model,\n\t\treplayContract: value.replayContract,\n\t};\n}\n\n/** Identity comes from the actual final native serialization, not a model/profile label. */\nexport function contextRequestContract(\n\trequest: ProviderRequestRepresentation,\n\treplayContract: ContextReplayContract,\n): ContextEpochRequestContract {\n\tconst route = requestTokenRouteIdentity(request.url);\n\tconst body: unknown = request.body === undefined ? undefined : JSON.parse(request.body);\n\tif (\n\t\t!route ||\n\t\t!body ||\n\t\ttypeof body !== \"object\" ||\n\t\t!(\"model\" in body) ||\n\t\ttypeof body.model !== \"string\" ||\n\t\t!body.model\n\t)\n\t\tthrow new Error(\"Native context request identity is unavailable\");\n\treturn { api: request.api, provider: request.provider, route, model: body.model, replayContract };\n}\n\nexport function assertContextRequestContract(\n\tcontract: ContextEpochRequestContract,\n\trequest: ProviderRequestRepresentation,\n\treplayContract: ContextReplayContract,\n): void {\n\tconst actual = contextRequestContract(request, replayContract);\n\tif (\n\t\tactual.api !== contract.api ||\n\t\tactual.provider !== contract.provider ||\n\t\tactual.route !== contract.route ||\n\t\tactual.model !== contract.model ||\n\t\tactual.replayContract !== contract.replayContract\n\t)\n\t\tthrow new Error(\"Retained context requires its accepted native request contract\");\n}\n\nexport function snapshotContextEpoch<T extends ContextEpochCheckpoint>(value: T, maxBytes: number): T {\n\treturn JSON.parse(stringifyBoundedJson(value, maxBytes)) as T;\n}\n\n/** Called only after checking the source frame's genuine epoch qualification. */\nexport function readContextEpoch(details: unknown, maxBytes: number): ContextEpochCheckpoint | undefined {\n\tif (!details || typeof details !== \"object\" || !(CONTEXT_EPOCH_DETAIL in details)) return;\n\tconst value: unknown = details[CONTEXT_EPOCH_DETAIL];\n\tif (\n\t\t!value ||\n\t\ttypeof value !== \"object\" ||\n\t\t!(\"version\" in value) ||\n\t\t!(\"renderer\" in value) ||\n\t\t!(\n\t\t\t(value.version === 1 && value.renderer === \"native-canonical-epoch/1\") ||\n\t\t\t(value.version === 2 && value.renderer === \"native-canonical-epoch/2\") ||\n\t\t\t(value.version === 3 && value.renderer === \"native-canonical-epoch/3\") ||\n\t\t\t(value.version === 4 && value.renderer === \"native-canonical-epoch/4\") ||\n\t\t\t(value.version === 5 && value.renderer === CONTEXT_POLICY_EPOCH_RENDERER) ||\n\t\t\t(value.version === 6 && value.renderer === CONTEXT_TOOL_EPOCH_RENDERER) ||\n\t\t\t(value.version === 8 && value.renderer === CONTEXT_TOOL_SUMMARY_RENDERER) ||\n\t\t\t([4, 5, 6].includes(value.version as number) && value.renderer === CONTEXT_SKILL_EPOCH_RENDERER)\n\t\t) ||\n\t\t(value.renderer === CONTEXT_SKILL_EPOCH_RENDERER || (value.version === 8 && \"selectedSkills\" in value)\n\t\t\t? !(\"selectedSkills\" in value) ||\n\t\t\t\t!Array.isArray(value.selectedSkills) ||\n\t\t\t\tvalue.selectedSkills.length === 0 ||\n\t\t\t\tvalue.selectedSkills.some(\n\t\t\t\t\t(item) =>\n\t\t\t\t\t\t!item ||\n\t\t\t\t\t\ttypeof item.name !== \"string\" ||\n\t\t\t\t\t\t!item.view ||\n\t\t\t\t\t\t![\"custom_message\", \"custom\"].includes(item.view.ref?.kind) ||\n\t\t\t\t\t\ttypeof item.view.sourceRevision !== \"string\",\n\t\t\t\t) ||\n\t\t\t\tnew Set(value.selectedSkills.map((item) => item.name)).size !== value.selectedSkills.length\n\t\t\t: \"selectedSkills\" in value) ||\n\t\t!(\"source\" in value) ||\n\t\t!value.source ||\n\t\t!(\"views\" in value) ||\n\t\t!Array.isArray(value.views) ||\n\t\t!(\"literalTailId\" in value) ||\n\t\ttypeof value.literalTailId !== \"string\" ||\n\t\t!(\"representation\" in value) ||\n\t\t(value.version === 5 || value.version === 8\n\t\t\t? !(\"mode\" in value) || (value.mode !== \"on\" && value.mode !== \"off\")\n\t\t\t: \"mode\" in value) ||\n\t\t(value.version === 8 &&\n\t\t\t(value.representation !== null || !(\"includeSummary\" in value) || value.includeSummary !== true)) ||\n\t\t(value.version === 5 &&\n\t\t\t(value.representation !== null || !(\"policyOnly\" in value) || value.policyOnly !== true)) ||\n\t\t(\"policyOnly\" in value &&\n\t\t\t(value.version !== 5 ||\n\t\t\t\tvalue.policyOnly !== true ||\n\t\t\t\tvalue.representation !== null ||\n\t\t\t\t\"includeSummary\" in value)) ||\n\t\t(\"pendingRequestContract\" in value &&\n\t\t\t(value.version !== 5 ||\n\t\t\t\t!(\"mode\" in value) ||\n\t\t\t\tvalue.mode !== \"off\" ||\n\t\t\t\tvalue.pendingRequestContract !== true ||\n\t\t\t\t\"requestContract\" in value)) ||\n\t\t(\"requestContract\" in value && (value.version !== 5 || !isRequestContract(value.requestContract))) ||\n\t\t!(\n\t\t\ttypeof value.representation === \"string\" ||\n\t\t\t(value.version === 5 && value.representation === null && \"policyOnly\" in value && value.policyOnly === true) ||\n\t\t\t((value.version === 2 || value.version === 3 || value.version === 4 || value.version === 8) &&\n\t\t\t\tvalue.representation === null &&\n\t\t\t\t\"includeSummary\" in value &&\n\t\t\t\tvalue.includeSummary === true)\n\t\t) ||\n\t\t(\"includeSummary\" in value &&\n\t\t\t((value.version !== 2 && value.version !== 3 && value.version !== 4 && value.version !== 8) ||\n\t\t\t\tvalue.includeSummary !== true ||\n\t\t\t\tvalue.representation !== null)) ||\n\t\t(\"replayContract\" in value &&\n\t\t\tvalue.replayContract !== \"complete-context\" &&\n\t\t\tvalue.replayContract !== \"message-groups\") ||\n\t\t(\"resourceRevision\" in value &&\n\t\t\t(typeof value.resourceRevision !== \"string\" ||\n\t\t\t\tBuffer.byteLength(value.resourceRevision, \"utf8\") > MAX_RESOURCE_REVISION_BYTES)) ||\n\t\t(\"publicWindow\" in value &&\n\t\t\t((value.version !== 3 &&\n\t\t\t\tvalue.version !== 4 &&\n\t\t\t\tvalue.version !== 5 &&\n\t\t\t\tvalue.version !== 6 &&\n\t\t\t\tvalue.version !== 8) ||\n\t\t\t\tvalue.publicWindow !== true)) ||\n\t\t(\"toolContinuations\" in value && value.version !== 6 && value.version !== 8) ||\n\t\t((value.version === 6 || value.version === 8) &&\n\t\t\t(!(\"toolContinuations\" in value) ||\n\t\t\t\t!Array.isArray(value.toolContinuations) ||\n\t\t\t\t!value.toolContinuations.length ||\n\t\t\t\t!(\"replayContract\" in value) ||\n\t\t\t\t(value.version === 6 &&\n\t\t\t\t\t(!(\"publicWindow\" in value) ||\n\t\t\t\t\t\tvalue.publicWindow !== true ||\n\t\t\t\t\t\tvalue.replayContract !== \"message-groups\")))) ||\n\t\t(\"continuation\" in value &&\n\t\t\t((value.version !== 3 &&\n\t\t\t\tvalue.version !== 4 &&\n\t\t\t\tvalue.version !== 5 &&\n\t\t\t\tvalue.version !== 6 &&\n\t\t\t\tvalue.version !== 8) ||\n\t\t\t\t!value.continuation ||\n\t\t\t\ttypeof value.continuation !== \"object\" ||\n\t\t\t\t!(\"kind\" in value.continuation) ||\n\t\t\t\t(value.continuation.kind !== \"harness-summary\" &&\n\t\t\t\t\t((value.version !== 4 && value.version !== 5 && value.version !== 6) ||\n\t\t\t\t\t\tvalue.continuation.kind !== \"portable-checkpoint\")) ||\n\t\t\t\t!(\"publicTailThrough\" in value.continuation) ||\n\t\t\t\t!value.continuation.publicTailThrough))\n\t)\n\t\tthrow new Error(\"Invalid committed context epoch\");\n\treturn snapshotContextEpoch(value as ContextEpochCheckpoint, maxBytes);\n}\n\n/** Stable representation, not the changing input, an auth envelope, or a cache-hit claim. */\nexport function contextEpochRepresentation(\n\trequest: ProviderRequestRepresentation,\n\tassessment: RequestTokenAssessment | undefined,\n\tmaxBytes: number,\n\tunbudgetedPublic = false,\n\tresponseItemIdentity?: string,\n): string {\n\tif (\n\t\t(!assessment && !unbudgetedPublic) ||\n\t\t(assessment &&\n\t\t\t(!assessment.profile ||\n\t\t\t\tassessment.limitSource !== \"explicit-profile\" ||\n\t\t\t\t!assessment.route ||\n\t\t\t\t!assessment.model)) ||\n\t\trequest.body === undefined\n\t)\n\t\tthrow new Error(\"Committed context epoch requires its explicit request profile\");\n\tconst identity = assessment ?? contextRequestContract(request, \"message-groups\");\n\tconst body: unknown = JSON.parse(request.body);\n\tif (!body || typeof body !== \"object\" || Array.isArray(body))\n\t\tthrow new Error(\"Context epoch request representation is unavailable\");\n\tconst configuration: Record<string, unknown> = {};\n\tconst fields = new Set([\n\t\t\"model\",\n\t\t\"instructions\",\n\t\t\"stream\",\n\t\t\"max_output_tokens\",\n\t\t\"max_tokens\",\n\t\t\"max_completion_tokens\",\n\t\t\"temperature\",\n\t\t\"top_p\",\n\t\t\"text\",\n\t\t\"tools\",\n\t\t\"tool_choice\",\n\t\t\"parallel_tool_calls\",\n\t\t\"store\",\n\t\t\"reasoning\",\n\t\t\"service_tier\",\n\t\t\"truncation\",\n\t\t\"include\",\n\t\t\"prompt_cache_retention\",\n\t\t\"stream_options\",\n\t]);\n\tif (\n\t\trequest.api === \"openai-completions\" &&\n\t\trequest.provider === \"deepseek\" &&\n\t\trequest.url === \"https://api.deepseek.com/chat/completions\" &&\n\t\tidentity.route === request.url &&\n\t\t\"model\" in body &&\n\t\tbody.model === \"deepseek-flash\" &&\n\t\tidentity.model === body.model\n\t) {\n\t\tfields.add(\"thinking\");\n\t\tfields.add(\"reasoning_effort\");\n\t}\n\tfor (const [key, value] of Object.entries(body)) {\n\t\tif ([\"input\", \"messages\", \"previous_response_id\", \"prompt_cache_key\"].includes(key)) continue;\n\t\t// Unknown payload extensions may contain private data or change the representation.\n\t\tif (!fields.has(key)) throw new Error(\"Unsupported context epoch request configuration\");\n\t\tconfiguration[key] = value;\n\t}\n\tconst input: unknown = \"input\" in body ? body.input : \"messages\" in body ? body.messages : undefined;\n\tif (!Array.isArray(input)) throw new Error(\"Context epoch request messages are unavailable\");\n\tconst policy = input.filter(\n\t\t(item: unknown) =>\n\t\t\titem && typeof item === \"object\" && \"role\" in item && (item.role === \"system\" || item.role === \"developer\"),\n\t);\n\treturn stringifyBoundedJson(\n\t\t{\n\t\t\trenderer: CONTEXT_EPOCH_RENDERER,\n\t\t\t...(responseItemIdentity ? { responseItemIdentity } : {}),\n\t\t\tapi: request.api,\n\t\t\tprovider: request.provider,\n\t\t\troute: identity.route,\n\t\t\tmodel: identity.model,\n\t\t\t...(assessment\n\t\t\t\t? {\n\t\t\t\t\t\tprofile: assessment.profile,\n\t\t\t\t\t\tcontextTokens: assessment.contextTokens,\n\t\t\t\t\t\toutputReserveTokens: assessment.outputReserveTokens,\n\t\t\t\t\t}\n\t\t\t\t: { budget: \"unbudgeted\" }),\n\t\t\tconfiguration,\n\t\t\tpolicy,\n\t\t},\n\t\tmaxBytes,\n\t);\n}\n"]}
1
+ {"version":3,"file":"context-epoch.d.ts","sourceRoot":"","sources":["../../src/core/context-epoch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAGlH,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,qFAAqF;AACrF,eAAO,MAAM,kBAAkB,eAA+B,CAAC;AAC/D,eAAO,MAAM,sBAAsB,6BAA6B,CAAC;AACjE,eAAO,MAAM,6BAA6B,6BAA6B,CAAC;AACxE,eAAO,MAAM,2BAA2B,6BAA6B,CAAC;AACtE,kGAAkG;AAClG,eAAO,MAAM,4BAA4B,6BAA6B,CAAC;AACvE,2FAA2F;AAC3F,eAAO,MAAM,6BAA6B,6BAA6B,CAAC;AACxE,wFAAwF;AACxF,eAAO,MAAM,iCAAiC,6BAA6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["import type { ProviderRequestRepresentation, RequestTokenAssessment, Usage } from \"@ponythewhite/base-context-ai\";\nimport { requestTokenRouteIdentity } from \"@ponythewhite/base-context-ai\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ContextRef, IndexedSourceEvent } from \"./history-index.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport { MAX_RESOURCE_REVISION_BYTES } from \"./resource-view.js\";\nimport type { SelectedSkillReference } from \"./selected-skills.js\";\nimport type { CompiledTaskFrame } from \"./task-frame.js\";\n\nexport const CONTEXT_EPOCH_DETAIL = \"baseContextEpoch\";\n/** Internal admission, not a field accepted by ordinary appendCompaction callers. */\nexport const appendContextEpoch = Symbol(\"appendContextEpoch\");\nexport const CONTEXT_EPOCH_RENDERER = \"native-canonical-epoch/4\";\nexport const CONTEXT_POLICY_EPOCH_RENDERER = \"native-canonical-epoch/5\";\nexport const CONTEXT_TOOL_EPOCH_RENDERER = \"native-canonical-epoch/6\";\n/** Selection-bearing v4/v5/v6 variants; older readers must refuse rather than drop these refs. */\nexport const CONTEXT_SKILL_EPOCH_RENDERER = \"native-canonical-epoch/7\";\n/** Source-backed summary with retained public tool groups, not a measured MAIN request. */\nexport const CONTEXT_TOOL_SUMMARY_RENDERER = \"native-canonical-epoch/8\";\n/** Public recipes may record absent admission, never a fabricated execution outcome. */\nexport const CONTEXT_INTERRUPTED_TOOL_RENDERER = \"native-canonical-epoch/9\";\n\n/** Descriptive, source-backed outcomes in the existing accepted epoch, not an execution store. */\nexport interface ToolContinuationGroup {\n\treadonly assistantEntryId: string;\n\treadonly calls: readonly (\n\t\t| {\n\t\t\t\treadonly admission?: never;\n\t\t\t\treadonly executionId: string;\n\t\t\t\treadonly intent: Pick<IndexedSourceEvent, \"id\" | \"sequence\" | \"revision\">;\n\t\t\t\treadonly outcome: \"outcome_unknown\" | \"not_started\" | \"completed\" | \"failed\";\n\t\t\t\treadonly result?: Pick<IndexedSourceEvent, \"id\" | \"sequence\" | \"revision\">;\n\t\t }\n\t\t| {\n\t\t\t\treadonly admission: \"absent\";\n\t\t\t\t/** Absence is scoped to this exact captured branch prefix, not external effects. */\n\t\t\t\treadonly source: SourceSnapshotRef;\n\t\t\t\treadonly executionId?: never;\n\t\t\t\treadonly intent?: never;\n\t\t\t\treadonly outcome?: never;\n\t\t\t\treadonly result?: never;\n\t\t }\n\t)[];\n}\nexport type ContextMode = \"on\" | \"off\";\n\n/** Compatibility retained from an accepted native request, not measurement or replay credit. */\nexport interface ContextEpochRequestContract {\n\treadonly api: string;\n\treadonly provider: string;\n\treadonly route: string;\n\treadonly model: string;\n\treadonly replayContract: ContextReplayContract;\n}\nexport type ContextReplayContract = \"complete-context\" | \"message-groups\";\n\n/** An ordinary summary and its retained source recipes share the existing compaction ACK. */\nexport interface ContextEpochSummary {\n\treadonly summary: string;\n\treadonly details?: Record<string, unknown>;\n\treadonly fromHook?: boolean;\n\treadonly customInstructions?: string;\n\treadonly usage?: Usage;\n}\n\n/** A frozen read recipe, not a second copy of an archived message body. */\nexport interface EpochViewReference {\n\treadonly source: SourceSnapshotRef;\n\treadonly ref: ContextRef;\n\treadonly sourceRevision: string;\n\t/** Present only for an existing rendered compaction summary. */\n\treadonly retainedMessageCount?: number;\n\treadonly rendering?: \"public-history/1\" | \"public-tool-continuation/1\";\n}\n\ninterface ContextEpochFields {\n\treadonly renderer:\n\t\t| \"native-canonical-epoch/1\"\n\t\t| \"native-canonical-epoch/2\"\n\t\t| \"native-canonical-epoch/3\"\n\t\t| typeof CONTEXT_EPOCH_RENDERER\n\t\t| typeof CONTEXT_POLICY_EPOCH_RENDERER\n\t\t| typeof CONTEXT_TOOL_EPOCH_RENDERER\n\t\t| typeof CONTEXT_SKILL_EPOCH_RENDERER\n\t\t| typeof CONTEXT_TOOL_SUMMARY_RENDERER\n\t\t| typeof CONTEXT_INTERRUPTED_TOOL_RENDERER;\n\treadonly source: SourceSnapshotRef;\n\treadonly includeSummary?: true;\n\t/** Granted by an actual accepted adapter projection, never a caller profile name. */\n\treadonly replayContract?: ContextReplayContract;\n\t/** Actual adapter permission to leave completed native groups for a fresh public window. */\n\treadonly publicWindow?: true;\n\t/** Frozen public transition. Later native messages are not silently converted. */\n\treadonly continuation?: {\n\t\treadonly kind: \"harness-summary\" | \"portable-checkpoint\";\n\t\treadonly publicTailThrough: SourceSnapshotRef;\n\t};\n\treadonly views: readonly EpochViewReference[];\n\t/** Captured versions, not a body cache or authority inferred from transcript markup. */\n\treadonly selectedSkills?: readonly SelectedSkillReference[];\n\t/** v6 requests and v8 summaries retain whole public groups and their exact outcome refs. */\n\treadonly toolContinuations?: readonly ToolContinuationGroup[];\n\t/** Derived display only. The task reducer remains the authority for later changes. */\n\treadonly taskFrame?: CompiledTaskFrame;\n\t/** Accepted-state comparison only; saved metadata never establishes current resource liveness. */\n\treadonly resourceRevision?: string;\n\treadonly literalTailId: string;\n}\n\n/** v5 policy-only null is a mode ACK, not an ordinary summary or a measured request. */\nexport type ContextEpochCheckpoint = ContextEpochFields &\n\t(\n\t\t| {\n\t\t\t\treadonly version: 1 | 2 | 3 | 4 | 6;\n\t\t\t\treadonly representation: string | null;\n\t\t\t\treadonly mode?: never;\n\t\t\t\treadonly policyOnly?: never;\n\t\t\t\treadonly requestContract?: never;\n\t\t\t\treadonly pendingRequestContract?: never;\n\t\t }\n\t\t| {\n\t\t\t\treadonly version: 8;\n\t\t\t\treadonly mode: ContextMode;\n\t\t\t\treadonly representation: null;\n\t\t\t\treadonly includeSummary: true;\n\t\t\t\treadonly policyOnly?: never;\n\t\t\t\treadonly requestContract?: never;\n\t\t\t\treadonly pendingRequestContract?: never;\n\t\t }\n\t\t| {\n\t\t\t\treadonly version: 5;\n\t\t\t\treadonly mode: ContextMode;\n\t\t\t\treadonly representation: null;\n\t\t\t\treadonly policyOnly: true;\n\t\t\t\treadonly includeSummary?: never;\n\t\t\t\treadonly requestContract?: ContextEpochRequestContract;\n\t\t\t\treadonly pendingRequestContract?: true;\n\t\t }\n\t);\n\nexport function contextEpochMode(\n\tcheckpoint: ContextEpochCheckpoint | undefined,\n\tinitial: ContextMode = \"on\",\n): ContextMode {\n\treturn checkpoint ? (checkpoint.version === 5 || checkpoint.version === 8 ? checkpoint.mode : \"on\") : initial;\n}\n\nfunction isRequestContract(value: unknown): value is ContextEpochRequestContract {\n\tif (!value || typeof value !== \"object\") return false;\n\treturn (\n\t\t[\"api\", \"provider\", \"route\", \"model\"].every(\n\t\t\t(key) =>\n\t\t\t\tkey in value &&\n\t\t\t\ttypeof (value as Record<string, unknown>)[key] === \"string\" &&\n\t\t\t\t(value as Record<string, unknown>)[key] !== \"\",\n\t\t) &&\n\t\t\"replayContract\" in value &&\n\t\t(value.replayContract === \"complete-context\" || value.replayContract === \"message-groups\")\n\t);\n}\n\n/** Only call with a qualified checkpoint, never raw compaction marker data. */\nexport function retainedContextRequestContract(\n\tcheckpoint: ContextEpochCheckpoint | undefined,\n): ContextEpochRequestContract | undefined {\n\tif (!checkpoint) return;\n\tif (checkpoint.requestContract) return structuredClone(checkpoint.requestContract);\n\tif (!checkpoint.representation) return;\n\tconst accepted: unknown = JSON.parse(checkpoint.representation);\n\tif (!accepted || typeof accepted !== \"object\") throw new Error(\"Accepted context request contract is unavailable\");\n\tconst value = { ...accepted, replayContract: checkpoint.replayContract ?? \"complete-context\" };\n\tif (!isRequestContract(value)) throw new Error(\"Accepted context request contract is unavailable\");\n\treturn {\n\t\tapi: value.api,\n\t\tprovider: value.provider,\n\t\troute: value.route,\n\t\tmodel: value.model,\n\t\treplayContract: value.replayContract,\n\t};\n}\n\n/** Identity comes from the actual final native serialization, not a model/profile label. */\nexport function contextRequestContract(\n\trequest: ProviderRequestRepresentation,\n\treplayContract: ContextReplayContract,\n): ContextEpochRequestContract {\n\tconst route = requestTokenRouteIdentity(request.url);\n\tconst body: unknown = request.body === undefined ? undefined : JSON.parse(request.body);\n\tif (\n\t\t!route ||\n\t\t!body ||\n\t\ttypeof body !== \"object\" ||\n\t\t!(\"model\" in body) ||\n\t\ttypeof body.model !== \"string\" ||\n\t\t!body.model\n\t)\n\t\tthrow new Error(\"Native context request identity is unavailable\");\n\treturn { api: request.api, provider: request.provider, route, model: body.model, replayContract };\n}\n\nexport function assertContextRequestContract(\n\tcontract: ContextEpochRequestContract,\n\trequest: ProviderRequestRepresentation,\n\treplayContract: ContextReplayContract,\n): void {\n\tconst actual = contextRequestContract(request, replayContract);\n\tif (\n\t\tactual.api !== contract.api ||\n\t\tactual.provider !== contract.provider ||\n\t\tactual.route !== contract.route ||\n\t\tactual.model !== contract.model ||\n\t\tactual.replayContract !== contract.replayContract\n\t)\n\t\tthrow new Error(\"Retained context requires its accepted native request contract\");\n}\n\nexport function snapshotContextEpoch<T extends ContextEpochCheckpoint>(value: T, maxBytes: number): T {\n\treturn JSON.parse(stringifyBoundedJson(value, maxBytes)) as T;\n}\n\n/** Called only after checking the source frame's genuine epoch qualification. */\nexport function readContextEpoch(details: unknown, maxBytes: number): ContextEpochCheckpoint | undefined {\n\tif (!details || typeof details !== \"object\" || !(CONTEXT_EPOCH_DETAIL in details)) return;\n\tconst value: unknown = details[CONTEXT_EPOCH_DETAIL];\n\tif (\n\t\t!value ||\n\t\ttypeof value !== \"object\" ||\n\t\t!(\"version\" in value) ||\n\t\t!(\"renderer\" in value) ||\n\t\t!(\n\t\t\t(value.version === 1 && value.renderer === \"native-canonical-epoch/1\") ||\n\t\t\t(value.version === 2 && value.renderer === \"native-canonical-epoch/2\") ||\n\t\t\t(value.version === 3 && value.renderer === \"native-canonical-epoch/3\") ||\n\t\t\t(value.version === 4 && value.renderer === \"native-canonical-epoch/4\") ||\n\t\t\t(value.version === 5 && value.renderer === CONTEXT_POLICY_EPOCH_RENDERER) ||\n\t\t\t(value.version === 6 && value.renderer === CONTEXT_TOOL_EPOCH_RENDERER) ||\n\t\t\t(value.version === 8 && value.renderer === CONTEXT_TOOL_SUMMARY_RENDERER) ||\n\t\t\t([6, 8].includes(value.version as number) && value.renderer === CONTEXT_INTERRUPTED_TOOL_RENDERER) ||\n\t\t\t([4, 5, 6].includes(value.version as number) && value.renderer === CONTEXT_SKILL_EPOCH_RENDERER)\n\t\t) ||\n\t\t(value.renderer === CONTEXT_SKILL_EPOCH_RENDERER ||\n\t\t((value.version === 8 || value.renderer === CONTEXT_INTERRUPTED_TOOL_RENDERER) && \"selectedSkills\" in value)\n\t\t\t? !(\"selectedSkills\" in value) ||\n\t\t\t\t!Array.isArray(value.selectedSkills) ||\n\t\t\t\tvalue.selectedSkills.length === 0 ||\n\t\t\t\tvalue.selectedSkills.some(\n\t\t\t\t\t(item) =>\n\t\t\t\t\t\t!item ||\n\t\t\t\t\t\ttypeof item.name !== \"string\" ||\n\t\t\t\t\t\t!item.view ||\n\t\t\t\t\t\t![\"custom_message\", \"custom\"].includes(item.view.ref?.kind) ||\n\t\t\t\t\t\ttypeof item.view.sourceRevision !== \"string\",\n\t\t\t\t) ||\n\t\t\t\tnew Set(value.selectedSkills.map((item) => item.name)).size !== value.selectedSkills.length\n\t\t\t: \"selectedSkills\" in value) ||\n\t\t!(\"source\" in value) ||\n\t\t!value.source ||\n\t\t!(\"views\" in value) ||\n\t\t!Array.isArray(value.views) ||\n\t\t!(\"literalTailId\" in value) ||\n\t\ttypeof value.literalTailId !== \"string\" ||\n\t\t!(\"representation\" in value) ||\n\t\t(value.version === 5 || value.version === 8\n\t\t\t? !(\"mode\" in value) || (value.mode !== \"on\" && value.mode !== \"off\")\n\t\t\t: \"mode\" in value) ||\n\t\t(value.version === 8 &&\n\t\t\t(value.representation !== null || !(\"includeSummary\" in value) || value.includeSummary !== true)) ||\n\t\t(value.version === 5 &&\n\t\t\t(value.representation !== null || !(\"policyOnly\" in value) || value.policyOnly !== true)) ||\n\t\t(\"policyOnly\" in value &&\n\t\t\t(value.version !== 5 ||\n\t\t\t\tvalue.policyOnly !== true ||\n\t\t\t\tvalue.representation !== null ||\n\t\t\t\t\"includeSummary\" in value)) ||\n\t\t(\"pendingRequestContract\" in value &&\n\t\t\t(value.version !== 5 ||\n\t\t\t\t!(\"mode\" in value) ||\n\t\t\t\tvalue.mode !== \"off\" ||\n\t\t\t\tvalue.pendingRequestContract !== true ||\n\t\t\t\t\"requestContract\" in value)) ||\n\t\t(\"requestContract\" in value && (value.version !== 5 || !isRequestContract(value.requestContract))) ||\n\t\t!(\n\t\t\ttypeof value.representation === \"string\" ||\n\t\t\t(value.version === 5 && value.representation === null && \"policyOnly\" in value && value.policyOnly === true) ||\n\t\t\t((value.version === 2 || value.version === 3 || value.version === 4 || value.version === 8) &&\n\t\t\t\tvalue.representation === null &&\n\t\t\t\t\"includeSummary\" in value &&\n\t\t\t\tvalue.includeSummary === true)\n\t\t) ||\n\t\t(\"includeSummary\" in value &&\n\t\t\t((value.version !== 2 && value.version !== 3 && value.version !== 4 && value.version !== 8) ||\n\t\t\t\tvalue.includeSummary !== true ||\n\t\t\t\tvalue.representation !== null)) ||\n\t\t(\"replayContract\" in value &&\n\t\t\tvalue.replayContract !== \"complete-context\" &&\n\t\t\tvalue.replayContract !== \"message-groups\") ||\n\t\t(\"resourceRevision\" in value &&\n\t\t\t(typeof value.resourceRevision !== \"string\" ||\n\t\t\t\tBuffer.byteLength(value.resourceRevision, \"utf8\") > MAX_RESOURCE_REVISION_BYTES)) ||\n\t\t(\"publicWindow\" in value &&\n\t\t\t((value.version !== 3 &&\n\t\t\t\tvalue.version !== 4 &&\n\t\t\t\tvalue.version !== 5 &&\n\t\t\t\tvalue.version !== 6 &&\n\t\t\t\tvalue.version !== 8) ||\n\t\t\t\tvalue.publicWindow !== true)) ||\n\t\t(\"toolContinuations\" in value && value.version !== 6 && value.version !== 8) ||\n\t\t((value.version === 6 || value.version === 8) &&\n\t\t\t(!(\"toolContinuations\" in value) ||\n\t\t\t\t!Array.isArray(value.toolContinuations) ||\n\t\t\t\t!value.toolContinuations.length ||\n\t\t\t\t!(\"replayContract\" in value) ||\n\t\t\t\t(value.version === 6 &&\n\t\t\t\t\t(!(\"publicWindow\" in value) ||\n\t\t\t\t\t\tvalue.publicWindow !== true ||\n\t\t\t\t\t\tvalue.replayContract !== \"message-groups\")))) ||\n\t\t(\"continuation\" in value &&\n\t\t\t((value.version !== 3 &&\n\t\t\t\tvalue.version !== 4 &&\n\t\t\t\tvalue.version !== 5 &&\n\t\t\t\tvalue.version !== 6 &&\n\t\t\t\tvalue.version !== 8) ||\n\t\t\t\t!value.continuation ||\n\t\t\t\ttypeof value.continuation !== \"object\" ||\n\t\t\t\t!(\"kind\" in value.continuation) ||\n\t\t\t\t(value.continuation.kind !== \"harness-summary\" &&\n\t\t\t\t\t((value.version !== 4 && value.version !== 5 && value.version !== 6) ||\n\t\t\t\t\t\tvalue.continuation.kind !== \"portable-checkpoint\")) ||\n\t\t\t\t!(\"publicTailThrough\" in value.continuation) ||\n\t\t\t\t!value.continuation.publicTailThrough))\n\t)\n\t\tthrow new Error(\"Invalid committed context epoch\");\n\treturn snapshotContextEpoch(value as ContextEpochCheckpoint, maxBytes);\n}\n\n/** Stable representation, not the changing input, an auth envelope, or a cache-hit claim. */\nexport function contextEpochRepresentation(\n\trequest: ProviderRequestRepresentation,\n\tassessment: RequestTokenAssessment | undefined,\n\tmaxBytes: number,\n\tunbudgetedPublic = false,\n\tresponseItemIdentity?: string,\n): string {\n\tif (\n\t\t(!assessment && !unbudgetedPublic) ||\n\t\t(assessment &&\n\t\t\t(!assessment.profile ||\n\t\t\t\tassessment.limitSource !== \"explicit-profile\" ||\n\t\t\t\t!assessment.route ||\n\t\t\t\t!assessment.model)) ||\n\t\trequest.body === undefined\n\t)\n\t\tthrow new Error(\"Committed context epoch requires its explicit request profile\");\n\tconst identity = assessment ?? contextRequestContract(request, \"message-groups\");\n\tconst body: unknown = JSON.parse(request.body);\n\tif (!body || typeof body !== \"object\" || Array.isArray(body))\n\t\tthrow new Error(\"Context epoch request representation is unavailable\");\n\tconst configuration: Record<string, unknown> = {};\n\tconst fields = new Set([\n\t\t\"model\",\n\t\t\"instructions\",\n\t\t\"stream\",\n\t\t\"max_output_tokens\",\n\t\t\"max_tokens\",\n\t\t\"max_completion_tokens\",\n\t\t\"temperature\",\n\t\t\"top_p\",\n\t\t\"text\",\n\t\t\"tools\",\n\t\t\"tool_choice\",\n\t\t\"parallel_tool_calls\",\n\t\t\"store\",\n\t\t\"reasoning\",\n\t\t\"service_tier\",\n\t\t\"truncation\",\n\t\t\"include\",\n\t\t\"prompt_cache_retention\",\n\t\t\"stream_options\",\n\t]);\n\tif (\n\t\trequest.api === \"openai-completions\" &&\n\t\trequest.provider === \"deepseek\" &&\n\t\trequest.url === \"https://api.deepseek.com/chat/completions\" &&\n\t\tidentity.route === request.url &&\n\t\t\"model\" in body &&\n\t\tbody.model === \"deepseek-flash\" &&\n\t\tidentity.model === body.model\n\t) {\n\t\tfields.add(\"thinking\");\n\t\tfields.add(\"reasoning_effort\");\n\t}\n\tfor (const [key, value] of Object.entries(body)) {\n\t\tif ([\"input\", \"messages\", \"previous_response_id\", \"prompt_cache_key\"].includes(key)) continue;\n\t\t// Unknown payload extensions may contain private data or change the representation.\n\t\tif (!fields.has(key)) throw new Error(\"Unsupported context epoch request configuration\");\n\t\tconfiguration[key] = value;\n\t}\n\tconst input: unknown = \"input\" in body ? body.input : \"messages\" in body ? body.messages : undefined;\n\tif (!Array.isArray(input)) throw new Error(\"Context epoch request messages are unavailable\");\n\tconst policy = input.filter(\n\t\t(item: unknown) =>\n\t\t\titem && typeof item === \"object\" && \"role\" in item && (item.role === \"system\" || item.role === \"developer\"),\n\t);\n\treturn stringifyBoundedJson(\n\t\t{\n\t\t\trenderer: CONTEXT_EPOCH_RENDERER,\n\t\t\t...(responseItemIdentity ? { responseItemIdentity } : {}),\n\t\t\tapi: request.api,\n\t\t\tprovider: request.provider,\n\t\t\troute: identity.route,\n\t\t\tmodel: identity.model,\n\t\t\t...(assessment\n\t\t\t\t? {\n\t\t\t\t\t\tprofile: assessment.profile,\n\t\t\t\t\t\tcontextTokens: assessment.contextTokens,\n\t\t\t\t\t\toutputReserveTokens: assessment.outputReserveTokens,\n\t\t\t\t\t}\n\t\t\t\t: { budget: \"unbudgeted\" }),\n\t\t\tconfiguration,\n\t\t\tpolicy,\n\t\t},\n\t\tmaxBytes,\n\t);\n}\n"]}
@@ -11,6 +11,8 @@ export const CONTEXT_TOOL_EPOCH_RENDERER = "native-canonical-epoch/6";
11
11
  export const CONTEXT_SKILL_EPOCH_RENDERER = "native-canonical-epoch/7";
12
12
  /** Source-backed summary with retained public tool groups, not a measured MAIN request. */
13
13
  export const CONTEXT_TOOL_SUMMARY_RENDERER = "native-canonical-epoch/8";
14
+ /** Public recipes may record absent admission, never a fabricated execution outcome. */
15
+ export const CONTEXT_INTERRUPTED_TOOL_RENDERER = "native-canonical-epoch/9";
14
16
  export function contextEpochMode(checkpoint, initial = "on") {
15
17
  return checkpoint ? (checkpoint.version === 5 || checkpoint.version === 8 ? checkpoint.mode : "on") : initial;
16
18
  }
@@ -86,8 +88,10 @@ export function readContextEpoch(details, maxBytes) {
86
88
  (value.version === 5 && value.renderer === CONTEXT_POLICY_EPOCH_RENDERER) ||
87
89
  (value.version === 6 && value.renderer === CONTEXT_TOOL_EPOCH_RENDERER) ||
88
90
  (value.version === 8 && value.renderer === CONTEXT_TOOL_SUMMARY_RENDERER) ||
91
+ ([6, 8].includes(value.version) && value.renderer === CONTEXT_INTERRUPTED_TOOL_RENDERER) ||
89
92
  ([4, 5, 6].includes(value.version) && value.renderer === CONTEXT_SKILL_EPOCH_RENDERER)) ||
90
- (value.renderer === CONTEXT_SKILL_EPOCH_RENDERER || (value.version === 8 && "selectedSkills" in value)
93
+ (value.renderer === CONTEXT_SKILL_EPOCH_RENDERER ||
94
+ ((value.version === 8 || value.renderer === CONTEXT_INTERRUPTED_TOOL_RENDERER) && "selectedSkills" in value)
91
95
  ? !("selectedSkills" in value) ||
92
96
  !Array.isArray(value.selectedSkills) ||
93
97
  value.selectedSkills.length === 0 ||
@@ -1 +1 @@
1
- {"version":3,"file":"context-epoch.js","sourceRoot":"","sources":["../../src/core/context-epo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AAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,GAAG,CAAC,UAAU;YACb,CAAC,CAAC;gBACA,OAAO,EAAE,UAAU,CAAC,OAAO;gBAC3B,aAAa,EAAE,UAAU,CAAC,aAAa;gBACvC,mBAAmB,EAAE,UAAU,CAAC,mBAAmB;aACnD;YACF,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;QAC5B,aAAa;QACb,MAAM;KACN,EACD,QAAQ,CACR,CAAC;AAAA,CACF","sourcesContent":["import type { ProviderRequestRepresentation, RequestTokenAssessment, Usage } from \"@ponythewhite/base-context-ai\";\nimport { requestTokenRouteIdentity } from \"@ponythewhite/base-context-ai\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ContextRef, IndexedSourceEvent } from \"./history-index.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport { MAX_RESOURCE_REVISION_BYTES } from \"./resource-view.js\";\nimport type { SelectedSkillReference } from \"./selected-skills.js\";\nimport type { CompiledTaskFrame } from \"./task-frame.js\";\n\nexport const CONTEXT_EPOCH_DETAIL = \"baseContextEpoch\";\n/** Internal admission, not a field accepted by ordinary appendCompaction callers. */\nexport const appendContextEpoch = Symbol(\"appendContextEpoch\");\nexport const CONTEXT_EPOCH_RENDERER = \"native-canonical-epoch/4\";\nexport const CONTEXT_POLICY_EPOCH_RENDERER = \"native-canonical-epoch/5\";\nexport const CONTEXT_TOOL_EPOCH_RENDERER = \"native-canonical-epoch/6\";\n/** Selection-bearing v4/v5/v6 variants; older readers must refuse rather than drop these refs. */\nexport const CONTEXT_SKILL_EPOCH_RENDERER = \"native-canonical-epoch/7\";\n/** Source-backed summary with retained public tool groups, not a measured MAIN request. */\nexport const CONTEXT_TOOL_SUMMARY_RENDERER = \"native-canonical-epoch/8\";\n\n/** Descriptive, source-backed outcomes in the existing accepted epoch, not an execution store. */\nexport interface ToolContinuationGroup {\n\treadonly assistantEntryId: string;\n\treadonly calls: readonly {\n\t\treadonly executionId: string;\n\t\treadonly intent: Pick<IndexedSourceEvent, \"id\" | \"sequence\" | \"revision\">;\n\t\treadonly outcome: \"outcome_unknown\" | \"not_started\" | \"completed\" | \"failed\";\n\t\treadonly result?: Pick<IndexedSourceEvent, \"id\" | \"sequence\" | \"revision\">;\n\t}[];\n}\nexport type ContextMode = \"on\" | \"off\";\n\n/** Compatibility retained from an accepted native request, not measurement or replay credit. */\nexport interface ContextEpochRequestContract {\n\treadonly api: string;\n\treadonly provider: string;\n\treadonly route: string;\n\treadonly model: string;\n\treadonly replayContract: ContextReplayContract;\n}\nexport type ContextReplayContract = \"complete-context\" | \"message-groups\";\n\n/** An ordinary summary and its retained source recipes share the existing compaction ACK. */\nexport interface ContextEpochSummary {\n\treadonly summary: string;\n\treadonly details?: Record<string, unknown>;\n\treadonly fromHook?: boolean;\n\treadonly customInstructions?: string;\n\treadonly usage?: Usage;\n}\n\n/** A frozen read recipe, not a second copy of an archived message body. */\nexport interface EpochViewReference {\n\treadonly source: SourceSnapshotRef;\n\treadonly ref: ContextRef;\n\treadonly sourceRevision: string;\n\t/** Present only for an existing rendered compaction summary. */\n\treadonly retainedMessageCount?: number;\n\treadonly rendering?: \"public-history/1\" | \"public-tool-continuation/1\";\n}\n\ninterface ContextEpochFields {\n\treadonly renderer:\n\t\t| \"native-canonical-epoch/1\"\n\t\t| \"native-canonical-epoch/2\"\n\t\t| \"native-canonical-epoch/3\"\n\t\t| typeof CONTEXT_EPOCH_RENDERER\n\t\t| typeof CONTEXT_POLICY_EPOCH_RENDERER\n\t\t| typeof CONTEXT_TOOL_EPOCH_RENDERER\n\t\t| typeof CONTEXT_SKILL_EPOCH_RENDERER\n\t\t| typeof CONTEXT_TOOL_SUMMARY_RENDERER;\n\treadonly source: SourceSnapshotRef;\n\treadonly includeSummary?: true;\n\t/** Granted by an actual accepted adapter projection, never a caller profile name. */\n\treadonly replayContract?: ContextReplayContract;\n\t/** Actual adapter permission to leave completed native groups for a fresh public window. */\n\treadonly publicWindow?: true;\n\t/** Frozen public transition. Later native messages are not silently converted. */\n\treadonly continuation?: {\n\t\treadonly kind: \"harness-summary\" | \"portable-checkpoint\";\n\t\treadonly publicTailThrough: SourceSnapshotRef;\n\t};\n\treadonly views: readonly EpochViewReference[];\n\t/** Captured versions, not a body cache or authority inferred from transcript markup. */\n\treadonly selectedSkills?: readonly SelectedSkillReference[];\n\t/** v6 requests and v8 summaries retain whole public groups and their exact outcome refs. */\n\treadonly toolContinuations?: readonly ToolContinuationGroup[];\n\t/** Derived display only. The task reducer remains the authority for later changes. */\n\treadonly taskFrame?: CompiledTaskFrame;\n\t/** Accepted-state comparison only; saved metadata never establishes current resource liveness. */\n\treadonly resourceRevision?: string;\n\treadonly literalTailId: string;\n}\n\n/** v5 policy-only null is a mode ACK, not an ordinary summary or a measured request. */\nexport type ContextEpochCheckpoint = ContextEpochFields &\n\t(\n\t\t| {\n\t\t\t\treadonly version: 1 | 2 | 3 | 4 | 6;\n\t\t\t\treadonly representation: string | null;\n\t\t\t\treadonly mode?: never;\n\t\t\t\treadonly policyOnly?: never;\n\t\t\t\treadonly requestContract?: never;\n\t\t\t\treadonly pendingRequestContract?: never;\n\t\t }\n\t\t| {\n\t\t\t\treadonly version: 8;\n\t\t\t\treadonly mode: ContextMode;\n\t\t\t\treadonly representation: null;\n\t\t\t\treadonly includeSummary: true;\n\t\t\t\treadonly policyOnly?: never;\n\t\t\t\treadonly requestContract?: never;\n\t\t\t\treadonly pendingRequestContract?: never;\n\t\t }\n\t\t| {\n\t\t\t\treadonly version: 5;\n\t\t\t\treadonly mode: ContextMode;\n\t\t\t\treadonly representation: null;\n\t\t\t\treadonly policyOnly: true;\n\t\t\t\treadonly includeSummary?: never;\n\t\t\t\treadonly requestContract?: ContextEpochRequestContract;\n\t\t\t\treadonly pendingRequestContract?: true;\n\t\t }\n\t);\n\nexport function contextEpochMode(\n\tcheckpoint: ContextEpochCheckpoint | undefined,\n\tinitial: ContextMode = \"on\",\n): ContextMode {\n\treturn checkpoint ? (checkpoint.version === 5 || checkpoint.version === 8 ? checkpoint.mode : \"on\") : initial;\n}\n\nfunction isRequestContract(value: unknown): value is ContextEpochRequestContract {\n\tif (!value || typeof value !== \"object\") return false;\n\treturn (\n\t\t[\"api\", \"provider\", \"route\", \"model\"].every(\n\t\t\t(key) =>\n\t\t\t\tkey in value &&\n\t\t\t\ttypeof (value as Record<string, unknown>)[key] === \"string\" &&\n\t\t\t\t(value as Record<string, unknown>)[key] !== \"\",\n\t\t) &&\n\t\t\"replayContract\" in value &&\n\t\t(value.replayContract === \"complete-context\" || value.replayContract === \"message-groups\")\n\t);\n}\n\n/** Only call with a qualified checkpoint, never raw compaction marker data. */\nexport function retainedContextRequestContract(\n\tcheckpoint: ContextEpochCheckpoint | undefined,\n): ContextEpochRequestContract | undefined {\n\tif (!checkpoint) return;\n\tif (checkpoint.requestContract) return structuredClone(checkpoint.requestContract);\n\tif (!checkpoint.representation) return;\n\tconst accepted: unknown = JSON.parse(checkpoint.representation);\n\tif (!accepted || typeof accepted !== \"object\") throw new Error(\"Accepted context request contract is unavailable\");\n\tconst value = { ...accepted, replayContract: checkpoint.replayContract ?? \"complete-context\" };\n\tif (!isRequestContract(value)) throw new Error(\"Accepted context request contract is unavailable\");\n\treturn {\n\t\tapi: value.api,\n\t\tprovider: value.provider,\n\t\troute: value.route,\n\t\tmodel: value.model,\n\t\treplayContract: value.replayContract,\n\t};\n}\n\n/** Identity comes from the actual final native serialization, not a model/profile label. */\nexport function contextRequestContract(\n\trequest: ProviderRequestRepresentation,\n\treplayContract: ContextReplayContract,\n): ContextEpochRequestContract {\n\tconst route = requestTokenRouteIdentity(request.url);\n\tconst body: unknown = request.body === undefined ? undefined : JSON.parse(request.body);\n\tif (\n\t\t!route ||\n\t\t!body ||\n\t\ttypeof body !== \"object\" ||\n\t\t!(\"model\" in body) ||\n\t\ttypeof body.model !== \"string\" ||\n\t\t!body.model\n\t)\n\t\tthrow new Error(\"Native context request identity is unavailable\");\n\treturn { api: request.api, provider: request.provider, route, model: body.model, replayContract };\n}\n\nexport function assertContextRequestContract(\n\tcontract: ContextEpochRequestContract,\n\trequest: ProviderRequestRepresentation,\n\treplayContract: ContextReplayContract,\n): void {\n\tconst actual = contextRequestContract(request, replayContract);\n\tif (\n\t\tactual.api !== contract.api ||\n\t\tactual.provider !== contract.provider ||\n\t\tactual.route !== contract.route ||\n\t\tactual.model !== contract.model ||\n\t\tactual.replayContract !== contract.replayContract\n\t)\n\t\tthrow new Error(\"Retained context requires its accepted native request contract\");\n}\n\nexport function snapshotContextEpoch<T extends ContextEpochCheckpoint>(value: T, maxBytes: number): T {\n\treturn JSON.parse(stringifyBoundedJson(value, maxBytes)) as T;\n}\n\n/** Called only after checking the source frame's genuine epoch qualification. */\nexport function readContextEpoch(details: unknown, maxBytes: number): ContextEpochCheckpoint | undefined {\n\tif (!details || typeof details !== \"object\" || !(CONTEXT_EPOCH_DETAIL in details)) return;\n\tconst value: unknown = details[CONTEXT_EPOCH_DETAIL];\n\tif (\n\t\t!value ||\n\t\ttypeof value !== \"object\" ||\n\t\t!(\"version\" in value) ||\n\t\t!(\"renderer\" in value) ||\n\t\t!(\n\t\t\t(value.version === 1 && value.renderer === \"native-canonical-epoch/1\") ||\n\t\t\t(value.version === 2 && value.renderer === \"native-canonical-epoch/2\") ||\n\t\t\t(value.version === 3 && value.renderer === \"native-canonical-epoch/3\") ||\n\t\t\t(value.version === 4 && value.renderer === \"native-canonical-epoch/4\") ||\n\t\t\t(value.version === 5 && value.renderer === CONTEXT_POLICY_EPOCH_RENDERER) ||\n\t\t\t(value.version === 6 && value.renderer === CONTEXT_TOOL_EPOCH_RENDERER) ||\n\t\t\t(value.version === 8 && value.renderer === CONTEXT_TOOL_SUMMARY_RENDERER) ||\n\t\t\t([4, 5, 6].includes(value.version as number) && value.renderer === CONTEXT_SKILL_EPOCH_RENDERER)\n\t\t) ||\n\t\t(value.renderer === CONTEXT_SKILL_EPOCH_RENDERER || (value.version === 8 && \"selectedSkills\" in value)\n\t\t\t? !(\"selectedSkills\" in value) ||\n\t\t\t\t!Array.isArray(value.selectedSkills) ||\n\t\t\t\tvalue.selectedSkills.length === 0 ||\n\t\t\t\tvalue.selectedSkills.some(\n\t\t\t\t\t(item) =>\n\t\t\t\t\t\t!item ||\n\t\t\t\t\t\ttypeof item.name !== \"string\" ||\n\t\t\t\t\t\t!item.view ||\n\t\t\t\t\t\t![\"custom_message\", \"custom\"].includes(item.view.ref?.kind) ||\n\t\t\t\t\t\ttypeof item.view.sourceRevision !== \"string\",\n\t\t\t\t) ||\n\t\t\t\tnew Set(value.selectedSkills.map((item) => item.name)).size !== value.selectedSkills.length\n\t\t\t: \"selectedSkills\" in value) ||\n\t\t!(\"source\" in value) ||\n\t\t!value.source ||\n\t\t!(\"views\" in value) ||\n\t\t!Array.isArray(value.views) ||\n\t\t!(\"literalTailId\" in value) ||\n\t\ttypeof value.literalTailId !== \"string\" ||\n\t\t!(\"representation\" in value) ||\n\t\t(value.version === 5 || value.version === 8\n\t\t\t? !(\"mode\" in value) || (value.mode !== \"on\" && value.mode !== \"off\")\n\t\t\t: \"mode\" in value) ||\n\t\t(value.version === 8 &&\n\t\t\t(value.representation !== null || !(\"includeSummary\" in value) || value.includeSummary !== true)) ||\n\t\t(value.version === 5 &&\n\t\t\t(value.representation !== null || !(\"policyOnly\" in value) || value.policyOnly !== true)) ||\n\t\t(\"policyOnly\" in value &&\n\t\t\t(value.version !== 5 ||\n\t\t\t\tvalue.policyOnly !== true ||\n\t\t\t\tvalue.representation !== null ||\n\t\t\t\t\"includeSummary\" in value)) ||\n\t\t(\"pendingRequestContract\" in value &&\n\t\t\t(value.version !== 5 ||\n\t\t\t\t!(\"mode\" in value) ||\n\t\t\t\tvalue.mode !== \"off\" ||\n\t\t\t\tvalue.pendingRequestContract !== true ||\n\t\t\t\t\"requestContract\" in value)) ||\n\t\t(\"requestContract\" in value && (value.version !== 5 || !isRequestContract(value.requestContract))) ||\n\t\t!(\n\t\t\ttypeof value.representation === \"string\" ||\n\t\t\t(value.version === 5 && value.representation === null && \"policyOnly\" in value && value.policyOnly === true) ||\n\t\t\t((value.version === 2 || value.version === 3 || value.version === 4 || value.version === 8) &&\n\t\t\t\tvalue.representation === null &&\n\t\t\t\t\"includeSummary\" in value &&\n\t\t\t\tvalue.includeSummary === true)\n\t\t) ||\n\t\t(\"includeSummary\" in value &&\n\t\t\t((value.version !== 2 && value.version !== 3 && value.version !== 4 && value.version !== 8) ||\n\t\t\t\tvalue.includeSummary !== true ||\n\t\t\t\tvalue.representation !== null)) ||\n\t\t(\"replayContract\" in value &&\n\t\t\tvalue.replayContract !== \"complete-context\" &&\n\t\t\tvalue.replayContract !== \"message-groups\") ||\n\t\t(\"resourceRevision\" in value &&\n\t\t\t(typeof value.resourceRevision !== \"string\" ||\n\t\t\t\tBuffer.byteLength(value.resourceRevision, \"utf8\") > MAX_RESOURCE_REVISION_BYTES)) ||\n\t\t(\"publicWindow\" in value &&\n\t\t\t((value.version !== 3 &&\n\t\t\t\tvalue.version !== 4 &&\n\t\t\t\tvalue.version !== 5 &&\n\t\t\t\tvalue.version !== 6 &&\n\t\t\t\tvalue.version !== 8) ||\n\t\t\t\tvalue.publicWindow !== true)) ||\n\t\t(\"toolContinuations\" in value && value.version !== 6 && value.version !== 8) ||\n\t\t((value.version === 6 || value.version === 8) &&\n\t\t\t(!(\"toolContinuations\" in value) ||\n\t\t\t\t!Array.isArray(value.toolContinuations) ||\n\t\t\t\t!value.toolContinuations.length ||\n\t\t\t\t!(\"replayContract\" in value) ||\n\t\t\t\t(value.version === 6 &&\n\t\t\t\t\t(!(\"publicWindow\" in value) ||\n\t\t\t\t\t\tvalue.publicWindow !== true ||\n\t\t\t\t\t\tvalue.replayContract !== \"message-groups\")))) ||\n\t\t(\"continuation\" in value &&\n\t\t\t((value.version !== 3 &&\n\t\t\t\tvalue.version !== 4 &&\n\t\t\t\tvalue.version !== 5 &&\n\t\t\t\tvalue.version !== 6 &&\n\t\t\t\tvalue.version !== 8) ||\n\t\t\t\t!value.continuation ||\n\t\t\t\ttypeof value.continuation !== \"object\" ||\n\t\t\t\t!(\"kind\" in value.continuation) ||\n\t\t\t\t(value.continuation.kind !== \"harness-summary\" &&\n\t\t\t\t\t((value.version !== 4 && value.version !== 5 && value.version !== 6) ||\n\t\t\t\t\t\tvalue.continuation.kind !== \"portable-checkpoint\")) ||\n\t\t\t\t!(\"publicTailThrough\" in value.continuation) ||\n\t\t\t\t!value.continuation.publicTailThrough))\n\t)\n\t\tthrow new Error(\"Invalid committed context epoch\");\n\treturn snapshotContextEpoch(value as ContextEpochCheckpoint, maxBytes);\n}\n\n/** Stable representation, not the changing input, an auth envelope, or a cache-hit claim. */\nexport function contextEpochRepresentation(\n\trequest: ProviderRequestRepresentation,\n\tassessment: RequestTokenAssessment | undefined,\n\tmaxBytes: number,\n\tunbudgetedPublic = false,\n\tresponseItemIdentity?: string,\n): string {\n\tif (\n\t\t(!assessment && !unbudgetedPublic) ||\n\t\t(assessment &&\n\t\t\t(!assessment.profile ||\n\t\t\t\tassessment.limitSource !== \"explicit-profile\" ||\n\t\t\t\t!assessment.route ||\n\t\t\t\t!assessment.model)) ||\n\t\trequest.body === undefined\n\t)\n\t\tthrow new Error(\"Committed context epoch requires its explicit request profile\");\n\tconst identity = assessment ?? contextRequestContract(request, \"message-groups\");\n\tconst body: unknown = JSON.parse(request.body);\n\tif (!body || typeof body !== \"object\" || Array.isArray(body))\n\t\tthrow new Error(\"Context epoch request representation is unavailable\");\n\tconst configuration: Record<string, unknown> = {};\n\tconst fields = new Set([\n\t\t\"model\",\n\t\t\"instructions\",\n\t\t\"stream\",\n\t\t\"max_output_tokens\",\n\t\t\"max_tokens\",\n\t\t\"max_completion_tokens\",\n\t\t\"temperature\",\n\t\t\"top_p\",\n\t\t\"text\",\n\t\t\"tools\",\n\t\t\"tool_choice\",\n\t\t\"parallel_tool_calls\",\n\t\t\"store\",\n\t\t\"reasoning\",\n\t\t\"service_tier\",\n\t\t\"truncation\",\n\t\t\"include\",\n\t\t\"prompt_cache_retention\",\n\t\t\"stream_options\",\n\t]);\n\tif (\n\t\trequest.api === \"openai-completions\" &&\n\t\trequest.provider === \"deepseek\" &&\n\t\trequest.url === \"https://api.deepseek.com/chat/completions\" &&\n\t\tidentity.route === request.url &&\n\t\t\"model\" in body &&\n\t\tbody.model === \"deepseek-flash\" &&\n\t\tidentity.model === body.model\n\t) {\n\t\tfields.add(\"thinking\");\n\t\tfields.add(\"reasoning_effort\");\n\t}\n\tfor (const [key, value] of Object.entries(body)) {\n\t\tif ([\"input\", \"messages\", \"previous_response_id\", \"prompt_cache_key\"].includes(key)) continue;\n\t\t// Unknown payload extensions may contain private data or change the representation.\n\t\tif (!fields.has(key)) throw new Error(\"Unsupported context epoch request configuration\");\n\t\tconfiguration[key] = value;\n\t}\n\tconst input: unknown = \"input\" in body ? body.input : \"messages\" in body ? body.messages : undefined;\n\tif (!Array.isArray(input)) throw new Error(\"Context epoch request messages are unavailable\");\n\tconst policy = input.filter(\n\t\t(item: unknown) =>\n\t\t\titem && typeof item === \"object\" && \"role\" in item && (item.role === \"system\" || item.role === \"developer\"),\n\t);\n\treturn stringifyBoundedJson(\n\t\t{\n\t\t\trenderer: CONTEXT_EPOCH_RENDERER,\n\t\t\t...(responseItemIdentity ? { responseItemIdentity } : {}),\n\t\t\tapi: request.api,\n\t\t\tprovider: request.provider,\n\t\t\troute: identity.route,\n\t\t\tmodel: identity.model,\n\t\t\t...(assessment\n\t\t\t\t? {\n\t\t\t\t\t\tprofile: assessment.profile,\n\t\t\t\t\t\tcontextTokens: assessment.contextTokens,\n\t\t\t\t\t\toutputReserveTokens: assessment.outputReserveTokens,\n\t\t\t\t\t}\n\t\t\t\t: { budget: \"unbudgeted\" }),\n\t\t\tconfiguration,\n\t\t\tpolicy,\n\t\t},\n\t\tmaxBytes,\n\t);\n}\n"]}
1
+ {"version":3,"file":"context-epoch.js","sourceRoot":"","sources":["../../src/core/context-epoch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAIjE,MAAM,CAAC,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AACvD,qFAAqF;AACrF,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAC/D,MAAM,CAAC,MAAM,sBAAsB,GAAG,0BAA0B,CAAC;AACjE,MAAM,CAAC,MAAM,6BAA6B,GAAG,0BAA0B,CAAC;AACxE,MAAM,CAAC,MAAM,2BAA2B,GAAG,0BAA0B,CAAC;AACtE,kGAAkG;AAClG,MAAM,CAAC,MAAM,4BAA4B,GAAG,0BAA0B,CAAC;AACvE,2FAA2F;AAC3F,MAAM,CAAC,MAAM,6BAA6B,GAAG,0BAA0B,CAAC;AACxE,wFAAwF;AACxF,MAAM,CAAC,MAAM,iCAAiC,GAAG,0BAA0B,CAAC;AAwH5E,MAAM,UAAU,gBAAgB,CAC/B,UAA8C,EAC9C,OAAO,GAAgB,IAAI,EACb;IACd,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,IAAI,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAAA,CAC9G;AAED,SAAS,iBAAiB,CAAC,KAAc,EAAwC;IAChF,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,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CAAC,CAAC,SAAS,CAAC;IACrG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAC7F,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAC1B,CAAC,IAAa,EAAE,EAAE,CACjB,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC,CAC5G,CAAC;IACF,OAAO,oBAAoB,CAC1B;QACC,QAAQ,EAAE,sBAAsB;QAChC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,GAAG,CAAC,UAAU;YACb,CAAC,CAAC;gBACA,OAAO,EAAE,UAAU,CAAC,OAAO;gBAC3B,aAAa,EAAE,UAAU,CAAC,aAAa;gBACvC,mBAAmB,EAAE,UAAU,CAAC,mBAAmB;aACnD;YACF,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;QAC5B,aAAa;QACb,MAAM;KACN,EACD,QAAQ,CACR,CAAC;AAAA,CACF","sourcesContent":["import type { ProviderRequestRepresentation, RequestTokenAssessment, Usage } from \"@ponythewhite/base-context-ai\";\nimport { requestTokenRouteIdentity } from \"@ponythewhite/base-context-ai\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ContextRef, IndexedSourceEvent } from \"./history-index.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport { MAX_RESOURCE_REVISION_BYTES } from \"./resource-view.js\";\nimport type { SelectedSkillReference } from \"./selected-skills.js\";\nimport type { CompiledTaskFrame } from \"./task-frame.js\";\n\nexport const CONTEXT_EPOCH_DETAIL = \"baseContextEpoch\";\n/** Internal admission, not a field accepted by ordinary appendCompaction callers. */\nexport const appendContextEpoch = Symbol(\"appendContextEpoch\");\nexport const CONTEXT_EPOCH_RENDERER = \"native-canonical-epoch/4\";\nexport const CONTEXT_POLICY_EPOCH_RENDERER = \"native-canonical-epoch/5\";\nexport const CONTEXT_TOOL_EPOCH_RENDERER = \"native-canonical-epoch/6\";\n/** Selection-bearing v4/v5/v6 variants; older readers must refuse rather than drop these refs. */\nexport const CONTEXT_SKILL_EPOCH_RENDERER = \"native-canonical-epoch/7\";\n/** Source-backed summary with retained public tool groups, not a measured MAIN request. */\nexport const CONTEXT_TOOL_SUMMARY_RENDERER = \"native-canonical-epoch/8\";\n/** Public recipes may record absent admission, never a fabricated execution outcome. */\nexport const CONTEXT_INTERRUPTED_TOOL_RENDERER = \"native-canonical-epoch/9\";\n\n/** Descriptive, source-backed outcomes in the existing accepted epoch, not an execution store. */\nexport interface ToolContinuationGroup {\n\treadonly assistantEntryId: string;\n\treadonly calls: readonly (\n\t\t| {\n\t\t\t\treadonly admission?: never;\n\t\t\t\treadonly executionId: string;\n\t\t\t\treadonly intent: Pick<IndexedSourceEvent, \"id\" | \"sequence\" | \"revision\">;\n\t\t\t\treadonly outcome: \"outcome_unknown\" | \"not_started\" | \"completed\" | \"failed\";\n\t\t\t\treadonly result?: Pick<IndexedSourceEvent, \"id\" | \"sequence\" | \"revision\">;\n\t\t }\n\t\t| {\n\t\t\t\treadonly admission: \"absent\";\n\t\t\t\t/** Absence is scoped to this exact captured branch prefix, not external effects. */\n\t\t\t\treadonly source: SourceSnapshotRef;\n\t\t\t\treadonly executionId?: never;\n\t\t\t\treadonly intent?: never;\n\t\t\t\treadonly outcome?: never;\n\t\t\t\treadonly result?: never;\n\t\t }\n\t)[];\n}\nexport type ContextMode = \"on\" | \"off\";\n\n/** Compatibility retained from an accepted native request, not measurement or replay credit. */\nexport interface ContextEpochRequestContract {\n\treadonly api: string;\n\treadonly provider: string;\n\treadonly route: string;\n\treadonly model: string;\n\treadonly replayContract: ContextReplayContract;\n}\nexport type ContextReplayContract = \"complete-context\" | \"message-groups\";\n\n/** An ordinary summary and its retained source recipes share the existing compaction ACK. */\nexport interface ContextEpochSummary {\n\treadonly summary: string;\n\treadonly details?: Record<string, unknown>;\n\treadonly fromHook?: boolean;\n\treadonly customInstructions?: string;\n\treadonly usage?: Usage;\n}\n\n/** A frozen read recipe, not a second copy of an archived message body. */\nexport interface EpochViewReference {\n\treadonly source: SourceSnapshotRef;\n\treadonly ref: ContextRef;\n\treadonly sourceRevision: string;\n\t/** Present only for an existing rendered compaction summary. */\n\treadonly retainedMessageCount?: number;\n\treadonly rendering?: \"public-history/1\" | \"public-tool-continuation/1\";\n}\n\ninterface ContextEpochFields {\n\treadonly renderer:\n\t\t| \"native-canonical-epoch/1\"\n\t\t| \"native-canonical-epoch/2\"\n\t\t| \"native-canonical-epoch/3\"\n\t\t| typeof CONTEXT_EPOCH_RENDERER\n\t\t| typeof CONTEXT_POLICY_EPOCH_RENDERER\n\t\t| typeof CONTEXT_TOOL_EPOCH_RENDERER\n\t\t| typeof CONTEXT_SKILL_EPOCH_RENDERER\n\t\t| typeof CONTEXT_TOOL_SUMMARY_RENDERER\n\t\t| typeof CONTEXT_INTERRUPTED_TOOL_RENDERER;\n\treadonly source: SourceSnapshotRef;\n\treadonly includeSummary?: true;\n\t/** Granted by an actual accepted adapter projection, never a caller profile name. */\n\treadonly replayContract?: ContextReplayContract;\n\t/** Actual adapter permission to leave completed native groups for a fresh public window. */\n\treadonly publicWindow?: true;\n\t/** Frozen public transition. Later native messages are not silently converted. */\n\treadonly continuation?: {\n\t\treadonly kind: \"harness-summary\" | \"portable-checkpoint\";\n\t\treadonly publicTailThrough: SourceSnapshotRef;\n\t};\n\treadonly views: readonly EpochViewReference[];\n\t/** Captured versions, not a body cache or authority inferred from transcript markup. */\n\treadonly selectedSkills?: readonly SelectedSkillReference[];\n\t/** v6 requests and v8 summaries retain whole public groups and their exact outcome refs. */\n\treadonly toolContinuations?: readonly ToolContinuationGroup[];\n\t/** Derived display only. The task reducer remains the authority for later changes. */\n\treadonly taskFrame?: CompiledTaskFrame;\n\t/** Accepted-state comparison only; saved metadata never establishes current resource liveness. */\n\treadonly resourceRevision?: string;\n\treadonly literalTailId: string;\n}\n\n/** v5 policy-only null is a mode ACK, not an ordinary summary or a measured request. */\nexport type ContextEpochCheckpoint = ContextEpochFields &\n\t(\n\t\t| {\n\t\t\t\treadonly version: 1 | 2 | 3 | 4 | 6;\n\t\t\t\treadonly representation: string | null;\n\t\t\t\treadonly mode?: never;\n\t\t\t\treadonly policyOnly?: never;\n\t\t\t\treadonly requestContract?: never;\n\t\t\t\treadonly pendingRequestContract?: never;\n\t\t }\n\t\t| {\n\t\t\t\treadonly version: 8;\n\t\t\t\treadonly mode: ContextMode;\n\t\t\t\treadonly representation: null;\n\t\t\t\treadonly includeSummary: true;\n\t\t\t\treadonly policyOnly?: never;\n\t\t\t\treadonly requestContract?: never;\n\t\t\t\treadonly pendingRequestContract?: never;\n\t\t }\n\t\t| {\n\t\t\t\treadonly version: 5;\n\t\t\t\treadonly mode: ContextMode;\n\t\t\t\treadonly representation: null;\n\t\t\t\treadonly policyOnly: true;\n\t\t\t\treadonly includeSummary?: never;\n\t\t\t\treadonly requestContract?: ContextEpochRequestContract;\n\t\t\t\treadonly pendingRequestContract?: true;\n\t\t }\n\t);\n\nexport function contextEpochMode(\n\tcheckpoint: ContextEpochCheckpoint | undefined,\n\tinitial: ContextMode = \"on\",\n): ContextMode {\n\treturn checkpoint ? (checkpoint.version === 5 || checkpoint.version === 8 ? checkpoint.mode : \"on\") : initial;\n}\n\nfunction isRequestContract(value: unknown): value is ContextEpochRequestContract {\n\tif (!value || typeof value !== \"object\") return false;\n\treturn (\n\t\t[\"api\", \"provider\", \"route\", \"model\"].every(\n\t\t\t(key) =>\n\t\t\t\tkey in value &&\n\t\t\t\ttypeof (value as Record<string, unknown>)[key] === \"string\" &&\n\t\t\t\t(value as Record<string, unknown>)[key] !== \"\",\n\t\t) &&\n\t\t\"replayContract\" in value &&\n\t\t(value.replayContract === \"complete-context\" || value.replayContract === \"message-groups\")\n\t);\n}\n\n/** Only call with a qualified checkpoint, never raw compaction marker data. */\nexport function retainedContextRequestContract(\n\tcheckpoint: ContextEpochCheckpoint | undefined,\n): ContextEpochRequestContract | undefined {\n\tif (!checkpoint) return;\n\tif (checkpoint.requestContract) return structuredClone(checkpoint.requestContract);\n\tif (!checkpoint.representation) return;\n\tconst accepted: unknown = JSON.parse(checkpoint.representation);\n\tif (!accepted || typeof accepted !== \"object\") throw new Error(\"Accepted context request contract is unavailable\");\n\tconst value = { ...accepted, replayContract: checkpoint.replayContract ?? \"complete-context\" };\n\tif (!isRequestContract(value)) throw new Error(\"Accepted context request contract is unavailable\");\n\treturn {\n\t\tapi: value.api,\n\t\tprovider: value.provider,\n\t\troute: value.route,\n\t\tmodel: value.model,\n\t\treplayContract: value.replayContract,\n\t};\n}\n\n/** Identity comes from the actual final native serialization, not a model/profile label. */\nexport function contextRequestContract(\n\trequest: ProviderRequestRepresentation,\n\treplayContract: ContextReplayContract,\n): ContextEpochRequestContract {\n\tconst route = requestTokenRouteIdentity(request.url);\n\tconst body: unknown = request.body === undefined ? undefined : JSON.parse(request.body);\n\tif (\n\t\t!route ||\n\t\t!body ||\n\t\ttypeof body !== \"object\" ||\n\t\t!(\"model\" in body) ||\n\t\ttypeof body.model !== \"string\" ||\n\t\t!body.model\n\t)\n\t\tthrow new Error(\"Native context request identity is unavailable\");\n\treturn { api: request.api, provider: request.provider, route, model: body.model, replayContract };\n}\n\nexport function assertContextRequestContract(\n\tcontract: ContextEpochRequestContract,\n\trequest: ProviderRequestRepresentation,\n\treplayContract: ContextReplayContract,\n): void {\n\tconst actual = contextRequestContract(request, replayContract);\n\tif (\n\t\tactual.api !== contract.api ||\n\t\tactual.provider !== contract.provider ||\n\t\tactual.route !== contract.route ||\n\t\tactual.model !== contract.model ||\n\t\tactual.replayContract !== contract.replayContract\n\t)\n\t\tthrow new Error(\"Retained context requires its accepted native request contract\");\n}\n\nexport function snapshotContextEpoch<T extends ContextEpochCheckpoint>(value: T, maxBytes: number): T {\n\treturn JSON.parse(stringifyBoundedJson(value, maxBytes)) as T;\n}\n\n/** Called only after checking the source frame's genuine epoch qualification. */\nexport function readContextEpoch(details: unknown, maxBytes: number): ContextEpochCheckpoint | undefined {\n\tif (!details || typeof details !== \"object\" || !(CONTEXT_EPOCH_DETAIL in details)) return;\n\tconst value: unknown = details[CONTEXT_EPOCH_DETAIL];\n\tif (\n\t\t!value ||\n\t\ttypeof value !== \"object\" ||\n\t\t!(\"version\" in value) ||\n\t\t!(\"renderer\" in value) ||\n\t\t!(\n\t\t\t(value.version === 1 && value.renderer === \"native-canonical-epoch/1\") ||\n\t\t\t(value.version === 2 && value.renderer === \"native-canonical-epoch/2\") ||\n\t\t\t(value.version === 3 && value.renderer === \"native-canonical-epoch/3\") ||\n\t\t\t(value.version === 4 && value.renderer === \"native-canonical-epoch/4\") ||\n\t\t\t(value.version === 5 && value.renderer === CONTEXT_POLICY_EPOCH_RENDERER) ||\n\t\t\t(value.version === 6 && value.renderer === CONTEXT_TOOL_EPOCH_RENDERER) ||\n\t\t\t(value.version === 8 && value.renderer === CONTEXT_TOOL_SUMMARY_RENDERER) ||\n\t\t\t([6, 8].includes(value.version as number) && value.renderer === CONTEXT_INTERRUPTED_TOOL_RENDERER) ||\n\t\t\t([4, 5, 6].includes(value.version as number) && value.renderer === CONTEXT_SKILL_EPOCH_RENDERER)\n\t\t) ||\n\t\t(value.renderer === CONTEXT_SKILL_EPOCH_RENDERER ||\n\t\t((value.version === 8 || value.renderer === CONTEXT_INTERRUPTED_TOOL_RENDERER) && \"selectedSkills\" in value)\n\t\t\t? !(\"selectedSkills\" in value) ||\n\t\t\t\t!Array.isArray(value.selectedSkills) ||\n\t\t\t\tvalue.selectedSkills.length === 0 ||\n\t\t\t\tvalue.selectedSkills.some(\n\t\t\t\t\t(item) =>\n\t\t\t\t\t\t!item ||\n\t\t\t\t\t\ttypeof item.name !== \"string\" ||\n\t\t\t\t\t\t!item.view ||\n\t\t\t\t\t\t![\"custom_message\", \"custom\"].includes(item.view.ref?.kind) ||\n\t\t\t\t\t\ttypeof item.view.sourceRevision !== \"string\",\n\t\t\t\t) ||\n\t\t\t\tnew Set(value.selectedSkills.map((item) => item.name)).size !== value.selectedSkills.length\n\t\t\t: \"selectedSkills\" in value) ||\n\t\t!(\"source\" in value) ||\n\t\t!value.source ||\n\t\t!(\"views\" in value) ||\n\t\t!Array.isArray(value.views) ||\n\t\t!(\"literalTailId\" in value) ||\n\t\ttypeof value.literalTailId !== \"string\" ||\n\t\t!(\"representation\" in value) ||\n\t\t(value.version === 5 || value.version === 8\n\t\t\t? !(\"mode\" in value) || (value.mode !== \"on\" && value.mode !== \"off\")\n\t\t\t: \"mode\" in value) ||\n\t\t(value.version === 8 &&\n\t\t\t(value.representation !== null || !(\"includeSummary\" in value) || value.includeSummary !== true)) ||\n\t\t(value.version === 5 &&\n\t\t\t(value.representation !== null || !(\"policyOnly\" in value) || value.policyOnly !== true)) ||\n\t\t(\"policyOnly\" in value &&\n\t\t\t(value.version !== 5 ||\n\t\t\t\tvalue.policyOnly !== true ||\n\t\t\t\tvalue.representation !== null ||\n\t\t\t\t\"includeSummary\" in value)) ||\n\t\t(\"pendingRequestContract\" in value &&\n\t\t\t(value.version !== 5 ||\n\t\t\t\t!(\"mode\" in value) ||\n\t\t\t\tvalue.mode !== \"off\" ||\n\t\t\t\tvalue.pendingRequestContract !== true ||\n\t\t\t\t\"requestContract\" in value)) ||\n\t\t(\"requestContract\" in value && (value.version !== 5 || !isRequestContract(value.requestContract))) ||\n\t\t!(\n\t\t\ttypeof value.representation === \"string\" ||\n\t\t\t(value.version === 5 && value.representation === null && \"policyOnly\" in value && value.policyOnly === true) ||\n\t\t\t((value.version === 2 || value.version === 3 || value.version === 4 || value.version === 8) &&\n\t\t\t\tvalue.representation === null &&\n\t\t\t\t\"includeSummary\" in value &&\n\t\t\t\tvalue.includeSummary === true)\n\t\t) ||\n\t\t(\"includeSummary\" in value &&\n\t\t\t((value.version !== 2 && value.version !== 3 && value.version !== 4 && value.version !== 8) ||\n\t\t\t\tvalue.includeSummary !== true ||\n\t\t\t\tvalue.representation !== null)) ||\n\t\t(\"replayContract\" in value &&\n\t\t\tvalue.replayContract !== \"complete-context\" &&\n\t\t\tvalue.replayContract !== \"message-groups\") ||\n\t\t(\"resourceRevision\" in value &&\n\t\t\t(typeof value.resourceRevision !== \"string\" ||\n\t\t\t\tBuffer.byteLength(value.resourceRevision, \"utf8\") > MAX_RESOURCE_REVISION_BYTES)) ||\n\t\t(\"publicWindow\" in value &&\n\t\t\t((value.version !== 3 &&\n\t\t\t\tvalue.version !== 4 &&\n\t\t\t\tvalue.version !== 5 &&\n\t\t\t\tvalue.version !== 6 &&\n\t\t\t\tvalue.version !== 8) ||\n\t\t\t\tvalue.publicWindow !== true)) ||\n\t\t(\"toolContinuations\" in value && value.version !== 6 && value.version !== 8) ||\n\t\t((value.version === 6 || value.version === 8) &&\n\t\t\t(!(\"toolContinuations\" in value) ||\n\t\t\t\t!Array.isArray(value.toolContinuations) ||\n\t\t\t\t!value.toolContinuations.length ||\n\t\t\t\t!(\"replayContract\" in value) ||\n\t\t\t\t(value.version === 6 &&\n\t\t\t\t\t(!(\"publicWindow\" in value) ||\n\t\t\t\t\t\tvalue.publicWindow !== true ||\n\t\t\t\t\t\tvalue.replayContract !== \"message-groups\")))) ||\n\t\t(\"continuation\" in value &&\n\t\t\t((value.version !== 3 &&\n\t\t\t\tvalue.version !== 4 &&\n\t\t\t\tvalue.version !== 5 &&\n\t\t\t\tvalue.version !== 6 &&\n\t\t\t\tvalue.version !== 8) ||\n\t\t\t\t!value.continuation ||\n\t\t\t\ttypeof value.continuation !== \"object\" ||\n\t\t\t\t!(\"kind\" in value.continuation) ||\n\t\t\t\t(value.continuation.kind !== \"harness-summary\" &&\n\t\t\t\t\t((value.version !== 4 && value.version !== 5 && value.version !== 6) ||\n\t\t\t\t\t\tvalue.continuation.kind !== \"portable-checkpoint\")) ||\n\t\t\t\t!(\"publicTailThrough\" in value.continuation) ||\n\t\t\t\t!value.continuation.publicTailThrough))\n\t)\n\t\tthrow new Error(\"Invalid committed context epoch\");\n\treturn snapshotContextEpoch(value as ContextEpochCheckpoint, maxBytes);\n}\n\n/** Stable representation, not the changing input, an auth envelope, or a cache-hit claim. */\nexport function contextEpochRepresentation(\n\trequest: ProviderRequestRepresentation,\n\tassessment: RequestTokenAssessment | undefined,\n\tmaxBytes: number,\n\tunbudgetedPublic = false,\n\tresponseItemIdentity?: string,\n): string {\n\tif (\n\t\t(!assessment && !unbudgetedPublic) ||\n\t\t(assessment &&\n\t\t\t(!assessment.profile ||\n\t\t\t\tassessment.limitSource !== \"explicit-profile\" ||\n\t\t\t\t!assessment.route ||\n\t\t\t\t!assessment.model)) ||\n\t\trequest.body === undefined\n\t)\n\t\tthrow new Error(\"Committed context epoch requires its explicit request profile\");\n\tconst identity = assessment ?? contextRequestContract(request, \"message-groups\");\n\tconst body: unknown = JSON.parse(request.body);\n\tif (!body || typeof body !== \"object\" || Array.isArray(body))\n\t\tthrow new Error(\"Context epoch request representation is unavailable\");\n\tconst configuration: Record<string, unknown> = {};\n\tconst fields = new Set([\n\t\t\"model\",\n\t\t\"instructions\",\n\t\t\"stream\",\n\t\t\"max_output_tokens\",\n\t\t\"max_tokens\",\n\t\t\"max_completion_tokens\",\n\t\t\"temperature\",\n\t\t\"top_p\",\n\t\t\"text\",\n\t\t\"tools\",\n\t\t\"tool_choice\",\n\t\t\"parallel_tool_calls\",\n\t\t\"store\",\n\t\t\"reasoning\",\n\t\t\"service_tier\",\n\t\t\"truncation\",\n\t\t\"include\",\n\t\t\"prompt_cache_retention\",\n\t\t\"stream_options\",\n\t]);\n\tif (\n\t\trequest.api === \"openai-completions\" &&\n\t\trequest.provider === \"deepseek\" &&\n\t\trequest.url === \"https://api.deepseek.com/chat/completions\" &&\n\t\tidentity.route === request.url &&\n\t\t\"model\" in body &&\n\t\tbody.model === \"deepseek-flash\" &&\n\t\tidentity.model === body.model\n\t) {\n\t\tfields.add(\"thinking\");\n\t\tfields.add(\"reasoning_effort\");\n\t}\n\tfor (const [key, value] of Object.entries(body)) {\n\t\tif ([\"input\", \"messages\", \"previous_response_id\", \"prompt_cache_key\"].includes(key)) continue;\n\t\t// Unknown payload extensions may contain private data or change the representation.\n\t\tif (!fields.has(key)) throw new Error(\"Unsupported context epoch request configuration\");\n\t\tconfiguration[key] = value;\n\t}\n\tconst input: unknown = \"input\" in body ? body.input : \"messages\" in body ? body.messages : undefined;\n\tif (!Array.isArray(input)) throw new Error(\"Context epoch request messages are unavailable\");\n\tconst policy = input.filter(\n\t\t(item: unknown) =>\n\t\t\titem && typeof item === \"object\" && \"role\" in item && (item.role === \"system\" || item.role === \"developer\"),\n\t);\n\treturn stringifyBoundedJson(\n\t\t{\n\t\t\trenderer: CONTEXT_EPOCH_RENDERER,\n\t\t\t...(responseItemIdentity ? { responseItemIdentity } : {}),\n\t\t\tapi: request.api,\n\t\t\tprovider: request.provider,\n\t\t\troute: identity.route,\n\t\t\tmodel: identity.model,\n\t\t\t...(assessment\n\t\t\t\t? {\n\t\t\t\t\t\tprofile: assessment.profile,\n\t\t\t\t\t\tcontextTokens: assessment.contextTokens,\n\t\t\t\t\t\toutputReserveTokens: assessment.outputReserveTokens,\n\t\t\t\t\t}\n\t\t\t\t: { budget: \"unbudgeted\" }),\n\t\t\tconfiguration,\n\t\t\tpolicy,\n\t\t},\n\t\tmaxBytes,\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"public-context.d.ts","sourceRoot":"","sources":["../../src/core/public-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAgB7D,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAC1D,eAAO,MAAM,iCAAiC,+BAA+B,CAAC;AAE9E,uGAAuG;AACvG,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,qBAAqB,EAC5B,QAAQ,EAAE,MAAM,GACd,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAwCrC;AAED,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAuC1G","sourcesContent":["import type { AgentMessage } from \"@ponythewhite/base-context-agent\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ToolContinuationGroup } from \"./context-epoch.js\";\nimport type { CustomMessage } from \"./messages.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport { retainedToolOutput } from \"./retained-tool-output.js\";\n\nfunction retainedRecovery(message: AgentMessage, entryId: string) {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst retained = retainedToolOutput((message.details as { retainedOutput?: unknown } | undefined)?.retainedOutput);\n\treturn retained\n\t\t? {\n\t\t\t\tref: entryId,\n\t\t\t\tfield: retained.field,\n\t\t\t\tbyteLength: retained.byteLength,\n\t\t\t\tcaptureComplete: retained.captureComplete,\n\t\t\t}\n\t\t: undefined;\n}\n\nexport const PUBLIC_CONTEXT_RENDERER = \"public-history/1\";\nexport const PUBLIC_TOOL_CONTINUATION_RENDERER = \"public-tool-continuation/1\";\n\n/** Original public text and minimal recorded facts. Intent ACK says nothing about external effects. */\nexport function renderToolContinuation(\n\tmessage: AgentMessage,\n\tentryId: string,\n\tsource: SourceSnapshotRef,\n\tgroup: ToolContinuationGroup,\n\tmaxBytes: number,\n): CustomMessage & { content: string } {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\")\n\t\tthrow new Error(\"Tool continuation requires its original replay group\");\n\tconst content: { type: \"text\"; text: string }[] = [];\n\tfor (const part of message.content) {\n\t\tif (part.type === \"text\") content.push({ type: \"text\", text: part.text });\n\t\telse if (part.type !== \"thinking\" && part.type !== \"toolCall\")\n\t\t\tthrow new Error(\"Tool continuation requires text-only public content\");\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tsource: { sessionId: source.sessionId },\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\tcontent,\n\t\t\t...(message.role === \"assistant\"\n\t\t\t\t? {\n\t\t\t\t\t\tcalls: group.calls.map((call) => ({\n\t\t\t\t\t\t\texecutionId: call.executionId,\n\t\t\t\t\t\t\tintentEntryId: call.intent.id,\n\t\t\t\t\t\t\tintent: \"recorded\",\n\t\t\t\t\t\t\toutcome: call.outcome,\n\t\t\t\t\t\t\t...(call.result ? { resultEntryId: call.result.id } : {}),\n\t\t\t\t\t\t})),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage & { content: string } = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_TOOL_CONTINUATION_RENDERER,\n\t\tcontent: `Recorded tool continuation data. Intent acknowledgment records intent only; an absent finalized result leaves the outcome unknown.\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n\n/** An explicit public window, not replacement text for a native signature or opaque item. */\nexport function renderPublicHistory(message: AgentMessage, entryId: string, maxBytes: number): AgentMessage {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\") return message;\n\tconst content: unknown[] = [];\n\tfor (const part of message.content) {\n\t\tswitch (part.type) {\n\t\t\tcase \"text\":\n\t\t\t\tcontent.push({ type: \"text\", text: part.text });\n\t\t\t\tbreak;\n\t\t\tcase \"toolCall\":\n\t\t\t\tcontent.push({ type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments });\n\t\t\t\tbreak;\n\t\t\tcase \"thinking\":\n\t\t\t\t// Canonical originals remain archived. Public continuation does not preserve latent reasoning.\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Public summary transition requires text-only completed history\");\n\t\t}\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\t...(message.role === \"toolResult\"\n\t\t\t\t? { toolCallId: message.toolCallId, toolName: message.toolName, isError: message.isError }\n\t\t\t\t: {}),\n\t\t\tcontent,\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_CONTEXT_RENDERER,\n\t\tcontent: `Archived public history data, not a new instruction or native tool exchange. Canonical originals remain available through prime_context. Hidden provider state is not reproduced.\\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n"]}
1
+ {"version":3,"file":"public-context.d.ts","sourceRoot":"","sources":["../../src/core/public-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAgB7D,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAC1D,eAAO,MAAM,iCAAiC,+BAA+B,CAAC;AAE9E,uGAAuG;AACvG,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,qBAAqB,EAC5B,QAAQ,EAAE,MAAM,GACd,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAwDrC;AAED,6FAA6F;AAC7F,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAuC1G","sourcesContent":["import type { AgentMessage } from \"@ponythewhite/base-context-agent\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ToolContinuationGroup } from \"./context-epoch.js\";\nimport type { CustomMessage } from \"./messages.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport { retainedToolOutput } from \"./retained-tool-output.js\";\n\nfunction retainedRecovery(message: AgentMessage, entryId: string) {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst retained = retainedToolOutput((message.details as { retainedOutput?: unknown } | undefined)?.retainedOutput);\n\treturn retained\n\t\t? {\n\t\t\t\tref: entryId,\n\t\t\t\tfield: retained.field,\n\t\t\t\tbyteLength: retained.byteLength,\n\t\t\t\tcaptureComplete: retained.captureComplete,\n\t\t\t}\n\t\t: undefined;\n}\n\nexport const PUBLIC_CONTEXT_RENDERER = \"public-history/1\";\nexport const PUBLIC_TOOL_CONTINUATION_RENDERER = \"public-tool-continuation/1\";\n\n/** Original public text and minimal recorded facts. Intent ACK says nothing about external effects. */\nexport function renderToolContinuation(\n\tmessage: AgentMessage,\n\tentryId: string,\n\tsource: SourceSnapshotRef,\n\tgroup: ToolContinuationGroup,\n\tmaxBytes: number,\n): CustomMessage & { content: string } {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\")\n\t\tthrow new Error(\"Tool continuation requires its original replay group\");\n\tconst content: { type: \"text\"; text: string }[] = [];\n\tfor (const part of message.content) {\n\t\tif (part.type === \"text\") content.push({ type: \"text\", text: part.text });\n\t\telse if (part.type !== \"thinking\" && part.type !== \"toolCall\")\n\t\t\tthrow new Error(\"Tool continuation requires text-only public content\");\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tsource: { sessionId: source.sessionId },\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\tcontent,\n\t\t\t...(message.role === \"assistant\"\n\t\t\t\t? {\n\t\t\t\t\t\tcalls: group.calls.map((call, sourceOrder) =>\n\t\t\t\t\t\t\tcall.admission === \"absent\"\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\tsourceOrder,\n\t\t\t\t\t\t\t\t\t\tadmission: \"not_recorded\",\n\t\t\t\t\t\t\t\t\t\tcapturedHistory: {\n\t\t\t\t\t\t\t\t\t\t\tsessionId: call.source.sessionId,\n\t\t\t\t\t\t\t\t\t\t\tleafId: call.source.leafId,\n\t\t\t\t\t\t\t\t\t\t\tsourceSequence: call.source.sourceSequence,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\texecutionId: call.executionId,\n\t\t\t\t\t\t\t\t\t\tintentEntryId: call.intent.id,\n\t\t\t\t\t\t\t\t\t\tintent: \"recorded\",\n\t\t\t\t\t\t\t\t\t\toutcome: call.outcome,\n\t\t\t\t\t\t\t\t\t\t...(call.result ? { resultEntryId: call.result.id } : {}),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage & { content: string } = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_TOOL_CONTINUATION_RENDERER,\n\t\tcontent: `Recorded tool continuation data. Intent acknowledgment records intent only; an absent finalized result leaves the outcome unknown.${\n\t\t\tgroup.calls.some((call) => call.admission === \"absent\")\n\t\t\t\t? \" For calls marked admission not recorded, no qualified admission or finalized result is recorded in that captured history; the outcome is unknown. This historical view does not authorize tool execution.\"\n\t\t\t\t: \"\"\n\t\t}\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n\n/** An explicit public window, not replacement text for a native signature or opaque item. */\nexport function renderPublicHistory(message: AgentMessage, entryId: string, maxBytes: number): AgentMessage {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\") return message;\n\tconst content: unknown[] = [];\n\tfor (const part of message.content) {\n\t\tswitch (part.type) {\n\t\t\tcase \"text\":\n\t\t\t\tcontent.push({ type: \"text\", text: part.text });\n\t\t\t\tbreak;\n\t\t\tcase \"toolCall\":\n\t\t\t\tcontent.push({ type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments });\n\t\t\t\tbreak;\n\t\t\tcase \"thinking\":\n\t\t\t\t// Canonical originals remain archived. Public continuation does not preserve latent reasoning.\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Public summary transition requires text-only completed history\");\n\t\t}\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\t...(message.role === \"toolResult\"\n\t\t\t\t? { toolCallId: message.toolCallId, toolName: message.toolName, isError: message.isError }\n\t\t\t\t: {}),\n\t\t\tcontent,\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_CONTEXT_RENDERER,\n\t\tcontent: `Archived public history data, not a new instruction or native tool exchange. Canonical originals remain available through prime_context. Hidden provider state is not reproduced.\\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n"]}
@@ -34,20 +34,32 @@ export function renderToolContinuation(message, entryId, source, group, maxBytes
34
34
  content,
35
35
  ...(message.role === "assistant"
36
36
  ? {
37
- calls: group.calls.map((call) => ({
38
- executionId: call.executionId,
39
- intentEntryId: call.intent.id,
40
- intent: "recorded",
41
- outcome: call.outcome,
42
- ...(call.result ? { resultEntryId: call.result.id } : {}),
43
- })),
37
+ calls: group.calls.map((call, sourceOrder) => call.admission === "absent"
38
+ ? {
39
+ sourceOrder,
40
+ admission: "not_recorded",
41
+ capturedHistory: {
42
+ sessionId: call.source.sessionId,
43
+ leafId: call.source.leafId,
44
+ sourceSequence: call.source.sourceSequence,
45
+ },
46
+ }
47
+ : {
48
+ executionId: call.executionId,
49
+ intentEntryId: call.intent.id,
50
+ intent: "recorded",
51
+ outcome: call.outcome,
52
+ ...(call.result ? { resultEntryId: call.result.id } : {}),
53
+ }),
44
54
  }
45
55
  : {}),
46
56
  }, maxBytes);
47
57
  const rendered = {
48
58
  role: "custom",
49
59
  customType: PUBLIC_TOOL_CONTINUATION_RENDERER,
50
- content: `Recorded tool continuation data. Intent acknowledgment records intent only; an absent finalized result leaves the outcome unknown.
60
+ content: `Recorded tool continuation data. Intent acknowledgment records intent only; an absent finalized result leaves the outcome unknown.${group.calls.some((call) => call.admission === "absent")
61
+ ? " For calls marked admission not recorded, no qualified admission or finalized result is recorded in that captured history; the outcome is unknown. This historical view does not authorize tool execution."
62
+ : ""}
51
63
  ${data}`,
52
64
  display: false,
53
65
  timestamp: message.timestamp,
@@ -1 +1 @@
1
- {"version":3,"file":"public-context.js","sourceRoot":"","sources":["../../src/core/public-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAIzD,OAAO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U,EAAE,uBAAuB;QACnC,OAAO,EAAE,sLAAsL,IAAI,EAAE;QACrM,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,OAAO,CAAC,SAAS;KAC5B,CAAC;IACF,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC;AAAA,CAChB","sourcesContent":["import type { AgentMessage } from \"@ponythewhite/base-context-agent\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ToolContinuationGroup } from \"./context-epoch.js\";\nimport type { CustomMessage } from \"./messages.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport { retainedToolOutput } from \"./retained-tool-output.js\";\n\nfunction retainedRecovery(message: AgentMessage, entryId: string) {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst retained = retainedToolOutput((message.details as { retainedOutput?: unknown } | undefined)?.retainedOutput);\n\treturn retained\n\t\t? {\n\t\t\t\tref: entryId,\n\t\t\t\tfield: retained.field,\n\t\t\t\tbyteLength: retained.byteLength,\n\t\t\t\tcaptureComplete: retained.captureComplete,\n\t\t\t}\n\t\t: undefined;\n}\n\nexport const PUBLIC_CONTEXT_RENDERER = \"public-history/1\";\nexport const PUBLIC_TOOL_CONTINUATION_RENDERER = \"public-tool-continuation/1\";\n\n/** Original public text and minimal recorded facts. Intent ACK says nothing about external effects. */\nexport function renderToolContinuation(\n\tmessage: AgentMessage,\n\tentryId: string,\n\tsource: SourceSnapshotRef,\n\tgroup: ToolContinuationGroup,\n\tmaxBytes: number,\n): CustomMessage & { content: string } {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\")\n\t\tthrow new Error(\"Tool continuation requires its original replay group\");\n\tconst content: { type: \"text\"; text: string }[] = [];\n\tfor (const part of message.content) {\n\t\tif (part.type === \"text\") content.push({ type: \"text\", text: part.text });\n\t\telse if (part.type !== \"thinking\" && part.type !== \"toolCall\")\n\t\t\tthrow new Error(\"Tool continuation requires text-only public content\");\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tsource: { sessionId: source.sessionId },\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\tcontent,\n\t\t\t...(message.role === \"assistant\"\n\t\t\t\t? {\n\t\t\t\t\t\tcalls: group.calls.map((call) => ({\n\t\t\t\t\t\t\texecutionId: call.executionId,\n\t\t\t\t\t\t\tintentEntryId: call.intent.id,\n\t\t\t\t\t\t\tintent: \"recorded\",\n\t\t\t\t\t\t\toutcome: call.outcome,\n\t\t\t\t\t\t\t...(call.result ? { resultEntryId: call.result.id } : {}),\n\t\t\t\t\t\t})),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage & { content: string } = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_TOOL_CONTINUATION_RENDERER,\n\t\tcontent: `Recorded tool continuation data. Intent acknowledgment records intent only; an absent finalized result leaves the outcome unknown.\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n\n/** An explicit public window, not replacement text for a native signature or opaque item. */\nexport function renderPublicHistory(message: AgentMessage, entryId: string, maxBytes: number): AgentMessage {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\") return message;\n\tconst content: unknown[] = [];\n\tfor (const part of message.content) {\n\t\tswitch (part.type) {\n\t\t\tcase \"text\":\n\t\t\t\tcontent.push({ type: \"text\", text: part.text });\n\t\t\t\tbreak;\n\t\t\tcase \"toolCall\":\n\t\t\t\tcontent.push({ type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments });\n\t\t\t\tbreak;\n\t\t\tcase \"thinking\":\n\t\t\t\t// Canonical originals remain archived. Public continuation does not preserve latent reasoning.\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Public summary transition requires text-only completed history\");\n\t\t}\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\t...(message.role === \"toolResult\"\n\t\t\t\t? { toolCallId: message.toolCallId, toolName: message.toolName, isError: message.isError }\n\t\t\t\t: {}),\n\t\t\tcontent,\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_CONTEXT_RENDERER,\n\t\tcontent: `Archived public history data, not a new instruction or native tool exchange. Canonical originals remain available through prime_context. Hidden provider state is not reproduced.\\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n"]}
1
+ {"version":3,"file":"public-context.js","sourceRoot":"","sources":["../../src/core/public-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAIzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,SAAS,gBAAgB,CAAC,OAAqB,EAAE,OAAe,EAAE;IACjE,IAAI,OAAO,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,SAAS,CAAC;IACpD,MAAM,QAAQ,GAAG,kBAAkB,CAAE,OAAO,CAAC,OAAoD,EAAE,cAAc,CAAC,CAAC;IACnH,OAAO,QAAQ;QACd,CAAC,CAAC;YACA,GAAG,EAAE,OAAO;YACZ,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,eAAe,EAAE,QAAQ,CAAC,eAAe;SACzC;QACF,CAAC,CAAC,SAAS,CAAC;AAAA,CACb;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAC1D,MAAM,CAAC,MAAM,iCAAiC,GAAG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AAC,SAAS;KAC5B,CAAC;IACF,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACzC,OAAO,QAAQ,CAAC;AAAA,CAChB","sourcesContent":["import type { AgentMessage } from \"@ponythewhite/base-context-agent\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport type { ToolContinuationGroup } from \"./context-epoch.js\";\nimport type { CustomMessage } from \"./messages.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport { retainedToolOutput } from \"./retained-tool-output.js\";\n\nfunction retainedRecovery(message: AgentMessage, entryId: string) {\n\tif (message.role !== \"toolResult\") return undefined;\n\tconst retained = retainedToolOutput((message.details as { retainedOutput?: unknown } | undefined)?.retainedOutput);\n\treturn retained\n\t\t? {\n\t\t\t\tref: entryId,\n\t\t\t\tfield: retained.field,\n\t\t\t\tbyteLength: retained.byteLength,\n\t\t\t\tcaptureComplete: retained.captureComplete,\n\t\t\t}\n\t\t: undefined;\n}\n\nexport const PUBLIC_CONTEXT_RENDERER = \"public-history/1\";\nexport const PUBLIC_TOOL_CONTINUATION_RENDERER = \"public-tool-continuation/1\";\n\n/** Original public text and minimal recorded facts. Intent ACK says nothing about external effects. */\nexport function renderToolContinuation(\n\tmessage: AgentMessage,\n\tentryId: string,\n\tsource: SourceSnapshotRef,\n\tgroup: ToolContinuationGroup,\n\tmaxBytes: number,\n): CustomMessage & { content: string } {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\")\n\t\tthrow new Error(\"Tool continuation requires its original replay group\");\n\tconst content: { type: \"text\"; text: string }[] = [];\n\tfor (const part of message.content) {\n\t\tif (part.type === \"text\") content.push({ type: \"text\", text: part.text });\n\t\telse if (part.type !== \"thinking\" && part.type !== \"toolCall\")\n\t\t\tthrow new Error(\"Tool continuation requires text-only public content\");\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tsource: { sessionId: source.sessionId },\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\tcontent,\n\t\t\t...(message.role === \"assistant\"\n\t\t\t\t? {\n\t\t\t\t\t\tcalls: group.calls.map((call, sourceOrder) =>\n\t\t\t\t\t\t\tcall.admission === \"absent\"\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\tsourceOrder,\n\t\t\t\t\t\t\t\t\t\tadmission: \"not_recorded\",\n\t\t\t\t\t\t\t\t\t\tcapturedHistory: {\n\t\t\t\t\t\t\t\t\t\t\tsessionId: call.source.sessionId,\n\t\t\t\t\t\t\t\t\t\t\tleafId: call.source.leafId,\n\t\t\t\t\t\t\t\t\t\t\tsourceSequence: call.source.sourceSequence,\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\texecutionId: call.executionId,\n\t\t\t\t\t\t\t\t\t\tintentEntryId: call.intent.id,\n\t\t\t\t\t\t\t\t\t\tintent: \"recorded\",\n\t\t\t\t\t\t\t\t\t\toutcome: call.outcome,\n\t\t\t\t\t\t\t\t\t\t...(call.result ? { resultEntryId: call.result.id } : {}),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage & { content: string } = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_TOOL_CONTINUATION_RENDERER,\n\t\tcontent: `Recorded tool continuation data. Intent acknowledgment records intent only; an absent finalized result leaves the outcome unknown.${\n\t\t\tgroup.calls.some((call) => call.admission === \"absent\")\n\t\t\t\t? \" For calls marked admission not recorded, no qualified admission or finalized result is recorded in that captured history; the outcome is unknown. This historical view does not authorize tool execution.\"\n\t\t\t\t: \"\"\n\t\t}\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n\n/** An explicit public window, not replacement text for a native signature or opaque item. */\nexport function renderPublicHistory(message: AgentMessage, entryId: string, maxBytes: number): AgentMessage {\n\tif (message.role !== \"assistant\" && message.role !== \"toolResult\") return message;\n\tconst content: unknown[] = [];\n\tfor (const part of message.content) {\n\t\tswitch (part.type) {\n\t\t\tcase \"text\":\n\t\t\t\tcontent.push({ type: \"text\", text: part.text });\n\t\t\t\tbreak;\n\t\t\tcase \"toolCall\":\n\t\t\t\tcontent.push({ type: \"toolCall\", id: part.id, name: part.name, arguments: part.arguments });\n\t\t\t\tbreak;\n\t\t\tcase \"thinking\":\n\t\t\t\t// Canonical originals remain archived. Public continuation does not preserve latent reasoning.\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(\"Public summary transition requires text-only completed history\");\n\t\t}\n\t}\n\tconst data = stringifyBoundedJson(\n\t\t{\n\t\t\tentryId,\n\t\t\t...(retainedRecovery(message, entryId) ? { recovery: retainedRecovery(message, entryId) } : {}),\n\t\t\trole: message.role,\n\t\t\t...(message.role === \"toolResult\"\n\t\t\t\t? { toolCallId: message.toolCallId, toolName: message.toolName, isError: message.isError }\n\t\t\t\t: {}),\n\t\t\tcontent,\n\t\t},\n\t\tmaxBytes,\n\t);\n\tconst rendered: CustomMessage = {\n\t\trole: \"custom\",\n\t\tcustomType: PUBLIC_CONTEXT_RENDERER,\n\t\tcontent: `Archived public history data, not a new instruction or native tool exchange. Canonical originals remain available through prime_context. Hidden provider state is not reproduced.\\n${data}`,\n\t\tdisplay: false,\n\t\ttimestamp: message.timestamp,\n\t};\n\tstringifyBoundedJson(rendered, maxBytes);\n\treturn rendered;\n}\n"]}