190proof 1.0.85 → 1.0.87

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/README.md CHANGED
@@ -245,7 +245,13 @@ interface ParsedResponseMessage {
245
245
  role: "assistant";
246
246
  content: string | null;
247
247
  function_call: FunctionCall | null;
248
+ function_calls: FunctionCall[];
248
249
  files: File[]; // For models that return files (e.g., image generation)
250
+ usage: {
251
+ prompt_tokens: number;
252
+ completion_tokens: number;
253
+ total_tokens: number;
254
+ } | null; // null when streaming
249
255
  }
250
256
  ```
251
257
 
package/dist/index.d.mts CHANGED
@@ -31,6 +31,8 @@ declare enum GPTModel {
31
31
  }
32
32
  declare enum GroqModel {
33
33
  LLAMA_3_70B_8192 = "llama3-70b-8192",
34
+ LLAMA_3_3_70B_VERSATILE = "llama-3.3-70b-versatile",
35
+ QWEN3_32B = "qwen/qwen3-32b",
34
36
  DEEPSEEK_R1_DISTILL_LLAMA_70B = "deepseek-r1-distill-llama-70b"
35
37
  }
36
38
  declare enum GeminiModel {
@@ -62,6 +64,11 @@ interface ParsedResponseMessage {
62
64
  function_call: FunctionCall | null;
63
65
  function_calls: FunctionCall[];
64
66
  files: File[];
67
+ usage: {
68
+ prompt_tokens: number;
69
+ completion_tokens: number;
70
+ total_tokens: number;
71
+ } | null;
65
72
  }
66
73
  interface FunctionCall {
67
74
  name: string;
package/dist/index.d.ts CHANGED
@@ -31,6 +31,8 @@ declare enum GPTModel {
31
31
  }
32
32
  declare enum GroqModel {
33
33
  LLAMA_3_70B_8192 = "llama3-70b-8192",
34
+ LLAMA_3_3_70B_VERSATILE = "llama-3.3-70b-versatile",
35
+ QWEN3_32B = "qwen/qwen3-32b",
34
36
  DEEPSEEK_R1_DISTILL_LLAMA_70B = "deepseek-r1-distill-llama-70b"
35
37
  }
36
38
  declare enum GeminiModel {
@@ -62,6 +64,11 @@ interface ParsedResponseMessage {
62
64
  function_call: FunctionCall | null;
63
65
  function_calls: FunctionCall[];
64
66
  files: File[];
67
+ usage: {
68
+ prompt_tokens: number;
69
+ completion_tokens: number;
70
+ total_tokens: number;
71
+ } | null;
65
72
  }
66
73
  interface FunctionCall {
67
74
  name: string;
package/dist/index.js CHANGED
@@ -74,6 +74,8 @@ var GPTModel = /* @__PURE__ */ ((GPTModel2) => {
74
74
  })(GPTModel || {});
75
75
  var GroqModel = /* @__PURE__ */ ((GroqModel2) => {
76
76
  GroqModel2["LLAMA_3_70B_8192"] = "llama3-70b-8192";
77
+ GroqModel2["LLAMA_3_3_70B_VERSATILE"] = "llama-3.3-70b-versatile";
78
+ GroqModel2["QWEN3_32B"] = "qwen/qwen3-32b";
77
79
  GroqModel2["DEEPSEEK_R1_DISTILL_LLAMA_70B"] = "deepseek-r1-distill-llama-70b";
78
80
  return GroqModel2;
79
81
  })(GroqModel || {});
@@ -200,7 +202,8 @@ function parseStreamedResponse(identifier, paragraph, toolCallAccumulators, allo
200
202
  content: paragraph || null,
201
203
  function_call: functionCalls[0] || null,
202
204
  function_calls: functionCalls,
203
- files: []
205
+ files: [],
206
+ usage: null
204
207
  };
205
208
  }
206
209
  function truncatePayload(payload) {
@@ -372,7 +375,10 @@ async function callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs)
372
375
  const { done, value } = await reader.read();
373
376
  clearTimeout(abortTimeout);
374
377
  if (done) {
375
- logger_default.error(id, `Stream ended prematurely after ${chunkIndex + 1} chunks`);
378
+ logger_default.error(
379
+ id,
380
+ `Stream ended prematurely after ${chunkIndex + 1} chunks`
381
+ );
376
382
  throw new Error("Stream error: ended prematurely");
377
383
  }
378
384
  let chunk = new TextDecoder().decode(value);
@@ -477,7 +483,12 @@ async function callOpenAI(id, openAiPayload, openAiConfig) {
477
483
  content: choice.message.content || null,
478
484
  function_call: functionCalls[0] || null,
479
485
  function_calls: functionCalls,
480
- files: []
486
+ files: [],
487
+ usage: data.usage ? {
488
+ prompt_tokens: data.usage.prompt_tokens,
489
+ completion_tokens: data.usage.completion_tokens,
490
+ total_tokens: data.usage.total_tokens
491
+ } : null
481
492
  };
482
493
  }
483
494
  async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries = 5, chunkTimeoutMs = 15e3) {
@@ -493,7 +504,12 @@ async function callOpenAiWithRetries(id, openAiPayload, openAiConfig, retries =
493
504
  "OpenAI",
494
505
  async () => {
495
506
  if (useStreaming) {
496
- return callOpenAIStream(id, openAiPayload, openAiConfig, chunkTimeoutMs);
507
+ return callOpenAIStream(
508
+ id,
509
+ openAiPayload,
510
+ openAiConfig,
511
+ chunkTimeoutMs
512
+ );
497
513
  } else {
498
514
  return callOpenAI(id, openAiPayload, openAiConfig);
499
515
  }
@@ -526,7 +542,10 @@ function jigAnthropicMessages(messages) {
526
542
  var _a, _b;
527
543
  let jiggedMessages = messages.slice();
528
544
  if (((_a = jiggedMessages[0]) == null ? void 0 : _a.role) !== "user") {
529
- jiggedMessages = [{ role: "user", content: "..." }, ...jiggedMessages];
545
+ jiggedMessages = [
546
+ { role: "user", content: "..." },
547
+ ...jiggedMessages
548
+ ];
530
549
  }
531
550
  jiggedMessages = jiggedMessages.reduce((acc, message) => {
532
551
  if (acc.length === 0)
@@ -571,24 +590,28 @@ async function prepareAnthropicPayload(_identifier, payload) {
571
590
  for (const file of message.files || []) {
572
591
  if (ALLOWED_IMAGE_MIME_TYPES.includes(file.mimeType)) {
573
592
  if (file.url) {
574
- contentBlocks.push({
575
- type: "image",
576
- source: {
577
- type: "base64",
578
- media_type: "image/png",
579
- data: await getNormalizedBase64PNG(file.url, file.mimeType)
580
- }
581
- });
593
+ if (message.role == "user") {
594
+ contentBlocks.push({
595
+ type: "image",
596
+ source: {
597
+ type: "base64",
598
+ media_type: "image/png",
599
+ data: await getNormalizedBase64PNG(file.url, file.mimeType)
600
+ }
601
+ });
602
+ }
582
603
  contentBlocks.push({ type: "text", text: `Image (${file.url})` });
583
604
  } else if (file.data) {
584
- contentBlocks.push({
585
- type: "image",
586
- source: {
587
- type: "base64",
588
- media_type: file.mimeType,
589
- data: file.data
590
- }
591
- });
605
+ if (message.role == "user") {
606
+ contentBlocks.push({
607
+ type: "image",
608
+ source: {
609
+ type: "base64",
610
+ media_type: file.mimeType,
611
+ data: file.data
612
+ }
613
+ });
614
+ }
592
615
  }
593
616
  } else if (file.url) {
594
617
  contentBlocks.push({
@@ -687,7 +710,11 @@ ${text}` : text;
687
710
  }
