@agentvault/agentvault 0.18.0 → 0.19.1

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.
Files changed (91) hide show
  1. package/README.md +10 -11
  2. package/dist/__tests__/crypto-helpers.test.d.ts +2 -0
  3. package/dist/__tests__/crypto-helpers.test.d.ts.map +1 -0
  4. package/dist/__tests__/functional.test.d.ts +21 -0
  5. package/dist/__tests__/functional.test.d.ts.map +1 -0
  6. package/dist/__tests__/multi-session.test.d.ts +2 -0
  7. package/dist/__tests__/multi-session.test.d.ts.map +1 -0
  8. package/dist/__tests__/state.test.d.ts +2 -0
  9. package/dist/__tests__/state.test.d.ts.map +1 -0
  10. package/dist/__tests__/transport.test.d.ts +2 -0
  11. package/dist/__tests__/transport.test.d.ts.map +1 -0
  12. package/dist/_cp.d.ts +10 -0
  13. package/dist/_cp.d.ts.map +1 -0
  14. package/dist/account-config.d.ts +20 -0
  15. package/dist/account-config.d.ts.map +1 -0
  16. package/dist/channel.d.ts +393 -0
  17. package/dist/channel.d.ts.map +1 -0
  18. package/dist/channel.js +2257 -0
  19. package/dist/channel.js.map +1 -0
  20. package/dist/cli.d.ts +2 -0
  21. package/dist/cli.d.ts.map +1 -0
  22. package/dist/cli.js +113 -1
  23. package/dist/cli.js.map +3 -3
  24. package/dist/create-agent.d.ts +28 -0
  25. package/dist/create-agent.d.ts.map +1 -0
  26. package/dist/credential-store.d.ts +62 -0
  27. package/dist/credential-store.d.ts.map +1 -0
  28. package/dist/crypto-helpers.d.ts +2 -0
  29. package/dist/crypto-helpers.d.ts.map +1 -0
  30. package/dist/crypto-helpers.js +4 -0
  31. package/dist/crypto-helpers.js.map +1 -0
  32. package/dist/doctor.d.ts +41 -0
  33. package/dist/doctor.d.ts.map +1 -0
  34. package/dist/fetch-interceptor.d.ts +32 -0
  35. package/dist/fetch-interceptor.d.ts.map +1 -0
  36. package/dist/gateway-send.d.ts +98 -0
  37. package/dist/gateway-send.d.ts.map +1 -0
  38. package/dist/http-handlers.d.ts +53 -0
  39. package/dist/http-handlers.d.ts.map +1 -0
  40. package/dist/index.d.ts +27 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +113 -1
  43. package/dist/index.js.map +2 -2
  44. package/dist/mcp-handlers.d.ts +26 -0
  45. package/dist/mcp-handlers.d.ts.map +1 -0
  46. package/dist/mcp-proxy-helpers.d.ts +9 -0
  47. package/dist/mcp-proxy-helpers.d.ts.map +1 -0
  48. package/dist/mcp-server.d.ts +90 -0
  49. package/dist/mcp-server.d.ts.map +1 -0
  50. package/dist/openclaw-compat.d.ts +33 -0
  51. package/dist/openclaw-compat.d.ts.map +1 -0
  52. package/dist/openclaw-entry.d.ts +27 -0
  53. package/dist/openclaw-entry.d.ts.map +1 -0
  54. package/dist/openclaw-entry.js +56 -8
  55. package/dist/openclaw-entry.js.map +2 -2
  56. package/dist/openclaw-plugin.d.ts +102 -0
  57. package/dist/openclaw-plugin.d.ts.map +1 -0
  58. package/dist/openclaw-plugin.js +222 -0
  59. package/dist/openclaw-plugin.js.map +1 -0
  60. package/dist/openclaw-types.d.ts +155 -0
  61. package/dist/openclaw-types.d.ts.map +1 -0
  62. package/dist/policy-enforcer.d.ts +78 -0
  63. package/dist/policy-enforcer.d.ts.map +1 -0
  64. package/dist/setup.d.ts +27 -0
  65. package/dist/setup.d.ts.map +1 -0
  66. package/dist/setup.js +329 -0
  67. package/dist/setup.js.map +1 -0
  68. package/dist/skill-invoker.d.ts +30 -0
  69. package/dist/skill-invoker.d.ts.map +1 -0
  70. package/dist/skill-manifest.d.ts +30 -0
  71. package/dist/skill-manifest.d.ts.map +1 -0
  72. package/dist/skill-telemetry.d.ts +36 -0
  73. package/dist/skill-telemetry.d.ts.map +1 -0
  74. package/dist/skills-publish.d.ts +8 -0
  75. package/dist/skills-publish.d.ts.map +1 -0
  76. package/dist/state.d.ts +32 -0
  77. package/dist/state.d.ts.map +1 -0
  78. package/dist/state.js +61 -0
  79. package/dist/state.js.map +1 -0
  80. package/dist/transport.d.ts +24 -0
  81. package/dist/transport.d.ts.map +1 -0
  82. package/dist/transport.js +43 -0
  83. package/dist/transport.js.map +1 -0
  84. package/dist/types.d.ts +417 -0
  85. package/dist/types.d.ts.map +1 -0
  86. package/dist/types.js +2 -0
  87. package/dist/types.js.map +1 -0
  88. package/dist/workspace-handlers.d.ts +62 -0
  89. package/dist/workspace-handlers.d.ts.map +1 -0
  90. package/openclaw.plugin.json +1 -1
  91. package/package.json +1 -1
