@ai-sdk/openai 4.0.44 → 4.0.46

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.
@@ -3438,6 +3438,84 @@ var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCall
3438
3438
  }
3439
3439
  });
3440
3440
 
3441
+ // src/responses/expand-parallel-tool-call.ts
3442
+ import {
3443
+ isJSONObject
3444
+ } from "@ai-sdk/provider";
3445
+ import { safeParseJSON as safeParseJSON2 } from "@ai-sdk/provider-utils";
3446
+ var parallelToolName = "parallel";
3447
+ var recipientNamePrefix = "functions.";
3448
+ function getParallelToolCallMetadata({
3449
+ providerOptions,
3450
+ providerOptionsName
3451
+ }) {
3452
+ var _a;
3453
+ const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
3454
+ 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) {
3455
+ return void 0;
3456
+ }
3457
+ return metadata;
3458
+ }
3459
+ function isUndeclaredParallelToolCall({
3460
+ toolName,
3461
+ tools
3462
+ }) {
3463
+ return toolName === parallelToolName && !tools.some((tool) => tool.name === parallelToolName);
3464
+ }
3465
+ async function expandParallelToolCall({
3466
+ toolCall,
3467
+ tools,
3468
+ providerOptionsName,
3469
+ itemId
3470
+ }) {
3471
+ if (!isUndeclaredParallelToolCall({ toolName: toolCall.toolName, tools })) {
3472
+ return void 0;
3473
+ }
3474
+ const parsedInput = await safeParseJSON2({ text: toolCall.input });
3475
+ if (!parsedInput.success || !isJSONObject(parsedInput.value)) {
3476
+ return void 0;
3477
+ }
3478
+ const toolUses = parsedInput.value.tool_uses;
3479
+ if (!Array.isArray(toolUses) || toolUses.length === 0) {
3480
+ return void 0;
3481
+ }
3482
+ const availableToolNames = new Set(tools.map((tool) => tool.name));
3483
+ const expandedToolCalls = [];
3484
+ for (const [index, toolUse] of toolUses.entries()) {
3485
+ if (!isJSONObject(toolUse)) {
3486
+ return void 0;
3487
+ }
3488
+ const recipientName = toolUse.recipient_name;
3489
+ const parameters = toolUse.parameters;
3490
+ if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !isJSONObject(parameters)) {
3491
+ return void 0;
3492
+ }
3493
+ const toolName = recipientName.slice(recipientNamePrefix.length);
3494
+ if (toolName.length === 0 || !availableToolNames.has(toolName)) {
3495
+ return void 0;
3496
+ }
3497
+ expandedToolCalls.push({
3498
+ type: "tool-call",
3499
+ toolCallId: `${toolCall.toolCallId}_${index}`,
3500
+ toolName,
3501
+ input: JSON.stringify(parameters),
3502
+ providerMetadata: {
3503
+ [providerOptionsName]: {
3504
+ parallelToolCall: {
3505
+ itemId,
3506
+ toolCallId: toolCall.toolCallId,
3507
+ toolName: toolCall.toolName,
3508
+ input: toolCall.input,
3509
+ index,
3510
+ count: toolUses.length
3511
+ }
3512
+ }
3513
+ }
3514
+ });
3515
+ }
3516
+ return expandedToolCalls;
3517
+ }
3518
+
3441
3519
  // src/responses/convert-to-openai-responses-input.ts
