ai 7.0.127 → 7.0.128
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/CHANGELOG.md +18 -0
- package/dist/index.d.ts +213 -153
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +239 -178
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +278 -68
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +340 -61
- package/dist/internal/index.js.map +1 -1
- package/dist/test/index.d.ts +25 -17
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +27 -21
- package/dist/test/index.js.map +1 -1
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +1 -1
- package/docs/02-getting-started/07-expo.mdx +1 -1
- package/docs/03-agents/07-workflow-agent.mdx +80 -12
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +44 -0
- package/docs/03-ai-sdk-core/{32-evaluation.mdx → 32-decisions.mdx} +49 -49
- package/docs/03-ai-sdk-core/35-image-generation.mdx +1 -1
- package/docs/03-ai-sdk-core/45-provider-management.mdx +8 -8
- package/docs/03-ai-sdk-core/60-telemetry.mdx +40 -31
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +21 -22
- package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +2 -2
- package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +74 -0
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +58 -4
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +11 -11
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +9 -9
- package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +24 -8
- package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +1 -1
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +1 -0
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +39 -2
- package/docs/07-reference/05-ai-sdk-errors/ai-decision-unsupported-question-type-error.mdx +31 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +3 -3
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +3 -3
- package/docs/08-migration-guides/23-migration-guide-7-0.mdx +1 -1
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1 -1
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +2 -2
- package/package.json +12 -12
- package/src/decide/decide-events.ts +129 -0
- package/src/{evaluate/evaluate.ts → decide/decide.ts} +36 -38
- package/src/decide/decision-provider.ts +11 -0
- package/src/decide/decision-result.ts +39 -0
- package/src/decide/index.ts +64 -0
- package/src/{evaluate → decide}/restricted-telemetry-dispatcher.ts +7 -7
- package/src/{evaluate/validate-evaluation.ts → decide/validate-decision.ts} +9 -9
- package/src/error/index.ts +10 -1
- package/src/generate-speech/generated-audio-file.ts +5 -4
- package/src/generate-text/default-generate-text-result.ts +127 -0
- package/src/generate-text/generate-text.ts +2 -122
- package/src/global.ts +1 -1
- package/src/index.ts +1 -1
- package/src/middleware/extract-reasoning-middleware.ts +25 -6
- package/src/model/resolve-model.ts +45 -14
- package/src/registry/custom-provider.ts +38 -26
- package/src/registry/index.ts +13 -1
- package/src/registry/no-such-provider-error.ts +2 -0
- package/src/registry/provider-registry.ts +56 -29
- package/src/telemetry/create-telemetry-dispatcher.ts +17 -5
- package/src/telemetry/telemetry.ts +35 -19
- package/src/telemetry/tracing-channel.ts +1 -1
- package/src/test/decision-mock-model-v4.ts +35 -0
- package/src/transcribe/transcribe.ts +1 -1
- package/src/ui/chat.ts +9 -1
- package/src/ui/process-ui-message-stream.ts +21 -0
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +0 -74
- package/docs/07-reference/05-ai-sdk-errors/ai-evaluation-unsupported-question-type-error.mdx +0 -31
- package/src/evaluate/evaluate-events.ts +0 -131
- package/src/evaluate/evaluation-provider.ts +0 -6
- package/src/evaluate/evaluation-result.ts +0 -39
- package/src/evaluate/index.ts +0 -13
- package/src/test/evaluation-mock-model-v4.ts +0 -27
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
2
|
import { GatewayAuthenticationError, GatewayError, createGateway, gateway, gateway as gateway$1 } from "@ai-sdk/gateway";
|
|
3
3
|
import { DEFAULT_MAX_DOWNLOAD_SIZE, DelayedPromise, DownloadError, DownloadError as DownloadError$1, EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, asArray, asSchema, asSchema as asSchema$1, cancelResponseBody, convertBase64ToUint8Array, convertUint8ArrayToBase64, createIdGenerator, createIdGenerator as createIdGenerator$1, delay, detectMediaType, dynamicTool, executeTool, experimental_getToolCaller, experimental_toolCaller, fetchUntrustedUrl, filterNullable, generateId, generateId as generateId$1, getErrorMessage, getRuntimeEnvironmentUserAgent, isAbortError, isBuffer, isExecutableTool, isFullMediaType, isNonNullable, isProviderReference, isProviderStreamError, isUrlSupported, jsonSchema, jsonSchema as jsonSchema$1, lazySchema, normalizeHeaders, parseJsonEventStream, parseJsonEventStream as parseJsonEventStream$1, readResponseWithSizeLimit, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, tool, tool as tool$1, validateTypes, withUserAgentSuffix, zodSchema, zodSchema as zodSchema$1 } from "@ai-sdk/provider-utils";
|
|
4
|
-
import { AISDKError, AISDKError as AISDKError$1, APICallError, APICallError as APICallError$1, EmptyResponseBodyError, EmptyResponseBodyError as EmptyResponseBodyError$1,
|
|
4
|
+
import { AISDKError, AISDKError as AISDKError$1, APICallError, APICallError as APICallError$1, EmptyResponseBodyError, EmptyResponseBodyError as EmptyResponseBodyError$1, Experimental_DecisionUnsupportedQuestionTypeError, Experimental_DecisionUnsupportedQuestionTypeError as Experimental_DecisionUnsupportedQuestionTypeError$1, InvalidArgumentError as InvalidArgumentError$1, InvalidPromptError, InvalidPromptError as InvalidPromptError$1, InvalidResponseDataError, InvalidResponseDataError as InvalidResponseDataError$1, JSONParseError, JSONParseError as JSONParseError$1, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchModelError as NoSuchModelError$1, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, TypeValidationError as TypeValidationError$1, UnsupportedFunctionalityError, UnsupportedFunctionalityError as UnsupportedFunctionalityError$1, getErrorMessage as getErrorMessage$1, isJSONArray, isJSONObject } from "@ai-sdk/provider";
|
|
5
5
|
import { array, boolean, custom, discriminatedUnion, enum as enum$1, instanceof as instanceof$1, lazy, literal, looseObject, never, null as null$1, number, object, record, string, union, unknown } from "zod/v4";
|
|
6
6
|
//#region src/error/invalid-argument-error.ts
|
|
7
7
|
const name$23 = "AI_InvalidArgumentError";
|
|
@@ -528,6 +528,10 @@ var RetryError = class extends AISDKError$1 {
|
|
|
528
528
|
}
|
|
529
529
|
};
|
|
530
530
|
//#endregion
|
|
531
|
+
//#region src/error/index.ts
|
|
532
|
+
/** @deprecated Use `Experimental_DecisionUnsupportedQuestionTypeError` instead. */
|
|
533
|
+
const Experimental_EvaluationUnsupportedQuestionTypeError = Experimental_DecisionUnsupportedQuestionTypeError$1;
|
|
534
|
+
//#endregion
|
|
531
535
|
//#region src/logger/log-warnings.ts
|
|
532
536
|
/**
|
|
533
537
|
* Formats a warning object into a human-readable string with clear AI SDK branding.
|
|
@@ -1057,18 +1061,19 @@ function resolveRerankingModel(model) {
|
|
|
1057
1061
|
}
|
|
1058
1062
|
return asRerankingModelV4(model);
|
|
1059
1063
|
}
|
|
1060
|
-
function
|
|
1064
|
+
function resolveDecisionModel(model) {
|
|
1061
1065
|
if (typeof model === "string") {
|
|
1062
1066
|
const provider = globalThis.AI_SDK_DEFAULT_PROVIDER ?? gateway$1;
|
|
1063
|
-
|
|
1067
|
+
const factory = provider.decisionModel ?? provider.evaluationModel;
|
|
1068
|
+
if (typeof factory !== "function") throw new NoSuchModelError$1({
|
|
1064
1069
|
modelId: model,
|
|
1065
|
-
modelType: "
|
|
1066
|
-
message: "The default provider does not support
|
|
1070
|
+
modelType: "decisionModel",
|
|
1071
|
+
message: "The default provider does not support decision models. Pass a decision model instance or configure AI_SDK_DEFAULT_PROVIDER with a decisionModel method."
|
|
1067
1072
|
});
|
|
1068
|
-
const resolvedModel =
|
|
1073
|
+
const resolvedModel = factory.call(provider, model);
|
|
1069
1074
|
if (resolvedModel == null) throw new NoSuchModelError$1({
|
|
1070
1075
|
modelId: model,
|
|
1071
|
-
modelType: "
|
|
1076
|
+
modelType: "decisionModel"
|
|
1072
1077
|
});
|
|
1073
1078
|
model = resolvedModel;
|
|
1074
1079
|
}
|
|
@@ -1077,11 +1082,31 @@ function resolveEvaluationModel(model) {
|
|
|
1077
1082
|
provider: model.provider,
|
|
1078
1083
|
modelId: model.modelId
|
|
1079
1084
|
});
|
|
1080
|
-
return model;
|
|
1085
|
+
if ("doDecide" in model) return model;
|
|
1086
|
+
const legacyModel = model;
|
|
1087
|
+
return {
|
|
1088
|
+
specificationVersion: legacyModel.specificationVersion,
|
|
1089
|
+
provider: legacyModel.provider,
|
|
1090
|
+
modelId: legacyModel.modelId,
|
|
1091
|
+
supportedQuestionTypes: legacyModel.supportedQuestionTypes,
|
|
1092
|
+
doDecide: (options) => legacyModel.doEvaluate(options)
|
|
1093
|
+
};
|
|
1081
1094
|
}
|
|
1082
1095
|
function getGlobalProvider() {
|
|
1083
1096
|
return asProviderV4(globalThis.AI_SDK_DEFAULT_PROVIDER ?? gateway$1);
|
|
1084
1097
|
}
|
|
1098
|
+
/** Internal adapter for deprecated provider factories. */
|
|
1099
|
+
function asEvaluationModel(model) {
|
|
1100
|
+
if ("doEvaluate" in model && typeof model.doEvaluate === "function") return model;
|
|
1101
|
+
return {
|
|
1102
|
+
specificationVersion: model.specificationVersion,
|
|
1103
|
+
provider: model.provider,
|
|
1104
|
+
modelId: model.modelId,
|
|
1105
|
+
supportedQuestionTypes: model.supportedQuestionTypes,
|
|
1106
|
+
doDecide: (options) => model.doDecide(options),
|
|
1107
|
+
doEvaluate: (options) => model.doDecide(options)
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1085
1110
|
//#endregion
|
|
1086
1111
|
//#region src/prompt/clone-model-message.ts
|
|
1087
1112
|
/**
|
|
@@ -1102,7 +1127,7 @@ function cloneValue(value) {
|
|
|
1102
1127
|
}
|
|
1103
1128
|
//#endregion
|
|
1104
1129
|
//#region src/version.ts
|
|
1105
|
-
const VERSION = "7.0.
|
|
1130
|
+
const VERSION = "7.0.128";
|
|
1106
1131
|
//#endregion
|
|
1107
1132
|
//#region src/util/download/download.ts
|
|
1108
1133
|
/**
|
|
@@ -3236,6 +3261,122 @@ function filterActiveTools({ tools, activeTools }) {
|
|
|
3236
3261
|
return Object.fromEntries(Object.entries(tools).filter(([name]) => activeTools.includes(name)));
|
|
3237
3262
|
}
|
|
3238
3263
|
//#endregion
|
|
3264
|
+
//#region src/generate-text/reasoning-output.ts
|
|
3265
|
+
function unwrapReasoningFileData(data) {
|
|
3266
|
+
if (typeof data === "object" && data !== null && "type" in data) return data.type === "data" ? data.data : data.url;
|
|
3267
|
+
return data;
|
|
3268
|
+
}
|
|
3269
|
+
function convertFromReasoningOutputs(parts) {
|
|
3270
|
+
return parts.map((part) => {
|
|
3271
|
+
if (part.type === "reasoning") return {
|
|
3272
|
+
type: "reasoning",
|
|
3273
|
+
text: part.text,
|
|
3274
|
+
...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
|
|
3275
|
+
};
|
|
3276
|
+
return {
|
|
3277
|
+
type: "reasoning-file",
|
|
3278
|
+
data: part.file.base64,
|
|
3279
|
+
mediaType: part.file.mediaType,
|
|
3280
|
+
...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
|
|
3281
|
+
};
|
|
3282
|
+
});
|
|
3283
|
+
}
|
|
3284
|
+
function convertToReasoningOutputs(parts) {
|
|
3285
|
+
return parts.map((part) => {
|
|
3286
|
+
if (part.type === "reasoning") return {
|
|
3287
|
+
type: "reasoning",
|
|
3288
|
+
text: part.text,
|
|
3289
|
+
...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
|
|
3290
|
+
};
|
|
3291
|
+
const rawData = unwrapReasoningFileData(part.data);
|
|
3292
|
+
return {
|
|
3293
|
+
type: "reasoning-file",
|
|
3294
|
+
file: new DefaultGeneratedFile({
|
|
3295
|
+
data: rawData instanceof ArrayBuffer ? new Uint8Array(rawData) : rawData instanceof URL ? rawData.toString() : rawData,
|
|
3296
|
+
mediaType: part.mediaType
|
|
3297
|
+
}),
|
|
3298
|
+
...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
|
|
3299
|
+
};
|
|
3300
|
+
});
|
|
3301
|
+
}
|
|
3302
|
+
//#endregion
|
|
3303
|
+
//#region src/generate-text/default-generate-text-result.ts
|
|
3304
|
+
var DefaultGenerateTextResult = class {
|
|
3305
|
+
constructor(options) {
|
|
3306
|
+
this.initialResponseMessages = options.initialResponseMessages;
|
|
3307
|
+
this.steps = options.steps;
|
|
3308
|
+
this._output = options.output;
|
|
3309
|
+
this.totalUsage = options.totalUsage;
|
|
3310
|
+
}
|
|
3311
|
+
get finalStep() {
|
|
3312
|
+
return this.steps.at(-1);
|
|
3313
|
+
}
|
|
3314
|
+
get content() {
|
|
3315
|
+
return this.steps.flatMap((step) => step.content);
|
|
3316
|
+
}
|
|
3317
|
+
get text() {
|
|
3318
|
+
return this.finalStep.text;
|
|
3319
|
+
}
|
|
3320
|
+
get files() {
|
|
3321
|
+
return this.steps.flatMap((step) => step.files);
|
|
3322
|
+
}
|
|
3323
|
+
get reasoningText() {
|
|
3324
|
+
return this.finalStep.reasoningText;
|
|
3325
|
+
}
|
|
3326
|
+
get reasoning() {
|
|
3327
|
+
return convertToReasoningOutputs(this.finalStep.reasoning);
|
|
3328
|
+
}
|
|
3329
|
+
get toolCalls() {
|
|
3330
|
+
return this.steps.flatMap((step) => step.toolCalls);
|
|
3331
|
+
}
|
|
3332
|
+
get staticToolCalls() {
|
|
3333
|
+
return this.steps.flatMap((step) => step.staticToolCalls);
|
|
3334
|
+
}
|
|
3335
|
+
get dynamicToolCalls() {
|
|
3336
|
+
return this.steps.flatMap((step) => step.dynamicToolCalls);
|
|
3337
|
+
}
|
|
3338
|
+
get toolResults() {
|
|
3339
|
+
return this.steps.flatMap((step) => step.toolResults);
|
|
3340
|
+
}
|
|
3341
|
+
get staticToolResults() {
|
|
3342
|
+
return this.steps.flatMap((step) => step.staticToolResults);
|
|
3343
|
+
}
|
|
3344
|
+
get dynamicToolResults() {
|
|
3345
|
+
return this.steps.flatMap((step) => step.dynamicToolResults);
|
|
3346
|
+
}
|
|
3347
|
+
get sources() {
|
|
3348
|
+
return this.steps.flatMap((step) => step.sources);
|
|
3349
|
+
}
|
|
3350
|
+
get finishReason() {
|
|
3351
|
+
return this.finalStep.finishReason;
|
|
3352
|
+
}
|
|
3353
|
+
get rawFinishReason() {
|
|
3354
|
+
return this.finalStep.rawFinishReason;
|
|
3355
|
+
}
|
|
3356
|
+
get warnings() {
|
|
3357
|
+
return this.steps.flatMap((step) => step.warnings ?? []);
|
|
3358
|
+
}
|
|
3359
|
+
get providerMetadata() {
|
|
3360
|
+
return this.finalStep.providerMetadata;
|
|
3361
|
+
}
|
|
3362
|
+
get response() {
|
|
3363
|
+
return this.finalStep.response;
|
|
3364
|
+
}
|
|
3365
|
+
get responseMessages() {
|
|
3366
|
+
return [...this.initialResponseMessages, ...this.steps.flatMap((step) => step.response.messages)];
|
|
3367
|
+
}
|
|
3368
|
+
get request() {
|
|
3369
|
+
return this.finalStep.request;
|
|
3370
|
+
}
|
|
3371
|
+
get usage() {
|
|
3372
|
+
return this.totalUsage;
|
|
3373
|
+
}
|
|
3374
|
+
get output() {
|
|
3375
|
+
if (this._output == null) throw new NoOutputGeneratedError();
|
|
3376
|
+
return this._output;
|
|
3377
|
+
}
|
|
3378
|
+
};
|
|
3379
|
+
//#endregion
|
|
3239
3380
|
//#region src/generate-text/is-tool-execution-allowed-finish-reason.ts
|
|
3240
3381
|
function isToolExecutionAllowedFinishReason(finishReason) {
|
|
3241
3382
|
return finishReason === "stop" || finishReason === "tool-calls";
|
|
@@ -4079,45 +4220,6 @@ function prepareStepCallSettings({ callSettings, stepSettings }) {
|
|
|
4079
4220
|
});
|
|
4080
4221
|
}
|
|
4081
4222
|
//#endregion
|
|
4082
|
-
//#region src/generate-text/reasoning-output.ts
|
|
4083
|
-
function unwrapReasoningFileData(data) {
|
|
4084
|
-
if (typeof data === "object" && data !== null && "type" in data) return data.type === "data" ? data.data : data.url;
|
|
4085
|
-
return data;
|
|
4086
|
-
}
|
|
4087
|
-
function convertFromReasoningOutputs(parts) {
|
|
4088
|
-
return parts.map((part) => {
|
|
4089
|
-
if (part.type === "reasoning") return {
|
|
4090
|
-
type: "reasoning",
|
|
4091
|
-
text: part.text,
|
|
4092
|
-
...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
|
|
4093
|
-
};
|
|
4094
|
-
return {
|
|
4095
|
-
type: "reasoning-file",
|
|
4096
|
-
data: part.file.base64,
|
|
4097
|
-
mediaType: part.file.mediaType,
|
|
4098
|
-
...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
|
|
4099
|
-
};
|
|
4100
|
-
});
|
|
4101
|
-
}
|
|
4102
|
-
function convertToReasoningOutputs(parts) {
|
|
4103
|
-
return parts.map((part) => {
|
|
4104
|
-
if (part.type === "reasoning") return {
|
|
4105
|
-
type: "reasoning",
|
|
4106
|
-
text: part.text,
|
|
4107
|
-
...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
|
|
4108
|
-
};
|
|
4109
|
-
const rawData = unwrapReasoningFileData(part.data);
|
|
4110
|
-
return {
|
|
4111
|
-
type: "reasoning-file",
|
|
4112
|
-
file: new DefaultGeneratedFile({
|
|
4113
|
-
data: rawData instanceof ArrayBuffer ? new Uint8Array(rawData) : rawData instanceof URL ? rawData.toString() : rawData,
|
|
4114
|
-
mediaType: part.mediaType
|
|
4115
|
-
}),
|
|
4116
|
-
...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
|
|
4117
|
-
};
|
|
4118
|
-
});
|
|
4119
|
-
}
|
|
4120
|
-
//#endregion
|
|
4121
4223
|
//#region src/generate-text/resolve-tool-approval.ts
|
|
4122
4224
|
/**
|
|
4123
4225
|
* Resolves the approval state for a tool call by checking user-supplied and tool-defined
|
|
@@ -4381,8 +4483,11 @@ function createTelemetryDispatcher({ telemetry }) {
|
|
|
4381
4483
|
includeRuntimeContext: telemetry?.includeRuntimeContext,
|
|
4382
4484
|
includeToolsContext: telemetry?.includeToolsContext
|
|
4383
4485
|
};
|
|
4384
|
-
const mergeTelemetryCallback = (key) => {
|
|
4385
|
-
const integrationCallbacks = integrations.map((integration) =>
|
|
4486
|
+
const mergeTelemetryCallback = (key, deprecatedKey) => {
|
|
4487
|
+
const integrationCallbacks = integrations.map((integration) => {
|
|
4488
|
+
const callback = integration[key] ?? (deprecatedKey == null ? void 0 : integration[deprecatedKey]);
|
|
4489
|
+
return typeof callback === "function" ? callback.bind(integration) : void 0;
|
|
4490
|
+
}).filter(Boolean).map((callback) => ((event) => callback(augmentEvent(event, telemetryMetadata))));
|
|
4386
4491
|
if (integrationCallbacks.length === 0) return;
|
|
4387
4492
|
const mergedIntegrationCallback = mergeCallbacks(...integrationCallbacks);
|
|
4388
4493
|
return async (event) => {
|
|
@@ -4418,10 +4523,10 @@ function createTelemetryDispatcher({ telemetry }) {
|
|
|
4418
4523
|
onEmbedEnd: mergeTelemetryCallback("onEmbedEnd"),
|
|
4419
4524
|
onRerankStart: mergeTelemetryCallback("onRerankStart"),
|
|
4420
4525
|
onRerankEnd: mergeTelemetryCallback("onRerankEnd"),
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4526
|
+
experimental_onDecideStart: mergeTelemetryCallback("experimental_onDecideStart", "experimental_onEvaluateStart"),
|
|
4527
|
+
experimental_onDecisionModelCallStart: mergeTelemetryCallback("experimental_onDecisionModelCallStart", "experimental_onEvaluationModelCallStart"),
|
|
4528
|
+
experimental_onDecisionModelCallEnd: mergeTelemetryCallback("experimental_onDecisionModelCallEnd", "experimental_onEvaluationModelCallEnd"),
|
|
4529
|
+
experimental_onDecideEnd: mergeTelemetryCallback("experimental_onDecideEnd", "experimental_onEvaluateEnd"),
|
|
4425
4530
|
experimental_onStreamTranscriptionStart: mergeTelemetryCallback("experimental_onStreamTranscriptionStart"),
|
|
4426
4531
|
experimental_onStreamTranscriptionEnd: mergeTelemetryCallback("experimental_onStreamTranscriptionEnd"),
|
|
4427
4532
|
onEnd: mergeTelemetryCallback("onEnd"),
|
|
@@ -5849,81 +5954,6 @@ async function executeTools({ toolCalls, tools, callId, messages, abortSignal, t
|
|
|
5849
5954
|
runInTracingChannelSpan
|
|
5850
5955
|
})))).filter((result) => result != null);
|
|
5851
5956
|
}
|
|
5852
|
-
var DefaultGenerateTextResult = class {
|
|
5853
|
-
constructor(options) {
|
|
5854
|
-
this.initialResponseMessages = options.initialResponseMessages;
|
|
5855
|
-
this.steps = options.steps;
|
|
5856
|
-
this._output = options.output;
|
|
5857
|
-
this.totalUsage = options.totalUsage;
|
|
5858
|
-
}
|
|
5859
|
-
get finalStep() {
|
|
5860
|
-
return this.steps.at(-1);
|
|
5861
|
-
}
|
|
5862
|
-
get content() {
|
|
5863
|
-
return this.steps.flatMap((step) => step.content);
|
|
5864
|
-
}
|
|
5865
|
-
get text() {
|
|
5866
|
-
return this.finalStep.text;
|
|
5867
|
-
}
|
|
5868
|
-
get files() {
|
|
5869
|
-
return this.steps.flatMap((step) => step.files);
|
|
5870
|
-
}
|
|
5871
|
-
get reasoningText() {
|
|
5872
|
-
return this.finalStep.reasoningText;
|
|
5873
|
-
}
|
|
5874
|
-
get reasoning() {
|
|
5875
|
-
return convertToReasoningOutputs(this.finalStep.reasoning);
|
|
5876
|
-
}
|
|
5877
|
-
get toolCalls() {
|
|
5878
|
-
return this.steps.flatMap((step) => step.toolCalls);
|
|
5879
|
-
}
|
|
5880
|
-
get staticToolCalls() {
|
|
5881
|
-
return this.steps.flatMap((step) => step.staticToolCalls);
|
|
5882
|
-
}
|
|
5883
|
-
get dynamicToolCalls() {
|
|
5884
|
-
return this.steps.flatMap((step) => step.dynamicToolCalls);
|
|
5885
|
-
}
|
|
5886
|
-
get toolResults() {
|
|
5887
|
-
return this.steps.flatMap((step) => step.toolResults);
|
|
5888
|
-
}
|
|
5889
|
-
get staticToolResults() {
|
|
5890
|
-
return this.steps.flatMap((step) => step.staticToolResults);
|
|
5891
|
-
}
|
|
5892
|
-
get dynamicToolResults() {
|
|
5893
|
-
return this.steps.flatMap((step) => step.dynamicToolResults);
|
|
5894
|
-
}
|
|
5895
|
-
get sources() {
|
|
5896
|
-
return this.steps.flatMap((step) => step.sources);
|
|
5897
|
-
}
|
|
5898
|
-
get finishReason() {
|
|
5899
|
-
return this.finalStep.finishReason;
|
|
5900
|
-
}
|
|
5901
|
-
get rawFinishReason() {
|
|
5902
|
-
return this.finalStep.rawFinishReason;
|
|
5903
|
-
}
|
|
5904
|
-
get warnings() {
|
|
5905
|
-
return this.steps.flatMap((step) => step.warnings ?? []);
|
|
5906
|
-
}
|
|
5907
|
-
get providerMetadata() {
|
|
5908
|
-
return this.finalStep.providerMetadata;
|
|
5909
|
-
}
|
|
5910
|
-
get response() {
|
|
5911
|
-
return this.finalStep.response;
|
|
5912
|
-
}
|
|
5913
|
-
get responseMessages() {
|
|
5914
|
-
return [...this.initialResponseMessages, ...this.steps.flatMap((step) => step.response.messages)];
|
|
5915
|
-
}
|
|
5916
|
-
get request() {
|
|
5917
|
-
return this.finalStep.request;
|
|
5918
|
-
}
|
|
5919
|
-
get usage() {
|
|
5920
|
-
return this.totalUsage;
|
|
5921
|
-
}
|
|
5922
|
-
get output() {
|
|
5923
|
-
if (this._output == null) throw new NoOutputGeneratedError();
|
|
5924
|
-
return this._output;
|
|
5925
|
-
}
|
|
5926
|
-
};
|
|
5927
5957
|
//#endregion
|
|
5928
5958
|
//#region src/util/prepare-headers.ts
|
|
5929
5959
|
function prepareHeaders(headers, defaultHeaders) {
|
|
@@ -6521,7 +6551,7 @@ function createStreamingUIMessageState({ lastMessage, messageId }) {
|
|
|
6521
6551
|
partialToolCalls
|
|
6522
6552
|
};
|
|
6523
6553
|
}
|
|
6524
|
-
function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas, runUpdateMessageJob, onError, onToolCall, onData }) {
|
|
6554
|
+
function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas, runUpdateMessageJob, onError, onToolCall, onData, resetStateOnMessageIdChange = false }) {
|
|
6525
6555
|
return stream.pipeThrough(new TransformStream({ async transform(chunk, controller) {
|
|
6526
6556
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
6527
6557
|
function getCurrentStepParts() {
|
|
@@ -6987,6 +7017,10 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
|
|
|
6987
7017
|
break;
|
|
6988
7018
|
}
|
|
6989
7019
|
case "start":
|
|
7020
|
+
if (resetStateOnMessageIdChange && chunk.messageId != null && chunk.messageId !== state.message.id) Object.assign(state, createStreamingUIMessageState({
|
|
7021
|
+
lastMessage: void 0,
|
|
7022
|
+
messageId: chunk.messageId
|
|
7023
|
+
}), { finishReason: void 0 });
|
|
6990
7024
|
if (chunk.messageId != null) state.message.id = chunk.messageId;
|
|
6991
7025
|
await updateMessageMetadata(chunk.messageMetadata);
|
|
6992
7026
|
if (chunk.messageId != null || chunk.messageMetadata != null) write({ updateStatus: false });
|
|
@@ -12544,19 +12578,19 @@ var DefaultEmbedManyResult = class {
|
|
|
12544
12578
|
}
|
|
12545
12579
|
};
|
|
12546
12580
|
//#endregion
|
|
12547
|
-
//#region src/
|
|
12581
|
+
//#region src/decide/restricted-telemetry-dispatcher.ts
|
|
12548
12582
|
function createRestrictedTelemetryDispatcher$1({ telemetry }) {
|
|
12549
12583
|
const dispatcher = createTelemetryDispatcher({ telemetry });
|
|
12550
12584
|
return {
|
|
12551
12585
|
...dispatcher,
|
|
12552
|
-
onStart: (event) => dispatcher.
|
|
12586
|
+
onStart: (event) => dispatcher.experimental_onDecideStart?.({
|
|
12553
12587
|
...event,
|
|
12554
12588
|
runtimeContext: filterIncludedContext({
|
|
12555
12589
|
context: event.runtimeContext,
|
|
12556
12590
|
includeContext: telemetry?.includeRuntimeContext
|
|
12557
12591
|
})
|
|
12558
12592
|
}),
|
|
12559
|
-
onEnd: (event) => dispatcher.
|
|
12593
|
+
onEnd: (event) => dispatcher.experimental_onDecideEnd?.({
|
|
12560
12594
|
...event,
|
|
12561
12595
|
runtimeContext: filterIncludedContext({
|
|
12562
12596
|
context: event.runtimeContext,
|
|
@@ -12566,7 +12600,7 @@ function createRestrictedTelemetryDispatcher$1({ telemetry }) {
|
|
|
12566
12600
|
};
|
|
12567
12601
|
}
|
|
12568
12602
|
//#endregion
|
|
12569
|
-
//#region src/
|
|
12603
|
+
//#region src/decide/validate-decision.ts
|
|
12570
12604
|
const tolerance = 1e-6;
|
|
12571
12605
|
function isRecord(value) {
|
|
12572
12606
|
if (value == null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
@@ -12593,7 +12627,7 @@ function invalidInput(parameter, value, message) {
|
|
|
12593
12627
|
message
|
|
12594
12628
|
});
|
|
12595
12629
|
}
|
|
12596
|
-
function
|
|
12630
|
+
function validateDecisionInput({ state, questions }) {
|
|
12597
12631
|
if (!isInput(state)) invalidInput("state", state, "must be a JSON-compatible string, object, or array");
|
|
12598
12632
|
if (!isRecord(questions) || Object.keys(questions).length === 0) invalidInput("questions", questions, "must be a nonempty question map");
|
|
12599
12633
|
for (const [id, question] of Object.entries(questions)) {
|
|
@@ -12633,15 +12667,15 @@ function validateDistribution(value, keys, answers, id, roundingError) {
|
|
|
12633
12667
|
const sum = Object.values(value).reduce((total, probability) => total + probability, 0);
|
|
12634
12668
|
if (Math.abs(sum - 1) > tolerance + keys.length * roundingError) invalidAnswer(answers, `Question "${id}" probabilities must sum to 1 within the declared rounding precision.`);
|
|
12635
12669
|
}
|
|
12636
|
-
function
|
|
12670
|
+
function validateDecisionAnswers({ questions, answers, rounding }) {
|
|
12637
12671
|
function roundingError(decimals) {
|
|
12638
12672
|
if (decimals === void 0) return 0;
|
|
12639
|
-
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 15) invalidAnswer(answers, "
|
|
12673
|
+
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 15) invalidAnswer(answers, "Decision rounding decimals must be integers between 0 and 15.");
|
|
12640
12674
|
return .5 * 10 ** -decimals;
|
|
12641
12675
|
}
|
|
12642
12676
|
const probabilityError = roundingError(rounding?.probabilityDecimals);
|
|
12643
12677
|
const scoreError = roundingError(rounding?.scoreDecimals);
|
|
12644
|
-
if (!isRecord(answers) || !hasExactKeys(answers, Object.keys(questions))) invalidAnswer(answers, "
|
|
12678
|
+
if (!isRecord(answers) || !hasExactKeys(answers, Object.keys(questions))) invalidAnswer(answers, "Decision must return exactly one answer for every question.");
|
|
12645
12679
|
for (const [id, question] of Object.entries(questions)) {
|
|
12646
12680
|
const answer = answers[id];
|
|
12647
12681
|
if (!isRecord(answer) || answer.type !== question.type) invalidAnswer(answers, `Question "${id}" returned an answer with the wrong type.`);
|
|
@@ -12669,19 +12703,19 @@ function validateEvaluationAnswers({ questions, answers, rounding }) {
|
|
|
12669
12703
|
}
|
|
12670
12704
|
}
|
|
12671
12705
|
//#endregion
|
|
12672
|
-
//#region src/
|
|
12706
|
+
//#region src/decide/decide.ts
|
|
12673
12707
|
const originalGenerateCallId$4 = createIdGenerator$1({
|
|
12674
12708
|
prefix: "call",
|
|
12675
12709
|
size: 24
|
|
12676
12710
|
});
|
|
12677
|
-
/**
|
|
12678
|
-
async function
|
|
12679
|
-
const model =
|
|
12680
|
-
|
|
12711
|
+
/** Decide answers to typed questions against one shared state. Experimental. */
|
|
12712
|
+
async function decide({ model: modelArg, state, questions, maxRetries, abortSignal, headers, providerOptions = {}, telemetry, runtimeContext = {}, onStart, onEnd, _internal: { generateCallId = originalGenerateCallId$4 } = {} }) {
|
|
12713
|
+
const model = resolveDecisionModel(modelArg);
|
|
12714
|
+
validateDecisionInput({
|
|
12681
12715
|
state,
|
|
12682
12716
|
questions
|
|
12683
12717
|
});
|
|
12684
|
-
for (const [questionId, question] of Object.entries(questions)) if (!model.supportedQuestionTypes.includes(question.type)) throw new
|
|
12718
|
+
for (const [questionId, question] of Object.entries(questions)) if (!model.supportedQuestionTypes.includes(question.type)) throw new Experimental_DecisionUnsupportedQuestionTypeError$1({
|
|
12685
12719
|
questionId,
|
|
12686
12720
|
questionType: question.type,
|
|
12687
12721
|
provider: model.provider,
|
|
@@ -12696,7 +12730,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12696
12730
|
const runInTracingChannelSpan = telemetryDispatcher.runInTracingChannelSpan ?? (async ({ execute }) => await execute());
|
|
12697
12731
|
const startEvent = {
|
|
12698
12732
|
callId,
|
|
12699
|
-
operationId: "ai.
|
|
12733
|
+
operationId: "ai.decide",
|
|
12700
12734
|
runtimeContext,
|
|
12701
12735
|
provider: model.provider,
|
|
12702
12736
|
modelId: model.modelId,
|
|
@@ -12707,7 +12741,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12707
12741
|
providerOptions
|
|
12708
12742
|
};
|
|
12709
12743
|
return await runInTracingChannelSpan({
|
|
12710
|
-
type: "
|
|
12744
|
+
type: "experimental_decide",
|
|
12711
12745
|
event: startEvent,
|
|
12712
12746
|
execute: async () => {
|
|
12713
12747
|
await notify({
|
|
@@ -12717,7 +12751,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12717
12751
|
try {
|
|
12718
12752
|
const modelCallEvent = {
|
|
12719
12753
|
callId,
|
|
12720
|
-
operationId: "ai.
|
|
12754
|
+
operationId: "ai.decide.doDecide",
|
|
12721
12755
|
provider: model.provider,
|
|
12722
12756
|
modelId: model.modelId,
|
|
12723
12757
|
state,
|
|
@@ -12725,11 +12759,11 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12725
12759
|
};
|
|
12726
12760
|
await notify({
|
|
12727
12761
|
event: modelCallEvent,
|
|
12728
|
-
callbacks: [telemetryDispatcher.
|
|
12762
|
+
callbacks: [telemetryDispatcher.experimental_onDecisionModelCallStart]
|
|
12729
12763
|
});
|
|
12730
12764
|
const result = await retry(async () => {
|
|
12731
12765
|
abortSignal?.throwIfAborted();
|
|
12732
|
-
return await model.
|
|
12766
|
+
return await model.doDecide({
|
|
12733
12767
|
state,
|
|
12734
12768
|
questions,
|
|
12735
12769
|
abortSignal,
|
|
@@ -12738,7 +12772,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12738
12772
|
});
|
|
12739
12773
|
});
|
|
12740
12774
|
abortSignal?.throwIfAborted();
|
|
12741
|
-
|
|
12775
|
+
validateDecisionAnswers({
|
|
12742
12776
|
questions,
|
|
12743
12777
|
answers: result.answers,
|
|
12744
12778
|
rounding: result.rounding
|
|
@@ -12748,7 +12782,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12748
12782
|
...modelCallEvent,
|
|
12749
12783
|
...result
|
|
12750
12784
|
},
|
|
12751
|
-
callbacks: [telemetryDispatcher.
|
|
12785
|
+
callbacks: [telemetryDispatcher.experimental_onDecisionModelCallEnd]
|
|
12752
12786
|
});
|
|
12753
12787
|
logWarnings({
|
|
12754
12788
|
warnings: result.warnings,
|
|
@@ -12757,7 +12791,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12757
12791
|
});
|
|
12758
12792
|
const inputTokens = result.usage?.inputTokens;
|
|
12759
12793
|
const outputTokens = result.usage?.outputTokens;
|
|
12760
|
-
const
|
|
12794
|
+
const decisionResult = {
|
|
12761
12795
|
answers: result.answers,
|
|
12762
12796
|
usage: {
|
|
12763
12797
|
inputTokens,
|
|
@@ -12776,11 +12810,11 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12776
12810
|
await notify({
|
|
12777
12811
|
event: {
|
|
12778
12812
|
...startEvent,
|
|
12779
|
-
...
|
|
12813
|
+
...decisionResult
|
|
12780
12814
|
},
|
|
12781
12815
|
callbacks: [onEnd, telemetryDispatcher.onEnd]
|
|
12782
12816
|
});
|
|
12783
|
-
return
|
|
12817
|
+
return decisionResult;
|
|
12784
12818
|
} catch (error) {
|
|
12785
12819
|
await telemetryDispatcher.onError?.({
|
|
12786
12820
|
callId,
|
|
@@ -12792,6 +12826,10 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12792
12826
|
});
|
|
12793
12827
|
}
|
|
12794
12828
|
//#endregion
|
|
12829
|
+
//#region src/decide/index.ts
|
|
12830
|
+
/** @deprecated Use `experimental_decide` instead. */
|
|
12831
|
+
const experimental_evaluate = decide;
|
|
12832
|
+
//#endregion
|
|
12795
12833
|
//#region src/generate-text/extract-reasoning-content.ts
|
|
12796
12834
|
function extractReasoningContent(content) {
|
|
12797
12835
|
const parts = content.filter((content) => content.type === "reasoning");
|
|
@@ -14124,7 +14162,10 @@ var DefaultGeneratedAudioFile = class extends DefaultGeneratedFile {
|
|
|
14124
14162
|
if (mediaType !== "audio/mpeg") format = mediaTypeParts[1];
|
|
14125
14163
|
}
|
|
14126
14164
|
}
|
|
14127
|
-
if (!format) throw new
|
|
14165
|
+
if (!format) throw new InvalidResponseDataError$1({
|
|
14166
|
+
data: mediaType,
|
|
14167
|
+
message: `Could not determine audio format from media type: ${mediaType}`
|
|
14168
|
+
});
|
|
14128
14169
|
this.format = format;
|
|
14129
14170
|
}
|
|
14130
14171
|
};
|
|
@@ -15218,16 +15259,24 @@ function getPotentialStartIndex(text, searchedText) {
|
|
|
15218
15259
|
//#endregion
|
|
15219
15260
|
//#region src/middleware/extract-reasoning-middleware.ts
|
|
15220
15261
|
/**
|
|
15221
|
-
* Extracts
|
|
15262
|
+
* Extracts a delimited reasoning section from the generated text and exposes it
|
|
15222
15263
|
* as a `reasoning` property on the result.
|
|
15223
15264
|
*
|
|
15224
|
-
* @param tagName -
|
|
15265
|
+
* @param tagName - An XML tag name (without angle brackets), or literal opening
|
|
15266
|
+
* and closing delimiters for formats such as Gemma's thought channel.
|
|
15225
15267
|
* @param separator - The separator to use between reasoning and text sections.
|
|
15226
15268
|
* @param startWithReasoning - Whether to start with reasoning tokens.
|
|
15227
15269
|
*/
|
|
15228
15270
|
function extractReasoningMiddleware({ tagName, separator = "\n", startWithReasoning = false }) {
|
|
15229
|
-
const openingTag = `<${tagName}
|
|
15230
|
-
const closingTag = `</${tagName}
|
|
15271
|
+
const openingTag = typeof tagName === "string" ? `<${tagName}>` : tagName.opening;
|
|
15272
|
+
const closingTag = typeof tagName === "string" ? `</${tagName}>` : tagName.closing;
|
|
15273
|
+
if (openingTag.length === 0 || closingTag.length === 0) throw new InvalidArgumentError({
|
|
15274
|
+
parameter: "tagName",
|
|
15275
|
+
value: tagName,
|
|
15276
|
+
message: "Reasoning delimiters must not be empty."
|
|
15277
|
+
});
|
|
15278
|
+
const escapedOpeningTag = openingTag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15279
|
+
const escapedClosingTag = closingTag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15231
15280
|
return {
|
|
15232
15281
|
specificationVersion: "v4",
|
|
15233
15282
|
wrapGenerate: async ({ doGenerate }) => {
|
|
@@ -15239,7 +15288,7 @@ function extractReasoningMiddleware({ tagName, separator = "\n", startWithReason
|
|
|
15239
15288
|
continue;
|
|
15240
15289
|
}
|
|
15241
15290
|
const text = startWithReasoning ? openingTag + part.text : part.text;
|
|
15242
|
-
const regexp = new RegExp(`${
|
|
15291
|
+
const regexp = new RegExp(`${escapedOpeningTag}(.*?)${escapedClosingTag}`, "gs");
|
|
15243
15292
|
const matches = Array.from(text.matchAll(regexp));
|
|
15244
15293
|
if (!matches.length) {
|
|
15245
15294
|
transformedContent.push(part);
|
|
@@ -18022,7 +18071,7 @@ var AbstractRealtimeSession = class {
|
|
|
18022
18071
|
* @param {Record<string, SpeechModel>} [options.speechModels] - A record of speech models, where keys are model IDs and values are speech model instances.
|
|
18023
18072
|
* @param {Record<string, RerankingModel>} [options.rerankingModels] - A record of reranking models, where keys are model IDs and values are reranking model instances.
|
|
18024
18073
|
* @param {Record<string, VideoModel>} [options.videoModels] - A record of video models, where keys are model IDs and values are video model instances.
|
|
18025
|
-
* @param {Record<string,
|
|
18074
|
+
* @param {Record<string, DecisionModel>} [options.decisionModels] - Experimental decision models or default-provider model IDs, keyed by alias.
|
|
18026
18075
|
* @param {FilesV4} [options.files] - A files interface for uploading files.
|
|
18027
18076
|
* @param {SkillsV4} [options.skills] - A skills interface for uploading skills.
|
|
18028
18077
|
* @param {ProviderV2 | ProviderV3 | ProviderV4} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
|
|
@@ -18030,7 +18079,8 @@ var AbstractRealtimeSession = class {
|
|
|
18030
18079
|
*
|
|
18031
18080
|
* @throws {NoSuchModelError} Throws when a requested model is not found and no fallback provider is available.
|
|
18032
18081
|
*/
|
|
18033
|
-
function customProvider({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels, videoModels, evaluationModels, files, skills, fallbackProvider: fallbackProviderArg }) {
|
|
18082
|
+
function customProvider({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels, videoModels, decisionModels: decisionModelsArg, evaluationModels, files, skills, fallbackProvider: fallbackProviderArg }) {
|
|
18083
|
+
const decisionModels = decisionModelsArg ?? evaluationModels;
|
|
18034
18084
|
const fallbackProvider = fallbackProviderArg == null ? void 0 : asProviderV4(fallbackProviderArg);
|
|
18035
18085
|
const baseProvider = {
|
|
18036
18086
|
specificationVersion: "v4",
|
|
@@ -18088,18 +18138,22 @@ function customProvider({ languageModels, embeddingModels, imageModels, transcri
|
|
|
18088
18138
|
modelType: "rerankingModel"
|
|
18089
18139
|
});
|
|
18090
18140
|
},
|
|
18091
|
-
|
|
18092
|
-
if (
|
|
18141
|
+
decisionModel(modelId) {
|
|
18142
|
+
if (decisionModels != null && Object.hasOwn(decisionModels, modelId)) return resolveDecisionModel(decisionModels[modelId]);
|
|
18093
18143
|
const provider = fallbackProviderArg;
|
|
18094
|
-
|
|
18095
|
-
|
|
18096
|
-
|
|
18144
|
+
const factory = provider?.decisionModel ?? provider?.evaluationModel;
|
|
18145
|
+
if (typeof factory === "function") {
|
|
18146
|
+
const model = factory.call(provider, modelId);
|
|
18147
|
+
if (model != null) return resolveDecisionModel(model);
|
|
18097
18148
|
}
|
|
18098
18149
|
throw new NoSuchModelError$1({
|
|
18099
18150
|
modelId,
|
|
18100
|
-
modelType: "
|
|
18151
|
+
modelType: "decisionModel"
|
|
18101
18152
|
});
|
|
18102
18153
|
},
|
|
18154
|
+
evaluationModel(modelId) {
|
|
18155
|
+
return asEvaluationModel(this.decisionModel(modelId));
|
|
18156
|
+
},
|
|
18103
18157
|
videoModel(modelId) {
|
|
18104
18158
|
if (videoModels != null && modelId in videoModels) return resolveVideoModel(videoModels[modelId]);
|
|
18105
18159
|
const provider = fallbackProviderArg;
|
|
@@ -18182,12 +18236,13 @@ var DefaultProviderRegistry = class {
|
|
|
18182
18236
|
registerProvider({ id, provider }) {
|
|
18183
18237
|
const providerV4 = asProviderV4(provider);
|
|
18184
18238
|
const videoModel = provider.videoModel?.bind(provider);
|
|
18185
|
-
const
|
|
18239
|
+
const decisionProvider = provider;
|
|
18240
|
+
const decisionModel = (decisionProvider.decisionModel ?? decisionProvider.evaluationModel)?.bind(provider);
|
|
18186
18241
|
const registeredProvider = videoModel == null ? providerV4 : Object.assign(Object.create(Object.getPrototypeOf(providerV4)), {
|
|
18187
18242
|
...providerV4,
|
|
18188
18243
|
videoModel: (modelId) => asVideoModelV4(videoModel(modelId))
|
|
18189
18244
|
});
|
|
18190
|
-
if (registeredProvider !== provider &&
|
|
18245
|
+
if (registeredProvider !== provider && decisionModel != null) Object.assign(registeredProvider, { decisionModel });
|
|
18191
18246
|
this.providers[id] = registeredProvider;
|
|
18192
18247
|
}
|
|
18193
18248
|
getProvider(id, modelType) {
|
|
@@ -18280,14 +18335,19 @@ var DefaultProviderRegistry = class {
|
|
|
18280
18335
|
});
|
|
18281
18336
|
return asVideoModelV4(model);
|
|
18282
18337
|
}
|
|
18283
|
-
|
|
18284
|
-
const [providerId, modelId] = this.splitId(id, "
|
|
18285
|
-
const
|
|
18338
|
+
decisionModel(id) {
|
|
18339
|
+
const [providerId, modelId] = this.splitId(id, "decisionModel");
|
|
18340
|
+
const provider = this.getProvider(providerId, "decisionModel");
|
|
18341
|
+
const model = (provider.decisionModel ?? provider.evaluationModel)?.call(provider, modelId);
|
|
18286
18342
|
if (model == null) throw new NoSuchModelError$1({
|
|
18287
18343
|
modelId: id,
|
|
18288
|
-
modelType: "
|
|
18344
|
+
modelType: "decisionModel"
|
|
18289
18345
|
});
|
|
18290
|
-
return
|
|
18346
|
+
return resolveDecisionModel(model);
|
|
18347
|
+
}
|
|
18348
|
+
/** @deprecated Use `decisionModel` instead. */
|
|
18349
|
+
evaluationModel(id) {
|
|
18350
|
+
return asEvaluationModel(this.decisionModel(id));
|
|
18291
18351
|
}
|
|
18292
18352
|
files(id) {
|
|
18293
18353
|
const files = this.getProvider(id, "languageModel").files?.();
|
|
@@ -18673,7 +18733,7 @@ async function transcribe({ model, audio, providerOptions = {}, maxRetries: maxR
|
|
|
18673
18733
|
provider: resolvedModel.provider,
|
|
18674
18734
|
model: resolvedModel.modelId
|
|
18675
18735
|
});
|
|
18676
|
-
if (
|
|
18736
|
+
if (result.text == null) throw new NoTranscriptGeneratedError({ responses: [result.response] });
|
|
18677
18737
|
await notify({
|
|
18678
18738
|
event: {
|
|
18679
18739
|
callId,
|
|
@@ -19730,7 +19790,7 @@ var AbstractChat = class {
|
|
|
19730
19790
|
const lastMessage = this.lastMessage;
|
|
19731
19791
|
const responseMessageIndex = trigger === "submit-message" && messageId != null ? this.state.messages.findIndex((message) => message.id === messageId) : this.state.messages.length - 1;
|
|
19732
19792
|
const responseMessage = responseMessageIndex === -1 ? lastMessage : this.state.messages[responseMessageIndex];
|
|
19733
|
-
const resumableResponseMessage = trigger === "resume-stream" && responseMessage?.role === "assistant" && responseMessage.parts.some((part) => isToolUIPart(part) && part.state === "input-streaming") ? this.state.snapshot(responseMessage) : void 0;
|
|
19793
|
+
const resumableResponseMessage = trigger === "resume-stream" && responseMessage?.role === "assistant" && responseMessage.parts.some((part) => isToolUIPart(part) && (part.state === "input-streaming" || part.state === "approval-responded")) ? this.state.snapshot(responseMessage) : void 0;
|
|
19734
19794
|
const usesEarlierAssistantMessage = responseMessageIndex !== -1 && responseMessageIndex < this.state.messages.length - 1 && responseMessage?.role === "assistant";
|
|
19735
19795
|
let isAbort = false;
|
|
19736
19796
|
let isDisconnect = false;
|
|
@@ -19777,6 +19837,7 @@ var AbstractChat = class {
|
|
|
19777
19837
|
await consumeStream({
|
|
19778
19838
|
stream: processUIMessageStream({
|
|
19779
19839
|
stream,
|
|
19840
|
+
resetStateOnMessageIdChange: trigger === "resume-stream",
|
|
19780
19841
|
onToolCall: this.onToolCall,
|
|
19781
19842
|
onData: this.onData,
|
|
19782
19843
|
messageMetadataSchema: this.messageMetadataSchema,
|
|
@@ -20077,6 +20138,6 @@ async function uploadSkill({ api, files, displayTitle, providerOptions }) {
|
|
|
20077
20138
|
});
|
|
20078
20139
|
}
|
|
20079
20140
|
//#endregion
|
|
20080
|
-
export { AISDKError, AI_SDK_TELEMETRY_TRACING_CHANNEL, APICallError, AbstractChat, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DownloadError, EmptyResponseBodyError, AbstractRealtimeSession as Experimental_AbstractRealtimeSession, ToolLoopAgent as Experimental_Agent, ToolLoopAgent, Experimental_EvaluationUnsupportedQuestionTypeError, HttpChatTransport, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidPromptError, InvalidResponseDataError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONParseError, JsonToSseTransformStream, LoadAPIKeyError, LoadSettingError, MessageConversionError, MissingToolResultsError, NoContentGeneratedError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchModelError, NoSuchProviderError, NoSuchProviderReferenceError, NoSuchToolError, NoTranscriptGeneratedError, NoTranslationGeneratedError, NoVideoGeneratedError, output_exports as Output, RetryError, SerialJobExecutor, StreamProviderError, TextStreamChatTransport, TooManyEmbeddingValuesForCallError, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolChoiceViolationError, TypeValidationError, UIMessageStreamError, UI_MESSAGE_STREAM_HEADERS, UnsupportedFunctionalityError, UnsupportedModelVersionError, addToolInputExamplesMiddleware, asSchema, assistantModelMessageSchema, callCompletionApi, consumeStream, convertDataContentToBase64String, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createGateway, createIdGenerator, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultInstructionsMiddleware, defaultSettingsMiddleware, detectToolDrift, dynamicTool, embed, embedMany, cancelBatch as experimental_cancelBatch, experimental_createProviderRegistry, decodeRealtimeAudio as experimental_decodeRealtimeAudio, encodeRealtimeAudio as experimental_encodeRealtimeAudio,
|
|
20141
|
+
export { AISDKError, AI_SDK_TELEMETRY_TRACING_CHANNEL, APICallError, AbstractChat, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DownloadError, EmptyResponseBodyError, AbstractRealtimeSession as Experimental_AbstractRealtimeSession, ToolLoopAgent as Experimental_Agent, ToolLoopAgent, Experimental_DecisionUnsupportedQuestionTypeError, Experimental_EvaluationUnsupportedQuestionTypeError, HttpChatTransport, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidPromptError, InvalidResponseDataError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONParseError, JsonToSseTransformStream, LoadAPIKeyError, LoadSettingError, MessageConversionError, MissingToolResultsError, NoContentGeneratedError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchModelError, NoSuchProviderError, NoSuchProviderReferenceError, NoSuchToolError, NoTranscriptGeneratedError, NoTranslationGeneratedError, NoVideoGeneratedError, output_exports as Output, RetryError, SerialJobExecutor, StreamProviderError, TextStreamChatTransport, TooManyEmbeddingValuesForCallError, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolChoiceViolationError, TypeValidationError, UIMessageStreamError, UI_MESSAGE_STREAM_HEADERS, UnsupportedFunctionalityError, UnsupportedModelVersionError, addToolInputExamplesMiddleware, asSchema, assistantModelMessageSchema, callCompletionApi, consumeStream, convertDataContentToBase64String, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createGateway, createIdGenerator, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultInstructionsMiddleware, defaultSettingsMiddleware, detectToolDrift, dynamicTool, embed, embedMany, cancelBatch as experimental_cancelBatch, experimental_createProviderRegistry, decide as experimental_decide, decodeRealtimeAudio as experimental_decodeRealtimeAudio, encodeRealtimeAudio as experimental_encodeRealtimeAudio, experimental_evaluate, filterActiveTools as experimental_filterActiveTools, experimental_generateSpeech, experimental_generateVideo, getBatchResults as experimental_getBatchResults, getBatchStatus as experimental_getBatchStatus, getRealtimeToolDefinitions as experimental_getRealtimeToolDefinitions, experimental_getVideoStatus, listBatches as experimental_listBatches, resampleAudio as experimental_resampleAudio, startBatch as experimental_startBatch, experimental_startVideo, streamLanguageModelCall as experimental_streamLanguageModelCall, streamTranscribe as experimental_streamTranscribe, streamTranslate as experimental_streamTranslate, experimental_toolCaller, experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, fingerprintTools, gateway, generateId, generateImage, generateObject, generateSpeech, generateText, getChunkTimeoutMs, getFirstChunkTimeoutMs, getStaticToolName, getStepTimeoutMs, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, getToolTimeoutMs, getTotalTimeoutMs, hasToolCall, isCustomContentUIPart, isDataUIPart, isDeepEqualData, isDynamicToolUIPart, isFileUIPart, isLoopFinished, isReasoningFileUIPart, isReasoningUIPart, isStaticToolUIPart, isStepCount, isStepCount as stepCountIs, isTextUIPart, isToolOutputErrorUIPart, isToolUIPart, jsonSchema, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parseJsonEventStream, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetry, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, toTextStream, toUIMessageChunk, toUIMessageStream, tool, toolModelMessageSchema, toolSearch, transcribe, uiMessageChunkSchema, uploadFile, uploadSkill, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider, zodSchema };
|
|
20081
20142
|
|
|
20082
20143
|
//# sourceMappingURL=index.js.map
|