web-agent-bridge 2.1.0 → 2.3.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.ar.md CHANGED
@@ -41,6 +41,14 @@
41
41
  - **لوحة السيادة** — مركز قيادة لحظي يعرض رادار العدالة، درع الخصوصية، سجل التفاوض، فحوصات التحقق، ومبدّل نماذج الذكاء الاصطناعي
42
42
  - **متجر قوالب الوكلاء** — ١١ قالب YAML جاهز (حجز فنادق، مقارنة بقالة، سوق حرفيين، صفقات طيران، إلخ) مع تشغيل من سطر الأوامر: `npx wab-agent run template.yaml`
43
43
  - **تبديل عقل الوكيل** — بدّل بين Llama 3، GPT-4، Claude، Gemini، Mistral، أو Ollama (محلي) بدون إعادة إعداد
44
+ - **تنسيق الوكيل عبر المواقع** — وكيل واحد يدير عدة مواقع WAB في نفس الوقت عبر `WABMultiAgent`. قارن الأسعار بين المتاجر، اجمع البيانات، نفّذ إجراءات متوازية، واعثر على أفضل صفقة تلقائياً
45
+
46
+ ### الإصدار 2.3 — شبكة الوكلاء الخاصة (العقل الموزّع)
47
+
48
+ - **بروتوكول التواصل بين الوكلاء** — الوكلاء يتواصلون عبر شبكة خاصة مع ٥ قنوات مدمجة (تنبيهات، اكتشافات، تكتيكات، مفاوضات، تصويت). مشاركة المعرفة في الوقت الفعلي مع تقييم الثقة ورسائل منتهية الصلاحية تلقائياً
49
+ - **التعلم المعزز المحلي** — الوكلاء يتعلمون من كل قرار للمستخدم باستخدام خوارزمية UCB1 متعددة الأذرع، تحديث السياسات بالنزول التدريجي، واستخراج أنماط السلوك. بدون أي مكالمات API خارجية — التعلم بالكامل محلي
50
+ - **منسق السيمفونية** — أربعة وكلاء متخصصين (باحث، محلل، مفاوض، حارس) يتعاونون ذاتياً عبر محركات قائمة على القواعد. ٥ قوالب، خط أنابيب من ٦ مراحل، حق نقض الحارس للقرارات الأمنية، إجماع مرجح. بدون أي اعتماد على نماذج LLM خارجية
51
+ - **لوحة شبكة الوكلاء** — عرض مباشر لشبكة الوكلاء: الوكلاء النشطون، قنوات الاتصال، قاعدة المعرفة المشتركة، تركيبات السيمفونية، ومقاييس أداء التعلم
44
52
 
45
53
  ---
46
54
 
package/README.md CHANGED
@@ -65,6 +65,14 @@ WAB is an open-source middleware layer that bridges AI agents and websites — l
65
65
  - **Sovereign Dashboard** — Real-time command center with fairness radar, privacy shield, negotiation logs, verification checks, and AI model switcher
66
66
  - **Community Agent Hub** — 11 pre-built YAML agent templates (hotel booking, grocery comparison, artisan marketplace, flight deals, etc.) with CLI runner: `npx wab-agent run template.yaml`
67
67
  - **AI Brain Swapping** — Switch between Llama 3, GPT-4, Claude, Gemini, Mistral, or Ollama (local) without reconfiguration
68
+ - **Cross-Site Agent Orchestration** — One agent manages multiple WAB-enabled sites simultaneously via `WABMultiAgent`. Compare prices across stores, aggregate data, run parallel actions, and find the best deal automatically
69
+
70
+ ### v2.3 — Private Agent Mesh (Distributed Mind)
71
+
72
+ - **Inter-Agent Protocol** — Agents communicate through a private mesh with 5 built-in channels (alerts, discoveries, tactics, negotiations, votes). Real-time knowledge sharing with confidence scoring and auto-expiring messages
73
+ - **Local Reinforcement Learning** — Agents learn from every user decision using UCB1 multi-armed bandit action selection, gradient-descent policy updates, and behavioral pattern mining. Zero external API calls — all learning is local
74
+ - **Symphony Orchestrator** — Four specialized agents (Researcher, Analyst, Negotiator, Guardian) collaborate autonomously through rule-based engines. 5 templates, 6-phase pipeline, Guardian veto for safety, weighted consensus. No external LLM dependency
75
+ - **Agent Mesh Dashboard** — Real-time visualization of your agent mesh: active agents, communication channels, shared knowledge base, symphony compositions, and learning performance metrics
68
76
 
69
77
  ---
