190proof 1.0.69 → 1.0.70

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.js CHANGED
@@ -86,6 +86,25 @@ var GeminiModel = /* @__PURE__ */ ((GeminiModel2) => {
86
86
  return GeminiModel2;
87
87
  })(GeminiModel || {});
88
88
 
89
+ // logger.ts
90
+ function formatMessage(level, identifier, message) {
91
+ return `[${level}] [${identifier}] ${message}`;
92
+ }
93
+ function log(identifier, message, ...args) {
94
+ console.log(formatMessage("LOG", identifier, message), ...args);
95
+ }
96
+ function warn(identifier, message, ...args) {
97
+ console.warn(formatMessage("WARN", identifier, message), ...args);
98
+ }
99
+ function error(identifier, message, ...args) {
100
+ console.error(formatMessage("ERROR", identifier, message), ...args);
101
+ }
102
+ var logger_default = {
103
+ log,
104
+ warn,
105
+ error
106
+ };
107
+
89
108
  // index.ts
90
109
  var import_client_bedrock_runtime = require("@aws-sdk/client-bedrock-runtime");
91
110
  var import_axios = __toESM(require("axios"));
@@ -118,13 +137,13 @@ function parseStreamedResponse(identifier, paragraph, functionCallName, function
118
137
  name: functionCallName,
119
138
  arguments: JSON.parse(functionCallArgs)
120
139
  };
121
- } catch (error) {
122
- console.error("Error parsing functionCallArgs:", functionCallArgs);
123
- throw error;
140
+ } catch (error2) {
141
+ logger_default.error(identifier, "Error parsing functionCallArgs:", functionCallArgs);
142
+ throw error2;
124
143
  }
125
144
  }
