ink-framework-lightos 0.1.0-alpha.13 → 0.1.0-alpha.14

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/ink-native.json CHANGED
@@ -15,6 +15,9 @@
15
15
  ],
16
16
  "src/push-delivery.ts": [
17
17
  "light-sdk-push"
18
+ ],
19
+ "src/tool-manager.ts": [
20
+ "light-sdk-tool-manager"
18
21
  ]
19
22
  }
20
23
  }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "ink-framework-lightos",
3
- "version": "0.1.0-alpha.13",
3
+ "version": "0.1.0-alpha.14",
4
4
  "exports": {
5
5
  ".": "./src/index.ts",
6
6
  "./ringtone": "./src/ringtone.ts",
7
7
  "./push": "./src/push.ts",
8
- "./push/delivery": "./src/push-delivery.ts"
8
+ "./push/delivery": "./src/push-delivery.ts",
9
+ "./tool-manager": "./src/tool-manager.ts"
9
10
  },
10
11
  "peerDependencies": {
11
- "ink": "npm:ink-framework@0.1.0-alpha.13",
12
+ "ink": "npm:ink-framework@0.1.0-alpha.14",
12
13
  "react": "19.2.8"
13
14
  },
14
15
  "license": "MIT",
package/src/push-hooks.ts CHANGED
@@ -15,7 +15,6 @@ export interface PushRegistration {
15
15
  url: string;
16
16
  bearerToken?: string;
17
17
  encryptionKey?: string;
18
- fetchOnWake?: boolean;
19
18
  }
20
19
  export interface PushOptions {
21
20
  foregroundGroup?: string | null;
@@ -0,0 +1,89 @@
1
+ import { useEffect, useState } from "ink/internal/react";
2
+ import { callNative, callNativeBytes, NativeError } from "ink/native";
3
+
4
+ export interface SharedFile {
5
+ name: string;
6
+ path: string;
7
+ uri: string;
8
+ isFile: boolean;
9
+ size: number;
10
+ lastModified: number;
11
+ }
12
+
13
+ function decodeFiles(source: string): SharedFile[] {
14
+ const files: unknown = JSON.parse(source);
15
+ if (!Array.isArray(files)) throw new NativeError("protocol", "Invalid shared file list");
16
+ return files.map((file: unknown) => {
17
+ if (typeof file !== "object" || file === null
18
+ || !["name", "path", "uri"].every(key => typeof Reflect.get(file, key) === "string")
19
+ || typeof Reflect.get(file, "isFile") !== "boolean"
20
+ || !["size", "lastModified"].every(key => {
21
+ const value: unknown = Reflect.get(file, key);
22
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
23
+ })) throw new NativeError("protocol", "Invalid shared file");
24
+ return file as SharedFile;
25
+ });
26
+ }
27
+
28
+ export async function setSharedFilesTask(task: { id: string } | null): Promise<void> {
29
+ await callNative("background", "set-shared-files-task", { task: task?.id ?? null });
30
+ }
31
+
32
+ export const sharedFiles = {
33
+ async list(path = ""): Promise<SharedFile[]> {
34
+ return decodeFiles(await callNative("tool-manager", "list", { path }));
35
+ },
36
+ async exists(path: string): Promise<boolean> {
37
+ return await callNative("tool-manager", "exists", { path }) === "true";
38
+ },
39
+ async readBytes(path: string, options: { offset?: number; length?: number; signal?: AbortSignal } = {}): Promise<Uint8Array> {
40
+ if (options.offset !== undefined && (!Number.isSafeInteger(options.offset) || options.offset < 0)) throw new RangeError("Invalid shared file offset");
41
+ if (options.length !== undefined && (!Number.isSafeInteger(options.length) || options.length < 0 || options.length > 524_288)) throw new RangeError("Shared reads accept up to 512 KiB");
42
+ return (await callNativeBytes("tool-manager", "read", { path, offset: options.offset, length: options.length }, { signal: options.signal })).bytes;
43
+ },
44
+ async writeBytes(path: string, bytes: Uint8Array): Promise<void> {
45
+ await callNativeBytes("tool-manager", "write", { path }, { bytes });
46
+ },
47
+ async copyFrom(path: string, source: string, options: { signal?: AbortSignal } = {}): Promise<void> {
48
+ await callNative("tool-manager", "copy-from", { path, source }, { signal: options.signal, timeoutMs: 600_000 });
49
+ },
50
+ async readText(path: string): Promise<string> {
51
+ return await callNative("tool-manager", "read-text", { path });
52
+ },
53
+ async writeText(path: string, text: string): Promise<void> {
54
+ await callNative("tool-manager", "write-text", { path, text });
55
+ },
56
+ async remove(path: string): Promise<boolean> {
57
+ return await callNative("tool-manager", "remove", { path }) === "true";
58
+ },
59
+ async mkdir(path: string): Promise<void> {
60
+ await callNative("tool-manager", "mkdir", { path });
61
+ },
62
+ };
63
+
64
+ export function useSharedFiles(path = "") {
65
+ const [state, setState] = useState<{ files: SharedFile[]; loading: boolean; error: Error | null }>({
66
+ files: [], loading: true, error: null,
67
+ });
68
+ useEffect(() => {
69
+ const controller = new AbortController();
70
+ setState({ files: [], loading: true, error: null });
71
+ void (async () => {
72
+ let revision = -1;
73
+ while (!controller.signal.aborted) {
74
+ const next = Number(await callNative("tool-manager", "observe", { revision }, { signal: controller.signal }));
75
+ if (!Number.isSafeInteger(next) || next < 0) throw new NativeError("protocol", "Invalid shared file state");
76
+ if (next !== revision) {
77
+ const files = await sharedFiles.list(path);
78
+ if (!controller.signal.aborted) setState({ files, loading: false, error: null });
79
+ }
80
+ revision = next;
81
+ }
82
+ })().catch(error => {
83
+ if (!controller.signal.aborted) setState(current => ({ ...current, loading: false,
84
+ error: error instanceof Error ? error : new Error(String(error)) }));
85
+ });
86
+ return () => controller.abort();
87
+ }, [path]);
88
+ return state;
89
+ }