@statelyai/agent 1.1.6 → 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 (92) hide show
  1. package/LICENSE +21 -0
  2. package/dist/adapter.cjs +15 -0
  3. package/dist/adapter.d.cts +4 -0
  4. package/dist/adapter.d.mts +4 -0
  5. package/dist/adapter.mjs +2 -0
  6. package/dist/ai-sdk.cjs +306 -0
  7. package/dist/ai-sdk.d.cts +96 -0
  8. package/dist/ai-sdk.d.mts +96 -0
  9. package/dist/ai-sdk.mjs +304 -0
  10. package/dist/decision-C3k4ve51.mjs +227 -0
  11. package/dist/decision-D8wJrM8W.cjs +286 -0
  12. package/dist/events-CRQj3VtP.cjs +1010 -0
  13. package/dist/events-JiVPYrct.mjs +759 -0
  14. package/dist/index.cjs +2528 -0
  15. package/dist/index.d.cts +1232 -0
  16. package/dist/index.d.mts +1217 -413
  17. package/dist/index.mjs +2489 -584
  18. package/dist/openai-compat.cjs +309 -0
  19. package/dist/openai-compat.d.cts +59 -0
  20. package/dist/openai-compat.d.mts +59 -0
  21. package/dist/openai-compat.mjs +308 -0
  22. package/dist/steps-BALp1eZo.d.mts +198 -0
  23. package/dist/steps-CVe54GPP.cjs +420 -0
  24. package/dist/steps-CkyyyuHd.mjs +379 -0
  25. package/dist/steps-MjnQI4aB.d.cts +198 -0
  26. package/dist/steps.cjs +12 -0
  27. package/dist/steps.d.cts +3 -0
  28. package/dist/steps.d.mts +3 -0
  29. package/dist/steps.mjs +3 -0
  30. package/dist/text-logic-CaKqgX4Y.d.mts +710 -0
  31. package/dist/text-logic-Ckhr2kKC.d.cts +710 -0
  32. package/dist/types-C9QiMjre.d.cts +219 -0
  33. package/dist/types-qm00QF91.d.mts +219 -0
  34. package/dist/utils-BYqT_Dyv.d.cts +108 -0
  35. package/dist/utils-Do5wIJrh.d.mts +108 -0
  36. package/dist/zod.cjs +31 -0
  37. package/dist/zod.d.cts +30 -0
  38. package/dist/zod.d.mts +30 -0
  39. package/dist/zod.mjs +30 -0
  40. package/package.json +132 -28
  41. package/readme.md +153 -6
  42. package/schemas/agent-workflow.json +526 -0
  43. package/.changeset/README.md +0 -8
  44. package/.changeset/config.json +0 -11
  45. package/.env.template +0 -3
  46. package/.github/actions/ci-setup/action.yml +0 -24
  47. package/.github/workflows/release.yml +0 -46
  48. package/.vscode/launch.json +0 -28
  49. package/CHANGELOG.md +0 -222
  50. package/dist/index.d.ts +0 -428
  51. package/dist/index.js +0 -621
  52. package/examples/chatbot.ts +0 -71
  53. package/examples/cot.ts +0 -89
  54. package/examples/email.ts +0 -118
  55. package/examples/example.ts +0 -81
  56. package/examples/goal.ts +0 -94
  57. package/examples/helpers/helpers.ts +0 -17
  58. package/examples/helpers/loader.ts +0 -32
  59. package/examples/helpers/runner.ts +0 -27
  60. package/examples/joke.ts +0 -225
  61. package/examples/multi.ts +0 -103
  62. package/examples/newspaper.ts +0 -324
  63. package/examples/number.ts +0 -102
  64. package/examples/raffle.ts +0 -105
  65. package/examples/sandbox.ts +0 -28
  66. package/examples/simple.ts +0 -39
  67. package/examples/support.ts +0 -147
  68. package/examples/ticTacToe.ts +0 -224
  69. package/examples/todo.ts +0 -137
  70. package/examples/tutor.ts +0 -100
  71. package/examples/verify.ts +0 -120
  72. package/examples/weather.ts +0 -178
  73. package/examples/wiki.ts +0 -30
  74. package/examples/word.ts +0 -171
  75. package/src/adapters/vercel.ts +0 -7
  76. package/src/agent-experimental.ts +0 -221
  77. package/src/agent.test.ts +0 -506
  78. package/src/agent.ts +0 -300
  79. package/src/decision.test.ts +0 -179
  80. package/src/decision.ts +0 -84
  81. package/src/index.ts +0 -4
  82. package/src/memory.ts +0 -25
  83. package/src/planners/shortestPathPlanner.ts +0 -22
  84. package/src/planners/simplePlanner.ts +0 -139
  85. package/src/schemas.ts +0 -11
  86. package/src/strategies/chain-of-note.ts +0 -155
  87. package/src/templates/defaultText.ts +0 -18
  88. package/src/text.ts +0 -241
  89. package/src/types.ts +0 -499
  90. package/src/utils.ts +0 -72
  91. package/tsconfig.json +0 -109
  92. package/vitest.config.ts +0 -9
