@ai-sdk/openai 2.0.0-canary.0 → 2.0.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/index.d.mts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +235 -375
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -375
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +13 -13
- package/internal/dist/index.d.ts +13 -13
- package/internal/dist/index.js +116 -256
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +114 -256
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -90,7 +90,7 @@ function convertToOpenAIChatMessages({
|
|
|
90
90
|
image_url: {
|
|
91
91
|
url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils.convertUint8ArrayToBase64)(part.image)}`,
|
|
92
92
|
// OpenAI specific extension: image detail
|
|
93
|
-
detail: (_c = (_b = part.
|
|
93
|
+
detail: (_c = (_b = part.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
}
|
|
@@ -269,17 +269,16 @@ function getResponseMetadata({
|
|
|
269
269
|
// src/openai-prepare-tools.ts
|
|
270
270
|
var import_provider2 = require("@ai-sdk/provider");
|
|
271
271
|
function prepareTools({
|
|
272
|
-
|
|
272
|
+
tools,
|
|
273
|
+
toolChoice,
|
|
273
274
|
useLegacyFunctionCalling = false,
|
|
274
275
|
structuredOutputs
|
|
275
276
|
}) {
|
|
276
|
-
|
|
277
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
277
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
278
278
|
const toolWarnings = [];
|
|
279
279
|
if (tools == null) {
|
|
280
|
-
return { tools: void 0,
|
|
280
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
281
281
|
}
|
|
282
|
-
const toolChoice = mode.toolChoice;
|
|
283
282
|
if (useLegacyFunctionCalling) {
|
|
284
283
|
const openaiFunctions = [];
|
|
285
284
|
for (const tool of tools) {
|
|
@@ -339,18 +338,18 @@ function prepareTools({
|
|
|
339
338
|
}
|
|
340
339
|
}
|
|
341
340
|
if (toolChoice == null) {
|
|
342
|
-
return { tools: openaiTools2,
|
|
341
|
+
return { tools: openaiTools2, toolChoice: void 0, toolWarnings };
|
|
343
342
|
}
|
|
344
343
|
const type = toolChoice.type;
|
|
345
344
|
switch (type) {
|
|
346
345
|
case "auto":
|
|
347
346
|
case "none":
|
|
348
347
|
case "required":
|
|
349
|
-
return { tools: openaiTools2,
|
|
348
|
+
return { tools: openaiTools2, toolChoice: type, toolWarnings };
|
|
350
349
|
case "tool":
|
|
351
350
|
return {
|
|
352
351
|
tools: openaiTools2,
|
|
353
|
-
|
|
352
|
+
toolChoice: {
|
|
354
353
|
type: "function",
|
|
355
354
|
function: {
|
|
356
355
|
name: toolChoice.toolName
|
|
@@ -370,7 +369,7 @@ function prepareTools({
|
|
|
370
369
|
// src/openai-chat-language-model.ts
|
|
371
370
|
var OpenAIChatLanguageModel = class {
|
|
372
371
|
constructor(modelId, settings, config) {
|
|
373
|
-
this.specificationVersion = "
|
|
372
|
+
this.specificationVersion = "v2";
|
|
374
373
|
this.modelId = modelId;
|
|
375
374
|
this.settings = settings;
|
|
376
375
|
this.config = config;
|
|
@@ -392,7 +391,6 @@ var OpenAIChatLanguageModel = class {
|
|
|
392
391
|
return !this.settings.downloadImages;
|
|
393
392
|
}
|
|
394
393
|
getArgs({
|
|
395
|
-
mode,
|
|
396
394
|
prompt,
|
|
397
395
|
maxTokens,
|
|
398
396
|
temperature,
|
|
@@ -403,10 +401,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
403
401
|
stopSequences,
|
|
404
402
|
responseFormat,
|
|
405
403
|
seed,
|
|
406
|
-
|
|
404
|
+
tools,
|
|
405
|
+
toolChoice,
|
|
406
|
+
providerOptions
|
|
407
407
|
}) {
|
|
408
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
409
|
-
const type = mode.type;
|
|
408
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
410
409
|
const warnings = [];
|
|
411
410
|
if (topK != null) {
|
|
412
411
|
warnings.push({
|
|
@@ -455,6 +454,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
455
454
|
top_p: topP,
|
|
456
455
|
frequency_penalty: frequencyPenalty,
|
|
457
456
|
presence_penalty: presencePenalty,
|
|
457
|
+
// TODO improve below:
|
|
458
458
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs && responseFormat.schema != null ? {
|
|
459
459
|
type: "json_schema",
|
|
460
460
|
json_schema: {
|
|
@@ -468,11 +468,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
468
468
|
seed,
|
|
469
469
|
// openai specific settings:
|
|
470
470
|
// TODO remove in next major version; we auto-map maxTokens now
|
|
471
|
-
max_completion_tokens: (_b =
|
|
472
|
-
store: (_c =
|
|
473
|
-
metadata: (_d =
|
|
474
|
-
prediction: (_e =
|
|
475
|
-
reasoning_effort: (_g = (_f =
|
|
471
|
+
max_completion_tokens: (_b = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _b.maxCompletionTokens,
|
|
472
|
+
store: (_c = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _c.store,
|
|
473
|
+
metadata: (_d = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _d.metadata,
|
|
474
|
+
prediction: (_e = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _e.prediction,
|
|
475
|
+
reasoning_effort: (_g = (_f = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _f.reasoningEffort) != null ? _g : this.settings.reasoningEffort,
|
|
476
476
|
// messages:
|
|
477
477
|
messages
|
|
478
478
|
};
|
|
@@ -537,81 +537,28 @@ var OpenAIChatLanguageModel = class {
|
|
|
537
537
|
baseArgs.max_tokens = void 0;
|
|
538
538
|
}
|
|
539
539
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
response_format: this.supportsStructuredOutputs && mode.schema != null ? {
|
|
563
|
-
type: "json_schema",
|
|
564
|
-
json_schema: {
|
|
565
|
-
schema: mode.schema,
|
|
566
|
-
strict: true,
|
|
567
|
-
name: (_h = mode.name) != null ? _h : "response",
|
|
568
|
-
description: mode.description
|
|
569
|
-
}
|
|
570
|
-
} : { type: "json_object" }
|
|
571
|
-
},
|
|
572
|
-
warnings
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
case "object-tool": {
|
|
576
|
-
return {
|
|
577
|
-
args: useLegacyFunctionCalling ? {
|
|
578
|
-
...baseArgs,
|
|
579
|
-
function_call: {
|
|
580
|
-
name: mode.tool.name
|
|
581
|
-
},
|
|
582
|
-
functions: [
|
|
583
|
-
{
|
|
584
|
-
name: mode.tool.name,
|
|
585
|
-
description: mode.tool.description,
|
|
586
|
-
parameters: mode.tool.parameters
|
|
587
|
-
}
|
|
588
|
-
]
|
|
589
|
-
} : {
|
|
590
|
-
...baseArgs,
|
|
591
|
-
tool_choice: {
|
|
592
|
-
type: "function",
|
|
593
|
-
function: { name: mode.tool.name }
|
|
594
|
-
},
|
|
595
|
-
tools: [
|
|
596
|
-
{
|
|
597
|
-
type: "function",
|
|
598
|
-
function: {
|
|
599
|
-
name: mode.tool.name,
|
|
600
|
-
description: mode.tool.description,
|
|
601
|
-
parameters: mode.tool.parameters,
|
|
602
|
-
strict: this.supportsStructuredOutputs ? true : void 0
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
]
|
|
606
|
-
},
|
|
607
|
-
warnings
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
default: {
|
|
611
|
-
const _exhaustiveCheck = type;
|
|
612
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
540
|
+
const {
|
|
541
|
+
tools: openaiTools2,
|
|
542
|
+
toolChoice: openaiToolChoice,
|
|
543
|
+
functions,
|
|
544
|
+
function_call,
|
|
545
|
+
toolWarnings
|
|
546
|
+
} = prepareTools({
|
|
547
|
+
tools,
|
|
548
|
+
toolChoice,
|
|
549
|
+
useLegacyFunctionCalling,
|
|
550
|
+
structuredOutputs: this.supportsStructuredOutputs
|
|
551
|
+
});
|
|
552
|
+
return {
|
|
553
|
+
args: {
|
|
554
|
+
...baseArgs,
|
|
555
|
+
tools: openaiTools2,
|
|
556
|
+
tool_choice: openaiToolChoice,
|
|
557
|
+
functions,
|
|
558
|
+
function_call
|
|
559
|
+
},
|
|
560
|
+
warnings: [...warnings, ...toolWarnings]
|
|
561
|
+
};
|
|
615
562
|
}
|
|
616
563
|
async doGenerate(options) {
|
|
617
564
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -1078,7 +1025,6 @@ var reasoningModels = {
|
|
|
1078
1025
|
};
|
|
1079
1026
|
|
|
1080
1027
|
// src/openai-completion-language-model.ts
|
|
1081
|
-
var import_provider5 = require("@ai-sdk/provider");
|
|
1082
1028
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1083
1029
|
var import_zod3 = require("zod");
|
|
1084
1030
|
|
|
@@ -1183,7 +1129,7 @@ function mapOpenAICompletionLogProbs(logprobs) {
|
|
|
1183
1129
|
// src/openai-completion-language-model.ts
|
|
1184
1130
|
var OpenAICompletionLanguageModel = class {
|
|
1185
1131
|
constructor(modelId, settings, config) {
|
|
1186
|
-
this.specificationVersion = "
|
|
1132
|
+
this.specificationVersion = "v2";
|
|
1187
1133
|
this.defaultObjectGenerationMode = void 0;
|
|
1188
1134
|
this.modelId = modelId;
|
|
1189
1135
|
this.settings = settings;
|
|
@@ -1193,7 +1139,6 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1193
1139
|
return this.config.provider;
|
|
1194
1140
|
}
|
|
1195
1141
|
getArgs({
|
|
1196
|
-
mode,
|
|
1197
1142
|
inputFormat,
|
|
1198
1143
|
prompt,
|
|
1199
1144
|
maxTokens,
|
|
@@ -1204,16 +1149,19 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1204
1149
|
presencePenalty,
|
|
1205
1150
|
stopSequences: userStopSequences,
|
|
1206
1151
|
responseFormat,
|
|
1152
|
+
tools,
|
|
1153
|
+
toolChoice,
|
|
1207
1154
|
seed
|
|
1208
1155
|
}) {
|
|
1209
|
-
var _a;
|
|
1210
|
-
const type = mode.type;
|
|
1211
1156
|
const warnings = [];
|
|
1212
1157
|
if (topK != null) {
|
|
1213
|
-
warnings.push({
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
});
|
|
1158
|
+
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
1159
|
+
}
|
|
1160
|
+
if (tools == null ? void 0 : tools.length) {
|
|
1161
|
+
warnings.push({ type: "unsupported-setting", setting: "tools" });
|
|
1162
|
+
}
|
|
1163
|
+
if (toolChoice != null) {
|
|
1164
|
+
warnings.push({ type: "unsupported-setting", setting: "toolChoice" });
|
|
1217
1165
|
}
|
|
1218
1166
|
if (responseFormat != null && responseFormat.type !== "text") {
|
|
1219
1167
|
warnings.push({
|
|
@@ -1224,56 +1172,30 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1224
1172
|
}
|
|
1225
1173
|
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt, inputFormat });
|
|
1226
1174
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1175
|
+
return {
|
|
1176
|
+
args: {
|
|
1177
|
+
// model id:
|
|
1178
|
+
model: this.modelId,
|
|
1179
|
+
// model specific settings:
|
|
1180
|
+
echo: this.settings.echo,
|
|
1181
|
+
logit_bias: this.settings.logitBias,
|
|
1182
|
+
logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
|
|
1183
|
+
suffix: this.settings.suffix,
|
|
1184
|
+
user: this.settings.user,
|
|
1185
|
+
// standardized settings:
|
|
1186
|
+
max_tokens: maxTokens,
|
|
1187
|
+
temperature,
|
|
1188
|
+
top_p: topP,
|
|
1189
|
+
frequency_penalty: frequencyPenalty,
|
|
1190
|
+
presence_penalty: presencePenalty,
|
|
1191
|
+
seed,
|
|
1192
|
+
// prompt:
|
|
1193
|
+
prompt: completionPrompt,
|
|
1194
|
+
// stop sequences:
|
|
1195
|
+
stop: stop.length > 0 ? stop : void 0
|
|
1196
|
+
},
|
|
1197
|
+
warnings
|
|
1247
1198
|
};
|
|
1248
|
-
switch (type) {
|
|
1249
|
-
case "regular": {
|
|
1250
|
-
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
|
1251
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1252
|
-
functionality: "tools"
|
|
1253
|
-
});
|
|
1254
|
-
}
|
|
1255
|
-
if (mode.toolChoice) {
|
|
1256
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1257
|
-
functionality: "toolChoice"
|
|
1258
|
-
});
|
|
1259
|
-
}
|
|
1260
|
-
return { args: baseArgs, warnings };
|
|
1261
|
-
}
|
|
1262
|
-
case "object-json": {
|
|
1263
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1264
|
-
functionality: "object-json mode"
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
case "object-tool": {
|
|
1268
|
-
throw new import_provider5.UnsupportedFunctionalityError({
|
|
1269
|
-
functionality: "object-tool mode"
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1272
|
-
default: {
|
|
1273
|
-
const _exhaustiveCheck = type;
|
|
1274
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
1199
|
}
|
|
1278
1200
|
async doGenerate(options) {
|
|
1279
1201
|
const { args, warnings } = this.getArgs(options);
|
|
@@ -1451,7 +1373,7 @@ var openaiCompletionChunkSchema = import_zod3.z.union([
|
|
|
1451
1373
|
]);
|
|
1452
1374
|
|
|
1453
1375
|
// src/openai-embedding-model.ts
|
|
1454
|
-
var
|
|
1376
|
+
var import_provider5 = require("@ai-sdk/provider");
|
|
1455
1377
|
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
1456
1378
|
var import_zod4 = require("zod");
|
|
1457
1379
|
var OpenAIEmbeddingModel = class {
|
|
@@ -1478,7 +1400,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1478
1400
|
abortSignal
|
|
1479
1401
|
}) {
|
|
1480
1402
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1481
|
-
throw new
|
|
1403
|
+
throw new import_provider5.TooManyEmbeddingValuesForCallError({
|
|
1482
1404
|
provider: this.provider,
|
|
1483
1405
|
modelId: this.modelId,
|
|
1484
1406
|
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
@@ -1601,12 +1523,33 @@ var openaiImageResponseSchema = import_zod5.z.object({
|
|
|
1601
1523
|
data: import_zod5.z.array(import_zod5.z.object({ b64_json: import_zod5.z.string() }))
|
|
1602
1524
|
});
|
|
1603
1525
|
|
|
1526
|
+
// src/openai-tools.ts
|
|
1527
|
+
var import_zod6 = require("zod");
|
|
1528
|
+
var WebSearchPreviewParameters = import_zod6.z.object({});
|
|
1529
|
+
function webSearchPreviewTool({
|
|
1530
|
+
searchContextSize,
|
|
1531
|
+
userLocation
|
|
1532
|
+
} = {}) {
|
|
1533
|
+
return {
|
|
1534
|
+
type: "provider-defined",
|
|
1535
|
+
id: "openai.web_search_preview",
|
|
1536
|
+
args: {
|
|
1537
|
+
searchContextSize,
|
|
1538
|
+
userLocation
|
|
1539
|
+
},
|
|
1540
|
+
parameters: WebSearchPreviewParameters
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
var openaiTools = {
|
|
1544
|
+
webSearchPreview: webSearchPreviewTool
|
|
1545
|
+
};
|
|
1546
|
+
|
|
1604
1547
|
// src/responses/openai-responses-language-model.ts
|
|
1605
1548
|
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1606
|
-
var
|
|
1549
|
+
var import_zod7 = require("zod");
|
|
1607
1550
|
|
|
1608
1551
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1609
|
-
var
|
|
1552
|
+
var import_provider6 = require("@ai-sdk/provider");
|
|
1610
1553
|
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1611
1554
|
function convertToOpenAIResponsesMessages({
|
|
1612
1555
|
prompt,
|
|
@@ -1656,12 +1599,12 @@ function convertToOpenAIResponsesMessages({
|
|
|
1656
1599
|
type: "input_image",
|
|
1657
1600
|
image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils7.convertUint8ArrayToBase64)(part.image)}`,
|
|
1658
1601
|
// OpenAI specific extension: image detail
|
|
1659
|
-
detail: (_c = (_b = part.
|
|
1602
|
+
detail: (_c = (_b = part.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
1660
1603
|
};
|
|
1661
1604
|
}
|
|
1662
1605
|
case "file": {
|
|
1663
1606
|
if (part.data instanceof URL) {
|
|
1664
|
-
throw new
|
|
1607
|
+
throw new import_provider6.UnsupportedFunctionalityError({
|
|
1665
1608
|
functionality: "File URLs in user messages"
|
|
1666
1609
|
});
|
|
1667
1610
|
}
|
|
@@ -1674,7 +1617,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1674
1617
|
};
|
|
1675
1618
|
}
|
|
1676
1619
|
default: {
|
|
1677
|
-
throw new
|
|
1620
|
+
throw new import_provider6.UnsupportedFunctionalityError({
|
|
1678
1621
|
functionality: "Only PDF files are supported in user messages"
|
|
1679
1622
|
});
|
|
1680
1623
|
}
|
|
@@ -1746,18 +1689,17 @@ function mapOpenAIResponseFinishReason({
|
|
|
1746
1689
|
}
|
|
1747
1690
|
|
|
1748
1691
|
// src/responses/openai-responses-prepare-tools.ts
|
|
1749
|
-
var
|
|
1692
|
+
var import_provider7 = require("@ai-sdk/provider");
|
|
1750
1693
|
function prepareResponsesTools({
|
|
1751
|
-
|
|
1694
|
+
tools,
|
|
1695
|
+
toolChoice,
|
|
1752
1696
|
strict
|
|
1753
1697
|
}) {
|
|
1754
|
-
|
|
1755
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
1698
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1756
1699
|
const toolWarnings = [];
|
|
1757
1700
|
if (tools == null) {
|
|
1758
|
-
return { tools: void 0,
|
|
1701
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
1759
1702
|
}
|
|
1760
|
-
const toolChoice = mode.toolChoice;
|
|
1761
1703
|
const openaiTools2 = [];
|
|
1762
1704
|
for (const tool of tools) {
|
|
1763
1705
|
switch (tool.type) {
|
|
@@ -1790,36 +1732,23 @@ function prepareResponsesTools({
|
|
|
1790
1732
|
}
|
|
1791
1733
|
}
|
|
1792
1734
|
if (toolChoice == null) {
|
|
1793
|
-
return { tools: openaiTools2,
|
|
1735
|
+
return { tools: openaiTools2, toolChoice: void 0, toolWarnings };
|
|
1794
1736
|
}
|
|
1795
1737
|
const type = toolChoice.type;
|
|
1796
1738
|
switch (type) {
|
|
1797
1739
|
case "auto":
|
|
1798
1740
|
case "none":
|
|
1799
1741
|
case "required":
|
|
1800
|
-
return { tools: openaiTools2,
|
|
1801
|
-
case "tool":
|
|
1802
|
-
if (toolChoice.toolName === "web_search_preview") {
|
|
1803
|
-
return {
|
|
1804
|
-
tools: openaiTools2,
|
|
1805
|
-
tool_choice: {
|
|
1806
|
-
type: "web_search_preview"
|
|
1807
|
-
},
|
|
1808
|
-
toolWarnings
|
|
1809
|
-
};
|
|
1810
|
-
}
|
|
1742
|
+
return { tools: openaiTools2, toolChoice: type, toolWarnings };
|
|
1743
|
+
case "tool":
|
|
1811
1744
|
return {
|
|
1812
1745
|
tools: openaiTools2,
|
|
1813
|
-
|
|
1814
|
-
type: "function",
|
|
1815
|
-
name: toolChoice.toolName
|
|
1816
|
-
},
|
|
1746
|
+
toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
1817
1747
|
toolWarnings
|
|
1818
1748
|
};
|
|
1819
|
-
}
|
|
1820
1749
|
default: {
|
|
1821
1750
|
const _exhaustiveCheck = type;
|
|
1822
|
-
throw new
|
|
1751
|
+
throw new import_provider7.UnsupportedFunctionalityError({
|
|
1823
1752
|
functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
|
|
1824
1753
|
});
|
|
1825
1754
|
}
|
|
@@ -1829,7 +1758,7 @@ function prepareResponsesTools({
|
|
|
1829
1758
|
// src/responses/openai-responses-language-model.ts
|
|
1830
1759
|
var OpenAIResponsesLanguageModel = class {
|
|
1831
1760
|
constructor(modelId, config) {
|
|
1832
|
-
this.specificationVersion = "
|
|
1761
|
+
this.specificationVersion = "v2";
|
|
1833
1762
|
this.defaultObjectGenerationMode = "json";
|
|
1834
1763
|
this.modelId = modelId;
|
|
1835
1764
|
this.config = config;
|
|
@@ -1838,7 +1767,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1838
1767
|
return this.config.provider;
|
|
1839
1768
|
}
|
|
1840
1769
|
getArgs({
|
|
1841
|
-
mode,
|
|
1842
1770
|
maxTokens,
|
|
1843
1771
|
temperature,
|
|
1844
1772
|
stopSequences,
|
|
@@ -1848,24 +1776,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1848
1776
|
frequencyPenalty,
|
|
1849
1777
|
seed,
|
|
1850
1778
|
prompt,
|
|
1851
|
-
|
|
1779
|
+
providerOptions,
|
|
1780
|
+
tools,
|
|
1781
|
+
toolChoice,
|
|
1852
1782
|
responseFormat
|
|
1853
1783
|
}) {
|
|
1854
|
-
var _a, _b
|
|
1784
|
+
var _a, _b;
|
|
1855
1785
|
const warnings = [];
|
|
1856
1786
|
const modelConfig = getResponsesModelConfig(this.modelId);
|
|
1857
|
-
const type = mode.type;
|
|
1858
1787
|
if (topK != null) {
|
|
1859
|
-
warnings.push({
|
|
1860
|
-
type: "unsupported-setting",
|
|
1861
|
-
setting: "topK"
|
|
1862
|
-
});
|
|
1788
|
+
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
1863
1789
|
}
|
|
1864
1790
|
if (seed != null) {
|
|
1865
|
-
warnings.push({
|
|
1866
|
-
type: "unsupported-setting",
|
|
1867
|
-
setting: "seed"
|
|
1868
|
-
});
|
|
1791
|
+
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
1869
1792
|
}
|
|
1870
1793
|
if (presencePenalty != null) {
|
|
1871
1794
|
warnings.push({
|
|
@@ -1880,10 +1803,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1880
1803
|
});
|
|
1881
1804
|
}
|
|
1882
1805
|
if (stopSequences != null) {
|
|
1883
|
-
warnings.push({
|
|
1884
|
-
type: "unsupported-setting",
|
|
1885
|
-
setting: "stopSequences"
|
|
1886
|
-
});
|
|
1806
|
+
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
1887
1807
|
}
|
|
1888
1808
|
const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
|
|
1889
1809
|
prompt,
|
|
@@ -1892,7 +1812,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1892
1812
|
warnings.push(...messageWarnings);
|
|
1893
1813
|
const openaiOptions = (0, import_provider_utils8.parseProviderOptions)({
|
|
1894
1814
|
provider: "openai",
|
|
1895
|
-
providerOptions
|
|
1815
|
+
providerOptions,
|
|
1896
1816
|
schema: openaiResponsesProviderOptionsSchema
|
|
1897
1817
|
});
|
|
1898
1818
|
const isStrict = (_a = openaiOptions == null ? void 0 : openaiOptions.strictSchemas) != null ? _a : true;
|
|
@@ -1946,62 +1866,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1946
1866
|
});
|
|
1947
1867
|
}
|
|
1948
1868
|
}
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
return {
|
|
1967
|
-
args: {
|
|
1968
|
-
...baseArgs,
|
|
1969
|
-
text: {
|
|
1970
|
-
format: mode.schema != null ? {
|
|
1971
|
-
type: "json_schema",
|
|
1972
|
-
strict: isStrict,
|
|
1973
|
-
name: (_c = mode.name) != null ? _c : "response",
|
|
1974
|
-
description: mode.description,
|
|
1975
|
-
schema: mode.schema
|
|
1976
|
-
} : { type: "json_object" }
|
|
1977
|
-
}
|
|
1978
|
-
},
|
|
1979
|
-
warnings
|
|
1980
|
-
};
|
|
1981
|
-
}
|
|
1982
|
-
case "object-tool": {
|
|
1983
|
-
return {
|
|
1984
|
-
args: {
|
|
1985
|
-
...baseArgs,
|
|
1986
|
-
tool_choice: { type: "function", name: mode.tool.name },
|
|
1987
|
-
tools: [
|
|
1988
|
-
{
|
|
1989
|
-
type: "function",
|
|
1990
|
-
name: mode.tool.name,
|
|
1991
|
-
description: mode.tool.description,
|
|
1992
|
-
parameters: mode.tool.parameters,
|
|
1993
|
-
strict: isStrict
|
|
1994
|
-
}
|
|
1995
|
-
]
|
|
1996
|
-
},
|
|
1997
|
-
warnings
|
|
1998
|
-
};
|
|
1999
|
-
}
|
|
2000
|
-
default: {
|
|
2001
|
-
const _exhaustiveCheck = type;
|
|
2002
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
2003
|
-
}
|
|
2004
|
-
}
|
|
1869
|
+
const {
|
|
1870
|
+
tools: openaiTools2,
|
|
1871
|
+
toolChoice: openaiToolChoice,
|
|
1872
|
+
toolWarnings
|
|
1873
|
+
} = prepareResponsesTools({
|
|
1874
|
+
tools,
|
|
1875
|
+
toolChoice,
|
|
1876
|
+
strict: isStrict
|
|
1877
|
+
});
|
|
1878
|
+
return {
|
|
1879
|
+
args: {
|
|
1880
|
+
...baseArgs,
|
|
1881
|
+
tools: openaiTools2,
|
|
1882
|
+
tool_choice: openaiToolChoice
|
|
1883
|
+
},
|
|
1884
|
+
warnings: [...warnings, ...toolWarnings]
|
|
1885
|
+
};
|
|
2005
1886
|
}
|
|
2006
1887
|
async doGenerate(options) {
|
|
2007
1888
|
var _a, _b, _c, _d, _e;
|
|
@@ -2019,49 +1900,49 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2019
1900
|
body,
|
|
2020
1901
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2021
1902
|
successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
|
|
2022
|
-
|
|
2023
|
-
id:
|
|
2024
|
-
created_at:
|
|
2025
|
-
model:
|
|
2026
|
-
output:
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
type:
|
|
2030
|
-
role:
|
|
2031
|
-
content:
|
|
2032
|
-
|
|
2033
|
-
type:
|
|
2034
|
-
text:
|
|
2035
|
-
annotations:
|
|
2036
|
-
|
|
2037
|
-
type:
|
|
2038
|
-
start_index:
|
|
2039
|
-
end_index:
|
|
2040
|
-
url:
|
|
2041
|
-
title:
|
|
1903
|
+
import_zod7.z.object({
|
|
1904
|
+
id: import_zod7.z.string(),
|
|
1905
|
+
created_at: import_zod7.z.number(),
|
|
1906
|
+
model: import_zod7.z.string(),
|
|
1907
|
+
output: import_zod7.z.array(
|
|
1908
|
+
import_zod7.z.discriminatedUnion("type", [
|
|
1909
|
+
import_zod7.z.object({
|
|
1910
|
+
type: import_zod7.z.literal("message"),
|
|
1911
|
+
role: import_zod7.z.literal("assistant"),
|
|
1912
|
+
content: import_zod7.z.array(
|
|
1913
|
+
import_zod7.z.object({
|
|
1914
|
+
type: import_zod7.z.literal("output_text"),
|
|
1915
|
+
text: import_zod7.z.string(),
|
|
1916
|
+
annotations: import_zod7.z.array(
|
|
1917
|
+
import_zod7.z.object({
|
|
1918
|
+
type: import_zod7.z.literal("url_citation"),
|
|
1919
|
+
start_index: import_zod7.z.number(),
|
|
1920
|
+
end_index: import_zod7.z.number(),
|
|
1921
|
+
url: import_zod7.z.string(),
|
|
1922
|
+
title: import_zod7.z.string()
|
|
2042
1923
|
})
|
|
2043
1924
|
)
|
|
2044
1925
|
})
|
|
2045
1926
|
)
|
|
2046
1927
|
}),
|
|
2047
|
-
|
|
2048
|
-
type:
|
|
2049
|
-
call_id:
|
|
2050
|
-
name:
|
|
2051
|
-
arguments:
|
|
1928
|
+
import_zod7.z.object({
|
|
1929
|
+
type: import_zod7.z.literal("function_call"),
|
|
1930
|
+
call_id: import_zod7.z.string(),
|
|
1931
|
+
name: import_zod7.z.string(),
|
|
1932
|
+
arguments: import_zod7.z.string()
|
|
2052
1933
|
}),
|
|
2053
|
-
|
|
2054
|
-
type:
|
|
1934
|
+
import_zod7.z.object({
|
|
1935
|
+
type: import_zod7.z.literal("web_search_call")
|
|
2055
1936
|
}),
|
|
2056
|
-
|
|
2057
|
-
type:
|
|
1937
|
+
import_zod7.z.object({
|
|
1938
|
+
type: import_zod7.z.literal("computer_call")
|
|
2058
1939
|
}),
|
|
2059
|
-
|
|
2060
|
-
type:
|
|
1940
|
+
import_zod7.z.object({
|
|
1941
|
+
type: import_zod7.z.literal("reasoning")
|
|
2061
1942
|
})
|
|
2062
1943
|
])
|
|
2063
1944
|
),
|
|
2064
|
-
incomplete_details:
|
|
1945
|
+
incomplete_details: import_zod7.z.object({ reason: import_zod7.z.string() }).nullable(),
|
|
2065
1946
|
usage: usageSchema
|
|
2066
1947
|
})
|
|
2067
1948
|
),
|
|
@@ -2259,79 +2140,79 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2259
2140
|
};
|
|
2260
2141
|
}
|
|
2261
2142
|
};
|
|
2262
|
-
var usageSchema =
|
|
2263
|
-
input_tokens:
|
|
2264
|
-
input_tokens_details:
|
|
2265
|
-
output_tokens:
|
|
2266
|
-
output_tokens_details:
|
|
2143
|
+
var usageSchema = import_zod7.z.object({
|
|
2144
|
+
input_tokens: import_zod7.z.number(),
|
|
2145
|
+
input_tokens_details: import_zod7.z.object({ cached_tokens: import_zod7.z.number().nullish() }).nullish(),
|
|
2146
|
+
output_tokens: import_zod7.z.number(),
|
|
2147
|
+
output_tokens_details: import_zod7.z.object({ reasoning_tokens: import_zod7.z.number().nullish() }).nullish()
|
|
2267
2148
|
});
|
|
2268
|
-
var textDeltaChunkSchema =
|
|
2269
|
-
type:
|
|
2270
|
-
delta:
|
|
2149
|
+
var textDeltaChunkSchema = import_zod7.z.object({
|
|
2150
|
+
type: import_zod7.z.literal("response.output_text.delta"),
|
|
2151
|
+
delta: import_zod7.z.string()
|
|
2271
2152
|
});
|
|
2272
|
-
var responseFinishedChunkSchema =
|
|
2273
|
-
type:
|
|
2274
|
-
response:
|
|
2275
|
-
incomplete_details:
|
|
2153
|
+
var responseFinishedChunkSchema = import_zod7.z.object({
|
|
2154
|
+
type: import_zod7.z.enum(["response.completed", "response.incomplete"]),
|
|
2155
|
+
response: import_zod7.z.object({
|
|
2156
|
+
incomplete_details: import_zod7.z.object({ reason: import_zod7.z.string() }).nullish(),
|
|
2276
2157
|
usage: usageSchema
|
|
2277
2158
|
})
|
|
2278
2159
|
});
|
|
2279
|
-
var responseCreatedChunkSchema =
|
|
2280
|
-
type:
|
|
2281
|
-
response:
|
|
2282
|
-
id:
|
|
2283
|
-
created_at:
|
|
2284
|
-
model:
|
|
2160
|
+
var responseCreatedChunkSchema = import_zod7.z.object({
|
|
2161
|
+
type: import_zod7.z.literal("response.created"),
|
|
2162
|
+
response: import_zod7.z.object({
|
|
2163
|
+
id: import_zod7.z.string(),
|
|
2164
|
+
created_at: import_zod7.z.number(),
|
|
2165
|
+
model: import_zod7.z.string()
|
|
2285
2166
|
})
|
|
2286
2167
|
});
|
|
2287
|
-
var responseOutputItemDoneSchema =
|
|
2288
|
-
type:
|
|
2289
|
-
output_index:
|
|
2290
|
-
item:
|
|
2291
|
-
|
|
2292
|
-
type:
|
|
2168
|
+
var responseOutputItemDoneSchema = import_zod7.z.object({
|
|
2169
|
+
type: import_zod7.z.literal("response.output_item.done"),
|
|
2170
|
+
output_index: import_zod7.z.number(),
|
|
2171
|
+
item: import_zod7.z.discriminatedUnion("type", [
|
|
2172
|
+
import_zod7.z.object({
|
|
2173
|
+
type: import_zod7.z.literal("message")
|
|
2293
2174
|
}),
|
|
2294
|
-
|
|
2295
|
-
type:
|
|
2296
|
-
id:
|
|
2297
|
-
call_id:
|
|
2298
|
-
name:
|
|
2299
|
-
arguments:
|
|
2300
|
-
status:
|
|
2175
|
+
import_zod7.z.object({
|
|
2176
|
+
type: import_zod7.z.literal("function_call"),
|
|
2177
|
+
id: import_zod7.z.string(),
|
|
2178
|
+
call_id: import_zod7.z.string(),
|
|
2179
|
+
name: import_zod7.z.string(),
|
|
2180
|
+
arguments: import_zod7.z.string(),
|
|
2181
|
+
status: import_zod7.z.literal("completed")
|
|
2301
2182
|
})
|
|
2302
2183
|
])
|
|
2303
2184
|
});
|
|
2304
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2305
|
-
type:
|
|
2306
|
-
item_id:
|
|
2307
|
-
output_index:
|
|
2308
|
-
delta:
|
|
2185
|
+
var responseFunctionCallArgumentsDeltaSchema = import_zod7.z.object({
|
|
2186
|
+
type: import_zod7.z.literal("response.function_call_arguments.delta"),
|
|
2187
|
+
item_id: import_zod7.z.string(),
|
|
2188
|
+
output_index: import_zod7.z.number(),
|
|
2189
|
+
delta: import_zod7.z.string()
|
|
2309
2190
|
});
|
|
2310
|
-
var responseOutputItemAddedSchema =
|
|
2311
|
-
type:
|
|
2312
|
-
output_index:
|
|
2313
|
-
item:
|
|
2314
|
-
|
|
2315
|
-
type:
|
|
2191
|
+
var responseOutputItemAddedSchema = import_zod7.z.object({
|
|
2192
|
+
type: import_zod7.z.literal("response.output_item.added"),
|
|
2193
|
+
output_index: import_zod7.z.number(),
|
|
2194
|
+
item: import_zod7.z.discriminatedUnion("type", [
|
|
2195
|
+
import_zod7.z.object({
|
|
2196
|
+
type: import_zod7.z.literal("message")
|
|
2316
2197
|
}),
|
|
2317
|
-
|
|
2318
|
-
type:
|
|
2319
|
-
id:
|
|
2320
|
-
call_id:
|
|
2321
|
-
name:
|
|
2322
|
-
arguments:
|
|
2198
|
+
import_zod7.z.object({
|
|
2199
|
+
type: import_zod7.z.literal("function_call"),
|
|
2200
|
+
id: import_zod7.z.string(),
|
|
2201
|
+
call_id: import_zod7.z.string(),
|
|
2202
|
+
name: import_zod7.z.string(),
|
|
2203
|
+
arguments: import_zod7.z.string()
|
|
2323
2204
|
})
|
|
2324
2205
|
])
|
|
2325
2206
|
});
|
|
2326
|
-
var responseAnnotationAddedSchema =
|
|
2327
|
-
type:
|
|
2328
|
-
annotation:
|
|
2329
|
-
type:
|
|
2330
|
-
url:
|
|
2331
|
-
title:
|
|
2207
|
+
var responseAnnotationAddedSchema = import_zod7.z.object({
|
|
2208
|
+
type: import_zod7.z.literal("response.output_text.annotation.added"),
|
|
2209
|
+
annotation: import_zod7.z.object({
|
|
2210
|
+
type: import_zod7.z.literal("url_citation"),
|
|
2211
|
+
url: import_zod7.z.string(),
|
|
2212
|
+
title: import_zod7.z.string()
|
|
2332
2213
|
})
|
|
2333
2214
|
});
|
|
2334
|
-
var openaiResponsesChunkSchema =
|
|
2215
|
+
var openaiResponsesChunkSchema = import_zod7.z.union([
|
|
2335
2216
|
textDeltaChunkSchema,
|
|
2336
2217
|
responseFinishedChunkSchema,
|
|
2337
2218
|
responseCreatedChunkSchema,
|
|
@@ -2339,7 +2220,7 @@ var openaiResponsesChunkSchema = import_zod6.z.union([
|
|
|
2339
2220
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2340
2221
|
responseOutputItemAddedSchema,
|
|
2341
2222
|
responseAnnotationAddedSchema,
|
|
2342
|
-
|
|
2223
|
+
import_zod7.z.object({ type: import_zod7.z.string() }).passthrough()
|
|
2343
2224
|
// fallback for unknown chunks
|
|
2344
2225
|
]);
|
|
2345
2226
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2384,38 +2265,17 @@ function getResponsesModelConfig(modelId) {
|
|
|
2384
2265
|
requiredAutoTruncation: false
|
|
2385
2266
|
};
|
|
2386
2267
|
}
|
|
2387
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2388
|
-
metadata:
|
|
2389
|
-
parallelToolCalls:
|
|
2390
|
-
previousResponseId:
|
|
2391
|
-
store:
|
|
2392
|
-
user:
|
|
2393
|
-
reasoningEffort:
|
|
2394
|
-
strictSchemas:
|
|
2395
|
-
instructions:
|
|
2268
|
+
var openaiResponsesProviderOptionsSchema = import_zod7.z.object({
|
|
2269
|
+
metadata: import_zod7.z.any().nullish(),
|
|
2270
|
+
parallelToolCalls: import_zod7.z.boolean().nullish(),
|
|
2271
|
+
previousResponseId: import_zod7.z.string().nullish(),
|
|
2272
|
+
store: import_zod7.z.boolean().nullish(),
|
|
2273
|
+
user: import_zod7.z.string().nullish(),
|
|
2274
|
+
reasoningEffort: import_zod7.z.string().nullish(),
|
|
2275
|
+
strictSchemas: import_zod7.z.boolean().nullish(),
|
|
2276
|
+
instructions: import_zod7.z.string().nullish()
|
|
2396
2277
|
});
|
|
2397
2278
|
|
|
2398
|
-
// src/openai-tools.ts
|
|
2399
|
-
var import_zod7 = require("zod");
|
|
2400
|
-
var WebSearchPreviewParameters = import_zod7.z.object({});
|
|
2401
|
-
function webSearchPreviewTool({
|
|
2402
|
-
searchContextSize,
|
|
2403
|
-
userLocation
|
|
2404
|
-
} = {}) {
|
|
2405
|
-
return {
|
|
2406
|
-
type: "provider-defined",
|
|
2407
|
-
id: "openai.web_search_preview",
|
|
2408
|
-
args: {
|
|
2409
|
-
searchContextSize,
|
|
2410
|
-
userLocation
|
|
2411
|
-
},
|
|
2412
|
-
parameters: WebSearchPreviewParameters
|
|
2413
|
-
};
|
|
2414
|
-
}
|
|
2415
|
-
var openaiTools = {
|
|
2416
|
-
webSearchPreview: webSearchPreviewTool
|
|
2417
|
-
};
|
|
2418
|
-
|
|
2419
2279
|
// src/openai-provider.ts
|
|
2420
2280
|
function createOpenAI(options = {}) {
|
|
2421
2281
|
var _a, _b, _c;
|