@haex-space/vault-sdk 4.5.0 → 4.6.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.
- package/README.md +40 -0
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{client-Dw2uH1EM.d.ts → client-CcNhK76M.d.mts} +131 -2
- package/dist/{client-D4VYF0bP.d.mts → client-DIvNHfx-.d.ts} +131 -2
- package/dist/{config-D_HXjsEV.d.mts → config-P_6DqTHl.d.mts} +2 -1
- package/dist/{config-D_HXjsEV.d.ts → config-P_6DqTHl.d.ts} +2 -1
- package/dist/index.d.mts +32 -7
- package/dist/index.d.ts +32 -7
- package/dist/index.js +98 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -5
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.mts +4 -3
- package/dist/node.d.ts +4 -3
- package/dist/node.mjs +1 -1
- package/dist/node.mjs.map +1 -1
- package/dist/nuxt.d.mts +2 -1
- package/dist/nuxt.d.ts +2 -1
- package/dist/nuxt.js +1 -1
- package/dist/nuxt.js.map +1 -1
- package/dist/react.d.mts +3 -2
- package/dist/react.d.ts +3 -2
- package/dist/react.js +94 -5
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +93 -4
- package/dist/react.mjs.map +1 -1
- package/dist/runtime/nuxt.plugin.client.d.mts +4 -3
- package/dist/runtime/nuxt.plugin.client.d.ts +4 -3
- package/dist/runtime/nuxt.plugin.client.js +83 -1
- package/dist/runtime/nuxt.plugin.client.js.map +1 -1
- package/dist/runtime/nuxt.plugin.client.mjs +83 -1
- package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
- package/dist/svelte.d.mts +3 -2
- package/dist/svelte.d.ts +3 -2
- package/dist/svelte.js +94 -5
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +93 -4
- package/dist/svelte.mjs.map +1 -1
- package/dist/{types-CYuW3glJ.d.mts → types-snPkjDCj.d.mts} +10 -1
- package/dist/{types-CYuW3glJ.d.ts → types-snPkjDCj.d.ts} +10 -1
- package/dist/vite.d.mts +2 -1
- package/dist/vite.d.ts +2 -1
- package/dist/vue.d.mts +3 -2
- package/dist/vue.d.ts +3 -2
- package/dist/vue.js +94 -5
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +93 -4
- package/dist/vue.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -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 MODEL_JOB_EVENTS = {
|
|
27
|
+
/** A job of this frame ended: completed, failed or cancelled. */
|
|
28
|
+
COMPLETED: "haextension:model-job:completed"
|
|
29
|
+
};
|
|
26
30
|
var EXTERNAL_EVENTS = {
|
|
27
31
|
/** External request from authorized client */
|
|
28
32
|
REQUEST: "haextension:external:request",
|
|
@@ -326,6 +330,16 @@ var CONTACT_COMMANDS = {
|
|
|
326
330
|
photo: "extension_contacts_photo"
|
|
327
331
|
};
|
|
328
332
|
|
|
333
|
+
// src/commands/models.ts
|
|
334
|
+
var MODEL_COMMANDS = {
|
|
335
|
+
/** The models the user allowed to this extension, without addresses or keys */
|
|
336
|
+
list: "extension_model_list",
|
|
337
|
+
/** Starts a job; the result follows as an event */
|
|
338
|
+
start: "extension_model_job_start",
|
|
339
|
+
/** Cancels a running job of this frame */
|
|
340
|
+
cancel: "extension_model_job_cancel"
|
|
341
|
+
};
|
|
342
|
+
|
|
329
343
|
// src/commands/mail.ts
|
|
330
344
|
var MAIL_COMMANDS = {
|
|
331
345
|
/** LIST mailboxes + optional STATUS counts */
|
|
@@ -1535,6 +1549,68 @@ var ContactsAPI = class {
|
|
|
1535
1549
|
}
|
|
1536
1550
|
};
|
|
1537
1551
|
|
|
1552
|
+
// src/api/models.ts
|
|
1553
|
+
var ModelsAPI = class {
|
|
1554
|
+
constructor(client) {
|
|
1555
|
+
this.client = client;
|
|
1556
|
+
}
|
|
1557
|
+
/** The models the user allowed to this extension; empty without any. */
|
|
1558
|
+
async listAsync() {
|
|
1559
|
+
const answer = await this.client.request(
|
|
1560
|
+
MODEL_COMMANDS.list,
|
|
1561
|
+
{}
|
|
1562
|
+
);
|
|
1563
|
+
return answer.models;
|
|
1564
|
+
}
|
|
1565
|
+
/** Starts a job; its end comes as {@link onCompleted}. Use {@link runAsync} to await it. */
|
|
1566
|
+
async startAsync(job) {
|
|
1567
|
+
const answer = await this.client.request(MODEL_COMMANDS.start, {
|
|
1568
|
+
job
|
|
1569
|
+
});
|
|
1570
|
+
return { jobId: answer.jobId };
|
|
1571
|
+
}
|
|
1572
|
+
/** Cancels a running job of this frame; `false` when it is unknown or already ended. */
|
|
1573
|
+
async cancelAsync(jobId) {
|
|
1574
|
+
const answer = await this.client.request(MODEL_COMMANDS.cancel, {
|
|
1575
|
+
jobId
|
|
1576
|
+
});
|
|
1577
|
+
return answer.cancelled;
|
|
1578
|
+
}
|
|
1579
|
+
/** Listens for the end of this frame's jobs. Returns an unsubscribe function. */
|
|
1580
|
+
onCompleted(handler) {
|
|
1581
|
+
const wrapped = (event) => {
|
|
1582
|
+
const data = event.data;
|
|
1583
|
+
if (data) handler(data);
|
|
1584
|
+
};
|
|
1585
|
+
this.client.on(MODEL_JOB_EVENTS.COMPLETED, wrapped);
|
|
1586
|
+
return () => this.client.off(MODEL_JOB_EVENTS.COMPLETED, wrapped);
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Starts a job and resolves with its end: `completed` with the result, or `failed` or
|
|
1590
|
+
* `cancelled` with the error. Errors of the start itself (an invalid job, a refused model or
|
|
1591
|
+
* consent, no fitting model) reject. The end can arrive before the start answers; it is kept
|
|
1592
|
+
* until then.
|
|
1593
|
+
*/
|
|
1594
|
+
async runAsync(job) {
|
|
1595
|
+
const ended = /* @__PURE__ */ new Map();
|
|
1596
|
+
let waiting = null;
|
|
1597
|
+
const unsubscribe = this.onCompleted((completion) => {
|
|
1598
|
+
if (waiting && completion.jobId === waiting.jobId) waiting.resolve(completion);
|
|
1599
|
+
else ended.set(completion.jobId, completion);
|
|
1600
|
+
});
|
|
1601
|
+
try {
|
|
1602
|
+
const { jobId } = await this.startAsync(job);
|
|
1603
|
+
return await new Promise((resolve) => {
|
|
1604
|
+
const early = ended.get(jobId);
|
|
1605
|
+
if (early) resolve(early);
|
|
1606
|
+
else waiting = { jobId, resolve };
|
|
1607
|
+
});
|
|
1608
|
+
} finally {
|
|
1609
|
+
unsubscribe();
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1538
1614
|
// src/api/mail.ts
|
|
1539
1615
|
var MailAPI = class {
|
|
1540
1616
|
constructor(client) {
|
|
@@ -2568,6 +2644,7 @@ var AI_COMMANDS = {
|
|
|
2568
2644
|
// src/client/permissionRetry.ts
|
|
2569
2645
|
var PERMISSION_DECISION_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
2570
2646
|
var MAX_PERMISSION_RETRIES = 3;
|
|
2647
|
+
var MAX_PERMISSION_PROMPTS = 8;
|
|
2571
2648
|
function permissionKey(resourceType, action, target) {
|
|
2572
2649
|
return `${resourceType}:${action}:${target}`;
|
|
2573
2650
|
}
|
|
@@ -2603,14 +2680,18 @@ function toDeniedError(error) {
|
|
|
2603
2680
|
return { ...error, code: 1002 /* DENIED */ };
|
|
2604
2681
|
}
|
|
2605
2682
|
async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_DECISION_TIMEOUT_MS) {
|
|
2683
|
+
const asked = /* @__PURE__ */ new Map();
|
|
2606
2684
|
for (let attempt = 0; ; attempt++) {
|
|
2607
2685
|
try {
|
|
2608
2686
|
return await send();
|
|
2609
2687
|
} catch (error) {
|
|
2610
|
-
if (!isPermissionPromptError(error) || attempt >=
|
|
2688
|
+
if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
|
|
2611
2689
|
throw error;
|
|
2612
2690
|
}
|
|
2613
2691
|
const key = permissionKey(error.resourceType, error.action, error.target);
|
|
2692
|
+
const times = asked.get(key) ?? 0;
|
|
2693
|
+
if (times >= MAX_PERMISSION_RETRIES) throw error;
|
|
2694
|
+
asked.set(key, times + 1);
|
|
2614
2695
|
log(`Permission prompt required for ${key} \u2014 waiting for user decision`);
|
|
2615
2696
|
const outcome = await registry.wait(key, timeoutMs);
|
|
2616
2697
|
if (outcome === "granted") {
|
|
@@ -2679,6 +2760,7 @@ var HaexVaultSdk = class {
|
|
|
2679
2760
|
this.shell = new ShellAPI(this);
|
|
2680
2761
|
this.passwords = new PasswordsAPI(this);
|
|
2681
2762
|
this.contacts = new ContactsAPI(this);
|
|
2763
|
+
this.models = new ModelsAPI(this);
|
|
2682
2764
|
this.mail = new MailAPI(this);
|
|
2683
2765
|
this.notifications = new NotificationsAPI(this);
|
|
2684
2766
|
this.tab = new TabAPI(this);
|