@statelyai/agent 2.0.0-alpha.10 → 2.0.0-alpha.11

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 (45) hide show
  1. package/dist/adapter.cjs +15 -0
  2. package/dist/adapter.d.cts +4 -0
  3. package/dist/adapter.d.mts +4 -0
  4. package/dist/adapter.mjs +2 -0
  5. package/dist/ai-sdk.cjs +66 -102
  6. package/dist/ai-sdk.d.cts +5 -115
  7. package/dist/ai-sdk.d.mts +5 -115
  8. package/dist/ai-sdk.mjs +64 -91
  9. package/dist/decision-C3k4ve51.mjs +227 -0
  10. package/dist/decision-D8wJrM8W.cjs +286 -0
  11. package/dist/{decision-b-lkcs4L.cjs → events-CRQj3VtP.cjs} +10 -295
  12. package/dist/{decision-CQdrKc8k.mjs → events-JiVPYrct.mjs} +10 -229
  13. package/dist/index.cjs +2521 -52
  14. package/dist/index.d.cts +1029 -9
  15. package/dist/index.d.mts +1029 -9
  16. package/dist/index.mjs +2493 -4
  17. package/dist/openai-compat.cjs +23 -33
  18. package/dist/openai-compat.d.cts +3 -42
  19. package/dist/openai-compat.d.mts +3 -42
  20. package/dist/openai-compat.mjs +20 -24
  21. package/dist/steps-BALp1eZo.d.mts +198 -0
  22. package/dist/steps-CVe54GPP.cjs +420 -0
  23. package/dist/steps-CkyyyuHd.mjs +379 -0
  24. package/dist/steps-MjnQI4aB.d.cts +198 -0
  25. package/dist/steps.cjs +12 -0
  26. package/dist/steps.d.cts +3 -0
  27. package/dist/steps.d.mts +3 -0
  28. package/dist/steps.mjs +3 -0
  29. package/dist/{text-logic-C7WJpCIc.d.mts → text-logic-CaKqgX4Y.d.mts} +8 -8
  30. package/dist/{text-logic-CZjyACzQ.d.cts → text-logic-Ckhr2kKC.d.cts} +8 -8
  31. package/package.json +27 -4
  32. package/readme.md +18 -8
  33. package/schemas/agent-workflow.json +4 -5
  34. package/dist/cli.cjs +0 -64
  35. package/dist/cli.d.cts +0 -1
  36. package/dist/cli.d.mts +0 -1
  37. package/dist/cli.mjs +0 -65
  38. package/dist/run-agent-BFMkuI1F.cjs +0 -1599
  39. package/dist/run-agent-BVMd--1l.d.cts +0 -1103
  40. package/dist/run-agent-BoAOq_0Z.mjs +0 -1540
  41. package/dist/run-agent-DzYJb3CK.d.mts +0 -1103
  42. package/dist/src-D-77Ha5p.cjs +0 -1087
  43. package/dist/src-DUeIFjv-.mjs +0 -1016
  44. /package/dist/{utils-Dri7aeEG.d.cts → utils-BYqT_Dyv.d.cts} +0 -0
  45. /package/dist/{utils-Y6GDRGGE.d.mts → utils-Do5wIJrh.d.mts} +0 -0
@@ -1,27 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_decision = require("./decision-b-lkcs4L.cjs");
3
- //#region src/openai-compat/index.ts
4
- /**
5
- * OpenAI-compatible Chat Completions adapter — a COMPLETE `{ generateText,
6
- * streamText, decide }` executor set built on raw `fetch`, with zero runtime
7
- * dependencies (no `openai` package, no Vercel AI SDK).
8
- *
9
- * The OpenAI Chat Completions wire format is the lingua franca of hosted and
10
- * local inference: Groq, Together, Fireworks, OpenRouter, vLLM, Ollama, LM
11
- * Studio, and OpenAI itself all speak it. Point `baseUrl` at any of them.
12
- *
13
- * Compare `createAiSdkExecutors` in `../ai-sdk/index.ts` (the AI-SDK-backed
14
- * adapter) — same three-function contract, different transport. The request
15
- * mapping is ported from `examples/openai-sdk-host/index.ts`, but wired
16
- * against `POST {baseUrl}/chat/completions` instead of the `openai` package.
17
- */
18
- /**
19
- * Reads a Standard Schema's optional `~standard.jsonSchema.input()` extension
20
- * (implemented by e.g. Zod v4's `z.toJSONSchema`), awaiting it when it returns
21
- * a Promise. Returns `undefined` when the schema doesn't expose the extension.
22
- * Thin re-export of core's {@link getJsonSchema}.
23
- */
24
- const extractJsonSchema = require_decision.getJsonSchema;
2
+ const require_events = require("./events-CRQj3VtP.cjs");
3
+ const require_decision = require("./decision-D8wJrM8W.cjs");
4
+ //#region src/openai-compat/mappers.ts
25
5
  /** Maps `AgentTextRequest.messages`/`system`/`prompt` to Chat Completions messages. */
