@ateam-ai-mobile/expo 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/aiLive/provider.d.mts +10 -4
  2. package/dist/aiLive/provider.d.ts +10 -4
  3. package/dist/aiLive/provider.js +119 -43
  4. package/dist/aiLive/provider.js.map +1 -1
  5. package/dist/aiLive/provider.mjs +5 -3
  6. package/dist/bootstrap.js +120 -46
  7. package/dist/bootstrap.js.map +1 -1
  8. package/dist/bootstrap.mjs +4 -4
  9. package/dist/capabilities/index.js +19 -1
  10. package/dist/capabilities/index.js.map +1 -1
  11. package/dist/capabilities/index.mjs +21 -3
  12. package/dist/capabilities/index.mjs.map +1 -1
  13. package/dist/{chunk-BAZFMTCC.mjs → chunk-4HJ5FO3S.mjs} +2 -2
  14. package/dist/{chunk-C62NQA4F.mjs → chunk-GGEFDRQQ.mjs} +2 -2
  15. package/dist/chunk-GGEFDRQQ.mjs.map +1 -0
  16. package/dist/{chunk-OEX4OKYQ.mjs → chunk-NH3CHSLR.mjs} +2 -2
  17. package/dist/{chunk-JUBLG3PN.mjs → chunk-PV2EHH2P.mjs} +119 -44
  18. package/dist/chunk-PV2EHH2P.mjs.map +1 -0
  19. package/dist/device/createDeviceProvider.mjs +3 -3
  20. package/dist/device-bridge/index.js +1 -1
  21. package/dist/device-bridge/index.js.map +1 -1
  22. package/dist/device-bridge/index.mjs +2 -2
  23. package/dist/push/silentSync.js.map +1 -1
  24. package/dist/push/silentSync.mjs +1 -1
  25. package/package.json +4 -4
  26. package/src/aiLive/provider.ts +138 -49
  27. package/src/aiLive/streamProtocol.ts +2 -2
  28. package/src/capabilities/store.ts +21 -1
  29. package/src/device-bridge/capabilities.ts +2 -1
  30. package/dist/chunk-C62NQA4F.mjs.map +0 -1
  31. package/dist/chunk-JUBLG3PN.mjs.map +0 -1
  32. /package/dist/{chunk-BAZFMTCC.mjs.map → chunk-4HJ5FO3S.mjs.map} +0 -0
  33. /package/dist/{chunk-OEX4OKYQ.mjs.map → chunk-NH3CHSLR.mjs.map} +0 -0
@@ -1,10 +1,7 @@
1
1
  import { AiLiveProvider } from '@ateam-ai-mobile/plugin-runtime';
2
2
 
3
- /** The most one phone session may spend (owner decision 2026-10-29), held from the AI Models budget. */
4
- declare const PHONE_SLICE_USD = 0.5;
5
3
  declare const LIVE_KIND = "ai-models.live";
