@glassly/miniapp 0.3.0-dev.1
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 +275 -0
- package/dist/background/index.d.ts +64 -0
- package/dist/background/index.d.ts.map +1 -0
- package/dist/background/index.js +26 -0
- package/dist/background/index.js.map +1 -0
- package/dist/background/register.d.ts +39 -0
- package/dist/background/register.d.ts.map +1 -0
- package/dist/background/register.js +72 -0
- package/dist/background/register.js.map +1 -0
- package/dist/dev-reload.d.ts +21 -0
- package/dist/dev-reload.d.ts.map +1 -0
- package/dist/dev-reload.js +60 -0
- package/dist/dev-reload.js.map +1 -0
- package/dist/envelope.d.ts +23 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +47 -0
- package/dist/envelope.js.map +1 -0
- package/dist/globals.d.ts +54 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +12 -0
- package/dist/globals.js.map +1 -0
- package/dist/hardware.d.ts +38 -0
- package/dist/hardware.d.ts.map +1 -0
- package/dist/hardware.js +31 -0
- package/dist/hardware.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/actions.d.ts +81 -0
- package/dist/modules/actions.d.ts.map +1 -0
- package/dist/modules/actions.js +137 -0
- package/dist/modules/actions.js.map +1 -0
- package/dist/modules/ai.d.ts +211 -0
- package/dist/modules/ai.d.ts.map +1 -0
- package/dist/modules/ai.js +117 -0
- package/dist/modules/ai.js.map +1 -0
- package/dist/modules/auth.d.ts +25 -0
- package/dist/modules/auth.d.ts.map +1 -0
- package/dist/modules/auth.js +52 -0
- package/dist/modules/auth.js.map +1 -0
- package/dist/modules/base64.d.ts +16 -0
- package/dist/modules/base64.d.ts.map +1 -0
- package/dist/modules/base64.js +92 -0
- package/dist/modules/base64.js.map +1 -0
- package/dist/modules/blob.d.ts +161 -0
- package/dist/modules/blob.d.ts.map +1 -0
- package/dist/modules/blob.js +277 -0
- package/dist/modules/blob.js.map +1 -0
- package/dist/modules/camera.d.ts +183 -0
- package/dist/modules/camera.d.ts.map +1 -0
- package/dist/modules/camera.js +119 -0
- package/dist/modules/camera.js.map +1 -0
- package/dist/modules/cloud.d.ts +34 -0
- package/dist/modules/cloud.d.ts.map +1 -0
- package/dist/modules/cloud.js +70 -0
- package/dist/modules/cloud.js.map +1 -0
- package/dist/modules/dashboard.d.ts +24 -0
- package/dist/modules/dashboard.d.ts.map +1 -0
- package/dist/modules/dashboard.js +39 -0
- package/dist/modules/dashboard.js.map +1 -0
- package/dist/modules/display.d.ts +167 -0
- package/dist/modules/display.d.ts.map +1 -0
- package/dist/modules/display.js +83 -0
- package/dist/modules/display.js.map +1 -0
- package/dist/modules/events.d.ts +178 -0
- package/dist/modules/events.d.ts.map +1 -0
- package/dist/modules/events.js +168 -0
- package/dist/modules/events.js.map +1 -0
- package/dist/modules/glasses.d.ts +36 -0
- package/dist/modules/glasses.d.ts.map +1 -0
- package/dist/modules/glasses.js +52 -0
- package/dist/modules/glasses.js.map +1 -0
- package/dist/modules/heading.d.ts +16 -0
- package/dist/modules/heading.d.ts.map +1 -0
- package/dist/modules/heading.js +20 -0
- package/dist/modules/heading.js.map +1 -0
- package/dist/modules/imu.d.ts +31 -0
- package/dist/modules/imu.d.ts.map +1 -0
- package/dist/modules/imu.js +40 -0
- package/dist/modules/imu.js.map +1 -0
- package/dist/modules/input.d.ts +34 -0
- package/dist/modules/input.d.ts.map +1 -0
- package/dist/modules/input.js +50 -0
- package/dist/modules/input.js.map +1 -0
- package/dist/modules/keys.d.ts +30 -0
- package/dist/modules/keys.d.ts.map +1 -0
- package/dist/modules/keys.js +37 -0
- package/dist/modules/keys.js.map +1 -0
- package/dist/modules/languages.d.ts +42 -0
- package/dist/modules/languages.d.ts.map +1 -0
- package/dist/modules/languages.js +57 -0
- package/dist/modules/languages.js.map +1 -0
- package/dist/modules/led.d.ts +35 -0
- package/dist/modules/led.d.ts.map +1 -0
- package/dist/modules/led.js +39 -0
- package/dist/modules/led.js.map +1 -0
- package/dist/modules/location.d.ts +27 -0
- package/dist/modules/location.d.ts.map +1 -0
- package/dist/modules/location.js +35 -0
- package/dist/modules/location.js.map +1 -0
- package/dist/modules/memory.d.ts +126 -0
- package/dist/modules/memory.d.ts.map +1 -0
- package/dist/modules/memory.js +141 -0
- package/dist/modules/memory.js.map +1 -0
- package/dist/modules/mic.d.ts +61 -0
- package/dist/modules/mic.d.ts.map +1 -0
- package/dist/modules/mic.js +94 -0
- package/dist/modules/mic.js.map +1 -0
- package/dist/modules/miniapps.d.ts +82 -0
- package/dist/modules/miniapps.d.ts.map +1 -0
- package/dist/modules/miniapps.js +58 -0
- package/dist/modules/miniapps.js.map +1 -0
- package/dist/modules/navigation.d.ts +332 -0
- package/dist/modules/navigation.d.ts.map +1 -0
- package/dist/modules/navigation.js +387 -0
- package/dist/modules/navigation.js.map +1 -0
- package/dist/modules/permissions.d.ts +58 -0
- package/dist/modules/permissions.d.ts.map +1 -0
- package/dist/modules/permissions.js +66 -0
- package/dist/modules/permissions.js.map +1 -0
- package/dist/modules/phone.d.ts +95 -0
- package/dist/modules/phone.d.ts.map +1 -0
- package/dist/modules/phone.js +110 -0
- package/dist/modules/phone.js.map +1 -0
- package/dist/modules/pivots/engine.d.ts +169 -0
- package/dist/modules/pivots/engine.d.ts.map +1 -0
- package/dist/modules/pivots/engine.js +778 -0
- package/dist/modules/pivots/engine.js.map +1 -0
- package/dist/modules/pivots/geometry.d.ts +84 -0
- package/dist/modules/pivots/geometry.d.ts.map +1 -0
- package/dist/modules/pivots/geometry.js +371 -0
- package/dist/modules/pivots/geometry.js.map +1 -0
- package/dist/modules/pivots/instructions.d.ts +139 -0
- package/dist/modules/pivots/instructions.d.ts.map +1 -0
- package/dist/modules/pivots/instructions.js +281 -0
- package/dist/modules/pivots/instructions.js.map +1 -0
- package/dist/modules/speaker.d.ts +175 -0
- package/dist/modules/speaker.d.ts.map +1 -0
- package/dist/modules/speaker.js +249 -0
- package/dist/modules/speaker.js.map +1 -0
- package/dist/modules/speakers.d.ts +29 -0
- package/dist/modules/speakers.d.ts.map +1 -0
- package/dist/modules/speakers.js +38 -0
- package/dist/modules/speakers.js.map +1 -0
- package/dist/modules/storage.d.ts +50 -0
- package/dist/modules/storage.d.ts.map +1 -0
- package/dist/modules/storage.js +99 -0
- package/dist/modules/storage.js.map +1 -0
- package/dist/modules/stream.d.ts +133 -0
- package/dist/modules/stream.d.ts.map +1 -0
- package/dist/modules/stream.js +53 -0
- package/dist/modules/stream.js.map +1 -0
- package/dist/modules/system.d.ts +71 -0
- package/dist/modules/system.d.ts.map +1 -0
- package/dist/modules/system.js +65 -0
- package/dist/modules/system.js.map +1 -0
- package/dist/modules/transcription.d.ts +99 -0
- package/dist/modules/transcription.d.ts.map +1 -0
- package/dist/modules/transcription.js +126 -0
- package/dist/modules/transcription.js.map +1 -0
- package/dist/modules/translation.d.ts +65 -0
- package/dist/modules/translation.d.ts.map +1 -0
- package/dist/modules/translation.js +121 -0
- package/dist/modules/translation.js.map +1 -0
- package/dist/modules/ui.d.ts +186 -0
- package/dist/modules/ui.d.ts.map +1 -0
- package/dist/modules/ui.js +289 -0
- package/dist/modules/ui.js.map +1 -0
- package/dist/protocol.d.ts +384 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +413 -0
- package/dist/protocol.js.map +1 -0
- package/dist/react/MiniappHeader.d.ts +44 -0
- package/dist/react/MiniappHeader.d.ts.map +1 -0
- package/dist/react/MiniappHeader.js +32 -0
- package/dist/react/MiniappHeader.js.map +1 -0
- package/dist/react/MiniappProvider.d.ts +33 -0
- package/dist/react/MiniappProvider.d.ts.map +1 -0
- package/dist/react/MiniappProvider.js +15 -0
- package/dist/react/MiniappProvider.js.map +1 -0
- package/dist/react/capsuleHeaderLayout.d.ts +3 -0
- package/dist/react/capsuleHeaderLayout.d.ts.map +1 -0
- package/dist/react/capsuleHeaderLayout.js +5 -0
- package/dist/react/capsuleHeaderLayout.js.map +1 -0
- package/dist/react/index.d.ts +13 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +9 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useCapabilities.d.ts +26 -0
- package/dist/react/useCapabilities.d.ts.map +1 -0
- package/dist/react/useCapabilities.js +27 -0
- package/dist/react/useCapabilities.js.map +1 -0
- package/dist/react/useCapsuleHeaderStyle.d.ts +27 -0
- package/dist/react/useCapsuleHeaderStyle.d.ts.map +1 -0
- package/dist/react/useCapsuleHeaderStyle.js +39 -0
- package/dist/react/useCapsuleHeaderStyle.js.map +1 -0
- package/dist/react/useColorScheme.d.ts +18 -0
- package/dist/react/useColorScheme.d.ts.map +1 -0
- package/dist/react/useColorScheme.js +24 -0
- package/dist/react/useColorScheme.js.map +1 -0
- package/dist/react/useConnected.d.ts +17 -0
- package/dist/react/useConnected.d.ts.map +1 -0
- package/dist/react/useConnected.js +39 -0
- package/dist/react/useConnected.js.map +1 -0
- package/dist/react/useRpc.d.ts +29 -0
- package/dist/react/useRpc.d.ts.map +1 -0
- package/dist/react/useRpc.js +82 -0
- package/dist/react/useRpc.js.map +1 -0
- package/dist/react/useSafeArea.d.ts +21 -0
- package/dist/react/useSafeArea.d.ts.map +1 -0
- package/dist/react/useSafeArea.js +22 -0
- package/dist/react/useSafeArea.js.map +1 -0
- package/dist/session.d.ts +355 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +688 -0
- package/dist/session.js.map +1 -0
- package/dist/sub-path-types.test-d.d.ts +40 -0
- package/dist/sub-path-types.test-d.d.ts.map +1 -0
- package/dist/sub-path-types.test-d.js +37 -0
- package/dist/sub-path-types.test-d.js.map +1 -0
- package/dist/transport/auto.d.ts +35 -0
- package/dist/transport/auto.d.ts.map +1 -0
- package/dist/transport/auto.js +124 -0
- package/dist/transport/auto.js.map +1 -0
- package/dist/transport/dispatch.d.ts +43 -0
- package/dist/transport/dispatch.d.ts.map +1 -0
- package/dist/transport/dispatch.js +91 -0
- package/dist/transport/dispatch.js.map +1 -0
- package/dist/transport/local-socket.d.ts +28 -0
- package/dist/transport/local-socket.d.ts.map +1 -0
- package/dist/transport/local-socket.js +80 -0
- package/dist/transport/local-socket.js.map +1 -0
- package/dist/transport/mock.d.ts +54 -0
- package/dist/transport/mock.d.ts.map +1 -0
- package/dist/transport/mock.js +210 -0
- package/dist/transport/mock.js.map +1 -0
- package/dist/transport/postmessage.d.ts +36 -0
- package/dist/transport/postmessage.d.ts.map +1 -0
- package/dist/transport/postmessage.js +78 -0
- package/dist/transport/postmessage.js.map +1 -0
- package/dist/transport/types.d.ts +25 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +11 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/ui/index.d.ts +107 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +32 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +84 -0
- package/src/background/index.ts +177 -0
- package/src/background/register.ts +89 -0
- package/src/dev-reload.ts +59 -0
- package/src/envelope.ts +54 -0
- package/src/globals.ts +62 -0
- package/src/hardware.ts +40 -0
- package/src/index.ts +216 -0
- package/src/modules/actions.ts +189 -0
- package/src/modules/ai.ts +281 -0
- package/src/modules/auth.ts +68 -0
- package/src/modules/base64.ts +87 -0
- package/src/modules/blob.ts +341 -0
- package/src/modules/camera.ts +258 -0
- package/src/modules/cloud.ts +94 -0
- package/src/modules/dashboard.ts +51 -0
- package/src/modules/display.ts +207 -0
- package/src/modules/events.ts +318 -0
- package/src/modules/glasses.ts +58 -0
- package/src/modules/heading.ts +23 -0
- package/src/modules/imu.ts +44 -0
- package/src/modules/input.ts +66 -0
- package/src/modules/keys.ts +46 -0
- package/src/modules/languages.ts +72 -0
- package/src/modules/led.ts +61 -0
- package/src/modules/location.ts +39 -0
- package/src/modules/memory.ts +224 -0
- package/src/modules/mic.ts +103 -0
- package/src/modules/miniapps.ts +103 -0
- package/src/modules/navigation.ts +674 -0
- package/src/modules/permissions.ts +83 -0
- package/src/modules/phone.ts +155 -0
- package/src/modules/pivots/engine.ts +863 -0
- package/src/modules/pivots/geometry.ts +409 -0
- package/src/modules/pivots/instructions.ts +341 -0
- package/src/modules/speaker.ts +347 -0
- package/src/modules/speakers.ts +40 -0
- package/src/modules/storage.ts +109 -0
- package/src/modules/stream.ts +168 -0
- package/src/modules/system.ts +113 -0
- package/src/modules/transcription.ts +180 -0
- package/src/modules/translation.ts +156 -0
- package/src/modules/ui.ts +481 -0
- package/src/protocol.ts +475 -0
- package/src/react/MiniappHeader.tsx +114 -0
- package/src/react/MiniappProvider.tsx +50 -0
- package/src/react/capsuleHeaderLayout.ts +11 -0
- package/src/react/index.ts +12 -0
- package/src/react/useCapabilities.ts +29 -0
- package/src/react/useCapsuleHeaderStyle.ts +55 -0
- package/src/react/useColorScheme.ts +26 -0
- package/src/react/useConnected.ts +47 -0
- package/src/react/useRpc.ts +103 -0
- package/src/react/useSafeArea.ts +36 -0
- package/src/session.ts +969 -0
- package/src/sub-path-types.test-d.ts +60 -0
- package/src/transport/auto.ts +143 -0
- package/src/transport/dispatch.ts +106 -0
- package/src/transport/local-socket.ts +91 -0
- package/src/transport/mock.ts +255 -0
- package/src/transport/postmessage.ts +95 -0
- package/src/transport/types.ts +26 -0
- package/src/ui/index.ts +129 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Bridge envelope format.
|
|
3
|
+
*
|
|
4
|
+
* Every message between @glassly/miniapp and LocalMiniappRuntime is wrapped in
|
|
5
|
+
* this envelope for request/response correlation.
|
|
6
|
+
*
|
|
7
|
+
* { payload: {...}, requestId?: string }
|
|
8
|
+
*/
|
|
9
|
+
export interface MiniappEnvelope<P = unknown> {
|
|
10
|
+
payload: P;
|
|
11
|
+
/** Correlates request/response pairs. Set by the sender when it wants a reply. */
|
|
12
|
+
requestId?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Serialize an envelope for postMessage / WebSocket transport. */
|
|
15
|
+
export declare function serializeEnvelope(envelope: MiniappEnvelope): string;
|
|
16
|
+
/**
|
|
17
|
+
* Parse a serialized envelope. Returns null for any malformed input — never throws.
|
|
18
|
+
* Transports should pass raw strings in and silently drop nulls.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseEnvelope(raw: unknown): MiniappEnvelope | null;
|
|
21
|
+
/** Generate a short random requestId. Browser-native (crypto.randomUUID). */
|
|
22
|
+
export declare function makeRequestId(): string;
|
|
23
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,OAAO,EAAE,CAAC,CAAA;IACV,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAEnE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAoBlE;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,IAAI,MAAM,CAMtC"}
|
package/dist/envelope.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Bridge envelope format.
|
|
3
|
+
*
|
|
4
|
+
* Every message between @glassly/miniapp and LocalMiniappRuntime is wrapped in
|
|
5
|
+
* this envelope for request/response correlation.
|
|
6
|
+
*
|
|
7
|
+
* { payload: {...}, requestId?: string }
|
|
8
|
+
*/
|
|
9
|
+
/** Serialize an envelope for postMessage / WebSocket transport. */
|
|
10
|
+
export function serializeEnvelope(envelope) {
|
|
11
|
+
return JSON.stringify(envelope);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parse a serialized envelope. Returns null for any malformed input — never throws.
|
|
15
|
+
* Transports should pass raw strings in and silently drop nulls.
|
|
16
|
+
*/
|
|
17
|
+
export function parseEnvelope(raw) {
|
|
18
|
+
if (typeof raw !== "string")
|
|
19
|
+
return null;
|
|
20
|
+
let parsed;
|
|
21
|
+
try {
|
|
22
|
+
parsed = JSON.parse(raw);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
28
|
+
return null;
|
|
29
|
+
const obj = parsed;
|
|
30
|
+
if (typeof obj.payload !== "object" || obj.payload === null)
|
|
31
|
+
return null;
|
|
32
|
+
if (obj.requestId !== undefined && typeof obj.requestId !== "string")
|
|
33
|
+
return null;
|
|
34
|
+
return {
|
|
35
|
+
payload: obj.payload,
|
|
36
|
+
requestId: obj.requestId,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Generate a short random requestId. Browser-native (crypto.randomUUID). */
|
|
40
|
+
export function makeRequestId() {
|
|
41
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
42
|
+
return crypto.randomUUID();
|
|
43
|
+
}
|
|
44
|
+
// Fallback for older engines: timestamp + random suffix. Not cryptographically secure.
|
|
45
|
+
return `req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,mEAAmE;AACnE,MAAM,UAAU,iBAAiB,CAAC,QAAyB;IACzD,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAExC,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC9D,MAAM,GAAG,GAAG,MAAiC,CAAA;IAE7C,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,IAAI,GAAG,CAAC,OAAO,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IACxE,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,SAAS,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAEjF,OAAO;QACL,OAAO,EAAE,GAAG,CAAC,OAAkB;QAC/B,SAAS,EAAE,GAAG,CAAC,SAA+B;KAC/C,CAAA;AACH,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,aAAa;IAC3B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC7E,OAAO,MAAM,CAAC,UAAU,EAAE,CAAA;IAC5B,CAAC;IACD,uFAAuF;IACvF,OAAO,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAA;AACpF,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shape of window.Glassly, injected by the host Glassly app
|
|
3
|
+
* before the miniapp's content loads. Miniapp authors generally won't read
|
|
4
|
+
* this directly — use the typed React hooks (useSafeArea, etc.) instead.
|
|
5
|
+
*/
|
|
6
|
+
export interface MiniappSafeAreaInsets {
|
|
7
|
+
top: number;
|
|
8
|
+
bottom: number;
|
|
9
|
+
left: number;
|
|
10
|
+
right: number;
|
|
11
|
+
}
|
|
12
|
+
export interface MiniappCapsuleMenuRect {
|
|
13
|
+
top: number;
|
|
14
|
+
right: number;
|
|
15
|
+
bottom: number;
|
|
16
|
+
left: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
}
|
|
20
|
+
export type MiniappColorScheme = "light" | "dark";
|
|
21
|
+
export interface GlasslyGlobals {
|
|
22
|
+
/** Package id the host assigned to this miniapp (e.g. "com.glassly.example"). */
|
|
23
|
+
packageName?: string;
|
|
24
|
+
/** "ios" | "android" | other. */
|
|
25
|
+
platform?: string;
|
|
26
|
+
/** Capabilities the host exposes to this miniapp (e.g. ["share", "open_url"]). */
|
|
27
|
+
capabilities?: string[];
|
|
28
|
+
/** True when this miniapp is running locally on-device (vs. hosted in the cloud). */
|
|
29
|
+
miniappLocal?: boolean;
|
|
30
|
+
/** True when the miniapp is running via the dev workflow (QR sideload). */
|
|
31
|
+
miniappDeveloperMode?: boolean;
|
|
32
|
+
/** Safe-area insets around the WebView content. Miniapps should pad accordingly. */
|
|
33
|
+
safeAreaInsets?: MiniappSafeAreaInsets;
|
|
34
|
+
/**
|
|
35
|
+
* Bounding rect (in CSS pixels) of the floating capsule menu the host draws
|
|
36
|
+
* over the WebView. The menu lives in the top-right and miniapps should
|
|
37
|
+
* avoid placing interactive elements beneath it.
|
|
38
|
+
*/
|
|
39
|
+
capsuleMenu?: MiniappCapsuleMenuRect;
|
|
40
|
+
/**
|
|
41
|
+
* The host's current color scheme. Miniapps can follow this to match the
|
|
42
|
+
* phone's appearance. Updates at runtime arrive via the session's
|
|
43
|
+
* `colorScheme` event — see `useColorScheme()` in @glassly/miniapp/react.
|
|
44
|
+
*/
|
|
45
|
+
colorScheme?: MiniappColorScheme;
|
|
46
|
+
}
|
|
47
|
+
declare global {
|
|
48
|
+
interface Window {
|
|
49
|
+
Glassly?: GlasslyGlobals;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Reads window.Glassly safely — returns an empty object if not set. */
|
|
53
|
+
export declare function getGlasslyGlobals(): GlasslyGlobals;
|
|
54
|
+
//# sourceMappingURL=globals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,CAAA;AAEjD,MAAM,WAAW,cAAc;IAC7B,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kFAAkF;IAClF,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,qFAAqF;IACrF,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,2EAA2E;IAC3E,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,oFAAoF;IACpF,cAAc,CAAC,EAAE,qBAAqB,CAAA;IACtC;;;;OAIG;IACH,WAAW,CAAC,EAAE,sBAAsB,CAAA;IACpC;;;;OAIG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAA;CACjC;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,CAAC,EAAE,cAAc,CAAA;KACzB;CACF;AAED,wEAAwE;AACxE,wBAAgB,iBAAiB,IAAI,cAAc,CAGlD"}
|
package/dist/globals.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shape of window.Glassly, injected by the host Glassly app
|
|
3
|
+
* before the miniapp's content loads. Miniapp authors generally won't read
|
|
4
|
+
* this directly — use the typed React hooks (useSafeArea, etc.) instead.
|
|
5
|
+
*/
|
|
6
|
+
/** Reads window.Glassly safely — returns an empty object if not set. */
|
|
7
|
+
export function getGlasslyGlobals() {
|
|
8
|
+
if (typeof window === "undefined")
|
|
9
|
+
return {};
|
|
10
|
+
return window.Glassly ?? {};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=globals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globals.js","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqDH,wEAAwE;AACxE,MAAM,UAAU,iBAAiB;IAC/B,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,EAAE,CAAA;IAC5C,OAAO,MAAM,CAAC,OAAO,IAAI,EAAE,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardware requirement types — canonical home.
|
|
3
|
+
*
|
|
4
|
+
* Moved verbatim from the legacy `@glassly/types` package so miniapp authors
|
|
5
|
+
* can type their miniapp.json manifest without any dependency on legacy cloud.
|
|
6
|
+
* `@glassly/engine` re-exports these; do not fork copies elsewhere.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Hardware component types that apps can require
|
|
10
|
+
*/
|
|
11
|
+
export declare enum HardwareType {
|
|
12
|
+
CAMERA = "CAMERA",
|
|
13
|
+
DISPLAY = "DISPLAY",
|
|
14
|
+
MICROPHONE = "MICROPHONE",
|
|
15
|
+
SPEAKER = "SPEAKER",
|
|
16
|
+
IMU = "IMU",
|
|
17
|
+
BUTTON = "BUTTON",
|
|
18
|
+
LIGHT = "LIGHT",
|
|
19
|
+
WIFI = "WIFI",
|
|
20
|
+
EXIST = "EXIST"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Levels of hardware requirements
|
|
24
|
+
*/
|
|
25
|
+
export declare enum HardwareRequirementLevel {
|
|
26
|
+
REQUIRED = "REQUIRED",// App cannot function without this hardware
|
|
27
|
+
OPTIONAL = "OPTIONAL"
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Hardware requirement for an app
|
|
31
|
+
* Specifies what hardware components an app needs
|
|
32
|
+
*/
|
|
33
|
+
export interface HardwareRequirement {
|
|
34
|
+
type: HardwareType;
|
|
35
|
+
level: HardwareRequirementLevel;
|
|
36
|
+
description?: string;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=hardware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardware.d.ts","sourceRoot":"","sources":["../src/hardware.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,oBAAY,YAAY;IACtB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED;;GAEG;AACH,oBAAY,wBAAwB;IAClC,QAAQ,aAAa,CAAE,4CAA4C;IACnE,QAAQ,aAAa;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE,wBAAwB,CAAA;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB"}
|
package/dist/hardware.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardware requirement types — canonical home.
|
|
3
|
+
*
|
|
4
|
+
* Moved verbatim from the legacy `@glassly/types` package so miniapp authors
|
|
5
|
+
* can type their miniapp.json manifest without any dependency on legacy cloud.
|
|
6
|
+
* `@glassly/engine` re-exports these; do not fork copies elsewhere.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Hardware component types that apps can require
|
|
10
|
+
*/
|
|
11
|
+
export var HardwareType;
|
|
12
|
+
(function (HardwareType) {
|
|
13
|
+
HardwareType["CAMERA"] = "CAMERA";
|
|
14
|
+
HardwareType["DISPLAY"] = "DISPLAY";
|
|
15
|
+
HardwareType["MICROPHONE"] = "MICROPHONE";
|
|
16
|
+
HardwareType["SPEAKER"] = "SPEAKER";
|
|
17
|
+
HardwareType["IMU"] = "IMU";
|
|
18
|
+
HardwareType["BUTTON"] = "BUTTON";
|
|
19
|
+
HardwareType["LIGHT"] = "LIGHT";
|
|
20
|
+
HardwareType["WIFI"] = "WIFI";
|
|
21
|
+
HardwareType["EXIST"] = "EXIST";
|
|
22
|
+
})(HardwareType || (HardwareType = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Levels of hardware requirements
|
|
25
|
+
*/
|
|
26
|
+
export var HardwareRequirementLevel;
|
|
27
|
+
(function (HardwareRequirementLevel) {
|
|
28
|
+
HardwareRequirementLevel["REQUIRED"] = "REQUIRED";
|
|
29
|
+
HardwareRequirementLevel["OPTIONAL"] = "OPTIONAL";
|
|
30
|
+
})(HardwareRequirementLevel || (HardwareRequirementLevel = {}));
|
|
31
|
+
//# sourceMappingURL=hardware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardware.js","sourceRoot":"","sources":["../src/hardware.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,YAUX;AAVD,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,mCAAmB,CAAA;IACnB,yCAAyB,CAAA;IACzB,mCAAmB,CAAA;IACnB,2BAAW,CAAA;IACX,iCAAiB,CAAA;IACjB,+BAAe,CAAA;IACf,6BAAa,CAAA;IACb,+BAAe,CAAA;AACjB,CAAC,EAVW,YAAY,KAAZ,YAAY,QAUvB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,wBAGX;AAHD,WAAY,wBAAwB;IAClC,iDAAqB,CAAA;IACrB,iDAAqB,CAAA;AACvB,CAAC,EAHW,wBAAwB,KAAxB,wBAAwB,QAGnC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @glassly/miniapp — SDK for building Glassly local miniapps.
|
|
3
|
+
*
|
|
4
|
+
* Public entry point. Consumers do:
|
|
5
|
+
*
|
|
6
|
+
* import {MiniappSession} from "@glassly/miniapp" // background JSContext
|
|
7
|
+
* import {useColorScheme} from "@glassly/miniapp/react" // UI WebView hooks
|
|
8
|
+
* import {MiniappRequestType} from "@glassly/miniapp/protocol"
|
|
9
|
+
*/
|
|
10
|
+
export { MiniappSession, NotConnectedError } from "./session";
|
|
11
|
+
export type { AuthUpdatePayload, ConnectAckPayload, DisplayCapabilities, GlassesCapabilities, MiniappAuthState, MiniappRequestError, MiniappSessionOptions, MiniappVisibility, } from "./session";
|
|
12
|
+
export type { AuthFetchOptions, AuthModule } from "./modules/auth";
|
|
13
|
+
export { makeRequestId, parseEnvelope, serializeEnvelope } from "./envelope";
|
|
14
|
+
export type { MiniappEnvelope } from "./envelope";
|
|
15
|
+
export { getGlasslyGlobals } from "./globals";
|
|
16
|
+
export type { GlasslyGlobals, MiniappCapsuleMenuRect, MiniappColorScheme, MiniappSafeAreaInsets } from "./globals";
|
|
17
|
+
export { MiniappErrorCode, MiniappRequestType, MiniappResponseType, MiniappStreamType } from "./protocol";
|
|
18
|
+
export { CLOUD_STATUS_STREAM } from "./modules/cloud";
|
|
19
|
+
export { MiniappValidationError, SUPPORTED_LANGUAGE_HINTS, SUPPORTED_TRANSCRIPTION_LANGUAGES, isTranscriptionLanguage, } from "./modules/languages";
|
|
20
|
+
export type { LanguageHint, TranscriptionLanguage } from "./modules/languages";
|
|
21
|
+
export type { CloudClientAudioTransport, CloudClientConnectionStatus, CloudClientStatus } from "./modules/cloud";
|
|
22
|
+
export { HardwareType, HardwareRequirementLevel } from "./hardware";
|
|
23
|
+
export type { HardwareRequirement } from "./hardware";
|
|
24
|
+
export { createTransport } from "./transport/auto";
|
|
25
|
+
export type { CreateTransportOptions } from "./transport/auto";
|
|
26
|
+
export { PostMessageTransport } from "./transport/postmessage";
|
|
27
|
+
export { LocalSocketTransport } from "./transport/local-socket";
|
|
28
|
+
export type { LocalSocketTransportOptions } from "./transport/local-socket";
|
|
29
|
+
export { MockTransport, isMockExplicitlyRequested } from "./transport/mock";
|
|
30
|
+
export type { MockTransportOptions } from "./transport/mock";
|
|
31
|
+
export type { Transport, TransportDisconnectHandler, TransportMessageHandler } from "./transport/types";
|
|
32
|
+
export type { DisplayBreakMode, NativeNavInfo, NativeNavResult, RenderBox, RenderElement, RenderOptions, RenderRectStyle, RenderResult, RenderTextStyle, ViewType, } from "./modules/display";
|
|
33
|
+
export type { AccelData, AudioChunkData, BatteryData, ButtonPressData, ConnectionData, HeadingData, HeadPositionData, LocationData, NotificationDismissedData, PhoneNotificationData, TouchData, TranscriptionData, TranslationData, UnsubscribeFn, VadData, WifiData, } from "./modules/events";
|
|
34
|
+
export type { CalendarEvent, CalendarListOptions, CalendarListResult } from "./modules/phone";
|
|
35
|
+
export type { PlayAudioOptions, SpeakOptions, SpeakResult, SpeakerState, SpeakerStateEvent, SpeakerStreamOptions, SpeakerStreamSampleRate, SpeakerStreamWriteResult, } from "./modules/speaker";
|
|
36
|
+
export { SpeakerStreamWriter, SPEAKER_STREAM_MAX_BUFFERED_MS, SPEAKER_WRITE_CHUNK_BYTES } from "./modules/speaker";
|
|
37
|
+
export type { CameraFovPreset, CameraFovRequest, CameraFovResult, CameraRoiPosition, PhotoTaken, SetCameraFovOptions, StartVideoRecordingOptions, StopVideoRecordingOptions, TakePhotoOptions, VideoRecordingStarted, } from "./modules/camera";
|
|
38
|
+
export type { DashboardMode, ShowNativeDashboardResult } from "./modules/dashboard";
|
|
39
|
+
export type { CloudModule } from "./modules/cloud";
|
|
40
|
+
export type { LedColor, LedControlOptions } from "./modules/led";
|
|
41
|
+
export type { RestreamDestination, StartStreamOptions, StreamAudioConfig, StreamResolvedConfig, StreamResult, StreamStatus, StreamVideoConfig, } from "./modules/stream";
|
|
42
|
+
export type { ShareOptions, ShareResult, DownloadOptions, DownloadResult, ScanQrOptions, ScanQrResult, } from "./modules/system";
|
|
43
|
+
export type { MiniappInfo, MiniappActionInfo, MiniappCompatibility, ListMiniappsOptions } from "./modules/miniapps";
|
|
44
|
+
export type { ActionContext, ActionDescriptor, ActionHandler, InvokeOptions } from "./modules/actions";
|
|
45
|
+
export type { DisplayManager } from "./modules/display";
|
|
46
|
+
export type { MiniappsModule } from "./modules/miniapps";
|
|
47
|
+
export type { ActionsModule } from "./modules/actions";
|
|
48
|
+
export type { GlassesModule } from "./modules/glasses";
|
|
49
|
+
export type { HeadingModule } from "./modules/heading";
|
|
50
|
+
export type { AiModule, AiProvider, AiTier, AiTool, AiToolCall, AiToolResult, AiMessage, AiCompleteRequest, AiCompleteResult, AiStopReason, AiUsage, } from "./modules/ai";
|
|
51
|
+
export type { ImuModule } from "./modules/imu";
|
|
52
|
+
export type { InputModule } from "./modules/input";
|
|
53
|
+
export type { KeysModule, ApiKeyProvider } from "./modules/keys";
|
|
54
|
+
export type { LocationModule } from "./modules/location";
|
|
55
|
+
export type { MemoryModule, MemoryEntry, MemoryEntryKind, MemoryNoteSource, MemoryQuery, MemorySearchResult, MemorySession, MemorySummary, } from "./modules/memory";
|
|
56
|
+
export type { SpeakersModule } from "./modules/speakers";
|
|
57
|
+
export type { MicModule } from "./modules/mic";
|
|
58
|
+
export type { ComputedRoute, ComputedRouteStep, ComputeRouteOptions, ComputeRouteResult, LatLng, NavArrived, NavCancelled, NavError, NavigationModule, NavManeuver, NavOffRoute, NavPermissionResult, NavPlaceDetails, NavPlaceSuggestion, NavRerouting, NavRoute, NavState, NavStep, NavUpdate, Pivot, PivotEvent, PivotOptions, RouteAvoidances, StartNavigationOptions, TravelMode, } from "./modules/navigation";
|
|
59
|
+
export type { PermissionsModule, PermissionErrorEvent } from "./modules/permissions";
|
|
60
|
+
export type { PhoneModule, PhoneNotificationsModule, PhoneCalendarModule } from "./modules/phone";
|
|
61
|
+
export type { TranscriptionModule, TranscriptionConfig, TranscriptionOptions } from "./modules/transcription";
|
|
62
|
+
export type { TranslationModule } from "./modules/translation";
|
|
63
|
+
export type { SpeakerModule } from "./modules/speaker";
|
|
64
|
+
export type { PermissionType, PermissionRecord } from "./session";
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,EAAC,cAAc,EAAE,iBAAiB,EAAC,MAAM,WAAW,CAAA;AAC3D,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,WAAW,CAAA;AAClB,YAAY,EAAC,gBAAgB,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAA;AAEhE,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAA;AAC1E,YAAY,EAAC,eAAe,EAAC,MAAM,YAAY,CAAA;AAE/C,OAAO,EAAC,iBAAiB,EAAC,MAAM,WAAW,CAAA;AAC3C,YAAY,EAAC,cAAc,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,qBAAqB,EAAC,MAAM,WAAW,CAAA;AAEhH,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,iBAAiB,EAAC,MAAM,YAAY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AA;AAC/F,YAAY,EAAC,mBAAmB,EAAE,mBAAmB,EAAE,oBAAoB,EAAC,MAAM,yBAAyB,CAAA;AAC3G,YAAY,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAA;AAC5D,YAAY,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAA;AAGpD,YAAY,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,WAAW,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @glassly/miniapp — SDK for building Glassly local miniapps.
|
|
3
|
+
*
|
|
4
|
+
* Public entry point. Consumers do:
|
|
5
|
+
*
|
|
6
|
+
* import {MiniappSession} from "@glassly/miniapp" // background JSContext
|
|
7
|
+
* import {useColorScheme} from "@glassly/miniapp/react" // UI WebView hooks
|
|
8
|
+
* import {MiniappRequestType} from "@glassly/miniapp/protocol"
|
|
9
|
+
*/
|
|
10
|
+
import { installDevReloadListenerIfDevMode } from "./dev-reload";
|
|
11
|
+
// Auto-install the dev-reload listener on module import so authors get live
|
|
12
|
+
// reload for free in dev builds. No-op in production (gated on
|
|
13
|
+
// window.Glassly.miniappDeveloperMode).
|
|
14
|
+
installDevReloadListenerIfDevMode();
|
|
15
|
+
export { MiniappSession, NotConnectedError } from "./session";
|
|
16
|
+
export { makeRequestId, parseEnvelope, serializeEnvelope } from "./envelope";
|
|
17
|
+
export { getGlasslyGlobals } from "./globals";
|
|
18
|
+
export { MiniappErrorCode, MiniappRequestType, MiniappResponseType, MiniappStreamType } from "./protocol";
|
|
19
|
+
export { CLOUD_STATUS_STREAM } from "./modules/cloud";
|
|
20
|
+
// Language registry (issue 021): canonical language types + the validation
|
|
21
|
+
// error the typed transcription/translation surfaces throw.
|
|
22
|
+
export { MiniappValidationError, SUPPORTED_LANGUAGE_HINTS, SUPPORTED_TRANSCRIPTION_LANGUAGES, isTranscriptionLanguage, } from "./modules/languages";
|
|
23
|
+
// Hardware requirement types — canonical defs live in ./hardware; miniapp
|
|
24
|
+
// authors type their miniapp.json manifest with these, and @glassly/engine
|
|
25
|
+
// re-exports them. Keep explicit exports (enums as value, interfaces as
|
|
26
|
+
// type) for Bun compat.
|
|
27
|
+
export { HardwareType, HardwareRequirementLevel } from "./hardware";
|
|
28
|
+
// Transports — exported for advanced uses (forced transport injection, tests)
|
|
29
|
+
export { createTransport } from "./transport/auto";
|
|
30
|
+
export { PostMessageTransport } from "./transport/postmessage";
|
|
31
|
+
export { LocalSocketTransport } from "./transport/local-socket";
|
|
32
|
+
export { MockTransport, isMockExplicitlyRequested } from "./transport/mock";
|
|
33
|
+
export { SpeakerStreamWriter, SPEAKER_STREAM_MAX_BUFFERED_MS, SPEAKER_WRITE_CHUNK_BYTES } from "./modules/speaker";
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAC,iCAAiC,EAAC,MAAM,cAAc,CAAA;AAE9D,4EAA4E;AAC5E,+DAA+D;AAC/D,wCAAwC;AACxC,iCAAiC,EAAE,CAAA;AAEnC,OAAO,EAAC,cAAc,EAAE,iBAAiB,EAAC,MAAM,WAAW,CAAA;AAa3D,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAA;AAG1E,OAAO,EAAC,iBAAiB,EAAC,MAAM,WAAW,CAAA;AAG3C,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAA;AACvG,OAAO,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAA;AAEnD,2EAA2E;AAC3E,4DAA4D;AAC5D,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,iCAAiC,EACjC,uBAAuB,GACxB,MAAM,qBAAqB,CAAA;AAI5B,0EAA0E;AAC1E,2EAA2E;AAC3E,wEAAwE;AACxE,wBAAwB;AACxB,OAAO,EAAC,YAAY,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAA;AAGjE,8EAA8E;AAC9E,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAA;AAEhD,OAAO,EAAC,oBAAoB,EAAC,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAA;AAE7D,OAAO,EAAC,aAAa,EAAE,yBAAyB,EAAC,MAAM,kBAAkB,CAAA;AA8CzE,OAAO,EAAC,mBAAmB,EAAE,8BAA8B,EAAE,yBAAyB,EAAC,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview ActionsModule — `session.actions`.
|
|
3
|
+
*
|
|
4
|
+
* The MCP-shaped capability layer (miniapp tools), all three directions:
|
|
5
|
+
* - `list()` — discover every action the caller may invoke across installed
|
|
6
|
+
* miniapps (the MCP tools/list analog).
|
|
7
|
+
* - `invoke(pkg, actionId, params)` — call another miniapp's declared action.
|
|
8
|
+
* Open to all miniapps; headless-wakes the target if it's stopped. Actions
|
|
9
|
+
* declared with `visibility: "system"` stay restricted to system apps.
|
|
10
|
+
* - `handle(actionId, fn)` — expose one of your own actions. Mirrors
|
|
11
|
+
* `session.ui.handle` (one handler per id, throws on double-register,
|
|
12
|
+
* errors propagate to the caller).
|
|
13
|
+
*
|
|
14
|
+
* `invoke` ↔ `handle` are the two ends of one wire (keyed by `actionId`), which
|
|
15
|
+
* is why they share this namespace rather than being split across
|
|
16
|
+
* `session.miniapps` (whose lifecycle surface stays SYSTEM-only).
|
|
17
|
+
*/
|
|
18
|
+
import { MiniappSession } from "../session";
|
|
19
|
+
/** Context handed to an action handler. `callerPackageName` is host-stamped. */
|
|
20
|
+
export interface ActionContext {
|
|
21
|
+
/** The package that invoked this action (trustworthy — set by the host). */
|
|
22
|
+
callerPackageName: string;
|
|
23
|
+
}
|
|
24
|
+
export type ActionHandler = (params: Record<string, unknown>, ctx: ActionContext) => unknown | Promise<unknown>;
|
|
25
|
+
export interface InvokeOptions {
|
|
26
|
+
/** Overall timeout in ms (default 30s, max 120s — host-enforced). */
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* One invokable action surfaced by {@link ActionsModule.list}. Maps 1:1 onto
|
|
31
|
+
* an MCP tool: `id`→name, `description`, `parameters`→inputSchema.
|
|
32
|
+
*/
|
|
33
|
+
export interface ActionDescriptor {
|
|
34
|
+
/** The miniapp that declares (and handles) the action. */
|
|
35
|
+
packageName: string;
|
|
36
|
+
/** Human-readable name of that miniapp. */
|
|
37
|
+
appName: string;
|
|
38
|
+
id: string;
|
|
39
|
+
description: string;
|
|
40
|
+
/** JSON-Schema input descriptor (the MCP-compatible subset). */
|
|
41
|
+
parameters?: Record<string, unknown>;
|
|
42
|
+
/** JSON-Schema descriptor for the structured result. */
|
|
43
|
+
outputSchema?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
export declare class ActionsModule {
|
|
46
|
+
private readonly session;
|
|
47
|
+
private readonly handlers;
|
|
48
|
+
/** Inbound calls buffered until their handler registers, keyed by actionId. */
|
|
49
|
+
private readonly buffered;
|
|
50
|
+
constructor(session: MiniappSession);
|
|
51
|
+
/**
|
|
52
|
+
* List every action this miniapp may invoke across installed miniapps.
|
|
53
|
+
* Incompatible apps and the caller's own actions are excluded; actions
|
|
54
|
+
* declared `visibility: "system"` only appear for system callers.
|
|
55
|
+
*/
|
|
56
|
+
list(): Promise<ActionDescriptor[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Invoke a declared action on another miniapp. Resolves with the handler's
|
|
59
|
+
* return value, rejects with a MiniappRequestError (NOT_PERMITTED,
|
|
60
|
+
* APP_NOT_FOUND, ACTION_NOT_FOUND, WAKE_FAILED, NO_ACTION_HANDLER,
|
|
61
|
+
* ACTION_TIMEOUT, PAYLOAD_TOO_LARGE, or the handler's own error). Open to
|
|
62
|
+
* all miniapps; the target keeps running after the call — a target that
|
|
63
|
+
* wants to shut down when done can call `session.system.exit()` itself.
|
|
64
|
+
*/
|
|
65
|
+
invoke<TResult = unknown>(packageName: string, actionId: string, params?: Record<string, unknown>, opts?: InvokeOptions): Promise<TResult>;
|
|
66
|
+
/**
|
|
67
|
+
* Register a handler for one of this miniapp's declared actions. One handler
|
|
68
|
+
* per actionId — throws synchronously on double-register. The returned
|
|
69
|
+
* function unregisters. Declare the action in `miniapp.json` for it to be
|
|
70
|
+
* invokable; an undeclared id still registers but the host never routes to it.
|
|
71
|
+
*/
|
|
72
|
+
handle(actionId: string, handler: ActionHandler): () => void;
|
|
73
|
+
/**
|
|
74
|
+
* @internal — called by MiniappSession.handleIncoming on an ACTION_CALL.
|
|
75
|
+
* Routes to the registered handler, or buffers briefly for one to appear.
|
|
76
|
+
*/
|
|
77
|
+
_deliver(callId: string, actionId: string, params: Record<string, unknown>, ctx: ActionContext): void;
|
|
78
|
+
private dispatch;
|
|
79
|
+
private sendResult;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/modules/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AAEzC,gFAAgF;AAChF,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,iBAAiB,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAE/G,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAA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ionsModule — `session.actions`.
|
|
3
|
+
*
|
|
4
|
+
* The MCP-shaped capability layer (miniapp tools), all three directions:
|
|
5
|
+
* - `list()` — discover every action the caller may invoke across installed
|
|
6
|
+
* miniapps (the MCP tools/list analog).
|
|
7
|
+
* - `invoke(pkg, actionId, params)` — call another miniapp's declared action.
|
|
8
|
+
* Open to all miniapps; headless-wakes the target if it's stopped. Actions
|
|
9
|
+
* declared with `visibility: "system"` stay restricted to system apps.
|
|
10
|
+
* - `handle(actionId, fn)` — expose one of your own actions. Mirrors
|
|
11
|
+
* `session.ui.handle` (one handler per id, throws on double-register,
|
|
12
|
+
* errors propagate to the caller).
|
|
13
|
+
*
|
|
14
|
+
* `invoke` ↔ `handle` are the two ends of one wire (keyed by `actionId`), which
|
|
15
|
+
* is why they share this namespace rather than being split across
|
|
16
|
+
* `session.miniapps` (whose lifecycle surface stays SYSTEM-only).
|
|
17
|
+
*/
|
|
18
|
+
import { MiniappErrorCode, MiniappRequestType } from "../protocol";
|
|
19
|
+
/**
|
|
20
|
+
* How long the SDK holds an inbound ACTION_CALL waiting for its handler to
|
|
21
|
+
* register (a just-woken miniapp registers handlers a beat after CONNECT).
|
|
22
|
+
* If no handler appears in this window the call is failed with
|
|
23
|
+
* NO_ACTION_HANDLER. Mirrors the UI bus's pre-handler buffering.
|
|
24
|
+
*/
|
|
25
|
+
const HANDLER_WAIT_MS = 5000;
|
|
26
|
+
export class ActionsModule {
|
|
27
|
+
constructor(session) {
|
|
28
|
+
this.session = session;
|
|
29
|
+
this.handlers = new Map();
|
|
30
|
+
/** Inbound calls buffered until their handler registers, keyed by actionId. */
|
|
31
|
+
this.buffered = new Map();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* List every action this miniapp may invoke across installed miniapps.
|
|
35
|
+
* Incompatible apps and the caller's own actions are excluded; actions
|
|
36
|
+
* declared `visibility: "system"` only appear for system callers.
|
|
37
|
+
*/
|
|
38
|
+
list() {
|
|
39
|
+
return this.session.sendRequest({
|
|
40
|
+
type: MiniappRequestType.ACTIONS_LIST,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Invoke a declared action on another miniapp. Resolves with the handler's
|
|
45
|
+
* return value, rejects with a MiniappRequestError (NOT_PERMITTED,
|
|
46
|
+
* APP_NOT_FOUND, ACTION_NOT_FOUND, WAKE_FAILED, NO_ACTION_HANDLER,
|
|
47
|
+
* ACTION_TIMEOUT, PAYLOAD_TOO_LARGE, or the handler's own error). Open to
|
|
48
|
+
* all miniapps; the target keeps running after the call — a target that
|
|
49
|
+
* wants to shut down when done can call `session.system.exit()` itself.
|
|
50
|
+
*/
|
|
51
|
+
invoke(packageName, actionId, params, opts) {
|
|
52
|
+
return this.session.sendRequest({
|
|
53
|
+
type: MiniappRequestType.ACTION_INVOKE,
|
|
54
|
+
targetPackageName: packageName,
|
|
55
|
+
actionId,
|
|
56
|
+
params: params ?? {},
|
|
57
|
+
...(opts?.timeoutMs != null ? { timeoutMs: opts.timeoutMs } : {}),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Register a handler for one of this miniapp's declared actions. One handler
|
|
62
|
+
* per actionId — throws synchronously on double-register. The returned
|
|
63
|
+
* function unregisters. Declare the action in `miniapp.json` for it to be
|
|
64
|
+
* invokable; an undeclared id still registers but the host never routes to it.
|
|
65
|
+
*/
|
|
66
|
+
handle(actionId, handler) {
|
|
67
|
+
if (this.handlers.has(actionId)) {
|
|
68
|
+
throw new Error(`session.actions.handle: a handler is already registered for "${actionId}"`);
|
|
69
|
+
}
|
|
70
|
+
this.handlers.set(actionId, handler);
|
|
71
|
+
// Flush any calls that arrived before this handler registered.
|
|
72
|
+
const waiting = this.buffered.get(actionId);
|
|
73
|
+
if (waiting) {
|
|
74
|
+
this.buffered.delete(actionId);
|
|
75
|
+
for (const call of waiting) {
|
|
76
|
+
clearTimeout(call.timer);
|
|
77
|
+
void this.dispatch(call.callId, actionId, call.params, call.ctx);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return () => {
|
|
81
|
+
if (this.handlers.get(actionId) === handler)
|
|
82
|
+
this.handlers.delete(actionId);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @internal — called by MiniappSession.handleIncoming on an ACTION_CALL.
|
|
87
|
+
* Routes to the registered handler, or buffers briefly for one to appear.
|
|
88
|
+
*/
|
|
89
|
+
_deliver(callId, actionId, params, ctx) {
|
|
90
|
+
if (this.handlers.has(actionId)) {
|
|
91
|
+
void this.dispatch(callId, actionId, params, ctx);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// No handler yet — buffer, and fail with NO_ACTION_HANDLER if none registers.
|
|
95
|
+
const timer = setTimeout(() => {
|
|
96
|
+
const arr = this.buffered.get(actionId);
|
|
97
|
+
if (arr) {
|
|
98
|
+
const idx = arr.findIndex((c) => c.callId === callId);
|
|
99
|
+
if (idx >= 0)
|
|
100
|
+
arr.splice(idx, 1);
|
|
101
|
+
if (arr.length === 0)
|
|
102
|
+
this.buffered.delete(actionId);
|
|
103
|
+
}
|
|
104
|
+
this.sendResult(callId, false, undefined, {
|
|
105
|
+
code: MiniappErrorCode.NO_ACTION_HANDLER,
|
|
106
|
+
message: `No handler registered for action "${actionId}"`,
|
|
107
|
+
});
|
|
108
|
+
}, HANDLER_WAIT_MS);
|
|
109
|
+
const arr = this.buffered.get(actionId) ?? [];
|
|
110
|
+
arr.push({ callId, params, ctx, timer });
|
|
111
|
+
this.buffered.set(actionId, arr);
|
|
112
|
+
}
|
|
113
|
+
async dispatch(callId, actionId, params, ctx) {
|
|
114
|
+
const handler = this.handlers.get(actionId);
|
|
115
|
+
if (!handler)
|
|
116
|
+
return;
|
|
117
|
+
try {
|
|
118
|
+
const result = await handler(params, ctx);
|
|
119
|
+
this.sendResult(callId, true, result ?? null);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
this.sendResult(callId, false, undefined, {
|
|
123
|
+
code: MiniappErrorCode.INTERNAL,
|
|
124
|
+
message: e?.message ?? "action handler threw",
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
sendResult(callId, ok, result, error) {
|
|
129
|
+
this.session.sendOneShot({
|
|
130
|
+
type: MiniappRequestType.ACTION_RESULT,
|
|
131
|
+
callId,
|
|
132
|
+
ok,
|
|
133
|
+
...(ok ? { result } : { error }),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/modules/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAA;AAwChE;;;;;GAKG;AACH,MAAM,eAAe,GAAG,IAAK,CAAA;AAE7B,MAAM,OAAO,aAAa;IAKxB,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;QAJnC,aAAQ,GAAG,IAAI,GAAG,EAAyB,CAAA;QAC5D,+EAA+E;QAC9D,aAAQ,GAAG,IAAI,GAAG,EAA0B,CAAA;IAEN,CAAC;IAExD;;;;OAIG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAqB;YAClD,IAAI,EAAE,kBAAkB,CAAC,YAAY;SACtC,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CACJ,WAAmB,EACnB,QAAgB,EAChB,MAAgC,EAChC,IAAoB;QAEpB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAU;YACvC,IAAI,EAAE,kBAAkB,CAAC,aAAa;YACtC,iBAAiB,EAAE,WAAW;YAC9B,QAAQ;YACR,MAAM,EAAE,MAAM,IAAI,EAAE;YACpB,GAAG,CAAC,IAAI,EAAE,SAAS,IAAI,IAAI,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