@ai-sdk/openai 3.0.97 → 3.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.mjs CHANGED
@@ -3074,9 +3074,228 @@ import {
3074
3074
  validateTypes
3075
3075
  } from "@ai-sdk/provider-utils";
3076
3076
  import { z as z21 } from "zod/v4";
3077
+
3078
+ // src/responses/expand-parallel-tool-call.ts
3079
+ import {
3080
+ isJSONObject
3081
+ } from "@ai-sdk/provider";
3082
+ import { safeParseJSON } from "@ai-sdk/provider-utils";
3083
+ var parallelToolName = "parallel";
3084
+ var recipientNamePrefix = "functions.";
3085
+ function getParallelToolCallMetadata({
3086
+ providerOptions,
3087
+ providerOptionsName
3088
+ }) {
3089
+ var _a;
3090
+ const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
3091
+ if (!isJSONObject(metadata) || typeof metadata.itemId !== "string" || typeof metadata.toolCallId !== "string" || typeof metadata.toolName !== "string" || typeof metadata.input !== "string" || typeof metadata.index !== "number" || !Number.isInteger(metadata.index) || typeof metadata.count !== "number" || !Number.isInteger(metadata.count) || metadata.index < 0 || metadata.count <= metadata.index) {
3092
+ return void 0;
3093
+ }
3094
+ return metadata;
3095
+ }
3096
+ function isUndeclaredParallelToolCall({
3097
+ toolName,
3098
+ tools
3099
+ }) {
3100
+ return toolName === parallelToolName && !tools.some((tool) => tool.name === parallelToolName);
3101
+ }
3102
+ async function expandParallelToolCall({
3103
+ toolCall,
3104
+ tools,
3105
+ providerOptionsName,
3106
+ itemId
3107
+ }) {
3108
+ if (!isUndeclaredParallelToolCall({ toolName: toolCall.toolName, tools })) {
3109
+ return void 0;
3110
+ }
3111
+ const parsedInput = await safeParseJSON({ text: toolCall.input });
3112
+ if (!parsedInput.success || !isJSONObject(parsedInput.value)) {
3113
+ return void 0;
3114
+ }
3115
+ const toolUses = parsedInput.value.tool_uses;
3116
+ if (!Array.isArray(toolUses) || toolUses.length === 0) {
3117
+ return void 0;
3118
+ }
3119
+ const availableToolNames = new Set(tools.map((tool) => tool.name));
3120
+ const expandedToolCalls = [];
3121
+ for (const [index, toolUse] of toolUses.entries()) {
3122
+ if (!isJSONObject(toolUse)) {
3123
+ return void 0;
3124
+ }
3125
+ const recipientName = toolUse.recipient_name;
3126
+ const parameters = toolUse.parameters;
3127
+ if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !isJSONObject(parameters)) {
3128
+ return void 0;
3129
+ }
3130
+ const toolName = recipientName.slice(recipientNamePrefix.length);
3131
+ if (toolName.length === 0 || !availableToolNames.has(toolName)) {
3132
+ return void 0;
3133
+ }
3134
+ expandedToolCalls.push({
3135
+ type: "tool-call",
3136
+ toolCallId: `${toolCall.toolCallId}_${index}`,
3137
+ toolName,
3138
+ input: JSON.stringify(parameters),
3139
+ providerMetadata: {
3140
+ [providerOptionsName]: {
3141
+ parallelToolCall: {
3142
+ itemId,
3143
+ toolCallId: toolCall.toolCallId,
3144
+ toolName: toolCall.toolName,
3145
+ input: toolCall.input,
3146
+ index,
3147
+ count: toolUses.length
3148
+ }
3149
+ }
3150
+ }
3151
+ });
3152
+ }
3153
+ return expandedToolCalls;
3154
+ }
3155
+
3156
+ // src/responses/convert-to-openai-responses-input.ts
3077
3157
  function serializeToolCallArguments2(input) {
3078
3158
  return JSON.stringify(input === void 0 ? {} : input);
3079
3159
  }
3160
+ async function convertFunctionToolResultOutput({
3161
+ output,
3162
+ providerOptionsName,
3163
+ warnings
3164
+ }) {
3165
+ var _a;
3166
+ switch (output.type) {
3167
+ case "text":
3168
+ case "error-text":
3169
+ return output.value;
3170
+ case "execution-denied":
3171
+ return (_a = output.reason) != null ? _a : "Tool call execution denied.";
3172
+ case "json":
3173
+ case "error-json":
3174
+ return JSON.stringify(output.value);
3175
+ case "content":
3176
+ return output.value.map((item) => {
3177
+ var _a2, _b, _c, _d, _e;
3178
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3179
+ item.providerOptions,
3180
+ providerOptionsName
3181
+ );
3182
+ switch (item.type) {
3183
+ case "text": {
3184
+ return {
3185
+ type: "input_text",
3186
+ text: item.text,
3187
+ ...promptCacheBreakpoint != null && {
3188
+ prompt_cache_breakpoint: promptCacheBreakpoint
3189
+ }
3190
+ };
3191
+ }
3192
+ case "image-data": {
3193
+ return {
3194
+ type: "input_image",
3195
+ image_url: `data:${item.mediaType};base64,${item.data}`,
3196
+ detail: (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3197
+ ...promptCacheBreakpoint != null && {
3198
+ prompt_cache_breakpoint: promptCacheBreakpoint
3199
+ }
3200
+ };
3201
+ }
3202
+ case "image-url": {
3203
+ return {
3204
+ type: "input_image",
3205
+ image_url: item.url,
3206
+ detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
3207
+ ...promptCacheBreakpoint != null && {
3208
+ prompt_cache_breakpoint: promptCacheBreakpoint
3209
+ }
3210
+ };
3211
+ }
3212
+ case "file-data": {
3213
+ return {
3214
+ type: "input_file",
3215
+ filename: (_e = item.filename) != null ? _e : "data",
3216
+ file_data: `data:${item.mediaType};base64,${item.data}`,
3217
+ ...promptCacheBreakpoint != null && {
3218
+ prompt_cache_breakpoint: promptCacheBreakpoint
3219
+ }
3220
+ };
3221
+ }
3222
+ case "file-url": {
3223
+ return {
3224
+ type: "input_file",
3225
+ file_url: item.url,
3226
+ ...promptCacheBreakpoint != null && {
3227
+ prompt_cache_breakpoint: promptCacheBreakpoint
3228
+ }
3229
+ };
3230
+ }
3231
+ default: {
3232
+ warnings.push({
3233
+ type: "other",
3234
+ message: `unsupported tool content part type: ${item.type}`
3235
+ });
3236
+ return void 0;
3237
+ }
3238
+ }
3239
+ }).filter(isNonNullable);
3240
+ }
3241
+ }
3242
+ function hasSameParallelToolCall(first, second) {
3243
+ return first.itemId === second.itemId && first.toolCallId === second.toolCallId && first.toolName === second.toolName && first.input === second.input && first.count === second.count;
3244
+ }
3245
+ function collectCompleteParallelToolResultGroups({
3246
+ prompt,
3247
+ providerOptionsName
3248
+ }) {
3249
+ const pendingGroups = /* @__PURE__ */ new Map();
3250
+ for (const message of prompt) {
3251
+ if (message.role !== "tool") {
3252
+ continue;
3253
+ }
3254
+ for (const part of message.content) {
3255
+ if (part.type !== "tool-result") {
3256
+ continue;
3257
+ }
3258
+ const metadata = getParallelToolCallMetadata({
3259
+ providerOptions: part.providerOptions,
3260
+ providerOptionsName
3261
+ });
3262
+ if (metadata == null) {
3263
+ continue;
3264
+ }
3265
+ const existing = pendingGroups.get(metadata.toolCallId);
3266
+ if (existing == null) {
3267
+ pendingGroups.set(metadata.toolCallId, {
3268
+ metadata,
3269
+ results: /* @__PURE__ */ new Map([[metadata.index, part]]),
3270
+ invalid: false
3271
+ });
3272
+ continue;
3273
+ }
3274
+ if (!hasSameParallelToolCall(existing.metadata, metadata) || existing.results.has(metadata.index)) {
3275
+ existing.invalid = true;
3276
+ continue;
3277
+ }
3278
+ existing.results.set(metadata.index, part);
3279
+ }
3280
+ }
3281
+ const completeGroups = /* @__PURE__ */ new Map();
3282
+ for (const [toolCallId, group] of pendingGroups) {
3283
+ if (group.invalid || group.results.size !== group.metadata.count) {
3284
+ continue;
3285
+ }
3286
+ const results = Array.from(
3287
+ { length: group.metadata.count },
3288
+ (_, index) => group.results.get(index)
3289
+ );
3290
+ if (results.every(isNonNullable)) {
3291
+ completeGroups.set(toolCallId, {
3292
+ metadata: group.metadata,
3293
+ results
3294
+ });
3295
+ }
3296
+ }
3297
+ return completeGroups;
3298
+ }
3080
3299
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
3081
3300
  var _a;
