@agentvault/secure-channel 0.6.19 → 0.6.20
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/channel.d.ts +15 -1
- package/dist/channel.d.ts.map +1 -1
- package/dist/cli.js +65 -0
- package/dist/cli.js.map +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +65 -0
- package/dist/index.js.map +3 -3
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/channel.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
|
-
import type { SecureChannelConfig, ChannelState, SendOptions } from "./types.js";
|
|
2
|
+
import type { SecureChannelConfig, ChannelState, SendOptions, DecisionRequest, DecisionResponse } from "./types.js";
|
|
3
3
|
export declare class SecureChannel extends EventEmitter {
|
|
4
4
|
private config;
|
|
5
5
|
private _state;
|
|
@@ -50,6 +50,20 @@ export declare class SecureChannel extends EventEmitter {
|
|
|
50
50
|
* Ephemeral (unencrypted metadata), no ratchet advancement.
|
|
51
51
|
*/
|
|
52
52
|
sendTyping(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Send a decision request to the owner.
|
|
55
|
+
* Builds a structured envelope with decision metadata and sends it
|
|
56
|
+
* as a high-priority message. Returns the generated decision_id.
|
|
57
|
+
*/
|
|
58
|
+
sendDecisionRequest(request: DecisionRequest): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Wait for a decision response matching the given decisionId.
|
|
61
|
+
* Listens on the "message" event for messages where
|
|
62
|
+
* metadata.messageType === "decision_response" and the parsed plaintext
|
|
63
|
+
* contains a matching decision.decision_id.
|
|
64
|
+
* Optional timeout rejects with an Error.
|
|
65
|
+
*/
|
|
66
|
+
waitForDecision(decisionId: string, timeoutMs?: number): Promise<DecisionResponse>;
|
|
53
67
|
stop(): Promise<void>;
|
|
54
68
|
startHttpServer(port: number): void;
|
|
55
69
|
private _stopHttpServer;
|
package/dist/channel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAoB3C,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EAMZ,WAAW,
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAoB3C,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EAMZ,WAAW,EACX,eAAe,EACf,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAmDpB,qBAAa,aAAc,SAAQ,YAAY;IA+BjC,OAAO,CAAC,MAAM;IA9B1B,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,sBAAsB,CAAc;IAC5C,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,SAAS,CAGH;IACd,OAAO,CAAC,GAAG,CAA0B;IACrC,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,eAAe,CAA8C;IACrE,OAAO,CAAC,UAAU,CAA+C;IACjE,OAAO,CAAC,kBAAkB,CAAK;IAC/B,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,kBAAkB,CAA+C;IACzE,OAAO,CAAC,eAAe,CAA4B;IAInD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAU;IAClD,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C1F;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;YAiCtE,OAAO;IAgDrB,OAAO,CAAC,KAAK;YAsCC,SAAS;IAyIvB,OAAO,CAAC,QAAQ;IAgFhB;;;;OAIG;YACW,sBAAsB;IAsJpC;;;OAGG;YACW,6BAA6B;IA6C3C;;;OAGG;YACW,iBAAiB;IAwD/B;;;OAGG;IACG,kBAAkB,CACtB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAC7B,OAAO,CAAC,IAAI,CAAC;IA8ChB;;;OAGG;YACW,oBAAoB;IAqClC;;;OAGG;YACW,uBAAuB;IAkCrC;;;;OAIG;YACW,mBAAmB;IAkEjC;;;OAGG;IACH;;;OAGG;YACW,mBAAmB;IA8GjC,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,UAAU;YAMJ,mBAAmB;IAmCjC,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,kBAAkB;IAoB1B,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,kBAAkB;IAiH1B,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,YAAY;IAKpB;;;OAGG;YACW,aAAa;CAc5B"}
|
package/dist/cli.js
CHANGED
|
@@ -45345,6 +45345,71 @@ var init_channel = __esm({
|
|
|
45345
45345
|
);
|
|
45346
45346
|
}
|
|
45347
45347
|
}
|
|
45348
|
+
/**
|
|
45349
|
+
* Send a decision request to the owner.
|
|
45350
|
+
* Builds a structured envelope with decision metadata and sends it
|
|
45351
|
+
* as a high-priority message. Returns the generated decision_id.
|
|
45352
|
+
*/
|
|
45353
|
+
async sendDecisionRequest(request) {
|
|
45354
|
+
const decision_id = `dec_${randomUUID().replace(/-/g, "").slice(0, 16)}`;
|
|
45355
|
+
const payload = JSON.stringify({
|
|
45356
|
+
type: "message",
|
|
45357
|
+
text: `\u{1F4CB} ${request.title}`,
|
|
45358
|
+
decision: {
|
|
45359
|
+
decision_id,
|
|
45360
|
+
...request
|
|
45361
|
+
}
|
|
45362
|
+
});
|
|
45363
|
+
await this.send(payload, {
|
|
45364
|
+
messageType: "decision_request",
|
|
45365
|
+
priority: "high",
|
|
45366
|
+
metadata: {
|
|
45367
|
+
decision_id,
|
|
45368
|
+
title: request.title,
|
|
45369
|
+
description: request.description,
|
|
45370
|
+
options: request.options,
|
|
45371
|
+
context_refs: request.context_refs,
|
|
45372
|
+
deadline: request.deadline,
|
|
45373
|
+
auto_action: request.auto_action
|
|
45374
|
+
}
|
|
45375
|
+
});
|
|
45376
|
+
return decision_id;
|
|
45377
|
+
}
|
|
45378
|
+
/**
|
|
45379
|
+
* Wait for a decision response matching the given decisionId.
|
|
45380
|
+
* Listens on the "message" event for messages where
|
|
45381
|
+
* metadata.messageType === "decision_response" and the parsed plaintext
|
|
45382
|
+
* contains a matching decision.decision_id.
|
|
45383
|
+
* Optional timeout rejects with an Error.
|
|
45384
|
+
*/
|
|
45385
|
+
waitForDecision(decisionId, timeoutMs) {
|
|
45386
|
+
return new Promise((resolve3, reject) => {
|
|
45387
|
+
let timer = null;
|
|
45388
|
+
const handler = (plaintext, metadata) => {
|
|
45389
|
+
if (metadata.messageType !== "decision_response") return;
|
|
45390
|
+
try {
|
|
45391
|
+
const parsed = JSON.parse(plaintext);
|
|
45392
|
+
if (parsed.decision?.decision_id === decisionId) {
|
|
45393
|
+
if (timer) clearTimeout(timer);
|
|
45394
|
+
this.removeListener("message", handler);
|
|
45395
|
+
resolve3({
|
|
45396
|
+
decision_id: parsed.decision.decision_id,
|
|
45397
|
+
selected_option_id: parsed.decision.selected_option_id,
|
|
45398
|
+
resolved_at: parsed.decision.resolved_at
|
|
45399
|
+
});
|
|
45400
|
+
}
|
|
45401
|
+
} catch {
|
|
45402
|
+
}
|
|
45403
|
+
};
|
|
45404
|
+
this.on("message", handler);
|
|
45405
|
+
if (timeoutMs !== void 0) {
|
|
45406
|
+
timer = setTimeout(() => {
|
|
45407
|
+
this.removeListener("message", handler);
|
|
45408
|
+
reject(new Error(`Decision ${decisionId} timed out after ${timeoutMs}ms`));
|
|
45409
|
+
}, timeoutMs);
|
|
45410
|
+
}
|
|
45411
|
+
});
|
|
45412
|
+
}
|
|
45348
45413
|
async stop() {
|
|
45349
45414
|
this._stopped = true;
|
|
45350
45415
|
this._flushAcks();
|