@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License Copyright (c) 2025 Stately Software, Inc.
2
+
3
+ Permission is hereby granted,
4
+ free of charge, to any person obtaining a copy of this software and associated
5
+ documentation files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use, copy, modify, merge,
7
+ publish, distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice
12
+ (including the next paragraph) shall be included in all copies or substantial
13
+ portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
18
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_events = require("./events-CRQj3VtP.cjs");
3
+ exports.bindRequestExecutor = require_events.bindRequestExecutor;
4
+ exports.buildEnvelopeSchema = require_events.buildEnvelopeSchema;
5
+ exports.getAgentOutputMode = require_events.getAgentOutputMode;
6
+ exports.getJsonSchema = require_events.getJsonSchema;
7
+ exports.getJsonSchemaSync = require_events.getJsonSchemaSync;
8
+ exports.getMachineStructuralHash = require_events.getMachineStructuralHash;
9
+ exports.isStandardSchema = require_events.isStandardSchema;
10
+ exports.isStructuredOutputSchema = require_events.isStructuredOutputSchema;
11
+ exports.matchesEventPattern = require_events.matchesEventPattern;
12
+ exports.parseModelRef = require_events.parseModelRef;
13
+ exports.parseOutput = require_events.parseOutput;
14
+ exports.parseStructuredEnvelope = require_events.parseStructuredEnvelope;
15
+ exports.validateSchemaSync = require_events.validateSchemaSync;
@@ -0,0 +1,4 @@
1
+ import { C as StandardSchemaV1 } from "./types-C9QiMjre.cjs";
2
+ import { D as parseOutput, E as parseModelRef, J as matchesEventPattern, O as parseStructuredEnvelope, S as buildEnvelopeSchema, T as isStructuredOutputSchema, a as AgentRequestExecutorInfo, h as TextLogic, i as AgentRequestExecutor, l as AgentTextRequest, m as StructuredOutputEnvelope, o as AgentRequestExecutorResult, r as AgentOutputMode, w as getAgentOutputMode, x as bindRequestExecutor } from "./text-logic-Ckhr2kKC.cjs";
3
+ import { a as getMachineStructuralHash, f as validateSchemaSync, i as getJsonSchemaSync, r as getJsonSchema, s as isStandardSchema } from "./utils-BYqT_Dyv.cjs";
4
+ export { type AgentOutputMode, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentTextRequest, type StandardSchemaV1, type StructuredOutputEnvelope, type TextLogic, bindRequestExecutor, buildEnvelopeSchema, getAgentOutputMode, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, isStandardSchema, isStructuredOutputSchema, matchesEventPattern, parseModelRef, parseOutput, parseStructuredEnvelope, validateSchemaSync };
@@ -0,0 +1,4 @@
1
+ import { C as StandardSchemaV1 } from "./types-qm00QF91.mjs";
2
+ import { D as parseOutput, E as parseModelRef, J as matchesEventPattern, O as parseStructuredEnvelope, S as buildEnvelopeSchema, T as isStructuredOutputSchema, a as AgentRequestExecutorInfo, h as TextLogic, i as AgentRequestExecutor, l as AgentTextRequest, m as StructuredOutputEnvelope, o as AgentRequestExecutorResult, r as AgentOutputMode, w as getAgentOutputMode, x as bindRequestExecutor } from "./text-logic-CaKqgX4Y.mjs";
3
+ import { a as getMachineStructuralHash, f as validateSchemaSync, i as getJsonSchemaSync, r as getJsonSchema, s as isStandardSchema } from "./utils-Do5wIJrh.mjs";
4
+ export { type AgentOutputMode, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentTextRequest, type StandardSchemaV1, type StructuredOutputEnvelope, type TextLogic, bindRequestExecutor, buildEnvelopeSchema, getAgentOutputMode, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, isStandardSchema, isStructuredOutputSchema, matchesEventPattern, parseModelRef, parseOutput, parseStructuredEnvelope, validateSchemaSync };
@@ -0,0 +1,2 @@
1
+ import { F as getMachineStructuralHash, H as validateSchemaSync, L as isStandardSchema, N as getJsonSchema, P as getJsonSchemaSync, b as parseOutput, d as buildEnvelopeSchema, g as isStructuredOutputSchema, h as getAgentOutputMode, r as matchesEventPattern, u as bindRequestExecutor, x as parseStructuredEnvelope, y as parseModelRef } from "./events-JiVPYrct.mjs";
2
+ export { bindRequestExecutor, buildEnvelopeSchema, getAgentOutputMode, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, isStandardSchema, isStructuredOutputSchema, matchesEventPattern, parseModelRef, parseOutput, parseStructuredEnvelope, validateSchemaSync };
@@ -0,0 +1,306 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_events = require("./events-CRQj3VtP.cjs");
3
+ const require_decision = require("./decision-D8wJrM8W.cjs");
4
+ let ai = require("ai");
5
+ //#region src/ai-sdk/mappers.ts
6
+ /**
7
+ * Maps an {@link AgentTools} map onto AI SDK `tool()` definitions. A tool that
8
+ * already carries its own Standard Schema `inputSchema` — an AI SDK
9
+ * `tool({...})`, or any equivalent descriptor — is passed through **unchanged**,
10
+ * so the SDK applies its own validation, calls `execute(input, options)`, and
11
+ * every extra property (`providerOptions`, `toModelOutput`, …) survives. A bare
12
+ * `AgentToolExecute` function becomes a tool with an unconstrained input schema;
13
+ * a minimal descriptor with no readable schema is converted with a permissive
14
+ * fallback. Used by {@link toAiSdkCallSettings}.
15
+ */
16
+ function toAiSdkTools(tools) {
17
+ const entries = [];
18
+ for (const [name, descriptor] of Object.entries(tools)) {
19
+ if (!descriptor) continue;
20
+ if (typeof descriptor === "function") {
21
+ entries.push([name, (0, ai.tool)({
22
+ inputSchema: unknownSchema,
23
+ execute: (input) => descriptor(input)
24
+ })]);
25
+ continue;
26
+ }
27
+ if (require_events.isStandardSchema(descriptor.inputSchema)) {
28
+ entries.push([name, descriptor]);
29
+ continue;
30
+ }
31
+ const inputSchema = descriptor.inputSchema ?? descriptor.schemas?.input;
32
+ const toolOptions = {
33
+ description: descriptor.description,
34
+ inputSchema: inputSchema ? inputSchema : unknownSchema
35
+ };
36
+ if (descriptor.execute) {
37
+ entries.push([name, (0, ai.tool)({
38
+ ...toolOptions,
39
+ execute: (input) => descriptor.execute?.(input)
40
+ })]);
41
+ continue;
42
+ }
43
+ entries.push([name, (0, ai.tool)(toolOptions)]);
44
+ }
45
+ return Object.fromEntries(entries);
46
+ }
47
+ const unknownSchema = { "~standard": {
48
+ version: 1,
49
+ vendor: "statelyai-agent",
50
+ validate: (value) => ({ value }),
51
+ jsonSchema: { input: () => ({}) }
52
+ } };
53
+ /**
54
+ * AI SDK request-mapping settings shared by `generateText`/`streamText`.
55
+ * `AgentTextRequest.messages` (`AgentMessage[]`) and AI SDK's `ModelMessage[]`
56
+ * are structurally compatible by design (§1 of .scratch/p0-design.md) — the cast
57
+ * below is a typed identity mapping, not a semantic conversion.
58
+ */
59
+ function toAiSdkCallSettings(request) {
60
+ const messages = request.messages;
61
+ return {
62
+ system: request.system,
63
+ ...messages ? { messages } : { prompt: request.prompt ?? "" },
64
+ temperature: request.temperature,
65
+ maxOutputTokens: request.maxOutputTokens,
66
+ topP: request.topP,
67
+ topK: request.topK,
68
+ seed: request.seed,
69
+ stopSequences: request.stopSequences,
70
+ tools: request.tools ? toAiSdkTools(request.tools) : void 0,
71
+ toolChoice: toAiSdkToolChoice(request.toolChoice)
72
+ };
73
+ }
74
+ /** Maps an {@link AgentToolChoice} to AI SDK's tool-choice shape — `{ type: 'tool'; name }` becomes `{ type: 'tool'; toolName }`; `'auto'`/`'none'`/`'required'`/`undefined` pass through unchanged. */
75
+ function toAiSdkToolChoice(toolChoice) {
76
+ return typeof toolChoice === "object" ? {
77
+ type: "tool",
78
+ toolName: toolChoice.name
79
+ } : toolChoice;
80
+ }
81
+ /** `true` when the request should use AI SDK structured `Output.object`. */
82
+ function isStructuredOutputRequest(request) {
83
+ return require_events.getAgentOutputMode(request.outputSchema) === "structured";
84
+ }
85
+ /**
86
+ * Extracts the first complete top-level JSON value from `text`, or returns
87
+ * `undefined` when there is nothing to repair (no complete value, or the value
88
+ * already spans the whole text). Models occasionally emit two structured-output
89
+ * envelopes back to back (`{"result":{…}}{"result":{…}}`), which fails JSON
90
+ * parsing wholesale; the balanced scan below recovers the first value and
91
+ * drops the rest.
92
+ */
93
+ function extractFirstJsonValue(text) {
94
+ const start = text.search(/[{[]/);
95
+ if (start === -1) return;
96
+ let depth = 0;
97
+ let inString = false;
98
+ let escaped = false;
99
+ for (let i = start; i < text.length; i++) {
100
+ const char = text[i];
101
+ if (inString) {
102
+ if (escaped) escaped = false;
103
+ else if (char === "\\") escaped = true;
104
+ else if (char === "\"") inString = false;
105
+ continue;
106
+ }
107
+ if (char === "\"") inString = true;
108
+ else if (char === "{" || char === "[") depth++;
109
+ else if (char === "}" || char === "]") {
110
+ depth--;
111
+ if (depth === 0) {
112
+ const value = text.slice(start, i + 1);
113
+ return value === text.trim() ? void 0 : value;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ /** One AI SDK `tool()` per candidate event — the "tool-per-event +
119
+ * toolChoice: 'required'" recipe from .scratch/p0-design.md §2.6. */
120
+ function toAiSdkEventTools(events) {
121
+ return Object.fromEntries(events.map((event) => [event.toolName, (0, ai.tool)({
122
+ description: `Choose the '${event.type}' move.`,
123
+ inputSchema: event.inputSchema ? event.inputSchema : unknownSchema
124
+ })]));
125
+ }
126
+ /**
127
+ * Messages for a decision request, with prior failed `attempts` (§2.6)
128
+ * rendered as appended user messages (via core's {@link renderDecisionAttempts})
129
+ * so retries converge. Core never rewrites prompts — this is adapter business.
130
+ */
131
+ function toDecisionMessages(request) {
132
+ if (!request.messages && request.attempts.length === 0) return;
133
+ const messages = [...request.messages ?? (request.prompt !== void 0 ? [{
134
+ role: "user",
135
+ content: request.prompt
136
+ }] : [])];
137
+ for (const attempt of require_decision.renderDecisionAttempts(request)) messages.push({
138
+ role: "user",
139
+ content: attempt.content
140
+ });
141
+ return messages;
142
+ }
143
+ //#endregion
144
+ //#region src/ai-sdk/index.ts
145
+ function maxStepsSetting(request) {
146
+ return typeof request.metadata?.maxSteps === "number" ? { stopWhen: (0, ai.stepCountIs)(request.metadata.maxSteps) } : {};
147
+ }
148
+ /**
149
+ * Identity helper for a `models` map whose value is exported. Returns the map
150
+ * unchanged, but types it as {@link AiSdkModelMap}`<keyof T & string>` — a
151
+ * portable, nameable type — so an exported `const models = defineModels({...})`
152
+ * needs no `Record<'a' | 'b', LanguageModel>` annotation and never triggers
153
+ * TS2742 ("inferred type cannot be named without a reference to …"). The exact
154
+ * ref keys survive, so `createAiSdkExecutors({ models })` and
155
+ * `setupAgent({ models })` still infer/autocomplete them.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * export const models = defineModels({
160
+ * quick: openai('gpt-5.4-mini'),
161
+ * deep: openai('gpt-5.4'),
162
+ * });
163
+ * // typeof models === AiSdkModelMap<'quick' | 'deep'>
164
+ * ```
165
+ */
166
+ function defineModels(models) {
167
+ return models;
168
+ }
169
+ function resolveAiSdkModel(options, modelRef) {
170
+ if (options.resolveModel) return options.resolveModel(modelRef);
171
+ const models = options.models;
172
+ if (!models) throw new Error(`createAiSdkExecutors: no model resolver configured for '${modelRef}'.`);
173
+ const model = models[modelRef];
174
+ if (!model) throw new Error(`createAiSdkExecutors: unknown model '${modelRef}'.`);
175
+ return model;
176
+ }
177
+ function withJsonRepair(output) {
178
+ return {
179
+ ...output,
180
+ parseCompleteOutput: async (options, context) => {
181
+ try {
182
+ return await output.parseCompleteOutput(options, context);
183
+ } catch (error) {
184
+ const repaired = extractFirstJsonValue(options.text);
185
+ if (repaired === void 0) throw error;
186
+ return await output.parseCompleteOutput({
187
+ ...options,
188
+ text: repaired
189
+ }, context);
190
+ }
191
+ }
192
+ };
193
+ }
194
+ /**
195
+ * The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
196
+ * decide }` executor set consumed by `runAgent`/`executeAgentRequest`. `ai`
197
+ * must not become a dependency of core `src/` files — this subpath is the one
198
+ * place it's imported, and callers must supply their own model resolver so no
199
+ * concrete provider package (e.g. `@ai-sdk/openai`) becomes a dependency here
200
+ * either.
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * const executors = createAiSdkExecutors({ models: { quick: openai('gpt-5.4-mini') } });
205
+ * const result = await runAgent(machine, { input, executors });
206
+ * ```
207
+ */
208
+ function createAiSdkExecutors(options) {
209
+ const generateText = async (request, info) => {
210
+ const common = {
211
+ model: resolveAiSdkModel(options, request.model),
212
+ abortSignal: info?.signal,
213
+ ...toAiSdkCallSettings(request),
214
+ ...maxStepsSetting(request)
215
+ };
216
+ if (isStructuredOutputRequest(request)) {
217
+ const envelope = require_events.buildEnvelopeSchema(request.outputSchema, { reasoning: request.reasoning });
218
+ const structuredOutput = withJsonRepair(ai.Output.object({ schema: envelope }));
219
+ const canRetry = !request.tools || Object.keys(request.tools).length === 0;
220
+ let result;
221
+ try {
222
+ result = await (0, ai.generateText)({
223
+ ...common,
224
+ output: structuredOutput
225
+ });
226
+ } catch (error) {
227
+ if (!canRetry || !ai.NoObjectGeneratedError.isInstance(error) || info?.signal?.aborted) throw error;
228
+ result = await (0, ai.generateText)({
229
+ ...common,
230
+ output: structuredOutput
231
+ });
232
+ }
233
+ const { result: output, reasoning } = result.output;
234
+ return {
235
+ output,
236
+ ...reasoning !== void 0 ? { reasoning } : {},
237
+ usage: result.usage,
238
+ finishReason: result.finishReason,
239
+ toolCalls: result.toolCalls,
240
+ toolResults: result.toolResults
241
+ };
242
+ }
243
+ const result = await (0, ai.generateText)(common);
244
+ return {
245
+ output: result.text,
246
+ usage: result.usage,
247
+ finishReason: result.finishReason,
248
+ toolCalls: result.toolCalls,
249
+ toolResults: result.toolResults
250
+ };
251
+ };
252
+ const streamText = async (request, info) => {
253
+ const result = (0, ai.streamText)({
254
+ model: resolveAiSdkModel(options, request.model),
255
+ abortSignal: info?.signal,
256
+ ...toAiSdkCallSettings(request),
257
+ ...maxStepsSetting(request)
258
+ });
259
+ for await (const chunk of result.textStream) info?.onChunk?.(chunk);
260
+ return {
261
+ output: await result.text,
262
+ usage: await result.usage,
263
+ finishReason: await result.finishReason
264
+ };
265
+ };
266
+ const decide = async (request) => {
267
+ const model = resolveAiSdkModel(options, request.model);
268
+ const tools = toAiSdkEventTools(request.events);
269
+ const messages = toDecisionMessages(request);
270
+ const result = await (0, ai.generateText)({
271
+ model,
272
+ abortSignal: request.signal,
273
+ system: request.system,
274
+ ...messages ? { messages } : { prompt: request.prompt ?? "" },
275
+ tools,
276
+ toolChoice: "required",
277
+ stopWhen: (0, ai.stepCountIs)(1),
278
+ temperature: request.temperature,
279
+ maxOutputTokens: request.maxOutputTokens,
280
+ topP: request.topP,
281
+ topK: request.topK,
282
+ seed: request.seed,
283
+ stopSequences: request.stopSequences
284
+ });
285
+ const toolCall = result.toolCalls[0];
286
+ if (!toolCall) throw new Error("createAiSdkExecutors: decide — model did not call an event tool.");
287
+ const chosenEvent = request.events.find((event) => event.toolName === toolCall.toolName);
288
+ if (!chosenEvent) throw new Error(`createAiSdkExecutors: decide — model called unknown tool '${toolCall.toolName}'.`);
289
+ return {
290
+ event: {
291
+ ...toolCall.input && typeof toolCall.input === "object" ? toolCall.input : {},
292
+ type: chosenEvent.type
293
+ },
294
+ usage: result.usage,
295
+ finishReason: result.finishReason
296
+ };
297
+ };
298
+ return {
299
+ generateText,
300
+ streamText,
301
+ decide
302
+ };
303
+ }
304
+ //#endregion
305
+ exports.createAiSdkExecutors = createAiSdkExecutors;
306
+ exports.defineModels = defineModels;
@@ -0,0 +1,96 @@
1
+ import { m as ChosenEvent } from "./types-C9QiMjre.cjs";
2
+ import { i as AgentRequestExecutor, k as AgentDecisionExecutor, s as AgentRequestExecutors } from "./text-logic-Ckhr2kKC.cjs";
3
+ import { FinishReason, LanguageModel, LanguageModelUsage, ToolSet, TypedToolCall, TypedToolResult } from "ai";
4
+
5
+ //#region src/ai-sdk/index.d.ts
6
+ /** AI SDK model registry: maps model refs (as used in `setupAgent({ models })`/`AgentTextRequest.model`) to AI SDK `LanguageModel` values. The optional `TKey` parameter pins the ref keys (see {@link defineModels}); it defaults to `string`, so bare `AiSdkModelMap` stays `Record<string, LanguageModel>`. */
7
+ type AiSdkModelMap<TKey extends string = string> = Record<TKey, LanguageModel>;
8
+ /**
9
+ * Identity helper for a `models` map whose value is exported. Returns the map
10
+ * unchanged, but types it as {@link AiSdkModelMap}`<keyof T & string>` — a
11
+ * portable, nameable type — so an exported `const models = defineModels({...})`
12
+ * needs no `Record<'a' | 'b', LanguageModel>` annotation and never triggers
13
+ * TS2742 ("inferred type cannot be named without a reference to …"). The exact
14
+ * ref keys survive, so `createAiSdkExecutors({ models })` and
15
+ * `setupAgent({ models })` still infer/autocomplete them.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * export const models = defineModels({
20
+ * quick: openai('gpt-5.4-mini'),
21
+ * deep: openai('gpt-5.4'),
22
+ * });
23
+ * // typeof models === AiSdkModelMap<'quick' | 'deep'>
24
+ * ```
25
+ */
26
+ declare function defineModels<T extends Record<string, LanguageModel>>(models: T): AiSdkModelMap<keyof T & string>;
27
+ /**
28
+ * Options for {@link createAiSdkExecutors}: either a static `models` map
29
+ * (model refs resolved by lookup), a `resolveModel` function (refs resolved
30
+ * dynamically, e.g. `"openai/gpt-5.4-mini"` → `openai('gpt-5.4-mini')`), or
31
+ * both — `resolveModel` takes precedence when both are supplied.
32
+ */
33
+ type CreateAiSdkExecutorsOptions<TModels extends AiSdkModelMap = AiSdkModelMap> = {
34
+ models: TModels;
35
+ resolveModel?: (modelRef: keyof TModels & string) => LanguageModel;
36
+ } | {
37
+ models?: TModels;
38
+ resolveModel: (modelRef: string) => LanguageModel;
39
+ };
40
+ /**
41
+ * Raw result shape from {@link AiSdkExecutors.generateText} — the `{ output }`
42
+ * envelope (the validated structured object for structured-output requests,
43
+ * or the accumulated text string otherwise; unwrapped by
44
+ * `normalizeGeneratorResult`) plus the AI SDK call metadata. Core only reads
45
+ * `output`; everything else flows verbatim to `runAgent`'s
46
+ * `onResult(request, { raw })`, so `raw as AiSdkGenerateResult` is the
47
+ * supported cast for token accounting and tracing.
48
+ */
49
+ type AiSdkGenerateResult = {
50
+ output: unknown;
51
+ /** The model's reasoning, present only when the request opted in via
52
+ * `reasoning: true` and the model produced it (see the structured-output
53
+ * envelope in {@link buildEnvelopeSchema}). Never enters machine context/output. */
54
+ reasoning?: string;
55
+ usage: LanguageModelUsage;
56
+ finishReason: FinishReason;
57
+ toolCalls: TypedToolCall<ToolSet>[];
58
+ toolResults: TypedToolResult<ToolSet>[];
59
+ };
60
+ /** Raw result shape from {@link AiSdkExecutors.streamText} — the `{ output }` envelope carrying the fully-accumulated text once the stream finishes (chunks are delivered separately via `onChunk`), plus the stream's final usage/finish metadata for `onResult`. */
61
+ type AiSdkStreamResult = {
62
+ output: string;
63
+ usage: LanguageModelUsage;
64
+ finishReason: FinishReason;
65
+ };
66
+ /** Raw result shape from {@link AiSdkExecutors.decide} — the chosen event plus the AI SDK call metadata, delivered per decision attempt to `onResult`. */
67
+ type AiSdkDecideResult = {
68
+ event: ChosenEvent;
69
+ usage: LanguageModelUsage;
70
+ finishReason: FinishReason;
71
+ };
72
+ /** `createAiSdkExecutors` always populates all three slots (unlike the
73
+ * general `AgentRequestExecutors`, where `streamText`/`decide` are optional),
74
+ * and its `generateText`/`streamText` results are concretely typed. */
75
+ interface AiSdkExecutors extends AgentRequestExecutors<AiSdkGenerateResult, AiSdkStreamResult> {
76
+ generateText: AgentRequestExecutor<AiSdkGenerateResult>;
77
+ streamText: AgentRequestExecutor<AiSdkStreamResult>;
78
+ decide: AgentDecisionExecutor;
79
+ }
80
+ /**
81
+ * The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
82
+ * decide }` executor set consumed by `runAgent`/`executeAgentRequest`. `ai`
83
+ * must not become a dependency of core `src/` files — this subpath is the one
84
+ * place it's imported, and callers must supply their own model resolver so no
85
+ * concrete provider package (e.g. `@ai-sdk/openai`) becomes a dependency here
86
+ * either.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const executors = createAiSdkExecutors({ models: { quick: openai('gpt-5.4-mini') } });
91
+ * const result = await runAgent(machine, { input, executors });
92
+ * ```
93
+ */
94
+ declare function createAiSdkExecutors<TModels extends AiSdkModelMap>(options: CreateAiSdkExecutorsOptions<TModels>): AiSdkExecutors;
95
+ //#endregion
96
+ export { AiSdkDecideResult, AiSdkExecutors, AiSdkGenerateResult, AiSdkModelMap, AiSdkStreamResult, CreateAiSdkExecutorsOptions, createAiSdkExecutors, defineModels };
@@ -0,0 +1,96 @@
1
+ import { m as ChosenEvent } from "./types-qm00QF91.mjs";
2
+ import { i as AgentRequestExecutor, k as AgentDecisionExecutor, s as AgentRequestExecutors } from "./text-logic-CaKqgX4Y.mjs";
3
+ import { FinishReason, LanguageModel, LanguageModelUsage, ToolSet, TypedToolCall, TypedToolResult } from "ai";
4
+
5
+ //#region src/ai-sdk/index.d.ts
6
+ /** AI SDK model registry: maps model refs (as used in `setupAgent({ models })`/`AgentTextRequest.model`) to AI SDK `LanguageModel` values. The optional `TKey` parameter pins the ref keys (see {@link defineModels}); it defaults to `string`, so bare `AiSdkModelMap` stays `Record<string, LanguageModel>`. */
7
+ type AiSdkModelMap<TKey extends string = string> = Record<TKey, LanguageModel>;
8
+ /**
9
+ * Identity helper for a `models` map whose value is exported. Returns the map
10
+ * unchanged, but types it as {@link AiSdkModelMap}`<keyof T & string>` — a
11
+ * portable, nameable type — so an exported `const models = defineModels({...})`
12
+ * needs no `Record<'a' | 'b', LanguageModel>` annotation and never triggers
13
+ * TS2742 ("inferred type cannot be named without a reference to …"). The exact
14
+ * ref keys survive, so `createAiSdkExecutors({ models })` and
15
+ * `setupAgent({ models })` still infer/autocomplete them.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * export const models = defineModels({
20
+ * quick: openai('gpt-5.4-mini'),
21
+ * deep: openai('gpt-5.4'),
22
+ * });
23
+ * // typeof models === AiSdkModelMap<'quick' | 'deep'>
24
+ * ```
25
+ */
26
+ declare function defineModels<T extends Record<string, LanguageModel>>(models: T): AiSdkModelMap<keyof T & string>;
27
+ /**
28
+ * Options for {@link createAiSdkExecutors}: either a static `models` map
29
+ * (model refs resolved by lookup), a `resolveModel` function (refs resolved
30
+ * dynamically, e.g. `"openai/gpt-5.4-mini"` → `openai('gpt-5.4-mini')`), or
31
+ * both — `resolveModel` takes precedence when both are supplied.
32
+ */
33
+ type CreateAiSdkExecutorsOptions<TModels extends AiSdkModelMap = AiSdkModelMap> = {
34
+ models: TModels;
35
+ resolveModel?: (modelRef: keyof TModels & string) => LanguageModel;
36
+ } | {
37
+ models?: TModels;
38
+ resolveModel: (modelRef: string) => LanguageModel;
39
+ };
40
+ /**
41
+ * Raw result shape from {@link AiSdkExecutors.generateText} — the `{ output }`
42
+ * envelope (the validated structured object for structured-output requests,
43
+ * or the accumulated text string otherwise; unwrapped by
44
+ * `normalizeGeneratorResult`) plus the AI SDK call metadata. Core only reads
45
+ * `output`; everything else flows verbatim to `runAgent`'s
46
+ * `onResult(request, { raw })`, so `raw as AiSdkGenerateResult` is the
47
+ * supported cast for token accounting and tracing.
48
+ */
49
+ type AiSdkGenerateResult = {
50
+ output: unknown;
51
+ /** The model's reasoning, present only when the request opted in via
52
+ * `reasoning: true` and the model produced it (see the structured-output
53
+ * envelope in {@link buildEnvelopeSchema}). Never enters machine context/output. */
54
+ reasoning?: string;
55
+ usage: LanguageModelUsage;
56
+ finishReason: FinishReason;
57
+ toolCalls: TypedToolCall<ToolSet>[];
58
+ toolResults: TypedToolResult<ToolSet>[];
59
+ };
60
+ /** Raw result shape from {@link AiSdkExecutors.streamText} — the `{ output }` envelope carrying the fully-accumulated text once the stream finishes (chunks are delivered separately via `onChunk`), plus the stream's final usage/finish metadata for `onResult`. */
61
+ type AiSdkStreamResult = {
62
+ output: string;
63
+ usage: LanguageModelUsage;
64
+ finishReason: FinishReason;
65
+ };
66
+ /** Raw result shape from {@link AiSdkExecutors.decide} — the chosen event plus the AI SDK call metadata, delivered per decision attempt to `onResult`. */
67
+ type AiSdkDecideResult = {
68
+ event: ChosenEvent;
69
+ usage: LanguageModelUsage;
70
+ finishReason: FinishReason;
71
+ };
72
+ /** `createAiSdkExecutors` always populates all three slots (unlike the
73
+ * general `AgentRequestExecutors`, where `streamText`/`decide` are optional),
74
+ * and its `generateText`/`streamText` results are concretely typed. */
75
+ interface AiSdkExecutors extends AgentRequestExecutors<AiSdkGenerateResult, AiSdkStreamResult> {
76
+ generateText: AgentRequestExecutor<AiSdkGenerateResult>;
77
+ streamText: AgentRequestExecutor<AiSdkStreamResult>;
78
+ decide: AgentDecisionExecutor;
79
+ }
80
+ /**
81
+ * The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
82
+ * decide }` executor set consumed by `runAgent`/`executeAgentRequest`. `ai`
83
+ * must not become a dependency of core `src/` files — this subpath is the one
84
+ * place it's imported, and callers must supply their own model resolver so no
85
+ * concrete provider package (e.g. `@ai-sdk/openai`) becomes a dependency here
86
+ * either.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const executors = createAiSdkExecutors({ models: { quick: openai('gpt-5.4-mini') } });
91
+ * const result = await runAgent(machine, { input, executors });
92
+ * ```
93
+ */
94
+ declare function createAiSdkExecutors<TModels extends AiSdkModelMap>(options: CreateAiSdkExecutorsOptions<TModels>): AiSdkExecutors;
95
+ //#endregion
96
+ export { AiSdkDecideResult, AiSdkExecutors, AiSdkGenerateResult, AiSdkModelMap, AiSdkStreamResult, CreateAiSdkExecutorsOptions, createAiSdkExecutors, defineModels };