@glassly/engine 0.3.2-dev.574 → 0.3.2-dev.580

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.
@@ -2,7 +2,8 @@
2
2
  * Decides whether on-device Sherpa STT should produce transcripts for local
3
3
  * miniapps, instead of (or in addition to) cloud transcription. Local STT is
4
4
  * active when the cloud is unavailable (disconnected or refusing STT for plan
5
- * quota) or any subscription requires `forceLocal`.
5
+ * quota) and some subscriber accepts fallback text, or any subscription
6
+ * requires `forceLocal`.
6
7
  *
7
8
  * Activation flips `localSttFallbackActive` in the settings store, which
8
9
  * the bluetooth-sdk native side reads to decide whether to feed PCM into
@@ -24,6 +25,8 @@ declare class LocalSttFallbackCoordinator {
24
25
  private static instance;
25
26
  private hasTranscriptionSubscription;
26
27
  private hasForceLocalSubscription;
28
+ /** Some default-route subscriber takes on-device text while the primary is down. */
29
+ private hasFallbackSubscription;
27
30
  private activeLanguage;
28
31
  /**
29
32
  * Default to "cloud is up" so we never accidentally activate local STT before
@@ -64,7 +67,7 @@ declare class LocalSttFallbackCoordinator {
64
67
  getActiveLanguage(): string | null;
65
68
  /** The cause of the current activation, or null while inactive. */
66
69
  getReason(): LocalSttFallbackReason | null;
67
- onSubscriptionChange(hasTranscription: boolean, language: string | null, hasForceLocal?: boolean): void;
70
+ onSubscriptionChange(hasTranscription: boolean, language: string | null, hasForceLocal?: boolean, acceptsFallback?: boolean): void;
68
71
  /**
69
72
  * Informational hook, retained for API stability. No longer called: the
70
73
  * authoritative switching signal is the cloud-client adapter (local miniapps
@@ -1 +1 @@
1
- {"version":3,"file":"LocalSttFallbackCoordinator.d.ts","sourceRoot":"","sources":["../../src/services/LocalSttFallbackCoordinator.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAC9B,aAAa,GACb,oBAAoB,GACpB,gBAAgB,GAChB,WAAW,GACX,sBAAsB,CAAA;AA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AEzB;;;;OAIG;IACG,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9D,iBAAiB,IAAI,OAAO;IAI5B,uEAAuE;IACvE,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAQnE;2CACuC;IACvC,OAAO,CAAC,SAAS;YAWH,SAAS;IAmBvB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,aAAa;YAQP,aAAa;YASb,gBAAgB;IAqB9B,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,GAAG;CAGZ;AAED,QAAA,MAAM,2BAA2B,6BAA4C,CAAA;AAC7E,eAAe,2BAA2B,CAAA"}
@@ -7,6 +7,8 @@ class LocalSttFallbackCoordinator {
7
7
  static instance;
8
8
  hasTranscriptionSubscription = false;
9
9
  hasForceLocalSubscription = false;
10
+ /** Some default-route subscriber takes on-device text while the primary is down. */
11
+ hasFallbackSubscription = false;
10
12
  activeLanguage = null;
11
13
  /**
12
14
  * Default to "cloud is up" so we never accidentally activate local STT before
@@ -87,10 +89,11 @@ class LocalSttFallbackCoordinator {
87
89
  getReason() {
88
90
  return this.localActive ? this.currentReason() : null;
89
91
  }
90
- onSubscriptionChange(hasTranscription, language, hasForceLocal = false) {
91
- this.log(`onSubscriptionChange(hasTx=${hasTranscription}, lang=${language}, forceLocal=${hasForceLocal})`);
92
+ onSubscriptionChange(hasTranscription, language, hasForceLocal = false, acceptsFallback = true) {
93
+ this.log(`onSubscriptionChange(hasTx=${hasTranscription}, lang=${language}, forceLocal=${hasForceLocal}, fallback=${acceptsFallback})`);
92
94
  this.hasTranscriptionSubscription = hasTranscription;
93
95
  this.hasForceLocalSubscription = hasTranscription && hasForceLocal;
96
+ this.hasFallbackSubscription = hasTranscription && acceptsFallback;
94
97
  this.activeLanguage = hasTranscription ? language : null;
95
98
  void this.reconcile();
96
99
  }
@@ -218,7 +221,8 @@ class LocalSttFallbackCoordinator {
218
221
  this.publishReason();
219
222
  }
220
223
  shouldUseLocalStt() {
221
- return this.hasTranscriptionSubscription && (this.hasForceLocalSubscription || !this.primaryUp());
224
+ return (this.hasTranscriptionSubscription &&
225
+ (this.hasForceLocalSubscription || (this.hasFallbackSubscription && !this.primaryUp())));
222
226
  }
223
227
  log(msg) {
224
228
  console.log(`[LocalSttFallback] ${msg}`);
@@ -1 +1 @@
1
- {"version":3,"file":"LocalSttFallbackCoordinator.js","sourceRoot":"","sources":["../../src/services/LocalSttFallbackCoordinator.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,iCAAiC,CAAA;AAC1D,OAAO,EAAC,oBAAoB,EAAC,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAA;AACvD,OAAO,eAAe,MAAM,mBAAmB,CAAA;AA8B/C,MAAM,2BAA2B;IACvB,MAAM,CAAC,QAAQ,CAA6B;IAE5C,4BAA4B,GAAG,KAAK,CAAA;IACpC,yBAAyB,GAAG,KAAK,CAAA;IACjC,cAAc,GAAkB,IAAI,CAAA;IAC5C;;;;;OAKG;IACK,cAAc,GAAG,IAAI,CAAA;IACrB,WAAW,GAAG,KAAK,CAAA;IACnB,QAAQ,GAAyB,IAAI,CAAA;IACrC,oBAAoB,GAAG,KAAK,CAAA;IACpC;;;;;;OAMG;IACK,mBAAmB,GAAG,KAAK,CAAA;IAC3B,mBAAmB,GAAG,IAAI,CAAA;IAClC;;;;;OAKG;IACK,eAAe,GAAG,KAAK,CAAA;IAE/B;QACE,wEAAwE;QACxE,uEAAuE;QACvE,wEAAwE;QACxE,6BAA6B;QAC7B,gBAAgB,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAA;QAC1F,gBAAgB,CAA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["import BluetoothSdk from \"@glassly/bluetooth-sdk/internal\"\nimport {ISLAND_SETTINGS_KEYS} from \"../runtime/config\"\nimport {useSettingsStore} from \"../stores/settings\"\nimport {cloudClientService} from \"./CloudClientService\"\nimport sttModelManager from \"./STTModelManager\"\n\n/**\n * Decides whether on-device Sherpa STT should produce transcripts for local\n * miniapps, instead of (or in addition to) cloud transcription. Local STT is\n * active when the cloud is unavailable (disconnected or refusing STT for plan\n * quota) or any subscription requires `forceLocal`.\n *\n * Activation flips `localSttFallbackActive` in the settings store, which\n * the bluetooth-sdk native side reads to decide whether to feed PCM into\n * the SherpaOnnxTranscriber. Local transcripts then flow back through the\n * `local_transcription` Bridge event; the host wires that event to\n * `localMiniappRuntime.forwardEvent`, with this coordinator providing the\n * subscription-active gate so we never publish transcripts to miniapps that\n * aren't asking for them. LocalMiniappRuntime filters mixed local/cloud\n * delivery per miniapp.\n */\n/**\n * Why local STT is currently active, mirrored into the\n * `local_stt_fallback_reason` setting (\"\" while inactive) so UI can show it.\n * When several causes hold at once, the primary-path outage wins over\n * `force_local` (a forced subscription would keep local STT on either way).\n */\nexport type LocalSttFallbackReason =\n | \"force_local\"\n | \"cloud_disconnected\"\n | \"cloud_disabled\"\n | \"stt_quota\"\n | \"provider_unreachable\"\n\nclass LocalSttFallbackCoordinator {\n private static instance: LocalSttFallbackCoordinator\n\n private hasTranscriptionSubscription = false\n private hasForceLocalSubscription = false\n private activeLanguage: string | null = null\n /**\n * Default to \"cloud is up\" so we never accidentally activate local STT before\n * the cloud client has had a chance to start. We attach lazily on the first\n * subscription/reconcile pass; once attached, this field reflects the real\n * cloud-client runtime status.\n */\n private cloudConnected = true\n private localActive = false\n private starting: Promise<void> | null = null\n private cloudAdapterAttached = false\n /**\n * Soniox-direct (user API key) state, pushed by SonioxDirectService. While\n * enabled, IT is the primary transcription path — cloud connectivity is\n * irrelevant and sherpa engages on Soniox health instead. Defaults healthy\n * for the same reason cloudConnected defaults true: never activate local STT\n * before the primary has had a chance to come up.\n */\n private sonioxDirectEnabled = false\n private sonioxDirectHealthy = true\n /**\n * Cloud STT refused for plan quota (`stream.quota` blocked=true). The cloud\n * connection stays up, so this is tracked separately from `cloudConnected`:\n * for transcription purposes the cloud path is down, and sherpa takes over\n * if its model is on-device. Soniox-direct is unmetered and unaffected.\n */\n private sttQuotaBlocked = false\n\n private constructor() {\n // Reset the persisted mirror flag on boot — the in-memory state in this\n // coordinator is the source of truth, and a stale \"true\" left from the\n // previous session would cause native to feed Sherpa before any miniapp\n // registered a subscription.\n useSettingsStore.getState().setSetting(ISLAND_SETTINGS_KEYS.localSttFallbackActive, false)\n useSettingsStore.getState().setSetting(ISLAND_SETTINGS_KEYS.localSttFallbackReason, \"\")\n sttModelManager.onModelReady(() => {\n void this.retryAfterModelReady()\n })\n }\n\n private async retryAfterModelReady(): Promise<void> {\n // A model can finish downloading while the initial availability check is\n // still pending. Wait for that attempt before retrying so readiness is\n // never lost and native restarts cannot overlap.\n await this.starting\n await this.reconcile()\n }\n\n /**\n * Lazy-attach the engine cloud connection listener. The coordinator is\n * constructed at module load, before engine.start() brings up the cloud\n * client, so we defer until the first reconcile.\n */\n private attachCloudAdapterIfReady(): void {\n if (this.cloudAdapterAttached) return\n this.cloudConnected = cloudClientService.isConnected()\n cloudClientService.onStatusChanged((status) => {\n const connected = status.status === \"connected\"\n if (this.cloudConnected === connected) return\n this.log(`cloud connection -> ${connected ? \"up\" : \"down\"}`)\n this.cloudConnected = connected\n void this.reconcile()\n })\n this.cloudAdapterAttached = true\n }\n\n static getInstance(): LocalSttFallbackCoordinator {\n if (!LocalSttFallbackCoordinator.instance) {\n LocalSttFallbackCoordinator.instance = new LocalSttFallbackCoordinator()\n }\n return LocalSttFallbackCoordinator.instance\n }\n\n isActive(): boolean {\n return this.localActive\n }\n\n getActiveLanguage(): string | null {\n return this.activeLanguage\n }\n\n /** The cause of the current activation, or null while inactive. */\n getReason(): LocalSttFallbackReason | null {\n return this.localActive ? this.currentReason() : null\n }\n\n onSubscriptionChange(hasTranscription: boolean, language: string | null, hasForceLocal = false): void {\n this.log(`onSubscriptionChange(hasTx=${hasTranscription}, lang=${language}, forceLocal=${hasForceLocal})`)\n this.hasTranscriptionSubscription = hasTranscription\n this.hasForceLocalSubscription = hasTranscription && hasForceLocal\n this.activeLanguage = hasTranscription ? language : null\n void this.reconcile()\n }\n\n /**\n * Informational hook, retained for API stability. No longer called: the\n * authoritative switching signal is the cloud-client adapter (local miniapps\n * are powered only by V2). v1 cloud transcripts deliberately do NOT drive this\n * coordinator anymore. Kept for future hysteresis if connection-state alone\n * proves too coarse.\n */\n onCloudTranscript(): void {}\n\n /**\n * Pushed when the cloud announces/clears an STT quota block. Awaitable so\n * the caller can inspect `isActive()` afterwards to phrase its user notice\n * (\"continuing on-device\" vs \"transcription paused\").\n */\n async onSttQuotaBlockedChange(blocked: boolean): Promise<void> {\n if (this.sttQuotaBlocked === blocked) return\n this.log(`stt quota -> ${blocked ? \"blocked\" : \"restored\"}`)\n this.sttQuotaBlocked = blocked\n await this.reconcile()\n }\n\n isSttQuotaBlocked(): boolean {\n return this.sttQuotaBlocked\n }\n\n /** Pushed by SonioxDirectService on every enable/health transition. */\n onSonioxDirectStateChange(enabled: boolean, healthy: boolean): void {\n if (this.sonioxDirectEnabled === enabled && this.sonioxDirectHealthy === healthy) return\n this.log(`soniox-direct -> enabled=${enabled} healthy=${healthy}`)\n this.sonioxDirectEnabled = enabled\n this.sonioxDirectHealthy = healthy\n void this.reconcile()\n }\n\n /** Whether the primary transcription path (Soniox-direct when a user key is\n * set, the cloud otherwise) is up. */\n private primaryUp(): boolean {\n // Cloud turned off in Privacy settings: the cloud path is not merely down,\n // it is never coming back, so on-device STT is the primary. Checked ahead\n // of `cloudConnected` because that field defaults to true (so local STT\n // doesn't pre-empt cloud at boot) and would otherwise report a path that\n // will never connect as up. Soniox-direct is a user-supplied third-party\n // key, not Glassly cloud, so it stays available.\n if (!this.sonioxDirectEnabled && cloudClientService.isCloudDisabled()) return false\n return this.sonioxDirectEnabled ? this.sonioxDirectHealthy : this.cloudConnected && !this.sttQuotaBlocked\n }\n\n private async reconcile(): Promise<void> {\n this.attachCloudAdapterIfReady()\n const shouldBeActive = this.shouldUseLocalStt()\n if (shouldBeActive && !this.localActive) {\n if (!this.starting) {\n this.starting = this.startLocalStt().finally(() => {\n this.starting = null\n })\n }\n await this.starting\n } else if (!shouldBeActive && this.localActive) {\n this.stopLocalStt(this.hasTranscriptionSubscription ? \"primary transcription recovered\" : \"subscription gone\")\n } else if (shouldBeActive && this.localActive) {\n // Still active, but the cause may have shifted (e.g. quota block landing\n // while already offline for a disconnect) — keep the mirror current.\n this.publishReason()\n }\n }\n\n /**\n * Ranks the concurrent causes: a dead-forever cloud path first, then the\n * primary provider's own failure, then transient outages, with `force_local`\n * only when the primary is actually up. Mirrors `primaryUp()`.\n */\n private currentReason(): LocalSttFallbackReason {\n if (!this.sonioxDirectEnabled && cloudClientService.isCloudDisabled()) return \"cloud_disabled\"\n if (this.sonioxDirectEnabled && !this.sonioxDirectHealthy) return \"provider_unreachable\"\n if (!this.sonioxDirectEnabled && !this.cloudConnected) return \"cloud_disconnected\"\n if (!this.sonioxDirectEnabled && this.sttQuotaBlocked) return \"stt_quota\"\n return \"force_local\"\n }\n\n private publishReason(): void {\n const reason = this.localActive ? this.currentReason() : \"\"\n const store = useSettingsStore.getState()\n if (store.getSetting(ISLAND_SETTINGS_KEYS.localSttFallbackReason) !== reason) {\n store.setSetting(ISLAND_SETTINGS_KEYS.localSttFallbackReason, reason)\n }\n }\n\n private async startLocalStt(): Promise<void> {\n this.log(\"starting local stt\")\n try {\n await this.activateLocalStt()\n } catch (err) {\n this.log(`local stt startup failed: ${err}`)\n }\n }\n\n private async activateLocalStt(): Promise<void> {\n const modelAvailable = await sttModelManager.isModelAvailable()\n if (!modelAvailable) {\n this.log(\"local stt model is not available yet — skipping activation\")\n return\n }\n if (!this.shouldUseLocalStt()) {\n this.log(\"local stt activation skipped: routing changed before start completed\")\n return\n }\n // Native rejects unless the recognizer and its processing loop are ready.\n await BluetoothSdk.restartTranscriber()\n if (!this.shouldUseLocalStt()) {\n this.log(\"local stt activation skipped: routing changed during transcriber restart\")\n return\n }\n useSettingsStore.getState().setSetting(ISLAND_SETTINGS_KEYS.localSttFallbackActive, true)\n this.localActive = true\n this.publishReason()\n }\n\n private stopLocalStt(reason: string): void {\n this.log(`stopping local stt: ${reason}`)\n useSettingsStore.getState().setSetting(ISLAND_SETTINGS_KEYS.localSttFallbackActive, false)\n this.localActive = false\n this.publishReason()\n }\n\n private shouldUseLocalStt(): boolean {\n return this.hasTranscriptionSubscription && (this.hasForceLocalSubscription || !this.primaryUp())\n }\n\n private log(msg: string): void {\n console.log(`[LocalSttFallback] ${msg}`)\n }\n}\n\nconst localSttFallbackCoordinator = LocalSttFallbackCoordinator.getInstance()\nexport default localSttFallbackCoordinator\n"]}
1
+ {"version":3,"file":"LocalSttFallbackCoordinator.js","sourceRoot":"","sources":["../../src/services/LocalSttFallbackCoordinator.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,iCAAiC,CAAA;AAC1D,OAAO,EAAC,oBAAoB,EAAC,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAA;AACvD,OAAO,eAAe,MAAM,mBAAmB,CAAA;AA+B/C,MAAM,2BAA2B;IACvB,MAAM,CAAC,QAAQ,CAA6B;IAE5C,4BAA4B,GAAG,KAAK,CAAA;IACpC,yBAAyB,GAAG,KAAK,CAAA;IACzC,oFAAoF;IAC5E,uBAAuB,GAAG,KAAK,CAAA;IAC/B,cAAc,GAAkB,IAAI,CAAA;IAC5C;;;;;OAKG;IACK,cAAc,GAAG,IAAI,CAAA;IACrB,WAAW,GAAG,KAAK,CAAA;IACnB,QAAQ,GAAyB,IAAI,CAAA;IACrC,oBAAoB,GAAG,KAAK,CAAA;IACpC;;;;;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,CAAA;QACxB,IAAI,CAAC,aAAa,EAAE,CAAA;IACtB,CAAC;IAEO,iBAAiB;QACvB,OAAO,CACL,IAAI,CAAC,4BAA4B;YACjC,CAAC,IAAI,CAAC,yBAAyB,IAAI,CAAC,IAAI,CAAC,uBAAuB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CACxF,CAAA;IACH,CAAC;IAEO,GAAG,CAAC,GAAW;QACrB,OAAO,CAAC,GAAG,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAA;IAC1C,CAAC;CACF;AAED,MAAM,2BAA2B,GAAG,2BAA2B,CAAC,WAAW,EAAE,CAAA;AAC7E,eAAe,2BAA2B,CAAA","sourcesContent":["import BluetoothSdk from \"@glassly/bluetooth-sdk/internal\"\nimport {ISLAND_SETTINGS_KEYS} from \"../runtime/config\"\nimport {useSettingsStore} from \"../stores/settings\"\nimport {cloudClientService} from \"./CloudClientService\"\nimport sttModelManager from \"./STTModelManager\"\n\n/**\n * Decides whether on-device Sherpa STT should produce transcripts for local\n * miniapps, instead of (or in addition to) cloud transcription. Local STT is\n * active when the cloud is unavailable (disconnected or refusing STT for plan\n * quota) and some subscriber accepts fallback text, or any subscription\n * requires `forceLocal`.\n *\n * Activation flips `localSttFallbackActive` in the settings store, which\n * the bluetooth-sdk native side reads to decide whether to feed PCM into\n * the SherpaOnnxTranscriber. Local transcripts then flow back through the\n * `local_transcription` Bridge event; the host wires that event to\n * `localMiniappRuntime.forwardEvent`, with this coordinator providing the\n * subscription-active gate so we never publish transcripts to miniapps that\n * aren't asking for them. LocalMiniappRuntime filters mixed local/cloud\n * delivery per miniapp.\n */\n/**\n * Why local STT is currently active, mirrored into the\n * `local_stt_fallback_reason` setting (\"\" while inactive) so UI can show it.\n * When several causes hold at once, the primary-path outage wins over\n * `force_local` (a forced subscription would keep local STT on either way).\n */\nexport type LocalSttFallbackReason =\n | \"force_local\"\n | \"cloud_disconnected\"\n | \"cloud_disabled\"\n | \"stt_quota\"\n | \"provider_unreachable\"\n\nclass LocalSttFallbackCoordinator {\n private static instance: LocalSttFallbackCoordinator\n\n private hasTranscriptionSubscription = false\n private hasForceLocalSubscription = false\n /** Some default-route subscriber takes on-device text while the primary is down. */\n private hasFallbackSubscription = false\n private activeLanguage: string | null = null\n /**\n * Default to \"cloud is up\" so we never accidentally activate local STT before\n * the cloud client has had a chance to start. We attach lazily on the first\n * subscription/reconcile pass; once attached, this field reflects the real\n * cloud-client runtime status.\n */\n private cloudConnected = true\n private localActive = false\n private starting: Promise<void> | null = null\n private cloudAdapterAttached = false\n /**\n * Soniox-direct (user API key) state, pushed by SonioxDirectService. While\n * enabled, IT is the primary transcription path — cloud connectivity is\n * irrelevant and sherpa engages on Soniox health instead. Defaults healthy\n * for the same reason cloudConnected defaults true: never activate local STT\n * before the primary has had a chance to come up.\n */\n private sonioxDirectEnabled = false\n private sonioxDirectHealthy = true\n /**\n * Cloud STT refused for plan quota (`stream.quota` blocked=true). The cloud\n * connection stays up, so this is tracked separately from `cloudConnected`:\n * for transcription purposes the cloud path is down, and sherpa takes over\n * if its model is on-device. Soniox-direct is unmetered and unaffected.\n */\n private sttQuotaBlocked = false\n\n private constructor() {\n // Reset the persisted mirror flag on boot — the in-memory state in this\n // coordinator is the source of truth, and a stale \"true\" left from the\n // previous session would cause native to feed Sherpa before any miniapp\n // registered a subscription.\n useSettingsStore.getState().setSetting(ISLAND_SETTINGS_KEYS.localSttFallbackActive, false)\n useSettingsStore.getState().setSetting(ISLAND_SETTINGS_KEYS.localSttFallbackReason, \"\")\n sttModelManager.onModelReady(() => {\n void this.retryAfterModelReady()\n })\n }\n\n private async retryAfterModelReady(): Promise<void> {\n // A model can finish downloading while the initial availability check is\n // still pending. Wait for that attempt before retrying so readiness is\n // never lost and native restarts cannot overlap.\n await this.starting\n await this.reconcile()\n }\n\n /**\n * Lazy-attach the engine cloud connection listener. The coordinator is\n * constructed at module load, before engine.start() brings up the cloud\n * client, so we defer until the first reconcile.\n */\n private attachCloudAdapterIfReady(): void {\n if (this.cloudAdapterAttached) return\n this.cloudConnected = cloudClientService.isConnected()\n cloudClientService.onStatusChanged((status) => {\n const connected = status.status === \"connected\"\n if (this.cloudConnected === connected) return\n this.log(`cloud connection -> ${connected ? \"up\" : \"down\"}`)\n this.cloudConnected = connected\n void this.reconcile()\n })\n this.cloudAdapterAttached = true\n }\n\n static getInstance(): LocalSttFallbackCoordinator {\n if (!LocalSttFallbackCoordinator.instance) {\n LocalSttFallbackCoordinator.instance = new LocalSttFallbackCoordinator()\n }\n return LocalSttFallbackCoordinator.instance\n }\n\n isActive(): boolean {\n return this.localActive\n }\n\n getActiveLanguage(): string | null {\n return this.activeLanguage\n }\n\n /** The cause of the current activation, or null while inactive. */\n getReason(): LocalSttFallbackReason | null {\n return this.localActive ? this.currentReason() : null\n }\n\n onSubscriptionChange(\n hasTranscription: boolean,\n language: string | null,\n hasForceLocal = false,\n acceptsFallback = true,\n ): void {\n this.log(\n `onSubscriptionChange(hasTx=${hasTranscription}, lang=${language}, forceLocal=${hasForceLocal}, fallback=${acceptsFallback})`,\n )\n this.hasTranscriptionSubscription = hasTranscription\n this.hasForceLocalSubscription = hasTranscription && hasForceLocal\n this.hasFallbackSubscription = hasTranscription && acceptsFallback\n this.activeLanguage = hasTranscription ? language : null\n void this.reconcile()\n }\n\n /**\n * Informational hook, retained for API stability. No longer called: the\n * authoritative switching signal is the cloud-client adapter (local miniapps\n * are powered only by V2). v1 cloud transcripts deliberately do NOT drive this\n * coordinator anymore. Kept for future hysteresis if connection-state alone\n * proves too coarse.\n */\n onCloudTranscript(): void {}\n\n /**\n * Pushed when the cloud announces/clears an STT quota block. Awaitable so\n * the caller can inspect `isActive()` afterwards to phrase its user notice\n * (\"continuing on-device\" vs \"transcription paused\").\n */\n async onSttQuotaBlockedChange(blocked: boolean): Promise<void> {\n if (this.sttQuotaBlocked === blocked) return\n this.log(`stt quota -> ${blocked ? \"blocked\" : \"restored\"}`)\n this.sttQuotaBlocked = blocked\n await this.reconcile()\n }\n\n isSttQuotaBlocked(): boolean {\n return this.sttQuotaBlocked\n }\n\n /** Pushed by SonioxDirectService on every enable/health transition. */\n onSonioxDirectStateChange(enabled: boolean, healthy: boolean): void {\n if (this.sonioxDirectEnabled === enabled && this.sonioxDirectHealthy === healthy) return\n this.log(`soniox-direct -> enabled=${enabled} healthy=${healthy}`)\n this.sonioxDirectEnabled = enabled\n this.sonioxDirectHealthy = healthy\n void this.reconcile()\n }\n\n /** Whether the primary transcription path (Soniox-direct when a user key is\n * set, the cloud otherwise) is up. */\n private primaryUp(): boolean {\n // Cloud turned off in Privacy settings: the cloud path is not merely down,\n // it is never coming back, so on-device STT is the primary. Checked ahead\n // of `cloudConnected` because that field defaults to true (so local STT\n // doesn't pre-empt cloud at boot) and would otherwise report a path that\n // will never connect as up. Soniox-direct is a user-supplied third-party\n // key, not Glassly cloud, so it stays available.\n if (!this.sonioxDirectEnabled && cloudClientService.isCloudDisabled()) return false\n return this.sonioxDirectEnabled ? this.sonioxDirectHealthy : this.cloudConnected && !this.sttQuotaBlocked\n }\n\n private async reconcile(): Promise<void> {\n this.attachCloudAdapterIfReady()\n const shouldBeActive = this.shouldUseLocalStt()\n if (shouldBeActive && !this.localActive) {\n if (!this.starting) {\n this.starting = this.startLocalStt().finally(() => {\n this.starting = null\n })\n }\n await this.starting\n } else if (!shouldBeActive && this.localActive) {\n this.stopLocalStt(this.hasTranscriptionSubscription ? \"primary transcription recovered\" : \"subscription gone\")\n } else if (shouldBeActive && this.localActive) {\n // Still active, but the cause may have shifted (e.g. quota block landing\n // while already offline for a disconnect) — keep the mirror current.\n this.publishReason()\n }\n }\n\n /**\n * Ranks the concurrent causes: a dead-forever cloud path first, then the\n * primary provider's own failure, then transient outages, with `force_local`\n * only when the primary is actually up. Mirrors `primaryUp()`.\n */\n private currentReason(): LocalSttFallbackReason {\n if (!this.sonioxDirectEnabled && cloudClientService.isCloudDisabled()) return \"cloud_disabled\"\n if (this.sonioxDirectEnabled && !this.sonioxDirectHealthy) return \"provider_unreachable\"\n if (!this.sonioxDirectEnabled && !this.cloudConnected) return \"cloud_disconnected\"\n if (!this.sonioxDirectEnabled && this.sttQuotaBlocked) return \"stt_quota\"\n return \"force_local\"\n }\n\n private publishReason(): void {\n const reason = this.localActive ? this.currentReason() : \"\"\n const store = useSettingsStore.getState()\n if (store.getSetting(ISLAND_SETTINGS_KEYS.localSttFallbackReason) !== reason) {\n store.setSetting(ISLAND_SETTINGS_KEYS.localSttFallbackReason, reason)\n }\n }\n\n private async startLocalStt(): Promise<void> {\n this.log(\"starting local stt\")\n try {\n await this.activateLocalStt()\n } catch (err) {\n this.log(`local stt startup failed: ${err}`)\n }\n }\n\n private async activateLocalStt(): Promise<void> {\n const modelAvailable = await sttModelManager.isModelAvailable()\n if (!modelAvailable) {\n this.log(\"local stt model is not available yet — skipping activation\")\n return\n }\n if (!this.shouldUseLocalStt()) {\n this.log(\"local stt activation skipped: routing changed before start completed\")\n return\n }\n // Native rejects unless the recognizer and its processing loop are ready.\n await BluetoothSdk.restartTranscriber()\n if (!this.shouldUseLocalStt()) {\n this.log(\"local stt activation skipped: routing changed during transcriber restart\")\n return\n }\n useSettingsStore.getState().setSetting(ISLAND_SETTINGS_KEYS.localSttFallbackActive, true)\n this.localActive = true\n this.publishReason()\n }\n\n private stopLocalStt(reason: string): void {\n this.log(`stopping local stt: ${reason}`)\n useSettingsStore.getState().setSetting(ISLAND_SETTINGS_KEYS.localSttFallbackActive, false)\n this.localActive = false\n this.publishReason()\n }\n\n private shouldUseLocalStt(): boolean {\n return (\n this.hasTranscriptionSubscription &&\n (this.hasForceLocalSubscription || (this.hasFallbackSubscription && !this.primaryUp()))\n )\n }\n\n private log(msg: string): void {\n console.log(`[LocalSttFallback] ${msg}`)\n }\n}\n\nconst localSttFallbackCoordinator = LocalSttFallbackCoordinator.getInstance()\nexport default localSttFallbackCoordinator\n"]}
@@ -1,12 +1,17 @@
1
1
  export interface TranscriptionRouteSummary {
2
2
  hasCloudSubscriber: boolean;
3
3
  hasForceLocalSubscriber: boolean;
4
+ /** A default-route subscriber that takes on-device text while the primary is down. */
5
+ hasFallbackSubscriber: boolean;
4
6
  }
5
7
  export interface TranscriptionSubscriberRoutes {
6
8
  cloud: boolean;
7
9
  forceLocal: boolean;
10
+ /** Default-route fallback acceptance; absent means accepted. */
11
+ localFallback?: boolean;
8
12
  }
9
- export type TranscriptionDeliveryRoute = "default" | "forceLocal" | "all";
13
+ /** "fallback" is on-device text serving the default route because the primary is down. */
14
+ export type TranscriptionDeliveryRoute = "default" | "forceLocal" | "fallback" | "all";
10
15
  export declare function summarizeTranscriptionRoutes<T>(subscribers: Iterable<T>, routesFor: (subscriber: T) => TranscriptionSubscriberRoutes): TranscriptionRouteSummary;
11
16
  /**
12
17
  * Decide which subscription route(s) a transcript reaches.
@@ -1 +1 @@
1
- {"version":3,"file":"TranscriptionRouting.d.ts","sourceRoot":"","sources":["../../src/services/TranscriptionRouting.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;IACxC,kBAAkB,EAAE,OAAO,CAAA;IAC3B,uBAAuB,EAAE,OAAO,CAAA;CACjC;AAED,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,OAAO,CAAA;IACd,UAAU,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,0BAA0B,GAAG,SAAS,GAAG,YAAY,GAAG,KAAK,CAAA;AAEzE,wBAAgB,4BAA4B,CAAC,CAAC,EAC5C,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,EACxB,SAAS,EAAE,CAAC,UAAU,EAAE,CAAC,KAAK,6BAA6B,GAC1D,yBAAyB,CAS3B;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,GAAG,OAAO,EACzB,MAAM,EAAE,6BAA6B,EACrC,SAAS,EAAE,OAAO,GACjB,0BAA0B,GAAG,IAAI,CAMnC"}
1
+ {"version":3,"file":"TranscriptionRouting.d.ts","sourceRoot":"","sources":["../../src/services/TranscriptionRouting.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;IACxC,kBAAkB,EAAE,OAAO,CAAA;IAC3B,uBAAuB,EAAE,OAAO,CAAA;IAChC,sFAAsF;IACtF,qBAAqB,EAAE,OAAO,CAAA;CAC/B;AAED,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,OAAO,CAAA;IACd,UAAU,EAAE,OAAO,CAAA;IACnB,gEAAgE;IAChE,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,0FAA0F;AAC1F,MAAM,MAAM,0BAA0B,GAAG,SAAS,GAAG,YAAY,GAAG,UAAU,GAAG,KAAK,CAAA;AAEtF,wBAAgB,4BAA4B,CAAC,CAAC,EAC5C,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,EACxB,SAAS,EAAE,CAAC,UAAU,EAAE,CAAC,KAAK,6BAA6B,GAC1D,yBAAyB,CAW3B;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,GAAG,OAAO,EACzB,MAAM,EAAE,6BAA6B,EACrC,SAAS,EAAE,OAAO,GACjB,0BAA0B,GAAG,IAAI,CAOnC"}
@@ -1,14 +1,17 @@
1
1
  export function summarizeTranscriptionRoutes(subscribers, routesFor) {
2
2
  let hasCloudSubscriber = false;
3
3
  let hasForceLocalSubscriber = false;
4
+ let hasFallbackSubscriber = false;
4
5
  for (const subscriber of subscribers) {
5
6
  const routes = routesFor(subscriber);
6
7
  if (routes.cloud)
7
8
  hasCloudSubscriber = true;
8
9
  if (routes.forceLocal)
9
10
  hasForceLocalSubscriber = true;
11
+ if (routes.cloud && routes.localFallback !== false)
12
+ hasFallbackSubscriber = true;
10
13
  }
11
- return { hasCloudSubscriber, hasForceLocalSubscriber };
14
+ return { hasCloudSubscriber, hasForceLocalSubscriber, hasFallbackSubscriber };
12
15
  }
13
16
  /**
14
17
  * Decide which subscription route(s) a transcript reaches.
@@ -25,10 +28,11 @@ export function transcriptionDeliveryRoute(source, routes, primaryUp) {
25
28
  return routes.cloud ? "default" : null;
26
29
  if (primaryUp)
27
30
  return routes.forceLocal ? "forceLocal" : null;
28
- if (routes.cloud && routes.forceLocal)
31
+ const fallback = routes.cloud && routes.localFallback !== false;
32
+ if (fallback && routes.forceLocal)
29
33
  return "all";
30
34
  if (routes.forceLocal)
31
35
  return "forceLocal";
32
- return routes.cloud ? "default" : null;
36
+ return fallback ? "fallback" : null;
33
37
  }
34
38
  //# sourceMappingURL=TranscriptionRouting.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TranscriptionRouting.js","sourceRoot":"","sources":["../../src/services/TranscriptionRouting.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,4BAA4B,CAC1C,WAAwB,EACxB,SAA2D;IAE3D,IAAI,kBAAkB,GAAG,KAAK,CAAA;IAC9B,IAAI,uBAAuB,GAAG,KAAK,CAAA;IACnC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,CAAA;QACpC,IAAI,MAAM,CAAC,KAAK;YAAE,kBAAkB,GAAG,IAAI,CAAA;QAC3C,IAAI,MAAM,CAAC,UAAU;YAAE,uBAAuB,GAAG,IAAI,CAAA;IACvD,CAAC;IACD,OAAO,EAAC,kBAAkB,EAAE,uBAAuB,EAAC,CAAA;AACtD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAAyB,EACzB,MAAqC,EACrC,SAAkB;IAElB,IAAI,MAAM,KAAK,OAAO;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;IAC9D,IAAI,SAAS;QAAE,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAA;IAC7D,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,UAAU;QAAE,OAAO,KAAK,CAAA;IACnD,IAAI,MAAM,CAAC,UAAU;QAAE,OAAO,YAAY,CAAA;IAC1C,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;AACxC,CAAC","sourcesContent":["export interface TranscriptionRouteSummary {\n hasCloudSubscriber: boolean\n hasForceLocalSubscriber: boolean\n}\n\nexport interface TranscriptionSubscriberRoutes {\n cloud: boolean\n forceLocal: boolean\n}\n\nexport type TranscriptionDeliveryRoute = \"default\" | \"forceLocal\" | \"all\"\n\nexport function summarizeTranscriptionRoutes<T>(\n subscribers: Iterable<T>,\n routesFor: (subscriber: T) => TranscriptionSubscriberRoutes,\n): TranscriptionRouteSummary {\n let hasCloudSubscriber = false\n let hasForceLocalSubscriber = false\n for (const subscriber of subscribers) {\n const routes = routesFor(subscriber)\n if (routes.cloud) hasCloudSubscriber = true\n if (routes.forceLocal) hasForceLocalSubscriber = true\n }\n return {hasCloudSubscriber, hasForceLocalSubscriber}\n}\n\n/**\n * Decide which subscription route(s) a transcript reaches.\n *\n * `source` is who produced the transcript: \"cloud\" is the PRIMARY provider\n * (the cloud runtime, or Soniox-direct when a user API key is set — both\n * deliver through the default route); \"local\" is on-device sherpa.\n * `primaryUp` is whether that primary path is currently believed usable\n * (cloud connectivity, or Soniox-direct session health) — when it is down,\n * local transcripts also serve default-route subscribers.\n */\nexport function transcriptionDeliveryRoute(\n source: \"cloud\" | \"local\",\n routes: TranscriptionSubscriberRoutes,\n primaryUp: boolean,\n): TranscriptionDeliveryRoute | null {\n if (source === \"cloud\") return routes.cloud ? \"default\" : null\n if (primaryUp) return routes.forceLocal ? \"forceLocal\" : null\n if (routes.cloud && routes.forceLocal) return \"all\"\n if (routes.forceLocal) return \"forceLocal\"\n return routes.cloud ? \"default\" : null\n}\n"]}
