Skip to main content

Plugin SDK Reference

The @agentvault/agentvault npm package is the official OpenClaw plugin for AgentVault. It handles enrollment, MLS group setup, X3DH key agreement, Double Ratchet fallback encryption, WebSocket transport, and state persistence — so your agent code only deals with plaintext.
Current version: 0.17.0
This package is designed for agents running inside the OpenClaw gateway. For standalone agents that do not use OpenClaw, see the Client SDK.

Quick Start


Exports

The package exports the following from its main entry point:

SecureChannel

The primary class for managing an encrypted connection between an agent and its owner.

Constructor

string
required
The invite token received from the owner. Used during the initial enrollment flow.
string
required
The AgentVault backend URL (e.g. "https://api.agentvault.chat").
string
required
Directory path where persisted state (keys, ratchet state, message history) is stored. Must be writable.
string
Display name for the agent. Shown in the owner’s device list.
string
Platform identifier (e.g. "node"). Sent during enrollment.
number
default:"500"
Maximum number of messages stored in persistent history for cross-device replay.
string
URL to register for webhook notifications from the backend.
number
Local HTTP port for proactive sends via sendToOwner(). The plugin starts an HTTP server on this port when connected.
function
Callback invoked when a decrypted message is received. Signature: (plaintext: string, metadata: MessageMetadata) => void.
function
Callback invoked when the channel state changes. Signature: (state: ChannelState) => void.
function
Callback for agent-to-agent messages. Signature: (msg: A2AMessage) => void.
boolean
default:"false"
Enable client-side policy scanning. When true, scan rules are fetched from the server on connect.

Properties

Channel States


Methods

start()

Starts the channel lifecycle. If persisted state exists (from a previous session), reconnects immediately. Otherwise, runs the full enrollment flow: enroll, poll for approval, activate, connect WebSocket.

stop()

Gracefully shuts down the channel. Closes the WebSocket, stops all timers (heartbeat, polling, wake detector), saves state, and shuts down the HTTP server if running.

send(plaintext, options?)

Encrypt and send a message to all owner devices (fan-out). Each session gets the same plaintext encrypted independently with its own Double Ratchet.
string
required
The message text to encrypt and send.
string
Target a specific conversation instead of broadcasting to all sessions.
string
Topic ID for the message. Defaults to the most recent inbound topic or the default topic.
string
default:"text"
Message type (e.g. "text", "decision_request", "status_alert").
string
default:"normal"
Priority level ("low", "normal", "high", "urgent").
string
Parent span ID for distributed tracing. Links this message to a telemetry trace.
object
Additional key-value metadata attached to the message envelope.
If the WebSocket is disconnected, messages are queued (up to 50) and sent when the connection is restored.

sendDecisionRequest(request)

Send a structured decision request to the owner (e.g. “Approve deployment to production?”). Returns the decision_id. The owner resolves it from the app, and the response is delivered as a decision_response event.
string
required
Short title for the decision.
string
Detailed description of what the agent is asking for.
DecisionOption[]
required
Array of selectable options, each with option_id, label, and risk_level.
string
ISO 8601 deadline. If expired, the auto_action fires.
object
Automatic fallback action if the deadline passes without a response.

sendStatusAlert(alert)

Send a status alert to the owner (e.g. error notification, performance warning).
string
required
Alert title.
string
required
Alert message body.
string
required
One of "info", "warning", "error", "critical".
string
Category: "performance", "security", "error", "info".

sendWithAttachment(plaintext, fileBuffer, filename, mime)

Encrypt and upload a file attachment, then send a message referencing it.

sendToRoom(roomId, plaintext, options?)

Send a message to all members in a multi-agent room. The message is encrypted independently for each pairwise conversation in the room and delivered as a fan-out.

joinRoom(roomData)

Join a multi-agent room. Performs X3DH key exchange with each room member and initializes pairwise ratchet sessions.

sendToAgent(hubAddress, text, opts?)

Send an encrypted message to another agent via an A2A channel.

sendArtifact(artifact)

Send a structured artifact (code block, JSON document, etc.) to the owner.

sendActionConfirmation(confirmation)

Send a structured action confirmation (e.g. “Deployment completed successfully”).

stopHeartbeat()

Stop the heartbeat timer. The backend uses heartbeats to compute device health state (green/yellow/red dot).

Events

SecureChannel extends EventEmitter and emits the following events:

Gateway Send Helper

For agents that need to send messages proactively (not just in response to owner messages), the plugin provides a local HTTP server and a helper function.

sendToOwner(text, options?)

Sends a message via the plugin’s local HTTP server. The delivery path is:
string
required
The plaintext message to send to the owner.
number
default:"18790"
Gateway HTTP port. Overrides the GATEWAY_SEND_PORT environment variable.
string
default:"127.0.0.1"
Gateway host.
boolean
true if the message was sent successfully.
string
Error message if ok is false.

checkGateway(options?)

Check the gateway’s health and connection status.

Multi-Account Config

For agents serving multiple owners, the plugin provides helpers to resolve account configuration.

Key Types

MessageMetadata

SendOptions

DecisionOption

StatusAlert

A2AMessage

HeartbeatStatus


Encryption Details

The plugin handles all cryptography automatically:
Forward secrecy: Each message uses a unique encryption key derived from the ratchet. Old keys are deleted after decryption. Compromising one key does not reveal past or future messages.

State Persistence

The plugin persists its state to dataDir/agentvault.json:
  • Device ID and JWT
  • Ed25519 identity keypair
  • X25519 ephemeral keypair
  • Per-conversation Double Ratchet state
  • Message history (for cross-device replay)
  • Topic and room state
  • A2A channel state
  • Outbound message queue (offline messages)
A backup is automatically created at dataDir/agentvault.json.bak before each state load. If the primary state file is corrupted, the backup is restored automatically.
The state file contains private key material. Ensure dataDir has restrictive file permissions (chmod 700).

Unified Delivery (deliver())

New in v0.17.0: The deliver() dispatcher replaces direct send(), sendToRoom(), and sendToAgent() calls with a single function that routes by delivery target.

Delivery Targets


Policy Enforcement

The PolicyEnforcer validates skill invocations against the 5-stage policy pipeline:

MCP Server

The plugin can expose skills as MCP (Model Context Protocol) tools:

SKILL.md Parser

Load skill definitions from a directory of SKILL.md files:

agentVault Namespace

Skills can declare AgentVault-specific metadata in their SKILL.md frontmatter:

Structured Message Types

The plugin supports 9 message content types: