open-agentic-web 0.0.0-stage → 1.0.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 +17 -0
- package/README.md +286 -2
- package/bin/cli.mjs +351 -0
- package/package.json +48 -4
- package/src/actions.js +271 -0
- package/src/bridge.js +278 -0
- package/src/federation.js +340 -0
- package/src/index.js +10 -0
- package/src/validator.js +442 -0
- package/test/actions.test.mjs +140 -0
- package/test/federation.test.mjs +121 -0
- package/test/fixtures/hub-node/agent-manifest.json +20 -0
- package/test/fixtures/hub-node/bridge/action-bridge.html +1 -0
- package/test/fixtures/hub-node/hub.network.json +15 -0
- package/test/fixtures/hub-node/links.json +7 -0
- package/test/fixtures/hub-node/site-actions.js +22 -0
- package/test/fixtures/peer-node/agent-manifest.json +20 -0
- package/test/fixtures/peer-node/bridge/action-bridge.html +1 -0
- package/test/fixtures/peer-node/links.json +5 -0
- package/test/fixtures/peer-node/peer.network.json +15 -0
- package/test/fixtures/peer-node/site-actions.js +11 -0
- package/test/validator.test.mjs +93 -0
package/src/validator.js
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open Agentic Web — Conformance Validator
|
|
3
|
+
* Validates manifests, declarative networks, peer link mappings, and site actions
|
|
4
|
+
* against the Cognizant / Mozilla / MIT NANDA MVP Profile 0.3 specification.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
let nodeEnvPromise = null;
|
|
8
|
+
async function getNodeEnv() {
|
|
9
|
+
if (!nodeEnvPromise) {
|
|
10
|
+
nodeEnvPromise = (async () => {
|
|
11
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
12
|
+
try {
|
|
13
|
+
const [fs, path, url] = await Promise.all([
|
|
14
|
+
import("node:fs"),
|
|
15
|
+
import("node:path"),
|
|
16
|
+
import("node:url")
|
|
17
|
+
]);
|
|
18
|
+
return { fs, path, url };
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
})();
|
|
25
|
+
}
|
|
26
|
+
return nodeEnvPromise;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class ConformanceReport {
|
|
30
|
+
constructor(targetName) {
|
|
31
|
+
this.target = targetName;
|
|
32
|
+
this.passed = 0;
|
|
33
|
+
this.failed = 0;
|
|
34
|
+
this.warnings = 0;
|
|
35
|
+
this.results = [];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
assert(condition, message, { warning = false, details = null } = {}) {
|
|
39
|
+
if (condition) {
|
|
40
|
+
this.passed++;
|
|
41
|
+
this.results.push({ status: "PASS", message, details });
|
|
42
|
+
} else if (warning) {
|
|
43
|
+
this.warnings++;
|
|
44
|
+
this.results.push({ status: "WARN", message, details });
|
|
45
|
+
} else {
|
|
46
|
+
this.failed++;
|
|
47
|
+
this.results.push({ status: "FAIL", message, details });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toSummary() {
|
|
52
|
+
return {
|
|
53
|
+
target: this.target,
|
|
54
|
+
valid: this.failed === 0,
|
|
55
|
+
total: this.passed + this.failed + this.warnings,
|
|
56
|
+
passed: this.passed,
|
|
57
|
+
failed: this.failed,
|
|
58
|
+
warnings: this.warnings,
|
|
59
|
+
results: this.results
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Validates agent-manifest.json
|
|
66
|
+
*/
|
|
67
|
+
export function validateManifest(manifest, { basePath = "", report = new ConformanceReport("agent-manifest"), fileExistsFn = null } = {}) {
|
|
68
|
+
report.assert(typeof manifest === "object" && manifest !== null, "Manifest must be a valid JSON object");
|
|
69
|
+
if (!manifest || typeof manifest !== "object") return report.toSummary();
|
|
70
|
+
|
|
71
|
+
// Basic identification (supports 'name' or 'brand')
|
|
72
|
+
const name = manifest.name || manifest.brand || manifest.networks?.[0]?.name;
|
|
73
|
+
report.assert(typeof name === "string" && name.length > 0, `Manifest declares valid name or brand ('${name || 'missing'}')`);
|
|
74
|
+
|
|
75
|
+
// Networks check
|
|
76
|
+
const hasNetworks = Array.isArray(manifest.networks) && manifest.networks.length > 0;
|
|
77
|
+
report.assert(hasNetworks, "Manifest declares at least one network in 'networks' array");
|
|
78
|
+
|
|
79
|
+
if (hasNetworks) {
|
|
80
|
+
manifest.networks.forEach((net, i) => {
|
|
81
|
+
report.assert(typeof net.name === "string" && net.name.length > 0, `Network[${i}] has valid 'name' (${net.name || 'unnamed'})`);
|
|
82
|
+
report.assert(typeof net.front_man === "string" && net.front_man.length > 0, `Network[${i}] declares 'front_man' (${net.front_man || 'missing'})`);
|
|
83
|
+
report.assert(typeof net.hocon === "string" && net.hocon.length > 0, `Network[${i}] declares 'hocon' file path (${net.hocon || 'missing'})`);
|
|
84
|
+
|
|
85
|
+
if (basePath && typeof net.hocon === "string" && fileExistsFn) {
|
|
86
|
+
report.assert(fileExistsFn(net.hocon), `Referenced network file exists: ${net.hocon}`);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// LLM Router check
|
|
92
|
+
report.assert(
|
|
93
|
+
manifest.llm_router && typeof manifest.llm_router.base_url === "string",
|
|
94
|
+
"Manifest declares 'llm_router' with valid 'base_url'"
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// Actions check
|
|
98
|
+
if (manifest.actions) {
|
|
99
|
+
report.assert(
|
|
100
|
+
Array.isArray(manifest.actions.agentTools),
|
|
101
|
+
"Manifest 'actions.agentTools' is an array of registered tools"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Action Bridge check
|
|
106
|
+
if (basePath && fileExistsFn) {
|
|
107
|
+
report.assert(fileExistsFn("bridge/action-bridge.html"), "Node provides 'bridge/action-bridge.html' for cross-origin tool execution");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Peer policy
|
|
111
|
+
if (manifest.peer_policy) {
|
|
112
|
+
const validModes = ["open", "closed"];
|
|
113
|
+
report.assert(
|
|
114
|
+
validModes.includes(manifest.peer_policy.mode),
|
|
115
|
+
`Peer policy mode '${manifest.peer_policy.mode}' is valid ('open' or 'closed')`
|
|
116
|
+
);
|
|
117
|
+
if (manifest.peer_policy.mode === "closed") {
|
|
118
|
+
const allowedPeers = manifest.peer_policy.allowed_peers || manifest.allowed_peers;
|
|
119
|
+
report.assert(
|
|
120
|
+
Array.isArray(allowedPeers) && allowedPeers.length > 0,
|
|
121
|
+
"Closed peer policy must declare 'allowed_peers' (in peer_policy or root)"
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return report.toSummary();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Validates declarative *.network.json
|
|
131
|
+
*/
|
|
132
|
+
export function validateNetwork(network, { frontMan = null, report = new ConformanceReport("network") } = {}) {
|
|
133
|
+
report.assert(typeof network === "object" && network !== null, "Network must be a valid JSON object");
|
|
134
|
+
if (!network || typeof network !== "object") return report.toSummary();
|
|
135
|
+
|
|
136
|
+
// Tools array
|
|
137
|
+
const hasTools = Array.isArray(network.tools) && network.tools.length > 0;
|
|
138
|
+
report.assert(hasTools, "Network defines 'tools' array");
|
|
139
|
+
|
|
140
|
+
// Agents or front agent
|
|
141
|
+
const agents = network.agents || network.tools?.filter(t => t.type === "agent" || t.instructions);
|
|
142
|
+
report.assert(Array.isArray(agents) && agents.length > 0, "Network defines at least one agent with instructions");
|
|
143
|
+
|
|
144
|
+
if (frontMan && Array.isArray(network.tools)) {
|
|
145
|
+
const agent = network.tools.find(t => t.name === frontMan);
|
|
146
|
+
report.assert(agent !== undefined, `Network defines front agent '${frontMan}'`);
|
|
147
|
+
if (agent) {
|
|
148
|
+
report.assert(
|
|
149
|
+
typeof agent.instructions === "string" && agent.instructions.trim().length >= 30,
|
|
150
|
+
`Front agent '${frontMan}' has grounded instructions (>= 30 chars)`
|
|
151
|
+
);
|
|
152
|
+
const params = agent.function?.parameters || agent.parameters;
|
|
153
|
+
report.assert(
|
|
154
|
+
params && typeof params === "object",
|
|
155
|
+
`Front agent '${frontMan}' declares JSON schema input parameters`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return report.toSummary();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Validates links.json
|
|
165
|
+
*/
|
|
166
|
+
export function validateLinks(links, { report = new ConformanceReport("links") } = {}) {
|
|
167
|
+
report.assert(typeof links === "object" && links !== null, "links.json must be a valid JSON object");
|
|
168
|
+
if (!links || typeof links !== "object") return report.toSummary();
|
|
169
|
+
|
|
170
|
+
report.assert(
|
|
171
|
+
links.networks && typeof links.networks === "object",
|
|
172
|
+
"links.json configures 'networks' mapping"
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
if (links.networks) {
|
|
176
|
+
const networkNames = Object.keys(links.networks);
|
|
177
|
+
report.assert(networkNames.length > 0, `links.json maps ${networkNames.length} network(s) to peer endpoints`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return report.toSummary();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Validates a site directory for full conformance
|
|
185
|
+
*/
|
|
186
|
+
export async function validateNode(nodeDir) {
|
|
187
|
+
const env = await getNodeEnv();
|
|
188
|
+
if (!env) {
|
|
189
|
+
throw new Error("validateNode requires a Node.js runtime environment.");
|
|
190
|
+
}
|
|
191
|
+
const { fs, path, url: urlModule } = env;
|
|
192
|
+
|
|
193
|
+
const dirPath = path.resolve(nodeDir);
|
|
194
|
+
const report = new ConformanceReport(dirPath);
|
|
195
|
+
|
|
196
|
+
report.assert(fs.existsSync(dirPath), `Directory exists: ${dirPath}`);
|
|
197
|
+
if (!fs.existsSync(dirPath)) return report.toSummary();
|
|
198
|
+
|
|
199
|
+
const manifestPath = path.join(dirPath, "agent-manifest.json");
|
|
200
|
+
report.assert(fs.existsSync(manifestPath), `Contains 'agent-manifest.json'`);
|
|
201
|
+
|
|
202
|
+
if (!fs.existsSync(manifestPath)) return report.toSummary();
|
|
203
|
+
|
|
204
|
+
let manifest;
|
|
205
|
+
try {
|
|
206
|
+
manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
207
|
+
} catch (err) {
|
|
208
|
+
report.assert(false, `agent-manifest.json is valid JSON: ${err.message}`);
|
|
209
|
+
return report.toSummary();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const fileExistsFn = (relPath) => fs.existsSync(path.resolve(dirPath, relPath));
|
|
213
|
+
|
|
214
|
+
// Validate manifest
|
|
215
|
+
validateManifest(manifest, { basePath: dirPath, report, fileExistsFn });
|
|
216
|
+
|
|
217
|
+
// Validate referenced networks
|
|
218
|
+
if (Array.isArray(manifest.networks)) {
|
|
219
|
+
for (const net of manifest.networks) {
|
|
220
|
+
if (typeof net.hocon === "string") {
|
|
221
|
+
const netPath = path.resolve(dirPath, net.hocon);
|
|
222
|
+
if (fs.existsSync(netPath)) {
|
|
223
|
+
try {
|
|
224
|
+
const netJson = JSON.parse(fs.readFileSync(netPath, "utf-8"));
|
|
225
|
+
validateNetwork(netJson, { frontMan: net.front_man, report });
|
|
226
|
+
} catch (err) {
|
|
227
|
+
report.assert(false, `Network file '${net.hocon}' is valid JSON: ${err.message}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Validate links.json if present
|
|
235
|
+
const linksPath = path.join(dirPath, "links.json");
|
|
236
|
+
if (fs.existsSync(linksPath)) {
|
|
237
|
+
try {
|
|
238
|
+
const linksJson = JSON.parse(fs.readFileSync(linksPath, "utf-8"));
|
|
239
|
+
validateLinks(linksJson, { report });
|
|
240
|
+
} catch (err) {
|
|
241
|
+
report.assert(false, `links.json is valid JSON: ${err.message}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Validate site-actions.js if present
|
|
246
|
+
const actionsPath = path.join(dirPath, "site-actions.js");
|
|
247
|
+
if (fs.existsSync(actionsPath)) {
|
|
248
|
+
try {
|
|
249
|
+
const fileUrl = urlModule.pathToFileURL(actionsPath).href;
|
|
250
|
+
// Provide dummy DOM mock in Node environment if needed
|
|
251
|
+
if (!globalThis.window) {
|
|
252
|
+
globalThis.window = { location: { origin: "http://localhost:8080" } };
|
|
253
|
+
}
|
|
254
|
+
if (!globalThis.document) {
|
|
255
|
+
globalThis.document = { querySelector: () => null, querySelectorAll: () => [], addEventListener: () => {} };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const mod = await import(fileUrl);
|
|
259
|
+
const actionClass = mod.SiteActions || mod.default;
|
|
260
|
+
report.assert(
|
|
261
|
+
actionClass !== undefined,
|
|
262
|
+
"site-actions.js exports SiteActions class or default export"
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
if (actionClass) {
|
|
266
|
+
const registeredActions = new Map();
|
|
267
|
+
const mockRegistry = {
|
|
268
|
+
register: (def) => {
|
|
269
|
+
if (Array.isArray(def)) {
|
|
270
|
+
def.forEach(d => mockRegistry.register(d));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (def && def.name) {
|
|
274
|
+
registeredActions.set(def.name, def);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
let registrationOk = false;
|
|
280
|
+
try {
|
|
281
|
+
if (typeof actionClass.registerActions === "function") {
|
|
282
|
+
await actionClass.registerActions(mockRegistry);
|
|
283
|
+
registrationOk = true;
|
|
284
|
+
} else if (typeof actionClass === "function") {
|
|
285
|
+
const inst = new actionClass();
|
|
286
|
+
if (typeof inst.registerActions === "function") {
|
|
287
|
+
await inst.registerActions(mockRegistry);
|
|
288
|
+
registrationOk = true;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
} catch (err) {
|
|
292
|
+
report.assert(false, `SiteActions.registerActions execution failed: ${err.message}`, { warning: false });
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (registrationOk) {
|
|
296
|
+
report.assert(
|
|
297
|
+
registeredActions.size > 0,
|
|
298
|
+
`SiteActions.registerActions registered ${registeredActions.size} action tool(s)`
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
const manifestTools = manifest.actions?.agentTools || [];
|
|
302
|
+
for (const declaredTool of manifestTools) {
|
|
303
|
+
const baseName = declaredTool.replace(/^website_/, "");
|
|
304
|
+
const hasTool = registeredActions.has(declaredTool) ||
|
|
305
|
+
registeredActions.has(baseName) ||
|
|
306
|
+
registeredActions.has(`website_${baseName}`);
|
|
307
|
+
report.assert(
|
|
308
|
+
hasTool,
|
|
309
|
+
`Declared tool '${declaredTool}' is implemented and registered by site-actions.js`
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
if (hasTool) {
|
|
313
|
+
const act = registeredActions.get(declaredTool) ||
|
|
314
|
+
registeredActions.get(baseName) ||
|
|
315
|
+
registeredActions.get(`website_${baseName}`);
|
|
316
|
+
report.assert(
|
|
317
|
+
typeof act.execute === "function",
|
|
318
|
+
`Tool '${declaredTool}' provides an executable handler`
|
|
319
|
+
);
|
|
320
|
+
report.assert(
|
|
321
|
+
["read", "irreversible", "undoable"].includes(act.effect),
|
|
322
|
+
`Tool '${declaredTool}' declares valid effect ('${act.effect || 'missing'}')`
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
} catch (err) {
|
|
329
|
+
report.assert(false, `site-actions.js can be inspected: ${err.message}`, { warning: true });
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return report.toSummary();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Validates cross-site federation between a hub and peer nodes.
|
|
338
|
+
* Verifies links.json mapping, peer_policy permissions, and network/tool alignment.
|
|
339
|
+
*/
|
|
340
|
+
export async function validateFederation(hubDir, peerDirs = []) {
|
|
341
|
+
const env = await getNodeEnv();
|
|
342
|
+
const { fs, path } = env || {};
|
|
343
|
+
|
|
344
|
+
const report = new ConformanceReport("federation-mesh");
|
|
345
|
+
const hubSummary = await validateNode(hubDir);
|
|
346
|
+
const peerSummaries = [];
|
|
347
|
+
|
|
348
|
+
let hubManifest = null;
|
|
349
|
+
let hubLinks = null;
|
|
350
|
+
|
|
351
|
+
if (fs) {
|
|
352
|
+
try {
|
|
353
|
+
const hubManifestPath = path.join(path.resolve(hubDir), "agent-manifest.json");
|
|
354
|
+
if (fs.existsSync(hubManifestPath)) {
|
|
355
|
+
hubManifest = JSON.parse(fs.readFileSync(hubManifestPath, "utf-8"));
|
|
356
|
+
}
|
|
357
|
+
const hubLinksPath = path.join(path.resolve(hubDir), "links.json");
|
|
358
|
+
if (fs.existsSync(hubLinksPath)) {
|
|
359
|
+
hubLinks = JSON.parse(fs.readFileSync(hubLinksPath, "utf-8"));
|
|
360
|
+
}
|
|
361
|
+
} catch {}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
report.assert(hubLinks !== null, "Hub provides a readable 'links.json' for peer federation");
|
|
365
|
+
|
|
366
|
+
// Collect all mapped peer keys/URLs from hub's links.json
|
|
367
|
+
const mappedPeers = new Map();
|
|
368
|
+
if (hubLinks && hubLinks.networks) {
|
|
369
|
+
for (const [netName, peerMap] of Object.entries(hubLinks.networks)) {
|
|
370
|
+
if (typeof peerMap === "object" && peerMap !== null) {
|
|
371
|
+
for (const [peerAlias, endpoint] of Object.entries(peerMap)) {
|
|
372
|
+
mappedPeers.set(peerAlias.toLowerCase(), { networkName: netName, endpoint });
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
for (const peerDir of peerDirs) {
|
|
379
|
+
const peerSum = await validateNode(peerDir);
|
|
380
|
+
peerSummaries.push(peerSum);
|
|
381
|
+
|
|
382
|
+
if (fs) {
|
|
383
|
+
try {
|
|
384
|
+
const peerManifestPath = path.join(path.resolve(peerDir), "agent-manifest.json");
|
|
385
|
+
if (fs.existsSync(peerManifestPath)) {
|
|
386
|
+
const peerManifest = JSON.parse(fs.readFileSync(peerManifestPath, "utf-8"));
|
|
387
|
+
const peerNetName = peerManifest.networks?.[0]?.name || "";
|
|
388
|
+
const peerBrand = (peerManifest.brand || peerManifest.name || "").toLowerCase();
|
|
389
|
+
const peerDirBase = path.basename(peerDir).toLowerCase().replace(/-(node|site|app)$/, "");
|
|
390
|
+
|
|
391
|
+
// 1. Verify hub links.json maps this peer
|
|
392
|
+
const isMapped = mappedPeers.has(peerNetName.toLowerCase()) ||
|
|
393
|
+
mappedPeers.has(peerBrand) ||
|
|
394
|
+
mappedPeers.has(peerDirBase) ||
|
|
395
|
+
Array.from(mappedPeers.keys()).some(k => peerNetName.toLowerCase().includes(k) || peerDirBase.includes(k));
|
|
396
|
+
|
|
397
|
+
report.assert(
|
|
398
|
+
isMapped,
|
|
399
|
+
`Hub links.json maps peer network '${peerNetName || peerDirBase}' (${path.basename(peerDir)})`
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
// 2. Peer policy permissions check
|
|
403
|
+
if (peerManifest.peer_policy) {
|
|
404
|
+
if (peerManifest.peer_policy.mode === "closed") {
|
|
405
|
+
const allowedPeers = peerManifest.peer_policy.allowed_peers || peerManifest.allowed_peers || [];
|
|
406
|
+
report.assert(
|
|
407
|
+
allowedPeers.length > 0,
|
|
408
|
+
`Peer '${peerNetName || peerDirBase}' declares allowed_peers for closed federation`
|
|
409
|
+
);
|
|
410
|
+
} else {
|
|
411
|
+
report.assert(
|
|
412
|
+
peerManifest.peer_policy.mode === "open",
|
|
413
|
+
`Peer '${peerNetName || peerDirBase}' has open federation mode`
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// 3. Network alignment: peer front_man exists
|
|
419
|
+
const peerFrontMan = peerManifest.networks?.[0]?.front_man;
|
|
420
|
+
report.assert(
|
|
421
|
+
typeof peerFrontMan === "string" && peerFrontMan.length > 0,
|
|
422
|
+
`Peer '${peerNetName || peerDirBase}' declares active front_man '${peerFrontMan}'`
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
} catch (err) {
|
|
426
|
+
report.assert(false, `Error reading peer manifest in '${peerDir}': ${err.message}`);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const allPassed = hubSummary.valid && peerSummaries.every(p => p.valid) && report.failed === 0;
|
|
432
|
+
|
|
433
|
+
return {
|
|
434
|
+
valid: allPassed,
|
|
435
|
+
hub: hubSummary,
|
|
436
|
+
peers: peerSummaries,
|
|
437
|
+
meshReport: report.toSummary(),
|
|
438
|
+
totalChecks: hubSummary.total + peerSummaries.reduce((acc, p) => acc + p.total, 0) + report.passed + report.failed,
|
|
439
|
+
totalPassed: hubSummary.passed + peerSummaries.reduce((acc, p) => acc + p.passed, 0) + report.passed,
|
|
440
|
+
totalFailed: hubSummary.failed + peerSummaries.reduce((acc, p) => acc + p.failed, 0) + report.failed
|
|
441
|
+
};
|
|
442
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { ActionSecurityError, ActionValidationError, createActionRegistry, defineAction, validateSchema } from "../src/actions.js";
|
|
4
|
+
|
|
5
|
+
describe("Open Agentic Web - Site Actions & Validation", () => {
|
|
6
|
+
it("validates data correctly with validateSchema", () => {
|
|
7
|
+
const schema = {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
destination: { type: "string", minLength: 3 },
|
|
11
|
+
party_size: { type: "integer", minimum: 1 },
|
|
12
|
+
tier: { type: "string", enum: ["standard", "vip"] }
|
|
13
|
+
},
|
|
14
|
+
required: ["destination", "party_size"],
|
|
15
|
+
additionalProperties: false
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Valid data
|
|
19
|
+
const valid = validateSchema(schema, { destination: "San Francisco", party_size: 2, tier: "vip" });
|
|
20
|
+
assert.strictEqual(valid.valid, true);
|
|
21
|
+
assert.strictEqual(valid.errors.length, 0);
|
|
22
|
+
|
|
23
|
+
// Missing required
|
|
24
|
+
const missing = validateSchema(schema, { party_size: 2 });
|
|
25
|
+
assert.strictEqual(missing.valid, false);
|
|
26
|
+
assert.ok(missing.errors.some(e => e.includes("Missing required property 'destination'")));
|
|
27
|
+
|
|
28
|
+
// Invalid enum
|
|
29
|
+
const badEnum = validateSchema(schema, { destination: "SF", party_size: 2, tier: "gold" });
|
|
30
|
+
assert.strictEqual(badEnum.valid, false);
|
|
31
|
+
assert.ok(badEnum.errors.some(e => e.includes("is not one of: \"standard\", \"vip\"")));
|
|
32
|
+
|
|
33
|
+
// Additional property
|
|
34
|
+
const extra = validateSchema(schema, { destination: "SF", party_size: 2, unknown: 123 });
|
|
35
|
+
assert.strictEqual(extra.valid, false);
|
|
36
|
+
assert.ok(extra.errors.some(e => e.includes("Unexpected property 'unknown'")));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("defines and executes an action with automatic validation", async () => {
|
|
40
|
+
const action = defineAction({
|
|
41
|
+
name: "website_search_rooms",
|
|
42
|
+
description: "Search available rooms",
|
|
43
|
+
effect: "read",
|
|
44
|
+
inputSchema: {
|
|
45
|
+
type: "object",
|
|
46
|
+
properties: {
|
|
47
|
+
nights: { type: "integer", minimum: 1 }
|
|
48
|
+
},
|
|
49
|
+
required: ["nights"]
|
|
50
|
+
},
|
|
51
|
+
execute: async (args) => {
|
|
52
|
+
return { ok: true, rooms: [`Room for ${args.nights} nights`] };
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
assert.strictEqual(action.name, "website_search_rooms");
|
|
57
|
+
assert.strictEqual(action.effect, "read");
|
|
58
|
+
|
|
59
|
+
// Success call
|
|
60
|
+
const res = await action.execute({ nights: 3 });
|
|
61
|
+
assert.strictEqual(res.ok, true);
|
|
62
|
+
assert.strictEqual(res.rooms[0], "Room for 3 nights");
|
|
63
|
+
|
|
64
|
+
// Invalid call (throws ActionValidationError)
|
|
65
|
+
await assert.rejects(
|
|
66
|
+
async () => action.execute({ nights: -1 }),
|
|
67
|
+
ActionValidationError
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("manages actions via createActionRegistry", async () => {
|
|
72
|
+
const registry = createActionRegistry();
|
|
73
|
+
registry.register({
|
|
74
|
+
name: "website_book_ticket",
|
|
75
|
+
description: "Book event pass",
|
|
76
|
+
effect: "irreversible",
|
|
77
|
+
inputSchema: {
|
|
78
|
+
type: "object",
|
|
79
|
+
properties: { count: { type: "integer" } },
|
|
80
|
+
required: ["count"]
|
|
81
|
+
},
|
|
82
|
+
execute: async (args) => ({ booked: args.count })
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
assert.strictEqual(registry.has("website_book_ticket"), true);
|
|
86
|
+
assert.strictEqual(registry.has("unknown_tool"), false);
|
|
87
|
+
|
|
88
|
+
const catalog = registry.catalog();
|
|
89
|
+
assert.strictEqual(catalog.length, 1);
|
|
90
|
+
assert.strictEqual(catalog[0].name, "website_book_ticket");
|
|
91
|
+
|
|
92
|
+
const execResult = await registry.execute("website_book_ticket", { count: 4 });
|
|
93
|
+
assert.strictEqual(execResult.booked, 4);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("enforces human confirmation on irreversible actions", async () => {
|
|
97
|
+
let confirmCalled = false;
|
|
98
|
+
const action = defineAction({
|
|
99
|
+
name: "website_irreversible_transfer",
|
|
100
|
+
description: "Transfer money or commit booking",
|
|
101
|
+
effect: "irreversible",
|
|
102
|
+
inputSchema: {
|
|
103
|
+
type: "object",
|
|
104
|
+
properties: { amount: { type: "number" } },
|
|
105
|
+
required: ["amount"]
|
|
106
|
+
},
|
|
107
|
+
execute: async (args) => ({ transferred: args.amount })
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// 1. Rejected if requireConfirmation is set and not confirmed
|
|
111
|
+
await assert.rejects(
|
|
112
|
+
async () => action.execute({ amount: 100 }, { requireConfirmation: true, confirmed: false }),
|
|
113
|
+
ActionSecurityError
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
// 2. onConfirm callback approves
|
|
117
|
+
const approvedResult = await action.execute(
|
|
118
|
+
{ amount: 100 },
|
|
119
|
+
{
|
|
120
|
+
onConfirm: async ({ name, arguments: args }) => {
|
|
121
|
+
confirmCalled = true;
|
|
122
|
+
assert.strictEqual(name, "website_irreversible_transfer");
|
|
123
|
+
assert.strictEqual(args.amount, 100);
|
|
124
|
+
return true; // user confirms
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
assert.strictEqual(confirmCalled, true);
|
|
129
|
+
assert.strictEqual(approvedResult.transferred, 100);
|
|
130
|
+
|
|
131
|
+
// 3. onConfirm callback rejects
|
|
132
|
+
await assert.rejects(
|
|
133
|
+
async () => action.execute(
|
|
134
|
+
{ amount: 100 },
|
|
135
|
+
{ onConfirm: async () => false } // user declines
|
|
136
|
+
),
|
|
137
|
+
ActionSecurityError
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { AgentSwarm } from "../src/federation.js";
|
|
4
|
+
|
|
5
|
+
describe("Open Agentic Web - Dynamic Swarm & Federation", () => {
|
|
6
|
+
it("registers, searches, and unregisters nodes on the fly", () => {
|
|
7
|
+
const swarm = new AgentSwarm();
|
|
8
|
+
|
|
9
|
+
swarm.registerNode({
|
|
10
|
+
id: "dining_sommelier",
|
|
11
|
+
name: "TableBespoke Dining",
|
|
12
|
+
category: "Dining",
|
|
13
|
+
front_man: "sommelier",
|
|
14
|
+
tools: ["website_reserve_table", "website_check_menu"],
|
|
15
|
+
description: "Michelin table priority reservations"
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
swarm.registerNode({
|
|
19
|
+
id: "ski_passes",
|
|
20
|
+
name: "AlpineTrail Expeditions",
|
|
21
|
+
category: "Adventures",
|
|
22
|
+
front_man: "mountain_ranger",
|
|
23
|
+
tools: ["website_book_ski_pass"],
|
|
24
|
+
description: "Backcountry ski passes and guides"
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
assert.strictEqual(swarm.getNodes().length, 2);
|
|
28
|
+
|
|
29
|
+
// Search by category
|
|
30
|
+
const diningResults = swarm.search({ category: "Dining" });
|
|
31
|
+
assert.strictEqual(diningResults.length, 1);
|
|
32
|
+
assert.strictEqual(diningResults[0].id, "dining_sommelier");
|
|
33
|
+
|
|
34
|
+
// Search by query keyword
|
|
35
|
+
const skiResults = swarm.search({ query: "ski" });
|
|
36
|
+
assert.strictEqual(skiResults.length, 1);
|
|
37
|
+
assert.strictEqual(skiResults[0].id, "ski_passes");
|
|
38
|
+
|
|
39
|
+
// Export links format
|
|
40
|
+
const links = swarm.exportLinks("my_orchestrator");
|
|
41
|
+
assert.ok(links.networks.my_orchestrator.dining_sommelier !== undefined);
|
|
42
|
+
|
|
43
|
+
// Unregister
|
|
44
|
+
const removed = swarm.unregisterNode("dining_sommelier");
|
|
45
|
+
assert.strictEqual(removed, true);
|
|
46
|
+
assert.strictEqual(swarm.getNodes().length, 1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("mounts node with user consent hook", async () => {
|
|
50
|
+
const swarm = new AgentSwarm();
|
|
51
|
+
|
|
52
|
+
const mockManifest = {
|
|
53
|
+
name: "travel_shield",
|
|
54
|
+
description: "TravelShield Parametric Insurance",
|
|
55
|
+
category: "Insurance",
|
|
56
|
+
networks: [{ front_man: "insurance_agent" }],
|
|
57
|
+
actions: { agentTools: ["website_quote_policy"] }
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const mockFetch = async () => ({
|
|
61
|
+
ok: true,
|
|
62
|
+
json: async () => mockManifest
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
let consentPrompted = false;
|
|
66
|
+
const consentHook = async ({ candidate }) => {
|
|
67
|
+
consentPrompted = true;
|
|
68
|
+
assert.strictEqual(candidate.id, "travel_shield");
|
|
69
|
+
return true; // Approve
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const mounted = await swarm.mountFromUrl("https://example.com/shield", {
|
|
73
|
+
fetchFn: mockFetch,
|
|
74
|
+
onConsent: consentHook
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
assert.strictEqual(consentPrompted, true);
|
|
78
|
+
assert.strictEqual(mounted.id, "travel_shield");
|
|
79
|
+
assert.strictEqual(swarm.getNodes().length, 1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("formats tools and runs autonomous turn with tool execution", async () => {
|
|
83
|
+
const swarm = new AgentSwarm({
|
|
84
|
+
defaultRouter: "mock",
|
|
85
|
+
defaultModel: "alibaba/qwen3.8-flash"
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
swarm.registerNode({
|
|
89
|
+
id: "rides",
|
|
90
|
+
name: "CityGlide Rides",
|
|
91
|
+
category: "Mobility",
|
|
92
|
+
tools: [
|
|
93
|
+
{
|
|
94
|
+
name: "website_quote_ride",
|
|
95
|
+
description: "Get ride fare estimate",
|
|
96
|
+
inputSchema: { type: "object", properties: { destination: { type: "string" } } }
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const openaiTools = swarm.getOpenAITools();
|
|
102
|
+
assert.strictEqual(openaiTools.length, 1);
|
|
103
|
+
assert.strictEqual(openaiTools[0].function.name, "website_quote_ride");
|
|
104
|
+
|
|
105
|
+
let actionExecuted = false;
|
|
106
|
+
const turnResult = await swarm.runTurn({
|
|
107
|
+
prompt: "Please book a ride to the hotel",
|
|
108
|
+
apiKey: "mock",
|
|
109
|
+
actionExecutor: async (tool, args) => {
|
|
110
|
+
actionExecuted = true;
|
|
111
|
+
assert.strictEqual(tool, "website_quote_ride");
|
|
112
|
+
return { fare_usd: 45, status: "DISPATCHED" };
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
assert.strictEqual(turnResult.ok, true);
|
|
117
|
+
assert.strictEqual(actionExecuted, true);
|
|
118
|
+
assert.strictEqual(turnResult.toolCallsCount, 1);
|
|
119
|
+
assert.ok(turnResult.text.includes("website_quote_ride"));
|
|
120
|
+
});
|
|
121
|
+
});
|