@inkeep/agents-sdk 0.1.0 → 0.1.1
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/LICENSE.md +22 -17
- package/dist/agent.d.ts +2 -2
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +3 -3
- package/dist/agent.js.map +1 -1
- package/dist/artifact-component.d.ts.map +1 -1
- package/dist/artifact-component.js +1 -2
- package/dist/artifact-component.js.map +1 -1
- package/dist/builders.d.ts +9 -9
- package/dist/builders.d.ts.map +1 -1
- package/dist/builders.js +5 -5
- package/dist/builders.js.map +1 -1
- package/dist/data-component.d.ts.map +1 -1
- package/dist/data-component.js +1 -2
- package/dist/data-component.js.map +1 -1
- package/dist/environment-settings.d.ts.map +1 -1
- package/dist/environment-settings.js.map +1 -1
- package/dist/externalAgent.d.ts +1 -1
- package/dist/externalAgent.d.ts.map +1 -1
- package/dist/externalAgent.js.map +1 -1
- package/dist/graph.d.ts +1 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +4 -4
- package/dist/graph.js.map +1 -1
- package/dist/graphFullClient.d.ts.map +1 -1
- package/dist/graphFullClient.js +3 -3
- package/dist/graphFullClient.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/module-hosted-tool-manager.js +2 -2
- package/dist/runner.d.ts +1 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +1 -1
- package/dist/runner.js.map +1 -1
- package/dist/tool.d.ts.map +1 -1
- package/dist/tool.js.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +21 -16
- package/dist/hosted-tool-manager.d.ts +0 -28
- package/dist/hosted-tool-manager.d.ts.map +0 -1
- package/dist/hosted-tool-manager.js +0 -256
- package/dist/hosted-tool-manager.js.map +0 -1
- package/dist/ipc-hosted-tool-manager.d.ts +0 -51
- package/dist/ipc-hosted-tool-manager.d.ts.map +0 -1
- package/dist/ipc-hosted-tool-manager.js +0 -409
- package/dist/ipc-hosted-tool-manager.js.map +0 -1
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { getLogger } from '@inkeep/agents-core';
|
|
5
|
-
const logger = getLogger('hosted-tool-manager');
|
|
6
|
-
export class HostedToolManager {
|
|
7
|
-
servers = new Map();
|
|
8
|
-
portCounter = 3011; // Start from port 3011
|
|
9
|
-
baseDir;
|
|
10
|
-
constructor() {
|
|
11
|
-
this.baseDir = join(process.cwd(), '.hosted-tools');
|
|
12
|
-
if (!existsSync(this.baseDir)) {
|
|
13
|
-
mkdirSync(this.baseDir, { recursive: true });
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async deployTool(config) {
|
|
17
|
-
const toolId = this.getToolId(config.name);
|
|
18
|
-
// Check if tool is already deployed
|
|
19
|
-
if (this.servers.has(toolId)) {
|
|
20
|
-
const existingServer = this.servers.get(toolId);
|
|
21
|
-
if (existingServer.status === 'running') {
|
|
22
|
-
logger.info({ toolId }, 'Tool already deployed and running');
|
|
23
|
-
return existingServer;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const port = config.port || this.getNextPort();
|
|
27
|
-
const serverUrl = `http://localhost:${port}/mcp`;
|
|
28
|
-
const server = {
|
|
29
|
-
config: { ...config, port, serverUrl },
|
|
30
|
-
port,
|
|
31
|
-
serverUrl,
|
|
32
|
-
status: 'starting',
|
|
33
|
-
};
|
|
34
|
-
this.servers.set(toolId, server);
|
|
35
|
-
try {
|
|
36
|
-
await this.generateServerCode(server);
|
|
37
|
-
await this.startServer(server);
|
|
38
|
-
// Wait for server to be ready
|
|
39
|
-
await this.waitForServerReady(server);
|
|
40
|
-
server.status = 'running';
|
|
41
|
-
logger.info({ toolId, port, serverUrl }, 'Tool deployed successfully');
|
|
42
|
-
return server;
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
server.status = 'error';
|
|
46
|
-
logger.error({ toolId, error: error instanceof Error ? error.message : 'Unknown error' }, 'Failed to deploy tool');
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async stopTool(toolName) {
|
|
51
|
-
const toolId = this.getToolId(toolName);
|
|
52
|
-
const server = this.servers.get(toolId);
|
|
53
|
-
if (!server || !server.process) {
|
|
54
|
-
logger.warn({ toolId }, 'Tool not found or not running');
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
return new Promise((resolve) => {
|
|
58
|
-
server.process.on('exit', () => {
|
|
59
|
-
server.status = 'stopped';
|
|
60
|
-
server.process = undefined;
|
|
61
|
-
server.pid = undefined;
|
|
62
|
-
logger.info({ toolId }, 'Tool stopped successfully');
|
|
63
|
-
resolve();
|
|
64
|
-
});
|
|
65
|
-
server.process.kill('SIGTERM');
|
|
66
|
-
// Force kill after 5 seconds
|
|
67
|
-
setTimeout(() => {
|
|
68
|
-
if (server.process && !server.process.killed) {
|
|
69
|
-
server.process.kill('SIGKILL');
|
|
70
|
-
}
|
|
71
|
-
}, 5000);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
getServer(toolName) {
|
|
75
|
-
const toolId = this.getToolId(toolName);
|
|
76
|
-
return this.servers.get(toolId);
|
|
77
|
-
}
|
|
78
|
-
getAllServers() {
|
|
79
|
-
return Array.from(this.servers.values());
|
|
80
|
-
}
|
|
81
|
-
getToolId(name) {
|
|
82
|
-
return name
|
|
83
|
-
.toLowerCase()
|
|
84
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
85
|
-
.replace(/^-+|-+$/g, '');
|
|
86
|
-
}
|
|
87
|
-
getNextPort() {
|
|
88
|
-
return this.portCounter++;
|
|
89
|
-
}
|
|
90
|
-
async generateServerCode(server) {
|
|
91
|
-
const toolId = this.getToolId(server.config.name);
|
|
92
|
-
const serverDir = join(this.baseDir, toolId);
|
|
93
|
-
if (!existsSync(serverDir)) {
|
|
94
|
-
mkdirSync(serverDir, { recursive: true });
|
|
95
|
-
}
|
|
96
|
-
const serverCode = this.createMCPServerCode(server);
|
|
97
|
-
const serverFile = join(serverDir, 'server.mjs');
|
|
98
|
-
writeFileSync(serverFile, serverCode, 'utf8');
|
|
99
|
-
// Create package.json for the tool server
|
|
100
|
-
const packageJson = {
|
|
101
|
-
name: `hosted-tool-${toolId}`,
|
|
102
|
-
version: '1.0.0',
|
|
103
|
-
type: 'module',
|
|
104
|
-
main: 'server.mjs',
|
|
105
|
-
dependencies: {
|
|
106
|
-
'@modelcontextprotocol/sdk': '^1.12.1',
|
|
107
|
-
zod: '^3.25.31',
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
writeFileSync(join(serverDir, 'package.json'), JSON.stringify(packageJson, null, 2), 'utf8');
|
|
111
|
-
logger.info({ toolId, serverFile }, 'Generated MCP server code');
|
|
112
|
-
}
|
|
113
|
-
createMCPServerCode(server) {
|
|
114
|
-
const { config } = server;
|
|
115
|
-
const toolId = this.getToolId(config.name);
|
|
116
|
-
return `#!/usr/bin/env node
|
|
117
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
118
|
-
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
119
|
-
import { z } from 'zod';
|
|
120
|
-
import { createServer } from 'node:http';
|
|
121
|
-
|
|
122
|
-
const server = new McpServer({
|
|
123
|
-
name: '${config.name}',
|
|
124
|
-
version: '1.0.0',
|
|
125
|
-
}, { capabilities: { logging: {} } });
|
|
126
|
-
|
|
127
|
-
// Define the tool function
|
|
128
|
-
const toolFunction = ${config.execute};
|
|
129
|
-
|
|
130
|
-
// Define parameter schema
|
|
131
|
-
const parameterSchema = z.object({${config.parameters
|
|
132
|
-
? Object.keys(config.parameters)
|
|
133
|
-
.map((key) => `\n ${key}: z.any()`)
|
|
134
|
-
.join(',') + '\n'
|
|
135
|
-
: ''}});
|
|
136
|
-
|
|
137
|
-
// Register the tool
|
|
138
|
-
server.tool('${toolId}', '${config.description}', parameterSchema.shape, async (params) => {
|
|
139
|
-
try {
|
|
140
|
-
const result = await toolFunction(params);
|
|
141
|
-
return {
|
|
142
|
-
content: [{
|
|
143
|
-
type: 'text',
|
|
144
|
-
text: typeof result === 'string' ? result : JSON.stringify(result)
|
|
145
|
-
}]
|
|
146
|
-
};
|
|
147
|
-
} catch (error) {
|
|
148
|
-
return {
|
|
149
|
-
content: [{
|
|
150
|
-
type: 'text',
|
|
151
|
-
text: \`Error executing tool: \${error instanceof Error ? error.message : 'Unknown error'}\`
|
|
152
|
-
}],
|
|
153
|
-
isError: true
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// Create HTTP server
|
|
159
|
-
const httpServer = createServer();
|
|
160
|
-
const transport = new StreamableHTTPServerTransport({});
|
|
161
|
-
|
|
162
|
-
httpServer.on('request', async (req, res) => {
|
|
163
|
-
if (req.url === '/mcp' && req.method === 'POST') {
|
|
164
|
-
let body = '';
|
|
165
|
-
req.on('data', chunk => body += chunk);
|
|
166
|
-
req.on('end', async () => {
|
|
167
|
-
try {
|
|
168
|
-
const jsonBody = JSON.parse(body);
|
|
169
|
-
await transport.handleRequest(req, res, jsonBody);
|
|
170
|
-
} catch (error) {
|
|
171
|
-
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
172
|
-
res.end(JSON.stringify({ error: 'Invalid JSON' }));
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
} else if (req.url === '/health' && req.method === 'GET') {
|
|
176
|
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
177
|
-
res.end(JSON.stringify({ status: 'healthy', tool: '${config.name}' }));
|
|
178
|
-
} else {
|
|
179
|
-
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
180
|
-
res.end(JSON.stringify({ error: 'Not found' }));
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// Start the server
|
|
185
|
-
await server.connect(transport);
|
|
186
|
-
httpServer.listen(${server.port}, () => {
|
|
187
|
-
console.log(\`MCP tool server '${config.name}' listening on port ${server.port}\`);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
process.on('SIGTERM', () => {
|
|
191
|
-
httpServer.close(() => {
|
|
192
|
-
console.log('Server stopped');
|
|
193
|
-
process.exit(0);
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
`;
|
|
197
|
-
}
|
|
198
|
-
async startServer(server) {
|
|
199
|
-
const toolId = this.getToolId(server.config.name);
|
|
200
|
-
const serverDir = join(this.baseDir, toolId);
|
|
201
|
-
const serverFile = join(serverDir, 'server.mjs');
|
|
202
|
-
return new Promise((resolve, reject) => {
|
|
203
|
-
const childProcess = spawn('node', [serverFile], {
|
|
204
|
-
cwd: serverDir,
|
|
205
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
206
|
-
detached: false,
|
|
207
|
-
});
|
|
208
|
-
server.process = childProcess;
|
|
209
|
-
server.pid = childProcess.pid;
|
|
210
|
-
childProcess.stdout?.on('data', (data) => {
|
|
211
|
-
logger.info({ toolId }, `Tool server stdout: ${data.toString().trim()}`);
|
|
212
|
-
});
|
|
213
|
-
childProcess.stderr?.on('data', (data) => {
|
|
214
|
-
logger.error({ toolId }, `Tool server stderr: ${data.toString().trim()}`);
|
|
215
|
-
});
|
|
216
|
-
childProcess.on('error', (error) => {
|
|
217
|
-
logger.error({ toolId, error: error.message }, 'Failed to start tool server');
|
|
218
|
-
reject(error);
|
|
219
|
-
});
|
|
220
|
-
childProcess.on('exit', (code, signal) => {
|
|
221
|
-
logger.info({ toolId, code, signal }, 'Tool server process exited');
|
|
222
|
-
server.status = 'stopped';
|
|
223
|
-
server.process = undefined;
|
|
224
|
-
server.pid = undefined;
|
|
225
|
-
});
|
|
226
|
-
// Give the process a moment to start
|
|
227
|
-
setTimeout(() => {
|
|
228
|
-
if (childProcess.pid) {
|
|
229
|
-
resolve();
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
reject(new Error('Failed to start server process'));
|
|
233
|
-
}
|
|
234
|
-
}, 1000);
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
async waitForServerReady(server, maxRetries = 10) {
|
|
238
|
-
for (let i = 0; i < maxRetries; i++) {
|
|
239
|
-
try {
|
|
240
|
-
const response = await fetch(`http://localhost:${server.port}/health`);
|
|
241
|
-
if (response.ok) {
|
|
242
|
-
logger.info({ toolId: this.getToolId(server.config.name) }, 'Server health check passed');
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
// Server not ready yet
|
|
248
|
-
}
|
|
249
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
250
|
-
}
|
|
251
|
-
throw new Error(`Server failed to become ready after ${maxRetries} attempts`);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
// Singleton instance
|
|
255
|
-
export const hostedToolManager = new HostedToolManager();
|
|
256
|
-
//# sourceMappingURL=hosted-tool-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-tool-manager.js","sourceRoot":"","sources":["../src/hosted-tool-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAW,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGhD,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAWhD,MAAM,OAAO,iBAAiB;IACpB,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IAC9C,WAAW,GAAG,IA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MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,4BAA4B,CAAC,CAAC;oBAC1F,OAAO;gBACT,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,uBAAuB;YACzB,CAAC;YAED,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,uCAAuC,UAAU,WAAW,CAAC,CAAC;IAChF,CAAC;CACF;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { type ChildProcess } from 'node:child_process';
|
|
2
|
-
export interface IPCToolFunction {
|
|
3
|
-
name: string;
|
|
4
|
-
description?: string;
|
|
5
|
-
execute: (params: any) => Promise<any>;
|
|
6
|
-
parameters?: Record<string, any>;
|
|
7
|
-
}
|
|
8
|
-
export interface IPCMessage {
|
|
9
|
-
type: 'execute-function' | 'function-result' | 'server-ready' | 'error';
|
|
10
|
-
requestId?: string;
|
|
11
|
-
toolName?: string;
|
|
12
|
-
params?: any;
|
|
13
|
-
result?: any;
|
|
14
|
-
error?: string;
|
|
15
|
-
port?: number;
|
|
16
|
-
message?: string;
|
|
17
|
-
}
|
|
18
|
-
export interface IPCHostedToolServer {
|
|
19
|
-
toolFunction: IPCToolFunction;
|
|
20
|
-
process?: ChildProcess;
|
|
21
|
-
port: number;
|
|
22
|
-
serverUrl: string;
|
|
23
|
-
status: 'starting' | 'running' | 'stopped' | 'error';
|
|
24
|
-
pid?: number;
|
|
25
|
-
serverFile: string;
|
|
26
|
-
}
|
|
27
|
-
export declare class IPCHostedToolManager {
|
|
28
|
-
private servers;
|
|
29
|
-
private toolFunctions;
|
|
30
|
-
private pendingRequests;
|
|
31
|
-
private portCounter;
|
|
32
|
-
private readonly baseDir;
|
|
33
|
-
private requestIdCounter;
|
|
34
|
-
constructor();
|
|
35
|
-
deployIPCTool(toolFunction: IPCToolFunction): Promise<IPCHostedToolServer>;
|
|
36
|
-
stopTool(toolName: string): Promise<void>;
|
|
37
|
-
getServer(toolName: string): IPCHostedToolServer | undefined;
|
|
38
|
-
getAllServers(): IPCHostedToolServer[];
|
|
39
|
-
private getToolId;
|
|
40
|
-
private getNextPort;
|
|
41
|
-
private generateRequestId;
|
|
42
|
-
private generateMCPServerChild;
|
|
43
|
-
private createIPCMCPServerCode;
|
|
44
|
-
private startIPCServer;
|
|
45
|
-
private handleIPCMessage;
|
|
46
|
-
private handleFunctionExecution;
|
|
47
|
-
private cleanupPendingRequests;
|
|
48
|
-
private waitForServerReady;
|
|
49
|
-
}
|
|
50
|
-
export declare const ipcHostedToolManager: IPCHostedToolManager;
|
|
51
|
-
//# sourceMappingURL=ipc-hosted-tool-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ipc-hosted-tool-manager.d.ts","sourceRoot":"","sources":["../src/ipc-hosted-tool-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAS,MAAM,oBAAoB,CAAC;AAO9D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,kBAAkB,GAAG,iBAAiB,GAAG,cAAc,GAAG,OAAO,CAAC;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,GA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