@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.
@@ -2966,10 +2966,227 @@ var toolSearchToolFactory = createProviderToolFactoryWithOutputSchema4({
2966
2966
  outputSchema: toolSearchOutputSchema
2967
2967
  });
2968
2968
 
2969
+ // src/responses/expand-parallel-tool-call.ts
2970
+ import {
2971
+ isJSONObject
2972
+ } from "@ai-sdk/provider";
2973
+ import { safeParseJSON } from "@ai-sdk/provider-utils";
2974
+ var parallelToolName = "parallel";
2975
+ var recipientNamePrefix = "functions.";
2976
+ function getParallelToolCallMetadata({
2977
+ providerOptions,
2978
+ providerOptionsName
2979
+ }) {
2980
+ var _a;
2981
+ const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
2982
+ 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) {
2983
+ return void 0;
2984
+ }
2985
+ return metadata;
2986
+ }
2987
+ function isUndeclaredParallelToolCall({
2988
+ toolName,
2989
+ tools
2990
+ }) {
2991
+ return toolName === parallelToolName && !tools.some((tool) => tool.name === parallelToolName);
2992
+ }
2993
+ async function expandParallelToolCall({
2994
+ toolCall,
2995
+ tools,
2996
+ providerOptionsName,
2997
+ itemId
2998
+ }) {
2999
+ if (!isUndeclaredParallelToolCall({ toolName: toolCall.toolName, tools })) {
3000
+ return void 0;
3001
+ }
3002
+ const parsedInput = await safeParseJSON({ text: toolCall.input });
3003
+ if (!parsedInput.success || !isJSONObject(parsedInput.value)) {
3004
+ return void 0;
3005
+ }
3006
+ const toolUses = parsedInput.value.tool_uses;
3007
+ if (!Array.isArray(toolUses) || toolUses.length === 0) {
3008
+ return void 0;
3009
+ }
3010
+ const availableToolNames = new Set(tools.map((tool) => tool.name));
3011
+ const expandedToolCalls = [];
3012
+ for (const [index, toolUse] of toolUses.entries()) {
3013
+ if (!isJSONObject(toolUse)) {
3014
+ return void 0;
3015
+ }
3016
+ const recipientName = toolUse.recipient_name;
3017
+ const parameters = toolUse.parameters;
3018
+ if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !isJSONObject(parameters)) {
3019
+ return void 0;
3020
+ }
3021
+ const toolName = recipientName.slice(recipientNamePrefix.length);
3022
+ if (toolName.length === 0 || !availableToolNames.has(toolName)) {
3023
+ return void 0;
3024
+ }
3025
+ expandedToolCalls.push({
3026
+ type: "tool-call",
3027
+ toolCallId: `${toolCall.toolCallId}_${index}`,
3028
+ toolName,
3029
+ input: JSON.stringify(parameters),
3030
+ providerMetadata: {
3031
+ [providerOptionsName]: {
3032
+ parallelToolCall: {
3033
+ itemId,
3034
+ toolCallId: toolCall.toolCallId,
3035
+ toolName: toolCall.toolName,
3036
+ input: toolCall.input,
3037
+ index,
3038
+ count: toolUses.length
3039
+ }
3040
+ }
3041
+ }
3042
+ });
3043
+ }
3044
+ return expandedToolCalls;
3045
+ }
3046
+
2969
3047
  // src/responses/convert-to-openai-responses-input.ts
2970
3048
  function serializeToolCallArguments2(input) {
2971
3049
  return JSON.stringify(input === void 0 ? {} : input);
2972
3050
  }
3051
+ async function convertFunctionToolResultOutput({
3052
+ output,
3053
+ providerOptionsName,
3054
+ warnings
3055
+ }) {
3056
+ var _a;
3057
+ switch (output.type) {
3058
+ case "text":
3059
+ case "error-text":
3060
+ return output.value;
3061
+ case "execution-denied":
3062
+ return (_a = output.reason) != null ? _a : "Tool call execution denied.";
3063
+ case "json":
3064
+ case "error-json":
3065
+ return JSON.stringify(output.value);
3066
+ case "content":
3067
+ return output.value.map((item) => {
3068
+ var _a2, _b, _c, _d, _e;
3069
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3070
+ item.providerOptions,
3071
+ providerOptionsName
3072
+ );
3073
+ switch (item.type) {
3074
+ case "text": {
3075
+ return {
3076
+ type: "input_text",
3077
+ text: item.text,
3078
+ ...promptCacheBreakpoint != null && {
3079
+ prompt_cache_breakpoint: promptCacheBreakpoint
3080
+ }
3081
+ };
3082
+ }
3083
+ case "image-data": {
3084
+ return {
3085
+ type: "input_image",
3086
+ image_url: `data:${item.mediaType};base64,${item.data}`,
3087
+ detail: (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail,
3088
+ ...promptCacheBreakpoint != null && {
3089
+ prompt_cache_breakpoint: promptCacheBreakpoint
3090
+ }
3091
+ };
3092
+ }
3093
+ case "image-url": {
3094
+ return {
3095
+ type: "input_image",
3096
+ image_url: item.url,
3097
+ detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
3098
+ ...promptCacheBreakpoint != null && {
3099
+ prompt_cache_breakpoint: promptCacheBreakpoint
3100
+ }
3101
+ };
3102
+ }
3103
+ case "file-data": {
3104
+ return {
3105
+ type: "input_file",
3106
+ filename: (_e = item.filename) != null ? _e : "data",
3107
+ file_data: `data:${item.mediaType};base64,${item.data}`,
3108
+ ...promptCacheBreakpoint != null && {
3109
+ prompt_cache_breakpoint: promptCacheBreakpoint
3110
+ }
3111
+ };
3112
+ }
3113
+ case "file-url": {
3114
+ return {
3115
+ type: "input_file",
3116
+ file_url: item.url,
3117
+ ...promptCacheBreakpoint != null && {
3118
+ prompt_cache_breakpoint: promptCacheBreakpoint
3119
+ }
3120
+ };
3121
+ }
3122
+ default: {
3123
+ warnings.push({
3124
+ type: "other",
3125
+ message: `unsupported tool content part type: ${item.type}`
3126
+ });
3127
+ return void 0;
3128
+ }
3129
+ }
3130
+ }).filter(isNonNullable);
3131
+ }
3132
+ }
3133
+ function hasSameParallelToolCall(first, second) {
3134
+ return first.itemId === second.itemId && first.toolCallId === second.toolCallId && first.toolName === second.toolName && first.input === second.input && first.count === second.count;
3135
+ }
3136
+ function collectCompleteParallelToolResultGroups({
3137
+ prompt,
3138
+ providerOptionsName
3139
+ }) {
3140
+ const pendingGroups = /* @__PURE__ */ new Map();
3141
+ for (const message of prompt) {
3142
+ if (message.role !== "tool") {
3143
+ continue;
3144
+ }
3145
+ for (const part of message.content) {
3146
+ if (part.type !== "tool-result") {
3147
+ continue;
3148
+ }
3149
+ const metadata = getParallelToolCallMetadata({
3150
+ providerOptions: part.providerOptions,
3151
+ providerOptionsName
3152
+ });
3153
+ if (metadata == null) {
3154
+ continue;
3155
+ }
3156
+ const existing = pendingGroups.get(metadata.toolCallId);
3157
+ if (existing == null) {
3158
+ pendingGroups.set(metadata.toolCallId, {
3159
+ metadata,
3160
+ results: /* @__PURE__ */ new Map([[metadata.index, part]]),
3161
+ invalid: false
3162
+ });
3163
+ continue;
3164
+ }
3165
+ if (!hasSameParallelToolCall(existing.metadata, metadata) || existing.results.has(metadata.index)) {
3166
+ existing.invalid = true;
3167
+ continue;
3168
+ }
3169
+ existing.results.set(metadata.index, part);
3170
+ }
3171
+ }
3172
+ const completeGroups = /* @__PURE__ */ new Map();
3173
+ for (const [toolCallId, group] of pendingGroups) {
3174
+ if (group.invalid || group.results.size !== group.metadata.count) {
3175
+ continue;
3176
+ }
3177
+ const results = Array.from(
3178
+ { length: group.metadata.count },
3179
+ (_, index) => group.results.get(index)
3180
+ );
3181
+ if (results.every(isNonNullable)) {
3182
+ completeGroups.set(toolCallId, {
3183
+ metadata: group.metadata,
3184
+ results
3185
+ });
3186
+ }
3187
+ }
3188
+ return completeGroups;
3189
+ }
2973
3190
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
2974
3191
  var _a;
