@statelyai/agent 2.0.0-alpha.22 → 2.0.0-alpha.24
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.
- package/dist/ai-sdk.cjs +53 -25
- package/dist/ai-sdk.d.cts +20 -12
- package/dist/ai-sdk.d.mts +20 -12
- package/dist/ai-sdk.mjs +53 -25
- package/dist/{decision-DxSTqzgZ.mjs → decision-BBZ2jMO1.mjs} +444 -79
- package/dist/{decision-1o45_ZrS.cjs → decision-Cv6SfNWl.cjs} +525 -94
- package/dist/index.cjs +2224 -1032
- package/dist/index.d.cts +413 -275
- package/dist/index.d.mts +413 -275
- package/dist/index.mjs +2163 -983
- package/dist/machines.cjs +30 -2
- package/dist/machines.d.cts +1 -1
- package/dist/machines.d.mts +1 -1
- package/dist/machines.mjs +30 -2
- package/dist/openai.cjs +447 -0
- package/dist/openai.d.cts +177 -0
- package/dist/openai.d.mts +177 -0
- package/dist/openai.mjs +437 -0
- package/dist/otel.cjs +3 -6
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/otel.mjs +3 -6
- package/dist/run-agent-Ck7Sa3Tb.d.mts +968 -0
- package/dist/run-agent-DWqA8KiI.d.cts +968 -0
- package/dist/setup-agent-CeO2fARv.mjs +639 -0
- package/dist/setup-agent-Dl2VELLi.cjs +663 -0
- package/dist/{text-logic-BaxPrcLk.d.cts → text-logic-C7bSnH_B.d.cts} +195 -44
- package/dist/{text-logic-DhfFWzu9.d.mts → text-logic-DJBK3LbG.d.mts} +195 -44
- package/dist/{types-DSdj2tGs.d.cts → types-CjHk5OdH.d.cts} +4 -19
- package/dist/{types-CvWRGFxP.d.mts → types-DWA6X9R-.d.mts} +4 -19
- package/package.json +17 -21
- package/readme.md +32 -17
- package/dist/errors-BQRk9eiZ.d.cts +0 -19
- package/dist/errors-C9rxnWbX.d.mts +0 -19
- package/dist/errors-CeSXQx0v.mjs +0 -23
- package/dist/errors-DUBBzRLP.cjs +0 -28
- package/dist/event-log-store-Bz7HDBkE.d.cts +0 -145
- package/dist/event-log-store-DmIDosD6.mjs +0 -427
- package/dist/event-log-store-a_TKy1gk.cjs +0 -468
- package/dist/event-log-store-hrA1vqtN.d.mts +0 -145
- package/dist/run-agent-0fpEZ1wJ.d.mts +0 -1098
- package/dist/run-agent-Zbkx7XP8.d.cts +0 -1098
- package/dist/setup-agent-DkCTy5Eu.cjs +0 -1707
- package/dist/setup-agent-nSFYrNTP.mjs +0 -1587
- package/dist/sqlite.cjs +0 -129
- package/dist/sqlite.d.cts +0 -57
- package/dist/sqlite.d.mts +0 -57
- package/dist/sqlite.mjs +0 -127
package/dist/ai-sdk.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_decision = require("./decision-
|
|
2
|
+
const require_decision = require("./decision-Cv6SfNWl.cjs");
|
|
3
3
|
require("./validate.cjs");
|
|
4
4
|
let ai = require("ai");
|
|
5
5
|
//#region src/ai-sdk/mappers.ts
|
|
@@ -67,6 +67,16 @@ function toAgentCallUsage(usage) {
|
|
|
67
67
|
...cachedInputTokens !== void 0 ? { cachedInputTokens } : {}
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Maps the AI SDK's unified finish reason onto the portable
|
|
72
|
+
* {@link AgentFinishReason}. Only `'error'` differs: core's union has no
|
|
73
|
+
* `'error'` member, since a call that failed outright rejects instead of
|
|
74
|
+
* returning, so it lands on `'other'`. The SDK's own value stays on the
|
|
75
|
+
* result's `raw`.
|
|
76
|
+
*/
|
|
77
|
+
function toAgentFinishReason(finishReason) {
|
|
78
|
+
return finishReason === "error" ? "other" : finishReason;
|
|
79
|
+
}
|
|
70
80
|
/** Drops keys whose value is `undefined`, so a spread cannot erase what it lands on. */
|
|
71
81
|
function defined(settings) {
|
|
72
82
|
return Object.fromEntries(Object.entries(settings).filter(([, value]) => value !== void 0));
|
|
@@ -184,7 +194,7 @@ function toDecisionMessages(request) {
|
|
|
184
194
|
//#endregion
|
|
185
195
|
//#region src/ai-sdk/index.ts
|
|
186
196
|
function maxStepsSetting(request) {
|
|
187
|
-
const maxSteps =
|
|
197
|
+
const maxSteps = request.maxSteps;
|
|
188
198
|
return typeof maxSteps === "number" ? { stopWhen: (0, ai.stepCountIs)(maxSteps) } : {};
|
|
189
199
|
}
|
|
190
200
|
/**
|
|
@@ -206,7 +216,12 @@ function maxStepsSetting(request) {
|
|
|
206
216
|
* ```
|
|
207
217
|
*/
|
|
208
218
|
function defineModels(models) {
|
|
209
|
-
|
|
219
|
+
const registry = { ...models };
|
|
220
|
+
Object.defineProperty(registry, require_decision.DEFAULT_AGENT_EXECUTORS, {
|
|
221
|
+
enumerable: false,
|
|
222
|
+
value: () => createAiSdkExecutors({ models: registry })
|
|
223
|
+
});
|
|
224
|
+
return registry;
|
|
210
225
|
}
|
|
211
226
|
/** Resolves the host's `settings` option for one request. */
|
|
212
227
|
function callSettings(options, request) {
|
|
@@ -249,6 +264,14 @@ function withJsonRepair(output) {
|
|
|
249
264
|
}
|
|
250
265
|
};
|
|
251
266
|
}
|
|
267
|
+
function truncated(request, info, partialOutput, cause) {
|
|
268
|
+
return new require_decision.AgentTruncatedError(`createAiSdkExecutors: request '${request.name ?? "(unnamed)"}' hit the output token limit — its structured output never completed. Raise \`maxOutputTokens\`, shorten the input, or ask for a smaller output schema.`, {
|
|
269
|
+
requestName: request.name ?? "(unnamed)",
|
|
270
|
+
...info?.requestId !== void 0 ? { requestId: info.requestId } : {},
|
|
271
|
+
...partialOutput !== void 0 ? { partialOutput } : {},
|
|
272
|
+
...cause !== void 0 ? { cause } : {}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
252
275
|
/**
|
|
253
276
|
* The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
|
|
254
277
|
* decide }` executor set consumed by `runAgent`/`executeAgentRequest`. `ai`
|
|
@@ -277,37 +300,40 @@ function createAiSdkExecutors(options) {
|
|
|
277
300
|
if (isStructuredOutputRequest(request)) {
|
|
278
301
|
const envelope = require_decision.buildEnvelopeSchema(request.outputSchema, { reasoning: request.includeReasoning });
|
|
279
302
|
const structuredOutput = withJsonRepair(ai.Output.object({ schema: envelope }));
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const { result: output, reasoning } = result.output;
|
|
303
|
+
const result = await (0, ai.generateText)({
|
|
304
|
+
...common,
|
|
305
|
+
output: structuredOutput
|
|
306
|
+
}).catch((error) => {
|
|
307
|
+
throw ai.NoObjectGeneratedError.isInstance(error) && error.finishReason === "length" ? truncated(request, info, error.text, error) : error;
|
|
308
|
+
});
|
|
309
|
+
const { result: output, reasoning } = (() => {
|
|
310
|
+
try {
|
|
311
|
+
return result.output;
|
|
312
|
+
} catch (error) {
|
|
313
|
+
throw result.finishReason === "length" ? truncated(request, info, result.text, error) : error;
|
|
314
|
+
}
|
|
315
|
+
})();
|
|
316
|
+
if (result.finishReason === "length") throw truncated(request, info, output);
|
|
295
317
|
return {
|
|
296
318
|
output,
|
|
297
319
|
...reasoning !== void 0 ? { reasoning } : {},
|
|
298
320
|
usage: toAgentCallUsage(result.usage),
|
|
299
|
-
finishReason: result.finishReason,
|
|
321
|
+
finishReason: toAgentFinishReason(result.finishReason),
|
|
300
322
|
toolCalls: result.toolCalls,
|
|
301
|
-
toolResults: result.toolResults
|
|
323
|
+
toolResults: result.toolResults,
|
|
324
|
+
messages: result.responseMessages,
|
|
325
|
+
raw: result
|
|
302
326
|
};
|
|
303
327
|
}
|
|
304
328
|
const result = await (0, ai.generateText)(common);
|
|
305
329
|
return {
|
|
306
330
|
output: result.text,
|
|
307
331
|
usage: toAgentCallUsage(result.usage),
|
|
308
|
-
finishReason: result.finishReason,
|
|
332
|
+
finishReason: toAgentFinishReason(result.finishReason),
|
|
309
333
|
toolCalls: result.toolCalls,
|
|
310
|
-
toolResults: result.toolResults
|
|
334
|
+
toolResults: result.toolResults,
|
|
335
|
+
messages: result.responseMessages,
|
|
336
|
+
raw: result
|
|
311
337
|
};
|
|
312
338
|
};
|
|
313
339
|
const streamText = async (request, info) => {
|
|
@@ -324,16 +350,18 @@ function createAiSdkExecutors(options) {
|
|
|
324
350
|
return {
|
|
325
351
|
output: await result.text,
|
|
326
352
|
usage: toAgentCallUsage(await result.usage),
|
|
327
|
-
finishReason: await result.finishReason
|
|
353
|
+
finishReason: toAgentFinishReason(await result.finishReason),
|
|
354
|
+
messages: await result.responseMessages,
|
|
355
|
+
raw: result
|
|
328
356
|
};
|
|
329
357
|
};
|
|
330
|
-
const decide = async (request) => {
|
|
358
|
+
const decide = async (request, info) => {
|
|
331
359
|
const { model, settings: modelSettings } = resolveAiSdkModel(options, request.model);
|
|
332
360
|
const tools = toAiSdkEventTools(request.events);
|
|
333
361
|
const messages = toDecisionMessages(request);
|
|
334
362
|
const result = await (0, ai.generateText)({
|
|
335
363
|
model,
|
|
336
|
-
abortSignal:
|
|
364
|
+
abortSignal: info?.signal,
|
|
337
365
|
...callSettings(options, request),
|
|
338
366
|
...defined(modelSettings ?? {}),
|
|
339
367
|
system: request.system,
|
package/dist/ai-sdk.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { FinishReason, LanguageModel, LanguageModelUsage, ToolSet, TypedToolCall, TypedToolResult, generateText } from "ai";
|
|
1
|
+
import { s as AgentTools, u as ChosenEvent } from "./types-CjHk5OdH.cjs";
|
|
2
|
+
import { F as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-C7bSnH_B.cjs";
|
|
3
|
+
import { FinishReason, LanguageModel, LanguageModelUsage, ModelMessage, ToolSet, TypedToolCall, TypedToolResult, generateText } from "ai";
|
|
4
4
|
|
|
5
5
|
//#region src/ai-sdk/mappers.d.ts
|
|
6
6
|
/**
|
|
@@ -99,16 +99,20 @@ type AiSdkGenerateResult = {
|
|
|
99
99
|
* `reasoningTokens`/`cachedInputTokens` fields are what `runAgent` folds into
|
|
100
100
|
* the run result's aggregated `AgentUsage`; the AI SDK's own nested
|
|
101
101
|
* `inputTokenDetails`/`outputTokenDetails` and `raw` ride along untouched. */
|
|
102
|
-
usage: AiSdkCallUsage;
|
|
103
|
-
finishReason:
|
|
102
|
+
usage: AiSdkCallUsage; /** Why the call stopped, normalized to the portable {@link AgentFinishReason}. The SDK's own value stays on `raw`. */
|
|
103
|
+
finishReason: AgentFinishReason;
|
|
104
104
|
toolCalls: TypedToolCall<ToolSet>[];
|
|
105
|
-
toolResults: TypedToolResult<ToolSet>[];
|
|
105
|
+
toolResults: TypedToolResult<ToolSet>[]; /** AI SDK response messages, including tool calls/results from every step. */
|
|
106
|
+
messages: ModelMessage[]; /** The untouched AI SDK result. */
|
|
107
|
+
raw: unknown;
|
|
106
108
|
};
|
|
107
109
|
/** 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`. */
|
|
108
110
|
type AiSdkStreamResult = {
|
|
109
111
|
output: string; /** The stream's final (awaited) usage; aggregated into the run result's `AgentUsage`. */
|
|
110
|
-
usage: AiSdkCallUsage;
|
|
111
|
-
finishReason:
|
|
112
|
+
usage: AiSdkCallUsage; /** Why the stream stopped, normalized to the portable {@link AgentFinishReason}. The SDK's own value stays on `raw`. */
|
|
113
|
+
finishReason: AgentFinishReason; /** AI SDK response messages, including tool calls/results from every step. */
|
|
114
|
+
messages: ModelMessage[]; /** The untouched AI SDK result. */
|
|
115
|
+
raw: unknown;
|
|
112
116
|
};
|
|
113
117
|
/** Raw result shape from {@link AiSdkExecutors.decide} — the chosen event plus the AI SDK call metadata, delivered per decision attempt to `onResult`. */
|
|
114
118
|
type AiSdkDecideResult = {
|
|
@@ -119,10 +123,14 @@ type AiSdkDecideResult = {
|
|
|
119
123
|
/** `createAiSdkExecutors` always populates all three slots (unlike the
|
|
120
124
|
* general `AgentRequestExecutors`, where `streamText`/`decide` are optional),
|
|
121
125
|
* and its `generateText`/`streamText` results are concretely typed. */
|
|
122
|
-
interface AiSdkExecutors
|
|
123
|
-
generateText:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
interface AiSdkExecutors {
|
|
127
|
+
generateText: (request: AgentTextRequest & {
|
|
128
|
+
tools: AgentTools;
|
|
129
|
+
}, info?: AgentRequestExecutorInfo) => Promise<AiSdkGenerateResult>;
|
|
130
|
+
streamText: (request: AgentTextRequest & {
|
|
131
|
+
tools: AgentTools;
|
|
132
|
+
}, info?: AgentRequestExecutorInfo) => Promise<AiSdkStreamResult>;
|
|
133
|
+
decide: (request: AgentDecisionRequest, info?: AgentRequestExecutorInfo) => Promise<AiSdkDecideResult>;
|
|
126
134
|
}
|
|
127
135
|
/**
|
|
128
136
|
* The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
|
package/dist/ai-sdk.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { FinishReason, LanguageModel, LanguageModelUsage, ToolSet, TypedToolCall, TypedToolResult, generateText } from "ai";
|
|
1
|
+
import { s as AgentTools, u as ChosenEvent } from "./types-DWA6X9R-.mjs";
|
|
2
|
+
import { F as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-DJBK3LbG.mjs";
|
|
3
|
+
import { FinishReason, LanguageModel, LanguageModelUsage, ModelMessage, ToolSet, TypedToolCall, TypedToolResult, generateText } from "ai";
|
|
4
4
|
|
|
5
5
|
//#region src/ai-sdk/mappers.d.ts
|
|
6
6
|
/**
|
|
@@ -99,16 +99,20 @@ type AiSdkGenerateResult = {
|
|
|
99
99
|
* `reasoningTokens`/`cachedInputTokens` fields are what `runAgent` folds into
|
|
100
100
|
* the run result's aggregated `AgentUsage`; the AI SDK's own nested
|
|
101
101
|
* `inputTokenDetails`/`outputTokenDetails` and `raw` ride along untouched. */
|
|
102
|
-
usage: AiSdkCallUsage;
|
|
103
|
-
finishReason:
|
|
102
|
+
usage: AiSdkCallUsage; /** Why the call stopped, normalized to the portable {@link AgentFinishReason}. The SDK's own value stays on `raw`. */
|
|
103
|
+
finishReason: AgentFinishReason;
|
|
104
104
|
toolCalls: TypedToolCall<ToolSet>[];
|
|
105
|
-
toolResults: TypedToolResult<ToolSet>[];
|
|
105
|
+
toolResults: TypedToolResult<ToolSet>[]; /** AI SDK response messages, including tool calls/results from every step. */
|
|
106
|
+
messages: ModelMessage[]; /** The untouched AI SDK result. */
|
|
107
|
+
raw: unknown;
|
|
106
108
|
};
|
|
107
109
|
/** 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`. */
|
|
108
110
|
type AiSdkStreamResult = {
|
|
109
111
|
output: string; /** The stream's final (awaited) usage; aggregated into the run result's `AgentUsage`. */
|
|
110
|
-
usage: AiSdkCallUsage;
|
|
111
|
-
finishReason:
|
|
112
|
+
usage: AiSdkCallUsage; /** Why the stream stopped, normalized to the portable {@link AgentFinishReason}. The SDK's own value stays on `raw`. */
|
|
113
|
+
finishReason: AgentFinishReason; /** AI SDK response messages, including tool calls/results from every step. */
|
|
114
|
+
messages: ModelMessage[]; /** The untouched AI SDK result. */
|
|
115
|
+
raw: unknown;
|
|
112
116
|
};
|
|
113
117
|
/** Raw result shape from {@link AiSdkExecutors.decide} — the chosen event plus the AI SDK call metadata, delivered per decision attempt to `onResult`. */
|
|
114
118
|
type AiSdkDecideResult = {
|
|
@@ -119,10 +123,14 @@ type AiSdkDecideResult = {
|
|
|
119
123
|
/** `createAiSdkExecutors` always populates all three slots (unlike the
|
|
120
124
|
* general `AgentRequestExecutors`, where `streamText`/`decide` are optional),
|
|
121
125
|
* and its `generateText`/`streamText` results are concretely typed. */
|
|
122
|
-
interface AiSdkExecutors
|
|
123
|
-
generateText:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
interface AiSdkExecutors {
|
|
127
|
+
generateText: (request: AgentTextRequest & {
|
|
128
|
+
tools: AgentTools;
|
|
129
|
+
}, info?: AgentRequestExecutorInfo) => Promise<AiSdkGenerateResult>;
|
|
130
|
+
streamText: (request: AgentTextRequest & {
|
|
131
|
+
tools: AgentTools;
|
|
132
|
+
}, info?: AgentRequestExecutorInfo) => Promise<AiSdkStreamResult>;
|
|
133
|
+
decide: (request: AgentDecisionRequest, info?: AgentRequestExecutorInfo) => Promise<AiSdkDecideResult>;
|
|
126
134
|
}
|
|
127
135
|
/**
|
|
128
136
|
* The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
|
package/dist/ai-sdk.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as getAgentOutputMode, Y as isStandardSchema, j as DEFAULT_AGENT_EXECUTORS, o as renderDecisionAttempts, st as AgentTruncatedError, v as buildEnvelopeSchema } from "./decision-BBZ2jMO1.mjs";
|
|
2
2
|
import { NoObjectGeneratedError, Output, generateText, stepCountIs, streamText, tool } from "ai";
|
|
3
3
|
//#region src/ai-sdk/mappers.ts
|
|
4
4
|
/**
|
|
@@ -65,6 +65,16 @@ function toAgentCallUsage(usage) {
|
|
|
65
65
|
...cachedInputTokens !== void 0 ? { cachedInputTokens } : {}
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Maps the AI SDK's unified finish reason onto the portable
|
|
70
|
+
* {@link AgentFinishReason}. Only `'error'` differs: core's union has no
|
|
71
|
+
* `'error'` member, since a call that failed outright rejects instead of
|
|
72
|
+
* returning, so it lands on `'other'`. The SDK's own value stays on the
|
|
73
|
+
* result's `raw`.
|
|
74
|
+
*/
|
|
75
|
+
function toAgentFinishReason(finishReason) {
|
|
76
|
+
return finishReason === "error" ? "other" : finishReason;
|
|
77
|
+
}
|
|
68
78
|
/** Drops keys whose value is `undefined`, so a spread cannot erase what it lands on. */
|
|
69
79
|
function defined(settings) {
|
|
70
80
|
return Object.fromEntries(Object.entries(settings).filter(([, value]) => value !== void 0));
|
|
@@ -182,7 +192,7 @@ function toDecisionMessages(request) {
|
|
|
182
192
|
//#endregion
|
|
183
193
|
//#region src/ai-sdk/index.ts
|
|
184
194
|
function maxStepsSetting(request) {
|
|
185
|
-
const maxSteps =
|
|
195
|
+
const maxSteps = request.maxSteps;
|
|
186
196
|
return typeof maxSteps === "number" ? { stopWhen: stepCountIs(maxSteps) } : {};
|
|
187
197
|
}
|
|
188
198
|
/**
|
|
@@ -204,7 +214,12 @@ function maxStepsSetting(request) {
|
|
|
204
214
|
* ```
|
|
205
215
|
*/
|
|
206
216
|
function defineModels(models) {
|
|
207
|
-
|
|
217
|
+
const registry = { ...models };
|
|
218
|
+
Object.defineProperty(registry, DEFAULT_AGENT_EXECUTORS, {
|
|
219
|
+
enumerable: false,
|
|
220
|
+
value: () => createAiSdkExecutors({ models: registry })
|
|
221
|
+
});
|
|
222
|
+
return registry;
|
|
208
223
|
}
|
|
209
224
|
/** Resolves the host's `settings` option for one request. */
|
|
210
225
|
function callSettings(options, request) {
|
|
@@ -247,6 +262,14 @@ function withJsonRepair(output) {
|
|
|
247
262
|
}
|
|
248
263
|
};
|
|
249
264
|
}
|
|
265
|
+
function truncated(request, info, partialOutput, cause) {
|
|
266
|
+
return new AgentTruncatedError(`createAiSdkExecutors: request '${request.name ?? "(unnamed)"}' hit the output token limit — its structured output never completed. Raise \`maxOutputTokens\`, shorten the input, or ask for a smaller output schema.`, {
|
|
267
|
+
requestName: request.name ?? "(unnamed)",
|
|
268
|
+
...info?.requestId !== void 0 ? { requestId: info.requestId } : {},
|
|
269
|
+
...partialOutput !== void 0 ? { partialOutput } : {},
|
|
270
|
+
...cause !== void 0 ? { cause } : {}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
250
273
|
/**
|
|
251
274
|
* The canonical Vercel AI SDK adapter: builds the `{ generateText, streamText,
|
|
252
275
|
* decide }` executor set consumed by `runAgent`/`executeAgentRequest`. `ai`
|
|
@@ -275,37 +298,40 @@ function createAiSdkExecutors(options) {
|
|
|
275
298
|
if (isStructuredOutputRequest(request)) {
|
|
276
299
|
const envelope = buildEnvelopeSchema(request.outputSchema, { reasoning: request.includeReasoning });
|
|
277
300
|
const structuredOutput = withJsonRepair(Output.object({ schema: envelope }));
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const { result: output, reasoning } = result.output;
|
|
301
|
+
const result = await generateText({
|
|
302
|
+
...common,
|
|
303
|
+
output: structuredOutput
|
|
304
|
+
}).catch((error) => {
|
|
305
|
+
throw NoObjectGeneratedError.isInstance(error) && error.finishReason === "length" ? truncated(request, info, error.text, error) : error;
|
|
306
|
+
});
|
|
307
|
+
const { result: output, reasoning } = (() => {
|
|
308
|
+
try {
|
|
309
|
+
return result.output;
|
|
310
|
+
} catch (error) {
|
|
311
|
+
throw result.finishReason === "length" ? truncated(request, info, result.text, error) : error;
|
|
312
|
+
}
|
|
313
|
+
})();
|
|
314
|
+
if (result.finishReason === "length") throw truncated(request, info, output);
|
|
293
315
|
return {
|
|
294
316
|
output,
|
|
295
317
|
...reasoning !== void 0 ? { reasoning } : {},
|
|
296
318
|
usage: toAgentCallUsage(result.usage),
|
|
297
|
-
finishReason: result.finishReason,
|
|
319
|
+
finishReason: toAgentFinishReason(result.finishReason),
|
|
298
320
|
toolCalls: result.toolCalls,
|
|
299
|
-
toolResults: result.toolResults
|
|
321
|
+
toolResults: result.toolResults,
|
|
322
|
+
messages: result.responseMessages,
|
|
323
|
+
raw: result
|
|
300
324
|
};
|
|
301
325
|
}
|
|
302
326
|
const result = await generateText(common);
|
|
303
327
|
return {
|
|
304
328
|
output: result.text,
|
|
305
329
|
usage: toAgentCallUsage(result.usage),
|
|
306
|
-
finishReason: result.finishReason,
|
|
330
|
+
finishReason: toAgentFinishReason(result.finishReason),
|
|
307
331
|
toolCalls: result.toolCalls,
|
|
308
|
-
toolResults: result.toolResults
|
|
332
|
+
toolResults: result.toolResults,
|
|
333
|
+
messages: result.responseMessages,
|
|
334
|
+
raw: result
|
|
309
335
|
};
|
|
310
336
|
};
|
|
311
337
|
const streamText$1 = async (request, info) => {
|
|
@@ -322,16 +348,18 @@ function createAiSdkExecutors(options) {
|
|
|
322
348
|
return {
|
|
323
349
|
output: await result.text,
|
|
324
350
|
usage: toAgentCallUsage(await result.usage),
|
|
325
|
-
finishReason: await result.finishReason
|
|
351
|
+
finishReason: toAgentFinishReason(await result.finishReason),
|
|
352
|
+
messages: await result.responseMessages,
|
|
353
|
+
raw: result
|
|
326
354
|
};
|
|
327
355
|
};
|
|
328
|
-
const decide = async (request) => {
|
|
356
|
+
const decide = async (request, info) => {
|
|
329
357
|
const { model, settings: modelSettings } = resolveAiSdkModel(options, request.model);
|
|
330
358
|
const tools = toAiSdkEventTools(request.events);
|
|
331
359
|
const messages = toDecisionMessages(request);
|
|
332
360
|
const result = await generateText({
|
|
333
361
|
model,
|
|
334
|
-
abortSignal:
|
|
362
|
+
abortSignal: info?.signal,
|
|
335
363
|
...callSettings(options, request),
|
|
336
364
|
...defined(modelSettings ?? {}),
|
|
337
365
|
system: request.system,
|