@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.
@@ -283,6 +283,9 @@ function convertToOpenAIChatMessages({
283
283
  }
284
284
  case "tool": {
285
285
  for (const toolResponse of content) {
286
+ if (toolResponse.type === "tool-approval-response") {
287
+ continue;
288
+ }
286
289
  const output = toolResponse.output;
287
290
  let contentValue;
288
291
  switch (output.type) {
@@ -342,7 +345,7 @@ function mapOpenAIFinishReason(finishReason) {
342
345
  case "tool_calls":
343
346
  return "tool-calls";
344
347
  default:
345
- return "unknown";
348
+ return "other";
346
349
  }
347
350
  }
348
351
 
@@ -864,7 +867,7 @@ var OpenAIChatLanguageModel = class {
864
867
  };
865
868
  }
866
869
  async doGenerate(options) {
867
- var _a, _b, _c, _d, _e, _f;
870
+ var _a, _b, _c, _d, _e, _f, _g;
868
871
  const { args: body, warnings } = await this.getArgs(options);
869
872
  const {
870
873
  responseHeaders,
@@ -921,7 +924,10 @@ var OpenAIChatLanguageModel = class {
921
924
  }
922
925
  return {
923
926
  content,
924
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
927
+ finishReason: {
928
+ unified: mapOpenAIFinishReason(choice.finish_reason),
929
+ raw: (_g = choice.finish_reason) != null ? _g : void 0
930
+ },
925
931
  usage: convertOpenAIChatUsage(response.usage),
926
932
  request: { body },
927
933
  response: {
@@ -957,7 +963,10 @@ var OpenAIChatLanguageModel = class {
957
963
  fetch: this.config.fetch
958
964
  });
959
965
  const toolCalls = [];
960
- let finishReason = "unknown";
966
+ let finishReason = {
967
+ unified: "other",
968
+ raw: void 0
969
+ };
961
970
  let usage = void 0;
962
971
  let metadataExtracted = false;
963
972
  let isActiveText = false;
@@ -974,13 +983,13 @@ var OpenAIChatLanguageModel = class {
974
983
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
975
984
  }
976
985
  if (!chunk.success) {
977
- finishReason = "error";
986
+ finishReason = { unified: "error", raw: void 0 };
978
987
  controller.enqueue({ type: "error", error: chunk.error });
979
988
  return;
980
989
  }
981
990
  const value = chunk.value;
982
991
  if ("error" in value) {
983
- finishReason = "error";
992
+ finishReason = { unified: "error", raw: void 0 };
984
993
  controller.enqueue({ type: "error", error: value.error });
985
994
  return;
986
995
  }
@@ -1005,7 +1014,10 @@ var OpenAIChatLanguageModel = class {
1005
1014
  }
1006
1015
  const choice = value.choices[0];
1007
1016
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1008
- finishReason = mapOpenAIFinishReason(choice.finish_reason);
1017
+ finishReason = {
1018
+ unified: mapOpenAIFinishReason(choice.finish_reason),
1019
+ raw: choice.finish_reason
1020
+ };
1009
1021
  }
1010
1022
  if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) {
1011
1023
  providerMetadata.openai.logprobs = choice.logprobs.content;
@@ -1285,7 +1297,7 @@ function mapOpenAIFinishReason2(finishReason) {
1285
1297
  case "tool_calls":
1286
1298
  return "tool-calls";
1287
1299
  default:
1288
- return "unknown";
1300
+ return "other";
1289
1301
  }
1290
1302
  }
1291
1303
 
@@ -1483,6 +1495,7 @@ var OpenAICompletionLanguageModel = class {
1483
1495
  };
1484
1496
  }
1485
1497
  async doGenerate(options) {
1498
+ var _a;
1486
1499
  const { args, warnings } = await this.getArgs(options);
1487
1500
  const {
1488
1501
  responseHeaders,
@@ -1510,7 +1523,10 @@ var OpenAICompletionLanguageModel = class {
1510
1523
  return {
1511
1524
  content: [{ type: "text", text: choice.text }],
1512
1525
  usage: convertOpenAICompletionUsage(response.usage),
1513
- finishReason: mapOpenAIFinishReason2(choice.finish_reason),
1526
+ finishReason: {
1527
+ unified: mapOpenAIFinishReason2(choice.finish_reason),
1528
+ raw: (_a = choice.finish_reason) != null ? _a : void 0
1529
+ },
1514
1530
  request: { body: args },
1515
1531
  response: {
1516
1532
  ...getResponseMetadata2(response),
@@ -1544,7 +1560,10 @@ var OpenAICompletionLanguageModel = class {
1544
1560
  abortSignal: options.abortSignal,
1545
1561
  fetch: this.config.fetch
1546
1562
  });
1547
- let finishReason = "unknown";
1563
+ let finishReason = {
1564
+ unified: "other",
1565
+ raw: void 0
1566
+ };
1548
1567
  const providerMetadata = { openai: {} };
1549
1568
  let usage = void 0;
1550
1569
  let isFirstChunk = true;
@@ -1559,13 +1578,13 @@ var OpenAICompletionLanguageModel = class {
1559
1578
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1560
1579
  }
1561
1580
  if (!chunk.success) {
1562
- finishReason = "error";
1581
+ finishReason = { unified: "error", raw: void 0 };
1563
1582
  controller.enqueue({ type: "error", error: chunk.error });
1564
1583
  return;
1565
1584
  }
1566
1585
  const value = chunk.value;
1567
1586
  if ("error" in value) {
1568
- finishReason = "error";
1587
+ finishReason = { unified: "error", raw: void 0 };
1569
1588
  controller.enqueue({ type: "error", error: value.error });
1570
1589
  return;
1571
1590
  }
@@ -1582,7 +1601,10 @@ var OpenAICompletionLanguageModel = class {
1582
1601
  }
1583
1602
  const choice = value.choices[0];
1584
1603
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1585
- finishReason = mapOpenAIFinishReason2(choice.finish_reason);
1604
+ finishReason = {
1605
+ unified: mapOpenAIFinishReason2(choice.finish_reason),
1606
+ raw: choice.finish_reason
1607
+ };
1586
1608
  }
1587
1609
  if ((choice == null ? void 0 : choice.logprobs) != null) {
1588
1610
  providerMetadata.openai.logprobs = choice.logprobs;
@@ -2670,6 +2692,9 @@ async function convertToOpenAIResponsesInput({
2670
2692
  }
2671
2693
  case "tool": {
2672
2694
  for (const part of content) {
2695
+ if (part.type === "tool-approval-response") {
2696
+ continue;
2697
+ }
2673
2698
  const output = part.output;
2674
2699
  const resolvedToolName = toolNameMapping.toProviderToolName(
2675
2700
  part.toolName
@@ -2797,7 +2822,7 @@ function mapOpenAIResponseFinishReason({
2797
2822
  case "content_filter":
2798
2823
  return "content-filter";
2799
2824
  default:
2800
- return hasFunctionCall ? "tool-calls" : "unknown";
2825
+ return hasFunctionCall ? "tool-calls" : "other";
2801
2826
  }
2802
2827
  }
2803
2828
 
@@ -3859,16 +3884,14 @@ var mcpArgsSchema = (0, import_provider_utils28.lazySchema)(
3859
3884
  authorization: import_v421.z.string().optional(),
3860
3885
  connectorId: import_v421.z.string().optional(),
3861
3886
  headers: import_v421.z.record(import_v421.z.string(), import_v421.z.string()).optional(),
3862
- // TODO: Integrate this MCP tool approval with our SDK's existing tool approval architecture
3863
- // requireApproval: z
3864
- // .union([
3865
- // z.enum(['always', 'never']),
3866
- // z.object({
3867
- // readOnly: z.boolean().optional(),
3868
- // toolNames: z.array(z.string()).optional(),
3869
- // }),
3870
- // ])
3871
- // .optional(),
3887
+ requireApproval: import_v421.z.union([
3888
+ import_v421.z.enum(["always", "never"]),
3889
+ import_v421.z.object({
3890
+ never: import_v421.z.object({
3891
+ toolNames: import_v421.z.array(import_v421.z.string()).optional()
3892
+ }).optional()
3893
+ })
3894
+ ]).optional(),
3872
3895
  serverDescription: import_v421.z.string().optional(),
3873
3896
  serverUrl: import_v421.z.string().optional()
3874
3897
  }).refine(
@@ -3880,36 +3903,14 @@ var mcpArgsSchema = (0, import_provider_utils28.lazySchema)(
3880
3903
  var mcpInputSchema = (0, import_provider_utils28.lazySchema)(() => (0, import_provider_utils28.zodSchema)(import_v421.z.object({})));
3881
3904
  var mcpOutputSchema = (0, import_provider_utils28.lazySchema)(
3882
3905
  () => (0, import_provider_utils28.zodSchema)(
3883
- import_v421.z.discriminatedUnion("type", [
3884
- import_v421.z.object({
3885
- type: import_v421.z.literal("call"),
3886
- serverLabel: import_v421.z.string(),
3887
- name: import_v421.z.string(),
3888
- arguments: import_v421.z.string(),
3889
- output: import_v421.z.string().nullable().optional(),
3890
- error: import_v421.z.union([import_v421.z.string(), jsonValueSchema]).optional()
3891
- }),
3892
- import_v421.z.object({
3893
- type: import_v421.z.literal("listTools"),
3894
- serverLabel: import_v421.z.string(),
3895
- tools: import_v421.z.array(
3896
- import_v421.z.object({
3897
- name: import_v421.z.string(),
3898
- description: import_v421.z.string().optional(),
3899
- inputSchema: jsonValueSchema,
3900
- annotations: import_v421.z.record(import_v421.z.string(), jsonValueSchema).optional()
3901
- })
3902
- ),
3903
- error: import_v421.z.union([import_v421.z.string(), jsonValueSchema]).optional()
3904
- }),
3905
- import_v421.z.object({
3906
- type: import_v421.z.literal("approvalRequest"),
3907
- serverLabel: import_v421.z.string(),
3908
- name: import_v421.z.string(),
3909
- arguments: import_v421.z.string(),
3910
- approvalRequestId: import_v421.z.string()
3911
- })
3912
- ])
3906
+ import_v421.z.object({
3907
+ type: import_v421.z.literal("call"),
3908
+ serverLabel: import_v421.z.string(),
3909
+ name: import_v421.z.string(),
3910
+ arguments: import_v421.z.string(),
3911
+ output: import_v421.z.string().nullable().optional(),
3912
+ error: import_v421.z.union([import_v421.z.string(), jsonValueSchema]).optional()
3913
+ })
3913
3914
  )
3914
3915
  );
3915
3916
  var mcpToolFactory = (0, import_provider_utils28.createProviderToolFactoryWithOutputSchema)({
@@ -4429,7 +4430,7 @@ var OpenAIResponsesLanguageModel = class {
4429
4430
  };
4430
4431
  }
4431
4432
  async doGenerate(options) {
4432
- 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;
4433
+ 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;
4433
4434
  const {
4434
4435
  args: body,
4435
4436
  warnings,
@@ -4680,54 +4681,9 @@ var OpenAIResponsesLanguageModel = class {
4680
4681
  break;
4681
4682
  }
4682
4683
  case "mcp_list_tools": {
4683
- content.push({
4684
- type: "tool-call",
4685
- toolCallId: part.id,
4686
- toolName: toolNameMapping.toCustomToolName("mcp"),
4687
- input: JSON.stringify({}),
4688
- providerExecuted: true
4689
- });
4690
- content.push({
4691
- type: "tool-result",
4692
- toolCallId: part.id,
4693
- toolName: toolNameMapping.toCustomToolName("mcp"),
4694
- result: {
4695
- type: "listTools",
4696
- serverLabel: part.server_label,
4697
- tools: part.tools.map((t) => {
4698
- var _a2, _b2;
4699
- return {
4700
- name: t.name,
4701
- description: (_a2 = t.description) != null ? _a2 : void 0,
4702
- inputSchema: t.input_schema,
4703
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4704
- };
4705
- }),
4706
- ...part.error != null ? { error: part.error } : {}
4707
- }
4708
- });
4709
4684
  break;
4710
4685
  }
4711
4686
  case "mcp_approval_request": {
4712
- content.push({
4713
- type: "tool-call",
4714
- toolCallId: part.id,
4715
- toolName: toolNameMapping.toCustomToolName("mcp"),
4716
- input: JSON.stringify({}),
4717
- providerExecuted: true
4718
- });
4719
- content.push({
4720
- type: "tool-result",
4721
- toolCallId: part.id,
4722
- toolName: toolNameMapping.toCustomToolName("mcp"),
4723
- result: {
4724
- type: "approvalRequest",
4725
- serverLabel: part.server_label,
4726
- name: part.name,
4727
- arguments: part.arguments,
4728
- approvalRequestId: part.approval_request_id
4729
- }
4730
- });
4731
4687
  break;
4732
4688
  }
4733
4689
  case "computer_call": {
@@ -4826,10 +4782,13 @@ var OpenAIResponsesLanguageModel = class {
4826
4782
  const usage = response.usage;
4827
4783
  return {
4828
4784
  content,
4829
- finishReason: mapOpenAIResponseFinishReason({
4830
- finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
4831
- hasFunctionCall
4832
- }),
4785
+ finishReason: {
4786
+ unified: mapOpenAIResponseFinishReason({
4787
+ finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
4788
+ hasFunctionCall
4789
+ }),
4790
+ raw: (_z = (_y = response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
4791
+ },
4833
4792
  usage: convertOpenAIResponsesUsage(usage),
4834
4793
  request: { body },
4835
4794
  response: {
@@ -4870,7 +4829,10 @@ var OpenAIResponsesLanguageModel = class {
4870
4829
  });
4871
4830
  const self = this;
4872
4831
  const providerKey = this.config.provider.replace(".responses", "");
4873
- let finishReason = "unknown";
4832
+ let finishReason = {
4833
+ unified: "other",
4834
+ raw: void 0
4835
+ };
4874
4836
  let usage = void 0;
4875
4837
  const logprobs = [];
4876
4838
  let responseId = null;
@@ -4886,12 +4848,12 @@ var OpenAIResponsesLanguageModel = class {
4886
4848
  controller.enqueue({ type: "stream-start", warnings });
4887
4849
  },
4888
4850
  transform(chunk, controller) {
4889
- 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;
4851
+ 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;
4890
4852
  if (options.includeRawChunks) {
4891
4853
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
4892
4854
  }
4893
4855
  if (!chunk.success) {
4894
- finishReason = "error";
4856
+ finishReason = { unified: "error", raw: void 0 };
4895
4857
  controller.enqueue({ type: "error", error: chunk.error });
4896
4858
  return;
4897
4859
  }
@@ -5159,25 +5121,6 @@ var OpenAIResponsesLanguageModel = class {
5159
5121
  });
5160
5122
  } else if (value.item.type === "mcp_list_tools") {
5161
5123
  ongoingToolCalls[value.output_index] = void 0;
5162
- controller.enqueue({
5163
- type: "tool-result",
5164
- toolCallId: value.item.id,
5165
- toolName: toolNameMapping.toCustomToolName("mcp"),
5166
- result: {
5167
- type: "listTools",
5168
- serverLabel: value.item.server_label,
5169
- tools: value.item.tools.map((t) => {
5170
- var _a2, _b2;
5171
- return {
5172
- name: t.name,
5173
- description: (_a2 = t.description) != null ? _a2 : void 0,
5174
- inputSchema: t.input_schema,
5175
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
5176
- };
5177
- }),
5178
- ...value.item.error != null ? { error: value.item.error } : {}
5179
- }
5180
- });
5181
5124
  } else if (value.item.type === "apply_patch_call") {
5182
5125
  ongoingToolCalls[value.output_index] = void 0;
5183
5126
  if (value.item.status === "completed") {
@@ -5198,18 +5141,6 @@ var OpenAIResponsesLanguageModel = class {
5198
5141
  }
5199
5142
  } else if (value.item.type === "mcp_approval_request") {
5200
5143
  ongoingToolCalls[value.output_index] = void 0;
5201
- controller.enqueue({
5202
- type: "tool-result",
5203
- toolCallId: value.item.id,
5204
- toolName: toolNameMapping.toCustomToolName("mcp"),
5205
- result: {
5206
- type: "approvalRequest",
5207
- serverLabel: value.item.server_label,
5208
- name: value.item.name,
5209
- arguments: value.item.arguments,
5210
- approvalRequestId: value.item.approval_request_id
5211
- }
5212
- });
5213
5144
  } else if (value.item.type === "local_shell_call") {
5214
5145
  ongoingToolCalls[value.output_index] = void 0;
5215
5146
  controller.enqueue({
@@ -5390,10 +5321,13 @@ var OpenAIResponsesLanguageModel = class {
5390
5321
  activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
5391
5322
  }
5392
5323
  } else if (isResponseFinishedChunk(value)) {
5393
- finishReason = mapOpenAIResponseFinishReason({
5394
- finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
5395
- hasFunctionCall
5396
- });
5324
+ finishReason = {
5325
+ unified: mapOpenAIResponseFinishReason({
5326
+ finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
5327
+ hasFunctionCall
5328
+ }),
5329
+ raw: (_k = (_j = value.response.incomplete_details) == null ? void 0 : _j.reason) != null ? _k : void 0
5330
+ };
5397
5331
  usage = value.response.usage;
5398
5332
  if (typeof value.response.service_tier === "string") {
5399
5333
  serviceTier = value.response.service_tier;
@@ -5404,7 +5338,7 @@ var OpenAIResponsesLanguageModel = class {
5404
5338
  controller.enqueue({
5405
5339
  type: "source",
5406
5340
  sourceType: "url",
5407
- id: (_l = (_k = (_j = self.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : (0, import_provider_utils32.generateId)(),
5341
+ id: (_n = (_m = (_l = self.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : (0, import_provider_utils32.generateId)(),
5408
5342
  url: value.annotation.url,
5409
5343
  title: value.annotation.title
5410
5344
  });
@@ -5412,10 +5346,10 @@ var OpenAIResponsesLanguageModel = class {
5412
5346
  controller.enqueue({
5413
5347
  type: "source",
5414
5348
  sourceType: "document",
5415
- id: (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0, import_provider_utils32.generateId)(),
5349
+ id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : (0, import_provider_utils32.generateId)(),
5416
5350
  mediaType: "text/plain",
5417
- title: (_q = (_p = value.annotation.quote) != null ? _p : value.annotation.filename) != null ? _q : "Document",
5418
- filename: (_r = value.annotation.filename) != null ? _r : value.annotation.file_id,
5351
+ title: (_s = (_r = value.annotation.quote) != null ? _r : value.annotation.filename) != null ? _s : "Document",
5352
+ filename: (_t = value.annotation.filename) != null ? _t : value.annotation.file_id,
5419
5353
  ...value.annotation.file_id ? {
5420
5354
  providerMetadata: {
5421
5355
  [providerKey]: {
@@ -5428,10 +5362,10 @@ var OpenAIResponsesLanguageModel = class {
5428
5362
  controller.enqueue({
5429
5363
  type: "source",
5430
5364
  sourceType: "document",
5431
- id: (_u = (_t = (_s = self.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : (0, import_provider_utils32.generateId)(),
5365
+ id: (_w = (_v = (_u = self.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : (0, import_provider_utils32.generateId)(),
5432
5366
  mediaType: "text/plain",
5433
- title: (_w = (_v = value.annotation.filename) != null ? _v : value.annotation.file_id) != null ? _w : "Document",
5434
- filename: (_x = value.annotation.filename) != null ? _x : value.annotation.file_id,
5367
+ title: (_y = (_x = value.annotation.filename) != null ? _x : value.annotation.file_id) != null ? _y : "Document",
5368
+ filename: (_z = value.annotation.filename) != null ? _z : value.annotation.file_id,
5435
5369
  providerMetadata: {
5436
5370
  [providerKey]: {
5437
5371
  fileId: value.annotation.file_id,
@@ -5444,7 +5378,7 @@ var OpenAIResponsesLanguageModel = class {
5444
5378
  controller.enqueue({
5445
5379
  type: "source",
5446
5380
  sourceType: "document",
5447
- id: (_A = (_z = (_y = self.config).generateId) == null ? void 0 : _z.call(_y)) != null ? _A : (0, import_provider_utils32.generateId)(),
5381
+ id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : (0, import_provider_utils32.generateId)(),
5448
5382
  mediaType: "application/octet-stream",
5449
5383
  title: value.annotation.file_id,
5450
5384
  filename: value.annotation.file_id,