open-agentic-web 0.0.0-stage → 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.
@@ -0,0 +1,300 @@
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 actionTools = manifest.actions?.agentTools || [];
267
+ report.assert(
268
+ actionTools.length > 0,
269
+ `site-actions provides registered action tools (${actionTools.length} declared in manifest)`
270
+ );
271
+ }
272
+ } catch (err) {
273
+ report.assert(false, `site-actions.js can be inspected: ${err.message}`, { warning: true });
274
+ }
275
+ }
276
+
277
+ return report.toSummary();
278
+ }
279
+
280
+ /**
281
+ * Validates cross-site federation between a hub and peer nodes
282
+ */
283
+ export async function validateFederation(hubDir, peerDirs = []) {
284
+ const hubSummary = await validateNode(hubDir);
285
+ const peerSummaries = [];
286
+
287
+ for (const peerDir of peerDirs) {
288
+ peerSummaries.push(await validateNode(peerDir));
289
+ }
290
+
291
+ const allPassed = hubSummary.valid && peerSummaries.every(p => p.valid);
292
+ return {
293
+ valid: allPassed,
294
+ hub: hubSummary,
295
+ peers: peerSummaries,
296
+ totalChecks: hubSummary.total + peerSummaries.reduce((acc, p) => acc + p.total, 0),
297
+ totalPassed: hubSummary.passed + peerSummaries.reduce((acc, p) => acc + p.passed, 0),
298
+ totalFailed: hubSummary.failed + peerSummaries.reduce((acc, p) => acc + p.failed, 0)
299
+ };
300
+ }
@@ -0,0 +1,95 @@
1
+ import assert from "node:assert";
2
+ import { describe, it } from "node:test";
3
+ import { 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
+ });
@@ -0,0 +1,81 @@
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
+ });
@@ -0,0 +1,71 @@
1
+ import assert from "node:assert";
2
+ import { dirname, join } from "node:path";
3
+ import { describe, it } from "node:test";
4
+ import { fileURLToPath } from "node:url";
5
+ import { validateFederation, validateManifest, validateNetwork, validateNode } from "../src/validator.js";
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const repoRoot = join(__dirname, "..", "..", "..");
9
+
10
+ describe("Open Agentic Web - Conformance Validator", () => {
11
+ it("validates manifest schema correctly", () => {
12
+ const validManifest = {
13
+ name: "test_node",
14
+ networks: [
15
+ { name: "test_net", front_man: "test_agent", hocon: "./net.json" }
16
+ ],
17
+ llm_router: { base_url: "https://api.otari.ai/api/v1" },
18
+ actions: { agentTools: ["website_do_something"] }
19
+ };
20
+
21
+ const report = validateManifest(validManifest);
22
+ assert.strictEqual(report.valid, true);
23
+ assert.strictEqual(report.failed, 0);
24
+
25
+ const invalidManifest = {
26
+ name: "broken"
27
+ // missing networks, llm_router
28
+ };
29
+
30
+ const badReport = validateManifest(invalidManifest);
31
+ assert.strictEqual(badReport.valid, false);
32
+ assert.ok(badReport.failed > 0);
33
+ });
34
+
35
+ it("validates declarative network graph correctly", () => {
36
+ const validNet = {
37
+ tools: [
38
+ {
39
+ name: "agent_concierge",
40
+ instructions: "Grounded instructions for the concierge agent to act on behalf of the user.",
41
+ function: {
42
+ parameters: { type: "object", properties: { dest: { type: "string" } } }
43
+ }
44
+ }
45
+ ]
46
+ };
47
+
48
+ const report = validateNetwork(validNet, { frontMan: "agent_concierge" });
49
+ assert.strictEqual(report.valid, true);
50
+ });
51
+
52
+ it("validates live repository nodes (tripsteward-hub, cityglide-node, metropass-node)", async () => {
53
+ const hubDir = join(repoRoot, "sites", "tripsteward-hub");
54
+ const ridesDir = join(repoRoot, "sites", "cityglide-node");
55
+ const expDir = join(repoRoot, "sites", "metropass-node");
56
+
57
+ const hubSummary = await validateNode(hubDir);
58
+ assert.strictEqual(hubSummary.valid, true, `tripsteward-hub failed: ${JSON.stringify(hubSummary.results.filter(r => r.status === 'FAIL'))}`);
59
+
60
+ const ridesSummary = await validateNode(ridesDir);
61
+ assert.strictEqual(ridesSummary.valid, true, `cityglide-node failed: ${JSON.stringify(ridesSummary.results.filter(r => r.status === 'FAIL'))}`);
62
+
63
+ const expSummary = await validateNode(expDir);
64
+ assert.strictEqual(expSummary.valid, true, `metropass-node failed: ${JSON.stringify(expSummary.results.filter(r => r.status === 'FAIL'))}`);
65
+
66
+ // Test multi-node federation
67
+ const fed = await validateFederation(hubDir, [ridesDir, expDir]);
68
+ assert.strictEqual(fed.valid, true);
69
+ assert.ok(fed.totalChecks > 30);
70
+ });
71
+ });