ai 3.0.20 → 3.0.21
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/anthropic/dist/index.d.mts +1 -353
- package/anthropic/dist/index.d.ts +1 -353
- package/anthropic/dist/index.js +30 -188
- package/anthropic/dist/index.js.map +1 -1
- package/anthropic/dist/index.mjs +18 -172
- package/anthropic/dist/index.mjs.map +1 -1
- package/dist/index.d.mts +7 -353
- package/dist/index.d.ts +7 -353
- package/dist/index.js +98 -324
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -296
- package/dist/index.mjs.map +1 -1
- package/google/dist/index.d.mts +1 -353
- package/google/dist/index.d.ts +1 -353
- package/google/dist/index.js +31 -189
- package/google/dist/index.js.map +1 -1
- package/google/dist/index.mjs +19 -173
- package/google/dist/index.mjs.map +1 -1
- package/mistral/dist/index.d.mts +1 -353
- package/mistral/dist/index.d.ts +1 -353
- package/mistral/dist/index.js +29 -187
- package/mistral/dist/index.js.map +1 -1
- package/mistral/dist/index.mjs +17 -171
- package/mistral/dist/index.mjs.map +1 -1
- package/openai/dist/index.d.mts +2 -354
- package/openai/dist/index.d.ts +2 -354
- package/openai/dist/index.js +64 -255
- package/openai/dist/index.js.map +1 -1
- package/openai/dist/index.mjs +52 -235
- package/openai/dist/index.mjs.map +1 -1
- package/package.json +4 -10
- package/react/dist/index.d.mts +1 -1
- package/react/dist/index.d.ts +1 -1
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs.map +1 -1
- package/solid/dist/index.d.mts +1 -1
- package/solid/dist/index.d.ts +1 -1
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs.map +1 -1
- package/svelte/dist/index.d.mts +1 -1
- package/svelte/dist/index.d.ts +1 -1
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs.map +1 -1
- package/vue/dist/index.d.mts +1 -1
- package/vue/dist/index.d.ts +1 -1
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs.map +1 -1
- package/spec/dist/index.d.mts +0 -780
- package/spec/dist/index.d.ts +0 -780
- package/spec/dist/index.js +0 -863
- package/spec/dist/index.js.map +0 -1
- package/spec/dist/index.mjs +0 -797
- package/spec/dist/index.mjs.map +0 -1
package/openai/dist/index.mjs
CHANGED
@@ -1,90 +1,3 @@
|
|
1
|
-
// spec/errors/api-call-error.ts
|
2
|
-
var APICallError = class extends Error {
|
3
|
-
constructor({
|
4
|
-
message,
|
5
|
-
url,
|
6
|
-
requestBodyValues,
|
7
|
-
statusCode,
|
8
|
-
responseBody,
|
9
|
-
cause,
|
10
|
-
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
11
|
-
statusCode === 409 || // conflict
|
12
|
-
statusCode === 429 || // too many requests
|
13
|
-
statusCode >= 500),
|
14
|
-
// server error
|
15
|
-
data
|
16
|
-
}) {
|
17
|
-
super(message);
|
18
|
-
this.name = "AI_APICallError";
|
19
|
-
this.url = url;
|
20
|
-
this.requestBodyValues = requestBodyValues;
|
21
|
-
this.statusCode = statusCode;
|
22
|
-
this.responseBody = responseBody;
|
23
|
-
this.cause = cause;
|
24
|
-
this.isRetryable = isRetryable;
|
25
|
-
this.data = data;
|
26
|
-
}
|
27
|
-
static isAPICallError(error) {
|
28
|
-
return error instanceof Error && error.name === "AI_APICallError" && typeof error.url === "string" && typeof error.requestBodyValues === "object" && (error.statusCode == null || typeof error.statusCode === "number") && (error.responseBody == null || typeof error.responseBody === "string") && (error.cause == null || typeof error.cause === "object") && typeof error.isRetryable === "boolean" && (error.data == null || typeof error.data === "object");
|
29
|
-
}
|
30
|
-
toJSON() {
|
31
|
-
return {
|
32
|
-
name: this.name,
|
33
|
-
message: this.message,
|
34
|
-
url: this.url,
|
35
|
-
requestBodyValues: this.requestBodyValues,
|
36
|
-
statusCode: this.statusCode,
|
37
|
-
responseBody: this.responseBody,
|
38
|
-
cause: this.cause,
|
39
|
-
isRetryable: this.isRetryable,
|
40
|
-
data: this.data
|
41
|
-
};
|
42
|
-
}
|
43
|
-
};
|
44
|
-
|
45
|
-
// spec/errors/invalid-prompt-error.ts
|
46
|
-
var InvalidPromptError = class extends Error {
|
47
|
-
constructor({ prompt: prompt2, message }) {
|
48
|
-
super(`Invalid prompt: ${message}`);
|
49
|
-
this.name = "AI_InvalidPromptError";
|
50
|
-
this.prompt = prompt2;
|
51
|
-
}
|
52
|
-
static isInvalidPromptError(error) {
|
53
|
-
return error instanceof Error && error.name === "AI_InvalidPromptError" && prompt != null;
|
54
|
-
}
|
55
|
-
toJSON() {
|
56
|
-
return {
|
57
|
-
name: this.name,
|
58
|
-
message: this.message,
|
59
|
-
stack: this.stack,
|
60
|
-
prompt: this.prompt
|
61
|
-
};
|
62
|
-
}
|
63
|
-
};
|
64
|
-
|
65
|
-
// spec/errors/invalid-response-data-error.ts
|
66
|
-
var InvalidResponseDataError = class extends Error {
|
67
|
-
constructor({
|
68
|
-
data,
|
69
|
-
message = `Invalid response data: ${JSON.stringify(data)}.`
|
70
|
-
}) {
|
71
|
-
super(message);
|
72
|
-
this.name = "AI_InvalidResponseDataError";
|
73
|
-
this.data = data;
|
74
|
-
}
|
75
|
-
static isInvalidResponseDataError(error) {
|
76
|
-
return error instanceof Error && error.name === "AI_InvalidResponseDataError" && error.data != null;
|
77
|
-
}
|
78
|
-
toJSON() {
|
79
|
-
return {
|
80
|
-
name: this.name,
|
81
|
-
message: this.message,
|
82
|
-
stack: this.stack,
|
83
|
-
data: this.data
|
84
|
-
};
|
85
|
-
}
|
86
|
-
};
|
87
|
-
|
88
1
|
// spec/util/generate-id.ts
|
89
2
|
import { customAlphabet } from "nanoid/non-secure";
|
90
3
|
var generateId = customAlphabet(
|
@@ -92,38 +5,8 @@ var generateId = customAlphabet(
|
|
92
5
|
7
|
93
6
|
);
|
94
7
|
|
95
|
-
// spec/util/get-error-message.ts
|
96
|
-
function getErrorMessage(error) {
|
97
|
-
if (error == null) {
|
98
|
-
return "unknown error";
|
99
|
-
}
|
100
|
-
if (typeof error === "string") {
|
101
|
-
return error;
|
102
|
-
}
|
103
|
-
if (error instanceof Error) {
|
104
|
-
return error.message;
|
105
|
-
}
|
106
|
-
return JSON.stringify(error);
|
107
|
-
}
|
108
|
-
|
109
|
-
// spec/errors/load-api-key-error.ts
|
110
|
-
var LoadAPIKeyError = class extends Error {
|
111
|
-
constructor({ message }) {
|
112
|
-
super(message);
|
113
|
-
this.name = "AI_LoadAPIKeyError";
|
114
|
-
}
|
115
|
-
static isLoadAPIKeyError(error) {
|
116
|
-
return error instanceof Error && error.name === "AI_LoadAPIKeyError";
|
117
|
-
}
|
118
|
-
toJSON() {
|
119
|
-
return {
|
120
|
-
name: this.name,
|
121
|
-
message: this.message
|
122
|
-
};
|
123
|
-
}
|
124
|
-
};
|
125
|
-
|
126
8
|
// spec/util/load-api-key.ts
|
9
|
+
import { LoadAPIKeyError } from "@ai-sdk/provider";
|
127
10
|
function loadApiKey({
|
128
11
|
apiKey,
|
129
12
|
environmentVariableName,
|
@@ -158,59 +41,11 @@ function loadApiKey({
|
|
158
41
|
}
|
159
42
|
|
160
43
|
// spec/util/parse-json.ts
|
44
|
+
import { JSONParseError, TypeValidationError as TypeValidationError2 } from "@ai-sdk/provider";
|
161
45
|
import SecureJSON from "secure-json-parse";
|
162
46
|
|
163
|
-
// spec/errors/json-parse-error.ts
|
164
|
-
var JSONParseError = class extends Error {
|
165
|
-
constructor({ text, cause }) {
|
166
|
-
super(
|
167
|
-
`JSON parsing failed: Text: ${text}.
|
168
|
-
Error message: ${getErrorMessage(cause)}`
|
169
|
-
);
|
170
|
-
this.name = "AI_JSONParseError";
|
171
|
-
this.cause = cause;
|
172
|
-
this.text = text;
|
173
|
-
}
|
174
|
-
static isJSONParseError(error) {
|
175
|
-
return error instanceof Error && error.name === "AI_JSONParseError" && typeof error.text === "string" && typeof error.cause === "string";
|
176
|
-
}
|
177
|
-
toJSON() {
|
178
|
-
return {
|
179
|
-
name: this.name,
|
180
|
-
message: this.message,
|
181
|
-
cause: this.cause,
|
182
|
-
stack: this.stack,
|
183
|
-
valueText: this.text
|
184
|
-
};
|
185
|
-
}
|
186
|
-
};
|
187
|
-
|
188
|
-
// spec/errors/type-validation-error.ts
|
189
|
-
var TypeValidationError = class extends Error {
|
190
|
-
constructor({ value, cause }) {
|
191
|
-
super(
|
192
|
-
`Type validation failed: Value: ${JSON.stringify(value)}.
|
193
|
-
Error message: ${getErrorMessage(cause)}`
|
194
|
-
);
|
195
|
-
this.name = "AI_TypeValidationError";
|
196
|
-
this.cause = cause;
|
197
|
-
this.value = value;
|
198
|
-
}
|
199
|
-
static isTypeValidationError(error) {
|
200
|
-
return error instanceof Error && error.name === "AI_TypeValidationError" && typeof error.value === "string" && typeof error.cause === "string";
|
201
|
-
}
|
202
|
-
toJSON() {
|
203
|
-
return {
|
204
|
-
name: this.name,
|
205
|
-
message: this.message,
|
206
|
-
cause: this.cause,
|
207
|
-
stack: this.stack,
|
208
|
-
value: this.value
|
209
|
-
};
|
210
|
-
}
|
211
|
-
};
|
212
|
-
|
213
47
|
// spec/util/validate-types.ts
|
48
|
+
import { TypeValidationError } from "@ai-sdk/provider";
|
214
49
|
function validateTypes({
|
215
50
|
value,
|
216
51
|
schema
|
@@ -260,7 +95,7 @@ function parseJSON({
|
|
260
95
|
}
|
261
96
|
return validateTypes({ value, schema });
|
262
97
|
} catch (error) {
|
263
|
-
if (JSONParseError.isJSONParseError(error) ||
|
98
|
+
if (JSONParseError.isJSONParseError(error) || TypeValidationError2.isTypeValidationError(error)) {
|
264
99
|
throw error;
|
265
100
|
}
|
266
101
|
throw new JSONParseError({ text, cause: error });
|
@@ -296,6 +131,7 @@ function isParseableJson(input) {
|
|
296
131
|
}
|
297
132
|
|
298
133
|
// spec/util/post-to-api.ts
|
134
|
+
import { APICallError } from "@ai-sdk/provider";
|
299
135
|
var postJsonToApi = async ({
|
300
136
|
url,
|
301
137
|
headers,
|
@@ -401,29 +237,10 @@ var postToApi = async ({
|
|
401
237
|
};
|
402
238
|
|
403
239
|
// spec/util/response-handler.ts
|
240
|
+
import { APICallError as APICallError2, NoResponseBodyError } from "@ai-sdk/provider";
|
404
241
|
import {
|
405
242
|
EventSourceParserStream
|
406
243
|
} from "eventsource-parser/stream";
|
407
|
-
|
408
|
-
// spec/errors/no-response-body-error.ts
|
409
|
-
var NoResponseBodyError = class extends Error {
|
410
|
-
constructor({ message = "No response body" } = {}) {
|
411
|
-
super(message);
|
412
|
-
this.name = "AI_NoResponseBodyError";
|
413
|
-
}
|
414
|
-
static isNoResponseBodyError(error) {
|
415
|
-
return error instanceof Error && error.name === "AI_NoResponseBodyError";
|
416
|
-
}
|
417
|
-
toJSON() {
|
418
|
-
return {
|
419
|
-
name: this.name,
|
420
|
-
message: this.message,
|
421
|
-
stack: this.stack
|
422
|
-
};
|
423
|
-
}
|
424
|
-
};
|
425
|
-
|
426
|
-
// spec/util/response-handler.ts
|
427
244
|
var createJsonErrorResponseHandler = ({
|
428
245
|
errorSchema,
|
429
246
|
errorToMessage,
|
@@ -431,7 +248,7 @@ var createJsonErrorResponseHandler = ({
|
|
431
248
|
}) => async ({ response, url, requestBodyValues }) => {
|
432
249
|
const responseBody = await response.text();
|
433
250
|
if (responseBody.trim() === "") {
|
434
|
-
return new
|
251
|
+
return new APICallError2({
|
435
252
|
message: response.statusText,
|
436
253
|
url,
|
437
254
|
requestBodyValues,
|
@@ -445,7 +262,7 @@ var createJsonErrorResponseHandler = ({
|
|
445
262
|
text: responseBody,
|
446
263
|
schema: errorSchema
|
447
264
|
});
|
448
|
-
return new
|
265
|
+
return new APICallError2({
|
449
266
|
message: errorToMessage(parsedError),
|
450
267
|
url,
|
451
268
|
requestBodyValues,
|
@@ -455,7 +272,7 @@ var createJsonErrorResponseHandler = ({
|
|
455
272
|
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
456
273
|
});
|
457
274
|
} catch (parseError) {
|
458
|
-
return new
|
275
|
+
return new APICallError2({
|
459
276
|
message: response.statusText,
|
460
277
|
url,
|
461
278
|
requestBodyValues,
|
@@ -492,7 +309,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
492
309
|
schema: responseSchema
|
493
310
|
});
|
494
311
|
if (!parsedResult.success) {
|
495
|
-
throw new
|
312
|
+
throw new APICallError2({
|
496
313
|
message: "Invalid JSON response",
|
497
314
|
cause: parsedResult.error,
|
498
315
|
statusCode: response.status,
|
@@ -529,33 +346,17 @@ function convertUint8ArrayToBase64(array) {
|
|
529
346
|
return globalThis.btoa(latin1string);
|
530
347
|
}
|
531
348
|
|
532
|
-
// spec/errors/unsupported-functionality-error.ts
|
533
|
-
var UnsupportedFunctionalityError = class extends Error {
|
534
|
-
constructor({ functionality }) {
|
535
|
-
super(`'${functionality}' functionality not supported.`);
|
536
|
-
this.name = "AI_UnsupportedFunctionalityError";
|
537
|
-
this.functionality = functionality;
|
538
|
-
}
|
539
|
-
static isUnsupportedFunctionalityError(error) {
|
540
|
-
return error instanceof Error && error.name === "AI_UnsupportedFunctionalityError" && typeof error.functionality === "string";
|
541
|
-
}
|
542
|
-
toJSON() {
|
543
|
-
return {
|
544
|
-
name: this.name,
|
545
|
-
message: this.message,
|
546
|
-
stack: this.stack,
|
547
|
-
functionality: this.functionality
|
548
|
-
};
|
549
|
-
}
|
550
|
-
};
|
551
|
-
|
552
349
|
// openai/openai-chat-language-model.ts
|
350
|
+
import {
|
351
|
+
InvalidResponseDataError,
|
352
|
+
UnsupportedFunctionalityError
|
353
|
+
} from "@ai-sdk/provider";
|
553
354
|
import { z as z2 } from "zod";
|
554
355
|
|
555
356
|
// openai/convert-to-openai-chat-messages.ts
|
556
|
-
function convertToOpenAIChatMessages(
|
357
|
+
function convertToOpenAIChatMessages(prompt) {
|
557
358
|
const messages = [];
|
558
|
-
for (const { role, content } of
|
359
|
+
for (const { role, content } of prompt) {
|
559
360
|
switch (role) {
|
560
361
|
case "system": {
|
561
362
|
messages.push({ role: "system", content });
|
@@ -681,7 +482,7 @@ var OpenAIChatLanguageModel = class {
|
|
681
482
|
}
|
682
483
|
getArgs({
|
683
484
|
mode,
|
684
|
-
prompt
|
485
|
+
prompt,
|
685
486
|
maxTokens,
|
686
487
|
temperature,
|
687
488
|
topP,
|
@@ -721,7 +522,7 @@ var OpenAIChatLanguageModel = class {
|
|
721
522
|
}),
|
722
523
|
seed,
|
723
524
|
// messages:
|
724
|
-
messages: convertToOpenAIChatMessages(
|
525
|
+
messages: convertToOpenAIChatMessages(prompt)
|
725
526
|
};
|
726
527
|
switch (type) {
|
727
528
|
case "regular": {
|
@@ -748,7 +549,16 @@ var OpenAIChatLanguageModel = class {
|
|
748
549
|
return {
|
749
550
|
...baseArgs,
|
750
551
|
tool_choice: { type: "function", function: { name: mode.tool.name } },
|
751
|
-
tools: [
|
552
|
+
tools: [
|
553
|
+
{
|
554
|
+
type: "function",
|
555
|
+
function: {
|
556
|
+
name: mode.tool.name,
|
557
|
+
description: mode.tool.description,
|
558
|
+
parameters: mode.tool.parameters
|
559
|
+
}
|
560
|
+
}
|
561
|
+
]
|
752
562
|
};
|
753
563
|
}
|
754
564
|
case "object-grammar": {
|
@@ -969,31 +779,38 @@ var openaiChatChunkSchema = z2.object({
|
|
969
779
|
});
|
970
780
|
|
971
781
|
// openai/openai-completion-language-model.ts
|
782
|
+
import {
|
783
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
784
|
+
} from "@ai-sdk/provider";
|
972
785
|
import { z as z3 } from "zod";
|
973
786
|
|
974
787
|
// openai/convert-to-openai-completion-prompt.ts
|
788
|
+
import {
|
789
|
+
InvalidPromptError,
|
790
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
791
|
+
} from "@ai-sdk/provider";
|
975
792
|
function convertToOpenAICompletionPrompt({
|
976
|
-
prompt
|
793
|
+
prompt,
|
977
794
|
inputFormat,
|
978
795
|
user = "user",
|
979
796
|
assistant = "assistant"
|
980
797
|
}) {
|
981
|
-
if (inputFormat === "prompt" &&
|
982
|
-
return { prompt:
|
798
|
+
if (inputFormat === "prompt" && prompt.length === 1 && prompt[0].role === "user" && prompt[0].content.length === 1 && prompt[0].content[0].type === "text") {
|
799
|
+
return { prompt: prompt[0].content[0].text };
|
983
800
|
}
|
984
801
|
let text = "";
|
985
|
-
if (
|
986
|
-
text += `${
|
802
|
+
if (prompt[0].role === "system") {
|
803
|
+
text += `${prompt[0].content}
|
987
804
|
|
988
805
|
`;
|
989
|
-
|
806
|
+
prompt = prompt.slice(1);
|
990
807
|
}
|
991
|
-
for (const { role, content } of
|
808
|
+
for (const { role, content } of prompt) {
|
992
809
|
switch (role) {
|
993
810
|
case "system": {
|
994
811
|
throw new InvalidPromptError({
|
995
812
|
message: "Unexpected system message in prompt: ${content}",
|
996
|
-
prompt
|
813
|
+
prompt
|
997
814
|
});
|
998
815
|
}
|
999
816
|
case "user": {
|
@@ -1003,7 +820,7 @@ function convertToOpenAICompletionPrompt({
|
|
1003
820
|
return part.text;
|
1004
821
|
}
|
1005
822
|
case "image": {
|
1006
|
-
throw new
|
823
|
+
throw new UnsupportedFunctionalityError2({
|
1007
824
|
functionality: "images"
|
1008
825
|
});
|
1009
826
|
}
|
@@ -1022,7 +839,7 @@ ${userMessage}
|
|
1022
839
|
return part.text;
|
1023
840
|
}
|
1024
841
|
case "tool-call": {
|
1025
|
-
throw new
|
842
|
+
throw new UnsupportedFunctionalityError2({
|
1026
843
|
functionality: "tool-call messages"
|
1027
844
|
});
|
1028
845
|
}
|
@@ -1035,7 +852,7 @@ ${assistantMessage}
|
|
1035
852
|
break;
|
1036
853
|
}
|
1037
854
|
case "tool": {
|
1038
|
-
throw new
|
855
|
+
throw new UnsupportedFunctionalityError2({
|
1039
856
|
functionality: "tool messages"
|
1040
857
|
});
|
1041
858
|
}
|
@@ -1069,7 +886,7 @@ var OpenAICompletionLanguageModel = class {
|
|
1069
886
|
getArgs({
|
1070
887
|
mode,
|
1071
888
|
inputFormat,
|
1072
|
-
prompt
|
889
|
+
prompt,
|
1073
890
|
maxTokens,
|
1074
891
|
temperature,
|
1075
892
|
topP,
|
@@ -1079,7 +896,7 @@ var OpenAICompletionLanguageModel = class {
|
|
1079
896
|
}) {
|
1080
897
|
var _a;
|
1081
898
|
const type = mode.type;
|
1082
|
-
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt
|
899
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt, inputFormat });
|
1083
900
|
const baseArgs = {
|
1084
901
|
// model id:
|
1085
902
|
model: this.modelId,
|
@@ -1119,24 +936,24 @@ var OpenAICompletionLanguageModel = class {
|
|
1119
936
|
switch (type) {
|
1120
937
|
case "regular": {
|
1121
938
|
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
1122
|
-
throw new
|
939
|
+
throw new UnsupportedFunctionalityError3({
|
1123
940
|
functionality: "tools"
|
1124
941
|
});
|
1125
942
|
}
|
1126
943
|
return baseArgs;
|
1127
944
|
}
|
1128
945
|
case "object-json": {
|
1129
|
-
throw new
|
946
|
+
throw new UnsupportedFunctionalityError3({
|
1130
947
|
functionality: "object-json mode"
|
1131
948
|
});
|
1132
949
|
}
|
1133
950
|
case "object-tool": {
|
1134
|
-
throw new
|
951
|
+
throw new UnsupportedFunctionalityError3({
|
1135
952
|
functionality: "object-tool mode"
|
1136
953
|
});
|
1137
954
|
}
|
1138
955
|
case "object-grammar": {
|
1139
|
-
throw new
|
956
|
+
throw new UnsupportedFunctionalityError3({
|
1140
957
|
functionality: "object-grammar mode"
|
1141
958
|
});
|
1142
959
|
}
|