@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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, StreamingToolCallTracker, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createBinaryStreamResponseHandler, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createLanguageModelResponseMetadata as getResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, deleteFromApi, detectMediaType, downloadBlob, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isFullMediaType, isNonNullable, isRecord, lazySchema, loadApiKey, loadOptionalSetting, mediaTypeToExtension, normalizeBatchRequestCounts, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, postMultipartStreamToApi, postToApi, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, toWebSocketUrl, validateBaseURL, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
1
+ import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, StreamingToolCallTracker, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createBinaryStreamResponseHandler, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createLanguageModelResponseMetadata as getResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, deleteFromApi, detectMediaType, downloadBlob, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isFullMediaType, isNonNullable, isRecord, lazySchema, loadApiKey, loadOptionalSetting, mediaTypeToExtension, normalizeBatchRequestCounts, parseJSON, parseProviderOptions, postFormDataToApi, postJsonToApi, postMultipartStreamToApi, postToApi, resolveFullMediaType, resolveProviderReference, safeParseJSON, safeValidateTypes, serializeModelOptions, toWebSocketUrl, validateBaseURL, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
2
2
  import { APICallError, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, TooManyEmbeddingValuesForCallError, UnsupportedFunctionalityError, isJSONObject } from "@ai-sdk/provider";
3
3
  import { z } from "zod/v4";
4
4
  //#region src/openai-config.ts
@@ -16,14 +16,15 @@ function prepareOpenAIConfigForWorkflowDeserialize(config) {
16
16
  }
17
17
  //#endregion
18
18
  //#region src/openai-error.ts
19
- const openaiErrorDataSchema = z.object({ error: z.object({
19
+ const openaiErrorDataSchema = () => z.object({ error: z.object({
20
20
  message: z.string(),
21
21
  type: z.string().nullish(),
22
22
  param: z.any().nullish(),
23
23
  code: z.union([z.string(), z.number()]).nullish()
24
24
  }) });
25
+ const openaiErrorDataSchemaValidator = lazySchema(() => zodSchema(openaiErrorDataSchema()));
25
26
  const openaiFailedResponseHandler = createJsonErrorResponseHandler({
26
- errorSchema: openaiErrorDataSchema,
27
+ errorSchema: openaiErrorDataSchemaValidator,
27
28
  errorToMessage: (data) => data.error.message
28
29
  });
29
30
  //#endregion
@@ -33,8 +34,8 @@ const openaiDecisionModelOptions = lazySchema(() => zodSchema(z.object({
33
34
  safetyIdentifier: z.string().max(128).optional() })));
34
35
  //#endregion
35
36
  //#region src/openai-decision-model.ts
36
- const probability = z.number().min(0).max(1);
37
- const responseSchema = z.object({
37
+ const probability = () => z.number().min(0).max(1);
38
+ const responseSchema = lazySchema(() => zodSchema(z.object({
38
39
  model: z.string().nullish(),
39
40
  usage: z.object({
40
41
  input_tokens: z.number().nullish(),
@@ -54,30 +55,30 @@ const responseSchema = z.object({
54
55
  z.object({
55
56
  type: z.literal("predicate"),
56
57
  name: z.string(),
57
- probability
58
+ probability: probability()
58
59
  }),
59
60
  z.object({
60
61
  type: z.literal("choice"),
61
62
  name: z.string(),
62
63
  choice: z.string(),
63
- confidence: probability.nullish(),
64
+ confidence: probability().nullish(),
64
65
  probabilities: z.array(z.object({
65
66
  value: z.string(),
66
- probability
67
+ probability: probability()
67
68
  }))
68
69
  }),
69
70
  z.object({
70
71
  type: z.literal("score"),
71
72
  name: z.string(),
72
73
  score: z.number(),
73
- confidence: probability.nullish(),
74
+ confidence: probability().nullish(),
74
75
  probabilities: z.array(z.object({
75
76
  value: z.number().int().nonnegative(),
76
- probability
77
+ probability: probability()
77
78
  }))
78
79
  })
79
80
  ]))
80
- });
81
+ })));
81
82
  var DecisionOpenAIModel = class DecisionOpenAIModel {
82
83
  constructor(modelId, config) {
83
84
  this.modelId = modelId;
@@ -105,7 +106,7 @@ var DecisionOpenAIModel = class DecisionOpenAIModel {
105
106
  doEvaluate(options) {
106
107
  return this.doDecide(options);
107
108
  }
108
- async doDecide({ state, questions, headers, abortSignal, providerOptions }) {
109
+ async doDecide({ state, questions, maxOutputTokens, reasoning, headers, abortSignal, providerOptions }) {
109
110
  const openaiOptions = await parseProviderOptions({
110
111
  provider: "openai",
111
112
  providerOptions,
@@ -230,10 +231,20 @@ var DecisionOpenAIModel = class DecisionOpenAIModel {
230
231
  probabilityDecimals: 2,
231
232
  scoreDecimals: 2
232
233
  },
233
- warnings: Object.keys(providerOptions?.openai ?? {}).filter((option) => option !== "safetyIdentifier").map((option) => ({
234
- type: "unsupported",
235
- feature: `providerOptions.openai.${option}`
236
- })),
234
+ warnings: [
235
+ ...maxOutputTokens != null ? [{
236
+ type: "unsupported",
237
+ feature: "maxOutputTokens"
238
+ }] : [],
239
+ ...reasoning != null ? [{
240
+ type: "unsupported",
241
+ feature: "reasoning"
242
+ }] : [],
243
+ ...Object.keys(providerOptions?.openai ?? {}).filter((option) => option !== "safetyIdentifier").map((option) => ({
244
+ type: "unsupported",
245
+ feature: `providerOptions.openai.${option}`
246
+ }))
247
+ ],
237
248
  providerMetadata: { openai: {
238
249
  ...response.usage == null ? {} : { usage: response.usage },
239
250
  confidence: Object.fromEntries(response.answers.flatMap((answer) => (answer.type === "choice" || answer.type === "score") && answer.confidence != null ? [[answer.name, answer.confidence]] : []))
@@ -804,7 +815,7 @@ const openaiChatChunkSchema = lazySchema(() => zodSchema(z.union([z.object({
804
815
  rejected_prediction_tokens: z.number().nullish()
805
816
  }).nullish()
806
817
  }).nullish()
807
- }), openaiErrorDataSchema])));
818
+ }), openaiErrorDataSchema()])));
808
819
  //#endregion
809
820
  //#region src/chat/openai-chat-language-model-options.ts
810
821
  const openaiLanguageModelChatOptions = lazySchema(() => zodSchema(z.object({
@@ -1664,7 +1675,7 @@ const openaiCompletionChunkSchema = lazySchema(() => zodSchema(z.union([z.object
1664
1675
  completion_tokens: z.number(),
1665
1676
  total_tokens: z.number()
1666
1677
  }).nullish()
1667
- }), openaiErrorDataSchema])));
1678
+ }), openaiErrorDataSchema()])));
1668
1679
  //#endregion
