@agentvault/agentvault 0.13.5 → 0.13.7

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.
@@ -29,20 +29,6 @@ export interface GatewayStatusResult {
29
29
  * Never throws — returns `{ ok: false, error }` on failure.
30
30
  */
31
31
  export declare function sendToOwner(text: string, options?: GatewaySendOptions): Promise<GatewaySendResult>;
32
- export interface ActionReport {
33
- action: string;
34
- status: "completed" | "failed" | "partial";
35
- room_id?: string;
36
- detail?: string;
37
- estimated_cost?: number;
38
- decision_id?: string;
39
- }
40
- /**
41
- * Report an action (deploy, execute, etc.) via the gateway HTTP server.
42
- * Routes to sendActionConfirmationToRoom() (if room_id) or sendActionConfirmation().
43
- * Never throws — returns `{ ok: false, error }` on failure.
44
- */
45
- export declare function sendAction(report: ActionReport, options?: GatewaySendOptions): Promise<GatewaySendResult>;
46
32
  /**
47
33
  * Check gateway health / status.
48
34
  * Never throws — returns `{ ok: false, error }` on failure.
@@ -1 +1 @@
1
- {"version":3,"file":"gateway-send.d.ts","sourceRoot":"","sources":["../src/gateway-send.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,kBAAkB;IACjC,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAsBD;;;GAGG;AACH,wB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C/B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,iBAAiB,CAAC,CAuB5B;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CAmB9B"}
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export type { SecureChannelConfig, ChannelState, MessageMetadata, AttachmentData
3
3
  export { listAccountIds, resolveAccount } from "./account-config.js";
4
4
  export type { ResolvedAccount } from "./account-config.js";
5
5
  export { agentVaultPlugin, setOcRuntime, getActiveChannel } from "./openclaw-plugin.js";
6
- export { sendToOwner, sendAction, checkGateway } from "./gateway-send.js";
7
- export type { GatewaySendOptions, GatewaySendResult, GatewayStatusResult, ActionReport, } from "./gateway-send.js";
8
- export declare const VERSION = "0.12.0";
6
+ export { sendToOwner, checkGateway } from "./gateway-send.js";
7
+ export type { GatewaySendOptions, GatewaySendResult, GatewayStatusResult, } from "./gateway-send.js";
8
+ export declare const VERSION = "0.13.7";
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,WAAW,EACX,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,WAAW,EACX,QAAQ,EACR,cAAc,EACd,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,UAAU,EACV,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC1E,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,GACb,MAAM,mBAAmB,CAAC;AAE3B,eAAO,MAAM,OAAO,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,WAAW,EACX,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,WAAW,EACX,QAAQ,EACR,cAAc,EACd,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,UAAU,EACV,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxF,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAE3B,eAAO,MAAM,OAAO,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -44880,7 +44880,6 @@ var DoubleRatchet = class _DoubleRatchet {
44880
44880
  serialize() {
44881
44881
  const s2 = this.state;
44882
44882
  return JSON.stringify({
44883
- version: 1,
44884
44883
  rootKey: libsodium_wrappers_default.to_hex(s2.rootKey),
44885
44884
  sendingChain: s2.sendingChain ? {
44886
44885
  chainKey: libsodium_wrappers_default.to_hex(s2.sendingChain.chainKey),
@@ -44908,59 +44907,33 @@ var DoubleRatchet = class _DoubleRatchet {
44908
44907
  });
44909
44908
  }
44910
44909
  static deserialize(json) {
44911
- let d2;
44912
- try {
44913
- d2 = JSON.parse(json);
44914
- } catch {
44915
- throw new Error("Ratchet state: corrupt JSON");
44916
- }
44917
- if (d2.version !== void 0 && d2.version !== 1) {
44918
- throw new Error(`Ratchet state version ${d2.version} not supported`);
44919
- }
44920
- if (typeof d2.rootKey !== "string") {
44921
- throw new Error("Ratchet state: missing required field rootKey");
44922
- }
44923
- const dhSend = d2.dhSendingKeypair;
44924
- if (!dhSend || typeof dhSend.publicKey !== "string" || typeof dhSend.privateKey !== "string") {
44925
- throw new Error("Ratchet state: missing required field dhSendingKeypair");
44926
- }
44927
- const idKp = d2.identityKeypair;
44928
- if (!idKp || typeof idKp.publicKey !== "string" || typeof idKp.privateKey !== "string") {
44929
- throw new Error("Ratchet state: missing required field identityKeypair");
44930
- }
44931
- try {
44932
- return new _DoubleRatchet({
44933
- rootKey: libsodium_wrappers_default.from_hex(d2.rootKey),
44934
- sendingChain: d2.sendingChain ? {
44935
- chainKey: libsodium_wrappers_default.from_hex(d2.sendingChain.chainKey),
44936
- messageNumber: d2.sendingChain.messageNumber
44937
- } : null,
44938
- receivingChain: d2.receivingChain ? {
44939
- chainKey: libsodium_wrappers_default.from_hex(d2.receivingChain.chainKey),
44940
- messageNumber: d2.receivingChain.messageNumber
44941
- } : null,
44942
- dhSendingKeypair: {
44943
- publicKey: libsodium_wrappers_default.from_hex(dhSend.publicKey),
44944
- privateKey: libsodium_wrappers_default.from_hex(dhSend.privateKey)
44945
- },
44946
- dhReceivingPublicKey: d2.dhReceivingPublicKey ? libsodium_wrappers_default.from_hex(d2.dhReceivingPublicKey) : null,
44947
- identityKeypair: {
44948
- publicKey: libsodium_wrappers_default.from_hex(idKp.publicKey),
44949
- privateKey: libsodium_wrappers_default.from_hex(idKp.privateKey)
44950
- },
44951
- previousSendingChainLength: d2.previousSendingChainLength,
44952
- skippedKeys: d2.skippedKeys.map((sk) => ({
44953
- dhPub: sk.dhPub,
44954
- n: sk.n,
44955
- messageKey: libsodium_wrappers_default.from_hex(sk.messageKey)
44956
- }))
44957
- });
44958
- } catch (err) {
44959
- if (err instanceof Error && err.message.startsWith("Ratchet state")) {
44960
- throw err;
44961
- }
44962
- throw new Error(`Ratchet state: corrupt hex data \u2014 ${err instanceof Error ? err.message : String(err)}`);
44963
- }
44910
+ const d2 = JSON.parse(json);
44911
+ return new _DoubleRatchet({
44912
+ rootKey: libsodium_wrappers_default.from_hex(d2.rootKey),
44913
+ sendingChain: d2.sendingChain ? {
44914
+ chainKey: libsodium_wrappers_default.from_hex(d2.sendingChain.chainKey),
44915
+ messageNumber: d2.sendingChain.messageNumber
44916
+ } : null,
44917
+ receivingChain: d2.receivingChain ? {
44918
+ chainKey: libsodium_wrappers_default.from_hex(d2.receivingChain.chainKey),
44919
+ messageNumber: d2.receivingChain.messageNumber
44920
+ } : null,
44921
+ dhSendingKeypair: {
44922
+ publicKey: libsodium_wrappers_default.from_hex(d2.dhSendingKeypair.publicKey),
44923
+ privateKey: libsodium_wrappers_default.from_hex(d2.dhSendingKeypair.privateKey)
44924
+ },
44925
+ dhReceivingPublicKey: d2.dhReceivingPublicKey ? libsodium_wrappers_default.from_hex(d2.dhReceivingPublicKey) : null,
44926
+ identityKeypair: {
44927
+ publicKey: libsodium_wrappers_default.from_hex(d2.identityKeypair.publicKey),
44928
+ privateKey: libsodium_wrappers_default.from_hex(d2.identityKeypair.privateKey)
44929
+ },
44930
+ previousSendingChainLength: d2.previousSendingChainLength,
44931
+ skippedKeys: d2.skippedKeys.map((sk) => ({
44932
+ dhPub: sk.dhPub,
44933
+ n: sk.n,
44934
+ messageKey: libsodium_wrappers_default.from_hex(sk.messageKey)
44935
+ }))
44936
+ });
44964
44937
  }
44965
44938
  };
44966
44939
 
@@ -45470,7 +45443,7 @@ var TelemetryReporter = class {
45470
45443
  };
45471
45444
 
45472
45445
  // src/state.ts
45473
- import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
45446
+ import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
45474
45447
  import { join } from "node:path";
45475
45448
  var STATE_FILE = "agentvault.json";
45476
45449
  var LEGACY_STATE_FILE = "secure-channel.json";
@@ -45502,6 +45475,44 @@ async function loadState(dataDir) {
45502
45475
  return null;
45503
45476
  }
45504
45477
  }
45478
+ async function isStateValid(dataDir) {
45479
+ try {
45480
+ const filePath = join(dataDir, STATE_FILE);
45481
+ const raw = await readFile(filePath, "utf-8");
45482
+ const parsed = JSON.parse(raw);
45483
+ return !!(parsed && parsed.deviceId && parsed.deviceJwt && parsed.sessions && Object.keys(parsed.sessions).length > 0);
45484
+ } catch {
45485
+ return false;
45486
+ }
45487
+ }
45488
+ async function backupState(dataDir) {
45489
+ const src = join(dataDir, STATE_FILE);
45490
+ const bak = join(dataDir, `${STATE_FILE}.bak`);
45491
+ const tmp = join(dataDir, `${STATE_FILE}.bak.tmp`);
45492
+ try {
45493
+ const data = await readFile(src, "utf-8");
45494
+ await writeFile(tmp, data, "utf-8");
45495
+ await rename(tmp, bak);
45496
+ } catch {
45497
+ }
45498
+ }
45499
+ async function restoreState(dataDir) {
45500
+ const primaryValid = await isStateValid(dataDir);
45501
+ if (primaryValid) return false;
45502
+ const bak = join(dataDir, `${STATE_FILE}.bak`);
45503
+ try {
45504
+ const data = await readFile(bak, "utf-8");
45505
+ const parsed = JSON.parse(data);
45506
+ if (!parsed || !parsed.deviceId || !parsed.deviceJwt || !parsed.sessions || Object.keys(parsed.sessions).length === 0) {
45507
+ return false;
45508
+ }
45509
+ await mkdir(dataDir, { recursive: true });
45510
+ await writeFile(join(dataDir, STATE_FILE), data, "utf-8");
45511
+ return true;
45512
+ } catch {
45513
+ return false;
45514
+ }
45515
+ }
45505
45516
  async function clearState(dataDir) {
45506
45517
  for (const filename of [STATE_FILE, LEGACY_STATE_FILE]) {
45507
45518
  try {
@@ -45656,6 +45667,7 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
45656
45667
  await libsodium_wrappers_default.ready;
45657
45668
  const raw = await loadState(this.config.dataDir);
45658
45669
  if (raw) {
45670
+ await backupState(this.config.dataDir);
45659
45671
  this._persisted = migratePersistedState(raw);
45660
45672
  if (!this._persisted.messageHistory) {
45661
45673
  this._persisted.messageHistory = [];
@@ -45679,6 +45691,30 @@ var SecureChannel = class _SecureChannel extends EventEmitter {
45679
45691
  this._connect();
45680
45692
  return;
45681
45693
  }
45694
+ const restored = await restoreState(this.config.dataDir);
45695
+ if (restored) {
45696
+ console.log("[SecureChannel] Restored state from backup");
45697
+ const restoredRaw = await loadState(this.config.dataDir);
45698
+ if (restoredRaw) {
45699
+ this._persisted = migratePersistedState(restoredRaw);
45700
+ if (!this._persisted.messageHistory) this._persisted.messageHistory = [];
45701
+ this._deviceId = this._persisted.deviceId;
45702
+ this._deviceJwt = this._persisted.deviceJwt;
45703
+ this._primaryConversationId = this._persisted.primaryConversationId;
45704
+ this._fingerprint = this._persisted.fingerprint;
45705
+ for (const [convId, sd] of Object.entries(this._persisted.sessions)) {
45706
+ if (sd.ratchetState) {
45707
+ this._sessions.set(convId, {
45708
+ ownerDeviceId: sd.ownerDeviceId,
45709
+ ratchet: DoubleRatchet.deserialize(sd.ratchetState),
45710
+ activated: sd.activated ?? false
45711
+ });
45712
+ }
45713
+ }
45714
+ this._connect();
45715
+ return;
45716
+ }
45717
+ }
45682
45718
  await this._enroll();
45683
45719
  }
45684
45720
  /**
@@ -48134,6 +48170,7 @@ ${messageText}`;
48134
48170
  };
48135
48171
  }
48136
48172
  await saveState(this.config.dataDir, this._persisted);
48173
+ await backupState(this.config.dataDir);
48137
48174
  }
48138
48175
  };
48139
48176
 
@@ -48406,27 +48443,6 @@ async function sendToOwner(text, options) {
48406
48443
  return { ok: false, error: friendlyError(err) };
48407
48444
  }
48408
48445
  }
48409
- async function sendAction(report, options) {
48410
- if (typeof report.action !== "string" || report.action.trim().length === 0) {
48411
- return { ok: false, error: "Action must be a non-empty string" };
48412
- }
48413
- try {
48414
- const base = resolveBaseUrl(options);
48415
- const res = await fetch(`${base}/action`, {
48416
- method: "POST",
48417
- headers: { "Content-Type": "application/json" },
48418
- body: JSON.stringify(report),
48419
- signal: options?.signal
48420
- });
48421
- if (!res.ok) {
48422
- const body = await res.text().catch(() => "");
48423
- return { ok: false, error: `HTTP ${res.status}${body ? `: ${body}` : ""}` };
48424
- }
48425
- return { ok: true };
48426
- } catch (err) {
48427
- return { ok: false, error: friendlyError(err) };
48428
- }
48429
- }
48430
48446
  async function checkGateway(options) {
48431
48447
  try {
48432
48448
  const base = resolveBaseUrl(options);
@@ -48447,7 +48463,7 @@ async function checkGateway(options) {
48447
48463
  }
48448
48464
 
48449
48465
  // src/index.ts
48450
- var VERSION = "0.12.0";
48466
+ var VERSION = "0.13.7";
48451
48467
  export {
48452
48468
  SecureChannel,
48453
48469
  VERSION,
@@ -48456,7 +48472,6 @@ export {
48456
48472
  getActiveChannel,
48457
48473
  listAccountIds,
48458
48474
  resolveAccount,
48459
- sendAction,
48460
48475
  sendToOwner,
48461
48476
  setOcRuntime
48462
48477
  };