ai 7.0.111 → 7.0.113
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 +41 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +345 -222
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +125 -31
- package/dist/internal/index.js.map +1 -1
- package/docs/03-agents/06-tool-approvals.mdx +16 -0
- package/docs/03-ai-sdk-core/37-speech.mdx +2 -0
- package/docs/03-ai-sdk-core/40-middleware.mdx +92 -7
- package/docs/06-advanced/02-stopping-streams.mdx +8 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/12-generate-speech.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +18 -0
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +9 -3
- package/package.json +12 -12
- package/src/embed/embed-many.ts +18 -2
- package/src/generate-speech/generate-speech.ts +15 -4
- package/src/generate-speech/generated-audio-file.ts +0 -8
- package/src/generate-text/execute-tools-from-stream.ts +0 -2
- package/src/generate-text/generate-text.ts +1 -0
- package/src/generate-text/generated-file.ts +0 -8
- package/src/generate-text/invoke-tool-callbacks-from-stream.ts +9 -8
- package/src/generate-text/output.ts +0 -2
- package/src/generate-text/parse-tool-call.ts +38 -25
- package/src/generate-text/prune-messages.ts +3 -1
- package/src/generate-text/stream-text.ts +1 -0
- package/src/generate-text/to-response-messages.ts +7 -0
- package/src/generate-text/tool-call.ts +26 -0
- package/src/generate-text/validate-tool-approvals.ts +39 -3
- package/src/generate-video/generate-video.ts +0 -2
- package/src/middleware/extract-reasoning-middleware.ts +1 -1
- package/src/middleware/wrap-embedding-model.ts +9 -1
- package/src/model/get-embedding-model-provider-options-transformer.ts +17 -0
- package/src/prompt/content-part.ts +3 -0
- package/src/prompt/convert-to-language-model-prompt.ts +12 -2
- package/src/prompt/file-part-data.ts +11 -1
- package/src/registry/custom-provider.ts +12 -5
- package/src/ui/chat.ts +108 -17
- package/src/ui/convert-to-model-messages.ts +8 -0
- package/src/ui/direct-chat-transport.ts +2 -0
- package/src/ui/process-ui-message-stream.ts +6 -0
- package/src/ui/ui-messages.ts +10 -0
- package/src/ui/validate-ui-messages.ts +100 -134
- package/src/ui-message-stream/handle-ui-message-stream-finish.ts +5 -3
- package/src/ui-message-stream/to-ui-message-chunk.ts +7 -0
- package/src/ui-message-stream/ui-message-chunks.ts +2 -0
- package/src/ui-message-stream/ui-message-stream-on-end-callback.ts +8 -0
- package/src/ui-message-stream/ui-message-stream-outcome.ts +4 -0
- package/src/util/write-to-server-response.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -1334,7 +1334,7 @@ import {
|
|
|
1334
1334
|
} from "@ai-sdk/provider-utils";
|
|
1335
1335
|
|
|
1336
1336
|
// src/version.ts
|
|
1337
|
-
var VERSION = true ? "7.0.
|
|
1337
|
+
var VERSION = true ? "7.0.113" : "0.0.0-test";
|
|
1338
1338
|
|
|
1339
1339
|
// src/util/download/download.ts
|
|
1340
1340
|
var download = async ({
|
|
@@ -1463,6 +1463,13 @@ function convertUrlToFilePartData(url) {
|
|
|
1463
1463
|
}
|
|
1464
1464
|
return { data: { type: "url", url }, mediaType: void 0 };
|
|
1465
1465
|
}
|
|
1466
|
+
function convertUrlStringToFilePartData(content) {
|
|
1467
|
+
const result = convertUrlToFilePartData(new URL(content));
|
|
1468
|
+
if (result.data.type === "url" && result.data.url.toString() !== content) {
|
|
1469
|
+
result.data.originalUrl = content;
|
|
1470
|
+
}
|
|
1471
|
+
return result;
|
|
1472
|
+
}
|
|
1466
1473
|
function convertInlineDataToFilePartData(content) {
|
|
1467
1474
|
if (content instanceof Uint8Array) {
|
|
1468
1475
|
return { data: { type: "data", data: content }, mediaType: void 0 };
|
|
@@ -1514,7 +1521,7 @@ function convertToLanguageModelV4FilePart(content) {
|
|
|
1514
1521
|
}
|
|
1515
1522
|
if (typeof content === "string") {
|
|
1516
1523
|
try {
|
|
1517
|
-
return
|
|
1524
|
+
return convertUrlStringToFilePartData(content);
|
|
1518
1525
|
} catch (e) {
|
|
1519
1526
|
return convertInlineDataToFilePartData(content);
|
|
1520
1527
|
}
|
|
@@ -1995,6 +2002,7 @@ function mapToolResultOutput({
|
|
|
1995
2002
|
}
|
|
1996
2003
|
case "file-url": {
|
|
1997
2004
|
const mediaType = (_a25 = item.mediaType) != null ? _a25 : getMediaTypeFromUrl(item.url);
|
|
2005
|
+
const url = new URL(item.url);
|
|
1998
2006
|
let message = `The "file-url" type for tool result content is deprecated. Use the "file" type with mediaType and { type: 'url', url } instead.`;
|
|
1999
2007
|
if (!item.mediaType) {
|
|
2000
2008
|
const inferenceSuffix = mediaType === "application/octet-stream" ? `Unable to infer media type from URL. Defaulting to 'application/octet-stream'.` : `Inferred media type '${mediaType}' from URL.`;
|
|
@@ -2007,7 +2015,11 @@ function mapToolResultOutput({
|
|
|
2007
2015
|
});
|
|
2008
2016
|
return {
|
|
2009
2017
|
type: "file",
|
|
2010
|
-
data: {
|
|
2018
|
+
data: {
|
|
2019
|
+
type: "url",
|
|
2020
|
+
url,
|
|
2021
|
+
...url.toString() !== item.url ? { originalUrl: item.url } : {}
|
|
2022
|
+
},
|
|
2011
2023
|
mediaType,
|
|
2012
2024
|
providerOptions: item.providerOptions
|
|
2013
2025
|
};
|
|
@@ -2063,6 +2075,7 @@ function mapToolResultOutput({
|
|
|
2063
2075
|
};
|
|
2064
2076
|
}
|
|
2065
2077
|
case "image-url": {
|
|
2078
|
+
const url = new URL(item.url);
|
|
2066
2079
|
warnings.push({
|
|
2067
2080
|
type: "deprecated",
|
|
2068
2081
|
setting: '"tool-result" content of type "image-url"',
|
|
@@ -2070,7 +2083,11 @@ function mapToolResultOutput({
|
|
|
2070
2083
|
});
|
|
2071
2084
|
return {
|
|
2072
2085
|
type: "file",
|
|
2073
|
-
data: {
|
|
2086
|
+
data: {
|
|
2087
|
+
type: "url",
|
|
2088
|
+
url,
|
|
2089
|
+
...url.toString() !== item.url ? { originalUrl: item.url } : {}
|
|
2090
|
+
},
|
|
2074
2091
|
mediaType: "image",
|
|
2075
2092
|
providerOptions: item.providerOptions
|
|
2076
2093
|
};
|
|
@@ -2678,7 +2695,10 @@ var toolApprovalRequestSchema = z.object(
|
|
|
2678
2695
|
type: z.literal("tool-approval-request"),
|
|
2679
2696
|
approvalId: z.string(),
|
|
2680
2697
|
toolCallId: z.string(),
|
|
2681
|
-
reason: z.string().optional()
|
|
2698
|
+
reason: z.string().optional(),
|
|
2699
|
+
isAutomatic: z.boolean().optional(),
|
|
2700
|
+
signature: z.string().optional(),
|
|
2701
|
+
inputSchemaInput: z.unknown().optional()
|
|
2682
2702
|
}
|
|
2683
2703
|
);
|
|
2684
2704
|
var toolApprovalResponseSchema = z.object({
|
|
@@ -3163,8 +3183,8 @@ var DefaultGeneratedFile = class {
|
|
|
3163
3183
|
}
|
|
3164
3184
|
};
|
|
3165
3185
|
var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
|
|
3166
|
-
constructor(
|
|
3167
|
-
super(
|
|
3186
|
+
constructor() {
|
|
3187
|
+
super(...arguments);
|
|
3168
3188
|
this.type = "file";
|
|
3169
3189
|
}
|
|
3170
3190
|
};
|
|
@@ -4452,7 +4472,6 @@ function getArrayLengthValidationError({
|
|
|
4452
4472
|
cause: `elements array must contain at most ${maxItems} items`
|
|
4453
4473
|
});
|
|
4454
4474
|
}
|
|
4455
|
-
return void 0;
|
|
4456
4475
|
}
|
|
4457
4476
|
var choice = ({
|
|
4458
4477
|
options: choiceOptions,
|
|
@@ -4583,6 +4602,22 @@ import {
|
|
|
4583
4602
|
safeParseJSON as safeParseJSON3,
|
|
4584
4603
|
safeValidateTypes as safeValidateTypes3
|
|
4585
4604
|
} from "@ai-sdk/provider-utils";
|
|
4605
|
+
|
|
4606
|
+
// src/generate-text/tool-call.ts
|
|
4607
|
+
var inputSchemaInputSymbol = /* @__PURE__ */ Symbol("ai-sdk-tool-call-input-schema-input");
|
|
4608
|
+
function setToolCallInputSchemaInput(toolCall, inputSchemaInput) {
|
|
4609
|
+
Object.defineProperty(toolCall, inputSchemaInputSymbol, {
|
|
4610
|
+
value: inputSchemaInput
|
|
4611
|
+
});
|
|
4612
|
+
return toolCall;
|
|
4613
|
+
}
|
|
4614
|
+
function getToolCallInputSchemaInput(toolCall) {
|
|
4615
|
+
return inputSchemaInputSymbol in toolCall ? {
|
|
4616
|
+
value: toolCall[inputSchemaInputSymbol]
|
|
4617
|
+
} : void 0;
|
|
4618
|
+
}
|
|
4619
|
+
|
|
4620
|
+
// src/generate-text/parse-tool-call.ts
|
|
4586
4621
|
async function parseToolCall({
|
|
4587
4622
|
toolCall,
|
|
4588
4623
|
tools,
|
|
@@ -4704,10 +4739,12 @@ async function refineParsedToolCallInput({
|
|
|
4704
4739
|
if (refine == null) {
|
|
4705
4740
|
return toolCall;
|
|
4706
4741
|
}
|
|
4707
|
-
|
|
4742
|
+
const refinedToolCall = {
|
|
4708
4743
|
...toolCall,
|
|
4709
4744
|
input: await refine(toolCall.input)
|
|
4710
4745
|
};
|
|
4746
|
+
const inputSchemaInput = getToolCallInputSchemaInput(toolCall);
|
|
4747
|
+
return inputSchemaInput == null ? refinedToolCall : setToolCallInputSchemaInput(refinedToolCall, inputSchemaInput.value);
|
|
4711
4748
|
}
|
|
4712
4749
|
async function parseProviderExecutedDynamicToolCall(toolCall) {
|
|
4713
4750
|
const parseResult = toolCall.input.trim() === "" ? { success: true, value: {} } : await safeParseJSON3({ text: toolCall.input });
|
|
@@ -4752,26 +4789,29 @@ async function doParseToolCall({
|
|
|
4752
4789
|
cause: parseResult.error
|
|
4753
4790
|
});
|
|
4754
4791
|
}
|
|
4755
|
-
return
|
|
4756
|
-
type
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4792
|
+
return setToolCallInputSchemaInput(
|
|
4793
|
+
tool3.type === "dynamic" ? {
|
|
4794
|
+
type: "tool-call",
|
|
4795
|
+
toolCallId: toolCall.toolCallId,
|
|
4796
|
+
toolName: toolCall.toolName,
|
|
4797
|
+
input: parseResult.value,
|
|
4798
|
+
providerExecuted: toolCall.providerExecuted,
|
|
4799
|
+
providerMetadata: toolCall.providerMetadata,
|
|
4800
|
+
...tool3.metadata != null ? { toolMetadata: tool3.metadata } : {},
|
|
4801
|
+
dynamic: true,
|
|
4802
|
+
title: tool3.title
|
|
4803
|
+
} : {
|
|
4804
|
+
type: "tool-call",
|
|
4805
|
+
toolCallId: toolCall.toolCallId,
|
|
4806
|
+
toolName,
|
|
4807
|
+
input: parseResult.value,
|
|
4808
|
+
providerExecuted: toolCall.providerExecuted,
|
|
4809
|
+
providerMetadata: toolCall.providerMetadata,
|
|
4810
|
+
...tool3.metadata != null ? { toolMetadata: tool3.metadata } : {},
|
|
4811
|
+
title: tool3.title
|
|
4812
|
+
},
|
|
4813
|
+
parseResult.rawValue
|
|
4814
|
+
);
|
|
4775
4815
|
}
|
|
4776
4816
|
|
|
4777
4817
|
// src/generate-text/prepare-step-call-settings.ts
|
|
@@ -5510,6 +5550,33 @@ function sumTokenCounts(tokenCount1, tokenCount2) {
|
|
|
5510
5550
|
return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 != null ? tokenCount1 : 0) + (tokenCount2 != null ? tokenCount2 : 0);
|
|
5511
5551
|
}
|
|
5512
5552
|
|
|
5553
|
+
// src/util/is-deep-equal-data.ts
|
|
5554
|
+
function isDeepEqualData(obj1, obj2) {
|
|
5555
|
+
if (obj1 === obj2) return true;
|
|
5556
|
+
if (obj1 == null || obj2 == null) return false;
|
|
5557
|
+
if (typeof obj1 !== "object" && typeof obj2 !== "object")
|
|
5558
|
+
return obj1 === obj2;
|
|
5559
|
+
if (obj1.constructor !== obj2.constructor) return false;
|
|
5560
|
+
if (obj1 instanceof Date && obj2 instanceof Date) {
|
|
5561
|
+
return obj1.getTime() === obj2.getTime();
|
|
5562
|
+
}
|
|
5563
|
+
if (Array.isArray(obj1)) {
|
|
5564
|
+
if (obj1.length !== obj2.length) return false;
|
|
5565
|
+
for (let i = 0; i < obj1.length; i++) {
|
|
5566
|
+
if (!isDeepEqualData(obj1[i], obj2[i])) return false;
|
|
5567
|
+
}
|
|
5568
|
+
return true;
|
|
5569
|
+
}
|
|
5570
|
+
const keys1 = Object.keys(obj1);
|
|
5571
|
+
const keys2 = Object.keys(obj2);
|
|
5572
|
+
if (keys1.length !== keys2.length) return false;
|
|
5573
|
+
for (const key of keys1) {
|
|
5574
|
+
if (!keys2.includes(key)) return false;
|
|
5575
|
+
if (!isDeepEqualData(obj1[key], obj2[key])) return false;
|
|
5576
|
+
}
|
|
5577
|
+
return true;
|
|
5578
|
+
}
|
|
5579
|
+
|
|
5513
5580
|
// src/generate-text/to-response-messages.ts
|
|
5514
5581
|
async function toResponseMessages({
|
|
5515
5582
|
content: inputContent,
|
|
@@ -5614,13 +5681,15 @@ async function toResponseMessages({
|
|
|
5614
5681
|
break;
|
|
5615
5682
|
}
|
|
5616
5683
|
case "tool-approval-request":
|
|
5684
|
+
const inputSchemaInput = getToolCallInputSchemaInput(part.toolCall);
|
|
5617
5685
|
content.push({
|
|
5618
5686
|
type: "tool-approval-request",
|
|
5619
5687
|
approvalId: part.approvalId,
|
|
5620
5688
|
toolCallId: part.toolCall.toolCallId,
|
|
5621
5689
|
...part.reason != null ? { reason: part.reason } : {},
|
|
5622
5690
|
isAutomatic: part.isAutomatic,
|
|
5623
|
-
...part.signature != null ? { signature: part.signature } : {}
|
|
5691
|
+
...part.signature != null ? { signature: part.signature } : {},
|
|
5692
|
+
...inputSchemaInput != null && !isDeepEqualData(inputSchemaInput.value, part.toolCall.input) ? { inputSchemaInput: inputSchemaInput.value } : {}
|
|
5624
5693
|
});
|
|
5625
5694
|
break;
|
|
5626
5695
|
}
|
|
@@ -5840,14 +5909,15 @@ async function validateApprovedToolApprovals({
|
|
|
5840
5909
|
messages,
|
|
5841
5910
|
toolsContext,
|
|
5842
5911
|
runtimeContext,
|
|
5843
|
-
toolApprovalSecret
|
|
5912
|
+
toolApprovalSecret,
|
|
5913
|
+
refineToolInput
|
|
5844
5914
|
}) {
|
|
5845
5915
|
var _a25;
|
|
5846
5916
|
const approved = [];
|
|
5847
5917
|
const denied = [];
|
|
5848
5918
|
const invalid = [];
|
|
5849
5919
|
for (const approval of approvedToolApprovals) {
|
|
5850
|
-
const {
|
|
5920
|
+
const { approvalRequest, toolCall } = approval;
|
|
5851
5921
|
const tool3 = getOwn(tools, toolCall.toolName);
|
|
5852
5922
|
if (toolApprovalSecret != null) {
|
|
5853
5923
|
if (approvalRequest.signature == null) {
|
|
@@ -5874,17 +5944,42 @@ async function validateApprovedToolApprovals({
|
|
|
5874
5944
|
}
|
|
5875
5945
|
}
|
|
5876
5946
|
if (isExecutableTool2(tool3) && tool3.inputSchema != null) {
|
|
5947
|
+
const hasInputSchemaInput = Object.prototype.hasOwnProperty.call(
|
|
5948
|
+
approvalRequest,
|
|
5949
|
+
"inputSchemaInput"
|
|
5950
|
+
);
|
|
5877
5951
|
const validation = await safeValidateTypes4({
|
|
5878
|
-
value: toolCall.input,
|
|
5952
|
+
value: hasInputSchemaInput ? approvalRequest.inputSchemaInput : toolCall.input,
|
|
5879
5953
|
schema: asSchema4(tool3.inputSchema)
|
|
5880
5954
|
});
|
|
5955
|
+
let validationError;
|
|
5881
5956
|
if (!validation.success) {
|
|
5957
|
+
validationError = validation.error;
|
|
5958
|
+
} else {
|
|
5959
|
+
try {
|
|
5960
|
+
const revalidatedToolCall = await refineParsedToolCallInput({
|
|
5961
|
+
toolCall: {
|
|
5962
|
+
...toolCall,
|
|
5963
|
+
input: validation.value
|
|
5964
|
+
},
|
|
5965
|
+
refineToolInput
|
|
5966
|
+
});
|
|
5967
|
+
if (!isDeepEqualData(revalidatedToolCall.input, toolCall.input)) {
|
|
5968
|
+
validationError = new Error(
|
|
5969
|
+
"Approved tool input does not match the validated schema output."
|
|
5970
|
+
);
|
|
5971
|
+
}
|
|
5972
|
+
} catch (error) {
|
|
5973
|
+
validationError = error;
|
|
5974
|
+
}
|
|
5975
|
+
}
|
|
5976
|
+
if (validationError != null) {
|
|
5882
5977
|
invalid.push({
|
|
5883
5978
|
...approval,
|
|
5884
5979
|
error: new InvalidToolInputError({
|
|
5885
5980
|
toolName: toolCall.toolName,
|
|
5886
5981
|
toolInput: JSON.stringify(toolCall.input),
|
|
5887
|
-
cause:
|
|
5982
|
+
cause: validationError
|
|
5888
5983
|
})
|
|
5889
5984
|
});
|
|
5890
5985
|
continue;
|
|
@@ -6113,7 +6208,8 @@ async function generateText({
|
|
|
6113
6208
|
messages: initialMessages,
|
|
6114
6209
|
toolsContext,
|
|
6115
6210
|
runtimeContext,
|
|
6116
|
-
toolApprovalSecret: experimental_toolApprovalSecret
|
|
6211
|
+
toolApprovalSecret: experimental_toolApprovalSecret,
|
|
6212
|
+
refineToolInput
|
|
6117
6213
|
});
|
|
6118
6214
|
const deniedToolApprovals = [
|
|
6119
6215
|
...collectedDeniedToolApprovals,
|
|
@@ -7021,8 +7117,6 @@ function writeToServerResponse({
|
|
|
7021
7117
|
});
|
|
7022
7118
|
}
|
|
7023
7119
|
}
|
|
7024
|
-
} catch (error) {
|
|
7025
|
-
throw error;
|
|
7026
7120
|
} finally {
|
|
7027
7121
|
response.end();
|
|
7028
7122
|
}
|
|
@@ -7222,6 +7316,7 @@ var uiMessageChunkSchema = lazySchema(
|
|
|
7222
7316
|
approvalId: z.string(),
|
|
7223
7317
|
toolCallId: z.string(),
|
|
7224
7318
|
approvalDescriptor: z.unknown().optional(),
|
|
7319
|
+
inputSchemaInput: z.unknown().optional(),
|
|
7225
7320
|
reason: z.string().optional(),
|
|
7226
7321
|
isAutomatic: z.boolean().optional(),
|
|
7227
7322
|
signature: z.string().optional()
|
|
@@ -7882,6 +7977,10 @@ function processUIMessageStream({
|
|
|
7882
7977
|
toolInvocation.approval = {
|
|
7883
7978
|
id: chunk.approvalId,
|
|
7884
7979
|
...chunk.approvalDescriptor != null ? { descriptor: chunk.approvalDescriptor } : {},
|
|
7980
|
+
...Object.prototype.hasOwnProperty.call(
|
|
7981
|
+
chunk,
|
|
7982
|
+
"inputSchemaInput"
|
|
7983
|
+
) ? { inputSchemaInput: chunk.inputSchemaInput } : {},
|
|
7885
7984
|
...chunk.reason != null ? { requestReason: chunk.reason } : {},
|
|
7886
7985
|
...chunk.isAutomatic === true ? { isAutomatic: true } : {},
|
|
7887
7986
|
...chunk.signature != null ? { signature: chunk.signature } : {}
|
|
@@ -8155,7 +8254,7 @@ function handleUIMessageStreamFinish({
|
|
|
8155
8254
|
}
|
|
8156
8255
|
};
|
|
8157
8256
|
let finishCalled = false;
|
|
8158
|
-
const callOnEnd = async () => {
|
|
8257
|
+
const callOnEnd = async ({ isCancelled }) => {
|
|
8159
8258
|
var _a25;
|
|
8160
8259
|
if (finishCalled || !resolvedOnEnd) {
|
|
8161
8260
|
return;
|
|
@@ -8164,8 +8263,10 @@ function handleUIMessageStreamFinish({
|
|
|
8164
8263
|
const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
|
|
8165
8264
|
const declaredOutcome = (_a25 = getOutcome == null ? void 0 : getOutcome()) != null ? _a25 : { status: "unknown" };
|
|
8166
8265
|
const outcome = hasProcessingFailure ? { status: "failed", error: processingError } : declaredOutcome.status === "unknown" && isAborted ? { status: "aborted" } : declaredOutcome;
|
|
8266
|
+
const isConsumerCancellation = isCancelled && outcome.status === "unknown";
|
|
8167
8267
|
await resolvedOnEnd({
|
|
8168
8268
|
isAborted: isAborted || outcome.status === "aborted",
|
|
8269
|
+
...isConsumerCancellation ? { isCancelled: true } : {},
|
|
8169
8270
|
isContinuation,
|
|
8170
8271
|
outcome,
|
|
8171
8272
|
responseMessage: state.message,
|
|
@@ -8208,10 +8309,10 @@ function handleUIMessageStreamFinish({
|
|
|
8208
8309
|
},
|
|
8209
8310
|
// @ts-expect-error cancel is still new and missing from types https://developer.mozilla.org/en-US/docs/Web/API/TransformStream#browser_compatibility
|
|
8210
8311
|
async cancel() {
|
|
8211
|
-
await callOnEnd();
|
|
8312
|
+
await callOnEnd({ isCancelled: true });
|
|
8212
8313
|
},
|
|
8213
8314
|
async flush() {
|
|
8214
|
-
await callOnEnd();
|
|
8315
|
+
await callOnEnd({ isCancelled: false });
|
|
8215
8316
|
}
|
|
8216
8317
|
})
|
|
8217
8318
|
);
|
|
@@ -8375,10 +8476,12 @@ function toUIMessageChunk(part, {
|
|
|
8375
8476
|
};
|
|
8376
8477
|
}
|
|
8377
8478
|
case "tool-approval-request": {
|
|
8479
|
+
const inputSchemaInput = getToolCallInputSchemaInput(part.toolCall);
|
|
8378
8480
|
return {
|
|
8379
8481
|
type: "tool-approval-request",
|
|
8380
8482
|
approvalId: part.approvalId,
|
|
8381
8483
|
toolCallId: part.toolCall.toolCallId,
|
|
8484
|
+
...inputSchemaInput != null && !isDeepEqualData(inputSchemaInput.value, part.toolCall.input) ? { inputSchemaInput: inputSchemaInput.value } : {},
|
|
8382
8485
|
...part.reason != null ? { reason: part.reason } : {},
|
|
8383
8486
|
...part.isAutomatic != null ? { isAutomatic: part.isAutomatic } : {},
|
|
8384
8487
|
...part.signature != null ? { signature: part.signature } : {}
|
|
@@ -8994,7 +9097,6 @@ function executeToolsFromStream({
|
|
|
8994
9097
|
}
|
|
8995
9098
|
})
|
|
8996
9099
|
);
|
|
8997
|
-
return;
|
|
8998
9100
|
}
|
|
8999
9101
|
}
|
|
9000
9102
|
}
|
|
@@ -9017,24 +9119,25 @@ function invokeToolCallbacksFromStream({
|
|
|
9017
9119
|
toolName
|
|
9018
9120
|
}) => {
|
|
9019
9121
|
const ongoingToolCall = ongoingToolCalls[toolCallId];
|
|
9020
|
-
|
|
9021
|
-
|
|
9122
|
+
const validatedContext = ongoingToolCall == null ? void 0 : ongoingToolCall.validatedContexts[toolName];
|
|
9123
|
+
if (validatedContext != null) {
|
|
9124
|
+
return validatedContext;
|
|
9022
9125
|
}
|
|
9023
9126
|
const tool3 = getOwn(tools, toolName);
|
|
9024
|
-
const
|
|
9127
|
+
const newValidatedContext = validateToolContext({
|
|
9025
9128
|
toolName,
|
|
9026
9129
|
context: getOwn(toolsContext, toolName),
|
|
9027
9130
|
contextSchema: tool3 == null ? void 0 : tool3.contextSchema
|
|
9028
9131
|
});
|
|
9029
9132
|
if (ongoingToolCall != null) {
|
|
9030
|
-
ongoingToolCall.
|
|
9133
|
+
ongoingToolCall.validatedContexts[toolName] = newValidatedContext;
|
|
9031
9134
|
}
|
|
9032
|
-
return
|
|
9135
|
+
return newValidatedContext;
|
|
9033
9136
|
};
|
|
9034
9137
|
return stream.pipeThrough(
|
|
9035
9138
|
new TransformStream({
|
|
9036
9139
|
async transform(chunk, controller) {
|
|
9037
|
-
var _a25
|
|
9140
|
+
var _a25;
|
|
9038
9141
|
controller.enqueue(chunk);
|
|
9039
9142
|
if (isStreamRetryAttemptBoundaryPart(chunk)) {
|
|
9040
9143
|
ongoingToolCalls = createIdMap();
|
|
@@ -9044,7 +9147,7 @@ function invokeToolCallbacksFromStream({
|
|
|
9044
9147
|
case "tool-input-start": {
|
|
9045
9148
|
ongoingToolCalls[chunk.id] = {
|
|
9046
9149
|
toolName: chunk.toolName,
|
|
9047
|
-
|
|
9150
|
+
validatedContexts: createIdMap()
|
|
9048
9151
|
};
|
|
9049
9152
|
const tool3 = getOwn(tools, chunk.toolName);
|
|
9050
9153
|
if ((tool3 == null ? void 0 : tool3.onInputStart) != null) {
|
|
@@ -9078,7 +9181,7 @@ function invokeToolCallbacksFromStream({
|
|
|
9078
9181
|
break;
|
|
9079
9182
|
}
|
|
9080
9183
|
case "tool-call": {
|
|
9081
|
-
const toolName =
|
|
9184
|
+
const toolName = chunk.toolName;
|
|
9082
9185
|
const tool3 = getOwn(tools, toolName);
|
|
9083
9186
|
if (!chunk.invalid && (tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
|
|
9084
9187
|
const validatedContext = getValidatedContext({
|
|
@@ -10656,7 +10759,8 @@ var DefaultStreamTextResult = class {
|
|
|
10656
10759
|
messages: initialMessages,
|
|
10657
10760
|
toolsContext,
|
|
10658
10761
|
runtimeContext,
|
|
10659
|
-
toolApprovalSecret: experimental_toolApprovalSecret
|
|
10762
|
+
toolApprovalSecret: experimental_toolApprovalSecret,
|
|
10763
|
+
refineToolInput
|
|
10660
10764
|
});
|
|
10661
10765
|
const localDeniedToolApprovals = [
|
|
10662
10766
|
...deniedToolApprovals.filter(
|
|
@@ -12339,6 +12443,12 @@ async function convertToModelMessages(messages, options) {
|
|
|
12339
12443
|
toolCallId: part.toolCallId,
|
|
12340
12444
|
isAutomatic: part.approval.isAutomatic,
|
|
12341
12445
|
...part.approval.requestReason != null ? { reason: part.approval.requestReason } : {},
|
|
12446
|
+
...Object.prototype.hasOwnProperty.call(
|
|
12447
|
+
part.approval,
|
|
12448
|
+
"inputSchemaInput"
|
|
12449
|
+
) ? {
|
|
12450
|
+
inputSchemaInput: part.approval.inputSchemaInput
|
|
12451
|
+
} : {},
|
|
12342
12452
|
...part.approval.signature != null ? { signature: part.approval.signature } : {}
|
|
12343
12453
|
});
|
|
12344
12454
|
}
|
|
@@ -12504,8 +12614,31 @@ function asDynamicToolPart(toolPart) {
|
|
|
12504
12614
|
toolName: type.slice(5)
|
|
12505
12615
|
};
|
|
12506
12616
|
}
|
|
12507
|
-
|
|
12508
|
-
()
|
|
12617
|
+
function getToolPartInputSchemaInput(toolPart) {
|
|
12618
|
+
return toolPart.approval != null && Object.prototype.hasOwnProperty.call(toolPart.approval, "inputSchemaInput") ? { value: toolPart.approval.inputSchemaInput } : void 0;
|
|
12619
|
+
}
|
|
12620
|
+
var uiMessagesSchema = lazySchema2(() => {
|
|
12621
|
+
const approvalRequestedSchema = z.object({
|
|
12622
|
+
id: z.string(),
|
|
12623
|
+
approved: z.never().optional(),
|
|
12624
|
+
descriptor: z.unknown().optional(),
|
|
12625
|
+
requestReason: z.string().optional(),
|
|
12626
|
+
reason: z.never().optional(),
|
|
12627
|
+
isAutomatic: z.boolean().optional(),
|
|
12628
|
+
signature: z.string().optional(),
|
|
12629
|
+
inputSchemaInput: z.unknown().optional()
|
|
12630
|
+
});
|
|
12631
|
+
const approvalRespondedSchema = approvalRequestedSchema.extend({
|
|
12632
|
+
approved: z.boolean(),
|
|
12633
|
+
reason: z.string().optional()
|
|
12634
|
+
});
|
|
12635
|
+
const approvalGrantedSchema = approvalRespondedSchema.extend({
|
|
12636
|
+
approved: z.literal(true)
|
|
12637
|
+
});
|
|
12638
|
+
const approvalDeniedSchema = approvalRespondedSchema.extend({
|
|
12639
|
+
approved: z.literal(false)
|
|
12640
|
+
});
|
|
12641
|
+
return zodSchema2(
|
|
12509
12642
|
z.array(
|
|
12510
12643
|
z.object({
|
|
12511
12644
|
id: z.string(),
|
|
@@ -12608,15 +12741,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12608
12741
|
output: z.never().optional(),
|
|
12609
12742
|
errorText: z.never().optional(),
|
|
12610
12743
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12611
|
-
approval:
|
|
12612
|
-
id: z.string(),
|
|
12613
|
-
approved: z.never().optional(),
|
|
12614
|
-
descriptor: z.unknown().optional(),
|
|
12615
|
-
requestReason: z.string().optional(),
|
|
12616
|
-
reason: z.never().optional(),
|
|
12617
|
-
isAutomatic: z.boolean().optional(),
|
|
12618
|
-
signature: z.string().optional()
|
|
12619
|
-
})
|
|
12744
|
+
approval: approvalRequestedSchema
|
|
12620
12745
|
}),
|
|
12621
12746
|
z.object({
|
|
12622
12747
|
type: z.literal("dynamic-tool"),
|
|
@@ -12630,15 +12755,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12630
12755
|
output: z.never().optional(),
|
|
12631
12756
|
errorText: z.never().optional(),
|
|
12632
12757
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12633
|
-
approval:
|
|
12634
|
-
id: z.string(),
|
|
12635
|
-
approved: z.boolean(),
|
|
12636
|
-
descriptor: z.unknown().optional(),
|
|
12637
|
-
requestReason: z.string().optional(),
|
|
12638
|
-
reason: z.string().optional(),
|
|
12639
|
-
isAutomatic: z.boolean().optional(),
|
|
12640
|
-
signature: z.string().optional()
|
|
12641
|
-
})
|
|
12758
|
+
approval: approvalRespondedSchema
|
|
12642
12759
|
}),
|
|
12643
12760
|
z.object({
|
|
12644
12761
|
type: z.literal("dynamic-tool"),
|
|
@@ -12654,15 +12771,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12654
12771
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12655
12772
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
12656
12773
|
preliminary: z.boolean().optional(),
|
|
12657
|
-
approval:
|
|
12658
|
-
id: z.string(),
|
|
12659
|
-
approved: z.literal(true),
|
|
12660
|
-
descriptor: z.unknown().optional(),
|
|
12661
|
-
requestReason: z.string().optional(),
|
|
12662
|
-
reason: z.string().optional(),
|
|
12663
|
-
isAutomatic: z.boolean().optional(),
|
|
12664
|
-
signature: z.string().optional()
|
|
12665
|
-
}).optional()
|
|
12774
|
+
approval: approvalGrantedSchema.optional()
|
|
12666
12775
|
}),
|
|
12667
12776
|
z.object({
|
|
12668
12777
|
type: z.literal("dynamic-tool"),
|
|
@@ -12678,15 +12787,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12678
12787
|
errorText: z.string(),
|
|
12679
12788
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12680
12789
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
12681
|
-
approval:
|
|
12682
|
-
id: z.string(),
|
|
12683
|
-
approved: z.literal(true),
|
|
12684
|
-
descriptor: z.unknown().optional(),
|
|
12685
|
-
requestReason: z.string().optional(),
|
|
12686
|
-
reason: z.string().optional(),
|
|
12687
|
-
isAutomatic: z.boolean().optional(),
|
|
12688
|
-
signature: z.string().optional()
|
|
12689
|
-
}).optional()
|
|
12790
|
+
approval: approvalGrantedSchema.optional()
|
|
12690
12791
|
}),
|
|
12691
12792
|
z.object({
|
|
12692
12793
|
type: z.literal("dynamic-tool"),
|
|
@@ -12700,15 +12801,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12700
12801
|
output: z.never().optional(),
|
|
12701
12802
|
errorText: z.never().optional(),
|
|
12702
12803
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12703
|
-
approval:
|
|
12704
|
-
id: z.string(),
|
|
12705
|
-
approved: z.literal(false),
|
|
12706
|
-
descriptor: z.unknown().optional(),
|
|
12707
|
-
requestReason: z.string().optional(),
|
|
12708
|
-
reason: z.string().optional(),
|
|
12709
|
-
isAutomatic: z.boolean().optional(),
|
|
12710
|
-
signature: z.string().optional()
|
|
12711
|
-
})
|
|
12804
|
+
approval: approvalDeniedSchema
|
|
12712
12805
|
}),
|
|
12713
12806
|
z.object({
|
|
12714
12807
|
type: z.string().startsWith("tool-"),
|
|
@@ -12747,15 +12840,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12747
12840
|
output: z.never().optional(),
|
|
12748
12841
|
errorText: z.never().optional(),
|
|
12749
12842
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12750
|
-
approval:
|
|
12751
|
-
id: z.string(),
|
|
12752
|
-
approved: z.never().optional(),
|
|
12753
|
-
descriptor: z.unknown().optional(),
|
|
12754
|
-
requestReason: z.string().optional(),
|
|
12755
|
-
reason: z.never().optional(),
|
|
12756
|
-
isAutomatic: z.boolean().optional(),
|
|
12757
|
-
signature: z.string().optional()
|
|
12758
|
-
})
|
|
12843
|
+
approval: approvalRequestedSchema
|
|
12759
12844
|
}),
|
|
12760
12845
|
z.object({
|
|
12761
12846
|
type: z.string().startsWith("tool-"),
|
|
@@ -12768,15 +12853,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12768
12853
|
output: z.never().optional(),
|
|
12769
12854
|
errorText: z.never().optional(),
|
|
12770
12855
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12771
|
-
approval:
|
|
12772
|
-
id: z.string(),
|
|
12773
|
-
approved: z.boolean(),
|
|
12774
|
-
descriptor: z.unknown().optional(),
|
|
12775
|
-
requestReason: z.string().optional(),
|
|
12776
|
-
reason: z.string().optional(),
|
|
12777
|
-
isAutomatic: z.boolean().optional(),
|
|
12778
|
-
signature: z.string().optional()
|
|
12779
|
-
})
|
|
12856
|
+
approval: approvalRespondedSchema
|
|
12780
12857
|
}),
|
|
12781
12858
|
z.object({
|
|
12782
12859
|
type: z.string().startsWith("tool-"),
|
|
@@ -12791,15 +12868,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12791
12868
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12792
12869
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
12793
12870
|
preliminary: z.boolean().optional(),
|
|
12794
|
-
approval:
|
|
12795
|
-
id: z.string(),
|
|
12796
|
-
approved: z.literal(true),
|
|
12797
|
-
descriptor: z.unknown().optional(),
|
|
12798
|
-
requestReason: z.string().optional(),
|
|
12799
|
-
reason: z.string().optional(),
|
|
12800
|
-
isAutomatic: z.boolean().optional(),
|
|
12801
|
-
signature: z.string().optional()
|
|
12802
|
-
}).optional()
|
|
12871
|
+
approval: approvalGrantedSchema.optional()
|
|
12803
12872
|
}),
|
|
12804
12873
|
z.object({
|
|
12805
12874
|
type: z.string().startsWith("tool-"),
|
|
@@ -12814,15 +12883,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12814
12883
|
errorText: z.string(),
|
|
12815
12884
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12816
12885
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
12817
|
-
approval:
|
|
12818
|
-
id: z.string(),
|
|
12819
|
-
approved: z.literal(true),
|
|
12820
|
-
descriptor: z.unknown().optional(),
|
|
12821
|
-
requestReason: z.string().optional(),
|
|
12822
|
-
reason: z.string().optional(),
|
|
12823
|
-
isAutomatic: z.boolean().optional(),
|
|
12824
|
-
signature: z.string().optional()
|
|
12825
|
-
}).optional()
|
|
12886
|
+
approval: approvalGrantedSchema.optional()
|
|
12826
12887
|
}),
|
|
12827
12888
|
z.object({
|
|
12828
12889
|
type: z.string().startsWith("tool-"),
|
|
@@ -12835,15 +12896,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12835
12896
|
output: z.never().optional(),
|
|
12836
12897
|
errorText: z.never().optional(),
|
|
12837
12898
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12838
|
-
approval:
|
|
12839
|
-
id: z.string(),
|
|
12840
|
-
approved: z.literal(false),
|
|
12841
|
-
descriptor: z.unknown().optional(),
|
|
12842
|
-
requestReason: z.string().optional(),
|
|
12843
|
-
reason: z.string().optional(),
|
|
12844
|
-
isAutomatic: z.boolean().optional(),
|
|
12845
|
-
signature: z.string().optional()
|
|
12846
|
-
})
|
|
12899
|
+
approval: approvalDeniedSchema
|
|
12847
12900
|
})
|
|
12848
12901
|
])
|
|
12849
12902
|
)
|
|
@@ -12861,13 +12914,14 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12861
12914
|
}
|
|
12862
12915
|
})
|
|
12863
12916
|
).nonempty("Messages array must not be empty")
|
|
12864
|
-
)
|
|
12865
|
-
);
|
|
12917
|
+
);
|
|
12918
|
+
});
|
|
12866
12919
|
async function safeValidateUIMessagesInternal({
|
|
12867
12920
|
messages,
|
|
12868
12921
|
metadataSchema,
|
|
12869
12922
|
dataSchemas,
|
|
12870
|
-
tools
|
|
12923
|
+
tools,
|
|
12924
|
+
experimental_refineToolInput
|
|
12871
12925
|
}, {
|
|
12872
12926
|
convertMissingTerminalToolsToDynamic
|
|
12873
12927
|
}) {
|
|
@@ -12889,7 +12943,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12889
12943
|
warnIfUIMessageHasDeprecatedRawInput(validatedMessages);
|
|
12890
12944
|
if (metadataSchema) {
|
|
12891
12945
|
for (const [msgIdx, message] of validatedMessages.entries()) {
|
|
12892
|
-
await validateTypes4({
|
|
12946
|
+
message.metadata = await validateTypes4({
|
|
12893
12947
|
value: message.metadata,
|
|
12894
12948
|
schema: metadataSchema,
|
|
12895
12949
|
context: {
|
|
@@ -12921,7 +12975,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12921
12975
|
})
|
|
12922
12976
|
};
|
|
12923
12977
|
}
|
|
12924
|
-
await validateTypes4({
|
|
12978
|
+
dataPart.data = await validateTypes4({
|
|
12925
12979
|
value: dataPart.data,
|
|
12926
12980
|
schema: dataSchema,
|
|
12927
12981
|
context: {
|
|
@@ -12963,35 +13017,44 @@ async function safeValidateUIMessagesInternal({
|
|
|
12963
13017
|
entityName: toolName,
|
|
12964
13018
|
entityId: toolPart.toolCallId
|
|
12965
13019
|
};
|
|
13020
|
+
const inputSchemaInput = getToolPartInputSchemaInput(toolPart);
|
|
13021
|
+
const inputToValidate = inputSchemaInput == null ? toolPart.input : inputSchemaInput.value;
|
|
12966
13022
|
let convertToDynamic = false;
|
|
12967
|
-
if (toolPart.state
|
|
12968
|
-
if (toolPart.input !== void 0) {
|
|
12969
|
-
const result = await safeValidateTypes5({
|
|
12970
|
-
value: toolPart.input,
|
|
12971
|
-
schema: tool3.inputSchema,
|
|
12972
|
-
context: inputValidationContext
|
|
12973
|
-
});
|
|
12974
|
-
convertToDynamic = !result.success;
|
|
12975
|
-
}
|
|
12976
|
-
} else if (toolPart.state === "output-available") {
|
|
13023
|
+
if (toolPart.state !== "input-streaming" && (toolPart.state !== "output-error" || inputSchemaInput != null || toolPart.input !== void 0)) {
|
|
12977
13024
|
const result = await safeValidateTypes5({
|
|
12978
|
-
value:
|
|
13025
|
+
value: inputToValidate,
|
|
12979
13026
|
schema: tool3.inputSchema,
|
|
12980
13027
|
context: inputValidationContext
|
|
12981
13028
|
});
|
|
13029
|
+
let inputError;
|
|
12982
13030
|
if (!result.success) {
|
|
12983
|
-
|
|
13031
|
+
inputError = result.error;
|
|
13032
|
+
} else if (inputSchemaInput != null) {
|
|
13033
|
+
try {
|
|
13034
|
+
const refine = getOwn(experimental_refineToolInput, toolName);
|
|
13035
|
+
const reconstructedInput = refine == null ? result.value : await refine(result.value);
|
|
13036
|
+
if (!isDeepEqualData(reconstructedInput, toolPart.input)) {
|
|
13037
|
+
inputError = new TypeValidationError3({
|
|
13038
|
+
value: toolPart.input,
|
|
13039
|
+
cause: "Tool input does not match the output reconstructed from inputSchemaInput.",
|
|
13040
|
+
context: inputValidationContext
|
|
13041
|
+
});
|
|
13042
|
+
}
|
|
13043
|
+
} catch (error) {
|
|
13044
|
+
inputError = new TypeValidationError3({
|
|
13045
|
+
value: inputToValidate,
|
|
13046
|
+
cause: error,
|
|
13047
|
+
context: inputValidationContext
|
|
13048
|
+
});
|
|
13049
|
+
}
|
|
13050
|
+
}
|
|
13051
|
+
if (inputError != null) {
|
|
13052
|
+
if (toolPart.state === "output-error" || toolPart.state === "output-available" && isEmptyObject(toolPart.input)) {
|
|
12984
13053
|
convertToDynamic = true;
|
|
12985
13054
|
} else {
|
|
12986
|
-
throw
|
|
13055
|
+
throw inputError;
|
|
12987
13056
|
}
|
|
12988
13057
|
}
|
|
12989
|
-
} else if (toolPart.state === "input-available" || toolPart.state === "approval-requested" || toolPart.state === "approval-responded" || toolPart.state === "output-denied") {
|
|
12990
|
-
await validateTypes4({
|
|
12991
|
-
value: toolPart.input,
|
|
12992
|
-
schema: tool3.inputSchema,
|
|
12993
|
-
context: inputValidationContext
|
|
12994
|
-
});
|
|
12995
13058
|
}
|
|
12996
13059
|
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
|
12997
13060
|
await validateTypes4({
|
|
@@ -13446,33 +13509,6 @@ function toImageModelV4File(dataContent) {
|
|
|
13446
13509
|
};
|
|
13447
13510
|
}
|
|
13448
13511
|
|
|
13449
|
-
// src/util/is-deep-equal-data.ts
|
|
13450
|
-
function isDeepEqualData(obj1, obj2) {
|
|
13451
|
-
if (obj1 === obj2) return true;
|
|
13452
|
-
if (obj1 == null || obj2 == null) return false;
|
|
13453
|
-
if (typeof obj1 !== "object" && typeof obj2 !== "object")
|
|
13454
|
-
return obj1 === obj2;
|
|
13455
|
-
if (obj1.constructor !== obj2.constructor) return false;
|
|
13456
|
-
if (obj1 instanceof Date && obj2 instanceof Date) {
|
|
13457
|
-
return obj1.getTime() === obj2.getTime();
|
|
13458
|
-
}
|
|
13459
|
-
if (Array.isArray(obj1)) {
|
|
13460
|
-
if (obj1.length !== obj2.length) return false;
|
|
13461
|
-
for (let i = 0; i < obj1.length; i++) {
|
|
13462
|
-
if (!isDeepEqualData(obj1[i], obj2[i])) return false;
|
|
13463
|
-
}
|
|
13464
|
-
return true;
|
|
13465
|
-
}
|
|
13466
|
-
const keys1 = Object.keys(obj1);
|
|
13467
|
-
const keys2 = Object.keys(obj2);
|
|
13468
|
-
if (keys1.length !== keys2.length) return false;
|
|
13469
|
-
for (const key of keys1) {
|
|
13470
|
-
if (!keys2.includes(key)) return false;
|
|
13471
|
-
if (!isDeepEqualData(obj1[key], obj2[key])) return false;
|
|
13472
|
-
}
|
|
13473
|
-
return true;
|
|
13474
|
-
}
|
|
13475
|
-
|
|
13476
13512
|
// src/batch/batch.ts
|
|
13477
13513
|
async function cancelBatch({
|
|
13478
13514
|
provider,
|
|
@@ -14194,6 +14230,14 @@ function getEmbeddingModelMaxInputBytesPerCall(model) {
|
|
|
14194
14230
|
return model[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL];
|
|
14195
14231
|
}
|
|
14196
14232
|
|
|
14233
|
+
// src/model/get-embedding-model-provider-options-transformer.ts
|
|
14234
|
+
import {
|
|
14235
|
+
EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER
|
|
14236
|
+
} from "@ai-sdk/provider-utils";
|
|
14237
|
+
function getEmbeddingModelProviderOptionsTransformer(model) {
|
|
14238
|
+
return model[EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER];
|
|
14239
|
+
}
|
|
14240
|
+
|
|
14197
14241
|
// src/util/split-array.ts
|
|
14198
14242
|
function splitArray(array3, chunkSize) {
|
|
14199
14243
|
if (chunkSize <= 0) {
|
|
@@ -14264,7 +14308,7 @@ async function embedMany({
|
|
|
14264
14308
|
type: "embedMany",
|
|
14265
14309
|
event: startEvent,
|
|
14266
14310
|
execute: async () => {
|
|
14267
|
-
var _a26
|
|
14311
|
+
var _a26;
|
|
14268
14312
|
await notify({
|
|
14269
14313
|
event: startEvent,
|
|
14270
14314
|
callbacks: [resolvedOnStart, telemetryDispatcher.onStart]
|
|
@@ -14283,7 +14327,7 @@ async function embedMany({
|
|
|
14283
14327
|
const hasInputByteLimit = maxInputBytesPerCall != null && maxInputBytesPerCall !== Infinity;
|
|
14284
14328
|
if (!hasEmbeddingLimit && !hasInputByteLimit) {
|
|
14285
14329
|
const { embeddings: embeddings2, usage, warnings: warnings2, response, providerMetadata: providerMetadata2 } = await retry(async () => {
|
|
14286
|
-
var _a27,
|
|
14330
|
+
var _a27, _b25;
|
|
14287
14331
|
const embedCallId = generateCallId();
|
|
14288
14332
|
await notify({
|
|
14289
14333
|
event: {
|
|
@@ -14320,7 +14364,7 @@ async function embedMany({
|
|
|
14320
14364
|
return {
|
|
14321
14365
|
embeddings: embeddings3,
|
|
14322
14366
|
usage: usage2,
|
|
14323
|
-
warnings: (
|
|
14367
|
+
warnings: (_b25 = modelResponse.warnings) != null ? _b25 : [],
|
|
14324
14368
|
providerMetadata: modelResponse.providerMetadata,
|
|
14325
14369
|
response: modelResponse.response
|
|
14326
14370
|
};
|
|
@@ -14361,6 +14405,7 @@ async function embedMany({
|
|
|
14361
14405
|
maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
|
|
14362
14406
|
maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
|
|
14363
14407
|
});
|
|
14408
|
+
const providerOptionsTransformer = getEmbeddingModelProviderOptionsTransformer(model);
|
|
14364
14409
|
const embeddings = [];
|
|
14365
14410
|
const warnings = [];
|
|
14366
14411
|
const responses = [];
|
|
@@ -14370,11 +14415,20 @@ async function embedMany({
|
|
|
14370
14415
|
valueChunks,
|
|
14371
14416
|
supportsParallelCalls ? maxParallelCalls : 1
|
|
14372
14417
|
);
|
|
14418
|
+
let nextChunkStartIndex = 0;
|
|
14373
14419
|
for (const parallelChunk of parallelChunks) {
|
|
14374
14420
|
const results = await Promise.all(
|
|
14375
14421
|
parallelChunk.map(async (chunk) => {
|
|
14422
|
+
const startIndex = nextChunkStartIndex;
|
|
14423
|
+
nextChunkStartIndex += chunk.length;
|
|
14424
|
+
const chunkProviderOptions = providerOptionsTransformer ? await providerOptionsTransformer({
|
|
14425
|
+
providerOptions,
|
|
14426
|
+
values,
|
|
14427
|
+
startIndex,
|
|
14428
|
+
endIndex: startIndex + chunk.length
|
|
14429
|
+
}) : providerOptions;
|
|
14376
14430
|
const result = await retry(async () => {
|
|
14377
|
-
var _a27,
|
|
14431
|
+
var _a27, _b25;
|
|
14378
14432
|
const embedCallId = generateCallId();
|
|
14379
14433
|
await notify({
|
|
14380
14434
|
event: {
|
|
@@ -14391,7 +14445,7 @@ async function embedMany({
|
|
|
14391
14445
|
values: chunk,
|
|
14392
14446
|
abortSignal,
|
|
14393
14447
|
headers: headersWithUserAgent,
|
|
14394
|
-
providerOptions
|
|
14448
|
+
providerOptions: chunkProviderOptions
|
|
14395
14449
|
});
|
|
14396
14450
|
const chunkEmbeddings = modelResponse.embeddings;
|
|
14397
14451
|
const usage = (_a27 = modelResponse.usage) != null ? _a27 : { tokens: NaN };
|
|
@@ -14411,7 +14465,7 @@ async function embedMany({
|
|
|
14411
14465
|
return {
|
|
14412
14466
|
embeddings: chunkEmbeddings,
|
|
14413
14467
|
usage,
|
|
14414
|
-
warnings: (
|
|
14468
|
+
warnings: (_b25 = modelResponse.warnings) != null ? _b25 : [],
|
|
14415
14469
|
providerMetadata: modelResponse.providerMetadata,
|
|
14416
14470
|
response: modelResponse.response
|
|
14417
14471
|
};
|
|
@@ -14436,7 +14490,7 @@ async function embedMany({
|
|
|
14436
14490
|
result.providerMetadata
|
|
14437
14491
|
)) {
|
|
14438
14492
|
providerMetadata[providerName] = {
|
|
14439
|
-
...
|
|
14493
|
+
...providerMetadata[providerName],
|
|
14440
14494
|
...metadata
|
|
14441
14495
|
};
|
|
14442
14496
|
}
|
|
@@ -14474,7 +14528,7 @@ async function embedMany({
|
|
|
14474
14528
|
responses
|
|
14475
14529
|
});
|
|
14476
14530
|
} catch (error) {
|
|
14477
|
-
await ((
|
|
14531
|
+
await ((_a26 = telemetryDispatcher.onError) == null ? void 0 : _a26.call(telemetryDispatcher, { callId, error }));
|
|
14478
14532
|
throw error;
|
|
14479
14533
|
}
|
|
14480
14534
|
}
|
|
@@ -16464,7 +16518,21 @@ function getOutputFormatMediaType(outputFormat) {
|
|
|
16464
16518
|
return void 0;
|
|
16465
16519
|
}
|
|
16466
16520
|
const normalizedOutputFormat = outputFormat.trim().toLowerCase();
|
|
16467
|
-
|
|
16521
|
+
switch (normalizedOutputFormat) {
|
|
16522
|
+
case "pcm":
|
|
16523
|
+
case "audio/pcm":
|
|
16524
|
+
return "audio/pcm";
|
|
16525
|
+
case "audio/l16":
|
|
16526
|
+
return "audio/l16";
|
|
16527
|
+
case "mulaw":
|
|
16528
|
+
case "audio/mulaw":
|
|
16529
|
+
return "audio/mulaw";
|
|
16530
|
+
case "alaw":
|
|
16531
|
+
case "audio/alaw":
|
|
16532
|
+
return "audio/alaw";
|
|
16533
|
+
default:
|
|
16534
|
+
return void 0;
|
|
16535
|
+
}
|
|
16468
16536
|
}
|
|
16469
16537
|
var DefaultSpeechResult = class {
|
|
16470
16538
|
constructor(options) {
|
|
@@ -16493,7 +16561,9 @@ function pruneMessages({
|
|
|
16493
16561
|
}
|
|
16494
16562
|
return {
|
|
16495
16563
|
...message,
|
|
16496
|
-
content: message.content.filter(
|
|
16564
|
+
content: message.content.filter(
|
|
16565
|
+
(part) => part.type !== "reasoning" && part.type !== "reasoning-file"
|
|
16566
|
+
)
|
|
16497
16567
|
};
|
|
16498
16568
|
});
|
|
16499
16569
|
}
|
|
@@ -17194,7 +17264,6 @@ function normalizeImageData(dataContent, { restrictToImages = true } = {}) {
|
|
|
17194
17264
|
data: bytes
|
|
17195
17265
|
};
|
|
17196
17266
|
}
|
|
17197
|
-
return void 0;
|
|
17198
17267
|
}
|
|
17199
17268
|
function normalizeReferenceData(reference) {
|
|
17200
17269
|
const isObjectForm = typeof reference === "object" && reference != null && !(reference instanceof Uint8Array) && !(reference instanceof ArrayBuffer) && "data" in reference;
|
|
@@ -17894,7 +17963,8 @@ var doWrap = ({
|
|
|
17894
17963
|
// src/middleware/wrap-embedding-model.ts
|
|
17895
17964
|
import {
|
|
17896
17965
|
asArray as asArray9,
|
|
17897
|
-
EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2
|
|
17966
|
+
EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2,
|
|
17967
|
+
EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER as EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER2
|
|
17898
17968
|
} from "@ai-sdk/provider-utils";
|
|
17899
17969
|
var wrapEmbeddingModel = ({
|
|
17900
17970
|
model: inputModel,
|
|
@@ -17932,6 +18002,7 @@ var doWrap2 = ({
|
|
|
17932
18002
|
modelId: (_b25 = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b25 : model.modelId,
|
|
17933
18003
|
maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? void 0 : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
|
|
17934
18004
|
[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2]: getEmbeddingModelMaxInputBytesPerCall(model),
|
|
18005
|
+
[EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER2]: getEmbeddingModelProviderOptionsTransformer(model),
|
|
17935
18006
|
supportsParallelCalls: (_d = overrideSupportsParallelCalls == null ? void 0 : overrideSupportsParallelCalls({ model })) != null ? _d : model.supportsParallelCalls,
|
|
17936
18007
|
async doEmbed(params) {
|
|
17937
18008
|
const transformedParams = await doTransform({ params });
|
|
@@ -20774,9 +20845,9 @@ function customProvider({
|
|
|
20774
20845
|
if (videoModels != null && modelId in videoModels) {
|
|
20775
20846
|
return resolveVideoModel(videoModels[modelId]);
|
|
20776
20847
|
}
|
|
20777
|
-
const
|
|
20778
|
-
if (videoModel) {
|
|
20779
|
-
return videoModel(modelId);
|
|
20848
|
+
const provider = fallbackProviderArg;
|
|
20849
|
+
if (provider == null ? void 0 : provider.videoModel) {
|
|
20850
|
+
return resolveVideoModel(provider.videoModel(modelId));
|
|
20780
20851
|
}
|
|
20781
20852
|
throw new NoSuchModelError3({ modelId, modelType: "videoModel" });
|
|
20782
20853
|
}
|
|
@@ -22185,9 +22256,24 @@ var AbstractChat = class {
|
|
|
22185
22256
|
this.sendMessage = async (message, options) => {
|
|
22186
22257
|
var _a25, _b25, _c, _d;
|
|
22187
22258
|
if (message == null) {
|
|
22188
|
-
|
|
22189
|
-
|
|
22190
|
-
messageId
|
|
22259
|
+
let messageId = this.pendingApprovalMessageId;
|
|
22260
|
+
if (messageId == null) {
|
|
22261
|
+
messageId = (_a25 = this.lastMessage) == null ? void 0 : _a25.id;
|
|
22262
|
+
for (let i = this.state.messages.length - 1; i >= 0; i--) {
|
|
22263
|
+
const candidate = this.state.messages[i];
|
|
22264
|
+
if (candidate.role === "assistant" && candidate.parts.some(
|
|
22265
|
+
(part) => isToolUIPart(part) && part.state === "approval-responded"
|
|
22266
|
+
)) {
|
|
22267
|
+
messageId = candidate.id;
|
|
22268
|
+
break;
|
|
22269
|
+
}
|
|
22270
|
+
}
|
|
22271
|
+
}
|
|
22272
|
+
const consumesPendingApproval = messageId != null && messageId === this.pendingApprovalMessageId;
|
|
22273
|
+
const pendingApprovalMessageIndex = consumesPendingApproval ? this.state.messages.findIndex((message2) => message2.id === messageId) : -1;
|
|
22274
|
+
await this.makeRequestForToolApproval({
|
|
22275
|
+
messageId,
|
|
22276
|
+
messageIndex: pendingApprovalMessageIndex,
|
|
22191
22277
|
...options
|
|
22192
22278
|
});
|
|
22193
22279
|
return;
|
|
@@ -22302,16 +22388,24 @@ var AbstractChat = class {
|
|
|
22302
22388
|
options
|
|
22303
22389
|
}) => this.jobExecutor.run(async () => {
|
|
22304
22390
|
const messages = this.state.messages;
|
|
22305
|
-
const lastMessage = messages[messages.length - 1];
|
|
22306
22391
|
const updatePart = (part) => isToolUIPart(part) && part.state === "approval-requested" && part.approval.id === id ? {
|
|
22307
22392
|
...part,
|
|
22308
22393
|
state: "approval-responded",
|
|
22309
22394
|
approval: { ...part.approval, id, approved, reason }
|
|
22310
22395
|
} : part;
|
|
22311
|
-
|
|
22312
|
-
|
|
22313
|
-
|
|
22314
|
-
|
|
22396
|
+
const messageIndex = messages.findIndex(
|
|
22397
|
+
(message) => message.parts.some(
|
|
22398
|
+
(part) => isToolUIPart(part) && part.state === "approval-requested" && part.approval.id === id
|
|
22399
|
+
)
|
|
22400
|
+
);
|
|
22401
|
+
if (messageIndex !== -1) {
|
|
22402
|
+
const message = messages[messageIndex];
|
|
22403
|
+
this.state.replaceMessage(messageIndex, {
|
|
22404
|
+
...message,
|
|
22405
|
+
parts: message.parts.map(updatePart)
|
|
22406
|
+
});
|
|
22407
|
+
this.pendingApprovalMessageId = message.id;
|
|
22408
|
+
}
|
|
22315
22409
|
if (this.activeResponse) {
|
|
22316
22410
|
this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(updatePart);
|
|
22317
22411
|
}
|
|
@@ -22319,9 +22413,10 @@ var AbstractChat = class {
|
|
|
22319
22413
|
this.shouldSendAutomatically().then((shouldSend) => {
|
|
22320
22414
|
var _a25;
|
|
22321
22415
|
if (shouldSend) {
|
|
22322
|
-
this.
|
|
22323
|
-
|
|
22324
|
-
messageId
|
|
22416
|
+
const messageId = messageIndex === -1 ? (_a25 = this.lastMessage) == null ? void 0 : _a25.id : messages[messageIndex].id;
|
|
22417
|
+
this.makeRequestForToolApproval({
|
|
22418
|
+
messageId,
|
|
22419
|
+
messageIndex,
|
|
22325
22420
|
...options
|
|
22326
22421
|
});
|
|
22327
22422
|
}
|
|
@@ -22424,6 +22519,25 @@ var AbstractChat = class {
|
|
|
22424
22519
|
}
|
|
22425
22520
|
return result;
|
|
22426
22521
|
}
|
|
22522
|
+
async makeRequestForToolApproval({
|
|
22523
|
+
messageId,
|
|
22524
|
+
messageIndex,
|
|
22525
|
+
...options
|
|
22526
|
+
}) {
|
|
22527
|
+
var _a25, _b25;
|
|
22528
|
+
const consumesPendingApproval = messageId != null && messageId === this.pendingApprovalMessageId;
|
|
22529
|
+
if (consumesPendingApproval) {
|
|
22530
|
+
this.pendingApprovalMessageId = void 0;
|
|
22531
|
+
}
|
|
22532
|
+
await this.makeRequest({
|
|
22533
|
+
trigger: "submit-message",
|
|
22534
|
+
messageId,
|
|
22535
|
+
...options
|
|
22536
|
+
});
|
|
22537
|
+
if (consumesPendingApproval && this.status === "error" && this.pendingApprovalMessageId == null) {
|
|
22538
|
+
this.pendingApprovalMessageId = (_b25 = (_a25 = this.state.messages[messageIndex]) == null ? void 0 : _a25.id) != null ? _b25 : messageId;
|
|
22539
|
+
}
|
|
22540
|
+
}
|
|
22427
22541
|
async makeRequest({
|
|
22428
22542
|
trigger,
|
|
22429
22543
|
metadata,
|
|
@@ -22490,6 +22604,9 @@ var AbstractChat = class {
|
|
|
22490
22604
|
}
|
|
22491
22605
|
this.setStatus({ status: "submitted", error: void 0 });
|
|
22492
22606
|
const lastMessage = this.lastMessage;
|
|
22607
|
+
const responseMessageIndex = trigger === "submit-message" && messageId != null ? this.state.messages.findIndex((message) => message.id === messageId) : this.state.messages.length - 1;
|
|
22608
|
+
const responseMessage = responseMessageIndex === -1 ? lastMessage : this.state.messages[responseMessageIndex];
|
|
22609
|
+
const usesEarlierAssistantMessage = responseMessageIndex !== -1 && responseMessageIndex < this.state.messages.length - 1 && (responseMessage == null ? void 0 : responseMessage.role) === "assistant";
|
|
22493
22610
|
let isAbort = false;
|
|
22494
22611
|
let isDisconnect = false;
|
|
22495
22612
|
let isError2 = false;
|
|
@@ -22497,7 +22614,7 @@ var AbstractChat = class {
|
|
|
22497
22614
|
try {
|
|
22498
22615
|
const response = {
|
|
22499
22616
|
state: createStreamingUIMessageState({
|
|
22500
|
-
lastMessage: trigger === "resume-stream" || trigger === "regenerate-message" ? void 0 : this.state.snapshot(
|
|
22617
|
+
lastMessage: trigger === "resume-stream" || trigger === "regenerate-message" ? void 0 : this.state.snapshot(responseMessage),
|
|
22501
22618
|
messageId: this.generateId()
|
|
22502
22619
|
}),
|
|
22503
22620
|
abortController
|
|
@@ -22538,8 +22655,12 @@ var AbstractChat = class {
|
|
|
22538
22655
|
if (updateStatus) {
|
|
22539
22656
|
this.setStatus({ status: "streaming" });
|
|
22540
22657
|
}
|
|
22541
|
-
|
|
22542
|
-
|
|
22658
|
+
if (usesEarlierAssistantMessage) {
|
|
22659
|
+
this.state.replaceMessage(
|
|
22660
|
+
responseMessageIndex,
|
|
22661
|
+
response.state.message
|
|
22662
|
+
);
|
|
22663
|
+
} else if (response.state.message.id === ((_a26 = this.lastMessage) == null ? void 0 : _a26.id)) {
|
|
22543
22664
|
this.state.replaceMessage(
|
|
22544
22665
|
this.state.messages.length - 1,
|
|
22545
22666
|
response.state.message
|
|
@@ -22642,6 +22763,7 @@ var DirectChatTransport = class {
|
|
|
22642
22763
|
messages,
|
|
22643
22764
|
abortSignal
|
|
22644
22765
|
}) {
|
|
22766
|
+
var _a25;
|
|
22645
22767
|
const validatedMessages = await validateUIMessagesForAgent({
|
|
22646
22768
|
messages,
|
|
22647
22769
|
// tools are compatible; the casting is required because the context param is
|
|
@@ -22658,6 +22780,7 @@ var DirectChatTransport = class {
|
|
|
22658
22780
|
});
|
|
22659
22781
|
return toUIMessageStream({
|
|
22660
22782
|
...this.uiMessageStreamOptions,
|
|
22783
|
+
originalMessages: (_a25 = this.uiMessageStreamOptions.originalMessages) != null ? _a25 : validatedMessages,
|
|
22661
22784
|
stream: result.stream,
|
|
22662
22785
|
tools: this.agent.tools
|
|
22663
22786
|
});
|