@statelyai/agent 2.0.0-alpha.26 → 2.0.0-alpha.28

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.
Files changed (54) hide show
  1. package/dist/ai-sdk.cjs +4 -4
  2. package/dist/ai-sdk.d.cts +6 -6
  3. package/dist/ai-sdk.d.mts +6 -6
  4. package/dist/ai-sdk.mjs +4 -4
  5. package/dist/{decision-CM9CYZ6t.cjs → decision-CmM8-HHz.cjs} +10 -9
  6. package/dist/{decision-DzSv1NpD.mjs → decision-RQ0iv0oZ.mjs} +10 -9
  7. package/dist/{event-log-store-Ba2fsc4E.mjs → event-log-store-2pAFiWuc.mjs} +1 -1
  8. package/dist/{event-log-store-DvOcs10J.d.cts → event-log-store-2xzFmgr2.d.cts} +1 -1
  9. package/dist/{event-log-store-DxyVgnas.d.mts → event-log-store-BIPOz-di.d.mts} +1 -1
  10. package/dist/{event-log-store-DQmImLYk.cjs → event-log-store-C-COhIXP.cjs} +1 -1
  11. package/dist/index.cjs +13 -195
  12. package/dist/index.d.cts +25 -105
  13. package/dist/index.d.mts +25 -105
  14. package/dist/index.mjs +12 -189
  15. package/dist/log.cjs +1 -1
  16. package/dist/log.d.cts +1 -1
  17. package/dist/log.d.mts +1 -1
  18. package/dist/log.mjs +1 -1
  19. package/dist/machines.cjs +4 -7
  20. package/dist/machines.d.cts +5 -7
  21. package/dist/machines.d.mts +5 -7
  22. package/dist/machines.mjs +4 -7
  23. package/dist/openai.cjs +3 -3
  24. package/dist/openai.d.cts +5 -5
  25. package/dist/openai.d.mts +5 -5
  26. package/dist/openai.mjs +3 -3
  27. package/dist/otel.cjs +2 -2
  28. package/dist/otel.d.cts +3 -3
  29. package/dist/otel.d.mts +3 -3
  30. package/dist/otel.mjs +2 -2
  31. package/dist/{run-agent-CG343kFs.d.mts → run-agent-ByO-Bxyd.d.cts} +184 -179
  32. package/dist/{run-agent-BOfoJg5B.d.cts → run-agent-COXXc0RW.d.mts} +184 -179
  33. package/dist/{run-agent-Cb1-LS5P.cjs → run-agent-Dmf8GV2d.cjs} +539 -737
  34. package/dist/{run-agent-DvDQd4If.mjs → run-agent-xNTxpt82.mjs} +537 -705
  35. package/dist/{setup-agent-CFW-jPI8.mjs → setup-agent-BuanDXeh.mjs} +6 -28
  36. package/dist/{setup-agent-CPf7MxnG.cjs → setup-agent-DV4cTou-.cjs} +6 -28
  37. package/dist/testing.cjs +276 -27
  38. package/dist/testing.d.cts +17 -15
  39. package/dist/testing.d.mts +17 -15
  40. package/dist/testing.mjs +260 -12
  41. package/dist/{text-logic-Bl_ZRxDi.mjs → text-logic-CIqHAmBi.mjs} +10 -26
  42. package/dist/{text-logic-BFEOxyxv.d.cts → text-logic-D-czVPYp.d.mts} +27 -28
  43. package/dist/{text-logic-hZSiRUo1.d.mts → text-logic-IjfYy9DP.d.cts} +27 -28
  44. package/dist/{text-logic-C8xyr6Ag.cjs → text-logic-f5F5sCdc.cjs} +9 -43
  45. package/dist/{types-B1Qs2q3q.d.cts → types-BgNbNKnJ.d.mts} +3 -3
  46. package/dist/{types-tA3SdczG.d.mts → types-hR5f5YXa.d.cts} +3 -3
  47. package/dist/{utils-C2DPqomn.d.mts → utils-_q7F-AZu.d.mts} +2 -2
  48. package/dist/{utils-ceStNCOh.d.cts → utils-o4YRdHJX.d.cts} +2 -2
  49. package/dist/validate.cjs +0 -8
  50. package/dist/validate.mjs +0 -8
  51. package/package.json +3 -3
  52. package/readme.md +26 -18
  53. package/schemas/agent-workflow.json +0 -8
  54. package/skills/generate-machine/SKILL.md +6 -8
package/dist/ai-sdk.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_text_logic = require("./text-logic-C8xyr6Ag.cjs");
3
- const require_decision = require("./decision-CM9CYZ6t.cjs");
2
+ const require_text_logic = require("./text-logic-f5F5sCdc.cjs");
3
+ const require_decision = require("./decision-CmM8-HHz.cjs");
4
4
  require("./validate.cjs");
5
5
  let ai = require("ai");
6
6
  //#region src/ai-sdk/mappers.ts
@@ -270,7 +270,7 @@ function truncated(request, info, partialOutput, cause) {
270
270
  }
