veryfront 0.1.197 → 0.1.198

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/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.197",
3
+ "version": "0.1.198",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "exclude": [
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-loader.d.ts","sourceRoot":"","sources":["../../../src/src/provider/runtime-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAkhDD,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,YAAY,CAkDd;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,MAAM,GACd,YAAY,CA4Dd;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,YAAY,CAkDd;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,gBAAgB,CA0ClB;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,gBAAgB,CAgDlB"}
1
+ {"version":3,"file":"runtime-loader.d.ts","sourceRoot":"","sources":["../../../src/src/provider/runtime-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AA0oDD,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,YAAY,CAkDd;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,MAAM,GACd,YAAY,CA4Dd;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,YAAY,CAkDd;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,gBAAgB,CA0ClB;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GACd,gBAAgB,CAgDlB"}
@@ -440,6 +440,7 @@ async function* streamAnthropicCompatibleParts(stream) {
440
440
  const decoder = new TextDecoder();
441
441
  let buffer = "";
442
442
  const toolCalls = new Map();
443
+ const reasoningBlocks = new Map();
443
444
  let finishReason = null;
444
445
  let usage;
445
446
  for await (const chunk of stream) {
@@ -466,6 +467,22 @@ async function* streamAnthropicCompatibleParts(stream) {
466
467
  yield { type: "text-delta", delta: contentBlock.text };
467
468
  continue;
468
469
  }
470
+ if (blockType === "thinking") {
471
+ const reasoningId = `thinking-${index}`;
472
+ reasoningBlocks.set(index, { id: reasoningId });
473
+ yield {
474
+ type: "reasoning-start",
475
+ id: reasoningId,
476
+ };
477
+ if (typeof contentBlock?.thinking === "string" && contentBlock.thinking.length > 0) {
478
+ yield {
479
+ type: "reasoning-delta",
480
+ id: reasoningId,
481
+ delta: contentBlock.thinking,
482
+ };
483
+ }
484
+ continue;
485
+ }
469
486
  if ((blockType === "tool_use" || blockType === "server_tool_use") &&
470
487
  typeof contentBlock?.id === "string" &&
471
488
  typeof contentBlock?.name === "string") {
@@ -527,6 +544,19 @@ async function* streamAnthropicCompatibleParts(stream) {
527
544
  yield { type: "text-delta", delta: delta.text };
528
545
  continue;
529
546
  }
547
+ if (deltaType === "thinking_delta" && typeof delta?.thinking === "string" &&
548
+ delta.thinking.length > 0) {
549
+ const current = reasoningBlocks.get(index);
550
+ if (!current) {
551
+ continue;
552
+ }
553
+ yield {
554
+ type: "reasoning-delta",
555
+ id: current.id,
556
+ delta: delta.thinking,
557
+ };
558
+ continue;
559
+ }
530
560
  if (deltaType === "input_json_delta" && typeof delta?.partial_json === "string") {
531
561
  const current = toolCalls.get(index);
532
562
  if (!current) {
@@ -543,6 +573,15 @@ async function* streamAnthropicCompatibleParts(stream) {
543
573
  }
544
574
  if (eventType === "content_block_stop") {
545
575
  const index = typeof record?.index === "number" ? record.index : 0;
576
+ const reasoning = reasoningBlocks.get(index);
577
+ if (reasoning) {
578
+ yield {
579
+ type: "reasoning-end",
580
+ id: reasoning.id,
581
+ };
582
+ reasoningBlocks.delete(index);
583
+ continue;
584
+ }
546
585
  const current = toolCalls.get(index);
547
586
  if (!current) {
548
587
  continue;
@@ -871,6 +910,8 @@ async function* streamGoogleCompatibleParts(stream) {
871
910
  const decoder = new TextDecoder();
872
911
  let buffer = "";
873
912
  const seenToolCalls = new Set();
913
+ let reasoningId = null;
914
+ let reasoningIndex = 0;
874
915
  let finishReason = null;
875
916
  let usage;
876
917
  for await (const chunk of stream) {
@@ -888,6 +929,29 @@ async function* streamGoogleCompatibleParts(stream) {
888
929
  finishReason = normalizedFinishReason;
889
930
  }
890
931
  for (const [index, part] of extractGoogleCandidateParts(event).entries()) {
932
+ const isThought = part.thought === true;
933
+ if (isThought && typeof part.text === "string" && part.text.length > 0) {
934
+ if (!reasoningId) {
935
+ reasoningId = `reasoning-${reasoningIndex++}`;
936
+ yield {
937
+ type: "reasoning-start",
938
+ id: reasoningId,
939
+ };
940
+ }
941
+ yield {
942
+ type: "reasoning-delta",
943
+ id: reasoningId,
944
+ delta: part.text,
945
+ };
946
+ continue;
947
+ }
948
+ if (reasoningId) {
949
+ yield {
950
+ type: "reasoning-end",
951
+ id: reasoningId,
952
+ };
953
+ reasoningId = null;
954
+ }
891
955
  if (typeof part.text === "string" && part.text.length > 0) {
892
956
  yield { type: "text-delta", delta: part.text };
893
957
  continue;
@@ -930,6 +994,12 @@ async function* streamGoogleCompatibleParts(stream) {
930
994
  usage = extractGoogleUsage(event) ?? usage;
931
995
  }
932
996
  }
997
+ if (reasoningId) {
998
+ yield {
999
+ type: "reasoning-end",
1000
+ id: reasoningId,
1001
+ };
1002
+ }
933
1003
  yield {
934
1004
  type: "finish",
935
1005
  finishReason,
@@ -971,6 +1041,8 @@ async function* streamOpenAICompatibleParts(stream) {
971
1041
  const decoder = new TextDecoder();
972
1042
  let buffer = "";
973
1043
  const toolCalls = new Map();
1044
+ let reasoningId = null;
1045
+ let reasoningIndex = 0;
974
1046
  let finishReason = null;
975
1047
  let usage;
976
1048
  for await (const chunk of stream) {
@@ -983,56 +1055,81 @@ async function* streamOpenAICompatibleParts(stream) {
983
1055
  }
984
1056
  const record = readRecord(event);
985
1057
  usage = extractOpenAIUsage(record) ?? usage;
986
- const choices = Array.isArray(record?.choices) ? record.choices : [];
987
- for (const choiceValue of choices) {
988
- const choice = readRecord(choiceValue);
989
- if (!choice) {
990
- continue;
1058
+ const choice = extractFirstChoice(record);
1059
+ if (!choice) {
1060
+ continue;
1061
+ }
1062
+ const delta = readRecord(choice.delta);
1063
+ if (typeof delta?.reasoning_content === "string" && delta.reasoning_content.length > 0) {
1064
+ if (!reasoningId) {
1065
+ reasoningId = `reasoning-${reasoningIndex++}`;
1066
+ yield {
1067
+ type: "reasoning-start",
1068
+ id: reasoningId,
1069
+ };
991
1070
  }
992
- const delta = readRecord(choice.delta);
993
- const textDelta = extractOpenAIContentText(delta?.content);
994
- if (textDelta.length > 0) {
995
- yield { type: "text-delta", delta: textDelta };
1071
+ yield {
1072
+ type: "reasoning-delta",
1073
+ id: reasoningId,
1074
+ delta: delta.reasoning_content,
1075
+ };
1076
+ }
1077
+ const textDelta = extractOpenAIContentText(delta?.content);
1078
+ if (textDelta.length > 0) {
1079
+ if (reasoningId) {
1080
+ yield {
1081
+ type: "reasoning-end",
1082
+ id: reasoningId,
1083
+ };
1084
+ reasoningId = null;
996
1085
  }
997
- const rawToolCalls = Array.isArray(delta?.tool_calls) ? delta.tool_calls : [];
998
- for (const rawToolCall of rawToolCalls) {
999
- const toolCallRecord = readRecord(rawToolCall);
1000
- const index = typeof toolCallRecord?.index === "number" ? toolCallRecord.index : 0;
1001
- const current = toolCalls.get(index) ?? {
1002
- id: typeof toolCallRecord?.id === "string" ? toolCallRecord.id : `tool-${index}`,
1003
- name: "",
1004
- arguments: "",
1005
- started: false,
1086
+ yield { type: "text-delta", delta: textDelta };
1087
+ }
1088
+ const rawToolCalls = Array.isArray(delta?.tool_calls) ? delta.tool_calls : [];
1089
+ for (const rawToolCall of rawToolCalls) {
1090
+ if (reasoningId) {
1091
+ yield {
1092
+ type: "reasoning-end",
1093
+ id: reasoningId,
1006
1094
  };
1007
- if (typeof toolCallRecord?.id === "string") {
1008
- current.id = toolCallRecord.id;
1009
- }
1010
- const fn = readRecord(toolCallRecord?.function);
1011
- if (typeof fn?.name === "string") {
1012
- current.name = fn.name;
1013
- }
1014
- if (!current.started && current.name.length > 0) {
1015
- current.started = true;
1016
- yield {
1017
- type: "tool-input-start",
1018
- id: current.id,
1019
- toolName: current.name,
1020
- };
1021
- }
1022
- if (typeof fn?.arguments === "string" && fn.arguments.length > 0) {
1023
- current.arguments += fn.arguments;
1024
- yield {
1025
- type: "tool-input-delta",
1026
- id: current.id,
1027
- delta: fn.arguments,
1028
- };
1029
- }
1030
- toolCalls.set(index, current);
1095
+ reasoningId = null;
1031
1096
  }
1032
- const normalizedFinishReason = normalizeOpenAIFinishReason(choice.finish_reason);
1033
- if (normalizedFinishReason) {
1034
- finishReason = normalizedFinishReason;
1097
+ const toolCallRecord = readRecord(rawToolCall);
1098
+ const index = typeof toolCallRecord?.index === "number" ? toolCallRecord.index : 0;
1099
+ const current = toolCalls.get(index) ?? {
1100
+ id: typeof toolCallRecord?.id === "string" ? toolCallRecord.id : `tool-${index}`,
1101
+ name: "",
1102
+ arguments: "",
1103
+ started: false,
1104
+ };
1105
+ if (typeof toolCallRecord?.id === "string") {
1106
+ current.id = toolCallRecord.id;
1107
+ }
1108
+ const fn = readRecord(toolCallRecord?.function);
1109
+ if (typeof fn?.name === "string") {
1110
+ current.name = fn.name;
1111
+ }
1112
+ if (!current.started && current.name.length > 0) {
1113
+ current.started = true;
1114
+ yield {
1115
+ type: "tool-input-start",
1116
+ id: current.id,
1117
+ toolName: current.name,
1118
+ };
1119
+ }
1120
+ if (typeof fn?.arguments === "string" && fn.arguments.length > 0) {
1121
+ current.arguments += fn.arguments;
1122
+ yield {
1123
+ type: "tool-input-delta",
1124
+ id: current.id,
1125
+ delta: fn.arguments,
1126
+ };
1035
1127
  }
1128
+ toolCalls.set(index, current);
1129
+ }
1130
+ const normalizedFinishReason = normalizeOpenAIFinishReason(choice.finish_reason);
1131
+ if (normalizedFinishReason) {
1132
+ finishReason = normalizedFinishReason;
1036
1133
  }
1037
1134
  }
1038
1135
  }
@@ -1046,6 +1143,12 @@ async function* streamOpenAICompatibleParts(stream) {
1046
1143
  usage = extractOpenAIUsage(record) ?? usage;
1047
1144
  }
1048
1145
  }
1146
+ if (reasoningId) {
1147
+ yield {
1148
+ type: "reasoning-end",
1149
+ id: reasoningId,
1150
+ };
1151
+ }
1049
1152
  if (finishReason &&
1050
1153
  typeof finishReason === "object" &&
1051
1154
  finishReason.unified === "tool-calls") {
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.197";
1
+ export declare const VERSION = "0.1.198";
2
2
  //# sourceMappingURL=version-constant.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.197";
3
+ export const VERSION = "0.1.198";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfront",
3
- "version": "0.1.197",
3
+ "version": "0.1.198",
4
4
  "description": "The simplest way to build AI-powered apps",
5
5
  "keywords": [
6
6
  "react",
package/src/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.197",
3
+ "version": "0.1.198",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "exclude": [
@@ -156,6 +156,9 @@ type AnthropicStreamToolCallState = {
156
156
  input: string;
157
157
  providerExecuted?: boolean;
158
158
  };
159
+ type AnthropicStreamReasoningState = {
160
+ id: string;
161
+ };
159
162
  type GoogleCompatibleContent = {
160
163
  role: "user" | "model";
161
164
  parts: Array<Record<string, unknown>>;
@@ -780,6 +783,7 @@ async function* streamAnthropicCompatibleParts(
780
783
  const decoder = new TextDecoder();
781
784
  let buffer = "";
782
785
  const toolCalls = new Map<number, AnthropicStreamToolCallState>();
786
+ const reasoningBlocks = new Map<number, AnthropicStreamReasoningState>();
783
787
  let finishReason: string | { unified: string; raw: string } | null = null;
784
788
  let usage: { inputTokens?: number; outputTokens?: number; totalTokens?: number } | undefined;
785
789
 
@@ -815,6 +819,24 @@ async function* streamAnthropicCompatibleParts(
815
819
  continue;
816
820
  }
817
821
 
822
+ if (blockType === "thinking") {
823
+ const reasoningId = `thinking-${index}`;
824
+ reasoningBlocks.set(index, { id: reasoningId });
825
+ yield {
826
+ type: "reasoning-start",
827
+ id: reasoningId,
828
+ };
829
+
830
+ if (typeof contentBlock?.thinking === "string" && contentBlock.thinking.length > 0) {
831
+ yield {
832
+ type: "reasoning-delta",
833
+ id: reasoningId,
834
+ delta: contentBlock.thinking,
835
+ };
836
+ }
837
+ continue;
838
+ }
839
+
818
840
  if (
819
841
  (blockType === "tool_use" || blockType === "server_tool_use") &&
820
842
  typeof contentBlock?.id === "string" &&
@@ -892,6 +914,23 @@ async function* streamAnthropicCompatibleParts(
892
914
  continue;
893
915
  }
894
916
 
917
+ if (
918
+ deltaType === "thinking_delta" && typeof delta?.thinking === "string" &&
919
+ delta.thinking.length > 0
920
+ ) {
921
+ const current = reasoningBlocks.get(index);
922
+ if (!current) {
923
+ continue;
924
+ }
925
+
926
+ yield {
927
+ type: "reasoning-delta",
928
+ id: current.id,
929
+ delta: delta.thinking,
930
+ };
931
+ continue;
932
+ }
933
+
895
934
  if (deltaType === "input_json_delta" && typeof delta?.partial_json === "string") {
896
935
  const current = toolCalls.get(index);
897
936
  if (!current) {
@@ -911,6 +950,16 @@ async function* streamAnthropicCompatibleParts(
911
950
 
912
951
  if (eventType === "content_block_stop") {
913
952
  const index = typeof record?.index === "number" ? record.index : 0;
953
+ const reasoning = reasoningBlocks.get(index);
954
+ if (reasoning) {
955
+ yield {
956
+ type: "reasoning-end",
957
+ id: reasoning.id,
958
+ };
959
+ reasoningBlocks.delete(index);
960
+ continue;
961
+ }
962
+
914
963
  const current = toolCalls.get(index);
915
964
  if (!current) {
916
965
  continue;
@@ -1334,6 +1383,8 @@ async function* streamGoogleCompatibleParts(
1334
1383
  const decoder = new TextDecoder();
1335
1384
  let buffer = "";
1336
1385
  const seenToolCalls = new Set<string>();
1386
+ let reasoningId: string | null = null;
1387
+ let reasoningIndex = 0;
1337
1388
  let finishReason: string | { unified: string; raw: string } | null = null;
1338
1389
  let usage: { inputTokens?: number; outputTokens?: number; totalTokens?: number } | undefined;
1339
1390
 
@@ -1355,6 +1406,32 @@ async function* streamGoogleCompatibleParts(
1355
1406
  }
1356
1407
 
1357
1408
  for (const [index, part] of extractGoogleCandidateParts(event).entries()) {
1409
+ const isThought = part.thought === true;
1410
+ if (isThought && typeof part.text === "string" && part.text.length > 0) {
1411
+ if (!reasoningId) {
1412
+ reasoningId = `reasoning-${reasoningIndex++}`;
1413
+ yield {
1414
+ type: "reasoning-start",
1415
+ id: reasoningId,
1416
+ };
1417
+ }
1418
+
1419
+ yield {
1420
+ type: "reasoning-delta",
1421
+ id: reasoningId,
1422
+ delta: part.text,
1423
+ };
1424
+ continue;
1425
+ }
1426
+
1427
+ if (reasoningId) {
1428
+ yield {
1429
+ type: "reasoning-end",
1430
+ id: reasoningId,
1431
+ };
1432
+ reasoningId = null;
1433
+ }
1434
+
1358
1435
  if (typeof part.text === "string" && part.text.length > 0) {
1359
1436
  yield { type: "text-delta", delta: part.text };
1360
1437
  continue;
@@ -1402,6 +1479,13 @@ async function* streamGoogleCompatibleParts(
1402
1479
  }
1403
1480
  }
1404
1481
 
1482
+ if (reasoningId) {
1483
+ yield {
1484
+ type: "reasoning-end",
1485
+ id: reasoningId,
1486
+ };
1487
+ }
1488
+
1405
1489
  yield {
1406
1490
  type: "finish",
1407
1491
  finishReason,
@@ -1462,6 +1546,8 @@ async function* streamOpenAICompatibleParts(
1462
1546
  const decoder = new TextDecoder();
1463
1547
  let buffer = "";
1464
1548
  const toolCalls = new Map<number, OpenAIStreamToolCallState>();
1549
+ let reasoningId: string | null = null;
1550
+ let reasoningIndex = 0;
1465
1551
  let finishReason: string | { unified: string; raw: string } | null = null;
1466
1552
  let usage: { inputTokens?: number; outputTokens?: number; totalTokens?: number } | undefined;
1467
1553
 
@@ -1477,65 +1563,92 @@ async function* streamOpenAICompatibleParts(
1477
1563
 
1478
1564
  const record = readRecord(event);
1479
1565
  usage = extractOpenAIUsage(record) ?? usage;
1480
- const choices = Array.isArray(record?.choices) ? record.choices : [];
1566
+ const choice = extractFirstChoice(record);
1567
+ if (!choice) {
1568
+ continue;
1569
+ }
1481
1570
 
1482
- for (const choiceValue of choices) {
1483
- const choice = readRecord(choiceValue);
1484
- if (!choice) {
1485
- continue;
1571
+ const delta = readRecord(choice.delta);
1572
+ if (typeof delta?.reasoning_content === "string" && delta.reasoning_content.length > 0) {
1573
+ if (!reasoningId) {
1574
+ reasoningId = `reasoning-${reasoningIndex++}`;
1575
+ yield {
1576
+ type: "reasoning-start",
1577
+ id: reasoningId,
1578
+ };
1486
1579
  }
1487
1580
 
1488
- const delta = readRecord(choice.delta);
1489
- const textDelta = extractOpenAIContentText(delta?.content);
1490
- if (textDelta.length > 0) {
1491
- yield { type: "text-delta", delta: textDelta };
1492
- }
1581
+ yield {
1582
+ type: "reasoning-delta",
1583
+ id: reasoningId,
1584
+ delta: delta.reasoning_content,
1585
+ };
1586
+ }
1493
1587
 
1494
- const rawToolCalls = Array.isArray(delta?.tool_calls) ? delta.tool_calls : [];
1495
- for (const rawToolCall of rawToolCalls) {
1496
- const toolCallRecord = readRecord(rawToolCall);
1497
- const index = typeof toolCallRecord?.index === "number" ? toolCallRecord.index : 0;
1498
- const current = toolCalls.get(index) ?? {
1499
- id: typeof toolCallRecord?.id === "string" ? toolCallRecord.id : `tool-${index}`,
1500
- name: "",
1501
- arguments: "",
1502
- started: false,
1588
+ const textDelta = extractOpenAIContentText(delta?.content);
1589
+ if (textDelta.length > 0) {
1590
+ if (reasoningId) {
1591
+ yield {
1592
+ type: "reasoning-end",
1593
+ id: reasoningId,
1503
1594
  };
1595
+ reasoningId = null;
1596
+ }
1597
+ yield { type: "text-delta", delta: textDelta };
1598
+ }
1504
1599
 
1505
- if (typeof toolCallRecord?.id === "string") {
1506
- current.id = toolCallRecord.id;
1507
- }
1600
+ const rawToolCalls = Array.isArray(delta?.tool_calls) ? delta.tool_calls : [];
1601
+ for (const rawToolCall of rawToolCalls) {
1602
+ if (reasoningId) {
1603
+ yield {
1604
+ type: "reasoning-end",
1605
+ id: reasoningId,
1606
+ };
1607
+ reasoningId = null;
1608
+ }
1508
1609
 
1509
- const fn = readRecord(toolCallRecord?.function);
1510
- if (typeof fn?.name === "string") {
1511
- current.name = fn.name;
1512
- }
1610
+ const toolCallRecord = readRecord(rawToolCall);
1611
+ const index = typeof toolCallRecord?.index === "number" ? toolCallRecord.index : 0;
1612
+ const current = toolCalls.get(index) ?? {
1613
+ id: typeof toolCallRecord?.id === "string" ? toolCallRecord.id : `tool-${index}`,
1614
+ name: "",
1615
+ arguments: "",
1616
+ started: false,
1617
+ };
1513
1618
 
1514
- if (!current.started && current.name.length > 0) {
1515
- current.started = true;
1516
- yield {
1517
- type: "tool-input-start",
1518
- id: current.id,
1519
- toolName: current.name,
1520
- };
1521
- }
1619
+ if (typeof toolCallRecord?.id === "string") {
1620
+ current.id = toolCallRecord.id;
1621
+ }
1522
1622
 
1523
- if (typeof fn?.arguments === "string" && fn.arguments.length > 0) {
1524
- current.arguments += fn.arguments;
1525
- yield {
1526
- type: "tool-input-delta",
1527
- id: current.id,
1528
- delta: fn.arguments,
1529
- };
1530
- }
1623
+ const fn = readRecord(toolCallRecord?.function);
1624
+ if (typeof fn?.name === "string") {
1625
+ current.name = fn.name;
1626
+ }
1531
1627
 
1532
- toolCalls.set(index, current);
1628
+ if (!current.started && current.name.length > 0) {
1629
+ current.started = true;
1630
+ yield {
1631
+ type: "tool-input-start",
1632
+ id: current.id,
1633
+ toolName: current.name,
1634
+ };
1533
1635
  }
1534
1636
 
1535
- const normalizedFinishReason = normalizeOpenAIFinishReason(choice.finish_reason);
1536
- if (normalizedFinishReason) {
1537
- finishReason = normalizedFinishReason;
1637
+ if (typeof fn?.arguments === "string" && fn.arguments.length > 0) {
1638
+ current.arguments += fn.arguments;
1639
+ yield {
1640
+ type: "tool-input-delta",
1641
+ id: current.id,
1642
+ delta: fn.arguments,
1643
+ };
1538
1644
  }
1645
+
1646
+ toolCalls.set(index, current);
1647
+ }
1648
+
1649
+ const normalizedFinishReason = normalizeOpenAIFinishReason(choice.finish_reason);
1650
+ if (normalizedFinishReason) {
1651
+ finishReason = normalizedFinishReason;
1539
1652
  }
1540
1653
  }
1541
1654
  }
@@ -1552,6 +1665,13 @@ async function* streamOpenAICompatibleParts(
1552
1665
  }
1553
1666
  }
1554
1667
 
1668
+ if (reasoningId) {
1669
+ yield {
1670
+ type: "reasoning-end",
1671
+ id: reasoningId,
1672
+ };
1673
+ }
1674
+
1555
1675
  if (
1556
1676
  finishReason &&
1557
1677
  typeof finishReason === "object" &&
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.197";
3
+ export const VERSION = "0.1.198";