@statelyai/agent 2.0.0-alpha.19 → 2.0.0-alpha.20

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/ai-sdk.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_decision = require("./decision-t26zsnSR.cjs");
2
+ const require_decision = require("./decision-DhsKLYAI.cjs");
3
3
  require("./validate.cjs");
4
4
  let ai = require("ai");
5
5
  //#region src/ai-sdk/mappers.ts
package/dist/ai-sdk.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { H as isStandardSchema, _ as getAgentOutputMode, i as renderDecisionAttempts, p as buildEnvelopeSchema } from "./decision-DsIkEuHz.mjs";
1
+ import { H as isStandardSchema, _ as getAgentOutputMode, i as renderDecisionAttempts, p as buildEnvelopeSchema } from "./decision-BfhSgCc6.mjs";
2
2
  import { NoObjectGeneratedError, Output, generateText, stepCountIs, streamText, tool } from "ai";
3
3
  //#region src/ai-sdk/mappers.ts
4
4
  /**
@@ -167,7 +167,7 @@ function toolMessage(content) {
167
167
  * ```
168
168
  */
169
169
  function getStateMeta(snapshot) {
170
- const nodes = snapshot._nodes;
170
+ const nodes = snapshot.nodes;
171
171
  const depthById = new Map(nodes?.map((node) => [node.id, node.path.length]));
172
172
  const depth = (id) => depthById.get(id) ?? id.split(".").length;
173
173
  const entries = Object.entries(snapshot.getMeta()).filter((entry) => entry[1] != null).sort(([a], [b]) => depth(a) - depth(b) || (a < b ? -1 : a > b ? 1 : 0));
@@ -168,7 +168,7 @@ function toolMessage(content) {
168
168
  * ```
169
169
  */
170
170
  function getStateMeta(snapshot) {
171
- const nodes = snapshot._nodes;
171
+ const nodes = snapshot.nodes;
172
172
  const depthById = new Map(nodes?.map((node) => [node.id, node.path.length]));
173
173
  const depth = (id) => depthById.get(id) ?? id.split(".").length;
174
174
  const entries = Object.entries(snapshot.getMeta()).filter((entry) => entry[1] != null).sort(([a], [b]) => depth(a) - depth(b) || (a < b ? -1 : a > b ? 1 : 0));
package/dist/index.cjs CHANGED
@@ -1,10 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_errors = require("./errors-DUBBzRLP.cjs");
3
- const require_setup_agent = require("./setup-agent-BFA4VKpN.cjs");
4
- const require_decision = require("./decision-t26zsnSR.cjs");
3
+ const require_setup_agent = require("./setup-agent-gISRLxRe.cjs");
4
+ const require_decision = require("./decision-DhsKLYAI.cjs");
5
5
  const require_event_log_store = require("./event-log-store-a_TKy1gk.cjs");
6
6
  require("./validate.cjs");
7
7
  let xstate = require("xstate");
8
+ let xstate_durable = require("xstate/durable");
8
9
  //#region src/internal/state-request-pass.ts
9
10
  async function runTextPhase(stateRequest, baseMessages, deps) {
10
11
  const { model, system } = stateRequest;
@@ -286,7 +287,7 @@ function serializeTraceEvent(event, options = {}) {
286
287
  return out;
287
288
  }
288
289
  function snapshotNodes(snapshot) {
289
- return (snapshot._nodes ?? []).map((raw) => {
290
+ return (snapshot.nodes ?? []).map((raw) => {
290
291
  const node = raw;
291
292
  return {
292
293
  id: node.id ?? "",
@@ -1161,6 +1162,7 @@ function createAgentSession(machine, options, lifecycle) {
1161
1162
  const aligned = Object.assign(Object.create(Object.getPrototypeOf(effectiveSnapshot)), effectiveSnapshot);
1162
1163
  if (machineOwnVersion === void 0) delete aligned.version;
1163
1164
  else aligned.version = machineOwnVersion;
1165
+ delete aligned.machine;
1164
1166
  effectiveSnapshot = aligned;
1165
1167
  }
1166
1168
  const priorMessages = require_decision.getAgentMessages(effectiveSnapshot);
@@ -2829,6 +2831,196 @@ async function runSeam(machine, options) {
2829
2831
  };
2830
2832
  }
2831
2833
  //#endregion
2834
+ //#region src/durable.ts
2835
+ /**
2836
+ * The durable host runner: {@link runDurableAgent} drives an executor-bound
2837
+ * agent machine on xstate's `createDurable` execution (`xstate/durable`),
2838
+ * with the agent event log as the journal.
2839
+ *
2840
+ * Where {@link replay} + `getAgentEffects` hand a host an effect list to run
2841
+ * itself, `runDurableAgent` owns the whole loop on the durable runtime:
2842
+ * invoked actors execute live through xstate's own runtime, every EXTERNAL
2843
+ * event (invoke completions included) is appended to the log, and a resume
2844
+ * folds the log back through pure transitions — an invoke whose completion is
2845
+ * already journaled is never re-started, so recorded model calls are never
2846
+ * re-executed. Crash recovery re-runs only the work that was still in flight.
2847
+ *
2848
+ * @module
2849
+ */
2850
+ const DONE_ACTOR_EVENT_TYPE = "xstate.done.actor";
2851
+ const ERROR_ACTOR_EVENT_TYPE = "xstate.error.actor";
2852
+ function completionActorId(event) {
2853
+ if (event.type !== DONE_ACTOR_EVENT_TYPE && event.type !== ERROR_ACTOR_EVENT_TYPE) return;
2854
+ const actorId = event.actorId;
2855
+ return typeof actorId === "string" ? actorId : void 0;
2856
+ }
2857
+ function createMailbox() {
2858
+ const queue = [];
2859
+ const waiters = [];
2860
+ return {
2861
+ push(event) {
2862
+ const waiter = waiters.shift();
2863
+ if (waiter) waiter(event);
2864
+ else queue.push(event);
2865
+ },
2866
+ take() {
2867
+ const next = queue.shift();
2868
+ if (next !== void 0) return Promise.resolve(next);
2869
+ return new Promise((resolve) => waiters.push(resolve));
2870
+ },
2871
+ size: () => queue.length
2872
+ };
2873
+ }
2874
+ /**
2875
+ * Runs an agent machine as a durable execution: journal in, journal out.
2876
+ *
2877
+ * A fresh call starts from `input` and appends a reserved init entry; a
2878
+ * resume call folds `entries` through pure transitions first — invokes whose
2879
+ * completions are journaled are suppressed (their recorded results replay
2880
+ * instead of re-executing), while work that was in flight at the crash
2881
+ * re-executes live. After the journal, an optional `options.event` is
2882
+ * delivered. The call settles:
2883
+ *
2884
+ * - `done` when the machine reaches a final state, with `output`;
2885
+ * - `idle` when the frontier needs an external event the host has not
2886
+ * supplied (no live work pending, or `isIdle` says the pending work is a
2887
+ * human wait). Persist `entries` and call again with them later.
2888
+ *
2889
+ * ```ts
2890
+ * const first = await runDurableAgent(machine, { input, executors });
2891
+ * // ... persist first.entries; later, in a new process:
2892
+ * const next = await runDurableAgent(machine, {
2893
+ * entries: first.entries,
2894
+ * event: { type: "APPROVE" },
2895
+ * executors,
2896
+ * });
2897
+ * ```
2898
+ *
2899
+ * @experimental Built on xstate's experimental `xstate/durable` entrypoint.
2900
+ */
2901
+ async function runDurableAgent(machine, options = {}) {
2902
+ const bound = options.executors ? provideExecutors(machine, options.executors, {
2903
+ actors: options.actors,
2904
+ onChunk: options.onChunk,
2905
+ onTrace: options.onTrace
2906
+ }) : options.actors ? machine.provide({ actors: options.actors }) : machine;
2907
+ const machineId = machine.config.id ?? machine.id ?? "(machine)";
2908
+ const machineVersion = options.machineVersion ?? require_decision.resolveMachineVersion(machine);
2909
+ const priorEntries = options.entries ?? [];
2910
+ if (priorEntries.length > 0) require_setup_agent.validateReplayEntries(priorEntries, {
2911
+ machineId,
2912
+ machineVersion
2913
+ }, "Durable journal entries");
2914
+ const hasInit = priorEntries[0]?.event.type === require_setup_agent.AGENT_INIT_EVENT_TYPE;
2915
+ const input = hasInit ? priorEntries[0].event.input : options.input;
2916
+ const journal = priorEntries.slice(hasInit ? 1 : 0).map((entry) => entry.event);
2917
+ const journaledCompletions = /* @__PURE__ */ new Map();
2918
+ for (const event of journal) {
2919
+ const actorId = completionActorId(event);
2920
+ if (actorId !== void 0) journaledCompletions.set(actorId, (journaledCompletions.get(actorId) ?? 0) + 1);
2921
+ }
2922
+ const mailbox = createMailbox();
2923
+ const rootAddress = machineId;
2924
+ const suppressedChildren = /* @__PURE__ */ new WeakSet();
2925
+ const startsSeen = /* @__PURE__ */ new Map();
2926
+ const liveInFlight = /* @__PURE__ */ new Set();
2927
+ const findChildRef = (effect) => {
2928
+ const raw = effect;
2929
+ const candidates = [raw.actor, ...Array.isArray(raw.args) ? raw.args : []];
2930
+ for (const candidate of candidates) {
2931
+ const ref = candidate;
2932
+ if (ref && typeof ref.sessionId === "string" && typeof ref.id === "string") return ref;
2933
+ }
2934
+ };
2935
+ let replaying = journal.length > 0;
2936
+ const execution = (0, xstate_durable.createDurable)(bound, {
2937
+ sendEvent(source, target, event) {
2938
+ if (target.address === rootAddress) {
2939
+ mailbox.push(event);
2940
+ return;
2941
+ }
2942
+ (0, xstate.deliverEvent)(source, target, event);
2943
+ },
2944
+ runtime(_metadata, effect) {
2945
+ const type = effect.type;
2946
+ if (type === "@xstate.spawn" || type === "@xstate.start") {
2947
+ const child = findChildRef(effect);
2948
+ if (!child) return {};
2949
+ if (type === "@xstate.spawn") {
2950
+ const seen = (startsSeen.get(child.id) ?? 0) + 1;
2951
+ startsSeen.set(child.id, seen);
2952
+ if (seen <= (journaledCompletions.get(child.id) ?? 0)) suppressedChildren.add(child);
2953
+ else liveInFlight.add(child.id);
2954
+ }
2955
+ if (suppressedChildren.has(child)) return {
2956
+ spawnActor() {},
2957
+ startActor() {}
2958
+ };
2959
+ }
2960
+ return {};
2961
+ },
2962
+ executeAction(action) {
2963
+ if (replaying) return;
2964
+ action.exec?.();
2965
+ },
2966
+ waitForEvent() {
2967
+ return mailbox.take();
2968
+ }
2969
+ });
2970
+ const entries = [...priorEntries];
2971
+ const entryOptions = {
2972
+ machineVersion,
2973
+ verification: options.verification ?? false
2974
+ };
2975
+ const appendEntry = (event) => {
2976
+ const entry = require_setup_agent.createReplayEntry(machine, entries, event, entryOptions);
2977
+ entries.push(entry);
2978
+ options.onEntry?.(entry);
2979
+ };
2980
+ if (!hasInit) {
2981
+ const entry = require_setup_agent.initEntry(machine, input, entryOptions);
2982
+ entries.push(entry);
2983
+ options.onEntry?.(entry);
2984
+ }
2985
+ const sessions = /* @__PURE__ */ new Map();
2986
+ let journalIndex = 0;
2987
+ let liveEventConsumed = false;
2988
+ let [snapshot, effects] = execution.initialTransition(input);
2989
+ for (;;) {
2990
+ const captured = await execution.executeEffects(effects);
2991
+ for (const rootEvent of captured) mailbox.push(rootEvent.event);
2992
+ const machineSnapshot = snapshot;
2993
+ if (machineSnapshot.status === "done") return {
2994
+ status: "done",
2995
+ output: machineSnapshot.output,
2996
+ snapshot,
2997
+ entries
2998
+ };
2999
+ if (machineSnapshot.status === "error") throw machineSnapshot.error;
3000
+ let event;
3001
+ let fromJournal = false;
3002
+ if (journalIndex < journal.length) {
3003
+ event = require_setup_agent.rebindActorSession(journal[journalIndex], machineSnapshot, sessions);
3004
+ journalIndex++;
3005
+ fromJournal = true;
3006
+ replaying = journalIndex < journal.length;
3007
+ } else if (mailbox.size() > 0) event = await mailbox.take();
3008
+ else if (liveInFlight.size > 0 && !(options.isIdle?.(snapshot) ?? false)) event = await mailbox.take();
3009
+ else if (!liveEventConsumed && options.event !== void 0) {
3010
+ event = options.event;
3011
+ liveEventConsumed = true;
3012
+ } else return {
3013
+ status: "idle",
3014
+ snapshot,
3015
+ entries
3016
+ };
3017
+ const completedId = completionActorId(event);
3018
+ if (completedId !== void 0) liveInFlight.delete(completedId);
3019
+ if (!fromJournal) appendEntry(event);
3020
+ [snapshot, effects] = execution.transition(snapshot, event);
3021
+ }
3022
+ }
3023
+ //#endregion
2832
3024
  exports.AGENT_EVENT_SCHEMA_VERSION = require_event_log_store.AGENT_EVENT_SCHEMA_VERSION;
2833
3025
  exports.AGENT_INIT_EVENT_TYPE = require_setup_agent.AGENT_INIT_EVENT_TYPE;
2834
3026
  exports.AGENT_TRACE_SCHEMA_VERSION = AGENT_TRACE_SCHEMA_VERSION;
@@ -2890,6 +3082,7 @@ exports.renderDecisionAttempts = require_decision.renderDecisionAttempts;
2890
3082
  exports.replay = require_setup_agent.replay;
2891
3083
  exports.resolveDecision = require_decision.resolveDecision;
2892
3084
  exports.runAgent = runAgent;
3085
+ exports.runDurableAgent = runDurableAgent;
2893
3086
  exports.runSeam = runSeam;
2894
3087
  exports.serializeTraceEvent = serializeTraceEvent;
2895
3088
  Object.defineProperty(exports, "setupAgent", {
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@ import { t as AgentError } from "./errors-BQRk9eiZ.cjs";
3
3
  import { A as AgentDecisionExecutor, B as AgentEventToolNameResolver, C as buildEnvelopeSchema, D as parseModelRef, E as getCallUsage, F as DecisionLogicConfig, G as parseAgentEvent, H as AgentRequestSource, I as ResolveDecisionOptions, L as renderDecisionAttempts, M as AgentDecisionInput, N as AgentDecisionRequest, O as parseOutput, P as DecisionAttempt, R as resolveDecision, S as bindRequestExecutor, T as getAgentOutputMode, U as AgentSchemas, V as AgentRequestOptions, W as getAcceptedEvents, _ as StructuredOutputEnvelope, a as AgentOutputMode, b as TextLogicExecuteArgs, c as AgentRequestExecutorResult, d as AgentTextRequest, f as AgentUsage, g as BuiltinAgentActors, h as AiSdkShapedTextResult, i as AgentModelRef, j as AgentDecisionExhaustedError, k as parseStructuredEnvelope, l as AgentRequestExecutors, m as AiSdkShapedStreamResult, n as AgentExecutorTextRequest, o as AgentRequestExecutor, p as AgentUserInput, r as AgentModelMap, s as AgentRequestExecutorInfo, t as AgentCallUsage, u as AgentRequestMode, v as TextLogic, w as createTextLogic, x as TextLogicExecutor, y as TextLogicConfig, z as AgentEventDescriptor } from "./text-logic-Cavva1W6.cjs";
4
4
  import { a as AgentLogVerification, c as assertAgentLogEntry, d as assertEventLogStoreConformance, i as AgentLogEntry, l as assertJsonSerializable, n as AgentEventLogConflictError, o as JsonValue, r as AgentEventLogStore, s as NonSerializableAgentEventError, t as AGENT_EVENT_SCHEMA_VERSION, u as createInMemoryEventLogStore } from "./event-log-store-Bz7HDBkE.cjs";
5
5
  import { A as AgentRequest, B as AgentReplayMachineMismatchError, C as getSnapshotNodes, D as serializeTraceEvent, E as runAgent, F as AgentEffect, G as ReplayResult, H as CreateReplayEntryOptions, I as AgentEffectDiff, J as getAgentEffects, K as createReplayEntry, L as AgentEventLogDiff, M as executeAgentRequest, N as AGENT_INIT_EVENT_TYPE, O as traceTransitions, P as AGENT_USAGE_EVENT_TYPE, R as AgentLogPatchOperation, S as generateResult, T as inspectTransitions, U as GetAgentEffectsOptions, V as AgentUsageEvent, W as ReplayOptions, X as replay, Y as initEntry, _ as PendingUserInput, a as AgentInputFrom, b as RunAgentResult, c as AgentRunMeta, d as AgentTraceEvent, f as AgentUserInputExecutor, g as JsonSerializableTraceEvent, h as InspectedActorRef, i as AgentIllegalResumeEventError, j as AgentStepRequest, k as AgentStateRequest, l as AgentSnapshotNode, m as GetSnapshotRequestsOptions, n as AgentActorSession, o as AgentMaxModelCallsExceededError, p as GenerateResult, q as diffEventLogs, r as AgentIdleError, s as AgentMessageInfo, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentSnapshotVersionMismatchError, v as RunAgentErrorCause, w as getSnapshotRequests, x as createAgentActor, y as RunAgentOptions, z as AgentReplayDivergenceError } from "./run-agent--4bbms-D.cjs";
6
- import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValue } from "xstate";
6
+ import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, OutputFrom, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValue } from "xstate";
7
7
 
8
8
  //#region src/messages.d.ts
9
9
  /**
@@ -1309,4 +1309,76 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
1309
1309
  */
1310
1310
  declare function runSeam<TMachine extends AnyStateMachine>(machine: TMachine, options: RunSeamOptions<TMachine>): Promise<RunSeamResult<TMachine>>;
1311
1311
  //#endregion
1312
- export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentActorSession, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentEffect, type AgentEffectDiff, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogDiff, type AgentEventLogStore, type AgentEventToolNameResolver, type AgentExecutorTextRequest, AgentIdleError, AgentIllegalResumeEventError, type AgentInputFrom, type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentLogEntry, type AgentLogPatchOperation, type AgentLogVerification, AgentMaxModelCallsExceededError, type AgentMessage, type AgentMessageInfo, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal, AgentReplayDivergenceError, AgentReplayMachineMismatchError, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRun, type AgentRunMeta, type AgentSchemaPack, type AgentSchemas, type AgentSnapshotNode, type AgentSnapshotStore, AgentSnapshotVersionMismatchError, type AgentStateRequest, type AgentStepRequest, type AgentTextRequest, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentUserInput, type AgentUserInputExecutor, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AiSdkShapedStreamResult, type AiSdkShapedTextResult, type AllowedEvents, type AssistantMessage, type CanReachResult, type ChosenEvent, type CreateReplayEntryOptions, type DecisionAttempt, type DecisionLogicConfig, type ExplorePathsOptions, type FilePart, type FromConfigOptions, type FromConfigResult, type GenerateResult, type GetAgentEffectsOptions, type GetSnapshotRequestsOptions, type ImagePart, type InferInput, type InferOutput, type InspectedActorRef, type JsonSerializableTraceEvent, type JsonValue, type LintAgentMachineOptions, type MatchTrajectoryOptions, NonSerializableAgentEventError, type PendingUserInput, type ProvideExecutorsOptions, type ReplayOptions, type ReplayResult, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type RunSeamOptions, type RunSeamResult, type SchemaCompiler, type ScriptedDecisionEntry, type ScriptedDecisionValue, type ScriptedExecutors, type ScriptedExecutorsScript, type ScriptedTextEntry, type ScriptedUserInputEntry, type SeamRef, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type StandardSchemaV1, type StructuredOutputEnvelope, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, type UserMessage, type WithAgentUsageEvent, appendMessages, assertAgentLogEntry, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getAgentSchemas, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getSnapshotNodes, getSnapshotRequests, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage };
1312
+ //#region src/durable.d.ts
1313
+ /** Options for {@link runDurableAgent}. */
1314
+ interface RunDurableAgentOptions<TMachine extends AnyStateMachine> extends Pick<ProvideExecutorsOptions<TMachine>, "actors" | "onChunk" | "onTrace"> {
1315
+ /** Machine input for a FRESH run (ignored when `entries` has an init entry). */
1316
+ input?: InputFrom<TMachine>;
1317
+ /**
1318
+ * The journal to resume from — the `entries` a previous
1319
+ * {@link runDurableAgent} result returned (or any replay-compatible
1320
+ * {@link AgentLogEntry} log with a reserved `@agent.init` first entry).
1321
+ */
1322
+ entries?: readonly AgentLogEntry[];
1323
+ /** One external event to feed after the journal is folded (a user reply, a timer). */
1324
+ event?: EventFromLogic<TMachine>;
1325
+ /** Host executors, bound with {@link provideExecutors} semantics. */
1326
+ executors?: AgentRequestExecutors;
1327
+ /** Called with each entry as it is appended, for incremental persistence. */
1328
+ onEntry?: (entry: AgentLogEntry) => void;
1329
+ /**
1330
+ * Settle `idle` when this returns true for the current snapshot even though
1331
+ * children are still pending — for machines whose wait states keep a
1332
+ * never-resolving invoke in flight (e.g. an unbound `agent.userInput`).
1333
+ */
1334
+ isIdle?: (snapshot: SnapshotFrom<TMachine>) => boolean;
1335
+ /** Explicit machine version for entry stamping; defaults to the structural hash. */
1336
+ machineVersion?: string;
1337
+ /**
1338
+ * Record replay-verification hashes on appended entries. Off by default:
1339
+ * hashing replays the whole prefix per entry, which is quadratic in log
1340
+ * length.
1341
+ */
1342
+ verification?: boolean;
1343
+ }
1344
+ /** The settled result of a {@link runDurableAgent} call. */
1345
+ type DurableAgentResult<TMachine extends AnyStateMachine> = {
1346
+ /** The machine reached a final state. */status: "done";
1347
+ output: OutputFrom<TMachine>;
1348
+ snapshot: SnapshotFrom<TMachine>; /** The complete journal; replaying it reproduces this run. */
1349
+ entries: AgentLogEntry[];
1350
+ } | {
1351
+ /** The machine is waiting for an external event. Persist `entries`; resume with them plus `event`. */status: "idle";
1352
+ snapshot: SnapshotFrom<TMachine>;
1353
+ entries: AgentLogEntry[];
1354
+ };
1355
+ /**
1356
+ * Runs an agent machine as a durable execution: journal in, journal out.
1357
+ *
1358
+ * A fresh call starts from `input` and appends a reserved init entry; a
1359
+ * resume call folds `entries` through pure transitions first — invokes whose
1360
+ * completions are journaled are suppressed (their recorded results replay
1361
+ * instead of re-executing), while work that was in flight at the crash
1362
+ * re-executes live. After the journal, an optional `options.event` is
1363
+ * delivered. The call settles:
1364
+ *
1365
+ * - `done` when the machine reaches a final state, with `output`;
1366
+ * - `idle` when the frontier needs an external event the host has not
1367
+ * supplied (no live work pending, or `isIdle` says the pending work is a
1368
+ * human wait). Persist `entries` and call again with them later.
1369
+ *
1370
+ * ```ts
1371
+ * const first = await runDurableAgent(machine, { input, executors });
1372
+ * // ... persist first.entries; later, in a new process:
1373
+ * const next = await runDurableAgent(machine, {
1374
+ * entries: first.entries,
1375
+ * event: { type: "APPROVE" },
1376
+ * executors,
1377
+ * });
1378
+ * ```
1379
+ *
1380
+ * @experimental Built on xstate's experimental `xstate/durable` entrypoint.
1381
+ */
1382
+ declare function runDurableAgent<TMachine extends AnyStateMachine>(machine: TMachine, options?: RunDurableAgentOptions<TMachine>): Promise<DurableAgentResult<TMachine>>;
1383
+ //#endregion
1384
+ export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentActorSession, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentEffect, type AgentEffectDiff, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogDiff, type AgentEventLogStore, type AgentEventToolNameResolver, type AgentExecutorTextRequest, AgentIdleError, AgentIllegalResumeEventError, type AgentInputFrom, type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentLogEntry, type AgentLogPatchOperation, type AgentLogVerification, AgentMaxModelCallsExceededError, type AgentMessage, type AgentMessageInfo, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal, AgentReplayDivergenceError, AgentReplayMachineMismatchError, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRun, type AgentRunMeta, type AgentSchemaPack, type AgentSchemas, type AgentSnapshotNode, type AgentSnapshotStore, AgentSnapshotVersionMismatchError, type AgentStateRequest, type AgentStepRequest, type AgentTextRequest, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentUserInput, type AgentUserInputExecutor, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AiSdkShapedStreamResult, type AiSdkShapedTextResult, type AllowedEvents, type AssistantMessage, type CanReachResult, type ChosenEvent, type CreateReplayEntryOptions, type DecisionAttempt, type DecisionLogicConfig, type DurableAgentResult, type ExplorePathsOptions, type FilePart, type FromConfigOptions, type FromConfigResult, type GenerateResult, type GetAgentEffectsOptions, type GetSnapshotRequestsOptions, type ImagePart, type InferInput, type InferOutput, type InspectedActorRef, type JsonSerializableTraceEvent, type JsonValue, type LintAgentMachineOptions, type MatchTrajectoryOptions, NonSerializableAgentEventError, type PendingUserInput, type ProvideExecutorsOptions, type ReplayOptions, type ReplayResult, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type RunDurableAgentOptions, type RunSeamOptions, type RunSeamResult, type SchemaCompiler, type ScriptedDecisionEntry, type ScriptedDecisionValue, type ScriptedExecutors, type ScriptedExecutorsScript, type ScriptedTextEntry, type ScriptedUserInputEntry, type SeamRef, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type StandardSchemaV1, type StructuredOutputEnvelope, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, type UserMessage, type WithAgentUsageEvent, appendMessages, assertAgentLogEntry, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getAgentSchemas, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getSnapshotNodes, getSnapshotRequests, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runDurableAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage };
package/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@ import { t as AgentError } from "./errors-C9rxnWbX.mjs";
3
3
  import { A as AgentDecisionExecutor, B as AgentEventToolNameResolver, C as buildEnvelopeSchema, D as parseModelRef, E as getCallUsage, F as DecisionLogicConfig, G as parseAgentEvent, H as AgentRequestSource, I as ResolveDecisionOptions, L as renderDecisionAttempts, M as AgentDecisionInput, N as AgentDecisionRequest, O as parseOutput, P as DecisionAttempt, R as resolveDecision, S as bindRequestExecutor, T as getAgentOutputMode, U as AgentSchemas, V as AgentRequestOptions, W as getAcceptedEvents, _ as StructuredOutputEnvelope, a as AgentOutputMode, b as TextLogicExecuteArgs, c as AgentRequestExecutorResult, d as AgentTextRequest, f as AgentUsage, g as BuiltinAgentActors, h as AiSdkShapedTextResult, i as AgentModelRef, j as AgentDecisionExhaustedError, k as parseStructuredEnvelope, l as AgentRequestExecutors, m as AiSdkShapedStreamResult, n as AgentExecutorTextRequest, o as AgentRequestExecutor, p as AgentUserInput, r as AgentModelMap, s as AgentRequestExecutorInfo, t as AgentCallUsage, u as AgentRequestMode, v as TextLogic, w as createTextLogic, x as TextLogicExecutor, y as TextLogicConfig, z as AgentEventDescriptor } from "./text-logic-Er5KkTX6.mjs";
4
4
  import { a as AgentLogVerification, c as assertAgentLogEntry, d as assertEventLogStoreConformance, i as AgentLogEntry, l as assertJsonSerializable, n as AgentEventLogConflictError, o as JsonValue, r as AgentEventLogStore, s as NonSerializableAgentEventError, t as AGENT_EVENT_SCHEMA_VERSION, u as createInMemoryEventLogStore } from "./event-log-store-hrA1vqtN.mjs";
5
5
  import { A as AgentRequest, B as AgentReplayMachineMismatchError, C as getSnapshotNodes, D as serializeTraceEvent, E as runAgent, F as AgentEffect, G as ReplayResult, H as CreateReplayEntryOptions, I as AgentEffectDiff, J as getAgentEffects, K as createReplayEntry, L as AgentEventLogDiff, M as executeAgentRequest, N as AGENT_INIT_EVENT_TYPE, O as traceTransitions, P as AGENT_USAGE_EVENT_TYPE, R as AgentLogPatchOperation, S as generateResult, T as inspectTransitions, U as GetAgentEffectsOptions, V as AgentUsageEvent, W as ReplayOptions, X as replay, Y as initEntry, _ as PendingUserInput, a as AgentInputFrom, b as RunAgentResult, c as AgentRunMeta, d as AgentTraceEvent, f as AgentUserInputExecutor, g as JsonSerializableTraceEvent, h as InspectedActorRef, i as AgentIllegalResumeEventError, j as AgentStepRequest, k as AgentStateRequest, l as AgentSnapshotNode, m as GetSnapshotRequestsOptions, n as AgentActorSession, o as AgentMaxModelCallsExceededError, p as GenerateResult, q as diffEventLogs, r as AgentIdleError, s as AgentMessageInfo, t as AGENT_TRACE_SCHEMA_VERSION, u as AgentSnapshotVersionMismatchError, v as RunAgentErrorCause, w as getSnapshotRequests, x as createAgentActor, y as RunAgentOptions, z as AgentReplayDivergenceError } from "./run-agent-CwmzAZwj.mjs";
6
- import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValue } from "xstate";
6
+ import { AnyActorLogic, AnyMachineSnapshot, AnySetupConfig, AnyStateMachine, AsyncActorLogic, EventFromLogic, EventObject, InputFrom, MachineContext, MetaObject, NonReducibleUnknown, OutputFrom, SetupReturnFromConfig, SetupStateSchema, SnapshotFrom, StateValue } from "xstate";
7
7
 
8
8
  //#region src/messages.d.ts
9
9
  /**
@@ -1309,4 +1309,76 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
1309
1309
  */
1310
1310
  declare function runSeam<TMachine extends AnyStateMachine>(machine: TMachine, options: RunSeamOptions<TMachine>): Promise<RunSeamResult<TMachine>>;
1311
1311
  //#endregion
1312
- export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentActorSession, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentEffect, type AgentEffectDiff, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogDiff, type AgentEventLogStore, type AgentEventToolNameResolver, type AgentExecutorTextRequest, AgentIdleError, AgentIllegalResumeEventError, type AgentInputFrom, type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentLogEntry, type AgentLogPatchOperation, type AgentLogVerification, AgentMaxModelCallsExceededError, type AgentMessage, type AgentMessageInfo, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal, AgentReplayDivergenceError, AgentReplayMachineMismatchError, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRun, type AgentRunMeta, type AgentSchemaPack, type AgentSchemas, type AgentSnapshotNode, type AgentSnapshotStore, AgentSnapshotVersionMismatchError, type AgentStateRequest, type AgentStepRequest, type AgentTextRequest, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentUserInput, type AgentUserInputExecutor, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AiSdkShapedStreamResult, type AiSdkShapedTextResult, type AllowedEvents, type AssistantMessage, type CanReachResult, type ChosenEvent, type CreateReplayEntryOptions, type DecisionAttempt, type DecisionLogicConfig, type ExplorePathsOptions, type FilePart, type FromConfigOptions, type FromConfigResult, type GenerateResult, type GetAgentEffectsOptions, type GetSnapshotRequestsOptions, type ImagePart, type InferInput, type InferOutput, type InspectedActorRef, type JsonSerializableTraceEvent, type JsonValue, type LintAgentMachineOptions, type MatchTrajectoryOptions, NonSerializableAgentEventError, type PendingUserInput, type ProvideExecutorsOptions, type ReplayOptions, type ReplayResult, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type RunSeamOptions, type RunSeamResult, type SchemaCompiler, type ScriptedDecisionEntry, type ScriptedDecisionValue, type ScriptedExecutors, type ScriptedExecutorsScript, type ScriptedTextEntry, type ScriptedUserInputEntry, type SeamRef, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type StandardSchemaV1, type StructuredOutputEnvelope, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, type UserMessage, type WithAgentUsageEvent, appendMessages, assertAgentLogEntry, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getAgentSchemas, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getSnapshotNodes, getSnapshotRequests, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage };
1312
+ //#region src/durable.d.ts
1313
+ /** Options for {@link runDurableAgent}. */
1314
+ interface RunDurableAgentOptions<TMachine extends AnyStateMachine> extends Pick<ProvideExecutorsOptions<TMachine>, "actors" | "onChunk" | "onTrace"> {
1315
+ /** Machine input for a FRESH run (ignored when `entries` has an init entry). */
1316
+ input?: InputFrom<TMachine>;
1317
+ /**
1318
+ * The journal to resume from — the `entries` a previous
1319
+ * {@link runDurableAgent} result returned (or any replay-compatible
1320
+ * {@link AgentLogEntry} log with a reserved `@agent.init` first entry).
1321
+ */
1322
+ entries?: readonly AgentLogEntry[];
1323
+ /** One external event to feed after the journal is folded (a user reply, a timer). */
1324
+ event?: EventFromLogic<TMachine>;
1325
+ /** Host executors, bound with {@link provideExecutors} semantics. */
1326
+ executors?: AgentRequestExecutors;
1327
+ /** Called with each entry as it is appended, for incremental persistence. */
1328
+ onEntry?: (entry: AgentLogEntry) => void;
1329
+ /**
1330
+ * Settle `idle` when this returns true for the current snapshot even though
1331
+ * children are still pending — for machines whose wait states keep a
1332
+ * never-resolving invoke in flight (e.g. an unbound `agent.userInput`).
1333
+ */
1334
+ isIdle?: (snapshot: SnapshotFrom<TMachine>) => boolean;
1335
+ /** Explicit machine version for entry stamping; defaults to the structural hash. */
1336
+ machineVersion?: string;
1337
+ /**
1338
+ * Record replay-verification hashes on appended entries. Off by default:
1339
+ * hashing replays the whole prefix per entry, which is quadratic in log
1340
+ * length.
1341
+ */
1342
+ verification?: boolean;
1343
+ }
1344
+ /** The settled result of a {@link runDurableAgent} call. */
1345
+ type DurableAgentResult<TMachine extends AnyStateMachine> = {
1346
+ /** The machine reached a final state. */status: "done";
1347
+ output: OutputFrom<TMachine>;
1348
+ snapshot: SnapshotFrom<TMachine>; /** The complete journal; replaying it reproduces this run. */
1349
+ entries: AgentLogEntry[];
1350
+ } | {
1351
+ /** The machine is waiting for an external event. Persist `entries`; resume with them plus `event`. */status: "idle";
1352
+ snapshot: SnapshotFrom<TMachine>;
1353
+ entries: AgentLogEntry[];
1354
+ };
1355
+ /**
1356
+ * Runs an agent machine as a durable execution: journal in, journal out.
1357
+ *
1358
+ * A fresh call starts from `input` and appends a reserved init entry; a
1359
+ * resume call folds `entries` through pure transitions first — invokes whose
1360
+ * completions are journaled are suppressed (their recorded results replay
1361
+ * instead of re-executing), while work that was in flight at the crash
1362
+ * re-executes live. After the journal, an optional `options.event` is
1363
+ * delivered. The call settles:
1364
+ *
1365
+ * - `done` when the machine reaches a final state, with `output`;
1366
+ * - `idle` when the frontier needs an external event the host has not
1367
+ * supplied (no live work pending, or `isIdle` says the pending work is a
1368
+ * human wait). Persist `entries` and call again with them later.
1369
+ *
1370
+ * ```ts
1371
+ * const first = await runDurableAgent(machine, { input, executors });
1372
+ * // ... persist first.entries; later, in a new process:
1373
+ * const next = await runDurableAgent(machine, {
1374
+ * entries: first.entries,
1375
+ * event: { type: "APPROVE" },
1376
+ * executors,
1377
+ * });
1378
+ * ```
1379
+ *
1380
+ * @experimental Built on xstate's experimental `xstate/durable` entrypoint.
1381
+ */
1382
+ declare function runDurableAgent<TMachine extends AnyStateMachine>(machine: TMachine, options?: RunDurableAgentOptions<TMachine>): Promise<DurableAgentResult<TMachine>>;
1383
+ //#endregion
1384
+ export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, type AgentActorSession, type AgentCallUsage, type AgentDecisionExecutor, AgentDecisionExhaustedError, type AgentDecisionInput, type AgentDecisionRequest, type AgentEffect, type AgentEffectDiff, AgentError, type AgentEventDescriptor, AgentEventLogConflictError, type AgentEventLogDiff, type AgentEventLogStore, type AgentEventToolNameResolver, type AgentExecutorTextRequest, AgentIdleError, AgentIllegalResumeEventError, type AgentInputFrom, type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentLogEntry, type AgentLogPatchOperation, type AgentLogVerification, AgentMaxModelCallsExceededError, type AgentMessage, type AgentMessageInfo, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal, AgentReplayDivergenceError, AgentReplayMachineMismatchError, type AgentRequest, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestOptions, type AgentRequestSource, type AgentRun, type AgentRunMeta, type AgentSchemaPack, type AgentSchemas, type AgentSnapshotNode, type AgentSnapshotStore, AgentSnapshotVersionMismatchError, type AgentStateRequest, type AgentStepRequest, type AgentTextRequest, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentTools, type AgentTraceEvent, type AgentUsage, type AgentUsageEvent, type AgentUsageEventPayload, type AgentUserInput, type AgentUserInputExecutor, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AiSdkShapedStreamResult, type AiSdkShapedTextResult, type AllowedEvents, type AssistantMessage, type CanReachResult, type ChosenEvent, type CreateReplayEntryOptions, type DecisionAttempt, type DecisionLogicConfig, type DurableAgentResult, type ExplorePathsOptions, type FilePart, type FromConfigOptions, type FromConfigResult, type GenerateResult, type GetAgentEffectsOptions, type GetSnapshotRequestsOptions, type ImagePart, type InferInput, type InferOutput, type InspectedActorRef, type JsonSerializableTraceEvent, type JsonValue, type LintAgentMachineOptions, type MatchTrajectoryOptions, NonSerializableAgentEventError, type PendingUserInput, type ProvideExecutorsOptions, type ReplayOptions, type ReplayResult, type ResolveDecisionOptions, type RunAgentErrorCause, type RunAgentOptions, type RunAgentResult, type RunDurableAgentOptions, type RunSeamOptions, type RunSeamResult, type SchemaCompiler, type ScriptedDecisionEntry, type ScriptedDecisionValue, type ScriptedExecutors, type ScriptedExecutorsScript, type ScriptedTextEntry, type ScriptedUserInputEntry, type SeamRef, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type StandardSchemaV1, type StructuredOutputEnvelope, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultPart, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, type UserMessage, type WithAgentUsageEvent, appendMessages, assertAgentLogEntry, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getAgentSchemas, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getSnapshotNodes, getSnapshotRequests, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runDurableAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage };
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  import { t as AgentError } from "./errors-CeSXQx0v.mjs";
2
- import { _ as resolveAgentStep, a as AGENT_USAGE_EVENT_TYPE, b as messagesSchema, c as createReplayEntry, d as initEntry, f as replay, g as initialAgentStep, h as getInvokeEffectMetadata, i as AGENT_INIT_EVENT_TYPE, l as diffEventLogs, m as executeAgentRequest, n as getAgentSchemas, o as AgentReplayDivergenceError, p as validateReplayEntries, r as setupAgent, s as AgentReplayMachineMismatchError, t as createAgentSchemas, u as getAgentEffects, v as transitionAgentStep, y as appendMessages } from "./setup-agent-CPFPN06s.mjs";
3
- import { A as isUnboundPlaceholder, B as getMachineStructuralHash, C as parseStructuredEnvelope, D as getMachineIdlePredicate, E as executorBoundLogics, G as toolMessage, H as isStandardSchema, I as findNonSerializableContextPaths, K as userMessage, L as getAgentMessages, O as getMachineStaticTransitionTargets, P as assistantMessage, R as getJsonSchema, S as parseOutput, U as resolveMachineVersion, V as getStateMeta, W as systemMessage, _ as getAgentOutputMode, a as resolveDecision, b as normalizeGeneratorResult, c as AGENT_USAGE_TOKEN_FIELDS, f as bindRequestExecutor, h as createTextLogic, i as renderDecisionAttempts, k as getRegisteredAgentExecutionOptions, o as getAcceptedEvents, p as buildEnvelopeSchema, q as validateSchemaSync, r as isDecisionLogic, s as parseAgentEvent, t as AgentDecisionExhaustedError, u as INTERPRET_SOURCE, v as getCallUsage, x as parseModelRef, y as isTextLogic, z as getJsonSchemaSync } from "./decision-DsIkEuHz.mjs";
2
+ import { _ as initialAgentStep, a as AGENT_USAGE_EVENT_TYPE, b as appendMessages, c as createReplayEntry, d as initEntry, f as rebindActorSession, g as getInvokeEffectMetadata, h as executeAgentRequest, i as AGENT_INIT_EVENT_TYPE, l as diffEventLogs, m as validateReplayEntries, n as getAgentSchemas, o as AgentReplayDivergenceError, p as replay, r as setupAgent, s as AgentReplayMachineMismatchError, t as createAgentSchemas, u as getAgentEffects, v as resolveAgentStep, x as messagesSchema, y as transitionAgentStep } from "./setup-agent-BOcSpsIq.mjs";
3
+ import { A as isUnboundPlaceholder, B as getMachineStructuralHash, C as parseStructuredEnvelope, D as getMachineIdlePredicate, E as executorBoundLogics, G as toolMessage, H as isStandardSchema, I as findNonSerializableContextPaths, K as userMessage, L as getAgentMessages, O as getMachineStaticTransitionTargets, P as assistantMessage, R as getJsonSchema, S as parseOutput, U as resolveMachineVersion, V as getStateMeta, W as systemMessage, _ as getAgentOutputMode, a as resolveDecision, b as normalizeGeneratorResult, c as AGENT_USAGE_TOKEN_FIELDS, f as bindRequestExecutor, h as createTextLogic, i as renderDecisionAttempts, k as getRegisteredAgentExecutionOptions, o as getAcceptedEvents, p as buildEnvelopeSchema, q as validateSchemaSync, r as isDecisionLogic, s as parseAgentEvent, t as AgentDecisionExhaustedError, u as INTERPRET_SOURCE, v as getCallUsage, x as parseModelRef, y as isTextLogic, z as getJsonSchemaSync } from "./decision-BfhSgCc6.mjs";
4
4
  import { a as assertJsonSerializable, i as assertAgentLogEntry, n as AgentEventLogConflictError, o as createInMemoryEventLogStore, r as NonSerializableAgentEventError, s as assertEventLogStoreConformance, t as AGENT_EVENT_SCHEMA_VERSION } from "./event-log-store-DmIDosD6.mjs";
5
- import { createActor, createAsyncLogic, getNextTransitions, isMachineSnapshot } from "xstate";
5
+ import { createActor, createAsyncLogic, deliverEvent, getNextTransitions, isMachineSnapshot } from "xstate";
6
+ import { createDurable } from "xstate/durable";
6
7
  //#region src/internal/state-request-pass.ts
7
8
  async function runTextPhase(stateRequest, baseMessages, deps) {
8
9
  const { model, system } = stateRequest;
@@ -284,7 +285,7 @@ function serializeTraceEvent(event, options = {}) {
284
285
  return out;
285
286
  }
286
287
  function snapshotNodes(snapshot) {
287
- return (snapshot._nodes ?? []).map((raw) => {
288
+ return (snapshot.nodes ?? []).map((raw) => {
288
289
  const node = raw;
289
290
  return {
290
291
  id: node.id ?? "",
@@ -1159,6 +1160,7 @@ function createAgentSession(machine, options, lifecycle) {
1159
1160
  const aligned = Object.assign(Object.create(Object.getPrototypeOf(effectiveSnapshot)), effectiveSnapshot);
1160
1161
  if (machineOwnVersion === void 0) delete aligned.version;
1161
1162
  else aligned.version = machineOwnVersion;
1163
+ delete aligned.machine;
1162
1164
  effectiveSnapshot = aligned;
1163
1165
  }
1164
1166
  const priorMessages = getAgentMessages(effectiveSnapshot);
@@ -2827,4 +2829,194 @@ async function runSeam(machine, options) {
2827
2829
  };
2828
2830
  }
2829
2831
  //#endregion
2830
- export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, AgentDecisionExhaustedError, AgentError, AgentEventLogConflictError, AgentIdleError, AgentIllegalResumeEventError, AgentLintError, AgentMaxModelCallsExceededError, AgentReplayDivergenceError, AgentReplayMachineMismatchError, AgentSnapshotVersionMismatchError, NonSerializableAgentEventError, appendMessages, assertAgentLogEntry, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getAgentSchemas, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getSnapshotNodes, getSnapshotRequests, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage };
2832
+ //#region src/durable.ts
2833
+ /**
2834
+ * The durable host runner: {@link runDurableAgent} drives an executor-bound
2835
+ * agent machine on xstate's `createDurable` execution (`xstate/durable`),
2836
+ * with the agent event log as the journal.
2837
+ *
2838
+ * Where {@link replay} + `getAgentEffects` hand a host an effect list to run
2839
+ * itself, `runDurableAgent` owns the whole loop on the durable runtime:
2840
+ * invoked actors execute live through xstate's own runtime, every EXTERNAL
2841
+ * event (invoke completions included) is appended to the log, and a resume
2842
+ * folds the log back through pure transitions — an invoke whose completion is
2843
+ * already journaled is never re-started, so recorded model calls are never
2844
+ * re-executed. Crash recovery re-runs only the work that was still in flight.
2845
+ *
2846
+ * @module
2847
+ */
2848
+ const DONE_ACTOR_EVENT_TYPE = "xstate.done.actor";
2849
+ const ERROR_ACTOR_EVENT_TYPE = "xstate.error.actor";
2850
+ function completionActorId(event) {
2851
+ if (event.type !== DONE_ACTOR_EVENT_TYPE && event.type !== ERROR_ACTOR_EVENT_TYPE) return;
2852
+ const actorId = event.actorId;
2853
+ return typeof actorId === "string" ? actorId : void 0;
2854
+ }
2855
+ function createMailbox() {
2856
+ const queue = [];
2857
+ const waiters = [];
2858
+ return {
2859
+ push(event) {
2860
+ const waiter = waiters.shift();
2861
+ if (waiter) waiter(event);
2862
+ else queue.push(event);
2863
+ },
2864
+ take() {
2865
+ const next = queue.shift();
2866
+ if (next !== void 0) return Promise.resolve(next);
2867
+ return new Promise((resolve) => waiters.push(resolve));
2868
+ },
2869
+ size: () => queue.length
2870
+ };
2871
+ }
2872
+ /**
2873
+ * Runs an agent machine as a durable execution: journal in, journal out.
2874
+ *
2875
+ * A fresh call starts from `input` and appends a reserved init entry; a
2876
+ * resume call folds `entries` through pure transitions first — invokes whose
2877
+ * completions are journaled are suppressed (their recorded results replay
2878
+ * instead of re-executing), while work that was in flight at the crash
2879
+ * re-executes live. After the journal, an optional `options.event` is
2880
+ * delivered. The call settles:
2881
+ *
2882
+ * - `done` when the machine reaches a final state, with `output`;
2883
+ * - `idle` when the frontier needs an external event the host has not
2884
+ * supplied (no live work pending, or `isIdle` says the pending work is a
2885
+ * human wait). Persist `entries` and call again with them later.
2886
+ *
2887
+ * ```ts
2888
+ * const first = await runDurableAgent(machine, { input, executors });
2889
+ * // ... persist first.entries; later, in a new process:
2890
+ * const next = await runDurableAgent(machine, {
2891
+ * entries: first.entries,
2892
+ * event: { type: "APPROVE" },
2893
+ * executors,
2894
+ * });
2895
+ * ```
2896
+ *
2897
+ * @experimental Built on xstate's experimental `xstate/durable` entrypoint.
2898
+ */
2899
+ async function runDurableAgent(machine, options = {}) {
2900
+ const bound = options.executors ? provideExecutors(machine, options.executors, {
2901
+ actors: options.actors,
2902
+ onChunk: options.onChunk,
2903
+ onTrace: options.onTrace
2904
+ }) : options.actors ? machine.provide({ actors: options.actors }) : machine;
2905
+ const machineId = machine.config.id ?? machine.id ?? "(machine)";
2906
+ const machineVersion = options.machineVersion ?? resolveMachineVersion(machine);
2907
+ const priorEntries = options.entries ?? [];
2908
+ if (priorEntries.length > 0) validateReplayEntries(priorEntries, {
2909
+ machineId,
2910
+ machineVersion
2911
+ }, "Durable journal entries");
2912
+ const hasInit = priorEntries[0]?.event.type === AGENT_INIT_EVENT_TYPE;
2913
+ const input = hasInit ? priorEntries[0].event.input : options.input;
2914
+ const journal = priorEntries.slice(hasInit ? 1 : 0).map((entry) => entry.event);
2915
+ const journaledCompletions = /* @__PURE__ */ new Map();
2916
+ for (const event of journal) {
2917
+ const actorId = completionActorId(event);
2918
+ if (actorId !== void 0) journaledCompletions.set(actorId, (journaledCompletions.get(actorId) ?? 0) + 1);
2919
+ }
2920
+ const mailbox = createMailbox();
2921
+ const rootAddress = machineId;
2922
+ const suppressedChildren = /* @__PURE__ */ new WeakSet();
2923
+ const startsSeen = /* @__PURE__ */ new Map();
2924
+ const liveInFlight = /* @__PURE__ */ new Set();
2925
+ const findChildRef = (effect) => {
2926
+ const raw = effect;
2927
+ const candidates = [raw.actor, ...Array.isArray(raw.args) ? raw.args : []];
2928
+ for (const candidate of candidates) {
2929
+ const ref = candidate;
2930
+ if (ref && typeof ref.sessionId === "string" && typeof ref.id === "string") return ref;
2931
+ }
2932
+ };
2933
+ let replaying = journal.length > 0;
2934
+ const execution = createDurable(bound, {
2935
+ sendEvent(source, target, event) {
2936
+ if (target.address === rootAddress) {
2937
+ mailbox.push(event);
2938
+ return;
2939
+ }
2940
+ deliverEvent(source, target, event);
2941
+ },
2942
+ runtime(_metadata, effect) {
2943
+ const type = effect.type;
2944
+ if (type === "@xstate.spawn" || type === "@xstate.start") {
2945
+ const child = findChildRef(effect);
2946
+ if (!child) return {};
2947
+ if (type === "@xstate.spawn") {
2948
+ const seen = (startsSeen.get(child.id) ?? 0) + 1;
2949
+ startsSeen.set(child.id, seen);
2950
+ if (seen <= (journaledCompletions.get(child.id) ?? 0)) suppressedChildren.add(child);
2951
+ else liveInFlight.add(child.id);
2952
+ }
2953
+ if (suppressedChildren.has(child)) return {
2954
+ spawnActor() {},
2955
+ startActor() {}
2956
+ };
2957
+ }
2958
+ return {};
2959
+ },
2960
+ executeAction(action) {
2961
+ if (replaying) return;
2962
+ action.exec?.();
2963
+ },
2964
+ waitForEvent() {
2965
+ return mailbox.take();
2966
+ }
2967
+ });
2968
+ const entries = [...priorEntries];
2969
+ const entryOptions = {
2970
+ machineVersion,
2971
+ verification: options.verification ?? false
2972
+ };
2973
+ const appendEntry = (event) => {
2974
+ const entry = createReplayEntry(machine, entries, event, entryOptions);
2975
+ entries.push(entry);
2976
+ options.onEntry?.(entry);
2977
+ };
2978
+ if (!hasInit) {
2979
+ const entry = initEntry(machine, input, entryOptions);
2980
+ entries.push(entry);
2981
+ options.onEntry?.(entry);
2982
+ }
2983
+ const sessions = /* @__PURE__ */ new Map();
2984
+ let journalIndex = 0;
2985
+ let liveEventConsumed = false;
2986
+ let [snapshot, effects] = execution.initialTransition(input);
2987
+ for (;;) {
2988
+ const captured = await execution.executeEffects(effects);
2989
+ for (const rootEvent of captured) mailbox.push(rootEvent.event);
2990
+ const machineSnapshot = snapshot;
2991
+ if (machineSnapshot.status === "done") return {
2992
+ status: "done",
2993
+ output: machineSnapshot.output,
2994
+ snapshot,
2995
+ entries
2996
+ };
2997
+ if (machineSnapshot.status === "error") throw machineSnapshot.error;
2998
+ let event;
2999
+ let fromJournal = false;
3000
+ if (journalIndex < journal.length) {
3001
+ event = rebindActorSession(journal[journalIndex], machineSnapshot, sessions);
3002
+ journalIndex++;
3003
+ fromJournal = true;
3004
+ replaying = journalIndex < journal.length;
3005
+ } else if (mailbox.size() > 0) event = await mailbox.take();
3006
+ else if (liveInFlight.size > 0 && !(options.isIdle?.(snapshot) ?? false)) event = await mailbox.take();
3007
+ else if (!liveEventConsumed && options.event !== void 0) {
3008
+ event = options.event;
3009
+ liveEventConsumed = true;
3010
+ } else return {
3011
+ status: "idle",
3012
+ snapshot,
3013
+ entries
3014
+ };
3015
+ const completedId = completionActorId(event);
3016
+ if (completedId !== void 0) liveInFlight.delete(completedId);
3017
+ if (!fromJournal) appendEntry(event);
3018
+ [snapshot, effects] = execution.transition(snapshot, event);
3019
+ }
3020
+ }
3021
+ //#endregion
3022
+ export { AGENT_EVENT_SCHEMA_VERSION, AGENT_INIT_EVENT_TYPE, AGENT_TRACE_SCHEMA_VERSION, AGENT_USAGE_EVENT_TYPE, AgentDecisionExhaustedError, AgentError, AgentEventLogConflictError, AgentIdleError, AgentIllegalResumeEventError, AgentLintError, AgentMaxModelCallsExceededError, AgentReplayDivergenceError, AgentReplayMachineMismatchError, AgentSnapshotVersionMismatchError, NonSerializableAgentEventError, appendMessages, assertAgentLogEntry, assertEventLogStoreConformance, assertJsonSerializable, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentActor, createAgentRun, createAgentSchemas, createInMemoryEventLogStore, createReplayEntry, createScriptedExecutors, createTextLogic, diffEventLogs, executeAgentRequest, explorePaths, generateResult, getAcceptedEvents, getAgentEffects, getAgentMessages, getAgentOutputMode, getAgentSchemas, getCallUsage, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getSnapshotNodes, getSnapshotRequests, getStateMeta, initEntry, inspectTransitions, isStandardSchema, lintAgentMachine, matchesTrajectory, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, provideExecutors, renderDecisionAttempts, replay, resolveDecision, runAgent, runDurableAgent, runSeam, serializeTraceEvent, setupAgent, simulateAgent, systemMessage, toolMessage, traceTransitions, userMessage };
package/dist/machines.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_setup_agent = require("./setup-agent-BFA4VKpN.cjs");
2
+ const require_setup_agent = require("./setup-agent-gISRLxRe.cjs");
3
3
  //#region src/machines/internal.ts
4
4
  /** The builtin inline text request every preset lowers a request entry to. */
5
5
  const GENERATE_TEXT_SRC = "agent.generateText";
package/dist/machines.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { r as setupAgent } from "./setup-agent-CPFPN06s.mjs";
1
+ import { r as setupAgent } from "./setup-agent-BOcSpsIq.mjs";
2
2
  //#region src/machines/internal.ts
3
3
  /** The builtin inline text request every preset lowers a request entry to. */
4
4
  const GENERATE_TEXT_SRC = "agent.generateText";
@@ -1,5 +1,5 @@
1
1
  import { t as AgentError } from "./errors-CeSXQx0v.mjs";
2
- import { F as djb2Hex, M as machineStaticTransitionTargets, N as missingActor, T as agentExecutionOptions, U as resolveMachineVersion, d as USER_INPUT_ACTOR, g as executeAgentTextRequest, h as createTextLogic, j as machineIdlePredicates, k as getRegisteredAgentExecutionOptions, l as DECIDE_ACTOR, m as builtinTextActors, n as createDecideActor, o as getAcceptedEvents, q as validateSchemaSync, r as isDecisionLogic, w as userInputActor, y as isTextLogic } from "./decision-DsIkEuHz.mjs";
2
+ import { F as djb2Hex, M as machineStaticTransitionTargets, N as missingActor, T as agentExecutionOptions, U as resolveMachineVersion, d as USER_INPUT_ACTOR, g as executeAgentTextRequest, h as createTextLogic, j as machineIdlePredicates, k as getRegisteredAgentExecutionOptions, l as DECIDE_ACTOR, m as builtinTextActors, n as createDecideActor, o as getAcceptedEvents, q as validateSchemaSync, r as isDecisionLogic, w as userInputActor, y as isTextLogic } from "./decision-BfhSgCc6.mjs";
3
3
  import { a as assertJsonSerializable, i as assertAgentLogEntry } from "./event-log-store-DmIDosD6.mjs";
4
4
  import { createMachineFromConfig, initialTransition, setup, transition } from "xstate";
5
5
  //#region src/messages.ts
@@ -373,6 +373,13 @@ function toEvents(history) {
373
373
  return candidate && typeof candidate === "object" && "event" in candidate && candidate.event ? candidate.event : entry;
374
374
  });
375
375
  }
376
+ /**
377
+ * Rewrites a journaled actor event's per-incarnation `sessionId` to the
378
+ * current snapshot's child for the same stable `actorId`, so replayed
379
+ * completions match freshly restored children.
380
+ *
381
+ * @internal
382
+ */
376
383
  function rebindActorSession(event, snapshot, sessions) {
377
384
  const actorEvent = event;
378
385
  if (typeof actorEvent.actorId !== "string" || typeof actorEvent.sessionId !== "string") return event;
@@ -1518,4 +1525,4 @@ function createAgentActors(actors, requestActors) {
1518
1525
  };
1519
1526
  }
1520
1527
  //#endregion
1521
- export { resolveAgentStep as _, AGENT_USAGE_EVENT_TYPE as a, messagesSchema as b, createReplayEntry as c, initEntry as d, replay as f, initialAgentStep as g, getInvokeEffectMetadata as h, AGENT_INIT_EVENT_TYPE as i, diffEventLogs as l, executeAgentRequest as m, getAgentSchemas as n, AgentReplayDivergenceError as o, validateReplayEntries as p, setupAgent as r, AgentReplayMachineMismatchError as s, createAgentSchemas as t, getAgentEffects as u, transitionAgentStep as v, appendMessages as y };
1528
+ export { initialAgentStep as _, AGENT_USAGE_EVENT_TYPE as a, appendMessages as b, createReplayEntry as c, initEntry as d, rebindActorSession as f, getInvokeEffectMetadata as g, executeAgentRequest as h, AGENT_INIT_EVENT_TYPE as i, diffEventLogs as l, validateReplayEntries as m, getAgentSchemas as n, AgentReplayDivergenceError as o, replay as p, setupAgent as r, AgentReplayMachineMismatchError as s, createAgentSchemas as t, getAgentEffects as u, resolveAgentStep as v, messagesSchema as x, transitionAgentStep as y };
@@ -1,5 +1,5 @@
1
1
  const require_errors = require("./errors-DUBBzRLP.cjs");
2
- const require_decision = require("./decision-t26zsnSR.cjs");
2
+ const require_decision = require("./decision-DhsKLYAI.cjs");
3
3
  const require_event_log_store = require("./event-log-store-a_TKy1gk.cjs");
4
4
  require("./validate.cjs");
5
5
  let xstate = require("xstate");
@@ -374,6 +374,13 @@ function toEvents(history) {
374
374
  return candidate && typeof candidate === "object" && "event" in candidate && candidate.event ? candidate.event : entry;
375
375
  });
376
376
  }
377
+ /**
378
+ * Rewrites a journaled actor event's per-incarnation `sessionId` to the
379
+ * current snapshot's child for the same stable `actorId`, so replayed
380
+ * completions match freshly restored children.
381
+ *
382
+ * @internal
383
+ */
377
384
  function rebindActorSession(event, snapshot, sessions) {
378
385
  const actorEvent = event;
379
386
  if (typeof actorEvent.actorId !== "string" || typeof actorEvent.sessionId !== "string") return event;
@@ -1609,6 +1616,12 @@ Object.defineProperty(exports, "messagesSchema", {
1609
1616
  return messagesSchema;
1610
1617
  }
1611
1618
  });
1619
+ Object.defineProperty(exports, "rebindActorSession", {
1620
+ enumerable: true,
1621
+ get: function() {
1622
+ return rebindActorSession;
1623
+ }
1624
+ });
1612
1625
  Object.defineProperty(exports, "replay", {
1613
1626
  enumerable: true,
1614
1627
  get: function() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/agent",
3
- "version": "2.0.0-alpha.19",
3
+ "version": "2.0.0-alpha.20",
4
4
  "description": "Make invalid agent actions impossible. Agent logic as state machines: deterministic, inspectable, resumable, runs anywhere.",
5
5
  "keywords": [
6
6
  "agent",
@@ -131,14 +131,14 @@
131
131
  "typescript": "^5.6.2",
132
132
  "valibot": "^1.4.2",
133
133
  "vitest": "^3.2.6",
134
- "xstate": "6.0.0-alpha.25",
134
+ "xstate": "6.0.0-alpha.41",
135
135
  "zod": "^4.3.6"
136
136
  },
137
137
  "peerDependencies": {
138
138
  "@opentelemetry/api": "^1",
139
139
  "ai": "^6.0.67",
140
140
  "ajv": "^8.20.0",
141
- "xstate": ">=6.0.0-alpha.25 <6.0.0"
141
+ "xstate": ">=6.0.0-alpha.41 <6.0.0"
142
142
  },
143
143
  "peerDependenciesMeta": {
144
144
  "@opentelemetry/api": {