26
6
  function toOpenAiMessages(request) {
27
7
  if (request.messages) return request.messages.flatMap((message) => {
@@ -82,7 +62,7 @@ function toOpenAiTools(tools) {
82
62
  function: {
83
63
  name,
84
64
  description: typeof descriptor === "function" ? void 0 : descriptor.description,
85
- parameters: (require_decision.isStandardSchema(inputSchema) ? require_decision.getJsonSchemaSync(inputSchema) : void 0) ?? {}
65
+ parameters: (require_events.isStandardSchema(inputSchema) ? require_events.getJsonSchemaSync(inputSchema) : void 0) ?? {}
86
66
  }
87
67
  }];
88
68
  });
@@ -95,7 +75,7 @@ function toOpenAiEventTools(events) {
95
75
  function: {
96
76
  name: event.toolName,
97
77
  description: `Choose the '${event.type}' move.`,
98
- parameters: require_decision.getJsonSchemaSync(event.inputSchema) ?? {}
78
+ parameters: require_events.getJsonSchemaSync(event.inputSchema) ?? {}
99
79
  }
100
80
  }));
101
81
  }
@@ -113,6 +93,22 @@ function toDecisionMessages(request) {
113
93
  function pruneUndefined(record) {
114
94
  return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== void 0));
115
95
  }