126
145
  if (!paragraph && !functionCall) {
127
- console.error(
146
+ logger_default.error(
128
147
  identifier,
129
148
  "Stream error: received message without content or function_call, raw:",
130
149
  JSON.stringify({ paragraph, functionCallName, functionCallArgs })
@@ -142,7 +161,7 @@ function parseStreamedResponse(identifier, paragraph, functionCallName, function
142
161
  }
143
162
  async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, retries = 5, chunkTimeoutMs = 15e3) {
144
163
  var _a, _b;
145
- console.log(
164
+ logger_default.log(
146
165
  identifier,
147
166
  "Calling OpenAI API with retries:",
148
167
  openAiConfig == null ? void 0 : openAiConfig.service,
@@ -162,27 +181,15 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
162
181
  chunkTimeoutMs
163
182
  );
164
183
  }
165
- } catch (error) {
166
- console.error(error);
167
- console.error(
184
+ } catch (error2) {
185
+ logger_default.error(
168
186
  identifier,
169
- `Retrying due to error: received bad response from OpenAI API [${openAiConfig == null ? void 0 : openAiConfig.service}-${openAiPayload.model}-${openAiConfig == null ? void 0 : openAiConfig.orgId}]: ${error.message} - ${JSON.stringify((_a = error.response) == null ? void 0 : _a.data)}`
187
+ `Retry #${i} error: ${error2.message}`,
188
+ ((_a = error2.response) == null ? void 0 : _a.data) || error2.data || error2
170
189
  );
171
- const errorCode = (_b = error.data) == null ? void 0 : _b.code;
172
- if (errorCode) {
173
- console.error(
174
- identifier,
175
- `Retry #${i} failed with API error: ${errorCode}`,
176
- JSON.stringify({
177
- data: error.data
178
- })
179
- );
180
- }
190
+ const errorCode = (_b = error2.data) == null ? void 0 : _b.code;
181
191
  if (errorCode === "content_policy_violation") {
182
- console.log(
183
- identifier,
184
- `Removing images due to content policy violation error`
185
- );
192
+ logger_default.log(identifier, "Removing images due to content policy violation error");
186
193
  openAiPayload.messages.forEach((message) => {
187
194
  if (Array.isArray(message.content)) {
188
195
  message.content = message.content.filter(
@@ -192,34 +199,25 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
192
199
  });
193
200
  }
194
201
  if (i >= 2 && (openAiConfig == null ? void 0 : openAiConfig.service) === "azure" && errorCode === "content_filter") {
195
- console.log(
196
- identifier,
197
- `Switching to OpenAI service due to content filter error`
198
- );
202
+ logger_default.log(identifier, "Switching to OpenAI service due to content filter error");
199
203
  openAiConfig.service = "openai";
200
204
  }
201
205
  if (i === 3) {
202
206
  if ((openAiConfig == null ? void 0 : openAiConfig.service) === "azure") {
203
- console.log(
204
- identifier,
205
- `Switching to OpenAI service due to Azure service error`
206
- );
207
+ logger_default.log(identifier, "Switching to OpenAI service due to Azure service error");
207
208
  openAiConfig.service = "openai";
208
209
  }
209
210
  }
210
211
  if (i === 4) {
211
212
  if (openAiPayload.tools) {
212
- console.log(
213
- identifier,
214
- `Switching to no tool choice due to persistent error`
215
- );
213
+ logger_default.log(identifier, "Switching to no tool choice due to persistent error");
216
214
  openAiPayload.tool_choice = "none";
217
215
  }
218
216
  }
219
217
  await timeout(250);
220
218
  }
221
219
  }
222
- console.error(
220
+ logger_default.error(
223
221
  identifier,
224
222
  `Failed to call OpenAI API after ${retries} attempts. Please lookup OpenAI status for active issues.`,
225
223
  errorObj
@@ -241,7 +239,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
241
239
  let response;
242
240
  const controller = new AbortController();
243
241
  if (openAiConfig.service === "azure") {
244
- console.log(identifier, "Using Azure OpenAI service", openAiPayload.model);
242
+ logger_default.log(identifier, "Using Azure OpenAI service", openAiPayload.model);
245
243
  const model = openAiPayload.model;
246
244
  if (!openAiConfig.modelConfigMap) {
247
245
  throw new Error(
@@ -255,19 +253,15 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
255
253
  } else {
256
254
  throw new Error("Azure OpenAI endpoint is required in modelConfigMap.");
257
255
  }
258
- console.log(identifier, "Using endpoint", endpoint);
256
+ logger_default.log(identifier, "Using endpoint", endpoint);
259
257
  try {
260
258
  const stringifiedPayload = JSON.stringify({
261
259
  ...openAiPayload,
262
260
  stream: true
263
261
  });
264
262
  const parsedPayload = JSON.parse(stringifiedPayload);
265
- } catch (error) {
266
- console.error(
267
- identifier,
268
- "Stream error: Azure OpenAI JSON parsing error:",
269
- JSON.stringify(error)
270
- );
263
+ } catch (error2) {
264
+ logger_default.error(identifier, "Stream error: Azure OpenAI JSON parsing error:", error2);
271
265
  }
272
266
  response = await fetch(endpoint, {
273
267
  method: "POST",
@@ -282,10 +276,10 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
282
276
  signal: controller.signal
283
277
  });
284
278
  } else {
285
- console.log(identifier, "Using OpenAI service", openAiPayload.model);
279
+ logger_default.log(identifier, "Using OpenAI service", openAiPayload.model);
286
280
  const endpoint = `https://api.openai.com/v1/chat/completions`;
287
281
  if (openAiConfig.orgId) {
288
- console.log(identifier, "Using orgId", openAiConfig.orgId);
282
+ logger_default.log(identifier, "Using orgId", openAiConfig.orgId);
289
283
  }
290
284
  response = await fetch(endpoint, {
291
285
  method: "POST",
@@ -312,11 +306,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
312
306
  const startAbortTimeout = () => {
313
307
  abortTimeout && clearTimeout(abortTimeout);
314
308
  return setTimeout(() => {
315
- console.log(
316
- identifier,
317
- `Stream error: aborted due to timeout after ${chunkTimeoutMs} ms.`,
318
- JSON.stringify({ paragraph })
319
- );
309
+ logger_default.error(identifier, `Stream timeout after ${chunkTimeoutMs}ms`);
320
310
  controller.abort();
321
311
  }, chunkTimeoutMs);
322
312
  };
@@ -327,11 +317,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
327
317
  const { done, value } = await reader.read();
328
318
  clearTimeout(abortTimeout2);
329
319
  if (done) {
330
- console.log(
331
- identifier,
332
- `Stream error: ended after ${chunkIndex + 1} chunks via reader done flag.`,
333
- rawStreamedBody
334
- );
320
+ logger_default.error(identifier, `Stream ended prematurely after ${chunkIndex + 1} chunks`);
335
321
  throw new Error("Stream error: ended prematurely");
336
322
  }
337
323
  let chunk = new TextDecoder().decode(value);
@@ -346,10 +332,6 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
346
332
  continue;
347
333
  }
348
334
  if (jsonString.includes("[DONE]")) {
349
- console.log(
350
- identifier,
351
- `Stream explicitly marked as done after ${chunkIndex + 1} chunks.`
352
- );
353
335
  try {
354
336
  return parseStreamedResponse(
355
337
  identifier,
@@ -358,40 +340,29 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
358
340
  functionCallArgs,
359
341
  functionNames
360
342
  );
361
- } catch (error) {
362
- console.error(
363
- identifier,
364
- "Stream error: parsing response:",
365
- rawStreamedBody
366
- );
367
- throw error;
343
+ } catch (error2) {
344
+ logger_default.error(identifier, "Stream error: parsing response");
345
+ throw error2;
368
346
  }
369
347
  }
370
348
  let json;
371
349
  try {
372
350
  json = JSON.parse(jsonString.trim());
373
- } catch (error) {
351
+ } catch (error2) {
374
352
  partialChunk = jsonString;
375
353
  continue;
376
354
  }
377
355
  if (!json.choices || !json.choices.length) {
378
356
  if (json.error) {
379
- console.error(
380
- identifier,
381
- "Stream error: OpenAI error:",
382
- json.error && JSON.stringify(json.error)
383
- );
384
- const error = new Error("Stream error: OpenAI error");
385
- error.data = json.error;
386
- error.requestBody = truncatePayload(openAiPayload);
387
- throw error;
357
+ logger_default.error(identifier, "Stream error: OpenAI error:", json.error);
358
+ const error2 = new Error("Stream error: OpenAI error");
359
+ error2.data = json.error;
360
+ error2.requestBody = truncatePayload(openAiPayload);
361
+ throw error2;
362
+ }
363
+ if (chunkIndex !== 0) {
364
+ logger_default.error(identifier, "Stream error: no choices in JSON:", json);
388
365
  }
389
- if (chunkIndex !== 0)
390
- console.error(
391
- identifier,
392
- "Stream error: no choices in JSON:",
393
- json
394
- );
395
366
  continue;
396
367
  }
397
368
  const dToolCall = (_d = (_c = (_b = (_a = json.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.delta) == null ? void 0 : _c.tool_calls) == null ? void 0 : _d[0];
@@ -426,7 +397,7 @@ async function callOpenAI(identifier, openAiPayload, openAiConfig) {
426
397
  }
427
398
  let response;
428
399
  if (openAiConfig.service === "azure") {
429
- console.log(identifier, "Using Azure OpenAI service", openAiPayload.model);
400
+ logger_default.log(identifier, "Using Azure OpenAI service", openAiPayload.model);
430
401
  const model = openAiPayload.model;
431
402
  if (!openAiConfig.modelConfigMap) {
432
403
  throw new Error(
@@ -440,20 +411,16 @@ async function callOpenAI(identifier, openAiPayload, openAiConfig) {
440
411
  } else {
441
412
  throw new Error("Azure OpenAI endpoint is required in modelConfigMap.");
442
413
  }
443
- console.log(identifier, "Using endpoint", endpoint);
414
+ logger_default.log(identifier, "Using endpoint", endpoint);
444
415
  try {
445
416
  const stringifiedPayload = JSON.stringify({
446
417
  ...openAiPayload,
447
418
  stream: false
448
419
  });
449
420
  const parsedPayload = JSON.parse(stringifiedPayload);
450
- } catch (error) {
451
- console.error(
452
- identifier,
453
- "OpenAI JSON parsing error:",
454
- JSON.stringify(error)
455
- );
456
- throw error;
421
+ } catch (error2) {
422
+ logger_default.error(identifier, "OpenAI JSON parsing error:", error2);
423
+ throw error2;
457
424
  }
458
425
  response = await fetch(endpoint, {
459
426
  method: "POST",
@@ -467,10 +434,10 @@ async function callOpenAI(identifier, openAiPayload, openAiConfig) {
467
434
  })
468
435
  });
469
436
  } else {
470
- console.log(identifier, "Using OpenAI service", openAiPayload.model);
437
+ logger_default.log(identifier, "Using OpenAI service", openAiPayload.model);
471
438
  const endpoint = `https://api.openai.com/v1/chat/completions`;
472
439
  if (openAiConfig.orgId) {
473
- console.log(identifier, "Using orgId", openAiConfig.orgId);
440
+ logger_default.log(identifier, "Using orgId", openAiConfig.orgId);
474
441
  }
475
442
  response = await fetch(endpoint, {
476
443
  method: "POST",
@@ -487,13 +454,13 @@ async function callOpenAI(identifier, openAiPayload, openAiConfig) {
487
454
  }
488
455
  if (!response.ok) {
489
456
  const errorData = await response.json();
490
- console.error(identifier, "OpenAI API error:", JSON.stringify(errorData));
457
+ logger_default.error(identifier, "OpenAI API error:", errorData);
491
458
  throw new Error(`OpenAI API Error: ${errorData.error.message}`);
492
459
  }
493
460
  const data = await response.json();
494
461
  if (!data.choices || !data.choices.length) {
495
462
  if (data.error) {
496
- console.error(identifier, "OpenAI error:", JSON.stringify(data.error));
463
+ logger_default.error(identifier, "OpenAI error:", data.error);
497
464
  throw new Error("OpenAI error: " + data.error.message);
498
465
  }
499
466
  throw new Error("OpenAI error: No choices returned.");
@@ -534,29 +501,28 @@ function truncatePayload(payload) {
534
501
  }
535
502
  async function callAnthropicWithRetries(identifier, AiPayload, AiConfig, attempts = 5) {
536
503
  var _a, _b, _c, _d;
537
- console.log(identifier, "Calling Anthropic API with retries");
504
+ logger_default.log(identifier, "Calling Anthropic API with retries");
538
505
  let lastResponse;
539
506
  for (let i = 0; i < attempts; i++) {
540
507
  try {
541
508
  lastResponse = await callAnthropic(identifier, AiPayload, AiConfig);
542
509
  return lastResponse;
543
510
  } catch (e) {
544
- console.error(e);
545
- console.error(
511
+ logger_default.error(
546
512
  identifier,
547
- `Retrying due to error: received bad response from Anthropic API: ${e.message}`,
548
- JSON.stringify((_a = e.response) == null ? void 0 : _a.data)
513
+ `Retry #${i} error: ${e.message}`,
514
+ ((_a = e.response) == null ? void 0 : _a.data) || e
549
515
  );
550
516
  if (((_d = (_c = (_b = e.response) == null ? void 0 : _b.data) == null ? void 0 : _c.error) == null ? void 0 : _d.type) === "rate_limit_error") {
551
517
  }
552
518
  await timeout(125 * i);
553
519
  }
554
520
  }
555
- const error = new Error(
521
+ const error2 = new Error(
556
522
  `Failed to call Anthropic API after ${attempts} attempts`
557
523
  );
558
- error.response = lastResponse;
559
- throw error;
524
+ error2.response = lastResponse;
525
+ throw error2;
560
526
  }
561
527
  async function callAnthropic(identifier, AiPayload, AiConfig) {
562
528
  var _a, _b;
@@ -615,14 +581,14 @@ async function callAnthropic(identifier, AiPayload, AiConfig) {
615
581
  }
616
582
  const answers = data.content;
617
583
  if (!answers[0]) {
618
- console.error(identifier, "Missing answer in Anthropic API:", data);
584
+ logger_default.error(identifier, "Missing answer in Anthropic API:", data);
619
585
  throw new Error("Missing answer in Anthropic API");
620
586
  }
621
587
  let textResponse = "";
622
588
  let functionCalls = [];
623
589
  for (const answer of answers) {
624
590
  if (!answer.type) {
625
- console.error(identifier, "Missing answer type in Anthropic API:", data);
591
+ logger_default.error(identifier, "Missing answer type in Anthropic API:", data);
626
592
  throw new Error("Missing answer type in Anthropic API");
627
593
  }
628
594
  let text = "";
@@ -633,7 +599,7 @@ async function callAnthropic(identifier, AiPayload, AiConfig) {
633
599
  /<thinking>|<\/thinking>|<answer>|<\/answer>/gs,
634
600
  ""
635
601
  );
636
- console.log("No text in answer, returning text within tags:", text);
602
+ logger_default.log(identifier, "No text in answer, returning text within tags:", text);
637
603
  }
638
604
  if (textResponse) {
639
605
  textResponse += `
@@ -651,11 +617,7 @@ ${text}`;
651
617
  }
652
618
  }
653
619
  if (!textResponse && !functionCalls.length) {
654
- console.error(
655
- identifier,
656
- "Missing text & fns in Anthropic API response:",
657
- JSON.stringify(data)
658
- );
620
+ logger_default.error(identifier, "Missing text & fns in Anthropic API response:", data);
659
621
  throw new Error("Missing text & fns in Anthropic API response");
660
622
  }
661
623
  return {
@@ -765,9 +727,7 @@ async function prepareGoogleAIPayload(payload) {
765
727
  }
766
728
  for (const file of message.files || []) {
767
729
  if (!((_a = file.mimeType) == null ? void 0 : _a.startsWith("image"))) {
768
- console.warn(
769
- "Google AI API does not support non-image file types. Skipping file."
770
- );
730
+ logger_default.warn("payload", "Google AI API does not support non-image file types. Skipping file.");
771
731
  continue;
772
732
  }
773
733
  if (file.url) {
@@ -805,9 +765,8 @@ async function prepareGoogleAIPayload(payload) {
805
765
  }
806
766
  async function callGoogleAI(identifier, payload) {
807
767
  var _a, _b, _c;
808
- console.log(identifier, "Calling Google AI API");
768
+ logger_default.log(identifier, "Calling Google AI API");
809
769
  const googleMessages = jigGoogleMessages(payload.messages);
810
- console.log(identifier, "Google AI API messages:", googleMessages);
811
770
  const history = googleMessages.slice(0, -1);
812
771
  const lastMessage = googleMessages.slice(-1)[0];
813
772
  const genAI = new import_genai.GoogleGenAI({
@@ -850,11 +809,7 @@ async function callGoogleAI(identifier, payload) {
850
809
  };
851
810
  });
852
811
  if (!text && !(parsedFunctionCalls == null ? void 0 : parsedFunctionCalls.length) && !files.length) {
853
- console.error(
854
- identifier,
855
- "Missing text & fns in Google AI API response:",
856
- response
857
- );
812
+ logger_default.error(identifier, "Missing text & fns in Google AI API response:", response);
858
813
  throw new Error("Missing text & fns in Google AI API response");
859
814
  }
860
815
  return {
@@ -865,32 +820,26 @@ async function callGoogleAI(identifier, payload) {
865
820
  };
866
821
  }
867
822
  async function callGoogleAIWithRetries(identifier, payload, retries = 5) {
868
- console.log(identifier, "Calling Google AI API with retries");
823
+ logger_default.log(identifier, "Calling Google AI API with retries");
869
824
  let lastError;
870
825
  for (let i = 0; i < retries; i++) {
871
826
  try {
872
827
  return await callGoogleAI(identifier, payload);
873
828
  } catch (e) {
874
829
  lastError = e;
875
- console.error(e);
876
- console.error(
877
- identifier,
878
- `Retrying due to error: received bad response from Google AI API: ${e.message}`,
879
- JSON.stringify(e)
880
- // Google AI errors might not have a response.data structure like others
881
- );
830
+ logger_default.error(identifier, `Retry #${i} error: ${e.message}`, e);
882
831
  await timeout(125 * i);
883
832
  }
884
833
  }
885
- const error = new Error(
834
+ const error2 = new Error(
886
835
  `Failed to call Google AI API after ${retries} attempts`
887
836
  );
888
- error.cause = lastError;
889
- throw error;
837
+ error2.cause = lastError;
838
+ throw error2;
890
839
  }
891
840
  async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) {
892
841
  if (isAnthropicPayload(aiPayload)) {
893
- console.log(identifier, "Delegating call to Anthropic API");
842
+ logger_default.log(identifier, "Delegating call to Anthropic API");
894
843
  return await callAnthropicWithRetries(
895
844
  identifier,
896
845
  await prepareAnthropicPayload(aiPayload),
@@ -898,7 +847,7 @@ async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chu
898
847
  retries
899
848
  );
900
849
  } else if (isOpenAiPayload(aiPayload)) {
901
- console.log(identifier, "Delegating call to OpenAI API");
850
+ logger_default.log(identifier, "Delegating call to OpenAI API");
902
851
  return await callOpenAiWithRetries(
903
852
  identifier,
904
853
  await prepareOpenAIPayload(aiPayload),
@@ -907,13 +856,13 @@ async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chu
907
856
  chunkTimeoutMs
908
857
  );
909
858
  } else if (isGroqPayload(aiPayload)) {
910
- console.log(identifier, "Delegating call to Groq API");
859
+ logger_default.log(identifier, "Delegating call to Groq API");
911
860
  return await callGroqWithRetries(
912
861
  identifier,
913
862
  await prepareGroqPayload(aiPayload)
914
863
  );
915
864
  } else if (isGoogleAIPayload(aiPayload)) {
916
- console.log(identifier, "Delegating call to Google AI API");
865
+ logger_default.log(identifier, "Delegating call to Google AI API");
917
866
  return await callGoogleAIWithRetries(
918
867
  identifier,
919
868
  await prepareGoogleAIPayload(aiPayload),
@@ -948,9 +897,7 @@ async function prepareAnthropicPayload(payload) {
948
897
  }
949
898
  for (const file of message.files || []) {
950
899
  if (!((_a = file.mimeType) == null ? void 0 : _a.startsWith("image"))) {
951
- console.warn(
952
- "Anthropic API does not support non-image file types. Skipping file."
953
- );
900
+ logger_default.warn("payload", "Anthropic API does not support non-image file types. Skipping file.");
954
901
  continue;
955
902
  }
956
903
  if (file.url) {
@@ -1040,10 +987,7 @@ async function prepareOpenAIPayload(payload) {
1040
987
  });
1041
988
  }
1042
989
  } else {
1043
- console.warn(
1044
- "Skipping file in message. File or image type not supported by OpenAI API:",
1045
- file.mimeType
1046
- );
990
+ logger_default.warn("payload", "Skipping file in message. File or image type not supported by OpenAI API:", file.mimeType);
1047
991
  }
1048
992
  }
1049
993
  preparedPayload.messages.push({
@@ -1095,7 +1039,7 @@ async function callGroq(identifier, payload) {
1095
1039
  const data = response.data;
1096
1040
  const answer = data.choices[0].message;
1097
1041
  if (!answer) {
1098
- console.error(identifier, "Missing answer in Groq API:", data);
1042
+ logger_default.error(identifier, "Missing answer in Groq API:", data);
1099
1043
  throw new Error("Missing answer in Groq API");
1100
1044
  }
1101
1045
  const textResponse = answer.content || null;
@@ -1116,30 +1060,24 @@ async function callGroq(identifier, payload) {
1116
1060
  }
1117
1061
  async function callGroqWithRetries(identifier, payload, retries = 5) {
1118
1062
  var _a;
1119
- console.log(identifier, "Calling Groq API with retries");
1063
+ logger_default.log(identifier, "Calling Groq API with retries");
1120
1064
  let lastResponse;
1121
1065
  for (let i = 0; i < retries; i++) {
1122
1066
  try {
1123
1067
  lastResponse = await callGroq(identifier, payload);
1124
1068
  return lastResponse;
1125
1069
  } catch (e) {
1126
- console.error(e);
1127
- console.error(
1128
- identifier,
1129
- `Retrying due to error: received bad response from Groq API: ${e.message}`,
1130
- JSON.stringify((_a = e.response) == null ? void 0 : _a.data)
1131
- );
1070
+ logger_default.error(identifier, `Retry #${i} error: ${e.message}`, ((_a = e.response) == null ? void 0 : _a.data) || e);
1132
1071
  await timeout(125 * i);
1133
1072
  }
1134
1073
  }
1135
- const error = new Error(
1074
+ const error2 = new Error(
1136
1075
  `Failed to call Groq API after ${retries} attempts`
1137
1076
  );
1138
- error.response = lastResponse;
1139
- throw error;
1077
+ error2.response = lastResponse;
1078
+ throw error2;
1140
1079
  }
1141
1080
  async function getNormalizedBase64PNG(url, mime) {
1142
- console.log("Normalizing image", url);
1143
1081
  const response = await import_axios.default.get(url, { responseType: "arraybuffer" });
1144
1082
  let imageBuffer = Buffer.from(response.data);
1145
1083
  let sharpOptions = {};