@statelyai/agent 2.0.0-alpha.23 → 2.0.0-alpha.25
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 +30 -34
- package/dist/ai-sdk.d.cts +27 -31
- package/dist/ai-sdk.d.mts +27 -31
- package/dist/ai-sdk.mjs +27 -31
- package/dist/decision-CM9CYZ6t.cjs +519 -0
- package/dist/decision-DzSv1NpD.mjs +453 -0
- package/dist/event-log-store-Ba2fsc4E.mjs +576 -0
- package/dist/event-log-store-DQmImLYk.cjs +702 -0
- package/dist/event-log-store-DvOcs10J.d.cts +338 -0
- package/dist/event-log-store-DxyVgnas.d.mts +338 -0
- package/dist/index.cjs +429 -4272
- package/dist/index.d.cts +104 -1005
- package/dist/index.d.mts +104 -1005
- package/dist/index.mjs +389 -4202
- package/dist/log.cjs +392 -0
- package/dist/log.d.cts +32 -0
- package/dist/log.d.mts +32 -0
- package/dist/log.mjs +371 -0
- package/dist/machines.cjs +27 -16
- package/dist/machines.d.cts +1 -1
- package/dist/machines.d.mts +1 -1
- package/dist/machines.mjs +27 -16
- package/dist/openai.cjs +16 -15
- package/dist/openai.d.cts +9 -9
- package/dist/openai.d.mts +9 -9
- package/dist/openai.mjs +10 -9
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/{run-agent-Ck7Sa3Tb.d.mts → run-agent-BOfoJg5B.d.cts} +86 -387
- package/dist/{run-agent-DWqA8KiI.d.cts → run-agent-CG343kFs.d.mts} +86 -387
- package/dist/run-agent-Cb1-LS5P.cjs +1783 -0
- package/dist/run-agent-DvDQd4If.mjs +1669 -0
- package/dist/{setup-agent-CeO2fARv.mjs → setup-agent-CFW-jPI8.mjs} +9 -20
- package/dist/{setup-agent-Dl2VELLi.cjs → setup-agent-CPf7MxnG.cjs} +20 -37
- package/dist/testing.cjs +1222 -0
- package/dist/testing.d.cts +602 -0
- package/dist/testing.d.mts +602 -0
- package/dist/testing.mjs +1212 -0
- package/dist/{text-logic-DJBK3LbG.d.mts → text-logic-BFEOxyxv.d.cts} +71 -147
- package/dist/text-logic-Bl_ZRxDi.mjs +833 -0
- package/dist/text-logic-C8xyr6Ag.cjs +1091 -0
- package/dist/{text-logic-C7bSnH_B.d.cts → text-logic-hZSiRUo1.d.mts} +71 -147
- package/dist/{types-CjHk5OdH.d.cts → types-B1Qs2q3q.d.cts} +2 -1
- package/dist/{types-DWA6X9R-.d.mts → types-tA3SdczG.d.mts} +2 -1
- package/dist/usage-BdEjFuIi.mjs +5 -0
- package/dist/usage-efOQPdf_.cjs +10 -0
- package/dist/utils-C1p37X_c.d.mts +209 -0
- package/dist/utils-RalRn9sk.d.cts +209 -0
- package/package.json +24 -4
- package/readme.md +2 -2
- package/skills/generate-machine/SKILL.md +4 -6
- package/dist/decision-BBZ2jMO1.mjs +0 -1490
- package/dist/decision-Cv6SfNWl.cjs +0 -1856
package/dist/ai-sdk.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_text_logic = require("./text-logic-C8xyr6Ag.cjs");
|
|
3
|
+
const require_decision = require("./decision-CM9CYZ6t.cjs");
|
|
3
4
|
require("./validate.cjs");
|
|
4
5
|
let ai = require("ai");
|
|
5
6
|
//#region src/ai-sdk/mappers.ts
|
|
@@ -24,7 +25,7 @@ function toAiSdkTools(tools) {
|
|
|
24
25
|
})]);
|
|
25
26
|
continue;
|
|
26
27
|
}
|
|
27
|
-
if (
|
|
28
|
+
if (require_text_logic.isStandardSchema(descriptor.inputSchema)) {
|
|
28
29
|
entries.push([name, descriptor]);
|
|
29
30
|
continue;
|
|
30
31
|
}
|
|
@@ -131,13 +132,13 @@ function toAiSdkToolChoice(toolChoice) {
|
|
|
131
132
|
}
|
|
132
133
|
/** `true` when the request should use AI SDK structured `Output.object`. */
|
|
133
134
|
function isStructuredOutputRequest(request) {
|
|
134
|
-
return
|
|
135
|
+
return require_text_logic.getAgentOutputMode(request.outputSchema) === "structured";
|
|
135
136
|
}
|
|
136
137
|
/**
|
|
137
138
|
* Extracts the first complete top-level JSON value from `text`, or returns
|
|
138
139
|
* `undefined` when there is nothing to repair (no complete value, or the value
|
|
139
140
|
* already spans the whole text). Models occasionally emit two structured-output
|
|
140
|
-
*
|
|
141
|
+
* objects back to back (`{"result":{…}}{"result":{…}}`), which fails JSON
|
|
141
142
|
* parsing wholesale; the balanced scan below recovers the first value and
|
|
142
143
|
* drops the rest.
|
|
143
144
|
*/
|
|
@@ -198,30 +199,25 @@ function maxStepsSetting(request) {
|
|
|
198
199
|
return typeof maxSteps === "number" ? { stopWhen: (0, ai.stepCountIs)(maxSteps) } : {};
|
|
199
200
|
}
|
|
200
201
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* TS2742 ("inferred type cannot be named without a reference to …"). The exact
|
|
206
|
-
* ref keys survive, so `createAiSdkExecutors({ models })` and
|
|
207
|
-
* `setupAgent({ models })` still infer/autocomplete them.
|
|
202
|
+
* Splits a portable `"provider/model-id"` model ref (the convention JSON
|
|
203
|
+
* workflows and registry-less hosts use, e.g. `"openai/gpt-5.4-mini"`) into
|
|
204
|
+
* its parts. A ref with no `/` has no provider — `modelId` is the whole ref.
|
|
205
|
+
* The standard building block for a host's `resolveModel`:
|
|
208
206
|
*
|
|
209
207
|
* @example
|
|
210
208
|
* ```ts
|
|
211
|
-
*
|
|
212
|
-
* quick: openai('gpt-5.4-mini'),
|
|
213
|
-
* deep: openai('gpt-5.4'),
|
|
214
|
-
* });
|
|
215
|
-
* // typeof models === AiSdkModelMap<'quick' | 'deep'>
|
|
209
|
+
* const resolveModel = (ref: string) => openai(parseModelRef(ref).modelId);
|
|
216
210
|
* ```
|
|
217
211
|
*/
|
|
218
|
-
function
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
212
|
+
function parseModelRef(modelRef) {
|
|
213
|
+
const slash = modelRef.indexOf("/");
|
|
214
|
+
return slash === -1 ? {
|
|
215
|
+
provider: void 0,
|
|
216
|
+
modelId: modelRef
|
|
217
|
+
} : {
|
|
218
|
+
provider: modelRef.slice(0, slash),
|
|
219
|
+
modelId: modelRef.slice(slash + 1)
|
|
220
|
+
};
|
|
225
221
|
}
|
|
226
222
|
/** Resolves the host's `settings` option for one request. */
|
|
227
223
|
function callSettings(options, request) {
|
|
@@ -237,7 +233,7 @@ function resolveAiSdkModel(options, modelRef) {
|
|
|
237
233
|
return isModelWithSettings(entry) ? entry : { model: entry };
|
|
238
234
|
}
|
|
239
235
|
/**
|
|
240
|
-
* The `LanguageModel` inside a map entry, whichever form it takes. `
|
|
236
|
+
* The `LanguageModel` inside a map entry, whichever form it takes. `AiSdkModelMap`
|
|
241
237
|
* widens its return to {@link AiSdkModelMap}, so reading an entry out of the map
|
|
242
238
|
* to hand to a raw AI SDK call needs this to get past the union.
|
|
243
239
|
*/
|
|
@@ -265,7 +261,7 @@ function withJsonRepair(output) {
|
|
|
265
261
|
};
|
|
266
262
|
}
|
|
267
263
|
function truncated(request, info, partialOutput, cause) {
|
|
268
|
-
return new
|
|
264
|
+
return new require_text_logic.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
265
|
requestName: request.name ?? "(unnamed)",
|
|
270
266
|
...info?.requestId !== void 0 ? { requestId: info.requestId } : {},
|
|
271
267
|
...partialOutput !== void 0 ? { partialOutput } : {},
|
|
@@ -298,25 +294,25 @@ function createAiSdkExecutors(options) {
|
|
|
298
294
|
...maxStepsSetting(request)
|
|
299
295
|
};
|
|
300
296
|
if (isStructuredOutputRequest(request)) {
|
|
301
|
-
const
|
|
302
|
-
const structuredOutput = withJsonRepair(ai.Output.object({ schema:
|
|
297
|
+
const outputSchema = require_text_logic.providerOutputSchema(request.outputSchema, { reasoning: request.includeReasoning });
|
|
298
|
+
const structuredOutput = withJsonRepair(ai.Output.object({ schema: outputSchema }));
|
|
303
299
|
const result = await (0, ai.generateText)({
|
|
304
300
|
...common,
|
|
305
301
|
output: structuredOutput
|
|
306
302
|
}).catch((error) => {
|
|
307
303
|
throw ai.NoObjectGeneratedError.isInstance(error) && error.finishReason === "length" ? truncated(request, info, error.text, error) : error;
|
|
308
304
|
});
|
|
309
|
-
const
|
|
305
|
+
const parsed = (() => {
|
|
310
306
|
try {
|
|
311
307
|
return result.output;
|
|
312
308
|
} catch (error) {
|
|
313
309
|
throw result.finishReason === "length" ? truncated(request, info, result.text, error) : error;
|
|
314
310
|
}
|
|
315
311
|
})();
|
|
316
|
-
if (result.finishReason === "length") throw truncated(request, info,
|
|
312
|
+
if (result.finishReason === "length") throw truncated(request, info, parsed.result);
|
|
317
313
|
return {
|
|
318
|
-
|
|
319
|
-
...reasoning !== void 0 ? { reasoning } : {},
|
|
314
|
+
result: parsed.result,
|
|
315
|
+
...parsed.reasoning !== void 0 ? { reasoning: parsed.reasoning } : {},
|
|
320
316
|
usage: toAgentCallUsage(result.usage),
|
|
321
317
|
finishReason: toAgentFinishReason(result.finishReason),
|
|
322
318
|
toolCalls: result.toolCalls,
|
|
@@ -327,7 +323,7 @@ function createAiSdkExecutors(options) {
|
|
|
327
323
|
}
|
|
328
324
|
const result = await (0, ai.generateText)(common);
|
|
329
325
|
return {
|
|
330
|
-
|
|
326
|
+
result: result.text,
|
|
331
327
|
usage: toAgentCallUsage(result.usage),
|
|
332
328
|
finishReason: toAgentFinishReason(result.finishReason),
|
|
333
329
|
toolCalls: result.toolCalls,
|
|
@@ -348,7 +344,7 @@ function createAiSdkExecutors(options) {
|
|
|
348
344
|
});
|
|
349
345
|
for await (const chunk of result.textStream) info?.onChunk?.(chunk);
|
|
350
346
|
return {
|
|
351
|
-
|
|
347
|
+
result: await result.text,
|
|
352
348
|
usage: toAgentCallUsage(await result.usage),
|
|
353
349
|
finishReason: toAgentFinishReason(await result.finishReason),
|
|
354
350
|
messages: await result.responseMessages,
|
|
@@ -395,5 +391,5 @@ function createAiSdkExecutors(options) {
|
|
|
395
391
|
}
|
|
396
392
|
//#endregion
|
|
397
393
|
exports.createAiSdkExecutors = createAiSdkExecutors;
|
|
398
|
-
exports.
|
|
394
|
+
exports.parseModelRef = parseModelRef;
|
|
399
395
|
exports.toLanguageModel = toLanguageModel;
|
package/dist/ai-sdk.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as AgentTools, u as ChosenEvent } from "./types-
|
|
2
|
-
import {
|
|
1
|
+
import { s as AgentTools, u as ChosenEvent } from "./types-B1Qs2q3q.cjs";
|
|
2
|
+
import { M as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-BFEOxyxv.cjs";
|
|
3
3
|
import { FinishReason, LanguageModel, LanguageModelUsage, ModelMessage, ToolSet, TypedToolCall, TypedToolResult, generateText } from "ai";
|
|
4
4
|
|
|
5
5
|
//#region src/ai-sdk/mappers.d.ts
|
|
@@ -21,27 +21,23 @@ type AiSdkModelEntry = LanguageModel | {
|
|
|
21
21
|
model: LanguageModel;
|
|
22
22
|
settings?: AiSdkCallSettings;
|
|
23
23
|
};
|
|
24
|
-
/** AI SDK model registry: maps model refs (as used in `setupAgent({ models })`/`AgentTextRequest.model`) to AI SDK `LanguageModel` values, or to `{ model, settings }` pairs. The optional `TKey` parameter pins the ref keys (see {@link defineModels}); it defaults to `string`, so bare `AiSdkModelMap` stays `Record<string, AiSdkModelEntry>`. */
|
|
25
|
-
type AiSdkModelMap<TKey extends string = string> = Record<TKey, AiSdkModelEntry>;
|
|
26
24
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* TS2742 ("inferred type cannot be named without a reference to …"). The exact
|
|
32
|
-
* ref keys survive, so `createAiSdkExecutors({ models })` and
|
|
33
|
-
* `setupAgent({ models })` still infer/autocomplete them.
|
|
25
|
+
* Splits a portable `"provider/model-id"` model ref (the convention JSON
|
|
26
|
+
* workflows and registry-less hosts use, e.g. `"openai/gpt-5.4-mini"`) into
|
|
27
|
+
* its parts. A ref with no `/` has no provider — `modelId` is the whole ref.
|
|
28
|
+
* The standard building block for a host's `resolveModel`:
|
|
34
29
|
*
|
|
35
30
|
* @example
|
|
36
31
|
* ```ts
|
|
37
|
-
*
|
|
38
|
-
* quick: openai('gpt-5.4-mini'),
|
|
39
|
-
* deep: openai('gpt-5.4'),
|
|
40
|
-
* });
|
|
41
|
-
* // typeof models === AiSdkModelMap<'quick' | 'deep'>
|
|
32
|
+
* const resolveModel = (ref: string) => openai(parseModelRef(ref).modelId);
|
|
42
33
|
* ```
|
|
43
34
|
*/
|
|
44
|
-
declare function
|
|
35
|
+
declare function parseModelRef(modelRef: string): {
|
|
36
|
+
provider: string | undefined;
|
|
37
|
+
modelId: string;
|
|
38
|
+
};
|
|
39
|
+
/** AI SDK model registry: maps model refs (as used in `setupAgent({ models })`/`AgentTextRequest.model`) to AI SDK `LanguageModel` values, or to `{ model, settings }` pairs. The optional `TKey` parameter pins the ref keys; it defaults to `string`, so bare `AiSdkModelMap` stays `Record<string, AiSdkModelEntry>`. */
|
|
40
|
+
type AiSdkModelMap<TKey extends string = string> = Record<TKey, AiSdkModelEntry>;
|
|
45
41
|
/**
|
|
46
42
|
* Per-call AI SDK settings a host can apply on top of what the machine asked
|
|
47
43
|
* for — reasoning effort, `providerOptions`, and anything else the SDK's call
|
|
@@ -75,25 +71,25 @@ type CreateAiSdkExecutorsOptions<TModels extends AiSdkModelMap = AiSdkModelMap>
|
|
|
75
71
|
resolveModel: (modelRef: string) => LanguageModel;
|
|
76
72
|
});
|
|
77
73
|
/**
|
|
78
|
-
* The `LanguageModel` inside a map entry, whichever form it takes. `
|
|
74
|
+
* The `LanguageModel` inside a map entry, whichever form it takes. `AiSdkModelMap`
|
|
79
75
|
* widens its return to {@link AiSdkModelMap}, so reading an entry out of the map
|
|
80
76
|
* to hand to a raw AI SDK call needs this to get past the union.
|
|
81
77
|
*/
|
|
82
78
|
declare function toLanguageModel(entry: AiSdkModelEntry): LanguageModel;
|
|
83
79
|
/**
|
|
84
|
-
* Raw result shape from {@link AiSdkExecutors.generateText} —
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* `
|
|
90
|
-
*
|
|
80
|
+
* Raw result shape from {@link AiSdkExecutors.generateText} — `result` (the
|
|
81
|
+
* validated structured object for structured-output requests, or the
|
|
82
|
+
* accumulated text string otherwise) and `messages`, plus the AI SDK call
|
|
83
|
+
* metadata. Core reads `result`, `messages` and `usage`; everything else flows
|
|
84
|
+
* verbatim to `runAgent`'s `onResult(request, { raw })`, so
|
|
85
|
+
* `raw as AiSdkGenerateResult` is the supported cast for token accounting and
|
|
86
|
+
* tracing.
|
|
91
87
|
*/
|
|
92
88
|
type AiSdkGenerateResult = {
|
|
93
|
-
|
|
89
|
+
result: unknown;
|
|
94
90
|
/** The model's reasoning, present only when the request opted in via
|
|
95
|
-
* `reasoning: true` and the model produced it (see
|
|
96
|
-
*
|
|
91
|
+
* `reasoning: true` and the model produced it (see
|
|
92
|
+
* {@link providerOutputSchema}). Never enters machine context/output. */
|
|
97
93
|
reasoning?: string;
|
|
98
94
|
/** The call's token usage. Its flat `inputTokens`/`outputTokens`/`totalTokens`/
|
|
99
95
|
* `reasoningTokens`/`cachedInputTokens` fields are what `runAgent` folds into
|
|
@@ -106,9 +102,9 @@ type AiSdkGenerateResult = {
|
|
|
106
102
|
messages: ModelMessage[]; /** The untouched AI SDK result. */
|
|
107
103
|
raw: unknown;
|
|
108
104
|
};
|
|
109
|
-
/** Raw result shape from {@link AiSdkExecutors.streamText} —
|
|
105
|
+
/** Raw result shape from {@link AiSdkExecutors.streamText} — `result` is the fully-accumulated text once the stream finishes (chunks are delivered separately via `onChunk`), plus the response messages and the stream's final usage/finish metadata for `onResult`. */
|
|
110
106
|
type AiSdkStreamResult = {
|
|
111
|
-
|
|
107
|
+
result: string; /** The stream's final (awaited) usage; aggregated into the run result's `AgentUsage`. */
|
|
112
108
|
usage: AiSdkCallUsage; /** Why the stream stopped, normalized to the portable {@link AgentFinishReason}. The SDK's own value stays on `raw`. */
|
|
113
109
|
finishReason: AgentFinishReason; /** AI SDK response messages, including tool calls/results from every step. */
|
|
114
110
|
messages: ModelMessage[]; /** The untouched AI SDK result. */
|
|
@@ -148,4 +144,4 @@ interface AiSdkExecutors {
|
|
|
148
144
|
*/
|
|
149
145
|
declare function createAiSdkExecutors<TModels extends AiSdkModelMap>(options: CreateAiSdkExecutorsOptions<TModels>): AiSdkExecutors;
|
|
150
146
|
//#endregion
|
|
151
|
-
export { AiSdkCallSettings, AiSdkDecideResult, AiSdkExecutors, AiSdkGenerateResult, AiSdkModelEntry, AiSdkModelMap, AiSdkStreamResult, CreateAiSdkExecutorsOptions, createAiSdkExecutors,
|
|
147
|
+
export { AiSdkCallSettings, AiSdkDecideResult, AiSdkExecutors, AiSdkGenerateResult, AiSdkModelEntry, AiSdkModelMap, AiSdkStreamResult, CreateAiSdkExecutorsOptions, createAiSdkExecutors, parseModelRef, toLanguageModel };
|
package/dist/ai-sdk.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as AgentTools, u as ChosenEvent } from "./types-
|
|
2
|
-
import {
|
|
1
|
+
import { s as AgentTools, u as ChosenEvent } from "./types-tA3SdczG.mjs";
|
|
2
|
+
import { M as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-hZSiRUo1.mjs";
|
|
3
3
|
import { FinishReason, LanguageModel, LanguageModelUsage, ModelMessage, ToolSet, TypedToolCall, TypedToolResult, generateText } from "ai";
|
|
4
4
|
|
|
5
5
|
//#region src/ai-sdk/mappers.d.ts
|
|
@@ -21,27 +21,23 @@ type AiSdkModelEntry = LanguageModel | {
|
|
|
21
21
|
model: LanguageModel;
|
|
22
22
|
settings?: AiSdkCallSettings;
|
|
23
23
|
};
|
|
24
|
-
/** AI SDK model registry: maps model refs (as used in `setupAgent({ models })`/`AgentTextRequest.model`) to AI SDK `LanguageModel` values, or to `{ model, settings }` pairs. The optional `TKey` parameter pins the ref keys (see {@link defineModels}); it defaults to `string`, so bare `AiSdkModelMap` stays `Record<string, AiSdkModelEntry>`. */
|
|
25
|
-
type AiSdkModelMap<TKey extends string = string> = Record<TKey, AiSdkModelEntry>;
|
|
26
24
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* TS2742 ("inferred type cannot be named without a reference to …"). The exact
|
|
32
|
-
* ref keys survive, so `createAiSdkExecutors({ models })` and
|
|
33
|
-
* `setupAgent({ models })` still infer/autocomplete them.
|
|
25
|
+
* Splits a portable `"provider/model-id"` model ref (the convention JSON
|
|
26
|
+
* workflows and registry-less hosts use, e.g. `"openai/gpt-5.4-mini"`) into
|
|
27
|
+
* its parts. A ref with no `/` has no provider — `modelId` is the whole ref.
|
|
28
|
+
* The standard building block for a host's `resolveModel`:
|
|
34
29
|
*
|
|
35
30
|
* @example
|
|
36
31
|
* ```ts
|
|
37
|
-
*
|
|
38
|
-
* quick: openai('gpt-5.4-mini'),
|
|
39
|
-
* deep: openai('gpt-5.4'),
|
|
40
|
-
* });
|
|
41
|
-
* // typeof models === AiSdkModelMap<'quick' | 'deep'>
|
|
32
|
+
* const resolveModel = (ref: string) => openai(parseModelRef(ref).modelId);
|
|
42
33
|
* ```
|
|
43
34
|
*/
|
|
44
|
-
declare function
|
|
35
|
+
declare function parseModelRef(modelRef: string): {
|
|
36
|
+
provider: string | undefined;
|
|
37
|
+
modelId: string;
|
|
38
|
+
};
|
|
39
|
+
/** AI SDK model registry: maps model refs (as used in `setupAgent({ models })`/`AgentTextRequest.model`) to AI SDK `LanguageModel` values, or to `{ model, settings }` pairs. The optional `TKey` parameter pins the ref keys; it defaults to `string`, so bare `AiSdkModelMap` stays `Record<string, AiSdkModelEntry>`. */
|
|
40
|
+
type AiSdkModelMap<TKey extends string = string> = Record<TKey, AiSdkModelEntry>;
|
|
45
41
|
/**
|
|
46
42
|
* Per-call AI SDK settings a host can apply on top of what the machine asked
|
|
47
43
|
* for — reasoning effort, `providerOptions`, and anything else the SDK's call
|
|
@@ -75,25 +71,25 @@ type CreateAiSdkExecutorsOptions<TModels extends AiSdkModelMap = AiSdkModelMap>
|
|
|
75
71
|
resolveModel: (modelRef: string) => LanguageModel;
|
|
76
72
|
});
|
|
77
73
|
/**
|
|
78
|
-
* The `LanguageModel` inside a map entry, whichever form it takes. `
|
|
74
|
+
* The `LanguageModel` inside a map entry, whichever form it takes. `AiSdkModelMap`
|
|
79
75
|
* widens its return to {@link AiSdkModelMap}, so reading an entry out of the map
|
|
80
76
|
* to hand to a raw AI SDK call needs this to get past the union.
|
|
81
77
|
*/
|
|
82
78
|
declare function toLanguageModel(entry: AiSdkModelEntry): LanguageModel;
|
|
83
79
|
/**
|
|
84
|
-
* Raw result shape from {@link AiSdkExecutors.generateText} —
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* `
|
|
90
|
-
*
|
|
80
|
+
* Raw result shape from {@link AiSdkExecutors.generateText} — `result` (the
|
|
81
|
+
* validated structured object for structured-output requests, or the
|
|
82
|
+
* accumulated text string otherwise) and `messages`, plus the AI SDK call
|
|
83
|
+
* metadata. Core reads `result`, `messages` and `usage`; everything else flows
|
|
84
|
+
* verbatim to `runAgent`'s `onResult(request, { raw })`, so
|
|
85
|
+
* `raw as AiSdkGenerateResult` is the supported cast for token accounting and
|
|
86
|
+
* tracing.
|
|
91
87
|
*/
|
|
92
88
|
type AiSdkGenerateResult = {
|
|
93
|
-
|
|
89
|
+
result: unknown;
|
|
94
90
|
/** The model's reasoning, present only when the request opted in via
|
|
95
|
-
* `reasoning: true` and the model produced it (see
|
|
96
|
-
*
|
|
91
|
+
* `reasoning: true` and the model produced it (see
|
|
92
|
+
* {@link providerOutputSchema}). Never enters machine context/output. */
|
|
97
93
|
reasoning?: string;
|
|
98
94
|
/** The call's token usage. Its flat `inputTokens`/`outputTokens`/`totalTokens`/
|
|
99
95
|
* `reasoningTokens`/`cachedInputTokens` fields are what `runAgent` folds into
|
|
@@ -106,9 +102,9 @@ type AiSdkGenerateResult = {
|
|
|
106
102
|
messages: ModelMessage[]; /** The untouched AI SDK result. */
|
|
107
103
|
raw: unknown;
|
|
108
104
|
};
|
|
109
|
-
/** Raw result shape from {@link AiSdkExecutors.streamText} —
|
|
105
|
+
/** Raw result shape from {@link AiSdkExecutors.streamText} — `result` is the fully-accumulated text once the stream finishes (chunks are delivered separately via `onChunk`), plus the response messages and the stream's final usage/finish metadata for `onResult`. */
|
|
110
106
|
type AiSdkStreamResult = {
|
|
111
|
-
|
|
107
|
+
result: string; /** The stream's final (awaited) usage; aggregated into the run result's `AgentUsage`. */
|
|
112
108
|
usage: AiSdkCallUsage; /** Why the stream stopped, normalized to the portable {@link AgentFinishReason}. The SDK's own value stays on `raw`. */
|
|
113
109
|
finishReason: AgentFinishReason; /** AI SDK response messages, including tool calls/results from every step. */
|
|
114
110
|
messages: ModelMessage[]; /** The untouched AI SDK result. */
|
|
@@ -148,4 +144,4 @@ interface AiSdkExecutors {
|
|
|
148
144
|
*/
|
|
149
145
|
declare function createAiSdkExecutors<TModels extends AiSdkModelMap>(options: CreateAiSdkExecutorsOptions<TModels>): AiSdkExecutors;
|
|
150
146
|
//#endregion
|
|
151
|
-
export { AiSdkCallSettings, AiSdkDecideResult, AiSdkExecutors, AiSdkGenerateResult, AiSdkModelEntry, AiSdkModelMap, AiSdkStreamResult, CreateAiSdkExecutorsOptions, createAiSdkExecutors,
|
|
147
|
+
export { AiSdkCallSettings, AiSdkDecideResult, AiSdkExecutors, AiSdkGenerateResult, AiSdkModelEntry, AiSdkModelMap, AiSdkStreamResult, CreateAiSdkExecutorsOptions, createAiSdkExecutors, parseModelRef, toLanguageModel };
|
package/dist/ai-sdk.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as isStandardSchema, U as AgentTruncatedError, g as providerOutputSchema, l as getAgentOutputMode } from "./text-logic-Bl_ZRxDi.mjs";
|
|
2
|
+
import { o as renderDecisionAttempts } from "./decision-DzSv1NpD.mjs";
|
|
2
3
|
import { NoObjectGeneratedError, Output, generateText, stepCountIs, streamText, tool } from "ai";
|
|
3
4
|
//#region src/ai-sdk/mappers.ts
|
|
4
5
|
/**
|
|
@@ -135,7 +136,7 @@ function isStructuredOutputRequest(request) {
|
|
|
135
136
|
* Extracts the first complete top-level JSON value from `text`, or returns
|
|
136
137
|
* `undefined` when there is nothing to repair (no complete value, or the value
|
|
137
138
|
* already spans the whole text). Models occasionally emit two structured-output
|
|
138
|
-
*
|
|
139
|
+
* objects back to back (`{"result":{…}}{"result":{…}}`), which fails JSON
|
|
139
140
|
* parsing wholesale; the balanced scan below recovers the first value and
|
|
140
141
|
* drops the rest.
|
|
141
142
|
*/
|
|
@@ -196,30 +197,25 @@ function maxStepsSetting(request) {
|
|
|
196
197
|
return typeof maxSteps === "number" ? { stopWhen: stepCountIs(maxSteps) } : {};
|
|
197
198
|
}
|
|
198
199
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* TS2742 ("inferred type cannot be named without a reference to …"). The exact
|
|
204
|
-
* ref keys survive, so `createAiSdkExecutors({ models })` and
|
|
205
|
-
* `setupAgent({ models })` still infer/autocomplete them.
|
|
200
|
+
* Splits a portable `"provider/model-id"` model ref (the convention JSON
|
|
201
|
+
* workflows and registry-less hosts use, e.g. `"openai/gpt-5.4-mini"`) into
|
|
202
|
+
* its parts. A ref with no `/` has no provider — `modelId` is the whole ref.
|
|
203
|
+
* The standard building block for a host's `resolveModel`:
|
|
206
204
|
*
|
|
207
205
|
* @example
|
|
208
206
|
* ```ts
|
|
209
|
-
*
|
|
210
|
-
* quick: openai('gpt-5.4-mini'),
|
|
211
|
-
* deep: openai('gpt-5.4'),
|
|
212
|
-
* });
|
|
213
|
-
* // typeof models === AiSdkModelMap<'quick' | 'deep'>
|
|
207
|
+
* const resolveModel = (ref: string) => openai(parseModelRef(ref).modelId);
|
|
214
208
|
* ```
|
|
215
209
|
*/
|
|
216
|
-
function
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
210
|
+
function parseModelRef(modelRef) {
|
|
211
|
+
const slash = modelRef.indexOf("/");
|
|
212
|
+
return slash === -1 ? {
|
|
213
|
+
provider: void 0,
|
|
214
|
+
modelId: modelRef
|
|
215
|
+
} : {
|
|
216
|
+
provider: modelRef.slice(0, slash),
|
|
217
|
+
modelId: modelRef.slice(slash + 1)
|
|
218
|
+
};
|
|
223
219
|
}
|
|
224
220
|
/** Resolves the host's `settings` option for one request. */
|
|
225
221
|
function callSettings(options, request) {
|
|
@@ -235,7 +231,7 @@ function resolveAiSdkModel(options, modelRef) {
|
|
|
235
231
|
return isModelWithSettings(entry) ? entry : { model: entry };
|
|
236
232
|
}
|
|
237
233
|
/**
|
|
238
|
-
* The `LanguageModel` inside a map entry, whichever form it takes. `
|
|
234
|
+
* The `LanguageModel` inside a map entry, whichever form it takes. `AiSdkModelMap`
|
|
239
235
|
* widens its return to {@link AiSdkModelMap}, so reading an entry out of the map
|
|
240
236
|
* to hand to a raw AI SDK call needs this to get past the union.
|
|
241
237
|
*/
|
|
@@ -296,25 +292,25 @@ function createAiSdkExecutors(options) {
|
|
|
296
292
|
...maxStepsSetting(request)
|
|
297
293
|
};
|
|
298
294
|
if (isStructuredOutputRequest(request)) {
|
|
299
|
-
const
|
|
300
|
-
const structuredOutput = withJsonRepair(Output.object({ schema:
|
|
295
|
+
const outputSchema = providerOutputSchema(request.outputSchema, { reasoning: request.includeReasoning });
|
|
296
|
+
const structuredOutput = withJsonRepair(Output.object({ schema: outputSchema }));
|
|
301
297
|
const result = await generateText({
|
|
302
298
|
...common,
|
|
303
299
|
output: structuredOutput
|
|
304
300
|
}).catch((error) => {
|
|
305
301
|
throw NoObjectGeneratedError.isInstance(error) && error.finishReason === "length" ? truncated(request, info, error.text, error) : error;
|
|
306
302
|
});
|
|
307
|
-
const
|
|
303
|
+
const parsed = (() => {
|
|
308
304
|
try {
|
|
309
305
|
return result.output;
|
|
310
306
|
} catch (error) {
|
|
311
307
|
throw result.finishReason === "length" ? truncated(request, info, result.text, error) : error;
|
|
312
308
|
}
|
|
313
309
|
})();
|
|
314
|
-
if (result.finishReason === "length") throw truncated(request, info,
|
|
310
|
+
if (result.finishReason === "length") throw truncated(request, info, parsed.result);
|
|
315
311
|
return {
|
|
316
|
-
|
|
317
|
-
...reasoning !== void 0 ? { reasoning } : {},
|
|
312
|
+
result: parsed.result,
|
|
313
|
+
...parsed.reasoning !== void 0 ? { reasoning: parsed.reasoning } : {},
|
|
318
314
|
usage: toAgentCallUsage(result.usage),
|
|
319
315
|
finishReason: toAgentFinishReason(result.finishReason),
|
|
320
316
|
toolCalls: result.toolCalls,
|
|
@@ -325,7 +321,7 @@ function createAiSdkExecutors(options) {
|
|
|
325
321
|
}
|
|
326
322
|
const result = await generateText(common);
|
|
327
323
|
return {
|
|
328
|
-
|
|
324
|
+
result: result.text,
|
|
329
325
|
usage: toAgentCallUsage(result.usage),
|
|
330
326
|
finishReason: toAgentFinishReason(result.finishReason),
|
|
331
327
|
toolCalls: result.toolCalls,
|
|
@@ -346,7 +342,7 @@ function createAiSdkExecutors(options) {
|
|
|
346
342
|
});
|
|
347
343
|
for await (const chunk of result.textStream) info?.onChunk?.(chunk);
|
|
348
344
|
return {
|
|
349
|
-
|
|
345
|
+
result: await result.text,
|
|
350
346
|
usage: toAgentCallUsage(await result.usage),
|
|
351
347
|
finishReason: toAgentFinishReason(await result.finishReason),
|
|
352
348
|
messages: await result.responseMessages,
|
|
@@ -392,4 +388,4 @@ function createAiSdkExecutors(options) {
|
|
|
392
388
|
};
|
|
393
389
|
}
|
|
394
390
|
//#endregion
|
|
395
|
-
export { createAiSdkExecutors,
|
|
391
|
+
export { createAiSdkExecutors, parseModelRef, toLanguageModel };
|