effect-durable-agent 0.3.0 → 0.4.1
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/{delivery-BKYmgnKC.d.ts → delivery-BygJwrSV.d.ts} +2 -2
- package/dist/domain/command-queues.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/{reduced-state-DV0696_s.d.ts → reduced-state-BvNK4zug.d.ts} +423 -400
- package/dist/services/compaction.d.ts +1 -1
- package/dist/services/decider.d.ts +1 -1
- package/dist/services/model-call.d.ts +1 -1
- package/dist/services/prompt-projector.d.ts +1 -1
- package/dist/services/run-scheduler.d.ts +1 -1
- package/dist/services/runtime-layer.d.ts +1 -2
- package/dist/services/runtime-layer.js +1 -1
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +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 +1 -1
- package/dist/services/session-state.d.ts +1 -1
- package/dist/services/session-state.js +1 -1
- package/dist/services/sink-registry.d.ts +1 -1
- package/dist/services/tool-registry.d.ts +1 -1
- package/dist/{session-state-BbJW2_P0.js → session-state-oUTUeAuF.js} +109 -16
- package/dist/session-state-oUTUeAuF.js.map +1 -0
- package/dist/testkit/layers.d.ts +1 -2
- package/dist/testkit/layers.js +1 -1
- package/dist/websocket/events.d.ts +1 -1
- package/dist/websocket.d.ts +1 -1
- package/package.json +1 -1
- package/dist/session-event-observer-BWQUJTcN.d.ts +0 -24
- package/dist/session-state-BbJW2_P0.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $t as PromptPrefixSummaryCompactionExecutorOptions, Bt as CompactionError, Gt as CompactionPlan, Ht as CompactionExecutorInput, Jt as CompactionPolicyShape, Kt as CompactionPolicy, Qt as LanguageModelSummaryCompactionExecutorOptions, Ut as CompactionExecutorShape, Vt as CompactionExecutor, Wt as CompactionOutput, Xt as CompactionRunnerInput, Yt as CompactionRunner, Zt as CompactionRunnerShape, an as promptPrefixSummaryCompactionExecutor, en as defaultCompactionCharsPerToken, in as defaultCompactionThresholdTokens, nn as defaultCompactionRetainTailTokens, qt as CompactionPolicyInput, rn as defaultCompactionSummaryInstructions, tn as defaultCompactionMinSummarizableTokens, zt as ApproximateTokenThresholdCompactionPolicyOptions } from "../reduced-state-
|
|
1
|
+
import { $t as PromptPrefixSummaryCompactionExecutorOptions, Bt as CompactionError, Gt as CompactionPlan, Ht as CompactionExecutorInput, Jt as CompactionPolicyShape, Kt as CompactionPolicy, Qt as LanguageModelSummaryCompactionExecutorOptions, Ut as CompactionExecutorShape, Vt as CompactionExecutor, Wt as CompactionOutput, Xt as CompactionRunnerInput, Yt as CompactionRunner, Zt as CompactionRunnerShape, an as promptPrefixSummaryCompactionExecutor, en as defaultCompactionCharsPerToken, in as defaultCompactionThresholdTokens, nn as defaultCompactionRetainTailTokens, qt as CompactionPolicyInput, rn as defaultCompactionSummaryInstructions, tn as defaultCompactionMinSummarizableTokens, zt as ApproximateTokenThresholdCompactionPolicyOptions } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
export { ApproximateTokenThresholdCompactionPolicyOptions, CompactionError, CompactionExecutor, CompactionExecutorInput, CompactionExecutorShape, CompactionOutput, CompactionPlan, CompactionPolicy, CompactionPolicyInput, CompactionPolicyShape, CompactionRunner, CompactionRunnerInput, CompactionRunnerShape, LanguageModelSummaryCompactionExecutorOptions, PromptPrefixSummaryCompactionExecutorOptions, defaultCompactionCharsPerToken, defaultCompactionMinSummarizableTokens, defaultCompactionRetainTailTokens, defaultCompactionSummaryInstructions, defaultCompactionThresholdTokens, promptPrefixSummaryCompactionExecutor };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $n as
|
|
1
|
+
import { $n as deciderMarkerDedupeKey, Gn as EDADeciderItem, Hn as EDADecider, Jn as EDADeciderView, Kn as EDADeciderOutcome, Qn as deciderIdempotencyKeyViolation, Un as EDADeciderDefinition, Wn as EDADeciderError, Xn as EDAErasedDecision, Yn as EDADecision, Zn as EDAEventDraft, ar as maxDeciderResultBytes, er as deciderNamePattern, ir as maxDeciderIdempotencyKeyLength, nr as encodeDeciderJson, qn as EDADeciderRegistry, rr as makeEDADeciderRegistry, tr as edaReservedDeciderNamePrefix } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
export { EDADecider, EDADeciderDefinition, EDADeciderError, EDADeciderItem, EDADeciderOutcome, EDADeciderRegistry, EDADeciderView, EDADecision, EDAErasedDecision, EDAEventDraft, deciderIdempotencyKeyViolation, deciderMarkerDedupeKey, deciderNamePattern, edaReservedDeciderNamePrefix, encodeDeciderJson, makeEDADeciderRegistry, maxDeciderIdempotencyKeyLength, maxDeciderResultBytes };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sn as EDAModelToolkit } from "../reduced-state-
|
|
1
|
+
import { sn as EDAModelToolkit } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as LanguageModel from "effect/ai/LanguageModel";
|
|
4
4
|
import * as Prompt from "effect/ai/Prompt";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cr as EDAProjectedPromptContext, dr as EDAPromptProjectorShape, fr as EDA_PROMPT_OPTIONS_KEY, gr as nativeCompactionSummaryMessage, hr as isEDACacheBreakpoint, lr as EDAPromptProjectionInput, mr as getNativeCompaction, pr as buildEDAPrompt, sr as EDANativeCompaction, ur as EDAPromptProjector } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
export { EDANativeCompaction, EDAProjectedPromptContext, EDAPromptProjectionInput, EDAPromptProjector, EDAPromptProjectorShape, EDA_PROMPT_OPTIONS_KEY, buildEDAPrompt, getNativeCompaction, isEDACacheBreakpoint, nativeCompactionSummaryMessage };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ct as RunSchedulingDeliveryError, St as RunSchedulingDelivery, Tn as LocalRunResolution, bt as RunScheduler, jn as RunSchedulingInput, kn as RunResolution, wn as DeferredRunResolution, xt as RunSchedulerShape } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
export { DeferredRunResolution, LocalRunResolution, type RunResolution, RunScheduler, RunSchedulerShape, RunSchedulingDelivery, RunSchedulingDeliveryError, type RunSchedulingInput };
|
|
@@ -2,8 +2,7 @@ import { g as SessionId } from "../core-BcimKMIv.js";
|
|
|
2
2
|
import { i as EDAAppEvents, o as EDASessionStore, s as EDASessionStoreError } from "../session-store-DaSHeg8Q.js";
|
|
3
3
|
import { t as ModelResolver } from "../model-resolver-O8Kn27GH.js";
|
|
4
4
|
import { r as EDAReducerRegistry } from "../reducer-registry-Bqn5B4JO.js";
|
|
5
|
-
import { $ as SessionCommandAdmissionError, At as EDASink,
|
|
6
|
-
import { t as SessionEventObserver } from "../session-event-observer-BWQUJTcN.js";
|
|
5
|
+
import { $ as SessionCommandAdmissionError, At as EDASink, Hn as EDADecider, J as EDARuntimeConfig, Kt as CompactionPolicy, Sn as SessionEventObserver, Vt as CompactionExecutor, bt as RunScheduler, q as EDARuntime, sn as EDAModelToolkit, un as EDAToolRegistryShape, ur as EDAPromptProjector } from "../reduced-state-BvNK4zug.js";
|
|
7
6
|
import { t as IdGenerator } from "../id-generator-BKGoKjt-.js";
|
|
8
7
|
import { t as EDAKeepAlive } from "../keep-alive-_zFCUvt3.js";
|
|
9
8
|
import { n as SinkCheckpointStore } from "../sink-checkpoint-store-CUvIVvlZ.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RunSchedulingWakeup } from "./run-scheduling-wakeup.js";
|
|
2
2
|
import { RunScheduler } from "./run-scheduler.js";
|
|
3
|
-
import { d as InferenceRunner, f as ToolExecutor, l as SessionState, p as LiveEventBus, u as TurnRunner } from "../session-state-
|
|
3
|
+
import { d as InferenceRunner, f as ToolExecutor, l as SessionState, p as LiveEventBus, u as TurnRunner } from "../session-state-oUTUeAuF.js";
|
|
4
4
|
import { t as RegisteredAppEvents } from "../session-admission-DC98zwtj.js";
|
|
5
5
|
import { EDASessionStore, registerAppEvents } from "./session-store.js";
|
|
6
6
|
import { a as CompactionPolicy, n as CompactionExecutor, o as CompactionRunner } from "../compaction-Dlq4wgZE.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { G as CommittedCommandTerminalEvent, J as EDARuntimeConfig, K as EDACommandTerminalEvent, X as EDARuntimeShape, Y as EDARuntimeError, Z as EDARuntimeSubmit, q as EDARuntime } from "../reduced-state-
|
|
1
|
+
import { G as CommittedCommandTerminalEvent, J as EDARuntimeConfig, K as EDACommandTerminalEvent, X as EDARuntimeShape, Y as EDARuntimeError, Z as EDARuntimeSubmit, q as EDARuntime } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
export { CommittedCommandTerminalEvent, EDACommandTerminalEvent, EDARuntime, EDARuntimeConfig, EDARuntimeError, EDARuntimeShape, EDARuntimeSubmit };
|
package/dist/services/runtime.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DurablePosition, SequenceNumber, durablePosition } from "../types/core.js";
|
|
2
2
|
import { d as NonNegativeInt, h as SystemPromptText, u as ModelSelectionPayload } from "../envelope-BSI_Xh-f.js";
|
|
3
3
|
import { w as CommandFailedEvent, x as CommandCompletedEvent, y as CommandCancelledEvent } from "../durable-Da57Rcml.js";
|
|
4
|
-
import { l as SessionState } from "../session-state-
|
|
4
|
+
import { l as SessionState } from "../session-state-oUTUeAuF.js";
|
|
5
5
|
import { annotateEdaSpan, committedBatchAttributes } from "./tracing.js";
|
|
6
6
|
import { EDASessionQuery } from "./session-query.js";
|
|
7
7
|
import * as Context from "effect/Context";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cn as SessionEventObserverShape, Sn as SessionEventObserver } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
export { SessionEventObserver, SessionEventObserverShape };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-event-observer.js","names":[],"sources":["../../src/services/session-event-observer.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\n\nimport type { PositionedEvent } from \"../types/events\";\n\n/**\n * Outbound integration point notified synchronously after EDA publishes an event.\n *\n * Hosts provide this service while composing the runtime. Implementations own\n * their failures and never expose host errors to the session runtime.\n */\nexport interface SessionEventObserverShape {\n readonly onEvent: (event: PositionedEvent) => Effect.Effect<void>;\n}\n\n/** Host-provided observer for append-driven integrations such as hibernatable WebSockets. */\nexport class SessionEventObserver extends Context.Service<\n SessionEventObserver,\n SessionEventObserverShape\n>()(\"@effect-durable-agent/SessionEventObserver\") {\n static readonly Noop = Layer.succeed(SessionEventObserver, {\n onEvent: () => Effect.void,\n });\n\n static readonly FromHandler = (\n onEvent: SessionEventObserverShape[\"onEvent\"],\n ): Layer.Layer<SessionEventObserver> => Layer.succeed(SessionEventObserver, { onEvent });\n}\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"session-event-observer.js","names":[],"sources":["../../src/services/session-event-observer.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\n\nimport type { ReducedState } from \"../domain/reduced-state\";\nimport type { PositionedEvent } from \"../types/events\";\n\n/**\n * Outbound integration point notified synchronously after EDA publishes an event.\n *\n * Hosts provide this service while composing the runtime. Implementations own\n * their failures and never expose host errors to the session runtime.\n */\nexport interface SessionEventObserverShape {\n /**\n * `state` is the session's reduced state when `event` is published. A durable batch folds\n * before it publishes, so `state.lastSeq >= event.position.seq`, with equality on the batch's\n * last event. An ephemeral event is published at the head, so `state.lastSeq` equals its seq.\n * State with `lastSeq` equal to a durable event's seq is exactly the fold through that event.\n */\n readonly onEvent: (event: PositionedEvent, state: ReducedState) => Effect.Effect<void>;\n}\n\n/** Host-provided observer for append-driven integrations such as hibernatable WebSockets. */\nexport class SessionEventObserver extends Context.Service<\n SessionEventObserver,\n SessionEventObserverShape\n>()(\"@effect-durable-agent/SessionEventObserver\") {\n static readonly Noop = Layer.succeed(SessionEventObserver, {\n onEvent: () => Effect.void,\n });\n\n static readonly FromHandler = (\n onEvent: SessionEventObserverShape[\"onEvent\"],\n ): Layer.Layer<SessionEventObserver> => Layer.succeed(SessionEventObserver, { onEvent });\n}\n"],"mappings":";;;;;AAwBA,IAAa,uBAAb,MAAa,6BAA6B,QAAQ,QAGhD,CAAC,CAAC,4CAA4C,CAAC,CAAC;CAChD,OAAgB,OAAO,MAAM,QAAQ,sBAAsB,EACzD,eAAe,OAAO,KACxB,CAAC;CAED,OAAgB,eACd,YACsC,MAAM,QAAQ,sBAAsB,EAAE,QAAQ,CAAC;AACzF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _n as EDASessionEventPage, bn as EDASessionSnapshot, vn as EDASessionQuery, yn as EDASessionQueryShape } from "../reduced-state-
|
|
1
|
+
import { _n as EDASessionEventPage, bn as EDASessionSnapshot, vn as EDASessionQuery, yn as EDASessionQueryShape } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
export { EDASessionEventPage, EDASessionQuery, EDASessionQueryShape, EDASessionSnapshot };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SequenceNumber } from "../types/core.js";
|
|
2
2
|
import { f as PositionedEvent } from "../envelope-BSI_Xh-f.js";
|
|
3
3
|
import { Xn as durableEventEnvelope } from "../durable-Da57Rcml.js";
|
|
4
|
-
import { l as SessionState, p as LiveEventBus } from "../session-state-
|
|
4
|
+
import { l as SessionState, p as LiveEventBus } from "../session-state-oUTUeAuF.js";
|
|
5
5
|
import { ReducedStateSchema } from "../domain/reduced-state-schema.js";
|
|
6
6
|
import { EDASessionStore } from "./session-store.js";
|
|
7
7
|
import { annotateEdaSpan } from "./tracing.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as SessionCommandAdmissionError, Q as EDASubmittable, at as SessionDecideError, ct as SessionForkedCommand, dt as SessionRunInput, et as SessionCommandCancelled, ft as SessionState, ht as SessionStateSnapshotData, it as SessionCommandResult, lt as SessionNoRunnableCommand, mt as SessionStateShape, nt as SessionCommandFailed, ot as SessionDrainProcessed, pt as SessionStateError, rt as SessionCommandOutcome, st as SessionDrainResult, tt as SessionCommandCompleted, ut as SessionNoRunnableReason
|
|
1
|
+
import { $ as SessionCommandAdmissionError, Q as EDASubmittable, Vn as SessionCommandAdmissionConflict, at as SessionDecideError, ct as SessionForkedCommand, dt as SessionRunInput, et as SessionCommandCancelled, ft as SessionState, ht as SessionStateSnapshotData, it as SessionCommandResult, lt as SessionNoRunnableCommand, mt as SessionStateShape, nt as SessionCommandFailed, ot as SessionDrainProcessed, pt as SessionStateError, rt as SessionCommandOutcome, st as SessionDrainResult, tt as SessionCommandCompleted, ut as SessionNoRunnableReason } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
export { EDASubmittable, SessionCommandAdmissionConflict, SessionCommandAdmissionError, SessionCommandCancelled, SessionCommandCompleted, SessionCommandFailed, SessionCommandOutcome, SessionCommandResult, SessionDecideError, SessionDrainProcessed, SessionDrainResult, SessionForkedCommand, SessionNoRunnableCommand, SessionNoRunnableReason, SessionRunInput, SessionState, SessionStateError, SessionStateShape, SessionStateSnapshotData };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as SessionForkedCommand, c as SessionRunInput, i as SessionCommandOutcome, l as SessionState, n as SessionCommandCompleted, o as SessionNoRunnableCommand, r as SessionCommandFailed, s as SessionNoRunnableReason, t as SessionCommandCancelled } from "../session-state-
|
|
1
|
+
import { a as SessionForkedCommand, c as SessionRunInput, i as SessionCommandOutcome, l as SessionState, n as SessionCommandCompleted, o as SessionNoRunnableCommand, r as SessionCommandFailed, s as SessionNoRunnableReason, t as SessionCommandCancelled } from "../session-state-oUTUeAuF.js";
|
|
2
2
|
import { n as SessionCommandAdmissionConflict } from "../session-admission-DC98zwtj.js";
|
|
3
3
|
export { SessionCommandAdmissionConflict, SessionCommandCancelled, SessionCommandCompleted, SessionCommandFailed, SessionCommandOutcome, SessionForkedCommand, SessionNoRunnableCommand, SessionNoRunnableReason, SessionRunInput, SessionState };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { At as EDASink, Dt as EDAProjectedSink, Et as EDAProjectedDurableSinkDefinition, Ft as EDASinkRawDurableBatch, It as EDASinkRegistry, Lt as EDASinkRegistryShape, Mt as EDASinkContext, Nt as EDASinkDurableBatch, Ot as EDARawDurableSinkDefinition, Pt as EDASinkInterests, Rt as EDASinkRunnerStartInput, Tt as EDAEphemeralSinkDefinition, jt as EDASinkCheckpoint, kt as EDARawSink, wt as EDADurableSinkDefinition } from "../reduced-state-
|
|
1
|
+
import { At as EDASink, Dt as EDAProjectedSink, Et as EDAProjectedDurableSinkDefinition, Ft as EDASinkRawDurableBatch, It as EDASinkRegistry, Lt as EDASinkRegistryShape, Mt as EDASinkContext, Nt as EDASinkDurableBatch, Ot as EDARawDurableSinkDefinition, Pt as EDASinkInterests, Rt as EDASinkRunnerStartInput, Tt as EDAEphemeralSinkDefinition, jt as EDASinkCheckpoint, kt as EDARawSink, wt as EDADurableSinkDefinition } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
export { EDADurableSinkDefinition, EDAEphemeralSinkDefinition, EDAProjectedDurableSinkDefinition, EDAProjectedSink, EDARawDurableSinkDefinition, EDARawSink, EDASink, EDASinkCheckpoint, EDASinkContext, EDASinkDurableBatch, EDASinkInterests, EDASinkRawDurableBatch, EDASinkRegistry, EDASinkRegistryShape, EDASinkRunnerStartInput };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { cn as EDAToolExecutionContext, dn as ToolParamsSchema, fn as ToolRecovery, gn as toolRecoveryPolicy, hn as maxToolCallAttempts, ln as EDAToolRegistry, mn as makeEDAToolkit, pn as ToolRecoveryPolicy, sn as EDAModelToolkit, un as EDAToolRegistryShape } from "../reduced-state-
|
|
1
|
+
import { cn as EDAToolExecutionContext, dn as ToolParamsSchema, fn as ToolRecovery, gn as toolRecoveryPolicy, hn as maxToolCallAttempts, ln as EDAToolRegistry, mn as makeEDAToolkit, pn as ToolRecoveryPolicy, sn as EDAModelToolkit, un as EDAToolRegistryShape } from "../reduced-state-BvNK4zug.js";
|
|
2
2
|
export { EDAModelToolkit, EDAToolExecutionContext, EDAToolRegistry, EDAToolRegistryShape, ToolParamsSchema, ToolRecovery, ToolRecoveryPolicy, makeEDAToolkit, maxToolCallAttempts, toolRecoveryPolicy };
|
|
@@ -6,7 +6,7 @@ import { ModelResolver } from "./services/model-resolver.js";
|
|
|
6
6
|
import { makeEDARunTrace } from "./types/tracing.js";
|
|
7
7
|
import { S as schemaV1, _ as UnixEpochMillis, c as FailurePayload, d as NonNegativeInt, f as PositionedEvent, g as ToolName, h as SystemPromptText, p as ProviderPartId, r as EventDedupeKey, t as DurableEventEnvelope, u as ModelSelectionPayload, y as effectDurableAgentNamespace } from "./envelope-BSI_Xh-f.js";
|
|
8
8
|
import { CancelPendingMessageCommand, PromotePendingMessageCommand, ResumePendingMessagesCommand, StopTurnCommand, SubmitMessageCommand } from "./types/commands.js";
|
|
9
|
-
import { H as DeciderAcceptedEvent, Jt as ToolCallCreatedEvent, Kn as deciderAcceptedEventType, Qn as inferenceFailedEventType, Sr as toolCallRejectedEventType, Tr as turnFailedEventType, Xn as durableEventEnvelope, Zn as inferenceCompletedEventType, _ as CommandAdmittedEvent, _n as TurnStoppedEvent, br as toolCallCreatedEventType, hn as TurnStartedEvent, pn as TurnFailedEvent, un as TurnCompletedEvent } from "./durable-Da57Rcml.js";
|
|
9
|
+
import { H as DeciderAcceptedEvent, Jt as ToolCallCreatedEvent, Kn as deciderAcceptedEventType, Qn as inferenceFailedEventType, Sr as toolCallRejectedEventType, Tr as turnFailedEventType, Xn as durableEventEnvelope, Zn as inferenceCompletedEventType, _ as CommandAdmittedEvent, _n as TurnStoppedEvent, br as toolCallCreatedEventType, er as interpretLegacyAttemptForReduction, hn as TurnStartedEvent, pn as TurnFailedEvent, un as TurnCompletedEvent } from "./durable-Da57Rcml.js";
|
|
10
10
|
import { n as assertNeverError, t as assertNever } from "./assert-never-CoyUpoRB.js";
|
|
11
11
|
import { activeTurnIdentityForCommand, classifyRecoverableWork, decodeReducedStateCheckpoint, encodeReducedStateCheckpoint, foldReducedState, frameworkReducedStateReducerName, initialReducedState, reducedStateCheckpointEventSeqs } from "./domain/reduced-state.js";
|
|
12
12
|
import { ContextProjection, emptyContextProjection } from "./domain/context-projection.js";
|
|
@@ -206,6 +206,7 @@ const decideRunContinuation = (input) => {
|
|
|
206
206
|
steerings
|
|
207
207
|
};
|
|
208
208
|
};
|
|
209
|
+
/** Steering messages pending for a run, in effective order. */
|
|
209
210
|
const pendingSteerings = (state, runId) => {
|
|
210
211
|
const current = state.commandQueues.pendingSteers.filter((message) => message.targetRunId === void 0 || message.targetRunId === runId);
|
|
211
212
|
const currentIds = new Set(current.map((message) => message.messageId));
|
|
@@ -220,8 +221,70 @@ const countRejectedTurns = (state, runId) => {
|
|
|
220
221
|
};
|
|
221
222
|
//#endregion
|
|
222
223
|
//#region src/domain/recovery-policy.ts
|
|
223
|
-
/**
|
|
224
|
-
|
|
224
|
+
/**
|
|
225
|
+
* One step of folding `runId`'s last turn from the session's events in log order. Events are read
|
|
226
|
+
* as `ReducedState` reads them: framework events only, retained attempt events as inferences, and
|
|
227
|
+
* the latest inference terminal wins.
|
|
228
|
+
*/
|
|
229
|
+
const stepRunLastTurn = (runId, last, entry) => {
|
|
230
|
+
if (entry.namespace !== "effect-durable-agent") return last;
|
|
231
|
+
const event = interpretLegacyAttemptForReduction(entry);
|
|
232
|
+
if (event.type === "TurnStarted") return event.payload.runId === runId ? {
|
|
233
|
+
runId,
|
|
234
|
+
turnId: event.payload.turnId,
|
|
235
|
+
toolDecisions: 0
|
|
236
|
+
} : last;
|
|
237
|
+
const inLastTurn = (payload) => last !== void 0 && payload.runId === runId && payload.turnId === last.turnId;
|
|
238
|
+
switch (event.type) {
|
|
239
|
+
case "InferenceStarted": return last !== void 0 && inLastTurn(event.payload) ? {
|
|
240
|
+
...last,
|
|
241
|
+
inference: {
|
|
242
|
+
inferenceId: event.payload.inferenceId,
|
|
243
|
+
completed: false
|
|
244
|
+
}
|
|
245
|
+
} : last;
|
|
246
|
+
case "InferenceFailed": return last?.inference !== void 0 && inLastTurn(event.payload) && event.payload.inferenceId === last.inference.inferenceId ? {
|
|
247
|
+
...last,
|
|
248
|
+
inference: {
|
|
249
|
+
inferenceId: last.inference.inferenceId,
|
|
250
|
+
completed: false
|
|
251
|
+
}
|
|
252
|
+
} : last;
|
|
253
|
+
case "InferenceCompleted": {
|
|
254
|
+
if (last?.inference === void 0 || !inLastTurn(event.payload) || event.payload.inferenceId !== last.inference.inferenceId) return last;
|
|
255
|
+
const usage = event.payload.usage;
|
|
256
|
+
return {
|
|
257
|
+
...last,
|
|
258
|
+
inference: {
|
|
259
|
+
inferenceId: last.inference.inferenceId,
|
|
260
|
+
completed: true,
|
|
261
|
+
...usage === void 0 ? {} : { usage }
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
case "ToolCallCreated":
|
|
266
|
+
case "ToolCallRejected": return last !== void 0 && inLastTurn(event.payload) ? {
|
|
267
|
+
...last,
|
|
268
|
+
toolDecisions: last.toolDecisions + 1
|
|
269
|
+
} : last;
|
|
270
|
+
case "TurnCompleted": return last !== void 0 && inLastTurn(event.payload) ? {
|
|
271
|
+
...last,
|
|
272
|
+
terminal: "Completed"
|
|
273
|
+
} : last;
|
|
274
|
+
case "TurnFailed":
|
|
275
|
+
case "TurnStopped": return last !== void 0 && inLastTurn(event.payload) ? {
|
|
276
|
+
...last,
|
|
277
|
+
terminal: "Failed"
|
|
278
|
+
} : last;
|
|
279
|
+
default: return last;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Pure startup-recovery policy over one canonical durable snapshot. `lastTurn`, folded from the
|
|
284
|
+
* log for the plan's continuation run, lets the plan complete a run that already answered instead
|
|
285
|
+
* of replacing it; without it the run is continued.
|
|
286
|
+
*/
|
|
287
|
+
const planSessionRecovery = (state, lastTurn) => {
|
|
225
288
|
const recoverable = classifyRecoverableWork(state);
|
|
226
289
|
const pendingCommandsById = new Set(state.commandQueues.pendingCommands.map((command) => command.commandId));
|
|
227
290
|
const resumeOwnedMessageIds = new Set([...Array.from(state.commands.values()), ...state.commandQueues.pendingCommands].flatMap((command) => ("terminal" in command ? command.terminal === void 0 : true) && command.command?._tag === "ResumePendingMessages" ? command.command.messageIds : []));
|
|
@@ -234,32 +297,50 @@ const planSessionRecovery = (state) => {
|
|
|
234
297
|
return (tag === "SubmitMessage" || tag === "ResumePendingMessages") && recoverable.activeRuns.some((run) => !stoppedRunIds.has(run.runId) && run.commandIds.includes(command.commandId));
|
|
235
298
|
});
|
|
236
299
|
const continuationRun = recoverable.activeRuns.find((run) => continuationCommand !== void 0 && !stoppedRunIds.has(run.runId) && run.commandIds.includes(continuationCommand.commandId));
|
|
300
|
+
const completion = continuationCommand === void 0 || continuationRun === void 0 ? void 0 : planAnsweredRunCompletion(state, recoverable, continuationCommand, continuationRun, lastTurn);
|
|
237
301
|
const sourceMessageIds = continuationCommand === void 0 ? [] : runSchedulingInputMessageIds(state, {
|
|
238
302
|
_tag: "Command",
|
|
239
303
|
commandId: continuationCommand.commandId
|
|
240
304
|
});
|
|
241
305
|
const eligibleSteerIds = continuationRun === void 0 ? [] : state.commandQueues.pendingSteers.filter((message) => message.targetRunId === void 0 || message.targetRunId === continuationRun.runId || continuationRun.commandIds.some((commandId) => state.runs.get(message.targetRunId)?.commandIds.includes(commandId) === true)).map((message) => message.messageId);
|
|
242
|
-
const continuationInputMessageIds = Array.from(/* @__PURE__ */ new Set([...sourceMessageIds, ...eligibleSteerIds]));
|
|
306
|
+
const continuationInputMessageIds = completion === void 0 ? Array.from(/* @__PURE__ */ new Set([...sourceMessageIds, ...eligibleSteerIds])) : [];
|
|
243
307
|
const continuationInputIds = new Set(continuationInputMessageIds);
|
|
244
308
|
const messageIdsToResume = state.commandQueues.pendingSteers.filter((message) => !pausedMessageIds.has(message.messageId) && !continuationInputIds.has(message.messageId) && !(state.runSchedulingRequest?.work._tag === "Recovery" && state.runSchedulingRequest.work.inputMessageIds.includes(message.messageId)) && !pendingCommandsById.has(message.commandId) && !resumeOwnedMessageIds.has(message.messageId)).map((message) => message.messageId);
|
|
245
309
|
return {
|
|
246
|
-
activeCommands: recoverable.activeCommands,
|
|
247
|
-
activeRuns: recoverable.activeRuns,
|
|
248
|
-
activeTurns: recoverable.activeTurns,
|
|
310
|
+
activeCommands: recoverable.activeCommands.filter((command) => command.commandId !== completion?.command.commandId),
|
|
311
|
+
activeRuns: recoverable.activeRuns.filter((run) => run.runId !== completion?.run.runId),
|
|
312
|
+
activeTurns: recoverable.activeTurns.filter((turn) => turn.turnId !== completion?.openTurn?.turnId),
|
|
249
313
|
activeInferences: recoverable.activeInferences,
|
|
250
314
|
openToolCalls: recoverable.openToolCalls,
|
|
251
315
|
pendingStopRequests: recoverable.pendingStopRequests,
|
|
252
316
|
openCompactions: recoverable.openCompactions,
|
|
253
317
|
messageIdsToPause,
|
|
254
318
|
messageIdsToResume,
|
|
255
|
-
...
|
|
319
|
+
...completion === void 0 ? {} : { completion },
|
|
320
|
+
...continuationCommand === void 0 || continuationRun === void 0 || completion !== void 0 ? {} : { continuation: {
|
|
256
321
|
command: continuationCommand,
|
|
257
322
|
run: continuationRun,
|
|
258
323
|
inputMessageIds: continuationInputMessageIds
|
|
259
324
|
} }
|
|
260
325
|
};
|
|
261
326
|
};
|
|
262
|
-
|
|
327
|
+
/**
|
|
328
|
+
* `decideRunContinuation`'s `CompleteRun` over the run's durable last turn: its inference
|
|
329
|
+
* completed, it decided no tool calls (no feedback to answer), and no steering is pending.
|
|
330
|
+
*/
|
|
331
|
+
const planAnsweredRunCompletion = (state, recoverable, command, run, lastTurn) => {
|
|
332
|
+
if (lastTurn?.runId !== run.runId || lastTurn.terminal === "Failed" || lastTurn.inference?.completed !== true || lastTurn.toolDecisions > 0 || pendingSteerings(state, run.runId).length > 0 || recoverable.activeInferences.some((inference) => inference.runId === run.runId) || recoverable.openToolCalls.some((tool) => tool.decision?.runId === run.runId)) return;
|
|
333
|
+
const usage = lastTurn.inference.usage;
|
|
334
|
+
return {
|
|
335
|
+
command,
|
|
336
|
+
run,
|
|
337
|
+
...lastTurn.terminal === void 0 ? { openTurn: {
|
|
338
|
+
turnId: lastTurn.turnId,
|
|
339
|
+
...usage === void 0 ? {} : { usage }
|
|
340
|
+
} } : {}
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
const isSessionRecoveryPlanEmpty = (plan) => plan.activeCommands.length === 0 && plan.activeRuns.length === 0 && plan.activeTurns.length === 0 && plan.activeInferences.length === 0 && plan.openToolCalls.length === 0 && plan.pendingStopRequests.length === 0 && plan.openCompactions.length === 0 && plan.messageIdsToPause.length === 0 && plan.messageIdsToResume.length === 0 && plan.continuation === void 0 && plan.completion === void 0;
|
|
263
344
|
//#endregion
|
|
264
345
|
//#region src/domain/run-terminal-policy.ts
|
|
265
346
|
/** Normal live-run failure policy. This is not startup recovery. */
|
|
@@ -285,9 +366,9 @@ var LiveEventBus = class LiveEventBus extends Context.Service()("@effect-durable
|
|
|
285
366
|
static Noop = LiveEventBus.Live.pipe(Layer.provide(SessionEventObserver.Noop));
|
|
286
367
|
};
|
|
287
368
|
const makeLiveBus = (pubsub, activeTurnReplay, observer) => ({
|
|
288
|
-
publish: (event) => Effect.gen(function* () {
|
|
369
|
+
publish: (event, state) => Effect.gen(function* () {
|
|
289
370
|
yield* updateActiveTurnReplay(activeTurnReplay, event);
|
|
290
|
-
yield* observer.onEvent(event);
|
|
371
|
+
yield* observer.onEvent(event, state);
|
|
291
372
|
return yield* PubSub.publish(pubsub, event);
|
|
292
373
|
}),
|
|
293
374
|
subscribeQueue: () => PubSub.subscribe(pubsub),
|
|
@@ -1741,7 +1822,7 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
1741
1822
|
for (const entry of fresh) yield* liveBus.publish(PositionedEvent.make({
|
|
1742
1823
|
position: entry.position,
|
|
1743
1824
|
event: durableEventEnvelope(entry.event)
|
|
1744
|
-
}));
|
|
1825
|
+
}), nextReduced);
|
|
1745
1826
|
return { head: nextReduced.lastSeq };
|
|
1746
1827
|
});
|
|
1747
1828
|
const snapshot = () => Ref.get(state).pipe(Effect.map((state) => state.reduced));
|
|
@@ -1798,7 +1879,7 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
1798
1879
|
lastSubSeq: nextSubSeq
|
|
1799
1880
|
}
|
|
1800
1881
|
});
|
|
1801
|
-
yield* liveBus.publish(positioned);
|
|
1882
|
+
yield* liveBus.publish(positioned, current.reduced);
|
|
1802
1883
|
yield* sinkRegistry.publishEphemeralToSinks(positioned);
|
|
1803
1884
|
return positioned;
|
|
1804
1885
|
}));
|
|
@@ -2699,7 +2780,8 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
2699
2780
|
}).pipe(Effect.catchTag("ToolExecutionEventNotCreated", (error) => Effect.die(error)));
|
|
2700
2781
|
});
|
|
2701
2782
|
const recoverSession = Effect.fnUntraced(function* (reduced, reason, input) {
|
|
2702
|
-
const
|
|
2783
|
+
const candidate = planSessionRecovery(reduced).continuation?.run;
|
|
2784
|
+
const plan = candidate === void 0 ? planSessionRecovery(reduced) : planSessionRecovery(reduced, yield* store.eventsAfter(SequenceNumber.make(candidate.startedSeq - 1)).pipe(Stream.runFold(() => void 0, (last, entry) => stepRunLastTurn(candidate.runId, last, entry.event))));
|
|
2703
2785
|
input = {
|
|
2704
2786
|
...input,
|
|
2705
2787
|
modelSelection: plan.continuation?.run.modelSelection ?? input.modelSelection
|
|
@@ -2714,7 +2796,8 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
2714
2796
|
"eda.recovery.pending_stop_requests": plan.pendingStopRequests.length,
|
|
2715
2797
|
"eda.recovery.open_compactions": plan.openCompactions.length,
|
|
2716
2798
|
"eda.recovery.messages_to_pause": plan.messageIdsToPause.length,
|
|
2717
|
-
"eda.recovery.messages_to_resume": plan.messageIdsToResume.length
|
|
2799
|
+
"eda.recovery.messages_to_resume": plan.messageIdsToResume.length,
|
|
2800
|
+
"eda.recovery.completed_answered_run": plan.completion !== void 0
|
|
2718
2801
|
});
|
|
2719
2802
|
const recoveryEvents = [];
|
|
2720
2803
|
for (const tool of plan.openToolCalls) {
|
|
@@ -2781,6 +2864,16 @@ const makeLiveSessionState = Effect.gen(function* () {
|
|
|
2781
2864
|
compactionId: compaction.compactionId,
|
|
2782
2865
|
error: FailurePayload.make({ message: "runtime restarted before compaction completed" })
|
|
2783
2866
|
}) : yield* events.compactionCompleted({ compactionId: compaction.compactionId }));
|
|
2867
|
+
if (plan.completion !== void 0) {
|
|
2868
|
+
const { command, run, openTurn } = plan.completion;
|
|
2869
|
+
if (openTurn !== void 0) recoveryEvents.push(yield* events.turnCompleted({
|
|
2870
|
+
runId: run.runId,
|
|
2871
|
+
turnId: openTurn.turnId,
|
|
2872
|
+
...openTurn.usage === void 0 ? {} : { usage: openTurn.usage }
|
|
2873
|
+
}));
|
|
2874
|
+
recoveryEvents.push(yield* events.runCompleted({ runId: run.runId }));
|
|
2875
|
+
recoveryEvents.push(yield* events.commandCompleted({ commandId: command.commandId }));
|
|
2876
|
+
}
|
|
2784
2877
|
if (plan.messageIdsToResume.length > 0) recoveryEvents.push(yield* events.commandAdmitted({ command: new ResumePendingMessagesCommand({
|
|
2785
2878
|
commandId: yield* ids.makeCommandId(),
|
|
2786
2879
|
messageIds: plan.messageIdsToResume
|
|
@@ -3512,4 +3605,4 @@ const isSessionNoRunnableCommand = (result) => "_tag" in result && result._tag =
|
|
|
3512
3605
|
//#endregion
|
|
3513
3606
|
export { SessionForkedCommand as a, SessionRunInput as c, InferenceRunner as d, ToolExecutor as f, SessionCommandOutcome as i, SessionState as l, SessionCommandCompleted as n, SessionNoRunnableCommand as o, LiveEventBus as p, SessionCommandFailed as r, SessionNoRunnableReason as s, SessionCommandCancelled as t, TurnRunner as u };
|
|
3514
3607
|
|
|
3515
|
-
//# sourceMappingURL=session-state-
|
|
3608
|
+
//# sourceMappingURL=session-state-oUTUeAuF.js.map
|