@glassly/miniapp 0.4.3-dev.1267 → 0.4.3-dev.1269

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 (52) hide show
  1. package/README.md +9 -1
  2. package/dist/host/index.d.ts +1 -0
  3. package/dist/host/index.d.ts.map +1 -1
  4. package/dist/host/index.js +1 -0
  5. package/dist/host/index.js.map +1 -1
  6. package/dist/host/settingsBridge.d.ts +31 -8
  7. package/dist/host/settingsBridge.d.ts.map +1 -1
  8. package/dist/host/settingsBridge.js +63 -11
  9. package/dist/host/settingsBridge.js.map +1 -1
  10. package/dist/host/ttsSanitizer.d.ts +5 -0
  11. package/dist/host/ttsSanitizer.d.ts.map +1 -0
  12. package/dist/host/ttsSanitizer.js +61 -0
  13. package/dist/host/ttsSanitizer.js.map +1 -0
  14. package/dist/modules/cloud.d.ts +2 -0
  15. package/dist/modules/cloud.d.ts.map +1 -1
  16. package/dist/modules/cloud.js +17 -7
  17. package/dist/modules/cloud.js.map +1 -1
  18. package/dist/modules/settings.d.ts +4 -1
  19. package/dist/modules/settings.d.ts.map +1 -1
  20. package/dist/modules/settings.js +4 -1
  21. package/dist/modules/settings.js.map +1 -1
  22. package/dist/reader/Reader.d.ts +147 -0
  23. package/dist/reader/Reader.d.ts.map +1 -0
  24. package/dist/reader/Reader.js +525 -0
  25. package/dist/reader/Reader.js.map +1 -0
  26. package/dist/reader/document.d.ts +54 -0
  27. package/dist/reader/document.d.ts.map +1 -0
  28. package/dist/reader/document.js +114 -0
  29. package/dist/reader/document.js.map +1 -0
  30. package/dist/reader/index.d.ts +12 -0
  31. package/dist/reader/index.d.ts.map +1 -0
  32. package/dist/reader/index.js +9 -0
  33. package/dist/reader/index.js.map +1 -0
  34. package/dist/reader/lens.d.ts +55 -0
  35. package/dist/reader/lens.d.ts.map +1 -0
  36. package/dist/reader/lens.js +210 -0
  37. package/dist/reader/lens.js.map +1 -0
  38. package/dist/sub-path-types.test-d.d.ts +3 -1
  39. package/dist/sub-path-types.test-d.d.ts.map +1 -1
  40. package/dist/sub-path-types.test-d.js +1 -7
  41. package/dist/sub-path-types.test-d.js.map +1 -1
  42. package/package.json +6 -2
  43. package/src/host/index.ts +1 -0
  44. package/src/host/settingsBridge.ts +70 -11
  45. package/src/host/ttsSanitizer.ts +66 -0
  46. package/src/modules/cloud.ts +21 -7
  47. package/src/modules/settings.ts +4 -1
  48. package/src/reader/Reader.ts +580 -0
  49. package/src/reader/document.ts +154 -0
  50. package/src/reader/index.ts +12 -0
  51. package/src/reader/lens.ts +250 -0
  52. package/src/sub-path-types.test-d.ts +5 -0
