@ai-sdk/openai 3.0.0-beta.110 → 3.0.0-beta.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -3298,6 +3298,19 @@ var openaiResponsesChunkSchema = lazySchema17(
3298
3298
  item_id: z19.string(),
3299
3299
  summary_index: z19.number()
3300
3300
  }),
3301
+ z19.object({
3302
+ type: z19.literal("response.apply_patch_call_operation_diff.delta"),
3303
+ item_id: z19.string(),
3304
+ output_index: z19.number(),
3305
+ delta: z19.string(),
3306
+ obfuscation: z19.string().nullish()
3307
+ }),
3308
+ z19.object({
3309
+ type: z19.literal("response.apply_patch_call_operation_diff.done"),
3310
+ item_id: z19.string(),
3311
+ output_index: z19.number(),
3312
+ diff: z19.string()
3313
+ }),
3301
3314
  z19.object({
3302
3315
  type: z19.literal("error"),
3303
3316
  sequence_number: z19.number(),
@@ -4739,24 +4752,40 @@ var OpenAIResponsesLanguageModel = class {
4739
4752
  providerExecuted: true
4740
4753
  });
4741
4754
  } else if (value.item.type === "apply_patch_call") {
4755
+ const { call_id: callId, operation } = value.item;
4742
4756
  ongoingToolCalls[value.output_index] = {
4743
4757
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
4744
- toolCallId: value.item.call_id
4758
+ toolCallId: callId,
4759
+ applyPatch: {
4760
+ // delete_file doesn't have diff
4761
+ hasDiff: operation.type === "delete_file",
4762
+ endEmitted: operation.type === "delete_file"
4763
+ }
4745
4764
  };
4746
- if (value.item.status === "completed") {
4765
+ controller.enqueue({
4766
+ type: "tool-input-start",
4767
+ id: callId,
4768
+ toolName: toolNameMapping.toCustomToolName("apply_patch")
4769
+ });
4770
+ if (operation.type === "delete_file") {
4771
+ const inputString = JSON.stringify({
4772
+ callId,
4773
+ operation
4774
+ });
4747
4775
  controller.enqueue({
4748
- type: "tool-call",
4749
- toolCallId: value.item.call_id,
4750
- toolName: toolNameMapping.toCustomToolName("apply_patch"),
4751
- input: JSON.stringify({
4752
- callId: value.item.call_id,
4753
- operation: value.item.operation
4754
- }),
4755
- providerMetadata: {
4756
- [providerKey]: {
4757
- itemId: value.item.id
4758
- }
4759
- }
4776
+ type: "tool-input-delta",
4777
+ id: callId,
4778
+ delta: inputString
4779
+ });
4780
+ controller.enqueue({
4781
+ type: "tool-input-end",
4782
+ id: callId
4783
+ });
4784
+ } else {
4785
+ controller.enqueue({
4786
+ type: "tool-input-delta",
4787
+ id: callId,
4788
+ delta: `{"callId":"${escapeJSONDelta(callId)}","operation":{"type":"${escapeJSONDelta(operation.type)}","path":"${escapeJSONDelta(operation.path)}","diff":"`
4760
4789
  });
4761
4790
  }
4762
4791
  } else if (value.item.type === "shell_call") {
@@ -4909,11 +4938,30 @@ var OpenAIResponsesLanguageModel = class {
4909
4938
  } else if (value.item.type === "mcp_list_tools") {
4910
4939
  ongoingToolCalls[value.output_index] = void 0;
4911
4940
  } else if (value.item.type === "apply_patch_call") {
4912
- ongoingToolCalls[value.output_index] = void 0;
4913
- if (value.item.status === "completed") {
4941
+ const toolCall = ongoingToolCalls[value.output_index];
4942
+ if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
4943
+ if (!toolCall.applyPatch.hasDiff) {
4944
+ controller.enqueue({
4945
+ type: "tool-input-delta",
4946
+ id: toolCall.toolCallId,
4947
+ delta: escapeJSONDelta(value.item.operation.diff)
4948
+ });
4949
+ }
4950
+ controller.enqueue({
4951
+ type: "tool-input-delta",
4952
+ id: toolCall.toolCallId,
4953
+ delta: '"}}'
4954
+ });
4955
+ controller.enqueue({
4956
+ type: "tool-input-end",
4957
+ id: toolCall.toolCallId
4958
+ });
4959
+ toolCall.applyPatch.endEmitted = true;
4960
+ }
4961
+ if (toolCall && value.item.status === "completed") {
4914
4962
  controller.enqueue({
4915
4963
  type: "tool-call",
4916
- toolCallId: value.item.call_id,
4964
+ toolCallId: toolCall.toolCallId,
4917
4965
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
4918
4966
  input: JSON.stringify({
4919
4967
  callId: value.item.call_id,
@@ -4926,6 +4974,7 @@ var OpenAIResponsesLanguageModel = class {
4926
4974
  }
4927
4975
  });
4928
4976
  }
4977
+ ongoingToolCalls[value.output_index] = void 0;
4929
4978
  } else if (value.item.type === "mcp_approval_request") {
4930
4979
  ongoingToolCalls[value.output_index] = void 0;
4931
4980
  } else if (value.item.type === "local_shell_call") {
@@ -4993,6 +5042,38 @@ var OpenAIResponsesLanguageModel = class {
4993
5042
  delta: value.delta
4994
5043
  });
4995
5044
  }
5045
+ } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
5046
+ const toolCall = ongoingToolCalls[value.output_index];
5047
+ if (toolCall == null ? void 0 : toolCall.applyPatch) {
5048
+ controller.enqueue({
5049
+ type: "tool-input-delta",
5050
+ id: toolCall.toolCallId,
5051
+ delta: escapeJSONDelta(value.delta)
5052
+ });
5053
+ toolCall.applyPatch.hasDiff = true;
5054
+ }
5055
+ } else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
5056
+ const toolCall = ongoingToolCalls[value.output_index];
5057
+ if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
5058
+ if (!toolCall.applyPatch.hasDiff) {
5059
+ controller.enqueue({
5060
+ type: "tool-input-delta",
5061
+ id: toolCall.toolCallId,
5062
+ delta: escapeJSONDelta(value.diff)
5063
+ });
5064
+ toolCall.applyPatch.hasDiff = true;
5065
+ }
5066
+ controller.enqueue({
5067
+ type: "tool-input-delta",
5068
+ id: toolCall.toolCallId,
5069
+ delta: '"}}'
5070
+ });
5071
+ controller.enqueue({
5072
+ type: "tool-input-end",
5073
+ id: toolCall.toolCallId
5074
+ });
5075
+ toolCall.applyPatch.endEmitted = true;
5076
+ }
4996
5077
  } else if (isResponseImageGenerationCallPartialImageChunk(value)) {
4997
5078
  controller.enqueue({
4998
5079
  type: "tool-result",
@@ -5009,9 +5090,7 @@ var OpenAIResponsesLanguageModel = class {
5009
5090
  controller.enqueue({
5010
5091
  type: "tool-input-delta",
5011
5092
  id: toolCall.toolCallId,
5012
- // The delta is code, which is embedding in a JSON string.
5013
- // To escape it, we use JSON.stringify and slice to remove the outer quotes.
5014
- delta: JSON.stringify(value.delta).slice(1, -1)
5093
+ delta: escapeJSONDelta(value.delta)
5015
5094
  });
5016
5095
  }
5017
5096
  } else if (isResponseCodeInterpreterCallCodeDoneChunk(value)) {
@@ -5231,6 +5310,12 @@ function isResponseCodeInterpreterCallCodeDeltaChunk(chunk) {
5231
5310
  function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
5232
5311
  return chunk.type === "response.code_interpreter_call_code.done";
5233
5312
  }
5313
+ function isResponseApplyPatchCallOperationDiffDeltaChunk(chunk) {
5314
+ return chunk.type === "response.apply_patch_call_operation_diff.delta";
5315
+ }
5316
+ function isResponseApplyPatchCallOperationDiffDoneChunk(chunk) {
5317
+ return chunk.type === "response.apply_patch_call_operation_diff.done";
5318
+ }
5234
5319
  function isResponseOutputItemAddedChunk(chunk) {
5235
5320
  return chunk.type === "response.output_item.added";
5236
5321
  }
@@ -5261,6 +5346,9 @@ function mapWebSearchOutput(action) {
5261
5346
  };
5262
5347
  }
5263
5348
  }
5349
+ function escapeJSONDelta(delta) {
5350
+ return JSON.stringify(delta).slice(1, -1);
5351
+ }
5264
5352
 
5265
5353
  // src/speech/openai-speech-model.ts
5266
5354
  import {
@@ -5627,7 +5715,7 @@ var OpenAITranscriptionModel = class {
5627
5715
  };
5628
5716
 
5629
5717
  // src/version.ts
5630
- var VERSION = true ? "3.0.0-beta.110" : "0.0.0-test";
5718
+ var VERSION = true ? "3.0.0-beta.111" : "0.0.0-test";
5631
5719
 
5632
5720
  // src/openai-provider.ts
5633
5721
  function createOpenAI(options = {}) {