@ax-llm/ax 11.0.56 → 11.0.58

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/index.js CHANGED
@@ -669,6 +669,46 @@ var ColorLog = class {
669
669
 
670
670
  // ai/debug.ts
671
671
  var colorLog = new ColorLog();
672
+ var defaultOutput = (message) => {
673
+ process.stdout.write(message);
674
+ };
675
+ var createDefaultLogger = (output = defaultOutput) => {
676
+ return (message, options) => {
677
+ const tags = options?.tags ?? [];
678
+ let formattedMessage = message;
679
+ if (tags.includes("error")) {
680
+ formattedMessage = colorLog.red(formattedMessage);
681
+ } else if (tags.includes("success") || tags.includes("responseContent")) {
682
+ formattedMessage = colorLog.greenBright(formattedMessage);
683
+ } else if (tags.includes("functionName")) {
684
+ formattedMessage = colorLog.whiteBright(formattedMessage);
685
+ } else if (tags.includes("functionArg") || tags.includes("systemContent") || tags.includes("assistantContent")) {
686
+ formattedMessage = colorLog.blueBright(formattedMessage);
687
+ } else if (tags.includes("warning") || tags.includes("discovery")) {
688
+ formattedMessage = colorLog.yellow(formattedMessage);
689
+ }
690
+ if (tags.includes("responseStart") || tags.includes("systemStart") || tags.includes("userStart")) {
691
+ formattedMessage = `
692
+ ${formattedMessage}`;
693
+ } else if (tags.includes("responseEnd") || tags.includes("systemEnd") || tags.includes("userEnd")) {
694
+ formattedMessage = `${formattedMessage}
695
+ `;
696
+ } else if (tags.includes("assistantStart")) {
697
+ formattedMessage = `
698
+ ${formattedMessage}
699
+ `;
700
+ } else if (tags.includes("error")) {
701
+ formattedMessage = `
702
+ ${formattedMessage}
703
+ `;
704
+ } else if (tags.includes("functionEnd")) {
705
+ formattedMessage = `${formattedMessage}
706
+ `;
707
+ }
708
+ output(formattedMessage);
709
+ };
710
+ };
711
+ var defaultLogger = createDefaultLogger();
672
712
  var formatChatMessage = (msg, hideContent, hideSystemPrompt) => {
673
713
  switch (msg.role) {
674
714
  case "system":
@@ -676,30 +716,30 @@ var formatChatMessage = (msg, hideContent, hideSystemPrompt) => {
676
716
  return "";
677
717
  }
678
718
  return `
679
- ${colorLog.blueBright("System:")}
680
- ${colorLog.whiteBright(msg.content)}`;
719
+ System:
720
+ ${msg.content}`;
681
721
  case "function":
682
722
  return `
683
- ${colorLog.blueBright("Function Result:")}
684
- ${colorLog.whiteBright(msg.result)}`;
723
+ Function Result:
724
+ ${msg.result}`;
685
725
  case "user": {
686
726
  if (typeof msg.content === "string") {
687
727
  return `
688
- ${colorLog.blueBright("User:")}
689
- ${colorLog.whiteBright(msg.content)}`;
728
+ User:
729
+ ${msg.content}`;
690
730
  }
691
731
  const items = msg.content.map((v) => {
692
732
  switch (v.type) {
693
733
  case "text":
694
- return `${colorLog.whiteBright(v.text)}`;
734
+ return v.text;
695
735
  case "image":
696
- return `(Image, ${v.mimeType}) ${colorLog.whiteBright(v.image.substring(0, 10))}`;
736
+ return `(Image, ${v.mimeType}) ${v.image.substring(0, 10)}`;
697
737
  default:
698
738
  throw new Error("Invalid content type");
699
739
  }
700
740
  });
701
741
  return `
702
- ${colorLog.blueBright("User:")}
742
+ User:
703
743
  ${items.join("\n")}`;
704
744
  }
705
745
  case "assistant": {
@@ -709,62 +749,64 @@ ${items.join("\n")}`;
709
749
  return `${fn.name}(${args})`;
710
750
  });
711
751
  return `
712
- ${colorLog.blueBright("\nFunctions:")}
713
- ${colorLog.whiteBright(fns.join("\n"))}`;
752
+ Functions:
753
+ ${fns.join("\n")}`;
714
754
  }
715
755
  return `
716
- ${colorLog.blueBright("\nAssistant:")}
717
- ${hideContent ? "" : colorLog.whiteBright(msg.content ?? "<empty>")}`;
756
+ Assistant:
757
+ ${hideContent ? "" : msg.content ?? "<empty>"}`;
718
758
  }
719
759
  default:
720
760
  throw new Error("Invalid role");
721
761
  }
722
762
  };