688
711
  }
689
712
  if (!textResponse && !functionCalls.length) {
690
- logger_default.error(id, "Missing text & functions in Anthropic API response:", data);
713
+ logger_default.error(
714
+ id,
715
+ "Missing text & functions in Anthropic API response:",
716
+ data
717
+ );
691
718
  throw new Error("Missing text & functions in Anthropic API response");
692
719
  }
693
720
  return {
@@ -695,19 +722,32 @@ ${text}` : text;
695
722
  content: textResponse,
696
723
  function_call: functionCalls[0] || null,
697
724
  function_calls: functionCalls,
698
- files: []
725
+ files: [],
726
+ usage: data.usage ? {
727
+ prompt_tokens: data.usage.input_tokens,
728
+ completion_tokens: data.usage.output_tokens,
729
+ total_tokens: data.usage.input_tokens + data.usage.output_tokens
730
+ } : null
699
731
  };
700
732
  }
701
733
  async function callAnthropicWithRetries(id, payload, config, retries = 5) {
702
- return withRetries(id, "Anthropic", () => callAnthropic(id, payload, config), {
703
- retries
704
- });
734
+ return withRetries(
735
+ id,
736
+ "Anthropic",
737
+ () => callAnthropic(id, payload, config),
738
+ {
739
+ retries
740
+ }
741
+ );
705
742
  }
706
743
  function jigGoogleMessages(messages) {
707
744
  var _a, _b;
708
745
  let jiggedMessages = messages.slice();
709
746
  if (((_a = jiggedMessages[0]) == null ? void 0 : _a.role) === "model") {
710
- jiggedMessages = [{ role: "user", parts: [{ text: "..." }] }, ...jiggedMessages];
747
+ jiggedMessages = [
748
+ { role: "user", parts: [{ text: "..." }] },
749
+ ...jiggedMessages
750
+ ];
711
751
  }
712
752
  jiggedMessages = jiggedMessages.reduce((acc, message) => {
713
753
  if (acc.length === 0)
@@ -779,7 +819,7 @@ async function prepareGoogleAIPayload(_identifier, payload) {
779
819
  return preparedPayload;
780
820
  }
781
821
  async function callGoogleAI(id, payload) {
782
- var _a, _b, _c, _d, _e, _f;
822
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
783
823
  const googleMessages = jigGoogleMessages(payload.messages);
784
824
  const history = googleMessages.slice(0, -1);
785
825
  const lastMessage = googleMessages.slice(-1)[0];
@@ -843,13 +883,15 @@ async function callGoogleAI(id, payload) {
843
883
  content: text || null,
844
884
  files,
845
885
  function_call: (functionCalls == null ? void 0 : functionCalls[0]) || null,
846
- function_calls: functionCalls || []
886
+ function_calls: functionCalls || [],
887
+ usage: response.usageMetadata ? {
888
+ prompt_tokens: (_g = response.usageMetadata.promptTokenCount) != null ? _g : 0,
889
+ completion_tokens: (_h = response.usageMetadata.candidatesTokenCount) != null ? _h : 0,
890
+ total_tokens: (_i = response.usageMetadata.totalTokenCount) != null ? _i : 0
891
+ } : null
847
892
  };
848
893
  }
849
- var CONTENT_VIOLATION_REASONS = /* @__PURE__ */ new Set([
850
- "PROHIBITED_CONTENT",
851
- "SAFETY"
852
- ]);
894
+ var CONTENT_VIOLATION_REASONS = /* @__PURE__ */ new Set(["PROHIBITED_CONTENT", "SAFETY"]);
853
895
  function removeImagesFromGooglePayload(payload) {
854
896
  let removedImages = false;
855
897
  for (const message of payload.messages) {
@@ -889,7 +931,14 @@ async function callGoogleAIWithRetries(id, payload, retries = 5) {
889
931
  errorDetails.errorCode = error2.code;
890
932
  if (error2.details)
891
933
  errorDetails.errorDetails = error2.details;
892
- logger_default.error(id, `Retry #${attempt} error: ${error2.message}`, errorDetails);
934
+ const fileUris = payload.messages.flatMap((m) => m.parts).filter((p) => "fileData" in p).map((p) => p.fileData.fileUri);
935
+ if (fileUris.length)
936
+ errorDetails.fileUris = fileUris;
937
+ logger_default.error(
938
+ id,
939
+ `Retry #${attempt} error: ${error2.message}`,
940
+ errorDetails
941
+ );
893
942
  const violationReason = CONTENT_VIOLATION_REASONS.has(error2.finishReason) && error2.finishReason || CONTENT_VIOLATION_REASONS.has((_a = error2.promptFeedback) == null ? void 0 : _a.blockReason) && ((_b = error2.promptFeedback) == null ? void 0 : _b.blockReason);
894
943
  if (violationReason) {
895
944
  if (!hasTriedWithoutImages) {
@@ -969,7 +1018,12 @@ async function callGroq(id, payload) {
969
1018
  content: answer.content || null,
970
1019
  function_call: functionCalls[0] || null,
971
1020
  function_calls: functionCalls,
972
- files: []
1021
+ files: [],
1022
+ usage: response.data.usage ? {
1023
+ prompt_tokens: response.data.usage.prompt_tokens,
1024
+ completion_tokens: response.data.usage.completion_tokens,
1025
+ total_tokens: response.data.usage.total_tokens
1026
+ } : null
973
1027
  };
974
1028
  }
975
1029
  async function callGroqWithRetries(id, payload, retries = 5) {
@@ -1007,7 +1061,11 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
1007
1061
  );
1008
1062
  }
1009
1063
  if (isGroqPayload(aiPayload)) {
1010
- return await callGroqWithRetries(id, prepareGroqPayload(aiPayload), retries);
1064
+ return await callGroqWithRetries(
1065
+ id,
1066
+ prepareGroqPayload(aiPayload),
1067
+ retries
1068
+ );
1011
1069
  }
1012
1070
  if (isGoogleAIPayload(aiPayload)) {
1013
1071
  return await callGoogleAIWithRetries(
@@ -1019,13 +1077,21 @@ async function callWithRetries(id, aiPayload, aiConfig, retries = 5, chunkTimeou
1019
1077
  throw new Error("Invalid AI payload: Unknown model type.");
1020
1078
  } catch (error2) {
1021
1079
  if (aiPayload.fallbackModel) {
1022
- logger_default.log(
1080
+ logger_default.error(
1023
1081
  id,
1024
- `Primary model ${aiPayload.model} failed, falling back to ${aiPayload.fallbackModel}`
1082
+ `Primary model ${aiPayload.model} failed, falling back to ${aiPayload.fallbackModel}`,
1083
+ {
1084
+ error: error2 instanceof Error ? error2.message : error2,
1085
+ cause: error2 instanceof Error && error2.cause instanceof Error ? error2.cause.message : void 0
1086
+ }
1025
1087
  );
1026
1088
  return callWithRetries(
1027
1089
  id,
1028
- { ...aiPayload, model: aiPayload.fallbackModel, fallbackModel: void 0 },
1090
+ {
1091
+ ...aiPayload,
1092
+ model: aiPayload.fallbackModel,
1093
+ fallbackModel: void 0
1094
+ },
1029
1095
  aiConfig,
1030
1096
  retries,
1031
1097
  chunkTimeoutMs