@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
@@ -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 };
package/dist/ai-sdk.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_run_agent = require("./run-agent-BFMkuI1F.cjs");
3
- const require_decision = require("./decision-b-lkcs4L.cjs");
2
+ const require_events = require("./events-CRQj3VtP.cjs");
3
+ const require_decision = require("./decision-D8wJrM8W.cjs");
4
4
  let ai = require("ai");
5
- //#region src/ai-sdk/index.ts
5
+ //#region src/ai-sdk/mappers.ts
6
6
  /**
7
7
  * Maps an {@link AgentTools} map onto AI SDK `tool()` definitions. A tool that
8
8
  * already carries its own Standard Schema `inputSchema` — an AI SDK
@@ -11,8 +11,7 @@ let ai = require("ai");
11
11
  * every extra property (`providerOptions`, `toModelOutput`, …) survives. A bare
12
12
  * `AgentToolExecute` function becomes a tool with an unconstrained input schema;
13
13
  * a minimal descriptor with no readable schema is converted with a permissive
14
- * fallback. Used internally by {@link toAiSdkCallSettings}; exported for callers
15
- * building AI SDK calls by hand outside `createAiSdkExecutors`.
14
+ * fallback. Used by {@link toAiSdkCallSettings}.
16
15
  */
17
16
  function toAiSdkTools(tools) {
18
17
  const entries = [];
@@ -25,7 +24,7 @@ function toAiSdkTools(tools) {
25
24
  })]);
26
25
  continue;
27
26
  }
28
- if (require_decision.isStandardSchema(descriptor.inputSchema)) {
27
+ if (require_events.isStandardSchema(descriptor.inputSchema)) {
29
28
  entries.push([name, descriptor]);
30
29
  continue;
31
30
  }
@@ -45,9 +44,6 @@ function toAiSdkTools(tools) {
45
44
  }
46
45
  return Object.fromEntries(entries);
47
46
  }