3442
3520
  function serializeToolCallArguments2(input) {
3443
3521
  return JSON.stringify(input === void 0 ? {} : input);
@@ -3445,6 +3523,160 @@ function serializeToolCallArguments2(input) {
3445
3523
  function mapToolCaller(caller) {
3446
3524
  return caller == null ? void 0 : caller.type === "program" ? { type: "program", caller_id: caller.callerId } : caller;
3447
3525
  }
3526
+ async function convertFunctionToolResultOutput({
3527
+ output,
3528
+ toolName,
3529
+ outputSchemaToolNames,
3530
+ providerOptionsName,
3531
+ warnings
3532
+ }) {
3533
+ var _a;
3534
+ const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
3535
+ switch (output.type) {
3536
+ case "text":
3537
+ case "error-text":
3538
+ return hasOutputSchema ? JSON.stringify(output.value) : output.value;
3539
+ case "execution-denied": {
3540
+ const reason = (_a = output.reason) != null ? _a : "Tool call execution denied.";
3541
+ return hasOutputSchema ? JSON.stringify(reason) : reason;
3542
+ }
3543
+ case "json":
3544
+ case "error-json":
3545
+ return JSON.stringify(output.value);
3546
+ case "content":
3547
+ return output.value.map((item) => {
3548
+ var _a2, _b, _c;
3549
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
3550
+ item.providerOptions,
3551
+ providerOptionsName
3552
+ );
3553
+ switch (item.type) {
3554
+ case "text": {
3555
+ return {
3556
+ type: "input_text",
3557
+ text: item.text,
3558
+ ...promptCacheBreakpoint != null && {
3559
+ prompt_cache_breakpoint: promptCacheBreakpoint
3560
+ }
3561
+ };
3562
+ }
3563
+ case "file": {
3564
+ const topLevel = getTopLevelMediaType2(item.mediaType);
3565
+ const imageDetail = (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail;
3566
+ if (item.data.type === "data") {
3567
+ const fullMediaType = resolveFullMediaType2({ part: item });
3568
+ if (topLevel === "image") {
3569
+ return {
3570
+ type: "input_image",
3571
+ image_url: `data:${fullMediaType};base64,${convertToBase643(item.data.data)}`,
3572
+ detail: imageDetail,
3573
+ ...promptCacheBreakpoint != null && {
3574
+ prompt_cache_breakpoint: promptCacheBreakpoint
3575
+ }
3576
+ };
3577
+ }
3578
+ return {
3579
+ type: "input_file",
3580
+ filename: (_c = item.filename) != null ? _c : "data",
3581
+ file_data: `data:${fullMediaType};base64,${convertToBase643(item.data.data)}`,
3582
+ ...promptCacheBreakpoint != null && {
3583
+ prompt_cache_breakpoint: promptCacheBreakpoint
3584
+ }
3585
+ };
3586
+ }
3587
+ if (item.data.type === "url") {
3588
+ if (topLevel === "image") {
3589
+ return {
3590
+ type: "input_image",
3591
+ image_url: item.data.url.toString(),
3592
+ detail: imageDetail,
3593
+ ...promptCacheBreakpoint != null && {
3594
+ prompt_cache_breakpoint: promptCacheBreakpoint
3595
+ }
3596
+ };
3597
+ }
3598
+ return {
3599
+ type: "input_file",
3600
+ file_url: item.data.url.toString(),
3601
+ ...promptCacheBreakpoint != null && {
3602
+ prompt_cache_breakpoint: promptCacheBreakpoint
3603
+ }
3604
+ };
3605
+ }
3606
+ warnings.push({
3607
+ type: "other",
3608
+ message: `unsupported tool content part type: ${item.type} with data type: ${item.data.type}`
3609
+ });
3610
+ return void 0;
3611
+ }
3612
+ default: {
3613
+ warnings.push({
3614
+ type: "other",
3615
+ message: `unsupported tool content part type: ${item.type}`
3616
+ });
3617
+ return void 0;
3618
+ }
3619
+ }
3620
+ }).filter(isNonNullable);
3621
+ }
3622
+ }
3623
+ function hasSameParallelToolCall(first, second) {
3624
+ return first.itemId === second.itemId && first.toolCallId === second.toolCallId && first.toolName === second.toolName && first.input === second.input && first.count === second.count;
3625
+ }
3626
+ function collectCompleteParallelToolResultGroups({
3627
+ prompt,
3628
+ providerOptionsName
3629
+ }) {
3630
+ const pendingGroups = /* @__PURE__ */ new Map();
3631
+ for (const message of prompt) {
3632
+ if (message.role !== "tool") {
3633
+ continue;
3634
+ }
3635
+ for (const part of message.content) {
3636
+ if (part.type !== "tool-result") {
3637
+ continue;
3638
+ }
3639
+ const metadata = getParallelToolCallMetadata({
3640
+ providerOptions: part.providerOptions,
3641
+ providerOptionsName
3642
+ });
3643
+ if (metadata == null) {
3644
+ continue;
3645
+ }
3646
+ const existing = pendingGroups.get(metadata.toolCallId);
3647
+ if (existing == null) {
3648
+ pendingGroups.set(metadata.toolCallId, {
3649
+ metadata,
3650
+ results: /* @__PURE__ */ new Map([[metadata.index, part]]),
3651
+ invalid: false
3652
+ });
3653
+ continue;
3654
+ }
3655
+ if (!hasSameParallelToolCall(existing.metadata, metadata) || existing.results.has(metadata.index)) {
3656
+ existing.invalid = true;
3657
+ continue;
3658
+ }
3659
+ existing.results.set(metadata.index, part);
3660
+ }
3661
+ }
3662
+ const completeGroups = /* @__PURE__ */ new Map();
3663
+ for (const [toolCallId, group] of pendingGroups) {
3664
+ if (group.invalid || group.results.size !== group.metadata.count) {
3665
+ continue;
3666
+ }
3667
+ const results = Array.from(
3668
+ { length: group.metadata.count },
3669
+ (_, index) => group.results.get(index)
3670
+ );
3671
+ if (results.every(isNonNullable)) {
3672
+ completeGroups.set(toolCallId, {
3673
+ metadata: group.metadata,
3674
+ results
3675
+ });
3676
+ }
3677
+ }
3678
+ return completeGroups;
3679
+ }
3448
3680
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
3449
3681
  var _a;
3450
3682
  return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
@@ -3470,10 +3702,16 @@ async function convertToOpenAIResponsesInput({
3470
3702
  customProviderToolNames,
3471
3703
  outputSchemaToolNames
3472
3704
  }) {
3473
- 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;
3705
+ 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;
3474
3706
  let input = [];
3475
3707
  const warnings = [];
3476
3708
  const processedApprovalIds = /* @__PURE__ */ new Set();
3709
+ const parallelToolResultGroups = hasConversation || hasPreviousResponseId ? collectCompleteParallelToolResultGroups({
3710
+ prompt,
3711
+ providerOptionsName
3712
+ }) : /* @__PURE__ */ new Map();
3713
+ const emittedParallelToolCalls = /* @__PURE__ */ new Set();
3714
+ const emittedParallelToolResults = /* @__PURE__ */ new Set();
3477
3715
  for (const { role, content, providerOptions } of prompt) {
3478
3716
  switch (role) {
3479
3717
  case "system": {
@@ -3654,6 +3892,34 @@ async function convertToOpenAIResponsesInput({
3654
3892
  break;
3655
3893
  }
3656
3894
  case "tool-call": {
3895
+ const parallelToolCallMetadata = getParallelToolCallMetadata({
3896
+ providerOptions: part.providerOptions,
3897
+ providerOptionsName
3898
+ });
3899
+ const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
3900
+ parallelToolCallMetadata.toolCallId
3901
+ );
3902
+ if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
3903
+ parallelToolResultGroup.metadata,
3904
+ parallelToolCallMetadata
3905
+ )) {
3906
+ if (!emittedParallelToolCalls.has(
3907
+ parallelToolResultGroup.metadata.toolCallId
3908
+ )) {
3909
+ emittedParallelToolCalls.add(
3910
+ parallelToolResultGroup.metadata.toolCallId
3911
+ );
3912
+ if (!hasConversation) {
3913
+ input.push({
3914
+ type: "function_call",
3915
+ call_id: parallelToolResultGroup.metadata.toolCallId,
3916
+ name: parallelToolResultGroup.metadata.toolName,
3917
+ arguments: parallelToolResultGroup.metadata.input
3918
+ });
3919
+ }
3920
+ }
3921
+ break;
3922
+ }
3657
3923
  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;
3658
3924
  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;
3659
3925
  const caller = (_m = (_l = part.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.caller;
@@ -4043,6 +4309,46 @@ async function convertToOpenAIResponsesInput({
4043
4309
  });
4044
4310
  continue;
4045
4311
  }
4312
+ const parallelToolCallMetadata = getParallelToolCallMetadata({
4313
+ providerOptions: part.providerOptions,
4314
+ providerOptionsName
4315
+ });
4316
+ const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
4317
+ parallelToolCallMetadata.toolCallId
4318
+ );
4319
+ if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
4320
+ parallelToolResultGroup.metadata,
4321
+ parallelToolCallMetadata
4322
+ )) {
4323
+ if (!emittedParallelToolResults.has(
4324
+ parallelToolResultGroup.metadata.toolCallId
4325
+ )) {
4326
+ emittedParallelToolResults.add(
4327
+ parallelToolResultGroup.metadata.toolCallId
4328
+ );
4329
+ const toolOutputs = await Promise.all(
4330
+ parallelToolResultGroup.results.map(
4331
+ async (result) => convertFunctionToolResultOutput({
4332
+ output: result.output,
4333
+ toolName: result.toolName,
4334
+ outputSchemaToolNames,
4335
+ providerOptionsName,
4336
+ warnings
4337
+ })
4338
+ )
4339
+ );
4340
+ input.push({
4341
+ type: "function_call_output",
4342
+ call_id: parallelToolResultGroup.metadata.toolCallId,
4343
+ // The internal wrapper returns one output containing the child
4344
+ // results in the same order as the original tool_uses array.
4345
+ output: toolOutputs.map(
4346
+ (output2) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
4347
+ ).join("\n")
4348
+ });
4349
+ }
4350
+ continue;
4351
+ }
4046
4352
  const output = part.output;
4047
4353
  if (output.type === "execution-denied") {
4048
4354
  const approvalId = (_G = (_F = output.providerOptions) == null ? void 0 : _F.openai) == null ? void 0 : _G.approvalId;
@@ -4233,103 +4539,15 @@ async function convertToOpenAIResponsesInput({
4233
4539
  });
4234
4540
  continue;
4235
4541
  }
4236
- let contentValue;
4237
- const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(part.toolName);
4238
- switch (output.type) {
4239
- case "text":
4240
- case "error-text":
4241
- contentValue = hasOutputSchema ? JSON.stringify(output.value) : output.value;
4242
- break;
4243
- case "execution-denied": {
4244
- const reason = (_J = output.reason) != null ? _J : "Tool call execution denied.";
4245
- contentValue = hasOutputSchema ? JSON.stringify(reason) : reason;
4246
- break;
4247
- }
4248
- case "json":
4249
- case "error-json":
4250
- contentValue = JSON.stringify(output.value);
4251
- break;
4252
- case "content":
4253
- contentValue = output.value.map((item) => {
4254
- var _a2, _b2, _c2;
4255
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
4256
- item.providerOptions,
4257
- providerOptionsName
4258
- );
4259
- switch (item.type) {
4260
- case "text": {
4261
- return {
4262
- type: "input_text",
4263
- text: item.text,
4264
- ...promptCacheBreakpoint != null && {
4265
- prompt_cache_breakpoint: promptCacheBreakpoint
4266
- }
4267
- };
4268
- }
4269
- case "file": {
4270
- const topLevel = getTopLevelMediaType2(item.mediaType);
4271
- const imageDetail = (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
4272
- if (item.data.type === "data") {
4273
- const fullMediaType = resolveFullMediaType2({
4274
- part: item
4275
- });
4276
- if (topLevel === "image") {
4277
- return {
4278
- type: "input_image",
4279
- image_url: `data:${fullMediaType};base64,${convertToBase643(item.data.data)}`,
4280
- detail: imageDetail,
4281
- ...promptCacheBreakpoint != null && {
4282
- prompt_cache_breakpoint: promptCacheBreakpoint
4283
- }
4284
- };
4285
- }
4286
- return {
4287
- type: "input_file",
4288
- filename: (_c2 = item.filename) != null ? _c2 : "data",
4289
- file_data: `data:${fullMediaType};base64,${convertToBase643(item.data.data)}`,
4290
- ...promptCacheBreakpoint != null && {
4291
- prompt_cache_breakpoint: promptCacheBreakpoint
4292
- }
4293
- };
4294
- }
4295
- if (item.data.type === "url") {
4296
- if (topLevel === "image") {
4297
- return {
4298
- type: "input_image",
4299
- image_url: item.data.url.toString(),
4300
- detail: imageDetail,
4301
- ...promptCacheBreakpoint != null && {
4302
- prompt_cache_breakpoint: promptCacheBreakpoint
4303
- }
4304
- };
4305
- }
4306
- return {
4307
- type: "input_file",
4308
- file_url: item.data.url.toString(),
4309
- ...promptCacheBreakpoint != null && {
4310
- prompt_cache_breakpoint: promptCacheBreakpoint
4311
- }
4312
- };
4313
- }
4314
- warnings.push({
4315
- type: "other",
4316
- message: `unsupported tool content part type: ${item.type} with data type: ${item.data.type}`
4317
- });
4318
- return void 0;
4319
- }
4320
- default: {
4321
- warnings.push({
4322
- type: "other",
4323
- message: `unsupported tool content part type: ${item.type}`
4324
- });
4325
- return void 0;
4326
- }
4327
- }
4328
- }).filter(isNonNullable);
4329
- break;
4330
- }
4542
+ const contentValue = await convertFunctionToolResultOutput({
4543
+ output,
4544
+ toolName: part.toolName,
4545
+ outputSchemaToolNames,
4546
+ providerOptionsName,
4547
+ warnings
4548
+ });
4331
4549
  const caller = mapToolCaller(
4332
- (_L = (_K = part.providerOptions) == null ? void 0 : _K[providerOptionsName]) == null ? void 0 : _L.caller
4550
+ (_K = (_J = part.providerOptions) == null ? void 0 : _J[providerOptionsName]) == null ? void 0 : _K.caller
4333
4551
  );
4334
4552
  input.push({
4335
4553
  type: "function_call_output",
@@ -6898,7 +7116,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6898
7116
  };
6899
7117
  }
6900
7118
  async doGenerate(options) {
6901
- 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;
7119
+ 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;
6902
7120
  const {
6903
7121
  args: body,
6904
7122
  warnings,
@@ -6952,6 +7170,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6952
7170
  }
6953
7171
  const content = [];
6954
7172
  const logprobs = [];
7173
+ const functionTools = (_e = (_d = options.tools) == null ? void 0 : _d.filter(
7174
+ (tool) => tool.type === "function"
7175
+ )) != null ? _e : [];
6955
7176
  let hasFunctionCall = false;
6956
7177
  const hostedToolSearchCallIds = [];
6957
7178
  for (const part of response.output) {
@@ -6967,7 +7188,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6967
7188
  providerMetadata: {
6968
7189
  [providerOptionsName]: {
6969
7190
  itemId: part.id,
6970
- reasoningEncryptedContent: (_d = part.encrypted_content) != null ? _d : null
7191
+ reasoningEncryptedContent: (_f = part.encrypted_content) != null ? _f : null
6971
7192
  }
6972
7193
  }
6973
7194
  });
@@ -6993,7 +7214,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6993
7214
  break;
6994
7215
  }
6995
7216
  case "tool_search_call": {
6996
- const toolCallId = (_e = part.call_id) != null ? _e : part.id;
7217
+ const toolCallId = (_g = part.call_id) != null ? _g : part.id;
6997
7218
  const isHosted = part.execution === "server";
6998
7219
  if (isHosted) {
6999
7220
  hostedToolSearchCallIds.push(toolCallId);
@@ -7016,7 +7237,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7016
7237
  break;
7017
7238
  }
7018
7239
  case "tool_search_output": {
7019
- const toolCallId = (_g = (_f = part.call_id) != null ? _f : hostedToolSearchCallIds.shift()) != null ? _g : part.id;
7240
+ const toolCallId = (_i = (_h = part.call_id) != null ? _h : hostedToolSearchCallIds.shift()) != null ? _i : part.id;
7020
7241
  content.push({
7021
7242
  type: "tool-result",
7022
7243
  toolCallId,
@@ -7087,7 +7308,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7087
7308
  }
7088
7309
  case "message": {
7089
7310
  for (const contentPart of part.content) {
7090
- if (((_i = (_h = options.providerOptions) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.logprobs) && contentPart.logprobs) {
7311
+ if (((_k = (_j = options.providerOptions) == null ? void 0 : _j[providerOptionsName]) == null ? void 0 : _k.logprobs) && contentPart.logprobs) {
7091
7312
  logprobs.push(contentPart.logprobs);
7092
7313
  }
7093
7314
  const providerMetadata2 = {
@@ -7109,7 +7330,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7109
7330
  content.push({
7110
7331
  type: "source",
7111
7332
  sourceType: "url",
7112
- id: (_l = (_k = (_j = this.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId2(),
7333
+ id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
7113
7334
  url: annotation.url,
7114
7335
  title: annotation.title
7115
7336
  });
@@ -7117,7 +7338,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7117
7338
  content.push({
7118
7339
  type: "source",
7119
7340
  sourceType: "document",
7120
- id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2(),
7341
+ id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
7121
7342
  mediaType: "text/plain",
7122
7343
  title: annotation.filename,
7123
7344
  filename: annotation.filename,
@@ -7133,7 +7354,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7133
7354
  content.push({
7134
7355
  type: "source",
7135
7356
  sourceType: "document",
7136
- id: (_r = (_q = (_p = this.config).generateId) == null ? void 0 : _q.call(_p)) != null ? _r : generateId2(),
7357
+ id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
7137
7358
  mediaType: "text/plain",
7138
7359
  title: annotation.filename,
7139
7360
  filename: annotation.filename,
@@ -7149,7 +7370,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7149
7370
  content.push({
7150
7371
  type: "source",
7151
7372
  sourceType: "document",
7152
- id: (_u = (_t = (_s = this.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : generateId2(),
7373
+ id: (_w = (_v = (_u = this.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2(),
7153
7374
  mediaType: "application/octet-stream",
7154
7375
  title: annotation.file_id,
7155
7376
  filename: annotation.file_id,
@@ -7168,6 +7389,20 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7168
7389
  }
7169
7390
  case "function_call": {
7170
7391
  hasFunctionCall = true;
7392
+ const expandedToolCalls = await expandParallelToolCall({
7393
+ toolCall: {
7394
+ toolCallId: part.call_id,
7395
+ toolName: part.name,
7396
+ input: part.arguments
7397
+ },
7398
+ tools: functionTools,
7399
+ providerOptionsName,
7400
+ itemId: part.id
7401
+ });
7402
+ if (expandedToolCalls != null) {
7403
+ content.push(...expandedToolCalls);
7404
+ break;
7405
+ }
7171
7406
  content.push({
7172
7407
  type: "tool-call",
7173
7408
  toolCallId: part.call_id,
@@ -7264,7 +7499,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7264
7499
  break;
7265
7500
  }
7266
7501
  case "mcp_call": {
7267
- const toolCallId = part.approval_request_id != null ? (_v = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _v : part.id : part.id;
7502
+ const toolCallId = part.approval_request_id != null ? (_x = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _x : part.id : part.id;
7268
7503
  const toolName = `mcp.${part.name}`;
7269
7504
  content.push({
7270
7505
  type: "tool-call",
@@ -7298,8 +7533,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7298
7533
  break;
7299
7534
  }
7300
7535
  case "mcp_approval_request": {
7301
- const approvalRequestId = (_w = part.approval_request_id) != null ? _w : part.id;
7302
- const dummyToolCallId = (_z = (_y = (_x = this.config).generateId) == null ? void 0 : _y.call(_x)) != null ? _z : generateId2();
7536
+ const approvalRequestId = (_y = part.approval_request_id) != null ? _y : part.id;
7537
+ const dummyToolCallId = (_B = (_A = (_z = this.config).generateId) == null ? void 0 : _A.call(_z)) != null ? _B : generateId2();
7303
7538
  const toolName = `mcp.${part.name}`;
7304
7539
  content.push({
7305
7540
  type: "tool-call",
@@ -7365,13 +7600,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7365
7600
  toolName: toolNameMapping.toCustomToolName("file_search"),
7366
7601
  result: {
7367
7602
  queries: part.queries,
7368
- results: (_B = (_A = part.results) == null ? void 0 : _A.map((result) => ({
7603
+ results: (_D = (_C = part.results) == null ? void 0 : _C.map((result) => ({
7369
7604
  attributes: result.attributes,
7370
7605
  fileId: result.file_id,
7371
7606
  filename: result.filename,
7372
7607
  score: result.score,
7373
7608
  text: result.text
7374
- }))) != null ? _B : null
7609
+ }))) != null ? _D : null
7375
7610
  }
7376
7611
  });
7377
7612
  break;
@@ -7435,7 +7670,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7435
7670
  responseId: response.id,
7436
7671
  ...logprobs.length > 0 ? { logprobs } : {},
7437
7672
  ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
7438
- ...((_C = response.reasoning) == null ? void 0 : _C.context) != null ? { reasoningContext: response.reasoning.context } : {}
7673
+ ...((_E = response.reasoning) == null ? void 0 : _E.context) != null ? { reasoningContext: response.reasoning.context } : {}
7439
7674
  }
7440
7675
  };
7441
7676
  const usage = response.usage;
@@ -7443,10 +7678,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7443
7678
  content,
7444
7679
  finishReason: {
7445
7680
  unified: mapOpenAIResponseFinishReason({
7446
- finishReason: (_D = response.incomplete_details) == null ? void 0 : _D.reason,
7681
+ finishReason: (_F = response.incomplete_details) == null ? void 0 : _F.reason,
7447
7682
  hasFunctionCall
7448
7683
  }),
7449
- raw: (_F = (_E = response.incomplete_details) == null ? void 0 : _E.reason) != null ? _F : void 0
7684
+ raw: (_H = (_G = response.incomplete_details) == null ? void 0 : _G.reason) != null ? _H : void 0
7450
7685
  },
7451
7686
  usage: convertOpenAIResponsesUsage(usage),
7452
7687
  request: { body },
@@ -7462,7 +7697,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7462
7697
  };
7463
7698
  }
7464
7699
  async doStream(options) {
7465
- var _a, _b;
7700
+ var _a, _b, _c, _d;
7466
7701
  const {
7467
7702
  args: body,
7468
7703
  warnings,
@@ -7501,6 +7736,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7501
7736
  });
7502
7737
  const self = this;
7503
7738
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
7739
+ const functionTools = (_d = (_c = options.tools) == null ? void 0 : _c.filter(
7740
+ (tool) => tool.type === "function"
7741
+ )) != null ? _d : [];
7504
7742
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
7505
7743
  let finishReason = {
7506
7744
  unified: "other",
@@ -7533,7 +7771,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7533
7771
  controller.enqueue({ type: "stream-start", warnings });
7534
7772
  },
7535
7773
  transform(chunk, controller) {
7536
- 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;
7774
+ var _a2, _b2, _c2, _d2, _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;
7537
7775
  if (options.includeRawChunks) {
7538
7776
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
7539
7777
  }
@@ -7552,15 +7790,23 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7552
7790
  const value = chunk.value;
7553
7791
  if (isResponseOutputItemAddedChunk(value)) {
7554
7792
  if (value.item.type === "function_call") {
7793
+ const suppressInputStreaming = isUndeclaredParallelToolCall({
7794
+ toolName: value.item.name,
7795
+ tools: functionTools
7796
+ });
7555
7797
  ongoingToolCalls[value.output_index] = {
7556
7798
  toolName: value.item.name,
7557
- toolCallId: value.item.call_id
7799
+ toolCallId: value.item.call_id,
7800
+ suppressInputStreaming,
7801
+ bufferedInputDeltas: suppressInputStreaming ? [] : void 0
7558
7802
  };
7559
- controller.enqueue({
7560
- type: "tool-input-start",
7561
- id: value.item.call_id,
7562
- toolName: value.item.name
7563
- });
7803
+ if (!suppressInputStreaming) {
7804
+ controller.enqueue({
7805
+ type: "tool-input-start",
7806
+ id: value.item.call_id,
7807
+ toolName: value.item.name
7808
+ });
7809
+ }
7564
7810
  } else if (value.item.type === "custom_tool_call") {
7565
7811
  const toolName = toolNameMapping.toCustomToolName(
7566
7812
  value.item.name
@@ -7713,7 +7959,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7713
7959
  } else if (value.item.type === "message") {
7714
7960
  activeOutputItemIds[value.output_index] = value.item.id;
7715
7961
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
7716
- activeMessagePhase = (_c = value.item.phase) != null ? _c : void 0;
7962
+ activeMessagePhase = (_c2 = value.item.phase) != null ? _c2 : void 0;
7717
7963
  controller.enqueue({
7718
7964
  type: "text-start",
7719
7965
  id: value.item.id,
@@ -7738,7 +7984,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7738
7984
  providerMetadata: {
7739
7985
  [providerOptionsName]: {
7740
7986
  itemId: value.item.id,
7741
- reasoningEncryptedContent: (_d = value.item.encrypted_content) != null ? _d : null
7987
+ reasoningEncryptedContent: (_d2 = value.item.encrypted_content) != null ? _d2 : null
7742
7988
  }
7743
7989
  }
7744
7990
  });
@@ -7766,37 +8012,105 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7766
8012
  });
7767
8013
  activeOutputItemIds[value.output_index] = void 0;
7768
8014
  } else if (value.item.type === "function_call") {
8015
+ const item = value.item;
8016
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
7769
8017
  ongoingToolCalls[value.output_index] = void 0;
7770
8018
  hasFunctionCall = true;
7771
- controller.enqueue({
7772
- type: "tool-input-end",
7773
- id: value.item.call_id,
7774
- ...value.item.namespace != null && {
7775
- providerMetadata: {
7776
- [providerOptionsName]: {
7777
- namespace: value.item.namespace
8019
+ const suppressInputStreaming = (_f = ongoingToolCall == null ? void 0 : ongoingToolCall.suppressInputStreaming) != null ? _f : isUndeclaredParallelToolCall({
8020
+ toolName: item.name,
8021
+ tools: functionTools
8022
+ });
8023
+ const enqueueUnexpandedToolCall = () => {
8024
+ var _a3;
8025
+ if (suppressInputStreaming) {
8026
+ controller.enqueue({
8027
+ type: "tool-input-start",
8028
+ id: item.call_id,
8029
+ toolName: item.name
8030
+ });
8031
+ const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
8032
+ if (bufferedInputDeltas.length > 0) {
8033
+ for (const delta of bufferedInputDeltas) {
8034
+ controller.enqueue({
8035
+ type: "tool-input-delta",
8036
+ id: item.call_id,
8037
+ delta
8038
+ });
7778
8039
  }
8040
+ } else if (item.arguments.length > 0) {
8041
+ controller.enqueue({
8042
+ type: "tool-input-delta",
8043
+ id: item.call_id,
8044
+ delta: item.arguments
8045
+ });
7779
8046
  }
7780
8047
  }
7781
- });
7782
- controller.enqueue({
7783
- type: "tool-call",
7784
- toolCallId: value.item.call_id,
7785
- toolName: value.item.name,
7786
- input: value.item.arguments,
7787
- providerMetadata: {
7788
- [providerOptionsName]: {
7789
- itemId: value.item.id,
7790
- ...value.item.namespace != null && {
7791
- namespace: value.item.namespace
7792
- },
7793
- ...value.item.caller != null && {
7794
- caller: value.item.caller.type === "program" ? {
7795
- type: "program",
7796
- callerId: value.item.caller.caller_id
7797
- } : value.item.caller
8048
+ controller.enqueue({
8049
+ type: "tool-input-end",
8050
+ id: item.call_id,
8051
+ ...item.namespace != null && {
8052
+ providerMetadata: {
8053
+ [providerOptionsName]: {
8054
+ namespace: item.namespace
8055
+ }
7798
8056
  }
7799
8057
  }
8058
+ });
8059
+ controller.enqueue({
8060
+ type: "tool-call",
8061
+ toolCallId: item.call_id,
8062
+ toolName: item.name,
8063
+ input: item.arguments,
8064
+ providerMetadata: {
8065
+ [providerOptionsName]: {
8066
+ itemId: item.id,
8067
+ ...item.namespace != null && {
8068
+ namespace: item.namespace
8069
+ },
8070
+ ...item.caller != null && {
8071
+ caller: item.caller.type === "program" ? {
8072
+ type: "program",
8073
+ callerId: item.caller.caller_id
8074
+ } : item.caller
8075
+ }
8076
+ }
8077
+ }
8078
+ });
8079
+ };
8080
+ if (!suppressInputStreaming) {
8081
+ enqueueUnexpandedToolCall();
8082
+ return;
8083
+ }
8084
+ return expandParallelToolCall({
8085
+ toolCall: {
8086
+ toolCallId: item.call_id,
8087
+ toolName: item.name,
8088
+ input: item.arguments
8089
+ },
8090
+ tools: functionTools,
8091
+ providerOptionsName,
8092
+ itemId: item.id
8093
+ }).then((expandedToolCalls) => {
8094
+ if (expandedToolCalls == null) {
8095
+ enqueueUnexpandedToolCall();
8096
+ return;
8097
+ }
8098
+ for (const toolCall of expandedToolCalls) {
8099
+ controller.enqueue({
8100
+ type: "tool-input-start",
8101
+ id: toolCall.toolCallId,
8102
+ toolName: toolCall.toolName
8103
+ });
8104
+ controller.enqueue({
8105
+ type: "tool-input-delta",
8106
+ id: toolCall.toolCallId,
8107
+ delta: toolCall.input
8108
+ });
8109
+ controller.enqueue({
8110
+ type: "tool-input-end",
8111
+ id: toolCall.toolCallId
8112
+ });
8113
+ controller.enqueue(toolCall);
7800
8114
  }
7801
8115
  });
7802
8116
  } else if (value.item.type === "program") {
@@ -7921,13 +8235,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7921
8235
  toolName: toolNameMapping.toCustomToolName("file_search"),
7922
8236
  result: {
7923
8237
  queries: value.item.queries,
7924
- results: (_g = (_f = value.item.results) == null ? void 0 : _f.map((result2) => ({
8238
+ results: (_h = (_g = value.item.results) == null ? void 0 : _g.map((result2) => ({
7925
8239
  attributes: result2.attributes,
7926
8240
  fileId: result2.file_id,
7927
8241
  filename: result2.filename,
7928
8242
  score: result2.score,
7929
8243
  text: result2.text
7930
- }))) != null ? _g : null
8244
+ }))) != null ? _h : null
7931
8245
  }
7932
8246
  });
7933
8247
  } else if (value.item.type === "code_interpreter_call") {
@@ -7953,7 +8267,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7953
8267
  const toolCall = ongoingToolCalls[value.output_index];
7954
8268
  const isHosted = value.item.execution === "server";
7955
8269
  if (toolCall != null) {
7956
- const toolCallId = isHosted ? toolCall.toolCallId : (_h = value.item.call_id) != null ? _h : value.item.id;
8270
+ const toolCallId = isHosted ? toolCall.toolCallId : (_i = value.item.call_id) != null ? _i : value.item.id;
7957
8271
  if (isHosted) {
7958
8272
  hostedToolSearchCallIds.push(toolCallId);
7959
8273
  } else {
@@ -7985,7 +8299,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7985
8299
  }
7986
8300
  ongoingToolCalls[value.output_index] = void 0;
7987
8301
  } else if (value.item.type === "tool_search_output") {
7988
- const toolCallId = (_j = (_i = value.item.call_id) != null ? _i : hostedToolSearchCallIds.shift()) != null ? _j : value.item.id;
8302
+ const toolCallId = (_k = (_j = value.item.call_id) != null ? _j : hostedToolSearchCallIds.shift()) != null ? _k : value.item.id;
7989
8303
  controller.enqueue({
7990
8304
  type: "tool-result",
7991
8305
  toolCallId,
@@ -8001,10 +8315,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8001
8315
  });
8002
8316
  } else if (value.item.type === "mcp_call") {
8003
8317
  ongoingToolCalls[value.output_index] = void 0;
8004
- const approvalRequestId = (_k = value.item.approval_request_id) != null ? _k : void 0;
8005
- const aliasedToolCallId = approvalRequestId != null ? (_m = (_l = approvalRequestIdToDummyToolCallIdFromStream.get(
8318
+ const approvalRequestId = (_l = value.item.approval_request_id) != null ? _l : void 0;
8319
+ const aliasedToolCallId = approvalRequestId != null ? (_n = (_m = approvalRequestIdToDummyToolCallIdFromStream.get(
8006
8320
  approvalRequestId
8007
- )) != null ? _l : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _m : value.item.id : value.item.id;
8321
+ )) != null ? _m : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _n : value.item.id : value.item.id;
8008
8322
  const toolName = `mcp.${value.item.name}`;
8009
8323
  controller.enqueue({
8010
8324
  type: "tool-call",
@@ -8074,8 +8388,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8074
8388
  ongoingToolCalls[value.output_index] = void 0;
8075
8389
  } else if (value.item.type === "mcp_approval_request") {
8076
8390
  ongoingToolCalls[value.output_index] = void 0;
8077
- const dummyToolCallId = (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2();
8078
- const approvalRequestId = (_q = value.item.approval_request_id) != null ? _q : value.item.id;
8391
+ const dummyToolCallId = (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2();
8392
+ const approvalRequestId = (_r = value.item.approval_request_id) != null ? _r : value.item.id;
8079
8393
  approvalRequestIdToDummyToolCallIdFromStream.set(
8080
8394
  approvalRequestId,
8081
8395
  dummyToolCallId
@@ -8169,7 +8483,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8169
8483
  providerMetadata: {
8170
8484
  [providerOptionsName]: {
8171
8485
  itemId,
8172
- reasoningEncryptedContent: (_r = value.item.encrypted_content) != null ? _r : null
8486
+ reasoningEncryptedContent: (_s = value.item.encrypted_content) != null ? _s : null
8173
8487
  }
8174
8488
  }
8175
8489
  });
@@ -8193,11 +8507,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8193
8507
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
8194
8508
  const toolCall = ongoingToolCalls[value.output_index];
8195
8509
  if (toolCall != null) {
8196
- controller.enqueue({
8197
- type: "tool-input-delta",
8198
- id: toolCall.toolCallId,
8199
- delta: value.delta
8200
- });
8510
+ if (toolCall.suppressInputStreaming) {
8511
+ (_t = toolCall.bufferedInputDeltas) == null ? void 0 : _t.push(value.delta);
8512
+ } else {
8513
+ controller.enqueue({
8514
+ type: "tool-input-delta",
8515
+ id: toolCall.toolCallId,
8516
+ delta: value.delta
8517
+ });
8518
+ }
8201
8519
  }
8202
8520
  } else if (isResponseCustomToolCallInputDeltaChunk(value)) {
8203
8521
  const toolCall = ongoingToolCalls[value.output_index];
@@ -8300,7 +8618,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8300
8618
  id: itemId,
8301
8619
  delta: value.delta
8302
8620
  });
8303
- if (((_t = (_s = options.providerOptions) == null ? void 0 : _s[providerOptionsName]) == null ? void 0 : _t.logprobs) && value.logprobs) {
8621
+ if (((_v = (_u = options.providerOptions) == null ? void 0 : _u[providerOptionsName]) == null ? void 0 : _v.logprobs) && value.logprobs) {
8304
8622
  logprobs.push(value.logprobs);
8305
8623
  }
8306
8624
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -8334,7 +8652,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8334
8652
  providerMetadata: {
8335
8653
  [providerOptionsName]: {
8336
8654
  itemId,
8337
- reasoningEncryptedContent: (_u = activeReasoningPart.encryptedContent) != null ? _u : null
8655
+ reasoningEncryptedContent: (_w = activeReasoningPart.encryptedContent) != null ? _w : null
8338
8656
  }
8339
8657
  }
8340
8658
  });
@@ -8380,20 +8698,20 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8380
8698
  } else if (isResponseFinishedChunk(value)) {
8381
8699
  finishReason = {
8382
8700
  unified: mapOpenAIResponseFinishReason({
8383
- finishReason: (_v = value.response.incomplete_details) == null ? void 0 : _v.reason,
8701
+ finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
8384
8702
  hasFunctionCall
8385
8703
  }),
8386
- raw: (_x = (_w = value.response.incomplete_details) == null ? void 0 : _w.reason) != null ? _x : void 0
8704
+ raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
8387
8705
  };
8388
8706
  usage = value.response.usage;
8389
8707
  if (typeof value.response.service_tier === "string") {
8390
8708
  serviceTier = value.response.service_tier;
8391
8709
  }
8392
- if (((_y = value.response.reasoning) == null ? void 0 : _y.context) != null) {
8710
+ if (((_A = value.response.reasoning) == null ? void 0 : _A.context) != null) {
8393
8711
  reasoningContext = value.response.reasoning.context;
8394
8712
  }
8395
8713
  } else if (isResponseFailedChunk(value)) {
8396
- const incompleteReason = (_z = value.response.incomplete_details) == null ? void 0 : _z.reason;
8714
+ const incompleteReason = (_B = value.response.incomplete_details) == null ? void 0 : _B.reason;
8397
8715
  finishReason = {
8398
8716
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
8399
8717
  finishReason: incompleteReason,
@@ -8401,8 +8719,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8401
8719
  }) : "error",
8402
8720
  raw: incompleteReason != null ? incompleteReason : "error"
8403
8721
  };
8404
- usage = (_A = value.response.usage) != null ? _A : void 0;
8405
- if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
8722
+ usage = (_C = value.response.usage) != null ? _C : void 0;
8723
+ if (((_D = value.response.reasoning) == null ? void 0 : _D.context) != null) {
8406
8724
  reasoningContext = value.response.reasoning.context;
8407
8725
  }
8408
8726
  if (!encounteredStreamError && value.response.error != null) {
@@ -8426,7 +8744,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8426
8744
  controller.enqueue({
8427
8745
  type: "source",
8428
8746
  sourceType: "url",
8429
- id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : generateId2(),
8747
+ id: (_G = (_F = (_E = self.config).generateId) == null ? void 0 : _F.call(_E)) != null ? _G : generateId2(),
8430
8748
  url: value.annotation.url,
8431
8749
  title: value.annotation.title
8432
8750
  });
@@ -8434,7 +8752,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8434
8752
  controller.enqueue({
8435
8753
  type: "source",
8436
8754
  sourceType: "document",
8437
- id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
8755
+ id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : generateId2(),
8438
8756
  mediaType: "text/plain",
8439
8757
  title: value.annotation.filename,
8440
8758
  filename: value.annotation.filename,
@@ -8450,7 +8768,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8450
8768
  controller.enqueue({
8451
8769
  type: "source",
8452
8770
  sourceType: "document",
8453
- id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
8771
+ id: (_M = (_L = (_K = self.config).generateId) == null ? void 0 : _L.call(_K)) != null ? _M : generateId2(),
8454
8772
  mediaType: "text/plain",
8455
8773
  title: value.annotation.filename,
8456
8774
  filename: value.annotation.filename,
@@ -8466,7 +8784,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8466
8784
  controller.enqueue({
8467
8785
  type: "source",
8468
8786
  sourceType: "document",
8469
- id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
8787
+ id: (_P = (_O = (_N = self.config).generateId) == null ? void 0 : _O.call(_N)) != null ? _P : generateId2(),
8470
8788
  mediaType: "application/octet-stream",
8471
8789
  title: value.annotation.file_id,
8472
8790
  filename: value.annotation.file_id,
@@ -8486,6 +8804,24 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8486
8804
  }
8487
8805
  },
8488
8806
  flush(controller) {
8807
+ var _a2;
8808
+ for (const toolCall of Object.values(ongoingToolCalls)) {
8809
+ if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
8810
+ continue;
8811
+ }
8812
+ controller.enqueue({
8813
+ type: "tool-input-start",
8814
+ id: toolCall.toolCallId,
8815
+ toolName: toolCall.toolName
8816
+ });
8817
+ for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
8818
+ controller.enqueue({
8819
+ type: "tool-input-delta",
8820
+ id: toolCall.toolCallId,
8821
+ delta
8822
+ });
8823
+ }
8824
+ }
8489
8825
  const providerMetadata = {
8490
8826
  [providerOptionsName]: {
8491
8827
  responseId,