ai 5.0.245 → 5.0.249
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 +34 -0
- package/dist/index.d.mts +38 -4
- package/dist/index.d.ts +38 -4
- package/dist/index.js +319 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +244 -43
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/test/index.d.mts +5 -1
- package/dist/test/index.d.ts +5 -1
- package/dist/test/index.js +11 -1
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +11 -1
- package/dist/test/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -59,7 +59,7 @@ __export(src_exports, {
|
|
|
59
59
|
UI_MESSAGE_STREAM_HEADERS: () => UI_MESSAGE_STREAM_HEADERS,
|
|
60
60
|
UnsupportedFunctionalityError: () => import_provider17.UnsupportedFunctionalityError,
|
|
61
61
|
UnsupportedModelVersionError: () => UnsupportedModelVersionError,
|
|
62
|
-
asSchema: () =>
|
|
62
|
+
asSchema: () => import_provider_utils35.asSchema,
|
|
63
63
|
assistantModelMessageSchema: () => assistantModelMessageSchema,
|
|
64
64
|
callCompletionApi: () => callCompletionApi,
|
|
65
65
|
consumeStream: () => consumeStream,
|
|
@@ -74,14 +74,14 @@ __export(src_exports, {
|
|
|
74
74
|
cosineSimilarity: () => cosineSimilarity,
|
|
75
75
|
createDownload: () => createDownload,
|
|
76
76
|
createGateway: () => import_gateway3.createGateway,
|
|
77
|
-
createIdGenerator: () =>
|
|
77
|
+
createIdGenerator: () => import_provider_utils35.createIdGenerator,
|
|
78
78
|
createProviderRegistry: () => createProviderRegistry,
|
|
79
79
|
createTextStreamResponse: () => createTextStreamResponse,
|
|
80
80
|
createUIMessageStream: () => createUIMessageStream,
|
|
81
81
|
createUIMessageStreamResponse: () => createUIMessageStreamResponse,
|
|
82
82
|
customProvider: () => customProvider,
|
|
83
83
|
defaultSettingsMiddleware: () => defaultSettingsMiddleware,
|
|
84
|
-
dynamicTool: () =>
|
|
84
|
+
dynamicTool: () => import_provider_utils35.dynamicTool,
|
|
85
85
|
embed: () => embed,
|
|
86
86
|
embedMany: () => embedMany,
|
|
87
87
|
experimental_createProviderRegistry: () => experimental_createProviderRegistry,
|
|
@@ -91,7 +91,7 @@ __export(src_exports, {
|
|
|
91
91
|
experimental_transcribe: () => transcribe,
|
|
92
92
|
extractReasoningMiddleware: () => extractReasoningMiddleware,
|
|
93
93
|
gateway: () => import_gateway3.gateway,
|
|
94
|
-
generateId: () =>
|
|
94
|
+
generateId: () => import_provider_utils35.generateId,
|
|
95
95
|
generateObject: () => generateObject,
|
|
96
96
|
generateText: () => generateText,
|
|
97
97
|
getTextFromDataUrl: () => getTextFromDataUrl,
|
|
@@ -105,10 +105,10 @@ __export(src_exports, {
|
|
|
105
105
|
isTextUIPart: () => isTextUIPart,
|
|
106
106
|
isToolOrDynamicToolUIPart: () => isToolOrDynamicToolUIPart,
|
|
107
107
|
isToolUIPart: () => isToolUIPart,
|
|
108
|
-
jsonSchema: () =>
|
|
108
|
+
jsonSchema: () => import_provider_utils35.jsonSchema,
|
|
109
109
|
lastAssistantMessageIsCompleteWithToolCalls: () => lastAssistantMessageIsCompleteWithToolCalls,
|
|
110
110
|
modelMessageSchema: () => modelMessageSchema,
|
|
111
|
-
parseJsonEventStream: () =>
|
|
111
|
+
parseJsonEventStream: () => import_provider_utils35.parseJsonEventStream,
|
|
112
112
|
parsePartialJson: () => parsePartialJson,
|
|
113
113
|
pipeTextStreamToResponse: () => pipeTextStreamToResponse,
|
|
114
114
|
pipeUIMessageStreamToResponse: () => pipeUIMessageStreamToResponse,
|
|
@@ -122,18 +122,18 @@ __export(src_exports, {
|
|
|
122
122
|
streamObject: () => streamObject,
|
|
123
123
|
streamText: () => streamText,
|
|
124
124
|
systemModelMessageSchema: () => systemModelMessageSchema,
|
|
125
|
-
tool: () =>
|
|
125
|
+
tool: () => import_provider_utils35.tool,
|
|
126
126
|
toolModelMessageSchema: () => toolModelMessageSchema,
|
|
127
127
|
uiMessageChunkSchema: () => uiMessageChunkSchema,
|
|
128
128
|
userModelMessageSchema: () => userModelMessageSchema,
|
|
129
129
|
validateUIMessages: () => validateUIMessages,
|
|
130
130
|
wrapLanguageModel: () => wrapLanguageModel,
|
|
131
131
|
wrapProvider: () => wrapProvider,
|
|
132
|
-
zodSchema: () =>
|
|
132
|
+
zodSchema: () => import_provider_utils35.zodSchema
|
|
133
133
|
});
|
|
134
134
|
module.exports = __toCommonJS(src_exports);
|
|
135
135
|
var import_gateway3 = require("@ai-sdk/gateway");
|
|
136
|
-
var
|
|
136
|
+
var import_provider_utils35 = require("@ai-sdk/provider-utils");
|
|
137
137
|
|
|
138
138
|
// src/generate-text/generate-text.ts
|
|
139
139
|
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
@@ -816,7 +816,7 @@ function detectMediaType({
|
|
|
816
816
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
817
817
|
|
|
818
818
|
// src/version.ts
|
|
819
|
-
var VERSION = true ? "5.0.
|
|
819
|
+
var VERSION = true ? "5.0.249" : "0.0.0-test";
|
|
820
820
|
|
|
821
821
|
// src/util/download/download.ts
|
|
822
822
|
var download = async ({
|
|
@@ -1600,13 +1600,22 @@ function assembleOperationName({
|
|
|
1600
1600
|
}
|
|
1601
1601
|
|
|
1602
1602
|
// src/telemetry/get-base-telemetry-attributes.ts
|
|
1603
|
+
function getTelemetryMetadataAttributes(telemetry) {
|
|
1604
|
+
var _a16;
|
|
1605
|
+
return Object.entries((_a16 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a16 : {}).reduce(
|
|
1606
|
+
(attributes, [key, value]) => {
|
|
1607
|
+
attributes[`ai.telemetry.metadata.${key}`] = value;
|
|
1608
|
+
return attributes;
|
|
1609
|
+
},
|
|
1610
|
+
{}
|
|
1611
|
+
);
|
|
1612
|
+
}
|
|
1603
1613
|
function getBaseTelemetryAttributes({
|
|
1604
1614
|
model,
|
|
1605
1615
|
settings,
|
|
1606
1616
|
telemetry,
|
|
1607
1617
|
headers
|
|
1608
1618
|
}) {
|
|
1609
|
-
var _a16;
|
|
1610
1619
|
return {
|
|
1611
1620
|
"ai.model.provider": model.provider,
|
|
1612
1621
|
"ai.model.id": model.modelId,
|
|
@@ -1616,13 +1625,7 @@ function getBaseTelemetryAttributes({
|
|
|
1616
1625
|
return attributes;
|
|
1617
1626
|
}, {}),
|
|
1618
1627
|
// add metadata as attributes:
|
|
1619
|
-
...
|
|
1620
|
-
(attributes, [key, value]) => {
|
|
1621
|
-
attributes[`ai.telemetry.metadata.${key}`] = value;
|
|
1622
|
-
return attributes;
|
|
1623
|
-
},
|
|
1624
|
-
{}
|
|
1625
|
-
),
|
|
1628
|
+
...getTelemetryMetadataAttributes(telemetry),
|
|
1626
1629
|
// request headers
|
|
1627
1630
|
...Object.entries(headers != null ? headers : {}).reduce((attributes, [key, value]) => {
|
|
1628
1631
|
if (value !== void 0) {
|
|
@@ -2697,6 +2700,7 @@ async function executeTools({
|
|
|
2697
2700
|
operationId: "ai.toolCall",
|
|
2698
2701
|
telemetry
|
|
2699
2702
|
}),
|
|
2703
|
+
...getTelemetryMetadataAttributes(telemetry),
|
|
2700
2704
|
"ai.toolCall.name": toolName,
|
|
2701
2705
|
"ai.toolCall.id": toolCallId,
|
|
2702
2706
|
"ai.toolCall.args": {
|
|
@@ -4137,7 +4141,8 @@ function handleUIMessageStreamFinish({
|
|
|
4137
4141
|
originalMessages = [],
|
|
4138
4142
|
onFinish,
|
|
4139
4143
|
onError,
|
|
4140
|
-
stream
|
|
4144
|
+
stream,
|
|
4145
|
+
getOutcome
|
|
4141
4146
|
}) {
|
|
4142
4147
|
let lastMessage = originalMessages == null ? void 0 : originalMessages[originalMessages.length - 1];
|
|
4143
4148
|
if ((lastMessage == null ? void 0 : lastMessage.role) !== "assistant") {
|
|
@@ -4146,19 +4151,34 @@ function handleUIMessageStreamFinish({
|
|
|
4146
4151
|
messageId = lastMessage.id;
|
|
4147
4152
|
}
|
|
4148
4153
|
let isAborted = false;
|
|
4154
|
+
let hasProcessingFailure = false;
|
|
4155
|
+
let processingError;
|
|
4156
|
+
const recordProcessingFailure = (error) => {
|
|
4157
|
+
hasProcessingFailure = true;
|
|
4158
|
+
processingError = error;
|
|
4159
|
+
};
|
|
4149
4160
|
const idInjectedStream = stream.pipeThrough(
|
|
4150
4161
|
new TransformStream({
|
|
4151
4162
|
transform(chunk, controller) {
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
if (
|
|
4155
|
-
startChunk
|
|
4163
|
+
try {
|
|
4164
|
+
let outputChunk = chunk;
|
|
4165
|
+
if (chunk.type === "start") {
|
|
4166
|
+
const startChunk = chunk;
|
|
4167
|
+
if (startChunk.messageId == null && messageId != null) {
|
|
4168
|
+
outputChunk = {
|
|
4169
|
+
...startChunk,
|
|
4170
|
+
messageId
|
|
4171
|
+
};
|
|
4172
|
+
}
|
|
4156
4173
|
}
|
|
4174
|
+
if (chunk.type === "abort") {
|
|
4175
|
+
isAborted = true;
|
|
4176
|
+
}
|
|
4177
|
+
controller.enqueue(outputChunk);
|
|
4178
|
+
} catch (error) {
|
|
4179
|
+
recordProcessingFailure(error);
|
|
4180
|
+
throw error;
|
|
4157
4181
|
}
|
|
4158
|
-
if (chunk.type === "abort") {
|
|
4159
|
-
isAborted = true;
|
|
4160
|
-
}
|
|
4161
|
-
controller.enqueue(chunk);
|
|
4162
4182
|
}
|
|
4163
4183
|
})
|
|
4164
4184
|
);
|
|
@@ -4171,19 +4191,28 @@ function handleUIMessageStreamFinish({
|
|
|
4171
4191
|
// will be overridden by the stream
|
|
4172
4192
|
});
|
|
4173
4193
|
const runUpdateMessageJob = async (job) => {
|
|
4174
|
-
|
|
4175
|
-
|
|
4194
|
+
try {
|
|
4195
|
+
await job({ state, write: () => {
|
|
4196
|
+
} });
|
|
4197
|
+
} catch (error) {
|
|
4198
|
+
recordProcessingFailure(error);
|
|
4199
|
+
throw error;
|
|
4200
|
+
}
|
|
4176
4201
|
};
|
|
4177
4202
|
let finishCalled = false;
|
|
4178
4203
|
const callOnFinish = async () => {
|
|
4204
|
+
var _a16;
|
|
4179
4205
|
if (finishCalled || !onFinish) {
|
|
4180
4206
|
return;
|
|
4181
4207
|
}
|
|
4182
4208
|
finishCalled = true;
|
|
4183
4209
|
const isContinuation = state.message.id === (lastMessage == null ? void 0 : lastMessage.id);
|
|
4210
|
+
const declaredOutcome = (_a16 = getOutcome == null ? void 0 : getOutcome()) != null ? _a16 : { status: "unknown" };
|
|
4211
|
+
const outcome = hasProcessingFailure ? { status: "failed", error: processingError } : declaredOutcome.status === "unknown" && isAborted ? { status: "aborted" } : declaredOutcome;
|
|
4184
4212
|
await onFinish({
|
|
4185
|
-
isAborted,
|
|
4213
|
+
isAborted: isAborted || outcome.status === "aborted",
|
|
4186
4214
|
isContinuation,
|
|
4215
|
+
outcome,
|
|
4187
4216
|
responseMessage: state.message,
|
|
4188
4217
|
messages: [
|
|
4189
4218
|
...isContinuation ? originalMessages.slice(0, -1) : originalMessages,
|
|
@@ -4516,6 +4545,7 @@ function runToolsTransformation({
|
|
|
4516
4545
|
operationId: "ai.toolCall",
|
|
4517
4546
|
telemetry
|
|
4518
4547
|
}),
|
|
4548
|
+
...getTelemetryMetadataAttributes(telemetry),
|
|
4519
4549
|
"ai.toolCall.name": toolCall.toolName,
|
|
4520
4550
|
"ai.toolCall.id": toolCall.toolCallId,
|
|
4521
4551
|
"ai.toolCall.args": {
|
|
@@ -5775,6 +5805,17 @@ var DefaultStreamTextResult = class {
|
|
|
5775
5805
|
onError = () => "An error occurred."
|
|
5776
5806
|
// prevent leaking server error details to the client by default
|
|
5777
5807
|
} = {}) {
|
|
5808
|
+
let outcome = { status: "unknown" };
|
|
5809
|
+
let hasFatalFailure = false;
|
|
5810
|
+
const setSourceOutcome = (newOutcome) => {
|
|
5811
|
+
if (!hasFatalFailure && outcome.status !== "completed" && outcome.status !== "aborted" && newOutcome.status !== "unknown" && (outcome.status === "unknown" || newOutcome.status !== "failed")) {
|
|
5812
|
+
outcome = newOutcome;
|
|
5813
|
+
}
|
|
5814
|
+
};
|
|
5815
|
+
const failOutcome = (error) => {
|
|
5816
|
+
hasFatalFailure = true;
|
|
5817
|
+
outcome = { status: "failed", error };
|
|
5818
|
+
};
|
|
5778
5819
|
const responseMessageId = generateMessageId != null ? getResponseUIMessageId({
|
|
5779
5820
|
originalMessages,
|
|
5780
5821
|
responseMessageId: generateMessageId
|
|
@@ -5786,7 +5827,48 @@ var DefaultStreamTextResult = class {
|
|
|
5786
5827
|
const dynamic = ((_b = (_a16 = this.tools) == null ? void 0 : _a16[toolName]) == null ? void 0 : _b.type) === "dynamic";
|
|
5787
5828
|
return dynamic ? true : void 0;
|
|
5788
5829
|
};
|
|
5789
|
-
const
|
|
5830
|
+
const sourceReader = this.fullStream.getReader();
|
|
5831
|
+
let sourceReaderReleased = false;
|
|
5832
|
+
let sourceStreamCancelled = false;
|
|
5833
|
+
const releaseSourceReader = () => {
|
|
5834
|
+
if (!sourceReaderReleased) {
|
|
5835
|
+
sourceReader.releaseLock();
|
|
5836
|
+
sourceReaderReleased = true;
|
|
5837
|
+
}
|
|
5838
|
+
};
|
|
5839
|
+
const sourceStream = new ReadableStream({
|
|
5840
|
+
async pull(controller) {
|
|
5841
|
+
try {
|
|
5842
|
+
const { done, value } = await sourceReader.read();
|
|
5843
|
+
if (done) {
|
|
5844
|
+
releaseSourceReader();
|
|
5845
|
+
if (!sourceStreamCancelled) {
|
|
5846
|
+
controller.close();
|
|
5847
|
+
}
|
|
5848
|
+
} else {
|
|
5849
|
+
controller.enqueue(value);
|
|
5850
|
+
}
|
|
5851
|
+
} catch (error) {
|
|
5852
|
+
releaseSourceReader();
|
|
5853
|
+
if (!sourceStreamCancelled) {
|
|
5854
|
+
failOutcome(error);
|
|
5855
|
+
controller.error(error);
|
|
5856
|
+
}
|
|
5857
|
+
}
|
|
5858
|
+
},
|
|
5859
|
+
async cancel(reason) {
|
|
5860
|
+
sourceStreamCancelled = true;
|
|
5861
|
+
if (sourceReaderReleased) {
|
|
5862
|
+
return;
|
|
5863
|
+
}
|
|
5864
|
+
try {
|
|
5865
|
+
await sourceReader.cancel(reason);
|
|
5866
|
+
} finally {
|
|
5867
|
+
releaseSourceReader();
|
|
5868
|
+
}
|
|
5869
|
+
}
|
|
5870
|
+
});
|
|
5871
|
+
const baseStream = sourceStream.pipeThrough(
|
|
5790
5872
|
new TransformStream({
|
|
5791
5873
|
transform: async (part, controller) => {
|
|
5792
5874
|
const messageMetadataValue = messageMetadata == null ? void 0 : messageMetadata({ part });
|
|
@@ -6000,16 +6082,65 @@ var DefaultStreamTextResult = class {
|
|
|
6000
6082
|
messageMetadata: messageMetadataValue
|
|
6001
6083
|
});
|
|
6002
6084
|
}
|
|
6085
|
+
if (part.type === "finish") {
|
|
6086
|
+
setSourceOutcome({ status: "completed" });
|
|
6087
|
+
} else if (part.type === "abort") {
|
|
6088
|
+
setSourceOutcome({ status: "aborted" });
|
|
6089
|
+
} else if (part.type === "error") {
|
|
6090
|
+
setSourceOutcome({ status: "failed", error: part.error });
|
|
6091
|
+
}
|
|
6003
6092
|
}
|
|
6004
6093
|
})
|
|
6005
6094
|
);
|
|
6095
|
+
const baseStreamReader = baseStream.getReader();
|
|
6096
|
+
let baseStreamReaderReleased = false;
|
|
6097
|
+
let baseStreamCancelled = false;
|
|
6098
|
+
const releaseBaseStreamReader = () => {
|
|
6099
|
+
if (!baseStreamReaderReleased) {
|
|
6100
|
+
baseStreamReader.releaseLock();
|
|
6101
|
+
baseStreamReaderReleased = true;
|
|
6102
|
+
}
|
|
6103
|
+
};
|
|
6104
|
+
const trackedBaseStream = new ReadableStream({
|
|
6105
|
+
async pull(controller) {
|
|
6106
|
+
try {
|
|
6107
|
+
const { done, value } = await baseStreamReader.read();
|
|
6108
|
+
if (done) {
|
|
6109
|
+
releaseBaseStreamReader();
|
|
6110
|
+
if (!baseStreamCancelled) {
|
|
6111
|
+
controller.close();
|
|
6112
|
+
}
|
|
6113
|
+
} else {
|
|
6114
|
+
controller.enqueue(value);
|
|
6115
|
+
}
|
|
6116
|
+
} catch (error) {
|
|
6117
|
+
releaseBaseStreamReader();
|
|
6118
|
+
if (!baseStreamCancelled) {
|
|
6119
|
+
failOutcome(error);
|
|
6120
|
+
controller.error(error);
|
|
6121
|
+
}
|
|
6122
|
+
}
|
|
6123
|
+
},
|
|
6124
|
+
async cancel(reason) {
|
|
6125
|
+
baseStreamCancelled = true;
|
|
6126
|
+
if (baseStreamReaderReleased) {
|
|
6127
|
+
return;
|
|
6128
|
+
}
|
|
6129
|
+
try {
|
|
6130
|
+
await baseStreamReader.cancel(reason);
|
|
6131
|
+
} finally {
|
|
6132
|
+
releaseBaseStreamReader();
|
|
6133
|
+
}
|
|
6134
|
+
}
|
|
6135
|
+
});
|
|
6006
6136
|
return createAsyncIterableStream(
|
|
6007
6137
|
handleUIMessageStreamFinish({
|
|
6008
|
-
stream:
|
|
6138
|
+
stream: trackedBaseStream,
|
|
6009
6139
|
messageId: responseMessageId != null ? responseMessageId : generateMessageId == null ? void 0 : generateMessageId(),
|
|
6010
6140
|
originalMessages,
|
|
6011
6141
|
onFinish,
|
|
6012
|
-
onError
|
|
6142
|
+
onError,
|
|
6143
|
+
getOutcome: () => outcome
|
|
6013
6144
|
})
|
|
6014
6145
|
);
|
|
6015
6146
|
}
|
|
@@ -6431,7 +6562,13 @@ var DefaultEmbedResult = class {
|
|
|
6431
6562
|
};
|
|
6432
6563
|
|
|
6433
6564
|
// src/embed/embed-many.ts
|
|
6565
|
+
var import_provider_utils18 = require("@ai-sdk/provider-utils");
|
|
6566
|
+
|
|
6567
|
+
// src/model/get-embedding-model-max-input-bytes-per-call.ts
|
|
6434
6568
|
var import_provider_utils17 = require("@ai-sdk/provider-utils");
|
|
6569
|
+
function getEmbeddingModelMaxInputBytesPerCall(model) {
|
|
6570
|
+
return model[import_provider_utils17.EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL];
|
|
6571
|
+
}
|
|
6435
6572
|
|
|
6436
6573
|
// src/util/split-array.ts
|
|
6437
6574
|
function splitArray(array, chunkSize) {
|
|
@@ -6461,7 +6598,7 @@ async function embedMany({
|
|
|
6461
6598
|
maxRetries: maxRetriesArg,
|
|
6462
6599
|
abortSignal
|
|
6463
6600
|
});
|
|
6464
|
-
const headersWithUserAgent = (0,
|
|
6601
|
+
const headersWithUserAgent = (0, import_provider_utils18.withUserAgentSuffix)(
|
|
6465
6602
|
headers != null ? headers : {},
|
|
6466
6603
|
`ai/${VERSION}`
|
|
6467
6604
|
);
|
|
@@ -6488,11 +6625,18 @@ async function embedMany({
|
|
|
6488
6625
|
tracer,
|
|
6489
6626
|
fn: async (span) => {
|
|
6490
6627
|
var _a16;
|
|
6491
|
-
const [
|
|
6628
|
+
const [
|
|
6629
|
+
maxEmbeddingsPerCall,
|
|
6630
|
+
maxInputBytesPerCall,
|
|
6631
|
+
supportsParallelCalls
|
|
6632
|
+
] = await Promise.all([
|
|
6492
6633
|
model.maxEmbeddingsPerCall,
|
|
6634
|
+
getEmbeddingModelMaxInputBytesPerCall(model),
|
|
6493
6635
|
model.supportsParallelCalls
|
|
6494
6636
|
]);
|
|
6495
|
-
|
|
6637
|
+
const hasEmbeddingLimit = maxEmbeddingsPerCall != null && maxEmbeddingsPerCall !== Infinity;
|
|
6638
|
+
const hasInputByteLimit = maxInputBytesPerCall != null && maxInputBytesPerCall !== Infinity;
|
|
6639
|
+
if (!hasEmbeddingLimit && !hasInputByteLimit) {
|
|
6496
6640
|
const { embeddings: embeddings2, usage, response, providerMetadata: providerMetadata2 } = await retry(
|
|
6497
6641
|
() => {
|
|
6498
6642
|
return recordSpan({
|
|
@@ -6564,7 +6708,11 @@ async function embedMany({
|
|
|
6564
6708
|
responses: [response]
|
|
6565
6709
|
});
|
|
6566
6710
|
}
|
|
6567
|
-
const valueChunks =
|
|
6711
|
+
const valueChunks = splitByEmbeddingLimits({
|
|
6712
|
+
values,
|
|
6713
|
+
maxEmbeddingsPerCall: hasEmbeddingLimit ? maxEmbeddingsPerCall : Infinity,
|
|
6714
|
+
maxInputBytesPerCall: hasInputByteLimit ? maxInputBytesPerCall : Infinity
|
|
6715
|
+
});
|
|
6568
6716
|
const embeddings = [];
|
|
6569
6717
|
const responses = [];
|
|
6570
6718
|
let tokens = 0;
|
|
@@ -6669,6 +6817,37 @@ async function embedMany({
|
|
|
6669
6817
|
}
|
|
6670
6818
|
});
|
|
6671
6819
|
}
|
|
6820
|
+
var textEncoder = new TextEncoder();
|
|
6821
|
+
function splitByEmbeddingLimits({
|
|
6822
|
+
values,
|
|
6823
|
+
maxEmbeddingsPerCall,
|
|
6824
|
+
maxInputBytesPerCall
|
|
6825
|
+
}) {
|
|
6826
|
+
if (maxEmbeddingsPerCall <= 0) {
|
|
6827
|
+
throw new Error("maxEmbeddingsPerCall must be greater than 0");
|
|
6828
|
+
}
|
|
6829
|
+
if (maxInputBytesPerCall <= 0) {
|
|
6830
|
+
throw new Error("maxInputBytesPerCall must be greater than 0");
|
|
6831
|
+
}
|
|
6832
|
+
if (values.length === 0) {
|
|
6833
|
+
return [];
|
|
6834
|
+
}
|
|
6835
|
+
const chunks = [];
|
|
6836
|
+
let currentChunk = [];
|
|
6837
|
+
let currentInputBytes = 0;
|
|
6838
|
+
for (const value of values) {
|
|
6839
|
+
const inputBytes = maxInputBytesPerCall === Infinity ? 0 : textEncoder.encode(value).length;
|
|
6840
|
+
if (currentChunk.length > 0 && (currentChunk.length >= maxEmbeddingsPerCall || currentInputBytes + inputBytes > maxInputBytesPerCall)) {
|
|
6841
|
+
chunks.push(currentChunk);
|
|
6842
|
+
currentChunk = [];
|
|
6843
|
+
currentInputBytes = 0;
|
|
6844
|
+
}
|
|
6845
|
+
currentChunk.push(value);
|
|
6846
|
+
currentInputBytes += inputBytes;
|
|
6847
|
+
}
|
|
6848
|
+
chunks.push(currentChunk);
|
|
6849
|
+
return chunks;
|
|
6850
|
+
}
|
|
6672
6851
|
var DefaultEmbedManyResult = class {
|
|
6673
6852
|
constructor(options) {
|
|
6674
6853
|
this.values = options.values;
|
|
@@ -6680,7 +6859,7 @@ var DefaultEmbedManyResult = class {
|
|
|
6680
6859
|
};
|
|
6681
6860
|
|
|
6682
6861
|
// src/generate-image/generate-image.ts
|
|
6683
|
-
var
|
|
6862
|
+
var import_provider_utils19 = require("@ai-sdk/provider-utils");
|
|
6684
6863
|
async function generateImage({
|
|
6685
6864
|
model: modelArg,
|
|
6686
6865
|
prompt,
|
|
@@ -6696,7 +6875,7 @@ async function generateImage({
|
|
|
6696
6875
|
}) {
|
|
6697
6876
|
var _a16, _b;
|
|
6698
6877
|
const model = resolveImageModel(modelArg);
|
|
6699
|
-
const headersWithUserAgent = (0,
|
|
6878
|
+
const headersWithUserAgent = (0, import_provider_utils19.withUserAgentSuffix)(
|
|
6700
6879
|
headers != null ? headers : {},
|
|
6701
6880
|
`ai/${VERSION}`
|
|
6702
6881
|
);
|
|
@@ -6808,7 +6987,7 @@ async function invokeModelMaxImagesPerCall(model) {
|
|
|
6808
6987
|
}
|
|
6809
6988
|
|
|
6810
6989
|
// src/generate-object/generate-object.ts
|
|
6811
|
-
var
|
|
6990
|
+
var import_provider_utils22 = require("@ai-sdk/provider-utils");
|
|
6812
6991
|
|
|
6813
6992
|
// src/generate-text/extract-reasoning-content.ts
|
|
6814
6993
|
function extractReasoningContent(content) {
|
|
@@ -6820,7 +6999,7 @@ function extractReasoningContent(content) {
|
|
|
6820
6999
|
|
|
6821
7000
|
// src/generate-object/output-strategy.ts
|
|
6822
7001
|
var import_provider23 = require("@ai-sdk/provider");
|
|
6823
|
-
var
|
|
7002
|
+
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
6824
7003
|
var noSchemaOutputStrategy = {
|
|
6825
7004
|
type: "no-schema",
|
|
6826
7005
|
jsonSchema: void 0,
|
|
@@ -6859,7 +7038,7 @@ var objectOutputStrategy = (schema) => ({
|
|
|
6859
7038
|
};
|
|
6860
7039
|
},
|
|
6861
7040
|
async validateFinalResult(value) {
|
|
6862
|
-
return (0,
|
|
7041
|
+
return (0, import_provider_utils20.safeValidateTypes)({ value, schema });
|
|
6863
7042
|
},
|
|
6864
7043
|
createElementStream() {
|
|
6865
7044
|
throw new import_provider23.UnsupportedFunctionalityError({
|
|
@@ -6903,7 +7082,7 @@ var arrayOutputStrategy = (schema) => {
|
|
|
6903
7082
|
const resultArray = [];
|
|
6904
7083
|
for (let i = 0; i < inputArray.length; i++) {
|
|
6905
7084
|
const element = inputArray[i];
|
|
6906
|
-
const result = await (0,
|
|
7085
|
+
const result = await (0, import_provider_utils20.safeValidateTypes)({ value: element, schema });
|
|
6907
7086
|
if (i === inputArray.length - 1 && !isFinalDelta) {
|
|
6908
7087
|
continue;
|
|
6909
7088
|
}
|
|
@@ -6945,7 +7124,7 @@ var arrayOutputStrategy = (schema) => {
|
|
|
6945
7124
|
const inputArray = value.elements;
|
|
6946
7125
|
const resultArray = [];
|
|
6947
7126
|
for (const element of inputArray) {
|
|
6948
|
-
const result = await (0,
|
|
7127
|
+
const result = await (0, import_provider_utils20.safeValidateTypes)({ value: element, schema });
|
|
6949
7128
|
if (!result.success) {
|
|
6950
7129
|
return result;
|
|
6951
7130
|
}
|
|
@@ -7064,9 +7243,9 @@ function getOutputStrategy({
|
|
|
7064
7243
|
}) {
|
|
7065
7244
|
switch (output) {
|
|
7066
7245
|
case "object":
|
|
7067
|
-
return objectOutputStrategy((0,
|
|
7246
|
+
return objectOutputStrategy((0, import_provider_utils20.asSchema)(schema));
|
|
7068
7247
|
case "array":
|
|
7069
|
-
return arrayOutputStrategy((0,
|
|
7248
|
+
return arrayOutputStrategy((0, import_provider_utils20.asSchema)(schema));
|
|
7070
7249
|
case "enum":
|
|
7071
7250
|
return enumOutputStrategy(enumValues);
|
|
7072
7251
|
case "no-schema":
|
|
@@ -7080,9 +7259,9 @@ function getOutputStrategy({
|
|
|
7080
7259
|
|
|
7081
7260
|
// src/generate-object/parse-and-validate-object-result.ts
|
|
7082
7261
|
var import_provider24 = require("@ai-sdk/provider");
|
|
7083
|
-
var
|
|
7262
|
+
var import_provider_utils21 = require("@ai-sdk/provider-utils");
|
|
7084
7263
|
async function parseAndValidateObjectResult(result, outputStrategy, context) {
|
|
7085
|
-
const parseResult = await (0,
|
|
7264
|
+
const parseResult = await (0, import_provider_utils21.safeParseJSON)({ text: result });
|
|
7086
7265
|
if (!parseResult.success) {
|
|
7087
7266
|
throw new NoObjectGeneratedError({
|
|
7088
7267
|
message: "No object generated: could not parse the response.",
|
|
@@ -7254,7 +7433,7 @@ function validateObjectGenerationInput({
|
|
|
7254
7433
|
}
|
|
7255
7434
|
|
|
7256
7435
|
// src/generate-object/generate-object.ts
|
|
7257
|
-
var originalGenerateId3 = (0,
|
|
7436
|
+
var originalGenerateId3 = (0, import_provider_utils22.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
|
7258
7437
|
async function generateObject(options) {
|
|
7259
7438
|
const {
|
|
7260
7439
|
model: modelArg,
|
|
@@ -7300,7 +7479,7 @@ async function generateObject(options) {
|
|
|
7300
7479
|
enumValues
|
|
7301
7480
|
});
|
|
7302
7481
|
const callSettings = prepareCallSettings(settings);
|
|
7303
|
-
const headersWithUserAgent = (0,
|
|
7482
|
+
const headersWithUserAgent = (0, import_provider_utils22.withUserAgentSuffix)(
|
|
7304
7483
|
headers != null ? headers : {},
|
|
7305
7484
|
`ai/${VERSION}`
|
|
7306
7485
|
);
|
|
@@ -7520,7 +7699,7 @@ var DefaultGenerateObjectResult = class {
|
|
|
7520
7699
|
};
|
|
7521
7700
|
|
|
7522
7701
|
// src/generate-object/stream-object.ts
|
|
7523
|
-
var
|
|
7702
|
+
var import_provider_utils24 = require("@ai-sdk/provider-utils");
|
|
7524
7703
|
|
|
7525
7704
|
// src/util/cosine-similarity.ts
|
|
7526
7705
|
function cosineSimilarity(vector1, vector2) {
|
|
@@ -7635,7 +7814,7 @@ var SerialJobExecutor = class {
|
|
|
7635
7814
|
};
|
|
7636
7815
|
|
|
7637
7816
|
// src/util/simulate-readable-stream.ts
|
|
7638
|
-
var
|
|
7817
|
+
var import_provider_utils23 = require("@ai-sdk/provider-utils");
|
|
7639
7818
|
function simulateReadableStream({
|
|
7640
7819
|
chunks,
|
|
7641
7820
|
initialDelayInMs = 0,
|
|
@@ -7643,7 +7822,7 @@ function simulateReadableStream({
|
|
|
7643
7822
|
_internal
|
|
7644
7823
|
}) {
|
|
7645
7824
|
var _a16;
|
|
7646
|
-
const delay2 = (_a16 = _internal == null ? void 0 : _internal.delay) != null ? _a16 :
|
|
7825
|
+
const delay2 = (_a16 = _internal == null ? void 0 : _internal.delay) != null ? _a16 : import_provider_utils23.delay;
|
|
7647
7826
|
let index = 0;
|
|
7648
7827
|
return new ReadableStream({
|
|
7649
7828
|
async pull(controller) {
|
|
@@ -7658,7 +7837,7 @@ function simulateReadableStream({
|
|
|
7658
7837
|
}
|
|
7659
7838
|
|
|
7660
7839
|
// src/generate-object/stream-object.ts
|
|
7661
|
-
var originalGenerateId4 = (0,
|
|
7840
|
+
var originalGenerateId4 = (0, import_provider_utils24.createIdGenerator)({ prefix: "aiobj", size: 24 });
|
|
7662
7841
|
async function markPromiseAsHandled(promise) {
|
|
7663
7842
|
try {
|
|
7664
7843
|
await promise;
|
|
@@ -7757,13 +7936,13 @@ var DefaultStreamObjectResult = class {
|
|
|
7757
7936
|
currentDate,
|
|
7758
7937
|
now: now2
|
|
7759
7938
|
}) {
|
|
7760
|
-
this._object = new
|
|
7761
|
-
this._usage = new
|
|
7762
|
-
this._providerMetadata = new
|
|
7763
|
-
this._warnings = new
|
|
7764
|
-
this._request = new
|
|
7765
|
-
this._response = new
|
|
7766
|
-
this._finishReason = new
|
|
7939
|
+
this._object = new import_provider_utils24.DelayedPromise();
|
|
7940
|
+
this._usage = new import_provider_utils24.DelayedPromise();
|
|
7941
|
+
this._providerMetadata = new import_provider_utils24.DelayedPromise();
|
|
7942
|
+
this._warnings = new import_provider_utils24.DelayedPromise();
|
|
7943
|
+
this._request = new import_provider_utils24.DelayedPromise();
|
|
7944
|
+
this._response = new import_provider_utils24.DelayedPromise();
|
|
7945
|
+
this._finishReason = new import_provider_utils24.DelayedPromise();
|
|
7767
7946
|
const model = resolveLanguageModel(modelArg);
|
|
7768
7947
|
const { maxRetries, retry } = prepareRetries({
|
|
7769
7948
|
maxRetries: maxRetriesArg,
|
|
@@ -8237,7 +8416,7 @@ var DefaultStreamObjectResult = class {
|
|
|
8237
8416
|
};
|
|
8238
8417
|
|
|
8239
8418
|
// src/generate-speech/generate-speech.ts
|
|
8240
|
-
var
|
|
8419
|
+
var import_provider_utils25 = require("@ai-sdk/provider-utils");
|
|
8241
8420
|
|
|
8242
8421
|
// src/generate-speech/generated-audio-file.ts
|
|
8243
8422
|
var DefaultGeneratedAudioFile = class extends DefaultGeneratedFile {
|
|
@@ -8286,7 +8465,7 @@ async function generateSpeech({
|
|
|
8286
8465
|
modelId: model.modelId
|
|
8287
8466
|
});
|
|
8288
8467
|
}
|
|
8289
|
-
const headersWithUserAgent = (0,
|
|
8468
|
+
const headersWithUserAgent = (0, import_provider_utils25.withUserAgentSuffix)(
|
|
8290
8469
|
headers != null ? headers : {},
|
|
8291
8470
|
`ai/${VERSION}`
|
|
8292
8471
|
);
|
|
@@ -8340,7 +8519,7 @@ __export(output_exports, {
|
|
|
8340
8519
|
object: () => object,
|
|
8341
8520
|
text: () => text
|
|
8342
8521
|
});
|
|
8343
|
-
var
|
|
8522
|
+
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
|
8344
8523
|
var text = () => ({
|
|
8345
8524
|
type: "text",
|
|
8346
8525
|
responseFormat: { type: "text" },
|
|
@@ -8354,7 +8533,7 @@ var text = () => ({
|
|
|
8354
8533
|
var object = ({
|
|
8355
8534
|
schema: inputSchema
|
|
8356
8535
|
}) => {
|
|
8357
|
-
const schema = (0,
|
|
8536
|
+
const schema = (0, import_provider_utils26.asSchema)(inputSchema);
|
|
8358
8537
|
return {
|
|
8359
8538
|
type: "object",
|
|
8360
8539
|
responseFormat: {
|
|
@@ -8380,7 +8559,7 @@ var object = ({
|
|
|
8380
8559
|
}
|
|
8381
8560
|
},
|
|
8382
8561
|
async parseOutput({ text: text2 }, context) {
|
|
8383
|
-
const parseResult = await (0,
|
|
8562
|
+
const parseResult = await (0, import_provider_utils26.safeParseJSON)({ text: text2 });
|
|
8384
8563
|
if (!parseResult.success) {
|
|
8385
8564
|
throw new NoObjectGeneratedError({
|
|
8386
8565
|
message: "No object generated: could not parse the response.",
|
|
@@ -8391,7 +8570,7 @@ var object = ({
|
|
|
8391
8570
|
finishReason: context.finishReason
|
|
8392
8571
|
});
|
|
8393
8572
|
}
|
|
8394
|
-
const validationResult = await (0,
|
|
8573
|
+
const validationResult = await (0, import_provider_utils26.safeValidateTypes)({
|
|
8395
8574
|
value: parseResult.value,
|
|
8396
8575
|
schema
|
|
8397
8576
|
});
|
|
@@ -8483,7 +8662,7 @@ function pruneMessages({
|
|
|
8483
8662
|
}
|
|
8484
8663
|
|
|
8485
8664
|
// src/generate-text/smooth-stream.ts
|
|
8486
|
-
var
|
|
8665
|
+
var import_provider_utils27 = require("@ai-sdk/provider-utils");
|
|
8487
8666
|
var import_provider25 = require("@ai-sdk/provider");
|
|
8488
8667
|
var CHUNKING_REGEXPS = {
|
|
8489
8668
|
word: /\S+\s+/m,
|
|
@@ -8492,7 +8671,7 @@ var CHUNKING_REGEXPS = {
|
|
|
8492
8671
|
function smoothStream({
|
|
8493
8672
|
delayInMs = 10,
|
|
8494
8673
|
chunking = "word",
|
|
8495
|
-
_internal: { delay: delay2 =
|
|
8674
|
+
_internal: { delay: delay2 = import_provider_utils27.delay } = {}
|
|
8496
8675
|
} = {}) {
|
|
8497
8676
|
let detectChunk;
|
|
8498
8677
|
if (typeof chunking === "function") {
|
|
@@ -9091,7 +9270,7 @@ var DefaultProviderRegistry = class {
|
|
|
9091
9270
|
};
|
|
9092
9271
|
|
|
9093
9272
|
// src/transcribe/transcribe.ts
|
|
9094
|
-
var
|
|
9273
|
+
var import_provider_utils28 = require("@ai-sdk/provider-utils");
|
|
9095
9274
|
|
|
9096
9275
|
// src/error/no-transcript-generated-error.ts
|
|
9097
9276
|
var import_provider29 = require("@ai-sdk/provider");
|
|
@@ -9127,7 +9306,7 @@ async function transcribe({
|
|
|
9127
9306
|
maxRetries: maxRetriesArg,
|
|
9128
9307
|
abortSignal
|
|
9129
9308
|
});
|
|
9130
|
-
const headersWithUserAgent = (0,
|
|
9309
|
+
const headersWithUserAgent = (0, import_provider_utils28.withUserAgentSuffix)(
|
|
9131
9310
|
headers != null ? headers : {},
|
|
9132
9311
|
`ai/${VERSION}`
|
|
9133
9312
|
);
|
|
@@ -9175,7 +9354,7 @@ var DefaultTranscriptionResult = class {
|
|
|
9175
9354
|
};
|
|
9176
9355
|
|
|
9177
9356
|
// src/ui/call-completion-api.ts
|
|
9178
|
-
var
|
|
9357
|
+
var import_provider_utils29 = require("@ai-sdk/provider-utils");
|
|
9179
9358
|
|
|
9180
9359
|
// src/ui/process-text-stream.ts
|
|
9181
9360
|
async function processTextStream({
|
|
@@ -9223,13 +9402,13 @@ async function callCompletionApi({
|
|
|
9223
9402
|
...body
|
|
9224
9403
|
}),
|
|
9225
9404
|
credentials,
|
|
9226
|
-
headers: (0,
|
|
9405
|
+
headers: (0, import_provider_utils29.withUserAgentSuffix)(
|
|
9227
9406
|
{
|
|
9228
9407
|
"Content-Type": "application/json",
|
|
9229
9408
|
...headers
|
|
9230
9409
|
},
|
|
9231
9410
|
`ai-sdk/${VERSION}`,
|
|
9232
|
-
(0,
|
|
9411
|
+
(0, import_provider_utils29.getRuntimeEnvironmentUserAgent)()
|
|
9233
9412
|
),
|
|
9234
9413
|
signal: abortController.signal
|
|
9235
9414
|
}).catch((err) => {
|
|
@@ -9257,7 +9436,7 @@ async function callCompletionApi({
|
|
|
9257
9436
|
}
|
|
9258
9437
|
case "data": {
|
|
9259
9438
|
await consumeStream({
|
|
9260
|
-
stream: (0,
|
|
9439
|
+
stream: (0, import_provider_utils29.parseJsonEventStream)({
|
|
9261
9440
|
stream: response.body,
|
|
9262
9441
|
schema: uiMessageChunkSchema
|
|
9263
9442
|
}).pipeThrough(
|
|
@@ -9309,7 +9488,7 @@ async function callCompletionApi({
|
|
|
9309
9488
|
}
|
|
9310
9489
|
|
|
9311
9490
|
// src/ui/chat.ts
|
|
9312
|
-
var
|
|
9491
|
+
var import_provider_utils32 = require("@ai-sdk/provider-utils");
|
|
9313
9492
|
|
|
9314
9493
|
// src/ui/convert-file-list-to-file-ui-parts.ts
|
|
9315
9494
|
async function convertFileListToFileUIParts(files) {
|
|
@@ -9342,10 +9521,10 @@ async function convertFileListToFileUIParts(files) {
|
|
|
9342
9521
|
}
|
|
9343
9522
|
|
|
9344
9523
|
// src/ui/default-chat-transport.ts
|
|
9345
|
-
var
|
|
9524
|
+
var import_provider_utils31 = require("@ai-sdk/provider-utils");
|
|
9346
9525
|
|
|
9347
9526
|
// src/ui/http-chat-transport.ts
|
|
9348
|
-
var
|
|
9527
|
+
var import_provider_utils30 = require("@ai-sdk/provider-utils");
|
|
9349
9528
|
var HttpChatTransport = class {
|
|
9350
9529
|
constructor({
|
|
9351
9530
|
api = "/api/chat",
|
|
@@ -9369,12 +9548,12 @@ var HttpChatTransport = class {
|
|
|
9369
9548
|
...options
|
|
9370
9549
|
}) {
|
|
9371
9550
|
var _a16, _b, _c, _d, _e;
|
|
9372
|
-
const resolvedBody = await (0,
|
|
9373
|
-
const resolvedHeaders = await (0,
|
|
9374
|
-
const resolvedCredentials = await (0,
|
|
9551
|
+
const resolvedBody = await (0, import_provider_utils30.resolve)(this.body);
|
|
9552
|
+
const resolvedHeaders = await (0, import_provider_utils30.resolve)(this.headers);
|
|
9553
|
+
const resolvedCredentials = await (0, import_provider_utils30.resolve)(this.credentials);
|
|
9375
9554
|
const baseHeaders = {
|
|
9376
|
-
...(0,
|
|
9377
|
-
...(0,
|
|
9555
|
+
...(0, import_provider_utils30.normalizeHeaders)(resolvedHeaders),
|
|
9556
|
+
...(0, import_provider_utils30.normalizeHeaders)(options.headers)
|
|
9378
9557
|
};
|
|
9379
9558
|
const preparedRequest = await ((_a16 = this.prepareSendMessagesRequest) == null ? void 0 : _a16.call(this, {
|
|
9380
9559
|
api: this.api,
|
|
@@ -9388,7 +9567,7 @@ var HttpChatTransport = class {
|
|
|
9388
9567
|
messageId: options.messageId
|
|
9389
9568
|
}));
|
|
9390
9569
|
const api = (_b = preparedRequest == null ? void 0 : preparedRequest.api) != null ? _b : this.api;
|
|
9391
|
-
const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? (0,
|
|
9570
|
+
const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? (0, import_provider_utils30.normalizeHeaders)(preparedRequest.headers) : baseHeaders;
|
|
9392
9571
|
const body = (preparedRequest == null ? void 0 : preparedRequest.body) !== void 0 ? preparedRequest.body : {
|
|
9393
9572
|
...resolvedBody,
|
|
9394
9573
|
...options.body,
|
|
@@ -9421,12 +9600,12 @@ var HttpChatTransport = class {
|
|
|
9421
9600
|
}
|
|
9422
9601
|
async reconnectToStream(options) {
|
|
9423
9602
|
var _a16, _b, _c, _d, _e;
|
|
9424
|
-
const resolvedBody = await (0,
|
|
9425
|
-
const resolvedHeaders = await (0,
|
|
9426
|
-
const resolvedCredentials = await (0,
|
|
9603
|
+
const resolvedBody = await (0, import_provider_utils30.resolve)(this.body);
|
|
9604
|
+
const resolvedHeaders = await (0, import_provider_utils30.resolve)(this.headers);
|
|
9605
|
+
const resolvedCredentials = await (0, import_provider_utils30.resolve)(this.credentials);
|
|
9427
9606
|
const baseHeaders = {
|
|
9428
|
-
...(0,
|
|
9429
|
-
...(0,
|
|
9607
|
+
...(0, import_provider_utils30.normalizeHeaders)(resolvedHeaders),
|
|
9608
|
+
...(0, import_provider_utils30.normalizeHeaders)(options.headers)
|
|
9430
9609
|
};
|
|
9431
9610
|
const preparedRequest = await ((_a16 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a16.call(this, {
|
|
9432
9611
|
api: this.api,
|
|
@@ -9437,7 +9616,7 @@ var HttpChatTransport = class {
|
|
|
9437
9616
|
requestMetadata: options.metadata
|
|
9438
9617
|
}));
|
|
9439
9618
|
const api = (_b = preparedRequest == null ? void 0 : preparedRequest.api) != null ? _b : `${this.api}/${options.chatId}/stream`;
|
|
9440
|
-
const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? (0,
|
|
9619
|
+
const headers = (preparedRequest == null ? void 0 : preparedRequest.headers) !== void 0 ? (0, import_provider_utils30.normalizeHeaders)(preparedRequest.headers) : baseHeaders;
|
|
9441
9620
|
const credentials = (_c = preparedRequest == null ? void 0 : preparedRequest.credentials) != null ? _c : resolvedCredentials;
|
|
9442
9621
|
const fetch2 = (_d = this.fetch) != null ? _d : globalThis.fetch;
|
|
9443
9622
|
const response = await fetch2(api, {
|
|
@@ -9467,7 +9646,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
|
|
|
9467
9646
|
super(options);
|
|
9468
9647
|
}
|
|
9469
9648
|
processResponseStream(stream) {
|
|
9470
|
-
return (0,
|
|
9649
|
+
return (0, import_provider_utils31.parseJsonEventStream)({
|
|
9471
9650
|
stream,
|
|
9472
9651
|
schema: uiMessageChunkSchema
|
|
9473
9652
|
}).pipeThrough(
|
|
@@ -9486,7 +9665,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
|
|
|
9486
9665
|
// src/ui/chat.ts
|
|
9487
9666
|
var AbstractChat = class {
|
|
9488
9667
|
constructor({
|
|
9489
|
-
generateId: generateId3 =
|
|
9668
|
+
generateId: generateId3 = import_provider_utils32.generateId,
|
|
9490
9669
|
id = generateId3(),
|
|
9491
9670
|
transport = new DefaultChatTransport(),
|
|
9492
9671
|
messageMetadataSchema,
|
|
@@ -9924,10 +10103,10 @@ var TextStreamChatTransport = class extends HttpChatTransport {
|
|
|
9924
10103
|
|
|
9925
10104
|
// src/ui/validate-ui-messages.ts
|
|
9926
10105
|
var import_provider30 = require("@ai-sdk/provider");
|
|
9927
|
-
var
|
|
10106
|
+
var import_provider_utils33 = require("@ai-sdk/provider-utils");
|
|
9928
10107
|
var import_v48 = require("zod/v4");
|
|
9929
|
-
var uiMessagesSchema = (0,
|
|
9930
|
-
() => (0,
|
|
10108
|
+
var uiMessagesSchema = (0, import_provider_utils33.lazyValidator)(
|
|
10109
|
+
() => (0, import_provider_utils33.zodSchema)(
|
|
9931
10110
|
import_v48.z.array(
|
|
9932
10111
|
import_v48.z.object({
|
|
9933
10112
|
id: import_v48.z.string(),
|
|
@@ -10154,13 +10333,13 @@ async function safeValidateUIMessages({
|
|
|
10154
10333
|
})
|
|
10155
10334
|
};
|
|
10156
10335
|
}
|
|
10157
|
-
const validatedMessages = await (0,
|
|
10336
|
+
const validatedMessages = await (0, import_provider_utils33.validateTypes)({
|
|
10158
10337
|
value: messages,
|
|
10159
10338
|
schema: uiMessagesSchema
|
|
10160
10339
|
});
|
|
10161
10340
|
if (metadataSchema) {
|
|
10162
10341
|
for (const message of validatedMessages) {
|
|
10163
|
-
await (0,
|
|
10342
|
+
await (0, import_provider_utils33.validateTypes)({
|
|
10164
10343
|
value: message.metadata,
|
|
10165
10344
|
schema: metadataSchema
|
|
10166
10345
|
});
|
|
@@ -10183,7 +10362,7 @@ async function safeValidateUIMessages({
|
|
|
10183
10362
|
})
|
|
10184
10363
|
};
|
|
10185
10364
|
}
|
|
10186
|
-
await (0,
|
|
10365
|
+
await (0, import_provider_utils33.validateTypes)({
|
|
10187
10366
|
value: dataPart.data,
|
|
10188
10367
|
schema: dataSchema
|
|
10189
10368
|
});
|
|
@@ -10208,13 +10387,13 @@ async function safeValidateUIMessages({
|
|
|
10208
10387
|
};
|
|
10209
10388
|
}
|
|
10210
10389
|
if (toolPart.state === "input-available") {
|
|
10211
|
-
await (0,
|
|
10390
|
+
await (0, import_provider_utils33.validateTypes)({
|
|
10212
10391
|
value: toolPart.input,
|
|
10213
10392
|
schema: tool2.inputSchema
|
|
10214
10393
|
});
|
|
10215
10394
|
}
|
|
10216
10395
|
if (toolPart.state === "output-available" && tool2.outputSchema) {
|
|
10217
|
-
await (0,
|
|
10396
|
+
await (0, import_provider_utils33.validateTypes)({
|
|
10218
10397
|
value: toolPart.output,
|
|
10219
10398
|
schema: tool2.outputSchema
|
|
10220
10399
|
});
|
|
@@ -10252,17 +10431,18 @@ async function validateUIMessages({
|
|
|
10252
10431
|
}
|
|
10253
10432
|
|
|
10254
10433
|
// src/ui-message-stream/create-ui-message-stream.ts
|
|
10255
|
-
var
|
|
10434
|
+
var import_provider_utils34 = require("@ai-sdk/provider-utils");
|
|
10256
10435
|
function createUIMessageStream({
|
|
10257
10436
|
execute,
|
|
10258
10437
|
onError = () => "An error occurred.",
|
|
10259
10438
|
// prevent leaking server error details to the client by default
|
|
10260
10439
|
originalMessages,
|
|
10261
10440
|
onFinish,
|
|
10262
|
-
generateId: generateId3 =
|
|
10441
|
+
generateId: generateId3 = import_provider_utils34.generateId
|
|
10263
10442
|
}) {
|
|
10264
10443
|
let controller;
|
|
10265
10444
|
const ongoingStreamPromises = [];
|
|
10445
|
+
let outcome = { status: "unknown" };
|
|
10266
10446
|
const stream = new ReadableStream({
|
|
10267
10447
|
start(controllerArg) {
|
|
10268
10448
|
controller = controllerArg;
|
|
@@ -10274,6 +10454,35 @@ function createUIMessageStream({
|
|
|
10274
10454
|
} catch (error) {
|
|
10275
10455
|
}
|
|
10276
10456
|
}
|
|
10457
|
+
function setOutcome(newOutcome) {
|
|
10458
|
+
if (outcome.status === "unknown" && newOutcome.status !== "unknown") {
|
|
10459
|
+
outcome = newOutcome;
|
|
10460
|
+
}
|
|
10461
|
+
}
|
|
10462
|
+
function failOutcome(error) {
|
|
10463
|
+
outcome = { status: "failed", error };
|
|
10464
|
+
}
|
|
10465
|
+
function safeError(error) {
|
|
10466
|
+
try {
|
|
10467
|
+
controller.error(error);
|
|
10468
|
+
} catch (e) {
|
|
10469
|
+
}
|
|
10470
|
+
}
|
|
10471
|
+
function handleError(error) {
|
|
10472
|
+
failOutcome(error);
|
|
10473
|
+
let errorText;
|
|
10474
|
+
try {
|
|
10475
|
+
errorText = onError(error);
|
|
10476
|
+
} catch (onErrorError) {
|
|
10477
|
+
failOutcome(onErrorError);
|
|
10478
|
+
safeError(onErrorError);
|
|
10479
|
+
return;
|
|
10480
|
+
}
|
|
10481
|
+
safeEnqueue({
|
|
10482
|
+
type: "error",
|
|
10483
|
+
errorText
|
|
10484
|
+
});
|
|
10485
|
+
}
|
|
10277
10486
|
try {
|
|
10278
10487
|
const result = execute({
|
|
10279
10488
|
writer: {
|
|
@@ -10291,38 +10500,29 @@ function createUIMessageStream({
|
|
|
10291
10500
|
safeEnqueue(value);
|
|
10292
10501
|
}
|
|
10293
10502
|
})().catch((error) => {
|
|
10294
|
-
|
|
10295
|
-
type: "error",
|
|
10296
|
-
errorText: onError(error)
|
|
10297
|
-
});
|
|
10503
|
+
handleError(error);
|
|
10298
10504
|
})
|
|
10299
10505
|
);
|
|
10300
10506
|
},
|
|
10507
|
+
setOutcome,
|
|
10301
10508
|
onError
|
|
10302
10509
|
}
|
|
10303
10510
|
});
|
|
10304
10511
|
if (result) {
|
|
10305
10512
|
ongoingStreamPromises.push(
|
|
10306
10513
|
result.catch((error) => {
|
|
10307
|
-
|
|
10308
|
-
type: "error",
|
|
10309
|
-
errorText: onError(error)
|
|
10310
|
-
});
|
|
10514
|
+
handleError(error);
|
|
10311
10515
|
})
|
|
10312
10516
|
);
|
|
10313
10517
|
}
|
|
10314
10518
|
} catch (error) {
|
|
10315
|
-
|
|
10316
|
-
type: "error",
|
|
10317
|
-
errorText: onError(error)
|
|
10318
|
-
});
|
|
10519
|
+
handleError(error);
|
|
10319
10520
|
}
|
|
10320
|
-
const waitForStreams =
|
|
10521
|
+
const waitForStreams = (async () => {
|
|
10321
10522
|
while (ongoingStreamPromises.length > 0) {
|
|
10322
10523
|
await ongoingStreamPromises.shift();
|
|
10323
10524
|
}
|
|
10324
|
-
|
|
10325
|
-
});
|
|
10525
|
+
})();
|
|
10326
10526
|
waitForStreams.finally(() => {
|
|
10327
10527
|
try {
|
|
10328
10528
|
controller.close();
|
|
@@ -10334,7 +10534,8 @@ function createUIMessageStream({
|
|
|
10334
10534
|
messageId: generateId3(),
|
|
10335
10535
|
originalMessages,
|
|
10336
10536
|
onFinish,
|
|
10337
|
-
onError
|
|
10537
|
+
onError,
|
|
10538
|
+
getOutcome: () => outcome
|
|
10338
10539
|
});
|
|
10339
10540
|
}
|
|
10340
10541
|
|