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.
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()
stop()
send(plaintext, options?)
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.
sendDecisionRequest(request)
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)
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)
sendToRoom(roomId, plaintext, options?)
joinRoom(roomData)
sendToAgent(hubAddress, text, opts?)
sendArtifact(artifact)
sendActionConfirmation(confirmation)
stopHeartbeat()
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?)
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?)
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 todataDir/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)
dataDir/agentvault.json.bak before each state load. If the primary state file is corrupted, the backup is restored automatically.
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
ThePolicyEnforcer validates skill invocations against the 5-stage policy pipeline: