ai 7.0.99 → 7.0.100
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 +8 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +76 -21
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.js.map +1 -1
- package/docs/02-getting-started/07-expo.mdx +7 -0
- package/docs/03-ai-sdk-core/55-testing.mdx +75 -0
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +28 -2
- package/docs/07-reference/05-ai-sdk-errors/ai-api-call-error.mdx +4 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-ui-message-stream-error.mdx +6 -2
- package/package.json +2 -2
- package/src/error/ui-message-stream-error.ts +5 -2
- package/src/ui/call-completion-api.ts +22 -6
- package/src/ui/chat.ts +16 -5
- package/src/ui/convert-file-list-to-file-ui-parts.ts +5 -1
- package/src/ui/create-ui-api-call-error.ts +23 -0
- package/src/ui/http-chat-transport.ts +18 -8
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -7519,9 +7519,11 @@ declare class UnsupportedModelVersionError extends AISDKError {
|
|
|
7519
7519
|
|
|
7520
7520
|
declare const symbol$5: unique symbol;
|
|
7521
7521
|
/**
|
|
7522
|
-
* Error thrown when a UI message stream
|
|
7522
|
+
* Error thrown when a UI message stream reports an error or contains invalid
|
|
7523
|
+
* or out-of-sequence chunks.
|
|
7523
7524
|
*
|
|
7524
7525
|
* This typically occurs when:
|
|
7526
|
+
* - An error chunk is received
|
|
7525
7527
|
* - A delta chunk is received without a corresponding start chunk
|
|
7526
7528
|
* - An end chunk is received without a corresponding start chunk
|
|
7527
7529
|
* - A tool invocation is not found for the given toolCallId
|
|
@@ -7535,7 +7537,8 @@ declare class UIMessageStreamError extends AISDKError {
|
|
|
7535
7537
|
*/
|
|
7536
7538
|
readonly chunkType: string;
|
|
7537
7539
|
/**
|
|
7538
|
-
* The ID associated with the failing chunk (part ID or toolCallId)
|
|
7540
|
+
* The ID associated with the failing chunk (part ID or toolCallId), or an
|
|
7541
|
+
* empty string when the chunk does not have an ID.
|
|
7539
7542
|
*/
|
|
7540
7543
|
readonly chunkId: string;
|
|
7541
7544
|
constructor({ chunkType, chunkId, message, }: {
|
package/dist/index.js
CHANGED
|
@@ -1178,7 +1178,7 @@ import {
|
|
|
1178
1178
|
} from "@ai-sdk/provider-utils";
|
|
1179
1179
|
|
|
1180
1180
|
// src/version.ts
|
|
1181
|
-
var VERSION = true ? "7.0.
|
|
1181
|
+
var VERSION = true ? "7.0.100" : "0.0.0-test";
|
|
1182
1182
|
|
|
1183
1183
|
// src/util/download/download.ts
|
|
1184
1184
|
var download = async ({
|
|
@@ -18974,6 +18974,26 @@ import {
|
|
|
18974
18974
|
withUserAgentSuffix as withUserAgentSuffix16,
|
|
18975
18975
|
getRuntimeEnvironmentUserAgent as getRuntimeEnvironmentUserAgent2
|
|
18976
18976
|
} from "@ai-sdk/provider-utils";
|
|
18977
|
+
import { EmptyResponseBodyError as EmptyResponseBodyError2 } from "@ai-sdk/provider";
|
|
18978
|
+
|
|
18979
|
+
// src/ui/create-ui-api-call-error.ts
|
|
18980
|
+
import { APICallError as APICallError3 } from "@ai-sdk/provider";
|
|
18981
|
+
async function createUIApiCallError({
|
|
18982
|
+
response,
|
|
18983
|
+
url,
|
|
18984
|
+
fallbackMessage
|
|
18985
|
+
}) {
|
|
18986
|
+
const responseBody = await response.text();
|
|
18987
|
+
return new APICallError3({
|
|
18988
|
+
message: responseBody || fallbackMessage,
|
|
18989
|
+
url,
|
|
18990
|
+
// UI requests can contain prompts, messages, and other sensitive values.
|
|
18991
|
+
// Keep them out of client-facing error objects.
|
|
18992
|
+
requestBodyValues: void 0,
|
|
18993
|
+
statusCode: response.status,
|
|
18994
|
+
responseBody
|
|
18995
|
+
});
|
|
18996
|
+
}
|
|
18977
18997
|
|
|
18978
18998
|
// src/ui/process-text-stream.ts
|
|
18979
18999
|
async function processTextStream({
|
|
@@ -19033,12 +19053,16 @@ async function callCompletionApi({
|
|
|
19033
19053
|
throw err;
|
|
19034
19054
|
});
|
|
19035
19055
|
if (!response.ok) {
|
|
19036
|
-
throw
|
|
19037
|
-
|
|
19038
|
-
|
|
19056
|
+
throw await createUIApiCallError({
|
|
19057
|
+
response,
|
|
19058
|
+
url: api,
|
|
19059
|
+
fallbackMessage: "Failed to fetch the chat response."
|
|
19060
|
+
});
|
|
19039
19061
|
}
|
|
19040
19062
|
if (!response.body) {
|
|
19041
|
-
throw new
|
|
19063
|
+
throw new EmptyResponseBodyError2({
|
|
19064
|
+
message: "The response body is empty."
|
|
19065
|
+
});
|
|
19042
19066
|
}
|
|
19043
19067
|
let result = "";
|
|
19044
19068
|
switch (streamProtocol) {
|
|
@@ -19068,7 +19092,11 @@ async function callCompletionApi({
|
|
|
19068
19092
|
result += streamPart.delta;
|
|
19069
19093
|
setCompletion(result);
|
|
19070
19094
|
} else if (streamPart.type === "error") {
|
|
19071
|
-
throw new
|
|
19095
|
+
throw new UIMessageStreamError({
|
|
19096
|
+
chunkType: "error",
|
|
19097
|
+
chunkId: "",
|
|
19098
|
+
message: streamPart.errorText
|
|
19099
|
+
});
|
|
19072
19100
|
}
|
|
19073
19101
|
}
|
|
19074
19102
|
})
|
|
@@ -19081,7 +19109,11 @@ async function callCompletionApi({
|
|
|
19081
19109
|
}
|
|
19082
19110
|
default: {
|
|
19083
19111
|
const exhaustiveCheck = streamProtocol;
|
|
19084
|
-
throw new
|
|
19112
|
+
throw new InvalidArgumentError({
|
|
19113
|
+
parameter: "streamProtocol",
|
|
19114
|
+
value: exhaustiveCheck,
|
|
19115
|
+
message: `Unknown stream protocol: ${exhaustiveCheck}`
|
|
19116
|
+
});
|
|
19085
19117
|
}
|
|
19086
19118
|
}
|
|
19087
19119
|
if (onFinish) {
|
|
@@ -19111,12 +19143,16 @@ import {
|
|
|
19111
19143
|
} from "@ai-sdk/provider-utils";
|
|
19112
19144
|
|
|
19113
19145
|
// src/ui/convert-file-list-to-file-ui-parts.ts
|
|
19146
|
+
import { UnsupportedFunctionalityError as UnsupportedFunctionalityError6 } from "@ai-sdk/provider";
|
|
19114
19147
|
async function convertFileListToFileUIParts(files) {
|
|
19115
19148
|
if (files == null) {
|
|
19116
19149
|
return [];
|
|
19117
19150
|
}
|
|
19118
19151
|
if (!globalThis.FileList || !(files instanceof globalThis.FileList)) {
|
|
19119
|
-
throw new
|
|
19152
|
+
throw new UnsupportedFunctionalityError6({
|
|
19153
|
+
functionality: "FileList",
|
|
19154
|
+
message: "FileList is not supported in the current environment"
|
|
19155
|
+
});
|
|
19120
19156
|
}
|
|
19121
19157
|
return Promise.all(
|
|
19122
19158
|
Array.from(files).map(async (file) => {
|
|
@@ -19148,6 +19184,7 @@ import {
|
|
|
19148
19184
|
normalizeHeaders,
|
|
19149
19185
|
resolve as resolve2
|
|
19150
19186
|
} from "@ai-sdk/provider-utils";
|
|
19187
|
+
import { EmptyResponseBodyError as EmptyResponseBodyError3 } from "@ai-sdk/provider";
|
|
19151
19188
|
var HttpChatTransport = class {
|
|
19152
19189
|
constructor({
|
|
19153
19190
|
api = "/api/chat",
|
|
@@ -19212,12 +19249,16 @@ var HttpChatTransport = class {
|
|
|
19212
19249
|
signal: abortSignal
|
|
19213
19250
|
});
|
|
19214
19251
|
if (!response.ok) {
|
|
19215
|
-
throw
|
|
19216
|
-
|
|
19217
|
-
|
|
19252
|
+
throw await createUIApiCallError({
|
|
19253
|
+
response,
|
|
19254
|
+
url: api,
|
|
19255
|
+
fallbackMessage: "Failed to fetch the chat response."
|
|
19256
|
+
});
|
|
19218
19257
|
}
|
|
19219
19258
|
if (!response.body) {
|
|
19220
|
-
throw new
|
|
19259
|
+
throw new EmptyResponseBodyError3({
|
|
19260
|
+
message: "The response body is empty."
|
|
19261
|
+
});
|
|
19221
19262
|
}
|
|
19222
19263
|
return this.processResponseStream(response.body);
|
|
19223
19264
|
}
|
|
@@ -19252,12 +19293,16 @@ var HttpChatTransport = class {
|
|
|
19252
19293
|
return null;
|
|
19253
19294
|
}
|
|
19254
19295
|
if (!response.ok) {
|
|
19255
|
-
throw
|
|
19256
|
-
|
|
19257
|
-
|
|
19296
|
+
throw await createUIApiCallError({
|
|
19297
|
+
response,
|
|
19298
|
+
url: api,
|
|
19299
|
+
fallbackMessage: "Failed to fetch the chat response."
|
|
19300
|
+
});
|
|
19258
19301
|
}
|
|
19259
19302
|
if (!response.body) {
|
|
19260
|
-
throw new
|
|
19303
|
+
throw new EmptyResponseBodyError3({
|
|
19304
|
+
message: "The response body is empty."
|
|
19305
|
+
});
|
|
19261
19306
|
}
|
|
19262
19307
|
return this.processResponseStream(response.body);
|
|
19263
19308
|
}
|
|
@@ -19347,12 +19392,18 @@ var AbstractChat = class {
|
|
|
19347
19392
|
(m) => m.id === message.messageId
|
|
19348
19393
|
);
|
|
19349
19394
|
if (messageIndex === -1) {
|
|
19350
|
-
throw new
|
|
19395
|
+
throw new InvalidArgumentError({
|
|
19396
|
+
parameter: "message.messageId",
|
|
19397
|
+
value: message.messageId,
|
|
19398
|
+
message: `message with id ${message.messageId} not found`
|
|
19399
|
+
});
|
|
19351
19400
|
}
|
|
19352
19401
|
if (this.state.messages[messageIndex].role !== "user") {
|
|
19353
|
-
throw new
|
|
19354
|
-
|
|
19355
|
-
|
|
19402
|
+
throw new InvalidArgumentError({
|
|
19403
|
+
parameter: "message.messageId",
|
|
19404
|
+
value: message.messageId,
|
|
19405
|
+
message: `message with id ${message.messageId} is not a user message`
|
|
19406
|
+
});
|
|
19356
19407
|
}
|
|
19357
19408
|
this.state.messages = this.state.messages.slice(0, messageIndex + 1);
|
|
19358
19409
|
this.state.replaceMessage(messageIndex, {
|
|
@@ -19385,7 +19436,11 @@ var AbstractChat = class {
|
|
|
19385
19436
|
} = {}) => {
|
|
19386
19437
|
const messageIndex = messageId == null ? this.state.messages.length - 1 : this.state.messages.findIndex((message) => message.id === messageId);
|
|
19387
19438
|
if (messageIndex === -1) {
|
|
19388
|
-
throw new
|
|
19439
|
+
throw new InvalidArgumentError({
|
|
19440
|
+
parameter: "messageId",
|
|
19441
|
+
value: messageId,
|
|
19442
|
+
message: `message ${messageId} not found`
|
|
19443
|
+
});
|
|
19389
19444
|
}
|
|
19390
19445
|
this.state.messages = this.state.messages.slice(
|
|
19391
19446
|
0,
|