@haex-space/vault-sdk 5.0.0 → 5.2.0

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.
@@ -23,6 +23,10 @@ var NOTIFICATION_EVENTS = {
23
23
  /** A click on one of this extension's notifications (body or action button). */
24
24
  CLICK: "haextension:notification:click"
25
25
  };
26
+ var OPENER_EVENTS = {
27
+ /** A request waits for this extension: take it with `client.openers.take()`. The event carries no content. */
28
+ REQUEST: "opener-request"
29
+ };
26
30
  var MODEL_JOB_EVENTS = {
27
31
  /** A job of this frame ended: completed, failed or cancelled. */
28
32
  COMPLETED: "haextension:model-job:completed"
@@ -200,7 +204,9 @@ var EXTENSION_COMMANDS = {
200
204
  /** Ask the host to mark (or unmark) this extension's own tab as wanting attention */
201
205
  tabAttention: "extension_tab_attention",
202
206
  /** Ask the user to confirm, in a dialog the host draws over this extension's tab */
203
- dialogConfirm: "extension_dialog_confirm"
207
+ dialogConfirm: "extension_dialog_confirm",
208
+ /** Take the request the user gave this extension (holzi spec 063): `null` or `{ action, mail }` */
209
+ openerTake: "extension_opener_take"
204
210
  };
205
211
 
206
212
  // src/commands/remoteStorage.ts
@@ -2091,6 +2097,48 @@ var DialogAPI = class {
2091
2097
  }
2092
2098
  };
2093
2099
 
2100
+ // src/api/openers.ts
2101
+ var OpenersAPI = class {
2102
+ constructor(client) {
2103
+ this.client = client;
2104
+ }
2105
+ /**
2106
+ * Takes the request that waits for this extension, or `null` when none does (it expired after
2107
+ * 15 seconds, was taken already, or the extension did not register for the kind). Call it once when
2108
+ * the extension starts: a frame that the choice itself opened misses the event.
2109
+ */
2110
+ async take() {
2111
+ await this.client.ready();
2112
+ const request = await this.client.request(EXTENSION_COMMANDS.openerTake, {});
2113
+ return request ?? null;
2114
+ }
2115
+ /**
2116
+ * Calls `handler` with each request that arrives while the extension is open; the SDK takes it
2117
+ * for you. Errors while taking a request go to `onError`, or to the SDK console log when omitted.
2118
+ * Returns an unsubscribe function.
2119
+ */
2120
+ onRequest(handler, onError) {
2121
+ let active = true;
2122
+ const wrapped = () => {
2123
+ void this.take().then(
2124
+ (request) => {
2125
+ if (active && request) handler(request);
2126
+ },
2127
+ (error) => {
2128
+ if (!active) return;
2129
+ if (onError) onError(error);
2130
+ else console.error("[HaexVault SDK] Failed to take opener request:", error);
2131
+ }
2132
+ );
2133
+ };
2134
+ this.client.on(OPENER_EVENTS.REQUEST, wrapped);
2135
+ return () => {
2136
+ active = false;
2137
+ this.client.off(OPENER_EVENTS.REQUEST, wrapped);
2138
+ };
2139
+ }
2140
+ };
2141
+
2094
2142
  // src/api/tools/schema.ts
2095
2143
  function fail(field, message) {
2096
2144
  return { ok: false, field, message };
@@ -3047,6 +3095,7 @@ var HaexVaultSdk = class {
3047
3095
  this.notifications = new NotificationsAPI(this);
3048
3096
  this.tab = new TabAPI(this);
3049
3097
  this.dialog = new DialogAPI(this);
3098
+ this.openers = new OpenersAPI(this);
3050
3099
  this.tools = new ToolsAPI({
3051
3100
  manifest: () => this.config.manifest,
3052
3101
  send: (message) => this.sendMcpMessage(message)