@@ -0,0 +1,66 @@
1
+ const HTML_ENTITIES: Record<string, string> = {
2
+ "&amp;": "&",
3
+ "&lt;": "<",
4
+ "&gt;": ">",
5
+ "&quot;": '"',
6
+ "&#39;": "'",
7
+ }
8
+
9
+ /** Convert display-oriented text into plain words before TTS synthesis. */
10
+ export function sanitizeTtsText(text: string): string {
11
+ let speech = text.replace(/&(amp|lt|gt|quot|#39);/gi, (entity) => HTML_ENTITIES[entity.toLowerCase()] ?? entity)
12
+
13
+ speech = speech
14
+ .replace(/<say-as\b[^>]*>(.*?)<\/say-as>/gis, "$1")
15
+ .replace(/<\/?[a-z][a-z0-9-]*(?:\s[^<>]*?)?\s*\/?>/gi, " ")
16
+ .replace(/\[([^\]]+)]\([^)]+\)/g, "$1")
17
+ .replace(/`([^`]*)`/g, "$1")
18
+ .replace(/(-?\d+(?:[.,]\d+)?)\s*(?:°\s*f\b|℉)/gi, "$1 degrees Fahrenheit")
19
+ .replace(/(-?\d+(?:[.,]\d+)?)\s*(?:°\s*c\b|℃)/gi, "$1 degrees Celsius")
20
+ .replace(/(-?\d+(?:[.,]\d+)?)\s*°/g, "$1 degrees")
21
+ .replace(/<=/g, " less than or equal to ")
22
+ .replace(/>=/g, " greater than or equal to ")
23
+ .replace(/</g, " less than ")
24
+ .replace(/>/g, " greater than ")
25
+ .replace(/[[\]{}()]/g, " ")
26
+ .replace(/(degrees Fahrenheit)\s+(-?\d+(?:[.,]\d+)? degrees Celsius)\b/gi, "$1 or $2")
27
+ .replace(/(degrees Celsius)\s+(-?\d+(?:[.,]\d+)? degrees Fahrenheit)\b/gi, "$1 or $2")
28
+ .replace(/&/g, " and ")
29
+ .replace(/\+/g, " plus ")
30
+ .replace(/=/g, " equals ")
31
+ .replace(/#/g, " hash ")
32
+ .replace(/@/g, " at ")
33
+ .replace(/%/g, " percent ")
34
+ .replace(/\\/g, " backslash ")
35
+ .replace(/\//g, (slash, offset, source) => {
36
+ const numericSeparator = /\d/.test(source[offset - 1] ?? "") && /\d/.test(source[offset + 1] ?? "")
37
+ return numericSeparator ? slash : " slash "
38
+ })
39
+ .replace(/\*/g, " star ")
40
+
41
+ return speech
42
+ .replace(/\s+([,.;:!?])/g, "$1")
43
+ .replace(/\s+/g, " ")
44
+ .trim()
45
+ }
46
+
47
+ /** Prepare an already-trimmed sentence list while preserving the exact-text opt-out. */
48
+ export function prepareTtsSentences(sentences: string[], enableSanitization = true): string[] {
49
+ if (!enableSanitization) return sentences
50
+
51
+ const sanitized = sentences.map((sentence) => sanitizeTtsText(sentence)).filter(Boolean)
52
+
53
+ return sanitized.map((sentence, index) => {
54
+ const previous = sanitized[index - 1]
55
+ if (!previous) return sentence
56
+
57
+ const followsFahrenheit = /degrees Fahrenheit[,.;:!?]?$/i.test(previous)
58
+ const followsCelsius = /degrees Celsius[,.;:!?]?$/i.test(previous)
59
+ const startsWithFahrenheit = /^-?\d+(?:[.,]\d+)? degrees Fahrenheit\b/i.test(sentence)
60
+ const startsWithCelsius = /^-?\d+(?:[.,]\d+)? degrees Celsius\b/i.test(sentence)
61
+
62
+ return (followsFahrenheit && startsWithCelsius) || (followsCelsius && startsWithFahrenheit)
63
+ ? `or ${sentence}`
64
+ : sentence
65
+ })
66
+ }
@@ -15,6 +15,7 @@ export type CloudClientConnectionStatus = "connected" | "connecting" | "reconnec
15
15
  export type CloudClientAudioTransport = "udp" | "ws" | "offline" | "none"
16
16
  /** Metered cloud features the account's plan can run out of. */
17
17
  export type CloudQuotaFeature = "transcription"
18
+ export type CloudSpeechFeature = "transcription" | "translation"
18
19
 
19
20
  export interface CloudClientStatus {
20
21
  status: CloudClientConnectionStatus
@@ -25,6 +26,7 @@ export interface CloudClientStatus {
25
26
  * declined. Empty on hosts that predate the field.
26
27
  */
27
28
  quotaBlocked: CloudQuotaFeature[]
29
+ speechFailed: CloudSpeechFeature[]
28
30
  }
29
31
 
30
32
  type CloudEmitterEvents = {
@@ -37,9 +39,19 @@ const DEFAULT_STATUS: CloudClientStatus = {
37
39
  status: "disconnected",
38
40
  audioTransport: "none",
39
41
  quotaBlocked: [],
42
+ speechFailed: [],
40
43
  }
41
44
 
42
45
  const QUOTA_FEATURES: readonly CloudQuotaFeature[] = ["transcription"]
46
+ const SPEECH_FEATURES: readonly CloudSpeechFeature[] = ["transcription", "translation"]
47
+
48
+ function knownFeatures<T extends string>(raw: unknown, known: readonly T[]): T[] {
49
+ return Array.isArray(raw) ? raw.filter((f): f is T => known.includes(f as T)) : []
50
+ }
51
+
52
+ function sameList(a: readonly string[], b: readonly string[]): boolean {
53
+ return a.length === b.length && a.every((f, i) => f === b[i])
54
+ }
43
55
 
44
56
  function normalizeCloudStatus(data: unknown): CloudClientStatus | null {
45
57
  if (!data || typeof data !== "object") return null
@@ -59,18 +71,20 @@ function normalizeCloudStatus(data: unknown): CloudClientStatus | null {
59
71
  return null
60
72
  }
61
73
 
62
- const quotaBlocked = Array.isArray(raw.quotaBlocked)
63
- ? raw.quotaBlocked.filter((f): f is CloudQuotaFeature => QUOTA_FEATURES.includes(f as CloudQuotaFeature))
64
- : []
65
- return {status, audioTransport, quotaBlocked}
74
+ return {
75
+ status,
76
+ audioTransport,
77
+ quotaBlocked: knownFeatures(raw.quotaBlocked, QUOTA_FEATURES),
78
+ speechFailed: knownFeatures(raw.speechFailed, SPEECH_FEATURES),
79
+ }
66
80
  }
67
81
 
68
82
  function sameStatus(a: CloudClientStatus, b: CloudClientStatus): boolean {
69
83
  return (
70
84
  a.status === b.status &&
71
85
  a.audioTransport === b.audioTransport &&
72
- a.quotaBlocked.length === b.quotaBlocked.length &&
73
- a.quotaBlocked.every((f, i) => f === b.quotaBlocked[i])
86
+ sameList(a.quotaBlocked, b.quotaBlocked) &&
87
+ sameList(a.speechFailed, b.speechFailed)
74
88
  )
75
89
  }
76
90
 
@@ -90,7 +104,7 @@ export class CloudModule {
90
104
 
91
105
  /** Latest status snapshot pushed by the phone runtime. */
92
106
  get status(): CloudClientStatus {
93
- return {...this.current, quotaBlocked: [...this.current.quotaBlocked]}
107
+ return {...this.current, quotaBlocked: [...this.current.quotaBlocked], speechFailed: [...this.current.speechFailed]}
94
108
  }
95
109
 
96
110
  /** Whether the plan quota is refusing `feature` right now. */
@@ -1,7 +1,10 @@
1
1
  /**
2
2
  * @fileoverview SettingsModule — `session.settings`, the engine's settings
3
3
  * store behind an allowlist. Needs the PLATFORM_SETTINGS manifest
4
- * permission: without it every call rejects with PERMISSION_NOT_DECLARED.
4
+ * permission, except for the wearer's reading settings (`reading_wpm` and
5
+ * the other `reading_*` keys), which every miniapp may read and follow, and
6
+ * whose speed it may set. Without it, other keys reject with
7
+ * PERMISSION_NOT_DECLARED.
5
8
  * A dashboard miniapp is the usual consumer: it reads and edits the
6
9
  * notification and glasses-menu keys the phone's settings screens used to,
7
10
  * so firmware sync and the host's notification policy keep one source of