48
- function maxStepsSetting(request) {
49
- return typeof request.metadata?.maxSteps === "number" ? { stopWhen: (0, ai.stepCountIs)(request.metadata.maxSteps) } : {};
50
- }
51
47
  const unknownSchema = { "~standard": {
52
48
  version: 1,
53
49
  vendor: "statelyai-agent",
@@ -55,35 +51,6 @@ const unknownSchema = { "~standard": {
55
51
  jsonSchema: { input: () => ({}) }
56
52
  } };
57
53
  /**
58
- * Identity helper for a `models` map whose value is exported. Returns the map
59
- * unchanged, but types it as {@link AiSdkModelMap}`<keyof T & string>` — a
60
- * portable, nameable type — so an exported `const models = defineModels({...})`
61
- * needs no `Record<'a' | 'b', LanguageModel>` annotation and never triggers
62
- * TS2742 ("inferred type cannot be named without a reference to …"). The exact
63
- * ref keys survive, so `createAiSdkExecutors({ models })` and
64
- * `setupAgent({ models })` still infer/autocomplete them.
65
- *
66
- * @example
67
- * ```ts
68
- * export const models = defineModels({
69
- * quick: openai('gpt-5.4-mini'),
70
- * deep: openai('gpt-5.4'),
71
- * });
72
- * // typeof models === AiSdkModelMap<'quick' | 'deep'>
73
- * ```
74
- */
75
- function defineModels(models) {
76
- return models;
77
- }
78
- function resolveAiSdkModel(options, modelRef) {
79
- if (options.resolveModel) return options.resolveModel(modelRef);
80
- const models = options.models;
81
- if (!models) throw new Error(`createAiSdkExecutors: no model resolver configured for '${modelRef}'.`);
82
- const model = models[modelRef];
83
- if (!model) throw new Error(`createAiSdkExecutors: unknown model '${modelRef}'.`);
84
- return model;
85
- }
86
- /**
87
54
  * AI SDK request-mapping settings shared by `generateText`/`streamText`.
88
55
  * `AgentTextRequest.messages` (`AgentMessage[]`) and AI SDK's `ModelMessage[]`
89
56
  * are structurally compatible by design (§1 of .scratch/p0-design.md) — the cast
@@ -113,7 +80,7 @@ function toAiSdkToolChoice(toolChoice) {
113
80
  }
114
81
  /** `true` when the request should use AI SDK structured `Output.object`. */
115
82
  function isStructuredOutputRequest(request) {
116
- return require_decision.getAgentOutputMode(request.outputSchema) === "structured";
83
+ return require_events.getAgentOutputMode(request.outputSchema) === "structured";
117
84
  }
118
85
  /**
119
86
  * Extracts the first complete top-level JSON value from `text`, or returns
@@ -148,6 +115,65 @@ function extractFirstJsonValue(text) {
148
115
  }
149
116
  }
150
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
+ }
151
177
  function withJsonRepair(output) {
152
178
  return {
153
179
  ...output,
@@ -188,7 +214,7 @@ function createAiSdkExecutors(options) {
188
214
  ...maxStepsSetting(request)
189
215
  };
190
216
  if (isStructuredOutputRequest(request)) {
191
- const envelope = require_decision.buildEnvelopeSchema(request.outputSchema, { reasoning: request.reasoning });
217
+ const envelope = require_events.buildEnvelopeSchema(request.outputSchema, { reasoning: request.reasoning });
192
218
  const structuredOutput = withJsonRepair(ai.Output.object({ schema: envelope }));
193
219
  const canRetry = !request.tools || Object.keys(request.tools).length === 0;
194
220
  let result;
@@ -275,68 +301,6 @@ function createAiSdkExecutors(options) {
275
301
  decide
276
302
  };
277
303
  }
278
- /** AI SDK host for a machine authored with `setupAgent({ models })`. */
279
- function runAgent(machine, options) {
280
- const models = require_decision.getRegisteredAgentModels(machine);
281
- if (!models || Object.keys(models).length === 0) throw new Error("AI SDK runAgent: machine has no models. Pass `models` to setupAgent, or use core runAgent with explicit executors.");
282
- return require_run_agent.runAgent(machine, {
283
- ...options,
284
- executors: createAiSdkExecutors({ models })
285
- });
286
- }
287
- function createAgent(config) {
288
- const { model, models: configuredModels, schemas, ...machineConfig } = config;
289
- const models = configuredModels ?? { default: model };
290
- const executors = createAiSdkExecutors({ models });
291
- const machine = require_run_agent.setupAgent({
292
- ...schemas,
293
- models
294
- }).createMachine(machineConfig);
295
- return {
296
- machine,
297
- run(runInput, options = {}) {
298
- return require_run_agent.runAgent(machine, {
299
- ...options,
300
- input: runInput,
301
- executors
302
- });
303
- }
304
- };
305
- }
306
- /** One AI SDK `tool()` per candidate event — the "tool-per-event +
307
- * toolChoice: 'required'" recipe from .scratch/p0-design.md §2.6. */
308
- function toAiSdkEventTools(events) {
309
- return Object.fromEntries(events.map((event) => [event.toolName, (0, ai.tool)({
310
- description: `Choose the '${event.type}' move.`,
311
- inputSchema: event.inputSchema ? event.inputSchema : unknownSchema
312
- })]));
313
- }
314
- /**
315
- * Messages for a decision request, with prior failed `attempts` (§2.6)
316
- * rendered as appended user messages (via core's {@link renderDecisionAttempts})
317
- * so retries converge. Core never rewrites prompts — this is adapter business.
318
- */
319
- function toDecisionMessages(request) {
320
- if (!request.messages && request.attempts.length === 0) return;
321
- const messages = [...request.messages ?? (request.prompt !== void 0 ? [{
322
- role: "user",
323
- content: request.prompt
324
- }] : [])];
325
- for (const attempt of require_decision.renderDecisionAttempts(request)) messages.push({
326
- role: "user",
327
- content: attempt.content
328
- });
329
- return messages;
330
- }
331
304
  //#endregion
332
- exports.createAgent = createAgent;
333
305
  exports.createAiSdkExecutors = createAiSdkExecutors;
334
306
  exports.defineModels = defineModels;
335
- exports.extractFirstJsonValue = extractFirstJsonValue;
336
- exports.isStructuredOutputRequest = isStructuredOutputRequest;
337
- exports.runAgent = runAgent;
338
- exports.toAiSdkCallSettings = toAiSdkCallSettings;
339
- exports.toAiSdkEventTools = toAiSdkEventTools;
340
- exports.toAiSdkToolChoice = toAiSdkToolChoice;
341
- exports.toAiSdkTools = toAiSdkTools;
342
- exports.toDecisionMessages = toDecisionMessages;
package/dist/ai-sdk.d.cts CHANGED
@@ -1,24 +1,8 @@
1
- import { C as StandardSchemaV1, m as ChosenEvent, n as AgentEventSchemaInputMap, u as AgentTools } from "./types-C9QiMjre.cjs";
2
- import { H as AgentEventDescriptor, i as AgentRequestExecutor, j as AgentDecisionRequest, k as AgentDecisionExecutor, l as AgentTextRequest, s as AgentRequestExecutors } from "./text-logic-CZjyACzQ.cjs";
3
- import { D as AgentMachine, O as AgentMachineConfig, l as RunAgentOptions, u as RunAgentResult } from "./run-agent-BVMd--1l.cjs";
4
- import * as _$xstate from "xstate";
5
- import { FinishReason, LanguageModel, LanguageModelUsage, ModelMessage, Tool, ToolSet, TypedToolCall, TypedToolResult } from "ai";
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";
6
4
 
7
5
  //#region src/ai-sdk/index.d.ts
8
- /**
9
- * Maps an {@link AgentTools} map onto AI SDK `tool()` definitions. A tool that
10
- * already carries its own Standard Schema `inputSchema` — an AI SDK
11
- * `tool({...})`, or any equivalent descriptor — is passed through **unchanged**,
12
- * so the SDK applies its own validation, calls `execute(input, options)`, and
13
- * every extra property (`providerOptions`, `toModelOutput`, …) survives. A bare
14
- * `AgentToolExecute` function becomes a tool with an unconstrained input schema;
15
- * a minimal descriptor with no readable schema is converted with a permissive
16
- * fallback. Used internally by {@link toAiSdkCallSettings}; exported for callers
17
- * building AI SDK calls by hand outside `createAiSdkExecutors`.
18
- */
19
- declare function toAiSdkTools(tools: AgentTools): {
20
- [k: string]: Tool<unknown, unknown> | Tool<unknown, never>;
21
- };
22
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>`. */
23
7
  type AiSdkModelMap<TKey extends string = string> = Record<TKey, LanguageModel>;
24
8
  /**
@@ -53,63 +37,6 @@ type CreateAiSdkExecutorsOptions<TModels extends AiSdkModelMap = AiSdkModelMap>
53
37
  models?: TModels;
54
38
  resolveModel: (modelRef: string) => LanguageModel;
55
39
  };
56
- /**
57
- * AI SDK request-mapping settings shared by `generateText`/`streamText`.
58
- * `AgentTextRequest.messages` (`AgentMessage[]`) and AI SDK's `ModelMessage[]`
59
- * are structurally compatible by design (§1 of .scratch/p0-design.md) — the cast
60
- * below is a typed identity mapping, not a semantic conversion.
61
- */
62
- declare function toAiSdkCallSettings(request: AgentTextRequest & {
63
- tools?: AgentTools;
64
- }): {
65
- temperature: number | undefined;
66
- maxOutputTokens: number | undefined;
67
- topP: number | undefined;
68
- topK: number | undefined;
69
- seed: number | undefined;
70
- stopSequences: string[] | undefined;
71
- tools: {
72
- [k: string]: Tool<unknown, unknown> | Tool<unknown, never>;
73
- } | undefined;
74
- toolChoice: "auto" | "none" | "required" | {
75
- type: "tool";
76
- toolName: string;
77
- } | undefined;
78
- messages: ModelMessage[];
79
- system: string | undefined;
80
- } | {
81
- temperature: number | undefined;
82
- maxOutputTokens: number | undefined;
83
- topP: number | undefined;
84
- topK: number | undefined;
85
- seed: number | undefined;
86
- stopSequences: string[] | undefined;
87
- tools: {
88
- [k: string]: Tool<unknown, unknown> | Tool<unknown, never>;
89
- } | undefined;
90
- toolChoice: "auto" | "none" | "required" | {
91
- type: "tool";
92
- toolName: string;
93
- } | undefined;
94
- prompt: string;
95
- system: string | undefined;
96
- };
97
- /** 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. */
98
- declare function toAiSdkToolChoice(toolChoice: AgentTextRequest["toolChoice"]): "auto" | "none" | "required" | {
99
- type: "tool";
100
- toolName: string;
101
- } | undefined;
102
- /** `true` when the request should use AI SDK structured `Output.object`. */
103
- declare function isStructuredOutputRequest(request: Pick<AgentTextRequest, "outputSchema">): boolean;
104
- /**
105
- * Extracts the first complete top-level JSON value from `text`, or returns
106
- * `undefined` when there is nothing to repair (no complete value, or the value
107
- * already spans the whole text). Models occasionally emit two structured-output
108
- * envelopes back to back (`{"result":{…}}{"result":{…}}`), which fails JSON
109
- * parsing wholesale; the balanced scan below recovers the first value and
110
- * drops the rest.
111
- */
112
- declare function extractFirstJsonValue(text: string): string | undefined;
113
40
  /**
114
41
  * Raw result shape from {@link AiSdkExecutors.generateText} — the `{ output }`
115
42
  * envelope (the validated structured object for structured-output requests,
@@ -146,6 +73,7 @@ type AiSdkDecideResult = {
146
73
  * general `AgentRequestExecutors`, where `streamText`/`decide` are optional),
147
74
  * and its `generateText`/`streamText` results are concretely typed. */
148
75
  interface AiSdkExecutors extends AgentRequestExecutors<AiSdkGenerateResult, AiSdkStreamResult> {
76
+ generateText: AgentRequestExecutor<AiSdkGenerateResult>;
149
77
  streamText: AgentRequestExecutor<AiSdkStreamResult>;
150
78
  decide: AgentDecisionExecutor;
151
79
  }
@@ -164,43 +92,5 @@ interface AiSdkExecutors extends AgentRequestExecutors<AiSdkGenerateResult, AiSd
164
92
  * ```
165
93
  */
166
94
  declare function createAiSdkExecutors<TModels extends AiSdkModelMap>(options: CreateAiSdkExecutorsOptions<TModels>): AiSdkExecutors;
167
- /** AI SDK host for a machine authored with `setupAgent({ models })`. */
168
- declare function runAgent<TMachine extends _$xstate.AnyStateMachine>(machine: TMachine, options: Omit<RunAgentOptions<TMachine>, "executors">): Promise<RunAgentResult<TMachine>>;
169
- type CreateAgentMachineConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TInputSchema extends StandardSchemaV1, TEventSchemas extends AgentEventSchemaInputMap, TOutputSchema extends StandardSchemaV1, TModels extends AiSdkModelMap> = Omit<AgentMachineConfig<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, TModels>, "schemas">;
170
- type CreateAgentBaseConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TInputSchema extends StandardSchemaV1, TEventSchemas extends AgentEventSchemaInputMap, TOutputSchema extends StandardSchemaV1, TModels extends AiSdkModelMap> = CreateAgentMachineConfig<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, TModels> & {
171
- schemas: {
172
- context: TContextSchema;
173
- input: TInputSchema;
174
- events?: TEventSchemas;
175
- output?: TOutputSchema;
176
- };
177
- };
178
- interface CreatedAgent<TMachine extends _$xstate.AnyStateMachine> {
179
- machine: TMachine;
180
- run(input: _$xstate.InputFrom<TMachine>, options?: Omit<RunAgentOptions<TMachine>, "input" | "executors">): Promise<RunAgentResult<TMachine>>;
181
- }
182
- /**
183
- * One-call AI SDK entry point for the common case: creates a typed machine and
184
- * a `run(input)` method with model executors already wired.
185
- */
186
- declare function createAgent<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TInputSchema extends StandardSchemaV1, TEventSchemas extends AgentEventSchemaInputMap = {}, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1>(config: CreateAgentBaseConfig<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, AiSdkModelMap<"default">> & {
187
- model: LanguageModel;
188
- models?: never;
189
- }): CreatedAgent<AgentMachine<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, AiSdkModelMap<"default">>>;
190
- declare function createAgent<TModels extends AiSdkModelMap, TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TInputSchema extends StandardSchemaV1, TEventSchemas extends AgentEventSchemaInputMap = {}, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1>(config: CreateAgentBaseConfig<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, TModels> & {
191
- models: TModels;
192
- model?: never;
193
- }): CreatedAgent<AgentMachine<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, TModels>>;
194
- /** One AI SDK `tool()` per candidate event — the "tool-per-event +
195
- * toolChoice: 'required'" recipe from .scratch/p0-design.md §2.6. */
196
- declare function toAiSdkEventTools(events: AgentEventDescriptor[]): {
197
- [k: string]: Tool<unknown, never>;
198
- };
199
- /**
200
- * Messages for a decision request, with prior failed `attempts` (§2.6)
201
- * rendered as appended user messages (via core's {@link renderDecisionAttempts})
202
- * so retries converge. Core never rewrites prompts — this is adapter business.
203
- */
204
- declare function toDecisionMessages(request: Pick<AgentDecisionRequest, "messages" | "prompt" | "events" | "attempts">): ModelMessage[] | undefined;
205
95
  //#endregion
206
- export { AiSdkDecideResult, AiSdkExecutors, AiSdkGenerateResult, AiSdkModelMap, AiSdkStreamResult, CreateAiSdkExecutorsOptions, CreatedAgent, createAgent, createAiSdkExecutors, defineModels, extractFirstJsonValue, isStructuredOutputRequest, runAgent, toAiSdkCallSettings, toAiSdkEventTools, toAiSdkToolChoice, toAiSdkTools, toDecisionMessages };
96
+ export { AiSdkDecideResult, AiSdkExecutors, AiSdkGenerateResult, AiSdkModelMap, AiSdkStreamResult, CreateAiSdkExecutorsOptions, createAiSdkExecutors, defineModels };
package/dist/ai-sdk.d.mts CHANGED
@@ -1,24 +1,8 @@
1
- import { C as StandardSchemaV1, m as ChosenEvent, n as AgentEventSchemaInputMap, u as AgentTools } from "./types-qm00QF91.mjs";
2
- import { H as AgentEventDescriptor, i as AgentRequestExecutor, j as AgentDecisionRequest, k as AgentDecisionExecutor, l as AgentTextRequest, s as AgentRequestExecutors } from "./text-logic-C7WJpCIc.mjs";
3
- import { D as AgentMachine, O as AgentMachineConfig, l as RunAgentOptions, u as RunAgentResult } from "./run-agent-DzYJb3CK.mjs";
4
- import * as _$xstate from "xstate";
5
- import { FinishReason, LanguageModel, LanguageModelUsage, ModelMessage, Tool, ToolSet, TypedToolCall, TypedToolResult } from "ai";
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";
6
4
 
7
5
  //#region src/ai-sdk/index.d.ts
8
- /**
9
- * Maps an {@link AgentTools} map onto AI SDK `tool()` definitions. A tool that
10
- * already carries its own Standard Schema `inputSchema` — an AI SDK
11
- * `tool({...})`, or any equivalent descriptor — is passed through **unchanged**,
12
- * so the SDK applies its own validation, calls `execute(input, options)`, and
13
- * every extra property (`providerOptions`, `toModelOutput`, …) survives. A bare
14
- * `AgentToolExecute` function becomes a tool with an unconstrained input schema;
15
- * a minimal descriptor with no readable schema is converted with a permissive
16
- * fallback. Used internally by {@link toAiSdkCallSettings}; exported for callers
17
- * building AI SDK calls by hand outside `createAiSdkExecutors`.
18
- */
19
- declare function toAiSdkTools(tools: AgentTools): {
20
- [k: string]: Tool<unknown, unknown> | Tool<unknown, never>;
21
- };
22
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>`. */
23
7
  type AiSdkModelMap<TKey extends string = string> = Record<TKey, LanguageModel>;
24
8
  /**
@@ -53,63 +37,6 @@ type CreateAiSdkExecutorsOptions<TModels extends AiSdkModelMap = AiSdkModelMap>
53
37
  models?: TModels;
54
38
  resolveModel: (modelRef: string) => LanguageModel;
55
39
  };
56
- /**
57
- * AI SDK request-mapping settings shared by `generateText`/`streamText`.
58
- * `AgentTextRequest.messages` (`AgentMessage[]`) and AI SDK's `ModelMessage[]`
59
- * are structurally compatible by design (§1 of .scratch/p0-design.md) — the cast
60
- * below is a typed identity mapping, not a semantic conversion.
61
- */
62
- declare function toAiSdkCallSettings(request: AgentTextRequest & {
63
- tools?: AgentTools;
64
- }): {
65
- temperature: number | undefined;
66
- maxOutputTokens: number | undefined;
67
- topP: number | undefined;
68
- topK: number | undefined;
69
- seed: number | undefined;
70
- stopSequences: string[] | undefined;
71
- tools: {
72
- [k: string]: Tool<unknown, unknown> | Tool<unknown, never>;
73
- } | undefined;
74
- toolChoice: "auto" | "none" | "required" | {
75
- type: "tool";
76
- toolName: string;
77
- } | undefined;
78
- messages: ModelMessage[];
79
- system: string | undefined;
80
- } | {
81
- temperature: number | undefined;
82
- maxOutputTokens: number | undefined;
83
- topP: number | undefined;
84
- topK: number | undefined;
85
- seed: number | undefined;
86
- stopSequences: string[] | undefined;
87
- tools: {
88
- [k: string]: Tool<unknown, unknown> | Tool<unknown, never>;
89
- } | undefined;
90
- toolChoice: "auto" | "none" | "required" | {
91
- type: "tool";
92
- toolName: string;
93
- } | undefined;
94
- prompt: string;
95
- system: string | undefined;
96
- };
97
- /** 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. */
98
- declare function toAiSdkToolChoice(toolChoice: AgentTextRequest["toolChoice"]): "auto" | "none" | "required" | {
99
- type: "tool";
100
- toolName: string;
101
- } | undefined;
102
- /** `true` when the request should use AI SDK structured `Output.object`. */
103
- declare function isStructuredOutputRequest(request: Pick<AgentTextRequest, "outputSchema">): boolean;
104
- /**
105
- * Extracts the first complete top-level JSON value from `text`, or returns
106
- * `undefined` when there is nothing to repair (no complete value, or the value
107
- * already spans the whole text). Models occasionally emit two structured-output
108
- * envelopes back to back (`{"result":{…}}{"result":{…}}`), which fails JSON
109
- * parsing wholesale; the balanced scan below recovers the first value and
110
- * drops the rest.
111
- */
112
- declare function extractFirstJsonValue(text: string): string | undefined;
113
40
  /**
114
41
  * Raw result shape from {@link AiSdkExecutors.generateText} — the `{ output }`
115
42
  * envelope (the validated structured object for structured-output requests,
@@ -146,6 +73,7 @@ type AiSdkDecideResult = {
146
73
  * general `AgentRequestExecutors`, where `streamText`/`decide` are optional),
147
74
  * and its `generateText`/`streamText` results are concretely typed. */
148
75
  interface AiSdkExecutors extends AgentRequestExecutors<AiSdkGenerateResult, AiSdkStreamResult> {
76
+ generateText: AgentRequestExecutor<AiSdkGenerateResult>;
149
77
  streamText: AgentRequestExecutor<AiSdkStreamResult>;
150
78
  decide: AgentDecisionExecutor;
151
79
  }
@@ -164,43 +92,5 @@ interface AiSdkExecutors extends AgentRequestExecutors<AiSdkGenerateResult, AiSd
164
92
  * ```
165
93
  */
166
94
  declare function createAiSdkExecutors<TModels extends AiSdkModelMap>(options: CreateAiSdkExecutorsOptions<TModels>): AiSdkExecutors;
167
- /** AI SDK host for a machine authored with `setupAgent({ models })`. */
168
- declare function runAgent<TMachine extends _$xstate.AnyStateMachine>(machine: TMachine, options: Omit<RunAgentOptions<TMachine>, "executors">): Promise<RunAgentResult<TMachine>>;
169
- type CreateAgentMachineConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TInputSchema extends StandardSchemaV1, TEventSchemas extends AgentEventSchemaInputMap, TOutputSchema extends StandardSchemaV1, TModels extends AiSdkModelMap> = Omit<AgentMachineConfig<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, TModels>, "schemas">;
170
- type CreateAgentBaseConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TInputSchema extends StandardSchemaV1, TEventSchemas extends AgentEventSchemaInputMap, TOutputSchema extends StandardSchemaV1, TModels extends AiSdkModelMap> = CreateAgentMachineConfig<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, TModels> & {
171
- schemas: {
172
- context: TContextSchema;
173
- input: TInputSchema;
174
- events?: TEventSchemas;
175
- output?: TOutputSchema;
176
- };
177
- };
178
- interface CreatedAgent<TMachine extends _$xstate.AnyStateMachine> {
179
- machine: TMachine;
180
- run(input: _$xstate.InputFrom<TMachine>, options?: Omit<RunAgentOptions<TMachine>, "input" | "executors">): Promise<RunAgentResult<TMachine>>;
181
- }
182
- /**
183
- * One-call AI SDK entry point for the common case: creates a typed machine and
184
- * a `run(input)` method with model executors already wired.
185
- */
186
- declare function createAgent<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TInputSchema extends StandardSchemaV1, TEventSchemas extends AgentEventSchemaInputMap = {}, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1>(config: CreateAgentBaseConfig<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, AiSdkModelMap<"default">> & {
187
- model: LanguageModel;
188
- models?: never;
189
- }): CreatedAgent<AgentMachine<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, AiSdkModelMap<"default">>>;
190
- declare function createAgent<TModels extends AiSdkModelMap, TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TInputSchema extends StandardSchemaV1, TEventSchemas extends AgentEventSchemaInputMap = {}, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1>(config: CreateAgentBaseConfig<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, TModels> & {
191
- models: TModels;
192
- model?: never;
193
- }): CreatedAgent<AgentMachine<TContextSchema, TInputSchema, TEventSchemas, TOutputSchema, TModels>>;
194
- /** One AI SDK `tool()` per candidate event — the "tool-per-event +
195
- * toolChoice: 'required'" recipe from .scratch/p0-design.md §2.6. */
196
- declare function toAiSdkEventTools(events: AgentEventDescriptor[]): {
197
- [k: string]: Tool<unknown, never>;
198
- };
199
- /**
200
- * Messages for a decision request, with prior failed `attempts` (§2.6)
201
- * rendered as appended user messages (via core's {@link renderDecisionAttempts})
202
- * so retries converge. Core never rewrites prompts — this is adapter business.
203
- */
204
- declare function toDecisionMessages(request: Pick<AgentDecisionRequest, "messages" | "prompt" | "events" | "attempts">): ModelMessage[] | undefined;
205
95
  //#endregion
206
- export { AiSdkDecideResult, AiSdkExecutors, AiSdkGenerateResult, AiSdkModelMap, AiSdkStreamResult, CreateAiSdkExecutorsOptions, CreatedAgent, createAgent, createAiSdkExecutors, defineModels, extractFirstJsonValue, isStructuredOutputRequest, runAgent, toAiSdkCallSettings, toAiSdkEventTools, toAiSdkToolChoice, toAiSdkTools, toDecisionMessages };
96
+ export { AiSdkDecideResult, AiSdkExecutors, AiSdkGenerateResult, AiSdkModelMap, AiSdkStreamResult, CreateAiSdkExecutorsOptions, createAiSdkExecutors, defineModels };