ai 3.0.19 → 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 -319
- package/anthropic/dist/index.d.ts +1 -319
- package/anthropic/dist/index.js +44 -216
- package/anthropic/dist/index.js.map +1 -1
- package/anthropic/dist/index.mjs +32 -200
- package/anthropic/dist/index.mjs.map +1 -1
- package/dist/index.d.mts +60 -333
- package/dist/index.d.ts +60 -333
- package/dist/index.js +152 -441
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -412
- package/dist/index.mjs.map +1 -1
- package/google/dist/index.d.mts +1 -319
- package/google/dist/index.d.ts +1 -319
- package/google/dist/index.js +75 -229
- package/google/dist/index.js.map +1 -1
- package/google/dist/index.mjs +63 -213
- package/google/dist/index.mjs.map +1 -1
- package/mistral/dist/index.d.mts +1 -319
- package/mistral/dist/index.d.ts +1 -319
- package/mistral/dist/index.js +32 -205
- package/mistral/dist/index.js.map +1 -1
- package/mistral/dist/index.mjs +20 -189
- package/mistral/dist/index.mjs.map +1 -1
- package/openai/dist/index.d.mts +2 -320
- package/openai/dist/index.d.ts +2 -320
- package/openai/dist/index.js +69 -280
- package/openai/dist/index.js.map +1 -1
- package/openai/dist/index.mjs +57 -260
- package/openai/dist/index.mjs.map +1 -1
- package/package.json +4 -10
- package/react/dist/index.d.mts +8 -4
- package/react/dist/index.d.ts +12 -6
- package/react/dist/index.js +23 -105
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +22 -105
- package/react/dist/index.mjs.map +1 -1
- package/react/dist/index.server.d.mts +4 -2
- package/react/dist/index.server.d.ts +4 -2
- package/react/dist/index.server.js.map +1 -1
- package/react/dist/index.server.mjs.map +1 -1
- package/rsc/dist/rsc-server.mjs +6 -16
- package/rsc/dist/rsc-server.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 +19 -104
- package/solid/dist/index.js.map +1 -1
- package/solid/dist/index.mjs +19 -104
- 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 +19 -104
- package/svelte/dist/index.js.map +1 -1
- package/svelte/dist/index.mjs +19 -104
- 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 +19 -104
- package/vue/dist/index.js.map +1 -1
- package/vue/dist/index.mjs +19 -104
- package/vue/dist/index.mjs.map +1 -1
- package/spec/dist/index.d.mts +0 -752
- package/spec/dist/index.d.ts +0 -752
- package/spec/dist/index.js +0 -873
- package/spec/dist/index.js.map +0 -1
- package/spec/dist/index.mjs +0 -807
- 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,40 +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({
|
570
|
-
provider,
|
571
|
-
functionality
|
572
|
-
}) {
|
573
|
-
super(
|
574
|
-
`'${functionality}' functionality not supported by the '${provider}' provider.`
|
575
|
-
);
|
576
|
-
this.name = "AI_UnsupportedFunctionalityError";
|
577
|
-
this.provider = provider;
|
578
|
-
this.functionality = functionality;
|
579
|
-
}
|
580
|
-
static isUnsupportedFunctionalityError(error) {
|
581
|
-
return error instanceof Error && error.name === "AI_UnsupportedFunctionalityError" && typeof error.provider === "string" && typeof error.functionality === "string";
|
582
|
-
}
|
583
|
-
toJSON() {
|
584
|
-
return {
|
585
|
-
name: this.name,
|
586
|
-
message: this.message,
|
587
|
-
stack: this.stack,
|
588
|
-
provider: this.provider,
|
589
|
-
functionality: this.functionality
|
590
|
-
};
|
591
|
-
}
|
592
|
-
};
|
593
|
-
|
594
384
|
// openai/openai-chat-language-model.ts
|
385
|
+
var import_provider6 = require("@ai-sdk/provider");
|
595
386
|
var import_zod2 = require("zod");
|
596
387
|
|
597
388
|
// openai/convert-to-openai-chat-messages.ts
|
598
|
-
function convertToOpenAIChatMessages(
|
389
|
+
function convertToOpenAIChatMessages(prompt) {
|
599
390
|
const messages = [];
|
600
|
-
for (const { role, content } of
|
391
|
+
for (const { role, content } of prompt) {
|
601
392
|
switch (role) {
|
602
393
|
case "system": {
|
603
394
|
messages.push({ role: "system", content });
|
@@ -723,7 +514,7 @@ var OpenAIChatLanguageModel = class {
|
|
723
514
|
}
|
724
515
|
getArgs({
|
725
516
|
mode,
|
726
|
-
prompt
|
517
|
+
prompt,
|
727
518
|
maxTokens,
|
728
519
|
temperature,
|
729
520
|
topP,
|
@@ -763,7 +554,7 @@ var OpenAIChatLanguageModel = class {
|
|
763
554
|
}),
|
764
555
|
seed,
|
765
556
|
// messages:
|
766
|
-
messages: convertToOpenAIChatMessages(
|
557
|
+
messages: convertToOpenAIChatMessages(prompt)
|
767
558
|
};
|
768
559
|
switch (type) {
|
769
560
|
case "regular": {
|
@@ -790,13 +581,21 @@ var OpenAIChatLanguageModel = class {
|
|
790
581
|
return {
|
791
582
|
...baseArgs,
|
792
583
|
tool_choice: { type: "function", function: { name: mode.tool.name } },
|
793
|
-
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
|
+
]
|
794
594
|
};
|
795
595
|
}
|
796
596
|
case "object-grammar": {
|
797
|
-
throw new UnsupportedFunctionalityError({
|
798
|
-
functionality: "object-grammar mode"
|
799
|
-
provider: this.provider
|
597
|
+
throw new import_provider6.UnsupportedFunctionalityError({
|
598
|
+
functionality: "object-grammar mode"
|
800
599
|
});
|
801
600
|
}
|
802
601
|
default: {
|
@@ -894,19 +693,19 @@ var OpenAIChatLanguageModel = class {
|
|
894
693
|
const index = toolCallDelta.index;
|
895
694
|
if (toolCalls[index] == null) {
|
896
695
|
if (toolCallDelta.type !== "function") {
|
897
|
-
throw new InvalidResponseDataError({
|
696
|
+
throw new import_provider6.InvalidResponseDataError({
|
898
697
|
data: toolCallDelta,
|
899
698
|
message: `Expected 'function' type.`
|
900
699
|
});
|
901
700
|
}
|
902
701
|
if (toolCallDelta.id == null) {
|
903
|
-
throw new InvalidResponseDataError({
|
702
|
+
throw new import_provider6.InvalidResponseDataError({
|
904
703
|
data: toolCallDelta,
|
905
704
|
message: `Expected 'id' to be a string.`
|
906
705
|
});
|
907
706
|
}
|
908
707
|
if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) {
|
909
|
-
throw new InvalidResponseDataError({
|
708
|
+
throw new import_provider6.InvalidResponseDataError({
|
910
709
|
data: toolCallDelta,
|
911
710
|
message: `Expected 'function.name' to be a string.`
|
912
711
|
});
|
@@ -1012,32 +811,33 @@ var openaiChatChunkSchema = import_zod2.z.object({
|
|
1012
811
|
});
|
1013
812
|
|
1014
813
|
// openai/openai-completion-language-model.ts
|
814
|
+
var import_provider8 = require("@ai-sdk/provider");
|
1015
815
|
var import_zod3 = require("zod");
|
1016
816
|
|
1017
817
|
// openai/convert-to-openai-completion-prompt.ts
|
818
|
+
var import_provider7 = require("@ai-sdk/provider");
|
1018
819
|
function convertToOpenAICompletionPrompt({
|
1019
|
-
prompt
|
820
|
+
prompt,
|
1020
821
|
inputFormat,
|
1021
|
-
provider,
|
1022
822
|
user = "user",
|
1023
823
|
assistant = "assistant"
|
1024
824
|
}) {
|
1025
|
-
if (inputFormat === "prompt" &&
|
1026
|
-
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 };
|
1027
827
|
}
|
1028
828
|
let text = "";
|
1029
|
-
if (
|
1030
|
-
text += `${
|
829
|
+
if (prompt[0].role === "system") {
|
830
|
+
text += `${prompt[0].content}
|
1031
831
|
|
1032
832
|
`;
|
1033
|
-
|
833
|
+
prompt = prompt.slice(1);
|
1034
834
|
}
|
1035
|
-
for (const { role, content } of
|
835
|
+
for (const { role, content } of prompt) {
|
1036
836
|
switch (role) {
|
1037
837
|
case "system": {
|
1038
|
-
throw new InvalidPromptError({
|
838
|
+
throw new import_provider7.InvalidPromptError({
|
1039
839
|
message: "Unexpected system message in prompt: ${content}",
|
1040
|
-
prompt
|
840
|
+
prompt
|
1041
841
|
});
|
1042
842
|
}
|
1043
843
|
case "user": {
|
@@ -1047,8 +847,7 @@ function convertToOpenAICompletionPrompt({
|
|
1047
847
|
return part.text;
|
1048
848
|
}
|
1049
849
|
case "image": {
|
1050
|
-
throw new UnsupportedFunctionalityError({
|
1051
|
-
provider,
|
850
|
+
throw new import_provider7.UnsupportedFunctionalityError({
|
1052
851
|
functionality: "images"
|
1053
852
|
});
|
1054
853
|
}
|
@@ -1067,8 +866,7 @@ ${userMessage}
|
|
1067
866
|
return part.text;
|
1068
867
|
}
|
1069
868
|
case "tool-call": {
|
1070
|
-
throw new UnsupportedFunctionalityError({
|
1071
|
-
provider,
|
869
|
+
throw new import_provider7.UnsupportedFunctionalityError({
|
1072
870
|
functionality: "tool-call messages"
|
1073
871
|
});
|
1074
872
|
}
|
@@ -1081,8 +879,7 @@ ${assistantMessage}
|
|
1081
879
|
break;
|
1082
880
|
}
|
1083
881
|
case "tool": {
|
1084
|
-
throw new UnsupportedFunctionalityError({
|
1085
|
-
provider,
|
882
|
+
throw new import_provider7.UnsupportedFunctionalityError({
|
1086
883
|
functionality: "tool messages"
|
1087
884
|
});
|
1088
885
|
}
|
@@ -1116,7 +913,7 @@ var OpenAICompletionLanguageModel = class {
|
|
1116
913
|
getArgs({
|
1117
914
|
mode,
|
1118
915
|
inputFormat,
|
1119
|
-
prompt
|
916
|
+
prompt,
|
1120
917
|
maxTokens,
|
1121
918
|
temperature,
|
1122
919
|
topP,
|
@@ -1126,11 +923,7 @@ var OpenAICompletionLanguageModel = class {
|
|
1126
923
|
}) {
|
1127
924
|
var _a;
|
1128
925
|
const type = mode.type;
|
1129
|
-
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({
|
1130
|
-
prompt: prompt2,
|
1131
|
-
inputFormat,
|
1132
|
-
provider: this.provider
|
1133
|
-
});
|
926
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt, inputFormat });
|
1134
927
|
const baseArgs = {
|
1135
928
|
// model id:
|
1136
929
|
model: this.modelId,
|
@@ -1170,29 +963,25 @@ var OpenAICompletionLanguageModel = class {
|
|
1170
963
|
switch (type) {
|
1171
964
|
case "regular": {
|
1172
965
|
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
1173
|
-
throw new UnsupportedFunctionalityError({
|
1174
|
-
functionality: "tools"
|
1175
|
-
provider: this.provider
|
966
|
+
throw new import_provider8.UnsupportedFunctionalityError({
|
967
|
+
functionality: "tools"
|
1176
968
|
});
|
1177
969
|
}
|
1178
970
|
return baseArgs;
|
1179
971
|
}
|
1180
972
|
case "object-json": {
|
1181
|
-
throw new UnsupportedFunctionalityError({
|
1182
|
-
functionality: "object-json mode"
|
1183
|
-
provider: this.provider
|
973
|
+
throw new import_provider8.UnsupportedFunctionalityError({
|
974
|
+
functionality: "object-json mode"
|
1184
975
|
});
|
1185
976
|
}
|
1186
977
|
case "object-tool": {
|
1187
|
-
throw new UnsupportedFunctionalityError({
|
1188
|
-
functionality: "object-tool mode"
|
1189
|
-
provider: this.provider
|
978
|
+
throw new import_provider8.UnsupportedFunctionalityError({
|
979
|
+
functionality: "object-tool mode"
|
1190
980
|
});
|
1191
981
|
}
|
1192
982
|
case "object-grammar": {
|
1193
|
-
throw new UnsupportedFunctionalityError({
|
1194
|
-
functionality: "object-grammar mode"
|
1195
|
-
provider: this.provider
|
983
|
+
throw new import_provider8.UnsupportedFunctionalityError({
|
984
|
+
functionality: "object-grammar mode"
|
1196
985
|
});
|
1197
986
|
}
|
1198
987
|
default: {
|