@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.
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) {
@@ -304,7 +307,7 @@ function mapOpenAIFinishReason(finishReason) {
304
307
  case "tool_calls":
305
308
  return "tool-calls";
306
309
  default:
307
- return "unknown";
310
+ return "other";
308
311
  }
309
312
  }
310
313
 
@@ -828,7 +831,7 @@ var OpenAIChatLanguageModel = class {
828
831
  };
829
832
  }
830
833
  async doGenerate(options) {
831
- var _a, _b, _c, _d, _e, _f;
834
+ var _a, _b, _c, _d, _e, _f, _g;
832
835
  const { args: body, warnings } = await this.getArgs(options);
833
836
  const {
834
837
  responseHeaders,
@@ -885,7 +888,10 @@ var OpenAIChatLanguageModel = class {
885
888
  }
886
889
  return {
887
890
  content,
888
- finishReason: mapOpenAIFinishReason(choice.finish_reason),
891
+ finishReason: {
892
+ unified: mapOpenAIFinishReason(choice.finish_reason),
893
+ raw: (_g = choice.finish_reason) != null ? _g : void 0
894
+ },
889
895
  usage: convertOpenAIChatUsage(response.usage),
890
896
  request: { body },
891
897
  response: {
@@ -921,7 +927,10 @@ var OpenAIChatLanguageModel = class {
921
927
  fetch: this.config.fetch
922
928
  });
923
929
  const toolCalls = [];
924
- let finishReason = "unknown";
930
+ let finishReason = {
931
+ unified: "other",
932
+ raw: void 0
933
+ };
925
934
  let usage = void 0;
926
935
  let metadataExtracted = false;
927
936
  let isActiveText = false;
@@ -938,13 +947,13 @@ var OpenAIChatLanguageModel = class {
938
947
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
939
948
  }
940
949
  if (!chunk.success) {
941
- finishReason = "error";
950
+ finishReason = { unified: "error", raw: void 0 };
942
951
  controller.enqueue({ type: "error", error: chunk.error });
943
952
  return;
944
953
  }
945
954
  const value = chunk.value;
946
955
  if ("error" in value) {
947
- finishReason = "error";
956
+ finishReason = { unified: "error", raw: void 0 };
948
957
  controller.enqueue({ type: "error", error: value.error });
949
958
  return;
950
959
  }
@@ -969,7 +978,10 @@ var OpenAIChatLanguageModel = class {
969
978
  }
970
979
  const choice = value.choices[0];
971
980
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
972
- finishReason = mapOpenAIFinishReason(choice.finish_reason);
981
+ finishReason = {
982
+ unified: mapOpenAIFinishReason(choice.finish_reason),
983
+ raw: choice.finish_reason
984
+ };
973
985
  }
974
986
  if (((_e = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _e.content) != null) {
975
987
  providerMetadata.openai.logprobs = choice.logprobs.content;
@@ -1258,7 +1270,7 @@ function mapOpenAIFinishReason2(finishReason) {
1258
1270
  case "tool_calls":
1259
1271
  return "tool-calls";
1260
1272
  default:
1261
- return "unknown";
1273
+ return "other";
1262
1274
  }
1263
1275
  }
1264
1276
 
@@ -1456,6 +1468,7 @@ var OpenAICompletionLanguageModel = class {
1456
1468
  };
1457
1469
  }
1458
1470
  async doGenerate(options) {
1471
+ var _a;
1459
1472
  const { args, warnings } = await this.getArgs(options);
1460
1473
  const {
1461
1474
  responseHeaders,
@@ -1483,7 +1496,10 @@ var OpenAICompletionLanguageModel = class {
1483
1496
  return {
1484
1497
  content: [{ type: "text", text: choice.text }],
1485
1498
  usage: convertOpenAICompletionUsage(response.usage),
1486
- finishReason: mapOpenAIFinishReason2(choice.finish_reason),
1499
+ finishReason: {
1500
+ unified: mapOpenAIFinishReason2(choice.finish_reason),
1501
+ raw: (_a = choice.finish_reason) != null ? _a : void 0
1502
+ },
1487
1503
  request: { body: args },
1488
1504
  response: {
1489
1505
  ...getResponseMetadata2(response),
@@ -1517,7 +1533,10 @@ var OpenAICompletionLanguageModel = class {
1517
1533
  abortSignal: options.abortSignal,
1518
1534
  fetch: this.config.fetch
1519
1535
  });
1520
- let finishReason = "unknown";
1536
+ let finishReason = {
1537
+ unified: "other",
1538
+ raw: void 0
1539
+ };
1521
1540
  const providerMetadata = { openai: {} };
1522
1541
  let usage = void 0;
1523
1542
  let isFirstChunk = true;
@@ -1532,13 +1551,13 @@ var OpenAICompletionLanguageModel = class {
1532
1551
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1533
1552
  }
1534
1553
  if (!chunk.success) {
1535
- finishReason = "error";
1554
+ finishReason = { unified: "error", raw: void 0 };
1536
1555
  controller.enqueue({ type: "error", error: chunk.error });
1537
1556
  return;
1538
1557
  }
1539
1558
  const value = chunk.value;
1540
1559
  if ("error" in value) {
1541
- finishReason = "error";
1560
+ finishReason = { unified: "error", raw: void 0 };
1542
1561
  controller.enqueue({ type: "error", error: value.error });
1543
1562
  return;
1544
1563
  }
@@ -1555,7 +1574,10 @@ var OpenAICompletionLanguageModel = class {
1555
1574
  }
1556
1575
  const choice = value.choices[0];
1557
1576
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1558
- finishReason = mapOpenAIFinishReason2(choice.finish_reason);
1577
+ finishReason = {
1578
+ unified: mapOpenAIFinishReason2(choice.finish_reason),
1579
+ raw: choice.finish_reason
1580
+ };
1559
1581
  }
1560
1582
  if ((choice == null ? void 0 : choice.logprobs) != null) {
1561
1583
  providerMetadata.openai.logprobs = choice.logprobs;
@@ -2312,16 +2334,14 @@ var mcpArgsSchema = lazySchema16(
2312
2334
  authorization: z17.string().optional(),
2313
2335
  connectorId: z17.string().optional(),
2314
2336
  headers: z17.record(z17.string(), z17.string()).optional(),
2315
- // TODO: Integrate this MCP tool approval with our SDK's existing tool approval architecture
2316
- // requireApproval: z
2317
- // .union([
2318
- // z.enum(['always', 'never']),
2319
- // z.object({
2320
- // readOnly: z.boolean().optional(),
2321
- // toolNames: z.array(z.string()).optional(),
2322
- // }),
2323
- // ])
2324
- // .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(),
2325
2345
  serverDescription: z17.string().optional(),
2326
2346
  serverUrl: z17.string().optional()
2327
2347
  }).refine(
@@ -2333,36 +2353,14 @@ var mcpArgsSchema = lazySchema16(
2333
2353
  var mcpInputSchema = lazySchema16(() => zodSchema16(z17.object({})));
2334
2354
  var mcpOutputSchema = lazySchema16(
2335
2355
  () => zodSchema16(
2336
- z17.discriminatedUnion("type", [
2337
- z17.object({
2338
- type: z17.literal("call"),
2339
- serverLabel: z17.string(),
2340
- name: z17.string(),
2341
- arguments: z17.string(),
2342
- output: z17.string().nullable().optional(),
2343
- error: z17.union([z17.string(), jsonValueSchema]).optional()
2344
- }),
2345
- z17.object({
2346
- type: z17.literal("listTools"),
2347
- serverLabel: z17.string(),
2348
- tools: z17.array(
2349
- z17.object({
2350
- name: z17.string(),
2351
- description: z17.string().optional(),
2352
- inputSchema: jsonValueSchema,
2353
- annotations: z17.record(z17.string(), jsonValueSchema).optional()
2354
- })
2355
- ),
2356
- error: z17.union([z17.string(), jsonValueSchema]).optional()
2357
- }),
2358
- z17.object({
2359
- type: z17.literal("approvalRequest"),
2360
- serverLabel: z17.string(),
2361
- name: z17.string(),
2362
- arguments: z17.string(),
2363
- approvalRequestId: z17.string()
2364
- })
2365
- ])
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
+ })
2366
2364
  )
2367
2365
  );
2368
2366
  var mcpToolFactory = createProviderToolFactoryWithOutputSchema9({
@@ -2771,6 +2769,9 @@ async function convertToOpenAIResponsesInput({
2771
2769
  }
2772
2770
  case "tool": {
2773
2771
  for (const part of content) {
2772
+ if (part.type === "tool-approval-response") {
2773
+ continue;
2774
+ }
2774
2775
  const output = part.output;
2775
2776
  const resolvedToolName = toolNameMapping.toProviderToolName(
2776
2777
  part.toolName
@@ -2898,7 +2899,7 @@ function mapOpenAIResponseFinishReason({
2898
2899
  case "content_filter":
2899
2900
  return "content-filter";
2900
2901
  default:
2901
- return hasFunctionCall ? "tool-calls" : "unknown";
2902
+ return hasFunctionCall ? "tool-calls" : "other";
2902
2903
  }
2903
2904
  }
2904
2905
 
@@ -4216,7 +4217,7 @@ var OpenAIResponsesLanguageModel = class {
4216
4217
  };
4217
4218
  }
4218
4219
  async doGenerate(options) {
4219
- 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;
4220
+ 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;
4220
4221
  const {
4221
4222
  args: body,
4222
4223
  warnings,
@@ -4467,54 +4468,9 @@ var OpenAIResponsesLanguageModel = class {
4467
4468
  break;
4468
4469
  }
4469
4470
  case "mcp_list_tools": {
4470
- content.push({
4471
- type: "tool-call",
4472
- toolCallId: part.id,
4473
- toolName: toolNameMapping.toCustomToolName("mcp"),
4474
- input: JSON.stringify({}),
4475
- providerExecuted: true
4476
- });
4477
- content.push({
4478
- type: "tool-result",
4479
- toolCallId: part.id,
4480
- toolName: toolNameMapping.toCustomToolName("mcp"),
4481
- result: {
4482
- type: "listTools",
4483
- serverLabel: part.server_label,
4484
- tools: part.tools.map((t) => {
4485
- var _a2, _b2;
4486
- return {
4487
- name: t.name,
4488
- description: (_a2 = t.description) != null ? _a2 : void 0,
4489
- inputSchema: t.input_schema,
4490
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4491
- };
4492
- }),
4493
- ...part.error != null ? { error: part.error } : {}
4494
- }
4495
- });
4496
4471
  break;
4497
4472
  }
4498
4473
  case "mcp_approval_request": {
4499
- content.push({
4500
- type: "tool-call",
4501
- toolCallId: part.id,
4502
- toolName: toolNameMapping.toCustomToolName("mcp"),
4503
- input: JSON.stringify({}),
4504
- providerExecuted: true
4505
- });
4506
- content.push({
4507
- type: "tool-result",
4508
- toolCallId: part.id,
4509
- toolName: toolNameMapping.toCustomToolName("mcp"),
4510
- result: {
4511
- type: "approvalRequest",
4512
- serverLabel: part.server_label,
4513
- name: part.name,
4514
- arguments: part.arguments,
4515
- approvalRequestId: part.approval_request_id
4516
- }
4517
- });
4518
4474
  break;
4519
4475
  }
4520
4476
  case "computer_call": {
@@ -4613,10 +4569,13 @@ var OpenAIResponsesLanguageModel = class {
4613
4569
  const usage = response.usage;
4614
4570
  return {
4615
4571
  content,
4616
- finishReason: mapOpenAIResponseFinishReason({
4617
- finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
4618
- hasFunctionCall
4619
- }),
4572
+ finishReason: {
4573
+ unified: mapOpenAIResponseFinishReason({
4574
+ finishReason: (_x = response.incomplete_details) == null ? void 0 : _x.reason,
4575
+ hasFunctionCall
4576
+ }),
4577
+ raw: (_z = (_y = response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
4578
+ },
4620
4579
  usage: convertOpenAIResponsesUsage(usage),
4621
4580
  request: { body },
4622
4581
  response: {
@@ -4657,7 +4616,10 @@ var OpenAIResponsesLanguageModel = class {
4657
4616
  });
4658
4617
  const self = this;
4659
4618
  const providerKey = this.config.provider.replace(".responses", "");
4660
- let finishReason = "unknown";
4619
+ let finishReason = {
4620
+ unified: "other",
4621
+ raw: void 0
4622
+ };
4661
4623
  let usage = void 0;
4662
4624
  const logprobs = [];
4663
4625
  let responseId = null;
@@ -4673,12 +4635,12 @@ var OpenAIResponsesLanguageModel = class {
4673
4635
  controller.enqueue({ type: "stream-start", warnings });
4674
4636
  },
4675
4637
  transform(chunk, controller) {
4676
- 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;
4638
+ 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;
4677
4639
  if (options.includeRawChunks) {
4678
4640
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
4679
4641
  }
4680
4642
  if (!chunk.success) {
4681
- finishReason = "error";
4643
+ finishReason = { unified: "error", raw: void 0 };
4682
4644
  controller.enqueue({ type: "error", error: chunk.error });
4683
4645
  return;
4684
4646
  }
@@ -4946,25 +4908,6 @@ var OpenAIResponsesLanguageModel = class {
4946
4908
  });
4947
4909
  } else if (value.item.type === "mcp_list_tools") {
4948
4910
  ongoingToolCalls[value.output_index] = void 0;
4949
- controller.enqueue({
4950
- type: "tool-result",
4951
- toolCallId: value.item.id,
4952
- toolName: toolNameMapping.toCustomToolName("mcp"),
4953
- result: {
4954
- type: "listTools",
4955
- serverLabel: value.item.server_label,
4956
- tools: value.item.tools.map((t) => {
4957
- var _a2, _b2;
4958
- return {
4959
- name: t.name,
4960
- description: (_a2 = t.description) != null ? _a2 : void 0,
4961
- inputSchema: t.input_schema,
4962
- annotations: (_b2 = t.annotations) != null ? _b2 : void 0
4963
- };
4964
- }),
4965
- ...value.item.error != null ? { error: value.item.error } : {}
4966
- }
4967
- });
4968
4911
  } else if (value.item.type === "apply_patch_call") {
4969
4912
  ongoingToolCalls[value.output_index] = void 0;
4970
4913
  if (value.item.status === "completed") {
@@ -4985,18 +4928,6 @@ var OpenAIResponsesLanguageModel = class {
4985
4928
  }
4986
4929
  } else if (value.item.type === "mcp_approval_request") {
4987
4930
  ongoingToolCalls[value.output_index] = void 0;
4988
- controller.enqueue({
4989
- type: "tool-result",
4990
- toolCallId: value.item.id,
4991
- toolName: toolNameMapping.toCustomToolName("mcp"),
4992
- result: {
4993
- type: "approvalRequest",
4994
- serverLabel: value.item.server_label,
4995
- name: value.item.name,
4996
- arguments: value.item.arguments,
4997
- approvalRequestId: value.item.approval_request_id
4998
- }
4999
- });
5000
4931
  } else if (value.item.type === "local_shell_call") {
5001
4932
  ongoingToolCalls[value.output_index] = void 0;
5002
4933
  controller.enqueue({
@@ -5177,10 +5108,13 @@ var OpenAIResponsesLanguageModel = class {
5177
5108
  activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
5178
5109
  }
5179
5110
  } else if (isResponseFinishedChunk(value)) {
5180
- finishReason = mapOpenAIResponseFinishReason({
5181
- finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
5182
- hasFunctionCall
5183
- });
5111
+ finishReason = {
5112
+ unified: mapOpenAIResponseFinishReason({
5113
+ finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
5114
+ hasFunctionCall
5115
+ }),
5116
+ raw: (_k = (_j = value.response.incomplete_details) == null ? void 0 : _j.reason) != null ? _k : void 0
5117
+ };
5184
5118
  usage = value.response.usage;
5185
5119
  if (typeof value.response.service_tier === "string") {
5186
5120
  serviceTier = value.response.service_tier;
@@ -5191,7 +5125,7 @@ var OpenAIResponsesLanguageModel = class {
5191
5125
  controller.enqueue({
5192
5126
  type: "source",
5193
5127
  sourceType: "url",
5194
- id: (_l = (_k = (_j = self.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : generateId2(),
5128
+ id: (_n = (_m = (_l = self.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
5195
5129
  url: value.annotation.url,
5196
5130
  title: value.annotation.title
5197
5131
  });
@@ -5199,10 +5133,10 @@ var OpenAIResponsesLanguageModel = class {
5199
5133
  controller.enqueue({
5200
5134
  type: "source",
5201
5135
  sourceType: "document",
5202
- id: (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : generateId2(),
5136
+ id: (_q = (_p = (_o = self.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
5203
5137
  mediaType: "text/plain",
5204
- title: (_q = (_p = value.annotation.quote) != null ? _p : value.annotation.filename) != null ? _q : "Document",
5205
- filename: (_r = value.annotation.filename) != null ? _r : value.annotation.file_id,
5138
+ title: (_s = (_r = value.annotation.quote) != null ? _r : value.annotation.filename) != null ? _s : "Document",
5139
+ filename: (_t = value.annotation.filename) != null ? _t : value.annotation.file_id,
5206
5140
  ...value.annotation.file_id ? {
5207
5141
  providerMetadata: {
5208
5142
  [providerKey]: {
@@ -5215,10 +5149,10 @@ var OpenAIResponsesLanguageModel = class {
5215
5149
  controller.enqueue({
5216
5150
  type: "source",
5217
5151
  sourceType: "document",
5218
- id: (_u = (_t = (_s = self.config).generateId) == null ? void 0 : _t.call(_s)) != null ? _u : generateId2(),
5152
+ id: (_w = (_v = (_u = self.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId2(),
5219
5153
  mediaType: "text/plain",
5220
- title: (_w = (_v = value.annotation.filename) != null ? _v : value.annotation.file_id) != null ? _w : "Document",
5221
- filename: (_x = value.annotation.filename) != null ? _x : value.annotation.file_id,
5154
+ title: (_y = (_x = value.annotation.filename) != null ? _x : value.annotation.file_id) != null ? _y : "Document",
5155
+ filename: (_z = value.annotation.filename) != null ? _z : value.annotation.file_id,
5222
5156
  providerMetadata: {
5223
5157
  [providerKey]: {
5224
5158
  fileId: value.annotation.file_id,
@@ -5231,7 +5165,7 @@ var OpenAIResponsesLanguageModel = class {
5231
5165
  controller.enqueue({
5232
5166
  type: "source",
5233
5167
  sourceType: "document",
5234
- id: (_A = (_z = (_y = self.config).generateId) == null ? void 0 : _z.call(_y)) != null ? _A : generateId2(),
5168
+ id: (_C = (_B = (_A = self.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : generateId2(),
5235
5169
  mediaType: "application/octet-stream",
5236
5170
  title: value.annotation.file_id,
5237
5171
  filename: value.annotation.file_id,
@@ -5693,7 +5627,7 @@ var OpenAITranscriptionModel = class {
5693
5627
  };
5694
5628
 
5695
5629
  // src/version.ts
5696
- var VERSION = true ? "3.0.0-beta.108" : "0.0.0-test";
5630
+ var VERSION = true ? "3.0.0-beta.110" : "0.0.0-test";
5697
5631
 
5698
5632
  // src/openai-provider.ts
5699
5633
  function createOpenAI(options = {}) {