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

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.
@@ -237,6 +237,9 @@ function convertToOpenAIChatMessages({
237
237
  }
238
238
  case "tool": {
239
239
  for (const toolResponse of content) {
240
+ if (toolResponse.type === "tool-approval-response") {
241
+ continue;
242
+ }
240
243
  const output = toolResponse.output;
241
244
  let contentValue;
242
245
  switch (output.type) {
@@ -296,7 +299,7 @@ function mapOpenAIFinishReason(finishReason) {
296
299
  case "tool_calls":
297
300
  return "tool-calls";
298
301
  default:
299
- return "unknown";
302
+ return "other";
300
303
  }
301
304
  }
302
305
 
@@ -820,7 +823,7 @@ var OpenAIChatLanguageModel = class {
820
823
  };
821
824
  }
822
825
  async doGenerate(options) {
823
- var _a, _b, _c, _d, _e, _f;
826
+ var _a, _b, _c, _d, _e, _f, _g;
824
827
  const { args: body, warnings } = await this.getArgs(options);
825
828
  const {
826
829
  responseHeaders,
@@ -877,7 +880,10 @@ var OpenAIChatLanguageModel = class {
877
880
  }
878
881
  return {
879
882
  content,
880
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
883
+ finishReason: {
884
+ unified: mapOpenAIFinishReason(choice.finish_reason),
885
+ raw: (_g = choice.finish_reason) != null ? _g : void 0
886
+ },
881
887
  usage: convertOpenAIChatUsage(response.usage),
882
888
  request: { body },
883
889
  response: {
@@ -913,7 +919,10 @@ var OpenAIChatLanguageModel = class {
913
919
  fetch: this.config.fetch
914
920
  });
915
921
  const toolCalls = [];
916
- let finishReason = "unknown";
922
+ let finishReason = {
923
+ unified: "other",
924
+ raw: void 0
925
+ };
917
926
  let usage = void 0;
918
927
  let metadataExtracted = false;
919
928
  let isActiveText = false;
@@ -930,13 +939,13 @@ var OpenAIChatLanguageModel = class {
930
939
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
931
940
  }
932
941
  if (!chunk.success) {
933
- finishReason = "error";
942
+ finishReason = { unified: "error", raw: void 0 };
934
943
  controller.enqueue({ type: "error", error: chunk.error });
935
944
  return;
936
945
  }
937
946
  const value = chunk.value;
938
947
  if ("error" in value) {
939
- finishReason = "error";
948
+ finishReason = { unified: "error", raw: void 0 };
940
949
  controller.enqueue({ type: "error", error: value.error });
941
950
  return;
942
951
  }
@@ -961,7 +970,10 @@ var OpenAIChatLanguageModel = class {
961
970
  }
962
971
  const choice = value.choices[0];
963
972
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
964
- finishReason = mapOpenAIFinishReason(choice.finish_reason);
973
+ finishReason = {
974
+ unified: mapOpenAIFinishReason(choice.finish_reason),
975
+ raw: choice.finish_reason
976
+ };
965
977
  }
966
978
  if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) {
967
979
  providerMetadata.openai.logprobs = choice.logprobs.content;
@@ -1250,7 +1262,7 @@ function mapOpenAIFinishReason2(finishReason) {
1250
1262
  case "tool_calls":
1251
1263
  return "tool-calls";
1252
1264
  default:
1253
- return "unknown";
1265
+ return "other";
1254
1266
  }
1255
1267
  }
1256
1268
 
@@ -1448,6 +1460,7 @@ var OpenAICompletionLanguageModel = class {
1448
1460
  };
1449
1461
  }
1450
1462
  async doGenerate(options) {
1463
+ var _a;
1451
1464
  const { args, warnings } = await this.getArgs(options);
1452
1465
  const {
1453
1466
  responseHeaders,
@@ -1475,7 +1488,10 @@ var OpenAICompletionLanguageModel = class {
1475
1488
  return {
1476
1489
  content: [{ type: "text", text: choice.text }],
1477
1490
  usage: convertOpenAICompletionUsage(response.usage),
1478
- finishReason: mapOpenAIFinishReason2(choice.finish_reason),
1491
+ finishReason: {
1492
+ unified: mapOpenAIFinishReason2(choice.finish_reason),
1493
+ raw: (_a = choice.finish_reason) != null ? _a : void 0
1494
+ },
1479
1495
  request: { body: args },
1480
1496
  response: {
1481
1497
  ...getResponseMetadata2(response),
@@ -1509,7 +1525,10 @@ var OpenAICompletionLanguageModel = class {
1509
1525
  abortSignal: options.abortSignal,
1510
1526
  fetch: this.config.fetch
1511
1527
  });
1512
- let finishReason = "unknown";
1528
+ let finishReason = {
1529
+ unified: "other",
1530
+ raw: void 0
1531
+ };
1513
1532
  const providerMetadata = { openai: {} };
1514
1533
  let usage = void 0;
1515
1534
  let isFirstChunk = true;
@@ -1524,13 +1543,13 @@ var OpenAICompletionLanguageModel = class {
1524
1543
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1525
1544
  }
1526
1545
  if (!chunk.success) {
1527
- finishReason = "error";
1546
+ finishReason = { unified: "error", raw: void 0 };
1528
1547
  controller.enqueue({ type: "error", error: chunk.error });
1529
1548
  return;
1530
1549
  }
1531
1550
  const value = chunk.value;
1532
1551
  if ("error" in value) {
1533
- finishReason = "error";
1552
+ finishReason = { unified: "error", raw: void 0 };
1534
1553
  controller.enqueue({ type: "error", error: value.error });
1535
1554
  return;
1536
1555
  }
@@ -1547,7 +1566,10 @@ var OpenAICompletionLanguageModel = class {
1547
1566
  }
1548
1567
  const choice = value.choices[0];
1549
1568
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1550
- finishReason = mapOpenAIFinishReason2(choice.finish_reason);
1569
+ finishReason = {
1570
+ unified: mapOpenAIFinishReason2(choice.finish_reason),
1571
+ raw: choice.finish_reason
1572
+ };
1551
1573
  }
1552
1574
  if ((choice == null ? void 0 : choice.logprobs) != null) {
1553
1575
  providerMetadata.openai.logprobs = choice.logprobs;
@@ -2691,6 +2713,9 @@ async function convertToOpenAIResponsesInput({
2691
2713
  }
2692
2714
  case "tool": {
2693
2715
  for (const part of content) {
2716
+ if (part.type === "tool-approval-response") {
2717
+ continue;
2718
+ }
2694
2719
  const output = part.output;
2695
2720
  const resolvedToolName = toolNameMapping.toProviderToolName(
2696
2721
  part.toolName
@@ -2818,7 +2843,7 @@ function mapOpenAIResponseFinishReason({
2818
2843
  case "content_filter":
2819
2844
  return "content-filter";
2820
2845
  default:
2821
- return hasFunctionCall ? "tool-calls" : "unknown";
2846
+ return hasFunctionCall ? "tool-calls" : "other";
2822
2847
  }
2823
2848
  }
2824
2849
 
@@ -3898,16 +3923,14 @@ var mcpArgsSchema = lazySchema19(
3898
3923
  authorization: z21.string().optional(),
3899
3924
  connectorId: z21.string().optional(),
3900
3925
  headers: z21.record(z21.string(), z21.string()).optional(),
3901
- // TODO: Integrate this MCP tool approval with our SDK's existing tool approval architecture
3902
- // requireApproval: z
3903
- // .union([
3904
- // z.enum(['always', 'never']),
3905
- // z.object({
3906
- // readOnly: z.boolean().optional(),
3907
- // toolNames: z.array(z.string()).optional(),
3908
- // }),
3909
- // ])
3910
- // .optional(),
3926
+ requireApproval: z21.union([
3927
+ z21.enum(["always", "never"]),
3928
+ z21.object({
3929
+ never: z21.object({
3930
+ toolNames: z21.array(z21.string()).optional()
3931
+ }).optional()
3932
+ })
3933
+ ]).optional(),
3911
3934
  serverDescription: z21.string().optional(),
3912
3935
  serverUrl: z21.string().optional()
3913
3936
  }).refine(
@@ -3919,36 +3942,14 @@ var mcpArgsSchema = lazySchema19(
3919
3942
  var mcpInputSchema = lazySchema19(() => zodSchema19(z21.object({})));
3920
3943
  var mcpOutputSchema = lazySchema19(
3921
3944
  () => zodSchema19(
3922
- z21.discriminatedUnion("type", [
3923
- z21.object({
3924
- type: z21.literal("call"),
3925
- serverLabel: z21.string(),
3926
- name: z21.string(),
3927
- arguments: z21.string(),
3928
- output: z21.string().nullable().optional(),
3929
- error: z21.union([z21.string(), jsonValueSchema]).optional()
3930
- }),
3931
- z21.object({
3932
- type: z21.literal("listTools"),
3933
- serverLabel: z21.string(),
3934
- tools: z21.array(
3935
- z21.object({
3936
- name: z21.string(),
3937
- description: z21.string().optional(),
3938
- inputSchema: jsonValueSchema,
3939
- annotations: z21.record(z21.string(), jsonValueSchema).optional()
3940
- })
3941
- ),
3942
- error: z21.union([z21.string(), jsonValueSchema]).optional()
3943
- }),
3944
- z21.object({
3945
- type: z21.literal("approvalRequest"),
3946
- serverLabel: z21.string(),
3947
- name: z21.string(),
3948
- arguments: z21.string(),
3949
- approvalRequestId: z21.string()
3950
- })
3951
- ])
3945
+ z21.object({
3946
+ type: z21.literal("call"),
3947
+ serverLabel: z21.string(),
3948
+ name: z21.string(),
3949
+ arguments: z21.string(),
3950
+ output: z21.string().nullable().optional(),
3951
+ error: z21.union([z21.string(), jsonValueSchema]).optional()
3952
+ })
3952
3953
  )
3953
3954
  );
3954
3955
  var mcpToolFactory = createProviderToolFactoryWithOutputSchema7({
@@ -4476,7 +4477,7 @@ var OpenAIResponsesLanguageModel = class {
4476
4477
  };
4477
4478
  }
4478
4479
  async doGenerate(options) {
4479
- 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;
4480
+ 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;
4480
4481
  const {
4481
4482
  args: body,
4482
4483
  warnings,
@@ -4727,54 +4728,9 @@ var OpenAIResponsesLanguageModel = class {
4727
4728
  break;
4728
4729
  }
4729
4730
  case "mcp_list_tools": {
4730
- content.push({
4731
- type: "tool-call",
4732
- toolCallId: part.id,
4733
- toolName: toolNameMapping.toCustomToolName("mcp"),
4734
- input: JSON.stringify({}),
4735
- providerExecuted: true
4736
- });
4737
- content.push({
4738
- type: "tool-result",
4739
- toolCallId: part.id,
4740
- toolName: toolNameMapping.toCustomToolName("mcp"),
4741
- result: {
4742
- type: "listTools",
4743
- serverLabel: part.server_label,
4744
- tools: part.tools.map((t) => {
4745
- var _a2, _b2;
4746
- return {
4747
- name: t.name,
4748
- description: (_a2 = t.description) != null ? _a2 : void 0,
4749
- inputSchema: t.input_schema,
4750
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4751
- };
4752
- }),
4753
- ...part.error != null ? { error: part.error } : {}
4754
- }
4755
- });
4756
4731
  break;
4757
4732
  }
4758
4733
  case "mcp_approval_request": {
4759
- content.push({
4760
- type: "tool-call",
4761
- toolCallId: part.id,
4762
- toolName: toolNameMapping.toCustomToolName("mcp"),
4763
- input: JSON.stringify({}),
4764
- providerExecuted: true
4765
- });
4766
- content.push({
4767
- type: "tool-result",
4768
- toolCallId: part.id,
4769
- toolName: toolNameMapping.toCustomToolName("mcp"),
4770
- result: {
4771
- type: "approvalRequest",
4772
- serverLabel: part.server_label,
4773
- name: part.name,
4774
- arguments: part.arguments,
4775
- approvalRequestId: part.approval_request_id
4776
- }
4777
- });
4778
4734
  break;
4779
4735
  }
4780
4736
  case "computer_call": {
@@ -4873,10 +4829,13 @@ var OpenAIResponsesLanguageModel = class {
4873
4829
  const usage = response.usage;
4874
4830
  return {
4875
4831
  content,
4876
- finishReason: mapOpenAIResponseFinishReason({
4877
- finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
4878
- hasFunctionCall
4879
- }),
4832
+ finishReason: {
4833
+ unified: mapOpenAIResponseFinishReason({
4834
+ finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
4835
+ hasFunctionCall
4836
+ }),
4837
+ raw: (_z = (_y = response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
4838
+ },
4880
4839
  usage: convertOpenAIResponsesUsage(usage),
4881
4840
  request: { body },
4882
4841
  response: {
@@ -4917,7 +4876,10 @@ var OpenAIResponsesLanguageModel = class {
4917
4876
  });
4918
4877
  const self = this;
4919
4878
  const providerKey = this.config.provider.replace(".responses", "");
4920
- let finishReason = "unknown";
4879
+ let finishReason = {
4880
+ unified: "other",
4881
+ raw: void 0
4882
+ };
4921
4883
  let usage = void 0;
4922
4884
  const logprobs = [];
4923
4885
  let responseId = null;
@@ -4933,12 +4895,12 @@ var OpenAIResponsesLanguageModel = class {
4933
4895
  controller.enqueue({ type: "stream-start", warnings });
4934
4896
  },
4935
4897
  transform(chunk, controller) {
4936
- 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;
4898
+ 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;
4937
4899
  if (options.includeRawChunks) {
4938
4900
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
4939
4901
  }
4940
4902
  if (!chunk.success) {
4941
- finishReason = "error";
4903
+ finishReason = { unified: "error", raw: void 0 };
4942
4904
  controller.enqueue({ type: "error", error: chunk.error });
4943
4905
  return;
4944
4906
  }
@@ -5206,25 +5168,6 @@ var OpenAIResponsesLanguageModel = class {
5206
5168
  });
5207
5169
  } else if (value.item.type === "mcp_list_tools") {
5208
5170
  ongoingToolCalls[value.output_index] = void 0;
5209
- controller.enqueue({
5210
- type: "tool-result",
5211
- toolCallId: value.item.id,
5212
- toolName: toolNameMapping.toCustomToolName("mcp"),
5213
- result: {
5214
- type: "listTools",
5215
- serverLabel: value.item.server_label,
5216
- tools: value.item.tools.map((t) => {
5217
- var _a2, _b2;
5218
- return {
5219
- name: t.name,
5220
- description: (_a2 = t.description) != null ? _a2 : void 0,
5221
- inputSchema: t.input_schema,
5222
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
5223
- };
5224
- }),
5225
- ...value.item.error != null ? { error: value.item.error } : {}
5226
- }
5227
- });
5228
5171
  } else if (value.item.type === "apply_patch_call") {
5229
5172
  ongoingToolCalls[value.output_index] = void 0;
5230
5173
  if (value.item.status === "completed") {
@@ -5245,18 +5188,6 @@ var OpenAIResponsesLanguageModel = class {
5245
5188
  }
5246
5189
  } else if (value.item.type === "mcp_approval_request") {
5247
5190
  ongoingToolCalls[value.output_index] = void 0;
5248
- controller.enqueue({
5249
- type: "tool-result",
5250
- toolCallId: value.item.id,
5251
- toolName: toolNameMapping.toCustomToolName("mcp"),
5252
- result: {
5253
- type: "approvalRequest",
5254
- serverLabel: value.item.server_label,
5255
- name: value.item.name,
5256
- arguments: value.item.arguments,
5257
- approvalRequestId: value.item.approval_request_id
5258
- }
5259
- });
5260
5191
  } else if (value.item.type === "local_shell_call") {
5261
5192
  ongoingToolCalls[value.output_index] = void 0;
5262
5193
  controller.enqueue({
@@ -5437,10 +5368,13 @@ var OpenAIResponsesLanguageModel = class {
5437
5368
  activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
5438
5369
  }
5439
5370
  } else if (isResponseFinishedChunk(value)) {
5440
- finishReason = mapOpenAIResponseFinishReason({
5441
- finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
5442
- hasFunctionCall
5443
- });
5371
+ finishReason = {
5372
+ unified: mapOpenAIResponseFinishReason({
5373
+ finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
5374
+ hasFunctionCall
5375
+ }),
5376
+ raw: (_k = (_j = value.response.incomplete_details) == null ? void 0 : _j.reason) != null ? _k : void 0
5377
+ };
5444
5378
  usage = value.response.usage;
5445
5379
  if (typeof value.response.service_tier === "string") {
5446
5380
  serviceTier = value.response.service_tier;
@@ -5451,7 +5385,7 @@ var OpenAIResponsesLanguageModel = class {
5451
5385
  controller.enqueue({
5452
5386
  type: "source",
5453
5387
  sourceType: "url",
5454
- id: (_l = (_k = (_j = self.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId2(),
5388
+ id: (_n = (_m = (_l = self.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
5455
5389
  url: value.annotation.url,
5456
5390
  title: value.annotation.title
5457
5391
  });
@@ -5459,10 +5393,10 @@ var OpenAIResponsesLanguageModel = class {
5459
5393
  controller.enqueue({
5460
5394
  type: "source",
5461
5395
  sourceType: "document",
5462
- id: (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2(),
5396
+ id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
5463
5397
  mediaType: "text/plain",
5464
- title: (_q = (_p = value.annotation.quote) != null ? _p : value.annotation.filename) != null ? _q : "Document",
5465
- filename: (_r = value.annotation.filename) != null ? _r : value.annotation.file_id,
5398
+ title: (_s = (_r = value.annotation.quote) != null ? _r : value.annotation.filename) != null ? _s : "Document",
5399
+ filename: (_t = value.annotation.filename) != null ? _t : value.annotation.file_id,
5466
5400
  ...value.annotation.file_id ? {
5467
5401
  providerMetadata: {
5468
5402
  [providerKey]: {
@@ -5475,10 +5409,10 @@ var OpenAIResponsesLanguageModel = class {
5475
5409
  controller.enqueue({
5476
5410
  type: "source",
5477
5411
  sourceType: "document",
5478
- id: (_u = (_t = (_s = self.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : generateId2(),
5412
+ id: (_w = (_v = (_u = self.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2(),
5479
5413
  mediaType: "text/plain",
5480
- title: (_w = (_v = value.annotation.filename) != null ? _v : value.annotation.file_id) != null ? _w : "Document",
5481
- filename: (_x = value.annotation.filename) != null ? _x : value.annotation.file_id,
5414
+ title: (_y = (_x = value.annotation.filename) != null ? _x : value.annotation.file_id) != null ? _y : "Document",
5415
+ filename: (_z = value.annotation.filename) != null ? _z : value.annotation.file_id,
5482
5416
  providerMetadata: {
5483
5417
  [providerKey]: {
5484
5418
  fileId: value.annotation.file_id,
@@ -5491,7 +5425,7 @@ var OpenAIResponsesLanguageModel = class {
5491
5425
  controller.enqueue({
5492
5426
  type: "source",
5493
5427
  sourceType: "document",
5494
- id: (_A = (_z = (_y = self.config).generateId) == null ? void 0 : _z.call(_y)) != null ? _A : generateId2(),
5428
+ id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : generateId2(),
5495
5429
  mediaType: "application/octet-stream",
5496
5430
  title: value.annotation.file_id,
5497
5431
  filename: value.annotation.file_id,