@ai-sdk/openai 3.0.0-beta.109 → 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
@@ -245,6 +245,9 @@ function convertToOpenAIChatMessages({
245
245
  }
246
246
  case "tool": {
247
247
  for (const toolResponse of content) {
248
+ if (toolResponse.type === "tool-approval-response") {
249
+ continue;
250
+ }
248
251
  const output = toolResponse.output;
249
252
  let contentValue;
250
253
  switch (output.type) {
@@ -2331,16 +2334,14 @@ var mcpArgsSchema = lazySchema16(
2331
2334
  authorization: z17.string().optional(),
2332
2335
  connectorId: z17.string().optional(),
2333
2336
  headers: z17.record(z17.string(), z17.string()).optional(),
2334
- // TODO: Integrate this MCP tool approval with our SDK's existing tool approval architecture
2335
- // requireApproval: z
2336
- // .union([
2337
- // z.enum(['always', 'never']),
2338
- // z.object({
2339
- // readOnly: z.boolean().optional(),
2340
- // toolNames: z.array(z.string()).optional(),
2341
- // }),
2342
- // ])
2343
- // .optional(),
2337
+ requireApproval: z17.union([
2338
+ z17.enum(["always", "never"]),
2339
+ z17.object({
2340
+ never: z17.object({
2341
+ toolNames: z17.array(z17.string()).optional()
2342
+ }).optional()
2343
+ })
2344
+ ]).optional(),
2344
2345
  serverDescription: z17.string().optional(),
2345
2346
  serverUrl: z17.string().optional()
2346
2347
  }).refine(
@@ -2352,36 +2353,14 @@ var mcpArgsSchema = lazySchema16(
2352
2353
  var mcpInputSchema = lazySchema16(() => zodSchema16(z17.object({})));
2353
2354
  var mcpOutputSchema = lazySchema16(
2354
2355
  () => zodSchema16(
2355
- z17.discriminatedUnion("type", [
2356
- z17.object({
2357
- type: z17.literal("call"),
2358
- serverLabel: z17.string(),
2359
- name: z17.string(),
2360
- arguments: z17.string(),
2361
- output: z17.string().nullable().optional(),
2362
- error: z17.union([z17.string(), jsonValueSchema]).optional()
2363
- }),
2364
- z17.object({
2365
- type: z17.literal("listTools"),
2366
- serverLabel: z17.string(),
2367
- tools: z17.array(
2368
- z17.object({
2369
- name: z17.string(),
2370
- description: z17.string().optional(),
2371
- inputSchema: jsonValueSchema,
2372
- annotations: z17.record(z17.string(), jsonValueSchema).optional()
2373
- })
2374
- ),
2375
- error: z17.union([z17.string(), jsonValueSchema]).optional()
2376
- }),
2377
- z17.object({
2378
- type: z17.literal("approvalRequest"),
2379
- serverLabel: z17.string(),
2380
- name: z17.string(),
2381
- arguments: z17.string(),
2382
- approvalRequestId: z17.string()
2383
- })
2384
- ])
2356
+ z17.object({
2357
+ type: z17.literal("call"),
2358
+ serverLabel: z17.string(),
2359
+ name: z17.string(),
2360
+ arguments: z17.string(),
2361
+ output: z17.string().nullable().optional(),
2362
+ error: z17.union([z17.string(), jsonValueSchema]).optional()
2363
+ })
2385
2364
  )
2386
2365
  );
2387
2366
  var mcpToolFactory = createProviderToolFactoryWithOutputSchema9({
@@ -2790,6 +2769,9 @@ async function convertToOpenAIResponsesInput({
2790
2769
  }
2791
2770
  case "tool": {
2792
2771
  for (const part of content) {
2772
+ if (part.type === "tool-approval-response") {
2773
+ continue;
2774
+ }
2793
2775
  const output = part.output;
2794
2776
  const resolvedToolName = toolNameMapping.toProviderToolName(
2795
2777
  part.toolName
@@ -3316,6 +3298,19 @@ var openaiResponsesChunkSchema = lazySchema17(
3316
3298
  item_id: z19.string(),
3317
3299
  summary_index: z19.number()
3318
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
+ }),
3319
3314
  z19.object({
3320
3315
  type: z19.literal("error"),
3321
3316
  sequence_number: z19.number(),
@@ -4486,54 +4481,9 @@ var OpenAIResponsesLanguageModel = class {
4486
4481
  break;
4487
4482
  }
4488
4483
  case "mcp_list_tools": {
4489
- content.push({
4490
- type: "tool-call",
4491
- toolCallId: part.id,
4492
- toolName: toolNameMapping.toCustomToolName("mcp"),
4493
- input: JSON.stringify({}),
4494
- providerExecuted: true
4495
- });
4496
- content.push({
4497
- type: "tool-result",
4498
- toolCallId: part.id,
4499
- toolName: toolNameMapping.toCustomToolName("mcp"),
4500
- result: {
4501
- type: "listTools",
4502
- serverLabel: part.server_label,
4503
- tools: part.tools.map((t) => {
4504
- var _a2, _b2;
4505
- return {
4506
- name: t.name,
4507
- description: (_a2 = t.description) != null ? _a2 : void 0,
4508
- inputSchema: t.input_schema,
4509
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4510
- };
4511
- }),
4512
- ...part.error != null ? { error: part.error } : {}
4513
- }
4514
- });
4515
4484
  break;
4516
4485
  }
4517
4486
  case "mcp_approval_request": {
4518
- content.push({
4519
- type: "tool-call",
4520
- toolCallId: part.id,
4521
- toolName: toolNameMapping.toCustomToolName("mcp"),
4522
- input: JSON.stringify({}),
4523
- providerExecuted: true
4524
- });
4525
- content.push({
4526
- type: "tool-result",
4527
- toolCallId: part.id,
4528
- toolName: toolNameMapping.toCustomToolName("mcp"),
4529
- result: {
4530
- type: "approvalRequest",
4531
- serverLabel: part.server_label,
4532
- name: part.name,
4533
- arguments: part.arguments,
4534
- approvalRequestId: part.approval_request_id
4535
- }
4536
- });
4537
4487
  break;
4538
4488
  }
4539
4489
  case "computer_call": {
@@ -4802,24 +4752,40 @@ var OpenAIResponsesLanguageModel = class {
4802
4752
  providerExecuted: true
4803
4753
  });
4804
4754
  } else if (value.item.type === "apply_patch_call") {
4755
+ const { call_id: callId, operation } = value.item;
4805
4756
  ongoingToolCalls[value.output_index] = {
4806
4757
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
4807
- 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
+ }
4808
4764
  };
4809
- 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
+ });
4810
4775
  controller.enqueue({
4811
- type: "tool-call",
4812
- toolCallId: value.item.call_id,
4813
- toolName: toolNameMapping.toCustomToolName("apply_patch"),
4814
- input: JSON.stringify({
4815
- callId: value.item.call_id,
4816
- operation: value.item.operation
4817
- }),
4818
- providerMetadata: {
4819
- [providerKey]: {
4820
- itemId: value.item.id
4821
- }
4822
- }
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":"`
4823
4789
  });
4824
4790
  }
4825
4791
  } else if (value.item.type === "shell_call") {
@@ -4971,31 +4937,31 @@ var OpenAIResponsesLanguageModel = class {
4971
4937
  });
4972
4938
  } else if (value.item.type === "mcp_list_tools") {
4973
4939
  ongoingToolCalls[value.output_index] = void 0;
4974
- controller.enqueue({
4975
- type: "tool-result",
4976
- toolCallId: value.item.id,
4977
- toolName: toolNameMapping.toCustomToolName("mcp"),
4978
- result: {
4979
- type: "listTools",
4980
- serverLabel: value.item.server_label,
4981
- tools: value.item.tools.map((t) => {
4982
- var _a2, _b2;
4983
- return {
4984
- name: t.name,
4985
- description: (_a2 = t.description) != null ? _a2 : void 0,
4986
- inputSchema: t.input_schema,
4987
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4988
- };
4989
- }),
4990
- ...value.item.error != null ? { error: value.item.error } : {}
4991
- }
4992
- });
4993
4940
  } else if (value.item.type === "apply_patch_call") {
4994
- ongoingToolCalls[value.output_index] = void 0;
4995
- 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") {
4996
4962
  controller.enqueue({
4997
4963
  type: "tool-call",
4998
- toolCallId: value.item.call_id,
4964
+ toolCallId: toolCall.toolCallId,
4999
4965
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
5000
4966
  input: JSON.stringify({
5001
4967
  callId: value.item.call_id,
@@ -5008,20 +4974,9 @@ var OpenAIResponsesLanguageModel = class {
5008
4974
  }
5009
4975
  });
5010
4976
  }
4977
+ ongoingToolCalls[value.output_index] = void 0;
5011
4978
  } else if (value.item.type === "mcp_approval_request") {
5012
4979
  ongoingToolCalls[value.output_index] = void 0;
5013
- controller.enqueue({
5014
- type: "tool-result",
5015
- toolCallId: value.item.id,
5016
- toolName: toolNameMapping.toCustomToolName("mcp"),
5017
- result: {
5018
- type: "approvalRequest",
5019
- serverLabel: value.item.server_label,
5020
- name: value.item.name,
5021
- arguments: value.item.arguments,
5022
- approvalRequestId: value.item.approval_request_id
5023
- }
5024
- });
5025
4980
  } else if (value.item.type === "local_shell_call") {
5026
4981
  ongoingToolCalls[value.output_index] = void 0;
5027
4982
  controller.enqueue({
@@ -5087,6 +5042,38 @@ var OpenAIResponsesLanguageModel = class {
5087
5042
  delta: value.delta
5088
5043
  });
5089
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
+ }
5090
5077
  } else if (isResponseImageGenerationCallPartialImageChunk(value)) {
5091
5078
  controller.enqueue({
5092
5079
  type: "tool-result",
@@ -5103,9 +5090,7 @@ var OpenAIResponsesLanguageModel = class {
5103
5090
  controller.enqueue({
5104
5091
  type: "tool-input-delta",
5105
5092
  id: toolCall.toolCallId,
5106
- // The delta is code, which is embedding in a JSON string.
5107
- // To escape it, we use JSON.stringify and slice to remove the outer quotes.
5108
- delta: JSON.stringify(value.delta).slice(1, -1)
5093
+ delta: escapeJSONDelta(value.delta)
5109
5094
  });
5110
5095
  }
5111
5096
  } else if (isResponseCodeInterpreterCallCodeDoneChunk(value)) {
@@ -5325,6 +5310,12 @@ function isResponseCodeInterpreterCallCodeDeltaChunk(chunk) {
5325
5310
  function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
5326
5311
  return chunk.type === "response.code_interpreter_call_code.done";
5327
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
+ }
5328
5319
  function isResponseOutputItemAddedChunk(chunk) {
5329
5320
  return chunk.type === "response.output_item.added";
5330
5321
  }
@@ -5355,6 +5346,9 @@ function mapWebSearchOutput(action) {
5355
5346
  };
5356
5347
  }
5357
5348
  }
5349
+ function escapeJSONDelta(delta) {
5350
+ return JSON.stringify(delta).slice(1, -1);
5351
+ }
5358
5352
 
5359
5353
  // src/speech/openai-speech-model.ts
5360
5354
  import {
@@ -5721,7 +5715,7 @@ var OpenAITranscriptionModel = class {
5721
5715
  };
5722
5716
 
5723
5717
  // src/version.ts
5724
- var VERSION = true ? "3.0.0-beta.109" : "0.0.0-test";
5718
+ var VERSION = true ? "3.0.0-beta.111" : "0.0.0-test";
5725
5719
 
5726
5720
  // src/openai-provider.ts
5727
5721
  function createOpenAI(options = {}) {