6
4
  interface AiLiveDeps {
7
- callCp(method: string, params?: Record<string, unknown>): Promise<any>;
8
5
  WebSocketImpl: any;
9
6
  wsBase(): string;
10
7
  token(): string | null;
@@ -13,8 +10,17 @@ interface AiLiveDeps {
13
10
  now(): number;
14
11
  setInterval(fn: () => void, ms: number): any;
15
12
  clearInterval(handle: any): void;
13
+ setTimeout(fn: () => void, ms: number): any;
14
+ clearTimeout(handle: any): void;
16
15
  }
16
+ /** Core answers "opened" in one round trip (it starts the session first). Past this, the start gives up
17
+ * and closes the connection, so a start can never hang a screen's queue. */
18
+ declare const OPEN_TIMEOUT_MS = 20000;
19
+ /** A stop waits this long, at most, for its connection to finish closing: Core ends the session when it
20
+ * sees the close, so a restart right after a stop must not open the next one before (Codex on #53).
21
+ * Past this the transport is taken as broken, and Core's own 60 s rule ends that session. */
22
+ declare const CLOSE_WAIT_MS = 3000;
17
23
  declare const defaultAiLiveDeps: () => AiLiveDeps;
18
24
  declare function createAiLiveProvider(overrides?: Partial<AiLiveDeps>): AiLiveProvider;
19
25
 
20
- export { type AiLiveDeps, LIVE_KIND, PHONE_SLICE_USD, createAiLiveProvider, defaultAiLiveDeps };
26
+ export { type AiLiveDeps, CLOSE_WAIT_MS, LIVE_KIND, OPEN_TIMEOUT_MS, createAiLiveProvider, defaultAiLiveDeps };
@@ -1,10 +1,7 @@
1
1
  import { AiLiveProvider } from '@ateam-ai-mobile/plugin-runtime';
2
2
 
3
- /** The most one phone session may spend (owner decision 2026-10-29), held from the AI Models budget. */
4
- declare const PHONE_SLICE_USD = 0.5;
5
3
  declare const LIVE_KIND = "ai-models.live";
6
4
  interface AiLiveDeps {
7
- callCp(method: string, params?: Record<string, unknown>): Promise<any>;
8
5
  WebSocketImpl: any;
9
6
  wsBase(): string;
10
7
  token(): string | null;
@@ -13,8 +10,17 @@ interface AiLiveDeps {
13
10
  now(): number;
14
11
  setInterval(fn: () => void, ms: number): any;
15
12
  clearInterval(handle: any): void;
13
+ setTimeout(fn: () => void, ms: number): any;
14
+ clearTimeout(handle: any): void;
16
15
  }
16
+ /** Core answers "opened" in one round trip (it starts the session first). Past this, the start gives up
17
+ * and closes the connection, so a start can never hang a screen's queue. */
18
+ declare const OPEN_TIMEOUT_MS = 20000;
19
+ /** A stop waits this long, at most, for its connection to finish closing: Core ends the session when it
20
+ * sees the close, so a restart right after a stop must not open the next one before (Codex on #53).
21
+ * Past this the transport is taken as broken, and Core's own 60 s rule ends that session. */
22
+ declare const CLOSE_WAIT_MS = 3000;
17
23
  declare const defaultAiLiveDeps: () => AiLiveDeps;
18
24
  declare function createAiLiveProvider(overrides?: Partial<AiLiveDeps>): AiLiveProvider;
19
25
 
20
- export { type AiLiveDeps, LIVE_KIND, PHONE_SLICE_USD, createAiLiveProvider, defaultAiLiveDeps };
26
+ export { type AiLiveDeps, CLOSE_WAIT_MS, LIVE_KIND, OPEN_TIMEOUT_MS, createAiLiveProvider, defaultAiLiveDeps };
@@ -20,13 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/aiLive/provider.ts
21
21
  var provider_exports = {};
22
22
  __export(provider_exports, {
23
+ CLOSE_WAIT_MS: () => CLOSE_WAIT_MS,
23
24
  LIVE_KIND: () => LIVE_KIND,
24
- PHONE_SLICE_USD: () => PHONE_SLICE_USD,
25
+ OPEN_TIMEOUT_MS: () => OPEN_TIMEOUT_MS,
25
26
  createAiLiveProvider: () => createAiLiveProvider,
26
27
  defaultAiLiveDeps: () => defaultAiLiveDeps
27
28
  });
28
29
  module.exports = __toCommonJS(provider_exports);
29
30
  var import_core = require("@ateam-ai-mobile/core");
31
+ var import_plugin_runtime = require("@ateam-ai-mobile/plugin-runtime");
30
32
 
31
33
  // src/vision/index.ts
32
34
  var import_expo_modules_core = require("expo-modules-core");
@@ -81,8 +83,8 @@ function encodeFrame({ seq, tCapture, payload }) {
81
83
  out.set(payload, HEADER_BYTES);
82
84
  return out;
83
85
  }
84
- function openMessage(kind) {
85
- return JSON.stringify({ type: "open", kind });
86
+ function openMessage(kind, params) {
87
+ return JSON.stringify(params ? { type: "open", kind, params } : { type: "open", kind });
86
88
  }
87
89
  var CLOSE_MESSAGE = JSON.stringify({ type: "close" });
88
90
  function parseServerEvent(text) {
@@ -130,22 +132,14 @@ function base64ToBytes(b64) {
130
132
  }
131
133
 
132
134
  // src/aiLive/provider.ts
133
- var PHONE_SLICE_USD = 0.5;
134
135
  var LIVE_KIND = "ai-models.live";
135
136
  var FRESH_MS = 3e3;
136
137
  var MAX_BUFFERED = 512 * 1024;
137
138
  var DEFAULT_CAMERA = { fps: 1, maxPx: 768 };
138
- var SESSION_UP = /* @__PURE__ */ new Set(["starting", "running", "degraded"]);
139
- async function defaultCallCp(method, params = {}) {
140
- const res = await (0, import_core.mcpToolCall)("cp.ai_models_api", { method, params });
141
- if (res?.error) throw new Error(res.error.message || "AI Models refused the request");
142
- const out = (0, import_core.unwrapMcpResult)(res?.result);
143
- if (res?.result?.isError) throw new Error(typeof out === "string" ? out : out?.message || out?.error || "AI Models refused the request");
144
- if (out && typeof out === "object" && out.ok === false) throw new Error(out.message || out.error || "AI Models refused the request");
145
- return out;
146
- }
139
+ var OPEN_TIMEOUT_MS = 2e4;
140
+ var CLOSE_WAIT_MS = 3e3;
141
+ var isEpisode = (d) => !!d && typeof d === "object" && typeof d.type === "string" && typeof d.class === "string" && typeof d.episodeId === "string" && typeof d.actorId === "string" && d.actorId.length > 0 && Number.isFinite(d.at);
147
142
  var defaultAiLiveDeps = () => ({
148
- callCp: defaultCallCp,
149
143
  WebSocketImpl: globalThis.WebSocket,
150
144
  wsBase: import_core.getCoreWsUrl,
151
145
  token: import_core.getToken,
@@ -153,7 +147,9 @@ var defaultAiLiveDeps = () => ({
153
147
  jpegById,
154
148
  now: Date.now,
155
149
  setInterval: (fn, ms) => setInterval(fn, ms),
156
- clearInterval: (h) => clearInterval(h)
150
+ clearInterval: (h) => clearInterval(h),
151
+ setTimeout: (fn, ms) => setTimeout(fn, ms),
152
+ clearTimeout: (h) => clearTimeout(h)
157
153
  });
158
154
  var idle = () => ({ state: "idle", camera: null, sent: 0, skipped: 0, lastEpisode: null, lastError: null });
159
155
  function createAiLiveProvider(overrides = {}) {
@@ -163,7 +159,11 @@ function createAiLiveProvider(overrides = {}) {
163
159
  let ws = null;
164
160
  let loop = null;
165
161
  let visual = null;
166
- let startedSession = false;
162
+ let allowed = () => false;
163
+ let stopReason = null;
164
+ let tearingDown = null;
165
+ const waitingToStart = /* @__PURE__ */ new Map();
166
+ const closedOf = /* @__PURE__ */ new WeakMap();
167
167
  let closingOnPurpose = false;
168
168
  let seq = 0;
169
169
  let busy = false;
@@ -216,6 +216,12 @@ function createAiLiveProvider(overrides = {}) {
216
216
  const g = gen;
217
217
  const sock = ws;
218
218
  const current = () => g === gen && ws === sock && sock?.readyState === 1;
219
+ const consentGone = () => {
220
+ if (allowed()) return false;
221
+ if (g === gen) void teardown("stopped", import_plugin_runtime.CONSENT_TAKEN_BACK);
222
+ return true;
223
+ };
224
+ if (consentGone()) return;
219
225
  if (busy || !current()) {
220
226
  set({ skipped: snap.skipped + 1 });
221
227
  return;
@@ -236,7 +242,7 @@ function createAiLiveProvider(overrides = {}) {
236
242
  return;
237
243
  }
238
244
  const b64 = await deps.jpegById(id, camera.maxPx, 0.7);
239
- if (!current()) return;
245
+ if (!current() || consentGone()) return;
240
246
  const frame = encodeFrame({ seq: mySeq, tCapture: t, payload: base64ToBytes(b64) });
241
247
  sock.send(frame.buffer);
242
248
  lastFrameId = id;
@@ -260,22 +266,42 @@ function createAiLiveProvider(overrides = {}) {
260
266
  const sock = new deps.WebSocketImpl(url, [SUBPROTOCOL, `adas.bearer.${token}`]);
261
267
  ws = sock;
262
268
  sock.binaryType = "arraybuffer";
269
+ let markClosed = () => {
270
+ };
271
+ closedOf.set(sock, new Promise((r) => {
272
+ markClosed = r;
273
+ }));
274
+ const gaveUp = deps.setTimeout(() => {
275
+ if (opened) return;
276
+ reject(new Error("Core did not answer in time. Try again."));
277
+ try {
278
+ sock.close();
279
+ } catch {
280
+ }
281
+ }, OPEN_TIMEOUT_MS);
263
282
  sock.onopen = () => {
264
283
  try {
265
- sock.send(openMessage(LIVE_KIND));
284
+ sock.send(openMessage(LIVE_KIND, { session: "own", source: "phone" }));
266
285
  } catch (e) {
267
286
  reject(e);
268
287
  }
269
288
  };
270
289
  sock.onmessage = (m) => {
290
+ if (ws !== sock) return;
271
291
  const ev = parseServerEvent(m?.data);
272
292
  if (!ev) return;
293
+ if (ev.event === "session" && !opened) {
294
+ const c = ev.data?.camera;
295
+ camera = c && Number(c.fps) > 0 && Number(c.maxPx) > 0 ? { fps: Number(c.fps), maxPx: Number(c.maxPx) } : DEFAULT_CAMERA;
296
+ return;
297
+ }
273
298
  if (ev.event === "opened" && !opened) {
274
299
  opened = true;
300
+ deps.clearTimeout(gaveUp);
275
301
  resolve();
276
302
  return;
277
303
  }
278
- if (ev.event === "episode" && ev.data && typeof ev.data === "object") {
304
+ if (ev.event === "episode" && isEpisode(ev.data)) {
279
305
  const episode = ev.data;
280
306
  set({ lastEpisode: episode });
281
307
  for (const cb of owner && episodeCbs.get(owner) || []) {
@@ -289,8 +315,10 @@ function createAiLiveProvider(overrides = {}) {
289
315
  sock.onerror = () => {
290
316
  };
291
317
  sock.onclose = (c) => {
318
+ markClosed();
292
319
  const why = describeClose(Number(c?.code), c?.reason);
293
320
  if (!opened) {
321
+ deps.clearTimeout(gaveUp);
294
322
  reject(new Error(why));
295
323
  return;
296
324
  }
@@ -299,9 +327,20 @@ function createAiLiveProvider(overrides = {}) {
299
327
  };
300
328
  });
301
329
  }
302
- async function teardown(state, lastError) {
303
- const hadSession = startedSession;
304
- startedSession = false;
330
+ function teardown(state, lastError) {
331
+ if (tearingDown) return tearingDown;
332
+ const p = teardownNow(state, lastError);
333
+ tearingDown = p;
334
+ void p.then(() => {
335
+ }, () => {
336
+ }).then(() => {
337
+ if (tearingDown === p) tearingDown = null;
338
+ });
339
+ return p;
340
+ }
341
+ async function teardownNow(state, lastError) {
342
+ stopReason = lastError;
343
+ allowed = () => false;
305
344
  gen++;
306
345
  stopTimers();
307
346
  const sock = ws;
@@ -318,21 +357,40 @@ function createAiLiveProvider(overrides = {}) {
318
357
  closingOnPurpose = false;
319
358
  const v = visual;
320
359
  visual = null;
321
- try {
322
- await v?.stop?.();
323
- } catch {
324
- }
325
- if (hadSession) {
326
- try {
327
- await deps.callCp("liveStop");
328
- } catch {
329
- }
330
- }
360
+ let gaveUp = null;
361
+ const closed = sock && closedOf.get(sock);
362
+ await Promise.all([
363
+ (async () => {
364
+ try {
365
+ await v?.stop?.();
366
+ } catch {
367
+ }
368
+ })(),
369
+ closed ? Promise.race([closed, new Promise((r) => {
370
+ gaveUp = deps.setTimeout(r, CLOSE_WAIT_MS);
371
+ })]) : Promise.resolve()
372
+ ]);
373
+ if (gaveUp != null) deps.clearTimeout(gaveUp);
331
374
  owner = null;
332
375
  set({ state, lastError });
333
376
  }
334
377
  return {
335
378
  async start(opts, who, ctx) {
379
+ if (tearingDown) {
380
+ const wait = { cancelled: false };
381
+ waitingToStart.set(who, wait);
382
+ try {
383
+ while (tearingDown) {
384
+ try {
385
+ await tearingDown;
386
+ } catch {
387
+ }
388
+ }
389
+ } finally {
390
+ if (waitingToStart.get(who) === wait) waitingToStart.delete(who);
391
+ }
392
+ if (wait.cancelled) throw Object.assign(new Error("aiLive: stopped before it started."), { code: "STOPPED" });
393
+ }
336
394
  if (owner && owner !== who) throw Object.assign(new Error("aiLive: another screen is sending to AI right now. Close it first."), { code: "CONFLICT" });
337
395
  if (owner === who) return snap;
338
396
  const cam = opts?.camera === "front" ? "front" : "back";
@@ -340,35 +398,52 @@ function createAiLiveProvider(overrides = {}) {
340
398
  owner = who;
341
399
  lastOwner = who;
342
400
  visual = ctx.visual;
401
+ allowed = typeof ctx.allowed === "function" ? ctx.allowed : () => false;
343
402
  gen++;
344
403
  seq = 0;
345
404
  lastFrameId = null;
346
405
  busy = false;
406
+ const g = gen;
407
+ const cameraOfScreen = ctx.visual;
347
408
  snap = { ...idle(), camera: cam };
348
409
  set({ state: "starting" });
410
+ const stillStarting = async () => {
411
+ if (g === gen && !allowed()) await teardown("stopped", import_plugin_runtime.CONSENT_TAKEN_BACK);
412
+ if (g !== gen) throw Object.assign(new Error(stopReason || "aiLive: stopped before it started sending."), { code: "STOPPED" });
413
+ };
349
414
  try {
350
- let session = (await deps.callCp("liveStatus"))?.session;
351
- if (!SESSION_UP.has(session?.state)) {
352
- session = (await deps.callCp("liveStart", { source: "phone", budgetSliceUsd: PHONE_SLICE_USD }))?.session;
353
- startedSession = true;
354
- }
355
- const c = session?.camera;
356
- camera = c && Number(c.fps) > 0 && Number(c.maxPx) > 0 ? { fps: Number(c.fps), maxPx: Number(c.maxPx) } : DEFAULT_CAMERA;
357
- await visual.start({ intent: "stream", facing: cam });
415
+ await stillStarting();
416
+ camera = DEFAULT_CAMERA;
417
+ if (g !== gen) throw Object.assign(new Error(stopReason || "aiLive: stopped before it started sending."), { code: "STOPPED" });
358
418
  await openSocket();
419
+ await stillStarting();
420
+ await cameraOfScreen.start({ intent: "stream", facing: cam });
421
+ if (g !== gen) {
422
+ try {
423
+ await cameraOfScreen.stop?.();
424
+ } catch {
425
+ }
426
+ }
427
+ await stillStarting();
428
+ if (g !== gen) throw Object.assign(new Error(stopReason || "aiLive: stopped before it started sending."), { code: "STOPPED" });
359
429
  loop = deps.setInterval(() => {
360
430
  void slot();
361
431
  }, Math.max(200, Math.round(1e3 / camera.fps)));
362
432
  set({ state: "sending" });
363
433
  return snap;
364
434
  } catch (e) {
435
+ if (g !== gen) {
436
+ throw e?.code === "STOPPED" ? e : Object.assign(new Error(stopReason || "aiLive: stopped before it started sending."), { code: "STOPPED" });
437
+ }
365
438
  await teardown("error", String(e?.message || e));
366
439
  throw e;
367
440
  }
368
441
  },
369
- async stop(who) {
442
+ async stop(who, why) {
443
+ const waiting = waitingToStart.get(who);
444
+ if (waiting) waiting.cancelled = true;
370
445
  if (owner !== who) return;
371
- await teardown("stopped", null);
446
+ await teardown("stopped", why ?? null);
372
447
  },
373
448
  getSnapshot: (who) => lastOwner === who ? snap : idle(),
374
449
  onEpisode: (cb, who) => add(episodeCbs, who, cb),
@@ -392,8 +467,9 @@ function createAiLiveProvider(overrides = {}) {
392
467
  }
393
468
  // Annotate the CommonJS export names for ESM import in node:
394
469
  0 && (module.exports = {
470
+ CLOSE_WAIT_MS,
395
471
  LIVE_KIND,
396
- PHONE_SLICE_USD,
472
+ OPEN_TIMEOUT_MS,
397
473
  createAiLiveProvider,
398
474
  defaultAiLiveDeps
399
475
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/aiLive/provider.ts","../../src/vision/index.ts","../../src/aiLive/streamProtocol.ts"],"sourcesContent":["/**\n * The AI live provider: this phone's camera → the workspace's live session → the chosen AI,\n * and what the AI saw back to the screen. Installed by the host once at startup:\n * import { createAiLiveProvider } from '@ateam-ai-mobile/expo/ai-live';\n * setAiLiveProvider(createAiLiveProvider());\n * A plugin reaches it only through props.aiLive,\n * whose gate (plugin-runtime aiLiveHost) has already checked the two-sided consent.\n *\n * One camera, one sender: while one screen sends, another's start() is refused by name.\n *\n * start():\n * 1. the live session: reuse the one running (an admin may have started it on the AI Models\n * page) or start one for the phone with a capped money slice (PHONE_SLICE_USD), and remember\n * that this phone started it, so stop() ends only what it began;\n * 2. the camera: the screen's held visual session on the requested camera;\n * 3. Core's stream endpoint (/ws/stream, kind \"ai-models.live\"), the login in the subprotocol;\n * 4. once Core says \"opened\": one picture per slot at the TESTED rate and size (the session's\n * `camera`), from the newest fresh frame, as a JPEG made by native (jpegById). A slot with no\n * fresh frame, or while the socket is still busy, sends nothing and still takes its sequence\n * number, so Core reports it as a gap;\n * 5. {\"event\":\"episode\"} from Core → the screen's onEpisode callbacks.\n */\nimport { getCoreWsUrl, getTenant, getToken, mcpToolCall, unwrapMcpResult } from '@ateam-ai-mobile/core';\nimport type { AiLiveEpisode, AiLiveProvider, AiLiveSnapshot, AiLiveStartOptions, DeviceState, Subscription } from '@ateam-ai-mobile/plugin-runtime';\nimport { jpegById as nativeJpegById } from '../vision';\nimport { CLOSE_MESSAGE, STREAM_PATH, SUBPROTOCOL, base64ToBytes, describeClose, encodeFrame, openMessage, parseServerEvent } from './streamProtocol';\n\n/** The most one phone session may spend (owner decision 2026-10-29), held from the AI Models budget. */\nexport const PHONE_SLICE_USD = 0.5;\nexport const LIVE_KIND = 'ai-models.live';\n/** A frame older than this is not \"what the camera sees now\" and is not sent. */\nconst FRESH_MS = 3000;\n/** Bytes still waiting in the socket above which a slot is skipped rather than queued. */\nconst MAX_BUFFERED = 512 * 1024;\nconst DEFAULT_CAMERA = { fps: 1, maxPx: 768 };\n\ntype Visual = DeviceState['visual'];\n\nexport interface AiLiveDeps {\n callCp(method: string, params?: Record<string, unknown>): Promise<any>;\n WebSocketImpl: any;\n wsBase(): string;\n token(): string | null;\n tenant(): string | null;\n jpegById(id: string, maxSide: number, quality: number): Promise<string>;\n now(): number;\n setInterval(fn: () => void, ms: number): any;\n clearInterval(handle: any): void;\n}\n\nconst SESSION_UP = new Set(['starting', 'running', 'degraded']);\n\nasync function defaultCallCp(method: string, params: Record<string, unknown> = {}): Promise<any> {\n const res = await mcpToolCall('cp.ai_models_api', { method, params });\n if (res?.error) throw new Error(res.error.message || 'AI Models refused the request');\n const out = unwrapMcpResult(res?.result);\n if (res?.result?.isError) throw new Error(typeof out === 'string' ? out : out?.message || out?.error || 'AI Models refused the request');\n if (out && typeof out === 'object' && out.ok === false) throw new Error(out.message || out.error || 'AI Models refused the request');\n return out;\n}\n\nexport const defaultAiLiveDeps = (): AiLiveDeps => ({\n callCp: defaultCallCp,\n WebSocketImpl: (globalThis as any).WebSocket,\n wsBase: getCoreWsUrl,\n token: getToken,\n tenant: getTenant,\n jpegById: nativeJpegById,\n now: Date.now,\n setInterval: (fn, ms) => setInterval(fn, ms),\n clearInterval: (h) => clearInterval(h),\n});\n\nconst idle = (): AiLiveSnapshot => ({ state: 'idle', camera: null, sent: 0, skipped: 0, lastEpisode: null, lastError: null });\n\nexport function createAiLiveProvider(overrides: Partial<AiLiveDeps> = {}): AiLiveProvider {\n const deps: AiLiveDeps = { ...defaultAiLiveDeps(), ...overrides };\n let owner: string | null = null; // the screen sending now\n let snap: AiLiveSnapshot = idle();\n let ws: any = null;\n let loop: any = null;\n let visual: Visual | null = null;\n let startedSession = false; // this phone started the live session, so it stops it\n let closingOnPurpose = false;\n let seq = 0;\n let busy = false;\n // Which session a slot belongs to. A slot awaits the camera and the JPEG maker; when the screen\n // stops (or another starts) meanwhile, that slot's picture must go nowhere, not into the next one.\n let gen = 0;\n let lastFrameId: string | null = null;\n let camera = DEFAULT_CAMERA;\n let lastOwner: string | null = null; // whose the current snapshot is (it outlives a stop)\n // Each screen hears only its own session: callbacks are kept per holder.\n const episodeCbs = new Map<string, Set<(ev: AiLiveEpisode) => void>>();\n const snapCbs = new Map<string, Set<(s: AiLiveSnapshot) => void>>();\n const sendingCbs = new Set<() => void>();\n let wasSending = false;\n const add = <T>(m: Map<string, Set<T>>, who: string, cb: T): Subscription => {\n let set = m.get(who);\n if (!set) { set = new Set(); m.set(who, set); }\n set.add(cb);\n return { unsubscribe: () => { set!.delete(cb); } };\n };\n\n const set = (patch: Partial<AiLiveSnapshot>) => {\n snap = { ...snap, ...patch };\n for (const cb of (lastOwner && snapCbs.get(lastOwner)) || []) { try { cb(snap); } catch { /* a listener's error is its own */ } }\n const sending = snap.state === 'starting' || snap.state === 'sending';\n if (sending !== wasSending) { wasSending = sending; for (const cb of sendingCbs) { try { cb(); } catch { /* idem */ } } }\n };\n\n function stopTimers() {\n if (loop != null) { deps.clearInterval(loop); loop = null; }\n }\n\n async function slot() {\n const mySeq = seq++; // every slot takes a number, sent or not\n const g = gen;\n const sock = ws;\n const current = () => g === gen && ws === sock && sock?.readyState === 1;\n if (busy || !current()) { set({ skipped: snap.skipped + 1 }); return; }\n if ((sock.bufferedAmount || 0) > MAX_BUFFERED) { set({ skipped: snap.skipped + 1 }); return; }\n busy = true;\n try {\n const v = await visual!.getSnapshot();\n if (!current()) return;\n const f: any = v?.latest;\n const id = f?.handle?.id;\n const t = Number(f?.timestamp);\n if (!id || id === lastFrameId || !(deps.now() - t < FRESH_MS)) { set({ skipped: snap.skipped + 1 }); return; }\n const b64 = await deps.jpegById(id, camera.maxPx, 0.7);\n if (!current()) return;\n const frame = encodeFrame({ seq: mySeq, tCapture: t, payload: base64ToBytes(b64) });\n sock.send(frame.buffer);\n lastFrameId = id;\n set({ sent: snap.sent + 1 });\n } catch (e: any) {\n if (g === gen) set({ skipped: snap.skipped + 1, lastError: String(e?.message || e) });\n } finally {\n if (g === gen) busy = false;\n }\n }\n\n function openSocket(): Promise<void> {\n return new Promise((resolve, reject) => {\n const token = deps.token();\n const tenant = deps.tenant();\n if (!token || !tenant) { reject(new Error('not signed in to a workspace')); return; }\n const url = `${deps.wsBase()}${STREAM_PATH}?tenant=${encodeURIComponent(tenant)}`;\n let opened = false;\n const sock = new deps.WebSocketImpl(url, [SUBPROTOCOL, `adas.bearer.${token}`]);\n ws = sock;\n sock.binaryType = 'arraybuffer';\n sock.onopen = () => { try { sock.send(openMessage(LIVE_KIND)); } catch (e) { reject(e); } };\n sock.onmessage = (m: any) => {\n const ev = parseServerEvent(m?.data);\n if (!ev) return;\n if (ev.event === 'opened' && !opened) { opened = true; resolve(); return; }\n if (ev.event === 'episode' && ev.data && typeof ev.data === 'object') {\n const episode = ev.data as AiLiveEpisode;\n set({ lastEpisode: episode });\n for (const cb of (owner && episodeCbs.get(owner)) || []) { try { cb(episode); } catch { /* a listener's error is its own */ } }\n }\n };\n sock.onerror = () => { /* the close that follows says why */ };\n sock.onclose = (c: any) => {\n const why = describeClose(Number(c?.code), c?.reason);\n if (!opened) { reject(new Error(why)); return; }\n if (closingOnPurpose || ws !== sock) return;\n void teardown('error', why);\n };\n });\n }\n\n async function teardown(state: 'stopped' | 'error', lastError: string | null) {\n const hadSession = startedSession;\n startedSession = false;\n gen++;\n stopTimers();\n const sock = ws;\n ws = null;\n closingOnPurpose = true;\n try { if (sock && sock.readyState === 1) sock.send(CLOSE_MESSAGE); } catch { /* closing anyway */ }\n try { sock?.close?.(); } catch { /* already closed */ }\n closingOnPurpose = false;\n const v = visual;\n visual = null;\n try { await v?.stop?.(); } catch { /* the camera hold is released by the gate too */ }\n if (hadSession) { try { await deps.callCp('liveStop'); } catch { /* the session ends by itself when no picture arrives */ } }\n owner = null;\n set({ state, lastError });\n }\n\n return {\n async start(opts: AiLiveStartOptions, who: string, ctx: { visual: Visual }) {\n if (owner && owner !== who) throw Object.assign(new Error('aiLive: another screen is sending to AI right now. Close it first.'), { code: 'CONFLICT' });\n if (owner === who) return snap;\n const cam = opts?.camera === 'front' ? 'front' : 'back';\n if (opts?.camera && opts.camera !== 'front' && opts.camera !== 'back') throw new Error(`aiLive: unknown camera \"${String(opts.camera)}\" — use \"front\" or \"back\"`);\n owner = who;\n lastOwner = who;\n visual = ctx.visual;\n gen++; seq = 0; lastFrameId = null; busy = false;\n snap = { ...idle(), camera: cam };\n set({ state: 'starting' });\n try {\n let session = (await deps.callCp('liveStatus'))?.session;\n if (!SESSION_UP.has(session?.state)) {\n session = (await deps.callCp('liveStart', { source: 'phone', budgetSliceUsd: PHONE_SLICE_USD }))?.session;\n startedSession = true;\n }\n const c = session?.camera;\n camera = c && Number(c.fps) > 0 && Number(c.maxPx) > 0 ? { fps: Number(c.fps), maxPx: Number(c.maxPx) } : DEFAULT_CAMERA;\n await visual.start({ intent: 'stream', facing: cam } as any);\n await openSocket();\n loop = deps.setInterval(() => { void slot(); }, Math.max(200, Math.round(1000 / camera.fps)));\n set({ state: 'sending' });\n return snap;\n } catch (e: any) {\n await teardown('error', String(e?.message || e));\n throw e;\n }\n },\n async stop(who: string) {\n if (owner !== who) return;\n await teardown('stopped', null);\n },\n getSnapshot: (who: string) => (lastOwner === who ? snap : idle()),\n onEpisode: (cb, who) => add(episodeCbs, who, cb),\n subscribe: (cb, who) => add(snapCbs, who, cb),\n forget(who: string) {\n episodeCbs.delete(who);\n snapCbs.delete(who);\n if (lastOwner === who && owner === null) { lastOwner = null; snap = idle(); }\n },\n isSending: () => snap.state === 'starting' || snap.state === 'sending',\n subscribeSending(cb) {\n sendingCbs.add(cb);\n return { unsubscribe: () => { sendingCbs.delete(cb); } } as Subscription;\n },\n };\n}\n","// ada-vision — on-device image understanding, our own native code (no camera lib).\n//\n// On-device, frames never leave the phone:\n// assessQuality(uri) — one-shot quality of a LOCAL frame file.\n// startVision()/onVisionFrame — the headless camera session that publishes a\n// timeline frame (id + quality, never pixels) at a\n// cadence; readText/describe/detectObjects resolve\n// a published id ON-DEVICE.\n//\n// The luma math mirrors ./analysis.js (which has the exhaustive unit tests).\n//\n// requireOptionalNativeModule: on a binary WITHOUT the native module, the import\n// is null, isSupported() is false, and the session calls refuse cleanly (no crash).\n\nimport type { ComponentType } from 'react';\nimport { requireOptionalNativeModule } from 'expo-modules-core';\nimport { requireNativeView } from 'expo';\n\n/** TEST-ONLY live preview bound to the same headless session (so a tester can\n * aim). The real Guide runs headless and never mounts this. Null on a binary\n * without the native view, so importing this module never crashes. */\nexport const CameraPreview: ComponentType<any> | null = (() => {\n try { return requireNativeView('AdaVision'); } catch { return null; }\n})();\n\nexport interface RawFrameQuality {\n blur: 'sharp' | 'slight' | 'severe' | 'unknown';\n exposure: 'good' | 'dark' | 'bright' | 'unknown';\n /** true = lens covered; false = clearly not; null = not assessed. */\n obstructed: boolean | null;\n}\n\ninterface Subscription { remove(): void }\n\n/** A published timeline frame from the vision session (metadata only — never\n * pixels; the buffer stays in the native ring, resolved by id). */\nexport interface VisionFrame {\n id: string;\n ts: number;\n expiresAt: number;\n blur: RawFrameQuality['blur'];\n exposure: RawFrameQuality['exposure'];\n obstructed: RawFrameQuality['obstructed'];\n}\n\n/** One OCR result on a frame — matches the SDK's VisionText. */\nexport interface VisionText {\n text: string;\n /** 0..1 recogniser confidence (never a 1.0 filler). */\n confidence: number | null;\n /** Normalised 0..1 box, origin TOP-left, in the UPRIGHT portrait frame (native\n * rotates frames at capture) — x runs from the user's left to their right. */\n box?: { x: number; y: number; width: number; height: number };\n}\n\n/** One classifier label — a vocabulary term, NOT prose. Matches VisionLabel. */\nexport interface VisionLabel {\n label: string;\n confidence: number | null;\n}\n\n/** One detected object — a located item with a box, from the bundled detector. */\nexport interface VisionObject {\n /** Open-Images class name (e.g. \"Car\", \"Traffic light\", \"Building\", \"Person\"). */\n label: string;\n /** 0..1 detector confidence. */\n confidence: number | null;\n /** Normalised 0..1 box, origin TOP-left, in the UPRIGHT portrait frame (native\n * rotates frames at capture) — x runs from the user's left to their right. */\n box?: { x: number; y: number; width: number; height: number };\n}\n\ninterface AdaVisionNative {\n isSupported(): boolean;\n assessQuality(uri: string): Promise<RawFrameQuality>;\n startVision(intervalMs: number): Promise<void>;\n /** Absent from binaries built before the front camera existed. */\n startVisionCamera?(intervalMs: number, facing: VisionFacing): Promise<void>;\n /** Absent from binaries built before AI live existed. A base64 JPEG. */\n jpegById?(id: string, maxSide: number, quality: number): Promise<string>;\n stopVision(): void;\n visionRetentionMs(): number;\n qualityById(id: string): RawFrameQuality | null;\n readText(id: string, languages: string[] | null): Promise<VisionText[]>;\n describe(id: string, maxLabels: number): Promise<VisionLabel[]>;\n detectObjects(id: string, maxItems: number, minConfidence: number): Promise<VisionObject[]>;\n addListener(event: 'visionFrame', cb: (f: VisionFrame) => void): Subscription;\n}\n\nconst native = requireOptionalNativeModule<AdaVisionNative>('AdaVision');\n\n/** The native function, or a refusal by name: Android's AdaVision has assessQuality only\n * (AI Models F4), so a verb it lacks says so instead of failing as \"not a function\". */\nfunction verb<K extends keyof AdaVisionNative>(name: K): AdaVisionNative[K] {\n if (!native) throw new Error('ada-vision native module not present in this build');\n const fn = native[name];\n if (typeof fn !== 'function') {\n throw Object.assign(new Error(`UNAVAILABLE: ada-vision ${String(name)} is not implemented on this platform (iOS only)`), { code: 'UNAVAILABLE' });\n }\n return (fn as Function).bind(native) as AdaVisionNative[K];\n}\n\n/** Is the native vision module present in this binary? */\nexport function isSupported(): boolean {\n try { return native?.isSupported() ?? false; } catch { return false; }\n}\n\n/** One-shot: measure a frame's quality from its LOCAL file. Throws if it cannot look. */\nexport async function assessQuality(uri: string): Promise<RawFrameQuality> {\n if (!native) throw new Error('ada-vision native module not present in this build');\n return native.assessQuality(uri);\n}\n\n// ── Vision session (feeds the Visual Engine) ──\n\n/** Which camera the vision session reads. */\nexport type VisionFacing = 'front' | 'back';\n\n/**\n * Start the vision session on `facing` — publishes a timeline frame every\n * `intervalMs`. The back camera works on every binary; the front camera needs a\n * binary built with it, and an older one REFUSES it rather than quietly reading\n * the back camera instead.\n */\nexport async function startVision(intervalMs = 1000, facing: VisionFacing = 'back'): Promise<void> {\n if (facing !== 'front' && facing !== 'back') {\n throw new Error(`Unknown camera \"${String(facing)}\" — use \"front\" or \"back\"`);\n }\n if (facing === 'back') return verb('startVision')(intervalMs);\n if (native && typeof native.startVisionCamera !== 'function') {\n throw new Error('the front camera needs a newer app build — this one can read the back camera only');\n }\n return verb('startVisionCamera')!(intervalMs, facing);\n}\n\n/** Stop the vision session and release the camera. */\nexport function stopVision(): void {\n native?.stopVision?.();\n}\n\n/** Subscribe to published timeline frames (id + quality + expiry; no pixels). */\nexport function onVisionFrame(cb: (f: VisionFrame) => void): Subscription {\n if (!native) return { remove() {} };\n return native.addListener('visionFrame', cb);\n}\n\n/** How far back the native ring can still resolve a frame id (ms). */\nexport function visionRetentionMs(): number {\n return native?.visionRetentionMs?.() ?? 0;\n}\n\n/** Resolve a published frame id → its measured quality (null if evicted). */\nexport function qualityById(id: string): RawFrameQuality | null {\n return native?.qualityById?.(id) ?? null;\n}\n\n/** On-device OCR on a published frame. [] = looked, no text; throws = couldn't look. */\nexport async function readText(id: string, languages?: string[]): Promise<VisionText[]> {\n return verb('readText')(id, languages ?? null);\n}\n\n/** On-device image classification → labels (not prose). [] = nothing recognised. */\nexport async function describe(id: string, maxLabels = 5): Promise<VisionLabel[]> {\n return verb('describe')(id, maxLabels);\n}\n\n/** On-device object detection (bundled YOLOv8n, Open-Images vocabulary) → located\n * items with boxes. [] = looked, found nothing above `minConfidence`; throws =\n * couldn't look (id aged out, or the model isn't in this build). */\nexport async function detectObjects(id: string, maxItems = 10, minConfidence = 0.25): Promise<VisionObject[]> {\n return verb('detectObjects')(id, maxItems, minConfidence);\n}\n\n/**\n * A published frame as a base64 JPEG, its longer side at most `maxSide`. FOR THE SDK'S AI LIVE SENDER ONLY\n * (aiLive/provider.ts), which calls it after the two-sided \"Pictures to AI\" consent: this is the one way a\n * picture leaves native, and no plugin-facing API reaches it. An older binary refuses by name.\n */\nexport async function jpegById(id: string, maxSide = 768, quality = 0.7): Promise<string> {\n if (native && typeof native.jpegById !== 'function') {\n throw new Error('sending pictures to AI needs a newer app build — this one cannot make a picture from a camera frame');\n }\n return verb('jpegById')!(id, maxSide, quality);\n}\n","/**\n * The wire protocol of Core's binary stream endpoint (/ws/stream), for the AI live sender.\n *\n * A PORT of Core's `packages/media-stream/src/index.js` (@ateam-ai/media-stream, not on npm\n * yet), limited to what a sender needs. The frame bytes are pinned by\n * tests/aiLiveStreamProtocol.test.mjs against the layout that file documents, so a drift is\n * a red test, not a silent mismatch. DEAD — replace with an import of @ateam-ai/media-stream\n * once Core publishes it.\n *\n * Frame envelope (bytes): 0 version (1) · 1 flags · 2-5 seq uint32 BE (one per sampling slot\n * of the SENDER, taken or skipped) · 6-13 tCapture float64 BE (ms since the epoch) · 14- payload.\n */\nexport const STREAM_PATH = '/ws/stream';\nexport const SUBPROTOCOL = 'adas.v1';\nexport const HEADER_BYTES = 14;\nconst ENVELOPE_VERSION = 1;\n\nexport const CLOSE = Object.freeze({\n AUTH_MISSING: 4001,\n AUTH_FAILED: 4002,\n NO_SUCH_WORKSPACE: 4003,\n NOT_ENTITLED: 4004,\n BAD_REQUEST: 4400,\n UNKNOWN_KIND: 4404,\n TIMEOUT: 4408,\n OVER_LIMIT: 4429,\n TOO_BIG: 1009,\n CONSUMER_FAILING: 1011,\n});\n\nexport function encodeFrame({ seq, tCapture, payload }: { seq: number; tCapture: number; payload: Uint8Array }): Uint8Array {\n const out = new Uint8Array(HEADER_BYTES + payload.length);\n const v = new DataView(out.buffer);\n v.setUint8(0, ENVELOPE_VERSION);\n v.setUint8(1, 0);\n v.setUint32(2, seq >>> 0, false);\n v.setFloat64(6, tCapture, false);\n out.set(payload, HEADER_BYTES);\n return out;\n}\n\nexport function openMessage(kind: string): string {\n return JSON.stringify({ type: 'open', kind });\n}\n\nexport const CLOSE_MESSAGE = JSON.stringify({ type: 'close' });\n\n/** A server text frame → { event, data }, or null for anything that is not an event. */\nexport function parseServerEvent(text: unknown): { event: string; data: any } | null {\n if (typeof text !== 'string') return null;\n try {\n const m = JSON.parse(text);\n return m && typeof m.event === 'string' ? { event: m.event, data: m.data } : null;\n } catch {\n return null;\n }\n}\n\nconst WHY: Record<number, string> = {\n [CLOSE.AUTH_MISSING]: 'The login or the workspace was missing. Sign in again and try once more.',\n [CLOSE.AUTH_FAILED]: 'The login was refused. Sign in again and try once more.',\n [CLOSE.NO_SUCH_WORKSPACE]: 'This workspace was not found.',\n [CLOSE.NOT_ENTITLED]: 'This workspace may not stream right now.',\n [CLOSE.TIMEOUT]: 'The connection to the AI timed out.',\n [CLOSE.OVER_LIMIT]: 'Too many cameras are sending to this workspace. Stop another one first.',\n [CLOSE.TOO_BIG]: 'A picture was too big to send.',\n [CLOSE.CONSUMER_FAILING]: 'The AI stopped taking pictures. Check the live session in AI Models.',\n};\n\n/** A close as one plain sentence: the server's own words for a refused open. */\nexport function describeClose(code: number, reason?: string): string {\n if (code === CLOSE.BAD_REQUEST && reason) return reason;\n return WHY[code] || (reason ? reason : `The connection to the AI closed (${code}).`);\n}\n\nconst B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\nconst B64_INDEX = (() => { const t = new Int16Array(256).fill(-1); for (let i = 0; i < 64; i++) t[B64.charCodeAt(i)] = i; return t; })();\n\n/** Base64 (the native module's JPEG) → bytes. Ignores padding and line breaks. */\nexport function base64ToBytes(b64: string): Uint8Array {\n const clean = b64.replace(/[^A-Za-z0-9+/]/g, '');\n const out = new Uint8Array(Math.floor((clean.length * 3) / 4));\n let o = 0, acc = 0, bits = 0;\n for (let i = 0; i < clean.length; i++) {\n acc = (acc << 6) | B64_INDEX[clean.charCodeAt(i)];\n bits += 6;\n if (bits >= 8) { bits -= 8; out[o++] = (acc >> bits) & 0xff; }\n }\n return o === out.length ? out : out.subarray(0, o);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,kBAAgF;;;ACPhF,+BAA4C;AAC5C,kBAAkC;AAK3B,IAAM,iBAA4C,MAAM;AAC7D,MAAI;AAAE,eAAO,+BAAkB,WAAW;AAAA,EAAG,QAAQ;AAAE,WAAO;AAAA,EAAM;AACtE,GAAG;AAkEH,IAAM,aAAS,sDAA6C,WAAW;AAIvE,SAAS,KAAsC,MAA6B;AAC1E,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,oDAAoD;AACjF,QAAM,KAAK,OAAO,IAAI;AACtB,MAAI,OAAO,OAAO,YAAY;AAC5B,UAAM,OAAO,OAAO,IAAI,MAAM,2BAA2B,OAAO,IAAI,CAAC,iDAAiD,GAAG,EAAE,MAAM,cAAc,CAAC;AAAA,EAClJ;AACA,SAAQ,GAAgB,KAAK,MAAM;AACrC;AA8EA,eAAsB,SAAS,IAAY,UAAU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O,MAAM,EAAE,QAAQ,UAAU,QAAQ,IAAI,CAAQ;AAC3D,cAAM,WAAW;AACjB,eAAO,KAAK,YAAY,MAAM;AAAE,eAAK,KAAK;AAAA,QAAG,GAAG,KAAK,IAAI,KAAK,KAAK,MAAM,MAAO,OAAO,GAAG,CAAC,CAAC;AAC5F,YAAI,EAAE,OAAO,UAAU,CAAC;AACxB,eAAO;AAAA,MACT,SAAS,GAAQ;AACf,cAAM,SAAS,SAAS,OAAO,GAAG,WAAW,CAAC,CAAC;AAC/C,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,MAAM,KAAK,KAAa;AACtB,UAAI,UAAU,IAAK;AACnB,YAAM,SAAS,WAAW,IAAI;AAAA,IAChC;AAAA,IACA,aAAa,CAAC,QAAiB,cAAc,MAAM,OAAO,KAAK;AAAA,IAC/D,WAAW,CAAC,IAAI,QAAQ,IAAI,YAAY,KAAK,EAAE;AAAA,IAC/C,WAAW,CAAC,IAAI,QAAQ,IAAI,SAAS,KAAK,EAAE;AAAA,IAC5C,OAAO,KAAa;AAClB,iBAAW,OAAO,GAAG;AACrB,cAAQ,OAAO,GAAG;AAClB,UAAI,cAAc,OAAO,UAAU,MAAM;AAAE,oBAAY;AAAM,eAAO,KAAK;AAAA,MAAG;AAAA,IAC9E;AAAA,IACA,WAAW,MAAM,KAAK,UAAU,cAAc,KAAK,UAAU;AAAA,IAC7D,iBAAiB,IAAI;AACnB,iBAAW,IAAI,EAAE;AACjB,aAAO,EAAE,aAAa,MAAM;AAAE,mBAAW,OAAO,EAAE;AAAA,MAAG,EAAE;AAAA,IACzD;AAAA,EACF;AACF;","names":["set"]}
1
+ {"version":3,"sources":["../../src/aiLive/provider.ts","../../src/vision/index.ts","../../src/aiLive/streamProtocol.ts"],"sourcesContent":["/**\n * The AI live provider: this phone's camera → the workspace's live session → the chosen AI,\n * and what the AI saw back to the screen. Installed by the host once at startup:\n * import { createAiLiveProvider } from '@ateam-ai-mobile/expo/ai-live';\n * setAiLiveProvider(createAiLiveProvider());\n * A plugin reaches it only through props.aiLive,\n * whose gate (plugin-runtime aiLiveHost) has already checked the two-sided consent. The gate\n * passes that check as ctx.allowed, and it is asked again right before every picture: once the\n * person takes the yes back, nothing more is sent and the session stops (GPT review 2026-10-30).\n *\n * One camera, one sender: while one screen sends, another's start() is refused by name.\n *\n * ONE CONNECTION IS THE SESSION (owner direction 2026-10-30). start():\n * 1. opens Core's stream endpoint (/ws/stream, kind \"ai-models.live\", the login in the\n * subprotocol) asking for a session of its own (params.session \"own\"). That one round trip\n * IS starting the person's live session: Core starts it with its own $0.50 cap, refuses in\n * plain words when the person already has one running (never joins), and says how to send\n * ({\"event\":\"session\"}: the rate and size the setup was tested at) before \"opened\";\n * 2. turns on the screen's held camera on the requested side;\n * 3. sends one picture per slot at that rate and size, from the newest fresh frame, as a JPEG\n * made by native (jpegById). A slot with no fresh frame, or while the socket is still busy,\n * sends nothing and still takes its sequence number, so Core reports it as a gap;\n * 4. {\"event\":\"episode\"} from Core → the screen's onEpisode callbacks.\n * stop() closes the connection and the camera; Core ends the session when the connection ends,\n * whatever ended it (a stop, the screen closing, the app killed, the network lost).\n */\nimport { getCoreWsUrl, getTenant, getToken } from '@ateam-ai-mobile/core';\nimport { CONSENT_TAKEN_BACK } from '@ateam-ai-mobile/plugin-runtime';\nimport type { AiLiveEpisode, AiLiveProvider, AiLiveSnapshot, AiLiveStartOptions, DeviceState, Subscription } from '@ateam-ai-mobile/plugin-runtime';\nimport { jpegById as nativeJpegById } from '../vision';\nimport { CLOSE_MESSAGE, STREAM_PATH, SUBPROTOCOL, base64ToBytes, describeClose, encodeFrame, openMessage, parseServerEvent } from './streamProtocol';\n\nexport const LIVE_KIND = 'ai-models.live';\n/** A frame older than this is not \"what the camera sees now\" and is not sent. */\nconst FRESH_MS = 3000;\n/** Bytes still waiting in the socket above which a slot is skipped rather than queued. */\nconst MAX_BUFFERED = 512 * 1024;\nconst DEFAULT_CAMERA = { fps: 1, maxPx: 768 };\n\ntype Visual = DeviceState['visual'];\n\nexport interface AiLiveDeps {\n WebSocketImpl: any;\n wsBase(): string;\n token(): string | null;\n tenant(): string | null;\n jpegById(id: string, maxSide: number, quality: number): Promise<string>;\n now(): number;\n setInterval(fn: () => void, ms: number): any;\n clearInterval(handle: any): void;\n setTimeout(fn: () => void, ms: number): any;\n clearTimeout(handle: any): void;\n}\n\n/** Core answers \"opened\" in one round trip (it starts the session first). Past this, the start gives up\n * and closes the connection, so a start can never hang a screen's queue. */\nexport const OPEN_TIMEOUT_MS = 20_000;\n/** A stop waits this long, at most, for its connection to finish closing: Core ends the session when it\n * sees the close, so a restart right after a stop must not open the next one before (Codex on #53).\n * Past this the transport is taken as broken, and Core's own 60 s rule ends that session. */\nexport const CLOSE_WAIT_MS = 3_000;\n\nconst isEpisode = (d: any): d is AiLiveEpisode =>\n !!d && typeof d === 'object' && typeof d.type === 'string' && typeof d.class === 'string' &&\n typeof d.episodeId === 'string' && typeof d.actorId === 'string' && d.actorId.length > 0 && Number.isFinite(d.at);\n\nexport const defaultAiLiveDeps = (): AiLiveDeps => ({\n WebSocketImpl: (globalThis as any).WebSocket,\n wsBase: getCoreWsUrl,\n token: getToken,\n tenant: getTenant,\n jpegById: nativeJpegById,\n now: Date.now,\n setInterval: (fn, ms) => setInterval(fn, ms),\n clearInterval: (h) => clearInterval(h),\n setTimeout: (fn, ms) => setTimeout(fn, ms),\n clearTimeout: (h) => clearTimeout(h),\n});\n\nconst idle = (): AiLiveSnapshot => ({ state: 'idle', camera: null, sent: 0, skipped: 0, lastEpisode: null, lastError: null });\n\nexport function createAiLiveProvider(overrides: Partial<AiLiveDeps> = {}): AiLiveProvider {\n const deps: AiLiveDeps = { ...defaultAiLiveDeps(), ...overrides };\n let owner: string | null = null; // the screen sending now\n let snap: AiLiveSnapshot = idle();\n let ws: any = null;\n let loop: any = null;\n let visual: Visual | null = null;\n let allowed: () => boolean = () => false; // the two-sided consent, asked before every picture\n let stopReason: string | null = null; // why the last teardown happened, known before it finishes\n // A teardown still finishing (the camera, the connection): a start waits for it, so a quick restart neither\n // reads the old session as its own nor is cleared by it afterwards (Codex on #53). Every teardown is\n // tracked, the ones the provider starts itself (consent gone, the connection dropped) included.\n let tearingDown: Promise<void> | null = null;\n // Screens whose start is waiting for that teardown, before they own anything: a stop meanwhile cancels\n // the start (it would otherwise go ahead after the screen had stopped or closed; Codex on #53).\n const waitingToStart = new Map<string, { cancelled: boolean }>();\n /** Each connection's \"it has closed\": a stop waits for it (CLOSE_WAIT_MS at most). */\n const closedOf = new WeakMap<object, Promise<void>>();\n let closingOnPurpose = false;\n let seq = 0;\n let busy = false;\n // Which session a slot belongs to. A slot awaits the camera and the JPEG maker; when the screen\n // stops (or another starts) meanwhile, that slot's picture must go nowhere, not into the next one.\n let gen = 0;\n let lastFrameId: string | null = null;\n let camera = DEFAULT_CAMERA;\n let lastOwner: string | null = null; // whose the current snapshot is (it outlives a stop)\n // Each screen hears only its own session: callbacks are kept per holder.\n const episodeCbs = new Map<string, Set<(ev: AiLiveEpisode) => void>>();\n const snapCbs = new Map<string, Set<(s: AiLiveSnapshot) => void>>();\n const sendingCbs = new Set<() => void>();\n let wasSending = false;\n const add = <T>(m: Map<string, Set<T>>, who: string, cb: T): Subscription => {\n let set = m.get(who);\n if (!set) { set = new Set(); m.set(who, set); }\n set.add(cb);\n return { unsubscribe: () => { set!.delete(cb); } };\n };\n\n const set = (patch: Partial<AiLiveSnapshot>) => {\n snap = { ...snap, ...patch };\n for (const cb of (lastOwner && snapCbs.get(lastOwner)) || []) { try { cb(snap); } catch { /* a listener's error is its own */ } }\n const sending = snap.state === 'starting' || snap.state === 'sending';\n if (sending !== wasSending) { wasSending = sending; for (const cb of sendingCbs) { try { cb(); } catch { /* idem */ } } }\n };\n\n function stopTimers() {\n if (loop != null) { deps.clearInterval(loop); loop = null; }\n }\n\n async function slot() {\n const mySeq = seq++; // every slot takes a number, sent or not\n const g = gen;\n const sock = ws;\n const current = () => g === gen && ws === sock && sock?.readyState === 1;\n const consentGone = () => { if (allowed()) return false; if (g === gen) void teardown('stopped', CONSENT_TAKEN_BACK); return true; };\n if (consentGone()) return;\n if (busy || !current()) { set({ skipped: snap.skipped + 1 }); return; }\n if ((sock.bufferedAmount || 0) > MAX_BUFFERED) { set({ skipped: snap.skipped + 1 }); return; }\n busy = true;\n try {\n const v = await visual!.getSnapshot();\n if (!current()) return;\n const f: any = v?.latest;\n const id = f?.handle?.id;\n const t = Number(f?.timestamp);\n if (!id || id === lastFrameId || !(deps.now() - t < FRESH_MS)) { set({ skipped: snap.skipped + 1 }); return; }\n const b64 = await deps.jpegById(id, camera.maxPx, 0.7);\n if (!current() || consentGone()) return;\n const frame = encodeFrame({ seq: mySeq, tCapture: t, payload: base64ToBytes(b64) });\n sock.send(frame.buffer);\n lastFrameId = id;\n set({ sent: snap.sent + 1 });\n } catch (e: any) {\n if (g === gen) set({ skipped: snap.skipped + 1, lastError: String(e?.message || e) });\n } finally {\n if (g === gen) busy = false;\n }\n }\n\n function openSocket(): Promise<void> {\n return new Promise((resolve, reject) => {\n const token = deps.token();\n const tenant = deps.tenant();\n if (!token || !tenant) { reject(new Error('not signed in to a workspace')); return; }\n const url = `${deps.wsBase()}${STREAM_PATH}?tenant=${encodeURIComponent(tenant)}`;\n let opened = false;\n const sock = new deps.WebSocketImpl(url, [SUBPROTOCOL, `adas.bearer.${token}`]);\n ws = sock;\n sock.binaryType = 'arraybuffer';\n let markClosed: () => void = () => {};\n closedOf.set(sock, new Promise<void>((r) => { markClosed = r; }));\n const gaveUp = deps.setTimeout(() => {\n if (opened) return;\n reject(new Error('Core did not answer in time. Try again.'));\n try { sock.close(); } catch { /* closing anyway */ }\n }, OPEN_TIMEOUT_MS);\n // Its own session: opening IS starting it, and Core ends it when this connection ends.\n sock.onopen = () => { try { sock.send(openMessage(LIVE_KIND, { session: 'own', source: 'phone' })); } catch (e) { reject(e); } };\n sock.onmessage = (m: any) => {\n // Only the current connection speaks for the current session. A message from a connection\n // already stopped or replaced (it can still be queued after a stop, a restart or a switch to\n // another screen) is dropped whole: its episode never reaches a newer screen, and its \"session\"\n // or \"opened\" never touches a newer connection (GPT code review v5).\n if (ws !== sock) return;\n const ev = parseServerEvent(m?.data);\n if (!ev) return;\n if (ev.event === 'session' && !opened) {\n const c = ev.data?.camera;\n camera = c && Number(c.fps) > 0 && Number(c.maxPx) > 0 ? { fps: Number(c.fps), maxPx: Number(c.maxPx) } : DEFAULT_CAMERA;\n return;\n }\n if (ev.event === 'opened' && !opened) { opened = true; deps.clearTimeout(gaveUp); resolve(); return; }\n // Only a whole episode reaches the screen: what happened, of which class, and whose camera saw it\n // (actorId: live sessions are per person). Anything less is dropped, never passed on half-made.\n if (ev.event === 'episode' && isEpisode(ev.data)) {\n const episode = ev.data;\n set({ lastEpisode: episode });\n for (const cb of (owner && episodeCbs.get(owner)) || []) { try { cb(episode); } catch { /* a listener's error is its own */ } }\n }\n };\n sock.onerror = () => { /* the close that follows says why */ };\n sock.onclose = (c: any) => {\n markClosed();\n const why = describeClose(Number(c?.code), c?.reason);\n if (!opened) { deps.clearTimeout(gaveUp); reject(new Error(why)); return; }\n if (closingOnPurpose || ws !== sock) return;\n void teardown('error', why);\n };\n });\n }\n\n function teardown(state: 'stopped' | 'error', lastError: string | null): Promise<void> {\n // One at a time: a second stop while one is finishing joins it (Codex on #53). Two at once could\n // finish out of order and the first, resuming late, would stop a session started in between.\n if (tearingDown) return tearingDown;\n const p = teardownNow(state, lastError);\n tearingDown = p;\n void p.then(() => {}, () => {}).then(() => { if (tearingDown === p) tearingDown = null; });\n return p;\n }\n\n // Closing the connection ends the session (Core); the camera is this phone's to stop.\n async function teardownNow(state: 'stopped' | 'error', lastError: string | null) {\n stopReason = lastError;\n allowed = () => false;\n gen++;\n stopTimers();\n const sock = ws;\n ws = null;\n closingOnPurpose = true;\n try { if (sock && sock.readyState === 1) sock.send(CLOSE_MESSAGE); } catch { /* closing anyway */ }\n try { sock?.close?.(); } catch { /* already closed */ }\n closingOnPurpose = false;\n const v = visual;\n visual = null;\n // The camera off, and the connection really closed (so Core has ended its session) before this stop\n // is done: a start right after it then never meets the old session (Codex on #53).\n let gaveUp: any = null;\n const closed = sock && closedOf.get(sock);\n await Promise.all([\n (async () => { try { await v?.stop?.(); } catch { /* the camera hold is released by the gate too */ } })(),\n closed ? Promise.race([closed, new Promise<void>((r) => { gaveUp = deps.setTimeout(r, CLOSE_WAIT_MS); })]) : Promise.resolve(),\n ]);\n if (gaveUp != null) deps.clearTimeout(gaveUp);\n owner = null;\n set({ state, lastError });\n }\n\n return {\n async start(opts: AiLiveStartOptions, who: string, ctx: { visual: Visual; allowed: () => boolean }) {\n if (tearingDown) {\n const wait = { cancelled: false };\n waitingToStart.set(who, wait);\n try {\n while (tearingDown) { try { await tearingDown; } catch { /* it stopped either way */ } }\n } finally {\n if (waitingToStart.get(who) === wait) waitingToStart.delete(who);\n }\n if (wait.cancelled) throw Object.assign(new Error('aiLive: stopped before it started.'), { code: 'STOPPED' });\n }\n if (owner && owner !== who) throw Object.assign(new Error('aiLive: another screen is sending to AI right now. Close it first.'), { code: 'CONFLICT' });\n if (owner === who) return snap;\n const cam = opts?.camera === 'front' ? 'front' : 'back';\n if (opts?.camera && opts.camera !== 'front' && opts.camera !== 'back') throw new Error(`aiLive: unknown camera \"${String(opts.camera)}\" — use \"front\" or \"back\"`);\n owner = who;\n lastOwner = who;\n visual = ctx.visual;\n allowed = typeof ctx.allowed === 'function' ? ctx.allowed : () => false;\n gen++; seq = 0; lastFrameId = null; busy = false;\n const g = gen;\n const cameraOfScreen = ctx.visual;\n snap = { ...idle(), camera: cam };\n set({ state: 'starting' });\n // Starting takes several awaits, and the screen may be stopped, or the yes taken back,\n // during any of them (Codex P1 on #53). After each: a stop already tore it down, so say why\n // and go no further; a yes taken back unannounced tears it down here.\n const stillStarting = async () => {\n if (g === gen && !allowed()) await teardown('stopped', CONSENT_TAKEN_BACK);\n if (g !== gen) throw Object.assign(new Error(stopReason || 'aiLive: stopped before it started sending.'), { code: 'STOPPED' });\n };\n try {\n await stillStarting();\n // One round trip: the connection starts the session (or Core refuses, in its own words), and\n // says how to send. Before the camera, so a refusal never turns the camera on.\n camera = DEFAULT_CAMERA;\n // Checked again with nothing in between: a stop that landed while the check above resolved has\n // already torn this start down, and opening now would start a session nobody closes (Codex on #53).\n if (g !== gen) throw Object.assign(new Error(stopReason || 'aiLive: stopped before it started sending.'), { code: 'STOPPED' });\n await openSocket();\n await stillStarting();\n await cameraOfScreen.start({ intent: 'stream', facing: cam } as any);\n if (g !== gen) { try { await cameraOfScreen.stop?.(); } catch { /* released by the gate too */ } }\n await stillStarting();\n // Again with nothing in between: a stop that landed while the last check resolved must not see\n // pictures start or the state flip back to \"sending\" (Codex on #53).\n if (g !== gen) throw Object.assign(new Error(stopReason || 'aiLive: stopped before it started sending.'), { code: 'STOPPED' });\n loop = deps.setInterval(() => { void slot(); }, Math.max(200, Math.round(1000 / camera.fps)));\n set({ state: 'sending' });\n return snap;\n } catch (e: any) {\n if (g !== gen) {\n // Already torn down by a stop: report why it stopped, not the closed socket.\n throw e?.code === 'STOPPED' ? e : Object.assign(new Error(stopReason || 'aiLive: stopped before it started sending.'), { code: 'STOPPED' });\n }\n await teardown('error', String(e?.message || e));\n throw e;\n }\n },\n async stop(who: string, why?: string) {\n const waiting = waitingToStart.get(who);\n if (waiting) waiting.cancelled = true;\n if (owner !== who) return;\n await teardown('stopped', why ?? null);\n },\n getSnapshot: (who: string) => (lastOwner === who ? snap : idle()),\n onEpisode: (cb, who) => add(episodeCbs, who, cb),\n subscribe: (cb, who) => add(snapCbs, who, cb),\n forget(who: string) {\n episodeCbs.delete(who);\n snapCbs.delete(who);\n if (lastOwner === who && owner === null) { lastOwner = null; snap = idle(); }\n },\n isSending: () => snap.state === 'starting' || snap.state === 'sending',\n subscribeSending(cb) {\n sendingCbs.add(cb);\n return { unsubscribe: () => { sendingCbs.delete(cb); } } as Subscription;\n },\n };\n}\n","// ada-vision — on-device image understanding, our own native code (no camera lib).\n//\n// On-device, frames never leave the phone:\n// assessQuality(uri) — one-shot quality of a LOCAL frame file.\n// startVision()/onVisionFrame — the headless camera session that publishes a\n// timeline frame (id + quality, never pixels) at a\n// cadence; readText/describe/detectObjects resolve\n// a published id ON-DEVICE.\n//\n// The luma math mirrors ./analysis.js (which has the exhaustive unit tests).\n//\n// requireOptionalNativeModule: on a binary WITHOUT the native module, the import\n// is null, isSupported() is false, and the session calls refuse cleanly (no crash).\n\nimport type { ComponentType } from 'react';\nimport { requireOptionalNativeModule } from 'expo-modules-core';\nimport { requireNativeView } from 'expo';\n\n/** TEST-ONLY live preview bound to the same headless session (so a tester can\n * aim). The real Guide runs headless and never mounts this. Null on a binary\n * without the native view, so importing this module never crashes. */\nexport const CameraPreview: ComponentType<any> | null = (() => {\n try { return requireNativeView('AdaVision'); } catch { return null; }\n})();\n\nexport interface RawFrameQuality {\n blur: 'sharp' | 'slight' | 'severe' | 'unknown';\n exposure: 'good' | 'dark' | 'bright' | 'unknown';\n /** true = lens covered; false = clearly not; null = not assessed. */\n obstructed: boolean | null;\n}\n\ninterface Subscription { remove(): void }\n\n/** A published timeline frame from the vision session (metadata only — never\n * pixels; the buffer stays in the native ring, resolved by id). */\nexport interface VisionFrame {\n id: string;\n ts: number;\n expiresAt: number;\n blur: RawFrameQuality['blur'];\n exposure: RawFrameQuality['exposure'];\n obstructed: RawFrameQuality['obstructed'];\n}\n\n/** One OCR result on a frame — matches the SDK's VisionText. */\nexport interface VisionText {\n text: string;\n /** 0..1 recogniser confidence (never a 1.0 filler). */\n confidence: number | null;\n /** Normalised 0..1 box, origin TOP-left, in the UPRIGHT portrait frame (native\n * rotates frames at capture) — x runs from the user's left to their right. */\n box?: { x: number; y: number; width: number; height: number };\n}\n\n/** One classifier label — a vocabulary term, NOT prose. Matches VisionLabel. */\nexport interface VisionLabel {\n label: string;\n confidence: number | null;\n}\n\n/** One detected object — a located item with a box, from the bundled detector. */\nexport interface VisionObject {\n /** Open-Images class name (e.g. \"Car\", \"Traffic light\", \"Building\", \"Person\"). */\n label: string;\n /** 0..1 detector confidence. */\n confidence: number | null;\n /** Normalised 0..1 box, origin TOP-left, in the UPRIGHT portrait frame (native\n * rotates frames at capture) — x runs from the user's left to their right. */\n box?: { x: number; y: number; width: number; height: number };\n}\n\ninterface AdaVisionNative {\n isSupported(): boolean;\n assessQuality(uri: string): Promise<RawFrameQuality>;\n startVision(intervalMs: number): Promise<void>;\n /** Absent from binaries built before the front camera existed. */\n startVisionCamera?(intervalMs: number, facing: VisionFacing): Promise<void>;\n /** Absent from binaries built before AI live existed. A base64 JPEG. */\n jpegById?(id: string, maxSide: number, quality: number): Promise<string>;\n stopVision(): void;\n visionRetentionMs(): number;\n qualityById(id: string): RawFrameQuality | null;\n readText(id: string, languages: string[] | null): Promise<VisionText[]>;\n describe(id: string, maxLabels: number): Promise<VisionLabel[]>;\n detectObjects(id: string, maxItems: number, minConfidence: number): Promise<VisionObject[]>;\n addListener(event: 'visionFrame', cb: (f: VisionFrame) => void): Subscription;\n}\n\nconst native = requireOptionalNativeModule<AdaVisionNative>('AdaVision');\n\n/** The native function, or a refusal by name: Android's AdaVision has assessQuality only\n * (AI Models F4), so a verb it lacks says so instead of failing as \"not a function\". */\nfunction verb<K extends keyof AdaVisionNative>(name: K): AdaVisionNative[K] {\n if (!native) throw new Error('ada-vision native module not present in this build');\n const fn = native[name];\n if (typeof fn !== 'function') {\n throw Object.assign(new Error(`UNAVAILABLE: ada-vision ${String(name)} is not implemented on this platform (iOS only)`), { code: 'UNAVAILABLE' });\n }\n return (fn as Function).bind(native) as AdaVisionNative[K];\n}\n\n/** Is the native vision module present in this binary? */\nexport function isSupported(): boolean {\n try { return native?.isSupported() ?? false; } catch { return false; }\n}\n\n/** One-shot: measure a frame's quality from its LOCAL file. Throws if it cannot look. */\nexport async function assessQuality(uri: string): Promise<RawFrameQuality> {\n if (!native) throw new Error('ada-vision native module not present in this build');\n return native.assessQuality(uri);\n}\n\n// ── Vision session (feeds the Visual Engine) ──\n\n/** Which camera the vision session reads. */\nexport type VisionFacing = 'front' | 'back';\n\n/**\n * Start the vision session on `facing` — publishes a timeline frame every\n * `intervalMs`. The back camera works on every binary; the front camera needs a\n * binary built with it, and an older one REFUSES it rather than quietly reading\n * the back camera instead.\n */\nexport async function startVision(intervalMs = 1000, facing: VisionFacing = 'back'): Promise<void> {\n if (facing !== 'front' && facing !== 'back') {\n throw new Error(`Unknown camera \"${String(facing)}\" — use \"front\" or \"back\"`);\n }\n if (facing === 'back') return verb('startVision')(intervalMs);\n if (native && typeof native.startVisionCamera !== 'function') {\n throw new Error('the front camera needs a newer app build — this one can read the back camera only');\n }\n return verb('startVisionCamera')!(intervalMs, facing);\n}\n\n/** Stop the vision session and release the camera. */\nexport function stopVision(): void {\n native?.stopVision?.();\n}\n\n/** Subscribe to published timeline frames (id + quality + expiry; no pixels). */\nexport function onVisionFrame(cb: (f: VisionFrame) => void): Subscription {\n if (!native) return { remove() {} };\n return native.addListener('visionFrame', cb);\n}\n\n/** How far back the native ring can still resolve a frame id (ms). */\nexport function visionRetentionMs(): number {\n return native?.visionRetentionMs?.() ?? 0;\n}\n\n/** Resolve a published frame id → its measured quality (null if evicted). */\nexport function qualityById(id: string): RawFrameQuality | null {\n return native?.qualityById?.(id) ?? null;\n}\n\n/** On-device OCR on a published frame. [] = looked, no text; throws = couldn't look. */\nexport async function readText(id: string, languages?: string[]): Promise<VisionText[]> {\n return verb('readText')(id, languages ?? null);\n}\n\n/** On-device image classification → labels (not prose). [] = nothing recognised. */\nexport async function describe(id: string, maxLabels = 5): Promise<VisionLabel[]> {\n return verb('describe')(id, maxLabels);\n}\n\n/** On-device object detection (bundled YOLOv8n, Open-Images vocabulary) → located\n * items with boxes. [] = looked, found nothing above `minConfidence`; throws =\n * couldn't look (id aged out, or the model isn't in this build). */\nexport async function detectObjects(id: string, maxItems = 10, minConfidence = 0.25): Promise<VisionObject[]> {\n return verb('detectObjects')(id, maxItems, minConfidence);\n}\n\n/**\n * A published frame as a base64 JPEG, its longer side at most `maxSide`. FOR THE SDK'S AI LIVE SENDER ONLY\n * (aiLive/provider.ts), which calls it after the two-sided \"Pictures to AI\" consent: this is the one way a\n * picture leaves native, and no plugin-facing API reaches it. An older binary refuses by name.\n */\nexport async function jpegById(id: string, maxSide = 768, quality = 0.7): Promise<string> {\n if (native && typeof native.jpegById !== 'function') {\n throw new Error('sending pictures to AI needs a newer app build — this one cannot make a picture from a camera frame');\n }\n return verb('jpegById')!(id, maxSide, quality);\n}\n","/**\n * The wire protocol of Core's binary stream endpoint (/ws/stream), for the AI live sender.\n *\n * A PORT of Core's `packages/media-stream/src/index.js` (@ateam-ai/media-stream, not on npm\n * yet), limited to what a sender needs. The frame bytes are pinned by\n * tests/aiLiveStreamProtocol.test.mjs against the layout that file documents, so a drift is\n * a red test, not a silent mismatch. DEAD — replace with an import of @ateam-ai/media-stream\n * once Core publishes it.\n *\n * Frame envelope (bytes): 0 version (1) · 1 flags · 2-5 seq uint32 BE (one per sampling slot\n * of the SENDER, taken or skipped) · 6-13 tCapture float64 BE (ms since the epoch) · 14- payload.\n */\nexport const STREAM_PATH = '/ws/stream';\nexport const SUBPROTOCOL = 'adas.v1';\nexport const HEADER_BYTES = 14;\nconst ENVELOPE_VERSION = 1;\n\nexport const CLOSE = Object.freeze({\n AUTH_MISSING: 4001,\n AUTH_FAILED: 4002,\n NO_SUCH_WORKSPACE: 4003,\n NOT_ENTITLED: 4004,\n BAD_REQUEST: 4400,\n UNKNOWN_KIND: 4404,\n TIMEOUT: 4408,\n OVER_LIMIT: 4429,\n TOO_BIG: 1009,\n CONSUMER_FAILING: 1011,\n});\n\nexport function encodeFrame({ seq, tCapture, payload }: { seq: number; tCapture: number; payload: Uint8Array }): Uint8Array {\n const out = new Uint8Array(HEADER_BYTES + payload.length);\n const v = new DataView(out.buffer);\n v.setUint8(0, ENVELOPE_VERSION);\n v.setUint8(1, 0);\n v.setUint32(2, seq >>> 0, false);\n v.setFloat64(6, tCapture, false);\n out.set(payload, HEADER_BYTES);\n return out;\n}\n\nexport function openMessage(kind: string, params?: Record<string, unknown>): string {\n return JSON.stringify(params ? { type: 'open', kind, params } : { type: 'open', kind });\n}\n\nexport const CLOSE_MESSAGE = JSON.stringify({ type: 'close' });\n\n/** A server text frame → { event, data }, or null for anything that is not an event. */\nexport function parseServerEvent(text: unknown): { event: string; data: any } | null {\n if (typeof text !== 'string') return null;\n try {\n const m = JSON.parse(text);\n return m && typeof m.event === 'string' ? { event: m.event, data: m.data } : null;\n } catch {\n return null;\n }\n}\n\nconst WHY: Record<number, string> = {\n [CLOSE.AUTH_MISSING]: 'The login or the workspace was missing. Sign in again and try once more.',\n [CLOSE.AUTH_FAILED]: 'The login was refused. Sign in again and try once more.',\n [CLOSE.NO_SUCH_WORKSPACE]: 'This workspace was not found.',\n [CLOSE.NOT_ENTITLED]: 'This workspace may not stream right now.',\n [CLOSE.TIMEOUT]: 'The connection to the AI timed out.',\n [CLOSE.OVER_LIMIT]: 'Too many cameras are sending to this workspace. Stop another one first.',\n [CLOSE.TOO_BIG]: 'A picture was too big to send.',\n [CLOSE.CONSUMER_FAILING]: 'The AI stopped taking pictures. Check the live session in AI Models.',\n};\n\n/** A close as one plain sentence: the server's own words for a refused open. */\nexport function describeClose(code: number, reason?: string): string {\n if (code === CLOSE.BAD_REQUEST && reason) return reason;\n return WHY[code] || (reason ? reason : `The connection to the AI closed (${code}).`);\n}\n\nconst B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\nconst B64_INDEX = (() => { const t = new Int16Array(256).fill(-1); for (let i = 0; i < 64; i++) t[B64.charCodeAt(i)] = i; return t; })();\n\n/** Base64 (the native module's JPEG) → bytes. Ignores padding and line breaks. */\nexport function base64ToBytes(b64: string): Uint8Array {\n const clean = b64.replace(/[^A-Za-z0-9+/]/g, '');\n const out = new Uint8Array(Math.floor((clean.length * 3) / 4));\n let o = 0, acc = 0, bits = 0;\n for (let i = 0; i < clean.length; i++) {\n acc = (acc << 6) | B64_INDEX[clean.charCodeAt(i)];\n bits += 6;\n if (bits >= 8) { bits -= 8; out[o++] = (acc >> bits) & 0xff; }\n }\n return o === out.length ? out : out.subarray(0, o);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BA,kBAAkD;AAClD,4BAAmC;;;ACZnC,+BAA4C;AAC5C,kBAAkC;AAK3B,IAAM,iBAA4C,MAAM;AAC7D,MAAI;AAAE,eAAO,+BAAkB,WAAW;AAAA,EAAG,QAAQ;AAAE,WAAO;AAAA,EAAM;AACtE,GAAG;AAkEH,IAAM,aAAS,sDAA6C,WAAW;AAIvE,SAAS,KAAsC,MAA6B;AAC1E,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,oDAAoD;AACjF,QAAM,KAAK,OAAO,IAAI;AACtB,MAAI,OAAO,OAAO,YAAY;AAC5B,UAAM,OAAO,OAAO,IAAI,MAAM,2BAA2B,OAAO,IAAI,CAAC,iDAAiD,GAAG,EAAE,MAAM,cAAc,CAAC;AAAA,EAClJ;AACA,SAAQ,GAAgB,KAAK,MAAM;AACrC;AA8EA,eAAsB,SAAS,IAAY,UAAU,KAAK,UAAU,KAAsB;AACxF,MAAI,UAAU,OAAO,OAAO,aAAa,YAAY;AACnD,UAAM,IAAI,MAAM,0GAAqG;AAAA,EACvH;AACA,SAAO,KAAK,UAAU,EAAG,IAAI,SAAS,OAAO;AAC/C;;;AC3KO,IAAM,cAAc;AACpB,IAAM,cAAc;AACpB,IAAM,eAAe;AAC5B,IAAM,mBAAmB;AAElB,IAAM,QAAQ,OAAO,OAAO;AAAA,EACjC,cAAc;AAAA,EACd,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA,EACd,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,kBAAkB;AACpB,CAAC;AA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AM;AAAE,oBAAY;AAAM,eAAO,KAAK;AAAA,MAAG;AAAA,IAC9E;AAAA,IACA,WAAW,MAAM,KAAK,UAAU,cAAc,KAAK,UAAU;AAAA,IAC7D,iBAAiB,IAAI;AACnB,iBAAW,IAAI,EAAE;AACjB,aAAO,EAAE,aAAa,MAAM;AAAE,mBAAW,OAAO,EAAE;AAAA,MAAG,EAAE;AAAA,IACzD;AAAA,EACF;AACF;","names":["set"]}
@@ -1,14 +1,16 @@
1
1
  import {
2
+ CLOSE_WAIT_MS,
2
3
  LIVE_KIND,
3
- PHONE_SLICE_USD,
4
+ OPEN_TIMEOUT_MS,
4
5
  createAiLiveProvider,
5
6
  defaultAiLiveDeps
6
- } from "../chunk-JUBLG3PN.mjs";
7
+ } from "../chunk-PV2EHH2P.mjs";
7
8
  import "../chunk-WQK6PUBN.mjs";
8
9
  import "../chunk-WMJKH4XE.mjs";
9
10
  export {
11
+ CLOSE_WAIT_MS,
10
12
  LIVE_KIND,
11
- PHONE_SLICE_USD,
13
+ OPEN_TIMEOUT_MS,
12
14
  createAiLiveProvider,
13
15
  defaultAiLiveDeps
14
16
  };