@ai-sdk/openai 2.0.0-canary.5 → 2.0.0-canary.7
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 +40 -0
- package/dist/index.d.mts +10 -71
- package/dist/index.d.ts +10 -71
- package/dist/index.js +442 -521
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +411 -490
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +94 -86
- package/dist/internal/index.d.ts +94 -86
- package/dist/internal/index.js +441 -518
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +411 -489
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -6,8 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
// src/openai-chat-language-model.ts
|
|
8
8
|
import {
|
|
9
|
-
InvalidResponseDataError
|
|
10
|
-
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
9
|
+
InvalidResponseDataError
|
|
11
10
|
} from "@ai-sdk/provider";
|
|
12
11
|
import {
|
|
13
12
|
combineHeaders,
|
|
@@ -15,17 +14,18 @@ import {
|
|
|
15
14
|
createJsonResponseHandler,
|
|
16
15
|
generateId,
|
|
17
16
|
isParsableJson,
|
|
18
|
-
postJsonToApi
|
|
17
|
+
postJsonToApi,
|
|
18
|
+
parseProviderOptions
|
|
19
19
|
} from "@ai-sdk/provider-utils";
|
|
20
|
-
import { z as
|
|
20
|
+
import { z as z3 } from "zod";
|
|
21
21
|
|
|
22
22
|
// src/convert-to-openai-chat-messages.ts
|
|
23
23
|
import {
|
|
24
24
|
UnsupportedFunctionalityError
|
|
25
25
|
} from "@ai-sdk/provider";
|
|
26
|
+
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
|
26
27
|
function convertToOpenAIChatMessages({
|
|
27
28
|
prompt,
|
|
28
|
-
useLegacyFunctionCalling = false,
|
|
29
29
|
systemMessageMode = "system"
|
|
30
30
|
}) {
|
|
31
31
|
const messages = [];
|
|
@@ -77,7 +77,7 @@ function convertToOpenAIChatMessages({
|
|
|
77
77
|
return {
|
|
78
78
|
type: "image_url",
|
|
79
79
|
image_url: {
|
|
80
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
80
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
|
|
81
81
|
// OpenAI specific extension: image detail
|
|
82
82
|
detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
|
|
83
83
|
}
|
|
@@ -92,14 +92,20 @@ function convertToOpenAIChatMessages({
|
|
|
92
92
|
case "audio/wav": {
|
|
93
93
|
return {
|
|
94
94
|
type: "input_audio",
|
|
95
|
-
input_audio: {
|
|
95
|
+
input_audio: {
|
|
96
|
+
data: convertToBase64(part.data),
|
|
97
|
+
format: "wav"
|
|
98
|
+
}
|
|
96
99
|
};
|
|
97
100
|
}
|
|
98
101
|
case "audio/mp3":
|
|
99
102
|
case "audio/mpeg": {
|
|
100
103
|
return {
|
|
101
104
|
type: "input_audio",
|
|
102
|
-
input_audio: {
|
|
105
|
+
input_audio: {
|
|
106
|
+
data: convertToBase64(part.data),
|
|
107
|
+
format: "mp3"
|
|
108
|
+
}
|
|
103
109
|
};
|
|
104
110
|
}
|
|
105
111
|
default: {
|
|
@@ -154,41 +160,20 @@ function convertToOpenAIChatMessages({
|
|
|
154
160
|
}
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
messages.push({
|
|
164
|
-
role: "assistant",
|
|
165
|
-
content: text,
|
|
166
|
-
function_call: toolCalls.length > 0 ? toolCalls[0].function : void 0
|
|
167
|
-
});
|
|
168
|
-
} else {
|
|
169
|
-
messages.push({
|
|
170
|
-
role: "assistant",
|
|
171
|
-
content: text,
|
|
172
|
-
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
173
|
-
});
|
|
174
|
-
}
|
|
163
|
+
messages.push({
|
|
164
|
+
role: "assistant",
|
|
165
|
+
content: text,
|
|
166
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
167
|
+
});
|
|
175
168
|
break;
|
|
176
169
|
}
|
|
177
170
|
case "tool": {
|
|
178
171
|
for (const toolResponse of content) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
});
|
|
185
|
-
} else {
|
|
186
|
-
messages.push({
|
|
187
|
-
role: "tool",
|
|
188
|
-
tool_call_id: toolResponse.toolCallId,
|
|
189
|
-
content: JSON.stringify(toolResponse.result)
|
|
190
|
-
});
|
|
191
|
-
}
|
|
172
|
+
messages.push({
|
|
173
|
+
role: "tool",
|
|
174
|
+
tool_call_id: toolResponse.toolCallId,
|
|
175
|
+
content: JSON.stringify(toolResponse.result)
|
|
176
|
+
});
|
|
192
177
|
}
|
|
193
178
|
break;
|
|
194
179
|
}
|
|
@@ -231,18 +216,69 @@ function mapOpenAIFinishReason(finishReason) {
|
|
|
231
216
|
}
|
|
232
217
|
}
|
|
233
218
|
|
|
234
|
-
// src/openai-
|
|
219
|
+
// src/openai-chat-options.ts
|
|
235
220
|
import { z } from "zod";
|
|
221
|
+
var openaiProviderOptions = z.object({
|
|
222
|
+
/**
|
|
223
|
+
* Modify the likelihood of specified tokens appearing in the completion.
|
|
224
|
+
*
|
|
225
|
+
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
226
|
+
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
227
|
+
*/
|
|
228
|
+
logitBias: z.record(z.coerce.number(), z.number()).optional(),
|
|
229
|
+
/**
|
|
230
|
+
* Return the log probabilities of the tokens.
|
|
231
|
+
*
|
|
232
|
+
* Setting to true will return the log probabilities of the tokens that
|
|
233
|
+
* were generated.
|
|
234
|
+
*
|
|
235
|
+
* Setting to a number will return the log probabilities of the top n
|
|
236
|
+
* tokens that were generated.
|
|
237
|
+
*/
|
|
238
|
+
logprobs: z.union([z.boolean(), z.number()]).optional(),
|
|
239
|
+
/**
|
|
240
|
+
* Whether to enable parallel function calling during tool use. Default to true.
|
|
241
|
+
*/
|
|
242
|
+
parallelToolCalls: z.boolean().optional(),
|
|
243
|
+
/**
|
|
244
|
+
* A unique identifier representing your end-user, which can help OpenAI to
|
|
245
|
+
* monitor and detect abuse.
|
|
246
|
+
*/
|
|
247
|
+
user: z.string().optional(),
|
|
248
|
+
/**
|
|
249
|
+
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
250
|
+
*/
|
|
251
|
+
reasoningEffort: z.enum(["low", "medium", "high"]).optional(),
|
|
252
|
+
/**
|
|
253
|
+
* Maximum number of completion tokens to generate. Useful for reasoning models.
|
|
254
|
+
*/
|
|
255
|
+
maxCompletionTokens: z.number().optional(),
|
|
256
|
+
/**
|
|
257
|
+
* Whether to enable persistence in responses API.
|
|
258
|
+
*/
|
|
259
|
+
store: z.boolean().optional(),
|
|
260
|
+
/**
|
|
261
|
+
* Metadata to associate with the request.
|
|
262
|
+
*/
|
|
263
|
+
metadata: z.record(z.string()).optional(),
|
|
264
|
+
/**
|
|
265
|
+
* Parameters for prediction mode.
|
|
266
|
+
*/
|
|
267
|
+
prediction: z.record(z.any()).optional()
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// src/openai-error.ts
|
|
271
|
+
import { z as z2 } from "zod";
|
|
236
272
|
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
237
|
-
var openaiErrorDataSchema =
|
|
238
|
-
error:
|
|
239
|
-
message:
|
|
273
|
+
var openaiErrorDataSchema = z2.object({
|
|
274
|
+
error: z2.object({
|
|
275
|
+
message: z2.string(),
|
|
240
276
|
// The additional information below is handled loosely to support
|
|
241
277
|
// OpenAI-compatible providers that have slightly different error
|
|
242
278
|
// responses:
|
|
243
|
-
type:
|
|
244
|
-
param:
|
|
245
|
-
code:
|
|
279
|
+
type: z2.string().nullish(),
|
|
280
|
+
param: z2.any().nullish(),
|
|
281
|
+
code: z2.union([z2.string(), z2.number()]).nullish()
|
|
246
282
|
})
|
|
247
283
|
});
|
|
248
284
|
var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -270,7 +306,6 @@ import {
|
|
|
270
306
|
function prepareTools({
|
|
271
307
|
tools,
|
|
272
308
|
toolChoice,
|
|
273
|
-
useLegacyFunctionCalling = false,
|
|
274
309
|
structuredOutputs
|
|
275
310
|
}) {
|
|
276
311
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
@@ -278,48 +313,6 @@ function prepareTools({
|
|
|
278
313
|
if (tools == null) {
|
|
279
314
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
280
315
|
}
|
|
281
|
-
if (useLegacyFunctionCalling) {
|
|
282
|
-
const openaiFunctions = [];
|
|
283
|
-
for (const tool of tools) {
|
|
284
|
-
if (tool.type === "provider-defined") {
|
|
285
|
-
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
286
|
-
} else {
|
|
287
|
-
openaiFunctions.push({
|
|
288
|
-
name: tool.name,
|
|
289
|
-
description: tool.description,
|
|
290
|
-
parameters: tool.parameters
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (toolChoice == null) {
|
|
295
|
-
return {
|
|
296
|
-
functions: openaiFunctions,
|
|
297
|
-
function_call: void 0,
|
|
298
|
-
toolWarnings
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
const type2 = toolChoice.type;
|
|
302
|
-
switch (type2) {
|
|
303
|
-
case "auto":
|
|
304
|
-
case "none":
|
|
305
|
-
case void 0:
|
|
306
|
-
return {
|
|
307
|
-
functions: openaiFunctions,
|
|
308
|
-
function_call: void 0,
|
|
309
|
-
toolWarnings
|
|
310
|
-
};
|
|
311
|
-
case "required":
|
|
312
|
-
throw new UnsupportedFunctionalityError2({
|
|
313
|
-
functionality: "useLegacyFunctionCalling and toolChoice: required"
|
|
314
|
-
});
|
|
315
|
-
default:
|
|
316
|
-
return {
|
|
317
|
-
functions: openaiFunctions,
|
|
318
|
-
function_call: { name: toolChoice.toolName },
|
|
319
|
-
toolWarnings
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
316
|
const openaiTools2 = [];
|
|
324
317
|
for (const tool of tools) {
|
|
325
318
|
if (tool.type === "provider-defined") {
|
|
@@ -391,7 +384,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
391
384
|
}
|
|
392
385
|
getArgs({
|
|
393
386
|
prompt,
|
|
394
|
-
|
|
387
|
+
maxOutputTokens,
|
|
395
388
|
temperature,
|
|
396
389
|
topP,
|
|
397
390
|
topK,
|
|
@@ -404,8 +397,13 @@ var OpenAIChatLanguageModel = class {
|
|
|
404
397
|
toolChoice,
|
|
405
398
|
providerOptions
|
|
406
399
|
}) {
|
|
407
|
-
var _a, _b
|
|
400
|
+
var _a, _b;
|
|
408
401
|
const warnings = [];
|
|
402
|
+
const openaiOptions = (_a = parseProviderOptions({
|
|
403
|
+
provider: "openai",
|
|
404
|
+
providerOptions,
|
|
405
|
+
schema: openaiProviderOptions
|
|
406
|
+
})) != null ? _a : {};
|
|
409
407
|
if (topK != null) {
|
|
410
408
|
warnings.push({
|
|
411
409
|
type: "unsupported-setting",
|
|
@@ -419,21 +417,9 @@ var OpenAIChatLanguageModel = class {
|
|
|
419
417
|
details: "JSON response format schema is only supported with structuredOutputs"
|
|
420
418
|
});
|
|
421
419
|
}
|
|
422
|
-
const useLegacyFunctionCalling = this.settings.useLegacyFunctionCalling;
|
|
423
|
-
if (useLegacyFunctionCalling && this.settings.parallelToolCalls === true) {
|
|
424
|
-
throw new UnsupportedFunctionalityError3({
|
|
425
|
-
functionality: "useLegacyFunctionCalling with parallelToolCalls"
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
if (useLegacyFunctionCalling && this.supportsStructuredOutputs) {
|
|
429
|
-
throw new UnsupportedFunctionalityError3({
|
|
430
|
-
functionality: "structuredOutputs with useLegacyFunctionCalling"
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
420
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
|
|
434
421
|
{
|
|
435
422
|
prompt,
|
|
436
|
-
useLegacyFunctionCalling,
|
|
437
423
|
systemMessageMode: getSystemMessageMode(this.modelId)
|
|
438
424
|
}
|
|
439
425
|
);
|
|
@@ -442,13 +428,13 @@ var OpenAIChatLanguageModel = class {
|
|
|
442
428
|
// model id:
|
|
443
429
|
model: this.modelId,
|
|
444
430
|
// model specific settings:
|
|
445
|
-
logit_bias:
|
|
446
|
-
logprobs:
|
|
447
|
-
top_logprobs: typeof
|
|
448
|
-
user:
|
|
449
|
-
parallel_tool_calls:
|
|
431
|
+
logit_bias: openaiOptions.logitBias,
|
|
432
|
+
logprobs: openaiOptions.logprobs === true || typeof openaiOptions.logprobs === "number" ? true : void 0,
|
|
433
|
+
top_logprobs: typeof openaiOptions.logprobs === "number" ? openaiOptions.logprobs : typeof openaiOptions.logprobs === "boolean" ? openaiOptions.logprobs ? 0 : void 0 : void 0,
|
|
434
|
+
user: openaiOptions.user,
|
|
435
|
+
parallel_tool_calls: openaiOptions.parallelToolCalls,
|
|
450
436
|
// standardized settings:
|
|
451
|
-
max_tokens:
|
|
437
|
+
max_tokens: maxOutputTokens,
|
|
452
438
|
temperature,
|
|
453
439
|
top_p: topP,
|
|
454
440
|
frequency_penalty: frequencyPenalty,
|
|
@@ -459,19 +445,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
459
445
|
json_schema: {
|
|
460
446
|
schema: responseFormat.schema,
|
|
461
447
|
strict: true,
|
|
462
|
-
name: (
|
|
448
|
+
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
463
449
|
description: responseFormat.description
|
|
464
450
|
}
|
|
465
451
|
} : { type: "json_object" } : void 0,
|
|
466
452
|
stop: stopSequences,
|
|
467
453
|
seed,
|
|
468
454
|
// openai specific settings:
|
|
469
|
-
// TODO remove in next major version; we auto-map
|
|
470
|
-
max_completion_tokens:
|
|
471
|
-
store:
|
|
472
|
-
metadata:
|
|
473
|
-
prediction:
|
|
474
|
-
reasoning_effort:
|
|
455
|
+
// TODO remove in next major version; we auto-map maxOutputTokens now
|
|
456
|
+
max_completion_tokens: openaiOptions.maxCompletionTokens,
|
|
457
|
+
store: openaiOptions.store,
|
|
458
|
+
metadata: openaiOptions.metadata,
|
|
459
|
+
prediction: openaiOptions.prediction,
|
|
460
|
+
reasoning_effort: openaiOptions.reasoningEffort,
|
|
475
461
|
// messages:
|
|
476
462
|
messages
|
|
477
463
|
};
|
|
@@ -535,32 +521,36 @@ var OpenAIChatLanguageModel = class {
|
|
|
535
521
|
}
|
|
536
522
|
baseArgs.max_tokens = void 0;
|
|
537
523
|
}
|
|
524
|
+
} else if (this.modelId.startsWith("gpt-4o-search-preview")) {
|
|
525
|
+
if (baseArgs.temperature != null) {
|
|
526
|
+
baseArgs.temperature = void 0;
|
|
527
|
+
warnings.push({
|
|
528
|
+
type: "unsupported-setting",
|
|
529
|
+
setting: "temperature",
|
|
530
|
+
details: "temperature is not supported for the gpt-4o-search-preview model and has been removed."
|
|
531
|
+
});
|
|
532
|
+
}
|
|
538
533
|
}
|
|
539
534
|
const {
|
|
540
535
|
tools: openaiTools2,
|
|
541
536
|
toolChoice: openaiToolChoice,
|
|
542
|
-
functions,
|
|
543
|
-
function_call,
|
|
544
537
|
toolWarnings
|
|
545
538
|
} = prepareTools({
|
|
546
539
|
tools,
|
|
547
540
|
toolChoice,
|
|
548
|
-
useLegacyFunctionCalling,
|
|
549
541
|
structuredOutputs: this.supportsStructuredOutputs
|
|
550
542
|
});
|
|
551
543
|
return {
|
|
552
544
|
args: {
|
|
553
545
|
...baseArgs,
|
|
554
546
|
tools: openaiTools2,
|
|
555
|
-
tool_choice: openaiToolChoice
|
|
556
|
-
functions,
|
|
557
|
-
function_call
|
|
547
|
+
tool_choice: openaiToolChoice
|
|
558
548
|
},
|
|
559
549
|
warnings: [...warnings, ...toolWarnings]
|
|
560
550
|
};
|
|
561
551
|
}
|
|
562
552
|
async doGenerate(options) {
|
|
563
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
553
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
564
554
|
const { args: body, warnings } = this.getArgs(options);
|
|
565
555
|
const {
|
|
566
556
|
responseHeaders,
|
|
@@ -598,17 +588,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
598
588
|
providerMetadata.openai.cachedPromptTokens = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens;
|
|
599
589
|
}
|
|
600
590
|
return {
|
|
601
|
-
text:
|
|
602
|
-
toolCalls:
|
|
603
|
-
{
|
|
604
|
-
toolCallType: "function",
|
|
605
|
-
toolCallId: generateId(),
|
|
606
|
-
toolName: choice.message.function_call.name,
|
|
607
|
-
args: choice.message.function_call.arguments
|
|
608
|
-
}
|
|
609
|
-
] : (_d = choice.message.tool_calls) == null ? void 0 : _d.map((toolCall) => {
|
|
591
|
+
text: choice.message.content != null ? { type: "text", text: choice.message.content } : void 0,
|
|
592
|
+
toolCalls: (_c = choice.message.tool_calls) == null ? void 0 : _c.map((toolCall) => {
|
|
610
593
|
var _a2;
|
|
611
594
|
return {
|
|
595
|
+
type: "tool-call",
|
|
612
596
|
toolCallType: "function",
|
|
613
597
|
toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
|
|
614
598
|
toolName: toolCall.function.name,
|
|
@@ -617,8 +601,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
617
601
|
}),
|
|
618
602
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
619
603
|
usage: {
|
|
620
|
-
|
|
621
|
-
|
|
604
|
+
inputTokens: (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens) != null ? _e : void 0,
|
|
605
|
+
outputTokens: (_g = (_f = response.usage) == null ? void 0 : _f.completion_tokens) != null ? _g : void 0
|
|
622
606
|
},
|
|
623
607
|
request: { body },
|
|
624
608
|
response: {
|
|
@@ -632,48 +616,6 @@ var OpenAIChatLanguageModel = class {
|
|
|
632
616
|
};
|
|
633
617
|
}
|
|
634
618
|
async doStream(options) {
|
|
635
|
-
if (this.settings.simulateStreaming) {
|
|
636
|
-
const result = await this.doGenerate(options);
|
|
637
|
-
const simulatedStream = new ReadableStream({
|
|
638
|
-
start(controller) {
|
|
639
|
-
controller.enqueue({ type: "response-metadata", ...result.response });
|
|
640
|
-
if (result.text) {
|
|
641
|
-
controller.enqueue({
|
|
642
|
-
type: "text-delta",
|
|
643
|
-
textDelta: result.text
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
if (result.toolCalls) {
|
|
647
|
-
for (const toolCall of result.toolCalls) {
|
|
648
|
-
controller.enqueue({
|
|
649
|
-
type: "tool-call-delta",
|
|
650
|
-
toolCallType: "function",
|
|
651
|
-
toolCallId: toolCall.toolCallId,
|
|
652
|
-
toolName: toolCall.toolName,
|
|
653
|
-
argsTextDelta: toolCall.args
|
|
654
|
-
});
|
|
655
|
-
controller.enqueue({
|
|
656
|
-
type: "tool-call",
|
|
657
|
-
...toolCall
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
controller.enqueue({
|
|
662
|
-
type: "finish",
|
|
663
|
-
finishReason: result.finishReason,
|
|
664
|
-
usage: result.usage,
|
|
665
|
-
logprobs: result.logprobs,
|
|
666
|
-
providerMetadata: result.providerMetadata
|
|
667
|
-
});
|
|
668
|
-
controller.close();
|
|
669
|
-
}
|
|
670
|
-
});
|
|
671
|
-
return {
|
|
672
|
-
stream: simulatedStream,
|
|
673
|
-
response: result.response,
|
|
674
|
-
warnings: result.warnings
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
619
|
const { args, warnings } = this.getArgs(options);
|
|
678
620
|
const body = {
|
|
679
621
|
...args,
|
|
@@ -698,13 +640,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
698
640
|
const { messages: rawPrompt, ...rawSettings } = args;
|
|
699
641
|
const toolCalls = [];
|
|
700
642
|
let finishReason = "unknown";
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
643
|
+
const usage = {
|
|
644
|
+
inputTokens: void 0,
|
|
645
|
+
outputTokens: void 0
|
|
704
646
|
};
|
|
705
647
|
let logprobs;
|
|
706
648
|
let isFirstChunk = true;
|
|
707
|
-
const { useLegacyFunctionCalling } = this.settings;
|
|
708
649
|
const providerMetadata = { openai: {} };
|
|
709
650
|
return {
|
|
710
651
|
stream: response.pipeThrough(
|
|
@@ -736,10 +677,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
736
677
|
prompt_tokens_details,
|
|
737
678
|
completion_tokens_details
|
|
738
679
|
} = value.usage;
|
|
739
|
-
usage =
|
|
740
|
-
|
|
741
|
-
completionTokens: completion_tokens != null ? completion_tokens : void 0
|
|
742
|
-
};
|
|
680
|
+
usage.inputTokens = prompt_tokens != null ? prompt_tokens : void 0;
|
|
681
|
+
usage.outputTokens = completion_tokens != null ? completion_tokens : void 0;
|
|
743
682
|
if ((completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens) != null) {
|
|
744
683
|
providerMetadata.openai.reasoningTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens;
|
|
745
684
|
}
|
|
@@ -763,8 +702,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
763
702
|
const delta = choice.delta;
|
|
764
703
|
if (delta.content != null) {
|
|
765
704
|
controller.enqueue({
|
|
766
|
-
type: "text
|
|
767
|
-
|
|
705
|
+
type: "text",
|
|
706
|
+
text: delta.content
|
|
768
707
|
});
|
|
769
708
|
}
|
|
770
709
|
const mappedLogprobs = mapOpenAIChatLogProbsOutput(
|
|
@@ -774,16 +713,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
774
713
|
if (logprobs === void 0) logprobs = [];
|
|
775
714
|
logprobs.push(...mappedLogprobs);
|
|
776
715
|
}
|
|
777
|
-
|
|
778
|
-
{
|
|
779
|
-
type: "function",
|
|
780
|
-
id: generateId(),
|
|
781
|
-
function: delta.function_call,
|
|
782
|
-
index: 0
|
|
783
|
-
}
|
|
784
|
-
] : delta.tool_calls;
|
|
785
|
-
if (mappedToolCalls != null) {
|
|
786
|
-
for (const toolCallDelta of mappedToolCalls) {
|
|
716
|
+
if (delta.tool_calls != null) {
|
|
717
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
787
718
|
const index = toolCallDelta.index;
|
|
788
719
|
if (toolCalls[index] == null) {
|
|
789
720
|
if (toolCallDelta.type !== "function") {
|
|
@@ -865,15 +796,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
865
796
|
}
|
|
866
797
|
},
|
|
867
798
|
flush(controller) {
|
|
868
|
-
var _a, _b;
|
|
869
799
|
controller.enqueue({
|
|
870
800
|
type: "finish",
|
|
871
801
|
finishReason,
|
|
872
802
|
logprobs,
|
|
873
|
-
usage
|
|
874
|
-
promptTokens: (_a = usage.promptTokens) != null ? _a : NaN,
|
|
875
|
-
completionTokens: (_b = usage.completionTokens) != null ? _b : NaN
|
|
876
|
-
},
|
|
803
|
+
usage,
|
|
877
804
|
...providerMetadata != null ? { providerMetadata } : {}
|
|
878
805
|
});
|
|
879
806
|
}
|
|
@@ -885,104 +812,96 @@ var OpenAIChatLanguageModel = class {
|
|
|
885
812
|
};
|
|
886
813
|
}
|
|
887
814
|
};
|
|
888
|
-
var openaiTokenUsageSchema =
|
|
889
|
-
prompt_tokens:
|
|
890
|
-
completion_tokens:
|
|
891
|
-
prompt_tokens_details:
|
|
892
|
-
cached_tokens:
|
|
815
|
+
var openaiTokenUsageSchema = z3.object({
|
|
816
|
+
prompt_tokens: z3.number().nullish(),
|
|
817
|
+
completion_tokens: z3.number().nullish(),
|
|
818
|
+
prompt_tokens_details: z3.object({
|
|
819
|
+
cached_tokens: z3.number().nullish()
|
|
893
820
|
}).nullish(),
|
|
894
|
-
completion_tokens_details:
|
|
895
|
-
reasoning_tokens:
|
|
896
|
-
accepted_prediction_tokens:
|
|
897
|
-
rejected_prediction_tokens:
|
|
821
|
+
completion_tokens_details: z3.object({
|
|
822
|
+
reasoning_tokens: z3.number().nullish(),
|
|
823
|
+
accepted_prediction_tokens: z3.number().nullish(),
|
|
824
|
+
rejected_prediction_tokens: z3.number().nullish()
|
|
898
825
|
}).nullish()
|
|
899
826
|
}).nullish();
|
|
900
|
-
var openaiChatResponseSchema =
|
|
901
|
-
id:
|
|
902
|
-
created:
|
|
903
|
-
model:
|
|
904
|
-
choices:
|
|
905
|
-
|
|
906
|
-
message:
|
|
907
|
-
role:
|
|
908
|
-
content:
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
type: z2.literal("function"),
|
|
917
|
-
function: z2.object({
|
|
918
|
-
name: z2.string(),
|
|
919
|
-
arguments: z2.string()
|
|
827
|
+
var openaiChatResponseSchema = z3.object({
|
|
828
|
+
id: z3.string().nullish(),
|
|
829
|
+
created: z3.number().nullish(),
|
|
830
|
+
model: z3.string().nullish(),
|
|
831
|
+
choices: z3.array(
|
|
832
|
+
z3.object({
|
|
833
|
+
message: z3.object({
|
|
834
|
+
role: z3.literal("assistant").nullish(),
|
|
835
|
+
content: z3.string().nullish(),
|
|
836
|
+
tool_calls: z3.array(
|
|
837
|
+
z3.object({
|
|
838
|
+
id: z3.string().nullish(),
|
|
839
|
+
type: z3.literal("function"),
|
|
840
|
+
function: z3.object({
|
|
841
|
+
name: z3.string(),
|
|
842
|
+
arguments: z3.string()
|
|
920
843
|
})
|
|
921
844
|
})
|
|
922
845
|
).nullish()
|
|
923
846
|
}),
|
|
924
|
-
index:
|
|
925
|
-
logprobs:
|
|
926
|
-
content:
|
|
927
|
-
|
|
928
|
-
token:
|
|
929
|
-
logprob:
|
|
930
|
-
top_logprobs:
|
|
931
|
-
|
|
932
|
-
token:
|
|
933
|
-
logprob:
|
|
847
|
+
index: z3.number(),
|
|
848
|
+
logprobs: z3.object({
|
|
849
|
+
content: z3.array(
|
|
850
|
+
z3.object({
|
|
851
|
+
token: z3.string(),
|
|
852
|
+
logprob: z3.number(),
|
|
853
|
+
top_logprobs: z3.array(
|
|
854
|
+
z3.object({
|
|
855
|
+
token: z3.string(),
|
|
856
|
+
logprob: z3.number()
|
|
934
857
|
})
|
|
935
858
|
)
|
|
936
859
|
})
|
|
937
860
|
).nullable()
|
|
938
861
|
}).nullish(),
|
|
939
|
-
finish_reason:
|
|
862
|
+
finish_reason: z3.string().nullish()
|
|
940
863
|
})
|
|
941
864
|
),
|
|
942
865
|
usage: openaiTokenUsageSchema
|
|
943
866
|
});
|
|
944
|
-
var openaiChatChunkSchema =
|
|
945
|
-
|
|
946
|
-
id:
|
|
947
|
-
created:
|
|
948
|
-
model:
|
|
949
|
-
choices:
|
|
950
|
-
|
|
951
|
-
delta:
|
|
952
|
-
role:
|
|
953
|
-
content:
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
type: z2.literal("function").optional(),
|
|
963
|
-
function: z2.object({
|
|
964
|
-
name: z2.string().nullish(),
|
|
965
|
-
arguments: z2.string().nullish()
|
|
867
|
+
var openaiChatChunkSchema = z3.union([
|
|
868
|
+
z3.object({
|
|
869
|
+
id: z3.string().nullish(),
|
|
870
|
+
created: z3.number().nullish(),
|
|
871
|
+
model: z3.string().nullish(),
|
|
872
|
+
choices: z3.array(
|
|
873
|
+
z3.object({
|
|
874
|
+
delta: z3.object({
|
|
875
|
+
role: z3.enum(["assistant"]).nullish(),
|
|
876
|
+
content: z3.string().nullish(),
|
|
877
|
+
tool_calls: z3.array(
|
|
878
|
+
z3.object({
|
|
879
|
+
index: z3.number(),
|
|
880
|
+
id: z3.string().nullish(),
|
|
881
|
+
type: z3.literal("function").optional(),
|
|
882
|
+
function: z3.object({
|
|
883
|
+
name: z3.string().nullish(),
|
|
884
|
+
arguments: z3.string().nullish()
|
|
966
885
|
})
|
|
967
886
|
})
|
|
968
887
|
).nullish()
|
|
969
888
|
}).nullish(),
|
|
970
|
-
logprobs:
|
|
971
|
-
content:
|
|
972
|
-
|
|
973
|
-
token:
|
|
974
|
-
logprob:
|
|
975
|
-
top_logprobs:
|
|
976
|
-
|
|
977
|
-
token:
|
|
978
|
-
logprob:
|
|
889
|
+
logprobs: z3.object({
|
|
890
|
+
content: z3.array(
|
|
891
|
+
z3.object({
|
|
892
|
+
token: z3.string(),
|
|
893
|
+
logprob: z3.number(),
|
|
894
|
+
top_logprobs: z3.array(
|
|
895
|
+
z3.object({
|
|
896
|
+
token: z3.string(),
|
|
897
|
+
logprob: z3.number()
|
|
979
898
|
})
|
|
980
899
|
)
|
|
981
900
|
})
|
|
982
901
|
).nullable()
|
|
983
902
|
}).nullish(),
|
|
984
|
-
finish_reason:
|
|
985
|
-
index:
|
|
903
|
+
finish_reason: z3.string().nullable().optional(),
|
|
904
|
+
index: z3.number()
|
|
986
905
|
})
|
|
987
906
|
),
|
|
988
907
|
usage: openaiTokenUsageSchema
|
|
@@ -1030,12 +949,12 @@ import {
|
|
|
1030
949
|
createJsonResponseHandler as createJsonResponseHandler2,
|
|
1031
950
|
postJsonToApi as postJsonToApi2
|
|
1032
951
|
} from "@ai-sdk/provider-utils";
|
|
1033
|
-
import { z as
|
|
952
|
+
import { z as z4 } from "zod";
|
|
1034
953
|
|
|
1035
954
|
// src/convert-to-openai-completion-prompt.ts
|
|
1036
955
|
import {
|
|
1037
956
|
InvalidPromptError,
|
|
1038
|
-
UnsupportedFunctionalityError as
|
|
957
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
1039
958
|
} from "@ai-sdk/provider";
|
|
1040
959
|
function convertToOpenAICompletionPrompt({
|
|
1041
960
|
prompt,
|
|
@@ -1082,7 +1001,7 @@ ${userMessage}
|
|
|
1082
1001
|
return part.text;
|
|
1083
1002
|
}
|
|
1084
1003
|
case "tool-call": {
|
|
1085
|
-
throw new
|
|
1004
|
+
throw new UnsupportedFunctionalityError3({
|
|
1086
1005
|
functionality: "tool-call messages"
|
|
1087
1006
|
});
|
|
1088
1007
|
}
|
|
@@ -1095,7 +1014,7 @@ ${assistantMessage}
|
|
|
1095
1014
|
break;
|
|
1096
1015
|
}
|
|
1097
1016
|
case "tool": {
|
|
1098
|
-
throw new
|
|
1017
|
+
throw new UnsupportedFunctionalityError3({
|
|
1099
1018
|
functionality: "tool messages"
|
|
1100
1019
|
});
|
|
1101
1020
|
}
|
|
@@ -1143,7 +1062,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1143
1062
|
getArgs({
|
|
1144
1063
|
inputFormat,
|
|
1145
1064
|
prompt,
|
|
1146
|
-
|
|
1065
|
+
maxOutputTokens,
|
|
1147
1066
|
temperature,
|
|
1148
1067
|
topP,
|
|
1149
1068
|
topK,
|
|
@@ -1185,7 +1104,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1185
1104
|
suffix: this.settings.suffix,
|
|
1186
1105
|
user: this.settings.user,
|
|
1187
1106
|
// standardized settings:
|
|
1188
|
-
max_tokens:
|
|
1107
|
+
max_tokens: maxOutputTokens,
|
|
1189
1108
|
temperature,
|
|
1190
1109
|
top_p: topP,
|
|
1191
1110
|
frequency_penalty: frequencyPenalty,
|
|
@@ -1221,10 +1140,10 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1221
1140
|
});
|
|
1222
1141
|
const choice = response.choices[0];
|
|
1223
1142
|
return {
|
|
1224
|
-
text: choice.text,
|
|
1143
|
+
text: { type: "text", text: choice.text },
|
|
1225
1144
|
usage: {
|
|
1226
|
-
|
|
1227
|
-
|
|
1145
|
+
inputTokens: response.usage.prompt_tokens,
|
|
1146
|
+
outputTokens: response.usage.completion_tokens
|
|
1228
1147
|
},
|
|
1229
1148
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
1230
1149
|
logprobs: mapOpenAICompletionLogProbs(choice.logprobs),
|
|
@@ -1260,9 +1179,9 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1260
1179
|
fetch: this.config.fetch
|
|
1261
1180
|
});
|
|
1262
1181
|
let finishReason = "unknown";
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1182
|
+
const usage = {
|
|
1183
|
+
inputTokens: void 0,
|
|
1184
|
+
outputTokens: void 0
|
|
1266
1185
|
};
|
|
1267
1186
|
let logprobs;
|
|
1268
1187
|
let isFirstChunk = true;
|
|
@@ -1289,10 +1208,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1289
1208
|
});
|
|
1290
1209
|
}
|
|
1291
1210
|
if (value.usage != null) {
|
|
1292
|
-
usage =
|
|
1293
|
-
|
|
1294
|
-
completionTokens: value.usage.completion_tokens
|
|
1295
|
-
};
|
|
1211
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
1212
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
1296
1213
|
}
|
|
1297
1214
|
const choice = value.choices[0];
|
|
1298
1215
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
@@ -1300,8 +1217,8 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1300
1217
|
}
|
|
1301
1218
|
if ((choice == null ? void 0 : choice.text) != null) {
|
|
1302
1219
|
controller.enqueue({
|
|
1303
|
-
type: "text
|
|
1304
|
-
|
|
1220
|
+
type: "text",
|
|
1221
|
+
text: choice.text
|
|
1305
1222
|
});
|
|
1306
1223
|
}
|
|
1307
1224
|
const mappedLogprobs = mapOpenAICompletionLogProbs(
|
|
@@ -1328,46 +1245,46 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1328
1245
|
};
|
|
1329
1246
|
}
|
|
1330
1247
|
};
|
|
1331
|
-
var openaiCompletionResponseSchema =
|
|
1332
|
-
id:
|
|
1333
|
-
created:
|
|
1334
|
-
model:
|
|
1335
|
-
choices:
|
|
1336
|
-
|
|
1337
|
-
text:
|
|
1338
|
-
finish_reason:
|
|
1339
|
-
logprobs:
|
|
1340
|
-
tokens:
|
|
1341
|
-
token_logprobs:
|
|
1342
|
-
top_logprobs:
|
|
1248
|
+
var openaiCompletionResponseSchema = z4.object({
|
|
1249
|
+
id: z4.string().nullish(),
|
|
1250
|
+
created: z4.number().nullish(),
|
|
1251
|
+
model: z4.string().nullish(),
|
|
1252
|
+
choices: z4.array(
|
|
1253
|
+
z4.object({
|
|
1254
|
+
text: z4.string(),
|
|
1255
|
+
finish_reason: z4.string(),
|
|
1256
|
+
logprobs: z4.object({
|
|
1257
|
+
tokens: z4.array(z4.string()),
|
|
1258
|
+
token_logprobs: z4.array(z4.number()),
|
|
1259
|
+
top_logprobs: z4.array(z4.record(z4.string(), z4.number())).nullable()
|
|
1343
1260
|
}).nullish()
|
|
1344
1261
|
})
|
|
1345
1262
|
),
|
|
1346
|
-
usage:
|
|
1347
|
-
prompt_tokens:
|
|
1348
|
-
completion_tokens:
|
|
1263
|
+
usage: z4.object({
|
|
1264
|
+
prompt_tokens: z4.number(),
|
|
1265
|
+
completion_tokens: z4.number()
|
|
1349
1266
|
})
|
|
1350
1267
|
});
|
|
1351
|
-
var openaiCompletionChunkSchema =
|
|
1352
|
-
|
|
1353
|
-
id:
|
|
1354
|
-
created:
|
|
1355
|
-
model:
|
|
1356
|
-
choices:
|
|
1357
|
-
|
|
1358
|
-
text:
|
|
1359
|
-
finish_reason:
|
|
1360
|
-
index:
|
|
1361
|
-
logprobs:
|
|
1362
|
-
tokens:
|
|
1363
|
-
token_logprobs:
|
|
1364
|
-
top_logprobs:
|
|
1268
|
+
var openaiCompletionChunkSchema = z4.union([
|
|
1269
|
+
z4.object({
|
|
1270
|
+
id: z4.string().nullish(),
|
|
1271
|
+
created: z4.number().nullish(),
|
|
1272
|
+
model: z4.string().nullish(),
|
|
1273
|
+
choices: z4.array(
|
|
1274
|
+
z4.object({
|
|
1275
|
+
text: z4.string(),
|
|
1276
|
+
finish_reason: z4.string().nullish(),
|
|
1277
|
+
index: z4.number(),
|
|
1278
|
+
logprobs: z4.object({
|
|
1279
|
+
tokens: z4.array(z4.string()),
|
|
1280
|
+
token_logprobs: z4.array(z4.number()),
|
|
1281
|
+
top_logprobs: z4.array(z4.record(z4.string(), z4.number())).nullable()
|
|
1365
1282
|
}).nullish()
|
|
1366
1283
|
})
|
|
1367
1284
|
),
|
|
1368
|
-
usage:
|
|
1369
|
-
prompt_tokens:
|
|
1370
|
-
completion_tokens:
|
|
1285
|
+
usage: z4.object({
|
|
1286
|
+
prompt_tokens: z4.number(),
|
|
1287
|
+
completion_tokens: z4.number()
|
|
1371
1288
|
}).nullish()
|
|
1372
1289
|
}),
|
|
1373
1290
|
openaiErrorDataSchema
|
|
@@ -1382,10 +1299,10 @@ import {
|
|
|
1382
1299
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1383
1300
|
postJsonToApi as postJsonToApi3
|
|
1384
1301
|
} from "@ai-sdk/provider-utils";
|
|
1385
|
-
import { z as
|
|
1302
|
+
import { z as z5 } from "zod";
|
|
1386
1303
|
var OpenAIEmbeddingModel = class {
|
|
1387
1304
|
constructor(modelId, settings, config) {
|
|
1388
|
-
this.specificationVersion = "
|
|
1305
|
+
this.specificationVersion = "v2";
|
|
1389
1306
|
this.modelId = modelId;
|
|
1390
1307
|
this.settings = settings;
|
|
1391
1308
|
this.config = config;
|
|
@@ -1414,7 +1331,11 @@ var OpenAIEmbeddingModel = class {
|
|
|
1414
1331
|
values
|
|
1415
1332
|
});
|
|
1416
1333
|
}
|
|
1417
|
-
const {
|
|
1334
|
+
const {
|
|
1335
|
+
responseHeaders,
|
|
1336
|
+
value: response,
|
|
1337
|
+
rawValue
|
|
1338
|
+
} = await postJsonToApi3({
|
|
1418
1339
|
url: this.config.url({
|
|
1419
1340
|
path: "/embeddings",
|
|
1420
1341
|
modelId: this.modelId
|
|
@@ -1437,13 +1358,13 @@ var OpenAIEmbeddingModel = class {
|
|
|
1437
1358
|
return {
|
|
1438
1359
|
embeddings: response.data.map((item) => item.embedding),
|
|
1439
1360
|
usage: response.usage ? { tokens: response.usage.prompt_tokens } : void 0,
|
|
1440
|
-
|
|
1361
|
+
response: { headers: responseHeaders, body: rawValue }
|
|
1441
1362
|
};
|
|
1442
1363
|
}
|
|
1443
1364
|
};
|
|
1444
|
-
var openaiTextEmbeddingResponseSchema =
|
|
1445
|
-
data:
|
|
1446
|
-
usage:
|
|
1365
|
+
var openaiTextEmbeddingResponseSchema = z5.object({
|
|
1366
|
+
data: z5.array(z5.object({ embedding: z5.array(z5.number()) })),
|
|
1367
|
+
usage: z5.object({ prompt_tokens: z5.number() }).nullish()
|
|
1447
1368
|
});
|
|
1448
1369
|
|
|
1449
1370
|
// src/openai-image-model.ts
|
|
@@ -1452,7 +1373,7 @@ import {
|
|
|
1452
1373
|
createJsonResponseHandler as createJsonResponseHandler4,
|
|
1453
1374
|
postJsonToApi as postJsonToApi4
|
|
1454
1375
|
} from "@ai-sdk/provider-utils";
|
|
1455
|
-
import { z as
|
|
1376
|
+
import { z as z6 } from "zod";
|
|
1456
1377
|
|
|
1457
1378
|
// src/openai-image-settings.ts
|
|
1458
1379
|
var modelMaxImagesPerCall = {
|
|
@@ -1530,13 +1451,13 @@ var OpenAIImageModel = class {
|
|
|
1530
1451
|
};
|
|
1531
1452
|
}
|
|
1532
1453
|
};
|
|
1533
|
-
var openaiImageResponseSchema =
|
|
1534
|
-
data:
|
|
1454
|
+
var openaiImageResponseSchema = z6.object({
|
|
1455
|
+
data: z6.array(z6.object({ b64_json: z6.string() }))
|
|
1535
1456
|
});
|
|
1536
1457
|
|
|
1537
1458
|
// src/openai-tools.ts
|
|
1538
|
-
import { z as
|
|
1539
|
-
var WebSearchPreviewParameters =
|
|
1459
|
+
import { z as z7 } from "zod";
|
|
1460
|
+
var WebSearchPreviewParameters = z7.object({});
|
|
1540
1461
|
function webSearchPreviewTool({
|
|
1541
1462
|
searchContextSize,
|
|
1542
1463
|
userLocation
|
|
@@ -1560,22 +1481,16 @@ import {
|
|
|
1560
1481
|
combineHeaders as combineHeaders5,
|
|
1561
1482
|
convertBase64ToUint8Array,
|
|
1562
1483
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
1563
|
-
parseProviderOptions,
|
|
1484
|
+
parseProviderOptions as parseProviderOptions2,
|
|
1564
1485
|
postFormDataToApi
|
|
1565
1486
|
} from "@ai-sdk/provider-utils";
|
|
1566
|
-
import { z as
|
|
1567
|
-
var
|
|
1568
|
-
include:
|
|
1569
|
-
|
|
1570
|
-
),
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
"An optional text to guide the model's style or continue a previous audio segment."
|
|
1574
|
-
),
|
|
1575
|
-
temperature: z7.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
|
|
1576
|
-
timestampGranularities: z7.array(z7.enum(["word", "segment"])).optional().default(["segment"]).describe(
|
|
1577
|
-
"The timestamp granularities to populate for this transcription."
|
|
1578
|
-
)
|
|
1487
|
+
import { z as z8 } from "zod";
|
|
1488
|
+
var openAIProviderOptionsSchema = z8.object({
|
|
1489
|
+
include: z8.array(z8.string()).nullish(),
|
|
1490
|
+
language: z8.string().nullish(),
|
|
1491
|
+
prompt: z8.string().nullish(),
|
|
1492
|
+
temperature: z8.number().min(0).max(1).nullish().default(0),
|
|
1493
|
+
timestampGranularities: z8.array(z8.enum(["word", "segment"])).nullish().default(["segment"])
|
|
1579
1494
|
});
|
|
1580
1495
|
var languageMap = {
|
|
1581
1496
|
afrikaans: "af",
|
|
@@ -1650,11 +1565,12 @@ var OpenAITranscriptionModel = class {
|
|
|
1650
1565
|
mediaType,
|
|
1651
1566
|
providerOptions
|
|
1652
1567
|
}) {
|
|
1568
|
+
var _a, _b, _c, _d, _e;
|
|
1653
1569
|
const warnings = [];
|
|
1654
|
-
const openAIOptions =
|
|
1570
|
+
const openAIOptions = parseProviderOptions2({
|
|
1655
1571
|
provider: "openai",
|
|
1656
1572
|
providerOptions,
|
|
1657
|
-
schema:
|
|
1573
|
+
schema: openAIProviderOptionsSchema
|
|
1658
1574
|
});
|
|
1659
1575
|
const formData = new FormData();
|
|
1660
1576
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
@@ -1662,16 +1578,16 @@ var OpenAITranscriptionModel = class {
|
|
|
1662
1578
|
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1663
1579
|
if (openAIOptions) {
|
|
1664
1580
|
const transcriptionModelOptions = {
|
|
1665
|
-
include: openAIOptions.include,
|
|
1666
|
-
language: openAIOptions.language,
|
|
1667
|
-
prompt: openAIOptions.prompt,
|
|
1668
|
-
temperature: openAIOptions.temperature,
|
|
1669
|
-
timestamp_granularities: openAIOptions.timestampGranularities
|
|
1581
|
+
include: (_a = openAIOptions.include) != null ? _a : void 0,
|
|
1582
|
+
language: (_b = openAIOptions.language) != null ? _b : void 0,
|
|
1583
|
+
prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
|
|
1584
|
+
temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
|
|
1585
|
+
timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
|
|
1670
1586
|
};
|
|
1671
1587
|
for (const key in transcriptionModelOptions) {
|
|
1672
1588
|
const value = transcriptionModelOptions[key];
|
|
1673
1589
|
if (value !== void 0) {
|
|
1674
|
-
formData.append(key, value);
|
|
1590
|
+
formData.append(key, String(value));
|
|
1675
1591
|
}
|
|
1676
1592
|
}
|
|
1677
1593
|
}
|
|
@@ -1722,15 +1638,15 @@ var OpenAITranscriptionModel = class {
|
|
|
1722
1638
|
};
|
|
1723
1639
|
}
|
|
1724
1640
|
};
|
|
1725
|
-
var openaiTranscriptionResponseSchema =
|
|
1726
|
-
text:
|
|
1727
|
-
language:
|
|
1728
|
-
duration:
|
|
1729
|
-
words:
|
|
1730
|
-
|
|
1731
|
-
word:
|
|
1732
|
-
start:
|
|
1733
|
-
end:
|
|
1641
|
+
var openaiTranscriptionResponseSchema = z8.object({
|
|
1642
|
+
text: z8.string(),
|
|
1643
|
+
language: z8.string().nullish(),
|
|
1644
|
+
duration: z8.number().nullish(),
|
|
1645
|
+
words: z8.array(
|
|
1646
|
+
z8.object({
|
|
1647
|
+
word: z8.string(),
|
|
1648
|
+
start: z8.number(),
|
|
1649
|
+
end: z8.number()
|
|
1734
1650
|
})
|
|
1735
1651
|
).nullish()
|
|
1736
1652
|
});
|
|
@@ -1741,14 +1657,14 @@ import {
|
|
|
1741
1657
|
createEventSourceResponseHandler as createEventSourceResponseHandler3,
|
|
1742
1658
|
createJsonResponseHandler as createJsonResponseHandler6,
|
|
1743
1659
|
generateId as generateId2,
|
|
1744
|
-
parseProviderOptions as
|
|
1660
|
+
parseProviderOptions as parseProviderOptions3,
|
|
1745
1661
|
postJsonToApi as postJsonToApi5
|
|
1746
1662
|
} from "@ai-sdk/provider-utils";
|
|
1747
|
-
import { z as
|
|
1663
|
+
import { z as z9 } from "zod";
|
|
1748
1664
|
|
|
1749
1665
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1750
1666
|
import {
|
|
1751
|
-
UnsupportedFunctionalityError as
|
|
1667
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError4
|
|
1752
1668
|
} from "@ai-sdk/provider";
|
|
1753
1669
|
function convertToOpenAIResponsesMessages({
|
|
1754
1670
|
prompt,
|
|
@@ -1804,7 +1720,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1804
1720
|
};
|
|
1805
1721
|
} else if (part.mediaType === "application/pdf") {
|
|
1806
1722
|
if (part.data instanceof URL) {
|
|
1807
|
-
throw new
|
|
1723
|
+
throw new UnsupportedFunctionalityError4({
|
|
1808
1724
|
functionality: "PDF file parts with URLs"
|
|
1809
1725
|
});
|
|
1810
1726
|
}
|
|
@@ -1814,7 +1730,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1814
1730
|
file_data: `data:application/pdf;base64,${part.data}`
|
|
1815
1731
|
};
|
|
1816
1732
|
} else {
|
|
1817
|
-
throw new
|
|
1733
|
+
throw new UnsupportedFunctionalityError4({
|
|
1818
1734
|
functionality: `file part media type ${part.mediaType}`
|
|
1819
1735
|
});
|
|
1820
1736
|
}
|
|
@@ -1886,7 +1802,7 @@ function mapOpenAIResponseFinishReason({
|
|
|
1886
1802
|
|
|
1887
1803
|
// src/responses/openai-responses-prepare-tools.ts
|
|
1888
1804
|
import {
|
|
1889
|
-
UnsupportedFunctionalityError as
|
|
1805
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError5
|
|
1890
1806
|
} from "@ai-sdk/provider";
|
|
1891
1807
|
function prepareResponsesTools({
|
|
1892
1808
|
tools,
|
|
@@ -1946,7 +1862,7 @@ function prepareResponsesTools({
|
|
|
1946
1862
|
};
|
|
1947
1863
|
default: {
|
|
1948
1864
|
const _exhaustiveCheck = type;
|
|
1949
|
-
throw new
|
|
1865
|
+
throw new UnsupportedFunctionalityError5({
|
|
1950
1866
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1951
1867
|
});
|
|
1952
1868
|
}
|
|
@@ -1965,7 +1881,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1965
1881
|
return this.config.provider;
|
|
1966
1882
|
}
|
|
1967
1883
|
getArgs({
|
|
1968
|
-
|
|
1884
|
+
maxOutputTokens,
|
|
1969
1885
|
temperature,
|
|
1970
1886
|
stopSequences,
|
|
1971
1887
|
topP,
|
|
@@ -2008,7 +1924,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2008
1924
|
systemMessageMode: modelConfig.systemMessageMode
|
|
2009
1925
|
});
|
|
2010
1926
|
warnings.push(...messageWarnings);
|
|
2011
|
-
const openaiOptions =
|
|
1927
|
+
const openaiOptions = parseProviderOptions3({
|
|
2012
1928
|
provider: "openai",
|
|
2013
1929
|
providerOptions,
|
|
2014
1930
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -2019,7 +1935,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2019
1935
|
input: messages,
|
|
2020
1936
|
temperature,
|
|
2021
1937
|
top_p: topP,
|
|
2022
|
-
max_output_tokens:
|
|
1938
|
+
max_output_tokens: maxOutputTokens,
|
|
2023
1939
|
...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
|
|
2024
1940
|
text: {
|
|
2025
1941
|
format: responseFormat.schema != null ? {
|
|
@@ -2098,49 +2014,49 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2098
2014
|
body,
|
|
2099
2015
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2100
2016
|
successfulResponseHandler: createJsonResponseHandler6(
|
|
2101
|
-
|
|
2102
|
-
id:
|
|
2103
|
-
created_at:
|
|
2104
|
-
model:
|
|
2105
|
-
output:
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
type:
|
|
2109
|
-
role:
|
|
2110
|
-
content:
|
|
2111
|
-
|
|
2112
|
-
type:
|
|
2113
|
-
text:
|
|
2114
|
-
annotations:
|
|
2115
|
-
|
|
2116
|
-
type:
|
|
2117
|
-
start_index:
|
|
2118
|
-
end_index:
|
|
2119
|
-
url:
|
|
2120
|
-
title:
|
|
2017
|
+
z9.object({
|
|
2018
|
+
id: z9.string(),
|
|
2019
|
+
created_at: z9.number(),
|
|
2020
|
+
model: z9.string(),
|
|
2021
|
+
output: z9.array(
|
|
2022
|
+
z9.discriminatedUnion("type", [
|
|
2023
|
+
z9.object({
|
|
2024
|
+
type: z9.literal("message"),
|
|
2025
|
+
role: z9.literal("assistant"),
|
|
2026
|
+
content: z9.array(
|
|
2027
|
+
z9.object({
|
|
2028
|
+
type: z9.literal("output_text"),
|
|
2029
|
+
text: z9.string(),
|
|
2030
|
+
annotations: z9.array(
|
|
2031
|
+
z9.object({
|
|
2032
|
+
type: z9.literal("url_citation"),
|
|
2033
|
+
start_index: z9.number(),
|
|
2034
|
+
end_index: z9.number(),
|
|
2035
|
+
url: z9.string(),
|
|
2036
|
+
title: z9.string()
|
|
2121
2037
|
})
|
|
2122
2038
|
)
|
|
2123
2039
|
})
|
|
2124
2040
|
)
|
|
2125
2041
|
}),
|
|
2126
|
-
|
|
2127
|
-
type:
|
|
2128
|
-
call_id:
|
|
2129
|
-
name:
|
|
2130
|
-
arguments:
|
|
2042
|
+
z9.object({
|
|
2043
|
+
type: z9.literal("function_call"),
|
|
2044
|
+
call_id: z9.string(),
|
|
2045
|
+
name: z9.string(),
|
|
2046
|
+
arguments: z9.string()
|
|
2131
2047
|
}),
|
|
2132
|
-
|
|
2133
|
-
type:
|
|
2048
|
+
z9.object({
|
|
2049
|
+
type: z9.literal("web_search_call")
|
|
2134
2050
|
}),
|
|
2135
|
-
|
|
2136
|
-
type:
|
|
2051
|
+
z9.object({
|
|
2052
|
+
type: z9.literal("computer_call")
|
|
2137
2053
|
}),
|
|
2138
|
-
|
|
2139
|
-
type:
|
|
2054
|
+
z9.object({
|
|
2055
|
+
type: z9.literal("reasoning")
|
|
2140
2056
|
})
|
|
2141
2057
|
])
|
|
2142
2058
|
),
|
|
2143
|
-
incomplete_details:
|
|
2059
|
+
incomplete_details: z9.object({ reason: z9.string() }).nullable(),
|
|
2144
2060
|
usage: usageSchema
|
|
2145
2061
|
})
|
|
2146
2062
|
),
|
|
@@ -2149,17 +2065,22 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2149
2065
|
});
|
|
2150
2066
|
const outputTextElements = response.output.filter((output) => output.type === "message").flatMap((output) => output.content).filter((content) => content.type === "output_text");
|
|
2151
2067
|
const toolCalls = response.output.filter((output) => output.type === "function_call").map((output) => ({
|
|
2068
|
+
type: "tool-call",
|
|
2152
2069
|
toolCallType: "function",
|
|
2153
2070
|
toolCallId: output.call_id,
|
|
2154
2071
|
toolName: output.name,
|
|
2155
2072
|
args: output.arguments
|
|
2156
2073
|
}));
|
|
2157
2074
|
return {
|
|
2158
|
-
text:
|
|
2075
|
+
text: {
|
|
2076
|
+
type: "text",
|
|
2077
|
+
text: outputTextElements.map((content) => content.text).join("\n")
|
|
2078
|
+
},
|
|
2159
2079
|
sources: outputTextElements.flatMap(
|
|
2160
2080
|
(content) => content.annotations.map((annotation) => {
|
|
2161
2081
|
var _a2, _b2, _c2;
|
|
2162
2082
|
return {
|
|
2083
|
+
type: "source",
|
|
2163
2084
|
sourceType: "url",
|
|
2164
2085
|
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : generateId2(),
|
|
2165
2086
|
url: annotation.url,
|
|
@@ -2173,8 +2094,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2173
2094
|
}),
|
|
2174
2095
|
toolCalls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
2175
2096
|
usage: {
|
|
2176
|
-
|
|
2177
|
-
|
|
2097
|
+
inputTokens: response.usage.input_tokens,
|
|
2098
|
+
outputTokens: response.usage.output_tokens
|
|
2178
2099
|
},
|
|
2179
2100
|
request: { body },
|
|
2180
2101
|
response: {
|
|
@@ -2215,8 +2136,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2215
2136
|
});
|
|
2216
2137
|
const self = this;
|
|
2217
2138
|
let finishReason = "unknown";
|
|
2218
|
-
|
|
2219
|
-
|
|
2139
|
+
const usage = {
|
|
2140
|
+
inputTokens: void 0,
|
|
2141
|
+
outputTokens: void 0
|
|
2142
|
+
};
|
|
2220
2143
|
let cachedPromptTokens = null;
|
|
2221
2144
|
let reasoningTokens = null;
|
|
2222
2145
|
let responseId = null;
|
|
@@ -2268,8 +2191,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2268
2191
|
});
|
|
2269
2192
|
} else if (isTextDeltaChunk(value)) {
|
|
2270
2193
|
controller.enqueue({
|
|
2271
|
-
type: "text
|
|
2272
|
-
|
|
2194
|
+
type: "text",
|
|
2195
|
+
text: value.delta
|
|
2273
2196
|
});
|
|
2274
2197
|
} else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
|
|
2275
2198
|
ongoingToolCalls[value.output_index] = void 0;
|
|
@@ -2286,19 +2209,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2286
2209
|
finishReason: (_a = value.response.incomplete_details) == null ? void 0 : _a.reason,
|
|
2287
2210
|
hasToolCalls
|
|
2288
2211
|
});
|
|
2289
|
-
|
|
2290
|
-
|
|
2212
|
+
usage.inputTokens = value.response.usage.input_tokens;
|
|
2213
|
+
usage.outputTokens = value.response.usage.output_tokens;
|
|
2291
2214
|
cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
|
|
2292
2215
|
reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
|
|
2293
2216
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2294
2217
|
controller.enqueue({
|
|
2295
2218
|
type: "source",
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
title: value.annotation.title
|
|
2301
|
-
}
|
|
2219
|
+
sourceType: "url",
|
|
2220
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : generateId2(),
|
|
2221
|
+
url: value.annotation.url,
|
|
2222
|
+
title: value.annotation.title
|
|
2302
2223
|
});
|
|
2303
2224
|
}
|
|
2304
2225
|
},
|
|
@@ -2306,7 +2227,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2306
2227
|
controller.enqueue({
|
|
2307
2228
|
type: "finish",
|
|
2308
2229
|
finishReason,
|
|
2309
|
-
usage
|
|
2230
|
+
usage,
|
|
2310
2231
|
...(cachedPromptTokens != null || reasoningTokens != null) && {
|
|
2311
2232
|
providerMetadata: {
|
|
2312
2233
|
openai: {
|
|
@@ -2326,79 +2247,79 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2326
2247
|
};
|
|
2327
2248
|
}
|
|
2328
2249
|
};
|
|
2329
|
-
var usageSchema =
|
|
2330
|
-
input_tokens:
|
|
2331
|
-
input_tokens_details:
|
|
2332
|
-
output_tokens:
|
|
2333
|
-
output_tokens_details:
|
|
2250
|
+
var usageSchema = z9.object({
|
|
2251
|
+
input_tokens: z9.number(),
|
|
2252
|
+
input_tokens_details: z9.object({ cached_tokens: z9.number().nullish() }).nullish(),
|
|
2253
|
+
output_tokens: z9.number(),
|
|
2254
|
+
output_tokens_details: z9.object({ reasoning_tokens: z9.number().nullish() }).nullish()
|
|
2334
2255
|
});
|
|
2335
|
-
var textDeltaChunkSchema =
|
|
2336
|
-
type:
|
|
2337
|
-
delta:
|
|
2256
|
+
var textDeltaChunkSchema = z9.object({
|
|
2257
|
+
type: z9.literal("response.output_text.delta"),
|
|
2258
|
+
delta: z9.string()
|
|
2338
2259
|
});
|
|
2339
|
-
var responseFinishedChunkSchema =
|
|
2340
|
-
type:
|
|
2341
|
-
response:
|
|
2342
|
-
incomplete_details:
|
|
2260
|
+
var responseFinishedChunkSchema = z9.object({
|
|
2261
|
+
type: z9.enum(["response.completed", "response.incomplete"]),
|
|
2262
|
+
response: z9.object({
|
|
2263
|
+
incomplete_details: z9.object({ reason: z9.string() }).nullish(),
|
|
2343
2264
|
usage: usageSchema
|
|
2344
2265
|
})
|
|
2345
2266
|
});
|
|
2346
|
-
var responseCreatedChunkSchema =
|
|
2347
|
-
type:
|
|
2348
|
-
response:
|
|
2349
|
-
id:
|
|
2350
|
-
created_at:
|
|
2351
|
-
model:
|
|
2267
|
+
var responseCreatedChunkSchema = z9.object({
|
|
2268
|
+
type: z9.literal("response.created"),
|
|
2269
|
+
response: z9.object({
|
|
2270
|
+
id: z9.string(),
|
|
2271
|
+
created_at: z9.number(),
|
|
2272
|
+
model: z9.string()
|
|
2352
2273
|
})
|
|
2353
2274
|
});
|
|
2354
|
-
var responseOutputItemDoneSchema =
|
|
2355
|
-
type:
|
|
2356
|
-
output_index:
|
|
2357
|
-
item:
|
|
2358
|
-
|
|
2359
|
-
type:
|
|
2275
|
+
var responseOutputItemDoneSchema = z9.object({
|
|
2276
|
+
type: z9.literal("response.output_item.done"),
|
|
2277
|
+
output_index: z9.number(),
|
|
2278
|
+
item: z9.discriminatedUnion("type", [
|
|
2279
|
+
z9.object({
|
|
2280
|
+
type: z9.literal("message")
|
|
2360
2281
|
}),
|
|
2361
|
-
|
|
2362
|
-
type:
|
|
2363
|
-
id:
|
|
2364
|
-
call_id:
|
|
2365
|
-
name:
|
|
2366
|
-
arguments:
|
|
2367
|
-
status:
|
|
2282
|
+
z9.object({
|
|
2283
|
+
type: z9.literal("function_call"),
|
|
2284
|
+
id: z9.string(),
|
|
2285
|
+
call_id: z9.string(),
|
|
2286
|
+
name: z9.string(),
|
|
2287
|
+
arguments: z9.string(),
|
|
2288
|
+
status: z9.literal("completed")
|
|
2368
2289
|
})
|
|
2369
2290
|
])
|
|
2370
2291
|
});
|
|
2371
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2372
|
-
type:
|
|
2373
|
-
item_id:
|
|
2374
|
-
output_index:
|
|
2375
|
-
delta:
|
|
2292
|
+
var responseFunctionCallArgumentsDeltaSchema = z9.object({
|
|
2293
|
+
type: z9.literal("response.function_call_arguments.delta"),
|
|
2294
|
+
item_id: z9.string(),
|
|
2295
|
+
output_index: z9.number(),
|
|
2296
|
+
delta: z9.string()
|
|
2376
2297
|
});
|
|
2377
|
-
var responseOutputItemAddedSchema =
|
|
2378
|
-
type:
|
|
2379
|
-
output_index:
|
|
2380
|
-
item:
|
|
2381
|
-
|
|
2382
|
-
type:
|
|
2298
|
+
var responseOutputItemAddedSchema = z9.object({
|
|
2299
|
+
type: z9.literal("response.output_item.added"),
|
|
2300
|
+
output_index: z9.number(),
|
|
2301
|
+
item: z9.discriminatedUnion("type", [
|
|
2302
|
+
z9.object({
|
|
2303
|
+
type: z9.literal("message")
|
|
2383
2304
|
}),
|
|
2384
|
-
|
|
2385
|
-
type:
|
|
2386
|
-
id:
|
|
2387
|
-
call_id:
|
|
2388
|
-
name:
|
|
2389
|
-
arguments:
|
|
2305
|
+
z9.object({
|
|
2306
|
+
type: z9.literal("function_call"),
|
|
2307
|
+
id: z9.string(),
|
|
2308
|
+
call_id: z9.string(),
|
|
2309
|
+
name: z9.string(),
|
|
2310
|
+
arguments: z9.string()
|
|
2390
2311
|
})
|
|
2391
2312
|
])
|
|
2392
2313
|
});
|
|
2393
|
-
var responseAnnotationAddedSchema =
|
|
2394
|
-
type:
|
|
2395
|
-
annotation:
|
|
2396
|
-
type:
|
|
2397
|
-
url:
|
|
2398
|
-
title:
|
|
2314
|
+
var responseAnnotationAddedSchema = z9.object({
|
|
2315
|
+
type: z9.literal("response.output_text.annotation.added"),
|
|
2316
|
+
annotation: z9.object({
|
|
2317
|
+
type: z9.literal("url_citation"),
|
|
2318
|
+
url: z9.string(),
|
|
2319
|
+
title: z9.string()
|
|
2399
2320
|
})
|
|
2400
2321
|
});
|
|
2401
|
-
var openaiResponsesChunkSchema =
|
|
2322
|
+
var openaiResponsesChunkSchema = z9.union([
|
|
2402
2323
|
textDeltaChunkSchema,
|
|
2403
2324
|
responseFinishedChunkSchema,
|
|
2404
2325
|
responseCreatedChunkSchema,
|
|
@@ -2406,7 +2327,7 @@ var openaiResponsesChunkSchema = z8.union([
|
|
|
2406
2327
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2407
2328
|
responseOutputItemAddedSchema,
|
|
2408
2329
|
responseAnnotationAddedSchema,
|
|
2409
|
-
|
|
2330
|
+
z9.object({ type: z9.string() }).passthrough()
|
|
2410
2331
|
// fallback for unknown chunks
|
|
2411
2332
|
]);
|
|
2412
2333
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2451,15 +2372,15 @@ function getResponsesModelConfig(modelId) {
|
|
|
2451
2372
|
requiredAutoTruncation: false
|
|
2452
2373
|
};
|
|
2453
2374
|
}
|
|
2454
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2455
|
-
metadata:
|
|
2456
|
-
parallelToolCalls:
|
|
2457
|
-
previousResponseId:
|
|
2458
|
-
store:
|
|
2459
|
-
user:
|
|
2460
|
-
reasoningEffort:
|
|
2461
|
-
strictSchemas:
|
|
2462
|
-
instructions:
|
|
2375
|
+
var openaiResponsesProviderOptionsSchema = z9.object({
|
|
2376
|
+
metadata: z9.any().nullish(),
|
|
2377
|
+
parallelToolCalls: z9.boolean().nullish(),
|
|
2378
|
+
previousResponseId: z9.string().nullish(),
|
|
2379
|
+
store: z9.boolean().nullish(),
|
|
2380
|
+
user: z9.string().nullish(),
|
|
2381
|
+
reasoningEffort: z9.string().nullish(),
|
|
2382
|
+
strictSchemas: z9.boolean().nullish(),
|
|
2383
|
+
instructions: z9.string().nullish()
|
|
2463
2384
|
});
|
|
2464
2385
|
|
|
2465
2386
|
// src/openai-provider.ts
|