@ai-sdk/openai 4.0.65 → 4.0.67
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 +34 -0
- package/README.md +26 -1
- package/dist/index.d.ts +133 -28
- package/dist/index.js +787 -130
- 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/docs/03-openai.mdx +102 -7
- 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/index.ts +10 -0
- package/src/live/openai-live-event-mapper.ts +286 -0
- package/src/live/openai-live-session-config.ts +145 -0
- package/src/live/openai-realtime-model-live-options.ts +65 -0
- package/src/live/openai-realtime-model-live.ts +107 -0
- package/src/normalize-openai-json-schema.ts +161 -0
- package/src/openai-batch.ts +16 -0
- package/src/openai-config.ts +7 -0
- package/src/openai-provider.ts +11 -32
- package/src/realtime/openai-realtime-event-mapper.ts +8 -1
- package/src/realtime/openai-realtime-factory.ts +88 -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/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,6 +9238,17 @@ 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
|
+
}
|
|
9100
9252
|
var openaiBatchResponseZodSchema = () => z28.object({
|
|
9101
9253
|
id: z28.string(),
|
|
9102
9254
|
status: z28.string(),
|
|
@@ -9155,6 +9307,7 @@ var OpenAIBatch = class {
|
|
|
9155
9307
|
}
|
|
9156
9308
|
async doStartBatch(options) {
|
|
9157
9309
|
var _a2, _b, _c, _d, _e, _f;
|
|
9310
|
+
assertTextBatchRequests(options.requests);
|
|
9158
9311
|
validateSingleModel(options.requests);
|
|
9159
9312
|
const fileParts = [];
|
|
9160
9313
|
const warnings = options.webhookUrl == null ? [] : [
|
|
@@ -9745,9 +9898,486 @@ async function convertOpenAIBatchResult(body) {
|
|
|
9745
9898
|
};
|
|
9746
9899
|
}
|
|
9747
9900
|
|
|
9901
|
+
// src/realtime/openai-realtime-factory.ts
|
|
9902
|
+
import {
|
|
9903
|
+
InvalidArgumentError as InvalidArgumentError4,
|
|
9904
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError10
|
|
9905
|
+
} from "@ai-sdk/provider";
|
|
9906
|
+
|
|
9907
|
+
// src/live/openai-realtime-model-live.ts
|
|
9908
|
+
import {
|
|
9909
|
+
createJsonResponseHandler as createJsonResponseHandler8,
|
|
9910
|
+
postJsonToApi as postJsonToApi7
|
|
9911
|
+
} from "@ai-sdk/provider-utils";
|
|
9912
|
+
import { z as z32 } from "zod/v4";
|
|
9913
|
+
|
|
9914
|
+
// src/live/openai-live-event-mapper.ts
|
|
9915
|
+
import {
|
|
9916
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError9
|
|
9917
|
+
} from "@ai-sdk/provider";
|
|
9918
|
+
import { z as z31 } from "zod/v4";
|
|
9919
|
+
|
|
9920
|
+
// src/live/openai-live-session-config.ts
|
|
9921
|
+
import {
|
|
9922
|
+
InvalidArgumentError as InvalidArgumentError3,
|
|
9923
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError8
|
|
9924
|
+
} from "@ai-sdk/provider";
|
|
9925
|
+
import { z as z30 } from "zod/v4";
|
|
9926
|
+
|
|
9927
|
+
// src/live/openai-realtime-model-live-options.ts
|
|
9928
|
+
import { z as z29 } from "zod/v4";
|
|
9929
|
+
var serverEventSelectorSchema = z29.strictObject({
|
|
9930
|
+
type: z29.string(),
|
|
9931
|
+
responseEvent: z29.string().optional()
|
|
9932
|
+
}).refine(
|
|
9933
|
+
(selector) => selector.type === "response.event" === (selector.responseEvent !== void 0),
|
|
9934
|
+
"responseEvent is required for response.event and forbidden for other event types."
|
|
9935
|
+
);
|
|
9936
|
+
var openaiRealtimeModelLiveOptionsSchema = z29.strictObject({
|
|
9937
|
+
client: z29.strictObject({
|
|
9938
|
+
dataChannel: z29.strictObject({
|
|
9939
|
+
allowedClientEvents: z29.union([z29.literal("all"), z29.array(z29.string())]).optional(),
|
|
9940
|
+
allowedServerEvents: z29.union([z29.literal("all"), z29.array(serverEventSelectorSchema)]).optional()
|
|
9941
|
+
})
|
|
9942
|
+
}).optional(),
|
|
9943
|
+
delegation: z29.strictObject({ type: z29.literal("client") }).nullable().optional(),
|
|
9944
|
+
input: z29.array(
|
|
9945
|
+
z29.discriminatedUnion("role", [
|
|
9946
|
+
z29.strictObject({
|
|
9947
|
+
type: z29.literal("message"),
|
|
9948
|
+
role: z29.enum(["developer", "user"]),
|
|
9949
|
+
content: z29.tuple([
|
|
9950
|
+
z29.strictObject({ type: z29.literal("input_text"), text: z29.string() })
|
|
9951
|
+
])
|
|
9952
|
+
}),
|
|
9953
|
+
z29.strictObject({
|
|
9954
|
+
type: z29.literal("message"),
|
|
9955
|
+
role: z29.literal("assistant"),
|
|
9956
|
+
content: z29.tuple([
|
|
9957
|
+
z29.strictObject({
|
|
9958
|
+
type: z29.enum(["text", "output_text"]),
|
|
9959
|
+
text: z29.string()
|
|
9960
|
+
})
|
|
9961
|
+
])
|
|
9962
|
+
})
|
|
9963
|
+
])
|
|
9964
|
+
).max(128).optional(),
|
|
9965
|
+
store: z29.boolean().optional(),
|
|
9966
|
+
voice: z29.strictObject({ id: z29.string().min(1) }).optional()
|
|
9967
|
+
});
|
|
9968
|
+
|
|
9969
|
+
// src/live/openai-live-session-config.ts
|
|
9970
|
+
var audioFormatSchema = z30.union([
|
|
9971
|
+
z30.strictObject({
|
|
9972
|
+
type: z30.literal("audio/pcm"),
|
|
9973
|
+
rate: z30.union([z30.literal(16e3), z30.literal(24e3)])
|
|
9974
|
+
}),
|
|
9975
|
+
z30.strictObject({
|
|
9976
|
+
type: z30.enum(["audio/pcma", "audio/pcmu"]),
|
|
9977
|
+
rate: z30.literal(8e3)
|
|
9978
|
+
})
|
|
9979
|
+
]);
|
|
9980
|
+
function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket") {
|
|
9981
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
9982
|
+
for (const key of Object.keys(config)) {
|
|
9983
|
+
if (![
|
|
9984
|
+
"instructions",
|
|
9985
|
+
"voice",
|
|
9986
|
+
"inputAudioFormat",
|
|
9987
|
+
"outputAudioFormat",
|
|
9988
|
+
"providerOptions"
|
|
9989
|
+
].includes(key)) {
|
|
9990
|
+
throw new UnsupportedFunctionalityError8({
|
|
9991
|
+
functionality: `OpenAI Live session setting: ${key}`
|
|
9992
|
+
});
|
|
9993
|
+
}
|
|
9994
|
+
}
|
|
9995
|
+
if (z30.object({ delegation: z30.object({ type: z30.literal("responses") }) }).safeParse((_a2 = config.providerOptions) == null ? void 0 : _a2.openai).success) {
|
|
9996
|
+
throw new UnsupportedFunctionalityError8({
|
|
9997
|
+
functionality: "OpenAI Live Responses delegation; only client delegation is supported"
|
|
9998
|
+
});
|
|
9999
|
+
}
|
|
10000
|
+
const options = openaiRealtimeModelLiveOptionsSchema.parse(
|
|
10001
|
+
(_c = (_b = config.providerOptions) == null ? void 0 : _b.openai) != null ? _c : {}
|
|
10002
|
+
);
|
|
10003
|
+
if (options.client !== void 0 && transport !== "webrtc") {
|
|
10004
|
+
throw new UnsupportedFunctionalityError8({
|
|
10005
|
+
functionality: "OpenAI Live client permissions outside WebRTC startup"
|
|
10006
|
+
});
|
|
10007
|
+
}
|
|
10008
|
+
if (options.voice != null && config.voice != null) {
|
|
10009
|
+
throw new InvalidArgumentError3({
|
|
10010
|
+
argument: "voice",
|
|
10011
|
+
message: "Choose either voice or providerOptions.openai.voice."
|
|
10012
|
+
});
|
|
10013
|
+
}
|
|
10014
|
+
if (transport === "webrtc" && (config.inputAudioFormat !== void 0 || config.outputAudioFormat !== void 0)) {
|
|
10015
|
+
throw new UnsupportedFunctionalityError8({
|
|
10016
|
+
functionality: "Fixed audio formats for OpenAI Live WebRTC; audio is negotiated through SDP"
|
|
10017
|
+
});
|
|
10018
|
+
}
|
|
10019
|
+
const inputFormat = config.inputAudioFormat == null ? void 0 : audioFormatSchema.parse(config.inputAudioFormat);
|
|
10020
|
+
const outputFormat = config.outputAudioFormat == null ? void 0 : audioFormatSchema.parse(config.outputAudioFormat);
|
|
10021
|
+
if (inputFormat != null && outputFormat != null && (inputFormat.type !== outputFormat.type || inputFormat.rate !== outputFormat.rate)) {
|
|
10022
|
+
throw new InvalidArgumentError3({
|
|
10023
|
+
argument: "outputAudioFormat",
|
|
10024
|
+
message: "OpenAI Live requires the same input and output audio format."
|
|
10025
|
+
});
|
|
10026
|
+
}
|
|
10027
|
+
return {
|
|
10028
|
+
model: modelId,
|
|
10029
|
+
...config.instructions !== void 0 ? { instructions: config.instructions } : {},
|
|
10030
|
+
audio: {
|
|
10031
|
+
...transport === "websocket" ? {
|
|
10032
|
+
format: (_d = inputFormat != null ? inputFormat : outputFormat) != null ? _d : { type: "audio/pcm", rate: 24e3 }
|
|
10033
|
+
} : {},
|
|
10034
|
+
output: { voice: (_f = (_e = options.voice) != null ? _e : config.voice) != null ? _f : "marin" }
|
|
10035
|
+
},
|
|
10036
|
+
...options.delegation !== void 0 ? { delegation: options.delegation } : {},
|
|
10037
|
+
...options.client !== void 0 ? {
|
|
10038
|
+
client: {
|
|
10039
|
+
data_channel: {
|
|
10040
|
+
...options.client.dataChannel.allowedClientEvents !== void 0 ? {
|
|
10041
|
+
allowed_client_events: options.client.dataChannel.allowedClientEvents
|
|
10042
|
+
} : {},
|
|
10043
|
+
...options.client.dataChannel.allowedServerEvents !== void 0 ? {
|
|
10044
|
+
allowed_server_events: options.client.dataChannel.allowedServerEvents === "all" ? "all" : options.client.dataChannel.allowedServerEvents.map(
|
|
10045
|
+
(selector) => ({
|
|
10046
|
+
type: selector.type,
|
|
10047
|
+
...selector.responseEvent !== void 0 ? { response_event: selector.responseEvent } : {}
|
|
10048
|
+
})
|
|
10049
|
+
)
|
|
10050
|
+
} : {}
|
|
10051
|
+
}
|
|
10052
|
+
}
|
|
10053
|
+
} : {},
|
|
10054
|
+
...options.input !== void 0 ? { input: options.input } : {},
|
|
10055
|
+
...options.store !== void 0 ? { store: options.store } : {}
|
|
10056
|
+
};
|
|
10057
|
+
}
|
|
10058
|
+
|
|
10059
|
+
// src/live/openai-live-event-mapper.ts
|
|
10060
|
+
var sessionSchema = z31.object({ id: z31.string().min(1) });
|
|
10061
|
+
var startedSessionSchema = sessionSchema.extend({
|
|
10062
|
+
delegation: z31.object({ type: z31.enum(["client", "responses"]) }).nullish()
|
|
10063
|
+
});
|
|
10064
|
+
var usageSchema = z31.object({ seconds: z31.number().nonnegative() });
|
|
10065
|
+
var transcriptFields = {
|
|
10066
|
+
delta: z31.string(),
|
|
10067
|
+
start_ms: z31.number().nonnegative(),
|
|
10068
|
+
end_ms: z31.number().nonnegative()
|
|
10069
|
+
};
|
|
10070
|
+
var acknowledgmentFields = { client_event_id: z31.string().nullish() };
|
|
10071
|
+
var appendAcknowledgmentFields = {
|
|
10072
|
+
...acknowledgmentFields,
|
|
10073
|
+
start_ms: z31.number().nonnegative(),
|
|
10074
|
+
end_ms: z31.number().nonnegative()
|
|
10075
|
+
};
|
|
10076
|
+
var serverEventSchema = z31.discriminatedUnion("type", [
|
|
10077
|
+
z31.object({
|
|
10078
|
+
type: z31.literal("session.started"),
|
|
10079
|
+
session: startedSessionSchema
|
|
10080
|
+
}),
|
|
10081
|
+
z31.object({
|
|
10082
|
+
type: z31.literal("session.closed"),
|
|
10083
|
+
session: sessionSchema.nullish(),
|
|
10084
|
+
usage: usageSchema,
|
|
10085
|
+
reason: z31.string()
|
|
10086
|
+
}),
|
|
10087
|
+
z31.object({
|
|
10088
|
+
type: z31.literal("session.usage.updated"),
|
|
10089
|
+
usage: usageSchema,
|
|
10090
|
+
context_window: z31.object({ usage_ratio: z31.number().min(0).max(1) }).nullish()
|
|
10091
|
+
}),
|
|
10092
|
+
z31.object({
|
|
10093
|
+
type: z31.literal("session.output_audio.delta"),
|
|
10094
|
+
delta: z31.string()
|
|
10095
|
+
}),
|
|
10096
|
+
z31.object({
|
|
10097
|
+
type: z31.literal("session.input_transcript.delta"),
|
|
10098
|
+
...transcriptFields
|
|
10099
|
+
}),
|
|
10100
|
+
z31.object({
|
|
10101
|
+
type: z31.literal("session.output_transcript.delta"),
|
|
10102
|
+
...transcriptFields
|
|
10103
|
+
}),
|
|
10104
|
+
z31.object({
|
|
10105
|
+
type: z31.literal("session.delegation.created"),
|
|
10106
|
+
offset_ms: z31.number().nonnegative().nullish(),
|
|
10107
|
+
delegation: z31.object({
|
|
10108
|
+
id: z31.string().min(1),
|
|
10109
|
+
target: z31.enum(["client", "responses"]).nullish(),
|
|
10110
|
+
response_id: z31.string().min(1).nullish()
|
|
10111
|
+
})
|
|
10112
|
+
}),
|
|
10113
|
+
z31.object({
|
|
10114
|
+
type: z31.literal("session.updated"),
|
|
10115
|
+
session: sessionSchema,
|
|
10116
|
+
...acknowledgmentFields
|
|
10117
|
+
}),
|
|
10118
|
+
z31.object({
|
|
10119
|
+
type: z31.literal("session.input_audio.muted"),
|
|
10120
|
+
...acknowledgmentFields
|
|
10121
|
+
}),
|
|
10122
|
+
z31.object({
|
|
10123
|
+
type: z31.literal("session.input_audio.unmuted"),
|
|
10124
|
+
...acknowledgmentFields
|
|
10125
|
+
}),
|
|
10126
|
+
z31.object({
|
|
10127
|
+
type: z31.literal("session.instructions.appended"),
|
|
10128
|
+
...appendAcknowledgmentFields
|
|
10129
|
+
}),
|
|
10130
|
+
z31.object({
|
|
10131
|
+
type: z31.literal("session.thinking.appended"),
|
|
10132
|
+
...appendAcknowledgmentFields
|
|
10133
|
+
}),
|
|
10134
|
+
z31.object({
|
|
10135
|
+
type: z31.literal("session.commentary.appended"),
|
|
10136
|
+
...appendAcknowledgmentFields
|
|
10137
|
+
}),
|
|
10138
|
+
z31.object({
|
|
10139
|
+
type: z31.literal("error"),
|
|
10140
|
+
error: z31.object({
|
|
10141
|
+
message: z31.string(),
|
|
10142
|
+
code: z31.string().nullish(),
|
|
10143
|
+
client_event_id: z31.string().nullish()
|
|
10144
|
+
})
|
|
10145
|
+
})
|
|
10146
|
+
]);
|
|
10147
|
+
var knownTypes = new Set(
|
|
10148
|
+
serverEventSchema.options.map((schema) => schema.shape.type.value)
|
|
10149
|
+
);
|
|
10150
|
+
var envelopeSchema = z31.object({ type: z31.string() });
|
|
10151
|
+
function createOpenAILiveServerEventParser() {
|
|
10152
|
+
return (raw) => parseOpenAILiveServerEvent(raw);
|
|
10153
|
+
}
|
|
10154
|
+
function parseOpenAILiveServerEvent(raw) {
|
|
10155
|
+
return [parseServerEvent(raw)];
|
|
10156
|
+
}
|
|
10157
|
+
function parseServerEvent(raw) {
|
|
10158
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
10159
|
+
const envelope = envelopeSchema.safeParse(raw);
|
|
10160
|
+
if (envelope.success && !knownTypes.has(envelope.data.type)) {
|
|
10161
|
+
return { type: "custom", rawType: envelope.data.type, raw };
|
|
10162
|
+
}
|
|
10163
|
+
const parsed = serverEventSchema.safeParse(raw);
|
|
10164
|
+
if (!parsed.success) {
|
|
10165
|
+
return {
|
|
10166
|
+
type: "error",
|
|
10167
|
+
code: "invalid_server_event",
|
|
10168
|
+
message: "Invalid OpenAI Live server event.",
|
|
10169
|
+
raw
|
|
10170
|
+
};
|
|
10171
|
+
}
|
|
10172
|
+
const event = parsed.data;
|
|
10173
|
+
if ("start_ms" in event && event.end_ms < event.start_ms) {
|
|
10174
|
+
return {
|
|
10175
|
+
type: "error",
|
|
10176
|
+
code: "invalid_server_event",
|
|
10177
|
+
message: "Invalid OpenAI Live event time interval.",
|
|
10178
|
+
raw
|
|
10179
|
+
};
|
|
10180
|
+
}
|
|
10181
|
+
switch (event.type) {
|
|
10182
|
+
case "session.started":
|
|
10183
|
+
return {
|
|
10184
|
+
type: "session-started",
|
|
10185
|
+
sessionId: event.session.id,
|
|
10186
|
+
delegationMode: ((_a2 = event.session.delegation) == null ? void 0 : _a2.type) === "responses" ? "provider" : "client",
|
|
10187
|
+
raw
|
|
10188
|
+
};
|
|
10189
|
+
case "session.closed":
|
|
10190
|
+
return {
|
|
10191
|
+
type: "session-closed",
|
|
10192
|
+
sessionId: (_b = event.session) == null ? void 0 : _b.id,
|
|
10193
|
+
usage: event.usage,
|
|
10194
|
+
reason: event.reason,
|
|
10195
|
+
raw
|
|
10196
|
+
};
|
|
10197
|
+
case "session.usage.updated":
|
|
10198
|
+
return {
|
|
10199
|
+
type: "session-usage",
|
|
10200
|
+
usage: event.usage,
|
|
10201
|
+
contextWindowUsageRatio: (_c = event.context_window) == null ? void 0 : _c.usage_ratio,
|
|
10202
|
+
raw
|
|
10203
|
+
};
|
|
10204
|
+
case "session.output_audio.delta":
|
|
10205
|
+
return { type: "audio-chunk", delta: event.delta, raw };
|
|
10206
|
+
case "session.input_transcript.delta":
|
|
10207
|
+
case "session.output_transcript.delta":
|
|
10208
|
+
return {
|
|
10209
|
+
type: "transcript-fragment",
|
|
10210
|
+
speaker: event.type === "session.input_transcript.delta" ? "user" : "assistant",
|
|
10211
|
+
delta: event.delta,
|
|
10212
|
+
startMs: event.start_ms,
|
|
10213
|
+
endMs: event.end_ms,
|
|
10214
|
+
raw
|
|
10215
|
+
};
|
|
10216
|
+
case "session.delegation.created":
|
|
10217
|
+
return {
|
|
10218
|
+
type: "delegation-created",
|
|
10219
|
+
delegationId: event.delegation.id,
|
|
10220
|
+
target: event.delegation.target === "responses" ? "provider" : (_d = event.delegation.target) != null ? _d : void 0,
|
|
10221
|
+
offsetMs: (_e = event.offset_ms) != null ? _e : void 0,
|
|
10222
|
+
...event.delegation.response_id != null ? { responseId: event.delegation.response_id } : {},
|
|
10223
|
+
raw
|
|
10224
|
+
};
|
|
10225
|
+
case "error":
|
|
10226
|
+
return {
|
|
10227
|
+
type: "error",
|
|
10228
|
+
message: event.error.message,
|
|
10229
|
+
code: (_f = event.error.code) != null ? _f : void 0,
|
|
10230
|
+
clientEventId: (_g = event.error.client_event_id) != null ? _g : void 0,
|
|
10231
|
+
raw
|
|
10232
|
+
};
|
|
10233
|
+
case "session.updated":
|
|
10234
|
+
return {
|
|
10235
|
+
type: "command-acknowledged",
|
|
10236
|
+
command: "session.update",
|
|
10237
|
+
clientEventId: (_h = event.client_event_id) != null ? _h : void 0,
|
|
10238
|
+
raw
|
|
10239
|
+
};
|
|
10240
|
+
case "session.input_audio.muted":
|
|
10241
|
+
case "session.input_audio.unmuted":
|
|
10242
|
+
return {
|
|
10243
|
+
type: "command-acknowledged",
|
|
10244
|
+
command: event.type.slice(0, -1),
|
|
10245
|
+
clientEventId: (_i = event.client_event_id) != null ? _i : void 0,
|
|
10246
|
+
raw
|
|
10247
|
+
};
|
|
10248
|
+
case "session.instructions.appended":
|
|
10249
|
+
case "session.thinking.appended":
|
|
10250
|
+
case "session.commentary.appended":
|
|
10251
|
+
return {
|
|
10252
|
+
type: "command-acknowledged",
|
|
10253
|
+
command: event.type.slice(0, -2),
|
|
10254
|
+
clientEventId: (_j = event.client_event_id) != null ? _j : void 0,
|
|
10255
|
+
raw
|
|
10256
|
+
};
|
|
10257
|
+
}
|
|
10258
|
+
}
|
|
10259
|
+
function serializeOpenAILiveClientEvent(event, modelId) {
|
|
10260
|
+
var _a2, _b, _c;
|
|
10261
|
+
const eventId = "eventId" in event && event.eventId !== void 0 ? { event_id: event.eventId } : {};
|
|
10262
|
+
switch (event.type) {
|
|
10263
|
+
case "session-start":
|
|
10264
|
+
return {
|
|
10265
|
+
type: "session.start",
|
|
10266
|
+
session: buildOpenAILiveSessionConfig(event.config, modelId),
|
|
10267
|
+
...eventId
|
|
10268
|
+
};
|
|
10269
|
+
case "session-update":
|
|
10270
|
+
throw new UnsupportedFunctionalityError9({
|
|
10271
|
+
functionality: "OpenAI Live session-update; startup settings are immutable; use context-append or input-audio-mute/input-audio-unmute"
|
|
10272
|
+
});
|
|
10273
|
+
case "session-close":
|
|
10274
|
+
return { type: "session.close", ...eventId };
|
|
10275
|
+
case "input-audio-append":
|
|
10276
|
+
return {
|
|
10277
|
+
type: "session.input_audio.append",
|
|
10278
|
+
audio: event.audio,
|
|
10279
|
+
...eventId
|
|
10280
|
+
};
|
|
10281
|
+
case "input-audio-mute":
|
|
10282
|
+
return { type: "session.input_audio.mute", ...eventId };
|
|
10283
|
+
case "input-audio-unmute":
|
|
10284
|
+
return { type: "session.input_audio.unmute", ...eventId };
|
|
10285
|
+
case "context-append": {
|
|
10286
|
+
const context = z31.object({
|
|
10287
|
+
content: z31.string(),
|
|
10288
|
+
delegationId: z31.string().min(1).nullable()
|
|
10289
|
+
}).parse(event);
|
|
10290
|
+
const options = z31.strictObject({
|
|
10291
|
+
channel: z31.enum(["instructions", "thinking", "commentary"]).optional()
|
|
10292
|
+
}).parse((_b = (_a2 = event.providerOptions) == null ? void 0 : _a2.openai) != null ? _b : {});
|
|
10293
|
+
return {
|
|
10294
|
+
type: `session.${(_c = options.channel) != null ? _c : "thinking"}.append`,
|
|
10295
|
+
content: context.content,
|
|
10296
|
+
delegation_id: context.delegationId,
|
|
10297
|
+
...eventId
|
|
10298
|
+
};
|
|
10299
|
+
}
|
|
10300
|
+
default:
|
|
10301
|
+
throw new UnsupportedFunctionalityError9({
|
|
10302
|
+
functionality: `OpenAI Live command: ${event.type}; use continuous audio and context-append instead of voice-turn commands`
|
|
10303
|
+
});
|
|
10304
|
+
}
|
|
10305
|
+
}
|
|
10306
|
+
|
|
10307
|
+
// src/live/openai-realtime-model-live.ts
|
|
10308
|
+
var webRTCSessionSchema = z32.object({
|
|
10309
|
+
session: z32.object({ id: z32.string().min(1) }),
|
|
10310
|
+
transport: z32.object({ type: z32.literal("webrtc"), sdp: z32.string().min(1) })
|
|
10311
|
+
});
|
|
10312
|
+
var OpenAIRealtimeModelLive = class {
|
|
10313
|
+
constructor(modelId, config) {
|
|
10314
|
+
this.modelId = modelId;
|
|
10315
|
+
this.config = config;
|
|
10316
|
+
this.specificationVersion = "v4";
|
|
10317
|
+
this.capabilities = {
|
|
10318
|
+
conversation: "continuous",
|
|
10319
|
+
transports: ["websocket", "webrtc"],
|
|
10320
|
+
connections: ["server-websocket", "webrtc"],
|
|
10321
|
+
startup: "session-start",
|
|
10322
|
+
finalization: "session-close"
|
|
10323
|
+
};
|
|
10324
|
+
}
|
|
10325
|
+
get provider() {
|
|
10326
|
+
return this.config.provider;
|
|
10327
|
+
}
|
|
10328
|
+
getWebRTCConfig() {
|
|
10329
|
+
return { dataChannelLabel: "oai-events" };
|
|
10330
|
+
}
|
|
10331
|
+
getServerWebSocketConfig() {
|
|
10332
|
+
const url = new URL(`${this.config.baseURL}/live/sessions`);
|
|
10333
|
+
url.protocol = url.protocol === "http:" ? "ws:" : "wss:";
|
|
10334
|
+
const headers = {};
|
|
10335
|
+
for (const [key, value] of Object.entries(this.config.headers())) {
|
|
10336
|
+
if (value !== void 0) headers[key] = value;
|
|
10337
|
+
}
|
|
10338
|
+
return { url: url.toString(), headers };
|
|
10339
|
+
}
|
|
10340
|
+
async doCreateWebRTCSession({
|
|
10341
|
+
sdp,
|
|
10342
|
+
sessionConfig = {},
|
|
10343
|
+
abortSignal
|
|
10344
|
+
}) {
|
|
10345
|
+
const session = buildOpenAILiveSessionConfig(
|
|
10346
|
+
sessionConfig,
|
|
10347
|
+
this.modelId,
|
|
10348
|
+
"webrtc"
|
|
10349
|
+
);
|
|
10350
|
+
const { value } = await postJsonToApi7({
|
|
10351
|
+
url: `${this.config.baseURL}/live/sessions`,
|
|
10352
|
+
headers: this.config.headers(),
|
|
10353
|
+
body: {
|
|
10354
|
+
session,
|
|
10355
|
+
transport: { type: "webrtc", sdp: z32.string().min(1).parse(sdp) }
|
|
10356
|
+
},
|
|
10357
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
10358
|
+
successfulResponseHandler: createJsonResponseHandler8(webRTCSessionSchema),
|
|
10359
|
+
abortSignal,
|
|
10360
|
+
fetch: this.config.fetch
|
|
10361
|
+
});
|
|
10362
|
+
return { sessionId: value.session.id, sdp: value.transport.sdp };
|
|
10363
|
+
}
|
|
10364
|
+
parseServerEvent(raw) {
|
|
10365
|
+
return parseOpenAILiveServerEvent(raw);
|
|
10366
|
+
}
|
|
10367
|
+
createServerEventParser() {
|
|
10368
|
+
return createOpenAILiveServerEventParser();
|
|
10369
|
+
}
|
|
10370
|
+
serializeClientEvent(event) {
|
|
10371
|
+
return serializeOpenAILiveClientEvent(event, this.modelId);
|
|
10372
|
+
}
|
|
10373
|
+
buildSessionConfig(config) {
|
|
10374
|
+
return buildOpenAILiveSessionConfig(config, this.modelId);
|
|
10375
|
+
}
|
|
10376
|
+
};
|
|
10377
|
+
|
|
9748
10378
|
// src/realtime/openai-realtime-event-mapper.ts
|
|
9749
10379
|
function parseOpenAIRealtimeServerEvent(raw) {
|
|
9750
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
10380
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
9751
10381
|
const event = raw;
|
|
9752
10382
|
const type = event.type;
|
|
9753
10383
|
switch (type) {
|
|
@@ -9914,6 +10544,7 @@ function parseOpenAIRealtimeServerEvent(raw) {
|
|
|
9914
10544
|
type: "error",
|
|
9915
10545
|
message: (_q = (_p = (_o = event.error) == null ? void 0 : _o.message) != null ? _p : event.message) != null ? _q : "Unknown error",
|
|
9916
10546
|
code: (_s = (_r = event.error) == null ? void 0 : _r.code) != null ? _s : event.code,
|
|
10547
|
+
clientEventId: (_u = (_t = event.error) == null ? void 0 : _t.event_id) != null ? _u : void 0,
|
|
9917
10548
|
raw
|
|
9918
10549
|
};
|
|
9919
10550
|
// ── Pass-through ────────────────────────────────────────────────
|
|
@@ -9926,12 +10557,14 @@ function serializeOpenAIRealtimeClientEvent(event, modelId) {
|
|
|
9926
10557
|
case "session-update":
|
|
9927
10558
|
return {
|
|
9928
10559
|
type: "session.update",
|
|
9929
|
-
session: buildOpenAISessionConfig(event.config, modelId)
|
|
10560
|
+
session: buildOpenAISessionConfig(event.config, modelId),
|
|
10561
|
+
...event.eventId != null ? { event_id: event.eventId } : {}
|
|
9930
10562
|
};
|
|
9931
10563
|
case "input-audio-append":
|
|
9932
10564
|
return {
|
|
9933
10565
|
type: "input_audio_buffer.append",
|
|
9934
|
-
audio: event.audio
|
|
10566
|
+
audio: event.audio,
|
|
10567
|
+
...event.eventId != null ? { event_id: event.eventId } : {}
|
|
9935
10568
|
};
|
|
9936
10569
|
case "input-audio-commit":
|
|
9937
10570
|
return { type: "input_audio_buffer.commit" };
|
|
@@ -10134,12 +10767,53 @@ var OpenAIRealtimeModel = class {
|
|
|
10134
10767
|
}
|
|
10135
10768
|
};
|
|
10136
10769
|
|
|
10770
|
+
// src/realtime/openai-realtime-factory.ts
|
|
10771
|
+
var knownLiveModelIds = ["gpt-live-1"];
|
|
10772
|
+
function resolveRealtimeApi(modelId, { api } = {}) {
|
|
10773
|
+
if (api !== void 0) {
|
|
10774
|
+
if (api !== "live" && api !== "realtime") {
|
|
10775
|
+
throw new InvalidArgumentError4({
|
|
10776
|
+
argument: "api",
|
|
10777
|
+
message: 'OpenAI realtime api must be "live" or "realtime".'
|
|
10778
|
+
});
|
|
10779
|
+
}
|
|
10780
|
+
return api;
|
|
10781
|
+
}
|
|
10782
|
+
return knownLiveModelIds.some((knownModelId) => knownModelId === modelId) ? "live" : "realtime";
|
|
10783
|
+
}
|
|
10784
|
+
function createOpenAIRealtimeFactory(config) {
|
|
10785
|
+
const createModel = (modelId, options) => {
|
|
10786
|
+
const api = resolveRealtimeApi(modelId, options);
|
|
10787
|
+
const modelConfig = { ...config, provider: `${config.provider}.${api}` };
|
|
10788
|
+
return api === "live" ? new OpenAIRealtimeModelLive(modelId, modelConfig) : new OpenAIRealtimeModel(modelId, modelConfig);
|
|
10789
|
+
};
|
|
10790
|
+
return Object.assign(createModel, {
|
|
10791
|
+
getToken: async (options) => {
|
|
10792
|
+
const model = createModel(options.model, options);
|
|
10793
|
+
if (model instanceof OpenAIRealtimeModelLive) {
|
|
10794
|
+
throw new UnsupportedFunctionalityError10({
|
|
10795
|
+
functionality: "Short-lived OpenAI credentials for the Live API. Use server WebSocket setup via getServerWebSocketConfig() with a server-side API key instead."
|
|
10796
|
+
});
|
|
10797
|
+
}
|
|
10798
|
+
const secret = await model.doCreateClientSecret({
|
|
10799
|
+
sessionConfig: options.sessionConfig,
|
|
10800
|
+
expiresAfterSeconds: options.expiresAfterSeconds
|
|
10801
|
+
});
|
|
10802
|
+
return {
|
|
10803
|
+
token: secret.token,
|
|
10804
|
+
url: secret.url,
|
|
10805
|
+
expiresAt: secret.expiresAt
|
|
10806
|
+
};
|
|
10807
|
+
}
|
|
10808
|
+
});
|
|
10809
|
+
}
|
|
10810
|
+
|
|
10137
10811
|
// src/speech/openai-speech-model.ts
|
|
10138
10812
|
import {
|
|
10139
10813
|
combineHeaders as combineHeaders8,
|
|
10140
10814
|
createBinaryResponseHandler,
|
|
10141
10815
|
parseProviderOptions as parseProviderOptions9,
|
|
10142
|
-
postJsonToApi as
|
|
10816
|
+
postJsonToApi as postJsonToApi8,
|
|
10143
10817
|
serializeModelOptions as serializeModelOptions6,
|
|
10144
10818
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE6,
|
|
10145
10819
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6
|
|
@@ -10150,12 +10824,12 @@ import {
|
|
|
10150
10824
|
lazySchema as lazySchema27,
|
|
10151
10825
|
zodSchema as zodSchema27
|
|
10152
10826
|
} from "@ai-sdk/provider-utils";
|
|
10153
|
-
import { z as
|
|
10827
|
+
import { z as z33 } from "zod/v4";
|
|
10154
10828
|
var openaiSpeechModelOptionsSchema = lazySchema27(
|
|
10155
10829
|
() => zodSchema27(
|
|
10156
|
-
|
|
10157
|
-
instructions:
|
|
10158
|
-
speed:
|
|
10830
|
+
z33.object({
|
|
10831
|
+
instructions: z33.string().nullish(),
|
|
10832
|
+
speed: z33.number().min(0.25).max(4).default(1).nullish()
|
|
10159
10833
|
})
|
|
10160
10834
|
)
|
|
10161
10835
|
);
|
|
@@ -10242,7 +10916,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
10242
10916
|
value: audio,
|
|
10243
10917
|
responseHeaders,
|
|
10244
10918
|
rawValue: rawResponse
|
|
10245
|
-
} = await
|
|
10919
|
+
} = await postJsonToApi8({
|
|
10246
10920
|
url: this.config.url({
|
|
10247
10921
|
path: "/audio/speech",
|
|
10248
10922
|
modelId: this.modelId
|
|
@@ -10272,13 +10946,13 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
10272
10946
|
|
|
10273
10947
|
// src/transcription/openai-transcription-model.ts
|
|
10274
10948
|
import {
|
|
10275
|
-
UnsupportedFunctionalityError as
|
|
10949
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError11
|
|
10276
10950
|
} from "@ai-sdk/provider";
|
|
10277
10951
|
import {
|
|
10278
10952
|
combineHeaders as combineHeaders9,
|
|
10279
10953
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
|
10280
10954
|
convertToBase64 as convertToBase643,
|
|
10281
|
-
createJsonResponseHandler as
|
|
10955
|
+
createJsonResponseHandler as createJsonResponseHandler9,
|
|
10282
10956
|
connectToWebSocket,
|
|
10283
10957
|
mediaTypeToExtension,
|
|
10284
10958
|
parseProviderOptions as parseProviderOptions10,
|
|
@@ -10293,41 +10967,41 @@ import {
|
|
|
10293
10967
|
|
|
10294
10968
|
// src/transcription/openai-transcription-api.ts
|
|
10295
10969
|
import { lazySchema as lazySchema28, zodSchema as zodSchema28 } from "@ai-sdk/provider-utils";
|
|
10296
|
-
import { z as
|
|
10970
|
+
import { z as z34 } from "zod/v4";
|
|
10297
10971
|
var openaiTranscriptionResponseSchema = lazySchema28(
|
|
10298
10972
|
() => zodSchema28(
|
|
10299
|
-
|
|
10300
|
-
text:
|
|
10301
|
-
language:
|
|
10302
|
-
duration:
|
|
10303
|
-
words:
|
|
10304
|
-
|
|
10305
|
-
word:
|
|
10306
|
-
start:
|
|
10307
|
-
end:
|
|
10973
|
+
z34.object({
|
|
10974
|
+
text: z34.string(),
|
|
10975
|
+
language: z34.string().nullish(),
|
|
10976
|
+
duration: z34.number().nullish(),
|
|
10977
|
+
words: z34.array(
|
|
10978
|
+
z34.object({
|
|
10979
|
+
word: z34.string(),
|
|
10980
|
+
start: z34.number(),
|
|
10981
|
+
end: z34.number()
|
|
10308
10982
|
})
|
|
10309
10983
|
).nullish(),
|
|
10310
|
-
segments:
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
id:
|
|
10314
|
-
seek:
|
|
10315
|
-
start:
|
|
10316
|
-
end:
|
|
10317
|
-
text:
|
|
10318
|
-
tokens:
|
|
10319
|
-
temperature:
|
|
10320
|
-
avg_logprob:
|
|
10321
|
-
compression_ratio:
|
|
10322
|
-
no_speech_prob:
|
|
10984
|
+
segments: z34.array(
|
|
10985
|
+
z34.union([
|
|
10986
|
+
z34.object({
|
|
10987
|
+
id: z34.number(),
|
|
10988
|
+
seek: z34.number(),
|
|
10989
|
+
start: z34.number(),
|
|
10990
|
+
end: z34.number(),
|
|
10991
|
+
text: z34.string(),
|
|
10992
|
+
tokens: z34.array(z34.number()),
|
|
10993
|
+
temperature: z34.number(),
|
|
10994
|
+
avg_logprob: z34.number(),
|
|
10995
|
+
compression_ratio: z34.number(),
|
|
10996
|
+
no_speech_prob: z34.number()
|
|
10323
10997
|
}),
|
|
10324
|
-
|
|
10325
|
-
type:
|
|
10326
|
-
id:
|
|
10327
|
-
start:
|
|
10328
|
-
end:
|
|
10329
|
-
text:
|
|
10330
|
-
speaker:
|
|
10998
|
+
z34.object({
|
|
10999
|
+
type: z34.literal("transcript.text.segment"),
|
|
11000
|
+
id: z34.string(),
|
|
11001
|
+
start: z34.number(),
|
|
11002
|
+
end: z34.number(),
|
|
11003
|
+
text: z34.string(),
|
|
11004
|
+
speaker: z34.string()
|
|
10331
11005
|
})
|
|
10332
11006
|
])
|
|
10333
11007
|
).nullish()
|
|
@@ -10340,60 +11014,60 @@ import {
|
|
|
10340
11014
|
lazySchema as lazySchema29,
|
|
10341
11015
|
zodSchema as zodSchema29
|
|
10342
11016
|
} from "@ai-sdk/provider-utils";
|
|
10343
|
-
import { z as
|
|
11017
|
+
import { z as z35 } from "zod/v4";
|
|
10344
11018
|
var openAITranscriptionModelOptions = lazySchema29(
|
|
10345
11019
|
() => zodSchema29(
|
|
10346
|
-
|
|
11020
|
+
z35.object({
|
|
10347
11021
|
/**
|
|
10348
11022
|
* Additional information to include in the transcription response.
|
|
10349
11023
|
*/
|
|
10350
|
-
include:
|
|
11024
|
+
include: z35.array(z35.string()).optional(),
|
|
10351
11025
|
/**
|
|
10352
11026
|
* The language of the input audio in ISO-639-1 format.
|
|
10353
11027
|
*/
|
|
10354
|
-
language:
|
|
11028
|
+
language: z35.string().optional(),
|
|
10355
11029
|
/**
|
|
10356
11030
|
* An optional text to guide the model's style or continue a previous audio segment.
|
|
10357
11031
|
*/
|
|
10358
|
-
prompt:
|
|
11032
|
+
prompt: z35.string().optional(),
|
|
10359
11033
|
/**
|
|
10360
11034
|
* The sampling temperature, between 0 and 1.
|
|
10361
11035
|
* @default 0
|
|
10362
11036
|
*/
|
|
10363
|
-
temperature:
|
|
11037
|
+
temperature: z35.number().min(0).max(1).default(0).optional(),
|
|
10364
11038
|
/**
|
|
10365
11039
|
* The timestamp granularities to populate for this transcription.
|
|
10366
11040
|
* @default ['segment']
|
|
10367
11041
|
*/
|
|
10368
|
-
timestampGranularities:
|
|
11042
|
+
timestampGranularities: z35.array(z35.enum(["word", "segment"])).default(["segment"]).optional(),
|
|
10369
11043
|
/**
|
|
10370
11044
|
* The format of the transcription response.
|
|
10371
11045
|
*/
|
|
10372
|
-
responseFormat:
|
|
11046
|
+
responseFormat: z35.enum(["json", "verbose_json", "diarized_json"]).optional(),
|
|
10373
11047
|
/**
|
|
10374
11048
|
* Controls how the audio is split into chunks before transcription.
|
|
10375
11049
|
*/
|
|
10376
|
-
chunkingStrategy:
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
type:
|
|
10380
|
-
threshold:
|
|
10381
|
-
prefixPaddingMs:
|
|
10382
|
-
silenceDurationMs:
|
|
11050
|
+
chunkingStrategy: z35.union([
|
|
11051
|
+
z35.literal("auto"),
|
|
11052
|
+
z35.object({
|
|
11053
|
+
type: z35.literal("server_vad"),
|
|
11054
|
+
threshold: z35.number().min(0).max(1).optional(),
|
|
11055
|
+
prefixPaddingMs: z35.number().int().min(0).optional(),
|
|
11056
|
+
silenceDurationMs: z35.number().int().min(0).optional()
|
|
10383
11057
|
})
|
|
10384
11058
|
]).optional(),
|
|
10385
11059
|
/**
|
|
10386
11060
|
* Options for streaming transcription models such as `gpt-realtime-whisper`.
|
|
10387
11061
|
*/
|
|
10388
|
-
streaming:
|
|
11062
|
+
streaming: z35.object({
|
|
10389
11063
|
/**
|
|
10390
11064
|
* Latency/accuracy tradeoff for realtime transcription.
|
|
10391
11065
|
*/
|
|
10392
|
-
delay:
|
|
11066
|
+
delay: z35.enum(["minimal", "low", "medium", "high", "xhigh"]).optional(),
|
|
10393
11067
|
/**
|
|
10394
11068
|
* Additional fields to include in realtime transcription events.
|
|
10395
11069
|
*/
|
|
10396
|
-
include:
|
|
11070
|
+
include: z35.array(z35.string()).optional()
|
|
10397
11071
|
}).optional()
|
|
10398
11072
|
})
|
|
10399
11073
|
)
|
|
@@ -10562,7 +11236,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
10562
11236
|
async doGenerate(options) {
|
|
10563
11237
|
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
10564
11238
|
if (isRealtimeTranscriptionModelId(this.modelId)) {
|
|
10565
|
-
throw new
|
|
11239
|
+
throw new UnsupportedFunctionalityError11({
|
|
10566
11240
|
functionality: `non-streaming transcription with ${this.modelId}`
|
|
10567
11241
|
});
|
|
10568
11242
|
}
|
|
@@ -10580,7 +11254,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
10580
11254
|
headers: combineHeaders9((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
|
|
10581
11255
|
formData,
|
|
10582
11256
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
10583
|
-
successfulResponseHandler:
|
|
11257
|
+
successfulResponseHandler: createJsonResponseHandler9(
|
|
10584
11258
|
openaiTranscriptionResponseSchema
|
|
10585
11259
|
),
|
|
10586
11260
|
abortSignal: options.abortSignal,
|
|
@@ -10629,7 +11303,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
10629
11303
|
async doStream(options) {
|
|
10630
11304
|
var _a2, _b, _c, _d, _e, _f, _g;
|
|
10631
11305
|
if (!isRealtimeTranscriptionModelId(this.modelId)) {
|
|
10632
|
-
throw new
|
|
11306
|
+
throw new UnsupportedFunctionalityError11({
|
|
10633
11307
|
functionality: `streaming transcription with ${this.modelId}`
|
|
10634
11308
|
});
|
|
10635
11309
|
}
|
|
@@ -10870,7 +11544,7 @@ function getOpenAIRealtimeConnection(headers) {
|
|
|
10870
11544
|
|
|
10871
11545
|
// src/speech-translation/openai-speech-translation-model.ts
|
|
10872
11546
|
import {
|
|
10873
|
-
InvalidArgumentError as
|
|
11547
|
+
InvalidArgumentError as InvalidArgumentError5
|
|
10874
11548
|
} from "@ai-sdk/provider";
|
|
10875
11549
|
import {
|
|
10876
11550
|
combineHeaders as combineHeaders10,
|
|
@@ -10890,9 +11564,9 @@ import {
|
|
|
10890
11564
|
lazySchema as lazySchema30,
|
|
10891
11565
|
zodSchema as zodSchema30
|
|
10892
11566
|
} from "@ai-sdk/provider-utils";
|
|
10893
|
-
import { z as
|
|
11567
|
+
import { z as z36 } from "zod/v4";
|
|
10894
11568
|
var openAISpeechTranslationModelOptions = lazySchema30(
|
|
10895
|
-
() => zodSchema30(
|
|
11569
|
+
() => zodSchema30(z36.object({}))
|
|
10896
11570
|
);
|
|
10897
11571
|
|
|
10898
11572
|
// src/speech-translation/openai-speech-translation-model.ts
|
|
@@ -10917,7 +11591,7 @@ var OpenAISpeechTranslationModel = class _OpenAISpeechTranslationModel {
|
|
|
10917
11591
|
async doStream(options) {
|
|
10918
11592
|
var _a2, _b, _c, _d, _e;
|
|
10919
11593
|
if (options.targetLanguage == null) {
|
|
10920
|
-
throw new
|
|
11594
|
+
throw new InvalidArgumentError5({
|
|
10921
11595
|
argument: "targetLanguage",
|
|
10922
11596
|
message: `targetLanguage is required for translation model '${this.modelId}'.`
|
|
10923
11597
|
});
|
|
@@ -11157,7 +11831,7 @@ function buildOpenAIRealtimeSpeechTranslationSession({
|
|
|
11157
11831
|
}
|
|
11158
11832
|
function validateOpenAISpeechTranslationInputAudioFormat(inputAudioFormat) {
|
|
11159
11833
|
if (inputAudioFormat.type !== "audio/pcm" || inputAudioFormat.rate != null && inputAudioFormat.rate !== 24e3) {
|
|
11160
|
-
throw new
|
|
11834
|
+
throw new InvalidArgumentError5({
|
|
11161
11835
|
argument: "inputAudioFormat",
|
|
11162
11836
|
message: "The OpenAI Realtime translation API only supports 24kHz 16-bit PCM input audio."
|
|
11163
11837
|
});
|
|
@@ -11189,33 +11863,33 @@ function getOpenAIRealtimeConnection2(headers) {
|
|
|
11189
11863
|
import {
|
|
11190
11864
|
combineHeaders as combineHeaders11,
|
|
11191
11865
|
convertInlineFileDataToUint8Array as convertInlineFileDataToUint8Array2,
|
|
11192
|
-
createJsonResponseHandler as
|
|
11866
|
+
createJsonResponseHandler as createJsonResponseHandler10,
|
|
11193
11867
|
postFormDataToApi as postFormDataToApi4
|
|
11194
11868
|
} from "@ai-sdk/provider-utils";
|
|
11195
11869
|
|
|
11196
11870
|
// src/skills/openai-skills-api.ts
|
|
11197
11871
|
import { lazySchema as lazySchema31, zodSchema as zodSchema31 } from "@ai-sdk/provider-utils";
|
|
11198
|
-
import { z as
|
|
11872
|
+
import { z as z37 } from "zod/v4";
|
|
11199
11873
|
var openaiSkillResponseSchema = lazySchema31(
|
|
11200
11874
|
() => zodSchema31(
|
|
11201
|
-
|
|
11202
|
-
id:
|
|
11203
|
-
name:
|
|
11204
|
-
description:
|
|
11205
|
-
default_version:
|
|
11206
|
-
latest_version:
|
|
11207
|
-
created_at:
|
|
11208
|
-
updated_at:
|
|
11875
|
+
z37.object({
|
|
11876
|
+
id: z37.string(),
|
|
11877
|
+
name: z37.string().nullish(),
|
|
11878
|
+
description: z37.string().nullish(),
|
|
11879
|
+
default_version: z37.string().nullish(),
|
|
11880
|
+
latest_version: z37.string().nullish(),
|
|
11881
|
+
created_at: z37.number(),
|
|
11882
|
+
updated_at: z37.number().nullish()
|
|
11209
11883
|
})
|
|
11210
11884
|
)
|
|
11211
11885
|
);
|
|
11212
11886
|
var openaiSkillVersionResponseSchema = lazySchema31(
|
|
11213
11887
|
() => zodSchema31(
|
|
11214
|
-
|
|
11215
|
-
id:
|
|
11216
|
-
version:
|
|
11217
|
-
name:
|
|
11218
|
-
description:
|
|
11888
|
+
z37.object({
|
|
11889
|
+
id: z37.string(),
|
|
11890
|
+
version: z37.string().nullish(),
|
|
11891
|
+
name: z37.string().nullish(),
|
|
11892
|
+
description: z37.string().nullish()
|
|
11219
11893
|
})
|
|
11220
11894
|
)
|
|
11221
11895
|
);
|
|
@@ -11247,7 +11921,7 @@ var OpenAISkills = class {
|
|
|
11247
11921
|
headers: combineHeaders11(this.config.headers()),
|
|
11248
11922
|
formData,
|
|
11249
11923
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
11250
|
-
successfulResponseHandler:
|
|
11924
|
+
successfulResponseHandler: createJsonResponseHandler10(
|
|
11251
11925
|
openaiSkillResponseSchema
|
|
11252
11926
|
),
|
|
11253
11927
|
fetch: this.config.fetch
|
|
@@ -11270,7 +11944,7 @@ var OpenAISkills = class {
|
|
|
11270
11944
|
};
|
|
11271
11945
|
|
|
11272
11946
|
// src/version.ts
|
|
11273
|
-
var VERSION = true ? "4.0.
|
|
11947
|
+
var VERSION = true ? "4.0.67" : "0.0.0-test";
|
|
11274
11948
|
|
|
11275
11949
|
// src/openai-provider.ts
|
|
11276
11950
|
function createOpenAI(options = {}) {
|
|
@@ -11384,29 +12058,6 @@ function createOpenAI(options = {}) {
|
|
|
11384
12058
|
fileIdPrefixes: ["file-"]
|
|
11385
12059
|
}
|
|
11386
12060
|
});
|
|
11387
|
-
const createRealtimeModel = (modelId) => new OpenAIRealtimeModel(modelId, {
|
|
11388
|
-
provider: `${providerName}.realtime`,
|
|
11389
|
-
baseURL,
|
|
11390
|
-
headers: getHeaders,
|
|
11391
|
-
fetch: options.fetch
|
|
11392
|
-
});
|
|
11393
|
-
const experimentalRealtimeFactory = Object.assign(
|
|
11394
|
-
(modelId) => createRealtimeModel(modelId),
|
|
11395
|
-
{
|
|
11396
|
-
getToken: async (tokenOptions) => {
|
|
11397
|
-
const model = createRealtimeModel(tokenOptions.model);
|
|
11398
|
-
const secret = await model.doCreateClientSecret({
|
|
11399
|
-
sessionConfig: tokenOptions.sessionConfig,
|
|
11400
|
-
expiresAfterSeconds: tokenOptions.expiresAfterSeconds
|
|
11401
|
-
});
|
|
11402
|
-
return {
|
|
11403
|
-
token: secret.token,
|
|
11404
|
-
url: secret.url,
|
|
11405
|
-
expiresAt: secret.expiresAt
|
|
11406
|
-
};
|
|
11407
|
-
}
|
|
11408
|
-
}
|
|
11409
|
-
);
|
|
11410
12061
|
const provider = function(modelId) {
|
|
11411
12062
|
return createLanguageModel(modelId);
|
|
11412
12063
|
};
|
|
@@ -11430,13 +12081,19 @@ function createOpenAI(options = {}) {
|
|
|
11430
12081
|
provider.files = createFiles;
|
|
11431
12082
|
provider.skills = createSkills;
|
|
11432
12083
|
provider.experimental_batch = createBatch;
|
|
11433
|
-
provider.experimental_realtime =
|
|
12084
|
+
provider.experimental_realtime = createOpenAIRealtimeFactory({
|
|
12085
|
+
provider: providerName,
|
|
12086
|
+
baseURL,
|
|
12087
|
+
headers: getHeaders,
|
|
12088
|
+
fetch: options.fetch
|
|
12089
|
+
});
|
|
11434
12090
|
provider.tools = openaiTools;
|
|
11435
12091
|
return provider;
|
|
11436
12092
|
}
|
|
11437
12093
|
var openai = createOpenAI();
|
|
11438
12094
|
export {
|
|
11439
12095
|
OpenAIRealtimeModel as Experimental_OpenAIRealtimeModel,
|
|
12096
|
+
OpenAIRealtimeModelLive as Experimental_OpenAIRealtimeModelLive,
|
|
11440
12097
|
OpenAISpeechTranslationModel as Experimental_OpenAISpeechTranslationModel,
|
|
11441
12098
|
OpenAISpeechTranslationModel as Experimental_OpenAITranslationModel,
|
|
11442
12099
|
VERSION,
|