@ai-sdk/openai 4.0.43 → 4.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1152,7 +1152,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1152
1152
  };
1153
1153
  }
1154
1154
  async doGenerate(options) {
1155
- var _a, _b, _c, _d, _e, _f, _g, _h;
1155
+ var _a, _b, _c, _d, _e, _f, _g;
1156
1156
  const { args: body, warnings } = await this.getArgs(options);
1157
1157
  const {
1158
1158
  responseHeaders,
@@ -1181,12 +1181,12 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1181
1181
  for (const toolCall of (_c = choice.message.tool_calls) != null ? _c : []) {
1182
1182
  content.push({
1183
1183
  type: "tool-call",
1184
- toolCallId: (_d = toolCall.id) != null ? _d : generateId(),
1184
+ toolCallId: toolCall.id || generateId(),
1185
1185
  toolName: toolCall.function.name,
1186
1186
  input: toolCall.function.arguments
1187
1187
  });
1188
1188
  }
1189
- for (const annotation of (_e = choice.message.annotations) != null ? _e : []) {
1189
+ for (const annotation of (_d = choice.message.annotations) != null ? _d : []) {
1190
1190
  content.push({
1191
1191
  type: "source",
1192
1192
  sourceType: "url",
@@ -1195,7 +1195,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1195
1195
  title: annotation.url_citation.title
1196
1196
  });
1197
1197
  }
1198
- const completionTokenDetails = (_f = response.usage) == null ? void 0 : _f.completion_tokens_details;
1198
+ const completionTokenDetails = (_e = response.usage) == null ? void 0 : _e.completion_tokens_details;
1199
1199
  const providerMetadata = { openai: {} };
1200
1200
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens) != null) {
1201
1201
  providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.accepted_prediction_tokens;
@@ -1203,14 +1203,14 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
1203
1203
  if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
1204
1204
  providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
1205
1205
  }
1206
- if (((_g = choice.logprobs) == null ? void 0 : _g.content) != null) {
1206
+ if (((_f = choice.logprobs) == null ? void 0 : _f.content) != null) {
1207
1207
  providerMetadata.openai.logprobs = choice.logprobs.content;
1208
1208
  }
1209
1209
  return {
1210
1210
  content,
1211
1211
  finishReason: {
1212
1212
  unified: mapOpenAIFinishReason(choice.finish_reason),
1213
- raw: (_h = choice.finish_reason) != null ? _h : void 0
1213
+ raw: (_g = choice.finish_reason) != null ? _g : void 0
1214
1214
  },
1215
1215
  usage: convertOpenAIChatUsage(response.usage),
1216
1216
  request: { body },
@@ -4420,12 +4420,246 @@ import {
4420
4420
  validateTypes
4421
4421
  } from "@ai-sdk/provider-utils";
4422
4422
  import { z as z26 } from "zod/v4";
4423
+
4424
+ // src/responses/expand-parallel-tool-call.ts
4425
+ import {
4426
+ isJSONObject
4427
+ } from "@ai-sdk/provider";
4428
+ import { safeParseJSON } from "@ai-sdk/provider-utils";
4429
+ var parallelToolName = "parallel";
4430
+ var recipientNamePrefix = "functions.";
4431
+ function getParallelToolCallMetadata({
4432
+ providerOptions,
4433
+ providerOptionsName
4434
+ }) {
4435
+ var _a;
4436
+ const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
4437
+ 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) {
4438
+ return void 0;
4439
+ }
4440
+ return metadata;
4441
+ }
4442
+ function isUndeclaredParallelToolCall({
4443
+ toolName,
4444
+ tools
4445
+ }) {
4446
+ return toolName === parallelToolName && !tools.some((tool) => tool.name === parallelToolName);
4447
+ }
4448
+ async function expandParallelToolCall({
4449
+ toolCall,
4450
+ tools,
4451
+ providerOptionsName,
4452
+ itemId
4453
+ }) {
4454
+ if (!isUndeclaredParallelToolCall({ toolName: toolCall.toolName, tools })) {
4455
+ return void 0;
4456
+ }
4457
+ const parsedInput = await safeParseJSON({ text: toolCall.input });
4458
+ if (!parsedInput.success || !isJSONObject(parsedInput.value)) {
4459
+ return void 0;
4460
+ }
4461
+ const toolUses = parsedInput.value.tool_uses;
4462
+ if (!Array.isArray(toolUses) || toolUses.length === 0) {
4463
+ return void 0;
4464
+ }
4465
+ const availableToolNames = new Set(tools.map((tool) => tool.name));
4466
+ const expandedToolCalls = [];
4467
+ for (const [index, toolUse] of toolUses.entries()) {
4468
+ if (!isJSONObject(toolUse)) {
4469
+ return void 0;
4470
+ }
4471
+ const recipientName = toolUse.recipient_name;
4472
+ const parameters = toolUse.parameters;
4473
+ if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !isJSONObject(parameters)) {
4474
+ return void 0;
4475
+ }
4476
+ const toolName = recipientName.slice(recipientNamePrefix.length);
4477
+ if (toolName.length === 0 || !availableToolNames.has(toolName)) {
4478
+ return void 0;
4479
+ }
4480
+ expandedToolCalls.push({
4481
+ type: "tool-call",
4482
+ toolCallId: `${toolCall.toolCallId}_${index}`,
4483
+ toolName,
4484
+ input: JSON.stringify(parameters),
4485
+ providerMetadata: {
4486
+ [providerOptionsName]: {
4487
+ parallelToolCall: {
4488
+ itemId,
4489
+ toolCallId: toolCall.toolCallId,
4490
+ toolName: toolCall.toolName,
4491
+ input: toolCall.input,
4492
+ index,
4493
+ count: toolUses.length
4494
+ }
4495
+ }
4496
+ }
4497
+ });
4498
+ }
4499
+ return expandedToolCalls;
4500
+ }
4501
+
4502
+ // src/responses/convert-to-openai-responses-input.ts
4423
4503
  function serializeToolCallArguments2(input) {
4424
4504
  return JSON.stringify(input === void 0 ? {} : input);
4425
4505
  }
4426
4506
  function mapToolCaller(caller) {
4427
4507
  return caller == null ? void 0 : caller.type === "program" ? { type: "program", caller_id: caller.callerId } : caller;
4428
4508
  }
4509
+ async function convertFunctionToolResultOutput({
4510
+ output,
4511
+ toolName,
4512
+ outputSchemaToolNames,
4513
+ providerOptionsName,
4514
+ warnings
4515
+ }) {
4516
+ var _a;
4517
+ const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
4518
+ switch (output.type) {
4519
+ case "text":
4520
+ case "error-text":
4521
+ return hasOutputSchema ? JSON.stringify(output.value) : output.value;
4522
+ case "execution-denied": {
4523
+ const reason = (_a = output.reason) != null ? _a : "Tool call execution denied.";
4524
+ return hasOutputSchema ? JSON.stringify(reason) : reason;
4525
+ }
4526
+ case "json":
4527
+ case "error-json":
4528
+ return JSON.stringify(output.value);
4529
+ case "content":
4530
+ return output.value.map((item) => {
4531
+ var _a2, _b, _c;
4532
+ const promptCacheBreakpoint = getPromptCacheBreakpoint2(
4533
+ item.providerOptions,
4534
+ providerOptionsName
4535
+ );
4536
+ switch (item.type) {
4537
+ case "text": {
4538
+ return {
4539
+ type: "input_text",
4540
+ text: item.text,
4541
+ ...promptCacheBreakpoint != null && {
4542
+ prompt_cache_breakpoint: promptCacheBreakpoint
4543
+ }
4544
+ };
4545
+ }
4546
+ case "file": {
4547
+ const topLevel = getTopLevelMediaType2(item.mediaType);
4548
+ const imageDetail = (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail;
4549
+ if (item.data.type === "data") {
4550
+ const fullMediaType = resolveFullMediaType2({ part: item });
4551
+ if (topLevel === "image") {
4552
+ return {
4553
+ type: "input_image",
4554
+ image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
4555
+ detail: imageDetail,
4556
+ ...promptCacheBreakpoint != null && {
4557
+ prompt_cache_breakpoint: promptCacheBreakpoint
4558
+ }
4559
+ };
4560
+ }
4561
+ return {
4562
+ type: "input_file",
4563
+ filename: (_c = item.filename) != null ? _c : "data",
4564
+ file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
4565
+ ...promptCacheBreakpoint != null && {
4566
+ prompt_cache_breakpoint: promptCacheBreakpoint
4567
+ }
4568
+ };
4569
+ }
4570
+ if (item.data.type === "url") {
4571
+ if (topLevel === "image") {
4572
+ return {
4573
+ type: "input_image",
4574
+ image_url: item.data.url.toString(),
4575
+ detail: imageDetail,
4576
+ ...promptCacheBreakpoint != null && {
4577
+ prompt_cache_breakpoint: promptCacheBreakpoint
4578
+ }
4579
+ };
4580
+ }
4581
+ return {
4582
+ type: "input_file",
4583
+ file_url: item.data.url.toString(),
4584
+ ...promptCacheBreakpoint != null && {
4585
+ prompt_cache_breakpoint: promptCacheBreakpoint
4586
+ }
4587
+ };
4588
+ }
4589
+ warnings.push({
4590
+ type: "other",
4591
+ message: `unsupported tool content part type: ${item.type} with data type: ${item.data.type}`
4592
+ });
4593
+ return void 0;
4594
+ }
4595
+ default: {
4596
+ warnings.push({
4597
+ type: "other",
4598
+ message: `unsupported tool content part type: ${item.type}`
4599
+ });
4600
+ return void 0;
4601
+ }
4602
+ }
4603
+ }).filter(isNonNullable);
4604
+ }
4605
+ }
4606
+ function hasSameParallelToolCall(first, second) {
4607
+ return first.itemId === second.itemId && first.toolCallId === second.toolCallId && first.toolName === second.toolName && first.input === second.input && first.count === second.count;
4608
+ }
4609
+ function collectCompleteParallelToolResultGroups({
4610
+ prompt,
4611
+ providerOptionsName
4612
+ }) {
4613
+ const pendingGroups = /* @__PURE__ */ new Map();
4614
+ for (const message of prompt) {
4615
+ if (message.role !== "tool") {
4616
+ continue;
4617
+ }
4618
+ for (const part of message.content) {
4619
+ if (part.type !== "tool-result") {
4620
+ continue;
4621
+ }
4622
+ const metadata = getParallelToolCallMetadata({
4623
+ providerOptions: part.providerOptions,
4624
+ providerOptionsName
4625
+ });
4626
+ if (metadata == null) {
4627
+ continue;
4628
+ }
4629
+ const existing = pendingGroups.get(metadata.toolCallId);
4630
+ if (existing == null) {
4631
+ pendingGroups.set(metadata.toolCallId, {
4632
+ metadata,
4633
+ results: /* @__PURE__ */ new Map([[metadata.index, part]]),
4634
+ invalid: false
4635
+ });
4636
+ continue;
4637
+ }
4638
+ if (!hasSameParallelToolCall(existing.metadata, metadata) || existing.results.has(metadata.index)) {
4639
+ existing.invalid = true;
4640
+ continue;
4641
+ }
4642
+ existing.results.set(metadata.index, part);
4643
+ }
4644
+ }
4645
+ const completeGroups = /* @__PURE__ */ new Map();
4646
+ for (const [toolCallId, group] of pendingGroups) {
4647
+ if (group.invalid || group.results.size !== group.metadata.count) {
4648
+ continue;
4649
+ }
4650
+ const results = Array.from(
4651
+ { length: group.metadata.count },
4652
+ (_, index) => group.results.get(index)
4653
+ );
4654
+ if (results.every(isNonNullable)) {
4655
+ completeGroups.set(toolCallId, {
4656
+ metadata: group.metadata,
4657
+ results
4658
+ });
4659
+ }
4660
+ }
4661
+ return completeGroups;
4662
+ }
4429
4663
  function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
4430
4664
  var _a;
4431
4665
  return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
@@ -4451,10 +4685,16 @@ async function convertToOpenAIResponsesInput({
4451
4685
  customProviderToolNames,
4452
4686
  outputSchemaToolNames
4453
4687
  }) {
4454
- 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;
4688
+ 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;
4455
4689
  let input = [];
4456
4690
  const warnings = [];
4457
4691
  const processedApprovalIds = /* @__PURE__ */ new Set();
4692
+ const parallelToolResultGroups = hasConversation || hasPreviousResponseId ? collectCompleteParallelToolResultGroups({
4693
+ prompt,
4694
+ providerOptionsName
4695
+ }) : /* @__PURE__ */ new Map();
4696
+ const emittedParallelToolCalls = /* @__PURE__ */ new Set();
4697
+ const emittedParallelToolResults = /* @__PURE__ */ new Set();
4458
4698
  for (const { role, content, providerOptions } of prompt) {
4459
4699
  switch (role) {
4460
4700
  case "system": {
@@ -4635,6 +4875,34 @@ async function convertToOpenAIResponsesInput({
4635
4875
  break;
4636
4876
  }
4637
4877
  case "tool-call": {
4878
+ const parallelToolCallMetadata = getParallelToolCallMetadata({
4879
+ providerOptions: part.providerOptions,
4880
+ providerOptionsName
4881
+ });
4882
+ const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
4883
+ parallelToolCallMetadata.toolCallId
4884
+ );
4885
+ if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
4886
+ parallelToolResultGroup.metadata,
4887
+ parallelToolCallMetadata
4888
+ )) {
4889
+ if (!emittedParallelToolCalls.has(
4890
+ parallelToolResultGroup.metadata.toolCallId
4891
+ )) {
4892
+ emittedParallelToolCalls.add(
4893
+ parallelToolResultGroup.metadata.toolCallId
4894
+ );
4895
+ if (!hasConversation) {
4896
+ input.push({
4897
+ type: "function_call",
4898
+ call_id: parallelToolResultGroup.metadata.toolCallId,
4899
+ name: parallelToolResultGroup.metadata.toolName,
4900
+ arguments: parallelToolResultGroup.metadata.input
4901
+ });
4902
+ }
4903
+ }
4904
+ break;
4905
+ }
4638
4906
  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;
4639
4907
  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;
4640
4908
  const caller = (_m = (_l = part.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.caller;
@@ -5024,6 +5292,46 @@ async function convertToOpenAIResponsesInput({
5024
5292
  });
5025
5293
  continue;
5026
5294
  }
5295
+ const parallelToolCallMetadata = getParallelToolCallMetadata({
5296
+ providerOptions: part.providerOptions,
5297
+ providerOptionsName
5298
+ });
5299
+ const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
5300
+ parallelToolCallMetadata.toolCallId
5301
+ );
5302
+ if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
5303
+ parallelToolResultGroup.metadata,
5304
+ parallelToolCallMetadata
5305
+ )) {
5306
+ if (!emittedParallelToolResults.has(
5307
+ parallelToolResultGroup.metadata.toolCallId
5308
+ )) {
5309
+ emittedParallelToolResults.add(
5310
+ parallelToolResultGroup.metadata.toolCallId
5311
+ );
5312
+ const toolOutputs = await Promise.all(
5313
+ parallelToolResultGroup.results.map(
5314
+ async (result) => convertFunctionToolResultOutput({
5315
+ output: result.output,
5316
+ toolName: result.toolName,
5317
+ outputSchemaToolNames,
5318
+ providerOptionsName,
5319
+ warnings
5320
+ })
5321
+ )
5322
+ );
5323
+ input.push({
5324
+ type: "function_call_output",
5325
+ call_id: parallelToolResultGroup.metadata.toolCallId,
5326
+ // The internal wrapper returns one output containing the child
5327
+ // results in the same order as the original tool_uses array.
5328
+ output: toolOutputs.map(
5329
+ (output2) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
5330
+ ).join("\n")
5331
+ });
5332
+ }
5333
+ continue;
5334
+ }
5027
5335
  const output = part.output;
5028
5336
  if (output.type === "execution-denied") {
5029
5337
  const approvalId = (_G = (_F = output.providerOptions) == null ? void 0 : _F.openai) == null ? void 0 : _G.approvalId;
@@ -5214,103 +5522,15 @@ async function convertToOpenAIResponsesInput({
5214
5522
  });
5215
5523
  continue;
5216
5524
  }
5217
- let contentValue;
5218
- const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(part.toolName);
5219
- switch (output.type) {
5220
- case "text":
5221
- case "error-text":
5222
- contentValue = hasOutputSchema ? JSON.stringify(output.value) : output.value;
5223
- break;
5224
- case "execution-denied": {
5225
- const reason = (_J = output.reason) != null ? _J : "Tool call execution denied.";
5226
- contentValue = hasOutputSchema ? JSON.stringify(reason) : reason;
5227
- break;
5228
- }
5229
- case "json":
5230
- case "error-json":
5231
- contentValue = JSON.stringify(output.value);
5232
- break;
5233
- case "content":
5234
- contentValue = output.value.map((item) => {
5235
- var _a2, _b2, _c2;
5236
- const promptCacheBreakpoint = getPromptCacheBreakpoint2(
5237
- item.providerOptions,
5238
- providerOptionsName
5239
- );
5240
- switch (item.type) {
5241
- case "text": {
5242
- return {
5243
- type: "input_text",
5244
- text: item.text,
5245
- ...promptCacheBreakpoint != null && {
5246
- prompt_cache_breakpoint: promptCacheBreakpoint
5247
- }
5248
- };
5249
- }
5250
- case "file": {
5251
- const topLevel = getTopLevelMediaType2(item.mediaType);
5252
- const imageDetail = (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
5253
- if (item.data.type === "data") {
5254
- const fullMediaType = resolveFullMediaType2({
5255
- part: item
5256
- });
5257
- if (topLevel === "image") {
5258
- return {
5259
- type: "input_image",
5260
- image_url: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
5261
- detail: imageDetail,
5262
- ...promptCacheBreakpoint != null && {
5263
- prompt_cache_breakpoint: promptCacheBreakpoint
5264
- }
5265
- };
5266
- }
5267
- return {
5268
- type: "input_file",
5269
- filename: (_c2 = item.filename) != null ? _c2 : "data",
5270
- file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
5271
- ...promptCacheBreakpoint != null && {
5272
- prompt_cache_breakpoint: promptCacheBreakpoint
5273
- }
5274
- };
5275
- }
5276
- if (item.data.type === "url") {
5277
- if (topLevel === "image") {
5278
- return {
5279
- type: "input_image",
5280
- image_url: item.data.url.toString(),
5281
- detail: imageDetail,
5282
- ...promptCacheBreakpoint != null && {
5283
- prompt_cache_breakpoint: promptCacheBreakpoint
5284
- }
5285
- };
5286
- }
5287
- return {
5288
- type: "input_file",
5289
- file_url: item.data.url.toString(),
5290
- ...promptCacheBreakpoint != null && {
5291
- prompt_cache_breakpoint: promptCacheBreakpoint
5292
- }
5293
- };
5294
- }
5295
- warnings.push({
5296
- type: "other",
5297
- message: `unsupported tool content part type: ${item.type} with data type: ${item.data.type}`
5298
- });
5299
- return void 0;
5300
- }
5301
- default: {
5302
- warnings.push({
5303
- type: "other",
5304
- message: `unsupported tool content part type: ${item.type}`
5305
- });
5306
- return void 0;
5307
- }
5308
- }
5309
- }).filter(isNonNullable);
5310
- break;
5311
- }
5525
+ const contentValue = await convertFunctionToolResultOutput({
5526
+ output,
5527
+ toolName: part.toolName,
5528
+ outputSchemaToolNames,
5529
+ providerOptionsName,
5530
+ warnings
5531
+ });
5312
5532
  const caller = mapToolCaller(
5313
- (_L = (_K = part.providerOptions) == null ? void 0 : _K[providerOptionsName]) == null ? void 0 : _L.caller
5533
+ (_K = (_J = part.providerOptions) == null ? void 0 : _J[providerOptionsName]) == null ? void 0 : _K.caller
5314
5534
  );
5315
5535
  input.push({
5316
5536
  type: "function_call_output",
@@ -6506,7 +6726,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6506
6726
  };
6507
6727
  }
6508
6728
  async doGenerate(options) {
6509
- 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;
6729
+ 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;
6510
6730
  const {
6511
6731
  args: body,
6512
6732
  warnings,
@@ -6560,6 +6780,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6560
6780
  }
6561
6781
  const content = [];
6562
6782
  const logprobs = [];
6783
+ const functionTools = (_e = (_d = options.tools) == null ? void 0 : _d.filter(
6784
+ (tool) => tool.type === "function"
6785
+ )) != null ? _e : [];
6563
6786
  let hasFunctionCall = false;
6564
6787
  const hostedToolSearchCallIds = [];
6565
6788
  for (const part of response.output) {
@@ -6575,7 +6798,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6575
6798
  providerMetadata: {
6576
6799
  [providerOptionsName]: {
6577
6800
  itemId: part.id,
6578
- reasoningEncryptedContent: (_d = part.encrypted_content) != null ? _d : null
6801
+ reasoningEncryptedContent: (_f = part.encrypted_content) != null ? _f : null
6579
6802
  }
6580
6803
  }
6581
6804
  });
@@ -6601,7 +6824,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6601
6824
  break;
6602
6825
  }
6603
6826
  case "tool_search_call": {
6604
- const toolCallId = (_e = part.call_id) != null ? _e : part.id;
6827
+ const toolCallId = (_g = part.call_id) != null ? _g : part.id;
6605
6828
  const isHosted = part.execution === "server";
6606
6829
  if (isHosted) {
6607
6830
  hostedToolSearchCallIds.push(toolCallId);
@@ -6624,7 +6847,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6624
6847
  break;
6625
6848
  }
6626
6849
  case "tool_search_output": {
6627
- const toolCallId = (_g = (_f = part.call_id) != null ? _f : hostedToolSearchCallIds.shift()) != null ? _g : part.id;
6850
+ const toolCallId = (_i = (_h = part.call_id) != null ? _h : hostedToolSearchCallIds.shift()) != null ? _i : part.id;
6628
6851
  content.push({
6629
6852
  type: "tool-result",
6630
6853
  toolCallId,
@@ -6695,7 +6918,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6695
6918
  }
6696
6919
  case "message": {
6697
6920
  for (const contentPart of part.content) {
6698
- if (((_i = (_h = options.providerOptions) == null ? void 0 : _h[providerOptionsName]) == null ? void 0 : _i.logprobs) && contentPart.logprobs) {
6921
+ if (((_k = (_j = options.providerOptions) == null ? void 0 : _j[providerOptionsName]) == null ? void 0 : _k.logprobs) && contentPart.logprobs) {
6699
6922
  logprobs.push(contentPart.logprobs);
6700
6923
  }
6701
6924
  const providerMetadata2 = {
@@ -6717,7 +6940,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6717
6940
  content.push({
6718
6941
  type: "source",
6719
6942
  sourceType: "url",
6720
- id: (_l = (_k = (_j = this.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId2(),
6943
+ id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
6721
6944
  url: annotation.url,
6722
6945
  title: annotation.title
6723
6946
  });
@@ -6725,7 +6948,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6725
6948
  content.push({
6726
6949
  type: "source",
6727
6950
  sourceType: "document",
6728
- id: (_o = (_n = (_m = this.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2(),
6951
+ id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
6729
6952
  mediaType: "text/plain",
6730
6953
  title: annotation.filename,
6731
6954
  filename: annotation.filename,
@@ -6741,7 +6964,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6741
6964
  content.push({
6742
6965
  type: "source",
6743
6966
  sourceType: "document",
6744
- id: (_r = (_q = (_p = this.config).generateId) == null ? void 0 : _q.call(_p)) != null ? _r : generateId2(),
6967
+ id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
6745
6968
  mediaType: "text/plain",
6746
6969
  title: annotation.filename,
6747
6970
  filename: annotation.filename,
@@ -6757,7 +6980,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6757
6980
  content.push({
6758
6981
  type: "source",
6759
6982
  sourceType: "document",
6760
- id: (_u = (_t = (_s = this.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : generateId2(),
6983
+ id: (_w = (_v = (_u = this.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2(),
6761
6984
  mediaType: "application/octet-stream",
6762
6985
  title: annotation.file_id,
6763
6986
  filename: annotation.file_id,
@@ -6776,6 +6999,20 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6776
6999
  }
6777
7000
  case "function_call": {
6778
7001
  hasFunctionCall = true;
7002
+ const expandedToolCalls = await expandParallelToolCall({
7003
+ toolCall: {
7004
+ toolCallId: part.call_id,
7005
+ toolName: part.name,
7006
+ input: part.arguments
7007
+ },
7008
+ tools: functionTools,
7009
+ providerOptionsName,
7010
+ itemId: part.id
7011
+ });
7012
+ if (expandedToolCalls != null) {
7013
+ content.push(...expandedToolCalls);
7014
+ break;
7015
+ }
6779
7016
  content.push({
6780
7017
  type: "tool-call",
6781
7018
  toolCallId: part.call_id,
@@ -6872,7 +7109,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6872
7109
  break;
6873
7110
  }
6874
7111
  case "mcp_call": {
6875
- const toolCallId = part.approval_request_id != null ? (_v = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _v : part.id : part.id;
7112
+ const toolCallId = part.approval_request_id != null ? (_x = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _x : part.id : part.id;
6876
7113
  const toolName = `mcp.${part.name}`;
6877
7114
  content.push({
6878
7115
  type: "tool-call",
@@ -6906,8 +7143,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6906
7143
  break;
6907
7144
  }
6908
7145
  case "mcp_approval_request": {
6909
- const approvalRequestId = (_w = part.approval_request_id) != null ? _w : part.id;
6910
- const dummyToolCallId = (_z = (_y = (_x = this.config).generateId) == null ? void 0 : _y.call(_x)) != null ? _z : generateId2();
7146
+ const approvalRequestId = (_y = part.approval_request_id) != null ? _y : part.id;
7147
+ const dummyToolCallId = (_B = (_A = (_z = this.config).generateId) == null ? void 0 : _A.call(_z)) != null ? _B : generateId2();
6911
7148
  const toolName = `mcp.${part.name}`;
6912
7149
  content.push({
6913
7150
  type: "tool-call",
@@ -6973,13 +7210,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
6973
7210
  toolName: toolNameMapping.toCustomToolName("file_search"),
6974
7211
  result: {
6975
7212
  queries: part.queries,
6976
- results: (_B = (_A = part.results) == null ? void 0 : _A.map((result) => ({
7213
+ results: (_D = (_C = part.results) == null ? void 0 : _C.map((result) => ({
6977
7214
  attributes: result.attributes,
6978
7215
  fileId: result.file_id,
6979
7216
  filename: result.filename,
6980
7217
  score: result.score,
6981
7218
  text: result.text
6982
- }))) != null ? _B : null
7219
+ }))) != null ? _D : null
6983
7220
  }
6984
7221
  });
6985
7222
  break;
@@ -7043,7 +7280,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7043
7280
  responseId: response.id,
7044
7281
  ...logprobs.length > 0 ? { logprobs } : {},
7045
7282
  ...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
7046
- ...((_C = response.reasoning) == null ? void 0 : _C.context) != null ? { reasoningContext: response.reasoning.context } : {}
7283
+ ...((_E = response.reasoning) == null ? void 0 : _E.context) != null ? { reasoningContext: response.reasoning.context } : {}
7047
7284
  }
7048
7285
  };
7049
7286
  const usage = response.usage;
@@ -7051,10 +7288,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7051
7288
  content,
7052
7289
  finishReason: {
7053
7290
  unified: mapOpenAIResponseFinishReason({
7054
- finishReason: (_D = response.incomplete_details) == null ? void 0 : _D.reason,
7291
+ finishReason: (_F = response.incomplete_details) == null ? void 0 : _F.reason,
7055
7292
  hasFunctionCall
7056
7293
  }),
7057
- raw: (_F = (_E = response.incomplete_details) == null ? void 0 : _E.reason) != null ? _F : void 0
7294
+ raw: (_H = (_G = response.incomplete_details) == null ? void 0 : _G.reason) != null ? _H : void 0
7058
7295
  },
7059
7296
  usage: convertOpenAIResponsesUsage(usage),
7060
7297
  request: { body },
@@ -7070,7 +7307,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7070
7307
  };
7071
7308
  }
7072
7309
  async doStream(options) {
7073
- var _a, _b;
7310
+ var _a, _b, _c, _d;
7074
7311
  const {
7075
7312
  args: body,
7076
7313
  warnings,
@@ -7109,6 +7346,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7109
7346
  });
7110
7347
  const self = this;
7111
7348
  const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
7349
+ const functionTools = (_d = (_c = options.tools) == null ? void 0 : _c.filter(
7350
+ (tool) => tool.type === "function"
7351
+ )) != null ? _d : [];
7112
7352
  const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
7113
7353
  let finishReason = {
7114
7354
  unified: "other",
@@ -7141,7 +7381,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7141
7381
  controller.enqueue({ type: "stream-start", warnings });
7142
7382
  },
7143
7383
  transform(chunk, controller) {
7144
- 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;
7384
+ 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;
7145
7385
  if (options.includeRawChunks) {
7146
7386
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
7147
7387
  }
@@ -7160,15 +7400,23 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7160
7400
  const value = chunk.value;
7161
7401
  if (isResponseOutputItemAddedChunk(value)) {
7162
7402
  if (value.item.type === "function_call") {
7403
+ const suppressInputStreaming = isUndeclaredParallelToolCall({
7404
+ toolName: value.item.name,
7405
+ tools: functionTools
7406
+ });
7163
7407
  ongoingToolCalls[value.output_index] = {
7164
7408
  toolName: value.item.name,
7165
- toolCallId: value.item.call_id
7409
+ toolCallId: value.item.call_id,
7410
+ suppressInputStreaming,
7411
+ bufferedInputDeltas: suppressInputStreaming ? [] : void 0
7166
7412
  };
7167
- controller.enqueue({
7168
- type: "tool-input-start",
7169
- id: value.item.call_id,
7170
- toolName: value.item.name
7171
- });
7413
+ if (!suppressInputStreaming) {
7414
+ controller.enqueue({
7415
+ type: "tool-input-start",
7416
+ id: value.item.call_id,
7417
+ toolName: value.item.name
7418
+ });
7419
+ }
7172
7420
  } else if (value.item.type === "custom_tool_call") {
7173
7421
  const toolName = toolNameMapping.toCustomToolName(
7174
7422
  value.item.name
@@ -7321,7 +7569,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7321
7569
  } else if (value.item.type === "message") {
7322
7570
  activeOutputItemIds[value.output_index] = value.item.id;
7323
7571
  ongoingAnnotations.splice(0, ongoingAnnotations.length);
7324
- activeMessagePhase = (_c = value.item.phase) != null ? _c : void 0;
7572
+ activeMessagePhase = (_c2 = value.item.phase) != null ? _c2 : void 0;
7325
7573
  controller.enqueue({
7326
7574
  type: "text-start",
7327
7575
  id: value.item.id,
@@ -7346,7 +7594,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7346
7594
  providerMetadata: {
7347
7595
  [providerOptionsName]: {
7348
7596
  itemId: value.item.id,
7349
- reasoningEncryptedContent: (_d = value.item.encrypted_content) != null ? _d : null
7597
+ reasoningEncryptedContent: (_d2 = value.item.encrypted_content) != null ? _d2 : null
7350
7598
  }
7351
7599
  }
7352
7600
  });
@@ -7374,37 +7622,105 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7374
7622
  });
7375
7623
  activeOutputItemIds[value.output_index] = void 0;
7376
7624
  } else if (value.item.type === "function_call") {
7625
+ const item = value.item;
7626
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
7377
7627
  ongoingToolCalls[value.output_index] = void 0;
7378
7628
  hasFunctionCall = true;
7379
- controller.enqueue({
7380
- type: "tool-input-end",
7381
- id: value.item.call_id,
7382
- ...value.item.namespace != null && {
7383
- providerMetadata: {
7384
- [providerOptionsName]: {
7385
- namespace: value.item.namespace
7629
+ const suppressInputStreaming = (_f = ongoingToolCall == null ? void 0 : ongoingToolCall.suppressInputStreaming) != null ? _f : isUndeclaredParallelToolCall({
7630
+ toolName: item.name,
7631
+ tools: functionTools
7632
+ });
7633
+ const enqueueUnexpandedToolCall = () => {
7634
+ var _a3;
7635
+ if (suppressInputStreaming) {
7636
+ controller.enqueue({
7637
+ type: "tool-input-start",
7638
+ id: item.call_id,
7639
+ toolName: item.name
7640
+ });
7641
+ const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
7642
+ if (bufferedInputDeltas.length > 0) {
7643
+ for (const delta of bufferedInputDeltas) {
7644
+ controller.enqueue({
7645
+ type: "tool-input-delta",
7646
+ id: item.call_id,
7647
+ delta
7648
+ });
7386
7649
  }
7650
+ } else if (item.arguments.length > 0) {
7651
+ controller.enqueue({
7652
+ type: "tool-input-delta",
7653
+ id: item.call_id,
7654
+ delta: item.arguments
7655
+ });
7387
7656
  }
7388
7657
  }
7389
- });
7390
- controller.enqueue({
7391
- type: "tool-call",
7392
- toolCallId: value.item.call_id,
7393
- toolName: value.item.name,
7394
- input: value.item.arguments,
7395
- providerMetadata: {
7396
- [providerOptionsName]: {
7397
- itemId: value.item.id,
7398
- ...value.item.namespace != null && {
7399
- namespace: value.item.namespace
7400
- },
7401
- ...value.item.caller != null && {
7402
- caller: value.item.caller.type === "program" ? {
7403
- type: "program",
7404
- callerId: value.item.caller.caller_id
7405
- } : value.item.caller
7658
+ controller.enqueue({
7659
+ type: "tool-input-end",
7660
+ id: item.call_id,
7661
+ ...item.namespace != null && {
7662
+ providerMetadata: {
7663
+ [providerOptionsName]: {
7664
+ namespace: item.namespace
7665
+ }
7406
7666
  }
7407
7667
  }
7668
+ });
7669
+ controller.enqueue({
7670
+ type: "tool-call",
7671
+ toolCallId: item.call_id,
7672
+ toolName: item.name,
7673
+ input: item.arguments,
7674
+ providerMetadata: {
7675
+ [providerOptionsName]: {
7676
+ itemId: item.id,
7677
+ ...item.namespace != null && {
7678
+ namespace: item.namespace
7679
+ },
7680
+ ...item.caller != null && {
7681
+ caller: item.caller.type === "program" ? {
7682
+ type: "program",
7683
+ callerId: item.caller.caller_id
7684
+ } : item.caller
7685
+ }
7686
+ }
7687
+ }
7688
+ });
7689
+ };
7690
+ if (!suppressInputStreaming) {
7691
+ enqueueUnexpandedToolCall();
7692
+ return;
7693
+ }
7694
+ return expandParallelToolCall({
7695
+ toolCall: {
7696
+ toolCallId: item.call_id,
7697
+ toolName: item.name,
7698
+ input: item.arguments
7699
+ },
7700
+ tools: functionTools,
7701
+ providerOptionsName,
7702
+ itemId: item.id
7703
+ }).then((expandedToolCalls) => {
7704
+ if (expandedToolCalls == null) {
7705
+ enqueueUnexpandedToolCall();
7706
+ return;
7707
+ }
7708
+ for (const toolCall of expandedToolCalls) {
7709
+ controller.enqueue({
7710
+ type: "tool-input-start",
7711
+ id: toolCall.toolCallId,
7712
+ toolName: toolCall.toolName
7713
+ });
7714
+ controller.enqueue({
7715
+ type: "tool-input-delta",
7716
+ id: toolCall.toolCallId,
7717
+ delta: toolCall.input
7718
+ });
7719
+ controller.enqueue({
7720
+ type: "tool-input-end",
7721
+ id: toolCall.toolCallId
7722
+ });
7723
+ controller.enqueue(toolCall);
7408
7724
  }
7409
7725
  });
7410
7726
  } else if (value.item.type === "program") {
@@ -7529,13 +7845,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7529
7845
  toolName: toolNameMapping.toCustomToolName("file_search"),
7530
7846
  result: {
7531
7847
  queries: value.item.queries,
7532
- results: (_g = (_f = value.item.results) == null ? void 0 : _f.map((result2) => ({
7848
+ results: (_h = (_g = value.item.results) == null ? void 0 : _g.map((result2) => ({
7533
7849
  attributes: result2.attributes,
7534
7850
  fileId: result2.file_id,
7535
7851
  filename: result2.filename,
7536
7852
  score: result2.score,
7537
7853
  text: result2.text
7538
- }))) != null ? _g : null
7854
+ }))) != null ? _h : null
7539
7855
  }
7540
7856
  });
7541
7857
  } else if (value.item.type === "code_interpreter_call") {
@@ -7561,7 +7877,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7561
7877
  const toolCall = ongoingToolCalls[value.output_index];
7562
7878
  const isHosted = value.item.execution === "server";
7563
7879
  if (toolCall != null) {
7564
- const toolCallId = isHosted ? toolCall.toolCallId : (_h = value.item.call_id) != null ? _h : value.item.id;
7880
+ const toolCallId = isHosted ? toolCall.toolCallId : (_i = value.item.call_id) != null ? _i : value.item.id;
7565
7881
  if (isHosted) {
7566
7882
  hostedToolSearchCallIds.push(toolCallId);
7567
7883
  } else {
@@ -7593,7 +7909,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7593
7909
  }
7594
7910
  ongoingToolCalls[value.output_index] = void 0;
7595
7911
  } else if (value.item.type === "tool_search_output") {
7596
- const toolCallId = (_j = (_i = value.item.call_id) != null ? _i : hostedToolSearchCallIds.shift()) != null ? _j : value.item.id;
7912
+ const toolCallId = (_k = (_j = value.item.call_id) != null ? _j : hostedToolSearchCallIds.shift()) != null ? _k : value.item.id;
7597
7913
  controller.enqueue({
7598
7914
  type: "tool-result",
7599
7915
  toolCallId,
@@ -7609,10 +7925,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7609
7925
  });
7610
7926
  } else if (value.item.type === "mcp_call") {
7611
7927
  ongoingToolCalls[value.output_index] = void 0;
7612
- const approvalRequestId = (_k = value.item.approval_request_id) != null ? _k : void 0;
7613
- const aliasedToolCallId = approvalRequestId != null ? (_m = (_l = approvalRequestIdToDummyToolCallIdFromStream.get(
7928
+ const approvalRequestId = (_l = value.item.approval_request_id) != null ? _l : void 0;
7929
+ const aliasedToolCallId = approvalRequestId != null ? (_n = (_m = approvalRequestIdToDummyToolCallIdFromStream.get(
7614
7930
  approvalRequestId
7615
- )) != null ? _l : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _m : value.item.id : value.item.id;
7931
+ )) != null ? _m : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _n : value.item.id : value.item.id;
7616
7932
  const toolName = `mcp.${value.item.name}`;
7617
7933
  controller.enqueue({
7618
7934
  type: "tool-call",
@@ -7682,8 +7998,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7682
7998
  ongoingToolCalls[value.output_index] = void 0;
7683
7999
  } else if (value.item.type === "mcp_approval_request") {
7684
8000
  ongoingToolCalls[value.output_index] = void 0;
7685
- const dummyToolCallId = (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2();
7686
- const approvalRequestId = (_q = value.item.approval_request_id) != null ? _q : value.item.id;
8001
+ const dummyToolCallId = (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2();
8002
+ const approvalRequestId = (_r = value.item.approval_request_id) != null ? _r : value.item.id;
7687
8003
  approvalRequestIdToDummyToolCallIdFromStream.set(
7688
8004
  approvalRequestId,
7689
8005
  dummyToolCallId
@@ -7777,7 +8093,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7777
8093
  providerMetadata: {
7778
8094
  [providerOptionsName]: {
7779
8095
  itemId,
7780
- reasoningEncryptedContent: (_r = value.item.encrypted_content) != null ? _r : null
8096
+ reasoningEncryptedContent: (_s = value.item.encrypted_content) != null ? _s : null
7781
8097
  }
7782
8098
  }
7783
8099
  });
@@ -7801,11 +8117,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7801
8117
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
7802
8118
  const toolCall = ongoingToolCalls[value.output_index];
7803
8119
  if (toolCall != null) {
7804
- controller.enqueue({
7805
- type: "tool-input-delta",
7806
- id: toolCall.toolCallId,
7807
- delta: value.delta
7808
- });
8120
+ if (toolCall.suppressInputStreaming) {
8121
+ (_t = toolCall.bufferedInputDeltas) == null ? void 0 : _t.push(value.delta);
8122
+ } else {
8123
+ controller.enqueue({
8124
+ type: "tool-input-delta",
8125
+ id: toolCall.toolCallId,
8126
+ delta: value.delta
8127
+ });
8128
+ }
7809
8129
  }
7810
8130
  } else if (isResponseCustomToolCallInputDeltaChunk(value)) {
7811
8131
  const toolCall = ongoingToolCalls[value.output_index];
@@ -7908,7 +8228,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7908
8228
  id: itemId,
7909
8229
  delta: value.delta
7910
8230
  });
7911
- if (((_t = (_s = options.providerOptions) == null ? void 0 : _s[providerOptionsName]) == null ? void 0 : _t.logprobs) && value.logprobs) {
8231
+ if (((_v = (_u = options.providerOptions) == null ? void 0 : _u[providerOptionsName]) == null ? void 0 : _v.logprobs) && value.logprobs) {
7912
8232
  logprobs.push(value.logprobs);
7913
8233
  }
7914
8234
  } else if (value.type === "response.reasoning_summary_part.added") {
@@ -7942,7 +8262,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7942
8262
  providerMetadata: {
7943
8263
  [providerOptionsName]: {
7944
8264
  itemId,
7945
- reasoningEncryptedContent: (_u = activeReasoningPart.encryptedContent) != null ? _u : null
8265
+ reasoningEncryptedContent: (_w = activeReasoningPart.encryptedContent) != null ? _w : null
7946
8266
  }
7947
8267
  }
7948
8268
  });
@@ -7988,20 +8308,20 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
7988
8308
  } else if (isResponseFinishedChunk(value)) {
7989
8309
  finishReason = {
7990
8310
  unified: mapOpenAIResponseFinishReason({
7991
- finishReason: (_v = value.response.incomplete_details) == null ? void 0 : _v.reason,
8311
+ finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
7992
8312
  hasFunctionCall
7993
8313
  }),
7994
- raw: (_x = (_w = value.response.incomplete_details) == null ? void 0 : _w.reason) != null ? _x : void 0
8314
+ raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
7995
8315
  };
7996
8316
  usage = value.response.usage;
7997
8317
  if (typeof value.response.service_tier === "string") {
7998
8318
  serviceTier = value.response.service_tier;
7999
8319
  }
8000
- if (((_y = value.response.reasoning) == null ? void 0 : _y.context) != null) {
8320
+ if (((_A = value.response.reasoning) == null ? void 0 : _A.context) != null) {
8001
8321
  reasoningContext = value.response.reasoning.context;
8002
8322
  }
8003
8323
  } else if (isResponseFailedChunk(value)) {
8004
- const incompleteReason = (_z = value.response.incomplete_details) == null ? void 0 : _z.reason;
8324
+ const incompleteReason = (_B = value.response.incomplete_details) == null ? void 0 : _B.reason;
8005
8325
  finishReason = {
8006
8326
  unified: incompleteReason ? mapOpenAIResponseFinishReason({
8007
8327
  finishReason: incompleteReason,
@@ -8009,8 +8329,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8009
8329
  }) : "error",
8010
8330
  raw: incompleteReason != null ? incompleteReason : "error"
8011
8331
  };
8012
- usage = (_A = value.response.usage) != null ? _A : void 0;
8013
- if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
8332
+ usage = (_C = value.response.usage) != null ? _C : void 0;
8333
+ if (((_D = value.response.reasoning) == null ? void 0 : _D.context) != null) {
8014
8334
  reasoningContext = value.response.reasoning.context;
8015
8335
  }
8016
8336
  if (!encounteredStreamError && value.response.error != null) {
@@ -8034,7 +8354,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8034
8354
  controller.enqueue({
8035
8355
  type: "source",
8036
8356
  sourceType: "url",
8037
- id: (_E = (_D = (_C = self.config).generateId) == null ? void 0 : _D.call(_C)) != null ? _E : generateId2(),
8357
+ id: (_G = (_F = (_E = self.config).generateId) == null ? void 0 : _F.call(_E)) != null ? _G : generateId2(),
8038
8358
  url: value.annotation.url,
8039
8359
  title: value.annotation.title
8040
8360
  });
@@ -8042,7 +8362,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8042
8362
  controller.enqueue({
8043
8363
  type: "source",
8044
8364
  sourceType: "document",
8045
- id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
8365
+ id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : generateId2(),
8046
8366
  mediaType: "text/plain",
8047
8367
  title: value.annotation.filename,
8048
8368
  filename: value.annotation.filename,
@@ -8058,7 +8378,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8058
8378
  controller.enqueue({
8059
8379
  type: "source",
8060
8380
  sourceType: "document",
8061
- id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
8381
+ id: (_M = (_L = (_K = self.config).generateId) == null ? void 0 : _L.call(_K)) != null ? _M : generateId2(),
8062
8382
  mediaType: "text/plain",
8063
8383
  title: value.annotation.filename,
8064
8384
  filename: value.annotation.filename,
@@ -8074,7 +8394,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8074
8394
  controller.enqueue({
8075
8395
  type: "source",
8076
8396
  sourceType: "document",
8077
- id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
8397
+ id: (_P = (_O = (_N = self.config).generateId) == null ? void 0 : _O.call(_N)) != null ? _P : generateId2(),
8078
8398
  mediaType: "application/octet-stream",
8079
8399
  title: value.annotation.file_id,
8080
8400
  filename: value.annotation.file_id,
@@ -8094,6 +8414,24 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
8094
8414
  }
8095
8415
  },
8096
8416
  flush(controller) {
8417
+ var _a2;
8418
+ for (const toolCall of Object.values(ongoingToolCalls)) {
8419
+ if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
8420
+ continue;
8421
+ }
8422
+ controller.enqueue({
8423
+ type: "tool-input-start",
8424
+ id: toolCall.toolCallId,
8425
+ toolName: toolCall.toolName
8426
+ });
8427
+ for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
8428
+ controller.enqueue({
8429
+ type: "tool-input-delta",
8430
+ id: toolCall.toolCallId,
8431
+ delta
8432
+ });
8433
+ }
8434
+ }
8097
8435
  const providerMetadata = {
8098
8436
  [providerOptionsName]: {
8099
8437
  responseId,
@@ -9238,7 +9576,7 @@ import {
9238
9576
  mediaTypeToExtension,
9239
9577
  parseProviderOptions as parseProviderOptions9,
9240
9578
  postFormDataToApi as postFormDataToApi3,
9241
- safeParseJSON,
9579
+ safeParseJSON as safeParseJSON2,
9242
9580
  serializeModelOptions as serializeModelOptions7,
9243
9581
  toWebSocketUrl,
9244
9582
  WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE8,
@@ -9663,7 +10001,7 @@ function createOpenAIRealtimeTranscriptionStream({
9663
10001
  },
9664
10002
  onMessageText: async (text) => {
9665
10003
  var _a, _b, _c, _d;
9666
- const parsed = await safeParseJSON({ text });
10004
+ const parsed = await safeParseJSON2({ text });
9667
10005
  if (!parsed.success) return;
9668
10006
  const raw = parsed.value;
9669
10007
  if (includeRawChunks) {
@@ -9767,7 +10105,7 @@ import {
9767
10105
  connectToWebSocket as connectToWebSocket2,
9768
10106
  convertToBase64 as convertToBase644,
9769
10107
  parseProviderOptions as parseProviderOptions10,
9770
- safeParseJSON as safeParseJSON2,
10108
+ safeParseJSON as safeParseJSON3,
9771
10109
  serializeModelOptions as serializeModelOptions8,
9772
10110
  toWebSocketUrl as toWebSocketUrl2,
9773
10111
  WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE9,
@@ -9960,7 +10298,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
9960
10298
  onMessageText: async (text) => {
9961
10299
  var _a, _b, _c, _d, _e, _f;
9962
10300
  if (finished) return;
9963
- const parsed = await safeParseJSON2({ text });
10301
+ const parsed = await safeParseJSON3({ text });
9964
10302
  if (!parsed.success) return;
9965
10303
  const raw = parsed.value;
9966
10304
  if (includeRawChunks) {
@@ -10160,7 +10498,7 @@ var OpenAISkills = class {
10160
10498
  };
10161
10499
 
10162
10500
  // src/version.ts
10163
- var VERSION = true ? "4.0.43" : "0.0.0-test";
10501
+ var VERSION = true ? "4.0.45" : "0.0.0-test";
10164
10502
 
10165
10503
  // src/openai-provider.ts
10166
10504
  function createOpenAI(options = {}) {