@ax-llm/ax 11.0.57 → 11.0.59

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 ?? []) {
@@ -985,6 +1036,9 @@ var AxBaseAI = class {
985
1036
  `Model ${model} does not support thinkingTokenBudget.`
986
1037
  );
987
1038
  }
1039
+ if (options?.showThoughts && !this.getFeatures(model).hasShowThoughts) {
1040
+ throw new Error(`Model ${model} does not support showThoughts.`);
1041
+ }
988
1042
  modelConfig.stream = (options?.stream !== void 0 ? options.stream : modelConfig.stream) ?? true;
989
1043
  const canStream = this.getFeatures(model).streaming;
990
1044
  if (!canStream) {
@@ -1077,7 +1131,11 @@ var AxBaseAI = class {
1077
1131
  return res2;
1078
1132
  };
1079
1133
  if (debug) {
1080
- logChatRequest(req.chatPrompt, options?.debugHideSystemPrompt);
1134
+ logChatRequest(
1135
+ req.chatPrompt,
1136
+ options?.debugHideSystemPrompt,
1137
+ options?.logger ?? this.logger
1138
+ );
1081
1139
  }
1082
1140
  const rt = options?.rateLimiter ?? this.rt;
1083
1141
  const rv = rt ? await rt(fn, { modelUsage: this.modelUsage }) : await fn();
@@ -1089,13 +1147,6 @@ var AxBaseAI = class {
1089
1147
  const wrappedRespFn = (state) => (resp) => {
1090
1148
  const res2 = respFn(resp, state);
1091
1149
  res2.sessionId = options?.sessionId;
1092
- if (options?.hideThought) {
1093
- res2.results.forEach((result) => {
1094
- if (result.thought) {
1095
- result.thought = void 0;
1096
- }
1097
- });
1098
- }
1099
1150
  if (!res2.modelUsage) {
1100
1151
  res2.modelUsage = {
1101
1152
  ai: this.name,
@@ -1108,13 +1159,14 @@ var AxBaseAI = class {
1108
1159
  setChatResponseEvents(res2, span, this.excludeContentFromTrace);
1109
1160
  }
1110
1161
  if (debug) {
1111
- logResponse(res2);
1162
+ logResponse(res2, options?.logger ?? this.logger);
1112
1163
  }
1113
1164
  return res2;
1114
1165
  };
1115
1166
  const doneCb = async (_values) => {
1116
1167
  if (debug) {
1117
- process.stdout.write("\n");
1168
+ const logger = options?.logger ?? this.logger;
1169
+ logger("", { tags: ["responseEnd"] });
1118
1170
  }
1119
1171
  if (span?.isRecording()) {
1120
1172
  span.end();
@@ -1133,13 +1185,6 @@ var AxBaseAI = class {
1133
1185
  }
1134
1186
  const res = this.aiImpl.createChatResp(rv);
1135
1187
  res.sessionId = options?.sessionId;
1136
- if (options?.hideThought) {
1137
- res.results.forEach((result) => {
1138
- if (result.thought) {
1139
- result.thought = void 0;
1140
- }
1141
- });
1142
- }
1143
1188
  if (!res.modelUsage) {
1144
1189
  const tokenUsage = this.aiImpl.getTokenUsage();
1145
1190
  if (tokenUsage) {
@@ -1158,7 +1203,10 @@ var AxBaseAI = class {
1158
1203
  span.end();
1159
1204
  }
1160
1205
  if (debug) {
1161
- logResponse(res);
1206
+ logResponse(res, options?.logger ?? this.logger);
1207
+ }
1208
+ if (debug) {
1209
+ this.logger("", { tags: ["responseEnd"] });
1162
1210
  }
1163
1211
  return res;
1164
1212
  }
@@ -1357,7 +1405,14 @@ function setChatResponseEvents(res, span, excludeContentFromTrace) {
1357
1405
  if (!res.results) {
1358
1406
  return;
1359
1407
  }
1360
- for (const [index, result] of res.results.entries()) {
1408
+ for (let index = 0; index < res.results.length; index++) {
1409
+ const result = res.results[index];
1410
+ if (!result) {
1411
+ continue;
1412
+ }
1413
+ if (!result.content && !result.thought && !result.functionCalls?.length && !result.finishReason) {
1414
+ continue;
1415
+ }
1361
1416
  const toolCalls = result.functionCalls?.map((call) => {
1362
1417
  return {
1363
1418
  id: call.id,
@@ -3272,6 +3327,9 @@ var AxAIGoogleGeminiImpl = class {
3272
3327
  break;
3273
3328
  }
3274
3329
  }
3330
+ if (config.showThoughts !== void 0) {
3331
+ thinkingConfig.includeThoughts = config.showThoughts;
3332
+ }
3275
3333
  const generationConfig = {
3276
3334
  maxOutputTokens: req.modelConfig?.maxTokens ?? this.config.maxTokens,
3277
3335
  temperature: req.modelConfig?.temperature ?? this.config.temperature,
@@ -4060,7 +4118,7 @@ var AxAIOpenAIResponsesImpl = class {
4060
4118
  }
4061
4119
  return items;
4062
4120
  }
4063
- createChatReq(req, _config) {
4121
+ createChatReq(req, config) {
4064
4122
  const model = req.model;
4065
4123
  const apiConfig = { name: "/responses" };
4066
4124
  let instructionsFromPrompt = null;
@@ -4083,6 +4141,10 @@ var AxAIOpenAIResponsesImpl = class {
4083
4141
  parameters: v.parameters ?? {}
4084
4142
  })
4085
4143
  );
4144
+ const includeFields = [];
4145
+ if (config.showThoughts) {
4146
+ includeFields.push("reasoning.encrypted_content");
4147
+ }
4086
4148
  let mutableReq = {
4087
4149
  model,
4088
4150
  input: "",
@@ -4097,7 +4159,7 @@ var AxAIOpenAIResponsesImpl = class {
4097
4159
  // Sourced from modelConfig or global config
4098
4160
  // Optional fields from AxAIOpenAIResponsesRequest that need to be in Mutable for initialization
4099
4161
  background: void 0,
4100
- include: void 0,
4162
+ include: includeFields.length > 0 ? includeFields : void 0,
4101
4163
  metadata: void 0,
4102
4164
  parallel_tool_calls: this.config.parallelToolCalls,
4103
4165
  previous_response_id: void 0,
@@ -4170,9 +4232,13 @@ var AxAIOpenAIResponsesImpl = class {
4170
4232
  break;
4171
4233
  case "reasoning":
4172
4234
  currentResult.id = item.id;
4173
- currentResult.thought = item.summary.map(
4174
- (s) => typeof s === "object" ? JSON.stringify(s) : s
4175
- ).join("\n");
4235
+ if (item.encrypted_content) {
4236
+ currentResult.thought = item.encrypted_content;
4237
+ } else {
4238
+ currentResult.thought = item.summary.map(
4239
+ (s) => typeof s === "object" ? JSON.stringify(s) : s
4240
+ ).join("\n");
4241
+ }
4176
4242
  break;
4177
4243
  case "file_search_call":
4178
4244
  currentResult.id = item.id;
@@ -4490,7 +4556,9 @@ var AxAIOpenAIResponsesImpl = class {
4490
4556
  {
4491
4557
  const reasoningItem = event.item;
4492
4558
  baseResult.id = event.item.id;
4493
- if (reasoningItem.summary) {
4559
+ if (reasoningItem.encrypted_content) {
4560
+ baseResult.thought = reasoningItem.encrypted_content;
4561
+ } else if (reasoningItem.summary) {
4494
4562
  baseResult.thought = reasoningItem.summary.map(
4495
4563
  (s) => typeof s === "object" ? JSON.stringify(s) : s
4496
4564
  ).join("\n");
@@ -5143,6 +5211,9 @@ var AxAI = class {
5143
5211
  getOptions() {
5144
5212
  return this.ai.getOptions();
5145
5213
  }
5214
+ getLogger() {
5215
+ return this.ai.getLogger();
5216
+ }
5146
5217
  };
5147
5218
 
5148
5219
  // ai/x-grok/types.ts
@@ -5366,7 +5437,7 @@ var MemoryImpl = class {
5366
5437
  if (this.options?.debug) {
5367
5438
  if (delta && typeof delta === "string") {
5368
5439
  debugResponseDelta(delta);
5369
- } else if (lastItem) {
5440
+ } else if (!delta && (content || functionCalls)) {
5370
5441
  debugResponse({ content, name, functionCalls });
5371
5442
  }
5372
5443
  }
@@ -6308,7 +6379,6 @@ function formatDescription(str) {
6308
6379
  }
6309
6380
 
6310
6381
  // dsp/validate.ts
6311
- var colorLog4 = new ColorLog();
6312
6382
  var ValidationError = class extends Error {
6313
6383
  fields;
6314
6384
  constructor({
@@ -6349,10 +6419,11 @@ function handleValidationError(mem, errorFields, ai, promptTemplate, sessionId)
6349
6419
  mem.addTag("error");
6350
6420
  if (ai.getOptions().debug) {
6351
6421
  const errors = errorFields.map((field) => `- ${field.title}: ${field.description}`).join("\n");
6352
- process.stdout.write(colorLog4.red(`
6353
- \u274C Error Correction:
6354
- ${errors}
6355
- `));
6422
+ const logger = ai.getLogger();
6423
+ logger(`\u274C Error Correction:
6424
+ ${errors}`, {
6425
+ tags: ["error"]
6426
+ });
6356
6427
  }
6357
6428
  }
6358
6429
 
@@ -6932,7 +7003,6 @@ var validateJSONSchema = (schema) => {
6932
7003
  };
6933
7004
 
6934
7005
  // dsp/functions.ts
6935
- var colorLog5 = new ColorLog();
6936
7006
  var AxFunctionError = class extends Error {
6937
7007
  constructor(fields) {
6938
7008
  super();
@@ -7101,12 +7171,11 @@ var processFunctions = async (ai, functionList, functionCalls, mem, sessionId, t
7101
7171
  );
7102
7172
  mem.addTag("error");
7103
7173
  if (ai.getOptions().debug) {
7104
- process.stdout.write(
7105
- colorLog5.red(`
7106
- \u274C Function Error Correction:
7107
- ${result}
7108
- `)
7109
- );
7174
+ const logger = ai.getLogger();
7175
+ logger(`\u274C Function Error Correction:
7176
+ ${result}`, {
7177
+ tags: ["error"]
7178
+ });
7110
7179
  }
7111
7180
  } else {
7112
7181
  throw e;
@@ -7872,9 +7941,11 @@ var AxGen = class extends AxProgramWithSignature {
7872
7941
  values = {};
7873
7942
  excludeContentFromTrace = false;
7874
7943
  thoughtFieldName;
7944
+ logger;
7875
7945
  constructor(signature, options) {
7876
7946
  super(signature, { description: options?.description });
7877
7947
  this.options = options;
7948
+ this.logger = options?.logger;
7878
7949
  this.thoughtFieldName = options?.thoughtFieldName ?? "thought";
7879
7950
  const promptTemplateOptions = {
7880
7951
  functions: options?.functions,
@@ -7938,7 +8009,8 @@ var AxGen = class extends AxProgramWithSignature {
7938
8009
  stream,
7939
8010
  functions: _functions,
7940
8011
  functionCall: _functionCall,
7941
- thinkingTokenBudget
8012
+ thinkingTokenBudget,
8013
+ showThoughts
7942
8014
  } = options ?? {};
7943
8015
  const chatPrompt = mem?.history(sessionId) ?? [];
7944
8016
  if (chatPrompt.length === 0) {
@@ -7964,6 +8036,7 @@ var AxGen = class extends AxProgramWithSignature {
7964
8036
  stream,
7965
8037
  debug: false,
7966
8038
  thinkingTokenBudget,
8039
+ showThoughts,
7967
8040
  traceContext,
7968
8041
  abortSignal: options?.abortSignal
7969
8042
  }
@@ -8162,6 +8235,10 @@ Content: ${content}`
8162
8235
  xstate
8163
8236
  );
8164
8237
  }
8238
+ if (ai.getOptions().debug) {
8239
+ const logger = ai.getLogger();
8240
+ logger("", { tags: ["responseEnd"] });
8241
+ }
8165
8242
  }
8166
8243
  async processResponse({
8167
8244
  ai,
@@ -8289,7 +8366,8 @@ Content: ${result.content}`
8289
8366
  continue multiStepLoop;
8290
8367
  }
8291
8368
  if (debug) {
8292
- process.stdout.write("\n");
8369
+ const logger = options.logger ?? this.logger ?? ai.getLogger();
8370
+ logger("", { tags: ["responseEnd"] });
8293
8371
  }
8294
8372
  return;
8295
8373
  } catch (e) {
@@ -8373,6 +8451,7 @@ Content: ${result.content}`
8373
8451
  ...funcNames ? { provided_functions: funcNames } : {},
8374
8452
  ...options?.model ? { model: options.model } : {},
8375
8453
  ...options?.thinkingTokenBudget ? { thinking_token_budget: options.thinkingTokenBudget } : {},
8454
+ ...options?.showThoughts ? { show_thoughts: options.showThoughts } : {},
8376
8455
  ...options?.maxSteps ? { max_steps: options.maxSteps } : {},
8377
8456
  ...options?.maxRetries ? { max_retries: options.maxRetries } : {},
8378
8457
  ...options?.fastFail ? { fast_fail: options.fastFail } : {}
@@ -8480,10 +8559,14 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
8480
8559
  ...pick(parentValues, injectionKeys)
8481
8560
  };
8482
8561
  if (options.debug && injectionKeys.length > 0) {
8483
- process.stdout.write(
8484
- `
8485
- Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`
8486
- );
8562
+ const ai = funcOptions?.ai;
8563
+ if (ai) {
8564
+ const logger = ai.getLogger();
8565
+ logger(
8566
+ `Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`,
8567
+ { tags: ["functionArg"] }
8568
+ );
8569
+ }
8487
8570
  }
8488
8571
  return await originalFunc(updatedChildArgs, funcOptions);
8489
8572
  };
@@ -8592,18 +8675,18 @@ var AxAgent = class {
8592
8675
  }
8593
8676
  const debug = this.getDebug(ai, options);
8594
8677
  if (debug) {
8595
- process.stdout.write(`
8596
- --- Agent Engaged: ${this.name} ---
8597
- `);
8678
+ const logger = ai.getLogger();
8679
+ logger(`\u{1F916} Agent ${this.name} starting...`, {
8680
+ tags: ["assistantStart"]
8681
+ });
8598
8682
  }
8599
8683
  const ret = await boundFunc(ai, values, {
8600
8684
  ...options,
8601
8685
  model
8602
8686
  });
8603
8687
  if (debug) {
8604
- process.stdout.write(`
8605
- --- Agent Done: ${this.name} ---
8606
- `);
8688
+ const logger = ai.getLogger();
8689
+ logger(`\u{1F916} Agent ${this.name} completed.`, { tags: ["assistantEnd"] });
8607
8690
  }
8608
8691
  const sig = this.program.getSignature();
8609
8692
  const outFields = sig.getOutputFields();
@@ -9006,6 +9089,9 @@ var AxBalancer = class _AxBalancer {
9006
9089
  getOptions() {
9007
9090
  return this.currentService.getOptions();
9008
9091
  }
9092
+ getLogger() {
9093
+ return this.currentService.getLogger();
9094
+ }
9009
9095
  };
9010
9096
  function validateModels2(services) {
9011
9097
  const serviceWithModel = services.find(
@@ -11441,6 +11527,11 @@ var AxMockAIService = class {
11441
11527
  getOptions() {
11442
11528
  return this.config.options ?? {};
11443
11529
  }
11530
+ getLogger() {
11531
+ return this.config.options?.logger ?? ((message) => {
11532
+ process.stdout.write(message);
11533
+ });
11534
+ }
11444
11535
  updateMetrics(type) {
11445
11536
  const latency = this.config.latencyMs ?? 0;
11446
11537
  this.metrics.latency[type].samples.push(latency);
@@ -11463,7 +11554,7 @@ var AxMockAIService = class {
11463
11554
  };
11464
11555
 
11465
11556
  // dsp/classifier.ts
11466
- var colorLog6 = new ColorLog();
11557
+ var colorLog4 = new ColorLog();
11467
11558
  var AxSimpleClassifierClass = class {
11468
11559
  name;
11469
11560
  context;
@@ -11525,7 +11616,7 @@ var AxSimpleClassifier = class {
11525
11616
  }
11526
11617
  if (this.debug) {
11527
11618
  console.log(
11528
- colorLog6.whiteBright(`query: ${text}`) + "\n" + colorLog6.greenBright(
11619
+ colorLog4.whiteBright(`query: ${text}`) + "\n" + colorLog4.greenBright(
11529
11620
  JSON.stringify(m.map((m2) => `${m2.id}, ${m2.score}`))
11530
11621
  )
11531
11622
  );
@@ -13016,15 +13107,16 @@ function v4(options, buf, offset) {
13016
13107
  var v4_default = v4;
13017
13108
 
13018
13109
  // mcp/client.ts
13019
- var colorLog7 = new ColorLog();
13020
13110
  var AxMCPClient = class {
13021
13111
  constructor(transport, options = {}) {
13022
13112
  this.transport = transport;
13023
13113
  this.options = options;
13114
+ this.logger = options.logger ?? ((message) => console.log(message));
13024
13115
  }
13025
13116
  functions = [];
13026
13117
  activeRequests = /* @__PURE__ */ new Map();
13027
13118
  capabilities = {};
13119
+ logger;
13028
13120
  async init() {
13029
13121
  if ("connect" in this.transport) {
13030
13122
  await this.transport.connect?.();
@@ -13083,11 +13175,13 @@ var AxMCPClient = class {
13083
13175
  };
13084
13176
  });
13085
13177
  if (this.options.debug) {
13086
- console.log(
13087
- colorLog7.yellow(`> Discovered ${this.functions.length} functions:`)
13088
- );
13178
+ this.logger(`> Discovered ${this.functions.length} functions:`, {
13179
+ tags: ["discovery"]
13180
+ });
13089
13181
  for (const fn of this.functions) {
13090
- console.log(colorLog7.yellow(` - ${fn.name}: ${fn.description}`));
13182
+ this.logger(` - ${fn.name}: ${fn.description}`, {
13183
+ tags: ["discovery"]
13184
+ });
13091
13185
  }
13092
13186
  }
13093
13187
  }
@@ -13130,11 +13224,10 @@ var AxMCPClient = class {
13130
13224
  params
13131
13225
  };
13132
13226
  if (this.options.debug) {
13133
- console.log(
13134
- colorLog7.blueBright(
13135
- `> Sending request ${requestId}:
13136
- ${JSON.stringify(request, null, 2)}`
13137
- )
13227
+ this.logger(
13228
+ `> Sending request ${requestId}:
13229
+ ${JSON.stringify(request, null, 2)}`,
13230
+ { tags: ["requestStart"] }
13138
13231
  );
13139
13232
  }
13140
13233
  const responsePromise = new Promise((resolve, reject) => {
@@ -13142,11 +13235,10 @@ ${JSON.stringify(request, null, 2)}`
13142
13235
  this.transport.send(request).then((res) => {
13143
13236
  this.activeRequests.delete(requestId);
13144
13237
  if (this.options.debug) {
13145
- console.log(
13146
- colorLog7.greenBright(
13147
- `> Received response for request ${requestId}:
13148
- ${JSON.stringify(res, null, 2)}`
13149
- )
13238
+ this.logger(
13239
+ `> Received response for request ${requestId}:
13240
+ ${JSON.stringify(res, null, 2)}`,
13241
+ { tags: ["responseContent"] }
13150
13242
  );
13151
13243
  }
13152
13244
  if (res !== null && typeof res === "object" && "error" in res) {
@@ -13176,9 +13268,9 @@ ${JSON.stringify(res, null, 2)}`
13176
13268
  params
13177
13269
  };
13178
13270
  if (this.options.debug) {
13179
- console.log(
13180
- "\u27A1\uFE0F Sending notification:",
13181
- JSON.stringify(notification, null, 2)
13271
+ this.logger(
13272
+ `\u27A1\uFE0F Sending notification: ${JSON.stringify(notification, null, 2)}`,
13273
+ { tags: ["requestStart"] }
13182
13274
  );
13183
13275
  }
13184
13276
  await this.transport.sendNotification(notification);
@@ -13408,6 +13500,25 @@ var AxMultiServiceRouter = class {
13408
13500
  getOptions() {
13409
13501
  return this.options ?? {};
13410
13502
  }
13503
+ /**
13504
+ * Returns the logger from the last used service,
13505
+ * or falls back to the first service if none has been used.
13506
+ */
13507
+ getLogger() {
13508
+ let serviceInstance = this.lastUsedService;
13509
+ if (!serviceInstance) {
13510
+ const firstServiceEntry = this.services.values().next().value;
13511
+ if (firstServiceEntry) {
13512
+ serviceInstance = firstServiceEntry.service;
13513
+ }
13514
+ }
13515
+ if (!serviceInstance) {
13516
+ return (message) => {
13517
+ process.stdout.write(message);
13518
+ };
13519
+ }
13520
+ return serviceInstance.getLogger();
13521
+ }
13411
13522
  };
13412
13523
 
13413
13524
  // prompts/rag.ts