ai 7.0.112 → 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 +26 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +315 -213
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +105 -28
- 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/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/package.json +11 -11
- 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/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/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 +98 -132
- 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/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 ({
|
|
@@ -2695,7 +2695,10 @@ var toolApprovalRequestSchema = z.object(
|
|
|
2695
2695
|
type: z.literal("tool-approval-request"),
|
|
2696
2696
|
approvalId: z.string(),
|
|
2697
2697
|
toolCallId: z.string(),
|
|
2698
|
-
reason: z.string().optional()
|
|
2698
|
+
reason: z.string().optional(),
|
|
2699
|
+
isAutomatic: z.boolean().optional(),
|
|
2700
|
+
signature: z.string().optional(),
|
|
2701
|
+
inputSchemaInput: z.unknown().optional()
|
|
2699
2702
|
}
|
|
2700
2703
|
);
|
|
2701
2704
|
var toolApprovalResponseSchema = z.object({
|
|
@@ -3180,8 +3183,8 @@ var DefaultGeneratedFile = class {
|
|
|
3180
3183
|
}
|
|
3181
3184
|
};
|
|
3182
3185
|
var DefaultGeneratedFileWithType = class extends DefaultGeneratedFile {
|
|
3183
|
-
constructor(
|
|
3184
|
-
super(
|
|
3186
|
+
constructor() {
|
|
3187
|
+
super(...arguments);
|
|
3185
3188
|
this.type = "file";
|
|
3186
3189
|
}
|
|
3187
3190
|
};
|
|
@@ -4469,7 +4472,6 @@ function getArrayLengthValidationError({
|
|
|
4469
4472
|
cause: `elements array must contain at most ${maxItems} items`
|
|
4470
4473
|
});
|
|
4471
4474
|
}
|
|
4472
|
-
return void 0;
|
|
4473
4475
|
}
|
|
4474
4476
|
var choice = ({
|
|
4475
4477
|
options: choiceOptions,
|
|
@@ -4600,6 +4602,22 @@ import {
|
|
|
4600
4602
|
safeParseJSON as safeParseJSON3,
|
|
4601
4603
|
safeValidateTypes as safeValidateTypes3
|
|
4602
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
|
|
4603
4621
|
async function parseToolCall({
|
|
4604
4622
|
toolCall,
|
|
4605
4623
|
tools,
|
|
@@ -4721,10 +4739,12 @@ async function refineParsedToolCallInput({
|
|
|
4721
4739
|
if (refine == null) {
|
|
4722
4740
|
return toolCall;
|
|
4723
4741
|
}
|
|
4724
|
-
|
|
4742
|
+
const refinedToolCall = {
|
|
4725
4743
|
...toolCall,
|
|
4726
4744
|
input: await refine(toolCall.input)
|
|
4727
4745
|
};
|
|
4746
|
+
const inputSchemaInput = getToolCallInputSchemaInput(toolCall);
|
|
4747
|
+
return inputSchemaInput == null ? refinedToolCall : setToolCallInputSchemaInput(refinedToolCall, inputSchemaInput.value);
|
|
4728
4748
|
}
|
|
4729
4749
|
async function parseProviderExecutedDynamicToolCall(toolCall) {
|
|
4730
4750
|
const parseResult = toolCall.input.trim() === "" ? { success: true, value: {} } : await safeParseJSON3({ text: toolCall.input });
|
|
@@ -4769,26 +4789,29 @@ async function doParseToolCall({
|
|
|
4769
4789
|
cause: parseResult.error
|
|
4770
4790
|
});
|
|
4771
4791
|
}
|
|
4772
|
-
return
|
|
4773
|
-
type
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
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
|
+
);
|
|
4792
4815
|
}
|
|
4793
4816
|
|
|
4794
4817
|
// src/generate-text/prepare-step-call-settings.ts
|
|
@@ -5527,6 +5550,33 @@ function sumTokenCounts(tokenCount1, tokenCount2) {
|
|
|
5527
5550
|
return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 != null ? tokenCount1 : 0) + (tokenCount2 != null ? tokenCount2 : 0);
|
|
5528
5551
|
}
|
|
5529
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
|
+
|
|
5530
5580
|
// src/generate-text/to-response-messages.ts
|
|
5531
5581
|
async function toResponseMessages({
|
|
5532
5582
|
content: inputContent,
|
|
@@ -5631,13 +5681,15 @@ async function toResponseMessages({
|
|
|
5631
5681
|
break;
|
|
5632
5682
|
}
|
|
5633
5683
|
case "tool-approval-request":
|
|
5684
|
+
const inputSchemaInput = getToolCallInputSchemaInput(part.toolCall);
|
|
5634
5685
|
content.push({
|
|
5635
5686
|
type: "tool-approval-request",
|
|
5636
5687
|
approvalId: part.approvalId,
|
|
5637
5688
|
toolCallId: part.toolCall.toolCallId,
|
|
5638
5689
|
...part.reason != null ? { reason: part.reason } : {},
|
|
5639
5690
|
isAutomatic: part.isAutomatic,
|
|
5640
|
-
...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 } : {}
|
|
5641
5693
|
});
|
|
5642
5694
|
break;
|
|
5643
5695
|
}
|
|
@@ -5857,14 +5909,15 @@ async function validateApprovedToolApprovals({
|
|
|
5857
5909
|
messages,
|
|
5858
5910
|
toolsContext,
|
|
5859
5911
|
runtimeContext,
|
|
5860
|
-
toolApprovalSecret
|
|
5912
|
+
toolApprovalSecret,
|
|
5913
|
+
refineToolInput
|
|
5861
5914
|
}) {
|
|
5862
5915
|
var _a25;
|
|
5863
5916
|
const approved = [];
|
|
5864
5917
|
const denied = [];
|
|
5865
5918
|
const invalid = [];
|
|
5866
5919
|
for (const approval of approvedToolApprovals) {
|
|
5867
|
-
const {
|
|
5920
|
+
const { approvalRequest, toolCall } = approval;
|
|
5868
5921
|
const tool3 = getOwn(tools, toolCall.toolName);
|
|
5869
5922
|
if (toolApprovalSecret != null) {
|
|
5870
5923
|
if (approvalRequest.signature == null) {
|
|
@@ -5891,17 +5944,42 @@ async function validateApprovedToolApprovals({
|
|
|
5891
5944
|
}
|
|
5892
5945
|
}
|
|
5893
5946
|
if (isExecutableTool2(tool3) && tool3.inputSchema != null) {
|
|
5947
|
+
const hasInputSchemaInput = Object.prototype.hasOwnProperty.call(
|
|
5948
|
+
approvalRequest,
|
|
5949
|
+
"inputSchemaInput"
|
|
5950
|
+
);
|
|
5894
5951
|
const validation = await safeValidateTypes4({
|
|
5895
|
-
value: toolCall.input,
|
|
5952
|
+
value: hasInputSchemaInput ? approvalRequest.inputSchemaInput : toolCall.input,
|
|
5896
5953
|
schema: asSchema4(tool3.inputSchema)
|
|
5897
5954
|
});
|
|
5955
|
+
let validationError;
|
|
5898
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) {
|
|
5899
5977
|
invalid.push({
|
|
5900
5978
|
...approval,
|
|
5901
5979
|
error: new InvalidToolInputError({
|
|
5902
5980
|
toolName: toolCall.toolName,
|
|
5903
5981
|
toolInput: JSON.stringify(toolCall.input),
|
|
5904
|
-
cause:
|
|
5982
|
+
cause: validationError
|
|
5905
5983
|
})
|
|
5906
5984
|
});
|
|
5907
5985
|
continue;
|
|
@@ -6130,7 +6208,8 @@ async function generateText({
|
|
|
6130
6208
|
messages: initialMessages,
|
|
6131
6209
|
toolsContext,
|
|
6132
6210
|
runtimeContext,
|
|
6133
|
-
toolApprovalSecret: experimental_toolApprovalSecret
|
|
6211
|
+
toolApprovalSecret: experimental_toolApprovalSecret,
|
|
6212
|
+
refineToolInput
|
|
6134
6213
|
});
|
|
6135
6214
|
const deniedToolApprovals = [
|
|
6136
6215
|
...collectedDeniedToolApprovals,
|
|
@@ -7038,8 +7117,6 @@ function writeToServerResponse({
|
|
|
7038
7117
|
});
|
|
7039
7118
|
}
|
|
7040
7119
|
}
|
|
7041
|
-
} catch (error) {
|
|
7042
|
-
throw error;
|
|
7043
7120
|
} finally {
|
|
7044
7121
|
response.end();
|
|
7045
7122
|
}
|
|
@@ -7239,6 +7316,7 @@ var uiMessageChunkSchema = lazySchema(
|
|
|
7239
7316
|
approvalId: z.string(),
|
|
7240
7317
|
toolCallId: z.string(),
|
|
7241
7318
|
approvalDescriptor: z.unknown().optional(),
|
|
7319
|
+
inputSchemaInput: z.unknown().optional(),
|
|
7242
7320
|
reason: z.string().optional(),
|
|
7243
7321
|
isAutomatic: z.boolean().optional(),
|
|
7244
7322
|
signature: z.string().optional()
|
|
@@ -7899,6 +7977,10 @@ function processUIMessageStream({
|
|
|
7899
7977
|
toolInvocation.approval = {
|
|
7900
7978
|
id: chunk.approvalId,
|
|
7901
7979
|
...chunk.approvalDescriptor != null ? { descriptor: chunk.approvalDescriptor } : {},
|
|
7980
|
+
...Object.prototype.hasOwnProperty.call(
|
|
7981
|
+
chunk,
|
|
7982
|
+
"inputSchemaInput"
|
|
7983
|
+
) ? { inputSchemaInput: chunk.inputSchemaInput } : {},
|
|
7902
7984
|
...chunk.reason != null ? { requestReason: chunk.reason } : {},
|
|
7903
7985
|
...chunk.isAutomatic === true ? { isAutomatic: true } : {},
|
|
7904
7986
|
...chunk.signature != null ? { signature: chunk.signature } : {}
|
|
@@ -8394,10 +8476,12 @@ function toUIMessageChunk(part, {
|
|
|
8394
8476
|
};
|
|
8395
8477
|
}
|
|
8396
8478
|
case "tool-approval-request": {
|
|
8479
|
+
const inputSchemaInput = getToolCallInputSchemaInput(part.toolCall);
|
|
8397
8480
|
return {
|
|
8398
8481
|
type: "tool-approval-request",
|
|
8399
8482
|
approvalId: part.approvalId,
|
|
8400
8483
|
toolCallId: part.toolCall.toolCallId,
|
|
8484
|
+
...inputSchemaInput != null && !isDeepEqualData(inputSchemaInput.value, part.toolCall.input) ? { inputSchemaInput: inputSchemaInput.value } : {},
|
|
8401
8485
|
...part.reason != null ? { reason: part.reason } : {},
|
|
8402
8486
|
...part.isAutomatic != null ? { isAutomatic: part.isAutomatic } : {},
|
|
8403
8487
|
...part.signature != null ? { signature: part.signature } : {}
|
|
@@ -9013,7 +9097,6 @@ function executeToolsFromStream({
|
|
|
9013
9097
|
}
|
|
9014
9098
|
})
|
|
9015
9099
|
);
|
|
9016
|
-
return;
|
|
9017
9100
|
}
|
|
9018
9101
|
}
|
|
9019
9102
|
}
|
|
@@ -9036,24 +9119,25 @@ function invokeToolCallbacksFromStream({
|
|
|
9036
9119
|
toolName
|
|
9037
9120
|
}) => {
|
|
9038
9121
|
const ongoingToolCall = ongoingToolCalls[toolCallId];
|
|
9039
|
-
|
|
9040
|
-
|
|
9122
|
+
const validatedContext = ongoingToolCall == null ? void 0 : ongoingToolCall.validatedContexts[toolName];
|
|
9123
|
+
if (validatedContext != null) {
|
|
9124
|
+
return validatedContext;
|
|
9041
9125
|
}
|
|
9042
9126
|
const tool3 = getOwn(tools, toolName);
|
|
9043
|
-
const
|
|
9127
|
+
const newValidatedContext = validateToolContext({
|
|
9044
9128
|
toolName,
|
|
9045
9129
|
context: getOwn(toolsContext, toolName),
|
|
9046
9130
|
contextSchema: tool3 == null ? void 0 : tool3.contextSchema
|
|
9047
9131
|
});
|
|
9048
9132
|
if (ongoingToolCall != null) {
|
|
9049
|
-
ongoingToolCall.
|
|
9133
|
+
ongoingToolCall.validatedContexts[toolName] = newValidatedContext;
|
|
9050
9134
|
}
|
|
9051
|
-
return
|
|
9135
|
+
return newValidatedContext;
|
|
9052
9136
|
};
|
|
9053
9137
|
return stream.pipeThrough(
|
|
9054
9138
|
new TransformStream({
|
|
9055
9139
|
async transform(chunk, controller) {
|
|
9056
|
-
var _a25
|
|
9140
|
+
var _a25;
|
|
9057
9141
|
controller.enqueue(chunk);
|
|
9058
9142
|
if (isStreamRetryAttemptBoundaryPart(chunk)) {
|
|
9059
9143
|
ongoingToolCalls = createIdMap();
|
|
@@ -9063,7 +9147,7 @@ function invokeToolCallbacksFromStream({
|
|
|
9063
9147
|
case "tool-input-start": {
|
|
9064
9148
|
ongoingToolCalls[chunk.id] = {
|
|
9065
9149
|
toolName: chunk.toolName,
|
|
9066
|
-
|
|
9150
|
+
validatedContexts: createIdMap()
|
|
9067
9151
|
};
|
|
9068
9152
|
const tool3 = getOwn(tools, chunk.toolName);
|
|
9069
9153
|
if ((tool3 == null ? void 0 : tool3.onInputStart) != null) {
|
|
@@ -9097,7 +9181,7 @@ function invokeToolCallbacksFromStream({
|
|
|
9097
9181
|
break;
|
|
9098
9182
|
}
|
|
9099
9183
|
case "tool-call": {
|
|
9100
|
-
const toolName =
|
|
9184
|
+
const toolName = chunk.toolName;
|
|
9101
9185
|
const tool3 = getOwn(tools, toolName);
|
|
9102
9186
|
if (!chunk.invalid && (tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
|
|
9103
9187
|
const validatedContext = getValidatedContext({
|
|
@@ -10675,7 +10759,8 @@ var DefaultStreamTextResult = class {
|
|
|
10675
10759
|
messages: initialMessages,
|
|
10676
10760
|
toolsContext,
|
|
10677
10761
|
runtimeContext,
|
|
10678
|
-
toolApprovalSecret: experimental_toolApprovalSecret
|
|
10762
|
+
toolApprovalSecret: experimental_toolApprovalSecret,
|
|
10763
|
+
refineToolInput
|
|
10679
10764
|
});
|
|
10680
10765
|
const localDeniedToolApprovals = [
|
|
10681
10766
|
...deniedToolApprovals.filter(
|
|
@@ -12358,6 +12443,12 @@ async function convertToModelMessages(messages, options) {
|
|
|
12358
12443
|
toolCallId: part.toolCallId,
|
|
12359
12444
|
isAutomatic: part.approval.isAutomatic,
|
|
12360
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
|
+
} : {},
|
|
12361
12452
|
...part.approval.signature != null ? { signature: part.approval.signature } : {}
|
|
12362
12453
|
});
|
|
12363
12454
|
}
|
|
@@ -12523,8 +12614,31 @@ function asDynamicToolPart(toolPart) {
|
|
|
12523
12614
|
toolName: type.slice(5)
|
|
12524
12615
|
};
|
|
12525
12616
|
}
|
|
12526
|
-
|
|
12527
|
-
()
|
|
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(
|
|
12528
12642
|
z.array(
|
|
12529
12643
|
z.object({
|
|
12530
12644
|
id: z.string(),
|
|
@@ -12627,15 +12741,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12627
12741
|
output: z.never().optional(),
|
|
12628
12742
|
errorText: z.never().optional(),
|
|
12629
12743
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12630
|
-
approval:
|
|
12631
|
-
id: z.string(),
|
|
12632
|
-
approved: z.never().optional(),
|
|
12633
|
-
descriptor: z.unknown().optional(),
|
|
12634
|
-
requestReason: z.string().optional(),
|
|
12635
|
-
reason: z.never().optional(),
|
|
12636
|
-
isAutomatic: z.boolean().optional(),
|
|
12637
|
-
signature: z.string().optional()
|
|
12638
|
-
})
|
|
12744
|
+
approval: approvalRequestedSchema
|
|
12639
12745
|
}),
|
|
12640
12746
|
z.object({
|
|
12641
12747
|
type: z.literal("dynamic-tool"),
|
|
@@ -12649,15 +12755,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12649
12755
|
output: z.never().optional(),
|
|
12650
12756
|
errorText: z.never().optional(),
|
|
12651
12757
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12652
|
-
approval:
|
|
12653
|
-
id: z.string(),
|
|
12654
|
-
approved: z.boolean(),
|
|
12655
|
-
descriptor: z.unknown().optional(),
|
|
12656
|
-
requestReason: z.string().optional(),
|
|
12657
|
-
reason: z.string().optional(),
|
|
12658
|
-
isAutomatic: z.boolean().optional(),
|
|
12659
|
-
signature: z.string().optional()
|
|
12660
|
-
})
|
|
12758
|
+
approval: approvalRespondedSchema
|
|
12661
12759
|
}),
|
|
12662
12760
|
z.object({
|
|
12663
12761
|
type: z.literal("dynamic-tool"),
|
|
@@ -12673,15 +12771,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12673
12771
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12674
12772
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
12675
12773
|
preliminary: z.boolean().optional(),
|
|
12676
|
-
approval:
|
|
12677
|
-
id: z.string(),
|
|
12678
|
-
approved: z.literal(true),
|
|
12679
|
-
descriptor: z.unknown().optional(),
|
|
12680
|
-
requestReason: z.string().optional(),
|
|
12681
|
-
reason: z.string().optional(),
|
|
12682
|
-
isAutomatic: z.boolean().optional(),
|
|
12683
|
-
signature: z.string().optional()
|
|
12684
|
-
}).optional()
|
|
12774
|
+
approval: approvalGrantedSchema.optional()
|
|
12685
12775
|
}),
|
|
12686
12776
|
z.object({
|
|
12687
12777
|
type: z.literal("dynamic-tool"),
|
|
@@ -12697,15 +12787,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12697
12787
|
errorText: z.string(),
|
|
12698
12788
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12699
12789
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
12700
|
-
approval:
|
|
12701
|
-
id: z.string(),
|
|
12702
|
-
approved: z.literal(true),
|
|
12703
|
-
descriptor: z.unknown().optional(),
|
|
12704
|
-
requestReason: z.string().optional(),
|
|
12705
|
-
reason: z.string().optional(),
|
|
12706
|
-
isAutomatic: z.boolean().optional(),
|
|
12707
|
-
signature: z.string().optional()
|
|
12708
|
-
}).optional()
|
|
12790
|
+
approval: approvalGrantedSchema.optional()
|
|
12709
12791
|
}),
|
|
12710
12792
|
z.object({
|
|
12711
12793
|
type: z.literal("dynamic-tool"),
|
|
@@ -12719,15 +12801,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12719
12801
|
output: z.never().optional(),
|
|
12720
12802
|
errorText: z.never().optional(),
|
|
12721
12803
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12722
|
-
approval:
|
|
12723
|
-
id: z.string(),
|
|
12724
|
-
approved: z.literal(false),
|
|
12725
|
-
descriptor: z.unknown().optional(),
|
|
12726
|
-
requestReason: z.string().optional(),
|
|
12727
|
-
reason: z.string().optional(),
|
|
12728
|
-
isAutomatic: z.boolean().optional(),
|
|
12729
|
-
signature: z.string().optional()
|
|
12730
|
-
})
|
|
12804
|
+
approval: approvalDeniedSchema
|
|
12731
12805
|
}),
|
|
12732
12806
|
z.object({
|
|
12733
12807
|
type: z.string().startsWith("tool-"),
|
|
@@ -12766,15 +12840,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12766
12840
|
output: z.never().optional(),
|
|
12767
12841
|
errorText: z.never().optional(),
|
|
12768
12842
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12769
|
-
approval:
|
|
12770
|
-
id: z.string(),
|
|
12771
|
-
approved: z.never().optional(),
|
|
12772
|
-
descriptor: z.unknown().optional(),
|
|
12773
|
-
requestReason: z.string().optional(),
|
|
12774
|
-
reason: z.never().optional(),
|
|
12775
|
-
isAutomatic: z.boolean().optional(),
|
|
12776
|
-
signature: z.string().optional()
|
|
12777
|
-
})
|
|
12843
|
+
approval: approvalRequestedSchema
|
|
12778
12844
|
}),
|
|
12779
12845
|
z.object({
|
|
12780
12846
|
type: z.string().startsWith("tool-"),
|
|
@@ -12787,15 +12853,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12787
12853
|
output: z.never().optional(),
|
|
12788
12854
|
errorText: z.never().optional(),
|
|
12789
12855
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12790
|
-
approval:
|
|
12791
|
-
id: z.string(),
|
|
12792
|
-
approved: z.boolean(),
|
|
12793
|
-
descriptor: z.unknown().optional(),
|
|
12794
|
-
requestReason: z.string().optional(),
|
|
12795
|
-
reason: z.string().optional(),
|
|
12796
|
-
isAutomatic: z.boolean().optional(),
|
|
12797
|
-
signature: z.string().optional()
|
|
12798
|
-
})
|
|
12856
|
+
approval: approvalRespondedSchema
|
|
12799
12857
|
}),
|
|
12800
12858
|
z.object({
|
|
12801
12859
|
type: z.string().startsWith("tool-"),
|
|
@@ -12810,15 +12868,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12810
12868
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12811
12869
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
12812
12870
|
preliminary: z.boolean().optional(),
|
|
12813
|
-
approval:
|
|
12814
|
-
id: z.string(),
|
|
12815
|
-
approved: z.literal(true),
|
|
12816
|
-
descriptor: z.unknown().optional(),
|
|
12817
|
-
requestReason: z.string().optional(),
|
|
12818
|
-
reason: z.string().optional(),
|
|
12819
|
-
isAutomatic: z.boolean().optional(),
|
|
12820
|
-
signature: z.string().optional()
|
|
12821
|
-
}).optional()
|
|
12871
|
+
approval: approvalGrantedSchema.optional()
|
|
12822
12872
|
}),
|
|
12823
12873
|
z.object({
|
|
12824
12874
|
type: z.string().startsWith("tool-"),
|
|
@@ -12833,15 +12883,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12833
12883
|
errorText: z.string(),
|
|
12834
12884
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12835
12885
|
resultProviderMetadata: providerMetadataSchema.optional(),
|
|
12836
|
-
approval:
|
|
12837
|
-
id: z.string(),
|
|
12838
|
-
approved: z.literal(true),
|
|
12839
|
-
descriptor: z.unknown().optional(),
|
|
12840
|
-
requestReason: z.string().optional(),
|
|
12841
|
-
reason: z.string().optional(),
|
|
12842
|
-
isAutomatic: z.boolean().optional(),
|
|
12843
|
-
signature: z.string().optional()
|
|
12844
|
-
}).optional()
|
|
12886
|
+
approval: approvalGrantedSchema.optional()
|
|
12845
12887
|
}),
|
|
12846
12888
|
z.object({
|
|
12847
12889
|
type: z.string().startsWith("tool-"),
|
|
@@ -12854,15 +12896,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12854
12896
|
output: z.never().optional(),
|
|
12855
12897
|
errorText: z.never().optional(),
|
|
12856
12898
|
callProviderMetadata: providerMetadataSchema.optional(),
|
|
12857
|
-
approval:
|
|
12858
|
-
id: z.string(),
|
|
12859
|
-
approved: z.literal(false),
|
|
12860
|
-
descriptor: z.unknown().optional(),
|
|
12861
|
-
requestReason: z.string().optional(),
|
|
12862
|
-
reason: z.string().optional(),
|
|
12863
|
-
isAutomatic: z.boolean().optional(),
|
|
12864
|
-
signature: z.string().optional()
|
|
12865
|
-
})
|
|
12899
|
+
approval: approvalDeniedSchema
|
|
12866
12900
|
})
|
|
12867
12901
|
])
|
|
12868
12902
|
)
|
|
@@ -12880,13 +12914,14 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12880
12914
|
}
|
|
12881
12915
|
})
|
|
12882
12916
|
).nonempty("Messages array must not be empty")
|
|
12883
|
-
)
|
|
12884
|
-
);
|
|
12917
|
+
);
|
|
12918
|
+
});
|
|
12885
12919
|
async function safeValidateUIMessagesInternal({
|
|
12886
12920
|
messages,
|
|
12887
12921
|
metadataSchema,
|
|
12888
12922
|
dataSchemas,
|
|
12889
|
-
tools
|
|
12923
|
+
tools,
|
|
12924
|
+
experimental_refineToolInput
|
|
12890
12925
|
}, {
|
|
12891
12926
|
convertMissingTerminalToolsToDynamic
|
|
12892
12927
|
}) {
|
|
@@ -12982,35 +13017,44 @@ async function safeValidateUIMessagesInternal({
|
|
|
12982
13017
|
entityName: toolName,
|
|
12983
13018
|
entityId: toolPart.toolCallId
|
|
12984
13019
|
};
|
|
13020
|
+
const inputSchemaInput = getToolPartInputSchemaInput(toolPart);
|
|
13021
|
+
const inputToValidate = inputSchemaInput == null ? toolPart.input : inputSchemaInput.value;
|
|
12985
13022
|
let convertToDynamic = false;
|
|
12986
|
-
if (toolPart.state
|
|
12987
|
-
if (toolPart.input !== void 0) {
|
|
12988
|
-
const result = await safeValidateTypes5({
|
|
12989
|
-
value: toolPart.input,
|
|
12990
|
-
schema: tool3.inputSchema,
|
|
12991
|
-
context: inputValidationContext
|
|
12992
|
-
});
|
|
12993
|
-
convertToDynamic = !result.success;
|
|
12994
|
-
}
|
|
12995
|
-
} else if (toolPart.state === "output-available") {
|
|
13023
|
+
if (toolPart.state !== "input-streaming" && (toolPart.state !== "output-error" || inputSchemaInput != null || toolPart.input !== void 0)) {
|
|
12996
13024
|
const result = await safeValidateTypes5({
|
|
12997
|
-
value:
|
|
13025
|
+
value: inputToValidate,
|
|
12998
13026
|
schema: tool3.inputSchema,
|
|
12999
13027
|
context: inputValidationContext
|
|
13000
13028
|
});
|
|
13029
|
+
let inputError;
|
|
13001
13030
|
if (!result.success) {
|
|
13002
|
-
|
|
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)) {
|
|
13003
13053
|
convertToDynamic = true;
|
|
13004
13054
|
} else {
|
|
13005
|
-
throw
|
|
13055
|
+
throw inputError;
|
|
13006
13056
|
}
|
|
13007
13057
|
}
|
|
13008
|
-
} else if (toolPart.state === "input-available" || toolPart.state === "approval-requested" || toolPart.state === "approval-responded" || toolPart.state === "output-denied") {
|
|
13009
|
-
await validateTypes4({
|
|
13010
|
-
value: toolPart.input,
|
|
13011
|
-
schema: tool3.inputSchema,
|
|
13012
|
-
context: inputValidationContext
|
|
13013
|
-
});
|
|
13014
13058
|
}
|
|
13015
13059
|
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
|
13016
13060
|
await validateTypes4({
|
|
@@ -13465,33 +13509,6 @@ function toImageModelV4File(dataContent) {
|
|
|
13465
13509
|
};
|
|
13466
13510
|
}
|
|
13467
13511
|
|
|
13468
|
-
// src/util/is-deep-equal-data.ts
|
|
13469
|
-
function isDeepEqualData(obj1, obj2) {
|
|
13470
|
-
if (obj1 === obj2) return true;
|
|
13471
|
-
if (obj1 == null || obj2 == null) return false;
|
|
13472
|
-
if (typeof obj1 !== "object" && typeof obj2 !== "object")
|
|
13473
|
-
return obj1 === obj2;
|
|
13474
|
-
if (obj1.constructor !== obj2.constructor) return false;
|
|
13475
|
-
if (obj1 instanceof Date && obj2 instanceof Date) {
|
|
13476
|
-
return obj1.getTime() === obj2.getTime();
|
|
13477
|
-
}
|
|
13478
|
-
if (Array.isArray(obj1)) {
|
|
13479
|
-
if (obj1.length !== obj2.length) return false;
|
|
13480
|
-
for (let i = 0; i < obj1.length; i++) {
|
|
13481
|
-
if (!isDeepEqualData(obj1[i], obj2[i])) return false;
|
|
13482
|
-
}
|
|
13483
|
-
return true;
|
|
13484
|
-
}
|
|
13485
|
-
const keys1 = Object.keys(obj1);
|
|
13486
|
-
const keys2 = Object.keys(obj2);
|
|
13487
|
-
if (keys1.length !== keys2.length) return false;
|
|
13488
|
-
for (const key of keys1) {
|
|
13489
|
-
if (!keys2.includes(key)) return false;
|
|
13490
|
-
if (!isDeepEqualData(obj1[key], obj2[key])) return false;
|
|
13491
|
-
}
|
|
13492
|
-
return true;
|
|
13493
|
-
}
|
|
13494
|
-
|
|
13495
13512
|
// src/batch/batch.ts
|
|
13496
13513
|
async function cancelBatch({
|
|
13497
13514
|
provider,
|
|
@@ -14213,6 +14230,14 @@ function getEmbeddingModelMaxInputBytesPerCall(model) {
|
|
|
14213
14230
|
return model[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL];
|
|
14214
14231
|
}
|
|
14215
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
|
+
|
|
14216
14241
|
// src/util/split-array.ts
|
|
14217
14242
|
function splitArray(array3, chunkSize) {
|
|
14218
14243
|
if (chunkSize <= 0) {
|
|
@@ -14283,7 +14308,7 @@ async function embedMany({
|
|
|
14283
14308
|
type: "embedMany",
|
|
14284
14309
|
event: startEvent,
|
|
14285
14310
|
execute: async () => {
|
|
14286
|
-
var _a26
|
|
14311
|
+
var _a26;
|
|
14287
14312
|
await notify({
|
|
14288
14313
|
event: startEvent,
|
|
14289
14314
|
callbacks: [resolvedOnStart, telemetryDispatcher.onStart]
|
|
@@ -14302,7 +14327,7 @@ async function embedMany({
|
|
|
14302
14327
|
const hasInputByteLimit = maxInputBytesPerCall != null && maxInputBytesPerCall !== Infinity;
|
|
14303
14328
|
if (!hasEmbeddingLimit && !hasInputByteLimit) {
|
|
14304
14329
|
const { embeddings: embeddings2, usage, warnings: warnings2, response, providerMetadata: providerMetadata2 } = await retry(async () => {
|
|
14305
|
-
var _a27,
|
|
14330
|
+
var _a27, _b25;
|
|
14306
14331
|
const embedCallId = generateCallId();
|
|
14307
14332
|
await notify({
|
|
14308
14333
|
event: {
|
|
@@ -14339,7 +14364,7 @@ async function embedMany({
|
|
|
14339
14364
|
return {
|
|
14340
14365
|
embeddings: embeddings3,
|
|
14341
14366
|
usage: usage2,
|
|
14342
|
-
warnings: (
|
|
14367
|
+
warnings: (_b25 = modelResponse.warnings) != null ? _b25 : [],
|
|
14343
14368
|
providerMetadata: modelResponse.providerMetadata,
|
|
14344
14369
|
response: modelResponse.response
|
|
14345
14370
|
};
|
|
@@ -14380,6 +14405,7 @@ async function embedMany({
|
|
|
14380
14405
|
maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
|
|
14381
14406
|
maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
|
|
14382
14407
|
});
|
|
14408
|
+
const providerOptionsTransformer = getEmbeddingModelProviderOptionsTransformer(model);
|
|
14383
14409
|
const embeddings = [];
|
|
14384
14410
|
const warnings = [];
|
|
14385
14411
|
const responses = [];
|
|
@@ -14389,11 +14415,20 @@ async function embedMany({
|
|
|
14389
14415
|
valueChunks,
|
|
14390
14416
|
supportsParallelCalls ? maxParallelCalls : 1
|
|
14391
14417
|
);
|
|
14418
|
+
let nextChunkStartIndex = 0;
|
|
14392
14419
|
for (const parallelChunk of parallelChunks) {
|
|
14393
14420
|
const results = await Promise.all(
|
|
14394
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;
|
|
14395
14430
|
const result = await retry(async () => {
|
|
14396
|
-
var _a27,
|
|
14431
|
+
var _a27, _b25;
|
|
14397
14432
|
const embedCallId = generateCallId();
|
|
14398
14433
|
await notify({
|
|
14399
14434
|
event: {
|
|
@@ -14410,7 +14445,7 @@ async function embedMany({
|
|
|
14410
14445
|
values: chunk,
|
|
14411
14446
|
abortSignal,
|
|
14412
14447
|
headers: headersWithUserAgent,
|
|
14413
|
-
providerOptions
|
|
14448
|
+
providerOptions: chunkProviderOptions
|
|
14414
14449
|
});
|
|
14415
14450
|
const chunkEmbeddings = modelResponse.embeddings;
|
|
14416
14451
|
const usage = (_a27 = modelResponse.usage) != null ? _a27 : { tokens: NaN };
|
|
@@ -14430,7 +14465,7 @@ async function embedMany({
|
|
|
14430
14465
|
return {
|
|
14431
14466
|
embeddings: chunkEmbeddings,
|
|
14432
14467
|
usage,
|
|
14433
|
-
warnings: (
|
|
14468
|
+
warnings: (_b25 = modelResponse.warnings) != null ? _b25 : [],
|
|
14434
14469
|
providerMetadata: modelResponse.providerMetadata,
|
|
14435
14470
|
response: modelResponse.response
|
|
14436
14471
|
};
|
|
@@ -14455,7 +14490,7 @@ async function embedMany({
|
|
|
14455
14490
|
result.providerMetadata
|
|
14456
14491
|
)) {
|
|
14457
14492
|
providerMetadata[providerName] = {
|
|
14458
|
-
...
|
|
14493
|
+
...providerMetadata[providerName],
|
|
14459
14494
|
...metadata
|
|
14460
14495
|
};
|
|
14461
14496
|
}
|
|
@@ -14493,7 +14528,7 @@ async function embedMany({
|
|
|
14493
14528
|
responses
|
|
14494
14529
|
});
|
|
14495
14530
|
} catch (error) {
|
|
14496
|
-
await ((
|
|
14531
|
+
await ((_a26 = telemetryDispatcher.onError) == null ? void 0 : _a26.call(telemetryDispatcher, { callId, error }));
|
|
14497
14532
|
throw error;
|
|
14498
14533
|
}
|
|
14499
14534
|
}
|
|
@@ -16483,7 +16518,21 @@ function getOutputFormatMediaType(outputFormat) {
|
|
|
16483
16518
|
return void 0;
|
|
16484
16519
|
}
|
|
16485
16520
|
const normalizedOutputFormat = outputFormat.trim().toLowerCase();
|
|
16486
|
-
|
|
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
|
+
}
|
|
16487
16536
|
}
|
|
16488
16537
|
var DefaultSpeechResult = class {
|
|
16489
16538
|
constructor(options) {
|
|
@@ -17215,7 +17264,6 @@ function normalizeImageData(dataContent, { restrictToImages = true } = {}) {
|
|
|
17215
17264
|
data: bytes
|
|
17216
17265
|
};
|
|
17217
17266
|
}
|
|
17218
|
-
return void 0;
|
|
17219
17267
|
}
|
|
17220
17268
|
function normalizeReferenceData(reference) {
|
|
17221
17269
|
const isObjectForm = typeof reference === "object" && reference != null && !(reference instanceof Uint8Array) && !(reference instanceof ArrayBuffer) && "data" in reference;
|
|
@@ -17915,7 +17963,8 @@ var doWrap = ({
|
|
|
17915
17963
|
// src/middleware/wrap-embedding-model.ts
|
|
17916
17964
|
import {
|
|
17917
17965
|
asArray as asArray9,
|
|
17918
|
-
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
|
|
17919
17968
|
} from "@ai-sdk/provider-utils";
|
|
17920
17969
|
var wrapEmbeddingModel = ({
|
|
17921
17970
|
model: inputModel,
|
|
@@ -17953,6 +18002,7 @@ var doWrap2 = ({
|
|
|
17953
18002
|
modelId: (_b25 = modelId != null ? modelId : overrideModelId == null ? void 0 : overrideModelId({ model })) != null ? _b25 : model.modelId,
|
|
17954
18003
|
maxEmbeddingsPerCall: (_c = overrideMaxEmbeddingsPerCall == null ? void 0 : overrideMaxEmbeddingsPerCall({ model })) != null ? _c : model.maxEmbeddingsPerCall,
|
|
17955
18004
|
[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL2]: getEmbeddingModelMaxInputBytesPerCall(model),
|
|
18005
|
+
[EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER2]: getEmbeddingModelProviderOptionsTransformer(model),
|
|
17956
18006
|
supportsParallelCalls: (_d = overrideSupportsParallelCalls == null ? void 0 : overrideSupportsParallelCalls({ model })) != null ? _d : model.supportsParallelCalls,
|
|
17957
18007
|
async doEmbed(params) {
|
|
17958
18008
|
const transformedParams = await doTransform({ params });
|
|
@@ -20795,9 +20845,9 @@ function customProvider({
|
|
|
20795
20845
|
if (videoModels != null && modelId in videoModels) {
|
|
20796
20846
|
return resolveVideoModel(videoModels[modelId]);
|
|
20797
20847
|
}
|
|
20798
|
-
const
|
|
20799
|
-
if (videoModel) {
|
|
20800
|
-
return videoModel(modelId);
|
|
20848
|
+
const provider = fallbackProviderArg;
|
|
20849
|
+
if (provider == null ? void 0 : provider.videoModel) {
|
|
20850
|
+
return resolveVideoModel(provider.videoModel(modelId));
|
|
20801
20851
|
}
|
|
20802
20852
|
throw new NoSuchModelError3({ modelId, modelType: "videoModel" });
|
|
20803
20853
|
}
|
|
@@ -22206,9 +22256,24 @@ var AbstractChat = class {
|
|
|
22206
22256
|
this.sendMessage = async (message, options) => {
|
|
22207
22257
|
var _a25, _b25, _c, _d;
|
|
22208
22258
|
if (message == null) {
|
|
22209
|
-
|
|
22210
|
-
|
|
22211
|
-
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,
|
|
22212
22277
|
...options
|
|
22213
22278
|
});
|
|
22214
22279
|
return;
|
|
@@ -22323,16 +22388,24 @@ var AbstractChat = class {
|
|
|
22323
22388
|
options
|
|
22324
22389
|
}) => this.jobExecutor.run(async () => {
|
|
22325
22390
|
const messages = this.state.messages;
|
|
22326
|
-
const lastMessage = messages[messages.length - 1];
|
|
22327
22391
|
const updatePart = (part) => isToolUIPart(part) && part.state === "approval-requested" && part.approval.id === id ? {
|
|
22328
22392
|
...part,
|
|
22329
22393
|
state: "approval-responded",
|
|
22330
22394
|
approval: { ...part.approval, id, approved, reason }
|
|
22331
22395
|
} : part;
|
|
22332
|
-
|
|
22333
|
-
|
|
22334
|
-
|
|
22335
|
-
|
|
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
|
+
}
|
|
22336
22409
|
if (this.activeResponse) {
|
|
22337
22410
|
this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(updatePart);
|
|
22338
22411
|
}
|
|
@@ -22340,9 +22413,10 @@ var AbstractChat = class {
|
|
|
22340
22413
|
this.shouldSendAutomatically().then((shouldSend) => {
|
|
22341
22414
|
var _a25;
|
|
22342
22415
|
if (shouldSend) {
|
|
22343
|
-
this.
|
|
22344
|
-
|
|
22345
|
-
messageId
|
|
22416
|
+
const messageId = messageIndex === -1 ? (_a25 = this.lastMessage) == null ? void 0 : _a25.id : messages[messageIndex].id;
|
|
22417
|
+
this.makeRequestForToolApproval({
|
|
22418
|
+
messageId,
|
|
22419
|
+
messageIndex,
|
|
22346
22420
|
...options
|
|
22347
22421
|
});
|
|
22348
22422
|
}
|
|
@@ -22445,6 +22519,25 @@ var AbstractChat = class {
|
|
|
22445
22519
|
}
|
|
22446
22520
|
return result;
|
|
22447
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
|
+
}
|
|
22448
22541
|
async makeRequest({
|
|
22449
22542
|
trigger,
|
|
22450
22543
|
metadata,
|
|
@@ -22511,6 +22604,9 @@ var AbstractChat = class {
|
|
|
22511
22604
|
}
|
|
22512
22605
|
this.setStatus({ status: "submitted", error: void 0 });
|
|
22513
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";
|
|
22514
22610
|
let isAbort = false;
|
|
22515
22611
|
let isDisconnect = false;
|
|
22516
22612
|
let isError2 = false;
|
|
@@ -22518,7 +22614,7 @@ var AbstractChat = class {
|
|
|
22518
22614
|
try {
|
|
22519
22615
|
const response = {
|
|
22520
22616
|
state: createStreamingUIMessageState({
|
|
22521
|
-
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),
|
|
22522
22618
|
messageId: this.generateId()
|
|
22523
22619
|
}),
|
|
22524
22620
|
abortController
|
|
@@ -22559,8 +22655,12 @@ var AbstractChat = class {
|
|
|
22559
22655
|
if (updateStatus) {
|
|
22560
22656
|
this.setStatus({ status: "streaming" });
|
|
22561
22657
|
}
|
|
22562
|
-
|
|
22563
|
-
|
|
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)) {
|
|
22564
22664
|
this.state.replaceMessage(
|
|
22565
22665
|
this.state.messages.length - 1,
|
|
22566
22666
|
response.state.message
|
|
@@ -22663,6 +22763,7 @@ var DirectChatTransport = class {
|
|
|
22663
22763
|
messages,
|
|
22664
22764
|
abortSignal
|
|
22665
22765
|
}) {
|
|
22766
|
+
var _a25;
|
|
22666
22767
|
const validatedMessages = await validateUIMessagesForAgent({
|
|
22667
22768
|
messages,
|
|
22668
22769
|
// tools are compatible; the casting is required because the context param is
|
|
@@ -22679,6 +22780,7 @@ var DirectChatTransport = class {
|
|
|
22679
22780
|
});
|
|
22680
22781
|
return toUIMessageStream({
|
|
22681
22782
|
...this.uiMessageStreamOptions,
|
|
22783
|
+
originalMessages: (_a25 = this.uiMessageStreamOptions.originalMessages) != null ? _a25 : validatedMessages,
|
|
22682
22784
|
stream: result.stream,
|
|
22683
22785
|
tools: this.agent.tools
|
|
22684
22786
|
});
|