@ikonai/sdk-ui 1.0.66 → 1.0.68

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.
@@ -0,0 +1,71 @@
1
+ import { StreamSnapshot } from './ui-store';
2
+ import { UiStreamSnapshotWire } from './ui-store-ops';
3
+ import { UiStylePayload } from './ikon-ui-core';
4
+ export interface LiveSnapshotConfig {
5
+ /** Stable per-app identifier (e.g. the space id). Part of the storage key. */
6
+ appId: string;
7
+ /**
8
+ * The connected user's id — real when logged in, or the unique id issued by anonymous auth (stable
9
+ * per browser instance). Part of the storage key. There is deliberately NO fallback: a falsy id
10
+ * disables the live snapshot entirely (it never reads, writes, or prunes), so an unidentified
11
+ * session can never paint another session's UI on a shared device.
12
+ */
13
+ userId: string;
14
+ /**
15
+ * Stored state older than this is treated as missing. Default 5 minutes — kept under the app
16
+ * server's idle-kill window (per-space, default 15 min). Set this to the space's configured
17
+ * idle-kill time so the live snapshot never outlives the server it was captured from (a longer
18
+ * value risks flashing a stale tree that then snaps to the cold-started server's default view).
19
+ */
20
+ maxAgeMs?: number;
21
+ /** Serialized envelopes larger than this are dropped (not written). Default ~5 MB. */
22
+ maxBytes?: number;
23
+ /** Throttle window for writes (at most one write per window). Default 1000 ms. */
24
+ debounceMs?: number;
25
+ }
26
+ /** UI state recovered from a live snapshot, shaped for `UiStore.applyStoreOp(ReplaceStreamSnapshot)`. */
27
+ export interface LiveSnapshotState {
28
+ streams: UiStreamSnapshotWire[];
29
+ styles: UiStylePayload[];
30
+ }
31
+ /**
32
+ * Persists the last rendered live snapshot (view tree + styles) per app/user in `localStorage`, so a
33
+ * return visit can paint the cached tree before the WebSocket connects. The store is
34
+ * schema-versioned, age-bounded, size-bounded, and silent on quota/serialization failure — a miss
35
+ * always degrades cleanly to the live connect path.
36
+ *
37
+ * Binary payloads (images etc.) are **not** stored: they would dominate the size and make every
38
+ * write re-encode unchanged bytes. The seeded tree paints layout + text instantly; payload-backed
39
+ * content fills in once the live connection delivers it. Writes are throttled and run at idle time.
40
+ *
41
+ * The key embeds the user id, and sibling keys for other users of the same app are pruned on
42
+ * construction so a shared device never paints one user's UI for another. A missing user id
43
+ * disables the live snapshot rather than falling back to a shared key.
44
+ */
45
+ export declare class LiveSnapshotCache {
46
+ private readonly key;
47
+ private readonly appId;
48
+ private readonly userId;
49
+ private readonly disabled;
50
+ private readonly maxAgeMs;
51
+ private readonly maxBytes;
52
+ private readonly debounceMs;
53
+ private writeTimer;
54
+ private pending;
55
+ /** Remove every stored live snapshot (all apps and users) from localStorage. Call on logout. */
56
+ static clearAll(): void;
57
+ constructor(config: LiveSnapshotConfig);
58
+ load(): LiveSnapshotState | null;
59
+ /**
60
+ * Schedule a throttled write of the current UI state (at most one write per window, captured at
61
+ * the trailing edge). Streams with no root are skipped. The actual write runs at idle time.
62
+ */
63
+ save(streams: StreamSnapshot[], styles: readonly UiStylePayload[]): void;
64
+ /** Write any pending state immediately and synchronously (used on dispose / unmount). */
65
+ flush(): void;
66
+ dispose(): void;
67
+ private writePending;
68
+ private writeNow;
69
+ private remove;
70
+ private pruneOtherUsers;
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikonai/sdk-ui",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",