@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.cjs CHANGED
@@ -835,6 +835,46 @@ var ColorLog = class {
835
835
 
836
836
  // ai/debug.ts
837
837
  var colorLog = new ColorLog();
838
+ var defaultOutput = (message) => {
839
+ process.stdout.write(message);
840
+ };
841
+ var createDefaultLogger = (output = defaultOutput) => {
842
+ return (message, options) => {
843
+ const tags = options?.tags ?? [];
844
+ let formattedMessage = message;
845
+ if (tags.includes("error")) {
846
+ formattedMessage = colorLog.red(formattedMessage);
847
+ } else if (tags.includes("success") || tags.includes("responseContent")) {
848
+ formattedMessage = colorLog.greenBright(formattedMessage);
849
+ } else if (tags.includes("functionName")) {
850
+ formattedMessage = colorLog.whiteBright(formattedMessage);
851
+ } else if (tags.includes("functionArg") || tags.includes("systemContent") || tags.includes("assistantContent")) {
852
+ formattedMessage = colorLog.blueBright(formattedMessage);
853
+ } else if (tags.includes("warning") || tags.includes("discovery")) {
854
+ formattedMessage = colorLog.yellow(formattedMessage);
855
+ }
856
+ if (tags.includes("responseStart") || tags.includes("systemStart") || tags.includes("userStart")) {
857
+ formattedMessage = `
858
+ ${formattedMessage}`;
859
+ } else if (tags.includes("responseEnd") || tags.includes("systemEnd") || tags.includes("userEnd")) {
860
+ formattedMessage = `${formattedMessage}
861
+ `;
862
+ } else if (tags.includes("assistantStart")) {
863
+ formattedMessage = `
864
+ ${formattedMessage}
865
+ `;
866
+ } else if (tags.includes("error")) {
867
+ formattedMessage = `
868
+ ${formattedMessage}
869
+ `;
870
+ } else if (tags.includes("functionEnd")) {
871
+ formattedMessage = `${formattedMessage}
872
+ `;
873
+ }
874
+ output(formattedMessage);
875
+ };
876
+ };
877
+ var defaultLogger = createDefaultLogger();
838
878
  var formatChatMessage = (msg, hideContent, hideSystemPrompt) => {
839
879
  switch (msg.role) {
840
880
  case "system":
@@ -842,30 +882,30 @@ var formatChatMessage = (msg, hideContent, hideSystemPrompt) => {
842
882
  return "";
843
883
  }
844
884
  return `
845
- ${colorLog.blueBright("System:")}
846
- ${colorLog.whiteBright(msg.content)}`;
885
+ System:
886
+ ${msg.content}`;
847
887
  case "function":
848
888
  return `
849
- ${colorLog.blueBright("Function Result:")}
850
- ${colorLog.whiteBright(msg.result)}`;
889
+ Function Result:
890
+ ${msg.result}`;
851
891
  case "user": {
852
892
  if (typeof msg.content === "string") {
853
893
  return `
854
- ${colorLog.blueBright("User:")}
855
- ${colorLog.whiteBright(msg.content)}`;
894
+ User:
895
+ ${msg.content}`;
856
896
  }
857
897
  const items = msg.content.map((v) => {
858
898
  switch (v.type) {
859
899
  case "text":
860
- return `${colorLog.whiteBright(v.text)}`;
900
+ return v.text;
861
901
  case "image":
862
- return `(Image, ${v.mimeType}) ${colorLog.whiteBright(v.image.substring(0, 10))}`;
902
+ return `(Image, ${v.mimeType}) ${v.image.substring(0, 10)}`;
863
903
  default:
864
904
  throw new Error("Invalid content type");
865
905
  }
866
906
  });
867
907
  return `
868
- ${colorLog.blueBright("User:")}
908
+ User:
869
909
  ${items.join("\n")}`;
870
910
  }
871
911
  case "assistant": {
@@ -875,62 +915,64 @@ ${items.join("\n")}`;
875
915
  return `${fn.name}(${args})`;
876
916
  });
877
917
  return `
878
- ${colorLog.blueBright("\nFunctions:")}
879
- ${colorLog.whiteBright(fns.join("\n"))}`;
918
+ Functions:
919
+ ${fns.join("\n")}`;
880
920
  }
881
921
  return `
882
- ${colorLog.blueBright("\nAssistant:")}
883
- ${hideContent ? "" : colorLog.whiteBright(msg.content ?? "<empty>")}`;
922
+ Assistant:
923
+ ${hideContent ? "" : msg.content ?? "<empty>"}`;
884
924
  }
885
925
  default:
886
926
  throw new Error("Invalid role");
887
927
  }
888
928
  };
