@ax-llm/ax-tools 16.1.2 → 16.1.6
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 +2 -2
- package/index.cjs.map +1 -1
- package/index.d.cts +15 -2
- package/index.d.ts +15 -2
- package/index.js +2 -2
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;var _child_process = require('child_process');var _readline = require('readline'); var _readline2 = _interopRequireDefault(_readline);var s= (_class =class{__init() {this.pendingResponses=new Map}constructor(e){;_class.prototype.__init.call(this);this.process=_child_process.spawn.call(void 0, e.command,_nullishCoalesce(e.args, () => ([])),{env:e.env?{...process.env,...e.env}:process.env}),this.rl=_readline2.default.createInterface({input:this.process.stdout}),this.rl.on("line",r=>{try{let t=JSON.parse(r),
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class; var _class2;var _child_process = require('child_process');var _readline = require('readline'); var _readline2 = _interopRequireDefault(_readline);var s= (_class =class{__init() {this.pendingResponses=new Map}constructor(e){;_class.prototype.__init.call(this);this.process=_child_process.spawn.call(void 0, e.command,_nullishCoalesce(e.args, () => ([])),{env:e.env?{...process.env,...e.env}:process.env}),this.rl=_readline2.default.createInterface({input:this.process.stdout}),this.rl.on("line",r=>{try{let t=JSON.parse(r),i=this.pendingResponses.get(t.id);i&&(i(t),this.pendingResponses.delete(t.id))}catch (e2){console.warn("Non-JSON output from MCP server:",r)}})}async send(e){return new Promise(r=>{this.pendingResponses.set(e.id,t=>{r(t)}),this.process.stdin.write(`${JSON.stringify(e)}
|
|
2
2
|
`)})}async sendNotification(e){this.process.stdin.write(`${JSON.stringify(e)}
|
|
3
|
-
`)}async connect(){return Promise.resolve()}async terminate(){return this.rl.close(),this.process.kill(),new Promise(e=>{this.process.on("exit",()=>e())})}}, _class);function
|
|
3
|
+
`)}async connect(){return Promise.resolve()}async terminate(){return this.rl.close(),this.process.kill(),new Promise(e=>{this.process.on("exit",()=>e())})}}, _class);function c(n){return new s(n)}var _fs = require('fs'); var x = _interopRequireWildcard(_fs);var _http = require('http'); var C = _interopRequireWildcard(_http);var _https = require('https'); var P = _interopRequireWildcard(_https);var _os = require('os'); var S = _interopRequireWildcard(_os);var _process = require('process'); var f = _interopRequireWildcard(_process);var _vm = require('vm');function y(){if(globalThis.crypto&&typeof globalThis.crypto.randomUUID=="function")return globalThis.crypto;throw new Error("Web Crypto API with randomUUID support not available. Requires Node.js 16+ or modern browser.")}var m=(o=>(o.FS="node:fs",o.NET="net",o.OS="os",o.CRYPTO="crypto",o.PROCESS="process",o))(m||{}),p= exports.AxJSInterpreter =class{constructor({permissions:e=[]}={}){this.permissions=_nullishCoalesce(e, () => ([]))}codeInterpreterJavascript(e){let r={console};return this.permissions.includes("node:fs")&&(r.fs=x),this.permissions.includes("net")&&(r.http=C,r.https=P),this.permissions.includes("os")&&(r.os=S),this.permissions.includes("crypto")&&(r.crypto=y()),this.permissions.includes("process")&&(r.process=f),_vm.runInNewContext.call(void 0, `(function() { ${e} })()`,r)}toFunction(){return{name:"javascriptInterpreter",description:"Use this function to run Javascript code and get any expected return value",parameters:{type:"object",properties:{code:{type:"string",description:"JS code with a return value in the end."}},required:["code"]},func:({code:e})=>this.codeInterpreterJavascript(e)}}};function h(n){return new p(n)}var a= (_class2 =class{constructor() { _class2.prototype.__init2.call(this); }__init2() {this.language="JavaScript"}createSession(e){let r=_vm.createContext.call(void 0, {console,setTimeout,clearTimeout,setInterval,clearInterval,...e});return{async execute(t){if(/\bawait\b/.test(t)){let i=`(async () => { ${t} })()`;return await _vm.runInContext.call(void 0, i,r,{timeout:3e4})}return _vm.runInContext.call(void 0, t,r,{timeout:3e4})},close(){}}}}, _class2);function J(){return new a}exports.AxJSInterpreter = p; exports.AxJSInterpreterPermission = m; exports.AxMCPStdioTransport = s; exports.AxRLMJSInterpreter = a; exports.axCreateJSInterpreter = h; exports.axCreateMCPStdioTransport = c; exports.axCreateRLMJSInterpreter = J;
|
|
4
4
|
//# sourceMappingURL=index.cjs.map
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../mcp/stdioTransport.ts","../functions/jsInterpreter.ts"],"names":["AxMCPStdioTransport","config","spawn","readline","line","response","resolver","message","resolve","res"],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"sources":["../mcp/stdioTransport.ts","../functions/jsInterpreter.ts"],"names":["AxMCPStdioTransport","config","spawn","readline","line","response","resolver","message","resolve","res"],"mappings":"AAAA,smBAA2D,wFACtC,IAeRA,CAAAA,WAAN,KAAoD,CACjD,eAEA,gBAAA,CAAmB,IAAI,IAAA,WAK/B,CAAYC,CAAAA,CAAwC,qCAClD,IAAA,CAAK,OAAA,CAAUC,kCAAAA,CAAMD,CAAO,OAAA,kBAASA,CAAAA,CAAO,IAAA,SAAQ,CAAC,GAAA,CAAG,CACtD,GAAA,CAAKA,CAAAA,CAAO,GAAA,CAAM,CAAE,GAAG,OAAA,CAAQ,GAAA,CAAK,GAAGA,CAAAA,CAAO,GAAI,CAAA,CAAI,OAAA,CAAQ,GAChE,CAAC,CAAA,CACD,IAAA,CAAK,EAAA,CAAKE,kBAAAA,CAAS,eAAA,CAAgB,CAAE,KAAA,CAAO,IAAA,CAAK,OAAA,CAAQ,MAAO,CAAC,CAAA,CACjE,IAAA,CAAK,EAAA,CAAG,EAAA,CAAG,MAAA,CAASC,CAAAA,EAAS,CAC3B,GAAI,CACF,IAAMC,CAAAA,CAAiC,IAAA,CAAK,KAAA,CAAMD,CAAI,CAAA,CAChDE,CAAAA,CAAW,IAAA,CAAK,gBAAA,CAAiB,GAAA,CAAID,CAAAA,CAAS,EAAE,CAAA,CAClDC,CAAAA,EAAAA,CACFA,CAAAA,CAASD,CAAQ,CAAA,CACjB,IAAA,CAAK,gBAAA,CAAiB,MAAA,CAAOA,CAAAA,CAAS,EAAE,CAAA,CAE5C,CAAA,UAAiB,CAEf,OAAA,CAAQ,IAAA,CAAK,kCAAA,CAAoCD,CAAI,CACvD,CACF,CAAC,CACH,CAEA,MAAM,IAAA,CACJG,CAAAA,CACwC,CACxC,OAAO,IAAI,OAAA,CAAwCC,CAAAA,EAAY,CAC7D,IAAA,CAAK,gBAAA,CAAiB,GAAA,CAAID,CAAAA,CAAQ,EAAA,CAAKE,CAAAA,EAA8B,CACnED,CAAAA,CAAQC,CAAoC,CAC9C,CAAC,CAAA,CACD,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,KAAA,CAAM,CAAA,EAAA;AAOwB;AC5CnD","file":"/home/runner/work/ax/ax/src/tools/dist/index.cjs","sourcesContent":["import { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process';\nimport readline from 'node:readline';\n\nimport type {\n AxMCPJSONRPCNotification,\n AxMCPJSONRPCRequest,\n AxMCPJSONRPCResponse,\n AxMCPTransport,\n} from '@ax-llm/ax';\n\nexport interface StdioTransportConfig {\n command: string;\n args?: string[];\n env?: NodeJS.ProcessEnv;\n}\n\nexport class AxMCPStdioTransport implements AxMCPTransport {\n private process: ChildProcessWithoutNullStreams;\n private rl: readline.Interface;\n private pendingResponses = new Map<\n string | number,\n (res: AxMCPJSONRPCResponse) => void\n >();\n\n constructor(config: Readonly<StdioTransportConfig>) {\n this.process = spawn(config.command, config.args ?? [], {\n env: config.env ? { ...process.env, ...config.env } : process.env,\n });\n this.rl = readline.createInterface({ input: this.process.stdout });\n this.rl.on('line', (line) => {\n try {\n const response: AxMCPJSONRPCResponse = JSON.parse(line);\n const resolver = this.pendingResponses.get(response.id);\n if (resolver) {\n resolver(response);\n this.pendingResponses.delete(response.id);\n }\n } catch (_error) {\n // Skip non-JSON lines (might be debug output from the MCP server)\n console.warn('Non-JSON output from MCP server:', line);\n }\n });\n }\n\n async send(\n message: Readonly<AxMCPJSONRPCRequest<unknown>>\n ): Promise<AxMCPJSONRPCResponse<unknown>> {\n return new Promise<AxMCPJSONRPCResponse<unknown>>((resolve) => {\n this.pendingResponses.set(message.id, (res: AxMCPJSONRPCResponse) => {\n resolve(res as AxMCPJSONRPCResponse<unknown>);\n });\n this.process.stdin.write(`${JSON.stringify(message)}\\n`);\n });\n }\n\n async sendNotification(\n message: Readonly<AxMCPJSONRPCNotification>\n ): Promise<void> {\n this.process.stdin.write(`${JSON.stringify(message)}\\n`);\n }\n\n async connect(): Promise<void> {\n // Connection is implicit when the process is spawned\n return Promise.resolve();\n }\n\n /**\n * Terminate the child process and clean up resources\n */\n async terminate(): Promise<void> {\n this.rl.close();\n this.process.kill();\n return new Promise((resolve) => {\n this.process.on('exit', () => resolve());\n });\n }\n}\n\n/**\n * Create a new AxMCPStdioTransport instance\n * @param config Configuration for the stdio transport\n * @returns A new AxMCPStdioTransport instance\n */\nexport function axCreateMCPStdioTransport(\n config: Readonly<StdioTransportConfig>\n): AxMCPStdioTransport {\n return new AxMCPStdioTransport(config);\n}\n","import * as _fs from 'node:fs';\nimport * as _http from 'node:http';\nimport * as _https from 'node:https';\nimport * as _os from 'node:os';\nimport * as _process from 'node:process';\nimport { runInNewContext } from 'node:vm';\nimport type { AxFunction } from '@ax-llm/ax';\n\n// Local implementation of getCrypto since it's not exported from main package\nfunction getCrypto() {\n if (globalThis.crypto && typeof globalThis.crypto.randomUUID === 'function') {\n return globalThis.crypto;\n }\n throw new Error(\n 'Web Crypto API with randomUUID support not available. Requires Node.js 16+ or modern browser.'\n );\n}\n\nexport enum AxJSInterpreterPermission {\n FS = 'node:fs',\n NET = 'net',\n OS = 'os',\n CRYPTO = 'crypto',\n PROCESS = 'process',\n}\n\ntype Context = {\n console: Console;\n fs: unknown;\n http: unknown;\n https: unknown;\n os: unknown;\n crypto: unknown;\n process: unknown;\n};\n\nexport class AxJSInterpreter {\n private permissions: readonly AxJSInterpreterPermission[];\n\n constructor({\n permissions = [],\n }:\n | Readonly<{ permissions?: readonly AxJSInterpreterPermission[] }>\n | undefined = {}) {\n this.permissions = permissions ?? [];\n }\n\n private codeInterpreterJavascript(code: string): unknown {\n const context: Partial<Context> = { console };\n\n if (this.permissions.includes(AxJSInterpreterPermission.FS)) {\n context.fs = _fs;\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.NET)) {\n context.http = _http;\n context.https = _https;\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.OS)) {\n context.os = _os;\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.CRYPTO)) {\n context.crypto = getCrypto();\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.PROCESS)) {\n context.process = _process;\n }\n\n return runInNewContext(`(function() { ${code} })()`, context);\n }\n\n public toFunction(): AxFunction {\n return {\n name: 'javascriptInterpreter',\n description:\n 'Use this function to run Javascript code and get any expected return value',\n parameters: {\n type: 'object',\n properties: {\n code: {\n type: 'string',\n description: 'JS code with a return value in the end.',\n },\n },\n required: ['code'],\n },\n\n func: ({ code }: Readonly<{ code: string }>) =>\n this.codeInterpreterJavascript(code),\n };\n }\n}\n\n// Factory function following the same pattern as MCP\nexport function axCreateJSInterpreter(\n options?: Readonly<{ permissions?: readonly AxJSInterpreterPermission[] }>\n): AxJSInterpreter {\n return new AxJSInterpreter(options);\n}\n"]}
|
package/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxMCPTransport, AxMCPJSONRPCRequest, AxMCPJSONRPCResponse, AxMCPJSONRPCNotification, AxFunction } from '@ax-llm/ax';
|
|
1
|
+
import { AxMCPTransport, AxMCPJSONRPCRequest, AxMCPJSONRPCResponse, AxMCPJSONRPCNotification, AxFunction, AxCodeInterpreter, AxCodeSession } from '@ax-llm/ax';
|
|
2
2
|
|
|
3
3
|
interface StdioTransportConfig {
|
|
4
4
|
command: string;
|
|
@@ -44,4 +44,17 @@ declare function axCreateJSInterpreter(options?: Readonly<{
|
|
|
44
44
|
permissions?: readonly AxJSInterpreterPermission[];
|
|
45
45
|
}>): AxJSInterpreter;
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Node.js JavaScript interpreter for RLM using `node:vm`.
|
|
49
|
+
* Creates persistent sessions where variables survive across `execute()` calls.
|
|
50
|
+
*/
|
|
51
|
+
declare class AxRLMJSInterpreter implements AxCodeInterpreter {
|
|
52
|
+
readonly language = "JavaScript";
|
|
53
|
+
createSession(globals?: Record<string, unknown>): AxCodeSession;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Factory function for creating an AxRLMJSInterpreter.
|
|
57
|
+
*/
|
|
58
|
+
declare function axCreateRLMJSInterpreter(): AxRLMJSInterpreter;
|
|
59
|
+
|
|
60
|
+
export { AxJSInterpreter, AxJSInterpreterPermission, AxMCPStdioTransport, AxRLMJSInterpreter, type StdioTransportConfig, axCreateJSInterpreter, axCreateMCPStdioTransport, axCreateRLMJSInterpreter };
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxMCPTransport, AxMCPJSONRPCRequest, AxMCPJSONRPCResponse, AxMCPJSONRPCNotification, AxFunction } from '@ax-llm/ax';
|
|
1
|
+
import { AxMCPTransport, AxMCPJSONRPCRequest, AxMCPJSONRPCResponse, AxMCPJSONRPCNotification, AxFunction, AxCodeInterpreter, AxCodeSession } from '@ax-llm/ax';
|
|
2
2
|
|
|
3
3
|
interface StdioTransportConfig {
|
|
4
4
|
command: string;
|
|
@@ -44,4 +44,17 @@ declare function axCreateJSInterpreter(options?: Readonly<{
|
|
|
44
44
|
permissions?: readonly AxJSInterpreterPermission[];
|
|
45
45
|
}>): AxJSInterpreter;
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Node.js JavaScript interpreter for RLM using `node:vm`.
|
|
49
|
+
* Creates persistent sessions where variables survive across `execute()` calls.
|
|
50
|
+
*/
|
|
51
|
+
declare class AxRLMJSInterpreter implements AxCodeInterpreter {
|
|
52
|
+
readonly language = "JavaScript";
|
|
53
|
+
createSession(globals?: Record<string, unknown>): AxCodeSession;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Factory function for creating an AxRLMJSInterpreter.
|
|
57
|
+
*/
|
|
58
|
+
declare function axCreateRLMJSInterpreter(): AxRLMJSInterpreter;
|
|
59
|
+
|
|
60
|
+
export { AxJSInterpreter, AxJSInterpreterPermission, AxMCPStdioTransport, AxRLMJSInterpreter, type StdioTransportConfig, axCreateJSInterpreter, axCreateMCPStdioTransport, axCreateRLMJSInterpreter };
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{spawn as
|
|
1
|
+
import{spawn as u}from"child_process";import l from"readline";var s=class{process;rl;pendingResponses=new Map;constructor(e){this.process=u(e.command,e.args??[],{env:e.env?{...process.env,...e.env}:process.env}),this.rl=l.createInterface({input:this.process.stdout}),this.rl.on("line",r=>{try{let t=JSON.parse(r),i=this.pendingResponses.get(t.id);i&&(i(t),this.pendingResponses.delete(t.id))}catch{console.warn("Non-JSON output from MCP server:",r)}})}async send(e){return new Promise(r=>{this.pendingResponses.set(e.id,t=>{r(t)}),this.process.stdin.write(`${JSON.stringify(e)}
|
|
2
2
|
`)})}async sendNotification(e){this.process.stdin.write(`${JSON.stringify(e)}
|
|
3
|
-
`)}async connect(){return Promise.resolve()}async terminate(){return this.rl.close(),this.process.kill(),new Promise(e=>{this.process.on("exit",()=>e())})}};function
|
|
3
|
+
`)}async connect(){return Promise.resolve()}async terminate(){return this.rl.close(),this.process.kill(),new Promise(e=>{this.process.on("exit",()=>e())})}};function c(n){return new s(n)}import*as x from"fs";import*as C from"http";import*as P from"https";import*as S from"os";import*as f from"process";import{runInNewContext as R}from"vm";function y(){if(globalThis.crypto&&typeof globalThis.crypto.randomUUID=="function")return globalThis.crypto;throw new Error("Web Crypto API with randomUUID support not available. Requires Node.js 16+ or modern browser.")}var m=(o=>(o.FS="node:fs",o.NET="net",o.OS="os",o.CRYPTO="crypto",o.PROCESS="process",o))(m||{}),p=class{permissions;constructor({permissions:e=[]}={}){this.permissions=e??[]}codeInterpreterJavascript(e){let r={console};return this.permissions.includes("node:fs")&&(r.fs=x),this.permissions.includes("net")&&(r.http=C,r.https=P),this.permissions.includes("os")&&(r.os=S),this.permissions.includes("crypto")&&(r.crypto=y()),this.permissions.includes("process")&&(r.process=f),R(`(function() { ${e} })()`,r)}toFunction(){return{name:"javascriptInterpreter",description:"Use this function to run Javascript code and get any expected return value",parameters:{type:"object",properties:{code:{type:"string",description:"JS code with a return value in the end."}},required:["code"]},func:({code:e})=>this.codeInterpreterJavascript(e)}}};function h(n){return new p(n)}import{createContext as w,runInContext as d}from"vm";var a=class{language="JavaScript";createSession(e){let r=w({console,setTimeout,clearTimeout,setInterval,clearInterval,...e});return{async execute(t){if(/\bawait\b/.test(t)){let i=`(async () => { ${t} })()`;return await d(i,r,{timeout:3e4})}return d(t,r,{timeout:3e4})},close(){}}}};function J(){return new a}export{p as AxJSInterpreter,m as AxJSInterpreterPermission,s as AxMCPStdioTransport,a as AxRLMJSInterpreter,h as axCreateJSInterpreter,c as axCreateMCPStdioTransport,J as axCreateRLMJSInterpreter};
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../mcp/stdioTransport.ts","../functions/jsInterpreter.ts"],"sourcesContent":["import { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process';\nimport readline from 'node:readline';\n\nimport type {\n AxMCPJSONRPCNotification,\n AxMCPJSONRPCRequest,\n AxMCPJSONRPCResponse,\n AxMCPTransport,\n} from '@ax-llm/ax';\n\nexport interface StdioTransportConfig {\n command: string;\n args?: string[];\n env?: NodeJS.ProcessEnv;\n}\n\nexport class AxMCPStdioTransport implements AxMCPTransport {\n private process: ChildProcessWithoutNullStreams;\n private rl: readline.Interface;\n private pendingResponses = new Map<\n string | number,\n (res: AxMCPJSONRPCResponse) => void\n >();\n\n constructor(config: Readonly<StdioTransportConfig>) {\n this.process = spawn(config.command, config.args ?? [], {\n env: config.env ? { ...process.env, ...config.env } : process.env,\n });\n this.rl = readline.createInterface({ input: this.process.stdout });\n this.rl.on('line', (line) => {\n try {\n const response: AxMCPJSONRPCResponse = JSON.parse(line);\n const resolver = this.pendingResponses.get(response.id);\n if (resolver) {\n resolver(response);\n this.pendingResponses.delete(response.id);\n }\n } catch (_error) {\n // Skip non-JSON lines (might be debug output from the MCP server)\n console.warn('Non-JSON output from MCP server:', line);\n }\n });\n }\n\n async send(\n message: Readonly<AxMCPJSONRPCRequest<unknown>>\n ): Promise<AxMCPJSONRPCResponse<unknown>> {\n return new Promise<AxMCPJSONRPCResponse<unknown>>((resolve) => {\n this.pendingResponses.set(message.id, (res: AxMCPJSONRPCResponse) => {\n resolve(res as AxMCPJSONRPCResponse<unknown>);\n });\n this.process.stdin.write(`${JSON.stringify(message)}\\n`);\n });\n }\n\n async sendNotification(\n message: Readonly<AxMCPJSONRPCNotification>\n ): Promise<void> {\n this.process.stdin.write(`${JSON.stringify(message)}\\n`);\n }\n\n async connect(): Promise<void> {\n // Connection is implicit when the process is spawned\n return Promise.resolve();\n }\n\n /**\n * Terminate the child process and clean up resources\n */\n async terminate(): Promise<void> {\n this.rl.close();\n this.process.kill();\n return new Promise((resolve) => {\n this.process.on('exit', () => resolve());\n });\n }\n}\n\n/**\n * Create a new AxMCPStdioTransport instance\n * @param config Configuration for the stdio transport\n * @returns A new AxMCPStdioTransport instance\n */\nexport function axCreateMCPStdioTransport(\n config: Readonly<StdioTransportConfig>\n): AxMCPStdioTransport {\n return new AxMCPStdioTransport(config);\n}\n","import * as _fs from 'node:fs';\nimport * as _http from 'node:http';\nimport * as _https from 'node:https';\nimport * as _os from 'node:os';\nimport * as _process from 'node:process';\nimport { runInNewContext } from 'node:vm';\nimport type { AxFunction } from '@ax-llm/ax';\n\n// Local implementation of getCrypto since it's not exported from main package\nfunction getCrypto() {\n if (globalThis.crypto && typeof globalThis.crypto.randomUUID === 'function') {\n return globalThis.crypto;\n }\n throw new Error(\n 'Web Crypto API with randomUUID support not available. Requires Node.js 16+ or modern browser.'\n );\n}\n\nexport enum AxJSInterpreterPermission {\n FS = 'node:fs',\n NET = 'net',\n OS = 'os',\n CRYPTO = 'crypto',\n PROCESS = 'process',\n}\n\ntype Context = {\n console: Console;\n fs: unknown;\n http: unknown;\n https: unknown;\n os: unknown;\n crypto: unknown;\n process: unknown;\n};\n\nexport class AxJSInterpreter {\n private permissions: readonly AxJSInterpreterPermission[];\n\n constructor({\n permissions = [],\n }:\n | Readonly<{ permissions?: readonly AxJSInterpreterPermission[] }>\n | undefined = {}) {\n this.permissions = permissions ?? [];\n }\n\n private codeInterpreterJavascript(code: string): unknown {\n const context: Partial<Context> = { console };\n\n if (this.permissions.includes(AxJSInterpreterPermission.FS)) {\n context.fs = _fs;\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.NET)) {\n context.http = _http;\n context.https = _https;\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.OS)) {\n context.os = _os;\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.CRYPTO)) {\n context.crypto = getCrypto();\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.PROCESS)) {\n context.process = _process;\n }\n\n return runInNewContext(`(function() { ${code} })()`, context);\n }\n\n public toFunction(): AxFunction {\n return {\n name: 'javascriptInterpreter',\n description:\n 'Use this function to run Javascript code and get any expected return value',\n parameters: {\n type: 'object',\n properties: {\n code: {\n type: 'string',\n description: 'JS code with a return value in the end.',\n },\n },\n required: ['code'],\n },\n\n func: ({ code }: Readonly<{ code: string }>) =>\n this.codeInterpreterJavascript(code),\n };\n }\n}\n\n// Factory function following the same pattern as MCP\nexport function axCreateJSInterpreter(\n options?: Readonly<{ permissions?: readonly AxJSInterpreterPermission[] }>\n): AxJSInterpreter {\n return new AxJSInterpreter(options);\n}\n"],"mappings":"AAAA,OAA8C,SAAAA,MAAa,gBAC3D,OAAOC,MAAc,WAed,IAAMC,EAAN,KAAoD,CACjD,QACA,GACA,iBAAmB,IAAI,IAK/B,YAAYC,EAAwC,CAClD,KAAK,QAAUH,EAAMG,EAAO,QAASA,EAAO,MAAQ,CAAC,EAAG,CACtD,IAAKA,EAAO,IAAM,CAAE,GAAG,QAAQ,IAAK,GAAGA,EAAO,GAAI,EAAI,QAAQ,GAChE,CAAC,EACD,KAAK,GAAKF,EAAS,gBAAgB,CAAE,MAAO,KAAK,QAAQ,MAAO,CAAC,EACjE,KAAK,GAAG,GAAG,OAASG,GAAS,CAC3B,GAAI,CACF,IAAMC,EAAiC,KAAK,MAAMD,CAAI,EAChDE,EAAW,KAAK,iBAAiB,IAAID,EAAS,EAAE,EAClDC,IACFA,EAASD,CAAQ,EACjB,KAAK,iBAAiB,OAAOA,EAAS,EAAE,EAE5C,MAAiB,CAEf,QAAQ,KAAK,mCAAoCD,CAAI,CACvD,CACF,CAAC,CACH,CAEA,MAAM,KACJG,EACwC,CACxC,OAAO,IAAI,QAAwCC,GAAY,CAC7D,KAAK,iBAAiB,IAAID,EAAQ,GAAKE,GAA8B,CACnED,EAAQC,CAAoC,CAC9C,CAAC,EACD,KAAK,QAAQ,MAAM,MAAM,GAAG,KAAK,UAAUF,CAAO,CAAC;AA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SAAiC,IAC7DK,EAAQ,QAAUP,GAGbC,EAAgB,iBAAiBK,CAAI,QAASC,CAAO,CAC9D,CAEO,YAAyB,CAC9B,MAAO,CACL,KAAM,wBACN,YACE,6EACF,WAAY,CACV,KAAM,SACN,WAAY,CACV,KAAM,CACJ,KAAM,SACN,YAAa,yCACf,CACF,EACA,SAAU,CAAC,MAAM,CACnB,EAEA,KAAM,CAAC,CAAE,KAAAD,CAAK,IACZ,KAAK,0BAA0BA,CAAI,CACvC,CACF,CACF,EAGO,SAASE,EACdC,EACiB,CACjB,OAAO,IAAIL,EAAgBK,CAAO,CACpC","names":["spawn","readline","AxMCPStdioTransport","config","line","response","resolver","message","resolve","res","axCreateMCPStdioTransport","_fs","_http","_https","_os","_process","runInNewContext","getCrypto","AxJSInterpreterPermission","AxJSInterpreter","permissions","code","context","axCreateJSInterpreter","options"]}
|
|
1
|
+
{"version":3,"sources":["../mcp/stdioTransport.ts","../functions/jsInterpreter.ts","../functions/rlmInterpreter.ts"],"sourcesContent":["import { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process';\nimport readline from 'node:readline';\n\nimport type {\n AxMCPJSONRPCNotification,\n AxMCPJSONRPCRequest,\n AxMCPJSONRPCResponse,\n AxMCPTransport,\n} from '@ax-llm/ax';\n\nexport interface StdioTransportConfig {\n command: string;\n args?: string[];\n env?: NodeJS.ProcessEnv;\n}\n\nexport class AxMCPStdioTransport implements AxMCPTransport {\n private process: ChildProcessWithoutNullStreams;\n private rl: readline.Interface;\n private pendingResponses = new Map<\n string | number,\n (res: AxMCPJSONRPCResponse) => void\n >();\n\n constructor(config: Readonly<StdioTransportConfig>) {\n this.process = spawn(config.command, config.args ?? [], {\n env: config.env ? { ...process.env, ...config.env } : process.env,\n });\n this.rl = readline.createInterface({ input: this.process.stdout });\n this.rl.on('line', (line) => {\n try {\n const response: AxMCPJSONRPCResponse = JSON.parse(line);\n const resolver = this.pendingResponses.get(response.id);\n if (resolver) {\n resolver(response);\n this.pendingResponses.delete(response.id);\n }\n } catch (_error) {\n // Skip non-JSON lines (might be debug output from the MCP server)\n console.warn('Non-JSON output from MCP server:', line);\n }\n });\n }\n\n async send(\n message: Readonly<AxMCPJSONRPCRequest<unknown>>\n ): Promise<AxMCPJSONRPCResponse<unknown>> {\n return new Promise<AxMCPJSONRPCResponse<unknown>>((resolve) => {\n this.pendingResponses.set(message.id, (res: AxMCPJSONRPCResponse) => {\n resolve(res as AxMCPJSONRPCResponse<unknown>);\n });\n this.process.stdin.write(`${JSON.stringify(message)}\\n`);\n });\n }\n\n async sendNotification(\n message: Readonly<AxMCPJSONRPCNotification>\n ): Promise<void> {\n this.process.stdin.write(`${JSON.stringify(message)}\\n`);\n }\n\n async connect(): Promise<void> {\n // Connection is implicit when the process is spawned\n return Promise.resolve();\n }\n\n /**\n * Terminate the child process and clean up resources\n */\n async terminate(): Promise<void> {\n this.rl.close();\n this.process.kill();\n return new Promise((resolve) => {\n this.process.on('exit', () => resolve());\n });\n }\n}\n\n/**\n * Create a new AxMCPStdioTransport instance\n * @param config Configuration for the stdio transport\n * @returns A new AxMCPStdioTransport instance\n */\nexport function axCreateMCPStdioTransport(\n config: Readonly<StdioTransportConfig>\n): AxMCPStdioTransport {\n return new AxMCPStdioTransport(config);\n}\n","import * as _fs from 'node:fs';\nimport * as _http from 'node:http';\nimport * as _https from 'node:https';\nimport * as _os from 'node:os';\nimport * as _process from 'node:process';\nimport { runInNewContext } from 'node:vm';\nimport type { AxFunction } from '@ax-llm/ax';\n\n// Local implementation of getCrypto since it's not exported from main package\nfunction getCrypto() {\n if (globalThis.crypto && typeof globalThis.crypto.randomUUID === 'function') {\n return globalThis.crypto;\n }\n throw new Error(\n 'Web Crypto API with randomUUID support not available. Requires Node.js 16+ or modern browser.'\n );\n}\n\nexport enum AxJSInterpreterPermission {\n FS = 'node:fs',\n NET = 'net',\n OS = 'os',\n CRYPTO = 'crypto',\n PROCESS = 'process',\n}\n\ntype Context = {\n console: Console;\n fs: unknown;\n http: unknown;\n https: unknown;\n os: unknown;\n crypto: unknown;\n process: unknown;\n};\n\nexport class AxJSInterpreter {\n private permissions: readonly AxJSInterpreterPermission[];\n\n constructor({\n permissions = [],\n }:\n | Readonly<{ permissions?: readonly AxJSInterpreterPermission[] }>\n | undefined = {}) {\n this.permissions = permissions ?? [];\n }\n\n private codeInterpreterJavascript(code: string): unknown {\n const context: Partial<Context> = { console };\n\n if (this.permissions.includes(AxJSInterpreterPermission.FS)) {\n context.fs = _fs;\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.NET)) {\n context.http = _http;\n context.https = _https;\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.OS)) {\n context.os = _os;\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.CRYPTO)) {\n context.crypto = getCrypto();\n }\n\n if (this.permissions.includes(AxJSInterpreterPermission.PROCESS)) {\n context.process = _process;\n }\n\n return runInNewContext(`(function() { ${code} })()`, context);\n }\n\n public toFunction(): AxFunction {\n return {\n name: 'javascriptInterpreter',\n description:\n 'Use this function to run Javascript code and get any expected return value',\n parameters: {\n type: 'object',\n properties: {\n code: {\n type: 'string',\n description: 'JS code with a return value in the end.',\n },\n },\n required: ['code'],\n },\n\n func: ({ code }: Readonly<{ code: string }>) =>\n this.codeInterpreterJavascript(code),\n };\n }\n}\n\n// Factory function following the same pattern as MCP\nexport function axCreateJSInterpreter(\n options?: Readonly<{ permissions?: readonly AxJSInterpreterPermission[] }>\n): AxJSInterpreter {\n return new AxJSInterpreter(options);\n}\n","import { createContext, runInContext } from 'node:vm';\n\nimport type { AxCodeInterpreter, AxCodeSession } from '@ax-llm/ax';\n\n/**\n * Node.js JavaScript interpreter for RLM using `node:vm`.\n * Creates persistent sessions where variables survive across `execute()` calls.\n */\nexport class AxRLMJSInterpreter implements AxCodeInterpreter {\n readonly language = 'JavaScript';\n\n createSession(globals?: Record<string, unknown>): AxCodeSession {\n const context = createContext({\n console,\n setTimeout,\n clearTimeout,\n setInterval,\n clearInterval,\n ...globals,\n });\n\n return {\n async execute(code: string): Promise<unknown> {\n if (/\\bawait\\b/.test(code)) {\n // Wrap in async IIFE so top-level await works.\n // Only bare assignments (no var/const/let) persist across calls.\n const wrapped = `(async () => { ${code} })()`;\n return await runInContext(wrapped, context, { timeout: 30_000 });\n }\n // Direct execution: var declarations persist on the context,\n // and the last expression value is auto-returned.\n return runInContext(code, context, { timeout: 30_000 });\n },\n close() {\n // No cleanup needed for vm contexts\n },\n };\n }\n}\n\n/**\n * Factory function for creating an AxRLMJSInterpreter.\n */\nexport function axCreateRLMJSInterpreter(): AxRLMJSInterpreter {\n return new AxRLMJSInterpreter();\n}\n"],"mappings":"AAAA,OAA8C,SAAAA,MAAa,gBAC3D,OAAOC,MAAc,WAed,IAAMC,EAAN,KAAoD,CACjD,QACA,GACA,iBAAmB,IAAI,IAK/B,YAAYC,EAAwC,CAClD,KAAK,QAAUH,EAAMG,EAAO,QAASA,EAAO,MAAQ,CAAC,EAAG,CACtD,IAAKA,EAAO,IAAM,CAAE,GAAG,QAAQ,IAAK,GAAGA,EAAO,GAAI,EAAI,QAAQ,GAChE,CAAC,EACD,KAAK,GAAKF,EAAS,gBAAgB,CAAE,MAAO,KAAK,QAAQ,MAAO,CAAC,EACjE,KAAK,GAAG,GAAG,OAASG,GAAS,CAC3B,GAAI,CACF,IAAMC,EAAiC,KAAK,MAAMD,CAAI,EAChDE,EAAW,KAAK,iBAAiB,IAAID,EAAS,EAAE,EAClDC,IACFA,EAASD,CAAQ,EACjB,KAAK,iBAAiB,OAAOA,EAAS,EAAE,EAE5C,MAAiB,CAEf,QAAQ,KAAK,mCAAoCD,CAAI,CACvD,CACF,CAAC,CACH,CAEA,MAAM,KACJG,EACwC,CACxC,OAAO,IAAI,QAAwCC,GAAY,CAC7D,KAAK,iBAAiB,IAAID,EAAQ,GAAKE,GAA8B,CACnED,EAAQC,CAAoC,CAC9C,CAAC,EACD,KAAK,QAAQ,MAAM,MAAM,GAAG,KAAK,UAAUF,CAAO,CAAC;AAAA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AiC,IAC7DK,EAAQ,QAAUP,GAGbC,EAAgB,iBAAiBK,CAAI,QAASC,CAAO,CAC9D,CAEO,YAAyB,CAC9B,MAAO,CACL,KAAM,wBACN,YACE,6EACF,WAAY,CACV,KAAM,SACN,WAAY,CACV,KAAM,CACJ,KAAM,SACN,YAAa,yCACf,CACF,EACA,SAAU,CAAC,MAAM,CACnB,EAEA,KAAM,CAAC,CAAE,KAAAD,CAAK,IACZ,KAAK,0BAA0BA,CAAI,CACvC,CACF,CACF,EAGO,SAASE,EACdC,EACiB,CACjB,OAAO,IAAIL,EAAgBK,CAAO,CACpC,CCrGA,OAAS,iBAAAC,EAAe,gBAAAC,MAAoB,KAQrC,IAAMC,EAAN,KAAsD,CAClD,SAAW,aAEpB,cAAcC,EAAkD,CAC9D,IAAMC,EAAUJ,EAAc,CAC5B,QACA,WACA,aACA,YACA,cACA,GAAGG,CACL,CAAC,EAED,MAAO,CACL,MAAM,QAAQE,EAAgC,CAC5C,GAAI,YAAY,KAAKA,CAAI,EAAG,CAG1B,IAAMC,EAAU,kBAAkBD,CAAI,QACtC,OAAO,MAAMJ,EAAaK,EAASF,EAAS,CAAE,QAAS,GAAO,CAAC,CACjE,CAGA,OAAOH,EAAaI,EAAMD,EAAS,CAAE,QAAS,GAAO,CAAC,CACxD,EACA,OAAQ,CAER,CACF,CACF,CACF,EAKO,SAASG,GAA+C,CAC7D,OAAO,IAAIL,CACb","names":["spawn","readline","AxMCPStdioTransport","config","line","response","resolver","message","resolve","res","axCreateMCPStdioTransport","_fs","_http","_https","_os","_process","runInNewContext","getCrypto","AxJSInterpreterPermission","AxJSInterpreter","permissions","code","context","axCreateJSInterpreter","options","createContext","runInContext","AxRLMJSInterpreter","globals","context","code","wrapped","axCreateRLMJSInterpreter"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ax-llm/ax-tools",
|
|
3
|
-
"version": "16.1.
|
|
3
|
+
"version": "16.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Ax tools package",
|
|
6
6
|
"repository": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"keywords": [],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@ax-llm/ax": "16.1.
|
|
16
|
+
"@ax-llm/ax": "16.1.6"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"**/*"
|