96
+ //#endregion
97
+ //#region src/openai-compat/index.ts
98
+ /**
99
+ * OpenAI-compatible Chat Completions adapter — a COMPLETE `{ generateText,
100
+ * streamText, decide }` executor set built on raw `fetch`, with zero runtime
101
+ * dependencies (no `openai` package, no Vercel AI SDK).
102
+ *
103
+ * The OpenAI Chat Completions wire format is the lingua franca of hosted and
104
+ * local inference: Groq, Together, Fireworks, OpenRouter, vLLM, Ollama, LM
105
+ * Studio, and OpenAI itself all speak it. Point `baseUrl` at any of them.
106
+ *
107
+ * Compare `createAiSdkExecutors` in `../ai-sdk/index.ts` (the AI-SDK-backed
108
+ * adapter) — same three-function contract, different transport. The request
109
+ * mapping is ported from `examples/openai-sdk-host/index.ts`, but wired
110
+ * against `POST {baseUrl}/chat/completions` instead of the `openai` package.
111
+ */
116
112
  /**
117
113
  * Builds a complete `{ generateText, streamText, decide }` executor set over
118
114
  * the OpenAI Chat Completions wire format via raw `fetch`.
@@ -165,9 +161,9 @@ function createOpenAiCompatExecutors(options) {
165
161
  ...tools.length > 0 ? { tools } : {},
166
162
  ...request.toolChoice ? { tool_choice: toWireToolChoice(request.toolChoice) } : {}
167
163
  };
168
- const structured = require_decision.getAgentOutputMode(request.outputSchema) === "structured";
164
+ const structured = require_events.getAgentOutputMode(request.outputSchema) === "structured";
169
165
  if (structured) {
170
- const jsonSchema = await require_decision.getJsonSchema(require_decision.buildEnvelopeSchema(request.outputSchema, { reasoning: request.reasoning }));
166
+ const jsonSchema = await require_events.getJsonSchema(require_events.buildEnvelopeSchema(request.outputSchema, { reasoning: request.reasoning }));
171
167
  body.response_format = jsonSchema ? {
172
168
  type: "json_schema",
173
169
  json_schema: {
@@ -311,9 +307,3 @@ function errorMessage(error) {
311
307
  }
312
308
  //#endregion
313
309
  exports.createOpenAiCompatExecutors = createOpenAiCompatExecutors;
314
- exports.extractJsonSchema = extractJsonSchema;
315
- exports.toDecisionMessages = toDecisionMessages;
316
- exports.toOpenAiCallSettings = toOpenAiCallSettings;
317
- exports.toOpenAiEventTools = toOpenAiEventTools;
318
- exports.toOpenAiMessages = toOpenAiMessages;
319
- exports.toOpenAiTools = toOpenAiTools;
@@ -1,46 +1,6 @@
1
- import { u as AgentTools } from "./types-C9QiMjre.cjs";
2
- import { H as AgentEventDescriptor, j as AgentDecisionRequest, k as AgentDecisionExecutor, l as AgentTextRequest, s as AgentRequestExecutors } from "./text-logic-CZjyACzQ.cjs";
3
- import { r as getJsonSchema } from "./utils-Dri7aeEG.cjs";
1
+ import { k as AgentDecisionExecutor, s as AgentRequestExecutors } from "./text-logic-Ckhr2kKC.cjs";
4
2
 
5
3
  //#region src/openai-compat/index.d.ts
6
- interface WireMessage {
7
- role: "system" | "user" | "assistant" | "tool";
8
- content: string;
9
- tool_call_id?: string;
10
- }
11
- interface WireTool {
12
- type: "function";
13
- function: {
14
- name: string;
15
- description?: string;
16
- parameters: Record<string, unknown>;
17
- };
18
- }
19
- /**
20
- * Reads a Standard Schema's optional `~standard.jsonSchema.input()` extension
21
- * (implemented by e.g. Zod v4's `z.toJSONSchema`), awaiting it when it returns
22
- * a Promise. Returns `undefined` when the schema doesn't expose the extension.
23
- * Thin re-export of core's {@link getJsonSchema}.
24
- */
25
- declare const extractJsonSchema: typeof getJsonSchema;
26
- /** Maps `AgentTextRequest.messages`/`system`/`prompt` to Chat Completions messages. */
27
- declare function toOpenAiMessages(request: Pick<AgentTextRequest, "system" | "prompt" | "messages">): WireMessage[];
28
- /**
29
- * Maps sampling/stop settings. Targets `max_tokens` (not
30
- * `max_completion_tokens`) — it's the field every OpenAI-compatible backend
31
- * accepts (Ollama, vLLM, Groq, …), where `max_completion_tokens` is
32
- * OpenAI-only. Undefined fields are pruned so they never hit the wire.
33
- */
34
- declare function toOpenAiCallSettings(request: AgentTextRequest): Record<string, unknown>;
35
- /** One wire function tool per `AgentTools` entry. */
36
- declare function toOpenAiTools(tools: AgentTools): WireTool[];
37
- /** One wire function tool per candidate decision event — the
38
- * "tool-per-event + tool_choice: 'required'" recipe. */
39
- declare function toOpenAiEventTools(events: AgentEventDescriptor[]): WireTool[];
40
- /** Messages for a decision request, with prior failed `attempts` rendered as
41
- * appended user messages (via core's {@link renderDecisionAttempts}) so
42
- * retries converge. */
43
- declare function toDecisionMessages(request: Pick<AgentDecisionRequest, "messages" | "prompt" | "events" | "attempts">): WireMessage[];
44
4
  /** Minimal `fetch` shape the adapter needs — matches the global `fetch` and
45
5
  * Cloudflare Workers' `fetch`, so a custom transport is drop-in. */
