effect-durable-agent 0.1.0-alpha.12 → 0.1.0-alpha.14
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/dist/{command-queues-B45Xa1Dl.d.ts → command-queues-CSEl1yrH.d.ts} +2 -2
- package/dist/{compaction-CLCDOR1t.d.ts → compaction-DYAlYxx5.d.ts} +5 -5
- package/dist/{context-projection-CCoN8m9W.d.ts → context-projection-C43pyxn2.d.ts} +4 -4
- package/dist/domain/command-queues.d.ts +1 -1
- package/dist/domain/context-projection.d.ts +1 -1
- package/dist/domain/message-transcript.d.ts +1 -1
- package/dist/domain/reduced-state.d.ts +1 -1
- package/dist/domain/run-scheduling.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{message-transcript-Dr6Rk-re.d.ts → message-transcript-CmCHC1Pg.d.ts} +3 -3
- package/dist/{prompt-projector-CGo1TGyZ.d.ts → prompt-projector-_Zxe7dlE.d.ts} +4 -4
- package/dist/{reducer-registry-DqljrD58.d.ts → reducer-registry-BgtK0NuX.d.ts} +2 -2
- package/dist/{run-scheduler-DvHWwWBJ.d.ts → run-scheduler-BBqZ0Ate.d.ts} +2 -2
- package/dist/{run-scheduling-wakeup-CGgJ7RNe.d.ts → run-scheduling-wakeup-DRYZztL6.d.ts} +2 -2
- package/dist/{runtime-j93ZOBnG.d.ts → runtime-CH6Ll_Rv.d.ts} +4 -4
- package/dist/services/compaction.d.ts +1 -1
- package/dist/services/prompt-projector.d.ts +1 -1
- package/dist/services/reducer-registry.d.ts +1 -1
- package/dist/services/run-scheduler.d.ts +2 -2
- package/dist/services/run-scheduling-wakeup.d.ts +1 -1
- package/dist/services/runtime-layer.d.ts +11 -11
- package/dist/services/runtime-layer.js +2 -2
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +1 -2
- package/dist/services/session-query.js.map +1 -1
- package/dist/services/session-state.d.ts +1 -1
- package/dist/services/session-state.js +1 -1
- package/dist/services/session-store.d.ts +1 -1
- package/dist/services/sink-checkpoint-store.d.ts +1 -1
- package/dist/services/sink-registry.d.ts +1 -1
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/span-names.d.ts +1 -1
- package/dist/services/span-names.js +3 -0
- package/dist/services/span-names.js.map +1 -1
- package/dist/services/tool-registry.d.ts +1 -1
- package/dist/services/tracing.js +1 -1
- package/dist/services/tracing.js.map +1 -1
- package/dist/{session-query-DYuJXhMQ.d.ts → session-query-CMeJog1g.d.ts} +6 -7
- package/dist/{session-state-13z-3YaF.d.ts → session-state-D4g0kV_K.d.ts} +43 -15
- package/dist/{session-state-xXXyniwU.js → session-state-DtPwg_EP.js} +76 -11
- package/dist/session-state-DtPwg_EP.js.map +1 -0
- package/dist/{session-store-BIr-xfJ7.d.ts → session-store-DCs--1kc.d.ts} +2 -2
- package/dist/{sink-checkpoint-store-Cr9_GmOw.d.ts → sink-checkpoint-store-CasqHvDz.d.ts} +2 -2
- package/dist/{sink-registry-CUIrrkXU.js → sink-registry-B7cG7gxK.js} +153 -121
- package/dist/sink-registry-B7cG7gxK.js.map +1 -0
- package/dist/{sink-registry-C2t3DI_g.d.ts → sink-registry-CAtl5OWV.d.ts} +9 -35
- package/dist/testkit/layers.d.ts +12 -12
- package/dist/testkit/layers.js +2 -2
- package/dist/{tool-registry-Dhs2KmYK.d.ts → tool-registry-CHMtDCJ5.d.ts} +2 -2
- package/package.json +1 -1
- package/dist/session-state-xXXyniwU.js.map +0 -1
- package/dist/sink-registry-CUIrrkXU.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.js","names":["#emit"],"sources":["../../src/services/tracing.ts"],"sourcesContent":["import * as Cause from \"effect/Cause\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport * as Option from \"effect/Option\";\nimport * as Tracer from \"effect/Tracer\";\n\nimport type { UsagePayload } from \"../types/events\";\nimport {\n EDATraceContext,\n type EDAEventTrace,\n type EDATraceAttributeValue,\n type EDATraceMetadata,\n makeEDAEventTrace,\n makeEDATraceContext,\n makeRootEDAEventTrace,\n} from \"../types/tracing\";\n\nexport {\n EDATraceContext,\n EDARunTrace,\n EDATraceLink,\n EDATraceMetadata,\n EDAEventTrace,\n makeEDAEventTrace,\n makeEDARunTrace,\n makeEDATraceContext,\n makeEDATraceMetadataFromParent,\n makeRootEDAEventTrace,\n makeRootEDATraceMetadata,\n} from \"../types/tracing\";\n\nexport { buildEDATraceparent, parseEDATraceparent } from \"../types/tracing\";\n\n/** Attribute value types accepted by Effect span annotations after compaction. */\nexport type EdaSpanAttributeValue = EDATraceAttributeValue | undefined;\n\n/** EDA span attribute map; undefined values are intentionally dropped before annotation. */\nexport type EdaSpanAttributes = Record<string, EdaSpanAttributeValue>;\n\nexport interface EDATracingOptions {\n readonly disableTracing?: boolean;\n readonly disableSpanPropagation?: boolean;\n readonly spanAttributes?: EdaSpanAttributes;\n readonly spanPrefix?: string;\n}\n\nexport interface EDAExportedSpanLink {\n readonly attributes: Record<string, string | number | boolean>;\n readonly sampled: boolean;\n readonly spanId: string;\n readonly traceId: string;\n}\n\nexport interface EDAExportedSpan {\n readonly attributes: Record<string, string | number | boolean>;\n readonly endedAtMs: number;\n readonly endedAtUnixNano: string;\n readonly kind: Tracer.SpanKind;\n readonly links: ReadonlyArray<EDAExportedSpanLink>;\n readonly name: string;\n readonly outcome: \"ok\" | \"error\" | \"timeout\" | \"canceled\";\n readonly parentSpanId?: string;\n readonly sampled: boolean;\n readonly spanId: string;\n readonly startedAtMs: number;\n readonly startedAtUnixNano: string;\n readonly statusCode: \"OK\" | \"ERROR\";\n readonly statusMessage?: string;\n readonly traceId: string;\n}\n\n/** Maximum primitive attributes copied from one native Effect span or link. */\nconst MAX_EXPORTED_SPAN_ATTRIBUTES = 256;\n\ninterface EventLike {\n readonly event?: { readonly type?: unknown; readonly durability?: unknown };\n readonly type?: unknown;\n}\n\ninterface PositionedEventLike {\n readonly position?: { readonly seq?: unknown; readonly subSeq?: unknown };\n readonly event?: { readonly type?: unknown; readonly durability?: unknown };\n}\n\n/** Compact undefined tracing attributes before handing them to Effect spans. */\nexport const compactSpanAttributes = (\n attributes: EdaSpanAttributes,\n): Record<string, string | number | boolean> => {\n const compacted: Record<string, string | number | boolean> = {};\n for (const [key, value] of Object.entries(attributes)) {\n if (value !== undefined) {\n compacted[key] = value;\n }\n }\n return compacted;\n};\n\nconst compactUnknownAttributes = (\n attributes: Readonly<Record<string, unknown>> | ReadonlyMap<string, unknown>,\n): Record<string, string | number | boolean> => {\n const compacted: Record<string, string | number | boolean> = {};\n try {\n if (attributes instanceof Map) {\n let count = 0;\n for (const [key, value] of attributes) {\n if (count >= MAX_EXPORTED_SPAN_ATTRIBUTES) {\n break;\n }\n count += 1;\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n compacted[key] = value;\n }\n }\n return compacted;\n }\n\n const keys = Object.keys(attributes).slice(0, MAX_EXPORTED_SPAN_ATTRIBUTES);\n for (const key of keys) {\n let value: unknown;\n try {\n value = Reflect.get(attributes, key);\n } catch {\n continue;\n }\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n compacted[key] = value;\n }\n }\n } catch {\n // Tracing diagnostics must not replace the operation whose span is ending.\n }\n return compacted;\n};\n\nexport const toEdaExternalSpan = (context: EDATraceContext): Tracer.ExternalSpan =>\n Tracer.externalSpan({\n traceId: context.traceId,\n spanId: context.spanId,\n sampled: context.sampled,\n });\n\nexport const edaTraceContextFromSpan = (span: Tracer.AnySpan): EDATraceContext =>\n makeEDATraceContext({\n traceId: span.traceId,\n spanId: span.spanId,\n sampled: span.sampled,\n tracestate: null,\n });\n\nexport const currentEDATraceContext: Effect.Effect<EDATraceContext, unknown> =\n Effect.currentSpan.pipe(Effect.map(edaTraceContextFromSpan));\n\nexport const currentOrRootEDAEventTrace: Effect.Effect<EDAEventTrace> = Effect.currentSpan.pipe(\n Effect.map((span) => makeEDAEventTrace(edaTraceContextFromSpan(span))),\n Effect.catch(() => Effect.sync(makeRootEDAEventTrace)),\n);\n\nexport const withEdaTraceMetadata =\n (metadata: EDATraceMetadata) =>\n <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>\n effect.pipe(Effect.annotateSpans(metadata.attributes));\n\n/** Add EDA attributes to the currently active span. */\nexport const annotateEdaSpan = (attributes: EdaSpanAttributes): Effect.Effect<void> =>\n Effect.annotateCurrentSpan(compactSpanAttributes(attributes));\n\nconst nanosToMillis = (nanos: bigint): number => Number(nanos / 1_000_000n);\n\nconst outcomeFromExit = (exit: Exit.Exit<unknown, unknown>): EDAExportedSpan[\"outcome\"] => {\n if (Exit.isSuccess(exit)) {\n return \"ok\";\n }\n return Cause.hasInterruptsOnly(exit.cause) ? \"canceled\" : \"error\";\n};\n\nconst statusMessageFromExit = (exit: Exit.Exit<unknown, unknown>): string | undefined => {\n if (Exit.isSuccess(exit)) {\n return undefined;\n }\n const error = Cause.squash(exit.cause);\n return error instanceof Error ? error.message : String(error);\n};\n\nclass ExportingNativeSpan extends Tracer.NativeSpan {\n readonly #emit: (span: EDAExportedSpan) => void;\n\n constructor(\n options: ConstructorParameters<typeof Tracer.NativeSpan>[0],\n emit: (span: EDAExportedSpan) => void,\n ) {\n super(options);\n this.#emit = emit;\n }\n\n override end(endTime: bigint, exit: Exit.Exit<unknown, unknown>): void {\n super.end(endTime, exit);\n // Workers can report the same clock tick for very fast operations. Such spans\n // add noise without describing execution, so keep them out of exported traces.\n if (endTime <= this.startTime) {\n return;\n }\n const parent = Option.getOrUndefined(this.parent);\n this.#emit({\n attributes: compactUnknownAttributes(this.attributes),\n endedAtMs: nanosToMillis(endTime),\n endedAtUnixNano: endTime.toString(),\n kind: this.kind,\n links: this.links.map((link) => ({\n attributes: compactUnknownAttributes(link.attributes),\n traceId: link.span.traceId,\n spanId: link.span.spanId,\n sampled: link.span.sampled,\n })),\n name: this.name,\n outcome: outcomeFromExit(exit),\n ...(parent === undefined ? {} : { parentSpanId: parent.spanId }),\n sampled: this.sampled,\n spanId: this.spanId,\n startedAtMs: nanosToMillis(this.startTime),\n startedAtUnixNano: this.startTime.toString(),\n statusCode: Exit.isSuccess(exit) ? \"OK\" : \"ERROR\",\n ...(statusMessageFromExit(exit) === undefined\n ? {}\n : { statusMessage: statusMessageFromExit(exit) }),\n traceId: this.traceId,\n });\n }\n}\n\n/** Create an Effect tracer that exports only spans with observable duration. */\nexport const makeEdaExportingTracer = (emit: (span: EDAExportedSpan) => void): Tracer.Tracer =>\n Tracer.make({\n span: (options) => new ExportingNativeSpan(options, emit),\n });\n\n/** Summarize a durable/logical event collection for span attributes. */\nexport const eventBatchAttributes = (events: ReadonlyArray<EventLike>): EdaSpanAttributes => ({\n \"eda.event.count\": events.length,\n \"eda.event.types\": eventTypeSummary(events),\n});\n\n/** Summarize a committed positioned event collection for span attributes. */\nexport const committedBatchAttributes = (\n events: ReadonlyArray<PositionedEventLike>,\n): EdaSpanAttributes => {\n const seqs = events\n .map((entry) => entry.position?.seq)\n .filter((seq): seq is number => typeof seq === \"number\");\n return {\n ...eventBatchAttributes(events),\n \"eda.seq.min\": seqs.length === 0 ? undefined : Math.min(...seqs),\n \"eda.seq.max\": seqs.length === 0 ? undefined : Math.max(...seqs),\n };\n};\n\n/** Stable, low-cardinality usage attributes for model lifecycle spans. */\nexport const usageAttributes = (usage: UsagePayload | undefined): EdaSpanAttributes => ({\n \"eda.usage.input_tokens\": usage?.inputTokens,\n \"eda.usage.cached_input_tokens\": usage?.cachedInputTokens,\n \"eda.usage.output_tokens\": usage?.outputTokens,\n \"eda.usage.text_tokens\": usage?.textTokens,\n \"eda.usage.reasoning_tokens\": usage?.reasoningTokens,\n});\n\nconst eventTypeSummary = (events: ReadonlyArray<EventLike>): string | undefined => {\n if (events.length === 0) {\n return undefined;\n }\n const seen = new Set<string>();\n for (const event of events) {\n const type = event.event?.type ?? event.type;\n if (typeof type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,KAAK,UAAU,SAAS;GAC3C,YAAY,KAAK,UAAU,IAAI,IAAI,OAAO;GAC1C,GAAI,sBAAsB,IAAI,MAAM,KAAA,IAChC,CAAC,IACD,EAAE,eAAe,sBAAsB,IAAI,EAAE;GACjD,SAAS,KAAK;EAChB,CAAC;CACH;AACF;;AAGA,MAAa,0BAA0B,SACrC,OAAO,KAAK,EACV,OAAO,YAAY,IAAI,oBAAoB,SAAS,IAAI,EAC1D,CAAC;;AAGH,MAAa,wBAAwB,YAAyD;CAC5F,mBAAmB,OAAO;CAC1B,mBAAmB,iBAAiB,MAAM;AAC5C;;AAGA,MAAa,4BACX,WACsB;CACtB,MAAM,OAAO,OACV,KAAK,UAAU,MAAM,UAAU,GAAG,EAClC,QAAQ,QAAuB,OAAO,QAAQ,QAAQ;CACzD,OAAO;EACL,GAAG,qBAAqB,MAAM;EAC9B,eAAe,KAAK,WAAW,IAAI,KAAA,IAAY,KAAK,IAAI,GAAG,IAAI;EAC/D,eAAe,KAAK,WAAW,IAAI,KAAA,IAAY,KAAK,IAAI,GAAG,IAAI;CACjE;AACF;;AAGA,MAAa,mBAAmB,WAAwD;CACtF,0BAA0B,OAAO;CACjC,iCAAiC,OAAO;CACxC,2BAA2B,OAAO;CAClC,yBAAyB,OAAO;CAChC,8BAA8B,OAAO;AACvC;AAEA,MAAM,oBAAoB,WAAyD;CACjF,IAAI,OAAO,WAAW,GACpB;CAEF,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,OAAO,MAAM,OAAO,QAAQ,MAAM;EACxC,IAAI,OAAO,SAAS,UAClB,KAAK,IAAI,IAAI;CAEjB;CACA,OAAO,KAAK,SAAS,IAAI,KAAA,IAAY,MAAM,KAAK,IAAI,EAAE,KAAK,GAAG;AAChE"}
|
|
1
|
+
{"version":3,"file":"tracing.js","names":["#emit"],"sources":["../../src/services/tracing.ts"],"sourcesContent":["import * as Cause from \"effect/Cause\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport * as Option from \"effect/Option\";\nimport * as Tracer from \"effect/Tracer\";\n\nimport type { UsagePayload } from \"../types/events\";\nimport {\n EDATraceContext,\n type EDAEventTrace,\n type EDATraceAttributeValue,\n type EDATraceMetadata,\n makeEDAEventTrace,\n makeEDATraceContext,\n makeRootEDAEventTrace,\n} from \"../types/tracing\";\n\nexport {\n EDATraceContext,\n EDARunTrace,\n EDATraceLink,\n EDATraceMetadata,\n EDAEventTrace,\n makeEDAEventTrace,\n makeEDARunTrace,\n makeEDATraceContext,\n makeEDATraceMetadataFromParent,\n makeRootEDAEventTrace,\n makeRootEDATraceMetadata,\n} from \"../types/tracing\";\n\nexport { buildEDATraceparent, parseEDATraceparent } from \"../types/tracing\";\n\n/** Attribute value types accepted by Effect span annotations after compaction. */\nexport type EdaSpanAttributeValue = EDATraceAttributeValue | undefined;\n\n/** EDA span attribute map; undefined values are intentionally dropped before annotation. */\nexport type EdaSpanAttributes = Record<string, EdaSpanAttributeValue>;\n\nexport interface EDATracingOptions {\n readonly disableTracing?: boolean;\n readonly disableSpanPropagation?: boolean;\n readonly spanAttributes?: EdaSpanAttributes;\n readonly spanPrefix?: string;\n}\n\nexport interface EDAExportedSpanLink {\n readonly attributes: Record<string, string | number | boolean>;\n readonly sampled: boolean;\n readonly spanId: string;\n readonly traceId: string;\n}\n\nexport interface EDAExportedSpan {\n readonly attributes: Record<string, string | number | boolean>;\n readonly endedAtMs: number;\n readonly endedAtUnixNano: string;\n readonly kind: Tracer.SpanKind;\n readonly links: ReadonlyArray<EDAExportedSpanLink>;\n readonly name: string;\n readonly outcome: \"ok\" | \"error\" | \"timeout\" | \"canceled\";\n readonly parentSpanId?: string;\n readonly sampled: boolean;\n readonly spanId: string;\n readonly startedAtMs: number;\n readonly startedAtUnixNano: string;\n readonly statusCode: \"OK\" | \"ERROR\";\n readonly statusMessage?: string;\n readonly traceId: string;\n}\n\n/** Maximum primitive attributes copied from one native Effect span or link. */\nconst MAX_EXPORTED_SPAN_ATTRIBUTES = 256;\n\ninterface EventLike {\n readonly event?: { readonly type?: unknown; readonly durability?: unknown };\n readonly type?: unknown;\n}\n\ninterface PositionedEventLike {\n readonly position?: { readonly seq?: unknown; readonly subSeq?: unknown };\n readonly event?: { readonly type?: unknown; readonly durability?: unknown };\n}\n\n/** Compact undefined tracing attributes before handing them to Effect spans. */\nexport const compactSpanAttributes = (\n attributes: EdaSpanAttributes,\n): Record<string, string | number | boolean> => {\n const compacted: Record<string, string | number | boolean> = {};\n for (const [key, value] of Object.entries(attributes)) {\n if (value !== undefined) {\n compacted[key] = value;\n }\n }\n return compacted;\n};\n\nconst compactUnknownAttributes = (\n attributes: Readonly<Record<string, unknown>> | ReadonlyMap<string, unknown>,\n): Record<string, string | number | boolean> => {\n const compacted: Record<string, string | number | boolean> = {};\n try {\n if (attributes instanceof Map) {\n let count = 0;\n for (const [key, value] of attributes) {\n if (count >= MAX_EXPORTED_SPAN_ATTRIBUTES) {\n break;\n }\n count += 1;\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n compacted[key] = value;\n }\n }\n return compacted;\n }\n\n const keys = Object.keys(attributes).slice(0, MAX_EXPORTED_SPAN_ATTRIBUTES);\n for (const key of keys) {\n let value: unknown;\n try {\n value = Reflect.get(attributes, key);\n } catch {\n continue;\n }\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n compacted[key] = value;\n }\n }\n } catch {\n // Tracing diagnostics must not replace the operation whose span is ending.\n }\n return compacted;\n};\n\nexport const toEdaExternalSpan = (context: EDATraceContext): Tracer.ExternalSpan =>\n Tracer.externalSpan({\n traceId: context.traceId,\n spanId: context.spanId,\n sampled: context.sampled,\n });\n\nexport const edaTraceContextFromSpan = (span: Tracer.AnySpan): EDATraceContext =>\n makeEDATraceContext({\n traceId: span.traceId,\n spanId: span.spanId,\n sampled: span.sampled,\n tracestate: null,\n });\n\nexport const currentEDATraceContext: Effect.Effect<EDATraceContext, unknown> =\n Effect.currentSpan.pipe(Effect.map(edaTraceContextFromSpan));\n\nexport const currentOrRootEDAEventTrace: Effect.Effect<EDAEventTrace> = Effect.currentSpan.pipe(\n Effect.map((span) => makeEDAEventTrace(edaTraceContextFromSpan(span))),\n Effect.catch(() => Effect.sync(makeRootEDAEventTrace)),\n);\n\nexport const withEdaTraceMetadata =\n (metadata: EDATraceMetadata) =>\n <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>\n effect.pipe(Effect.annotateSpans(metadata.attributes));\n\n/** Add EDA attributes to the currently active span. */\nexport const annotateEdaSpan = (attributes: EdaSpanAttributes): Effect.Effect<void> =>\n Effect.annotateCurrentSpan(compactSpanAttributes(attributes));\n\nconst nanosToMillis = (nanos: bigint): number => Number(nanos / 1_000_000n);\n\nconst outcomeFromExit = (exit: Exit.Exit<unknown, unknown>): EDAExportedSpan[\"outcome\"] => {\n if (Exit.isSuccess(exit)) {\n return \"ok\";\n }\n return Cause.hasInterruptsOnly(exit.cause) ? \"canceled\" : \"error\";\n};\n\nconst statusMessageFromExit = (exit: Exit.Exit<unknown, unknown>): string | undefined => {\n if (Exit.isSuccess(exit)) {\n return undefined;\n }\n const error = Cause.squash(exit.cause);\n return error instanceof Error ? error.message : String(error);\n};\n\nclass ExportingNativeSpan extends Tracer.NativeSpan {\n readonly #emit: (span: EDAExportedSpan) => void;\n\n constructor(\n options: ConstructorParameters<typeof Tracer.NativeSpan>[0],\n emit: (span: EDAExportedSpan) => void,\n ) {\n super(options);\n this.#emit = emit;\n }\n\n override end(endTime: bigint, exit: Exit.Exit<unknown, unknown>): void {\n super.end(endTime, exit);\n // Keep the two startup summaries even within one clock tick: their checkpoint\n // and reuse counts explain why initialization was fast. Other zero-duration\n // spans add noise without describing execution.\n if (\n endTime <= this.startTime &&\n this.name !== \"agent.session.hydrate\" &&\n this.name !== \"agent.sinks.initialize\"\n ) {\n return;\n }\n const parent = Option.getOrUndefined(this.parent);\n this.#emit({\n attributes: compactUnknownAttributes(this.attributes),\n endedAtMs: nanosToMillis(endTime),\n endedAtUnixNano: endTime.toString(),\n kind: this.kind,\n links: this.links.map((link) => ({\n attributes: compactUnknownAttributes(link.attributes),\n traceId: link.span.traceId,\n spanId: link.span.spanId,\n sampled: link.span.sampled,\n })),\n name: this.name,\n outcome: outcomeFromExit(exit),\n ...(parent === undefined ? {} : { parentSpanId: parent.spanId }),\n sampled: this.sampled,\n spanId: this.spanId,\n startedAtMs: nanosToMillis(this.startTime),\n startedAtUnixNano: this.startTime.toString(),\n statusCode: Exit.isSuccess(exit) ? \"OK\" : \"ERROR\",\n ...(statusMessageFromExit(exit) === undefined\n ? {}\n : { statusMessage: statusMessageFromExit(exit) }),\n traceId: this.traceId,\n });\n }\n}\n\n/** Create an Effect tracer that exports only spans with observable duration. */\nexport const makeEdaExportingTracer = (emit: (span: EDAExportedSpan) => void): Tracer.Tracer =>\n Tracer.make({\n span: (options) => new ExportingNativeSpan(options, emit),\n });\n\n/** Summarize a durable/logical event collection for span attributes. */\nexport const eventBatchAttributes = (events: ReadonlyArray<EventLike>): EdaSpanAttributes => ({\n \"eda.event.count\": events.length,\n \"eda.event.types\": eventTypeSummary(events),\n});\n\n/** Summarize a committed positioned event collection for span attributes. */\nexport const committedBatchAttributes = (\n events: ReadonlyArray<PositionedEventLike>,\n): EdaSpanAttributes => {\n const seqs = events\n .map((entry) => entry.position?.seq)\n .filter((seq): seq is number => typeof seq === \"number\");\n return {\n ...eventBatchAttributes(events),\n \"eda.seq.min\": seqs.length === 0 ? undefined : Math.min(...seqs),\n \"eda.seq.max\": seqs.length === 0 ? undefined : Math.max(...seqs),\n };\n};\n\n/** Stable, low-cardinality usage attributes for model lifecycle spans. */\nexport const usageAttributes = (usage: UsagePayload | undefined): EdaSpanAttributes => ({\n \"eda.usage.input_tokens\": usage?.inputTokens,\n \"eda.usage.cached_input_tokens\": usage?.cachedInputTokens,\n \"eda.usage.output_tokens\": usage?.outputTokens,\n \"eda.usage.text_tokens\": usage?.textTokens,\n \"eda.usage.reasoning_tokens\": usage?.reasoningTokens,\n});\n\nconst eventTypeSummary = (events: ReadonlyArray<EventLike>): string | undefined => {\n if (events.length === 0) {\n return undefined;\n }\n const seen = new Set<string>();\n for (const event of events) {\n const type = event.event?.type ?? event.type;\n if (typeof type === \"string\") {\n seen.add(type);\n }\n }\n return seen.size === 0 ? undefined : Array.from(seen).join(\",\");\n};\n"],"mappings":";;;;;;;;AAwEA,MAAM,+BAA+B;;AAarC,MAAa,yBACX,eAC8C;CAC9C,MAAM,YAAuD,CAAC;CAC9D,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,GAClD,IAAI,UAAU,KAAA,GACZ,UAAU,OAAO;CAGrB,OAAO;AACT;AAEA,MAAM,4BACJ,eAC8C;CAC9C,MAAM,YAAuD,CAAC;CAC9D,IAAI;EACF,IAAI,sBAAsB,KAAK;GAC7B,IAAI,QAAQ;GACZ,KAAK,MAAM,CAAC,KAAK,UAAU,YAAY;IACrC,IAAI,SAAS,8BACX;IAEF,SAAS;IACT,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,WAC7E,UAAU,OAAO;GAErB;GACA,OAAO;EACT;EAEA,MAAM,OAAO,OAAO,KAAK,UAAU,EAAE,MAAM,GAAG,4BAA4B;EAC1E,KAAK,MAAM,OAAO,MAAM;GACtB,IAAI;GACJ,IAAI;IACF,QAAQ,QAAQ,IAAI,YAAY,GAAG;GACrC,QAAQ;IACN;GACF;GACA,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,WAC7E,UAAU,OAAO;EAErB;CACF,QAAQ,CAER;CACA,OAAO;AACT;AAEA,MAAa,qBAAqB,YAChC,OAAO,aAAa;CAClB,SAAS,QAAQ;CACjB,QAAQ,QAAQ;CAChB,SAAS,QAAQ;AACnB,CAAC;AAEH,MAAa,2BAA2B,SACtC,oBAAoB;CAClB,SAAS,KAAK;CACd,QAAQ,KAA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AClB,KAAK,IAAI,IAAI;CAEjB;CACA,OAAO,KAAK,SAAS,IAAI,KAAA,IAAY,MAAM,KAAK,IAAI,EAAE,KAAK,GAAG;AAChE"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { h as SequenceNumber, m as RunRequestId } from "./core-C-6xHzRx.js";
|
|
2
|
-
import { $ as RunRequestOutcome, S as ReducedState } from "./command-queues-
|
|
2
|
+
import { $ as RunRequestOutcome, S as ReducedState } from "./command-queues-CSEl1yrH.js";
|
|
3
3
|
import { d as PositionedEvent } from "./envelope-DkZyMIgp.js";
|
|
4
|
-
import { a as EDASessionStore, o as EDASessionStoreError } from "./session-store-
|
|
5
|
-
import { t as DurableTranscriptMessage } from "./message-transcript-
|
|
6
|
-
import {
|
|
7
|
-
import { a as EDAReducerStateSnapshot } from "./reducer-registry-
|
|
8
|
-
import { h as SessionState } from "./session-state-13z-3YaF.js";
|
|
4
|
+
import { a as EDASessionStore, o as EDASessionStoreError } from "./session-store-DCs--1kc.js";
|
|
5
|
+
import { t as DurableTranscriptMessage } from "./message-transcript-CmCHC1Pg.js";
|
|
6
|
+
import { C as LiveEventBus, h as SessionState } from "./session-state-D4g0kV_K.js";
|
|
7
|
+
import { a as EDAReducerStateSnapshot } from "./reducer-registry-BgtK0NuX.js";
|
|
9
8
|
import * as Context from "effect/Context";
|
|
10
9
|
import * as Effect from "effect/Effect";
|
|
11
10
|
import * as Layer from "effect/Layer";
|
|
@@ -44,4 +43,4 @@ declare class EDASessionQuery extends EDASessionQuery_base {
|
|
|
44
43
|
}
|
|
45
44
|
//#endregion
|
|
46
45
|
export { EDASessionSnapshot as i, EDASessionQuery as n, EDASessionQueryShape as r, EDASessionEventPage as t };
|
|
47
|
-
//# sourceMappingURL=session-query-
|
|
46
|
+
//# sourceMappingURL=session-query-CMeJog1g.d.ts.map
|
|
@@ -1,27 +1,55 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as TurnId } from "./core-C-6xHzRx.js";
|
|
2
|
+
import { Q as RunGrantResult, S as ReducedState } from "./command-queues-CSEl1yrH.js";
|
|
2
3
|
import { d as PositionedEvent, l as ModelSelectionPayload, n as EphemeralEventEnvelope, t as DurableEventEnvelope, u as NonNegativeInt } from "./envelope-DkZyMIgp.js";
|
|
3
4
|
import { i as GrantRunCommand, r as EDACommand } from "./commands-p8venTWs.js";
|
|
4
5
|
import { zt as ToolCallCreatedEvent } from "./durable-DeLCAvbw.js";
|
|
5
|
-
import { a as EDASessionStore, o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-
|
|
6
|
+
import { a as EDASessionStore, o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-DCs--1kc.js";
|
|
6
7
|
import { t as ModelResolver } from "./model-resolver-BPPJAsuh.js";
|
|
7
8
|
import { t as IdGenerator } from "./id-generator--x6itQZ2.js";
|
|
8
9
|
import { r as SessionContext, t as EventFactory } from "./event-factory-EL4szNWm.js";
|
|
9
10
|
import { t as EDAKeepAlive } from "./keep-alive-Chl5SJxy.js";
|
|
10
|
-
import { d as CompactionRunner } from "./compaction-
|
|
11
|
-
import {
|
|
12
|
-
import { a as EDAReducerStateSnapshot, r as EDAReducerRegistry } from "./reducer-registry-
|
|
13
|
-
import { r as EDAPromptProjector } from "./prompt-projector-
|
|
14
|
-
import {
|
|
15
|
-
import { t as
|
|
16
|
-
import {
|
|
11
|
+
import { d as CompactionRunner } from "./compaction-DYAlYxx5.js";
|
|
12
|
+
import { t as SessionEventObserver } from "./session-event-observer-DaFMKKNc.js";
|
|
13
|
+
import { a as EDAReducerStateSnapshot, r as EDAReducerRegistry } from "./reducer-registry-BgtK0NuX.js";
|
|
14
|
+
import { r as EDAPromptProjector } from "./prompt-projector-_Zxe7dlE.js";
|
|
15
|
+
import { s as EDASinkRegistry } from "./sink-registry-CAtl5OWV.js";
|
|
16
|
+
import { t as RunScheduler } from "./run-scheduler-BBqZ0Ate.js";
|
|
17
|
+
import { t as RunSchedulingWakeup } from "./run-scheduling-wakeup-DRYZztL6.js";
|
|
18
|
+
import { r as EDAToolRegistry } from "./tool-registry-CHMtDCJ5.js";
|
|
17
19
|
import * as Context from "effect/Context";
|
|
18
20
|
import * as Effect from "effect/Effect";
|
|
19
21
|
import * as Layer from "effect/Layer";
|
|
20
22
|
import * as Schema from "effect/Schema";
|
|
23
|
+
import * as Stream from "effect/Stream";
|
|
21
24
|
import * as Prompt from "effect/unstable/ai/Prompt";
|
|
22
25
|
import * as Cause from "effect/Cause";
|
|
26
|
+
import * as Scope from "effect/Scope";
|
|
27
|
+
import * as PubSub from "effect/PubSub";
|
|
23
28
|
import * as Response from "effect/unstable/ai/Response";
|
|
24
29
|
|
|
30
|
+
//#region src/services/live-event-bus.d.ts
|
|
31
|
+
/** Live-only replay buffer for the currently open turn. */
|
|
32
|
+
interface ActiveTurnEphemeralReplay {
|
|
33
|
+
readonly turnId?: TurnId;
|
|
34
|
+
readonly events: ReadonlyArray<PositionedEvent>;
|
|
35
|
+
readonly overflowed: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** In-memory live fanout plus active-turn replay source for reconnect streams. */
|
|
38
|
+
interface LiveEventBusShape {
|
|
39
|
+
readonly publish: (event: PositionedEvent) => Effect.Effect<boolean>;
|
|
40
|
+
readonly subscribe: () => Effect.Effect<Stream.Stream<PositionedEvent>, never, Scope.Scope>;
|
|
41
|
+
readonly subscribeQueue: () => Effect.Effect<PubSub.Subscription<PositionedEvent>, never, Scope.Scope>;
|
|
42
|
+
/** Snapshot raw live-only events retained for the currently open turn. */
|
|
43
|
+
readonly activeTurnReplay: () => Effect.Effect<ActiveTurnEphemeralReplay>;
|
|
44
|
+
}
|
|
45
|
+
declare const LiveEventBus_base: Context.ServiceClass<LiveEventBus, "@effect-durable-agent/LiveEventBus", LiveEventBusShape>;
|
|
46
|
+
/** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */
|
|
47
|
+
declare class LiveEventBus extends LiveEventBus_base {
|
|
48
|
+
static readonly Live: Layer.Layer<LiveEventBus, never, SessionEventObserver>;
|
|
49
|
+
/** Live bus for hosts that do not install an append-driven observer. */
|
|
50
|
+
static readonly Noop: Layer.Layer<LiveEventBus, never, never>;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
25
53
|
//#region src/services/session-event-sink.d.ts
|
|
26
54
|
/**
|
|
27
55
|
* Narrow write/publish capability passed from `SessionState` into execution subcomponents.
|
|
@@ -145,7 +173,7 @@ interface ToolExecutorShape {
|
|
|
145
173
|
declare const ToolExecutor_base: Context.ServiceClass<ToolExecutor, "@effect-durable-agent/ToolExecutor", ToolExecutorShape>;
|
|
146
174
|
/** Executes sealed framework-owned tool calls and commits tool lifecycle boundaries. */
|
|
147
175
|
declare class ToolExecutor extends ToolExecutor_base {
|
|
148
|
-
static readonly Live: Layer.Layer<ToolExecutor, never,
|
|
176
|
+
static readonly Live: Layer.Layer<ToolExecutor, never, IdGenerator | EDAToolRegistry | SessionContext | EventFactory>;
|
|
149
177
|
}
|
|
150
178
|
//#endregion
|
|
151
179
|
//#region src/services/inference-runner.d.ts
|
|
@@ -293,7 +321,7 @@ interface InferenceRunnerShape {
|
|
|
293
321
|
declare const InferenceRunner_base: Context.ServiceClass<InferenceRunner, "@effect-durable-agent/InferenceRunner", InferenceRunnerShape>;
|
|
294
322
|
/** Owns provider inference streams and routes them into durable/live inference emissions. */
|
|
295
323
|
declare class InferenceRunner extends InferenceRunner_base {
|
|
296
|
-
static readonly Live: Layer.Layer<InferenceRunner, never, ModelResolver |
|
|
324
|
+
static readonly Live: Layer.Layer<InferenceRunner, never, ModelResolver | IdGenerator | EDAToolRegistry | EventFactory>;
|
|
297
325
|
}
|
|
298
326
|
//#endregion
|
|
299
327
|
//#region src/services/turn-runner.d.ts
|
|
@@ -546,7 +574,7 @@ interface TurnRunnerShape {
|
|
|
546
574
|
declare const TurnRunner_base: Context.ServiceClass<TurnRunner, "@effect-durable-agent/TurnRunner", TurnRunnerShape>;
|
|
547
575
|
/** Owns one turn: turn boundaries, inferences, tool handoff, and terminal turn events. */
|
|
548
576
|
declare class TurnRunner extends TurnRunner_base {
|
|
549
|
-
static readonly Live: Layer.Layer<TurnRunner, never,
|
|
577
|
+
static readonly Live: Layer.Layer<TurnRunner, never, IdGenerator | EventFactory | InferenceRunner | ToolExecutor>;
|
|
550
578
|
}
|
|
551
579
|
//#endregion
|
|
552
580
|
//#region src/services/session-state.d.ts
|
|
@@ -860,8 +888,8 @@ interface SessionStateShape extends SessionEventSink {
|
|
|
860
888
|
declare const SessionState_base: Context.ServiceClass<SessionState, "@effect-durable-agent/SessionState", SessionStateShape>;
|
|
861
889
|
/** Internal authoritative live state and root control loop for one session. */
|
|
862
890
|
declare class SessionState extends SessionState_base {
|
|
863
|
-
static readonly Live: Layer.Layer<SessionState, EDASessionStoreError, RunScheduler |
|
|
891
|
+
static readonly Live: Layer.Layer<SessionState, EDASessionStoreError, RunScheduler | EDASessionStore | LiveEventBus | RunSchedulingWakeup | IdGenerator | EDAKeepAlive | EDAReducerRegistry | EDAPromptProjector | EDASinkRegistry | SessionContext | EventFactory | CompactionRunner | TurnRunner>;
|
|
864
892
|
}
|
|
865
893
|
//#endregion
|
|
866
|
-
export { ToolExecutor as S, SessionStateShape as _, SessionCommandCompleted as a, InferenceRunner as b, SessionCommandResult as c, SessionForkedCommand as d, SessionNoRunnableCommand as f, SessionStateError as g, SessionState as h, SessionCommandCancelled as i, SessionDrainProcessed as l, SessionRunInput as m, SessionCommandAdmissionConflict as n, SessionCommandFailed as o, SessionNoRunnableReason as p, SessionCommandAdmissionError as r, SessionCommandOutcome as s, EDASubmittable as t, SessionDrainResult as u, SessionStateSnapshotData as v, InferenceRunnerStreamPart as x, TurnRunner as y };
|
|
867
|
-
//# sourceMappingURL=session-state-
|
|
894
|
+
export { LiveEventBus as C, ToolExecutor as S, SessionStateShape as _, SessionCommandCompleted as a, InferenceRunner as b, SessionCommandResult as c, SessionForkedCommand as d, SessionNoRunnableCommand as f, SessionStateError as g, SessionState as h, SessionCommandCancelled as i, SessionDrainProcessed as l, SessionRunInput as m, SessionCommandAdmissionConflict as n, SessionCommandFailed as o, SessionNoRunnableReason as p, SessionCommandAdmissionError as r, SessionCommandOutcome as s, EDASubmittable as t, SessionDrainResult as u, SessionStateSnapshotData as v, InferenceRunnerStreamPart as x, TurnRunner as y };
|
|
895
|
+
//# sourceMappingURL=session-state-D4g0kV_K.d.ts.map
|
|
@@ -6,7 +6,7 @@ import { ModelResolver } from "./services/model-resolver.js";
|
|
|
6
6
|
import { makeEDARunTrace } from "./types/tracing.js";
|
|
7
7
|
import { c as ModelSelectionPayload, d as ProviderPartId, l as NonNegativeInt, m as ToolName, p as SystemPromptText, s as FailurePayload, u as PositionedEvent } from "./envelope-DxQzo5rN.js";
|
|
8
8
|
import { CancelPendingMessageCommand, PromotePendingMessageCommand, ResumePendingMessagesCommand, StopTurnCommand, SubmitMessageCommand } from "./types/commands.js";
|
|
9
|
-
import { Bn as inferenceFailedEventType, En as commandAdmittedEventType, fr as turnFailedEventType, lr as toolCallRejectedEventType, sr as toolCallCreatedEventType, zn as inferenceCompletedEventType } from "./durable-BPHVFVvV.js";
|
|
9
|
+
import { Bn as inferenceFailedEventType, En as commandAdmittedEventType, dr as turnCompletedEventType, fr as turnFailedEventType, lr as toolCallRejectedEventType, mr as turnStoppedEventType, pr as turnStartedEventType, sr as toolCallCreatedEventType, zn as inferenceCompletedEventType } from "./durable-BPHVFVvV.js";
|
|
10
10
|
import { a as encodeReducedStateCheckpoint, h as assertNeverError, i as decodeReducedStateCheckpoint, l as initialReducedState, m as assertNever, n as activeTurnIdentityForCommand, o as foldReducedState, p as reducedStateCheckpointEventSeqs, r as classifyRecoverableWork, s as frameworkReducedStateReducerName } from "./reduced-state-Bz68V2H8.js";
|
|
11
11
|
import { ContextProjection, emptyContextProjection } from "./domain/context-projection.js";
|
|
12
12
|
import { CommittedDurableEvent, EDASessionStore, EDASessionStoreError, hasEDASessionStoreError } from "./services/session-store.js";
|
|
@@ -15,9 +15,10 @@ import { IdGenerator } from "./services/id-generator.js";
|
|
|
15
15
|
import { n as SessionContext, t as EventFactory } from "./event-factory-QuC_UvyP.js";
|
|
16
16
|
import { annotateEdaSpan, committedBatchAttributes, edaTraceContextFromSpan, eventBatchAttributes, toEdaExternalSpan, usageAttributes } from "./services/tracing.js";
|
|
17
17
|
import { EDAKeepAlive } from "./services/keep-alive.js";
|
|
18
|
-
import {
|
|
18
|
+
import { SessionEventObserver } from "./services/session-event-observer.js";
|
|
19
19
|
import { EDAPromptProjector, buildEDAPrompt } from "./services/prompt-projector.js";
|
|
20
20
|
import { EDAReducerRegistry, decodeReducerState, encodeReducerState, reducerSchemaVersion } from "./services/reducer-registry.js";
|
|
21
|
+
import { n as EDASinkRegistry } from "./sink-registry-B7cG7gxK.js";
|
|
21
22
|
import { EDAToolRegistry } from "./services/tool-registry.js";
|
|
22
23
|
import * as Context from "effect/Context";
|
|
23
24
|
import * as Effect from "effect/Effect";
|
|
@@ -34,6 +35,7 @@ import * as Ref from "effect/Ref";
|
|
|
34
35
|
import * as Scope from "effect/Scope";
|
|
35
36
|
import * as Semaphore from "effect/Semaphore";
|
|
36
37
|
import * as Option from "effect/Option";
|
|
38
|
+
import * as PubSub from "effect/PubSub";
|
|
37
39
|
import * as Response from "effect/unstable/ai/Response";
|
|
38
40
|
//#region src/domain/dispatch-policy.ts
|
|
39
41
|
/** Durable/runtime evidence for active work blocking new queued commands. */
|
|
@@ -259,6 +261,57 @@ const planRunFailure = (state) => ({ messageIdsToResume: state.commandQueues.pen
|
|
|
259
261
|
/** Normal explicit Stop/Interrupt policy. This is not startup recovery. */
|
|
260
262
|
const planUserInterruption = (state) => ({ messageIdsToPause: [...state.commandQueues.pendingQueue, ...state.commandQueues.pendingSteers].map((message) => message.messageId) });
|
|
261
263
|
//#endregion
|
|
264
|
+
//#region src/services/live-event-bus.ts
|
|
265
|
+
/** Conservative raw-delta cap for one open turn's live-only reconnect replay. */
|
|
266
|
+
const activeTurnEphemeralReplayCapacity = 4096;
|
|
267
|
+
/** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */
|
|
268
|
+
var LiveEventBus = class LiveEventBus extends Context.Service()("@effect-durable-agent/LiveEventBus") {
|
|
269
|
+
static Live = Layer.effect(LiveEventBus, Effect.gen(function* () {
|
|
270
|
+
return makeLiveBus(yield* Effect.acquireRelease(PubSub.unbounded(), PubSub.shutdown), yield* Ref.make({
|
|
271
|
+
events: [],
|
|
272
|
+
overflowed: false
|
|
273
|
+
}), yield* SessionEventObserver);
|
|
274
|
+
}));
|
|
275
|
+
/** Live bus for hosts that do not install an append-driven observer. */
|
|
276
|
+
static Noop = LiveEventBus.Live.pipe(Layer.provide(SessionEventObserver.Noop));
|
|
277
|
+
};
|
|
278
|
+
const makeLiveBus = (pubsub, activeTurnReplay, observer) => ({
|
|
279
|
+
publish: (event) => Effect.gen(function* () {
|
|
280
|
+
yield* updateActiveTurnReplay(activeTurnReplay, event);
|
|
281
|
+
yield* observer.onEvent(event);
|
|
282
|
+
return yield* PubSub.publish(pubsub, event);
|
|
283
|
+
}),
|
|
284
|
+
subscribeQueue: () => PubSub.subscribe(pubsub),
|
|
285
|
+
subscribe: () => Effect.map(PubSub.subscribe(pubsub), (subscription) => Stream.fromEffectRepeat(PubSub.take(subscription))),
|
|
286
|
+
activeTurnReplay: () => Ref.get(activeTurnReplay)
|
|
287
|
+
});
|
|
288
|
+
const updateActiveTurnReplay = (ref, event) => Ref.update(ref, (state) => nextActiveTurnReplay(state, event));
|
|
289
|
+
const nextActiveTurnReplay = (state, event) => {
|
|
290
|
+
if (event.event.type === turnStartedEventType) return {
|
|
291
|
+
turnId: event.event.payload.turnId,
|
|
292
|
+
events: [],
|
|
293
|
+
overflowed: false
|
|
294
|
+
};
|
|
295
|
+
if (event.event.type === turnCompletedEventType || event.event.type === turnFailedEventType || event.event.type === turnStoppedEventType) {
|
|
296
|
+
const turnId = event.event.payload.turnId;
|
|
297
|
+
return turnId === void 0 || state.turnId === void 0 || turnId === state.turnId ? {
|
|
298
|
+
events: [],
|
|
299
|
+
overflowed: false
|
|
300
|
+
} : state;
|
|
301
|
+
}
|
|
302
|
+
if (event.event.durability !== "ephemeral" || state.turnId === void 0) return state;
|
|
303
|
+
const events = [...state.events, event];
|
|
304
|
+
if (events.length <= 4096) return {
|
|
305
|
+
...state,
|
|
306
|
+
events
|
|
307
|
+
};
|
|
308
|
+
return {
|
|
309
|
+
...state,
|
|
310
|
+
events: events.slice(events.length - activeTurnEphemeralReplayCapacity),
|
|
311
|
+
overflowed: true
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
//#endregion
|
|
262
315
|
//#region src/services/started-boundary-guard.ts
|
|
263
316
|
/** Build a guard bound to the session's durable append boundary. */
|
|
264
317
|
const makeStartedBoundaryGuard = (state) => (spec) => {
|
|
@@ -1513,8 +1566,23 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
1513
1566
|
const schedulingWakeup = yield* RunSchedulingWakeup;
|
|
1514
1567
|
const reducerRegistry = yield* EDAReducerRegistry;
|
|
1515
1568
|
const sinkRegistry = yield* EDASinkRegistry;
|
|
1516
|
-
const hydrated = yield*
|
|
1517
|
-
|
|
1569
|
+
const { hydrated, hydratedReducerStates } = yield* Effect.gen(function* () {
|
|
1570
|
+
const hydrated = yield* hydrateFrameworkReducedState(store);
|
|
1571
|
+
const hydratedReducerStates = yield* hydrateAppReducerStates(store, reducerRegistry.reducers);
|
|
1572
|
+
yield* Effect.annotateCurrentSpan({
|
|
1573
|
+
"eda.seq.head": hydrated.state.lastSeq,
|
|
1574
|
+
"eda.checkpoint.framework_seq": hydrated.checkpointSeq,
|
|
1575
|
+
...hydratedReducerStates.checkpointSeq === void 0 ? {} : { "eda.checkpoint.app_min_seq": hydratedReducerStates.checkpointSeq }
|
|
1576
|
+
});
|
|
1577
|
+
return {
|
|
1578
|
+
hydrated,
|
|
1579
|
+
hydratedReducerStates
|
|
1580
|
+
};
|
|
1581
|
+
}).pipe(Effect.withSpan("agent.session.hydrate", { attributes: {
|
|
1582
|
+
sessionId: sessionContext.sessionId,
|
|
1583
|
+
"eda.session.id": sessionContext.sessionId,
|
|
1584
|
+
"eda.reducers.count": reducerRegistry.reducers.length
|
|
1585
|
+
} }));
|
|
1518
1586
|
yield* schedulingWakeup.setPending(hydrated.state.runSchedulingRequest !== void 0 && hydrated.state.runSchedulingRequest.deliveredSeq === void 0);
|
|
1519
1587
|
const startupRecoveryCheckpointSeq = hydratedReducerStates.checkpointSeq === void 0 ? hydrated.checkpointSeq : SequenceNumber.make(Math.min(hydrated.checkpointSeq, hydratedReducerStates.checkpointSeq));
|
|
1520
1588
|
const state = yield* Ref.make({
|
|
@@ -1653,13 +1721,10 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
1653
1721
|
}
|
|
1654
1722
|
});
|
|
1655
1723
|
yield* liveBus.publish(positioned);
|
|
1724
|
+
yield* sinkRegistry.publishEphemeralToSinks(positioned);
|
|
1656
1725
|
return positioned;
|
|
1657
1726
|
}));
|
|
1658
|
-
const publishEphemeral =
|
|
1659
|
-
const positioned = yield* publishEphemeralCore(event);
|
|
1660
|
-
yield* sinkRegistry.publishEphemeralToSinks(positioned, publishEphemeralCore);
|
|
1661
|
-
return positioned;
|
|
1662
|
-
});
|
|
1727
|
+
const publishEphemeral = publishEphemeralCore;
|
|
1663
1728
|
const wakeAfterCommandAdmission = () => Queue.offer(ingressSignals, void 0);
|
|
1664
1729
|
/** Use indexed store lookup for command idempotency instead of genesis replay. */
|
|
1665
1730
|
const findExistingCommandAdmission = (command) => Effect.gen(function* () {
|
|
@@ -3092,6 +3157,6 @@ const requireTurnFailed = (committed) => isTurnFailed(committed) ? Effect.succee
|
|
|
3092
3157
|
const isTurnFailed = (committed) => committed.event.type === turnFailedEventType;
|
|
3093
3158
|
const isSessionNoRunnableCommand = (result) => "_tag" in result && result._tag === "SessionNoRunnableCommand";
|
|
3094
3159
|
//#endregion
|
|
3095
|
-
export { SessionCommandOutcome as a, SessionNoRunnableReason as c, TurnRunner as d, InferenceRunner as f, SessionCommandFailed as i, SessionRunInput as l, SessionCommandCancelled as n, SessionForkedCommand as o, ToolExecutor as p, SessionCommandCompleted as r, SessionNoRunnableCommand as s, SessionCommandAdmissionConflict as t, SessionState as u };
|
|
3160
|
+
export { SessionCommandOutcome as a, SessionNoRunnableReason as c, TurnRunner as d, InferenceRunner as f, SessionCommandFailed as i, SessionRunInput as l, LiveEventBus as m, SessionCommandCancelled as n, SessionForkedCommand as o, ToolExecutor as p, SessionCommandCompleted as r, SessionNoRunnableCommand as s, SessionCommandAdmissionConflict as t, SessionState as u };
|
|
3096
3161
|
|
|
3097
|
-
//# sourceMappingURL=session-state-
|
|
3162
|
+
//# sourceMappingURL=session-state-DtPwg_EP.js.map
|