@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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 3.0.0-beta.111
4
+
5
+ ### Patch Changes
6
+
7
+ - 304222e: Add streaming support for apply_patch partial diffs.
8
+
9
+ ## 3.0.0-beta.110
10
+
11
+ ### Patch Changes
12
+
13
+ - 2625a04: feat(openai); update spec for mcp approval
14
+ - Updated dependencies [2625a04]
15
+ - @ai-sdk/provider@3.0.0-beta.31
16
+ - @ai-sdk/provider-utils@4.0.0-beta.58
17
+
3
18
  ## 3.0.0-beta.109
4
19
 
5
20
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -417,6 +417,11 @@ declare const openaiTools: {
417
417
  authorization?: string;
418
418
  connectorId?: string;
419
419
  headers?: Record<string, string>;
420
+ requireApproval?: "always" | "never" | {
421
+ never?: {
422
+ toolNames?: string[];
423
+ };
424
+ };
420
425
  serverDescription?: string;
421
426
  serverUrl?: string;
422
427
  }) => _ai_sdk_provider_utils.Tool<{}, {
@@ -426,22 +431,6 @@ declare const openaiTools: {
426
431
  arguments: string;
427
432
  output?: string | null;
428
433
  error?: _ai_sdk_provider.JSONValue;
429
- } | {
430
- type: "listTools";
431
- serverLabel: string;
432
- tools: Array<{
433
- name: string;
434
- description?: string;
435
- inputSchema: unknown;
436
- annotations?: unknown;
437
- }>;
438
- error?: _ai_sdk_provider.JSONValue;
439
- } | {
440
- type: "approvalRequest";
441
- serverLabel: string;
442
- name: string;
443
- arguments: string;
444
- approvalRequestId: string;
445
434
  }>;
446
435
  };
447
436
 
package/dist/index.d.ts CHANGED
@@ -417,6 +417,11 @@ declare const openaiTools: {
417
417
  authorization?: string;
418
418
  connectorId?: string;
419
419
  headers?: Record<string, string>;
420
+ requireApproval?: "always" | "never" | {
421
+ never?: {
422
+ toolNames?: string[];
423
+ };
424
+ };
420
425
  serverDescription?: string;
421
426
  serverUrl?: string;
422
427
  }) => _ai_sdk_provider_utils.Tool<{}, {
@@ -426,22 +431,6 @@ declare const openaiTools: {
426
431
  arguments: string;
427
432
  output?: string | null;
428
433
  error?: _ai_sdk_provider.JSONValue;
429
- } | {
430
- type: "listTools";
431
- serverLabel: string;
432
- tools: Array<{
433
- name: string;
434
- description?: string;
435
- inputSchema: unknown;
436
- annotations?: unknown;
437
- }>;
438
- error?: _ai_sdk_provider.JSONValue;
439
- } | {
440
- type: "approvalRequest";
441
- serverLabel: string;
442
- name: string;
443
- arguments: string;
444
- approvalRequestId: string;
445
434
  }>;
446
435
  };
447
436
 
