@ai-sdk/openai 3.0.35 → 3.0.37

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.
@@ -1041,7 +1041,7 @@ var OpenAIChatLanguageModel = class {
1041
1041
  for (const toolCallDelta of delta.tool_calls) {
1042
1042
  const index = toolCallDelta.index;
1043
1043
  if (toolCalls[index] == null) {
1044
- if (toolCallDelta.type !== "function") {
1044
+ if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
1045
1045
  throw new import_provider3.InvalidResponseDataError({
1046
1046
  data: toolCallDelta,
1047
1047
  message: `Expected 'function' type.`
@@ -2338,7 +2338,7 @@ var OpenAISpeechModel = class {
2338
2338
 
2339
2339
  // src/responses/openai-responses-language-model.ts
2340
2340
  var import_provider8 = require("@ai-sdk/provider");
2341
- var import_provider_utils32 = require("@ai-sdk/provider-utils");
2341
+ var import_provider_utils33 = require("@ai-sdk/provider-utils");
2342
2342
 
2343
2343
  // src/responses/convert-openai-responses-usage.ts
2344
2344
  function convertOpenAIResponsesUsage(usage) {
@@ -2564,9 +2564,10 @@ async function convertToOpenAIResponsesInput({
2564
2564
  hasConversation = false,
2565
2565
  hasLocalShellTool = false,
2566
2566
  hasShellTool = false,
2567
- hasApplyPatchTool = false
2567
+ hasApplyPatchTool = false,
2568
+ customProviderToolNames
2568
2569
  }) {
2569
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
2570
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2570
2571
  const input = [];
2571
2572
  const warnings = [];
2572
2573
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -2735,6 +2736,16 @@ async function convertToOpenAIResponsesInput({
2735
2736
  });
2736
2737
  break;
2737
2738
  }
2739
+ if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
2740
+ input.push({
2741
+ type: "custom_tool_call",
2742
+ call_id: part.toolCallId,
2743
+ name: resolvedToolName,
2744
+ input: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
2745
+ id
2746
+ });
2747
+ break;
2748
+ }
2738
2749
  input.push({
2739
2750
  type: "function_call",
2740
2751
  call_id: part.toolCallId,
@@ -2939,6 +2950,61 @@ async function convertToOpenAIResponsesInput({
2939
2950
  });
2940
2951
  continue;
2941
2952
  }
2953
+ if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
2954
+ let outputValue;
2955
+ switch (output.type) {
2956
+ case "text":
2957
+ case "error-text":
2958
+ outputValue = output.value;
2959
+ break;
2960
+ case "execution-denied":
2961
+ outputValue = (_l = output.reason) != null ? _l : "Tool execution denied.";
2962
+ break;
2963
+ case "json":
2964
+ case "error-json":
2965
+ outputValue = JSON.stringify(output.value);
2966
+ break;
2967
+ case "content":
2968
+ outputValue = output.value.map((item) => {
2969
+ var _a2;
2970
+ switch (item.type) {
2971
+ case "text":
2972
+ return { type: "input_text", text: item.text };
2973
+ case "image-data":
2974
+ return {
2975
+ type: "input_image",
2976
+ image_url: `data:${item.mediaType};base64,${item.data}`
2977
+ };
2978
+ case "image-url":
2979
+ return {
2980
+ type: "input_image",
2981
+ image_url: item.url
2982
+ };
2983
+ case "file-data":
2984
+ return {
2985
+ type: "input_file",
2986
+ filename: (_a2 = item.filename) != null ? _a2 : "data",
2987
+ file_data: `data:${item.mediaType};base64,${item.data}`
2988
+ };
2989
+ default:
2990
+ warnings.push({
2991
+ type: "other",
2992
+ message: `unsupported custom tool content part type: ${item.type}`
2993
+ });
2994
+ return void 0;
2995
+ }
2996
+ }).filter(import_provider_utils22.isNonNullable);
2997
+ break;
2998
+ default:
2999
+ outputValue = "";
3000
+ }
3001
+ input.push({
3002
+ type: "custom_tool_call_output",
3003
+ call_id: part.toolCallId,
3004
+ output: outputValue
3005
+ });
3006
+ continue;
3007
+ }
2942
3008
  let contentValue;
2943
3009
  switch (output.type) {
2944
3010
  case "text":
@@ -2946,7 +3012,7 @@ async function convertToOpenAIResponsesInput({
2946
3012
  contentValue = output.value;
2947
3013
  break;
2948
3014
  case "execution-denied":
2949
- contentValue = (_l = output.reason) != null ? _l : "Tool execution denied.";
3015
+ contentValue = (_m = output.reason) != null ? _m : "Tool execution denied.";
2950
3016
  break;
2951
3017
  case "json":
2952
3018
  case "error-json":
@@ -3161,6 +3227,13 @@ var openaiResponsesChunkSchema = (0, import_provider_utils23.lazySchema)(
3161
3227
  })
3162
3228
  ])
3163
3229
  }),
3230
+ import_v416.z.object({
3231
+ type: import_v416.z.literal("custom_tool_call"),
3232
+ id: import_v416.z.string(),
3233
+ call_id: import_v416.z.string(),
3234
+ name: import_v416.z.string(),
3235
+ input: import_v416.z.string()
3236
+ }),
3164
3237
  import_v416.z.object({
3165
3238
  type: import_v416.z.literal("shell_call"),
3166
3239
  id: import_v416.z.string(),
@@ -3213,6 +3286,14 @@ var openaiResponsesChunkSchema = (0, import_provider_utils23.lazySchema)(
3213
3286
  arguments: import_v416.z.string(),
3214
3287
  status: import_v416.z.literal("completed")
3215
3288
  }),
3289
+ import_v416.z.object({
3290
+ type: import_v416.z.literal("custom_tool_call"),
3291
+ id: import_v416.z.string(),
3292
+ call_id: import_v416.z.string(),
3293
+ name: import_v416.z.string(),
3294
+ input: import_v416.z.string(),
3295
+ status: import_v416.z.literal("completed")
3296
+ }),
3216
3297
  import_v416.z.object({
3217
3298
  type: import_v416.z.literal("code_interpreter_call"),
3218
3299
  id: import_v416.z.string(),
@@ -3396,6 +3477,12 @@ var openaiResponsesChunkSchema = (0, import_provider_utils23.lazySchema)(
3396
3477
  output_index: import_v416.z.number(),
3397
3478
  delta: import_v416.z.string()
3398
3479
  }),
3480
+ import_v416.z.object({
3481
+ type: import_v416.z.literal("response.custom_tool_call_input.delta"),
3482
+ item_id: import_v416.z.string(),
3483
+ output_index: import_v416.z.number(),
3484
+ delta: import_v416.z.string()
3485
+ }),
3399
3486
  import_v416.z.object({
3400
3487
  type: import_v416.z.literal("response.image_generation_call.partial_image"),
3401
3488
  item_id: import_v416.z.string(),
@@ -3643,6 +3730,13 @@ var openaiResponsesResponseSchema = (0, import_provider_utils23.lazySchema)(
3643
3730
  arguments: import_v416.z.string(),
3644
3731
  id: import_v416.z.string()
3645
3732
  }),
3733
+ import_v416.z.object({
3734
+ type: import_v416.z.literal("custom_tool_call"),
3735
+ call_id: import_v416.z.string(),
3736
+ name: import_v416.z.string(),
3737
+ input: import_v416.z.string(),
3738
+ id: import_v416.z.string()
3739
+ }),
3646
3740
  import_v416.z.object({
3647
3741
  type: import_v416.z.literal("computer_call"),
3648
3742
  id: import_v416.z.string(),
@@ -4002,7 +4096,7 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils24.lazy
4002
4096
 
4003
4097
  // src/responses/openai-responses-prepare-tools.ts
4004
4098
  var import_provider7 = require("@ai-sdk/provider");
4005
- var import_provider_utils31 = require("@ai-sdk/provider-utils");
4099
+ var import_provider_utils32 = require("@ai-sdk/provider-utils");
4006
4100
 
4007
4101
  // src/tool/code-interpreter.ts
4008
4102
  var import_provider_utils25 = require("@ai-sdk/provider-utils");
@@ -4132,127 +4226,103 @@ var imageGeneration = (args = {}) => {
4132
4226
  return imageGenerationToolFactory(args);
4133
4227
  };
4134
4228
 
4135
- // src/tool/mcp.ts
4229
+ // src/tool/custom.ts
4136
4230
  var import_provider_utils28 = require("@ai-sdk/provider-utils");
4137
4231
  var import_v421 = require("zod/v4");
4138
- var jsonValueSchema = import_v421.z.lazy(
4139
- () => import_v421.z.union([
4140
- import_v421.z.string(),
4141
- import_v421.z.number(),
4142
- import_v421.z.boolean(),
4143
- import_v421.z.null(),
4144
- import_v421.z.array(jsonValueSchema),
4145
- import_v421.z.record(import_v421.z.string(), jsonValueSchema)
4146
- ])
4147
- );
4148
- var mcpArgsSchema = (0, import_provider_utils28.lazySchema)(
4232
+ var customArgsSchema = (0, import_provider_utils28.lazySchema)(
4149
4233
  () => (0, import_provider_utils28.zodSchema)(
4150
4234
  import_v421.z.object({
4151
- serverLabel: import_v421.z.string(),
4152
- allowedTools: import_v421.z.union([
4153
- import_v421.z.array(import_v421.z.string()),
4235
+ name: import_v421.z.string(),
4236
+ description: import_v421.z.string().optional(),
4237
+ format: import_v421.z.union([
4154
4238
  import_v421.z.object({
4155
- readOnly: import_v421.z.boolean().optional(),
4156
- toolNames: import_v421.z.array(import_v421.z.string()).optional()
4157
- })
4158
- ]).optional(),
4159
- authorization: import_v421.z.string().optional(),
4160
- connectorId: import_v421.z.string().optional(),
4161
- headers: import_v421.z.record(import_v421.z.string(), import_v421.z.string()).optional(),
4162
- requireApproval: import_v421.z.union([
4163
- import_v421.z.enum(["always", "never"]),
4239
+ type: import_v421.z.literal("grammar"),
4240
+ syntax: import_v421.z.enum(["regex", "lark"]),
4241
+ definition: import_v421.z.string()
4242
+ }),
4164
4243
  import_v421.z.object({
4165
- never: import_v421.z.object({
4166
- toolNames: import_v421.z.array(import_v421.z.string()).optional()
4167
- }).optional()
4244
+ type: import_v421.z.literal("text")
4168
4245
  })
4169
- ]).optional(),
4170
- serverDescription: import_v421.z.string().optional(),
4171
- serverUrl: import_v421.z.string().optional()
4172
- }).refine(
4173
- (v) => v.serverUrl != null || v.connectorId != null,
4174
- "One of serverUrl or connectorId must be provided."
4175
- )
4176
- )
4177
- );
4178
- var mcpInputSchema = (0, import_provider_utils28.lazySchema)(() => (0, import_provider_utils28.zodSchema)(import_v421.z.object({})));
4179
- var mcpOutputSchema = (0, import_provider_utils28.lazySchema)(
4180
- () => (0, import_provider_utils28.zodSchema)(
4181
- import_v421.z.object({
4182
- type: import_v421.z.literal("call"),
4183
- serverLabel: import_v421.z.string(),
4184
- name: import_v421.z.string(),
4185
- arguments: import_v421.z.string(),
4186
- output: import_v421.z.string().nullish(),
4187
- error: import_v421.z.union([import_v421.z.string(), jsonValueSchema]).optional()
4246
+ ]).optional()
4188
4247
  })
4189
4248
  )
4190
4249
  );
4191
- var mcpToolFactory = (0, import_provider_utils28.createProviderToolFactoryWithOutputSchema)({
4192
- id: "openai.mcp",
4193
- inputSchema: mcpInputSchema,
4194
- outputSchema: mcpOutputSchema
4250
+ var customInputSchema = (0, import_provider_utils28.lazySchema)(() => (0, import_provider_utils28.zodSchema)(import_v421.z.string()));
4251
+ var customToolFactory = (0, import_provider_utils28.createProviderToolFactory)({
4252
+ id: "openai.custom",
4253
+ inputSchema: customInputSchema
4195
4254
  });
4196
4255
 
4197
- // src/tool/web-search.ts
4256
+ // src/tool/mcp.ts
4198
4257
  var import_provider_utils29 = require("@ai-sdk/provider-utils");
4199
4258
  var import_v422 = require("zod/v4");
4200
- var webSearchArgsSchema = (0, import_provider_utils29.lazySchema)(
4201
- () => (0, import_provider_utils29.zodSchema)(
4202
- import_v422.z.object({
4203
- externalWebAccess: import_v422.z.boolean().optional(),
4204
- filters: import_v422.z.object({ allowedDomains: import_v422.z.array(import_v422.z.string()).optional() }).optional(),
4205
- searchContextSize: import_v422.z.enum(["low", "medium", "high"]).optional(),
4206
- userLocation: import_v422.z.object({
4207
- type: import_v422.z.literal("approximate"),
4208
- country: import_v422.z.string().optional(),
4209
- city: import_v422.z.string().optional(),
4210
- region: import_v422.z.string().optional(),
4211
- timezone: import_v422.z.string().optional()
4212
- }).optional()
4213
- })
4214
- )
4259
+ var jsonValueSchema = import_v422.z.lazy(
4260
+ () => import_v422.z.union([
4261
+ import_v422.z.string(),
4262
+ import_v422.z.number(),
4263
+ import_v422.z.boolean(),
4264
+ import_v422.z.null(),
4265
+ import_v422.z.array(jsonValueSchema),
4266
+ import_v422.z.record(import_v422.z.string(), jsonValueSchema)
4267
+ ])
4215
4268
  );
4216
- var webSearchInputSchema = (0, import_provider_utils29.lazySchema)(() => (0, import_provider_utils29.zodSchema)(import_v422.z.object({})));
4217
- var webSearchOutputSchema = (0, import_provider_utils29.lazySchema)(
4269
+ var mcpArgsSchema = (0, import_provider_utils29.lazySchema)(
4218
4270
  () => (0, import_provider_utils29.zodSchema)(
4219
4271
  import_v422.z.object({
4220
- action: import_v422.z.discriminatedUnion("type", [
4221
- import_v422.z.object({
4222
- type: import_v422.z.literal("search"),
4223
- query: import_v422.z.string().optional()
4224
- }),
4272
+ serverLabel: import_v422.z.string(),
4273
+ allowedTools: import_v422.z.union([
4274
+ import_v422.z.array(import_v422.z.string()),
4225
4275
  import_v422.z.object({
4226
- type: import_v422.z.literal("openPage"),
4227
- url: import_v422.z.string().nullish()
4228
- }),
4276
+ readOnly: import_v422.z.boolean().optional(),
4277
+ toolNames: import_v422.z.array(import_v422.z.string()).optional()
4278
+ })
4279
+ ]).optional(),
4280
+ authorization: import_v422.z.string().optional(),
4281
+ connectorId: import_v422.z.string().optional(),
4282
+ headers: import_v422.z.record(import_v422.z.string(), import_v422.z.string()).optional(),
4283
+ requireApproval: import_v422.z.union([
4284
+ import_v422.z.enum(["always", "never"]),
4229
4285
  import_v422.z.object({
4230
- type: import_v422.z.literal("findInPage"),
4231
- url: import_v422.z.string().nullish(),
4232
- pattern: import_v422.z.string().nullish()
4286
+ never: import_v422.z.object({
4287
+ toolNames: import_v422.z.array(import_v422.z.string()).optional()
4288
+ }).optional()
4233
4289
  })
4234
4290
  ]).optional(),
4235
- sources: import_v422.z.array(
4236
- import_v422.z.discriminatedUnion("type", [
4237
- import_v422.z.object({ type: import_v422.z.literal("url"), url: import_v422.z.string() }),
4238
- import_v422.z.object({ type: import_v422.z.literal("api"), name: import_v422.z.string() })
4239
- ])
4240
- ).optional()
4291
+ serverDescription: import_v422.z.string().optional(),
4292
+ serverUrl: import_v422.z.string().optional()
4293
+ }).refine(
4294
+ (v) => v.serverUrl != null || v.connectorId != null,
4295
+ "One of serverUrl or connectorId must be provided."
4296
+ )
4297
+ )
4298
+ );
4299
+ var mcpInputSchema = (0, import_provider_utils29.lazySchema)(() => (0, import_provider_utils29.zodSchema)(import_v422.z.object({})));
4300
+ var mcpOutputSchema = (0, import_provider_utils29.lazySchema)(
4301
+ () => (0, import_provider_utils29.zodSchema)(
4302
+ import_v422.z.object({
4303
+ type: import_v422.z.literal("call"),
4304
+ serverLabel: import_v422.z.string(),
4305
+ name: import_v422.z.string(),
4306
+ arguments: import_v422.z.string(),
4307
+ output: import_v422.z.string().nullish(),
4308
+ error: import_v422.z.union([import_v422.z.string(), jsonValueSchema]).optional()
4241
4309
  })
4242
4310
  )
4243
4311
  );
4244
- var webSearchToolFactory = (0, import_provider_utils29.createProviderToolFactoryWithOutputSchema)({
4245
- id: "openai.web_search",
4246
- inputSchema: webSearchInputSchema,
4247
- outputSchema: webSearchOutputSchema
4312
+ var mcpToolFactory = (0, import_provider_utils29.createProviderToolFactoryWithOutputSchema)({
4313
+ id: "openai.mcp",
4314
+ inputSchema: mcpInputSchema,
4315
+ outputSchema: mcpOutputSchema
4248
4316
  });
4249
4317
 
4250
- // src/tool/web-search-preview.ts
4318
+ // src/tool/web-search.ts
4251
4319
  var import_provider_utils30 = require("@ai-sdk/provider-utils");
4252
4320
  var import_v423 = require("zod/v4");
4253
- var webSearchPreviewArgsSchema = (0, import_provider_utils30.lazySchema)(
4321
+ var webSearchArgsSchema = (0, import_provider_utils30.lazySchema)(
4254
4322
  () => (0, import_provider_utils30.zodSchema)(
4255
4323
  import_v423.z.object({
4324
+ externalWebAccess: import_v423.z.boolean().optional(),
4325
+ filters: import_v423.z.object({ allowedDomains: import_v423.z.array(import_v423.z.string()).optional() }).optional(),
4256
4326
  searchContextSize: import_v423.z.enum(["low", "medium", "high"]).optional(),
4257
4327
  userLocation: import_v423.z.object({
4258
4328
  type: import_v423.z.literal("approximate"),
@@ -4264,10 +4334,8 @@ var webSearchPreviewArgsSchema = (0, import_provider_utils30.lazySchema)(
4264
4334
  })
4265
4335
  )
4266
4336
  );
4267
- var webSearchPreviewInputSchema = (0, import_provider_utils30.lazySchema)(
4268
- () => (0, import_provider_utils30.zodSchema)(import_v423.z.object({}))
4269
- );
4270
- var webSearchPreviewOutputSchema = (0, import_provider_utils30.lazySchema)(
4337
+ var webSearchInputSchema = (0, import_provider_utils30.lazySchema)(() => (0, import_provider_utils30.zodSchema)(import_v423.z.object({})));
4338
+ var webSearchOutputSchema = (0, import_provider_utils30.lazySchema)(
4271
4339
  () => (0, import_provider_utils30.zodSchema)(
4272
4340
  import_v423.z.object({
4273
4341
  action: import_v423.z.discriminatedUnion("type", [
@@ -4284,11 +4352,64 @@ var webSearchPreviewOutputSchema = (0, import_provider_utils30.lazySchema)(
4284
4352
  url: import_v423.z.string().nullish(),
4285
4353
  pattern: import_v423.z.string().nullish()
4286
4354
  })
4355
+ ]).optional(),
4356
+ sources: import_v423.z.array(
4357
+ import_v423.z.discriminatedUnion("type", [
4358
+ import_v423.z.object({ type: import_v423.z.literal("url"), url: import_v423.z.string() }),
4359
+ import_v423.z.object({ type: import_v423.z.literal("api"), name: import_v423.z.string() })
4360
+ ])
4361
+ ).optional()
4362
+ })
4363
+ )
4364
+ );
4365
+ var webSearchToolFactory = (0, import_provider_utils30.createProviderToolFactoryWithOutputSchema)({
4366
+ id: "openai.web_search",
4367
+ inputSchema: webSearchInputSchema,
4368
+ outputSchema: webSearchOutputSchema
4369
+ });
4370
+
4371
+ // src/tool/web-search-preview.ts
4372
+ var import_provider_utils31 = require("@ai-sdk/provider-utils");
4373
+ var import_v424 = require("zod/v4");
4374
+ var webSearchPreviewArgsSchema = (0, import_provider_utils31.lazySchema)(
4375
+ () => (0, import_provider_utils31.zodSchema)(
4376
+ import_v424.z.object({
4377
+ searchContextSize: import_v424.z.enum(["low", "medium", "high"]).optional(),
4378
+ userLocation: import_v424.z.object({
4379
+ type: import_v424.z.literal("approximate"),
4380
+ country: import_v424.z.string().optional(),
4381
+ city: import_v424.z.string().optional(),
4382
+ region: import_v424.z.string().optional(),
4383
+ timezone: import_v424.z.string().optional()
4384
+ }).optional()
4385
+ })
4386
+ )
4387
+ );
4388
+ var webSearchPreviewInputSchema = (0, import_provider_utils31.lazySchema)(
4389
+ () => (0, import_provider_utils31.zodSchema)(import_v424.z.object({}))
4390
+ );
4391
+ var webSearchPreviewOutputSchema = (0, import_provider_utils31.lazySchema)(
4392
+ () => (0, import_provider_utils31.zodSchema)(
4393
+ import_v424.z.object({
4394
+ action: import_v424.z.discriminatedUnion("type", [
4395
+ import_v424.z.object({
4396
+ type: import_v424.z.literal("search"),
4397
+ query: import_v424.z.string().optional()
4398
+ }),
4399
+ import_v424.z.object({
4400
+ type: import_v424.z.literal("openPage"),
4401
+ url: import_v424.z.string().nullish()
4402
+ }),
4403
+ import_v424.z.object({
4404
+ type: import_v424.z.literal("findInPage"),
4405
+ url: import_v424.z.string().nullish(),
4406
+ pattern: import_v424.z.string().nullish()
4407
+ })
4287
4408
  ]).optional()
4288
4409
  })
4289
4410
  )
4290
4411
  );
4291
- var webSearchPreview = (0, import_provider_utils30.createProviderToolFactoryWithOutputSchema)({
4412
+ var webSearchPreview = (0, import_provider_utils31.createProviderToolFactoryWithOutputSchema)({
4292
4413
  id: "openai.web_search_preview",
4293
4414
  inputSchema: webSearchPreviewInputSchema,
4294
4415
  outputSchema: webSearchPreviewOutputSchema
@@ -4297,14 +4418,18 @@ var webSearchPreview = (0, import_provider_utils30.createProviderToolFactoryWith
4297
4418
  // src/responses/openai-responses-prepare-tools.ts
4298
4419
  async function prepareResponsesTools({
4299
4420
  tools,
4300
- toolChoice
4421
+ toolChoice,
4422
+ toolNameMapping,
4423
+ customProviderToolNames
4301
4424
  }) {
4425
+ var _a;
4302
4426
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
4303
4427
  const toolWarnings = [];
4304
4428
  if (tools == null) {
4305
4429
  return { tools: void 0, toolChoice: void 0, toolWarnings };
4306
4430
  }
4307
4431
  const openaiTools = [];
4432
+ const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
4308
4433
  for (const tool of tools) {
4309
4434
  switch (tool.type) {
4310
4435
  case "function":
@@ -4319,7 +4444,7 @@ async function prepareResponsesTools({
4319
4444
  case "provider": {
4320
4445
  switch (tool.id) {
4321
4446
  case "openai.file_search": {
4322
- const args = await (0, import_provider_utils31.validateTypes)({
4447
+ const args = await (0, import_provider_utils32.validateTypes)({
4323
4448
  value: tool.args,
4324
4449
  schema: fileSearchArgsSchema
4325
4450
  });
@@ -4342,7 +4467,7 @@ async function prepareResponsesTools({
4342
4467
  break;
4343
4468
  }
4344
4469
  case "openai.shell": {
4345
- const args = await (0, import_provider_utils31.validateTypes)({
4470
+ const args = await (0, import_provider_utils32.validateTypes)({
4346
4471
  value: tool.args,
4347
4472
  schema: shellArgsSchema
4348
4473
  });
@@ -4361,7 +4486,7 @@ async function prepareResponsesTools({
4361
4486
  break;
4362
4487
  }
4363
4488
  case "openai.web_search_preview": {
4364
- const args = await (0, import_provider_utils31.validateTypes)({
4489
+ const args = await (0, import_provider_utils32.validateTypes)({
4365
4490
  value: tool.args,
4366
4491
  schema: webSearchPreviewArgsSchema
4367
4492
  });
@@ -4373,7 +4498,7 @@ async function prepareResponsesTools({
4373
4498
  break;
4374
4499
  }
4375
4500
  case "openai.web_search": {
4376
- const args = await (0, import_provider_utils31.validateTypes)({
4501
+ const args = await (0, import_provider_utils32.validateTypes)({
4377
4502
  value: tool.args,
4378
4503
  schema: webSearchArgsSchema
4379
4504
  });
@@ -4387,7 +4512,7 @@ async function prepareResponsesTools({
4387
4512
  break;
4388
4513
  }
4389
4514
  case "openai.code_interpreter": {
4390
- const args = await (0, import_provider_utils31.validateTypes)({
4515
+ const args = await (0, import_provider_utils32.validateTypes)({
4391
4516
  value: tool.args,
4392
4517
  schema: codeInterpreterArgsSchema
4393
4518
  });
@@ -4398,7 +4523,7 @@ async function prepareResponsesTools({
4398
4523
  break;
4399
4524
  }
4400
4525
  case "openai.image_generation": {
4401
- const args = await (0, import_provider_utils31.validateTypes)({
4526
+ const args = await (0, import_provider_utils32.validateTypes)({
4402
4527
  value: tool.args,
4403
4528
  schema: imageGenerationArgsSchema
4404
4529
  });
@@ -4421,7 +4546,7 @@ async function prepareResponsesTools({
4421
4546
  break;
4422
4547
  }
4423
4548
  case "openai.mcp": {
4424
- const args = await (0, import_provider_utils31.validateTypes)({
4549
+ const args = await (0, import_provider_utils32.validateTypes)({
4425
4550
  value: tool.args,
4426
4551
  schema: mcpArgsSchema
4427
4552
  });
@@ -4446,6 +4571,20 @@ async function prepareResponsesTools({
4446
4571
  });
4447
4572
  break;
4448
4573
  }
4574
+ case "openai.custom": {
4575
+ const args = await (0, import_provider_utils32.validateTypes)({
4576
+ value: tool.args,
4577
+ schema: customArgsSchema
4578
+ });
4579
+ openaiTools.push({
4580
+ type: "custom",
4581
+ name: args.name,
4582
+ description: args.description,
4583
+ format: args.format
4584
+ });
4585
+ resolvedCustomProviderToolNames.add(args.name);
4586
+ break;
4587
+ }
4449
4588
  }
4450
4589
  break;
4451
4590
  }
@@ -4466,12 +4605,14 @@ async function prepareResponsesTools({
4466
4605
  case "none":
4467
4606
  case "required":
4468
4607
  return { tools: openaiTools, toolChoice: type, toolWarnings };
4469
- case "tool":
4608
+ case "tool": {
4609
+ const resolvedToolName = (_a = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _a : toolChoice.toolName;
4470
4610
  return {
4471
4611
  tools: openaiTools,
4472
- toolChoice: toolChoice.toolName === "code_interpreter" || toolChoice.toolName === "file_search" || toolChoice.toolName === "image_generation" || toolChoice.toolName === "web_search_preview" || toolChoice.toolName === "web_search" || toolChoice.toolName === "mcp" || toolChoice.toolName === "apply_patch" ? { type: toolChoice.toolName } : { type: "function", name: toolChoice.toolName },
4612
+ toolChoice: resolvedToolName === "code_interpreter" || resolvedToolName === "file_search" || resolvedToolName === "image_generation" || resolvedToolName === "web_search_preview" || resolvedToolName === "web_search" || resolvedToolName === "mcp" || resolvedToolName === "apply_patch" ? { type: resolvedToolName } : resolvedCustomProviderToolNames.has(resolvedToolName) ? { type: "custom", name: resolvedToolName } : { type: "function", name: resolvedToolName },
4473
4613
  toolWarnings
4474
4614
  };
4615
+ }
4475
4616
  default: {
4476
4617
  const _exhaustiveCheck = type;
4477
4618
  throw new import_provider7.UnsupportedFunctionalityError({
@@ -4590,13 +4731,13 @@ var OpenAIResponsesLanguageModel = class {
4590
4731
  warnings.push({ type: "unsupported", feature: "stopSequences" });
4591
4732
  }
4592
4733
  const providerOptionsName = this.config.provider.includes("azure") ? "azure" : "openai";
4593
- let openaiOptions = await (0, import_provider_utils32.parseProviderOptions)({
4734
+ let openaiOptions = await (0, import_provider_utils33.parseProviderOptions)({
4594
4735
  provider: providerOptionsName,
4595
4736
  providerOptions,
4596
4737
  schema: openaiLanguageModelResponsesOptionsSchema
4597
4738
  });
4598
4739
  if (openaiOptions == null && providerOptionsName !== "openai") {
4599
- openaiOptions = await (0, import_provider_utils32.parseProviderOptions)({
4740
+ openaiOptions = await (0, import_provider_utils33.parseProviderOptions)({
4600
4741
  provider: "openai",
4601
4742
  providerOptions,
4602
4743
  schema: openaiLanguageModelResponsesOptionsSchema
@@ -4610,7 +4751,7 @@ var OpenAIResponsesLanguageModel = class {
4610
4751
  details: "conversation and previousResponseId cannot be used together"
4611
4752
  });
4612
4753
  }
4613
- const toolNameMapping = (0, import_provider_utils32.createToolNameMapping)({
4754
+ const toolNameMapping = (0, import_provider_utils33.createToolNameMapping)({
4614
4755
  tools,
4615
4756
  providerToolNames: {
4616
4757
  "openai.code_interpreter": "code_interpreter",
@@ -4622,7 +4763,19 @@ var OpenAIResponsesLanguageModel = class {
4622
4763
  "openai.web_search_preview": "web_search_preview",
4623
4764
  "openai.mcp": "mcp",
4624
4765
  "openai.apply_patch": "apply_patch"
4625
- }
4766
+ },
4767
+ resolveProviderToolName: (tool) => tool.id === "openai.custom" ? tool.args.name : void 0
4768
+ });
4769
+ const customProviderToolNames = /* @__PURE__ */ new Set();
4770
+ const {
4771
+ tools: openaiTools,
4772
+ toolChoice: openaiToolChoice,
4773
+ toolWarnings
4774
+ } = await prepareResponsesTools({
4775
+ tools,
4776
+ toolChoice,
4777
+ toolNameMapping,
4778
+ customProviderToolNames
4626
4779
  });
4627
4780
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
4628
4781
  prompt,
@@ -4634,7 +4787,8 @@ var OpenAIResponsesLanguageModel = class {
4634
4787
  hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
4635
4788
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
4636
4789
  hasShellTool: hasOpenAITool("openai.shell"),
4637
- hasApplyPatchTool: hasOpenAITool("openai.apply_patch")
4790
+ hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
4791
+ customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
4638
4792
  });
4639
4793
  warnings.push(...inputWarnings);
4640
4794
  const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
@@ -4767,14 +4921,6 @@ var OpenAIResponsesLanguageModel = class {
4767
4921
  });
4768
4922
  delete baseArgs.service_tier;
4769
4923
  }
4770
- const {
4771
- tools: openaiTools,
4772
- toolChoice: openaiToolChoice,
4773
- toolWarnings
4774
- } = await prepareResponsesTools({
4775
- tools,
4776
- toolChoice
4777
- });
4778
4924
  const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
4779
4925
  (tool) => tool.type === "provider" && tool.id === "openai.shell"
4780
4926
  )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
@@ -4812,12 +4958,12 @@ var OpenAIResponsesLanguageModel = class {
4812
4958
  responseHeaders,
4813
4959
  value: response,
4814
4960
  rawValue: rawResponse
4815
- } = await (0, import_provider_utils32.postJsonToApi)({
4961
+ } = await (0, import_provider_utils33.postJsonToApi)({
4816
4962
  url,
4817
- headers: (0, import_provider_utils32.combineHeaders)(this.config.headers(), options.headers),
4963
+ headers: (0, import_provider_utils33.combineHeaders)(this.config.headers(), options.headers),
4818
4964
  body,
4819
4965
  failedResponseHandler: openaiFailedResponseHandler,
4820
- successfulResponseHandler: (0, import_provider_utils32.createJsonResponseHandler)(
4966
+ successfulResponseHandler: (0, import_provider_utils33.createJsonResponseHandler)(
4821
4967
  openaiResponsesResponseSchema
4822
4968
  ),
4823
4969
  abortSignal: options.abortSignal,
@@ -4952,7 +5098,7 @@ var OpenAIResponsesLanguageModel = class {
4952
5098
  content.push({
4953
5099
  type: "source",
4954
5100
  sourceType: "url",
4955
- id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : (0, import_provider_utils32.generateId)(),
5101
+ id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : (0, import_provider_utils33.generateId)(),
4956
5102
  url: annotation.url,
4957
5103
  title: annotation.title
4958
5104
  });
@@ -4960,7 +5106,7 @@ var OpenAIResponsesLanguageModel = class {
4960
5106
  content.push({
4961
5107
  type: "source",
4962
5108
  sourceType: "document",
4963
- id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : (0, import_provider_utils32.generateId)(),
5109
+ id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : (0, import_provider_utils33.generateId)(),
4964
5110
  mediaType: "text/plain",
4965
5111
  title: annotation.filename,
4966
5112
  filename: annotation.filename,
@@ -4976,7 +5122,7 @@ var OpenAIResponsesLanguageModel = class {
4976
5122
  content.push({
4977
5123
  type: "source",
4978
5124
  sourceType: "document",
4979
- id: (_l = (_k = (_j = this.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : (0, import_provider_utils32.generateId)(),
5125
+ id: (_l = (_k = (_j = this.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : (0, import_provider_utils33.generateId)(),
4980
5126
  mediaType: "text/plain",
4981
5127
  title: annotation.filename,
4982
5128
  filename: annotation.filename,
@@ -4992,7 +5138,7 @@ var OpenAIResponsesLanguageModel = class {
4992
5138
  content.push({
4993
5139
  type: "source",
4994
5140
  sourceType: "document",
4995
- id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0, import_provider_utils32.generateId)(),
5141
+ id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0, import_provider_utils33.generateId)(),
4996
5142
  mediaType: "application/octet-stream",
4997
5143
  title: annotation.file_id,
4998
5144
  filename: annotation.file_id,
@@ -5024,6 +5170,22 @@ var OpenAIResponsesLanguageModel = class {
5024
5170
  });
5025
5171
  break;
5026
5172
  }
5173
+ case "custom_tool_call": {
5174
+ hasFunctionCall = true;
5175
+ const toolName = toolNameMapping.toCustomToolName(part.name);
5176
+ content.push({
5177
+ type: "tool-call",
5178
+ toolCallId: part.call_id,
5179
+ toolName,
5180
+ input: JSON.stringify(part.input),
5181
+ providerMetadata: {
5182
+ [providerOptionsName]: {
5183
+ itemId: part.id
5184
+ }
5185
+ }
5186
+ });
5187
+ break;
5188
+ }
5027
5189
  case "web_search_call": {
5028
5190
  content.push({
5029
5191
  type: "tool-call",
@@ -5080,7 +5242,7 @@ var OpenAIResponsesLanguageModel = class {
5080
5242
  }
5081
5243
  case "mcp_approval_request": {
5082
5244
  const approvalRequestId = (_q = part.approval_request_id) != null ? _q : part.id;
5083
- const dummyToolCallId = (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : (0, import_provider_utils32.generateId)();
5245
+ const dummyToolCallId = (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : (0, import_provider_utils33.generateId)();
5084
5246
  const toolName = `mcp.${part.name}`;
5085
5247
  content.push({
5086
5248
  type: "tool-call",
@@ -5221,18 +5383,18 @@ var OpenAIResponsesLanguageModel = class {
5221
5383
  providerOptionsName,
5222
5384
  isShellProviderExecuted
5223
5385
  } = await this.getArgs(options);
5224
- const { responseHeaders, value: response } = await (0, import_provider_utils32.postJsonToApi)({
5386
+ const { responseHeaders, value: response } = await (0, import_provider_utils33.postJsonToApi)({
5225
5387
  url: this.config.url({
5226
5388
  path: "/responses",
5227
5389
  modelId: this.modelId
5228
5390
  }),
5229
- headers: (0, import_provider_utils32.combineHeaders)(this.config.headers(), options.headers),
5391
+ headers: (0, import_provider_utils33.combineHeaders)(this.config.headers(), options.headers),
5230
5392
  body: {
5231
5393
  ...body,
5232
5394
  stream: true
5233
5395
  },
5234
5396
  failedResponseHandler: openaiFailedResponseHandler,
5235
- successfulResponseHandler: (0, import_provider_utils32.createEventSourceResponseHandler)(
5397
+ successfulResponseHandler: (0, import_provider_utils33.createEventSourceResponseHandler)(
5236
5398
  openaiResponsesChunkSchema
5237
5399
  ),
5238
5400
  abortSignal: options.abortSignal,
@@ -5282,6 +5444,19 @@ var OpenAIResponsesLanguageModel = class {
5282
5444
  id: value.item.call_id,
5283
5445
  toolName: value.item.name
5284
5446
  });
5447
+ } else if (value.item.type === "custom_tool_call") {
5448
+ const toolName = toolNameMapping.toCustomToolName(
5449
+ value.item.name
5450
+ );
5451
+ ongoingToolCalls[value.output_index] = {
5452
+ toolName,
5453
+ toolCallId: value.item.call_id
5454
+ };
5455
+ controller.enqueue({
5456
+ type: "tool-input-start",
5457
+ id: value.item.call_id,
5458
+ toolName
5459
+ });
5285
5460
  } else if (value.item.type === "web_search_call") {
5286
5461
  ongoingToolCalls[value.output_index] = {
5287
5462
  toolName: toolNameMapping.toCustomToolName(
@@ -5466,6 +5641,27 @@ var OpenAIResponsesLanguageModel = class {
5466
5641
  }
5467
5642
  }
5468
5643
  });
5644
+ } else if (value.item.type === "custom_tool_call") {
5645
+ ongoingToolCalls[value.output_index] = void 0;
5646
+ hasFunctionCall = true;
5647
+ const toolName = toolNameMapping.toCustomToolName(
5648
+ value.item.name
5649
+ );
5650
+ controller.enqueue({
5651
+ type: "tool-input-end",
5652
+ id: value.item.call_id
5653
+ });
5654
+ controller.enqueue({
5655
+ type: "tool-call",
5656
+ toolCallId: value.item.call_id,
5657
+ toolName,
5658
+ input: JSON.stringify(value.item.input),
5659
+ providerMetadata: {
5660
+ [providerOptionsName]: {
5661
+ itemId: value.item.id
5662
+ }
5663
+ }
5664
+ });
5469
5665
  } else if (value.item.type === "web_search_call") {
5470
5666
  ongoingToolCalls[value.output_index] = void 0;
5471
5667
  controller.enqueue({
@@ -5609,7 +5805,7 @@ var OpenAIResponsesLanguageModel = class {
5609
5805
  ongoingToolCalls[value.output_index] = void 0;
5610
5806
  } else if (value.item.type === "mcp_approval_request") {
5611
5807
  ongoingToolCalls[value.output_index] = void 0;
5612
- const dummyToolCallId = (_k = (_j = (_i = self.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : (0, import_provider_utils32.generateId)();
5808
+ const dummyToolCallId = (_k = (_j = (_i = self.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : (0, import_provider_utils33.generateId)();
5613
5809
  const approvalRequestId = (_l = value.item.approval_request_id) != null ? _l : value.item.id;
5614
5810
  approvalRequestIdToDummyToolCallIdFromStream.set(
5615
5811
  approvalRequestId,
@@ -5715,6 +5911,15 @@ var OpenAIResponsesLanguageModel = class {
5715
5911
  delta: value.delta
5716
5912
  });
5717
5913
  }
5914
+ } else if (isResponseCustomToolCallInputDeltaChunk(value)) {
5915
+ const toolCall = ongoingToolCalls[value.output_index];
5916
+ if (toolCall != null) {
5917
+ controller.enqueue({
5918
+ type: "tool-input-delta",
5919
+ id: toolCall.toolCallId,
5920
+ delta: value.delta
5921
+ });
5922
+ }
5718
5923
  } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
5719
5924
  const toolCall = ongoingToolCalls[value.output_index];
5720
5925
  if (toolCall == null ? void 0 : toolCall.applyPatch) {
@@ -5881,7 +6086,7 @@ var OpenAIResponsesLanguageModel = class {
5881
6086
  controller.enqueue({
5882
6087
  type: "source",
5883
6088
  sourceType: "url",
5884
- id: (_w = (_v = (_u = self.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : (0, import_provider_utils32.generateId)(),
6089
+ id: (_w = (_v = (_u = self.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : (0, import_provider_utils33.generateId)(),
5885
6090
  url: value.annotation.url,
5886
6091
  title: value.annotation.title
5887
6092
  });
@@ -5889,7 +6094,7 @@ var OpenAIResponsesLanguageModel = class {
5889
6094
  controller.enqueue({
5890
6095
  type: "source",
5891
6096
  sourceType: "document",
5892
- id: (_z = (_y = (_x = self.config).generateId) == null ? void 0 : _y.call(_x)) != null ? _z : (0, import_provider_utils32.generateId)(),
6097
+ id: (_z = (_y = (_x = self.config).generateId) == null ? void 0 : _y.call(_x)) != null ? _z : (0, import_provider_utils33.generateId)(),
5893
6098
  mediaType: "text/plain",
5894
6099
  title: value.annotation.filename,
5895
6100
  filename: value.annotation.filename,
@@ -5905,7 +6110,7 @@ var OpenAIResponsesLanguageModel = class {
5905
6110
  controller.enqueue({
5906
6111
  type: "source",
5907
6112
  sourceType: "document",
5908
- id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : (0, import_provider_utils32.generateId)(),
6113
+ id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : (0, import_provider_utils33.generateId)(),
5909
6114
  mediaType: "text/plain",
5910
6115
  title: value.annotation.filename,
5911
6116
  filename: value.annotation.filename,
@@ -5921,7 +6126,7 @@ var OpenAIResponsesLanguageModel = class {
5921
6126
  controller.enqueue({
5922
6127
  type: "source",
5923
6128
  sourceType: "document",
5924
- id: (_F = (_E = (_D = self.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : (0, import_provider_utils32.generateId)(),
6129
+ id: (_F = (_E = (_D = self.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : (0, import_provider_utils33.generateId)(),
5925
6130
  mediaType: "application/octet-stream",
5926
6131
  title: value.annotation.file_id,
5927
6132
  filename: value.annotation.file_id,
@@ -5975,6 +6180,9 @@ function isResponseCreatedChunk(chunk) {
5975
6180
  function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
5976
6181
  return chunk.type === "response.function_call_arguments.delta";
5977
6182
  }
6183
+ function isResponseCustomToolCallInputDeltaChunk(chunk) {
6184
+ return chunk.type === "response.custom_tool_call_input.delta";
6185
+ }
5978
6186
  function isResponseImageGenerationCallPartialImageChunk(chunk) {
5979
6187
  return chunk.type === "response.image_generation_call.partial_image";
5980
6188
  }