@openweave/weave-tools 1.0.0
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 +21 -0
- package/dist/adapters/http-adapter.d.ts +18 -0
- package/dist/adapters/http-adapter.d.ts.map +1 -0
- package/dist/adapters/http-adapter.js +94 -0
- package/dist/adapters/http-adapter.js.map +1 -0
- package/dist/adapters/mcp-adapter.d.ts +14 -0
- package/dist/adapters/mcp-adapter.d.ts.map +1 -0
- package/dist/adapters/mcp-adapter.js +119 -0
- package/dist/adapters/mcp-adapter.js.map +1 -0
- package/dist/adapters/script-adapter.d.ts +20 -0
- package/dist/adapters/script-adapter.d.ts.map +1 -0
- package/dist/adapters/script-adapter.js +107 -0
- package/dist/adapters/script-adapter.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/tool-bridge.d.ts +58 -0
- package/dist/tool-bridge.d.ts.map +1 -0
- package/dist/tool-bridge.js +125 -0
- package/dist/tool-bridge.js.map +1 -0
- package/dist/tool-loader.d.ts +34 -0
- package/dist/tool-loader.d.ts.map +1 -0
- package/dist/tool-loader.js +103 -0
- package/dist/tool-loader.js.map +1 -0
- package/dist/tool-store.d.ts +37 -0
- package/dist/tool-store.d.ts.map +1 -0
- package/dist/tool-store.js +83 -0
- package/dist/tool-store.js.map +1 -0
- package/dist/types.d.ts +75 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +52 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 lemur bookstores
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Routes tool calls to a REST/webhook endpoint.
|
|
5
|
+
* Supports bearer token, api-key, basic, and no-auth strategies.
|
|
6
|
+
* Injectable fetch for test isolation.
|
|
7
|
+
*/
|
|
8
|
+
import type { ToolManifest, ToolHandler, ToolAuth } from '../types.js';
|
|
9
|
+
export declare function buildAuthHeaders(auth: ToolAuth | undefined): Record<string, string>;
|
|
10
|
+
export type FetchFn = typeof fetch;
|
|
11
|
+
export interface HttpAdapterOptions {
|
|
12
|
+
manifest: ToolManifest;
|
|
13
|
+
/** Injectable fetch implementation for tests */
|
|
14
|
+
fetchFn?: FetchFn;
|
|
15
|
+
}
|
|
16
|
+
export declare function createHttpHandler(manifest: ToolManifest, actionName: string, fetchFn?: FetchFn): ToolHandler;
|
|
17
|
+
export declare function createHttpAdapter(opts: HttpAdapterOptions): Map<string, ToolHandler>;
|
|
18
|
+
//# sourceMappingURL=http-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/http-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAkB,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAMvF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAmBnF;AAMD,MAAM,MAAM,OAAO,GAAG,OAAO,KAAK,CAAC;AAEnC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,YAAY,CAAC;IACvB,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,OAAe,GACvB,WAAW,CA0Db;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAOpF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Routes tool calls to a REST/webhook endpoint.
|
|
5
|
+
* Supports bearer token, api-key, basic, and no-auth strategies.
|
|
6
|
+
* Injectable fetch for test isolation.
|
|
7
|
+
*/
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Auth header builder
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
export function buildAuthHeaders(auth) {
|
|
12
|
+
if (!auth || auth.type === 'none')
|
|
13
|
+
return {};
|
|
14
|
+
const credential = auth.envVar ? (process.env[auth.envVar] ?? '') : '';
|
|
15
|
+
switch (auth.type) {
|
|
16
|
+
case 'bearer':
|
|
17
|
+
return { Authorization: `Bearer ${credential}` };
|
|
18
|
+
case 'api-key': {
|
|
19
|
+
const headerName = auth.headerName ?? 'X-API-Key';
|
|
20
|
+
return { [headerName]: credential };
|
|
21
|
+
}
|
|
22
|
+
case 'basic': {
|
|
23
|
+
const encoded = Buffer.from(credential).toString('base64');
|
|
24
|
+
return { Authorization: `Basic ${encoded}` };
|
|
25
|
+
}
|
|
26
|
+
default:
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function createHttpHandler(manifest, actionName, fetchFn = fetch) {
|
|
31
|
+
const endpoint = manifest.endpoint;
|
|
32
|
+
const timeoutMs = manifest.timeout_ms ?? 10_000;
|
|
33
|
+
return async (args) => {
|
|
34
|
+
const start = Date.now();
|
|
35
|
+
const prefixedName = `${manifest.id}__${actionName}`;
|
|
36
|
+
try {
|
|
37
|
+
const authHeaders = buildAuthHeaders(manifest.auth);
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
40
|
+
let response;
|
|
41
|
+
try {
|
|
42
|
+
response = await fetchFn(`${endpoint}/tools/call`, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
...authHeaders,
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify({ name: actionName, arguments: args }),
|
|
49
|
+
signal: controller.signal,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
}
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
const text = await response.text().catch(() => '');
|
|
57
|
+
return {
|
|
58
|
+
toolId: manifest.id,
|
|
59
|
+
action: prefixedName,
|
|
60
|
+
success: false,
|
|
61
|
+
error: `HTTP ${response.status}: ${text.slice(0, 200)}`,
|
|
62
|
+
durationMs: Date.now() - start,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const data = await response.json();
|
|
66
|
+
return {
|
|
67
|
+
toolId: manifest.id,
|
|
68
|
+
action: prefixedName,
|
|
69
|
+
success: true,
|
|
70
|
+
data,
|
|
71
|
+
durationMs: Date.now() - start,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
76
|
+
return {
|
|
77
|
+
toolId: manifest.id,
|
|
78
|
+
action: prefixedName,
|
|
79
|
+
success: false,
|
|
80
|
+
error: msg.includes('abort') ? `Timeout after ${timeoutMs}ms` : msg,
|
|
81
|
+
durationMs: Date.now() - start,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function createHttpAdapter(opts) {
|
|
87
|
+
const handlers = new Map();
|
|
88
|
+
for (const action of opts.manifest.tools) {
|
|
89
|
+
const prefixedName = `${opts.manifest.id}__${action.name}`;
|
|
90
|
+
handlers.set(prefixedName, createHttpHandler(opts.manifest, action.name, opts.fetchFn));
|
|
91
|
+
}
|
|
92
|
+
return handlers;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=http-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-adapter.js","sourceRoot":"","sources":["../../src/adapters/http-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E,MAAM,UAAU,gBAAgB,CAAC,IAA0B;IACzD,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,EAAE,CAAC;IAE7C,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAEvE,QAAQ,IA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E;gBACnB,MAAM,EAAE,YAAY;gBACpB,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iBAAiB,SAAS,IAAI,CAAC,CAAC,CAAC,GAAG;gBACnE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;aAC/B,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAwB;IACxD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAChD,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACzC,MAAM,YAAY,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3D,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,iBAAiB,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Routes tool calls to an external MCP server (HTTP transport).
|
|
5
|
+
* Sends POST /tools/call in MCP JSON-RPC style and reads the result.
|
|
6
|
+
* For stdio MCP servers, users should set endpoint to the HTTP bridge URL.
|
|
7
|
+
*
|
|
8
|
+
* Injectable fetch for test isolation.
|
|
9
|
+
*/
|
|
10
|
+
import type { ToolManifest, ToolHandler } from '../types.js';
|
|
11
|
+
import { type FetchFn } from './http-adapter.js';
|
|
12
|
+
export declare function createMcpHandler(manifest: ToolManifest, actionName: string, fetchFn?: FetchFn): ToolHandler;
|
|
13
|
+
export declare function createMcpAdapter(manifest: ToolManifest, fetchFn?: FetchFn): Map<string, ToolHandler>;
|
|
14
|
+
//# sourceMappingURL=mcp-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/mcp-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAkB,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AA0BnE,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,OAAe,GACvB,WAAW,CAuGb;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,YAAY,EACtB,OAAO,GAAE,OAAe,GACvB,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAO1B"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Adapter
|
|
3
|
+
*
|
|
4
|
+
* Routes tool calls to an external MCP server (HTTP transport).
|
|
5
|
+
* Sends POST /tools/call in MCP JSON-RPC style and reads the result.
|
|
6
|
+
* For stdio MCP servers, users should set endpoint to the HTTP bridge URL.
|
|
7
|
+
*
|
|
8
|
+
* Injectable fetch for test isolation.
|
|
9
|
+
*/
|
|
10
|
+
import { buildAuthHeaders } from './http-adapter.js';
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// MCP handler factory
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
let _mcpRequestId = 1;
|
|
15
|
+
export function createMcpHandler(manifest, actionName, fetchFn = fetch) {
|
|
16
|
+
const endpoint = manifest.endpoint;
|
|
17
|
+
const timeoutMs = manifest.timeout_ms ?? 10_000;
|
|
18
|
+
return async (args) => {
|
|
19
|
+
const start = Date.now();
|
|
20
|
+
const prefixedName = `${manifest.id}__${actionName}`;
|
|
21
|
+
const requestId = _mcpRequestId++;
|
|
22
|
+
const body = {
|
|
23
|
+
jsonrpc: '2.0',
|
|
24
|
+
id: requestId,
|
|
25
|
+
method: 'tools/call',
|
|
26
|
+
params: { name: actionName, arguments: args },
|
|
27
|
+
};
|
|
28
|
+
try {
|
|
29
|
+
const authHeaders = buildAuthHeaders(manifest.auth);
|
|
30
|
+
const controller = new AbortController();
|
|
31
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
32
|
+
let response;
|
|
33
|
+
try {
|
|
34
|
+
response = await fetchFn(endpoint, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
Accept: 'application/json',
|
|
39
|
+
...authHeaders,
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify(body),
|
|
42
|
+
signal: controller.signal,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
}
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
const text = await response.text().catch(() => '');
|
|
50
|
+
return {
|
|
51
|
+
toolId: manifest.id,
|
|
52
|
+
action: prefixedName,
|
|
53
|
+
success: false,
|
|
54
|
+
error: `MCP HTTP ${response.status}: ${text.slice(0, 200)}`,
|
|
55
|
+
durationMs: Date.now() - start,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const rpc = (await response.json());
|
|
59
|
+
if (rpc.error) {
|
|
60
|
+
return {
|
|
61
|
+
toolId: manifest.id,
|
|
62
|
+
action: prefixedName,
|
|
63
|
+
success: false,
|
|
64
|
+
error: `MCP error ${rpc.error.code}: ${rpc.error.message}`,
|
|
65
|
+
durationMs: Date.now() - start,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const result = rpc.result;
|
|
69
|
+
if (!result) {
|
|
70
|
+
return {
|
|
71
|
+
toolId: manifest.id,
|
|
72
|
+
action: prefixedName,
|
|
73
|
+
success: true,
|
|
74
|
+
data: null,
|
|
75
|
+
durationMs: Date.now() - start,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// Extract text content from MCP content array
|
|
79
|
+
const textContent = result.content
|
|
80
|
+
.filter((c) => c.type === 'text' && c.text)
|
|
81
|
+
.map((c) => c.text)
|
|
82
|
+
.join('\n');
|
|
83
|
+
let parsedData = textContent;
|
|
84
|
+
try {
|
|
85
|
+
parsedData = JSON.parse(textContent);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// keep as string
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
toolId: manifest.id,
|
|
92
|
+
action: prefixedName,
|
|
93
|
+
success: !result.isError,
|
|
94
|
+
data: parsedData,
|
|
95
|
+
error: result.isError ? String(parsedData) : undefined,
|
|
96
|
+
durationMs: Date.now() - start,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
101
|
+
return {
|
|
102
|
+
toolId: manifest.id,
|
|
103
|
+
action: prefixedName,
|
|
104
|
+
success: false,
|
|
105
|
+
error: msg.includes('abort') ? `Timeout after ${timeoutMs}ms` : msg,
|
|
106
|
+
durationMs: Date.now() - start,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function createMcpAdapter(manifest, fetchFn = fetch) {
|
|
112
|
+
const handlers = new Map();
|
|
113
|
+
for (const action of manifest.tools) {
|
|
114
|
+
const prefixedName = `${manifest.id}__${action.name}`;
|
|
115
|
+
handlers.set(prefixedName, createMcpHandler(manifest, action.name, fetchFn));
|
|
116
|
+
}
|
|
117
|
+
return handlers;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=mcp-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-adapter.js","sourceRoot":"","sources":["../../src/adapters/mcp-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,E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AAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,QAAsB,EACtB,UAAmB,KAAK;IAExB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAChD,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,YAAY,GAAG,GAAG,QAAQ,CAAC,EAAE,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;QACtD,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script Adapter
|
|
3
|
+
*
|
|
4
|
+
* Executes a local script (bash/python/Node) and reads JSON from stdout.
|
|
5
|
+
* The script receives tool arguments as a JSON string on stdin or via the
|
|
6
|
+
* WEAVE_TOOL_ARGS environment variable.
|
|
7
|
+
*
|
|
8
|
+
* Injectable spawn function for test isolation.
|
|
9
|
+
*/
|
|
10
|
+
import { spawn, type SpawnOptionsWithoutStdio } from 'node:child_process';
|
|
11
|
+
import type { ToolManifest, ToolHandler } from '../types.js';
|
|
12
|
+
export type SpawnFn = (command: string, args: string[], options: SpawnOptionsWithoutStdio) => ReturnType<typeof spawn>;
|
|
13
|
+
export declare function runScript(scriptPath: string, actionName: string, args: Record<string, unknown>, env: Record<string, string>, timeoutMs: number, spawnFn?: SpawnFn): Promise<{
|
|
14
|
+
stdout: string;
|
|
15
|
+
stderr: string;
|
|
16
|
+
exitCode: number;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function createScriptHandler(manifest: ToolManifest, actionName: string, spawnFn?: SpawnFn): ToolHandler;
|
|
19
|
+
export declare function createScriptAdapter(manifest: ToolManifest, spawnFn?: SpawnFn): Map<string, ToolHandler>;
|
|
20
|
+
//# sourceMappingURL=script-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/script-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAE,KAAK,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAkB,WAAW,EAAE,MAAM,aAAa,CAAC;AAM7E,MAAM,MAAM,OAAO,GAAG,CACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,wBAAwB,KAC9B,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AAM9B,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3B,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,OAAe,GACvB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA2C/D;AAMD,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,OAAO,GAChB,WAAW,CAuDb;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,YAAY,EACtB,OAAO,CAAC,EAAE,OAAO,GAChB,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAO1B"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Script Adapter
|
|
3
|
+
*
|
|
4
|
+
* Executes a local script (bash/python/Node) and reads JSON from stdout.
|
|
5
|
+
* The script receives tool arguments as a JSON string on stdin or via the
|
|
6
|
+
* WEAVE_TOOL_ARGS environment variable.
|
|
7
|
+
*
|
|
8
|
+
* Injectable spawn function for test isolation.
|
|
9
|
+
*/
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Script runner
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
export function runScript(scriptPath, actionName, args, env, timeoutMs, spawnFn = spawn) {
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
const child = spawnFn(scriptPath, [actionName], {
|
|
17
|
+
env: {
|
|
18
|
+
...process.env,
|
|
19
|
+
WEAVE_TOOL_ACTION: actionName,
|
|
20
|
+
WEAVE_TOOL_ARGS: JSON.stringify(args),
|
|
21
|
+
...env,
|
|
22
|
+
},
|
|
23
|
+
shell: true,
|
|
24
|
+
});
|
|
25
|
+
let stdout = '';
|
|
26
|
+
let stderr = '';
|
|
27
|
+
let timedOut = false;
|
|
28
|
+
const timer = setTimeout(() => {
|
|
29
|
+
timedOut = true;
|
|
30
|
+
child.kill('SIGTERM');
|
|
31
|
+
}, timeoutMs);
|
|
32
|
+
child.stdout?.on('data', (chunk) => {
|
|
33
|
+
stdout += chunk.toString();
|
|
34
|
+
});
|
|
35
|
+
child.stderr?.on('data', (chunk) => {
|
|
36
|
+
stderr += chunk.toString();
|
|
37
|
+
});
|
|
38
|
+
child.on('close', (code) => {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
resolve({
|
|
41
|
+
stdout,
|
|
42
|
+
stderr,
|
|
43
|
+
exitCode: timedOut ? -1 : (code ?? 0),
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
child.on('error', (err) => {
|
|
47
|
+
clearTimeout(timer);
|
|
48
|
+
resolve({ stdout: '', stderr: err.message, exitCode: -2 });
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Handler factory
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
export function createScriptHandler(manifest, actionName, spawnFn) {
|
|
56
|
+
const scriptPath = manifest.scriptPath;
|
|
57
|
+
const timeoutMs = manifest.timeout_ms ?? 10_000;
|
|
58
|
+
const scriptEnv = manifest.scriptEnv ?? {};
|
|
59
|
+
return async (args) => {
|
|
60
|
+
const start = Date.now();
|
|
61
|
+
const prefixedName = `${manifest.id}__${actionName}`;
|
|
62
|
+
const { stdout, stderr, exitCode } = await runScript(scriptPath, actionName, args, scriptEnv, timeoutMs, spawnFn);
|
|
63
|
+
if (exitCode === -1) {
|
|
64
|
+
return {
|
|
65
|
+
toolId: manifest.id,
|
|
66
|
+
action: prefixedName,
|
|
67
|
+
success: false,
|
|
68
|
+
error: `Script timeout after ${timeoutMs}ms`,
|
|
69
|
+
durationMs: Date.now() - start,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (exitCode !== 0) {
|
|
73
|
+
return {
|
|
74
|
+
toolId: manifest.id,
|
|
75
|
+
action: prefixedName,
|
|
76
|
+
success: false,
|
|
77
|
+
error: stderr.trim() || `Script exited with code ${exitCode}`,
|
|
78
|
+
durationMs: Date.now() - start,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// Parse JSON from stdout
|
|
82
|
+
const trimmed = stdout.trim();
|
|
83
|
+
let data = trimmed;
|
|
84
|
+
try {
|
|
85
|
+
data = JSON.parse(trimmed);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Return raw string if not valid JSON
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
toolId: manifest.id,
|
|
92
|
+
action: prefixedName,
|
|
93
|
+
success: true,
|
|
94
|
+
data,
|
|
95
|
+
durationMs: Date.now() - start,
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export function createScriptAdapter(manifest, spawnFn) {
|
|
100
|
+
const handlers = new Map();
|
|
101
|
+
for (const action of manifest.tools) {
|
|
102
|
+
const prefixedName = `${manifest.id}__${action.name}`;
|
|
103
|
+
handlers.set(prefixedName, createScriptHandler(manifest, action.name, spawnFn));
|
|
104
|
+
}
|
|
105
|
+
return handlers;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=script-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script-adapter.js","sourceRoot":"","sources":["../../src/adapters/script-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAiC,MAAM,oBAAoB,CAAC;AAa1E,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E,MAAM,UAAU,SAAS,CACvB,UAAkB,EAClB,UAAkB,EAClB,IAA6B,EAC7B,GAA2B,EAC3B,SAAiB,EACjB,UAAmB,KAAK;IAExB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,EAAE;YAC9C,GAAG,EAAE;gBACH,GAAG,OAAO,CAAC,GAAG;gBACd,iBAAiB,EAAE,UAAU;gBAC7B,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBACrC,GAAG,GAAG;aACP;YACD,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;QAEH,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,QAAQ,GAAG,KAAK,CAAC;QAErB,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,QAAQ,GAAG,IAAI,CAAC;YAChB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC,EAAE,SAAS,CAAC,CAAC;QAEd,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;YACzC,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE,C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G,EAAuB,CAAC;IAChD,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,YAAY,GAAG,GAAG,QAAQ,CAAC,EAAE,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC;QACtD,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @openweave/weave-tools
|
|
3
|
+
*
|
|
4
|
+
* External Tool Registry & Adapters — M24
|
|
5
|
+
* Enables users and developers to register any external tool and expose it
|
|
6
|
+
* to the OpenWeave agent as if it were a native tool.
|
|
7
|
+
*/
|
|
8
|
+
export { validateManifest, type AdapterType, type AuthType, type ToolAuth, type ToolInputSchema, type ToolAction, type ToolManifest, type ManifestValidationResult, type ToolCallResult, type ToolHandler, type RegisteredExternalTool, } from './types.js';
|
|
9
|
+
export { buildAuthHeaders, createHttpHandler, createHttpAdapter, type FetchFn, type HttpAdapterOptions, } from './adapters/http-adapter.js';
|
|
10
|
+
export { createMcpHandler, createMcpAdapter, } from './adapters/mcp-adapter.js';
|
|
11
|
+
export { runScript, createScriptHandler, createScriptAdapter, type SpawnFn, } from './adapters/script-adapter.js';
|
|
12
|
+
export { loadManifestFile, loadLocalManifests, loadNpmManifests, loadAllManifests, type LoadResult, type FsAdapter as LoaderFsAdapter, } from './tool-loader.js';
|
|
13
|
+
export { ToolStore, createToolStore, type ToolStoreData, } from './tool-store.js';
|
|
14
|
+
export { ExternalToolBridge, type ToolRegistryLike, } from './tool-bridge.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,gBAAgB,EAChB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,sBAAsB,GAC5B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,OAAO,EACZ,KAAK,kBAAkB,GACxB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,OAAO,GACb,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,IAAI,eAAe,GAClC,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,SAAS,EACT,eAAe,EACf,KAAK,aAAa,GACnB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,kBAAkB,EAClB,KAAK,gBAAgB,GACtB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @openweave/weave-tools
|
|
3
|
+
*
|
|
4
|
+
* External Tool Registry & Adapters — M24
|
|
5
|
+
* Enables users and developers to register any external tool and expose it
|
|
6
|
+
* to the OpenWeave agent as if it were a native tool.
|
|
7
|
+
*/
|
|
8
|
+
// Types
|
|
9
|
+
export { validateManifest, } from './types.js';
|
|
10
|
+
// Adapters
|
|
11
|
+
export { buildAuthHeaders, createHttpHandler, createHttpAdapter, } from './adapters/http-adapter.js';
|
|
12
|
+
export { createMcpHandler, createMcpAdapter, } from './adapters/mcp-adapter.js';
|
|
13
|
+
export { runScript, createScriptHandler, createScriptAdapter, } from './adapters/script-adapter.js';
|
|
14
|
+
// Loader
|
|
15
|
+
export { loadManifestFile, loadLocalManifests, loadNpmManifests, loadAllManifests, } from './tool-loader.js';
|
|
16
|
+
// Store
|
|
17
|
+
export { ToolStore, createToolStore, } from './tool-store.js';
|
|
18
|
+
// Bridge
|
|
19
|
+
export { ExternalToolBridge, } from './tool-bridge.js';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,QAAQ;AACR,OAAO,EACL,gBAAgB,GAWjB,MAAM,YAAY,CAAC;AAEpB,WAAW;AACX,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GAGlB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,mBAAmB,GAEpB,MAAM,8BAA8B,CAAC;AAEtC,SAAS;AACT,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,GAGjB,MAAM,kBAAkB,CAAC;AAE1B,QAAQ;AACR,OAAO,EACL,SAAS,EACT,eAAe,GAEhB,MAAM,iBAAiB,CAAC;AAEzB,SAAS;AACT,OAAO,EACL,kBAAkB,GAEnB,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExternalToolBridge
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates tool discovery, manifest loading, adapter creation and
|
|
5
|
+
* registration into any object that exposes a `register(name, handler)` API.
|
|
6
|
+
*
|
|
7
|
+
* This is the main entry point called from `AgentCore.init()`.
|
|
8
|
+
*
|
|
9
|
+
* Design:
|
|
10
|
+
* - Loads manifests from ToolLoader (local + npm)
|
|
11
|
+
* - Persists to ToolStore
|
|
12
|
+
* - Creates adapter handlers (HTTP / MCP / Script)
|
|
13
|
+
* - Registers prefixed action names into the provided registry
|
|
14
|
+
*/
|
|
15
|
+
import { type FsAdapter } from './tool-loader.js';
|
|
16
|
+
import { ToolStore } from './tool-store.js';
|
|
17
|
+
import { type ToolManifest, type RegisteredExternalTool, type ToolCallResult } from './types.js';
|
|
18
|
+
export interface ToolRegistryLike {
|
|
19
|
+
/** Register a new tool action */
|
|
20
|
+
register(def: {
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
parameters?: unknown;
|
|
24
|
+
}, handler: (args: Record<string, unknown>) => Promise<ToolCallResult>): void;
|
|
25
|
+
}
|
|
26
|
+
export declare class ExternalToolBridge {
|
|
27
|
+
private readonly registeredTools;
|
|
28
|
+
private readonly store;
|
|
29
|
+
private readonly projectRoot;
|
|
30
|
+
constructor(projectRoot: string, store?: ToolStore);
|
|
31
|
+
private createHandlers;
|
|
32
|
+
/**
|
|
33
|
+
* Register a single manifest and wire its handlers into the registry.
|
|
34
|
+
*/
|
|
35
|
+
registerManifest(manifest: ToolManifest, registry?: ToolRegistryLike): RegisteredExternalTool;
|
|
36
|
+
/**
|
|
37
|
+
* Load all manifests from disk and register them.
|
|
38
|
+
* Called from AgentCore.init().
|
|
39
|
+
*/
|
|
40
|
+
loadAll(registry?: ToolRegistryLike, fs?: FsAdapter): Promise<{
|
|
41
|
+
loaded: number;
|
|
42
|
+
errors: Array<{
|
|
43
|
+
source: string;
|
|
44
|
+
error: string;
|
|
45
|
+
}>;
|
|
46
|
+
}>;
|
|
47
|
+
get(id: string): RegisteredExternalTool | undefined;
|
|
48
|
+
list(): RegisteredExternalTool[];
|
|
49
|
+
has(id: string): boolean;
|
|
50
|
+
get size(): number;
|
|
51
|
+
/** Remove a tool at runtime */
|
|
52
|
+
unregister(id: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Execute an action directly (useful when calling from the CLI `weave tools test`).
|
|
55
|
+
*/
|
|
56
|
+
execute(prefixedActionName: string, args: Record<string, unknown>): Promise<ToolCallResult>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=tool-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-bridge.d.ts","sourceRoot":"","sources":["../src/tool-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,EAAoB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;AAMpB,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,QAAQ,CACN,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,EAChE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,cAAc,CAAC,GAClE,IAAI,CAAC;CACT;AAMD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkD;IAClF,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAEzB,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS;IAOlD,OAAO,CAAC,cAAc;IAatB;;OAEG;IACH,gBAAgB,CACd,QAAQ,EAAE,YAAY,EACtB,QAAQ,CAAC,EAAE,gBAAgB,GAC1B,sBAAsB;IAkCzB;;;OAGG;IACG,OAAO,CAAC,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;QAClE,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,KAAK,CAAC;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAClD,CAAC;IAcF,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,sBAAsB,GAAG,SAAS;IAInD,IAAI,IAAI,sBAAsB,EAAE;IAIhC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIxB,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,+BAA+B;IAC/B,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAM/B;;OAEG;IACG,OAAO,CACX,kBAAkB,EAAE,MAAM,EAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,cAAc,CAAC;CAgB3B"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExternalToolBridge
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates tool discovery, manifest loading, adapter creation and
|
|
5
|
+
* registration into any object that exposes a `register(name, handler)` API.
|
|
6
|
+
*
|
|
7
|
+
* This is the main entry point called from `AgentCore.init()`.
|
|
8
|
+
*
|
|
9
|
+
* Design:
|
|
10
|
+
* - Loads manifests from ToolLoader (local + npm)
|
|
11
|
+
* - Persists to ToolStore
|
|
12
|
+
* - Creates adapter handlers (HTTP / MCP / Script)
|
|
13
|
+
* - Registers prefixed action names into the provided registry
|
|
14
|
+
*/
|
|
15
|
+
import { createHttpAdapter } from './adapters/http-adapter.js';
|
|
16
|
+
import { createMcpAdapter } from './adapters/mcp-adapter.js';
|
|
17
|
+
import { createScriptAdapter } from './adapters/script-adapter.js';
|
|
18
|
+
import { loadAllManifests } from './tool-loader.js';
|
|
19
|
+
import { ToolStore } from './tool-store.js';
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// ExternalToolBridge
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
export class ExternalToolBridge {
|
|
24
|
+
registeredTools = new Map();
|
|
25
|
+
store;
|
|
26
|
+
projectRoot;
|
|
27
|
+
constructor(projectRoot, store) {
|
|
28
|
+
this.projectRoot = projectRoot;
|
|
29
|
+
this.store = store ?? new ToolStore(projectRoot);
|
|
30
|
+
}
|
|
31
|
+
// -------------------------------------------------------------------------
|
|
32
|
+
createHandlers(manifest) {
|
|
33
|
+
switch (manifest.adapter) {
|
|
34
|
+
case 'http':
|
|
35
|
+
return createHttpAdapter({ manifest });
|
|
36
|
+
case 'mcp':
|
|
37
|
+
return createMcpAdapter(manifest);
|
|
38
|
+
case 'script':
|
|
39
|
+
return createScriptAdapter(manifest);
|
|
40
|
+
default:
|
|
41
|
+
return new Map();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Register a single manifest and wire its handlers into the registry.
|
|
46
|
+
*/
|
|
47
|
+
registerManifest(manifest, registry) {
|
|
48
|
+
const handlers = this.createHandlers(manifest);
|
|
49
|
+
const actionNames = Array.from(handlers.keys());
|
|
50
|
+
const registered = {
|
|
51
|
+
manifest,
|
|
52
|
+
actionNames,
|
|
53
|
+
handlers,
|
|
54
|
+
registeredAt: new Date().toISOString(),
|
|
55
|
+
};
|
|
56
|
+
this.registeredTools.set(manifest.id, registered);
|
|
57
|
+
this.store.add(manifest);
|
|
58
|
+
// Wire handlers into the registry (if provided)
|
|
59
|
+
if (registry) {
|
|
60
|
+
for (const action of manifest.tools) {
|
|
61
|
+
const prefixedName = `${manifest.id}__${action.name}`;
|
|
62
|
+
const handler = handlers.get(prefixedName);
|
|
63
|
+
if (handler) {
|
|
64
|
+
registry.register({
|
|
65
|
+
name: prefixedName,
|
|
66
|
+
description: `[${manifest.name}] ${action.description}`,
|
|
67
|
+
}, handler);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return registered;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Load all manifests from disk and register them.
|
|
75
|
+
* Called from AgentCore.init().
|
|
76
|
+
*/
|
|
77
|
+
async loadAll(registry, fs) {
|
|
78
|
+
const { manifests, errors } = loadAllManifests(this.projectRoot, fs);
|
|
79
|
+
for (const manifest of manifests) {
|
|
80
|
+
this.registerManifest(manifest, registry);
|
|
81
|
+
}
|
|
82
|
+
return { loaded: manifests.length, errors };
|
|
83
|
+
}
|
|
84
|
+
// -------------------------------------------------------------------------
|
|
85
|
+
// Query API
|
|
86
|
+
// -------------------------------------------------------------------------
|
|
87
|
+
get(id) {
|
|
88
|
+
return this.registeredTools.get(id);
|
|
89
|
+
}
|
|
90
|
+
list() {
|
|
91
|
+
return Array.from(this.registeredTools.values());
|
|
92
|
+
}
|
|
93
|
+
has(id) {
|
|
94
|
+
return this.registeredTools.has(id);
|
|
95
|
+
}
|
|
96
|
+
get size() {
|
|
97
|
+
return this.registeredTools.size;
|
|
98
|
+
}
|
|
99
|
+
/** Remove a tool at runtime */
|
|
100
|
+
unregister(id) {
|
|
101
|
+
const existed = this.registeredTools.delete(id);
|
|
102
|
+
this.store.remove(id);
|
|
103
|
+
return existed;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Execute an action directly (useful when calling from the CLI `weave tools test`).
|
|
107
|
+
*/
|
|
108
|
+
async execute(prefixedActionName, args) {
|
|
109
|
+
// Find which tool owns this action
|
|
110
|
+
for (const reg of this.registeredTools.values()) {
|
|
111
|
+
const handler = reg.handlers.get(prefixedActionName);
|
|
112
|
+
if (handler) {
|
|
113
|
+
return handler(args);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
toolId: 'unknown',
|
|
118
|
+
action: prefixedActionName,
|
|
119
|
+
success: false,
|
|
120
|
+
error: `Action "${prefixedActionName}" not found in any registered tool`,
|
|
121
|
+
durationMs: 0,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|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
|
+
* Tool Loader
|
|
3
|
+
*
|
|
4
|
+
* Discovers ToolManifest descriptors from:
|
|
5
|
+
* 1. `.weave/tools/*.tool.json` — local project manifests
|
|
6
|
+
* 2. npm packages under `node_modules/@openweave-tools/` — community adapters
|
|
7
|
+
*
|
|
8
|
+
* Injectable FS functions for test isolation.
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
11
|
+
import { type ToolManifest } from './types.js';
|
|
12
|
+
export interface LoadResult {
|
|
13
|
+
manifests: ToolManifest[];
|
|
14
|
+
errors: Array<{
|
|
15
|
+
source: string;
|
|
16
|
+
error: string;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export interface FsAdapter {
|
|
20
|
+
existsSync: typeof existsSync;
|
|
21
|
+
readdirSync: typeof readdirSync;
|
|
22
|
+
readFileSync: typeof readFileSync;
|
|
23
|
+
}
|
|
24
|
+
export declare function loadManifestFile(filePath: string, fs?: FsAdapter): {
|
|
25
|
+
manifest: ToolManifest | null;
|
|
26
|
+
error: string | null;
|
|
27
|
+
};
|
|
28
|
+
/** Scans `.weave/tools/` directory for `*.tool.json` files. */
|
|
29
|
+
export declare function loadLocalManifests(projectRoot: string, fs?: FsAdapter): LoadResult;
|
|
30
|
+
/** Scans `node_modules/@openweave-tools/` for community adapter packages. */
|
|
31
|
+
export declare function loadNpmManifests(projectRoot: string, fs?: FsAdapter): LoadResult;
|
|
32
|
+
/** Load all manifests: local + npm. */
|
|
33
|
+
export declare function loadAllManifests(projectRoot: string, fs?: FsAdapter): LoadResult;
|
|
34
|
+
//# sourceMappingURL=tool-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-loader.d.ts","sourceRoot":"","sources":["../src/tool-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEhE,OAAO,EAAoB,KAAK,YAAY,EAAiC,MAAM,YAAY,CAAC;AAMhG,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,MAAM,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,WAAW,EAAE,OAAO,WAAW,CAAC;IAChC,YAAY,EAAE,OAAO,YAAY,CAAC;CACnC;AAQD,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,EAAE,GAAE,SAAsB,GACzB;IAAE,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAqBzD;AAED,+DAA+D;AAC/D,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,EAAE,GAAE,SAAsB,GACzB,UAAU,CA0BZ;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,EAAE,GAAE,SAAsB,GACzB,UAAU,CA2BZ;AAED,uCAAuC;AACvC,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,EAAE,GAAE,SAAsB,GACzB,UAAU,CAQZ"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Loader
|
|
3
|
+
*
|
|
4
|
+
* Discovers ToolManifest descriptors from:
|
|
5
|
+
* 1. `.weave/tools/*.tool.json` — local project manifests
|
|
6
|
+
* 2. npm packages under `node_modules/@openweave-tools/` — community adapters
|
|
7
|
+
*
|
|
8
|
+
* Injectable FS functions for test isolation.
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { validateManifest } from './types.js';
|
|
13
|
+
const DEFAULT_FS = { existsSync, readdirSync, readFileSync };
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Loaders
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
export function loadManifestFile(filePath, fs = DEFAULT_FS) {
|
|
18
|
+
let raw;
|
|
19
|
+
try {
|
|
20
|
+
raw = fs.readFileSync(filePath, 'utf8');
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
return { manifest: null, error: `Cannot read file: ${err instanceof Error ? err.message : String(err)}` };
|
|
24
|
+
}
|
|
25
|
+
let parsed;
|
|
26
|
+
try {
|
|
27
|
+
parsed = JSON.parse(raw);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return { manifest: null, error: `Invalid JSON in ${filePath}` };
|
|
31
|
+
}
|
|
32
|
+
const validation = validateManifest(parsed);
|
|
33
|
+
if (!validation.valid) {
|
|
34
|
+
return { manifest: null, error: `Validation failed: ${validation.errors.join('; ')}` };
|
|
35
|
+
}
|
|
36
|
+
return { manifest: parsed, error: null };
|
|
37
|
+
}
|
|
38
|
+
/** Scans `.weave/tools/` directory for `*.tool.json` files. */
|
|
39
|
+
export function loadLocalManifests(projectRoot, fs = DEFAULT_FS) {
|
|
40
|
+
const toolsDir = join(projectRoot, '.weave', 'tools');
|
|
41
|
+
const result = { manifests: [], errors: [] };
|
|
42
|
+
if (!fs.existsSync(toolsDir))
|
|
43
|
+
return result;
|
|
44
|
+
let entries;
|
|
45
|
+
try {
|
|
46
|
+
entries = fs.readdirSync(toolsDir);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
result.errors.push({ source: toolsDir, error: String(err) });
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
for (const entry of entries) {
|
|
53
|
+
if (!entry.endsWith('.tool.json'))
|
|
54
|
+
continue;
|
|
55
|
+
const filePath = join(toolsDir, entry);
|
|
56
|
+
const { manifest, error } = loadManifestFile(filePath, fs);
|
|
57
|
+
if (error) {
|
|
58
|
+
result.errors.push({ source: filePath, error });
|
|
59
|
+
}
|
|
60
|
+
else if (manifest) {
|
|
61
|
+
result.manifests.push(manifest);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
/** Scans `node_modules/@openweave-tools/` for community adapter packages. */
|
|
67
|
+
export function loadNpmManifests(projectRoot, fs = DEFAULT_FS) {
|
|
68
|
+
const nmDir = join(projectRoot, 'node_modules', '@openweave-tools');
|
|
69
|
+
const result = { manifests: [], errors: [] };
|
|
70
|
+
if (!fs.existsSync(nmDir))
|
|
71
|
+
return result;
|
|
72
|
+
let pkgs;
|
|
73
|
+
try {
|
|
74
|
+
pkgs = fs.readdirSync(nmDir);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
for (const pkg of pkgs) {
|
|
80
|
+
// Each @openweave-tools/<pkg> may have an `openweave.tool.json` at its root
|
|
81
|
+
const manifestPath = join(nmDir, pkg, 'openweave.tool.json');
|
|
82
|
+
if (!fs.existsSync(manifestPath))
|
|
83
|
+
continue;
|
|
84
|
+
const { manifest, error } = loadManifestFile(manifestPath, fs);
|
|
85
|
+
if (error) {
|
|
86
|
+
result.errors.push({ source: manifestPath, error });
|
|
87
|
+
}
|
|
88
|
+
else if (manifest) {
|
|
89
|
+
result.manifests.push(manifest);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
/** Load all manifests: local + npm. */
|
|
95
|
+
export function loadAllManifests(projectRoot, fs = DEFAULT_FS) {
|
|
96
|
+
const local = loadLocalManifests(projectRoot, fs);
|
|
97
|
+
const npm = loadNpmManifests(projectRoot, fs);
|
|
98
|
+
return {
|
|
99
|
+
manifests: [...local.manifests, ...npm.manifests],
|
|
100
|
+
errors: [...local.errors, ...npm.errors],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103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C;AAED,uCAAuC;AACvC,MAAM,UAAU,gBAAgB,CAC9B,WAAmB,EACnB,KAAgB,UAAU;IAE1B,MAAM,KAAK,GAAG,kBAAkB,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAClD,MAAM,GAAG,GAAG,gBAAgB,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAE9C,OAAO;QACL,SAAS,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC;QACjD,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;KACzC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Store
|
|
3
|
+
*
|
|
4
|
+
* Persists registered tool manifests to `.weave/tools.json`.
|
|
5
|
+
* Supports add / remove / list / get operations.
|
|
6
|
+
*
|
|
7
|
+
* Injectable FS functions for test isolation.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
10
|
+
import type { ToolManifest } from './types.js';
|
|
11
|
+
export interface ToolStoreData {
|
|
12
|
+
version: 1;
|
|
13
|
+
tools: Record<string, ToolManifest>;
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
}
|
|
16
|
+
export interface FsAdapter {
|
|
17
|
+
existsSync: typeof existsSync;
|
|
18
|
+
readFileSync: typeof readFileSync;
|
|
19
|
+
writeFileSync: typeof writeFileSync;
|
|
20
|
+
mkdirSync: typeof mkdirSync;
|
|
21
|
+
}
|
|
22
|
+
export declare class ToolStore {
|
|
23
|
+
private readonly storePath;
|
|
24
|
+
private readonly fs;
|
|
25
|
+
constructor(projectRoot: string, fs?: FsAdapter);
|
|
26
|
+
private read;
|
|
27
|
+
private write;
|
|
28
|
+
add(manifest: ToolManifest): void;
|
|
29
|
+
remove(id: string): boolean;
|
|
30
|
+
get(id: string): ToolManifest | null;
|
|
31
|
+
list(): ToolManifest[];
|
|
32
|
+
has(id: string): boolean;
|
|
33
|
+
size(): number;
|
|
34
|
+
clear(): void;
|
|
35
|
+
}
|
|
36
|
+
export declare function createToolStore(projectRoot: string, fs?: FsAdapter): ToolStore;
|
|
37
|
+
//# sourceMappingURL=tool-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-store.d.ts","sourceRoot":"","sources":["../src/tool-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM/C,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,YAAY,EAAE,OAAO,YAAY,CAAC;IAClC,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,SAAS,EAAE,OAAO,SAAS,CAAC;CAC7B;AAQD,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAY;gBAEnB,WAAW,EAAE,MAAM,EAAE,EAAE,GAAE,SAAsB;IAO3D,OAAO,CAAC,IAAI;IAYZ,OAAO,CAAC,KAAK;IAUb,GAAG,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IAOjC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAS3B,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAKpC,IAAI,IAAI,YAAY,EAAE;IAKtB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAKxB,IAAI,IAAI,MAAM;IAId,KAAK,IAAI,IAAI;CAGd;AAMD,wBAAgB,eAAe,CAC7B,WAAW,EAAE,MAAM,EACnB,EAAE,CAAC,EAAE,SAAS,GACb,SAAS,CAEX"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Store
|
|
3
|
+
*
|
|
4
|
+
* Persists registered tool manifests to `.weave/tools.json`.
|
|
5
|
+
* Supports add / remove / list / get operations.
|
|
6
|
+
*
|
|
7
|
+
* Injectable FS functions for test isolation.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
10
|
+
import { join, dirname } from 'node:path';
|
|
11
|
+
const DEFAULT_FS = { existsSync, readFileSync, writeFileSync, mkdirSync };
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// ToolStore
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
export class ToolStore {
|
|
16
|
+
storePath;
|
|
17
|
+
fs;
|
|
18
|
+
constructor(projectRoot, fs = DEFAULT_FS) {
|
|
19
|
+
this.storePath = join(projectRoot, '.weave', 'tools.json');
|
|
20
|
+
this.fs = fs;
|
|
21
|
+
}
|
|
22
|
+
// -------------------------------------------------------------------------
|
|
23
|
+
read() {
|
|
24
|
+
if (!this.fs.existsSync(this.storePath)) {
|
|
25
|
+
return { version: 1, tools: {}, updatedAt: new Date().toISOString() };
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const raw = this.fs.readFileSync(this.storePath, 'utf8');
|
|
29
|
+
return JSON.parse(raw);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { version: 1, tools: {}, updatedAt: new Date().toISOString() };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
write(data) {
|
|
36
|
+
const dir = dirname(this.storePath);
|
|
37
|
+
if (!this.fs.existsSync(dir)) {
|
|
38
|
+
this.fs.mkdirSync(dir, { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
this.fs.writeFileSync(this.storePath, JSON.stringify(data, null, 2), 'utf8');
|
|
41
|
+
}
|
|
42
|
+
// -------------------------------------------------------------------------
|
|
43
|
+
add(manifest) {
|
|
44
|
+
const data = this.read();
|
|
45
|
+
data.tools[manifest.id] = manifest;
|
|
46
|
+
data.updatedAt = new Date().toISOString();
|
|
47
|
+
this.write(data);
|
|
48
|
+
}
|
|
49
|
+
remove(id) {
|
|
50
|
+
const data = this.read();
|
|
51
|
+
if (!(id in data.tools))
|
|
52
|
+
return false;
|
|
53
|
+
delete data.tools[id];
|
|
54
|
+
data.updatedAt = new Date().toISOString();
|
|
55
|
+
this.write(data);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
get(id) {
|
|
59
|
+
const data = this.read();
|
|
60
|
+
return data.tools[id] ?? null;
|
|
61
|
+
}
|
|
62
|
+
list() {
|
|
63
|
+
const data = this.read();
|
|
64
|
+
return Object.values(data.tools);
|
|
65
|
+
}
|
|
66
|
+
has(id) {
|
|
67
|
+
const data = this.read();
|
|
68
|
+
return id in data.tools;
|
|
69
|
+
}
|
|
70
|
+
size() {
|
|
71
|
+
return this.list().length;
|
|
72
|
+
}
|
|
73
|
+
clear() {
|
|
74
|
+
this.write({ version: 1, tools: {}, updatedAt: new Date().toISOString() });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Factory
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
export function createToolStore(projectRoot, fs) {
|
|
81
|
+
return new ToolStore(projectRoot, fs);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=tool-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-store.js","sourceRoot":"","sources":["../src/tool-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAA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CAAC,CAAC;IACnC,CAAC;IAED,GAAG,CAAC,EAAU;QACZ,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC7E,CAAC;CACF;AAED,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,MAAM,UAAU,eAAe,CAC7B,WAAmB,EACnB,EAAc;IAEd,OAAO,IAAI,SAAS,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeaveTools — Type Definitions (M24)
|
|
3
|
+
*
|
|
4
|
+
* Core contracts for the External Tool Registry & Adapters system.
|
|
5
|
+
* A ToolManifest describes any external tool; adapters route calls to the right backend.
|
|
6
|
+
*/
|
|
7
|
+
/** Transport mechanism used to reach the external tool. */
|
|
8
|
+
export type AdapterType = 'http' | 'mcp' | 'script';
|
|
9
|
+
/** Authentication strategies for HTTP/MCP adapters. */
|
|
10
|
+
export type AuthType = 'bearer' | 'api-key' | 'basic' | 'none';
|
|
11
|
+
export interface ToolAuth {
|
|
12
|
+
type: AuthType;
|
|
13
|
+
/** Name of the environment variable holding the credential */
|
|
14
|
+
envVar?: string;
|
|
15
|
+
/** HTTP header name for api-key auth (default: 'X-API-Key') */
|
|
16
|
+
headerName?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ToolInputSchema {
|
|
19
|
+
type: 'object';
|
|
20
|
+
properties: Record<string, {
|
|
21
|
+
type: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
enum?: unknown[];
|
|
24
|
+
}>;
|
|
25
|
+
required?: string[];
|
|
26
|
+
}
|
|
27
|
+
/** A single callable action within an external tool manifest. */
|
|
28
|
+
export interface ToolAction {
|
|
29
|
+
/** Matches the MCP tool name / HTTP action path */
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
inputSchema: ToolInputSchema;
|
|
33
|
+
}
|
|
34
|
+
export interface ToolManifest {
|
|
35
|
+
/** Unique identifier, used as prefix: `<id>__<action>` */
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
description: string;
|
|
39
|
+
version: string;
|
|
40
|
+
adapter: AdapterType;
|
|
41
|
+
endpoint?: string;
|
|
42
|
+
auth?: ToolAuth;
|
|
43
|
+
/** Path to executable script (relative to project root) */
|
|
44
|
+
scriptPath?: string;
|
|
45
|
+
/** Extra environment variables to pass to the script */
|
|
46
|
+
scriptEnv?: Record<string, string>;
|
|
47
|
+
/** Timeout in milliseconds (default: 10 000) */
|
|
48
|
+
timeout_ms?: number;
|
|
49
|
+
tools: ToolAction[];
|
|
50
|
+
}
|
|
51
|
+
export interface ManifestValidationResult {
|
|
52
|
+
valid: boolean;
|
|
53
|
+
errors: string[];
|
|
54
|
+
}
|
|
55
|
+
export declare function validateManifest(manifest: unknown): ManifestValidationResult;
|
|
56
|
+
/** Result of invoking a single tool action. */
|
|
57
|
+
export interface ToolCallResult {
|
|
58
|
+
toolId: string;
|
|
59
|
+
action: string;
|
|
60
|
+
success: boolean;
|
|
61
|
+
data?: unknown;
|
|
62
|
+
error?: string;
|
|
63
|
+
durationMs: number;
|
|
64
|
+
}
|
|
65
|
+
/** Internal handler function registered in the tool registry for each action. */
|
|
66
|
+
export type ToolHandler = (args: Record<string, unknown>) => Promise<ToolCallResult>;
|
|
67
|
+
/** A registered external tool with its resolved handler. */
|
|
68
|
+
export interface RegisteredExternalTool {
|
|
69
|
+
manifest: ToolManifest;
|
|
70
|
+
/** Prefixed action names: `<id>__<action>` */
|
|
71
|
+
actionNames: string[];
|
|
72
|
+
handlers: Map<string, ToolHandler>;
|
|
73
|
+
registeredAt: string;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,2DAA2D;AAC3D,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEpD,uDAAuD;AACvD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;AAE/D,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,QAAQ,CAAC;IACf,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAMD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC,CAAC;IACrF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,iEAAiE;AACjE,MAAM,WAAW,UAAU;IACzB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,eAAe,CAAC;CAC9B;AAMD,MAAM,WAAW,YAAY;IAC3B,0DAA0D;IAC1D,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,WAAW,CAA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olManifest describes any external tool; adapters route calls to the right backend.
|
|
6
|
+
*/
|
|
7
|
+
export function validateManifest(manifest) {
|
|
8
|
+
const errors = [];
|
|
9
|
+
if (!manifest || typeof manifest !== 'object') {
|
|
10
|
+
return { valid: false, errors: ['Manifest must be an object'] };
|
|
11
|
+
}
|
|
12
|
+
const m = manifest;
|
|
13
|
+
if (!m['id'] || typeof m['id'] !== 'string')
|
|
14
|
+
errors.push('Missing required field: id (string)');
|
|
15
|
+
if (!m['name'] || typeof m['name'] !== 'string')
|
|
16
|
+
errors.push('Missing required field: name (string)');
|
|
17
|
+
if (!m['description'] || typeof m['description'] !== 'string')
|
|
18
|
+
errors.push('Missing required field: description (string)');
|
|
19
|
+
if (!m['version'] || typeof m['version'] !== 'string')
|
|
20
|
+
errors.push('Missing required field: version (string)');
|
|
21
|
+
const validAdapters = ['http', 'mcp', 'script'];
|
|
22
|
+
if (!validAdapters.includes(m['adapter'])) {
|
|
23
|
+
errors.push(`Invalid adapter "${m['adapter']}" — must be one of: ${validAdapters.join(', ')}`);
|
|
24
|
+
}
|
|
25
|
+
if (m['adapter'] === 'http' || m['adapter'] === 'mcp') {
|
|
26
|
+
if (!m['endpoint'] || typeof m['endpoint'] !== 'string') {
|
|
27
|
+
errors.push('HTTP/MCP adapter requires endpoint (string)');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (m['adapter'] === 'script') {
|
|
31
|
+
if (!m['scriptPath'] || typeof m['scriptPath'] !== 'string') {
|
|
32
|
+
errors.push('Script adapter requires scriptPath (string)');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!Array.isArray(m['tools'])) {
|
|
36
|
+
errors.push('Missing required field: tools (array)');
|
|
37
|
+
}
|
|
38
|
+
else if (m['tools'].length === 0) {
|
|
39
|
+
errors.push('tools array must contain at least one action');
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
for (const t of m['tools']) {
|
|
43
|
+
const tool = t;
|
|
44
|
+
if (!tool['name'])
|
|
45
|
+
errors.push(`Tool action missing "name" field`);
|
|
46
|
+
if (!tool['description'])
|
|
47
|
+
errors.push(`Tool action "${tool['name']}" missing "description"`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { valid: errors.length === 0, errors };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA2EH,MAAM,UAAU,gBAAgB,CAAC,QAAiB;IAChD,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC9C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,4BAA4B,CAAC,EAAE,CAAC;IAClE,CAAC;IAED,MAAM,CAAC,GAAG,QAAmC,CAAC;IAE9C,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,QAAQ;QAAE,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;IAChG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,QAAQ;QAAE,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;IACtG,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,OAAO,CAAC,CAAC,aAAa,CAAC,KAAK,QAAQ;QAAE,MAAM,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;IAC3H,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,QAAQ;QAAE,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;IAE/G,MAAM,aAAa,GAAkB,CAAC,MAAM,EAAE,KAAK,EAAE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AAC,kCAAkC,CAAC,CAAC;YACnE,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;gBAAE,MAAM,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openweave/weave-tools",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "WeaveTools — External Tool Registry & Adapters for OpenWeave agent extensibility",
|
|
5
|
+
"private": false,
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"openweave",
|
|
22
|
+
"tools",
|
|
23
|
+
"adapters",
|
|
24
|
+
"mcp",
|
|
25
|
+
"agent",
|
|
26
|
+
"extensibility"
|
|
27
|
+
],
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "22.10.2",
|
|
30
|
+
"typescript": "5.7.2",
|
|
31
|
+
"vitest": "3.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"dev": "tsc --watch",
|
|
36
|
+
"test": "vitest",
|
|
37
|
+
"lint": "eslint src --max-warnings 0",
|
|
38
|
+
"clean": "rm -rf dist"
|
|
39
|
+
}
|
|
40
|
+
}
|