web-agent-bridge 2.4.0 → 2.6.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/sdk/index.js CHANGED
@@ -371,4 +371,249 @@ class WABUniversalAgent {
371
371
  const { WABMultiAgent } = require('./multi-agent');
372
372
  const { WABAgentMesh } = require('./agent-mesh');
373
373
 
374
- module.exports = { WABAgent, WABUniversalAgent, WABMultiAgent, WABAgentMesh };
374
+ // ─── WAB Agent OS Client ────────────────────────────────────────────────────
375
+
376
+ /**
377
+ * WABAgentOS — Client for the Agent OS runtime.
378
+ * Provides access to protocol, tasks, execution, registry, observability, and LLM.
379
+ */
380
+ class WABAgentOS {
381
+ /**
382
+ * @param {object} options
383
+ * @param {string} options.serverUrl — WAB server base URL
384
+ * @param {string} [options.agentId] — Pre-registered agent ID
385
+ * @param {string} [options.apiKey] — Pre-registered API key
386
+ * @param {string} [options.sessionToken] — Active session token
387
+ */
388
+ constructor(options = {}) {
389
+ this.serverUrl = (options.serverUrl || 'http://localhost:3000').replace(/\/$/, '');
390
+ this.agentId = options.agentId || null;
391
+ this.apiKey = options.apiKey || null;
392
+ this.sessionToken = options.sessionToken || null;
393
+ this._base = `${this.serverUrl}/api/os`;
394
+ }
395
+
396
+ // ─── Agent Identity ───────────────────────────────────────────────────
397
+
398
+ async register(name, type, capabilities = []) {
399
+ const res = await this._post('/agents/register', { name, type, capabilities });
400
+ this.agentId = res.agentId;
401
+ this.apiKey = res.apiKey;
402
+ return res;
403
+ }
404
+
405
+ async authenticate(apiKey) {
406
+ const res = await this._post('/agents/authenticate', { apiKey: apiKey || this.apiKey });
407
+ if (res.sessionToken) this.sessionToken = res.sessionToken;
408
+ return res;
409
+ }
410
+
411
+ async negotiateCapabilities(capabilities, siteId) {
412
+ return this._post(`/agents/${this.agentId}/capabilities`, { capabilities, siteId });
413
+ }
414
+
415
+ // ─── Protocol ─────────────────────────────────────────────────────────
416
+
417
+ async getProtocol() {
418
+ return this._get('/protocol');
419
+ }
420
+
421
+ async sendMessage(command, payload = {}) {
422
+ return this._post('/protocol/message', { command, payload, agentId: this.agentId });
423
+ }
424
+
425
+ // ─── Tasks ────────────────────────────────────────────────────────────
426
+
427
+ async submitTask(task) {
428
+ return this._post('/tasks', task);
429
+ }
430
+
431
+ async getTask(taskId) {
432
+ return this._get(`/tasks/${taskId}`);
433
+ }
434
+
435
+ async listTasks(state, limit) {
436
+ const params = [];
437
+ if (state) params.push(`state=${state}`);
438
+ if (limit) params.push(`limit=${limit}`);
439
+ return this._get(`/tasks${params.length ? '?' + params.join('&') : ''}`);
440
+ }
441
+
442
+ async cancelTask(taskId) {
443
+ return this._delete(`/tasks/${taskId}`);
444
+ }
445
+
446
+ async pauseTask(taskId) {
447
+ return this._post(`/tasks/${taskId}/pause`);
448
+ }
449
+
450
+ async resumeTask(taskId) {
451
+ return this._post(`/tasks/${taskId}/resume`);
452
+ }
453
+
454
+ // ─── Execution ────────────────────────────────────────────────────────
455
+
456
+ async execute(command) {
457
+ return this._post('/execute', command);
458
+ }
459
+
460
+ async executeSemantic(domain, action, params = {}) {
461
+ return this._post('/execute/semantic', { domain, action, params, agentId: this.agentId });
462
+ }
463
+
464
+ async executePipeline(steps) {
465
+ return this._post('/execute/pipeline', { steps });
466
+ }
467
+
468
+ async resolveAction(domain, action, siteDomain) {
469
+ const params = `domain=${domain}&action=${action}${siteDomain ? `&siteDomain=${siteDomain}` : ''}`;
470
+ return this._get(`/execute/resolve?${params}`);
471
+ }
472
+
473
+ // ─── Registry ─────────────────────────────────────────────────────────
474
+
475
+ async searchCommands(query = {}) {
476
+ const params = Object.entries(query).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join('&');
477
+ return this._get(`/registry/commands${params ? '?' + params : ''}`);
478
+ }
479
+
480
+ async registerCommand(siteId, command) {
481
+ return this._post('/registry/commands', { siteId, ...command });
482
+ }
483
+
484
+ async searchSites(query = {}) {
485
+ const params = Object.entries(query).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join('&');
486
+ return this._get(`/registry/sites${params ? '?' + params : ''}`);
487
+ }
488
+
489
+ async registerSite(domain, info) {
490
+ return this._post('/registry/sites', { domain, ...info });
491
+ }
492
+
493
+ async searchTemplates(query = {}) {
494
+ const params = Object.entries(query).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join('&');
495
+ return this._get(`/registry/templates${params ? '?' + params : ''}`);
496
+ }
497
+
498
+ async getTemplate(templateId) {
499
+ return this._get(`/registry/templates/${templateId}`);
500
+ }
501
+
502
+ // ─── LLM ──────────────────────────────────────────────────────────────
503
+
504
+ async complete(prompt, options = {}) {
505
+ return this._post('/llm/complete', { prompt, options });
506
+ }
507
+
508
+ async embed(text, options = {}) {
509
+ return this._post('/llm/embed', { text, options });
510
+ }
511
+
512
+ async listModels() {
513
+ return this._get('/llm/models');
514
+ }
515
+
516
+ // ─── Observability ────────────────────────────────────────────────────
517
+
518
+ async getMetrics() {
519
+ return this._get('/observability/metrics');
520
+ }
521
+
522
+ async getTraces(query = {}) {
523
+ const params = Object.entries(query).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join('&');
524
+ return this._get(`/observability/traces${params ? '?' + params : ''}`);
525
+ }
526
+
527
+ async getTrace(traceId) {
528
+ return this._get(`/observability/traces/${traceId}`);
529
+ }
530
+
531
+ async getLogs(query = {}) {
532
+ const params = Object.entries(query).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join('&');
533
+ return this._get(`/observability/logs${params ? '?' + params : ''}`);
534
+ }
535
+
536
+ async getHealth() {
537
+ return this._get('/observability/health');
538
+ }
539
+
540
+ // ─── Events (SSE) ────────────────────────────────────────────────────
541
+
542
+ subscribe(filter, onEvent) {
543
+ if (typeof EventSource === 'undefined') {
544
+ throw new Error('EventSource not available. Use a polyfill for Node.js.');
545
+ }
546
+ const url = `${this._base}/events${filter ? '?filter=' + encodeURIComponent(filter) : ''}`;
547
+ const es = new EventSource(url);
548
+ es.onmessage = (e) => {
549
+ try { onEvent(JSON.parse(e.data)); } catch { onEvent(e.data); }
550
+ };
551
+ return es; // Call es.close() to unsubscribe
552
+ }
553
+
554
+ // ─── Policies ─────────────────────────────────────────────────────────
555
+
556
+ async createPolicy(policy) {
557
+ return this._post('/policies', policy);
558
+ }
559
+
560
+ async evaluatePolicy(entityId, action, context = {}) {
561
+ return this._post('/policies/evaluate', { entityId, action, context });
562
+ }
563
+
564
+ // ─── Deploy ───────────────────────────────────────────────────────────
565
+
566
+ async deploy(config = {}) {
567
+ return this._post('/deployments', { agentId: this.agentId, config });
568
+ }
569
+
570
+ async listDeployments(query = {}) {
571
+ const params = Object.entries(query).map(([k, v]) => `${k}=${encodeURIComponent(v)}`).join('&');
572
+ return this._get(`/deployments${params ? '?' + params : ''}`);
573
+ }
574
+
575
+ // ─── HTTP Helpers ─────────────────────────────────────────────────────
576
+
577
+ async _get(path) {
578
+ const url = `${this._base}${path}`;
579
+ const headers = this._headers();
580
+ const res = await fetch(url, { headers });
581
+ if (!res.ok) {
582
+ const body = await res.json().catch(() => ({ error: res.statusText }));
583
+ throw new Error(body.error || `HTTP ${res.status}`);
584
+ }
585
+ return res.json();
586
+ }
587
+
588
+ async _post(path, body) {
589
+ const url = `${this._base}${path}`;
590
+ const headers = { ...this._headers(), 'Content-Type': 'application/json' };
591
+ const res = await fetch(url, { method: 'POST', headers, body: JSON.stringify(body) });
592
+ if (!res.ok) {
593
+ const data = await res.json().catch(() => ({ error: res.statusText }));
594
+ throw new Error(data.error || `HTTP ${res.status}`);
595
+ }
596
+ return res.json();
597
+ }
598
+
599
+ async _delete(path) {
600
+ const url = `${this._base}${path}`;
601
+ const headers = this._headers();
602
+ const res = await fetch(url, { method: 'DELETE', headers });
603
+ if (!res.ok) {
604
+ const data = await res.json().catch(() => ({ error: res.statusText }));
605
+ throw new Error(data.error || `HTTP ${res.status}`);
606
+ }
607
+ return res.json();
608
+ }
609
+
610
+ _headers() {
611
+ const h = {};
612
+ if (this.sessionToken) h['Authorization'] = `Bearer ${this.sessionToken}`;
613
+ else if (this.apiKey) h['X-WAB-Key'] = this.apiKey;
614
+ if (this.agentId) h['X-WAB-Agent'] = this.agentId;
615
+ return h;
616
+ }
617
+ }
618
+
619
+ module.exports = { WABAgent, WABUniversalAgent, WABMultiAgent, WABAgentMesh, WABAgentOS };
package/sdk/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-agent-bridge-sdk",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "description": "SDK for building AI agents that interact with Web Agent Bridge (WAB)",
5
5
  "main": "index.js",
6
6
  "license": "MIT",