2975
3192
  return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
@@ -2993,10 +3210,16 @@ async function convertToOpenAIResponsesInput({
2993
3210
  hasApplyPatchTool = false,
2994
3211
  customProviderToolNames
2995
3212
  }) {
2996
- 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;
3213
+ 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;
2997
3214
  let input = [];
2998
3215
  const warnings = [];
2999
3216
  const processedApprovalIds = /* @__PURE__ */ new Set();
3217
+ const parallelToolResultGroups = hasConversation || hasPreviousResponseId ? collectCompleteParallelToolResultGroups({
3218
+ prompt,
3219
+ providerOptionsName
3220
+ }) : /* @__PURE__ */ new Map();
3221
+ const emittedParallelToolCalls = /* @__PURE__ */ new Set();
3222
+ const emittedParallelToolResults = /* @__PURE__ */ new Set();
3000
3223
  for (const { role, content, providerOptions } of prompt) {
3001
3224
  switch (role) {
3002
3225
  case "system": {
@@ -3142,6 +3365,34 @@ async function convertToOpenAIResponsesInput({
3142
3365
  break;
3143
3366
  }
3144
3367
  case "tool-call": {
3368
+ const parallelToolCallMetadata = getParallelToolCallMetadata({
3369
+ providerOptions: part.providerOptions,
3370
+ providerOptionsName
3371
+ });
3372
+ const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
3373
+ parallelToolCallMetadata.toolCallId
3374
+ );
3375
+ if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
3376
+ parallelToolResultGroup.metadata,
3377
+ parallelToolCallMetadata
3378
+ )) {
3379
+ if (!emittedParallelToolCalls.has(
3380
+ parallelToolResultGroup.metadata.toolCallId
3381
+ )) {
3382
+ emittedParallelToolCalls.add(
3383
+ parallelToolResultGroup.metadata.toolCallId
3384
+ );
3385
+ if (!hasConversation) {
3386
+ input.push({
3387
+ type: "function_call",
3388
+ call_id: parallelToolResultGroup.metadata.toolCallId,
3389
+ name: parallelToolResultGroup.metadata.toolName,
3390
+ arguments: parallelToolResultGroup.metadata.input
3391
+ });
3392
+ }
3393
+ }
3394
+ break;
3395
+ }
3145
3396
  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;
3146
3397
  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;
3147
3398
  if (hasConversation && id != null) {
@@ -3421,6 +3672,44 @@ async function convertToOpenAIResponsesInput({
3421
3672
  });
3422
3673
  continue;
3423
3674
  }
3675
+ const parallelToolCallMetadata = getParallelToolCallMetadata({
3676
+ providerOptions: part.providerOptions,
3677
+ providerOptionsName
3678
+ });
3679
+ const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
3680
+ parallelToolCallMetadata.toolCallId
3681
+ );
3682
+ if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
3683
+ parallelToolResultGroup.metadata,
3684
+ parallelToolCallMetadata
3685
+ )) {
3686
+ if (!emittedParallelToolResults.has(
3687
+ parallelToolResultGroup.metadata.toolCallId
3688
+ )) {
3689
+ emittedParallelToolResults.add(
3690
+ parallelToolResultGroup.metadata.toolCallId
3691
+ );
3692
+ const toolOutputs = await Promise.all(
3693
+ parallelToolResultGroup.results.map(
3694
+ async (result) => convertFunctionToolResultOutput({
3695
+ output: result.output,
3696
+ providerOptionsName,
3697
+ warnings
3698
+ })
3699
+ )
3700
+ );
3701
+ input.push({
3702
+ type: "function_call_output",
3703
+ call_id: parallelToolResultGroup.metadata.toolCallId,
3704
+ // The internal wrapper returns one output containing the child
3705
+ // results in the same order as the original tool_uses array.
3706
+ output: toolOutputs.map(
3707
+ (output2) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
3708
+ ).join("\n")
3709
+ });
3710
+ }
3711
+ continue;
3712
+ }
3424
3713
  const output = part.output;
3425
3714
  if (output.type === "execution-denied") {
3426
3715
  const approvalId = (_x = (_w = output.providerOptions) == null ? void 0 : _w.openai) == null ? void 0 : _x.approvalId;
@@ -3573,86 +3862,11 @@ async function convertToOpenAIResponsesInput({
3573
3862
  });
3574
3863
  continue;
3575
3864
  }
