@mentra/engine 3.4.0-dev.1207 → 3.4.0-dev.1209

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 (67) hide show
  1. package/build/facades/glasses.d.ts.map +1 -1
  2. package/build/facades/glasses.js +5 -3
  3. package/build/facades/glasses.js.map +1 -1
  4. package/build/generated/releaseMetadata.js +5 -5
  5. package/build/generated/releaseMetadata.js.map +1 -1
  6. package/build/services/AppRegistry.d.ts +2 -0
  7. package/build/services/AppRegistry.d.ts.map +1 -1
  8. package/build/services/AppRegistry.js.map +1 -1
  9. package/build/services/LocalMiniappRuntime.d.ts +2 -0
  10. package/build/services/LocalMiniappRuntime.d.ts.map +1 -1
  11. package/build/services/LocalMiniappRuntime.js +18 -1
  12. package/build/services/LocalMiniappRuntime.js.map +1 -1
  13. package/build/services/MentraJSCrashController.d.ts +2 -0
  14. package/build/services/MentraJSCrashController.d.ts.map +1 -1
  15. package/build/services/MentraJSCrashController.js +4 -0
  16. package/build/services/MentraJSCrashController.js.map +1 -1
  17. package/build/services/MentraJSRouter.d.ts.map +1 -1
  18. package/build/services/MentraJSRouter.js +14 -3
  19. package/build/services/MentraJSRouter.js.map +1 -1
  20. package/build/services/MiniappLauncher.d.ts +6 -0
  21. package/build/services/MiniappLauncher.d.ts.map +1 -1
  22. package/build/services/MiniappLauncher.js +20 -3
  23. package/build/services/MiniappLauncher.js.map +1 -1
  24. package/build/services/fleet/FleetReporter.d.ts.map +1 -1
  25. package/build/services/fleet/FleetReporter.js +43 -0
  26. package/build/services/fleet/FleetReporter.js.map +1 -1
  27. package/build/services/fleet/fleetCollector.d.ts +1 -1
  28. package/build/services/fleet/fleetCollector.d.ts.map +1 -1
  29. package/build/services/fleet/fleetCollector.js +146 -5
  30. package/build/services/fleet/fleetCollector.js.map +1 -1
  31. package/build/services/fleet/fleetEvents.d.ts +39 -3
  32. package/build/services/fleet/fleetEvents.d.ts.map +1 -1
  33. package/build/services/fleet/fleetEvents.js +66 -22
  34. package/build/services/fleet/fleetEvents.js.map +1 -1
  35. package/build/services/fleet/fleetQueue.d.ts +26 -0
  36. package/build/services/fleet/fleetQueue.d.ts.map +1 -1
  37. package/build/services/fleet/fleetQueue.js +94 -8
  38. package/build/services/fleet/fleetQueue.js.map +1 -1
  39. package/build/services/fleet/telemetryLimits.d.ts +16 -0
  40. package/build/services/fleet/telemetryLimits.d.ts.map +1 -0
  41. package/build/services/fleet/telemetryLimits.js +69 -0
  42. package/build/services/fleet/telemetryLimits.js.map +1 -0
  43. package/build/services/installMiniapp.d.ts +13 -0
  44. package/build/services/installMiniapp.d.ts.map +1 -1
  45. package/build/services/installMiniapp.js +64 -1
  46. package/build/services/installMiniapp.js.map +1 -1
  47. package/build/services/miniappReleaseInstall.js +1 -1
  48. package/build/services/miniappReleaseInstall.js.map +1 -1
  49. package/build/stores/apps.d.ts.map +1 -1
  50. package/build/stores/apps.js +16 -1
  51. package/build/stores/apps.js.map +1 -1
  52. package/package.json +8 -8
  53. package/src/facades/glasses.ts +5 -3
  54. package/src/generated/releaseMetadata.ts +5 -5
  55. package/src/services/AppRegistry.ts +2 -0
  56. package/src/services/LocalMiniappRuntime.ts +20 -1
  57. package/src/services/MentraJSCrashController.ts +5 -0
  58. package/src/services/MentraJSRouter.ts +15 -3
  59. package/src/services/MiniappLauncher.ts +18 -2
  60. package/src/services/fleet/FleetReporter.ts +40 -0
  61. package/src/services/fleet/fleetCollector.ts +160 -6
  62. package/src/services/fleet/fleetEvents.ts +104 -20
  63. package/src/services/fleet/fleetQueue.ts +100 -7
  64. package/src/services/fleet/telemetryLimits.ts +78 -0
  65. package/src/services/installMiniapp.ts +78 -2
  66. package/src/services/miniappReleaseInstall.ts +1 -1
  67. package/src/stores/apps.ts +19 -2
