web-agent-bridge 2.4.0 → 2.5.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 +18 -0
- package/README.md +18 -0
- package/package.json +1 -1
- package/sdk/index.d.ts +170 -0
- package/sdk/index.js +246 -1
- package/sdk/package.json +1 -1
- package/server/control-plane/index.js +301 -0
- package/server/data-plane/index.js +354 -0
- package/server/index.js +2 -0
- package/server/llm/index.js +404 -0
- package/server/observability/index.js +394 -0
- package/server/protocol/capabilities.js +223 -0
- package/server/protocol/index.js +243 -0
- package/server/protocol/schema.js +584 -0
- package/server/registry/index.js +326 -0
- package/server/routes/runtime.js +725 -0
- package/server/runtime/event-bus.js +210 -0
- package/server/runtime/index.js +233 -0
- package/server/runtime/sandbox.js +266 -0
- package/server/runtime/scheduler.js +395 -0
- package/server/runtime/state-manager.js +188 -0
- package/server/security/index.js +355 -0
package/README.ar.md
CHANGED
|
@@ -70,6 +70,24 @@
|
|
|
70
70
|
- **نظام الحوسبة الطرفية (Edge Compute)** — يحول كل جهاز مستخدم إلى عقدة AI سيادية. تحليل المعدات (CPU, RAM, GPU)، تشفير AES-256-GCM بين العقد، موازنة حمل مرجحة، مراقبة صحة بنبضات القلب مع تجاوز فشل تلقائي، وتشكيل أسراب حسب القدرات
|
|
71
71
|
- **محرك التنفيذ بالسرب** — إطلاق عدة وكلاء بالتوازي لحل مهمة واحدة. استراتيجيات قابلة للتكوين (متوازي، متسلسل، هجين)، دمج النتائج بأفضل درجة، تخصص بالأدوار، تجميع مرجح بالعدالة، وتقييم ثقة لكل وكيل
|
|
72
72
|
|
|
73
|
+
### الإصدار 3.0 — نظام تشغيل الوكلاء (طبقة التنفيذ للويب)
|
|
74
|
+
|
|
75
|
+
الإصدار 3.0 يحوّل WAB من أداة أتمتة متقدمة إلى **نظام تشغيل حقيقي للوكلاء** — طبقة تنفيذ كاملة لوكلاء الذكاء الاصطناعي على الويب، منافس لـ MCP لكنه مصمم خصيصاً للتفاعل مع المتصفح.
|
|
76
|
+
|
|
77
|
+
- **بروتوكول WAB (WABP) v1.0.0** — بروتوكول رسمي مع سجل أوامر JSON Schema، رسائل مُنمطة، التحقق من المدخلات/المخرجات، وتعريفات أوامر مُنسّخة. ١٠ أوامر مدمجة (اكتشاف، تنفيذ، تنفيذ دلالي، تسجيل وكيل، إرسال مهمة، حالة مهمة، مقارنة تجارية، تفاوض تجاري، إرسال شبكة، استدلال AI). كل أمر يعلن عن القدرات المطلوبة ومستوى الخطر وصلاحيات الوصول
|
|
78
|
+
- **تفاوض القدرات** — منح قدرات ديناميكي بين الوكلاء والمواقع. موافقة تلقائية حسب مستوى الخطر (منخفض = موافقة تلقائية، عالي = يتطلب سياسة)، تحديد معدل لكل قدرة، منح قابلة للانتهاء مع تتبع الاستخدام، ودعم إبطال كامل
|
|
79
|
+
- **محرك تشغيل الوكلاء** — نظام تشغيل مهام بمستوى إنتاجي مع جدولة بقائمة أولويات، حل التبعيات، إعادة المحاولة بتراجع أسي، إيقاف/استئناف/إلغاء، حدود تزامن، وانتقالات حالة. ناقل أحداث غير متزامن مع وسيط، أحرف بدل مساحات الأسماء، ذاكرة إعادة (١٠ آلاف حدث)، وقائمة الرسائل الميتة
|
|
80
|
+
- **صندوق حماية التنفيذ** — عزل لكل مهمة مع حدود موارد (مهلة، ذاكرة قصوى، حد استدعاءات الشبكة، حد عمليات DOM)، قوائم نطاقات مسموحة، حظر محددات CSS، فحوصات قدرات وقت التنفيذ، وسجل تدقيق كامل لكل عملية
|
|
81
|
+
- **مدير الحالة** — حفظ حالة الوكيل بنقاط تفتيش مُسمّاة، تراجع لأي نقطة تفتيش، انتقالات حالة بالتحقق، عمليات دمج، وتنظيف بانتهاء الصلاحية
|
|
82
|
+
- **حزمة المراقبة** — مسجل JSON هيكلي مع مسجلات فرعية ومخارج قابلة للتوصيل، متتبع موزع بفترات أب-ابن (متوافق مع OpenTelemetry)، ومجمع مقاييس بعدادات ومقاييس ورسوم بيانية (مئينات p50/p90/p95/p99) وسلاسل زمنية للوحات التحكم
|
|
83
|
+
- **نموذج الأمان** — هوية الوكيل (تسجيل، مصادقة بمفتاح API مشفر، إدارة جلسات بمدة صلاحية، قوائم IP المسموحة، إبطال)، توقيع الأوامر (HMAC-SHA256 مع رمز فريد + طابع زمني، مقارنة آمنة زمنياً)، وعزل المواقع (تحكم وصول لكل موقع، وكلاء مسموحون/محظورون، حد تزامن أقصى، حظر محددات، تصنيف بيانات)
|
|
84
|
+
- **مستوى التحكم** — مدير الوكلاء لدورة حياة النشر (نشر، تعيين لمواقع، فحوصات صحة، إلغاء نشر) ومحرك السياسات بقواعد مُنمّطة، تقييم شروط (يساوي، يحتوي، نمط، حد أدنى، حد أقصى، ضمن)، ربط سياسات بأولوية، وتطبيق على مستوى الكيان
|
|
85
|
+
- **مستوى البيانات** — محلل الإجراءات الدلالية يربط صيغة `domain.action` (مثل `checkout.addItem`) بالتنفيذ الفعلي لكل موقع. المنفّذ يوجّه المهام عبر التتبع + المقاييس، يدعم أوضاع التنفيذ الدلالي/الخط الأنبوبي/المتوازي، مع ٨ إجراءات دلالية مدمجة للسلة والبحث والمصادقة والتنقل والمحتوى
|
|
86
|
+
- **تجريد LLM متعدد النماذج** — واجهة موحدة لـ OpenAI (محادثة + تضمينات)، Anthropic (API الرسائل)، وOllama (نماذج محلية مع اكتشاف تلقائي). مدير LLM يوفر سلسلة احتياطية تلقائية عبر جميع الموفرين، تخزين مؤقت للاستجابات (٥ دقائق)، تتبع التكاليف عبر عدد الرموز، وقائمة نماذج
|
|
87
|
+
- **السجل والنظام البيئي** — سجل الأوامر (كـ npm لأوامر WAB — تسجيل، اكتشاف، بحث حسب الفئة/الوسم/القدرة، تتبع الاستخدام)، سجل المواقع (دليل مواقع WAB مع التحقق، قائمة القدرات، تتبع الزيارات)، وسجل القوالب (قوالب سير عمل قابلة لإعادة الاستخدام مع عدد التنزيلات والتقييمات)
|
|
88
|
+
- **واجهة API الموحدة لنظام التشغيل** — جميع طبقات نظام التشغيل مكشوفة عبر نقاط REST على `/api/os/*`: اكتشاف البروتوكول، هوية/مصادقة الوكيل، CRUD المهام، التنفيذ الدلالي، النشر، السياسات، العزل، المراقبة (مقاييس/آثار/سجلات)، السجل (أوامر/مواقع/قوالب)، عمليات LLM، توقيع الأوامر، وأحداث Server-Sent Events للبث المباشر
|
|
89
|
+
- **عميل WABAgentOS في SDK** — فئة `WABAgentOS` جديدة في SDK مع كتابة TypeScript كاملة لجميع عمليات نظام التشغيل: تسجيل ← مصادقة ← تفاوض قدرات ← إرسال مهام ← تنفيذ دلالي ← استعلام المراقبة ← الاشتراك في الأحداث
|
|
90
|
+
|
|
73
91
|
---
|
|
74
92
|
|
|
75
93
|
## 🚀 البدء السريع
|
package/README.md
CHANGED
|
@@ -101,6 +101,24 @@ WAB is an open-source middleware layer that bridges AI agents and websites — l
|
|
|
101
101
|
- **Multilingual Agent** — The smart agent understands and responds in any language the user writes in — Arabic, English, French, Spanish, Turkish, and more. No restrictions on input style, dialect, or format
|
|
102
102
|
- **Dynamic Pricing Shield** — Detects price manipulation by websites that change prices based on device type, geolocation, cookies, browsing history, referral source, or repeat visits. The agent probes the same page with 12 distinct identity personas (clean desktop, mobile, Mac premium, EU/MENA/SEA geo, repeat visitor, Google/social/comparison referral, privacy-focused, bot-like) and uses statistical analysis (coefficient of variation, z-score outliers) to expose hidden pricing. Includes manipulation scoring (0–100), actionable tips, historical trend detection, and a strategy builder that recommends the best identity for the lowest price. Full API at `/api/sovereign/price-shield/`
|
|
103
103
|
|
|
104
|
+
### v3.0 — Agent OS (Execution Layer for the Web)
|
|
105
|
+
|
|
106
|
+
WAB v3.0 transforms the project from an advanced automation tool into a **real Agent Operating System** — a complete execution layer for AI agents on the web, comparable to MCP but purpose-built for browser interaction.
|
|
107
|
+
|
|
108
|
+
- **WAB Protocol (WABP) v1.0.0** — Formal protocol with JSON Schema command registry, typed messages, input/output validation, and versioned command definitions. 10 built-in commands (discover, execute, semantic.execute, agent.register, task.submit, task.status, commerce.compare, commerce.negotiate, mesh.send, ai.infer). Every command has declared capabilities, risk levels, and permission requirements
|
|
109
|
+
- **Capability Negotiation** — Dynamic capability grants between agents and sites. Risk-based auto-approval (low-risk auto-granted, high-risk requires policy), rate limiting per capability, expirable grants with usage tracking, and full revocation support
|
|
110
|
+
- **Agent Runtime Engine** — Production-grade task runtime with priority queue scheduler, dependency resolution, retry with exponential backoff, pause/resume/cancel, concurrency limits, and state machine transitions. EventBus with async middleware, namespace wildcards, replay buffer (10K events), and dead letter queue
|
|
111
|
+
- **Execution Sandbox** — Per-task isolation with resource limits (timeout, maxMemory, maxNetworkCalls, maxDomOperations), domain allowlists, blocked selector enforcement, capability checks at execution time, and full audit trail of every operation
|
|
112
|
+
- **State Manager** — Agent state persistence with labeled checkpoints, rollback to any checkpoint, state transitions with validation, merge operations, and TTL-based cleanup
|
|
113
|
+
- **Observability Stack** — Structured JSON logger with child loggers and pluggable sinks, distributed tracer with parent-child spans (OpenTelemetry-compatible), and metrics collector with counters, gauges, histograms (p50/p90/p95/p99 percentiles), and time series for dashboards
|
|
114
|
+
- **Security Model** — AgentIdentity (registration, hashed API key authentication, session management with TTL, IP allowlists, revocation), CommandSigner (HMAC-SHA256 signing/verification with nonce + timestamp, timing-safe comparison), and SiteIsolation (per-site access control, allowed/blocked agents, max concurrency, selector blocking, data classification)
|
|
115
|
+
- **Control Plane** — AgentManager for deployment lifecycle (deploy, assign to sites, health checks, undeploy) and PolicyEngine with typed rules, condition evaluation (equals, contains, pattern, min, max, in), priority-ordered policy binding, and entity-level policy enforcement
|
|
116
|
+
- **Data Plane** — SemanticActionResolver maps `domain.action` notation (e.g., `checkout.addItem`) to concrete implementations per site. Executor routes tasks through tracing + metrics, supports semantic/pipeline/parallel execution modes, with 8 built-in semantic actions for checkout, search, auth, navigation, and content
|
|
117
|
+
- **Multi-Model LLM Abstraction** — Unified interface for OpenAI (chat completions + embeddings), Anthropic (messages API), and Ollama (local models with auto-discovery). LLMManager provides automatic fallback chain through all providers, response caching (5min TTL), cost tracking via token counts, and model listing
|
|
118
|
+
- **Registry & Ecosystem** — CommandRegistry (like npm for WAB commands — register, discover, search by category/tag/capability, usage tracking), SiteRegistry (WAB-enabled sites directory with verification, capability listing, visit tracking), and TemplateRegistry (reusable workflow templates with download counts and ratings)
|
|
119
|
+
- **Unified Runtime API** — All Agent OS layers exposed via RESTful endpoints at `/api/os/*`: protocol discovery, agent identity/auth, task CRUD, semantic execution, deployments, policies, isolation, observability (metrics/traces/logs), registry (commands/sites/templates), LLM operations, command signing, and Server-Sent Events for real-time streaming
|
|
120
|
+
- **WABAgentOS SDK Client** — New `WABAgentOS` class in the SDK provides full TypeScript-typed API for all Agent OS operations: register → authenticate → negotiate capabilities → submit tasks → execute semantically → query observability → subscribe to events
|
|
121
|
+
|
|
104
122
|
> **Many more features** are available on the live website that aren't listed here — dashboards, analytics, admin tools, and more. Visit [webagentbridge.com](https://webagentbridge.com) to explore.
|
|
105
123
|
|
|
106
124
|
---
|
package/package.json
CHANGED
package/sdk/index.d.ts
CHANGED
|
@@ -292,3 +292,173 @@ export declare class WABUniversalAgent {
|
|
|
292
292
|
/** Get all known competing sources. */
|
|
293
293
|
sources(): Promise<any>;
|
|
294
294
|
}
|
|
295
|
+
|
|
296
|
+
// ─── WABAgentOS — Agent OS Runtime Client ──────────────────────────────
|
|
297
|
+
|
|
298
|
+
export interface WABAgentOSOptions {
|
|
299
|
+
/** WAB server base URL (default http://localhost:3000). */
|
|
300
|
+
serverUrl?: string;
|
|
301
|
+
/** Pre-registered agent ID. */
|
|
302
|
+
agentId?: string;
|
|
303
|
+
/** Pre-registered API key. */
|
|
304
|
+
apiKey?: string;
|
|
305
|
+
/** Active session token. */
|
|
306
|
+
sessionToken?: string;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export interface AgentRegistration {
|
|
310
|
+
agentId: string;
|
|
311
|
+
apiKey: string;
|
|
312
|
+
message: string;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export interface AgentSession {
|
|
316
|
+
sessionToken?: string;
|
|
317
|
+
agentId: string;
|
|
318
|
+
expiresAt: number;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface ProtocolInfo {
|
|
322
|
+
protocol: string;
|
|
323
|
+
version: string;
|
|
324
|
+
commands: Array<{
|
|
325
|
+
name: string;
|
|
326
|
+
version: string;
|
|
327
|
+
category: string;
|
|
328
|
+
description: string;
|
|
329
|
+
capabilities: string[];
|
|
330
|
+
}>;
|
|
331
|
+
capabilities: string[];
|
|
332
|
+
permissionLevels: Record<string, number>;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export interface TaskSubmitResult {
|
|
336
|
+
taskId: string;
|
|
337
|
+
state: string;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface TaskInfo {
|
|
341
|
+
taskId: string;
|
|
342
|
+
type: string;
|
|
343
|
+
state: string;
|
|
344
|
+
priority: number;
|
|
345
|
+
result?: any;
|
|
346
|
+
error?: string;
|
|
347
|
+
createdAt: number;
|
|
348
|
+
startedAt?: number;
|
|
349
|
+
completedAt?: number;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export interface ExecuteResult {
|
|
353
|
+
success: boolean;
|
|
354
|
+
result?: any;
|
|
355
|
+
error?: string;
|
|
356
|
+
traceId?: string;
|
|
357
|
+
duration?: number;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export interface RegistryCommand {
|
|
361
|
+
id: string;
|
|
362
|
+
siteId: string;
|
|
363
|
+
name: string;
|
|
364
|
+
description: string;
|
|
365
|
+
category: string;
|
|
366
|
+
version: string;
|
|
367
|
+
tags: string[];
|
|
368
|
+
usageCount: number;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export interface RegistrySite {
|
|
372
|
+
domain: string;
|
|
373
|
+
name: string;
|
|
374
|
+
tier: string;
|
|
375
|
+
capabilities: string[];
|
|
376
|
+
verified: boolean;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface RegistryTemplate {
|
|
380
|
+
id: string;
|
|
381
|
+
name: string;
|
|
382
|
+
description: string;
|
|
383
|
+
category: string;
|
|
384
|
+
steps: any[];
|
|
385
|
+
downloads: number;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export interface HealthInfo {
|
|
389
|
+
runtime: any;
|
|
390
|
+
identity: any;
|
|
391
|
+
registry: any;
|
|
392
|
+
executor: any;
|
|
393
|
+
llm: any;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export interface LLMCompletionResult {
|
|
397
|
+
text: string;
|
|
398
|
+
provider: string;
|
|
399
|
+
model: string;
|
|
400
|
+
tokens?: { input: number; output: number; total: number };
|
|
401
|
+
cached?: boolean;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export declare class WABAgentOS {
|
|
405
|
+
agentId: string | null;
|
|
406
|
+
apiKey: string | null;
|
|
407
|
+
sessionToken: string | null;
|
|
408
|
+
|
|
409
|
+
constructor(options?: WABAgentOSOptions);
|
|
410
|
+
|
|
411
|
+
// Agent Identity
|
|
412
|
+
register(name: string, type: string, capabilities?: string[]): Promise<AgentRegistration>;
|
|
413
|
+
authenticate(apiKey?: string): Promise<AgentSession>;
|
|
414
|
+
negotiateCapabilities(capabilities: string[], siteId?: string): Promise<any>;
|
|
415
|
+
|
|
416
|
+
// Protocol
|
|
417
|
+
getProtocol(): Promise<ProtocolInfo>;
|
|
418
|
+
sendMessage(command: string, payload?: Record<string, unknown>): Promise<any>;
|
|
419
|
+
|
|
420
|
+
// Tasks
|
|
421
|
+
submitTask(task: Record<string, unknown>): Promise<TaskSubmitResult>;
|
|
422
|
+
getTask(taskId: string): Promise<TaskInfo>;
|
|
423
|
+
listTasks(state?: string, limit?: number): Promise<{ tasks: TaskInfo[]; total: number }>;
|
|
424
|
+
cancelTask(taskId: string): Promise<{ success: boolean }>;
|
|
425
|
+
pauseTask(taskId: string): Promise<{ success: boolean }>;
|
|
426
|
+
resumeTask(taskId: string): Promise<{ success: boolean }>;
|
|
427
|
+
|
|
428
|
+
// Execution
|
|
429
|
+
execute(command: Record<string, unknown>): Promise<ExecuteResult>;
|
|
430
|
+
executeSemantic(domain: string, action: string, params?: Record<string, unknown>): Promise<ExecuteResult>;
|
|
431
|
+
executePipeline(steps: Array<Record<string, unknown>>): Promise<ExecuteResult>;
|
|
432
|
+
resolveAction(domain: string, action: string, siteDomain?: string): Promise<any>;
|
|
433
|
+
|
|
434
|
+
// Registry
|
|
435
|
+
searchCommands(query?: Record<string, string>): Promise<{ commands: RegistryCommand[]; total: number }>;
|
|
436
|
+
registerCommand(siteId: string, command: Record<string, unknown>): Promise<RegistryCommand>;
|
|
437
|
+
searchSites(query?: Record<string, string>): Promise<{ sites: RegistrySite[]; total: number }>;
|
|
438
|
+
registerSite(domain: string, info: Record<string, unknown>): Promise<RegistrySite>;
|
|
439
|
+
searchTemplates(query?: Record<string, string>): Promise<{ templates: RegistryTemplate[]; total: number }>;
|
|
440
|
+
getTemplate(templateId: string): Promise<RegistryTemplate>;
|
|
441
|
+
|
|
442
|
+
// LLM
|
|
443
|
+
complete(prompt: string, options?: Record<string, unknown>): Promise<LLMCompletionResult>;
|
|
444
|
+
embed(text: string, options?: Record<string, unknown>): Promise<any>;
|
|
445
|
+
listModels(): Promise<{ models: any[] }>;
|
|
446
|
+
|
|
447
|
+
// Observability
|
|
448
|
+
getMetrics(): Promise<any>;
|
|
449
|
+
getTraces(query?: Record<string, string>): Promise<any>;
|
|
450
|
+
getTrace(traceId: string): Promise<any>;
|
|
451
|
+
getLogs(query?: Record<string, string>): Promise<any>;
|
|
452
|
+
getHealth(): Promise<HealthInfo>;
|
|
453
|
+
|
|
454
|
+
// Events (SSE)
|
|
455
|
+
subscribe(filter: string | null, onEvent: (data: any) => void): EventSource;
|
|
456
|
+
|
|
457
|
+
// Policies
|
|
458
|
+
createPolicy(policy: Record<string, unknown>): Promise<any>;
|
|
459
|
+
evaluatePolicy(entityId: string, action: string, context?: Record<string, unknown>): Promise<any>;
|
|
460
|
+
|
|
461
|
+
// Deploy
|
|
462
|
+
deploy(config?: Record<string, unknown>): Promise<any>;
|
|
463
|
+
listDeployments(query?: Record<string, string>): Promise<any>;
|
|
464
|
+
}
|
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
|
-
|
|
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 };
|