@ai-sdk/openai 2.0.0-beta.1 → 2.0.0-beta.10
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 +67 -0
- package/dist/index.d.mts +12 -27
- package/dist/index.d.ts +12 -27
- package/dist/index.js +592 -397
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +426 -229
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +35 -205
- package/dist/internal/index.d.ts +35 -205
- package/dist/internal/index.js +584 -389
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +421 -224
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
parseProviderOptions,
|
|
18
18
|
postJsonToApi
|
|
19
19
|
} from "@ai-sdk/provider-utils";
|
|
20
|
-
import { z as z5 } from "zod";
|
|
20
|
+
import { z as z5 } from "zod/v4";
|
|
21
21
|
|
|
22
22
|
// src/convert-to-openai-chat-messages.ts
|
|
23
23
|
import {
|
|
@@ -230,7 +230,7 @@ function mapOpenAIFinishReason(finishReason) {
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
// src/openai-chat-options.ts
|
|
233
|
-
import { z } from "zod";
|
|
233
|
+
import { z } from "zod/v4";
|
|
234
234
|
var openaiProviderOptions = z.object({
|
|
235
235
|
/**
|
|
236
236
|
* Modify the likelihood of specified tokens appearing in the completion.
|
|
@@ -273,11 +273,11 @@ var openaiProviderOptions = z.object({
|
|
|
273
273
|
/**
|
|
274
274
|
* Metadata to associate with the request.
|
|
275
275
|
*/
|
|
276
|
-
metadata: z.record(z.string()).optional(),
|
|
276
|
+
metadata: z.record(z.string().max(64), z.string().max(512)).optional(),
|
|
277
277
|
/**
|
|
278
278
|
* Parameters for prediction mode.
|
|
279
279
|
*/
|
|
280
|
-
prediction: z.record(z.any()).optional(),
|
|
280
|
+
prediction: z.record(z.string(), z.any()).optional(),
|
|
281
281
|
/**
|
|
282
282
|
* Whether to use structured outputs.
|
|
283
283
|
*
|
|
@@ -290,11 +290,17 @@ var openaiProviderOptions = z.object({
|
|
|
290
290
|
*
|
|
291
291
|
* @default 'auto'
|
|
292
292
|
*/
|
|
293
|
-
serviceTier: z.enum(["auto", "flex"]).optional()
|
|
293
|
+
serviceTier: z.enum(["auto", "flex"]).optional(),
|
|
294
|
+
/**
|
|
295
|
+
* Whether to use strict JSON schema validation.
|
|
296
|
+
*
|
|
297
|
+
* @default false
|
|
298
|
+
*/
|
|
299
|
+
strictJsonSchema: z.boolean().optional()
|
|
294
300
|
});
|
|
295
301
|
|
|
296
302
|
// src/openai-error.ts
|
|
297
|
-
import { z as z2 } from "zod";
|
|
303
|
+
import { z as z2 } from "zod/v4";
|
|
298
304
|
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
299
305
|
var openaiErrorDataSchema = z2.object({
|
|
300
306
|
error: z2.object({
|
|
@@ -319,7 +325,7 @@ import {
|
|
|
319
325
|
|
|
320
326
|
// src/tool/file-search.ts
|
|
321
327
|
import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
|
|
322
|
-
import { z as z3 } from "zod";
|
|
328
|
+
import { z as z3 } from "zod/v4";
|
|
323
329
|
var fileSearchArgsSchema = z3.object({
|
|
324
330
|
/**
|
|
325
331
|
* List of vector store IDs to search through. If not provided, searches all available vector stores.
|
|
@@ -344,7 +350,7 @@ var fileSearch = createProviderDefinedToolFactory({
|
|
|
344
350
|
|
|
345
351
|
// src/tool/web-search-preview.ts
|
|
346
352
|
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory2 } from "@ai-sdk/provider-utils";
|
|
347
|
-
import { z as z4 } from "zod";
|
|
353
|
+
import { z as z4 } from "zod/v4";
|
|
348
354
|
var webSearchPreviewArgsSchema = z4.object({
|
|
349
355
|
/**
|
|
350
356
|
* Search context size to use for the web search.
|
|
@@ -389,7 +395,8 @@ var webSearchPreview = createProviderDefinedToolFactory2({
|
|
|
389
395
|
function prepareTools({
|
|
390
396
|
tools,
|
|
391
397
|
toolChoice,
|
|
392
|
-
structuredOutputs
|
|
398
|
+
structuredOutputs,
|
|
399
|
+
strictJsonSchema
|
|
393
400
|
}) {
|
|
394
401
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
395
402
|
const toolWarnings = [];
|
|
@@ -406,7 +413,7 @@ function prepareTools({
|
|
|
406
413
|
name: tool.name,
|
|
407
414
|
description: tool.description,
|
|
408
415
|
parameters: tool.inputSchema,
|
|
409
|
-
strict: structuredOutputs ?
|
|
416
|
+
strict: structuredOutputs ? strictJsonSchema : void 0
|
|
410
417
|
}
|
|
411
418
|
});
|
|
412
419
|
break;
|
|
@@ -498,7 +505,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
498
505
|
toolChoice,
|
|
499
506
|
providerOptions
|
|
500
507
|
}) {
|
|
501
|
-
var _a, _b, _c;
|
|
508
|
+
var _a, _b, _c, _d;
|
|
502
509
|
const warnings = [];
|
|
503
510
|
const openaiOptions = (_a = await parseProviderOptions({
|
|
504
511
|
provider: "openai",
|
|
@@ -526,6 +533,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
526
533
|
}
|
|
527
534
|
);
|
|
528
535
|
warnings.push(...messageWarnings);
|
|
536
|
+
const strictJsonSchema = (_c = openaiOptions.strictJsonSchema) != null ? _c : false;
|
|
529
537
|
const baseArgs = {
|
|
530
538
|
// model id:
|
|
531
539
|
model: this.modelId,
|
|
@@ -541,18 +549,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
541
549
|
top_p: topP,
|
|
542
550
|
frequency_penalty: frequencyPenalty,
|
|
543
551
|
presence_penalty: presencePenalty,
|
|
544
|
-
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ?
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
} : { type: "json_object" }
|
|
555
|
-
) : void 0,
|
|
552
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && responseFormat.schema != null ? {
|
|
553
|
+
type: "json_schema",
|
|
554
|
+
json_schema: {
|
|
555
|
+
schema: responseFormat.schema,
|
|
556
|
+
strict: strictJsonSchema,
|
|
557
|
+
name: (_d = responseFormat.name) != null ? _d : "response",
|
|
558
|
+
description: responseFormat.description
|
|
559
|
+
}
|
|
560
|
+
} : { type: "json_object" } : void 0,
|
|
556
561
|
stop: stopSequences,
|
|
557
562
|
seed,
|
|
558
563
|
// openai specific settings:
|
|
@@ -651,7 +656,8 @@ var OpenAIChatLanguageModel = class {
|
|
|
651
656
|
} = prepareTools({
|
|
652
657
|
tools,
|
|
653
658
|
toolChoice,
|
|
654
|
-
structuredOutputs
|
|
659
|
+
structuredOutputs,
|
|
660
|
+
strictJsonSchema
|
|
655
661
|
});
|
|
656
662
|
return {
|
|
657
663
|
args: {
|
|
@@ -1084,7 +1090,7 @@ import {
|
|
|
1084
1090
|
parseProviderOptions as parseProviderOptions2,
|
|
1085
1091
|
postJsonToApi as postJsonToApi2
|
|
1086
1092
|
} from "@ai-sdk/provider-utils";
|
|
1087
|
-
import { z as z7 } from "zod";
|
|
1093
|
+
import { z as z7 } from "zod/v4";
|
|
1088
1094
|
|
|
1089
1095
|
// src/convert-to-openai-completion-prompt.ts
|
|
1090
1096
|
import {
|
|
@@ -1165,7 +1171,7 @@ ${user}:`]
|
|
|
1165
1171
|
}
|
|
1166
1172
|
|
|
1167
1173
|
// src/openai-completion-options.ts
|
|
1168
|
-
import { z as z6 } from "zod";
|
|
1174
|
+
import { z as z6 } from "zod/v4";
|
|
1169
1175
|
var openaiCompletionProviderOptions = z6.object({
|
|
1170
1176
|
/**
|
|
1171
1177
|
Echo back the prompt in addition to the completion.
|
|
@@ -1490,10 +1496,10 @@ import {
|
|
|
1490
1496
|
parseProviderOptions as parseProviderOptions3,
|
|
1491
1497
|
postJsonToApi as postJsonToApi3
|
|
1492
1498
|
} from "@ai-sdk/provider-utils";
|
|
1493
|
-
import { z as z9 } from "zod";
|
|
1499
|
+
import { z as z9 } from "zod/v4";
|
|
1494
1500
|
|
|
1495
1501
|
// src/openai-embedding-options.ts
|
|
1496
|
-
import { z as z8 } from "zod";
|
|
1502
|
+
import { z as z8 } from "zod/v4";
|
|
1497
1503
|
var openaiEmbeddingProviderOptions = z8.object({
|
|
1498
1504
|
/**
|
|
1499
1505
|
The number of dimensions the resulting output embeddings should have.
|
|
@@ -1581,7 +1587,7 @@ import {
|
|
|
1581
1587
|
createJsonResponseHandler as createJsonResponseHandler4,
|
|
1582
1588
|
postJsonToApi as postJsonToApi4
|
|
1583
1589
|
} from "@ai-sdk/provider-utils";
|
|
1584
|
-
import { z as z10 } from "zod";
|
|
1590
|
+
import { z as z10 } from "zod/v4";
|
|
1585
1591
|
|
|
1586
1592
|
// src/openai-image-settings.ts
|
|
1587
1593
|
var modelMaxImagesPerCall = {
|
|
@@ -1689,10 +1695,10 @@ import {
|
|
|
1689
1695
|
parseProviderOptions as parseProviderOptions4,
|
|
1690
1696
|
postFormDataToApi
|
|
1691
1697
|
} from "@ai-sdk/provider-utils";
|
|
1692
|
-
import { z as z12 } from "zod";
|
|
1698
|
+
import { z as z12 } from "zod/v4";
|
|
1693
1699
|
|
|
1694
1700
|
// src/openai-transcription-options.ts
|
|
1695
|
-
import { z as z11 } from "zod";
|
|
1701
|
+
import { z as z11 } from "zod/v4";
|
|
1696
1702
|
var openAITranscriptionProviderOptions = z11.object({
|
|
1697
1703
|
/**
|
|
1698
1704
|
* Additional information to include in the transcription response.
|
|
@@ -1877,24 +1883,30 @@ var openaiTranscriptionResponseSchema = z12.object({
|
|
|
1877
1883
|
});
|
|
1878
1884
|
|
|
1879
1885
|
// src/responses/openai-responses-language-model.ts
|
|
1886
|
+
import {
|
|
1887
|
+
APICallError
|
|
1888
|
+
} from "@ai-sdk/provider";
|
|
1880
1889
|
import {
|
|
1881
1890
|
combineHeaders as combineHeaders6,
|
|
1882
1891
|
createEventSourceResponseHandler as createEventSourceResponseHandler3,
|
|
1883
1892
|
createJsonResponseHandler as createJsonResponseHandler6,
|
|
1884
1893
|
generateId as generateId2,
|
|
1885
|
-
parseProviderOptions as
|
|
1894
|
+
parseProviderOptions as parseProviderOptions6,
|
|
1886
1895
|
postJsonToApi as postJsonToApi5
|
|
1887
1896
|
} from "@ai-sdk/provider-utils";
|
|
1888
|
-
import { z as
|
|
1897
|
+
import { z as z14 } from "zod/v4";
|
|
1889
1898
|
|
|
1890
1899
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1891
1900
|
import {
|
|
1892
1901
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError4
|
|
1893
1902
|
} from "@ai-sdk/provider";
|
|
1894
|
-
|
|
1903
|
+
import { parseProviderOptions as parseProviderOptions5 } from "@ai-sdk/provider-utils";
|
|
1904
|
+
import { z as z13 } from "zod/v4";
|
|
1905
|
+
async function convertToOpenAIResponsesMessages({
|
|
1895
1906
|
prompt,
|
|
1896
1907
|
systemMessageMode
|
|
1897
1908
|
}) {
|
|
1909
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1898
1910
|
const messages = [];
|
|
1899
1911
|
const warnings = [];
|
|
1900
1912
|
for (const { role, content } of prompt) {
|
|
@@ -1929,7 +1941,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1929
1941
|
messages.push({
|
|
1930
1942
|
role: "user",
|
|
1931
1943
|
content: content.map((part, index) => {
|
|
1932
|
-
var
|
|
1944
|
+
var _a2, _b2, _c2;
|
|
1933
1945
|
switch (part.type) {
|
|
1934
1946
|
case "text": {
|
|
1935
1947
|
return { type: "input_text", text: part.text };
|
|
@@ -1941,7 +1953,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1941
1953
|
type: "input_image",
|
|
1942
1954
|
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
1943
1955
|
// OpenAI specific extension: image detail
|
|
1944
|
-
detail: (
|
|
1956
|
+
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
|
|
1945
1957
|
};
|
|
1946
1958
|
} else if (part.mediaType === "application/pdf") {
|
|
1947
1959
|
if (part.data instanceof URL) {
|
|
@@ -1951,7 +1963,7 @@ function convertToOpenAIResponsesMessages({
|
|
|
1951
1963
|
}
|
|
1952
1964
|
return {
|
|
1953
1965
|
type: "input_file",
|
|
1954
|
-
filename: (
|
|
1966
|
+
filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
|
|
1955
1967
|
file_data: `data:application/pdf;base64,${part.data}`
|
|
1956
1968
|
};
|
|
1957
1969
|
} else {
|
|
@@ -1966,12 +1978,14 @@ function convertToOpenAIResponsesMessages({
|
|
|
1966
1978
|
break;
|
|
1967
1979
|
}
|
|
1968
1980
|
case "assistant": {
|
|
1981
|
+
const reasoningMessages = {};
|
|
1969
1982
|
for (const part of content) {
|
|
1970
1983
|
switch (part.type) {
|
|
1971
1984
|
case "text": {
|
|
1972
1985
|
messages.push({
|
|
1973
1986
|
role: "assistant",
|
|
1974
|
-
content: [{ type: "output_text", text: part.text }]
|
|
1987
|
+
content: [{ type: "output_text", text: part.text }],
|
|
1988
|
+
id: (_c = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId) != null ? _c : void 0
|
|
1975
1989
|
});
|
|
1976
1990
|
break;
|
|
1977
1991
|
}
|
|
@@ -1983,7 +1997,8 @@ function convertToOpenAIResponsesMessages({
|
|
|
1983
1997
|
type: "function_call",
|
|
1984
1998
|
call_id: part.toolCallId,
|
|
1985
1999
|
name: part.toolName,
|
|
1986
|
-
arguments: JSON.stringify(part.input)
|
|
2000
|
+
arguments: JSON.stringify(part.input),
|
|
2001
|
+
id: (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.openai) == null ? void 0 : _e.itemId) != null ? _f : void 0
|
|
1987
2002
|
});
|
|
1988
2003
|
break;
|
|
1989
2004
|
}
|
|
@@ -1994,6 +2009,43 @@ function convertToOpenAIResponsesMessages({
|
|
|
1994
2009
|
});
|
|
1995
2010
|
break;
|
|
1996
2011
|
}
|
|
2012
|
+
case "reasoning": {
|
|
2013
|
+
const providerOptions = await parseProviderOptions5({
|
|
2014
|
+
provider: "openai",
|
|
2015
|
+
providerOptions: part.providerOptions,
|
|
2016
|
+
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
2017
|
+
});
|
|
2018
|
+
const reasoningId = providerOptions == null ? void 0 : providerOptions.itemId;
|
|
2019
|
+
if (reasoningId != null) {
|
|
2020
|
+
const existingReasoningMessage = reasoningMessages[reasoningId];
|
|
2021
|
+
const summaryParts = [];
|
|
2022
|
+
if (part.text.length > 0) {
|
|
2023
|
+
summaryParts.push({ type: "summary_text", text: part.text });
|
|
2024
|
+
} else if (existingReasoningMessage !== void 0) {
|
|
2025
|
+
warnings.push({
|
|
2026
|
+
type: "other",
|
|
2027
|
+
message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
2028
|
+
});
|
|
2029
|
+
}
|
|
2030
|
+
if (existingReasoningMessage === void 0) {
|
|
2031
|
+
reasoningMessages[reasoningId] = {
|
|
2032
|
+
type: "reasoning",
|
|
2033
|
+
id: reasoningId,
|
|
2034
|
+
encrypted_content: providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent,
|
|
2035
|
+
summary: summaryParts
|
|
2036
|
+
};
|
|
2037
|
+
messages.push(reasoningMessages[reasoningId]);
|
|
2038
|
+
} else {
|
|
2039
|
+
existingReasoningMessage.summary.push(...summaryParts);
|
|
2040
|
+
}
|
|
2041
|
+
} else {
|
|
2042
|
+
warnings.push({
|
|
2043
|
+
type: "other",
|
|
2044
|
+
message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
break;
|
|
2048
|
+
}
|
|
1997
2049
|
}
|
|
1998
2050
|
}
|
|
1999
2051
|
break;
|
|
@@ -2029,6 +2081,10 @@ function convertToOpenAIResponsesMessages({
|
|
|
2029
2081
|
}
|
|
2030
2082
|
return { messages, warnings };
|
|
2031
2083
|
}
|
|
2084
|
+
var openaiResponsesReasoningProviderOptionsSchema = z13.object({
|
|
2085
|
+
itemId: z13.string().nullish(),
|
|
2086
|
+
reasoningEncryptedContent: z13.string().nullish()
|
|
2087
|
+
});
|
|
2032
2088
|
|
|
2033
2089
|
// src/responses/map-openai-responses-finish-reason.ts
|
|
2034
2090
|
function mapOpenAIResponseFinishReason({
|
|
@@ -2055,7 +2111,7 @@ import {
|
|
|
2055
2111
|
function prepareResponsesTools({
|
|
2056
2112
|
tools,
|
|
2057
2113
|
toolChoice,
|
|
2058
|
-
|
|
2114
|
+
strictJsonSchema
|
|
2059
2115
|
}) {
|
|
2060
2116
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
2061
2117
|
const toolWarnings = [];
|
|
@@ -2071,11 +2127,21 @@ function prepareResponsesTools({
|
|
|
2071
2127
|
name: tool.name,
|
|
2072
2128
|
description: tool.description,
|
|
2073
2129
|
parameters: tool.inputSchema,
|
|
2074
|
-
strict:
|
|
2130
|
+
strict: strictJsonSchema
|
|
2075
2131
|
});
|
|
2076
2132
|
break;
|
|
2077
2133
|
case "provider-defined":
|
|
2078
2134
|
switch (tool.id) {
|
|
2135
|
+
case "openai.file_search": {
|
|
2136
|
+
const args = fileSearchArgsSchema.parse(tool.args);
|
|
2137
|
+
openaiTools2.push({
|
|
2138
|
+
type: "file_search",
|
|
2139
|
+
vector_store_ids: args.vectorStoreIds,
|
|
2140
|
+
max_results: args.maxResults,
|
|
2141
|
+
search_type: args.searchType
|
|
2142
|
+
});
|
|
2143
|
+
break;
|
|
2144
|
+
}
|
|
2079
2145
|
case "openai.web_search_preview":
|
|
2080
2146
|
openaiTools2.push({
|
|
2081
2147
|
type: "web_search_preview",
|
|
@@ -2105,7 +2171,7 @@ function prepareResponsesTools({
|
|
|
2105
2171
|
case "tool":
|
|
2106
2172
|
return {
|
|
2107
2173
|
tools: openaiTools2,
|
|
2108
|
-
toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
2174
|
+
toolChoice: toolChoice.toolName === "file_search" ? { type: "file_search" } : toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
2109
2175
|
toolWarnings
|
|
2110
2176
|
};
|
|
2111
2177
|
default: {
|
|
@@ -2169,17 +2235,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2169
2235
|
if (stopSequences != null) {
|
|
2170
2236
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
2171
2237
|
}
|
|
2172
|
-
const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
|
|
2238
|
+
const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
|
|
2173
2239
|
prompt,
|
|
2174
2240
|
systemMessageMode: modelConfig.systemMessageMode
|
|
2175
2241
|
});
|
|
2176
2242
|
warnings.push(...messageWarnings);
|
|
2177
|
-
const openaiOptions = await
|
|
2243
|
+
const openaiOptions = await parseProviderOptions6({
|
|
2178
2244
|
provider: "openai",
|
|
2179
2245
|
providerOptions,
|
|
2180
2246
|
schema: openaiResponsesProviderOptionsSchema
|
|
2181
2247
|
});
|
|
2182
|
-
const
|
|
2248
|
+
const strictJsonSchema = (_a = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _a : false;
|
|
2183
2249
|
const baseArgs = {
|
|
2184
2250
|
model: this.modelId,
|
|
2185
2251
|
input: messages,
|
|
@@ -2190,7 +2256,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2190
2256
|
text: {
|
|
2191
2257
|
format: responseFormat.schema != null ? {
|
|
2192
2258
|
type: "json_schema",
|
|
2193
|
-
strict:
|
|
2259
|
+
strict: strictJsonSchema,
|
|
2194
2260
|
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
2195
2261
|
description: responseFormat.description,
|
|
2196
2262
|
schema: responseFormat.schema
|
|
@@ -2205,6 +2271,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2205
2271
|
user: openaiOptions == null ? void 0 : openaiOptions.user,
|
|
2206
2272
|
instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
|
|
2207
2273
|
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
2274
|
+
include: openaiOptions == null ? void 0 : openaiOptions.include,
|
|
2208
2275
|
// model-specific settings:
|
|
2209
2276
|
...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
2210
2277
|
reasoning: {
|
|
@@ -2237,6 +2304,21 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2237
2304
|
details: "topP is not supported for reasoning models"
|
|
2238
2305
|
});
|
|
2239
2306
|
}
|
|
2307
|
+
} else {
|
|
2308
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
|
|
2309
|
+
warnings.push({
|
|
2310
|
+
type: "unsupported-setting",
|
|
2311
|
+
setting: "reasoningEffort",
|
|
2312
|
+
details: "reasoningEffort is not supported for non-reasoning models"
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) {
|
|
2316
|
+
warnings.push({
|
|
2317
|
+
type: "unsupported-setting",
|
|
2318
|
+
setting: "reasoningSummary",
|
|
2319
|
+
details: "reasoningSummary is not supported for non-reasoning models"
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2240
2322
|
}
|
|
2241
2323
|
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
|
|
2242
2324
|
warnings.push({
|
|
@@ -2253,7 +2335,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2253
2335
|
} = prepareResponsesTools({
|
|
2254
2336
|
tools,
|
|
2255
2337
|
toolChoice,
|
|
2256
|
-
|
|
2338
|
+
strictJsonSchema
|
|
2257
2339
|
});
|
|
2258
2340
|
return {
|
|
2259
2341
|
args: {
|
|
@@ -2265,101 +2347,137 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2265
2347
|
};
|
|
2266
2348
|
}
|
|
2267
2349
|
async doGenerate(options) {
|
|
2268
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2350
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2269
2351
|
const { args: body, warnings } = await this.getArgs(options);
|
|
2352
|
+
const url = this.config.url({
|
|
2353
|
+
path: "/responses",
|
|
2354
|
+
modelId: this.modelId
|
|
2355
|
+
});
|
|
2270
2356
|
const {
|
|
2271
2357
|
responseHeaders,
|
|
2272
2358
|
value: response,
|
|
2273
2359
|
rawValue: rawResponse
|
|
2274
2360
|
} = await postJsonToApi5({
|
|
2275
|
-
url
|
|
2276
|
-
path: "/responses",
|
|
2277
|
-
modelId: this.modelId
|
|
2278
|
-
}),
|
|
2361
|
+
url,
|
|
2279
2362
|
headers: combineHeaders6(this.config.headers(), options.headers),
|
|
2280
2363
|
body,
|
|
2281
2364
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2282
2365
|
successfulResponseHandler: createJsonResponseHandler6(
|
|
2283
|
-
|
|
2284
|
-
id:
|
|
2285
|
-
created_at:
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2366
|
+
z14.object({
|
|
2367
|
+
id: z14.string(),
|
|
2368
|
+
created_at: z14.number(),
|
|
2369
|
+
error: z14.object({
|
|
2370
|
+
code: z14.string(),
|
|
2371
|
+
message: z14.string()
|
|
2372
|
+
}).nullish(),
|
|
2373
|
+
model: z14.string(),
|
|
2374
|
+
output: z14.array(
|
|
2375
|
+
z14.discriminatedUnion("type", [
|
|
2376
|
+
z14.object({
|
|
2377
|
+
type: z14.literal("message"),
|
|
2378
|
+
role: z14.literal("assistant"),
|
|
2379
|
+
id: z14.string(),
|
|
2380
|
+
content: z14.array(
|
|
2381
|
+
z14.object({
|
|
2382
|
+
type: z14.literal("output_text"),
|
|
2383
|
+
text: z14.string(),
|
|
2384
|
+
annotations: z14.array(
|
|
2385
|
+
z14.object({
|
|
2386
|
+
type: z14.literal("url_citation"),
|
|
2387
|
+
start_index: z14.number(),
|
|
2388
|
+
end_index: z14.number(),
|
|
2389
|
+
url: z14.string(),
|
|
2390
|
+
title: z14.string()
|
|
2303
2391
|
})
|
|
2304
2392
|
)
|
|
2305
2393
|
})
|
|
2306
2394
|
)
|
|
2307
2395
|
}),
|
|
2308
|
-
|
|
2309
|
-
type:
|
|
2310
|
-
call_id:
|
|
2311
|
-
name:
|
|
2312
|
-
arguments:
|
|
2396
|
+
z14.object({
|
|
2397
|
+
type: z14.literal("function_call"),
|
|
2398
|
+
call_id: z14.string(),
|
|
2399
|
+
name: z14.string(),
|
|
2400
|
+
arguments: z14.string(),
|
|
2401
|
+
id: z14.string()
|
|
2313
2402
|
}),
|
|
2314
|
-
|
|
2315
|
-
type:
|
|
2316
|
-
id:
|
|
2317
|
-
status:
|
|
2403
|
+
z14.object({
|
|
2404
|
+
type: z14.literal("web_search_call"),
|
|
2405
|
+
id: z14.string(),
|
|
2406
|
+
status: z14.string().optional()
|
|
2318
2407
|
}),
|
|
2319
|
-
|
|
2320
|
-
type:
|
|
2321
|
-
id:
|
|
2322
|
-
status:
|
|
2408
|
+
z14.object({
|
|
2409
|
+
type: z14.literal("computer_call"),
|
|
2410
|
+
id: z14.string(),
|
|
2411
|
+
status: z14.string().optional()
|
|
2323
2412
|
}),
|
|
2324
|
-
|
|
2325
|
-
type:
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2413
|
+
z14.object({
|
|
2414
|
+
type: z14.literal("reasoning"),
|
|
2415
|
+
id: z14.string(),
|
|
2416
|
+
encrypted_content: z14.string().nullish(),
|
|
2417
|
+
summary: z14.array(
|
|
2418
|
+
z14.object({
|
|
2419
|
+
type: z14.literal("summary_text"),
|
|
2420
|
+
text: z14.string()
|
|
2330
2421
|
})
|
|
2331
2422
|
)
|
|
2332
2423
|
})
|
|
2333
2424
|
])
|
|
2334
2425
|
),
|
|
2335
|
-
incomplete_details:
|
|
2426
|
+
incomplete_details: z14.object({ reason: z14.string() }).nullable(),
|
|
2336
2427
|
usage: usageSchema2
|
|
2337
2428
|
})
|
|
2338
2429
|
),
|
|
2339
2430
|
abortSignal: options.abortSignal,
|
|
2340
2431
|
fetch: this.config.fetch
|
|
2341
2432
|
});
|
|
2433
|
+
if (response.error) {
|
|
2434
|
+
throw new APICallError({
|
|
2435
|
+
message: response.error.message,
|
|
2436
|
+
url,
|
|
2437
|
+
requestBodyValues: body,
|
|
2438
|
+
statusCode: 400,
|
|
2439
|
+
responseHeaders,
|
|
2440
|
+
responseBody: rawResponse,
|
|
2441
|
+
isRetryable: false
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2342
2444
|
const content = [];
|
|
2343
2445
|
for (const part of response.output) {
|
|
2344
2446
|
switch (part.type) {
|
|
2345
2447
|
case "reasoning": {
|
|
2346
|
-
|
|
2347
|
-
type: "
|
|
2348
|
-
|
|
2349
|
-
|
|
2448
|
+
if (part.summary.length === 0) {
|
|
2449
|
+
part.summary.push({ type: "summary_text", text: "" });
|
|
2450
|
+
}
|
|
2451
|
+
for (const summary of part.summary) {
|
|
2452
|
+
content.push({
|
|
2453
|
+
type: "reasoning",
|
|
2454
|
+
text: summary.text,
|
|
2455
|
+
providerMetadata: {
|
|
2456
|
+
openai: {
|
|
2457
|
+
itemId: part.id,
|
|
2458
|
+
reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2350
2463
|
break;
|
|
2351
2464
|
}
|
|
2352
2465
|
case "message": {
|
|
2353
2466
|
for (const contentPart of part.content) {
|
|
2354
2467
|
content.push({
|
|
2355
2468
|
type: "text",
|
|
2356
|
-
text: contentPart.text
|
|
2469
|
+
text: contentPart.text,
|
|
2470
|
+
providerMetadata: {
|
|
2471
|
+
openai: {
|
|
2472
|
+
itemId: part.id
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2357
2475
|
});
|
|
2358
2476
|
for (const annotation of contentPart.annotations) {
|
|
2359
2477
|
content.push({
|
|
2360
2478
|
type: "source",
|
|
2361
2479
|
sourceType: "url",
|
|
2362
|
-
id: (
|
|
2480
|
+
id: (_d = (_c = (_b = this.config).generateId) == null ? void 0 : _c.call(_b)) != null ? _d : generateId2(),
|
|
2363
2481
|
url: annotation.url,
|
|
2364
2482
|
title: annotation.title
|
|
2365
2483
|
});
|
|
@@ -2372,7 +2490,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2372
2490
|
type: "tool-call",
|
|
2373
2491
|
toolCallId: part.call_id,
|
|
2374
2492
|
toolName: part.name,
|
|
2375
|
-
input: part.arguments
|
|
2493
|
+
input: part.arguments,
|
|
2494
|
+
providerMetadata: {
|
|
2495
|
+
openai: {
|
|
2496
|
+
itemId: part.id
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2376
2499
|
});
|
|
2377
2500
|
break;
|
|
2378
2501
|
}
|
|
@@ -2418,15 +2541,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2418
2541
|
return {
|
|
2419
2542
|
content,
|
|
2420
2543
|
finishReason: mapOpenAIResponseFinishReason({
|
|
2421
|
-
finishReason: (
|
|
2544
|
+
finishReason: (_e = response.incomplete_details) == null ? void 0 : _e.reason,
|
|
2422
2545
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
|
2423
2546
|
}),
|
|
2424
2547
|
usage: {
|
|
2425
2548
|
inputTokens: response.usage.input_tokens,
|
|
2426
2549
|
outputTokens: response.usage.output_tokens,
|
|
2427
2550
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
2428
|
-
reasoningTokens: (
|
|
2429
|
-
cachedInputTokens: (
|
|
2551
|
+
reasoningTokens: (_g = (_f = response.usage.output_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0,
|
|
2552
|
+
cachedInputTokens: (_i = (_h = response.usage.input_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : void 0
|
|
2430
2553
|
},
|
|
2431
2554
|
request: { body },
|
|
2432
2555
|
response: {
|
|
@@ -2473,6 +2596,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2473
2596
|
let responseId = null;
|
|
2474
2597
|
const ongoingToolCalls = {};
|
|
2475
2598
|
let hasToolCalls = false;
|
|
2599
|
+
const activeReasoning = {};
|
|
2476
2600
|
return {
|
|
2477
2601
|
stream: response.pipeThrough(
|
|
2478
2602
|
new TransformStream({
|
|
@@ -2480,7 +2604,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2480
2604
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2481
2605
|
},
|
|
2482
2606
|
transform(chunk, controller) {
|
|
2483
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2607
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2484
2608
|
if (options.includeRawChunks) {
|
|
2485
2609
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2486
2610
|
}
|
|
@@ -2524,12 +2648,27 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2524
2648
|
} else if (value.item.type === "message") {
|
|
2525
2649
|
controller.enqueue({
|
|
2526
2650
|
type: "text-start",
|
|
2527
|
-
id: value.item.id
|
|
2651
|
+
id: value.item.id,
|
|
2652
|
+
providerMetadata: {
|
|
2653
|
+
openai: {
|
|
2654
|
+
itemId: value.item.id
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2528
2657
|
});
|
|
2529
|
-
} else if (value
|
|
2658
|
+
} else if (isResponseOutputItemAddedReasoningChunk(value)) {
|
|
2659
|
+
activeReasoning[value.item.id] = {
|
|
2660
|
+
encryptedContent: value.item.encrypted_content,
|
|
2661
|
+
summaryParts: [0]
|
|
2662
|
+
};
|
|
2530
2663
|
controller.enqueue({
|
|
2531
2664
|
type: "reasoning-start",
|
|
2532
|
-
id: value.item.id
|
|
2665
|
+
id: `${value.item.id}:0`,
|
|
2666
|
+
providerMetadata: {
|
|
2667
|
+
openai: {
|
|
2668
|
+
itemId: value.item.id,
|
|
2669
|
+
reasoningEncryptedContent: (_a = value.item.encrypted_content) != null ? _a : null
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2533
2672
|
});
|
|
2534
2673
|
}
|
|
2535
2674
|
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
@@ -2544,7 +2683,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2544
2683
|
type: "tool-call",
|
|
2545
2684
|
toolCallId: value.item.call_id,
|
|
2546
2685
|
toolName: value.item.name,
|
|
2547
|
-
input: value.item.arguments
|
|
2686
|
+
input: value.item.arguments,
|
|
2687
|
+
providerMetadata: {
|
|
2688
|
+
openai: {
|
|
2689
|
+
itemId: value.item.id
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2548
2692
|
});
|
|
2549
2693
|
} else if (value.item.type === "web_search_call") {
|
|
2550
2694
|
ongoingToolCalls[value.output_index] = void 0;
|
|
@@ -2599,11 +2743,21 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2599
2743
|
type: "text-end",
|
|
2600
2744
|
id: value.item.id
|
|
2601
2745
|
});
|
|
2602
|
-
} else if (value
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2746
|
+
} else if (isResponseOutputItemDoneReasoningChunk(value)) {
|
|
2747
|
+
const activeReasoningPart = activeReasoning[value.item.id];
|
|
2748
|
+
for (const summaryIndex of activeReasoningPart.summaryParts) {
|
|
2749
|
+
controller.enqueue({
|
|
2750
|
+
type: "reasoning-end",
|
|
2751
|
+
id: `${value.item.id}:${summaryIndex}`,
|
|
2752
|
+
providerMetadata: {
|
|
2753
|
+
openai: {
|
|
2754
|
+
itemId: value.item.id,
|
|
2755
|
+
reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
});
|
|
2759
|
+
}
|
|
2760
|
+
delete activeReasoning[value.item.id];
|
|
2607
2761
|
}
|
|
2608
2762
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
2609
2763
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -2628,30 +2782,53 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2628
2782
|
id: value.item_id,
|
|
2629
2783
|
delta: value.delta
|
|
2630
2784
|
});
|
|
2785
|
+
} else if (isResponseReasoningSummaryPartAddedChunk(value)) {
|
|
2786
|
+
if (value.summary_index > 0) {
|
|
2787
|
+
(_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
|
|
2788
|
+
value.summary_index
|
|
2789
|
+
);
|
|
2790
|
+
controller.enqueue({
|
|
2791
|
+
type: "reasoning-start",
|
|
2792
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2793
|
+
providerMetadata: {
|
|
2794
|
+
openai: {
|
|
2795
|
+
itemId: value.item_id,
|
|
2796
|
+
reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
});
|
|
2800
|
+
}
|
|
2631
2801
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2632
2802
|
controller.enqueue({
|
|
2633
2803
|
type: "reasoning-delta",
|
|
2804
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2634
2805
|
delta: value.delta,
|
|
2635
|
-
|
|
2806
|
+
providerMetadata: {
|
|
2807
|
+
openai: {
|
|
2808
|
+
itemId: value.item_id
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2636
2811
|
});
|
|
2637
2812
|
} else if (isResponseFinishedChunk(value)) {
|
|
2638
2813
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2639
|
-
finishReason: (
|
|
2814
|
+
finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
|
|
2640
2815
|
hasToolCalls
|
|
2641
2816
|
});
|
|
2642
2817
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2643
2818
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
2644
2819
|
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
2645
|
-
usage.reasoningTokens = (
|
|
2646
|
-
usage.cachedInputTokens = (
|
|
2820
|
+
usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
|
|
2821
|
+
usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
|
|
2647
2822
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2648
2823
|
controller.enqueue({
|
|
2649
2824
|
type: "source",
|
|
2650
2825
|
sourceType: "url",
|
|
2651
|
-
id: (
|
|
2826
|
+
id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
|
|
2652
2827
|
url: value.annotation.url,
|
|
2653
2828
|
title: value.annotation.title
|
|
2654
2829
|
});
|
|
2830
|
+
} else if (isErrorChunk(value)) {
|
|
2831
|
+
controller.enqueue({ type: "error", error: value });
|
|
2655
2832
|
}
|
|
2656
2833
|
},
|
|
2657
2834
|
flush(controller) {
|
|
@@ -2673,124 +2850,130 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2673
2850
|
};
|
|
2674
2851
|
}
|
|
2675
2852
|
};
|
|
2676
|
-
var usageSchema2 =
|
|
2677
|
-
input_tokens:
|
|
2678
|
-
input_tokens_details:
|
|
2679
|
-
output_tokens:
|
|
2680
|
-
output_tokens_details:
|
|
2853
|
+
var usageSchema2 = z14.object({
|
|
2854
|
+
input_tokens: z14.number(),
|
|
2855
|
+
input_tokens_details: z14.object({ cached_tokens: z14.number().nullish() }).nullish(),
|
|
2856
|
+
output_tokens: z14.number(),
|
|
2857
|
+
output_tokens_details: z14.object({ reasoning_tokens: z14.number().nullish() }).nullish()
|
|
2858
|
+
});
|
|
2859
|
+
var textDeltaChunkSchema = z14.object({
|
|
2860
|
+
type: z14.literal("response.output_text.delta"),
|
|
2861
|
+
item_id: z14.string(),
|
|
2862
|
+
delta: z14.string()
|
|
2681
2863
|
});
|
|
2682
|
-
var
|
|
2683
|
-
type:
|
|
2684
|
-
|
|
2685
|
-
|
|
2864
|
+
var errorChunkSchema = z14.object({
|
|
2865
|
+
type: z14.literal("error"),
|
|
2866
|
+
code: z14.string(),
|
|
2867
|
+
message: z14.string(),
|
|
2868
|
+
param: z14.string().nullish(),
|
|
2869
|
+
sequence_number: z14.number()
|
|
2686
2870
|
});
|
|
2687
|
-
var responseFinishedChunkSchema =
|
|
2688
|
-
type:
|
|
2689
|
-
response:
|
|
2690
|
-
incomplete_details:
|
|
2871
|
+
var responseFinishedChunkSchema = z14.object({
|
|
2872
|
+
type: z14.enum(["response.completed", "response.incomplete"]),
|
|
2873
|
+
response: z14.object({
|
|
2874
|
+
incomplete_details: z14.object({ reason: z14.string() }).nullish(),
|
|
2691
2875
|
usage: usageSchema2
|
|
2692
2876
|
})
|
|
2693
2877
|
});
|
|
2694
|
-
var responseCreatedChunkSchema =
|
|
2695
|
-
type:
|
|
2696
|
-
response:
|
|
2697
|
-
id:
|
|
2698
|
-
created_at:
|
|
2699
|
-
model:
|
|
2878
|
+
var responseCreatedChunkSchema = z14.object({
|
|
2879
|
+
type: z14.literal("response.created"),
|
|
2880
|
+
response: z14.object({
|
|
2881
|
+
id: z14.string(),
|
|
2882
|
+
created_at: z14.number(),
|
|
2883
|
+
model: z14.string()
|
|
2700
2884
|
})
|
|
2701
2885
|
});
|
|
2702
|
-
var responseOutputItemAddedSchema =
|
|
2703
|
-
type:
|
|
2704
|
-
output_index:
|
|
2705
|
-
item:
|
|
2706
|
-
|
|
2707
|
-
type:
|
|
2708
|
-
id:
|
|
2886
|
+
var responseOutputItemAddedSchema = z14.object({
|
|
2887
|
+
type: z14.literal("response.output_item.added"),
|
|
2888
|
+
output_index: z14.number(),
|
|
2889
|
+
item: z14.discriminatedUnion("type", [
|
|
2890
|
+
z14.object({
|
|
2891
|
+
type: z14.literal("message"),
|
|
2892
|
+
id: z14.string()
|
|
2709
2893
|
}),
|
|
2710
|
-
|
|
2711
|
-
type:
|
|
2712
|
-
id:
|
|
2894
|
+
z14.object({
|
|
2895
|
+
type: z14.literal("reasoning"),
|
|
2896
|
+
id: z14.string(),
|
|
2897
|
+
encrypted_content: z14.string().nullish()
|
|
2713
2898
|
}),
|
|
2714
|
-
|
|
2715
|
-
type:
|
|
2716
|
-
id:
|
|
2717
|
-
call_id:
|
|
2718
|
-
name:
|
|
2719
|
-
arguments:
|
|
2899
|
+
z14.object({
|
|
2900
|
+
type: z14.literal("function_call"),
|
|
2901
|
+
id: z14.string(),
|
|
2902
|
+
call_id: z14.string(),
|
|
2903
|
+
name: z14.string(),
|
|
2904
|
+
arguments: z14.string()
|
|
2720
2905
|
}),
|
|
2721
|
-
|
|
2722
|
-
type:
|
|
2723
|
-
id:
|
|
2724
|
-
status:
|
|
2906
|
+
z14.object({
|
|
2907
|
+
type: z14.literal("web_search_call"),
|
|
2908
|
+
id: z14.string(),
|
|
2909
|
+
status: z14.string()
|
|
2725
2910
|
}),
|
|
2726
|
-
|
|
2727
|
-
type:
|
|
2728
|
-
id:
|
|
2729
|
-
status:
|
|
2911
|
+
z14.object({
|
|
2912
|
+
type: z14.literal("computer_call"),
|
|
2913
|
+
id: z14.string(),
|
|
2914
|
+
status: z14.string()
|
|
2730
2915
|
})
|
|
2731
2916
|
])
|
|
2732
2917
|
});
|
|
2733
|
-
var responseOutputItemDoneSchema =
|
|
2734
|
-
type:
|
|
2735
|
-
output_index:
|
|
2736
|
-
item:
|
|
2737
|
-
|
|
2738
|
-
type:
|
|
2739
|
-
id:
|
|
2918
|
+
var responseOutputItemDoneSchema = z14.object({
|
|
2919
|
+
type: z14.literal("response.output_item.done"),
|
|
2920
|
+
output_index: z14.number(),
|
|
2921
|
+
item: z14.discriminatedUnion("type", [
|
|
2922
|
+
z14.object({
|
|
2923
|
+
type: z14.literal("message"),
|
|
2924
|
+
id: z14.string()
|
|
2740
2925
|
}),
|
|
2741
|
-
|
|
2742
|
-
type:
|
|
2743
|
-
id:
|
|
2926
|
+
z14.object({
|
|
2927
|
+
type: z14.literal("reasoning"),
|
|
2928
|
+
id: z14.string(),
|
|
2929
|
+
encrypted_content: z14.string().nullish()
|
|
2744
2930
|
}),
|
|
2745
|
-
|
|
2746
|
-
type:
|
|
2747
|
-
id:
|
|
2748
|
-
call_id:
|
|
2749
|
-
name:
|
|
2750
|
-
arguments:
|
|
2751
|
-
status:
|
|
2931
|
+
z14.object({
|
|
2932
|
+
type: z14.literal("function_call"),
|
|
2933
|
+
id: z14.string(),
|
|
2934
|
+
call_id: z14.string(),
|
|
2935
|
+
name: z14.string(),
|
|
2936
|
+
arguments: z14.string(),
|
|
2937
|
+
status: z14.literal("completed")
|
|
2752
2938
|
}),
|
|
2753
|
-
|
|
2754
|
-
type:
|
|
2755
|
-
id:
|
|
2756
|
-
status:
|
|
2939
|
+
z14.object({
|
|
2940
|
+
type: z14.literal("web_search_call"),
|
|
2941
|
+
id: z14.string(),
|
|
2942
|
+
status: z14.literal("completed")
|
|
2757
2943
|
}),
|
|
2758
|
-
|
|
2759
|
-
type:
|
|
2760
|
-
id:
|
|
2761
|
-
status:
|
|
2944
|
+
z14.object({
|
|
2945
|
+
type: z14.literal("computer_call"),
|
|
2946
|
+
id: z14.string(),
|
|
2947
|
+
status: z14.literal("completed")
|
|
2762
2948
|
})
|
|
2763
2949
|
])
|
|
2764
2950
|
});
|
|
2765
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2766
|
-
type:
|
|
2767
|
-
item_id:
|
|
2768
|
-
output_index:
|
|
2769
|
-
delta:
|
|
2951
|
+
var responseFunctionCallArgumentsDeltaSchema = z14.object({
|
|
2952
|
+
type: z14.literal("response.function_call_arguments.delta"),
|
|
2953
|
+
item_id: z14.string(),
|
|
2954
|
+
output_index: z14.number(),
|
|
2955
|
+
delta: z14.string()
|
|
2770
2956
|
});
|
|
2771
|
-
var responseAnnotationAddedSchema =
|
|
2772
|
-
type:
|
|
2773
|
-
annotation:
|
|
2774
|
-
type:
|
|
2775
|
-
url:
|
|
2776
|
-
title:
|
|
2957
|
+
var responseAnnotationAddedSchema = z14.object({
|
|
2958
|
+
type: z14.literal("response.output_text.annotation.added"),
|
|
2959
|
+
annotation: z14.object({
|
|
2960
|
+
type: z14.literal("url_citation"),
|
|
2961
|
+
url: z14.string(),
|
|
2962
|
+
title: z14.string()
|
|
2777
2963
|
})
|
|
2778
2964
|
});
|
|
2779
|
-
var
|
|
2780
|
-
type:
|
|
2781
|
-
item_id:
|
|
2782
|
-
|
|
2783
|
-
summary_index: z13.number(),
|
|
2784
|
-
delta: z13.string()
|
|
2965
|
+
var responseReasoningSummaryPartAddedSchema = z14.object({
|
|
2966
|
+
type: z14.literal("response.reasoning_summary_part.added"),
|
|
2967
|
+
item_id: z14.string(),
|
|
2968
|
+
summary_index: z14.number()
|
|
2785
2969
|
});
|
|
2786
|
-
var
|
|
2787
|
-
type:
|
|
2788
|
-
item_id:
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
part: z13.unknown().nullish()
|
|
2970
|
+
var responseReasoningSummaryTextDeltaSchema = z14.object({
|
|
2971
|
+
type: z14.literal("response.reasoning_summary_text.delta"),
|
|
2972
|
+
item_id: z14.string(),
|
|
2973
|
+
summary_index: z14.number(),
|
|
2974
|
+
delta: z14.string()
|
|
2792
2975
|
});
|
|
2793
|
-
var openaiResponsesChunkSchema =
|
|
2976
|
+
var openaiResponsesChunkSchema = z14.union([
|
|
2794
2977
|
textDeltaChunkSchema,
|
|
2795
2978
|
responseFinishedChunkSchema,
|
|
2796
2979
|
responseCreatedChunkSchema,
|
|
@@ -2798,9 +2981,10 @@ var openaiResponsesChunkSchema = z13.union([
|
|
|
2798
2981
|
responseOutputItemDoneSchema,
|
|
2799
2982
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2800
2983
|
responseAnnotationAddedSchema,
|
|
2984
|
+
responseReasoningSummaryPartAddedSchema,
|
|
2801
2985
|
responseReasoningSummaryTextDeltaSchema,
|
|
2802
|
-
|
|
2803
|
-
|
|
2986
|
+
errorChunkSchema,
|
|
2987
|
+
z14.object({ type: z14.string() }).loose()
|
|
2804
2988
|
// fallback for unknown chunks
|
|
2805
2989
|
]);
|
|
2806
2990
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2809,6 +2993,9 @@ function isTextDeltaChunk(chunk) {
|
|
|
2809
2993
|
function isResponseOutputItemDoneChunk(chunk) {
|
|
2810
2994
|
return chunk.type === "response.output_item.done";
|
|
2811
2995
|
}
|
|
2996
|
+
function isResponseOutputItemDoneReasoningChunk(chunk) {
|
|
2997
|
+
return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
|
|
2998
|
+
}
|
|
2812
2999
|
function isResponseFinishedChunk(chunk) {
|
|
2813
3000
|
return chunk.type === "response.completed" || chunk.type === "response.incomplete";
|
|
2814
3001
|
}
|
|
@@ -2821,14 +3008,23 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
|
2821
3008
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
2822
3009
|
return chunk.type === "response.output_item.added";
|
|
2823
3010
|
}
|
|
3011
|
+
function isResponseOutputItemAddedReasoningChunk(chunk) {
|
|
3012
|
+
return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
|
|
3013
|
+
}
|
|
2824
3014
|
function isResponseAnnotationAddedChunk(chunk) {
|
|
2825
3015
|
return chunk.type === "response.output_text.annotation.added";
|
|
2826
3016
|
}
|
|
3017
|
+
function isResponseReasoningSummaryPartAddedChunk(chunk) {
|
|
3018
|
+
return chunk.type === "response.reasoning_summary_part.added";
|
|
3019
|
+
}
|
|
2827
3020
|
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
2828
3021
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
2829
3022
|
}
|
|
3023
|
+
function isErrorChunk(chunk) {
|
|
3024
|
+
return chunk.type === "error";
|
|
3025
|
+
}
|
|
2830
3026
|
function getResponsesModelConfig(modelId) {
|
|
2831
|
-
if (modelId.startsWith("o")) {
|
|
3027
|
+
if (modelId.startsWith("o") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
|
|
2832
3028
|
if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
|
|
2833
3029
|
return {
|
|
2834
3030
|
isReasoningModel: true,
|
|
@@ -2851,30 +3047,31 @@ function getResponsesModelConfig(modelId) {
|
|
|
2851
3047
|
function supportsFlexProcessing2(modelId) {
|
|
2852
3048
|
return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
2853
3049
|
}
|
|
2854
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2855
|
-
metadata:
|
|
2856
|
-
parallelToolCalls:
|
|
2857
|
-
previousResponseId:
|
|
2858
|
-
store:
|
|
2859
|
-
user:
|
|
2860
|
-
reasoningEffort:
|
|
2861
|
-
|
|
2862
|
-
instructions:
|
|
2863
|
-
reasoningSummary:
|
|
2864
|
-
serviceTier:
|
|
3050
|
+
var openaiResponsesProviderOptionsSchema = z14.object({
|
|
3051
|
+
metadata: z14.any().nullish(),
|
|
3052
|
+
parallelToolCalls: z14.boolean().nullish(),
|
|
3053
|
+
previousResponseId: z14.string().nullish(),
|
|
3054
|
+
store: z14.boolean().nullish(),
|
|
3055
|
+
user: z14.string().nullish(),
|
|
3056
|
+
reasoningEffort: z14.string().nullish(),
|
|
3057
|
+
strictJsonSchema: z14.boolean().nullish(),
|
|
3058
|
+
instructions: z14.string().nullish(),
|
|
3059
|
+
reasoningSummary: z14.string().nullish(),
|
|
3060
|
+
serviceTier: z14.enum(["auto", "flex"]).nullish(),
|
|
3061
|
+
include: z14.array(z14.enum(["reasoning.encrypted_content"])).nullish()
|
|
2865
3062
|
});
|
|
2866
3063
|
|
|
2867
3064
|
// src/openai-speech-model.ts
|
|
2868
3065
|
import {
|
|
2869
3066
|
combineHeaders as combineHeaders7,
|
|
2870
3067
|
createBinaryResponseHandler,
|
|
2871
|
-
parseProviderOptions as
|
|
3068
|
+
parseProviderOptions as parseProviderOptions7,
|
|
2872
3069
|
postJsonToApi as postJsonToApi6
|
|
2873
3070
|
} from "@ai-sdk/provider-utils";
|
|
2874
|
-
import { z as
|
|
2875
|
-
var OpenAIProviderOptionsSchema =
|
|
2876
|
-
instructions:
|
|
2877
|
-
speed:
|
|
3071
|
+
import { z as z15 } from "zod/v4";
|
|
3072
|
+
var OpenAIProviderOptionsSchema = z15.object({
|
|
3073
|
+
instructions: z15.string().nullish(),
|
|
3074
|
+
speed: z15.number().min(0.25).max(4).default(1).nullish()
|
|
2878
3075
|
});
|
|
2879
3076
|
var OpenAISpeechModel = class {
|
|
2880
3077
|
constructor(modelId, config) {
|
|
@@ -2895,7 +3092,7 @@ var OpenAISpeechModel = class {
|
|
|
2895
3092
|
providerOptions
|
|
2896
3093
|
}) {
|
|
2897
3094
|
const warnings = [];
|
|
2898
|
-
const openAIOptions = await
|
|
3095
|
+
const openAIOptions = await parseProviderOptions7({
|
|
2899
3096
|
provider: "openai",
|
|
2900
3097
|
providerOptions,
|
|
2901
3098
|
schema: OpenAIProviderOptionsSchema
|