@ai-sdk/openai 2.0.0-alpha.9 → 2.0.0-beta.10
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 +150 -0
- package/dist/index.d.mts +63 -76
- package/dist/index.d.ts +63 -76
- package/dist/index.js +1003 -452
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +942 -389
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +43 -201
- package/dist/internal/index.d.ts +43 -201
- package/dist/internal/index.js +997 -428
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +937 -366
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -26,12 +26,12 @@ __export(src_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(src_exports);
|
|
27
27
|
|
|
28
28
|
// src/openai-provider.ts
|
|
29
|
-
var
|
|
29
|
+
var import_provider_utils13 = 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_utils5 = require("@ai-sdk/provider-utils");
|
|
34
|
+
var import_v45 = require("zod/v4");
|
|
35
35
|
|
|
36
36
|
// src/convert-to-openai-chat-messages.ts
|
|
37
37
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -165,7 +165,7 @@ function convertToOpenAIChatMessages({
|
|
|
165
165
|
type: "function",
|
|
166
166
|
function: {
|
|
167
167
|
name: part.toolName,
|
|
168
|
-
arguments: JSON.stringify(part.
|
|
168
|
+
arguments: JSON.stringify(part.input)
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
171
|
break;
|
|
@@ -181,10 +181,23 @@ function convertToOpenAIChatMessages({
|
|
|
181
181
|
}
|
|
182
182
|
case "tool": {
|
|
183
183
|
for (const toolResponse of content) {
|
|
184
|
+
const output = toolResponse.output;
|
|
185
|
+
let contentValue;
|
|
186
|
+
switch (output.type) {
|
|
187
|
+
case "text":
|
|
188
|
+
case "error-text":
|
|
189
|
+
contentValue = output.value;
|
|
190
|
+
break;
|
|
191
|
+
case "content":
|
|
192
|
+
case "json":
|
|
193
|
+
case "error-json":
|
|
194
|
+
contentValue = JSON.stringify(output.value);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
184
197
|
messages.push({
|
|
185
198
|
role: "tool",
|
|
186
199
|
tool_call_id: toolResponse.toolCallId,
|
|
187
|
-
content:
|
|
200
|
+
content: contentValue
|
|
188
201
|
});
|
|
189
202
|
}
|
|
190
203
|
break;
|
|
@@ -229,15 +242,15 @@ function mapOpenAIFinishReason(finishReason) {
|
|
|
229
242
|
}
|
|
230
243
|
|
|
231
244
|
// src/openai-chat-options.ts
|
|
232
|
-
var
|
|
233
|
-
var openaiProviderOptions =
|
|
245
|
+
var import_v4 = require("zod/v4");
|
|
246
|
+
var openaiProviderOptions = import_v4.z.object({
|
|
234
247
|
/**
|
|
235
248
|
* Modify the likelihood of specified tokens appearing in the completion.
|
|
236
249
|
*
|
|
237
250
|
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
238
251
|
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
239
252
|
*/
|
|
240
|
-
logitBias:
|
|
253
|
+
logitBias: import_v4.z.record(import_v4.z.coerce.number(), import_v4.z.number()).optional(),
|
|
241
254
|
/**
|
|
242
255
|
* Return the log probabilities of the tokens.
|
|
243
256
|
*
|
|
@@ -247,56 +260,69 @@ var openaiProviderOptions = import_zod.z.object({
|
|
|
247
260
|
* Setting to a number will return the log probabilities of the top n
|
|
248
261
|
* tokens that were generated.
|
|
249
262
|
*/
|
|
250
|
-
logprobs:
|
|
263
|
+
logprobs: import_v4.z.union([import_v4.z.boolean(), import_v4.z.number()]).optional(),
|
|
251
264
|
/**
|
|
252
265
|
* Whether to enable parallel function calling during tool use. Default to true.
|
|
253
266
|
*/
|
|
254
|
-
parallelToolCalls:
|
|
267
|
+
parallelToolCalls: import_v4.z.boolean().optional(),
|
|
255
268
|
/**
|
|
256
269
|
* A unique identifier representing your end-user, which can help OpenAI to
|
|
257
270
|
* monitor and detect abuse.
|
|
258
271
|
*/
|
|
259
|
-
user:
|
|
272
|
+
user: import_v4.z.string().optional(),
|
|
260
273
|
/**
|
|
261
274
|
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
262
275
|
*/
|
|
263
|
-
reasoningEffort:
|
|
276
|
+
reasoningEffort: import_v4.z.enum(["low", "medium", "high"]).optional(),
|
|
264
277
|
/**
|
|
265
278
|
* Maximum number of completion tokens to generate. Useful for reasoning models.
|
|
266
279
|
*/
|
|
267
|
-
maxCompletionTokens:
|
|
280
|
+
maxCompletionTokens: import_v4.z.number().optional(),
|
|
268
281
|
/**
|
|
269
282
|
* Whether to enable persistence in responses API.
|
|
270
283
|
*/
|
|
271
|
-
store:
|
|
284
|
+
store: import_v4.z.boolean().optional(),
|
|
272
285
|
/**
|
|
273
286
|
* Metadata to associate with the request.
|
|
274
287
|
*/
|
|
275
|
-
metadata:
|
|
288
|
+
metadata: import_v4.z.record(import_v4.z.string().max(64), import_v4.z.string().max(512)).optional(),
|
|
276
289
|
/**
|
|
277
290
|
* Parameters for prediction mode.
|
|
278
291
|
*/
|
|
279
|
-
prediction:
|
|
292
|
+
prediction: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
|
|
280
293
|
/**
|
|
281
294
|
* Whether to use structured outputs.
|
|
282
295
|
*
|
|
283
296
|
* @default true
|
|
284
297
|
*/
|
|
285
|
-
structuredOutputs:
|
|
298
|
+
structuredOutputs: import_v4.z.boolean().optional(),
|
|
299
|
+
/**
|
|
300
|
+
* Service tier for the request. Set to 'flex' for 50% cheaper processing
|
|
301
|
+
* at the cost of increased latency. Only available for o3 and o4-mini models.
|
|
302
|
+
*
|
|
303
|
+
* @default 'auto'
|
|
304
|
+
*/
|
|
305
|
+
serviceTier: import_v4.z.enum(["auto", "flex"]).optional(),
|
|
306
|
+
/**
|
|
307
|
+
* Whether to use strict JSON schema validation.
|
|
308
|
+
*
|
|
309
|
+
* @default false
|
|
310
|
+
*/
|
|
311
|
+
strictJsonSchema: import_v4.z.boolean().optional()
|
|
286
312
|
});
|
|
287
313
|
|
|
288
314
|
// src/openai-error.ts
|
|
289
|
-
var
|
|
315
|
+
var import_v42 = require("zod/v4");
|
|
290
316
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
291
|
-
var openaiErrorDataSchema =
|
|
292
|
-
error:
|
|
293
|
-
message:
|
|
317
|
+
var openaiErrorDataSchema = import_v42.z.object({
|
|
318
|
+
error: import_v42.z.object({
|
|
319
|
+
message: import_v42.z.string(),
|
|
294
320
|
// The additional information below is handled loosely to support
|
|
295
321
|
// OpenAI-compatible providers that have slightly different error
|
|
296
322
|
// responses:
|
|
297
|
-
type:
|
|
298
|
-
param:
|
|
299
|
-
code:
|
|
323
|
+
type: import_v42.z.string().nullish(),
|
|
324
|
+
param: import_v42.z.any().nullish(),
|
|
325
|
+
code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullish()
|
|
300
326
|
})
|
|
301
327
|
});
|
|
302
328
|
var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
|
|
@@ -306,10 +332,81 @@ var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResp
|
|
|
306
332
|
|
|
307
333
|
// src/openai-prepare-tools.ts
|
|
308
334
|
var import_provider2 = require("@ai-sdk/provider");
|
|
335
|
+
|
|
336
|
+
// src/tool/file-search.ts
|
|
337
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
338
|
+
var import_v43 = require("zod/v4");
|
|
339
|
+
var fileSearchArgsSchema = import_v43.z.object({
|
|
340
|
+
/**
|
|
341
|
+
* List of vector store IDs to search through. If not provided, searches all available vector stores.
|
|
342
|
+
*/
|
|
343
|
+
vectorStoreIds: import_v43.z.array(import_v43.z.string()).optional(),
|
|
344
|
+
/**
|
|
345
|
+
* Maximum number of search results to return. Defaults to 10.
|
|
346
|
+
*/
|
|
347
|
+
maxResults: import_v43.z.number().optional(),
|
|
348
|
+
/**
|
|
349
|
+
* Type of search to perform. Defaults to 'auto'.
|
|
350
|
+
*/
|
|
351
|
+
searchType: import_v43.z.enum(["auto", "keyword", "semantic"]).optional()
|
|
352
|
+
});
|
|
353
|
+
var fileSearch = (0, import_provider_utils3.createProviderDefinedToolFactory)({
|
|
354
|
+
id: "openai.file_search",
|
|
355
|
+
name: "file_search",
|
|
356
|
+
inputSchema: import_v43.z.object({
|
|
357
|
+
query: import_v43.z.string()
|
|
358
|
+
})
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// src/tool/web-search-preview.ts
|
|
362
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
363
|
+
var import_v44 = require("zod/v4");
|
|
364
|
+
var webSearchPreviewArgsSchema = import_v44.z.object({
|
|
365
|
+
/**
|
|
366
|
+
* Search context size to use for the web search.
|
|
367
|
+
* - high: Most comprehensive context, highest cost, slower response
|
|
368
|
+
* - medium: Balanced context, cost, and latency (default)
|
|
369
|
+
* - low: Least context, lowest cost, fastest response
|
|
370
|
+
*/
|
|
371
|
+
searchContextSize: import_v44.z.enum(["low", "medium", "high"]).optional(),
|
|
372
|
+
/**
|
|
373
|
+
* User location information to provide geographically relevant search results.
|
|
374
|
+
*/
|
|
375
|
+
userLocation: import_v44.z.object({
|
|
376
|
+
/**
|
|
377
|
+
* Type of location (always 'approximate')
|
|
378
|
+
*/
|
|
379
|
+
type: import_v44.z.literal("approximate"),
|
|
380
|
+
/**
|
|
381
|
+
* Two-letter ISO country code (e.g., 'US', 'GB')
|
|
382
|
+
*/
|
|
383
|
+
country: import_v44.z.string().optional(),
|
|
384
|
+
/**
|
|
385
|
+
* City name (free text, e.g., 'Minneapolis')
|
|
386
|
+
*/
|
|
387
|
+
city: import_v44.z.string().optional(),
|
|
388
|
+
/**
|
|
389
|
+
* Region name (free text, e.g., 'Minnesota')
|
|
390
|
+
*/
|
|
391
|
+
region: import_v44.z.string().optional(),
|
|
392
|
+
/**
|
|
393
|
+
* IANA timezone (e.g., 'America/Chicago')
|
|
394
|
+
*/
|
|
395
|
+
timezone: import_v44.z.string().optional()
|
|
396
|
+
}).optional()
|
|
397
|
+
});
|
|
398
|
+
var webSearchPreview = (0, import_provider_utils4.createProviderDefinedToolFactory)({
|
|
399
|
+
id: "openai.web_search_preview",
|
|
400
|
+
name: "web_search_preview",
|
|
401
|
+
inputSchema: import_v44.z.object({})
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// src/openai-prepare-tools.ts
|
|
309
405
|
function prepareTools({
|
|
310
406
|
tools,
|
|
311
407
|
toolChoice,
|
|
312
|
-
structuredOutputs
|
|
408
|
+
structuredOutputs,
|
|
409
|
+
strictJsonSchema
|
|
313
410
|
}) {
|
|
314
411
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
315
412
|
const toolWarnings = [];
|
|
@@ -318,18 +415,47 @@ function prepareTools({
|
|
|
318
415
|
}
|
|
319
416
|
const openaiTools2 = [];
|
|
320
417
|
for (const tool of tools) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
418
|
+
switch (tool.type) {
|
|
419
|
+
case "function":
|
|
420
|
+
openaiTools2.push({
|
|
421
|
+
type: "function",
|
|
422
|
+
function: {
|
|
423
|
+
name: tool.name,
|
|
424
|
+
description: tool.description,
|
|
425
|
+
parameters: tool.inputSchema,
|
|
426
|
+
strict: structuredOutputs ? strictJsonSchema : void 0
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
break;
|
|
430
|
+
case "provider-defined":
|
|
431
|
+
switch (tool.id) {
|
|
432
|
+
case "openai.file_search": {
|
|
433
|
+
const args = fileSearchArgsSchema.parse(tool.args);
|
|
434
|
+
openaiTools2.push({
|
|
435
|
+
type: "file_search",
|
|
436
|
+
vector_store_ids: args.vectorStoreIds,
|
|
437
|
+
max_results: args.maxResults,
|
|
438
|
+
search_type: args.searchType
|
|
439
|
+
});
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
case "openai.web_search_preview": {
|
|
443
|
+
const args = webSearchPreviewArgsSchema.parse(tool.args);
|
|
444
|
+
openaiTools2.push({
|
|
445
|
+
type: "web_search_preview",
|
|
446
|
+
search_context_size: args.searchContextSize,
|
|
447
|
+
user_location: args.userLocation
|
|
448
|
+
});
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
default:
|
|
452
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
453
|
+
break;
|
|
331
454
|
}
|
|
332
|
-
|
|
455
|
+
break;
|
|
456
|
+
default:
|
|
457
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
458
|
+
break;
|
|
333
459
|
}
|
|
334
460
|
}
|
|
335
461
|
if (toolChoice == null) {
|
|
@@ -389,9 +515,9 @@ var OpenAIChatLanguageModel = class {
|
|
|
389
515
|
toolChoice,
|
|
390
516
|
providerOptions
|
|
391
517
|
}) {
|
|
392
|
-
var _a, _b, _c;
|
|
518
|
+
var _a, _b, _c, _d;
|
|
393
519
|
const warnings = [];
|
|
394
|
-
const openaiOptions = (_a = await (0,
|
|
520
|
+
const openaiOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
|
|
395
521
|
provider: "openai",
|
|
396
522
|
providerOptions,
|
|
397
523
|
schema: openaiProviderOptions
|
|
@@ -417,6 +543,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
417
543
|
}
|
|
418
544
|
);
|
|
419
545
|
warnings.push(...messageWarnings);
|
|
546
|
+
const strictJsonSchema = (_c = openaiOptions.strictJsonSchema) != null ? _c : false;
|
|
420
547
|
const baseArgs = {
|
|
421
548
|
// model id:
|
|
422
549
|
model: this.modelId,
|
|
@@ -432,18 +559,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
432
559
|
top_p: topP,
|
|
433
560
|
frequency_penalty: frequencyPenalty,
|
|
434
561
|
presence_penalty: presencePenalty,
|
|
435
|
-
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ?
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
} : { type: "json_object" }
|
|
446
|
-
) : void 0,
|
|
562
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && responseFormat.schema != null ? {
|
|
563
|
+
type: "json_schema",
|
|
564
|
+
json_schema: {
|
|
565
|
+
schema: responseFormat.schema,
|
|
566
|
+
strict: strictJsonSchema,
|
|
567
|
+
name: (_d = responseFormat.name) != null ? _d : "response",
|
|
568
|
+
description: responseFormat.description
|
|
569
|
+
}
|
|
570
|
+
} : { type: "json_object" } : void 0,
|
|
447
571
|
stop: stopSequences,
|
|
448
572
|
seed,
|
|
449
573
|
// openai specific settings:
|
|
@@ -453,6 +577,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
453
577
|
metadata: openaiOptions.metadata,
|
|
454
578
|
prediction: openaiOptions.prediction,
|
|
455
579
|
reasoning_effort: openaiOptions.reasoningEffort,
|
|
580
|
+
service_tier: openaiOptions.serviceTier,
|
|
456
581
|
// messages:
|
|
457
582
|
messages
|
|
458
583
|
};
|
|
@@ -526,6 +651,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
526
651
|
});
|
|
527
652
|
}
|
|
528
653
|
}
|
|
654
|
+
if (openaiOptions.serviceTier === "flex" && !supportsFlexProcessing(this.modelId)) {
|
|
655
|
+
warnings.push({
|
|
656
|
+
type: "unsupported-setting",
|
|
657
|
+
setting: "serviceTier",
|
|
658
|
+
details: "flex processing is only available for o3 and o4-mini models"
|
|
659
|
+
});
|
|
660
|
+
baseArgs.service_tier = void 0;
|
|
661
|
+
}
|
|
529
662
|
const {
|
|
530
663
|
tools: openaiTools2,
|
|
531
664
|
toolChoice: openaiToolChoice,
|
|
@@ -533,7 +666,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
533
666
|
} = prepareTools({
|
|
534
667
|
tools,
|
|
535
668
|
toolChoice,
|
|
536
|
-
structuredOutputs
|
|
669
|
+
structuredOutputs,
|
|
670
|
+
strictJsonSchema
|
|
537
671
|
});
|
|
538
672
|
return {
|
|
539
673
|
args: {
|
|
@@ -551,15 +685,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
551
685
|
responseHeaders,
|
|
552
686
|
value: response,
|
|
553
687
|
rawValue: rawResponse
|
|
554
|
-
} = await (0,
|
|
688
|
+
} = await (0, import_provider_utils5.postJsonToApi)({
|
|
555
689
|
url: this.config.url({
|
|
556
690
|
path: "/chat/completions",
|
|
557
691
|
modelId: this.modelId
|
|
558
692
|
}),
|
|
559
|
-
headers: (0,
|
|
693
|
+
headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
|
|
560
694
|
body,
|
|
561
695
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
562
|
-
successfulResponseHandler: (0,
|
|
696
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
563
697
|
openaiChatResponseSchema
|
|
564
698
|
),
|
|
565
699
|
abortSignal: options.abortSignal,
|
|
@@ -574,10 +708,9 @@ var OpenAIChatLanguageModel = class {
|
|
|
574
708
|
for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
|
|
575
709
|
content.push({
|
|
576
710
|
type: "tool-call",
|
|
577
|
-
|
|
578
|
-
toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils3.generateId)(),
|
|
711
|
+
toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils5.generateId)(),
|
|
579
712
|
toolName: toolCall.function.name,
|
|
580
|
-
|
|
713
|
+
input: toolCall.function.arguments
|
|
581
714
|
});
|
|
582
715
|
}
|
|
583
716
|
const completionTokenDetails = (_c = response.usage) == null ? void 0 : _c.completion_tokens_details;
|
|
@@ -621,15 +754,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
621
754
|
include_usage: true
|
|
622
755
|
}
|
|
623
756
|
};
|
|
624
|
-
const { responseHeaders, value: response } = await (0,
|
|
757
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({
|
|
625
758
|
url: this.config.url({
|
|
626
759
|
path: "/chat/completions",
|
|
627
760
|
modelId: this.modelId
|
|
628
761
|
}),
|
|
629
|
-
headers: (0,
|
|
762
|
+
headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
|
|
630
763
|
body,
|
|
631
764
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
632
|
-
successfulResponseHandler: (0,
|
|
765
|
+
successfulResponseHandler: (0, import_provider_utils5.createEventSourceResponseHandler)(
|
|
633
766
|
openaiChatChunkSchema
|
|
634
767
|
),
|
|
635
768
|
abortSignal: options.abortSignal,
|
|
@@ -643,6 +776,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
643
776
|
totalTokens: void 0
|
|
644
777
|
};
|
|
645
778
|
let isFirstChunk = true;
|
|
779
|
+
let isActiveText = false;
|
|
646
780
|
const providerMetadata = { openai: {} };
|
|
647
781
|
return {
|
|
648
782
|
stream: response.pipeThrough(
|
|
@@ -652,6 +786,9 @@ var OpenAIChatLanguageModel = class {
|
|
|
652
786
|
},
|
|
653
787
|
transform(chunk, controller) {
|
|
654
788
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
789
|
+
if (options.includeRawChunks) {
|
|
790
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
791
|
+
}
|
|
655
792
|
if (!chunk.success) {
|
|
656
793
|
finishReason = "error";
|
|
657
794
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -695,9 +832,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
695
832
|
}
|
|
696
833
|
const delta = choice.delta;
|
|
697
834
|
if (delta.content != null) {
|
|
835
|
+
if (!isActiveText) {
|
|
836
|
+
controller.enqueue({ type: "text-start", id: "0" });
|
|
837
|
+
isActiveText = true;
|
|
838
|
+
}
|
|
698
839
|
controller.enqueue({
|
|
699
|
-
type: "text",
|
|
700
|
-
|
|
840
|
+
type: "text-delta",
|
|
841
|
+
id: "0",
|
|
842
|
+
delta: delta.content
|
|
701
843
|
});
|
|
702
844
|
}
|
|
703
845
|
if (delta.tool_calls != null) {
|
|
@@ -722,6 +864,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
722
864
|
message: `Expected 'function.name' to be a string.`
|
|
723
865
|
});
|
|
724
866
|
}
|
|
867
|
+
controller.enqueue({
|
|
868
|
+
type: "tool-input-start",
|
|
869
|
+
id: toolCallDelta.id,
|
|
870
|
+
toolName: toolCallDelta.function.name
|
|
871
|
+
});
|
|
725
872
|
toolCalls[index] = {
|
|
726
873
|
id: toolCallDelta.id,
|
|
727
874
|
type: "function",
|
|
@@ -735,20 +882,21 @@ var OpenAIChatLanguageModel = class {
|
|
|
735
882
|
if (((_o = toolCall2.function) == null ? void 0 : _o.name) != null && ((_p = toolCall2.function) == null ? void 0 : _p.arguments) != null) {
|
|
736
883
|
if (toolCall2.function.arguments.length > 0) {
|
|
737
884
|
controller.enqueue({
|
|
738
|
-
type: "tool-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
toolName: toolCall2.function.name,
|
|
742
|
-
argsTextDelta: toolCall2.function.arguments
|
|
885
|
+
type: "tool-input-delta",
|
|
886
|
+
id: toolCall2.id,
|
|
887
|
+
delta: toolCall2.function.arguments
|
|
743
888
|
});
|
|
744
889
|
}
|
|
745
|
-
if ((0,
|
|
890
|
+
if ((0, import_provider_utils5.isParsableJson)(toolCall2.function.arguments)) {
|
|
891
|
+
controller.enqueue({
|
|
892
|
+
type: "tool-input-end",
|
|
893
|
+
id: toolCall2.id
|
|
894
|
+
});
|
|
746
895
|
controller.enqueue({
|
|
747
896
|
type: "tool-call",
|
|
748
|
-
|
|
749
|
-
toolCallId: (_q = toolCall2.id) != null ? _q : (0, import_provider_utils3.generateId)(),
|
|
897
|
+
toolCallId: (_q = toolCall2.id) != null ? _q : (0, import_provider_utils5.generateId)(),
|
|
750
898
|
toolName: toolCall2.function.name,
|
|
751
|
-
|
|
899
|
+
input: toolCall2.function.arguments
|
|
752
900
|
});
|
|
753
901
|
toolCall2.hasFinished = true;
|
|
754
902
|
}
|
|
@@ -763,19 +911,20 @@ var OpenAIChatLanguageModel = class {
|
|
|
763
911
|
toolCall.function.arguments += (_t = (_s = toolCallDelta.function) == null ? void 0 : _s.arguments) != null ? _t : "";
|
|
764
912
|
}
|
|
765
913
|
controller.enqueue({
|
|
766
|
-
type: "tool-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
toolName: toolCall.function.name,
|
|
770
|
-
argsTextDelta: (_u = toolCallDelta.function.arguments) != null ? _u : ""
|
|
914
|
+
type: "tool-input-delta",
|
|
915
|
+
id: toolCall.id,
|
|
916
|
+
delta: (_u = toolCallDelta.function.arguments) != null ? _u : ""
|
|
771
917
|
});
|
|
772
|
-
if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null && (0,
|
|
918
|
+
if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null && (0, import_provider_utils5.isParsableJson)(toolCall.function.arguments)) {
|
|
919
|
+
controller.enqueue({
|
|
920
|
+
type: "tool-input-end",
|
|
921
|
+
id: toolCall.id
|
|
922
|
+
});
|
|
773
923
|
controller.enqueue({
|
|
774
924
|
type: "tool-call",
|
|
775
|
-
|
|
776
|
-
toolCallId: (_x = toolCall.id) != null ? _x : (0, import_provider_utils3.generateId)(),
|
|
925
|
+
toolCallId: (_x = toolCall.id) != null ? _x : (0, import_provider_utils5.generateId)(),
|
|
777
926
|
toolName: toolCall.function.name,
|
|
778
|
-
|
|
927
|
+
input: toolCall.function.arguments
|
|
779
928
|
});
|
|
780
929
|
toolCall.hasFinished = true;
|
|
781
930
|
}
|
|
@@ -783,6 +932,9 @@ var OpenAIChatLanguageModel = class {
|
|
|
783
932
|
}
|
|
784
933
|
},
|
|
785
934
|
flush(controller) {
|
|
935
|
+
if (isActiveText) {
|
|
936
|
+
controller.enqueue({ type: "text-end", id: "0" });
|
|
937
|
+
}
|
|
786
938
|
controller.enqueue({
|
|
787
939
|
type: "finish",
|
|
788
940
|
finishReason,
|
|
@@ -797,97 +949,97 @@ var OpenAIChatLanguageModel = class {
|
|
|
797
949
|
};
|
|
798
950
|
}
|
|
799
951
|
};
|
|
800
|
-
var openaiTokenUsageSchema =
|
|
801
|
-
prompt_tokens:
|
|
802
|
-
completion_tokens:
|
|
803
|
-
total_tokens:
|
|
804
|
-
prompt_tokens_details:
|
|
805
|
-
cached_tokens:
|
|
952
|
+
var openaiTokenUsageSchema = import_v45.z.object({
|
|
953
|
+
prompt_tokens: import_v45.z.number().nullish(),
|
|
954
|
+
completion_tokens: import_v45.z.number().nullish(),
|
|
955
|
+
total_tokens: import_v45.z.number().nullish(),
|
|
956
|
+
prompt_tokens_details: import_v45.z.object({
|
|
957
|
+
cached_tokens: import_v45.z.number().nullish()
|
|
806
958
|
}).nullish(),
|
|
807
|
-
completion_tokens_details:
|
|
808
|
-
reasoning_tokens:
|
|
809
|
-
accepted_prediction_tokens:
|
|
810
|
-
rejected_prediction_tokens:
|
|
959
|
+
completion_tokens_details: import_v45.z.object({
|
|
960
|
+
reasoning_tokens: import_v45.z.number().nullish(),
|
|
961
|
+
accepted_prediction_tokens: import_v45.z.number().nullish(),
|
|
962
|
+
rejected_prediction_tokens: import_v45.z.number().nullish()
|
|
811
963
|
}).nullish()
|
|
812
964
|
}).nullish();
|
|
813
|
-
var openaiChatResponseSchema =
|
|
814
|
-
id:
|
|
815
|
-
created:
|
|
816
|
-
model:
|
|
817
|
-
choices:
|
|
818
|
-
|
|
819
|
-
message:
|
|
820
|
-
role:
|
|
821
|
-
content:
|
|
822
|
-
tool_calls:
|
|
823
|
-
|
|
824
|
-
id:
|
|
825
|
-
type:
|
|
826
|
-
function:
|
|
827
|
-
name:
|
|
828
|
-
arguments:
|
|
965
|
+
var openaiChatResponseSchema = import_v45.z.object({
|
|
966
|
+
id: import_v45.z.string().nullish(),
|
|
967
|
+
created: import_v45.z.number().nullish(),
|
|
968
|
+
model: import_v45.z.string().nullish(),
|
|
969
|
+
choices: import_v45.z.array(
|
|
970
|
+
import_v45.z.object({
|
|
971
|
+
message: import_v45.z.object({
|
|
972
|
+
role: import_v45.z.literal("assistant").nullish(),
|
|
973
|
+
content: import_v45.z.string().nullish(),
|
|
974
|
+
tool_calls: import_v45.z.array(
|
|
975
|
+
import_v45.z.object({
|
|
976
|
+
id: import_v45.z.string().nullish(),
|
|
977
|
+
type: import_v45.z.literal("function"),
|
|
978
|
+
function: import_v45.z.object({
|
|
979
|
+
name: import_v45.z.string(),
|
|
980
|
+
arguments: import_v45.z.string()
|
|
829
981
|
})
|
|
830
982
|
})
|
|
831
983
|
).nullish()
|
|
832
984
|
}),
|
|
833
|
-
index:
|
|
834
|
-
logprobs:
|
|
835
|
-
content:
|
|
836
|
-
|
|
837
|
-
token:
|
|
838
|
-
logprob:
|
|
839
|
-
top_logprobs:
|
|
840
|
-
|
|
841
|
-
token:
|
|
842
|
-
logprob:
|
|
985
|
+
index: import_v45.z.number(),
|
|
986
|
+
logprobs: import_v45.z.object({
|
|
987
|
+
content: import_v45.z.array(
|
|
988
|
+
import_v45.z.object({
|
|
989
|
+
token: import_v45.z.string(),
|
|
990
|
+
logprob: import_v45.z.number(),
|
|
991
|
+
top_logprobs: import_v45.z.array(
|
|
992
|
+
import_v45.z.object({
|
|
993
|
+
token: import_v45.z.string(),
|
|
994
|
+
logprob: import_v45.z.number()
|
|
843
995
|
})
|
|
844
996
|
)
|
|
845
997
|
})
|
|
846
998
|
).nullish()
|
|
847
999
|
}).nullish(),
|
|
848
|
-
finish_reason:
|
|
1000
|
+
finish_reason: import_v45.z.string().nullish()
|
|
849
1001
|
})
|
|
850
1002
|
),
|
|
851
1003
|
usage: openaiTokenUsageSchema
|
|
852
1004
|
});
|
|
853
|
-
var openaiChatChunkSchema =
|
|
854
|
-
|
|
855
|
-
id:
|
|
856
|
-
created:
|
|
857
|
-
model:
|
|
858
|
-
choices:
|
|
859
|
-
|
|
860
|
-
delta:
|
|
861
|
-
role:
|
|
862
|
-
content:
|
|
863
|
-
tool_calls:
|
|
864
|
-
|
|
865
|
-
index:
|
|
866
|
-
id:
|
|
867
|
-
type:
|
|
868
|
-
function:
|
|
869
|
-
name:
|
|
870
|
-
arguments:
|
|
1005
|
+
var openaiChatChunkSchema = import_v45.z.union([
|
|
1006
|
+
import_v45.z.object({
|
|
1007
|
+
id: import_v45.z.string().nullish(),
|
|
1008
|
+
created: import_v45.z.number().nullish(),
|
|
1009
|
+
model: import_v45.z.string().nullish(),
|
|
1010
|
+
choices: import_v45.z.array(
|
|
1011
|
+
import_v45.z.object({
|
|
1012
|
+
delta: import_v45.z.object({
|
|
1013
|
+
role: import_v45.z.enum(["assistant"]).nullish(),
|
|
1014
|
+
content: import_v45.z.string().nullish(),
|
|
1015
|
+
tool_calls: import_v45.z.array(
|
|
1016
|
+
import_v45.z.object({
|
|
1017
|
+
index: import_v45.z.number(),
|
|
1018
|
+
id: import_v45.z.string().nullish(),
|
|
1019
|
+
type: import_v45.z.literal("function").nullish(),
|
|
1020
|
+
function: import_v45.z.object({
|
|
1021
|
+
name: import_v45.z.string().nullish(),
|
|
1022
|
+
arguments: import_v45.z.string().nullish()
|
|
871
1023
|
})
|
|
872
1024
|
})
|
|
873
1025
|
).nullish()
|
|
874
1026
|
}).nullish(),
|
|
875
|
-
logprobs:
|
|
876
|
-
content:
|
|
877
|
-
|
|
878
|
-
token:
|
|
879
|
-
logprob:
|
|
880
|
-
top_logprobs:
|
|
881
|
-
|
|
882
|
-
token:
|
|
883
|
-
logprob:
|
|
1027
|
+
logprobs: import_v45.z.object({
|
|
1028
|
+
content: import_v45.z.array(
|
|
1029
|
+
import_v45.z.object({
|
|
1030
|
+
token: import_v45.z.string(),
|
|
1031
|
+
logprob: import_v45.z.number(),
|
|
1032
|
+
top_logprobs: import_v45.z.array(
|
|
1033
|
+
import_v45.z.object({
|
|
1034
|
+
token: import_v45.z.string(),
|
|
1035
|
+
logprob: import_v45.z.number()
|
|
884
1036
|
})
|
|
885
1037
|
)
|
|
886
1038
|
})
|
|
887
1039
|
).nullish()
|
|
888
1040
|
}).nullish(),
|
|
889
|
-
finish_reason:
|
|
890
|
-
index:
|
|
1041
|
+
finish_reason: import_v45.z.string().nullish(),
|
|
1042
|
+
index: import_v45.z.number()
|
|
891
1043
|
})
|
|
892
1044
|
),
|
|
893
1045
|
usage: openaiTokenUsageSchema
|
|
@@ -897,6 +1049,9 @@ var openaiChatChunkSchema = import_zod3.z.union([
|
|
|
897
1049
|
function isReasoningModel(modelId) {
|
|
898
1050
|
return modelId.startsWith("o");
|
|
899
1051
|
}
|
|
1052
|
+
function supportsFlexProcessing(modelId) {
|
|
1053
|
+
return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
1054
|
+
}
|
|
900
1055
|
function getSystemMessageMode(modelId) {
|
|
901
1056
|
var _a, _b;
|
|
902
1057
|
if (!isReasoningModel(modelId)) {
|
|
@@ -938,8 +1093,8 @@ var reasoningModels = {
|
|
|
938
1093
|
};
|
|
939
1094
|
|
|
940
1095
|
// src/openai-completion-language-model.ts
|
|
941
|
-
var
|
|
942
|
-
var
|
|
1096
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1097
|
+
var import_v47 = require("zod/v4");
|
|
943
1098
|
|
|
944
1099
|
// src/convert-to-openai-completion-prompt.ts
|
|
945
1100
|
var import_provider4 = require("@ai-sdk/provider");
|
|
@@ -1017,12 +1172,12 @@ ${user}:`]
|
|
|
1017
1172
|
}
|
|
1018
1173
|
|
|
1019
1174
|
// src/openai-completion-options.ts
|
|
1020
|
-
var
|
|
1021
|
-
var openaiCompletionProviderOptions =
|
|
1175
|
+
var import_v46 = require("zod/v4");
|
|
1176
|
+
var openaiCompletionProviderOptions = import_v46.z.object({
|
|
1022
1177
|
/**
|
|
1023
1178
|
Echo back the prompt in addition to the completion.
|
|
1024
1179
|
*/
|
|
1025
|
-
echo:
|
|
1180
|
+
echo: import_v46.z.boolean().optional(),
|
|
1026
1181
|
/**
|
|
1027
1182
|
Modify the likelihood of specified tokens appearing in the completion.
|
|
1028
1183
|
|
|
@@ -1037,16 +1192,16 @@ var openaiCompletionProviderOptions = import_zod4.z.object({
|
|
|
1037
1192
|
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
1038
1193
|
token from being generated.
|
|
1039
1194
|
*/
|
|
1040
|
-
logitBias:
|
|
1195
|
+
logitBias: import_v46.z.record(import_v46.z.string(), import_v46.z.number()).optional(),
|
|
1041
1196
|
/**
|
|
1042
1197
|
The suffix that comes after a completion of inserted text.
|
|
1043
1198
|
*/
|
|
1044
|
-
suffix:
|
|
1199
|
+
suffix: import_v46.z.string().optional(),
|
|
1045
1200
|
/**
|
|
1046
1201
|
A unique identifier representing your end-user, which can help OpenAI to
|
|
1047
1202
|
monitor and detect abuse. Learn more.
|
|
1048
1203
|
*/
|
|
1049
|
-
user:
|
|
1204
|
+
user: import_v46.z.string().optional(),
|
|
1050
1205
|
/**
|
|
1051
1206
|
Return the log probabilities of the tokens. Including logprobs will increase
|
|
1052
1207
|
the response size and can slow down response times. However, it can
|
|
@@ -1056,7 +1211,7 @@ var openaiCompletionProviderOptions = import_zod4.z.object({
|
|
|
1056
1211
|
Setting to a number will return the log probabilities of the top n
|
|
1057
1212
|
tokens that were generated.
|
|
1058
1213
|
*/
|
|
1059
|
-
logprobs:
|
|
1214
|
+
logprobs: import_v46.z.union([import_v46.z.boolean(), import_v46.z.number()]).optional()
|
|
1060
1215
|
});
|
|
1061
1216
|
|
|
1062
1217
|
// src/openai-completion-language-model.ts
|
|
@@ -1092,12 +1247,12 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1092
1247
|
}) {
|
|
1093
1248
|
const warnings = [];
|
|
1094
1249
|
const openaiOptions = {
|
|
1095
|
-
...await (0,
|
|
1250
|
+
...await (0, import_provider_utils6.parseProviderOptions)({
|
|
1096
1251
|
provider: "openai",
|
|
1097
1252
|
providerOptions,
|
|
1098
1253
|
schema: openaiCompletionProviderOptions
|
|
1099
1254
|
}),
|
|
1100
|
-
...await (0,
|
|
1255
|
+
...await (0, import_provider_utils6.parseProviderOptions)({
|
|
1101
1256
|
provider: this.providerOptionsName,
|
|
1102
1257
|
providerOptions,
|
|
1103
1258
|
schema: openaiCompletionProviderOptions
|
|
@@ -1153,15 +1308,15 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1153
1308
|
responseHeaders,
|
|
1154
1309
|
value: response,
|
|
1155
1310
|
rawValue: rawResponse
|
|
1156
|
-
} = await (0,
|
|
1311
|
+
} = await (0, import_provider_utils6.postJsonToApi)({
|
|
1157
1312
|
url: this.config.url({
|
|
1158
1313
|
path: "/completions",
|
|
1159
1314
|
modelId: this.modelId
|
|
1160
1315
|
}),
|
|
1161
|
-
headers: (0,
|
|
1316
|
+
headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
|
|
1162
1317
|
body: args,
|
|
1163
1318
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1164
|
-
successfulResponseHandler: (0,
|
|
1319
|
+
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
|
|
1165
1320
|
openaiCompletionResponseSchema
|
|
1166
1321
|
),
|
|
1167
1322
|
abortSignal: options.abortSignal,
|
|
@@ -1199,15 +1354,15 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1199
1354
|
include_usage: true
|
|
1200
1355
|
}
|
|
1201
1356
|
};
|
|
1202
|
-
const { responseHeaders, value: response } = await (0,
|
|
1357
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({
|
|
1203
1358
|
url: this.config.url({
|
|
1204
1359
|
path: "/completions",
|
|
1205
1360
|
modelId: this.modelId
|
|
1206
1361
|
}),
|
|
1207
|
-
headers: (0,
|
|
1362
|
+
headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
|
|
1208
1363
|
body,
|
|
1209
1364
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1210
|
-
successfulResponseHandler: (0,
|
|
1365
|
+
successfulResponseHandler: (0, import_provider_utils6.createEventSourceResponseHandler)(
|
|
1211
1366
|
openaiCompletionChunkSchema
|
|
1212
1367
|
),
|
|
1213
1368
|
abortSignal: options.abortSignal,
|
|
@@ -1228,6 +1383,9 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1228
1383
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1229
1384
|
},
|
|
1230
1385
|
transform(chunk, controller) {
|
|
1386
|
+
if (options.includeRawChunks) {
|
|
1387
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1388
|
+
}
|
|
1231
1389
|
if (!chunk.success) {
|
|
1232
1390
|
finishReason = "error";
|
|
1233
1391
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1245,6 +1403,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1245
1403
|
type: "response-metadata",
|
|
1246
1404
|
...getResponseMetadata(value)
|
|
1247
1405
|
});
|
|
1406
|
+
controller.enqueue({ type: "text-start", id: "0" });
|
|
1248
1407
|
}
|
|
1249
1408
|
if (value.usage != null) {
|
|
1250
1409
|
usage.inputTokens = value.usage.prompt_tokens;
|
|
@@ -1258,14 +1417,18 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1258
1417
|
if ((choice == null ? void 0 : choice.logprobs) != null) {
|
|
1259
1418
|
providerMetadata.openai.logprobs = choice.logprobs;
|
|
1260
1419
|
}
|
|
1261
|
-
if ((choice == null ? void 0 : choice.text) != null) {
|
|
1420
|
+
if ((choice == null ? void 0 : choice.text) != null && choice.text.length > 0) {
|
|
1262
1421
|
controller.enqueue({
|
|
1263
|
-
type: "text",
|
|
1264
|
-
|
|
1422
|
+
type: "text-delta",
|
|
1423
|
+
id: "0",
|
|
1424
|
+
delta: choice.text
|
|
1265
1425
|
});
|
|
1266
1426
|
}
|
|
1267
1427
|
},
|
|
1268
1428
|
flush(controller) {
|
|
1429
|
+
if (!isFirstChunk) {
|
|
1430
|
+
controller.enqueue({ type: "text-end", id: "0" });
|
|
1431
|
+
}
|
|
1269
1432
|
controller.enqueue({
|
|
1270
1433
|
type: "finish",
|
|
1271
1434
|
finishReason,
|
|
@@ -1280,42 +1443,42 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1280
1443
|
};
|
|
1281
1444
|
}
|
|
1282
1445
|
};
|
|
1283
|
-
var usageSchema =
|
|
1284
|
-
prompt_tokens:
|
|
1285
|
-
completion_tokens:
|
|
1286
|
-
total_tokens:
|
|
1446
|
+
var usageSchema = import_v47.z.object({
|
|
1447
|
+
prompt_tokens: import_v47.z.number(),
|
|
1448
|
+
completion_tokens: import_v47.z.number(),
|
|
1449
|
+
total_tokens: import_v47.z.number()
|
|
1287
1450
|
});
|
|
1288
|
-
var openaiCompletionResponseSchema =
|
|
1289
|
-
id:
|
|
1290
|
-
created:
|
|
1291
|
-
model:
|
|
1292
|
-
choices:
|
|
1293
|
-
|
|
1294
|
-
text:
|
|
1295
|
-
finish_reason:
|
|
1296
|
-
logprobs:
|
|
1297
|
-
tokens:
|
|
1298
|
-
token_logprobs:
|
|
1299
|
-
top_logprobs:
|
|
1451
|
+
var openaiCompletionResponseSchema = import_v47.z.object({
|
|
1452
|
+
id: import_v47.z.string().nullish(),
|
|
1453
|
+
created: import_v47.z.number().nullish(),
|
|
1454
|
+
model: import_v47.z.string().nullish(),
|
|
1455
|
+
choices: import_v47.z.array(
|
|
1456
|
+
import_v47.z.object({
|
|
1457
|
+
text: import_v47.z.string(),
|
|
1458
|
+
finish_reason: import_v47.z.string(),
|
|
1459
|
+
logprobs: import_v47.z.object({
|
|
1460
|
+
tokens: import_v47.z.array(import_v47.z.string()),
|
|
1461
|
+
token_logprobs: import_v47.z.array(import_v47.z.number()),
|
|
1462
|
+
top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullish()
|
|
1300
1463
|
}).nullish()
|
|
1301
1464
|
})
|
|
1302
1465
|
),
|
|
1303
1466
|
usage: usageSchema.nullish()
|
|
1304
1467
|
});
|
|
1305
|
-
var openaiCompletionChunkSchema =
|
|
1306
|
-
|
|
1307
|
-
id:
|
|
1308
|
-
created:
|
|
1309
|
-
model:
|
|
1310
|
-
choices:
|
|
1311
|
-
|
|
1312
|
-
text:
|
|
1313
|
-
finish_reason:
|
|
1314
|
-
index:
|
|
1315
|
-
logprobs:
|
|
1316
|
-
tokens:
|
|
1317
|
-
token_logprobs:
|
|
1318
|
-
top_logprobs:
|
|
1468
|
+
var openaiCompletionChunkSchema = import_v47.z.union([
|
|
1469
|
+
import_v47.z.object({
|
|
1470
|
+
id: import_v47.z.string().nullish(),
|
|
1471
|
+
created: import_v47.z.number().nullish(),
|
|
1472
|
+
model: import_v47.z.string().nullish(),
|
|
1473
|
+
choices: import_v47.z.array(
|
|
1474
|
+
import_v47.z.object({
|
|
1475
|
+
text: import_v47.z.string(),
|
|
1476
|
+
finish_reason: import_v47.z.string().nullish(),
|
|
1477
|
+
index: import_v47.z.number(),
|
|
1478
|
+
logprobs: import_v47.z.object({
|
|
1479
|
+
tokens: import_v47.z.array(import_v47.z.string()),
|
|
1480
|
+
token_logprobs: import_v47.z.array(import_v47.z.number()),
|
|
1481
|
+
top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullish()
|
|
1319
1482
|
}).nullish()
|
|
1320
1483
|
})
|
|
1321
1484
|
),
|
|
@@ -1326,22 +1489,22 @@ var openaiCompletionChunkSchema = import_zod5.z.union([
|
|
|
1326
1489
|
|
|
1327
1490
|
// src/openai-embedding-model.ts
|
|
1328
1491
|
var import_provider5 = require("@ai-sdk/provider");
|
|
1329
|
-
var
|
|
1330
|
-
var
|
|
1492
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1493
|
+
var import_v49 = require("zod/v4");
|
|
1331
1494
|
|
|
1332
1495
|
// src/openai-embedding-options.ts
|
|
1333
|
-
var
|
|
1334
|
-
var openaiEmbeddingProviderOptions =
|
|
1496
|
+
var import_v48 = require("zod/v4");
|
|
1497
|
+
var openaiEmbeddingProviderOptions = import_v48.z.object({
|
|
1335
1498
|
/**
|
|
1336
1499
|
The number of dimensions the resulting output embeddings should have.
|
|
1337
1500
|
Only supported in text-embedding-3 and later models.
|
|
1338
1501
|
*/
|
|
1339
|
-
dimensions:
|
|
1502
|
+
dimensions: import_v48.z.number().optional(),
|
|
1340
1503
|
/**
|
|
1341
1504
|
A unique identifier representing your end-user, which can help OpenAI to
|
|
1342
1505
|
monitor and detect abuse. Learn more.
|
|
1343
1506
|
*/
|
|
1344
|
-
user:
|
|
1507
|
+
user: import_v48.z.string().optional()
|
|
1345
1508
|
});
|
|
1346
1509
|
|
|
1347
1510
|
// src/openai-embedding-model.ts
|
|
@@ -1371,7 +1534,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1371
1534
|
values
|
|
1372
1535
|
});
|
|
1373
1536
|
}
|
|
1374
|
-
const openaiOptions = (_a = await (0,
|
|
1537
|
+
const openaiOptions = (_a = await (0, import_provider_utils7.parseProviderOptions)({
|
|
1375
1538
|
provider: "openai",
|
|
1376
1539
|
providerOptions,
|
|
1377
1540
|
schema: openaiEmbeddingProviderOptions
|
|
@@ -1380,12 +1543,12 @@ var OpenAIEmbeddingModel = class {
|
|
|
1380
1543
|
responseHeaders,
|
|
1381
1544
|
value: response,
|
|
1382
1545
|
rawValue
|
|
1383
|
-
} = await (0,
|
|
1546
|
+
} = await (0, import_provider_utils7.postJsonToApi)({
|
|
1384
1547
|
url: this.config.url({
|
|
1385
1548
|
path: "/embeddings",
|
|
1386
1549
|
modelId: this.modelId
|
|
1387
1550
|
}),
|
|
1388
|
-
headers: (0,
|
|
1551
|
+
headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), headers),
|
|
1389
1552
|
body: {
|
|
1390
1553
|
model: this.modelId,
|
|
1391
1554
|
input: values,
|
|
@@ -1394,7 +1557,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1394
1557
|
user: openaiOptions.user
|
|
1395
1558
|
},
|
|
1396
1559
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1397
|
-
successfulResponseHandler: (0,
|
|
1560
|
+
successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
|
|
1398
1561
|
openaiTextEmbeddingResponseSchema
|
|
1399
1562
|
),
|
|
1400
1563
|
abortSignal,
|
|
@@ -1407,14 +1570,14 @@ var OpenAIEmbeddingModel = class {
|
|
|
1407
1570
|
};
|
|
1408
1571
|
}
|
|
1409
1572
|
};
|
|
1410
|
-
var openaiTextEmbeddingResponseSchema =
|
|
1411
|
-
data:
|
|
1412
|
-
usage:
|
|
1573
|
+
var openaiTextEmbeddingResponseSchema = import_v49.z.object({
|
|
1574
|
+
data: import_v49.z.array(import_v49.z.object({ embedding: import_v49.z.array(import_v49.z.number()) })),
|
|
1575
|
+
usage: import_v49.z.object({ prompt_tokens: import_v49.z.number() }).nullish()
|
|
1413
1576
|
});
|
|
1414
1577
|
|
|
1415
1578
|
// src/openai-image-model.ts
|
|
1416
|
-
var
|
|
1417
|
-
var
|
|
1579
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1580
|
+
var import_v410 = require("zod/v4");
|
|
1418
1581
|
|
|
1419
1582
|
// src/openai-image-settings.ts
|
|
1420
1583
|
var modelMaxImagesPerCall = {
|
|
@@ -1461,12 +1624,12 @@ var OpenAIImageModel = class {
|
|
|
1461
1624
|
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
1462
1625
|
}
|
|
1463
1626
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1464
|
-
const { value: response, responseHeaders } = await (0,
|
|
1627
|
+
const { value: response, responseHeaders } = await (0, import_provider_utils8.postJsonToApi)({
|
|
1465
1628
|
url: this.config.url({
|
|
1466
1629
|
path: "/images/generations",
|
|
1467
1630
|
modelId: this.modelId
|
|
1468
1631
|
}),
|
|
1469
|
-
headers: (0,
|
|
1632
|
+
headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), headers),
|
|
1470
1633
|
body: {
|
|
1471
1634
|
model: this.modelId,
|
|
1472
1635
|
prompt,
|
|
@@ -1476,7 +1639,7 @@ var OpenAIImageModel = class {
|
|
|
1476
1639
|
...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
|
|
1477
1640
|
},
|
|
1478
1641
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1479
|
-
successfulResponseHandler: (0,
|
|
1642
|
+
successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
|
|
1480
1643
|
openaiImageResponseSchema
|
|
1481
1644
|
),
|
|
1482
1645
|
abortSignal,
|
|
@@ -1502,62 +1665,47 @@ var OpenAIImageModel = class {
|
|
|
1502
1665
|
};
|
|
1503
1666
|
}
|
|
1504
1667
|
};
|
|
1505
|
-
var openaiImageResponseSchema =
|
|
1506
|
-
data:
|
|
1507
|
-
|
|
1668
|
+
var openaiImageResponseSchema = import_v410.z.object({
|
|
1669
|
+
data: import_v410.z.array(
|
|
1670
|
+
import_v410.z.object({ b64_json: import_v410.z.string(), revised_prompt: import_v410.z.string().optional() })
|
|
1508
1671
|
)
|
|
1509
1672
|
});
|
|
1510
1673
|
|
|
1511
1674
|
// src/openai-tools.ts
|
|
1512
|
-
var import_zod9 = require("zod");
|
|
1513
|
-
var WebSearchPreviewParameters = import_zod9.z.object({});
|
|
1514
|
-
function webSearchPreviewTool({
|
|
1515
|
-
searchContextSize,
|
|
1516
|
-
userLocation
|
|
1517
|
-
} = {}) {
|
|
1518
|
-
return {
|
|
1519
|
-
type: "provider-defined",
|
|
1520
|
-
id: "openai.web_search_preview",
|
|
1521
|
-
args: {
|
|
1522
|
-
searchContextSize,
|
|
1523
|
-
userLocation
|
|
1524
|
-
},
|
|
1525
|
-
parameters: WebSearchPreviewParameters
|
|
1526
|
-
};
|
|
1527
|
-
}
|
|
1528
1675
|
var openaiTools = {
|
|
1529
|
-
|
|
1676
|
+
fileSearch,
|
|
1677
|
+
webSearchPreview
|
|
1530
1678
|
};
|
|
1531
1679
|
|
|
1532
1680
|
// src/openai-transcription-model.ts
|
|
1533
|
-
var
|
|
1534
|
-
var
|
|
1681
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1682
|
+
var import_v412 = require("zod/v4");
|
|
1535
1683
|
|
|
1536
1684
|
// src/openai-transcription-options.ts
|
|
1537
|
-
var
|
|
1538
|
-
var openAITranscriptionProviderOptions =
|
|
1685
|
+
var import_v411 = require("zod/v4");
|
|
1686
|
+
var openAITranscriptionProviderOptions = import_v411.z.object({
|
|
1539
1687
|
/**
|
|
1540
1688
|
* Additional information to include in the transcription response.
|
|
1541
1689
|
*/
|
|
1542
|
-
include:
|
|
1690
|
+
include: import_v411.z.array(import_v411.z.string()).optional(),
|
|
1543
1691
|
/**
|
|
1544
1692
|
* The language of the input audio in ISO-639-1 format.
|
|
1545
1693
|
*/
|
|
1546
|
-
language:
|
|
1694
|
+
language: import_v411.z.string().optional(),
|
|
1547
1695
|
/**
|
|
1548
1696
|
* An optional text to guide the model's style or continue a previous audio segment.
|
|
1549
1697
|
*/
|
|
1550
|
-
prompt:
|
|
1698
|
+
prompt: import_v411.z.string().optional(),
|
|
1551
1699
|
/**
|
|
1552
1700
|
* The sampling temperature, between 0 and 1.
|
|
1553
1701
|
* @default 0
|
|
1554
1702
|
*/
|
|
1555
|
-
temperature:
|
|
1703
|
+
temperature: import_v411.z.number().min(0).max(1).default(0).optional(),
|
|
1556
1704
|
/**
|
|
1557
1705
|
* The timestamp granularities to populate for this transcription.
|
|
1558
1706
|
* @default ['segment']
|
|
1559
1707
|
*/
|
|
1560
|
-
timestampGranularities:
|
|
1708
|
+
timestampGranularities: import_v411.z.array(import_v411.z.enum(["word", "segment"])).default(["segment"]).optional()
|
|
1561
1709
|
});
|
|
1562
1710
|
|
|
1563
1711
|
// src/openai-transcription-model.ts
|
|
@@ -1624,7 +1772,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1624
1772
|
constructor(modelId, config) {
|
|
1625
1773
|
this.modelId = modelId;
|
|
1626
1774
|
this.config = config;
|
|
1627
|
-
this.specificationVersion = "
|
|
1775
|
+
this.specificationVersion = "v2";
|
|
1628
1776
|
}
|
|
1629
1777
|
get provider() {
|
|
1630
1778
|
return this.config.provider;
|
|
@@ -1635,13 +1783,13 @@ var OpenAITranscriptionModel = class {
|
|
|
1635
1783
|
providerOptions
|
|
1636
1784
|
}) {
|
|
1637
1785
|
const warnings = [];
|
|
1638
|
-
const openAIOptions = await (0,
|
|
1786
|
+
const openAIOptions = await (0, import_provider_utils9.parseProviderOptions)({
|
|
1639
1787
|
provider: "openai",
|
|
1640
1788
|
providerOptions,
|
|
1641
1789
|
schema: openAITranscriptionProviderOptions
|
|
1642
1790
|
});
|
|
1643
1791
|
const formData = new FormData();
|
|
1644
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0,
|
|
1792
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils9.convertBase64ToUint8Array)(audio)]);
|
|
1645
1793
|
formData.append("model", this.modelId);
|
|
1646
1794
|
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1647
1795
|
if (openAIOptions) {
|
|
@@ -1671,15 +1819,15 @@ var OpenAITranscriptionModel = class {
|
|
|
1671
1819
|
value: response,
|
|
1672
1820
|
responseHeaders,
|
|
1673
1821
|
rawValue: rawResponse
|
|
1674
|
-
} = await (0,
|
|
1822
|
+
} = await (0, import_provider_utils9.postFormDataToApi)({
|
|
1675
1823
|
url: this.config.url({
|
|
1676
1824
|
path: "/audio/transcriptions",
|
|
1677
1825
|
modelId: this.modelId
|
|
1678
1826
|
}),
|
|
1679
|
-
headers: (0,
|
|
1827
|
+
headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
|
|
1680
1828
|
formData,
|
|
1681
1829
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1682
|
-
successfulResponseHandler: (0,
|
|
1830
|
+
successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
|
|
1683
1831
|
openaiTranscriptionResponseSchema
|
|
1684
1832
|
),
|
|
1685
1833
|
abortSignal: options.abortSignal,
|
|
@@ -1705,29 +1853,33 @@ var OpenAITranscriptionModel = class {
|
|
|
1705
1853
|
};
|
|
1706
1854
|
}
|
|
1707
1855
|
};
|
|
1708
|
-
var openaiTranscriptionResponseSchema =
|
|
1709
|
-
text:
|
|
1710
|
-
language:
|
|
1711
|
-
duration:
|
|
1712
|
-
words:
|
|
1713
|
-
|
|
1714
|
-
word:
|
|
1715
|
-
start:
|
|
1716
|
-
end:
|
|
1856
|
+
var openaiTranscriptionResponseSchema = import_v412.z.object({
|
|
1857
|
+
text: import_v412.z.string(),
|
|
1858
|
+
language: import_v412.z.string().nullish(),
|
|
1859
|
+
duration: import_v412.z.number().nullish(),
|
|
1860
|
+
words: import_v412.z.array(
|
|
1861
|
+
import_v412.z.object({
|
|
1862
|
+
word: import_v412.z.string(),
|
|
1863
|
+
start: import_v412.z.number(),
|
|
1864
|
+
end: import_v412.z.number()
|
|
1717
1865
|
})
|
|
1718
1866
|
).nullish()
|
|
1719
1867
|
});
|
|
1720
1868
|
|
|
1721
1869
|
// src/responses/openai-responses-language-model.ts
|
|
1722
|
-
var
|
|
1723
|
-
var
|
|
1870
|
+
var import_provider8 = require("@ai-sdk/provider");
|
|
1871
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
1872
|
+
var import_v414 = require("zod/v4");
|
|
1724
1873
|
|
|
1725
1874
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1726
1875
|
var import_provider6 = require("@ai-sdk/provider");
|
|
1727
|
-
|
|
1876
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
1877
|
+
var import_v413 = require("zod/v4");
|
|
1878
|
+
async function convertToOpenAIResponsesMessages({
|
|
1728
1879
|
prompt,
|
|
1729
1880
|
systemMessageMode
|
|
1730
1881
|
}) {
|
|
1882
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1731
1883
|
const messages = [];
|
|
1732
1884
|
const warnings = [];
|
|
1733
1885
|
for (const { role, content } of prompt) {
|
|
@@ -1762,7 +1914,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1762
1914
|
messages.push({
|
|
1763
1915
|
role: "user",
|
|
1764
1916
|
content: content.map((part, index) => {
|
|
1765
|
-
var
|
|
1917
|
+
var _a2, _b2, _c2;
|
|
1766
1918
|
switch (part.type) {
|
|
1767
1919
|
case "text": {
|
|
1768
1920
|
return { type: "input_text", text: part.text };
|
|
@@ -1774,7 +1926,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1774
1926
|
type: "input_image",
|
|
1775
1927
|
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
1776
1928
|
// OpenAI specific extension: image detail
|
|
1777
|
-
detail: (
|
|
1929
|
+
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
|
|
1778
1930
|
};
|
|
1779
1931
|
} else if (part.mediaType === "application/pdf") {
|
|
1780
1932
|
if (part.data instanceof URL) {
|
|
@@ -1784,7 +1936,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1784
1936
|
}
|
|
1785
1937
|
return {
|
|
1786
1938
|
type: "input_file",
|
|
1787
|
-
filename: (
|
|
1939
|
+
filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
|
|
1788
1940
|
file_data: `data:application/pdf;base64,${part.data}`
|
|
1789
1941
|
};
|
|
1790
1942
|
} else {
|
|
@@ -1799,34 +1951,97 @@ function convertToOpenAIResponsesMessages({
|
|
|
1799
1951
|
break;
|
|
1800
1952
|
}
|
|
1801
1953
|
case "assistant": {
|
|
1954
|
+
const reasoningMessages = {};
|
|
1802
1955
|
for (const part of content) {
|
|
1803
1956
|
switch (part.type) {
|
|
1804
1957
|
case "text": {
|
|
1805
1958
|
messages.push({
|
|
1806
1959
|
role: "assistant",
|
|
1807
|
-
content: [{ type: "output_text", text: part.text }]
|
|
1960
|
+
content: [{ type: "output_text", text: part.text }],
|
|
1961
|
+
id: (_c = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId) != null ? _c : void 0
|
|
1808
1962
|
});
|
|
1809
1963
|
break;
|
|
1810
1964
|
}
|
|
1811
1965
|
case "tool-call": {
|
|
1966
|
+
if (part.providerExecuted) {
|
|
1967
|
+
break;
|
|
1968
|
+
}
|
|
1812
1969
|
messages.push({
|
|
1813
1970
|
type: "function_call",
|
|
1814
1971
|
call_id: part.toolCallId,
|
|
1815
1972
|
name: part.toolName,
|
|
1816
|
-
arguments: JSON.stringify(part.
|
|
1973
|
+
arguments: JSON.stringify(part.input),
|
|
1974
|
+
id: (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.openai) == null ? void 0 : _e.itemId) != null ? _f : void 0
|
|
1817
1975
|
});
|
|
1818
1976
|
break;
|
|
1819
1977
|
}
|
|
1978
|
+
case "tool-result": {
|
|
1979
|
+
warnings.push({
|
|
1980
|
+
type: "other",
|
|
1981
|
+
message: `tool result parts in assistant messages are not supported for OpenAI responses`
|
|
1982
|
+
});
|
|
1983
|
+
break;
|
|
1984
|
+
}
|
|
1985
|
+
case "reasoning": {
|
|
1986
|
+
const providerOptions = await (0, import_provider_utils10.parseProviderOptions)({
|
|
1987
|
+
provider: "openai",
|
|
1988
|
+
providerOptions: part.providerOptions,
|
|
1989
|
+
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
1990
|
+
});
|
|
1991
|
+
const reasoningId = providerOptions == null ? void 0 : providerOptions.itemId;
|
|
1992
|
+
if (reasoningId != null) {
|
|
1993
|
+
const existingReasoningMessage = reasoningMessages[reasoningId];
|
|
1994
|
+
const summaryParts = [];
|
|
1995
|
+
if (part.text.length > 0) {
|
|
1996
|
+
summaryParts.push({ type: "summary_text", text: part.text });
|
|
1997
|
+
} else if (existingReasoningMessage !== void 0) {
|
|
1998
|
+
warnings.push({
|
|
1999
|
+
type: "other",
|
|
2000
|
+
message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
if (existingReasoningMessage === void 0) {
|
|
2004
|
+
reasoningMessages[reasoningId] = {
|
|
2005
|
+
type: "reasoning",
|
|
2006
|
+
id: reasoningId,
|
|
2007
|
+
encrypted_content: providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent,
|
|
2008
|
+
summary: summaryParts
|
|
2009
|
+
};
|
|
2010
|
+
messages.push(reasoningMessages[reasoningId]);
|
|
2011
|
+
} else {
|
|
2012
|
+
existingReasoningMessage.summary.push(...summaryParts);
|
|
2013
|
+
}
|
|
2014
|
+
} else {
|
|
2015
|
+
warnings.push({
|
|
2016
|
+
type: "other",
|
|
2017
|
+
message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
2018
|
+
});
|
|
2019
|
+
}
|
|
2020
|
+
break;
|
|
2021
|
+
}
|
|
1820
2022
|
}
|
|
1821
2023
|
}
|
|
1822
2024
|
break;
|
|
1823
2025
|
}
|
|
1824
2026
|
case "tool": {
|
|
1825
2027
|
for (const part of content) {
|
|
2028
|
+
const output = part.output;
|
|
2029
|
+
let contentValue;
|
|
2030
|
+
switch (output.type) {
|
|
2031
|
+
case "text":
|
|
2032
|
+
case "error-text":
|
|
2033
|
+
contentValue = output.value;
|
|
2034
|
+
break;
|
|
2035
|
+
case "content":
|
|
2036
|
+
case "json":
|
|
2037
|
+
case "error-json":
|
|
2038
|
+
contentValue = JSON.stringify(output.value);
|
|
2039
|
+
break;
|
|
2040
|
+
}
|
|
1826
2041
|
messages.push({
|
|
1827
2042
|
type: "function_call_output",
|
|
1828
2043
|
call_id: part.toolCallId,
|
|
1829
|
-
output:
|
|
2044
|
+
output: contentValue
|
|
1830
2045
|
});
|
|
1831
2046
|
}
|
|
1832
2047
|
break;
|
|
@@ -1839,6 +2054,10 @@ function convertToOpenAIResponsesMessages({
|
|
|
1839
2054
|
}
|
|
1840
2055
|
return { messages, warnings };
|
|
1841
2056
|
}
|
|
2057
|
+
var openaiResponsesReasoningProviderOptionsSchema = import_v413.z.object({
|
|
2058
|
+
itemId: import_v413.z.string().nullish(),
|
|
2059
|
+
reasoningEncryptedContent: import_v413.z.string().nullish()
|
|
2060
|
+
});
|
|
1842
2061
|
|
|
1843
2062
|
// src/responses/map-openai-responses-finish-reason.ts
|
|
1844
2063
|
function mapOpenAIResponseFinishReason({
|
|
@@ -1863,7 +2082,7 @@ var import_provider7 = require("@ai-sdk/provider");
|
|
|
1863
2082
|
function prepareResponsesTools({
|
|
1864
2083
|
tools,
|
|
1865
2084
|
toolChoice,
|
|
1866
|
-
|
|
2085
|
+
strictJsonSchema
|
|
1867
2086
|
}) {
|
|
1868
2087
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1869
2088
|
const toolWarnings = [];
|
|
@@ -1878,12 +2097,22 @@ function prepareResponsesTools({
|
|
|
1878
2097
|
type: "function",
|
|
1879
2098
|
name: tool.name,
|
|
1880
2099
|
description: tool.description,
|
|
1881
|
-
parameters: tool.
|
|
1882
|
-
strict:
|
|
2100
|
+
parameters: tool.inputSchema,
|
|
2101
|
+
strict: strictJsonSchema
|
|
1883
2102
|
});
|
|
1884
2103
|
break;
|
|
1885
2104
|
case "provider-defined":
|
|
1886
2105
|
switch (tool.id) {
|
|
2106
|
+
case "openai.file_search": {
|
|
2107
|
+
const args = fileSearchArgsSchema.parse(tool.args);
|
|
2108
|
+
openaiTools2.push({
|
|
2109
|
+
type: "file_search",
|
|
2110
|
+
vector_store_ids: args.vectorStoreIds,
|
|
2111
|
+
max_results: args.maxResults,
|
|
2112
|
+
search_type: args.searchType
|
|
2113
|
+
});
|
|
2114
|
+
break;
|
|
2115
|
+
}
|
|
1887
2116
|
case "openai.web_search_preview":
|
|
1888
2117
|
openaiTools2.push({
|
|
1889
2118
|
type: "web_search_preview",
|
|
@@ -1913,7 +2142,7 @@ function prepareResponsesTools({
|
|
|
1913
2142
|
case "tool":
|
|
1914
2143
|
return {
|
|
1915
2144
|
tools: openaiTools2,
|
|
1916
|
-
toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
2145
|
+
toolChoice: toolChoice.toolName === "file_search" ? { type: "file_search" } : toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
1917
2146
|
toolWarnings
|
|
1918
2147
|
};
|
|
1919
2148
|
default: {
|
|
@@ -1977,17 +2206,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1977
2206
|
if (stopSequences != null) {
|
|
1978
2207
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
1979
2208
|
}
|
|
1980
|
-
const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
|
|
2209
|
+
const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
|
|
1981
2210
|
prompt,
|
|
1982
2211
|
systemMessageMode: modelConfig.systemMessageMode
|
|
1983
2212
|
});
|
|
1984
2213
|
warnings.push(...messageWarnings);
|
|
1985
|
-
const openaiOptions = await (0,
|
|
2214
|
+
const openaiOptions = await (0, import_provider_utils11.parseProviderOptions)({
|
|
1986
2215
|
provider: "openai",
|
|
1987
2216
|
providerOptions,
|
|
1988
2217
|
schema: openaiResponsesProviderOptionsSchema
|
|
1989
2218
|
});
|
|
1990
|
-
const
|
|
2219
|
+
const strictJsonSchema = (_a = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _a : false;
|
|
1991
2220
|
const baseArgs = {
|
|
1992
2221
|
model: this.modelId,
|
|
1993
2222
|
input: messages,
|
|
@@ -1998,7 +2227,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1998
2227
|
text: {
|
|
1999
2228
|
format: responseFormat.schema != null ? {
|
|
2000
2229
|
type: "json_schema",
|
|
2001
|
-
strict:
|
|
2230
|
+
strict: strictJsonSchema,
|
|
2002
2231
|
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
2003
2232
|
description: responseFormat.description,
|
|
2004
2233
|
schema: responseFormat.schema
|
|
@@ -2012,6 +2241,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2012
2241
|
store: openaiOptions == null ? void 0 : openaiOptions.store,
|
|
2013
2242
|
user: openaiOptions == null ? void 0 : openaiOptions.user,
|
|
2014
2243
|
instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
|
|
2244
|
+
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
2245
|
+
include: openaiOptions == null ? void 0 : openaiOptions.include,
|
|
2015
2246
|
// model-specific settings:
|
|
2016
2247
|
...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
2017
2248
|
reasoning: {
|
|
@@ -2044,6 +2275,29 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2044
2275
|
details: "topP is not supported for reasoning models"
|
|
2045
2276
|
});
|
|
2046
2277
|
}
|
|
2278
|
+
} else {
|
|
2279
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
|
|
2280
|
+
warnings.push({
|
|
2281
|
+
type: "unsupported-setting",
|
|
2282
|
+
setting: "reasoningEffort",
|
|
2283
|
+
details: "reasoningEffort is not supported for non-reasoning models"
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) {
|
|
2287
|
+
warnings.push({
|
|
2288
|
+
type: "unsupported-setting",
|
|
2289
|
+
setting: "reasoningSummary",
|
|
2290
|
+
details: "reasoningSummary is not supported for non-reasoning models"
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
|
|
2295
|
+
warnings.push({
|
|
2296
|
+
type: "unsupported-setting",
|
|
2297
|
+
setting: "serviceTier",
|
|
2298
|
+
details: "flex processing is only available for o3 and o4-mini models"
|
|
2299
|
+
});
|
|
2300
|
+
delete baseArgs.service_tier;
|
|
2047
2301
|
}
|
|
2048
2302
|
const {
|
|
2049
2303
|
tools: openaiTools2,
|
|
@@ -2052,7 +2306,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2052
2306
|
} = prepareResponsesTools({
|
|
2053
2307
|
tools,
|
|
2054
2308
|
toolChoice,
|
|
2055
|
-
|
|
2309
|
+
strictJsonSchema
|
|
2056
2310
|
});
|
|
2057
2311
|
return {
|
|
2058
2312
|
args: {
|
|
@@ -2064,97 +2318,137 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2064
2318
|
};
|
|
2065
2319
|
}
|
|
2066
2320
|
async doGenerate(options) {
|
|
2067
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2321
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2068
2322
|
const { args: body, warnings } = await this.getArgs(options);
|
|
2323
|
+
const url = this.config.url({
|
|
2324
|
+
path: "/responses",
|
|
2325
|
+
modelId: this.modelId
|
|
2326
|
+
});
|
|
2069
2327
|
const {
|
|
2070
2328
|
responseHeaders,
|
|
2071
2329
|
value: response,
|
|
2072
2330
|
rawValue: rawResponse
|
|
2073
|
-
} = await (0,
|
|
2074
|
-
url
|
|
2075
|
-
|
|
2076
|
-
modelId: this.modelId
|
|
2077
|
-
}),
|
|
2078
|
-
headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
|
|
2331
|
+
} = await (0, import_provider_utils11.postJsonToApi)({
|
|
2332
|
+
url,
|
|
2333
|
+
headers: (0, import_provider_utils11.combineHeaders)(this.config.headers(), options.headers),
|
|
2079
2334
|
body,
|
|
2080
2335
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2081
|
-
successfulResponseHandler: (0,
|
|
2082
|
-
|
|
2083
|
-
id:
|
|
2084
|
-
created_at:
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2336
|
+
successfulResponseHandler: (0, import_provider_utils11.createJsonResponseHandler)(
|
|
2337
|
+
import_v414.z.object({
|
|
2338
|
+
id: import_v414.z.string(),
|
|
2339
|
+
created_at: import_v414.z.number(),
|
|
2340
|
+
error: import_v414.z.object({
|
|
2341
|
+
code: import_v414.z.string(),
|
|
2342
|
+
message: import_v414.z.string()
|
|
2343
|
+
}).nullish(),
|
|
2344
|
+
model: import_v414.z.string(),
|
|
2345
|
+
output: import_v414.z.array(
|
|
2346
|
+
import_v414.z.discriminatedUnion("type", [
|
|
2347
|
+
import_v414.z.object({
|
|
2348
|
+
type: import_v414.z.literal("message"),
|
|
2349
|
+
role: import_v414.z.literal("assistant"),
|
|
2350
|
+
id: import_v414.z.string(),
|
|
2351
|
+
content: import_v414.z.array(
|
|
2352
|
+
import_v414.z.object({
|
|
2353
|
+
type: import_v414.z.literal("output_text"),
|
|
2354
|
+
text: import_v414.z.string(),
|
|
2355
|
+
annotations: import_v414.z.array(
|
|
2356
|
+
import_v414.z.object({
|
|
2357
|
+
type: import_v414.z.literal("url_citation"),
|
|
2358
|
+
start_index: import_v414.z.number(),
|
|
2359
|
+
end_index: import_v414.z.number(),
|
|
2360
|
+
url: import_v414.z.string(),
|
|
2361
|
+
title: import_v414.z.string()
|
|
2102
2362
|
})
|
|
2103
2363
|
)
|
|
2104
2364
|
})
|
|
2105
2365
|
)
|
|
2106
2366
|
}),
|
|
2107
|
-
|
|
2108
|
-
type:
|
|
2109
|
-
call_id:
|
|
2110
|
-
name:
|
|
2111
|
-
arguments:
|
|
2367
|
+
import_v414.z.object({
|
|
2368
|
+
type: import_v414.z.literal("function_call"),
|
|
2369
|
+
call_id: import_v414.z.string(),
|
|
2370
|
+
name: import_v414.z.string(),
|
|
2371
|
+
arguments: import_v414.z.string(),
|
|
2372
|
+
id: import_v414.z.string()
|
|
2112
2373
|
}),
|
|
2113
|
-
|
|
2114
|
-
type:
|
|
2374
|
+
import_v414.z.object({
|
|
2375
|
+
type: import_v414.z.literal("web_search_call"),
|
|
2376
|
+
id: import_v414.z.string(),
|
|
2377
|
+
status: import_v414.z.string().optional()
|
|
2115
2378
|
}),
|
|
2116
|
-
|
|
2117
|
-
type:
|
|
2379
|
+
import_v414.z.object({
|
|
2380
|
+
type: import_v414.z.literal("computer_call"),
|
|
2381
|
+
id: import_v414.z.string(),
|
|
2382
|
+
status: import_v414.z.string().optional()
|
|
2118
2383
|
}),
|
|
2119
|
-
|
|
2120
|
-
type:
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2384
|
+
import_v414.z.object({
|
|
2385
|
+
type: import_v414.z.literal("reasoning"),
|
|
2386
|
+
id: import_v414.z.string(),
|
|
2387
|
+
encrypted_content: import_v414.z.string().nullish(),
|
|
2388
|
+
summary: import_v414.z.array(
|
|
2389
|
+
import_v414.z.object({
|
|
2390
|
+
type: import_v414.z.literal("summary_text"),
|
|
2391
|
+
text: import_v414.z.string()
|
|
2125
2392
|
})
|
|
2126
2393
|
)
|
|
2127
2394
|
})
|
|
2128
2395
|
])
|
|
2129
2396
|
),
|
|
2130
|
-
incomplete_details:
|
|
2397
|
+
incomplete_details: import_v414.z.object({ reason: import_v414.z.string() }).nullable(),
|
|
2131
2398
|
usage: usageSchema2
|
|
2132
2399
|
})
|
|
2133
2400
|
),
|
|
2134
2401
|
abortSignal: options.abortSignal,
|
|
2135
2402
|
fetch: this.config.fetch
|
|
2136
2403
|
});
|
|
2404
|
+
if (response.error) {
|
|
2405
|
+
throw new import_provider8.APICallError({
|
|
2406
|
+
message: response.error.message,
|
|
2407
|
+
url,
|
|
2408
|
+
requestBodyValues: body,
|
|
2409
|
+
statusCode: 400,
|
|
2410
|
+
responseHeaders,
|
|
2411
|
+
responseBody: rawResponse,
|
|
2412
|
+
isRetryable: false
|
|
2413
|
+
});
|
|
2414
|
+
}
|
|
2137
2415
|
const content = [];
|
|
2138
2416
|
for (const part of response.output) {
|
|
2139
2417
|
switch (part.type) {
|
|
2140
2418
|
case "reasoning": {
|
|
2141
|
-
|
|
2142
|
-
type: "
|
|
2143
|
-
|
|
2144
|
-
|
|
2419
|
+
if (part.summary.length === 0) {
|
|
2420
|
+
part.summary.push({ type: "summary_text", text: "" });
|
|
2421
|
+
}
|
|
2422
|
+
for (const summary of part.summary) {
|
|
2423
|
+
content.push({
|
|
2424
|
+
type: "reasoning",
|
|
2425
|
+
text: summary.text,
|
|
2426
|
+
providerMetadata: {
|
|
2427
|
+
openai: {
|
|
2428
|
+
itemId: part.id,
|
|
2429
|
+
reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2145
2434
|
break;
|
|
2146
2435
|
}
|
|
2147
2436
|
case "message": {
|
|
2148
2437
|
for (const contentPart of part.content) {
|
|
2149
2438
|
content.push({
|
|
2150
2439
|
type: "text",
|
|
2151
|
-
text: contentPart.text
|
|
2440
|
+
text: contentPart.text,
|
|
2441
|
+
providerMetadata: {
|
|
2442
|
+
openai: {
|
|
2443
|
+
itemId: part.id
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2152
2446
|
});
|
|
2153
2447
|
for (const annotation of contentPart.annotations) {
|
|
2154
2448
|
content.push({
|
|
2155
2449
|
type: "source",
|
|
2156
2450
|
sourceType: "url",
|
|
2157
|
-
id: (
|
|
2451
|
+
id: (_d = (_c = (_b = this.config).generateId) == null ? void 0 : _c.call(_b)) != null ? _d : (0, import_provider_utils11.generateId)(),
|
|
2158
2452
|
url: annotation.url,
|
|
2159
2453
|
title: annotation.title
|
|
2160
2454
|
});
|
|
@@ -2165,10 +2459,51 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2165
2459
|
case "function_call": {
|
|
2166
2460
|
content.push({
|
|
2167
2461
|
type: "tool-call",
|
|
2168
|
-
toolCallType: "function",
|
|
2169
2462
|
toolCallId: part.call_id,
|
|
2170
2463
|
toolName: part.name,
|
|
2171
|
-
|
|
2464
|
+
input: part.arguments,
|
|
2465
|
+
providerMetadata: {
|
|
2466
|
+
openai: {
|
|
2467
|
+
itemId: part.id
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
});
|
|
2471
|
+
break;
|
|
2472
|
+
}
|
|
2473
|
+
case "web_search_call": {
|
|
2474
|
+
content.push({
|
|
2475
|
+
type: "tool-call",
|
|
2476
|
+
toolCallId: part.id,
|
|
2477
|
+
toolName: "web_search_preview",
|
|
2478
|
+
input: "",
|
|
2479
|
+
providerExecuted: true
|
|
2480
|
+
});
|
|
2481
|
+
content.push({
|
|
2482
|
+
type: "tool-result",
|
|
2483
|
+
toolCallId: part.id,
|
|
2484
|
+
toolName: "web_search_preview",
|
|
2485
|
+
result: { status: part.status || "completed" },
|
|
2486
|
+
providerExecuted: true
|
|
2487
|
+
});
|
|
2488
|
+
break;
|
|
2489
|
+
}
|
|
2490
|
+
case "computer_call": {
|
|
2491
|
+
content.push({
|
|
2492
|
+
type: "tool-call",
|
|
2493
|
+
toolCallId: part.id,
|
|
2494
|
+
toolName: "computer_use",
|
|
2495
|
+
input: "",
|
|
2496
|
+
providerExecuted: true
|
|
2497
|
+
});
|
|
2498
|
+
content.push({
|
|
2499
|
+
type: "tool-result",
|
|
2500
|
+
toolCallId: part.id,
|
|
2501
|
+
toolName: "computer_use",
|
|
2502
|
+
result: {
|
|
2503
|
+
type: "computer_use_tool_result",
|
|
2504
|
+
status: part.status || "completed"
|
|
2505
|
+
},
|
|
2506
|
+
providerExecuted: true
|
|
2172
2507
|
});
|
|
2173
2508
|
break;
|
|
2174
2509
|
}
|
|
@@ -2177,15 +2512,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2177
2512
|
return {
|
|
2178
2513
|
content,
|
|
2179
2514
|
finishReason: mapOpenAIResponseFinishReason({
|
|
2180
|
-
finishReason: (
|
|
2515
|
+
finishReason: (_e = response.incomplete_details) == null ? void 0 : _e.reason,
|
|
2181
2516
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
2182
2517
|
}),
|
|
2183
2518
|
usage: {
|
|
2184
2519
|
inputTokens: response.usage.input_tokens,
|
|
2185
2520
|
outputTokens: response.usage.output_tokens,
|
|
2186
2521
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
2187
|
-
reasoningTokens: (
|
|
2188
|
-
cachedInputTokens: (
|
|
2522
|
+
reasoningTokens: (_g = (_f = response.usage.output_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0,
|
|
2523
|
+
cachedInputTokens: (_i = (_h = response.usage.input_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : void 0
|
|
2189
2524
|
},
|
|
2190
2525
|
request: { body },
|
|
2191
2526
|
response: {
|
|
@@ -2205,18 +2540,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2205
2540
|
}
|
|
2206
2541
|
async doStream(options) {
|
|
2207
2542
|
const { args: body, warnings } = await this.getArgs(options);
|
|
2208
|
-
const { responseHeaders, value: response } = await (0,
|
|
2543
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({
|
|
2209
2544
|
url: this.config.url({
|
|
2210
2545
|
path: "/responses",
|
|
2211
2546
|
modelId: this.modelId
|
|
2212
2547
|
}),
|
|
2213
|
-
headers: (0,
|
|
2548
|
+
headers: (0, import_provider_utils11.combineHeaders)(this.config.headers(), options.headers),
|
|
2214
2549
|
body: {
|
|
2215
2550
|
...body,
|
|
2216
2551
|
stream: true
|
|
2217
2552
|
},
|
|
2218
2553
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2219
|
-
successfulResponseHandler: (0,
|
|
2554
|
+
successfulResponseHandler: (0, import_provider_utils11.createEventSourceResponseHandler)(
|
|
2220
2555
|
openaiResponsesChunkSchema
|
|
2221
2556
|
),
|
|
2222
2557
|
abortSignal: options.abortSignal,
|
|
@@ -2232,6 +2567,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2232
2567
|
let responseId = null;
|
|
2233
2568
|
const ongoingToolCalls = {};
|
|
2234
2569
|
let hasToolCalls = false;
|
|
2570
|
+
const activeReasoning = {};
|
|
2235
2571
|
return {
|
|
2236
2572
|
stream: response.pipeThrough(
|
|
2237
2573
|
new TransformStream({
|
|
@@ -2239,7 +2575,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2239
2575
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2240
2576
|
},
|
|
2241
2577
|
transform(chunk, controller) {
|
|
2242
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2578
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2579
|
+
if (options.includeRawChunks) {
|
|
2580
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2581
|
+
}
|
|
2243
2582
|
if (!chunk.success) {
|
|
2244
2583
|
finishReason = "error";
|
|
2245
2584
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2253,22 +2592,151 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2253
2592
|
toolCallId: value.item.call_id
|
|
2254
2593
|
};
|
|
2255
2594
|
controller.enqueue({
|
|
2256
|
-
type: "tool-
|
|
2257
|
-
|
|
2595
|
+
type: "tool-input-start",
|
|
2596
|
+
id: value.item.call_id,
|
|
2597
|
+
toolName: value.item.name
|
|
2598
|
+
});
|
|
2599
|
+
} else if (value.item.type === "web_search_call") {
|
|
2600
|
+
ongoingToolCalls[value.output_index] = {
|
|
2601
|
+
toolName: "web_search_preview",
|
|
2602
|
+
toolCallId: value.item.id
|
|
2603
|
+
};
|
|
2604
|
+
controller.enqueue({
|
|
2605
|
+
type: "tool-input-start",
|
|
2606
|
+
id: value.item.id,
|
|
2607
|
+
toolName: "web_search_preview"
|
|
2608
|
+
});
|
|
2609
|
+
} else if (value.item.type === "computer_call") {
|
|
2610
|
+
ongoingToolCalls[value.output_index] = {
|
|
2611
|
+
toolName: "computer_use",
|
|
2612
|
+
toolCallId: value.item.id
|
|
2613
|
+
};
|
|
2614
|
+
controller.enqueue({
|
|
2615
|
+
type: "tool-input-start",
|
|
2616
|
+
id: value.item.id,
|
|
2617
|
+
toolName: "computer_use"
|
|
2618
|
+
});
|
|
2619
|
+
} else if (value.item.type === "message") {
|
|
2620
|
+
controller.enqueue({
|
|
2621
|
+
type: "text-start",
|
|
2622
|
+
id: value.item.id,
|
|
2623
|
+
providerMetadata: {
|
|
2624
|
+
openai: {
|
|
2625
|
+
itemId: value.item.id
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
});
|
|
2629
|
+
} else if (isResponseOutputItemAddedReasoningChunk(value)) {
|
|
2630
|
+
activeReasoning[value.item.id] = {
|
|
2631
|
+
encryptedContent: value.item.encrypted_content,
|
|
2632
|
+
summaryParts: [0]
|
|
2633
|
+
};
|
|
2634
|
+
controller.enqueue({
|
|
2635
|
+
type: "reasoning-start",
|
|
2636
|
+
id: `${value.item.id}:0`,
|
|
2637
|
+
providerMetadata: {
|
|
2638
|
+
openai: {
|
|
2639
|
+
itemId: value.item.id,
|
|
2640
|
+
reasoningEncryptedContent: (_a = value.item.encrypted_content) != null ? _a : null
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
});
|
|
2644
|
+
}
|
|
2645
|
+
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
2646
|
+
if (value.item.type === "function_call") {
|
|
2647
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2648
|
+
hasToolCalls = true;
|
|
2649
|
+
controller.enqueue({
|
|
2650
|
+
type: "tool-input-end",
|
|
2651
|
+
id: value.item.call_id
|
|
2652
|
+
});
|
|
2653
|
+
controller.enqueue({
|
|
2654
|
+
type: "tool-call",
|
|
2258
2655
|
toolCallId: value.item.call_id,
|
|
2259
2656
|
toolName: value.item.name,
|
|
2260
|
-
|
|
2657
|
+
input: value.item.arguments,
|
|
2658
|
+
providerMetadata: {
|
|
2659
|
+
openai: {
|
|
2660
|
+
itemId: value.item.id
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
});
|
|
2664
|
+
} else if (value.item.type === "web_search_call") {
|
|
2665
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2666
|
+
hasToolCalls = true;
|
|
2667
|
+
controller.enqueue({
|
|
2668
|
+
type: "tool-input-end",
|
|
2669
|
+
id: value.item.id
|
|
2670
|
+
});
|
|
2671
|
+
controller.enqueue({
|
|
2672
|
+
type: "tool-call",
|
|
2673
|
+
toolCallId: value.item.id,
|
|
2674
|
+
toolName: "web_search_preview",
|
|
2675
|
+
input: "",
|
|
2676
|
+
providerExecuted: true
|
|
2677
|
+
});
|
|
2678
|
+
controller.enqueue({
|
|
2679
|
+
type: "tool-result",
|
|
2680
|
+
toolCallId: value.item.id,
|
|
2681
|
+
toolName: "web_search_preview",
|
|
2682
|
+
result: {
|
|
2683
|
+
type: "web_search_tool_result",
|
|
2684
|
+
status: value.item.status || "completed"
|
|
2685
|
+
},
|
|
2686
|
+
providerExecuted: true
|
|
2687
|
+
});
|
|
2688
|
+
} else if (value.item.type === "computer_call") {
|
|
2689
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2690
|
+
hasToolCalls = true;
|
|
2691
|
+
controller.enqueue({
|
|
2692
|
+
type: "tool-input-end",
|
|
2693
|
+
id: value.item.id
|
|
2694
|
+
});
|
|
2695
|
+
controller.enqueue({
|
|
2696
|
+
type: "tool-call",
|
|
2697
|
+
toolCallId: value.item.id,
|
|
2698
|
+
toolName: "computer_use",
|
|
2699
|
+
input: "",
|
|
2700
|
+
providerExecuted: true
|
|
2701
|
+
});
|
|
2702
|
+
controller.enqueue({
|
|
2703
|
+
type: "tool-result",
|
|
2704
|
+
toolCallId: value.item.id,
|
|
2705
|
+
toolName: "computer_use",
|
|
2706
|
+
result: {
|
|
2707
|
+
type: "computer_use_tool_result",
|
|
2708
|
+
status: value.item.status || "completed"
|
|
2709
|
+
},
|
|
2710
|
+
providerExecuted: true
|
|
2261
2711
|
});
|
|
2712
|
+
} else if (value.item.type === "message") {
|
|
2713
|
+
controller.enqueue({
|
|
2714
|
+
type: "text-end",
|
|
2715
|
+
id: value.item.id
|
|
2716
|
+
});
|
|
2717
|
+
} else if (isResponseOutputItemDoneReasoningChunk(value)) {
|
|
2718
|
+
const activeReasoningPart = activeReasoning[value.item.id];
|
|
2719
|
+
for (const summaryIndex of activeReasoningPart.summaryParts) {
|
|
2720
|
+
controller.enqueue({
|
|
2721
|
+
type: "reasoning-end",
|
|
2722
|
+
id: `${value.item.id}:${summaryIndex}`,
|
|
2723
|
+
providerMetadata: {
|
|
2724
|
+
openai: {
|
|
2725
|
+
itemId: value.item.id,
|
|
2726
|
+
reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
});
|
|
2730
|
+
}
|
|
2731
|
+
delete activeReasoning[value.item.id];
|
|
2262
2732
|
}
|
|
2263
2733
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
2264
2734
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
2265
2735
|
if (toolCall != null) {
|
|
2266
2736
|
controller.enqueue({
|
|
2267
|
-
type: "tool-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
toolName: toolCall.toolName,
|
|
2271
|
-
argsTextDelta: value.delta
|
|
2737
|
+
type: "tool-input-delta",
|
|
2738
|
+
id: toolCall.toolCallId,
|
|
2739
|
+
delta: value.delta
|
|
2272
2740
|
});
|
|
2273
2741
|
}
|
|
2274
2742
|
} else if (isResponseCreatedChunk(value)) {
|
|
@@ -2281,42 +2749,57 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2281
2749
|
});
|
|
2282
2750
|
} else if (isTextDeltaChunk(value)) {
|
|
2283
2751
|
controller.enqueue({
|
|
2284
|
-
type: "text",
|
|
2285
|
-
|
|
2752
|
+
type: "text-delta",
|
|
2753
|
+
id: value.item_id,
|
|
2754
|
+
delta: value.delta
|
|
2286
2755
|
});
|
|
2756
|
+
} else if (isResponseReasoningSummaryPartAddedChunk(value)) {
|
|
2757
|
+
if (value.summary_index > 0) {
|
|
2758
|
+
(_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
|
|
2759
|
+
value.summary_index
|
|
2760
|
+
);
|
|
2761
|
+
controller.enqueue({
|
|
2762
|
+
type: "reasoning-start",
|
|
2763
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2764
|
+
providerMetadata: {
|
|
2765
|
+
openai: {
|
|
2766
|
+
itemId: value.item_id,
|
|
2767
|
+
reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
});
|
|
2771
|
+
}
|
|
2287
2772
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2288
2773
|
controller.enqueue({
|
|
2289
|
-
type: "reasoning",
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
toolCallType: "function",
|
|
2298
|
-
toolCallId: value.item.call_id,
|
|
2299
|
-
toolName: value.item.name,
|
|
2300
|
-
args: value.item.arguments
|
|
2774
|
+
type: "reasoning-delta",
|
|
2775
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2776
|
+
delta: value.delta,
|
|
2777
|
+
providerMetadata: {
|
|
2778
|
+
openai: {
|
|
2779
|
+
itemId: value.item_id
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2301
2782
|
});
|
|
2302
2783
|
} else if (isResponseFinishedChunk(value)) {
|
|
2303
2784
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2304
|
-
finishReason: (
|
|
2785
|
+
finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
|
|
2305
2786
|
hasToolCalls
|
|
2306
2787
|
});
|
|
2307
2788
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2308
2789
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
2309
2790
|
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
2310
|
-
usage.reasoningTokens = (
|
|
2311
|
-
usage.cachedInputTokens = (
|
|
2791
|
+
usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
|
|
2792
|
+
usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
|
|
2312
2793
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2313
2794
|
controller.enqueue({
|
|
2314
2795
|
type: "source",
|
|
2315
2796
|
sourceType: "url",
|
|
2316
|
-
id: (
|
|
2797
|
+
id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : (0, import_provider_utils11.generateId)(),
|
|
2317
2798
|
url: value.annotation.url,
|
|
2318
2799
|
title: value.annotation.title
|
|
2319
2800
|
});
|
|
2801
|
+
} else if (isErrorChunk(value)) {
|
|
2802
|
+
controller.enqueue({ type: "error", error: value });
|
|
2320
2803
|
}
|
|
2321
2804
|
},
|
|
2322
2805
|
flush(controller) {
|
|
@@ -2338,95 +2821,141 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2338
2821
|
};
|
|
2339
2822
|
}
|
|
2340
2823
|
};
|
|
2341
|
-
var usageSchema2 =
|
|
2342
|
-
input_tokens:
|
|
2343
|
-
input_tokens_details:
|
|
2344
|
-
output_tokens:
|
|
2345
|
-
output_tokens_details:
|
|
2824
|
+
var usageSchema2 = import_v414.z.object({
|
|
2825
|
+
input_tokens: import_v414.z.number(),
|
|
2826
|
+
input_tokens_details: import_v414.z.object({ cached_tokens: import_v414.z.number().nullish() }).nullish(),
|
|
2827
|
+
output_tokens: import_v414.z.number(),
|
|
2828
|
+
output_tokens_details: import_v414.z.object({ reasoning_tokens: import_v414.z.number().nullish() }).nullish()
|
|
2346
2829
|
});
|
|
2347
|
-
var textDeltaChunkSchema =
|
|
2348
|
-
type:
|
|
2349
|
-
|
|
2830
|
+
var textDeltaChunkSchema = import_v414.z.object({
|
|
2831
|
+
type: import_v414.z.literal("response.output_text.delta"),
|
|
2832
|
+
item_id: import_v414.z.string(),
|
|
2833
|
+
delta: import_v414.z.string()
|
|
2350
2834
|
});
|
|
2351
|
-
var
|
|
2352
|
-
type:
|
|
2353
|
-
|
|
2354
|
-
|
|
2835
|
+
var errorChunkSchema = import_v414.z.object({
|
|
2836
|
+
type: import_v414.z.literal("error"),
|
|
2837
|
+
code: import_v414.z.string(),
|
|
2838
|
+
message: import_v414.z.string(),
|
|
2839
|
+
param: import_v414.z.string().nullish(),
|
|
2840
|
+
sequence_number: import_v414.z.number()
|
|
2841
|
+
});
|
|
2842
|
+
var responseFinishedChunkSchema = import_v414.z.object({
|
|
2843
|
+
type: import_v414.z.enum(["response.completed", "response.incomplete"]),
|
|
2844
|
+
response: import_v414.z.object({
|
|
2845
|
+
incomplete_details: import_v414.z.object({ reason: import_v414.z.string() }).nullish(),
|
|
2355
2846
|
usage: usageSchema2
|
|
2356
2847
|
})
|
|
2357
2848
|
});
|
|
2358
|
-
var responseCreatedChunkSchema =
|
|
2359
|
-
type:
|
|
2360
|
-
response:
|
|
2361
|
-
id:
|
|
2362
|
-
created_at:
|
|
2363
|
-
model:
|
|
2849
|
+
var responseCreatedChunkSchema = import_v414.z.object({
|
|
2850
|
+
type: import_v414.z.literal("response.created"),
|
|
2851
|
+
response: import_v414.z.object({
|
|
2852
|
+
id: import_v414.z.string(),
|
|
2853
|
+
created_at: import_v414.z.number(),
|
|
2854
|
+
model: import_v414.z.string()
|
|
2364
2855
|
})
|
|
2365
2856
|
});
|
|
2366
|
-
var
|
|
2367
|
-
type:
|
|
2368
|
-
output_index:
|
|
2369
|
-
item:
|
|
2370
|
-
|
|
2371
|
-
type:
|
|
2857
|
+
var responseOutputItemAddedSchema = import_v414.z.object({
|
|
2858
|
+
type: import_v414.z.literal("response.output_item.added"),
|
|
2859
|
+
output_index: import_v414.z.number(),
|
|
2860
|
+
item: import_v414.z.discriminatedUnion("type", [
|
|
2861
|
+
import_v414.z.object({
|
|
2862
|
+
type: import_v414.z.literal("message"),
|
|
2863
|
+
id: import_v414.z.string()
|
|
2864
|
+
}),
|
|
2865
|
+
import_v414.z.object({
|
|
2866
|
+
type: import_v414.z.literal("reasoning"),
|
|
2867
|
+
id: import_v414.z.string(),
|
|
2868
|
+
encrypted_content: import_v414.z.string().nullish()
|
|
2372
2869
|
}),
|
|
2373
|
-
|
|
2374
|
-
type:
|
|
2375
|
-
id:
|
|
2376
|
-
call_id:
|
|
2377
|
-
name:
|
|
2378
|
-
arguments:
|
|
2379
|
-
|
|
2870
|
+
import_v414.z.object({
|
|
2871
|
+
type: import_v414.z.literal("function_call"),
|
|
2872
|
+
id: import_v414.z.string(),
|
|
2873
|
+
call_id: import_v414.z.string(),
|
|
2874
|
+
name: import_v414.z.string(),
|
|
2875
|
+
arguments: import_v414.z.string()
|
|
2876
|
+
}),
|
|
2877
|
+
import_v414.z.object({
|
|
2878
|
+
type: import_v414.z.literal("web_search_call"),
|
|
2879
|
+
id: import_v414.z.string(),
|
|
2880
|
+
status: import_v414.z.string()
|
|
2881
|
+
}),
|
|
2882
|
+
import_v414.z.object({
|
|
2883
|
+
type: import_v414.z.literal("computer_call"),
|
|
2884
|
+
id: import_v414.z.string(),
|
|
2885
|
+
status: import_v414.z.string()
|
|
2380
2886
|
})
|
|
2381
2887
|
])
|
|
2382
2888
|
});
|
|
2383
|
-
var
|
|
2384
|
-
type:
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2889
|
+
var responseOutputItemDoneSchema = import_v414.z.object({
|
|
2890
|
+
type: import_v414.z.literal("response.output_item.done"),
|
|
2891
|
+
output_index: import_v414.z.number(),
|
|
2892
|
+
item: import_v414.z.discriminatedUnion("type", [
|
|
2893
|
+
import_v414.z.object({
|
|
2894
|
+
type: import_v414.z.literal("message"),
|
|
2895
|
+
id: import_v414.z.string()
|
|
2896
|
+
}),
|
|
2897
|
+
import_v414.z.object({
|
|
2898
|
+
type: import_v414.z.literal("reasoning"),
|
|
2899
|
+
id: import_v414.z.string(),
|
|
2900
|
+
encrypted_content: import_v414.z.string().nullish()
|
|
2395
2901
|
}),
|
|
2396
|
-
|
|
2397
|
-
type:
|
|
2398
|
-
id:
|
|
2399
|
-
call_id:
|
|
2400
|
-
name:
|
|
2401
|
-
arguments:
|
|
2902
|
+
import_v414.z.object({
|
|
2903
|
+
type: import_v414.z.literal("function_call"),
|
|
2904
|
+
id: import_v414.z.string(),
|
|
2905
|
+
call_id: import_v414.z.string(),
|
|
2906
|
+
name: import_v414.z.string(),
|
|
2907
|
+
arguments: import_v414.z.string(),
|
|
2908
|
+
status: import_v414.z.literal("completed")
|
|
2909
|
+
}),
|
|
2910
|
+
import_v414.z.object({
|
|
2911
|
+
type: import_v414.z.literal("web_search_call"),
|
|
2912
|
+
id: import_v414.z.string(),
|
|
2913
|
+
status: import_v414.z.literal("completed")
|
|
2914
|
+
}),
|
|
2915
|
+
import_v414.z.object({
|
|
2916
|
+
type: import_v414.z.literal("computer_call"),
|
|
2917
|
+
id: import_v414.z.string(),
|
|
2918
|
+
status: import_v414.z.literal("completed")
|
|
2402
2919
|
})
|
|
2403
2920
|
])
|
|
2404
2921
|
});
|
|
2405
|
-
var
|
|
2406
|
-
type:
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2922
|
+
var responseFunctionCallArgumentsDeltaSchema = import_v414.z.object({
|
|
2923
|
+
type: import_v414.z.literal("response.function_call_arguments.delta"),
|
|
2924
|
+
item_id: import_v414.z.string(),
|
|
2925
|
+
output_index: import_v414.z.number(),
|
|
2926
|
+
delta: import_v414.z.string()
|
|
2927
|
+
});
|
|
2928
|
+
var responseAnnotationAddedSchema = import_v414.z.object({
|
|
2929
|
+
type: import_v414.z.literal("response.output_text.annotation.added"),
|
|
2930
|
+
annotation: import_v414.z.object({
|
|
2931
|
+
type: import_v414.z.literal("url_citation"),
|
|
2932
|
+
url: import_v414.z.string(),
|
|
2933
|
+
title: import_v414.z.string()
|
|
2411
2934
|
})
|
|
2412
2935
|
});
|
|
2413
|
-
var
|
|
2414
|
-
type:
|
|
2415
|
-
item_id:
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2936
|
+
var responseReasoningSummaryPartAddedSchema = import_v414.z.object({
|
|
2937
|
+
type: import_v414.z.literal("response.reasoning_summary_part.added"),
|
|
2938
|
+
item_id: import_v414.z.string(),
|
|
2939
|
+
summary_index: import_v414.z.number()
|
|
2940
|
+
});
|
|
2941
|
+
var responseReasoningSummaryTextDeltaSchema = import_v414.z.object({
|
|
2942
|
+
type: import_v414.z.literal("response.reasoning_summary_text.delta"),
|
|
2943
|
+
item_id: import_v414.z.string(),
|
|
2944
|
+
summary_index: import_v414.z.number(),
|
|
2945
|
+
delta: import_v414.z.string()
|
|
2419
2946
|
});
|
|
2420
|
-
var openaiResponsesChunkSchema =
|
|
2947
|
+
var openaiResponsesChunkSchema = import_v414.z.union([
|
|
2421
2948
|
textDeltaChunkSchema,
|
|
2422
2949
|
responseFinishedChunkSchema,
|
|
2423
2950
|
responseCreatedChunkSchema,
|
|
2951
|
+
responseOutputItemAddedSchema,
|
|
2424
2952
|
responseOutputItemDoneSchema,
|
|
2425
2953
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2426
|
-
responseOutputItemAddedSchema,
|
|
2427
2954
|
responseAnnotationAddedSchema,
|
|
2955
|
+
responseReasoningSummaryPartAddedSchema,
|
|
2428
2956
|
responseReasoningSummaryTextDeltaSchema,
|
|
2429
|
-
|
|
2957
|
+
errorChunkSchema,
|
|
2958
|
+
import_v414.z.object({ type: import_v414.z.string() }).loose()
|
|
2430
2959
|
// fallback for unknown chunks
|
|
2431
2960
|
]);
|
|
2432
2961
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2435,6 +2964,9 @@ function isTextDeltaChunk(chunk) {
|
|
|
2435
2964
|
function isResponseOutputItemDoneChunk(chunk) {
|
|
2436
2965
|
return chunk.type === "response.output_item.done";
|
|
2437
2966
|
}
|
|
2967
|
+
function isResponseOutputItemDoneReasoningChunk(chunk) {
|
|
2968
|
+
return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
|
|
2969
|
+
}
|
|
2438
2970
|
function isResponseFinishedChunk(chunk) {
|
|
2439
2971
|
return chunk.type === "response.completed" || chunk.type === "response.incomplete";
|
|
2440
2972
|
}
|
|
@@ -2447,14 +2979,23 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
|
2447
2979
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
2448
2980
|
return chunk.type === "response.output_item.added";
|
|
2449
2981
|
}
|
|
2982
|
+
function isResponseOutputItemAddedReasoningChunk(chunk) {
|
|
2983
|
+
return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
|
|
2984
|
+
}
|
|
2450
2985
|
function isResponseAnnotationAddedChunk(chunk) {
|
|
2451
2986
|
return chunk.type === "response.output_text.annotation.added";
|
|
2452
2987
|
}
|
|
2988
|
+
function isResponseReasoningSummaryPartAddedChunk(chunk) {
|
|
2989
|
+
return chunk.type === "response.reasoning_summary_part.added";
|
|
2990
|
+
}
|
|
2453
2991
|
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
2454
2992
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
2455
2993
|
}
|
|
2994
|
+
function isErrorChunk(chunk) {
|
|
2995
|
+
return chunk.type === "error";
|
|
2996
|
+
}
|
|
2456
2997
|
function getResponsesModelConfig(modelId) {
|
|
2457
|
-
if (modelId.startsWith("o")) {
|
|
2998
|
+
if (modelId.startsWith("o") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
|
|
2458
2999
|
if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
|
|
2459
3000
|
return {
|
|
2460
3001
|
isReasoningModel: true,
|
|
@@ -2474,30 +3015,35 @@ function getResponsesModelConfig(modelId) {
|
|
|
2474
3015
|
requiredAutoTruncation: false
|
|
2475
3016
|
};
|
|
2476
3017
|
}
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
3018
|
+
function supportsFlexProcessing2(modelId) {
|
|
3019
|
+
return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
3020
|
+
}
|
|
3021
|
+
var openaiResponsesProviderOptionsSchema = import_v414.z.object({
|
|
3022
|
+
metadata: import_v414.z.any().nullish(),
|
|
3023
|
+
parallelToolCalls: import_v414.z.boolean().nullish(),
|
|
3024
|
+
previousResponseId: import_v414.z.string().nullish(),
|
|
3025
|
+
store: import_v414.z.boolean().nullish(),
|
|
3026
|
+
user: import_v414.z.string().nullish(),
|
|
3027
|
+
reasoningEffort: import_v414.z.string().nullish(),
|
|
3028
|
+
strictJsonSchema: import_v414.z.boolean().nullish(),
|
|
3029
|
+
instructions: import_v414.z.string().nullish(),
|
|
3030
|
+
reasoningSummary: import_v414.z.string().nullish(),
|
|
3031
|
+
serviceTier: import_v414.z.enum(["auto", "flex"]).nullish(),
|
|
3032
|
+
include: import_v414.z.array(import_v414.z.enum(["reasoning.encrypted_content"])).nullish()
|
|
2487
3033
|
});
|
|
2488
3034
|
|
|
2489
3035
|
// src/openai-speech-model.ts
|
|
2490
|
-
var
|
|
2491
|
-
var
|
|
2492
|
-
var OpenAIProviderOptionsSchema =
|
|
2493
|
-
instructions:
|
|
2494
|
-
speed:
|
|
3036
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
3037
|
+
var import_v415 = require("zod/v4");
|
|
3038
|
+
var OpenAIProviderOptionsSchema = import_v415.z.object({
|
|
3039
|
+
instructions: import_v415.z.string().nullish(),
|
|
3040
|
+
speed: import_v415.z.number().min(0.25).max(4).default(1).nullish()
|
|
2495
3041
|
});
|
|
2496
3042
|
var OpenAISpeechModel = class {
|
|
2497
3043
|
constructor(modelId, config) {
|
|
2498
3044
|
this.modelId = modelId;
|
|
2499
3045
|
this.config = config;
|
|
2500
|
-
this.specificationVersion = "
|
|
3046
|
+
this.specificationVersion = "v2";
|
|
2501
3047
|
}
|
|
2502
3048
|
get provider() {
|
|
2503
3049
|
return this.config.provider;
|
|
@@ -2508,10 +3054,11 @@ var OpenAISpeechModel = class {
|
|
|
2508
3054
|
outputFormat = "mp3",
|
|
2509
3055
|
speed,
|
|
2510
3056
|
instructions,
|
|
3057
|
+
language,
|
|
2511
3058
|
providerOptions
|
|
2512
3059
|
}) {
|
|
2513
3060
|
const warnings = [];
|
|
2514
|
-
const openAIOptions = await (0,
|
|
3061
|
+
const openAIOptions = await (0, import_provider_utils12.parseProviderOptions)({
|
|
2515
3062
|
provider: "openai",
|
|
2516
3063
|
providerOptions,
|
|
2517
3064
|
schema: OpenAIProviderOptionsSchema
|
|
@@ -2544,6 +3091,13 @@ var OpenAISpeechModel = class {
|
|
|
2544
3091
|
}
|
|
2545
3092
|
}
|
|
2546
3093
|
}
|
|
3094
|
+
if (language) {
|
|
3095
|
+
warnings.push({
|
|
3096
|
+
type: "unsupported-setting",
|
|
3097
|
+
setting: "language",
|
|
3098
|
+
details: `OpenAI speech models do not support language selection. Language parameter "${language}" was ignored.`
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
2547
3101
|
return {
|
|
2548
3102
|
requestBody,
|
|
2549
3103
|
warnings
|
|
@@ -2557,15 +3111,15 @@ var OpenAISpeechModel = class {
|
|
|
2557
3111
|
value: audio,
|
|
2558
3112
|
responseHeaders,
|
|
2559
3113
|
rawValue: rawResponse
|
|
2560
|
-
} = await (0,
|
|
3114
|
+
} = await (0, import_provider_utils12.postJsonToApi)({
|
|
2561
3115
|
url: this.config.url({
|
|
2562
3116
|
path: "/audio/speech",
|
|
2563
3117
|
modelId: this.modelId
|
|
2564
3118
|
}),
|
|
2565
|
-
headers: (0,
|
|
3119
|
+
headers: (0, import_provider_utils12.combineHeaders)(this.config.headers(), options.headers),
|
|
2566
3120
|
body: requestBody,
|
|
2567
3121
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2568
|
-
successfulResponseHandler: (0,
|
|
3122
|
+
successfulResponseHandler: (0, import_provider_utils12.createBinaryResponseHandler)(),
|
|
2569
3123
|
abortSignal: options.abortSignal,
|
|
2570
3124
|
fetch: this.config.fetch
|
|
2571
3125
|
});
|
|
@@ -2588,10 +3142,10 @@ var OpenAISpeechModel = class {
|
|
|
2588
3142
|
// src/openai-provider.ts
|
|
2589
3143
|
function createOpenAI(options = {}) {
|
|
2590
3144
|
var _a, _b;
|
|
2591
|
-
const baseURL = (_a = (0,
|
|
3145
|
+
const baseURL = (_a = (0, import_provider_utils13.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
|
|
2592
3146
|
const providerName = (_b = options.name) != null ? _b : "openai";
|
|
2593
3147
|
const getHeaders = () => ({
|
|
2594
|
-
Authorization: `Bearer ${(0,
|
|
3148
|
+
Authorization: `Bearer ${(0, import_provider_utils13.loadApiKey)({
|
|
2595
3149
|
apiKey: options.apiKey,
|
|
2596
3150
|
environmentVariableName: "OPENAI_API_KEY",
|
|
2597
3151
|
description: "OpenAI"
|
|
@@ -2642,10 +3196,7 @@ function createOpenAI(options = {}) {
|
|
|
2642
3196
|
"The OpenAI model function cannot be called with the new keyword."
|
|
2643
3197
|
);
|
|
2644
3198
|
}
|
|
2645
|
-
|
|
2646
|
-
return createCompletionModel(modelId);
|
|
2647
|
-
}
|
|
2648
|
-
return createChatModel(modelId);
|
|
3199
|
+
return createResponsesModel(modelId);
|
|
2649
3200
|
};
|
|
2650
3201
|
const createResponsesModel = (modelId) => {
|
|
2651
3202
|
return new OpenAIResponsesLanguageModel(modelId, {
|