@parlor/capabilities 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/README.md +15 -2
- package/dist/adapters/capacitor.d.ts +3 -0
- package/dist/adapters/capacitor.d.ts.map +1 -0
- package/dist/adapters/capacitor.js +24 -0
- package/dist/adapters/capacitor.js.map +1 -0
- package/dist/adapters/tauri.d.ts +3 -0
- package/dist/adapters/tauri.d.ts.map +1 -0
- package/dist/adapters/tauri.js +24 -0
- package/dist/adapters/tauri.js.map +1 -0
- package/dist/adapters/types.d.ts +18 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/adapters/web.d.ts +3 -0
- package/dist/adapters/web.d.ts.map +1 -0
- package/dist/adapters/web.js +17 -0
- package/dist/adapters/web.js.map +1 -0
- package/dist/auth-browser/capacitor.d.ts +15 -0
- package/dist/auth-browser/capacitor.d.ts.map +1 -0
- package/dist/auth-browser/capacitor.js +16 -0
- package/dist/auth-browser/capacitor.js.map +1 -0
- package/dist/auth-browser/index.d.ts +7 -0
- package/dist/auth-browser/index.d.ts.map +1 -0
- package/dist/auth-browser/index.js +10 -0
- package/dist/auth-browser/index.js.map +1 -0
- package/dist/auth-browser/interface.d.ts +9 -0
- package/dist/auth-browser/interface.d.ts.map +1 -0
- package/dist/auth-browser/interface.js +2 -0
- package/dist/auth-browser/interface.js.map +1 -0
- package/dist/auth-browser/scheme.d.ts +2 -0
- package/dist/auth-browser/scheme.d.ts.map +1 -0
- package/dist/auth-browser/scheme.js +4 -0
- package/dist/auth-browser/scheme.js.map +1 -0
- package/dist/auth-browser/tauri.d.ts +6 -0
- package/dist/auth-browser/tauri.d.ts.map +1 -0
- package/dist/auth-browser/tauri.js +20 -0
- package/dist/auth-browser/tauri.js.map +1 -0
- package/dist/auth-browser/web.d.ts +5 -0
- package/dist/auth-browser/web.d.ts.map +1 -0
- package/dist/auth-browser/web.js +15 -0
- package/dist/auth-browser/web.js.map +1 -0
- package/dist/capability.d.ts +21 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +21 -0
- package/dist/capability.js.map +1 -0
- package/dist/deep-link/capacitor.d.ts +16 -0
- package/dist/deep-link/capacitor.d.ts.map +1 -0
- package/dist/deep-link/capacitor.js +28 -0
- package/dist/deep-link/capacitor.js.map +1 -0
- package/dist/deep-link/index.d.ts +7 -0
- package/dist/deep-link/index.d.ts.map +1 -0
- package/dist/deep-link/index.js +10 -0
- package/dist/deep-link/index.js.map +1 -0
- package/dist/deep-link/interface.d.ts +5 -0
- package/dist/deep-link/interface.d.ts.map +1 -0
- package/dist/deep-link/interface.js +2 -0
- package/dist/deep-link/interface.js.map +1 -0
- package/dist/deep-link/tauri.d.ts +8 -0
- package/dist/deep-link/tauri.d.ts.map +1 -0
- package/dist/deep-link/tauri.js +28 -0
- package/dist/deep-link/tauri.js.map +1 -0
- package/dist/deep-link/web.d.ts +4 -0
- package/dist/deep-link/web.d.ts.map +1 -0
- package/dist/deep-link/web.js +20 -0
- package/dist/deep-link/web.js.map +1 -0
- package/dist/device-key/capacitor.d.ts +32 -0
- package/dist/device-key/capacitor.d.ts.map +1 -0
- package/dist/device-key/capacitor.js +9 -0
- package/dist/device-key/capacitor.js.map +1 -0
- package/dist/device-key/encoding.d.ts +12 -0
- package/dist/device-key/encoding.d.ts.map +1 -0
- package/dist/device-key/encoding.js +45 -0
- package/dist/device-key/encoding.js.map +1 -0
- package/dist/device-key/index.d.ts +8 -0
- package/dist/device-key/index.d.ts.map +1 -0
- package/dist/device-key/index.js +11 -0
- package/dist/device-key/index.js.map +1 -0
- package/dist/device-key/interface.d.ts +74 -0
- package/dist/device-key/interface.d.ts.map +1 -0
- package/dist/device-key/interface.js +7 -0
- package/dist/device-key/interface.js.map +1 -0
- package/dist/device-key/native.d.ts +38 -0
- package/dist/device-key/native.d.ts.map +1 -0
- package/dist/device-key/native.js +67 -0
- package/dist/device-key/native.js.map +1 -0
- package/dist/device-key/tauri.d.ts +8 -0
- package/dist/device-key/tauri.d.ts.map +1 -0
- package/dist/device-key/tauri.js +16 -0
- package/dist/device-key/tauri.js.map +1 -0
- package/dist/device-key/web.d.ts +11 -0
- package/dist/device-key/web.d.ts.map +1 -0
- package/dist/device-key/web.js +210 -0
- package/dist/device-key/web.js.map +1 -0
- package/dist/files/capacitor.d.ts +19 -0
- package/dist/files/capacitor.d.ts.map +1 -0
- package/dist/files/capacitor.js +47 -0
- package/dist/files/capacitor.js.map +1 -0
- package/dist/files/index.d.ts +7 -0
- package/dist/files/index.d.ts.map +1 -0
- package/dist/files/index.js +10 -0
- package/dist/files/index.js.map +1 -0
- package/dist/files/interface.d.ts +29 -0
- package/dist/files/interface.d.ts.map +1 -0
- package/dist/files/interface.js +2 -0
- package/dist/files/interface.js.map +1 -0
- package/dist/files/mime.d.ts +11 -0
- package/dist/files/mime.d.ts.map +1 -0
- package/dist/files/mime.js +56 -0
- package/dist/files/mime.js.map +1 -0
- package/dist/files/tauri.d.ts +27 -0
- package/dist/files/tauri.d.ts.map +1 -0
- package/dist/files/tauri.js +46 -0
- package/dist/files/tauri.js.map +1 -0
- package/dist/files/web.d.ts +21 -0
- package/dist/files/web.d.ts.map +1 -0
- package/dist/files/web.js +82 -0
- package/dist/files/web.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/local-agent-host/capacitor.d.ts +5 -0
- package/dist/local-agent-host/capacitor.d.ts.map +1 -0
- package/dist/local-agent-host/capacitor.js +11 -0
- package/dist/local-agent-host/capacitor.js.map +1 -0
- package/dist/local-agent-host/index.d.ts +7 -0
- package/dist/local-agent-host/index.d.ts.map +1 -0
- package/dist/local-agent-host/index.js +10 -0
- package/dist/local-agent-host/index.js.map +1 -0
- package/dist/local-agent-host/interface.d.ts +62 -0
- package/dist/local-agent-host/interface.d.ts.map +1 -0
- package/dist/local-agent-host/interface.js +2 -0
- package/dist/local-agent-host/interface.js.map +1 -0
- package/dist/local-agent-host/tauri.d.ts +10 -0
- package/dist/local-agent-host/tauri.d.ts.map +1 -0
- package/dist/local-agent-host/tauri.js +38 -0
- package/dist/local-agent-host/tauri.js.map +1 -0
- package/dist/local-agent-host/web.d.ts +5 -0
- package/dist/local-agent-host/web.d.ts.map +1 -0
- package/dist/local-agent-host/web.js +11 -0
- package/dist/local-agent-host/web.js.map +1 -0
- package/dist/notifications/capacitor.d.ts +28 -0
- package/dist/notifications/capacitor.d.ts.map +1 -0
- package/dist/notifications/capacitor.js +39 -0
- package/dist/notifications/capacitor.js.map +1 -0
- package/dist/notifications/index.d.ts +7 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +10 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/interface.d.ts +14 -0
- package/dist/notifications/interface.d.ts.map +1 -0
- package/dist/notifications/interface.js +2 -0
- package/dist/notifications/interface.js.map +1 -0
- package/dist/notifications/tauri.d.ts +12 -0
- package/dist/notifications/tauri.d.ts.map +1 -0
- package/dist/notifications/tauri.js +28 -0
- package/dist/notifications/tauri.js.map +1 -0
- package/dist/notifications/web.d.ts +15 -0
- package/dist/notifications/web.d.ts.map +1 -0
- package/dist/notifications/web.js +23 -0
- package/dist/notifications/web.js.map +1 -0
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +9 -0
- package/dist/runtime.js.map +1 -0
- package/dist/session-store/capacitor.d.ts +17 -0
- package/dist/session-store/capacitor.d.ts.map +1 -0
- package/dist/session-store/capacitor.js +21 -0
- package/dist/session-store/capacitor.js.map +1 -0
- package/dist/session-store/index.d.ts +8 -0
- package/dist/session-store/index.d.ts.map +1 -0
- package/dist/session-store/index.js +11 -0
- package/dist/session-store/index.js.map +1 -0
- package/dist/session-store/interface.d.ts +9 -0
- package/dist/session-store/interface.d.ts.map +1 -0
- package/dist/session-store/interface.js +2 -0
- package/dist/session-store/interface.js.map +1 -0
- package/dist/session-store/keychain.d.ts +13 -0
- package/dist/session-store/keychain.d.ts.map +1 -0
- package/dist/session-store/keychain.js +36 -0
- package/dist/session-store/keychain.js.map +1 -0
- package/dist/session-store/local.d.ts +10 -0
- package/dist/session-store/local.d.ts.map +1 -0
- package/dist/session-store/local.js +15 -0
- package/dist/session-store/local.js.map +1 -0
- package/dist/session-store/tauri.d.ts +10 -0
- package/dist/session-store/tauri.d.ts.map +1 -0
- package/dist/session-store/tauri.js +24 -0
- package/dist/session-store/tauri.js.map +1 -0
- package/dist/session-store/web.d.ts +5 -0
- package/dist/session-store/web.d.ts.map +1 -0
- package/dist/session-store/web.js +11 -0
- package/dist/session-store/web.js.map +1 -0
- package/package.json +95 -3
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { bytesOf } from "./mime.js";
|
|
2
|
+
const browserApis = () => ({
|
|
3
|
+
document: globalThis.document,
|
|
4
|
+
showSaveFilePicker: globalThis.showSaveFilePicker?.bind(globalThis),
|
|
5
|
+
});
|
|
6
|
+
const pickedFrom = (file) => ({
|
|
7
|
+
name: file.name,
|
|
8
|
+
type: file.type,
|
|
9
|
+
size: file.size,
|
|
10
|
+
bytes: async () => new Uint8Array(await file.arrayBuffer()),
|
|
11
|
+
text: () => file.text(),
|
|
12
|
+
});
|
|
13
|
+
/** An `<input type="file">` the user answers or cancels; also what a phone's webview shows. */
|
|
14
|
+
export function pickWithInput(document, options = {}) {
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
const input = document.createElement("input");
|
|
17
|
+
input.type = "file";
|
|
18
|
+
input.hidden = true;
|
|
19
|
+
if (options.accept?.length)
|
|
20
|
+
input.accept = options.accept.join(",");
|
|
21
|
+
input.multiple = options.multiple === true;
|
|
22
|
+
const done = (files) => {
|
|
23
|
+
input.remove();
|
|
24
|
+
resolve(files);
|
|
25
|
+
};
|
|
26
|
+
input.addEventListener("change", () => done([...(input.files ?? [])].map(pickedFrom)));
|
|
27
|
+
input.addEventListener("cancel", () => done([]));
|
|
28
|
+
document.body.append(input);
|
|
29
|
+
input.click();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function download(document, blob, name) {
|
|
33
|
+
const url = URL.createObjectURL(blob);
|
|
34
|
+
const link = document.createElement("a");
|
|
35
|
+
link.href = url;
|
|
36
|
+
link.download = name;
|
|
37
|
+
link.hidden = true;
|
|
38
|
+
document.body.append(link);
|
|
39
|
+
link.click();
|
|
40
|
+
link.remove();
|
|
41
|
+
setTimeout(() => URL.revokeObjectURL(url), 60_000);
|
|
42
|
+
return "saved";
|
|
43
|
+
}
|
|
44
|
+
async function saveInBrowser(apis, document, data, options) {
|
|
45
|
+
const blob = new Blob([new Uint8Array(await bytesOf(data))], {
|
|
46
|
+
type: options.type ?? "",
|
|
47
|
+
});
|
|
48
|
+
if (!apis.showSaveFilePicker)
|
|
49
|
+
return download(document, blob, options.name);
|
|
50
|
+
try {
|
|
51
|
+
const handle = await apis.showSaveFilePicker({ suggestedName: options.name });
|
|
52
|
+
const writable = await handle.createWritable();
|
|
53
|
+
await writable.write(blob);
|
|
54
|
+
await writable.close();
|
|
55
|
+
return "saved";
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error instanceof Error && error.name === "AbortError")
|
|
59
|
+
return "cancelled";
|
|
60
|
+
if (error instanceof Error && error.name === "SecurityError") {
|
|
61
|
+
return download(document, blob, options.name);
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export function webFiles(getApis = browserApis) {
|
|
67
|
+
return {
|
|
68
|
+
platform: "web",
|
|
69
|
+
available: () => getApis().document !== undefined,
|
|
70
|
+
create: () => {
|
|
71
|
+
const apis = getApis();
|
|
72
|
+
const { document } = apis;
|
|
73
|
+
if (!document)
|
|
74
|
+
throw new Error("Files need a document");
|
|
75
|
+
return {
|
|
76
|
+
pick: (options) => pickWithInput(document, options),
|
|
77
|
+
save: (data, options) => saveInBrowser(apis, document, data, options),
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/files/web.ts"],"names":[],"mappings":"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","sourcesContent":["import type { CapabilityAdapter } from \"../capability.js\";\nimport type {\n Files,\n PickedFile,\n PickOptions,\n SaveOptions,\n SaveOutcome,\n} from \"./interface.js\";\nimport { bytesOf } from \"./mime.js\";\n\ninterface SaveFilePicker {\n (options: { suggestedName: string }): Promise<{\n createWritable(): Promise<{\n write(data: Blob): Promise<void>;\n close(): Promise<void>;\n }>;\n }>;\n}\n\nexport interface WebFilesApis {\n readonly document: Document | undefined;\n readonly showSaveFilePicker?: SaveFilePicker | undefined;\n}\n\nconst browserApis = (): WebFilesApis => ({\n document: globalThis.document,\n showSaveFilePicker: (\n globalThis as { showSaveFilePicker?: SaveFilePicker }\n ).showSaveFilePicker?.bind(globalThis),\n});\n\nconst pickedFrom = (file: File): PickedFile => ({\n name: file.name,\n type: file.type,\n size: file.size,\n bytes: async () => new Uint8Array(await file.arrayBuffer()),\n text: () => file.text(),\n});\n\n/** An `<input type=\"file\">` the user answers or cancels; also what a phone's webview shows. */\nexport function pickWithInput(\n document: Document,\n options: PickOptions = {},\n): Promise<readonly PickedFile[]> {\n return new Promise((resolve) => {\n const input = document.createElement(\"input\");\n input.type = \"file\";\n input.hidden = true;\n if (options.accept?.length) input.accept = options.accept.join(\",\");\n input.multiple = options.multiple === true;\n const done = (files: readonly PickedFile[]) => {\n input.remove();\n resolve(files);\n };\n input.addEventListener(\"change\", () =>\n done([...(input.files ?? [])].map(pickedFrom)),\n );\n input.addEventListener(\"cancel\", () => done([]));\n document.body.append(input);\n input.click();\n });\n}\n\nfunction download(document: Document, blob: Blob, name: string): SaveOutcome {\n const url = URL.createObjectURL(blob);\n const link = document.createElement(\"a\");\n link.href = url;\n link.download = name;\n link.hidden = true;\n document.body.append(link);\n link.click();\n link.remove();\n setTimeout(() => URL.revokeObjectURL(url), 60_000);\n return \"saved\";\n}\n\nasync function saveInBrowser(\n apis: WebFilesApis,\n document: Document,\n data: Blob | Uint8Array | string,\n options: SaveOptions,\n): Promise<SaveOutcome> {\n const blob = new Blob([new Uint8Array(await bytesOf(data))], {\n type: options.type ?? \"\",\n });\n if (!apis.showSaveFilePicker) return download(document, blob, options.name);\n try {\n const handle = await apis.showSaveFilePicker({ suggestedName: options.name });\n const writable = await handle.createWritable();\n await writable.write(blob);\n await writable.close();\n return \"saved\";\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") return \"cancelled\";\n if (error instanceof Error && error.name === \"SecurityError\") {\n return download(document, blob, options.name);\n }\n throw error;\n }\n}\n\nexport function webFiles(\n getApis: () => WebFilesApis = browserApis,\n): CapabilityAdapter<Files> {\n return {\n platform: \"web\",\n available: () => getApis().document !== undefined,\n create: () => {\n const apis = getApis();\n const { document } = apis;\n if (!document) throw new Error(\"Files need a document\");\n return {\n pick: (options) => pickWithInput(document, options),\n save: (data, options) => saveInBrowser(apis, document, data, options),\n };\n },\n };\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { PlatformAdapters } from "./adapters/types.js";
|
|
2
|
+
export * from "./auth-browser/index.js";
|
|
3
|
+
export { type CapabilityAdapter, type CapabilityDefinition, type CapabilityHandle, defineCapability, resolveCapability, } from "./capability.js";
|
|
4
|
+
export * from "./deep-link/index.js";
|
|
5
|
+
export * from "./device-key/index.js";
|
|
6
|
+
export { capacitorLocalAgentHost, localAgentHost, tauriLocalAgentHost, webLocalAgentHost, } from "./local-agent-host/index.js";
|
|
7
|
+
export type { HostPairing, LocalAgentHost, LocalConnectInput, LocalConnectResult, LocalHostStatus, PairingDevice, PairingPresenceKey, } from "./local-agent-host/interface.js";
|
|
8
|
+
export * from "./files/index.js";
|
|
9
|
+
export * from "./notifications/index.js";
|
|
10
|
+
export { detectPlatform, type Platform } from "./runtime.js";
|
|
11
|
+
export * from "./session-store/index.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,cAAc,yBAAyB,CAAC;AACxC,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7D,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./auth-browser/index.js";
|
|
2
|
+
export { defineCapability, resolveCapability, } from "./capability.js";
|
|
3
|
+
export * from "./deep-link/index.js";
|
|
4
|
+
export * from "./device-key/index.js";
|
|
5
|
+
export { capacitorLocalAgentHost, localAgentHost, tauriLocalAgentHost, webLocalAgentHost, } from "./local-agent-host/index.js";
|
|
6
|
+
export * from "./files/index.js";
|
|
7
|
+
export * from "./notifications/index.js";
|
|
8
|
+
export { detectPlatform } from "./runtime.js";
|
|
9
|
+
export * from "./session-store/index.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAIL,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AAUrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,cAAc,EAAiB,MAAM,cAAc,CAAC;AAC7D,cAAc,0BAA0B,CAAC","sourcesContent":["export type { PlatformAdapters } from \"./adapters/types.js\";\nexport * from \"./auth-browser/index.js\";\nexport {\n type CapabilityAdapter,\n type CapabilityDefinition,\n type CapabilityHandle,\n defineCapability,\n resolveCapability,\n} from \"./capability.js\";\nexport * from \"./deep-link/index.js\";\nexport * from \"./device-key/index.js\";\nexport {\n capacitorLocalAgentHost,\n localAgentHost,\n tauriLocalAgentHost,\n webLocalAgentHost,\n} from \"./local-agent-host/index.js\";\nexport type {\n HostPairing,\n LocalAgentHost,\n LocalConnectInput,\n LocalConnectResult,\n LocalHostStatus,\n PairingDevice,\n PairingPresenceKey,\n} from \"./local-agent-host/interface.js\";\nexport * from \"./files/index.js\";\nexport * from \"./notifications/index.js\";\nexport { detectPlatform, type Platform } from \"./runtime.js\";\nexport * from \"./session-store/index.js\";\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CapabilityAdapter } from "../capability.js";
|
|
2
|
+
import type { LocalAgentHost } from "./interface.js";
|
|
3
|
+
/** A phone cannot spawn an agent process. */
|
|
4
|
+
export declare function capacitorLocalAgentHost(): CapabilityAdapter<LocalAgentHost>;
|
|
5
|
+
//# sourceMappingURL=capacitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capacitor.d.ts","sourceRoot":"","sources":["../../src/local-agent-host/capacitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,6CAA6C;AAC7C,wBAAgB,uBAAuB,IAAI,iBAAiB,CAAC,cAAc,CAAC,CAQ3E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A phone cannot spawn an agent process. */
|
|
2
|
+
export function capacitorLocalAgentHost() {
|
|
3
|
+
return {
|
|
4
|
+
platform: "capacitor",
|
|
5
|
+
available: () => false,
|
|
6
|
+
create: () => {
|
|
7
|
+
throw new Error("Agents cannot run on a phone; connect a computer instead.");
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=capacitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capacitor.js","sourceRoot":"","sources":["../../src/local-agent-host/capacitor.ts"],"names":[],"mappings":"AAGA,6CAA6C;AAC7C,MAAM,UAAU,uBAAuB;IACrC,OAAO;QACL,QAAQ,EAAE,WAAW;QACrB,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK;QACtB,MAAM,EAAE,GAAG,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAC/E,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { CapabilityAdapter } from \"../capability.js\";\nimport type { LocalAgentHost } from \"./interface.js\";\n\n/** A phone cannot spawn an agent process. */\nexport function capacitorLocalAgentHost(): CapabilityAdapter<LocalAgentHost> {\n return {\n platform: \"capacitor\",\n available: () => false,\n create: () => {\n throw new Error(\"Agents cannot run on a phone; connect a computer instead.\");\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LocalAgentHost } from "./interface.js";
|
|
2
|
+
export { capacitorLocalAgentHost } from "./capacitor.js";
|
|
3
|
+
export type { HostPairing, LocalAgentHost, LocalConnectInput, LocalConnectResult, LocalHostStatus, } from "./interface.js";
|
|
4
|
+
export { tauriLocalAgentHost } from "./tauri.js";
|
|
5
|
+
export { webLocalAgentHost } from "./web.js";
|
|
6
|
+
export declare const localAgentHost: import("../capability.js").CapabilityDefinition<LocalAgentHost>;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/local-agent-host/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,YAAY,EACV,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,eAAO,MAAM,cAAc,iEAGzB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { platformAdapters } from "#adapters";
|
|
2
|
+
import { defineCapability } from "../capability.js";
|
|
3
|
+
export { capacitorLocalAgentHost } from "./capacitor.js";
|
|
4
|
+
export { tauriLocalAgentHost } from "./tauri.js";
|
|
5
|
+
export { webLocalAgentHost } from "./web.js";
|
|
6
|
+
export const localAgentHost = defineCapability({
|
|
7
|
+
name: "localAgentHost",
|
|
8
|
+
adapters: platformAdapters.localAgentHost,
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/local-agent-host/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAQzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAiB;IAC7D,IAAI,EAAE,gBAAgB;IACtB,QAAQ,EAAE,gBAAgB,CAAC,cAAc;CAC1C,CAAC,CAAC","sourcesContent":["import { platformAdapters } from \"#adapters\";\n\nimport { defineCapability } from \"../capability.js\";\nimport type { LocalAgentHost } from \"./interface.js\";\n\nexport { capacitorLocalAgentHost } from \"./capacitor.js\";\nexport type {\n HostPairing,\n LocalAgentHost,\n LocalConnectInput,\n LocalConnectResult,\n LocalHostStatus,\n} from \"./interface.js\";\nexport { tauriLocalAgentHost } from \"./tauri.js\";\nexport { webLocalAgentHost } from \"./web.js\";\n\nexport const localAgentHost = defineCapability<LocalAgentHost>({\n name: \"localAgentHost\",\n adapters: platformAdapters.localAgentHost,\n});\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parlor Host on this very computer, reachable without the network. Available only in a
|
|
3
|
+
* desktop shell built with `desktop.agentHost`; elsewhere the chat shows the install
|
|
4
|
+
* command instead.
|
|
5
|
+
*/
|
|
6
|
+
export interface LocalAgentHost {
|
|
7
|
+
status(): Promise<LocalHostStatus>;
|
|
8
|
+
/**
|
|
9
|
+
* Pairs this computer's host with the signed-in account: the host starts the pairing,
|
|
10
|
+
* `authorize` gets the code from the backend with the page's session, and the host
|
|
11
|
+
* confirms the account and matching code in a native dialog the page cannot skip.
|
|
12
|
+
*/
|
|
13
|
+
connect(input: LocalConnectInput): Promise<LocalConnectResult>;
|
|
14
|
+
}
|
|
15
|
+
export type LocalHostStatus = {
|
|
16
|
+
readonly state: "stopped";
|
|
17
|
+
} | {
|
|
18
|
+
readonly state: "running";
|
|
19
|
+
readonly version: string;
|
|
20
|
+
/** App origins this host holds a grant for. */
|
|
21
|
+
readonly apps: readonly string[];
|
|
22
|
+
};
|
|
23
|
+
export interface LocalConnectInput {
|
|
24
|
+
readonly appOrigin: string;
|
|
25
|
+
authorize(pairing: HostPairing): Promise<string>;
|
|
26
|
+
/** This app's own device, pinned at pairing so its first prompt needs no second approval. */
|
|
27
|
+
readonly device?: PairingDevice | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** The public half of a device's keys, as the account registered them. */
|
|
30
|
+
export interface PairingDevice {
|
|
31
|
+
readonly deviceId: string;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly platform: string;
|
|
34
|
+
readonly signingKey: JsonWebKey;
|
|
35
|
+
readonly presenceKey?: PairingPresenceKey | undefined;
|
|
36
|
+
}
|
|
37
|
+
export type PairingPresenceKey = {
|
|
38
|
+
readonly format: "webauthn";
|
|
39
|
+
readonly credentialId: string;
|
|
40
|
+
readonly rpId: string;
|
|
41
|
+
readonly publicKey: JsonWebKey;
|
|
42
|
+
} | {
|
|
43
|
+
readonly format: "es256-raw";
|
|
44
|
+
readonly keyId: string;
|
|
45
|
+
readonly publicKey: JsonWebKey;
|
|
46
|
+
};
|
|
47
|
+
/** What the backend's host authorize endpoint needs from the host, and shows on consent. */
|
|
48
|
+
export interface HostPairing {
|
|
49
|
+
readonly hostName: string;
|
|
50
|
+
readonly platform: string;
|
|
51
|
+
readonly codeChallenge: string;
|
|
52
|
+
readonly state: string;
|
|
53
|
+
readonly matchingCode: string;
|
|
54
|
+
readonly keyThumbprint: string;
|
|
55
|
+
}
|
|
56
|
+
export type LocalConnectResult = {
|
|
57
|
+
readonly connected: true;
|
|
58
|
+
} | {
|
|
59
|
+
readonly connected: false;
|
|
60
|
+
readonly reason: "declined_locally" | "failed";
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/local-agent-host/interface.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;IACnC;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAChE;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAC7B;IACE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAEN,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CAC7C;AAED,0EAA0E;AAC1E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;CACvD;AAED,MAAM,MAAM,kBAAkB,GAC1B;IACE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;CAChC,GACD;IACE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;CAChC,CAAC;AAEN,4FAA4F;AAC5F,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,QAAQ,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/local-agent-host/interface.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Parlor Host on this very computer, reachable without the network. Available only in a\n * desktop shell built with `desktop.agentHost`; elsewhere the chat shows the install\n * command instead.\n */\nexport interface LocalAgentHost {\n status(): Promise<LocalHostStatus>;\n /**\n * Pairs this computer's host with the signed-in account: the host starts the pairing,\n * `authorize` gets the code from the backend with the page's session, and the host\n * confirms the account and matching code in a native dialog the page cannot skip.\n */\n connect(input: LocalConnectInput): Promise<LocalConnectResult>;\n}\n\nexport type LocalHostStatus =\n | { readonly state: \"stopped\" }\n | {\n readonly state: \"running\";\n readonly version: string;\n /** App origins this host holds a grant for. */\n readonly apps: readonly string[];\n };\n\nexport interface LocalConnectInput {\n readonly appOrigin: string;\n authorize(pairing: HostPairing): Promise<string>;\n /** This app's own device, pinned at pairing so its first prompt needs no second approval. */\n readonly device?: PairingDevice | undefined;\n}\n\n/** The public half of a device's keys, as the account registered them. */\nexport interface PairingDevice {\n readonly deviceId: string;\n readonly name: string;\n readonly platform: string;\n readonly signingKey: JsonWebKey;\n readonly presenceKey?: PairingPresenceKey | undefined;\n}\n\nexport type PairingPresenceKey =\n | {\n readonly format: \"webauthn\";\n readonly credentialId: string;\n readonly rpId: string;\n readonly publicKey: JsonWebKey;\n }\n | {\n readonly format: \"es256-raw\";\n readonly keyId: string;\n readonly publicKey: JsonWebKey;\n };\n\n/** What the backend's host authorize endpoint needs from the host, and shows on consent. */\nexport interface HostPairing {\n readonly hostName: string;\n readonly platform: string;\n readonly codeChallenge: string;\n readonly state: string;\n readonly matchingCode: string;\n readonly keyThumbprint: string;\n}\n\nexport type LocalConnectResult =\n | { readonly connected: true }\n | { readonly connected: false; readonly reason: \"declined_locally\" | \"failed\" };\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CapabilityAdapter } from "../capability.js";
|
|
2
|
+
import type { TauriInvoke } from "../device-key/tauri.js";
|
|
3
|
+
import type { LocalAgentHost } from "./interface.js";
|
|
4
|
+
/**
|
|
5
|
+
* The generated `parlor_host_*` commands, which reach the shared daemon on its control
|
|
6
|
+
* socket (starting the bundled sidecar when none runs) and draw the pairing confirmation
|
|
7
|
+
* as a native dialog outside the webview.
|
|
8
|
+
*/
|
|
9
|
+
export declare function tauriLocalAgentHost(load?: () => Promise<TauriInvoke>): CapabilityAdapter<LocalAgentHost>;
|
|
10
|
+
//# sourceMappingURL=tauri.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tauri.d.ts","sourceRoot":"","sources":["../../src/local-agent-host/tauri.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,EAEV,cAAc,EAGf,MAAM,gBAAgB,CAAC;AAWxB;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,GAAE,MAAM,OAAO,CAAC,WAAW,CAAwC,GACtE,iBAAiB,CAAC,cAAc,CAAC,CAoBnC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { detectPlatform } from "../runtime.js";
|
|
2
|
+
async function hasBundledHost(load) {
|
|
3
|
+
if (detectPlatform() !== "tauri")
|
|
4
|
+
return false;
|
|
5
|
+
try {
|
|
6
|
+
return (await (await load()).invoke("parlor_host_bundled")) === true;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The generated `parlor_host_*` commands, which reach the shared daemon on its control
|
|
14
|
+
* socket (starting the bundled sidecar when none runs) and draw the pairing confirmation
|
|
15
|
+
* as a native dialog outside the webview.
|
|
16
|
+
*/
|
|
17
|
+
export function tauriLocalAgentHost(load = () => import("@tauri-apps/api/core")) {
|
|
18
|
+
return {
|
|
19
|
+
platform: "tauri",
|
|
20
|
+
available: () => hasBundledHost(load),
|
|
21
|
+
create: async () => {
|
|
22
|
+
const { invoke } = await load();
|
|
23
|
+
return {
|
|
24
|
+
status: () => invoke("parlor_host_status"),
|
|
25
|
+
connect: async ({ appOrigin, authorize, device }) => {
|
|
26
|
+
const pairing = await invoke("parlor_host_begin", { appOrigin });
|
|
27
|
+
const code = await authorize(pairing);
|
|
28
|
+
return invoke("parlor_host_finish", {
|
|
29
|
+
appOrigin,
|
|
30
|
+
code,
|
|
31
|
+
device: device ?? null,
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=tauri.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tauri.js","sourceRoot":"","sources":["../../src/local-agent-host/tauri.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAQ/C,KAAK,UAAU,cAAc,CAAC,IAAgC;IAC5D,IAAI,cAAc,EAAE,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAC/C,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,MAAM,CAAU,qBAAqB,CAAC,CAAC,KAAK,IAAI,CAAC;IAChF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAI,GAA+B,GAAG,EAAE,CAAC,MAAM,CAAC,sBAAsB,CAAC;IAEvE,OAAO;QACL,QAAQ,EAAE,OAAO;QACjB,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC;QACrC,MAAM,EAAE,KAAK,IAAI,EAAE;YACjB,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;YAChC,OAAO;gBACL,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAkB,oBAAoB,CAAC;gBAC3D,OAAO,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE;oBAClD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAc,mBAAmB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;oBAC9E,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC;oBACtC,OAAO,MAAM,CAAqB,oBAAoB,EAAE;wBACtD,SAAS;wBACT,IAAI;wBACJ,MAAM,EAAE,MAAM,IAAI,IAAI;qBACvB,CAAC,CAAC;gBACL,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { CapabilityAdapter } from \"../capability.js\";\nimport type { TauriInvoke } from \"../device-key/tauri.js\";\nimport { detectPlatform } from \"../runtime.js\";\nimport type {\n HostPairing,\n LocalAgentHost,\n LocalConnectResult,\n LocalHostStatus,\n} from \"./interface.js\";\n\nasync function hasBundledHost(load: () => Promise<TauriInvoke>): Promise<boolean> {\n if (detectPlatform() !== \"tauri\") return false;\n try {\n return (await (await load()).invoke<boolean>(\"parlor_host_bundled\")) === true;\n } catch {\n return false;\n }\n}\n\n/**\n * The generated `parlor_host_*` commands, which reach the shared daemon on its control\n * socket (starting the bundled sidecar when none runs) and draw the pairing confirmation\n * as a native dialog outside the webview.\n */\nexport function tauriLocalAgentHost(\n load: () => Promise<TauriInvoke> = () => import(\"@tauri-apps/api/core\"),\n): CapabilityAdapter<LocalAgentHost> {\n return {\n platform: \"tauri\",\n available: () => hasBundledHost(load),\n create: async () => {\n const { invoke } = await load();\n return {\n status: () => invoke<LocalHostStatus>(\"parlor_host_status\"),\n connect: async ({ appOrigin, authorize, device }) => {\n const pairing = await invoke<HostPairing>(\"parlor_host_begin\", { appOrigin });\n const code = await authorize(pairing);\n return invoke<LocalConnectResult>(\"parlor_host_finish\", {\n appOrigin,\n code,\n device: device ?? null,\n });\n },\n };\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CapabilityAdapter } from "../capability.js";
|
|
2
|
+
import type { LocalAgentHost } from "./interface.js";
|
|
3
|
+
/** A web page never reaches a local process: the host has no listener to reach. */
|
|
4
|
+
export declare function webLocalAgentHost(): CapabilityAdapter<LocalAgentHost>;
|
|
5
|
+
//# sourceMappingURL=web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/local-agent-host/web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,mFAAmF;AACnF,wBAAgB,iBAAiB,IAAI,iBAAiB,CAAC,cAAc,CAAC,CAQrE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A web page never reaches a local process: the host has no listener to reach. */
|
|
2
|
+
export function webLocalAgentHost() {
|
|
3
|
+
return {
|
|
4
|
+
platform: "web",
|
|
5
|
+
available: () => false,
|
|
6
|
+
create: () => {
|
|
7
|
+
throw new Error("Parlor Host is not reachable from a web page.");
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/local-agent-host/web.ts"],"names":[],"mappings":"AAGA,mFAAmF;AACnF,MAAM,UAAU,iBAAiB;IAC/B,OAAO;QACL,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK;QACtB,MAAM,EAAE,GAAG,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { CapabilityAdapter } from \"../capability.js\";\nimport type { LocalAgentHost } from \"./interface.js\";\n\n/** A web page never reaches a local process: the host has no listener to reach. */\nexport function webLocalAgentHost(): CapabilityAdapter<LocalAgentHost> {\n return {\n platform: \"web\",\n available: () => false,\n create: () => {\n throw new Error(\"Parlor Host is not reachable from a web page.\");\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CapabilityAdapter } from "../capability.js";
|
|
2
|
+
import type { Notifications } from "./interface.js";
|
|
3
|
+
type CapacitorPermissionState = "prompt" | "prompt-with-rationale" | "granted" | "denied";
|
|
4
|
+
export interface CapacitorNotificationModule {
|
|
5
|
+
LocalNotifications: {
|
|
6
|
+
checkPermissions(): Promise<{
|
|
7
|
+
display: CapacitorPermissionState;
|
|
8
|
+
}>;
|
|
9
|
+
requestPermissions(): Promise<{
|
|
10
|
+
display: CapacitorPermissionState;
|
|
11
|
+
}>;
|
|
12
|
+
schedule(options: {
|
|
13
|
+
notifications: Array<{
|
|
14
|
+
id: number;
|
|
15
|
+
title: string;
|
|
16
|
+
body: string;
|
|
17
|
+
}>;
|
|
18
|
+
}): Promise<unknown>;
|
|
19
|
+
cancel(options: {
|
|
20
|
+
notifications: Array<{
|
|
21
|
+
id: number;
|
|
22
|
+
}>;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare function capacitorNotifications(load?: () => Promise<CapacitorNotificationModule>): CapabilityAdapter<Notifications>;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=capacitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capacitor.d.ts","sourceRoot":"","sources":["../../src/notifications/capacitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EAA0B,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE5E,KAAK,wBAAwB,GAAG,QAAQ,GAAG,uBAAuB,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE1F,MAAM,WAAW,2BAA2B;IAC1C,kBAAkB,EAAE;QAClB,gBAAgB,IAAI,OAAO,CAAC;YAAE,OAAO,EAAE,wBAAwB,CAAA;SAAE,CAAC,CAAC;QACnE,kBAAkB,IAAI,OAAO,CAAC;YAAE,OAAO,EAAE,wBAAwB,CAAA;SAAE,CAAC,CAAC;QACrE,QAAQ,CAAC,OAAO,EAAE;YAChB,aAAa,EAAE,KAAK,CAAC;gBAAE,EAAE,EAAE,MAAM,CAAC;gBAAC,KAAK,EAAE,MAAM,CAAC;gBAAC,IAAI,EAAE,MAAM,CAAA;aAAE,CAAC,CAAC;SACnE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,CAAC,OAAO,EAAE;YAAE,aAAa,EAAE,KAAK,CAAC;gBAAE,EAAE,EAAE,MAAM,CAAA;aAAE,CAAC,CAAA;SAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KAC1E,CAAC;CACH;AAQD,wBAAgB,sBAAsB,CACpC,IAAI,GAAE,MAAM,OAAO,CAAC,2BAA2B,CACL,GACzC,iBAAiB,CAAC,aAAa,CAAC,CAiClC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { detectPlatform } from "../runtime.js";
|
|
2
|
+
function toPermission(state) {
|
|
3
|
+
if (state === "granted")
|
|
4
|
+
return "granted";
|
|
5
|
+
if (state === "denied")
|
|
6
|
+
return "denied";
|
|
7
|
+
return "default";
|
|
8
|
+
}
|
|
9
|
+
export function capacitorNotifications(load = () => import("@capacitor/local-notifications")) {
|
|
10
|
+
return {
|
|
11
|
+
platform: "capacitor",
|
|
12
|
+
available: () => detectPlatform() === "capacitor",
|
|
13
|
+
create: async () => {
|
|
14
|
+
const { LocalNotifications } = await load();
|
|
15
|
+
let permission = toPermission((await LocalNotifications.checkPermissions()).display);
|
|
16
|
+
let nextId = Date.now() % 2_000_000_000;
|
|
17
|
+
return {
|
|
18
|
+
permission: () => permission,
|
|
19
|
+
request: async () => {
|
|
20
|
+
permission = toPermission((await LocalNotifications.requestPermissions()).display);
|
|
21
|
+
return permission;
|
|
22
|
+
},
|
|
23
|
+
show: async (title, options) => {
|
|
24
|
+
if (permission !== "granted") {
|
|
25
|
+
throw new Error("Notification permission has not been granted");
|
|
26
|
+
}
|
|
27
|
+
const id = nextId++;
|
|
28
|
+
await LocalNotifications.schedule({
|
|
29
|
+
notifications: [{ id, title, body: options?.body ?? "" }],
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
close: () => void LocalNotifications.cancel({ notifications: [{ id }] }),
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=capacitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capacitor.js","sourceRoot":"","sources":["../../src/notifications/capacitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAgB/C,SAAS,YAAY,CAAC,KAA+B;IACnD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,KAAK,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACxC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,IAAI,GAA+C,GAAG,EAAE,CACtD,MAAM,CAAC,gCAAgC,CAAC;IAE1C,OAAO;QACL,QAAQ,EAAE,WAAW;QACrB,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc,EAAE,KAAK,WAAW;QACjD,MAAM,EAAE,KAAK,IAAI,EAAE;YACjB,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;YAC5C,IAAI,UAAU,GAAG,YAAY,CAC3B,CAAC,MAAM,kBAAkB,CAAC,gBAAgB,EAAE,CAAC,CAAC,OAAO,CACtD,CAAC;YACF,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,aAAa,CAAC;YACxC,OAAO;gBACL,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU;gBAC5B,OAAO,EAAE,KAAK,IAAI,EAAE;oBAClB,UAAU,GAAG,YAAY,CACvB,CAAC,MAAM,kBAAkB,CAAC,kBAAkB,EAAE,CAAC,CAAC,OAAO,CACxD,CAAC;oBACF,OAAO,UAAU,CAAC;gBACpB,CAAC;gBACD,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;oBAC7B,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;wBAC7B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;oBAClE,CAAC;oBACD,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;oBACpB,MAAM,kBAAkB,CAAC,QAAQ,CAAC;wBAChC,aAAa,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC;qBAC1D,CAAC,CAAC;oBACH,OAAO;wBACL,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,kBAAkB,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;qBACzE,CAAC;gBACJ,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { CapabilityAdapter } from \"../capability.js\";\nimport { detectPlatform } from \"../runtime.js\";\nimport type { NotificationPermission, Notifications } from \"./interface.js\";\n\ntype CapacitorPermissionState = \"prompt\" | \"prompt-with-rationale\" | \"granted\" | \"denied\";\n\nexport interface CapacitorNotificationModule {\n LocalNotifications: {\n checkPermissions(): Promise<{ display: CapacitorPermissionState }>;\n requestPermissions(): Promise<{ display: CapacitorPermissionState }>;\n schedule(options: {\n notifications: Array<{ id: number; title: string; body: string }>;\n }): Promise<unknown>;\n cancel(options: { notifications: Array<{ id: number }> }): Promise<void>;\n };\n}\n\nfunction toPermission(state: CapacitorPermissionState): NotificationPermission {\n if (state === \"granted\") return \"granted\";\n if (state === \"denied\") return \"denied\";\n return \"default\";\n}\n\nexport function capacitorNotifications(\n load: () => Promise<CapacitorNotificationModule> = () =>\n import(\"@capacitor/local-notifications\"),\n): CapabilityAdapter<Notifications> {\n return {\n platform: \"capacitor\",\n available: () => detectPlatform() === \"capacitor\",\n create: async () => {\n const { LocalNotifications } = await load();\n let permission = toPermission(\n (await LocalNotifications.checkPermissions()).display,\n );\n let nextId = Date.now() % 2_000_000_000;\n return {\n permission: () => permission,\n request: async () => {\n permission = toPermission(\n (await LocalNotifications.requestPermissions()).display,\n );\n return permission;\n },\n show: async (title, options) => {\n if (permission !== \"granted\") {\n throw new Error(\"Notification permission has not been granted\");\n }\n const id = nextId++;\n await LocalNotifications.schedule({\n notifications: [{ id, title, body: options?.body ?? \"\" }],\n });\n return {\n close: () => void LocalNotifications.cancel({ notifications: [{ id }] }),\n };\n },\n };\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Notifications } from "./interface.js";
|
|
2
|
+
export type { NotificationHandle, NotificationOptions, NotificationPermission, Notifications, } from "./interface.js";
|
|
3
|
+
export { capacitorNotifications, type CapacitorNotificationModule } from "./capacitor.js";
|
|
4
|
+
export { tauriNotifications, type TauriNotificationModule } from "./tauri.js";
|
|
5
|
+
export { webNotifications } from "./web.js";
|
|
6
|
+
export declare const notifications: import("../capability.js").CapabilityDefinition<Notifications>;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notifications/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,KAAK,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,eAAO,MAAM,aAAa,gEAGxB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { platformAdapters } from "#adapters";
|
|
2
|
+
import { defineCapability } from "../capability.js";
|
|
3
|
+
export { capacitorNotifications } from "./capacitor.js";
|
|
4
|
+
export { tauriNotifications } from "./tauri.js";
|
|
5
|
+
export { webNotifications } from "./web.js";
|
|
6
|
+
export const notifications = defineCapability({
|
|
7
|
+
name: "notifications",
|
|
8
|
+
adapters: platformAdapters.notifications,
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/notifications/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AASpD,OAAO,EAAE,sBAAsB,EAAoC,MAAM,gBAAgB,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAgC,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAgB;IAC3D,IAAI,EAAE,eAAe;IACrB,QAAQ,EAAE,gBAAgB,CAAC,aAAa;CACzC,CAAC,CAAC","sourcesContent":["import { platformAdapters } from \"#adapters\";\n\nimport { defineCapability } from \"../capability.js\";\nimport type { Notifications } from \"./interface.js\";\n\nexport type {\n NotificationHandle,\n NotificationOptions,\n NotificationPermission,\n Notifications,\n} from \"./interface.js\";\nexport { capacitorNotifications, type CapacitorNotificationModule } from \"./capacitor.js\";\nexport { tauriNotifications, type TauriNotificationModule } from \"./tauri.js\";\nexport { webNotifications } from \"./web.js\";\n\nexport const notifications = defineCapability<Notifications>({\n name: \"notifications\",\n adapters: platformAdapters.notifications,\n});\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type NotificationPermission = "granted" | "denied" | "default";
|
|
2
|
+
export interface NotificationOptions {
|
|
3
|
+
readonly body?: string | undefined;
|
|
4
|
+
readonly tag?: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface NotificationHandle {
|
|
7
|
+
close(): void;
|
|
8
|
+
}
|
|
9
|
+
export interface Notifications {
|
|
10
|
+
permission(): NotificationPermission;
|
|
11
|
+
request(): Promise<NotificationPermission>;
|
|
12
|
+
show(title: string, options?: NotificationOptions): Promise<NotificationHandle>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/notifications/interface.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,IAAI,sBAAsB,CAAC;IACrC,OAAO,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACjF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/notifications/interface.ts"],"names":[],"mappings":"","sourcesContent":["export type NotificationPermission = \"granted\" | \"denied\" | \"default\";\n\nexport interface NotificationOptions {\n readonly body?: string | undefined;\n readonly tag?: string | undefined;\n}\n\nexport interface NotificationHandle {\n close(): void;\n}\n\nexport interface Notifications {\n permission(): NotificationPermission;\n request(): Promise<NotificationPermission>;\n show(title: string, options?: NotificationOptions): Promise<NotificationHandle>;\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CapabilityAdapter } from "../capability.js";
|
|
2
|
+
import type { NotificationPermission, Notifications } from "./interface.js";
|
|
3
|
+
export interface TauriNotificationModule {
|
|
4
|
+
isPermissionGranted(): Promise<boolean>;
|
|
5
|
+
requestPermission(): Promise<NotificationPermission>;
|
|
6
|
+
sendNotification(options: {
|
|
7
|
+
title: string;
|
|
8
|
+
body?: string;
|
|
9
|
+
}): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function tauriNotifications(load?: () => Promise<TauriNotificationModule>): CapabilityAdapter<Notifications>;
|
|
12
|
+
//# sourceMappingURL=tauri.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tauri.d.ts","sourceRoot":"","sources":["../../src/notifications/tauri.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE5E,MAAM,WAAW,uBAAuB;IACtC,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,iBAAiB,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrD,gBAAgB,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACnE;AAED,wBAAgB,kBAAkB,CAChC,IAAI,GAAE,MAAM,OAAO,CAAC,uBAAuB,CACA,GAC1C,iBAAiB,CAAC,aAAa,CAAC,CA2BlC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { detectPlatform } from "../runtime.js";
|
|
2
|
+
export function tauriNotifications(load = () => import("@tauri-apps/plugin-notification")) {
|
|
3
|
+
return {
|
|
4
|
+
platform: "tauri",
|
|
5
|
+
available: () => detectPlatform() === "tauri",
|
|
6
|
+
create: async () => {
|
|
7
|
+
const plugin = await load();
|
|
8
|
+
let permission = (await plugin.isPermissionGranted())
|
|
9
|
+
? "granted"
|
|
10
|
+
: "default";
|
|
11
|
+
return {
|
|
12
|
+
permission: () => permission,
|
|
13
|
+
request: async () => {
|
|
14
|
+
permission = await plugin.requestPermission();
|
|
15
|
+
return permission;
|
|
16
|
+
},
|
|
17
|
+
show: async (title, options) => {
|
|
18
|
+
if (permission !== "granted") {
|
|
19
|
+
throw new Error("Notification permission has not been granted");
|
|
20
|
+
}
|
|
21
|
+
plugin.sendNotification(options?.body === undefined ? { title } : { title, body: options.body });
|
|
22
|
+
return { close: () => { } };
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=tauri.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tauri.js","sourceRoot":"","sources":["../../src/notifications/tauri.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAS/C,MAAM,UAAU,kBAAkB,CAChC,IAAI,GAA2C,GAAG,EAAE,CAClD,MAAM,CAAC,iCAAiC,CAAC;IAE3C,OAAO;QACL,QAAQ,EAAE,OAAO;QACjB,SAAS,EAAE,GAAG,EAAE,CAAC,cAAc,EAAE,KAAK,OAAO;QAC7C,MAAM,EAAE,KAAK,IAAI,EAAE;YACjB,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;YAC5B,IAAI,UAAU,GAA2B,CAAC,MAAM,MAAM,CAAC,mBAAmB,EAAE,CAAC;gBAC3E,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,SAAS,CAAC;YACd,OAAO;gBACL,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU;gBAC5B,OAAO,EAAE,KAAK,IAAI,EAAE;oBAClB,UAAU,GAAG,MAAM,MAAM,CAAC,iBAAiB,EAAE,CAAC;oBAC9C,OAAO,UAAU,CAAC;gBACpB,CAAC;gBACD,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;oBAC7B,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;wBAC7B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;oBAClE,CAAC;oBACD,MAAM,CAAC,gBAAgB,CACrB,OAAO,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CACxE,CAAC;oBACF,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;gBAC7B,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { CapabilityAdapter } from \"../capability.js\";\nimport { detectPlatform } from \"../runtime.js\";\nimport type { NotificationPermission, Notifications } from \"./interface.js\";\n\nexport interface TauriNotificationModule {\n isPermissionGranted(): Promise<boolean>;\n requestPermission(): Promise<NotificationPermission>;\n sendNotification(options: { title: string; body?: string }): void;\n}\n\nexport function tauriNotifications(\n load: () => Promise<TauriNotificationModule> = () =>\n import(\"@tauri-apps/plugin-notification\"),\n): CapabilityAdapter<Notifications> {\n return {\n platform: \"tauri\",\n available: () => detectPlatform() === \"tauri\",\n create: async () => {\n const plugin = await load();\n let permission: NotificationPermission = (await plugin.isPermissionGranted())\n ? \"granted\"\n : \"default\";\n return {\n permission: () => permission,\n request: async () => {\n permission = await plugin.requestPermission();\n return permission;\n },\n show: async (title, options) => {\n if (permission !== \"granted\") {\n throw new Error(\"Notification permission has not been granted\");\n }\n plugin.sendNotification(\n options?.body === undefined ? { title } : { title, body: options.body },\n );\n return { close: () => {} };\n },\n };\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CapabilityAdapter } from "../capability.js";
|
|
2
|
+
import type { NotificationPermission, Notifications } from "./interface.js";
|
|
3
|
+
interface NotificationApi {
|
|
4
|
+
readonly permission: NotificationPermission;
|
|
5
|
+
requestPermission(): Promise<NotificationPermission>;
|
|
6
|
+
new (title: string, options?: {
|
|
7
|
+
body?: string | undefined;
|
|
8
|
+
tag?: string | undefined;
|
|
9
|
+
}): {
|
|
10
|
+
close(): void;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare function webNotifications(getApi?: () => NotificationApi | undefined): CapabilityAdapter<Notifications>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/notifications/web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE5E,UAAU,eAAe;IACvB,QAAQ,CAAC,UAAU,EAAE,sBAAsB,CAAC;IAC5C,iBAAiB,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACrD,KACE,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GAChE;QAAE,KAAK,IAAI,IAAI,CAAA;KAAE,CAAC;CACtB;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,GAAE,MAAM,eAAe,GAAG,SACiC,GAChE,iBAAiB,CAAC,aAAa,CAAC,CAoBlC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function webNotifications(getApi = () => globalThis.Notification) {
|
|
2
|
+
return {
|
|
3
|
+
platform: "web",
|
|
4
|
+
available: () => getApi() !== undefined,
|
|
5
|
+
create: () => {
|
|
6
|
+
const api = getApi();
|
|
7
|
+
if (!api)
|
|
8
|
+
throw new Error("Notification API is not available");
|
|
9
|
+
return {
|
|
10
|
+
permission: () => api.permission,
|
|
11
|
+
request: () => api.requestPermission(),
|
|
12
|
+
show: async (title, options) => {
|
|
13
|
+
if (api.permission !== "granted") {
|
|
14
|
+
throw new Error("Notification permission has not been granted");
|
|
15
|
+
}
|
|
16
|
+
const notification = new api(title, options);
|
|
17
|
+
return { close: () => notification.close() };
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=web.js.map
|