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