@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.mjs
CHANGED
|
@@ -78,7 +78,7 @@ function convertToOpenAIChatMessages({
|
|
|
78
78
|
image_url: {
|
|
79
79
|
url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${convertUint8ArrayToBase64(part.image)}`,
|
|
80
80
|
// OpenAI specific extension: image detail
|
|
81
|
-
detail: (_c = (_b = part.
|
|
81
|
+
detail: (_c = (_b = part.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
84
|
}
|
|
@@ -259,17 +259,16 @@ import {
|
|
|
259
259
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
260
260
|
} from "@ai-sdk/provider";
|
|
261
261
|
function prepareTools({
|
|
262
|
-
|
|
262
|
+
tools,
|
|
263
|
+
toolChoice,
|
|
263
264
|
useLegacyFunctionCalling = false,
|
|
264
265
|
structuredOutputs
|
|
265
266
|
}) {
|
|
266
|
-
|
|
267
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
267
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
268
268
|
const toolWarnings = [];
|
|
269
269
|
if (tools == null) {
|
|
270
|
-
return { tools: void 0,
|
|
270
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
271
271
|
}
|
|
272
|
-
const toolChoice = mode.toolChoice;
|
|
273
272
|
if (useLegacyFunctionCalling) {
|
|
274
273
|
const openaiFunctions = [];
|
|
275
274
|
for (const tool of tools) {
|
|
@@ -329,18 +328,18 @@ function prepareTools({
|
|
|
329
328
|
}
|
|
330
329
|
}
|
|
331
330
|
if (toolChoice == null) {
|
|
332
|
-
return { tools: openaiTools2,
|
|
331
|
+
return { tools: openaiTools2, toolChoice: void 0, toolWarnings };
|
|
333
332
|
}
|
|
334
333
|
const type = toolChoice.type;
|
|
335
334
|
switch (type) {
|
|
336
335
|
case "auto":
|
|
337
336
|
case "none":
|
|
338
337
|
case "required":
|
|
339
|
-
return { tools: openaiTools2,
|
|
338
|
+
return { tools: openaiTools2, toolChoice: type, toolWarnings };
|
|
340
339
|
case "tool":
|
|
341
340
|
return {
|
|
342
341
|
tools: openaiTools2,
|
|
343
|
-
|
|
342
|
+
toolChoice: {
|
|
344
343
|
type: "function",
|
|
345
344
|
function: {
|
|
346
345
|
name: toolChoice.toolName
|
|
@@ -360,7 +359,7 @@ function prepareTools({
|
|
|
360
359
|
// src/openai-chat-language-model.ts
|
|
361
360
|
var OpenAIChatLanguageModel = class {
|
|
362
361
|
constructor(modelId, settings, config) {
|
|
363
|
-
this.specificationVersion = "
|
|
362
|
+
this.specificationVersion = "v2";
|
|
364
363
|
this.modelId = modelId;
|
|
365
364
|
this.settings = settings;
|
|
366
365
|
this.config = config;
|
|
@@ -382,7 +381,6 @@ var OpenAIChatLanguageModel = class {
|
|
|
382
381
|
return !this.settings.downloadImages;
|
|
383
382
|
}
|
|
384
383
|
getArgs({
|
|
385
|
-
mode,
|
|
386
384
|
prompt,
|
|
387
385
|
maxTokens,
|
|
388
386
|
temperature,
|
|
@@ -393,10 +391,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
393
391
|
stopSequences,
|
|
394
392
|
responseFormat,
|
|
395
393
|
seed,
|
|
396
|
-
|
|
394
|
+
tools,
|
|
395
|
+
toolChoice,
|
|
396
|
+
providerOptions
|
|
397
397
|
}) {
|
|
398
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
399
|
-
const type = mode.type;
|
|
398
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
400
399
|
const warnings = [];
|
|
401
400
|
if (topK != null) {
|
|
402
401
|
warnings.push({
|
|
@@ -445,6 +444,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
445
444
|
top_p: topP,
|
|
446
445
|
frequency_penalty: frequencyPenalty,
|
|
447
446
|
presence_penalty: presencePenalty,
|
|
447
|
+
// TODO improve below:
|
|
448
448
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs && responseFormat.schema != null ? {
|
|
449
449
|
type: "json_schema",
|
|
450
450
|
json_schema: {
|
|
@@ -458,11 +458,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
458
458
|
seed,
|
|
459
459
|
// openai specific settings:
|
|
460
460
|
// TODO remove in next major version; we auto-map maxTokens now
|
|
461
|
-
max_completion_tokens: (_b =
|
|
462
|
-
store: (_c =
|
|
463
|
-
metadata: (_d =
|
|
464
|
-
prediction: (_e =
|
|
465
|
-
reasoning_effort: (_g = (_f =
|
|
461
|
+
max_completion_tokens: (_b = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _b.maxCompletionTokens,
|
|
462
|
+
store: (_c = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _c.store,
|
|
463
|
+
metadata: (_d = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _d.metadata,
|
|
464
|
+
prediction: (_e = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _e.prediction,
|
|
465
|
+
reasoning_effort: (_g = (_f = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _f.reasoningEffort) != null ? _g : this.settings.reasoningEffort,
|
|
466
466
|
// messages:
|
|
467
467
|
messages
|
|
468
468
|
};
|
|
@@ -527,81 +527,28 @@ var OpenAIChatLanguageModel = class {
|
|
|
527
527
|
baseArgs.max_tokens = void 0;
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
response_format: this.supportsStructuredOutputs && mode.schema != null ? {
|
|
553
|
-
type: "json_schema",
|
|
554
|
-
json_schema: {
|
|
555
|
-
schema: mode.schema,
|
|
556
|
-
strict: true,
|
|
557
|
-
name: (_h = mode.name) != null ? _h : "response",
|
|
558
|
-
description: mode.description
|
|
559
|
-
}
|
|
560
|
-
} : { type: "json_object" }
|
|
561
|
-
},
|
|
562
|
-
warnings
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
case "object-tool": {
|
|
566
|
-
return {
|
|
567
|
-
args: useLegacyFunctionCalling ? {
|
|
568
|
-
...baseArgs,
|
|
569
|
-
function_call: {
|
|
570
|
-
name: mode.tool.name
|
|
571
|
-
},
|
|
572
|
-
functions: [
|
|
573
|
-
{
|
|
574
|
-
name: mode.tool.name,
|
|
575
|
-
description: mode.tool.description,
|
|
576
|
-
parameters: mode.tool.parameters
|
|
577
|
-
}
|
|
578
|
-
]
|
|
579
|
-
} : {
|
|
580
|
-
...baseArgs,
|
|
581
|
-
tool_choice: {
|
|
582
|
-
type: "function",
|
|
583
|
-
function: { name: mode.tool.name }
|
|
584
|
-
},
|
|
585
|
-
tools: [
|
|
586
|
-
{
|
|
587
|
-
type: "function",
|
|
588
|
-
function: {
|
|
589
|
-
name: mode.tool.name,
|
|
590
|
-
description: mode.tool.description,
|
|
591
|
-
parameters: mode.tool.parameters,
|
|
592
|
-
strict: this.supportsStructuredOutputs ? true : void 0
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
]
|
|
596
|
-
},
|
|
597
|
-
warnings
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
default: {
|
|
601
|
-
const _exhaustiveCheck = type;
|
|
602
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
530
|
+
const {
|
|
531
|
+
tools: openaiTools2,
|
|
532
|
+
toolChoice: openaiToolChoice,
|
|
533
|
+
functions,
|
|
534
|
+
function_call,
|
|
535
|
+
toolWarnings
|
|
536
|
+
} = prepareTools({
|
|
537
|
+
tools,
|
|
538
|
+
toolChoice,
|
|
539
|
+
useLegacyFunctionCalling,
|
|
540
|
+
structuredOutputs: this.supportsStructuredOutputs
|
|
541
|
+
});
|
|
542
|
+
return {
|
|
543
|
+
args: {
|
|
544
|
+
...baseArgs,
|
|
545
|
+
tools: openaiTools2,
|
|
546
|
+
tool_choice: openaiToolChoice,
|
|
547
|
+
functions,
|
|
548
|
+
function_call
|
|
549
|
+
},
|
|
550
|
+
warnings: [...warnings, ...toolWarnings]
|
|
551
|
+
};
|
|
605
552
|
}
|
|
606
553
|
async doGenerate(options) {
|
|
607
554
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -1068,9 +1015,6 @@ var reasoningModels = {
|
|
|
1068
1015
|
};
|
|
1069
1016
|
|
|
1070
1017
|
// src/openai-completion-language-model.ts
|
|
1071
|
-
import {
|
|
1072
|
-
UnsupportedFunctionalityError as UnsupportedFunctionalityError5
|
|
1073
|
-
} from "@ai-sdk/provider";
|
|
1074
1018
|
import {
|
|
1075
1019
|
combineHeaders as combineHeaders2,
|
|
1076
1020
|
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
@@ -1183,7 +1127,7 @@ function mapOpenAICompletionLogProbs(logprobs) {
|
|
|
1183
1127
|
// src/openai-completion-language-model.ts
|
|
1184
1128
|
var OpenAICompletionLanguageModel = class {
|
|
1185
1129
|
constructor(modelId, settings, config) {
|
|
1186
|
-
this.specificationVersion = "
|
|
1130
|
+
this.specificationVersion = "v2";
|
|
1187
1131
|
this.defaultObjectGenerationMode = void 0;
|
|
1188
1132
|
this.modelId = modelId;
|
|
1189
1133
|
this.settings = settings;
|
|
@@ -1193,7 +1137,6 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1193
1137
|
return this.config.provider;
|
|
1194
1138
|
}
|
|
1195
1139
|
getArgs({
|
|
1196
|
-
mode,
|
|
1197
1140
|
inputFormat,
|
|
1198
1141
|
prompt,
|
|
1199
1142
|
maxTokens,
|
|
@@ -1204,16 +1147,19 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1204
1147
|
presencePenalty,
|
|
1205
1148
|
stopSequences: userStopSequences,
|
|
1206
1149
|
responseFormat,
|
|
1150
|
+
tools,
|
|
1151
|
+
toolChoice,
|
|
1207
1152
|
seed
|
|
1208
1153
|
}) {
|
|
1209
|
-
var _a;
|
|
1210
|
-
const type = mode.type;
|
|
1211
1154
|
const warnings = [];
|
|
1212
1155
|
if (topK != null) {
|
|
1213
|
-
warnings.push({
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
});
|
|
1156
|
+
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
1157
|
+
}
|
|
1158
|
+
if (tools == null ? void 0 : tools.length) {
|
|
1159
|
+
warnings.push({ type: "unsupported-setting", setting: "tools" });
|
|
1160
|
+
}
|
|
1161
|
+
if (toolChoice != null) {
|
|
1162
|
+
warnings.push({ type: "unsupported-setting", setting: "toolChoice" });
|
|
1217
1163
|
}
|
|
1218
1164
|
if (responseFormat != null && responseFormat.type !== "text") {
|
|
1219
1165
|
warnings.push({
|
|
@@ -1224,56 +1170,30 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1224
1170
|
}
|
|
1225
1171
|
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt, inputFormat });
|
|
1226
1172
|
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
|
-
|
|
1173
|
+
return {
|
|
1174
|
+
args: {
|
|
1175
|
+
// model id:
|
|
1176
|
+
model: this.modelId,
|
|
1177
|
+
// model specific settings:
|
|
1178
|
+
echo: this.settings.echo,
|
|
1179
|
+
logit_bias: this.settings.logitBias,
|
|
1180
|
+
logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
|
|
1181
|
+
suffix: this.settings.suffix,
|
|
1182
|
+
user: this.settings.user,
|
|
1183
|
+
// standardized settings:
|
|
1184
|
+
max_tokens: maxTokens,
|
|
1185
|
+
temperature,
|
|
1186
|
+
top_p: topP,
|
|
1187
|
+
frequency_penalty: frequencyPenalty,
|
|
1188
|
+
presence_penalty: presencePenalty,
|
|
1189
|
+
seed,
|
|
1190
|
+
// prompt:
|
|
1191
|
+
prompt: completionPrompt,
|
|
1192
|
+
// stop sequences:
|
|
1193
|
+
stop: stop.length > 0 ? stop : void 0
|
|
1194
|
+
},
|
|
1195
|
+
warnings
|
|
1247
1196
|
};
|
|
1248
|
-
switch (type) {
|
|
1249
|
-
case "regular": {
|
|
1250
|
-
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
|
1251
|
-
throw new UnsupportedFunctionalityError5({
|
|
1252
|
-
functionality: "tools"
|
|
1253
|
-
});
|
|
1254
|
-
}
|
|
1255
|
-
if (mode.toolChoice) {
|
|
1256
|
-
throw new UnsupportedFunctionalityError5({
|
|
1257
|
-
functionality: "toolChoice"
|
|
1258
|
-
});
|
|
1259
|
-
}
|
|
1260
|
-
return { args: baseArgs, warnings };
|
|
1261
|
-
}
|
|
1262
|
-
case "object-json": {
|
|
1263
|
-
throw new UnsupportedFunctionalityError5({
|
|
1264
|
-
functionality: "object-json mode"
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
case "object-tool": {
|
|
1268
|
-
throw new UnsupportedFunctionalityError5({
|
|
1269
|
-
functionality: "object-tool mode"
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1272
|
-
default: {
|
|
1273
|
-
const _exhaustiveCheck = type;
|
|
1274
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
1197
|
}
|
|
1278
1198
|
async doGenerate(options) {
|
|
1279
1199
|
const { args, warnings } = this.getArgs(options);
|
|
@@ -1611,6 +1531,27 @@ var openaiImageResponseSchema = z5.object({
|
|
|
1611
1531
|
data: z5.array(z5.object({ b64_json: z5.string() }))
|
|
1612
1532
|
});
|
|
1613
1533
|
|
|
1534
|
+
// src/openai-tools.ts
|
|
1535
|
+
import { z as z6 } from "zod";
|
|
1536
|
+
var WebSearchPreviewParameters = z6.object({});
|
|
1537
|
+
function webSearchPreviewTool({
|
|
1538
|
+
searchContextSize,
|
|
1539
|
+
userLocation
|
|
1540
|
+
} = {}) {
|
|
1541
|
+
return {
|
|
1542
|
+
type: "provider-defined",
|
|
1543
|
+
id: "openai.web_search_preview",
|
|
1544
|
+
args: {
|
|
1545
|
+
searchContextSize,
|
|
1546
|
+
userLocation
|
|
1547
|
+
},
|
|
1548
|
+
parameters: WebSearchPreviewParameters
|
|
1549
|
+
};
|
|
1550
|
+
}
|
|
1551
|
+
var openaiTools = {
|
|
1552
|
+
webSearchPreview: webSearchPreviewTool
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1614
1555
|
// src/responses/openai-responses-language-model.ts
|
|
1615
1556
|
import {
|
|
1616
1557
|
combineHeaders as combineHeaders5,
|
|
@@ -1620,11 +1561,11 @@ import {
|
|
|
1620
1561
|
parseProviderOptions,
|
|
1621
1562
|
postJsonToApi as postJsonToApi5
|
|
1622
1563
|
} from "@ai-sdk/provider-utils";
|
|
1623
|
-
import { z as
|
|
1564
|
+
import { z as z7 } from "zod";
|
|
1624
1565
|
|
|
1625
1566
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1626
1567
|
import {
|
|
1627
|
-
UnsupportedFunctionalityError as
|
|
1568
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError5
|
|
1628
1569
|
} from "@ai-sdk/provider";
|
|
1629
1570
|
import { convertUint8ArrayToBase64 as convertUint8ArrayToBase642 } from "@ai-sdk/provider-utils";
|
|
1630
1571
|
function convertToOpenAIResponsesMessages({
|
|
@@ -1675,12 +1616,12 @@ function convertToOpenAIResponsesMessages({
|
|
|
1675
1616
|
type: "input_image",
|
|
1676
1617
|
image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${convertUint8ArrayToBase642(part.image)}`,
|
|
1677
1618
|
// OpenAI specific extension: image detail
|
|
1678
|
-
detail: (_c = (_b = part.
|
|
1619
|
+
detail: (_c = (_b = part.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
1679
1620
|
};
|
|
1680
1621
|
}
|
|
1681
1622
|
case "file": {
|
|
1682
1623
|
if (part.data instanceof URL) {
|
|
1683
|
-
throw new
|
|
1624
|
+
throw new UnsupportedFunctionalityError5({
|
|
1684
1625
|
functionality: "File URLs in user messages"
|
|
1685
1626
|
});
|
|
1686
1627
|
}
|
|
@@ -1693,7 +1634,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1693
1634
|
};
|
|
1694
1635
|
}
|
|
1695
1636
|
default: {
|
|
1696
|
-
throw new
|
|
1637
|
+
throw new UnsupportedFunctionalityError5({
|
|
1697
1638
|
functionality: "Only PDF files are supported in user messages"
|
|
1698
1639
|
});
|
|
1699
1640
|
}
|
|
@@ -1766,19 +1707,18 @@ function mapOpenAIResponseFinishReason({
|
|
|
1766
1707
|
|
|
1767
1708
|
// src/responses/openai-responses-prepare-tools.ts
|
|
1768
1709
|
import {
|
|
1769
|
-
UnsupportedFunctionalityError as
|
|
1710
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError6
|
|
1770
1711
|
} from "@ai-sdk/provider";
|
|
1771
1712
|
function prepareResponsesTools({
|
|
1772
|
-
|
|
1713
|
+
tools,
|
|
1714
|
+
toolChoice,
|
|
1773
1715
|
strict
|
|
1774
1716
|
}) {
|
|
1775
|
-
|
|
1776
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
1717
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1777
1718
|
const toolWarnings = [];
|
|
1778
1719
|
if (tools == null) {
|
|
1779
|
-
return { tools: void 0,
|
|
1720
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
1780
1721
|
}
|
|
1781
|
-
const toolChoice = mode.toolChoice;
|
|
1782
1722
|
const openaiTools2 = [];
|
|
1783
1723
|
for (const tool of tools) {
|
|
1784
1724
|
switch (tool.type) {
|
|
@@ -1811,36 +1751,23 @@ function prepareResponsesTools({
|
|
|
1811
1751
|
}
|
|
1812
1752
|
}
|
|
1813
1753
|
if (toolChoice == null) {
|
|
1814
|
-
return { tools: openaiTools2,
|
|
1754
|
+
return { tools: openaiTools2, toolChoice: void 0, toolWarnings };
|
|
1815
1755
|
}
|
|
1816
1756
|
const type = toolChoice.type;
|
|
1817
1757
|
switch (type) {
|
|
1818
1758
|
case "auto":
|
|
1819
1759
|
case "none":
|
|
1820
1760
|
case "required":
|
|
1821
|
-
return { tools: openaiTools2,
|
|
1822
|
-
case "tool":
|
|
1823
|
-
if (toolChoice.toolName === "web_search_preview") {
|
|
1824
|
-
return {
|
|
1825
|
-
tools: openaiTools2,
|
|
1826
|
-
tool_choice: {
|
|
1827
|
-
type: "web_search_preview"
|
|
1828
|
-
},
|
|
1829
|
-
toolWarnings
|
|
1830
|
-
};
|
|
1831
|
-
}
|
|
1761
|
+
return { tools: openaiTools2, toolChoice: type, toolWarnings };
|
|
1762
|
+
case "tool":
|
|
1832
1763
|
return {
|
|
1833
1764
|
tools: openaiTools2,
|
|
1834
|
-
|
|
1835
|
-
type: "function",
|
|
1836
|
-
name: toolChoice.toolName
|
|
1837
|
-
},
|
|
1765
|
+
toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
1838
1766
|
toolWarnings
|
|
1839
1767
|
};
|
|
1840
|
-
}
|
|
1841
1768
|
default: {
|
|
1842
1769
|
const _exhaustiveCheck = type;
|
|
1843
|
-
throw new
|
|
1770
|
+
throw new UnsupportedFunctionalityError6({
|
|
1844
1771
|
functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
|
|
1845
1772
|
});
|
|
1846
1773
|
}
|
|
@@ -1850,7 +1777,7 @@ function prepareResponsesTools({
|
|
|
1850
1777
|
// src/responses/openai-responses-language-model.ts
|
|
1851
1778
|
var OpenAIResponsesLanguageModel = class {
|
|
1852
1779
|
constructor(modelId, config) {
|
|
1853
|
-
this.specificationVersion = "
|
|
1780
|
+
this.specificationVersion = "v2";
|
|
1854
1781
|
this.defaultObjectGenerationMode = "json";
|
|
1855
1782
|
this.modelId = modelId;
|
|
1856
1783
|
this.config = config;
|
|
@@ -1859,7 +1786,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1859
1786
|
return this.config.provider;
|
|
1860
1787
|
}
|
|
1861
1788
|
getArgs({
|
|
1862
|
-
mode,
|
|
1863
1789
|
maxTokens,
|
|
1864
1790
|
temperature,
|
|
1865
1791
|
stopSequences,
|
|
@@ -1869,24 +1795,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1869
1795
|
frequencyPenalty,
|
|
1870
1796
|
seed,
|
|
1871
1797
|
prompt,
|
|
1872
|
-
|
|
1798
|
+
providerOptions,
|
|
1799
|
+
tools,
|
|
1800
|
+
toolChoice,
|
|
1873
1801
|
responseFormat
|
|
1874
1802
|
}) {
|
|
1875
|
-
var _a, _b
|
|
1803
|
+
var _a, _b;
|
|
1876
1804
|
const warnings = [];
|
|
1877
1805
|
const modelConfig = getResponsesModelConfig(this.modelId);
|
|
1878
|
-
const type = mode.type;
|
|
1879
1806
|
if (topK != null) {
|
|
1880
|
-
warnings.push({
|
|
1881
|
-
type: "unsupported-setting",
|
|
1882
|
-
setting: "topK"
|
|
1883
|
-
});
|
|
1807
|
+
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
1884
1808
|
}
|
|
1885
1809
|
if (seed != null) {
|
|
1886
|
-
warnings.push({
|
|
1887
|
-
type: "unsupported-setting",
|
|
1888
|
-
setting: "seed"
|
|
1889
|
-
});
|
|
1810
|
+
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
1890
1811
|
}
|
|
1891
1812
|
if (presencePenalty != null) {
|
|
1892
1813
|
warnings.push({
|
|
@@ -1901,10 +1822,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1901
1822
|
});
|
|
1902
1823
|
}
|
|
1903
1824
|
if (stopSequences != null) {
|
|
1904
|
-
warnings.push({
|
|
1905
|
-
type: "unsupported-setting",
|
|
1906
|
-
setting: "stopSequences"
|
|
1907
|
-
});
|
|
1825
|
+
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
1908
1826
|
}
|
|
1909
1827
|
const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
|
|
1910
1828
|
prompt,
|
|
@@ -1913,7 +1831,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1913
1831
|
warnings.push(...messageWarnings);
|
|
1914
1832
|
const openaiOptions = parseProviderOptions({
|
|
1915
1833
|
provider: "openai",
|
|
1916
|
-
providerOptions
|
|
1834
|
+
providerOptions,
|
|
1917
1835
|
schema: openaiResponsesProviderOptionsSchema
|
|
1918
1836
|
});
|
|
1919
1837
|
const isStrict = (_a = openaiOptions == null ? void 0 : openaiOptions.strictSchemas) != null ? _a : true;
|
|
@@ -1967,62 +1885,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1967
1885
|
});
|
|
1968
1886
|
}
|
|
1969
1887
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
return {
|
|
1988
|
-
args: {
|
|
1989
|
-
...baseArgs,
|
|
1990
|
-
text: {
|
|
1991
|
-
format: mode.schema != null ? {
|
|
1992
|
-
type: "json_schema",
|
|
1993
|
-
strict: isStrict,
|
|
1994
|
-
name: (_c = mode.name) != null ? _c : "response",
|
|
1995
|
-
description: mode.description,
|
|
1996
|
-
schema: mode.schema
|
|
1997
|
-
} : { type: "json_object" }
|
|
1998
|
-
}
|
|
1999
|
-
},
|
|
2000
|
-
warnings
|
|
2001
|
-
};
|
|
2002
|
-
}
|
|
2003
|
-
case "object-tool": {
|
|
2004
|
-
return {
|
|
2005
|
-
args: {
|
|
2006
|
-
...baseArgs,
|
|
2007
|
-
tool_choice: { type: "function", name: mode.tool.name },
|
|
2008
|
-
tools: [
|
|
2009
|
-
{
|
|
2010
|
-
type: "function",
|
|
2011
|
-
name: mode.tool.name,
|
|
2012
|
-
description: mode.tool.description,
|
|
2013
|
-
parameters: mode.tool.parameters,
|
|
2014
|
-
strict: isStrict
|
|
2015
|
-
}
|
|
2016
|
-
]
|
|
2017
|
-
},
|
|
2018
|
-
warnings
|
|
2019
|
-
};
|
|
2020
|
-
}
|
|
2021
|
-
default: {
|
|
2022
|
-
const _exhaustiveCheck = type;
|
|
2023
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
1888
|
+
const {
|
|
1889
|
+
tools: openaiTools2,
|
|
1890
|
+
toolChoice: openaiToolChoice,
|
|
1891
|
+
toolWarnings
|
|
1892
|
+
} = prepareResponsesTools({
|
|
1893
|
+
tools,
|
|
1894
|
+
toolChoice,
|
|
1895
|
+
strict: isStrict
|
|
1896
|
+
});
|
|
1897
|
+
return {
|
|
1898
|
+
args: {
|
|
1899
|
+
...baseArgs,
|
|
1900
|
+
tools: openaiTools2,
|
|
1901
|
+
tool_choice: openaiToolChoice
|
|
1902
|
+
},
|
|
1903
|
+
warnings: [...warnings, ...toolWarnings]
|
|
1904
|
+
};
|
|
2026
1905
|
}
|
|
2027
1906
|
async doGenerate(options) {
|
|
2028
1907
|
var _a, _b, _c, _d, _e;
|
|
@@ -2040,49 +1919,49 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2040
1919
|
body,
|
|
2041
1920
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2042
1921
|
successfulResponseHandler: createJsonResponseHandler5(
|
|
2043
|
-
|
|
2044
|
-
id:
|
|
2045
|
-
created_at:
|
|
2046
|
-
model:
|
|
2047
|
-
output:
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
type:
|
|
2051
|
-
role:
|
|
2052
|
-
content:
|
|
2053
|
-
|
|
2054
|
-
type:
|
|
2055
|
-
text:
|
|
2056
|
-
annotations:
|
|
2057
|
-
|
|
2058
|
-
type:
|
|
2059
|
-
start_index:
|
|
2060
|
-
end_index:
|
|
2061
|
-
url:
|
|
2062
|
-
title:
|
|
1922
|
+
z7.object({
|
|
1923
|
+
id: z7.string(),
|
|
1924
|
+
created_at: z7.number(),
|
|
1925
|
+
model: z7.string(),
|
|
1926
|
+
output: z7.array(
|
|
1927
|
+
z7.discriminatedUnion("type", [
|
|
1928
|
+
z7.object({
|
|
1929
|
+
type: z7.literal("message"),
|
|
1930
|
+
role: z7.literal("assistant"),
|
|
1931
|
+
content: z7.array(
|
|
1932
|
+
z7.object({
|
|
1933
|
+
type: z7.literal("output_text"),
|
|
1934
|
+
text: z7.string(),
|
|
1935
|
+
annotations: z7.array(
|
|
1936
|
+
z7.object({
|
|
1937
|
+
type: z7.literal("url_citation"),
|
|
1938
|
+
start_index: z7.number(),
|
|
1939
|
+
end_index: z7.number(),
|
|
1940
|
+
url: z7.string(),
|
|
1941
|
+
title: z7.string()
|
|
2063
1942
|
})
|
|
2064
1943
|
)
|
|
2065
1944
|
})
|
|
2066
1945
|
)
|
|
2067
1946
|
}),
|
|
2068
|
-
|
|
2069
|
-
type:
|
|
2070
|
-
call_id:
|
|
2071
|
-
name:
|
|
2072
|
-
arguments:
|
|
1947
|
+
z7.object({
|
|
1948
|
+
type: z7.literal("function_call"),
|
|
1949
|
+
call_id: z7.string(),
|
|
1950
|
+
name: z7.string(),
|
|
1951
|
+
arguments: z7.string()
|
|
2073
1952
|
}),
|
|
2074
|
-
|
|
2075
|
-
type:
|
|
1953
|
+
z7.object({
|
|
1954
|
+
type: z7.literal("web_search_call")
|
|
2076
1955
|
}),
|
|
2077
|
-
|
|
2078
|
-
type:
|
|
1956
|
+
z7.object({
|
|
1957
|
+
type: z7.literal("computer_call")
|
|
2079
1958
|
}),
|
|
2080
|
-
|
|
2081
|
-
type:
|
|
1959
|
+
z7.object({
|
|
1960
|
+
type: z7.literal("reasoning")
|
|
2082
1961
|
})
|
|
2083
1962
|
])
|
|
2084
1963
|
),
|
|
2085
|
-
incomplete_details:
|
|
1964
|
+
incomplete_details: z7.object({ reason: z7.string() }).nullable(),
|
|
2086
1965
|
usage: usageSchema
|
|
2087
1966
|
})
|
|
2088
1967
|
),
|
|
@@ -2280,79 +2159,79 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2280
2159
|
};
|
|
2281
2160
|
}
|
|
2282
2161
|
};
|
|
2283
|
-
var usageSchema =
|
|
2284
|
-
input_tokens:
|
|
2285
|
-
input_tokens_details:
|
|
2286
|
-
output_tokens:
|
|
2287
|
-
output_tokens_details:
|
|
2162
|
+
var usageSchema = z7.object({
|
|
2163
|
+
input_tokens: z7.number(),
|
|
2164
|
+
input_tokens_details: z7.object({ cached_tokens: z7.number().nullish() }).nullish(),
|
|
2165
|
+
output_tokens: z7.number(),
|
|
2166
|
+
output_tokens_details: z7.object({ reasoning_tokens: z7.number().nullish() }).nullish()
|
|
2288
2167
|
});
|
|
2289
|
-
var textDeltaChunkSchema =
|
|
2290
|
-
type:
|
|
2291
|
-
delta:
|
|
2168
|
+
var textDeltaChunkSchema = z7.object({
|
|
2169
|
+
type: z7.literal("response.output_text.delta"),
|
|
2170
|
+
delta: z7.string()
|
|
2292
2171
|
});
|
|
2293
|
-
var responseFinishedChunkSchema =
|
|
2294
|
-
type:
|
|
2295
|
-
response:
|
|
2296
|
-
incomplete_details:
|
|
2172
|
+
var responseFinishedChunkSchema = z7.object({
|
|
2173
|
+
type: z7.enum(["response.completed", "response.incomplete"]),
|
|
2174
|
+
response: z7.object({
|
|
2175
|
+
incomplete_details: z7.object({ reason: z7.string() }).nullish(),
|
|
2297
2176
|
usage: usageSchema
|
|
2298
2177
|
})
|
|
2299
2178
|
});
|
|
2300
|
-
var responseCreatedChunkSchema =
|
|
2301
|
-
type:
|
|
2302
|
-
response:
|
|
2303
|
-
id:
|
|
2304
|
-
created_at:
|
|
2305
|
-
model:
|
|
2179
|
+
var responseCreatedChunkSchema = z7.object({
|
|
2180
|
+
type: z7.literal("response.created"),
|
|
2181
|
+
response: z7.object({
|
|
2182
|
+
id: z7.string(),
|
|
2183
|
+
created_at: z7.number(),
|
|
2184
|
+
model: z7.string()
|
|
2306
2185
|
})
|
|
2307
2186
|
});
|
|
2308
|
-
var responseOutputItemDoneSchema =
|
|
2309
|
-
type:
|
|
2310
|
-
output_index:
|
|
2311
|
-
item:
|
|
2312
|
-
|
|
2313
|
-
type:
|
|
2187
|
+
var responseOutputItemDoneSchema = z7.object({
|
|
2188
|
+
type: z7.literal("response.output_item.done"),
|
|
2189
|
+
output_index: z7.number(),
|
|
2190
|
+
item: z7.discriminatedUnion("type", [
|
|
2191
|
+
z7.object({
|
|
2192
|
+
type: z7.literal("message")
|
|
2314
2193
|
}),
|
|
2315
|
-
|
|
2316
|
-
type:
|
|
2317
|
-
id:
|
|
2318
|
-
call_id:
|
|
2319
|
-
name:
|
|
2320
|
-
arguments:
|
|
2321
|
-
status:
|
|
2194
|
+
z7.object({
|
|
2195
|
+
type: z7.literal("function_call"),
|
|
2196
|
+
id: z7.string(),
|
|
2197
|
+
call_id: z7.string(),
|
|
2198
|
+
name: z7.string(),
|
|
2199
|
+
arguments: z7.string(),
|
|
2200
|
+
status: z7.literal("completed")
|
|
2322
2201
|
})
|
|
2323
2202
|
])
|
|
2324
2203
|
});
|
|
2325
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2326
|
-
type:
|
|
2327
|
-
item_id:
|
|
2328
|
-
output_index:
|
|
2329
|
-
delta:
|
|
2204
|
+
var responseFunctionCallArgumentsDeltaSchema = z7.object({
|
|
2205
|
+
type: z7.literal("response.function_call_arguments.delta"),
|
|
2206
|
+
item_id: z7.string(),
|
|
2207
|
+
output_index: z7.number(),
|
|
2208
|
+
delta: z7.string()
|
|
2330
2209
|
});
|
|
2331
|
-
var responseOutputItemAddedSchema =
|
|
2332
|
-
type:
|
|
2333
|
-
output_index:
|
|
2334
|
-
item:
|
|
2335
|
-
|
|
2336
|
-
type:
|
|
2210
|
+
var responseOutputItemAddedSchema = z7.object({
|
|
2211
|
+
type: z7.literal("response.output_item.added"),
|
|
2212
|
+
output_index: z7.number(),
|
|
2213
|
+
item: z7.discriminatedUnion("type", [
|
|
2214
|
+
z7.object({
|
|
2215
|
+
type: z7.literal("message")
|
|
2337
2216
|
}),
|
|
2338
|
-
|
|
2339
|
-
type:
|
|
2340
|
-
id:
|
|
2341
|
-
call_id:
|
|
2342
|
-
name:
|
|
2343
|
-
arguments:
|
|
2217
|
+
z7.object({
|
|
2218
|
+
type: z7.literal("function_call"),
|
|
2219
|
+
id: z7.string(),
|
|
2220
|
+
call_id: z7.string(),
|
|
2221
|
+
name: z7.string(),
|
|
2222
|
+
arguments: z7.string()
|
|
2344
2223
|
})
|
|
2345
2224
|
])
|
|
2346
2225
|
});
|
|
2347
|
-
var responseAnnotationAddedSchema =
|
|
2348
|
-
type:
|
|
2349
|
-
annotation:
|
|
2350
|
-
type:
|
|
2351
|
-
url:
|
|
2352
|
-
title:
|
|
2226
|
+
var responseAnnotationAddedSchema = z7.object({
|
|
2227
|
+
type: z7.literal("response.output_text.annotation.added"),
|
|
2228
|
+
annotation: z7.object({
|
|
2229
|
+
type: z7.literal("url_citation"),
|
|
2230
|
+
url: z7.string(),
|
|
2231
|
+
title: z7.string()
|
|
2353
2232
|
})
|
|
2354
2233
|
});
|
|
2355
|
-
var openaiResponsesChunkSchema =
|
|
2234
|
+
var openaiResponsesChunkSchema = z7.union([
|
|
2356
2235
|
textDeltaChunkSchema,
|
|
2357
2236
|
responseFinishedChunkSchema,
|
|
2358
2237
|
responseCreatedChunkSchema,
|
|
@@ -2360,7 +2239,7 @@ var openaiResponsesChunkSchema = z6.union([
|
|
|
2360
2239
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2361
2240
|
responseOutputItemAddedSchema,
|
|
2362
2241
|
responseAnnotationAddedSchema,
|
|
2363
|
-
|
|
2242
|
+
z7.object({ type: z7.string() }).passthrough()
|
|
2364
2243
|
// fallback for unknown chunks
|
|
2365
2244
|
]);
|
|
2366
2245
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2405,38 +2284,17 @@ function getResponsesModelConfig(modelId) {
|
|
|
2405
2284
|
requiredAutoTruncation: false
|
|
2406
2285
|
};
|
|
2407
2286
|
}
|
|
2408
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2409
|
-
metadata:
|
|
2410
|
-
parallelToolCalls:
|
|
2411
|
-
previousResponseId:
|
|
2412
|
-
store:
|
|
2413
|
-
user:
|
|
2414
|
-
reasoningEffort:
|
|
2415
|
-
strictSchemas:
|
|
2416
|
-
instructions:
|
|
2287
|
+
var openaiResponsesProviderOptionsSchema = z7.object({
|
|
2288
|
+
metadata: z7.any().nullish(),
|
|
2289
|
+
parallelToolCalls: z7.boolean().nullish(),
|
|
2290
|
+
previousResponseId: z7.string().nullish(),
|
|
2291
|
+
store: z7.boolean().nullish(),
|
|
2292
|
+
user: z7.string().nullish(),
|
|
2293
|
+
reasoningEffort: z7.string().nullish(),
|
|
2294
|
+
strictSchemas: z7.boolean().nullish(),
|
|
2295
|
+
instructions: z7.string().nullish()
|
|
2417
2296
|
});
|
|
2418
2297
|
|
|
2419
|
-
// src/openai-tools.ts
|
|
2420
|
-
import { z as z7 } from "zod";
|
|
2421
|
-
var WebSearchPreviewParameters = z7.object({});
|
|
2422
|
-
function webSearchPreviewTool({
|
|
2423
|
-
searchContextSize,
|
|
2424
|
-
userLocation
|
|
2425
|
-
} = {}) {
|
|
2426
|
-
return {
|
|
2427
|
-
type: "provider-defined",
|
|
2428
|
-
id: "openai.web_search_preview",
|
|
2429
|
-
args: {
|
|
2430
|
-
searchContextSize,
|
|
2431
|
-
userLocation
|
|
2432
|
-
},
|
|
2433
|
-
parameters: WebSearchPreviewParameters
|
|
2434
|
-
};
|
|
2435
|
-
}
|
|
2436
|
-
var openaiTools = {
|
|
2437
|
-
webSearchPreview: webSearchPreviewTool
|
|
2438
|
-
};
|
|
2439
|
-
|
|
2440
2298
|
// src/openai-provider.ts
|
|
2441
2299
|
function createOpenAI(options = {}) {
|
|
2442
2300
|
var _a, _b, _c;
|