lavs-runtime 0.1.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/README.md +75 -0
- package/dist/function-executor.d.ts +26 -0
- package/dist/function-executor.d.ts.map +1 -0
- package/dist/function-executor.js +116 -0
- package/dist/function-executor.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +37 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +187 -0
- package/dist/loader.js.map +1 -0
- package/dist/permission-checker.d.ts +86 -0
- package/dist/permission-checker.d.ts.map +1 -0
- package/dist/permission-checker.js +172 -0
- package/dist/permission-checker.js.map +1 -0
- package/dist/rate-limiter.d.ts +57 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/rate-limiter.js +84 -0
- package/dist/rate-limiter.js.map +1 -0
- package/dist/script-executor.d.ts +70 -0
- package/dist/script-executor.d.ts.map +1 -0
- package/dist/script-executor.js +314 -0
- package/dist/script-executor.js.map +1 -0
- package/dist/subscription-manager.d.ts +106 -0
- package/dist/subscription-manager.d.ts.map +1 -0
- package/dist/subscription-manager.js +257 -0
- package/dist/subscription-manager.js.map +1 -0
- package/dist/tool-generator.d.ts +51 -0
- package/dist/tool-generator.d.ts.map +1 -0
- package/dist/tool-generator.js +147 -0
- package/dist/tool-generator.js.map +1 -0
- package/dist/types.d.ts +171 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +38 -0
- package/dist/types.js.map +1 -0
- package/dist/validator.d.ts +94 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +187 -0
- package/dist/validator.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* LAVS Subscription Manager
|
|
4
|
+
*
|
|
5
|
+
* Manages real-time subscriptions for LAVS endpoints.
|
|
6
|
+
* Uses Server-Sent Events (SSE) as the transport layer.
|
|
7
|
+
*
|
|
8
|
+
* Protocol flow:
|
|
9
|
+
* 1. Client opens SSE connection: GET /api/agents/:agentId/lavs/:endpoint/subscribe
|
|
10
|
+
* 2. Server sends events when data changes
|
|
11
|
+
* 3. Client or server can close the connection
|
|
12
|
+
*/
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.subscriptionManager = exports.SubscriptionManager = void 0;
|
|
18
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
19
|
+
/**
|
|
20
|
+
* LAVS Subscription Manager - manages SSE-based subscriptions
|
|
21
|
+
*/
|
|
22
|
+
class SubscriptionManager {
|
|
23
|
+
subscriptions = new Map();
|
|
24
|
+
maxSubscriptions;
|
|
25
|
+
heartbeatTimer = null;
|
|
26
|
+
constructor(options = {}) {
|
|
27
|
+
this.maxSubscriptions = options.maxSubscriptions ?? 100;
|
|
28
|
+
const heartbeatMs = options.heartbeatIntervalMs ?? 30_000;
|
|
29
|
+
// Send periodic heartbeats to keep connections alive and detect stale ones
|
|
30
|
+
this.heartbeatTimer = setInterval(() => this.sendHeartbeats(), heartbeatMs);
|
|
31
|
+
// Allow the process to exit even with the timer running
|
|
32
|
+
if (this.heartbeatTimer.unref) {
|
|
33
|
+
this.heartbeatTimer.unref();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Send heartbeat to all subscriptions. Removes stale connections.
|
|
38
|
+
*/
|
|
39
|
+
sendHeartbeats() {
|
|
40
|
+
for (const [subId, sub] of this.subscriptions.entries()) {
|
|
41
|
+
try {
|
|
42
|
+
if (sub.res.writableEnded) {
|
|
43
|
+
this.subscriptions.delete(subId);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
// SSE comment line as heartbeat (ignored by clients but keeps connection alive)
|
|
47
|
+
sub.res.write(': heartbeat\n\n');
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
this.subscriptions.delete(subId);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Stop the heartbeat timer (for graceful shutdown / tests)
|
|
56
|
+
*/
|
|
57
|
+
destroy() {
|
|
58
|
+
if (this.heartbeatTimer) {
|
|
59
|
+
clearInterval(this.heartbeatTimer);
|
|
60
|
+
this.heartbeatTimer = null;
|
|
61
|
+
}
|
|
62
|
+
// Close all active subscriptions
|
|
63
|
+
for (const subId of [...this.subscriptions.keys()]) {
|
|
64
|
+
this.unsubscribe(subId);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create a new subscription.
|
|
69
|
+
*
|
|
70
|
+
* @param agentId - Agent identifier
|
|
71
|
+
* @param endpointId - Endpoint identifier (must be a subscription endpoint)
|
|
72
|
+
* @param res - Express response object (will be held open for SSE)
|
|
73
|
+
* @returns Subscription ID
|
|
74
|
+
* @throws Error if max subscriptions limit is reached
|
|
75
|
+
*/
|
|
76
|
+
subscribe(agentId, endpointId, res) {
|
|
77
|
+
if (this.subscriptions.size >= this.maxSubscriptions) {
|
|
78
|
+
throw new Error(`Maximum subscriptions limit reached (${this.maxSubscriptions}). ` +
|
|
79
|
+
'Close existing subscriptions before opening new ones.');
|
|
80
|
+
}
|
|
81
|
+
const subscriptionId = crypto_1.default.randomUUID();
|
|
82
|
+
// Set SSE headers
|
|
83
|
+
res.writeHead(200, {
|
|
84
|
+
'Content-Type': 'text/event-stream',
|
|
85
|
+
'Cache-Control': 'no-cache',
|
|
86
|
+
'Connection': 'keep-alive',
|
|
87
|
+
'X-Subscription-Id': subscriptionId,
|
|
88
|
+
});
|
|
89
|
+
// Send initial connection event
|
|
90
|
+
this.sendSSE(res, {
|
|
91
|
+
event: 'connected',
|
|
92
|
+
data: JSON.stringify({
|
|
93
|
+
subscriptionId,
|
|
94
|
+
agentId,
|
|
95
|
+
endpointId,
|
|
96
|
+
message: 'Subscription active',
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
// Store subscription
|
|
100
|
+
const subscription = {
|
|
101
|
+
id: subscriptionId,
|
|
102
|
+
agentId,
|
|
103
|
+
endpointId,
|
|
104
|
+
res,
|
|
105
|
+
createdAt: Date.now(),
|
|
106
|
+
};
|
|
107
|
+
this.subscriptions.set(subscriptionId, subscription);
|
|
108
|
+
// Clean up on client disconnect
|
|
109
|
+
res.on('close', () => {
|
|
110
|
+
this.unsubscribe(subscriptionId);
|
|
111
|
+
});
|
|
112
|
+
console.log(JSON.stringify({
|
|
113
|
+
level: 'info',
|
|
114
|
+
module: 'lavs',
|
|
115
|
+
event: 'subscription_created',
|
|
116
|
+
subscriptionId,
|
|
117
|
+
agentId,
|
|
118
|
+
endpointId,
|
|
119
|
+
totalActive: this.subscriptions.size,
|
|
120
|
+
}));
|
|
121
|
+
return subscriptionId;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Remove a subscription
|
|
125
|
+
*/
|
|
126
|
+
unsubscribe(subscriptionId) {
|
|
127
|
+
const sub = this.subscriptions.get(subscriptionId);
|
|
128
|
+
if (!sub)
|
|
129
|
+
return false;
|
|
130
|
+
// End the SSE stream
|
|
131
|
+
try {
|
|
132
|
+
if (!sub.res.writableEnded) {
|
|
133
|
+
this.sendSSE(sub.res, {
|
|
134
|
+
event: 'disconnected',
|
|
135
|
+
data: JSON.stringify({ reason: 'unsubscribed' }),
|
|
136
|
+
});
|
|
137
|
+
sub.res.end();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
// Ignore errors on cleanup
|
|
142
|
+
}
|
|
143
|
+
this.subscriptions.delete(subscriptionId);
|
|
144
|
+
console.log(JSON.stringify({
|
|
145
|
+
level: 'info',
|
|
146
|
+
module: 'lavs',
|
|
147
|
+
event: 'subscription_removed',
|
|
148
|
+
subscriptionId,
|
|
149
|
+
agentId: sub.agentId,
|
|
150
|
+
endpointId: sub.endpointId,
|
|
151
|
+
totalActive: this.subscriptions.size,
|
|
152
|
+
}));
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Push an event to all subscribers of a specific agent+endpoint.
|
|
157
|
+
*
|
|
158
|
+
* @param agentId - Agent identifier
|
|
159
|
+
* @param endpointId - Endpoint identifier
|
|
160
|
+
* @param event - Event data to push
|
|
161
|
+
* @returns Number of subscribers notified
|
|
162
|
+
*/
|
|
163
|
+
publish(agentId, endpointId, event) {
|
|
164
|
+
let count = 0;
|
|
165
|
+
for (const [subId, sub] of this.subscriptions.entries()) {
|
|
166
|
+
if (sub.agentId === agentId && sub.endpointId === endpointId) {
|
|
167
|
+
try {
|
|
168
|
+
if (!sub.res.writableEnded) {
|
|
169
|
+
this.sendSSE(sub.res, {
|
|
170
|
+
event: event.type,
|
|
171
|
+
data: JSON.stringify({
|
|
172
|
+
...event,
|
|
173
|
+
timestamp: event.timestamp || new Date().toISOString(),
|
|
174
|
+
}),
|
|
175
|
+
id: subId,
|
|
176
|
+
});
|
|
177
|
+
count++;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
// Remove broken connections
|
|
182
|
+
this.subscriptions.delete(subId);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return count;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Push an event to all subscribers of a specific agent (any endpoint).
|
|
190
|
+
*
|
|
191
|
+
* @param agentId - Agent identifier
|
|
192
|
+
* @param event - Event data to push
|
|
193
|
+
* @returns Number of subscribers notified
|
|
194
|
+
*/
|
|
195
|
+
publishToAgent(agentId, event) {
|
|
196
|
+
let count = 0;
|
|
197
|
+
for (const [subId, sub] of this.subscriptions.entries()) {
|
|
198
|
+
if (sub.agentId === agentId) {
|
|
199
|
+
try {
|
|
200
|
+
if (!sub.res.writableEnded) {
|
|
201
|
+
this.sendSSE(sub.res, {
|
|
202
|
+
event: event.type,
|
|
203
|
+
data: JSON.stringify({
|
|
204
|
+
...event,
|
|
205
|
+
timestamp: event.timestamp || new Date().toISOString(),
|
|
206
|
+
}),
|
|
207
|
+
id: subId,
|
|
208
|
+
});
|
|
209
|
+
count++;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
this.subscriptions.delete(subId);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return count;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get count of active subscriptions
|
|
221
|
+
*/
|
|
222
|
+
getActiveCount() {
|
|
223
|
+
return this.subscriptions.size;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get active subscriptions for an agent
|
|
227
|
+
*/
|
|
228
|
+
getSubscriptionsForAgent(agentId) {
|
|
229
|
+
const result = [];
|
|
230
|
+
for (const sub of this.subscriptions.values()) {
|
|
231
|
+
if (sub.agentId === agentId) {
|
|
232
|
+
result.push({
|
|
233
|
+
id: sub.id,
|
|
234
|
+
endpointId: sub.endpointId,
|
|
235
|
+
createdAt: sub.createdAt,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Send an SSE event to a response stream
|
|
243
|
+
*/
|
|
244
|
+
sendSSE(res, opts) {
|
|
245
|
+
if (opts.id) {
|
|
246
|
+
res.write(`id: ${opts.id}\n`);
|
|
247
|
+
}
|
|
248
|
+
if (opts.event) {
|
|
249
|
+
res.write(`event: ${opts.event}\n`);
|
|
250
|
+
}
|
|
251
|
+
res.write(`data: ${opts.data}\n\n`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.SubscriptionManager = SubscriptionManager;
|
|
255
|
+
// Singleton instance
|
|
256
|
+
exports.subscriptionManager = new SubscriptionManager();
|
|
257
|
+
//# sourceMappingURL=subscription-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription-manager.js","sourceRoot":"","sources":["../src/subscription-manager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;AAEH,oDAA4B;AA4C5B;;GAEG;AACH,MAAa,mBAAmB;IACtB,aAAa,GAA8B,IAAI,GAAG,EAAE,CAAC;IAC5C,gBAAgB,CAAS;IAClC,cAAc,GAA0C,IAAI,CAAC;IAErE,YAAY,UAAsC,EAAE;QAClD,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,GAAG,CAAC;QACxD,MAAM,WAAW,GAAG,OAAO,CAAC,mBAAmB,IAAI,MAAM,CAAC;QAE1D,2EAA2E;QAC3E,IAAI,CAAC,cAAc,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,WAAW,CAAC,CAAC;QAC5E,wDAAwD;QACxD,IAAI,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;YAC9B,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IAED;;OAEG;IACK,cAAc;QACpB,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC;YACxD,IAAI,CAAC;gBACH,IAAI,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;oBAC1B,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACjC,SAAS;gBACX,CAAC;gBACD,gFAAgF;gBAChF,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACnC,CAAC;YAAC,MAAM,CAAC;gBACP,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACnC,C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E,CAAC;YACZ,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QACtC,CAAC;QACD,GAAG,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC;IACtC,CAAC;CACF;AAhQD,kDAgQC;AAED,qBAAqB;AACR,QAAA,mBAAmB,GAAG,IAAI,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LAVS Tool Generator
|
|
3
|
+
*
|
|
4
|
+
* Automatically generates Claude SDK tool definitions from LAVS manifests.
|
|
5
|
+
* This allows AI agents to call LAVS endpoints as tools.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Claude SDK tool definition
|
|
9
|
+
*/
|
|
10
|
+
export interface ClaudeTool {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
input_schema: {
|
|
14
|
+
type: 'object';
|
|
15
|
+
properties: Record<string, any>;
|
|
16
|
+
required?: string[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Tool execution function
|
|
21
|
+
*/
|
|
22
|
+
export type ToolExecutor = (params: any) => Promise<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Generated tool with executor
|
|
25
|
+
*/
|
|
26
|
+
export interface GeneratedTool {
|
|
27
|
+
tool: ClaudeTool;
|
|
28
|
+
execute: ToolExecutor;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generate tools from LAVS manifest
|
|
32
|
+
*/
|
|
33
|
+
export declare class LAVSToolGenerator {
|
|
34
|
+
/**
|
|
35
|
+
* Generate tools for an agent
|
|
36
|
+
* @param agentId - Agent ID
|
|
37
|
+
* @param agentDir - Agent directory path
|
|
38
|
+
* @param projectPath - Optional project path for data isolation
|
|
39
|
+
* @returns Array of generated tools
|
|
40
|
+
*/
|
|
41
|
+
generateTools(agentId: string, agentDir: string, projectPath?: string): Promise<GeneratedTool[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Generate tool definition and executor for an endpoint
|
|
44
|
+
*/
|
|
45
|
+
private generateToolForEndpoint;
|
|
46
|
+
/**
|
|
47
|
+
* Check if agent has LAVS
|
|
48
|
+
*/
|
|
49
|
+
hasLAVS(agentDir: string): Promise<boolean>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=tool-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-generator.d.ts","sourceRoot":"","sources":["../src/tool-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE;QACZ,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,YAAY,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,iBAAiB;IAC5B;;;;;;OAMG;IACG,aAAa,CACjB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,aAAa,EAAE,CAAC;IAiC3B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAyG/B;;OAEG;IACG,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAUlD"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* LAVS Tool Generator
|
|
4
|
+
*
|
|
5
|
+
* Automatically generates Claude SDK tool definitions from LAVS manifests.
|
|
6
|
+
* This allows AI agents to call LAVS endpoints as tools.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LAVSToolGenerator = void 0;
|
|
13
|
+
const loader_1 = require("./loader");
|
|
14
|
+
const script_executor_1 = require("./script-executor");
|
|
15
|
+
const function_executor_1 = require("./function-executor");
|
|
16
|
+
const validator_1 = require("./validator");
|
|
17
|
+
const permission_checker_1 = require("./permission-checker");
|
|
18
|
+
const path_1 = __importDefault(require("path"));
|
|
19
|
+
/**
|
|
20
|
+
* Generate tools from LAVS manifest
|
|
21
|
+
*/
|
|
22
|
+
class LAVSToolGenerator {
|
|
23
|
+
/**
|
|
24
|
+
* Generate tools for an agent
|
|
25
|
+
* @param agentId - Agent ID
|
|
26
|
+
* @param agentDir - Agent directory path
|
|
27
|
+
* @param projectPath - Optional project path for data isolation
|
|
28
|
+
* @returns Array of generated tools
|
|
29
|
+
*/
|
|
30
|
+
async generateTools(agentId, agentDir, projectPath) {
|
|
31
|
+
try {
|
|
32
|
+
// Load manifest
|
|
33
|
+
const lavsPath = path_1.default.join(agentDir, 'lavs.json');
|
|
34
|
+
const loader = new loader_1.ManifestLoader();
|
|
35
|
+
const manifest = await loader.load(lavsPath);
|
|
36
|
+
// Generate tool for each endpoint
|
|
37
|
+
const tools = [];
|
|
38
|
+
for (const endpoint of manifest.endpoints) {
|
|
39
|
+
// Only generate tools for query and mutation endpoints
|
|
40
|
+
// Subscriptions don't make sense as tools
|
|
41
|
+
if (endpoint.method === 'subscription') {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const tool = this.generateToolForEndpoint(endpoint, manifest, agentId, agentDir, projectPath);
|
|
45
|
+
tools.push(tool);
|
|
46
|
+
}
|
|
47
|
+
console.log(`[LAVS] Generated ${tools.length} tools for agent ${agentId}`);
|
|
48
|
+
return tools;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// If no lavs.json, that's OK - just return empty array
|
|
52
|
+
const message = error instanceof Error ? error.message : '';
|
|
53
|
+
if (message.includes('not found')) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generate tool definition and executor for an endpoint
|
|
61
|
+
*/
|
|
62
|
+
generateToolForEndpoint(endpoint, manifest, agentId, agentDir, projectPath) {
|
|
63
|
+
// Generate tool name (prefix with lavs_ to avoid conflicts)
|
|
64
|
+
const toolName = `lavs_${endpoint.id}`;
|
|
65
|
+
// Generate tool description
|
|
66
|
+
const description = endpoint.description || `Call ${endpoint.id} endpoint from ${manifest.name}`;
|
|
67
|
+
// Generate input schema from endpoint schema
|
|
68
|
+
const inputSchema = endpoint.schema?.input || {
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: {},
|
|
71
|
+
};
|
|
72
|
+
// Ensure it's an object schema
|
|
73
|
+
if (inputSchema.type !== 'object') {
|
|
74
|
+
throw new Error(`Endpoint ${endpoint.id} must have object input schema`);
|
|
75
|
+
}
|
|
76
|
+
const tool = {
|
|
77
|
+
name: toolName,
|
|
78
|
+
description,
|
|
79
|
+
input_schema: {
|
|
80
|
+
type: 'object',
|
|
81
|
+
properties: inputSchema.properties || {},
|
|
82
|
+
required: inputSchema.required || [],
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
// Create shared instances for validation and permission checking
|
|
86
|
+
const validator = new validator_1.LAVSValidator();
|
|
87
|
+
const permChecker = new permission_checker_1.PermissionChecker();
|
|
88
|
+
// Create executor function
|
|
89
|
+
const execute = async (params) => {
|
|
90
|
+
console.log(`[LAVS] Executing tool ${toolName} with params:`, params);
|
|
91
|
+
// 1. Validate input against schema
|
|
92
|
+
validator.assertValidInput(endpoint, params);
|
|
93
|
+
// 2. Merge permissions
|
|
94
|
+
const mergedPermissions = permChecker.mergePermissions(manifest.permissions, endpoint.permissions);
|
|
95
|
+
// 3. Check permissions for script handlers
|
|
96
|
+
if (endpoint.handler.type === 'script') {
|
|
97
|
+
permChecker.assertAllowed(endpoint.handler, mergedPermissions, agentDir);
|
|
98
|
+
}
|
|
99
|
+
// 4. Build execution context
|
|
100
|
+
const context = {
|
|
101
|
+
endpointId: endpoint.id,
|
|
102
|
+
agentId,
|
|
103
|
+
workdir: agentDir,
|
|
104
|
+
permissions: mergedPermissions,
|
|
105
|
+
env: projectPath ? {
|
|
106
|
+
LAVS_PROJECT_PATH: projectPath,
|
|
107
|
+
} : undefined,
|
|
108
|
+
};
|
|
109
|
+
// 5. Execute the handler
|
|
110
|
+
let result;
|
|
111
|
+
switch (endpoint.handler.type) {
|
|
112
|
+
case 'script': {
|
|
113
|
+
const executor = new script_executor_1.ScriptExecutor();
|
|
114
|
+
result = await executor.execute(endpoint.handler, params, context);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'function': {
|
|
118
|
+
const funcExecutor = new function_executor_1.FunctionExecutor();
|
|
119
|
+
result = await funcExecutor.execute(endpoint.handler, params, context);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
default:
|
|
123
|
+
throw new Error(`Handler type '${endpoint.handler.type}' is not yet supported in tool generation`);
|
|
124
|
+
}
|
|
125
|
+
// 5. Validate output against schema
|
|
126
|
+
validator.assertValidOutput(endpoint, result);
|
|
127
|
+
return result;
|
|
128
|
+
};
|
|
129
|
+
return { tool, execute };
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Check if agent has LAVS
|
|
133
|
+
*/
|
|
134
|
+
async hasLAVS(agentDir) {
|
|
135
|
+
try {
|
|
136
|
+
const lavsPath = path_1.default.join(agentDir, 'lavs.json');
|
|
137
|
+
const loader = new loader_1.ManifestLoader();
|
|
138
|
+
await loader.load(lavsPath);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.LAVSToolGenerator = LAVSToolGenerator;
|
|
147
|
+
//# sourceMappingURL=tool-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-generator.js","sourceRoot":"","sources":["../src/tool-generator.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAGH,qCAA0C;AAC1C,uDAAmD;AACnD,2DAAuD;AACvD,2CAA4C;AAC5C,6DAAyD;AAEzD,gDAAwB;AA4BxB;;GAEG;AACH,MAAa,iBAAiB;IAC5B;;;;;;OAMG;IACH,KAAK,CAAC,aAAa,CACjB,OAAe,EACf,QAAgB,EAChB,WAAoB;QAEpB,IAAI,CAAC;YACH,gBAAgB;YAChB,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YAClD,MAAM,MAAM,GAAG,IAAI,uBAAc,EAAE,CAAC;YACpC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAE7C,kCAAkC;YAClC,MAAM,KAAK,GAAoB,EAAE,CAAC;YAElC,KAAK,MAAM,QAAQ,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;gBAC1C,uDAAuD;gBACvD,0CAA0C;gBAC1C,IAAI,QAAQ,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;oBACvC,SAAS;gBACX,CAAC;gBAED,MAAM,IAAI,GAAG,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,Q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,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAC7B,QAAQ,CAAC,OAAwB,EACjC,MAAM,EACN,OAAO,CACR,CAAC;oBACF,MAAM;gBACR,CAAC;gBACD,KAAK,UAAU,CAAC,CAAC,CAAC;oBAChB,MAAM,YAAY,GAAG,IAAI,oCAAgB,EAAE,CAAC;oBAC5C,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CACjC,QAAQ,CAAC,OAA0B,EACnC,MAAM,EACN,OAAO,CACR,CAAC;oBACF,MAAM;gBACR,CAAC;gBACD;oBACE,MAAM,IAAI,KAAK,CAAC,iBAAiB,QAAQ,CAAC,OAAO,CAAC,IAAI,2CAA2C,CAAC,CAAC;YACvG,CAAC;YAED,oCAAoC;YACpC,SAAS,CAAC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAE9C,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;QAEF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,QAAgB;QAC5B,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YAClD,MAAM,MAAM,GAAG,IAAI,uBAAc,EAAE,CAAC;YACpC,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AAtKD,8CAsKC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LAVS (Local Agent View Service) Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* This file defines the TypeScript types for LAVS manifests and related interfaces.
|
|
5
|
+
* See docs/LAVS-SPEC.md for full specification.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* LAVS Manifest - defines agent's data interface and view configuration
|
|
9
|
+
*/
|
|
10
|
+
export interface LAVSManifest {
|
|
11
|
+
lavs: string;
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
endpoints: Endpoint[];
|
|
16
|
+
view?: ViewConfig;
|
|
17
|
+
types?: TypeDefinitions;
|
|
18
|
+
permissions?: Permissions;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Endpoint - a callable operation exposed by the service
|
|
22
|
+
*/
|
|
23
|
+
export interface Endpoint {
|
|
24
|
+
id: string;
|
|
25
|
+
method: 'query' | 'mutation' | 'subscription';
|
|
26
|
+
description?: string;
|
|
27
|
+
handler: Handler;
|
|
28
|
+
schema?: Schema;
|
|
29
|
+
permissions?: Permissions;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Handler - defines how to execute an endpoint
|
|
33
|
+
*/
|
|
34
|
+
export type Handler = ScriptHandler | FunctionHandler | HTTPHandler | MCPHandler;
|
|
35
|
+
/**
|
|
36
|
+
* Script Handler - executes a script/command
|
|
37
|
+
*/
|
|
38
|
+
export interface ScriptHandler {
|
|
39
|
+
type: 'script';
|
|
40
|
+
command: string;
|
|
41
|
+
args?: string[];
|
|
42
|
+
input?: 'args' | 'stdin' | 'env';
|
|
43
|
+
cwd?: string;
|
|
44
|
+
timeout?: number;
|
|
45
|
+
env?: Record<string, string>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Function Handler - calls a JavaScript/TypeScript function
|
|
49
|
+
*/
|
|
50
|
+
export interface FunctionHandler {
|
|
51
|
+
type: 'function';
|
|
52
|
+
module: string;
|
|
53
|
+
function: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* HTTP Handler - proxies to HTTP endpoint
|
|
57
|
+
*/
|
|
58
|
+
export interface HTTPHandler {
|
|
59
|
+
type: 'http';
|
|
60
|
+
url: string;
|
|
61
|
+
method: string;
|
|
62
|
+
headers?: Record<string, string>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* MCP Handler - bridges to MCP server tool
|
|
66
|
+
*/
|
|
67
|
+
export interface MCPHandler {
|
|
68
|
+
type: 'mcp';
|
|
69
|
+
server: string;
|
|
70
|
+
tool: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Schema - JSON Schema for input/output validation
|
|
74
|
+
*/
|
|
75
|
+
export interface Schema {
|
|
76
|
+
input?: JSONSchema;
|
|
77
|
+
output?: JSONSchema;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* JSON Schema type (simplified)
|
|
81
|
+
*/
|
|
82
|
+
export type JSONSchema = Record<string, any>;
|
|
83
|
+
/**
|
|
84
|
+
* Type Definitions - reusable type schemas
|
|
85
|
+
*/
|
|
86
|
+
export type TypeDefinitions = Record<string, JSONSchema>;
|
|
87
|
+
/**
|
|
88
|
+
* View Configuration - UI component definition
|
|
89
|
+
*/
|
|
90
|
+
export interface ViewConfig {
|
|
91
|
+
component: ComponentSource;
|
|
92
|
+
fallback?: 'list' | 'table' | 'json';
|
|
93
|
+
icon?: string;
|
|
94
|
+
theme?: Record<string, string>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Component Source - how to load the view component
|
|
98
|
+
*/
|
|
99
|
+
export type ComponentSource = {
|
|
100
|
+
type: 'cdn';
|
|
101
|
+
url: string;
|
|
102
|
+
exportName?: string;
|
|
103
|
+
} | {
|
|
104
|
+
type: 'npm';
|
|
105
|
+
package: string;
|
|
106
|
+
version?: string;
|
|
107
|
+
} | {
|
|
108
|
+
type: 'local';
|
|
109
|
+
path: string;
|
|
110
|
+
} | {
|
|
111
|
+
type: 'inline';
|
|
112
|
+
code: string;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Permissions - security constraints
|
|
116
|
+
*
|
|
117
|
+
* Enforcement levels:
|
|
118
|
+
* - ENFORCED: Runtime actively prevents violations
|
|
119
|
+
* - ADVISORY: Declared for documentation/auditing, not enforced at OS level
|
|
120
|
+
*
|
|
121
|
+
* | Permission | Enforcement | Notes |
|
|
122
|
+
* |-----------------|-------------|------------------------------------------------|
|
|
123
|
+
* | fileAccess | ADVISORY | Glob patterns for allowed paths; checked at |
|
|
124
|
+
* | | | handler dispatch (path traversal) but not at |
|
|
125
|
+
* | | | OS/syscall level during script execution |
|
|
126
|
+
* | networkAccess | ADVISORY | Declared intent; not enforced (no network |
|
|
127
|
+
* | | | namespacing). Use OS-level isolation for strict |
|
|
128
|
+
* | | | enforcement (e.g., nsjail, Docker) |
|
|
129
|
+
* | maxExecutionTime| ENFORCED | Script killed via SIGTERM/SIGKILL on timeout |
|
|
130
|
+
* | maxMemory | ADVISORY | Not enforced in current runtime; future: use |
|
|
131
|
+
* | | | Node.js child_process resource limits |
|
|
132
|
+
*/
|
|
133
|
+
export interface Permissions {
|
|
134
|
+
fileAccess?: string[];
|
|
135
|
+
networkAccess?: boolean | string[];
|
|
136
|
+
maxExecutionTime?: number;
|
|
137
|
+
maxMemory?: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Execution Context - runtime context for handler execution
|
|
141
|
+
*/
|
|
142
|
+
export interface ExecutionContext {
|
|
143
|
+
endpointId: string;
|
|
144
|
+
agentId: string;
|
|
145
|
+
workdir: string;
|
|
146
|
+
permissions: Permissions;
|
|
147
|
+
timeout?: number;
|
|
148
|
+
env?: Record<string, string>;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* LAVS Error - standard error format
|
|
152
|
+
*/
|
|
153
|
+
export declare class LAVSError extends Error {
|
|
154
|
+
code: number;
|
|
155
|
+
data?: Record<string, unknown> | undefined;
|
|
156
|
+
constructor(code: number, message: string, data?: Record<string, unknown> | undefined);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* LAVS Error Codes (JSON-RPC 2.0 compatible)
|
|
160
|
+
*/
|
|
161
|
+
export declare enum LAVSErrorCode {
|
|
162
|
+
ParseError = -32700,
|
|
163
|
+
InvalidRequest = -32600,
|
|
164
|
+
MethodNotFound = -32601,
|
|
165
|
+
InvalidParams = -32602,
|
|
166
|
+
InternalError = -32603,
|
|
167
|
+
PermissionDenied = -32001,
|
|
168
|
+
Timeout = -32002,
|
|
169
|
+
HandlerError = -32003
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,GAAG,UAAU,GAAG,cAAc,CAAC;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,aAAa,GAAG,eAAe,GAAG,WAAW,GAAG,UAAU,CAAC;AAEjF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO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