ai 7.0.91 → 7.0.93
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 +27 -0
- package/dist/index.d.ts +178 -159
- package/dist/index.js +143 -25
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +2 -2
- package/dist/internal/index.js.map +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +1 -0
- package/docs/03-agents/04-loop-control.mdx +5 -3
- package/docs/03-agents/07-workflow-agent.mdx +27 -6
- package/docs/03-ai-sdk-core/10-generating-structured-data.mdx +15 -3
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +64 -1
- package/docs/03-ai-sdk-core/35-image-generation.mdx +7 -0
- package/docs/03-ai-sdk-core/36-transcription.mdx +36 -35
- package/docs/03-ai-sdk-harnesses/02-harness-agent.mdx +36 -0
- package/docs/04-ai-sdk-ui/20-streaming-data.mdx +11 -6
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +14 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +30 -3
- package/docs/07-reference/01-ai-sdk-core/28-output.mdx +27 -1
- package/docs/07-reference/01-ai-sdk-core/80-smooth-stream.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/01-use-chat.mdx +1 -1
- package/docs/07-reference/02-ai-sdk-ui/40-create-ui-message-stream.mdx +4 -0
- package/docs/07-reference/02-ai-sdk-ui/41-create-ui-message-stream-response.mdx +6 -1
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +42 -28
- package/docs/07-reference/05-ai-sdk-errors/ai-no-image-generated-error.mdx +7 -0
- package/package.json +6 -6
- package/src/agent/tool-loop-agent-settings.ts +15 -0
- package/src/embed/embed-many.ts +27 -2
- package/src/error/no-image-generated-error.ts +9 -0
- package/src/generate-image/generate-image.ts +1 -1
- package/src/generate-text/generate-text-events.ts +1 -1
- package/src/generate-text/output.ts +111 -1
- package/src/generate-text/smooth-stream.ts +19 -4
- package/src/generate-text/stream-text.ts +2 -6
- package/src/ui/call-completion-api.ts +1 -1
- package/src/ui/chat.ts +1 -1
- package/src/ui/convert-to-model-messages.ts +8 -2
- package/src/ui/http-chat-transport.ts +2 -2
- package/src/ui/validate-ui-messages.ts +14 -0
- package/src/util/async-iterable-stream.ts +1 -1
- package/src/util/data-url.ts +1 -1
- package/src/util/merge-abort-signals.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -222,10 +222,12 @@ var NoImageGeneratedError = class extends (_b8 = AISDKError8, _a8 = symbol8, _b8
|
|
|
222
222
|
constructor({
|
|
223
223
|
message = "No image generated.",
|
|
224
224
|
cause,
|
|
225
|
+
calls,
|
|
225
226
|
responses
|
|
226
227
|
}) {
|
|
227
228
|
super({ name: name8, message, cause });
|
|
228
229
|
this[_a8] = true;
|
|
230
|
+
this.calls = calls;
|
|
229
231
|
this.responses = responses;
|
|
230
232
|
}
|
|
231
233
|
static isInstance(error) {
|
|
@@ -1176,7 +1178,7 @@ import {
|
|
|
1176
1178
|
} from "@ai-sdk/provider-utils";
|
|
1177
1179
|
|
|
1178
1180
|
// src/version.ts
|
|
1179
|
-
var VERSION = true ? "7.0.
|
|
1181
|
+
var VERSION = true ? "7.0.93" : "0.0.0-test";
|
|
1180
1182
|
|
|
1181
1183
|
// src/util/download/download.ts
|
|
1182
1184
|
var download = async ({
|
|
@@ -2749,7 +2751,7 @@ function getOwn(obj, key) {
|
|
|
2749
2751
|
import { filterNullable } from "@ai-sdk/provider-utils";
|
|
2750
2752
|
function mergeAbortSignals(...signals) {
|
|
2751
2753
|
const validSignals = filterNullable(...signals).map(
|
|
2752
|
-
(signal) => signal
|
|
2754
|
+
(signal) => typeof signal === "number" ? AbortSignal.timeout(signal) : signal
|
|
2753
2755
|
);
|
|
2754
2756
|
return validSignals.length === 0 ? void 0 : validSignals.length === 1 ? validSignals[0] : AbortSignal.any(validSignals);
|
|
2755
2757
|
}
|
|
@@ -3780,9 +3782,20 @@ var object2 = ({
|
|
|
3780
3782
|
};
|
|
3781
3783
|
var array2 = ({
|
|
3782
3784
|
element: inputElementSchema,
|
|
3785
|
+
minItems,
|
|
3786
|
+
maxItems,
|
|
3783
3787
|
name: name25,
|
|
3784
3788
|
description
|
|
3785
3789
|
}) => {
|
|
3790
|
+
validateArrayBound({ name: "minItems", value: minItems });
|
|
3791
|
+
validateArrayBound({ name: "maxItems", value: maxItems });
|
|
3792
|
+
if (minItems != null && maxItems != null && minItems > maxItems) {
|
|
3793
|
+
throw new InvalidArgumentError({
|
|
3794
|
+
parameter: "minItems",
|
|
3795
|
+
value: minItems,
|
|
3796
|
+
message: "minItems must be less than or equal to maxItems"
|
|
3797
|
+
});
|
|
3798
|
+
}
|
|
3786
3799
|
const elementSchema = asSchema2(inputElementSchema);
|
|
3787
3800
|
return {
|
|
3788
3801
|
name: "array",
|
|
@@ -3802,7 +3815,12 @@ var array2 = ({
|
|
|
3802
3815
|
...$defs != null && { $defs },
|
|
3803
3816
|
type: "object",
|
|
3804
3817
|
properties: {
|
|
3805
|
-
elements: {
|
|
3818
|
+
elements: {
|
|
3819
|
+
type: "array",
|
|
3820
|
+
items: itemSchema,
|
|
3821
|
+
...minItems != null && { minItems },
|
|
3822
|
+
...maxItems != null && { maxItems }
|
|
3823
|
+
}
|
|
3806
3824
|
},
|
|
3807
3825
|
required: ["elements"],
|
|
3808
3826
|
additionalProperties: false
|
|
@@ -3837,6 +3855,21 @@ var array2 = ({
|
|
|
3837
3855
|
finishReason: context.finishReason
|
|
3838
3856
|
});
|
|
3839
3857
|
}
|
|
3858
|
+
const lengthValidationError = getArrayLengthValidationError({
|
|
3859
|
+
value: outerValue.elements,
|
|
3860
|
+
minItems,
|
|
3861
|
+
maxItems
|
|
3862
|
+
});
|
|
3863
|
+
if (lengthValidationError != null) {
|
|
3864
|
+
throw new NoObjectGeneratedError({
|
|
3865
|
+
message: "No object generated: response did not match schema.",
|
|
3866
|
+
cause: lengthValidationError,
|
|
3867
|
+
text: text2,
|
|
3868
|
+
response: context.response,
|
|
3869
|
+
usage: context.usage,
|
|
3870
|
+
finishReason: context.finishReason
|
|
3871
|
+
});
|
|
3872
|
+
}
|
|
3840
3873
|
const validatedElements = [];
|
|
3841
3874
|
for (const element of outerValue.elements) {
|
|
3842
3875
|
const validationResult = await safeValidateTypes2({
|
|
@@ -3891,6 +3924,15 @@ var array2 = ({
|
|
|
3891
3924
|
transform({ partialOutput }, controller) {
|
|
3892
3925
|
if (partialOutput != null) {
|
|
3893
3926
|
for (; publishedElements < partialOutput.length; publishedElements++) {
|
|
3927
|
+
if (maxItems != null && publishedElements >= maxItems) {
|
|
3928
|
+
controller.error(
|
|
3929
|
+
getArrayLengthValidationError({
|
|
3930
|
+
value: partialOutput,
|
|
3931
|
+
maxItems
|
|
3932
|
+
})
|
|
3933
|
+
);
|
|
3934
|
+
return;
|
|
3935
|
+
}
|
|
3894
3936
|
controller.enqueue(partialOutput[publishedElements]);
|
|
3895
3937
|
}
|
|
3896
3938
|
}
|
|
@@ -3899,6 +3941,47 @@ var array2 = ({
|
|
|
3899
3941
|
}
|
|
3900
3942
|
};
|
|
3901
3943
|
};
|
|
3944
|
+
function validateArrayBound({
|
|
3945
|
+
name: name25,
|
|
3946
|
+
value
|
|
3947
|
+
}) {
|
|
3948
|
+
if (value == null) {
|
|
3949
|
+
return;
|
|
3950
|
+
}
|
|
3951
|
+
if (!Number.isInteger(value)) {
|
|
3952
|
+
throw new InvalidArgumentError({
|
|
3953
|
+
parameter: name25,
|
|
3954
|
+
value,
|
|
3955
|
+
message: `${name25} must be an integer`
|
|
3956
|
+
});
|
|
3957
|
+
}
|
|
3958
|
+
if (value < 0) {
|
|
3959
|
+
throw new InvalidArgumentError({
|
|
3960
|
+
parameter: name25,
|
|
3961
|
+
value,
|
|
3962
|
+
message: `${name25} must be greater than or equal to 0`
|
|
3963
|
+
});
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3966
|
+
function getArrayLengthValidationError({
|
|
3967
|
+
value,
|
|
3968
|
+
minItems,
|
|
3969
|
+
maxItems
|
|
3970
|
+
}) {
|
|
3971
|
+
if (minItems != null && value.length < minItems) {
|
|
3972
|
+
return new TypeValidationError2({
|
|
3973
|
+
value,
|
|
3974
|
+
cause: `elements array must contain at least ${minItems} items`
|
|
3975
|
+
});
|
|
3976
|
+
}
|
|
3977
|
+
if (maxItems != null && value.length > maxItems) {
|
|
3978
|
+
return new TypeValidationError2({
|
|
3979
|
+
value,
|
|
3980
|
+
cause: `elements array must contain at most ${maxItems} items`
|
|
3981
|
+
});
|
|
3982
|
+
}
|
|
3983
|
+
return void 0;
|
|
3984
|
+
}
|
|
3902
3985
|
var choice = ({
|
|
3903
3986
|
options: choiceOptions,
|
|
3904
3987
|
name: name25,
|
|
@@ -11589,7 +11672,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
11589
11672
|
if (message.parts != null) {
|
|
11590
11673
|
let block = [];
|
|
11591
11674
|
async function processBlock() {
|
|
11592
|
-
var _a25, _b25, _c, _d, _e, _f, _g;
|
|
11675
|
+
var _a25, _b25, _c, _d, _e, _f, _g, _h;
|
|
11593
11676
|
if (block.length === 0) {
|
|
11594
11677
|
return;
|
|
11595
11678
|
}
|
|
@@ -11634,13 +11717,14 @@ async function convertToModelMessages(messages, options) {
|
|
|
11634
11717
|
} else if (isToolUIPart(part)) {
|
|
11635
11718
|
const toolName = getToolName(part);
|
|
11636
11719
|
if (part.state !== "input-streaming") {
|
|
11720
|
+
const callProviderMetadata = (_a25 = part.callProviderMetadata) != null ? _a25 : part.state === "output-error" ? part.resultProviderMetadata : void 0;
|
|
11637
11721
|
content.push({
|
|
11638
11722
|
type: "tool-call",
|
|
11639
11723
|
toolCallId: part.toolCallId,
|
|
11640
11724
|
toolName,
|
|
11641
|
-
input: part.state === "output-error" ? (
|
|
11725
|
+
input: part.state === "output-error" ? (_b25 = part.input) != null ? _b25 : "rawInput" in part ? part.rawInput : void 0 : part.input,
|
|
11642
11726
|
providerExecuted: part.providerExecuted,
|
|
11643
|
-
...
|
|
11727
|
+
...callProviderMetadata != null ? { providerOptions: callProviderMetadata } : {}
|
|
11644
11728
|
});
|
|
11645
11729
|
if (part.approval != null) {
|
|
11646
11730
|
content.push({
|
|
@@ -11653,7 +11737,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
11653
11737
|
});
|
|
11654
11738
|
}
|
|
11655
11739
|
if (part.providerExecuted === true && part.state !== "approval-responded" && (part.state === "output-available" || part.state === "output-error")) {
|
|
11656
|
-
const resultProviderMetadata = (
|
|
11740
|
+
const resultProviderMetadata = (_c = part.resultProviderMetadata) != null ? _c : part.callProviderMetadata;
|
|
11657
11741
|
content.push({
|
|
11658
11742
|
type: "tool-result",
|
|
11659
11743
|
toolCallId: part.toolCallId,
|
|
@@ -11670,7 +11754,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
11670
11754
|
}
|
|
11671
11755
|
}
|
|
11672
11756
|
} else if (isDataUIPart(part)) {
|
|
11673
|
-
const dataPart = (
|
|
11757
|
+
const dataPart = (_d = options == null ? void 0 : options.convertDataPart) == null ? void 0 : _d.call(
|
|
11674
11758
|
options,
|
|
11675
11759
|
part
|
|
11676
11760
|
);
|
|
@@ -11698,7 +11782,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
11698
11782
|
{
|
|
11699
11783
|
const content2 = [];
|
|
11700
11784
|
for (const toolPart of toolParts) {
|
|
11701
|
-
if (((
|
|
11785
|
+
if (((_e = toolPart.approval) == null ? void 0 : _e.approved) != null) {
|
|
11702
11786
|
content2.push({
|
|
11703
11787
|
type: "tool-approval-response",
|
|
11704
11788
|
approvalId: toolPart.approval.id,
|
|
@@ -11707,7 +11791,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
11707
11791
|
providerExecuted: toolPart.providerExecuted
|
|
11708
11792
|
});
|
|
11709
11793
|
}
|
|
11710
|
-
if (toolPart.state === "approval-responded" && ((
|
|
11794
|
+
if (toolPart.state === "approval-responded" && ((_f = toolPart.approval) == null ? void 0 : _f.approved) === false) {
|
|
11711
11795
|
content2.push({
|
|
11712
11796
|
type: "tool-result",
|
|
11713
11797
|
toolCallId: toolPart.toolCallId,
|
|
@@ -11730,7 +11814,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
11730
11814
|
toolName: getToolName(toolPart),
|
|
11731
11815
|
output: {
|
|
11732
11816
|
type: "error-text",
|
|
11733
|
-
value: (
|
|
11817
|
+
value: (_h = (_g = toolPart.approval) == null ? void 0 : _g.reason) != null ? _h : "Tool call execution denied."
|
|
11734
11818
|
},
|
|
11735
11819
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
11736
11820
|
});
|
|
@@ -11882,6 +11966,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
11882
11966
|
type: z.literal("dynamic-tool"),
|
|
11883
11967
|
toolName: z.string(),
|
|
11884
11968
|
toolCallId: z.string(),
|
|
11969
|
+
title: z.string().optional(),
|
|
11885
11970
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
11886
11971
|
state: z.literal("input-streaming"),
|
|
11887
11972
|
input: z.unknown().optional(),
|
|
@@ -11895,6 +11980,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
11895
11980
|
type: z.literal("dynamic-tool"),
|
|
11896
11981
|
toolName: z.string(),
|
|
11897
11982
|
toolCallId: z.string(),
|
|
11983
|
+
title: z.string().optional(),
|
|
11898
11984
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
11899
11985
|
state: z.literal("input-available"),
|
|
11900
11986
|
input: z.unknown(),
|
|
@@ -11908,6 +11994,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
11908
11994
|
type: z.literal("dynamic-tool"),
|
|
11909
11995
|
toolName: z.string(),
|
|
11910
11996
|
toolCallId: z.string(),
|
|
11997
|
+
title: z.string().optional(),
|
|
11911
11998
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
11912
11999
|
state: z.literal("approval-requested"),
|
|
11913
12000
|
input: z.unknown(),
|
|
@@ -11929,6 +12016,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
11929
12016
|
type: z.literal("dynamic-tool"),
|
|
11930
12017
|
toolName: z.string(),
|
|
11931
12018
|
toolCallId: z.string(),
|
|
12019
|
+
title: z.string().optional(),
|
|
11932
12020
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
11933
12021
|
state: z.literal("approval-responded"),
|
|
11934
12022
|
input: z.unknown(),
|
|
@@ -11950,6 +12038,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
11950
12038
|
type: z.literal("dynamic-tool"),
|
|
11951
12039
|
toolName: z.string(),
|
|
11952
12040
|
toolCallId: z.string(),
|
|
12041
|
+
title: z.string().optional(),
|
|
11953
12042
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
11954
12043
|
state: z.literal("output-available"),
|
|
11955
12044
|
input: z.unknown(),
|
|
@@ -11973,6 +12062,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
11973
12062
|
type: z.literal("dynamic-tool"),
|
|
11974
12063
|
toolName: z.string(),
|
|
11975
12064
|
toolCallId: z.string(),
|
|
12065
|
+
title: z.string().optional(),
|
|
11976
12066
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
11977
12067
|
state: z.literal("output-error"),
|
|
11978
12068
|
input: z.unknown().optional(),
|
|
@@ -11996,6 +12086,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
11996
12086
|
type: z.literal("dynamic-tool"),
|
|
11997
12087
|
toolName: z.string(),
|
|
11998
12088
|
toolCallId: z.string(),
|
|
12089
|
+
title: z.string().optional(),
|
|
11999
12090
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
12000
12091
|
state: z.literal("output-denied"),
|
|
12001
12092
|
input: z.unknown(),
|
|
@@ -12016,6 +12107,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12016
12107
|
z.object({
|
|
12017
12108
|
type: z.string().startsWith("tool-"),
|
|
12018
12109
|
toolCallId: z.string(),
|
|
12110
|
+
title: z.string().optional(),
|
|
12019
12111
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
12020
12112
|
state: z.literal("input-streaming"),
|
|
12021
12113
|
providerExecuted: z.boolean().optional(),
|
|
@@ -12028,6 +12120,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12028
12120
|
z.object({
|
|
12029
12121
|
type: z.string().startsWith("tool-"),
|
|
12030
12122
|
toolCallId: z.string(),
|
|
12123
|
+
title: z.string().optional(),
|
|
12031
12124
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
12032
12125
|
state: z.literal("input-available"),
|
|
12033
12126
|
providerExecuted: z.boolean().optional(),
|
|
@@ -12040,6 +12133,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12040
12133
|
z.object({
|
|
12041
12134
|
type: z.string().startsWith("tool-"),
|
|
12042
12135
|
toolCallId: z.string(),
|
|
12136
|
+
title: z.string().optional(),
|
|
12043
12137
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
12044
12138
|
state: z.literal("approval-requested"),
|
|
12045
12139
|
input: z.unknown(),
|
|
@@ -12060,6 +12154,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12060
12154
|
z.object({
|
|
12061
12155
|
type: z.string().startsWith("tool-"),
|
|
12062
12156
|
toolCallId: z.string(),
|
|
12157
|
+
title: z.string().optional(),
|
|
12063
12158
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
12064
12159
|
state: z.literal("approval-responded"),
|
|
12065
12160
|
input: z.unknown(),
|
|
@@ -12080,6 +12175,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12080
12175
|
z.object({
|
|
12081
12176
|
type: z.string().startsWith("tool-"),
|
|
12082
12177
|
toolCallId: z.string(),
|
|
12178
|
+
title: z.string().optional(),
|
|
12083
12179
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
12084
12180
|
state: z.literal("output-available"),
|
|
12085
12181
|
providerExecuted: z.boolean().optional(),
|
|
@@ -12102,6 +12198,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12102
12198
|
z.object({
|
|
12103
12199
|
type: z.string().startsWith("tool-"),
|
|
12104
12200
|
toolCallId: z.string(),
|
|
12201
|
+
title: z.string().optional(),
|
|
12105
12202
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
12106
12203
|
state: z.literal("output-error"),
|
|
12107
12204
|
providerExecuted: z.boolean().optional(),
|
|
@@ -12124,6 +12221,7 @@ var uiMessagesSchema = lazySchema2(
|
|
|
12124
12221
|
z.object({
|
|
12125
12222
|
type: z.string().startsWith("tool-"),
|
|
12126
12223
|
toolCallId: z.string(),
|
|
12224
|
+
title: z.string().optional(),
|
|
12127
12225
|
toolMetadata: toolMetadataSchema2.optional(),
|
|
12128
12226
|
state: z.literal("output-denied"),
|
|
12129
12227
|
providerExecuted: z.boolean().optional(),
|
|
@@ -12859,6 +12957,7 @@ var DefaultEmbedResult = class {
|
|
|
12859
12957
|
};
|
|
12860
12958
|
|
|
12861
12959
|
// src/embed/embed-many.ts
|
|
12960
|
+
import { InvalidResponseDataError as InvalidResponseDataError2 } from "@ai-sdk/provider";
|
|
12862
12961
|
import {
|
|
12863
12962
|
createIdGenerator as createIdGenerator5,
|
|
12864
12963
|
withUserAgentSuffix as withUserAgentSuffix6
|
|
@@ -12995,6 +13094,7 @@ async function embedMany({
|
|
|
12995
13094
|
response: modelResponse.response
|
|
12996
13095
|
};
|
|
12997
13096
|
});
|
|
13097
|
+
validateEmbeddingCount({ embeddings: embeddings2, values });
|
|
12998
13098
|
logWarnings({
|
|
12999
13099
|
warnings: warnings2,
|
|
13000
13100
|
provider: model.provider,
|
|
@@ -13040,8 +13140,8 @@ async function embedMany({
|
|
|
13040
13140
|
);
|
|
13041
13141
|
for (const parallelChunk of parallelChunks) {
|
|
13042
13142
|
const results = await Promise.all(
|
|
13043
|
-
parallelChunk.map((chunk) => {
|
|
13044
|
-
|
|
13143
|
+
parallelChunk.map(async (chunk) => {
|
|
13144
|
+
const result = await retry(async () => {
|
|
13045
13145
|
var _a27, _b26;
|
|
13046
13146
|
const embedCallId = generateCallId();
|
|
13047
13147
|
await notify({
|
|
@@ -13084,6 +13184,11 @@ async function embedMany({
|
|
|
13084
13184
|
response: modelResponse.response
|
|
13085
13185
|
};
|
|
13086
13186
|
});
|
|
13187
|
+
validateEmbeddingCount({
|
|
13188
|
+
embeddings: result.embeddings,
|
|
13189
|
+
values: chunk
|
|
13190
|
+
});
|
|
13191
|
+
return result;
|
|
13087
13192
|
})
|
|
13088
13193
|
);
|
|
13089
13194
|
for (const result of results) {
|
|
@@ -13142,6 +13247,17 @@ async function embedMany({
|
|
|
13142
13247
|
}
|
|
13143
13248
|
});
|
|
13144
13249
|
}
|
|
13250
|
+
function validateEmbeddingCount({
|
|
13251
|
+
embeddings,
|
|
13252
|
+
values
|
|
13253
|
+
}) {
|
|
13254
|
+
if (embeddings.length !== values.length) {
|
|
13255
|
+
throw new InvalidResponseDataError2({
|
|
13256
|
+
data: embeddings,
|
|
13257
|
+
message: `Expected ${values.length} embeddings, but received ${embeddings.length}.`
|
|
13258
|
+
});
|
|
13259
|
+
}
|
|
13260
|
+
}
|
|
13145
13261
|
var textEncoder = new TextEncoder();
|
|
13146
13262
|
function splitByEmbeddingLimits({
|
|
13147
13263
|
values,
|
|
@@ -13370,7 +13486,7 @@ async function generateImage({
|
|
|
13370
13486
|
}
|
|
13371
13487
|
logWarnings({ warnings, provider: model.provider, model: model.modelId });
|
|
13372
13488
|
if (!images.length) {
|
|
13373
|
-
throw new NoImageGeneratedError({ responses });
|
|
13489
|
+
throw new NoImageGeneratedError({ calls, responses });
|
|
13374
13490
|
}
|
|
13375
13491
|
return new DefaultGenerateImageResult({
|
|
13376
13492
|
images,
|
|
@@ -14240,7 +14356,7 @@ function getTextFromDataUrl(dataUrl) {
|
|
|
14240
14356
|
throw new Error("Invalid data URL format");
|
|
14241
14357
|
}
|
|
14242
14358
|
try {
|
|
14243
|
-
return
|
|
14359
|
+
return globalThis.atob(base64Content);
|
|
14244
14360
|
} catch (e) {
|
|
14245
14361
|
throw new Error(`Error decoding data URL`);
|
|
14246
14362
|
}
|
|
@@ -15094,6 +15210,9 @@ var CHUNKING_REGEXPS = {
|
|
|
15094
15210
|
word: /\S+\s+/m,
|
|
15095
15211
|
line: /\n+/m
|
|
15096
15212
|
};
|
|
15213
|
+
function isDocumentHidden() {
|
|
15214
|
+
return typeof document !== "undefined" && document.visibilityState === "hidden";
|
|
15215
|
+
}
|
|
15097
15216
|
function smoothStream({
|
|
15098
15217
|
delayInMs = 10,
|
|
15099
15218
|
chunking = "word",
|
|
@@ -15156,7 +15275,7 @@ function smoothStream({
|
|
|
15156
15275
|
let type = void 0;
|
|
15157
15276
|
let providerMetadata = void 0;
|
|
15158
15277
|
function flushBuffer(controller) {
|
|
15159
|
-
if (buffer.length > 0
|
|
15278
|
+
if (type !== void 0 && (buffer.length > 0 || providerMetadata != null)) {
|
|
15160
15279
|
controller.enqueue({
|
|
15161
15280
|
type,
|
|
15162
15281
|
text: buffer,
|
|
@@ -15174,7 +15293,7 @@ function smoothStream({
|
|
|
15174
15293
|
controller.enqueue(chunk);
|
|
15175
15294
|
return;
|
|
15176
15295
|
}
|
|
15177
|
-
if ((chunk.type !== type || chunk.id !== id) && buffer.length > 0) {
|
|
15296
|
+
if ((chunk.type !== type || chunk.id !== id) && (buffer.length > 0 || providerMetadata != null)) {
|
|
15178
15297
|
flushBuffer(controller);
|
|
15179
15298
|
}
|
|
15180
15299
|
buffer += chunk.text;
|
|
@@ -15187,7 +15306,7 @@ function smoothStream({
|
|
|
15187
15306
|
while ((match = detectChunk(buffer)) != null) {
|
|
15188
15307
|
controller.enqueue({ type, text: match, id });
|
|
15189
15308
|
buffer = buffer.slice(match.length);
|
|
15190
|
-
await delay(delayInMs);
|
|
15309
|
+
await delay(isDocumentHidden() ? null : delayInMs);
|
|
15191
15310
|
}
|
|
15192
15311
|
}
|
|
15193
15312
|
});
|
|
@@ -18463,7 +18582,6 @@ async function callCompletionApi({
|
|
|
18463
18582
|
onError,
|
|
18464
18583
|
fetch: fetch2 = getOriginalFetch()
|
|
18465
18584
|
}) {
|
|
18466
|
-
var _a25;
|
|
18467
18585
|
try {
|
|
18468
18586
|
setLoading(true);
|
|
18469
18587
|
setError(void 0);
|
|
@@ -18491,7 +18609,7 @@ async function callCompletionApi({
|
|
|
18491
18609
|
});
|
|
18492
18610
|
if (!response.ok) {
|
|
18493
18611
|
throw new Error(
|
|
18494
|
-
|
|
18612
|
+
await response.text() || "Failed to fetch the chat response."
|
|
18495
18613
|
);
|
|
18496
18614
|
}
|
|
18497
18615
|
if (!response.body) {
|
|
@@ -18627,7 +18745,7 @@ var HttpChatTransport = class {
|
|
|
18627
18745
|
abortSignal,
|
|
18628
18746
|
...options
|
|
18629
18747
|
}) {
|
|
18630
|
-
var _a25, _b25, _c, _d
|
|
18748
|
+
var _a25, _b25, _c, _d;
|
|
18631
18749
|
const resolvedBody = await resolve2(this.body);
|
|
18632
18750
|
const resolvedHeaders = await resolve2(this.headers);
|
|
18633
18751
|
const resolvedCredentials = await resolve2(this.credentials);
|
|
@@ -18670,7 +18788,7 @@ var HttpChatTransport = class {
|
|
|
18670
18788
|
});
|
|
18671
18789
|
if (!response.ok) {
|
|
18672
18790
|
throw new Error(
|
|
18673
|
-
|
|
18791
|
+
await response.text() || "Failed to fetch the chat response."
|
|
18674
18792
|
);
|
|
18675
18793
|
}
|
|
18676
18794
|
if (!response.body) {
|
|
@@ -18679,7 +18797,7 @@ var HttpChatTransport = class {
|
|
|
18679
18797
|
return this.processResponseStream(response.body);
|
|
18680
18798
|
}
|
|
18681
18799
|
async reconnectToStream(options) {
|
|
18682
|
-
var _a25, _b25, _c, _d
|
|
18800
|
+
var _a25, _b25, _c, _d;
|
|
18683
18801
|
const resolvedBody = await resolve2(this.body);
|
|
18684
18802
|
const resolvedHeaders = await resolve2(this.headers);
|
|
18685
18803
|
const resolvedCredentials = await resolve2(this.credentials);
|
|
@@ -18710,7 +18828,7 @@ var HttpChatTransport = class {
|
|
|
18710
18828
|
}
|
|
18711
18829
|
if (!response.ok) {
|
|
18712
18830
|
throw new Error(
|
|
18713
|
-
|
|
18831
|
+
await response.text() || "Failed to fetch the chat response."
|
|
18714
18832
|
);
|
|
18715
18833
|
}
|
|
18716
18834
|
if (!response.body) {
|
|
@@ -18813,8 +18931,8 @@ var AbstractChat = class {
|
|
|
18813
18931
|
}
|
|
18814
18932
|
this.state.messages = this.state.messages.slice(0, messageIndex + 1);
|
|
18815
18933
|
this.state.replaceMessage(messageIndex, {
|
|
18816
|
-
...uiMessage,
|
|
18817
18934
|
id: message.messageId,
|
|
18935
|
+
...uiMessage,
|
|
18818
18936
|
role: (_b25 = uiMessage.role) != null ? _b25 : "user",
|
|
18819
18937
|
metadata: message.metadata
|
|
18820
18938
|
});
|