@ax-llm/ax 11.0.25 → 11.0.26
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 +142 -35
- package/index.cjs.map +1 -1
- package/index.d.cts +40 -2
- package/index.d.ts +40 -2
- package/index.js +142 -35
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -2448,20 +2448,58 @@ interface AxMCPTransport {
|
|
|
2448
2448
|
connect?(): Promise<void>;
|
|
2449
2449
|
}
|
|
2450
2450
|
|
|
2451
|
+
/**
|
|
2452
|
+
* Configuration for overriding function properties
|
|
2453
|
+
*/
|
|
2454
|
+
interface FunctionOverride {
|
|
2455
|
+
/** Original function name to override */
|
|
2456
|
+
name: string;
|
|
2457
|
+
/** Updates to apply to the function */
|
|
2458
|
+
updates: {
|
|
2459
|
+
/** Alternative name for the function */
|
|
2460
|
+
name?: string;
|
|
2461
|
+
/** Alternative description for the function */
|
|
2462
|
+
description?: string;
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2465
|
+
/**
|
|
2466
|
+
* Options for the MCP client
|
|
2467
|
+
*/
|
|
2451
2468
|
interface AxMCPClientOptions {
|
|
2469
|
+
/** Enable debug logging */
|
|
2452
2470
|
debug?: boolean;
|
|
2471
|
+
/**
|
|
2472
|
+
* List of function overrides
|
|
2473
|
+
* Use this to provide alternative names and descriptions for functions
|
|
2474
|
+
* while preserving their original functionality
|
|
2475
|
+
*
|
|
2476
|
+
* Example:
|
|
2477
|
+
* ```
|
|
2478
|
+
* functionOverrides: [
|
|
2479
|
+
* {
|
|
2480
|
+
* name: "original-function-name",
|
|
2481
|
+
* updates: {
|
|
2482
|
+
* name: "new-function-name",
|
|
2483
|
+
* description: "New function description"
|
|
2484
|
+
* }
|
|
2485
|
+
* }
|
|
2486
|
+
* ]
|
|
2487
|
+
* ```
|
|
2488
|
+
*/
|
|
2489
|
+
functionOverrides?: FunctionOverride[];
|
|
2453
2490
|
}
|
|
2454
2491
|
declare class AxMCPClient {
|
|
2455
2492
|
private readonly transport;
|
|
2456
2493
|
private readonly options;
|
|
2457
2494
|
private functions;
|
|
2458
|
-
private
|
|
2495
|
+
private activeRequests;
|
|
2459
2496
|
private capabilities;
|
|
2460
2497
|
constructor(transport: AxMCPTransport, options?: Readonly<AxMCPClientOptions>);
|
|
2461
2498
|
init(): Promise<void>;
|
|
2462
2499
|
private discoverFunctions;
|
|
2463
|
-
ping(): Promise<void>;
|
|
2500
|
+
ping(timeout?: number): Promise<void>;
|
|
2464
2501
|
toFunction(): AxFunction[];
|
|
2502
|
+
cancelRequest(id: string): void;
|
|
2465
2503
|
private sendRequest;
|
|
2466
2504
|
private sendNotification;
|
|
2467
2505
|
}
|
package/index.d.ts
CHANGED
|
@@ -2448,20 +2448,58 @@ interface AxMCPTransport {
|
|
|
2448
2448
|
connect?(): Promise<void>;
|
|
2449
2449
|
}
|
|
2450
2450
|
|
|
2451
|
+
/**
|
|
2452
|
+
* Configuration for overriding function properties
|
|
2453
|
+
*/
|
|
2454
|
+
interface FunctionOverride {
|
|
2455
|
+
/** Original function name to override */
|
|
2456
|
+
name: string;
|
|
2457
|
+
/** Updates to apply to the function */
|
|
2458
|
+
updates: {
|
|
2459
|
+
/** Alternative name for the function */
|
|
2460
|
+
name?: string;
|
|
2461
|
+
/** Alternative description for the function */
|
|
2462
|
+
description?: string;
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2465
|
+
/**
|
|
2466
|
+
* Options for the MCP client
|
|
2467
|
+
*/
|
|
2451
2468
|
interface AxMCPClientOptions {
|
|
2469
|
+
/** Enable debug logging */
|
|
2452
2470
|
debug?: boolean;
|
|
2471
|
+
/**
|
|
2472
|
+
* List of function overrides
|
|
2473
|
+
* Use this to provide alternative names and descriptions for functions
|
|
2474
|
+
* while preserving their original functionality
|
|
2475
|
+
*
|
|
2476
|
+
* Example:
|
|
2477
|
+
* ```
|
|
2478
|
+
* functionOverrides: [
|
|
2479
|
+
* {
|
|
2480
|
+
* name: "original-function-name",
|
|
2481
|
+
* updates: {
|
|
2482
|
+
* name: "new-function-name",
|
|
2483
|
+
* description: "New function description"
|
|
2484
|
+
* }
|
|
2485
|
+
* }
|
|
2486
|
+
* ]
|
|
2487
|
+
* ```
|
|
2488
|
+
*/
|
|
2489
|
+
functionOverrides?: FunctionOverride[];
|
|
2453
2490
|
}
|
|
2454
2491
|
declare class AxMCPClient {
|
|
2455
2492
|
private readonly transport;
|
|
2456
2493
|
private readonly options;
|
|
2457
2494
|
private functions;
|
|
2458
|
-
private
|
|
2495
|
+
private activeRequests;
|
|
2459
2496
|
private capabilities;
|
|
2460
2497
|
constructor(transport: AxMCPTransport, options?: Readonly<AxMCPClientOptions>);
|
|
2461
2498
|
init(): Promise<void>;
|
|
2462
2499
|
private discoverFunctions;
|
|
2463
|
-
ping(): Promise<void>;
|
|
2500
|
+
ping(timeout?: number): Promise<void>;
|
|
2464
2501
|
toFunction(): AxFunction[];
|
|
2502
|
+
cancelRequest(id: string): void;
|
|
2465
2503
|
private sendRequest;
|
|
2466
2504
|
private sendNotification;
|
|
2467
2505
|
}
|
package/index.js
CHANGED
|
@@ -8519,6 +8519,53 @@ var AxEmbeddingAdapter = class {
|
|
|
8519
8519
|
}
|
|
8520
8520
|
};
|
|
8521
8521
|
|
|
8522
|
+
// ../../node_modules/uuid/dist/esm-node/rng.js
|
|
8523
|
+
import crypto2 from "crypto";
|
|
8524
|
+
var rnds8Pool = new Uint8Array(256);
|
|
8525
|
+
var poolPtr = rnds8Pool.length;
|
|
8526
|
+
function rng() {
|
|
8527
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
8528
|
+
crypto2.randomFillSync(rnds8Pool);
|
|
8529
|
+
poolPtr = 0;
|
|
8530
|
+
}
|
|
8531
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
8532
|
+
}
|
|
8533
|
+
|
|
8534
|
+
// ../../node_modules/uuid/dist/esm-node/stringify.js
|
|
8535
|
+
var byteToHex = [];
|
|
8536
|
+
for (let i = 0; i < 256; ++i) {
|
|
8537
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
8538
|
+
}
|
|
8539
|
+
function unsafeStringify(arr, offset = 0) {
|
|
8540
|
+
return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
|
|
8541
|
+
}
|
|
8542
|
+
|
|
8543
|
+
// ../../node_modules/uuid/dist/esm-node/native.js
|
|
8544
|
+
import crypto3 from "crypto";
|
|
8545
|
+
var native_default = {
|
|
8546
|
+
randomUUID: crypto3.randomUUID
|
|
8547
|
+
};
|
|
8548
|
+
|
|
8549
|
+
// ../../node_modules/uuid/dist/esm-node/v4.js
|
|
8550
|
+
function v4(options, buf, offset) {
|
|
8551
|
+
if (native_default.randomUUID && !buf && !options) {
|
|
8552
|
+
return native_default.randomUUID();
|
|
8553
|
+
}
|
|
8554
|
+
options = options || {};
|
|
8555
|
+
const rnds = options.random || (options.rng || rng)();
|
|
8556
|
+
rnds[6] = rnds[6] & 15 | 64;
|
|
8557
|
+
rnds[8] = rnds[8] & 63 | 128;
|
|
8558
|
+
if (buf) {
|
|
8559
|
+
offset = offset || 0;
|
|
8560
|
+
for (let i = 0; i < 16; ++i) {
|
|
8561
|
+
buf[offset + i] = rnds[i];
|
|
8562
|
+
}
|
|
8563
|
+
return buf;
|
|
8564
|
+
}
|
|
8565
|
+
return unsafeStringify(rnds);
|
|
8566
|
+
}
|
|
8567
|
+
var v4_default = v4;
|
|
8568
|
+
|
|
8522
8569
|
// mcp/client.ts
|
|
8523
8570
|
var colorLog7 = new ColorLog();
|
|
8524
8571
|
var AxMCPClient = class {
|
|
@@ -8527,13 +8574,13 @@ var AxMCPClient = class {
|
|
|
8527
8574
|
this.options = options;
|
|
8528
8575
|
}
|
|
8529
8576
|
functions = [];
|
|
8530
|
-
|
|
8577
|
+
activeRequests = /* @__PURE__ */ new Map();
|
|
8531
8578
|
capabilities = {};
|
|
8532
8579
|
async init() {
|
|
8533
8580
|
if ("connect" in this.transport) {
|
|
8534
8581
|
await this.transport.connect?.();
|
|
8535
8582
|
}
|
|
8536
|
-
const res = await this.sendRequest("initialize", {
|
|
8583
|
+
const { result: res } = await this.sendRequest("initialize", {
|
|
8537
8584
|
protocolVersion: "2024-11-05",
|
|
8538
8585
|
capabilities: {
|
|
8539
8586
|
roots: { listChanged: true },
|
|
@@ -8544,6 +8591,12 @@ var AxMCPClient = class {
|
|
|
8544
8591
|
version: "1.0.0"
|
|
8545
8592
|
}
|
|
8546
8593
|
});
|
|
8594
|
+
const expectedProtocolVersion = "2024-11-05";
|
|
8595
|
+
if (res.protocolVersion !== expectedProtocolVersion) {
|
|
8596
|
+
throw new Error(
|
|
8597
|
+
`Protocol version mismatch. Expected ${expectedProtocolVersion} but got ${res.protocolVersion}`
|
|
8598
|
+
);
|
|
8599
|
+
}
|
|
8547
8600
|
if (res.capabilities.tools) {
|
|
8548
8601
|
this.capabilities.tools = true;
|
|
8549
8602
|
}
|
|
@@ -8553,67 +8606,121 @@ var AxMCPClient = class {
|
|
|
8553
8606
|
if (res.capabilities.prompts) {
|
|
8554
8607
|
this.capabilities.prompts = true;
|
|
8555
8608
|
}
|
|
8556
|
-
await this.sendNotification("initialized");
|
|
8609
|
+
await this.sendNotification("notifications/initialized");
|
|
8557
8610
|
await this.discoverFunctions();
|
|
8558
8611
|
}
|
|
8559
8612
|
async discoverFunctions() {
|
|
8560
8613
|
if (!this.capabilities.tools) {
|
|
8561
8614
|
throw new Error("Tools are not supported");
|
|
8562
8615
|
}
|
|
8563
|
-
const res = await this.sendRequest(
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
|
|
8616
|
+
const { result: res } = await this.sendRequest("tools/list");
|
|
8617
|
+
this.functions = res.tools.map((fn) => {
|
|
8618
|
+
const override = this.options.functionOverrides?.find(
|
|
8619
|
+
(o) => o.name === fn.name
|
|
8620
|
+
);
|
|
8621
|
+
const parameters = fn.inputSchema.properties ? {
|
|
8622
|
+
properties: fn.inputSchema.properties,
|
|
8623
|
+
required: fn.inputSchema.required ?? [],
|
|
8624
|
+
type: fn.inputSchema.type
|
|
8625
|
+
} : void 0;
|
|
8626
|
+
return {
|
|
8627
|
+
name: override?.updates.name ?? fn.name,
|
|
8628
|
+
description: override?.updates.description ?? fn.description,
|
|
8629
|
+
parameters,
|
|
8571
8630
|
func: async (args) => {
|
|
8572
|
-
const result = await this.sendRequest("tools/call", { name: fn.name, arguments: args });
|
|
8631
|
+
const { result } = await this.sendRequest("tools/call", { name: fn.name, arguments: args });
|
|
8573
8632
|
return result;
|
|
8574
8633
|
}
|
|
8575
|
-
}
|
|
8576
|
-
);
|
|
8634
|
+
};
|
|
8635
|
+
});
|
|
8636
|
+
if (this.options.debug) {
|
|
8637
|
+
console.log(
|
|
8638
|
+
colorLog7.yellow(`> Discovered ${this.functions.length} functions:`)
|
|
8639
|
+
);
|
|
8640
|
+
for (const fn of this.functions) {
|
|
8641
|
+
console.log(colorLog7.yellow(` - ${fn.name}: ${fn.description}`));
|
|
8642
|
+
}
|
|
8643
|
+
}
|
|
8577
8644
|
}
|
|
8578
|
-
async ping() {
|
|
8579
|
-
|
|
8645
|
+
async ping(timeout = 3e3) {
|
|
8646
|
+
const pingPromise = this.sendRequest("ping");
|
|
8647
|
+
const timeoutPromise = new Promise(
|
|
8648
|
+
(_, reject) => setTimeout(
|
|
8649
|
+
() => reject(new Error("Ping response timeout exceeded")),
|
|
8650
|
+
timeout
|
|
8651
|
+
)
|
|
8652
|
+
);
|
|
8653
|
+
const response = await Promise.race([pingPromise, timeoutPromise]);
|
|
8654
|
+
const { result } = response;
|
|
8655
|
+
if (typeof result !== "object" || result === null || Object.keys(result).length !== 0) {
|
|
8656
|
+
throw new Error(`Unexpected ping response: ${JSON.stringify(result)}`);
|
|
8657
|
+
}
|
|
8580
8658
|
}
|
|
8581
8659
|
toFunction() {
|
|
8582
8660
|
return this.functions;
|
|
8583
8661
|
}
|
|
8584
|
-
|
|
8662
|
+
cancelRequest(id) {
|
|
8663
|
+
if (this.activeRequests.has(id)) {
|
|
8664
|
+
this.sendNotification("notifications/cancelled", {
|
|
8665
|
+
requestId: id,
|
|
8666
|
+
reason: "Client cancelled request"
|
|
8667
|
+
});
|
|
8668
|
+
const entry = this.activeRequests.get(id);
|
|
8669
|
+
if (entry) {
|
|
8670
|
+
entry.reject(new Error(`Request ${id} cancelled`));
|
|
8671
|
+
}
|
|
8672
|
+
this.activeRequests.delete(id);
|
|
8673
|
+
}
|
|
8674
|
+
}
|
|
8675
|
+
async sendRequest(method, params = {}) {
|
|
8676
|
+
const requestId = v4_default();
|
|
8585
8677
|
const request = {
|
|
8586
8678
|
jsonrpc: "2.0",
|
|
8587
|
-
id:
|
|
8679
|
+
id: requestId,
|
|
8588
8680
|
method,
|
|
8589
8681
|
params
|
|
8590
8682
|
};
|
|
8591
8683
|
if (this.options.debug) {
|
|
8592
8684
|
console.log(
|
|
8593
8685
|
colorLog7.blueBright(
|
|
8594
|
-
`> Sending request:
|
|
8686
|
+
`> Sending request ${requestId}:
|
|
8595
8687
|
${JSON.stringify(request, null, 2)}`
|
|
8596
8688
|
)
|
|
8597
8689
|
);
|
|
8598
8690
|
}
|
|
8599
|
-
const
|
|
8600
|
-
|
|
8601
|
-
|
|
8602
|
-
|
|
8603
|
-
|
|
8691
|
+
const responsePromise = new Promise((resolve, reject) => {
|
|
8692
|
+
this.activeRequests.set(requestId, { reject });
|
|
8693
|
+
this.transport.send(request).then((res) => {
|
|
8694
|
+
this.activeRequests.delete(requestId);
|
|
8695
|
+
if (this.options.debug) {
|
|
8696
|
+
console.log(
|
|
8697
|
+
colorLog7.greenBright(
|
|
8698
|
+
`> Received response for request ${requestId}:
|
|
8604
8699
|
${JSON.stringify(res, null, 2)}`
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
|
|
8614
|
-
|
|
8700
|
+
)
|
|
8701
|
+
);
|
|
8702
|
+
}
|
|
8703
|
+
if (res !== null && typeof res === "object" && "error" in res) {
|
|
8704
|
+
const errorObj = res;
|
|
8705
|
+
reject(
|
|
8706
|
+
new Error(
|
|
8707
|
+
`RPC Error ${errorObj.error.code}: ${errorObj.error.message}`
|
|
8708
|
+
)
|
|
8709
|
+
);
|
|
8710
|
+
} else if (res !== null && typeof res === "object" && "result" in res) {
|
|
8711
|
+
resolve({ result: res.result });
|
|
8712
|
+
} else {
|
|
8713
|
+
reject(new Error("Invalid response no result or error"));
|
|
8714
|
+
}
|
|
8715
|
+
}).catch((err) => {
|
|
8716
|
+
this.activeRequests.delete(requestId);
|
|
8717
|
+
reject(err);
|
|
8718
|
+
});
|
|
8719
|
+
});
|
|
8720
|
+
const { result } = await responsePromise;
|
|
8721
|
+
return { id: requestId, result };
|
|
8615
8722
|
}
|
|
8616
|
-
async sendNotification(method, params) {
|
|
8723
|
+
async sendNotification(method, params = {}) {
|
|
8617
8724
|
const notification = {
|
|
8618
8725
|
jsonrpc: "2.0",
|
|
8619
8726
|
method,
|