@@ -1 +1 @@
1
- {"version":3,"file":"MiniappLauncher.js","sourceRoot":"","sources":["../../src/services/MiniappLauncher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;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AO,CAAC,IAAI,CAAS,GAAG,WAAW,WAAW,CAAC,CAAA;QAC9D,IAAI,MAAM,CAAC,KAAK,EAAE;YAAE,OAAO,MAAM,CAAC,KAAK,CAAA;QACvC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA","sourcesContent":["/**\n * MiniappLauncher — headless launch/teardown of a local miniapp's background\n * JS context.\n *\n * This is the one piece of \"run a miniapp\" that used to live inside the\n * `LocalMiniappView` React component (resolve the bundle → read the manifest →\n * `spawnAndRegister`), triggered only when the Compositor mounted that\n * component on foreground. Pulling it into the runtime means:\n *\n * - `start()` can actually spawn an app even when nothing foregrounds it\n * (e.g. a system app launching another miniapp via `session.miniapps`).\n * - the action broker can wake a stopped target headlessly — no UI at all.\n * - the dev hot-reload respawn path and the WebView mount path share one\n * resolve+spawn recipe instead of three copies.\n *\n * The launcher is **headless**: no React, no RN components. The engine-owned\n * MiniappEngine hands it the {@link MentraJSRouter} instance once during\n * engine construction. OEMs embedding the runtime drive miniapp lifecycle\n * through the engine facade and stores, not a separate launcher configure API.\n *\n * Boundary: the launcher owns the **background** context. WebView *rendering*\n * (the UI layer) stays with the host — the launcher just hands back the\n * resolved UI entry so the host can mount its `<WebView>`.\n *\n * Fleet: every path that makes a local miniapp execute as user activity comes\n * through here, so the launcher reports each such launch (and each that fails\n * once past the availability gate) — a restore, a miniapp started by another\n * miniapp or an action, a screen opened directly, a restart after a reinstall.\n * A launch the apps store's `start` makes is reported by `start` itself\n * (`fleetEvents.claimLaunch`); a context already executing, or one a hidden\n * action wake keeps out of the running tray, is no launch.\n *\n * Age ratings: every launch path comes through here, so this is where a miniapp rated above the host app's own\n * rating meets the age gate as it opens, whether it was installed with the sheet or headlessly (a Fleet assignment,\n * a system miniapp). A launch the person makes in front of the app may ask their age once; any other launch needs it\n * declared already.\n */\n\nimport {File} from \"expo-file-system\"\nimport {AppState, Platform} from \"react-native\"\n\nimport {isDevMiniappAllowed, isMiniappAvailable, type MiniappAvailabilityMode} from \"../runtime/bootstrap\"\nimport {resolveDevBundleSource} from \"../utils/devMiniappSnapshot\"\nimport {storage} from \"../utils/storage/storage\"\nimport {MiniappRunningError} from \"../utils/storeInstallRuntime\"\nimport appRegistry, {getLocalAppRunningState, saveLocalAppRunningState} from \"./AppRegistry\"\nimport devServerBridge from \"./DevServerBridge\"\nimport {fleetEvents} from \"./fleet/fleetEvents\"\nimport localMiniappRuntime, {type InstalledMiniappManifest} from \"./LocalMiniappRuntime\"\nimport type {MentraJSRouter} from \"./MentraJSRouter\"\nimport {checkMiniappAge, type AgeGateVerdict, type AgeRatedMiniapp} from \"./miniappAgeGate\"\nimport {developmentOriginName, miniappOrigin, miniappOriginUrl, type MiniappOriginPlatform} from \"./miniappOrigin\"\nimport {isHostTrustedSystemMiniapp} from \"./SystemMiniappPolicy\"\n\n/** The miniapp's server no longer admits this account (Fleet revocation): it cannot launch until access returns. */\nexport class MiniappAccessRevokedError extends Error {\n constructor(readonly packageName: string) {\n super(`MiniappLauncher: access to ${packageName} was revoked`)\n this.name = \"MiniappAccessRevokedError\"\n }\n}\n\n/**\n * The miniapp is rated above the host app's own rating and the person's declared age doesn't let it open (see\n * {@link AgeGateVerdict}). A person opening it in front of the app was asked their age, or told why.\n */\nexport class MiniappAgeRestrictedError extends Error {\n constructor(\n readonly packageName: string,\n readonly verdict: Exclude<AgeGateVerdict, \"allowed\">,\n ) {\n super(`MiniappLauncher: ${packageName} is age-rated and did not open (${verdict})`)\n this.name = \"MiniappAgeRestrictedError\"\n }\n}\n\ninterface LauncherDeps {\n /** The host-constructed router (needs the native Crust binding). */\n router: MentraJSRouter\n}\n\n/** Hints the host may pass from a view's props to avoid re-deriving them. */\nexport interface LaunchHints {\n devUrl?: string\n /** Retained for caller compatibility; released launches use the committed active version. */\n version?: string\n devPort?: string\n}\n\nexport interface RuntimeLaunchOptions {\n /** False for an invocation-scoped wake that must not enter the running tray. */\n projectRunning?: boolean\n /**\n * Who started the miniapp, for the Fleet launch this call makes, if it makes one: the person (a screen they opened)\n * or the platform (a restore, another miniapp, a restart). Defaults to automatic.\n */\n trigger?: \"user\" | \"automatic\"\n}\n\nfunction availabilityMode(options?: RuntimeLaunchOptions): MiniappAvailabilityMode {\n return options?.projectRunning === false ? \"background\" : \"interactive\"\n}\n\n/** Everything the launcher resolved for a package — bg source + UI entry. */\nexport interface ResolvedBundle {\n bgSource: string\n /** Where the screen loads from. See {@link LaunchResult.uiUri}. */\n uiUri: string | null\n /** The origin `uiUri` belongs to. See {@link LaunchResult.uiOrigin}. */\n uiOrigin: string | null\n /** The bundle root the package's origin serves. See {@link LaunchResult.uiRootDir}. */\n uiRootDir: string | null\n /** The name the origin is for. See {@link LaunchResult.uiOriginName}. */\n uiOriginName: string | null\n /** A development build: a live development server or a development snapshot. */\n devBuild: boolean\n declaredPermissions: string[]\n installedManifest?: InstalledMiniappManifest\n /** What the bundle's `miniapp.json` declares as `ageRating`; null when it declares none. */\n ageRating: unknown\n /** Build-owned SYSTEM trust derived from install provenance, never the manifest. */\n hostTrustedSystem: boolean\n /** Set for dev miniapps (HTTP off the dev server); null for released. */\n devUrl: string | null\n devPort: number | null\n}\n\n/** What the host needs back to render the UI layer. */\nexport interface LaunchResult {\n /**\n * Where the screen loads from. An installed release loads from its\n * package's own origin: `miniapp://<packageName>/<ui entry>` on iOS and\n * `https://<host>.miniapp.invalid/<ui entry>` on Android (see\n * {@link miniappOriginUrl}), a development snapshot from the origin of its\n * {@link uiOriginName}. A live development build loads from its development\n * server. Null when there is no screen to load.\n */\n uiUri: string | null\n /** The origin `uiUri` belongs to, for the WebView's `originWhitelist`. */\n uiOrigin: string | null\n /**\n * The root of the active version's bundle, which the package's origin\n * serves (the WebView's `miniappOrigin.rootDir`). Null when the screen loads\n * from a development server.\n */\n uiRootDir: string | null\n /**\n * The name the origin serves `uiRootDir` under (the WebView's\n * `miniappOrigin.packageName`): the package name for a release, and\n * {@link developmentOriginName} for a development snapshot, so a development\n * build never shares web storage with a release of its name. Null with\n * `uiRootDir`.\n */\n uiOriginName: string | null\n /** A development build: a live development server or a development snapshot. */\n devBuild: boolean\n}\n\nconst NO_UI: LaunchResult = {uiUri: null, uiOrigin: null, uiRootDir: null, uiOriginName: null, devBuild: false}\n\nfunction launchResultOf(resolved: ResolvedBundle | null | undefined): LaunchResult {\n if (!resolved) return NO_UI\n return {\n uiUri: resolved.uiUri,\n uiOrigin: resolved.uiOrigin,\n uiRootDir: resolved.uiRootDir,\n uiOriginName: resolved.uiOriginName,\n devBuild: resolved.devBuild,\n }\n}\n\n/** The platform whose origin shape the Mentra App's WebView serves. */\nfunction originPlatform(): MiniappOriginPlatform {\n return Platform.OS === \"android\" ? \"android\" : \"ios\"\n}\n\n/** `scheme://host[:port]` of an http(s) URL, lowercased as a page's `location.origin` reads it. */\nfunction serverOrigin(url: string): string | null {\n const match = /^(https?:\\/\\/[^/?#]+)/i.exec(url)\n return match ? match[1].toLowerCase() : null\n}\n\nclass MiniappLauncher {\n private deps: LauncherDeps | null = null\n\n /**\n * In-flight launches keyed by packageName. Both apps.ts start() and the\n * WebView mount call ensureRunning() before the first spawnAndRegister\n * resolves — without this, neither sees the package in registeredPackages()\n * yet and both spawn the same context (a clobber/double-spawn). Concurrent\n * callers share the same promise.\n */\n private readonly inFlight = new Map<string, Promise<LaunchResult>>()\n /** In-flight launches that keep their context out of the running tray (a hidden action wake). */\n private readonly hiddenInFlight = new Set<string>()\n\n /**\n * Installs hold new launches of their package until they commit or roll\n * back: explicit installs for the whole install, automatic updates only while\n * their files change.\n */\n private readonly installing = new Map<string, Promise<void>>()\n\n /**\n * Run an automatic update only while the miniapp is idle. `install` prepares\n * the release, then calls `beforeActivate` immediately before files change:\n * a launch during preparation wins and the update defers with\n * {@link MiniappRunningError}; a launch during activation waits for the\n * commit or rollback and then reads the resulting bundle.\n */\n async installWhenIdle<T>(packageName: string, install: (beforeActivate: () => void) => Promise<T>): Promise<T> {\n const assertIdle = () => {\n if (this.isRunning(packageName) || this.inFlight.has(packageName)) throw new MiniappRunningError(packageName)\n }\n assertIdle()\n let release: (() => void) | undefined\n try {\n return await install(() => {\n assertIdle()\n release = this.reserveInstall(packageName)\n })\n } finally {\n release?.()\n }\n }\n\n /** Stabilize existing launches and hold new ones until an explicit install finishes. */\n async pauseLaunches(packageName: string): Promise<() => void> {\n const release = this.reserveInstall(packageName)\n // Launches already resolving a bundle must settle before the installer\n // decides whether a context needs stopping/restarting. A failed launch is also settled.\n await this.inFlight.get(packageName)?.catch(() => {})\n return release\n }\n\n private reserveInstall(packageName: string): () => void {\n if (this.installing.has(packageName)) throw new Error(`An install is already activating ${packageName}`)\n let resume!: () => void\n const pending = new Promise<void>((resolve) => {\n resume = resolve\n })\n this.installing.set(packageName, pending)\n return () => {\n if (this.installing.get(packageName) !== pending) return\n this.installing.delete(packageName)\n resume()\n }\n }\n\n /**\n * The name and age rating of the installed bundle a launch of `packageName` runs (the version `getActiveVersion`\n * chooses, a development snapshot included), read without waiting. The apps store checks it before it opens the\n * screen or stops other miniapps, so a refusal changes nothing. A live development server's rating is read when\n * its context spawns, where every launch is checked again.\n */\n installedAgeRating(packageName: string): AgeRatedMiniapp {\n const version = appRegistry.peekActiveVersion(packageName)\n const manifest = version\n ? (appRegistry.getMiniappManifest(packageName, version) as {name?: unknown; ageRating?: unknown} | null)\n : null\n const name = typeof manifest?.name === \"string\" && manifest.name ? manifest.name : packageName\n return {packageName, name, ageRating: manifest?.ageRating ?? null}\n }\n\n /** Wire the router in. Called once from MiniappEngine construction. */\n configure(deps: LauncherDeps): void {\n this.deps = deps\n }\n\n private requireRouter(): MentraJSRouter {\n if (!this.deps) {\n throw new Error(\"MiniappLauncher not configured — ensureMiniappEngine() has not run\")\n }\n return this.deps.router\n }\n\n /** True iff the package's background JS context is currently spawned. */\n isRunning(packageName: string): boolean {\n return this.deps?.router.registeredPackages().includes(packageName) ?? false\n }\n\n /** True iff the live context is projected as normal user activity. */\n isProjectedRunning(packageName: string): boolean {\n return this.deps?.router.isProjectedRunning(packageName) ?? false\n }\n\n /**\n * Resolve the background JS source + UI entry + declared permissions for a\n * package. Handles both dev (HTTP off the running dev server) and released\n * (the installed snapshot on disk, whose screen loads from the package's own\n * origin). Reads disk/network/storage; does\n * NOT spawn. Returns null when the bundle can't be resolved (dev server\n * unreachable with no on-disk snapshot, missing entry, no installed version).\n */\n async resolveBundle(\n packageName: string,\n hints?: LaunchHints,\n runtimeOptions?: RuntimeLaunchOptions,\n ): Promise<ResolvedBundle | null> {\n if (!isMiniappAvailable(packageName, availabilityMode(runtimeOptions))) return null\n const devAllowed = isDevMiniappAllowed(packageName)\n // Live dev code is unsigned, so it never runs under a package installed with\n // a publisher signature; that package runs its installed bundle instead.\n const liveDevAllowed = devAllowed && !appRegistry.getPublisherKeyFingerprint(packageName)\n const devUrl = liveDevAllowed ? (hints?.devUrl ?? this.storedDevUrl(packageName)) : undefined\n\n const selectedSnapshot = devAllowed ? appRegistry.getSelectedDevSnapshot(packageName) : null\n if (selectedSnapshot) return this.resolveInstalledBundle(packageName, selectedSnapshot)\n\n // --- Dev: live HTTP, then the last on-disk snapshot if the laptop is gone. ---\n // A stored URL from a scan that this workspace will not run must fall\n // through to the released bundle, or the home tile disappears.\n if (devUrl && devAllowed) {\n const source = await resolveDevBundleSource(packageName, devUrl)\n if (source.kind === \"live\") {\n const live = await this.resolveLiveHttp(packageName, source.resolvedUrl, source.manifest, hints)\n if (live) return live\n // Live probe succeeded but the entry fetch failed — still try disk.\n }\n const snapshotVersion =\n source.kind === \"snapshot\" ? source.version : appRegistry.getLatestDevSnapshotVersion(packageName)\n if (snapshotVersion) {\n const snapshot = await this.resolveInstalledBundle(packageName, snapshotVersion)\n if (snapshot) return snapshot\n }\n return null\n }\n\n // --- Released: resolve from the installed snapshot on disk. ---\n // A view can retain its old version prop across an install or rollback.\n // Resolve the committed pointer here, including after an installation wait.\n const version = await appRegistry.getActiveVersion(packageName)\n if (!version) return null\n return this.resolveInstalledBundle(packageName, version)\n }\n\n private async resolveLiveHttp(\n packageName: string,\n resolvedUrl: string,\n manifest: {entry?: unknown; permissions?: unknown; [key: string]: unknown},\n hints?: LaunchHints,\n ): Promise<ResolvedBundle | null> {\n const entry = manifest.entry as {background?: string; ui?: string} | undefined\n if (!entry?.background) return null\n\n // Use the host that actually answered — may differ from the stored IP\n // after a laptop Wi-Fi change (mDNS / Metro failover inside resolveDevBundleSource).\n const base = resolvedUrl.replace(/\\/$/, \"\")\n // entry.* are bundle-root paths (dist/ stripped); the dev server serves\n // files relative to cwd, so prepend dist/.\n const bgUrl = `${base}/dist/${entry.background.replace(/^\\.?\\/+/, \"\")}`\n const uiUri = entry.ui ? `${base}/dist/${entry.ui.replace(/^\\.?\\/+/, \"\")}` : null\n\n const perms = manifest.permissions as Array<{type?: string} | string> | undefined\n const declaredPermissions = (perms ?? [])\n .map((p) => (typeof p === \"string\" ? p : p?.type))\n .filter((t): t is string => typeof t === \"string\")\n const installedManifest: InstalledMiniappManifest = {\n packageName: typeof manifest.packageName === \"string\" ? manifest.packageName : packageName,\n name: typeof manifest.name === \"string\" ? manifest.name : undefined,\n version: typeof manifest.version === \"string\" ? manifest.version : undefined,\n sdkVersion: typeof manifest.sdkVersion === \"string\" ? manifest.sdkVersion : undefined,\n minHostVersion: typeof manifest.minHostVersion === \"string\" ? manifest.minHostVersion : undefined,\n type: typeof manifest.type === \"string\" ? manifest.type : undefined,\n entry: manifest.entry as InstalledMiniappManifest[\"entry\"],\n permissions: manifest.permissions as InstalledMiniappManifest[\"permissions\"],\n hardwareRequirements: manifest.hardwareRequirements as InstalledMiniappManifest[\"hardwareRequirements\"],\n actions: manifest.actions as InstalledMiniappManifest[\"actions\"],\n }\n\n let bgSource: string\n try {\n const res = await fetch(bgUrl)\n if (!res.ok) return null\n bgSource = await res.text()\n } catch {\n return null\n }\n\n return {\n bgSource,\n uiUri,\n uiOrigin: uiUri ? serverOrigin(uiUri) : null,\n uiRootDir: null,\n uiOriginName: null,\n devBuild: true,\n declaredPermissions,\n installedManifest,\n ageRating: manifest.ageRating ?? null,\n // A dev server is never host-trusted, whatever package name it claims.\n hostTrustedSystem: false,\n devUrl: resolvedUrl,\n devPort: this.resolveDevPort(hints?.devPort, packageName),\n }\n }\n\n private async resolveInstalledBundle(packageName: string, version: string): Promise<ResolvedBundle | null> {\n const entryPaths = appRegistry.getMiniappEntryPaths(packageName, version)\n if (!entryPaths?.background) return null\n\n const manifest = appRegistry.getMiniappManifest(packageName, version) as {\n packageName?: string\n name?: string\n version?: string\n sdkVersion?: string\n minHostVersion?: string\n type?: string\n ageRating?: unknown\n entry?: {background?: string; ui?: string}\n permissions?: Array<{type: string; required?: boolean; description?: string}>\n hardwareRequirements?: Array<{type: string; level: string; description?: string}>\n actions?: Array<{\n id?: unknown\n description?: unknown\n parameters?: unknown\n outputSchema?: unknown\n lifecycle?: unknown\n audience?: unknown\n }>\n } | null\n const declaredPermissions = (manifest?.permissions ?? [])\n .map((p) => p.type)\n .filter((t): t is string => typeof t === \"string\")\n const installedManifest: InstalledMiniappManifest | undefined = manifest\n ? {\n packageName: manifest.packageName ?? packageName,\n name: manifest.name,\n version: manifest.version ?? version,\n sdkVersion: manifest.sdkVersion,\n minHostVersion: manifest.minHostVersion,\n type: manifest.type,\n entry: manifest.entry,\n permissions: manifest.permissions,\n hardwareRequirements: manifest.hardwareRequirements,\n actions: manifest.actions,\n }\n : undefined\n\n let bgSource: string\n try {\n bgSource = new File(entryPaths.background).textSync()\n } catch {\n return null\n }\n\n // The screen loads from the package's own origin, which serves only this\n // version's bundle and never grants file access. A development snapshot\n // claims its name without proof, so it loads from a development origin of\n // that name instead and never sees a release's web storage. A package name\n // that can't have an origin gets no screen rather than a file:// page.\n const devBuild = version.startsWith(\"dev-\")\n const originName = devBuild ? developmentOriginName(packageName) : packageName\n const platform = originPlatform()\n const uiUri = entryPaths.uiPath ? miniappOriginUrl(originName, entryPaths.uiPath, platform) : null\n if (entryPaths.uiPath && !uiUri) {\n console.warn(`MiniappLauncher: ${packageName} can't have an origin of its own, so its screen doesn't load`)\n }\n\n return {\n bgSource,\n uiUri,\n uiOrigin: uiUri ? miniappOrigin(originName, platform) : null,\n uiRootDir: uiUri ? entryPaths.rootDir : null,\n uiOriginName: uiUri ? originName : null,\n devBuild,\n declaredPermissions,\n installedManifest,\n ageRating: manifest?.ageRating ?? null,\n // A development build never runs with the build's privileges, whatever name it claims.\n hostTrustedSystem:\n !devBuild && isHostTrustedSystemMiniapp(packageName, appRegistry.getReleaseIdentity(packageName, version)),\n // A snapshot on disk — do not wire the sidecar; the laptop is gone.\n devUrl: null,\n devPort: null,\n }\n }\n\n /**\n * Ensure a miniapp's background JS context is spawned. Idempotent — if the\n * context is already alive this is a no-op spawn-wise (it still resolves the\n * UI entry so a re-mounting host gets its `<WebView>` source back).\n *\n * Resolves once the context is SPAWNED. It does NOT block on the context's\n * CONNECT handshake — the host's WebView mount shouldn't wait on background\n * JS. Callers that need the context to be connected and ready to receive\n * messages (the action broker) follow up with\n * {@link LocalMiniappRuntime.waitForConnect}.\n */\n async ensureRunning(\n packageName: string,\n hints?: LaunchHints,\n runtimeOptions?: RuntimeLaunchOptions,\n ): Promise<LaunchResult> {\n // An install holds launches until its files and metadata commit or roll\n // back; the launch then resolves whichever bundle is active.\n const installation = this.installing.get(packageName)\n if (installation) await installation\n if (\n !isMiniappAvailable(packageName, availabilityMode(runtimeOptions)) ||\n !appRegistry.isPackageAllowed(packageName)\n ) {\n throw new Error(`MiniappLauncher: ${packageName} is disabled by deployment policy`)\n }\n if (appRegistry.isMiniappAccessRevoked(packageName)) throw new MiniappAccessRevokedError(packageName)\n const router = this.requireRouter()\n const projectRunning = runtimeOptions?.projectRunning ?? true\n\n // Already spawned: best-effort resolve for the UI entry, never throw —\n // a headless caller that doesn't need UI gets {null, null} fast even if\n // the dev server has since dropped. A user launch promotes a context a\n // transient action woke.\n if (router.registeredPackages().includes(packageName)) {\n const promoted = projectRunning && this.promote(packageName)\n const existing = await this.resolveBundle(packageName, hints, runtimeOptions).catch(() => null)\n if (promoted) this.reportLaunch(packageName, \"started\", runtimeOptions, existing?.installedManifest)\n return launchResultOf(existing)\n }\n\n // Coalesce concurrent launches of the same package onto one promise.\n const pending = this.inFlight.get(packageName)\n if (pending) {\n const joinedHidden = this.hiddenInFlight.has(packageName)\n let result: LaunchResult\n try {\n result = await pending\n } catch (error) {\n // A visible launch reports its own failure; one joined to a hidden wake fails with it.\n if (projectRunning && joinedHidden) this.reportLaunch(packageName, \"failed\", runtimeOptions)\n throw error\n }\n if (projectRunning && this.promote(packageName)) this.reportLaunch(packageName, \"started\", runtimeOptions)\n return result\n }\n\n const launch = this.spawn(packageName, hints, {...runtimeOptions, projectRunning})\n this.inFlight.set(packageName, launch)\n if (!projectRunning) this.hiddenInFlight.add(packageName)\n try {\n return await launch\n } catch (error) {\n if (projectRunning) this.reportLaunch(packageName, \"failed\", runtimeOptions)\n throw error\n } finally {\n this.inFlight.delete(packageName)\n this.hiddenInFlight.delete(packageName)\n }\n }\n\n /** Projects a context already spawned as user activity: true if this made it so. */\n private promote(packageName: string): boolean {\n const router = this.requireRouter()\n if (router.isProjectedRunning(packageName)) return false\n router.projectRunning(packageName)\n return router.isProjectedRunning(packageName)\n }\n\n /** Reports a launch this call made to Fleet, unless the apps store's `start` is making it and reports it itself. */\n private reportLaunch(\n packageName: string,\n outcome: \"started\" | \"failed\",\n runtimeOptions?: RuntimeLaunchOptions,\n manifest?: InstalledMiniappManifest,\n ): void {\n fleetEvents.launchUnlessClaimed({\n packageName,\n ...(manifest?.name ? {miniappName: manifest.name} : {}),\n ...(manifest?.version ? {versionName: manifest.version} : {}),\n start: runtimeOptions?.trigger ?? \"automatic\",\n outcome,\n })\n }\n\n /** Resolve the bundle and spawn the context. Serialized via {@link inFlight}. */\n private async spawn(\n packageName: string,\n hints?: LaunchHints,\n runtimeOptions?: RuntimeLaunchOptions,\n ): Promise<LaunchResult> {\n const router = this.requireRouter()\n const resolved = await this.resolveBundle(packageName, hints, runtimeOptions)\n if (!resolved) {\n throw new Error(`MiniappLauncher: cannot resolve bundle for ${packageName}`)\n }\n const version = resolved.installedManifest?.version\n const projectRunning = runtimeOptions?.projectRunning ?? true\n // The age gate, before the deployment checks below, which then see the state after any question the person\n // answered. Only a launch the person makes in front of the app may ask.\n const verdict = await checkMiniappAge(\n {packageName, name: resolved.installedManifest?.name || packageName, ageRating: resolved.ageRating},\n {interactive: projectRunning && AppState.currentState === \"active\"},\n )\n if (verdict !== \"allowed\") throw new MiniappAgeRestrictedError(packageName, verdict)\n // A live dev server sets devUrl. A snapshot keeps the directory name `dev-*`\n // as the active version. Either one is the scanned build; a release fallback is neither.\n const activeVersion = await appRegistry.getActiveVersion(packageName)\n const devBuild = Boolean(resolved.devUrl) || Boolean(activeVersion?.startsWith(\"dev-\"))\n if (\n // Availability may change while the bundle resolves.\n !isMiniappAvailable(packageName, availabilityMode(runtimeOptions)) ||\n (devBuild ? !isDevMiniappAllowed(packageName) : !appRegistry.isReleaseAllowed(packageName, version))\n ) {\n throw new Error(`MiniappLauncher: ${packageName} bundle is not authorized by deployment policy`)\n }\n\n // Re-check after the async resolve: a different path may have spawned it\n // while we were fetching/reading the bundle.\n if (router.registeredPackages().includes(packageName)) {\n if (projectRunning && this.promote(packageName)) {\n this.reportLaunch(packageName, \"started\", runtimeOptions, resolved.installedManifest)\n }\n } else {\n const ok = await router.spawnAndRegister(packageName, resolved.bgSource, {\n permissions: resolved.declaredPermissions,\n installedManifest: resolved.installedManifest,\n hostTrustedSystem: resolved.hostTrustedSystem,\n projectRunning,\n developmentBuild: resolved.devBuild,\n })\n if (!ok) {\n throw new Error(`MiniappLauncher: spawn failed for ${packageName}`)\n }\n\n // Dev: wire the hot-reload + log-forwarding sidecar. No-op in prod\n // (devServerBridge silently drops when no sidecar is up).\n if (resolved.devUrl && resolved.devPort != null) {\n devServerBridge.connect(packageName, resolved.devUrl, resolved.devPort)\n } else if (resolved.devUrl) {\n // Dev miniapp with no resolvable port — it still launches, but hot\n // reload + log forwarding won't connect. Surface it instead of failing\n // silently (the old inline path hard-failed with \"no dev port\").\n console.warn(`MiniappLauncher: ${packageName} has no dev port — hot reload + log forwarding disabled`)\n }\n if (projectRunning) this.reportLaunch(packageName, \"started\", runtimeOptions, resolved.installedManifest)\n }\n\n return launchResultOf(resolved)\n }\n\n /**\n * Re-spawn local miniapps that were running when the app was last killed.\n *\n * Every miniapp runs as local JavaScript in the Mentra App on the phone.\n * A host-process kill tears down its JSContext, so without this restoration\n * it stays stopped on the next launch even though the user left it running.\n *\n * Each local miniapp persists its running flag to disk on start/stop\n * (`saveLocalAppRunningState`, via the applet's `onStart`/`onStop`). We read\n * those flags back and re-spawn the background context headlessly (no\n * foreground, no navigation) — the spawn registers the package so the home\n * tray/switcher project it as running, exactly as a normal start would. The\n * WebView, if any, re-attaches lazily when the user opens the app.\n *\n * Idempotent and best-effort: skips already-spawned contexts and clears the\n * persisted running flag if ensureRunning fails (for example, bundle resolution,\n * deployment policy, or context spawning) so it does not retry every boot.\n * Each restore is an automatic launch to Fleet, reported by ensureRunning.\n * Not compatibility-gated: a previously-running background app shouldn't be\n * dropped just because glasses are momentarily disconnected at boot — it\n * resumes when they reconnect, same as mid-session.\n */\n async autostartLocalMiniapps(): Promise<void> {\n const apps = await appRegistry.getInstalledMiniapps()\n for (const app of apps) {\n // Only phone-hosted miniapps have a JSContext to re-spawn. Offline\n // built-ins (`local:false, offline:true`) restore their native running\n // state elsewhere and have no bundle to launch.\n if (!app.local) continue\n if (!getLocalAppRunningState(app.packageName)) continue\n if (this.isRunning(app.packageName)) continue\n try {\n // Restoring what was running is the platform's doing, never the user's.\n await this.ensureRunning(app.packageName, undefined, {trigger: \"automatic\"})\n } catch (e) {\n console.warn(`MiniappLauncher: autostart failed for ${app.packageName} — clearing stale running flag`, e)\n saveLocalAppRunningState(app.packageName, false)\n }\n }\n }\n\n /**\n * Ensure the context is running AND has completed its CONNECT handshake.\n * Used by the action broker, which must not deliver to a context that hasn't\n * come up yet. Throws on spawn failure or connect timeout.\n */\n async ensureConnected(\n packageName: string,\n connectTimeoutMs = 10_000,\n hints?: LaunchHints,\n runtimeOptions?: RuntimeLaunchOptions,\n ): Promise<void> {\n await this.ensureRunning(packageName, hints, runtimeOptions)\n await localMiniappRuntime.waitForConnect(packageName, connectTimeoutMs)\n }\n\n /** Tear down a miniapp's background JS context. */\n async stop(packageName: string): Promise<void> {\n // If a launch is in flight, let it finish first. Otherwise unregister()\n // no-ops on the not-yet-registered package and the pending spawn then\n // re-registers the context — leaving it running despite the stop.\n const pending = this.inFlight.get(packageName)\n if (pending) {\n try {\n await pending\n } catch {\n // Launch failed — nothing got registered, so nothing to tear down.\n }\n }\n await this.deps?.router.unregister(packageName)\n }\n\n // --- internals -----------------------------------------------------------\n\n private storedDevUrl(packageName: string): string | undefined {\n const r = storage.load<string>(`${packageName}_dev_url`)\n return r.is_ok() ? r.value : undefined\n }\n\n /** resolveDevPort — moved verbatim from the old LocalMiniappView helper. */\n private resolveDevPort(searchParam: string | undefined, packageName: string): number | null {\n if (searchParam) {\n const n = parseInt(searchParam, 10)\n if (Number.isFinite(n)) return n\n }\n const stored = storage.load<number>(`${packageName}_dev_port`)\n if (stored.is_ok()) return stored.value\n return null\n }\n}\n\nexport const miniappLauncher = new MiniappLauncher()\n"]}
1
+ {"version":3,"file":"MiniappLauncher.js","sourceRoot":"","sources":["../../src/services/MiniappLauncher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAGH,OAAO,EAAC,IAAI,EAAC,MAAM,kBAAkB,CAAA;AACrC,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAA;AAE/C,OAAO,EAAC,mBAAmB,EAAE,kBAAkB,EAA+B,MAAM,sBAAsB,CAAA;AAC1G,OAAO,EAAC,sBAAsB,EAAC,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAC,OAAO,EAAC,MAAM,0BAA0B,CA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GAAG,OAAO,CAAC,IAAI,CAAS,GAAG,WAAW,UAAU,CAAC,CAAA;QACxD,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;IACxC,CAAC;IAED,4EAA4E;IACpE,cAAc,CAAC,WAA+B,EAAE,WAAmB;QACzE,IAAI,WAAW,EAAE,CAAC;YAChB,MAAM,CAAC,GAAG,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;YACnC,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAAE,OAAO,CAAC,CAAA;QAClC,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAS,GAAG,WAAW,WAAW,CAAC,CAAA;QAC9D,IAAI,MAAM,CAAC,KAAK,EAAE;YAAE,OAAO,MAAM,CAAC,KAAK,CAAA;QACvC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA","sourcesContent":["/**\n * MiniappLauncher — headless launch/teardown of a local miniapp's background\n * JS context.\n *\n * This is the one piece of \"run a miniapp\" that used to live inside the\n * `LocalMiniappView` React component (resolve the bundle → read the manifest →\n * `spawnAndRegister`), triggered only when the Compositor mounted that\n * component on foreground. Pulling it into the runtime means:\n *\n * - `start()` can actually spawn an app even when nothing foregrounds it\n * (e.g. a system app launching another miniapp via `session.miniapps`).\n * - the action broker can wake a stopped target headlessly — no UI at all.\n * - the dev hot-reload respawn path and the WebView mount path share one\n * resolve+spawn recipe instead of three copies.\n *\n * The launcher is **headless**: no React, no RN components. The engine-owned\n * MiniappEngine hands it the {@link MentraJSRouter} instance once during\n * engine construction. OEMs embedding the runtime drive miniapp lifecycle\n * through the engine facade and stores, not a separate launcher configure API.\n *\n * Boundary: the launcher owns the **background** context. WebView *rendering*\n * (the UI layer) stays with the host — the launcher just hands back the\n * resolved UI entry so the host can mount its `<WebView>`.\n *\n * Fleet: every path that makes a local miniapp execute as user activity comes\n * through here, so the launcher reports each such launch (and each that fails\n * once past the availability gate) — a restore, a miniapp started by another\n * miniapp or an action, a screen opened directly, a restart after a reinstall.\n * A launch the apps store's `start` makes is reported by `start` itself\n * (`fleetEvents.claimLaunch`); a context already executing, or one a hidden\n * action wake keeps out of the running tray, is no launch.\n *\n * Age ratings: every launch path comes through here, so this is where a miniapp rated above the host app's own\n * rating meets the age gate as it opens, whether it was installed with the sheet or headlessly (a Fleet assignment,\n * a system miniapp). A launch the person makes in front of the app may ask their age once; any other launch needs it\n * declared already.\n */\n\nimport type {FleetLaunchFailureReason} from \"@mentra/cloud-protocol\"\nimport {File} from \"expo-file-system\"\nimport {AppState, Platform} from \"react-native\"\n\nimport {isDevMiniappAllowed, isMiniappAvailable, type MiniappAvailabilityMode} from \"../runtime/bootstrap\"\nimport {resolveDevBundleSource} from \"../utils/devMiniappSnapshot\"\nimport {storage} from \"../utils/storage/storage\"\nimport {MiniappRunningError} from \"../utils/storeInstallRuntime\"\nimport appRegistry, {getLocalAppRunningState, saveLocalAppRunningState} from \"./AppRegistry\"\nimport devServerBridge from \"./DevServerBridge\"\nimport {fleetEvents} from \"./fleet/fleetEvents\"\nimport localMiniappRuntime, {type InstalledMiniappManifest} from \"./LocalMiniappRuntime\"\nimport type {MentraJSRouter} from \"./MentraJSRouter\"\nimport {checkMiniappAge, type AgeGateVerdict, type AgeRatedMiniapp} from \"./miniappAgeGate\"\nimport {developmentOriginName, miniappOrigin, miniappOriginUrl, type MiniappOriginPlatform} from \"./miniappOrigin\"\nimport {isHostTrustedSystemMiniapp} from \"./SystemMiniappPolicy\"\n\n/** The miniapp's server no longer admits this account (Fleet revocation): it cannot launch until access returns. */\nexport class MiniappAccessRevokedError extends Error {\n constructor(readonly packageName: string) {\n super(`MiniappLauncher: access to ${packageName} was revoked`)\n this.name = \"MiniappAccessRevokedError\"\n }\n}\n\n/**\n * The miniapp is rated above the host app's own rating and the person's declared age doesn't let it open (see\n * {@link AgeGateVerdict}). A person opening it in front of the app was asked their age, or told why.\n */\nexport class MiniappAgeRestrictedError extends Error {\n constructor(\n readonly packageName: string,\n readonly verdict: Exclude<AgeGateVerdict, \"allowed\">,\n ) {\n super(`MiniappLauncher: ${packageName} is age-rated and did not open (${verdict})`)\n this.name = \"MiniappAgeRestrictedError\"\n }\n}\n\ninterface LauncherDeps {\n /** The host-constructed router (needs the native Crust binding). */\n router: MentraJSRouter\n}\n\n/** Hints the host may pass from a view's props to avoid re-deriving them. */\nexport interface LaunchHints {\n devUrl?: string\n /** Retained for caller compatibility; released launches use the committed active version. */\n version?: string\n devPort?: string\n}\n\nexport interface RuntimeLaunchOptions {\n /** False for an invocation-scoped wake that must not enter the running tray. */\n projectRunning?: boolean\n /**\n * Who started the miniapp, for the Fleet launch this call makes, if it makes one: the person (a screen they opened)\n * or the platform (a restore, another miniapp, a restart). Defaults to automatic.\n */\n trigger?: \"user\" | \"automatic\"\n}\n\nfunction availabilityMode(options?: RuntimeLaunchOptions): MiniappAvailabilityMode {\n return options?.projectRunning === false ? \"background\" : \"interactive\"\n}\n\n/** Everything the launcher resolved for a package — bg source + UI entry. */\nexport interface ResolvedBundle {\n bgSource: string\n /** Where the screen loads from. See {@link LaunchResult.uiUri}. */\n uiUri: string | null\n /** The origin `uiUri` belongs to. See {@link LaunchResult.uiOrigin}. */\n uiOrigin: string | null\n /** The bundle root the package's origin serves. See {@link LaunchResult.uiRootDir}. */\n uiRootDir: string | null\n /** The name the origin is for. See {@link LaunchResult.uiOriginName}. */\n uiOriginName: string | null\n /** A development build: a live development server or a development snapshot. */\n devBuild: boolean\n declaredPermissions: string[]\n installedManifest?: InstalledMiniappManifest\n /** What the bundle's `miniapp.json` declares as `ageRating`; null when it declares none. */\n ageRating: unknown\n /** Build-owned SYSTEM trust derived from install provenance, never the manifest. */\n hostTrustedSystem: boolean\n /** Set for dev miniapps (HTTP off the dev server); null for released. */\n devUrl: string | null\n devPort: number | null\n}\n\n/** What the host needs back to render the UI layer. */\nexport interface LaunchResult {\n /**\n * Where the screen loads from. An installed release loads from its\n * package's own origin: `miniapp://<packageName>/<ui entry>` on iOS and\n * `https://<host>.miniapp.invalid/<ui entry>` on Android (see\n * {@link miniappOriginUrl}), a development snapshot from the origin of its\n * {@link uiOriginName}. A live development build loads from its development\n * server. Null when there is no screen to load.\n */\n uiUri: string | null\n /** The origin `uiUri` belongs to, for the WebView's `originWhitelist`. */\n uiOrigin: string | null\n /**\n * The root of the active version's bundle, which the package's origin\n * serves (the WebView's `miniappOrigin.rootDir`). Null when the screen loads\n * from a development server.\n */\n uiRootDir: string | null\n /**\n * The name the origin serves `uiRootDir` under (the WebView's\n * `miniappOrigin.packageName`): the package name for a release, and\n * {@link developmentOriginName} for a development snapshot, so a development\n * build never shares web storage with a release of its name. Null with\n * `uiRootDir`.\n */\n uiOriginName: string | null\n /** A development build: a live development server or a development snapshot. */\n devBuild: boolean\n}\n\nconst NO_UI: LaunchResult = {uiUri: null, uiOrigin: null, uiRootDir: null, uiOriginName: null, devBuild: false}\n\nfunction launchResultOf(resolved: ResolvedBundle | null | undefined): LaunchResult {\n if (!resolved) return NO_UI\n return {\n uiUri: resolved.uiUri,\n uiOrigin: resolved.uiOrigin,\n uiRootDir: resolved.uiRootDir,\n uiOriginName: resolved.uiOriginName,\n devBuild: resolved.devBuild,\n }\n}\n\n/** The platform whose origin shape the Mentra App's WebView serves. */\nfunction originPlatform(): MiniappOriginPlatform {\n return Platform.OS === \"android\" ? \"android\" : \"ios\"\n}\n\n/** `scheme://host[:port]` of an http(s) URL, lowercased as a page's `location.origin` reads it. */\nfunction serverOrigin(url: string): string | null {\n const match = /^(https?:\\/\\/[^/?#]+)/i.exec(url)\n return match ? match[1].toLowerCase() : null\n}\n\n/**\n * Why a launch failed, as the code Fleet takes (Phase 12): never the error's text. A bundle that cannot be found is\n * `bundle_missing`; a deployment, age or access block `policy_blocked`; a context that did not start `spawn_failed`.\n */\nexport function launchFailureReason(error: unknown): FleetLaunchFailureReason {\n if (error instanceof MiniappAgeRestrictedError || error instanceof MiniappAccessRevokedError) return \"policy_blocked\"\n const message = error instanceof Error ? error.message : \"\"\n if (message.includes(\"cannot resolve bundle\")) return \"bundle_missing\"\n if (message.includes(\"by deployment policy\")) return \"policy_blocked\"\n if (message.includes(\"spawn failed\")) return \"spawn_failed\"\n return \"unknown\"\n}\n\nclass MiniappLauncher {\n private deps: LauncherDeps | null = null\n\n /**\n * In-flight launches keyed by packageName. Both apps.ts start() and the\n * WebView mount call ensureRunning() before the first spawnAndRegister\n * resolves — without this, neither sees the package in registeredPackages()\n * yet and both spawn the same context (a clobber/double-spawn). Concurrent\n * callers share the same promise.\n */\n private readonly inFlight = new Map<string, Promise<LaunchResult>>()\n /** In-flight launches that keep their context out of the running tray (a hidden action wake). */\n private readonly hiddenInFlight = new Set<string>()\n\n /**\n * Installs hold new launches of their package until they commit or roll\n * back: explicit installs for the whole install, automatic updates only while\n * their files change.\n */\n private readonly installing = new Map<string, Promise<void>>()\n\n /**\n * Run an automatic update only while the miniapp is idle. `install` prepares\n * the release, then calls `beforeActivate` immediately before files change:\n * a launch during preparation wins and the update defers with\n * {@link MiniappRunningError}; a launch during activation waits for the\n * commit or rollback and then reads the resulting bundle.\n */\n async installWhenIdle<T>(packageName: string, install: (beforeActivate: () => void) => Promise<T>): Promise<T> {\n const assertIdle = () => {\n if (this.isRunning(packageName) || this.inFlight.has(packageName)) throw new MiniappRunningError(packageName)\n }\n assertIdle()\n let release: (() => void) | undefined\n try {\n return await install(() => {\n assertIdle()\n release = this.reserveInstall(packageName)\n })\n } finally {\n release?.()\n }\n }\n\n /** Stabilize existing launches and hold new ones until an explicit install finishes. */\n async pauseLaunches(packageName: string): Promise<() => void> {\n const release = this.reserveInstall(packageName)\n // Launches already resolving a bundle must settle before the installer\n // decides whether a context needs stopping/restarting. A failed launch is also settled.\n await this.inFlight.get(packageName)?.catch(() => {})\n return release\n }\n\n private reserveInstall(packageName: string): () => void {\n if (this.installing.has(packageName)) throw new Error(`An install is already activating ${packageName}`)\n let resume!: () => void\n const pending = new Promise<void>((resolve) => {\n resume = resolve\n })\n this.installing.set(packageName, pending)\n return () => {\n if (this.installing.get(packageName) !== pending) return\n this.installing.delete(packageName)\n resume()\n }\n }\n\n /**\n * The name and age rating of the installed bundle a launch of `packageName` runs (the version `getActiveVersion`\n * chooses, a development snapshot included), read without waiting. The apps store checks it before it opens the\n * screen or stops other miniapps, so a refusal changes nothing. A live development server's rating is read when\n * its context spawns, where every launch is checked again.\n */\n installedAgeRating(packageName: string): AgeRatedMiniapp {\n const version = appRegistry.peekActiveVersion(packageName)\n const manifest = version\n ? (appRegistry.getMiniappManifest(packageName, version) as {name?: unknown; ageRating?: unknown} | null)\n : null\n const name = typeof manifest?.name === \"string\" && manifest.name ? manifest.name : packageName\n return {packageName, name, ageRating: manifest?.ageRating ?? null}\n }\n\n /** Wire the router in. Called once from MiniappEngine construction. */\n configure(deps: LauncherDeps): void {\n this.deps = deps\n }\n\n private requireRouter(): MentraJSRouter {\n if (!this.deps) {\n throw new Error(\"MiniappLauncher not configured — ensureMiniappEngine() has not run\")\n }\n return this.deps.router\n }\n\n /** True iff the package's background JS context is currently spawned. */\n isRunning(packageName: string): boolean {\n return this.deps?.router.registeredPackages().includes(packageName) ?? false\n }\n\n /** True iff the live context is projected as normal user activity. */\n isProjectedRunning(packageName: string): boolean {\n return this.deps?.router.isProjectedRunning(packageName) ?? false\n }\n\n /**\n * Resolve the background JS source + UI entry + declared permissions for a\n * package. Handles both dev (HTTP off the running dev server) and released\n * (the installed snapshot on disk, whose screen loads from the package's own\n * origin). Reads disk/network/storage; does\n * NOT spawn. Returns null when the bundle can't be resolved (dev server\n * unreachable with no on-disk snapshot, missing entry, no installed version).\n */\n async resolveBundle(\n packageName: string,\n hints?: LaunchHints,\n runtimeOptions?: RuntimeLaunchOptions,\n ): Promise<ResolvedBundle | null> {\n if (!isMiniappAvailable(packageName, availabilityMode(runtimeOptions))) return null\n const devAllowed = isDevMiniappAllowed(packageName)\n // Live dev code is unsigned, so it never runs under a package installed with\n // a publisher signature; that package runs its installed bundle instead.\n const liveDevAllowed = devAllowed && !appRegistry.getPublisherKeyFingerprint(packageName)\n const devUrl = liveDevAllowed ? (hints?.devUrl ?? this.storedDevUrl(packageName)) : undefined\n\n const selectedSnapshot = devAllowed ? appRegistry.getSelectedDevSnapshot(packageName) : null\n if (selectedSnapshot) return this.resolveInstalledBundle(packageName, selectedSnapshot)\n\n // --- Dev: live HTTP, then the last on-disk snapshot if the laptop is gone. ---\n // A stored URL from a scan that this workspace will not run must fall\n // through to the released bundle, or the home tile disappears.\n if (devUrl && devAllowed) {\n const source = await resolveDevBundleSource(packageName, devUrl)\n if (source.kind === \"live\") {\n const live = await this.resolveLiveHttp(packageName, source.resolvedUrl, source.manifest, hints)\n if (live) return live\n // Live probe succeeded but the entry fetch failed — still try disk.\n }\n const snapshotVersion =\n source.kind === \"snapshot\" ? source.version : appRegistry.getLatestDevSnapshotVersion(packageName)\n if (snapshotVersion) {\n const snapshot = await this.resolveInstalledBundle(packageName, snapshotVersion)\n if (snapshot) return snapshot\n }\n return null\n }\n\n // --- Released: resolve from the installed snapshot on disk. ---\n // A view can retain its old version prop across an install or rollback.\n // Resolve the committed pointer here, including after an installation wait.\n const version = await appRegistry.getActiveVersion(packageName)\n if (!version) return null\n return this.resolveInstalledBundle(packageName, version)\n }\n\n private async resolveLiveHttp(\n packageName: string,\n resolvedUrl: string,\n manifest: {entry?: unknown; permissions?: unknown; [key: string]: unknown},\n hints?: LaunchHints,\n ): Promise<ResolvedBundle | null> {\n const entry = manifest.entry as {background?: string; ui?: string} | undefined\n if (!entry?.background) return null\n\n // Use the host that actually answered — may differ from the stored IP\n // after a laptop Wi-Fi change (mDNS / Metro failover inside resolveDevBundleSource).\n const base = resolvedUrl.replace(/\\/$/, \"\")\n // entry.* are bundle-root paths (dist/ stripped); the dev server serves\n // files relative to cwd, so prepend dist/.\n const bgUrl = `${base}/dist/${entry.background.replace(/^\\.?\\/+/, \"\")}`\n const uiUri = entry.ui ? `${base}/dist/${entry.ui.replace(/^\\.?\\/+/, \"\")}` : null\n\n const perms = manifest.permissions as Array<{type?: string} | string> | undefined\n const declaredPermissions = (perms ?? [])\n .map((p) => (typeof p === \"string\" ? p : p?.type))\n .filter((t): t is string => typeof t === \"string\")\n const installedManifest: InstalledMiniappManifest = {\n packageName: typeof manifest.packageName === \"string\" ? manifest.packageName : packageName,\n name: typeof manifest.name === \"string\" ? manifest.name : undefined,\n version: typeof manifest.version === \"string\" ? manifest.version : undefined,\n sdkVersion: typeof manifest.sdkVersion === \"string\" ? manifest.sdkVersion : undefined,\n minHostVersion: typeof manifest.minHostVersion === \"string\" ? manifest.minHostVersion : undefined,\n type: typeof manifest.type === \"string\" ? manifest.type : undefined,\n entry: manifest.entry as InstalledMiniappManifest[\"entry\"],\n permissions: manifest.permissions as InstalledMiniappManifest[\"permissions\"],\n hardwareRequirements: manifest.hardwareRequirements as InstalledMiniappManifest[\"hardwareRequirements\"],\n actions: manifest.actions as InstalledMiniappManifest[\"actions\"],\n }\n\n let bgSource: string\n try {\n const res = await fetch(bgUrl)\n if (!res.ok) return null\n bgSource = await res.text()\n } catch {\n return null\n }\n\n return {\n bgSource,\n uiUri,\n uiOrigin: uiUri ? serverOrigin(uiUri) : null,\n uiRootDir: null,\n uiOriginName: null,\n devBuild: true,\n declaredPermissions,\n installedManifest,\n ageRating: manifest.ageRating ?? null,\n // A dev server is never host-trusted, whatever package name it claims.\n hostTrustedSystem: false,\n devUrl: resolvedUrl,\n devPort: this.resolveDevPort(hints?.devPort, packageName),\n }\n }\n\n private async resolveInstalledBundle(packageName: string, version: string): Promise<ResolvedBundle | null> {\n const entryPaths = appRegistry.getMiniappEntryPaths(packageName, version)\n if (!entryPaths?.background) return null\n\n const manifest = appRegistry.getMiniappManifest(packageName, version) as {\n packageName?: string\n name?: string\n version?: string\n sdkVersion?: string\n minHostVersion?: string\n type?: string\n ageRating?: unknown\n entry?: {background?: string; ui?: string}\n permissions?: Array<{type: string; required?: boolean; description?: string}>\n hardwareRequirements?: Array<{type: string; level: string; description?: string}>\n actions?: Array<{\n id?: unknown\n description?: unknown\n parameters?: unknown\n outputSchema?: unknown\n lifecycle?: unknown\n audience?: unknown\n }>\n } | null\n const declaredPermissions = (manifest?.permissions ?? [])\n .map((p) => p.type)\n .filter((t): t is string => typeof t === \"string\")\n const installedManifest: InstalledMiniappManifest | undefined = manifest\n ? {\n packageName: manifest.packageName ?? packageName,\n name: manifest.name,\n version: manifest.version ?? version,\n sdkVersion: manifest.sdkVersion,\n minHostVersion: manifest.minHostVersion,\n type: manifest.type,\n entry: manifest.entry,\n permissions: manifest.permissions,\n hardwareRequirements: manifest.hardwareRequirements,\n actions: manifest.actions,\n }\n : undefined\n\n let bgSource: string\n try {\n bgSource = new File(entryPaths.background).textSync()\n } catch {\n return null\n }\n\n // The screen loads from the package's own origin, which serves only this\n // version's bundle and never grants file access. A development snapshot\n // claims its name without proof, so it loads from a development origin of\n // that name instead and never sees a release's web storage. A package name\n // that can't have an origin gets no screen rather than a file:// page.\n const devBuild = version.startsWith(\"dev-\")\n const originName = devBuild ? developmentOriginName(packageName) : packageName\n const platform = originPlatform()\n const uiUri = entryPaths.uiPath ? miniappOriginUrl(originName, entryPaths.uiPath, platform) : null\n if (entryPaths.uiPath && !uiUri) {\n console.warn(`MiniappLauncher: ${packageName} can't have an origin of its own, so its screen doesn't load`)\n }\n\n return {\n bgSource,\n uiUri,\n uiOrigin: uiUri ? miniappOrigin(originName, platform) : null,\n uiRootDir: uiUri ? entryPaths.rootDir : null,\n uiOriginName: uiUri ? originName : null,\n devBuild,\n declaredPermissions,\n installedManifest,\n ageRating: manifest?.ageRating ?? null,\n // A development build never runs with the build's privileges, whatever name it claims.\n hostTrustedSystem:\n !devBuild && isHostTrustedSystemMiniapp(packageName, appRegistry.getReleaseIdentity(packageName, version)),\n // A snapshot on disk — do not wire the sidecar; the laptop is gone.\n devUrl: null,\n devPort: null,\n }\n }\n\n /**\n * Ensure a miniapp's background JS context is spawned. Idempotent — if the\n * context is already alive this is a no-op spawn-wise (it still resolves the\n * UI entry so a re-mounting host gets its `<WebView>` source back).\n *\n * Resolves once the context is SPAWNED. It does NOT block on the context's\n * CONNECT handshake — the host's WebView mount shouldn't wait on background\n * JS. Callers that need the context to be connected and ready to receive\n * messages (the action broker) follow up with\n * {@link LocalMiniappRuntime.waitForConnect}.\n */\n async ensureRunning(\n packageName: string,\n hints?: LaunchHints,\n runtimeOptions?: RuntimeLaunchOptions,\n ): Promise<LaunchResult> {\n // An install holds launches until its files and metadata commit or roll\n // back; the launch then resolves whichever bundle is active.\n const installation = this.installing.get(packageName)\n if (installation) await installation\n if (\n !isMiniappAvailable(packageName, availabilityMode(runtimeOptions)) ||\n !appRegistry.isPackageAllowed(packageName)\n ) {\n throw new Error(`MiniappLauncher: ${packageName} is disabled by deployment policy`)\n }\n if (appRegistry.isMiniappAccessRevoked(packageName)) throw new MiniappAccessRevokedError(packageName)\n const router = this.requireRouter()\n const projectRunning = runtimeOptions?.projectRunning ?? true\n\n // Already spawned: best-effort resolve for the UI entry, never throw —\n // a headless caller that doesn't need UI gets {null, null} fast even if\n // the dev server has since dropped. A user launch promotes a context a\n // transient action woke.\n if (router.registeredPackages().includes(packageName)) {\n const promoted = projectRunning && this.promote(packageName)\n const existing = await this.resolveBundle(packageName, hints, runtimeOptions).catch(() => null)\n if (promoted) this.reportLaunch(packageName, \"started\", runtimeOptions, existing?.installedManifest)\n return launchResultOf(existing)\n }\n\n // Coalesce concurrent launches of the same package onto one promise.\n const pending = this.inFlight.get(packageName)\n if (pending) {\n const joinedHidden = this.hiddenInFlight.has(packageName)\n let result: LaunchResult\n try {\n result = await pending\n } catch (error) {\n // A visible launch reports its own failure; one joined to a hidden wake fails with it.\n if (projectRunning && joinedHidden) this.reportLaunch(packageName, \"failed\", runtimeOptions, undefined, launchFailureReason(error))\n throw error\n }\n if (projectRunning && this.promote(packageName)) this.reportLaunch(packageName, \"started\", runtimeOptions)\n return result\n }\n\n const launch = this.spawn(packageName, hints, {...runtimeOptions, projectRunning})\n this.inFlight.set(packageName, launch)\n if (!projectRunning) this.hiddenInFlight.add(packageName)\n try {\n return await launch\n } catch (error) {\n if (projectRunning) this.reportLaunch(packageName, \"failed\", runtimeOptions, undefined, launchFailureReason(error))\n throw error\n } finally {\n this.inFlight.delete(packageName)\n this.hiddenInFlight.delete(packageName)\n }\n }\n\n /** Projects a context already spawned as user activity: true if this made it so. */\n private promote(packageName: string): boolean {\n const router = this.requireRouter()\n if (router.isProjectedRunning(packageName)) return false\n router.projectRunning(packageName)\n return router.isProjectedRunning(packageName)\n }\n\n /** Reports a launch this call made to Fleet, unless the apps store's `start` is making it and reports it itself. */\n private reportLaunch(\n packageName: string,\n outcome: \"started\" | \"failed\",\n runtimeOptions?: RuntimeLaunchOptions,\n manifest?: InstalledMiniappManifest,\n failureReason?: FleetLaunchFailureReason,\n ): void {\n fleetEvents.launchUnlessClaimed({\n packageName,\n ...(manifest?.name ? {miniappName: manifest.name} : {}),\n ...(manifest?.version ? {versionName: manifest.version} : {}),\n start: runtimeOptions?.trigger ?? \"automatic\",\n outcome,\n ...(outcome === \"failed\" ? {failureReason: failureReason ?? \"unknown\"} : {}),\n })\n }\n\n /** Resolve the bundle and spawn the context. Serialized via {@link inFlight}. */\n private async spawn(\n packageName: string,\n hints?: LaunchHints,\n runtimeOptions?: RuntimeLaunchOptions,\n ): Promise<LaunchResult> {\n const router = this.requireRouter()\n const resolved = await this.resolveBundle(packageName, hints, runtimeOptions)\n if (!resolved) {\n throw new Error(`MiniappLauncher: cannot resolve bundle for ${packageName}`)\n }\n const version = resolved.installedManifest?.version\n const projectRunning = runtimeOptions?.projectRunning ?? true\n // The age gate, before the deployment checks below, which then see the state after any question the person\n // answered. Only a launch the person makes in front of the app may ask.\n const verdict = await checkMiniappAge(\n {packageName, name: resolved.installedManifest?.name || packageName, ageRating: resolved.ageRating},\n {interactive: projectRunning && AppState.currentState === \"active\"},\n )\n if (verdict !== \"allowed\") throw new MiniappAgeRestrictedError(packageName, verdict)\n // A live dev server sets devUrl. A snapshot keeps the directory name `dev-*`\n // as the active version. Either one is the scanned build; a release fallback is neither.\n const activeVersion = await appRegistry.getActiveVersion(packageName)\n const devBuild = Boolean(resolved.devUrl) || Boolean(activeVersion?.startsWith(\"dev-\"))\n if (\n // Availability may change while the bundle resolves.\n !isMiniappAvailable(packageName, availabilityMode(runtimeOptions)) ||\n (devBuild ? !isDevMiniappAllowed(packageName) : !appRegistry.isReleaseAllowed(packageName, version))\n ) {\n throw new Error(`MiniappLauncher: ${packageName} bundle is not authorized by deployment policy`)\n }\n\n // Re-check after the async resolve: a different path may have spawned it\n // while we were fetching/reading the bundle.\n if (router.registeredPackages().includes(packageName)) {\n if (projectRunning && this.promote(packageName)) {\n this.reportLaunch(packageName, \"started\", runtimeOptions, resolved.installedManifest)\n }\n } else {\n const ok = await router.spawnAndRegister(packageName, resolved.bgSource, {\n permissions: resolved.declaredPermissions,\n installedManifest: resolved.installedManifest,\n hostTrustedSystem: resolved.hostTrustedSystem,\n projectRunning,\n developmentBuild: resolved.devBuild,\n })\n if (!ok) {\n throw new Error(`MiniappLauncher: spawn failed for ${packageName}`)\n }\n\n // Dev: wire the hot-reload + log-forwarding sidecar. No-op in prod\n // (devServerBridge silently drops when no sidecar is up).\n if (resolved.devUrl && resolved.devPort != null) {\n devServerBridge.connect(packageName, resolved.devUrl, resolved.devPort)\n } else if (resolved.devUrl) {\n // Dev miniapp with no resolvable port — it still launches, but hot\n // reload + log forwarding won't connect. Surface it instead of failing\n // silently (the old inline path hard-failed with \"no dev port\").\n console.warn(`MiniappLauncher: ${packageName} has no dev port — hot reload + log forwarding disabled`)\n }\n if (projectRunning) this.reportLaunch(packageName, \"started\", runtimeOptions, resolved.installedManifest)\n }\n\n return launchResultOf(resolved)\n }\n\n /**\n * Re-spawn local miniapps that were running when the app was last killed.\n *\n * Every miniapp runs as local JavaScript in the Mentra App on the phone.\n * A host-process kill tears down its JSContext, so without this restoration\n * it stays stopped on the next launch even though the user left it running.\n *\n * Each local miniapp persists its running flag to disk on start/stop\n * (`saveLocalAppRunningState`, via the applet's `onStart`/`onStop`). We read\n * those flags back and re-spawn the background context headlessly (no\n * foreground, no navigation) — the spawn registers the package so the home\n * tray/switcher project it as running, exactly as a normal start would. The\n * WebView, if any, re-attaches lazily when the user opens the app.\n *\n * Idempotent and best-effort: skips already-spawned contexts and clears the\n * persisted running flag if ensureRunning fails (for example, bundle resolution,\n * deployment policy, or context spawning) so it does not retry every boot.\n * Each restore is an automatic launch to Fleet, reported by ensureRunning.\n * Not compatibility-gated: a previously-running background app shouldn't be\n * dropped just because glasses are momentarily disconnected at boot — it\n * resumes when they reconnect, same as mid-session.\n */\n async autostartLocalMiniapps(): Promise<void> {\n const apps = await appRegistry.getInstalledMiniapps()\n for (const app of apps) {\n // Only phone-hosted miniapps have a JSContext to re-spawn. Offline\n // built-ins (`local:false, offline:true`) restore their native running\n // state elsewhere and have no bundle to launch.\n if (!app.local) continue\n if (!getLocalAppRunningState(app.packageName)) continue\n if (this.isRunning(app.packageName)) continue\n try {\n // Restoring what was running is the platform's doing, never the user's.\n await this.ensureRunning(app.packageName, undefined, {trigger: \"automatic\"})\n } catch (e) {\n console.warn(`MiniappLauncher: autostart failed for ${app.packageName} — clearing stale running flag`, e)\n saveLocalAppRunningState(app.packageName, false)\n }\n }\n }\n\n /**\n * Ensure the context is running AND has completed its CONNECT handshake.\n * Used by the action broker, which must not deliver to a context that hasn't\n * come up yet. Throws on spawn failure or connect timeout.\n */\n async ensureConnected(\n packageName: string,\n connectTimeoutMs = 10_000,\n hints?: LaunchHints,\n runtimeOptions?: RuntimeLaunchOptions,\n ): Promise<void> {\n await this.ensureRunning(packageName, hints, runtimeOptions)\n await localMiniappRuntime.waitForConnect(packageName, connectTimeoutMs)\n }\n\n /** Tear down a miniapp's background JS context. */\n async stop(packageName: string): Promise<void> {\n // If a launch is in flight, let it finish first. Otherwise unregister()\n // no-ops on the not-yet-registered package and the pending spawn then\n // re-registers the context — leaving it running despite the stop.\n const pending = this.inFlight.get(packageName)\n if (pending) {\n try {\n await pending\n } catch {\n // Launch failed — nothing got registered, so nothing to tear down.\n }\n }\n await this.deps?.router.unregister(packageName)\n }\n\n // --- internals -----------------------------------------------------------\n\n private storedDevUrl(packageName: string): string | undefined {\n const r = storage.load<string>(`${packageName}_dev_url`)\n return r.is_ok() ? r.value : undefined\n }\n\n /** resolveDevPort — moved verbatim from the old LocalMiniappView helper. */\n private resolveDevPort(searchParam: string | undefined, packageName: string): number | null {\n if (searchParam) {\n const n = parseInt(searchParam, 10)\n if (Number.isFinite(n)) return n\n }\n const stored = storage.load<number>(`${packageName}_dev_port`)\n if (stored.is_ok()) return stored.value\n return null\n }\n}\n\nexport const miniappLauncher = new MiniappLauncher()\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"FleetReporter.d.ts","sourceRoot":"","sources":["../../../src/services/fleet/FleetReporter.ts"],"names":[],"mappings":"AAyDA,OAAO,EACL,kBAAkB,EAInB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAuB,KAAK,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAG1E,OAAO,EAAmD,KAAK,UAAU,EAAC,MAAM,cAAc,CAAA;AAG9F,MAAM,WAAW,aAAa;IAC5B,qHAAqH;IACrH,KAAK,IAAI,IAAI,CAAA;IACb,2GAA2G;IAC3G,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,KAAK,WAAW,GAAG,OAAO,kBAAkB,CAAA;AAC5C,0DAA0D;AAC1D,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,WAAW,EAAE,gBAAgB,GAAG,oBAAoB,GAAG,sBAAsB,CAAC,GAAG;IACrH,IAAI,EAAE;QAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAA;K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,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAA;KAAC,CAAA;CAC9D,CAAA;AAED,MAAM,WAAW,iBAAiB;IAChC,4CAA4C;IAC5C,KAAK,CAAC,EAAE,kBAAkB,CAAA;IAC1B,0CAA0C;IAC1C,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,qGAAqG;IACrG,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,cAAc,CAAA;IACvD,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,MAAM,CAAA;CACtB;AAwBD,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,GAAG,MAAM,CAG7E;AA6DD,wBAAgB,mBAAmB,CAAC,IAAI,GAAE,iBAAsB,GAAG,aAAa,CAkoB/E;AAID,mGAAmG;AACnG,wBAAgB,kBAAkB,IAAI,IAAI,CAOzC;AAED,gCAAgC;AAChC,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEvD"}
@@ -139,6 +139,8 @@ export function createFleetReporter(deps = {}) {
139
139
  clearPartition: (partition) => queue.clearPartition(partition),
140
140
  size: (partition) => queue.size(partition),
141
141
  nextSequence: (partition, collectorSessionId) => queue.nextSequence(partition, collectorSessionId),
142
+ noteTelemetryLoss: (partition, packageName, kind, count, at) => queue.noteTelemetryLoss(partition, packageName, kind, count, at),
143
+ takeTelemetryLosses: (partition, at) => queue.takeTelemetryLosses(partition, at),
142
144
  };
143
145
  const collector = (deps.createCollector ?? ((q) => createFleetCollector({ queue: q })))(collectorQueue);
144
146
  function guard(what, work) {
@@ -361,6 +363,7 @@ export function createFleetReporter(deps = {}) {
361
363
  const at = now();
362
364
  // takeLosses clears the counts it returns, so their gap is queued before anything else can happen.
363
365
  recordLosses(r, queue.takeLosses(r.partition, at), at);
366
+ recordTelemetryLosses(r, at);
364
367
  const records = queue.nextBatch(r.partition, r.batchLimit, MAX_BATCH_BYTES);
365
368
  if (records.length === 0)
366
369
  return ASLEEP;
@@ -618,10 +621,50 @@ export function createFleetReporter(deps = {}) {
618
621
  warn("recording a coverage gap", error);
619
622
  }
620
623
  }
624
+ /**
625
+ * The miniapp telemetry lost since the last upload, per package, as one `telemetry_loss` record. Telemetry losses
626
+ * never become coverage gaps. Counts that cannot be queued are lost with the events they counted.
627
+ */
628
+ function recordTelemetryLosses(r, at) {
629
+ const losses = queue.takeTelemetryLosses(r.partition, at);
630
+ if (losses === null)
631
+ return;
632
+ const entries = Object.entries(losses.packages)
633
+ .map(([packageName, counts]) => ({ packageName, ...counts }))
634
+ .filter((loss) => loss.overLimit + loss.evicted + loss.expired + loss.rejected > 0)
635
+ .slice(0, FLEET_LIMITS.maxTelemetryLossPackages);
636
+ if (entries.length === 0)
637
+ return;
638
+ const end = iso(at);
639
+ const from = losses.from !== null && timeOf(losses.from) !== null && timeOf(losses.from) <= at ? losses.from : end;
640
+ try {
641
+ queue.enqueue(r.partition, {
642
+ schemaVersion: FLEET_SCHEMA_VERSION,
643
+ recordId: newId(),
644
+ phoneDeviceId: phoneDeviceId(),
645
+ collectorSessionId: r.collectorSessionId,
646
+ sequence: queue.nextSequence(r.partition, r.collectorSessionId),
647
+ observedAt: end,
648
+ capabilities: ["miniapp_telemetry"],
649
+ kind: "telemetry_loss",
650
+ payload: { from, to: end, losses: entries },
651
+ });
652
+ }
653
+ catch (error) {
654
+ warn("recording telemetry losses", error);
655
+ }
656
+ }
621
657
  function recordRejected(r, record, at) {
622
658
  // A refused gap gets no gap of its own, so a rejection can never feed itself.
623
659
  if (record.kind === "coverage_gap")
624
660
  return;
661
+ // Rejected telemetry is counted for its miniapp, never as a gap; a refused loss report is not counted again.
662
+ if (record.kind === "telemetry_event") {
663
+ queue.noteTelemetryLoss(r.partition, record.payload.packageName, "rejected", 1, at);
664
+ return;
665
+ }
666
+ if (record.kind === "telemetry_loss")
667
+ return;
625
668
  const time = iso(timeOf(record.observedAt) ?? at);
626
669
  enqueueGap(r, { reason: "record_rejected", from: time, to: time, droppedRecordCount: 1 }, at);
627
670
  }