@ponythewhite/base-context 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/base-context-runtime/pyproject.toml +1 -1
- package/dist/base-context-runtime/uv.lock +1 -1
- package/dist/build-info.json +1 -1
- package/dist/bundle/amazon-bedrock.js +2 -2
- package/dist/bundle/{bundled-modules-R5EAJ62K.js → bundled-modules-MEACET4U.js} +4 -4
- package/dist/bundle/{chunk-HKINIBP4.js → chunk-LFPWHI42.js} +1 -1
- package/dist/bundle/{chunk-BV25CVRM.js → chunk-LIZVVGHR.js} +83 -108
- package/dist/bundle/{chunk-XDJ56NJA.js → chunk-QKI6KEGP.js} +47 -23
- package/dist/bundle/{chunk-27QCJ2AZ.js → chunk-UPVDERMD.js} +0 -12
- package/dist/bundle/{cli-main-OUKN743U.js → cli-main-ANUJY7Y4.js} +3 -3
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/{main-QPCXSW6X.js → main-4GIKOHIT.js} +4 -4
- package/dist/cli/product-doctor.d.ts.map +1 -1
- package/dist/cli/product-doctor.js +2 -2
- package/dist/cli/product-doctor.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +9 -3
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/canonical-context.d.ts +3 -1
- package/dist/core/canonical-context.d.ts.map +1 -1
- package/dist/core/canonical-context.js +46 -16
- package/dist/core/canonical-context.js.map +1 -1
- package/dist/core/context-epoch-copy.d.ts.map +1 -1
- package/dist/core/context-epoch-copy.js +1 -1
- package/dist/core/context-epoch-copy.js.map +1 -1
- package/dist/core/context-epoch.d.ts +12 -2
- package/dist/core/context-epoch.d.ts.map +1 -1
- package/dist/core/context-epoch.js +28 -12
- package/dist/core/context-epoch.js.map +1 -1
- package/dist/core/session-bootstrap.d.ts +1 -0
- package/dist/core/session-bootstrap.d.ts.map +1 -1
- package/dist/core/session-bootstrap.js +1 -1
- package/dist/core/session-bootstrap.js.map +1 -1
- package/dist/modes/interactive/components/brand-announcement.d.ts +5 -0
- package/dist/modes/interactive/components/brand-announcement.d.ts.map +1 -0
- package/dist/modes/interactive/components/brand-announcement.js +14 -0
- package/dist/modes/interactive/components/brand-announcement.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +9 -6
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +4 -4
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/shared/startup-notices.d.ts.map +1 -1
- package/dist/modes/shared/startup-notices.js +1 -1
- package/dist/modes/shared/startup-notices.js.map +1 -1
- package/dist/themes/synerise-logo.d.ts +3 -0
- package/dist/themes/synerise-logo.d.ts.map +1 -0
- package/dist/themes/synerise-logo.js +9 -0
- package/dist/themes/synerise-logo.js.map +1 -0
- package/package.json +6 -6
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts +0 -5
- package/dist/modes/interactive/components/earendil-announcement.d.ts.map +0 -1
- package/dist/modes/interactive/components/earendil-announcement.js +0 -40
- package/dist/modes/interactive/components/earendil-announcement.js.map +0 -1
- package/dist/themes/prime-logo.d.ts +0 -9
- package/dist/themes/prime-logo.d.ts.map +0 -1
- package/dist/themes/prime-logo.js +0 -18
- package/dist/themes/prime-logo.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-epoch-copy.d.ts","sourceRoot":"","sources":["../../src/core/context-epoch-copy.ts"],"names":[],"mappings":"AAEA,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EAIxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,EAEN,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAE5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,eAAO,MAAM,qBAAqB,eAAkC,CAAC;AAErE,6FAA6F;AAC7F,MAAM,WAAW,gBAChB,SAAQ,IAAI,CACX,kBAAkB,EAClB,IAAI,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,eAAe,CAChG;IACD,QAAQ,CAAC,YAAY,CAAC,EAAE,mBAAmB,CAAC;CAC5C;AACD,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC9C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,GAC5C,gBAAgB,CAoBlB;AAED,gGAAgG;AAChG,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,uBAAuB,EAChC,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,wBAAwB,GAC9B,OAAO,CACT;IAAE,UAAU,EAAE,sBAAsB,CAAC;IAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAAE,GAAG,SAAS,CAC9G,CAqLA","sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport {\n\tCONTEXT_EPOCH_DETAIL,\n\ttype ContextEpochCheckpoint,\n\ttype ContextEpochSummary,\n\ttype EpochViewReference,\n\treadContextEpoch,\n\tsnapshotContextEpoch,\n} from \"./context-epoch.js\";\nimport type { ContextUpdateTarget, IndexedSourceEvent } from \"./history-index.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport {\n\thydrateCapturedHistoryEntry,\n\ttype SessionHistoryReadLimits,\n\ttype SessionHistoryReadScope,\n\ttype SessionHistoryReadView,\n} from \"./session-history-index.js\";\nimport type { SessionEntry } from \"./session-manager.js\";\nimport { compileTaskFrame, taskFrameLimits } from \"./task-frame.js\";\nimport { readTaskStateFromView } from \"./task-state-reader.js\";\n\nexport const readCopiedEpochSource = Symbol(\"readCopiedEpochSource\");\n\n/** Operation-local metadata from the actual old capture, not another body or epoch store. */\nexport interface CopiedEpochEntry\n\textends Pick<\n\t\tIndexedSourceEvent,\n\t\t\"id\" | \"parentId\" | \"kind\" | \"sequence\" | \"revision\" | \"locator\" | \"retention\" | \"qualification\"\n\t> {\n\treadonly updateTarget?: ContextUpdateTarget;\n}\nexport interface CapturedEpochCopy {\n\treadonly sessionId: string;\n\treadonly sessionFile?: string;\n\treadonly through: number;\n\treadonly entries: readonly CopiedEpochEntry[];\n\treadonly retained: boolean;\n}\n\nexport function captureEpochCopyEntry(\n\tentry: SessionEntry,\n\tsource: Omit<CopiedEpochEntry, \"updateTarget\">,\n): CopiedEpochEntry {\n\tconst updateTarget: ContextUpdateTarget | undefined =\n\t\tentry.type === \"message\"\n\t\t\t? entry.message.role === \"assistant\"\n\t\t\t\t? { kind: \"assistant-usage\", targetId: entry.id }\n\t\t\t\t: entry.message.role === \"toolResult\" && entry.message.toolName === \"ipython\"\n\t\t\t\t\t? { kind: \"ipython-sent-message\", toolCallId: entry.message.toolCallId }\n\t\t\t\t\t: undefined\n\t\t\t: undefined;\n\treturn {\n\t\tid: source.id,\n\t\tparentId: source.parentId,\n\t\tkind: source.kind,\n\t\tsequence: source.sequence,\n\t\trevision: source.revision,\n\t\tlocator: { ...source.locator },\n\t\tretention: source.retention,\n\t\tqualification: source.qualification,\n\t\t...(updateTarget ? { updateTarget } : {}),\n\t};\n}\n\n/** Rebuild only at the explicit copy boundary; later provider reads remain destination-only. */\nexport async function rebuildCopiedContextEpoch(\n\thistory: SessionHistoryReadScope,\n\tcopied: CapturedEpochCopy,\n\tlimits: SessionHistoryReadLimits,\n): Promise<\n\t{ checkpoint: ContextEpochCheckpoint; tokensBefore: number | null; summary?: ContextEpochSummary } | undefined\n> {\n\tconst view = history.branchContext;\n\tconst manifest = await view.contextManifest({ limit: 1 });\n\tif (manifest.selection !== \"known\") throw new Error(\"Copied context selection is unavailable\");\n\tconst selected = manifest.summaryRef;\n\tif (!selected) return;\n\tconst metadata = await view.get(selected.entryId);\n\tif (!metadata) throw new Error(\"Copied context summary source is unavailable\");\n\tconst hydrated = await hydrateCapturedHistoryEntry(metadata, limits.maxSourceBytes, view.readPayload);\n\tif (!hydrated || hydrated.entry.type !== \"compaction\") throw new Error(\"Copied context summary is unavailable\");\n\tconst entry = hydrated.entry;\n\tif (!entry.details || typeof entry.details !== \"object\" || !(CONTEXT_EPOCH_DETAIL in entry.details)) return;\n\tconst oldById = new Map<string, CopiedEpochEntry>();\n\tfor (const source of copied.entries) if (!oldById.has(source.id)) oldById.set(source.id, source);\n\tconst origin = oldById.get(entry.id);\n\tif (origin?.qualification !== \"native-context-epoch\" || hydrated.source.qualification !== \"native-context-epoch\")\n\t\tthrow new Error(\"Copied context epoch has no qualified source\");\n\tconst checkpoint = readContextEpoch(entry.details, limits.maxSourceBytes);\n\tif (checkpoint?.version === 6)\n\t\tthrow new Error(\"Tool continuation recipes require their original native execution source\");\n\tif (!checkpoint || checkpoint.literalTailId !== entry.firstKeptEntryId || !view.atSnapshot)\n\t\tthrow new Error(\"Copied context epoch boundary is unavailable\");\n\tif (copied.entries.length > limits.maxEntries || checkpoint.views.length > limits.maxEntries)\n\t\tthrow new Error(\"Copied context epoch item budget exceeded\");\n\tstringifyBoundedJson(copied, limits.maxSourceBytes);\n\tconst oldByRevision = new Map([...oldById.values()].map((source) => [source.revision, source]));\n\tconst destination = new Map<string, IndexedSourceEvent>();\n\tfor (const source of oldById.values()) {\n\t\tconst actual = await history.get(source.id);\n\t\tif (actual) destination.set(source.id, actual);\n\t}\n\tconst prefixViews = new Map<string, SessionHistoryReadView>();\n\tconst prefix = async (source: SourceSnapshotRef): Promise<SessionHistoryReadView> => {\n\t\tif (\n\t\t\tsource.sessionId !== copied.sessionId ||\n\t\t\tsource.sessionFile !== copied.sessionFile ||\n\t\t\t!source.persistent ||\n\t\t\t!Number.isSafeInteger(source.sourceSequence) ||\n\t\t\tsource.sourceSequence < 0 ||\n\t\t\tsource.sourceSequence > copied.through\n\t\t)\n\t\t\tthrow new Error(\"Copied epoch recipe is outside the captured old source\");\n\t\tconst key = JSON.stringify(source);\n\t\tconst existing = prefixViews.get(key);\n\t\tif (existing) return existing;\n\t\tlet leafId = source.leafId;\n\t\tif (leafId !== null && (!oldById.has(leafId) || oldById.get(leafId)!.sequence > source.sourceSequence))\n\t\t\tthrow new Error(\"Copied epoch leaf is outside its captured prefix\");\n\t\tconst seen = new Set<string>();\n\t\twhile (leafId !== null && !destination.has(leafId)) {\n\t\t\tif (seen.has(leafId)) throw new Error(\"Copied epoch parent path is unresolved\");\n\t\t\tseen.add(leafId);\n\t\t\tconst old = oldById.get(leafId);\n\t\t\tif (!old) throw new Error(\"Copied epoch parent source is unavailable\");\n\t\t\tleafId = old.parentId;\n\t\t}\n\t\tconst rows = [...oldById.values()]\n\t\t\t.filter((old) => old.sequence <= source.sourceSequence)\n\t\t\t.flatMap((old) => {\n\t\t\t\tconst actual = destination.get(old.id);\n\t\t\t\treturn actual ? [actual] : [];\n\t\t\t});\n\t\tconst last = rows.reduce<IndexedSourceEvent | undefined>(\n\t\t\t(previous, actual) => (!previous || actual.sequence > previous.sequence ? actual : previous),\n\t\t\tundefined,\n\t\t);\n\t\tif (!last) throw new Error(\"Copied epoch prefix has no preserved source\");\n\t\tconst narrowed = await view.atSnapshot!({ ...view.source, leafId, sourceSequence: last.sequence });\n\t\tprefixViews.set(key, narrowed);\n\t\treturn narrowed;\n\t};\n\tawait prefix(checkpoint.source);\n\tconst copyReference = async <\n\t\tT extends EpochViewReference | NonNullable<ContextEpochCheckpoint[\"selectedSkills\"]>[number][\"view\"],\n\t>(\n\t\tpinned: T,\n\t): Promise<T> => {\n\t\tconst old = oldById.get(pinned.ref.entryId);\n\t\tif (\n\t\t\t!old ||\n\t\t\told.revision !== pinned.ref.revision ||\n\t\t\told.sequence !== pinned.ref.sequence ||\n\t\t\told.kind !== pinned.ref.kind ||\n\t\t\t!isDeepStrictEqual(old.locator, pinned.ref.locator)\n\t\t)\n\t\t\tthrow new Error(\"Copied epoch recipe does not match its captured source\");\n\t\tconst read = await prefix(pinned.source);\n\t\tconst actual = await read.get(old.id);\n\t\tif (!actual || actual.kind !== old.kind) throw new Error(\"Copied epoch view source is unavailable\");\n\t\tconst ref = {\n\t\t\tentryId: actual.id,\n\t\t\tsequence: actual.sequence,\n\t\t\tkind: pinned.ref.kind,\n\t\t\tlocator: { ...actual.locator },\n\t\t\trevision: actual.revision,\n\t\t\tauthority: actual.authority,\n\t\t\tqualification: actual.qualification,\n\t\t\tretention: actual.retention,\n\t\t};\n\t\tlet sourceRevision = actual.revision;\n\t\tif (ref.kind !== \"compaction\") {\n\t\t\tconst original: unknown = JSON.parse(pinned.sourceRevision);\n\t\t\tif (\n\t\t\t\t!Array.isArray(original) ||\n\t\t\t\toriginal[0] !== old.revision ||\n\t\t\t\toriginal.some((revision) => typeof revision !== \"string\")\n\t\t\t)\n\t\t\t\tthrow new Error(\"Copied epoch frozen revisions are unavailable\");\n\t\t\tconst updates = old.updateTarget ? (await read.contextUpdates(old.updateTarget)).refs : [];\n\t\t\tconst expected = original.slice(1).map((revision) => oldByRevision.get(revision));\n\t\t\tif (\n\t\t\t\texpected.some((source) => !source || source.sequence > pinned.source.sourceSequence) ||\n\t\t\t\t!isDeepStrictEqual(\n\t\t\t\t\texpected.map((source) => source!.id),\n\t\t\t\t\tupdates.map((source) => source.entryId),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new Error(\"Copied epoch update sources were not preserved\");\n\t\t\tsourceRevision = JSON.stringify([actual.revision, ...updates.map((update) => update.revision)]);\n\t\t} else if (pinned.sourceRevision !== old.revision || pinned.retainedMessageCount === undefined) {\n\t\t\tthrow new Error(\"Copied epoch summary source is unavailable\");\n\t\t}\n\t\treturn {\n\t\t\tsource: read.source,\n\t\t\tref,\n\t\t\tsourceRevision,\n\t\t\t...(pinned.retainedMessageCount === undefined ? {} : { retainedMessageCount: pinned.retainedMessageCount }),\n\t\t\t...(pinned.rendering === undefined ? {} : { rendering: pinned.rendering }),\n\t\t} as T;\n\t};\n\tconst views: EpochViewReference[] = [];\n\tfor (const pinned of checkpoint.views) views.push(await copyReference(pinned));\n\tconst selectedSkills: Array<NonNullable<ContextEpochCheckpoint[\"selectedSkills\"]>[number]> | undefined =\n\t\tcheckpoint.selectedSkills ? [] : undefined;\n\tfor (const skill of checkpoint.selectedSkills ?? [])\n\t\tselectedSkills!.push({ name: skill.name, view: await copyReference(skill.view) });\n\tif (!(await view.get(checkpoint.literalTailId))) throw new Error(\"Copied epoch literal tail is unavailable\");\n\tconst tasks = await readTaskStateFromView(view, {\n\t\tmaxItems: limits.maxEntries,\n\t\tmaxSourceBytes: limits.maxSourceBytes,\n\t\tmaxViewBytes: limits.maxSourceBytes,\n\t});\n\tconst taskFrame = compileTaskFrame(tasks, taskFrameLimits({ maxBytes: Math.min(16_384, limits.maxSourceBytes) }));\n\tconst lowered =\n\t\tcopied.retained || origin.retention === \"retained-import\" || hydrated.source.retention === \"retained-import\";\n\tconst inherited =\n\t\tcheckpoint.version === 5 && lowered ? { ...checkpoint, pendingRequestContract: undefined } : checkpoint;\n\tconst { replayContract, publicWindow: _publicWindow, continuation, ...unchanged } = inherited;\n\tconst rebuiltContinuation = continuation\n\t\t? {\n\t\t\t\tkind: continuation.kind,\n\t\t\t\tpublicTailThrough: (await prefix(continuation.publicTailThrough)).source,\n\t\t\t}\n\t\t: undefined;\n\tconst rebuilt = snapshotContextEpoch(\n\t\t{\n\t\t\t...unchanged,\n\t\t\tsource: view.source,\n\t\t\tviews,\n\t\t\t...(selectedSkills?.length ? { selectedSkills } : {}),\n\t\t\ttaskFrame,\n\t\t\tresourceRevision: undefined, // Explicit copies must capture their destination owner anew.\n\t\t\t...(rebuiltContinuation ? { continuation: rebuiltContinuation } : {}),\n\t\t\t...(!lowered && replayContract !== undefined ? { replayContract } : {}),\n\t\t},\n\t\tlimits.maxSourceBytes,\n\t);\n\treturn {\n\t\tcheckpoint: rebuilt,\n\t\ttokensBefore: entry.tokensBefore,\n\t\t...(checkpoint.includeSummary\n\t\t\t? {\n\t\t\t\t\tsummary: {\n\t\t\t\t\t\tsummary: entry.summary,\n\t\t\t\t\t\tdetails: { ...entry.details },\n\t\t\t\t\t\tfromHook: entry.fromHook,\n\t\t\t\t\t\tcustomInstructions: entry.customInstructions, // The copied original alone retains its model usage.\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-epoch-copy.d.ts","sourceRoot":"","sources":["../../src/core/context-epoch-copy.ts"],"names":[],"mappings":"AAEA,OAAO,EAEN,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EAIxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,EAEN,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAE5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,eAAO,MAAM,qBAAqB,eAAkC,CAAC;AAErE,6FAA6F;AAC7F,MAAM,WAAW,gBAChB,SAAQ,IAAI,CACX,kBAAkB,EAClB,IAAI,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,eAAe,CAChG;IACD,QAAQ,CAAC,YAAY,CAAC,EAAE,mBAAmB,CAAC;CAC5C;AACD,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC9C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,GAC5C,gBAAgB,CAoBlB;AAED,gGAAgG;AAChG,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,uBAAuB,EAChC,MAAM,EAAE,iBAAiB,EACzB,MAAM,EAAE,wBAAwB,GAC9B,OAAO,CACT;IAAE,UAAU,EAAE,sBAAsB,CAAC;IAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAAE,GAAG,SAAS,CAC9G,CAqLA","sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport {\n\tCONTEXT_EPOCH_DETAIL,\n\ttype ContextEpochCheckpoint,\n\ttype ContextEpochSummary,\n\ttype EpochViewReference,\n\treadContextEpoch,\n\tsnapshotContextEpoch,\n} from \"./context-epoch.js\";\nimport type { ContextUpdateTarget, IndexedSourceEvent } from \"./history-index.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport {\n\thydrateCapturedHistoryEntry,\n\ttype SessionHistoryReadLimits,\n\ttype SessionHistoryReadScope,\n\ttype SessionHistoryReadView,\n} from \"./session-history-index.js\";\nimport type { SessionEntry } from \"./session-manager.js\";\nimport { compileTaskFrame, taskFrameLimits } from \"./task-frame.js\";\nimport { readTaskStateFromView } from \"./task-state-reader.js\";\n\nexport const readCopiedEpochSource = Symbol(\"readCopiedEpochSource\");\n\n/** Operation-local metadata from the actual old capture, not another body or epoch store. */\nexport interface CopiedEpochEntry\n\textends Pick<\n\t\tIndexedSourceEvent,\n\t\t\"id\" | \"parentId\" | \"kind\" | \"sequence\" | \"revision\" | \"locator\" | \"retention\" | \"qualification\"\n\t> {\n\treadonly updateTarget?: ContextUpdateTarget;\n}\nexport interface CapturedEpochCopy {\n\treadonly sessionId: string;\n\treadonly sessionFile?: string;\n\treadonly through: number;\n\treadonly entries: readonly CopiedEpochEntry[];\n\treadonly retained: boolean;\n}\n\nexport function captureEpochCopyEntry(\n\tentry: SessionEntry,\n\tsource: Omit<CopiedEpochEntry, \"updateTarget\">,\n): CopiedEpochEntry {\n\tconst updateTarget: ContextUpdateTarget | undefined =\n\t\tentry.type === \"message\"\n\t\t\t? entry.message.role === \"assistant\"\n\t\t\t\t? { kind: \"assistant-usage\", targetId: entry.id }\n\t\t\t\t: entry.message.role === \"toolResult\" && entry.message.toolName === \"ipython\"\n\t\t\t\t\t? { kind: \"ipython-sent-message\", toolCallId: entry.message.toolCallId }\n\t\t\t\t\t: undefined\n\t\t\t: undefined;\n\treturn {\n\t\tid: source.id,\n\t\tparentId: source.parentId,\n\t\tkind: source.kind,\n\t\tsequence: source.sequence,\n\t\trevision: source.revision,\n\t\tlocator: { ...source.locator },\n\t\tretention: source.retention,\n\t\tqualification: source.qualification,\n\t\t...(updateTarget ? { updateTarget } : {}),\n\t};\n}\n\n/** Rebuild only at the explicit copy boundary; later provider reads remain destination-only. */\nexport async function rebuildCopiedContextEpoch(\n\thistory: SessionHistoryReadScope,\n\tcopied: CapturedEpochCopy,\n\tlimits: SessionHistoryReadLimits,\n): Promise<\n\t{ checkpoint: ContextEpochCheckpoint; tokensBefore: number | null; summary?: ContextEpochSummary } | undefined\n> {\n\tconst view = history.branchContext;\n\tconst manifest = await view.contextManifest({ limit: 1 });\n\tif (manifest.selection !== \"known\") throw new Error(\"Copied context selection is unavailable\");\n\tconst selected = manifest.summaryRef;\n\tif (!selected) return;\n\tconst metadata = await view.get(selected.entryId);\n\tif (!metadata) throw new Error(\"Copied context summary source is unavailable\");\n\tconst hydrated = await hydrateCapturedHistoryEntry(metadata, limits.maxSourceBytes, view.readPayload);\n\tif (!hydrated || hydrated.entry.type !== \"compaction\") throw new Error(\"Copied context summary is unavailable\");\n\tconst entry = hydrated.entry;\n\tif (!entry.details || typeof entry.details !== \"object\" || !(CONTEXT_EPOCH_DETAIL in entry.details)) return;\n\tconst oldById = new Map<string, CopiedEpochEntry>();\n\tfor (const source of copied.entries) if (!oldById.has(source.id)) oldById.set(source.id, source);\n\tconst origin = oldById.get(entry.id);\n\tif (origin?.qualification !== \"native-context-epoch\" || hydrated.source.qualification !== \"native-context-epoch\")\n\t\tthrow new Error(\"Copied context epoch has no qualified source\");\n\tconst checkpoint = readContextEpoch(entry.details, limits.maxSourceBytes);\n\tif (checkpoint?.version === 6 || checkpoint?.version === 8)\n\t\tthrow new Error(\"Tool continuation recipes require their original native execution source\");\n\tif (!checkpoint || checkpoint.literalTailId !== entry.firstKeptEntryId || !view.atSnapshot)\n\t\tthrow new Error(\"Copied context epoch boundary is unavailable\");\n\tif (copied.entries.length > limits.maxEntries || checkpoint.views.length > limits.maxEntries)\n\t\tthrow new Error(\"Copied context epoch item budget exceeded\");\n\tstringifyBoundedJson(copied, limits.maxSourceBytes);\n\tconst oldByRevision = new Map([...oldById.values()].map((source) => [source.revision, source]));\n\tconst destination = new Map<string, IndexedSourceEvent>();\n\tfor (const source of oldById.values()) {\n\t\tconst actual = await history.get(source.id);\n\t\tif (actual) destination.set(source.id, actual);\n\t}\n\tconst prefixViews = new Map<string, SessionHistoryReadView>();\n\tconst prefix = async (source: SourceSnapshotRef): Promise<SessionHistoryReadView> => {\n\t\tif (\n\t\t\tsource.sessionId !== copied.sessionId ||\n\t\t\tsource.sessionFile !== copied.sessionFile ||\n\t\t\t!source.persistent ||\n\t\t\t!Number.isSafeInteger(source.sourceSequence) ||\n\t\t\tsource.sourceSequence < 0 ||\n\t\t\tsource.sourceSequence > copied.through\n\t\t)\n\t\t\tthrow new Error(\"Copied epoch recipe is outside the captured old source\");\n\t\tconst key = JSON.stringify(source);\n\t\tconst existing = prefixViews.get(key);\n\t\tif (existing) return existing;\n\t\tlet leafId = source.leafId;\n\t\tif (leafId !== null && (!oldById.has(leafId) || oldById.get(leafId)!.sequence > source.sourceSequence))\n\t\t\tthrow new Error(\"Copied epoch leaf is outside its captured prefix\");\n\t\tconst seen = new Set<string>();\n\t\twhile (leafId !== null && !destination.has(leafId)) {\n\t\t\tif (seen.has(leafId)) throw new Error(\"Copied epoch parent path is unresolved\");\n\t\t\tseen.add(leafId);\n\t\t\tconst old = oldById.get(leafId);\n\t\t\tif (!old) throw new Error(\"Copied epoch parent source is unavailable\");\n\t\t\tleafId = old.parentId;\n\t\t}\n\t\tconst rows = [...oldById.values()]\n\t\t\t.filter((old) => old.sequence <= source.sourceSequence)\n\t\t\t.flatMap((old) => {\n\t\t\t\tconst actual = destination.get(old.id);\n\t\t\t\treturn actual ? [actual] : [];\n\t\t\t});\n\t\tconst last = rows.reduce<IndexedSourceEvent | undefined>(\n\t\t\t(previous, actual) => (!previous || actual.sequence > previous.sequence ? actual : previous),\n\t\t\tundefined,\n\t\t);\n\t\tif (!last) throw new Error(\"Copied epoch prefix has no preserved source\");\n\t\tconst narrowed = await view.atSnapshot!({ ...view.source, leafId, sourceSequence: last.sequence });\n\t\tprefixViews.set(key, narrowed);\n\t\treturn narrowed;\n\t};\n\tawait prefix(checkpoint.source);\n\tconst copyReference = async <\n\t\tT extends EpochViewReference | NonNullable<ContextEpochCheckpoint[\"selectedSkills\"]>[number][\"view\"],\n\t>(\n\t\tpinned: T,\n\t): Promise<T> => {\n\t\tconst old = oldById.get(pinned.ref.entryId);\n\t\tif (\n\t\t\t!old ||\n\t\t\told.revision !== pinned.ref.revision ||\n\t\t\told.sequence !== pinned.ref.sequence ||\n\t\t\told.kind !== pinned.ref.kind ||\n\t\t\t!isDeepStrictEqual(old.locator, pinned.ref.locator)\n\t\t)\n\t\t\tthrow new Error(\"Copied epoch recipe does not match its captured source\");\n\t\tconst read = await prefix(pinned.source);\n\t\tconst actual = await read.get(old.id);\n\t\tif (!actual || actual.kind !== old.kind) throw new Error(\"Copied epoch view source is unavailable\");\n\t\tconst ref = {\n\t\t\tentryId: actual.id,\n\t\t\tsequence: actual.sequence,\n\t\t\tkind: pinned.ref.kind,\n\t\t\tlocator: { ...actual.locator },\n\t\t\trevision: actual.revision,\n\t\t\tauthority: actual.authority,\n\t\t\tqualification: actual.qualification,\n\t\t\tretention: actual.retention,\n\t\t};\n\t\tlet sourceRevision = actual.revision;\n\t\tif (ref.kind !== \"compaction\") {\n\t\t\tconst original: unknown = JSON.parse(pinned.sourceRevision);\n\t\t\tif (\n\t\t\t\t!Array.isArray(original) ||\n\t\t\t\toriginal[0] !== old.revision ||\n\t\t\t\toriginal.some((revision) => typeof revision !== \"string\")\n\t\t\t)\n\t\t\t\tthrow new Error(\"Copied epoch frozen revisions are unavailable\");\n\t\t\tconst updates = old.updateTarget ? (await read.contextUpdates(old.updateTarget)).refs : [];\n\t\t\tconst expected = original.slice(1).map((revision) => oldByRevision.get(revision));\n\t\t\tif (\n\t\t\t\texpected.some((source) => !source || source.sequence > pinned.source.sourceSequence) ||\n\t\t\t\t!isDeepStrictEqual(\n\t\t\t\t\texpected.map((source) => source!.id),\n\t\t\t\t\tupdates.map((source) => source.entryId),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new Error(\"Copied epoch update sources were not preserved\");\n\t\t\tsourceRevision = JSON.stringify([actual.revision, ...updates.map((update) => update.revision)]);\n\t\t} else if (pinned.sourceRevision !== old.revision || pinned.retainedMessageCount === undefined) {\n\t\t\tthrow new Error(\"Copied epoch summary source is unavailable\");\n\t\t}\n\t\treturn {\n\t\t\tsource: read.source,\n\t\t\tref,\n\t\t\tsourceRevision,\n\t\t\t...(pinned.retainedMessageCount === undefined ? {} : { retainedMessageCount: pinned.retainedMessageCount }),\n\t\t\t...(pinned.rendering === undefined ? {} : { rendering: pinned.rendering }),\n\t\t} as T;\n\t};\n\tconst views: EpochViewReference[] = [];\n\tfor (const pinned of checkpoint.views) views.push(await copyReference(pinned));\n\tconst selectedSkills: Array<NonNullable<ContextEpochCheckpoint[\"selectedSkills\"]>[number]> | undefined =\n\t\tcheckpoint.selectedSkills ? [] : undefined;\n\tfor (const skill of checkpoint.selectedSkills ?? [])\n\t\tselectedSkills!.push({ name: skill.name, view: await copyReference(skill.view) });\n\tif (!(await view.get(checkpoint.literalTailId))) throw new Error(\"Copied epoch literal tail is unavailable\");\n\tconst tasks = await readTaskStateFromView(view, {\n\t\tmaxItems: limits.maxEntries,\n\t\tmaxSourceBytes: limits.maxSourceBytes,\n\t\tmaxViewBytes: limits.maxSourceBytes,\n\t});\n\tconst taskFrame = compileTaskFrame(tasks, taskFrameLimits({ maxBytes: Math.min(16_384, limits.maxSourceBytes) }));\n\tconst lowered =\n\t\tcopied.retained || origin.retention === \"retained-import\" || hydrated.source.retention === \"retained-import\";\n\tconst inherited =\n\t\tcheckpoint.version === 5 && lowered ? { ...checkpoint, pendingRequestContract: undefined } : checkpoint;\n\tconst { replayContract, publicWindow: _publicWindow, continuation, ...unchanged } = inherited;\n\tconst rebuiltContinuation = continuation\n\t\t? {\n\t\t\t\tkind: continuation.kind,\n\t\t\t\tpublicTailThrough: (await prefix(continuation.publicTailThrough)).source,\n\t\t\t}\n\t\t: undefined;\n\tconst rebuilt = snapshotContextEpoch(\n\t\t{\n\t\t\t...unchanged,\n\t\t\tsource: view.source,\n\t\t\tviews,\n\t\t\t...(selectedSkills?.length ? { selectedSkills } : {}),\n\t\t\ttaskFrame,\n\t\t\tresourceRevision: undefined, // Explicit copies must capture their destination owner anew.\n\t\t\t...(rebuiltContinuation ? { continuation: rebuiltContinuation } : {}),\n\t\t\t...(!lowered && replayContract !== undefined ? { replayContract } : {}),\n\t\t},\n\t\tlimits.maxSourceBytes,\n\t);\n\treturn {\n\t\tcheckpoint: rebuilt,\n\t\ttokensBefore: entry.tokensBefore,\n\t\t...(checkpoint.includeSummary\n\t\t\t? {\n\t\t\t\t\tsummary: {\n\t\t\t\t\t\tsummary: entry.summary,\n\t\t\t\t\t\tdetails: { ...entry.details },\n\t\t\t\t\t\tfromHook: entry.fromHook,\n\t\t\t\t\t\tcustomInstructions: entry.customInstructions, // The copied original alone retains its model usage.\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n"]}
|
|
@@ -51,7 +51,7 @@ export async function rebuildCopiedContextEpoch(history, copied, limits) {
|
|
|
51
51
|
if (origin?.qualification !== "native-context-epoch" || hydrated.source.qualification !== "native-context-epoch")
|
|
52
52
|
throw new Error("Copied context epoch has no qualified source");
|
|
53
53
|
const checkpoint = readContextEpoch(entry.details, limits.maxSourceBytes);
|
|
54
|
-
if (checkpoint?.version === 6)
|
|
54
|
+
if (checkpoint?.version === 6 || checkpoint?.version === 8)
|
|
55
55
|
throw new Error("Tool continuation recipes require their original native execution source");
|
|
56
56
|
if (!checkpoint || checkpoint.literalTailId !== entry.firstKeptEntryId || !view.atSnapshot)
|
|
57
57
|
throw new Error("Copied context epoch boundary is unavailable");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-epoch-copy.js","sourceRoot":"","sources":["../../src/core/context-epoch-copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EACN,oBAAoB,EAIpB,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACN,2BAA2B,GAI3B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE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AE,CAAC;QACrE,GAAG,CAAC,CAAC,OAAO,IAAI,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,EACD,MAAM,CAAC,cAAc,CACrB,CAAC;IACF,OAAO;QACN,UAAU,EAAE,OAAO;QACnB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,GAAG,CAAC,UAAU,CAAC,cAAc;YAC5B,CAAC,CAAC;gBACA,OAAO,EAAE;oBACR,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,OAAO,EAAE,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE;oBAC7B,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAAE,qDAAqD;iBACnG;aACD;YACF,CAAC,CAAC,EAAE,CAAC;KACN,CAAC;AAAA,CACF","sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport {\n\tCONTEXT_EPOCH_DETAIL,\n\ttype ContextEpochCheckpoint,\n\ttype ContextEpochSummary,\n\ttype EpochViewReference,\n\treadContextEpoch,\n\tsnapshotContextEpoch,\n} from \"./context-epoch.js\";\nimport type { ContextUpdateTarget, IndexedSourceEvent } from \"./history-index.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport {\n\thydrateCapturedHistoryEntry,\n\ttype SessionHistoryReadLimits,\n\ttype SessionHistoryReadScope,\n\ttype SessionHistoryReadView,\n} from \"./session-history-index.js\";\nimport type { SessionEntry } from \"./session-manager.js\";\nimport { compileTaskFrame, taskFrameLimits } from \"./task-frame.js\";\nimport { readTaskStateFromView } from \"./task-state-reader.js\";\n\nexport const readCopiedEpochSource = Symbol(\"readCopiedEpochSource\");\n\n/** Operation-local metadata from the actual old capture, not another body or epoch store. */\nexport interface CopiedEpochEntry\n\textends Pick<\n\t\tIndexedSourceEvent,\n\t\t\"id\" | \"parentId\" | \"kind\" | \"sequence\" | \"revision\" | \"locator\" | \"retention\" | \"qualification\"\n\t> {\n\treadonly updateTarget?: ContextUpdateTarget;\n}\nexport interface CapturedEpochCopy {\n\treadonly sessionId: string;\n\treadonly sessionFile?: string;\n\treadonly through: number;\n\treadonly entries: readonly CopiedEpochEntry[];\n\treadonly retained: boolean;\n}\n\nexport function captureEpochCopyEntry(\n\tentry: SessionEntry,\n\tsource: Omit<CopiedEpochEntry, \"updateTarget\">,\n): CopiedEpochEntry {\n\tconst updateTarget: ContextUpdateTarget | undefined =\n\t\tentry.type === \"message\"\n\t\t\t? entry.message.role === \"assistant\"\n\t\t\t\t? { kind: \"assistant-usage\", targetId: entry.id }\n\t\t\t\t: entry.message.role === \"toolResult\" && entry.message.toolName === \"ipython\"\n\t\t\t\t\t? { kind: \"ipython-sent-message\", toolCallId: entry.message.toolCallId }\n\t\t\t\t\t: undefined\n\t\t\t: undefined;\n\treturn {\n\t\tid: source.id,\n\t\tparentId: source.parentId,\n\t\tkind: source.kind,\n\t\tsequence: source.sequence,\n\t\trevision: source.revision,\n\t\tlocator: { ...source.locator },\n\t\tretention: source.retention,\n\t\tqualification: source.qualification,\n\t\t...(updateTarget ? { updateTarget } : {}),\n\t};\n}\n\n/** Rebuild only at the explicit copy boundary; later provider reads remain destination-only. */\nexport async function rebuildCopiedContextEpoch(\n\thistory: SessionHistoryReadScope,\n\tcopied: CapturedEpochCopy,\n\tlimits: SessionHistoryReadLimits,\n): Promise<\n\t{ checkpoint: ContextEpochCheckpoint; tokensBefore: number | null; summary?: ContextEpochSummary } | undefined\n> {\n\tconst view = history.branchContext;\n\tconst manifest = await view.contextManifest({ limit: 1 });\n\tif (manifest.selection !== \"known\") throw new Error(\"Copied context selection is unavailable\");\n\tconst selected = manifest.summaryRef;\n\tif (!selected) return;\n\tconst metadata = await view.get(selected.entryId);\n\tif (!metadata) throw new Error(\"Copied context summary source is unavailable\");\n\tconst hydrated = await hydrateCapturedHistoryEntry(metadata, limits.maxSourceBytes, view.readPayload);\n\tif (!hydrated || hydrated.entry.type !== \"compaction\") throw new Error(\"Copied context summary is unavailable\");\n\tconst entry = hydrated.entry;\n\tif (!entry.details || typeof entry.details !== \"object\" || !(CONTEXT_EPOCH_DETAIL in entry.details)) return;\n\tconst oldById = new Map<string, CopiedEpochEntry>();\n\tfor (const source of copied.entries) if (!oldById.has(source.id)) oldById.set(source.id, source);\n\tconst origin = oldById.get(entry.id);\n\tif (origin?.qualification !== \"native-context-epoch\" || hydrated.source.qualification !== \"native-context-epoch\")\n\t\tthrow new Error(\"Copied context epoch has no qualified source\");\n\tconst checkpoint = readContextEpoch(entry.details, limits.maxSourceBytes);\n\tif (checkpoint?.version === 6)\n\t\tthrow new Error(\"Tool continuation recipes require their original native execution source\");\n\tif (!checkpoint || checkpoint.literalTailId !== entry.firstKeptEntryId || !view.atSnapshot)\n\t\tthrow new Error(\"Copied context epoch boundary is unavailable\");\n\tif (copied.entries.length > limits.maxEntries || checkpoint.views.length > limits.maxEntries)\n\t\tthrow new Error(\"Copied context epoch item budget exceeded\");\n\tstringifyBoundedJson(copied, limits.maxSourceBytes);\n\tconst oldByRevision = new Map([...oldById.values()].map((source) => [source.revision, source]));\n\tconst destination = new Map<string, IndexedSourceEvent>();\n\tfor (const source of oldById.values()) {\n\t\tconst actual = await history.get(source.id);\n\t\tif (actual) destination.set(source.id, actual);\n\t}\n\tconst prefixViews = new Map<string, SessionHistoryReadView>();\n\tconst prefix = async (source: SourceSnapshotRef): Promise<SessionHistoryReadView> => {\n\t\tif (\n\t\t\tsource.sessionId !== copied.sessionId ||\n\t\t\tsource.sessionFile !== copied.sessionFile ||\n\t\t\t!source.persistent ||\n\t\t\t!Number.isSafeInteger(source.sourceSequence) ||\n\t\t\tsource.sourceSequence < 0 ||\n\t\t\tsource.sourceSequence > copied.through\n\t\t)\n\t\t\tthrow new Error(\"Copied epoch recipe is outside the captured old source\");\n\t\tconst key = JSON.stringify(source);\n\t\tconst existing = prefixViews.get(key);\n\t\tif (existing) return existing;\n\t\tlet leafId = source.leafId;\n\t\tif (leafId !== null && (!oldById.has(leafId) || oldById.get(leafId)!.sequence > source.sourceSequence))\n\t\t\tthrow new Error(\"Copied epoch leaf is outside its captured prefix\");\n\t\tconst seen = new Set<string>();\n\t\twhile (leafId !== null && !destination.has(leafId)) {\n\t\t\tif (seen.has(leafId)) throw new Error(\"Copied epoch parent path is unresolved\");\n\t\t\tseen.add(leafId);\n\t\t\tconst old = oldById.get(leafId);\n\t\t\tif (!old) throw new Error(\"Copied epoch parent source is unavailable\");\n\t\t\tleafId = old.parentId;\n\t\t}\n\t\tconst rows = [...oldById.values()]\n\t\t\t.filter((old) => old.sequence <= source.sourceSequence)\n\t\t\t.flatMap((old) => {\n\t\t\t\tconst actual = destination.get(old.id);\n\t\t\t\treturn actual ? [actual] : [];\n\t\t\t});\n\t\tconst last = rows.reduce<IndexedSourceEvent | undefined>(\n\t\t\t(previous, actual) => (!previous || actual.sequence > previous.sequence ? actual : previous),\n\t\t\tundefined,\n\t\t);\n\t\tif (!last) throw new Error(\"Copied epoch prefix has no preserved source\");\n\t\tconst narrowed = await view.atSnapshot!({ ...view.source, leafId, sourceSequence: last.sequence });\n\t\tprefixViews.set(key, narrowed);\n\t\treturn narrowed;\n\t};\n\tawait prefix(checkpoint.source);\n\tconst copyReference = async <\n\t\tT extends EpochViewReference | NonNullable<ContextEpochCheckpoint[\"selectedSkills\"]>[number][\"view\"],\n\t>(\n\t\tpinned: T,\n\t): Promise<T> => {\n\t\tconst old = oldById.get(pinned.ref.entryId);\n\t\tif (\n\t\t\t!old ||\n\t\t\told.revision !== pinned.ref.revision ||\n\t\t\told.sequence !== pinned.ref.sequence ||\n\t\t\told.kind !== pinned.ref.kind ||\n\t\t\t!isDeepStrictEqual(old.locator, pinned.ref.locator)\n\t\t)\n\t\t\tthrow new Error(\"Copied epoch recipe does not match its captured source\");\n\t\tconst read = await prefix(pinned.source);\n\t\tconst actual = await read.get(old.id);\n\t\tif (!actual || actual.kind !== old.kind) throw new Error(\"Copied epoch view source is unavailable\");\n\t\tconst ref = {\n\t\t\tentryId: actual.id,\n\t\t\tsequence: actual.sequence,\n\t\t\tkind: pinned.ref.kind,\n\t\t\tlocator: { ...actual.locator },\n\t\t\trevision: actual.revision,\n\t\t\tauthority: actual.authority,\n\t\t\tqualification: actual.qualification,\n\t\t\tretention: actual.retention,\n\t\t};\n\t\tlet sourceRevision = actual.revision;\n\t\tif (ref.kind !== \"compaction\") {\n\t\t\tconst original: unknown = JSON.parse(pinned.sourceRevision);\n\t\t\tif (\n\t\t\t\t!Array.isArray(original) ||\n\t\t\t\toriginal[0] !== old.revision ||\n\t\t\t\toriginal.some((revision) => typeof revision !== \"string\")\n\t\t\t)\n\t\t\t\tthrow new Error(\"Copied epoch frozen revisions are unavailable\");\n\t\t\tconst updates = old.updateTarget ? (await read.contextUpdates(old.updateTarget)).refs : [];\n\t\t\tconst expected = original.slice(1).map((revision) => oldByRevision.get(revision));\n\t\t\tif (\n\t\t\t\texpected.some((source) => !source || source.sequence > pinned.source.sourceSequence) ||\n\t\t\t\t!isDeepStrictEqual(\n\t\t\t\t\texpected.map((source) => source!.id),\n\t\t\t\t\tupdates.map((source) => source.entryId),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new Error(\"Copied epoch update sources were not preserved\");\n\t\t\tsourceRevision = JSON.stringify([actual.revision, ...updates.map((update) => update.revision)]);\n\t\t} else if (pinned.sourceRevision !== old.revision || pinned.retainedMessageCount === undefined) {\n\t\t\tthrow new Error(\"Copied epoch summary source is unavailable\");\n\t\t}\n\t\treturn {\n\t\t\tsource: read.source,\n\t\t\tref,\n\t\t\tsourceRevision,\n\t\t\t...(pinned.retainedMessageCount === undefined ? {} : { retainedMessageCount: pinned.retainedMessageCount }),\n\t\t\t...(pinned.rendering === undefined ? {} : { rendering: pinned.rendering }),\n\t\t} as T;\n\t};\n\tconst views: EpochViewReference[] = [];\n\tfor (const pinned of checkpoint.views) views.push(await copyReference(pinned));\n\tconst selectedSkills: Array<NonNullable<ContextEpochCheckpoint[\"selectedSkills\"]>[number]> | undefined =\n\t\tcheckpoint.selectedSkills ? [] : undefined;\n\tfor (const skill of checkpoint.selectedSkills ?? [])\n\t\tselectedSkills!.push({ name: skill.name, view: await copyReference(skill.view) });\n\tif (!(await view.get(checkpoint.literalTailId))) throw new Error(\"Copied epoch literal tail is unavailable\");\n\tconst tasks = await readTaskStateFromView(view, {\n\t\tmaxItems: limits.maxEntries,\n\t\tmaxSourceBytes: limits.maxSourceBytes,\n\t\tmaxViewBytes: limits.maxSourceBytes,\n\t});\n\tconst taskFrame = compileTaskFrame(tasks, taskFrameLimits({ maxBytes: Math.min(16_384, limits.maxSourceBytes) }));\n\tconst lowered =\n\t\tcopied.retained || origin.retention === \"retained-import\" || hydrated.source.retention === \"retained-import\";\n\tconst inherited =\n\t\tcheckpoint.version === 5 && lowered ? { ...checkpoint, pendingRequestContract: undefined } : checkpoint;\n\tconst { replayContract, publicWindow: _publicWindow, continuation, ...unchanged } = inherited;\n\tconst rebuiltContinuation = continuation\n\t\t? {\n\t\t\t\tkind: continuation.kind,\n\t\t\t\tpublicTailThrough: (await prefix(continuation.publicTailThrough)).source,\n\t\t\t}\n\t\t: undefined;\n\tconst rebuilt = snapshotContextEpoch(\n\t\t{\n\t\t\t...unchanged,\n\t\t\tsource: view.source,\n\t\t\tviews,\n\t\t\t...(selectedSkills?.length ? { selectedSkills } : {}),\n\t\t\ttaskFrame,\n\t\t\tresourceRevision: undefined, // Explicit copies must capture their destination owner anew.\n\t\t\t...(rebuiltContinuation ? { continuation: rebuiltContinuation } : {}),\n\t\t\t...(!lowered && replayContract !== undefined ? { replayContract } : {}),\n\t\t},\n\t\tlimits.maxSourceBytes,\n\t);\n\treturn {\n\t\tcheckpoint: rebuilt,\n\t\ttokensBefore: entry.tokensBefore,\n\t\t...(checkpoint.includeSummary\n\t\t\t? {\n\t\t\t\t\tsummary: {\n\t\t\t\t\t\tsummary: entry.summary,\n\t\t\t\t\t\tdetails: { ...entry.details },\n\t\t\t\t\t\tfromHook: entry.fromHook,\n\t\t\t\t\t\tcustomInstructions: entry.customInstructions, // The copied original alone retains its model usage.\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-epoch-copy.js","sourceRoot":"","sources":["../../src/core/context-epoch-copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EACN,oBAAoB,EAIpB,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACN,2BAA2B,GAI3B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAkBrE,MAAM,UAAU,qBAAqB,CACpC,KAAmB,EACnB,MAA8C,EAC3B;IACnB,MAAM,YAAY,GACjB,KAAK,CAAC,IAAI,KAAK,SAAS;QACvB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW;YACnC,CAAC,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE;YACjD,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS;gBAC5E,CAAC,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE;gBACxE,CAAC,CAAC,SAAS;QACb,CAAC,CAAC,SAAS,CAAC;IACd,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F,MAAM,mBAAmB,GAAG,YAAY;QACvC,CAAC,CAAC;YACA,IAAI,EAAE,YAAY,CAAC,IAAI;YACvB,iBAAiB,EAAE,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM;SACxE;QACF,CAAC,CAAC,SAAS,CAAC;IACb,MAAM,OAAO,GAAG,oBAAoB,CACnC;QACC,GAAG,SAAS;QACZ,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK;QACL,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,SAAS;QACT,gBAAgB,EAAE,SAAS,EAAE,6DAA6D;QAC1F,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrE,GAAG,CAAC,CAAC,OAAO,IAAI,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,EACD,MAAM,CAAC,cAAc,CACrB,CAAC;IACF,OAAO;QACN,UAAU,EAAE,OAAO;QACnB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,GAAG,CAAC,UAAU,CAAC,cAAc;YAC5B,CAAC,CAAC;gBACA,OAAO,EAAE;oBACR,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,OAAO,EAAE,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE;oBAC7B,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAAE,qDAAqD;iBACnG;aACD;YACF,CAAC,CAAC,EAAE,CAAC;KACN,CAAC;AAAA,CACF","sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport { stringifyBoundedJson } from \"./bounded-json.js\";\nimport {\n\tCONTEXT_EPOCH_DETAIL,\n\ttype ContextEpochCheckpoint,\n\ttype ContextEpochSummary,\n\ttype EpochViewReference,\n\treadContextEpoch,\n\tsnapshotContextEpoch,\n} from \"./context-epoch.js\";\nimport type { ContextUpdateTarget, IndexedSourceEvent } from \"./history-index.js\";\nimport type { SourceSnapshotRef } from \"./request-events.js\";\nimport {\n\thydrateCapturedHistoryEntry,\n\ttype SessionHistoryReadLimits,\n\ttype SessionHistoryReadScope,\n\ttype SessionHistoryReadView,\n} from \"./session-history-index.js\";\nimport type { SessionEntry } from \"./session-manager.js\";\nimport { compileTaskFrame, taskFrameLimits } from \"./task-frame.js\";\nimport { readTaskStateFromView } from \"./task-state-reader.js\";\n\nexport const readCopiedEpochSource = Symbol(\"readCopiedEpochSource\");\n\n/** Operation-local metadata from the actual old capture, not another body or epoch store. */\nexport interface CopiedEpochEntry\n\textends Pick<\n\t\tIndexedSourceEvent,\n\t\t\"id\" | \"parentId\" | \"kind\" | \"sequence\" | \"revision\" | \"locator\" | \"retention\" | \"qualification\"\n\t> {\n\treadonly updateTarget?: ContextUpdateTarget;\n}\nexport interface CapturedEpochCopy {\n\treadonly sessionId: string;\n\treadonly sessionFile?: string;\n\treadonly through: number;\n\treadonly entries: readonly CopiedEpochEntry[];\n\treadonly retained: boolean;\n}\n\nexport function captureEpochCopyEntry(\n\tentry: SessionEntry,\n\tsource: Omit<CopiedEpochEntry, \"updateTarget\">,\n): CopiedEpochEntry {\n\tconst updateTarget: ContextUpdateTarget | undefined =\n\t\tentry.type === \"message\"\n\t\t\t? entry.message.role === \"assistant\"\n\t\t\t\t? { kind: \"assistant-usage\", targetId: entry.id }\n\t\t\t\t: entry.message.role === \"toolResult\" && entry.message.toolName === \"ipython\"\n\t\t\t\t\t? { kind: \"ipython-sent-message\", toolCallId: entry.message.toolCallId }\n\t\t\t\t\t: undefined\n\t\t\t: undefined;\n\treturn {\n\t\tid: source.id,\n\t\tparentId: source.parentId,\n\t\tkind: source.kind,\n\t\tsequence: source.sequence,\n\t\trevision: source.revision,\n\t\tlocator: { ...source.locator },\n\t\tretention: source.retention,\n\t\tqualification: source.qualification,\n\t\t...(updateTarget ? { updateTarget } : {}),\n\t};\n}\n\n/** Rebuild only at the explicit copy boundary; later provider reads remain destination-only. */\nexport async function rebuildCopiedContextEpoch(\n\thistory: SessionHistoryReadScope,\n\tcopied: CapturedEpochCopy,\n\tlimits: SessionHistoryReadLimits,\n): Promise<\n\t{ checkpoint: ContextEpochCheckpoint; tokensBefore: number | null; summary?: ContextEpochSummary } | undefined\n> {\n\tconst view = history.branchContext;\n\tconst manifest = await view.contextManifest({ limit: 1 });\n\tif (manifest.selection !== \"known\") throw new Error(\"Copied context selection is unavailable\");\n\tconst selected = manifest.summaryRef;\n\tif (!selected) return;\n\tconst metadata = await view.get(selected.entryId);\n\tif (!metadata) throw new Error(\"Copied context summary source is unavailable\");\n\tconst hydrated = await hydrateCapturedHistoryEntry(metadata, limits.maxSourceBytes, view.readPayload);\n\tif (!hydrated || hydrated.entry.type !== \"compaction\") throw new Error(\"Copied context summary is unavailable\");\n\tconst entry = hydrated.entry;\n\tif (!entry.details || typeof entry.details !== \"object\" || !(CONTEXT_EPOCH_DETAIL in entry.details)) return;\n\tconst oldById = new Map<string, CopiedEpochEntry>();\n\tfor (const source of copied.entries) if (!oldById.has(source.id)) oldById.set(source.id, source);\n\tconst origin = oldById.get(entry.id);\n\tif (origin?.qualification !== \"native-context-epoch\" || hydrated.source.qualification !== \"native-context-epoch\")\n\t\tthrow new Error(\"Copied context epoch has no qualified source\");\n\tconst checkpoint = readContextEpoch(entry.details, limits.maxSourceBytes);\n\tif (checkpoint?.version === 6 || checkpoint?.version === 8)\n\t\tthrow new Error(\"Tool continuation recipes require their original native execution source\");\n\tif (!checkpoint || checkpoint.literalTailId !== entry.firstKeptEntryId || !view.atSnapshot)\n\t\tthrow new Error(\"Copied context epoch boundary is unavailable\");\n\tif (copied.entries.length > limits.maxEntries || checkpoint.views.length > limits.maxEntries)\n\t\tthrow new Error(\"Copied context epoch item budget exceeded\");\n\tstringifyBoundedJson(copied, limits.maxSourceBytes);\n\tconst oldByRevision = new Map([...oldById.values()].map((source) => [source.revision, source]));\n\tconst destination = new Map<string, IndexedSourceEvent>();\n\tfor (const source of oldById.values()) {\n\t\tconst actual = await history.get(source.id);\n\t\tif (actual) destination.set(source.id, actual);\n\t}\n\tconst prefixViews = new Map<string, SessionHistoryReadView>();\n\tconst prefix = async (source: SourceSnapshotRef): Promise<SessionHistoryReadView> => {\n\t\tif (\n\t\t\tsource.sessionId !== copied.sessionId ||\n\t\t\tsource.sessionFile !== copied.sessionFile ||\n\t\t\t!source.persistent ||\n\t\t\t!Number.isSafeInteger(source.sourceSequence) ||\n\t\t\tsource.sourceSequence < 0 ||\n\t\t\tsource.sourceSequence > copied.through\n\t\t)\n\t\t\tthrow new Error(\"Copied epoch recipe is outside the captured old source\");\n\t\tconst key = JSON.stringify(source);\n\t\tconst existing = prefixViews.get(key);\n\t\tif (existing) return existing;\n\t\tlet leafId = source.leafId;\n\t\tif (leafId !== null && (!oldById.has(leafId) || oldById.get(leafId)!.sequence > source.sourceSequence))\n\t\t\tthrow new Error(\"Copied epoch leaf is outside its captured prefix\");\n\t\tconst seen = new Set<string>();\n\t\twhile (leafId !== null && !destination.has(leafId)) {\n\t\t\tif (seen.has(leafId)) throw new Error(\"Copied epoch parent path is unresolved\");\n\t\t\tseen.add(leafId);\n\t\t\tconst old = oldById.get(leafId);\n\t\t\tif (!old) throw new Error(\"Copied epoch parent source is unavailable\");\n\t\t\tleafId = old.parentId;\n\t\t}\n\t\tconst rows = [...oldById.values()]\n\t\t\t.filter((old) => old.sequence <= source.sourceSequence)\n\t\t\t.flatMap((old) => {\n\t\t\t\tconst actual = destination.get(old.id);\n\t\t\t\treturn actual ? [actual] : [];\n\t\t\t});\n\t\tconst last = rows.reduce<IndexedSourceEvent | undefined>(\n\t\t\t(previous, actual) => (!previous || actual.sequence > previous.sequence ? actual : previous),\n\t\t\tundefined,\n\t\t);\n\t\tif (!last) throw new Error(\"Copied epoch prefix has no preserved source\");\n\t\tconst narrowed = await view.atSnapshot!({ ...view.source, leafId, sourceSequence: last.sequence });\n\t\tprefixViews.set(key, narrowed);\n\t\treturn narrowed;\n\t};\n\tawait prefix(checkpoint.source);\n\tconst copyReference = async <\n\t\tT extends EpochViewReference | NonNullable<ContextEpochCheckpoint[\"selectedSkills\"]>[number][\"view\"],\n\t>(\n\t\tpinned: T,\n\t): Promise<T> => {\n\t\tconst old = oldById.get(pinned.ref.entryId);\n\t\tif (\n\t\t\t!old ||\n\t\t\told.revision !== pinned.ref.revision ||\n\t\t\told.sequence !== pinned.ref.sequence ||\n\t\t\told.kind !== pinned.ref.kind ||\n\t\t\t!isDeepStrictEqual(old.locator, pinned.ref.locator)\n\t\t)\n\t\t\tthrow new Error(\"Copied epoch recipe does not match its captured source\");\n\t\tconst read = await prefix(pinned.source);\n\t\tconst actual = await read.get(old.id);\n\t\tif (!actual || actual.kind !== old.kind) throw new Error(\"Copied epoch view source is unavailable\");\n\t\tconst ref = {\n\t\t\tentryId: actual.id,\n\t\t\tsequence: actual.sequence,\n\t\t\tkind: pinned.ref.kind,\n\t\t\tlocator: { ...actual.locator },\n\t\t\trevision: actual.revision,\n\t\t\tauthority: actual.authority,\n\t\t\tqualification: actual.qualification,\n\t\t\tretention: actual.retention,\n\t\t};\n\t\tlet sourceRevision = actual.revision;\n\t\tif (ref.kind !== \"compaction\") {\n\t\t\tconst original: unknown = JSON.parse(pinned.sourceRevision);\n\t\t\tif (\n\t\t\t\t!Array.isArray(original) ||\n\t\t\t\toriginal[0] !== old.revision ||\n\t\t\t\toriginal.some((revision) => typeof revision !== \"string\")\n\t\t\t)\n\t\t\t\tthrow new Error(\"Copied epoch frozen revisions are unavailable\");\n\t\t\tconst updates = old.updateTarget ? (await read.contextUpdates(old.updateTarget)).refs : [];\n\t\t\tconst expected = original.slice(1).map((revision) => oldByRevision.get(revision));\n\t\t\tif (\n\t\t\t\texpected.some((source) => !source || source.sequence > pinned.source.sourceSequence) ||\n\t\t\t\t!isDeepStrictEqual(\n\t\t\t\t\texpected.map((source) => source!.id),\n\t\t\t\t\tupdates.map((source) => source.entryId),\n\t\t\t\t)\n\t\t\t)\n\t\t\t\tthrow new Error(\"Copied epoch update sources were not preserved\");\n\t\t\tsourceRevision = JSON.stringify([actual.revision, ...updates.map((update) => update.revision)]);\n\t\t} else if (pinned.sourceRevision !== old.revision || pinned.retainedMessageCount === undefined) {\n\t\t\tthrow new Error(\"Copied epoch summary source is unavailable\");\n\t\t}\n\t\treturn {\n\t\t\tsource: read.source,\n\t\t\tref,\n\t\t\tsourceRevision,\n\t\t\t...(pinned.retainedMessageCount === undefined ? {} : { retainedMessageCount: pinned.retainedMessageCount }),\n\t\t\t...(pinned.rendering === undefined ? {} : { rendering: pinned.rendering }),\n\t\t} as T;\n\t};\n\tconst views: EpochViewReference[] = [];\n\tfor (const pinned of checkpoint.views) views.push(await copyReference(pinned));\n\tconst selectedSkills: Array<NonNullable<ContextEpochCheckpoint[\"selectedSkills\"]>[number]> | undefined =\n\t\tcheckpoint.selectedSkills ? [] : undefined;\n\tfor (const skill of checkpoint.selectedSkills ?? [])\n\t\tselectedSkills!.push({ name: skill.name, view: await copyReference(skill.view) });\n\tif (!(await view.get(checkpoint.literalTailId))) throw new Error(\"Copied epoch literal tail is unavailable\");\n\tconst tasks = await readTaskStateFromView(view, {\n\t\tmaxItems: limits.maxEntries,\n\t\tmaxSourceBytes: limits.maxSourceBytes,\n\t\tmaxViewBytes: limits.maxSourceBytes,\n\t});\n\tconst taskFrame = compileTaskFrame(tasks, taskFrameLimits({ maxBytes: Math.min(16_384, limits.maxSourceBytes) }));\n\tconst lowered =\n\t\tcopied.retained || origin.retention === \"retained-import\" || hydrated.source.retention === \"retained-import\";\n\tconst inherited =\n\t\tcheckpoint.version === 5 && lowered ? { ...checkpoint, pendingRequestContract: undefined } : checkpoint;\n\tconst { replayContract, publicWindow: _publicWindow, continuation, ...unchanged } = inherited;\n\tconst rebuiltContinuation = continuation\n\t\t? {\n\t\t\t\tkind: continuation.kind,\n\t\t\t\tpublicTailThrough: (await prefix(continuation.publicTailThrough)).source,\n\t\t\t}\n\t\t: undefined;\n\tconst rebuilt = snapshotContextEpoch(\n\t\t{\n\t\t\t...unchanged,\n\t\t\tsource: view.source,\n\t\t\tviews,\n\t\t\t...(selectedSkills?.length ? { selectedSkills } : {}),\n\t\t\ttaskFrame,\n\t\t\tresourceRevision: undefined, // Explicit copies must capture their destination owner anew.\n\t\t\t...(rebuiltContinuation ? { continuation: rebuiltContinuation } : {}),\n\t\t\t...(!lowered && replayContract !== undefined ? { replayContract } : {}),\n\t\t},\n\t\tlimits.maxSourceBytes,\n\t);\n\treturn {\n\t\tcheckpoint: rebuilt,\n\t\ttokensBefore: entry.tokensBefore,\n\t\t...(checkpoint.includeSummary\n\t\t\t? {\n\t\t\t\t\tsummary: {\n\t\t\t\t\t\tsummary: entry.summary,\n\t\t\t\t\t\tdetails: { ...entry.details },\n\t\t\t\t\t\tfromHook: entry.fromHook,\n\t\t\t\t\t\tcustomInstructions: entry.customInstructions, // The copied original alone retains its model usage.\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n"]}
|
|
@@ -11,6 +11,8 @@ export declare const CONTEXT_POLICY_EPOCH_RENDERER = "native-canonical-epoch/5";
|
|
|
11
11
|
export declare const CONTEXT_TOOL_EPOCH_RENDERER = "native-canonical-epoch/6";
|
|
12
12
|
/** Selection-bearing v4/v5/v6 variants; older readers must refuse rather than drop these refs. */
|
|
13
13
|
export declare const CONTEXT_SKILL_EPOCH_RENDERER = "native-canonical-epoch/7";
|
|
14
|
+
/** Source-backed summary with retained public tool groups, not a measured MAIN request. */
|
|
15
|
+
export declare const CONTEXT_TOOL_SUMMARY_RENDERER = "native-canonical-epoch/8";
|
|
14
16
|
/** Descriptive, source-backed outcomes in the existing accepted epoch, not an execution store. */
|
|
15
17
|
export interface ToolContinuationGroup {
|
|
16
18
|
readonly assistantEntryId: string;
|
|
@@ -49,7 +51,7 @@ export interface EpochViewReference {
|
|
|
49
51
|
readonly rendering?: "public-history/1" | "public-tool-continuation/1";
|
|
50
52
|
}
|
|
51
53
|
interface ContextEpochFields {
|
|
52
|
-
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;
|
|
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;
|
|
53
55
|
readonly source: SourceSnapshotRef;
|
|
54
56
|
readonly includeSummary?: true;
|
|
55
57
|
/** Granted by an actual accepted adapter projection, never a caller profile name. */
|
|
@@ -64,7 +66,7 @@ interface ContextEpochFields {
|
|
|
64
66
|
readonly views: readonly EpochViewReference[];
|
|
65
67
|
/** Captured versions, not a body cache or authority inferred from transcript markup. */
|
|
66
68
|
readonly selectedSkills?: readonly SelectedSkillReference[];
|
|
67
|
-
/**
|
|
69
|
+
/** v6 requests and v8 summaries retain whole public groups and their exact outcome refs. */
|
|
68
70
|
readonly toolContinuations?: readonly ToolContinuationGroup[];
|
|
69
71
|
/** Derived display only. The task reducer remains the authority for later changes. */
|
|
70
72
|
readonly taskFrame?: CompiledTaskFrame;
|
|
@@ -80,6 +82,14 @@ export type ContextEpochCheckpoint = ContextEpochFields & ({
|
|
|
80
82
|
readonly policyOnly?: never;
|
|
81
83
|
readonly requestContract?: never;
|
|
82
84
|
readonly pendingRequestContract?: never;
|
|
85
|
+
} | {
|
|
86
|
+
readonly version: 8;
|
|
87
|
+
readonly mode: ContextMode;
|
|
88
|
+
readonly representation: null;
|
|
89
|
+
readonly includeSummary: true;
|
|
90
|
+
readonly policyOnly?: never;
|
|
91
|
+
readonly requestContract?: never;
|
|
92
|
+
readonly pendingRequestContract?: never;
|
|
83
93
|
} | {
|
|
84
94
|
readonly version: 5;
|
|
85
95
|
readonly mode: ContextMode;
|
|
@@ -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;AAEvE,kGAAkG;AAClG,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,SAAS;QACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,GAAG,UAAU,GAAG,UAAU,CAAC,CAAC;QAC1E,QAAQ,CAAC,OAAO,EAAE,iBAAiB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E,6BAA6B,EACtC,UAAU,EAAE,sBAAsB,GAAG,SAAS,EAC9C,QAAQ,EAAE,MAAM,GACd,MAAM,CAyER","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\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\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/** Only v6 records this whole-group public representation and its 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: 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.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([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\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 ? !(\"mode\" in value) || (value.mode !== \"on\" && value.mode !== \"off\") : \"mode\" in value) ||\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) &&\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) ||\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 && value.version !== 4 && value.version !== 5 && value.version !== 6) ||\n\t\t\t\tvalue.publicWindow !== true)) ||\n\t\t(\"toolContinuations\" in value && value.version !== 6) ||\n\t\t(value.version === 6 &&\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!(\"publicWindow\" in value) ||\n\t\t\t\tvalue.publicWindow !== true ||\n\t\t\t\t!(\"replayContract\" in value) ||\n\t\t\t\tvalue.replayContract !== \"message-groups\")) ||\n\t\t(\"continuation\" in value &&\n\t\t\t((value.version !== 3 && value.version !== 4 && value.version !== 5 && value.version !== 6) ||\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): string {\n\tif (\n\t\t!assessment?.profile ||\n\t\tassessment.limitSource !== \"explicit-profile\" ||\n\t\t!assessment.route ||\n\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 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\tassessment.route === request.url &&\n\t\t\"model\" in body &&\n\t\tbody.model === \"deepseek-flash\" &&\n\t\tassessment.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\tapi: request.api,\n\t\t\tprovider: request.provider,\n\t\t\troute: assessment.route,\n\t\t\tmodel: assessment.model,\n\t\t\tprofile: assessment.profile,\n\t\t\tcontextTokens: assessment.contextTokens,\n\t\t\toutputReserveTokens: assessment.outputReserveTokens,\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,6BAA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,GAAG,SAAS,CA8GvG;AAED,6FAA6F;AAC7F,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,6BAA6B,EACtC,UAAU,EAAE,sBAAsB,GAAG,SAAS,EAC9C,QAAQ,EAAE,MAAM,GACd,MAAM,CAyER","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): string {\n\tif (\n\t\t!assessment?.profile ||\n\t\tassessment.limitSource !== \"explicit-profile\" ||\n\t\t!assessment.route ||\n\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 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\tassessment.route === request.url &&\n\t\t\"model\" in body &&\n\t\tbody.model === \"deepseek-flash\" &&\n\t\tassessment.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\tapi: request.api,\n\t\t\tprovider: request.provider,\n\t\t\troute: assessment.route,\n\t\t\tmodel: assessment.model,\n\t\t\tprofile: assessment.profile,\n\t\t\tcontextTokens: assessment.contextTokens,\n\t\t\toutputReserveTokens: assessment.outputReserveTokens,\n\t\t\tconfiguration,\n\t\t\tpolicy,\n\t\t},\n\t\tmaxBytes,\n\t);\n}\n"]}
|
|
@@ -9,8 +9,10 @@ export const CONTEXT_POLICY_EPOCH_RENDERER = "native-canonical-epoch/5";
|
|
|
9
9
|
export const CONTEXT_TOOL_EPOCH_RENDERER = "native-canonical-epoch/6";
|
|
10
10
|
/** Selection-bearing v4/v5/v6 variants; older readers must refuse rather than drop these refs. */
|
|
11
11
|
export const CONTEXT_SKILL_EPOCH_RENDERER = "native-canonical-epoch/7";
|
|
12
|
+
/** Source-backed summary with retained public tool groups, not a measured MAIN request. */
|
|
13
|
+
export const CONTEXT_TOOL_SUMMARY_RENDERER = "native-canonical-epoch/8";
|
|
12
14
|
export function contextEpochMode(checkpoint, initial = "on") {
|
|
13
|
-
return checkpoint ? (checkpoint.version === 5 ? checkpoint.mode : "on") : initial;
|
|
15
|
+
return checkpoint ? (checkpoint.version === 5 || checkpoint.version === 8 ? checkpoint.mode : "on") : initial;
|
|
14
16
|
}
|
|
15
17
|
function isRequestContract(value) {
|
|
16
18
|
if (!value || typeof value !== "object")
|
|
@@ -83,8 +85,9 @@ export function readContextEpoch(details, maxBytes) {
|
|
|
83
85
|
(value.version === 4 && value.renderer === "native-canonical-epoch/4") ||
|
|
84
86
|
(value.version === 5 && value.renderer === CONTEXT_POLICY_EPOCH_RENDERER) ||
|
|
85
87
|
(value.version === 6 && value.renderer === CONTEXT_TOOL_EPOCH_RENDERER) ||
|
|
88
|
+
(value.version === 8 && value.renderer === CONTEXT_TOOL_SUMMARY_RENDERER) ||
|
|
86
89
|
([4, 5, 6].includes(value.version) && value.renderer === CONTEXT_SKILL_EPOCH_RENDERER)) ||
|
|
87
|
-
(value.renderer === CONTEXT_SKILL_EPOCH_RENDERER
|
|
90
|
+
(value.renderer === CONTEXT_SKILL_EPOCH_RENDERER || (value.version === 8 && "selectedSkills" in value)
|
|
88
91
|
? !("selectedSkills" in value) ||
|
|
89
92
|
!Array.isArray(value.selectedSkills) ||
|
|
90
93
|
value.selectedSkills.length === 0 ||
|
|
@@ -102,7 +105,11 @@ export function readContextEpoch(details, maxBytes) {
|
|
|
102
105
|
!("literalTailId" in value) ||
|
|
103
106
|
typeof value.literalTailId !== "string" ||
|
|
104
107
|
!("representation" in value) ||
|
|
105
|
-
(value.version === 5
|
|
108
|
+
(value.version === 5 || value.version === 8
|
|
109
|
+
? !("mode" in value) || (value.mode !== "on" && value.mode !== "off")
|
|
110
|
+
: "mode" in value) ||
|
|
111
|
+
(value.version === 8 &&
|
|
112
|
+
(value.representation !== null || !("includeSummary" in value) || value.includeSummary !== true)) ||
|
|
106
113
|
(value.version === 5 &&
|
|
107
114
|
(value.representation !== null || !("policyOnly" in value) || value.policyOnly !== true)) ||
|
|
108
115
|
("policyOnly" in value &&
|
|
@@ -119,12 +126,12 @@ export function readContextEpoch(details, maxBytes) {
|
|
|
119
126
|
("requestContract" in value && (value.version !== 5 || !isRequestContract(value.requestContract))) ||
|
|
120
127
|
!(typeof value.representation === "string" ||
|
|
121
128
|
(value.version === 5 && value.representation === null && "policyOnly" in value && value.policyOnly === true) ||
|
|
122
|
-
((value.version === 2 || value.version === 3 || value.version === 4) &&
|
|
129
|
+
((value.version === 2 || value.version === 3 || value.version === 4 || value.version === 8) &&
|
|
123
130
|
value.representation === null &&
|
|
124
131
|
"includeSummary" in value &&
|
|
125
132
|
value.includeSummary === true)) ||
|
|
126
133
|
("includeSummary" in value &&
|
|
127
|
-
((value.version !== 2 && value.version !== 3 && value.version !== 4) ||
|
|
134
|
+
((value.version !== 2 && value.version !== 3 && value.version !== 4 && value.version !== 8) ||
|
|
128
135
|
value.includeSummary !== true ||
|
|
129
136
|
value.representation !== null)) ||
|
|
130
137
|
("replayContract" in value &&
|
|
@@ -134,19 +141,28 @@ export function readContextEpoch(details, maxBytes) {
|
|
|
134
141
|
(typeof value.resourceRevision !== "string" ||
|
|
135
142
|
Buffer.byteLength(value.resourceRevision, "utf8") > MAX_RESOURCE_REVISION_BYTES)) ||
|
|
136
143
|
("publicWindow" in value &&
|
|
137
|
-
((value.version !== 3 &&
|
|
144
|
+
((value.version !== 3 &&
|
|
145
|
+
value.version !== 4 &&
|
|
146
|
+
value.version !== 5 &&
|
|
147
|
+
value.version !== 6 &&
|
|
148
|
+
value.version !== 8) ||
|
|
138
149
|
value.publicWindow !== true)) ||
|
|
139
|
-
("toolContinuations" in value && value.version !== 6) ||
|
|
140
|
-
(value.version === 6 &&
|
|
150
|
+
("toolContinuations" in value && value.version !== 6 && value.version !== 8) ||
|
|
151
|
+
((value.version === 6 || value.version === 8) &&
|
|
141
152
|
(!("toolContinuations" in value) ||
|
|
142
153
|
!Array.isArray(value.toolContinuations) ||
|
|
143
154
|
!value.toolContinuations.length ||
|
|
144
|
-
!("publicWindow" in value) ||
|
|
145
|
-
value.publicWindow !== true ||
|
|
146
155
|
!("replayContract" in value) ||
|
|
147
|
-
value.
|
|
156
|
+
(value.version === 6 &&
|
|
157
|
+
(!("publicWindow" in value) ||
|
|
158
|
+
value.publicWindow !== true ||
|
|
159
|
+
value.replayContract !== "message-groups")))) ||
|
|
148
160
|
("continuation" in value &&
|
|
149
|
-
((value.version !== 3 &&
|
|
161
|
+
((value.version !== 3 &&
|
|
162
|
+
value.version !== 4 &&
|
|
163
|
+
value.version !== 5 &&
|
|
164
|
+
value.version !== 6 &&
|
|
165
|
+
value.version !== 8) ||
|
|
150
166
|
!value.continuation ||
|
|
151
167
|
typeof value.continuation !== "object" ||
|
|
152
168
|
!("kind" in value.continuation) ||
|
|
@@ -1 +1 @@
|
|
|
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;AAiGvE,MAAM,UAAU,gBAAgB,CAC/B,UAA8C,EAC9C,OAAO,GAAgB,IAAI,EACb;IACd,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAA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AC,iDAAiD,CAAC,CAAC;QACzF,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IAC5B,CAAC;IACD,MAAM,KAAK,GAAY,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,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,EAAE,OAAO,CAAC,GAAG;QAChB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,mBAAmB,EAAE,UAAU,CAAC,mBAAmB;QACnD,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\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\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/** Only v6 records this whole-group public representation and its 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: 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.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([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\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 ? !(\"mode\" in value) || (value.mode !== \"on\" && value.mode !== \"off\") : \"mode\" in value) ||\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) &&\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) ||\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 && value.version !== 4 && value.version !== 5 && value.version !== 6) ||\n\t\t\t\tvalue.publicWindow !== true)) ||\n\t\t(\"toolContinuations\" in value && value.version !== 6) ||\n\t\t(value.version === 6 &&\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!(\"publicWindow\" in value) ||\n\t\t\t\tvalue.publicWindow !== true ||\n\t\t\t\t!(\"replayContract\" in value) ||\n\t\t\t\tvalue.replayContract !== \"message-groups\")) ||\n\t\t(\"continuation\" in value &&\n\t\t\t((value.version !== 3 && value.version !== 4 && value.version !== 5 && value.version !== 6) ||\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): string {\n\tif (\n\t\t!assessment?.profile ||\n\t\tassessment.limitSource !== \"explicit-profile\" ||\n\t\t!assessment.route ||\n\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 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\tassessment.route === request.url &&\n\t\t\"model\" in body &&\n\t\tbody.model === \"deepseek-flash\" &&\n\t\tassessment.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\tapi: request.api,\n\t\t\tprovider: request.provider,\n\t\t\troute: assessment.route,\n\t\t\tmodel: assessment.model,\n\t\t\tprofile: assessment.profile,\n\t\t\tcontextTokens: assessment.contextTokens,\n\t\t\toutputReserveTokens: assessment.outputReserveTokens,\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,CAA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CAAC,GAAG,KAAK,CAAC;IAC5B,CAAC;IACD,MAAM,KAAK,GAAY,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,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,EAAE,OAAO,CAAC,GAAG;QAChB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,mBAAmB,EAAE,UAAU,CAAC,mBAAmB;QACnD,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): string {\n\tif (\n\t\t!assessment?.profile ||\n\t\tassessment.limitSource !== \"explicit-profile\" ||\n\t\t!assessment.route ||\n\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 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\tassessment.route === request.url &&\n\t\t\"model\" in body &&\n\t\tbody.model === \"deepseek-flash\" &&\n\t\tassessment.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\tapi: request.api,\n\t\t\tprovider: request.provider,\n\t\t\troute: assessment.route,\n\t\t\tmodel: assessment.model,\n\t\t\tprofile: assessment.profile,\n\t\t\tcontextTokens: assessment.contextTokens,\n\t\t\toutputReserveTokens: assessment.outputReserveTokens,\n\t\t\tconfiguration,\n\t\t\tpolicy,\n\t\t},\n\t\tmaxBytes,\n\t);\n}\n"]}
|
|
@@ -6,6 +6,7 @@ export declare function readSessionBootstrap(sessionManager: SessionManager, lim
|
|
|
6
6
|
includeMessages?: boolean;
|
|
7
7
|
allowPendingToolPublic?: boolean;
|
|
8
8
|
initialContextMode?: ContextMode;
|
|
9
|
+
purpose?: "request" | "read";
|
|
9
10
|
}): Promise<{
|
|
10
11
|
context: SessionContext;
|
|
11
12
|
hasExistingSession: boolean;
|