1
+ {"version":3,"file":"TranscriptionRouting.js","sourceRoot":"","sources":["../../src/services/TranscriptionRouting.ts"],"names":[],"mappings":"AAiB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olean\n hasForceLocalSubscriber: boolean\n /** A default-route subscriber that takes on-device text while the primary is down. */\n hasFallbackSubscriber: boolean\n}\n\nexport interface TranscriptionSubscriberRoutes {\n cloud: boolean\n forceLocal: boolean\n /** Default-route fallback acceptance; absent means accepted. */\n localFallback?: boolean\n}\n\n/** \"fallback\" is on-device text serving the default route because the primary is down. */\nexport type TranscriptionDeliveryRoute = \"default\" | \"forceLocal\" | \"fallback\" | \"all\"\n\nexport function summarizeTranscriptionRoutes<T>(\n subscribers: Iterable<T>,\n routesFor: (subscriber: T) => TranscriptionSubscriberRoutes,\n): TranscriptionRouteSummary {\n let hasCloudSubscriber = false\n let hasForceLocalSubscriber = false\n let hasFallbackSubscriber = false\n for (const subscriber of subscribers) {\n const routes = routesFor(subscriber)\n if (routes.cloud) hasCloudSubscriber = true\n if (routes.forceLocal) hasForceLocalSubscriber = true\n if (routes.cloud && routes.localFallback !== false) hasFallbackSubscriber = true\n }\n return {hasCloudSubscriber, hasForceLocalSubscriber, hasFallbackSubscriber}\n}\n\n/**\n * Decide which subscription route(s) a transcript reaches.\n *\n * `source` is who produced the transcript: \"cloud\" is the PRIMARY provider\n * (the cloud runtime, or Soniox-direct when a user API key is set — both\n * deliver through the default route); \"local\" is on-device sherpa.\n * `primaryUp` is whether that primary path is currently believed usable\n * (cloud connectivity, or Soniox-direct session health) — when it is down,\n * local transcripts also serve default-route subscribers.\n */\nexport function transcriptionDeliveryRoute(\n source: \"cloud\" | \"local\",\n routes: TranscriptionSubscriberRoutes,\n primaryUp: boolean,\n): TranscriptionDeliveryRoute | null {\n if (source === \"cloud\") return routes.cloud ? \"default\" : null\n if (primaryUp) return routes.forceLocal ? \"forceLocal\" : null\n const fallback = routes.cloud && routes.localFallback !== false\n if (fallback && routes.forceLocal) return \"all\"\n if (routes.forceLocal) return \"forceLocal\"\n return fallback ? \"fallback\" : null\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/stores/settings.ts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M,EAoD1C,CAAA;AAeD,eAAO,MAAM,qBAAqB,EAAE,MAAM,EAEV,CAAA;AAIhC,MAAM,WAAW,aAAa;IAE5B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAE7B,aAAa,EAAE,OAAO,CAAA;IAEtB,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE,OAAO,KAAK,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACzF,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAC3E,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAA;IAEhC,eAAe,EAAE,MAAM,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAE/C,oBAAoB,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/C,uBAAuB,EAAE,MAAM,IAAI,CAAA;CACpC;AAoBD,eAAO,MAAM,gBAAgB;;;;;;;;EA+U5B,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,GAAG,GAAG,EAAE,KAAK,MAAM,KAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAI3F,CAAA"}
@@ -698,19 +698,6 @@ export const SETTINGS = {
698
698
  saveOnServer: false,
699
699
  persist: true,
700
700
  },