271
271
  /**
272
272
  * The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
273
- * decide }` executor set consumed by `runAgent`/`executeAgentRequest`. `ai`
273
+ * decide }` executor set consumed by `createAgentRuntime`/`executeAgentRequest`. `ai`
274
274
  * must not become a dependency of core `src/` files — this subpath is the one
275
275
  * place it's imported, and callers must supply their own model resolver so no
276
276
  * concrete provider package (e.g. `@ai-sdk/openai`) becomes a dependency here
@@ -279,7 +279,7 @@ function truncated(request, info, partialOutput, cause) {
279
279
  * @example
280
280
  * ```ts
281
281
  * const executors = createAiSdkExecutors({ models: { quick: openai('gpt-5.4-mini') } });
282
- * const result = await runAgent(machine, { input, executors });
282
+ * const result = await runToQuiescence(createAgentRuntime(machine, { executors }), { input });
283
283
  * ```
284
284
  */
285
285
  function createAiSdkExecutors(options) {
package/dist/ai-sdk.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { s as AgentTools, u as ChosenEvent } from "./types-B1Qs2q3q.cjs";
2
- import { M as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-BFEOxyxv.cjs";
1
+ import { s as AgentTools, u as ChosenEvent } from "./types-hR5f5YXa.cjs";
2
+ import { M as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-IjfYy9DP.cjs";
3
3
  import { FinishReason, LanguageModel, LanguageModelUsage, ModelMessage, ToolSet, TypedToolCall, TypedToolResult, generateText } from "ai";
4
4
 
5
5
  //#region src/ai-sdk/mappers.d.ts
@@ -81,7 +81,7 @@ declare function toLanguageModel(entry: AiSdkModelEntry): LanguageModel;
81
81
  * validated structured object for structured-output requests, or the
82
82
  * accumulated text string otherwise) and `messages`, plus the AI SDK call
83
83
  * metadata. Core reads `result`, `messages` and `usage`; everything else flows
84
- * verbatim to `runAgent`'s `onResult(request, { raw })`, so
84
+ * verbatim to `createAgentRuntime`'s `onResult(request, { raw })`, so
85
85
  * `raw as AiSdkGenerateResult` is the supported cast for token accounting and
86
86
  * tracing.
87
87
  */
@@ -92,7 +92,7 @@ type AiSdkGenerateResult = {
92
92
  * {@link providerOutputSchema}). Never enters machine context/output. */
93
93
  reasoning?: string;
94
94
  /** The call's token usage. Its flat `inputTokens`/`outputTokens`/`totalTokens`/
95
- * `reasoningTokens`/`cachedInputTokens` fields are what `runAgent` folds into
95
+ * `reasoningTokens`/`cachedInputTokens` fields are what the runtime folds into
96
96
  * the run result's aggregated `AgentUsage`; the AI SDK's own nested
97
97
  * `inputTokenDetails`/`outputTokenDetails` and `raw` ride along untouched. */
98
98
  usage: AiSdkCallUsage; /** Why the call stopped, normalized to the portable {@link AgentFinishReason}. The SDK's own value stays on `raw`. */
@@ -130,7 +130,7 @@ interface AiSdkExecutors {
130
130
  }
131
131
  /**
132
132
  * The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
133
- * decide }` executor set consumed by `runAgent`/`executeAgentRequest`. `ai`
133
+ * decide }` executor set consumed by `createAgentRuntime`/`executeAgentRequest`. `ai`
134
134
  * must not become a dependency of core `src/` files — this subpath is the one
135
135
  * place it's imported, and callers must supply their own model resolver so no
136
136
  * concrete provider package (e.g. `@ai-sdk/openai`) becomes a dependency here
@@ -139,7 +139,7 @@ interface AiSdkExecutors {
139
139
  * @example
140
140
  * ```ts
141
141
  * const executors = createAiSdkExecutors({ models: { quick: openai('gpt-5.4-mini') } });
142
- * const result = await runAgent(machine, { input, executors });
142
+ * const result = await runToQuiescence(createAgentRuntime(machine, { executors }), { input });
143
143
  * ```
144
144
  */
145
145
  declare function createAiSdkExecutors<TModels extends AiSdkModelMap>(options: CreateAiSdkExecutorsOptions<TModels>): AiSdkExecutors;
package/dist/ai-sdk.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { s as AgentTools, u as ChosenEvent } from "./types-tA3SdczG.mjs";
2
- import { M as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-hZSiRUo1.mjs";
1
+ import { s as AgentTools, u as ChosenEvent } from "./types-BgNbNKnJ.mjs";
2
+ import { M as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-D-czVPYp.mjs";
3
3
  import { FinishReason, LanguageModel, LanguageModelUsage, ModelMessage, ToolSet, TypedToolCall, TypedToolResult, generateText } from "ai";
4
4
 
5
5
  //#region src/ai-sdk/mappers.d.ts
@@ -81,7 +81,7 @@ declare function toLanguageModel(entry: AiSdkModelEntry): LanguageModel;
81
81
  * validated structured object for structured-output requests, or the
82
82
  * accumulated text string otherwise) and `messages`, plus the AI SDK call
83
83
  * metadata. Core reads `result`, `messages` and `usage`; everything else flows
84
- * verbatim to `runAgent`'s `onResult(request, { raw })`, so
84
+ * verbatim to `createAgentRuntime`'s `onResult(request, { raw })`, so
85
85
  * `raw as AiSdkGenerateResult` is the supported cast for token accounting and
86
86
  * tracing.
87
87
  */
@@ -92,7 +92,7 @@ type AiSdkGenerateResult = {
92
92
  * {@link providerOutputSchema}). Never enters machine context/output. */
93
93
  reasoning?: string;
94
94
  /** The call's token usage. Its flat `inputTokens`/`outputTokens`/`totalTokens`/
95
- * `reasoningTokens`/`cachedInputTokens` fields are what `runAgent` folds into
95
+ * `reasoningTokens`/`cachedInputTokens` fields are what the runtime folds into
96
96
  * the run result's aggregated `AgentUsage`; the AI SDK's own nested
97
97
  * `inputTokenDetails`/`outputTokenDetails` and `raw` ride along untouched. */
98
98
  usage: AiSdkCallUsage; /** Why the call stopped, normalized to the portable {@link AgentFinishReason}. The SDK's own value stays on `raw`. */
@@ -130,7 +130,7 @@ interface AiSdkExecutors {
130
130
  }
131
131
  /**
132
132
  * The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
133
- * decide }` executor set consumed by `runAgent`/`executeAgentRequest`. `ai`
133
+ * decide }` executor set consumed by `createAgentRuntime`/`executeAgentRequest`. `ai`
134
134
  * must not become a dependency of core `src/` files — this subpath is the one
135
135
  * place it's imported, and callers must supply their own model resolver so no
136
136
  * concrete provider package (e.g. `@ai-sdk/openai`) becomes a dependency here
@@ -139,7 +139,7 @@ interface AiSdkExecutors {
139
139
  * @example
140
140
  * ```ts
141
141
  * const executors = createAiSdkExecutors({ models: { quick: openai('gpt-5.4-mini') } });
142
- * const result = await runAgent(machine, { input, executors });
142
+ * const result = await runToQuiescence(createAgentRuntime(machine, { executors }), { input });
143
143
  * ```
144
144
  */
145
145
  declare function createAiSdkExecutors<TModels extends AiSdkModelMap>(options: CreateAiSdkExecutorsOptions<TModels>): AiSdkExecutors;
package/dist/ai-sdk.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { I as isStandardSchema, U as AgentTruncatedError, g as providerOutputSchema, l as getAgentOutputMode } from "./text-logic-Bl_ZRxDi.mjs";
2
- import { o as renderDecisionAttempts } from "./decision-DzSv1NpD.mjs";
1
+ import { B as AgentTruncatedError, N as isStandardSchema, c as getAgentOutputMode, h as providerOutputSchema } from "./text-logic-CIqHAmBi.mjs";
2
+ import { o as renderDecisionAttempts } from "./decision-RQ0iv0oZ.mjs";
3
3
  import { NoObjectGeneratedError, Output, generateText, stepCountIs, streamText, tool } from "ai";
4
4
  //#region src/ai-sdk/mappers.ts
5
5
  /**
@@ -268,7 +268,7 @@ function truncated(request, info, partialOutput, cause) {
268
268
  }
269
269
  /**
270
270
  * The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
271
- * decide }` executor set consumed by `runAgent`/`executeAgentRequest`. `ai`
271
+ * decide }` executor set consumed by `createAgentRuntime`/`executeAgentRequest`. `ai`
272
272
  * must not become a dependency of core `src/` files — this subpath is the one
273
273
  * place it's imported, and callers must supply their own model resolver so no
274
274
  * concrete provider package (e.g. `@ai-sdk/openai`) becomes a dependency here
@@ -277,7 +277,7 @@ function truncated(request, info, partialOutput, cause) {
277
277
  * @example
278
278
  * ```ts
279
279
  * const executors = createAiSdkExecutors({ models: { quick: openai('gpt-5.4-mini') } });
280
- * const result = await runAgent(machine, { input, executors });
280
+ * const result = await runToQuiescence(createAgentRuntime(machine, { executors }), { input });
281
281
  * ```
282
282
  */
283
283
  function createAiSdkExecutors(options) {
@@ -1,4 +1,4 @@
1
- const require_text_logic = require("./text-logic-C8xyr6Ag.cjs");
1
+ const require_text_logic = require("./text-logic-f5F5sCdc.cjs");
2
2
  require("./validate.cjs");
3
3
  let xstate = require("xstate");
4
4
  //#region src/internal/is-record.ts
@@ -81,7 +81,7 @@ function isEventPattern(entry) {
81
81
  /**
82
82
  * Parses a wire payload (a request body, a socket frame) into an
83
83
  * event typed as the machine's event union, so it can go straight to
84
- * `runAgent({ event })` / `actor.send(...)` without a cast. Pass the machine
84
+ * `runToQuiescence(runtime, { event })` / `actor.send(...)` without a cast. Pass the machine
85
85
  * itself, or any snapshot of it.
86
86
  *
87
87
  * It checks exactly what a schema can check: the payload is an object with a
@@ -98,7 +98,8 @@ function isEventPattern(entry) {
98
98
  * @example
99
99
  * ```ts
100
100
  * const event = parseAgentEvent(machine, await request.json());
101
- * const result = await runAgent(machine, { store, threadId, event, executors });
101
+ * const runtime = createAgentRuntime(machine, { store, threadId, executors });
102
+ * const result = await runToQuiescence(runtime, { event });
102
103
  * ```
103
104
  */
104
105
  function parseAgentEvent(source, payload, options = {}) {
@@ -182,8 +183,8 @@ function decideActorWithExecutor(execute) {
182
183
  const logic = (0, xstate.createAsyncLogic)({ run: async ({ input, signal }) => {
183
184
  if (!execute) throw new Error(`'${require_text_logic.DECIDE_ACTOR}' has no host execution. Provide an implementation with machine.provide({ actors: { '${require_text_logic.DECIDE_ACTOR}': ... } }) or resolve the returned agent request with resolveDecision(...).`);
184
185
  const resolvedEventTypes = resolveAllowedEventTypes(input.allowedEvents, input);
185
- if (resolvedEventTypes === void 0) throw new Error(`'${require_text_logic.DECIDE_ACTOR}' input has omitted \`allowedEvents\`, which means "all currently-legal events" — but that requires a snapshot-aware host (runAgent or the step path) to resolve. Under a bare createActor(...), declare \`allowedEvents\` explicitly to use this actor here.`);
186
- if (resolvedEventTypes.some(isEventPattern)) throw new Error(`'${require_text_logic.DECIDE_ACTOR}' input uses wildcard \`allowedEvents\` patterns, which expand against the live snapshot — that requires a snapshot-aware host (runAgent or the step path). Under a bare createActor(...), list event types explicitly.`);
186
+ if (resolvedEventTypes === void 0) throw new Error(`'${require_text_logic.DECIDE_ACTOR}' input has omitted \`allowedEvents\`, which means "all currently-legal events" — but that requires a snapshot-aware host (createAgentRuntime) to resolve. Under a bare createActor(...), declare \`allowedEvents\` explicitly to use this actor here.`);
187
+ if (resolvedEventTypes.some(isEventPattern)) throw new Error(`'${require_text_logic.DECIDE_ACTOR}' input uses wildcard \`allowedEvents\` patterns, which expand against the live snapshot — that requires a snapshot-aware host (createAgentRuntime). Under a bare createActor(...), list event types explicitly.`);
187
188
  return resolveDecision(decideRequestFromInput(input), { decide: execute }, {
188
189
  maxRetries: input.maxRetries ?? 2,
189
190
  signal
@@ -210,7 +211,7 @@ function resolveAllowedEventTypes(allowedEvents, input) {
210
211
  * run, resolves to exactly one currently-legal {@link ChosenEvent} by
211
212
  * calling the host `decide` executor (passed here as `execute`, or supplied
212
213
  * later via {@link DecisionLogic.withExecutor}, `machine.provide(...)`, or
213
- * `runAgent`'s `decide` option). Register the result under `actors:` and
214
+ * `createAgentRuntime`'s `executors.decide`). Register the result under `actors:` and
214
215
  * invoke it by name; for a one-off, state-local decision, prefer the
215
216
  * `agent.decide` builtin invoke instead — it needs no separate declaration
216
217
  * and types `allowedEvents` against the machine's own event schemas.
@@ -262,10 +263,10 @@ function createDecisionLogic(config, execute) {
262
263
  };
263
264
  };
264
265
  const logic = (0, xstate.createAsyncLogic)({ run: async ({ input, signal }) => {
265
- if (!execute) throw new Error("Decision logic has no host execution. Pass an executor as the second argument to createDecisionLogic(...), provide a runtime adapter, or bind it through runAgent/provideExecutors, or call resolveDecision from your host.");
266
+ if (!execute) throw new Error("Decision logic has no host execution. Pass an executor as the second argument to createDecisionLogic(...), provide a runtime adapter, or bind it through createAgentRuntime/provideExecutors, or call resolveDecision from your host.");
266
267
  const allowedEventTypes = resolveAllowedEventTypes(config.allowedEvents, input);
267
- if (allowedEventTypes === void 0) throw new Error("Decision logic has omitted `allowedEvents`, which means \"all currently-legal events\" — but that requires a snapshot-aware host (runAgent or the step path) to resolve. Under a bare createActor(...), declare `allowedEvents` explicitly on this logic to use it here.");
268
- if (allowedEventTypes.some(isEventPattern)) throw new Error("Decision logic uses wildcard `allowedEvents` patterns, which expand against the live snapshot — that requires a snapshot-aware host (runAgent or the step path). Under a bare createActor(...), list event types explicitly.");
268
+ if (allowedEventTypes === void 0) throw new Error("Decision logic has omitted `allowedEvents`, which means \"all currently-legal events\" — but that requires a snapshot-aware host (createAgentRuntime) to resolve. Under a bare createActor(...), declare `allowedEvents` explicitly on this logic to use it here.");
269
+ if (allowedEventTypes.some(isEventPattern)) throw new Error("Decision logic uses wildcard `allowedEvents` patterns, which expand against the live snapshot — that requires a snapshot-aware host (createAgentRuntime). Under a bare createActor(...), list event types explicitly.");
269
270
  return resolveDecision(request(input), { decide: execute }, {
270
271
  maxRetries,
271
272
  signal
@@ -1,4 +1,4 @@
1
- import { B as userMessage, H as AgentError, V as validateSchemaSync, _ as resolveTextLogicValue, b as getAgentExecutionOptions, n as DECIDE_ACTOR, y as executorBoundLogics } from "./text-logic-Bl_ZRxDi.mjs";
1
+ import { L as userMessage, R as validateSchemaSync, g as resolveTextLogicValue, n as DECIDE_ACTOR, v as executorBoundLogics, y as getAgentExecutionOptions, z as AgentError } from "./text-logic-CIqHAmBi.mjs";
2
2
  import { createAsyncLogic, getNextTransitions } from "xstate";
3
3
  //#region src/internal/is-record.ts
4
4
  /** True for a plain object-like value (arrays excluded). @internal */
@@ -80,7 +80,7 @@ function isEventPattern(entry) {
80
80
  /**
81
81
  * Parses a wire payload (a request body, a socket frame) into an
82
82
  * event typed as the machine's event union, so it can go straight to
83
- * `runAgent({ event })` / `actor.send(...)` without a cast. Pass the machine
83
+ * `runToQuiescence(runtime, { event })` / `actor.send(...)` without a cast. Pass the machine
84
84
  * itself, or any snapshot of it.
85
85
  *
86
86
  * It checks exactly what a schema can check: the payload is an object with a
@@ -97,7 +97,8 @@ function isEventPattern(entry) {
97
97
  * @example
98
98
  * ```ts
99
99
  * const event = parseAgentEvent(machine, await request.json());
100
- * const result = await runAgent(machine, { store, threadId, event, executors });
100
+ * const runtime = createAgentRuntime(machine, { store, threadId, executors });
101
+ * const result = await runToQuiescence(runtime, { event });
101
102
  * ```
102
103
  */
103
104
  function parseAgentEvent(source, payload, options = {}) {
@@ -181,8 +182,8 @@ function decideActorWithExecutor(execute) {
181
182
  const logic = createAsyncLogic({ run: async ({ input, signal }) => {
182
183
  if (!execute) throw new Error(`'${DECIDE_ACTOR}' has no host execution. Provide an implementation with machine.provide({ actors: { '${DECIDE_ACTOR}': ... } }) or resolve the returned agent request with resolveDecision(...).`);
183
184
  const resolvedEventTypes = resolveAllowedEventTypes(input.allowedEvents, input);
184
- if (resolvedEventTypes === void 0) throw new Error(`'${DECIDE_ACTOR}' input has omitted \`allowedEvents\`, which means "all currently-legal events" — but that requires a snapshot-aware host (runAgent or the step path) to resolve. Under a bare createActor(...), declare \`allowedEvents\` explicitly to use this actor here.`);
185
- if (resolvedEventTypes.some(isEventPattern)) throw new Error(`'${DECIDE_ACTOR}' input uses wildcard \`allowedEvents\` patterns, which expand against the live snapshot — that requires a snapshot-aware host (runAgent or the step path). Under a bare createActor(...), list event types explicitly.`);
185
+ if (resolvedEventTypes === void 0) throw new Error(`'${DECIDE_ACTOR}' input has omitted \`allowedEvents\`, which means "all currently-legal events" — but that requires a snapshot-aware host (createAgentRuntime) to resolve. Under a bare createActor(...), declare \`allowedEvents\` explicitly to use this actor here.`);
186
+ if (resolvedEventTypes.some(isEventPattern)) throw new Error(`'${DECIDE_ACTOR}' input uses wildcard \`allowedEvents\` patterns, which expand against the live snapshot — that requires a snapshot-aware host (createAgentRuntime). Under a bare createActor(...), list event types explicitly.`);
186
187
  return resolveDecision(decideRequestFromInput(input), { decide: execute }, {
187
188
  maxRetries: input.maxRetries ?? 2,
188
189
  signal
@@ -209,7 +210,7 @@ function resolveAllowedEventTypes(allowedEvents, input) {
209
210
  * run, resolves to exactly one currently-legal {@link ChosenEvent} by
210
211
  * calling the host `decide` executor (passed here as `execute`, or supplied
211
212
  * later via {@link DecisionLogic.withExecutor}, `machine.provide(...)`, or
212
- * `runAgent`'s `decide` option). Register the result under `actors:` and
213
+ * `createAgentRuntime`'s `executors.decide`). Register the result under `actors:` and
213
214
  * invoke it by name; for a one-off, state-local decision, prefer the
214
215
  * `agent.decide` builtin invoke instead — it needs no separate declaration
215
216
  * and types `allowedEvents` against the machine's own event schemas.
@@ -261,10 +262,10 @@ function createDecisionLogic(config, execute) {
261
262
  };
262
263
  };
263
264
  const logic = createAsyncLogic({ run: async ({ input, signal }) => {
264
- if (!execute) throw new Error("Decision logic has no host execution. Pass an executor as the second argument to createDecisionLogic(...), provide a runtime adapter, or bind it through runAgent/provideExecutors, or call resolveDecision from your host.");
265
+ if (!execute) throw new Error("Decision logic has no host execution. Pass an executor as the second argument to createDecisionLogic(...), provide a runtime adapter, or bind it through createAgentRuntime/provideExecutors, or call resolveDecision from your host.");
265
266
  const allowedEventTypes = resolveAllowedEventTypes(config.allowedEvents, input);
266
- if (allowedEventTypes === void 0) throw new Error("Decision logic has omitted `allowedEvents`, which means \"all currently-legal events\" — but that requires a snapshot-aware host (runAgent or the step path) to resolve. Under a bare createActor(...), declare `allowedEvents` explicitly on this logic to use it here.");
267
- if (allowedEventTypes.some(isEventPattern)) throw new Error("Decision logic uses wildcard `allowedEvents` patterns, which expand against the live snapshot — that requires a snapshot-aware host (runAgent or the step path). Under a bare createActor(...), list event types explicitly.");
267
+ if (allowedEventTypes === void 0) throw new Error("Decision logic has omitted `allowedEvents`, which means \"all currently-legal events\" — but that requires a snapshot-aware host (createAgentRuntime) to resolve. Under a bare createActor(...), declare `allowedEvents` explicitly on this logic to use it here.");
268
+ if (allowedEventTypes.some(isEventPattern)) throw new Error("Decision logic uses wildcard `allowedEvents` patterns, which expand against the live snapshot — that requires a snapshot-aware host (createAgentRuntime). Under a bare createActor(...), list event types explicitly.");
268
269
  return resolveDecision(request(input), { decide: execute }, {
269
270
  maxRetries,
270
271
  signal
@@ -1,4 +1,4 @@
1
- import { H as AgentError, L as resolveMachineVersion, O as djb2Hex, t as AGENT_USAGE_TOKEN_FIELDS } from "./text-logic-Bl_ZRxDi.mjs";
1
+ import { P as resolveMachineVersion, T as djb2Hex, t as AGENT_USAGE_TOKEN_FIELDS, z as AgentError } from "./text-logic-CIqHAmBi.mjs";
2
2
  import "./usage-BdEjFuIi.mjs";
3
3
  import { initialTransition, transition } from "xstate";
4
4
  //#region src/event-log.ts
@@ -1,4 +1,4 @@
1
- import { Z as AgentError, t as AgentCallUsage } from "./text-logic-BFEOxyxv.cjs";
1
+ import { Z as AgentError, t as AgentCallUsage } from "./text-logic-IjfYy9DP.cjs";
2
2
  import { AnyMachineSnapshot, AnyStateMachine, EventObject, Snapshot, SnapshotFrom } from "xstate";
3
3
 
4
4
  //#region src/event-log.d.ts
@@ -1,4 +1,4 @@
1
- import { Z as AgentError, t as AgentCallUsage } from "./text-logic-hZSiRUo1.mjs";
1
+ import { Z as AgentError, t as AgentCallUsage } from "./text-logic-D-czVPYp.mjs";
2
2
  import { AnyMachineSnapshot, AnyStateMachine, EventObject, Snapshot, SnapshotFrom } from "xstate";
3
3
 
4
4
  //#region src/event-log.d.ts
@@ -1,4 +1,4 @@
1
- const require_text_logic = require("./text-logic-C8xyr6Ag.cjs");
1
+ const require_text_logic = require("./text-logic-f5F5sCdc.cjs");
2
2
  require("./usage-efOQPdf_.cjs");
3
3
  require("./validate.cjs");
4
4
  let xstate = require("xstate");
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_text_logic = require("./text-logic-C8xyr6Ag.cjs");
3
- const require_decision = require("./decision-CM9CYZ6t.cjs");
2
+ const require_text_logic = require("./text-logic-f5F5sCdc.cjs");
3
+ const require_decision = require("./decision-CmM8-HHz.cjs");
4
4
  const require_usage = require("./usage-efOQPdf_.cjs");
5
- const require_setup_agent = require("./setup-agent-CPf7MxnG.cjs");
6
- const require_run_agent = require("./run-agent-Cb1-LS5P.cjs");
7
- const require_event_log_store = require("./event-log-store-DQmImLYk.cjs");
5
+ const require_setup_agent = require("./setup-agent-DV4cTou-.cjs");
6
+ const require_event_log_store = require("./event-log-store-C-COhIXP.cjs");
7
+ const require_run_agent = require("./run-agent-Dmf8GV2d.cjs");
8
8
  //#region src/messages.ts
9
9
  const KNOWN_PART_TYPES = new Set([
10
10
  "text",
@@ -257,189 +257,12 @@ function eventFromInteraction(snapshot, choice) {
257
257
  return require_decision.parseAgentEvent(snapshot, event);
258
258
  }
259
259
  //#endregion
260
- //#region src/agent-run.ts
261
- /**
262
- * Wraps {@link runAgent} in a canonical run-stream handle: the run's trace
263
- * events as a pull-based {@link AgentRun.events} async iterator, alongside the
264
- * unchanged {@link AgentRun.result} promise.
265
- *
266
- * Semantics:
267
- *
268
- * 1. **Starts immediately.** The underlying `runAgent` is invoked on this call,
269
- * not on the first `events` iteration — work is already in flight when
270
- * `createAgentRun` returns.
271
- * 2. **Buffer, don't stall.** Events are queued in an unbounded in-memory
272
- * buffer as the run emits them; a slow or absent consumer never applies
273
- * backpressure to the run. Once `run.end` is delivered, the iterator
274
- * completes.
275
- * 3. **Composes `onTrace`.** If `options.onTrace` is passed, it still fires for
276
- * every event — the wrapper adds queue delivery, it does not replace the
277
- * caller's sink.
278
- * 4. **`result` mirrors `runAgent`.** Same resolution and rejection behavior
279
- * (see {@link AgentRun.result}). A no-op rejection handler is attached
280
- * internally so a caller who reads only `events` never trips an unhandled
281
- * rejection on a bind-time throw; the returned promise still rejects for a
282
- * caller who awaits it.
283
- * 5. **Resume is identical.** Options pass straight through, so starting from a
284
- * persisted `snapshot` (+ resume `event`) streams that run's events from its
285
- * own `run.start`, exactly as `runAgent` would run it.
286
- * 6. **Early termination does not cancel the run.** Breaking out of a
287
- * `for await` (or calling `events.return()`) stops delivery, but the run
288
- * keeps going and `result` still settles. Cancelling the run itself is
289
- * future work — pass `options.signal` to abort it.
290
- * 7. **`events` is single-consumer.** See {@link AgentRun.events}.
291
- */
292
- function createAgentRun(machine, options) {
293
- const buffer = [];
294
- const resolvers = [];
295
- let closed = false;
296
- let stopped = false;
297
- const push = (event) => {
298
- if (closed || stopped) return;
299
- const resolve = resolvers.shift();
300
- if (resolve) resolve({
301
- value: event,
302
- done: false
303
- });
304
- else buffer.push(event);
305
- };
306
- const drain = () => {
307
- while (resolvers.length > 0) resolvers.shift()({
308
- value: void 0,
309
- done: true
310
- });
311
- };
312
- const close = () => {
313
- if (closed) return;
314
- closed = true;
315
- drain();
316
- };
317
- const userOnTrace = options.onTrace;
318
- const result = require_run_agent.runAgent(machine, {
319
- ...options,
320
- onTrace: (event) => {
321
- push(event);
322
- userOnTrace?.(event);
323
- if (event.type === "run.end") close();
324
- }
325
- });
326
- result.then(close, close);
327
- return {
328
- events: {
329
- next() {
330
- if (buffer.length > 0) return Promise.resolve({
331
- value: buffer.shift(),
332
- done: false
333
- });
334
- if (closed || stopped) return Promise.resolve({
335
- value: void 0,
336
- done: true
337
- });
338
- return new Promise((resolve) => {
339
- resolvers.push(resolve);
340
- });
341
- },
342
- return() {
343
- stopped = true;
344
- buffer.length = 0;
345
- drain();
346
- return Promise.resolve({
347
- value: void 0,
348
- done: true
349
- });
350
- },
351
- [Symbol.asyncIterator]() {
352
- return this;
353
- }
354
- },
355
- result
356
- };
357
- }
358
- function requestIdentity(request) {
359
- const candidate = request;
360
- const id = candidate.id ?? candidate.name ?? "agent.request";
361
- return {
362
- name: candidate.kind === "text" ? candidate.input?.name ?? id : candidate.name ?? id,
363
- id
364
- };
365
- }
366
- /**
367
- * Streams one {@link runAgent} call as agent-level events. The machine remains
368
- * the single artifact; this function only projects its requests, chunks,
369
- * transitions, emitted events, and terminal result into an async iterable.
370
- */
371
- async function* runAgentStream(machine, options) {
372
- const run = createAgentRun(machine, options);
373
- for await (const event of run.events) switch (event.type) {
374
- case "request.start":
375
- yield {
376
- kind: "request",
377
- phase: "start",
378
- ...requestIdentity(event.request),
379
- request: event.request
380
- };
381
- break;
382
- case "request.end":
383
- yield {
384
- kind: "request",
385
- phase: "end",
386
- ...requestIdentity(event.request),
387
- request: event.request,
388
- output: event.output,
389
- raw: event.raw
390
- };
391
- break;
392
- case "request.error":
393
- yield {
394
- kind: "request",
395
- phase: "error",
396
- ...requestIdentity(event.request),
397
- request: event.request,
398
- error: event.error
399
- };
400
- break;
401
- case "stream.chunk":
402
- yield {
403
- kind: "chunk",
404
- ...requestIdentity(event.request),
405
- delta: event.chunk
406
- };
407
- break;
408
- case "machine.transition":
409
- yield {
410
- kind: "transition",
411
- value: event.snapshot.value,
412
- event: event.event
413
- };
414
- break;
415
- case "emit":
416
- yield {
417
- kind: "emit",
418
- event: event.event
419
- };
420
- break;
421
- }
422
- const result = await run.result;
423
- if (result.status === "done") yield {
424
- kind: "done",
425
- result
426
- };
427
- else if (result.status === "idle") yield {
428
- kind: "idle",
429
- result
430
- };
431
- else yield {
432
- kind: "error",
433
- result
434
- };
435
- }
436
- //#endregion
437
260
  //#region src/provide-executors.ts
438
261
  /**
439
262
  * Binds a machine's agent actor sources to a set of host `executors` in one
440
263
  * call, returning a `machine.provide(...)`-ed copy ready for a plain
441
- * `createActor(...)` — the uncontrolled-mode counterpart to {@link runAgent}.
442
- * No run loop, no idle settling: the returned machine drives itself, so
264
+ * `createActor(...)` — the uncontrolled-mode counterpart to {@link createAgentRuntime}.
265
+ * No run loop, no settling: the returned machine drives itself, so
443
266
  *
444
267
  * ```ts
445
268
  * const actor = createActor(provideExecutors(machine, { generateText, decide }), { input });
@@ -454,10 +277,10 @@ async function* runAgentStream(machine, options) {
454
277
  * - `mode: 'stream'` text source → `executors.streamText`
455
278
  * - decision / `agent.decide` source → `executors.decide` (snapshot-driven
456
279
  * candidate events, guard `canTake`, and auto-delivery of the chosen event,
457
- * mirroring `runAgent` but without its model-call counting)
280
+ * mirroring `createAgentRuntime` but without its model-call counting)
458
281
  *
459
282
  * Pass `options.onTrace` to observe request-level trace events (identical in
460
- * shape to `runAgent`'s); pair it with {@link traceTransitions} on the actor's
283
+ * shape to `createAgentRuntime`'s); pair it with {@link traceTransitions} on the actor's
461
284
  * `inspect` to also capture `machine.transition` events in the same stream.
462
285
  *
463
286
  * A source that already carries its own executor (`.withExecutor(...)`) is left
@@ -468,7 +291,7 @@ async function* runAgentStream(machine, options) {
468
291
  * Throws at bind time if a source needs an executor kind that `executors` does
469
292
  * not provide.
470
293
  *
471
- * Executor inheritance is RECURSIVE, exactly as in `runAgent`: a string-keyed
294
+ * Executor inheritance is RECURSIVE, exactly as in `createAgentRuntime`: a string-keyed
472
295
  * invoked child machine is rebound too, so its own text/decision requests — at
473
296
  * any depth — reach the same host executors. A direct-object invoke `src`
474
297
  * cannot be swapped via `.provide`, so nothing under one inherits; bind those
@@ -524,7 +347,7 @@ function executorRequirementOf(logic) {
524
347
  /**
525
348
  * Walks an invoked child machine's own invoked sources (recursively, at any
526
349
  * depth) and throws the same missing-executor error `provideExecutors` throws
527
- * for the top-level machine — before any actor starts. Mirrors runAgent's
350
+ * for the top-level machine — before any actor starts. Mirrors the runtime's
528
351
  * `assertBindable` for the uncontrolled path. Cycle-safe via `visited`.
529
352
  */
530
353
  function assertChildBindable(childMachine, executors, path, visited) {
@@ -559,12 +382,12 @@ exports.AgentSnapshotDivergedError = require_run_agent.AgentSnapshotDivergedErro
559
382
  exports.AgentTruncatedError = require_text_logic.AgentTruncatedError;
560
383
  exports.assistantMessage = require_text_logic.assistantMessage;
561
384
  exports.bindRequestExecutor = require_text_logic.bindRequestExecutor;
385
+ exports.createAgentRuntime = require_run_agent.createAgentRuntime;
562
386
  exports.createAgentSchemas = require_setup_agent.createAgentSchemas;
563
387
  exports.createDecisionLogic = require_decision.createDecisionLogic;
564
388
  exports.createDecisionRequest = require_decision.createDecisionRequest;
565
389
  exports.createTextLogic = require_text_logic.createTextLogic;
566
390
  exports.eventFromInteraction = eventFromInteraction;
567
- exports.executeAgentRequest = require_run_agent.executeAgentRequest;
568
391
  exports.getAcceptedEvents = require_decision.getAcceptedEvents;
569
392
  exports.getAgentOutputMode = require_text_logic.getAgentOutputMode;
570
393
  exports.getAgentSchemas = require_setup_agent.getAgentSchemas;
@@ -577,7 +400,6 @@ exports.getMachineStructuralHash = require_text_logic.getMachineStructuralHash;
577
400
  exports.getMessageText = require_text_logic.getMessageText;
578
401
  exports.getStateMeta = require_text_logic.getStateMeta;
579
402
  exports.getStatePath = require_text_logic.getStatePath;
580
- exports.initialAgentStep = require_run_agent.initialAgentStep;
581
403
  exports.inspectTransitions = require_run_agent.inspectTransitions;
582
404
  exports.interactionMetaSchema = interactionMetaSchema;
583
405
  exports.isAgentIdle = require_run_agent.isAgentIdle;
@@ -589,12 +411,9 @@ exports.parseOutput = require_text_logic.parseOutput;
589
411
  exports.parseProviderOutput = require_text_logic.parseProviderOutput;
590
412
  exports.provideExecutors = provideExecutors;
591
413
  exports.providerOutputSchema = require_text_logic.providerOutputSchema;
592
- exports.rejectAgentStep = require_run_agent.rejectAgentStep;
593
414
  exports.renderDecisionAttempts = require_decision.renderDecisionAttempts;
594
- exports.resolveAgentStep = require_run_agent.resolveAgentStep;
595
415
  exports.resolveDecision = require_decision.resolveDecision;
596
- exports.runAgent = require_run_agent.runAgent;
597
- exports.runAgentStream = runAgentStream;
416
+ exports.runToQuiescence = require_run_agent.runToQuiescence;
598
417
  exports.serializeTraceEvent = require_run_agent.serializeTraceEvent;
599
418
  Object.defineProperty(exports, "setupAgent", {
600
419
  enumerable: true,
@@ -605,5 +424,4 @@ Object.defineProperty(exports, "setupAgent", {
605
424
  exports.systemMessage = require_text_logic.systemMessage;
606
425
  exports.toolMessage = require_text_logic.toolMessage;
607
426
  exports.traceTransitions = require_run_agent.traceTransitions;
608
- exports.transitionAgentStep = require_run_agent.transitionAgentStep;
609
427
  exports.userMessage = require_text_logic.userMessage;