70
78
 
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Example: Cross-Site Agent Orchestration
3
+ *
4
+ * One agent manages multiple WAB-enabled sites simultaneously.
5
+ * Compares prices, aggregates product data, and finds the best deal.
6
+ *
7
+ * Prerequisites:
8
+ * npm install puppeteer web-agent-bridge-sdk
9
+ *
10
+ * Usage:
11
+ * node examples/cross-site-agent.js site1.com site2.com site3.com
12
+ */
13
+
14
+ const { WABMultiAgent } = require('../sdk');
15
+
16
+ const sites = process.argv.slice(2);
17
+ if (sites.length < 2) {
18
+ console.log('Usage: node cross-site-agent.js <url1> <url2> [url3 ...]');
19
+ console.log('Example: node cross-site-agent.js https://shop1.com https://shop2.com');
20
+ process.exit(1);
21
+ }
22
+
23
+ // Ensure URLs have protocol
24
+ const urls = sites.map((s) => (s.startsWith('http') ? s : `https://${s}`));
25
+
26
+ async function main() {
27
+ console.log('\n🌐 WAB Cross-Site Agent Orchestration');
28
+ console.log(` Sites: ${urls.length}\n`);
29
+
30
+ // 1. Create multi-agent and connect to all sites
31
+ const multiAgent = new WABMultiAgent(urls, {
32
+ timeout: 20000,
33
+ headless: true
34
+ });
35
+
36
+ console.log('⏳ Launching browsers and connecting...');
37
+ const { connected, failed } = await multiAgent.launch();
38
+
39
+ for (const site of connected) console.log(` ✓ Connected: ${site}`);
40
+ for (const site of failed) console.log(` ✗ Failed: ${site}`);
41
+
42
+ if (connected.length === 0) {
43
+ console.log('\n✗ No sites connected. Exiting.');
44
+ await multiAgent.close();
45
+ return;
46
+ }
47
+
48
+ // 2. Discover all sites
49
+ console.log('\n📡 Discovering WAB capabilities...');
50
+ const discoveries = await multiAgent.discoverAll();
51
+ for (const d of discoveries) {
52
+ console.log(` ${d.site}: ${d.actions.length} actions`);
53
+ }
54
+
55
+ // 3. Compare prices for a product
56
+ console.log('\n💰 Comparing prices...');
57
+ const comparison = await multiAgent.comparePrices('product-sku');
58
+ for (const r of comparison.results) {
59
+ if (r.price != null) {
60
+ console.log(` ${r.site}: ${r.currency} ${r.price.toFixed(2)} — ${r.product}`);
61
+ } else {
62
+ console.log(` ${r.site}: ${r.error || 'No price data'}`);
63
+ }
64
+ }
65
+
66
+ if (comparison.cheapest) {
67
+ console.log(`\n🏆 Best deal: ${comparison.cheapest.site}`);
68
+ console.log(` Price: ${comparison.cheapest.currency} ${comparison.cheapest.price.toFixed(2)}`);
69
+ if (comparison.savings != null) {
70
+ console.log(` You save: ${comparison.cheapest.currency} ${comparison.savings.toFixed(2)}`);
71
+ }
72
+ }
73
+
74
+ // 4. Execute a common action across all sites
75
+ console.log('\n🔄 Executing getPageInfo on all sites...');
76
+ const infos = await multiAgent.executeAll('getPageInfo');
77
+ for (const info of infos) {
78
+ if (info.status === 'fulfilled' && info.value) {
79
+ console.log(` ${info.site}: "${info.value.title}" (v${info.value.bridgeVersion})`);
80
+ }
81
+ }
82
+
83
+ // 5. Cleanup
84
+ await multiAgent.close();
85
+ console.log('\n✓ All sessions closed. Done!\n');
86
+ }
87
+
88
+ main().catch((err) => {
89
+ console.error('Error:', err.message);
90
+ process.exit(1);
91
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-agent-bridge",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "Open-source middleware that bridges AI agents and websites — providing a standardized command interface for intelligent automation",
5
5
  "main": "server/index.js",
6
6
  "bin": {
package/public/index.html CHANGED
@@ -26,6 +26,7 @@
26
26
  <li><a href="#how-it-works">How It Works</a></li>
27
27
  <li><a href="#pricing">Pricing</a></li>
28
28
  <li><a href="#v2-features">v2.0</a></li>
29
+ <li><a href="#agent-mesh">Agent Mesh</a></li>
29
30
  <li><a href="/docs">Docs</a></li>
30
31
  </ul>
31
32
  <div class="navbar-actions">
@@ -212,7 +213,18 @@
212
213
  <li>Supports negotiation + verification</li>
213
214
  </ul>
214
215
  </div>
215
- <div class="card fade-in fade-in-delay-2" style="border-left: 3px solid #06b6d4;">
216
+ <div class="card fade-in fade-in-delay-2" style="border-left: 3px solid #0ea5e9;">
217
+ <div class="card-icon cyan">🌐</div>
218
+ <h3>Cross-Site Agent Orchestration</h3>
219
+ <p>One agent manages multiple WAB-enabled sites simultaneously. Compare prices across stores, aggregate product data, run parallel actions — all from a single <code>WABMultiAgent</code> instance in the SDK.</p>
220
+ <ul style="margin-top:12px;font-size:0.85rem;color:var(--text-secondary);list-style:disc;padding-left:20px;">
221
+ <li>Parallel multi-site browser sessions</li>
222
+ <li>comparePrices() with cheapest-deal finder</li>
223
+ <li>Schema.org + WAB action price extraction</li>
224
+ <li>Cross-site screenshots for vision verification</li>
225
+ </ul>
226
+ </div>
227
+ <div class="card fade-in" style="border-left: 3px solid #06b6d4;">
216
228
  <div class="card-icon cyan">🔄</div>
217
229
  <h3>AI Brain Swapping</h3>
218
230
  <p>WAB is the bridge — the AI model is your choice. Switch between Llama 3, GPT-4, Claude, Gemini, Mistral, or run fully local with Ollama. Your data, your model, your sovereignty.</p>
@@ -231,6 +243,57 @@
231
243
  </div>
232
244
  </section>
233
245
 
246
+ <!-- ═══════════ PRIVATE AGENT MESH ═══════════ -->
247
+ <section class="section" id="agent-mesh">
248
+ <div class="container">
249
+ <div class="section-header">
250
+ <span class="label" style="background: rgba(139,92,246,0.15); color: #8b5cf6;">v2.3 — Distributed Mind</span>
251
+ <h2>Private Agent Mesh</h2>
252
+ <p>Agents communicate, learn, and orchestrate autonomously — zero external LLM dependency. Your private fortress now has a distributed intelligence layer.</p>
253
+ </div>
254
+
255
+ <div class="grid-3">
256
+ <div class="card fade-in" style="border-left: 3px solid #8b5cf6;">
257
+ <div class="card-icon purple">🕸️</div>
258
+ <h3>Inter-Agent Protocol</h3>
259
+ <p>Agents communicate through a private mesh — sharing discoveries, broadcasting alerts, and exchanging tactics in real-time. 5 built-in channels: alerts, discoveries, tactics, negotiations, votes.</p>
260
+ <ul style="margin-top:12px;font-size:0.85rem;color:var(--text-secondary);list-style:disc;padding-left:20px;">
261
+ <li>Real-time agent-to-agent messaging</li>
262
+ <li>Shared knowledge base with confidence scoring</li>
263
+ <li>Priority-based message routing</li>
264
+ <li>Auto-expiring messages with TTL</li>
265
+ </ul>
266
+ </div>
267
+ <div class="card fade-in fade-in-delay-1" style="border-left: 3px solid #10b981;">
268
+ <div class="card-icon green">🧠</div>
269
+ <h3>Local Reinforcement Learning</h3>
270
+ <p>Agents learn from every user decision — accepted, rejected, or modified. Multi-armed bandit action selection, gradient-descent policy updates, and behavioral pattern mining. All local, zero tokens consumed.</p>
271
+ <ul style="margin-top:12px;font-size:0.85rem;color:var(--text-secondary);list-style:disc;padding-left:20px;">
272
+ <li>UCB1 multi-armed bandit for action selection</li>
273
+ <li>Sigmoid prediction with gradient descent</li>
274
+ <li>Behavioral sequence pattern mining</li>
275
+ <li>Bayesian confidence estimation</li>
276
+ </ul>
277
+ </div>
278
+ <div class="card fade-in fade-in-delay-2" style="border-left: 3px solid #f59e0b;">
279
+ <div class="card-icon orange">🎼</div>
280
+ <h3>Symphony Orchestrator</h3>
281
+ <p>Four specialized agents (Researcher, Analyst, Negotiator, Guardian) collaborate autonomously through rule-based engines. No external AI needed — the symphony runs entirely on local heuristics and learned preferences.</p>
282
+ <ul style="margin-top:12px;font-size:0.85rem;color:var(--text-secondary);list-style:disc;padding-left:20px;">
283
+ <li>5 templates: purchase, price comparison, negotiation, exploration, audit</li>
284
+ <li>6-phase pipeline: compose → discover → analyze → negotiate → guard → decide</li>
285
+ <li>Guardian veto for safety-critical decisions</li>
286
+ <li>Weighted consensus with agreement scoring</li>
287
+ </ul>
288
+ </div>
289
+ </div>
290
+
291
+ <div style="text-align:center; margin-top:32px;">
292
+ <a href="/mesh-dashboard" class="btn btn-primary btn-lg" style="background: #8b5cf6;">Open Agent Mesh Dashboard</a>
293
+ </div>
294
+ </div>
295
+ </section>
296
+
234
297
  <!-- ═══════════ HOW IT WORKS ═══════════ -->
235
298
  <section class="section" id="how-it-works" style="background: var(--bg-secondary);">
236
299
  <div class="container">
package/public/llms.txt CHANGED
@@ -30,6 +30,7 @@ AI agents today interact with websites through brittle DOM scraping, CSS selecto
30
30
  4. **Fairness Engine** — Prevents AI bias toward large platforms; ensures small businesses get equal visibility
31
31
  5. **MCP Compatibility** — `wab-mcp-adapter` converts WAB commands into MCP tools for any LLM
32
32
  6. **NoScript Fallback** — HTTP-only agents can interact via REST API when JavaScript is unavailable
33
+ 7. **Private Agent Mesh** — Inter-agent communication, local reinforcement learning, and symphony orchestration without external LLM dependency
33
34
 
34
35
  ## Use Cases
35
36
 
@@ -0,0 +1,401 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Agent Mesh — Web Agent Bridge</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com">
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
10
+ <link rel="stylesheet" href="/css/styles.css">
11
+ <style>
12
+ :root { --mesh-green: #10b981; --mesh-blue: #3b82f6; --mesh-purple: #8b5cf6; --mesh-orange: #f59e0b; --mesh-red: #ef4444; }
13
+
14
+ .mesh-layout { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }
15
+ .mesh-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 32px; flex-wrap: wrap; gap: 16px; }
16
+ .mesh-header h1 { font-size: 1.8rem; font-weight: 800; }
17
+ .mesh-header h1 span { color: var(--mesh-purple); }
18
+ .mesh-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; }
19
+
20
+ .mesh-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 32px; }
21
+ .stat-card { background: var(--bg-card); border: 1px solid var(--border-primary); border-radius: 12px; padding: 20px; text-align: center; }
22
+ .stat-card .stat-value { font-size: 2rem; font-weight: 800; color: var(--text-primary); }
23
+ .stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
24
+ .stat-card.green .stat-value { color: var(--mesh-green); }
25
+ .stat-card.blue .stat-value { color: var(--mesh-blue); }
26
+ .stat-card.purple .stat-value { color: var(--mesh-purple); }
27
+ .stat-card.orange .stat-value { color: var(--mesh-orange); }
28
+
29
+ .mesh-tabs { display: flex; gap: 4px; margin-bottom: 24px; background: var(--bg-card); border-radius: 10px; padding: 4px; border: 1px solid var(--border-primary); }
30
+ .mesh-tab { padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.85rem; color: var(--text-muted); border: none; background: transparent; transition: all 0.2s; }
31
+ .mesh-tab.active { background: var(--mesh-purple); color: white; }
32
+ .mesh-tab:hover:not(.active) { background: var(--bg-secondary); color: var(--text-primary); }
33
+
34
+ .tab-content { display: none; }
35
+ .tab-content.active { display: block; }
36
+
37
+ .section-title { font-size: 1.1rem; font-weight: 700; margin: 0 0 16px; }
38
+
39
+ .agents-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 24px; }
40
+ .agent-card { background: var(--bg-card); border: 1px solid var(--border-primary); border-radius: 12px; padding: 20px; position: relative; overflow: hidden; }
41
+ .agent-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
42
+ .agent-card.researcher::before { background: var(--mesh-blue); }
43
+ .agent-card.negotiator::before { background: var(--mesh-orange); }
44
+ .agent-card.analyst::before { background: var(--mesh-purple); }
45
+ .agent-card.guardian::before { background: var(--mesh-green); }
46
+ .agent-card .agent-role { font-weight: 700; font-size: 0.95rem; margin-bottom: 4px; text-transform: capitalize; }
47
+ .agent-card .agent-name { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 12px; }
48
+ .agent-card .agent-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
49
+ .agent-card .agent-stat { font-size: 0.75rem; color: var(--text-secondary); }
50
+ .agent-card .agent-stat strong { display: block; font-size: 1rem; color: var(--text-primary); }
51
+ .agent-status { display: inline-block; padding: 2px 8px; border-radius: 100px; font-size: 0.7rem; font-weight: 600; }
52
+ .agent-status.active { background: rgba(16,185,129,0.15); color: var(--mesh-green); }
53
+ .agent-status.idle { background: rgba(100,116,139,0.15); color: var(--text-muted); }
54
+
55
+ .channels-list { display: grid; gap: 12px; margin-bottom: 24px; }
56
+ .channel-card { background: var(--bg-card); border: 1px solid var(--border-primary); border-radius: 10px; padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; }
57
+ .channel-name { font-weight: 700; font-size: 0.95rem; }
58
+ .channel-desc { color: var(--text-muted); font-size: 0.8rem; margin-top: 2px; }
59
+ .channel-badge { background: var(--mesh-purple); color: white; padding: 4px 12px; border-radius: 100px; font-size: 0.75rem; font-weight: 600; }
60
+
61
+ .messages-list { max-height: 400px; overflow-y: auto; display: grid; gap: 8px; }
62
+ .message-item { background: var(--bg-card); border: 1px solid var(--border-primary); border-radius: 8px; padding: 12px 16px; }
63
+ .message-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
64
+ .message-type { font-size: 0.7rem; font-weight: 600; padding: 2px 8px; border-radius: 100px; }
65
+ .message-type.alert { background: rgba(239,68,68,0.15); color: var(--mesh-red); }
66
+ .message-type.discovery { background: rgba(59,130,246,0.15); color: var(--mesh-blue); }
67
+ .message-type.tactic { background: rgba(139,92,246,0.15); color: var(--mesh-purple); }
68
+ .message-type.request { background: rgba(245,158,11,0.15); color: var(--mesh-orange); }
69
+ .message-subject { font-weight: 600; font-size: 0.85rem; }
70
+ .message-sender { font-size: 0.75rem; color: var(--text-muted); }
71
+ .message-time { font-size: 0.7rem; color: var(--text-muted); }
72
+
73
+ .symphony-grid { display: grid; gap: 16px; margin-bottom: 24px; }
74
+ .symphony-card { background: var(--bg-card); border: 1px solid var(--border-primary); border-radius: 12px; padding: 20px; }
75
+ .symphony-name { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
76
+ .symphony-desc { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 12px; }
77
+ .symphony-phases { display: flex; gap: 8px; flex-wrap: wrap; }
78
+ .phase-tag { font-size: 0.7rem; padding: 3px 10px; border-radius: 100px; font-weight: 600; background: var(--bg-secondary); color: var(--text-secondary); }
79
+
80
+ .learning-chart { background: var(--bg-card); border: 1px solid var(--border-primary); border-radius: 12px; padding: 24px; margin-bottom: 24px; }
81
+ .learning-bars { display: flex; gap: 4px; align-items: flex-end; height: 120px; }
82
+ .learning-bar { flex: 1; background: var(--mesh-purple); border-radius: 4px 4px 0 0; min-width: 8px; transition: height 0.3s; opacity: 0.7; }
83
+ .learning-bar:hover { opacity: 1; }
84
+
85
+ .knowledge-table { width: 100%; border-collapse: collapse; }
86
+ .knowledge-table th { text-align: left; font-size: 0.75rem; color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border-primary); }
87
+ .knowledge-table td { padding: 10px 12px; font-size: 0.85rem; border-bottom: 1px solid var(--border-primary); }
88
+ .confidence-bar { height: 6px; border-radius: 3px; background: var(--bg-secondary); overflow: hidden; width: 80px; display: inline-block; }
89
+ .confidence-fill { height: 100%; border-radius: 3px; }
90
+
91
+ .demo-btn { background: var(--mesh-purple); color: white; border: none; padding: 10px 24px; border-radius: 8px; font-weight: 600; font-size: 0.85rem; cursor: pointer; }
92
+ .demo-btn:hover { opacity: 0.9; }
93
+ .demo-output { background: var(--bg-secondary); border-radius: 10px; padding: 16px; margin-top: 16px; font-family: 'JetBrains Mono', monospace; font-size: 0.8rem; max-height: 300px; overflow-y: auto; white-space: pre-wrap; }
94
+
95
+ @media (max-width: 768px) {
96
+ .mesh-stats { grid-template-columns: repeat(2, 1fr); }
97
+ .mesh-tabs { flex-wrap: wrap; }
98
+ }
99
+ </style>
100
+ </head>
101
+ <body>
102
+ <nav class="nav-header">
103
+ <div class="nav-inner">
104
+ <a href="/" class="nav-logo">WAB</a>
105
+ <div class="nav-links">
106
+ <a href="/dashboard">Dashboard</a>
107
+ <a href="/premium-dashboard">Sovereign</a>
108
+ <a href="/mesh-dashboard" class="nav-active">Agent Mesh</a>
109
+ <a href="/docs">Docs</a>
110
+ </div>
111
+ </div>
112
+ </nav>
113
+
114
+ <div class="mesh-layout">
115
+ <div class="mesh-header">
116
+ <div>
117
+ <h1>Agent <span>Mesh</span></h1>
118
+ <div class="mesh-subtitle">Private Agent Communication, Autonomous Learning, and Symphony Orchestration</div>
119
+ </div>
120
+ <button class="demo-btn" onclick="runDemo()">Run Symphony Demo</button>
121
+ </div>
122
+
123
+ <!-- Stats -->
124
+ <div class="mesh-stats">
125
+ <div class="stat-card green"><div class="stat-value" id="stat-agents">0</div><div class="stat-label">Active Agents</div></div>
126
+ <div class="stat-card blue"><div class="stat-value" id="stat-messages">0</div><div class="stat-label">Active Messages</div></div>
127
+ <div class="stat-card purple"><div class="stat-value" id="stat-knowledge">0</div><div class="stat-label">Knowledge Items</div></div>
128
+ <div class="stat-card orange"><div class="stat-value" id="stat-domains">0</div><div class="stat-label">Known Domains</div></div>
129
+ </div>
130
+
131
+ <!-- Tabs -->
132
+ <div class="mesh-tabs">
133
+ <button class="mesh-tab active" data-tab="agents">Agents</button>
134
+ <button class="mesh-tab" data-tab="channels">Channels</button>
135
+ <button class="mesh-tab" data-tab="knowledge">Knowledge</button>
136
+ <button class="mesh-tab" data-tab="symphony">Symphony</button>
137
+ <button class="mesh-tab" data-tab="learning">Learning</button>
138
+ </div>
139
+
140
+ <!-- Agents Tab -->
141
+ <div class="tab-content active" id="tab-agents">
142
+ <h3 class="section-title">Active Mesh Agents</h3>
143
+ <div class="agents-grid" id="agents-grid"></div>
144
+ </div>
145
+
146
+ <!-- Channels Tab -->
147
+ <div class="tab-content" id="tab-channels">
148
+ <h3 class="section-title">Communication Channels</h3>
149
+ <div class="channels-list" id="channels-list"></div>
150
+ <h3 class="section-title" style="margin-top: 24px">Recent Messages</h3>
151
+ <div class="messages-list" id="messages-list"></div>
152
+ </div>
153
+
154
+ <!-- Knowledge Tab -->
155
+ <div class="tab-content" id="tab-knowledge">
156
+ <h3 class="section-title">Shared Knowledge Base</h3>
157
+ <div style="background: var(--bg-card); border: 1px solid var(--border-primary); border-radius: 12px; overflow: hidden;">
158
+ <table class="knowledge-table" id="knowledge-table">
159
+ <thead>
160
+ <tr><th>Domain</th><th>Key</th><th>Type</th><th>Source</th><th>Confidence</th><th>Accessed</th></tr>
161
+ </thead>
162
+ <tbody id="knowledge-body"></tbody>
163
+ </table>
164
+ </div>
165
+ </div>
166
+
167
+ <!-- Symphony Tab -->
168
+ <div class="tab-content" id="tab-symphony">
169
+ <h3 class="section-title">Symphony Templates</h3>
170
+ <div class="symphony-grid" id="symphony-templates"></div>
171
+ <h3 class="section-title" style="margin-top: 24px">Recent Compositions</h3>
172
+ <div class="symphony-grid" id="symphony-history"></div>
173
+ </div>
174
+
175
+ <!-- Learning Tab -->
176
+ <div class="tab-content" id="tab-learning">
177
+ <h3 class="section-title">Learning Performance</h3>
178
+ <div class="mesh-stats" style="grid-template-columns: repeat(3, 1fr); margin-bottom: 24px;">
179
+ <div class="stat-card green"><div class="stat-value" id="learn-accuracy">0%</div><div class="stat-label">Prediction Accuracy</div></div>
180
+ <div class="stat-card blue"><div class="stat-value" id="learn-decisions">0</div><div class="stat-label">Total Decisions</div></div>
181
+ <div class="stat-card purple"><div class="stat-value" id="learn-patterns">0</div><div class="stat-label">Patterns Discovered</div></div>
182
+ </div>
183
+ <div class="learning-chart">
184
+ <h3 class="section-title">Reward History</h3>
185
+ <div class="learning-bars" id="learning-bars"></div>
186
+ </div>
187
+ </div>
188
+
189
+ <!-- Demo Output -->
190
+ <div id="demo-output" style="display: none;">
191
+ <h3 class="section-title">Demo Output</h3>
192
+ <div class="demo-output" id="demo-log"></div>
193
+ </div>
194
+ </div>
195
+
196
+ <script>
197
+ const API = '';
198
+
199
+ // Tab switching
200
+ document.querySelectorAll('.mesh-tab').forEach(function(tab) {
201
+ tab.addEventListener('click', function() {
202
+ document.querySelectorAll('.mesh-tab').forEach(function(t) { t.classList.remove('active'); });
203
+ document.querySelectorAll('.tab-content').forEach(function(c) { c.classList.remove('active'); });
204
+ tab.classList.add('active');
205
+ document.getElementById('tab-' + tab.dataset.tab).classList.add('active');
206
+ });
207
+ });
208
+
209
+ async function loadDashboard() {
210
+ try {
211
+ const res = await fetch(API + '/api/mesh/dashboard');
212
+ const data = await res.json();
213
+
214
+ // Stats
215
+ document.getElementById('stat-agents').textContent = data.mesh?.active_agents || 0;
216
+ document.getElementById('stat-messages').textContent = data.mesh?.active_messages || 0;
217
+ document.getElementById('stat-knowledge').textContent = data.mesh?.total_knowledge || 0;
218
+ document.getElementById('stat-domains').textContent = data.mesh?.known_domains || 0;
219
+
220
+ // Agents
221
+ const agentsGrid = document.getElementById('agents-grid');
222
+ if (data.agents && data.agents.length > 0) {
223
+ agentsGrid.innerHTML = data.agents.map(function(a) {
224
+ return '<div class="agent-card ' + a.agent_role + '">' +
225
+ '<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">' +
226
+ '<div class="agent-role">' + a.agent_role + '</div>' +
227
+ '<span class="agent-status ' + a.status + '">' + a.status + '</span></div>' +
228
+ '<div class="agent-name">' + (a.display_name || a.id.slice(0, 8)) + '</div>' +
229
+ '<div class="agent-stats">' +
230
+ '<div class="agent-stat"><strong>' + a.messages_sent + '</strong>Sent</div>' +
231
+ '<div class="agent-stat"><strong>' + a.messages_received + '</strong>Received</div>' +
232
+ '<div class="agent-stat"><strong>' + a.knowledge_count + '</strong>Knowledge</div>' +
233
+ '<div class="agent-stat"><strong>' + timeAgo(a.last_heartbeat) + '</strong>Last Seen</div></div></div>';
234
+ }).join('');
235
+ } else {
236
+ agentsGrid.innerHTML = '<div style="grid-column: 1/-1; text-align: center; padding: 40px; color: var(--text-muted);">No agents active. Run a demo or connect agents via SDK.</div>';
237
+ }
238
+
239
+ // Channels
240
+ var channelsList = document.getElementById('channels-list');
241
+ channelsList.innerHTML = data.channels.map(function(ch) {
242
+ return '<div class="channel-card"><div><div class="channel-name">#' + ch.name + '</div>' +
243
+ '<div class="channel-desc">' + (ch.description || '') + '</div></div>' +
244
+ '<span class="channel-badge">' + ch.channel_type + '</span></div>';
245
+ }).join('');
246
+
247
+ // Load messages for discoveries channel
248
+ loadMessages('discoveries');
249
+
250
+ // Symphony templates
251
+ var templatesGrid = document.getElementById('symphony-templates');
252
+ templatesGrid.innerHTML = data.symphonyTemplates.map(function(t) {
253
+ return '<div class="symphony-card"><div class="symphony-name">' + t.name.replace(/_/g, ' ') + '</div>' +
254
+ '<div class="symphony-desc">' + (t.description || '') + '</div>' +
255
+ '<div class="symphony-phases">' + t.phase_order.map(function(p) {
256
+ return '<span class="phase-tag">' + p + '</span>';
257
+ }).join('') + '</div></div>';
258
+ }).join('');
259
+
260
+ } catch (err) {
261
+ console.error('Failed to load dashboard:', err);
262
+ }
263
+ }
264
+
265
+ async function loadMessages(channel) {
266
+ try {
267
+ var res = await fetch(API + '/api/mesh/channels/' + channel + '/messages?limit=20');
268
+ var messages = await res.json();
269
+ var list = document.getElementById('messages-list');
270
+
271
+ if (messages.length > 0) {
272
+ list.innerHTML = messages.map(function(m) {
273
+ return '<div class="message-item"><div class="message-header">' +
274
+ '<div><span class="message-type ' + m.message_type + '">' + m.message_type + '</span> ' +
275
+ '<span class="message-subject">' + escapeHtml(m.subject) + '</span></div>' +
276
+ '<span class="message-time">' + timeAgo(m.created_at) + '</span></div>' +
277
+ '<div class="message-sender">From: ' + (m.sender_name || m.sender_role || m.sender_id?.slice(0, 8)) + '</div></div>';
278
+ }).join('');
279
+ } else {
280
+ list.innerHTML = '<div style="text-align: center; padding: 30px; color: var(--text-muted);">No messages yet</div>';
281
+ }
282
+ } catch (e) {
283
+ console.error('Failed to load messages:', e);
284
+ }
285
+ }
286
+
287
+ async function runDemo() {
288
+ var output = document.getElementById('demo-output');
289
+ var log = document.getElementById('demo-log');
290
+ output.style.display = 'block';
291
+ log.textContent = '';
292
+
293
+ function addLog(msg) { log.textContent += msg + '\n'; log.scrollTop = log.scrollHeight; }
294
+
295
+ addLog('=== Agent Mesh Symphony Demo ===\n');
296
+
297
+ try {
298
+ // 1. Register agents
299
+ addLog('[1/6] Registering agents in mesh...');
300
+ var researcher = await (await fetch(API + '/api/mesh/agents', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ siteId: 'demo', role: 'researcher', displayName: 'PriceBot', capabilities: ['scrape', 'compare'] }) })).json();
301
+ var analyst = await (await fetch(API + '/api/mesh/agents', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ siteId: 'demo', role: 'analyst', displayName: 'ValueBot', capabilities: ['score', 'rank'] }) })).json();
302
+ var negotiator = await (await fetch(API + '/api/mesh/agents', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ siteId: 'demo', role: 'negotiator', displayName: 'DealBot', capabilities: ['negotiate', 'bundle'] }) })).json();
303
+ var guardian = await (await fetch(API + '/api/mesh/agents', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ siteId: 'demo', role: 'guardian', displayName: 'TrustBot', capabilities: ['verify', 'audit'] }) })).json();
304
+ addLog(' Researcher: ' + researcher.id.slice(0, 8) + ' (PriceBot)');
305
+ addLog(' Analyst: ' + analyst.id.slice(0, 8) + ' (ValueBot)');
306
+ addLog(' Negotiator: ' + negotiator.id.slice(0, 8) + ' (DealBot)');
307
+ addLog(' Guardian: ' + guardian.id.slice(0, 8) + ' (TrustBot)');
308
+
309
+ // 2. Share knowledge
310
+ addLog('\n[2/6] Sharing knowledge to mesh...');
311
+ await (await fetch(API + '/api/mesh/knowledge', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ agentId: researcher.id, knowledgeType: 'price', domain: 'electronics', key: 'iphone-15-price', value: { price: 999, currency: 'USD', source: 'apple.com' }, confidence: 0.95 }) })).json();
312
+ addLog(' Shared: iPhone 15 price data (confidence: 0.95)');
313
+
314
+ await (await fetch(API + '/api/mesh/knowledge', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ agentId: researcher.id, knowledgeType: 'price', domain: 'electronics', key: 'competitor-price', value: { price: 949, currency: 'USD', source: 'bestbuy.com' }, confidence: 0.9 }) })).json();
315
+ addLog(' Shared: Competitor price data (confidence: 0.90)');
316
+
317
+ // 3. Broadcast alert
318
+ addLog('\n[3/6] Broadcasting alert...');
319
+ await (await fetch(API + '/api/mesh/alerts', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ senderId: guardian.id, subject: 'Price drop detected on competitor site', details: { domain: 'electronics', oldPrice: 999, newPrice: 949 }, priority: 2 }) })).json();
320
+ addLog(' Alert: Price drop detected on competitor site');
321
+
322
+ // 4. Run Symphony
323
+ addLog('\n[4/6] Running Symphony Orchestration...');
324
+ addLog(' Template: purchase_advisor');
325
+ addLog(' Phases: discover → analyze → negotiate → guard → decide');
326
+ var symphony = await (await fetch(API + '/api/mesh/symphony/perform', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({
327
+ siteId: 'demo',
328
+ task: 'Find the best deal on iPhone 15',
329
+ taskType: 'purchase',
330
+ inputData: {
331
+ siteData: { schema: { actions: { buy: { params: {} }, compare: { params: {} } } }, policies: { returns: '30 days', shipping: 'Free over $50' } },
332
+ products: [
333
+ { name: 'iPhone 15', price: 999, rating: 4.7, inStock: true, discount: 5 },
334
+ { name: 'iPhone 15 Pro', price: 1199, rating: 4.8, inStock: true },
335
+ { name: 'iPhone 14', price: 699, rating: 4.5, inStock: true, discount: 15 }
336
+ ],
337
+ preferences: { maxPrice: 1000, preferredCategory: 'electronics' }
338
+ }
339
+ }) })).json();
340
+
341
+ addLog('\n Symphony Results:');
342
+ addLog(' Status: ' + symphony.status);
343
+ addLog(' Confidence: ' + (symphony.confidence * 100).toFixed(1) + '%');
344
+ addLog(' Duration: ' + symphony.duration_ms + 'ms');
345
+
346
+ if (symphony.phases) {
347
+ Object.entries(symphony.phases).forEach(function(entry) {
348
+ var phase = entry[0], result = entry[1];
349
+ addLog('\n Phase: ' + phase);
350
+ if (result.output?.reasoning) addLog(' → ' + result.output.reasoning);
351
+ if (result.consensus?.reasoning) {
352
+ result.consensus.reasoning.forEach(function(r) { addLog(' → ' + r); });
353
+ }
354
+ });
355
+ }
356
+
357
+ // 5. Learning
358
+ addLog('\n[5/6] Training learning engine...');
359
+ var decision = await (await fetch(API + '/api/mesh/learning/decisions', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ siteId: 'demo', agentId: researcher.id, domain: 'electronics', action: 'buy_cheapest', context: { category: 'phones' }, features: { price: 699, discount: 15, rating: 4.5 } }) })).json();
360
+ addLog(' Decision recorded: ' + decision.decisionId?.slice(0, 8));
361
+ addLog(' Predicted reward: ' + (decision.predictedReward * 100).toFixed(1) + '%');
362
+
363
+ var fb = await (await fetch(API + '/api/mesh/learning/decisions/' + decision.decisionId + '/feedback', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ outcome: 'accepted', reward: 0.8 }) })).json();
364
+ addLog(' Feedback: accepted (reward: 0.8)');
365
+ addLog(' Updated confidence: ' + (fb.updatedConfidence * 100).toFixed(1) + '%');
366
+
367
+ // 6. Get recommendation
368
+ addLog('\n[6/6] Getting recommendation...');
369
+ var rec = await (await fetch(API + '/api/mesh/learning/recommend', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ siteId: 'demo', agentId: researcher.id, domain: 'electronics', actions: ['buy_cheapest', 'buy_best_rated', 'wait_for_sale'], context: { category: 'phones', price: 999 } }) })).json();
370
+ addLog(' Recommended: ' + rec.recommended);
371
+ addLog(' Confidence: ' + (rec.confidence * 100).toFixed(1) + '%');
372
+
373
+ addLog('\n=== Demo Complete ===');
374
+ addLog('All processing was LOCAL — zero external API calls, zero tokens consumed.');
375
+
376
+ } catch (err) {
377
+ addLog('\nError: ' + err.message);
378
+ }
379
+
380
+ loadDashboard();
381
+ }
382
+
383
+ function timeAgo(dateStr) {
384
+ if (!dateStr) return 'never';
385
+ var diff = Date.now() - new Date(dateStr).getTime();
386
+ if (diff < 60000) return 'just now';
387
+ if (diff < 3600000) return Math.floor(diff / 60000) + 'm ago';
388
+ if (diff < 86400000) return Math.floor(diff / 3600000) + 'h ago';
389
+ return Math.floor(diff / 86400000) + 'd ago';
390
+ }
391
+
392
+ function escapeHtml(str) {
393
+ var div = document.createElement('div');
394
+ div.textContent = str || '';
395
+ return div.innerHTML;
396
+ }
397
+
398
+ loadDashboard();
399
+ </script>
400
+ </body>
401
+ </html>