effect-durable-agent 0.1.0-alpha.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/assert-never-CoyUpoRB.js +18 -0
- package/dist/assert-never-CoyUpoRB.js.map +1 -0
- package/dist/{commands-Ce1ec6kH.d.ts → commands-BUquEZVP.d.ts} +31 -12
- package/dist/{compaction-BgDr5VJy.js → compaction-D7WJa899.js} +63 -13
- package/dist/compaction-D7WJa899.js.map +1 -0
- package/dist/{context-projection-n6Rdup0N.d.ts → context-projection-Bezx3drD.d.ts} +16 -40
- package/dist/{core-CYT6DBaS.d.ts → core-BcimKMIv.d.ts} +5 -3
- package/dist/delivery-B_LDTuIB.d.ts +3169 -0
- package/dist/delivery-BoF-NZbZ.js +507 -0
- package/dist/delivery-BoF-NZbZ.js.map +1 -0
- package/dist/domain/command-queues.d.ts +81 -2
- package/dist/domain/command-queues.js +1 -1
- package/dist/domain/command-queues.js.map +1 -1
- package/dist/domain/context-projection.d.ts +1 -1
- package/dist/domain/context-projection.js +1 -1
- package/dist/domain/context-projection.js.map +1 -1
- package/dist/domain/message-transcript.d.ts +36 -2
- package/dist/domain/message-transcript.js +10 -2
- package/dist/domain/message-transcript.js.map +1 -1
- package/dist/domain/model-usage.d.ts +1 -1
- package/dist/domain/model-usage.js +1 -1
- package/dist/domain/reduced-state-schema.d.ts +3 -992
- package/dist/domain/reduced-state-schema.js +126 -7
- package/dist/domain/reduced-state-schema.js.map +1 -1
- package/dist/domain/reduced-state.d.ts +2 -2
- package/dist/domain/reduced-state.js +937 -2
- package/dist/domain/reduced-state.js.map +1 -0
- package/dist/domain/run-scheduling.d.ts +2 -0
- package/dist/domain/run-scheduling.js +127 -0
- package/dist/domain/run-scheduling.js.map +1 -0
- package/dist/{durable-br2C1bWK.d.ts → durable-BXqwM70o.d.ts} +8983 -2800
- package/dist/{durable-BGFvX7Mh.js → durable-Da57Rcml.js} +243 -15
- package/dist/durable-Da57Rcml.js.map +1 -0
- package/dist/{envelope-DxQzo5rN.js → envelope-BSI_Xh-f.js} +31 -6
- package/dist/envelope-BSI_Xh-f.js.map +1 -0
- package/dist/{envelope-DkZyMIgp.d.ts → envelope-CJnPfbjC.d.ts} +121 -11
- package/dist/{event-factory-DTFdy0Cb.js → event-factory-BUoBwqAy.js} +7 -3
- package/dist/event-factory-BUoBwqAy.js.map +1 -0
- package/dist/{events-LZFNoESe.d.ts → events-AIIwZ6dS.d.ts} +139 -137
- package/dist/{id-generator-Ckl8_XWW.d.ts → id-generator-BKGoKjt-.d.ts} +3 -3
- package/dist/in-memory-E497WhtS.js +150 -0
- package/dist/in-memory-E497WhtS.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -6
- package/dist/interpreter-BwYN2PCC.js +1453 -0
- package/dist/interpreter-BwYN2PCC.js.map +1 -0
- package/dist/{keep-alive-Chl5SJxy.d.ts → keep-alive-_zFCUvt3.d.ts} +1 -2
- package/dist/{model-resolver-BPPJAsuh.d.ts → model-resolver-O8Kn27GH.d.ts} +11 -5
- package/dist/{model-usage-CdBEkTwU.d.ts → model-usage-mttrPN0j.d.ts} +2 -3
- package/dist/records-D0ZIAOzd.js +675 -0
- package/dist/records-D0ZIAOzd.js.map +1 -0
- package/dist/reduced-state-YbjpihEf.d.ts +52933 -0
- package/dist/reduced-state-schema-B9TYxkP9.d.ts +2338 -0
- package/dist/{reducer-registry-aFjz_ZLT.d.ts → reducer-registry-Bqn5B4JO.d.ts} +12 -6
- package/dist/run-scheduling-wakeup-DX2zRAxd.d.ts +24 -0
- package/dist/services/compaction.d.ts +2 -2
- package/dist/services/compaction.js +2 -2
- package/dist/services/decider.d.ts +2 -0
- package/dist/services/decider.js +97 -0
- package/dist/services/decider.js.map +1 -0
- package/dist/services/id-generator.d.ts +1 -1
- package/dist/services/id-generator.js +6 -12
- package/dist/services/id-generator.js.map +1 -1
- package/dist/services/keep-alive.d.ts +1 -1
- package/dist/services/keep-alive.js.map +1 -1
- package/dist/services/model-call.d.ts +15 -0
- package/dist/services/model-call.js +15 -0
- package/dist/services/model-call.js.map +1 -0
- package/dist/services/model-resolver.d.ts +1 -1
- package/dist/services/model-resolver.js +1 -1
- package/dist/services/model-resolver.js.map +1 -1
- package/dist/services/prompt-projector.d.ts +2 -2
- package/dist/services/prompt-projector.js +49 -5
- package/dist/services/prompt-projector.js.map +1 -1
- package/dist/services/reducer-registry.d.ts +1 -1
- package/dist/services/reducer-registry.js +19 -6
- package/dist/services/reducer-registry.js.map +1 -1
- package/dist/services/run-scheduler.d.ts +2 -2
- package/dist/services/run-scheduler.js +25 -2
- package/dist/services/run-scheduler.js.map +1 -0
- package/dist/services/run-scheduling-wakeup.d.ts +2 -0
- package/dist/services/run-scheduling-wakeup.js +13 -0
- package/dist/services/run-scheduling-wakeup.js.map +1 -0
- package/dist/services/runtime-layer.d.ts +21 -33
- package/dist/services/runtime-layer.js +24 -16
- package/dist/services/runtime-layer.js.map +1 -1
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +32 -20
- package/dist/services/runtime.js.map +1 -1
- package/dist/services/session-event-observer.d.ts +1 -1
- package/dist/services/session-event-observer.js.map +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +57 -10
- package/dist/services/session-query.js.map +1 -1
- package/dist/services/session-state.d.ts +2 -2
- package/dist/services/session-state.js +2 -1
- package/dist/services/session-store.d.ts +2 -2
- package/dist/services/session-store.js +143 -38
- package/dist/services/session-store.js.map +1 -1
- package/dist/services/sink-checkpoint-store.d.ts +1 -1
- package/dist/services/sink-checkpoint-store.js +2 -1
- package/dist/services/sink-checkpoint-store.js.map +1 -1
- package/dist/services/sink-registry.d.ts +2 -2
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/span-names.d.ts +1 -1
- package/dist/services/span-names.js +7 -1
- package/dist/services/span-names.js.map +1 -1
- package/dist/services/tool-registry.d.ts +2 -2
- package/dist/services/tool-registry.js +12 -3
- package/dist/services/tool-registry.js.map +1 -1
- package/dist/services/tracing.d.ts +3 -3
- package/dist/services/tracing.js +2 -2
- package/dist/services/tracing.js.map +1 -1
- package/dist/session-admission-WE8J_0z9.js +138 -0
- package/dist/session-admission-WE8J_0z9.js.map +1 -0
- package/dist/{session-event-observer-DaFMKKNc.d.ts → session-event-observer-BWQUJTcN.d.ts} +3 -3
- package/dist/{session-state-Bkc6u-Wr.js → session-state-D02LCVcC.js} +815 -170
- package/dist/session-state-D02LCVcC.js.map +1 -0
- package/dist/session-store-DaSHeg8Q.d.ts +3343 -0
- package/dist/{sink-checkpoint-store-M7qIxoSH.d.ts → sink-checkpoint-store-CUvIVvlZ.d.ts} +3 -4
- package/dist/sink-registry-AOjX5_A1.js +369 -0
- package/dist/sink-registry-AOjX5_A1.js.map +1 -0
- package/dist/subscription-BhwUmsl4.d.ts +966 -0
- package/dist/subscription-D7U4Tziv.js +505 -0
- package/dist/subscription-D7U4Tziv.js.map +1 -0
- package/dist/testkit/layers.d.ts +33 -23
- package/dist/testkit/layers.js +34 -19
- package/dist/testkit/layers.js.map +1 -1
- package/dist/testkit/transcript.d.ts +232 -0
- package/dist/testkit/transcript.js +1526 -0
- package/dist/testkit/transcript.js.map +1 -0
- package/dist/{tracing-BXHAkxkx.d.ts → tracing-BwjbF285.d.ts} +1 -2
- package/dist/transcript.d.ts +101 -0
- package/dist/transcript.js +107 -0
- package/dist/transcript.js.map +1 -0
- package/dist/types/commands.d.ts +2 -2
- package/dist/types/commands.js +8 -3
- package/dist/types/commands.js.map +1 -1
- package/dist/types/core.d.ts +2 -2
- package/dist/types/core.js +3 -1
- package/dist/types/core.js.map +1 -1
- package/dist/types/events/durable.d.ts +2 -2
- package/dist/types/events/durable.js +2 -2
- package/dist/types/events.d.ts +5 -5
- package/dist/types/events.js +3 -3
- package/dist/types/tracing.d.ts +1 -1
- package/dist/types/tracing.js.map +1 -1
- package/dist/websocket/events.d.ts +2 -0
- package/dist/websocket/events.js +2 -0
- package/dist/websocket.d.ts +2123 -2552
- package/dist/websocket.js +628 -442
- package/dist/websocket.js.map +1 -1
- package/dist/window-read-BELSkO-r.d.ts +113 -0
- package/dist/window-read-FJTCDaSq.js +264 -0
- package/dist/window-read-FJTCDaSq.js.map +1 -0
- package/package.json +41 -13
- package/dist/command-queues-DdDB_aYM.d.ts +0 -462
- package/dist/compaction-BgDr5VJy.js.map +0 -1
- package/dist/compaction-ch8z6G9x.d.ts +0 -165
- package/dist/durable-BGFvX7Mh.js.map +0 -1
- package/dist/envelope-DxQzo5rN.js.map +0 -1
- package/dist/event-factory-DTFdy0Cb.js.map +0 -1
- package/dist/event-factory-Di1jwQvm.d.ts +0 -87
- package/dist/index-BVVgDSdq.d.ts +0 -1
- package/dist/message-transcript-DQNlzxle.d.ts +0 -32
- package/dist/prompt-projector-f4ElyXCE.d.ts +0 -39
- package/dist/reduced-state-DF0-6mbR.js +0 -921
- package/dist/reduced-state-DF0-6mbR.js.map +0 -1
- package/dist/run-scheduler-CAt7dF6C.js +0 -21
- package/dist/run-scheduler-CAt7dF6C.js.map +0 -1
- package/dist/run-scheduler-xkhZyto5.d.ts +0 -44
- package/dist/runtime-DDSYP9jS.d.ts +0 -63
- package/dist/session-query-B72HY_0L.d.ts +0 -45
- package/dist/session-state-Bkc6u-Wr.js.map +0 -1
- package/dist/session-state-C9YLSAso.d.ts +0 -862
- package/dist/session-store-Cpi_NwTR.d.ts +0 -206
- package/dist/sink-registry-Bl-vQES6.d.ts +0 -133
- package/dist/sink-registry-NDgeyzO0.js +0 -272
- package/dist/sink-registry-NDgeyzO0.js.map +0 -1
- package/dist/tool-registry-BJaVNtw4.d.ts +0 -51
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"window-read-FJTCDaSq.js","names":[],"sources":["../src/transcript/store.ts","../src/transcript/window-read.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport type * as Effect from \"effect/Effect\";\nimport * as Schema from \"effect/Schema\";\n\nimport type { EDASessionStoreError } from \"../services/session-store\";\nimport type { TranscriptDefinition } from \"./mapping\";\nimport type {\n TranscriptVersionMeta,\n TranscriptWindow,\n TranscriptWindowLimits,\n TranscriptWindowSelector,\n} from \"./window\";\n\n/**\n * The transcript definitions a store maintains, fixed when the store is constructed.\n *\n * `current` is what new sessions start with and every session converges to. `previous` is\n * carried for one release only, so a session not yet rebuilt keeps its active rows maintained.\n * A stored version that matches neither is frozen.\n */\nexport interface TranscriptMaintenanceConfig {\n readonly current: TranscriptDefinition;\n readonly previous?: TranscriptDefinition;\n}\n\n/** A cursor minted for another log incarnation or transcript version. The client takes `Latest`. */\nexport class TranscriptCursorMismatch extends Schema.TaggedError<TranscriptCursorMismatch>()(\n \"TranscriptCursorMismatch\",\n { message: Schema.String },\n) {}\n\n/**\n * Storage-level transcript reads for one session.\n *\n * Maintenance has no method here: the store runs it inside its own append transaction for every\n * carried, healthy version, so `EDASessionStore.append` semantics are unchanged. These reads never\n * construct the model runtime and never include live active content, which only the delivery\n * layer can capture.\n */\nexport interface EDATranscriptStoreShape {\n /** Read one complete window of the served version at a single cut. */\n readonly readTranscriptWindow: (\n selector: TranscriptWindowSelector,\n limits: TranscriptWindowLimits,\n ) => Effect.Effect<TranscriptWindow, EDASessionStoreError | TranscriptCursorMismatch>;\n /** Maintenance state of every version present, for builders, backfill proofs and alerts. */\n readonly readTranscriptMeta: Effect.Effect<\n ReadonlyArray<TranscriptVersionMeta>,\n EDASessionStoreError\n >;\n}\n\n/** Transcript read port, provided alongside `EDASessionStore` by stores that maintain transcripts. */\nexport class EDATranscriptStore extends Context.Service<\n EDATranscriptStore,\n EDATranscriptStoreShape\n>()(\"@effect-durable-agent/EDATranscriptStore\") {}\n","import * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\n\nimport { SequenceNumber } from \"../types/core\";\nimport { NonNegativeInt } from \"../types/events/envelope\";\nimport type { TranscriptAliasNamespace } from \"./plan\";\nimport {\n TranscriptOrder,\n TranscriptRecordFromEnvelope,\n isPendingTranscriptUserRecord,\n transcriptRecordId,\n type AssistantRecordId,\n type TranscriptAssistantPart,\n type TranscriptBody,\n type TranscriptCursor,\n type TranscriptLogIncarnation,\n type TranscriptOrderKey,\n type TranscriptRecord,\n type TranscriptRecordId,\n type TranscriptToolRecord,\n type TranscriptTopLevelRecord,\n type TranscriptUserRecord,\n type TranscriptVersion,\n} from \"./records\";\nimport { TranscriptCursorMismatch } from \"./store\";\nimport type {\n TranscriptReadiness,\n TranscriptVersionMeta,\n TranscriptWindow,\n TranscriptWindowLimits,\n TranscriptWindowSelector,\n} from \"./window\";\n\n/**\n * Synchronous indexed reads of the served version at one cut, as a store provides them.\n *\n * Window assembly (paging, dependency collection, byte budgeting and body references) is shared\n * by every store through `readTranscriptWindowFrom`; a store only supplies these reads.\n */\nexport interface TranscriptWindowSource {\n readonly incarnation: TranscriptLogIncarnation;\n /** Maintenance state of the served (active) version; its cursor is the window's `throughSeq`. */\n readonly meta: TranscriptVersionMeta;\n /** False when this release no longer carries the served version (a missed session). */\n readonly carried: boolean;\n /** Top-level records before `key` (or before the end), newest first. */\n readonly topLevelBefore: (\n key: TranscriptOrderKey | undefined,\n limit: number,\n inclusive: boolean,\n ) => ReadonlyArray<TranscriptTopLevelRecord>;\n /** Top-level records after `key` (or after the start), oldest first. */\n readonly topLevelAfter: (\n key: TranscriptOrderKey | undefined,\n limit: number,\n inclusive: boolean,\n ) => ReadonlyArray<TranscriptTopLevelRecord>;\n readonly record: (id: TranscriptRecordId) => TranscriptRecord | undefined;\n readonly alias: (\n namespace: TranscriptAliasNamespace,\n key: string,\n ) => TranscriptRecordId | undefined;\n /** Tool records of one assistant (the typed dependency lookup). */\n readonly toolsOf: (assistantId: AssistantRecordId) => ReadonlyArray<TranscriptToolRecord>;\n /** Every user record still waiting for the agent (the pending-membership index). */\n readonly pendingUsers: () => ReadonlyArray<TranscriptUserRecord>;\n}\n\n/** Readiness of a served version: why its cut may be behind the log. */\nexport const transcriptReadiness = (\n meta: TranscriptVersionMeta,\n carried: boolean,\n): TranscriptReadiness => {\n if (!carried) return { _tag: \"UpdatingHistory\" };\n switch (meta.status._tag) {\n case \"Ok\":\n return { _tag: \"Ready\" };\n case \"Failed\":\n return {\n _tag: \"Degraded\",\n failedAtSeq: meta.status.failedAtSeq,\n error: meta.status.error,\n };\n }\n};\n\n/** The empty window served while no version is servable yet. */\nexport const buildingTranscriptWindow = (\n incarnation: TranscriptLogIncarnation,\n version: TranscriptVersion,\n): TranscriptWindow => ({\n incarnation,\n version,\n throughSeq: SequenceNumber.make(0),\n records: [],\n dependencies: [],\n hasOlder: false,\n hasNewer: false,\n readiness: { _tag: \"Building\" },\n});\n\n/**\n * The empty window served while no version is active.\n *\n * It reads as `Building` while the build of `currentVersion` can still finish. A build that has\n * frozen as failed is never retried (only a new definition repairs it), so once the build of\n * `currentVersion` has failed the window is `Unreadable` and names that failure, rather than\n * reading as building forever.\n */\nexport const inactiveTranscriptWindow = (\n incarnation: TranscriptLogIncarnation,\n currentVersion: TranscriptVersion,\n build: Pick<TranscriptVersionMeta, \"version\" | \"status\"> | undefined,\n): TranscriptWindow => {\n const building = buildingTranscriptWindow(incarnation, currentVersion);\n if (build?.version !== currentVersion || build.status._tag !== \"Failed\") return building;\n return {\n ...building,\n readiness: {\n _tag: \"Unreadable\",\n error: `transcript version ${build.version} failed to build at seq ${build.status.failedAtSeq}: ${build.status.error}`,\n },\n };\n};\n\nconst orderKey = (record: TranscriptTopLevelRecord): TranscriptOrderKey => ({\n anchorSeq: record.position?.anchorSeq ?? 0,\n ordinal: record.position?.ordinal ?? 0,\n recordId: record.id,\n});\n\nconst cursorKey = (cursor: TranscriptCursor): TranscriptOrderKey => ({\n anchorSeq: cursor.anchorSeq,\n ordinal: cursor.ordinal,\n recordId: cursor.recordId,\n});\n\n/**\n * Assemble one window from a source at a single cut.\n *\n * The response never contains anything newer than the served version's cursor: a frozen (failed\n * or no longer carried) version's rows, pending users and session context all stop at its last\n * good cut, which is the degraded-read rule. Bodies above the inline limit become references;\n * if the response still exceeds the byte budget, records are dropped from the far end of the\n * selection, keeping at least one so paging always progresses.\n */\nexport const readTranscriptWindowFrom = (\n source: TranscriptWindowSource,\n selector: TranscriptWindowSelector,\n limits: TranscriptWindowLimits,\n): Result.Result<TranscriptWindow, TranscriptCursorMismatch> => {\n const version = source.meta.version;\n for (const cursor of selectorCursors(selector)) {\n if (cursor.incarnation !== source.incarnation || cursor.version !== version) {\n return Result.fail(\n new TranscriptCursorMismatch({\n message: `cursor for ${cursor.incarnation}/${cursor.version} read against ${source.incarnation}/${version}`,\n }),\n );\n }\n }\n\n const selected = selectTopLevel(source, selector, limits.maxRecords);\n // Latest and Page(before) keep the newest records when trimming; the others keep the oldest.\n const keepNewest =\n selector._tag === \"Latest\" || (selector._tag === \"Page\" && selector.direction === \"before\");\n const kept = trimToBudget(\n dependencyGroups(\n source,\n selected.map((record) => withBodyRefs(record, limits.maxInlineBodyBytes)),\n limits.maxInlineBodyBytes,\n ),\n limits.maxBytes,\n keepNewest,\n );\n const top = kept.top;\n const dependencies = flattenDependencies(kept);\n\n const first = top[0];\n const last = top[top.length - 1];\n const [hasOlder, hasNewer] =\n first === undefined || last === undefined\n ? emptySelectionNeighbours(source, selector)\n : [\n source.topLevelBefore(orderKey(first), 1, false).length > 0,\n source.topLevelAfter(orderKey(last), 1, false).length > 0,\n ];\n\n return Result.succeed({\n incarnation: source.incarnation,\n version,\n throughSeq: source.meta.cursor,\n records: top,\n dependencies,\n hasOlder,\n hasNewer,\n readiness: transcriptReadiness(source.meta, source.carried),\n });\n};\n\nconst selectorCursors = (selector: TranscriptWindowSelector): ReadonlyArray<TranscriptCursor> => {\n switch (selector._tag) {\n case \"Latest\":\n return [];\n case \"Page\":\n return [selector.cursor];\n case \"Range\":\n return [selector.from, selector.to];\n }\n};\n\nconst selectTopLevel = (\n source: TranscriptWindowSource,\n selector: TranscriptWindowSelector,\n maxRecords: number,\n): ReadonlyArray<TranscriptTopLevelRecord> => {\n switch (selector._tag) {\n case \"Latest\":\n return [\n ...source.topLevelBefore(undefined, Math.min(selector.count, maxRecords), false),\n ].reverse();\n case \"Page\": {\n const count = Math.min(selector.count, maxRecords);\n return selector.direction === \"before\"\n ? [...source.topLevelBefore(cursorKey(selector.cursor), count, false)].reverse()\n : source.topLevelAfter(cursorKey(selector.cursor), count, false);\n }\n case \"Range\": {\n const to = cursorKey(selector.to);\n return source\n .topLevelAfter(cursorKey(selector.from), maxRecords, true)\n .filter((record) => TranscriptOrder(orderKey(record), to) <= 0);\n }\n }\n};\n\nconst emptySelectionNeighbours = (\n source: TranscriptWindowSource,\n selector: TranscriptWindowSelector,\n): readonly [boolean, boolean] => {\n switch (selector._tag) {\n case \"Latest\":\n return [false, false];\n case \"Page\": {\n const key = cursorKey(selector.cursor);\n return selector.direction === \"before\"\n ? [false, source.topLevelAfter(key, 1, true).length > 0]\n : [source.topLevelBefore(key, 1, true).length > 0, false];\n }\n case \"Range\":\n return [\n source.topLevelBefore(cursorKey(selector.from), 1, false).length > 0,\n source.topLevelAfter(cursorKey(selector.to), 1, false).length > 0,\n ];\n }\n};\n\n/**\n * A selection with its dependencies grouped by owner: the session context first, each top-level\n * record's run group and tools in part order, then pending users. A record may appear in several\n * groups; the window carries it once, where it first appears.\n */\ninterface DependencyGroups {\n readonly top: ReadonlyArray<TranscriptTopLevelRecord>;\n readonly leading: ReadonlyArray<TranscriptRecord>;\n /** Dependencies of `top[i]`, in order. */\n readonly perTop: ReadonlyArray<ReadonlyArray<TranscriptRecord>>;\n readonly trailing: ReadonlyArray<TranscriptRecord>;\n}\n\nconst dependencyGroups = (\n source: TranscriptWindowSource,\n top: ReadonlyArray<TranscriptTopLevelRecord>,\n maxInlineBodyBytes: number,\n): DependencyGroups => {\n const referenced = (records: ReadonlyArray<TranscriptRecord | undefined>) =>\n records.flatMap((record) =>\n record === undefined ? [] : [withBodyRefs(record, maxInlineBodyBytes)],\n );\n return {\n top,\n leading: referenced([source.record(transcriptRecordId.session)]),\n perTop: top.map((record) => referenced(recordDependencies(source, record))),\n trailing: referenced(\n [...source.pendingUsers()]\n .filter(isPendingTranscriptUserRecord)\n .sort(\n (left, right) =>\n left.submittedSeq - right.submittedSeq ||\n (left.id < right.id ? -1 : left.id > right.id ? 1 : 0),\n ),\n ),\n };\n};\n\n/** One top-level record's run group and tools, in part order. */\nconst recordDependencies = (\n source: TranscriptWindowSource,\n record: TranscriptTopLevelRecord,\n): ReadonlyArray<TranscriptRecord | undefined> => {\n switch (record.kind) {\n case \"assistant\": {\n const partOrder = new Map(\n record.parts.flatMap((part, index) =>\n part._tag === \"ToolCall\" && part.toolId !== undefined ? [[part.toolId, index]] : [],\n ),\n );\n const tools = [...source.toolsOf(record.id)].sort(\n (left, right) =>\n (partOrder.get(left.id) ?? Number.MAX_SAFE_INTEGER) -\n (partOrder.get(right.id) ?? Number.MAX_SAFE_INTEGER) ||\n (left.id < right.id ? -1 : left.id > right.id ? 1 : 0),\n );\n return [\n ...(record.runGroupId === undefined ? [] : [source.record(record.runGroupId)]),\n ...tools,\n ];\n }\n case \"user\": {\n // The consuming run's group, or, for a submission committed at its own run's start (the\n // interrupt path, which records no run on the user), the group that owns its command.\n const runId = record.state._tag === \"Consumed\" ? record.state.runId : undefined;\n const groupId =\n (runId === undefined ? undefined : source.alias(\"runId\", runId)) ??\n source.alias(\"runCommand\", record.commandId);\n return groupId === undefined ? [] : [source.record(groupId)];\n }\n case \"compaction\":\n return [];\n }\n};\n\n/** Each dependency once, where it first appears. */\nconst flattenDependencies = (groups: DependencyGroups): ReadonlyArray<TranscriptRecord> => {\n const dependencies = new Map<string, TranscriptRecord>();\n for (const record of [...groups.leading, ...groups.perTop.flat(), ...groups.trailing]) {\n if (!dependencies.has(record.id)) dependencies.set(record.id, record);\n }\n return Array.from(dependencies.values());\n};\n\n/**\n * Drop records from the far end of the selection until the window (records and their\n * dependencies) fits `maxBytes`, keeping at least one.\n *\n * Each record is measured once. A dependency's bytes count while any kept record (or the\n * window itself, for the session context and pending users) needs it, so dropping a record\n * subtracts its own bytes and those of the dependencies only it needed. The result equals\n * re-measuring the whole window after every drop, in time linear in the selection.\n */\nconst trimToBudget = (\n groups: DependencyGroups,\n maxBytes: number,\n keepNewest: boolean,\n): DependencyGroups => {\n const { top } = groups;\n if (top.length <= 1) return groups;\n const users = new Map<string, number>();\n const sizes = new Map<string, number>();\n const sizeOf = (record: TranscriptRecord) => {\n const known = sizes.get(record.id);\n if (known !== undefined) return known;\n const bytes = recordBytes(record);\n sizes.set(record.id, bytes);\n return bytes;\n };\n let total = 0;\n const need = (record: TranscriptRecord) => {\n const count = users.get(record.id) ?? 0;\n if (count === 0) total += sizeOf(record);\n users.set(record.id, count + 1);\n };\n const release = (record: TranscriptRecord) => {\n const count = (users.get(record.id) ?? 0) - 1;\n if (count === 0) total -= sizeOf(record);\n users.set(record.id, count);\n };\n // Within one record a dependency counts once, as the window carries it once.\n const ownDependencies = groups.perTop.map((records) => [\n ...new Map(records.map((record) => [record.id, record])).values(),\n ]);\n const topBytes = top.map(recordBytes);\n for (const record of [...groups.leading, ...groups.trailing]) need(record);\n top.forEach((_, index) => {\n total += topBytes[index] ?? 0;\n ownDependencies[index]?.forEach(need);\n });\n let from = 0;\n let to = top.length;\n while (to - from > 1 && total > maxBytes) {\n const dropped = keepNewest ? from++ : --to;\n total -= topBytes[dropped] ?? 0;\n ownDependencies[dropped]?.forEach(release);\n }\n return { ...groups, top: top.slice(from, to), perTop: groups.perTop.slice(from, to) };\n};\n\nconst encoder = new TextEncoder();\nconst encodeRecord = Schema.encodeSync(TranscriptRecordFromEnvelope);\n\nconst jsonBytes = (value: unknown): number => {\n const json = JSON.stringify(value);\n return json === undefined ? 0 : encoder.encode(json).length;\n};\n\n/** A record's size in the window, as it is encoded on the wire. */\nconst recordBytes = (record: TranscriptRecord): number => jsonBytes(encodeRecord(record));\n\nconst bodyRef = (body: TranscriptBody, maxInlineBodyBytes: number): TranscriptBody => {\n if (body._tag === \"Ref\") return body;\n const byteLength = jsonBytes(body.value);\n return byteLength <= maxInlineBodyBytes\n ? body\n : { _tag: \"Ref\", source: body.source, byteLength: NonNegativeInt.make(byteLength) };\n};\n\n/** Replace inline bodies above the limit with references to their immutable log source. */\nconst withBodyRefs = <R extends TranscriptRecord>(record: R, maxInlineBodyBytes: number): R => {\n switch (record.kind) {\n case \"tool\": {\n const tool: TranscriptToolRecord = {\n ...record,\n ...(record.params === undefined\n ? {}\n : { params: bodyRef(record.params, maxInlineBodyBytes) }),\n lifecycle:\n record.lifecycle._tag === \"Completed\"\n ? { _tag: \"Completed\", result: bodyRef(record.lifecycle.result, maxInlineBodyBytes) }\n : record.lifecycle,\n };\n return { ...record, ...tool };\n }\n case \"assistant\": {\n const parts = record.parts.map((part): TranscriptAssistantPart =>\n part._tag === \"ToolResult\"\n ? { ...part, result: bodyRef(part.result, maxInlineBodyBytes) }\n : part,\n );\n return { ...record, parts };\n }\n default:\n return record;\n }\n};\n"],"mappings":";;;;;;;;AA0BA,IAAa,2BAAb,cAA8C,OAAO,YAAsC,CAAC,CAC1F,4BACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;;AAwBH,IAAa,qBAAb,cAAwC,QAAQ,QAG9C,CAAC,CAAC,0CAA0C,CAAC,CAAC,CAAC;;;;ACajD,MAAa,uBACX,MACA,YACwB;CACxB,IAAI,CAAC,SAAS,OAAO,EAAE,MAAM,kBAAkB;CAC/C,QAAQ,KAAK,OAAO,MAApB;EACE,KAAK,MACH,OAAO,EAAE,MAAM,QAAQ;EACzB,KAAK,UACH,OAAO;GACL,MAAM;GACN,aAAa,KAAK,OAAO;GACzB,OAAO,KAAK,OAAO;EACrB;CACJ;AACF;;AAGA,MAAa,4BACX,aACA,aACsB;CACtB;CACA;CACA,YAAY,eAAe,KAAK,CAAC;CACjC,SAAS,CAAC;CACV,cAAc,CAAC;CACf,UAAU;CACV,UAAU;CACV,WAAW,EAAE,MAAM,WAAW;AAChC;;;;;;;;;AAUA,MAAa,4BACX,aACA,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AM,eAAe,WAAqC,UAAU,aAAa,MAAM,CAAC;AAExF,MAAM,WAAW,MAAsB,uBAA+C;CACpF,IAAI,KAAK,SAAS,OAAO,OAAO;CAChC,MAAM,aAAa,UAAU,KAAK,KAAK;CACvC,OAAO,cAAc,qBACjB,OACA;EAAE,MAAM;EAAO,QAAQ,KAAK;EAAQ,YAAY,eAAe,KAAK,UAAU;CAAE;AACtF;;AAGA,MAAM,gBAA4C,QAAW,uBAAkC;CAC7F,QAAQ,OAAO,MAAf;EACE,KAAK,QAAQ;GACX,MAAM,OAA6B;IACjC,GAAG;IACH,GAAI,OAAO,WAAW,KAAA,IAClB,CAAC,IACD,EAAE,QAAQ,QAAQ,OAAO,QAAQ,kBAAkB,EAAE;IACzD,WACE,OAAO,UAAU,SAAS,cACtB;KAAE,MAAM;KAAa,QAAQ,QAAQ,OAAO,UAAU,QAAQ,kBAAkB;IAAE,IAClF,OAAO;GACf;GACA,OAAO;IAAE,GAAG;IAAQ,GAAG;GAAK;EAC9B;EACA,KAAK,aAAa;GAChB,MAAM,QAAQ,OAAO,MAAM,KAAK,SAC9B,KAAK,SAAS,eACV;IAAE,GAAG;IAAM,QAAQ,QAAQ,KAAK,QAAQ,kBAAkB;GAAE,IAC5D,IACN;GACA,OAAO;IAAE,GAAG;IAAQ;GAAM;EAC5B;EACA,SACE,OAAO;CACX;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-durable-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A host-independent, event-sourced durable state-management and execution layer for agentic applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -58,18 +58,34 @@
|
|
|
58
58
|
"types": "./dist/domain/reduced-state-schema.d.ts",
|
|
59
59
|
"import": "./dist/domain/reduced-state-schema.js"
|
|
60
60
|
},
|
|
61
|
+
"./transcript": {
|
|
62
|
+
"types": "./dist/transcript.d.ts",
|
|
63
|
+
"import": "./dist/transcript.js"
|
|
64
|
+
},
|
|
61
65
|
"./websocket": {
|
|
62
66
|
"types": "./dist/websocket.d.ts",
|
|
63
67
|
"import": "./dist/websocket.js"
|
|
64
68
|
},
|
|
69
|
+
"./websocket/events": {
|
|
70
|
+
"types": "./dist/websocket/events.d.ts",
|
|
71
|
+
"import": "./dist/websocket/events.js"
|
|
72
|
+
},
|
|
65
73
|
"./services/keep-alive": {
|
|
66
74
|
"types": "./dist/services/keep-alive.d.ts",
|
|
67
75
|
"import": "./dist/services/keep-alive.js"
|
|
68
76
|
},
|
|
77
|
+
"./services/decider": {
|
|
78
|
+
"types": "./dist/services/decider.d.ts",
|
|
79
|
+
"import": "./dist/services/decider.js"
|
|
80
|
+
},
|
|
69
81
|
"./services/compaction": {
|
|
70
82
|
"types": "./dist/services/compaction.d.ts",
|
|
71
83
|
"import": "./dist/services/compaction.js"
|
|
72
84
|
},
|
|
85
|
+
"./services/model-call": {
|
|
86
|
+
"types": "./dist/services/model-call.d.ts",
|
|
87
|
+
"import": "./dist/services/model-call.js"
|
|
88
|
+
},
|
|
73
89
|
"./services/id-generator": {
|
|
74
90
|
"types": "./dist/services/id-generator.d.ts",
|
|
75
91
|
"import": "./dist/services/id-generator.js"
|
|
@@ -134,6 +150,10 @@
|
|
|
134
150
|
"types": "./dist/testkit/layers.d.ts",
|
|
135
151
|
"import": "./dist/testkit/layers.js"
|
|
136
152
|
},
|
|
153
|
+
"./testkit/transcript": {
|
|
154
|
+
"types": "./dist/testkit/transcript.d.ts",
|
|
155
|
+
"import": "./dist/testkit/transcript.js"
|
|
156
|
+
},
|
|
137
157
|
"./tooling/oxlint": "./tooling/oxlint/index.mjs",
|
|
138
158
|
"./types/commands": {
|
|
139
159
|
"types": "./dist/types/commands.d.ts",
|
|
@@ -159,39 +179,47 @@
|
|
|
159
179
|
"./services/run-scheduler": {
|
|
160
180
|
"types": "./dist/services/run-scheduler.d.ts",
|
|
161
181
|
"import": "./dist/services/run-scheduler.js"
|
|
182
|
+
},
|
|
183
|
+
"./services/run-scheduling-wakeup": {
|
|
184
|
+
"types": "./dist/services/run-scheduling-wakeup.d.ts",
|
|
185
|
+
"import": "./dist/services/run-scheduling-wakeup.js"
|
|
186
|
+
},
|
|
187
|
+
"./domain/run-scheduling": {
|
|
188
|
+
"types": "./dist/domain/run-scheduling.d.ts",
|
|
189
|
+
"import": "./dist/domain/run-scheduling.js"
|
|
162
190
|
}
|
|
163
191
|
},
|
|
164
192
|
"publishConfig": {
|
|
165
193
|
"access": "public",
|
|
166
194
|
"registry": "https://registry.npmjs.org/",
|
|
167
|
-
"tag": "
|
|
195
|
+
"tag": "latest"
|
|
168
196
|
},
|
|
169
197
|
"peerDependencies": {
|
|
170
|
-
"effect": "4.
|
|
198
|
+
"effect": "~4.1.2"
|
|
171
199
|
},
|
|
172
200
|
"devDependencies": {
|
|
173
201
|
"@cloudflare/workers-types": "5.20260813.1",
|
|
174
|
-
"@effect/ai-openai": "4.
|
|
175
|
-
"@effect/tsgo": "0.
|
|
176
|
-
"@effect/vitest": "4.
|
|
202
|
+
"@effect/ai-openai": "4.1.2",
|
|
203
|
+
"@effect/tsgo": "0.51.1",
|
|
204
|
+
"@effect/vitest": "4.1.2",
|
|
177
205
|
"@types/node": "^25.7.0",
|
|
178
|
-
"effect": "4.
|
|
206
|
+
"effect": "4.1.2",
|
|
179
207
|
"esbuild": "^0.28.1",
|
|
180
208
|
"fast-check": "^4.8.0",
|
|
181
|
-
"oxlint": "1.
|
|
182
|
-
"oxlint-tsgolint": "7.0.
|
|
209
|
+
"oxlint": "1.87.0",
|
|
210
|
+
"oxlint-tsgolint": "7.0.2003",
|
|
183
211
|
"publint": "^0.3.22",
|
|
184
212
|
"tsx": "4.21.0",
|
|
185
|
-
"typescript": "
|
|
186
|
-
"vite-plus": "
|
|
213
|
+
"typescript": "7.0.2",
|
|
214
|
+
"vite-plus": "0.3.0",
|
|
187
215
|
"vitest": "^4.1.8",
|
|
188
216
|
"wrangler": "^4.114.0"
|
|
189
217
|
},
|
|
190
218
|
"scripts": {
|
|
191
219
|
"build": "vp pack",
|
|
192
220
|
"check": "pnpm run lint && pnpm run typecheck",
|
|
193
|
-
"lint": "vp fmt --check src testing tooling package.json tsconfig.json vite.config.ts &&
|
|
194
|
-
"lint:fix": "vp fmt src testing tooling package.json tsconfig.json vite.config.ts &&
|
|
221
|
+
"lint": "vp fmt --check src testing tooling package.json tsconfig.json vite.config.ts && pnpm --dir ../.. exec oxlint --config oxlint.config.mjs --deny-warnings packages/effect-durable-agent/src packages/effect-durable-agent/testing packages/effect-durable-agent/vite.config.ts",
|
|
222
|
+
"lint:fix": "vp fmt src testing tooling package.json tsconfig.json vite.config.ts && pnpm --dir ../.. exec oxlint --config oxlint.config.mjs --fix packages/effect-durable-agent/src packages/effect-durable-agent/testing packages/effect-durable-agent/vite.config.ts",
|
|
195
223
|
"test": "vp test run --passWithNoTests src testing/offline-trace",
|
|
196
224
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
197
225
|
}
|
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
import { _ as UsagePayload, c as FailurePayload, f as ProviderPartId, h as ToolName, l as ModelSelectionPayload, m as SystemPromptText } from "./envelope-DkZyMIgp.js";
|
|
2
|
-
import { n as TokenConsumptionState } from "./model-usage-CdBEkTwU.js";
|
|
3
|
-
import { _ as SummaryId, i as ContextVersion, l as InferenceId, m as SequenceNumber, n as CommandId, p as RunId, r as CompactionId, u as MessageId, v as ToolCallId, y as TurnId } from "./core-CYT6DBaS.js";
|
|
4
|
-
import { r as EDACommand, u as UserMessageContent } from "./commands-Ce1ec6kH.js";
|
|
5
|
-
import { n as EDARunTrace, t as EDAEventTrace } from "./tracing-BXHAkxkx.js";
|
|
6
|
-
import { r as AssistantMessageContent, rt as RecoveryContinuation } from "./durable-br2C1bWK.js";
|
|
7
|
-
import { t as CommittedDurableEvent } from "./session-store-Cpi_NwTR.js";
|
|
8
|
-
import * as Prompt from "effect/unstable/ai/Prompt";
|
|
9
|
-
|
|
10
|
-
//#region src/domain/reduced-state.d.ts
|
|
11
|
-
/** Failure payload paired with the durable sequence that recorded it. */
|
|
12
|
-
type LifecycleFailure = {
|
|
13
|
-
readonly seq: SequenceNumber;
|
|
14
|
-
readonly error: FailurePayload;
|
|
15
|
-
};
|
|
16
|
-
/** Terminal command state folded from command lifecycle events. */
|
|
17
|
-
type CommandTerminal = {
|
|
18
|
-
readonly _tag: "Completed";
|
|
19
|
-
readonly seq: SequenceNumber;
|
|
20
|
-
} | {
|
|
21
|
-
readonly _tag: "Failed";
|
|
22
|
-
readonly seq: SequenceNumber;
|
|
23
|
-
readonly error: FailurePayload;
|
|
24
|
-
} | {
|
|
25
|
-
readonly _tag: "Cancelled";
|
|
26
|
-
readonly seq: SequenceNumber;
|
|
27
|
-
readonly reason: string;
|
|
28
|
-
};
|
|
29
|
-
/** Durable command lifecycle projection used for scheduling and recovery. */
|
|
30
|
-
interface CommandRecord {
|
|
31
|
-
readonly commandId: CommandId;
|
|
32
|
-
readonly command?: EDACommand;
|
|
33
|
-
readonly admittedSeq?: SequenceNumber;
|
|
34
|
-
readonly admissionTrace?: EDAEventTrace;
|
|
35
|
-
readonly startedSeq?: SequenceNumber;
|
|
36
|
-
readonly terminal?: CommandTerminal;
|
|
37
|
-
}
|
|
38
|
-
/** Terminal run state folded from run lifecycle events. */
|
|
39
|
-
type RunTerminal = {
|
|
40
|
-
readonly _tag: "Completed";
|
|
41
|
-
readonly seq: SequenceNumber;
|
|
42
|
-
} | {
|
|
43
|
-
readonly _tag: "Failed";
|
|
44
|
-
readonly seq: SequenceNumber;
|
|
45
|
-
readonly error: FailurePayload;
|
|
46
|
-
} | {
|
|
47
|
-
readonly _tag: "Interrupted";
|
|
48
|
-
readonly seq: SequenceNumber;
|
|
49
|
-
readonly reason: string;
|
|
50
|
-
};
|
|
51
|
-
/** Common wall-clock lifecycle timing folded from durable event envelopes. */
|
|
52
|
-
interface LifecycleTiming {
|
|
53
|
-
readonly startedAtMs?: number;
|
|
54
|
-
readonly terminalAtMs?: number;
|
|
55
|
-
readonly durationMs?: number;
|
|
56
|
-
}
|
|
57
|
-
/** Durable run lifecycle projection tying one run to its owning command ids. */
|
|
58
|
-
interface RunRecord extends LifecycleTiming {
|
|
59
|
-
readonly modelSelection?: ModelSelectionPayload;
|
|
60
|
-
readonly runId: RunId;
|
|
61
|
-
readonly commandIds: ReadonlyArray<CommandId>;
|
|
62
|
-
readonly startedSeq: SequenceNumber;
|
|
63
|
-
readonly trace: EDARunTrace;
|
|
64
|
-
readonly terminal?: RunTerminal;
|
|
65
|
-
}
|
|
66
|
-
/** Terminal turn state folded from turn lifecycle events. */
|
|
67
|
-
type TurnTerminal = {
|
|
68
|
-
readonly _tag: "Completed";
|
|
69
|
-
readonly seq: SequenceNumber;
|
|
70
|
-
readonly usage?: UsagePayload;
|
|
71
|
-
} | {
|
|
72
|
-
readonly _tag: "Failed";
|
|
73
|
-
readonly seq: SequenceNumber;
|
|
74
|
-
readonly error: FailurePayload;
|
|
75
|
-
} | {
|
|
76
|
-
readonly _tag: "Stopped";
|
|
77
|
-
readonly seq: SequenceNumber;
|
|
78
|
-
readonly reason: string;
|
|
79
|
-
};
|
|
80
|
-
/** Durable turn lifecycle projection nested under a run. */
|
|
81
|
-
interface TurnRecord extends LifecycleTiming {
|
|
82
|
-
readonly runId: RunId;
|
|
83
|
-
readonly turnId: TurnId;
|
|
84
|
-
readonly startedSeq: SequenceNumber;
|
|
85
|
-
readonly terminal?: TurnTerminal;
|
|
86
|
-
}
|
|
87
|
-
/** Terminal inference state folded from inference lifecycle events. */
|
|
88
|
-
type InferenceTerminal = {
|
|
89
|
-
readonly _tag: "Completed";
|
|
90
|
-
readonly seq: SequenceNumber;
|
|
91
|
-
readonly usage?: UsagePayload;
|
|
92
|
-
} | {
|
|
93
|
-
readonly _tag: "Failed";
|
|
94
|
-
readonly seq: SequenceNumber;
|
|
95
|
-
readonly error: FailurePayload;
|
|
96
|
-
};
|
|
97
|
-
/** Durable model-inference lifecycle projection nested under a turn. */
|
|
98
|
-
interface InferenceRecord extends LifecycleTiming {
|
|
99
|
-
readonly runId: RunId;
|
|
100
|
-
readonly turnId: TurnId;
|
|
101
|
-
readonly inferenceId: InferenceId;
|
|
102
|
-
readonly startedSeq: SequenceNumber;
|
|
103
|
-
readonly terminal?: InferenceTerminal;
|
|
104
|
-
}
|
|
105
|
-
/** Durable decision produced after a model inference seals final tool calls. */
|
|
106
|
-
type ToolDecision = {
|
|
107
|
-
readonly _tag: "Created";
|
|
108
|
-
readonly seq: SequenceNumber;
|
|
109
|
-
readonly runId: RunId;
|
|
110
|
-
readonly turnId: TurnId;
|
|
111
|
-
readonly inferenceId: InferenceId;
|
|
112
|
-
readonly providerPartId: ProviderPartId;
|
|
113
|
-
readonly toolName: ToolName;
|
|
114
|
-
readonly params: unknown;
|
|
115
|
-
readonly providerExecuted: boolean;
|
|
116
|
-
readonly promptPart?: Prompt.ToolCallPart;
|
|
117
|
-
} | {
|
|
118
|
-
readonly _tag: "Rejected";
|
|
119
|
-
readonly seq: SequenceNumber;
|
|
120
|
-
readonly runId: RunId;
|
|
121
|
-
readonly turnId: TurnId;
|
|
122
|
-
readonly inferenceId: InferenceId;
|
|
123
|
-
readonly providerPartId: ProviderPartId;
|
|
124
|
-
readonly toolName: ToolName;
|
|
125
|
-
readonly reason: "unknown-tool" | "invalid-params";
|
|
126
|
-
readonly modelFeedback: string;
|
|
127
|
-
readonly promptPart?: Prompt.ToolResultPart;
|
|
128
|
-
};
|
|
129
|
-
/** Terminal framework-owned tool-call execution state. */
|
|
130
|
-
type ToolTerminal = {
|
|
131
|
-
readonly _tag: "Completed";
|
|
132
|
-
readonly seq: SequenceNumber;
|
|
133
|
-
readonly result: unknown;
|
|
134
|
-
readonly promptPart?: Prompt.ToolResultPart;
|
|
135
|
-
} | {
|
|
136
|
-
readonly _tag: "Failed";
|
|
137
|
-
readonly seq: SequenceNumber;
|
|
138
|
-
readonly error: FailurePayload;
|
|
139
|
-
readonly promptPart?: Prompt.ToolResultPart;
|
|
140
|
-
};
|
|
141
|
-
/** Durable tool-call projection from decision through execution terminal. */
|
|
142
|
-
interface ToolCallRecord extends LifecycleTiming {
|
|
143
|
-
readonly toolCallId: ToolCallId;
|
|
144
|
-
readonly decision?: ToolDecision;
|
|
145
|
-
readonly startedSeq?: SequenceNumber;
|
|
146
|
-
readonly terminal?: ToolTerminal;
|
|
147
|
-
}
|
|
148
|
-
/** Durable message-like facts folded from the event log. */
|
|
149
|
-
type MessageRecord = {
|
|
150
|
-
readonly _tag: "System";
|
|
151
|
-
readonly messageId: MessageId;
|
|
152
|
-
readonly content: SystemPromptText;
|
|
153
|
-
readonly createdAtMs?: number;
|
|
154
|
-
readonly seq: SequenceNumber;
|
|
155
|
-
} | {
|
|
156
|
-
readonly _tag: "User";
|
|
157
|
-
readonly messageId: MessageId;
|
|
158
|
-
readonly commandId: CommandId;
|
|
159
|
-
readonly content: UserMessageContent;
|
|
160
|
-
readonly createdAtMs?: number;
|
|
161
|
-
readonly seq: SequenceNumber; /** Present for admission-time message entities; absent on legacy committed users. */
|
|
162
|
-
readonly requestedDisposition?: "queue" | "steer";
|
|
163
|
-
readonly disposition?: "queue" | "steer";
|
|
164
|
-
readonly promotedSeq?: SequenceNumber;
|
|
165
|
-
readonly pausedSeq?: SequenceNumber;
|
|
166
|
-
readonly pausedByCommandId?: CommandId;
|
|
167
|
-
readonly consumedSeq?: SequenceNumber;
|
|
168
|
-
readonly consumedTurnId?: TurnId;
|
|
169
|
-
readonly cancelledSeq?: SequenceNumber;
|
|
170
|
-
readonly cancelledByCommandId?: CommandId;
|
|
171
|
-
readonly cancellationReason?: string;
|
|
172
|
-
} | {
|
|
173
|
-
readonly _tag: "Steering";
|
|
174
|
-
readonly messageId: MessageId;
|
|
175
|
-
readonly commandId: CommandId;
|
|
176
|
-
readonly runId: RunId;
|
|
177
|
-
readonly content: UserMessageContent;
|
|
178
|
-
readonly createdAtMs?: number;
|
|
179
|
-
readonly seq: SequenceNumber;
|
|
180
|
-
readonly promotedSeq?: SequenceNumber;
|
|
181
|
-
readonly consumedSeq?: SequenceNumber;
|
|
182
|
-
readonly consumedTurnId?: TurnId;
|
|
183
|
-
readonly cancelledSeq?: SequenceNumber;
|
|
184
|
-
readonly cancelledByCommandId?: CommandId;
|
|
185
|
-
readonly cancellationReason?: string;
|
|
186
|
-
readonly pausedSeq?: SequenceNumber;
|
|
187
|
-
readonly pausedByCommandId?: CommandId;
|
|
188
|
-
} | {
|
|
189
|
-
readonly _tag: "Assistant";
|
|
190
|
-
readonly messageId: MessageId;
|
|
191
|
-
readonly runId: RunId;
|
|
192
|
-
readonly turnId: TurnId;
|
|
193
|
-
readonly inferenceId: InferenceId; /** True when the assistant message originated outside this EDA session. */
|
|
194
|
-
readonly imported?: true;
|
|
195
|
-
readonly content: AssistantMessageContent;
|
|
196
|
-
readonly createdAtMs?: number;
|
|
197
|
-
readonly promptParts?: ReadonlyArray<Prompt.AssistantMessagePart>;
|
|
198
|
-
readonly seq: SequenceNumber;
|
|
199
|
-
} | {
|
|
200
|
-
readonly _tag: "AssistantPartial";
|
|
201
|
-
readonly messageId: MessageId;
|
|
202
|
-
readonly runId: RunId;
|
|
203
|
-
readonly turnId: TurnId;
|
|
204
|
-
readonly inferenceId: InferenceId;
|
|
205
|
-
readonly content: AssistantMessageContent;
|
|
206
|
-
readonly createdAtMs?: number;
|
|
207
|
-
readonly promptParts?: ReadonlyArray<Prompt.AssistantMessagePart>;
|
|
208
|
-
readonly reason: string;
|
|
209
|
-
readonly seq: SequenceNumber;
|
|
210
|
-
};
|
|
211
|
-
/** Terminal compaction state folded from compaction lifecycle events. */
|
|
212
|
-
type CompactionTerminal = {
|
|
213
|
-
readonly _tag: "Completed";
|
|
214
|
-
readonly seq: SequenceNumber;
|
|
215
|
-
} | {
|
|
216
|
-
readonly _tag: "Failed";
|
|
217
|
-
readonly seq: SequenceNumber;
|
|
218
|
-
readonly error: FailurePayload;
|
|
219
|
-
};
|
|
220
|
-
/** Durable compaction lifecycle projection and its produced summary cursor. */
|
|
221
|
-
interface CompactionRecord {
|
|
222
|
-
readonly compactionId: CompactionId;
|
|
223
|
-
readonly requestedSeq?: SequenceNumber;
|
|
224
|
-
readonly startedSeq?: SequenceNumber;
|
|
225
|
-
readonly summaryCreatedSeq?: SequenceNumber;
|
|
226
|
-
readonly summaryId?: SummaryId;
|
|
227
|
-
readonly sourceFromSeq?: SequenceNumber;
|
|
228
|
-
readonly sourceToSeq?: SequenceNumber;
|
|
229
|
-
readonly rebasedSeq?: SequenceNumber;
|
|
230
|
-
readonly contextVersion?: ContextVersion;
|
|
231
|
-
readonly terminal?: CompactionTerminal;
|
|
232
|
-
}
|
|
233
|
-
/** Current model-context version and summary selected by compaction. */
|
|
234
|
-
interface ContextRecord {
|
|
235
|
-
readonly version: ContextVersion;
|
|
236
|
-
readonly currentSummaryId?: SummaryId;
|
|
237
|
-
}
|
|
238
|
-
/** Durable StopTurn request and the lifecycle boundary it eventually applied to. */
|
|
239
|
-
interface StopRequestRecord {
|
|
240
|
-
readonly commandId: CommandId;
|
|
241
|
-
readonly requestedSeq: SequenceNumber;
|
|
242
|
-
readonly requestedRunId?: RunId;
|
|
243
|
-
readonly requestedTurnId?: TurnId;
|
|
244
|
-
readonly appliedSeq?: SequenceNumber;
|
|
245
|
-
readonly appliedRunId?: RunId;
|
|
246
|
-
readonly appliedTurnId?: TurnId;
|
|
247
|
-
readonly appliedInferenceId?: InferenceId;
|
|
248
|
-
}
|
|
249
|
-
/** Admitted command that has not yet crossed the `CommandStarted` boundary. */
|
|
250
|
-
interface PendingCommand {
|
|
251
|
-
/** Lifecycle ID for the admitted command. */
|
|
252
|
-
readonly commandId: CommandId;
|
|
253
|
-
/** Typed command payload admitted durably. */
|
|
254
|
-
readonly command: EDACommand;
|
|
255
|
-
/** Admission sequence used for deterministic FIFO/control ordering. */
|
|
256
|
-
readonly admittedSeq: SequenceNumber;
|
|
257
|
-
/** Trace context captured at the durable command admission boundary. */
|
|
258
|
-
readonly admissionTrace?: EDAEventTrace;
|
|
259
|
-
}
|
|
260
|
-
/** Started command without a terminal command boundary, optionally tied to an open run. */
|
|
261
|
-
interface ActiveCommandEvidence {
|
|
262
|
-
readonly commandId: CommandId;
|
|
263
|
-
readonly runId?: RunId;
|
|
264
|
-
}
|
|
265
|
-
/** Active run/turn/inference identity derived from unfinished lifecycle records. */
|
|
266
|
-
type ActiveTurnIdentity = {
|
|
267
|
-
readonly runId: RunId;
|
|
268
|
-
readonly turnId: TurnId;
|
|
269
|
-
readonly inferenceId?: InferenceId;
|
|
270
|
-
};
|
|
271
|
-
/** Canonical durable replay product used by queries, recovery, and scheduling. */
|
|
272
|
-
interface ReducedState {
|
|
273
|
-
/** Session execution policy established by configuration or the first historical run. */
|
|
274
|
-
readonly modelSelection?: ModelSelectionPayload;
|
|
275
|
-
readonly lastSeq: SequenceNumber;
|
|
276
|
-
readonly commands: ReadonlyMap<CommandId, CommandRecord>;
|
|
277
|
-
readonly runs: ReadonlyMap<RunId, RunRecord>;
|
|
278
|
-
/** Explicit startup-recovery links keyed by replacement physical run id. */
|
|
279
|
-
readonly recoveryContinuations: ReadonlyMap<RunId, RecoveryContinuationRecord>;
|
|
280
|
-
readonly turns: ReadonlyMap<TurnId, TurnRecord>;
|
|
281
|
-
readonly inferences: ReadonlyMap<InferenceId, InferenceRecord>;
|
|
282
|
-
readonly toolCalls: ReadonlyMap<ToolCallId, ToolCallRecord>;
|
|
283
|
-
readonly messages: ReadonlyMap<MessageId, MessageRecord>;
|
|
284
|
-
readonly stopRequests: ReadonlyMap<CommandId, StopRequestRecord>;
|
|
285
|
-
readonly compactions: ReadonlyMap<CompactionId, CompactionRecord>;
|
|
286
|
-
readonly context: ContextRecord;
|
|
287
|
-
/** Rolling model-token usage totals derived from completed provider inferences. */
|
|
288
|
-
readonly tokenConsumption: TokenConsumptionState;
|
|
289
|
-
/** Materialized scheduler queues derived from the maps above after every fold. */
|
|
290
|
-
readonly commandQueues: CommandQueues;
|
|
291
|
-
}
|
|
292
|
-
/** Durable recovery continuation plus the sequence of its completion barrier. */
|
|
293
|
-
interface RecoveryContinuationRecord extends RecoveryContinuation {
|
|
294
|
-
readonly seq: SequenceNumber;
|
|
295
|
-
}
|
|
296
|
-
/** Unfinished lifecycle records requiring deterministic startup recovery. */
|
|
297
|
-
interface RecoverableWork {
|
|
298
|
-
readonly activeCommands: ReadonlyArray<CommandRecord>;
|
|
299
|
-
readonly activeRuns: ReadonlyArray<RunRecord>;
|
|
300
|
-
readonly activeTurns: ReadonlyArray<TurnRecord>;
|
|
301
|
-
readonly activeInferences: ReadonlyArray<InferenceRecord>;
|
|
302
|
-
readonly openToolCalls: ReadonlyArray<ToolCallRecord>;
|
|
303
|
-
readonly runningToolCalls: ReadonlyArray<ToolCallRecord>;
|
|
304
|
-
readonly pendingStopRequests: ReadonlyArray<StopRequestRecord>;
|
|
305
|
-
readonly openCompactions: ReadonlyArray<CompactionRecord>;
|
|
306
|
-
}
|
|
307
|
-
/** Empty durable replay state before any session event has committed. */
|
|
308
|
-
declare const initialReducedState: ReducedState;
|
|
309
|
-
/** Reserved reducer checkpoint name for the framework-owned `ReducedState`. */
|
|
310
|
-
declare const frameworkReducedStateReducerName = "_eda.framework.reduced-state";
|
|
311
|
-
/** Schema version for the framework-owned `ReducedState` checkpoint payload. */
|
|
312
|
-
declare const frameworkReducedStateReducerSchemaVersion = 6;
|
|
313
|
-
/** JSON payload stored for the framework-owned reduced-state reducer checkpoint. */
|
|
314
|
-
type ReducedStateCheckpointCommandRecord = Omit<CommandRecord, "command">;
|
|
315
|
-
type SystemMessageRecord = Extract<MessageRecord, {
|
|
316
|
-
readonly _tag: "System";
|
|
317
|
-
}>;
|
|
318
|
-
type UserMessageRecord = Extract<MessageRecord, {
|
|
319
|
-
readonly _tag: "User";
|
|
320
|
-
}>;
|
|
321
|
-
type SteeringMessageRecord = Extract<MessageRecord, {
|
|
322
|
-
readonly _tag: "Steering";
|
|
323
|
-
}>;
|
|
324
|
-
type AssistantMessageRecord = Extract<MessageRecord, {
|
|
325
|
-
readonly _tag: "Assistant";
|
|
326
|
-
}>;
|
|
327
|
-
type AssistantPartialMessageRecord = Extract<MessageRecord, {
|
|
328
|
-
readonly _tag: "AssistantPartial";
|
|
329
|
-
}>;
|
|
330
|
-
type ReducedStateCheckpointMessageRecord = Omit<SystemMessageRecord, "content"> | Omit<UserMessageRecord, "content"> | Omit<SteeringMessageRecord, "content"> | Omit<AssistantMessageRecord, "content" | "promptParts"> | Omit<AssistantPartialMessageRecord, "content" | "promptParts">;
|
|
331
|
-
type CreatedToolDecision = Extract<ToolDecision, {
|
|
332
|
-
readonly _tag: "Created";
|
|
333
|
-
}>;
|
|
334
|
-
type RejectedToolDecision = Extract<ToolDecision, {
|
|
335
|
-
readonly _tag: "Rejected";
|
|
336
|
-
}>;
|
|
337
|
-
type CompletedToolTerminal = Extract<ToolTerminal, {
|
|
338
|
-
readonly _tag: "Completed";
|
|
339
|
-
}>;
|
|
340
|
-
type FailedToolTerminal = Extract<ToolTerminal, {
|
|
341
|
-
readonly _tag: "Failed";
|
|
342
|
-
}>;
|
|
343
|
-
type ReducedStateCheckpointToolDecision = Omit<CreatedToolDecision, "params" | "promptPart"> | Omit<RejectedToolDecision, "promptPart">;
|
|
344
|
-
type ReducedStateCheckpointToolTerminal = Omit<CompletedToolTerminal, "result" | "promptPart"> | Omit<FailedToolTerminal, "error" | "promptPart">;
|
|
345
|
-
interface ReducedStateCheckpointToolCallRecord extends Omit<ToolCallRecord, "decision" | "terminal"> {
|
|
346
|
-
readonly decision?: ReducedStateCheckpointToolDecision;
|
|
347
|
-
readonly terminal?: ReducedStateCheckpointToolTerminal;
|
|
348
|
-
}
|
|
349
|
-
interface ReducedStateCheckpointPayload {
|
|
350
|
-
readonly modelSelection?: ModelSelectionPayload;
|
|
351
|
-
readonly lastSeq: SequenceNumber;
|
|
352
|
-
readonly commands: ReadonlyArray<readonly [CommandId, ReducedStateCheckpointCommandRecord]>;
|
|
353
|
-
readonly runs: ReadonlyArray<readonly [RunId, RunRecord]>;
|
|
354
|
-
readonly recoveryContinuations?: ReadonlyArray<readonly [RunId, RecoveryContinuationRecord]>;
|
|
355
|
-
readonly turns: ReadonlyArray<readonly [TurnId, TurnRecord]>;
|
|
356
|
-
readonly inferences: ReadonlyArray<readonly [InferenceId, InferenceRecord]>;
|
|
357
|
-
readonly toolCalls: ReadonlyArray<readonly [ToolCallId, ReducedStateCheckpointToolCallRecord]>;
|
|
358
|
-
readonly messages: ReadonlyArray<readonly [MessageId, ReducedStateCheckpointMessageRecord]>;
|
|
359
|
-
readonly stopRequests: ReadonlyArray<readonly [CommandId, StopRequestRecord]>;
|
|
360
|
-
readonly compactions: ReadonlyArray<readonly [CompactionId, CompactionRecord]>;
|
|
361
|
-
readonly context: ContextRecord;
|
|
362
|
-
readonly tokenConsumption?: TokenConsumptionState;
|
|
363
|
-
}
|
|
364
|
-
/** Encode the framework reducer state into a pointer-based JSON-safe checkpoint payload. */
|
|
365
|
-
declare const encodeReducedStateCheckpoint: (state: ReducedState) => ReducedStateCheckpointPayload;
|
|
366
|
-
/** Event-log positions required to hydrate a pointer-based framework checkpoint. */
|
|
367
|
-
declare const reducedStateCheckpointEventSeqs: (payload: unknown) => ReadonlyArray<SequenceNumber>;
|
|
368
|
-
/** Decode the framework reducer checkpoint and rebuild derived scheduler queues. */
|
|
369
|
-
declare const decodeReducedStateCheckpoint: (payload: unknown, referencedEvents: ReadonlyArray<CommittedDurableEvent>) => ReducedState;
|
|
370
|
-
/** Fold newly committed durable events into the canonical replay state. */
|
|
371
|
-
declare const foldReducedState: (state: ReducedState, committed: ReadonlyArray<CommittedDurableEvent>) => ReducedState;
|
|
372
|
-
/** Fold committed events from genesis into a fresh `ReducedState`. */
|
|
373
|
-
declare const reduceCommittedEvents: (committed: ReadonlyArray<CommittedDurableEvent>) => ReducedState;
|
|
374
|
-
/** Pending admitted commands in deterministic scheduler order. */
|
|
375
|
-
declare const pendingCommands: (state: ReducedState) => ReadonlyArray<PendingCommand>;
|
|
376
|
-
/** First pending StopTurn control command, when one is waiting. */
|
|
377
|
-
declare const pendingStopCommand: (state: ReducedState) => PendingCommand | undefined;
|
|
378
|
-
/** Currently active command evidence, if any unfinished command is blocking FIFO work. */
|
|
379
|
-
declare const activeCommand: (state: ReducedState) => ActiveCommandEvidence | undefined;
|
|
380
|
-
/** Active run/turn/inference identity owned by a specific active command. */
|
|
381
|
-
declare const activeTurnIdentityForCommand: (state: ReducedState, commandId: CommandId) => ActiveTurnIdentity | undefined;
|
|
382
|
-
/** Classify unfinished durable lifecycles that recovery may need to repair. */
|
|
383
|
-
declare const classifyRecoverableWork: (state: ReducedState) => RecoverableWork;
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region src/domain/command-queues.d.ts
|
|
386
|
-
/**
|
|
387
|
-
* A steering message admitted for an active run but not necessarily consumed
|
|
388
|
-
* by a later turn yet.
|
|
389
|
-
*/
|
|
390
|
-
interface PendingSteeringMessage {
|
|
391
|
-
/** Durable message identity used by `TurnStarted.inputMessageIds` when consumed. */
|
|
392
|
-
readonly messageId: MessageId;
|
|
393
|
-
/** Command that admitted this steering message. */
|
|
394
|
-
readonly commandId: PendingCommand["commandId"];
|
|
395
|
-
/** Active run this steering message may continue. */
|
|
396
|
-
readonly runId: RunId;
|
|
397
|
-
/** User content to append to the next continuation prompt when selected. */
|
|
398
|
-
readonly content: UserMessageContent;
|
|
399
|
-
/** Sequence where `SteeringMessageQueued` committed; used for one-by-one ordering. */
|
|
400
|
-
readonly queuedSeq: SequenceNumber;
|
|
401
|
-
/** Sequence where a later `TurnStarted` consumed this steering message. */
|
|
402
|
-
readonly consumedSeq?: SequenceNumber;
|
|
403
|
-
/** Turn that consumed this steering message. */
|
|
404
|
-
readonly consumedTurnId?: TurnId;
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Materialized command scheduler view derived from durable `ReducedState`.
|
|
408
|
-
*
|
|
409
|
-
* `pendingCommands` means admitted commands with no `CommandStarted` yet.
|
|
410
|
-
* `queuedCommands` is the FIFO subset that should wait for idle session work
|
|
411
|
-
* (`SubmitMessage{disposition:"queue"}`). `activeControlCommands` is the
|
|
412
|
-
* subset that may affect an active run (`StopTurn`, `steer`, `interrupt`).
|
|
413
|
-
* `steeringByRun` is not a command queue; it is queued steering content already
|
|
414
|
-
* admitted/completed as commands but not yet consumed by a turn.
|
|
415
|
-
*/
|
|
416
|
-
interface CommandQueues {
|
|
417
|
-
/** Started command without terminal command evidence, plus active run when known. */
|
|
418
|
-
readonly active?: ActiveCommandEvidence;
|
|
419
|
-
/** All admitted commands that have not yet crossed `CommandStarted`. */
|
|
420
|
-
readonly pendingCommands: ReadonlyArray<PendingCommand>;
|
|
421
|
-
/** FIFO user-message work that waits until no command/run is active. */
|
|
422
|
-
readonly queuedCommands: ReadonlyArray<PendingCommand>;
|
|
423
|
-
/** Stop/steer/interrupt work that can be interpreted while a run is active. */
|
|
424
|
-
readonly activeControlCommands: ReadonlyArray<PendingCommand>;
|
|
425
|
-
/** Unconsumed steering messages grouped by target run and sorted by queued seq. */
|
|
426
|
-
readonly steeringByRun: ReadonlyMap<RunId, ReadonlyArray<PendingSteeringMessage>>;
|
|
427
|
-
/** Admission-time queue messages eligible for separate work. */
|
|
428
|
-
readonly pendingQueue: ReadonlyArray<PendingUserMessage>;
|
|
429
|
-
/** Admission-time steer messages eligible at the next boundary. */
|
|
430
|
-
readonly pendingSteers: ReadonlyArray<PendingUserMessage>;
|
|
431
|
-
/** Queue messages held by an explicit interruption pause. */
|
|
432
|
-
readonly pausedQueue: ReadonlyArray<PendingUserMessage>;
|
|
433
|
-
}
|
|
434
|
-
interface PendingUserMessage {
|
|
435
|
-
readonly messageId: MessageId;
|
|
436
|
-
readonly commandId: PendingCommand["commandId"];
|
|
437
|
-
readonly content: UserMessageContent;
|
|
438
|
-
readonly submittedSeq: SequenceNumber;
|
|
439
|
-
readonly effectiveSeq: SequenceNumber;
|
|
440
|
-
readonly disposition: "queue" | "steer";
|
|
441
|
-
readonly targetRunId?: RunId;
|
|
442
|
-
readonly pausedByCommandId?: PendingCommand["commandId"];
|
|
443
|
-
}
|
|
444
|
-
/** Durable records needed to derive `CommandQueues` without services or refs. */
|
|
445
|
-
interface CommandQueueSource {
|
|
446
|
-
readonly commands: ReadonlyMap<PendingCommand["commandId"], CommandRecord>;
|
|
447
|
-
readonly runs: ReadonlyMap<RunId, RunRecord>;
|
|
448
|
-
readonly messages: ReadonlyMap<MessageId, MessageRecord>;
|
|
449
|
-
}
|
|
450
|
-
/** Empty queue view for `initialReducedState` before any durable events exist. */
|
|
451
|
-
declare const emptyCommandQueues: CommandQueues;
|
|
452
|
-
/**
|
|
453
|
-
* Derive scheduler queues from durable replay state.
|
|
454
|
-
*
|
|
455
|
-
* These queues are cached inside `ReducedState` for clarity and fast scheduler
|
|
456
|
-
* reads, but durable command/message/run records remain the source of truth.
|
|
457
|
-
* Never mutate a queue directly; fold durable events and derive again.
|
|
458
|
-
*/
|
|
459
|
-
declare const deriveCommandQueues: (state: CommandQueueSource) => CommandQueues;
|
|
460
|
-
//#endregion
|
|
461
|
-
export { RunTerminal as A, decodeReducedStateCheckpoint as B, ReducedStateCheckpointCommandRecord as C, ReducedStateCheckpointToolDecision as D, ReducedStateCheckpointToolCallRecord as E, TurnRecord as F, initialReducedState as G, foldReducedState as H, TurnTerminal as I, reduceCommittedEvents as J, pendingCommands as K, activeCommand as L, ToolCallRecord as M, ToolDecision as N, ReducedStateCheckpointToolTerminal as O, ToolTerminal as P, activeTurnIdentityForCommand as R, ReducedState as S, ReducedStateCheckpointPayload as T, frameworkReducedStateReducerName as U, encodeReducedStateCheckpoint as V, frameworkReducedStateReducerSchemaVersion as W, reducedStateCheckpointEventSeqs as Y, LifecycleTiming as _, deriveCommandQueues as a, RecoverableWork as b, ActiveTurnIdentity as c, CompactionRecord as d, CompactionTerminal as f, LifecycleFailure as g, InferenceTerminal as h, PendingUserMessage as i, StopRequestRecord as j, RunRecord as k, CommandRecord as l, InferenceRecord as m, CommandQueues as n, emptyCommandQueues as o, ContextRecord as p, pendingStopCommand as q, PendingSteeringMessage as r, ActiveCommandEvidence as s, CommandQueueSource as t, CommandTerminal as u, MessageRecord as v, ReducedStateCheckpointMessageRecord as w, RecoveryContinuationRecord as x, PendingCommand as y, classifyRecoverableWork as z };
|
|
462
|
-
//# sourceMappingURL=command-queues-DdDB_aYM.d.ts.map
|