package/dist/index.js CHANGED
@@ -256,6 +256,9 @@ function convertToOpenAIChatMessages({
256
256
  }
257
257
  case "tool": {
258
258
  for (const toolResponse of content) {
259
+ if (toolResponse.type === "tool-approval-response") {
260
+ continue;
261
+ }
259
262
  const output = toolResponse.output;
260
263
  let contentValue;
261
264
  switch (output.type) {
@@ -2280,16 +2283,14 @@ var mcpArgsSchema = (0, import_provider_utils22.lazySchema)(
2280
2283
  authorization: import_v417.z.string().optional(),
2281
2284
  connectorId: import_v417.z.string().optional(),
2282
2285
  headers: import_v417.z.record(import_v417.z.string(), import_v417.z.string()).optional(),
2283
- // TODO: Integrate this MCP tool approval with our SDK's existing tool approval architecture
2284
- // requireApproval: z
2285
- // .union([
2286
- // z.enum(['always', 'never']),
2287
- // z.object({
2288
- // readOnly: z.boolean().optional(),
2289
- // toolNames: z.array(z.string()).optional(),
2290
- // }),
2291
- // ])
2292
- // .optional(),
2286
+ requireApproval: import_v417.z.union([
2287
+ import_v417.z.enum(["always", "never"]),
2288
+ import_v417.z.object({
2289
+ never: import_v417.z.object({
2290
+ toolNames: import_v417.z.array(import_v417.z.string()).optional()
2291
+ }).optional()
2292
+ })
2293
+ ]).optional(),
2293
2294
  serverDescription: import_v417.z.string().optional(),
2294
2295
  serverUrl: import_v417.z.string().optional()
2295
2296
  }).refine(
@@ -2301,36 +2302,14 @@ var mcpArgsSchema = (0, import_provider_utils22.lazySchema)(
2301
2302
  var mcpInputSchema = (0, import_provider_utils22.lazySchema)(() => (0, import_provider_utils22.zodSchema)(import_v417.z.object({})));
2302
2303
  var mcpOutputSchema = (0, import_provider_utils22.lazySchema)(
2303
2304
  () => (0, import_provider_utils22.zodSchema)(
2304
- import_v417.z.discriminatedUnion("type", [
2305
- import_v417.z.object({
2306
- type: import_v417.z.literal("call"),
2307
- serverLabel: import_v417.z.string(),
2308
- name: import_v417.z.string(),
2309
- arguments: import_v417.z.string(),
2310
- output: import_v417.z.string().nullable().optional(),
2311
- error: import_v417.z.union([import_v417.z.string(), jsonValueSchema]).optional()
2312
- }),
2313
- import_v417.z.object({
2314
- type: import_v417.z.literal("listTools"),
2315
- serverLabel: import_v417.z.string(),
2316
- tools: import_v417.z.array(
2317
- import_v417.z.object({
2318
- name: import_v417.z.string(),
2319
- description: import_v417.z.string().optional(),
2320
- inputSchema: jsonValueSchema,
2321
- annotations: import_v417.z.record(import_v417.z.string(), jsonValueSchema).optional()
2322
- })
2323
- ),
2324
- error: import_v417.z.union([import_v417.z.string(), jsonValueSchema]).optional()
2325
- }),
2326
- import_v417.z.object({
2327
- type: import_v417.z.literal("approvalRequest"),
2328
- serverLabel: import_v417.z.string(),
2329
- name: import_v417.z.string(),
2330
- arguments: import_v417.z.string(),
2331
- approvalRequestId: import_v417.z.string()
2332
- })
2333
- ])
2305
+ import_v417.z.object({
2306
+ type: import_v417.z.literal("call"),
2307
+ serverLabel: import_v417.z.string(),
2308
+ name: import_v417.z.string(),
2309
+ arguments: import_v417.z.string(),
2310
+ output: import_v417.z.string().nullable().optional(),
2311
+ error: import_v417.z.union([import_v417.z.string(), jsonValueSchema]).optional()
2312
+ })
2334
2313
  )
2335
2314
  );
2336
2315
  var mcpToolFactory = (0, import_provider_utils22.createProviderToolFactoryWithOutputSchema)({
@@ -2722,6 +2701,9 @@ async function convertToOpenAIResponsesInput({
2722
2701
  }
2723
2702
  case "tool": {
2724
2703
  for (const part of content) {
2704
+ if (part.type === "tool-approval-response") {
2705
+ continue;
2706
+ }
2725
2707
  const output = part.output;
2726
2708
  const resolvedToolName = toolNameMapping.toProviderToolName(
2727
2709
  part.toolName
@@ -3248,6 +3230,19 @@ var openaiResponsesChunkSchema = (0, import_provider_utils24.lazySchema)(
3248
3230
  item_id: import_v419.z.string(),
3249
3231
  summary_index: import_v419.z.number()
3250
3232
  }),
3233
+ import_v419.z.object({
3234
+ type: import_v419.z.literal("response.apply_patch_call_operation_diff.delta"),
3235
+ item_id: import_v419.z.string(),
3236
+ output_index: import_v419.z.number(),
3237
+ delta: import_v419.z.string(),
3238
+ obfuscation: import_v419.z.string().nullish()
3239
+ }),
3240
+ import_v419.z.object({
3241
+ type: import_v419.z.literal("response.apply_patch_call_operation_diff.done"),
3242
+ item_id: import_v419.z.string(),
3243
+ output_index: import_v419.z.number(),
3244
+ diff: import_v419.z.string()
3245
+ }),
3251
3246
  import_v419.z.object({
3252
3247
  type: import_v419.z.literal("error"),
3253
3248
  sequence_number: import_v419.z.number(),
@@ -4416,54 +4411,9 @@ var OpenAIResponsesLanguageModel = class {
4416
4411
  break;
4417
4412
  }
4418
4413
  case "mcp_list_tools": {
4419
- content.push({
4420
- type: "tool-call",
4421
- toolCallId: part.id,
4422
- toolName: toolNameMapping.toCustomToolName("mcp"),
4423
- input: JSON.stringify({}),
4424
- providerExecuted: true
4425
- });
4426
- content.push({
4427
- type: "tool-result",
4428
- toolCallId: part.id,
4429
- toolName: toolNameMapping.toCustomToolName("mcp"),
4430
- result: {
4431
- type: "listTools",
4432
- serverLabel: part.server_label,
4433
- tools: part.tools.map((t) => {
4434
- var _a2, _b2;
4435
- return {
4436
- name: t.name,
4437
- description: (_a2 = t.description) != null ? _a2 : void 0,
4438
- inputSchema: t.input_schema,
4439
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4440
- };
4441
- }),
4442
- ...part.error != null ? { error: part.error } : {}
4443
- }
4444
- });
4445
4414
  break;
4446
4415
  }
4447
4416
  case "mcp_approval_request": {
4448
- content.push({
4449
- type: "tool-call",
4450
- toolCallId: part.id,
4451
- toolName: toolNameMapping.toCustomToolName("mcp"),
4452
- input: JSON.stringify({}),
4453
- providerExecuted: true
4454
- });
4455
- content.push({
4456
- type: "tool-result",
4457
- toolCallId: part.id,
4458
- toolName: toolNameMapping.toCustomToolName("mcp"),
4459
- result: {
4460
- type: "approvalRequest",
4461
- serverLabel: part.server_label,
4462
- name: part.name,
4463
- arguments: part.arguments,
4464
- approvalRequestId: part.approval_request_id
4465
- }
4466
- });
4467
4417
  break;
4468
4418
  }
4469
4419
  case "computer_call": {
@@ -4732,24 +4682,40 @@ var OpenAIResponsesLanguageModel = class {
4732
4682
  providerExecuted: true
4733
4683
  });
4734
4684
  } else if (value.item.type === "apply_patch_call") {
4685
+ const { call_id: callId, operation } = value.item;
4735
4686
  ongoingToolCalls[value.output_index] = {
4736
4687
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
4737
- toolCallId: value.item.call_id
4688
+ toolCallId: callId,
4689
+ applyPatch: {
4690
+ // delete_file doesn't have diff
4691
+ hasDiff: operation.type === "delete_file",
4692
+ endEmitted: operation.type === "delete_file"
4693
+ }
4738
4694
  };
4739
- if (value.item.status === "completed") {
4695
+ controller.enqueue({
4696
+ type: "tool-input-start",
4697
+ id: callId,
4698
+ toolName: toolNameMapping.toCustomToolName("apply_patch")
4699
+ });
4700
+ if (operation.type === "delete_file") {
4701
+ const inputString = JSON.stringify({
4702
+ callId,
4703
+ operation
4704
+ });
4740
4705
  controller.enqueue({
4741
- type: "tool-call",
4742
- toolCallId: value.item.call_id,
4743
- toolName: toolNameMapping.toCustomToolName("apply_patch"),
4744
- input: JSON.stringify({
4745
- callId: value.item.call_id,
4746
- operation: value.item.operation
4747
- }),
4748
- providerMetadata: {
4749
- [providerKey]: {
4750
- itemId: value.item.id
4751
- }
4752
- }
4706
+ type: "tool-input-delta",
4707
+ id: callId,
4708
+ delta: inputString
4709
+ });
4710
+ controller.enqueue({
4711
+ type: "tool-input-end",
4712
+ id: callId
4713
+ });
4714
+ } else {
4715
+ controller.enqueue({
4716
+ type: "tool-input-delta",
4717
+ id: callId,
4718
+ delta: `{"callId":"${escapeJSONDelta(callId)}","operation":{"type":"${escapeJSONDelta(operation.type)}","path":"${escapeJSONDelta(operation.path)}","diff":"`
4753
4719
  });
4754
4720
  }
4755
4721
  } else if (value.item.type === "shell_call") {
@@ -4901,31 +4867,31 @@ var OpenAIResponsesLanguageModel = class {
4901
4867
  });
4902
4868
  } else if (value.item.type === "mcp_list_tools") {
4903
4869
  ongoingToolCalls[value.output_index] = void 0;
4904
- controller.enqueue({
4905
- type: "tool-result",
4906
- toolCallId: value.item.id,
4907
- toolName: toolNameMapping.toCustomToolName("mcp"),
4908
- result: {
4909
- type: "listTools",
4910
- serverLabel: value.item.server_label,
4911
- tools: value.item.tools.map((t) => {
4912
- var _a2, _b2;
4913
- return {
4914
- name: t.name,
4915
- description: (_a2 = t.description) != null ? _a2 : void 0,
4916
- inputSchema: t.input_schema,
4917
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4918
- };
4919
- }),
4920
- ...value.item.error != null ? { error: value.item.error } : {}
4921
- }
4922
- });
4923
4870
  } else if (value.item.type === "apply_patch_call") {
4924
- ongoingToolCalls[value.output_index] = void 0;
4925
- if (value.item.status === "completed") {
4871
+ const toolCall = ongoingToolCalls[value.output_index];
4872
+ if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
4873
+ if (!toolCall.applyPatch.hasDiff) {
4874
+ controller.enqueue({
4875
+ type: "tool-input-delta",
4876
+ id: toolCall.toolCallId,
4877
+ delta: escapeJSONDelta(value.item.operation.diff)
4878
+ });
4879
+ }
4880
+ controller.enqueue({
4881
+ type: "tool-input-delta",
4882
+ id: toolCall.toolCallId,
4883
+ delta: '"}}'
4884
+ });
4885
+ controller.enqueue({
4886
+ type: "tool-input-end",
4887
+ id: toolCall.toolCallId
4888
+ });
4889
+ toolCall.applyPatch.endEmitted = true;
4890
+ }
4891
+ if (toolCall && value.item.status === "completed") {
4926
4892
  controller.enqueue({
4927
4893
  type: "tool-call",
4928
- toolCallId: value.item.call_id,
4894
+ toolCallId: toolCall.toolCallId,
4929
4895
  toolName: toolNameMapping.toCustomToolName("apply_patch"),
4930
4896
  input: JSON.stringify({
4931
4897
  callId: value.item.call_id,
@@ -4938,20 +4904,9 @@ var OpenAIResponsesLanguageModel = class {
4938
4904
  }
4939
4905
  });
4940
4906
  }
4907
+ ongoingToolCalls[value.output_index] = void 0;
4941
4908
  } else if (value.item.type === "mcp_approval_request") {
4942
4909
  ongoingToolCalls[value.output_index] = void 0;
4943
- controller.enqueue({
4944
- type: "tool-result",
4945
- toolCallId: value.item.id,
4946
- toolName: toolNameMapping.toCustomToolName("mcp"),
4947
- result: {
4948
- type: "approvalRequest",
4949
- serverLabel: value.item.server_label,
4950
- name: value.item.name,
4951
- arguments: value.item.arguments,
4952
- approvalRequestId: value.item.approval_request_id
4953
- }
4954
- });
4955
4910
  } else if (value.item.type === "local_shell_call") {
4956
4911
  ongoingToolCalls[value.output_index] = void 0;
4957
4912
  controller.enqueue({
@@ -5017,6 +4972,38 @@ var OpenAIResponsesLanguageModel = class {
5017
4972
  delta: value.delta
5018
4973
  });
5019
4974
  }
4975
+ } else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
4976
+ const toolCall = ongoingToolCalls[value.output_index];
4977
+ if (toolCall == null ? void 0 : toolCall.applyPatch) {
4978
+ controller.enqueue({
4979
+ type: "tool-input-delta",
4980
+ id: toolCall.toolCallId,
4981
+ delta: escapeJSONDelta(value.delta)
4982
+ });
4983
+ toolCall.applyPatch.hasDiff = true;
4984
+ }
4985
+ } else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
4986
+ const toolCall = ongoingToolCalls[value.output_index];
4987
+ if ((toolCall == null ? void 0 : toolCall.applyPatch) && !toolCall.applyPatch.endEmitted) {
4988
+ if (!toolCall.applyPatch.hasDiff) {
4989
+ controller.enqueue({
4990
+ type: "tool-input-delta",
4991
+ id: toolCall.toolCallId,
4992
+ delta: escapeJSONDelta(value.diff)
4993
+ });
4994
+ toolCall.applyPatch.hasDiff = true;
4995
+ }
4996
+ controller.enqueue({
4997
+ type: "tool-input-delta",
4998
+ id: toolCall.toolCallId,
4999
+ delta: '"}}'
5000
+ });
5001
+ controller.enqueue({
5002
+ type: "tool-input-end",
5003
+ id: toolCall.toolCallId
5004
+ });
5005
+ toolCall.applyPatch.endEmitted = true;
5006
+ }
5020
5007
  } else if (isResponseImageGenerationCallPartialImageChunk(value)) {
5021
5008
  controller.enqueue({
5022
5009
  type: "tool-result",
@@ -5033,9 +5020,7 @@ var OpenAIResponsesLanguageModel = class {
5033
5020
  controller.enqueue({
5034
5021
  type: "tool-input-delta",
5035
5022
  id: toolCall.toolCallId,
5036
- // The delta is code, which is embedding in a JSON string.
5037
- // To escape it, we use JSON.stringify and slice to remove the outer quotes.
5038
- delta: JSON.stringify(value.delta).slice(1, -1)
5023
+ delta: escapeJSONDelta(value.delta)
5039
5024
  });
5040
5025
  }
5041
5026
  } else if (isResponseCodeInterpreterCallCodeDoneChunk(value)) {
@@ -5255,6 +5240,12 @@ function isResponseCodeInterpreterCallCodeDeltaChunk(chunk) {
5255
5240
  function isResponseCodeInterpreterCallCodeDoneChunk(chunk) {
5256
5241
  return chunk.type === "response.code_interpreter_call_code.done";
5257
5242
  }
5243
+ function isResponseApplyPatchCallOperationDiffDeltaChunk(chunk) {
5244
+ return chunk.type === "response.apply_patch_call_operation_diff.delta";
5245
+ }
5246
+ function isResponseApplyPatchCallOperationDiffDoneChunk(chunk) {
5247
+ return chunk.type === "response.apply_patch_call_operation_diff.done";
5248
+ }
5258
5249
  function isResponseOutputItemAddedChunk(chunk) {
5259
5250
  return chunk.type === "response.output_item.added";
5260
5251
  }
@@ -5285,6 +5276,9 @@ function mapWebSearchOutput(action) {
5285
5276
  };
5286
5277
  }
5287
5278
  }
5279
+ function escapeJSONDelta(delta) {
5280
+ return JSON.stringify(delta).slice(1, -1);
5281
+ }
5288
5282
 
5289
5283
  // src/speech/openai-speech-model.ts
5290
5284
  var import_provider_utils29 = require("@ai-sdk/provider-utils");
@@ -5639,7 +5633,7 @@ var OpenAITranscriptionModel = class {
5639
5633
  };
5640
5634
 
5641
5635
  // src/version.ts
5642
- var VERSION = true ? "3.0.0-beta.109" : "0.0.0-test";
5636
+ var VERSION = true ? "3.0.0-beta.111" : "0.0.0-test";
5643
5637
 
5644
5638
  // src/openai-provider.ts
5645
5639
  function createOpenAI(options = {}) {