@glassly/miniapp 0.4.2-dev.1193 → 0.4.3-beta.1211

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.
Files changed (85) hide show
  1. package/dist/display/index.d.ts +2 -1
  2. package/dist/display/index.d.ts.map +1 -1
  3. package/dist/display/index.js +1 -1
  4. package/dist/display/index.js.map +1 -1
  5. package/dist/display/profiles/index.d.ts +3 -2
  6. package/dist/display/profiles/index.d.ts.map +1 -1
  7. package/dist/display/profiles/index.js +2 -3
  8. package/dist/display/profiles/index.js.map +1 -1
  9. package/dist/display/profiles/nimo.d.ts +10 -3
  10. package/dist/display/profiles/nimo.d.ts.map +1 -1
  11. package/dist/display/profiles/nimo.js +35 -3
  12. package/dist/display/profiles/nimo.js.map +1 -1
  13. package/dist/display/profiles/textProfile.d.ts +24 -0
  14. package/dist/display/profiles/textProfile.d.ts.map +1 -0
  15. package/dist/display/profiles/textProfile.js +48 -0
  16. package/dist/display/profiles/textProfile.js.map +1 -0
  17. package/dist/display/profiles/types.d.ts +5 -0
  18. package/dist/display/profiles/types.d.ts.map +1 -1
  19. package/dist/display/scene/degrade.d.ts +1 -1
  20. package/dist/display/scene/degrade.js +1 -1
  21. package/dist/display/scene/process.d.ts.map +1 -1
  22. package/dist/display/scene/process.js +2 -3
  23. package/dist/display/scene/process.js.map +1 -1
  24. package/dist/host/actionInvoke.d.ts +44 -0
  25. package/dist/host/actionInvoke.d.ts.map +1 -0
  26. package/dist/host/actionInvoke.js +87 -0
  27. package/dist/host/actionInvoke.js.map +1 -0
  28. package/dist/host/gestureClaims.d.ts +37 -0
  29. package/dist/host/gestureClaims.d.ts.map +1 -0
  30. package/dist/host/gestureClaims.js +45 -0
  31. package/dist/host/gestureClaims.js.map +1 -0
  32. package/dist/host/index.d.ts +8 -0
  33. package/dist/host/index.d.ts.map +1 -1
  34. package/dist/host/index.js +9 -0
  35. package/dist/host/index.js.map +1 -1
  36. package/dist/host/manifestActions.d.ts +69 -0
  37. package/dist/host/manifestActions.d.ts.map +1 -0
  38. package/dist/host/manifestActions.js +89 -0
  39. package/dist/host/manifestActions.js.map +1 -0
  40. package/dist/host/memory/MemoryStore.d.ts +178 -0
  41. package/dist/host/memory/MemoryStore.d.ts.map +1 -0
  42. package/dist/host/memory/MemoryStore.js +615 -0
  43. package/dist/host/memory/MemoryStore.js.map +1 -0
  44. package/dist/host/memory/search.d.ts +72 -0
  45. package/dist/host/memory/search.d.ts.map +1 -0
  46. package/dist/host/memory/search.js +188 -0
  47. package/dist/host/memory/search.js.map +1 -0
  48. package/dist/host/miniappPermissions.d.ts +16 -0
  49. package/dist/host/miniappPermissions.d.ts.map +1 -0
  50. package/dist/host/miniappPermissions.js +7 -0
  51. package/dist/host/miniappPermissions.js.map +1 -0
  52. package/dist/host/settingsBridge.d.ts +49 -0
  53. package/dist/host/settingsBridge.d.ts.map +1 -0
  54. package/dist/host/settingsBridge.js +110 -0
  55. package/dist/host/settingsBridge.js.map +1 -0
  56. package/dist/host/widgetPlacements.d.ts +44 -0
  57. package/dist/host/widgetPlacements.d.ts.map +1 -0
  58. package/dist/host/widgetPlacements.js +84 -0
  59. package/dist/host/widgetPlacements.js.map +1 -0
  60. package/dist/session.d.ts +6 -0
  61. package/dist/session.d.ts.map +1 -1
  62. package/dist/session.js.map +1 -1
  63. package/package.json +2 -2
  64. package/src/display/index.ts +4 -3
  65. package/src/display/profiles/index.ts +4 -4
  66. package/src/display/profiles/nimo.ts +38 -3
  67. package/src/display/profiles/textProfile.ts +62 -0
  68. package/src/display/profiles/types.ts +2 -0
  69. package/src/display/scene/degrade.ts +1 -1
  70. package/src/display/scene/process.ts +2 -3
  71. package/src/host/actionInvoke.ts +110 -0
  72. package/src/host/gestureClaims.ts +77 -0
  73. package/src/host/index.ts +10 -0
  74. package/src/host/manifestActions.ts +152 -0
  75. package/src/host/memory/MemoryStore.ts +704 -0
  76. package/src/host/memory/search.ts +214 -0
  77. package/src/host/miniappPermissions.ts +19 -0
  78. package/src/host/settingsBridge.ts +119 -0
  79. package/src/host/widgetPlacements.ts +135 -0
  80. package/src/session.ts +6 -0
  81. package/dist/display/profiles/z100.d.ts +0 -33
  82. package/dist/display/profiles/z100.d.ts.map +0 -1
  83. package/dist/display/profiles/z100.js +0 -182
  84. package/dist/display/profiles/z100.js.map +0 -1
  85. package/src/display/profiles/z100.ts +0 -198
