@ai-sdk/openai-compatible 1.0.0-alpha.8 → 1.0.0-beta.1

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
@@ -86,7 +86,7 @@ function convertToOpenAICompatibleChatMessages(prompt) {
86
86
  type: "function",
87
87
  function: {
88
88
  name: part.toolName,
89
- arguments: JSON.stringify(part.args)
89
+ arguments: JSON.stringify(part.input)
90
90
  },
91
91
  ...partMetadata
92
92
  });
@@ -104,11 +104,24 @@ function convertToOpenAICompatibleChatMessages(prompt) {
104
104
  }
105
105
  case "tool": {
106
106
  for (const toolResponse of content) {
107
+ const output = toolResponse.output;
108
+ let contentValue;
109
+ switch (output.type) {
110
+ case "text":
111
+ case "error-text":
112
+ contentValue = output.value;
113
+ break;
114
+ case "content":
115
+ case "json":
116
+ case "error-json":
117
+ contentValue = JSON.stringify(output.value);
118
+ break;
119
+ }
107
120
  const toolResponseMetadata = getOpenAIMetadata(toolResponse);
108
121
  messages.push({
109
122
  role: "tool",
110
123
  tool_call_id: toolResponse.toolCallId,
111
- content: JSON.stringify(toolResponse.result),
124
+ content: contentValue,
112
125
  ...toolResponseMetadata
113
126
  });
114
127
  }
@@ -208,7 +221,7 @@ function prepareTools({
208
221
  function: {
209
222
  name: tool.name,
210
223
  description: tool.description,
211
- parameters: tool.parameters
224
+ parameters: tool.inputSchema
212
225
  }
213
226
  });
214
227
  }
@@ -384,10 +397,9 @@ var OpenAICompatibleChatLanguageModel = class {
384
397
  for (const toolCall of choice.message.tool_calls) {
385
398
  content.push({
386
399
  type: "tool-call",
387
- toolCallType: "function",
388
400
  toolCallId: (_a = toolCall.id) != null ? _a : generateId(),
389
401
  toolName: toolCall.function.name,
390
- args: toolCall.function.arguments
402
+ input: toolCall.function.arguments
391
403
  });
392
404
  }
393
405
  }
@@ -465,6 +477,8 @@ var OpenAICompatibleChatLanguageModel = class {
465
477
  };
466
478
  let isFirstChunk = true;
467
479
  const providerOptionsName = this.providerOptionsName;