1669
1680
  //#region src/completion/openai-completion-language-model-options.ts
1670
1681
  const openaiLanguageModelCompletionOptions = lazySchema(() => zodSchema(z.object({
@@ -2046,10 +2057,6 @@ const openaiFilesOptionsSchema = lazySchema(() => zodSchema(z.object({
2046
2057
  })));
2047
2058
  //#endregion
2048
2059
  //#region src/files/openai-files.ts
2049
- function encodePathSegment(value) {
2050
- const encodedValue = encodeURIComponent(value);
2051
- return encodedValue === "." ? "%252E" : encodedValue === ".." ? "%252E%252E" : encodedValue;
2052
- }
2053
2060
  var OpenAIFiles = class {
2054
2061
  get provider() {
2055
2062
  return this.config.provider;
@@ -2258,7 +2265,7 @@ function hasDefaultResponseFormat(modelId) {
2258
2265
  function getMaxImagesPerCall(modelId) {
2259
2266
  return modelMaxImagesPerCall[modelId] ?? (modelId.startsWith("gpt-image-") ? 10 : 1);
2260
2267
  }
2261
- const baseImageModelOptionsObject = z.object({
2268
+ const baseImageModelOptionsObject = () => z.object({
2262
2269
  /**
2263
2270
  * Quality of the generated image(s).
2264
2271
  *
@@ -2305,8 +2312,8 @@ const baseImageModelOptionsObject = z.object({
2305
2312
  */
2306
2313
  user: z.string().optional()
2307
2314
  });
2308
- lazySchema(() => zodSchema(baseImageModelOptionsObject));
2309
- const openaiImageModelGenerationOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject.extend({
2315
+ lazySchema(() => zodSchema(baseImageModelOptionsObject()));
2316
+ const openaiImageModelGenerationOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject().extend({
2310
2317
  /**
2311
2318
  * Style of the generated image. `vivid` produces hyper-real and
2312
2319
  * dramatic images; `natural` produces more subdued, less hyper-real
@@ -2319,7 +2326,7 @@ const openaiImageModelGenerationOptions = lazySchema(() => zodSchema(baseImageMo
2319
2326
  */
2320
2327
  moderation: z.enum(["auto", "low"]).optional()
2321
2328
  })));
2322
- const openaiImageModelEditOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject.extend({
2329
+ const openaiImageModelEditOptions = lazySchema(() => zodSchema(baseImageModelOptionsObject().extend({
2323
2330
  /**
2324
2331
  * Fidelity of the output image(s) to the input image(s).
2325
2332
  */
@@ -2585,12 +2592,12 @@ const codeInterpreter = (args = {}) => {
2585
2592
  };
2586
2593
  //#endregion
2587
2594
  //#region src/tool/computer.ts
2588
- const safetyCheckSchema = z.object({
2595
+ const safetyCheckSchema = () => z.object({
2589
2596
  id: z.string(),
2590
2597
  code: z.string().optional(),
2591
2598
  message: z.string().optional()
2592
2599
  });
2593
- const computerActionSchema = z.discriminatedUnion("type", [
2600
+ const computerActionSchema = () => z.discriminatedUnion("type", [
2594
2601
  z.object({
2595
2602
  type: z.literal("click"),
2596
2603
  button: z.enum([
@@ -2644,8 +2651,8 @@ const computerActionSchema = z.discriminatedUnion("type", [
2644
2651
  z.object({ type: z.literal("wait") })
2645
2652
  ]);
2646
2653
  const computerInputSchema = lazySchema(() => zodSchema(z.object({
2647
- actions: z.array(computerActionSchema),
2648
- pendingSafetyChecks: z.array(safetyCheckSchema),
2654
+ actions: z.array(computerActionSchema()),
2655
+ pendingSafetyChecks: z.array(safetyCheckSchema()),
2649
2656
  status: z.enum([
2650
2657
  "in_progress",
2651
2658
  "completed",
@@ -2674,7 +2681,7 @@ const computerOutputSchema = lazySchema(() => zodSchema(z.object({
2674
2681
  "original"
2675
2682
  ]).optional()
2676
2683
  })]),
2677
- acknowledgedSafetyChecks: z.array(safetyCheckSchema).optional()
2684
+ acknowledgedSafetyChecks: z.array(safetyCheckSchema()).optional()
2678
2685
  })));
2679
2686
  const computerToolFactory = createProviderDefinedToolFactoryWithOutputSchema({
2680
2687
  id: "openai.computer",
@@ -2701,7 +2708,7 @@ const customToolFactory = createProviderDefinedToolFactory({
2701
2708
  const customTool = (args) => customToolFactory(args);
2702
2709
  //#endregion
2703
2710
  //#region src/tool/file-search.ts
2704
- const comparisonFilterSchema = z.object({
2711
+ const comparisonFilterSchema = () => z.object({
2705
2712
  key: z.string(),
2706
2713
  type: z.enum([
2707
2714
  "eq",
@@ -2720,9 +2727,10 @@ const comparisonFilterSchema = z.object({
2720
2727
  z.array(z.string())
2721
2728
  ])
2722
2729
  });
2723
- const compoundFilterSchema = z.object({
2730
+ let cachedCompoundFilterSchema;
2731
+ const compoundFilterSchema = () => cachedCompoundFilterSchema ??= z.object({
2724
2732
  type: z.enum(["and", "or"]),
2725
- filters: z.array(z.union([comparisonFilterSchema, z.lazy(() => compoundFilterSchema)]))
2733
+ filters: z.array(z.union([comparisonFilterSchema(), z.lazy(() => compoundFilterSchema())]))
2726
2734
  });
2727
2735
  const fileSearchArgsSchema = lazySchema(() => zodSchema(z.object({
2728
2736
  vectorStoreIds: z.array(z.string()),
@@ -2731,7 +2739,7 @@ const fileSearchArgsSchema = lazySchema(() => zodSchema(z.object({
2731
2739
  ranker: z.string().optional(),
2732
2740
  scoreThreshold: z.number().optional()
2733
2741
  }).optional(),
2734
- filters: z.union([comparisonFilterSchema, compoundFilterSchema]).optional()
2742
+ filters: z.union([comparisonFilterSchema(), compoundFilterSchema()]).optional()
2735
2743
  })));
2736
2744
  const fileSearchOutputSchema = lazySchema(() => zodSchema(z.object({
2737
2745
  queries: z.array(z.string()),
@@ -2823,15 +2831,18 @@ const shellInputSchema = lazySchema(() => zodSchema(z.object({ action: z.object(
2823
2831
  timeoutMs: z.number().optional(),
2824
2832
  maxOutputLength: z.number().optional()
2825
2833
  }) })));
2826
- const shellOutputSchema = lazySchema(() => zodSchema(z.object({ output: z.array(z.object({
2827
- stdout: z.string(),
2828
- stderr: z.string(),
2829
- outcome: z.discriminatedUnion("type", [z.object({ type: z.literal("timeout") }), z.object({
2830
- type: z.literal("exit"),
2831
- exitCode: z.number()
2832
- })])
2833
- })) })));
2834
- const shellSkillsSchema = z.array(z.discriminatedUnion("type", [z.object({
2834
+ const shellOutputSchema = lazySchema(() => zodSchema(z.object({
2835
+ maxOutputLength: z.number().optional(),
2836
+ output: z.array(z.object({
2837
+ stdout: z.string(),
2838
+ stderr: z.string(),
2839
+ outcome: z.discriminatedUnion("type", [z.object({ type: z.literal("timeout") }), z.object({
2840
+ type: z.literal("exit"),
2841
+ exitCode: z.number()
2842
+ })])
2843
+ }))
2844
+ })));
2845
+ const shellSkillsSchema = () => z.array(z.discriminatedUnion("type", [z.object({
2835
2846
  type: z.literal("skillReference"),
2836
2847
  providerReference: z.record(z.string(), z.string()),
2837
2848
  version: z.string().optional()
@@ -2864,7 +2875,7 @@ const shellArgsSchema = lazySchema(() => zodSchema(z.object({ environment: z.uni
2864
2875
  value: z.string()
2865
2876
  })).optional()
2866
2877
  })]).optional(),
2867
- skills: shellSkillsSchema
2878
+ skills: shellSkillsSchema()
2868
2879
  }),
2869
2880
  z.object({
2870
2881
  type: z.literal("containerReference"),
@@ -2994,13 +3005,14 @@ const webSearchPreview = createProviderExecutedToolFactory({
2994
3005
  });
2995
3006
  //#endregion
2996
3007
  //#region src/tool/mcp.ts
2997
- const jsonValueSchema$1 = z.lazy(() => z.union([
3008
+ let cachedJsonValueSchema$1;
3009
+ const jsonValueSchema$1 = () => cachedJsonValueSchema$1 ??= z.lazy(() => z.union([
2998
3010
  z.string(),
2999
3011
  z.number(),
3000
3012
  z.boolean(),
3001
3013
  z.null(),
3002
- z.array(jsonValueSchema$1),
3003
- z.record(z.string(), jsonValueSchema$1)
3014
+ z.array(jsonValueSchema$1()),
3015
+ z.record(z.string(), jsonValueSchema$1())
3004
3016
  ]));
3005
3017
  const mcpArgsSchema = lazySchema(() => zodSchema(z.object({
3006
3018
  serverLabel: z.string(),
@@ -3022,7 +3034,7 @@ const mcpOutputSchema = lazySchema(() => zodSchema(z.object({
3022
3034
  name: z.string(),
3023
3035
  arguments: z.string(),
3024
3036
  output: z.string().nullish(),
3025
- error: z.union([z.string(), jsonValueSchema$1]).optional()
3037
+ error: z.union([z.string(), jsonValueSchema$1()]).optional()
3026
3038
  })));
3027
3039
  const mcpToolFactory = createProviderExecutedToolFactory({
3028
3040
  id: "openai.mcp",
@@ -3230,36 +3242,41 @@ function mapOpenAIResponseFinishReason({ finishReason, hasFunctionCall }) {
3230
3242
  }
3231
3243
  //#endregion
3232
3244
  //#region src/responses/openai-responses-api.ts
3233
- const jsonValueSchema = z.lazy(() => z.union([
3245
+ let cachedJsonValueSchema;
3246
+ const jsonValueSchema = () => cachedJsonValueSchema ??= z.lazy(() => z.union([
3234
3247
  z.string(),
3235
3248
  z.number(),
3236
3249
  z.boolean(),
3237
3250
  z.null(),
3238
- z.array(jsonValueSchema),
3239
- z.record(z.string(), jsonValueSchema.optional())
3251
+ z.array(jsonValueSchema()),
3252
+ z.record(z.string(), jsonValueSchema().optional())
3240
3253
  ]));
3241
- const jsonObjectSchema = z.record(z.string(), jsonValueSchema.optional());
3242
- const openaiResponsesUsageSchema = z.intersection(jsonObjectSchema, z.object({
3254
+ const jsonObjectSchema = () => z.record(z.string(), jsonValueSchema().optional());
3255
+ const openaiResponsesUsageSchema = () => z.intersection(jsonObjectSchema(), z.object({
3243
3256
  input_tokens: z.number(),
3244
- input_tokens_details: z.intersection(jsonObjectSchema, z.object({
3257
+ input_tokens_details: z.intersection(jsonObjectSchema(), z.object({
3245
3258
  cached_tokens: z.number().nullish(),
3246
3259
  cache_write_tokens: z.number().nullish(),
3260
+ cache_write_tokens_details: z.intersection(jsonObjectSchema(), z.object({
3261
+ ttl_30m_tokens: z.number().nullish(),
3262
+ ttl_12h_tokens: z.number().nullish()
3263
+ })).nullish(),
3247
3264
  orchestration_input_tokens: z.number().nullish(),
3248
3265
  orchestration_input_cached_tokens: z.number().nullish()
3249
3266
  })).nullish(),
3250
3267
  output_tokens: z.number(),
3251
- output_tokens_details: z.intersection(jsonObjectSchema, z.object({
3268
+ output_tokens_details: z.intersection(jsonObjectSchema(), z.object({
3252
3269
  reasoning_tokens: z.number().nullish(),
3253
3270
  orchestration_output_tokens: z.number().nullish()
3254
3271
  })).nullish(),
3255
3272
  total_tokens: z.number().optional()
3256
3273
  }));
3257
- const openaiResponsesComputerSafetyCheckSchema = z.object({
3274
+ const openaiResponsesComputerSafetyCheckSchema = () => z.object({
3258
3275
  id: z.string(),
3259
3276
  code: z.string().nullish(),
3260
3277
  message: z.string().nullish()
3261
3278
  });
3262
- const openaiResponsesComputerActionSchema = z.discriminatedUnion("type", [
3279
+ const openaiResponsesComputerActionSchema = () => z.discriminatedUnion("type", [
3263
3280
  z.object({
3264
3281
  type: z.literal("click"),
3265
3282
  button: z.enum([
@@ -3312,7 +3329,7 @@ const openaiResponsesComputerActionSchema = z.discriminatedUnion("type", [
3312
3329
  }),
3313
3330
  z.object({ type: z.literal("wait") })
3314
3331
  ]);
3315
- const openaiResponsesComputerCallSchema = z.object({
3332
+ const openaiResponsesComputerCallSchema = () => z.object({
3316
3333
  type: z.literal("computer_call"),
3317
3334
  id: z.string(),
3318
3335
  call_id: z.string().nullish(),
@@ -3321,29 +3338,29 @@ const openaiResponsesComputerCallSchema = z.object({
3321
3338
  "completed",
3322
3339
  "incomplete"
3323
3340
  ]),
3324
- action: openaiResponsesComputerActionSchema.nullish(),
3325
- actions: z.array(openaiResponsesComputerActionSchema).nullish(),
3326
- pending_safety_checks: z.array(openaiResponsesComputerSafetyCheckSchema).nullish()
3341
+ action: openaiResponsesComputerActionSchema().nullish(),
3342
+ actions: z.array(openaiResponsesComputerActionSchema()).nullish(),
3343
+ pending_safety_checks: z.array(openaiResponsesComputerSafetyCheckSchema()).nullish()
3327
3344
  });
3328
- const openaiResponsesToolCallerSchema = z.discriminatedUnion("type", [z.object({ type: z.literal("direct") }), z.object({
3345
+ const openaiResponsesToolCallerSchema = () => z.discriminatedUnion("type", [z.object({ type: z.literal("direct") }), z.object({
3329
3346
  type: z.literal("program"),
3330
3347
  caller_id: z.string()
3331
3348
  })]);
3332
- const openaiResponsesProgramSchema = z.object({
3349
+ const openaiResponsesProgramSchema = () => z.object({
3333
3350
  type: z.literal("program"),
3334
3351
  id: z.string(),
3335
3352
  call_id: z.string(),
3336
3353
  code: z.string(),
3337
3354
  fingerprint: z.string()
3338
3355
  });
3339
- const openaiResponsesProgramOutputSchema = z.object({
3356
+ const openaiResponsesProgramOutputSchema = () => z.object({
3340
3357
  type: z.literal("program_output"),
3341
3358
  id: z.string(),
3342
3359
  call_id: z.string(),
3343
3360
  result: z.string(),
3344
3361
  status: z.enum(["completed", "incomplete"])
3345
3362
  });
3346
- const openaiResponsesLocalShellCallSchema = z.object({
3363
+ const openaiResponsesLocalShellCallSchema = () => z.object({
3347
3364
  type: z.literal("local_shell_call"),
3348
3365
  id: z.string(),
3349
3366
  call_id: z.string(),
@@ -3356,7 +3373,7 @@ const openaiResponsesLocalShellCallSchema = z.object({
3356
3373
  env: z.record(z.string(), z.string()).optional()
3357
3374
  })
3358
3375
  });
3359
- const openaiResponsesNestedErrorChunkSchema = z.object({
3376
+ const openaiResponsesNestedErrorChunkSchema = () => z.object({
3360
3377
  type: z.literal("error"),
3361
3378
  sequence_number: z.number(),
3362
3379
  error: z.object({
@@ -3366,7 +3383,7 @@ const openaiResponsesNestedErrorChunkSchema = z.object({
3366
3383
  param: z.string().nullish()
3367
3384
  })
3368
3385
  });
3369
- const openaiResponsesErrorChunkSchema = z.object({
3386
+ const openaiResponsesErrorChunkSchema = () => z.object({
3370
3387
  type: z.literal("error"),
3371
3388
  sequence_number: z.number(),
3372
3389
  code: z.string().nullish(),
@@ -3454,7 +3471,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3454
3471
  type: z.enum(["response.completed", "response.incomplete"]),
3455
3472
  response: z.object({
3456
3473
  incomplete_details: z.object({ reason: z.string() }).nullish(),
3457
- usage: openaiResponsesUsageSchema.nullish(),
3474
+ usage: openaiResponsesUsageSchema().nullish(),
3458
3475
  reasoning: z.object({ context: z.string().nullish() }).nullish(),
3459
3476
  service_tier: z.string().nullish()
3460
3477
  })
@@ -3468,7 +3485,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3468
3485
  message: z.string()
3469
3486
  }).nullish(),
3470
3487
  incomplete_details: z.object({ reason: z.string() }).nullish(),
3471
- usage: openaiResponsesUsageSchema.nullish(),
3488
+ usage: openaiResponsesUsageSchema().nullish(),
3472
3489
  reasoning: z.object({ context: z.string().nullish() }).nullish(),
3473
3490
  service_tier: z.string().nullish()
3474
3491
  })
@@ -3513,21 +3530,21 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3513
3530
  arguments: z.string(),
3514
3531
  async: z.boolean().nullish(),
3515
3532
  namespace: z.string().nullish(),
3516
- caller: openaiResponsesToolCallerSchema.nullish()
3533
+ caller: openaiResponsesToolCallerSchema().nullish()
3517
3534
  }),
3518
- openaiResponsesProgramSchema,
3519
- openaiResponsesProgramOutputSchema,
3535
+ openaiResponsesProgramSchema(),
3536
+ openaiResponsesProgramOutputSchema(),
3520
3537
  z.object({
3521
3538
  type: z.literal("web_search_call"),
3522
3539
  id: z.string(),
3523
3540
  status: z.string()
3524
3541
  }),
3525
- openaiResponsesComputerCallSchema,
3542
+ openaiResponsesComputerCallSchema(),
3526
3543
  z.object({
3527
3544
  type: z.literal("file_search_call"),
3528
3545
  id: z.string()
3529
3546
  }),
3530
- openaiResponsesLocalShellCallSchema,
3547
+ openaiResponsesLocalShellCallSchema(),
3531
3548
  z.object({
3532
3549
  type: z.literal("image_generation_call"),
3533
3550
  id: z.string()
@@ -3599,7 +3616,11 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3599
3616
  "completed",
3600
3617
  "incomplete"
3601
3618
  ]),
3602
- action: z.object({ commands: z.array(z.string()) })
3619
+ action: z.object({
3620
+ commands: z.array(z.string()),
3621
+ timeout_ms: z.number().nullish(),
3622
+ max_output_length: z.number().nullish()
3623
+ })
3603
3624
  }),
3604
3625
  z.object({
3605
3626
  type: z.literal("compaction"),
@@ -3615,6 +3636,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3615
3636
  "completed",
3616
3637
  "incomplete"
3617
3638
  ]),
3639
+ max_output_length: z.number().nullish(),
3618
3640
  output: z.array(z.object({
3619
3641
  stdout: z.string(),
3620
3642
  stderr: z.string(),
@@ -3646,7 +3668,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3646
3668
  "completed",
3647
3669
  "incomplete"
3648
3670
  ]),
3649
- tools: z.array(z.record(z.string(), jsonValueSchema.optional()))
3671
+ tools: z.array(z.record(z.string(), jsonValueSchema().optional()))
3650
3672
  })
3651
3673
  ])
3652
3674
  }),
@@ -3677,10 +3699,10 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3677
3699
  "incomplete"
3678
3700
  ]),
3679
3701
  namespace: z.string().nullish(),
3680
- caller: openaiResponsesToolCallerSchema.nullish()
3702
+ caller: openaiResponsesToolCallerSchema().nullish()
3681
3703
  }),
3682
- openaiResponsesProgramSchema,
3683
- openaiResponsesProgramOutputSchema,
3704
+ openaiResponsesProgramSchema(),
3705
+ openaiResponsesProgramOutputSchema(),
3684
3706
  z.object({
3685
3707
  type: z.literal("custom_tool_call"),
3686
3708
  id: z.string(),
@@ -3752,8 +3774,8 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3752
3774
  text: z.string()
3753
3775
  })).nullish()
3754
3776
  }),
3755
- openaiResponsesLocalShellCallSchema,
3756
- openaiResponsesComputerCallSchema,
3777
+ openaiResponsesLocalShellCallSchema(),
3778
+ openaiResponsesComputerCallSchema(),
3757
3779
  z.object({
3758
3780
  type: z.literal("mcp_call"),
3759
3781
  id: z.string(),
@@ -3824,7 +3846,11 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3824
3846
  "completed",
3825
3847
  "incomplete"
3826
3848
  ]),
3827
- action: z.object({ commands: z.array(z.string()) })
3849
+ action: z.object({
3850
+ commands: z.array(z.string()),
3851
+ timeout_ms: z.number().nullish(),
3852
+ max_output_length: z.number().nullish()
3853
+ })
3828
3854
  }),
3829
3855
  z.object({
3830
3856
  type: z.literal("compaction"),
@@ -3840,6 +3866,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3840
3866
  "completed",
3841
3867
  "incomplete"
3842
3868
  ]),
3869
+ max_output_length: z.number().nullish(),
3843
3870
  output: z.array(z.object({
3844
3871
  stdout: z.string(),
3845
3872
  stderr: z.string(),
@@ -3871,7 +3898,7 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3871
3898
  "completed",
3872
3899
  "incomplete"
3873
3900
  ]),
3874
- tools: z.array(z.record(z.string(), jsonValueSchema.optional()))
3901
+ tools: z.array(z.record(z.string(), jsonValueSchema().optional()))
3875
3902
  })
3876
3903
  ])
3877
3904
  }),
@@ -3974,8 +4001,8 @@ const openaiResponsesChunkSchema = lazySchema(() => zodSchema(z.union([
3974
4001
  output_index: z.number(),
3975
4002
  diff: z.string()
3976
4003
  }),
3977
- openaiResponsesNestedErrorChunkSchema,
3978
- openaiResponsesErrorChunkSchema,
4004
+ openaiResponsesNestedErrorChunkSchema(),
4005
+ openaiResponsesErrorChunkSchema(),
3979
4006
  z.object({ type: z.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), { message: "Known response chunk failed schema validation" }).transform((value) => ({
3980
4007
  type: "unknown_chunk",
3981
4008
  message: value.type
@@ -4100,7 +4127,7 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
4100
4127
  id: z.string(),
4101
4128
  result: z.string()
4102
4129
  }),
4103
- openaiResponsesLocalShellCallSchema,
4130
+ openaiResponsesLocalShellCallSchema(),
4104
4131
  z.object({
4105
4132
  type: z.literal("function_call"),
4106
4133
  call_id: z.string(),
@@ -4109,10 +4136,10 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
4109
4136
  id: z.string(),
4110
4137
  async: z.boolean().nullish(),
4111
4138
  namespace: z.string().nullish(),
4112
- caller: openaiResponsesToolCallerSchema.nullish()
4139
+ caller: openaiResponsesToolCallerSchema().nullish()
4113
4140
  }),
4114
- openaiResponsesProgramSchema,
4115
- openaiResponsesProgramOutputSchema,
4141
+ openaiResponsesProgramSchema(),
4142
+ openaiResponsesProgramOutputSchema(),
4116
4143
  z.object({
4117
4144
  type: z.literal("custom_tool_call"),
4118
4145
  call_id: z.string(),
@@ -4121,7 +4148,7 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
4121
4148
  id: z.string(),
4122
4149
  async: z.boolean().nullish()
4123
4150
  }),
4124
- openaiResponsesComputerCallSchema,
4151
+ openaiResponsesComputerCallSchema(),
4125
4152
  z.object({
4126
4153
  type: z.literal("reasoning"),
4127
4154
  id: z.string(),
@@ -4201,7 +4228,11 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
4201
4228
  "completed",
4202
4229
  "incomplete"
4203
4230
  ]),
4204
- action: z.object({ commands: z.array(z.string()) })
4231
+ action: z.object({
4232
+ commands: z.array(z.string()),
4233
+ timeout_ms: z.number().nullish(),
4234
+ max_output_length: z.number().nullish()
4235
+ })
4205
4236
  }),
4206
4237
  z.object({
4207
4238
  type: z.literal("compaction"),
@@ -4217,6 +4248,7 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
4217
4248
  "completed",
4218
4249
  "incomplete"
4219
4250
  ]),
4251
+ max_output_length: z.number().nullish(),
4220
4252
  output: z.array(z.object({
4221
4253
  stdout: z.string(),
4222
4254
  stderr: z.string(),
@@ -4248,13 +4280,13 @@ const openaiResponsesResponseSchema = lazySchema(() => zodSchema(z.object({
4248
4280
  "completed",
4249
4281
  "incomplete"
4250
4282
  ]),
4251
- tools: z.array(z.record(z.string(), jsonValueSchema.optional()))
4283
+ tools: z.array(z.record(z.string(), jsonValueSchema().optional()))
4252
4284
  })
4253
4285
  ])).optional(),
4254
4286
  service_tier: z.string().nullish(),
4255
4287
  reasoning: z.object({ context: z.string().nullish() }).nullish(),
4256
4288
  incomplete_details: z.object({ reason: z.string() }).nullish(),
4257
- usage: openaiResponsesUsageSchema.nullish()
4289
+ usage: openaiResponsesUsageSchema().nullish()
4258
4290
  })));
4259
4291
  const openaiLanguageModelResponsesOptionsSchema = lazySchema(() => zodSchema(z.object({
4260
4292
  /**
@@ -4330,11 +4362,13 @@ const openaiLanguageModelResponsesOptionsSchema = lazySchema(() => zodSchema(z.o
4330
4362
  /**
4331
4363
  * Prompt cache behavior for GPT-5.6 and later models.
4332
4364
  * `mode` controls whether OpenAI also places an implicit breakpoint.
4333
- * `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
4365
+ * `ttl` sets the minimum cache lifetime: `'30m'` (default) or `'12h'`.
4366
+ * `prewarm` writes the prompt to the cache without generating output.
4334
4367
  */
4335
4368
  promptCacheOptions: z.object({
4336
4369
  mode: z.enum(["implicit", "explicit"]).optional(),
4337
- ttl: z.literal("30m").optional()
4370
+ ttl: z.enum(["30m", "12h"]).optional(),
4371
+ prewarm: z.boolean().optional()
4338
4372
  }).optional(),
4339
4373
  /**
4340
4374
  * The retention policy for the prompt cache.
@@ -5220,6 +5254,7 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
5220
5254
  input.push({
5221
5255
  type: "shell_call_output",
5222
5256
  call_id: part.toolCallId,
5257
+ ...parsedOutput.maxOutputLength != null && { max_output_length: parsedOutput.maxOutputLength },
5223
5258
  output: parsedOutput.output.map((item) => ({
5224
5259
  stdout: item.stdout,
5225
5260
  stderr: item.stderr,
@@ -5426,6 +5461,7 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
5426
5461
  input.push({
5427
5462
  type: "shell_call_output",
5428
5463
  call_id: part.toolCallId,
5464
+ ...parsedOutput.maxOutputLength != null && { max_output_length: parsedOutput.maxOutputLength },
5429
5465
  output: parsedOutput.output.map((item) => ({
5430
5466
  stdout: item.stdout,
5431
5467
  stderr: item.stderr,
@@ -5609,10 +5645,10 @@ async function convertToOpenAIResponsesInput({ prompt, toolNameMapping, systemMe
5609
5645
  warnings
5610
5646
  };
5611
5647
  }
5612
- const openaiResponsesReasoningProviderOptionsSchema = z.object({
5648
+ const openaiResponsesReasoningProviderOptionsSchema = lazySchema(() => zodSchema(z.object({
5613
5649
  itemId: z.string().nullish(),
5614
5650
  reasoningEncryptedContent: z.string().nullish()
5615
- });
5651
+ })));
5616
5652
  //#endregion
5617
5653
  //#region src/responses/map-openai-responses-annotation.ts
5618
5654
  function mapOpenAIResponsesAnnotationSource(annotation, providerOptionsName, id) {
@@ -6620,7 +6656,11 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
6620
6656
  type: "tool-call",
6621
6657
  toolCallId: part.call_id,
6622
6658
  toolName: toolNameMapping.toCustomToolName("shell"),
6623
- input: JSON.stringify({ action: { commands: part.action.commands } }),
6659
+ input: JSON.stringify({ action: {
6660
+ commands: part.action.commands,
6661
+ timeoutMs: part.action.timeout_ms ?? void 0,
6662
+ maxOutputLength: part.action.max_output_length ?? void 0
6663
+ } }),
6624
6664
  ...isShellProviderExecuted && { providerExecuted: true },
6625
6665
  providerMetadata: { [providerOptionsName]: { itemId: part.id } }
6626
6666
  });
@@ -6630,14 +6670,17 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
6630
6670
  type: "tool-result",
6631
6671
  toolCallId: part.call_id,
6632
6672
  toolName: toolNameMapping.toCustomToolName("shell"),
6633
- result: { output: part.output.map((item) => ({
6634
- stdout: item.stdout,
6635
- stderr: item.stderr,
6636
- outcome: item.outcome.type === "exit" ? {
6637
- type: "exit",
6638
- exitCode: item.outcome.exit_code
6639
- } : { type: "timeout" }
6640
- })) }
6673
+ result: {
6674
+ ...part.max_output_length != null && { maxOutputLength: part.max_output_length },
6675
+ output: part.output.map((item) => ({
6676
+ stdout: item.stdout,
6677
+ stderr: item.stderr,
6678
+ outcome: item.outcome.type === "exit" ? {
6679
+ type: "exit",
6680
+ exitCode: item.outcome.exit_code
6681
+ } : { type: "timeout" }
6682
+ }))
6683
+ }
6641
6684
  });
6642
6685
  break;
6643
6686
  case "message":
@@ -7605,7 +7648,11 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
7605
7648
  type: "tool-call",
7606
7649
  toolCallId: value.item.call_id,
7607
7650
  toolName: toolNameMapping.toCustomToolName("shell"),
7608
- input: JSON.stringify({ action: { commands: value.item.action.commands } }),
7651
+ input: JSON.stringify({ action: {
7652
+ commands: value.item.action.commands,
7653
+ timeoutMs: value.item.action.timeout_ms ?? void 0,
7654
+ maxOutputLength: value.item.action.max_output_length ?? void 0
7655
+ } }),
7609
7656
  ...isShellProviderExecuted && { providerExecuted: true },
7610
7657
  providerMetadata: { [providerOptionsName]: { itemId: value.item.id } }
7611
7658
  });
@@ -7613,14 +7660,17 @@ var OpenAIResponsesLanguageModel = class OpenAIResponsesLanguageModel {
7613
7660
  type: "tool-result",
7614
7661
  toolCallId: value.item.call_id,
7615
7662
  toolName: toolNameMapping.toCustomToolName("shell"),
7616
- result: { output: value.item.output.map((item) => ({
7617
- stdout: item.stdout,
7618
- stderr: item.stderr,
7619
- outcome: item.outcome.type === "exit" ? {
7620
- type: "exit",
7621
- exitCode: item.outcome.exit_code
7622
- } : { type: "timeout" }
7623
- })) }
7663
+ result: {
7664
+ ...value.item.max_output_length != null && { maxOutputLength: value.item.max_output_length },
7665
+ output: value.item.output.map((item) => ({
7666
+ stdout: item.stdout,
7667
+ stderr: item.stderr,
7668
+ outcome: item.outcome.type === "exit" ? {
7669
+ type: "exit",
7670
+ exitCode: item.outcome.exit_code
7671
+ } : { type: "timeout" }
7672
+ }))
7673
+ }
7624
7674
  });
7625
7675
  else if (value.item.type === "reasoning") {
7626
7676
  const itemId = resolveOutputItemId({
@@ -8370,7 +8420,7 @@ function convertUnixTimestamp(value) {
8370
8420
  async function convertOpenAIErrorResponse({ body, statusCode }) {
8371
8421
  const result = await safeValidateTypes({
8372
8422
  value: body,
8373
- schema: openaiErrorDataSchema
8423
+ schema: openaiErrorDataSchemaValidator
8374
8424
  });
8375
8425
  if (!result.success) return {
8376
8426
  message: `OpenAI batch request failed with status code ${statusCode}.`,
@@ -8889,13 +8939,13 @@ function serializeOpenAILiveClientEvent(event, modelId) {
8889
8939
  }
8890
8940
  //#endregion
8891
8941
  //#region src/live/openai-realtime-model-live.ts
8892
- const webRTCSessionSchema = z.object({
8942
+ const webRTCSessionSchema = lazySchema(() => zodSchema(z.object({
8893
8943
  session: z.object({ id: z.string().min(1) }),
8894
8944
  transport: z.object({
8895
8945
  type: z.literal("webrtc"),
8896
8946
  sdp: z.string().min(1)
8897
8947
  })
8898
- });
8948
+ })));
8899
8949
  var OpenAIRealtimeModelLive = class {
8900
8950
  constructor(modelId, config) {
8901
8951
  this.modelId = modelId;
@@ -9441,6 +9491,7 @@ var OpenAISpeechModel = class OpenAISpeechModel {
9441
9491
  const openaiTranscriptionResponseSchema = lazySchema(() => zodSchema(z.object({
9442
9492
  text: z.string(),
9443
9493
  language: z.string().nullish(),
9494
+ languages: z.array(z.object({ code: z.string() })).nullish(),
9444
9495
  duration: z.number().nullish(),
9445
9496
  words: z.array(z.object({
9446
9497
  word: z.string(),
@@ -9599,6 +9650,9 @@ const languageMap = {
9599
9650
  vietnamese: "vi",
9600
9651
  welsh: "cy"
9601
9652
  };
9653
+ function isLanguageCode(language) {
9654
+ return language != null && /^[a-z]{2}$/.test(language);
9655
+ }
9602
9656
  var OpenAITranscriptionModel = class OpenAITranscriptionModel {
9603
9657
  static [WORKFLOW_SERIALIZE](model) {
9604
9658
  return serializeModelOptions({
@@ -9674,7 +9728,7 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
9674
9728
  abortSignal: options.abortSignal,
9675
9729
  fetch: this.config.fetch
9676
9730
  });
9677
- const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
9731
+ 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);
9678
9732
  const diarizedSegments = response.segments?.flatMap((segment) => "speaker" in segment ? [{
9679
9733
  text: segment.text,
9680
9734
  startSecond: segment.start,
@@ -9702,7 +9756,10 @@ var OpenAITranscriptionModel = class OpenAITranscriptionModel {
9702
9756
  headers: responseHeaders,
9703
9757
  body: rawResponse
9704
9758
  },
9705
- ...diarizedSegments != null && diarizedSegments.length > 0 && { providerMetadata: { openai: { segments: diarizedSegments } } }
9759
+ ...(diarizedSegments != null && diarizedSegments.length > 0 || response.languages != null) && { providerMetadata: { openai: {
9760
+ ...diarizedSegments != null && diarizedSegments.length > 0 && { segments: diarizedSegments },
9761
+ ...response.languages != null && { languages: response.languages }
9762
+ } } }
9706
9763
  };
9707
9764
  }
9708
9765
  async doStream(options) {
@@ -10191,7 +10248,7 @@ var OpenAISkills = class {
10191
10248
  };
10192
10249
  //#endregion
10193
10250
  //#region src/version.ts
10194
- const VERSION = "4.0.97";
10251
+ const VERSION = "4.0.99";
10195
10252
  //#endregion
10196
10253
  //#region src/openai-provider.ts
10197
10254
  /**