@@ -0,0 +1,28 @@
1
+ /**
2
+ * AgentVault "create" command — spin up a brand new OpenClaw peer agent.
3
+ *
4
+ * Ports the logic from ~/.openclaw/workspace/scripts/create-agent.sh into
5
+ * TypeScript, eliminating the jq dependency.
6
+ *
7
+ * Usage: npx @agentvault/agentvault create <name> --token=av_tok_...
8
+ */
9
+ export interface CreateAgentOptions {
10
+ name: string;
11
+ token: string;
12
+ port?: number;
13
+ apiUrl: string;
14
+ force?: boolean;
15
+ }
16
+ /** Resolve the OpenClaw home directory (~/.openclaw) */
17
+ export declare function openclawHome(): string;
18
+ /** Parse openclaw.json and return its contents. */
19
+ export declare function readOpenClawConfig(home: string): any;
20
+ /**
21
+ * Scan all accounts in openclaw.json for httpPort values and return next free port.
22
+ * Minimum port is `startPort` (default 18790).
23
+ */
24
+ export declare function findNextPort(config: any, startPort?: number): number;
25
+ /** Generate workspace template files for a new agent. */
26
+ export declare function generateWorkspaceFiles(name: string): Record<string, string>;
27
+ export declare function runCreateCommand(options: CreateAgentOptions): Promise<void>;
28
+ //# sourceMappingURL=create-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-agent.d.ts","sourceRoot":"","sources":["../src/create-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAID,wDAAwD;AACxD,wBAAgB,YAAY,IAAI,MAAM,CAGrC;AAED,mDAAmD;AACnD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAIpD;AA4BD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,SAAQ,GAAG,MAAM,CAInE;AAOD,yDAAyD;AACzD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA8C3E;AAID,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqOjF"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * In-memory credential store for renter-provided credentials.
3
+ *
4
+ * Security design:
5
+ * - Never persisted to disk (agentvault.json or any file)
6
+ * - Scoped by room ID (each rental = one room)
7
+ * - Auto-purges on process exit (SIGINT, SIGTERM, exit)
8
+ * - Credential values stripped before any logging
9
+ * - Nonce tracking for replay prevention
10
+ */
11
+ export interface RenterCredential {
12
+ key: string;
13
+ value: string;
14
+ type: string;
15
+ scope: string;
16
+ grantedAt: string;
17
+ agreementId: string;
18
+ roomId: string;
19
+ }
20
+ /** Redacted view of a credential (for logging / context without values). */
21
+ export interface CredentialInfo {
22
+ key: string;
23
+ type: string;
24
+ scope: string;
25
+ grantedAt: string;
26
+ }
27
+ export declare class CredentialStore {
28
+ /** Map<roomId, Map<credentialKey, RenterCredential>> */
29
+ private _store;
30
+ /** Seen nonces for replay prevention — bounded per room */
31
+ private _seenNonces;
32
+ private static readonly MAX_NONCES_PER_ROOM;
33
+ constructor();
34
+ /**
35
+ * Check if a nonce has been seen (replay prevention).
36
+ * Returns true if the nonce is new (not a replay), false if seen before.
37
+ */
38
+ checkNonce(roomId: string, nonce: string): boolean;
39
+ /** Store a credential for a room. */
40
+ grant(roomId: string, credential: RenterCredential): void;
41
+ /** Revoke a specific credential. */
42
+ revoke(roomId: string, key: string): boolean;
43
+ /** Revoke all credentials for a room. */
44
+ revokeAll(roomId: string): void;
45
+ /** Get a credential value. */
46
+ get(roomId: string, key: string): RenterCredential | undefined;
47
+ /** Get all credentials for a room (values included — only for agent context injection). */
48
+ getAll(roomId: string): RenterCredential[];
49
+ /** Get credential info without values (safe for logging). */
50
+ getInfo(roomId: string): CredentialInfo[];
51
+ /** Check if a specific credential exists. */
52
+ has(roomId: string, key: string): boolean;
53
+ /** Get credential count for a room. */
54
+ count(roomId: string): number;
55
+ /** Purge all credentials for a room (rental end). */
56
+ purgeForRoom(roomId: string): void;
57
+ /** Purge everything (process exit). */
58
+ purgeAll(): void;
59
+ /** Get a map of credential key → value for context injection. */
60
+ getCredentialMap(roomId: string): Record<string, string>;
61
+ }
62
+ //# sourceMappingURL=credential-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-store.d.ts","sourceRoot":"","sources":["../src/credential-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,eAAe;IAC1B,wDAAwD;IACxD,OAAO,CAAC,MAAM,CAAoD;IAClE,2DAA2D;IAC3D,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAQ;;IAUnD;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAwBlD,qCAAqC;IACrC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,GAAG,IAAI;IASzD,oCAAoC;IACpC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAM5C,yCAAyC;IACzC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,8BAA8B;IAC9B,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAI9D,2FAA2F;IAC3F,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAM1C,6DAA6D;IAC7D,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE;IAWzC,6CAA6C;IAC7C,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzC,uCAAuC;IACvC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI7B,qDAAqD;IACrD,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKlC,uCAAuC;IACvC,QAAQ,IAAI,IAAI;IAKhB,iEAAiE;IACjE,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CASzD"}
@@ -0,0 +1,2 @@
1
+ export { hexToBytes, bytesToHex, base64ToBytes, bytesToBase64, encryptedMessageToTransport, transportToEncryptedMessage, encryptedMessageToTransportV2Full, type TransportMessage, type TransportMessageV2, SenderKeyChain, SenderKeyState, type SenderKeyDistribution, type SenderKeyMessage, } from "@agentvault/crypto";
2
+ //# sourceMappingURL=crypto-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-helpers.d.ts","sourceRoot":"","sources":["../src/crypto-helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,2BAA2B,EAC3B,2BAA2B,EAC3B,iCAAiC,EACjC,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,cAAc,EACd,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,GACtB,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,4 @@
1
+ // Re-export transport utilities from shared @agentvault/crypto package.
2
+ // Plugin code continues importing from ./crypto-helpers.js — no import changes needed.
3
+ export { hexToBytes, bytesToHex, base64ToBytes, bytesToBase64, encryptedMessageToTransport, transportToEncryptedMessage, } from "@agentvault/crypto";
4
+ //# sourceMappingURL=crypto-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-helpers.js","sourceRoot":"","sources":["../src/crypto-helpers.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,uFAAuF;AACvF,OAAO,EACL,UAAU,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,2BAA2B,EAC3B,2BAA2B,GAE5B,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * AgentVault "doctor" command — diagnostic checks and plist fixer.
3
+ *
4
+ * Detects stale macOS LaunchAgent plist paths (common after pnpm updates)
5
+ * and offers to install a stable wrapper script so future updates don't
6
+ * break the gateway.
7
+ *
8
+ * Usage: npx @agentvault/agentvault doctor [--fix]
9
+ */
10
+ export type CheckStatus = "pass" | "warn" | "fail" | "skip";
11
+ export interface CheckResult {
12
+ name: string;
13
+ status: CheckStatus;
14
+ message: string;
15
+ }
16
+ export interface PlistInfo {
17
+ plistPath: string;
18
+ programArgs: string[];
19
+ stalePaths: string[];
20
+ }
21
+ export interface PlistValidationResult {
22
+ status: "ok" | "stale" | "missing" | "skip" | "already-fixed";
23
+ plistPath?: string;
24
+ stalePaths?: string[];
25
+ }
26
+ export declare function checkOpenClawInstalled(): CheckResult;
27
+ export declare function checkConfigExists(home: string): CheckResult;
28
+ export declare function checkAgentVaultChannel(config: any): CheckResult;
29
+ export declare function checkPluginsAllow(config: any): CheckResult;
30
+ export declare function checkPlist(): CheckResult;
31
+ export declare function checkGatewayPort(): CheckResult;
32
+ export declare function checkAgentDataDirs(config: any): CheckResult;
33
+ export declare function checkPm2Status(): CheckResult;
34
+ export declare function plistPath(): string;
35
+ export declare function parsePlist(plistFile: string): PlistInfo | null;
36
+ export declare function validatePlist(): PlistValidationResult;
37
+ export declare function applyPlistFix(info: PlistInfo): boolean;
38
+ export declare function runDoctorCommand(options?: {
39
+ fix?: boolean;
40
+ }): Promise<void>;
41
+ //# sourceMappingURL=doctor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../src/doctor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAE5D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,IAAI,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,eAAe,CAAC;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAOD,wBAAgB,sBAAsB,IAAI,WAAW,CAYpD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAmB3D;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,GAAG,GAAG,WAAW,CAgB/D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,GAAG,GAAG,WAAW,CAoB1D;AAED,wBAAgB,UAAU,IAAI,WAAW,CAyBxC;AAED,wBAAgB,gBAAgB,IAAI,WAAW,CAW9C;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,GAAG,GAAG,WAAW,CAsC3D;AAED,wBAAgB,cAAc,IAAI,WAAW,CAoB5C;AAID,wBAAgB,SAAS,IAAI,MAAM,CAGlC;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CA2B9D;AAED,wBAAgB,aAAa,IAAI,qBAAqB,CA2BrD;AAID,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAsEtD;AAID,wBAAsB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAoGjF"}
@@ -0,0 +1,32 @@
1
+ export interface HttpCallReport {
2
+ method: string;
3
+ url: string;
4
+ statusCode: number;
5
+ latencyMs: number;
6
+ traceId?: string;
7
+ parentSpanId?: string;
8
+ }
9
+ export interface TraceContext {
10
+ traceId: string;
11
+ parentSpanId: string;
12
+ }
13
+ export interface FetchInterceptorOptions {
14
+ onHttpCall: (report: HttpCallReport) => void;
15
+ skipPatterns?: RegExp[];
16
+ }
17
+ /**
18
+ * Install HTTP interceptor using both undici diagnostics channels and
19
+ * globalThis.fetch monkey-patching. Idempotent.
20
+ */
21
+ export declare function installFetchInterceptor(opts: FetchInterceptorOptions): void;
22
+ /**
23
+ * Uninstall all interceptors. Safe to call even if not installed.
24
+ */
25
+ export declare function uninstallFetchInterceptor(): void;
26
+ /**
27
+ * Run an async function with trace context attached via AsyncLocalStorage.
28
+ * Any HTTP calls made within `fn` (via undici or fetch) will include
29
+ * traceId/parentSpanId in their HttpCallReport.
30
+ */
31
+ export declare function runWithTraceContext<T>(ctx: TraceContext, fn: () => T | Promise<T>): Promise<T>;
32
+ //# sourceMappingURL=fetch-interceptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-interceptor.d.ts","sourceRoot":"","sources":["../src/fetch-interceptor.ts"],"names":[],"mappings":"AAoBA,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAC7C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AA0CD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,uBAAuB,GAAG,IAAI,CAmK3E;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAkBhD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,GAAG,EAAE,YAAY,EACjB,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,CAAC,CAAC,CAEZ"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Gateway send helper — lets agents send messages to their owner
3
+ * via the plugin's local HTTP server (port 18790) or OpenClaw managed routes.
4
+ *
5
+ * Delivery path: sendToOwner() → plugin HTTP /send → SecureChannel.send()
6
+ * → Double Ratchet encrypt → WebSocket → backend → owner's app
7
+ */
8
+ export interface GatewaySendOptions {
9
+ /** Override the gateway port (default: env GATEWAY_SEND_PORT or 18790) */
10
+ port?: number;
11
+ /** Override the gateway host (default: 127.0.0.1) */
12
+ host?: string;
13
+ /** AbortSignal for cancellation */
14
+ signal?: AbortSignal;
15
+ }
16
+ export interface GatewaySendResult {
17
+ ok: boolean;
18
+ error?: string;
19
+ }
20
+ export interface GatewayStatusResult {
21
+ ok: boolean;
22
+ state?: string;
23
+ deviceId?: string;
24
+ sessions?: number;
25
+ error?: string;
26
+ }
27
+ /**
28
+ * Send a plaintext message to the agent's owner via the gateway HTTP server.
29
+ * Never throws — returns `{ ok: false, error }` on failure.
30
+ */
31
+ export declare function sendToOwner(text: string, options?: GatewaySendOptions): Promise<GatewaySendResult>;
32
+ /**
33
+ * Send a decision request to the agent's owner via the gateway HTTP server.
34
+ * Never throws — returns `{ ok: false, error }` on failure.
35
+ */
36
+ export declare function sendDecisionToOwner(request: {
37
+ title: string;
38
+ description?: string;
39
+ options: Array<{
40
+ option_id: string;
41
+ label: string;
42
+ risk_level?: string;
43
+ is_default?: boolean;
44
+ }>;
45
+ context_refs?: Array<{
46
+ type: string;
47
+ uri: string;
48
+ label: string;
49
+ }>;
50
+ deadline?: string;
51
+ auto_action?: {
52
+ option_id: string;
53
+ trigger: string;
54
+ description?: string;
55
+ };
56
+ }, options?: GatewaySendOptions): Promise<GatewaySendResult & {
57
+ decision_id?: string;
58
+ }>;
59
+ /**
60
+ * Send a plaintext message to a specific room via the gateway HTTP server.
61
+ * Never throws — returns `{ ok: false, error }` on failure.
62
+ */
63
+ export declare function sendToRoom(roomId: string, text: string, options?: GatewaySendOptions): Promise<GatewaySendResult>;
64
+ /**
65
+ * Send a plaintext message to any target via the gateway HTTP server.
66
+ * Accepts target strings: "owner", "room:<id>", "a2a:<addr>", "context".
67
+ * Never throws — returns `{ ok: false, error }` on failure.
68
+ */
69
+ export declare function sendToTarget(target: string, text: string, options?: GatewaySendOptions): Promise<GatewaySendResult & {
70
+ destination?: {
71
+ kind: string;
72
+ id?: string;
73
+ };
74
+ }>;
75
+ /**
76
+ * Discover available delivery targets from the gateway.
77
+ * Never throws — returns `{ ok: false, error }` on failure.
78
+ */
79
+ export declare function listTargets(options?: GatewaySendOptions): Promise<{
80
+ ok: boolean;
81
+ targets?: Array<{
82
+ kind: string;
83
+ id: string;
84
+ label: string;
85
+ available: boolean;
86
+ }>;
87
+ context?: {
88
+ kind: string;
89
+ roomId?: string;
90
+ };
91
+ error?: string;
92
+ }>;
93
+ /**
94
+ * Check gateway health / status.
95
+ * Never throws — returns `{ ok: false, error }` on failure.
96
+ */
97
+ export declare function checkGateway(options?: GatewaySendOptions): Promise<GatewayStatusResult>;
98
+ //# sourceMappingURL=gateway-send.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway-send.d.ts","sourceRoot":"","sources":["../src/gateway-send.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,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;AA4BD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,iBAAiB,CAAC,CA4B5B;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE;IACP,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAChG,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5E,EACD,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,iBAAiB,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA8BvD;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,iBAAiB,CAAC,CA8B5B;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,iBAAiB,GAAG;IAAE,WAAW,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC,CA0C9E;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAmBzK;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CAoB9B"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Extracted HTTP handler logic for the AgentVault plugin.
3
+ *
4
+ * These handlers are shared between:
5
+ * 1. The self-managed HTTP server in channel.ts (legacy/fallback path)
6
+ * 2. OpenClaw's registerHttpRoute() managed routes (new path)
7
+ *
8
+ * Both entry points call the same handler functions, ensuring consistent
9
+ * behavior regardless of how the route is served.
10
+ */
11
+ import type { SecureChannel } from "./channel.js";
12
+ export interface HandlerResult {
13
+ status: number;
14
+ body: Record<string, unknown>;
15
+ }
16
+ /**
17
+ * Handle POST /send — send a message (text, file, or room).
18
+ *
19
+ * Routing: explicit target fields only — no silent lastInboundRoomId fallback.
20
+ * - hub_address / a2a_address / channel_id → A2A
21
+ * - room_id → room
22
+ * - target: "context" → resolve from lastInboundRoomId (opt-in)
23
+ * - No target fields → owner (the breaking fix)
24
+ */
25
+ export declare function handleSendRequest(parsed: Record<string, unknown>, channel: SecureChannel): Promise<HandlerResult>;
26
+ /**
27
+ * Handle POST /action — send an action confirmation.
28
+ */
29
+ export declare function handleActionRequest(parsed: Record<string, unknown>, channel: SecureChannel): Promise<HandlerResult>;
30
+ /**
31
+ * Handle POST /decision — send a decision request to the owner.
32
+ */
33
+ export declare function handleDecisionRequest(parsed: Record<string, unknown>, channel: SecureChannel): Promise<HandlerResult>;
34
+ /**
35
+ * Handle GET /status — return channel health info.
36
+ */
37
+ export declare function handleStatusRequest(channel: SecureChannel): HandlerResult;
38
+ /**
39
+ * Handle GET /targets — return available delivery destinations.
40
+ */
41
+ export declare function handleTargetsRequest(channel: SecureChannel): HandlerResult;
42
+ /**
43
+ * Handle GET /trust — return the agent's current Trust Gate token state.
44
+ */
45
+ export declare function handleTrustRequest(channel: SecureChannel): HandlerResult;
46
+ /**
47
+ * Handle GET /mcp-config — return MCP connection config for this agent.
48
+ *
49
+ * Returns JSON suitable for adding to Claude Code, Cursor, or other MCP host
50
+ * configuration files.
51
+ */
52
+ export declare function handleMcpConfigRequest(agentName: string, port: number, mcpSkillCount: number): HandlerResult;
53
+ //# sourceMappingURL=http-handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-handlers.d.ts","sourceRoot":"","sources":["../src/http-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,aAAa,CAAC,CAqExB;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,aAAa,CAAC,CAmCxB;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,aAAa,CAAC,CA8BxB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAUzE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAW1E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,aAAa,GACrB,aAAa,CAiBf;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,GACpB,aAAa,CAkBf"}
@@ -0,0 +1,27 @@
1
+ export { SecureChannel } from "./channel.js";
2
+ export type { SecureChannelConfig, ChannelState, MessageMetadata, AttachmentData, PersistedState, LegacyPersistedState, DeviceSession, HistoryEntry, SendOptions, DecisionOption, DecisionRequest, DecisionResponse, ContextRef, HeartbeatStatus, StatusAlert, RoomInfo, RoomMemberInfo, RoomConversationInfo, RoomState, A2AChannel, A2AMessage, RoomParticipantEvent, DeliveryTarget, DeliveryContent, DeliveryOptions, DeliveryReceipt, TargetInfo, ActionConfirmation, ArtifactPayload, PolicyAlert, ApprovalRequest, ApprovalResponse, CredentialGrantPayload, CredentialRevokePayload, CredentialAckPayload, CredentialRequestPayload, } from "./types.js";
3
+ export { parseTarget } from "./types.js";
4
+ export { CredentialStore } from "./credential-store.js";
5
+ export type { RenterCredential, CredentialInfo } from "./credential-store.js";
6
+ export { listAccountIds, resolveAccount } from "./account-config.js";
7
+ export type { ResolvedAccount } from "./account-config.js";
8
+ export { agentVaultPlugin, setOcRuntime, getActiveChannel } from "./openclaw-plugin.js";
9
+ export { sendToOwner, sendToRoom, sendToTarget, listTargets, sendDecisionToOwner, checkGateway } from "./gateway-send.js";
10
+ export type { GatewaySendOptions, GatewaySendResult, GatewayStatusResult, } from "./gateway-send.js";
11
+ export { requestHeartbeatNow, onAgentEvent, onSessionTranscriptUpdate } from "./openclaw-compat.js";
12
+ export { isUsingManagedRoutes } from "./openclaw-entry.js";
13
+ export { handleSendRequest, handleActionRequest, handleDecisionRequest, handleStatusRequest, handleTargetsRequest } from "./http-handlers.js";
14
+ export type { HandlerResult } from "./http-handlers.js";
15
+ export { AgentVaultMcpServer } from "./mcp-server.js";
16
+ export type { SkillDefinition, McpServerOpts } from "./mcp-server.js";
17
+ export { createMcpHandler, getMcpStatus } from "./mcp-handlers.js";
18
+ export { parseSkillMd, loadSkillsFromDirectory, loadSkillsFromApi, mergeSkills } from "./skill-manifest.js";
19
+ export type { SkillManifest } from "./skill-manifest.js";
20
+ export { invokeSkill } from "./skill-invoker.js";
21
+ export type { InvocationResult, InvocationOpts } from "./skill-invoker.js";
22
+ export { wrapSkillExecution, reportSkillInvocation, drainSkillSpans } from "./skill-telemetry.js";
23
+ export { PolicyEnforcer } from "./policy-enforcer.js";
24
+ export type { PolicyContext, PolicyResult, PolicyViolation, PolicyMetrics } from "./policy-enforcer.js";
25
+ export type { OpenClawPluginApi, PluginRuntime, ChannelGatewayContext, ChannelOutboundPayloadContext, ReplyPayload, MessageSentEvent, SessionStartEvent, SessionEndEvent, AgentEventPayload, TranscriptUpdatePayload, } from "./openclaw-types.js";
26
+ export declare const VERSION = "0.14.1";
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,EACpB,cAAc,EACd,eAAe,EACf,eAAe,EACf,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG9E,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,WAAW,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC1H,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC9I,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGtE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGnE,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC5G,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAG3E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGlG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGxG,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,6BAA6B,EAC7B,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,OAAO,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -46658,7 +46658,8 @@ __export(http_handlers_exports, {
46658
46658
  handleMcpConfigRequest: () => handleMcpConfigRequest,
46659
46659
  handleSendRequest: () => handleSendRequest,
46660
46660
  handleStatusRequest: () => handleStatusRequest,
46661
- handleTargetsRequest: () => handleTargetsRequest
46661
+ handleTargetsRequest: () => handleTargetsRequest,
46662
+ handleTrustRequest: () => handleTrustRequest
46662
46663
  });
