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.js
CHANGED
@@ -35,93 +35,6 @@ __export(openai_exports, {
|
|
35
35
|
});
|
36
36
|
module.exports = __toCommonJS(openai_exports);
|
37
37
|
|
38
|
-
// spec/errors/api-call-error.ts
|
39
|
-
var APICallError = class extends Error {
|
40
|
-
constructor({
|
41
|
-
message,
|
42
|
-
url,
|
43
|
-
requestBodyValues,
|
44
|
-
statusCode,
|
45
|
-
responseBody,
|
46
|
-
cause,
|
47
|
-
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
48
|
-
statusCode === 409 || // conflict
|
49
|
-
statusCode === 429 || // too many requests
|
50
|
-
statusCode >= 500),
|
51
|
-
// server error
|
52
|
-
data
|
53
|
-
}) {
|
54
|
-
super(message);
|
55
|
-
this.name = "AI_APICallError";
|
56
|
-
this.url = url;
|
57
|
-
this.requestBodyValues = requestBodyValues;
|
58
|
-
this.statusCode = statusCode;
|
59
|
-
this.responseBody = responseBody;
|
60
|
-
this.cause = cause;
|
61
|
-
this.isRetryable = isRetryable;
|
62
|
-
this.data = data;
|
63
|
-
}
|
64
|
-
static isAPICallError(error) {
|
65
|
-
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");
|
66
|
-
}
|
67
|
-
toJSON() {
|
68
|
-
return {
|
69
|
-
name: this.name,
|
70
|
-
message: this.message,
|
71
|
-
url: this.url,
|
72
|
-
requestBodyValues: this.requestBodyValues,
|
73
|
-
statusCode: this.statusCode,
|
74
|
-
responseBody: this.responseBody,
|
75
|
-
cause: this.cause,
|
76
|
-
isRetryable: this.isRetryable,
|
77
|
-
data: this.data
|
78
|
-
};
|
79
|
-
}
|
80
|
-
};
|
81
|
-
|
82
|
-
// spec/errors/invalid-prompt-error.ts
|
83
|
-
var InvalidPromptError = class extends Error {
|
84
|
-
constructor({ prompt: prompt2, message }) {
|
85
|
-
super(`Invalid prompt: ${message}`);
|
86
|
-
this.name = "AI_InvalidPromptError";
|
87
|
-
this.prompt = prompt2;
|
88
|
-
}
|
89
|
-
static isInvalidPromptError(error) {
|
90
|
-
return error instanceof Error && error.name === "AI_InvalidPromptError" && prompt != null;
|
91
|
-
}
|
92
|
-
toJSON() {
|
93
|
-
return {
|
94
|
-
name: this.name,
|
95
|
-
message: this.message,
|
96
|
-
stack: this.stack,
|
97
|
-
prompt: this.prompt
|
98
|
-
};
|
99
|
-
}
|
100
|
-
};
|
101
|
-
|
102
|
-
// spec/errors/invalid-response-data-error.ts
|
103
|
-
var InvalidResponseDataError = class extends Error {
|
104
|
-
constructor({
|
105
|
-
data,
|
106
|
-
message = `Invalid response data: ${JSON.stringify(data)}.`
|
107
|
-
}) {
|
108
|
-
super(message);
|
109
|
-
this.name = "AI_InvalidResponseDataError";
|
110
|
-
this.data = data;
|
111
|
-
}
|
112
|
-
static isInvalidResponseDataError(error) {
|
113
|
-
return error instanceof Error && error.name === "AI_InvalidResponseDataError" && error.data != null;
|
114
|
-
}
|
115
|
-
toJSON() {
|
116
|
-
return {
|
117
|
-
name: this.name,
|
118
|
-
message: this.message,
|
119
|
-
stack: this.stack,
|
120
|
-
data: this.data
|
121
|
-
};
|
122
|
-
}
|
123
|
-
};
|
124
|
-
|
125
38
|
// spec/util/generate-id.ts
|
126
39
|
var import_non_secure = require("nanoid/non-secure");
|
127
40
|
var generateId = (0, import_non_secure.customAlphabet)(
|
@@ -129,38 +42,8 @@ var generateId = (0, import_non_secure.customAlphabet)(
|
|
129
42
|
7
|
130
43
|
);
|
131
44
|
|
132
|
-
// spec/util/get-error-message.ts
|
133
|
-
function getErrorMessage(error) {
|
134
|
-
if (error == null) {
|
135
|
-
return "unknown error";
|
136
|
-
}
|
137
|
-
if (typeof error === "string") {
|
138
|
-
return error;
|
139
|
-
}
|
140
|
-
if (error instanceof Error) {
|
141
|
-
return error.message;
|
142
|
-
}
|
143
|
-
return JSON.stringify(error);
|
144
|
-
}
|
145
|
-
|
146
|
-
// spec/errors/load-api-key-error.ts
|
147
|
-
var LoadAPIKeyError = class extends Error {
|
148
|
-
constructor({ message }) {
|
149
|
-
super(message);
|
150
|
-
this.name = "AI_LoadAPIKeyError";
|
151
|
-
}
|
152
|
-
static isLoadAPIKeyError(error) {
|
153
|
-
return error instanceof Error && error.name === "AI_LoadAPIKeyError";
|
154
|
-
}
|
155
|
-
toJSON() {
|
156
|
-
return {
|
157
|
-
name: this.name,
|
158
|
-
message: this.message
|
159
|
-
};
|
160
|
-
}
|
161
|
-
};
|
162
|
-
|
163
45
|
// spec/util/load-api-key.ts
|
46
|
+
var import_provider = require("@ai-sdk/provider");
|
164
47
|
function loadApiKey({
|
165
48
|
apiKey,
|
166
49
|
environmentVariableName,
|
@@ -171,23 +54,23 @@ function loadApiKey({
|
|
171
54
|
return apiKey;
|
172
55
|
}
|
173
56
|
if (apiKey != null) {
|
174
|
-
throw new LoadAPIKeyError({
|
57
|
+
throw new import_provider.LoadAPIKeyError({
|
175
58
|
message: `${description} API key must be a string.`
|
176
59
|
});
|
177
60
|
}
|
178
61
|
if (typeof process === "undefined") {
|
179
|
-
throw new LoadAPIKeyError({
|
62
|
+
throw new import_provider.LoadAPIKeyError({
|
180
63
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
181
64
|
});
|
182
65
|
}
|
183
66
|
apiKey = process.env[environmentVariableName];
|
184
67
|
if (apiKey == null) {
|
185
|
-
throw new LoadAPIKeyError({
|
68
|
+
throw new import_provider.LoadAPIKeyError({
|
186
69
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
187
70
|
});
|
188
71
|
}
|
189
72
|
if (typeof apiKey !== "string") {
|
190
|
-
throw new LoadAPIKeyError({
|
73
|
+
throw new import_provider.LoadAPIKeyError({
|
191
74
|
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
192
75
|
});
|
193
76
|
}
|
@@ -195,59 +78,11 @@ function loadApiKey({
|
|
195
78
|
}
|
196
79
|
|
197
80
|
// spec/util/parse-json.ts
|
81
|
+
var import_provider3 = require("@ai-sdk/provider");
|
198
82
|
var import_secure_json_parse = __toESM(require("secure-json-parse"));
|
199
83
|
|
200
|
-
// spec/errors/json-parse-error.ts
|
201
|
-
var JSONParseError = class extends Error {
|
202
|
-
constructor({ text, cause }) {
|
203
|
-
super(
|
204
|
-
`JSON parsing failed: Text: ${text}.
|
205
|
-
Error message: ${getErrorMessage(cause)}`
|
206
|
-
);
|
207
|
-
this.name = "AI_JSONParseError";
|
208
|
-
this.cause = cause;
|
209
|
-
this.text = text;
|
210
|
-
}
|
211
|
-
static isJSONParseError(error) {
|
212
|
-
return error instanceof Error && error.name === "AI_JSONParseError" && typeof error.text === "string" && typeof error.cause === "string";
|
213
|
-
}
|
214
|
-
toJSON() {
|
215
|
-
return {
|
216
|
-
name: this.name,
|
217
|
-
message: this.message,
|
218
|
-
cause: this.cause,
|
219
|
-
stack: this.stack,
|
220
|
-
valueText: this.text
|
221
|
-
};
|
222
|
-
}
|
223
|
-
};
|
224
|
-
|
225
|
-
// spec/errors/type-validation-error.ts
|
226
|
-
var TypeValidationError = class extends Error {
|
227
|
-
constructor({ value, cause }) {
|
228
|
-
super(
|
229
|
-
`Type validation failed: Value: ${JSON.stringify(value)}.
|
230
|
-
Error message: ${getErrorMessage(cause)}`
|
231
|
-
);
|
232
|
-
this.name = "AI_TypeValidationError";
|
233
|
-
this.cause = cause;
|
234
|
-
this.value = value;
|
235
|
-
}
|
236
|
-
static isTypeValidationError(error) {
|
237
|
-
return error instanceof Error && error.name === "AI_TypeValidationError" && typeof error.value === "string" && typeof error.cause === "string";
|
238
|
-
}
|
239
|
-
toJSON() {
|
240
|
-
return {
|
241
|
-
name: this.name,
|
242
|
-
message: this.message,
|
243
|
-
cause: this.cause,
|
244
|
-
stack: this.stack,
|
245
|
-
value: this.value
|
246
|
-
};
|
247
|
-
}
|
248
|
-
};
|
249
|
-
|
250
84
|
// spec/util/validate-types.ts
|
85
|
+
var import_provider2 = require("@ai-sdk/provider");
|
251
86
|
function validateTypes({
|
252
87
|
value,
|
253
88
|
schema
|
@@ -255,7 +90,7 @@ function validateTypes({
|
|
255
90
|
try {
|
256
91
|
return schema.parse(value);
|
257
92
|
} catch (error) {
|
258
|
-
throw new TypeValidationError({ value, cause: error });
|
93
|
+
throw new import_provider2.TypeValidationError({ value, cause: error });
|
259
94
|
}
|
260
95
|
}
|
261
96
|
function safeValidateTypes({
|
@@ -272,7 +107,7 @@ function safeValidateTypes({
|
|
272
107
|
}
|
273
108
|
return {
|
274
109
|
success: false,
|
275
|
-
error: new TypeValidationError({
|
110
|
+
error: new import_provider2.TypeValidationError({
|
276
111
|
value,
|
277
112
|
cause: validationResult.error
|
278
113
|
})
|
@@ -280,7 +115,7 @@ function safeValidateTypes({
|
|
280
115
|
} catch (error) {
|
281
116
|
return {
|
282
117
|
success: false,
|
283
|
-
error: TypeValidationError.isTypeValidationError(error) ? error : new TypeValidationError({ value, cause: error })
|
118
|
+
error: import_provider2.TypeValidationError.isTypeValidationError(error) ? error : new import_provider2.TypeValidationError({ value, cause: error })
|
284
119
|
};
|
285
120
|
}
|
286
121
|
}
|
@@ -297,10 +132,10 @@ function parseJSON({
|
|
297
132
|
}
|
298
133
|
return validateTypes({ value, schema });
|
299
134
|
} catch (error) {
|
300
|
-
if (JSONParseError.isJSONParseError(error) || TypeValidationError.isTypeValidationError(error)) {
|
135
|
+
if (import_provider3.JSONParseError.isJSONParseError(error) || import_provider3.TypeValidationError.isTypeValidationError(error)) {
|
301
136
|
throw error;
|
302
137
|
}
|
303
|
-
throw new JSONParseError({ text, cause: error });
|
138
|
+
throw new import_provider3.JSONParseError({ text, cause: error });
|
304
139
|
}
|
305
140
|
}
|
306
141
|
function safeParseJSON({
|
@@ -319,7 +154,7 @@ function safeParseJSON({
|
|
319
154
|
} catch (error) {
|
320
155
|
return {
|
321
156
|
success: false,
|
322
|
-
error: JSONParseError.isJSONParseError(error) ? error : new JSONParseError({ text, cause: error })
|
157
|
+
error: import_provider3.JSONParseError.isJSONParseError(error) ? error : new import_provider3.JSONParseError({ text, cause: error })
|
323
158
|
};
|
324
159
|
}
|
325
160
|
}
|
@@ -333,6 +168,7 @@ function isParseableJson(input) {
|
|
333
168
|
}
|
334
169
|
|
335
170
|
// spec/util/post-to-api.ts
|
171
|
+
var import_provider4 = require("@ai-sdk/provider");
|
336
172
|
var postJsonToApi = async ({
|
337
173
|
url,
|
338
174
|
headers,
|
@@ -381,11 +217,11 @@ var postToApi = async ({
|
|
381
217
|
});
|
382
218
|
} catch (error) {
|
383
219
|
if (error instanceof Error) {
|
384
|
-
if (error.name === "AbortError" || APICallError.isAPICallError(error)) {
|
220
|
+
if (error.name === "AbortError" || import_provider4.APICallError.isAPICallError(error)) {
|
385
221
|
throw error;
|
386
222
|
}
|
387
223
|
}
|
388
|
-
throw new APICallError({
|
224
|
+
throw new import_provider4.APICallError({
|
389
225
|
message: "Failed to process error response",
|
390
226
|
cause: error,
|
391
227
|
statusCode: response.status,
|
@@ -402,11 +238,11 @@ var postToApi = async ({
|
|
402
238
|
});
|
403
239
|
} catch (error) {
|
404
240
|
if (error instanceof Error) {
|
405
|
-
if (error.name === "AbortError" || APICallError.isAPICallError(error)) {
|
241
|
+
if (error.name === "AbortError" || import_provider4.APICallError.isAPICallError(error)) {
|
406
242
|
throw error;
|
407
243
|
}
|
408
244
|
}
|
409
|
-
throw new APICallError({
|
245
|
+
throw new import_provider4.APICallError({
|
410
246
|
message: "Failed to process successful response",
|
411
247
|
cause: error,
|
412
248
|
statusCode: response.status,
|
@@ -423,7 +259,7 @@ var postToApi = async ({
|
|
423
259
|
if (error instanceof TypeError && error.message === "fetch failed") {
|
424
260
|
const cause = error.cause;
|
425
261
|
if (cause != null) {
|
426
|
-
throw new APICallError({
|
262
|
+
throw new import_provider4.APICallError({
|
427
263
|
message: `Cannot connect to API: ${cause.message}`,
|
428
264
|
cause,
|
429
265
|
url,
|
@@ -438,27 +274,8 @@ var postToApi = async ({
|
|
438
274
|
};
|
439
275
|
|
440
276
|
// spec/util/response-handler.ts
|
277
|
+
var import_provider5 = require("@ai-sdk/provider");
|
441
278
|
var import_stream = require("eventsource-parser/stream");
|
442
|
-
|
443
|
-
// spec/errors/no-response-body-error.ts
|
444
|
-
var NoResponseBodyError = class extends Error {
|
445
|
-
constructor({ message = "No response body" } = {}) {
|
446
|
-
super(message);
|
447
|
-
this.name = "AI_NoResponseBodyError";
|
448
|
-
}
|
449
|
-
static isNoResponseBodyError(error) {
|
450
|
-
return error instanceof Error && error.name === "AI_NoResponseBodyError";
|
451
|
-
}
|
452
|
-
toJSON() {
|
453
|
-
return {
|
454
|
-
name: this.name,
|
455
|
-
message: this.message,
|
456
|
-
stack: this.stack
|
457
|
-
};
|
458
|
-
}
|
459
|
-
};
|
460
|
-
|
461
|
-
// spec/util/response-handler.ts
|
462
279
|
var createJsonErrorResponseHandler = ({
|
463
280
|
errorSchema,
|
464
281
|
errorToMessage,
|
@@ -466,7 +283,7 @@ var createJsonErrorResponseHandler = ({
|
|
466
283
|
}) => async ({ response, url, requestBodyValues }) => {
|
467
284
|
const responseBody = await response.text();
|
468
285
|
if (responseBody.trim() === "") {
|
469
|
-
return new APICallError({
|
286
|
+
return new import_provider5.APICallError({
|
470
287
|
message: response.statusText,
|
471
288
|
url,
|
472
289
|
requestBodyValues,
|
@@ -480,7 +297,7 @@ var createJsonErrorResponseHandler = ({
|
|
480
297
|
text: responseBody,
|
481
298
|
schema: errorSchema
|
482
299
|
});
|
483
|
-
return new APICallError({
|
300
|
+
return new import_provider5.APICallError({
|
484
301
|
message: errorToMessage(parsedError),
|
485
302
|
url,
|
486
303
|
requestBodyValues,
|
@@ -490,7 +307,7 @@ var createJsonErrorResponseHandler = ({
|
|
490
307
|
isRetryable: isRetryable == null ? void 0 : isRetryable(response, parsedError)
|
491
308
|
});
|
492
309
|
} catch (parseError) {
|
493
|
-
return new APICallError({
|
310
|
+
return new import_provider5.APICallError({
|
494
311
|
message: response.statusText,
|
495
312
|
url,
|
496
313
|
requestBodyValues,
|
@@ -502,7 +319,7 @@ var createJsonErrorResponseHandler = ({
|
|
502
319
|
};
|
503
320
|
var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
|
504
321
|
if (response.body == null) {
|
505
|
-
throw new NoResponseBodyError();
|
322
|
+
throw new import_provider5.NoResponseBodyError();
|
506
323
|
}
|
507
324
|
return response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_stream.EventSourceParserStream()).pipeThrough(
|
508
325
|
new TransformStream({
|
@@ -527,7 +344,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
527
344
|
schema: responseSchema
|
528
345
|
});
|
529
346
|
if (!parsedResult.success) {
|
530
|
-
throw new APICallError({
|
347
|
+
throw new import_provider5.APICallError({
|
531
348
|
message: "Invalid JSON response",
|
532
349
|
cause: parsedResult.error,
|
533
350
|
statusCode: response.status,
|
@@ -564,33 +381,14 @@ function convertUint8ArrayToBase64(array) {
|
|
564
381
|
return globalThis.btoa(latin1string);
|
565
382
|
}
|
566
383
|
|
567
|
-
// spec/errors/unsupported-functionality-error.ts
|
568
|
-
var UnsupportedFunctionalityError = class extends Error {
|
569
|
-
constructor({ functionality }) {
|
570
|
-
super(`'${functionality}' functionality not supported.`);
|
571
|
-
this.name = "AI_UnsupportedFunctionalityError";
|
572
|
-
this.functionality = functionality;
|
573
|
-
}
|
574
|
-
static isUnsupportedFunctionalityError(error) {
|
575
|
-
return error instanceof Error && error.name === "AI_UnsupportedFunctionalityError" && typeof error.functionality === "string";
|
576
|
-
}
|
577
|
-
toJSON() {
|
578
|
-
return {
|
579
|
-
name: this.name,
|
580
|
-
message: this.message,
|
581
|
-
stack: this.stack,
|
582
|
-
functionality: this.functionality
|
583
|
-
};
|
584
|
-
}
|
585
|
-
};
|
586
|
-
|
587
384
|
// openai/openai-chat-language-model.ts
|
385
|
+
var import_provider6 = require("@ai-sdk/provider");
|
588
386
|
var import_zod2 = require("zod");
|
589
387
|
|
590
388
|
// openai/convert-to-openai-chat-messages.ts
|
591
|
-
function convertToOpenAIChatMessages(
|
389
|
+
function convertToOpenAIChatMessages(prompt) {
|
592
390
|
const messages = [];
|
593
|
-
for (const { role, content } of
|
391
|
+
for (const { role, content } of prompt) {
|
594
392
|
switch (role) {
|
595
393
|
case "system": {
|
596
394
|
messages.push({ role: "system", content });
|
@@ -716,7 +514,7 @@ var OpenAIChatLanguageModel = class {
|
|
716
514
|
}
|
717
515
|
getArgs({
|
718
516
|
mode,
|
719
|
-
prompt
|
517
|
+
prompt,
|
720
518
|
maxTokens,
|
721
519
|
temperature,
|
722
520
|
topP,
|
@@ -756,7 +554,7 @@ var OpenAIChatLanguageModel = class {
|
|
756
554
|
}),
|
757
555
|
seed,
|
758
556
|
// messages:
|
759
|
-
messages: convertToOpenAIChatMessages(
|
557
|
+
messages: convertToOpenAIChatMessages(prompt)
|
760
558
|
};
|
761
559
|
switch (type) {
|
762
560
|
case "regular": {
|
@@ -783,11 +581,20 @@ var OpenAIChatLanguageModel = class {
|
|
783
581
|
return {
|
784
582
|
...baseArgs,
|
785
583
|
tool_choice: { type: "function", function: { name: mode.tool.name } },
|
786
|
-
tools: [
|
584
|
+
tools: [
|
585
|
+
{
|
586
|
+
type: "function",
|
587
|
+
function: {
|
588
|
+
name: mode.tool.name,
|
589
|
+
description: mode.tool.description,
|
590
|
+
parameters: mode.tool.parameters
|
591
|
+
}
|
592
|
+
}
|
593
|
+
]
|
787
594
|
};
|
788
595
|
}
|
789
596
|
case "object-grammar": {
|
790
|
-
throw new UnsupportedFunctionalityError({
|
597
|
+
throw new import_provider6.UnsupportedFunctionalityError({
|
791
598
|
functionality: "object-grammar mode"
|
792
599
|
});
|
793
600
|
}
|
@@ -886,19 +693,19 @@ var OpenAIChatLanguageModel = class {
|
|
886
693
|
const index = toolCallDelta.index;
|
887
694
|
if (toolCalls[index] == null) {
|
888
695
|
if (toolCallDelta.type !== "function") {
|
889
|
-
throw new InvalidResponseDataError({
|
696
|
+
throw new import_provider6.InvalidResponseDataError({
|
890
697
|
data: toolCallDelta,
|
891
698
|
message: `Expected 'function' type.`
|
892
699
|
});
|
893
700
|
}
|
894
701
|
if (toolCallDelta.id == null) {
|
895
|
-
throw new InvalidResponseDataError({
|
702
|
+
throw new import_provider6.InvalidResponseDataError({
|
896
703
|
data: toolCallDelta,
|
897
704
|
message: `Expected 'id' to be a string.`
|
898
705
|
});
|
899
706
|
}
|
900
707
|
if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) {
|
901
|
-
throw new InvalidResponseDataError({
|
708
|
+
throw new import_provider6.InvalidResponseDataError({
|
902
709
|
data: toolCallDelta,
|
903
710
|
message: `Expected 'function.name' to be a string.`
|
904
711
|
});
|
@@ -1004,31 +811,33 @@ var openaiChatChunkSchema = import_zod2.z.object({
|
|
1004
811
|
});
|
1005
812
|
|
1006
813
|
// openai/openai-completion-language-model.ts
|
814
|
+
var import_provider8 = require("@ai-sdk/provider");
|
1007
815
|
var import_zod3 = require("zod");
|
1008
816
|
|
1009
817
|
// openai/convert-to-openai-completion-prompt.ts
|
818
|
+
var import_provider7 = require("@ai-sdk/provider");
|
1010
819
|
function convertToOpenAICompletionPrompt({
|
1011
|
-
prompt
|
820
|
+
prompt,
|
1012
821
|
inputFormat,
|
1013
822
|
user = "user",
|
1014
823
|
assistant = "assistant"
|
1015
824
|
}) {
|
1016
|
-
if (inputFormat === "prompt" &&
|
1017
|
-
return { prompt:
|
825
|
+
if (inputFormat === "prompt" && prompt.length === 1 && prompt[0].role === "user" && prompt[0].content.length === 1 && prompt[0].content[0].type === "text") {
|
826
|
+
return { prompt: prompt[0].content[0].text };
|
1018
827
|
}
|
1019
828
|
let text = "";
|
1020
|
-
if (
|
1021
|
-
text += `${
|
829
|
+
if (prompt[0].role === "system") {
|
830
|
+
text += `${prompt[0].content}
|
1022
831
|
|
1023
832
|
`;
|
1024
|
-
|
833
|
+
prompt = prompt.slice(1);
|
1025
834
|
}
|
1026
|
-
for (const { role, content } of
|
835
|
+
for (const { role, content } of prompt) {
|
1027
836
|
switch (role) {
|
1028
837
|
case "system": {
|
1029
|
-
throw new InvalidPromptError({
|
838
|
+
throw new import_provider7.InvalidPromptError({
|
1030
839
|
message: "Unexpected system message in prompt: ${content}",
|
1031
|
-
prompt
|
840
|
+
prompt
|
1032
841
|
});
|
1033
842
|
}
|
1034
843
|
case "user": {
|
@@ -1038,7 +847,7 @@ function convertToOpenAICompletionPrompt({
|
|
1038
847
|
return part.text;
|
1039
848
|
}
|
1040
849
|
case "image": {
|
1041
|
-
throw new UnsupportedFunctionalityError({
|
850
|
+
throw new import_provider7.UnsupportedFunctionalityError({
|
1042
851
|
functionality: "images"
|
1043
852
|
});
|
1044
853
|
}
|
@@ -1057,7 +866,7 @@ ${userMessage}
|
|
1057
866
|
return part.text;
|
1058
867
|
}
|
1059
868
|
case "tool-call": {
|
1060
|
-
throw new UnsupportedFunctionalityError({
|
869
|
+
throw new import_provider7.UnsupportedFunctionalityError({
|
1061
870
|
functionality: "tool-call messages"
|
1062
871
|
});
|
1063
872
|
}
|
@@ -1070,7 +879,7 @@ ${assistantMessage}
|
|
1070
879
|
break;
|
1071
880
|
}
|
1072
881
|
case "tool": {
|
1073
|
-
throw new UnsupportedFunctionalityError({
|
882
|
+
throw new import_provider7.UnsupportedFunctionalityError({
|
1074
883
|
functionality: "tool messages"
|
1075
884
|
});
|
1076
885
|
}
|
@@ -1104,7 +913,7 @@ var OpenAICompletionLanguageModel = class {
|
|
1104
913
|
getArgs({
|
1105
914
|
mode,
|
1106
915
|
inputFormat,
|
1107
|
-
prompt
|
916
|
+
prompt,
|
1108
917
|
maxTokens,
|
1109
918
|
temperature,
|
1110
919
|
topP,
|
@@ -1114,7 +923,7 @@ var OpenAICompletionLanguageModel = class {
|
|
1114
923
|
}) {
|
1115
924
|
var _a;
|
1116
925
|
const type = mode.type;
|
1117
|
-
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt
|
926
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt, inputFormat });
|
1118
927
|
const baseArgs = {
|
1119
928
|
// model id:
|
1120
929
|
model: this.modelId,
|
@@ -1154,24 +963,24 @@ var OpenAICompletionLanguageModel = class {
|
|
1154
963
|
switch (type) {
|
1155
964
|
case "regular": {
|
1156
965
|
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
1157
|
-
throw new UnsupportedFunctionalityError({
|
966
|
+
throw new import_provider8.UnsupportedFunctionalityError({
|
1158
967
|
functionality: "tools"
|
1159
968
|
});
|
1160
969
|
}
|
1161
970
|
return baseArgs;
|
1162
971
|
}
|
1163
972
|
case "object-json": {
|
1164
|
-
throw new UnsupportedFunctionalityError({
|
973
|
+
throw new import_provider8.UnsupportedFunctionalityError({
|
1165
974
|
functionality: "object-json mode"
|
1166
975
|
});
|
1167
976
|
}
|
1168
977
|
case "object-tool": {
|
1169
|
-
throw new UnsupportedFunctionalityError({
|
978
|
+
throw new import_provider8.UnsupportedFunctionalityError({
|
1170
979
|
functionality: "object-tool mode"
|
1171
980
|
});
|
1172
981
|
}
|
1173
982
|
case "object-grammar": {
|
1174
|
-
throw new UnsupportedFunctionalityError({
|
983
|
+
throw new import_provider8.UnsupportedFunctionalityError({
|
1175
984
|
functionality: "object-grammar mode"
|
1176
985
|
});
|
1177
986
|
}
|