46
6
  type FetchLike = (input: string, init: {
@@ -76,6 +36,7 @@ interface CreateOpenAiCompatExecutorsOptions {
76
36
  }
77
37
  /** `createOpenAiCompatExecutors` always populates all three executor slots. */
78
38
  interface OpenAiCompatExecutors extends AgentRequestExecutors {
39
+ generateText: NonNullable<AgentRequestExecutors["generateText"]>;
79
40
  streamText: NonNullable<AgentRequestExecutors["streamText"]>;
80
41
  decide: AgentDecisionExecutor;
81
42
  }
@@ -95,4 +56,4 @@ interface OpenAiCompatExecutors extends AgentRequestExecutors {
95
56
  */
96
57
  declare function createOpenAiCompatExecutors(options: CreateOpenAiCompatExecutorsOptions): OpenAiCompatExecutors;
97
58
  //#endregion
98
- export { CreateOpenAiCompatExecutorsOptions, FetchLike, OpenAiCompatExecutors, createOpenAiCompatExecutors, extractJsonSchema, toDecisionMessages, toOpenAiCallSettings, toOpenAiEventTools, toOpenAiMessages, toOpenAiTools };
59
+ export { CreateOpenAiCompatExecutorsOptions, FetchLike, OpenAiCompatExecutors, createOpenAiCompatExecutors };
@@ -1,46 +1,6 @@
1
- import { u as AgentTools } from "./types-qm00QF91.mjs";
2
- import { H as AgentEventDescriptor, j as AgentDecisionRequest, k as AgentDecisionExecutor, l as AgentTextRequest, s as AgentRequestExecutors } from "./text-logic-C7WJpCIc.mjs";
3
- import { r as getJsonSchema } from "./utils-Y6GDRGGE.mjs";
1
+ import { k as AgentDecisionExecutor, s as AgentRequestExecutors } from "./text-logic-CaKqgX4Y.mjs";
4
2
 
5
3
  //#region src/openai-compat/index.d.ts
6
- interface WireMessage {
7
- role: "system" | "user" | "assistant" | "tool";
8
- content: string;
9
- tool_call_id?: string;
10
- }
11
- interface WireTool {
12
- type: "function";
13
- function: {
14
- name: string;
15
- description?: string;
16
- parameters: Record<string, unknown>;
17
- };
18
- }
19
- /**
20
- * Reads a Standard Schema's optional `~standard.jsonSchema.input()` extension
21
- * (implemented by e.g. Zod v4's `z.toJSONSchema`), awaiting it when it returns
22
- * a Promise. Returns `undefined` when the schema doesn't expose the extension.
23
- * Thin re-export of core's {@link getJsonSchema}.
24
- */
25
- declare const extractJsonSchema: typeof getJsonSchema;
26
- /** Maps `AgentTextRequest.messages`/`system`/`prompt` to Chat Completions messages. */
27
- declare function toOpenAiMessages(request: Pick<AgentTextRequest, "system" | "prompt" | "messages">): WireMessage[];
28
- /**
29
- * Maps sampling/stop settings. Targets `max_tokens` (not
30
- * `max_completion_tokens`) — it's the field every OpenAI-compatible backend
31
- * accepts (Ollama, vLLM, Groq, …), where `max_completion_tokens` is
32
- * OpenAI-only. Undefined fields are pruned so they never hit the wire.
33
- */
34
- declare function toOpenAiCallSettings(request: AgentTextRequest): Record<string, unknown>;
35
- /** One wire function tool per `AgentTools` entry. */
36
- declare function toOpenAiTools(tools: AgentTools): WireTool[];
37
- /** One wire function tool per candidate decision event — the
38
- * "tool-per-event + tool_choice: 'required'" recipe. */
39
- declare function toOpenAiEventTools(events: AgentEventDescriptor[]): WireTool[];
40
- /** Messages for a decision request, with prior failed `attempts` rendered as
41
- * appended user messages (via core's {@link renderDecisionAttempts}) so
42
- * retries converge. */
43
- declare function toDecisionMessages(request: Pick<AgentDecisionRequest, "messages" | "prompt" | "events" | "attempts">): WireMessage[];
44
4
  /** Minimal `fetch` shape the adapter needs — matches the global `fetch` and
45
5
  * Cloudflare Workers' `fetch`, so a custom transport is drop-in. */
46
6
  type FetchLike = (input: string, init: {
@@ -76,6 +36,7 @@ interface CreateOpenAiCompatExecutorsOptions {
76
36
  }
77
37
  /** `createOpenAiCompatExecutors` always populates all three executor slots. */
78
38
  interface OpenAiCompatExecutors extends AgentRequestExecutors {
39
+ generateText: NonNullable<AgentRequestExecutors["generateText"]>;
79
40
  streamText: NonNullable<AgentRequestExecutors["streamText"]>;
80
41
  decide: AgentDecisionExecutor;
81
42
  }
@@ -95,4 +56,4 @@ interface OpenAiCompatExecutors extends AgentRequestExecutors {
95
56
  */
96
57
  declare function createOpenAiCompatExecutors(options: CreateOpenAiCompatExecutorsOptions): OpenAiCompatExecutors;
97
58
  //#endregion
98
- export { CreateOpenAiCompatExecutorsOptions, FetchLike, OpenAiCompatExecutors, createOpenAiCompatExecutors, extractJsonSchema, toDecisionMessages, toOpenAiCallSettings, toOpenAiEventTools, toOpenAiMessages, toOpenAiTools };
59
+ export { CreateOpenAiCompatExecutorsOptions, FetchLike, OpenAiCompatExecutors, createOpenAiCompatExecutors };
@@ -1,26 +1,6 @@
1
- import { G as getJsonSchemaSync, J as isStandardSchema, T as getAgentOutputMode, W as getJsonSchema, l as renderDecisionAttempts, x as buildEnvelopeSchema } from "./decision-CQdrKc8k.mjs";
2
- //#region src/openai-compat/index.ts
3
- /**
4
- * OpenAI-compatible Chat Completions adapter — a COMPLETE `{ generateText,
5
- * streamText, decide }` executor set built on raw `fetch`, with zero runtime
6
- * dependencies (no `openai` package, no Vercel AI SDK).
7
- *
8
- * The OpenAI Chat Completions wire format is the lingua franca of hosted and
9
- * local inference: Groq, Together, Fireworks, OpenRouter, vLLM, Ollama, LM
10
- * Studio, and OpenAI itself all speak it. Point `baseUrl` at any of them.
11
- *
12
- * Compare `createAiSdkExecutors` in `../ai-sdk/index.ts` (the AI-SDK-backed
13
- * adapter) — same three-function contract, different transport. The request
14
- * mapping is ported from `examples/openai-sdk-host/index.ts`, but wired
15
- * against `POST {baseUrl}/chat/completions` instead of the `openai` package.
16
- */
17
- /**
18
- * Reads a Standard Schema's optional `~standard.jsonSchema.input()` extension
19
- * (implemented by e.g. Zod v4's `z.toJSONSchema`), awaiting it when it returns
20
- * a Promise. Returns `undefined` when the schema doesn't expose the extension.
21
- * Thin re-export of core's {@link getJsonSchema}.
22
- */
23
- const extractJsonSchema = getJsonSchema;
1
+ import { L as isStandardSchema, N as getJsonSchema, P as getJsonSchemaSync, d as buildEnvelopeSchema, h as getAgentOutputMode } from "./events-JiVPYrct.mjs";
2
+ import { l as renderDecisionAttempts } from "./decision-C3k4ve51.mjs";
3
+ //#region src/openai-compat/mappers.ts
24
4
  /** Maps `AgentTextRequest.messages`/`system`/`prompt` to Chat Completions messages. */
25
5
  function toOpenAiMessages(request) {
26
6
  if (request.messages) return request.messages.flatMap((message) => {
@@ -112,6 +92,22 @@ function toDecisionMessages(request) {
112
92
  function pruneUndefined(record) {
113
93
  return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== void 0));
114
94
  }
95
+ //#endregion
96
+ //#region src/openai-compat/index.ts
97
+ /**
98
+ * OpenAI-compatible Chat Completions adapter — a COMPLETE `{ generateText,
99
+ * streamText, decide }` executor set built on raw `fetch`, with zero runtime
100
+ * dependencies (no `openai` package, no Vercel AI SDK).
101
+ *
102
+ * The OpenAI Chat Completions wire format is the lingua franca of hosted and
103
+ * local inference: Groq, Together, Fireworks, OpenRouter, vLLM, Ollama, LM
104
+ * Studio, and OpenAI itself all speak it. Point `baseUrl` at any of them.
105
+ *
106
+ * Compare `createAiSdkExecutors` in `../ai-sdk/index.ts` (the AI-SDK-backed
107
+ * adapter) — same three-function contract, different transport. The request
108
+ * mapping is ported from `examples/openai-sdk-host/index.ts`, but wired
109
+ * against `POST {baseUrl}/chat/completions` instead of the `openai` package.
110
+ */
115
111
  /**
116
112
  * Builds a complete `{ generateText, streamText, decide }` executor set over
117
113
  * the OpenAI Chat Completions wire format via raw `fetch`.
@@ -309,4 +305,4 @@ function errorMessage(error) {
309
305
  return error instanceof Error ? error.message : String(error);
310
306
  }
311
307
  //#endregion
312
- export { createOpenAiCompatExecutors, extractJsonSchema, toDecisionMessages, toOpenAiCallSettings, toOpenAiEventTools, toOpenAiMessages, toOpenAiTools };
308
+ export { createOpenAiCompatExecutors };
@@ -0,0 +1,198 @@
1
+ import { m as ChosenEvent, u as AgentTools } from "./types-qm00QF91.mjs";
2
+ import { G as AgentRequestOptions, K as AgentRequestSource, M as AgentPlanInput, U as AgentEventDescriptor, c as AgentRequestMode, j as AgentDecisionRequest, l as AgentTextRequest, s as AgentRequestExecutors } from "./text-logic-CaKqgX4Y.mjs";
3
+ import { AnyActorLogic, AnyMachineSnapshot, AnyStateMachine, AsyncActorLogic, EventFromLogic, SnapshotFrom } from "xstate";
4
+
5
+ //#region src/internal/registry.d.ts
6
+ type AgentExecutionOptions = Pick<AgentRequestOptions, "schemas" | "actorSources"> & {
7
+ models?: object;
8
+ };
9
+ //#endregion
10
+ //#region src/steps.d.ts
11
+ /**
12
+ * A pending text request surfaced by step discovery ({@link getAgentRequests}
13
+ * / {@link AgentStep.requests}): the machine has spawned a
14
+ * `TextLogic`-backed invoke and is waiting on its result. Resolve it with
15
+ * {@link executeAgentRequest} (or by hand, then feed the output into
16
+ * {@link resolveAgentStep} via `xstate.done.actor.<id>`).
17
+ */
18
+ interface AgentRequest<TInput extends AgentTextRequest = AgentTextRequest> {
19
+ kind: "text";
20
+ id: string;
21
+ src: AgentRequestSource;
22
+ mode?: AgentRequestMode;
23
+ input: TInput;
24
+ tools: AgentTools;
25
+ events: AgentEventDescriptor[];
26
+ }
27
+ /**
28
+ * A pending **plan** request re-surfaced by step discovery: the machine
29
+ * invoked `agent.plan`, which applies an ordered sequence of legal events
30
+ * (each one a decision) rather than a single one. Unlike text/decision
31
+ * requests — surfaced once and resolved once — a plan request **re-surfaces on
32
+ * every step** while the plan is in flight, its `events`/`applied`/
33
+ * `stepsRemaining` updated each time, until it terminates.
34
+ *
35
+ * All fields are plain serializable data. Resolve ONE decision per step from
36
+ * `events` (via {@link resolveDecision}, wiring `canTake` to
37
+ * `snapshot.can` exactly like a single decision) then apply it: a real machine
38
+ * event advances the plan (the next step re-surfaces this request); the
39
+ * reserved `agent.plan.done` move, a `stopOn` event, an exhausted budget, or no
40
+ * legal events completes it (its invoke resolves with `{ steps, stopped }`).
41
+ * {@link resolveAgentRequests} does all of this natively — one decision (or one
42
+ * completion) per call.
43
+ *
44
+ * The in-progress plan state (`applied` trail + remaining budget) lives in the
45
+ * plan invoke child's own `createLogic` snapshot `context`
46
+ * (`children.<id>.snapshot.context`), so it survives a full JSON
47
+ * `getPersistedSnapshot` → restore round-trip: a host that persists the step
48
+ * after every event and reloads resumes the plan identically.
49
+ */
50
+ interface AgentPlanRequest {
51
+ kind: "plan";
52
+ /** Durable invoke id of the `agent.plan` invoke. */
53
+ id: string;
54
+ /** Invoke src (`'agent.plan'` or a registered plan-logic source name). */
55
+ src: AgentRequestSource;
56
+ /** The resolved plan input (`model`/`system`/`prompt`/`allowedEvents`/`stopOn`/`maxSteps`/…). */
57
+ input: AgentPlanInput;
58
+ /**
59
+ * The legal candidates for the NEXT plan step: the currently
60
+ * snapshot-legal machine events (∩ declared `allowedEvents`) plus the
61
+ * reserved `agent.plan.done` move.
62
+ */
63
+ events: AgentEventDescriptor[];
64
+ /** The events applied so far in this plan, in order (the trail). */
65
+ applied: ChosenEvent[];
66
+ /** How many more events the plan may apply (`maxSteps - applied.length`). */
67
+ stepsRemaining: number;
68
+ }
69
+ /** `AgentStep.requests` element: a text, decision, or plan request. */
70
+ type AgentStepRequest = AgentRequest | AgentDecisionRequest | AgentPlanRequest;
71
+ /**
72
+ * One durable checkpoint on the step path: the machine's current snapshot,
73
+ * the executable actions that produced it, the pending
74
+ * {@link AgentStepRequest}s (text/decision work still to resolve), and
75
+ * whether the machine has reached a final state. This is the
76
+ * per-model-call-checkpoint path for durable hosts (Workflows, Temporal,
77
+ * queues, …) — a peer of `runAgent`, not a lesser version of it. Produced by
78
+ * {@link initialAgentStep}/{@link transitionAgentStep}/{@link resolveAgentStep}.
79
+ */
80
+ interface AgentStep<TSnapshot extends AnyMachineSnapshot = AnyMachineSnapshot> {
81
+ snapshot: TSnapshot;
82
+ actions: readonly {
83
+ type?: string;
84
+ params?: unknown;
85
+ }[];
86
+ requests: AgentStepRequest[];
87
+ done: boolean;
88
+ }
89
+ /**
90
+ * Starts a machine and returns its first {@link AgentStep} — the step-path
91
+ * equivalent of `initialTransition` plus request discovery. Begins the
92
+ * durable/per-model-call-checkpoint loop: resolve each `step.requests` entry
93
+ * (via {@link executeAgentRequest} for `kind: 'text'`, or
94
+ * {@link resolveDecision} for `kind: 'decision'`), then advance with
95
+ * {@link resolveAgentStep} or {@link transitionAgentStep}.
96
+ */
97
+ declare function initialAgentStep<TMachine extends AnyActorLogic>(machine: TMachine, input?: unknown, options?: Partial<AgentExecutionOptions>): AgentStep<SnapshotFrom<TMachine>>;
98
+ /**
99
+ * Applies an externally-sent event (e.g. a decision's chosen event, or a
100
+ * human's reply) and returns the next {@link AgentStep}. Accepts **either**
101
+ * a raw snapshot **or** a prior `AgentStep` as the second argument —
102
+ * `.snapshot` is unwrapped automatically, so callers can thread the whole
103
+ * step object through without manually plucking the snapshot out.
104
+ */
105
+ declare function transitionAgentStep<TMachine extends AnyActorLogic>(machine: TMachine, snapshotOrStep: SnapshotFrom<TMachine> | AgentStep<SnapshotFrom<TMachine>>, event: EventFromLogic<TMachine>, options?: Partial<AgentExecutionOptions>): AgentStep<SnapshotFrom<TMachine>>;
106
+ /**
107
+ * Applies a resolved text request's output (a `kind: 'text'`
108
+ * {@link AgentRequest} — not a decision) as a done event and returns the
109
+ * next {@link AgentStep}. For decisions, resolve with `resolveDecision`
110
+ * (which returns a {@link ChosenEvent}) and apply it with
111
+ * {@link transitionAgentStep} instead — a decision has no output value of
112
+ * its own to feed here.
113
+ */
114
+ declare function resolveAgentStep<TMachine extends AnyActorLogic>(machine: TMachine, step: AgentStep<SnapshotFrom<TMachine>>, request: Pick<AgentRequest, "id"> | string, output: unknown, options?: Partial<AgentExecutionOptions>): AgentStep<SnapshotFrom<TMachine>>;
115
+ /**
116
+ * Snapshot in, requests out: scans executable actions for spawned agent
117
+ * invokes and lowers each into an {@link AgentStepRequest}, pre-filled with
118
+ * the machine's registered `setupAgent` schemas/actorSources (so callers
119
+ * don't pass them by hand each call) — merged with any `options` passed here,
120
+ * which take precedence. The step path's public discovery primitive;
121
+ * `initialAgentStep`/`transitionAgentStep`/`resolveAgentStep` call it
122
+ * internally to populate `AgentStep.requests`.
123
+ */
124
+ declare function getAgentRequests(machine: AnyActorLogic, actions: readonly {
125
+ type?: string;
126
+ params?: unknown;
127
+ }[], snapshot?: AnyMachineSnapshot, options?: Pick<AgentRequestOptions, "eventToolName"> & Partial<AgentExecutionOptions>): AgentStepRequest[];
128
+ /**
129
+ * Resolves one **text** {@link AgentRequest} against a host's
130
+ * {@link AgentRequestExecutors} — merges the request's tools, dispatches to
131
+ * `generateText`/`streamText` per `request.mode`, and validates the result
132
+ * against `request.input.outputSchema` if present. **Text-only**: passing a
133
+ * `kind: 'decision'` request throws, directing the caller to
134
+ * `resolveDecision(request, executors.decide, ...)` instead. By default
135
+ * returns the normalized output; pass `{ verbose: true }` to also get the
136
+ * raw executor result (tool calls, usage, finish reason — needed for
137
+ * observability and event-sourced replay).
138
+ */
139
+ declare function executeAgentRequest(request: AgentRequest, executors: Partial<AgentRequestExecutors>): Promise<unknown>;
140
+ declare function executeAgentRequest(request: AgentRequest, executors: Partial<AgentRequestExecutors>, options: {
141
+ verbose: true;
142
+ }): Promise<{
143
+ output: unknown;
144
+ raw: unknown;
145
+ }>;
146
+ /**
147
+ * Options for {@link resolveAgentRequests}.
148
+ */
149
+ interface ResolveAgentRequestsOptions extends Partial<AgentExecutionOptions> {
150
+ /** Retries per decision, passed to `resolveDecision`. Default `2`. */
151
+ maxRetries?: number;
152
+ }
153
+ /**
154
+ * Resolves the current step's pending requests and returns the next
155
+ * {@link AgentStep} — one iteration of the durable step loop, collapsing the
156
+ * manual `request.kind` dispatch a host would otherwise write by hand.
157
+ *
158
+ * For each pending request, in order: a `kind: 'text'` request is run with
159
+ * {@link executeAgentRequest} then fed back via {@link resolveAgentStep}; a
160
+ * `kind: 'decision'` request is resolved with `resolveDecision` (wiring
161
+ * `canTake` to `step.snapshot.can` so guard-rejected choices retry) then
162
+ * applied with {@link transitionAgentStep}. The **current** step is re-read
163
+ * after each application — the machine may advance and its `requests` change —
164
+ * so this always resolves against the live step, never a stale list.
165
+ *
166
+ * A `kind: 'plan'` request (`agent.plan`) is resolved natively too: one plan
167
+ * step per call. It resolves a single decision from `request.events` (wiring
168
+ * `canTake` to `step.snapshot.can`, exempting the reserved `agent.plan.done`
169
+ * move and `stopOn` events), then either applies the chosen machine event and
170
+ * lets the next step re-surface the plan, or completes the plan (feeding its
171
+ * `{ steps, stopped }` output back) on the done move / a `stopOn` event / an
172
+ * exhausted budget / no legal events. The plan's applied trail is carried in
173
+ * the invoke child's snapshot, so persisting the step between calls resumes the
174
+ * plan identically.
175
+ *
176
+ * Missing the executor a request needs throws a clear error
177
+ * (`generateText`/`streamText` for text, `decide` for decisions and plans).
178
+ *
179
+ * A complete durable host is two lines:
180
+ *
181
+ * ```ts
182
+ * let step = initialAgentStep(machine, input);
183
+ * while (!step.done) step = await resolveAgentRequests(machine, step, executors);
184
+ * ```
185
+ *
186
+ * All pending **text** requests of a step are resolved in parallel
187
+ * (`Promise.all`) — parallel statechart regions are genuinely concurrent, so
188
+ * their model calls run concurrently — then their outputs apply in
189
+ * **request-array order** (deterministic for durable replay regardless of which
190
+ * call finishes first). Decisions and plans stay **one at a time**: applying
191
+ * either changes the set of legal candidates for what follows, so they cannot be
192
+ * resolved against a stale snapshot. A host that instead wants strictly
193
+ * sequential text resolution loops the manual per-request helpers
194
+ * ({@link executeAgentRequest} + {@link resolveAgentStep}) one at a time.
195
+ */
196
+ declare function resolveAgentRequests<TMachine extends AnyActorLogic>(machine: TMachine, step: AgentStep<SnapshotFrom<TMachine>>, executors: Partial<AgentRequestExecutors>, options?: ResolveAgentRequestsOptions): Promise<AgentStep<SnapshotFrom<TMachine>>>;
197
+ //#endregion
198
+ export { ResolveAgentRequestsOptions as a, initialAgentStep as c, transitionAgentStep as d, AgentStepRequest as i, resolveAgentRequests as l, AgentRequest as n, executeAgentRequest as o, AgentStep as r, getAgentRequests as s, AgentPlanRequest as t, resolveAgentStep as u };