701
- // Debug: route the R1 ring through the glasses (advStart + RING_CONNECT_INFO,
702
- // events forwarded by the CFW) instead of the phone link. OFF by default:
703
- // the ring sends its touch reports to the glasses whenever it holds glasses
704
- // targets, so the phone link only carries telemetry until those are erased.
705
- // Synced to the Bluetooth SDK, which re-routes a connected ring on change.
706
- // Device-local debug knob, so not saved on the server.
707
- ring_via_glasses: {
708
- key: "ring_via_glasses",
709
- defaultValue: () => false,
710
- writable: true,
711
- saveOnServer: false,
712
- persist: true,
713
- },
714
701
  // Maximum rate at which display updates leave the phone for the glasses.
715
702
  // The Bluetooth SDK paces every scene frame and legacy layout to this,
716
703
  // coalescing faster updates last-wins; clears bypass it. No effect on G2
@@ -1060,7 +1047,6 @@ export const BLUETOOTH_SETTING_KEYS = [
1060
1047
  SETTINGS.cfw_scene_renderer.key,
1061
1048
  SETTINGS.cfw_fast_ble.key,
1062
1049
  SETTINGS.g2_perf_logs.key,
1063
- SETTINGS.ring_via_glasses.key,
1064
1050
  SETTINGS.display_max_fps.key,
1065
1051
  SETTINGS.twelve_hour_time.key,
1066
1052
  SETTINGS.metric_system.key,