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

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.
@@ -3242,6 +3242,19 @@ var openaiResponsesChunkSchema = lazySchema14(
3242
3242
  item_id: z16.string(),
3243
3243
  summary_index: z16.number()
3244
3244
  }),
3245
+ z16.object({
3246
+ type: z16.literal("response.apply_patch_call_operation_diff.delta"),
3247
+ item_id: z16.string(),
3248
+ output_index: z16.number(),
3249
+ delta: z16.string(),
3250
+ obfuscation: z16.string().nullish()
3251
+ }),
3252
+ z16.object({
3253
+ type: z16.literal("response.apply_patch_call_operation_diff.done"),
3254
+ item_id: z16.string(),
3255
+ output_index: z16.number(),
3256
+ diff: z16.string()
3257
+ }),
3245
3258
  z16.object({
3246
3259
  type: z16.literal("error"),
3247
3260
  sequence_number: z16.number(),
@@ -4999,24 +5012,40 @@ var OpenAIResponsesLanguageModel = class {
4999
5012
  providerExecuted: true
5000
5013
  });
5001
5014
  } else if (value.item.type === "apply_patch_call") {
5015
+ const { call_id: callId, operation } = value.item;
5002
5016
  ongoingToolCalls[value.output_index] = {
5003
5017
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
5004
- toolCallId: value.item.call_id
5018
+ toolCallId: callId,
5019
+ applyPatch: {
5020
+ // delete_file doesn't have diff
5021
+ hasDiff: operation.type === "delete_file",
5022
+ endEmitted: operation.type === "delete_file"
5023
+ }
5005
5024
  };
5006
- if (value.item.status === "completed") {
5025
+ controller.enqueue({
5026
+ type: "tool-input-start",
5027
+ id: callId,
5028
+ toolName: toolNameMapping.toCustomToolName("apply_patch")
5029
+ });
5030
+ if (operation.type === "delete_file") {
5031
+ const inputString = JSON.stringify({
5032
+ callId,
5033
+ operation
5034
+ });
5007
5035
  controller.enqueue({
5008
- type: "tool-call",
5009
- toolCallId: value.item.call_id,
5010
- toolName: toolNameMapping.toCustomToolName("apply_patch"),
5011
- input: JSON.stringify({
5012
- callId: value.item.call_id,
5013
- operation: value.item.operation
5014
- }),
5015
- providerMetadata: {
5016
- [providerKey]: {
5017
- itemId: value.item.id
5018
- }
5019
- }
5036
+ type: "tool-input-delta",
5037
+ id: callId,
5038
+ delta: inputString
5039
+ });
5040
+ controller.enqueue({
5041
+ type: "tool-input-end",
5042
+ id: callId
5043
+ });
5044
+ } else {
5045
+ controller.enqueue({
5046
+ type: "tool-input-delta",
5047
+ id: callId,
5048
+ delta: `{"callId":"${escapeJSONDelta(callId)}","operation":{"type":"${escapeJSONDelta(operation.type)}","path":"${escapeJSONDelta(operation.path)}","diff":"`
5020
5049
  });
5021
5050
  }
5022
5051
  } else if (value.item.type === "shell_call") {
@@ -5169,11 +5198,30 @@ var OpenAIResponsesLanguageModel = class {
5169
5198
  } else if (value.item.type === "mcp_list_tools") {
5170
5199
  ongoingToolCalls[value.output_index] = void 0;
5171
5200
  } else if (value.item.type === "apply_patch_call") {
5172
- ongoingToolCalls[value.output_index] = void 0;
5173
- if (value.item.status === "completed") {
5201
+ const toolCall = ongoingToolCalls[value.output_index];
5202
+ if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
5203
+ if (!toolCall.applyPatch.hasDiff) {
5204
+ controller.enqueue({
5205
+ type: "tool-input-delta",
5206
+ id: toolCall.toolCallId,
5207
+ delta: escapeJSONDelta(value.item.operation.diff)
5208
+ });
5209
+ }
5210
+ controller.enqueue({
5211
+ type: "tool-input-delta",
5212
+ id: toolCall.toolCallId,
5213
+ delta: '"}}'
5214
+ });
5215
+ controller.enqueue({
5216
+ type: "tool-input-end",
5217
+ id: toolCall.toolCallId
5218
+ });
5219
+ toolCall.applyPatch.endEmitted = true;
5220
+ }
5221
+ if (toolCall && value.item.status === "completed") {
5174
5222
  controller.enqueue({
5175
5223
  type: "tool-call",
5176
- toolCallId: value.item.call_id,
5224
+ toolCallId: toolCall.toolCallId,
5177
5225
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
5178
5226
  input: JSON.stringify({
5179
5227
  callId: value.item.call_id,
@@ -5186,6 +5234,7 @@ var OpenAIResponsesLanguageModel = class {
5186
5234
  }
5187
5235
  });
5188
5236
  }
5237
+ ongoingToolCalls[value.output_index] = void 0;
5189
5238
  } else if (value.item.type === "mcp_approval_request") {
5190
5239
  ongoingToolCalls[value.output_index] = void 0;
5191
5240
  } else if (value.item.type === "local_shell_call") {
@@ -5253,6 +5302,38 @@ var OpenAIResponsesLanguageModel = class {
5253
5302
  delta: value.delta
5254
5303
  });
5255
5304
  }
5305
+ } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
5306
+ const toolCall = ongoingToolCalls[value.output_index];
5307
+ if (toolCall == null ? void 0 : toolCall.applyPatch) {
5308
+ controller.enqueue({
5309
+ type: "tool-input-delta",
5310
+ id: toolCall.toolCallId,
5311
+ delta: escapeJSONDelta(value.delta)
5312
+ });
5313
+ toolCall.applyPatch.hasDiff = true;
5314
+ }
5315
+ } else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
5316
+ const toolCall = ongoingToolCalls[value.output_index];
5317
+ if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
5318
+ if (!toolCall.applyPatch.hasDiff) {
5319
+ controller.enqueue({
5320
+ type: "tool-input-delta",
5321
+ id: toolCall.toolCallId,
5322
+ delta: escapeJSONDelta(value.diff)
5323
+ });
5324
+ toolCall.applyPatch.hasDiff = true;
5325
+ }
5326
+ controller.enqueue({
5327
+ type: "tool-input-delta",
5328
+ id: toolCall.toolCallId,
5329
+ delta: '"}}'
5330
+ });
5331
+ controller.enqueue({
5332
+ type: "tool-input-end",
5333
+ id: toolCall.toolCallId
5334
+ });
5335
+ toolCall.applyPatch.endEmitted = true;
5336
+ }
5256
5337
  } else if (isResponseImageGenerationCallPartialImageChunk(value)) {
5257
5338
  controller.enqueue({
5258
5339
  type: "tool-result",
@@ -5269,9 +5350,7 @@ var OpenAIResponsesLanguageModel = class {
5269
5350
  controller.enqueue({
5270
5351
  type: "tool-input-delta",
5271
5352
  id: toolCall.toolCallId,
5272
- // The delta is code, which is embedding in a JSON string.
5273
- // To escape it, we use JSON.stringify and slice to remove the outer quotes.
5274
- delta: JSON.stringify(value.delta).slice(1, -1)
5353
+ delta: escapeJSONDelta(value.delta)
5275
5354
  });
5276
5355
  }
5277
5356
  } else if (isResponseCodeInterpreterCallCodeDoneChunk(value)) {
@@ -5491,6 +5570,12 @@ function isResponseCodeInterpreterCallCodeDeltaChunk(chunk) {
5491
5570
  function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
5492
5571
  return chunk.type === "response.code_interpreter_call_code.done";
5493
5572
  }
5573
+ function isResponseApplyPatchCallOperationDiffDeltaChunk(chunk) {
5574
+ return chunk.type === "response.apply_patch_call_operation_diff.delta";
5575
+ }
5576
+ function isResponseApplyPatchCallOperationDiffDoneChunk(chunk) {
5577
+ return chunk.type === "response.apply_patch_call_operation_diff.done";
5578
+ }
5494
5579
  function isResponseOutputItemAddedChunk(chunk) {
5495
5580
  return chunk.type === "response.output_item.added";
5496
5581
  }
@@ -5521,6 +5606,9 @@ function mapWebSearchOutput(action) {
5521
5606
  };
5522
5607
  }
5523
5608
  }
5609
+ function escapeJSONDelta(delta) {
5610
+ return JSON.stringify(delta).slice(1, -1);
5611
+ }
5524
5612
  export {
5525
5613
  OpenAIChatLanguageModel,
5526
5614
  OpenAICompletionLanguageModel,