@agentvault/agentvault 0.9.6 → 0.9.8
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/dist/__tests__/crypto-helpers.test.d.ts +2 -0
- package/dist/__tests__/crypto-helpers.test.d.ts.map +1 -0
- package/dist/__tests__/functional.test.d.ts +21 -0
- package/dist/__tests__/functional.test.d.ts.map +1 -0
- package/dist/__tests__/multi-session.test.d.ts +2 -0
- package/dist/__tests__/multi-session.test.d.ts.map +1 -0
- package/dist/__tests__/state.test.d.ts +2 -0
- package/dist/__tests__/state.test.d.ts.map +1 -0
- package/dist/__tests__/transport.test.d.ts +2 -0
- package/dist/__tests__/transport.test.d.ts.map +1 -0
- package/dist/channel.d.ts +4 -0
- package/dist/channel.d.ts.map +1 -1
- package/dist/channel.js +2257 -0
- package/dist/channel.js.map +1 -0
- package/dist/cli.js +313 -35
- package/dist/cli.js.map +4 -4
- package/dist/crypto-helpers.js +4 -0
- package/dist/crypto-helpers.js.map +1 -0
- package/dist/index.js +274 -19
- package/dist/index.js.map +4 -4
- package/dist/openclaw-plugin.js +222 -0
- package/dist/openclaw-plugin.js.map +1 -0
- package/dist/setup.js +329 -0
- package/dist/setup.js.map +1 -0
- package/dist/state.js +61 -0
- package/dist/state.js.map +1 -0
- package/dist/transport.js +43 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentVault OpenClaw Channel Plugin
|
|
3
|
+
*
|
|
4
|
+
* Registers AgentVault as a first-class OpenClaw messaging channel.
|
|
5
|
+
* Messages from the AgentVault UI are decrypted and routed into the
|
|
6
|
+
* OpenClaw agent loop; agent replies are encrypted and sent back.
|
|
7
|
+
*
|
|
8
|
+
* Installation (one-time):
|
|
9
|
+
* npx @agentvault/agentvault setup --token=av_tok_...
|
|
10
|
+
*
|
|
11
|
+
* After setup, restart OpenClaw — no further configuration needed.
|
|
12
|
+
*/
|
|
13
|
+
import { resolve } from "node:path";
|
|
14
|
+
import { SecureChannel } from "./channel.js";
|
|
15
|
+
// Runtime injected by register() — used in inbound handler
|
|
16
|
+
let _ocRuntime = null;
|
|
17
|
+
// Active channel instances keyed by accountId
|
|
18
|
+
const _channels = new Map();
|
|
19
|
+
export function setOcRuntime(runtime) {
|
|
20
|
+
_ocRuntime = runtime;
|
|
21
|
+
}
|
|
22
|
+
export function getActiveChannel(accountId = "default") {
|
|
23
|
+
return _channels.get(accountId);
|
|
24
|
+
}
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Channel plugin definition
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
export const agentVaultPlugin = {
|
|
29
|
+
id: "agentvault",
|
|
30
|
+
meta: {
|
|
31
|
+
id: "agentvault",
|
|
32
|
+
label: "AgentVault",
|
|
33
|
+
selectionLabel: "AgentVault (E2E Encrypted)",
|
|
34
|
+
docsPath: "https://agentvault.chat/docs",
|
|
35
|
+
blurb: "Zero-knowledge, end-to-end encrypted messaging between owners and their AI agents.",
|
|
36
|
+
aliases: ["av", "agent-vault"],
|
|
37
|
+
},
|
|
38
|
+
capabilities: {
|
|
39
|
+
chatTypes: ["direct"],
|
|
40
|
+
},
|
|
41
|
+
config: {
|
|
42
|
+
listAccountIds: (cfg) => {
|
|
43
|
+
const av = cfg?.channels?.agentvault;
|
|
44
|
+
return av?.dataDir ? ["default"] : [];
|
|
45
|
+
},
|
|
46
|
+
resolveAccount: (cfg, accountId) => {
|
|
47
|
+
const av = cfg?.channels?.agentvault ?? {};
|
|
48
|
+
return {
|
|
49
|
+
accountId: accountId ?? "default",
|
|
50
|
+
dataDir: av.dataDir ?? "~/.openclaw/agentvault",
|
|
51
|
+
apiUrl: av.apiUrl ?? "https://api.agentvault.chat",
|
|
52
|
+
agentName: av.agentName ?? "OpenClaw Agent",
|
|
53
|
+
httpPort: av.httpPort ?? 18790,
|
|
54
|
+
configured: Boolean(av.dataDir),
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
gateway: {
|
|
59
|
+
startAccount: async (ctx) => {
|
|
60
|
+
const { account, cfg, log, abortSignal } = ctx;
|
|
61
|
+
if (!account.configured) {
|
|
62
|
+
throw new Error("AgentVault channel is not configured.\n" +
|
|
63
|
+
"Run the one-time setup: npx @agentvault/agentvault setup --token=av_tok_...\n" +
|
|
64
|
+
"Then restart OpenClaw: openclaw gateway restart");
|
|
65
|
+
}
|
|
66
|
+
const dataDir = resolve(account.dataDir.replace(/^~/, process.env.HOME ?? "~"));
|
|
67
|
+
log?.(`[AgentVault] starting channel (dataDir=${dataDir})`);
|
|
68
|
+
const channel = new SecureChannel({
|
|
69
|
+
// No invite token needed — resuming from persisted enrolled state
|
|
70
|
+
inviteToken: "",
|
|
71
|
+
dataDir,
|
|
72
|
+
apiUrl: account.apiUrl,
|
|
73
|
+
agentName: account.agentName,
|
|
74
|
+
onMessage: async (plaintext, metadata) => {
|
|
75
|
+
if (!_ocRuntime) {
|
|
76
|
+
log?.("[AgentVault] runtime not ready — dropping inbound message");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
await _handleInbound({ plaintext, metadata, channel, account, cfg });
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
log?.(`[AgentVault] inbound dispatch error: ${String(err)}`);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
onStateChange: (state) => {
|
|
87
|
+
log?.(`[AgentVault] state → ${state}`);
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
_channels.set(account.accountId, channel);
|
|
91
|
+
// Start local HTTP server for proactive sends when channel is ready
|
|
92
|
+
const httpPort = account.httpPort;
|
|
93
|
+
channel.on("ready", () => {
|
|
94
|
+
channel.startHttpServer(httpPort);
|
|
95
|
+
log?.(`[AgentVault] HTTP send server listening on http://127.0.0.1:${httpPort}`);
|
|
96
|
+
});
|
|
97
|
+
// Respect gateway abort signal (OpenClaw gateway shutdown)
|
|
98
|
+
abortSignal?.addEventListener("abort", () => {
|
|
99
|
+
_channels.delete(account.accountId);
|
|
100
|
+
});
|
|
101
|
+
await channel.start();
|
|
102
|
+
return {
|
|
103
|
+
stop: async () => {
|
|
104
|
+
await channel.stop();
|
|
105
|
+
_channels.delete(account.accountId);
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
outbound: {
|
|
111
|
+
deliveryMode: "direct",
|
|
112
|
+
targets: [
|
|
113
|
+
{
|
|
114
|
+
id: "owner",
|
|
115
|
+
label: "AgentVault Owner",
|
|
116
|
+
accountId: "default",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "default",
|
|
120
|
+
label: "AgentVault Owner (default)",
|
|
121
|
+
accountId: "default",
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
sendText: async ({ text, accountId, targetId, }) => {
|
|
125
|
+
const resolvedId = accountId ?? (targetId === "owner" ? "default" : (targetId ?? "default"));
|
|
126
|
+
const channel = _channels.get(resolvedId);
|
|
127
|
+
if (!channel) {
|
|
128
|
+
return { ok: false, error: "AgentVault channel is not connected" };
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
await channel.send(text);
|
|
132
|
+
return { ok: true };
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
return { ok: false, error: String(err) };
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
// Inbound message handler — routes decrypted messages into the agent loop
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
async function _handleInbound(params) {
|
|
144
|
+
const { plaintext, metadata, channel, account, cfg } = params;
|
|
145
|
+
const core = _ocRuntime;
|
|
146
|
+
// Stable session key scoped to this AgentVault conversation
|
|
147
|
+
const sessionKey = `agentvault:${account.accountId}:${(metadata.conversationId ?? "default").slice(0, 8)}`;
|
|
148
|
+
const senderId = `agentvault:owner`;
|
|
149
|
+
// Resolve agent routing (respects agents.list routing rules if configured)
|
|
150
|
+
const route = core.channel.routing.resolveAgentRoute({
|
|
151
|
+
cfg,
|
|
152
|
+
channel: "agentvault",
|
|
153
|
+
accountId: account.accountId,
|
|
154
|
+
peer: { kind: "direct", id: senderId },
|
|
155
|
+
});
|
|
156
|
+
const storePath = core.channel.session.resolveStorePath(cfg?.session?.store, {
|
|
157
|
+
agentId: route.agentId,
|
|
158
|
+
});
|
|
159
|
+
const envelopeOptions = core.channel.reply.resolveEnvelopeFormatOptions(cfg);
|
|
160
|
+
const previousTimestamp = core.channel.session.readSessionUpdatedAt({
|
|
161
|
+
storePath,
|
|
162
|
+
sessionKey: route.sessionKey,
|
|
163
|
+
});
|
|
164
|
+
// Format the message body with standard OpenClaw envelope (channel label, timestamps, etc.)
|
|
165
|
+
const body = core.channel.reply.formatAgentEnvelope({
|
|
166
|
+
channel: "AgentVault",
|
|
167
|
+
from: "Owner",
|
|
168
|
+
timestamp: new Date(metadata.timestamp).getTime(),
|
|
169
|
+
previousTimestamp,
|
|
170
|
+
envelope: envelopeOptions,
|
|
171
|
+
body: plaintext,
|
|
172
|
+
});
|
|
173
|
+
// Build the inbound context payload OpenClaw expects
|
|
174
|
+
const ctxPayload = core.channel.reply.finalizeInboundContext({
|
|
175
|
+
Body: body,
|
|
176
|
+
RawBody: plaintext,
|
|
177
|
+
CommandBody: plaintext,
|
|
178
|
+
From: senderId,
|
|
179
|
+
To: `agentvault:agent:${account.accountId}`,
|
|
180
|
+
SessionKey: route.sessionKey,
|
|
181
|
+
AccountId: account.accountId,
|
|
182
|
+
ChatType: "direct",
|
|
183
|
+
ConversationLabel: "AgentVault",
|
|
184
|
+
SenderName: "Owner",
|
|
185
|
+
SenderId: senderId,
|
|
186
|
+
Provider: "agentvault",
|
|
187
|
+
Surface: "agentvault",
|
|
188
|
+
MessageSid: metadata.messageId,
|
|
189
|
+
Timestamp: new Date(metadata.timestamp).getTime(),
|
|
190
|
+
OriginatingChannel: "agentvault",
|
|
191
|
+
OriginatingTo: `agentvault:agent:${account.accountId}`,
|
|
192
|
+
// Owner is cryptographically verified via X3DH + Double Ratchet enrollment
|
|
193
|
+
CommandAuthorized: true,
|
|
194
|
+
});
|
|
195
|
+
// Record session metadata for context continuity
|
|
196
|
+
await core.channel.session.recordInboundSession({
|
|
197
|
+
storePath,
|
|
198
|
+
sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
|
|
199
|
+
ctx: ctxPayload,
|
|
200
|
+
onRecordError: (err) => {
|
|
201
|
+
core.error?.(`[AgentVault] session record failed: ${String(err)}`);
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
// Dispatch to the OpenClaw agent loop; deliver replies back through the channel
|
|
205
|
+
await core.channel.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
206
|
+
ctx: ctxPayload,
|
|
207
|
+
cfg,
|
|
208
|
+
dispatcherOptions: {
|
|
209
|
+
deliver: async (payload) => {
|
|
210
|
+
const text = (payload.text ?? "").trim();
|
|
211
|
+
if (text) {
|
|
212
|
+
await channel.send(text);
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
onError: (err, info) => {
|
|
216
|
+
core.error?.(`[AgentVault] ${info?.kind ?? "reply"} error: ${String(err)}`);
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
replyOptions: {},
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=openclaw-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openclaw-plugin.js","sourceRoot":"","sources":["../src/openclaw-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,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L,CAAC"}
|
package/dist/setup.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentVault one-time setup command.
|
|
3
|
+
*
|
|
4
|
+
* Runs enrollment + waits for owner approval + persists state,
|
|
5
|
+
* then auto-registers the agentvault channel in openclaw config.
|
|
6
|
+
*
|
|
7
|
+
* Usage: npx @agentvault/agentvault setup --token=av_tok_...
|
|
8
|
+
*/
|
|
9
|
+
import { execSync, spawnSync } from "node:child_process";
|
|
10
|
+
import * as readline from "node:readline";
|
|
11
|
+
import { resolve } from "node:path";
|
|
12
|
+
import { SecureChannel } from "./channel.js";
|
|
13
|
+
import { VERSION } from "./index.js";
|
|
14
|
+
export async function runSetupCommand(options) {
|
|
15
|
+
const { token, name, apiUrl } = options;
|
|
16
|
+
const dataDir = resolve(options.dataDir.replace(/^~/, process.env.HOME ?? "~"));
|
|
17
|
+
console.log(`
|
|
18
|
+
╔══════════════════════════════════════════════╗
|
|
19
|
+
║ AgentVault — First-Time Setup ║
|
|
20
|
+
╚══════════════════════════════════════════════╝
|
|
21
|
+
|
|
22
|
+
Agent name : ${name}
|
|
23
|
+
Data dir : ${dataDir}
|
|
24
|
+
API : ${apiUrl}
|
|
25
|
+
`);
|
|
26
|
+
let enrollDone = false;
|
|
27
|
+
const channel = new SecureChannel({
|
|
28
|
+
inviteToken: token,
|
|
29
|
+
dataDir,
|
|
30
|
+
apiUrl,
|
|
31
|
+
agentName: name,
|
|
32
|
+
onMessage: () => { }, // Not handling messages during setup
|
|
33
|
+
onStateChange: (state) => {
|
|
34
|
+
switch (state) {
|
|
35
|
+
case "enrolling":
|
|
36
|
+
console.log(" Enrolling with AgentVault server...");
|
|
37
|
+
break;
|
|
38
|
+
case "polling":
|
|
39
|
+
console.log(" Waiting for approval in your AgentVault dashboard...");
|
|
40
|
+
if (channel.fingerprint) {
|
|
41
|
+
console.log(`\n Fingerprint: ${channel.fingerprint}`);
|
|
42
|
+
console.log(" Verify this fingerprint matches the one shown in your dashboard");
|
|
43
|
+
console.log(" before clicking Approve.\n");
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case "activating":
|
|
47
|
+
console.log(" Approved! Setting up encryption...");
|
|
48
|
+
break;
|
|
49
|
+
case "ready":
|
|
50
|
+
enrollDone = true;
|
|
51
|
+
console.log(" ✅ Enrollment complete! Secure channel established.\n");
|
|
52
|
+
break;
|
|
53
|
+
case "error":
|
|
54
|
+
console.error(" ❌ Setup encountered an error.");
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
channel.on("error", (err) => {
|
|
60
|
+
console.error(`\n ❌ Setup failed: ${err.message}\n`);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
});
|
|
63
|
+
// Start enrollment — blocks until ready or error
|
|
64
|
+
await new Promise((res, rej) => {
|
|
65
|
+
const check = setInterval(() => {
|
|
66
|
+
if (enrollDone) {
|
|
67
|
+
clearInterval(check);
|
|
68
|
+
res();
|
|
69
|
+
}
|
|
70
|
+
}, 500);
|
|
71
|
+
channel.start().catch((err) => {
|
|
72
|
+
clearInterval(check);
|
|
73
|
+
rej(err);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
// Stop the live connection — OpenClaw's gateway will own it after restart
|
|
77
|
+
await channel.stop();
|
|
78
|
+
// --- Install plugin + register in OpenClaw config ---
|
|
79
|
+
console.log(" Installing AgentVault plugin in OpenClaw...\n");
|
|
80
|
+
// Extend PATH to find openclaw regardless of how npx was invoked
|
|
81
|
+
const home = process.env.HOME ?? "";
|
|
82
|
+
const extraPaths = [
|
|
83
|
+
`${home}/.local/bin`,
|
|
84
|
+
`${home}/.pnpm/bin`,
|
|
85
|
+
`${home}/Library/pnpm/bin`,
|
|
86
|
+
"/usr/local/bin",
|
|
87
|
+
"/opt/homebrew/bin",
|
|
88
|
+
].join(":");
|
|
89
|
+
const env = { ...process.env, PATH: `${extraPaths}:${process.env.PATH ?? ""}` };
|
|
90
|
+
const pluginInstalled = installPlugin(env);
|
|
91
|
+
if (!pluginInstalled) {
|
|
92
|
+
// openclaw not in PATH — print full manual instructions and bail
|
|
93
|
+
console.log(`
|
|
94
|
+
⚠️ Could not auto-configure OpenClaw (is 'openclaw' in your PATH?).
|
|
95
|
+
|
|
96
|
+
1. Install the plugin:
|
|
97
|
+
openclaw plugins install @agentvault/agentvault
|
|
98
|
+
|
|
99
|
+
2. Register the plugin in the allow list:
|
|
100
|
+
openclaw config set plugins.allow '["agentvault"]'
|
|
101
|
+
|
|
102
|
+
3. Add this to your OpenClaw config (openclaw.yaml or openclaw.json):
|
|
103
|
+
channels:
|
|
104
|
+
agentvault:
|
|
105
|
+
dataDir: "${dataDir}"
|
|
106
|
+
apiUrl: "${apiUrl}"
|
|
107
|
+
agentName: "${name}"
|
|
108
|
+
|
|
109
|
+
4. (Recommended) Install pm2 for auto-restart and crash recovery:
|
|
110
|
+
npm install -g pm2
|
|
111
|
+
pm2 start "openclaw gateway start" --name openclaw-gateway
|
|
112
|
+
pm2 startup
|
|
113
|
+
pm2 save
|
|
114
|
+
|
|
115
|
+
5. Restart the gateway:
|
|
116
|
+
openclaw gateway restart
|
|
117
|
+
`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
console.log("\n Registering AgentVault channel in OpenClaw config...\n");
|
|
121
|
+
const patchCommands = [
|
|
122
|
+
`openclaw config set channels.agentvault.dataDir "${dataDir}"`,
|
|
123
|
+
`openclaw config set channels.agentvault.apiUrl "${apiUrl}"`,
|
|
124
|
+
`openclaw config set channels.agentvault.agentName "${name}"`,
|
|
125
|
+
`openclaw config set plugins.allow '["agentvault"]'`,
|
|
126
|
+
];
|
|
127
|
+
let configPatched = false;
|
|
128
|
+
for (const cmd of patchCommands) {
|
|
129
|
+
try {
|
|
130
|
+
execSync(cmd, { stdio: "pipe", env });
|
|
131
|
+
configPatched = true;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// config write failed — fall through to manual
|
|
135
|
+
configPatched = false;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (configPatched) {
|
|
140
|
+
console.log(` ✅ Channel registered in OpenClaw config.\n`);
|
|
141
|
+
// --- Step 6: Configure pm2 process management ---
|
|
142
|
+
console.log(" Configuring pm2 process management...\n");
|
|
143
|
+
configurePm2(env);
|
|
144
|
+
await promptAndRestart(env);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
console.log(` ⚠️ Could not auto-configure OpenClaw channel.
|
|
148
|
+
Add this to your OpenClaw config (openclaw.yaml or openclaw.json) manually:
|
|
149
|
+
|
|
150
|
+
channels:
|
|
151
|
+
agentvault:
|
|
152
|
+
dataDir: "${dataDir}"
|
|
153
|
+
apiUrl: "${apiUrl}"
|
|
154
|
+
agentName: "${name}"
|
|
155
|
+
|
|
156
|
+
Then restart OpenClaw:
|
|
157
|
+
openclaw gateway restart
|
|
158
|
+
`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Install/update the plugin in OpenClaw's extensions directory.
|
|
163
|
+
* Returns true if the plugin is installed (or was already up-to-date).
|
|
164
|
+
*/
|
|
165
|
+
export function installPlugin(env) {
|
|
166
|
+
// Check if already installed
|
|
167
|
+
try {
|
|
168
|
+
const info = execSync("openclaw plugins info agentvault", {
|
|
169
|
+
stdio: "pipe",
|
|
170
|
+
env,
|
|
171
|
+
});
|
|
172
|
+
const infoStr = info.toString();
|
|
173
|
+
const versionMatch = infoStr.match(/version[:\s]+(\S+)/i);
|
|
174
|
+
const installedVersion = versionMatch?.[1];
|
|
175
|
+
if (installedVersion && installedVersion !== VERSION) {
|
|
176
|
+
console.log(` Updating plugin ${installedVersion} → ${VERSION}...`);
|
|
177
|
+
spawnSync("openclaw", ["plugins", "uninstall", "agentvault"], {
|
|
178
|
+
stdio: "pipe",
|
|
179
|
+
input: "y\n",
|
|
180
|
+
env,
|
|
181
|
+
});
|
|
182
|
+
execSync("openclaw plugins install @agentvault/agentvault", {
|
|
183
|
+
stdio: "pipe",
|
|
184
|
+
env,
|
|
185
|
+
});
|
|
186
|
+
console.log(" ✅ Plugin updated.");
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
console.log(` Plugin already installed (v${installedVersion ?? "unknown"}).`);
|
|
190
|
+
}
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
// Not installed — install fresh
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
execSync("openclaw plugins install @agentvault/agentvault", {
|
|
198
|
+
stdio: "pipe",
|
|
199
|
+
env,
|
|
200
|
+
});
|
|
201
|
+
console.log(" ✅ Plugin installed in OpenClaw.");
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
console.log(" ⚠️ Could not auto-install plugin.");
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Configure pm2 to manage the OpenClaw gateway process.
|
|
211
|
+
* Returns true if pm2 was configured (or already configured).
|
|
212
|
+
*/
|
|
213
|
+
export function configurePm2(env) {
|
|
214
|
+
// Check if pm2 is available
|
|
215
|
+
try {
|
|
216
|
+
execSync("pm2 --version", { stdio: "pipe", env });
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
console.log(`
|
|
220
|
+
ℹ️ pm2 not found. For best reliability, install pm2:
|
|
221
|
+
npm install -g pm2
|
|
222
|
+
|
|
223
|
+
Then configure the gateway to auto-restart:
|
|
224
|
+
pm2 start "openclaw gateway start" --name openclaw-gateway
|
|
225
|
+
pm2 startup
|
|
226
|
+
pm2 save
|
|
227
|
+
`);
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
// Check if already configured
|
|
231
|
+
try {
|
|
232
|
+
const info = execSync("pm2 describe openclaw-gateway", { stdio: "pipe", env });
|
|
233
|
+
const infoStr = info.toString();
|
|
234
|
+
if (infoStr.includes("online") || infoStr.includes("stopped")) {
|
|
235
|
+
console.log(" pm2 process 'openclaw-gateway' already exists.");
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
// Not configured yet — continue
|
|
241
|
+
}
|
|
242
|
+
// Determine platform-specific command
|
|
243
|
+
const isMac = process.platform === "darwin";
|
|
244
|
+
const startCmd = isMac
|
|
245
|
+
? "caffeinate -i openclaw gateway start"
|
|
246
|
+
: "openclaw gateway start";
|
|
247
|
+
try {
|
|
248
|
+
execSync(`pm2 start "${startCmd}" --name openclaw-gateway`, { stdio: "pipe", env });
|
|
249
|
+
console.log(" ✅ Gateway registered with pm2.");
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
console.log(` ⚠️ Failed to register with pm2: ${err}`);
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
// Generate startup script
|
|
256
|
+
try {
|
|
257
|
+
execSync("pm2 startup", { stdio: "pipe", env });
|
|
258
|
+
console.log(" ✅ pm2 startup configured (auto-start on boot).");
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
console.log(" ⚠️ pm2 startup failed — you may need to run 'pm2 startup' manually with sudo.");
|
|
262
|
+
}
|
|
263
|
+
// Save process list
|
|
264
|
+
try {
|
|
265
|
+
execSync("pm2 save", { stdio: "pipe", env });
|
|
266
|
+
console.log(" ✅ pm2 process list saved.");
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
console.log(" ⚠️ pm2 save failed.");
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Prompt the user to restart the OpenClaw gateway now or later.
|
|
275
|
+
* Runs `openclaw gateway restart` synchronously if they confirm.
|
|
276
|
+
*/
|
|
277
|
+
async function promptAndRestart(env) {
|
|
278
|
+
const answer = await ask(" ⚠️ OpenClaw gateway will restart, briefly interrupting any active conversations.\n" +
|
|
279
|
+
" Restart now? [y/N] ");
|
|
280
|
+
if (answer.trim().toLowerCase() === "y") {
|
|
281
|
+
console.log("\n Restarting OpenClaw gateway...");
|
|
282
|
+
const result = spawnSync("openclaw", ["gateway", "restart"], {
|
|
283
|
+
stdio: "inherit",
|
|
284
|
+
env,
|
|
285
|
+
});
|
|
286
|
+
if (result.status === 0) {
|
|
287
|
+
console.log(`
|
|
288
|
+
✅ Gateway restarted. AgentVault is now active.
|
|
289
|
+
Your AgentVault UI will route encrypted messages
|
|
290
|
+
directly into your agent.
|
|
291
|
+
`);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
console.log(`
|
|
295
|
+
⚠️ Restart command failed (exit ${result.status ?? "unknown"}).
|
|
296
|
+
Please restart manually:
|
|
297
|
+
|
|
298
|
+
openclaw gateway restart
|
|
299
|
+
`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
console.log(`
|
|
304
|
+
──────────────────────────────────────────────
|
|
305
|
+
Run this when you're ready to activate:
|
|
306
|
+
|
|
307
|
+
openclaw gateway restart
|
|
308
|
+
|
|
309
|
+
After restart, your AgentVault UI will route
|
|
310
|
+
encrypted messages directly into your agent.
|
|
311
|
+
──────────────────────────────────────────────
|
|
312
|
+
`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/** Prompt helper — resolves with the user's input line. */
|
|
316
|
+
function ask(question) {
|
|
317
|
+
return new Promise((resolve) => {
|
|
318
|
+
const rl = readline.createInterface({
|
|
319
|
+
input: process.stdin,
|
|
320
|
+
output: process.stdout,
|
|
321
|
+
terminal: true,
|
|
322
|
+
});
|
|
323
|
+
rl.question(question, (answer) => {
|
|
324
|
+
rl.close();
|
|
325
|
+
resolve(answer);
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"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,CAAC;QACH,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC;;;;CAIjB,CAAC,CAAC;QACC,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC;qCACmB,MAAM,CAAC,MAAM,IAAI,SAAS;;;;CAI9D,CAAC,CAAC;QACC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC;;;;;;;;;CASf,CAAC,CAAC;IACD,CAAC;AACH,CAAC;AAED,2DAA2D;AAC3D,SAAS,GAAG,CAAC,QAAgB;IAC3B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;YAClC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QACH,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;YAC/B,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const STATE_FILE = "agentvault.json";
|
|
4
|
+
const LEGACY_STATE_FILE = "secure-channel.json";
|
|
5
|
+
export async function saveState(dataDir, state) {
|
|
6
|
+
await mkdir(dataDir, { recursive: true });
|
|
7
|
+
const filePath = join(dataDir, STATE_FILE);
|
|
8
|
+
await writeFile(filePath, JSON.stringify(state, null, 2), "utf-8");
|
|
9
|
+
// Clean up legacy file after migration
|
|
10
|
+
try {
|
|
11
|
+
await rm(join(dataDir, LEGACY_STATE_FILE));
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
// Already removed or never existed
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Load raw persisted state from disk.
|
|
19
|
+
* Returns the raw parsed JSON — caller is responsible for migration
|
|
20
|
+
* from legacy format to current PersistedState.
|
|
21
|
+
*
|
|
22
|
+
* Checks agentvault.json first, falls back to secure-channel.json
|
|
23
|
+
* for backward compatibility. Auto-migrates on first legacy load.
|
|
24
|
+
*/
|
|
25
|
+
export async function loadState(dataDir) {
|
|
26
|
+
// Try new filename first
|
|
27
|
+
const filePath = join(dataDir, STATE_FILE);
|
|
28
|
+
try {
|
|
29
|
+
const raw = await readFile(filePath, "utf-8");
|
|
30
|
+
return JSON.parse(raw);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Fall through to legacy
|
|
34
|
+
}
|
|
35
|
+
// Fall back to legacy filename
|
|
36
|
+
const legacyPath = join(dataDir, LEGACY_STATE_FILE);
|
|
37
|
+
try {
|
|
38
|
+
const raw = await readFile(legacyPath, "utf-8");
|
|
39
|
+
const parsed = JSON.parse(raw);
|
|
40
|
+
// Auto-migrate: write to new filename, remove legacy
|
|
41
|
+
await mkdir(dataDir, { recursive: true });
|
|
42
|
+
await writeFile(filePath, JSON.stringify(parsed, null, 2), "utf-8");
|
|
43
|
+
await rm(legacyPath);
|
|
44
|
+
return parsed;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export async function clearState(dataDir) {
|
|
51
|
+
// Remove both files to cover migration edge cases
|
|
52
|
+
for (const filename of [STATE_FILE, LEGACY_STATE_FILE]) {
|
|
53
|
+
try {
|
|
54
|
+
await rm(join(dataDir, filename));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// File doesn't exist — nothing to clear
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//#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