723
- var logChatRequestMessage = (msg, hideSystemPrompt) => {
724
- process.stdout.write(`${formatChatMessage(msg, hideSystemPrompt)}
725
- `);
726
- process.stdout.write(colorLog.blueBright("\nAssistant:\n"));
763
+ var logChatRequestMessage = (msg, hideSystemPrompt, logger = defaultLogger) => {
764
+ const formattedMessage = formatChatMessage(msg, false, hideSystemPrompt);
765
+ if (formattedMessage) {
766
+ const tags = msg.role === "system" ? ["systemStart", "systemContent"] : msg.role === "function" ? ["functionName"] : msg.role === "user" ? ["userStart", "userContent"] : [];
767
+ logger(formattedMessage, { tags });
768
+ }
769
+ logger("Assistant:", { tags: ["assistantStart"] });
727
770
  };
728
- var logChatRequest = (chatPrompt, hideSystemPrompt) => {
729
- const items = chatPrompt?.map(
730
- (msg) => formatChatMessage(msg, hideSystemPrompt)
731
- );
732
- if (items) {
733
- process.stdout.write(items.join("\n"));
734
- process.stdout.write(colorLog.blueBright("\nAssistant:\n"));
771
+ var logChatRequest = (chatPrompt, hideSystemPrompt, logger = defaultLogger) => {
772
+ for (const msg of chatPrompt ?? []) {
773
+ const formattedMessage = formatChatMessage(msg, false, hideSystemPrompt);
774
+ if (formattedMessage) {
775
+ const tags = msg.role === "system" ? ["systemContent"] : msg.role === "function" ? ["functionName"] : msg.role === "user" ? ["userContent"] : [];
776
+ logger(formattedMessage, { tags });
777
+ }
735
778
  }
779
+ logger("Assistant:", { tags: ["assistantStart"] });
736
780
  };
737
- var logResponseResult = (r) => {
781
+ var logResponseResult = (r, logger = defaultLogger) => {
738
782
  if (r.content) {
739
- process.stdout.write(colorLog.greenBright(r.content));
783
+ logger(r.content, { tags: ["responseContent"] });
740
784
  }
741
- if (r.functionCalls) {
785
+ if (r.functionCalls && r.functionCalls.length > 0) {
742
786
  for (const [i, f] of r.functionCalls.entries()) {
743
787
  if (f.function.name) {
744
- if (i > 0) {
745
- process.stdout.write("\n");
746
- }
747
- process.stdout.write(
748
- `Function ${i + 1} -> ${colorLog.greenBright(f.function.name)}`
749
- );
788
+ logger(`[${i + 1}] ${f.function.name}`, {
789
+ tags: ["functionName"]
790
+ });
750
791
  }
751
792
  if (f.function.params) {
752
793
  const params = typeof f.function.params === "string" ? f.function.params : JSON.stringify(f.function.params, null, 2);
753
- process.stdout.write(`${colorLog.greenBright(params)}`);
794
+ logger(params, { tags: ["functionArg"] });
754
795
  }
755
796
  }
797
+ logger("", { tags: ["functionEnd"] });
756
798
  }
757
799
  };
758
- var logResponse = (resp) => {
800
+ var logResponse = (resp, logger = defaultLogger) => {
759
801
  if (!resp.results) {
760
802
  return;
761
803
  }
762
804
  for (const r of resp.results) {
763
- logResponseResult(r);
805
+ logResponseResult(r, logger);
764
806
  }
765
807
  };
766
- var logResponseDelta = (delta) => {
767
- process.stdout.write(colorLog.greenBright(delta));
808
+ var logResponseDelta = (delta, logger = defaultLogger) => {
809
+ logger(delta, { tags: ["responseContent"] });
768
810
  };
769
811
 
770
812
  // ai/base.ts
@@ -778,6 +820,9 @@ var axBaseAIDefaultCreativeConfig = () => structuredClone({
778
820
  topP: 0.7,
779
821
  frequencyPenalty: 0.2
780
822
  });
823
+ var defaultLogger2 = (message, _options) => {
824
+ process.stdout.write(message);
825
+ };
781
826
  var AxBaseAI = class {
782
827
  constructor(aiImpl, {
783
828
  name,
@@ -817,6 +862,7 @@ var AxBaseAI = class {
817
862
  excludeContentFromTrace;
818
863
  models;
819
864
  abortSignal;
865
+ logger = defaultLogger2;
820
866
  modelInfo;
821
867
  modelUsage;
822
868
  embedModelUsage;
@@ -878,6 +924,7 @@ var AxBaseAI = class {
878
924
  this.tracer = options.tracer;
879
925
  this.excludeContentFromTrace = options.excludeContentFromTrace;
880
926
  this.abortSignal = options.abortSignal;
927
+ this.logger = options.logger ?? defaultLogger2;
881
928
  }
882
929
  getOptions() {
883
930
  return {
@@ -887,9 +934,13 @@ var AxBaseAI = class {
887
934
  tracer: this.tracer,
888
935
  timeout: this.timeout,
889
936
  excludeContentFromTrace: this.excludeContentFromTrace,
890
- abortSignal: this.abortSignal
937
+ abortSignal: this.abortSignal,
938
+ logger: this.logger
891
939
  };
892
940
  }
941
+ getLogger() {
942
+ return this.logger;
943
+ }
893
944
  getModelList() {
894
945
  const models = [];
895
946
  for (const model of this.models ?? []) {
@@ -1077,7 +1128,11 @@ var AxBaseAI = class {
1077
1128
  return res2;
1078
1129
  };
1079
1130
  if (debug) {
1080
- logChatRequest(req.chatPrompt, options?.debugHideSystemPrompt);
1131
+ logChatRequest(
1132
+ req.chatPrompt,
1133
+ options?.debugHideSystemPrompt,
1134
+ options?.logger ?? this.logger
1135
+ );
1081
1136
  }
1082
1137
  const rt = options?.rateLimiter ?? this.rt;
1083
1138
  const rv = rt ? await rt(fn, { modelUsage: this.modelUsage }) : await fn();
@@ -1108,13 +1163,14 @@ var AxBaseAI = class {
1108
1163
  setChatResponseEvents(res2, span, this.excludeContentFromTrace);
1109
1164
  }
1110
1165
  if (debug) {
1111
- logResponse(res2);
1166
+ logResponse(res2, options?.logger ?? this.logger);
1112
1167
  }
1113
1168
  return res2;
1114
1169
  };
1115
1170
  const doneCb = async (_values) => {
1116
1171
  if (debug) {
1117
- process.stdout.write("\n");
1172
+ const logger = options?.logger ?? this.logger;
1173
+ logger("", { tags: ["responseEnd"] });
1118
1174
  }
1119
1175
  if (span?.isRecording()) {
1120
1176
  span.end();
@@ -1158,7 +1214,10 @@ var AxBaseAI = class {
1158
1214
  span.end();
1159
1215
  }
1160
1216
  if (debug) {
1161
- logResponse(res);
1217
+ logResponse(res, options?.logger ?? this.logger);
1218
+ }
1219
+ if (debug) {
1220
+ this.logger("", { tags: ["responseEnd"] });
1162
1221
  }
1163
1222
  return res;
1164
1223
  }
@@ -1425,6 +1484,8 @@ var GoogleVertexAuth = class {
1425
1484
 
1426
1485
  // ai/anthropic/types.ts
1427
1486
  var AxAIAnthropicModel = /* @__PURE__ */ ((AxAIAnthropicModel2) => {
1487
+ AxAIAnthropicModel2["Claude4Opus"] = "claude-opus-4-20250514";
1488
+ AxAIAnthropicModel2["Claude4Sonnet"] = "claude-sonnet-4-20250514";
1428
1489
  AxAIAnthropicModel2["Claude37Sonnet"] = "claude-3-7-sonnet-latest";
1429
1490
  AxAIAnthropicModel2["Claude35Sonnet"] = "claude-3-5-sonnet-latest";
1430
1491
  AxAIAnthropicModel2["Claude35Haiku"] = "claude-3-5-haiku-latest";
@@ -1447,50 +1508,80 @@ var AxAIAnthropicVertexModel = /* @__PURE__ */ ((AxAIAnthropicVertexModel2) => {
1447
1508
 
1448
1509
  // ai/anthropic/info.ts
1449
1510
  var axModelInfoAnthropic = [
1450
- // 35
1511
+ // 4
1512
+ {
1513
+ name: "claude-opus-4-20250514" /* Claude4Opus */,
1514
+ currency: "usd",
1515
+ promptTokenCostPer1M: 15,
1516
+ completionTokenCostPer1M: 75,
1517
+ maxTokens: 32e3
1518
+ },
1519
+ {
1520
+ name: "claude-sonnet-4-20250514" /* Claude4Sonnet */,
1521
+ currency: "usd",
1522
+ promptTokenCostPer1M: 3,
1523
+ completionTokenCostPer1M: 15,
1524
+ maxTokens: 64e3
1525
+ },
1526
+ // 3.7
1527
+ {
1528
+ name: "claude-3-7-sonnet-latest" /* Claude37Sonnet */,
1529
+ currency: "usd",
1530
+ promptTokenCostPer1M: 3,
1531
+ completionTokenCostPer1M: 15,
1532
+ maxTokens: 64e3
1533
+ },
1534
+ // 3.5
1451
1535
  {
1452
1536
  name: "claude-3-5-sonnet-latest" /* Claude35Sonnet */,
1453
1537
  currency: "usd",
1454
1538
  promptTokenCostPer1M: 3,
1455
- completionTokenCostPer1M: 15
1539
+ completionTokenCostPer1M: 15,
1540
+ maxTokens: 8192
1456
1541
  },
1457
1542
  {
1458
1543
  name: "claude-3-5-haiku-latest" /* Claude35Haiku */,
1459
1544
  currency: "usd",
1460
1545
  promptTokenCostPer1M: 0.8,
1461
- completionTokenCostPer1M: 4
1546
+ completionTokenCostPer1M: 4,
1547
+ maxTokens: 8192
1462
1548
  },
1463
1549
  // 3
1464
1550
  {
1465
1551
  name: "claude-3-opus-latest" /* Claude3Opus */,
1466
1552
  currency: "usd",
1467
1553
  promptTokenCostPer1M: 15,
1468
- completionTokenCostPer1M: 75
1554
+ completionTokenCostPer1M: 75,
1555
+ maxTokens: 4096
1469
1556
  },
1470
1557
  {
1471
1558
  name: "claude-3-sonnet-20240229" /* Claude3Sonnet */,
1472
1559
  currency: "usd",
1473
1560
  promptTokenCostPer1M: 3,
1474
- completionTokenCostPer1M: 15
1561
+ completionTokenCostPer1M: 15,
1562
+ maxTokens: 4096
1475
1563
  },
1476
1564
  {
1477
1565
  name: "claude-3-haiku-20240307" /* Claude3Haiku */,
1478
1566
  currency: "usd",
1479
1567
  promptTokenCostPer1M: 0.25,
1480
- completionTokenCostPer1M: 1.25
1568
+ completionTokenCostPer1M: 1.25,
1569
+ maxTokens: 4096
1481
1570
  },
1482
- // 21
1571
+ // 2.1
1483
1572
  {
1484
1573
  name: "claude-2.1" /* Claude21 */,
1485
1574
  currency: "usd",
1486
1575
  promptTokenCostPer1M: 8,
1487
- completionTokenCostPer1M: 25
1576
+ completionTokenCostPer1M: 25,
1577
+ maxTokens: 4096
1488
1578
  },
1489
1579
  {
1490
1580
  name: "claude-instant-1.2" /* ClaudeInstant12 */,
1491
1581
  currency: "usd",
1492
1582
  promptTokenCostPer1M: 0.8,
1493
- completionTokenCostPer1M: 2.24
1583
+ completionTokenCostPer1M: 2.24,
1584
+ maxTokens: 4096
1494
1585
  }
1495
1586
  ];
1496
1587
 
@@ -1515,7 +1606,7 @@ var AxAIAnthropicImpl = class {
1515
1606
  getModelConfig() {
1516
1607
  const { config } = this;
1517
1608
  return {
1518
- maxTokens: config.maxTokens,
1609
+ maxTokens: config.maxTokens ?? 4096,
1519
1610
  temperature: config.temperature,
1520
1611
  topP: config.topP,
1521
1612
  topK: config.topK,
@@ -1578,13 +1669,18 @@ var AxAIAnthropicImpl = class {
1578
1669
  input_schema: v.parameters
1579
1670
  })
1580
1671
  );
1672
+ const maxTokens = req.modelConfig?.maxTokens ?? this.config.maxTokens;
1673
+ const stopSequences = req.modelConfig?.stopSequences ?? this.config.stopSequences;
1674
+ const temperature = req.modelConfig?.temperature ?? this.config.temperature;
1675
+ const topP = req.modelConfig?.topP ?? this.config.topP;
1676
+ const topK = req.modelConfig?.topK ?? this.config.topK;
1581
1677
  const reqValue = {
1582
1678
  ...this.isVertex ? { anthropic_version: "vertex-2023-10-16" } : { model },
1583
- max_tokens: req.modelConfig?.maxTokens ?? this.config.maxTokens,
1584
- stop_sequences: req.modelConfig?.stopSequences ?? this.config.stopSequences,
1585
- temperature: req.modelConfig?.temperature ?? this.config.temperature,
1586
- top_p: req.modelConfig?.topP ?? this.config.topP,
1587
- top_k: req.modelConfig?.topK ?? this.config.topK,
1679
+ ...maxTokens ? { max_tokens: maxTokens } : {},
1680
+ ...stopSequences && stopSequences.length > 0 ? { stop_sequences: stopSequences } : {},
1681
+ ...temperature ? { temperature } : {},
1682
+ ...topP ? { top_p: topP } : {},
1683
+ ...topK ? { top_k: topK } : {},
1588
1684
  ...toolsChoice,
1589
1685
  ...tools && tools.length > 0 ? { tools } : {},
1590
1686
  ...stream ? { stream: true } : {},
@@ -5106,6 +5202,9 @@ var AxAI = class {
5106
5202
  getOptions() {
5107
5203
  return this.ai.getOptions();
5108
5204
  }
5205
+ getLogger() {
5206
+ return this.ai.getLogger();
5207
+ }
5109
5208
  };
5110
5209
 
5111
5210
  // ai/x-grok/types.ts
@@ -5329,7 +5428,7 @@ var MemoryImpl = class {
5329
5428
  if (this.options?.debug) {
5330
5429
  if (delta && typeof delta === "string") {
5331
5430
  debugResponseDelta(delta);
5332
- } else if (lastItem) {
5431
+ } else if (!delta && (content || functionCalls)) {
5333
5432
  debugResponse({ content, name, functionCalls });
5334
5433
  }
5335
5434
  }
@@ -6271,7 +6370,6 @@ function formatDescription(str) {
6271
6370
  }
6272
6371
 
6273
6372
  // dsp/validate.ts
6274
- var colorLog4 = new ColorLog();
6275
6373
  var ValidationError = class extends Error {
6276
6374
  fields;
6277
6375
  constructor({
@@ -6312,10 +6410,11 @@ function handleValidationError(mem, errorFields, ai, promptTemplate, sessionId)
6312
6410
  mem.addTag("error");
6313
6411
  if (ai.getOptions().debug) {
6314
6412
  const errors = errorFields.map((field) => `- ${field.title}: ${field.description}`).join("\n");
6315
- process.stdout.write(colorLog4.red(`
6316
- \u274C Error Correction:
6317
- ${errors}
6318
- `));
6413
+ const logger = ai.getLogger();
6414
+ logger(`\u274C Error Correction:
6415
+ ${errors}`, {
6416
+ tags: ["error"]
6417
+ });
6319
6418
  }
6320
6419
  }
6321
6420
 
@@ -6895,7 +6994,6 @@ var validateJSONSchema = (schema) => {
6895
6994
  };
6896
6995
 
6897
6996
  // dsp/functions.ts
6898
- var colorLog5 = new ColorLog();
6899
6997
  var AxFunctionError = class extends Error {
6900
6998
  constructor(fields) {
6901
6999
  super();
@@ -7064,12 +7162,11 @@ var processFunctions = async (ai, functionList, functionCalls, mem, sessionId, t
7064
7162
  );
7065
7163
  mem.addTag("error");
7066
7164
  if (ai.getOptions().debug) {
7067
- process.stdout.write(
7068
- colorLog5.red(`
7069
- \u274C Function Error Correction:
7070
- ${result}
7071
- `)
7072
- );
7165
+ const logger = ai.getLogger();
7166
+ logger(`\u274C Function Error Correction:
7167
+ ${result}`, {
7168
+ tags: ["error"]
7169
+ });
7073
7170
  }
7074
7171
  } else {
7075
7172
  throw e;
@@ -7835,9 +7932,11 @@ var AxGen = class extends AxProgramWithSignature {
7835
7932
  values = {};
7836
7933
  excludeContentFromTrace = false;
7837
7934
  thoughtFieldName;
7935
+ logger;
7838
7936
  constructor(signature, options) {
7839
7937
  super(signature, { description: options?.description });
7840
7938
  this.options = options;
7939
+ this.logger = options?.logger;
7841
7940
  this.thoughtFieldName = options?.thoughtFieldName ?? "thought";
7842
7941
  const promptTemplateOptions = {
7843
7942
  functions: options?.functions,
@@ -8125,6 +8224,10 @@ Content: ${content}`
8125
8224
  xstate
8126
8225
  );
8127
8226
  }
8227
+ if (ai.getOptions().debug) {
8228
+ const logger = ai.getLogger();
8229
+ logger("", { tags: ["responseEnd"] });
8230
+ }
8128
8231
  }
8129
8232
  async processResponse({
8130
8233
  ai,
@@ -8252,7 +8355,8 @@ Content: ${result.content}`
8252
8355
  continue multiStepLoop;
8253
8356
  }
8254
8357
  if (debug) {
8255
- process.stdout.write("\n");
8358
+ const logger = options.logger ?? this.logger ?? ai.getLogger();
8359
+ logger("", { tags: ["responseEnd"] });
8256
8360
  }
8257
8361
  return;
8258
8362
  } catch (e) {
@@ -8443,10 +8547,14 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
8443
8547
  ...pick(parentValues, injectionKeys)
8444
8548
  };
8445
8549
  if (options.debug && injectionKeys.length > 0) {
8446
- process.stdout.write(
8447
- `
8448
- Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`
8449
- );
8550
+ const ai = funcOptions?.ai;
8551
+ if (ai) {
8552
+ const logger = ai.getLogger();
8553
+ logger(
8554
+ `Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`,
8555
+ { tags: ["functionArg"] }
8556
+ );
8557
+ }
8450
8558
  }
8451
8559
  return await originalFunc(updatedChildArgs, funcOptions);
8452
8560
  };
@@ -8555,18 +8663,18 @@ var AxAgent = class {
8555
8663
  }
8556
8664
  const debug = this.getDebug(ai, options);
8557
8665
  if (debug) {
8558
- process.stdout.write(`
8559
- --- Agent Engaged: ${this.name} ---
8560
- `);
8666
+ const logger = ai.getLogger();
8667
+ logger(`\u{1F916} Agent ${this.name} starting...`, {
8668
+ tags: ["assistantStart"]
8669
+ });
8561
8670
  }
8562
8671
  const ret = await boundFunc(ai, values, {
8563
8672
  ...options,
8564
8673
  model
8565
8674
  });
8566
8675
  if (debug) {
8567
- process.stdout.write(`
8568
- --- Agent Done: ${this.name} ---
8569
- `);
8676
+ const logger = ai.getLogger();
8677
+ logger(`\u{1F916} Agent ${this.name} completed.`, { tags: ["assistantEnd"] });
8570
8678
  }
8571
8679
  const sig = this.program.getSignature();
8572
8680
  const outFields = sig.getOutputFields();
@@ -8969,6 +9077,9 @@ var AxBalancer = class _AxBalancer {
8969
9077
  getOptions() {
8970
9078
  return this.currentService.getOptions();
8971
9079
  }
9080
+ getLogger() {
9081
+ return this.currentService.getLogger();
9082
+ }
8972
9083
  };
8973
9084
  function validateModels2(services) {
8974
9085
  const serviceWithModel = services.find(
@@ -11404,6 +11515,11 @@ var AxMockAIService = class {
11404
11515
  getOptions() {
11405
11516
  return this.config.options ?? {};
11406
11517
  }
11518
+ getLogger() {
11519
+ return this.config.options?.logger ?? ((message) => {
11520
+ process.stdout.write(message);
11521
+ });
11522
+ }
11407
11523
  updateMetrics(type) {
11408
11524
  const latency = this.config.latencyMs ?? 0;
11409
11525
  this.metrics.latency[type].samples.push(latency);
@@ -11426,7 +11542,7 @@ var AxMockAIService = class {
11426
11542
  };
11427
11543
 
11428
11544
  // dsp/classifier.ts
11429
- var colorLog6 = new ColorLog();
11545
+ var colorLog4 = new ColorLog();
11430
11546
  var AxSimpleClassifierClass = class {
11431
11547
  name;
11432
11548
  context;
@@ -11488,7 +11604,7 @@ var AxSimpleClassifier = class {
11488
11604
  }
11489
11605
  if (this.debug) {
11490
11606
  console.log(
11491
- colorLog6.whiteBright(`query: ${text}`) + "\n" + colorLog6.greenBright(
11607
+ colorLog4.whiteBright(`query: ${text}`) + "\n" + colorLog4.greenBright(
11492
11608
  JSON.stringify(m.map((m2) => `${m2.id}, ${m2.score}`))
11493
11609
  )
11494
11610
  );
@@ -12979,15 +13095,16 @@ function v4(options, buf, offset) {
12979
13095
  var v4_default = v4;
12980
13096
 
12981
13097
  // mcp/client.ts
12982
- var colorLog7 = new ColorLog();
12983
13098
  var AxMCPClient = class {
12984
13099
  constructor(transport, options = {}) {
12985
13100
  this.transport = transport;
12986
13101
  this.options = options;
13102
+ this.logger = options.logger ?? ((message) => console.log(message));
12987
13103
  }
12988
13104
  functions = [];
12989
13105
  activeRequests = /* @__PURE__ */ new Map();
12990
13106
  capabilities = {};
13107
+ logger;
12991
13108
  async init() {
12992
13109
  if ("connect" in this.transport) {
12993
13110
  await this.transport.connect?.();
@@ -13046,11 +13163,13 @@ var AxMCPClient = class {
13046
13163
  };
13047
13164
  });
13048
13165
  if (this.options.debug) {
13049
- console.log(
13050
- colorLog7.yellow(`> Discovered ${this.functions.length} functions:`)
13051
- );
13166
+ this.logger(`> Discovered ${this.functions.length} functions:`, {
13167
+ tags: ["discovery"]
13168
+ });
13052
13169
  for (const fn of this.functions) {
13053
- console.log(colorLog7.yellow(` - ${fn.name}: ${fn.description}`));
13170
+ this.logger(` - ${fn.name}: ${fn.description}`, {
13171
+ tags: ["discovery"]
13172
+ });
13054
13173
  }
13055
13174
  }
13056
13175
  }
@@ -13093,11 +13212,10 @@ var AxMCPClient = class {
13093
13212
  params
13094
13213
  };
13095
13214
  if (this.options.debug) {
13096
- console.log(
13097
- colorLog7.blueBright(
13098
- `> Sending request ${requestId}:
13099
- ${JSON.stringify(request, null, 2)}`
13100
- )
13215
+ this.logger(
13216
+ `> Sending request ${requestId}:
13217
+ ${JSON.stringify(request, null, 2)}`,
13218
+ { tags: ["requestStart"] }
13101
13219
  );
13102
13220
  }
13103
13221
  const responsePromise = new Promise((resolve, reject) => {
@@ -13105,11 +13223,10 @@ ${JSON.stringify(request, null, 2)}`
13105
13223
  this.transport.send(request).then((res) => {
13106
13224
  this.activeRequests.delete(requestId);
13107
13225
  if (this.options.debug) {
13108
- console.log(
13109
- colorLog7.greenBright(
13110
- `> Received response for request ${requestId}:
13111
- ${JSON.stringify(res, null, 2)}`
13112
- )
13226
+ this.logger(
13227
+ `> Received response for request ${requestId}:
13228
+ ${JSON.stringify(res, null, 2)}`,
13229
+ { tags: ["responseContent"] }
13113
13230
  );
13114
13231
  }
13115
13232
  if (res !== null && typeof res === "object" && "error" in res) {
@@ -13139,9 +13256,9 @@ ${JSON.stringify(res, null, 2)}`
13139
13256
  params
13140
13257
  };
13141
13258
  if (this.options.debug) {
13142
- console.log(
13143
- "\u27A1\uFE0F Sending notification:",
13144
- JSON.stringify(notification, null, 2)
13259
+ this.logger(
13260
+ `\u27A1\uFE0F Sending notification: ${JSON.stringify(notification, null, 2)}`,
13261
+ { tags: ["requestStart"] }
13145
13262
  );
13146
13263
  }
13147
13264
  await this.transport.sendNotification(notification);
@@ -13371,6 +13488,25 @@ var AxMultiServiceRouter = class {
13371
13488
  getOptions() {
13372
13489
  return this.options ?? {};
13373
13490
  }
13491
+ /**
13492
+ * Returns the logger from the last used service,
13493
+ * or falls back to the first service if none has been used.
13494
+ */
13495
+ getLogger() {
13496
+ let serviceInstance = this.lastUsedService;
13497
+ if (!serviceInstance) {
13498
+ const firstServiceEntry = this.services.values().next().value;
13499
+ if (firstServiceEntry) {
13500
+ serviceInstance = firstServiceEntry.service;
13501
+ }
13502
+ }
13503
+ if (!serviceInstance) {
13504
+ return (message) => {
13505
+ process.stdout.write(message);
13506
+ };
13507
+ }
13508
+ return serviceInstance.getLogger();
13509
+ }
13374
13510
  };
13375
13511
 
13376
13512
  // prompts/rag.ts