@ai-sdk/openai-compatible 2.0.0-beta.57 → 2.0.0-beta.59

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
@@ -163,6 +163,9 @@ function convertToOpenAICompatibleChatMessages(prompt) {
163
163
  }
164
164
  case "tool": {
165
165
  for (const toolResponse of content) {
166
+ if (toolResponse.type === "tool-approval-response") {
167
+ continue;
168
+ }
166
169
  const output = toolResponse.output;
167
170
  let contentValue;
168
171
  switch (output.type) {
@@ -224,7 +227,7 @@ function mapOpenAICompatibleFinishReason(finishReason) {
224
227
  case "tool_calls":
225
228
  return "tool-calls";
226
229
  default:
227
- return "unknown";
230
+ return "other";
228
231
  }
229
232
  }
230
233
 
@@ -418,7 +421,7 @@ var OpenAICompatibleChatLanguageModel = class {
418
421
  };
419
422
  }
420
423
  async doGenerate(options) {
421
- var _a, _b, _c, _d, _e;
424
+ var _a, _b, _c, _d, _e, _f;
422
425
  const { args, warnings } = await this.getArgs({ ...options });
423
426
  const body = JSON.stringify(args);
424
427
  const {
@@ -477,7 +480,10 @@ var OpenAICompatibleChatLanguageModel = class {
477
480
  }
478
481
  return {
479
482
  content,
480
- finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason),
483
+ finishReason: {
484
+ unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
485
+ raw: (_f = choice.finish_reason) != null ? _f : void 0
486
+ },
481
487
  usage: convertOpenAICompatibleChatUsage(responseBody.usage),
482
488
  providerMetadata,
483
489
  request: { body },
@@ -514,7 +520,10 @@ var OpenAICompatibleChatLanguageModel = class {
514
520
  fetch: this.config.fetch
515
521
  });
516
522
  const toolCalls = [];
517
- let finishReason = "unknown";
523
+ let finishReason = {
524
+ unified: "other",
525
+ raw: void 0
526
+ };
518
527
  let usage = void 0;
519
528
  let isFirstChunk = true;
520
529
  const providerOptionsName = this.providerOptionsName;
@@ -527,18 +536,18 @@ var OpenAICompatibleChatLanguageModel = class {
527
536
  controller.enqueue({ type: "stream-start", warnings });
528
537
  },
529
538
  transform(chunk, controller) {
530
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
539
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
531
540
  if (options.includeRawChunks) {
532
541
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
533
542
  }
534
543
  if (!chunk.success) {
535
- finishReason = "error";
544
+ finishReason = { unified: "error", raw: void 0 };
536
545
  controller.enqueue({ type: "error", error: chunk.error });
537
546
  return;
538
547
  }
539
548
  metadataExtractor == null ? void 0 : metadataExtractor.processChunk(chunk.rawValue);
540
549
  if ("error" in chunk.value) {
541
- finishReason = "error";
550
+ finishReason = { unified: "error", raw: void 0 };
542
551
  controller.enqueue({
543
552
  type: "error",
544
553
  error: chunk.value.error.message
@@ -558,15 +567,16 @@ var OpenAICompatibleChatLanguageModel = class {
558
567
  }
559
568
  const choice = value.choices[0];
560
569
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
561
- finishReason = mapOpenAICompatibleFinishReason(
562
- choice.finish_reason
563
- );
570
+ finishReason = {
571
+ unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
572
+ raw: (_a2 = choice.finish_reason) != null ? _a2 : void 0
573
+ };
564
574
  }
565
575
  if ((choice == null ? void 0 : choice.delta) == null) {
566
576
  return;
567
577
  }
568
578
  const delta = choice.delta;
569
- const reasoningContent = (_a2 = delta.reasoning_content) != null ? _a2 : delta.reasoning;
579
+ const reasoningContent = (_b = delta.reasoning_content) != null ? _b : delta.reasoning;
570
580
  if (reasoningContent) {
571
581
  if (!isActiveReasoning) {
572
582
  controller.enqueue({
@@ -602,7 +612,7 @@ var OpenAICompatibleChatLanguageModel = class {
602
612
  message: `Expected 'id' to be a string.`
603
613
  });
604
614
  }
605
- if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
615
+ if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) {
606
616
  throw new InvalidResponseDataError({
607
617
  data: toolCallDelta,
608
618
  message: `Expected 'function.name' to be a string.`
@@ -618,12 +628,12 @@ var OpenAICompatibleChatLanguageModel = class {
618
628
  type: "function",
619
629
  function: {
620
630
  name: toolCallDelta.function.name,
621
- arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
631
+ arguments: (_d = toolCallDelta.function.arguments) != null ? _d : ""
622
632
  },
623
633
  hasFinished: false
624
634
  };
625
635
  const toolCall2 = toolCalls[index];
626
- if (((_d = toolCall2.function) == null ? void 0 : _d.name) != null && ((_e = toolCall2.function) == null ? void 0 : _e.arguments) != null) {
636
+ if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null) {
627
637
  if (toolCall2.function.arguments.length > 0) {
628
638
  controller.enqueue({
629
639
  type: "tool-input-delta",
@@ -638,7 +648,7 @@ var OpenAICompatibleChatLanguageModel = class {
638
648
  });
639
649
  controller.enqueue({
640
650
  type: "tool-call",
641
- toolCallId: (_f = toolCall2.id) != null ? _f : generateId(),
651
+ toolCallId: (_g = toolCall2.id) != null ? _g : generateId(),
642
652
  toolName: toolCall2.function.name,
643
653
  input: toolCall2.function.arguments
644
654
  });
@@ -651,22 +661,22 @@ var OpenAICompatibleChatLanguageModel = class {
651
661
  if (toolCall.hasFinished) {
652
662
  continue;
653
663
  }
654
- if (((_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null) {
655
- toolCall.function.arguments += (_i = (_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null ? _i : "";
664
+ if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) {
665
+ toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : "";
656
666
  }
657
667
  controller.enqueue({
658
668
  type: "tool-input-delta",
659
669
  id: toolCall.id,
660
- delta: (_j = toolCallDelta.function.arguments) != null ? _j : ""
670
+ delta: (_k = toolCallDelta.function.arguments) != null ? _k : ""
661
671
  });
662
- if (((_k = toolCall.function) == null ? void 0 : _k.name) != null && ((_l = toolCall.function) == null ? void 0 : _l.arguments) != null && isParsableJson(toolCall.function.arguments)) {
672
+ if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && isParsableJson(toolCall.function.arguments)) {
663
673
  controller.enqueue({
664
674
  type: "tool-input-end",
665
675
  id: toolCall.id
666
676
  });
667
677
  controller.enqueue({
668
678
  type: "tool-call",
669
- toolCallId: (_m = toolCall.id) != null ? _m : generateId(),
679
+ toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
670
680
  toolName: toolCall.function.name,
671
681
  input: toolCall.function.arguments
672
682
  });
@@ -943,7 +953,7 @@ function mapOpenAICompatibleFinishReason2(finishReason) {
943
953
  case "tool_calls":
944
954
  return "tool-calls";
945
955
  default:
946
- return "unknown";
956
+ return "other";
947
957
  }
948
958
  }
949
959
 
@@ -1089,7 +1099,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
1089
1099
  return {
1090
1100
  content,
1091
1101
  usage: convertOpenAICompatibleCompletionUsage(response.usage),
1092
- finishReason: mapOpenAICompatibleFinishReason2(choice.finish_reason),
1102
+ finishReason: {
1103
+ unified: mapOpenAICompatibleFinishReason2(choice.finish_reason),
1104
+ raw: choice.finish_reason
1105
+ },
1093
1106
  request: { body: args },
1094
1107
  response: {
1095
1108
  ...getResponseMetadata2(response),
@@ -1121,7 +1134,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
1121
1134
  abortSignal: options.abortSignal,
1122
1135
  fetch: this.config.fetch
1123
1136
  });
1124
- let finishReason = "unknown";
1137
+ let finishReason = {
1138
+ unified: "other",
1139
+ raw: void 0
1140
+ };
1125
1141
  let usage = void 0;
1126
1142
  let isFirstChunk = true;
1127
1143
  return {
@@ -1131,17 +1147,18 @@ var OpenAICompatibleCompletionLanguageModel = class {
1131
1147
  controller.enqueue({ type: "stream-start", warnings });
1132
1148
  },
1133
1149
  transform(chunk, controller) {
1150
+ var _a;
1134
1151
  if (options.includeRawChunks) {
1135
1152
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1136
1153
  }
1137
1154
  if (!chunk.success) {
1138
- finishReason = "error";
1155
+ finishReason = { unified: "error", raw: void 0 };
1139
1156
  controller.enqueue({ type: "error", error: chunk.error });
1140
1157
  return;
1141
1158
  }
1142
1159
  const value = chunk.value;
1143
1160
  if ("error" in value) {
1144
- finishReason = "error";
1161
+ finishReason = { unified: "error", raw: void 0 };
1145
1162
  controller.enqueue({ type: "error", error: value.error });
1146
1163
  return;
1147
1164
  }
@@ -1161,9 +1178,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
1161
1178
  }
1162
1179
  const choice = value.choices[0];
1163
1180
  if ((choice == null ? void 0 : choice.finish_reason) != null) {
1164
- finishReason = mapOpenAICompatibleFinishReason2(
1165
- choice.finish_reason
1166
- );
1181
+ finishReason = {
1182
+ unified: mapOpenAICompatibleFinishReason2(choice.finish_reason),
1183
+ raw: (_a = choice.finish_reason) != null ? _a : void 0
1184
+ };
1167
1185
  }
1168
1186
  if ((choice == null ? void 0 : choice.text) != null) {
1169
1187
  controller.enqueue({
@@ -1475,7 +1493,7 @@ import {
1475
1493
  } from "@ai-sdk/provider-utils";
1476
1494
 
1477
1495
  // src/version.ts
1478
- var VERSION = true ? "2.0.0-beta.57" : "0.0.0-test";
1496
+ var VERSION = true ? "2.0.0-beta.59" : "0.0.0-test";
1479
1497
 
1480
1498
  // src/openai-compatible-provider.ts
1481
1499
  function createOpenAICompatible(options) {