@ai-sdk/openai 2.0.0-canary.5 → 2.0.0-canary.6
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 +18 -0
- package/dist/index.d.mts +6 -67
- package/dist/index.d.ts +6 -67
- package/dist/index.js +416 -503
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +383 -470
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +88 -80
- package/dist/internal/index.d.ts +88 -80
- package/dist/internal/index.js +415 -500
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +383 -469
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -26,18 +26,18 @@ __export(src_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(src_exports);
|
|
27
27
|
|
|
28
28
|
// src/openai-provider.ts
|
|
29
|
-
var
|
|
29
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
30
30
|
|
|
31
31
|
// src/openai-chat-language-model.ts
|
|
32
32
|
var import_provider3 = require("@ai-sdk/provider");
|
|
33
|
-
var
|
|
34
|
-
var
|
|
33
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
34
|
+
var import_zod3 = require("zod");
|
|
35
35
|
|
|
36
36
|
// src/convert-to-openai-chat-messages.ts
|
|
37
37
|
var import_provider = require("@ai-sdk/provider");
|
|
38
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
38
39
|
function convertToOpenAIChatMessages({
|
|
39
40
|
prompt,
|
|
40
|
-
useLegacyFunctionCalling = false,
|
|
41
41
|
systemMessageMode = "system"
|
|
42
42
|
}) {
|
|
43
43
|
const messages = [];
|
|
@@ -89,7 +89,7 @@ function convertToOpenAIChatMessages({
|
|
|
89
89
|
return {
|
|
90
90
|
type: "image_url",
|
|
91
91
|
image_url: {
|
|
92
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
92
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils.convertToBase64)(part.data)}`,
|
|
93
93
|
// OpenAI specific extension: image detail
|
|
94
94
|
detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
|
|
95
95
|
}
|
|
@@ -104,14 +104,20 @@ function convertToOpenAIChatMessages({
|
|
|
104
104
|
case "audio/wav": {
|
|
105
105
|
return {
|
|
106
106
|
type: "input_audio",
|
|
107
|
-
input_audio: {
|
|
107
|
+
input_audio: {
|
|
108
|
+
data: (0, import_provider_utils.convertToBase64)(part.data),
|
|
109
|
+
format: "wav"
|
|
110
|
+
}
|
|
108
111
|
};
|
|
109
112
|
}
|
|
110
113
|
case "audio/mp3":
|
|
111
114
|
case "audio/mpeg": {
|
|
112
115
|
return {
|
|
113
116
|
type: "input_audio",
|
|
114
|
-
input_audio: {
|
|
117
|
+
input_audio: {
|
|
118
|
+
data: (0, import_provider_utils.convertToBase64)(part.data),
|
|
119
|
+
format: "mp3"
|
|
120
|
+
}
|
|
115
121
|
};
|
|
116
122
|
}
|
|
117
123
|
default: {
|
|
@@ -166,41 +172,20 @@ function convertToOpenAIChatMessages({
|
|
|
166
172
|
}
|
|
167
173
|
}
|
|
168
174
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
messages.push({
|
|
176
|
-
role: "assistant",
|
|
177
|
-
content: text,
|
|
178
|
-
function_call: toolCalls.length > 0 ? toolCalls[0].function : void 0
|
|
179
|
-
});
|
|
180
|
-
} else {
|
|
181
|
-
messages.push({
|
|
182
|
-
role: "assistant",
|
|
183
|
-
content: text,
|
|
184
|
-
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
185
|
-
});
|
|
186
|
-
}
|
|
175
|
+
messages.push({
|
|
176
|
+
role: "assistant",
|
|
177
|
+
content: text,
|
|
178
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
179
|
+
});
|
|
187
180
|
break;
|
|
188
181
|
}
|
|
189
182
|
case "tool": {
|
|
190
183
|
for (const toolResponse of content) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
});
|
|
197
|
-
} else {
|
|
198
|
-
messages.push({
|
|
199
|
-
role: "tool",
|
|
200
|
-
tool_call_id: toolResponse.toolCallId,
|
|
201
|
-
content: JSON.stringify(toolResponse.result)
|
|
202
|
-
});
|
|
203
|
-
}
|
|
184
|
+
messages.push({
|
|
185
|
+
role: "tool",
|
|
186
|
+
tool_call_id: toolResponse.toolCallId,
|
|
187
|
+
content: JSON.stringify(toolResponse.result)
|
|
188
|
+
});
|
|
204
189
|
}
|
|
205
190
|
break;
|
|
206
191
|
}
|
|
@@ -243,21 +228,72 @@ function mapOpenAIFinishReason(finishReason) {
|
|
|
243
228
|
}
|
|
244
229
|
}
|
|
245
230
|
|
|
246
|
-
// src/openai-
|
|
231
|
+
// src/openai-chat-options.ts
|
|
247
232
|
var import_zod = require("zod");
|
|
248
|
-
var
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
233
|
+
var openaiProviderOptions = import_zod.z.object({
|
|
234
|
+
/**
|
|
235
|
+
* Modify the likelihood of specified tokens appearing in the completion.
|
|
236
|
+
*
|
|
237
|
+
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
238
|
+
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
239
|
+
*/
|
|
240
|
+
logitBias: import_zod.z.record(import_zod.z.coerce.number(), import_zod.z.number()).optional(),
|
|
241
|
+
/**
|
|
242
|
+
* Return the log probabilities of the tokens.
|
|
243
|
+
*
|
|
244
|
+
* Setting to true will return the log probabilities of the tokens that
|
|
245
|
+
* were generated.
|
|
246
|
+
*
|
|
247
|
+
* Setting to a number will return the log probabilities of the top n
|
|
248
|
+
* tokens that were generated.
|
|
249
|
+
*/
|
|
250
|
+
logprobs: import_zod.z.union([import_zod.z.boolean(), import_zod.z.number()]).optional(),
|
|
251
|
+
/**
|
|
252
|
+
* Whether to enable parallel function calling during tool use. Default to true.
|
|
253
|
+
*/
|
|
254
|
+
parallelToolCalls: import_zod.z.boolean().optional(),
|
|
255
|
+
/**
|
|
256
|
+
* A unique identifier representing your end-user, which can help OpenAI to
|
|
257
|
+
* monitor and detect abuse.
|
|
258
|
+
*/
|
|
259
|
+
user: import_zod.z.string().optional(),
|
|
260
|
+
/**
|
|
261
|
+
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
262
|
+
*/
|
|
263
|
+
reasoningEffort: import_zod.z.enum(["low", "medium", "high"]).optional(),
|
|
264
|
+
/**
|
|
265
|
+
* Maximum number of completion tokens to generate. Useful for reasoning models.
|
|
266
|
+
*/
|
|
267
|
+
maxCompletionTokens: import_zod.z.number().optional(),
|
|
268
|
+
/**
|
|
269
|
+
* Whether to enable persistence in responses API.
|
|
270
|
+
*/
|
|
271
|
+
store: import_zod.z.boolean().optional(),
|
|
272
|
+
/**
|
|
273
|
+
* Metadata to associate with the request.
|
|
274
|
+
*/
|
|
275
|
+
metadata: import_zod.z.record(import_zod.z.string()).optional(),
|
|
276
|
+
/**
|
|
277
|
+
* Parameters for prediction mode.
|
|
278
|
+
*/
|
|
279
|
+
prediction: import_zod.z.record(import_zod.z.any()).optional()
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// src/openai-error.ts
|
|
283
|
+
var import_zod2 = require("zod");
|
|
284
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
285
|
+
var openaiErrorDataSchema = import_zod2.z.object({
|
|
286
|
+
error: import_zod2.z.object({
|
|
287
|
+
message: import_zod2.z.string(),
|
|
252
288
|
// The additional information below is handled loosely to support
|
|
253
289
|
// OpenAI-compatible providers that have slightly different error
|
|
254
290
|
// responses:
|
|
255
|
-
type:
|
|
256
|
-
param:
|
|
257
|
-
code:
|
|
291
|
+
type: import_zod2.z.string().nullish(),
|
|
292
|
+
param: import_zod2.z.any().nullish(),
|
|
293
|
+
code: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number()]).nullish()
|
|
258
294
|
})
|
|
259
295
|
});
|
|
260
|
-
var openaiFailedResponseHandler = (0,
|
|
296
|
+
var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
|
|
261
297
|
errorSchema: openaiErrorDataSchema,
|
|
262
298
|
errorToMessage: (data) => data.error.message
|
|
263
299
|
});
|
|
@@ -280,7 +316,6 @@ var import_provider2 = require("@ai-sdk/provider");
|
|
|
280
316
|
function prepareTools({
|
|
281
317
|
tools,
|
|
282
318
|
toolChoice,
|
|
283
|
-
useLegacyFunctionCalling = false,
|
|
284
319
|
structuredOutputs
|
|
285
320
|
}) {
|
|
286
321
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
@@ -288,48 +323,6 @@ function prepareTools({
|
|
|
288
323
|
if (tools == null) {
|
|
289
324
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
290
325
|
}
|
|
291
|
-
if (useLegacyFunctionCalling) {
|
|
292
|
-
const openaiFunctions = [];
|
|
293
|
-
for (const tool of tools) {
|
|
294
|
-
if (tool.type === "provider-defined") {
|
|
295
|
-
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
296
|
-
} else {
|
|
297
|
-
openaiFunctions.push({
|
|
298
|
-
name: tool.name,
|
|
299
|
-
description: tool.description,
|
|
300
|
-
parameters: tool.parameters
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
if (toolChoice == null) {
|
|
305
|
-
return {
|
|
306
|
-
functions: openaiFunctions,
|
|
307
|
-
function_call: void 0,
|
|
308
|
-
toolWarnings
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
const type2 = toolChoice.type;
|
|
312
|
-
switch (type2) {
|
|
313
|
-
case "auto":
|
|
314
|
-
case "none":
|
|
315
|
-
case void 0:
|
|
316
|
-
return {
|
|
317
|
-
functions: openaiFunctions,
|
|
318
|
-
function_call: void 0,
|
|
319
|
-
toolWarnings
|
|
320
|
-
};
|
|
321
|
-
case "required":
|
|
322
|
-
throw new import_provider2.UnsupportedFunctionalityError({
|
|
323
|
-
functionality: "useLegacyFunctionCalling and toolChoice: required"
|
|
324
|
-
});
|
|
325
|
-
default:
|
|
326
|
-
return {
|
|
327
|
-
functions: openaiFunctions,
|
|
328
|
-
function_call: { name: toolChoice.toolName },
|
|
329
|
-
toolWarnings
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
326
|
const openaiTools2 = [];
|
|
334
327
|
for (const tool of tools) {
|
|
335
328
|
if (tool.type === "provider-defined") {
|
|
@@ -401,7 +394,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
401
394
|
}
|
|
402
395
|
getArgs({
|
|
403
396
|
prompt,
|
|
404
|
-
|
|
397
|
+
maxOutputTokens,
|
|
405
398
|
temperature,
|
|
406
399
|
topP,
|
|
407
400
|
topK,
|
|
@@ -414,8 +407,13 @@ var OpenAIChatLanguageModel = class {
|
|
|
414
407
|
toolChoice,
|
|
415
408
|
providerOptions
|
|
416
409
|
}) {
|
|
417
|
-
var _a, _b
|
|
410
|
+
var _a, _b;
|
|
418
411
|
const warnings = [];
|
|
412
|
+
const openaiOptions = (_a = (0, import_provider_utils3.parseProviderOptions)({
|
|
413
|
+
provider: "openai",
|
|
414
|
+
providerOptions,
|
|
415
|
+
schema: openaiProviderOptions
|
|
416
|
+
})) != null ? _a : {};
|
|
419
417
|
if (topK != null) {
|
|
420
418
|
warnings.push({
|
|
421
419
|
type: "unsupported-setting",
|
|
@@ -429,21 +427,9 @@ var OpenAIChatLanguageModel = class {
|
|
|
429
427
|
details: "JSON response format schema is only supported with structuredOutputs"
|
|
430
428
|
});
|
|
431
429
|
}
|
|
432
|
-
const useLegacyFunctionCalling = this.settings.useLegacyFunctionCalling;
|
|
433
|
-
if (useLegacyFunctionCalling && this.settings.parallelToolCalls === true) {
|
|
434
|
-
throw new import_provider3.UnsupportedFunctionalityError({
|
|
435
|
-
functionality: "useLegacyFunctionCalling with parallelToolCalls"
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
if (useLegacyFunctionCalling && this.supportsStructuredOutputs) {
|
|
439
|
-
throw new import_provider3.UnsupportedFunctionalityError({
|
|
440
|
-
functionality: "structuredOutputs with useLegacyFunctionCalling"
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
430
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
|
|
444
431
|
{
|
|
445
432
|
prompt,
|
|
446
|
-
useLegacyFunctionCalling,
|
|
447
433
|
systemMessageMode: getSystemMessageMode(this.modelId)
|
|
448
434
|
}
|
|
449
435
|
);
|
|
@@ -452,13 +438,13 @@ var OpenAIChatLanguageModel = class {
|
|
|
452
438
|
// model id:
|
|
453
439
|
model: this.modelId,
|
|
454
440
|
// model specific settings:
|
|
455
|
-
logit_bias:
|
|
456
|
-
logprobs:
|
|
457
|
-
top_logprobs: typeof
|
|
458
|
-
user:
|
|
459
|
-
parallel_tool_calls:
|
|
441
|
+
logit_bias: openaiOptions.logitBias,
|
|
442
|
+
logprobs: openaiOptions.logprobs === true || typeof openaiOptions.logprobs === "number" ? true : void 0,
|
|
443
|
+
top_logprobs: typeof openaiOptions.logprobs === "number" ? openaiOptions.logprobs : typeof openaiOptions.logprobs === "boolean" ? openaiOptions.logprobs ? 0 : void 0 : void 0,
|
|
444
|
+
user: openaiOptions.user,
|
|
445
|
+
parallel_tool_calls: openaiOptions.parallelToolCalls,
|
|
460
446
|
// standardized settings:
|
|
461
|
-
max_tokens:
|
|
447
|
+
max_tokens: maxOutputTokens,
|
|
462
448
|
temperature,
|
|
463
449
|
top_p: topP,
|
|
464
450
|
frequency_penalty: frequencyPenalty,
|
|
@@ -469,19 +455,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
469
455
|
json_schema: {
|
|
470
456
|
schema: responseFormat.schema,
|
|
471
457
|
strict: true,
|
|
472
|
-
name: (
|
|
458
|
+
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
473
459
|
description: responseFormat.description
|
|
474
460
|
}
|
|
475
461
|
} : { type: "json_object" } : void 0,
|
|
476
462
|
stop: stopSequences,
|
|
477
463
|
seed,
|
|
478
464
|
// openai specific settings:
|
|
479
|
-
// TODO remove in next major version; we auto-map
|
|
480
|
-
max_completion_tokens:
|
|
481
|
-
store:
|
|
482
|
-
metadata:
|
|
483
|
-
prediction:
|
|
484
|
-
reasoning_effort:
|
|
465
|
+
// TODO remove in next major version; we auto-map maxOutputTokens now
|
|
466
|
+
max_completion_tokens: openaiOptions.maxCompletionTokens,
|
|
467
|
+
store: openaiOptions.store,
|
|
468
|
+
metadata: openaiOptions.metadata,
|
|
469
|
+
prediction: openaiOptions.prediction,
|
|
470
|
+
reasoning_effort: openaiOptions.reasoningEffort,
|
|
485
471
|
// messages:
|
|
486
472
|
messages
|
|
487
473
|
};
|
|
@@ -545,26 +531,30 @@ var OpenAIChatLanguageModel = class {
|
|
|
545
531
|
}
|
|
546
532
|
baseArgs.max_tokens = void 0;
|
|
547
533
|
}
|
|
534
|
+
} else if (this.modelId.startsWith("gpt-4o-search-preview")) {
|
|
535
|
+
if (baseArgs.temperature != null) {
|
|
536
|
+
baseArgs.temperature = void 0;
|
|
537
|
+
warnings.push({
|
|
538
|
+
type: "unsupported-setting",
|
|
539
|
+
setting: "temperature",
|
|
540
|
+
details: "temperature is not supported for the gpt-4o-search-preview model and has been removed."
|
|
541
|
+
});
|
|
542
|
+
}
|
|
548
543
|
}
|
|
549
544
|
const {
|
|
550
545
|
tools: openaiTools2,
|
|
551
546
|
toolChoice: openaiToolChoice,
|
|
552
|
-
functions,
|
|
553
|
-
function_call,
|
|
554
547
|
toolWarnings
|
|
555
548
|
} = prepareTools({
|
|
556
549
|
tools,
|
|
557
550
|
toolChoice,
|
|
558
|
-
useLegacyFunctionCalling,
|
|
559
551
|
structuredOutputs: this.supportsStructuredOutputs
|
|
560
552
|
});
|
|
561
553
|
return {
|
|
562
554
|
args: {
|
|
563
555
|
...baseArgs,
|
|
564
556
|
tools: openaiTools2,
|
|
565
|
-
tool_choice: openaiToolChoice
|
|
566
|
-
functions,
|
|
567
|
-
function_call
|
|
557
|
+
tool_choice: openaiToolChoice
|
|
568
558
|
},
|
|
569
559
|
warnings: [...warnings, ...toolWarnings]
|
|
570
560
|
};
|
|
@@ -576,15 +566,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
576
566
|
responseHeaders,
|
|
577
567
|
value: response,
|
|
578
568
|
rawValue: rawResponse
|
|
579
|
-
} = await (0,
|
|
569
|
+
} = await (0, import_provider_utils3.postJsonToApi)({
|
|
580
570
|
url: this.config.url({
|
|
581
571
|
path: "/chat/completions",
|
|
582
572
|
modelId: this.modelId
|
|
583
573
|
}),
|
|
584
|
-
headers: (0,
|
|
574
|
+
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
|
|
585
575
|
body,
|
|
586
576
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
587
|
-
successfulResponseHandler: (0,
|
|
577
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
|
588
578
|
openaiChatResponseSchema
|
|
589
579
|
),
|
|
590
580
|
abortSignal: options.abortSignal,
|
|
@@ -609,26 +599,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
609
599
|
}
|
|
610
600
|
return {
|
|
611
601
|
text: (_c = choice.message.content) != null ? _c : void 0,
|
|
612
|
-
toolCalls:
|
|
613
|
-
{
|
|
614
|
-
toolCallType: "function",
|
|
615
|
-
toolCallId: (0, import_provider_utils2.generateId)(),
|
|
616
|
-
toolName: choice.message.function_call.name,
|
|
617
|
-
args: choice.message.function_call.arguments
|
|
618
|
-
}
|
|
619
|
-
] : (_d = choice.message.tool_calls) == null ? void 0 : _d.map((toolCall) => {
|
|
602
|
+
toolCalls: (_d = choice.message.tool_calls) == null ? void 0 : _d.map((toolCall) => {
|
|
620
603
|
var _a2;
|
|
621
604
|
return {
|
|
622
605
|
toolCallType: "function",
|
|
623
|
-
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0,
|
|
606
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils3.generateId)(),
|
|
624
607
|
toolName: toolCall.function.name,
|
|
625
608
|
args: toolCall.function.arguments
|
|
626
609
|
};
|
|
627
610
|
}),
|
|
628
611
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
629
612
|
usage: {
|
|
630
|
-
|
|
631
|
-
|
|
613
|
+
inputTokens: (_f = (_e = response.usage) == null ? void 0 : _e.prompt_tokens) != null ? _f : void 0,
|
|
614
|
+
outputTokens: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0
|
|
632
615
|
},
|
|
633
616
|
request: { body },
|
|
634
617
|
response: {
|
|
@@ -642,48 +625,6 @@ var OpenAIChatLanguageModel = class {
|
|
|
642
625
|
};
|
|
643
626
|
}
|
|
644
627
|
async doStream(options) {
|
|
645
|
-
if (this.settings.simulateStreaming) {
|
|
646
|
-
const result = await this.doGenerate(options);
|
|
647
|
-
const simulatedStream = new ReadableStream({
|
|
648
|
-
start(controller) {
|
|
649
|
-
controller.enqueue({ type: "response-metadata", ...result.response });
|
|
650
|
-
if (result.text) {
|
|
651
|
-
controller.enqueue({
|
|
652
|
-
type: "text-delta",
|
|
653
|
-
textDelta: result.text
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
if (result.toolCalls) {
|
|
657
|
-
for (const toolCall of result.toolCalls) {
|
|
658
|
-
controller.enqueue({
|
|
659
|
-
type: "tool-call-delta",
|
|
660
|
-
toolCallType: "function",
|
|
661
|
-
toolCallId: toolCall.toolCallId,
|
|
662
|
-
toolName: toolCall.toolName,
|
|
663
|
-
argsTextDelta: toolCall.args
|
|
664
|
-
});
|
|
665
|
-
controller.enqueue({
|
|
666
|
-
type: "tool-call",
|
|
667
|
-
...toolCall
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
controller.enqueue({
|
|
672
|
-
type: "finish",
|
|
673
|
-
finishReason: result.finishReason,
|
|
674
|
-
usage: result.usage,
|
|
675
|
-
logprobs: result.logprobs,
|
|
676
|
-
providerMetadata: result.providerMetadata
|
|
677
|
-
});
|
|
678
|
-
controller.close();
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
return {
|
|
682
|
-
stream: simulatedStream,
|
|
683
|
-
response: result.response,
|
|
684
|
-
warnings: result.warnings
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
628
|
const { args, warnings } = this.getArgs(options);
|
|
688
629
|
const body = {
|
|
689
630
|
...args,
|
|
@@ -691,15 +632,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
691
632
|
// only include stream_options when in strict compatibility mode:
|
|
692
633
|
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
693
634
|
};
|
|
694
|
-
const { responseHeaders, value: response } = await (0,
|
|
635
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
|
695
636
|
url: this.config.url({
|
|
696
637
|
path: "/chat/completions",
|
|
697
638
|
modelId: this.modelId
|
|
698
639
|
}),
|
|
699
|
-
headers: (0,
|
|
640
|
+
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
|
|
700
641
|
body,
|
|
701
642
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
702
|
-
successfulResponseHandler: (0,
|
|
643
|
+
successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(
|
|
703
644
|
openaiChatChunkSchema
|
|
704
645
|
),
|
|
705
646
|
abortSignal: options.abortSignal,
|
|
@@ -708,13 +649,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
708
649
|
const { messages: rawPrompt, ...rawSettings } = args;
|
|
709
650
|
const toolCalls = [];
|
|
710
651
|
let finishReason = "unknown";
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
652
|
+
const usage = {
|
|
653
|
+
inputTokens: void 0,
|
|
654
|
+
outputTokens: void 0
|
|
714
655
|
};
|
|
715
656
|
let logprobs;
|
|
716
657
|
let isFirstChunk = true;
|
|
717
|
-
const { useLegacyFunctionCalling } = this.settings;
|
|
718
658
|
const providerMetadata = { openai: {} };
|
|
719
659
|
return {
|
|
720
660
|
stream: response.pipeThrough(
|
|
@@ -746,10 +686,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
746
686
|
prompt_tokens_details,
|
|
747
687
|
completion_tokens_details
|
|
748
688
|
} = value.usage;
|
|
749
|
-
usage =
|
|
750
|
-
|
|
751
|
-
completionTokens: completion_tokens != null ? completion_tokens : void 0
|
|
752
|
-
};
|
|
689
|
+
usage.inputTokens = prompt_tokens != null ? prompt_tokens : void 0;
|
|
690
|
+
usage.outputTokens = completion_tokens != null ? completion_tokens : void 0;
|
|
753
691
|
if ((completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens) != null) {
|
|
754
692
|
providerMetadata.openai.reasoningTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens;
|
|
755
693
|
}
|
|
@@ -784,16 +722,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
784
722
|
if (logprobs === void 0) logprobs = [];
|
|
785
723
|
logprobs.push(...mappedLogprobs);
|
|
786
724
|
}
|
|
787
|
-
|
|
788
|
-
{
|
|
789
|
-
type: "function",
|
|
790
|
-
id: (0, import_provider_utils2.generateId)(),
|
|
791
|
-
function: delta.function_call,
|
|
792
|
-
index: 0
|
|
793
|
-
}
|
|
794
|
-
] : delta.tool_calls;
|
|
795
|
-
if (mappedToolCalls != null) {
|
|
796
|
-
for (const toolCallDelta of mappedToolCalls) {
|
|
725
|
+
if (delta.tool_calls != null) {
|
|
726
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
797
727
|
const index = toolCallDelta.index;
|
|
798
728
|
if (toolCalls[index] == null) {
|
|
799
729
|
if (toolCallDelta.type !== "function") {
|
|
@@ -834,11 +764,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
834
764
|
argsTextDelta: toolCall2.function.arguments
|
|
835
765
|
});
|
|
836
766
|
}
|
|
837
|
-
if ((0,
|
|
767
|
+
if ((0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) {
|
|
838
768
|
controller.enqueue({
|
|
839
769
|
type: "tool-call",
|
|
840
770
|
toolCallType: "function",
|
|
841
|
-
toolCallId: (_e = toolCall2.id) != null ? _e : (0,
|
|
771
|
+
toolCallId: (_e = toolCall2.id) != null ? _e : (0, import_provider_utils3.generateId)(),
|
|
842
772
|
toolName: toolCall2.function.name,
|
|
843
773
|
args: toolCall2.function.arguments
|
|
844
774
|
});
|
|
@@ -861,11 +791,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
861
791
|
toolName: toolCall.function.name,
|
|
862
792
|
argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
|
|
863
793
|
});
|
|
864
|
-
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && (0,
|
|
794
|
+
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) {
|
|
865
795
|
controller.enqueue({
|
|
866
796
|
type: "tool-call",
|
|
867
797
|
toolCallType: "function",
|
|
868
|
-
toolCallId: (_l = toolCall.id) != null ? _l : (0,
|
|
798
|
+
toolCallId: (_l = toolCall.id) != null ? _l : (0, import_provider_utils3.generateId)(),
|
|
869
799
|
toolName: toolCall.function.name,
|
|
870
800
|
args: toolCall.function.arguments
|
|
871
801
|
});
|
|
@@ -875,15 +805,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
875
805
|
}
|
|
876
806
|
},
|
|
877
807
|
flush(controller) {
|
|
878
|
-
var _a, _b;
|
|
879
808
|
controller.enqueue({
|
|
880
809
|
type: "finish",
|
|
881
810
|
finishReason,
|
|
882
811
|
logprobs,
|
|
883
|
-
usage
|
|
884
|
-
promptTokens: (_a = usage.promptTokens) != null ? _a : NaN,
|
|
885
|
-
completionTokens: (_b = usage.completionTokens) != null ? _b : NaN
|
|
886
|
-
},
|
|
812
|
+
usage,
|
|
887
813
|
...providerMetadata != null ? { providerMetadata } : {}
|
|
888
814
|
});
|
|
889
815
|
}
|
|
@@ -895,104 +821,96 @@ var OpenAIChatLanguageModel = class {
|
|
|
895
821
|
};
|
|
896
822
|
}
|
|
897
823
|
};
|
|
898
|
-
var openaiTokenUsageSchema =
|
|
899
|
-
prompt_tokens:
|
|
900
|
-
completion_tokens:
|
|
901
|
-
prompt_tokens_details:
|
|
902
|
-
cached_tokens:
|
|
824
|
+
var openaiTokenUsageSchema = import_zod3.z.object({
|
|
825
|
+
prompt_tokens: import_zod3.z.number().nullish(),
|
|
826
|
+
completion_tokens: import_zod3.z.number().nullish(),
|
|
827
|
+
prompt_tokens_details: import_zod3.z.object({
|
|
828
|
+
cached_tokens: import_zod3.z.number().nullish()
|
|
903
829
|
}).nullish(),
|
|
904
|
-
completion_tokens_details:
|
|
905
|
-
reasoning_tokens:
|
|
906
|
-
accepted_prediction_tokens:
|
|
907
|
-
rejected_prediction_tokens:
|
|
830
|
+
completion_tokens_details: import_zod3.z.object({
|
|
831
|
+
reasoning_tokens: import_zod3.z.number().nullish(),
|
|
832
|
+
accepted_prediction_tokens: import_zod3.z.number().nullish(),
|
|
833
|
+
rejected_prediction_tokens: import_zod3.z.number().nullish()
|
|
908
834
|
}).nullish()
|
|
909
835
|
}).nullish();
|
|
910
|
-
var openaiChatResponseSchema =
|
|
911
|
-
id:
|
|
912
|
-
created:
|
|
913
|
-
model:
|
|
914
|
-
choices:
|
|
915
|
-
|
|
916
|
-
message:
|
|
917
|
-
role:
|
|
918
|
-
content:
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
type: import_zod2.z.literal("function"),
|
|
927
|
-
function: import_zod2.z.object({
|
|
928
|
-
name: import_zod2.z.string(),
|
|
929
|
-
arguments: import_zod2.z.string()
|
|
836
|
+
var openaiChatResponseSchema = import_zod3.z.object({
|
|
837
|
+
id: import_zod3.z.string().nullish(),
|
|
838
|
+
created: import_zod3.z.number().nullish(),
|
|
839
|
+
model: import_zod3.z.string().nullish(),
|
|
840
|
+
choices: import_zod3.z.array(
|
|
841
|
+
import_zod3.z.object({
|
|
842
|
+
message: import_zod3.z.object({
|
|
843
|
+
role: import_zod3.z.literal("assistant").nullish(),
|
|
844
|
+
content: import_zod3.z.string().nullish(),
|
|
845
|
+
tool_calls: import_zod3.z.array(
|
|
846
|
+
import_zod3.z.object({
|
|
847
|
+
id: import_zod3.z.string().nullish(),
|
|
848
|
+
type: import_zod3.z.literal("function"),
|
|
849
|
+
function: import_zod3.z.object({
|
|
850
|
+
name: import_zod3.z.string(),
|
|
851
|
+
arguments: import_zod3.z.string()
|
|
930
852
|
})
|
|
931
853
|
})
|
|
932
854
|
).nullish()
|
|
933
855
|
}),
|
|
934
|
-
index:
|
|
935
|
-
logprobs:
|
|
936
|
-
content:
|
|
937
|
-
|
|
938
|
-
token:
|
|
939
|
-
logprob:
|
|
940
|
-
top_logprobs:
|
|
941
|
-
|
|
942
|
-
token:
|
|
943
|
-
logprob:
|
|
856
|
+
index: import_zod3.z.number(),
|
|
857
|
+
logprobs: import_zod3.z.object({
|
|
858
|
+
content: import_zod3.z.array(
|
|
859
|
+
import_zod3.z.object({
|
|
860
|
+
token: import_zod3.z.string(),
|
|
861
|
+
logprob: import_zod3.z.number(),
|
|
862
|
+
top_logprobs: import_zod3.z.array(
|
|
863
|
+
import_zod3.z.object({
|
|
864
|
+
token: import_zod3.z.string(),
|
|
865
|
+
logprob: import_zod3.z.number()
|
|
944
866
|
})
|
|
945
867
|
)
|
|
946
868
|
})
|
|
947
869
|
).nullable()
|
|
948
870
|
}).nullish(),
|
|
949
|
-
finish_reason:
|
|
871
|
+
finish_reason: import_zod3.z.string().nullish()
|
|
950
872
|
})
|
|
951
873
|
),
|
|
952
874
|
usage: openaiTokenUsageSchema
|
|
953
875
|
});
|
|
954
|
-
var openaiChatChunkSchema =
|
|
955
|
-
|
|
956
|
-
id:
|
|
957
|
-
created:
|
|
958
|
-
model:
|
|
959
|
-
choices:
|
|
960
|
-
|
|
961
|
-
delta:
|
|
962
|
-
role:
|
|
963
|
-
content:
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
type: import_zod2.z.literal("function").optional(),
|
|
973
|
-
function: import_zod2.z.object({
|
|
974
|
-
name: import_zod2.z.string().nullish(),
|
|
975
|
-
arguments: import_zod2.z.string().nullish()
|
|
876
|
+
var openaiChatChunkSchema = import_zod3.z.union([
|
|
877
|
+
import_zod3.z.object({
|
|
878
|
+
id: import_zod3.z.string().nullish(),
|
|
879
|
+
created: import_zod3.z.number().nullish(),
|
|
880
|
+
model: import_zod3.z.string().nullish(),
|
|
881
|
+
choices: import_zod3.z.array(
|
|
882
|
+
import_zod3.z.object({
|
|
883
|
+
delta: import_zod3.z.object({
|
|
884
|
+
role: import_zod3.z.enum(["assistant"]).nullish(),
|
|
885
|
+
content: import_zod3.z.string().nullish(),
|
|
886
|
+
tool_calls: import_zod3.z.array(
|
|
887
|
+
import_zod3.z.object({
|
|
888
|
+
index: import_zod3.z.number(),
|
|
889
|
+
id: import_zod3.z.string().nullish(),
|
|
890
|
+
type: import_zod3.z.literal("function").optional(),
|
|
891
|
+
function: import_zod3.z.object({
|
|
892
|
+
name: import_zod3.z.string().nullish(),
|
|
893
|
+
arguments: import_zod3.z.string().nullish()
|
|
976
894
|
})
|
|
977
895
|
})
|
|
978
896
|
).nullish()
|
|
979
897
|
}).nullish(),
|
|
980
|
-
logprobs:
|
|
981
|
-
content:
|
|
982
|
-
|
|
983
|
-
token:
|
|
984
|
-
logprob:
|
|
985
|
-
top_logprobs:
|
|
986
|
-
|
|
987
|
-
token:
|
|
988
|
-
logprob:
|
|
898
|
+
logprobs: import_zod3.z.object({
|
|
899
|
+
content: import_zod3.z.array(
|
|
900
|
+
import_zod3.z.object({
|
|
901
|
+
token: import_zod3.z.string(),
|
|
902
|
+
logprob: import_zod3.z.number(),
|
|
903
|
+
top_logprobs: import_zod3.z.array(
|
|
904
|
+
import_zod3.z.object({
|
|
905
|
+
token: import_zod3.z.string(),
|
|
906
|
+
logprob: import_zod3.z.number()
|
|
989
907
|
})
|
|
990
908
|
)
|
|
991
909
|
})
|
|
992
910
|
).nullable()
|
|
993
911
|
}).nullish(),
|
|
994
|
-
finish_reason:
|
|
995
|
-
index:
|
|
912
|
+
finish_reason: import_zod3.z.string().nullable().optional(),
|
|
913
|
+
index: import_zod3.z.number()
|
|
996
914
|
})
|
|
997
915
|
),
|
|
998
916
|
usage: openaiTokenUsageSchema
|
|
@@ -1034,8 +952,8 @@ var reasoningModels = {
|
|
|
1034
952
|
};
|
|
1035
953
|
|
|
1036
954
|
// src/openai-completion-language-model.ts
|
|
1037
|
-
var
|
|
1038
|
-
var
|
|
955
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
956
|
+
var import_zod4 = require("zod");
|
|
1039
957
|
|
|
1040
958
|
// src/convert-to-openai-completion-prompt.ts
|
|
1041
959
|
var import_provider4 = require("@ai-sdk/provider");
|
|
@@ -1145,7 +1063,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1145
1063
|
getArgs({
|
|
1146
1064
|
inputFormat,
|
|
1147
1065
|
prompt,
|
|
1148
|
-
|
|
1066
|
+
maxOutputTokens,
|
|
1149
1067
|
temperature,
|
|
1150
1068
|
topP,
|
|
1151
1069
|
topK,
|
|
@@ -1187,7 +1105,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1187
1105
|
suffix: this.settings.suffix,
|
|
1188
1106
|
user: this.settings.user,
|
|
1189
1107
|
// standardized settings:
|
|
1190
|
-
max_tokens:
|
|
1108
|
+
max_tokens: maxOutputTokens,
|
|
1191
1109
|
temperature,
|
|
1192
1110
|
top_p: topP,
|
|
1193
1111
|
frequency_penalty: frequencyPenalty,
|
|
@@ -1207,15 +1125,15 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1207
1125
|
responseHeaders,
|
|
1208
1126
|
value: response,
|
|
1209
1127
|
rawValue: rawResponse
|
|
1210
|
-
} = await (0,
|
|
1128
|
+
} = await (0, import_provider_utils4.postJsonToApi)({
|
|
1211
1129
|
url: this.config.url({
|
|
1212
1130
|
path: "/completions",
|
|
1213
1131
|
modelId: this.modelId
|
|
1214
1132
|
}),
|
|
1215
|
-
headers: (0,
|
|
1133
|
+
headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
|
|
1216
1134
|
body: args,
|
|
1217
1135
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1218
|
-
successfulResponseHandler: (0,
|
|
1136
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
|
1219
1137
|
openaiCompletionResponseSchema
|
|
1220
1138
|
),
|
|
1221
1139
|
abortSignal: options.abortSignal,
|
|
@@ -1225,8 +1143,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1225
1143
|
return {
|
|
1226
1144
|
text: choice.text,
|
|
1227
1145
|
usage: {
|
|
1228
|
-
|
|
1229
|
-
|
|
1146
|
+
inputTokens: response.usage.prompt_tokens,
|
|
1147
|
+
outputTokens: response.usage.completion_tokens
|
|
1230
1148
|
},
|
|
1231
1149
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
1232
1150
|
logprobs: mapOpenAICompletionLogProbs(choice.logprobs),
|
|
@@ -1247,24 +1165,24 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1247
1165
|
// only include stream_options when in strict compatibility mode:
|
|
1248
1166
|
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
1249
1167
|
};
|
|
1250
|
-
const { responseHeaders, value: response } = await (0,
|
|
1168
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
|
1251
1169
|
url: this.config.url({
|
|
1252
1170
|
path: "/completions",
|
|
1253
1171
|
modelId: this.modelId
|
|
1254
1172
|
}),
|
|
1255
|
-
headers: (0,
|
|
1173
|
+
headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
|
|
1256
1174
|
body,
|
|
1257
1175
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1258
|
-
successfulResponseHandler: (0,
|
|
1176
|
+
successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(
|
|
1259
1177
|
openaiCompletionChunkSchema
|
|
1260
1178
|
),
|
|
1261
1179
|
abortSignal: options.abortSignal,
|
|
1262
1180
|
fetch: this.config.fetch
|
|
1263
1181
|
});
|
|
1264
1182
|
let finishReason = "unknown";
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1183
|
+
const usage = {
|
|
1184
|
+
inputTokens: void 0,
|
|
1185
|
+
outputTokens: void 0
|
|
1268
1186
|
};
|
|
1269
1187
|
let logprobs;
|
|
1270
1188
|
let isFirstChunk = true;
|
|
@@ -1291,10 +1209,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1291
1209
|
});
|
|
1292
1210
|
}
|
|
1293
1211
|
if (value.usage != null) {
|
|
1294
|
-
usage =
|
|
1295
|
-
|
|
1296
|
-
completionTokens: value.usage.completion_tokens
|
|
1297
|
-
};
|
|
1212
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
1213
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
1298
1214
|
}
|
|
1299
1215
|
const choice = value.choices[0];
|
|
1300
1216
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
@@ -1330,46 +1246,46 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1330
1246
|
};
|
|
1331
1247
|
}
|
|
1332
1248
|
};
|
|
1333
|
-
var openaiCompletionResponseSchema =
|
|
1334
|
-
id:
|
|
1335
|
-
created:
|
|
1336
|
-
model:
|
|
1337
|
-
choices:
|
|
1338
|
-
|
|
1339
|
-
text:
|
|
1340
|
-
finish_reason:
|
|
1341
|
-
logprobs:
|
|
1342
|
-
tokens:
|
|
1343
|
-
token_logprobs:
|
|
1344
|
-
top_logprobs:
|
|
1249
|
+
var openaiCompletionResponseSchema = import_zod4.z.object({
|
|
1250
|
+
id: import_zod4.z.string().nullish(),
|
|
1251
|
+
created: import_zod4.z.number().nullish(),
|
|
1252
|
+
model: import_zod4.z.string().nullish(),
|
|
1253
|
+
choices: import_zod4.z.array(
|
|
1254
|
+
import_zod4.z.object({
|
|
1255
|
+
text: import_zod4.z.string(),
|
|
1256
|
+
finish_reason: import_zod4.z.string(),
|
|
1257
|
+
logprobs: import_zod4.z.object({
|
|
1258
|
+
tokens: import_zod4.z.array(import_zod4.z.string()),
|
|
1259
|
+
token_logprobs: import_zod4.z.array(import_zod4.z.number()),
|
|
1260
|
+
top_logprobs: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number())).nullable()
|
|
1345
1261
|
}).nullish()
|
|
1346
1262
|
})
|
|
1347
1263
|
),
|
|
1348
|
-
usage:
|
|
1349
|
-
prompt_tokens:
|
|
1350
|
-
completion_tokens:
|
|
1264
|
+
usage: import_zod4.z.object({
|
|
1265
|
+
prompt_tokens: import_zod4.z.number(),
|
|
1266
|
+
completion_tokens: import_zod4.z.number()
|
|
1351
1267
|
})
|
|
1352
1268
|
});
|
|
1353
|
-
var openaiCompletionChunkSchema =
|
|
1354
|
-
|
|
1355
|
-
id:
|
|
1356
|
-
created:
|
|
1357
|
-
model:
|
|
1358
|
-
choices:
|
|
1359
|
-
|
|
1360
|
-
text:
|
|
1361
|
-
finish_reason:
|
|
1362
|
-
index:
|
|
1363
|
-
logprobs:
|
|
1364
|
-
tokens:
|
|
1365
|
-
token_logprobs:
|
|
1366
|
-
top_logprobs:
|
|
1269
|
+
var openaiCompletionChunkSchema = import_zod4.z.union([
|
|
1270
|
+
import_zod4.z.object({
|
|
1271
|
+
id: import_zod4.z.string().nullish(),
|
|
1272
|
+
created: import_zod4.z.number().nullish(),
|
|
1273
|
+
model: import_zod4.z.string().nullish(),
|
|
1274
|
+
choices: import_zod4.z.array(
|
|
1275
|
+
import_zod4.z.object({
|
|
1276
|
+
text: import_zod4.z.string(),
|
|
1277
|
+
finish_reason: import_zod4.z.string().nullish(),
|
|
1278
|
+
index: import_zod4.z.number(),
|
|
1279
|
+
logprobs: import_zod4.z.object({
|
|
1280
|
+
tokens: import_zod4.z.array(import_zod4.z.string()),
|
|
1281
|
+
token_logprobs: import_zod4.z.array(import_zod4.z.number()),
|
|
1282
|
+
top_logprobs: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number())).nullable()
|
|
1367
1283
|
}).nullish()
|
|
1368
1284
|
})
|
|
1369
1285
|
),
|
|
1370
|
-
usage:
|
|
1371
|
-
prompt_tokens:
|
|
1372
|
-
completion_tokens:
|
|
1286
|
+
usage: import_zod4.z.object({
|
|
1287
|
+
prompt_tokens: import_zod4.z.number(),
|
|
1288
|
+
completion_tokens: import_zod4.z.number()
|
|
1373
1289
|
}).nullish()
|
|
1374
1290
|
}),
|
|
1375
1291
|
openaiErrorDataSchema
|
|
@@ -1377,8 +1293,8 @@ var openaiCompletionChunkSchema = import_zod3.z.union([
|
|
|
1377
1293
|
|
|
1378
1294
|
// src/openai-embedding-model.ts
|
|
1379
1295
|
var import_provider5 = require("@ai-sdk/provider");
|
|
1380
|
-
var
|
|
1381
|
-
var
|
|
1296
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
1297
|
+
var import_zod5 = require("zod");
|
|
1382
1298
|
var OpenAIEmbeddingModel = class {
|
|
1383
1299
|
constructor(modelId, settings, config) {
|
|
1384
1300
|
this.specificationVersion = "v1";
|
|
@@ -1410,12 +1326,12 @@ var OpenAIEmbeddingModel = class {
|
|
|
1410
1326
|
values
|
|
1411
1327
|
});
|
|
1412
1328
|
}
|
|
1413
|
-
const { responseHeaders, value: response } = await (0,
|
|
1329
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({
|
|
1414
1330
|
url: this.config.url({
|
|
1415
1331
|
path: "/embeddings",
|
|
1416
1332
|
modelId: this.modelId
|
|
1417
1333
|
}),
|
|
1418
|
-
headers: (0,
|
|
1334
|
+
headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), headers),
|
|
1419
1335
|
body: {
|
|
1420
1336
|
model: this.modelId,
|
|
1421
1337
|
input: values,
|
|
@@ -1424,7 +1340,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1424
1340
|
user: this.settings.user
|
|
1425
1341
|
},
|
|
1426
1342
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1427
|
-
successfulResponseHandler: (0,
|
|
1343
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
1428
1344
|
openaiTextEmbeddingResponseSchema
|
|
1429
1345
|
),
|
|
1430
1346
|
abortSignal,
|
|
@@ -1437,14 +1353,14 @@ var OpenAIEmbeddingModel = class {
|
|
|
1437
1353
|
};
|
|
1438
1354
|
}
|
|
1439
1355
|
};
|
|
1440
|
-
var openaiTextEmbeddingResponseSchema =
|
|
1441
|
-
data:
|
|
1442
|
-
usage:
|
|
1356
|
+
var openaiTextEmbeddingResponseSchema = import_zod5.z.object({
|
|
1357
|
+
data: import_zod5.z.array(import_zod5.z.object({ embedding: import_zod5.z.array(import_zod5.z.number()) })),
|
|
1358
|
+
usage: import_zod5.z.object({ prompt_tokens: import_zod5.z.number() }).nullish()
|
|
1443
1359
|
});
|
|
1444
1360
|
|
|
1445
1361
|
// src/openai-image-model.ts
|
|
1446
|
-
var
|
|
1447
|
-
var
|
|
1362
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1363
|
+
var import_zod6 = require("zod");
|
|
1448
1364
|
|
|
1449
1365
|
// src/openai-image-settings.ts
|
|
1450
1366
|
var modelMaxImagesPerCall = {
|
|
@@ -1490,12 +1406,12 @@ var OpenAIImageModel = class {
|
|
|
1490
1406
|
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
1491
1407
|
}
|
|
1492
1408
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1493
|
-
const { value: response, responseHeaders } = await (0,
|
|
1409
|
+
const { value: response, responseHeaders } = await (0, import_provider_utils6.postJsonToApi)({
|
|
1494
1410
|
url: this.config.url({
|
|
1495
1411
|
path: "/images/generations",
|
|
1496
1412
|
modelId: this.modelId
|
|
1497
1413
|
}),
|
|
1498
|
-
headers: (0,
|
|
1414
|
+
headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), headers),
|
|
1499
1415
|
body: {
|
|
1500
1416
|
model: this.modelId,
|
|
1501
1417
|
prompt,
|
|
@@ -1505,7 +1421,7 @@ var OpenAIImageModel = class {
|
|
|
1505
1421
|
response_format: "b64_json"
|
|
1506
1422
|
},
|
|
1507
1423
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1508
|
-
successfulResponseHandler: (0,
|
|
1424
|
+
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
|
|
1509
1425
|
openaiImageResponseSchema
|
|
1510
1426
|
),
|
|
1511
1427
|
abortSignal,
|
|
@@ -1522,13 +1438,13 @@ var OpenAIImageModel = class {
|
|
|
1522
1438
|
};
|
|
1523
1439
|
}
|
|
1524
1440
|
};
|
|
1525
|
-
var openaiImageResponseSchema =
|
|
1526
|
-
data:
|
|
1441
|
+
var openaiImageResponseSchema = import_zod6.z.object({
|
|
1442
|
+
data: import_zod6.z.array(import_zod6.z.object({ b64_json: import_zod6.z.string() }))
|
|
1527
1443
|
});
|
|
1528
1444
|
|
|
1529
1445
|
// src/openai-tools.ts
|
|
1530
|
-
var
|
|
1531
|
-
var WebSearchPreviewParameters =
|
|
1446
|
+
var import_zod7 = require("zod");
|
|
1447
|
+
var WebSearchPreviewParameters = import_zod7.z.object({});
|
|
1532
1448
|
function webSearchPreviewTool({
|
|
1533
1449
|
searchContextSize,
|
|
1534
1450
|
userLocation
|
|
@@ -1548,20 +1464,14 @@ var openaiTools = {
|
|
|
1548
1464
|
};
|
|
1549
1465
|
|
|
1550
1466
|
// src/openai-transcription-model.ts
|
|
1551
|
-
var
|
|
1552
|
-
var
|
|
1553
|
-
var OpenAIProviderOptionsSchema =
|
|
1554
|
-
include:
|
|
1555
|
-
|
|
1556
|
-
),
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
"An optional text to guide the model's style or continue a previous audio segment."
|
|
1560
|
-
),
|
|
1561
|
-
temperature: import_zod7.z.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
|
|
1562
|
-
timestampGranularities: import_zod7.z.array(import_zod7.z.enum(["word", "segment"])).optional().default(["segment"]).describe(
|
|
1563
|
-
"The timestamp granularities to populate for this transcription."
|
|
1564
|
-
)
|
|
1467
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1468
|
+
var import_zod8 = require("zod");
|
|
1469
|
+
var OpenAIProviderOptionsSchema = import_zod8.z.object({
|
|
1470
|
+
include: import_zod8.z.array(import_zod8.z.string()).nullish(),
|
|
1471
|
+
language: import_zod8.z.string().nullish(),
|
|
1472
|
+
prompt: import_zod8.z.string().nullish(),
|
|
1473
|
+
temperature: import_zod8.z.number().min(0).max(1).nullish().default(0),
|
|
1474
|
+
timestampGranularities: import_zod8.z.array(import_zod8.z.enum(["word", "segment"])).nullish().default(["segment"])
|
|
1565
1475
|
});
|
|
1566
1476
|
var languageMap = {
|
|
1567
1477
|
afrikaans: "af",
|
|
@@ -1636,28 +1546,29 @@ var OpenAITranscriptionModel = class {
|
|
|
1636
1546
|
mediaType,
|
|
1637
1547
|
providerOptions
|
|
1638
1548
|
}) {
|
|
1549
|
+
var _a, _b, _c, _d, _e;
|
|
1639
1550
|
const warnings = [];
|
|
1640
|
-
const openAIOptions = (0,
|
|
1551
|
+
const openAIOptions = (0, import_provider_utils7.parseProviderOptions)({
|
|
1641
1552
|
provider: "openai",
|
|
1642
1553
|
providerOptions,
|
|
1643
1554
|
schema: OpenAIProviderOptionsSchema
|
|
1644
1555
|
});
|
|
1645
1556
|
const formData = new FormData();
|
|
1646
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0,
|
|
1557
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
|
|
1647
1558
|
formData.append("model", this.modelId);
|
|
1648
1559
|
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1649
1560
|
if (openAIOptions) {
|
|
1650
1561
|
const transcriptionModelOptions = {
|
|
1651
|
-
include: openAIOptions.include,
|
|
1652
|
-
language: openAIOptions.language,
|
|
1653
|
-
prompt: openAIOptions.prompt,
|
|
1654
|
-
temperature: openAIOptions.temperature,
|
|
1655
|
-
timestamp_granularities: openAIOptions.timestampGranularities
|
|
1562
|
+
include: (_a = openAIOptions.include) != null ? _a : void 0,
|
|
1563
|
+
language: (_b = openAIOptions.language) != null ? _b : void 0,
|
|
1564
|
+
prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
|
|
1565
|
+
temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
|
|
1566
|
+
timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
|
|
1656
1567
|
};
|
|
1657
1568
|
for (const key in transcriptionModelOptions) {
|
|
1658
1569
|
const value = transcriptionModelOptions[key];
|
|
1659
1570
|
if (value !== void 0) {
|
|
1660
|
-
formData.append(key, value);
|
|
1571
|
+
formData.append(key, String(value));
|
|
1661
1572
|
}
|
|
1662
1573
|
}
|
|
1663
1574
|
}
|
|
@@ -1674,15 +1585,15 @@ var OpenAITranscriptionModel = class {
|
|
|
1674
1585
|
value: response,
|
|
1675
1586
|
responseHeaders,
|
|
1676
1587
|
rawValue: rawResponse
|
|
1677
|
-
} = await (0,
|
|
1588
|
+
} = await (0, import_provider_utils7.postFormDataToApi)({
|
|
1678
1589
|
url: this.config.url({
|
|
1679
1590
|
path: "/audio/transcriptions",
|
|
1680
1591
|
modelId: this.modelId
|
|
1681
1592
|
}),
|
|
1682
|
-
headers: (0,
|
|
1593
|
+
headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
|
|
1683
1594
|
formData,
|
|
1684
1595
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1685
|
-
successfulResponseHandler: (0,
|
|
1596
|
+
successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
|
|
1686
1597
|
openaiTranscriptionResponseSchema
|
|
1687
1598
|
),
|
|
1688
1599
|
abortSignal: options.abortSignal,
|
|
@@ -1708,22 +1619,22 @@ var OpenAITranscriptionModel = class {
|
|
|
1708
1619
|
};
|
|
1709
1620
|
}
|
|
1710
1621
|
};
|
|
1711
|
-
var openaiTranscriptionResponseSchema =
|
|
1712
|
-
text:
|
|
1713
|
-
language:
|
|
1714
|
-
duration:
|
|
1715
|
-
words:
|
|
1716
|
-
|
|
1717
|
-
word:
|
|
1718
|
-
start:
|
|
1719
|
-
end:
|
|
1622
|
+
var openaiTranscriptionResponseSchema = import_zod8.z.object({
|
|
1623
|
+
text: import_zod8.z.string(),
|
|
1624
|
+
language: import_zod8.z.string().nullish(),
|
|
1625
|
+
duration: import_zod8.z.number().nullish(),
|
|
1626
|
+
words: import_zod8.z.array(
|
|
1627
|
+
import_zod8.z.object({
|
|
1628
|
+
word: import_zod8.z.string(),
|
|
1629
|
+
start: import_zod8.z.number(),
|
|
1630
|
+
end: import_zod8.z.number()
|
|
1720
1631
|
})
|
|
1721
1632
|
).nullish()
|
|
1722
1633
|
});
|
|
1723
1634
|
|
|
1724
1635
|
// src/responses/openai-responses-language-model.ts
|
|
1725
|
-
var
|
|
1726
|
-
var
|
|
1636
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1637
|
+
var import_zod9 = require("zod");
|
|
1727
1638
|
|
|
1728
1639
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1729
1640
|
var import_provider6 = require("@ai-sdk/provider");
|
|
@@ -1940,7 +1851,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1940
1851
|
return this.config.provider;
|
|
1941
1852
|
}
|
|
1942
1853
|
getArgs({
|
|
1943
|
-
|
|
1854
|
+
maxOutputTokens,
|
|
1944
1855
|
temperature,
|
|
1945
1856
|
stopSequences,
|
|
1946
1857
|
topP,
|
|
@@ -1983,7 +1894,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1983
1894
|
systemMessageMode: modelConfig.systemMessageMode
|
|
1984
1895
|
});
|
|
1985
1896
|
warnings.push(...messageWarnings);
|
|
1986
|
-
const openaiOptions = (0,
|
|
1897
|
+
const openaiOptions = (0, import_provider_utils8.parseProviderOptions)({
|
|
1987
1898
|
provider: "openai",
|
|
1988
1899
|
providerOptions,
|
|
1989
1900
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -1994,7 +1905,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1994
1905
|
input: messages,
|
|
1995
1906
|
temperature,
|
|
1996
1907
|
top_p: topP,
|
|
1997
|
-
max_output_tokens:
|
|
1908
|
+
max_output_tokens: maxOutputTokens,
|
|
1998
1909
|
...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
|
|
1999
1910
|
text: {
|
|
2000
1911
|
format: responseFormat.schema != null ? {
|
|
@@ -2064,58 +1975,58 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2064
1975
|
responseHeaders,
|
|
2065
1976
|
value: response,
|
|
2066
1977
|
rawValue: rawResponse
|
|
2067
|
-
} = await (0,
|
|
1978
|
+
} = await (0, import_provider_utils8.postJsonToApi)({
|
|
2068
1979
|
url: this.config.url({
|
|
2069
1980
|
path: "/responses",
|
|
2070
1981
|
modelId: this.modelId
|
|
2071
1982
|
}),
|
|
2072
|
-
headers: (0,
|
|
1983
|
+
headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
|
|
2073
1984
|
body,
|
|
2074
1985
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2075
|
-
successfulResponseHandler: (0,
|
|
2076
|
-
|
|
2077
|
-
id:
|
|
2078
|
-
created_at:
|
|
2079
|
-
model:
|
|
2080
|
-
output:
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
type:
|
|
2084
|
-
role:
|
|
2085
|
-
content:
|
|
2086
|
-
|
|
2087
|
-
type:
|
|
2088
|
-
text:
|
|
2089
|
-
annotations:
|
|
2090
|
-
|
|
2091
|
-
type:
|
|
2092
|
-
start_index:
|
|
2093
|
-
end_index:
|
|
2094
|
-
url:
|
|
2095
|
-
title:
|
|
1986
|
+
successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
|
|
1987
|
+
import_zod9.z.object({
|
|
1988
|
+
id: import_zod9.z.string(),
|
|
1989
|
+
created_at: import_zod9.z.number(),
|
|
1990
|
+
model: import_zod9.z.string(),
|
|
1991
|
+
output: import_zod9.z.array(
|
|
1992
|
+
import_zod9.z.discriminatedUnion("type", [
|
|
1993
|
+
import_zod9.z.object({
|
|
1994
|
+
type: import_zod9.z.literal("message"),
|
|
1995
|
+
role: import_zod9.z.literal("assistant"),
|
|
1996
|
+
content: import_zod9.z.array(
|
|
1997
|
+
import_zod9.z.object({
|
|
1998
|
+
type: import_zod9.z.literal("output_text"),
|
|
1999
|
+
text: import_zod9.z.string(),
|
|
2000
|
+
annotations: import_zod9.z.array(
|
|
2001
|
+
import_zod9.z.object({
|
|
2002
|
+
type: import_zod9.z.literal("url_citation"),
|
|
2003
|
+
start_index: import_zod9.z.number(),
|
|
2004
|
+
end_index: import_zod9.z.number(),
|
|
2005
|
+
url: import_zod9.z.string(),
|
|
2006
|
+
title: import_zod9.z.string()
|
|
2096
2007
|
})
|
|
2097
2008
|
)
|
|
2098
2009
|
})
|
|
2099
2010
|
)
|
|
2100
2011
|
}),
|
|
2101
|
-
|
|
2102
|
-
type:
|
|
2103
|
-
call_id:
|
|
2104
|
-
name:
|
|
2105
|
-
arguments:
|
|
2012
|
+
import_zod9.z.object({
|
|
2013
|
+
type: import_zod9.z.literal("function_call"),
|
|
2014
|
+
call_id: import_zod9.z.string(),
|
|
2015
|
+
name: import_zod9.z.string(),
|
|
2016
|
+
arguments: import_zod9.z.string()
|
|
2106
2017
|
}),
|
|
2107
|
-
|
|
2108
|
-
type:
|
|
2018
|
+
import_zod9.z.object({
|
|
2019
|
+
type: import_zod9.z.literal("web_search_call")
|
|
2109
2020
|
}),
|
|
2110
|
-
|
|
2111
|
-
type:
|
|
2021
|
+
import_zod9.z.object({
|
|
2022
|
+
type: import_zod9.z.literal("computer_call")
|
|
2112
2023
|
}),
|
|
2113
|
-
|
|
2114
|
-
type:
|
|
2024
|
+
import_zod9.z.object({
|
|
2025
|
+
type: import_zod9.z.literal("reasoning")
|
|
2115
2026
|
})
|
|
2116
2027
|
])
|
|
2117
2028
|
),
|
|
2118
|
-
incomplete_details:
|
|
2029
|
+
incomplete_details: import_zod9.z.object({ reason: import_zod9.z.string() }).nullable(),
|
|
2119
2030
|
usage: usageSchema
|
|
2120
2031
|
})
|
|
2121
2032
|
),
|
|
@@ -2136,7 +2047,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2136
2047
|
var _a2, _b2, _c2;
|
|
2137
2048
|
return {
|
|
2138
2049
|
sourceType: "url",
|
|
2139
|
-
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0,
|
|
2050
|
+
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0, import_provider_utils8.generateId)(),
|
|
2140
2051
|
url: annotation.url,
|
|
2141
2052
|
title: annotation.title
|
|
2142
2053
|
};
|
|
@@ -2148,8 +2059,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2148
2059
|
}),
|
|
2149
2060
|
toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
2150
2061
|
usage: {
|
|
2151
|
-
|
|
2152
|
-
|
|
2062
|
+
inputTokens: response.usage.input_tokens,
|
|
2063
|
+
outputTokens: response.usage.output_tokens
|
|
2153
2064
|
},
|
|
2154
2065
|
request: { body },
|
|
2155
2066
|
response: {
|
|
@@ -2171,18 +2082,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2171
2082
|
}
|
|
2172
2083
|
async doStream(options) {
|
|
2173
2084
|
const { args: body, warnings } = this.getArgs(options);
|
|
2174
|
-
const { responseHeaders, value: response } = await (0,
|
|
2085
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils8.postJsonToApi)({
|
|
2175
2086
|
url: this.config.url({
|
|
2176
2087
|
path: "/responses",
|
|
2177
2088
|
modelId: this.modelId
|
|
2178
2089
|
}),
|
|
2179
|
-
headers: (0,
|
|
2090
|
+
headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
|
|
2180
2091
|
body: {
|
|
2181
2092
|
...body,
|
|
2182
2093
|
stream: true
|
|
2183
2094
|
},
|
|
2184
2095
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2185
|
-
successfulResponseHandler: (0,
|
|
2096
|
+
successfulResponseHandler: (0, import_provider_utils8.createEventSourceResponseHandler)(
|
|
2186
2097
|
openaiResponsesChunkSchema
|
|
2187
2098
|
),
|
|
2188
2099
|
abortSignal: options.abortSignal,
|
|
@@ -2190,8 +2101,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2190
2101
|
});
|
|
2191
2102
|
const self = this;
|
|
2192
2103
|
let finishReason = "unknown";
|
|
2193
|
-
|
|
2194
|
-
|
|
2104
|
+
const usage = {
|
|
2105
|
+
inputTokens: void 0,
|
|
2106
|
+
outputTokens: void 0
|
|
2107
|
+
};
|
|
2195
2108
|
let cachedPromptTokens = null;
|
|
2196
2109
|
let reasoningTokens = null;
|
|
2197
2110
|
let responseId = null;
|
|
@@ -2261,8 +2174,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2261
2174
|
finishReason: (_a = value.response.incomplete_details) == null ? void 0 : _a.reason,
|
|
2262
2175
|
hasToolCalls
|
|
2263
2176
|
});
|
|
2264
|
-
|
|
2265
|
-
|
|
2177
|
+
usage.inputTokens = value.response.usage.input_tokens;
|
|
2178
|
+
usage.outputTokens = value.response.usage.output_tokens;
|
|
2266
2179
|
cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
|
|
2267
2180
|
reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
|
|
2268
2181
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
@@ -2270,7 +2183,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2270
2183
|
type: "source",
|
|
2271
2184
|
source: {
|
|
2272
2185
|
sourceType: "url",
|
|
2273
|
-
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0,
|
|
2186
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils8.generateId)(),
|
|
2274
2187
|
url: value.annotation.url,
|
|
2275
2188
|
title: value.annotation.title
|
|
2276
2189
|
}
|
|
@@ -2281,7 +2194,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2281
2194
|
controller.enqueue({
|
|
2282
2195
|
type: "finish",
|
|
2283
2196
|
finishReason,
|
|
2284
|
-
usage
|
|
2197
|
+
usage,
|
|
2285
2198
|
...(cachedPromptTokens != null || reasoningTokens != null) && {
|
|
2286
2199
|
providerMetadata: {
|
|
2287
2200
|
openai: {
|
|
@@ -2301,79 +2214,79 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2301
2214
|
};
|
|
2302
2215
|
}
|
|
2303
2216
|
};
|
|
2304
|
-
var usageSchema =
|
|
2305
|
-
input_tokens:
|
|
2306
|
-
input_tokens_details:
|
|
2307
|
-
output_tokens:
|
|
2308
|
-
output_tokens_details:
|
|
2217
|
+
var usageSchema = import_zod9.z.object({
|
|
2218
|
+
input_tokens: import_zod9.z.number(),
|
|
2219
|
+
input_tokens_details: import_zod9.z.object({ cached_tokens: import_zod9.z.number().nullish() }).nullish(),
|
|
2220
|
+
output_tokens: import_zod9.z.number(),
|
|
2221
|
+
output_tokens_details: import_zod9.z.object({ reasoning_tokens: import_zod9.z.number().nullish() }).nullish()
|
|
2309
2222
|
});
|
|
2310
|
-
var textDeltaChunkSchema =
|
|
2311
|
-
type:
|
|
2312
|
-
delta:
|
|
2223
|
+
var textDeltaChunkSchema = import_zod9.z.object({
|
|
2224
|
+
type: import_zod9.z.literal("response.output_text.delta"),
|
|
2225
|
+
delta: import_zod9.z.string()
|
|
2313
2226
|
});
|
|
2314
|
-
var responseFinishedChunkSchema =
|
|
2315
|
-
type:
|
|
2316
|
-
response:
|
|
2317
|
-
incomplete_details:
|
|
2227
|
+
var responseFinishedChunkSchema = import_zod9.z.object({
|
|
2228
|
+
type: import_zod9.z.enum(["response.completed", "response.incomplete"]),
|
|
2229
|
+
response: import_zod9.z.object({
|
|
2230
|
+
incomplete_details: import_zod9.z.object({ reason: import_zod9.z.string() }).nullish(),
|
|
2318
2231
|
usage: usageSchema
|
|
2319
2232
|
})
|
|
2320
2233
|
});
|
|
2321
|
-
var responseCreatedChunkSchema =
|
|
2322
|
-
type:
|
|
2323
|
-
response:
|
|
2324
|
-
id:
|
|
2325
|
-
created_at:
|
|
2326
|
-
model:
|
|
2234
|
+
var responseCreatedChunkSchema = import_zod9.z.object({
|
|
2235
|
+
type: import_zod9.z.literal("response.created"),
|
|
2236
|
+
response: import_zod9.z.object({
|
|
2237
|
+
id: import_zod9.z.string(),
|
|
2238
|
+
created_at: import_zod9.z.number(),
|
|
2239
|
+
model: import_zod9.z.string()
|
|
2327
2240
|
})
|
|
2328
2241
|
});
|
|
2329
|
-
var responseOutputItemDoneSchema =
|
|
2330
|
-
type:
|
|
2331
|
-
output_index:
|
|
2332
|
-
item:
|
|
2333
|
-
|
|
2334
|
-
type:
|
|
2242
|
+
var responseOutputItemDoneSchema = import_zod9.z.object({
|
|
2243
|
+
type: import_zod9.z.literal("response.output_item.done"),
|
|
2244
|
+
output_index: import_zod9.z.number(),
|
|
2245
|
+
item: import_zod9.z.discriminatedUnion("type", [
|
|
2246
|
+
import_zod9.z.object({
|
|
2247
|
+
type: import_zod9.z.literal("message")
|
|
2335
2248
|
}),
|
|
2336
|
-
|
|
2337
|
-
type:
|
|
2338
|
-
id:
|
|
2339
|
-
call_id:
|
|
2340
|
-
name:
|
|
2341
|
-
arguments:
|
|
2342
|
-
status:
|
|
2249
|
+
import_zod9.z.object({
|
|
2250
|
+
type: import_zod9.z.literal("function_call"),
|
|
2251
|
+
id: import_zod9.z.string(),
|
|
2252
|
+
call_id: import_zod9.z.string(),
|
|
2253
|
+
name: import_zod9.z.string(),
|
|
2254
|
+
arguments: import_zod9.z.string(),
|
|
2255
|
+
status: import_zod9.z.literal("completed")
|
|
2343
2256
|
})
|
|
2344
2257
|
])
|
|
2345
2258
|
});
|
|
2346
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2347
|
-
type:
|
|
2348
|
-
item_id:
|
|
2349
|
-
output_index:
|
|
2350
|
-
delta:
|
|
2259
|
+
var responseFunctionCallArgumentsDeltaSchema = import_zod9.z.object({
|
|
2260
|
+
type: import_zod9.z.literal("response.function_call_arguments.delta"),
|
|
2261
|
+
item_id: import_zod9.z.string(),
|
|
2262
|
+
output_index: import_zod9.z.number(),
|
|
2263
|
+
delta: import_zod9.z.string()
|
|
2351
2264
|
});
|
|
2352
|
-
var responseOutputItemAddedSchema =
|
|
2353
|
-
type:
|
|
2354
|
-
output_index:
|
|
2355
|
-
item:
|
|
2356
|
-
|
|
2357
|
-
type:
|
|
2265
|
+
var responseOutputItemAddedSchema = import_zod9.z.object({
|
|
2266
|
+
type: import_zod9.z.literal("response.output_item.added"),
|
|
2267
|
+
output_index: import_zod9.z.number(),
|
|
2268
|
+
item: import_zod9.z.discriminatedUnion("type", [
|
|
2269
|
+
import_zod9.z.object({
|
|
2270
|
+
type: import_zod9.z.literal("message")
|
|
2358
2271
|
}),
|
|
2359
|
-
|
|
2360
|
-
type:
|
|
2361
|
-
id:
|
|
2362
|
-
call_id:
|
|
2363
|
-
name:
|
|
2364
|
-
arguments:
|
|
2272
|
+
import_zod9.z.object({
|
|
2273
|
+
type: import_zod9.z.literal("function_call"),
|
|
2274
|
+
id: import_zod9.z.string(),
|
|
2275
|
+
call_id: import_zod9.z.string(),
|
|
2276
|
+
name: import_zod9.z.string(),
|
|
2277
|
+
arguments: import_zod9.z.string()
|
|
2365
2278
|
})
|
|
2366
2279
|
])
|
|
2367
2280
|
});
|
|
2368
|
-
var responseAnnotationAddedSchema =
|
|
2369
|
-
type:
|
|
2370
|
-
annotation:
|
|
2371
|
-
type:
|
|
2372
|
-
url:
|
|
2373
|
-
title:
|
|
2281
|
+
var responseAnnotationAddedSchema = import_zod9.z.object({
|
|
2282
|
+
type: import_zod9.z.literal("response.output_text.annotation.added"),
|
|
2283
|
+
annotation: import_zod9.z.object({
|
|
2284
|
+
type: import_zod9.z.literal("url_citation"),
|
|
2285
|
+
url: import_zod9.z.string(),
|
|
2286
|
+
title: import_zod9.z.string()
|
|
2374
2287
|
})
|
|
2375
2288
|
});
|
|
2376
|
-
var openaiResponsesChunkSchema =
|
|
2289
|
+
var openaiResponsesChunkSchema = import_zod9.z.union([
|
|
2377
2290
|
textDeltaChunkSchema,
|
|
2378
2291
|
responseFinishedChunkSchema,
|
|
2379
2292
|
responseCreatedChunkSchema,
|
|
@@ -2381,7 +2294,7 @@ var openaiResponsesChunkSchema = import_zod8.z.union([
|
|
|
2381
2294
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2382
2295
|
responseOutputItemAddedSchema,
|
|
2383
2296
|
responseAnnotationAddedSchema,
|
|
2384
|
-
|
|
2297
|
+
import_zod9.z.object({ type: import_zod9.z.string() }).passthrough()
|
|
2385
2298
|
// fallback for unknown chunks
|
|
2386
2299
|
]);
|
|
2387
2300
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2426,25 +2339,25 @@ function getResponsesModelConfig(modelId) {
|
|
|
2426
2339
|
requiredAutoTruncation: false
|
|
2427
2340
|
};
|
|
2428
2341
|
}
|
|
2429
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2430
|
-
metadata:
|
|
2431
|
-
parallelToolCalls:
|
|
2432
|
-
previousResponseId:
|
|
2433
|
-
store:
|
|
2434
|
-
user:
|
|
2435
|
-
reasoningEffort:
|
|
2436
|
-
strictSchemas:
|
|
2437
|
-
instructions:
|
|
2342
|
+
var openaiResponsesProviderOptionsSchema = import_zod9.z.object({
|
|
2343
|
+
metadata: import_zod9.z.any().nullish(),
|
|
2344
|
+
parallelToolCalls: import_zod9.z.boolean().nullish(),
|
|
2345
|
+
previousResponseId: import_zod9.z.string().nullish(),
|
|
2346
|
+
store: import_zod9.z.boolean().nullish(),
|
|
2347
|
+
user: import_zod9.z.string().nullish(),
|
|
2348
|
+
reasoningEffort: import_zod9.z.string().nullish(),
|
|
2349
|
+
strictSchemas: import_zod9.z.boolean().nullish(),
|
|
2350
|
+
instructions: import_zod9.z.string().nullish()
|
|
2438
2351
|
});
|
|
2439
2352
|
|
|
2440
2353
|
// src/openai-provider.ts
|
|
2441
2354
|
function createOpenAI(options = {}) {
|
|
2442
2355
|
var _a, _b, _c;
|
|
2443
|
-
const baseURL = (_a = (0,
|
|
2356
|
+
const baseURL = (_a = (0, import_provider_utils9.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
|
|
2444
2357
|
const compatibility = (_b = options.compatibility) != null ? _b : "compatible";
|
|
2445
2358
|
const providerName = (_c = options.name) != null ? _c : "openai";
|
|
2446
2359
|
const getHeaders = () => ({
|
|
2447
|
-
Authorization: `Bearer ${(0,
|
|
2360
|
+
Authorization: `Bearer ${(0, import_provider_utils9.loadApiKey)({
|
|
2448
2361
|
apiKey: options.apiKey,
|
|
2449
2362
|
environmentVariableName: "OPENAI_API_KEY",
|
|
2450
2363
|
description: "OpenAI"
|