480
+ let isActiveReasoning = false;
481
+ let isActiveText = false;
468
482
  return {
469
483
  stream: response.pipeThrough(
470
484
  new TransformStream({
@@ -474,6 +488,9 @@ var OpenAICompatibleChatLanguageModel = class {
474
488
  // TODO we lost type safety on Chunk, most likely due to the error schema. MUST FIX
475
489
  transform(chunk, controller) {
476
490
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
491
+ if (options.includeRawChunks) {
492
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
493
+ }
477
494
  if (!chunk.success) {
478
495
  finishReason = "error";
479
496
  controller.enqueue({ type: "error", error: chunk.error });
@@ -528,15 +545,28 @@ var OpenAICompatibleChatLanguageModel = class {
528
545
  }
529
546
  const delta = choice.delta;
530
547
  if (delta.reasoning_content != null) {
548
+ if (!isActiveReasoning) {
549
+ controller.enqueue({
550
+ type: "reasoning-start",
551
+ id: "reasoning-0"
552
+ });
553
+ isActiveReasoning = true;
554
+ }
531
555
  controller.enqueue({
532
- type: "reasoning",
533
- text: delta.reasoning_content
556
+ type: "reasoning-delta",
557
+ id: "reasoning-0",
558
+ delta: delta.reasoning_content
534
559
  });
535
560
  }
536
561
  if (delta.content != null) {
562
+ if (!isActiveText) {
563
+ controller.enqueue({ type: "text-start", id: "txt-0" });
564
+ isActiveText = true;
565
+ }
537
566
  controller.enqueue({
538
- type: "text",
539
- text: delta.content
567
+ type: "text-delta",
568
+ id: "txt-0",
569
+ delta: delta.content
540
570
  });
541
571
  }
542
572
  if (delta.tool_calls != null) {
@@ -561,6 +591,11 @@ var OpenAICompatibleChatLanguageModel = class {
561
591
  message: `Expected 'function.name' to be a string.`
562
592
  });
563
593
  }
594
+ controller.enqueue({
595
+ type: "tool-input-start",
596
+ id: toolCallDelta.id,
597
+ toolName: toolCallDelta.function.name
598
+ });
564
599
  toolCalls[index] = {
565
600
  id: toolCallDelta.id,
566
601
  type: "function",
@@ -574,20 +609,21 @@ var OpenAICompatibleChatLanguageModel = class {
574
609
  if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null) {
575
610
  if (toolCall2.function.arguments.length > 0) {
576
611
  controller.enqueue({
577
- type: "tool-call-delta",
578
- toolCallType: "function",
579
- toolCallId: toolCall2.id,
580
- toolName: toolCall2.function.name,
581
- argsTextDelta: toolCall2.function.arguments
612
+ type: "tool-input-start",
613
+ id: toolCall2.id,
614
+ toolName: toolCall2.function.name
582
615
  });
583
616
  }
584
617
  if (isParsableJson(toolCall2.function.arguments)) {
618
+ controller.enqueue({
619
+ type: "tool-input-end",
620
+ id: toolCall2.id
621
+ });
585
622
  controller.enqueue({
586
623
  type: "tool-call",
587
- toolCallType: "function",
588
624
  toolCallId: (_e = toolCall2.id) != null ? _e : generateId(),
589
625
  toolName: toolCall2.function.name,
590
- args: toolCall2.function.arguments
626
+ input: toolCall2.function.arguments
591
627
  });
592
628
  toolCall2.hasFinished = true;
593
629
  }
@@ -602,19 +638,20 @@ var OpenAICompatibleChatLanguageModel = class {
602
638
  toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : "";
603
639
  }
604
640
  controller.enqueue({
605
- type: "tool-call-delta",
606
- toolCallType: "function",
607
- toolCallId: toolCall.id,
608
- toolName: toolCall.function.name,
609
- argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
641
+ type: "tool-input-delta",
642
+ id: toolCall.id,
643
+ delta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
610
644
  });
611
645
  if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && isParsableJson(toolCall.function.arguments)) {
646
+ controller.enqueue({
647
+ type: "tool-input-end",
648
+ id: toolCall.id
649
+ });
612
650
  controller.enqueue({
613
651
  type: "tool-call",
614
- toolCallType: "function",
615
652
  toolCallId: (_l = toolCall.id) != null ? _l : generateId(),
616
653
  toolName: toolCall.function.name,
617
- args: toolCall.function.arguments
654
+ input: toolCall.function.arguments
618
655
  });
619
656
  toolCall.hasFinished = true;
620
657
  }
@@ -623,6 +660,12 @@ var OpenAICompatibleChatLanguageModel = class {
623
660
  },
624
661
  flush(controller) {
625
662
  var _a2, _b, _c, _d, _e;
663
+ if (isActiveReasoning) {
664
+ controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
665
+ }
666
+ if (isActiveText) {
667
+ controller.enqueue({ type: "text-end", id: "txt-0" });
668
+ }
626
669
  const providerMetadata = {
627
670
  [providerOptionsName]: {},
628
671
  ...metadataExtractor == null ? void 0 : metadataExtractor.buildMetadata()
@@ -1006,6 +1049,9 @@ var OpenAICompatibleCompletionLanguageModel = class {
1006
1049
  },
1007
1050
  transform(chunk, controller) {
1008
1051
  var _a, _b, _c;
1052
+ if (options.includeRawChunks) {
1053
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1054
+ }
1009
1055
  if (!chunk.success) {
1010
1056
  finishReason = "error";
1011
1057
  controller.enqueue({ type: "error", error: chunk.error });
@@ -1023,6 +1069,10 @@ var OpenAICompatibleCompletionLanguageModel = class {
1023
1069
  type: "response-metadata",
1024
1070
  ...getResponseMetadata(value)
1025
1071
  });
1072
+ controller.enqueue({
1073
+ type: "text-start",
1074
+ id: "0"
1075
+ });
1026
1076
  }
1027
1077
  if (value.usage != null) {
1028
1078
  usage.inputTokens = (_a = value.usage.prompt_tokens) != null ? _a : void 0;
@@ -1037,12 +1087,16 @@ var OpenAICompatibleCompletionLanguageModel = class {
1037
1087
  }
1038
1088
  if ((choice == null ? void 0 : choice.text) != null) {
1039
1089
  controller.enqueue({
1040
- type: "text",
1041
- text: choice.text
1090
+ type: "text-delta",
1091
+ id: "0",
1092
+ delta: choice.text
1042
1093
  });
1043
1094
  }
1044
1095
  },
1045
1096
  flush(controller) {
1097
+ if (!isFirstChunk) {
1098
+ controller.enqueue({ type: "text-end", id: "0" });
1099
+ }
1046
1100
  controller.enqueue({
1047
1101
  type: "finish",
1048
1102
  finishReason,