46663
46664
  async function handleSendRequest(parsed, channel) {
46664
46665
  const text = parsed.text;
@@ -46797,6 +46798,24 @@ function handleTargetsRequest(channel) {
46797
46798
  }
46798
46799
  };
46799
46800
  }
46801
+ function handleTrustRequest(channel) {
46802
+ const token = channel.trustToken;
46803
+ if (!token) {
46804
+ return {
46805
+ status: 503,
46806
+ body: { ok: false, error: "token_unavailable" }
46807
+ };
46808
+ }
46809
+ return {
46810
+ status: 200,
46811
+ body: {
46812
+ ok: true,
46813
+ tier: channel.trustTier,
46814
+ composite: null,
46815
+ token_expires_at: channel.trustTokenExpiresAt
46816
+ }
46817
+ };
46818
+ }
46800
46819
  function handleMcpConfigRequest(agentName, port, mcpSkillCount) {
46801
46820
  return {
46802
46821
  status: 200,
@@ -47109,6 +47128,10 @@ var init_channel = __esm({
47109
47128
  _heartbeatIntervalSeconds = 0;
47110
47129
  _wakeDetectorTimer = null;
47111
47130
  _lastWakeTick = Date.now();
47131
+ _trustToken = null;
47132
+ _trustTier = null;
47133
+ _trustTokenExpiresAt = null;
47134
+ _trustTokenInterval = null;
47112
47135
  _pendingPollTimer = null;
47113
47136
  _syncMessageIds = null;
47114
47137
  /** Sender Key chains — own chain per room for O(1) encryption */
@@ -47122,6 +47145,9 @@ var init_channel = __esm({
47122
47145
  /** Dedup buffer for A2A message IDs (prevents double-delivery via direct + Redis) */
47123
47146
  _a2aSeenMessageIds = /* @__PURE__ */ new Set();
47124
47147
  static A2A_SEEN_MAX = 500;
47148
+ /** Dedup buffer for regular message IDs (prevents double-decrypt via direct WS + Redis pub/sub) */
47149
+ _seenMessageIds = /* @__PURE__ */ new Set();
47150
+ static SEEN_MSG_MAX = 500;
47125
47151
  _scanEngine = null;
47126
47152
  _scanRuleSetVersion = 0;
47127
47153
  _telemetryReporter = null;
@@ -48051,9 +48077,56 @@ var init_channel = __esm({
48051
48077
  this.emit("error", new Error(`Heartbeat send failed: ${err}`));
48052
48078
  });
48053
48079
  }
48080
+ // --- Trust Gate token management ---
48081
+ getTrustHeaders() {
48082
+ if (!this._trustToken) return {};
48083
+ return { "AgentVault-Trust": this._trustToken };
48084
+ }
48085
+ get trustToken() {
48086
+ return this._trustToken;
48087
+ }
48088
+ get trustTier() {
48089
+ return this._trustTier;
48090
+ }
48091
+ get trustTokenExpiresAt() {
48092
+ return this._trustTokenExpiresAt;
48093
+ }
48094
+ async refreshTrustToken() {
48095
+ try {
48096
+ const res = await fetch(`${this.config.apiUrl}/api/v1/gate/token`, {
48097
+ method: "POST",
48098
+ headers: {
48099
+ Authorization: `Bearer ${this._deviceJwt}`,
48100
+ "Content-Type": "application/json"
48101
+ }
48102
+ });
48103
+ if (res.ok) {
48104
+ const data = await res.json();
48105
+ this._trustToken = data.token;
48106
+ this._trustTier = data.tier;
48107
+ this._trustTokenExpiresAt = data.expires_at;
48108
+ }
48109
+ } catch (err) {
48110
+ console.warn("[AgentVault] Trust token refresh failed:", err);
48111
+ }
48112
+ }
48113
+ startTrustTokenRefresh() {
48114
+ this.refreshTrustToken();
48115
+ this._trustTokenInterval = setInterval(
48116
+ () => this.refreshTrustToken(),
48117
+ 12 * 60 * 1e3
48118
+ );
48119
+ }
48120
+ stopTrustTokenRefresh() {
48121
+ if (this._trustTokenInterval) {
48122
+ clearInterval(this._trustTokenInterval);
48123
+ this._trustTokenInterval = null;
48124
+ }
48125
+ }
48054
48126
  async stop() {
48055
48127
  this._stopped = true;
48056
48128
  await this.stopHeartbeat();
48129
+ this.stopTrustTokenRefresh();
48057
48130
  this._flushAcks();
48058
48131
  this._stopPing();
48059
48132
  this._stopWakeDetector();
@@ -48169,6 +48242,10 @@ var init_channel = __esm({
48169
48242
  res.end(JSON.stringify({ ok: false, error: "Internal MCP error" }));
48170
48243
  }
48171
48244
  });
48245
+ } else if (req.method === "GET" && req.url === "/trust") {
48246
+ const result = handlers.handleTrustRequest(this);
48247
+ res.writeHead(result.status, { "Content-Type": "application/json" });
48248
+ res.end(JSON.stringify(result.body));
48172
48249
  } else if (req.method === "GET" && req.url === "/mcp-config") {
48173
48250
  const agentName = this.config.agentName ?? "agent";
48174
48251
  const mcpSkillCount = this._mcpServer?.skillCount ?? 0;
@@ -48675,6 +48752,7 @@ var init_channel = __esm({
48675
48752
  });
48676
48753
  this._telemetryReporter.startAutoFlush(3e4);
48677
48754
  }
48755
+ this.startTrustTokenRefresh();
48678
48756
  this.emit("ready");
48679
48757
  } catch (openErr) {
48680
48758
  console.error("[SecureChannel] Error in WS open handler:", openErr);
@@ -48707,6 +48785,17 @@ var init_channel = __esm({
48707
48785
  return;
48708
48786
  }
48709
48787
  if (data.event === "message") {
48788
+ const inMsgId = data.data?.message_id;
48789
+ if (inMsgId && this._seenMessageIds.has(inMsgId)) {
48790
+ return;
48791
+ }
48792
+ if (inMsgId) {
48793
+ this._seenMessageIds.add(inMsgId);
48794
+ if (this._seenMessageIds.size > _SecureChannel.SEEN_MSG_MAX) {
48795
+ const first = this._seenMessageIds.values().next().value;
48796
+ if (first) this._seenMessageIds.delete(first);
48797
+ }
48798
+ }
48710
48799
  try {
48711
48800
  await this._handleIncomingMessage(data.data);
48712
48801
  } catch (msgErr) {
@@ -48737,6 +48826,17 @@ var init_channel = __esm({
48737
48826
  }).catch((err) => this.emit("error", err));
48738
48827
  }
48739
48828
  if (data.event === "room_message") {
48829
+ const rmMsgId = data.data?.message_id;
48830
+ if (rmMsgId && this._seenMessageIds.has(rmMsgId)) {
48831
+ return;
48832
+ }
48833
+ if (rmMsgId) {
48834
+ this._seenMessageIds.add(rmMsgId);
48835
+ if (this._seenMessageIds.size > _SecureChannel.SEEN_MSG_MAX) {
48836
+ const first = this._seenMessageIds.values().next().value;
48837
+ if (first) this._seenMessageIds.delete(first);
48838
+ }
48839
+ }
48740
48840
  try {
48741
48841
  await this._handleRoomMessage(data.data);
48742
48842
  } catch (rmErr) {
@@ -49271,6 +49371,10 @@ var init_channel = __esm({
49271
49371
  if (!session.activated) {
49272
49372
  session.activated = true;
49273
49373
  console.log(`[SecureChannel] Session ${convId.slice(0, 8)}... activated by first owner message`);
49374
+ if (this._persisted?.sessions[convId]) {
49375
+ this._persisted.sessions[convId].activated = true;
49376
+ }
49377
+ await this._persistState();
49274
49378
  }
49275
49379
  let messageText;
49276
49380
  let messageType;
@@ -49885,6 +49989,14 @@ ${messageText}`;
49885
49989
  `[SecureChannel] Room ratchet re-initialized for conv ${convId.slice(0, 8)}...`
49886
49990
  );
49887
49991
  plaintext = session.ratchet.decrypt(encrypted);
49992
+ session.activated = true;
49993
+ if (this._persisted.sessions[convId]) {
49994
+ this._persisted.sessions[convId].activated = true;
49995
+ }
49996
+ await this._persistState();
49997
+ console.log(
49998
+ `[SecureChannel] Room session ${convId.slice(0, 8)}... re-activated after ratchet re-init`
49999
+ );
49888
50000
  } catch (reinitErr) {
49889
50001
  console.error(
49890
50002
  `[SecureChannel] Room ratchet re-init failed for conv ${convId.slice(0, 8)}...:`,