@ai-sdk/openai 2.0.0-canary.8 → 2.0.0
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 +663 -0
- package/README.md +2 -2
- package/dist/index.d.mts +84 -176
- package/dist/index.d.ts +84 -176
- package/dist/index.js +1323 -627
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1275 -575
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +85 -252
- package/dist/internal/index.d.ts +85 -252
- package/dist/internal/index.js +1315 -584
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1266 -535
- package/dist/internal/index.mjs.map +1 -1
- package/internal.d.ts +1 -0
- package/package.json +11 -9
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");
|
|
@@ -136,7 +136,7 @@ function convertToOpenAIChatMessages({
|
|
|
136
136
|
type: "file",
|
|
137
137
|
file: {
|
|
138
138
|
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
139
|
-
file_data: `data:application/pdf;base64,${part.data}`
|
|
139
|
+
file_data: `data:application/pdf;base64,${(0, import_provider_utils.convertToBase64)(part.data)}`
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
142
|
} else {
|
|
@@ -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;
|
|
@@ -198,17 +211,17 @@ function convertToOpenAIChatMessages({
|
|
|
198
211
|
return { messages, warnings };
|
|
199
212
|
}
|
|
200
213
|
|
|
201
|
-
// src/
|
|
202
|
-
function
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
214
|
+
// src/get-response-metadata.ts
|
|
215
|
+
function getResponseMetadata({
|
|
216
|
+
id,
|
|
217
|
+
model,
|
|
218
|
+
created
|
|
219
|
+
}) {
|
|
220
|
+
return {
|
|
221
|
+
id: id != null ? id : void 0,
|
|
222
|
+
modelId: model != null ? model : void 0,
|
|
223
|
+
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
224
|
+
};
|
|
212
225
|
}
|
|
213
226
|
|
|
214
227
|
// src/map-openai-finish-reason.ts
|
|
@@ -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,50 +260,71 @@ 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(),
|
|
293
|
+
/**
|
|
294
|
+
* Whether to use structured outputs.
|
|
295
|
+
*
|
|
296
|
+
* @default true
|
|
297
|
+
*/
|
|
298
|
+
structuredOutputs: import_v4.z.boolean().optional(),
|
|
299
|
+
/**
|
|
300
|
+
* Service tier for the request.
|
|
301
|
+
* - 'auto': Default service tier
|
|
302
|
+
* - 'flex': 50% cheaper processing at the cost of increased latency. Only available for o3 and o4-mini models.
|
|
303
|
+
* - 'priority': Higher-speed processing with predictably low latency at premium cost. Available for Enterprise customers.
|
|
304
|
+
*
|
|
305
|
+
* @default 'auto'
|
|
306
|
+
*/
|
|
307
|
+
serviceTier: import_v4.z.enum(["auto", "flex", "priority"]).optional(),
|
|
308
|
+
/**
|
|
309
|
+
* Whether to use strict JSON schema validation.
|
|
310
|
+
*
|
|
311
|
+
* @default false
|
|
312
|
+
*/
|
|
313
|
+
strictJsonSchema: import_v4.z.boolean().optional()
|
|
280
314
|
});
|
|
281
315
|
|
|
282
316
|
// src/openai-error.ts
|
|
283
|
-
var
|
|
317
|
+
var import_v42 = require("zod/v4");
|
|
284
318
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
285
|
-
var openaiErrorDataSchema =
|
|
286
|
-
error:
|
|
287
|
-
message:
|
|
319
|
+
var openaiErrorDataSchema = import_v42.z.object({
|
|
320
|
+
error: import_v42.z.object({
|
|
321
|
+
message: import_v42.z.string(),
|
|
288
322
|
// The additional information below is handled loosely to support
|
|
289
323
|
// OpenAI-compatible providers that have slightly different error
|
|
290
324
|
// responses:
|
|
291
|
-
type:
|
|
292
|
-
param:
|
|
293
|
-
code:
|
|
325
|
+
type: import_v42.z.string().nullish(),
|
|
326
|
+
param: import_v42.z.any().nullish(),
|
|
327
|
+
code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullish()
|
|
294
328
|
})
|
|
295
329
|
});
|
|
296
330
|
var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
|
|
@@ -298,25 +332,101 @@ var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResp
|
|
|
298
332
|
errorToMessage: (data) => data.error.message
|
|
299
333
|
});
|
|
300
334
|
|
|
301
|
-
// src/get-response-metadata.ts
|
|
302
|
-
function getResponseMetadata({
|
|
303
|
-
id,
|
|
304
|
-
model,
|
|
305
|
-
created
|
|
306
|
-
}) {
|
|
307
|
-
return {
|
|
308
|
-
id: id != null ? id : void 0,
|
|
309
|
-
modelId: model != null ? model : void 0,
|
|
310
|
-
timestamp: created != null ? new Date(created * 1e3) : void 0
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
335
|
// src/openai-prepare-tools.ts
|
|
315
336
|
var import_provider2 = require("@ai-sdk/provider");
|
|
337
|
+
|
|
338
|
+
// src/tool/file-search.ts
|
|
339
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
340
|
+
var import_v43 = require("zod/v4");
|
|
341
|
+
var comparisonFilterSchema = import_v43.z.object({
|
|
342
|
+
key: import_v43.z.string(),
|
|
343
|
+
type: import_v43.z.enum(["eq", "ne", "gt", "gte", "lt", "lte"]),
|
|
344
|
+
value: import_v43.z.union([import_v43.z.string(), import_v43.z.number(), import_v43.z.boolean()])
|
|
345
|
+
});
|
|
346
|
+
var compoundFilterSchema = import_v43.z.object({
|
|
347
|
+
type: import_v43.z.enum(["and", "or"]),
|
|
348
|
+
filters: import_v43.z.array(
|
|
349
|
+
import_v43.z.union([comparisonFilterSchema, import_v43.z.lazy(() => compoundFilterSchema)])
|
|
350
|
+
)
|
|
351
|
+
});
|
|
352
|
+
var filtersSchema = import_v43.z.union([comparisonFilterSchema, compoundFilterSchema]);
|
|
353
|
+
var fileSearchArgsSchema = import_v43.z.object({
|
|
354
|
+
/**
|
|
355
|
+
* List of vector store IDs to search through. If not provided, searches all available vector stores.
|
|
356
|
+
*/
|
|
357
|
+
vectorStoreIds: import_v43.z.array(import_v43.z.string()).optional(),
|
|
358
|
+
/**
|
|
359
|
+
* Maximum number of search results to return. Defaults to 10.
|
|
360
|
+
*/
|
|
361
|
+
maxNumResults: import_v43.z.number().optional(),
|
|
362
|
+
/**
|
|
363
|
+
* Ranking options for the search.
|
|
364
|
+
*/
|
|
365
|
+
ranking: import_v43.z.object({
|
|
366
|
+
ranker: import_v43.z.enum(["auto", "default-2024-08-21"]).optional()
|
|
367
|
+
}).optional(),
|
|
368
|
+
/**
|
|
369
|
+
* A filter to apply based on file attributes.
|
|
370
|
+
*/
|
|
371
|
+
filters: filtersSchema.optional()
|
|
372
|
+
});
|
|
373
|
+
var fileSearch = (0, import_provider_utils3.createProviderDefinedToolFactory)({
|
|
374
|
+
id: "openai.file_search",
|
|
375
|
+
name: "file_search",
|
|
376
|
+
inputSchema: import_v43.z.object({
|
|
377
|
+
query: import_v43.z.string()
|
|
378
|
+
})
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// src/tool/web-search-preview.ts
|
|
382
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
383
|
+
var import_v44 = require("zod/v4");
|
|
384
|
+
var webSearchPreviewArgsSchema = import_v44.z.object({
|
|
385
|
+
/**
|
|
386
|
+
* Search context size to use for the web search.
|
|
387
|
+
* - high: Most comprehensive context, highest cost, slower response
|
|
388
|
+
* - medium: Balanced context, cost, and latency (default)
|
|
389
|
+
* - low: Least context, lowest cost, fastest response
|
|
390
|
+
*/
|
|
391
|
+
searchContextSize: import_v44.z.enum(["low", "medium", "high"]).optional(),
|
|
392
|
+
/**
|
|
393
|
+
* User location information to provide geographically relevant search results.
|
|
394
|
+
*/
|
|
395
|
+
userLocation: import_v44.z.object({
|
|
396
|
+
/**
|
|
397
|
+
* Type of location (always 'approximate')
|
|
398
|
+
*/
|
|
399
|
+
type: import_v44.z.literal("approximate"),
|
|
400
|
+
/**
|
|
401
|
+
* Two-letter ISO country code (e.g., 'US', 'GB')
|
|
402
|
+
*/
|
|
403
|
+
country: import_v44.z.string().optional(),
|
|
404
|
+
/**
|
|
405
|
+
* City name (free text, e.g., 'Minneapolis')
|
|
406
|
+
*/
|
|
407
|
+
city: import_v44.z.string().optional(),
|
|
408
|
+
/**
|
|
409
|
+
* Region name (free text, e.g., 'Minnesota')
|
|
410
|
+
*/
|
|
411
|
+
region: import_v44.z.string().optional(),
|
|
412
|
+
/**
|
|
413
|
+
* IANA timezone (e.g., 'America/Chicago')
|
|
414
|
+
*/
|
|
415
|
+
timezone: import_v44.z.string().optional()
|
|
416
|
+
}).optional()
|
|
417
|
+
});
|
|
418
|
+
var webSearchPreview = (0, import_provider_utils4.createProviderDefinedToolFactory)({
|
|
419
|
+
id: "openai.web_search_preview",
|
|
420
|
+
name: "web_search_preview",
|
|
421
|
+
inputSchema: import_v44.z.object({})
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// src/openai-prepare-tools.ts
|
|
316
425
|
function prepareTools({
|
|
317
426
|
tools,
|
|
318
427
|
toolChoice,
|
|
319
|
-
structuredOutputs
|
|
428
|
+
structuredOutputs,
|
|
429
|
+
strictJsonSchema
|
|
320
430
|
}) {
|
|
321
431
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
322
432
|
const toolWarnings = [];
|
|
@@ -325,18 +435,48 @@ function prepareTools({
|
|
|
325
435
|
}
|
|
326
436
|
const openaiTools2 = [];
|
|
327
437
|
for (const tool of tools) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
438
|
+
switch (tool.type) {
|
|
439
|
+
case "function":
|
|
440
|
+
openaiTools2.push({
|
|
441
|
+
type: "function",
|
|
442
|
+
function: {
|
|
443
|
+
name: tool.name,
|
|
444
|
+
description: tool.description,
|
|
445
|
+
parameters: tool.inputSchema,
|
|
446
|
+
strict: structuredOutputs ? strictJsonSchema : void 0
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
break;
|
|
450
|
+
case "provider-defined":
|
|
451
|
+
switch (tool.id) {
|
|
452
|
+
case "openai.file_search": {
|
|
453
|
+
const args = fileSearchArgsSchema.parse(tool.args);
|
|
454
|
+
openaiTools2.push({
|
|
455
|
+
type: "file_search",
|
|
456
|
+
vector_store_ids: args.vectorStoreIds,
|
|
457
|
+
max_num_results: args.maxNumResults,
|
|
458
|
+
ranking_options: args.ranking ? { ranker: args.ranking.ranker } : void 0,
|
|
459
|
+
filters: args.filters
|
|
460
|
+
});
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
case "openai.web_search_preview": {
|
|
464
|
+
const args = webSearchPreviewArgsSchema.parse(tool.args);
|
|
465
|
+
openaiTools2.push({
|
|
466
|
+
type: "web_search_preview",
|
|
467
|
+
search_context_size: args.searchContextSize,
|
|
468
|
+
user_location: args.userLocation
|
|
469
|
+
});
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
default:
|
|
473
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
474
|
+
break;
|
|
338
475
|
}
|
|
339
|
-
|
|
476
|
+
break;
|
|
477
|
+
default:
|
|
478
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
479
|
+
break;
|
|
340
480
|
}
|
|
341
481
|
}
|
|
342
482
|
if (toolChoice == null) {
|
|
@@ -370,29 +510,18 @@ function prepareTools({
|
|
|
370
510
|
|
|
371
511
|
// src/openai-chat-language-model.ts
|
|
372
512
|
var OpenAIChatLanguageModel = class {
|
|
373
|
-
constructor(modelId,
|
|
513
|
+
constructor(modelId, config) {
|
|
374
514
|
this.specificationVersion = "v2";
|
|
515
|
+
this.supportedUrls = {
|
|
516
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
517
|
+
};
|
|
375
518
|
this.modelId = modelId;
|
|
376
|
-
this.settings = settings;
|
|
377
519
|
this.config = config;
|
|
378
520
|
}
|
|
379
|
-
get supportsStructuredOutputs() {
|
|
380
|
-
var _a;
|
|
381
|
-
return (_a = this.settings.structuredOutputs) != null ? _a : isReasoningModel(this.modelId);
|
|
382
|
-
}
|
|
383
|
-
get defaultObjectGenerationMode() {
|
|
384
|
-
if (isAudioModel(this.modelId)) {
|
|
385
|
-
return "tool";
|
|
386
|
-
}
|
|
387
|
-
return this.supportsStructuredOutputs ? "json" : "tool";
|
|
388
|
-
}
|
|
389
521
|
get provider() {
|
|
390
522
|
return this.config.provider;
|
|
391
523
|
}
|
|
392
|
-
|
|
393
|
-
return !this.settings.downloadImages;
|
|
394
|
-
}
|
|
395
|
-
getArgs({
|
|
524
|
+
async getArgs({
|
|
396
525
|
prompt,
|
|
397
526
|
maxOutputTokens,
|
|
398
527
|
temperature,
|
|
@@ -407,20 +536,21 @@ var OpenAIChatLanguageModel = class {
|
|
|
407
536
|
toolChoice,
|
|
408
537
|
providerOptions
|
|
409
538
|
}) {
|
|
410
|
-
var _a, _b;
|
|
539
|
+
var _a, _b, _c, _d;
|
|
411
540
|
const warnings = [];
|
|
412
|
-
const openaiOptions = (_a = (0,
|
|
541
|
+
const openaiOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
|
|
413
542
|
provider: "openai",
|
|
414
543
|
providerOptions,
|
|
415
544
|
schema: openaiProviderOptions
|
|
416
545
|
})) != null ? _a : {};
|
|
546
|
+
const structuredOutputs = (_b = openaiOptions.structuredOutputs) != null ? _b : true;
|
|
417
547
|
if (topK != null) {
|
|
418
548
|
warnings.push({
|
|
419
549
|
type: "unsupported-setting",
|
|
420
550
|
setting: "topK"
|
|
421
551
|
});
|
|
422
552
|
}
|
|
423
|
-
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !
|
|
553
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !structuredOutputs) {
|
|
424
554
|
warnings.push({
|
|
425
555
|
type: "unsupported-setting",
|
|
426
556
|
setting: "responseFormat",
|
|
@@ -434,6 +564,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
434
564
|
}
|
|
435
565
|
);
|
|
436
566
|
warnings.push(...messageWarnings);
|
|
567
|
+
const strictJsonSchema = (_c = openaiOptions.strictJsonSchema) != null ? _c : false;
|
|
437
568
|
const baseArgs = {
|
|
438
569
|
// model id:
|
|
439
570
|
model: this.modelId,
|
|
@@ -449,13 +580,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
449
580
|
top_p: topP,
|
|
450
581
|
frequency_penalty: frequencyPenalty,
|
|
451
582
|
presence_penalty: presencePenalty,
|
|
452
|
-
|
|
453
|
-
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs && responseFormat.schema != null ? {
|
|
583
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && responseFormat.schema != null ? {
|
|
454
584
|
type: "json_schema",
|
|
455
585
|
json_schema: {
|
|
456
586
|
schema: responseFormat.schema,
|
|
457
|
-
strict:
|
|
458
|
-
name: (
|
|
587
|
+
strict: strictJsonSchema,
|
|
588
|
+
name: (_d = responseFormat.name) != null ? _d : "response",
|
|
459
589
|
description: responseFormat.description
|
|
460
590
|
}
|
|
461
591
|
} : { type: "json_object" } : void 0,
|
|
@@ -468,6 +598,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
468
598
|
metadata: openaiOptions.metadata,
|
|
469
599
|
prediction: openaiOptions.prediction,
|
|
470
600
|
reasoning_effort: openaiOptions.reasoningEffort,
|
|
601
|
+
service_tier: openaiOptions.serviceTier,
|
|
471
602
|
// messages:
|
|
472
603
|
messages
|
|
473
604
|
};
|
|
@@ -531,16 +662,32 @@ var OpenAIChatLanguageModel = class {
|
|
|
531
662
|
}
|
|
532
663
|
baseArgs.max_tokens = void 0;
|
|
533
664
|
}
|
|
534
|
-
} else if (this.modelId.startsWith("gpt-4o-search-preview")) {
|
|
665
|
+
} else if (this.modelId.startsWith("gpt-4o-search-preview") || this.modelId.startsWith("gpt-4o-mini-search-preview")) {
|
|
535
666
|
if (baseArgs.temperature != null) {
|
|
536
667
|
baseArgs.temperature = void 0;
|
|
537
668
|
warnings.push({
|
|
538
669
|
type: "unsupported-setting",
|
|
539
670
|
setting: "temperature",
|
|
540
|
-
details: "temperature is not supported for the
|
|
671
|
+
details: "temperature is not supported for the search preview models and has been removed."
|
|
541
672
|
});
|
|
542
673
|
}
|
|
543
674
|
}
|
|
675
|
+
if (openaiOptions.serviceTier === "flex" && !supportsFlexProcessing(this.modelId)) {
|
|
676
|
+
warnings.push({
|
|
677
|
+
type: "unsupported-setting",
|
|
678
|
+
setting: "serviceTier",
|
|
679
|
+
details: "flex processing is only available for o3 and o4-mini models"
|
|
680
|
+
});
|
|
681
|
+
baseArgs.service_tier = void 0;
|
|
682
|
+
}
|
|
683
|
+
if (openaiOptions.serviceTier === "priority" && !supportsPriorityProcessing(this.modelId)) {
|
|
684
|
+
warnings.push({
|
|
685
|
+
type: "unsupported-setting",
|
|
686
|
+
setting: "serviceTier",
|
|
687
|
+
details: "priority processing is only available for supported models (GPT-4, o3, o4-mini) and requires Enterprise access"
|
|
688
|
+
});
|
|
689
|
+
baseArgs.service_tier = void 0;
|
|
690
|
+
}
|
|
544
691
|
const {
|
|
545
692
|
tools: openaiTools2,
|
|
546
693
|
toolChoice: openaiToolChoice,
|
|
@@ -548,7 +695,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
548
695
|
} = prepareTools({
|
|
549
696
|
tools,
|
|
550
697
|
toolChoice,
|
|
551
|
-
structuredOutputs
|
|
698
|
+
structuredOutputs,
|
|
699
|
+
strictJsonSchema
|
|
552
700
|
});
|
|
553
701
|
return {
|
|
554
702
|
args: {
|
|
@@ -560,21 +708,21 @@ var OpenAIChatLanguageModel = class {
|
|
|
560
708
|
};
|
|
561
709
|
}
|
|
562
710
|
async doGenerate(options) {
|
|
563
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
564
|
-
const { args: body, warnings } = this.getArgs(options);
|
|
711
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
712
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
565
713
|
const {
|
|
566
714
|
responseHeaders,
|
|
567
715
|
value: response,
|
|
568
716
|
rawValue: rawResponse
|
|
569
|
-
} = await (0,
|
|
717
|
+
} = await (0, import_provider_utils5.postJsonToApi)({
|
|
570
718
|
url: this.config.url({
|
|
571
719
|
path: "/chat/completions",
|
|
572
720
|
modelId: this.modelId
|
|
573
721
|
}),
|
|
574
|
-
headers: (0,
|
|
722
|
+
headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
|
|
575
723
|
body,
|
|
576
724
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
577
|
-
successfulResponseHandler: (0,
|
|
725
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
578
726
|
openaiChatResponseSchema
|
|
579
727
|
),
|
|
580
728
|
abortSignal: options.abortSignal,
|
|
@@ -589,33 +737,32 @@ var OpenAIChatLanguageModel = class {
|
|
|
589
737
|
for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
|
|
590
738
|
content.push({
|
|
591
739
|
type: "tool-call",
|
|
592
|
-
|
|
593
|
-
toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils3.generateId)(),
|
|
740
|
+
toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils5.generateId)(),
|
|
594
741
|
toolName: toolCall.function.name,
|
|
595
|
-
|
|
742
|
+
input: toolCall.function.arguments
|
|
596
743
|
});
|
|
597
744
|
}
|
|
598
745
|
const completionTokenDetails = (_c = response.usage) == null ? void 0 : _c.completion_tokens_details;
|
|
599
746
|
const promptTokenDetails = (_d = response.usage) == null ? void 0 : _d.prompt_tokens_details;
|
|
600
747
|
const providerMetadata = { openai: {} };
|
|
601
|
-
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null) {
|
|
602
|
-
providerMetadata.openai.reasoningTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens;
|
|
603
|
-
}
|
|
604
748
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
|
|
605
749
|
providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
|
|
606
750
|
}
|
|
607
751
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
608
752
|
providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
|
609
753
|
}
|
|
610
|
-
if ((
|
|
611
|
-
providerMetadata.openai.
|
|
754
|
+
if (((_e = choice.logprobs) == null ? void 0 : _e.content) != null) {
|
|
755
|
+
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
612
756
|
}
|
|
613
757
|
return {
|
|
614
758
|
content,
|
|
615
759
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
616
760
|
usage: {
|
|
617
|
-
inputTokens: (
|
|
618
|
-
outputTokens: (
|
|
761
|
+
inputTokens: (_g = (_f = response.usage) == null ? void 0 : _f.prompt_tokens) != null ? _g : void 0,
|
|
762
|
+
outputTokens: (_i = (_h = response.usage) == null ? void 0 : _h.completion_tokens) != null ? _i : void 0,
|
|
763
|
+
totalTokens: (_k = (_j = response.usage) == null ? void 0 : _j.total_tokens) != null ? _k : void 0,
|
|
764
|
+
reasoningTokens: (_l = completionTokenDetails == null ? void 0 : completionTokenDetails.reasoning_tokens) != null ? _l : void 0,
|
|
765
|
+
cachedInputTokens: (_m = promptTokenDetails == null ? void 0 : promptTokenDetails.cached_tokens) != null ? _m : void 0
|
|
619
766
|
},
|
|
620
767
|
request: { body },
|
|
621
768
|
response: {
|
|
@@ -624,41 +771,41 @@ var OpenAIChatLanguageModel = class {
|
|
|
624
771
|
body: rawResponse
|
|
625
772
|
},
|
|
626
773
|
warnings,
|
|
627
|
-
logprobs: mapOpenAIChatLogProbsOutput(choice.logprobs),
|
|
628
774
|
providerMetadata
|
|
629
775
|
};
|
|
630
776
|
}
|
|
631
777
|
async doStream(options) {
|
|
632
|
-
const { args, warnings } = this.getArgs(options);
|
|
778
|
+
const { args, warnings } = await this.getArgs(options);
|
|
633
779
|
const body = {
|
|
634
780
|
...args,
|
|
635
781
|
stream: true,
|
|
636
|
-
|
|
637
|
-
|
|
782
|
+
stream_options: {
|
|
783
|
+
include_usage: true
|
|
784
|
+
}
|
|
638
785
|
};
|
|
639
|
-
const { responseHeaders, value: response } = await (0,
|
|
786
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({
|
|
640
787
|
url: this.config.url({
|
|
641
788
|
path: "/chat/completions",
|
|
642
789
|
modelId: this.modelId
|
|
643
790
|
}),
|
|
644
|
-
headers: (0,
|
|
791
|
+
headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
|
|
645
792
|
body,
|
|
646
793
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
647
|
-
successfulResponseHandler: (0,
|
|
794
|
+
successfulResponseHandler: (0, import_provider_utils5.createEventSourceResponseHandler)(
|
|
648
795
|
openaiChatChunkSchema
|
|
649
796
|
),
|
|
650
797
|
abortSignal: options.abortSignal,
|
|
651
798
|
fetch: this.config.fetch
|
|
652
799
|
});
|
|
653
|
-
const { messages: rawPrompt, ...rawSettings } = args;
|
|
654
800
|
const toolCalls = [];
|
|
655
801
|
let finishReason = "unknown";
|
|
656
802
|
const usage = {
|
|
657
803
|
inputTokens: void 0,
|
|
658
|
-
outputTokens: void 0
|
|
804
|
+
outputTokens: void 0,
|
|
805
|
+
totalTokens: void 0
|
|
659
806
|
};
|
|
660
|
-
let logprobs;
|
|
661
807
|
let isFirstChunk = true;
|
|
808
|
+
let isActiveText = false;
|
|
662
809
|
const providerMetadata = { openai: {} };
|
|
663
810
|
return {
|
|
664
811
|
stream: response.pipeThrough(
|
|
@@ -667,7 +814,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
667
814
|
controller.enqueue({ type: "stream-start", warnings });
|
|
668
815
|
},
|
|
669
816
|
transform(chunk, controller) {
|
|
670
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
817
|
+
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;
|
|
818
|
+
if (options.includeRawChunks) {
|
|
819
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
820
|
+
}
|
|
671
821
|
if (!chunk.success) {
|
|
672
822
|
finishReason = "error";
|
|
673
823
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -687,48 +837,40 @@ var OpenAIChatLanguageModel = class {
|
|
|
687
837
|
});
|
|
688
838
|
}
|
|
689
839
|
if (value.usage != null) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
usage.outputTokens = completion_tokens != null ? completion_tokens : void 0;
|
|
698
|
-
if ((completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens) != null) {
|
|
699
|
-
providerMetadata.openai.reasoningTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.reasoning_tokens;
|
|
700
|
-
}
|
|
701
|
-
if ((completion_tokens_details == null ? void 0 : completion_tokens_details.accepted_prediction_tokens) != null) {
|
|
702
|
-
providerMetadata.openai.acceptedPredictionTokens = completion_tokens_details == null ? void 0 : completion_tokens_details.accepted_prediction_tokens;
|
|
840
|
+
usage.inputTokens = (_a = value.usage.prompt_tokens) != null ? _a : void 0;
|
|
841
|
+
usage.outputTokens = (_b = value.usage.completion_tokens) != null ? _b : void 0;
|
|
842
|
+
usage.totalTokens = (_c = value.usage.total_tokens) != null ? _c : void 0;
|
|
843
|
+
usage.reasoningTokens = (_e = (_d = value.usage.completion_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
|
|
844
|
+
usage.cachedInputTokens = (_g = (_f = value.usage.prompt_tokens_details) == null ? void 0 : _f.cached_tokens) != null ? _g : void 0;
|
|
845
|
+
if (((_h = value.usage.completion_tokens_details) == null ? void 0 : _h.accepted_prediction_tokens) != null) {
|
|
846
|
+
providerMetadata.openai.acceptedPredictionTokens = (_i = value.usage.completion_tokens_details) == null ? void 0 : _i.accepted_prediction_tokens;
|
|
703
847
|
}
|
|
704
|
-
if ((completion_tokens_details == null ? void 0 :
|
|
705
|
-
providerMetadata.openai.rejectedPredictionTokens = completion_tokens_details == null ? void 0 :
|
|
706
|
-
}
|
|
707
|
-
if ((prompt_tokens_details == null ? void 0 : prompt_tokens_details.cached_tokens) != null) {
|
|
708
|
-
providerMetadata.openai.cachedPromptTokens = prompt_tokens_details == null ? void 0 : prompt_tokens_details.cached_tokens;
|
|
848
|
+
if (((_j = value.usage.completion_tokens_details) == null ? void 0 : _j.rejected_prediction_tokens) != null) {
|
|
849
|
+
providerMetadata.openai.rejectedPredictionTokens = (_k = value.usage.completion_tokens_details) == null ? void 0 : _k.rejected_prediction_tokens;
|
|
709
850
|
}
|
|
710
851
|
}
|
|
711
852
|
const choice = value.choices[0];
|
|
712
853
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
713
854
|
finishReason = mapOpenAIFinishReason(choice.finish_reason);
|
|
714
855
|
}
|
|
856
|
+
if (((_l = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _l.content) != null) {
|
|
857
|
+
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
858
|
+
}
|
|
715
859
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
716
860
|
return;
|
|
717
861
|
}
|
|
718
862
|
const delta = choice.delta;
|
|
719
863
|
if (delta.content != null) {
|
|
864
|
+
if (!isActiveText) {
|
|
865
|
+
controller.enqueue({ type: "text-start", id: "0" });
|
|
866
|
+
isActiveText = true;
|
|
867
|
+
}
|
|
720
868
|
controller.enqueue({
|
|
721
|
-
type: "text",
|
|
722
|
-
|
|
869
|
+
type: "text-delta",
|
|
870
|
+
id: "0",
|
|
871
|
+
delta: delta.content
|
|
723
872
|
});
|
|
724
873
|
}
|
|
725
|
-
const mappedLogprobs = mapOpenAIChatLogProbsOutput(
|
|
726
|
-
choice == null ? void 0 : choice.logprobs
|
|
727
|
-
);
|
|
728
|
-
if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
|
|
729
|
-
if (logprobs === void 0) logprobs = [];
|
|
730
|
-
logprobs.push(...mappedLogprobs);
|
|
731
|
-
}
|
|
732
874
|
if (delta.tool_calls != null) {
|
|
733
875
|
for (const toolCallDelta of delta.tool_calls) {
|
|
734
876
|
const index = toolCallDelta.index;
|
|
@@ -745,39 +887,45 @@ var OpenAIChatLanguageModel = class {
|
|
|
745
887
|
message: `Expected 'id' to be a string.`
|
|
746
888
|
});
|
|
747
889
|
}
|
|
748
|
-
if (((
|
|
890
|
+
if (((_m = toolCallDelta.function) == null ? void 0 : _m.name) == null) {
|
|
749
891
|
throw new import_provider3.InvalidResponseDataError({
|
|
750
892
|
data: toolCallDelta,
|
|
751
893
|
message: `Expected 'function.name' to be a string.`
|
|
752
894
|
});
|
|
753
895
|
}
|
|
896
|
+
controller.enqueue({
|
|
897
|
+
type: "tool-input-start",
|
|
898
|
+
id: toolCallDelta.id,
|
|
899
|
+
toolName: toolCallDelta.function.name
|
|
900
|
+
});
|
|
754
901
|
toolCalls[index] = {
|
|
755
902
|
id: toolCallDelta.id,
|
|
756
903
|
type: "function",
|
|
757
904
|
function: {
|
|
758
905
|
name: toolCallDelta.function.name,
|
|
759
|
-
arguments: (
|
|
906
|
+
arguments: (_n = toolCallDelta.function.arguments) != null ? _n : ""
|
|
760
907
|
},
|
|
761
908
|
hasFinished: false
|
|
762
909
|
};
|
|
763
910
|
const toolCall2 = toolCalls[index];
|
|
764
|
-
if (((
|
|
911
|
+
if (((_o = toolCall2.function) == null ? void 0 : _o.name) != null && ((_p = toolCall2.function) == null ? void 0 : _p.arguments) != null) {
|
|
765
912
|
if (toolCall2.function.arguments.length > 0) {
|
|
766
913
|
controller.enqueue({
|
|
767
|
-
type: "tool-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
toolName: toolCall2.function.name,
|
|
771
|
-
argsTextDelta: toolCall2.function.arguments
|
|
914
|
+
type: "tool-input-delta",
|
|
915
|
+
id: toolCall2.id,
|
|
916
|
+
delta: toolCall2.function.arguments
|
|
772
917
|
});
|
|
773
918
|
}
|
|
774
|
-
if ((0,
|
|
919
|
+
if ((0, import_provider_utils5.isParsableJson)(toolCall2.function.arguments)) {
|
|
920
|
+
controller.enqueue({
|
|
921
|
+
type: "tool-input-end",
|
|
922
|
+
id: toolCall2.id
|
|
923
|
+
});
|
|
775
924
|
controller.enqueue({
|
|
776
925
|
type: "tool-call",
|
|
777
|
-
|
|
778
|
-
toolCallId: (_e = toolCall2.id) != null ? _e : (0, import_provider_utils3.generateId)(),
|
|
926
|
+
toolCallId: (_q = toolCall2.id) != null ? _q : (0, import_provider_utils5.generateId)(),
|
|
779
927
|
toolName: toolCall2.function.name,
|
|
780
|
-
|
|
928
|
+
input: toolCall2.function.arguments
|
|
781
929
|
});
|
|
782
930
|
toolCall2.hasFinished = true;
|
|
783
931
|
}
|
|
@@ -788,23 +936,24 @@ var OpenAIChatLanguageModel = class {
|
|
|
788
936
|
if (toolCall.hasFinished) {
|
|
789
937
|
continue;
|
|
790
938
|
}
|
|
791
|
-
if (((
|
|
792
|
-
toolCall.function.arguments += (
|
|
939
|
+
if (((_r = toolCallDelta.function) == null ? void 0 : _r.arguments) != null) {
|
|
940
|
+
toolCall.function.arguments += (_t = (_s = toolCallDelta.function) == null ? void 0 : _s.arguments) != null ? _t : "";
|
|
793
941
|
}
|
|
794
942
|
controller.enqueue({
|
|
795
|
-
type: "tool-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
toolName: toolCall.function.name,
|
|
799
|
-
argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
|
|
943
|
+
type: "tool-input-delta",
|
|
944
|
+
id: toolCall.id,
|
|
945
|
+
delta: (_u = toolCallDelta.function.arguments) != null ? _u : ""
|
|
800
946
|
});
|
|
801
|
-
if (((
|
|
947
|
+
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)) {
|
|
948
|
+
controller.enqueue({
|
|
949
|
+
type: "tool-input-end",
|
|
950
|
+
id: toolCall.id
|
|
951
|
+
});
|
|
802
952
|
controller.enqueue({
|
|
803
953
|
type: "tool-call",
|
|
804
|
-
|
|
805
|
-
toolCallId: (_l = toolCall.id) != null ? _l : (0, import_provider_utils3.generateId)(),
|
|
954
|
+
toolCallId: (_x = toolCall.id) != null ? _x : (0, import_provider_utils5.generateId)(),
|
|
806
955
|
toolName: toolCall.function.name,
|
|
807
|
-
|
|
956
|
+
input: toolCall.function.arguments
|
|
808
957
|
});
|
|
809
958
|
toolCall.hasFinished = true;
|
|
810
959
|
}
|
|
@@ -812,10 +961,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
812
961
|
}
|
|
813
962
|
},
|
|
814
963
|
flush(controller) {
|
|
964
|
+
if (isActiveText) {
|
|
965
|
+
controller.enqueue({ type: "text-end", id: "0" });
|
|
966
|
+
}
|
|
815
967
|
controller.enqueue({
|
|
816
968
|
type: "finish",
|
|
817
969
|
finishReason,
|
|
818
|
-
logprobs,
|
|
819
970
|
usage,
|
|
820
971
|
...providerMetadata != null ? { providerMetadata } : {}
|
|
821
972
|
});
|
|
@@ -827,96 +978,97 @@ var OpenAIChatLanguageModel = class {
|
|
|
827
978
|
};
|
|
828
979
|
}
|
|
829
980
|
};
|
|
830
|
-
var openaiTokenUsageSchema =
|
|
831
|
-
prompt_tokens:
|
|
832
|
-
completion_tokens:
|
|
833
|
-
|
|
834
|
-
|
|
981
|
+
var openaiTokenUsageSchema = import_v45.z.object({
|
|
982
|
+
prompt_tokens: import_v45.z.number().nullish(),
|
|
983
|
+
completion_tokens: import_v45.z.number().nullish(),
|
|
984
|
+
total_tokens: import_v45.z.number().nullish(),
|
|
985
|
+
prompt_tokens_details: import_v45.z.object({
|
|
986
|
+
cached_tokens: import_v45.z.number().nullish()
|
|
835
987
|
}).nullish(),
|
|
836
|
-
completion_tokens_details:
|
|
837
|
-
reasoning_tokens:
|
|
838
|
-
accepted_prediction_tokens:
|
|
839
|
-
rejected_prediction_tokens:
|
|
988
|
+
completion_tokens_details: import_v45.z.object({
|
|
989
|
+
reasoning_tokens: import_v45.z.number().nullish(),
|
|
990
|
+
accepted_prediction_tokens: import_v45.z.number().nullish(),
|
|
991
|
+
rejected_prediction_tokens: import_v45.z.number().nullish()
|
|
840
992
|
}).nullish()
|
|
841
993
|
}).nullish();
|
|
842
|
-
var openaiChatResponseSchema =
|
|
843
|
-
id:
|
|
844
|
-
created:
|
|
845
|
-
model:
|
|
846
|
-
choices:
|
|
847
|
-
|
|
848
|
-
message:
|
|
849
|
-
role:
|
|
850
|
-
content:
|
|
851
|
-
tool_calls:
|
|
852
|
-
|
|
853
|
-
id:
|
|
854
|
-
type:
|
|
855
|
-
function:
|
|
856
|
-
name:
|
|
857
|
-
arguments:
|
|
994
|
+
var openaiChatResponseSchema = import_v45.z.object({
|
|
995
|
+
id: import_v45.z.string().nullish(),
|
|
996
|
+
created: import_v45.z.number().nullish(),
|
|
997
|
+
model: import_v45.z.string().nullish(),
|
|
998
|
+
choices: import_v45.z.array(
|
|
999
|
+
import_v45.z.object({
|
|
1000
|
+
message: import_v45.z.object({
|
|
1001
|
+
role: import_v45.z.literal("assistant").nullish(),
|
|
1002
|
+
content: import_v45.z.string().nullish(),
|
|
1003
|
+
tool_calls: import_v45.z.array(
|
|
1004
|
+
import_v45.z.object({
|
|
1005
|
+
id: import_v45.z.string().nullish(),
|
|
1006
|
+
type: import_v45.z.literal("function"),
|
|
1007
|
+
function: import_v45.z.object({
|
|
1008
|
+
name: import_v45.z.string(),
|
|
1009
|
+
arguments: import_v45.z.string()
|
|
858
1010
|
})
|
|
859
1011
|
})
|
|
860
1012
|
).nullish()
|
|
861
1013
|
}),
|
|
862
|
-
index:
|
|
863
|
-
logprobs:
|
|
864
|
-
content:
|
|
865
|
-
|
|
866
|
-
token:
|
|
867
|
-
logprob:
|
|
868
|
-
top_logprobs:
|
|
869
|
-
|
|
870
|
-
token:
|
|
871
|
-
logprob:
|
|
1014
|
+
index: import_v45.z.number(),
|
|
1015
|
+
logprobs: import_v45.z.object({
|
|
1016
|
+
content: import_v45.z.array(
|
|
1017
|
+
import_v45.z.object({
|
|
1018
|
+
token: import_v45.z.string(),
|
|
1019
|
+
logprob: import_v45.z.number(),
|
|
1020
|
+
top_logprobs: import_v45.z.array(
|
|
1021
|
+
import_v45.z.object({
|
|
1022
|
+
token: import_v45.z.string(),
|
|
1023
|
+
logprob: import_v45.z.number()
|
|
872
1024
|
})
|
|
873
1025
|
)
|
|
874
1026
|
})
|
|
875
|
-
).
|
|
1027
|
+
).nullish()
|
|
876
1028
|
}).nullish(),
|
|
877
|
-
finish_reason:
|
|
1029
|
+
finish_reason: import_v45.z.string().nullish()
|
|
878
1030
|
})
|
|
879
1031
|
),
|
|
880
1032
|
usage: openaiTokenUsageSchema
|
|
881
1033
|
});
|
|
882
|
-
var openaiChatChunkSchema =
|
|
883
|
-
|
|
884
|
-
id:
|
|
885
|
-
created:
|
|
886
|
-
model:
|
|
887
|
-
choices:
|
|
888
|
-
|
|
889
|
-
delta:
|
|
890
|
-
role:
|
|
891
|
-
content:
|
|
892
|
-
tool_calls:
|
|
893
|
-
|
|
894
|
-
index:
|
|
895
|
-
id:
|
|
896
|
-
type:
|
|
897
|
-
function:
|
|
898
|
-
name:
|
|
899
|
-
arguments:
|
|
1034
|
+
var openaiChatChunkSchema = import_v45.z.union([
|
|
1035
|
+
import_v45.z.object({
|
|
1036
|
+
id: import_v45.z.string().nullish(),
|
|
1037
|
+
created: import_v45.z.number().nullish(),
|
|
1038
|
+
model: import_v45.z.string().nullish(),
|
|
1039
|
+
choices: import_v45.z.array(
|
|
1040
|
+
import_v45.z.object({
|
|
1041
|
+
delta: import_v45.z.object({
|
|
1042
|
+
role: import_v45.z.enum(["assistant"]).nullish(),
|
|
1043
|
+
content: import_v45.z.string().nullish(),
|
|
1044
|
+
tool_calls: import_v45.z.array(
|
|
1045
|
+
import_v45.z.object({
|
|
1046
|
+
index: import_v45.z.number(),
|
|
1047
|
+
id: import_v45.z.string().nullish(),
|
|
1048
|
+
type: import_v45.z.literal("function").nullish(),
|
|
1049
|
+
function: import_v45.z.object({
|
|
1050
|
+
name: import_v45.z.string().nullish(),
|
|
1051
|
+
arguments: import_v45.z.string().nullish()
|
|
900
1052
|
})
|
|
901
1053
|
})
|
|
902
1054
|
).nullish()
|
|
903
1055
|
}).nullish(),
|
|
904
|
-
logprobs:
|
|
905
|
-
content:
|
|
906
|
-
|
|
907
|
-
token:
|
|
908
|
-
logprob:
|
|
909
|
-
top_logprobs:
|
|
910
|
-
|
|
911
|
-
token:
|
|
912
|
-
logprob:
|
|
1056
|
+
logprobs: import_v45.z.object({
|
|
1057
|
+
content: import_v45.z.array(
|
|
1058
|
+
import_v45.z.object({
|
|
1059
|
+
token: import_v45.z.string(),
|
|
1060
|
+
logprob: import_v45.z.number(),
|
|
1061
|
+
top_logprobs: import_v45.z.array(
|
|
1062
|
+
import_v45.z.object({
|
|
1063
|
+
token: import_v45.z.string(),
|
|
1064
|
+
logprob: import_v45.z.number()
|
|
913
1065
|
})
|
|
914
1066
|
)
|
|
915
1067
|
})
|
|
916
|
-
).
|
|
1068
|
+
).nullish()
|
|
917
1069
|
}).nullish(),
|
|
918
|
-
finish_reason:
|
|
919
|
-
index:
|
|
1070
|
+
finish_reason: import_v45.z.string().nullish(),
|
|
1071
|
+
index: import_v45.z.number()
|
|
920
1072
|
})
|
|
921
1073
|
),
|
|
922
1074
|
usage: openaiTokenUsageSchema
|
|
@@ -924,10 +1076,13 @@ var openaiChatChunkSchema = import_zod3.z.union([
|
|
|
924
1076
|
openaiErrorDataSchema
|
|
925
1077
|
]);
|
|
926
1078
|
function isReasoningModel(modelId) {
|
|
927
|
-
return modelId
|
|
1079
|
+
return modelId.startsWith("o");
|
|
928
1080
|
}
|
|
929
|
-
function
|
|
930
|
-
return modelId.startsWith("
|
|
1081
|
+
function supportsFlexProcessing(modelId) {
|
|
1082
|
+
return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
1083
|
+
}
|
|
1084
|
+
function supportsPriorityProcessing(modelId) {
|
|
1085
|
+
return modelId.startsWith("gpt-4") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
931
1086
|
}
|
|
932
1087
|
function getSystemMessageMode(modelId) {
|
|
933
1088
|
var _a, _b;
|
|
@@ -949,29 +1104,37 @@ var reasoningModels = {
|
|
|
949
1104
|
"o1-preview-2024-09-12": {
|
|
950
1105
|
systemMessageMode: "remove"
|
|
951
1106
|
},
|
|
1107
|
+
o3: {
|
|
1108
|
+
systemMessageMode: "developer"
|
|
1109
|
+
},
|
|
1110
|
+
"o3-2025-04-16": {
|
|
1111
|
+
systemMessageMode: "developer"
|
|
1112
|
+
},
|
|
952
1113
|
"o3-mini": {
|
|
953
1114
|
systemMessageMode: "developer"
|
|
954
1115
|
},
|
|
955
1116
|
"o3-mini-2025-01-31": {
|
|
956
1117
|
systemMessageMode: "developer"
|
|
1118
|
+
},
|
|
1119
|
+
"o4-mini": {
|
|
1120
|
+
systemMessageMode: "developer"
|
|
1121
|
+
},
|
|
1122
|
+
"o4-mini-2025-04-16": {
|
|
1123
|
+
systemMessageMode: "developer"
|
|
957
1124
|
}
|
|
958
1125
|
};
|
|
959
1126
|
|
|
960
1127
|
// src/openai-completion-language-model.ts
|
|
961
|
-
var
|
|
962
|
-
var
|
|
1128
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1129
|
+
var import_v47 = require("zod/v4");
|
|
963
1130
|
|
|
964
1131
|
// src/convert-to-openai-completion-prompt.ts
|
|
965
1132
|
var import_provider4 = require("@ai-sdk/provider");
|
|
966
1133
|
function convertToOpenAICompletionPrompt({
|
|
967
1134
|
prompt,
|
|
968
|
-
inputFormat,
|
|
969
1135
|
user = "user",
|
|
970
1136
|
assistant = "assistant"
|
|
971
1137
|
}) {
|
|
972
|
-
if (inputFormat === "prompt" && prompt.length === 1 && prompt[0].role === "user" && prompt[0].content.length === 1 && prompt[0].content[0].type === "text") {
|
|
973
|
-
return { prompt: prompt[0].content[0].text };
|
|
974
|
-
}
|
|
975
1138
|
let text = "";
|
|
976
1139
|
if (prompt[0].role === "system") {
|
|
977
1140
|
text += `${prompt[0].content}
|
|
@@ -1040,34 +1203,66 @@ ${user}:`]
|
|
|
1040
1203
|
};
|
|
1041
1204
|
}
|
|
1042
1205
|
|
|
1043
|
-
// src/
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1206
|
+
// src/openai-completion-options.ts
|
|
1207
|
+
var import_v46 = require("zod/v4");
|
|
1208
|
+
var openaiCompletionProviderOptions = import_v46.z.object({
|
|
1209
|
+
/**
|
|
1210
|
+
Echo back the prompt in addition to the completion.
|
|
1211
|
+
*/
|
|
1212
|
+
echo: import_v46.z.boolean().optional(),
|
|
1213
|
+
/**
|
|
1214
|
+
Modify the likelihood of specified tokens appearing in the completion.
|
|
1215
|
+
|
|
1216
|
+
Accepts a JSON object that maps tokens (specified by their token ID in
|
|
1217
|
+
the GPT tokenizer) to an associated bias value from -100 to 100. You
|
|
1218
|
+
can use this tokenizer tool to convert text to token IDs. Mathematically,
|
|
1219
|
+
the bias is added to the logits generated by the model prior to sampling.
|
|
1220
|
+
The exact effect will vary per model, but values between -1 and 1 should
|
|
1221
|
+
decrease or increase likelihood of selection; values like -100 or 100
|
|
1222
|
+
should result in a ban or exclusive selection of the relevant token.
|
|
1223
|
+
|
|
1224
|
+
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
1225
|
+
token from being generated.
|
|
1226
|
+
*/
|
|
1227
|
+
logitBias: import_v46.z.record(import_v46.z.string(), import_v46.z.number()).optional(),
|
|
1228
|
+
/**
|
|
1229
|
+
The suffix that comes after a completion of inserted text.
|
|
1230
|
+
*/
|
|
1231
|
+
suffix: import_v46.z.string().optional(),
|
|
1232
|
+
/**
|
|
1233
|
+
A unique identifier representing your end-user, which can help OpenAI to
|
|
1234
|
+
monitor and detect abuse. Learn more.
|
|
1235
|
+
*/
|
|
1236
|
+
user: import_v46.z.string().optional(),
|
|
1237
|
+
/**
|
|
1238
|
+
Return the log probabilities of the tokens. Including logprobs will increase
|
|
1239
|
+
the response size and can slow down response times. However, it can
|
|
1240
|
+
be useful to better understand how the model is behaving.
|
|
1241
|
+
Setting to true will return the log probabilities of the tokens that
|
|
1242
|
+
were generated.
|
|
1243
|
+
Setting to a number will return the log probabilities of the top n
|
|
1244
|
+
tokens that were generated.
|
|
1245
|
+
*/
|
|
1246
|
+
logprobs: import_v46.z.union([import_v46.z.boolean(), import_v46.z.number()]).optional()
|
|
1247
|
+
});
|
|
1056
1248
|
|
|
1057
1249
|
// src/openai-completion-language-model.ts
|
|
1058
1250
|
var OpenAICompletionLanguageModel = class {
|
|
1059
|
-
constructor(modelId,
|
|
1251
|
+
constructor(modelId, config) {
|
|
1060
1252
|
this.specificationVersion = "v2";
|
|
1061
|
-
this.
|
|
1253
|
+
this.supportedUrls = {
|
|
1254
|
+
// No URLs are supported for completion models.
|
|
1255
|
+
};
|
|
1062
1256
|
this.modelId = modelId;
|
|
1063
|
-
this.settings = settings;
|
|
1064
1257
|
this.config = config;
|
|
1065
1258
|
}
|
|
1259
|
+
get providerOptionsName() {
|
|
1260
|
+
return this.config.provider.split(".")[0].trim();
|
|
1261
|
+
}
|
|
1066
1262
|
get provider() {
|
|
1067
1263
|
return this.config.provider;
|
|
1068
1264
|
}
|
|
1069
|
-
getArgs({
|
|
1070
|
-
inputFormat,
|
|
1265
|
+
async getArgs({
|
|
1071
1266
|
prompt,
|
|
1072
1267
|
maxOutputTokens,
|
|
1073
1268
|
temperature,
|
|
@@ -1079,9 +1274,22 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1079
1274
|
responseFormat,
|
|
1080
1275
|
tools,
|
|
1081
1276
|
toolChoice,
|
|
1082
|
-
seed
|
|
1277
|
+
seed,
|
|
1278
|
+
providerOptions
|
|
1083
1279
|
}) {
|
|
1084
1280
|
const warnings = [];
|
|
1281
|
+
const openaiOptions = {
|
|
1282
|
+
...await (0, import_provider_utils6.parseProviderOptions)({
|
|
1283
|
+
provider: "openai",
|
|
1284
|
+
providerOptions,
|
|
1285
|
+
schema: openaiCompletionProviderOptions
|
|
1286
|
+
}),
|
|
1287
|
+
...await (0, import_provider_utils6.parseProviderOptions)({
|
|
1288
|
+
provider: this.providerOptionsName,
|
|
1289
|
+
providerOptions,
|
|
1290
|
+
schema: openaiCompletionProviderOptions
|
|
1291
|
+
})
|
|
1292
|
+
};
|
|
1085
1293
|
if (topK != null) {
|
|
1086
1294
|
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
1087
1295
|
}
|
|
@@ -1098,18 +1306,18 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1098
1306
|
details: "JSON response format is not supported."
|
|
1099
1307
|
});
|
|
1100
1308
|
}
|
|
1101
|
-
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt
|
|
1309
|
+
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt });
|
|
1102
1310
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
1103
1311
|
return {
|
|
1104
1312
|
args: {
|
|
1105
1313
|
// model id:
|
|
1106
1314
|
model: this.modelId,
|
|
1107
1315
|
// model specific settings:
|
|
1108
|
-
echo:
|
|
1109
|
-
logit_bias:
|
|
1110
|
-
logprobs:
|
|
1111
|
-
suffix:
|
|
1112
|
-
user:
|
|
1316
|
+
echo: openaiOptions.echo,
|
|
1317
|
+
logit_bias: openaiOptions.logitBias,
|
|
1318
|
+
logprobs: (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? 0 : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === false ? void 0 : openaiOptions == null ? void 0 : openaiOptions.logprobs,
|
|
1319
|
+
suffix: openaiOptions.suffix,
|
|
1320
|
+
user: openaiOptions.user,
|
|
1113
1321
|
// standardized settings:
|
|
1114
1322
|
max_tokens: maxOutputTokens,
|
|
1115
1323
|
temperature,
|
|
@@ -1126,71 +1334,79 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1126
1334
|
};
|
|
1127
1335
|
}
|
|
1128
1336
|
async doGenerate(options) {
|
|
1129
|
-
|
|
1337
|
+
var _a, _b, _c;
|
|
1338
|
+
const { args, warnings } = await this.getArgs(options);
|
|
1130
1339
|
const {
|
|
1131
1340
|
responseHeaders,
|
|
1132
1341
|
value: response,
|
|
1133
1342
|
rawValue: rawResponse
|
|
1134
|
-
} = await (0,
|
|
1343
|
+
} = await (0, import_provider_utils6.postJsonToApi)({
|
|
1135
1344
|
url: this.config.url({
|
|
1136
1345
|
path: "/completions",
|
|
1137
1346
|
modelId: this.modelId
|
|
1138
1347
|
}),
|
|
1139
|
-
headers: (0,
|
|
1348
|
+
headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
|
|
1140
1349
|
body: args,
|
|
1141
1350
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1142
|
-
successfulResponseHandler: (0,
|
|
1351
|
+
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
|
|
1143
1352
|
openaiCompletionResponseSchema
|
|
1144
1353
|
),
|
|
1145
1354
|
abortSignal: options.abortSignal,
|
|
1146
1355
|
fetch: this.config.fetch
|
|
1147
1356
|
});
|
|
1148
1357
|
const choice = response.choices[0];
|
|
1358
|
+
const providerMetadata = { openai: {} };
|
|
1359
|
+
if (choice.logprobs != null) {
|
|
1360
|
+
providerMetadata.openai.logprobs = choice.logprobs;
|
|
1361
|
+
}
|
|
1149
1362
|
return {
|
|
1150
1363
|
content: [{ type: "text", text: choice.text }],
|
|
1151
1364
|
usage: {
|
|
1152
|
-
inputTokens: response.usage.prompt_tokens,
|
|
1153
|
-
outputTokens: response.usage.completion_tokens
|
|
1365
|
+
inputTokens: (_a = response.usage) == null ? void 0 : _a.prompt_tokens,
|
|
1366
|
+
outputTokens: (_b = response.usage) == null ? void 0 : _b.completion_tokens,
|
|
1367
|
+
totalTokens: (_c = response.usage) == null ? void 0 : _c.total_tokens
|
|
1154
1368
|
},
|
|
1155
1369
|
finishReason: mapOpenAIFinishReason(choice.finish_reason),
|
|
1156
|
-
logprobs: mapOpenAICompletionLogProbs(choice.logprobs),
|
|
1157
1370
|
request: { body: args },
|
|
1158
1371
|
response: {
|
|
1159
1372
|
...getResponseMetadata(response),
|
|
1160
1373
|
headers: responseHeaders,
|
|
1161
1374
|
body: rawResponse
|
|
1162
1375
|
},
|
|
1376
|
+
providerMetadata,
|
|
1163
1377
|
warnings
|
|
1164
1378
|
};
|
|
1165
1379
|
}
|
|
1166
1380
|
async doStream(options) {
|
|
1167
|
-
const { args, warnings } = this.getArgs(options);
|
|
1381
|
+
const { args, warnings } = await this.getArgs(options);
|
|
1168
1382
|
const body = {
|
|
1169
1383
|
...args,
|
|
1170
1384
|
stream: true,
|
|
1171
|
-
|
|
1172
|
-
|
|
1385
|
+
stream_options: {
|
|
1386
|
+
include_usage: true
|
|
1387
|
+
}
|
|
1173
1388
|
};
|
|
1174
|
-
const { responseHeaders, value: response } = await (0,
|
|
1389
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({
|
|
1175
1390
|
url: this.config.url({
|
|
1176
1391
|
path: "/completions",
|
|
1177
1392
|
modelId: this.modelId
|
|
1178
1393
|
}),
|
|
1179
|
-
headers: (0,
|
|
1394
|
+
headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
|
|
1180
1395
|
body,
|
|
1181
1396
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1182
|
-
successfulResponseHandler: (0,
|
|
1397
|
+
successfulResponseHandler: (0, import_provider_utils6.createEventSourceResponseHandler)(
|
|
1183
1398
|
openaiCompletionChunkSchema
|
|
1184
1399
|
),
|
|
1185
1400
|
abortSignal: options.abortSignal,
|
|
1186
1401
|
fetch: this.config.fetch
|
|
1187
1402
|
});
|
|
1188
1403
|
let finishReason = "unknown";
|
|
1404
|
+
const providerMetadata = { openai: {} };
|
|
1189
1405
|
const usage = {
|
|
1190
1406
|
inputTokens: void 0,
|
|
1191
|
-
outputTokens: void 0
|
|
1407
|
+
outputTokens: void 0,
|
|
1408
|
+
totalTokens: void 0
|
|
1192
1409
|
};
|
|
1193
|
-
let logprobs;
|
|
1194
1410
|
let isFirstChunk = true;
|
|
1195
1411
|
return {
|
|
1196
1412
|
stream: response.pipeThrough(
|
|
@@ -1199,6 +1415,9 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1199
1415
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1200
1416
|
},
|
|
1201
1417
|
transform(chunk, controller) {
|
|
1418
|
+
if (options.includeRawChunks) {
|
|
1419
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1420
|
+
}
|
|
1202
1421
|
if (!chunk.success) {
|
|
1203
1422
|
finishReason = "error";
|
|
1204
1423
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -1216,34 +1435,36 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1216
1435
|
type: "response-metadata",
|
|
1217
1436
|
...getResponseMetadata(value)
|
|
1218
1437
|
});
|
|
1438
|
+
controller.enqueue({ type: "text-start", id: "0" });
|
|
1219
1439
|
}
|
|
1220
1440
|
if (value.usage != null) {
|
|
1221
1441
|
usage.inputTokens = value.usage.prompt_tokens;
|
|
1222
1442
|
usage.outputTokens = value.usage.completion_tokens;
|
|
1443
|
+
usage.totalTokens = value.usage.total_tokens;
|
|
1223
1444
|
}
|
|
1224
1445
|
const choice = value.choices[0];
|
|
1225
1446
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
1226
1447
|
finishReason = mapOpenAIFinishReason(choice.finish_reason);
|
|
1227
1448
|
}
|
|
1228
|
-
if ((choice == null ? void 0 : choice.
|
|
1449
|
+
if ((choice == null ? void 0 : choice.logprobs) != null) {
|
|
1450
|
+
providerMetadata.openai.logprobs = choice.logprobs;
|
|
1451
|
+
}
|
|
1452
|
+
if ((choice == null ? void 0 : choice.text) != null && choice.text.length > 0) {
|
|
1229
1453
|
controller.enqueue({
|
|
1230
|
-
type: "text",
|
|
1231
|
-
|
|
1454
|
+
type: "text-delta",
|
|
1455
|
+
id: "0",
|
|
1456
|
+
delta: choice.text
|
|
1232
1457
|
});
|
|
1233
1458
|
}
|
|
1234
|
-
const mappedLogprobs = mapOpenAICompletionLogProbs(
|
|
1235
|
-
choice == null ? void 0 : choice.logprobs
|
|
1236
|
-
);
|
|
1237
|
-
if (mappedLogprobs == null ? void 0 : mappedLogprobs.length) {
|
|
1238
|
-
if (logprobs === void 0) logprobs = [];
|
|
1239
|
-
logprobs.push(...mappedLogprobs);
|
|
1240
|
-
}
|
|
1241
1459
|
},
|
|
1242
1460
|
flush(controller) {
|
|
1461
|
+
if (!isFirstChunk) {
|
|
1462
|
+
controller.enqueue({ type: "text-end", id: "0" });
|
|
1463
|
+
}
|
|
1243
1464
|
controller.enqueue({
|
|
1244
1465
|
type: "finish",
|
|
1245
1466
|
finishReason,
|
|
1246
|
-
|
|
1467
|
+
providerMetadata,
|
|
1247
1468
|
usage
|
|
1248
1469
|
});
|
|
1249
1470
|
}
|
|
@@ -1254,78 +1475,89 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1254
1475
|
};
|
|
1255
1476
|
}
|
|
1256
1477
|
};
|
|
1257
|
-
var
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1478
|
+
var usageSchema = import_v47.z.object({
|
|
1479
|
+
prompt_tokens: import_v47.z.number(),
|
|
1480
|
+
completion_tokens: import_v47.z.number(),
|
|
1481
|
+
total_tokens: import_v47.z.number()
|
|
1482
|
+
});
|
|
1483
|
+
var openaiCompletionResponseSchema = import_v47.z.object({
|
|
1484
|
+
id: import_v47.z.string().nullish(),
|
|
1485
|
+
created: import_v47.z.number().nullish(),
|
|
1486
|
+
model: import_v47.z.string().nullish(),
|
|
1487
|
+
choices: import_v47.z.array(
|
|
1488
|
+
import_v47.z.object({
|
|
1489
|
+
text: import_v47.z.string(),
|
|
1490
|
+
finish_reason: import_v47.z.string(),
|
|
1491
|
+
logprobs: import_v47.z.object({
|
|
1492
|
+
tokens: import_v47.z.array(import_v47.z.string()),
|
|
1493
|
+
token_logprobs: import_v47.z.array(import_v47.z.number()),
|
|
1494
|
+
top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullish()
|
|
1269
1495
|
}).nullish()
|
|
1270
1496
|
})
|
|
1271
1497
|
),
|
|
1272
|
-
usage:
|
|
1273
|
-
prompt_tokens: import_zod4.z.number(),
|
|
1274
|
-
completion_tokens: import_zod4.z.number()
|
|
1275
|
-
})
|
|
1498
|
+
usage: usageSchema.nullish()
|
|
1276
1499
|
});
|
|
1277
|
-
var openaiCompletionChunkSchema =
|
|
1278
|
-
|
|
1279
|
-
id:
|
|
1280
|
-
created:
|
|
1281
|
-
model:
|
|
1282
|
-
choices:
|
|
1283
|
-
|
|
1284
|
-
text:
|
|
1285
|
-
finish_reason:
|
|
1286
|
-
index:
|
|
1287
|
-
logprobs:
|
|
1288
|
-
tokens:
|
|
1289
|
-
token_logprobs:
|
|
1290
|
-
top_logprobs:
|
|
1500
|
+
var openaiCompletionChunkSchema = import_v47.z.union([
|
|
1501
|
+
import_v47.z.object({
|
|
1502
|
+
id: import_v47.z.string().nullish(),
|
|
1503
|
+
created: import_v47.z.number().nullish(),
|
|
1504
|
+
model: import_v47.z.string().nullish(),
|
|
1505
|
+
choices: import_v47.z.array(
|
|
1506
|
+
import_v47.z.object({
|
|
1507
|
+
text: import_v47.z.string(),
|
|
1508
|
+
finish_reason: import_v47.z.string().nullish(),
|
|
1509
|
+
index: import_v47.z.number(),
|
|
1510
|
+
logprobs: import_v47.z.object({
|
|
1511
|
+
tokens: import_v47.z.array(import_v47.z.string()),
|
|
1512
|
+
token_logprobs: import_v47.z.array(import_v47.z.number()),
|
|
1513
|
+
top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullish()
|
|
1291
1514
|
}).nullish()
|
|
1292
1515
|
})
|
|
1293
1516
|
),
|
|
1294
|
-
usage:
|
|
1295
|
-
prompt_tokens: import_zod4.z.number(),
|
|
1296
|
-
completion_tokens: import_zod4.z.number()
|
|
1297
|
-
}).nullish()
|
|
1517
|
+
usage: usageSchema.nullish()
|
|
1298
1518
|
}),
|
|
1299
1519
|
openaiErrorDataSchema
|
|
1300
1520
|
]);
|
|
1301
1521
|
|
|
1302
1522
|
// src/openai-embedding-model.ts
|
|
1303
1523
|
var import_provider5 = require("@ai-sdk/provider");
|
|
1304
|
-
var
|
|
1305
|
-
var
|
|
1524
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1525
|
+
var import_v49 = require("zod/v4");
|
|
1526
|
+
|
|
1527
|
+
// src/openai-embedding-options.ts
|
|
1528
|
+
var import_v48 = require("zod/v4");
|
|
1529
|
+
var openaiEmbeddingProviderOptions = import_v48.z.object({
|
|
1530
|
+
/**
|
|
1531
|
+
The number of dimensions the resulting output embeddings should have.
|
|
1532
|
+
Only supported in text-embedding-3 and later models.
|
|
1533
|
+
*/
|
|
1534
|
+
dimensions: import_v48.z.number().optional(),
|
|
1535
|
+
/**
|
|
1536
|
+
A unique identifier representing your end-user, which can help OpenAI to
|
|
1537
|
+
monitor and detect abuse. Learn more.
|
|
1538
|
+
*/
|
|
1539
|
+
user: import_v48.z.string().optional()
|
|
1540
|
+
});
|
|
1541
|
+
|
|
1542
|
+
// src/openai-embedding-model.ts
|
|
1306
1543
|
var OpenAIEmbeddingModel = class {
|
|
1307
|
-
constructor(modelId,
|
|
1544
|
+
constructor(modelId, config) {
|
|
1308
1545
|
this.specificationVersion = "v2";
|
|
1546
|
+
this.maxEmbeddingsPerCall = 2048;
|
|
1547
|
+
this.supportsParallelCalls = true;
|
|
1309
1548
|
this.modelId = modelId;
|
|
1310
|
-
this.settings = settings;
|
|
1311
1549
|
this.config = config;
|
|
1312
1550
|
}
|
|
1313
1551
|
get provider() {
|
|
1314
1552
|
return this.config.provider;
|
|
1315
1553
|
}
|
|
1316
|
-
get maxEmbeddingsPerCall() {
|
|
1317
|
-
var _a;
|
|
1318
|
-
return (_a = this.settings.maxEmbeddingsPerCall) != null ? _a : 2048;
|
|
1319
|
-
}
|
|
1320
|
-
get supportsParallelCalls() {
|
|
1321
|
-
var _a;
|
|
1322
|
-
return (_a = this.settings.supportsParallelCalls) != null ? _a : true;
|
|
1323
|
-
}
|
|
1324
1554
|
async doEmbed({
|
|
1325
1555
|
values,
|
|
1326
1556
|
headers,
|
|
1327
|
-
abortSignal
|
|
1557
|
+
abortSignal,
|
|
1558
|
+
providerOptions
|
|
1328
1559
|
}) {
|
|
1560
|
+
var _a;
|
|
1329
1561
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1330
1562
|
throw new import_provider5.TooManyEmbeddingValuesForCallError({
|
|
1331
1563
|
provider: this.provider,
|
|
@@ -1334,25 +1566,30 @@ var OpenAIEmbeddingModel = class {
|
|
|
1334
1566
|
values
|
|
1335
1567
|
});
|
|
1336
1568
|
}
|
|
1569
|
+
const openaiOptions = (_a = await (0, import_provider_utils7.parseProviderOptions)({
|
|
1570
|
+
provider: "openai",
|
|
1571
|
+
providerOptions,
|
|
1572
|
+
schema: openaiEmbeddingProviderOptions
|
|
1573
|
+
})) != null ? _a : {};
|
|
1337
1574
|
const {
|
|
1338
1575
|
responseHeaders,
|
|
1339
1576
|
value: response,
|
|
1340
1577
|
rawValue
|
|
1341
|
-
} = await (0,
|
|
1578
|
+
} = await (0, import_provider_utils7.postJsonToApi)({
|
|
1342
1579
|
url: this.config.url({
|
|
1343
1580
|
path: "/embeddings",
|
|
1344
1581
|
modelId: this.modelId
|
|
1345
1582
|
}),
|
|
1346
|
-
headers: (0,
|
|
1583
|
+
headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), headers),
|
|
1347
1584
|
body: {
|
|
1348
1585
|
model: this.modelId,
|
|
1349
1586
|
input: values,
|
|
1350
1587
|
encoding_format: "float",
|
|
1351
|
-
dimensions:
|
|
1352
|
-
user:
|
|
1588
|
+
dimensions: openaiOptions.dimensions,
|
|
1589
|
+
user: openaiOptions.user
|
|
1353
1590
|
},
|
|
1354
1591
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1355
|
-
successfulResponseHandler: (0,
|
|
1592
|
+
successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
|
|
1356
1593
|
openaiTextEmbeddingResponseSchema
|
|
1357
1594
|
),
|
|
1358
1595
|
abortSignal,
|
|
@@ -1365,32 +1602,33 @@ var OpenAIEmbeddingModel = class {
|
|
|
1365
1602
|
};
|
|
1366
1603
|
}
|
|
1367
1604
|
};
|
|
1368
|
-
var openaiTextEmbeddingResponseSchema =
|
|
1369
|
-
data:
|
|
1370
|
-
usage:
|
|
1605
|
+
var openaiTextEmbeddingResponseSchema = import_v49.z.object({
|
|
1606
|
+
data: import_v49.z.array(import_v49.z.object({ embedding: import_v49.z.array(import_v49.z.number()) })),
|
|
1607
|
+
usage: import_v49.z.object({ prompt_tokens: import_v49.z.number() }).nullish()
|
|
1371
1608
|
});
|
|
1372
1609
|
|
|
1373
1610
|
// src/openai-image-model.ts
|
|
1374
|
-
var
|
|
1375
|
-
var
|
|
1611
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1612
|
+
var import_v410 = require("zod/v4");
|
|
1376
1613
|
|
|
1377
1614
|
// src/openai-image-settings.ts
|
|
1378
1615
|
var modelMaxImagesPerCall = {
|
|
1379
1616
|
"dall-e-3": 1,
|
|
1380
|
-
"dall-e-2": 10
|
|
1617
|
+
"dall-e-2": 10,
|
|
1618
|
+
"gpt-image-1": 10
|
|
1381
1619
|
};
|
|
1620
|
+
var hasDefaultResponseFormat = /* @__PURE__ */ new Set(["gpt-image-1"]);
|
|
1382
1621
|
|
|
1383
1622
|
// src/openai-image-model.ts
|
|
1384
1623
|
var OpenAIImageModel = class {
|
|
1385
|
-
constructor(modelId,
|
|
1624
|
+
constructor(modelId, config) {
|
|
1386
1625
|
this.modelId = modelId;
|
|
1387
|
-
this.settings = settings;
|
|
1388
1626
|
this.config = config;
|
|
1389
|
-
this.specificationVersion = "
|
|
1627
|
+
this.specificationVersion = "v2";
|
|
1390
1628
|
}
|
|
1391
1629
|
get maxImagesPerCall() {
|
|
1392
|
-
var _a
|
|
1393
|
-
return (
|
|
1630
|
+
var _a;
|
|
1631
|
+
return (_a = modelMaxImagesPerCall[this.modelId]) != null ? _a : 1;
|
|
1394
1632
|
}
|
|
1395
1633
|
get provider() {
|
|
1396
1634
|
return this.config.provider;
|
|
@@ -1418,22 +1656,22 @@ var OpenAIImageModel = class {
|
|
|
1418
1656
|
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
1419
1657
|
}
|
|
1420
1658
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1421
|
-
const { value: response, responseHeaders } = await (0,
|
|
1659
|
+
const { value: response, responseHeaders } = await (0, import_provider_utils8.postJsonToApi)({
|
|
1422
1660
|
url: this.config.url({
|
|
1423
1661
|
path: "/images/generations",
|
|
1424
1662
|
modelId: this.modelId
|
|
1425
1663
|
}),
|
|
1426
|
-
headers: (0,
|
|
1664
|
+
headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), headers),
|
|
1427
1665
|
body: {
|
|
1428
1666
|
model: this.modelId,
|
|
1429
1667
|
prompt,
|
|
1430
1668
|
n,
|
|
1431
1669
|
size,
|
|
1432
1670
|
...(_d = providerOptions.openai) != null ? _d : {},
|
|
1433
|
-
response_format: "b64_json"
|
|
1671
|
+
...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
|
|
1434
1672
|
},
|
|
1435
1673
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1436
|
-
successfulResponseHandler: (0,
|
|
1674
|
+
successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
|
|
1437
1675
|
openaiImageResponseSchema
|
|
1438
1676
|
),
|
|
1439
1677
|
abortSignal,
|
|
@@ -1446,45 +1684,63 @@ var OpenAIImageModel = class {
|
|
|
1446
1684
|
timestamp: currentDate,
|
|
1447
1685
|
modelId: this.modelId,
|
|
1448
1686
|
headers: responseHeaders
|
|
1687
|
+
},
|
|
1688
|
+
providerMetadata: {
|
|
1689
|
+
openai: {
|
|
1690
|
+
images: response.data.map(
|
|
1691
|
+
(item) => item.revised_prompt ? {
|
|
1692
|
+
revisedPrompt: item.revised_prompt
|
|
1693
|
+
} : null
|
|
1694
|
+
)
|
|
1695
|
+
}
|
|
1449
1696
|
}
|
|
1450
1697
|
};
|
|
1451
1698
|
}
|
|
1452
1699
|
};
|
|
1453
|
-
var openaiImageResponseSchema =
|
|
1454
|
-
data:
|
|
1700
|
+
var openaiImageResponseSchema = import_v410.z.object({
|
|
1701
|
+
data: import_v410.z.array(
|
|
1702
|
+
import_v410.z.object({ b64_json: import_v410.z.string(), revised_prompt: import_v410.z.string().optional() })
|
|
1703
|
+
)
|
|
1455
1704
|
});
|
|
1456
1705
|
|
|
1457
1706
|
// src/openai-tools.ts
|
|
1458
|
-
var import_zod7 = require("zod");
|
|
1459
|
-
var WebSearchPreviewParameters = import_zod7.z.object({});
|
|
1460
|
-
function webSearchPreviewTool({
|
|
1461
|
-
searchContextSize,
|
|
1462
|
-
userLocation
|
|
1463
|
-
} = {}) {
|
|
1464
|
-
return {
|
|
1465
|
-
type: "provider-defined",
|
|
1466
|
-
id: "openai.web_search_preview",
|
|
1467
|
-
args: {
|
|
1468
|
-
searchContextSize,
|
|
1469
|
-
userLocation
|
|
1470
|
-
},
|
|
1471
|
-
parameters: WebSearchPreviewParameters
|
|
1472
|
-
};
|
|
1473
|
-
}
|
|
1474
1707
|
var openaiTools = {
|
|
1475
|
-
|
|
1708
|
+
fileSearch,
|
|
1709
|
+
webSearchPreview
|
|
1476
1710
|
};
|
|
1477
1711
|
|
|
1478
1712
|
// src/openai-transcription-model.ts
|
|
1479
|
-
var
|
|
1480
|
-
var
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1713
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1714
|
+
var import_v412 = require("zod/v4");
|
|
1715
|
+
|
|
1716
|
+
// src/openai-transcription-options.ts
|
|
1717
|
+
var import_v411 = require("zod/v4");
|
|
1718
|
+
var openAITranscriptionProviderOptions = import_v411.z.object({
|
|
1719
|
+
/**
|
|
1720
|
+
* Additional information to include in the transcription response.
|
|
1721
|
+
*/
|
|
1722
|
+
include: import_v411.z.array(import_v411.z.string()).optional(),
|
|
1723
|
+
/**
|
|
1724
|
+
* The language of the input audio in ISO-639-1 format.
|
|
1725
|
+
*/
|
|
1726
|
+
language: import_v411.z.string().optional(),
|
|
1727
|
+
/**
|
|
1728
|
+
* An optional text to guide the model's style or continue a previous audio segment.
|
|
1729
|
+
*/
|
|
1730
|
+
prompt: import_v411.z.string().optional(),
|
|
1731
|
+
/**
|
|
1732
|
+
* The sampling temperature, between 0 and 1.
|
|
1733
|
+
* @default 0
|
|
1734
|
+
*/
|
|
1735
|
+
temperature: import_v411.z.number().min(0).max(1).default(0).optional(),
|
|
1736
|
+
/**
|
|
1737
|
+
* The timestamp granularities to populate for this transcription.
|
|
1738
|
+
* @default ['segment']
|
|
1739
|
+
*/
|
|
1740
|
+
timestampGranularities: import_v411.z.array(import_v411.z.enum(["word", "segment"])).default(["segment"]).optional()
|
|
1487
1741
|
});
|
|
1742
|
+
|
|
1743
|
+
// src/openai-transcription-model.ts
|
|
1488
1744
|
var languageMap = {
|
|
1489
1745
|
afrikaans: "af",
|
|
1490
1746
|
arabic: "ar",
|
|
@@ -1548,38 +1804,36 @@ var OpenAITranscriptionModel = class {
|
|
|
1548
1804
|
constructor(modelId, config) {
|
|
1549
1805
|
this.modelId = modelId;
|
|
1550
1806
|
this.config = config;
|
|
1551
|
-
this.specificationVersion = "
|
|
1807
|
+
this.specificationVersion = "v2";
|
|
1552
1808
|
}
|
|
1553
1809
|
get provider() {
|
|
1554
1810
|
return this.config.provider;
|
|
1555
1811
|
}
|
|
1556
|
-
getArgs({
|
|
1812
|
+
async getArgs({
|
|
1557
1813
|
audio,
|
|
1558
1814
|
mediaType,
|
|
1559
1815
|
providerOptions
|
|
1560
1816
|
}) {
|
|
1561
|
-
var _a, _b, _c, _d, _e;
|
|
1562
1817
|
const warnings = [];
|
|
1563
|
-
const openAIOptions = (0,
|
|
1818
|
+
const openAIOptions = await (0, import_provider_utils9.parseProviderOptions)({
|
|
1564
1819
|
provider: "openai",
|
|
1565
1820
|
providerOptions,
|
|
1566
|
-
schema:
|
|
1821
|
+
schema: openAITranscriptionProviderOptions
|
|
1567
1822
|
});
|
|
1568
1823
|
const formData = new FormData();
|
|
1569
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0,
|
|
1824
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils9.convertBase64ToUint8Array)(audio)]);
|
|
1570
1825
|
formData.append("model", this.modelId);
|
|
1571
1826
|
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1572
1827
|
if (openAIOptions) {
|
|
1573
1828
|
const transcriptionModelOptions = {
|
|
1574
|
-
include:
|
|
1575
|
-
language:
|
|
1576
|
-
prompt:
|
|
1577
|
-
temperature:
|
|
1578
|
-
timestamp_granularities:
|
|
1829
|
+
include: openAIOptions.include,
|
|
1830
|
+
language: openAIOptions.language,
|
|
1831
|
+
prompt: openAIOptions.prompt,
|
|
1832
|
+
temperature: openAIOptions.temperature,
|
|
1833
|
+
timestamp_granularities: openAIOptions.timestampGranularities
|
|
1579
1834
|
};
|
|
1580
|
-
for (const key
|
|
1581
|
-
|
|
1582
|
-
if (value !== void 0) {
|
|
1835
|
+
for (const [key, value] of Object.entries(transcriptionModelOptions)) {
|
|
1836
|
+
if (value != null) {
|
|
1583
1837
|
formData.append(key, String(value));
|
|
1584
1838
|
}
|
|
1585
1839
|
}
|
|
@@ -1592,20 +1846,20 @@ var OpenAITranscriptionModel = class {
|
|
|
1592
1846
|
async doGenerate(options) {
|
|
1593
1847
|
var _a, _b, _c, _d, _e, _f;
|
|
1594
1848
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1595
|
-
const { formData, warnings } = this.getArgs(options);
|
|
1849
|
+
const { formData, warnings } = await this.getArgs(options);
|
|
1596
1850
|
const {
|
|
1597
1851
|
value: response,
|
|
1598
1852
|
responseHeaders,
|
|
1599
1853
|
rawValue: rawResponse
|
|
1600
|
-
} = await (0,
|
|
1854
|
+
} = await (0, import_provider_utils9.postFormDataToApi)({
|
|
1601
1855
|
url: this.config.url({
|
|
1602
1856
|
path: "/audio/transcriptions",
|
|
1603
1857
|
modelId: this.modelId
|
|
1604
1858
|
}),
|
|
1605
|
-
headers: (0,
|
|
1859
|
+
headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
|
|
1606
1860
|
formData,
|
|
1607
1861
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1608
|
-
successfulResponseHandler: (0,
|
|
1862
|
+
successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
|
|
1609
1863
|
openaiTranscriptionResponseSchema
|
|
1610
1864
|
),
|
|
1611
1865
|
abortSignal: options.abortSignal,
|
|
@@ -1631,29 +1885,33 @@ var OpenAITranscriptionModel = class {
|
|
|
1631
1885
|
};
|
|
1632
1886
|
}
|
|
1633
1887
|
};
|
|
1634
|
-
var openaiTranscriptionResponseSchema =
|
|
1635
|
-
text:
|
|
1636
|
-
language:
|
|
1637
|
-
duration:
|
|
1638
|
-
words:
|
|
1639
|
-
|
|
1640
|
-
word:
|
|
1641
|
-
start:
|
|
1642
|
-
end:
|
|
1888
|
+
var openaiTranscriptionResponseSchema = import_v412.z.object({
|
|
1889
|
+
text: import_v412.z.string(),
|
|
1890
|
+
language: import_v412.z.string().nullish(),
|
|
1891
|
+
duration: import_v412.z.number().nullish(),
|
|
1892
|
+
words: import_v412.z.array(
|
|
1893
|
+
import_v412.z.object({
|
|
1894
|
+
word: import_v412.z.string(),
|
|
1895
|
+
start: import_v412.z.number(),
|
|
1896
|
+
end: import_v412.z.number()
|
|
1643
1897
|
})
|
|
1644
1898
|
).nullish()
|
|
1645
1899
|
});
|
|
1646
1900
|
|
|
1647
1901
|
// src/responses/openai-responses-language-model.ts
|
|
1648
|
-
var
|
|
1649
|
-
var
|
|
1902
|
+
var import_provider8 = require("@ai-sdk/provider");
|
|
1903
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
1904
|
+
var import_v414 = require("zod/v4");
|
|
1650
1905
|
|
|
1651
1906
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1652
1907
|
var import_provider6 = require("@ai-sdk/provider");
|
|
1653
|
-
|
|
1908
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
1909
|
+
var import_v413 = require("zod/v4");
|
|
1910
|
+
async function convertToOpenAIResponsesMessages({
|
|
1654
1911
|
prompt,
|
|
1655
1912
|
systemMessageMode
|
|
1656
1913
|
}) {
|
|
1914
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1657
1915
|
const messages = [];
|
|
1658
1916
|
const warnings = [];
|
|
1659
1917
|
for (const { role, content } of prompt) {
|
|
@@ -1688,7 +1946,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1688
1946
|
messages.push({
|
|
1689
1947
|
role: "user",
|
|
1690
1948
|
content: content.map((part, index) => {
|
|
1691
|
-
var
|
|
1949
|
+
var _a2, _b2, _c2;
|
|
1692
1950
|
switch (part.type) {
|
|
1693
1951
|
case "text": {
|
|
1694
1952
|
return { type: "input_text", text: part.text };
|
|
@@ -1700,7 +1958,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1700
1958
|
type: "input_image",
|
|
1701
1959
|
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
1702
1960
|
// OpenAI specific extension: image detail
|
|
1703
|
-
detail: (
|
|
1961
|
+
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
|
|
1704
1962
|
};
|
|
1705
1963
|
} else if (part.mediaType === "application/pdf") {
|
|
1706
1964
|
if (part.data instanceof URL) {
|
|
@@ -1710,7 +1968,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1710
1968
|
}
|
|
1711
1969
|
return {
|
|
1712
1970
|
type: "input_file",
|
|
1713
|
-
filename: (
|
|
1971
|
+
filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
|
|
1714
1972
|
file_data: `data:application/pdf;base64,${part.data}`
|
|
1715
1973
|
};
|
|
1716
1974
|
} else {
|
|
@@ -1725,34 +1983,97 @@ function convertToOpenAIResponsesMessages({
|
|
|
1725
1983
|
break;
|
|
1726
1984
|
}
|
|
1727
1985
|
case "assistant": {
|
|
1986
|
+
const reasoningMessages = {};
|
|
1728
1987
|
for (const part of content) {
|
|
1729
1988
|
switch (part.type) {
|
|
1730
1989
|
case "text": {
|
|
1731
1990
|
messages.push({
|
|
1732
1991
|
role: "assistant",
|
|
1733
|
-
content: [{ type: "output_text", text: part.text }]
|
|
1992
|
+
content: [{ type: "output_text", text: part.text }],
|
|
1993
|
+
id: (_c = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId) != null ? _c : void 0
|
|
1734
1994
|
});
|
|
1735
1995
|
break;
|
|
1736
1996
|
}
|
|
1737
1997
|
case "tool-call": {
|
|
1998
|
+
if (part.providerExecuted) {
|
|
1999
|
+
break;
|
|
2000
|
+
}
|
|
1738
2001
|
messages.push({
|
|
1739
2002
|
type: "function_call",
|
|
1740
2003
|
call_id: part.toolCallId,
|
|
1741
2004
|
name: part.toolName,
|
|
1742
|
-
arguments: JSON.stringify(part.
|
|
2005
|
+
arguments: JSON.stringify(part.input),
|
|
2006
|
+
id: (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.openai) == null ? void 0 : _e.itemId) != null ? _f : void 0
|
|
2007
|
+
});
|
|
2008
|
+
break;
|
|
2009
|
+
}
|
|
2010
|
+
case "tool-result": {
|
|
2011
|
+
warnings.push({
|
|
2012
|
+
type: "other",
|
|
2013
|
+
message: `tool result parts in assistant messages are not supported for OpenAI responses`
|
|
1743
2014
|
});
|
|
1744
2015
|
break;
|
|
1745
2016
|
}
|
|
2017
|
+
case "reasoning": {
|
|
2018
|
+
const providerOptions = await (0, import_provider_utils10.parseProviderOptions)({
|
|
2019
|
+
provider: "openai",
|
|
2020
|
+
providerOptions: part.providerOptions,
|
|
2021
|
+
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
2022
|
+
});
|
|
2023
|
+
const reasoningId = providerOptions == null ? void 0 : providerOptions.itemId;
|
|
2024
|
+
if (reasoningId != null) {
|
|
2025
|
+
const existingReasoningMessage = reasoningMessages[reasoningId];
|
|
2026
|
+
const summaryParts = [];
|
|
2027
|
+
if (part.text.length > 0) {
|
|
2028
|
+
summaryParts.push({ type: "summary_text", text: part.text });
|
|
2029
|
+
} else if (existingReasoningMessage !== void 0) {
|
|
2030
|
+
warnings.push({
|
|
2031
|
+
type: "other",
|
|
2032
|
+
message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
2033
|
+
});
|
|
2034
|
+
}
|
|
2035
|
+
if (existingReasoningMessage === void 0) {
|
|
2036
|
+
reasoningMessages[reasoningId] = {
|
|
2037
|
+
type: "reasoning",
|
|
2038
|
+
id: reasoningId,
|
|
2039
|
+
encrypted_content: providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent,
|
|
2040
|
+
summary: summaryParts
|
|
2041
|
+
};
|
|
2042
|
+
messages.push(reasoningMessages[reasoningId]);
|
|
2043
|
+
} else {
|
|
2044
|
+
existingReasoningMessage.summary.push(...summaryParts);
|
|
2045
|
+
}
|
|
2046
|
+
} else {
|
|
2047
|
+
warnings.push({
|
|
2048
|
+
type: "other",
|
|
2049
|
+
message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
break;
|
|
2053
|
+
}
|
|
1746
2054
|
}
|
|
1747
2055
|
}
|
|
1748
2056
|
break;
|
|
1749
2057
|
}
|
|
1750
2058
|
case "tool": {
|
|
1751
2059
|
for (const part of content) {
|
|
2060
|
+
const output = part.output;
|
|
2061
|
+
let contentValue;
|
|
2062
|
+
switch (output.type) {
|
|
2063
|
+
case "text":
|
|
2064
|
+
case "error-text":
|
|
2065
|
+
contentValue = output.value;
|
|
2066
|
+
break;
|
|
2067
|
+
case "content":
|
|
2068
|
+
case "json":
|
|
2069
|
+
case "error-json":
|
|
2070
|
+
contentValue = JSON.stringify(output.value);
|
|
2071
|
+
break;
|
|
2072
|
+
}
|
|
1752
2073
|
messages.push({
|
|
1753
2074
|
type: "function_call_output",
|
|
1754
2075
|
call_id: part.toolCallId,
|
|
1755
|
-
output:
|
|
2076
|
+
output: contentValue
|
|
1756
2077
|
});
|
|
1757
2078
|
}
|
|
1758
2079
|
break;
|
|
@@ -1765,6 +2086,10 @@ function convertToOpenAIResponsesMessages({
|
|
|
1765
2086
|
}
|
|
1766
2087
|
return { messages, warnings };
|
|
1767
2088
|
}
|
|
2089
|
+
var openaiResponsesReasoningProviderOptionsSchema = import_v413.z.object({
|
|
2090
|
+
itemId: import_v413.z.string().nullish(),
|
|
2091
|
+
reasoningEncryptedContent: import_v413.z.string().nullish()
|
|
2092
|
+
});
|
|
1768
2093
|
|
|
1769
2094
|
// src/responses/map-openai-responses-finish-reason.ts
|
|
1770
2095
|
function mapOpenAIResponseFinishReason({
|
|
@@ -1789,7 +2114,7 @@ var import_provider7 = require("@ai-sdk/provider");
|
|
|
1789
2114
|
function prepareResponsesTools({
|
|
1790
2115
|
tools,
|
|
1791
2116
|
toolChoice,
|
|
1792
|
-
|
|
2117
|
+
strictJsonSchema
|
|
1793
2118
|
}) {
|
|
1794
2119
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1795
2120
|
const toolWarnings = [];
|
|
@@ -1804,12 +2129,23 @@ function prepareResponsesTools({
|
|
|
1804
2129
|
type: "function",
|
|
1805
2130
|
name: tool.name,
|
|
1806
2131
|
description: tool.description,
|
|
1807
|
-
parameters: tool.
|
|
1808
|
-
strict:
|
|
2132
|
+
parameters: tool.inputSchema,
|
|
2133
|
+
strict: strictJsonSchema
|
|
1809
2134
|
});
|
|
1810
2135
|
break;
|
|
1811
2136
|
case "provider-defined":
|
|
1812
2137
|
switch (tool.id) {
|
|
2138
|
+
case "openai.file_search": {
|
|
2139
|
+
const args = fileSearchArgsSchema.parse(tool.args);
|
|
2140
|
+
openaiTools2.push({
|
|
2141
|
+
type: "file_search",
|
|
2142
|
+
vector_store_ids: args.vectorStoreIds,
|
|
2143
|
+
max_num_results: args.maxNumResults,
|
|
2144
|
+
ranking_options: args.ranking ? { ranker: args.ranking.ranker } : void 0,
|
|
2145
|
+
filters: args.filters
|
|
2146
|
+
});
|
|
2147
|
+
break;
|
|
2148
|
+
}
|
|
1813
2149
|
case "openai.web_search_preview":
|
|
1814
2150
|
openaiTools2.push({
|
|
1815
2151
|
type: "web_search_preview",
|
|
@@ -1839,7 +2175,7 @@ function prepareResponsesTools({
|
|
|
1839
2175
|
case "tool":
|
|
1840
2176
|
return {
|
|
1841
2177
|
tools: openaiTools2,
|
|
1842
|
-
toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
2178
|
+
toolChoice: toolChoice.toolName === "file_search" ? { type: "file_search" } : toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
1843
2179
|
toolWarnings
|
|
1844
2180
|
};
|
|
1845
2181
|
default: {
|
|
@@ -1855,14 +2191,16 @@ function prepareResponsesTools({
|
|
|
1855
2191
|
var OpenAIResponsesLanguageModel = class {
|
|
1856
2192
|
constructor(modelId, config) {
|
|
1857
2193
|
this.specificationVersion = "v2";
|
|
1858
|
-
this.
|
|
2194
|
+
this.supportedUrls = {
|
|
2195
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
2196
|
+
};
|
|
1859
2197
|
this.modelId = modelId;
|
|
1860
2198
|
this.config = config;
|
|
1861
2199
|
}
|
|
1862
2200
|
get provider() {
|
|
1863
2201
|
return this.config.provider;
|
|
1864
2202
|
}
|
|
1865
|
-
getArgs({
|
|
2203
|
+
async getArgs({
|
|
1866
2204
|
maxOutputTokens,
|
|
1867
2205
|
temperature,
|
|
1868
2206
|
stopSequences,
|
|
@@ -1901,17 +2239,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1901
2239
|
if (stopSequences != null) {
|
|
1902
2240
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
1903
2241
|
}
|
|
1904
|
-
const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
|
|
2242
|
+
const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
|
|
1905
2243
|
prompt,
|
|
1906
2244
|
systemMessageMode: modelConfig.systemMessageMode
|
|
1907
2245
|
});
|
|
1908
2246
|
warnings.push(...messageWarnings);
|
|
1909
|
-
const openaiOptions = (0,
|
|
2247
|
+
const openaiOptions = await (0, import_provider_utils11.parseProviderOptions)({
|
|
1910
2248
|
provider: "openai",
|
|
1911
2249
|
providerOptions,
|
|
1912
2250
|
schema: openaiResponsesProviderOptionsSchema
|
|
1913
2251
|
});
|
|
1914
|
-
const
|
|
2252
|
+
const strictJsonSchema = (_a = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _a : false;
|
|
1915
2253
|
const baseArgs = {
|
|
1916
2254
|
model: this.modelId,
|
|
1917
2255
|
input: messages,
|
|
@@ -1922,7 +2260,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1922
2260
|
text: {
|
|
1923
2261
|
format: responseFormat.schema != null ? {
|
|
1924
2262
|
type: "json_schema",
|
|
1925
|
-
strict:
|
|
2263
|
+
strict: strictJsonSchema,
|
|
1926
2264
|
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
1927
2265
|
description: responseFormat.description,
|
|
1928
2266
|
schema: responseFormat.schema
|
|
@@ -1936,9 +2274,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1936
2274
|
store: openaiOptions == null ? void 0 : openaiOptions.store,
|
|
1937
2275
|
user: openaiOptions == null ? void 0 : openaiOptions.user,
|
|
1938
2276
|
instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
|
|
2277
|
+
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
2278
|
+
include: openaiOptions == null ? void 0 : openaiOptions.include,
|
|
1939
2279
|
// model-specific settings:
|
|
1940
|
-
...modelConfig.isReasoningModel && (openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
|
|
1941
|
-
reasoning: {
|
|
2280
|
+
...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
2281
|
+
reasoning: {
|
|
2282
|
+
...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
|
|
2283
|
+
effort: openaiOptions.reasoningEffort
|
|
2284
|
+
},
|
|
2285
|
+
...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
|
|
2286
|
+
summary: openaiOptions.reasoningSummary
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
1942
2289
|
},
|
|
1943
2290
|
...modelConfig.requiredAutoTruncation && {
|
|
1944
2291
|
truncation: "auto"
|
|
@@ -1961,6 +2308,37 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1961
2308
|
details: "topP is not supported for reasoning models"
|
|
1962
2309
|
});
|
|
1963
2310
|
}
|
|
2311
|
+
} else {
|
|
2312
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
|
|
2313
|
+
warnings.push({
|
|
2314
|
+
type: "unsupported-setting",
|
|
2315
|
+
setting: "reasoningEffort",
|
|
2316
|
+
details: "reasoningEffort is not supported for non-reasoning models"
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2319
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) {
|
|
2320
|
+
warnings.push({
|
|
2321
|
+
type: "unsupported-setting",
|
|
2322
|
+
setting: "reasoningSummary",
|
|
2323
|
+
details: "reasoningSummary is not supported for non-reasoning models"
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
|
|
2328
|
+
warnings.push({
|
|
2329
|
+
type: "unsupported-setting",
|
|
2330
|
+
setting: "serviceTier",
|
|
2331
|
+
details: "flex processing is only available for o3 and o4-mini models"
|
|
2332
|
+
});
|
|
2333
|
+
delete baseArgs.service_tier;
|
|
2334
|
+
}
|
|
2335
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "priority" && !supportsPriorityProcessing2(this.modelId)) {
|
|
2336
|
+
warnings.push({
|
|
2337
|
+
type: "unsupported-setting",
|
|
2338
|
+
setting: "serviceTier",
|
|
2339
|
+
details: "priority processing is only available for supported models (GPT-4, o3, o4-mini) and requires Enterprise access"
|
|
2340
|
+
});
|
|
2341
|
+
delete baseArgs.service_tier;
|
|
1964
2342
|
}
|
|
1965
2343
|
const {
|
|
1966
2344
|
tools: openaiTools2,
|
|
@@ -1969,7 +2347,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1969
2347
|
} = prepareResponsesTools({
|
|
1970
2348
|
tools,
|
|
1971
2349
|
toolChoice,
|
|
1972
|
-
|
|
2350
|
+
strictJsonSchema
|
|
1973
2351
|
});
|
|
1974
2352
|
return {
|
|
1975
2353
|
args: {
|
|
@@ -1981,84 +2359,137 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1981
2359
|
};
|
|
1982
2360
|
}
|
|
1983
2361
|
async doGenerate(options) {
|
|
1984
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1985
|
-
const { args: body, warnings } = this.getArgs(options);
|
|
2362
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2363
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
2364
|
+
const url = this.config.url({
|
|
2365
|
+
path: "/responses",
|
|
2366
|
+
modelId: this.modelId
|
|
2367
|
+
});
|
|
1986
2368
|
const {
|
|
1987
2369
|
responseHeaders,
|
|
1988
2370
|
value: response,
|
|
1989
2371
|
rawValue: rawResponse
|
|
1990
|
-
} = await (0,
|
|
1991
|
-
url
|
|
1992
|
-
|
|
1993
|
-
modelId: this.modelId
|
|
1994
|
-
}),
|
|
1995
|
-
headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
|
|
2372
|
+
} = await (0, import_provider_utils11.postJsonToApi)({
|
|
2373
|
+
url,
|
|
2374
|
+
headers: (0, import_provider_utils11.combineHeaders)(this.config.headers(), options.headers),
|
|
1996
2375
|
body,
|
|
1997
2376
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1998
|
-
successfulResponseHandler: (0,
|
|
1999
|
-
|
|
2000
|
-
id:
|
|
2001
|
-
created_at:
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2377
|
+
successfulResponseHandler: (0, import_provider_utils11.createJsonResponseHandler)(
|
|
2378
|
+
import_v414.z.object({
|
|
2379
|
+
id: import_v414.z.string(),
|
|
2380
|
+
created_at: import_v414.z.number(),
|
|
2381
|
+
error: import_v414.z.object({
|
|
2382
|
+
code: import_v414.z.string(),
|
|
2383
|
+
message: import_v414.z.string()
|
|
2384
|
+
}).nullish(),
|
|
2385
|
+
model: import_v414.z.string(),
|
|
2386
|
+
output: import_v414.z.array(
|
|
2387
|
+
import_v414.z.discriminatedUnion("type", [
|
|
2388
|
+
import_v414.z.object({
|
|
2389
|
+
type: import_v414.z.literal("message"),
|
|
2390
|
+
role: import_v414.z.literal("assistant"),
|
|
2391
|
+
id: import_v414.z.string(),
|
|
2392
|
+
content: import_v414.z.array(
|
|
2393
|
+
import_v414.z.object({
|
|
2394
|
+
type: import_v414.z.literal("output_text"),
|
|
2395
|
+
text: import_v414.z.string(),
|
|
2396
|
+
annotations: import_v414.z.array(
|
|
2397
|
+
import_v414.z.object({
|
|
2398
|
+
type: import_v414.z.literal("url_citation"),
|
|
2399
|
+
start_index: import_v414.z.number(),
|
|
2400
|
+
end_index: import_v414.z.number(),
|
|
2401
|
+
url: import_v414.z.string(),
|
|
2402
|
+
title: import_v414.z.string()
|
|
2019
2403
|
})
|
|
2020
2404
|
)
|
|
2021
2405
|
})
|
|
2022
2406
|
)
|
|
2023
2407
|
}),
|
|
2024
|
-
|
|
2025
|
-
type:
|
|
2026
|
-
call_id:
|
|
2027
|
-
name:
|
|
2028
|
-
arguments:
|
|
2408
|
+
import_v414.z.object({
|
|
2409
|
+
type: import_v414.z.literal("function_call"),
|
|
2410
|
+
call_id: import_v414.z.string(),
|
|
2411
|
+
name: import_v414.z.string(),
|
|
2412
|
+
arguments: import_v414.z.string(),
|
|
2413
|
+
id: import_v414.z.string()
|
|
2029
2414
|
}),
|
|
2030
|
-
|
|
2031
|
-
type:
|
|
2415
|
+
import_v414.z.object({
|
|
2416
|
+
type: import_v414.z.literal("web_search_call"),
|
|
2417
|
+
id: import_v414.z.string(),
|
|
2418
|
+
status: import_v414.z.string().optional()
|
|
2032
2419
|
}),
|
|
2033
|
-
|
|
2034
|
-
type:
|
|
2420
|
+
import_v414.z.object({
|
|
2421
|
+
type: import_v414.z.literal("computer_call"),
|
|
2422
|
+
id: import_v414.z.string(),
|
|
2423
|
+
status: import_v414.z.string().optional()
|
|
2035
2424
|
}),
|
|
2036
|
-
|
|
2037
|
-
type:
|
|
2425
|
+
import_v414.z.object({
|
|
2426
|
+
type: import_v414.z.literal("reasoning"),
|
|
2427
|
+
id: import_v414.z.string(),
|
|
2428
|
+
encrypted_content: import_v414.z.string().nullish(),
|
|
2429
|
+
summary: import_v414.z.array(
|
|
2430
|
+
import_v414.z.object({
|
|
2431
|
+
type: import_v414.z.literal("summary_text"),
|
|
2432
|
+
text: import_v414.z.string()
|
|
2433
|
+
})
|
|
2434
|
+
)
|
|
2038
2435
|
})
|
|
2039
2436
|
])
|
|
2040
2437
|
),
|
|
2041
|
-
incomplete_details:
|
|
2042
|
-
usage:
|
|
2438
|
+
incomplete_details: import_v414.z.object({ reason: import_v414.z.string() }).nullable(),
|
|
2439
|
+
usage: usageSchema2
|
|
2043
2440
|
})
|
|
2044
2441
|
),
|
|
2045
2442
|
abortSignal: options.abortSignal,
|
|
2046
2443
|
fetch: this.config.fetch
|
|
2047
2444
|
});
|
|
2445
|
+
if (response.error) {
|
|
2446
|
+
throw new import_provider8.APICallError({
|
|
2447
|
+
message: response.error.message,
|
|
2448
|
+
url,
|
|
2449
|
+
requestBodyValues: body,
|
|
2450
|
+
statusCode: 400,
|
|
2451
|
+
responseHeaders,
|
|
2452
|
+
responseBody: rawResponse,
|
|
2453
|
+
isRetryable: false
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2048
2456
|
const content = [];
|
|
2049
2457
|
for (const part of response.output) {
|
|
2050
2458
|
switch (part.type) {
|
|
2459
|
+
case "reasoning": {
|
|
2460
|
+
if (part.summary.length === 0) {
|
|
2461
|
+
part.summary.push({ type: "summary_text", text: "" });
|
|
2462
|
+
}
|
|
2463
|
+
for (const summary of part.summary) {
|
|
2464
|
+
content.push({
|
|
2465
|
+
type: "reasoning",
|
|
2466
|
+
text: summary.text,
|
|
2467
|
+
providerMetadata: {
|
|
2468
|
+
openai: {
|
|
2469
|
+
itemId: part.id,
|
|
2470
|
+
reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
break;
|
|
2476
|
+
}
|
|
2051
2477
|
case "message": {
|
|
2052
2478
|
for (const contentPart of part.content) {
|
|
2053
2479
|
content.push({
|
|
2054
2480
|
type: "text",
|
|
2055
|
-
text: contentPart.text
|
|
2481
|
+
text: contentPart.text,
|
|
2482
|
+
providerMetadata: {
|
|
2483
|
+
openai: {
|
|
2484
|
+
itemId: part.id
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2056
2487
|
});
|
|
2057
2488
|
for (const annotation of contentPart.annotations) {
|
|
2058
2489
|
content.push({
|
|
2059
2490
|
type: "source",
|
|
2060
2491
|
sourceType: "url",
|
|
2061
|
-
id: (
|
|
2492
|
+
id: (_d = (_c = (_b = this.config).generateId) == null ? void 0 : _c.call(_b)) != null ? _d : (0, import_provider_utils11.generateId)(),
|
|
2062
2493
|
url: annotation.url,
|
|
2063
2494
|
title: annotation.title
|
|
2064
2495
|
});
|
|
@@ -2069,10 +2500,51 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2069
2500
|
case "function_call": {
|
|
2070
2501
|
content.push({
|
|
2071
2502
|
type: "tool-call",
|
|
2072
|
-
toolCallType: "function",
|
|
2073
2503
|
toolCallId: part.call_id,
|
|
2074
2504
|
toolName: part.name,
|
|
2075
|
-
|
|
2505
|
+
input: part.arguments,
|
|
2506
|
+
providerMetadata: {
|
|
2507
|
+
openai: {
|
|
2508
|
+
itemId: part.id
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
});
|
|
2512
|
+
break;
|
|
2513
|
+
}
|
|
2514
|
+
case "web_search_call": {
|
|
2515
|
+
content.push({
|
|
2516
|
+
type: "tool-call",
|
|
2517
|
+
toolCallId: part.id,
|
|
2518
|
+
toolName: "web_search_preview",
|
|
2519
|
+
input: "",
|
|
2520
|
+
providerExecuted: true
|
|
2521
|
+
});
|
|
2522
|
+
content.push({
|
|
2523
|
+
type: "tool-result",
|
|
2524
|
+
toolCallId: part.id,
|
|
2525
|
+
toolName: "web_search_preview",
|
|
2526
|
+
result: { status: part.status || "completed" },
|
|
2527
|
+
providerExecuted: true
|
|
2528
|
+
});
|
|
2529
|
+
break;
|
|
2530
|
+
}
|
|
2531
|
+
case "computer_call": {
|
|
2532
|
+
content.push({
|
|
2533
|
+
type: "tool-call",
|
|
2534
|
+
toolCallId: part.id,
|
|
2535
|
+
toolName: "computer_use",
|
|
2536
|
+
input: "",
|
|
2537
|
+
providerExecuted: true
|
|
2538
|
+
});
|
|
2539
|
+
content.push({
|
|
2540
|
+
type: "tool-result",
|
|
2541
|
+
toolCallId: part.id,
|
|
2542
|
+
toolName: "computer_use",
|
|
2543
|
+
result: {
|
|
2544
|
+
type: "computer_use_tool_result",
|
|
2545
|
+
status: part.status || "completed"
|
|
2546
|
+
},
|
|
2547
|
+
providerExecuted: true
|
|
2076
2548
|
});
|
|
2077
2549
|
break;
|
|
2078
2550
|
}
|
|
@@ -2081,12 +2553,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2081
2553
|
return {
|
|
2082
2554
|
content,
|
|
2083
2555
|
finishReason: mapOpenAIResponseFinishReason({
|
|
2084
|
-
finishReason: (
|
|
2556
|
+
finishReason: (_e = response.incomplete_details) == null ? void 0 : _e.reason,
|
|
2085
2557
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
2086
2558
|
}),
|
|
2087
2559
|
usage: {
|
|
2088
2560
|
inputTokens: response.usage.input_tokens,
|
|
2089
|
-
outputTokens: response.usage.output_tokens
|
|
2561
|
+
outputTokens: response.usage.output_tokens,
|
|
2562
|
+
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
2563
|
+
reasoningTokens: (_g = (_f = response.usage.output_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0,
|
|
2564
|
+
cachedInputTokens: (_i = (_h = response.usage.input_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : void 0
|
|
2090
2565
|
},
|
|
2091
2566
|
request: { body },
|
|
2092
2567
|
response: {
|
|
@@ -2098,28 +2573,26 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2098
2573
|
},
|
|
2099
2574
|
providerMetadata: {
|
|
2100
2575
|
openai: {
|
|
2101
|
-
responseId: response.id
|
|
2102
|
-
cachedPromptTokens: (_f = (_e = response.usage.input_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : null,
|
|
2103
|
-
reasoningTokens: (_h = (_g = response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : null
|
|
2576
|
+
responseId: response.id
|
|
2104
2577
|
}
|
|
2105
2578
|
},
|
|
2106
2579
|
warnings
|
|
2107
2580
|
};
|
|
2108
2581
|
}
|
|
2109
2582
|
async doStream(options) {
|
|
2110
|
-
const { args: body, warnings } = this.getArgs(options);
|
|
2111
|
-
const { responseHeaders, value: response } = await (0,
|
|
2583
|
+
const { args: body, warnings } = await this.getArgs(options);
|
|
2584
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({
|
|
2112
2585
|
url: this.config.url({
|
|
2113
2586
|
path: "/responses",
|
|
2114
2587
|
modelId: this.modelId
|
|
2115
2588
|
}),
|
|
2116
|
-
headers: (0,
|
|
2589
|
+
headers: (0, import_provider_utils11.combineHeaders)(this.config.headers(), options.headers),
|
|
2117
2590
|
body: {
|
|
2118
2591
|
...body,
|
|
2119
2592
|
stream: true
|
|
2120
2593
|
},
|
|
2121
2594
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2122
|
-
successfulResponseHandler: (0,
|
|
2595
|
+
successfulResponseHandler: (0, import_provider_utils11.createEventSourceResponseHandler)(
|
|
2123
2596
|
openaiResponsesChunkSchema
|
|
2124
2597
|
),
|
|
2125
2598
|
abortSignal: options.abortSignal,
|
|
@@ -2129,13 +2602,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2129
2602
|
let finishReason = "unknown";
|
|
2130
2603
|
const usage = {
|
|
2131
2604
|
inputTokens: void 0,
|
|
2132
|
-
outputTokens: void 0
|
|
2605
|
+
outputTokens: void 0,
|
|
2606
|
+
totalTokens: void 0
|
|
2133
2607
|
};
|
|
2134
|
-
let cachedPromptTokens = null;
|
|
2135
|
-
let reasoningTokens = null;
|
|
2136
2608
|
let responseId = null;
|
|
2137
2609
|
const ongoingToolCalls = {};
|
|
2138
2610
|
let hasToolCalls = false;
|
|
2611
|
+
const activeReasoning = {};
|
|
2139
2612
|
return {
|
|
2140
2613
|
stream: response.pipeThrough(
|
|
2141
2614
|
new TransformStream({
|
|
@@ -2143,7 +2616,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2143
2616
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2144
2617
|
},
|
|
2145
2618
|
transform(chunk, controller) {
|
|
2146
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2619
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2620
|
+
if (options.includeRawChunks) {
|
|
2621
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2622
|
+
}
|
|
2147
2623
|
if (!chunk.success) {
|
|
2148
2624
|
finishReason = "error";
|
|
2149
2625
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2157,22 +2633,151 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2157
2633
|
toolCallId: value.item.call_id
|
|
2158
2634
|
};
|
|
2159
2635
|
controller.enqueue({
|
|
2160
|
-
type: "tool-
|
|
2161
|
-
|
|
2636
|
+
type: "tool-input-start",
|
|
2637
|
+
id: value.item.call_id,
|
|
2638
|
+
toolName: value.item.name
|
|
2639
|
+
});
|
|
2640
|
+
} else if (value.item.type === "web_search_call") {
|
|
2641
|
+
ongoingToolCalls[value.output_index] = {
|
|
2642
|
+
toolName: "web_search_preview",
|
|
2643
|
+
toolCallId: value.item.id
|
|
2644
|
+
};
|
|
2645
|
+
controller.enqueue({
|
|
2646
|
+
type: "tool-input-start",
|
|
2647
|
+
id: value.item.id,
|
|
2648
|
+
toolName: "web_search_preview"
|
|
2649
|
+
});
|
|
2650
|
+
} else if (value.item.type === "computer_call") {
|
|
2651
|
+
ongoingToolCalls[value.output_index] = {
|
|
2652
|
+
toolName: "computer_use",
|
|
2653
|
+
toolCallId: value.item.id
|
|
2654
|
+
};
|
|
2655
|
+
controller.enqueue({
|
|
2656
|
+
type: "tool-input-start",
|
|
2657
|
+
id: value.item.id,
|
|
2658
|
+
toolName: "computer_use"
|
|
2659
|
+
});
|
|
2660
|
+
} else if (value.item.type === "message") {
|
|
2661
|
+
controller.enqueue({
|
|
2662
|
+
type: "text-start",
|
|
2663
|
+
id: value.item.id,
|
|
2664
|
+
providerMetadata: {
|
|
2665
|
+
openai: {
|
|
2666
|
+
itemId: value.item.id
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
});
|
|
2670
|
+
} else if (isResponseOutputItemAddedReasoningChunk(value)) {
|
|
2671
|
+
activeReasoning[value.item.id] = {
|
|
2672
|
+
encryptedContent: value.item.encrypted_content,
|
|
2673
|
+
summaryParts: [0]
|
|
2674
|
+
};
|
|
2675
|
+
controller.enqueue({
|
|
2676
|
+
type: "reasoning-start",
|
|
2677
|
+
id: `${value.item.id}:0`,
|
|
2678
|
+
providerMetadata: {
|
|
2679
|
+
openai: {
|
|
2680
|
+
itemId: value.item.id,
|
|
2681
|
+
reasoningEncryptedContent: (_a = value.item.encrypted_content) != null ? _a : null
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
2687
|
+
if (value.item.type === "function_call") {
|
|
2688
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2689
|
+
hasToolCalls = true;
|
|
2690
|
+
controller.enqueue({
|
|
2691
|
+
type: "tool-input-end",
|
|
2692
|
+
id: value.item.call_id
|
|
2693
|
+
});
|
|
2694
|
+
controller.enqueue({
|
|
2695
|
+
type: "tool-call",
|
|
2162
2696
|
toolCallId: value.item.call_id,
|
|
2163
2697
|
toolName: value.item.name,
|
|
2164
|
-
|
|
2698
|
+
input: value.item.arguments,
|
|
2699
|
+
providerMetadata: {
|
|
2700
|
+
openai: {
|
|
2701
|
+
itemId: value.item.id
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
});
|
|
2705
|
+
} else if (value.item.type === "web_search_call") {
|
|
2706
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2707
|
+
hasToolCalls = true;
|
|
2708
|
+
controller.enqueue({
|
|
2709
|
+
type: "tool-input-end",
|
|
2710
|
+
id: value.item.id
|
|
2711
|
+
});
|
|
2712
|
+
controller.enqueue({
|
|
2713
|
+
type: "tool-call",
|
|
2714
|
+
toolCallId: value.item.id,
|
|
2715
|
+
toolName: "web_search_preview",
|
|
2716
|
+
input: "",
|
|
2717
|
+
providerExecuted: true
|
|
2718
|
+
});
|
|
2719
|
+
controller.enqueue({
|
|
2720
|
+
type: "tool-result",
|
|
2721
|
+
toolCallId: value.item.id,
|
|
2722
|
+
toolName: "web_search_preview",
|
|
2723
|
+
result: {
|
|
2724
|
+
type: "web_search_tool_result",
|
|
2725
|
+
status: value.item.status || "completed"
|
|
2726
|
+
},
|
|
2727
|
+
providerExecuted: true
|
|
2728
|
+
});
|
|
2729
|
+
} else if (value.item.type === "computer_call") {
|
|
2730
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2731
|
+
hasToolCalls = true;
|
|
2732
|
+
controller.enqueue({
|
|
2733
|
+
type: "tool-input-end",
|
|
2734
|
+
id: value.item.id
|
|
2735
|
+
});
|
|
2736
|
+
controller.enqueue({
|
|
2737
|
+
type: "tool-call",
|
|
2738
|
+
toolCallId: value.item.id,
|
|
2739
|
+
toolName: "computer_use",
|
|
2740
|
+
input: "",
|
|
2741
|
+
providerExecuted: true
|
|
2742
|
+
});
|
|
2743
|
+
controller.enqueue({
|
|
2744
|
+
type: "tool-result",
|
|
2745
|
+
toolCallId: value.item.id,
|
|
2746
|
+
toolName: "computer_use",
|
|
2747
|
+
result: {
|
|
2748
|
+
type: "computer_use_tool_result",
|
|
2749
|
+
status: value.item.status || "completed"
|
|
2750
|
+
},
|
|
2751
|
+
providerExecuted: true
|
|
2752
|
+
});
|
|
2753
|
+
} else if (value.item.type === "message") {
|
|
2754
|
+
controller.enqueue({
|
|
2755
|
+
type: "text-end",
|
|
2756
|
+
id: value.item.id
|
|
2165
2757
|
});
|
|
2758
|
+
} else if (isResponseOutputItemDoneReasoningChunk(value)) {
|
|
2759
|
+
const activeReasoningPart = activeReasoning[value.item.id];
|
|
2760
|
+
for (const summaryIndex of activeReasoningPart.summaryParts) {
|
|
2761
|
+
controller.enqueue({
|
|
2762
|
+
type: "reasoning-end",
|
|
2763
|
+
id: `${value.item.id}:${summaryIndex}`,
|
|
2764
|
+
providerMetadata: {
|
|
2765
|
+
openai: {
|
|
2766
|
+
itemId: value.item.id,
|
|
2767
|
+
reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
});
|
|
2771
|
+
}
|
|
2772
|
+
delete activeReasoning[value.item.id];
|
|
2166
2773
|
}
|
|
2167
2774
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
2168
2775
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
2169
2776
|
if (toolCall != null) {
|
|
2170
2777
|
controller.enqueue({
|
|
2171
|
-
type: "tool-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
toolName: toolCall.toolName,
|
|
2175
|
-
argsTextDelta: value.delta
|
|
2778
|
+
type: "tool-input-delta",
|
|
2779
|
+
id: toolCall.toolCallId,
|
|
2780
|
+
delta: value.delta
|
|
2176
2781
|
});
|
|
2177
2782
|
}
|
|
2178
2783
|
} else if (isResponseCreatedChunk(value)) {
|
|
@@ -2185,36 +2790,57 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2185
2790
|
});
|
|
2186
2791
|
} else if (isTextDeltaChunk(value)) {
|
|
2187
2792
|
controller.enqueue({
|
|
2188
|
-
type: "text",
|
|
2189
|
-
|
|
2793
|
+
type: "text-delta",
|
|
2794
|
+
id: value.item_id,
|
|
2795
|
+
delta: value.delta
|
|
2190
2796
|
});
|
|
2191
|
-
} else if (
|
|
2192
|
-
|
|
2193
|
-
|
|
2797
|
+
} else if (isResponseReasoningSummaryPartAddedChunk(value)) {
|
|
2798
|
+
if (value.summary_index > 0) {
|
|
2799
|
+
(_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
|
|
2800
|
+
value.summary_index
|
|
2801
|
+
);
|
|
2802
|
+
controller.enqueue({
|
|
2803
|
+
type: "reasoning-start",
|
|
2804
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2805
|
+
providerMetadata: {
|
|
2806
|
+
openai: {
|
|
2807
|
+
itemId: value.item_id,
|
|
2808
|
+
reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
});
|
|
2812
|
+
}
|
|
2813
|
+
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2194
2814
|
controller.enqueue({
|
|
2195
|
-
type: "
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2815
|
+
type: "reasoning-delta",
|
|
2816
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2817
|
+
delta: value.delta,
|
|
2818
|
+
providerMetadata: {
|
|
2819
|
+
openai: {
|
|
2820
|
+
itemId: value.item_id
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2200
2823
|
});
|
|
2201
2824
|
} else if (isResponseFinishedChunk(value)) {
|
|
2202
2825
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2203
|
-
finishReason: (
|
|
2826
|
+
finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
|
|
2204
2827
|
hasToolCalls
|
|
2205
2828
|
});
|
|
2206
2829
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2207
2830
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
2208
|
-
|
|
2209
|
-
reasoningTokens = (
|
|
2831
|
+
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
2832
|
+
usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
|
|
2833
|
+
usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
|
|
2210
2834
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2211
2835
|
controller.enqueue({
|
|
2212
2836
|
type: "source",
|
|
2213
2837
|
sourceType: "url",
|
|
2214
|
-
id: (
|
|
2838
|
+
id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : (0, import_provider_utils11.generateId)(),
|
|
2215
2839
|
url: value.annotation.url,
|
|
2216
2840
|
title: value.annotation.title
|
|
2217
2841
|
});
|
|
2842
|
+
} else if (isErrorChunk(value)) {
|
|
2843
|
+
controller.enqueue({ type: "error", error: value });
|
|
2218
2844
|
}
|
|
2219
2845
|
},
|
|
2220
2846
|
flush(controller) {
|
|
@@ -2222,13 +2848,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2222
2848
|
type: "finish",
|
|
2223
2849
|
finishReason,
|
|
2224
2850
|
usage,
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
responseId,
|
|
2229
|
-
cachedPromptTokens,
|
|
2230
|
-
reasoningTokens
|
|
2231
|
-
}
|
|
2851
|
+
providerMetadata: {
|
|
2852
|
+
openai: {
|
|
2853
|
+
responseId
|
|
2232
2854
|
}
|
|
2233
2855
|
}
|
|
2234
2856
|
});
|
|
@@ -2240,87 +2862,141 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2240
2862
|
};
|
|
2241
2863
|
}
|
|
2242
2864
|
};
|
|
2243
|
-
var
|
|
2244
|
-
input_tokens:
|
|
2245
|
-
input_tokens_details:
|
|
2246
|
-
output_tokens:
|
|
2247
|
-
output_tokens_details:
|
|
2865
|
+
var usageSchema2 = import_v414.z.object({
|
|
2866
|
+
input_tokens: import_v414.z.number(),
|
|
2867
|
+
input_tokens_details: import_v414.z.object({ cached_tokens: import_v414.z.number().nullish() }).nullish(),
|
|
2868
|
+
output_tokens: import_v414.z.number(),
|
|
2869
|
+
output_tokens_details: import_v414.z.object({ reasoning_tokens: import_v414.z.number().nullish() }).nullish()
|
|
2248
2870
|
});
|
|
2249
|
-
var textDeltaChunkSchema =
|
|
2250
|
-
type:
|
|
2251
|
-
|
|
2871
|
+
var textDeltaChunkSchema = import_v414.z.object({
|
|
2872
|
+
type: import_v414.z.literal("response.output_text.delta"),
|
|
2873
|
+
item_id: import_v414.z.string(),
|
|
2874
|
+
delta: import_v414.z.string()
|
|
2252
2875
|
});
|
|
2253
|
-
var
|
|
2254
|
-
type:
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2876
|
+
var errorChunkSchema = import_v414.z.object({
|
|
2877
|
+
type: import_v414.z.literal("error"),
|
|
2878
|
+
code: import_v414.z.string(),
|
|
2879
|
+
message: import_v414.z.string(),
|
|
2880
|
+
param: import_v414.z.string().nullish(),
|
|
2881
|
+
sequence_number: import_v414.z.number()
|
|
2882
|
+
});
|
|
2883
|
+
var responseFinishedChunkSchema = import_v414.z.object({
|
|
2884
|
+
type: import_v414.z.enum(["response.completed", "response.incomplete"]),
|
|
2885
|
+
response: import_v414.z.object({
|
|
2886
|
+
incomplete_details: import_v414.z.object({ reason: import_v414.z.string() }).nullish(),
|
|
2887
|
+
usage: usageSchema2
|
|
2258
2888
|
})
|
|
2259
2889
|
});
|
|
2260
|
-
var responseCreatedChunkSchema =
|
|
2261
|
-
type:
|
|
2262
|
-
response:
|
|
2263
|
-
id:
|
|
2264
|
-
created_at:
|
|
2265
|
-
model:
|
|
2890
|
+
var responseCreatedChunkSchema = import_v414.z.object({
|
|
2891
|
+
type: import_v414.z.literal("response.created"),
|
|
2892
|
+
response: import_v414.z.object({
|
|
2893
|
+
id: import_v414.z.string(),
|
|
2894
|
+
created_at: import_v414.z.number(),
|
|
2895
|
+
model: import_v414.z.string()
|
|
2266
2896
|
})
|
|
2267
2897
|
});
|
|
2268
|
-
var
|
|
2269
|
-
type:
|
|
2270
|
-
output_index:
|
|
2271
|
-
item:
|
|
2272
|
-
|
|
2273
|
-
type:
|
|
2898
|
+
var responseOutputItemAddedSchema = import_v414.z.object({
|
|
2899
|
+
type: import_v414.z.literal("response.output_item.added"),
|
|
2900
|
+
output_index: import_v414.z.number(),
|
|
2901
|
+
item: import_v414.z.discriminatedUnion("type", [
|
|
2902
|
+
import_v414.z.object({
|
|
2903
|
+
type: import_v414.z.literal("message"),
|
|
2904
|
+
id: import_v414.z.string()
|
|
2905
|
+
}),
|
|
2906
|
+
import_v414.z.object({
|
|
2907
|
+
type: import_v414.z.literal("reasoning"),
|
|
2908
|
+
id: import_v414.z.string(),
|
|
2909
|
+
encrypted_content: import_v414.z.string().nullish()
|
|
2910
|
+
}),
|
|
2911
|
+
import_v414.z.object({
|
|
2912
|
+
type: import_v414.z.literal("function_call"),
|
|
2913
|
+
id: import_v414.z.string(),
|
|
2914
|
+
call_id: import_v414.z.string(),
|
|
2915
|
+
name: import_v414.z.string(),
|
|
2916
|
+
arguments: import_v414.z.string()
|
|
2274
2917
|
}),
|
|
2275
|
-
|
|
2276
|
-
type:
|
|
2277
|
-
id:
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2918
|
+
import_v414.z.object({
|
|
2919
|
+
type: import_v414.z.literal("web_search_call"),
|
|
2920
|
+
id: import_v414.z.string(),
|
|
2921
|
+
status: import_v414.z.string()
|
|
2922
|
+
}),
|
|
2923
|
+
import_v414.z.object({
|
|
2924
|
+
type: import_v414.z.literal("computer_call"),
|
|
2925
|
+
id: import_v414.z.string(),
|
|
2926
|
+
status: import_v414.z.string()
|
|
2282
2927
|
})
|
|
2283
2928
|
])
|
|
2284
2929
|
});
|
|
2285
|
-
var
|
|
2286
|
-
type:
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2930
|
+
var responseOutputItemDoneSchema = import_v414.z.object({
|
|
2931
|
+
type: import_v414.z.literal("response.output_item.done"),
|
|
2932
|
+
output_index: import_v414.z.number(),
|
|
2933
|
+
item: import_v414.z.discriminatedUnion("type", [
|
|
2934
|
+
import_v414.z.object({
|
|
2935
|
+
type: import_v414.z.literal("message"),
|
|
2936
|
+
id: import_v414.z.string()
|
|
2937
|
+
}),
|
|
2938
|
+
import_v414.z.object({
|
|
2939
|
+
type: import_v414.z.literal("reasoning"),
|
|
2940
|
+
id: import_v414.z.string(),
|
|
2941
|
+
encrypted_content: import_v414.z.string().nullish()
|
|
2297
2942
|
}),
|
|
2298
|
-
|
|
2299
|
-
type:
|
|
2300
|
-
id:
|
|
2301
|
-
call_id:
|
|
2302
|
-
name:
|
|
2303
|
-
arguments:
|
|
2943
|
+
import_v414.z.object({
|
|
2944
|
+
type: import_v414.z.literal("function_call"),
|
|
2945
|
+
id: import_v414.z.string(),
|
|
2946
|
+
call_id: import_v414.z.string(),
|
|
2947
|
+
name: import_v414.z.string(),
|
|
2948
|
+
arguments: import_v414.z.string(),
|
|
2949
|
+
status: import_v414.z.literal("completed")
|
|
2950
|
+
}),
|
|
2951
|
+
import_v414.z.object({
|
|
2952
|
+
type: import_v414.z.literal("web_search_call"),
|
|
2953
|
+
id: import_v414.z.string(),
|
|
2954
|
+
status: import_v414.z.literal("completed")
|
|
2955
|
+
}),
|
|
2956
|
+
import_v414.z.object({
|
|
2957
|
+
type: import_v414.z.literal("computer_call"),
|
|
2958
|
+
id: import_v414.z.string(),
|
|
2959
|
+
status: import_v414.z.literal("completed")
|
|
2304
2960
|
})
|
|
2305
2961
|
])
|
|
2306
2962
|
});
|
|
2307
|
-
var
|
|
2308
|
-
type:
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2963
|
+
var responseFunctionCallArgumentsDeltaSchema = import_v414.z.object({
|
|
2964
|
+
type: import_v414.z.literal("response.function_call_arguments.delta"),
|
|
2965
|
+
item_id: import_v414.z.string(),
|
|
2966
|
+
output_index: import_v414.z.number(),
|
|
2967
|
+
delta: import_v414.z.string()
|
|
2968
|
+
});
|
|
2969
|
+
var responseAnnotationAddedSchema = import_v414.z.object({
|
|
2970
|
+
type: import_v414.z.literal("response.output_text.annotation.added"),
|
|
2971
|
+
annotation: import_v414.z.object({
|
|
2972
|
+
type: import_v414.z.literal("url_citation"),
|
|
2973
|
+
url: import_v414.z.string(),
|
|
2974
|
+
title: import_v414.z.string()
|
|
2313
2975
|
})
|
|
2314
2976
|
});
|
|
2315
|
-
var
|
|
2977
|
+
var responseReasoningSummaryPartAddedSchema = import_v414.z.object({
|
|
2978
|
+
type: import_v414.z.literal("response.reasoning_summary_part.added"),
|
|
2979
|
+
item_id: import_v414.z.string(),
|
|
2980
|
+
summary_index: import_v414.z.number()
|
|
2981
|
+
});
|
|
2982
|
+
var responseReasoningSummaryTextDeltaSchema = import_v414.z.object({
|
|
2983
|
+
type: import_v414.z.literal("response.reasoning_summary_text.delta"),
|
|
2984
|
+
item_id: import_v414.z.string(),
|
|
2985
|
+
summary_index: import_v414.z.number(),
|
|
2986
|
+
delta: import_v414.z.string()
|
|
2987
|
+
});
|
|
2988
|
+
var openaiResponsesChunkSchema = import_v414.z.union([
|
|
2316
2989
|
textDeltaChunkSchema,
|
|
2317
2990
|
responseFinishedChunkSchema,
|
|
2318
2991
|
responseCreatedChunkSchema,
|
|
2992
|
+
responseOutputItemAddedSchema,
|
|
2319
2993
|
responseOutputItemDoneSchema,
|
|
2320
2994
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2321
|
-
responseOutputItemAddedSchema,
|
|
2322
2995
|
responseAnnotationAddedSchema,
|
|
2323
|
-
|
|
2996
|
+
responseReasoningSummaryPartAddedSchema,
|
|
2997
|
+
responseReasoningSummaryTextDeltaSchema,
|
|
2998
|
+
errorChunkSchema,
|
|
2999
|
+
import_v414.z.object({ type: import_v414.z.string() }).loose()
|
|
2324
3000
|
// fallback for unknown chunks
|
|
2325
3001
|
]);
|
|
2326
3002
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2329,6 +3005,9 @@ function isTextDeltaChunk(chunk) {
|
|
|
2329
3005
|
function isResponseOutputItemDoneChunk(chunk) {
|
|
2330
3006
|
return chunk.type === "response.output_item.done";
|
|
2331
3007
|
}
|
|
3008
|
+
function isResponseOutputItemDoneReasoningChunk(chunk) {
|
|
3009
|
+
return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
|
|
3010
|
+
}
|
|
2332
3011
|
function isResponseFinishedChunk(chunk) {
|
|
2333
3012
|
return chunk.type === "response.completed" || chunk.type === "response.incomplete";
|
|
2334
3013
|
}
|
|
@@ -2341,11 +3020,23 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
|
2341
3020
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
2342
3021
|
return chunk.type === "response.output_item.added";
|
|
2343
3022
|
}
|
|
3023
|
+
function isResponseOutputItemAddedReasoningChunk(chunk) {
|
|
3024
|
+
return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
|
|
3025
|
+
}
|
|
2344
3026
|
function isResponseAnnotationAddedChunk(chunk) {
|
|
2345
3027
|
return chunk.type === "response.output_text.annotation.added";
|
|
2346
3028
|
}
|
|
3029
|
+
function isResponseReasoningSummaryPartAddedChunk(chunk) {
|
|
3030
|
+
return chunk.type === "response.reasoning_summary_part.added";
|
|
3031
|
+
}
|
|
3032
|
+
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
3033
|
+
return chunk.type === "response.reasoning_summary_text.delta";
|
|
3034
|
+
}
|
|
3035
|
+
function isErrorChunk(chunk) {
|
|
3036
|
+
return chunk.type === "error";
|
|
3037
|
+
}
|
|
2347
3038
|
function getResponsesModelConfig(modelId) {
|
|
2348
|
-
if (modelId.startsWith("o")) {
|
|
3039
|
+
if (modelId.startsWith("o") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
|
|
2349
3040
|
if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
|
|
2350
3041
|
return {
|
|
2351
3042
|
isReasoningModel: true,
|
|
@@ -2365,43 +3056,53 @@ function getResponsesModelConfig(modelId) {
|
|
|
2365
3056
|
requiredAutoTruncation: false
|
|
2366
3057
|
};
|
|
2367
3058
|
}
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
3059
|
+
function supportsFlexProcessing2(modelId) {
|
|
3060
|
+
return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
3061
|
+
}
|
|
3062
|
+
function supportsPriorityProcessing2(modelId) {
|
|
3063
|
+
return modelId.startsWith("gpt-4") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
3064
|
+
}
|
|
3065
|
+
var openaiResponsesProviderOptionsSchema = import_v414.z.object({
|
|
3066
|
+
metadata: import_v414.z.any().nullish(),
|
|
3067
|
+
parallelToolCalls: import_v414.z.boolean().nullish(),
|
|
3068
|
+
previousResponseId: import_v414.z.string().nullish(),
|
|
3069
|
+
store: import_v414.z.boolean().nullish(),
|
|
3070
|
+
user: import_v414.z.string().nullish(),
|
|
3071
|
+
reasoningEffort: import_v414.z.string().nullish(),
|
|
3072
|
+
strictJsonSchema: import_v414.z.boolean().nullish(),
|
|
3073
|
+
instructions: import_v414.z.string().nullish(),
|
|
3074
|
+
reasoningSummary: import_v414.z.string().nullish(),
|
|
3075
|
+
serviceTier: import_v414.z.enum(["auto", "flex", "priority"]).nullish(),
|
|
3076
|
+
include: import_v414.z.array(import_v414.z.enum(["reasoning.encrypted_content", "file_search_call.results"])).nullish()
|
|
2377
3077
|
});
|
|
2378
3078
|
|
|
2379
3079
|
// src/openai-speech-model.ts
|
|
2380
|
-
var
|
|
2381
|
-
var
|
|
2382
|
-
var OpenAIProviderOptionsSchema =
|
|
2383
|
-
instructions:
|
|
2384
|
-
speed:
|
|
3080
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
3081
|
+
var import_v415 = require("zod/v4");
|
|
3082
|
+
var OpenAIProviderOptionsSchema = import_v415.z.object({
|
|
3083
|
+
instructions: import_v415.z.string().nullish(),
|
|
3084
|
+
speed: import_v415.z.number().min(0.25).max(4).default(1).nullish()
|
|
2385
3085
|
});
|
|
2386
3086
|
var OpenAISpeechModel = class {
|
|
2387
3087
|
constructor(modelId, config) {
|
|
2388
3088
|
this.modelId = modelId;
|
|
2389
3089
|
this.config = config;
|
|
2390
|
-
this.specificationVersion = "
|
|
3090
|
+
this.specificationVersion = "v2";
|
|
2391
3091
|
}
|
|
2392
3092
|
get provider() {
|
|
2393
3093
|
return this.config.provider;
|
|
2394
3094
|
}
|
|
2395
|
-
getArgs({
|
|
3095
|
+
async getArgs({
|
|
2396
3096
|
text,
|
|
2397
3097
|
voice = "alloy",
|
|
2398
3098
|
outputFormat = "mp3",
|
|
2399
3099
|
speed,
|
|
2400
3100
|
instructions,
|
|
3101
|
+
language,
|
|
2401
3102
|
providerOptions
|
|
2402
3103
|
}) {
|
|
2403
3104
|
const warnings = [];
|
|
2404
|
-
const openAIOptions = (0,
|
|
3105
|
+
const openAIOptions = await (0, import_provider_utils12.parseProviderOptions)({
|
|
2405
3106
|
provider: "openai",
|
|
2406
3107
|
providerOptions,
|
|
2407
3108
|
schema: OpenAIProviderOptionsSchema
|
|
@@ -2434,6 +3135,13 @@ var OpenAISpeechModel = class {
|
|
|
2434
3135
|
}
|
|
2435
3136
|
}
|
|
2436
3137
|
}
|
|
3138
|
+
if (language) {
|
|
3139
|
+
warnings.push({
|
|
3140
|
+
type: "unsupported-setting",
|
|
3141
|
+
setting: "language",
|
|
3142
|
+
details: `OpenAI speech models do not support language selection. Language parameter "${language}" was ignored.`
|
|
3143
|
+
});
|
|
3144
|
+
}
|
|
2437
3145
|
return {
|
|
2438
3146
|
requestBody,
|
|
2439
3147
|
warnings
|
|
@@ -2442,20 +3150,20 @@ var OpenAISpeechModel = class {
|
|
|
2442
3150
|
async doGenerate(options) {
|
|
2443
3151
|
var _a, _b, _c;
|
|
2444
3152
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2445
|
-
const { requestBody, warnings } = this.getArgs(options);
|
|
3153
|
+
const { requestBody, warnings } = await this.getArgs(options);
|
|
2446
3154
|
const {
|
|
2447
3155
|
value: audio,
|
|
2448
3156
|
responseHeaders,
|
|
2449
3157
|
rawValue: rawResponse
|
|
2450
|
-
} = await (0,
|
|
3158
|
+
} = await (0, import_provider_utils12.postJsonToApi)({
|
|
2451
3159
|
url: this.config.url({
|
|
2452
3160
|
path: "/audio/speech",
|
|
2453
3161
|
modelId: this.modelId
|
|
2454
3162
|
}),
|
|
2455
|
-
headers: (0,
|
|
3163
|
+
headers: (0, import_provider_utils12.combineHeaders)(this.config.headers(), options.headers),
|
|
2456
3164
|
body: requestBody,
|
|
2457
3165
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2458
|
-
successfulResponseHandler: (0,
|
|
3166
|
+
successfulResponseHandler: (0, import_provider_utils12.createBinaryResponseHandler)(),
|
|
2459
3167
|
abortSignal: options.abortSignal,
|
|
2460
3168
|
fetch: this.config.fetch
|
|
2461
3169
|
});
|
|
@@ -2477,12 +3185,11 @@ var OpenAISpeechModel = class {
|
|
|
2477
3185
|
|
|
2478
3186
|
// src/openai-provider.ts
|
|
2479
3187
|
function createOpenAI(options = {}) {
|
|
2480
|
-
var _a, _b
|
|
2481
|
-
const baseURL = (_a = (0,
|
|
2482
|
-
const
|
|
2483
|
-
const providerName = (_c = options.name) != null ? _c : "openai";
|
|
3188
|
+
var _a, _b;
|
|
3189
|
+
const baseURL = (_a = (0, import_provider_utils13.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
|
|
3190
|
+
const providerName = (_b = options.name) != null ? _b : "openai";
|
|
2484
3191
|
const getHeaders = () => ({
|
|
2485
|
-
Authorization: `Bearer ${(0,
|
|
3192
|
+
Authorization: `Bearer ${(0, import_provider_utils13.loadApiKey)({
|
|
2486
3193
|
apiKey: options.apiKey,
|
|
2487
3194
|
environmentVariableName: "OPENAI_API_KEY",
|
|
2488
3195
|
description: "OpenAI"
|
|
@@ -2491,27 +3198,25 @@ function createOpenAI(options = {}) {
|
|
|
2491
3198
|
"OpenAI-Project": options.project,
|
|
2492
3199
|
...options.headers
|
|
2493
3200
|
});
|
|
2494
|
-
const createChatModel = (modelId
|
|
3201
|
+
const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
|
|
2495
3202
|
provider: `${providerName}.chat`,
|
|
2496
3203
|
url: ({ path }) => `${baseURL}${path}`,
|
|
2497
3204
|
headers: getHeaders,
|
|
2498
|
-
compatibility,
|
|
2499
3205
|
fetch: options.fetch
|
|
2500
3206
|
});
|
|
2501
|
-
const createCompletionModel = (modelId
|
|
3207
|
+
const createCompletionModel = (modelId) => new OpenAICompletionLanguageModel(modelId, {
|
|
2502
3208
|
provider: `${providerName}.completion`,
|
|
2503
3209
|
url: ({ path }) => `${baseURL}${path}`,
|
|
2504
3210
|
headers: getHeaders,
|
|
2505
|
-
compatibility,
|
|
2506
3211
|
fetch: options.fetch
|
|
2507
3212
|
});
|
|
2508
|
-
const createEmbeddingModel = (modelId
|
|
3213
|
+
const createEmbeddingModel = (modelId) => new OpenAIEmbeddingModel(modelId, {
|
|
2509
3214
|
provider: `${providerName}.embedding`,
|
|
2510
3215
|
url: ({ path }) => `${baseURL}${path}`,
|
|
2511
3216
|
headers: getHeaders,
|
|
2512
3217
|
fetch: options.fetch
|
|
2513
3218
|
});
|
|
2514
|
-
const createImageModel = (modelId
|
|
3219
|
+
const createImageModel = (modelId) => new OpenAIImageModel(modelId, {
|
|
2515
3220
|
provider: `${providerName}.image`,
|
|
2516
3221
|
url: ({ path }) => `${baseURL}${path}`,
|
|
2517
3222
|
headers: getHeaders,
|
|
@@ -2529,19 +3234,13 @@ function createOpenAI(options = {}) {
|
|
|
2529
3234
|
headers: getHeaders,
|
|
2530
3235
|
fetch: options.fetch
|
|
2531
3236
|
});
|
|
2532
|
-
const createLanguageModel = (modelId
|
|
3237
|
+
const createLanguageModel = (modelId) => {
|
|
2533
3238
|
if (new.target) {
|
|
2534
3239
|
throw new Error(
|
|
2535
3240
|
"The OpenAI model function cannot be called with the new keyword."
|
|
2536
3241
|
);
|
|
2537
3242
|
}
|
|
2538
|
-
|
|
2539
|
-
return createCompletionModel(
|
|
2540
|
-
modelId,
|
|
2541
|
-
settings
|
|
2542
|
-
);
|
|
2543
|
-
}
|
|
2544
|
-
return createChatModel(modelId, settings);
|
|
3243
|
+
return createResponsesModel(modelId);
|
|
2545
3244
|
};
|
|
2546
3245
|
const createResponsesModel = (modelId) => {
|
|
2547
3246
|
return new OpenAIResponsesLanguageModel(modelId, {
|
|
@@ -2551,8 +3250,8 @@ function createOpenAI(options = {}) {
|
|
|
2551
3250
|
fetch: options.fetch
|
|
2552
3251
|
});
|
|
2553
3252
|
};
|
|
2554
|
-
const provider = function(modelId
|
|
2555
|
-
return createLanguageModel(modelId
|
|
3253
|
+
const provider = function(modelId) {
|
|
3254
|
+
return createLanguageModel(modelId);
|
|
2556
3255
|
};
|
|
2557
3256
|
provider.languageModel = createLanguageModel;
|
|
2558
3257
|
provider.chat = createChatModel;
|
|
@@ -2570,10 +3269,7 @@ function createOpenAI(options = {}) {
|
|
|
2570
3269
|
provider.tools = openaiTools;
|
|
2571
3270
|
return provider;
|
|
2572
3271
|
}
|
|
2573
|
-
var openai = createOpenAI(
|
|
2574
|
-
compatibility: "strict"
|
|
2575
|
-
// strict for OpenAI API
|
|
2576
|
-
});
|
|
3272
|
+
var openai = createOpenAI();
|
|
2577
3273
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2578
3274
|
0 && (module.exports = {
|
|
2579
3275
|
createOpenAI,
|