889
- var logChatRequestMessage = (msg, hideSystemPrompt) => {
890
- process.stdout.write(`${formatChatMessage(msg, hideSystemPrompt)}
891
- `);
892
- process.stdout.write(colorLog.blueBright("\nAssistant:\n"));
929
+ var logChatRequestMessage = (msg, hideSystemPrompt, logger = defaultLogger) => {
930
+ const formattedMessage = formatChatMessage(msg, false, hideSystemPrompt);
931
+ if (formattedMessage) {
932
+ const tags = msg.role === "system" ? ["systemStart", "systemContent"] : msg.role === "function" ? ["functionName"] : msg.role === "user" ? ["userStart", "userContent"] : [];
933
+ logger(formattedMessage, { tags });
934
+ }
935
+ logger("Assistant:", { tags: ["assistantStart"] });
893
936
  };
894
- var logChatRequest = (chatPrompt, hideSystemPrompt) => {
895
- const items = chatPrompt?.map(
896
- (msg) => formatChatMessage(msg, hideSystemPrompt)
897
- );
898
- if (items) {
899
- process.stdout.write(items.join("\n"));
900
- process.stdout.write(colorLog.blueBright("\nAssistant:\n"));
937
+ var logChatRequest = (chatPrompt, hideSystemPrompt, logger = defaultLogger) => {
938
+ for (const msg of chatPrompt ?? []) {
939
+ const formattedMessage = formatChatMessage(msg, false, hideSystemPrompt);
940
+ if (formattedMessage) {
941
+ const tags = msg.role === "system" ? ["systemContent"] : msg.role === "function" ? ["functionName"] : msg.role === "user" ? ["userContent"] : [];
942
+ logger(formattedMessage, { tags });
943
+ }
901
944
  }
945
+ logger("Assistant:", { tags: ["assistantStart"] });
902
946
  };
903
- var logResponseResult = (r) => {
947
+ var logResponseResult = (r, logger = defaultLogger) => {
904
948
  if (r.content) {
905
- process.stdout.write(colorLog.greenBright(r.content));
949
+ logger(r.content, { tags: ["responseContent"] });
906
950
  }
907
- if (r.functionCalls) {
951
+ if (r.functionCalls && r.functionCalls.length > 0) {
908
952
  for (const [i, f] of r.functionCalls.entries()) {
909
953
  if (f.function.name) {
910
- if (i > 0) {
911
- process.stdout.write("\n");
912
- }
913
- process.stdout.write(
914
- `Function ${i + 1} -> ${colorLog.greenBright(f.function.name)}`
915
- );
954
+ logger(`[${i + 1}] ${f.function.name}`, {
955
+ tags: ["functionName"]
956
+ });
916
957
  }
917
958
  if (f.function.params) {
918
959
  const params = typeof f.function.params === "string" ? f.function.params : JSON.stringify(f.function.params, null, 2);
919
- process.stdout.write(`${colorLog.greenBright(params)}`);
960
+ logger(params, { tags: ["functionArg"] });
920
961
  }
921
962
  }
963
+ logger("", { tags: ["functionEnd"] });
922
964
  }
923
965
  };
924
- var logResponse = (resp) => {
966
+ var logResponse = (resp, logger = defaultLogger) => {
925
967
  if (!resp.results) {
926
968
  return;
927
969
  }
928
970
  for (const r of resp.results) {
929
- logResponseResult(r);
971
+ logResponseResult(r, logger);
930
972
  }
931
973
  };
932
- var logResponseDelta = (delta) => {
933
- process.stdout.write(colorLog.greenBright(delta));
974
+ var logResponseDelta = (delta, logger = defaultLogger) => {
975
+ logger(delta, { tags: ["responseContent"] });
934
976
  };
935
977
 
936
978
  // ai/base.ts
@@ -944,6 +986,9 @@ var axBaseAIDefaultCreativeConfig = () => structuredClone({
944
986
  topP: 0.7,
945
987
  frequencyPenalty: 0.2
946
988
  });
989
+ var defaultLogger2 = (message, _options) => {
990
+ process.stdout.write(message);
991
+ };
947
992
  var AxBaseAI = class {
948
993
  constructor(aiImpl, {
949
994
  name,
@@ -983,6 +1028,7 @@ var AxBaseAI = class {
983
1028
  excludeContentFromTrace;
984
1029
  models;
985
1030
  abortSignal;
1031
+ logger = defaultLogger2;
986
1032
  modelInfo;
987
1033
  modelUsage;
988
1034
  embedModelUsage;
@@ -1044,6 +1090,7 @@ var AxBaseAI = class {
1044
1090
  this.tracer = options.tracer;
1045
1091
  this.excludeContentFromTrace = options.excludeContentFromTrace;
1046
1092
  this.abortSignal = options.abortSignal;
1093
+ this.logger = options.logger ?? defaultLogger2;
1047
1094
  }
1048
1095
  getOptions() {
1049
1096
  return {
@@ -1053,9 +1100,13 @@ var AxBaseAI = class {
1053
1100
  tracer: this.tracer,
1054
1101
  timeout: this.timeout,
1055
1102
  excludeContentFromTrace: this.excludeContentFromTrace,
1056
- abortSignal: this.abortSignal
1103
+ abortSignal: this.abortSignal,
1104
+ logger: this.logger
1057
1105
  };
1058
1106
  }
1107
+ getLogger() {
1108
+ return this.logger;
1109
+ }
1059
1110
  getModelList() {
1060
1111
  const models = [];
1061
1112
  for (const model of this.models ?? []) {
@@ -1151,6 +1202,9 @@ var AxBaseAI = class {
1151
1202
  `Model ${model} does not support thinkingTokenBudget.`
1152
1203
  );
1153
1204
  }
1205
+ if (options?.showThoughts && !this.getFeatures(model).hasShowThoughts) {
1206
+ throw new Error(`Model ${model} does not support showThoughts.`);
1207
+ }
1154
1208
  modelConfig.stream = (options?.stream !== void 0 ? options.stream : modelConfig.stream) ?? true;
1155
1209
  const canStream = this.getFeatures(model).streaming;
1156
1210
  if (!canStream) {
@@ -1243,7 +1297,11 @@ var AxBaseAI = class {
1243
1297
  return res2;
1244
1298
  };
1245
1299
  if (debug) {
1246
- logChatRequest(req.chatPrompt, options?.debugHideSystemPrompt);
1300
+ logChatRequest(
1301
+ req.chatPrompt,
1302
+ options?.debugHideSystemPrompt,
1303
+ options?.logger ?? this.logger
1304
+ );
1247
1305
  }
1248
1306
  const rt = options?.rateLimiter ?? this.rt;
1249
1307
  const rv = rt ? await rt(fn, { modelUsage: this.modelUsage }) : await fn();
@@ -1255,13 +1313,6 @@ var AxBaseAI = class {
1255
1313
  const wrappedRespFn = (state) => (resp) => {
1256
1314
  const res2 = respFn(resp, state);
1257
1315
  res2.sessionId = options?.sessionId;
1258
- if (options?.hideThought) {
1259
- res2.results.forEach((result) => {
1260
- if (result.thought) {
1261
- result.thought = void 0;
1262
- }
1263
- });
1264
- }
1265
1316
  if (!res2.modelUsage) {
1266
1317
  res2.modelUsage = {
1267
1318
  ai: this.name,
@@ -1274,13 +1325,14 @@ var AxBaseAI = class {
1274
1325
  setChatResponseEvents(res2, span, this.excludeContentFromTrace);
1275
1326
  }
1276
1327
  if (debug) {
1277
- logResponse(res2);
1328
+ logResponse(res2, options?.logger ?? this.logger);
1278
1329
  }
1279
1330
  return res2;
1280
1331
  };
1281
1332
  const doneCb = async (_values) => {
1282
1333
  if (debug) {
1283
- process.stdout.write("\n");
1334
+ const logger = options?.logger ?? this.logger;
1335
+ logger("", { tags: ["responseEnd"] });
1284
1336
  }
1285
1337
  if (span?.isRecording()) {
1286
1338
  span.end();
@@ -1299,13 +1351,6 @@ var AxBaseAI = class {
1299
1351
  }
1300
1352
  const res = this.aiImpl.createChatResp(rv);
1301
1353
  res.sessionId = options?.sessionId;
1302
- if (options?.hideThought) {
1303
- res.results.forEach((result) => {
1304
- if (result.thought) {
1305
- result.thought = void 0;
1306
- }
1307
- });
1308
- }
1309
1354
  if (!res.modelUsage) {
1310
1355
  const tokenUsage = this.aiImpl.getTokenUsage();
1311
1356
  if (tokenUsage) {
@@ -1324,7 +1369,10 @@ var AxBaseAI = class {
1324
1369
  span.end();
1325
1370
  }
1326
1371
  if (debug) {
1327
- logResponse(res);
1372
+ logResponse(res, options?.logger ?? this.logger);
1373
+ }
1374
+ if (debug) {
1375
+ this.logger("", { tags: ["responseEnd"] });
1328
1376
  }
1329
1377
  return res;
1330
1378
  }
@@ -1523,7 +1571,14 @@ function setChatResponseEvents(res, span, excludeContentFromTrace) {
1523
1571
  if (!res.results) {
1524
1572
  return;
1525
1573
  }
1526
- for (const [index, result] of res.results.entries()) {
1574
+ for (let index = 0; index < res.results.length; index++) {
1575
+ const result = res.results[index];
1576
+ if (!result) {
1577
+ continue;
1578
+ }
1579
+ if (!result.content && !result.thought && !result.functionCalls?.length && !result.finishReason) {
1580
+ continue;
1581
+ }
1527
1582
  const toolCalls = result.functionCalls?.map((call) => {
1528
1583
  return {
1529
1584
  id: call.id,
@@ -3438,6 +3493,9 @@ var AxAIGoogleGeminiImpl = class {
3438
3493
  break;
3439
3494
  }
3440
3495
  }
3496
+ if (config.showThoughts !== void 0) {
3497
+ thinkingConfig.includeThoughts = config.showThoughts;
3498
+ }
3441
3499
  const generationConfig = {
3442
3500
  maxOutputTokens: req.modelConfig?.maxTokens ?? this.config.maxTokens,
3443
3501
  temperature: req.modelConfig?.temperature ?? this.config.temperature,
@@ -4226,7 +4284,7 @@ var AxAIOpenAIResponsesImpl = class {
4226
4284
  }
4227
4285
  return items;
4228
4286
  }
4229
- createChatReq(req, _config) {
4287
+ createChatReq(req, config) {
4230
4288
  const model = req.model;
4231
4289
  const apiConfig = { name: "/responses" };
4232
4290
  let instructionsFromPrompt = null;
@@ -4249,6 +4307,10 @@ var AxAIOpenAIResponsesImpl = class {
4249
4307
  parameters: v.parameters ?? {}
4250
4308
  })
4251
4309
  );
4310
+ const includeFields = [];
4311
+ if (config.showThoughts) {
4312
+ includeFields.push("reasoning.encrypted_content");
4313
+ }
4252
4314
  let mutableReq = {
4253
4315
  model,
4254
4316
  input: "",
@@ -4263,7 +4325,7 @@ var AxAIOpenAIResponsesImpl = class {
4263
4325
  // Sourced from modelConfig or global config
4264
4326
  // Optional fields from AxAIOpenAIResponsesRequest that need to be in Mutable for initialization
4265
4327
  background: void 0,
4266
- include: void 0,
4328
+ include: includeFields.length > 0 ? includeFields : void 0,
4267
4329
  metadata: void 0,
4268
4330
  parallel_tool_calls: this.config.parallelToolCalls,
4269
4331
  previous_response_id: void 0,
@@ -4336,9 +4398,13 @@ var AxAIOpenAIResponsesImpl = class {
4336
4398
  break;
4337
4399
  case "reasoning":
4338
4400
  currentResult.id = item.id;
4339
- currentResult.thought = item.summary.map(
4340
- (s) => typeof s === "object" ? JSON.stringify(s) : s
4341
- ).join("\n");
4401
+ if (item.encrypted_content) {
4402
+ currentResult.thought = item.encrypted_content;
4403
+ } else {
4404
+ currentResult.thought = item.summary.map(
4405
+ (s) => typeof s === "object" ? JSON.stringify(s) : s
4406
+ ).join("\n");
4407
+ }
4342
4408
  break;
4343
4409
  case "file_search_call":
4344
4410
  currentResult.id = item.id;
@@ -4656,7 +4722,9 @@ var AxAIOpenAIResponsesImpl = class {
4656
4722
  {
4657
4723
  const reasoningItem = event.item;
4658
4724
  baseResult.id = event.item.id;
4659
- if (reasoningItem.summary) {
4725
+ if (reasoningItem.encrypted_content) {
4726
+ baseResult.thought = reasoningItem.encrypted_content;
4727
+ } else if (reasoningItem.summary) {
4660
4728
  baseResult.thought = reasoningItem.summary.map(
4661
4729
  (s) => typeof s === "object" ? JSON.stringify(s) : s
4662
4730
  ).join("\n");
@@ -5309,6 +5377,9 @@ var AxAI = class {
5309
5377
  getOptions() {
5310
5378
  return this.ai.getOptions();
5311
5379
  }
5380
+ getLogger() {
5381
+ return this.ai.getLogger();
5382
+ }
5312
5383
  };
5313
5384
 
5314
5385
  // ai/x-grok/types.ts
@@ -5528,7 +5599,7 @@ var MemoryImpl = class {
5528
5599
  if (this.options?.debug) {
5529
5600
  if (delta && typeof delta === "string") {
5530
5601
  debugResponseDelta(delta);
5531
- } else if (lastItem) {
5602
+ } else if (!delta && (content || functionCalls)) {
5532
5603
  debugResponse({ content, name, functionCalls });
5533
5604
  }
5534
5605
  }
@@ -6470,7 +6541,6 @@ function formatDescription(str) {
6470
6541
  }
6471
6542
 
6472
6543
  // dsp/validate.ts
6473
- var colorLog4 = new ColorLog();
6474
6544
  var ValidationError = class extends Error {
6475
6545
  fields;
6476
6546
  constructor({
@@ -6511,10 +6581,11 @@ function handleValidationError(mem, errorFields, ai, promptTemplate, sessionId)
6511
6581
  mem.addTag("error");
6512
6582
  if (ai.getOptions().debug) {
6513
6583
  const errors = errorFields.map((field) => `- ${field.title}: ${field.description}`).join("\n");
6514
- process.stdout.write(colorLog4.red(`
6515
- \u274C Error Correction:
6516
- ${errors}
6517
- `));
6584
+ const logger = ai.getLogger();
6585
+ logger(`\u274C Error Correction:
6586
+ ${errors}`, {
6587
+ tags: ["error"]
6588
+ });
6518
6589
  }
6519
6590
  }
6520
6591
 
@@ -7094,7 +7165,6 @@ var validateJSONSchema = (schema) => {
7094
7165
  };
7095
7166
 
7096
7167
  // dsp/functions.ts
7097
- var colorLog5 = new ColorLog();
7098
7168
  var AxFunctionError = class extends Error {
7099
7169
  constructor(fields) {
7100
7170
  super();
@@ -7263,12 +7333,11 @@ var processFunctions = async (ai, functionList, functionCalls, mem, sessionId, t
7263
7333
  );
7264
7334
  mem.addTag("error");
7265
7335
  if (ai.getOptions().debug) {
7266
- process.stdout.write(
7267
- colorLog5.red(`
7268
- \u274C Function Error Correction:
7269
- ${result}
7270
- `)
7271
- );
7336
+ const logger = ai.getLogger();
7337
+ logger(`\u274C Function Error Correction:
7338
+ ${result}`, {
7339
+ tags: ["error"]
7340
+ });
7272
7341
  }
7273
7342
  } else {
7274
7343
  throw e;
@@ -8034,9 +8103,11 @@ var AxGen = class extends AxProgramWithSignature {
8034
8103
  values = {};
8035
8104
  excludeContentFromTrace = false;
8036
8105
  thoughtFieldName;
8106
+ logger;
8037
8107
  constructor(signature, options) {
8038
8108
  super(signature, { description: options?.description });
8039
8109
  this.options = options;
8110
+ this.logger = options?.logger;
8040
8111
  this.thoughtFieldName = options?.thoughtFieldName ?? "thought";
8041
8112
  const promptTemplateOptions = {
8042
8113
  functions: options?.functions,
@@ -8100,7 +8171,8 @@ var AxGen = class extends AxProgramWithSignature {
8100
8171
  stream,
8101
8172
  functions: _functions,
8102
8173
  functionCall: _functionCall,
8103
- thinkingTokenBudget
8174
+ thinkingTokenBudget,
8175
+ showThoughts
8104
8176
  } = options ?? {};
8105
8177
  const chatPrompt = mem?.history(sessionId) ?? [];
8106
8178
  if (chatPrompt.length === 0) {
@@ -8126,6 +8198,7 @@ var AxGen = class extends AxProgramWithSignature {
8126
8198
  stream,
8127
8199
  debug: false,
8128
8200
  thinkingTokenBudget,
8201
+ showThoughts,
8129
8202
  traceContext,
8130
8203
  abortSignal: options?.abortSignal
8131
8204
  }
@@ -8324,6 +8397,10 @@ Content: ${content}`
8324
8397
  xstate
8325
8398
  );
8326
8399
  }
8400
+ if (ai.getOptions().debug) {
8401
+ const logger = ai.getLogger();
8402
+ logger("", { tags: ["responseEnd"] });
8403
+ }
8327
8404
  }
8328
8405
  async processResponse({
8329
8406
  ai,
@@ -8451,7 +8528,8 @@ Content: ${result.content}`
8451
8528
  continue multiStepLoop;
8452
8529
  }
8453
8530
  if (debug) {
8454
- process.stdout.write("\n");
8531
+ const logger = options.logger ?? this.logger ?? ai.getLogger();
8532
+ logger("", { tags: ["responseEnd"] });
8455
8533
  }
8456
8534
  return;
8457
8535
  } catch (e) {
@@ -8535,6 +8613,7 @@ Content: ${result.content}`
8535
8613
  ...funcNames ? { provided_functions: funcNames } : {},
8536
8614
  ...options?.model ? { model: options.model } : {},
8537
8615
  ...options?.thinkingTokenBudget ? { thinking_token_budget: options.thinkingTokenBudget } : {},
8616
+ ...options?.showThoughts ? { show_thoughts: options.showThoughts } : {},
8538
8617
  ...options?.maxSteps ? { max_steps: options.maxSteps } : {},
8539
8618
  ...options?.maxRetries ? { max_retries: options.maxRetries } : {},
8540
8619
  ...options?.fastFail ? { fast_fail: options.fastFail } : {}
@@ -8642,10 +8721,14 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
8642
8721
  ...pick(parentValues, injectionKeys)
8643
8722
  };
8644
8723
  if (options.debug && injectionKeys.length > 0) {
8645
- process.stdout.write(
8646
- `
8647
- Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`
8648
- );
8724
+ const ai = funcOptions?.ai;
8725
+ if (ai) {
8726
+ const logger = ai.getLogger();
8727
+ logger(
8728
+ `Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`,
8729
+ { tags: ["functionArg"] }
8730
+ );
8731
+ }
8649
8732
  }
8650
8733
  return await originalFunc(updatedChildArgs, funcOptions);
8651
8734
  };
@@ -8754,18 +8837,18 @@ var AxAgent = class {
8754
8837
  }
8755
8838
  const debug = this.getDebug(ai, options);
8756
8839
  if (debug) {
8757
- process.stdout.write(`
8758
- --- Agent Engaged: ${this.name} ---
8759
- `);
8840
+ const logger = ai.getLogger();
8841
+ logger(`\u{1F916} Agent ${this.name} starting...`, {
8842
+ tags: ["assistantStart"]
8843
+ });
8760
8844
  }
8761
8845
  const ret = await boundFunc(ai, values, {
8762
8846
  ...options,
8763
8847
  model
8764
8848
  });
8765
8849
  if (debug) {
8766
- process.stdout.write(`
8767
- --- Agent Done: ${this.name} ---
8768
- `);
8850
+ const logger = ai.getLogger();
8851
+ logger(`\u{1F916} Agent ${this.name} completed.`, { tags: ["assistantEnd"] });
8769
8852
  }
8770
8853
  const sig = this.program.getSignature();
8771
8854
  const outFields = sig.getOutputFields();
@@ -9168,6 +9251,9 @@ var AxBalancer = class _AxBalancer {
9168
9251
  getOptions() {
9169
9252
  return this.currentService.getOptions();
9170
9253
  }
9254
+ getLogger() {
9255
+ return this.currentService.getLogger();
9256
+ }
9171
9257
  };
9172
9258
  function validateModels2(services) {
9173
9259
  const serviceWithModel = services.find(
@@ -11603,6 +11689,11 @@ var AxMockAIService = class {
11603
11689
  getOptions() {
11604
11690
  return this.config.options ?? {};
11605
11691
  }
11692
+ getLogger() {
11693
+ return this.config.options?.logger ?? ((message) => {
11694
+ process.stdout.write(message);
11695
+ });
11696
+ }
11606
11697
  updateMetrics(type) {
11607
11698
  const latency = this.config.latencyMs ?? 0;
11608
11699
  this.metrics.latency[type].samples.push(latency);
@@ -11625,7 +11716,7 @@ var AxMockAIService = class {
11625
11716
  };
11626
11717
 
11627
11718
  // dsp/classifier.ts
11628
- var colorLog6 = new ColorLog();
11719
+ var colorLog4 = new ColorLog();
11629
11720
  var AxSimpleClassifierClass = class {
11630
11721
  name;
11631
11722
  context;
@@ -11687,7 +11778,7 @@ var AxSimpleClassifier = class {
11687
11778
  }
11688
11779
  if (this.debug) {
11689
11780
  console.log(
11690
- colorLog6.whiteBright(`query: ${text}`) + "\n" + colorLog6.greenBright(
11781
+ colorLog4.whiteBright(`query: ${text}`) + "\n" + colorLog4.greenBright(
11691
11782
  JSON.stringify(m.map((m2) => `${m2.id}, ${m2.score}`))
11692
11783
  )
11693
11784
  );
@@ -13178,15 +13269,16 @@ function v4(options, buf, offset) {
13178
13269
  var v4_default = v4;
13179
13270
 
13180
13271
  // mcp/client.ts
13181
- var colorLog7 = new ColorLog();
13182
13272
  var AxMCPClient = class {
13183
13273
  constructor(transport, options = {}) {
13184
13274
  this.transport = transport;
13185
13275
  this.options = options;
13276
+ this.logger = options.logger ?? ((message) => console.log(message));
13186
13277
  }
13187
13278
  functions = [];
13188
13279
  activeRequests = /* @__PURE__ */ new Map();
13189
13280
  capabilities = {};
13281
+ logger;
13190
13282
  async init() {
13191
13283
  if ("connect" in this.transport) {
13192
13284
  await this.transport.connect?.();
@@ -13245,11 +13337,13 @@ var AxMCPClient = class {
13245
13337
  };
13246
13338
  });
13247
13339
  if (this.options.debug) {
13248
- console.log(
13249
- colorLog7.yellow(`> Discovered ${this.functions.length} functions:`)
13250
- );
13340
+ this.logger(`> Discovered ${this.functions.length} functions:`, {
13341
+ tags: ["discovery"]
13342
+ });
13251
13343
  for (const fn of this.functions) {
13252
- console.log(colorLog7.yellow(` - ${fn.name}: ${fn.description}`));
13344
+ this.logger(` - ${fn.name}: ${fn.description}`, {
13345
+ tags: ["discovery"]
13346
+ });
13253
13347
  }
13254
13348
  }
13255
13349
  }
@@ -13292,11 +13386,10 @@ var AxMCPClient = class {
13292
13386
  params
13293
13387
  };
13294
13388
  if (this.options.debug) {
13295
- console.log(
13296
- colorLog7.blueBright(
13297
- `> Sending request ${requestId}:
13298
- ${JSON.stringify(request, null, 2)}`
13299
- )
13389
+ this.logger(
13390
+ `> Sending request ${requestId}:
13391
+ ${JSON.stringify(request, null, 2)}`,
13392
+ { tags: ["requestStart"] }
13300
13393
  );
13301
13394
  }
13302
13395
  const responsePromise = new Promise((resolve, reject) => {
@@ -13304,11 +13397,10 @@ ${JSON.stringify(request, null, 2)}`
13304
13397
  this.transport.send(request).then((res) => {
13305
13398
  this.activeRequests.delete(requestId);
13306
13399
  if (this.options.debug) {
13307
- console.log(
13308
- colorLog7.greenBright(
13309
- `> Received response for request ${requestId}:
13310
- ${JSON.stringify(res, null, 2)}`
13311
- )
13400
+ this.logger(
13401
+ `> Received response for request ${requestId}:
13402
+ ${JSON.stringify(res, null, 2)}`,
13403
+ { tags: ["responseContent"] }
13312
13404
  );
13313
13405
  }
13314
13406
  if (res !== null && typeof res === "object" && "error" in res) {
@@ -13338,9 +13430,9 @@ ${JSON.stringify(res, null, 2)}`
13338
13430
  params
13339
13431
  };
13340
13432
  if (this.options.debug) {
13341
- console.log(
13342
- "\u27A1\uFE0F Sending notification:",
13343
- JSON.stringify(notification, null, 2)
13433
+ this.logger(
13434
+ `\u27A1\uFE0F Sending notification: ${JSON.stringify(notification, null, 2)}`,
13435
+ { tags: ["requestStart"] }
13344
13436
  );
13345
13437
  }
13346
13438
  await this.transport.sendNotification(notification);
@@ -13570,6 +13662,25 @@ var AxMultiServiceRouter = class {
13570
13662
  getOptions() {
13571
13663
  return this.options ?? {};
13572
13664
  }
13665
+ /**
13666
+ * Returns the logger from the last used service,
13667
+ * or falls back to the first service if none has been used.
13668
+ */
13669
+ getLogger() {
13670
+ let serviceInstance = this.lastUsedService;
13671
+ if (!serviceInstance) {
13672
+ const firstServiceEntry = this.services.values().next().value;
13673
+ if (firstServiceEntry) {
13674
+ serviceInstance = firstServiceEntry.service;
13675
+ }
13676
+ }
13677
+ if (!serviceInstance) {
13678
+ return (message) => {
13679
+ process.stdout.write(message);
13680
+ };
13681
+ }
13682
+ return serviceInstance.getLogger();
13683
+ }
13573
13684
  };
13574
13685
 
13575
13686
  // prompts/rag.ts