@ateam-ai-mobile/plugin-runtime 0.1.8 → 0.1.9
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.
- package/dist/{chunk-RXR6M623.mjs → chunk-SICFDA5K.mjs} +121 -15
- package/dist/chunk-SICFDA5K.mjs.map +1 -0
- package/dist/index.d.mts +114 -18
- package/dist/index.d.ts +114 -18
- package/dist/index.js +142 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -59
- package/dist/index.mjs.map +1 -1
- package/dist/{loader-UUOPZQSI.mjs → loader-MSZ4PVTO.mjs} +2 -2
- package/package.json +2 -2
- package/src/api/plugins.ts +15 -9
- package/src/bundles/bundleManager.ts +28 -9
- package/src/bundles/bundleModuleNames.ts +52 -0
- package/src/bundles/bundleUrl.ts +41 -0
- package/src/bundles/storage.ts +52 -0
- package/src/hooks/usePlugin.ts +2 -1
- package/src/index.ts +10 -36
- package/src/sdk/CameraPreview.tsx +7 -0
- package/src/sdk/device-state.ts +20 -7
- package/src/sdk/index.ts +34 -0
- package/src/sdk/types.ts +13 -0
- package/src/sdk/voice.ts +48 -4
- package/src/tools/loader.ts +4 -2
- package/src/tools/registry.ts +2 -2
- package/dist/chunk-RXR6M623.mjs.map +0 -1
- /package/dist/{loader-UUOPZQSI.mjs.map → loader-MSZ4PVTO.mjs.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/api/plugins.ts","../src/bundles/bundleUrl.ts","../src/bundles/bundleManager.ts","../src/sdk/index.ts","../src/sdk/registration.ts","../src/sdk/voice.ts","../src/sdk/device-state.ts","../src/sdk/primitives.ts","../src/sdk/components.ts","../src/host.ts","../src/sdk/CameraPreview.tsx","../src/sdk/usePluginTheme.ts","../src/sdk/useApi.ts","../src/surfaces/SurfaceDrawer.tsx","../src/surfaces/AdaOrb.tsx","../src/surfaces/SurfaceCard.tsx","../src/surfaces/SurfaceFullscreen.tsx","../src/registry/store.ts","../src/registry/SurfaceDispatcher.tsx","../src/bundles/bundleModuleNames.ts","../src/utils/sha256.ts","../src/bundles/integrity.ts","../src/bundles/storage.ts","../src/bridge/native.ts","../src/deviceStateHost.ts","../src/tools/registry.ts","../src/voiceHost.ts","../src/pluginRuntime.ts","../src/tools/loader.ts"],"sourcesContent":["import { apiFetch } from '@ateam-ai-mobile/core';\nimport { getCoreApiUrl } from '@ateam-ai-mobile/core';\nimport { pluginBundleUrl } from '../bundles/bundleUrl';\n\n/**\n * Summary returned by cp.listContextPlugins — no `render` field.\n * Used for the plugin grid (name, icon, description).\n */\nexport interface PluginSurfaceMeta {\n type: 'drawer' | 'card' | 'fullscreen' | 'header' | 'ambient' | 'nudge';\n visibility?: 'always' | 'user' | 'engine';\n trigger?: { from?: string; gesture?: string };\n icon?: string;\n title?: string;\n subtitle?: string;\n privacy?: boolean;\n prompt?: string;\n}\n\nexport interface PluginSummary {\n id: string;\n name: string;\n version: string;\n description?: string;\n _source?: string; // \"mcp\" for connector plugins\n _connectorId?: string;\n /** Declarative surface placement — added by the surface-SDK migration */\n surface?: PluginSurfaceMeta;\n}\n\n/**\n * Native capability flags (declared in manifest).\n */\nexport interface NativeCapabilities {\n camera?: boolean;\n location?: boolean;\n biometrics?: boolean;\n offline?: boolean;\n backgroundTasks?: boolean;\n fileSystem?: boolean;\n notifications?: boolean;\n bluetooth?: boolean;\n haptics?: boolean;\n}\n\n/**\n * Lifecycle hooks for service/hybrid plugins.\n */\nexport interface PluginHooks {\n onAppStart?: boolean;\n onPushReceived?: boolean;\n onConnectivity?: boolean;\n onForeground?: boolean;\n onBackground?: boolean;\n}\n\n/**\n * Render mode — polymorphic.\n * - 'iframe': existing WebView (backward compat)\n * - 'react-native': native RN component only\n * - 'adaptive': both web and native, host picks best\n */\nexport type PluginRenderMode =\n | { mode: 'iframe'; iframeUrl: string; bundleUrl?: string; bundleHash?: string; external?: boolean }\n | { mode: 'react-native'; component: string; bundleUrl?: string; bundleHash?: string; bundleId?: string }\n | {\n mode: 'adaptive';\n iframe: { iframeUrl: string; external?: boolean };\n reactNative: { component: string; bundleUrl?: string; bundleHash?: string; bundleId?: string };\n };\n\n/**\n * Full manifest returned by cp.getContextPlugin.\n * Extended to support native mobile plugins alongside existing web plugins.\n */\nexport interface PluginManifest extends PluginSummary {\n type?: 'ui' | 'service' | 'hybrid';\n render: PluginRenderMode;\n native?: NativeCapabilities;\n hooks?: PluginHooks;\n channels?: string[] | {\n events: string[];\n actions: string[];\n };\n capabilities?: Record<string, unknown>;\n _mcpEndpoint?: string;\n}\n\n/**\n * Determine if a manifest supports native rendering.\n */\nexport function supportsNative(manifest: PluginManifest): boolean {\n const mode = manifest.render?.mode;\n return mode === 'react-native' || mode === 'adaptive';\n}\n\n/**\n * Get the native component ID from a manifest (if it has native support).\n */\nexport function getNativeComponentId(manifest: PluginManifest): string | null {\n if (manifest.render?.mode === 'react-native') return manifest.render.component;\n if (manifest.render?.mode === 'adaptive') return manifest.render.reactNative?.component;\n return null;\n}\n\n/**\n * The native bundle URL for a manifest that has a bundle on the server, or null.\n *\n * Core writes `bundleUrl` into the manifest only when the connector's bundle\n * exists, so its PRESENCE says \"there is a bundle\". Its SPELLING is not used:\n * Core writes the id unencoded, and a connector could inject any URL. The URL\n * returned is always the one derivation, pluginBundleUrl(manifest.id), the same\n * one the rendered surface uses. Returning the manifest's own string (6294cc3)\n * gave the device-tool loader a second spelling, so one plugin downloaded and\n * evaluated twice, as two module instances (MGAP-C8).\n */\nexport function getNativeBundleUrl(manifest: PluginManifest): string | null {\n const render = manifest.render;\n const declared =\n (manifest as any).bundleUrl ||\n (render?.mode === 'react-native' ? render.bundleUrl : null) ||\n (render?.mode === 'adaptive' ? render.reactNative?.bundleUrl : null);\n return declared && manifest.id ? pluginBundleUrl(manifest.id) : null;\n}\n\n/**\n * Get the SHA-256 integrity hash for a native bundle, if the server provided one.\n * Used post-download to verify the bundle bytes weren't tampered in transit\n * — a MITM-replaced bundle gets `eval`'d as RN code with full capability access.\n */\nexport function getNativeBundleHash(manifest: PluginManifest): string | null {\n const direct = (manifest as any).bundleHash;\n if (direct) return direct;\n const render = manifest.render;\n if (render.mode === 'react-native') return (render as any).bundleHash || null;\n if (render.mode === 'adaptive') return render.reactNative?.bundleHash || null;\n return null;\n}\n\n/**\n * Check if a manifest can be rendered as a WebView (iframe or adaptive with iframe).\n */\nexport function supportsWebView(manifest: PluginManifest): boolean {\n return manifest.render?.mode === 'iframe' || manifest.render?.mode === 'adaptive';\n}\n\n/**\n * List all available UI plugins via MCP JSON-RPC.\n * Returns summary data only (no render field).\n * Protocol: cp.listContextPlugins → core plugins + MCP connector plugins.\n */\nexport async function listPlugins(): Promise<PluginSummary[]> {\n const res = await apiFetch<{\n result: {\n content: Array<{ type: string; text: string }>;\n structuredContent?: { plugins?: PluginSummary[] };\n };\n }>('/mcp', {\n method: 'POST',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: Date.now(),\n method: 'tools/call',\n params: {\n name: 'cp.listContextPlugins',\n arguments: {},\n },\n }),\n });\n\n // Accept multiple response formats (matches web mcpClient.js fallback chain)\n const structured = res.result?.structuredContent?.plugins;\n if (structured) return structured;\n\n const text = res.result?.content?.[0]?.text;\n if (!text) return [];\n try {\n const parsed = JSON.parse(text);\n return parsed.plugins || parsed || [];\n } catch {\n return [];\n }\n}\n\n/**\n * Get a specific plugin's FULL manifest (with render.iframeUrl).\n * Protocol: cp.getContextPlugin({ id }) → resolves iframeUrl for core/MCP/external.\n *\n * IMPORTANT: The backend parameter is `id`, not `pluginId`.\n */\nexport async function getPlugin(pluginId: string): Promise<PluginManifest | null> {\n const res = await apiFetch<{\n result: {\n content: Array<{ type: string; text: string }>;\n structuredContent?: PluginManifest;\n };\n }>('/mcp', {\n method: 'POST',\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: Date.now(),\n method: 'tools/call',\n params: {\n name: 'cp.getContextPlugin',\n arguments: { id: pluginId }, // Backend expects { id }, NOT { pluginId }\n },\n }),\n });\n\n // Accept structured or text response\n if (res.result?.structuredContent) return res.result.structuredContent;\n\n const text = res.result?.content?.[0]?.text;\n if (!text) return null;\n try {\n const parsed = JSON.parse(text);\n // Backend may return error object\n if (parsed.error) {\n console.warn('[getPlugin] Backend error:', parsed.error);\n return null;\n }\n return parsed;\n } catch {\n return null;\n }\n}\n\n/**\n * Resolve plugin iframe URL to a full URL for WebView.\n * Matches the web frontend's PluginHost.jsx logic:\n * - External (absolute http): append ?tenant=\n * - MCP plugin (/mcp-ui/...): inject tenant into path → /mcp-ui/{tenant}/{connectorId}/...\n * - Core plugin (/assets/...): prepend getCoreApiUrl()\n */\nexport function resolvePluginUrl(manifest: PluginManifest, tenant?: string): string {\n // Extract iframeUrl from different render modes.\n // Adaptive manifests in the wild use a flat shape — `render.iframeUrl` —\n // not the nested `render.iframe.iframeUrl` from the type. Accept both.\n const render = manifest.render as any;\n let url: string | undefined;\n if (render?.mode === 'iframe') {\n url = render.iframeUrl;\n } else if (render?.mode === 'adaptive') {\n url = render.iframeUrl || render.iframe?.iframeUrl;\n }\n // react-native only → no URL\n if (!url) return '';\n\n // Already absolute URL (external plugins like Voice)\n if (url.startsWith('http')) {\n const sep = url.includes('?') ? '&' : '?';\n return tenant ? `${url}${sep}tenant=${encodeURIComponent(tenant)}` : url;\n }\n\n // MCP plugin — inject tenant into path: /mcp-ui/{connectorId}/... → /mcp-ui/{tenant}/{connectorId}/...\n if (tenant && url.startsWith('/mcp-ui/')) {\n const tenantUrl = url.replace('/mcp-ui/', `/mcp-ui/${encodeURIComponent(tenant)}/`);\n return `${getCoreApiUrl()}${tenantUrl}`;\n }\n\n // Core plugin — prepend core API base\n return `${getCoreApiUrl()}${url}`;\n}\n","/**\n * THE bundle URL of a plugin: the one place it is spelled.\n *\n * Core serves a plugin's React Native bundle at\n * `/api/ui-plugins/<pluginId>/bundle.js`, where the id is URL-encoded because\n * plugin ids contain ':' (`mcp:<connector>:<plugin>`). The bundle manager keys\n * everything it holds by this string: evaluated modules, in-flight downloads and\n * the disk index. To it, two spellings of one plugin's URL are two plugins, which\n * means two downloads, two evaluations and two separate copies of module state.\n *\n * That happened (MGAP-C8). The rendered surface derived the encoded route, while\n * the device-tool loader (6294cc3) used the manifest's `bundleUrl`, which Core\n * fills in UNENCODED. A plugin that was on screen and also had device tools ran\n * as two module instances, and its tools never saw its UI's state.\n *\n * So the URL is DERIVED from the plugin id and never read from a manifest (a\n * connector-supplied URL is ignored, as in ea435149). Every path that builds a\n * plugin's bundle URL, or looks one up, calls this function.\n */\nexport function pluginBundleUrl(pluginId: string): string {\n return `/api/ui-plugins/${encodeURIComponent(pluginId)}/bundle.js`;\n}\n\n/**\n * Is `url` this plugin's bundle URL, however the id is spelled in it?\n *\n * Core's manifest writes the id unencoded (`/api/ui-plugins/mcp:c:p/bundle.js`).\n * That is the same route as `pluginBundleUrl(pluginId)`, but it is not a key the\n * SDK may use. The check compares decoded forms, so it asks \"same route?\" without\n * parsing the URL. A URL that cannot be decoded is not a match (fail closed).\n */\nexport function isPluginBundleUrl(url: unknown, pluginId: string): boolean {\n if (typeof url !== 'string') return false;\n const canonical = pluginBundleUrl(pluginId);\n if (url === canonical) return true;\n try {\n return decodeURIComponent(url) === decodeURIComponent(canonical);\n } catch {\n return false;\n }\n}\n","/**\n * Global Plugin Bundle Manager — singleton.\n *\n * ONE download per bundleUrl (deduplicates multi-plugin bundles); all plugin\n * renderer instances share the same loaded modules. Persistence goes through\n * the BundleStorage adapter (in-memory by default; @ateam-ai-mobile/expo provides disk).\n *\n * Usage:\n * const component = await bundleManager.load(pluginId, bundleUrl, version, hash, grants);\n * // component = { id, type, Component, ... } (RegisteredUIPlugin)\n */\nimport React from 'react';\nimport {\n useState, useEffect, useCallback, useMemo, useRef,\n useContext, useReducer, useLayoutEffect, useImperativeHandle, useDebugValue,\n} from 'react';\nimport * as ReactNative from 'react-native';\nimport { apiFetchRaw, getTenant } from '@ateam-ai-mobile/core';\nimport * as PluginSDKModule from '../sdk';\nimport SurfaceDrawer from '../surfaces/SurfaceDrawer';\nimport SurfaceCard from '../surfaces/SurfaceCard';\nimport SurfaceFullscreen from '../surfaces/SurfaceFullscreen';\nimport { useSurfaceStore } from '../registry/store';\nimport SurfaceDispatcher from '../registry/SurfaceDispatcher';\nimport { resolveBundleModule } from '../host';\nimport { PLUGIN_SDK_MODULE, sdkModuleRefusal } from './bundleModuleNames';\nimport { sha256Hex } from '../utils/sha256';\nimport { assertBundleIntegrity } from './integrity';\nimport { getBundleStorage, loadCacheIndex, type BundleCacheEntry, type TrustedToolDeclaration } from './storage';\nimport { pluginBundleUrl, isPluginBundleUrl } from './bundleUrl';\n\n/** The key a plugin's bundle is held under: its ONE canonical URL whenever the\n * URL given is that plugin's route in any spelling (MGAP-C8). Any other URL is\n * used as given. Every public load enters through this, so no caller, whichever\n * spelling it holds, can make one plugin load twice. */\nfunction bundleKey(pluginId: string, bundleUrl: string): string {\n return isPluginBundleUrl(bundleUrl, pluginId) ? pluginBundleUrl(pluginId) : bundleUrl;\n}\nimport { registerDeviceTools, unregisterDeviceTools, listDeviceTools } from '../tools/registry';\nimport type { PluginGrants } from '../pluginRuntime';\nimport type { RegisteredUIPlugin } from '../sdk/types';\n\n// ── Require shim ─────────────────────────────────────────────\n// Bundles are built with external: ['react', 'react-native', '@adas/plugin-sdk']\n// so they emit require() calls that this shim resolves at runtime. Anything\n// beyond the built-ins (react-native-webview, expo-linking, …) must be\n// registered by the host via registerBundleModules() — the host is the one\n// that actually has those modules installed. Any other name in the SDK's own\n// namespaces ('@ateam-ai-mobile/*', '@adas/*') fails the evaluation BY NAME —\n// see bundleModuleNames.ts for why that, and only that, is not warn-and-{}.\n\nconst ReactShim: any = {\n __esModule: true,\n default: React,\n ...React,\n // Explicitly include hooks (React 19 may not have them as own enumerable props)\n useState, useEffect, useCallback, useMemo, useRef, useContext,\n useReducer, useLayoutEffect, useImperativeHandle, useDebugValue,\n createElement: React.createElement,\n Fragment: React.Fragment,\n Component: React.Component,\n PureComponent: React.PureComponent,\n createContext: React.createContext,\n forwardRef: React.forwardRef,\n memo: React.memo,\n Children: React.Children,\n cloneElement: React.cloneElement,\n isValidElement: React.isValidElement,\n createRef: React.createRef,\n lazy: React.lazy,\n Suspense: React.Suspense,\n};\n\n// Freeze PluginSDK shim to prevent bundle monkey-patching of register().\n// Surface containers + registry ride along — the reference app's original\n// shim exposed the FULL plugin-sdk index, and bundles built against it may\n// import SurfaceDrawer/useSurfaceStore/etc. from '@adas/plugin-sdk'.\nconst PluginSDKShim = Object.freeze({\n ...PluginSDKModule,\n SurfaceDrawer,\n SurfaceCard,\n SurfaceFullscreen,\n useSurfaceStore,\n SurfaceDispatcher,\n PluginSDK: Object.freeze({\n ...PluginSDKModule.PluginSDK,\n register: PluginSDKModule.PluginSDK.register,\n }),\n register: PluginSDKModule.register,\n});\n\nconst requireShim = (name: string) => {\n if (name === 'react') return ReactShim;\n if (name === 'react-native') return ReactNative;\n if (name === PLUGIN_SDK_MODULE) return PluginSDKShim;\n const refusal = sdkModuleRefusal(name);\n if (refusal) throw new Error(`[BundleManager] ${refusal}`);\n const hostModule = resolveBundleModule(name);\n if (hostModule !== undefined) return hostModule;\n console.warn(`[BundleManager] Unknown module: ${name} — register it via registerBundleModules()`);\n return {};\n};\n\n// ── Cache constants ──────────────────────────────────────────\n\nconst CACHE_TTL = 7 * 24 * 60 * 60 * 1000; // 7 days\n\n// What findPluginExport looks for: a renderable plugin, or one with a `tools` section.\nconst hasComponent = (val: any): boolean =>\n !!val && typeof val === 'object' && typeof val.Component === 'function';\nconst hasTools = (val: any): boolean =>\n !!val && typeof val === 'object' && Array.isArray(val.tools) && val.tools.length > 0;\n\n// ── BundleManager singleton ──────────────────────────────────\n\n/** Where the bytes currently running came from. */\nexport type LoadedBundleSource = 'download' | 'disk-cache' | 'memory';\n\n/**\n * Provenance of one loaded bundle — what is RUNNING, not what was requested.\n *\n * `hash` is the sha256 of the evaluated bytes. `expected` is the hash the\n * server's manifest advertised for that url. Equal means the phone is running\n * the build the server currently describes; different means it is not, and the\n * pair says so without needing a rebuild, a reinstall or a guess.\n */\nexport interface LoadedBundleInfo {\n bundleUrl: string;\n version: string;\n /** sha256 (hex, lowercase) of the bytes that were evaluated. */\n hash: string | null;\n /** sha256 the server advertised for this url at load time, if any. */\n expected: string | null;\n source: LoadedBundleSource;\n tenant: string | null;\n loadedAt: number;\n}\n\nclass BundleManager {\n /** In-memory module cache: bundleUrl → evaluated module.exports. Holds ONE\n * tenant's modules at a time — the tenant boundary is `cacheTenant` /\n * `requireTenant()`, NOT the key. */\n private modules = new Map<string, any>();\n /** What is actually RUNNING, keyed by bundleUrl (for the current tenant). See\n * getLoadedBundles(). */\n private provenance = new Map<string, LoadedBundleInfo>();\n\n /** In-flight download deduplication: bundleUrl → Promise */\n private inflight = new Map<string, Promise<any>>();\n\n /**\n * The tenant the in-memory caches (modules / provenance / inflight) currently\n * belong to. This is the tenant BOUNDARY for evaluated code.\n *\n * A bundleUrl resolves PER-TENANT on the server — one url, different bytes for\n * different tenants — so a memory hit keyed on url alone would hand tenant B\n * the module tenant A already evaluated and ran. PR #9 scoped the DISK cache\n * (per-tenant index + hash gate); the in-memory map was left url-keyed. This\n * closes that: the caches only ever hold ONE tenant's modules, and a switch\n * drops them before anything is served.\n */\n private cacheTenant: string | null = null;\n\n /**\n * pluginIds this manager registered device tools for. A tenant switch drops\n * the in-memory modules AND unregisters these, so the incoming tenant's bundle\n * re-registers into a clean registry instead of being refused as a duplicate\n * of the previous tenant's tools.\n */\n private registeredToolPluginIds = new Set<string>();\n\n /** bundleUrl → the trusted declaration last recorded on its disk-cache entry\n * this session, so a memory hit with unchanged grants skips the index I/O. */\n private recordedDeclarations = new Map<string, string>();\n\n /**\n * Enforce the in-memory tenant boundary. Call at the top of every public load\n * path, BEFORE any cache read.\n *\n * FAIL CLOSED: without a tenant identity we cannot prove a cached module is\n * this session's, so we drop everything and refuse rather than risk serving\n * one tenant's evaluated code to another. On a tenant change we drop the\n * previous tenant's modules (and their tool registrations) before proceeding.\n */\n /**\n * Monotonic load generation. Bumped on every in-memory wipe (a tenant change,\n * fail-closed, or clearAll). A load captures it at ENTRY; a completion whose\n * generation no longer matches is stale and is discarded before it can commit.\n * This closes the async race the sequential guard cannot: tenant A's in-flight\n * loadModule can resolve AFTER a switch to B — clearing `inflight` does not\n * cancel that Promise — and would otherwise write A's module / provenance /\n * device tools into the singleton now marked cacheTenant=B.\n */\n private epoch = 0;\n\n private requireTenant(): string {\n const tenant = getTenant();\n if (!tenant) {\n this.dropInMemory();\n this.cacheTenant = null;\n throw new Error(\n '[BundleManager] refusing to load a tenant-scoped bundle without a tenant identity (fail closed)',\n );\n }\n if (tenant !== this.cacheTenant) {\n // First load, or a tenant switch: the caches hold the previous tenant's\n // evaluated modules — none of it may cross the boundary.\n this.dropInMemory();\n this.cacheTenant = tenant;\n }\n return tenant;\n }\n\n /** Drop every in-memory cache and unregister the device tools this manager\n * registered — used on a tenant change and by clearAll(). */\n private dropInMemory(): void {\n for (const pluginId of this.registeredToolPluginIds) {\n try { unregisterDeviceTools(pluginId); } catch { /* ignore */ }\n }\n this.registeredToolPluginIds.clear();\n this.recordedDeclarations.clear();\n this.modules.clear();\n this.provenance.clear();\n this.inflight.clear();\n // Bump the generation: any load that started before this wipe is now stale\n // and must not commit its results (see epoch / stale check in loadModule).\n this.epoch++;\n }\n\n /** True once the boundary has moved since a load captured `epoch` — i.e. a\n * tenant switch (or wipe) happened while this load was in flight. Its results\n * belong to a tenant that is no longer current and must be discarded. */\n private isStale(epoch: number, tenant: string): boolean {\n return this.epoch !== epoch || getTenant() !== tenant;\n }\n\n /** Record a memory serve: the running bytes are the already-evaluated module,\n * and `expected` is refreshed from the manifest hash the caller JUST passed —\n * so after a redeploy the record reads hash !== expected (STALE) instead of\n * the old in-sync pair. The ONE place both memory paths (load()'s early return\n * and loadModule's) record reuse. No-op if nothing was recorded yet. */\n private markMemoryHit(bundleUrl: string, expectedHash?: string): void {\n const prev = this.provenance.get(bundleUrl);\n if (prev) {\n this.provenance.set(bundleUrl, { ...prev, source: 'memory', expected: expectedHash?.toLowerCase() ?? prev.expected });\n }\n }\n\n // ── Public API ──────────────────────────────────────────────\n\n /**\n * Load a plugin component. Returns the RegisteredUIPlugin object.\n * Handles: in-memory cache → disk cache → download → evaluate → extract.\n *\n * `expectedHash` (SHA-256 hex from cp.getContextPlugin manifest) MUST be\n * provided for any bundle the user has not previously verified — without\n * it, a tampered bundle is `eval`'d as JS with full RN runtime + every\n * native capability the manifest declares.\n *\n * `grants` is what the MANIFEST grants this plugin (resolvePluginGrants) — the\n * only authority its device tools are registered under. Omitted (e.g. a\n * prewarm from the slim plugin list) → the bundle is loaded but its tools are\n * NOT registered: without the manifest there is nothing trusted to gate them\n * on, and registering with nothing would downgrade a registration the\n * manifest-driven tool loader already made.\n */\n async load(\n pluginId: string,\n bundleUrl: string,\n version: string,\n expectedHash?: string,\n grants?: PluginGrants,\n ): Promise<RegisteredUIPlugin> {\n bundleUrl = bundleKey(pluginId, bundleUrl);\n // Tenant boundary FIRST — fail closed without a tenant, drop the previous\n // tenant's modules on a switch, and CAPTURE the tenant + generation at entry\n // so a switch during the async load is caught before any result is used.\n const tenant = this.requireTenant();\n const epoch = this.epoch;\n\n // 1. In-memory cache — instant\n const cached = this.getComponentFromMemory(pluginId, bundleUrl);\n if (cached) {\n // Record the reuse. load() returns HERE, before loadModule, so without\n // this the provenance would freeze on the first download/disk source and\n // getLoadedBundles() would never report a memory serve. (loadModule's\n // own memory branch covers the loadTools path, which has no early return.)\n this.markMemoryHit(bundleUrl, expectedHash);\n if (grants) await this.commitTools(pluginId, bundleUrl, grants, tenant, epoch);\n return cached;\n }\n\n // 2. Deduplicate in-flight downloads for same bundleUrl\n let modulePromise = this.inflight.get(bundleUrl);\n if (!modulePromise) {\n const promise = this.loadModule(bundleUrl, version, expectedHash, tenant, epoch);\n modulePromise = promise;\n this.inflight.set(bundleUrl, promise);\n // Swallow rejection on the cleanup chain — the original `await` below\n // still surfaces the error to the caller. Delete ONLY our own entry: a\n // tenant switch clears `inflight` and the incoming tenant installs a NEW\n // promise for the same url, so an unconditional delete here would evict\n // B's live entry when stale A finally settles — breaking dedup and letting\n // a duplicate B load start.\n promise.catch(() => {}).finally(() => {\n if (this.inflight.get(bundleUrl) === promise) this.inflight.delete(bundleUrl);\n });\n }\n\n await modulePromise;\n\n // The switch could have landed while we awaited. Even if another tenant has\n // since populated modules[bundleUrl], this load must not return that code.\n if (this.isStale(epoch, tenant)) {\n throw new Error('[BundleManager] tenant changed while loading — discarding (fail closed)');\n }\n\n // Tools register at LOAD, not at mount — and for a UI bundle too, so a hybrid\n // plugin's tools are callable whether or not its component is found.\n if (grants) await this.commitTools(pluginId, bundleUrl, grants, tenant, epoch);\n\n // 3. Extract component for this specific pluginId\n const component = this.getComponentFromMemory(pluginId, bundleUrl);\n if (!component) {\n throw new Error(\n `Bundle loaded from ${bundleUrl} but no component found for \"${pluginId}\". ` +\n `Available exports: ${this.describeModule(this.modules.get(bundleUrl))}`\n );\n }\n\n return component;\n }\n\n /**\n * Load a bundle for its `tools/` section only — no UI required.\n *\n * Same download, same integrity check, same evaluation as `load()`; the only\n * difference is that a bundle exporting tools and no `Component` is a success\n * here rather than \"no component found\". Returns the tool names registered.\n *\n * `grants` is REQUIRED: the tools are registered under `pluginId` with exactly\n * what the manifest grants (see load()), never what the bundle claims.\n */\n async loadTools(\n pluginId: string,\n bundleUrl: string,\n version: string,\n expectedHash: string | undefined,\n grants: PluginGrants,\n ): Promise<string[]> {\n if (!grants) {\n throw new Error(`[BundleManager] loadTools(${pluginId}) needs the manifest's grants (resolvePluginGrants) — refusing to register tools on the bundle's own claim`);\n }\n bundleUrl = bundleKey(pluginId, bundleUrl);\n // Tenant boundary FIRST — same fail-closed / drop-on-switch as load(), and\n // capture the tenant + generation for the stale check after the async load.\n const tenant = this.requireTenant();\n const epoch = this.epoch;\n let modulePromise = this.inflight.get(bundleUrl);\n if (!modulePromise) {\n const promise = this.loadModule(bundleUrl, version, expectedHash, tenant, epoch);\n modulePromise = promise;\n this.inflight.set(bundleUrl, promise);\n // Delete ONLY our own entry — see load() for why an unconditional delete\n // lets stale A evict B's live inflight promise across a tenant switch.\n promise.catch(() => {}).finally(() => {\n if (this.inflight.get(bundleUrl) === promise) this.inflight.delete(bundleUrl);\n });\n }\n await modulePromise;\n\n if (this.isStale(epoch, tenant)) {\n throw new Error('[BundleManager] tenant changed while loading tools — discarding (fail closed)');\n }\n await this.commitTools(pluginId, bundleUrl, grants, tenant, epoch);\n\n const names = listDeviceTools()\n .filter(t => t.pluginId === pluginId)\n .map(t => t.name);\n\n if (names.length === 0) {\n console.warn(\n `[BundleManager] ${pluginId}: bundle loaded from ${bundleUrl} but registered no tools. ` +\n `Available exports: ${this.describeModule(this.modules.get(bundleUrl))}`,\n );\n }\n return names;\n }\n\n /**\n * Prewarm: load every plugin bundle in the background after app boot, so a\n * later open is instant (in-memory hit) instead of round-tripping the\n * network. Errors are swallowed per-plugin — one bad bundle shouldn't\n * block others. Concurrency capped at 3.\n */\n async prewarmAll(items: Array<{\n pluginId: string;\n bundleUrl: string;\n version: string;\n bundleHash?: string;\n /** The manifest's grants, when the caller has the manifest (see load()). */\n grants?: PluginGrants;\n }>): Promise<void> {\n const queue = [...items];\n const concurrency = Math.min(3, queue.length);\n const start = Date.now();\n let okCount = 0;\n let failCount = 0;\n\n const worker = async () => {\n while (queue.length > 0) {\n const it = queue.shift();\n if (!it) return;\n try {\n await this.load(it.pluginId, it.bundleUrl, it.version, it.bundleHash, it.grants);\n okCount++;\n } catch (err) {\n failCount++;\n // Silent — preload is best-effort. Log for diagnostics only.\n console.log(`[prewarm] ${it.pluginId}: ${err instanceof Error ? err.message : String(err)}`);\n }\n }\n };\n\n await Promise.all(Array.from({ length: concurrency }, worker));\n console.log(`[prewarm] ${okCount} loaded, ${failCount} failed in ${Date.now() - start}ms`);\n }\n\n /**\n * Clear all caches (in-memory + storage).\n */\n async clearAll(): Promise<void> {\n // Full reset — in-memory modules + provenance + inflight + the device tools\n // this manager registered, then the tenant marker and the disk storage.\n this.dropInMemory();\n this.cacheTenant = null;\n try {\n await getBundleStorage().clearAll();\n } catch (err) {\n console.warn('[BundleManager] clearAll error:', err);\n }\n }\n\n /**\n * Clear cache for a specific plugin/bundle.\n */\n async clearPlugin(pluginId: string): Promise<void> {\n const storage = getBundleStorage();\n const index = await loadCacheIndex(storage);\n // The index is keyed by bundle URL (0ea266d4), so the plugin's entry is\n // under its canonical URL, never under its id.\n const bundleUrl = pluginBundleUrl(pluginId);\n const entry = index[bundleUrl];\n if (entry) {\n this.modules.delete(bundleUrl);\n delete index[bundleUrl];\n await storage.saveIndex(index);\n try {\n await storage.deleteBundle(entry.localPath);\n } catch { /* ignore */ }\n }\n }\n\n /**\n * What every loaded bundle IS, right now: the sha256 of the bytes running,\n * the hash the server advertised, and where they came from.\n *\n * Deliberately not filtered or prettified — this is the raw answer to \"did my\n * redeploy reach the phone?\", and it is comparable directly against the\n * manifest `bundleHash` and the server's X-Bundle-SHA256 header.\n */\n getLoadedBundles(): LoadedBundleInfo[] {\n return [...this.provenance.values()];\n }\n\n // ── Private: module loading pipeline ────────────────────────\n\n private async loadModule(\n bundleUrl: string,\n version: string,\n expectedHash: string | undefined,\n // The tenant + generation captured at the caller's ENTRY. Every step that\n // commits into the singleton (disk write, evaluate, module/provenance set,\n // tool registration) is gated on these still being current — a switch to\n // another tenant during the download must NOT let this load's results land.\n expectedTenant: string,\n expectedEpoch: number,\n ): Promise<void> {\n // The boundary may already have moved before we even start (a switch landed\n // between requireTenant() and here). Fail closed rather than proceed.\n if (this.isStale(expectedEpoch, expectedTenant)) {\n throw new Error('[BundleManager] tenant changed before load started — discarding (fail closed)');\n }\n // Already in memory? Then the running bytes are whatever this session\n // already evaluated — record the reuse so provenance never goes silent.\n if (this.modules.has(bundleUrl)) {\n this.markMemoryHit(bundleUrl, expectedHash);\n return;\n }\n\n const storage = getBundleStorage();\n const index = await loadCacheIndex(storage);\n const expectedLc = expectedHash ? expectedHash.toLowerCase() : null;\n\n // Check disk cache. A cache hit is only valid when the cached SHA-256\n // matches the manifest hash exactly — never trust a cached bundle\n // without proof. The file is read via entry.localPath (the content-addressed\n // path recorded at write time), never reconstructed from url+version, so a\n // hit follows the index straight to the right bytes.\n let content: string | null = null;\n // The SHA-256 that gate-kept THIS content (the manifest hash for a cache hit,\n // the freshly-verified download hash otherwise) — re-checked inline at the\n // eval so a tampered cache file cannot run (see evaluate()).\n let verifiedHash: string | null = null;\n let servedFrom: LoadedBundleSource = 'download';\n for (const entry of Object.values(index)) {\n if (entry.bundleUrl === bundleUrl && entry.version === version) {\n const age = Date.now() - entry.timestamp;\n const hashOk = expectedLc && entry.bundleHash && entry.bundleHash.toLowerCase() === expectedLc;\n if (age < CACHE_TTL && hashOk) {\n content = await storage.readBundle(entry.localPath);\n if (content) { verifiedHash = entry.bundleHash!.toLowerCase(); servedFrom = 'disk-cache'; break; }\n }\n }\n }\n\n // Download if not cached\n if (!content) {\n const downloaded = await this.download(bundleUrl, expectedLc);\n content = downloaded.content;\n verifiedHash = downloaded.sha256.toLowerCase();\n // The download is the long await where a tenant switch is most likely to\n // land. If it did, discard NOW — before we stamp a disk-cache entry with\n // the (now wrong) current tenant.\n if (this.isStale(expectedEpoch, expectedTenant)) {\n throw new Error('[BundleManager] tenant changed during download — discarding (fail closed)');\n }\n // Save with verified hash. CONTENT-ADDRESS the file by its own sha256, NOT\n // by url+version: a bundleUrl+version pair is identical across tenants but\n // resolves to DIFFERENT bytes per tenant, so a url+version filename is\n // SHARED between them. A stale tenant-A writeBundle that completes after a\n // switch to B would then clobber B's cached file bytes at that shared path.\n // Keying the file by verifiedHash gives A's bytes and B's bytes distinct\n // paths that can never collide (identical bytes dedup to one file, which is\n // correct). The index entry below — keyed by url, stamped with the captured\n // tenant + hash + this localPath — is unchanged and stays authoritative.\n try {\n const localPath = await storage.writeBundle(`${verifiedHash}.js`, content);\n // The index entry is the AUTHORITATIVE disk-cache commit: loadFromDiskCache\n // reads the index (a loose file with no entry is never selected), and it\n // trusts the entry's `tenant` stamp as the authorization boundary while\n // passing the entry's OWN hash (an integrity check that cannot fail). So:\n // (a) stamp ownership from the CAPTURED tenant, never live getTenant() —\n // writeBundle awaited, and a switch here would otherwise label A's\n // bytes as B, which the recovery path would later re-run under B;\n // (b) do not publish the entry at all if the tenant/generation moved\n // while we awaited — fail closed, leaving only an orphan file.\n if (!this.isStale(expectedEpoch, expectedTenant)) {\n index[bundleUrl] = {\n localPath,\n version,\n timestamp: Date.now(),\n bundleUrl,\n bundleHash: downloaded.sha256,\n tenant: expectedTenant,\n } satisfies BundleCacheEntry;\n await storage.saveIndex(index);\n }\n } catch (err) {\n console.warn('[BundleManager] Cache write error:', err);\n }\n }\n\n // FINAL boundary check before anything commits into the singleton. This is\n // the one that also covers the disk-cache-hit path (which never entered the\n // download branch above). Everything after this line — evaluate, module set,\n // provenance set, tool registration — writes tenant-scoped state; if the\n // tenant moved while we awaited, none of it may land (fail closed).\n if (this.isStale(expectedEpoch, expectedTenant)) {\n throw new Error('[BundleManager] tenant changed while loading — discarding stale bundle before eval (fail closed)');\n }\n\n // Evaluate — the eval re-hashes `content` against verifiedHash first.\n const mod = this.evaluate(content, bundleUrl, verifiedHash);\n this.modules.set(bundleUrl, mod);\n\n // Record WHAT IS RUNNING. Until this existed, nothing on the device or the\n // server could answer \"which build is the phone actually executing?\" — so a\n // redeploy that failed to arrive was indistinguishable from one that did,\n // and the only diagnosis available was to reinstall and guess.\n // `expected` is the server's advertised manifest hash: when it differs from\n // `hash`, the phone is running something the server did not just describe.\n this.provenance.set(bundleUrl, {\n bundleUrl,\n version,\n hash: verifiedHash,\n expected: expectedLc,\n source: servedFrom,\n // The captured owner — same rule as the disk stamp. The final stale check\n // above guarantees getTenant() === expectedTenant here, but binding it to\n // the captured value keeps the ownership record impossible to mislabel.\n tenant: expectedTenant,\n loadedAt: Date.now(),\n });\n console.log(\n `[BundleManager] RUNNING ${bundleUrl} v${version} sha=${(verifiedHash || 'none').slice(0, 12)} ` +\n `(${servedFrom}${expectedLc && verifiedHash && expectedLc !== verifiedHash ? `, EXPECTED ${expectedLc.slice(0, 12)} — STALE` : ''})`,\n );\n }\n\n /**\n * Register THIS plugin's device tools under the TRUSTED declaration, then\n * record that declaration on the disk-cache entry. Runs on every trusted load\n * — memory hit included — so the grants in force are always the latest the\n * manifest gave (a revoked grant stops applying on the next load, not the next\n * app start). Callers run it only after their stale check.\n */\n private async commitTools(\n pluginId: string,\n bundleUrl: string,\n grants: PluginGrants,\n tenant: string,\n epoch: number,\n ): Promise<void> {\n const declaration: TrustedToolDeclaration = {\n pluginId,\n capabilities: grants.capabilities,\n stateDomains: grants.stateDomains,\n };\n this.registerToolsFromModule(this.modules.get(bundleUrl), declaration);\n await this.recordTrustedDeclaration(bundleUrl, declaration, tenant, epoch);\n }\n\n /**\n * Put the plugin's own `tools` section in the device tool registry — under the\n * pluginId and grants the MANIFEST resolved, never the bundle's own `id`,\n * `capabilities` or `stateDomains`. A bundle is code the manifest authorised\n * by hash; what it may touch is the manifest's to say, same as its rendered\n * surface (resolvePluginRuntimeProps). Its own `id` would also let it register\n * as another plugin — including the host's platform tools, which a same-id\n * re-registration replaces.\n *\n * Only this plugin's export (the same lookup the component uses) is\n * registered. Another export's tools in the same bundle belong to another\n * plugin and register when THAT plugin's manifest loads it.\n */\n private registerToolsFromModule(mod: any, { pluginId, capabilities, stateDomains }: TrustedToolDeclaration): void {\n if (!mod) return;\n\n const own = this.findPluginExport(mod, pluginId, hasTools);\n const others = Object.keys(mod).filter((k) => hasTools(mod[k]) && mod[k] !== own);\n if (others.length > 0) {\n console.warn(\n `[BundleManager] ${pluginId}: not registering tools from export(s) ${others.join(', ')} — ` +\n `they are not this plugin's, and only their own manifest can grant them`,\n );\n }\n if (!own) return;\n\n // The bundle's own declaration grants nothing, but a gap between it and the\n // manifest is the author's bug — name it, or the tool just reads \"not declared\".\n const ungranted = [\n ...(Array.isArray(own.stateDomains) ? own.stateDomains : []).filter((d: any) => !stateDomains?.includes(d)),\n ...Object.keys(own.capabilities || {}).filter((k) => own.capabilities[k] === true && !(capabilities as any)?.[k]),\n ];\n if (ungranted.length > 0) {\n console.warn(\n `[BundleManager] ${pluginId}: bundle declares ${ungranted.join(', ')} but the manifest does not grant it — denied`,\n );\n }\n\n try {\n registerDeviceTools(pluginId, own.tools, capabilities, stateDomains);\n // Remember it so a tenant switch (or clearAll) can unregister the OLD\n // tenant's tools before the incoming tenant re-registers.\n this.registeredToolPluginIds.add(pluginId);\n } catch (err) {\n console.warn(\n `[BundleManager] tool registration failed for ${pluginId}:`,\n err instanceof Error ? err.message : String(err),\n );\n }\n }\n\n /**\n * Record the trusted declaration on this tenant's disk-cache entry for the\n * bytes RUNNING — the recovery path (tools/loader loadFromDiskCache) has no\n * manifest and re-registers with exactly this. Only onto an entry this tenant\n * owns whose hash is the running hash: the grant was issued for these bytes,\n * and those are the bytes recovery will evaluate. Best-effort — a lost write\n * leaves no `trusted`, which recovery treats as fail closed.\n */\n private async recordTrustedDeclaration(\n bundleUrl: string,\n declaration: TrustedToolDeclaration,\n tenant: string,\n epoch: number,\n ): Promise<void> {\n const key = JSON.stringify(declaration);\n if (this.recordedDeclarations.get(bundleUrl) === key) return;\n try {\n const storage = getBundleStorage();\n const index = await loadCacheIndex(storage);\n const entry = index[bundleUrl];\n const running = this.provenance.get(bundleUrl)?.hash;\n if (!entry || entry.tenant !== tenant || !running || entry.bundleHash?.toLowerCase() !== running) return;\n if (this.isStale(epoch, tenant)) return;\n if (JSON.stringify(entry.trusted) !== key) {\n index[bundleUrl] = { ...entry, trusted: declaration };\n await storage.saveIndex(index);\n }\n this.recordedDeclarations.set(bundleUrl, key);\n } catch (err) {\n console.warn('[BundleManager] could not record trusted declaration:', err);\n }\n }\n\n /**\n * Download + integrity-verify a bundle. Refuses to return when:\n * - manifest hash and computed hash disagree\n * - server's `X-Bundle-SHA256` disagrees with manifest hash\n * - no expected hash AND no server hash header (cannot prove the bundle\n * wasn't tampered with — fail closed rather than trust the wire).\n */\n private async download(bundleUrl: string, expectedHash: string | null): Promise<{ content: string; sha256: string }> {\n const cacheBust = `${bundleUrl}${bundleUrl.includes('?') ? '&' : '?'}t=${Date.now()}`;\n const response = await apiFetchRaw(cacheBust);\n if (!response.ok) {\n const body = await response.text().catch(() => '');\n throw new Error(`Download failed: ${response.status} ${response.statusText} — ${body.substring(0, 200)}`);\n }\n\n const content = await response.text();\n if (content.length < 50 || content.trimStart().startsWith('<!')) {\n throw new Error('Bundle content is empty or HTML — server may have returned an error page');\n }\n\n const headerHash = (response.headers.get('x-bundle-sha256') || '').toLowerCase();\n const computed = sha256Hex(content);\n\n if (expectedHash) {\n if (computed !== expectedHash) {\n throw new Error(\n `Bundle integrity FAIL: expected sha256=${expectedHash.slice(0, 12)}... got ${computed.slice(0, 12)}.... Refusing to evaluate.`\n );\n }\n if (headerHash && headerHash !== expectedHash) {\n throw new Error(\n `Bundle hash mismatch: manifest=${expectedHash.slice(0, 12)}... server=${headerHash.slice(0, 12)}.... Refusing to evaluate.`\n );\n }\n } else if (headerHash) {\n if (computed !== headerHash) {\n throw new Error(\n `Bundle body sha256 (${computed.slice(0, 12)}...) does not match server's X-Bundle-SHA256 (${headerHash.slice(0, 12)}...).`\n );\n }\n console.warn(`[BundleManager] No manifest bundleHash — verified via X-Bundle-SHA256 header only`);\n } else {\n throw new Error(\n `No bundleHash in manifest and no X-Bundle-SHA256 header from server. Refusing to evaluate untrusted bundle.`\n );\n }\n\n return { content, sha256: computed };\n }\n\n private evaluate(content: string, bundleUrl: string, verifiedHash: string | null): any {\n // R8 SECURITY GATE — mandatory, fail-closed integrity INLINE at the eval, on\n // the exact bytes about to run. The download path verifies too, but a disk-\n // cache hit reads a file whose STORED metadata hash matched; it never re-hashes\n // the actual bytes, so a tampered cache file would execute. Re-hashing here\n // refuses a missing or mismatched hash whatever path produced `content`.\n //\n // NOTE — this is integrity, NOT a sandbox. `new Function` shares this JS\n // realm; a bundle that passes the hash still runs with full in-app authority\n // (its only capability gating is the plugin manifest via gatePluginNative).\n // The hash proves the bytes are the ones the trusted manifest names; it does\n // not isolate them. Publisher SIGNATURE is deliberately NOT required — the\n // manifest hash already comes from an authenticated Core call\n // (docs/decisions/REMOTE_BUNDLE_INTEGRITY.md).\n assertBundleIntegrity(content, verifiedHash, bundleUrl);\n\n // Strip __toESM wrapping — our shim already provides correct ESM objects.\n // esbuild's __toESM + isNodeMode=1 double-wraps and breaks React 19 hooks.\n let cleaned = content.replace(\n /__toESM\\(require\\((\"[^\"]+\")\\)(?:,\\s*\\d+)?\\)/g,\n 'require($1)',\n );\n\n // Strip __toCommonJS wrapper — it creates a getter-based Proxy that\n // collapses all named exports to the same object in Hermes/JSC.\n cleaned = cleaned.replace(\n /module\\.exports\\s*=\\s*__toCommonJS\\((\\w+)\\)/g,\n 'module.exports = $1',\n );\n\n const mod: { exports: any } = { exports: {} };\n try {\n const factory = new Function(\n 'module', 'exports', 'require', '__filename', '__dirname',\n cleaned,\n );\n factory(mod, mod.exports, requireShim, bundleUrl, 'adas-plugin-bundles');\n } catch (err) {\n throw new Error(`Bundle evaluation failed: ${err instanceof Error ? err.message : String(err)}`);\n }\n\n // Materialize getter-based exports into plain values.\n // esbuild's __export uses Object.defineProperty getters which can\n // misbehave in Hermes/JSC — force-resolve them now.\n const raw = mod.exports;\n const materialized: Record<string, any> = {};\n for (const key of Object.getOwnPropertyNames(raw)) {\n try {\n materialized[key] = raw[key];\n } catch { /* skip broken getters */ }\n }\n return materialized;\n }\n\n // ── Private: component extraction ───────────────────────────\n\n /** Find a plugin component in a loaded module. */\n private getComponentFromMemory(pluginId: string, bundleUrl: string): RegisteredUIPlugin | null {\n return this.findPluginExport(this.modules.get(bundleUrl), pluginId, hasComponent);\n }\n\n /**\n * Find THIS plugin's export in a loaded module — the one lookup both the\n * component and the device tools use, so a plugin's UI and its tools always\n * come from the same export. `accept` says what the caller needs from it.\n * Handles: direct key match, PascalCase key, default export, multi-plugin .id match.\n */\n private findPluginExport(mod: any, pluginId: string, accept: (val: any) => boolean): any | null {\n if (!mod) return null;\n\n const shortName = pluginId.includes(':') ? pluginId.split(':').pop()! : pluginId;\n\n // 1. Direct key match (full pluginId as key)\n if (accept(mod[pluginId])) return mod[pluginId];\n\n // 2. PascalCase match from shortName (most reliable for combined bundles)\n // e.g., \"memories-panel\" → \"MemoriesPanel\"\n const pascal = shortName.replace(/(^|-)([a-z])/g, (_: string, __: string, c: string) => c.toUpperCase());\n if (accept(mod[pascal])) return mod[pascal];\n\n // 3. Default export (single-plugin bundles)\n if (accept(mod.default)) return mod.default;\n\n // 4. Match by .id field (last resort — can be unreliable in combined bundles)\n for (const key of Object.keys(mod)) {\n const val = mod[key];\n if (val && (val.id === pluginId || val.id === shortName) && accept(val)) return val;\n }\n\n return null;\n }\n\n private describeModule(mod: any): string {\n if (!mod) return '(empty)';\n return Object.keys(mod)\n .map(k => {\n const v = mod[k];\n if (v && typeof v === 'object' && v.id) return `${k}(id=\"${v.id}\")`;\n return k;\n })\n .join(', ');\n }\n}\n\n/** Singleton — shared across all plugin renderers */\nexport const bundleManager = new BundleManager();\n","/**\n * @adas/plugin-sdk namespace — everything a PLUGIN author imports.\n * Remote bundles resolve `require('@adas/plugin-sdk')` to exactly this\n * module via the bundle manager's require shim.\n */\n\n// Registration API\nexport { register, registerService, registerTools } from './registration';\nimport { register, registerService, registerTools } from './registration';\nexport const PluginSDK = { register, registerService, registerTools } as const;\n\n// Types\nexport type {\n PluginBridge,\n PluginNative,\n PluginContext,\n PluginProps,\n ThemeTokens,\n HapticsAPI,\n CameraAPI,\n LocationAPI,\n StorageAPI,\n NotificationsAPI,\n ConnectivityAPI,\n FileSystemAPI,\n CookiesAPI,\n WebViewCookie,\n SharingAPI,\n ScannerAPI,\n NfcAPI,\n BluetoothAPI,\n BluetoothDevice,\n VisionAPI,\n VisionText,\n VisionLabel,\n VisionObject,\n VisionFrameQuality,\n MapsAPI,\n MapsCoordinate,\n MapsAddress,\n MapsPlace,\n MapsRoute,\n MapsRouteStep,\n BiometricsAPI,\n BiometricsAPIv2,\n NativeCapabilities,\n PluginHooks,\n PluginManifest,\n RenderMode,\n RegisteredPlugin,\n RegisteredUIPlugin,\n RegisteredServicePlugin,\n RegisteredToolsPlugin,\n DeviceToolContext,\n DeviceToolDefinition,\n DeviceToolFn,\n DeviceToolFailureReason,\n} from './types';\n\n// Voice — the live conversational SESSION surface (props.voice).\nexport type {\n VoiceAPI,\n VoiceState,\n VoiceSnapshot,\n VoiceDeviceToolCall,\n VoiceDeviceToolReason,\n VoiceTranscriptEntry,\n VoiceStartOptions,\n VoicePersona,\n VoiceEvent,\n VoiceSubscription,\n VoiceCaller,\n VoiceSessionProvider,\n} from './voice';\n// The privileged platform caller (a value) — the host injects the owner-aware\n// provider and its own surfaces call it as this caller. See VoiceSessionProvider.\nexport { PLATFORM_VOICE_CALLER } from './voice';\n\n// Device state — the SEMANTIC layer: the types of what `props.deviceState`\n// returns, and the two pure helpers for reading a snapshot. They are here, in\n// the one module a bundle can require, because a bundle has no other SDK name\n// ('@adas/device-state' never resolved, and is refused by name). What keeps the\n// two layers apart is the CONTAINER a call starts with — `deviceState.` vs\n// `device.` — not the import line.\nexport type {\n DeviceState,\n DeviceBridgeDomain,\n StateQuality,\n Freshness,\n Confidence,\n VisualSnapshot,\n SpatialSnapshot,\n SpatialPoint,\n SpatialIntent,\n SpatialEvent,\n SpatialStateEvent,\n StateEvent,\n StateListener,\n Subscription,\n ActivitySnapshot,\n EnvironmentSnapshot,\n InteractionSnapshot,\n CapabilitySnapshot,\n CapabilityStatus,\n DeviceContextSnapshot,\n ConnectivitySnapshot,\n} from './device-state';\nexport { isActionable, explainCapability } from './device-state';\n\n// RN primitives (plugins import from the SDK, not from react-native)\nexport {\n View,\n Text,\n ScrollView,\n FlatList,\n SectionList,\n Pressable,\n TouchableOpacity,\n TextInput,\n Image,\n ActivityIndicator,\n Modal,\n Switch,\n StyleSheet,\n Animated,\n Platform,\n RefreshControl,\n} from './primitives';\n\n// Pre-built components\nexport {\n Card,\n Badge,\n TabBar,\n ListItem,\n SearchBar,\n EmptyState,\n ErrorState,\n LoadingState,\n ActionButton,\n} from './components';\n\n// Theme + API hooks\n// Showing the camera is a COMPONENT, not a native module handed to bundles —\n// one door, one lock. See CameraPreview.tsx for why.\nexport { CameraPreview } from './CameraPreview';\nexport type { CameraPreviewProps } from './CameraPreview';\nexport { usePluginTheme, setPluginThemeColors } from './usePluginTheme';\nexport { useApi } from './useApi';\n","/**\n * Plugin registration API.\n * Solution developers use these to register their plugins.\n */\nimport type {\n DeviceToolDefinition,\n NativeCapabilities,\n PluginHooks,\n PluginProps,\n RegisteredUIPlugin,\n RegisteredServicePlugin,\n RegisteredToolsPlugin,\n} from './types';\nimport type { DeviceBridgeDomain } from './device-state';\n\n/**\n * Register a UI or hybrid plugin (has a visual component).\n *\n * `tools` is optional: a plugin may ship UI and local tools together. Tools are\n * picked up when the bundle loads, independently of whether the UI is mounted.\n */\nexport function register(\n id: string,\n config: {\n type?: 'ui' | 'hybrid';\n capabilities?: NativeCapabilities;\n /** L3 DeviceState domains this plugin's UI reads via props.deviceState (e.g.\n * ['spatial','visual']). Carried through so a HOST-registered plugin (no\n * server manifest) can declare its domains — resolvePluginRuntimeProps reads\n * this as the trusted source when there is no manifest. Dropping it here left\n * every registered UI plugin with no L3, silently. Mirrors registerTools. */\n stateDomains?: DeviceBridgeDomain[];\n Component: React.FC<PluginProps>;\n tools?: DeviceToolDefinition[];\n },\n): RegisteredUIPlugin {\n return {\n id,\n type: config.type || 'ui',\n capabilities: config.capabilities,\n stateDomains: config.stateDomains,\n Component: config.Component,\n tools: config.tools,\n };\n}\n\n/**\n * Register a tools-only plugin — a `tools/` section with no UI at all.\n *\n * Nothing here mounts. The tools become callable as soon as the bundle is\n * evaluated, and stay callable with nothing of the plugin on screen.\n */\nexport function registerTools(\n id: string,\n config: {\n capabilities?: NativeCapabilities;\n /** L3 DeviceState domains the tools read via ctx.deviceState (e.g. ['visual']).\n * For a remote bundle the MANIFEST grants them — see RegisteredToolsPlugin. */\n stateDomains?: DeviceBridgeDomain[];\n tools: DeviceToolDefinition[];\n },\n): RegisteredToolsPlugin {\n return {\n id,\n type: 'tools',\n capabilities: config.capabilities,\n stateDomains: config.stateDomains,\n tools: config.tools,\n };\n}\n\n/**\n * Register a headless service plugin (no UI).\n */\nexport function registerService(\n id: string,\n config: {\n capabilities?: NativeCapabilities;\n hooks?: PluginHooks;\n onStart: (props: Omit<PluginProps, 'theme'>) => Promise<void> | void;\n onStop?: () => Promise<void> | void;\n },\n): RegisteredServicePlugin {\n return {\n id,\n type: 'service',\n capabilities: config.capabilities,\n hooks: config.hooks,\n onStart: config.onStart,\n onStop: config.onStop,\n };\n}\n","/**\n * props.voice — the live conversational SESSION a plugin may drive.\n *\n * Voice is a SESSION, not a device sensor. `props.device.*` is mechanical verbs\n * that throw; `props.deviceState.*` is eight semantic domains describing the\n * device. A Realtime conversation is neither — it is a long-lived loop with its\n * own state (connecting/connected), its own transcript, and two ways to take a\n * turn (the user speaks, or the agent speaks first). So it gets its own gated\n * surface, mirroring the deviceState GRAMMAR (start / stop / getSnapshot /\n * subscribe) because a reasoning loop reads it the same way — state with\n * freshness, not bare values.\n *\n * TRUST BOUNDARY. This type is the WHOLE surface. There is deliberately NO way\n * from here to inject fake user speech, read raw audio, reach the WebView, or\n * hide the mic-active indicator — those are new doors, and the reason\n * `CameraPreview` is a component rather than a module is that we keep closing\n * doors of that shape. `prompt()` is an AGENT turn, not a forged user turn.\n *\n * See docs/handoff/SPEC_voice_session_without_the_voice_screen_2026-09-12.md.\n */\nimport type { DeviceToolFailureReason } from './types';\n\n/** The session lifecycle — identical vocabulary to the built-in `CallState`. */\nexport type VoiceState = 'idle' | 'connecting' | 'connected' | 'error';\n\n/** One line of the conversation. `tool` entries are device/skill tool activity. */\nexport interface VoiceTranscriptEntry {\n role: 'user' | 'ai' | 'tool';\n text: string;\n ts: number;\n}\n\n/**\n * Why a device-tool call the session received did not produce a result.\n * - the tool RAN and did not return: `not_found` | `no_context` | `timeout` |\n * `failed` (it threw) — see DeviceToolFailureReason;\n * - the phone REFUSED it before running: `not_ready` (Core's tool allowset for\n * this session had not arrived yet — transient, a retry can succeed) or\n * `not_authorized` (not allowed in this session — final);\n * - `invalid`: the call itself was malformed (it named no tool, or carried no\n * correlationId to answer on) — not run.\n */\nexport type VoiceDeviceToolReason = DeviceToolFailureReason | 'not_ready' | 'not_authorized' | 'invalid';\n\n/**\n * One finished device-tool call, as `VoiceSnapshot.lastDeviceTool` reports it.\n * `name` and `at` keep their original meaning, so a reader of just those two is\n * unaffected.\n */\nexport type VoiceDeviceToolCall = {\n /** The tool the model called ('' if the call named none — see `invalid`). */\n name: string;\n /** Epoch ms the call REACHED the phone (not when it finished — that is at + ms). */\n at: number;\n /** Milliseconds from arrival to outcome (≈0 for a refusal). */\n ms: number;\n} & (\n | { ok: true; reason: null; error: null }\n | {\n ok: false;\n reason: VoiceDeviceToolReason;\n /** What went wrong, clipped to 200 characters: tool errors can echo the\n * call's arguments, which may carry what the user said. */\n error: string;\n }\n);\n\n/** A point-in-time read of the session — what a reasoning loop polls. */\nexport interface VoiceSnapshot {\n state: VoiceState;\n sessionId: string | null;\n muted: boolean;\n /** The agent is currently producing audio. */\n speaking: boolean;\n /** The user is currently being heard (partial user transcript in flight). */\n listening: boolean;\n /** The user is currently speaking, per the session's own VAD (authoritative,\n * distinct from `listening` which tracks a partial transcript). */\n userSpeaking: boolean;\n /**\n * Epoch ms of the last moment the user STOPPED speaking, or `null` if they\n * have not spoken yet this session. `null` is deliberate and load-bearing: a\n * silence timer must arm on the first real `speaking:false`, never at session\n * start — \"not speaking\" and \"has never spoken\" are different, and arming on\n * the wrong one fires before anyone has said anything.\n */\n lastUserSpeechEndedAt: number | null;\n /** The last error, if `state === 'error'`; also carries a refusal reason when\n * this surface was handed to a plugin that did not declare `voice`. */\n lastError: string | null;\n /**\n * The most recently FINISHED device-tool call the model made through this\n * session, with its outcome — or null if none has finished yet. Set once the\n * outcome is known (ran, refused, malformed, threw, timed out), never on\n * arrival, so a refused call can no longer look like one that ran.\n *\n * SCOPED to the caller: a plugin sees only calls to tools IT registered (never\n * another solution's tool names or errors, even on its own call); the platform\n * sees every call. Cleared when the session ends or a new one starts.\n * Diagnostic — every solution's debug view gets \"why did that call fail\" free.\n */\n lastDeviceTool: VoiceDeviceToolCall | null;\n /** The sessionId the Core allowset is bound to. Diagnostic: authorization\n * requires it to equal `sessionId`; a mismatch is why tools refuse. */\n authorizedSessionId: string | null;\n}\n\nexport interface VoiceStartOptions {\n /** Hand the mic to a specific skill on connect (voice /session → takeMic),\n * exactly as `sys.focusUiPlugin(\"platform:voice\", { skillSlug })` does. */\n skillSlug?: string;\n /**\n * A PER-CALL persona override, same shape as the authored\n * `solution.voice.persona` ({ name, style }). Declared on the voice\n * session-create call (POST /session `persona`); the server sanitizes it\n * (name/style only, length-capped) and layers it OVER the solution's authored\n * persona for THIS call only — prompt-layer, so it can never touch caller\n * verification or tool allow-lists. Set once at session start and constant\n * for the call, so it adds no per-turn prompt pushes.\n *\n * Use it when a plugin needs its own voice persona without owning a skill\n * (e.g. a guide HUD). A solution-wide persona belongs in solution.voice.\n */\n persona?: VoicePersona;\n /**\n * `'none'` = a CLEAN call: the voice gets none of the workspace's skills — no\n * skill manifest, no skill tools, no platform welcome line, no mid-call\n * skill-state prompt refresh — only the voice basics, this call's persona and\n * the CALLING plugin's own device tools (other solutions' tools registered on\n * the same phone are neither offered nor run). For a plugin that owns its conversation (e.g.\n * a guide HUD). Reduce-only: it can remove what the voice gets, never add.\n * Absent = the workspace's skills, as today. Not combinable with `skillSlug`.\n */\n skills?: 'none';\n}\n\n/** The authored persona shape (solution.voice.persona). */\nexport interface VoicePersona {\n /** The name the voice uses for itself (\"You are <name> …\"). */\n name?: string;\n /** Free-text style/behaviour guidance rendered under the identity line. */\n style?: string;\n}\n\n/**\n * What changed. Coarse on purpose: `state` covers connect/mute/session/partials,\n * `transcript` fires when a finalized line was appended. A subscriber re-reads\n * `getSnapshot()` / `transcript()` — the event is a nudge, not a payload, so the\n * surface never has to keep two shapes of the same fact in sync.\n */\nexport type VoiceEvent = { type: 'state' } | { type: 'transcript' };\n\nexport interface VoiceSubscription {\n unsubscribe(): void;\n}\n\n/**\n * WHO is asking. The one physical session has an OWNER; access is scoped to it.\n *\n * A plugin's caller is its `pluginId` (a string), stamped by gateVoice so the\n * plugin never supplies its own identity. The PLATFORM caller — the built-in\n * voice screen, the user's own surface — is a Symbol, deliberately: a Symbol can\n * never equal any pluginId string, so a plugin cannot forge platform access by\n * naming itself `platform:voice`.\n */\nexport type VoiceCaller = string | symbol;\n\n/** The privileged caller — the platform's own surfaces (the built-in sheet, the\n * mic indicator, the session host). Sees and controls any live session, because\n * it is the USER's direct surface onto their own conversation. Unforgeable. */\nexport const PLATFORM_VOICE_CALLER: unique symbol = Symbol('adas.voice.platform');\n\n/**\n * The OWNER-AWARE session the HOST implements and hands to setVoiceProvider.\n *\n * This is NOT what a plugin receives — a plugin gets a `VoiceAPI` facade\n * (gateVoice) that stamps its `pluginId` as the caller on every call, so the\n * provider can enforce that a plugin only ever reads, controls, or attaches to a\n * session IT owns. One physical session, isolated per authorized identity.\n */\nexport interface VoiceSessionProvider {\n start(opts: VoiceStartOptions | undefined, caller: VoiceCaller): Promise<VoiceSnapshot>;\n stop(caller: VoiceCaller): void;\n setMuted(muted: boolean, caller: VoiceCaller): void;\n prompt(input: string, caller: VoiceCaller): void;\n observe(text: string, caller: VoiceCaller): void;\n getSnapshot(caller: VoiceCaller): VoiceSnapshot;\n subscribe(cb: (event: VoiceEvent) => void, caller: VoiceCaller): VoiceSubscription;\n transcript(caller: VoiceCaller): VoiceTranscriptEntry[];\n}\n\n/**\n * The gated surface a plugin receives as `props.voice`. Present on EVERY plugin;\n * a plugin that did not declare `capabilities: { voice: true }` gets a version\n * whose reads say so and whose actions throw — never a silent no-op, never a\n * fake `idle` (see gateVoice in voiceHost.ts).\n */\nexport interface VoiceAPI {\n /** Open the live loop. Resolves once connected (or rejects on connect error).\n * If a session is ALREADY live, ATTACHES to it and resolves immediately —\n * never a second Realtime loop (one phone, one mic, one bill). */\n start(opts?: VoiceStartOptions): Promise<VoiceSnapshot>;\n /** End the live loop. Safe to call when idle. */\n stop(): void;\n /** Mute/unmute the microphone. The session stays live; the mic indicator\n * reflects it. */\n setMuted(muted: boolean): void;\n /**\n * Make the agent take a turn WITHOUT the user speaking — the guide speaking\n * first. `input` is the instruction for that turn. This is an agent-initiated\n * turn into the SAME session, NOT fabricated user speech: one session, two\n * trigger sources. Throws if the session is not connected.\n */\n prompt(input: string): void;\n /**\n * Stream a silent OBSERVATION into the session — tell the model something\n * without asking it to speak (a `system` conversation item). Cheap and\n * high-frequency (safe once or twice a second): this is the channel for what\n * the camera sees while the user walks. The model answers with the\n * observations in hand the next time it takes a turn (user VAD, or prompt()) —\n * an observation never triggers a turn by itself. Throws if not connected.\n */\n observe(text: string): void;\n /** Point-in-time session state. */\n getSnapshot(): VoiceSnapshot;\n /** Subscribe to state + transcript changes. Returns an unsubscribe handle. */\n subscribe(cb: (event: VoiceEvent) => void): VoiceSubscription;\n /** The conversation so far. */\n transcript(): VoiceTranscriptEntry[];\n}\n","/**\n * Device state — Device Bridge v2, the SEMANTIC layer.\n *\n * Repo path:\n * packages/plugin-runtime/src/sdk/device-state.ts\n * Module specifier for plugin bundles:\n * '@adas/plugin-sdk' — the only SDK module a bundle can require. This file\n * once named '@adas/device-state' here (4110943); the require shim never\n * resolved it, so a bundle that imported it got `{}` and failed later. It is\n * now refused by name at evaluation (bundles/bundleModuleNames.ts).\n *\n * ─────────────────────────────────────────────────────────────────────────\n * WHICH LAYER AM I IN?\n *\n * props.device.* MECHANICAL. \"Do this to the hardware, now.\"\n * VERB names: takePhoto, getCurrent, scanBarcode,\n * readOnce, authenticate, pickImage.\n * Returns a BARE value. THROWS when it cannot.\n * Declared in the manifest as `capabilities: { camera: true }`\n * (the legacy `native: {}` field is still honoured).\n * Its types are imported from '@adas/plugin-sdk'.\n *\n * props.deviceState.* SEMANTIC. \"What is true right now, and how well do\n * we know it?\"\n * STATE names: getSnapshot, subscribe, start, stop.\n * Returns a SNAPSHOT carrying freshness + confidence,\n * and able to say `unknown` in every field.\n * A read NEVER throws for absence.\n * Declared in the manifest as `stateDomains: ['visual']`.\n * Defined in this file; its types and helpers are\n * imported from '@adas/plugin-sdk' too.\n *\n * The two containers are the discriminator. Every semantic call in a plugin\n * begins with the eight characters `deviceState.`; every mechanical call\n * begins with `native.`. There is no line of code where the layer is\n * ambiguous, and no object on which both appear.\n *\n * This is a deliberate departure from\n * Docs/device-bridge-v2/DEVICE_BRIDGE_V2_IMPLEMENTATION_GROUNDING_2026-08-07.md\n * §\"Migration strategy\", which proposed adding `visual`, `spatial`,\n * `connectivityState`… as fields ON `PluginNative`. See the design note at the\n * bottom of this file for why that layout is rejected and what it costs.\n * ─────────────────────────────────────────────────────────────────────────\n *\n * PROVENANCE MARKERS used throughout. They are not decoration — the freeze\n * really does fix some of this and really does leave the rest open, and an\n * implementor needs to know which is which before changing a line:\n *\n * FROZEN — API_FREEZE 2026-08-07 §15 lists it as a frozen candidate.\n * V0.1 — \"v0.1 freeze candidate; may change only when implementation\n * grounding proves a field impossible/non-portable.\"\n * OPEN — the docs explicitly leave it undecided. Do not quietly close it.\n * DECISION — not in the docs at all; decided here, and reversible.\n */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\n\n// ═════════════════════════════════════════════════════════════════════════\n// 1. Common metadata model\n// FROZEN (API_FREEZE §1, §15 \"Common metadata model: frozen candidate\").\n// Shared verbatim by all eight domains. Do not fork a per-domain variant.\n// ═════════════════════════════════════════════════════════════════════════\n\n/** FROZEN (API_FREEZE §1). The eight domain keys. */\nexport type DeviceBridgeDomain =\n | 'spatial'\n | 'visual'\n | 'activity'\n | 'deviceContext'\n | 'connectivity'\n | 'capability'\n | 'environment'\n | 'interaction';\n\nexport type FreshnessState = 'fresh' | 'aging' | 'stale' | 'unknown';\n\n/**\n * FROZEN. Both fields are nullable on purpose: \"we have no observation at all\"\n * has to be expressible without inventing a timestamp.\n *\n * `aging` is a real third state, not a rounding of fresh/stale — a consumer\n * that only branches on fresh-vs-stale is misreading the contract.\n *\n * API_FREEZE §1 \"Why observedAt + ageMs\": the host may compute `ageMs` at read\n * time, so it can be more accurate than `Date.now() - observedAt` measured on\n * the JS side after a bridge hop. Read `ageMs` when you have it.\n */\nexport interface Freshness {\n state: FreshnessState;\n /** Epoch ms of the observation itself. `null` = never observed. */\n observedAt: number | null;\n /** Age at read time. `null` = never observed. */\n ageMs: number | null;\n}\n\nexport type ConfidenceLevel = 'high' | 'medium' | 'low' | 'unknown';\n\n/**\n * FROZEN. `level` is mandatory and ordinal; `score` is optional and exists\n * only \"when a stable numeric estimate exists\" (API_FREEZE §1).\n *\n * The asymmetry is the point: native must not manufacture 0.5 to fill a field.\n * A missing `score` is information — it says the estimator has no calibrated\n * number, only a bucket.\n */\nexport interface Confidence {\n level: ConfidenceLevel;\n /** 0..1. Omitted when no stable numeric estimate exists. */\n score?: number;\n}\n\n/**\n * FROZEN. Every snapshot in v2 carries exactly one of these.\n *\n * `freshness` required, `confidence` optional — because some domains report\n * exact OS facts (battery level, audio route) where a confidence is\n * meaningless, and others report inference (activity, indoor/outdoor) where it\n * is mandatory. Cross-domain review: \"Freshness is mandatory for dynamic\n * state. Confidence is mandatory for inferred/estimated state; optional for\n * exact OS facts.\"\n *\n * NOTE (OPEN): freshness is per-SNAPSHOT, never per-field. So a snapshot\n * cannot today say \"lighting is fresh but acoustics is stale\". The\n * architecture doc raised this for Spatial and Environment and never resolved\n * it. Do not work around it by inventing a second freshness field.\n */\nexport interface StateQuality {\n freshness: Freshness;\n confidence?: Confidence;\n}\n\n// ── Support / permission / availability / restriction ──────────────────────\n// FROZEN (API_FREEZE §1). Four INDEPENDENT axes. The capability doc is blunt:\n// \"Do not collapse all failure modes into a single boolean.\" A camera can be\n// supported + granted + busy, and each of those three answers leads the caller\n// somewhere different.\n\nexport type SupportState = 'supported' | 'unsupported' | 'unknown';\n\nexport type PermissionState =\n | 'granted'\n | 'denied'\n | 'restricted'\n | 'notDetermined'\n | 'limited'\n | 'unavailable'\n | 'unknown';\n\nexport type AvailabilityState =\n | 'available'\n | 'busy'\n | 'temporarilyUnavailable'\n | 'unavailable'\n | 'unknown';\n\nexport type RestrictionState =\n | 'none'\n | 'backgroundRestricted'\n | 'systemRestricted'\n | 'policyRestricted'\n | 'lowPowerRestricted'\n | 'unknown';\n\n// ── Events ────────────────────────────────────────────────────────────────\n\n/**\n * FROZEN (API_FREEZE core rule 4): \"Events are meaningful semantic changes,\n * never raw sensor streams.\" If you find yourself wanting an event per frame\n * or per GPS fix, you are in the wrong layer.\n */\nexport interface StateEvent<TName extends string = string, TPayload = unknown> {\n domain: DeviceBridgeDomain;\n name: TName;\n /** Epoch ms. */\n timestamp: number;\n /**\n * OPEN: per-event payload schemas are not specified anywhere in the three\n * design docs. Defaults to `unknown` rather than `any` so a consumer is forced\n * to narrow it rather than read a field that may not exist. A domain that\n * decides its schemas (spatial — see `SpatialStateEvent`) passes `TPayload`,\n * which is the freeze's own second parameter, dropped here until one did.\n */\n payload?: TPayload;\n}\n\nexport interface Subscription {\n unsubscribe(): void;\n}\n\nexport type StateListener<TName extends string = string> = (\n event: StateEvent<TName>,\n) => void;\n\n/**\n * VOCABULARY §\"Event Naming Rule\", expressed as a type.\n *\n * Four domains (visual, activity, spatial, deviceContext) have NO frozen event\n * vocabulary — the vocabulary doc publishes \"Initial … Events\" lists for\n * connectivity, capability, interaction and environment only. Rather than mint\n * names those docs deliberately did not mint, their events are typed against\n * the naming RULE. A wrong-shaped name is a compile error; the specific\n * vocabulary stays open, as the docs left it — except where a DECISION closes\n * it (spatial, see `SpatialEvent`), and that list is checked against the rule\n * through `AssertConforming`.\n */\nexport type ConformingEventName =\n | `${string}Changed`\n | `${string}Started`\n | `${string}Stopped`\n | `${string}Available`\n | `${string}Unavailable`\n | `${string}StateStale`;\n\n/**\n * A closed list of names, checked against the naming rule at compile time.\n * Wrap a decided vocabulary in this and a name like `turnCompleted` stops\n * compiling instead of reaching a plugin.\n */\nexport type AssertConforming<T extends ConformingEventName> = T;\n\n// ── Errors ────────────────────────────────────────────────────────────────\n\n/** FROZEN (API_FREEZE §12). */\nexport type DeviceBridgeErrorCode =\n | 'UNSUPPORTED'\n | 'PERMISSION_DENIED'\n | 'RESTRICTED'\n | 'BUSY'\n | 'TEMPORARILY_UNAVAILABLE'\n | 'STALE'\n | 'TIMEOUT'\n | 'CANCELLED'\n | 'INTERNAL';\n\n/**\n * FROZEN shape (API_FREEZE §12).\n *\n * READ THE SCOPE LINE CAREFULLY. This is for FAILED OPERATIONS —\n * `visual.capture()`, `visual.start()`. It is NOT how the surface reports that\n * a camera is denied or a sensor is missing: \"Expected state should still be\n * exposed in snapshots.\"\n *\n * So: `getSnapshot()` does not throw this. `capture()` and `start()` do.\n * That split is the whole no-fabrication contract in one sentence — a read\n * always returns something honest, an action either happens or explains\n * itself in a typed code.\n */\nexport class DeviceBridgeError extends Error {\n readonly code: DeviceBridgeErrorCode;\n readonly domain?: DeviceBridgeDomain;\n /** Whether retrying could plausibly succeed (BUSY yes, UNSUPPORTED no). */\n readonly recoverable?: boolean;\n\n constructor(\n code: DeviceBridgeErrorCode,\n message: string,\n opts?: { domain?: DeviceBridgeDomain; recoverable?: boolean },\n ) {\n super(message);\n this.name = 'DeviceBridgeError';\n this.code = code;\n this.domain = opts?.domain;\n this.recoverable = opts?.recoverable;\n }\n}\n\n// ── Sessions and the lifecycle pattern ────────────────────────────────────\n\nexport interface StateSession {\n id: string;\n /** The intent this session was started with. */\n intent: string;\n startedAt: number;\n}\n\nexport interface StartOptions<TIntent extends string> {\n /**\n * MANDATORY, and that is the single most important line in this file.\n *\n * You cannot open a v2 session without naming what it is FOR. Native then\n * owns sampling rate, resolution, buffering, fusion and power — API_FREEZE\n * core rule 6. `start()` means \"maintain state according to this intent\",\n * not \"open a particular native API\" (§2).\n *\n * Contrast the mechanical layer, where `camera.takePhoto()` is a legal,\n * complete, intent-free call. That difference is visible at every call site.\n */\n intent: TIntent;\n /**\n * DECISION (not frozen). §13 requires bounded timeout/cancellation for\n * session starts and says chain STOP must propagate to native, but leaves\n * the plumbing \"implementation-specific\". `AbortSignal` is what\n * `DeviceToolContext.signal` already carries in this SDK, so reuse it rather\n * than invent a second cancellation idiom.\n */\n signal?: AbortSignal;\n}\n\n/**\n * FROZEN pattern (API_FREEZE §2), reproduced as documentation. The eight\n * concrete domains below do NOT extend this — each spells out exactly the\n * methods it has, because §11 warns \"domains should not be forced to implement\n * meaningless lifecycle methods\" and three domains genuinely have no intent\n * vocabulary at all.\n *\n * Two invariants apply to every domain:\n * - `getSnapshot()` reads CACHED state. It must not trigger expensive raw\n * sensing (no camera open, no network probe, no GPS cold start).\n * - \"Multiple plugins may eventually share one native engine; session\n * ownership must not imply duplicate sensor pipelines.\" (OPEN: the\n * arbitration mechanism is undefined. See DESIGN NOTE 3.)\n */\nexport interface StatefulDomain<\n TSnapshot,\n TIntent extends string = never,\n TEvent extends string = string,\n> {\n getSnapshot(): Promise<TSnapshot>;\n start?(options: StartOptions<TIntent>): Promise<StateSession>;\n stop?(sessionId?: string): Promise<void>;\n subscribe?(listener: StateListener<TEvent>): Subscription;\n}\n\n/**\n * Why every read is `Promise<T>` even though it is a cached read.\n *\n * Not because it samples — it must not. Because it crosses the RN bridge, and\n * this SDK has no synchronous JSI module today (verified: everything in\n * PluginNative except haptics/connectivity.isOnline is Promise-based). The\n * grounding doc's own target for a warm cached snapshot is p50 < 10 ms /\n * p95 < 30 ms, which is an async-bridge budget, not a sampling budget.\n */\n\n// ═════════════════════════════════════════════════════════════════════════\n// 2. Domain 1 — Spatial State\n// ═════════════════════════════════════════════════════════════════════════\n\n/**\n * FROZEN (API_FREEZE §3). Copied verbatim, not designed here.\n *\n * This landed as a placeholder first, on the belief that §3's field schema had\n * never been written. It had — the placeholder was a gap in what got read, not\n * a gap in the freeze. Worth recording, because \"the docs leave this open\" and\n * \"I did not find it\" produce identical-looking comments and only one of them\n * is a reason to invent a shape.\n */\nexport type SpatialIntent =\n | 'navigation'\n | 'fitness'\n | 'geofence'\n | 'lowPowerTracking'\n | 'preciseLocate';\n\n/** FROZEN (API_FREEZE §3). */\nexport interface SpatialPoint {\n latitude: number;\n longitude: number;\n altitude?: number | null;\n /** Metres. `null` when the platform gives no estimate — never 0, which\n * would read as a perfect fix. */\n accuracyM?: number | null;\n timestamp: number;\n}\n\n/** FROZEN (API_FREEZE §3). */\nexport interface SpatialSnapshot {\n /** `null` when there is no usable fix. Not a zero coordinate — (0,0) is a\n * real place in the Gulf of Guinea. */\n position: SpatialPoint | null;\n movement: {\n speedMps: number | null;\n bearingDeg: number | null;\n distanceRecentM: number | null;\n state?: 'stationary' | 'moving' | 'unknown';\n };\n orientation: {\n headingDeg: number | null;\n headingAccuracyDeg?: number | null;\n pitchDeg?: number | null;\n rollDeg?: number | null;\n };\n /** Newest last. Empty when nothing has been recorded — the ring is a native\n * concern, and its window is chosen by intent. */\n recentPath: SpatialPoint[];\n changes?: {\n lastMeaningfulTurnDeg?: number | null;\n timestamp?: number | null;\n };\n quality: StateQuality;\n}\n\n/**\n * DECISION (not frozen) — the spatial event vocabulary. Six names, all ending\n * in a suffix the naming rule allows, which `AssertConforming` enforces.\n *\n * Drawn from the architecture doc's spatial candidates (meaningful movement,\n * meaningful turn, location quality degraded/recovered, state became stale)\n * and named after the SNAPSHOT fields they report, so an event and a read use\n * one vocabulary: `lastMeaningfulTurnChanged` is `changes.lastMeaningfulTurnDeg`\n * changing. The names an earlier note floated (`turnCompleted`, `arrived`,\n * `headingLost`) are rejected — the first two fail the rule, and \"arrived\" is a\n * destination, which the vocabulary's Governance puts above Device Bridge.\n */\nexport type SpatialEvent = AssertConforming<\n | 'movementStarted'\n | 'movementStopped'\n | 'lastMeaningfulTurnChanged'\n | 'positionConfidenceChanged'\n | 'positionChanged'\n | 'spatialStateStale'\n>;\n\n/** A spatial event: the frozen envelope, with its payload always present. */\ntype SpatialEventOf<TName extends SpatialEvent, TPayload> =\n StateEvent<TName, TPayload> & { domain: 'spatial'; payload: TPayload };\n\n/**\n * DECISION — what each spatial event carries. Only the facts of the\n * transition, in the snapshot's own field names; everything else is one\n * `getSnapshot()` away, which keeps two shapes of the same fact from drifting.\n *\n * `timestamp` on the envelope is when the transition was RECOGNISED. Where a\n * hold delays that on purpose, `since` carries the true onset.\n */\nexport type SpatialStateEvent =\n /** `movement.state` became `moving` and held (navigation: 3 s). */\n | SpatialEventOf<'movementStarted', {\n previous: 'stationary' | 'unknown';\n speedMps: number | null;\n bearingDeg: number | null;\n since: number;\n }>\n /** `moving` → `stationary`, held (navigation: 5 s). Never fired on moving →\n * `unknown`: losing the speed is not evidence of stopping. */\n | SpatialEventOf<'movementStopped', { previous: 'moving'; since: number }>\n /** A new completed turn. Signed: positive = clockwise = right. */\n | SpatialEventOf<'lastMeaningfulTurnChanged', { lastMeaningfulTurnDeg: number; timestamp: number }>\n /** The GPS fix band (high ≤10 m, medium ≤50 m, else low) changed and held.\n * The fix alone — a compass calibration change is not a position event. */\n | SpatialEventOf<'positionConfidenceChanged', {\n level: ConfidenceLevel;\n previous: ConfidenceLevel;\n accuracyM: number | null;\n direction: 'dropped' | 'recovered';\n }>\n /** Moved at least max(profile floor, 2 × accuracyM) from the last reported\n * position, so GPS jitter never fires it. The session's first fix fires\n * with `previous: null`. */\n | SpatialEventOf<'positionChanged', {\n position: SpatialPoint;\n previous: SpatialPoint | null;\n distanceM: number | null;\n }>\n /** `quality.freshness.state` became `stale`. Once; re-armed by a fresh read. */\n | SpatialEventOf<'spatialStateStale', { observedAt: number | null; ageMs: number | null }>;\n\nexport interface SpatialDomain {\n getSnapshot(): Promise<SpatialSnapshot>;\n start(options: StartOptions<SpatialIntent>): Promise<StateSession>;\n stop(sessionId?: string): Promise<void>;\n /**\n * DECISION: the six `SpatialEvent`s, typed per name — narrow on `e.name` and\n * `e.payload` is that event's shape.\n *\n * Events flow only while a spatial session is open; subscribing opens no\n * sensor. They are derived from the same snapshot `getSnapshot()` returns: a\n * listener that re-reads inside the callback sees the snapshot its event came\n * from. A state change must hold, on at least two fixes, before it fires.\n *\n * From a device tool's `ctx.deviceState` this refuses (RESTRICTED): a call\n * has no lifetime to own the listener.\n */\n subscribe(listener: (event: SpatialStateEvent) => void): Subscription;\n}\n\n// ═════════════════════════════════════════════════════════════════════════\n// 3. Domain 2 — Visual State\n//\n// Visual is NOT \"the camera API\". It is a native-maintained visual timeline\n// plus camera/capture state. Everything interpretive — what is in the scene,\n// what the sign says, which corridor to take — sits ABOVE Device Bridge and is\n// not modelled here.\n// ═════════════════════════════════════════════════════════════════════════\n\n/** FROZEN (API_FREEZE §4) + VOCABULARY §\"Visual Intents\". Nine values. */\nexport type VisualIntent =\n | 'navigation'\n | 'document'\n | 'ocr'\n | 'shopping'\n | 'inspection'\n | 'accessibility'\n | 'stream'\n | 'highQuality'\n | 'lowPower';\n\n/**\n * Media crosses by REFERENCE, never as inline bytes (core rule 3).\n *\n * AN ID AND NOTHING ELSE. The `uri` field is gone (2026-08-16), and its\n * removal answers the question this comment used to record as OPEN — \"how does\n * a plugin turn a handle into pixels?\" It doesn't. Ever.\n *\n * Frames now live in a native ring keyed by id and are never written to disk.\n * `native.vision.readText/describe/assessQuality` take this id and resolve it\n * INSIDE the trusted layer; the pixels do not cross into plugin code, so a\n * solution's bundle cannot copy, upload or retain them. That is what makes\n * \"frames never leave the phone\" enforceable rather than a promise.\n *\n * Do not add `uri` or `bytes` back. A plugin that believes it needs the pixels\n * needs a new method on `native.vision` instead — one whose implementation\n * stays on this side of the boundary.\n */\nexport interface MediaHandle {\n id: string;\n mimeType?: string;\n /**\n * Epoch ms after which this id no longer resolves — the frame's real\n * eviction time from the native ring, not a guess.\n *\n * Past it, `native.vision` throws rather than returning an empty result:\n * \"I cannot look at that frame\" and \"I looked and found nothing\" are\n * different answers and must never be confused by a caller about to speak.\n * In practice a caller rarely hits this, because the timeline is clamped to\n * native retention — see `visualEngine.effectiveWindowMs()`.\n */\n expiresAt?: number | null;\n}\n\n/**\n * V0.1. Per-frame usability is CATEGORICAL, not numeric — 'degraded' rather\n * than a blur score. Coarse honest classes beat false precision; the same\n * principle the connectivity doc states outright for connection quality.\n *\n * Every member carries `'unknown'` so a platform that cannot assess blur says\n * so instead of defaulting to 'good'.\n */\nexport interface VisualFrameQuality {\n blur?: 'good' | 'degraded' | 'unknown';\n exposure?: 'good' | 'dark' | 'bright' | 'unknown';\n /** `null` = cannot tell. Distinct from `false` = checked, not obstructed. */\n obstructed?: boolean | null;\n}\n\nexport interface VisualFrameRef {\n handle: MediaHandle;\n timestamp: number;\n orientation?: { headingDeg?: number; pitchDeg?: number; rollDeg?: number };\n quality?: VisualFrameQuality;\n}\n\nexport interface VisualSnapshot {\n camera: {\n available: boolean;\n /**\n * Independent of `available` on purpose. A camera can be present and\n * permitted (`available: true`) while no session is running\n * (`active: false`) — that is a different situation from a camera the app\n * cannot use at all, and Guide has to say different things about them.\n *\n * DRIFT (flagged, not resolved): the architecture doc's conceptual block\n * also carried `camera.orientation`; the frozen §4 block does not. Not\n * added here.\n */\n active: boolean;\n facing?: 'front' | 'back' | 'unknown';\n };\n /**\n * `null` when there is no usable current frame.\n *\n * This is the anti-fabrication field. The alternative implementation —\n * returning the last frame you happen to still hold — is precisely how a\n * guidance loop ends up describing a corridor the user left thirty seconds\n * ago. If it is not current, it is `null`, and the timeline below is where\n * you go looking for history, knowingly.\n */\n latest: VisualFrameRef | null;\n /**\n * TIME-based, not frame-count-based. Default window ~5s; documented bounded\n * range roughly 1–15s, selected by profile/intent. Native decides how\n * densely to retain frames inside the window and evicts everything outside\n * it automatically.\n *\n * `windowMs` is exposed; FPS knobs are NOT, and must never be added\n * (API_FREEZE §4). If a plugin wants \"more frames\", it declares a different\n * intent — it does not turn a dial.\n */\n recentTimeline: { windowMs: number; frames: VisualFrameRef[] };\n quality: StateQuality;\n}\n\nexport interface VisualCaptureResult {\n frame: VisualFrameRef;\n}\n\n/**\n * OPEN, worth knowing before you use it: whether `capture({intent})` may pass\n * an intent DIFFERENT from the running session's intent is not addressed\n * anywhere in the three docs.\n */\nexport interface VisualCaptureOptions {\n intent: VisualIntent;\n /** §13: capture must support bounded timeout/cancellation. */\n signal?: AbortSignal;\n timeoutMs?: number;\n}\n\nexport interface VisualDomain {\n /**\n * Cached read. Does NOT open the camera and does NOT take a picture.\n *\n * This is the call a guidance loop makes on every turn. The hot path is:\n * native camera pipeline → rolling native timeline → cached visual state →\n * one snapshot read from RN. \"Avoid repeatedly starting the camera or\n * capturing a new image for every plugin-tool call during an interactive\n * session.\"\n */\n getSnapshot(): Promise<VisualSnapshot>;\n\n /** Maintain visual state according to this intent. Not \"open the camera\". */\n start(options: StartOptions<VisualIntent>): Promise<StateSession>;\n\n /**\n * An intentional, one-shot, high-quality-ish acquisition. THROWS\n * DeviceBridgeError on failure — it is an operation, not a read.\n *\n * If you are about to call this once per conversational turn, stop: that is\n * `getSnapshot()`'s job, and doing it here is the frame-timer pattern this\n * whole layer exists to replace.\n */\n capture(options: VisualCaptureOptions): Promise<VisualCaptureResult>;\n\n /**\n * OPEN (doc conflict): the architecture doc shows `visual.subscribe(events)`\n * — a filter — while API_FREEZE shows `visual.subscribe(listener)`. The\n * freeze is followed here. Unresolved.\n *\n * OPEN: there is no \"Initial Visual Events\" list anywhere. The candidate set\n * in prose (camera became available/unavailable, frame quality degraded/\n * recovered, camera appears obstructed, significant scene change, visual\n * session suspended/resumed, visual state became stale) is NOT a minted\n * vocabulary. Typed against the naming rule only.\n */\n subscribe(listener: StateListener<ConformingEventName>): Subscription;\n\n stop(sessionId?: string): Promise<void>;\n}\n\n// ═════════════════════════════════════════════════════════════════════════\n// 4. Domain 3 — Human Activity State\n// ═════════════════════════════════════════════════════════════════════════\n\n/** FROZEN (API_FREEZE §5, VOCABULARY §\"Human Activity Values\"). */\nexport type HumanActivity =\n | 'stationary'\n | 'walking'\n | 'running'\n | 'cycling'\n | 'driving'\n | 'unknown';\n\n/**\n * FROZEN. Independent of HumanActivity — walking+pocket, driving+mounted.\n *\n * What is returned TODAY: `handheld`, `table` and `unknown` only. Do not write\n * a branch that waits for `pocket` or `mounted`; it will never run. A pocketed\n * phone shows up in the Visual domain's frame quality (`obstructed: true` /\n * `exposure: 'dark'`), not here.\n */\nexport type DevicePlacement =\n | 'handheld'\n /** RESERVED — never returned until the proximity/light sensor is wired. */\n | 'pocket'\n | 'table'\n /** RESERVED — never returned until Bluetooth/CarPlay mount context is wired. */\n | 'mounted'\n | 'unknown';\n\n/**\n * FROZEN. Note `driving` is BOTH an intent here and a HumanActivity value\n * above. The docs define no relationship between the two and do not flag the\n * collision: declaring intent `driving` does not assert the user is driving.\n */\nexport type ActivityIntent =\n | 'navigation'\n | 'fitness'\n | 'driving'\n | 'safety'\n | 'accessibility'\n | 'lowPower';\n\nexport interface ActivitySnapshot {\n human: {\n state: HumanActivity;\n /** `null` when the start of the current activity is not known. */\n since: number | null;\n /** REQUIRED, unlike StateQuality.confidence — an inferred activity may\n * never be handed over without saying how sure the inference is. */\n confidence: Confidence;\n };\n devicePose: {\n placement: DevicePlacement;\n /** V0.1. These four values appear only in the freeze TS, not in the\n * vocabulary doc — unlike the placement values. Mild drift, flagged. */\n orientation?: 'portrait' | 'landscape' | 'flat' | 'unknown';\n confidence: Confidence;\n };\n /**\n * Advisory only. `likelyNext` is a hint and never a fact.\n * OPEN: transition names are bare `string` — no controlled vocabulary exists\n * anywhere, which sits awkwardly beside \"Intents are not arbitrary strings\".\n */\n transition?: {\n current?: string | null;\n likelyNext?: string | null;\n confidence?: Confidence;\n };\n /** OPEN: no window length or cap is specified for Activity (Spatial gets\n * ~10–20s, Visual ~5s). Required array — an empty one is a real answer. */\n recentTransitions: Array<{ name: string; timestamp: number }>;\n quality: StateQuality;\n}\n\nexport interface ActivityDomain {\n getSnapshot(): Promise<ActivitySnapshot>;\n /**\n * OPEN: §11's naming list shows only `activity.getSnapshot()`, and §2 makes\n * start/stop optional. Whether Activity is session-based or a passive\n * always-on domain is genuinely unstated. Included here because the six\n * frozen ActivityIntent values would otherwise have no seam to arrive\n * through — but this is a DECISION, not a reading of the freeze.\n */\n start(options: StartOptions<ActivityIntent>): Promise<StateSession>;\n stop(sessionId?: string): Promise<void>;\n /** OPEN: no \"Initial Activity Events\" list exists. */\n subscribe(listener: StateListener<ConformingEventName>): Subscription;\n}\n\n// ═════════════════════════════════════════════════════════════════════════\n// 5. Domain 4 — Device Context\n//\n// SCOPE WARNING. The early architecture draft put lifecycle, audio route and\n// hardware availability here. The freeze REMOVED all three: app foreground/\n// background and active channels are canonicalized under Interaction; hardware\n// support/permission moved to Capability. Frozen Device Context is power +\n// thermal + resources, and nothing else.\n// ═════════════════════════════════════════════════════════════════════════\n\nexport interface DeviceContextSnapshot {\n power: {\n /** 0..1 FRACTION, not a percentage. `null` = not known. */\n batteryLevel: number | null;\n charging: boolean | null;\n lowPowerMode: boolean | null;\n };\n thermal: {\n state: 'nominal' | 'fair' | 'serious' | 'critical' | 'unknown';\n };\n resources: {\n memoryPressure?: 'normal' | 'warning' | 'critical' | 'unknown';\n storagePressure?: 'normal' | 'warning' | 'critical' | 'unknown';\n };\n /** Confidence is legitimately omitted here — these are exact OS facts, not\n * estimates. Freshness still matters: a populated batteryLevel says nothing\n * about whether it was sampled a second or a minute ago. */\n quality: StateQuality;\n}\n\n/**\n * NO INTENT TYPE, and that is deliberate — not an oversight, and not a gap to\n * fill in later. There is no `DeviceContextIntent` in the freeze and no\n * \"Device Context Intents\" section in the vocabulary, because\n * (cross-domain review) \"A domain may expose an intent only if it changes\n * native implementation strategy in a meaningful way.\" Reading battery and\n * thermal does not.\n *\n * The direction of flow is the other way round: Device Context is an INPUT to\n * how OTHER domains satisfy their intents. Visual intent `navigation` +\n * device context `battery 5% + low-power mode` → native picks a lower-power\n * camera strategy while still honouring the Visual contract. The plugin does\n * not retune anything, and must not be asked to.\n *\n * Do not add `deviceContext.start({intent:'lowPower'})` because five other\n * domains have a lowPower intent.\n */\nexport interface DeviceContextDomain {\n getSnapshot(): Promise<DeviceContextSnapshot>;\n /**\n * OPEN: `DeviceContextDomain`'s interface body is never written in the\n * freeze, and no Device Context event names are frozen (the vocabulary has\n * \"Initial … Events\" for connectivity/capability/interaction/environment\n * only). DECISION: expose subscribe, because the candidate events —\n * low-power mode changed, charging changed, thermal pressure changed — are\n * exactly what an adaptive session needs and polling for them is wasteful.\n *\n * OPEN: \"battery crossed significant threshold\" and \"changed materially\"\n * have no numbers anywhere, and Device Context has no profiles to\n * parameterize them.\n */\n subscribe(listener: StateListener<ConformingEventName>): Subscription;\n}\n\n// ═════════════════════════════════════════════════════════════════════════\n// 6. Domain 5 — Connectivity State\n// ═════════════════════════════════════════════════════════════════════════\n\n/** FROZEN (API_FREEZE §7, VOCABULARY §\"Connectivity Intents\"). */\nexport type ConnectivityIntent =\n | 'lowLatencyConversation'\n | 'interactive'\n | 'bulkTransfer'\n | 'backgroundSync'\n | 'offlineResilient'\n | 'lowPower';\n\n/**\n * V0.1, and note it is FLAT — the connectivity design doc sketched a nested\n * shape (internet{…}, quality{…}, recent_history{…}) and the freeze flattened\n * it. Two unreconciled deltas, carried here as-is rather than merged:\n * - `bandwidthClass` appears in the freeze but in neither the design doc nor\n * the vocabulary's Connectivity Values.\n * - there is NO recent-history field, although the design doc requires native\n * to maintain recent transitions and leaves the default window OPEN.\n */\nexport interface ConnectivitySnapshot {\n /** NOTE: the design doc says \"online / offline / uncertain\"; the frozen\n * third value is `unknown`. The two words are never reconciled. */\n reachability: 'online' | 'offline' | 'unknown';\n transport: 'wifi' | 'cellular' | 'ethernet' | 'other' | 'none' | 'unknown';\n qualityClass:\n | 'excellent'\n | 'good'\n | 'degraded'\n | 'poor'\n | 'unusable'\n | 'unknown';\n stability: 'stable' | 'changing' | 'flapping' | 'unknown';\n /** `null` when no recent measurement exists. Explicitly preferred over\n * reporting a stale number: \"return unknown rather than stale precision.\" */\n latencyMs?: number | null;\n bandwidthClass?: 'high' | 'medium' | 'low' | 'unknown';\n metered?: boolean | null;\n constrained?: boolean | null;\n quality: StateQuality;\n}\n\n/** FROZEN v0.1 (VOCABULARY §\"Initial Connectivity Events\"). All ten. */\nexport type ConnectivityEvent =\n | 'connectivityOnline'\n | 'connectivityOffline'\n | 'transportChanged'\n | 'connectivityDegraded'\n | 'connectivityRecovered'\n | 'connectivityUnstable'\n | 'connectivityStable'\n | 'meteredStateChanged'\n | 'constrainedStateChanged'\n | 'connectivityStateStale';\n\nexport interface ConnectivityDomain {\n /**\n * A fast local cached read. It must NOT ping, and must NOT run a bandwidth\n * or speed test. Latency is sampled on native's own schedule, chosen by\n * intent, and cached with a timestamp.\n */\n getSnapshot(): Promise<ConnectivitySnapshot>;\n /**\n * OPEN: `ConnectivityDomain` is named in §11 but never defined, so whether\n * connectivity is session-based is unstated. DECISION: yes — six frozen\n * intents with documented behavioural differences (lowLatencyConversation\n * \"prioritize fresh latency knowledge\"; lowPower \"rely primarily on passive\n * OS signals and minimize active probes\") only mean something if there is a\n * way to declare one.\n */\n start(options: StartOptions<ConnectivityIntent>): Promise<StateSession>;\n stop(sessionId?: string): Promise<void>;\n subscribe(listener: StateListener<ConnectivityEvent>): Subscription;\n}\n\n// ═════════════════════════════════════════════════════════════════════════\n// 7. Domain 6 — Capability / Permission State\n//\n// The \"why\" domain. When another snapshot says `unknown`, this is where the\n// reason lives. Descriptive only — it never triggers a permission dialog.\n// ═════════════════════════════════════════════════════════════════════════\n\n/**\n * FROZEN. Four independent axes, deliberately not collapsed. The canonical\n * worked example from the capability doc: supported + granted + busy + none —\n * a camera you own, are allowed to use, and cannot have right now.\n */\nexport interface CapabilityStatus {\n support: SupportState;\n permission?: PermissionState;\n availability: AvailabilityState;\n restriction?: RestrictionState;\n}\n\nexport interface CapabilitySnapshot {\n camera: CapabilityStatus;\n microphone: CapabilityStatus;\n /** The only capability the freeze gives scoped detail to. Health and\n * photos/media do NOT get one — see the gap note below. */\n location: CapabilityStatus & {\n precision?: 'precise' | 'approximate' | 'unknown';\n backgroundPermission?: PermissionState;\n };\n motion: CapabilityStatus;\n bluetooth: CapabilityStatus;\n uwb: CapabilityStatus;\n nfc: CapabilityStatus;\n notifications: CapabilityStatus;\n /**\n * GAP (flagged): the capability doc notes health \"authorization is often\n * record-type specific rather than a single global permission\" and its\n * candidate shape had a `permission_summary`. The frozen §9 gives health a\n * plain CapabilityStatus, so scoped health authorization is NOT\n * representable in v0.1. Its own exit criterion (\"scoped permissions are\n * representable\") is therefore only partly met.\n */\n health: CapabilityStatus;\n backgroundExecution: CapabilityStatus;\n /** GAP (flagged): photos/media appears in the design doc's native inputs and\n * its full-vs-limited scope discussion, but there is NO photos key in the\n * frozen CapabilitySnapshot. Not added here. */\n quality: StateQuality;\n}\n\n/** FROZEN v0.1 (VOCABULARY §\"Initial Capability Events\"). All ten. */\nexport type CapabilityEvent =\n | 'capabilityChanged'\n | 'permissionChanged'\n | 'capabilityAvailable'\n | 'capabilityUnavailable'\n /** NOTE: this pair does not match the documented naming patterns. The docs\n * neither flag nor reconcile it; carried verbatim rather than \"fixed\". */\n | 'capabilityBusy'\n | 'capabilityFree'\n | 'restrictionChanged'\n | 'locationPrecisionChanged'\n | 'backgroundPermissionChanged'\n | 'capabilityStateStale';\n\n/**\n * NO INTENT TYPE — the one domain that is intent-less by explicit reasoning\n * rather than by omission: \"Capability State itself should generally be cheap\n * and mostly event-driven, so it does not need many sensing profiles.\"\n * A candidate `interactive/background/minimal` vocabulary is floated in the\n * design doc and explicitly conditional (\"only be kept if implementation\n * proves they add value\"). Nothing frozen. Not added.\n *\n * Also NOT here: any `requestPermission()`. Permission-request UX is outside\n * this state engine by design, and a floated generic primitive is future work.\n */\nexport interface CapabilityDomain {\n getSnapshot(): Promise<CapabilitySnapshot>;\n subscribe(listener: StateListener<CapabilityEvent>): Subscription;\n}\n\n// ═════════════════════════════════════════════════════════════════════════\n// 8. Domain 7 — Environment State\n// ═════════════════════════════════════════════════════════════════════════\n\n/** FROZEN (VOCABULARY §\"Environment Intents\"). */\nexport type EnvironmentIntent =\n | 'ambient'\n | 'navigation'\n | 'accessibility'\n | 'proximity'\n | 'safety'\n | 'lowPower';\n\nexport interface EnvironmentSnapshot {\n /** Privacy is part of the SHAPE, not advice: this says `dim`, never a camera\n * frame; `loud`, never microphone audio; a beacon count, never a BLE\n * payload. Raw audio/images/BLE payloads are not part of this domain. */\n lighting: {\n level: 'dark' | 'dim' | 'normal' | 'bright' | 'veryBright' | 'unknown';\n lux?: number | null;\n confidence?: Confidence;\n };\n acoustics: {\n level: 'quiet' | 'moderate' | 'loud' | 'veryLoud' | 'unknown';\n approximateDb?: number | null;\n confidence?: Confidence;\n };\n /** `uncertain` and `unknown` are different: uncertain = we looked and cannot\n * decide; unknown = we have no basis to decide. */\n enclosure: {\n state: 'indoor' | 'outdoor' | 'uncertain' | 'unknown';\n confidence?: Confidence;\n };\n proximity?: {\n distanceClass?: 'immediate' | 'near' | 'far' | 'unknown';\n confidence?: Confidence;\n };\n /** The only sub-block with no confidence — these are presence booleans, not\n * estimates. Note they cannot distinguish unsupported / denied / switched\n * off; that distinction lives in `capability`. */\n nearbySignals?: {\n bleAvailable?: boolean;\n beaconCount?: number | null;\n uwbAvailable?: boolean;\n nfcAvailable?: boolean;\n };\n quality: StateQuality;\n}\n\n/** FROZEN v0.1 (VOCABULARY §\"Initial Environment Events\"). All ten. */\nexport type EnvironmentEvent =\n | 'lightingChanged'\n | 'environmentBecameDark'\n | 'environmentBecameBright'\n | 'noiseLevelChanged'\n | 'environmentBecameLoud'\n | 'indoorOutdoorChanged'\n | 'proximityChanged'\n | 'nearbySignalAppeared'\n | 'nearbySignalDisappeared'\n | 'environmentStateStale';\n\nexport interface EnvironmentDomain {\n getSnapshot(): Promise<EnvironmentSnapshot>;\n start(options: StartOptions<EnvironmentIntent>): Promise<StateSession>;\n stop(sessionId?: string): Promise<void>;\n subscribe(listener: StateListener<EnvironmentEvent>): Subscription;\n}\n\n// ═════════════════════════════════════════════════════════════════════════\n// 9. Domain 8 — Interaction State\n//\n// Reports interaction FACTS. It never decides \"pause the guide\" or \"speak now\"\n// — that is orchestration and belongs to the Plugin Tool / Skill / AI.\n// ═════════════════════════════════════════════════════════════════════════\n\nexport interface InteractionSnapshot {\n lifecycle: {\n appState: 'foreground' | 'background' | 'inactive' | 'unknown';\n screenOn: boolean | null;\n userActive?: boolean | null;\n idleDurationMs?: number | null;\n };\n audio: {\n captureActive: boolean | null;\n playbackActive: boolean | null;\n route:\n | 'speaker'\n | 'earpiece'\n | 'wiredHeadset'\n | 'bluetooth'\n | 'carAudio'\n | 'other'\n | 'unknown';\n /** `none` (checked, nothing interrupting) and `unknown` (no knowledge) are\n * deliberately different values. */\n interruption: 'none' | 'temporary' | 'system' | 'unknown';\n };\n /** Optional GROUP: a platform that cannot report voice session state omits\n * the whole block rather than guessing `false` for each field. */\n voice?: {\n sessionActive: boolean | null;\n userSpeaking?: boolean | null;\n assistantSpeaking?: boolean | null;\n };\n /** May report that a camera session is running; must NOT duplicate frame\n * state. Frames belong to `visual`. */\n visual?: {\n cameraSessionActive: boolean | null;\n };\n quality: StateQuality;\n}\n\n/** FROZEN v0.1 (VOCABULARY §\"Initial Interaction Events\"). All twelve. */\nexport type InteractionEvent =\n | 'appStateChanged'\n | 'screenStateChanged'\n | 'audioRouteChanged'\n | 'audioInterruptionStarted'\n | 'audioInterruptionEnded'\n | 'voiceSessionStarted'\n | 'voiceSessionStopped'\n | 'cameraSessionStarted'\n | 'cameraSessionStopped'\n | 'userBecameActive'\n | 'userBecameIdle'\n | 'interactionStateStale';\n\n/**\n * NO INTENT TYPE. §10 declares only `InteractionSnapshot`, and the vocabulary\n * — which does publish intents for spatial, visual, activity, connectivity and\n * environment — has no \"Interaction Intents\" section. Five profiles are\n * floated in the design doc, hedged twice (\"Likely profiles, if needed\") with\n * no obligation attached to any of them. Not added.\n */\nexport interface InteractionDomain {\n getSnapshot(): Promise<InteractionSnapshot>;\n subscribe(listener: StateListener<InteractionEvent>): Subscription;\n}\n\n// ═════════════════════════════════════════════════════════════════════════\n// 10. Root surface\n// ═════════════════════════════════════════════════════════════════════════\n\n/**\n * FROZEN name (API_FREEZE §11) and FROZEN member names.\n *\n * §11's \"Recommended naming rule\" says to call it `visual.getSnapshot()`, not\n * `device.visual.*`. Read here as a rule about the WIRE/tool-name convention\n * (`device.*` stays a human/backend routing convention for callable plugin\n * tools) rather than a ban on a plugin-prop container. That reading is a\n * judgement call and is flagged as such — if it is wrong, the fix is to rename\n * the PROP, never to merge these eight members into `PluginNative`.\n */\nexport interface DeviceBridgeV2 {\n readonly spatial: SpatialDomain;\n readonly visual: VisualDomain;\n readonly activity: ActivityDomain;\n readonly deviceContext: DeviceContextDomain;\n readonly connectivity: ConnectivityDomain;\n readonly capability: CapabilityDomain;\n readonly environment: EnvironmentDomain;\n readonly interaction: InteractionDomain;\n}\n\n/** The name plugin authors see. See DESIGN NOTE 1 for why not `deviceBridge`. */\nexport type DeviceState = DeviceBridgeV2;\n\n// ═════════════════════════════════════════════════════════════════════════\n// 11. Manifest gate — a SEPARATE declaration from `native`\n// ═════════════════════════════════════════════════════════════════════════\n\n/**\n * DECISION (not in the docs). A second, differently-named manifest field, so a\n * plugin cannot half-declare its way across the boundary:\n *\n * native: { camera: true } → props.device.camera.takePhoto()\n * stateDomains: ['visual', 'spatial'] → props.deviceState.visual.getSnapshot()\n *\n * Declaring `native.camera` grants NOTHING in the semantic layer, and vice\n * versa. There is no field whose meaning spans both.\n *\n * How an UNDECLARED domain must behave — and this is the load-bearing part:\n * it returns a normal snapshot in which every enum is `unknown`, every\n * nullable is `null`, and `quality.freshness` is\n * `{ state:'unknown', observedAt:null, ageMs:null }`. It does NOT throw and it\n * does NOT return undefined.\n *\n * Why that matters here specifically: today's `gatePluginNative` gives an\n * undeclared capability a proxy whose methods `console.warn` and return\n * `undefined` (packages/plugin-runtime/src/host.ts:67-76). So\n * `await native.location.getCurrent()` on an undeclared plugin resolves to\n * `undefined`, and `pos?.latitude` is `undefined` — which then flows into an\n * LLM answer as a confident nothing. A silent undefined is a fabrication\n * vector; a snapshot of explicit unknowns is not.\n *\n * The \"why\" is readable from `capability.getSnapshot()` using an existing\n * frozen enum member: a manifest-gate denial maps to\n * `restriction: 'policyRestricted'` — the plugin manifest IS a policy. No new\n * vocabulary needed. (The docs never consider a manifest gate, so this\n * mapping is a DECISION, but it uses only frozen values.)\n */\nexport type StateDomainDeclaration = readonly DeviceBridgeDomain[];\n\n// ═════════════════════════════════════════════════════════════════════════\n// 12. Small helpers — the \"present does not mean fresh\" guard\n// DECISION. Not frozen, not in any doc. Included because the single most\n// likely misuse of this API is reading a value and ignoring `quality`, and a\n// one-line guard is easier to reach for than a correct hand-rolled check.\n// ═════════════════════════════════════════════════════════════════════════\n\nconst CONFIDENCE_ORDER: Record<ConfidenceLevel, number> = {\n unknown: 0,\n low: 1,\n medium: 2,\n high: 3,\n};\n\n/**\n * Is this snapshot good enough to act on?\n *\n * Deliberately requires the caller to state a budget: there is no universal\n * \"fresh enough\", and the docs give no numeric thresholds for any domain\n * (native chooses sampling behaviour). A guidance loop wants ~1500 ms; a\n * battery-aware background job is happy with 60 s.\n *\n * `unknown` freshness fails: it means nothing was ever observed, which is not\n * the same as an old-but-real reading and must not be treated as one.\n */\nexport function isActionable(\n quality: StateQuality,\n budget: { maxAgeMs: number; minConfidence?: ConfidenceLevel },\n): boolean {\n const { freshness, confidence } = quality;\n if (freshness.state === 'unknown' || freshness.state === 'stale') return false;\n if (freshness.ageMs === null || freshness.ageMs > budget.maxAgeMs) return false;\n if (budget.minConfidence) {\n const have = CONFIDENCE_ORDER[confidence?.level ?? 'unknown'];\n if (have < CONFIDENCE_ORDER[budget.minConfidence]) return false;\n }\n return true;\n}\n\n/** The honest \"we have never observed this\" value. Use it instead of\n * inventing a timestamp when constructing a degraded snapshot. This is the\n * canonical source of the `unknown` freshness shape — the engine's\n * `qualityUnknown()` derives from it so the two never drift. */\nexport function neverObserved(): Freshness {\n return { state: 'unknown', observedAt: null, ageMs: null };\n}\n\n/**\n * One human-readable sentence for why a capability cannot answer, built ONLY\n * from what the four axes actually say. Returns null when the capability is\n * fine — so a caller cannot accidentally print a reason that does not exist.\n */\nexport function explainCapability(status: CapabilityStatus): string | null {\n if (status.support === 'unsupported') return 'this device does not have it';\n if (status.permission === 'denied') return 'permission was denied';\n if (status.permission === 'restricted') return 'permission is restricted';\n if (status.permission === 'notDetermined') return 'permission has not been asked for yet';\n if (status.permission === 'limited') return 'only limited access was granted';\n if (status.restriction === 'policyRestricted') return 'this plugin did not declare it';\n if (status.restriction === 'backgroundRestricted') return 'the app is in the background';\n if (status.restriction === 'lowPowerRestricted') return 'the device is in low-power mode';\n if (status.availability === 'busy') return 'it is in use by something else';\n if (status.availability === 'temporarilyUnavailable') return 'it is temporarily unavailable';\n if (status.availability === 'unavailable') return 'it is unavailable';\n if (status.support === 'unknown' || status.availability === 'unknown') {\n return 'its state could not be determined';\n }\n return null;\n}\n\n// ═════════════════════════════════════════════════════════════════════════\n// 13. Integration seams into the existing SDK\n// ═════════════════════════════════════════════════════════════════════════\n\n/**\n * Additive extension of `PluginProps` (sdk/types.ts:259).\n *\n * `deviceState` is OPTIONAL because a host that has not installed a v2\n * provider must not pretend to have one. `undefined` means \"this host has no\n * semantic layer\", which a plugin can check once; it does NOT mean \"the\n * sensors said nothing\". Those are different, and collapsing them would\n * reintroduce exactly the ambiguity this file exists to remove.\n */\nexport interface PluginPropsV2Extension {\n readonly deviceState?: DeviceState;\n}\n\n/**\n * Additive extension of `DeviceToolContext` (sdk/types.ts:320-327).\n *\n * This is the seam that matters most: device tools are what the AI calls, and\n * device tools are where a fabricated value reaches a user. The lint rule\n * proposed alongside this file (`no-mechanical-sensing-in-device-tools`) bans\n * `ctx.native.camera`, `ctx.native.location` and `ctx.native.connectivity`\n * inside a `DeviceToolDefinition.run` body — a device tool must reach sensing\n * through `ctx.deviceState`. UI code is unaffected.\n */\nexport interface DeviceToolContextV2Extension {\n readonly deviceState?: DeviceState;\n}\n\n// ═════════════════════════════════════════════════════════════════════════\n// DESIGN NOTES\n// ═════════════════════════════════════════════════════════════════════════\n\n/**\n * DESIGN NOTE 1 — why the prop is `deviceState`, not `deviceBridge`.\n *\n * \"Device Bridge\" already names three different things in this codebase:\n * - `DeviceBridge`, the telemetry sync class that polls collectors and\n * pushes to the relay (packages/expo/src/device-bridge/index.ts:60);\n * - `PluginNative`, which sdk/types.ts:323 documents verbatim as\n * \"Device Bridge — camera, location, sensors, storage\";\n * - the v2 semantic layer in this file.\n * A fourth use of the word would be the opposite of unmistakable. `deviceState`\n * says what the object is (state, not actions) and collides with nothing.\n *\n *\n * DESIGN NOTE 2 — why NOT `PluginNative.visual` / `PluginNative.connectivityState`.\n *\n * The implementation-grounding doc proposes adding the eight domains as fields\n * on `PluginNative`, with `connectivityState` to dodge the collision with the\n * existing `connectivity`. Rejected, for three reasons:\n *\n * (a) It puts `native.camera.takePhoto()` and `native.visual.getSnapshot()`\n * on one object, one keystroke apart in autocomplete. The layer becomes\n * invisible at the call site, which is the failure being designed out.\n * (b) `native.connectivity` vs `native.connectivityState` is a confusable\n * pair by construction — two fields, one object, near-identical names,\n * different layers, different return shapes. `deviceState.connectivity`\n * vs `native.connectivity` is disambiguated by the first token instead.\n * (c) The gate model would have to span both meanings of one manifest field.\n *\n * The grounding doc's actual constraint is §14's \"Do not create a second\n * plugin runtime\" — and this design does not. Same runtime, same registration,\n * same bundle pipeline, same props object; one additional namespace on it.\n * Everything else in that doc's file-by-file plan (resident engines, warm\n * sessions, reference counting, no pipeline per tool call, the p50<10ms /\n * p95<30ms snapshot budget) stands unchanged.\n *\n *\n * DESIGN NOTE 3 — what this file does NOT decide, because the docs did not.\n *\n * - Per-intent behavioural contracts. The architecture doc MANDATES that each\n * intent document latency goal, quality target, continuous-vs-one-shot,\n * rolling-history behaviour, power posture, background behaviour, required\n * permissions and output shape. No document supplies these for ANY of the\n * nine visual intents, and there is no equivalent table for activity. The\n * vocabulary is minted; the semantics behind each name are not. This is the\n * largest hole in the whole design and no amount of TypeScript closes it.\n * - Multi-consumer session ownership / reference counting.\n * - MediaHandle → bytes resolution, and expiry behaviour.\n * - Whether `visual.capture()` may use a different intent from the session.\n * - Event vocabularies for visual, activity, deviceContext. (Spatial's is a\n * DECISION, recorded at `SpatialEvent`, not a reading of the docs.)\n * - Per-event payload schemas for every domain but spatial\n * (`SpatialStateEvent`, likewise a DECISION).\n * - Background/foreground semantics for activity and connectivity (specified\n * only for visual).\n * - Numeric thresholds for fresh/aging/stale, and for \"materially changed\".\n * - Cross-domain conflict resolution (activity says walking, spatial speed\n * says vehicle) — explicitly deferred as future State Engine Fusion and\n * out of v2 scope. A v2 snapshot must be internally coherent; it is NOT\n * obliged to reconcile itself with another domain.\n */\n","/**\n * Re-exported React Native primitives.\n * Plugins import these from '@adas/plugin-sdk' — never from 'react-native' directly.\n */\nexport {\n View,\n Text,\n ScrollView,\n FlatList,\n SectionList,\n Pressable,\n TouchableOpacity,\n TextInput,\n Image,\n ActivityIndicator,\n Modal,\n Switch,\n StyleSheet,\n Animated,\n Platform,\n RefreshControl,\n} from 'react-native';\n","/**\n * Pre-built UI components for native plugins.\n * These provide consistent styling using ThemeTokens.\n */\nimport React from 'react';\nimport {\n View,\n Text,\n Pressable,\n TextInput,\n ActivityIndicator,\n StyleSheet,\n} from 'react-native';\nimport type { ThemeTokens } from './types';\n\n// ── Card ────────────────────────────────────────────────────\n\ninterface CardProps {\n theme: ThemeTokens;\n children: React.ReactNode;\n style?: any;\n onPress?: () => void;\n}\n\nexport function Card({ theme, children, style, onPress }: CardProps) {\n const cardStyle = [\n styles.card,\n {\n backgroundColor: theme.colors.surface,\n borderColor: theme.colors.border,\n },\n style,\n ];\n\n if (onPress) {\n return React.createElement(Pressable, { style: cardStyle, onPress }, children);\n }\n return React.createElement(View, { style: cardStyle }, children);\n}\n\n// ── Badge ───────────────────────────────────────────────────\n\ninterface BadgeProps {\n theme: ThemeTokens;\n label: string;\n color?: 'accent' | 'success' | 'warning' | 'error' | 'purple';\n style?: any;\n}\n\nconst BADGE_COLORS = {\n accent: { bg: 'accentSoft', text: 'accent' },\n success: { bg: 'successSoft', text: 'success' },\n warning: { bg: 'warningSoft', text: 'warning' },\n error: { bg: 'errorSoft', text: 'error' },\n purple: { bg: 'purpleSoft', text: 'purple' },\n} as const;\n\nexport function Badge({ theme, label, color = 'accent', style }: BadgeProps) {\n const mapping = BADGE_COLORS[color];\n return React.createElement(\n View,\n {\n style: [\n styles.badge,\n {\n backgroundColor: theme.colors[mapping.bg],\n borderRadius: theme.borderRadius.sm,\n },\n style,\n ],\n },\n React.createElement(Text, {\n style: [styles.badgeText, { color: theme.colors[mapping.text] }],\n }, label),\n );\n}\n\n// ── TabBar ──────────────────────────────────────────────────\n\ninterface TabBarProps {\n theme: ThemeTokens;\n tabs: string[];\n activeTab: string;\n onTabChange: (tab: string) => void;\n style?: any;\n}\n\nexport function TabBar({ theme, tabs, activeTab, onTabChange, style }: TabBarProps) {\n return React.createElement(\n View,\n {\n style: [\n styles.tabBar,\n { borderBottomColor: theme.colors.border },\n style,\n ],\n },\n tabs.map((tab) =>\n React.createElement(\n Pressable,\n {\n key: tab,\n style: [\n styles.tab,\n {\n borderBottomColor: tab === activeTab ? theme.colors.accent : 'transparent',\n },\n ],\n onPress: () => onTabChange(tab),\n },\n React.createElement(Text, {\n style: {\n color: tab === activeTab ? theme.colors.accent : theme.colors.textSecondary,\n fontSize: theme.fontSize.sm,\n fontWeight: tab === activeTab ? '600' : '400',\n },\n }, tab),\n ),\n ),\n );\n}\n\n// ── ListItem ────────────────────────────────────────────────\n\ninterface ListItemProps {\n theme: ThemeTokens;\n title: string;\n subtitle?: string;\n right?: React.ReactNode;\n onPress?: () => void;\n style?: any;\n}\n\nexport function ListItem({ theme, title, subtitle, right, onPress, style }: ListItemProps) {\n const content = [\n React.createElement(\n View,\n { key: 'content', style: styles.listItemContent },\n React.createElement(Text, {\n style: { color: theme.colors.text, fontSize: theme.fontSize.md },\n numberOfLines: 1,\n }, title),\n subtitle\n ? React.createElement(Text, {\n style: { color: theme.colors.textSecondary, fontSize: theme.fontSize.xs, marginTop: 2 },\n numberOfLines: 1,\n }, subtitle)\n : null,\n ),\n right ? React.createElement(View, { key: 'right' }, right) : null,\n ];\n\n if (onPress) {\n return React.createElement(\n Pressable,\n { style: [styles.listItem, { borderBottomColor: theme.colors.border }, style], onPress },\n ...content,\n );\n }\n return React.createElement(\n View,\n { style: [styles.listItem, { borderBottomColor: theme.colors.border }, style] },\n ...content,\n );\n}\n\n// ── SearchBar ───────────────────────────────────────────────\n\ninterface SearchBarProps {\n theme: ThemeTokens;\n value: string;\n onChangeText: (text: string) => void;\n placeholder?: string;\n style?: any;\n}\n\nexport function SearchBar({ theme, value, onChangeText, placeholder = 'Search...', style }: SearchBarProps) {\n return React.createElement(TextInput, {\n style: [\n styles.searchBar,\n {\n backgroundColor: theme.colors.input,\n color: theme.colors.text,\n borderColor: theme.colors.border,\n borderRadius: theme.borderRadius.sm,\n fontSize: theme.fontSize.sm,\n },\n style,\n ],\n value,\n onChangeText,\n placeholder,\n placeholderTextColor: theme.colors.textMuted,\n autoCapitalize: 'none',\n autoCorrect: false,\n });\n}\n\n// ── EmptyState ──────────────────────────────────────────────\n\ninterface EmptyStateProps {\n theme: ThemeTokens;\n title: string;\n subtitle?: string;\n style?: any;\n}\n\nexport function EmptyState({ theme, title, subtitle, style }: EmptyStateProps) {\n return React.createElement(\n View,\n { style: [styles.emptyState, style] },\n React.createElement(Text, {\n style: { color: theme.colors.textSecondary, fontSize: theme.fontSize.md, textAlign: 'center' },\n }, title),\n subtitle\n ? React.createElement(Text, {\n style: { color: theme.colors.textMuted, fontSize: theme.fontSize.sm, textAlign: 'center', marginTop: 4 },\n }, subtitle)\n : null,\n );\n}\n\n// ── ErrorState ──────────────────────────────────────────────\n\ninterface ErrorStateProps {\n theme: ThemeTokens;\n message: string;\n onRetry?: () => void;\n style?: any;\n}\n\nexport function ErrorState({ theme, message, onRetry, style }: ErrorStateProps) {\n return React.createElement(\n View,\n { style: [styles.emptyState, style] },\n React.createElement(Text, {\n style: { color: theme.colors.error, fontSize: theme.fontSize.md, textAlign: 'center' },\n }, message),\n onRetry\n ? React.createElement(\n Pressable,\n {\n style: [styles.retryButton, { backgroundColor: theme.colors.accentSoft, borderRadius: theme.borderRadius.sm }],\n onPress: onRetry,\n },\n React.createElement(Text, {\n style: { color: theme.colors.accent, fontSize: theme.fontSize.sm, fontWeight: '600' },\n }, 'Retry'),\n )\n : null,\n );\n}\n\n// ── LoadingState ────────────────────────────────────────────\n\ninterface LoadingStateProps {\n theme: ThemeTokens;\n message?: string;\n style?: any;\n}\n\nexport function LoadingState({ theme, message = 'Loading...', style }: LoadingStateProps) {\n return React.createElement(\n View,\n { style: [styles.emptyState, style] },\n React.createElement(ActivityIndicator, { size: 'small', color: theme.colors.accent }),\n React.createElement(Text, {\n style: { color: theme.colors.textSecondary, fontSize: theme.fontSize.sm, marginTop: 8 },\n }, message),\n );\n}\n\n// ── ActionButton (FAB) ──────────────────────────────────────\n\ninterface ActionButtonProps {\n theme: ThemeTokens;\n label?: string;\n icon?: React.ReactNode;\n onPress: () => void;\n style?: any;\n}\n\nexport function ActionButton({ theme, label, icon, onPress, style }: ActionButtonProps) {\n return React.createElement(\n Pressable,\n {\n style: [\n styles.fab,\n { backgroundColor: theme.colors.accent, borderRadius: theme.borderRadius.full },\n style,\n ],\n onPress,\n },\n icon || React.createElement(Text, { style: styles.fabText }, label || '+'),\n );\n}\n\n// ── Styles ──────────────────────────────────────────────────\n\nconst styles = StyleSheet.create({\n card: {\n padding: 12,\n borderRadius: 12,\n borderWidth: 1,\n marginBottom: 8,\n },\n badge: {\n paddingHorizontal: 8,\n paddingVertical: 3,\n },\n badgeText: {\n fontSize: 11,\n fontWeight: '600',\n },\n tabBar: {\n flexDirection: 'row',\n borderBottomWidth: 1,\n },\n tab: {\n flex: 1,\n padding: 12,\n alignItems: 'center',\n borderBottomWidth: 2,\n },\n listItem: {\n flexDirection: 'row',\n alignItems: 'center',\n paddingVertical: 12,\n paddingHorizontal: 16,\n borderBottomWidth: StyleSheet.hairlineWidth,\n },\n listItemContent: {\n flex: 1,\n },\n searchBar: {\n height: 40,\n paddingHorizontal: 12,\n borderWidth: 1,\n },\n emptyState: {\n flex: 1,\n justifyContent: 'center',\n alignItems: 'center',\n padding: 32,\n },\n retryButton: {\n marginTop: 12,\n paddingHorizontal: 16,\n paddingVertical: 8,\n },\n fab: {\n position: 'absolute',\n bottom: 24,\n right: 24,\n width: 56,\n height: 56,\n justifyContent: 'center',\n alignItems: 'center',\n shadowColor: '#000',\n shadowOffset: { width: 0, height: 2 },\n shadowOpacity: 0.25,\n shadowRadius: 4,\n elevation: 5,\n },\n fabText: {\n color: '#fff',\n fontSize: 24,\n fontWeight: '600',\n },\n});\n","/**\n * Host integration points — the DI seams that keep this package free of\n * Expo imports. The host app (or @ateam-ai-mobile/expo) plugs in concrete providers\n * once at startup; everything here has a safe no-op/in-memory default so\n * a bare host works with zero configuration.\n */\n\nimport type { HapticsAPI, NativeCapabilities, PluginNative } from './sdk/types';\nimport type { RegisteredPlugin } from './sdk/types';\n\n// ── Haptics ────────────────────────────────────────────────────────────────\n\nlet _haptics: HapticsAPI | null = null;\n\n/** Register a haptics implementation (e.g. expo-haptics via @ateam-ai-mobile/expo). */\nexport function setHapticsProvider(haptics: HapticsAPI | null): void {\n _haptics = haptics;\n}\n\n/** No-op safe accessor — surfaces call this for tap feedback. */\nexport function getHaptics(): HapticsAPI | null {\n return _haptics;\n}\n\n// ── PluginNative (device capabilities handed to plugins) ──────────────────\n// The full implementation lives in the HOST (it owns the native modules —\n// e.g. ateam-mobile's device-bridge). Without a provider, plugins get\n// clearly-erroring stubs instead of crashes.\n\nfunction unavailable(api: string): any {\n return new Proxy({}, {\n get: (_t, method) => () =>\n Promise.reject(new Error(`[adas] native.${api}.${String(method)} unavailable — host did not call setPluginNativeProvider()`)),\n });\n}\n\nconst noopNative: PluginNative = {\n camera: unavailable('camera'),\n location: unavailable('location'),\n storage: unavailable('storage'),\n biometrics: unavailable('biometrics'),\n biometricsV2: unavailable('biometricsV2'),\n notifications: unavailable('notifications'),\n haptics: { impact: () => {}, notification: () => {}, selection: () => {}, error: () => {} },\n connectivity: { isOnline: () => true, onChange: () => () => {} },\n fileSystem: unavailable('fileSystem'),\n cookies: unavailable('cookies'),\n sharing: unavailable('sharing'),\n scanner: unavailable('scanner'),\n nfc: unavailable('nfc'),\n bluetooth: unavailable('bluetooth'),\n vision: unavailable('vision'),\n maps: unavailable('maps'),\n};\n\nlet _pluginNative: PluginNative = noopNative;\n\n/** Install the device-capabilities implementation plugins receive as\n * `props.device` (the L1 native modules keep the `native` name; the plugin-\n * facing prop is `device`). The host owns the native modules. */\nexport function setPluginNativeProvider(native: PluginNative): void {\n _pluginNative = native;\n}\n\nexport function getPluginNative(): PluginNative {\n return _pluginNative;\n}\n\n/** Blocked-capability proxy: any call warns and is ignored (no throw) —\n * matches the reference app's behaviour for undeclared capabilities. */\nfunction blocked(api: string, reason?: string): any {\n return new Proxy({}, {\n get: (_t, method) => {\n if (typeof method !== 'string') return undefined;\n return () => {\n console.warn(`[adas] native.${api}.${method} blocked — ${reason ?? `capability '${api}' not declared in the plugin manifest`}`);\n };\n },\n });\n}\n\n/**\n * Gate a PluginNative by the capabilities a plugin's manifest declares.\n * Undeclared capabilities become warn-and-ignore proxies, so a plugin can\n * only touch device APIs it asked for (per-plugin security model, preserved\n * from the reference app). Connectivity is always allowed.\n *\n * Flag mapping mirrors the manifest contract: `storage` is gated by\n * `offline` (offline data ⇒ local storage).\n */\nexport function gatePluginNative(\n native: PluginNative,\n declared?: NativeCapabilities,\n pluginId?: string,\n): PluginNative {\n const caps = declared || {};\n // Per-plugin filesystem + storage isolation, FAIL CLOSED. A declared plugin\n // gets a sandbox/namespace scoped to its OWN id (plugin-files/<pluginId>/,\n // @plugin:<id>: KV, plugin-storage-<id>.db) via the provider's\n // fileSystemFor/storageFor. There is deliberately NO shared fallback: if the\n // id is missing or the provider can't scope, the plugin is BLOCKED, not handed\n // a bucket some other plugin also holds. A silent shared fallback is exactly\n // the P1 that reopened when the UI renderer omitted the id — the isolation must\n // fail closed, never degrade to \"shared\" without anyone noticing.\n const scopedFileSystem =\n native.fileSystemFor && pluginId ? native.fileSystemFor(pluginId) : null;\n const scopedStorage =\n native.storageFor && pluginId ? native.storageFor(pluginId) : null;\n const gated = {\n camera: caps.camera ? native.camera : blocked('camera'),\n location: caps.location ? native.location : blocked('location'),\n storage: caps.offline\n ? (scopedStorage ?? blocked('storage', \"no trusted pluginId to scope storage — refusing shared access (fail closed)\"))\n : blocked('storage'),\n biometrics: caps.biometrics ? native.biometrics : blocked('biometrics'),\n biometricsV2: caps.biometricsV2 ? native.biometricsV2 : blocked('biometricsV2'),\n notifications: caps.notifications ? native.notifications : blocked('notifications'),\n haptics: caps.haptics ? native.haptics : blocked('haptics'),\n connectivity: native.connectivity,\n fileSystem: caps.fileSystem\n ? (scopedFileSystem ?? blocked('fileSystem', \"no trusted pluginId to scope the filesystem — refusing shared access (fail closed)\"))\n : blocked('fileSystem'),\n cookies: caps.cookies ? native.cookies : blocked('cookies'),\n sharing: caps.sharing ? native.sharing : blocked('sharing'),\n scanner: caps.scanner ? native.scanner : blocked('scanner'),\n nfc: caps.nfc ? native.nfc : blocked('nfc'),\n // Gated like the rest even though nothing implements it yet. An undeclared\n // plugin gets the usual blocked proxy; a DECLARED one reaches an API whose\n // every method refuses by name. Both are better than the `undefined` this\n // used to be, which crashed with \"cannot read properties of undefined\".\n bluetooth: caps.bluetooth ? native.bluetooth : blocked('bluetooth'),\n vision: caps.vision ? native.vision : blocked('vision'),\n maps: caps.maps ? native.maps : blocked('maps'),\n // What this plugin DECLARED, carried on the object it already receives.\n //\n // It is how a COMPONENT can be capability-gated: <CameraPreview> is handed\n // `native` and reads this, so showing the camera obeys the same flag as\n // calling it. Without this the preview would be a second door to the camera\n // with only one lock. Non-enumerable so it cannot be mistaken for an API.\n } as any;\n\n Object.defineProperty(gated, '__declaredCapabilities', {\n value: Object.freeze({ ...caps }),\n enumerable: false,\n writable: false,\n });\n return gated;\n}\n\n// ── Camera preview (the plugin-facing way to SHOW the camera) ─────────────\n//\n// A plugin composes <CameraPreview native={native} /> from the SDK; the HOST\n// supplies what actually renders, because only the host has the native module.\n//\n// This exists so we do NOT register raw `expo-camera` for bundles. That would\n// be a third door to the device with no capability gate and no honest failure\n// mode — a plugin could mount a camera without declaring it. Here the pixels\n// stay on the host's side: a plugin can SHOW the camera and still cannot touch\n// a frame.\n\n/** Props the host's preview implementation receives. */\nexport interface CameraPreviewImplProps {\n facing?: 'front' | 'back';\n style?: any;\n renderUnavailable?: (reason: string) => any;\n}\n\nlet _cameraPreview: ((props: CameraPreviewImplProps) => any) | null = null;\n\n/** Install the host's camera preview (e.g. an expo-camera CameraView). */\nexport function setCameraPreviewProvider(\n Component: ((props: CameraPreviewImplProps) => any) | null,\n): void {\n _cameraPreview = Component;\n}\n\n/** Null when the host installed none — the SDK then renders a stated reason,\n * never a black rectangle that looks like a dark room. */\nexport function getCameraPreviewProvider(): ((props: CameraPreviewImplProps) => any) | null {\n return _cameraPreview;\n}\n\n// ── Native (host-bundled) plugin registry ─────────────────────────────────\n// Plugins compiled into the host binary (dev plugins, first-party panels).\n// usePlugin checks this registry before hitting the remote bundle pipeline.\n// Values may be lazy loaders so heavy plugins don't cost app-start time.\n\ntype PluginResolver = RegisteredPlugin | (() => Promise<RegisteredPlugin | null>);\n\nconst _nativeRegistry = new Map<string, PluginResolver>();\n\nexport function registerNativePlugin(id: string, plugin: PluginResolver): void {\n _nativeRegistry.set(id, plugin);\n}\n\nexport function unregisterNativePlugin(id: string): void {\n _nativeRegistry.delete(id);\n}\n\nexport const nativePluginRegistry = {\n has(id: string): boolean {\n return _nativeRegistry.has(id);\n },\n async get(id: string): Promise<RegisteredPlugin | null> {\n const entry = _nativeRegistry.get(id);\n if (!entry) return null;\n if (typeof entry === 'function') {\n try {\n return await entry();\n } catch (err) {\n console.warn(`[adas-plugins] lazy native plugin '${id}' failed to load:`, err);\n return null;\n }\n }\n return entry;\n },\n};\n\n// ── Extra bundle modules ───────────────────────────────────────────────────\n// Remote bundles are built with externals resolved by the require shim in\n// bundleManager. react / react-native / @adas/plugin-sdk are always provided;\n// anything else (react-native-webview, expo-linking, …) must be registered\n// by the host, which actually has those modules installed.\n\nconst _bundleModules = new Map<string, any>();\n\nexport function registerBundleModules(modules: Record<string, any>): void {\n for (const [name, mod] of Object.entries(modules)) {\n _bundleModules.set(name, mod);\n }\n}\n\nexport function resolveBundleModule(name: string): any | undefined {\n return _bundleModules.get(name);\n}\n","/**\n * CameraPreview — the plugin-facing way to SHOW the user what the camera sees.\n *\n * import { CameraPreview } from '@adas/plugin-sdk';\n * <CameraPreview native={native} /> // native = the plugin's own props.native\n *\n * '@adas/plugin-sdk' is the only SDK module a bundle can require. The same code\n * is published as '@ateam-ai-mobile/plugin-runtime', but that is the host app's\n * package: a bundle that requires it fails at evaluation, by name.\n *\n * WHY THIS EXISTS RATHER THAN HANDING PLUGINS `expo-camera`.\n *\n * The design has exactly two doors to the device: `props.native.*` (mechanical\n * verbs, capability-gated, throws) and `props.deviceState.*` (semantic state,\n * gated, says unknown). Registering a raw native module for bundles would open\n * a THIRD door with no grammar, no gate and no honest failure mode — a plugin\n * could mount a camera without declaring it, and nothing in the manifest would\n * say so. That is the shape of hole this platform keeps closing, not opening.\n *\n * So the preview is a COMPONENT the plugin composes, and the pixels stay on the\n * host's side of the boundary. A plugin can show the camera; it still cannot\n * touch a frame. Reading frames remains `deviceState.visual` (semantic, with\n * freshness) and analysing them remains `native.vision` (which takes an id and\n * resolves it inside the trusted layer).\n *\n * IT IS GATED BY THE SAME FLAG AS `native.camera`. One door, one lock: a plugin\n * that has not declared `capabilities: { camera: true }` gets a refusal panel\n * saying exactly that, not a black rectangle it might mistake for a dark room.\n *\n * IT NEVER RENDERS NOTHING. Every failure — capability not declared, host has\n * not installed a provider, OS permission refused — draws a panel stating which\n * one. A preview that silently renders empty is indistinguishable from a camera\n * pointed at a wall, and a guide built on it would describe a scene nobody saw.\n */\nimport React from 'react';\nimport { View, Text } from './primitives';\nimport type { PluginNative } from './types';\nimport { getCameraPreviewProvider } from '../host';\n\nexport interface CameraPreviewProps {\n /**\n * The plugin's own `props.native`. REQUIRED, and it is the gate: the runtime\n * stamps the declared capabilities onto this object, so passing it is how the\n * component knows whether this plugin may show a camera at all.\n */\n native: PluginNative;\n facing?: 'front' | 'back';\n style?: any;\n /** Rendered instead of the built-in panel when the preview is unavailable. */\n renderUnavailable?: (reason: string) => React.ReactElement | null;\n}\n\n/** Declared capabilities, stamped onto the gated object by gatePluginNative. */\nfunction declaredCapabilities(native: any): Record<string, boolean> | null {\n return (native && native.__declaredCapabilities) || null;\n}\n\nexport function CameraPreview({ native, facing = 'back', style, renderUnavailable }: CameraPreviewProps) {\n const caps = declaredCapabilities(native);\n\n // The gate. Deliberately checked BEFORE asking the host for a provider, so a\n // plugin cannot learn whether a camera exists without declaring that it wants\n // one — an undeclared plugin gets the same answer on every device.\n if (caps && !caps.camera) {\n return unavailable(\n \"this plugin did not declare `capabilities: { camera: true }`, so it may not show the camera\",\n renderUnavailable,\n style,\n );\n }\n\n const Provider = getCameraPreviewProvider();\n if (!Provider) {\n // The host has not installed a preview implementation. Say so rather than\n // rendering black: \"no provider\" and \"a dark room\" must never look alike.\n return unavailable(\n 'this app does not provide a camera preview (the host has not called setCameraPreviewProvider)',\n renderUnavailable,\n style,\n );\n }\n\n return <Provider facing={facing} style={style} renderUnavailable={renderUnavailable} />;\n}\n\nfunction unavailable(\n reason: string,\n render: CameraPreviewProps['renderUnavailable'],\n style: any,\n): React.ReactElement | null {\n if (render) return render(reason);\n return (\n <View style={[{ flex: 1, backgroundColor: '#000', alignItems: 'center', justifyContent: 'center', padding: 20 }, style]}>\n <Text style={{ color: '#39FF66', fontSize: 12, textAlign: 'center' }}>\n {`NO CAMERA PREVIEW\\n${reason}`}\n </Text>\n </View>\n );\n}\n\nexport default CameraPreview;\n","/**\n * Theme delivered to plugins via `usePluginTheme()`.\n *\n * Theming flows from the HOST — plugin-side fallback hex values are a no-op\n * by design. The default is the Ada warm-paper palette (matching the\n * reference app); hosts with their own brand call `setPluginThemeColors()`\n * once at startup to override.\n */\nimport { useMemo, useSyncExternalStore } from 'react';\nimport { useColorScheme } from 'react-native';\nimport { ada, spacing, fontSize, borderRadius } from '@ateam-ai-mobile/core';\nimport type { ThemeTokens } from './types';\n\ntype ThemeColors = ThemeTokens['colors'];\n\n// Ada palette mapped onto the plugin theme contract — mirrors the reference\n// app's useTheme.ts. Everything renders against warm paper; dark mode is on\n// the roadmap.\nconst adaColors: ThemeColors = {\n bg: ada.paper,\n surface: ada.paperSoft,\n surfaceAlt: ada.paperDeep,\n input: ada.paper,\n border: ada.border,\n text: ada.ink,\n textSecondary: ada.inkSoft,\n textMuted: ada.inkMuted,\n accent: ada.orange,\n accentSoft: ada.orangeSoft,\n success: '#5A8A5C',\n successSoft: 'rgba(90,138,92,0.14)',\n warning: '#D49A4E',\n warningSoft: 'rgba(212,154,78,0.16)',\n error: '#C15545',\n errorSoft: 'rgba(193,85,69,0.14)',\n purple: ada.orangeDeep,\n purpleSoft: ada.orangeSoft,\n};\n\nlet _colors: ThemeColors = adaColors;\n// null = host hasn't pinned it → track the device color scheme live\n// (parity with the reference app, whose isDark followed useColorScheme()).\nlet _isDark: boolean | null = null;\nconst _subscribers = new Set<() => void>();\n\n/** Override the plugin theme (host brand). Call once at startup — mounted\n * plugins re-render with the new tokens. */\nexport function setPluginThemeColors(colors: Partial<ThemeColors>, opts?: { isDark?: boolean }): void {\n _colors = { ...adaColors, ...colors };\n if (opts?.isDark !== undefined) _isDark = opts.isDark;\n _subscribers.forEach(fn => fn());\n}\n\nfunction subscribe(fn: () => void): () => void {\n _subscribers.add(fn);\n return () => { _subscribers.delete(fn); };\n}\n\nexport function usePluginTheme(): ThemeTokens {\n const colors = useSyncExternalStore(subscribe, () => _colors);\n const hostIsDark = useSyncExternalStore(subscribe, () => _isDark);\n const scheme = useColorScheme();\n const isDark = hostIsDark ?? scheme === 'dark';\n\n // Memoize so plugins don't re-render on every host render.\n return useMemo(() => ({\n colors,\n spacing: {\n xs: spacing.xs,\n sm: spacing.sm,\n md: spacing.md,\n lg: spacing.lg,\n xl: spacing.xl,\n xxl: spacing.xxl,\n },\n fontSize: {\n xs: fontSize.xs,\n sm: fontSize.sm,\n md: fontSize.md,\n lg: fontSize.lg,\n xl: fontSize.xl,\n },\n borderRadius: {\n sm: borderRadius.sm,\n md: borderRadius.md,\n lg: borderRadius.lg,\n full: borderRadius.full,\n },\n isDark,\n }), [colors, isDark]);\n}\n","/**\n * Simple plugin API — call any connector tool.\n *\n * Supports THREE usage patterns:\n *\n * // Pattern 1: Direct function call\n * const api = useApi(bridge);\n * const tasks = await api('task-board-mcp', 'tasks.list', {});\n *\n * // Pattern 2: .call(connector, tool, args) — connector first\n * const api = useApi(bridge);\n * const tasks = await api.call('memory-mcp', 'rules.list', {});\n *\n * // Pattern 3: .call(tool, args, connector) — connector last (rn-src plugins use this!)\n * const api = useApi(bridge);\n * const tasks = await api.call('memory.list', { type: 'rule' }, 'memory-mcp');\n *\n * All three work. The .call method auto-detects argument order.\n */\nimport { useMemo } from 'react';\nimport type { PluginBridge } from './types';\n\ninterface PluginApi {\n (connectorId: string, tool: string, args?: Record<string, any>): Promise<any>;\n call(connectorOrTool: string, toolOrArgs?: string | Record<string, any>, argsOrConnector?: Record<string, any> | string): Promise<any>;\n}\n\n/**\n * Create a simple API function to call connector tools.\n */\nexport function useApi(bridge: PluginBridge): PluginApi {\n return useMemo(() => {\n // Core implementation: (connectorId, tool, args) => Promise\n const apiFn = async (connectorId: string, tool: string, args: Record<string, any> = {}): Promise<any> => {\n if (!bridge) {\n throw new Error('useApi: bridge is required. Pass it from plugin props.');\n }\n return bridge.mcpCall(tool, args, connectorId);\n };\n\n // Add .call method that supports ALL THREE patterns:\n // api.call(connector, tool, args) — 2nd arg is string → connector first\n // api.call(tool, args, connector) — 3rd arg is string → connector last (rn-src pattern)\n // api.call(tool, args) — 2 args only → use bridge default connector\n const callMethod = async (\n first: string,\n second?: string | Record<string, any>,\n third?: Record<string, any> | string,\n ): Promise<any> => {\n if (!bridge) {\n throw new Error('useApi: bridge is required. Pass it from plugin props.');\n }\n\n if (typeof second === 'string') {\n // api.call(connector, tool, args) — 2nd arg is tool name string\n return bridge.mcpCall(second, (third as Record<string, any>) || {}, first);\n }\n\n if (typeof third === 'string') {\n // api.call(tool, args, connector) — 3rd arg is connector ID string\n return bridge.mcpCall(first, (second as Record<string, any>) || {}, third);\n }\n\n // api.call(tool, args) — no connector, use bridge default\n return bridge.mcpCall(first, (second as Record<string, any>) || {});\n };\n\n // Override .call on the function to be our custom method\n // (shadows Function.prototype.call intentionally)\n Object.defineProperty(apiFn, 'call', {\n value: callMethod,\n writable: false,\n configurable: false,\n });\n\n return apiFn as PluginApi;\n }, [bridge]);\n}\n","/**\n * SurfaceDrawer — generic bottom-sheet container for plugins.\n *\n * Plugins render their content; SurfaceDrawer provides the Ada chrome:\n * drag handle, header (orb + title + subtitle + optional privacy pill),\n * close button, motion, backdrop dismiss.\n *\n * Usage:\n * <SurfaceDrawer\n * visible={open}\n * onClose={() => setOpen(false)}\n * title=\"What I remember about you\"\n * subtitle=\"Only you can see this\"\n * privacy\n * >\n * <MyPluginContent />\n * </SurfaceDrawer>\n */\nimport { useEffect, useRef, type ReactNode } from 'react';\nimport {\n View,\n Text,\n Pressable,\n StyleSheet,\n Animated,\n Dimensions,\n Platform,\n} from 'react-native';\nimport Svg, { Path } from 'react-native-svg';\nimport { ada } from '@ateam-ai-mobile/core';\nimport AdaOrb from './AdaOrb';\n\nconst SCREEN_H = Dimensions.get('window').height;\nconst fontFam = Platform.OS === 'ios' ? 'SF Pro Rounded' : undefined;\n\nexport interface SurfaceDrawerProps {\n visible: boolean;\n onClose: () => void;\n title: string;\n subtitle?: string;\n /** Show the lock + \"Only you can see this\" privacy pill under the title */\n privacy?: boolean;\n /** Show the small Ada orb in the header (default: true) */\n showOrb?: boolean;\n /** Sheet height ratio of screen (default: 0.85) */\n heightRatio?: number;\n children: ReactNode;\n}\n\nexport default function SurfaceDrawer({\n visible,\n onClose,\n title,\n subtitle,\n privacy,\n showOrb = true,\n heightRatio = 0.85,\n children,\n}: SurfaceDrawerProps) {\n const sheetH = Math.round(SCREEN_H * heightRatio);\n const fadeAnim = useRef(new Animated.Value(0)).current;\n const slideAnim = useRef(new Animated.Value(sheetH)).current;\n\n useEffect(() => {\n if (visible) {\n Animated.parallel([\n Animated.timing(fadeAnim, { toValue: 1, duration: 220, useNativeDriver: true }),\n Animated.spring(slideAnim, { toValue: 0, useNativeDriver: true, tension: 80, friction: 12 }),\n ]).start();\n } else {\n fadeAnim.setValue(0);\n slideAnim.setValue(sheetH);\n }\n }, [visible]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const close = () => {\n Animated.parallel([\n Animated.timing(fadeAnim, { toValue: 0, duration: 160, useNativeDriver: true }),\n Animated.timing(slideAnim, { toValue: sheetH, duration: 200, useNativeDriver: true }),\n ]).start(() => onClose());\n };\n\n if (!visible) return null;\n\n return (\n <Animated.View style={[styles.overlay, { opacity: fadeAnim }]} pointerEvents=\"auto\">\n <Pressable style={StyleSheet.absoluteFill} onPress={close} />\n <Animated.View\n style={[\n styles.sheet,\n { height: sheetH, transform: [{ translateY: slideAnim }] },\n ]}\n >\n {/* Drag handle */}\n <View style={styles.handle} />\n\n {/* Header */}\n <View style={styles.header}>\n {showOrb ? (\n <View style={styles.headerOrb}>\n <AdaOrb size={36} state=\"idle\" />\n </View>\n ) : null}\n <View style={{ flex: 1 }}>\n <Text style={styles.title}>{title}</Text>\n {subtitle ? <Text style={styles.subtitle}>{subtitle}</Text> : null}\n {privacy ? (\n <View style={styles.privacyPill}>\n <Svg width={11} height={11} viewBox=\"0 0 24 24\" fill=\"none\" stroke={ada.inkSoft} strokeWidth={2.5} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n <Path d=\"M19 11H5a2 2 0 00-2 2v7a2 2 0 002 2h14a2 2 0 002-2v-7a2 2 0 00-2-2z\" />\n <Path d=\"M7 11V7a5 5 0 0110 0v4\" />\n </Svg>\n <Text style={styles.privacyText}>Only you can see this</Text>\n </View>\n ) : null}\n </View>\n <Pressable\n accessibilityRole=\"button\"\n accessibilityLabel=\"Close\"\n style={styles.closeBtn}\n onPress={close}\n hitSlop={12}\n >\n <Svg width={18} height={18} viewBox=\"0 0 24 24\" fill=\"none\" stroke={ada.inkSoft} strokeWidth={2.2} strokeLinecap=\"round\">\n <Path d=\"M18 6L6 18M6 6l12 12\" />\n </Svg>\n </Pressable>\n </View>\n\n {/* Body — caller renders content */}\n <View style={styles.body}>{children}</View>\n </Animated.View>\n </Animated.View>\n );\n}\n\nconst styles = StyleSheet.create({\n overlay: {\n position: 'absolute',\n top: 0, left: 0, right: 0, bottom: 0,\n backgroundColor: 'rgba(26, 20, 16, 0.35)',\n justifyContent: 'flex-end',\n zIndex: 999,\n elevation: 999,\n },\n sheet: {\n backgroundColor: ada.paper,\n borderTopLeftRadius: 28,\n borderTopRightRadius: 28,\n overflow: 'hidden',\n },\n handle: {\n width: 40,\n height: 4,\n borderRadius: 2,\n backgroundColor: ada.inkMuted,\n opacity: 0.3,\n alignSelf: 'center',\n marginTop: 10,\n marginBottom: 6,\n },\n header: {\n flexDirection: 'row',\n alignItems: 'center',\n paddingHorizontal: 22,\n paddingVertical: 16,\n gap: 12,\n borderBottomWidth: 1,\n borderBottomColor: ada.border,\n },\n headerOrb: {\n width: 36,\n height: 36,\n alignItems: 'center',\n justifyContent: 'center',\n },\n title: {\n fontSize: 17,\n fontWeight: '600',\n color: ada.ink,\n letterSpacing: -0.2,\n fontFamily: fontFam,\n },\n subtitle: {\n fontSize: 13,\n fontWeight: '400',\n color: ada.inkSoft,\n marginTop: 2,\n letterSpacing: -0.1,\n fontFamily: fontFam,\n },\n privacyPill: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: 5,\n marginTop: 4,\n },\n privacyText: {\n fontSize: 11,\n fontWeight: '500',\n color: ada.inkSoft,\n letterSpacing: 0.2,\n fontFamily: fontFam,\n },\n closeBtn: {\n width: 32,\n height: 32,\n borderRadius: 16,\n backgroundColor: ada.paperSoft,\n justifyContent: 'center',\n alignItems: 'center',\n },\n body: {\n flex: 1,\n },\n});\n","import { useEffect } from 'react';\nimport { View, StyleSheet } from 'react-native';\nimport Animated, {\n useSharedValue,\n useAnimatedProps,\n withRepeat,\n withTiming,\n withSequence,\n withDelay,\n Easing,\n cancelAnimation,\n} from 'react-native-reanimated';\nimport Svg, { Circle, Defs, RadialGradient, Stop, Text as SvgText } from 'react-native-svg';\n\nconst AnimatedCircle = Animated.createAnimatedComponent(Circle);\n\nexport type AdaOrbState = 'idle' | 'listening' | 'thinking' | 'speaking';\n\ninterface AdaOrbProps {\n size?: number;\n state?: AdaOrbState;\n /** Show the \"iA\" wordmark inside the orb. Suppressed below 60px because\n * glyphs become unreadable at avatar/chevron sizes — render as a plain\n * orb there. Default true. */\n inscription?: boolean;\n}\n\nexport default function AdaOrb({ size = 120, state = 'idle', inscription = true }: AdaOrbProps) {\n const showInscription = inscription && size >= 60;\n const center = size / 2;\n const coreR = size * 0.32;\n const innerHaloR = size * 0.42;\n const outerHaloR = size * 0.5;\n\n // Base breath layers\n const coreScale = useSharedValue(1);\n const innerScale = useSharedValue(1);\n const outerScale = useSharedValue(1);\n const outerOpacity = useSharedValue(0.55);\n\n // Listening: continuous ripple cycle (one shared value, phase-shifted reads)\n const rippleCycle = useSharedValue(0);\n\n // Thinking: 3 orbiting sparks at different speeds + directions\n const orbit1 = useSharedValue(0); // fast inner\n const orbit2 = useSharedValue(0); // medium mid\n const orbit3 = useSharedValue(0); // slow outer (counter)\n\n // Speaking: secondary fast double-beat overlay\n const beat = useSharedValue(1);\n\n useEffect(() => {\n cancelAnimation(coreScale);\n cancelAnimation(innerScale);\n cancelAnimation(outerScale);\n cancelAnimation(outerOpacity);\n cancelAnimation(rippleCycle);\n cancelAnimation(orbit1);\n cancelAnimation(orbit2);\n cancelAnimation(orbit3);\n cancelAnimation(beat);\n\n // Reset state-specific drivers\n rippleCycle.value = 0;\n orbit1.value = 0;\n orbit2.value = 0;\n orbit3.value = 0;\n beat.value = 1;\n\n let breathMs = 3600;\n let breathAmount = 0.025;\n\n if (state === 'listening') {\n breathMs = 2000;\n breathAmount = 0.05;\n // Continuous ripple loop — one cycle = one ripple lifetime\n rippleCycle.value = withRepeat(\n withTiming(1, { duration: 2000, easing: Easing.out(Easing.quad) }),\n -1,\n false,\n );\n } else if (state === 'thinking') {\n breathMs = 2400;\n breathAmount = 0.04;\n // Three sparks orbiting at different speeds + directions — feels like processing\n orbit1.value = withRepeat(\n withTiming(1, { duration: 1100, easing: Easing.linear }),\n -1,\n false,\n );\n orbit2.value = withRepeat(\n withTiming(1, { duration: 1900, easing: Easing.linear }),\n -1,\n false,\n );\n orbit3.value = withRepeat(\n withTiming(-1, { duration: 2700, easing: Easing.linear }),\n -1,\n false,\n );\n } else if (state === 'speaking') {\n breathMs = 700;\n breathAmount = 0.13;\n // Double-beat overlay — quick punch + secondary kick\n beat.value = withRepeat(\n withSequence(\n withTiming(1.08, { duration: 90, easing: Easing.out(Easing.quad) }),\n withTiming(1.0, { duration: 130, easing: Easing.in(Easing.quad) }),\n withTiming(1.05, { duration: 80, easing: Easing.out(Easing.quad) }),\n withTiming(1.0, { duration: 200, easing: Easing.in(Easing.quad) }),\n withTiming(1.0, { duration: 280 }),\n ),\n -1,\n false,\n );\n }\n\n // Base breath — different easing per state\n const breathEasing =\n state === 'speaking' ? Easing.out(Easing.cubic) : Easing.inOut(Easing.sin);\n\n coreScale.value = withRepeat(\n withSequence(\n withTiming(1 + breathAmount, { duration: breathMs, easing: breathEasing }),\n withTiming(1, { duration: breathMs, easing: breathEasing }),\n ),\n -1,\n false,\n );\n innerScale.value = withRepeat(\n withSequence(\n withTiming(1 + breathAmount * 1.4, { duration: breathMs * 1.15, easing: breathEasing }),\n withTiming(1, { duration: breathMs * 1.15, easing: breathEasing }),\n ),\n -1,\n false,\n );\n outerScale.value = withRepeat(\n withSequence(\n withTiming(1 + breathAmount * 1.8, { duration: breathMs * 1.3, easing: breathEasing }),\n withTiming(1, { duration: breathMs * 1.3, easing: breathEasing }),\n ),\n -1,\n false,\n );\n outerOpacity.value = withRepeat(\n withSequence(\n withTiming(state === 'idle' ? 0.55 : 0.8, { duration: breathMs * 1.3, easing: breathEasing }),\n withTiming(0.35, { duration: breathMs * 1.3, easing: breathEasing }),\n ),\n -1,\n false,\n );\n }, [state]);\n\n // Animated props for base layers — multiplied by `beat` so speaking double-pulse stacks\n const coreProps = useAnimatedProps(() => ({\n r: coreR * coreScale.value * beat.value,\n }));\n const innerProps = useAnimatedProps(() => ({\n r: innerHaloR * innerScale.value * beat.value,\n }));\n const outerProps = useAnimatedProps(() => ({\n r: outerHaloR * outerScale.value,\n opacity: outerOpacity.value,\n }));\n\n // Listening ripples — three phase-shifted reads of rippleCycle\n const ripple1Props = useAnimatedProps(() => {\n const t = rippleCycle.value;\n return {\n r: outerHaloR * (1 + t * 0.55),\n opacity: state === 'listening' ? 0.55 * (1 - t) : 0,\n };\n });\n const ripple2Props = useAnimatedProps(() => {\n const t = (rippleCycle.value + 0.34) % 1;\n return {\n r: outerHaloR * (1 + t * 0.55),\n opacity: state === 'listening' ? 0.45 * (1 - t) : 0,\n };\n });\n const ripple3Props = useAnimatedProps(() => {\n const t = (rippleCycle.value + 0.67) % 1;\n return {\n r: outerHaloR * (1 + t * 0.55),\n opacity: state === 'listening' ? 0.35 * (1 - t) : 0,\n };\n });\n\n // Thinking sparks — three at different radii and angular velocities\n const spark1Props = useAnimatedProps(() => {\n const angle = orbit1.value * Math.PI * 2 - Math.PI / 2;\n const r = coreR * 0.55;\n return {\n cx: center + Math.cos(angle) * r,\n cy: center + Math.sin(angle) * r,\n opacity: state === 'thinking' ? 1 : 0,\n };\n });\n const spark2Props = useAnimatedProps(() => {\n const angle = orbit2.value * Math.PI * 2 + Math.PI * 0.6;\n const r = coreR * 0.85;\n return {\n cx: center + Math.cos(angle) * r,\n cy: center + Math.sin(angle) * r,\n opacity: state === 'thinking' ? 0.9 : 0,\n };\n });\n const spark3Props = useAnimatedProps(() => {\n const angle = orbit3.value * Math.PI * 2 + Math.PI * 1.3;\n const r = coreR * 1.05;\n return {\n cx: center + Math.cos(angle) * r,\n cy: center + Math.sin(angle) * r,\n opacity: state === 'thinking' ? 0.7 : 0,\n };\n });\n\n return (\n <View style={[styles.wrap, { width: size, height: size }]}>\n <Svg width={size} height={size}>\n <Defs>\n <RadialGradient id=\"adaCore\" cx=\"36%\" cy=\"30%\" r=\"70%\">\n <Stop offset=\"0%\" stopColor=\"#FFE0B0\" stopOpacity=\"1\" />\n <Stop offset=\"28%\" stopColor=\"#FFA85A\" stopOpacity=\"1\" />\n <Stop offset=\"65%\" stopColor=\"#FF7A28\" stopOpacity=\"1\" />\n <Stop offset=\"100%\" stopColor=\"#B8410A\" stopOpacity=\"1\" />\n </RadialGradient>\n <RadialGradient id=\"adaInner\" cx=\"50%\" cy=\"50%\" r=\"50%\">\n <Stop offset=\"0%\" stopColor=\"#FF8A3C\" stopOpacity=\"0.55\" />\n <Stop offset=\"100%\" stopColor=\"#FF7028\" stopOpacity=\"0\" />\n </RadialGradient>\n <RadialGradient id=\"adaOuter\" cx=\"50%\" cy=\"50%\" r=\"50%\">\n <Stop offset=\"0%\" stopColor=\"#FF7A28\" stopOpacity=\"0.4\" />\n <Stop offset=\"100%\" stopColor=\"#FF6018\" stopOpacity=\"0\" />\n </RadialGradient>\n <RadialGradient id=\"adaSpark\" cx=\"50%\" cy=\"50%\" r=\"50%\">\n <Stop offset=\"0%\" stopColor=\"#FFFAEB\" stopOpacity=\"1\" />\n <Stop offset=\"60%\" stopColor=\"#FFD095\" stopOpacity=\"0.9\" />\n <Stop offset=\"100%\" stopColor=\"#FFA85A\" stopOpacity=\"0\" />\n </RadialGradient>\n </Defs>\n\n {/* Listening ripples — drawn behind orb body */}\n <AnimatedCircle\n cx={center}\n cy={center}\n stroke=\"#FF7A28\"\n strokeWidth={1.5}\n fill=\"none\"\n animatedProps={ripple1Props}\n />\n <AnimatedCircle\n cx={center}\n cy={center}\n stroke=\"#FF7A28\"\n strokeWidth={1.5}\n fill=\"none\"\n animatedProps={ripple2Props}\n />\n <AnimatedCircle\n cx={center}\n cy={center}\n stroke=\"#FF7A28\"\n strokeWidth={1.5}\n fill=\"none\"\n animatedProps={ripple3Props}\n />\n\n {/* Base orb body */}\n <AnimatedCircle cx={center} cy={center} fill=\"url(#adaOuter)\" animatedProps={outerProps} />\n <AnimatedCircle cx={center} cy={center} fill=\"url(#adaInner)\" animatedProps={innerProps} />\n <AnimatedCircle cx={center} cy={center} fill=\"url(#adaCore)\" animatedProps={coreProps} />\n\n {/* Thinking sparks — three orbiting particles drawn on top */}\n <AnimatedCircle\n r={Math.max(3, size * 0.05)}\n fill=\"url(#adaSpark)\"\n animatedProps={spark1Props}\n />\n <AnimatedCircle\n r={Math.max(2.5, size * 0.04)}\n fill=\"url(#adaSpark)\"\n animatedProps={spark2Props}\n />\n <AnimatedCircle\n r={Math.max(2, size * 0.032)}\n fill=\"url(#adaSpark)\"\n animatedProps={spark3Props}\n />\n\n {/* \"iA\" wordmark — matches the app icon. Suppressed at small sizes\n where the glyphs would be unreadable (see showInscription). */}\n {showInscription && (\n <SvgText\n x={center}\n y={center + size * 0.11}\n fontSize={size * 0.34}\n fontWeight=\"600\"\n fill=\"#FFF5E0\"\n textAnchor=\"middle\"\n letterSpacing={-size * 0.005}\n >\n iA\n </SvgText>\n )}\n </Svg>\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n wrap: {\n alignItems: 'center',\n justifyContent: 'center',\n },\n});\n","/**\n * SurfaceCard — a tappable tile shape for plugins that surface as cards\n * (empty-state suggestions, dashboards, daily-brief items).\n *\n * Plugins declare icon + title + subtitle + onPress; the host provides\n * the warm Ada chrome (paper-soft bg, soft border, arrow chevron, haptic).\n *\n * Optional `children` render below the title block for richer previews\n * (e.g. small ring widget, last-meal photo, current weather).\n *\n * Usage:\n * <SurfaceCard\n * icon=\"🥗\"\n * title=\"Today's plate\"\n * subtitle=\"2,100 kcal · 140g protein\"\n * onPress={() => sendPrompt('Tell me about my nutrition today')}\n * />\n */\nimport { type ReactNode } from 'react';\nimport {\n View,\n Text,\n Pressable,\n StyleSheet,\n Platform,\n} from 'react-native';\nimport { getHaptics } from '../host';\nimport { ada, borderRadius } from '@ateam-ai-mobile/core';\n\nconst fontFam = Platform.OS === 'ios' ? 'SF Pro Rounded' : undefined;\n\nexport interface SurfaceCardProps {\n /** Emoji or short string icon shown on the left */\n icon?: string;\n /** Card headline (e.g. \"Today's plate\") */\n title: string;\n /** Optional secondary line below title */\n subtitle?: string;\n /** Tap handler. Fires haptic before invoking. */\n onPress?: () => void;\n /** Long-press handler. Fires a heavier haptic. Used by user widgets for\n * the Delete / (later) Hide / Rename context menu. */\n onLongPress?: () => void;\n /** Whether to show the ›-style trailing arrow (default: true if onPress) */\n showArrow?: boolean;\n /** Optional preview content rendered below the title block */\n children?: ReactNode;\n}\n\nexport default function SurfaceCard({\n icon,\n title,\n subtitle,\n onPress,\n onLongPress,\n showArrow,\n children,\n}: SurfaceCardProps) {\n const arrow = showArrow ?? !!onPress;\n const handlePress = () => {\n if (!onPress) return;\n getHaptics()?.impact('light');\n onPress();\n };\n const handleLongPress = () => {\n if (!onLongPress) return;\n getHaptics()?.impact('medium');\n onLongPress();\n };\n\n return (\n <Pressable\n accessibilityRole=\"button\"\n accessibilityLabel={[icon, title, subtitle].filter(Boolean).join(', ')}\n accessibilityHint={onLongPress ? 'Long-press for more options' : undefined}\n style={styles.card}\n onPress={onPress ? handlePress : undefined}\n onLongPress={onLongPress ? handleLongPress : undefined}\n disabled={!onPress && !onLongPress}\n >\n <View style={styles.row}>\n {icon ? <Text style={styles.icon}>{icon}</Text> : null}\n <View style={{ flex: 1 }}>\n <Text style={styles.title}>{title}</Text>\n {subtitle ? <Text style={styles.subtitle}>{subtitle}</Text> : null}\n </View>\n {arrow ? <Text style={styles.arrow}>{'\\u2192'}</Text> : null}\n </View>\n {children ? <View style={styles.body}>{children}</View> : null}\n </Pressable>\n );\n}\n\nconst styles = StyleSheet.create({\n card: {\n backgroundColor: ada.paperSoft,\n borderWidth: 1,\n borderColor: ada.border,\n borderRadius: borderRadius.xl,\n paddingHorizontal: 16,\n paddingVertical: 14,\n },\n row: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: 14,\n },\n icon: {\n fontSize: 22,\n },\n title: {\n fontSize: 15,\n fontWeight: '600',\n color: ada.ink,\n letterSpacing: -0.2,\n fontFamily: fontFam,\n },\n subtitle: {\n fontSize: 13,\n fontWeight: '400',\n color: ada.inkMuted,\n marginTop: 2,\n letterSpacing: -0.1,\n fontFamily: fontFam,\n },\n arrow: {\n fontSize: 18,\n color: ada.inkMuted,\n fontWeight: '400',\n },\n body: {\n marginTop: 10,\n paddingTop: 10,\n borderTopWidth: 1,\n borderTopColor: ada.border,\n },\n});\n","/**\n * SurfaceFullscreen — edge-to-edge takeover container for plugins\n * (voice mode, focus modes, photo capture, etc.).\n *\n * Plugins render their content; SurfaceFullscreen provides:\n * - Paper background, fade-in motion\n * - Top status line (\"ada\" wordmark + status text)\n * - Optional hero element above body (e.g. AdaOrb)\n * - Bottom close button with label\n * - Spring entry on the hero (scale 0.6 → 1)\n *\n * Usage:\n * <SurfaceFullscreen\n * visible={open}\n * onClose={hangUp}\n * status=\"Ada is speaking\"\n * hero={<AdaOrb size={180} state=\"speaking\" />}\n * closeIcon=\"hangup\"\n * closeLabel=\"End\"\n * >\n * <Transcript ... />\n * </SurfaceFullscreen>\n */\nimport { useEffect, useRef, type ReactNode } from 'react';\nimport {\n View,\n Text,\n Pressable,\n StyleSheet,\n Animated,\n Platform,\n} from 'react-native';\nimport Svg, { Path } from 'react-native-svg';\nimport { ada } from '@ateam-ai-mobile/core';\n\nconst fontFam = Platform.OS === 'ios' ? 'SF Pro Rounded' : undefined;\n\nexport interface SurfaceFullscreenProps {\n visible: boolean;\n onClose: () => void;\n /** Status text shown under the wordmark */\n status?: string;\n /** Optional hero element above body (typically an AdaOrb) */\n hero?: ReactNode;\n /** Body content */\n children?: ReactNode;\n /** Whether to show the small \"ada\" wordmark (default: true) */\n showWordmark?: boolean;\n /** Built-in close icon flavor or a custom node. Default: 'x' */\n closeIcon?: 'x' | 'hangup' | ReactNode;\n /** Label under the close button (default: \"Close\") */\n closeLabel?: string;\n}\n\nexport default function SurfaceFullscreen({\n visible,\n onClose,\n status,\n hero,\n children,\n showWordmark = true,\n closeIcon = 'x',\n closeLabel = 'Close',\n}: SurfaceFullscreenProps) {\n const fadeAnim = useRef(new Animated.Value(0)).current;\n const heroScale = useRef(new Animated.Value(0.6)).current;\n\n useEffect(() => {\n if (visible) {\n Animated.parallel([\n Animated.timing(fadeAnim, { toValue: 1, duration: 280, useNativeDriver: true }),\n Animated.spring(heroScale, { toValue: 1, useNativeDriver: true, tension: 60, friction: 11 }),\n ]).start();\n } else {\n fadeAnim.setValue(0);\n heroScale.setValue(0.6);\n }\n }, [visible]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const close = () => {\n Animated.parallel([\n Animated.timing(fadeAnim, { toValue: 0, duration: 180, useNativeDriver: true }),\n Animated.timing(heroScale, { toValue: 0.6, duration: 180, useNativeDriver: true }),\n ]).start(() => onClose());\n };\n\n if (!visible) return null;\n\n const renderCloseIcon = () => {\n if (closeIcon === 'hangup') {\n return (\n <Svg width={22} height={22} viewBox=\"0 0 24 24\" fill={ada.paper}>\n <Path d=\"M3.68 16.07l3.92-3.11c.28-.23.68-.28 1.01-.14l2.77 1.15c.36.15.61.5.61.89v2.82c4.34-.76 7.93-4.35 8.69-8.69h-2.82c-.39 0-.74-.25-.89-.61L16.12 5.6c-.13-.33-.09-.73.14-1.01l3.11-3.92c.29-.37.81-.41 1.15-.08l3.24 3.24c.2.2.31.47.31.76C24 14.44 14.44 24 4.59 24c-.29 0-.56-.11-.76-.31L.59 20.45c-.33-.34-.29-.86.09-1.15z\" />\n </Svg>\n );\n }\n if (closeIcon === 'x') {\n return (\n <Svg width={20} height={20} viewBox=\"0 0 24 24\" fill=\"none\" stroke={ada.paper} strokeWidth={2.5} strokeLinecap=\"round\">\n <Path d=\"M18 6L6 18M6 6l12 12\" />\n </Svg>\n );\n }\n return closeIcon;\n };\n\n return (\n <Animated.View style={[styles.overlay, { opacity: fadeAnim }]} pointerEvents=\"auto\">\n {/* Top status */}\n <View style={styles.topBar}>\n {showWordmark ? <Text style={styles.wordmark}>ada</Text> : null}\n {status ? <Text style={styles.status}>{status}</Text> : null}\n </View>\n\n {/* Optional hero (e.g. AdaOrb) — springs in */}\n {hero ? (\n <View style={styles.heroWrap}>\n <Animated.View style={{ transform: [{ scale: heroScale }] }}>\n {hero}\n </Animated.View>\n </View>\n ) : null}\n\n {/* Body — caller content */}\n <View style={styles.body}>{children}</View>\n\n {/* Bottom close */}\n <View style={styles.bottomBar}>\n <Pressable\n accessibilityRole=\"button\"\n accessibilityLabel={closeLabel}\n style={styles.closeBtn}\n onPress={close}\n hitSlop={12}\n >\n {renderCloseIcon()}\n </Pressable>\n {closeLabel ? <Text style={styles.closeLabel}>{closeLabel}</Text> : null}\n </View>\n </Animated.View>\n );\n}\n\nconst styles = StyleSheet.create({\n overlay: {\n position: 'absolute',\n top: 0, left: 0, right: 0, bottom: 0,\n backgroundColor: ada.paper,\n zIndex: 1000,\n elevation: 1000,\n },\n topBar: {\n paddingTop: Platform.OS === 'ios' ? 64 : 36,\n paddingHorizontal: 24,\n alignItems: 'center',\n gap: 6,\n },\n wordmark: {\n fontSize: 14,\n fontFamily: fontFam,\n fontWeight: '500',\n color: ada.inkMuted,\n letterSpacing: 4,\n },\n status: {\n fontSize: 17,\n fontFamily: fontFam,\n fontWeight: '500',\n color: ada.ink,\n letterSpacing: -0.2,\n },\n heroWrap: {\n paddingTop: 24,\n paddingBottom: 12,\n alignItems: 'center',\n justifyContent: 'center',\n },\n body: {\n flex: 1,\n },\n bottomBar: {\n paddingBottom: Platform.OS === 'ios' ? 48 : 32,\n paddingTop: 12,\n alignItems: 'center',\n gap: 8,\n },\n closeBtn: {\n width: 64,\n height: 64,\n borderRadius: 32,\n backgroundColor: ada.ink,\n justifyContent: 'center',\n alignItems: 'center',\n shadowColor: ada.ink,\n shadowOffset: { width: 0, height: 8 },\n shadowOpacity: 0.18,\n shadowRadius: 14,\n elevation: 8,\n },\n closeLabel: {\n fontSize: 13,\n fontFamily: fontFam,\n fontWeight: '500',\n color: ada.inkMuted,\n letterSpacing: 0.3,\n },\n});\n","/**\n * Surface registry + active-state store.\n *\n * - `manifests`: map of registered surface plugins\n * - `activeDrawer` / `activeFullscreen`: which surface (if any) is currently mounted\n * (only one of each at a time)\n *\n * Plugins are registered by calling `register(...)` from bootstrap or by an\n * \"engine\" event. The dispatcher subscribes to active state and mounts.\n */\nimport { create } from 'zustand';\nimport type {\n SurfaceManifest,\n SurfaceType,\n SurfaceVisibility,\n SurfacePlacement,\n InlineSurfaceManifest,\n MountSurfaceManifest,\n} from './types';\n\ninterface SurfaceState {\n manifests: Record<string, SurfaceManifest>;\n activeDrawer: string | null;\n activeFullscreen: string | null;\n /** Props passed by the engine when summoning a surface via sys.focusUiPlugin.\n * Keyed by surface id; cleared on hide. Plugins read these on first mount. */\n activeProps: Record<string, any>;\n /** Increments on every `show()` call. Used as a React `key` so the Surface\n * Component remounts even if the same surface is shown again — guarantees\n * the plugin's data-fetching effects re-run, so the user always sees fresh\n * data when they open a drawer. */\n mountKey: number;\n\n register: (manifest: SurfaceManifest) => void;\n unregister: (id: string) => void;\n\n /** Open a surface in its declared container. Props (optional) are forwarded\n * to the mounted plugin on first render. */\n show: (id: string, props?: any) => void;\n /** Close the surface with the given id (or whatever is active for the matching type) */\n hide: (id?: string) => void;\n\n /** All registered manifests, optionally filtered.\n * `placement: 'unset'` selects only plugins WITHOUT a placement (default list). */\n list: (filter?: {\n type?: SurfaceType;\n visibility?: SurfaceVisibility[];\n placement?: SurfacePlacement | 'unset';\n }) => SurfaceManifest[];\n}\n\nexport const useSurfaceStore = create<SurfaceState>((set, get) => ({\n manifests: {},\n activeDrawer: null,\n activeFullscreen: null,\n activeProps: {},\n mountKey: 0,\n\n register: (manifest) =>\n set(s => ({ manifests: { ...s.manifests, [manifest.id]: manifest } })),\n\n unregister: (id) =>\n set(s => {\n const next = { ...s.manifests };\n delete next[id];\n const nextProps = { ...s.activeProps };\n delete nextProps[id];\n return { manifests: next, activeProps: nextProps };\n }),\n\n show: (id, props) => {\n const m = get().manifests[id];\n if (!m) {\n console.warn('[SurfaceStore] show: unknown surface id', id);\n return;\n }\n set(s => {\n const nextProps = props !== undefined\n ? { ...s.activeProps, [id]: props }\n : s.activeProps;\n // Bump mountKey on every show so the dispatcher remounts the Component,\n // forcing the plugin's data fetch to re-run with fresh results.\n const mountKey = s.mountKey + 1;\n if (m.type === 'drawer') return { activeDrawer: id, activeProps: nextProps, mountKey };\n if (m.type === 'fullscreen') return { activeFullscreen: id, activeProps: nextProps, mountKey };\n return { mountKey };\n });\n },\n\n hide: (id) => {\n const s = get();\n if (!id) {\n // Hide whichever is active and clear their props\n const cleanup = { ...s.activeProps };\n if (s.activeDrawer) delete cleanup[s.activeDrawer];\n if (s.activeFullscreen) delete cleanup[s.activeFullscreen];\n set({ activeDrawer: null, activeFullscreen: null, activeProps: cleanup });\n return;\n }\n const cleanup = { ...s.activeProps };\n delete cleanup[id];\n const patch: Partial<SurfaceState> = { activeProps: cleanup };\n if (s.activeDrawer === id) patch.activeDrawer = null;\n if (s.activeFullscreen === id) patch.activeFullscreen = null;\n set(patch);\n },\n\n list: (filter) => {\n const all = Object.values(get().manifests);\n return all.filter(m => {\n if (filter?.type && m.type !== filter.type) return false;\n if (filter?.visibility && !filter.visibility.includes(m.visibility)) return false;\n if (filter?.placement) {\n if (filter.placement === 'unset') {\n if (m.placement) return false;\n } else if (m.placement !== filter.placement) {\n return false;\n }\n }\n return true;\n });\n },\n}));\n\n// Convenience guards\nexport function isMountSurface(m: SurfaceManifest): m is MountSurfaceManifest {\n return m.type === 'drawer' || m.type === 'fullscreen';\n}\nexport function isInlineSurface(m: SurfaceManifest): m is InlineSurfaceManifest {\n return m.type === 'card' || m.type === 'header' || m.type === 'ambient' || m.type === 'nudge';\n}\n","/**\n * SurfaceDispatcher — mounted once at the app root.\n *\n * Watches the surface store and:\n * - Mounts the active drawer surface (max one at a time)\n * - Mounts the active fullscreen surface (max one at a time)\n *\n * The mounted Component receives `dismiss` to close itself; the dispatcher\n * clears active-state after dismiss.\n *\n * Inline surfaces (card / header / ambient / nudge) are NOT rendered by the\n * dispatcher — they're queried via `useSurfaceStore().list({ type: 'card' })`\n * and rendered inline by the host screen that owns that placement.\n */\nimport { useEffect } from 'react';\nimport { useSurfaceStore } from './store';\nimport { pluginCommandEmitter } from '@ateam-ai-mobile/core';\n\nexport default function SurfaceDispatcher() {\n const manifests = useSurfaceStore(s => s.manifests);\n const activeDrawer = useSurfaceStore(s => s.activeDrawer);\n const activeFullscreen = useSurfaceStore(s => s.activeFullscreen);\n const activeProps = useSurfaceStore(s => s.activeProps);\n const mountKey = useSurfaceStore(s => s.mountKey);\n const hide = useSurfaceStore(s => s.hide);\n\n // bridge.close() inside a plugin emits a global `plugin-close` event.\n // The legacy plugins overlay listens for this; we mirror that here so\n // surface-mounted plugins (auth-webview, etc.) actually dismiss themselves.\n useEffect(() => {\n const unsub = pluginCommandEmitter.on('plugin-close', ({ pluginId }: { pluginId?: string } = {}) => {\n if (!pluginId) return;\n const s = useSurfaceStore.getState();\n if (s.activeDrawer === pluginId || s.activeFullscreen === pluginId) {\n s.hide(pluginId);\n }\n });\n return unsub;\n }, []);\n\n const drawer = activeDrawer ? manifests[activeDrawer] : null;\n const fullscreen = activeFullscreen ? manifests[activeFullscreen] : null;\n const drawerProps = activeDrawer ? activeProps[activeDrawer] : undefined;\n const fullscreenProps = activeFullscreen ? activeProps[activeFullscreen] : undefined;\n\n // mountKey changes on every show() so React remounts the Component → the\n // plugin's data-fetching useEffects re-run → user sees fresh data each open.\n return (\n <>\n {drawer && drawer.type === 'drawer' && drawer.Component ? (\n <drawer.Component\n key={`drawer-${drawer.id}-${mountKey}`}\n dismiss={() => hide(drawer.id)}\n props={drawerProps}\n />\n ) : null}\n {fullscreen && fullscreen.type === 'fullscreen' && fullscreen.Component ? (\n <fullscreen.Component\n key={`fullscreen-${fullscreen.id}-${mountKey}`}\n dismiss={() => hide(fullscreen.id)}\n props={fullscreenProps}\n />\n ) : null}\n </>\n );\n}\n","/**\n * The SDK's module names, as a remote bundle sees them.\n *\n * A bundle keeps its SDK external, and the require shim (bundleManager) answers\n * exactly ONE SDK name: '@adas/plugin-sdk'. The same code is published to npm as\n * '@ateam-ai-mobile/plugin-runtime' — but that is the HOST app's dependency, and\n * inside a bundle it resolves to nothing.\n *\n * Until MGAP-C2 (2026-09-27) the shim answered that name the way it answers any\n * unknown module: a console warning and `{}`. So a bundle doing\n * `import { CameraPreview } from '@ateam-ai-mobile/plugin-runtime'` evaluated\n * cleanly, got `undefined`, and crashed on first render as \"undefined is not a\n * component\" — nowhere near the import that caused it. The app's in-app\n * reference HUD imports it that way (it is host code, compiled with the app, so\n * the name resolves there), and that is where an agent copied it from.\n *\n * So the SDK's own namespaces fail BY NAME at evaluation:\n * - '@ateam-ai-mobile/*' — the host's packages, never a bundle's.\n * - '@adas/*' other than '@adas/plugin-sdk' — the SDK's own docs once told\n * plugin authors to import '@adas/device-state' (sdk/device-state.ts header,\n * 4110943), a name the shim never resolved. There is one SDK module name.\n * Neither is aliased to '@adas/plugin-sdk': two names for one SDK is a second\n * source of truth, and that is what this closes (CORE's call). The shim checks\n * them BEFORE the host's module registry, so no host registration can alias one\n * either.\n *\n * Every OTHER unknown module keeps the warning and `{}`. What exists there is\n * the host's decision, not the SDK's — each host registers its own set\n * (@ateam-ai-mobile/expo adds expo-web-browser and expo-linking, the reference\n * app adds react-native-webview) — and a bundle built for one host may keep\n * such a module external and only use it on a path another host never takes.\n * Failing those at evaluation would break already-deployed bundles we have no\n * inventory of, and there is no single right name to point the author at.\n */\n\n/** The one SDK module name a bundle can require (values and types alike). */\nexport const PLUGIN_SDK_MODULE = '@adas/plugin-sdk';\n\n/**\n * The by-name refusal for a require of an SDK-namespace name the shim will\n * never satisfy, or null when the name is the SDK itself or not the SDK's.\n */\nexport function sdkModuleRefusal(name: string): string | null {\n if (name === PLUGIN_SDK_MODULE) return null;\n if (!name.startsWith('@ateam-ai-mobile/') && !name.startsWith('@adas/')) return null;\n return (\n `a plugin bundle required '${name}', which does not exist inside a bundle. ` +\n `Import from '${PLUGIN_SDK_MODULE}' instead — it is the only SDK module a bundle can require ` +\n `(values and types alike), and the one to keep external when building. ` +\n `'@ateam-ai-mobile/*' are the host app's packages, not the plugin's.`\n );\n}\n","/**\n * Pure-JS SHA-256 — used to verify integrity of downloaded plugin bundles.\n * Avoids pulling expo-crypto / a native module into the dependency graph for\n * what amounts to a one-shot post-download check.\n *\n * Hot path: hash a ~100KB-1MB bundle once after download. Performance is\n * acceptable on every supported device (sub-50ms).\n *\n * Algorithm reference: FIPS 180-4. Implementation derived from the public-\n * domain reference code; see https://en.wikipedia.org/wiki/SHA-2#Pseudocode.\n */\n\nconst K = new Uint32Array([\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\n 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\n 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\n 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\n 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\n]);\n\nconst rotr = (n: number, x: number) => (x >>> n) | (x << (32 - n));\n\n/** SHA-256 of a UTF-8 string. Returns the lowercase hex digest. */\nexport function sha256Hex(message: string): string {\n // 1. Encode to UTF-8 bytes\n const utf8 = unescape(encodeURIComponent(message));\n const bytes = new Uint8Array(utf8.length);\n for (let i = 0; i < utf8.length; i++) bytes[i] = utf8.charCodeAt(i);\n\n // 2. Pre-processing: append 0x80, pad with zeros, then append 64-bit big-endian length\n const bitLen = bytes.length * 8;\n const padLen = (56 - (bytes.length + 1) % 64 + 64) % 64;\n const buf = new Uint8Array(bytes.length + 1 + padLen + 8);\n buf.set(bytes);\n buf[bytes.length] = 0x80;\n // 64-bit big-endian length (high 32 bits zeroed — bundles are well under 2^32 bits)\n const len = buf.length;\n buf[len - 4] = (bitLen >>> 24) & 0xff;\n buf[len - 3] = (bitLen >>> 16) & 0xff;\n buf[len - 2] = (bitLen >>> 8) & 0xff;\n buf[len - 1] = bitLen & 0xff;\n\n const h = new Uint32Array([\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,\n 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,\n ]);\n const w = new Uint32Array(64);\n\n // 3. Process each 512-bit chunk\n for (let i = 0; i < buf.length; i += 64) {\n for (let t = 0; t < 16; t++) {\n const j = i + t * 4;\n w[t] = (buf[j] << 24) | (buf[j + 1] << 16) | (buf[j + 2] << 8) | buf[j + 3];\n }\n for (let t = 16; t < 64; t++) {\n const s0 = rotr(7, w[t - 15]) ^ rotr(18, w[t - 15]) ^ (w[t - 15] >>> 3);\n const s1 = rotr(17, w[t - 2]) ^ rotr(19, w[t - 2]) ^ (w[t - 2] >>> 10);\n w[t] = (w[t - 16] + s0 + w[t - 7] + s1) | 0;\n }\n\n let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], hh = h[7];\n for (let t = 0; t < 64; t++) {\n const S1 = rotr(6, e) ^ rotr(11, e) ^ rotr(25, e);\n const ch = (e & f) ^ (~e & g);\n const temp1 = (hh + S1 + ch + K[t] + w[t]) | 0;\n const S0 = rotr(2, a) ^ rotr(13, a) ^ rotr(22, a);\n const maj = (a & b) ^ (a & c) ^ (b & c);\n const temp2 = (S0 + maj) | 0;\n hh = g; g = f; f = e; e = (d + temp1) | 0; d = c; c = b; b = a; a = (temp1 + temp2) | 0;\n }\n\n h[0] = (h[0] + a) | 0; h[1] = (h[1] + b) | 0; h[2] = (h[2] + c) | 0; h[3] = (h[3] + d) | 0;\n h[4] = (h[4] + e) | 0; h[5] = (h[5] + f) | 0; h[6] = (h[6] + g) | 0; h[7] = (h[7] + hh) | 0;\n }\n\n // 4. Produce hex\n let out = '';\n for (let i = 0; i < 8; i++) {\n out += h[i].toString(16).padStart(8, '0');\n }\n return out;\n}\n","/**\n * R8 remote-bundle integrity — the fail-closed check run INLINE, immediately\n * before a remote bundle is evaluated with `new Function`.\n *\n * See docs/decisions/REMOTE_BUNDLE_INTEGRITY.md for the threat model and the\n * (declined) publisher-signature decision. This is INTEGRITY, not a sandbox:\n * it proves the bytes about to run are exactly the ones the trusted manifest\n * hash names; it does not isolate what they can do.\n */\nimport { sha256Hex } from '../utils/sha256';\n\n/**\n * Refuse to evaluate a bundle whose bytes do not match the SHA-256 that\n * gate-kept them. Fail-closed on a MISSING hash too — an unverifiable bundle is\n * treated exactly like a mismatched one. `verifiedHash` is the manifest hash for\n * a cache hit or the freshly-verified download hash; re-hashing `content` here\n * closes the disk-cache-tamper gap the download-time check leaves open.\n */\nexport function assertBundleIntegrity(content: string, verifiedHash: string | null, label: string): void {\n const digest = sha256Hex(content);\n if (!verifiedHash) {\n throw new Error(`[bundle-integrity] refusing to evaluate ${label}: no verified SHA-256 (fail closed).`);\n }\n if (digest !== verifiedHash.toLowerCase()) {\n throw new Error(\n `[bundle-integrity] integrity FAIL at eval for ${label}: content sha256 ${digest.slice(0, 12)}… ≠ verified ${verifiedHash.slice(0, 12)}…. Refusing to evaluate.`,\n );\n }\n}\n","/**\n * Bundle disk-cache adapter. The bundle manager persists downloaded plugin\n * bundles through this interface so the package stays free of Expo/RN\n * storage imports. @ateam-ai-mobile/expo ships a file-system implementation; the\n * default is in-memory (bundles re-download per app session — correct,\n * just slower on cold start).\n */\nimport type { PluginGrants } from '../pluginRuntime';\nimport { pluginBundleUrl, isPluginBundleUrl } from './bundleUrl';\n\nexport interface BundleCacheEntry {\n localPath: string;\n version: string;\n timestamp: number;\n bundleUrl: string;\n /** SHA-256 (hex, lowercase) of the cached bundle bytes — integrity proof */\n bundleHash?: string;\n /**\n * Tenant whose session downloaded these bytes.\n *\n * A bundle URL is NOT tenant-independent: `/api/ui-plugins/<id>/bundle.js`\n * resolves per-tenant on the server, so the SAME url returns different code\n * for different tenants. On the normal load path the hash gate catches this\n * for free — the expected hash comes from the current tenant's manifest and\n * will not match another tenant's cached bytes. The disk-cache recovery path\n * has no manifest to check against, so it must discriminate by tenant.\n *\n * Absent on entries written before this field existed: unknown ownership, so\n * untrusted. Never read a missing tenant as \"mine\".\n */\n tenant?: string;\n /**\n * The trusted declaration these bytes' device tools were last registered\n * under: the pluginId and grants resolved from the server manifest that named\n * this bundle (resolvePluginGrants). Recorded so the disk-cache recovery path —\n * which runs exactly when there is NO manifest — re-registers with the same\n * authority instead of the bundle's own claim.\n *\n * Absent → no trusted declaration is known for these bytes, so recovery skips\n * the entry (fail closed) and the catalog path registers it once the owning\n * connector answers again.\n */\n trusted?: TrustedToolDeclaration;\n}\n\n/** Who a bundle's device tools belong to and what they are granted — always\n * from the manifest, never from the bundle. */\nexport interface TrustedToolDeclaration extends PluginGrants {\n pluginId: string;\n}\n\n/**\n * Which cached entries belong to `tenant` and may therefore be re-evaluated.\n *\n * Lives here, beside the entry type, so \"may I run this cached code\" has ONE\n * owner rather than being re-answered by each caller. `loadIndex()` returns\n * every entry regardless of owner — it has to, since the manager looks entries\n * up by url and rewrites them — so any caller that EVALUATES cached code must\n * come through this function first.\n *\n * Fail-closed on both unknowns. An empty tenant owns nothing. An entry with no\n * recorded tenant has unknown ownership and is never assumed to be the current\n * one: every device already in the field has unstamped entries, so reading\n * \"missing\" as \"mine\" would keep the hole open exactly where it is hardest to\n * see.\n *\n * Compares the tenant field directly — it never builds a composite key, so\n * there is no separator a tenant name could forge across.\n */\nexport function selectOwnedCacheEntries<T extends { tenant?: string }>(\n entries: T[],\n tenant: string | null | undefined,\n): T[] {\n if (!tenant) return [];\n return (entries || []).filter((e) => !!e && e.tenant === tenant);\n}\n\n/**\n * Read the disk index with every entry filed under its plugin's ONE bundle URL\n * (pluginBundleUrl). The SDK reads the index only through this function.\n *\n * Before MGAP-C8, the device-tool loader recorded entries under the manifest's\n * UNENCODED spelling (`/api/ui-plugins/mcp:c:p/bundle.js`), while the rendered\n * surface used the encoded one. A device that ran both can therefore hold one\n * plugin under two keys. Every load now asks for the canonical URL, so an entry\n * stored under the other spelling would never be read again.\n *\n * The decision is to RECOVER such an entry rather than discard it, but only when\n * it provably is the same bundle. An entry moves to the canonical key only when\n * both of these hold:\n * (a) it carries the trusted declaration that names its plugin. That record\n * comes from the manifest, never from the bundle.\n * (b) its URL is that plugin's route in another spelling (isPluginBundleUrl).\n * Its tenant stamp, hash and trusted declaration move with it unchanged. So its\n * ownership (selectOwnedCacheEntries) and its integrity (the hash is re-checked\n * at eval) stay exactly as they were. When both spellings hold an entry, the\n * NEWER one is kept. That is the same last-writer-wins rule one key always had.\n *\n * Everything else stays where it is and is never adopted:\n * - an entry with no trusted declaration (its plugin is unknown without parsing\n * its URL);\n * - a URL that is not the plugin's route at all, such as a connector-declared\n * URL the old loader followed.\n * Such an entry is simply never matched. Its plugin downloads once more under\n * the canonical key, and the hash gate still applies.\n *\n * The index is mutated in place (the manager does read-modify-write on it), and\n * the move reaches disk with the next index write.\n */\nexport async function loadCacheIndex(\n storage: BundleStorage = getBundleStorage(),\n): Promise<Record<string, BundleCacheEntry>> {\n const index = (await storage.loadIndex()) || {};\n for (const [key, entry] of Object.entries(index)) {\n const pluginId = entry?.trusted?.pluginId;\n if (!pluginId) continue;\n const canonical = pluginBundleUrl(pluginId);\n if (key === canonical) continue;\n if (!isPluginBundleUrl(key, pluginId) || !isPluginBundleUrl(entry.bundleUrl, pluginId)) continue;\n delete index[key];\n const held = index[canonical];\n if (!held || (entry.timestamp ?? 0) > (held.timestamp ?? 0)) {\n index[canonical] = { ...entry, bundleUrl: canonical };\n }\n }\n return index;\n}\n\nexport interface BundleStorage {\n loadIndex(): Promise<Record<string, BundleCacheEntry>>;\n saveIndex(index: Record<string, BundleCacheEntry>): Promise<void>;\n /** Read a cached bundle. Returns null when missing/unreadable. */\n readBundle(localPath: string): Promise<string | null>;\n /** Persist a bundle; returns the localPath to record in the index.\n * `key` is a filesystem-safe name derived from the bundle URL+version. */\n writeBundle(key: string, content: string): Promise<string>;\n deleteBundle(localPath: string): Promise<void>;\n /** Wipe everything (index + bundles). */\n clearAll(): Promise<void>;\n}\n\n/** Default storage: keeps bundles for the lifetime of the JS context only. */\nexport class MemoryBundleStorage implements BundleStorage {\n private index: Record<string, BundleCacheEntry> = {};\n private files = new Map<string, string>();\n\n async loadIndex() {\n return this.index;\n }\n async saveIndex(index: Record<string, BundleCacheEntry>) {\n this.index = index;\n }\n async readBundle(localPath: string) {\n return this.files.get(localPath) ?? null;\n }\n async writeBundle(key: string, content: string) {\n const localPath = `memory://${key}`;\n this.files.set(localPath, content);\n return localPath;\n }\n async deleteBundle(localPath: string) {\n this.files.delete(localPath);\n }\n async clearAll() {\n this.index = {};\n this.files.clear();\n }\n}\n\nlet _storage: BundleStorage = new MemoryBundleStorage();\n\n/** Install a persistent storage implementation (call before first plugin load). */\nexport function setBundleStorage(storage: BundleStorage): void {\n _storage = storage;\n}\n\nexport function getBundleStorage(): BundleStorage {\n return _storage;\n}\n","/**\n * Native bridge for React Native plugins.\n * Direct function calls — no postMessage, no serialization.\n *\n * Identity comes from @ateam-ai-mobile/core config (host-owned auth); tool calls go\n * through the same MCP layer as everything else.\n */\nimport { useCallback, useMemo, useRef, useEffect } from 'react';\nimport type { MutableRefObject } from 'react';\nimport {\n connectorCall,\n mcpFetch as mcpFetchApi,\n unwrapMcpResult,\n postCommandResult,\n getTenant,\n getUser,\n pluginCommandEmitter,\n useChatStore,\n} from '@ateam-ai-mobile/core';\nimport type { PluginBridge, PluginContext } from '../sdk/types';\n\ntype CommandListener = (type: string, payload: any) => void;\n\nfunction buildContext(pluginId: string, connectorId?: string): PluginContext {\n const user = getUser();\n return {\n tenant: getTenant(),\n pluginId,\n connectorId,\n user: user ? { id: user.actorId || '', name: user.name || '', roles: user.roles || [] } : undefined,\n };\n}\n\nexport function useNativeBridge(pluginId: string, connectorId?: string, commandBufferRef?: MutableRefObject<any[]>): PluginBridge {\n const initCallbackRef = useRef<((ctx: PluginContext) => void) | null>(null);\n const commandListenersRef = useRef<Set<CommandListener>>(new Set());\n const initializedRef = useRef(false);\n\n const fireInit = useCallback(() => {\n if (initializedRef.current || !initCallbackRef.current) return;\n initCallbackRef.current(buildContext(pluginId, connectorId));\n initializedRef.current = true;\n }, [pluginId, connectorId]);\n\n const onInit = useCallback((cb: (ctx: PluginContext) => void) => {\n initCallbackRef.current = cb;\n setTimeout(fireInit, 0);\n }, [fireInit]);\n\n const mcpCall = useCallback(async (toolOrConnector: string, argsOrTool: any, cIdOrArgs?: any): Promise<any> => {\n // Support BOTH argument orders:\n // (tool, args, connectorId?) — bridge standard\n // (connectorId, tool, args?) — plugin convenience (matches useApi pattern)\n // Detect: if 2nd arg is a string, caller used (connector, tool, args) order\n let tool: string;\n let args: any;\n let cId: string | undefined;\n\n if (typeof argsOrTool === 'string') {\n // (connectorId, tool, args) order\n cId = toolOrConnector;\n tool = argsOrTool;\n args = cIdOrArgs || {};\n } else {\n // Standard (tool, args, connectorId?) order\n tool = toolOrConnector;\n args = argsOrTool;\n cId = typeof cIdOrArgs === 'string' ? cIdOrArgs : undefined;\n }\n\n const targetConnector = cId || connectorId;\n if (!targetConnector) {\n console.warn(`[NativeBridge:${pluginId}] mcpCall failed — no connectorId. tool=${tool}`);\n throw new Error(`[NativeBridge:${pluginId}] mcpCall requires a connectorId`);\n }\n\n try {\n const data = await connectorCall(targetConnector, tool, args);\n\n if (!data.ok && data.error) {\n throw new Error(data.error);\n }\n return unwrapMcpResult(data.result);\n } catch (err) {\n console.warn(`[NativeBridge:${pluginId}] mcpCall failed → connector=${targetConnector} tool=${tool}:`, (err as any)?.message || err);\n throw err;\n }\n }, [pluginId, connectorId]);\n\n const mcpFetch = useCallback(async (body: any): Promise<any> => {\n return mcpFetchApi(body);\n }, []);\n\n const sendCommand = useCallback((type: string, payload: any) => {\n // Handle command results — mirror web PluginHost pattern\n if (type === 'plugin.command.result' && payload?.correlationId) {\n postCommandResult(payload.correlationId, payload.result, payload.error);\n return;\n }\n }, [pluginId]);\n\n const onCommand = useCallback((cb: CommandListener): (() => void) => {\n commandListenersRef.current.add(cb);\n // Flush buffered commands immediately when a listener registers —\n // the buffer may have commands that arrived before the plugin mounted.\n if (commandBufferRef) {\n const buf = commandBufferRef.current;\n const remaining: any[] = [];\n for (const cmd of buf) {\n if (cmd.pluginId === pluginId && cmd.command !== '__focus') {\n try { cb(cmd.command, { ...cmd.args, correlationId: cmd.correlationId }); } catch {}\n } else {\n remaining.push(cmd);\n }\n }\n commandBufferRef.current = remaining;\n }\n // Also drain the emitter's own recent-commands buffer (covers the\n // surface-dispatcher path which has no commandBufferRef).\n for (const cmd of pluginCommandEmitter.drainPluginCommands(pluginId)) {\n try { cb(cmd.command, { ...cmd.args, correlationId: cmd.correlationId }); } catch {}\n }\n return () => {\n commandListenersRef.current.delete(cb);\n };\n }, [pluginId, commandBufferRef]);\n\n // Dispatch live plugin commands to registered listeners\n useEffect(() => {\n const unsub = pluginCommandEmitter.on('plugin-command', (cmd: any) => {\n if (cmd.pluginId !== pluginId) return;\n if (cmd.command === '__focus') return; // Focus-only, no dispatch\n commandListenersRef.current.forEach(fn => {\n try { fn(cmd.command, { ...cmd.args, correlationId: cmd.correlationId }); } catch {}\n });\n });\n return unsub;\n }, [pluginId]);\n\n // Flush buffered commands on mount (commands that arrived before plugin\n // was ready). Two sources, both safe to drain:\n // 1. The parent-passed `commandBufferRef` (legacy overlay path).\n // 2. The emitter's own recent-commands buffer (surface-dispatcher path).\n useEffect(() => {\n const timer = setTimeout(() => {\n const dispatch = (cmd: any) => {\n commandListenersRef.current.forEach(fn => {\n try { fn(cmd.command, { ...cmd.args, correlationId: cmd.correlationId }); } catch {}\n });\n };\n\n if (commandBufferRef) {\n const remaining: any[] = [];\n for (const cmd of commandBufferRef.current) {\n if (cmd.pluginId === pluginId && cmd.command !== '__focus') dispatch(cmd);\n else remaining.push(cmd);\n }\n commandBufferRef.current = remaining;\n }\n\n // Always drain the emitter buffer too — the dispatcher path has no\n // parent buffer, and the legacy path may still have lost commands here\n // if they arrived before the parent's listener registered.\n for (const cmd of pluginCommandEmitter.drainPluginCommands(pluginId)) {\n dispatch(cmd);\n }\n }, 500); // Delay to let plugin register its onCommand listener\n return () => clearTimeout(timer);\n }, [pluginId, commandBufferRef]);\n\n useEffect(() => {\n return () => {\n commandListenersRef.current.clear();\n initializedRef.current = false;\n };\n }, []);\n\n const close = useCallback(() => {\n pluginCommandEmitter.emit('plugin-close', { pluginId });\n }, [pluginId]);\n\n /** Send a chat message into the user's thread (e.g. confirmed \"connect my\n * Gmail\"). Pair with bridge.close() to land the user on chat. */\n const sendMessage = useCallback((text: string) => {\n const t = (text || '').trim();\n if (!t) return;\n try {\n useChatStore.getState().sendMessage(t);\n } catch (err) {\n console.warn('[bridge.sendMessage] failed:', err instanceof Error ? err.message : String(err));\n }\n }, []);\n\n /** Prepare (pre-fill) the chat composer without sending. The host chat\n * screen listens for `prepare-chat-message` and stuffs `text` into its\n * input state. Pair with bridge.close(). */\n const prepareMessage = useCallback((text: string) => {\n const t = (text || '').trim();\n if (!t) return;\n pluginCommandEmitter.emit('prepare-chat-message', { text: t });\n }, []);\n\n // Memoize the bridge object to prevent child re-renders — a new object\n // every render → useApi recreates → fetch effects refire → flicker loop.\n return useMemo(\n () => ({ onInit, mcpCall, mcpFetch, sendCommand, onCommand, close, sendMessage, prepareMessage }),\n [onInit, mcpCall, mcpFetch, sendCommand, onCommand, close, sendMessage, prepareMessage],\n );\n}\n\n/**\n * Non-hook version for service plugins (no React lifecycle).\n */\nexport function createNativeBridge(pluginId: string, connectorId?: string): PluginBridge {\n const commandListeners = new Set<CommandListener>();\n\n return {\n onInit(cb) {\n setTimeout(() => {\n cb(buildContext(pluginId, connectorId));\n }, 0);\n },\n\n async mcpCall(tool: string, args: any, cId?: string) {\n const targetConnector = cId || connectorId;\n if (!targetConnector) {\n throw new Error(`[NativeBridge:${pluginId}] mcpCall requires a connectorId`);\n }\n const data = await connectorCall(targetConnector, tool, args);\n if (!data.ok && data.error) throw new Error(data.error);\n return unwrapMcpResult(data.result);\n },\n\n async mcpFetch(body: any) {\n return mcpFetchApi(body);\n },\n\n sendCommand(_type: string, _payload: any) {\n },\n\n onCommand(cb: CommandListener) {\n commandListeners.add(cb);\n return () => { commandListeners.delete(cb); };\n },\n\n close() {\n pluginCommandEmitter.emit('plugin-close', { pluginId });\n },\n\n sendMessage(text: string) {\n const t = (text || '').trim();\n if (!t) return;\n try {\n useChatStore.getState().sendMessage(t);\n } catch (err) {\n console.warn('[bridge.sendMessage] failed:', err instanceof Error ? err.message : String(err));\n }\n },\n\n prepareMessage(text: string) {\n const t = (text || '').trim();\n if (!t) return;\n pluginCommandEmitter.emit('prepare-chat-message', { text: t });\n },\n } as PluginBridge;\n}\n","/**\n * Host DI for the SEMANTIC layer — the `props.deviceState` counterpart of\n * `setPluginNativeProvider`.\n *\n * Kept in its own file rather than added to host.ts, for the same reason the\n * two layers have separate namespaces: the moment they share a module, the\n * next person adds a domain to `PluginNative` or a capability to\n * `stateDomains` and the boundary starts to blur.\n *\n * THE GATE IS NOT THE MECHANICAL ONE. `gatePluginNative` replaces an\n * undeclared capability with a proxy whose methods warn and return `undefined`\n * — so `await native.location.getCurrent()` resolves to `undefined`, and\n * `pos?.latitude` is `undefined`, which flows into a model answer as a\n * confident nothing. A silent undefined is a fabrication vector.\n *\n * Here, an undeclared domain returns a real snapshot in which everything is\n * explicitly `unknown` / `null`, with `freshness.state = 'unknown'`. The\n * plugin gets a well-formed answer that says \"I know nothing\", which no\n * reasonable code path can mistake for data.\n */\nimport type { DeviceBridgeDomain, DeviceState, StateQuality } from './sdk/device-state';\n\n// The `unknown` freshness/confidence shape is the canonical `neverObserved()` +\n// `{ level: 'unknown' }` (see sdk/device-state.ts). It is inlined here rather\n// than imported because this module is imported directly by node --test and the\n// harness resolves only the explicit entry, not a nested extensionless value\n// import. The golden snapshot test pins this shape === neverObserved()'s.\nconst UNKNOWN_QUALITY: StateQuality = {\n freshness: { state: 'unknown', observedAt: null, ageMs: null },\n confidence: { level: 'unknown' },\n};\n\n/**\n * The empty snapshot for a domain the plugin did not declare.\n *\n * Deliberately built per domain rather than one shared `{}`: each snapshot has\n * required fields, and a caller reading `snapshot.position` must get `null`,\n * not a TypeError. Domains not listed fall through to `{ quality }`, which is\n * the one field every snapshot in the design shares.\n */\nfunction deniedSnapshot(domain: DeviceBridgeDomain): any {\n const base = { quality: UNKNOWN_QUALITY };\n switch (domain) {\n case 'spatial':\n return {\n ...base,\n position: null,\n movement: { speedMps: null, bearingDeg: null, distanceRecentM: null, state: 'unknown' },\n orientation: { headingDeg: null },\n recentPath: [],\n };\n case 'visual':\n return {\n ...base,\n camera: { available: false, active: false, facing: 'unknown' },\n latest: null,\n recentTimeline: { windowMs: 0, frames: [] },\n };\n case 'deviceContext':\n return {\n ...base,\n power: { batteryLevel: null, charging: null, lowPowerMode: null },\n thermal: { state: 'unknown' },\n resources: { memoryPressure: 'unknown', storagePressure: 'unknown' },\n };\n case 'connectivity':\n return {\n ...base,\n reachability: 'unknown',\n transport: 'unknown',\n qualityClass: 'unknown',\n stability: 'unknown',\n latencyMs: null,\n };\n case 'interaction':\n return {\n ...base,\n lifecycle: { appState: 'unknown', screenOn: null },\n audio: { captureActive: null, playbackActive: null, route: 'unknown', interruption: 'unknown' },\n };\n case 'activity':\n return {\n ...base,\n // `confidence` is REQUIRED on both blocks in the freeze, precisely\n // because an inferred activity must never be handed over without\n // saying how sure the inference is. An empty snapshot is the least\n // sure of all.\n human: { state: 'unknown', since: null, confidence: { level: 'unknown' } },\n devicePose: { placement: 'unknown', orientation: 'unknown', confidence: { level: 'unknown' } },\n recentTransitions: [],\n };\n case 'environment':\n return {\n ...base,\n lighting: { level: 'unknown', lux: null },\n acoustics: { level: 'unknown', approximateDb: null },\n // 'unknown' rather than 'uncertain': uncertain means we looked and\n // could not decide, and nothing looked at all here.\n enclosure: { state: 'unknown' },\n proximity: { distanceClass: 'unknown' },\n nearbySignals: { bleAvailable: false, beaconCount: null, uwbAvailable: false },\n };\n case 'capability': {\n // Every axis unknown — and note this is NOT the same as `denied`.\n // \"I could not check\" and \"the user said no\" lead to different things\n // being said to the user, which is why the freeze keeps them apart.\n const unknownStatus = { support: 'unknown', permission: 'unknown', availability: 'unknown' };\n return {\n ...base,\n camera: unknownStatus,\n microphone: unknownStatus,\n location: { ...unknownStatus, precision: 'unknown', backgroundPermission: 'unknown' },\n motion: unknownStatus,\n bluetooth: unknownStatus,\n uwb: unknownStatus,\n nfc: unknownStatus,\n notifications: unknownStatus,\n health: unknownStatus,\n backgroundExecution: unknownStatus,\n };\n }\n default:\n return base;\n }\n}\n\n/**\n * A domain the plugin may not use, or that this build does not implement.\n *\n * Reads answer with explicit unknowns. Anything that ACTS — start, stop,\n * subscribe — throws, because there is no honest \"unknown\" for an action: a\n * silent no-op start would leave the caller believing a session is open, and a\n * subscription that never fires reads as \"nothing has changed\".\n */\nfunction deniedDomain(domain: DeviceBridgeDomain, why: string): any {\n return {\n async getSnapshot() { return deniedSnapshot(domain); },\n async start() { throw denial(domain, why); },\n async stop() { throw denial(domain, why); },\n subscribe() { throw denial(domain, why); },\n };\n}\n\nfunction denial(domain: DeviceBridgeDomain, why: string): Error {\n const err: any = new Error(`deviceState.${domain}: ${why}`);\n // Frozen vocabulary. A manifest gate IS a policy, so a manifest denial is\n // policyRestricted — no new error vocabulary needed.\n err.code = 'RESTRICTED';\n err.domain = domain;\n return err;\n}\n\nconst ALL_DOMAINS: DeviceBridgeDomain[] = [\n 'spatial', 'visual', 'activity', 'deviceContext',\n 'connectivity', 'capability', 'environment', 'interaction',\n];\n\nlet _provider: Partial<DeviceState> = {};\n\n/** Host DI: the app supplies the engines it has. Called once at startup. */\nexport function setDeviceStateProvider(state: Partial<DeviceState>): void {\n _provider = state || {};\n}\n\n/**\n * The `deviceState` a plugin receives, gated by what it declared.\n *\n * Every domain is always present — a plugin can call any of the eight without\n * an existence check. What differs is whether it answers with data, or with\n * an explicit \"I know nothing\" and a reason.\n */\nexport function gateDeviceState(declared?: readonly DeviceBridgeDomain[]): DeviceState {\n const allowed = new Set(declared || []);\n const out: any = {};\n\n for (const domain of ALL_DOMAINS) {\n if (!allowed.has(domain)) {\n out[domain] = deniedDomain(\n domain,\n `not declared in this plugin's stateDomains. Add '${domain}' to use it.`,\n );\n continue;\n }\n const engine = (_provider as any)[domain];\n out[domain] = engine ?? deniedDomain(\n domain,\n 'no engine in this build — the native side does not exist yet. See docs/DEVICE_API_STATUS.md.',\n );\n }\n\n return out as DeviceState;\n}\n\n/**\n * The `deviceState` a device TOOL call receives: the same domains, but\n * `subscribe` refuses.\n *\n * A declared domain IS the engine, and the engines live as long as the app. A\n * UI plugin has a mount to unsubscribe in; a tool call has nothing — a listener\n * `run()` adds outlives it and runs on every later event, once per call that\n * added one. Refused loudly rather than quietly scoped to the call: a\n * subscription that stops hearing when `run` returns reads as \"nothing has\n * changed\". Everything else passes through untouched.\n */\nexport function withoutSubscribe(state: DeviceState): DeviceState {\n if (!state) return state;\n const out: any = {};\n for (const domain of ALL_DOMAINS) {\n const d = (state as any)[domain];\n out[domain] = d && Object.assign(Object.create(d), {\n subscribe() {\n throw denial(domain, 'a device tool call has no lifetime to own a subscription. Subscribe from the plugin UI, or read getSnapshot() within the call.');\n },\n });\n }\n return out as DeviceState;\n}\n\n/** Which domains this build can actually answer — for diagnostics. */\nexport function implementedStateDomains(): DeviceBridgeDomain[] {\n return ALL_DOMAINS.filter(d => !!(_provider as any)[d]);\n}\n","/**\n * Device tool registry.\n *\n * A solution's RN plugin may ship a `tools/` section alongside (or instead of)\n * its UI. Those tools are registered HERE, when the bundle is evaluated — not\n * when a screen mounts — so a caller can invoke one with nothing of the plugin\n * on screen.\n *\n * Lookup is by the tool's own domain name (e.g. \"guide.observe\"). Callers never\n * route on a name prefix: whether a tool runs locally is declared by the server\n * in the session payload, and resolved against this registry. The full LOCAL\n * reasoning path (discovery → call → result, and its independence from\n * relay/MCP) is documented in docs/architecture/LOCAL_REASONING_PATH.md (R13).\n */\nimport { createNativeBridge } from '../bridge/native';\nimport { getPluginNative, gatePluginNative } from '../host';\nimport { gateDeviceState, withoutSubscribe } from '../deviceStateHost';\nimport type { DeviceToolContext, DeviceToolDefinition, DeviceToolFailureReason, NativeCapabilities } from '../sdk/types';\nimport type { DeviceBridgeDomain } from '../sdk/device-state';\n\nexport interface DeviceToolSummary {\n name: string;\n pluginId: string;\n description?: string;\n input_schema?: Record<string, unknown>;\n}\n\nexport type DeviceToolOutcome =\n | { ok: true; result: any }\n | { ok: false; error: string; reason: DeviceToolFailureReason };\n\ninterface Entry {\n pluginId: string;\n tool: DeviceToolDefinition;\n capabilities?: NativeCapabilities;\n /** L3 DeviceState domains this plugin declared — gates ctx.deviceState. */\n stateDomains?: DeviceBridgeDomain[];\n}\n\n/** toolName → entry. One name, one implementation. */\nconst registry = new Map<string, Entry>();\n\n/** Optional host override; the SDK supplies a working default (see below). */\nlet contextProvider:\n | ((pluginId: string, capabilities?: NativeCapabilities, stateDomains?: DeviceBridgeDomain[]) => DeviceToolContext)\n | null = null;\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\n\n/**\n * Override how a device tool reaches the Device Bridge. Rarely needed — the\n * default below builds the same bridge/native pair a plugin gets when it\n * renders, gated by the capabilities the plugin declared.\n */\nexport function setDeviceToolContextProvider(\n fn: (pluginId: string, capabilities?: NativeCapabilities, stateDomains?: DeviceBridgeDomain[]) => DeviceToolContext,\n): void {\n contextProvider = fn;\n}\n\n/**\n * Default context: the plugin's own bridge + a capability-gated Device Bridge +\n * the L3 DeviceState gated to the domains the plugin declared. All three are the\n * SAME gated objects the plugin gets when it renders — a tool reaches nothing a\n * UI plugin couldn't. (One thing less: `callDeviceTool` takes `subscribe` away,\n * because a call has no lifetime to own one.)\n */\nfunction defaultContext(\n pluginId: string,\n capabilities?: NativeCapabilities,\n stateDomains?: DeviceBridgeDomain[],\n): DeviceToolContext {\n return {\n bridge: createNativeBridge(pluginId),\n native: gatePluginNative(getPluginNative(), capabilities, pluginId),\n deviceState: gateDeviceState(stateDomains),\n };\n}\n\n/**\n * Register a plugin's tools. Called from the bundle pipeline at load time.\n *\n * A name already taken by ANOTHER plugin is refused — a bundle loaded later\n * must not be able to take over \"guide.observe\" from the plugin that owns it.\n * Re-registering the same plugin (bundle reload) replaces its own entries.\n */\nexport function registerDeviceTools(\n pluginId: string,\n tools: DeviceToolDefinition[],\n capabilities?: NativeCapabilities,\n stateDomains?: DeviceBridgeDomain[],\n): string[] {\n const accepted: string[] = [];\n\n for (const tool of tools || []) {\n if (!tool || typeof tool.name !== 'string' || typeof tool.run !== 'function') {\n console.warn(`[deviceTools] ${pluginId}: skipping malformed tool entry`);\n continue;\n }\n const existing = registry.get(tool.name);\n if (existing && existing.pluginId !== pluginId) {\n console.warn(\n `[deviceTools] ${pluginId}: \"${tool.name}\" already registered by ${existing.pluginId} — refusing to override`,\n );\n continue;\n }\n registry.set(tool.name, { pluginId, tool, capabilities, stateDomains });\n accepted.push(tool.name);\n }\n\n if (accepted.length > 0) {\n console.log(`[deviceTools] ${pluginId} registered: ${accepted.join(', ')}`);\n }\n return accepted;\n}\n\n/** Drop every tool owned by a plugin (bundle eviction / plugin revoked). */\nexport function unregisterDeviceTools(pluginId: string): void {\n for (const [name, entry] of registry.entries()) {\n if (entry.pluginId === pluginId) registry.delete(name);\n }\n}\n\n/** Is `name` registered — and, given `pluginId`, registered BY that plugin?\n * (A clean voice call only lets its owner's own tools run.) */\nexport function hasDeviceTool(name: string, pluginId?: string): boolean {\n const entry = registry.get(name);\n return !!entry && (pluginId === undefined || entry.pluginId === pluginId);\n}\n\nexport function listDeviceTools(): DeviceToolSummary[] {\n return Array.from(registry.entries()).map(([name, { pluginId, tool }]) => ({\n name,\n pluginId,\n description: tool.description,\n input_schema: tool.input_schema,\n }));\n}\n\n/**\n * Invoke a device tool. Never throws — every failure comes back as a typed\n * outcome, because the caller is usually a reasoning loop that has to say\n * something useful out loud rather than swallow an exception.\n */\nexport async function callDeviceTool(\n name: string,\n args: any = {},\n opts: { timeoutMs?: number; signal?: AbortSignal } = {},\n): Promise<DeviceToolOutcome> {\n const entry = registry.get(name);\n if (!entry) {\n return { ok: false, reason: 'not_found', error: `No device tool registered as \"${name}\"` };\n }\n const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n try {\n const build = contextProvider || defaultContext;\n const built = build(entry.pluginId, entry.capabilities, entry.stateDomains);\n const ctx: DeviceToolContext = {\n ...built,\n // Whoever built the context, a call cannot own a subscription.\n deviceState: withoutSubscribe(built.deviceState),\n signal: opts.signal,\n };\n\n const result = await Promise.race([\n Promise.resolve(entry.tool.run(args, ctx)),\n new Promise<never>((_, reject) => {\n timer = setTimeout(\n () => reject(new Error(`Device tool \"${name}\" timed out after ${timeoutMs}ms`)),\n timeoutMs,\n );\n }),\n ]);\n\n return { ok: true, result };\n } catch (err: any) {\n const message = err?.message || String(err);\n const timedOut = message.includes('timed out after');\n return { ok: false, reason: timedOut ? 'timeout' : 'failed', error: message };\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n\n/** Test/host reset. */\nexport function clearDeviceTools(): void {\n registry.clear();\n}\n","/**\n * Host DI + gate for `props.voice` — the session counterpart of\n * setDeviceStateProvider / setPluginNativeProvider.\n *\n * The app mounts one live voice session (VoiceSessionHost in @ateam-ai-mobile/ui)\n * and hands it here once at startup via setVoiceProvider. gateVoice then decides,\n * per plugin, whether that session is exposed:\n *\n * - declared (`capabilities: { voice: true }`) + a provider present → the real\n * session.\n * - declared but no provider (no session host in this build) → a refusal that\n * names the reason.\n * - NOT declared → a refusal that names the reason.\n *\n * ABSENCE IS AN ANSWER (spec invariant 6). A denied surface never fakes an\n * `idle` snapshot and never silently no-ops: reads report `state: 'error'` with\n * an explicit `lastError`, and actions throw. A silent `idle` would read to a\n * reasoning loop as \"a working session that simply isn't connected yet\" — a\n * fabrication, the same class of bug as an undefined that flows into an answer.\n */\nimport type { VoiceAPI, VoiceSnapshot, VoiceSessionProvider } from './sdk/voice';\n\nlet _provider: VoiceSessionProvider | null = null;\n\n/** Host DI: the app supplies its live (owner-aware) voice session. Called once\n * at startup; pass null to detach (e.g. in a build with no voice). */\nexport function setVoiceProvider(provider: VoiceSessionProvider | null): void {\n _provider = provider || null;\n}\n\n/** Whether this build has a voice session to expose — for diagnostics. */\nexport function implementedVoice(): boolean {\n return !!_provider;\n}\n\nfunction voiceDenial(why: string): Error {\n const err: any = new Error(`voice: ${why}`);\n // Frozen vocabulary (matches gateDeviceState): a capability/manifest gate IS a\n // policy, so a denial is RESTRICTED — no new error vocabulary.\n err.code = 'RESTRICTED';\n return err;\n}\n\n/**\n * The refused surface. Reads answer honestly (\"I am not available, here is\n * why\"); actions throw. Deliberately NOT a fake `idle` and NOT a silent no-op.\n */\nfunction deniedVoice(why: string): VoiceAPI {\n const fail = () => { throw voiceDenial(why); };\n return {\n async start() { return fail(); },\n stop() { fail(); },\n setMuted() { fail(); },\n prompt() { fail(); },\n observe() { fail(); },\n getSnapshot(): VoiceSnapshot {\n return {\n state: 'error',\n sessionId: null,\n muted: false,\n speaking: false,\n listening: false,\n userSpeaking: false,\n lastUserSpeechEndedAt: null,\n lastDeviceTool: null,\n authorizedSessionId: null,\n lastError: why,\n };\n },\n subscribe() { return fail(); },\n transcript() { return []; },\n };\n}\n\n/**\n * A per-plugin VoiceAPI that stamps `pluginId` as the caller on every call, so\n * the owner-aware provider can isolate it. TWO plugins get TWO facades bound to\n * TWO identities; neither can read, control, or attach to the other's live\n * session — even though both declared voice and both share the one physical\n * session. A plugin never supplies its own identity: it is captured here.\n */\nfunction scopedVoice(provider: VoiceSessionProvider, pluginId: string): VoiceAPI {\n return {\n start: (opts) => provider.start(opts, pluginId),\n stop: () => provider.stop(pluginId),\n setMuted: (muted) => provider.setMuted(muted, pluginId),\n prompt: (input) => provider.prompt(input, pluginId),\n observe: (text) => provider.observe(text, pluginId),\n getSnapshot: () => provider.getSnapshot(pluginId),\n subscribe: (cb) => provider.subscribe(cb, pluginId),\n transcript: () => provider.transcript(pluginId),\n };\n}\n\n/**\n * The `voice` a plugin receives, gated by whether it declared the capability AND\n * scoped to its identity.\n *\n * `declared` is `!!capabilities.voice` from the plugin's TRUSTED declaration\n * (resolved in pluginRuntime.ts — the server manifest for a remote plugin, the\n * registry entry for a host-owned one). A downloaded bundle cannot grant itself\n * voice. `pluginId` is the trusted identity the returned facade is bound to.\n *\n * Reading the transcript of a live session is a privacy surface, not just an\n * API: this gate is the only thing between a plugin and everything the user\n * says. Two protections stack: (1) it is coupled to evidence — a live session\n * shows the platform-owned, unsuppressable mic indicator, so there is no path to\n * a transcript without visible proof the mic is/was live; and (2) it is scoped\n * to the owner, so declaring `voice` lets a plugin run ITS OWN conversation, not\n * eavesdrop on another solution's. A missing identity FAILS CLOSED.\n */\nexport function gateVoice(declared: boolean, pluginId: string): VoiceAPI {\n if (!declared) {\n return deniedVoice(\n \"not declared in this plugin's capabilities. Add `capabilities: { voice: true }` to use it.\",\n );\n }\n if (!pluginId) {\n return deniedVoice(\n 'no plugin identity — voice fails closed without a caller to scope the session to.',\n );\n }\n return _provider\n ? scopedVoice(_provider, pluginId)\n : deniedVoice(\n 'no voice session in this build — the app has not mounted a VoiceSessionHost / called setVoiceProvider.',\n );\n}\n","/**\n * The ONE runtime contract that turns a plugin's declarations into its gated\n * device surface — `props.device` / `props.native` (L2) and `props.deviceState`\n * (L3) — for EVERY renderer, on EVERY surface, and for its device tools.\n *\n * WHY THIS EXISTS. Each renderer used to resolve this itself: the embedded route\n * gated both `native` and `deviceState`; the drawer/fullscreen renderer gated\n * only `native` and read `manifest.native` instead of `manifest.capabilities`;\n * the host-built-in surfaces gated `native` off the registry entry and passed no\n * `deviceState` at all. The SAME plugin therefore got full device access on one\n * surface and `undefined` on another — invisible to the author, whose manifest\n * was correct. A seam owned by three renderers is tested by none. This makes it\n * owned by one: every renderer calls resolvePluginRuntimeProps, so they cannot\n * disagree, and a parity test on this function covers all of them at once.\n */\nimport { getPluginNative, gatePluginNative } from './host';\nimport { gateDeviceState } from './deviceStateHost';\nimport { gateVoice } from './voiceHost';\nimport type { PluginNative, NativeCapabilities } from './sdk/types';\nimport type { DeviceState, DeviceBridgeDomain } from './sdk/device-state';\nimport type { VoiceAPI } from './sdk/voice';\n\n/** The gated surface a plugin Component receives. `device` and `native` are the\n * SAME object (native is the deprecated alias). */\nexport interface PluginRuntimeProps {\n device: PluginNative;\n native: PluginNative;\n deviceState: DeviceState;\n voice: VoiceAPI;\n}\n\n/** One declaration source — either the server manifest or the registry entry. */\ninterface PluginDeclaration {\n capabilities?: NativeCapabilities | Record<string, unknown>;\n native?: NativeCapabilities;\n stateDomains?: readonly DeviceBridgeDomain[];\n}\n\nexport interface PluginRuntimeSource {\n pluginId: string;\n /**\n * The server manifest (Core-passed) — the TRUSTED authority for a REMOTE\n * plugin. `capabilities` is the current field Core emits; `native` is the\n * legacy one. A grant absent here is NOT GRANTED (fail closed).\n */\n manifest?: PluginDeclaration | null;\n /**\n * The registry entry — the trusted authority for a HOST-OWNED plugin\n * (registered locally, no server manifest). For a REMOTE plugin this is the\n * downloaded bundle's own claim and is UNTRUSTED for gating; it is used ONLY\n * when there is no manifest.\n */\n plugin?: PluginDeclaration | null;\n}\n\n/** Union the recognized native-capability flags from a source's `native`\n * (legacy) and `capabilities` (current) fields. A grant in EITHER is honored;\n * neither shadows the other. `capabilities` may also carry non-capability\n * metadata (e.g. `device_tools`) — gatePluginNative reads only the flags it\n * knows and ignores the rest. */\nfunction mergeCaps(decl: PluginDeclaration | null | undefined): NativeCapabilities | undefined {\n if (!decl) return undefined;\n return { ...(decl.native as any), ...(decl.capabilities as any) } as NativeCapabilities;\n}\n\n/** What a plugin is GRANTED — resolved from its one trusted source. The same\n * value gates its rendered surface and its device tools (the tool registry\n * receives it through bundleManager.load/loadTools). */\nexport interface PluginGrants {\n capabilities?: NativeCapabilities;\n stateDomains?: DeviceBridgeDomain[];\n}\n\n/**\n * Resolve a plugin's grants — the SINGLE place this happens, for every rendered\n * surface AND for the device tools its bundle registers, so a plugin gets\n * identical access through either.\n *\n * TRUST BOUNDARY. Exactly ONE source is authoritative: the server `manifest` for\n * a remote plugin, the registry `plugin` for a host-owned one. They are NEVER\n * mixed, and a remote plugin's own downloaded bundle claim NEVER expands its\n * capabilities or L3 domains past what the trusted source granted. If the\n * trusted source omits a grant, it is not granted — fail closed. (If Core does\n * not carry `stateDomains` for a remote plugin, the fix is Core passing it, not\n * trusting the bundle: Core already holds the solution's declaration.)\n */\nexport function resolvePluginGrants(src: PluginRuntimeSource): PluginGrants {\n const trusted = src.manifest ?? src.plugin ?? null;\n // Copied, so the grant cannot change after the fact by mutating the source.\n const stateDomains = trusted?.stateDomains ? [...trusted.stateDomains] : undefined;\n return { capabilities: mergeCaps(trusted), stateDomains };\n}\n\n/** Turn a plugin's grants into the gated { device, native, deviceState, voice } it\n * receives on every rendered surface. */\nexport function resolvePluginRuntimeProps(src: PluginRuntimeSource): PluginRuntimeProps {\n const { capabilities, stateDomains } = resolvePluginGrants(src);\n const native = gatePluginNative(getPluginNative(), capabilities, src.pluginId);\n const deviceState = gateDeviceState(stateDomains);\n // Voice is a capability flag, gated the same way — the TRUSTED declaration\n // decides, a downloaded bundle cannot grant itself the session (or the\n // transcript it can read). The facade is bound to the TRUSTED pluginId, so the\n // session is isolated per solution: declaring voice runs YOUR conversation, it\n // does not attach to another plugin's live one.\n const voice = gateVoice(!!(capabilities as any)?.voice, src.pluginId);\n // device and native are intentionally the SAME gated object (R4 rename).\n return { device: native, native, deviceState, voice };\n}\n","/**\n * Device tool loading.\n *\n * A device tool is only callable once its plugin bundle has been evaluated —\n * that is when the tools register (see `./registry`). Nothing else in the app\n * guarantees that: bundle prewarm runs on the home screen and is best-effort, so\n * a user who goes straight into a voice call can reach a tool the phone has\n * never loaded. The model then hears \"no such tool\" and improvises, which looks\n * exactly like a broken feature.\n *\n * So the voice path calls `ensureDeviceToolsLoaded()` before connecting.\n */\nimport { listPlugins, getPlugin, getNativeBundleUrl, getNativeBundleHash } from '../api/plugins';\nimport { bundleManager } from '../bundles/bundleManager';\nimport { listDeviceTools } from './registry';\nimport { getBundleStorage, loadCacheIndex, selectOwnedCacheEntries } from '../bundles/storage';\nimport { resolvePluginGrants } from '../pluginRuntime';\nimport { getTenant } from '@ateam-ai-mobile/core';\n\nlet inflight: Promise<string[]> | null = null;\nlet loadedOnce = false;\n\n/**\n * Load every plugin that declares `capabilities.device_tools`, so its tools are\n * registered and callable. Best-effort and idempotent: safe to call on every\n * call start. Returns the tool names currently registered.\n *\n * Pass `force` after a plugin catalog change (a newly deployed connector).\n */\nexport async function ensureDeviceToolsLoaded({ force = false } = {}): Promise<string[]> {\n if (loadedOnce && !force) return listDeviceTools().map(t => t.name);\n if (inflight) return inflight;\n\n inflight = (async () => {\n try {\n const summaries = await listPlugins();\n\n // The list response is slim, so the manifest is the authority on whether a\n // plugin declares device tools. Fetched in parallel — a cold connector\n // that answers slowly must not hold up a call.\n const manifests = await Promise.all(\n (summaries || []).map(s =>\n getPlugin((s as any).id).catch(() => null),\n ),\n );\n\n const targets = manifests.filter((m: any) => {\n const declared = m?.capabilities?.device_tools;\n return Array.isArray(declared) && declared.length > 0;\n });\n\n if (targets.length === 0) {\n // The catalog can go blind: a solution connector is lazy, and while it\n // is not running its plugins are absent from the list entirely. That is\n // a fact about a server process, not about this phone — the bundle we\n // already downloaded still has the tools in it.\n //\n // So fall back to what is on disk: re-evaluate this tenant's cached\n // bundles under the trusted declaration recorded when a manifest last\n // loaded them (see loadFromDiskCache).\n const recovered = await loadFromDiskCache();\n if (recovered.length > 0) {\n console.log(`[deviceTools] catalog listed none — recovered from cache: ${recovered.join(', ')}`);\n return recovered;\n }\n // Do NOT latch: \"nothing yet\" is usually just \"not yet\".\n console.log('[deviceTools] no device tools available yet — will look again next call');\n return [];\n }\n\n await Promise.all(\n targets.map(async (m: any) => {\n const bundleUrl = getNativeBundleUrl(m);\n if (!bundleUrl) {\n console.warn(`[deviceTools] ${m.id} declares device_tools but has no native bundle`);\n return;\n }\n try {\n // The manifest is the authority on what the tools may touch — the\n // same grants its rendered surface gets, never the bundle's claim.\n await bundleManager.loadTools(\n m.id,\n bundleUrl,\n m.version || '1.0.0',\n getNativeBundleHash(m) || undefined,\n resolvePluginGrants({ pluginId: m.id, manifest: m }),\n );\n } catch (err: any) {\n console.warn(`[deviceTools] ${m.id} failed to load:`, err?.message || String(err));\n }\n }),\n );\n\n const names = listDeviceTools().map(t => t.name);\n // Only latch on success. An empty result is a cold read, not a fact —\n // same reasoning as the server-side discovery cache.\n loadedOnce = names.length > 0;\n console.log(`[deviceTools] ready: ${names.length > 0 ? names.join(', ') : '(none registered — will retry next call)'}`);\n return names;\n } finally {\n inflight = null;\n }\n })();\n\n return inflight;\n}\n\n/**\n * Re-evaluate the CURRENT TENANT'S bundles already cached on disk.\n *\n * Used when the plugin catalog comes back empty — which happens whenever the\n * owning connector is asleep. This is a local read, not a download.\n *\n * TENANT SCOPING IS LOAD-BEARING, NOT DEFENCE IN DEPTH.\n *\n * Every other load path is gated by the manifest hash: the expected hash comes\n * from the current tenant's server, so another tenant's cached bytes simply\n * fail to match and are re-downloaded. This path has no manifest — that is the\n * whole reason it exists — so it passes each entry's OWN stored hash as the\n * expected hash. That check compares an entry to itself and can never fail. It\n * is an integrity check against disk corruption, and it is not, and cannot be,\n * an authorisation check.\n *\n * Without the tenant filter below this loop re-evaluated EVERY cached bundle,\n * so a plugin cached during a session on tenant A registered its device tools\n * into a live session on tenant B, and subsequent tool calls ran tenant-A code\n * holding tenant-B credentials. No id collision was required: bundle urls are\n * identical across tenants and resolve per-tenant on the server, and the code\n * cache deliberately survives logout.\n *\n * An entry with no recorded tenant predates the stamp. Its owner is unknown,\n * which means untrusted — skip it and let the normal catalog path re-download\n * it under a real hash gate.\n *\n * GRANTS COME FROM THE RECORDED MANIFEST, NEVER THE BUNDLE. With no manifest\n * here, the tools register under the `trusted` declaration (pluginId +\n * capabilities + stateDomains) the bundle manager recorded on the entry when a\n * manifest last loaded these bytes. An entry without one — written before the\n * record existed, or never loaded under a manifest — is skipped (fail closed):\n * the only other source is the bundle's own claim, and the catalog path\n * registers it properly once its connector answers.\n */\nasync function loadFromDiskCache(): Promise<string[]> {\n try {\n // Canonical keys only (loadCacheIndex): an entry an older build filed under\n // the manifest's unencoded spelling is recovered under pluginBundleUrl.\n const index = await loadCacheIndex(getBundleStorage());\n const entries = Object.values(index || {});\n if (entries.length === 0) return [];\n\n const tenant = getTenant();\n if (!tenant) {\n // No active tenant: nothing can be proven to be ours.\n console.warn('[deviceTools] disk-cache recovery skipped — no active tenant');\n return [];\n }\n const mine = selectOwnedCacheEntries(entries, tenant);\n const skipped = entries.length - mine.length;\n if (skipped > 0) {\n console.log(`[deviceTools] disk-cache recovery: ${mine.length} for \"${tenant}\", skipped ${skipped} not owned by it`);\n }\n const declared = mine.filter((e) => !!e.trusted?.pluginId);\n if (declared.length < mine.length) {\n console.log(\n `[deviceTools] disk-cache recovery: skipped ${mine.length - declared.length} with no recorded manifest grant (fail closed)`,\n );\n }\n if (declared.length === 0) return [];\n\n await Promise.all(declared.map(async (e) => {\n try {\n await bundleManager.loadTools(e.trusted!.pluginId, e.bundleUrl, e.version, e.bundleHash, e.trusted!);\n } catch {\n // A cached bundle that no longer loads is not worth failing a call over.\n }\n }));\n return listDeviceTools().map(t => t.name);\n } catch (err: any) {\n console.warn('[deviceTools] disk-cache recovery failed:', err?.message || String(err));\n return [];\n }\n}\n\n/** Forget that we loaded, so the next call re-reads the catalog. */\nexport function resetDeviceToolLoader(): void {\n loadedOnce = false;\n}\n"],"mappings":";;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;;;ACkBvB,SAAS,gBAAgB,UAA0B;AACxD,SAAO,mBAAmB,mBAAmB,QAAQ,CAAC;AACxD;AAUO,SAAS,kBAAkB,KAAc,UAA2B;AACzE,MAAI,OAAO,QAAQ,SAAU,QAAO;AACpC,QAAM,YAAY,gBAAgB,QAAQ;AAC1C,MAAI,QAAQ,UAAW,QAAO;AAC9B,MAAI;AACF,WAAO,mBAAmB,GAAG,MAAM,mBAAmB,SAAS;AAAA,EACjE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;;;ADmDO,SAAS,eAAe,UAAmC;AAChE,QAAM,OAAO,SAAS,QAAQ;AAC9B,SAAO,SAAS,kBAAkB,SAAS;AAC7C;AAKO,SAAS,qBAAqB,UAAyC;AAC5E,MAAI,SAAS,QAAQ,SAAS,eAAgB,QAAO,SAAS,OAAO;AACrE,MAAI,SAAS,QAAQ,SAAS,WAAY,QAAO,SAAS,OAAO,aAAa;AAC9E,SAAO;AACT;AAaO,SAAS,mBAAmB,UAA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React","useEffect","useCallback","useMemo","useRef","getTenant","View","Text","Pressable","TextInput","ActivityIndicator","StyleSheet","unavailable","useMemo","useEffect","View","Text","Pressable","StyleSheet","Animated","Platform","Svg","ada","View","StyleSheet","Animated","jsx","styles","jsx","jsxs","Platform","Animated","useEffect","styles","Pressable","StyleSheet","View","Text","Svg","ada","View","Text","Pressable","StyleSheet","Platform","ada","borderRadius","jsx","jsxs","fontFam","Platform","Pressable","styles","View","Text","StyleSheet","useEffect","useRef","View","Text","Pressable","StyleSheet","Animated","Platform","Svg","Path","ada","jsx","jsxs","fontFam","styles","cleanup","useEffect","jsx","jsxs","useEffect","useMemo","useRef","useEffect","pluginCommandEmitter","React","useEffect","useCallback","useMemo","useRef","getTenant","_provider","getTenant"]}
|