3576
- let contentValue;
3577
- switch (output.type) {
3578
- case "text":
3579
- case "error-text":
3580
- contentValue = output.value;
3581
- break;
3582
- case "execution-denied":
3583
- contentValue = (_z = output.reason) != null ? _z : "Tool call execution denied.";
3584
- break;
3585
- case "json":
3586
- case "error-json":
3587
- contentValue = JSON.stringify(output.value);
3588
- break;
3589
- case "content":
3590
- contentValue = output.value.map((item) => {
3591
- var _a2, _b2, _c2, _d2, _e2;
3592
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3593
- item.providerOptions,
3594
- providerOptionsName
3595
- );
3596
- switch (item.type) {
3597
- case "text": {
3598
- return {
3599
- type: "input_text",
3600
- text: item.text,
3601
- ...promptCacheBreakpoint != null && {
3602
- prompt_cache_breakpoint: promptCacheBreakpoint
3603
- }
3604
- };
3605
- }
3606
- case "image-data": {
3607
- return {
3608
- type: "input_image",
3609
- image_url: `data:${item.mediaType};base64,${item.data}`,
3610
- detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
3611
- ...promptCacheBreakpoint != null && {
3612
- prompt_cache_breakpoint: promptCacheBreakpoint
3613
- }
3614
- };
3615
- }
3616
- case "image-url": {
3617
- return {
3618
- type: "input_image",
3619
- image_url: item.url,
3620
- detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
3621
- ...promptCacheBreakpoint != null && {
3622
- prompt_cache_breakpoint: promptCacheBreakpoint
3623
- }
3624
- };
3625
- }
3626
- case "file-data": {
3627
- return {
3628
- type: "input_file",
3629
- filename: (_e2 = item.filename) != null ? _e2 : "data",
3630
- file_data: `data:${item.mediaType};base64,${item.data}`,
3631
- ...promptCacheBreakpoint != null && {
3632
- prompt_cache_breakpoint: promptCacheBreakpoint
3633
- }
3634
- };
3635
- }
3636
- case "file-url": {
3637
- return {
3638
- type: "input_file",
3639
- file_url: item.url,
3640
- ...promptCacheBreakpoint != null && {
3641
- prompt_cache_breakpoint: promptCacheBreakpoint
3642
- }
3643
- };
3644
- }
3645
- default: {
3646
- warnings.push({
3647
- type: "other",
3648
- message: `unsupported tool content part type: ${item.type}`
3649
- });
3650
- return void 0;
3651
- }
3652
- }
3653
- }).filter(isNonNullable);
3654
- break;
3655
- }
3865
+ const contentValue = await convertFunctionToolResultOutput({
3866
+ output,
3867
+ providerOptionsName,
3868
+ warnings
3869
+ });
3656
3870
  input.push({
3657
3871
  type: "function_call_output",
3658
3872
  call_id: part.toolCallId,
@@ -5236,7 +5450,7 @@ async function prepareResponsesTools({
5236
5450
  toolNameMapping,
5237
5451
  customProviderToolNames
5238
5452
  }) {
5239
- var _a, _b, _c;
5453
+ var _a, _b, _c, _d;
5240
5454
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
5241
5455
  const toolWarnings = [];
5242
5456
  if (tools == null) {
@@ -5245,6 +5459,20 @@ async function prepareResponsesTools({
5245
5459
  const openaiTools = [];
5246
5460
  const namespaceTools = /* @__PURE__ */ new Map();
5247
5461
  const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
5462
+ const allowedToolResolutions = /* @__PURE__ */ new Map();
5463
+ const allowedToolAliases = /* @__PURE__ */ new Map();
5464
+ const recordAllowedTool = (toolName, resolution, canonicalName) => {
5465
+ allowedToolResolutions.set(toolName, resolution);
5466
+ if (canonicalName == null || canonicalName === toolName) {
5467
+ return;
5468
+ }
5469
+ const existingAlias = allowedToolAliases.get(canonicalName);
5470
+ if (existingAlias == null) {
5471
+ allowedToolAliases.set(canonicalName, resolution);
5472
+ } else if (existingAlias !== "ambiguous" && !isSameAllowedTool(existingAlias, resolution)) {
5473
+ allowedToolAliases.set(canonicalName, "ambiguous");
5474
+ }
5475
+ };
5248
5476
  for (const tool of tools) {
5249
5477
  switch (tool.type) {
5250
5478
  case "function": {
@@ -5274,9 +5502,24 @@ async function prepareResponsesTools({
5274
5502
  }
5275
5503
  namespaceTool.tools.push(openaiFunctionTool);
5276
5504
  }
5505
+ recordAllowedTool(
5506
+ tool.name,
5507
+ namespace != null ? {
5508
+ supported: false,
5509
+ reason: "tools inside an OpenAI tool namespace are not visible to tool_choice.allowed_tools"
5510
+ } : (openaiOptions == null ? void 0 : openaiOptions.deferLoading) === true ? {
5511
+ supported: false,
5512
+ reason: "deferred tools are not visible to tool_choice.allowed_tools"
5513
+ } : {
5514
+ supported: true,
5515
+ entry: { type: "function", name: tool.name }
5516
+ },
5517
+ void 0
5518
+ );
5277
5519
  break;
5278
5520
  }
5279
5521
  case "provider": {
5522
+ const openaiToolCountBefore = openaiTools.length;
5280
5523
  switch (tool.id) {
5281
5524
  case "openai.file_search": {
5282
5525
  const args = await validateTypes2({
@@ -5437,6 +5680,14 @@ async function prepareResponsesTools({
5437
5680
  break;
5438
5681
  }
5439
5682
  }
5683
+ if (openaiTools.length > openaiToolCountBefore) {
5684
+ const openaiTool = openaiTools[openaiToolCountBefore];
5685
+ recordAllowedTool(
5686
+ tool.name,
5687
+ toAllowedToolResolution(openaiTool),
5688
+ toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(tool.name)
5689
+ );
5690
+ }
5440
5691
  break;
5441
5692
  }
5442
5693
  default:
@@ -5448,18 +5699,63 @@ async function prepareResponsesTools({
5448
5699
  }
5449
5700
  }
5450
5701
  if (allowedTools != null) {
5702
+ const allowedToolEntries = [];
5703
+ const droppedToolNames = [];
5704
+ for (const name of allowedTools.toolNames) {
5705
+ const directResolution = allowedToolResolutions.get(name);
5706
+ const resolution = directResolution != null ? directResolution : allowedToolAliases.get(name);
5707
+ if (directResolution != null && allowedToolAliases.has(name)) {
5708
+ toolWarnings.push({
5709
+ type: "unsupported",
5710
+ feature: `allowedTools entry "${name}"`,
5711
+ 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"
5712
+ });
5713
+ }
5714
+ if (resolution === "ambiguous") {
5715
+ toolWarnings.push({
5716
+ type: "unsupported",
5717
+ feature: `allowedTools entry "${name}"`,
5718
+ details: "several tools in this request share this provider tool name; use the tool name from the tools for this request instead"
5719
+ });
5720
+ droppedToolNames.push(name);
5721
+ continue;
5722
+ }
5723
+ if (resolution == null) {
5724
+ toolWarnings.push({
5725
+ type: "unsupported",
5726
+ feature: `allowedTools entry "${name}"`,
5727
+ details: "the tool is not part of the tools for this request and is sent as a function tool"
5728
+ });
5729
+ allowedToolEntries.push({
5730
+ type: "function",
5731
+ name: (_b = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _b : name
5732
+ });
5733
+ continue;
5734
+ }
5735
+ if (!resolution.supported) {
5736
+ toolWarnings.push({
5737
+ type: "unsupported",
5738
+ feature: `allowedTools entry "${name}"`,
5739
+ details: `${resolution.reason}; the tool is removed from the allowed tools`
5740
+ });
5741
+ droppedToolNames.push(name);
5742
+ continue;
5743
+ }
5744
+ allowedToolEntries.push(resolution.entry);
5745
+ }
5746
+ if (allowedToolEntries.length === 0) {
5747
+ throw new UnsupportedFunctionalityError5({
5748
+ functionality: `allowedTools with only tools that cannot be allow-listed (${droppedToolNames.join(
5749
+ ", "
5750
+ )})`
5751
+ });
5752
+ }
5451
5753
  return {
5452
5754
  tools: openaiTools,
5453
5755
  toolChoice: {
5454
5756
  type: "allowed_tools",
5455
- mode: (_b = allowedTools.mode) != null ? _b : "auto",
5456
- tools: allowedTools.toolNames.map((name) => {
5457
- var _a2;
5458
- return {
5459
- type: "function",
5460
- name: (_a2 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _a2 : name
5461
- };
5462
- })
5757
+ mode: (_c = allowedTools.mode) != null ? _c : "auto",
5758
+ tools: allowedToolEntries
5463
5759
  },
5464
5760
  toolWarnings
5465
5761
  };
@@ -5474,7 +5770,7 @@ async function prepareResponsesTools({
5474
5770
  case "required":
5475
5771
  return { tools: openaiTools, toolChoice: type, toolWarnings };
5476
5772
  case "tool": {
5477
- const resolvedToolName = (_c = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _c : toolChoice.toolName;
5773
+ const resolvedToolName = (_d = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _d : toolChoice.toolName;
5478
5774
  return {
5479
5775
  tools: openaiTools,
5480
5776
  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 },
@@ -5489,6 +5785,51 @@ async function prepareResponsesTools({
5489
5785
  }
5490
5786
  }
5491
5787
  }
5788
+ function allowedToolKey(entry) {
5789
+ switch (entry.type) {
5790
+ case "mcp":
5791
+ return `mcp:${entry.server_label}`;
5792
+ case "function":
5793
+ case "custom":
5794
+ return `${entry.type}:${entry.name}`;
5795
+ default:
5796
+ return entry.type;
5797
+ }
5798
+ }
5799
+ function isSameAllowedTool(a, b) {
5800
+ if (a.supported && b.supported) {
5801
+ return allowedToolKey(a.entry) === allowedToolKey(b.entry);
5802
+ }
5803
+ if (!a.supported && !b.supported) {
5804
+ return a.reason === b.reason;
5805
+ }
5806
+ return false;
5807
+ }
5808
+ function toAllowedToolResolution(tool) {
5809
+ switch (tool.type) {
5810
+ case "custom":
5811
+ return { supported: true, entry: { type: "custom", name: tool.name } };
5812
+ case "mcp":
5813
+ return {
5814
+ supported: true,
5815
+ entry: { type: "mcp", server_label: tool.server_label }
5816
+ };
5817
+ case "file_search":
5818
+ case "web_search":
5819
+ case "web_search_preview":
5820
+ case "image_generation":
5821
+ case "code_interpreter":
5822
+ case "apply_patch":
5823
+ case "shell":
5824
+ case "local_shell":
5825
+ return { supported: true, entry: { type: tool.type } };
5826
+ default:
5827
+ return {
5828
+ supported: false,
5829
+ reason: `OpenAI does not support ${tool.type} tools in tool_choice.allowed_tools`
5830
+ };
5831
+ }
5832
+ }
5492
5833
  function prepareFunctionTool({
5493
5834
  tool,
5494
5835
  options
@@ -5847,7 +6188,7 @@ var OpenAIResponsesLanguageModel = class {
5847
6188
  };
5848
6189
  }
5849
6190
  async doGenerate(options) {
5850
- 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;
6191
+ 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;
5851
6192
  const {
5852
6193
  args: body,
5853
6194
  warnings,
@@ -5889,6 +6230,9 @@ var OpenAIResponsesLanguageModel = class {
5889
6230
  }
5890
6231
  const content = [];
5891
6232
  const logprobs = [];
6233
+ const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
6234
+ (tool) => tool.type === "function"
6235
+ )) != null ? _b : [];
5892
6236
  let hasFunctionCall = false;
5893
6237
  const hostedToolSearchCallIds = [];
5894
6238
  for (const part of response.output) {
@@ -5904,7 +6248,7 @@ var OpenAIResponsesLanguageModel = class {
5904
6248
  providerMetadata: {
5905
6249
  [providerOptionsName]: {
5906
6250
  itemId: part.id,
5907
- reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
6251
+ reasoningEncryptedContent: (_c = part.encrypted_content) != null ? _c : null
5908
6252
  }
5909
6253
  }
5910
6254
  });
@@ -5930,7 +6274,7 @@ var OpenAIResponsesLanguageModel = class {
5930
6274
  break;
5931
6275
  }
5932
6276
  case "tool_search_call": {
5933
- const toolCallId = (_b = part.call_id) != null ? _b : part.id;
6277
+ const toolCallId = (_d = part.call_id) != null ? _d : part.id;
5934
6278
  const isHosted = part.execution === "server";
5935
6279
  if (isHosted) {
5936
6280
  hostedToolSearchCallIds.push(toolCallId);
@@ -5953,7 +6297,7 @@ var OpenAIResponsesLanguageModel = class {
5953
6297
  break;
5954
6298
  }
5955
6299
  case "tool_search_output": {
5956
- const toolCallId = (_d = (_c = part.call_id) != null ? _c : hostedToolSearchCallIds.shift()) != null ? _d : part.id;
6300
+ const toolCallId = (_f = (_e = part.call_id) != null ? _e : hostedToolSearchCallIds.shift()) != null ? _f : part.id;
5957
6301
  content.push({
5958
6302
  type: "tool-result",
5959
6303
  toolCallId,
@@ -6024,7 +6368,7 @@ var OpenAIResponsesLanguageModel = class {
6024
6368
  }
6025
6369
  case "message": {
6026
6370
  for (const contentPart of part.content) {
6027
- if (((_f = (_e = options.providerOptions) == null ? void 0 : _e[providerOptionsName]) == null ? void 0 : _f.logprobs) && contentPart.logprobs) {
6371
+ if (((_h = (_g = options.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.logprobs) && contentPart.logprobs) {
6028
6372
  logprobs.push(contentPart.logprobs);
6029
6373
  }
6030
6374
  const providerMetadata2 = {
@@ -6046,7 +6390,7 @@ var OpenAIResponsesLanguageModel = class {
6046
6390
  content.push({
6047
6391
  type: "source",
6048
6392
  sourceType: "url",
6049
- id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : generateId2(),
6393
+ id: (_k = (_j = (_i = this.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : generateId2(),
6050
6394
  url: annotation.url,
6051
6395
  title: annotation.title
6052
6396
  });
@@ -6054,7 +6398,7 @@ var OpenAIResponsesLanguageModel = class {
6054
6398
  content.push({
6055
6399
  type: "source",
6056
6400
  sourceType: "document",
6057
- id: (_l = (_k = (_j = this.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId2(),
6401
+ id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
6058
6402
  mediaType: "text/plain",
6059
6403
  title: annotation.filename,
6060
6404
  filename: annotation.filename,
@@ -6070,7 +6414,7 @@ var OpenAIResponsesLanguageModel = class {
6070
6414
  content.push({
6071
6415
  type: "source",
6072
6416
  sourceType: "document",
6073
- id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2(),
6417
+ id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
6074
6418
  mediaType: "text/plain",
6075
6419
  title: annotation.filename,
6076
6420
  filename: annotation.filename,
@@ -6086,7 +6430,7 @@ var OpenAIResponsesLanguageModel = class {
6086
6430
  content.push({
6087
6431
  type: "source",
6088
6432
  sourceType: "document",
6089
- id: (_r = (_q = (_p = this.config).generateId) == null ? void 0 : _q.call(_p)) != null ? _r : generateId2(),
6433
+ id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
6090
6434
  mediaType: "application/octet-stream",
6091
6435
  title: annotation.file_id,
6092
6436
  filename: annotation.file_id,
@@ -6105,6 +6449,20 @@ var OpenAIResponsesLanguageModel = class {
6105
6449
  }
6106
6450
  case "function_call": {
6107
6451
  hasFunctionCall = true;
6452
+ const expandedToolCalls = await expandParallelToolCall({
6453
+ toolCall: {
6454
+ toolCallId: part.call_id,
6455
+ toolName: part.name,
6456
+ input: part.arguments
6457
+ },
6458
+ tools: functionTools,
6459
+ providerOptionsName,
6460
+ itemId: part.id
6461
+ });
6462
+ if (expandedToolCalls != null) {
6463
+ content.push(...expandedToolCalls);
6464
+ break;
6465
+ }
6108
6466
  content.push({
6109
6467
  type: "tool-call",
6110
6468
  toolCallId: part.call_id,
@@ -6156,7 +6514,7 @@ var OpenAIResponsesLanguageModel = class {
6156
6514
  break;
6157
6515
  }
6158
6516
  case "mcp_call": {
6159
- const toolCallId = part.approval_request_id != null ? (_s = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _s : part.id : part.id;
6517
+ const toolCallId = part.approval_request_id != null ? (_u = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _u : part.id : part.id;
6160
6518
  const toolName = `mcp.${part.name}`;
6161
6519
  content.push({
6162
6520
  type: "tool-call",
@@ -6190,8 +6548,8 @@ var OpenAIResponsesLanguageModel = class {
6190
6548
  break;
6191
6549
  }
6192
6550
  case "mcp_approval_request": {
6193
- const approvalRequestId = (_t = part.approval_request_id) != null ? _t : part.id;
6194
- const dummyToolCallId = (_w = (_v = (_u = this.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2();
6551
+ const approvalRequestId = (_v = part.approval_request_id) != null ? _v : part.id;
6552
+ const dummyToolCallId = (_y = (_x = (_w = this.config).generateId) == null ? void 0 : _x.call(_w)) != null ? _y : generateId2();
6195
6553
  const toolName = `mcp.${part.name}`;
6196
6554
  content.push({
6197
6555
  type: "tool-call",
@@ -6241,13 +6599,13 @@ var OpenAIResponsesLanguageModel = class {
6241
6599
  toolName: toolNameMapping.toCustomToolName("file_search"),
6242
6600
  result: {
6243
6601
  queries: part.queries,
6244
- results: (_y = (_x = part.results) == null ? void 0 : _x.map((result) => ({
6602
+ results: (_A = (_z = part.results) == null ? void 0 : _z.map((result) => ({
6245
6603
  attributes: result.attributes,
6246
6604
  fileId: result.file_id,
6247
6605
  filename: result.filename,
6248
6606
  score: result.score,
6249
6607
  text: result.text
6250
- }))) != null ? _y : null
6608
+ }))) != null ? _A : null
6251
6609
  }
6252
6610
  });
6253
6611
  break;
@@ -6297,7 +6655,7 @@ var OpenAIResponsesLanguageModel = class {
6297
6655
  responseId: response.id,
6298
6656
  ...logprobs.length > 0 ? { logprobs } : {},
6299
6657
  ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
6300
- ...((_z = response.reasoning) == null ? void 0 : _z.context) != null ? { reasoningContext: response.reasoning.context } : {}
6658
+ ...((_B = response.reasoning) == null ? void 0 : _B.context) != null ? { reasoningContext: response.reasoning.context } : {}
6301
6659
  }
6302
6660
  };
6303
6661
  const usage = response.usage;
@@ -6305,10 +6663,10 @@ var OpenAIResponsesLanguageModel = class {
6305
6663
  content,
6306
6664
  finishReason: {
6307
6665
  unified: mapOpenAIResponseFinishReason({
6308
- finishReason: (_A = response.incomplete_details) == null ? void 0 : _A.reason,
6666
+ finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
6309
6667
  hasFunctionCall
6310
6668
  }),
6311
- raw: (_C = (_B = response.incomplete_details) == null ? void 0 : _B.reason) != null ? _C : void 0
6669
+ raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
6312
6670
  },
6313
6671
  usage: convertOpenAIResponsesUsage(usage),
6314
6672
  request: { body },
@@ -6324,6 +6682,7 @@ var OpenAIResponsesLanguageModel = class {
6324
6682
  };
6325
6683
  }
6326
6684
  async doStream(options) {
6685
+ var _a, _b;
6327
6686
  const {
6328
6687
  args: body,
6329
6688
  warnings,
@@ -6361,6 +6720,9 @@ var OpenAIResponsesLanguageModel = class {
6361
6720
  });
6362
6721
  const self = this;
6363
6722
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
6723
+ const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
6724
+ (tool) => tool.type === "function"
6725
+ )) != null ? _b : [];
6364
6726
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
6365
6727
  let finishReason = {
6366
6728
  unified: "other",
@@ -6385,7 +6747,7 @@ var OpenAIResponsesLanguageModel = class {
6385
6747
  controller.enqueue({ type: "stream-start", warnings });
6386
6748
  },
6387
6749
  transform(chunk, controller) {
6388
- 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;
6750
+ 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;
6389
6751
  if (options.includeRawChunks) {
6390
6752
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
6391
6753
  }
@@ -6404,15 +6766,23 @@ var OpenAIResponsesLanguageModel = class {
6404
6766
  const value = chunk.value;
6405
6767
  if (isResponseOutputItemAddedChunk(value)) {
6406
6768
  if (value.item.type === "function_call") {
6769
+ const suppressInputStreaming = isUndeclaredParallelToolCall({
6770
+ toolName: value.item.name,
6771
+ tools: functionTools
6772
+ });
6407
6773
  ongoingToolCalls[value.output_index] = {
6408
6774
  toolName: value.item.name,
6409
- toolCallId: value.item.call_id
6775
+ toolCallId: value.item.call_id,
6776
+ suppressInputStreaming,
6777
+ bufferedInputDeltas: suppressInputStreaming ? [] : void 0
6410
6778
  };
6411
- controller.enqueue({
6412
- type: "tool-input-start",
6413
- id: value.item.call_id,
6414
- toolName: value.item.name
6415
- });
6779
+ if (!suppressInputStreaming) {
6780
+ controller.enqueue({
6781
+ type: "tool-input-start",
6782
+ id: value.item.call_id,
6783
+ toolName: value.item.name
6784
+ });
6785
+ }
6416
6786
  } else if (value.item.type === "custom_tool_call") {
6417
6787
  const toolName = toolNameMapping.toCustomToolName(
6418
6788
  value.item.name
@@ -6507,7 +6877,7 @@ var OpenAIResponsesLanguageModel = class {
6507
6877
  ongoingToolCalls[value.output_index] = {
6508
6878
  toolName,
6509
6879
  toolCallId,
6510
- toolSearchExecution: (_a = value.item.execution) != null ? _a : "server"
6880
+ toolSearchExecution: (_a2 = value.item.execution) != null ? _a2 : "server"
6511
6881
  };
6512
6882
  if (isHosted) {
6513
6883
  controller.enqueue({
@@ -6564,7 +6934,7 @@ var OpenAIResponsesLanguageModel = class {
6564
6934
  } else if (value.item.type === "shell_call_output") {
6565
6935
  } else if (value.item.type === "message") {
6566
6936
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
6567
- activeMessagePhase = (_b = value.item.phase) != null ? _b : void 0;
6937
+ activeMessagePhase = (_b2 = value.item.phase) != null ? _b2 : void 0;
6568
6938
  controller.enqueue({
6569
6939
  type: "text-start",
6570
6940
  id: value.item.id,
@@ -6611,31 +6981,99 @@ var OpenAIResponsesLanguageModel = class {
6611
6981
  }
6612
6982
  });
6613
6983
  } else if (value.item.type === "function_call") {
6984
+ const item = value.item;
6985
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
6614
6986
  ongoingToolCalls[value.output_index] = void 0;
6615
6987
  hasFunctionCall = true;
6616
- controller.enqueue({
6617
- type: "tool-input-end",
6618
- id: value.item.call_id,
6619
- ...value.item.namespace != null && {
6620
- providerMetadata: {
6621
- [providerOptionsName]: {
6622
- namespace: value.item.namespace
6988
+ const suppressInputStreaming = (_e = ongoingToolCall == null ? void 0 : ongoingToolCall.suppressInputStreaming) != null ? _e : isUndeclaredParallelToolCall({
6989
+ toolName: item.name,
6990
+ tools: functionTools
6991
+ });
6992
+ const enqueueUnexpandedToolCall = () => {
6993
+ var _a3;
6994
+ if (suppressInputStreaming) {
6995
+ controller.enqueue({
6996
+ type: "tool-input-start",
6997
+ id: item.call_id,
6998
+ toolName: item.name
6999
+ });
7000
+ const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
7001
+ if (bufferedInputDeltas.length > 0) {
7002
+ for (const delta of bufferedInputDeltas) {
7003
+ controller.enqueue({
7004
+ type: "tool-input-delta",
7005
+ id: item.call_id,
7006
+ delta
7007
+ });
6623
7008
  }
7009
+ } else if (item.arguments.length > 0) {
7010
+ controller.enqueue({
7011
+ type: "tool-input-delta",
7012
+ id: item.call_id,
7013
+ delta: item.arguments
7014
+ });
6624
7015
  }
6625
7016
  }
6626
- });
6627
- controller.enqueue({
6628
- type: "tool-call",
6629
- toolCallId: value.item.call_id,
6630
- toolName: value.item.name,
6631
- input: value.item.arguments,
6632
- providerMetadata: {
6633
- [providerOptionsName]: {
6634
- itemId: value.item.id,
6635
- ...value.item.namespace != null && {
6636
- namespace: value.item.namespace
7017
+ controller.enqueue({
7018
+ type: "tool-input-end",
7019
+ id: item.call_id,
7020
+ ...item.namespace != null && {
7021
+ providerMetadata: {
7022
+ [providerOptionsName]: {
7023
+ namespace: item.namespace
7024
+ }
6637
7025
  }
6638
7026
  }
7027
+ });
7028
+ controller.enqueue({
7029
+ type: "tool-call",
7030
+ toolCallId: item.call_id,
7031
+ toolName: item.name,
7032
+ input: item.arguments,
7033
+ providerMetadata: {
7034
+ [providerOptionsName]: {
7035
+ itemId: item.id,
7036
+ ...item.namespace != null && {
7037
+ namespace: item.namespace
7038
+ }
7039
+ }
7040
+ }
7041
+ });
7042
+ };
7043
+ if (!suppressInputStreaming) {
7044
+ enqueueUnexpandedToolCall();
7045
+ return;
7046
+ }
7047
+ return expandParallelToolCall({
7048
+ toolCall: {
7049
+ toolCallId: item.call_id,
7050
+ toolName: item.name,
7051
+ input: item.arguments
7052
+ },
7053
+ tools: functionTools,
7054
+ providerOptionsName,
7055
+ itemId: item.id
7056
+ }).then((expandedToolCalls) => {
7057
+ if (expandedToolCalls == null) {
7058
+ enqueueUnexpandedToolCall();
7059
+ return;
7060
+ }
7061
+ for (const toolCall of expandedToolCalls) {
7062
+ controller.enqueue({
7063
+ type: "tool-input-start",
7064
+ id: toolCall.toolCallId,
7065
+ toolName: toolCall.toolName
7066
+ });
7067
+ controller.enqueue({
7068
+ type: "tool-input-delta",
7069
+ id: toolCall.toolCallId,
7070
+ delta: toolCall.input
7071
+ });
7072
+ controller.enqueue({
7073
+ type: "tool-input-end",
7074
+ id: toolCall.toolCallId
7075
+ });
7076
+ controller.enqueue(toolCall);
6639
7077
  }
6640
7078
  });
6641
7079
  } else if (value.item.type === "custom_tool_call") {
@@ -6699,13 +7137,13 @@ var OpenAIResponsesLanguageModel = class {
6699
7137
  toolName: toolNameMapping.toCustomToolName("file_search"),
6700
7138
  result: {
6701
7139
  queries: value.item.queries,
6702
- results: (_f = (_e = value.item.results) == null ? void 0 : _e.map((result2) => ({
7140
+ results: (_g = (_f = value.item.results) == null ? void 0 : _f.map((result2) => ({
6703
7141
  attributes: result2.attributes,
6704
7142
  fileId: result2.file_id,
6705
7143
  filename: result2.filename,
6706
7144
  score: result2.score,
6707
7145
  text: result2.text
6708
- }))) != null ? _f : null
7146
+ }))) != null ? _g : null
6709
7147
  }
6710
7148
  });
6711
7149
  } else if (value.item.type === "code_interpreter_call") {
@@ -6731,7 +7169,7 @@ var OpenAIResponsesLanguageModel = class {
6731
7169
  const toolCall = ongoingToolCalls[value.output_index];
6732
7170
  const isHosted = value.item.execution === "server";
6733
7171
  if (toolCall != null) {
6734
- const toolCallId = isHosted ? toolCall.toolCallId : (_g = value.item.call_id) != null ? _g : value.item.id;
7172
+ const toolCallId = isHosted ? toolCall.toolCallId : (_h = value.item.call_id) != null ? _h : value.item.id;
6735
7173
  if (isHosted) {
6736
7174
  hostedToolSearchCallIds.push(toolCallId);
6737
7175
  } else {
@@ -6763,7 +7201,7 @@ var OpenAIResponsesLanguageModel = class {
6763
7201
  }
6764
7202
  ongoingToolCalls[value.output_index] = void 0;
6765
7203
  } else if (value.item.type === "tool_search_output") {
6766
- const toolCallId = (_i = (_h = value.item.call_id) != null ? _h : hostedToolSearchCallIds.shift()) != null ? _i : value.item.id;
7204
+ const toolCallId = (_j = (_i = value.item.call_id) != null ? _i : hostedToolSearchCallIds.shift()) != null ? _j : value.item.id;
6767
7205
  controller.enqueue({
6768
7206
  type: "tool-result",
6769
7207
  toolCallId,
@@ -6779,10 +7217,10 @@ var OpenAIResponsesLanguageModel = class {
6779
7217
  });
6780
7218
  } else if (value.item.type === "mcp_call") {
6781
7219
  ongoingToolCalls[value.output_index] = void 0;
6782
- const approvalRequestId = (_j = value.item.approval_request_id) != null ? _j : void 0;
6783
- const aliasedToolCallId = approvalRequestId != null ? (_l = (_k = approvalRequestIdToDummyToolCallIdFromStream.get(
7220
+ const approvalRequestId = (_k = value.item.approval_request_id) != null ? _k : void 0;
7221
+ const aliasedToolCallId = approvalRequestId != null ? (_m = (_l = approvalRequestIdToDummyToolCallIdFromStream.get(
6784
7222
  approvalRequestId
6785
- )) != null ? _k : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _l : value.item.id : value.item.id;
7223
+ )) != null ? _l : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _m : value.item.id : value.item.id;
6786
7224
  const toolName = `mcp.${value.item.name}`;
6787
7225
  controller.enqueue({
6788
7226
  type: "tool-call",
@@ -6852,8 +7290,8 @@ var OpenAIResponsesLanguageModel = class {
6852
7290
  ongoingToolCalls[value.output_index] = void 0;
6853
7291
  } else if (value.item.type === "mcp_approval_request") {
6854
7292
  ongoingToolCalls[value.output_index] = void 0;
6855
- const dummyToolCallId = (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2();
6856
- const approvalRequestId = (_p = value.item.approval_request_id) != null ? _p : value.item.id;
7293
+ const dummyToolCallId = (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2();
7294
+ const approvalRequestId = (_q = value.item.approval_request_id) != null ? _q : value.item.id;
6857
7295
  approvalRequestIdToDummyToolCallIdFromStream.set(
6858
7296
  approvalRequestId,
6859
7297
  dummyToolCallId
@@ -6942,7 +7380,7 @@ var OpenAIResponsesLanguageModel = class {
6942
7380
  providerMetadata: {
6943
7381
  [providerOptionsName]: {
6944
7382
  itemId: value.item.id,
6945
- reasoningEncryptedContent: (_q = value.item.encrypted_content) != null ? _q : null
7383
+ reasoningEncryptedContent: (_r = value.item.encrypted_content) != null ? _r : null
6946
7384
  }
6947
7385
  }
6948
7386
  });
@@ -6952,11 +7390,15 @@ var OpenAIResponsesLanguageModel = class {
6952
7390
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
6953
7391
  const toolCall = ongoingToolCalls[value.output_index];
6954
7392
  if (toolCall != null) {
6955
- controller.enqueue({
6956
- type: "tool-input-delta",
6957
- id: toolCall.toolCallId,
6958
- delta: value.delta
6959
- });
7393
+ if (toolCall.suppressInputStreaming) {
7394
+ (_s = toolCall.bufferedInputDeltas) == null ? void 0 : _s.push(value.delta);
7395
+ } else {
7396
+ controller.enqueue({
7397
+ type: "tool-input-delta",
7398
+ id: toolCall.toolCallId,
7399
+ delta: value.delta
7400
+ });
7401
+ }
6960
7402
  }
6961
7403
  } else if (isResponseCustomToolCallInputDeltaChunk(value)) {
6962
7404
  const toolCall = ongoingToolCalls[value.output_index];
@@ -7055,7 +7497,7 @@ var OpenAIResponsesLanguageModel = class {
7055
7497
  id: value.item_id,
7056
7498
  delta: value.delta
7057
7499
  });
7058
- if (((_s = (_r = options.providerOptions) == null ? void 0 : _r[providerOptionsName]) == null ? void 0 : _s.logprobs) && value.logprobs) {
7500
+ if (((_u = (_t = options.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.logprobs) && value.logprobs) {
7059
7501
  logprobs.push(value.logprobs);
7060
7502
  }
7061
7503
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -7084,7 +7526,7 @@ var OpenAIResponsesLanguageModel = class {
7084
7526
  providerMetadata: {
7085
7527
  [providerOptionsName]: {
7086
7528
  itemId: value.item_id,
7087
- reasoningEncryptedContent: (_u = (_t = activeReasoning[value.item_id]) == null ? void 0 : _t.encryptedContent) != null ? _u : null
7529
+ reasoningEncryptedContent: (_w = (_v = activeReasoning[value.item_id]) == null ? void 0 : _v.encryptedContent) != null ? _w : null
7088
7530
  }
7089
7531
  }
7090
7532
  });
@@ -7118,20 +7560,20 @@ var OpenAIResponsesLanguageModel = class {
7118
7560
  } else if (isResponseFinishedChunk(value)) {
7119
7561
  finishReason = {
7120
7562
  unified: mapOpenAIResponseFinishReason({
7121
- finishReason: (_v = value.response.incomplete_details) == null ? void 0 : _v.reason,
7563
+ finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
7122
7564
  hasFunctionCall
7123
7565
  }),
7124
- raw: (_x = (_w = value.response.incomplete_details) == null ? void 0 : _w.reason) != null ? _x : void 0
7566
+ raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7125
7567
  };
7126
7568
  usage = value.response.usage;
7127
7569
  if (typeof value.response.service_tier === "string") {
7128
7570
  serviceTier = value.response.service_tier;
7129
7571
  }
7130
- if (((_y = value.response.reasoning) == null ? void 0 : _y.context) != null) {
7572
+ if (((_A = value.response.reasoning) == null ? void 0 : _A.context) != null) {
7131
7573
  reasoningContext = value.response.reasoning.context;
7132
7574
  }
7133
7575
  } else if (isResponseFailedChunk(value)) {
7134
- const incompleteReason = (_z = value.response.incomplete_details) == null ? void 0 : _z.reason;
7576
+ const incompleteReason = (_B = value.response.incomplete_details) == null ? void 0 : _B.reason;
7135
7577
  finishReason = {
7136
7578
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
7137
7579
  finishReason: incompleteReason,
@@ -7139,8 +7581,8 @@ var OpenAIResponsesLanguageModel = class {
7139
7581
  }) : "error",
7140
7582
  raw: incompleteReason != null ? incompleteReason : "error"
7141
7583
  };
7142
- usage = (_A = value.response.usage) != null ? _A : void 0;
7143
- if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
7584
+ usage = (_C = value.response.usage) != null ? _C : void 0;
7585
+ if (((_D = value.response.reasoning) == null ? void 0 : _D.context) != null) {
7144
7586
  reasoningContext = value.response.reasoning.context;
7145
7587
  }
7146
7588
  if (!encounteredStreamError && value.response.error != null) {
@@ -7164,7 +7606,7 @@ var OpenAIResponsesLanguageModel = class {
7164
7606
  controller.enqueue({
7165
7607
  type: "source",
7166
7608
  sourceType: "url",
7167
- id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : generateId2(),
7609
+ id: (_G = (_F = (_E = self.config).generateId) == null ? void 0 : _F.call(_E)) != null ? _G : generateId2(),
7168
7610
  url: value.annotation.url,
7169
7611
  title: value.annotation.title
7170
7612
  });
@@ -7172,7 +7614,7 @@ var OpenAIResponsesLanguageModel = class {
7172
7614
  controller.enqueue({
7173
7615
  type: "source",
7174
7616
  sourceType: "document",
7175
- id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
7617
+ id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : generateId2(),
7176
7618
  mediaType: "text/plain",
7177
7619
  title: value.annotation.filename,
7178
7620
  filename: value.annotation.filename,
@@ -7188,7 +7630,7 @@ var OpenAIResponsesLanguageModel = class {
7188
7630
  controller.enqueue({
7189
7631
  type: "source",
7190
7632
  sourceType: "document",
7191
- id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
7633
+ id: (_M = (_L = (_K = self.config).generateId) == null ? void 0 : _L.call(_K)) != null ? _M : generateId2(),
7192
7634
  mediaType: "text/plain",
7193
7635
  title: value.annotation.filename,
7194
7636
  filename: value.annotation.filename,
@@ -7204,7 +7646,7 @@ var OpenAIResponsesLanguageModel = class {
7204
7646
  controller.enqueue({
7205
7647
  type: "source",
7206
7648
  sourceType: "document",
7207
- id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
7649
+ id: (_P = (_O = (_N = self.config).generateId) == null ? void 0 : _O.call(_N)) != null ? _P : generateId2(),
7208
7650
  mediaType: "application/octet-stream",
7209
7651
  title: value.annotation.file_id,
7210
7652
  filename: value.annotation.file_id,
@@ -7224,6 +7666,24 @@ var OpenAIResponsesLanguageModel = class {
7224
7666
  }
7225
7667
  },
7226
7668
  flush(controller) {
7669
+ var _a2;
7670
+ for (const toolCall of Object.values(ongoingToolCalls)) {
7671
+ if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
7672
+ continue;
7673
+ }
7674
+ controller.enqueue({
7675
+ type: "tool-input-start",
7676
+ id: toolCall.toolCallId,
7677
+ toolName: toolCall.toolName
7678
+ });
7679
+ for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
7680
+ controller.enqueue({
7681
+ type: "tool-input-delta",
7682
+ id: toolCall.toolCallId,
7683
+ delta
7684
+ });
7685
+ }
7686
+ }
7227
7687
  const providerMetadata = {
7228
7688
  [providerOptionsName]: {
7229
7689
  responseId,