@ai-sdk/openai 4.0.97 → 4.0.99
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 +23 -0
- package/dist/index.d.ts +21 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +179 -122
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +37 -44
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +151 -100
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +52 -8
- package/package.json +4 -3
- package/src/chat/openai-chat-api.ts +1 -1
- package/src/completion/openai-completion-api.ts +1 -1
- package/src/files/openai-files.ts +1 -11
- package/src/image/openai-image-model-options.ts +40 -39
- package/src/live/openai-realtime-model-live.ts +13 -4
- package/src/openai-batch.ts +2 -2
- package/src/openai-decision-model.ts +71 -50
- package/src/openai-error.ts +22 -14
- package/src/responses/convert-openai-responses-usage.ts +6 -0
- package/src/responses/convert-to-openai-responses-input.ts +23 -11
- package/src/responses/openai-responses-api.ts +230 -192
- package/src/responses/openai-responses-language-model-options.ts +4 -2
- package/src/responses/openai-responses-language-model.ts +11 -0
- package/src/tool/computer.ts +64 -58
- package/src/tool/file-search.ts +15 -12
- package/src/tool/mcp.ts +13 -11
- package/src/tool/shell.ts +28 -21
- package/src/transcription/openai-transcription-api.ts +1 -0
- package/src/transcription/openai-transcription-model.ts +29 -10
package/dist/internal/index.js
CHANGED
|
@@ -2,14 +2,15 @@ import { APICallError, InvalidPromptError, InvalidResponseDataError, TooManyEmbe
|
|
|
2
2
|
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, StreamingToolCallTracker, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertBase64ToUint8Array, convertToBase64, convertToFormData, createBinaryResponseHandler, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createLanguageModelResponseMetadata as getResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, downloadBlob, experimental_toolCaller, generateId, getTopLevelMediaType, isCustomReasoning, isNonNullable, isRecord, lazySchema, mediaTypeToExtension, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, toWebSocketUrl, validateTypes, waitForWebSocketBufferDrain, zodSchema } from "@ai-sdk/provider-utils";
|
|
3
3
|
import { z } from "zod/v4";
|
|
4
4
|
//#region src/openai-error.ts
|
|
5
|
-
const openaiErrorDataSchema = z.object({ error: z.object({
|
|
5
|
+
const openaiErrorDataSchema = () => z.object({ error: z.object({
|
|
6
6
|
message: z.string(),
|
|
7
7
|
type: z.string().nullish(),
|
|
8
8
|
param: z.any().nullish(),
|
|
9
9
|
code: z.union([z.string(), z.number()]).nullish()
|
|
10
10
|
}) });
|
|
11
|
+
const openaiErrorDataSchemaValidator = lazySchema(() => zodSchema(openaiErrorDataSchema()));
|
|
11
12
|
const openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
12
|
-
errorSchema:
|
|
13
|
+
errorSchema: openaiErrorDataSchemaValidator,
|
|
13
14
|
errorToMessage: (data) => data.error.message
|
|
14
15
|
});
|
|
15
16
|
//#endregion
|
|
@@ -567,7 +568,7 @@ const openaiChatChunkSchema = lazySchema(() => zodSchema(z.union([z.object({
|
|
|
567
568
|
rejected_prediction_tokens: z.number().nullish()
|
|
568
569
|
}).nullish()
|
|
569
570
|
}).nullish()
|
|
570
|
-
}), openaiErrorDataSchema])));
|
|
571
|
+
}), openaiErrorDataSchema()])));
|
|
571
572
|
//#endregion
|
|
572
573
|
//#region src/chat/openai-chat-language-model-options.ts
|
|
573
574
|
const openaiLanguageModelChatOptions = lazySchema(() => zodSchema(z.object({
|
|
@@ -1427,7 +1428,7 @@ const openaiCompletionChunkSchema = lazySchema(() => zodSchema(z.union([z.object
|
|
|
1427
1428
|
completion_tokens: z.number(),
|
|
1428
1429
|
total_tokens: z.number()
|
|
1429
1430
|
}).nullish()
|
|
1430
|
-
}), openaiErrorDataSchema])));
|
|
1431
|
+
}), openaiErrorDataSchema()])));
|
|
1431
1432
|
//#endregion
|
|
1432
1433
|
//#region src/completion/openai-completion-language-model-options.ts
|
|
1433
1434
|
const openaiLanguageModelCompletionOptions = lazySchema(() => zodSchema(z.object({
|
|
@@ -1828,7 +1829,7 @@ function hasDefaultResponseFormat(modelId) {
|
|
|
1828
1829
|
function getMaxImagesPerCall(modelId) {
|
|
1829
1830
|
return modelMaxImagesPerCall[modelId] ?? (modelId.startsWith("gpt-image-") ? 10 : 1);
|
|
1830
1831
|
}
|
|
1831
|
-
const baseImageModelOptionsObject = z.object({
|
|
1832
|
+
const baseImageModelOptionsObject = () => z.object({
|
|
1832
1833
|
/**
|
|
1833
1834
|
* Quality of the generated image(s).
|
|
1834
1835
|
*
|
|
@@ -1875,8 +1876,8 @@ const baseImageModelOptionsObject = z.object({
|
|
|
1875
1876
|
*/
|
|
1876
1877
|
user: z.string().optional()
|
|
1877
1878
|
});
|
|
1878
|
-
const openaiImageModelOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject));
|
|
1879
|
-
const openaiImageModelGenerationOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject.extend({
|
|
1879
|
+
const openaiImageModelOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject()));
|
|
1880
|
+
const openaiImageModelGenerationOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject().extend({
|
|
1880
1881
|
/**
|
|
1881
1882
|
* Style of the generated image. `vivid` produces hyper-real and
|
|
1882
1883
|
* dramatic images; `natural` produces more subdued, less hyper-real
|
|
@@ -1889,7 +1890,7 @@ const openaiImageModelGenerationOptions = lazySchema(() => zodSchema(baseImageMo
|
|
|
1889
1890
|
*/
|
|
1890
1891
|
moderation: z.enum(["auto", "low"]).optional()
|
|
1891
1892
|
})));
|
|
1892
|
-
const openaiImageModelEditOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject.extend({
|
|
1893
|
+
const openaiImageModelEditOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject().extend({
|
|
1893
1894
|
/**
|
|
1894
1895
|
* Fidelity of the output image(s) to the input image(s).
|
|
1895
1896
|
*/
|
|
@@ -2090,6 +2091,7 @@ async function fileToBlob(file, abortSignal) {
|
|
|
2090
2091
|
const openaiTranscriptionResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
2091
2092
|
text: z.string(),
|
|
2092
2093
|
language: z.string().nullish(),
|
|
2094
|
+
languages: z.array(z.object({ code: z.string() })).nullish(),
|
|
2093
2095
|
duration: z.number().nullish(),
|
|
2094
2096
|
words: z.array(z.object({
|
|
2095
2097
|
word: z.string(),
|
|
@@ -2248,6 +2250,9 @@ const languageMap = {
|
|
|
2248
2250
|
vietnamese: "vi",
|
|
2249
2251
|
welsh: "cy"
|
|
2250
2252
|
};
|
|
2253
|
+
function isLanguageCode(language) {
|
|
2254
|
+
return language != null && /^[a-z]{2}$/.test(language);
|
|
2255
|
+
}
|
|
2251
2256
|
var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
2252
2257
|
static [WORKFLOW_SERIALIZE](model) {
|
|
2253
2258
|
return serializeModelOptions({
|
|
@@ -2323,7 +2328,7 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2323
2328
|
abortSignal: options.abortSignal,
|
|
2324
2329
|
fetch: this.config.fetch
|
|
2325
2330
|
});
|
|
2326
|
-
const language = response.language != null && response.language
|
|
2331
|
+
const language = (isLanguageCode(response.language) ? response.language : response.language != null && Object.prototype.hasOwnProperty.call(languageMap, response.language) ? languageMap[response.language] : void 0) ?? (response.languages?.length === 1 && isLanguageCode(response.languages[0].code) ? response.languages[0].code : void 0);
|
|
2327
2332
|
const diarizedSegments = response.segments?.flatMap((segment) => "speaker" in segment ? [{
|
|
2328
2333
|
text: segment.text,
|
|
2329
2334
|
startSecond: segment.start,
|
|
@@ -2351,7 +2356,10 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
|
|
|
2351
2356
|
headers: responseHeaders,
|
|
2352
2357
|
body: rawResponse
|
|
2353
2358
|
},
|
|
2354
|
-
...diarizedSegments != null && diarizedSegments.length > 0 && { providerMetadata: { openai: {
|
|
2359
|
+
...(diarizedSegments != null && diarizedSegments.length > 0 || response.languages != null) && { providerMetadata: { openai: {
|
|
2360
|
+
...diarizedSegments != null && diarizedSegments.length > 0 && { segments: diarizedSegments },
|
|
2361
|
+
...response.languages != null && { languages: response.languages }
|
|
2362
|
+
} } }
|
|
2355
2363
|
};
|
|
2356
2364
|
}
|
|
2357
2365
|
async doStream(options) {
|
|
@@ -2763,11 +2771,13 @@ const openaiLanguageModelResponsesOptionsSchema = lazySchema(() => zodSchema(z.o
|
|
|
2763
2771
|
/**
|
|
2764
2772
|
* Prompt cache behavior for GPT-5.6 and later models.
|
|
2765
2773
|
* `mode` controls whether OpenAI also places an implicit breakpoint.
|
|
2766
|
-
* `ttl` sets the minimum cache lifetime
|
|
2774
|
+
* `ttl` sets the minimum cache lifetime: `'30m'` (default) or `'12h'`.
|
|
2775
|
+
* `prewarm` writes the prompt to the cache without generating output.
|
|
2767
2776
|
*/
|
|
2768
2777
|
promptCacheOptions: z.object({
|
|
2769
2778
|
mode: z.enum(["implicit", "explicit"]).optional(),
|
|
2770
|
-
ttl: z.
|
|
2779
|
+
ttl: z.enum(["30m", "12h"]).optional(),
|
|
2780
|
+
prewarm: z.boolean().optional()
|
|
2771
2781
|
}).optional(),
|
|
2772
2782
|
/**
|
|
2773
2783
|
* The retention policy for the prompt cache.
|
|
@@ -3025,12 +3035,12 @@ const applyPatchToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
3025
3035
|
const applyPatch = applyPatchToolFactory;
|
|
3026
3036
|
//#endregion
|
|
3027
3037
|
//#region src/tool/computer.ts
|
|
3028
|
-
const safetyCheckSchema = z.object({
|
|
3038
|
+
const safetyCheckSchema = () => z.object({
|
|
3029
3039
|
id: z.string(),
|
|
3030
3040
|
code: z.string().optional(),
|
|
3031
3041
|
message: z.string().optional()
|
|
3032
3042
|
});
|
|
3033
|
-
const computerActionSchema = z.discriminatedUnion("type", [
|
|
3043
|
+
const computerActionSchema = () => z.discriminatedUnion("type", [
|
|
3034
3044
|
z.object({
|
|
3035
3045
|
type: z.literal("click"),
|
|
3036
3046
|
button: z.enum([
|
|
@@ -3084,8 +3094,8 @@ const computerActionSchema = z.discriminatedUnion("type", [
|
|
|
3084
3094
|
z.object({ type: z.literal("wait") })
|
|
3085
3095
|
]);
|
|
3086
3096
|
const computerInputSchema = lazySchema(() => zodSchema(z.object({
|
|
3087
|
-
actions: z.array(computerActionSchema),
|
|
3088
|
-
pendingSafetyChecks: z.array(safetyCheckSchema),
|
|
3097
|
+
actions: z.array(computerActionSchema()),
|
|
3098
|
+
pendingSafetyChecks: z.array(safetyCheckSchema()),
|
|
3089
3099
|
status: z.enum([
|
|
3090
3100
|
"in_progress",
|
|
3091
3101
|
"completed",
|
|
@@ -3114,7 +3124,7 @@ const computerOutputSchema = lazySchema(() => zodSchema(z.object({
|
|
|
3114
3124
|
"original"
|
|
3115
3125
|
]).optional()
|
|
3116
3126
|
})]),
|
|
3117
|
-
acknowledgedSafetyChecks: z.array(safetyCheckSchema).optional()
|
|
3127
|
+
acknowledgedSafetyChecks: z.array(safetyCheckSchema()).optional()
|
|
3118
3128
|
})));
|
|
3119
3129
|
createProviderDefinedToolFactoryWithOutputSchema({
|
|
3120
3130
|
id: "openai.computer",
|
|
@@ -3144,15 +3154,18 @@ const shellInputSchema = lazySchema(() => zodSchema(z.object({ action: z.object(
|
|
|
3144
3154
|
timeoutMs: z.number().optional(),
|
|
3145
3155
|
maxOutputLength: z.number().optional()
|
|
3146
3156
|
}) })));
|
|
3147
|
-
const shellOutputSchema = lazySchema(() => zodSchema(z.object({
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3157
|
+
const shellOutputSchema = lazySchema(() => zodSchema(z.object({
|
|
3158
|
+
maxOutputLength: z.number().optional(),
|
|
3159
|
+
output: z.array(z.object({
|
|
3160
|
+
stdout: z.string(),
|
|
3161
|
+
stderr: z.string(),
|
|
3162
|
+
outcome: z.discriminatedUnion("type", [z.object({ type: z.literal("timeout") }), z.object({
|
|
3163
|
+
type: z.literal("exit"),
|
|
3164
|
+
exitCode: z.number()
|
|
3165
|
+
})])
|
|
3166
|
+
}))
|
|
3167
|
+
})));
|
|
3168
|
+
const shellSkillsSchema = () => z.array(z.discriminatedUnion("type", [z.object({
|
|
3156
3169
|
type: z.literal("skillReference"),
|
|
3157
3170
|
providerReference: z.record(z.string(), z.string()),
|
|
3158
3171
|
version: z.string().optional()
|
|
@@ -3185,7 +3198,7 @@ const shellArgsSchema = lazySchema(() => zodSchema(z.object({ environment: z.uni
|
|
|
3185
3198
|
value: z.string()
|
|
3186
3199
|
})).optional()
|
|
3187
3200
|
})]).optional(),
|
|
3188
|
-
skills: shellSkillsSchema
|
|
3201
|
+
skills: shellSkillsSchema()
|
|
3189
3202
|
}),
|
|
3190
3203
|
z.object({
|
|
3191
3204
|
type: z.literal("containerReference"),
|
|
@@ -3996,6 +4009,7 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
|
|
|
3996
4009
|
input.push({
|
|
3997
4010
|
type: "shell_call_output",
|
|
3998
4011
|
call_id: part.toolCallId,
|
|
4012
|
+
...parsedOutput.maxOutputLength != null && { max_output_length: parsedOutput.maxOutputLength },
|
|
3999
4013
|
output: parsedOutput.output.map((item) => ({
|
|
4000
4014
|
stdout: item.stdout,
|
|
4001
4015
|
stderr: item.stderr,
|
|
@@ -4202,6 +4216,7 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
|
|
|
4202
4216
|
input.push({
|
|
4203
4217
|
type: "shell_call_output",
|
|
4204
4218
|
call_id: part.toolCallId,
|
|
4219
|
+
...parsedOutput.maxOutputLength != null && { max_output_length: parsedOutput.maxOutputLength },
|
|
4205
4220
|
output: parsedOutput.output.map((item) => ({
|
|
4206
4221
|
stdout: item.stdout,
|
|
4207
4222
|
stderr: item.stderr,
|
|
@@ -4385,10 +4400,10 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
|
|
|
4385
4400
|
warnings
|
|
4386
4401
|
};
|
|
4387
4402
|
}
|
|
4388
|
-
const openaiResponsesReasoningProviderOptionsSchema = z.object({
|
|
4403
|
+
const openaiResponsesReasoningProviderOptionsSchema = lazySchema(() => zodSchema(z.object({
|
|
4389
4404
|
itemId: z.string().nullish(),
|
|
4390
4405
|
reasoningEncryptedContent: z.string().nullish()
|
|
4391
|
-
});
|
|
4406
|
+
})));
|
|
4392
4407
|
//#endregion
|
|
4393
4408
|
//#region src/responses/map-openai-responses-annotation.ts
|
|
4394
4409
|
function mapOpenAIResponsesAnnotationSource(annotation, providerOptionsName, id) {
|
|
@@ -4436,36 +4451,41 @@ function mapOpenAIResponseFinishReason({ finishReason, hasFunctionCall }) {
|
|
|
4436
4451
|
}
|
|
4437
4452
|
//#endregion
|
|
4438
4453
|
//#region src/responses/openai-responses-api.ts
|
|
4439
|
-
|
|
4454
|
+
let cachedJsonValueSchema$1;
|
|
4455
|
+
const jsonValueSchema$1 = () => cachedJsonValueSchema$1 ??= z.lazy(() => z.union([
|
|
4440
4456
|
z.string(),
|
|
4441
4457
|
z.number(),
|
|
4442
4458
|
z.boolean(),
|
|
4443
4459
|
z.null(),
|
|
4444
|
-
z.array(jsonValueSchema$1),
|
|
4445
|
-
z.record(z.string(), jsonValueSchema$1.optional())
|
|
4460
|
+
z.array(jsonValueSchema$1()),
|
|
4461
|
+
z.record(z.string(), jsonValueSchema$1().optional())
|
|
4446
4462
|
]));
|
|
4447
|
-
const jsonObjectSchema = z.record(z.string(), jsonValueSchema$1.optional());
|
|
4448
|
-
const openaiResponsesUsageSchema = z.intersection(jsonObjectSchema, z.object({
|
|
4463
|
+
const jsonObjectSchema = () => z.record(z.string(), jsonValueSchema$1().optional());
|
|
4464
|
+
const openaiResponsesUsageSchema = () => z.intersection(jsonObjectSchema(), z.object({
|
|
4449
4465
|
input_tokens: z.number(),
|
|
4450
|
-
input_tokens_details: z.intersection(jsonObjectSchema, z.object({
|
|
4466
|
+
input_tokens_details: z.intersection(jsonObjectSchema(), z.object({
|
|
4451
4467
|
cached_tokens: z.number().nullish(),
|
|
4452
4468
|
cache_write_tokens: z.number().nullish(),
|
|
4469
|
+
cache_write_tokens_details: z.intersection(jsonObjectSchema(), z.object({
|
|
4470
|
+
ttl_30m_tokens: z.number().nullish(),
|
|
4471
|
+
ttl_12h_tokens: z.number().nullish()
|
|
4472
|
+
})).nullish(),
|
|
4453
4473
|
orchestration_input_tokens: z.number().nullish(),
|
|
4454
4474
|
orchestration_input_cached_tokens: z.number().nullish()
|
|
4455
4475
|
})).nullish(),
|
|
4456
4476
|
output_tokens: z.number(),
|
|
4457
|
-
output_tokens_details: z.intersection(jsonObjectSchema, z.object({
|
|
4477
|
+
output_tokens_details: z.intersection(jsonObjectSchema(), z.object({
|
|
4458
4478
|
reasoning_tokens: z.number().nullish(),
|
|
4459
4479
|
orchestration_output_tokens: z.number().nullish()
|
|
4460
4480
|
})).nullish(),
|
|
4461
4481
|
total_tokens: z.number().optional()
|
|
4462
4482
|
}));
|
|
4463
|
-
const openaiResponsesComputerSafetyCheckSchema = z.object({
|
|
4483
|
+
const openaiResponsesComputerSafetyCheckSchema = () => z.object({
|
|
4464
4484
|
id: z.string(),
|
|
4465
4485
|
code: z.string().nullish(),
|
|
4466
4486
|
message: z.string().nullish()
|
|
4467
4487
|
});
|
|
4468
|
-
const openaiResponsesComputerActionSchema = z.discriminatedUnion("type", [
|
|
4488
|
+
const openaiResponsesComputerActionSchema = () => z.discriminatedUnion("type", [
|
|
4469
4489
|
z.object({
|
|
4470
4490
|
type: z.literal("click"),
|
|
4471
4491
|
button: z.enum([
|
|
@@ -4518,7 +4538,7 @@ const openaiResponsesComputerActionSchema = z.discriminatedUnion("type", [
|
|
|
4518
4538
|
}),
|
|
4519
4539
|
z.object({ type: z.literal("wait") })
|
|
4520
4540
|
]);
|
|
4521
|
-
const openaiResponsesComputerCallSchema = z.object({
|
|
4541
|
+
const openaiResponsesComputerCallSchema = () => z.object({
|
|
4522
4542
|
type: z.literal("computer_call"),
|
|
4523
4543
|
id: z.string(),
|
|
4524
4544
|
call_id: z.string().nullish(),
|
|
@@ -4527,29 +4547,29 @@ const openaiResponsesComputerCallSchema = z.object({
|
|
|
4527
4547
|
"completed",
|
|
4528
4548
|
"incomplete"
|
|
4529
4549
|
]),
|
|
4530
|
-
action: openaiResponsesComputerActionSchema.nullish(),
|
|
4531
|
-
actions: z.array(openaiResponsesComputerActionSchema).nullish(),
|
|
4532
|
-
pending_safety_checks: z.array(openaiResponsesComputerSafetyCheckSchema).nullish()
|
|
4550
|
+
action: openaiResponsesComputerActionSchema().nullish(),
|
|
4551
|
+
actions: z.array(openaiResponsesComputerActionSchema()).nullish(),
|
|
4552
|
+
pending_safety_checks: z.array(openaiResponsesComputerSafetyCheckSchema()).nullish()
|
|
4533
4553
|
});
|
|
4534
|
-
const openaiResponsesToolCallerSchema = z.discriminatedUnion("type", [z.object({ type: z.literal("direct") }), z.object({
|
|
4554
|
+
const openaiResponsesToolCallerSchema = () => z.discriminatedUnion("type", [z.object({ type: z.literal("direct") }), z.object({
|
|
4535
4555
|
type: z.literal("program"),
|
|
4536
4556
|
caller_id: z.string()
|
|
4537
4557
|
})]);
|
|
4538
|
-
const openaiResponsesProgramSchema = z.object({
|
|
4558
|
+
const openaiResponsesProgramSchema = () => z.object({
|
|
4539
4559
|
type: z.literal("program"),
|
|
4540
4560
|
id: z.string(),
|
|
4541
4561
|
call_id: z.string(),
|
|
4542
4562
|
code: z.string(),
|
|
4543
4563
|
fingerprint: z.string()
|
|
4544
4564
|
});
|
|
4545
|
-
const openaiResponsesProgramOutputSchema = z.object({
|
|
4565
|
+
const openaiResponsesProgramOutputSchema = () => z.object({
|
|
4546
4566
|
type: z.literal("program_output"),
|
|
4547
4567
|
id: z.string(),
|
|
4548
4568
|
call_id: z.string(),
|
|
4549
4569
|
result: z.string(),
|
|
4550
4570
|
status: z.enum(["completed", "incomplete"])
|
|
4551
4571
|
});
|
|
4552
|
-
const openaiResponsesLocalShellCallSchema = z.object({
|
|
4572
|
+
const openaiResponsesLocalShellCallSchema = () => z.object({
|
|
4553
4573
|
type: z.literal("local_shell_call"),
|
|
4554
4574
|
id: z.string(),
|
|
4555
4575
|
call_id: z.string(),
|
|
@@ -4562,7 +4582,7 @@ const openaiResponsesLocalShellCallSchema = z.object({
|
|
|
4562
4582
|
env: z.record(z.string(), z.string()).optional()
|
|
4563
4583
|
})
|
|
4564
4584
|
});
|
|
4565
|
-
const openaiResponsesNestedErrorChunkSchema = z.object({
|
|
4585
|
+
const openaiResponsesNestedErrorChunkSchema = () => z.object({
|
|
4566
4586
|
type: z.literal("error"),
|
|
4567
4587
|
sequence_number: z.number(),
|
|
4568
4588
|
error: z.object({
|
|
@@ -4572,7 +4592,7 @@ const openaiResponsesNestedErrorChunkSchema = z.object({
|
|
|
4572
4592
|
param: z.string().nullish()
|
|
4573
4593
|
})
|
|
4574
4594
|
});
|
|
4575
|
-
const openaiResponsesErrorChunkSchema = z.object({
|
|
4595
|
+
const openaiResponsesErrorChunkSchema = () => z.object({
|
|
4576
4596
|
type: z.literal("error"),
|
|
4577
4597
|
sequence_number: z.number(),
|
|
4578
4598
|
code: z.string().nullish(),
|
|
@@ -4660,7 +4680,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
4660
4680
|
type: z.enum(["response.completed", "response.incomplete"]),
|
|
4661
4681
|
response: z.object({
|
|
4662
4682
|
incomplete_details: z.object({ reason: z.string() }).nullish(),
|
|
4663
|
-
usage: openaiResponsesUsageSchema.nullish(),
|
|
4683
|
+
usage: openaiResponsesUsageSchema().nullish(),
|
|
4664
4684
|
reasoning: z.object({ context: z.string().nullish() }).nullish(),
|
|
4665
4685
|
service_tier: z.string().nullish()
|
|
4666
4686
|
})
|
|
@@ -4674,7 +4694,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
4674
4694
|
message: z.string()
|
|
4675
4695
|
}).nullish(),
|
|
4676
4696
|
incomplete_details: z.object({ reason: z.string() }).nullish(),
|
|
4677
|
-
usage: openaiResponsesUsageSchema.nullish(),
|
|
4697
|
+
usage: openaiResponsesUsageSchema().nullish(),
|
|
4678
4698
|
reasoning: z.object({ context: z.string().nullish() }).nullish(),
|
|
4679
4699
|
service_tier: z.string().nullish()
|
|
4680
4700
|
})
|
|
@@ -4719,21 +4739,21 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
4719
4739
|
arguments: z.string(),
|
|
4720
4740
|
async: z.boolean().nullish(),
|
|
4721
4741
|
namespace: z.string().nullish(),
|
|
4722
|
-
caller: openaiResponsesToolCallerSchema.nullish()
|
|
4742
|
+
caller: openaiResponsesToolCallerSchema().nullish()
|
|
4723
4743
|
}),
|
|
4724
|
-
openaiResponsesProgramSchema,
|
|
4725
|
-
openaiResponsesProgramOutputSchema,
|
|
4744
|
+
openaiResponsesProgramSchema(),
|
|
4745
|
+
openaiResponsesProgramOutputSchema(),
|
|
4726
4746
|
z.object({
|
|
4727
4747
|
type: z.literal("web_search_call"),
|
|
4728
4748
|
id: z.string(),
|
|
4729
4749
|
status: z.string()
|
|
4730
4750
|
}),
|
|
4731
|
-
openaiResponsesComputerCallSchema,
|
|
4751
|
+
openaiResponsesComputerCallSchema(),
|
|
4732
4752
|
z.object({
|
|
4733
4753
|
type: z.literal("file_search_call"),
|
|
4734
4754
|
id: z.string()
|
|
4735
4755
|
}),
|
|
4736
|
-
openaiResponsesLocalShellCallSchema,
|
|
4756
|
+
openaiResponsesLocalShellCallSchema(),
|
|
4737
4757
|
z.object({
|
|
4738
4758
|
type: z.literal("image_generation_call"),
|
|
4739
4759
|
id: z.string()
|
|
@@ -4805,7 +4825,11 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
4805
4825
|
"completed",
|
|
4806
4826
|
"incomplete"
|
|
4807
4827
|
]),
|
|
4808
|
-
action: z.object({
|
|
4828
|
+
action: z.object({
|
|
4829
|
+
commands: z.array(z.string()),
|
|
4830
|
+
timeout_ms: z.number().nullish(),
|
|
4831
|
+
max_output_length: z.number().nullish()
|
|
4832
|
+
})
|
|
4809
4833
|
}),
|
|
4810
4834
|
z.object({
|
|
4811
4835
|
type: z.literal("compaction"),
|
|
@@ -4821,6 +4845,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
4821
4845
|
"completed",
|
|
4822
4846
|
"incomplete"
|
|
4823
4847
|
]),
|
|
4848
|
+
max_output_length: z.number().nullish(),
|
|
4824
4849
|
output: z.array(z.object({
|
|
4825
4850
|
stdout: z.string(),
|
|
4826
4851
|
stderr: z.string(),
|
|
@@ -4852,7 +4877,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
4852
4877
|
"completed",
|
|
4853
4878
|
"incomplete"
|
|
4854
4879
|
]),
|
|
4855
|
-
tools: z.array(z.record(z.string(), jsonValueSchema$1.optional()))
|
|
4880
|
+
tools: z.array(z.record(z.string(), jsonValueSchema$1().optional()))
|
|
4856
4881
|
})
|
|
4857
4882
|
])
|
|
4858
4883
|
}),
|
|
@@ -4883,10 +4908,10 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
4883
4908
|
"incomplete"
|
|
4884
4909
|
]),
|
|
4885
4910
|
namespace: z.string().nullish(),
|
|
4886
|
-
caller: openaiResponsesToolCallerSchema.nullish()
|
|
4911
|
+
caller: openaiResponsesToolCallerSchema().nullish()
|
|
4887
4912
|
}),
|
|
4888
|
-
openaiResponsesProgramSchema,
|
|
4889
|
-
openaiResponsesProgramOutputSchema,
|
|
4913
|
+
openaiResponsesProgramSchema(),
|
|
4914
|
+
openaiResponsesProgramOutputSchema(),
|
|
4890
4915
|
z.object({
|
|
4891
4916
|
type: z.literal("custom_tool_call"),
|
|
4892
4917
|
id: z.string(),
|
|
@@ -4958,8 +4983,8 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
4958
4983
|
text: z.string()
|
|
4959
4984
|
})).nullish()
|
|
4960
4985
|
}),
|
|
4961
|
-
openaiResponsesLocalShellCallSchema,
|
|
4962
|
-
openaiResponsesComputerCallSchema,
|
|
4986
|
+
openaiResponsesLocalShellCallSchema(),
|
|
4987
|
+
openaiResponsesComputerCallSchema(),
|
|
4963
4988
|
z.object({
|
|
4964
4989
|
type: z.literal("mcp_call"),
|
|
4965
4990
|
id: z.string(),
|
|
@@ -5030,7 +5055,11 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
5030
5055
|
"completed",
|
|
5031
5056
|
"incomplete"
|
|
5032
5057
|
]),
|
|
5033
|
-
action: z.object({
|
|
5058
|
+
action: z.object({
|
|
5059
|
+
commands: z.array(z.string()),
|
|
5060
|
+
timeout_ms: z.number().nullish(),
|
|
5061
|
+
max_output_length: z.number().nullish()
|
|
5062
|
+
})
|
|
5034
5063
|
}),
|
|
5035
5064
|
z.object({
|
|
5036
5065
|
type: z.literal("compaction"),
|
|
@@ -5046,6 +5075,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
5046
5075
|
"completed",
|
|
5047
5076
|
"incomplete"
|
|
5048
5077
|
]),
|
|
5078
|
+
max_output_length: z.number().nullish(),
|
|
5049
5079
|
output: z.array(z.object({
|
|
5050
5080
|
stdout: z.string(),
|
|
5051
5081
|
stderr: z.string(),
|
|
@@ -5077,7 +5107,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
5077
5107
|
"completed",
|
|
5078
5108
|
"incomplete"
|
|
5079
5109
|
]),
|
|
5080
|
-
tools: z.array(z.record(z.string(), jsonValueSchema$1.optional()))
|
|
5110
|
+
tools: z.array(z.record(z.string(), jsonValueSchema$1().optional()))
|
|
5081
5111
|
})
|
|
5082
5112
|
])
|
|
5083
5113
|
}),
|
|
@@ -5180,8 +5210,8 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
|
|
|
5180
5210
|
output_index: z.number(),
|
|
5181
5211
|
diff: z.string()
|
|
5182
5212
|
}),
|
|
5183
|
-
openaiResponsesNestedErrorChunkSchema,
|
|
5184
|
-
openaiResponsesErrorChunkSchema,
|
|
5213
|
+
openaiResponsesNestedErrorChunkSchema(),
|
|
5214
|
+
openaiResponsesErrorChunkSchema(),
|
|
5185
5215
|
z.object({ type: z.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), { message: "Known response chunk failed schema validation" }).transform((value) => ({
|
|
5186
5216
|
type: "unknown_chunk",
|
|
5187
5217
|
message: value.type
|
|
@@ -5306,7 +5336,7 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
5306
5336
|
id: z.string(),
|
|
5307
5337
|
result: z.string()
|
|
5308
5338
|
}),
|
|
5309
|
-
openaiResponsesLocalShellCallSchema,
|
|
5339
|
+
openaiResponsesLocalShellCallSchema(),
|
|
5310
5340
|
z.object({
|
|
5311
5341
|
type: z.literal("function_call"),
|
|
5312
5342
|
call_id: z.string(),
|
|
@@ -5315,10 +5345,10 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
5315
5345
|
id: z.string(),
|
|
5316
5346
|
async: z.boolean().nullish(),
|
|
5317
5347
|
namespace: z.string().nullish(),
|
|
5318
|
-
caller: openaiResponsesToolCallerSchema.nullish()
|
|
5348
|
+
caller: openaiResponsesToolCallerSchema().nullish()
|
|
5319
5349
|
}),
|
|
5320
|
-
openaiResponsesProgramSchema,
|
|
5321
|
-
openaiResponsesProgramOutputSchema,
|
|
5350
|
+
openaiResponsesProgramSchema(),
|
|
5351
|
+
openaiResponsesProgramOutputSchema(),
|
|
5322
5352
|
z.object({
|
|
5323
5353
|
type: z.literal("custom_tool_call"),
|
|
5324
5354
|
call_id: z.string(),
|
|
@@ -5327,7 +5357,7 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
5327
5357
|
id: z.string(),
|
|
5328
5358
|
async: z.boolean().nullish()
|
|
5329
5359
|
}),
|
|
5330
|
-
openaiResponsesComputerCallSchema,
|
|
5360
|
+
openaiResponsesComputerCallSchema(),
|
|
5331
5361
|
z.object({
|
|
5332
5362
|
type: z.literal("reasoning"),
|
|
5333
5363
|
id: z.string(),
|
|
@@ -5407,7 +5437,11 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
5407
5437
|
"completed",
|
|
5408
5438
|
"incomplete"
|
|
5409
5439
|
]),
|
|
5410
|
-
action: z.object({
|
|
5440
|
+
action: z.object({
|
|
5441
|
+
commands: z.array(z.string()),
|
|
5442
|
+
timeout_ms: z.number().nullish(),
|
|
5443
|
+
max_output_length: z.number().nullish()
|
|
5444
|
+
})
|
|
5411
5445
|
}),
|
|
5412
5446
|
z.object({
|
|
5413
5447
|
type: z.literal("compaction"),
|
|
@@ -5423,6 +5457,7 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
5423
5457
|
"completed",
|
|
5424
5458
|
"incomplete"
|
|
5425
5459
|
]),
|
|
5460
|
+
max_output_length: z.number().nullish(),
|
|
5426
5461
|
output: z.array(z.object({
|
|
5427
5462
|
stdout: z.string(),
|
|
5428
5463
|
stderr: z.string(),
|
|
@@ -5454,13 +5489,13 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
5454
5489
|
"completed",
|
|
5455
5490
|
"incomplete"
|
|
5456
5491
|
]),
|
|
5457
|
-
tools: z.array(z.record(z.string(), jsonValueSchema$1.optional()))
|
|
5492
|
+
tools: z.array(z.record(z.string(), jsonValueSchema$1().optional()))
|
|
5458
5493
|
})
|
|
5459
5494
|
])).optional(),
|
|
5460
5495
|
service_tier: z.string().nullish(),
|
|
5461
5496
|
reasoning: z.object({ context: z.string().nullish() }).nullish(),
|
|
5462
5497
|
incomplete_details: z.object({ reason: z.string() }).nullish(),
|
|
5463
|
-
usage: openaiResponsesUsageSchema.nullish()
|
|
5498
|
+
usage: openaiResponsesUsageSchema().nullish()
|
|
5464
5499
|
})));
|
|
5465
5500
|
//#endregion
|
|
5466
5501
|
//#region src/tool/code-interpreter.ts
|
|
@@ -5486,7 +5521,7 @@ const codeInterpreter = (args = {}) => {
|
|
|
5486
5521
|
};
|
|
5487
5522
|
//#endregion
|
|
5488
5523
|
//#region src/tool/file-search.ts
|
|
5489
|
-
const comparisonFilterSchema = z.object({
|
|
5524
|
+
const comparisonFilterSchema = () => z.object({
|
|
5490
5525
|
key: z.string(),
|
|
5491
5526
|
type: z.enum([
|
|
5492
5527
|
"eq",
|
|
@@ -5505,9 +5540,10 @@ const comparisonFilterSchema = z.object({
|
|
|
5505
5540
|
z.array(z.string())
|
|
5506
5541
|
])
|
|
5507
5542
|
});
|
|
5508
|
-
|
|
5543
|
+
let cachedCompoundFilterSchema;
|
|
5544
|
+
const compoundFilterSchema = () => cachedCompoundFilterSchema ??= z.object({
|
|
5509
5545
|
type: z.enum(["and", "or"]),
|
|
5510
|
-
filters: z.array(z.union([comparisonFilterSchema, z.lazy(() => compoundFilterSchema)]))
|
|
5546
|
+
filters: z.array(z.union([comparisonFilterSchema(), z.lazy(() => compoundFilterSchema())]))
|
|
5511
5547
|
});
|
|
5512
5548
|
const fileSearchArgsSchema = lazySchema(() => zodSchema(z.object({
|
|
5513
5549
|
vectorStoreIds: z.array(z.string()),
|
|
@@ -5516,7 +5552,7 @@ const fileSearchArgsSchema = lazySchema(() => zodSchema(z.object({
|
|
|
5516
5552
|
ranker: z.string().optional(),
|
|
5517
5553
|
scoreThreshold: z.number().optional()
|
|
5518
5554
|
}).optional(),
|
|
5519
|
-
filters: z.union([comparisonFilterSchema, compoundFilterSchema]).optional()
|
|
5555
|
+
filters: z.union([comparisonFilterSchema(), compoundFilterSchema()]).optional()
|
|
5520
5556
|
})));
|
|
5521
5557
|
const fileSearchOutputSchema = lazySchema(() => zodSchema(z.object({
|
|
5522
5558
|
queries: z.array(z.string()),
|
|
@@ -5603,13 +5639,14 @@ createProviderDefinedToolFactory({
|
|
|
5603
5639
|
});
|
|
5604
5640
|
//#endregion
|
|
5605
5641
|
//#region src/tool/mcp.ts
|
|
5606
|
-
|
|
5642
|
+
let cachedJsonValueSchema;
|
|
5643
|
+
const jsonValueSchema = () => cachedJsonValueSchema ??= z.lazy(() => z.union([
|
|
5607
5644
|
z.string(),
|
|
5608
5645
|
z.number(),
|
|
5609
5646
|
z.boolean(),
|
|
5610
5647
|
z.null(),
|
|
5611
|
-
z.array(jsonValueSchema),
|
|
5612
|
-
z.record(z.string(), jsonValueSchema)
|
|
5648
|
+
z.array(jsonValueSchema()),
|
|
5649
|
+
z.record(z.string(), jsonValueSchema())
|
|
5613
5650
|
]));
|
|
5614
5651
|
const mcpArgsSchema = lazySchema(() => zodSchema(z.object({
|
|
5615
5652
|
serverLabel: z.string(),
|
|
@@ -5631,7 +5668,7 @@ const mcpOutputSchema = lazySchema(() => zodSchema(z.object({
|
|
|
5631
5668
|
name: z.string(),
|
|
5632
5669
|
arguments: z.string(),
|
|
5633
5670
|
output: z.string().nullish(),
|
|
5634
|
-
error: z.union([z.string(), jsonValueSchema]).optional()
|
|
5671
|
+
error: z.union([z.string(), jsonValueSchema()]).optional()
|
|
5635
5672
|
})));
|
|
5636
5673
|
createProviderExecutedToolFactory({
|
|
5637
5674
|
id: "openai.mcp",
|
|
@@ -6648,7 +6685,11 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6648
6685
|
type: "tool-call",
|
|
6649
6686
|
toolCallId: part.call_id,
|
|
6650
6687
|
toolName: toolNameMapping.toCustomToolName("shell"),
|
|
6651
|
-
input: JSON.stringify({ action: {
|
|
6688
|
+
input: JSON.stringify({ action: {
|
|
6689
|
+
commands: part.action.commands,
|
|
6690
|
+
timeoutMs: part.action.timeout_ms ?? void 0,
|
|
6691
|
+
maxOutputLength: part.action.max_output_length ?? void 0
|
|
6692
|
+
} }),
|
|
6652
6693
|
...isShellProviderExecuted && { providerExecuted: true },
|
|
6653
6694
|
providerMetadata: { [providerOptionsName]: { itemId: part.id } }
|
|
6654
6695
|
});
|
|
@@ -6658,14 +6699,17 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
6658
6699
|
type: "tool-result",
|
|
6659
6700
|
toolCallId: part.call_id,
|
|
6660
6701
|
toolName: toolNameMapping.toCustomToolName("shell"),
|
|
6661
|
-
result: {
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6702
|
+
result: {
|
|
6703
|
+
...part.max_output_length != null && { maxOutputLength: part.max_output_length },
|
|
6704
|
+
output: part.output.map((item) => ({
|
|
6705
|
+
stdout: item.stdout,
|
|
6706
|
+
stderr: item.stderr,
|
|
6707
|
+
outcome: item.outcome.type === "exit" ? {
|
|
6708
|
+
type: "exit",
|
|
6709
|
+
exitCode: item.outcome.exit_code
|
|
6710
|
+
} : { type: "timeout" }
|
|
6711
|
+
}))
|
|
6712
|
+
}
|
|
6669
6713
|
});
|
|
6670
6714
|
break;
|
|
6671
6715
|
case "message":
|
|
@@ -7633,7 +7677,11 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7633
7677
|
type: "tool-call",
|
|
7634
7678
|
toolCallId: value.item.call_id,
|
|
7635
7679
|
toolName: toolNameMapping.toCustomToolName("shell"),
|
|
7636
|
-
input: JSON.stringify({ action: {
|
|
7680
|
+
input: JSON.stringify({ action: {
|
|
7681
|
+
commands: value.item.action.commands,
|
|
7682
|
+
timeoutMs: value.item.action.timeout_ms ?? void 0,
|
|
7683
|
+
maxOutputLength: value.item.action.max_output_length ?? void 0
|
|
7684
|
+
} }),
|
|
7637
7685
|
...isShellProviderExecuted && { providerExecuted: true },
|
|
7638
7686
|
providerMetadata: { [providerOptionsName]: { itemId: value.item.id } }
|
|
7639
7687
|
});
|
|
@@ -7641,14 +7689,17 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
|
|
|
7641
7689
|
type: "tool-result",
|
|
7642
7690
|
toolCallId: value.item.call_id,
|
|
7643
7691
|
toolName: toolNameMapping.toCustomToolName("shell"),
|
|
7644
|
-
result: {
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7692
|
+
result: {
|
|
7693
|
+
...value.item.max_output_length != null && { maxOutputLength: value.item.max_output_length },
|
|
7694
|
+
output: value.item.output.map((item) => ({
|
|
7695
|
+
stdout: item.stdout,
|
|
7696
|
+
stderr: item.stderr,
|
|
7697
|
+
outcome: item.outcome.type === "exit" ? {
|
|
7698
|
+
type: "exit",
|
|
7699
|
+
exitCode: item.outcome.exit_code
|
|
7700
|
+
} : { type: "timeout" }
|
|
7701
|
+
}))
|
|
7702
|
+
}
|
|
7652
7703
|
});
|
|
7653
7704
|
else if (value.item.type === "reasoning") {
|
|
7654
7705
|
const itemId = resolveOutputItemId({
|