3082
3301
  return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
@@ -3100,10 +3319,16 @@ async function convertToOpenAIResponsesInput({
3100
3319
  hasApplyPatchTool = false,
3101
3320
  customProviderToolNames
3102
3321
  }) {
3103
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
3322
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
3104
3323
  let input = [];
3105
3324
  const warnings = [];
3106
3325
  const processedApprovalIds = /* @__PURE__ */ new Set();
3326
+ const parallelToolResultGroups = hasConversation || hasPreviousResponseId ? collectCompleteParallelToolResultGroups({
3327
+ prompt,
3328
+ providerOptionsName
3329
+ }) : /* @__PURE__ */ new Map();
3330
+ const emittedParallelToolCalls = /* @__PURE__ */ new Set();
3331
+ const emittedParallelToolResults = /* @__PURE__ */ new Set();
3107
3332
  for (const { role, content, providerOptions } of prompt) {
3108
3333
  switch (role) {
3109
3334
  case "system": {
@@ -3249,6 +3474,34 @@ async function convertToOpenAIResponsesInput({
3249
3474
  break;
3250
3475
  }
3251
3476
  case "tool-call": {
3477
+ const parallelToolCallMetadata = getParallelToolCallMetadata({
3478
+ providerOptions: part.providerOptions,
3479
+ providerOptionsName
3480
+ });
3481
+ const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
3482
+ parallelToolCallMetadata.toolCallId
3483
+ );
3484
+ if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
3485
+ parallelToolResultGroup.metadata,
3486
+ parallelToolCallMetadata
3487
+ )) {
3488
+ if (!emittedParallelToolCalls.has(
3489
+ parallelToolResultGroup.metadata.toolCallId
3490
+ )) {
3491
+ emittedParallelToolCalls.add(
3492
+ parallelToolResultGroup.metadata.toolCallId
3493
+ );
3494
+ if (!hasConversation) {
3495
+ input.push({
3496
+ type: "function_call",
3497
+ call_id: parallelToolResultGroup.metadata.toolCallId,
3498
+ name: parallelToolResultGroup.metadata.toolName,
3499
+ arguments: parallelToolResultGroup.metadata.input
3500
+ });
3501
+ }
3502
+ }
3503
+ break;
3504
+ }
3252
3505
  const id = (_f = (_c = (_b = part.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.itemId) != null ? _f : (_e = (_d = part.providerMetadata) == null ? void 0 : _d[providerOptionsName]) == null ? void 0 : _e.itemId;
3253
3506
  const namespace = (_k = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.namespace) != null ? _k : (_j = (_i = part.providerMetadata) == null ? void 0 : _i[providerOptionsName]) == null ? void 0 : _j.namespace;
3254
3507
  if (hasConversation && id != null) {
@@ -3528,6 +3781,44 @@ async function convertToOpenAIResponsesInput({
3528
3781
  });
3529
3782
  continue;
3530
3783
  }
3784
+ const parallelToolCallMetadata = getParallelToolCallMetadata({
3785
+ providerOptions: part.providerOptions,
3786
+ providerOptionsName
3787
+ });
3788
+ const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
3789
+ parallelToolCallMetadata.toolCallId
3790
+ );
3791
+ if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
3792
+ parallelToolResultGroup.metadata,
3793
+ parallelToolCallMetadata
3794
+ )) {
3795
+ if (!emittedParallelToolResults.has(
3796
+ parallelToolResultGroup.metadata.toolCallId
3797
+ )) {
3798
+ emittedParallelToolResults.add(
3799
+ parallelToolResultGroup.metadata.toolCallId
3800
+ );
3801
+ const toolOutputs = await Promise.all(
3802
+ parallelToolResultGroup.results.map(
3803
+ async (result) => convertFunctionToolResultOutput({
3804
+ output: result.output,
3805
+ providerOptionsName,
3806
+ warnings
3807
+ })
3808
+ )
3809
+ );
3810
+ input.push({
3811
+ type: "function_call_output",
3812
+ call_id: parallelToolResultGroup.metadata.toolCallId,
3813
+ // The internal wrapper returns one output containing the child
3814
+ // results in the same order as the original tool_uses array.
3815
+ output: toolOutputs.map(
3816
+ (output2) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
3817
+ ).join("\n")
3818
+ });
3819
+ }
3820
+ continue;
3821
+ }
3531
3822
  const output = part.output;
3532
3823
  if (output.type === "execution-denied") {
3533
3824
  const approvalId = (_x = (_w = output.providerOptions) == null ? void 0 : _w.openai) == null ? void 0 : _x.approvalId;
@@ -3680,86 +3971,11 @@ async function convertToOpenAIResponsesInput({
3680
3971
  });
3681
3972
  continue;
3682
3973
  }
3683
- let contentValue;
3684
- switch (output.type) {
3685
- case "text":
3686
- case "error-text":
3687
- contentValue = output.value;
3688
- break;
3689
- case "execution-denied":
3690
- contentValue = (_z = output.reason) != null ? _z : "Tool call execution denied.";
3691
- break;
3692
- case "json":
3693
- case "error-json":
3694
- contentValue = JSON.stringify(output.value);
3695
- break;
3696
- case "content":
3697
- contentValue = output.value.map((item) => {
3698
- var _a2, _b2, _c2, _d2, _e2;
3699
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3700
- item.providerOptions,
3701
- providerOptionsName
3702
- );
3703
- switch (item.type) {
3704
- case "text": {
3705
- return {
3706
- type: "input_text",
3707
- text: item.text,
3708
- ...promptCacheBreakpoint != null && {
3709
- prompt_cache_breakpoint: promptCacheBreakpoint
3710
- }
3711
- };
3712
- }
3713
- case "image-data": {
3714
- return {
3715
- type: "input_image",
3716
- image_url: `data:${item.mediaType};base64,${item.data}`,
3717
- detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3718
- ...promptCacheBreakpoint != null && {
3719
- prompt_cache_breakpoint: promptCacheBreakpoint
3720
- }
3721
- };
3722
- }
3723
- case "image-url": {
3724
- return {
3725
- type: "input_image",
3726
- image_url: item.url,
3727
- detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
3728
- ...promptCacheBreakpoint != null && {
3729
- prompt_cache_breakpoint: promptCacheBreakpoint
3730
- }
3731
- };
3732
- }
3733
- case "file-data": {
3734
- return {
3735
- type: "input_file",
3736
- filename: (_e2 = item.filename) != null ? _e2 : "data",
3737
- file_data: `data:${item.mediaType};base64,${item.data}`,
3738
- ...promptCacheBreakpoint != null && {
3739
- prompt_cache_breakpoint: promptCacheBreakpoint
3740
- }
3741
- };
3742
- }
3743
- case "file-url": {
3744
- return {
3745
- type: "input_file",
3746
- file_url: item.url,
3747
- ...promptCacheBreakpoint != null && {
3748
- prompt_cache_breakpoint: promptCacheBreakpoint
3749
- }
3750
- };
3751
- }
3752
- default: {
3753
- warnings.push({
3754
- type: "other",
3755
- message: `unsupported tool content part type: ${item.type}`
3756
- });
3757
- return void 0;
3758
- }
3759
- }
3760
- }).filter(isNonNullable);
3761
- break;
3762
- }
3974
+ const contentValue = await convertFunctionToolResultOutput({
3975
+ output,
3976
+ providerOptionsName,
3977
+ warnings
3978
+ });
3763
3979
  input.push({
3764
3980
  type: "function_call_output",
3765
3981
  call_id: part.toolCallId,
@@ -4991,7 +5207,7 @@ async function prepareResponsesTools({
4991
5207
  toolNameMapping,
4992
5208
  customProviderToolNames
4993
5209
  }) {
4994
- var _a, _b, _c;
5210
+ var _a, _b, _c, _d;
4995
5211
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
4996
5212
  const toolWarnings = [];
4997
5213
  if (tools == null) {
@@ -5000,6 +5216,20 @@ async function prepareResponsesTools({
5000
5216
  const openaiTools2 = [];
5001
5217
  const namespaceTools = /* @__PURE__ */ new Map();
5002
5218
  const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
5219
+ const allowedToolResolutions = /* @__PURE__ */ new Map();
5220
+ const allowedToolAliases = /* @__PURE__ */ new Map();
5221
+ const recordAllowedTool = (toolName, resolution, canonicalName) => {
5222
+ allowedToolResolutions.set(toolName, resolution);
5223
+ if (canonicalName == null || canonicalName === toolName) {
5224
+ return;
5225
+ }
5226
+ const existingAlias = allowedToolAliases.get(canonicalName);
5227
+ if (existingAlias == null) {
5228
+ allowedToolAliases.set(canonicalName, resolution);
5229
+ } else if (existingAlias !== "ambiguous" && !isSameAllowedTool(existingAlias, resolution)) {
5230
+ allowedToolAliases.set(canonicalName, "ambiguous");
5231
+ }
5232
+ };
5003
5233
  for (const tool of tools) {
5004
5234
  switch (tool.type) {
5005
5235
  case "function": {
@@ -5029,9 +5259,24 @@ async function prepareResponsesTools({
5029
5259
  }
5030
5260
  namespaceTool.tools.push(openaiFunctionTool);
5031
5261
  }
5262
+ recordAllowedTool(
5263
+ tool.name,
5264
+ namespace != null ? {
5265
+ supported: false,
5266
+ reason: "tools inside an OpenAI tool namespace are not visible to tool_choice.allowed_tools"
5267
+ } : (openaiOptions == null ? void 0 : openaiOptions.deferLoading) === true ? {
5268
+ supported: false,
5269
+ reason: "deferred tools are not visible to tool_choice.allowed_tools"
5270
+ } : {
5271
+ supported: true,
5272
+ entry: { type: "function", name: tool.name }
5273
+ },
5274
+ void 0
5275
+ );
5032
5276
  break;
5033
5277
  }
5034
5278
  case "provider": {
5279
+ const openaiToolCountBefore = openaiTools2.length;
5035
5280
  switch (tool.id) {
5036
5281
  case "openai.file_search": {
5037
5282
  const args = await validateTypes2({
@@ -5192,6 +5437,14 @@ async function prepareResponsesTools({
5192
5437
  break;
5193
5438
  }
5194
5439
  }
5440
+ if (openaiTools2.length > openaiToolCountBefore) {
5441
+ const openaiTool = openaiTools2[openaiToolCountBefore];
5442
+ recordAllowedTool(
5443
+ tool.name,
5444
+ toAllowedToolResolution(openaiTool),
5445
+ toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(tool.name)
5446
+ );
5447
+ }
5195
5448
  break;
5196
5449
  }
5197
5450
  default:
@@ -5203,18 +5456,63 @@ async function prepareResponsesTools({
5203
5456
  }
5204
5457
  }
5205
5458
  if (allowedTools != null) {
5459
+ const allowedToolEntries = [];
5460
+ const droppedToolNames = [];
5461
+ for (const name of allowedTools.toolNames) {
5462
+ const directResolution = allowedToolResolutions.get(name);
5463
+ const resolution = directResolution != null ? directResolution : allowedToolAliases.get(name);
5464
+ if (directResolution != null && allowedToolAliases.has(name)) {
5465
+ toolWarnings.push({
5466
+ type: "unsupported",
5467
+ feature: `allowedTools entry "${name}"`,
5468
+ details: "this name is both a tool name and the provider tool name of another tool in this request; the tool with this name is allowed"
5469
+ });
5470
+ }
5471
+ if (resolution === "ambiguous") {
5472
+ toolWarnings.push({
5473
+ type: "unsupported",
5474
+ feature: `allowedTools entry "${name}"`,
5475
+ details: "several tools in this request share this provider tool name; use the tool name from the tools for this request instead"
5476
+ });
5477
+ droppedToolNames.push(name);
5478
+ continue;
5479
+ }
5480
+ if (resolution == null) {
5481
+ toolWarnings.push({
5482
+ type: "unsupported",
5483
+ feature: `allowedTools entry "${name}"`,
5484
+ details: "the tool is not part of the tools for this request and is sent as a function tool"
5485
+ });
5486
+ allowedToolEntries.push({
5487
+ type: "function",
5488
+ name: (_b = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _b : name
5489
+ });
5490
+ continue;
5491
+ }
5492
+ if (!resolution.supported) {
5493
+ toolWarnings.push({
5494
+ type: "unsupported",
5495
+ feature: `allowedTools entry "${name}"`,
5496
+ details: `${resolution.reason}; the tool is removed from the allowed tools`
5497
+ });
5498
+ droppedToolNames.push(name);
5499
+ continue;
5500
+ }
5501
+ allowedToolEntries.push(resolution.entry);
5502
+ }
5503
+ if (allowedToolEntries.length === 0) {
5504
+ throw new UnsupportedFunctionalityError5({
5505
+ functionality: `allowedTools with only tools that cannot be allow-listed (${droppedToolNames.join(
5506
+ ", "
5507
+ )})`
5508
+ });
5509
+ }
5206
5510
  return {
5207
5511
  tools: openaiTools2,
5208
5512
  toolChoice: {
5209
5513
  type: "allowed_tools",
5210
- mode: (_b = allowedTools.mode) != null ? _b : "auto",
5211
- tools: allowedTools.toolNames.map((name) => {
5212
- var _a2;
5213
- return {
5214
- type: "function",
5215
- name: (_a2 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _a2 : name
5216
- };
5217
- })
5514
+ mode: (_c = allowedTools.mode) != null ? _c : "auto",
5515
+ tools: allowedToolEntries
5218
5516
  },
5219
5517
  toolWarnings
5220
5518
  };
@@ -5229,7 +5527,7 @@ async function prepareResponsesTools({
5229
5527
  case "required":
5230
5528
  return { tools: openaiTools2, toolChoice: type, toolWarnings };
5231
5529
  case "tool": {
5232
- const resolvedToolName = (_c = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _c : toolChoice.toolName;
5530
+ const resolvedToolName = (_d = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _d : toolChoice.toolName;
5233
5531
  return {
5234
5532
  tools: openaiTools2,
5235
5533
  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 },
@@ -5244,6 +5542,51 @@ async function prepareResponsesTools({
5244
5542
  }
5245
5543
  }
5246
5544
  }
5545
+ function allowedToolKey(entry) {
5546
+ switch (entry.type) {
5547
+ case "mcp":
5548
+ return `mcp:${entry.server_label}`;
5549
+ case "function":
5550
+ case "custom":
5551
+ return `${entry.type}:${entry.name}`;
5552
+ default:
5553
+ return entry.type;
5554
+ }
5555
+ }
5556
+ function isSameAllowedTool(a, b) {
5557
+ if (a.supported && b.supported) {
5558
+ return allowedToolKey(a.entry) === allowedToolKey(b.entry);
5559
+ }
5560
+ if (!a.supported && !b.supported) {
5561
+ return a.reason === b.reason;
5562
+ }
5563
+ return false;
5564
+ }
5565
+ function toAllowedToolResolution(tool) {
5566
+ switch (tool.type) {
5567
+ case "custom":
5568
+ return { supported: true, entry: { type: "custom", name: tool.name } };
5569
+ case "mcp":
5570
+ return {
5571
+ supported: true,
5572
+ entry: { type: "mcp", server_label: tool.server_label }
5573
+ };
5574
+ case "file_search":
5575
+ case "web_search":
5576
+ case "web_search_preview":
5577
+ case "image_generation":
5578
+ case "code_interpreter":
5579
+ case "apply_patch":
5580
+ case "shell":
5581
+ case "local_shell":
5582
+ return { supported: true, entry: { type: tool.type } };
5583
+ default:
5584
+ return {
5585
+ supported: false,
5586
+ reason: `OpenAI does not support ${tool.type} tools in tool_choice.allowed_tools`
5587
+ };
5588
+ }
5589
+ }
5247
5590
  function prepareFunctionTool({
5248
5591
  tool,
5249
5592
  options
@@ -5602,7 +5945,7 @@ var OpenAIResponsesLanguageModel = class {
5602
5945
  };
5603
5946
  }
5604
5947
  async doGenerate(options) {
5605
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C;
5948
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E;
5606
5949
  const {
5607
5950
  args: body,
5608
5951
  warnings,
@@ -5644,6 +5987,9 @@ var OpenAIResponsesLanguageModel = class {
5644
5987
  }
5645
5988
  const content = [];
5646
5989
  const logprobs = [];
5990
+ const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
5991
+ (tool) => tool.type === "function"
5992
+ )) != null ? _b : [];
5647
5993
  let hasFunctionCall = false;
5648
5994
  const hostedToolSearchCallIds = [];
5649
5995
  for (const part of response.output) {
@@ -5659,7 +6005,7 @@ var OpenAIResponsesLanguageModel = class {
5659
6005
  providerMetadata: {
5660
6006
  [providerOptionsName]: {
5661
6007
  itemId: part.id,
5662
- reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
6008
+ reasoningEncryptedContent: (_c = part.encrypted_content) != null ? _c : null
5663
6009
  }
5664
6010
  }
5665
6011
  });
@@ -5685,7 +6031,7 @@ var OpenAIResponsesLanguageModel = class {
5685
6031
  break;
5686
6032
  }
5687
6033
  case "tool_search_call": {
5688
- const toolCallId = (_b = part.call_id) != null ? _b : part.id;
6034
+ const toolCallId = (_d = part.call_id) != null ? _d : part.id;
5689
6035
  const isHosted = part.execution === "server";
5690
6036
  if (isHosted) {
5691
6037
  hostedToolSearchCallIds.push(toolCallId);
@@ -5708,7 +6054,7 @@ var OpenAIResponsesLanguageModel = class {
5708
6054
  break;
5709
6055
  }
5710
6056
  case "tool_search_output": {
5711
- const toolCallId = (_d = (_c = part.call_id) != null ? _c : hostedToolSearchCallIds.shift()) != null ? _d : part.id;
6057
+ const toolCallId = (_f = (_e = part.call_id) != null ? _e : hostedToolSearchCallIds.shift()) != null ? _f : part.id;
5712
6058
  content.push({
5713
6059
  type: "tool-result",
5714
6060
  toolCallId,
@@ -5779,7 +6125,7 @@ var OpenAIResponsesLanguageModel = class {
5779
6125
  }
5780
6126
  case "message": {
5781
6127
  for (const contentPart of part.content) {
5782
- if (((_f = (_e = options.providerOptions) == null ? void 0 : _e[providerOptionsName]) == null ? void 0 : _f.logprobs) && contentPart.logprobs) {
6128
+ if (((_h = (_g = options.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.logprobs) && contentPart.logprobs) {
5783
6129
  logprobs.push(contentPart.logprobs);
5784
6130
  }
5785
6131
  const providerMetadata2 = {
@@ -5801,7 +6147,7 @@ var OpenAIResponsesLanguageModel = class {
5801
6147
  content.push({
5802
6148
  type: "source",
5803
6149
  sourceType: "url",
5804
- id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId2(),
6150
+ id: (_k = (_j = (_i = this.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : generateId2(),
5805
6151
  url: annotation.url,
5806
6152
  title: annotation.title
5807
6153
  });
@@ -5809,7 +6155,7 @@ var OpenAIResponsesLanguageModel = class {
5809
6155
  content.push({
5810
6156
  type: "source",
5811
6157
  sourceType: "document",
5812
- id: (_l = (_k = (_j = this.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId2(),
6158
+ id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
5813
6159
  mediaType: "text/plain",
5814
6160
  title: annotation.filename,
5815
6161
  filename: annotation.filename,
@@ -5825,7 +6171,7 @@ var OpenAIResponsesLanguageModel = class {
5825
6171
  content.push({
5826
6172
  type: "source",
5827
6173
  sourceType: "document",
5828
- id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2(),
6174
+ id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
5829
6175
  mediaType: "text/plain",
5830
6176
  title: annotation.filename,
5831
6177
  filename: annotation.filename,
@@ -5841,7 +6187,7 @@ var OpenAIResponsesLanguageModel = class {
5841
6187
  content.push({
5842
6188
  type: "source",
5843
6189
  sourceType: "document",
5844
- id: (_r = (_q = (_p = this.config).generateId) == null ? void 0 : _q.call(_p)) != null ? _r : generateId2(),
6190
+ id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
5845
6191
  mediaType: "application/octet-stream",
5846
6192
  title: annotation.file_id,
5847
6193
  filename: annotation.file_id,
@@ -5860,6 +6206,20 @@ var OpenAIResponsesLanguageModel = class {
5860
6206
  }
5861
6207
  case "function_call": {
5862
6208
  hasFunctionCall = true;
6209
+ const expandedToolCalls = await expandParallelToolCall({
6210
+ toolCall: {
6211
+ toolCallId: part.call_id,
6212
+ toolName: part.name,
6213
+ input: part.arguments
6214
+ },
6215
+ tools: functionTools,
6216
+ providerOptionsName,
6217
+ itemId: part.id
6218
+ });
6219
+ if (expandedToolCalls != null) {
6220
+ content.push(...expandedToolCalls);
6221
+ break;
6222
+ }
5863
6223
  content.push({
5864
6224
  type: "tool-call",
5865
6225
  toolCallId: part.call_id,
@@ -5911,7 +6271,7 @@ var OpenAIResponsesLanguageModel = class {
5911
6271
  break;
5912
6272
  }
5913
6273
  case "mcp_call": {
5914
- const toolCallId = part.approval_request_id != null ? (_s = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _s : part.id : part.id;
6274
+ const toolCallId = part.approval_request_id != null ? (_u = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _u : part.id : part.id;
5915
6275
  const toolName = `mcp.${part.name}`;
5916
6276
  content.push({
5917
6277
  type: "tool-call",
@@ -5945,8 +6305,8 @@ var OpenAIResponsesLanguageModel = class {
5945
6305
  break;
5946
6306
  }
5947
6307
  case "mcp_approval_request": {
5948
- const approvalRequestId = (_t = part.approval_request_id) != null ? _t : part.id;
5949
- const dummyToolCallId = (_w = (_v = (_u = this.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2();
6308
+ const approvalRequestId = (_v = part.approval_request_id) != null ? _v : part.id;
6309
+ const dummyToolCallId = (_y = (_x = (_w = this.config).generateId) == null ? void 0 : _x.call(_w)) != null ? _y : generateId2();
5950
6310
  const toolName = `mcp.${part.name}`;
5951
6311
  content.push({
5952
6312
  type: "tool-call",
@@ -5996,13 +6356,13 @@ var OpenAIResponsesLanguageModel = class {
5996
6356
  toolName: toolNameMapping.toCustomToolName("file_search"),
5997
6357
  result: {
5998
6358
  queries: part.queries,
5999
- results: (_y = (_x = part.results) == null ? void 0 : _x.map((result) => ({
6359
+ results: (_A = (_z = part.results) == null ? void 0 : _z.map((result) => ({
6000
6360
  attributes: result.attributes,
6001
6361
  fileId: result.file_id,
6002
6362
  filename: result.filename,
6003
6363
  score: result.score,
6004
6364
  text: result.text
6005
- }))) != null ? _y : null
6365
+ }))) != null ? _A : null
6006
6366
  }
6007
6367
  });
6008
6368
  break;
@@ -6052,7 +6412,7 @@ var OpenAIResponsesLanguageModel = class {
6052
6412
  responseId: response.id,
6053
6413
  ...logprobs.length > 0 ? { logprobs } : {},
6054
6414
  ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
6055
- ...((_z = response.reasoning) == null ? void 0 : _z.context) != null ? { reasoningContext: response.reasoning.context } : {}
6415
+ ...((_B = response.reasoning) == null ? void 0 : _B.context) != null ? { reasoningContext: response.reasoning.context } : {}
6056
6416
  }
6057
6417
  };
6058
6418
  const usage = response.usage;
@@ -6060,10 +6420,10 @@ var OpenAIResponsesLanguageModel = class {
6060
6420
  content,
6061
6421
  finishReason: {
6062
6422
  unified: mapOpenAIResponseFinishReason({
6063
- finishReason: (_A = response.incomplete_details) == null ? void 0 : _A.reason,
6423
+ finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
6064
6424
  hasFunctionCall
6065
6425
  }),
6066
- raw: (_C = (_B = response.incomplete_details) == null ? void 0 : _B.reason) != null ? _C : void 0
6426
+ raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
6067
6427
  },
6068
6428
  usage: convertOpenAIResponsesUsage(usage),
6069
6429
  request: { body },
@@ -6079,6 +6439,7 @@ var OpenAIResponsesLanguageModel = class {
6079
6439
  };
6080
6440
  }
6081
6441
  async doStream(options) {
6442
+ var _a, _b;
6082
6443
  const {
6083
6444
  args: body,
6084
6445
  warnings,
@@ -6116,6 +6477,9 @@ var OpenAIResponsesLanguageModel = class {
6116
6477
  });
6117
6478
  const self = this;
6118
6479
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
6480
+ const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
6481
+ (tool) => tool.type === "function"
6482
+ )) != null ? _b : [];
6119
6483
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
6120
6484
  let finishReason = {
6121
6485
  unified: "other",
@@ -6140,7 +6504,7 @@ var OpenAIResponsesLanguageModel = class {
6140
6504
  controller.enqueue({ type: "stream-start", warnings });
6141
6505
  },
6142
6506
  transform(chunk, controller) {
6143
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N;
6507
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P;
6144
6508
  if (options.includeRawChunks) {
6145
6509
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
6146
6510
  }
@@ -6159,15 +6523,23 @@ var OpenAIResponsesLanguageModel = class {
6159
6523
  const value = chunk.value;
6160
6524
  if (isResponseOutputItemAddedChunk(value)) {
6161
6525
  if (value.item.type === "function_call") {
6526
+ const suppressInputStreaming = isUndeclaredParallelToolCall({
6527
+ toolName: value.item.name,
6528
+ tools: functionTools
6529
+ });
6162
6530
  ongoingToolCalls[value.output_index] = {
6163
6531
  toolName: value.item.name,
6164
- toolCallId: value.item.call_id
6532
+ toolCallId: value.item.call_id,
6533
+ suppressInputStreaming,
6534
+ bufferedInputDeltas: suppressInputStreaming ? [] : void 0
6165
6535
  };
6166
- controller.enqueue({
6167
- type: "tool-input-start",
6168
- id: value.item.call_id,
6169
- toolName: value.item.name
6170
- });
6536
+ if (!suppressInputStreaming) {
6537
+ controller.enqueue({
6538
+ type: "tool-input-start",
6539
+ id: value.item.call_id,
6540
+ toolName: value.item.name
6541
+ });
6542
+ }
6171
6543
  } else if (value.item.type === "custom_tool_call") {
6172
6544
  const toolName = toolNameMapping.toCustomToolName(
6173
6545
  value.item.name
@@ -6262,7 +6634,7 @@ var OpenAIResponsesLanguageModel = class {
6262
6634
  ongoingToolCalls[value.output_index] = {
6263
6635
  toolName,
6264
6636
  toolCallId,
6265
- toolSearchExecution: (_a = value.item.execution) != null ? _a : "server"
6637
+ toolSearchExecution: (_a2 = value.item.execution) != null ? _a2 : "server"
6266
6638
  };
6267
6639
  if (isHosted) {
6268
6640
  controller.enqueue({
@@ -6319,7 +6691,7 @@ var OpenAIResponsesLanguageModel = class {
6319
6691
  } else if (value.item.type === "shell_call_output") {
6320
6692
  } else if (value.item.type === "message") {
6321
6693
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
6322
- activeMessagePhase = (_b = value.item.phase) != null ? _b : void 0;
6694
+ activeMessagePhase = (_b2 = value.item.phase) != null ? _b2 : void 0;
6323
6695
  controller.enqueue({
6324
6696
  type: "text-start",
6325
6697
  id: value.item.id,
@@ -6366,31 +6738,99 @@ var OpenAIResponsesLanguageModel = class {
6366
6738
  }
6367
6739
  });
6368
6740
  } else if (value.item.type === "function_call") {
6741
+ const item = value.item;
6742
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
6369
6743
  ongoingToolCalls[value.output_index] = void 0;
6370
6744
  hasFunctionCall = true;
6371
- controller.enqueue({
6372
- type: "tool-input-end",
6373
- id: value.item.call_id,
6374
- ...value.item.namespace != null && {
6375
- providerMetadata: {
6376
- [providerOptionsName]: {
6377
- namespace: value.item.namespace
6745
+ const suppressInputStreaming = (_e = ongoingToolCall == null ? void 0 : ongoingToolCall.suppressInputStreaming) != null ? _e : isUndeclaredParallelToolCall({
6746
+ toolName: item.name,
6747
+ tools: functionTools
6748
+ });
6749
+ const enqueueUnexpandedToolCall = () => {
6750
+ var _a3;
6751
+ if (suppressInputStreaming) {
6752
+ controller.enqueue({
6753
+ type: "tool-input-start",
6754
+ id: item.call_id,
6755
+ toolName: item.name
6756
+ });
6757
+ const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
6758
+ if (bufferedInputDeltas.length > 0) {
6759
+ for (const delta of bufferedInputDeltas) {
6760
+ controller.enqueue({
6761
+ type: "tool-input-delta",
6762
+ id: item.call_id,
6763
+ delta
6764
+ });
6378
6765
  }
6766
+ } else if (item.arguments.length > 0) {
6767
+ controller.enqueue({
6768
+ type: "tool-input-delta",
6769
+ id: item.call_id,
6770
+ delta: item.arguments
6771
+ });
6379
6772
  }
6380
6773
  }
6381
- });
6382
- controller.enqueue({
6383
- type: "tool-call",
6384
- toolCallId: value.item.call_id,
6385
- toolName: value.item.name,
6386
- input: value.item.arguments,
6387
- providerMetadata: {
6388
- [providerOptionsName]: {
6389
- itemId: value.item.id,
6390
- ...value.item.namespace != null && {
6391
- namespace: value.item.namespace
6774
+ controller.enqueue({
6775
+ type: "tool-input-end",
6776
+ id: item.call_id,
6777
+ ...item.namespace != null && {
6778
+ providerMetadata: {
6779
+ [providerOptionsName]: {
6780
+ namespace: item.namespace
6781
+ }
6392
6782
  }
6393
6783
  }
6784
+ });
6785
+ controller.enqueue({
6786
+ type: "tool-call",
6787
+ toolCallId: item.call_id,
6788
+ toolName: item.name,
6789
+ input: item.arguments,
6790
+ providerMetadata: {
6791
+ [providerOptionsName]: {
6792
+ itemId: item.id,
6793
+ ...item.namespace != null && {
6794
+ namespace: item.namespace
6795
+ }
6796
+ }
6797
+ }
6798
+ });
6799
+ };
6800
+ if (!suppressInputStreaming) {
6801
+ enqueueUnexpandedToolCall();
6802
+ return;
6803
+ }
6804
+ return expandParallelToolCall({
6805
+ toolCall: {
6806
+ toolCallId: item.call_id,
6807
+ toolName: item.name,
6808
+ input: item.arguments
6809
+ },
6810
+ tools: functionTools,
6811
+ providerOptionsName,
6812
+ itemId: item.id
6813
+ }).then((expandedToolCalls) => {
6814
+ if (expandedToolCalls == null) {
6815
+ enqueueUnexpandedToolCall();
6816
+ return;
6817
+ }
6818
+ for (const toolCall of expandedToolCalls) {
6819
+ controller.enqueue({
6820
+ type: "tool-input-start",
6821
+ id: toolCall.toolCallId,
6822
+ toolName: toolCall.toolName
6823
+ });
6824
+ controller.enqueue({
6825
+ type: "tool-input-delta",
6826
+ id: toolCall.toolCallId,
6827
+ delta: toolCall.input
6828
+ });
6829
+ controller.enqueue({
6830
+ type: "tool-input-end",
6831
+ id: toolCall.toolCallId
6832
+ });
6833
+ controller.enqueue(toolCall);
6394
6834
  }
6395
6835
  });
6396
6836
  } else if (value.item.type === "custom_tool_call") {
@@ -6454,13 +6894,13 @@ var OpenAIResponsesLanguageModel = class {
6454
6894
  toolName: toolNameMapping.toCustomToolName("file_search"),
6455
6895
  result: {
6456
6896
  queries: value.item.queries,
6457
- results: (_f = (_e = value.item.results) == null ? void 0 : _e.map((result2) => ({
6897
+ results: (_g = (_f = value.item.results) == null ? void 0 : _f.map((result2) => ({
6458
6898
  attributes: result2.attributes,
6459
6899
  fileId: result2.file_id,
6460
6900
  filename: result2.filename,
6461
6901
  score: result2.score,
6462
6902
  text: result2.text
6463
- }))) != null ? _f : null
6903
+ }))) != null ? _g : null
6464
6904
  }
6465
6905
  });
6466
6906
  } else if (value.item.type === "code_interpreter_call") {
@@ -6486,7 +6926,7 @@ var OpenAIResponsesLanguageModel = class {
6486
6926
  const toolCall = ongoingToolCalls[value.output_index];
6487
6927
  const isHosted = value.item.execution === "server";
6488
6928
  if (toolCall != null) {
6489
- const toolCallId = isHosted ? toolCall.toolCallId : (_g = value.item.call_id) != null ? _g : value.item.id;
6929
+ const toolCallId = isHosted ? toolCall.toolCallId : (_h = value.item.call_id) != null ? _h : value.item.id;
6490
6930
  if (isHosted) {
6491
6931
  hostedToolSearchCallIds.push(toolCallId);
6492
6932
  } else {
@@ -6518,7 +6958,7 @@ var OpenAIResponsesLanguageModel = class {
6518
6958
  }
6519
6959
  ongoingToolCalls[value.output_index] = void 0;
6520
6960
  } else if (value.item.type === "tool_search_output") {
6521
- const toolCallId = (_i = (_h = value.item.call_id) != null ? _h : hostedToolSearchCallIds.shift()) != null ? _i : value.item.id;
6961
+ const toolCallId = (_j = (_i = value.item.call_id) != null ? _i : hostedToolSearchCallIds.shift()) != null ? _j : value.item.id;
6522
6962
  controller.enqueue({
6523
6963
  type: "tool-result",
6524
6964
  toolCallId,
@@ -6534,10 +6974,10 @@ var OpenAIResponsesLanguageModel = class {
6534
6974
  });
6535
6975
  } else if (value.item.type === "mcp_call") {
6536
6976
  ongoingToolCalls[value.output_index] = void 0;
6537
- const approvalRequestId = (_j = value.item.approval_request_id) != null ? _j : void 0;
6538
- const aliasedToolCallId = approvalRequestId != null ? (_l = (_k = approvalRequestIdToDummyToolCallIdFromStream.get(
6977
+ const approvalRequestId = (_k = value.item.approval_request_id) != null ? _k : void 0;
6978
+ const aliasedToolCallId = approvalRequestId != null ? (_m = (_l = approvalRequestIdToDummyToolCallIdFromStream.get(
6539
6979
  approvalRequestId
6540
- )) != null ? _k : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _l : value.item.id : value.item.id;
6980
+ )) != null ? _l : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _m : value.item.id : value.item.id;
6541
6981
  const toolName = `mcp.${value.item.name}`;
6542
6982
  controller.enqueue({
6543
6983
  type: "tool-call",
@@ -6607,8 +7047,8 @@ var OpenAIResponsesLanguageModel = class {
6607
7047
  ongoingToolCalls[value.output_index] = void 0;
6608
7048
  } else if (value.item.type === "mcp_approval_request") {
6609
7049
  ongoingToolCalls[value.output_index] = void 0;
6610
- const dummyToolCallId = (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2();
6611
- const approvalRequestId = (_p = value.item.approval_request_id) != null ? _p : value.item.id;
7050
+ const dummyToolCallId = (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2();
7051
+ const approvalRequestId = (_q = value.item.approval_request_id) != null ? _q : value.item.id;
6612
7052
  approvalRequestIdToDummyToolCallIdFromStream.set(
6613
7053
  approvalRequestId,
6614
7054
  dummyToolCallId
@@ -6697,7 +7137,7 @@ var OpenAIResponsesLanguageModel = class {
6697
7137
  providerMetadata: {
6698
7138
  [providerOptionsName]: {
6699
7139
  itemId: value.item.id,
6700
- reasoningEncryptedContent: (_q = value.item.encrypted_content) != null ? _q : null
7140
+ reasoningEncryptedContent: (_r = value.item.encrypted_content) != null ? _r : null
6701
7141
  }
6702
7142
  }
6703
7143
  });
@@ -6707,11 +7147,15 @@ var OpenAIResponsesLanguageModel = class {
6707
7147
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
6708
7148
  const toolCall = ongoingToolCalls[value.output_index];
6709
7149
  if (toolCall != null) {
6710
- controller.enqueue({
6711
- type: "tool-input-delta",
6712
- id: toolCall.toolCallId,
6713
- delta: value.delta
6714
- });
7150
+ if (toolCall.suppressInputStreaming) {
7151
+ (_s = toolCall.bufferedInputDeltas) == null ? void 0 : _s.push(value.delta);
7152
+ } else {
7153
+ controller.enqueue({
7154
+ type: "tool-input-delta",
7155
+ id: toolCall.toolCallId,
7156
+ delta: value.delta
7157
+ });
7158
+ }
6715
7159
  }
6716
7160
  } else if (isResponseCustomToolCallInputDeltaChunk(value)) {
6717
7161
  const toolCall = ongoingToolCalls[value.output_index];
@@ -6810,7 +7254,7 @@ var OpenAIResponsesLanguageModel = class {
6810
7254
  id: value.item_id,
6811
7255
  delta: value.delta
6812
7256
  });
6813
- if (((_s = (_r = options.providerOptions) == null ? void 0 : _r[providerOptionsName]) == null ? void 0 : _s.logprobs) && value.logprobs) {
7257
+ if (((_u = (_t = options.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.logprobs) && value.logprobs) {
6814
7258
  logprobs.push(value.logprobs);
6815
7259
  }
6816
7260
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -6839,7 +7283,7 @@ var OpenAIResponsesLanguageModel = class {
6839
7283
  providerMetadata: {
6840
7284
  [providerOptionsName]: {
6841
7285
  itemId: value.item_id,
6842
- reasoningEncryptedContent: (_u = (_t = activeReasoning[value.item_id]) == null ? void 0 : _t.encryptedContent) != null ? _u : null
7286
+ reasoningEncryptedContent: (_w = (_v = activeReasoning[value.item_id]) == null ? void 0 : _v.encryptedContent) != null ? _w : null
6843
7287
  }
6844
7288
  }
6845
7289
  });
@@ -6873,20 +7317,20 @@ var OpenAIResponsesLanguageModel = class {
6873
7317
  } else if (isResponseFinishedChunk(value)) {
6874
7318
  finishReason = {
6875
7319
  unified: mapOpenAIResponseFinishReason({
6876
- finishReason: (_v = value.response.incomplete_details) == null ? void 0 : _v.reason,
7320
+ finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
6877
7321
  hasFunctionCall
6878
7322
  }),
6879
- raw: (_x = (_w = value.response.incomplete_details) == null ? void 0 : _w.reason) != null ? _x : void 0
7323
+ raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
6880
7324
  };
6881
7325
  usage = value.response.usage;
6882
7326
  if (typeof value.response.service_tier === "string") {
6883
7327
  serviceTier = value.response.service_tier;
6884
7328
  }
6885
- if (((_y = value.response.reasoning) == null ? void 0 : _y.context) != null) {
7329
+ if (((_A = value.response.reasoning) == null ? void 0 : _A.context) != null) {
6886
7330
  reasoningContext = value.response.reasoning.context;
6887
7331
  }
6888
7332
  } else if (isResponseFailedChunk(value)) {
6889
- const incompleteReason = (_z = value.response.incomplete_details) == null ? void 0 : _z.reason;
7333
+ const incompleteReason = (_B = value.response.incomplete_details) == null ? void 0 : _B.reason;
6890
7334
  finishReason = {
6891
7335
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
6892
7336
  finishReason: incompleteReason,
@@ -6894,8 +7338,8 @@ var OpenAIResponsesLanguageModel = class {
6894
7338
  }) : "error",
6895
7339
  raw: incompleteReason != null ? incompleteReason : "error"
6896
7340
  };
6897
- usage = (_A = value.response.usage) != null ? _A : void 0;
6898
- if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
7341
+ usage = (_C = value.response.usage) != null ? _C : void 0;
7342
+ if (((_D = value.response.reasoning) == null ? void 0 : _D.context) != null) {
6899
7343
  reasoningContext = value.response.reasoning.context;
6900
7344
  }
6901
7345
  if (!encounteredStreamError && value.response.error != null) {
@@ -6919,7 +7363,7 @@ var OpenAIResponsesLanguageModel = class {
6919
7363
  controller.enqueue({
6920
7364
  type: "source",
6921
7365
  sourceType: "url",
6922
- id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : generateId2(),
7366
+ id: (_G = (_F = (_E = self.config).generateId) == null ? void 0 : _F.call(_E)) != null ? _G : generateId2(),
6923
7367
  url: value.annotation.url,
6924
7368
  title: value.annotation.title
6925
7369
  });
@@ -6927,7 +7371,7 @@ var OpenAIResponsesLanguageModel = class {
6927
7371
  controller.enqueue({
6928
7372
  type: "source",
6929
7373
  sourceType: "document",
6930
- id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
7374
+ id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : generateId2(),
6931
7375
  mediaType: "text/plain",
6932
7376
  title: value.annotation.filename,
6933
7377
  filename: value.annotation.filename,
@@ -6943,7 +7387,7 @@ var OpenAIResponsesLanguageModel = class {
6943
7387
  controller.enqueue({
6944
7388
  type: "source",
6945
7389
  sourceType: "document",
6946
- id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
7390
+ id: (_M = (_L = (_K = self.config).generateId) == null ? void 0 : _L.call(_K)) != null ? _M : generateId2(),
6947
7391
  mediaType: "text/plain",
6948
7392
  title: value.annotation.filename,
6949
7393
  filename: value.annotation.filename,
@@ -6959,7 +7403,7 @@ var OpenAIResponsesLanguageModel = class {
6959
7403
  controller.enqueue({
6960
7404
  type: "source",
6961
7405
  sourceType: "document",
6962
- id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
7406
+ id: (_P = (_O = (_N = self.config).generateId) == null ? void 0 : _O.call(_N)) != null ? _P : generateId2(),
6963
7407
  mediaType: "application/octet-stream",
6964
7408
  title: value.annotation.file_id,
6965
7409
  filename: value.annotation.file_id,
@@ -6979,6 +7423,24 @@ var OpenAIResponsesLanguageModel = class {
6979
7423
  }
6980
7424
  },
6981
7425
  flush(controller) {
7426
+ var _a2;
7427
+ for (const toolCall of Object.values(ongoingToolCalls)) {
7428
+ if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
7429
+ continue;
7430
+ }
7431
+ controller.enqueue({
7432
+ type: "tool-input-start",
7433
+ id: toolCall.toolCallId,
7434
+ toolName: toolCall.toolName
7435
+ });
7436
+ for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
7437
+ controller.enqueue({
7438
+ type: "tool-input-delta",
7439
+ id: toolCall.toolCallId,
7440
+ delta
7441
+ });
7442
+ }
7443
+ }
6982
7444
  const providerMetadata = {
6983
7445
  [providerOptionsName]: {
6984
7446
  responseId,
@@ -7478,7 +7940,7 @@ var OpenAITranscriptionModel = class {
7478
7940
  };
7479
7941
 
7480
7942
  // src/version.ts
7481
- var VERSION = true ? "3.0.97" : "0.0.0-test";
7943
+ var VERSION = true ? "3.0.99" : "0.0.0-test";
7482
7944
 
7483
7945
  // src/openai-provider.ts
7484
7946
  function createOpenAI(options = {}) {