@@ -0,0 +1,214 @@
1
+ /**
2
+ * Pure memory-timeline search — the matching engine behind MemoryStore.query
3
+ * and the assistant's get_transcripts tool.
4
+ *
5
+ * Lives outside MemoryStore so it is unit-testable and importable by the
6
+ * assistant's eval harness (which replays the exact host semantics against a
7
+ * mock corpus). Keep it dependency-free and runtime-neutral: it also runs
8
+ * under bun for tests.
9
+ *
10
+ * TWO MATCH MODES, deliberately different:
11
+ * - `contains`: exact case-insensitive substring — the pre-existing contract,
12
+ * kept verbatim for callers that need precision (codes, URLs, exact phrases).
13
+ * - `terms`: ANY-of term matching with per-word fuzziness. Speech-to-text
14
+ * mangles proper nouns ("Sompo" for "Sampo", "Korwin" for "Corwin"), so a
15
+ * term word matches a transcript token on exact/substring, small edit
16
+ * distance, OR same Soundex key. A multi-word term ("ring size") requires
17
+ * all of its words to match somewhere in the entry.
18
+ *
19
+ * The scan walks BACKWARDS from the newest in-window entry and stops at
20
+ * `limit` matches: the caller keeps the most recent matches anyway, and the
21
+ * common "last 90 minutes" query then touches dozens of entries instead of
22
+ * the full 4000-entry timeline. Window bounds are found by binary search on
23
+ * `at` (the timeline is maintained time-sorted).
24
+ */
25
+
26
+ export interface MemorySearchableEntry {
27
+ text: string
28
+ at: number
29
+ }
30
+
31
+ export interface MemorySearchQuery {
32
+ /** Epoch ms lower bound (inclusive). */
33
+ sinceMs?: number
34
+ /** Epoch ms upper bound (inclusive). */
35
+ untilMs?: number
36
+ /** Exact case-insensitive substring filter. */
37
+ contains?: string
38
+ /** Fuzzy any-of terms (see file header). Combined with `contains` as AND. */
39
+ terms?: string[]
40
+ /** Max matches kept (newest win). Caller enforces its own cap. */
41
+ limit: number
42
+ }
43
+
44
+ export interface MemorySearchResult<T> {
45
+ /** Matches in chronological order (newest last), at most `limit`. */
46
+ entries: T[]
47
+ /**
48
+ * Entries inside the TIME window before keyword filtering. Lets the caller
49
+ * tell "keyword matched nothing" apart from "window itself is empty" — the
50
+ * distinction that saves an LLM a blind retry round.
51
+ */
52
+ windowCount: number
53
+ }
54
+
55
+ /** Tokenized lowercase text per entry, cached for the entry object's lifetime. */
56
+ const tokenCache = new WeakMap<object, string[]>()
57
+
58
+ export function searchMemoryEntries<T extends MemorySearchableEntry>(
59
+ entries: readonly T[],
60
+ q: MemorySearchQuery,
61
+ ): MemorySearchResult<T> {
62
+ const since = q.sinceMs ?? 0
63
+ const until = q.untilMs ?? Number.MAX_SAFE_INTEGER
64
+ const lo = lowerBound(entries, since)
65
+ const hi = upperBound(entries, until) // exclusive
66
+ const windowCount = Math.max(0, hi - lo)
67
+
68
+ const needle = q.contains?.trim().toLowerCase() || null
69
+ const termWords = (q.terms ?? []).map((t) => tokenize(t)).filter((words) => words.length > 0)
70
+
71
+ const picked: T[] = []
72
+ for (let i = hi - 1; i >= lo && picked.length < q.limit; i--) {
73
+ const e = entries[i]
74
+ if (needle && !e.text.toLowerCase().includes(needle)) continue
75
+ if (termWords.length > 0 && !matchesAnyTerm(e, termWords)) continue
76
+ picked.push(e)
77
+ }
78
+ picked.reverse()
79
+ return {entries: picked, windowCount}
80
+ }
81
+
82
+ /** True when any term matches — a term matches iff ALL its words match a token. */
83
+ function matchesAnyTerm(entry: MemorySearchableEntry, termWords: string[][]): boolean {
84
+ let tokens = tokenCache.get(entry)
85
+ if (!tokens) {
86
+ tokens = tokenize(entry.text)
87
+ tokenCache.set(entry, tokens)
88
+ }
89
+ outer: for (const words of termWords) {
90
+ for (const word of words) {
91
+ if (!tokens.some((tok) => fuzzyWordMatch(word, tok))) continue outer
92
+ }
93
+ return true
94
+ }
95
+ return false
96
+ }
97
+
98
+ /**
99
+ * Does query word `w` match transcript token `t`?
100
+ * - exact, or substring for w of 3+ chars ("kestrel" in "kestrels")
101
+ * - for words of 5+ chars: bounded edit distance (1, or 2 for 7+ chars)
102
+ * — catches one-vowel STT swaps ("sompo"/"sampo", "korwin"/"corwin").
103
+ * 5 is the floor because at 4 chars a one-edit radius swallows unrelated
104
+ * common words ("code"→"mode"); mistranscribed NAMES are almost always 5+.
105
+ * - same Soundex key with similar length — catches phonetic respellings that
106
+ * edit distance misses ("warryn"/"warren" style doublings)
107
+ */
108
+ export function fuzzyWordMatch(w: string, t: string): boolean {
109
+ if (w === t) return true
110
+ if (w.length >= 3 && t.includes(w)) return true
111
+ if (w.length < 5 || t.length < 4) return false
112
+ const maxDist = w.length >= 7 ? 2 : 1
113
+ if (Math.abs(w.length - t.length) <= maxDist && editDistanceAtMost(w, t, maxDist)) return true
114
+ return Math.abs(w.length - t.length) <= 2 && soundex(w) === soundex(t)
115
+ }
116
+
117
+ /** Lowercase, strip diacritics, split on non-alphanumerics. */
118
+ export function tokenize(text: string): string[] {
119
+ return text
120
+ .toLowerCase()
121
+ .normalize("NFD")
122
+ .replace(/[\u0300-\u036f]/g, "")
123
+ .split(/[^a-z0-9]+/)
124
+ .filter((t) => t.length > 0)
125
+ }
126
+
127
+ /**
128
+ * Optimal-string-alignment edit distance, early-exited: returns whether
129
+ * dist(a, b) <= max. Transpositions count as one edit (common in STT output).
130
+ */
131
+ export function editDistanceAtMost(a: string, b: string, max: number): boolean {
132
+ if (Math.abs(a.length - b.length) > max) return false
133
+ let prev2: number[] | null = null
134
+ let prev = Array.from({length: b.length + 1}, (_, j) => j)
135
+ for (let i = 1; i <= a.length; i++) {
136
+ const cur = [i]
137
+ let rowMin = i
138
+ for (let j = 1; j <= b.length; j++) {
139
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1
140
+ let v = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + cost)
141
+ if (prev2 && i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
142
+ v = Math.min(v, prev2[j - 2] + 1)
143
+ }
144
+ cur.push(v)
145
+ if (v < rowMin) rowMin = v
146
+ }
147
+ if (rowMin > max) return false
148
+ prev2 = prev
149
+ prev = cur
150
+ }
151
+ return prev[b.length] <= max
152
+ }
153
+
154
+ const SOUNDEX_CODES: Record<string, string> = {
155
+ b: "1",
156
+ f: "1",
157
+ p: "1",
158
+ v: "1",
159
+ c: "2",
160
+ g: "2",
161
+ j: "2",
162
+ k: "2",
163
+ q: "2",
164
+ s: "2",
165
+ x: "2",
166
+ z: "2",
167
+ d: "3",
168
+ t: "3",
169
+ l: "4",
170
+ m: "5",
171
+ n: "5",
172
+ r: "6",
173
+ }
174
+
175
+ /** Classic Soundex. Empty input returns "". */
176
+ export function soundex(word: string): string {
177
+ const w = word.toLowerCase().replace(/[^a-z]/g, "")
178
+ if (!w) return ""
179
+ let out = w[0].toUpperCase()
180
+ let lastCode = SOUNDEX_CODES[w[0]] ?? ""
181
+ for (let i = 1; i < w.length && out.length < 4; i++) {
182
+ const ch = w[i]
183
+ const code = SOUNDEX_CODES[ch] ?? ""
184
+ // h/w are transparent: they don't reset the adjacent-duplicate rule.
185
+ if (ch === "h" || ch === "w") continue
186
+ if (code && code !== lastCode) out += code
187
+ lastCode = code
188
+ }
189
+ return out.padEnd(4, "0")
190
+ }
191
+
192
+ /** First index with at >= value (entries time-sorted ascending). */
193
+ function lowerBound(entries: readonly MemorySearchableEntry[], value: number): number {
194
+ let lo = 0
195
+ let hi = entries.length
196
+ while (lo < hi) {
197
+ const mid = (lo + hi) >> 1
198
+ if (entries[mid].at < value) lo = mid + 1
199
+ else hi = mid
200
+ }
201
+ return lo
202
+ }
203
+
204
+ /** First index with at > value (i.e. exclusive end for an inclusive bound). */
205
+ function upperBound(entries: readonly MemorySearchableEntry[], value: number): number {
206
+ let lo = 0
207
+ let hi = entries.length
208
+ while (lo < hi) {
209
+ const mid = (lo + hi) >> 1
210
+ if (entries[mid].at <= value) lo = mid + 1
211
+ else hi = mid
212
+ }
213
+ return lo
214
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Whether a miniapp may use an API gated on a manifest permission
3
+ * (miniapp.json -> permissions): `session.miniapps` needs MANAGE_MINIAPPS,
4
+ * `session.settings` PLATFORM_SETTINGS, the notification app list
5
+ * READ_NOTIFICATIONS. System apps pass without declaring it. Pure, so the
6
+ * runtime only does the reply.
7
+ */
8
+ export interface PermissionCaller {
9
+ system: boolean
10
+ permissions?: ReadonlyArray<{type?: string}>
11
+ }
12
+
13
+ export function declaresPermission(permissions: PermissionCaller["permissions"], permission: string): boolean {
14
+ return (permissions ?? []).some((declared) => declared.type?.toUpperCase() === permission)
15
+ }
16
+
17
+ export function mayUsePermission(caller: PermissionCaller, permission: string): boolean {
18
+ return caller.system || declaresPermission(caller.permissions, permission)
19
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * The settings bridge's vocabulary (session.settings): which engine settings
3
+ * a miniapp with the PLATFORM_SETTINGS permission may read or write, the
4
+ * derived read-only keys the engine computes rather than stores, and the
5
+ * request validation. Pure, so the runtime's handlers stay thin and this can
6
+ * be tested without the native import surface the runtime pulls in.
7
+ *
8
+ * A dashboard miniapp is the usual consumer: it edits the notification,
9
+ * glasses-menu, display-position, brightness and microphone keys the phone's
10
+ * settings screens do, through the store, so persistence, server sync and the
11
+ * Bluetooth sync behave as if a phone screen wrote them. A dashboard's own
12
+ * look is not here; it keeps that in its storage.
13
+ */
14
+
15
+ export type SettingsBridgeAccess = "read" | "write"
16
+
17
+ /** Stored settings the bridge serves, by key, with what a permitted app may do to each. */
18
+ export const SETTINGS_BRIDGE_KEYS: Readonly<Record<string, SettingsBridgeAccess>> = {
19
+ // The dashboard's master switch is a phone-side debug knob.
20
+ custom_dashboard_enabled: "read",
21
+ head_up_angle: "write",
22
+ // Where the glasses draw; each model's steps are its display.positionRange.
23
+ dashboard_depth: "write",
24
+ dashboard_height: "write",
25
+ // Device settings the dashboard's glasses Settings page edits.
26
+ brightness: "write",
27
+ auto_brightness: "write",
28
+ // Per paired model: the store resolves the indexed key.
29
+ preferred_mic: "write",
30
+ menu_apps: "write",
31
+ notifications_enabled: "write",
32
+ notifications_popups: "write",
33
+ notifications_popup_seconds: "write",
34
+ notifications_batch_seconds: "write",
35
+ notifications_hold_during_apps: "write",
36
+ notifications_ignore_while_active: "write",
37
+ notifications_blocklist: "write",
38
+ // Apps the glasses reported posting notifications; the engine records it.
39
+ notification_seen_apps: "read",
40
+ }
41
+
42
+ // What each stored key holds until someone writes it; the Glassly App's settings store reads these.
43
+ const SETTINGS_BRIDGE_DEFAULTS: Readonly<Record<string, unknown>> = {
44
+ custom_dashboard_enabled: true,
45
+ head_up_angle: 45,
46
+ dashboard_depth: 2,
47
+ dashboard_height: 4,
48
+ brightness: 50,
49
+ auto_brightness: true,
50
+ preferred_mic: "auto",
51
+ menu_apps: null,
52
+ notifications_enabled: true,
53
+ notifications_popups: true,
54
+ notifications_popup_seconds: 5,
55
+ notifications_batch_seconds: 0,
56
+ notifications_hold_during_apps: true,
57
+ notifications_ignore_while_active: true,
58
+ notifications_blocklist: [],
59
+ notification_seen_apps: [],
60
+ }
61
+
62
+ /** A stored key's default, as a fresh copy; undefined for a key the bridge does not store. */
63
+ export function settingsBridgeDefault(key: string): unknown {
64
+ const value = SETTINGS_BRIDGE_DEFAULTS[key]
65
+ return value !== null && typeof value === "object" ? JSON.parse(JSON.stringify(value)) : value
66
+ }
67
+
68
+ /**
69
+ * Read-only keys the engine computes: whether the wearer can see the phone,
70
+ * whether the foreground miniapp is drawing on the glasses, and the paired
71
+ * controllers with their battery and input. They change on their own clocks;
72
+ * the runtime pushes them like stored keys.
73
+ */
74
+ export const DERIVED_SETTINGS_KEYS = ["phone_active", "foreground_app_on_screen", "controllers"] as const
75
+ export type DerivedSettingsKey = (typeof DERIVED_SETTINGS_KEYS)[number]
76
+
77
+ export function isDerivedSettingsKey(key: string): key is DerivedSettingsKey {
78
+ return (DERIVED_SETTINGS_KEYS as readonly string[]).includes(key)
79
+ }
80
+
81
+ /** What a permitted app may do with `key`, or null when the bridge does not serve it. */
82
+ export function settingsBridgeAccess(key: string): SettingsBridgeAccess | null {
83
+ if (isDerivedSettingsKey(key)) return "read"
84
+ return SETTINGS_BRIDGE_KEYS[key] ?? null
85
+ }
86
+
87
+ /** Every key the bridge serves, stored then derived. */
88
+ export function allSettingsBridgeKeys(): string[] {
89
+ return [...Object.keys(SETTINGS_BRIDGE_KEYS), ...DERIVED_SETTINGS_KEYS]
90
+ }
91
+
92
+ /**
93
+ * The keys a SETTINGS_GET asks for: everything when `requested` is absent,
94
+ * else the known ones among the requested strings (unknown keys are left
95
+ * out, never rejected).
96
+ */
97
+ export function selectSettingsBridgeKeys(requested: unknown): string[] {
98
+ if (requested === undefined || requested === null) return allSettingsBridgeKeys()
99
+ if (!Array.isArray(requested)) return []
100
+ return requested.filter((key): key is string => typeof key === "string" && settingsBridgeAccess(key) !== null)
101
+ }
102
+
103
+ export type SettingsSetValidation =
104
+ {ok: true; key: string; value: unknown} | {ok: false; code: "INVALID_ARGUMENT" | "NOT_PERMITTED"; message: string}
105
+
106
+ /** A SETTINGS_SET payload: a writable key and a JSON value (undefined is not a value). */
107
+ export function validateSettingsSet(payload: Record<string, unknown>): SettingsSetValidation {
108
+ const key = payload.key
109
+ if (typeof key !== "string" || !key) {
110
+ return {ok: false, code: "INVALID_ARGUMENT", message: "settings.set requires a key"}
111
+ }
112
+ const access = settingsBridgeAccess(key)
113
+ if (access === null) return {ok: false, code: "INVALID_ARGUMENT", message: `Unknown setting "${key}"`}
114
+ if (access !== "write") return {ok: false, code: "NOT_PERMITTED", message: `Setting "${key}" is read-only`}
115
+ if (!("value" in payload) || payload.value === undefined) {
116
+ return {ok: false, code: "INVALID_ARGUMENT", message: "settings.set requires a value"}
117
+ }
118
+ return {ok: true, key, value: payload.value}
119
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Who placed which widget where: the pure bookkeeping behind the runtime's
3
+ * widget routing. A placement is one host's box for one provider widget;
4
+ * a provider is placed while any host holds one of its widgets. Frames are
5
+ * kept per widget and view so a host that places one again gets the last
6
+ * card and expanded frames at once.
7
+ */
8
+
9
+ export type WidgetView = "card" | "expanded"
10
+
11
+ export interface WidgetBox {
12
+ size: "XS" | "XSM" | "SM" | "MD" | "LG"
13
+ width: number
14
+ height: number
15
+ }
16
+
17
+ export interface Placement {
18
+ hostPackageName: string
19
+ providerPackageName: string
20
+ widgetId: string
21
+ box: WidgetBox
22
+ }
23
+
24
+ export interface WidgetPlacements {
25
+ /** Keyed by `${host}|${provider}/${widgetId}`. */
26
+ placements: ReadonlyMap<string, Placement>
27
+ /** The latest frame per `${provider}/${widgetId}` and view. */
28
+ frames: ReadonlyMap<string, Readonly<Partial<Record<WidgetView, unknown[]>>>>
29
+ }
30
+
31
+ export const widgetKey = (providerPackageName: string, widgetId: string): string => `${providerPackageName}/${widgetId}`
32
+ const placementKey = (hostPackageName: string, providerPackageName: string, widgetId: string): string =>
33
+ `${hostPackageName}|${widgetKey(providerPackageName, widgetId)}`
34
+
35
+ export function emptyWidgetPlacements(): WidgetPlacements {
36
+ return {placements: new Map(), frames: new Map()}
37
+ }
38
+
39
+ export function placeWidget(state: WidgetPlacements, placement: Placement): WidgetPlacements {
40
+ const placements = new Map(state.placements)
41
+ placements.set(placementKey(placement.hostPackageName, placement.providerPackageName, placement.widgetId), placement)
42
+ return {...state, placements}
43
+ }
44
+
45
+ export function unplaceWidget(
46
+ state: WidgetPlacements,
47
+ hostPackageName: string,
48
+ providerPackageName: string,
49
+ widgetId: string,
50
+ ): WidgetPlacements {
51
+ const key = placementKey(hostPackageName, providerPackageName, widgetId)
52
+ if (!state.placements.has(key)) return state
53
+ const placements = new Map(state.placements)
54
+ placements.delete(key)
55
+ return {...state, placements}
56
+ }
57
+
58
+ /** A host went away: drop everything it placed. */
59
+ export function dropHost(state: WidgetPlacements, hostPackageName: string): WidgetPlacements {
60
+ const placements = new Map(state.placements)
61
+ for (const [key, placement] of state.placements) {
62
+ if (placement.hostPackageName === hostPackageName) placements.delete(key)
63
+ }
64
+ return placements.size === state.placements.size ? state : {...state, placements}
65
+ }
66
+
67
+ /** A provider went away: drop its placements, keep its frames for the placeholder. */
68
+ export function dropProvider(state: WidgetPlacements, providerPackageName: string): WidgetPlacements {
69
+ const placements = new Map(state.placements)
70
+ for (const [key, placement] of state.placements) {
71
+ if (placement.providerPackageName === providerPackageName) placements.delete(key)
72
+ }
73
+ return placements.size === state.placements.size ? state : {...state, placements}
74
+ }
75
+
76
+ export function setFrame(
77
+ state: WidgetPlacements,
78
+ providerPackageName: string,
79
+ widgetId: string,
80
+ elements: unknown[],
81
+ view: WidgetView = "card",
82
+ ): WidgetPlacements {
83
+ const key = widgetKey(providerPackageName, widgetId)
84
+ const frames = new Map(state.frames)
85
+ frames.set(key, {...state.frames.get(key), [view]: elements})
86
+ return {...state, frames}
87
+ }
88
+
89
+ export function frameOf(
90
+ state: WidgetPlacements,
91
+ providerPackageName: string,
92
+ widgetId: string,
93
+ view: WidgetView = "card",
94
+ ): unknown[] | null {
95
+ return state.frames.get(widgetKey(providerPackageName, widgetId))?.[view] ?? null
96
+ }
97
+
98
+ export function placementOf(
99
+ state: WidgetPlacements,
100
+ hostPackageName: string,
101
+ providerPackageName: string,
102
+ widgetId: string,
103
+ ): Placement | null {
104
+ return state.placements.get(placementKey(hostPackageName, providerPackageName, widgetId)) ?? null
105
+ }
106
+
107
+ /** Hosts holding this widget, each once. */
108
+ export function hostsOf(state: WidgetPlacements, providerPackageName: string, widgetId: string): string[] {
109
+ const hosts = new Set<string>()
110
+ for (const placement of state.placements.values()) {
111
+ if (placement.providerPackageName === providerPackageName && placement.widgetId === widgetId) {
112
+ hosts.add(placement.hostPackageName)
113
+ }
114
+ }
115
+ return Array.from(hosts)
116
+ }
117
+
118
+ /** Providers with at least one widget placed. */
119
+ export function placedProviders(state: WidgetPlacements): Set<string> {
120
+ const providers = new Set<string>()
121
+ for (const placement of state.placements.values()) providers.add(placement.providerPackageName)
122
+ return providers
123
+ }
124
+
125
+ export function isProviderPlaced(state: WidgetPlacements, providerPackageName: string): boolean {
126
+ for (const placement of state.placements.values()) {
127
+ if (placement.providerPackageName === providerPackageName) return true
128
+ }
129
+ return false
130
+ }
131
+
132
+ /** The placements a host holds on a provider, for re-delivering boxes. */
133
+ export function placementsBy(state: WidgetPlacements, hostPackageName: string): Placement[] {
134
+ return Array.from(state.placements.values()).filter((placement) => placement.hostPackageName === hostPackageName)
135
+ }
package/src/session.ts CHANGED
@@ -93,6 +93,12 @@ export interface DisplayCapabilities {
93
93
  * glasses can show the overlay slot (see display.showView).
94
94
  */
95
95
  views?: Array<"main" | "dashboard">
96
+ /**
97
+ * Id of the display profile the Glassly App wraps this app's text with right
98
+ * now (see `textProfileFor` in `@glassly/miniapp/display`). Absent on older
99
+ * Glassly App versions.
100
+ */
101
+ textProfile?: string
96
102
  /** Legacy capability fields (resolution, isColor, maxTextLines, …) ride along. */
97
103
  [key: string]: unknown
98
104
  }
@@ -1,33 +0,0 @@
1
- import { DisplayProfile } from "./types";
2
- /**
3
- * Vuzix Z100 Smart Glasses Display Profile
4
- *
5
- * The Z100 has a green monochrome display with 640x480 resolution.
6
- * It uses the Vuzix Ultralite SDK and Noto Sans font family.
7
- *
8
- * Display specs:
9
- * - Resolution: 640x480
10
- * - Usable text width: ~390px (empirically tested - SDK applies margins)
11
- * - Color: Green monochrome
12
- * - Max text lines: 7
13
- * - Font: Noto Sans Regular at 21px
14
- * - No bitmap support via text commands
15
- * - Adjustable brightness
16
- *
17
- * NOTE: The Vuzix Ultralite SDK handles text rendering internally and applies
18
- * its own margins/padding. The usable text width is significantly less than
19
- * the physical 640px resolution. Empirical testing shows ~42 characters of
20
- * mixed text (387px measured) fits on one line before the SDK wraps.
21
- */
22
- export declare const Z100_PROFILE: DisplayProfile;
23
- /**
24
- * Get the hyphen width for Z100 in pixels.
25
- * Used for line breaking calculations.
26
- */
27
- export declare const Z100_HYPHEN_WIDTH_PX = 7;
28
- /**
29
- * Get the space width for Z100 in pixels.
30
- * Used for column alignment calculations.
31
- */
32
- export declare const Z100_SPACE_WIDTH_PX = 5;
33
- //# sourceMappingURL=z100.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"z100.d.ts","sourceRoot":"","sources":["../../../src/display/profiles/z100.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,SAAS,CAAA;AAyHtC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,YAAY,EAAE,cA4C1B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAA;AAErC;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAA"}