@@ -0,0 +1,1010 @@
1
+ let xstate = require("xstate");
2
+ //#region src/utils.ts
3
+ /**
4
+ * Deep-clones a snapshot to a plain-JSON value via a `JSON` round-trip, the
5
+ * shape you persist and later feed back to `runAgent({ snapshot })`. Asserts
6
+ * JSON-serializability: functions, `undefined`, and other non-JSON values are
7
+ * dropped or throw exactly as `JSON.stringify`/`JSON.parse` would. Returns a
8
+ * plain-JSON deep clone, not a live snapshot.
9
+ */
10
+ function persistSnapshot(snapshot) {
11
+ return JSON.parse(JSON.stringify(snapshot));
12
+ }
13
+ /**
14
+ * Walks a context value and returns the dot-paths of the first few values that
15
+ * would NOT survive a JSON persist/resume round-trip (see {@link persistSnapshot}):
16
+ * `Date`, `Map`, `Set`, `RegExp`, functions, `undefined`, `bigint`, class
17
+ * instances (non-plain objects), and circular references. Plain objects,
18
+ * arrays, and JSON primitives are walked/allowed. Returns `[]` for a
19
+ * fully-JSON-safe value. Cheap and bounded (stops after `limit` findings) —
20
+ * intended for a dev-only warning at the moment persistence matters.
21
+ */
22
+ function findNonSerializableContextPaths(context, limit = 5) {
23
+ const paths = [];
24
+ const seen = /* @__PURE__ */ new WeakSet();
25
+ const walk = (value, path) => {
26
+ if (paths.length >= limit) return;
27
+ if (value === null) return;
28
+ const type = typeof value;
29
+ if (type === "string" || type === "number" || type === "boolean") return;
30
+ if (type === "undefined" || type === "bigint" || type === "function" || type === "symbol") {
31
+ paths.push(`${path} (${type})`);
32
+ return;
33
+ }
34
+ const obj = value;
35
+ if (seen.has(obj)) {
36
+ paths.push(`${path} (circular)`);
37
+ return;
38
+ }
39
+ if (Array.isArray(value)) {
40
+ seen.add(obj);
41
+ value.forEach((item, index) => walk(item, `${path}[${index}]`));
42
+ seen.delete(obj);
43
+ return;
44
+ }
45
+ const proto = Object.getPrototypeOf(value);
46
+ if (proto === Object.prototype || proto === null) {
47
+ seen.add(obj);
48
+ for (const [key, item] of Object.entries(value)) walk(item, `${path}.${key}`);
49
+ seen.delete(obj);
50
+ return;
51
+ }
52
+ const ctorName = value.constructor?.name ?? "object";
53
+ paths.push(`${path} (${ctorName})`);
54
+ };
55
+ walk(context, "context");
56
+ return paths;
57
+ }
58
+ /**
59
+ * A stable, dependency-free structural fingerprint of a machine — a short hex
60
+ * `djb2` hash over its **structural** config only: state ids/nesting, transition
61
+ * event types and targets, invoke `src`s, `initial`, and any other serializable
62
+ * config fields. Function values (context/output builders, prompts, inline
63
+ * guards/actions) are excluded entirely, so two machines that differ only in
64
+ * their prompts or executors hash identically; adding/removing/retargeting a
65
+ * state or transition changes the hash.
66
+ *
67
+ * Used by {@link runAgent} to stamp settled snapshots with a `version` and to
68
+ * detect a structurally-edited machine on resume. It is a change detector, not
69
+ * a cryptographic digest — collisions are possible but unlikely for real
70
+ * configs. Pass an explicit `machineVersion` to `runAgent` to override it.
71
+ */
72
+ function getMachineStructuralHash(machine) {
73
+ return djb2Hex(stableStructuralString(machine.config));
74
+ }
75
+ function stableStructuralString(value, seen = /* @__PURE__ */ new WeakSet()) {
76
+ if (value === null) return "null";
77
+ const type = typeof value;
78
+ if (type === "function" || type === "undefined" || type === "symbol") return "";
79
+ if (type === "string") return JSON.stringify(value);
80
+ if (type === "number" || type === "boolean") return String(value);
81
+ if (type === "bigint") return `${value}n`;
82
+ const obj = value;
83
+ if (seen.has(obj)) return "\"[circular]\"";
84
+ seen.add(obj);
85
+ let out;
86
+ if (Array.isArray(value)) out = `[${value.map((item) => stableStructuralString(item, seen)).join(",")}]`;
87
+ else {
88
+ const parts = [];
89
+ for (const key of Object.keys(obj).sort()) {
90
+ const child = obj[key];
91
+ const childType = typeof child;
92
+ if (childType === "function" || childType === "undefined" || childType === "symbol") continue;
93
+ parts.push(`${JSON.stringify(key)}:${stableStructuralString(child, seen)}`);
94
+ }
95
+ out = `{${parts.join(",")}}`;
96
+ }
97
+ seen.delete(obj);
98
+ return out;
99
+ }
100
+ function djb2Hex(input) {
101
+ let hash = 5381;
102
+ for (let i = 0; i < input.length; i++) hash = (hash << 5) + hash + input.charCodeAt(i) | 0;
103
+ return (hash >>> 0).toString(16).padStart(8, "0");
104
+ }
105
+ /** Builds a {@link UserMessage} from a string or multimodal content parts. */
106
+ function userMessage(content) {
107
+ return {
108
+ role: "user",
109
+ content
110
+ };
111
+ }
112
+ /** Builds an {@link AssistantMessage} from a string or content parts (text, files, tool calls/results). */
113
+ function assistantMessage(content) {
114
+ return {
115
+ role: "assistant",
116
+ content
117
+ };
118
+ }
119
+ /** Builds a {@link SystemMessage}. */
120
+ function systemMessage(content) {
121
+ return {
122
+ role: "system",
123
+ content
124
+ };
125
+ }
126
+ /** Builds a {@link ToolMessage} from one or more tool-result parts. */
127
+ function toolMessage(content) {
128
+ return {
129
+ role: "tool",
130
+ content
131
+ };
132
+ }
133
+ /**
134
+ * Returns the merged `meta` of a snapshot's active state(s) — the typed
135
+ * replacement for the `Object.values(snapshot.getMeta())[0]` dance.
136
+ *
137
+ * `snapshot.getMeta()` is keyed by state id; a leaf machine has one active
138
+ * state, but parallel/nested machines can have several. This shallow-merges
139
+ * every active state's meta into one object (later/deeper entries win) and
140
+ * returns `{}` when no active state declares meta.
141
+ *
142
+ * The return type is recovered from the snapshot's own `getMeta()` type, so a
143
+ * schema-typed machine (`setupAgent({ meta })`) yields the meta schema's
144
+ * output type. Pass an explicit `TMeta` to override when the snapshot is
145
+ * untyped (e.g. `AnyMachineSnapshot`).
146
+ *
147
+ * @example HITL: read the current state's interaction protocol off an idle
148
+ * snapshot to render for a human.
149
+ * ```ts
150
+ * const { interaction } = getStateMeta(result.snapshot);
151
+ * ```
152
+ */
153
+ function getStateMeta(snapshot) {
154
+ return Object.assign({}, ...Object.values(snapshot.getMeta()).filter((meta) => meta != null));
155
+ }
156
+ /**
157
+ * Reads the run-owned message log off a snapshot settled by a `runAgent` call
158
+ * that used `getRequests` (or `options.messages`) — the typed replacement for
159
+ * the `(snapshot as { messages?: AgentMessage[] }).messages` cast. runAgent
160
+ * stamps the log as a plain enumerable `messages` property (like `agentMeta`),
161
+ * so it survives a JSON persist/resume round-trip; this accessor works on the
162
+ * live settled snapshot and on a JSON-parsed persisted one alike. Returns `[]`
163
+ * when no log was stamped (e.g. a default invoke-driven run).
164
+ *
165
+ * The write path is `runAgent(..., { messages })`: an explicit seed that
166
+ * overrides the resume snapshot's stamped log (fold in a user reply on
167
+ * resume, or start a run with prior history).
168
+ */
169
+ function getAgentMessages(snapshot) {
170
+ const stamped = snapshot?.messages;
171
+ return Array.isArray(stamped) ? stamped : [];
172
+ }
173
+ /**
174
+ * Structural guard for a {@link StandardSchemaV1}: `true` when `value` carries
175
+ * the `~standard` marker. Used to tell an already-schema'd tool `inputSchema`
176
+ * (a Zod/Valibot/… schema) apart from an SDK-specific schema wrapper that core
177
+ * can't read directly — see the `ai-sdk` tool pass-through and `openai-compat`
178
+ * tool serialization.
179
+ */
180
+ function isStandardSchema(value) {
181
+ return typeof value === "object" && value !== null && "~standard" in value;
182
+ }
183
+ /**
184
+ * Pulls the JSON Schema off a {@link StandardSchemaV1} via its optional
185
+ * `~standard.jsonSchema.input()` extension (implemented by e.g. Zod v4's
186
+ * `z.toJSONSchema`), awaiting it when the producer is async. Returns
187
+ * `undefined` when the schema doesn't expose the extension. Use this to build
188
+ * a provider request's `response_format`/tool `parameters` from a schema.
189
+ */
190
+ async function getJsonSchema(schema) {
191
+ const jsonSchemaFn = schema?.["~standard"].jsonSchema?.input;
192
+ if (!jsonSchemaFn) return;
193
+ const result = jsonSchemaFn();
194
+ return result instanceof Promise ? await result : result;
195
+ }
196
+ /**
197
+ * Synchronous variant of {@link getJsonSchema}, for call sites that can't
198
+ * await (building tool/event descriptors inline). An async JSON Schema
199
+ * producer is treated as absent (returns `undefined`) — in practice Zod's
200
+ * `z.toJSONSchema` resolves synchronously.
201
+ */
202
+ function getJsonSchemaSync(schema) {
203
+ const jsonSchemaFn = schema?.["~standard"].jsonSchema?.input;
204
+ if (!jsonSchemaFn) return;
205
+ const result = jsonSchemaFn();
206
+ return result instanceof Promise ? void 0 : result;
207
+ }
208
+ /**
209
+ * Validates `value` against a {@link StandardSchemaV1}, synchronously.
210
+ * Throws if the schema's `validate` returns a `Promise` (async validation is
211
+ * not supported anywhere in this library) or if validation reports issues —
212
+ * in which case the thrown `Error.message` joins every issue message with
213
+ * `', '`.
214
+ */
215
+ function validateSchemaSync(schema, value) {
216
+ const result = schema["~standard"].validate(value);
217
+ if (result instanceof Promise) throw new Error("Async schema validation is not supported.");
218
+ if (result.issues) throw new Error(result.issues.map((issue) => issue.message).join(", "));
219
+ return result.value;
220
+ }
221
+ //#endregion
222
+ //#region src/internal/registry.ts
223
+ const agentExecutionOptions = /* @__PURE__ */ new WeakMap();
224
+ /**
225
+ * Machine-carried wait-state predicates, keyed on the machine's root `config`
226
+ * object. `config` is shared by reference across `machine.provide(...)` (unlike
227
+ * the machine object itself), so a predicate registered here travels with the
228
+ * machine through `.provide` — which is why it is keyed on `config`, not the
229
+ * machine. Set by `setupAgent({ isSuspended })` in `createMachine`, read by
230
+ * `runAgent` (below the host `options.isSuspended` override, above the timing
231
+ * heuristic).
232
+ */
233
+ const machineSuspensionPredicates = /* @__PURE__ */ new WeakMap();
234
+ /** Reads the {@link machineSuspensionPredicates} predicate carried by `machine` (via its root `config`), if any. */
235
+ function getMachineSuspensionPredicate(machine) {
236
+ const config = machine.config;
237
+ return config ? machineSuspensionPredicates.get(config) : void 0;
238
+ }
239
+ const unboundPlaceholderLogics = /* @__PURE__ */ new WeakSet();
240
+ /** Text/decision logics created WITH their own executor (withExecutor or the
241
+ * factory's second arg) — these are runnable as-is, so runAgent's bind check
242
+ * must not reject them as direct-object invoke srcs. */
243
+ const executorBoundLogics = /* @__PURE__ */ new WeakSet();
244
+ function missingActor(src) {
245
+ const logic = (0, xstate.createAsyncLogic)({ run: async () => {
246
+ throw new Error(`'${src}' has no host execution. Provide an implementation with machine.provide({ actorSources: { '${src}': ... } }).`);
247
+ } });
248
+ unboundPlaceholderLogics.add(logic);
249
+ return logic;
250
+ }
251
+ function isUnboundPlaceholder(logic) {
252
+ return !!logic && typeof logic === "object" && unboundPlaceholderLogics.has(logic);
253
+ }
254
+ function getRegisteredAgentExecutionOptions(machine, options) {
255
+ return {
256
+ ...agentExecutionOptions.get(machine),
257
+ ...options
258
+ };
259
+ }
260
+ //#endregion
261
+ //#region src/text-logic.ts
262
+ const USER_INPUT_ACTOR = "agent.userInput";
263
+ const GENERATE_TEXT_ACTOR = "agent.generateText";
264
+ const STREAM_TEXT_ACTOR = "agent.streamText";
265
+ const DECIDE_ACTOR = "agent.decide";
266
+ const PLAN_ACTOR = "agent.plan";
267
+ /** Synthetic `src` stamped on trace requests produced by `getRequests` state interpretation — NOT a registered actor source (nothing is invoked; the pass makes the call directly). */
268
+ const INTERPRET_SOURCE = "agent.interpret";
269
+ /**
270
+ * Splits a portable `"provider/model-id"` model ref (the convention JSON
271
+ * workflows and registry-less hosts use, e.g. `"openai/gpt-5.4-mini"`) into
272
+ * its parts. A ref with no `/` has no provider — `modelId` is the whole ref.
273
+ * The standard building block for a host's `resolveModel`:
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * const resolveModel = (ref: string) => openai(parseModelRef(ref).modelId);
278
+ * ```
279
+ */
280
+ function parseModelRef(modelRef) {
281
+ const slash = modelRef.indexOf("/");
282
+ return slash === -1 ? {
283
+ provider: void 0,
284
+ modelId: modelRef
285
+ } : {
286
+ provider: modelRef.slice(0, slash),
287
+ modelId: modelRef.slice(slash + 1)
288
+ };
289
+ }
290
+ const agentTextInputSchema = { "~standard": {
291
+ version: 1,
292
+ vendor: "statelyai-agent",
293
+ validate(value) {
294
+ if (!value || typeof value !== "object") return { issues: [{ message: "Expected agent text input object" }] };
295
+ const request = value;
296
+ if (typeof request.model !== "string") return { issues: [{ message: "Expected agent text input with a string `model`" }] };
297
+ const hasPrompt = typeof request.prompt === "string" && request.prompt.length > 0;
298
+ const hasMessages = Array.isArray(request.messages) && request.messages.length > 0;
299
+ if (!hasPrompt && !hasMessages) return { issues: [{ message: `Agent text request${request.name ? ` '${request.name}'` : ""} has neither a non-empty \`prompt\` nor \`messages\` — provide at least one so the model has something to respond to.` }] };
300
+ return { value: request };
301
+ }
302
+ } };
303
+ const unknownOutputSchema = { "~standard": {
304
+ version: 1,
305
+ vendor: "statelyai-agent",
306
+ validate(value) {
307
+ return { value };
308
+ }
309
+ } };
310
+ const stringOutputSchema = { "~standard": {
311
+ version: 1,
312
+ vendor: "statelyai-agent",
313
+ validate(value) {
314
+ return typeof value === "string" ? { value } : { issues: [{ message: "Expected string output" }] };
315
+ }
316
+ } };
317
+ function createBuiltinTextActor(src, mode, outputSchema) {
318
+ const logic = (0, xstate.createAsyncLogic)({ run: async () => {
319
+ throw new Error(`'${src}' has no host execution. Provide an implementation with machine.provide({ actorSources: { '${src}': ... } }) or execute the returned agent request with executeAgentRequest(...).`);
320
+ } });
321
+ return Object.assign(logic, {
322
+ kind: "statelyai.textLogic",
323
+ mode,
324
+ schemas: {
325
+ input: agentTextInputSchema,
326
+ output: outputSchema
327
+ },
328
+ request(input) {
329
+ return validateSchemaSync(agentTextInputSchema, input);
330
+ },
331
+ async execute(input, executors) {
332
+ const { output } = await executeAgentTextRequest(mode, src, validateSchemaSync(agentTextInputSchema, input), executors);
333
+ return validateSchemaSync(outputSchema, output);
334
+ },
335
+ withExecutor(execute) {
336
+ return Object.assign(createTextLogic({
337
+ mode,
338
+ schemas: {
339
+ input: agentTextInputSchema,
340
+ output: outputSchema
341
+ },
342
+ name: ({ input }) => input.name,
343
+ model: ({ input }) => input.model,
344
+ system: ({ input }) => input.system,
345
+ prompt: ({ input }) => input.prompt,
346
+ messages: ({ input }) => input.messages,
347
+ tools: ({ input }) => input.tools,
348
+ toolChoice: ({ input }) => input.toolChoice,
349
+ reasoning: ({ input }) => input.reasoning,
350
+ temperature: ({ input }) => input.temperature,
351
+ maxOutputTokens: ({ input }) => input.maxOutputTokens,
352
+ topP: ({ input }) => input.topP,
353
+ topK: ({ input }) => input.topK,
354
+ seed: ({ input }) => input.seed,
355
+ stopSequences: ({ input }) => input.stopSequences,
356
+ metadata: ({ input }) => input.metadata
357
+ }, execute));
358
+ }
359
+ });
360
+ }
361
+ /** The unbound `agent.generateText`/`agent.streamText` builtins registered by setupAgent. @internal */
362
+ const builtinTextActors = {
363
+ [GENERATE_TEXT_ACTOR]: createBuiltinTextActor(GENERATE_TEXT_ACTOR, "generate", unknownOutputSchema),
364
+ [STREAM_TEXT_ACTOR]: createBuiltinTextActor(STREAM_TEXT_ACTOR, "stream", stringOutputSchema)
365
+ };
366
+ /** The unbound `agent.userInput` builtin registered by setupAgent (an unbound-placeholder logic — see internal/registry.ts). Output is `string` — what the human typed. @internal */
367
+ const userInputActor = (0, xstate.createAsyncLogic)({ run: async () => {
368
+ throw new Error(`'${USER_INPUT_ACTOR}' has no host execution. Provide an implementation with machine.provide({ actorSources: { '${USER_INPUT_ACTOR}': ... } }).`);
369
+ } });
370
+ unboundPlaceholderLogics.add(userInputActor);
371
+ /**
372
+ * Validates a raw model/executor output against `schema`, returning the
373
+ * parsed value. Thin wrapper over {@link validateSchemaSync} for parsing a
374
+ * text request's structured output outside of `TextLogic.execute`/
375
+ * `executeAgentRequest` (e.g. a custom host loop).
376
+ */
377
+ function parseOutput(schema, output) {
378
+ return validateSchemaSync(schema, output);
379
+ }
380
+ /** Resolves a `ResolveTextLogicValue` (calls it if it's a function, else returns it as-is). @internal */
381
+ function resolveTextLogicValue(value, args) {
382
+ return typeof value === "function" ? value(args) : value;
383
+ }
384
+ /**
385
+ * Creates reusable, standalone {@link TextLogic}: an actor that, when run,
386
+ * resolves typed input to typed output via a model call. Register the
387
+ * result under `actorSources:` and invoke it by name (equivalent to what
388
+ * `setupAgent({ requests })` builds internally for each request entry). Pass
389
+ * `execute` here, or bind it later with `.withExecutor(...)`, a runtime
390
+ * adapter's `machine.provide(...)`, or `runAgent`'s `generateText`/
391
+ * `streamText` options.
392
+ *
393
+ * @example
394
+ * ```ts
395
+ * export const tellJoke = createTextLogic({
396
+ * mode: 'stream',
397
+ * schemas: { input: z.object({ topic: z.string() }), output: z.string() },
398
+ * model: 'openai/gpt-5.4-mini',
399
+ * system: 'You tell short, punchy jokes.',
400
+ * prompt: ({ input }) => `Tell a joke about ${input.topic}.`,
401
+ * });
402
+ * ```
403
+ */
404
+ function createTextLogic(config, execute) {
405
+ const request = (input) => {
406
+ const args = { input: validateSchemaSync(config.schemas.input, input) };
407
+ return {
408
+ name: resolveTextLogicValue(config.name, args),
409
+ model: resolveTextLogicValue(config.model, args),
410
+ system: resolveTextLogicValue(config.system, args),
411
+ prompt: resolveTextLogicValue(config.prompt, args),
412
+ messages: resolveTextLogicValue(config.messages, args),
413
+ tools: resolveTextLogicValue(config.tools, args),
414
+ toolChoice: resolveTextLogicValue(config.toolChoice, args),
415
+ outputSchema: config.schemas.output,
416
+ reasoning: resolveTextLogicValue(config.reasoning, args),
417
+ temperature: resolveTextLogicValue(config.temperature, args),
418
+ maxOutputTokens: resolveTextLogicValue(config.maxOutputTokens, args),
419
+ topP: resolveTextLogicValue(config.topP, args),
420
+ topK: resolveTextLogicValue(config.topK, args),
421
+ seed: resolveTextLogicValue(config.seed, args),
422
+ stopSequences: resolveTextLogicValue(config.stopSequences, args),
423
+ metadata: resolveTextLogicValue(config.metadata, args)
424
+ };
425
+ };
426
+ const logic = (0, xstate.createAsyncLogic)({ run: async ({ input, signal, system, self }, enq) => {
427
+ const resolvedRequest = request(input);
428
+ if (!execute) throw new Error("Text logic has no host execution. Pass an executor as the second argument to createTextLogic(...), provide a runtime adapter, or extract it with getAgentRequests(..., { actorSources }).");
429
+ const result = await execute({
430
+ input,
431
+ request: resolvedRequest,
432
+ signal,
433
+ system,
434
+ self,
435
+ emit: enq.emit
436
+ });
437
+ const selfId = self?.id;
438
+ const output = await normalizeGeneratorResult(result, typeof selfId === "string" ? selfId : "text logic", { request: resolvedRequest });
439
+ return validateSchemaSync(config.schemas.output, output);
440
+ } });
441
+ const textLogic = Object.assign(logic, {
442
+ kind: "statelyai.textLogic",
443
+ mode: config.mode ?? "generate",
444
+ schemas: config.schemas,
445
+ request,
446
+ async execute(input, executors) {
447
+ const { output } = await executeAgentTextRequest(config.mode ?? "generate", "textLogic", request(input), executors);
448
+ return validateSchemaSync(config.schemas.output, output);
449
+ },
450
+ withExecutor(nextExecute) {
451
+ return createTextLogic(config, nextExecute);
452
+ }
453
+ });
454
+ if (execute) executorBoundLogics.add(textLogic);
455
+ return textLogic;
456
+ }
457
+ /**
458
+ * Binds a child machine's {@link TextLogic} to a raw
459
+ * {@link AgentRequestExecutor} (the `generateText`/`streamText` shape hosts
460
+ * implement). Encapsulates the `withExecutor` idiom child agents repeat:
461
+ * default the request's `tools` to `{}`, forward the actor `signal`, call the
462
+ * executor, and return its `{ output }` envelope. Use this to share ONE
463
+ * executor across a parent and its nested children.
464
+ *
465
+ * @example
466
+ * ```ts
467
+ * childMachine.provide({
468
+ * actorSources: {
469
+ * researchTopic: bindRequestExecutor(setup.requests.researchTopic, generateText),
470
+ * },
471
+ * });
472
+ * ```
473
+ */
474
+ function bindRequestExecutor(logic, executor, info) {
475
+ return logic.withExecutor(async ({ request, signal }) => {
476
+ const { output } = await executor({
477
+ ...request,
478
+ tools: request.tools ?? {}
479
+ }, {
480
+ signal,
481
+ onChunk: info?.onChunk
482
+ });
483
+ return { output };
484
+ });
485
+ }
486
+ /** Type guard: true for any actor logic built by createTextLogic (checks the `kind` marker). @internal */
487
+ function isTextLogic(value) {
488
+ return !!value && typeof value === "object" && value.kind === "statelyai.textLogic" && typeof value.request === "function";
489
+ }
490
+ /**
491
+ * Classifies a text request's output schema as `'structured'` (its JSON
492
+ * Schema is `type: 'object'`, `type: 'array'`, or a top-level union/
493
+ * composition — `anyOf`/`oneOf`/`allOf`, which a bare `z.union`/
494
+ * `z.discriminatedUnion` emits with no top-level `type`) or `'text'`
495
+ * (anything else, including no schema). Reads the schema's
496
+ * `~standard.jsonSchema.input()` extension — schemas without it are treated
497
+ * as `'text'`.
498
+ */
499
+ function getAgentOutputMode(schema) {
500
+ const jsonSchema = getStandardSchemaJson(schema);
501
+ if (!jsonSchema) return "text";
502
+ if (jsonSchema.type === "object" || jsonSchema.type === "array") return "structured";
503
+ if (jsonSchema.type === void 0 && ("anyOf" in jsonSchema || "oneOf" in jsonSchema || "allOf" in jsonSchema)) return "structured";
504
+ return "text";
505
+ }
506
+ /** True when {@link getAgentOutputMode} classifies `schema` as `'structured'`. */
507
+ function isStructuredOutputSchema(schema) {
508
+ return getAgentOutputMode(schema) === "structured";
509
+ }
510
+ /**
511
+ * Builds the uniform structured-output envelope schema every structured request
512
+ * is sent to the provider as: a root object `{ result: <inner> }`, plus — when
513
+ * `options.reasoning` is `true` — an optional string `reasoning` property listed
514
+ * BEFORE `result` (property order nudges the model to reason first). This is THE
515
+ * wire contract for structured output: a root object is universally accepted as
516
+ * a provider response schema, unlike a bare union/array root that many providers
517
+ * reject.
518
+ *
519
+ * The returned {@link StandardSchemaV1} validates the `{ reasoning?, result }`
520
+ * envelope (unwrapping `result` through the original schema, capturing a string
521
+ * `reasoning` when present) and exposes the enveloped JSON Schema. Adapters read
522
+ * `.result` off the provider output before the machine validates it — so this is
523
+ * transparent: user-facing output types stay the declared (un-enveloped) schema,
524
+ * and `reasoning` is surfaced only on the raw executor result, never in machine
525
+ * context/output.
526
+ */
527
+ function buildEnvelopeSchema(inner, options = {}) {
528
+ const includeReasoning = options.reasoning === true;
529
+ const buildJson = (innerJson) => ({
530
+ type: "object",
531
+ properties: {
532
+ ...includeReasoning ? { reasoning: { type: "string" } } : {},
533
+ result: innerJson ?? {}
534
+ },
535
+ required: ["result"],
536
+ additionalProperties: false
537
+ });
538
+ return { "~standard": {
539
+ version: 1,
540
+ vendor: "statelyai-agent",
541
+ validate(value) {
542
+ if (!value || typeof value !== "object" || !("result" in value)) return { issues: [{ message: "Expected a { result } envelope object" }] };
543
+ const innerResult = inner["~standard"].validate(value.result);
544
+ if (innerResult instanceof Promise) throw new Error("Async schema validation is not supported.");
545
+ if (innerResult.issues) return innerResult;
546
+ const envelope = { result: innerResult.value };
547
+ const reasoning = value.reasoning;
548
+ if (typeof reasoning === "string") envelope.reasoning = reasoning;
549
+ return { value: envelope };
550
+ },
551
+ jsonSchema: { input: () => {
552
+ const innerJson = inner["~standard"].jsonSchema?.input?.();
553
+ return innerJson instanceof Promise ? innerJson.then(buildJson) : buildJson(innerJson);
554
+ } }
555
+ } };
556
+ }
557
+ /**
558
+ * Validates a raw provider value against the structured-output envelope for
559
+ * `request` and returns the unwrapped `{ result, reasoning? }` — the checked
560
+ * replacement for `raw as StructuredOutputEnvelope` in hand-written hosts.
561
+ * Pair with {@link buildEnvelopeSchema} (which produced the schema the
562
+ * provider was asked to satisfy).
563
+ */
564
+ function parseStructuredEnvelope(request, value) {
565
+ if (!request.outputSchema) throw new Error("parseStructuredEnvelope: the request declares no outputSchema.");
566
+ return validateSchemaSync(buildEnvelopeSchema(request.outputSchema, { reasoning: request.reasoning }), value);
567
+ }
568
+ function getStandardSchemaJson(schema) {
569
+ const jsonSchema = (schema?.["~standard"])?.jsonSchema?.input?.();
570
+ return jsonSchema && !(jsonSchema instanceof Promise) ? jsonSchema : void 0;
571
+ }
572
+ /**
573
+ * Merges request-declared and call-site `tools`, dispatches to the
574
+ * `mode`-appropriate executor (`generateText`/`streamText`), and normalizes
575
+ * the raw result via {@link normalizeGeneratorResult}. Shared by
576
+ * `TextLogic.execute`, `executeAgentRequest`, and the `agent.generateText`/
577
+ * `agent.streamText` builtins. Throws if no executor is registered for
578
+ * `mode`.
579
+ *
580
+ * @internal
581
+ */
582
+ async function executeAgentTextRequest(mode, id, input, executors, tools = {}, info) {
583
+ const request = {
584
+ ...input,
585
+ tools: {
586
+ ...input.tools,
587
+ ...tools
588
+ }
589
+ };
590
+ const executor = mode === "stream" ? executors.streamText : executors.generateText;
591
+ if (!executor) throw new Error(`No executor provided for ${mode === "stream" ? "stream" : "generate"} request '${id}'.`);
592
+ const raw = await executor(request, info);
593
+ return {
594
+ output: await normalizeGeneratorResult(raw, id, {
595
+ request,
596
+ onChunk: info?.onChunk
597
+ }),
598
+ raw
599
+ };
600
+ }
601
+ function hasTextStream(value) {
602
+ return "textStream" in value && typeof value.textStream === "object" && !!value.textStream?.[Symbol.asyncIterator];
603
+ }
604
+ function parseRawAiSdkText(text, request, id) {
605
+ if (!request?.outputSchema) return text;
606
+ let parsed = text;
607
+ try {
608
+ parsed = JSON.parse(text);
609
+ } catch {}
610
+ try {
611
+ return parseOutput(request.outputSchema, parsed);
612
+ } catch (error) {
613
+ throw new Error(`Executor for '${id}' returned a raw AI SDK result whose text could not be parsed against the request's outputSchema. Structured-output requests through raw AI SDK generateText/streamText functions are best-effort — for reliable structured output, use createAiSdkExecutors from '@statelyai/agent/ai-sdk'. Cause: ${error instanceof Error ? error.message : String(error)}`);
614
+ }
615
+ }
616
+ /**
617
+ * Unwraps an executor result into the request's final output. Accepts three
618
+ * shapes:
619
+ * - `{ output }` (the {@link AgentRequestExecutorResult} envelope) — awaits and
620
+ * returns `output` (the fast path; unchanged).
621
+ * - a raw AI SDK `streamText` result (`{ textStream }` async iterable) — iterates
622
+ * `textStream`, forwarding each string chunk to `info.onChunk`, then resolves
623
+ * the final text from `await result.text` if present else the accumulated chunks.
624
+ * - a raw AI SDK `generateText` result (`{ text }` string or promise) — awaits `text`.
625
+ *
626
+ * For the two raw AI SDK shapes, if `info.request?.outputSchema` is set the final
627
+ * text is parsed through {@link parseOutput} (best-effort); a parse failure throws
628
+ * an error recommending `createAiSdkExecutors` from '@statelyai/agent/ai-sdk'.
629
+ *
630
+ * A value matching none of these is a runtime error naming `id`. This is
631
+ * generator-result unwrapping only — decision results are extracted separately
632
+ * by `resolveDecision`.
633
+ *
634
+ * @internal
635
+ */
636
+ async function normalizeGeneratorResult(result, id = "text request", info) {
637
+ const resolved = await result;
638
+ if (!resolved || typeof resolved !== "object") throw invalidGeneratorResult(id);
639
+ if ("output" in resolved) return await resolved.output;
640
+ if (hasTextStream(resolved)) {
641
+ let accumulated = "";
642
+ for await (const chunk of resolved.textStream) {
643
+ accumulated += chunk;
644
+ info?.onChunk?.(chunk);
645
+ }
646
+ const finalText = "text" in resolved && resolved.text !== void 0 ? await resolved.text : accumulated;
647
+ return parseRawAiSdkText(String(finalText), info?.request, id);
648
+ }
649
+ if ("text" in resolved) {
650
+ const finalText = await resolved.text;
651
+ return parseRawAiSdkText(String(finalText), info?.request, id);
652
+ }
653
+ throw invalidGeneratorResult(id);
654
+ }
655
+ function invalidGeneratorResult(id) {
656
+ return /* @__PURE__ */ new Error(`Executor for '${id}' returned an invalid result: executors must return { output } (an envelope with the text string or structured object as \`output\`, plus optional passthrough fields). Raw Vercel AI SDK generateText/streamText results ({ text } or { textStream }) are also accepted.`);
657
+ }
658
+ //#endregion
659
+ //#region src/events.ts
660
+ /** Default prefix for the synthetic tool name generated per candidate event (e.g. `send_event_ASK`). Override per-request with {@link AgentEventToolNameResolver}. @internal */
661
+ const EVENT_TOOL_PREFIX = "send_event_";
662
+ function hashString(value) {
663
+ let hash = 5381;
664
+ for (let i = 0; i < value.length; i++) hash = hash * 33 ^ value.charCodeAt(i);
665
+ return (hash >>> 0).toString(36);
666
+ }
667
+ function sanitizeEventToolName(eventType) {
668
+ const base = `${EVENT_TOOL_PREFIX}${eventType.replace(/[^a-zA-Z0-9_-]/g, "_") || "event"}`;
669
+ if (base.length <= 64) return base;
670
+ const hash = hashString(eventType);
671
+ const prefixLength = 64 - hash.length - 1;
672
+ return `${base.slice(0, prefixLength)}_${hash}`;
673
+ }
674
+ function disambiguateEventToolName(toolName, eventType, usedToolNames) {
675
+ if (!usedToolNames.has(toolName)) {
676
+ usedToolNames.add(toolName);
677
+ return toolName;
678
+ }
679
+ const suffix = `_${hashString(eventType)}`;
680
+ const uniqueToolName = `${toolName.slice(0, 64 - suffix.length)}${suffix}`;
681
+ usedToolNames.add(uniqueToolName);
682
+ return uniqueToolName;
683
+ }
684
+ /**
685
+ * True when an event type matches an `allowedEvents` entry: an exact type,
686
+ * `'*'` (every event), or a `'prefix.*'` wildcard matching any deeper
687
+ * segment (`'todo.*'` matches `'todo.add'` and `'todo.list.clear'`, not
688
+ * `'todo'` itself — mirroring xstate's partial wildcard events).
689
+ */
690
+ function matchesEventPattern(eventType, pattern) {
691
+ if (pattern === "*") return true;
692
+ if (pattern.endsWith(".*")) return eventType.startsWith(`${pattern.slice(0, -1)}`);
693
+ return eventType === pattern;
694
+ }
695
+ /** True when an `allowedEvents` entry is a wildcard pattern rather than a concrete event type. @internal */
696
+ function isEventPattern(entry) {
697
+ return entry === "*" || entry.endsWith(".*");
698
+ }
699
+ /**
700
+ * Runtime-validates a dynamically-built `{ type, ...payload }` event against a
701
+ * snapshot's currently-accepted events (via {@link getAcceptedEvents}) and,
702
+ * when one is registered, the event type's payload schema — returning the
703
+ * event typed as the machine's event union (recovered from the snapshot type)
704
+ * so it can be sent to `runAgent({ event })` / `actor.send(...)` without an
705
+ * `as never` cast. For generic, meta-driven hosts that assemble events from
706
+ * user input or a wire message.
707
+ *
708
+ * Throws a descriptive error when `event.type` is not currently accepted
709
+ * (listing the accepted types) or when its payload fails the registered schema.
710
+ * Pass event payload schemas via `options.events`/`options.schemas` (the same
711
+ * shape {@link getAcceptedEvents} takes) — the accepted TYPES always come from
712
+ * the live snapshot; the schemas only add payload validation.
713
+ *
714
+ * @example
715
+ * ```ts
716
+ * const event = parseAgentEvent(result.snapshot, rawEvent, { events: schemas.events });
717
+ * result = await runAgent(machine, { snapshot: result.snapshot, event, executors });
718
+ * ```
719
+ */
720
+ function parseAgentEvent(snapshot, event, options = {}) {
721
+ const accepted = getAcceptedEvents(snapshot, options);
722
+ const descriptor = accepted.find((candidate) => candidate.type === event.type);
723
+ if (!descriptor) throw new Error(`parseAgentEvent: '${event.type}' is not an accepted event in the current state. Accepted: ${accepted.map((candidate) => candidate.type).join(", ") || "(none)"}.`);
724
+ if (descriptor.inputSchema) {
725
+ const { type, ...payload } = event;
726
+ try {
727
+ return {
728
+ ...validateSchemaSync(descriptor.inputSchema, payload),
729
+ type
730
+ };
731
+ } catch (error) {
732
+ throw new Error(`parseAgentEvent: '${event.type}' payload failed validation: ${error instanceof Error ? error.message : String(error)}`);
733
+ }
734
+ }
735
+ return event;
736
+ }
737
+ function getAcceptedEvents(snapshot, options = {}) {
738
+ const eventTypes = options.eventTypes;
739
+ const seen = /* @__PURE__ */ new Set();
740
+ const usedToolNames = /* @__PURE__ */ new Set();
741
+ return (0, xstate.getNextTransitions)(snapshot).flatMap((transitionDefinition) => {
742
+ const eventType = transitionDefinition.eventType;
743
+ if (!eventType || eventType === "*" || eventType.startsWith("xstate.") || eventTypes && !eventTypes.some((pattern) => matchesEventPattern(eventType, pattern)) || seen.has(eventType)) return [];
744
+ seen.add(eventType);
745
+ const defaultToolName = sanitizeEventToolName(eventType);
746
+ const toolName = options.eventToolName ? options.eventToolName({
747
+ eventType,
748
+ defaultToolName
749
+ }) : disambiguateEventToolName(defaultToolName, eventType, usedToolNames);
750
+ const inputSchema = (options.events ?? options.schemas?.events)?.[eventType];
751
+ return [{
752
+ type: eventType,
753
+ toolName,
754
+ ...inputSchema ? { inputSchema } : {}
755
+ }];
756
+ });
757
+ }
758
+ //#endregion
759
+ Object.defineProperty(exports, "DECIDE_ACTOR", {
760
+ enumerable: true,
761
+ get: function() {
762
+ return DECIDE_ACTOR;
763
+ }
764
+ });
765
+ Object.defineProperty(exports, "INTERPRET_SOURCE", {
766
+ enumerable: true,
767
+ get: function() {
768
+ return INTERPRET_SOURCE;
769
+ }
770
+ });
771
+ Object.defineProperty(exports, "PLAN_ACTOR", {
772
+ enumerable: true,
773
+ get: function() {
774
+ return PLAN_ACTOR;
775
+ }
776
+ });
777
+ Object.defineProperty(exports, "USER_INPUT_ACTOR", {
778
+ enumerable: true,
779
+ get: function() {
780
+ return USER_INPUT_ACTOR;
781
+ }
782
+ });
783
+ Object.defineProperty(exports, "agentExecutionOptions", {
784
+ enumerable: true,
785
+ get: function() {
786
+ return agentExecutionOptions;
787
+ }
788
+ });
789
+ Object.defineProperty(exports, "assistantMessage", {
790
+ enumerable: true,
791
+ get: function() {
792
+ return assistantMessage;
793
+ }
794
+ });
795
+ Object.defineProperty(exports, "bindRequestExecutor", {
796
+ enumerable: true,
797
+ get: function() {
798
+ return bindRequestExecutor;
799
+ }
800
+ });
801
+ Object.defineProperty(exports, "buildEnvelopeSchema", {
802
+ enumerable: true,
803
+ get: function() {
804
+ return buildEnvelopeSchema;
805
+ }
806
+ });
807
+ Object.defineProperty(exports, "builtinTextActors", {
808
+ enumerable: true,
809
+ get: function() {
810
+ return builtinTextActors;
811
+ }
812
+ });
813
+ Object.defineProperty(exports, "createTextLogic", {
814
+ enumerable: true,
815
+ get: function() {
816
+ return createTextLogic;
817
+ }
818
+ });
819
+ Object.defineProperty(exports, "executeAgentTextRequest", {
820
+ enumerable: true,
821
+ get: function() {
822
+ return executeAgentTextRequest;
823
+ }
824
+ });
825
+ Object.defineProperty(exports, "executorBoundLogics", {
826
+ enumerable: true,
827
+ get: function() {
828
+ return executorBoundLogics;
829
+ }
830
+ });
831
+ Object.defineProperty(exports, "findNonSerializableContextPaths", {
832
+ enumerable: true,
833
+ get: function() {
834
+ return findNonSerializableContextPaths;
835
+ }
836
+ });
837
+ Object.defineProperty(exports, "getAcceptedEvents", {
838
+ enumerable: true,
839
+ get: function() {
840
+ return getAcceptedEvents;
841
+ }
842
+ });
843
+ Object.defineProperty(exports, "getAgentMessages", {
844
+ enumerable: true,
845
+ get: function() {
846
+ return getAgentMessages;
847
+ }
848
+ });
849
+ Object.defineProperty(exports, "getAgentOutputMode", {
850
+ enumerable: true,
851
+ get: function() {
852
+ return getAgentOutputMode;
853
+ }
854
+ });
855
+ Object.defineProperty(exports, "getJsonSchema", {
856
+ enumerable: true,
857
+ get: function() {
858
+ return getJsonSchema;
859
+ }
860
+ });
861
+ Object.defineProperty(exports, "getJsonSchemaSync", {
862
+ enumerable: true,
863
+ get: function() {
864
+ return getJsonSchemaSync;
865
+ }
866
+ });
867
+ Object.defineProperty(exports, "getMachineStructuralHash", {
868
+ enumerable: true,
869
+ get: function() {
870
+ return getMachineStructuralHash;
871
+ }
872
+ });
873
+ Object.defineProperty(exports, "getMachineSuspensionPredicate", {
874
+ enumerable: true,
875
+ get: function() {
876
+ return getMachineSuspensionPredicate;
877
+ }
878
+ });
879
+ Object.defineProperty(exports, "getRegisteredAgentExecutionOptions", {
880
+ enumerable: true,
881
+ get: function() {
882
+ return getRegisteredAgentExecutionOptions;
883
+ }
884
+ });
885
+ Object.defineProperty(exports, "getStateMeta", {
886
+ enumerable: true,
887
+ get: function() {
888
+ return getStateMeta;
889
+ }
890
+ });
891
+ Object.defineProperty(exports, "isEventPattern", {
892
+ enumerable: true,
893
+ get: function() {
894
+ return isEventPattern;
895
+ }
896
+ });
897
+ Object.defineProperty(exports, "isStandardSchema", {
898
+ enumerable: true,
899
+ get: function() {
900
+ return isStandardSchema;
901
+ }
902
+ });
903
+ Object.defineProperty(exports, "isStructuredOutputSchema", {
904
+ enumerable: true,
905
+ get: function() {
906
+ return isStructuredOutputSchema;
907
+ }
908
+ });
909
+ Object.defineProperty(exports, "isTextLogic", {
910
+ enumerable: true,
911
+ get: function() {
912
+ return isTextLogic;
913
+ }
914
+ });
915
+ Object.defineProperty(exports, "isUnboundPlaceholder", {
916
+ enumerable: true,
917
+ get: function() {
918
+ return isUnboundPlaceholder;
919
+ }
920
+ });
921
+ Object.defineProperty(exports, "machineSuspensionPredicates", {
922
+ enumerable: true,
923
+ get: function() {
924
+ return machineSuspensionPredicates;
925
+ }
926
+ });
927
+ Object.defineProperty(exports, "matchesEventPattern", {
928
+ enumerable: true,
929
+ get: function() {
930
+ return matchesEventPattern;
931
+ }
932
+ });
933
+ Object.defineProperty(exports, "missingActor", {
934
+ enumerable: true,
935
+ get: function() {
936
+ return missingActor;
937
+ }
938
+ });
939
+ Object.defineProperty(exports, "normalizeGeneratorResult", {
940
+ enumerable: true,
941
+ get: function() {
942
+ return normalizeGeneratorResult;
943
+ }
944
+ });
945
+ Object.defineProperty(exports, "parseAgentEvent", {
946
+ enumerable: true,
947
+ get: function() {
948
+ return parseAgentEvent;
949
+ }
950
+ });
951
+ Object.defineProperty(exports, "parseModelRef", {
952
+ enumerable: true,
953
+ get: function() {
954
+ return parseModelRef;
955
+ }
956
+ });
957
+ Object.defineProperty(exports, "parseOutput", {
958
+ enumerable: true,
959
+ get: function() {
960
+ return parseOutput;
961
+ }
962
+ });
963
+ Object.defineProperty(exports, "parseStructuredEnvelope", {
964
+ enumerable: true,
965
+ get: function() {
966
+ return parseStructuredEnvelope;
967
+ }
968
+ });
969
+ Object.defineProperty(exports, "persistSnapshot", {
970
+ enumerable: true,
971
+ get: function() {
972
+ return persistSnapshot;
973
+ }
974
+ });
975
+ Object.defineProperty(exports, "sanitizeEventToolName", {
976
+ enumerable: true,
977
+ get: function() {
978
+ return sanitizeEventToolName;
979
+ }
980
+ });
981
+ Object.defineProperty(exports, "systemMessage", {
982
+ enumerable: true,
983
+ get: function() {
984
+ return systemMessage;
985
+ }
986
+ });
987
+ Object.defineProperty(exports, "toolMessage", {
988
+ enumerable: true,
989
+ get: function() {
990
+ return toolMessage;
991
+ }
992
+ });
993
+ Object.defineProperty(exports, "userInputActor", {
994
+ enumerable: true,
995
+ get: function() {
996
+ return userInputActor;
997
+ }
998
+ });
999
+ Object.defineProperty(exports, "userMessage", {
1000
+ enumerable: true,
1001
+ get: function() {
1002
+ return userMessage;
1003
+ }
1004
+ });
1005
+ Object.defineProperty(exports, "validateSchemaSync", {
1006
+ enumerable: true,
1007
+ get: function() {
1008
+ return validateSchemaSync;
1009
+ }
1010
+ });