@ai-sdk/openai 4.0.64 → 4.0.66
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 +24 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +255 -49
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +7 -0
- package/dist/internal/index.js +164 -24
- package/dist/internal/index.js.map +1 -1
- package/package.json +3 -3
- package/src/chat/openai-chat-language-model.ts +11 -2
- package/src/chat/openai-chat-prepare-tools.ts +9 -2
- package/src/normalize-openai-json-schema.ts +161 -0
- package/src/openai-batch.ts +111 -29
- package/src/openai-config.ts +7 -0
- package/src/responses/openai-responses-language-model-options.ts +9 -0
- package/src/responses/openai-responses-language-model.ts +16 -3
- package/src/responses/openai-responses-prepare-tools.ts +16 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 4.0.66
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5ec21a6: fix: reject unsupported batch request types
|
|
8
|
+
- 7469a3b: feat: support image generation requests in batches
|
|
9
|
+
- 0de8886: fix(openai): allow providers to disable web search source includes
|
|
10
|
+
- d5e3024: fix(openai): remove propertyNames from JSON Schema
|
|
11
|
+
- Updated dependencies [5ec21a6]
|
|
12
|
+
- Updated dependencies [7469a3b]
|
|
13
|
+
- Updated dependencies [813bb36]
|
|
14
|
+
- Updated dependencies [c43e4b7]
|
|
15
|
+
- @ai-sdk/provider@4.0.14
|
|
16
|
+
- @ai-sdk/provider-utils@5.0.40
|
|
17
|
+
|
|
18
|
+
## 4.0.65
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 9942196: feat(openai): add batch cancellation and listing
|
|
23
|
+
- Updated dependencies [9942196]
|
|
24
|
+
- @ai-sdk/provider@4.0.13
|
|
25
|
+
- @ai-sdk/provider-utils@5.0.39
|
|
26
|
+
|
|
3
27
|
## 4.0.64
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1379,6 +1379,7 @@ type OpenAIResponsesModelId = 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-1106' | 'gpt
|
|
|
1379
1379
|
declare const openaiLanguageModelResponsesOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
1380
1380
|
conversation?: string | null | undefined;
|
|
1381
1381
|
include?: ("web_search_call.results" | "file_search_call.results" | "message.output_text.logprobs" | "reasoning.encrypted_content")[] | null | undefined;
|
|
1382
|
+
includeWebSearchSources?: boolean | undefined;
|
|
1382
1383
|
instructions?: string | null | undefined;
|
|
1383
1384
|
logprobs?: number | boolean | undefined;
|
|
1384
1385
|
maxToolCalls?: number | null | undefined;
|
|
@@ -1636,6 +1637,13 @@ type OpenAIConfig = {
|
|
|
1636
1637
|
* @see https://github.com/vercel/ai/issues/20180
|
|
1637
1638
|
*/
|
|
1638
1639
|
explicitMessageItemType?: boolean;
|
|
1640
|
+
/**
|
|
1641
|
+
* Whether the provider supports the
|
|
1642
|
+
* `web_search_call.action.sources` Responses API include value.
|
|
1643
|
+
*
|
|
1644
|
+
* Defaults to `true`.
|
|
1645
|
+
*/
|
|
1646
|
+
supportsWebSearchSourcesInclude?: boolean;
|
|
1639
1647
|
/**
|
|
1640
1648
|
* This is soft-deprecated. Use provider references (e.g. `{ openai: 'file-abc123' }`)
|
|
1641
1649
|
* in file part data instead. File ID prefixes used to identify file IDs
|
package/dist/index.js
CHANGED
|
@@ -918,9 +918,119 @@ var openaiLanguageModelChatOptions = lazySchema2(
|
|
|
918
918
|
);
|
|
919
919
|
|
|
920
920
|
// src/chat/openai-chat-prepare-tools.ts
|
|
921
|
+
import {
|
|
922
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
923
|
+
} from "@ai-sdk/provider";
|
|
924
|
+
|
|
925
|
+
// src/normalize-openai-json-schema.ts
|
|
921
926
|
import {
|
|
922
927
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
923
928
|
} from "@ai-sdk/provider";
|
|
929
|
+
function normalizeOpenAIJsonSchema(schema) {
|
|
930
|
+
let removedPropertyNames = false;
|
|
931
|
+
const normalizedSchema = normalizeSchema(schema);
|
|
932
|
+
return {
|
|
933
|
+
schema: normalizedSchema,
|
|
934
|
+
warnings: removedPropertyNames ? [
|
|
935
|
+
{
|
|
936
|
+
type: "compatibility",
|
|
937
|
+
feature: "JSON Schema propertyNames",
|
|
938
|
+
details: "OpenAI does not support JSON Schema propertyNames. It was removed before sending the schema, so OpenAI will not enforce property-name constraints."
|
|
939
|
+
}
|
|
940
|
+
] : []
|
|
941
|
+
};
|
|
942
|
+
function normalizeSchema(schema2) {
|
|
943
|
+
const propertyNames = schema2.propertyNames;
|
|
944
|
+
if (propertyNames != null) {
|
|
945
|
+
if (typeof propertyNames === "boolean" || propertyNames.type !== "string") {
|
|
946
|
+
throw new UnsupportedFunctionalityError2({
|
|
947
|
+
functionality: "JSON Schema propertyNames that does not use a string schema"
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
removedPropertyNames = true;
|
|
951
|
+
}
|
|
952
|
+
const normalizedSchema2 = { ...schema2 };
|
|
953
|
+
delete normalizedSchema2.propertyNames;
|
|
954
|
+
if (normalizedSchema2.properties != null) {
|
|
955
|
+
normalizedSchema2.properties = normalizeSchemaRecord(
|
|
956
|
+
normalizedSchema2.properties
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
if (normalizedSchema2.patternProperties != null) {
|
|
960
|
+
normalizedSchema2.patternProperties = normalizeSchemaRecord(
|
|
961
|
+
normalizedSchema2.patternProperties
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
if (normalizedSchema2.additionalProperties != null) {
|
|
965
|
+
normalizedSchema2.additionalProperties = normalizeDefinition(
|
|
966
|
+
normalizedSchema2.additionalProperties
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
if (normalizedSchema2.additionalItems != null) {
|
|
970
|
+
normalizedSchema2.additionalItems = normalizeDefinition(
|
|
971
|
+
normalizedSchema2.additionalItems
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
if (normalizedSchema2.items != null) {
|
|
975
|
+
normalizedSchema2.items = Array.isArray(normalizedSchema2.items) ? normalizedSchema2.items.map(normalizeDefinition) : normalizeDefinition(normalizedSchema2.items);
|
|
976
|
+
}
|
|
977
|
+
if (normalizedSchema2.contains != null) {
|
|
978
|
+
normalizedSchema2.contains = normalizeDefinition(
|
|
979
|
+
normalizedSchema2.contains
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
if (normalizedSchema2.not != null) {
|
|
983
|
+
normalizedSchema2.not = normalizeDefinition(normalizedSchema2.not);
|
|
984
|
+
}
|
|
985
|
+
if (normalizedSchema2.allOf != null) {
|
|
986
|
+
normalizedSchema2.allOf = normalizedSchema2.allOf.map(normalizeDefinition);
|
|
987
|
+
}
|
|
988
|
+
if (normalizedSchema2.anyOf != null) {
|
|
989
|
+
normalizedSchema2.anyOf = normalizedSchema2.anyOf.map(normalizeDefinition);
|
|
990
|
+
}
|
|
991
|
+
if (normalizedSchema2.oneOf != null) {
|
|
992
|
+
normalizedSchema2.oneOf = normalizedSchema2.oneOf.map(normalizeDefinition);
|
|
993
|
+
}
|
|
994
|
+
if (normalizedSchema2.definitions != null) {
|
|
995
|
+
normalizedSchema2.definitions = normalizeSchemaRecord(
|
|
996
|
+
normalizedSchema2.definitions
|
|
997
|
+
);
|
|
998
|
+
}
|
|
999
|
+
if (normalizedSchema2.$defs != null) {
|
|
1000
|
+
normalizedSchema2.$defs = normalizeSchemaRecord(normalizedSchema2.$defs);
|
|
1001
|
+
}
|
|
1002
|
+
if (normalizedSchema2.dependencies != null) {
|
|
1003
|
+
normalizedSchema2.dependencies = Object.fromEntries(
|
|
1004
|
+
Object.entries(normalizedSchema2.dependencies).map(
|
|
1005
|
+
([key, dependency]) => [
|
|
1006
|
+
key,
|
|
1007
|
+
Array.isArray(dependency) ? dependency : normalizeDefinition(dependency)
|
|
1008
|
+
]
|
|
1009
|
+
)
|
|
1010
|
+
);
|
|
1011
|
+
}
|
|
1012
|
+
for (const keyword of ["if", "then", "else"]) {
|
|
1013
|
+
const conditionalSchema = normalizedSchema2[keyword];
|
|
1014
|
+
if (conditionalSchema != null) {
|
|
1015
|
+
normalizedSchema2[keyword] = normalizeDefinition(conditionalSchema);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return normalizedSchema2;
|
|
1019
|
+
}
|
|
1020
|
+
function normalizeSchemaRecord(schemas) {
|
|
1021
|
+
return Object.fromEntries(
|
|
1022
|
+
Object.entries(schemas).map(([key, schema2]) => [
|
|
1023
|
+
key,
|
|
1024
|
+
normalizeDefinition(schema2)
|
|
1025
|
+
])
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
function normalizeDefinition(definition) {
|
|
1029
|
+
return typeof definition === "boolean" ? definition : normalizeSchema(definition);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// src/chat/openai-chat-prepare-tools.ts
|
|
924
1034
|
function prepareChatTools({
|
|
925
1035
|
tools,
|
|
926
1036
|
toolChoice
|
|
@@ -933,17 +1043,22 @@ function prepareChatTools({
|
|
|
933
1043
|
const openaiTools2 = [];
|
|
934
1044
|
for (const tool of tools) {
|
|
935
1045
|
switch (tool.type) {
|
|
936
|
-
case "function":
|
|
1046
|
+
case "function": {
|
|
1047
|
+
const normalizedInputSchema = normalizeOpenAIJsonSchema(
|
|
1048
|
+
tool.inputSchema
|
|
1049
|
+
);
|
|
1050
|
+
toolWarnings.push(...normalizedInputSchema.warnings);
|
|
937
1051
|
openaiTools2.push({
|
|
938
1052
|
type: "function",
|
|
939
1053
|
function: {
|
|
940
1054
|
name: tool.name,
|
|
941
1055
|
description: tool.description,
|
|
942
|
-
parameters:
|
|
1056
|
+
parameters: normalizedInputSchema.schema,
|
|
943
1057
|
...tool.strict != null ? { strict: tool.strict } : {}
|
|
944
1058
|
}
|
|
945
1059
|
});
|
|
946
1060
|
break;
|
|
1061
|
+
}
|
|
947
1062
|
default:
|
|
948
1063
|
toolWarnings.push({
|
|
949
1064
|
type: "unsupported",
|
|
@@ -974,7 +1089,7 @@ function prepareChatTools({
|
|
|
974
1089
|
};
|
|
975
1090
|
default: {
|
|
976
1091
|
const _exhaustiveCheck = type;
|
|
977
|
-
throw new
|
|
1092
|
+
throw new UnsupportedFunctionalityError3({
|
|
978
1093
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
979
1094
|
});
|
|
980
1095
|
}
|
|
@@ -1050,6 +1165,10 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1050
1165
|
);
|
|
1051
1166
|
warnings.push(...messageWarnings);
|
|
1052
1167
|
const strictJsonSchema = (_e = openaiOptions.strictJsonSchema) != null ? _e : true;
|
|
1168
|
+
const normalizedResponseFormatSchema = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
|
|
1169
|
+
if (normalizedResponseFormatSchema != null) {
|
|
1170
|
+
warnings.push(...normalizedResponseFormatSchema.warnings);
|
|
1171
|
+
}
|
|
1053
1172
|
const baseArgs = {
|
|
1054
1173
|
// model id:
|
|
1055
1174
|
model: this.modelId,
|
|
@@ -1065,10 +1184,10 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1065
1184
|
top_p: topP,
|
|
1066
1185
|
frequency_penalty: frequencyPenalty,
|
|
1067
1186
|
presence_penalty: presencePenalty,
|
|
1068
|
-
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ?
|
|
1187
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? normalizedResponseFormatSchema != null ? {
|
|
1069
1188
|
type: "json_schema",
|
|
1070
1189
|
json_schema: {
|
|
1071
|
-
schema:
|
|
1190
|
+
schema: normalizedResponseFormatSchema.schema,
|
|
1072
1191
|
strict: strictJsonSchema,
|
|
1073
1192
|
name: (_f = responseFormat.name) != null ? _f : "response",
|
|
1074
1193
|
description: responseFormat.description
|
|
@@ -1485,7 +1604,7 @@ function convertOpenAICompletionUsage(usage) {
|
|
|
1485
1604
|
// src/completion/convert-to-openai-completion-prompt.ts
|
|
1486
1605
|
import {
|
|
1487
1606
|
InvalidPromptError,
|
|
1488
|
-
UnsupportedFunctionalityError as
|
|
1607
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError4
|
|
1489
1608
|
} from "@ai-sdk/provider";
|
|
1490
1609
|
function convertToOpenAICompletionPrompt({
|
|
1491
1610
|
prompt,
|
|
@@ -1528,7 +1647,7 @@ ${userMessage}
|
|
|
1528
1647
|
return part.text;
|
|
1529
1648
|
}
|
|
1530
1649
|
case "tool-call": {
|
|
1531
|
-
throw new
|
|
1650
|
+
throw new UnsupportedFunctionalityError4({
|
|
1532
1651
|
functionality: "tool-call messages"
|
|
1533
1652
|
});
|
|
1534
1653
|
}
|
|
@@ -1541,7 +1660,7 @@ ${assistantMessage}
|
|
|
1541
1660
|
break;
|
|
1542
1661
|
}
|
|
1543
1662
|
case "tool": {
|
|
1544
|
-
throw new
|
|
1663
|
+
throw new UnsupportedFunctionalityError4({
|
|
1545
1664
|
functionality: "tool messages"
|
|
1546
1665
|
});
|
|
1547
1666
|
}
|
|
@@ -3562,7 +3681,8 @@ var openaiTools = {
|
|
|
3562
3681
|
// src/openai-batch.ts
|
|
3563
3682
|
import {
|
|
3564
3683
|
InvalidArgumentError as InvalidArgumentError2,
|
|
3565
|
-
InvalidResponseDataError as InvalidResponseDataError2
|
|
3684
|
+
InvalidResponseDataError as InvalidResponseDataError2,
|
|
3685
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError7
|
|
3566
3686
|
} from "@ai-sdk/provider";
|
|
3567
3687
|
import {
|
|
3568
3688
|
combineHeaders as combineHeaders7,
|
|
@@ -4723,7 +4843,7 @@ function prepareOpenAIConfigForWorkflowDeserialize(config) {
|
|
|
4723
4843
|
|
|
4724
4844
|
// src/responses/convert-to-openai-responses-input.ts
|
|
4725
4845
|
import {
|
|
4726
|
-
UnsupportedFunctionalityError as
|
|
4846
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError5
|
|
4727
4847
|
} from "@ai-sdk/provider";
|
|
4728
4848
|
import {
|
|
4729
4849
|
convertToBase64 as convertToBase642,
|
|
@@ -5143,7 +5263,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5143
5263
|
};
|
|
5144
5264
|
}
|
|
5145
5265
|
case "text": {
|
|
5146
|
-
throw new
|
|
5266
|
+
throw new UnsupportedFunctionalityError5({
|
|
5147
5267
|
functionality: "text file parts"
|
|
5148
5268
|
});
|
|
5149
5269
|
}
|
|
@@ -5173,7 +5293,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5173
5293
|
}
|
|
5174
5294
|
const fullMediaType = resolveFullMediaType2({ part });
|
|
5175
5295
|
if (fullMediaType !== "application/pdf" && !passThroughUnsupportedFiles) {
|
|
5176
|
-
throw new
|
|
5296
|
+
throw new UnsupportedFunctionalityError5({
|
|
5177
5297
|
functionality: `file part media type ${fullMediaType}`
|
|
5178
5298
|
});
|
|
5179
5299
|
}
|
|
@@ -5909,7 +6029,7 @@ ${text}`,
|
|
|
5909
6029
|
}
|
|
5910
6030
|
const resultCaller = (_P = (_O = part.providerOptions) == null ? void 0 : _O[providerOptionsName]) == null ? void 0 : _P.caller;
|
|
5911
6031
|
if (output.type === "execution-denied" && ((resultCaller == null ? void 0 : resultCaller.type) === "program" || programmaticToolCallIds.has(part.toolCallId))) {
|
|
5912
|
-
throw new
|
|
6032
|
+
throw new UnsupportedFunctionalityError5({
|
|
5913
6033
|
functionality: "execution-denied results for programmatic tool calls"
|
|
5914
6034
|
});
|
|
5915
6035
|
}
|
|
@@ -6060,6 +6180,14 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
|
|
|
6060
6180
|
"message.output_text.logprobs"
|
|
6061
6181
|
])
|
|
6062
6182
|
).nullish(),
|
|
6183
|
+
/**
|
|
6184
|
+
* Whether to automatically include web search action sources in the
|
|
6185
|
+
* response. Disable this for OpenAI-compatible providers that do not
|
|
6186
|
+
* support the `web_search_call.action.sources` include value.
|
|
6187
|
+
*
|
|
6188
|
+
* Defaults to `true`.
|
|
6189
|
+
*/
|
|
6190
|
+
includeWebSearchSources: z27.boolean().optional(),
|
|
6063
6191
|
/**
|
|
6064
6192
|
* Instructions for the model.
|
|
6065
6193
|
* They can be used to change the system or developer message when continuing a conversation using the `previousResponseId` option.
|
|
@@ -6259,7 +6387,7 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema25(
|
|
|
6259
6387
|
|
|
6260
6388
|
// src/responses/openai-responses-prepare-tools.ts
|
|
6261
6389
|
import {
|
|
6262
|
-
UnsupportedFunctionalityError as
|
|
6390
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError6
|
|
6263
6391
|
} from "@ai-sdk/provider";
|
|
6264
6392
|
import {
|
|
6265
6393
|
resolveProviderReference as resolveProviderReference3,
|
|
@@ -6307,6 +6435,7 @@ async function prepareResponsesTools({
|
|
|
6307
6435
|
const openaiFunctionTool = prepareFunctionTool({
|
|
6308
6436
|
tool,
|
|
6309
6437
|
options: openaiOptions,
|
|
6438
|
+
toolWarnings,
|
|
6310
6439
|
async: resolveAsyncToolOption({
|
|
6311
6440
|
value: openaiOptions == null ? void 0 : openaiOptions.async,
|
|
6312
6441
|
supportsAsyncToolCalling,
|
|
@@ -6329,7 +6458,7 @@ async function prepareResponsesTools({
|
|
|
6329
6458
|
namespaceTools.set(namespace.name, namespaceTool);
|
|
6330
6459
|
openaiTools2.push(namespaceTool);
|
|
6331
6460
|
} else if (namespaceTool.description !== namespace.description) {
|
|
6332
|
-
throw new
|
|
6461
|
+
throw new UnsupportedFunctionalityError6({
|
|
6333
6462
|
functionality: `conflicting descriptions for OpenAI tool namespace "${namespace.name}"`
|
|
6334
6463
|
});
|
|
6335
6464
|
}
|
|
@@ -6596,7 +6725,7 @@ async function prepareResponsesTools({
|
|
|
6596
6725
|
allowedToolEntries.push(resolution.entry);
|
|
6597
6726
|
}
|
|
6598
6727
|
if (allowedToolEntries.length === 0) {
|
|
6599
|
-
throw new
|
|
6728
|
+
throw new UnsupportedFunctionalityError6({
|
|
6600
6729
|
functionality: `allowedTools with only tools that cannot be allow-listed (${droppedToolNames.join(
|
|
6601
6730
|
", "
|
|
6602
6731
|
)})`
|
|
@@ -6631,7 +6760,7 @@ async function prepareResponsesTools({
|
|
|
6631
6760
|
}
|
|
6632
6761
|
default: {
|
|
6633
6762
|
const _exhaustiveCheck = type;
|
|
6634
|
-
throw new
|
|
6763
|
+
throw new UnsupportedFunctionalityError6({
|
|
6635
6764
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
6636
6765
|
});
|
|
6637
6766
|
}
|
|
@@ -6687,19 +6816,27 @@ function toAllowedToolResolution(tool) {
|
|
|
6687
6816
|
function prepareFunctionTool({
|
|
6688
6817
|
tool,
|
|
6689
6818
|
options,
|
|
6819
|
+
toolWarnings,
|
|
6690
6820
|
async
|
|
6691
6821
|
}) {
|
|
6822
|
+
var _a2;
|
|
6692
6823
|
const deferLoading = options == null ? void 0 : options.deferLoading;
|
|
6824
|
+
const normalizedInputSchema = normalizeOpenAIJsonSchema(tool.inputSchema);
|
|
6825
|
+
const normalizedOutputSchema = (options == null ? void 0 : options.outputSchema) != null ? normalizeOpenAIJsonSchema(options.outputSchema) : void 0;
|
|
6826
|
+
toolWarnings.push(
|
|
6827
|
+
...normalizedInputSchema.warnings,
|
|
6828
|
+
...(_a2 = normalizedOutputSchema == null ? void 0 : normalizedOutputSchema.warnings) != null ? _a2 : []
|
|
6829
|
+
);
|
|
6693
6830
|
return {
|
|
6694
6831
|
type: "function",
|
|
6695
6832
|
name: tool.name,
|
|
6696
6833
|
description: tool.description,
|
|
6697
|
-
parameters:
|
|
6834
|
+
parameters: normalizedInputSchema.schema,
|
|
6698
6835
|
...async != null ? { async } : {},
|
|
6699
6836
|
...tool.strict != null ? { strict: tool.strict } : {},
|
|
6700
6837
|
...deferLoading != null ? { defer_loading: deferLoading } : {},
|
|
6701
6838
|
...(options == null ? void 0 : options.allowedCallers) != null ? { allowed_callers: options.allowedCallers } : {},
|
|
6702
|
-
...(options == null ? void 0 : options.outputSchema) != null ? { output_schema:
|
|
6839
|
+
...(options == null ? void 0 : options.outputSchema) != null ? { output_schema: normalizedOutputSchema == null ? void 0 : normalizedOutputSchema.schema } : {}
|
|
6703
6840
|
};
|
|
6704
6841
|
}
|
|
6705
6842
|
function resolveAsyncToolOption({
|
|
@@ -7022,6 +7159,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7022
7159
|
input.push({ type: "compaction_trigger" });
|
|
7023
7160
|
}
|
|
7024
7161
|
const strictJsonSchema = (_g = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _g : true;
|
|
7162
|
+
const normalizedResponseFormatSchema = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
|
|
7163
|
+
if (normalizedResponseFormatSchema != null) {
|
|
7164
|
+
warnings.push(...normalizedResponseFormatSchema.warnings);
|
|
7165
|
+
}
|
|
7025
7166
|
let include = openaiOptions == null ? void 0 : openaiOptions.include;
|
|
7026
7167
|
function addInclude(key) {
|
|
7027
7168
|
if (include == null) {
|
|
@@ -7044,7 +7185,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7044
7185
|
const webSearchToolName = (_h = tools == null ? void 0 : tools.find(
|
|
7045
7186
|
(tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
7046
7187
|
)) == null ? void 0 : _h.name;
|
|
7047
|
-
if (webSearchToolName) {
|
|
7188
|
+
if (webSearchToolName && config.supportsWebSearchSourcesInclude !== false && (openaiOptions == null ? void 0 : openaiOptions.includeWebSearchSources) !== false) {
|
|
7048
7189
|
addInclude("web_search_call.action.sources");
|
|
7049
7190
|
}
|
|
7050
7191
|
if (hasOpenAITool("openai.code_interpreter")) {
|
|
@@ -7063,12 +7204,12 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7063
7204
|
...((responseFormat == null ? void 0 : responseFormat.type) === "json" || (openaiOptions == null ? void 0 : openaiOptions.textVerbosity)) && {
|
|
7064
7205
|
text: {
|
|
7065
7206
|
...(responseFormat == null ? void 0 : responseFormat.type) === "json" && {
|
|
7066
|
-
format:
|
|
7207
|
+
format: normalizedResponseFormatSchema != null ? {
|
|
7067
7208
|
type: "json_schema",
|
|
7068
7209
|
strict: strictJsonSchema,
|
|
7069
7210
|
name: (_i = responseFormat.name) != null ? _i : "response",
|
|
7070
7211
|
description: responseFormat.description,
|
|
7071
|
-
schema:
|
|
7212
|
+
schema: normalizedResponseFormatSchema.schema
|
|
7072
7213
|
} : { type: "json_object" }
|
|
7073
7214
|
},
|
|
7074
7215
|
...(openaiOptions == null ? void 0 : openaiOptions.textVerbosity) && {
|
|
@@ -9097,30 +9238,40 @@ var openaiBatchProviderOptionsSchema = lazySchema26(
|
|
|
9097
9238
|
})
|
|
9098
9239
|
)
|
|
9099
9240
|
);
|
|
9241
|
+
function assertTextBatchRequests(requests) {
|
|
9242
|
+
for (const request of requests) {
|
|
9243
|
+
const requestType = request.type;
|
|
9244
|
+
if (requestType !== "text") {
|
|
9245
|
+
throw new UnsupportedFunctionalityError7({
|
|
9246
|
+
functionality: `batch request type: ${requestType}`,
|
|
9247
|
+
message: `The OpenAI Batch API does not support batch requests with type "${requestType}".`
|
|
9248
|
+
});
|
|
9249
|
+
}
|
|
9250
|
+
}
|
|
9251
|
+
}
|
|
9252
|
+
var openaiBatchResponseZodSchema = () => z28.object({
|
|
9253
|
+
id: z28.string(),
|
|
9254
|
+
status: z28.string(),
|
|
9255
|
+
output_file_id: z28.string().nullish(),
|
|
9256
|
+
error_file_id: z28.string().nullish(),
|
|
9257
|
+
created_at: z28.number().nullish(),
|
|
9258
|
+
expires_at: z28.number().nullish(),
|
|
9259
|
+
request_counts: z28.object({
|
|
9260
|
+
total: z28.number().nullish(),
|
|
9261
|
+
completed: z28.number().nullish(),
|
|
9262
|
+
failed: z28.number().nullish()
|
|
9263
|
+
}).nullish(),
|
|
9264
|
+
errors: z28.object({
|
|
9265
|
+
data: z28.array(
|
|
9266
|
+
z28.object({
|
|
9267
|
+
code: z28.string().nullish(),
|
|
9268
|
+
message: z28.string().nullish()
|
|
9269
|
+
})
|
|
9270
|
+
).nullish()
|
|
9271
|
+
}).nullish()
|
|
9272
|
+
});
|
|
9100
9273
|
var openaiBatchResponseSchema = lazySchema26(
|
|
9101
|
-
() => zodSchema26(
|
|
9102
|
-
z28.object({
|
|
9103
|
-
id: z28.string(),
|
|
9104
|
-
status: z28.string(),
|
|
9105
|
-
output_file_id: z28.string().nullish(),
|
|
9106
|
-
error_file_id: z28.string().nullish(),
|
|
9107
|
-
created_at: z28.number().nullish(),
|
|
9108
|
-
expires_at: z28.number().nullish(),
|
|
9109
|
-
request_counts: z28.object({
|
|
9110
|
-
total: z28.number().nullish(),
|
|
9111
|
-
completed: z28.number().nullish(),
|
|
9112
|
-
failed: z28.number().nullish()
|
|
9113
|
-
}).nullish(),
|
|
9114
|
-
errors: z28.object({
|
|
9115
|
-
data: z28.array(
|
|
9116
|
-
z28.object({
|
|
9117
|
-
code: z28.string().nullish(),
|
|
9118
|
-
message: z28.string().nullish()
|
|
9119
|
-
})
|
|
9120
|
-
).nullish()
|
|
9121
|
-
}).nullish()
|
|
9122
|
-
})
|
|
9123
|
-
)
|
|
9274
|
+
() => zodSchema26(openaiBatchResponseZodSchema())
|
|
9124
9275
|
);
|
|
9125
9276
|
var openaiBatchResultLineSchema = lazySchema26(
|
|
9126
9277
|
() => zodSchema26(
|
|
@@ -9138,6 +9289,15 @@ var openaiBatchResultLineSchema = lazySchema26(
|
|
|
9138
9289
|
})
|
|
9139
9290
|
)
|
|
9140
9291
|
);
|
|
9292
|
+
var openaiBatchListResponseSchema = lazySchema26(
|
|
9293
|
+
() => zodSchema26(
|
|
9294
|
+
z28.object({
|
|
9295
|
+
data: z28.array(openaiBatchResponseZodSchema()),
|
|
9296
|
+
has_more: z28.boolean(),
|
|
9297
|
+
last_id: z28.string().nullish()
|
|
9298
|
+
})
|
|
9299
|
+
)
|
|
9300
|
+
);
|
|
9141
9301
|
var OpenAIBatch = class {
|
|
9142
9302
|
constructor(options) {
|
|
9143
9303
|
this.options = options;
|
|
@@ -9147,6 +9307,7 @@ var OpenAIBatch = class {
|
|
|
9147
9307
|
}
|
|
9148
9308
|
async doStartBatch(options) {
|
|
9149
9309
|
var _a2, _b, _c, _d, _e, _f;
|
|
9310
|
+
assertTextBatchRequests(options.requests);
|
|
9150
9311
|
validateSingleModel(options.requests);
|
|
9151
9312
|
const fileParts = [];
|
|
9152
9313
|
const warnings = options.webhookUrl == null ? [] : [
|
|
@@ -9273,6 +9434,51 @@ var OpenAIBatch = class {
|
|
|
9273
9434
|
const batch = await this.retrieveBatch(options);
|
|
9274
9435
|
return convertOpenAIBatchStatus(batch);
|
|
9275
9436
|
}
|
|
9437
|
+
async doCancelBatch(options) {
|
|
9438
|
+
var _a2, _b;
|
|
9439
|
+
await postJsonToApi6({
|
|
9440
|
+
url: this.getUrl(
|
|
9441
|
+
`/batches/${encodeURIComponent(options.batchId)}/cancel`
|
|
9442
|
+
),
|
|
9443
|
+
headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
9444
|
+
body: {},
|
|
9445
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
9446
|
+
successfulResponseHandler: createJsonResponseHandler7(
|
|
9447
|
+
openaiBatchResponseSchema
|
|
9448
|
+
),
|
|
9449
|
+
abortSignal: options.abortSignal,
|
|
9450
|
+
fetch: this.options.config.fetch
|
|
9451
|
+
});
|
|
9452
|
+
return {};
|
|
9453
|
+
}
|
|
9454
|
+
async doListBatches(options) {
|
|
9455
|
+
var _a2, _b;
|
|
9456
|
+
const url = new URL(this.getUrl("/batches"));
|
|
9457
|
+
if (options.limit != null) {
|
|
9458
|
+
url.searchParams.set("limit", String(options.limit));
|
|
9459
|
+
}
|
|
9460
|
+
if (options.cursor != null) {
|
|
9461
|
+
url.searchParams.set("after", options.cursor);
|
|
9462
|
+
}
|
|
9463
|
+
const { value: page } = await getFromApi2({
|
|
9464
|
+
url: url.toString(),
|
|
9465
|
+
headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
9466
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
9467
|
+
successfulResponseHandler: createJsonResponseHandler7(
|
|
9468
|
+
openaiBatchListResponseSchema
|
|
9469
|
+
),
|
|
9470
|
+
abortSignal: options.abortSignal,
|
|
9471
|
+
fetch: this.options.config.fetch,
|
|
9472
|
+
validateUrl: false
|
|
9473
|
+
});
|
|
9474
|
+
return {
|
|
9475
|
+
batches: page.data.map((batch) => ({
|
|
9476
|
+
batchId: batch.id,
|
|
9477
|
+
...convertOpenAIBatchStatus(batch)
|
|
9478
|
+
})),
|
|
9479
|
+
...page.has_more && page.last_id != null ? { nextCursor: page.last_id } : {}
|
|
9480
|
+
};
|
|
9481
|
+
}
|
|
9276
9482
|
async doGetBatchResults(options) {
|
|
9277
9483
|
const batch = await this.retrieveBatch(options);
|
|
9278
9484
|
const batchStatus = convertOpenAIBatchStatus(batch);
|
|
@@ -10219,7 +10425,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
10219
10425
|
|
|
10220
10426
|
// src/transcription/openai-transcription-model.ts
|
|
10221
10427
|
import {
|
|
10222
|
-
UnsupportedFunctionalityError as
|
|
10428
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError8
|
|
10223
10429
|
} from "@ai-sdk/provider";
|
|
10224
10430
|
import {
|
|
10225
10431
|
combineHeaders as combineHeaders9,
|
|
@@ -10509,7 +10715,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
10509
10715
|
async doGenerate(options) {
|
|
10510
10716
|
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
10511
10717
|
if (isRealtimeTranscriptionModelId(this.modelId)) {
|
|
10512
|
-
throw new
|
|
10718
|
+
throw new UnsupportedFunctionalityError8({
|
|
10513
10719
|
functionality: `non-streaming transcription with ${this.modelId}`
|
|
10514
10720
|
});
|
|
10515
10721
|
}
|
|
@@ -10576,7 +10782,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
10576
10782
|
async doStream(options) {
|
|
10577
10783
|
var _a2, _b, _c, _d, _e, _f, _g;
|
|
10578
10784
|
if (!isRealtimeTranscriptionModelId(this.modelId)) {
|
|
10579
|
-
throw new
|
|
10785
|
+
throw new UnsupportedFunctionalityError8({
|
|
10580
10786
|
functionality: `streaming transcription with ${this.modelId}`
|
|
10581
10787
|
});
|
|
10582
10788
|
}
|
|
@@ -11217,7 +11423,7 @@ var OpenAISkills = class {
|
|
|
11217
11423
|
};
|
|
11218
11424
|
|
|
11219
11425
|
// src/version.ts
|
|
11220
|
-
var VERSION = true ? "4.0.
|
|
11426
|
+
var VERSION = true ? "4.0.66" : "0.0.0-test";
|
|
11221
11427
|
|
|
11222
11428
|
// src/openai-provider.ts
|
|
11223
11429
|
function createOpenAI(options = {}) {
|