@ax-llm/ax 11.0.22 → 11.0.25

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
@@ -93,6 +93,9 @@ __export(index_exports, {
93
93
  AxJSInterpreter: () => AxJSInterpreter,
94
94
  AxJSInterpreterPermission: () => AxJSInterpreterPermission,
95
95
  AxLLMRequestTypeValues: () => AxLLMRequestTypeValues,
96
+ AxMCPClient: () => AxMCPClient,
97
+ AxMCPHTTPTransport: () => AxMCPHTTPTransport,
98
+ AxMCPStdioTransport: () => AxMCPStdioTransport,
96
99
  AxMemory: () => AxMemory,
97
100
  AxMockAIService: () => AxMockAIService,
98
101
  AxMultiServiceRouter: () => AxMultiServiceRouter,
@@ -752,7 +755,8 @@ ${hideContent ? "" : colorLog.whiteBright(msg.content ?? "<empty>")}`;
752
755
  }
753
756
  };
754
757
  var logChatRequestMessage = (msg) => {
755
- process.stdout.write(formatChatMessage(msg) + "\n");
758
+ process.stdout.write(`${formatChatMessage(msg)}
759
+ `);
756
760
  process.stdout.write(colorLog.blueBright("\nAssistant:\n"));
757
761
  };
758
762
  var logChatRequest = (chatPrompt) => {
@@ -1070,7 +1074,7 @@ var AxBaseAI = class {
1070
1074
  return res2;
1071
1075
  };
1072
1076
  if (options?.debug ?? this.debug) {
1073
- logChatRequest(req["chatPrompt"]);
1077
+ logChatRequest(req.chatPrompt);
1074
1078
  }
1075
1079
  const rt = options?.rateLimiter ?? this.rt;
1076
1080
  const rv = rt ? await rt(fn, { modelUsage: this.modelUsage }) : await fn();
@@ -1257,6 +1261,7 @@ var GoogleVertexAuth = class {
1257
1261
 
1258
1262
  // ai/anthropic/types.ts
1259
1263
  var AxAIAnthropicModel = /* @__PURE__ */ ((AxAIAnthropicModel2) => {
1264
+ AxAIAnthropicModel2["Claude37Sonnet"] = "claude-3-7-sonnet-latest";
1260
1265
  AxAIAnthropicModel2["Claude35Sonnet"] = "claude-3-5-sonnet-latest";
1261
1266
  AxAIAnthropicModel2["Claude35Haiku"] = "claude-3-5-haiku-latest";
1262
1267
  AxAIAnthropicModel2["Claude3Opus"] = "claude-3-opus-latest";
@@ -1267,6 +1272,7 @@ var AxAIAnthropicModel = /* @__PURE__ */ ((AxAIAnthropicModel2) => {
1267
1272
  return AxAIAnthropicModel2;
1268
1273
  })(AxAIAnthropicModel || {});
1269
1274
  var AxAIAnthropicVertexModel = /* @__PURE__ */ ((AxAIAnthropicVertexModel3) => {
1275
+ AxAIAnthropicVertexModel3["Claude37Sonnet"] = "claude-3-7-sonnet";
1270
1276
  AxAIAnthropicVertexModel3["Claude35Haiku"] = "claude-3-5-haiku";
1271
1277
  AxAIAnthropicVertexModel3["Claude35Sonnet"] = "claude-3-5-sonnet";
1272
1278
  AxAIAnthropicVertexModel3["Claude35SonnetV2"] = "claude-3-5-sonnet-v2";
@@ -1734,6 +1740,7 @@ var AxAIOpenAIModel = /* @__PURE__ */ ((AxAIOpenAIModel2) => {
1734
1740
  AxAIOpenAIModel2["O1Mini"] = "o1-mini";
1735
1741
  AxAIOpenAIModel2["O3Mini"] = "o3-mini";
1736
1742
  AxAIOpenAIModel2["GPT4"] = "gpt-4";
1743
+ AxAIOpenAIModel2["GPT45"] = "gpt-4.5-preview";
1737
1744
  AxAIOpenAIModel2["GPT4O"] = "gpt-4o";
1738
1745
  AxAIOpenAIModel2["GPT4OMini"] = "gpt-4o-mini";
1739
1746
  AxAIOpenAIModel2["GPT4ChatGPT4O"] = "chatgpt-4o-latest";
@@ -1754,6 +1761,12 @@ var AxAIOpenAIEmbedModel = /* @__PURE__ */ ((AxAIOpenAIEmbedModel2) => {
1754
1761
 
1755
1762
  // ai/openai/info.ts
1756
1763
  var axModelInfoOpenAI = [
1764
+ {
1765
+ name: "gpt-4.5-preview" /* GPT45 */,
1766
+ currency: "usd",
1767
+ promptTokenCostPer1M: 75,
1768
+ completionTokenCostPer1M: 150
1769
+ },
1757
1770
  {
1758
1771
  name: "o1" /* O1 */,
1759
1772
  currency: "usd",
@@ -3762,7 +3775,7 @@ var AxAI = class {
3762
3775
 
3763
3776
  // dsp/generate.ts
3764
3777
  var import_web5 = require("stream/web");
3765
- var import_api22 = require("@opentelemetry/api");
3778
+ var import_api21 = require("@opentelemetry/api");
3766
3779
 
3767
3780
  // ai/util.ts
3768
3781
  function mergeFunctionCalls(functionCalls, functionCallDeltas) {
@@ -3855,7 +3868,7 @@ var MemoryImpl = class {
3855
3868
  }
3856
3869
  }
3857
3870
  if (this.debug) {
3858
- if (delta) {
3871
+ if (delta && typeof delta === "string") {
3859
3872
  debugResponseDelta(delta);
3860
3873
  } else if (lastItem) {
3861
3874
  debugResponse({ content, name, functionCalls });
@@ -3988,10 +4001,10 @@ var AxAssertionError = class extends Error {
3988
4001
  return extraFields;
3989
4002
  };
3990
4003
  };
3991
- var assertAssertions = (asserts, values) => {
4004
+ var assertAssertions = async (asserts, values) => {
3992
4005
  for (const assert of asserts) {
3993
4006
  const { fn, message } = assert;
3994
- const res = fn(values);
4007
+ const res = await fn(values);
3995
4008
  if (res === void 0) {
3996
4009
  continue;
3997
4010
  }
@@ -4003,7 +4016,7 @@ var assertAssertions = (asserts, values) => {
4003
4016
  }
4004
4017
  }
4005
4018
  };
4006
- var assertStreamingAssertions = (asserts, xstate, content, final = false) => {
4019
+ var assertStreamingAssertions = async (asserts, xstate, content, final = false) => {
4007
4020
  if (!xstate.currField || xstate.s === -1 || !asserts || asserts.length === 0) {
4008
4021
  return;
4009
4022
  }
@@ -4016,7 +4029,7 @@ var assertStreamingAssertions = (asserts, xstate, content, final = false) => {
4016
4029
  const currValue = content.substring(xstate.s);
4017
4030
  for (const assert of fieldAsserts) {
4018
4031
  const { message, fn } = assert;
4019
- const res = fn(currValue, final);
4032
+ const res = await fn(currValue, final);
4020
4033
  if (res === void 0) {
4021
4034
  continue;
4022
4035
  }
@@ -4029,9 +4042,6 @@ var assertStreamingAssertions = (asserts, xstate, content, final = false) => {
4029
4042
  // dsp/datetime.ts
4030
4043
  var import_moment_timezone = __toESM(require("moment-timezone"), 1);
4031
4044
 
4032
- // dsp/program.ts
4033
- var import_api21 = require("@opentelemetry/api");
4034
-
4035
4045
  // dsp/registry.ts
4036
4046
  var AxInstanceRegistry = class {
4037
4047
  reg;
@@ -4562,7 +4572,7 @@ function validateField(field) {
4562
4572
 
4563
4573
  // dsp/util.ts
4564
4574
  var colorLog3 = new ColorLog();
4565
- var updateProgressBar = (current, total, success, elapsedTime, progressBarWidth = 20, msg) => {
4575
+ var updateProgressBar = (current, total, success, elapsedTime, msg, progressBarWidth = 20) => {
4566
4576
  const percentage = (current / total * 100).toFixed(1);
4567
4577
  const filledBarLength = Math.round(progressBarWidth * current / total);
4568
4578
  const emptyBarLength = progressBarWidth - filledBarLength;
@@ -4809,6 +4819,7 @@ var AxProgramWithSignature = class {
4809
4819
  async forward(_ai, _values, _options) {
4810
4820
  throw new Error("forward() not implemented");
4811
4821
  }
4822
+ // biome-ignore lint/correctness/useYield: just a placeholder
4812
4823
  async *streamingForward(_ai, _values, _options) {
4813
4824
  throw new Error("streamingForward() not implemented");
4814
4825
  }
@@ -4906,6 +4917,7 @@ var AxProgram = class {
4906
4917
  async forward(_ai, _values, _options) {
4907
4918
  throw new Error("forward() not implemented");
4908
4919
  }
4920
+ // biome-ignore lint/correctness/useYield: just a placeholder
4909
4921
  async *streamingForward(_ai, _values, _options) {
4910
4922
  throw new Error("streamingForward() not implemented");
4911
4923
  }
@@ -4985,9 +4997,7 @@ var AxPromptTemplate = class {
4985
4997
  task.push(
4986
4998
  `You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
4987
4999
  );
4988
- const funcs = functions?.map(
4989
- (f) => "toFunction" in f ? f.toFunction() : f
4990
- );
5000
+ const funcs = functions?.map((f) => "toFunction" in f ? f.toFunction() : f)?.flat();
4991
5001
  const funcList = funcs?.map((fn) => `- \`${fn.name}\`: ${formatDescription(fn.description)}`).join("\n");
4992
5002
  if (funcList && funcList.length > 0) {
4993
5003
  task.push(`## Available Functions
@@ -5886,10 +5896,10 @@ var AxFunctionProcessor = class {
5886
5896
  (v) => v.name.localeCompare(func.name) === 0
5887
5897
  );
5888
5898
  if (!fnSpec) {
5889
- throw new Error(`Function not found: ` + func.name);
5899
+ throw new Error(`Function not found: ${func.name}`);
5890
5900
  }
5891
5901
  if (!fnSpec.func) {
5892
- throw new Error("No handler for function: " + func.name);
5902
+ throw new Error(`No handler for function: ${func.name}`);
5893
5903
  }
5894
5904
  try {
5895
5905
  return await this.executeFunction(fnSpec, func, options);
@@ -5910,9 +5920,11 @@ var parseFunctions = (newFuncs, existingFuncs) => {
5910
5920
  return f.toFunction();
5911
5921
  }
5912
5922
  return f;
5913
- });
5923
+ }).flat();
5914
5924
  for (const fn of functions.filter((v) => v.parameters)) {
5915
- validateJSONSchema(fn.parameters);
5925
+ if (fn.parameters) {
5926
+ validateJSONSchema(fn.parameters);
5927
+ }
5916
5928
  }
5917
5929
  return [...existingFuncs ?? [], ...functions];
5918
5930
  };
@@ -5958,11 +5970,11 @@ ${result}
5958
5970
  return promise;
5959
5971
  });
5960
5972
  const results = await Promise.all(promises);
5961
- results.forEach((result) => {
5973
+ for (const result of results) {
5962
5974
  if (result) {
5963
5975
  mem.add(result, sessionId);
5964
5976
  }
5965
- });
5977
+ }
5966
5978
  return functionsExecuted;
5967
5979
  };
5968
5980
  function parseFunctionCalls(ai, functionCalls, values, model) {
@@ -6046,13 +6058,14 @@ var AxGen = class extends AxProgramWithSignature {
6046
6058
  model,
6047
6059
  rateLimiter,
6048
6060
  stream,
6049
- functions,
6061
+ functions: _functions,
6050
6062
  functionCall: _functionCall
6051
6063
  } = options ?? {};
6052
6064
  const chatPrompt = mem?.history(sessionId) ?? [];
6053
6065
  if (chatPrompt.length === 0) {
6054
6066
  throw new Error("No chat prompt found");
6055
6067
  }
6068
+ const functions = _functions?.map((f) => "toFunction" in f ? f.toFunction() : f)?.flat();
6056
6069
  const functionCall = _functionCall ?? this.options?.functionCall;
6057
6070
  const res = await ai.chat(
6058
6071
  {
@@ -6077,13 +6090,14 @@ var AxGen = class extends AxProgramWithSignature {
6077
6090
  mem,
6078
6091
  options
6079
6092
  }) {
6080
- const { sessionId, traceId, model, functions } = options ?? {};
6093
+ const { sessionId, traceId, model, functions: _functions } = options ?? {};
6081
6094
  const fastFail = options?.fastFail ?? this.options?.fastFail;
6082
6095
  const modelName = model ?? ai.getDefaultModels().model;
6083
6096
  const usageInfo = {
6084
6097
  ai: ai.getName(),
6085
6098
  model: modelName
6086
6099
  };
6100
+ const functions = _functions?.map((f) => "toFunction" in f ? f.toFunction() : f)?.flat();
6087
6101
  const res = await this.forwardSendRequest({
6088
6102
  ai,
6089
6103
  mem,
@@ -6167,7 +6181,11 @@ var AxGen = class extends AxProgramWithSignature {
6167
6181
  streamingValidation
6168
6182
  );
6169
6183
  if (this.streamingAsserts.length !== 0) {
6170
- assertStreamingAssertions(this.streamingAsserts, xstate, content);
6184
+ await assertStreamingAssertions(
6185
+ this.streamingAsserts,
6186
+ xstate,
6187
+ content
6188
+ );
6171
6189
  }
6172
6190
  if (this.streamingFieldProcessors.length !== 0) {
6173
6191
  await processStreamingFieldProcessors(
@@ -6183,7 +6201,7 @@ var AxGen = class extends AxProgramWithSignature {
6183
6201
  if (skip) {
6184
6202
  continue;
6185
6203
  }
6186
- assertAssertions(this.asserts, values);
6204
+ await assertAssertions(this.asserts, values);
6187
6205
  }
6188
6206
  if (result.finishReason === "length") {
6189
6207
  throw new Error("Max tokens reached before completion");
@@ -6205,8 +6223,13 @@ var AxGen = class extends AxProgramWithSignature {
6205
6223
  this.functionsExecuted = /* @__PURE__ */ new Set([...this.functionsExecuted, ...fx]);
6206
6224
  } else {
6207
6225
  streamingExtractFinalValue(this.signature, values, xstate, content);
6208
- assertStreamingAssertions(this.streamingAsserts, xstate, content, true);
6209
- assertAssertions(this.asserts, values);
6226
+ await assertStreamingAssertions(
6227
+ this.streamingAsserts,
6228
+ xstate,
6229
+ content,
6230
+ true
6231
+ );
6232
+ await assertAssertions(this.asserts, values);
6210
6233
  if (this.fieldProcessors.length) {
6211
6234
  await processFieldProcessors(
6212
6235
  this.fieldProcessors,
@@ -6266,7 +6289,7 @@ var AxGen = class extends AxProgramWithSignature {
6266
6289
  }
6267
6290
  } else if (result.content) {
6268
6291
  extractValues(this.signature, values, result.content);
6269
- assertAssertions(this.asserts, values);
6292
+ await assertAssertions(this.asserts, values);
6270
6293
  if (this.fieldProcessors.length) {
6271
6294
  await processFieldProcessors(
6272
6295
  this.fieldProcessors,
@@ -6384,11 +6407,11 @@ var AxGen = class extends AxProgramWithSignature {
6384
6407
  }
6385
6408
  const funcNames = functions?.map((f) => f.name).join(",");
6386
6409
  const attributes = {
6387
- ["generate.signature"]: this.signature.toString(),
6388
- ["generate.functions"]: funcNames ?? ""
6410
+ "generate.signature": this.signature.toString(),
6411
+ "generate.functions": funcNames ?? ""
6389
6412
  };
6390
6413
  const span = tracer.startSpan("Generate", {
6391
- kind: import_api22.SpanKind.SERVER,
6414
+ kind: import_api21.SpanKind.SERVER,
6392
6415
  attributes
6393
6416
  });
6394
6417
  try {
@@ -6431,7 +6454,7 @@ var AxGen = class extends AxProgramWithSignature {
6431
6454
 
6432
6455
  // prompts/agent.ts
6433
6456
  function processChildAgentFunction(childFunction, parentValues, parentInputKeys, modelList, options) {
6434
- let processedFunction = { ...childFunction };
6457
+ const processedFunction = { ...childFunction };
6435
6458
  if (processedFunction.parameters) {
6436
6459
  const childKeys = processedFunction.parameters.properties ? Object.keys(processedFunction.parameters.properties) : [];
6437
6460
  const commonKeys = parentInputKeys.filter((key) => childKeys.includes(key)).filter((key) => key !== "model");
@@ -6503,7 +6526,7 @@ var AxAgent = class {
6503
6526
  this.debug = debug;
6504
6527
  if (!name || name.length < 5) {
6505
6528
  throw new Error(
6506
- `Agent name must be at least 10 characters (more descriptive)`
6529
+ "Agent name must be at least 10 characters (more descriptive)"
6507
6530
  );
6508
6531
  }
6509
6532
  if (!description || description.length < 20) {
@@ -7065,8 +7088,8 @@ var AxBootstrapFewShot = class {
7065
7088
  total,
7066
7089
  this.traces.length,
7067
7090
  et,
7068
- 30,
7069
- "Tuning Prompt"
7091
+ "Tuning Prompt",
7092
+ 30
7070
7093
  );
7071
7094
  if (this.traces.length > maxDemos) {
7072
7095
  return;
@@ -7119,7 +7142,7 @@ var randomSample = (array, n) => {
7119
7142
  };
7120
7143
 
7121
7144
  // db/base.ts
7122
- var import_api23 = require("@opentelemetry/api");
7145
+ var import_api22 = require("@opentelemetry/api");
7123
7146
  var AxDBBase = class {
7124
7147
  name;
7125
7148
  fetch;
@@ -7146,7 +7169,7 @@ var AxDBBase = class {
7146
7169
  return await this.tracer?.startActiveSpan(
7147
7170
  "DB Upsert Request",
7148
7171
  {
7149
- kind: import_api23.SpanKind.SERVER,
7172
+ kind: import_api22.SpanKind.SERVER,
7150
7173
  attributes: {
7151
7174
  [axSpanAttributes.DB_SYSTEM]: this.name,
7152
7175
  [axSpanAttributes.DB_OPERATION_NAME]: "upsert",
@@ -7180,7 +7203,7 @@ var AxDBBase = class {
7180
7203
  return await this.tracer?.startActiveSpan(
7181
7204
  "DB Batch Upsert Request",
7182
7205
  {
7183
- kind: import_api23.SpanKind.SERVER,
7206
+ kind: import_api22.SpanKind.SERVER,
7184
7207
  attributes: {
7185
7208
  [axSpanAttributes.DB_SYSTEM]: this.name,
7186
7209
  [axSpanAttributes.DB_OPERATION_NAME]: "upsert",
@@ -7208,7 +7231,7 @@ var AxDBBase = class {
7208
7231
  return await this.tracer?.startActiveSpan(
7209
7232
  "DB Query Request",
7210
7233
  {
7211
- kind: import_api23.SpanKind.SERVER,
7234
+ kind: import_api22.SpanKind.SERVER,
7212
7235
  attributes: {
7213
7236
  [axSpanAttributes.DB_SYSTEM]: this.name,
7214
7237
  [axSpanAttributes.DB_OPERATION_NAME]: "upsert",
@@ -8160,12 +8183,12 @@ var AxHFDataLoader = class {
8160
8183
 
8161
8184
  // funcs/code.ts
8162
8185
  var _crypto = __toESM(require("crypto"), 1);
8186
+ var _fs = __toESM(require("fs"), 1);
8163
8187
  var _http = __toESM(require("http"), 1);
8164
8188
  var _https = __toESM(require("https"), 1);
8165
- var _fs = __toESM(require("fs"), 1);
8166
8189
  var _os = __toESM(require("os"), 1);
8167
8190
  var _process = __toESM(require("process"), 1);
8168
- var import_vm = require("vm");
8191
+ var import_node_vm = require("vm");
8169
8192
  var AxJSInterpreterPermission = /* @__PURE__ */ ((AxJSInterpreterPermission2) => {
8170
8193
  AxJSInterpreterPermission2["FS"] = "node:fs";
8171
8194
  AxJSInterpreterPermission2["NET"] = "net";
@@ -8199,7 +8222,7 @@ var AxJSInterpreter = class {
8199
8222
  if (this.permissions.includes("process" /* PROCESS */)) {
8200
8223
  context.process = _process;
8201
8224
  }
8202
- return (0, import_vm.runInNewContext)(`(function() { ${code} })()`, context);
8225
+ return (0, import_node_vm.runInNewContext)(`(function() { ${code} })()`, context);
8203
8226
  }
8204
8227
  toFunction() {
8205
8228
  return {
@@ -8436,7 +8459,7 @@ var AxTestPrompt = class {
8436
8459
  successCount++;
8437
8460
  }
8438
8461
  const et = (/* @__PURE__ */ new Date()).getTime() - st;
8439
- updateProgressBar(i, total, successCount, et, 30, "Testing Prompt");
8462
+ updateProgressBar(i, total, successCount, et, "Testing Prompt", 30);
8440
8463
  }
8441
8464
  console.log(
8442
8465
  "\nPerformance: ",
@@ -8602,6 +8625,213 @@ var AxEmbeddingAdapter = class {
8602
8625
  }
8603
8626
  };
8604
8627
 
8628
+ // mcp/client.ts
8629
+ var colorLog7 = new ColorLog();
8630
+ var AxMCPClient = class {
8631
+ constructor(transport, options = {}) {
8632
+ this.transport = transport;
8633
+ this.options = options;
8634
+ }
8635
+ functions = [];
8636
+ requestId = 0;
8637
+ capabilities = {};
8638
+ async init() {
8639
+ if ("connect" in this.transport) {
8640
+ await this.transport.connect?.();
8641
+ }
8642
+ const res = await this.sendRequest("initialize", {
8643
+ protocolVersion: "2024-11-05",
8644
+ capabilities: {
8645
+ roots: { listChanged: true },
8646
+ sampling: {}
8647
+ },
8648
+ clientInfo: {
8649
+ name: "AxMCPClient",
8650
+ version: "1.0.0"
8651
+ }
8652
+ });
8653
+ if (res.capabilities.tools) {
8654
+ this.capabilities.tools = true;
8655
+ }
8656
+ if (res.capabilities.resources) {
8657
+ this.capabilities.resources = true;
8658
+ }
8659
+ if (res.capabilities.prompts) {
8660
+ this.capabilities.prompts = true;
8661
+ }
8662
+ await this.sendNotification("initialized");
8663
+ await this.discoverFunctions();
8664
+ }
8665
+ async discoverFunctions() {
8666
+ if (!this.capabilities.tools) {
8667
+ throw new Error("Tools are not supported");
8668
+ }
8669
+ const res = await this.sendRequest(
8670
+ "tools/list"
8671
+ );
8672
+ this.functions = res.tools.map(
8673
+ (fn) => ({
8674
+ name: fn.name,
8675
+ description: fn.description,
8676
+ parameters: fn.inputSchema,
8677
+ func: async (args) => {
8678
+ const result = await this.sendRequest("tools/call", { name: fn.name, arguments: args });
8679
+ return result;
8680
+ }
8681
+ })
8682
+ );
8683
+ }
8684
+ async ping() {
8685
+ await this.sendRequest("ping");
8686
+ }
8687
+ toFunction() {
8688
+ return this.functions;
8689
+ }
8690
+ async sendRequest(method, params) {
8691
+ const request = {
8692
+ jsonrpc: "2.0",
8693
+ id: ++this.requestId,
8694
+ method,
8695
+ params
8696
+ };
8697
+ if (this.options.debug) {
8698
+ console.log(
8699
+ colorLog7.blueBright(
8700
+ `> Sending request:
8701
+ ${JSON.stringify(request, null, 2)}`
8702
+ )
8703
+ );
8704
+ }
8705
+ const res = await this.transport.send(request);
8706
+ if (this.options.debug) {
8707
+ console.log(
8708
+ colorLog7.greenBright(
8709
+ `> Received response:
8710
+ ${JSON.stringify(res, null, 2)}`
8711
+ )
8712
+ );
8713
+ }
8714
+ if ("error" in res) {
8715
+ throw new Error(`RPC Error ${res.error.code}: ${res.error.message}`);
8716
+ }
8717
+ if ("result" in res) {
8718
+ return res.result;
8719
+ }
8720
+ throw new Error("Invalid response no result or error");
8721
+ }
8722
+ async sendNotification(method, params) {
8723
+ const notification = {
8724
+ jsonrpc: "2.0",
8725
+ method,
8726
+ params
8727
+ };
8728
+ if (this.options.debug) {
8729
+ console.log(
8730
+ "\u27A1\uFE0F Sending notification:",
8731
+ JSON.stringify(notification, null, 2)
8732
+ );
8733
+ }
8734
+ await this.transport.sendNotification(notification);
8735
+ }
8736
+ };
8737
+
8738
+ // mcp/httpTransport.ts
8739
+ var AxMCPHTTPTransport = class {
8740
+ endpoint = null;
8741
+ sseUrl;
8742
+ eventSource;
8743
+ constructor(sseUrl) {
8744
+ this.sseUrl = sseUrl;
8745
+ }
8746
+ async connect() {
8747
+ return new Promise((resolve, reject) => {
8748
+ this.eventSource = new EventSource(this.sseUrl);
8749
+ this.eventSource.addEventListener("endpoint", (event) => {
8750
+ try {
8751
+ const messageEvent = event;
8752
+ const data = JSON.parse(messageEvent.data);
8753
+ if (!data.uri) {
8754
+ throw new Error("Endpoint URI missing in SSE event data");
8755
+ }
8756
+ this.endpoint = data.uri;
8757
+ resolve();
8758
+ } catch (error) {
8759
+ reject(error);
8760
+ }
8761
+ });
8762
+ this.eventSource.onerror = () => {
8763
+ reject(new Error("Failed to establish SSE connection"));
8764
+ };
8765
+ });
8766
+ }
8767
+ async send(message) {
8768
+ if (!this.endpoint) {
8769
+ throw new Error(
8770
+ "HTTPTransport endpoint is not initialized. Call connect() first."
8771
+ );
8772
+ }
8773
+ const res = await fetch(this.endpoint, {
8774
+ method: "POST",
8775
+ headers: { "Content-Type": "application/json" },
8776
+ body: JSON.stringify(message)
8777
+ });
8778
+ if (!res.ok) {
8779
+ throw new Error(`HTTP error ${res.status}: ${res.statusText}`);
8780
+ }
8781
+ return res.json();
8782
+ }
8783
+ async sendNotification(message) {
8784
+ if (!this.endpoint) {
8785
+ throw new Error(
8786
+ "HTTPTransport endpoint is not initialized. Call connect() first."
8787
+ );
8788
+ }
8789
+ await fetch(this.endpoint, {
8790
+ method: "POST",
8791
+ headers: { "Content-Type": "application/json" },
8792
+ body: JSON.stringify(message)
8793
+ });
8794
+ }
8795
+ };
8796
+
8797
+ // mcp/stdioTransport.ts
8798
+ var import_node_child_process = require("child_process");
8799
+ var import_node_readline = __toESM(require("readline"), 1);
8800
+ var AxMCPStdioTransport = class {
8801
+ process;
8802
+ rl;
8803
+ pendingResponses = /* @__PURE__ */ new Map();
8804
+ constructor(config) {
8805
+ this.process = (0, import_node_child_process.spawn)(config.command, config.args ?? [], {
8806
+ env: config.env ? { ...process.env, ...config.env } : process.env
8807
+ });
8808
+ this.rl = import_node_readline.default.createInterface({ input: this.process.stdout });
8809
+ this.rl.on("line", (line) => {
8810
+ const response = JSON.parse(line);
8811
+ const resolver = this.pendingResponses.get(response.id);
8812
+ if (resolver) {
8813
+ resolver(response);
8814
+ this.pendingResponses.delete(response.id);
8815
+ }
8816
+ });
8817
+ }
8818
+ async send(message) {
8819
+ return new Promise((resolve) => {
8820
+ this.pendingResponses.set(message.id, (res) => {
8821
+ resolve(res);
8822
+ });
8823
+ this.process.stdin.write(`${JSON.stringify(message)}
8824
+ `);
8825
+ });
8826
+ }
8827
+ async sendNotification(message) {
8828
+ this.process.stdin.write(`${JSON.stringify(message)}
8829
+ `);
8830
+ }
8831
+ async connect() {
8832
+ }
8833
+ };
8834
+
8605
8835
  // ai/multiservice.ts
8606
8836
  var AxMultiServiceRouter = class {
8607
8837
  services = /* @__PURE__ */ new Map();
@@ -8854,6 +9084,9 @@ var AxRAG = class extends AxChainOfThought {
8854
9084
  AxJSInterpreter,
8855
9085
  AxJSInterpreterPermission,
8856
9086
  AxLLMRequestTypeValues,
9087
+ AxMCPClient,
9088
+ AxMCPHTTPTransport,
9089
+ AxMCPStdioTransport,
8857
9090
  AxMemory,
8858
9091
  AxMockAIService,
8859
9092
  AxMultiServiceRouter,