190proof 1.0.68 → 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.mjs CHANGED
@@ -15,6 +15,7 @@ var ClaudeModel = /* @__PURE__ */ ((ClaudeModel2) => {
15
15
  ClaudeModel2["SONNET_4"] = "claude-sonnet-4-20250514";
16
16
  ClaudeModel2["OPUS_4"] = "claude-opus-4-20250514";
17
17
  ClaudeModel2["SONNET_4_5"] = "claude-sonnet-4-5";
18
+ ClaudeModel2["OPUS_4_5"] = "claude-opus-4-5";
18
19
  return ClaudeModel2;
19
20
  })(ClaudeModel || {});
20
21
  var GPTModel = /* @__PURE__ */ ((GPTModel2) => {
@@ -49,9 +50,29 @@ var GeminiModel = /* @__PURE__ */ ((GeminiModel2) => {
49
50
  GeminiModel2["GEMINI_2_0_FLASH_THINKING_EXP"] = "gemini-2.0-flash-thinking-exp";
50
51
  GeminiModel2["GEMINI_2_0_FLASH_THINKING_EXP_01_21"] = "gemini-2.0-flash-thinking-exp-01-21";
51
52
  GeminiModel2["GEMINI_2_5_FLASH_PREVIEW_04_17"] = "gemini-2.5-flash-preview-04-17";
53
+ GeminiModel2["GEMINI_3_FLASH_PREVIEW"] = "gemini-3-flash-preview";
52
54
  return GeminiModel2;
53
55
  })(GeminiModel || {});
54
56
 
57
+ // logger.ts
58
+ function formatMessage(level, identifier, message) {
59
+ return `[${level}] [${identifier}] ${message}`;
60
+ }
61
+ function log(identifier, message, ...args) {
62
+ console.log(formatMessage("LOG", identifier, message), ...args);
63
+ }
64
+ function warn(identifier, message, ...args) {
65
+ console.warn(formatMessage("WARN", identifier, message), ...args);
66
+ }
67
+ function error(identifier, message, ...args) {
68
+ console.error(formatMessage("ERROR", identifier, message), ...args);
69
+ }
70
+ var logger_default = {
71
+ log,
72
+ warn,
73
+ error
74
+ };
75
+
55
76
  // index.ts
56
77
  import {
57
78
  BedrockRuntimeClient,
@@ -87,13 +108,13 @@ function parseStreamedResponse(identifier, paragraph, functionCallName, function
87
108
  name: functionCallName,
88
109
  arguments: JSON.parse(functionCallArgs)
89
110
  };
90
- } catch (error) {
91
- console.error("Error parsing functionCallArgs:", functionCallArgs);
92
- throw error;
111
+ } catch (error2) {
112
+ logger_default.error(identifier, "Error parsing functionCallArgs:", functionCallArgs);
113
+ throw error2;
93
114
  }
94
115
  }
95
116
  if (!paragraph && !functionCall) {
96
- console.error(
117
+ logger_default.error(
97
118
  identifier,
98
119
  "Stream error: received message without content or function_call, raw:",
99
120
  JSON.stringify({ paragraph, functionCallName, functionCallArgs })
@@ -111,7 +132,7 @@ function parseStreamedResponse(identifier, paragraph, functionCallName, function
111
132
  }
112
133
  async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, retries = 5, chunkTimeoutMs = 15e3) {
113
134
  var _a, _b;
114
- console.log(
135
+ logger_default.log(
115
136
  identifier,
116
137
  "Calling OpenAI API with retries:",
117
138
  openAiConfig == null ? void 0 : openAiConfig.service,
@@ -131,27 +152,15 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
131
152
  chunkTimeoutMs
132
153
  );
133
154
  }
134
- } catch (error) {
135
- console.error(error);
136
- console.error(
155
+ } catch (error2) {
156
+ logger_default.error(
137
157
  identifier,
138
- `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)}`
158
+ `Retry #${i} error: ${error2.message}`,
159
+ ((_a = error2.response) == null ? void 0 : _a.data) || error2.data || error2
139
160
  );
140
- const errorCode = (_b = error.data) == null ? void 0 : _b.code;
141
- if (errorCode) {
142
- console.error(
143
- identifier,
144
- `Retry #${i} failed with API error: ${errorCode}`,
145
- JSON.stringify({
146
- data: error.data
147
- })
148
- );
149
- }
161
+ const errorCode = (_b = error2.data) == null ? void 0 : _b.code;
150
162
  if (errorCode === "content_policy_violation") {
151
- console.log(
152
- identifier,
153
- `Removing images due to content policy violation error`
154
- );
163
+ logger_default.log(identifier, "Removing images due to content policy violation error");
155
164
  openAiPayload.messages.forEach((message) => {
156
165
  if (Array.isArray(message.content)) {
157
166
  message.content = message.content.filter(
@@ -161,34 +170,25 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
161
170
  });
162
171
  }
163
172
  if (i >= 2 && (openAiConfig == null ? void 0 : openAiConfig.service) === "azure" && errorCode === "content_filter") {
164
- console.log(
165
- identifier,
166
- `Switching to OpenAI service due to content filter error`
167
- );
173
+ logger_default.log(identifier, "Switching to OpenAI service due to content filter error");
168
174
  openAiConfig.service = "openai";
169
175
  }
170
176
  if (i === 3) {
171
177
  if ((openAiConfig == null ? void 0 : openAiConfig.service) === "azure") {
172
- console.log(
173
- identifier,
174
- `Switching to OpenAI service due to Azure service error`
175
- );
178
+ logger_default.log(identifier, "Switching to OpenAI service due to Azure service error");
176
179
  openAiConfig.service = "openai";
177
180
  }
178
181
  }
179
182
  if (i === 4) {
180
183
  if (openAiPayload.tools) {
181
- console.log(
182
- identifier,
183
- `Switching to no tool choice due to persistent error`
184
- );
184
+ logger_default.log(identifier, "Switching to no tool choice due to persistent error");
185
185
  openAiPayload.tool_choice = "none";
186
186
  }
187
187
  }
188
188
  await timeout(250);
189
189
  }
190
190
  }
191
- console.error(
191
+ logger_default.error(
192
192
  identifier,
193
193
  `Failed to call OpenAI API after ${retries} attempts. Please lookup OpenAI status for active issues.`,
194
194
  errorObj
@@ -210,7 +210,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
210
210
  let response;
211
211
  const controller = new AbortController();
212
212
  if (openAiConfig.service === "azure") {
213
- console.log(identifier, "Using Azure OpenAI service", openAiPayload.model);
213
+ logger_default.log(identifier, "Using Azure OpenAI service", openAiPayload.model);
214
214
  const model = openAiPayload.model;
215
215
  if (!openAiConfig.modelConfigMap) {
216
216
  throw new Error(
@@ -224,19 +224,15 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
224
224
  } else {
225
225
  throw new Error("Azure OpenAI endpoint is required in modelConfigMap.");
226
226
  }
227
- console.log(identifier, "Using endpoint", endpoint);
227
+ logger_default.log(identifier, "Using endpoint", endpoint);
228
228
  try {
229
229
  const stringifiedPayload = JSON.stringify({
230
230
  ...openAiPayload,
231
231
  stream: true
232
232
  });
233
233
  const parsedPayload = JSON.parse(stringifiedPayload);
234
- } catch (error) {
235
- console.error(
236
- identifier,
237
- "Stream error: Azure OpenAI JSON parsing error:",
238
- JSON.stringify(error)
239
- );
234
+ } catch (error2) {
235
+ logger_default.error(identifier, "Stream error: Azure OpenAI JSON parsing error:", error2);
240
236
  }
241
237
  response = await fetch(endpoint, {
242
238
  method: "POST",
@@ -251,10 +247,10 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
251
247
  signal: controller.signal
252
248
  });
253
249
  } else {
254
- console.log(identifier, "Using OpenAI service", openAiPayload.model);
250
+ logger_default.log(identifier, "Using OpenAI service", openAiPayload.model);
255
251
  const endpoint = `https://api.openai.com/v1/chat/completions`;
256
252
  if (openAiConfig.orgId) {
257
- console.log(identifier, "Using orgId", openAiConfig.orgId);
253
+ logger_default.log(identifier, "Using orgId", openAiConfig.orgId);
258
254
  }
259
255
  response = await fetch(endpoint, {
260
256
  method: "POST",
@@ -281,11 +277,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
281
277
  const startAbortTimeout = () => {
282
278
  abortTimeout && clearTimeout(abortTimeout);
283
279
  return setTimeout(() => {
284
- console.log(
285
- identifier,
286
- `Stream error: aborted due to timeout after ${chunkTimeoutMs} ms.`,
287
- JSON.stringify({ paragraph })
288
- );
280
+ logger_default.error(identifier, `Stream timeout after ${chunkTimeoutMs}ms`);
289
281
  controller.abort();
290
282
  }, chunkTimeoutMs);
291
283
  };
@@ -296,11 +288,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
296
288
  const { done, value } = await reader.read();
297
289
  clearTimeout(abortTimeout2);
298
290
  if (done) {
299
- console.log(
300
- identifier,
301
- `Stream error: ended after ${chunkIndex + 1} chunks via reader done flag.`,
302
- rawStreamedBody
303
- );
291
+ logger_default.error(identifier, `Stream ended prematurely after ${chunkIndex + 1} chunks`);
304
292
  throw new Error("Stream error: ended prematurely");
305
293
  }
306
294
  let chunk = new TextDecoder().decode(value);
@@ -315,10 +303,6 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
315
303
  continue;
316
304
  }
317
305
  if (jsonString.includes("[DONE]")) {
318
- console.log(
319
- identifier,
320
- `Stream explicitly marked as done after ${chunkIndex + 1} chunks.`
321
- );
322
306
  try {
323
307
  return parseStreamedResponse(
324
308
  identifier,
@@ -327,40 +311,29 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
327
311
  functionCallArgs,
328
312
  functionNames
329
313
  );
330
- } catch (error) {
331
- console.error(
332
- identifier,
333
- "Stream error: parsing response:",
334
- rawStreamedBody
335
- );
336
- throw error;
314
+ } catch (error2) {
315
+ logger_default.error(identifier, "Stream error: parsing response");
316
+ throw error2;
337
317
  }
338
318
  }
339
319
  let json;
340
320
  try {
341
321
  json = JSON.parse(jsonString.trim());
342
- } catch (error) {
322
+ } catch (error2) {
343
323
  partialChunk = jsonString;
344
324
  continue;
345
325
  }
346
326
  if (!json.choices || !json.choices.length) {
347
327
  if (json.error) {
348
- console.error(
349
- identifier,
350
- "Stream error: OpenAI error:",
351
- json.error && JSON.stringify(json.error)
352
- );
353
- const error = new Error("Stream error: OpenAI error");
354
- error.data = json.error;
355
- error.requestBody = truncatePayload(openAiPayload);
356
- throw error;
328
+ logger_default.error(identifier, "Stream error: OpenAI error:", json.error);
329
+ const error2 = new Error("Stream error: OpenAI error");
330
+ error2.data = json.error;
331
+ error2.requestBody = truncatePayload(openAiPayload);
332
+ throw error2;
333
+ }
334
+ if (chunkIndex !== 0) {
335
+ logger_default.error(identifier, "Stream error: no choices in JSON:", json);
357
336
  }
358
- if (chunkIndex !== 0)
359
- console.error(
360
- identifier,
361
- "Stream error: no choices in JSON:",
362
- json
363
- );
364
337
  continue;
365
338
  }
366
339
  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];
@@ -395,7 +368,7 @@ async function callOpenAI(identifier, openAiPayload, openAiConfig) {
395
368
  }
396
369
  let response;
397
370
  if (openAiConfig.service === "azure") {
398
- console.log(identifier, "Using Azure OpenAI service", openAiPayload.model);
371
+ logger_default.log(identifier, "Using Azure OpenAI service", openAiPayload.model);
399
372
  const model = openAiPayload.model;
400
373
  if (!openAiConfig.modelConfigMap) {
401
374
  throw new Error(
@@ -409,20 +382,16 @@ async function callOpenAI(identifier, openAiPayload, openAiConfig) {
409
382
  } else {
410
383
  throw new Error("Azure OpenAI endpoint is required in modelConfigMap.");
411
384
  }
412
- console.log(identifier, "Using endpoint", endpoint);
385
+ logger_default.log(identifier, "Using endpoint", endpoint);
413
386
  try {
414
387
  const stringifiedPayload = JSON.stringify({
415
388
  ...openAiPayload,
416
389
  stream: false
417
390
  });
418
391
  const parsedPayload = JSON.parse(stringifiedPayload);
419
- } catch (error) {
420
- console.error(
421
- identifier,
422
- "OpenAI JSON parsing error:",
423
- JSON.stringify(error)
424
- );
425
- throw error;
392
+ } catch (error2) {
393
+ logger_default.error(identifier, "OpenAI JSON parsing error:", error2);
394
+ throw error2;
426
395
  }
427
396
  response = await fetch(endpoint, {
428
397
  method: "POST",
@@ -436,10 +405,10 @@ async function callOpenAI(identifier, openAiPayload, openAiConfig) {
436
405
  })
437
406
  });
438
407
  } else {
439
- console.log(identifier, "Using OpenAI service", openAiPayload.model);
408
+ logger_default.log(identifier, "Using OpenAI service", openAiPayload.model);
440
409
  const endpoint = `https://api.openai.com/v1/chat/completions`;
441
410
  if (openAiConfig.orgId) {
442
- console.log(identifier, "Using orgId", openAiConfig.orgId);
411
+ logger_default.log(identifier, "Using orgId", openAiConfig.orgId);
443
412
  }
444
413
  response = await fetch(endpoint, {
445
414
  method: "POST",
@@ -456,13 +425,13 @@ async function callOpenAI(identifier, openAiPayload, openAiConfig) {
456
425
  }
457
426
  if (!response.ok) {
458
427
  const errorData = await response.json();
459
- console.error(identifier, "OpenAI API error:", JSON.stringify(errorData));
428
+ logger_default.error(identifier, "OpenAI API error:", errorData);
460
429
  throw new Error(`OpenAI API Error: ${errorData.error.message}`);
461
430
  }
462
431
  const data = await response.json();
463
432
  if (!data.choices || !data.choices.length) {
464
433
  if (data.error) {
465
- console.error(identifier, "OpenAI error:", JSON.stringify(data.error));
434
+ logger_default.error(identifier, "OpenAI error:", data.error);
466
435
  throw new Error("OpenAI error: " + data.error.message);
467
436
  }
468
437
  throw new Error("OpenAI error: No choices returned.");
@@ -503,29 +472,28 @@ function truncatePayload(payload) {
503
472
  }
504
473
  async function callAnthropicWithRetries(identifier, AiPayload, AiConfig, attempts = 5) {
505
474
  var _a, _b, _c, _d;
506
- console.log(identifier, "Calling Anthropic API with retries");
475
+ logger_default.log(identifier, "Calling Anthropic API with retries");
507
476
  let lastResponse;
508
477
  for (let i = 0; i < attempts; i++) {
509
478
  try {
510
479
  lastResponse = await callAnthropic(identifier, AiPayload, AiConfig);
511
480
  return lastResponse;
512
481
  } catch (e) {
513
- console.error(e);
514
- console.error(
482
+ logger_default.error(
515
483
  identifier,
516
- `Retrying due to error: received bad response from Anthropic API: ${e.message}`,
517
- JSON.stringify((_a = e.response) == null ? void 0 : _a.data)
484
+ `Retry #${i} error: ${e.message}`,
485
+ ((_a = e.response) == null ? void 0 : _a.data) || e
518
486
  );
519
487
  if (((_d = (_c = (_b = e.response) == null ? void 0 : _b.data) == null ? void 0 : _c.error) == null ? void 0 : _d.type) === "rate_limit_error") {
520
488
  }
521
489
  await timeout(125 * i);
522
490
  }
523
491
  }
524
- const error = new Error(
492
+ const error2 = new Error(
525
493
  `Failed to call Anthropic API after ${attempts} attempts`
526
494
  );
527
- error.response = lastResponse;
528
- throw error;
495
+ error2.response = lastResponse;
496
+ throw error2;
529
497
  }
530
498
  async function callAnthropic(identifier, AiPayload, AiConfig) {
531
499
  var _a, _b;
@@ -584,14 +552,14 @@ async function callAnthropic(identifier, AiPayload, AiConfig) {
584
552
  }
585
553
  const answers = data.content;
586
554
  if (!answers[0]) {
587
- console.error(identifier, "Missing answer in Anthropic API:", data);
555
+ logger_default.error(identifier, "Missing answer in Anthropic API:", data);
588
556
  throw new Error("Missing answer in Anthropic API");
589
557
  }
590
558
  let textResponse = "";
591
559
  let functionCalls = [];
592
560
  for (const answer of answers) {
593
561
  if (!answer.type) {
594
- console.error(identifier, "Missing answer type in Anthropic API:", data);
562
+ logger_default.error(identifier, "Missing answer type in Anthropic API:", data);
595
563
  throw new Error("Missing answer type in Anthropic API");
596
564
  }
597
565
  let text = "";
@@ -602,7 +570,7 @@ async function callAnthropic(identifier, AiPayload, AiConfig) {
602
570
  /<thinking>|<\/thinking>|<answer>|<\/answer>/gs,
603
571
  ""
604
572
  );
605
- console.log("No text in answer, returning text within tags:", text);
573
+ logger_default.log(identifier, "No text in answer, returning text within tags:", text);
606
574
  }
607
575
  if (textResponse) {
608
576
  textResponse += `
@@ -620,11 +588,7 @@ ${text}`;
620
588
  }
621
589
  }
622
590
  if (!textResponse && !functionCalls.length) {
623
- console.error(
624
- identifier,
625
- "Missing text & fns in Anthropic API response:",
626
- JSON.stringify(data)
627
- );
591
+ logger_default.error(identifier, "Missing text & fns in Anthropic API response:", data);
628
592
  throw new Error("Missing text & fns in Anthropic API response");
629
593
  }
630
594
  return {
@@ -734,9 +698,7 @@ async function prepareGoogleAIPayload(payload) {
734
698
  }
735
699
  for (const file of message.files || []) {
736
700
  if (!((_a = file.mimeType) == null ? void 0 : _a.startsWith("image"))) {
737
- console.warn(
738
- "Google AI API does not support non-image file types. Skipping file."
739
- );
701
+ logger_default.warn("payload", "Google AI API does not support non-image file types. Skipping file.");
740
702
  continue;
741
703
  }
742
704
  if (file.url) {
@@ -774,9 +736,8 @@ async function prepareGoogleAIPayload(payload) {
774
736
  }
775
737
  async function callGoogleAI(identifier, payload) {
776
738
  var _a, _b, _c;
777
- console.log(identifier, "Calling Google AI API");
739
+ logger_default.log(identifier, "Calling Google AI API");
778
740
  const googleMessages = jigGoogleMessages(payload.messages);
779
- console.log(identifier, "Google AI API messages:", googleMessages);
780
741
  const history = googleMessages.slice(0, -1);
781
742
  const lastMessage = googleMessages.slice(-1)[0];
782
743
  const genAI = new GoogleGenAI({
@@ -819,11 +780,7 @@ async function callGoogleAI(identifier, payload) {
819
780
  };
820
781
  });
821
782
  if (!text && !(parsedFunctionCalls == null ? void 0 : parsedFunctionCalls.length) && !files.length) {
822
- console.error(
823
- identifier,
824
- "Missing text & fns in Google AI API response:",
825
- response
826
- );
783
+ logger_default.error(identifier, "Missing text & fns in Google AI API response:", response);
827
784
  throw new Error("Missing text & fns in Google AI API response");
828
785
  }
829
786
  return {
@@ -834,32 +791,26 @@ async function callGoogleAI(identifier, payload) {
834
791
  };
835
792
  }
836
793
  async function callGoogleAIWithRetries(identifier, payload, retries = 5) {
837
- console.log(identifier, "Calling Google AI API with retries");
794
+ logger_default.log(identifier, "Calling Google AI API with retries");
838
795
  let lastError;
839
796
  for (let i = 0; i < retries; i++) {
840
797
  try {
841
798
  return await callGoogleAI(identifier, payload);
842
799
  } catch (e) {
843
800
  lastError = e;
844
- console.error(e);
845
- console.error(
846
- identifier,
847
- `Retrying due to error: received bad response from Google AI API: ${e.message}`,
848
- JSON.stringify(e)
849
- // Google AI errors might not have a response.data structure like others
850
- );
801
+ logger_default.error(identifier, `Retry #${i} error: ${e.message}`, e);
851
802
  await timeout(125 * i);
852
803
  }
853
804
  }
854
- const error = new Error(
805
+ const error2 = new Error(
855
806
  `Failed to call Google AI API after ${retries} attempts`
856
807
  );
857
- error.cause = lastError;
858
- throw error;
808
+ error2.cause = lastError;
809
+ throw error2;
859
810
  }
860
811
  async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chunkTimeoutMs = 15e3) {
861
812
  if (isAnthropicPayload(aiPayload)) {
862
- console.log(identifier, "Delegating call to Anthropic API");
813
+ logger_default.log(identifier, "Delegating call to Anthropic API");
863
814
  return await callAnthropicWithRetries(
864
815
  identifier,
865
816
  await prepareAnthropicPayload(aiPayload),
@@ -867,7 +818,7 @@ async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chu
867
818
  retries
868
819
  );
869
820
  } else if (isOpenAiPayload(aiPayload)) {
870
- console.log(identifier, "Delegating call to OpenAI API");
821
+ logger_default.log(identifier, "Delegating call to OpenAI API");
871
822
  return await callOpenAiWithRetries(
872
823
  identifier,
873
824
  await prepareOpenAIPayload(aiPayload),
@@ -876,13 +827,13 @@ async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chu
876
827
  chunkTimeoutMs
877
828
  );
878
829
  } else if (isGroqPayload(aiPayload)) {
879
- console.log(identifier, "Delegating call to Groq API");
830
+ logger_default.log(identifier, "Delegating call to Groq API");
880
831
  return await callGroqWithRetries(
881
832
  identifier,
882
833
  await prepareGroqPayload(aiPayload)
883
834
  );
884
835
  } else if (isGoogleAIPayload(aiPayload)) {
885
- console.log(identifier, "Delegating call to Google AI API");
836
+ logger_default.log(identifier, "Delegating call to Google AI API");
886
837
  return await callGoogleAIWithRetries(
887
838
  identifier,
888
839
  await prepareGoogleAIPayload(aiPayload),
@@ -917,9 +868,7 @@ async function prepareAnthropicPayload(payload) {
917
868
  }
918
869
  for (const file of message.files || []) {
919
870
  if (!((_a = file.mimeType) == null ? void 0 : _a.startsWith("image"))) {
920
- console.warn(
921
- "Anthropic API does not support non-image file types. Skipping file."
922
- );
871
+ logger_default.warn("payload", "Anthropic API does not support non-image file types. Skipping file.");
923
872
  continue;
924
873
  }
925
874
  if (file.url) {
@@ -1009,10 +958,7 @@ async function prepareOpenAIPayload(payload) {
1009
958
  });
1010
959
  }
1011
960
  } else {
1012
- console.warn(
1013
- "Skipping file in message. File or image type not supported by OpenAI API:",
1014
- file.mimeType
1015
- );
961
+ logger_default.warn("payload", "Skipping file in message. File or image type not supported by OpenAI API:", file.mimeType);
1016
962
  }
1017
963
  }
1018
964
  preparedPayload.messages.push({
@@ -1064,7 +1010,7 @@ async function callGroq(identifier, payload) {
1064
1010
  const data = response.data;
1065
1011
  const answer = data.choices[0].message;
1066
1012
  if (!answer) {
1067
- console.error(identifier, "Missing answer in Groq API:", data);
1013
+ logger_default.error(identifier, "Missing answer in Groq API:", data);
1068
1014
  throw new Error("Missing answer in Groq API");
1069
1015
  }
1070
1016
  const textResponse = answer.content || null;
@@ -1085,30 +1031,24 @@ async function callGroq(identifier, payload) {
1085
1031
  }
1086
1032
  async function callGroqWithRetries(identifier, payload, retries = 5) {
1087
1033
  var _a;
1088
- console.log(identifier, "Calling Groq API with retries");
1034
+ logger_default.log(identifier, "Calling Groq API with retries");
1089
1035
  let lastResponse;
1090
1036
  for (let i = 0; i < retries; i++) {
1091
1037
  try {
1092
1038
  lastResponse = await callGroq(identifier, payload);
1093
1039
  return lastResponse;
1094
1040
  } catch (e) {
1095
- console.error(e);
1096
- console.error(
1097
- identifier,
1098
- `Retrying due to error: received bad response from Groq API: ${e.message}`,
1099
- JSON.stringify((_a = e.response) == null ? void 0 : _a.data)
1100
- );
1041
+ logger_default.error(identifier, `Retry #${i} error: ${e.message}`, ((_a = e.response) == null ? void 0 : _a.data) || e);
1101
1042
  await timeout(125 * i);
1102
1043
  }
1103
1044
  }
1104
- const error = new Error(
1045
+ const error2 = new Error(
1105
1046
  `Failed to call Groq API after ${retries} attempts`
1106
1047
  );
1107
- error.response = lastResponse;
1108
- throw error;
1048
+ error2.response = lastResponse;
1049
+ throw error2;
1109
1050
  }
1110
1051
  async function getNormalizedBase64PNG(url, mime) {
1111
- console.log("Normalizing image", url);
1112
1052
  const response = await axios.get(url, { responseType: "arraybuffer" });
1113
1053
  let imageBuffer = Buffer.from(response.data);
1114
1054
  let sharpOptions = {};