@karlorz/codexhost-cli-win32-arm64 0.13.3-6 → 0.13.3-7

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.
@@ -14848,6 +14848,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14848
14848
  "codexhost/harness/installation",
14849
14849
  "codexhost/harness/launch-settings/get",
14850
14850
  "codexhost/harness/launch-settings/set",
14851
+ "codexhost/harness/grok-computer-use/get",
14852
+ "codexhost/harness/grok-computer-use/set",
14851
14853
  "codexhost/harness/web-ui/open",
14852
14854
  "codexhost/harness/accounts/sources",
14853
14855
  "codexhost/harness/accounts/list",
@@ -15376,7 +15378,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15376
15378
  var harnessInspectParamsSchema = external_exports.object({
15377
15379
  harnessId: harnessIdSchema,
15378
15380
  cwd: nonBlankTextSchema2.max(16384).optional(),
15379
- refresh: external_exports.boolean().optional()
15381
+ refresh: external_exports.boolean().optional(),
15382
+ /** `availability` asks only whether the Harness can run; see `InspectHarnessInput.purpose`. */
15383
+ purpose: external_exports.literal("availability").optional()
15380
15384
  }).strict();
15381
15385
  var harnessWebUiOpenParamsSchema = external_exports.object({
15382
15386
  harnessId: harnessIdSchema
@@ -15550,6 +15554,26 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15550
15554
  restartRequired: external_exports.boolean()
15551
15555
  }).strict();
15552
15556
 
15557
+ // ../shared-contracts/dist/grok-computer-use.js
15558
+ var grokComputerUseGetSchema = external_exports.object({}).strict();
15559
+ var grokComputerUseSetSchema = external_exports.object({
15560
+ enabled: external_exports.boolean().optional(),
15561
+ browser: external_exports.boolean().optional()
15562
+ }).strict().refine((value) => value.enabled !== void 0 || value.browser !== void 0, {
15563
+ message: "Expected enabled or browser"
15564
+ });
15565
+ var grokComputerUseSettingsSchema = external_exports.object({
15566
+ enabled: external_exports.boolean(),
15567
+ available: external_exports.boolean(),
15568
+ unavailableReason: external_exports.string().min(1).max(500).optional(),
15569
+ browser: external_exports.boolean().optional(),
15570
+ browserFilesPresent: external_exports.boolean().optional(),
15571
+ browserAvailable: external_exports.boolean().optional(),
15572
+ browserUnavailableReason: external_exports.string().min(1).max(500).optional(),
15573
+ applyFailed: external_exports.boolean().optional(),
15574
+ applyError: external_exports.string().min(1).max(500).optional()
15575
+ }).strict();
15576
+
15553
15577
  // ../shared-contracts/dist/harness-installation.js
15554
15578
  var harnessInstallationParamsSchema = external_exports.object({
15555
15579
  harnessId: harnessIdSchema,
@@ -15943,6 +15967,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15943
15967
  ]);
15944
15968
 
15945
15969
  // ../shared-contracts/dist/voice-settings.js
15970
+ var VOICE_GATEWAY_STATUS_METHOD = "codexhost/voice/gateway-status";
15946
15971
  var voiceRoutesSchema = external_exports.strictObject({
15947
15972
  chatExperience: external_exports.enum(["chatgpt", "codex"]),
15948
15973
  chatConnection: external_exports.enum(["desktop", "gateway"]),
@@ -15992,7 +16017,11 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15992
16017
  var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
15993
16018
 
15994
16019
  // src/renderer-cpa-live-voice-preference.ts
15995
- var sharedRoutes = /* @__PURE__ */ new WeakMap();
16020
+ var voiceStateOwner = globalThis;
16021
+ var { sharedRoutes, gatewayReady } = voiceStateOwner.__codexhostVoicePreferenceStateV1 ??= {
16022
+ sharedRoutes: /* @__PURE__ */ new WeakMap(),
16023
+ gatewayReady: /* @__PURE__ */ new WeakMap()
16024
+ };
15996
16025
  var SHARED_VOICE_CACHE = "codexhost.voice-routes-cache.v1";
15997
16026
  function cachedRoutes(owner) {
15998
16027
  const memory = sharedRoutes.get(owner);
@@ -16166,6 +16195,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16166
16195
  return handle;
16167
16196
  }
16168
16197
 
16198
+ // src/renderer-voice-assets.ts
16199
+ function supportsVoiceVersion(profiles, version2) {
16200
+ return version2 === void 0 || profiles.some((profile) => profile.version === version2);
16201
+ }
16202
+ function selectVoiceAssets(profiles, names, version2) {
16203
+ const present = profiles.filter(
16204
+ (profile2) => [profile2.initial, profile2.shared].some((asset) => auditedAppInitialAssetPresent(names, asset))
16205
+ );
16206
+ const profile = present.length === 1 ? present[0] : void 0;
16207
+ return profile && (version2 === void 0 || profile.version === version2) && [profile.initial, profile.shared].every((asset) => auditedAppInitialAssetPresent(names, asset)) ? profile : void 0;
16208
+ }
16209
+
16169
16210
  // src/renderer-chat-voice-debug.ts
16170
16211
  var CHAT_VOICE_DEBUG_GLOBAL = "__codexhostChatVoiceDebug";
16171
16212
  var CHAT_VOICE_DEBUG_STORAGE_KEY = "codexhost.chat-voice-debug.v1";
@@ -16187,14 +16228,34 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16187
16228
  var RENDERER_NEW_THREAD_PREFERENCE_KEY = "codexhost.new-thread-preference.v1";
16188
16229
 
16189
16230
  // src/renderer-client-owned-voice.ts
16190
- var CLIENT_OWNED_VOICE_VERSION = "26.1013.40934";
16191
- var CLIENT_OWNED_VOICE_INITIAL_ASSET = "app-initial-90eb42395b7d.js";
16192
- var CLIENT_OWNED_VOICE_SHARED_ASSET = "app-shared-52443cbe9ac4.js";
16231
+ var CLIENT_OWNED_VOICE_VERSION = "26.1016.62342";
16232
+ var CLIENT_OWNED_VOICE_INITIAL_ASSET = "app-initial-dddef47d6ef6.js";
16233
+ var CLIENT_OWNED_VOICE_SHARED_ASSET = "app-shared-fc3316d48427.js";
16234
+ var CLIENT_OWNED_VOICE_SERVICES = "ist";
16235
+ var CLIENT_OWNED_VOICE_OVERLAY_ASSET = "avatar-overlay-native-page-ef8332c6a2fb.js";
16236
+ var CLIENT_OWNED_VOICE_ASSETS = [
16237
+ {
16238
+ version: CLIENT_OWNED_VOICE_VERSION,
16239
+ initial: CLIENT_OWNED_VOICE_INITIAL_ASSET,
16240
+ shared: CLIENT_OWNED_VOICE_SHARED_ASSET,
16241
+ overlay: CLIENT_OWNED_VOICE_OVERLAY_ASSET
16242
+ },
16243
+ {
16244
+ version: "26.1016.61520",
16245
+ initial: "app-initial-c95ddb62696e.js",
16246
+ shared: "app-shared-2eda13eb7044.js",
16247
+ overlay: "avatar-overlay-native-page-fcc17283519a.js"
16248
+ }
16249
+ ];
16250
+ var SHARED_INIT = "Oit";
16251
+ var SHARED_FETCH = "Eit";
16252
+ var SHARED_BRIDGE = "AFt";
16253
+ var SHARED_RESPONSE_ERROR = "Mit";
16193
16254
  var HOOK_GLOBAL = "__codexhostClientOwnedVoiceV1";
16194
16255
  function object2(value) {
16195
16256
  return value !== null && typeof value === "object";
16196
16257
  }
16197
- function requestHost(bridge, params) {
16258
+ function requestVoiceHost(bridge, params, method = REALTIME_CALL_METHOD) {
16198
16259
  const id = `codexhost-voice:${crypto.randomUUID()}`;
16199
16260
  return new Promise((resolve, reject) => {
16200
16261
  let unsubscribe = () => {
@@ -16217,7 +16278,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16217
16278
  try {
16218
16279
  bridge.dispatchMessage("mcp-request", {
16219
16280
  hostId: "local",
16220
- request: { id, method: REALTIME_CALL_METHOD, params }
16281
+ request: { id, method, params }
16221
16282
  });
16222
16283
  } catch {
16223
16284
  done();
@@ -16242,24 +16303,50 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16242
16303
  if (model2.startsWith("codexhost/")) return true;
16243
16304
  return model2.includes("codex") && !model2.includes("gpt-live");
16244
16305
  }
16306
+ function visibleWorkComposer(owner) {
16307
+ const document = owner.document;
16308
+ if (!document?.querySelectorAll) return false;
16309
+ const work = [...document.querySelectorAll("[data-codex-composer-root]")].some((element) => {
16310
+ const box = element.getBoundingClientRect?.() ?? { width: 0 };
16311
+ return box.width > 0 && !element.closest?.("[hidden], [inert]");
16312
+ });
16313
+ return work && document.querySelectorAll("[data-chatgpt-composer]").length === 0;
16314
+ }
16315
+ function selectedWorkTab(owner) {
16316
+ const document = owner.document;
16317
+ if (!document?.querySelectorAll) return false;
16318
+ const controls = document.querySelectorAll("button, [role='tab'], a");
16319
+ let workSelected = false;
16320
+ let chatSelected = false;
16321
+ for (const element of controls) {
16322
+ const name = (element.textContent ?? "").replace(/\s+/gu, " ").trim();
16323
+ if (name !== "Chat" && name !== "Work") continue;
16324
+ const selected = element.getAttribute("aria-selected") === "true" || element.getAttribute("aria-pressed") === "true" || element.getAttribute("data-state") === "active" || element.getAttribute("data-state") === "on";
16325
+ if (!selected) continue;
16326
+ if (name === "Work") workSelected = true;
16327
+ if (name === "Chat") chatSelected = true;
16328
+ }
16329
+ return workSelected && !chatSelected;
16330
+ }
16245
16331
  function isWorkComposerSurface(owner = globalThis) {
16246
16332
  const storage = owner.localStorage;
16247
- if (!storage) return false;
16248
16333
  try {
16249
- const raw = storage.getItem(HOME_COMPOSER_MODE_STORAGE_KEY);
16250
- if (raw == null || raw === "") return false;
16251
- let value = raw;
16252
- if (raw.startsWith("{") || raw.startsWith('"') || raw.startsWith("[")) {
16253
- try {
16254
- value = JSON.parse(raw);
16255
- } catch {
16256
- value = raw;
16334
+ const raw = storage?.getItem(HOME_COMPOSER_MODE_STORAGE_KEY);
16335
+ if (raw != null && raw !== "") {
16336
+ let value = raw;
16337
+ if (raw.startsWith("{") || raw.startsWith('"') || raw.startsWith("[")) {
16338
+ try {
16339
+ value = JSON.parse(raw);
16340
+ } catch {
16341
+ value = raw;
16342
+ }
16257
16343
  }
16344
+ if (value === "work") return true;
16345
+ if (value === "chat") return false;
16258
16346
  }
16259
- return value === "work";
16260
16347
  } catch {
16261
- return false;
16262
16348
  }
16349
+ return selectedWorkTab(owner) || visibleWorkComposer(owner);
16263
16350
  }
16264
16351
  function selectedComposerModel(owner) {
16265
16352
  const routing = owner.__codexhostHostRoutingV1;
@@ -16271,6 +16358,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16271
16358
  }
16272
16359
  }
16273
16360
  var lastVoiceProductExperience;
16361
+ function rememberVoiceProductExperience(request) {
16362
+ const experience = object2(request) ? request.productExperience : void 0;
16363
+ lastVoiceProductExperience = experience === "chat" || experience === "work" ? experience : void 0;
16364
+ }
16274
16365
  function lastVoiceLaunchProductExperience() {
16275
16366
  return lastVoiceProductExperience;
16276
16367
  }
@@ -16292,16 +16383,17 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16292
16383
  const wrapped = async function(url2, options) {
16293
16384
  if (typeof url2 !== "string" || url2.split("?")[0] !== "/wham/realtime/calls" || options?.method !== "POST")
16294
16385
  return original.call(this, url2, options);
16295
- const chat = lastVoiceLaunchProductExperience() === "chat";
16386
+ const experience = lastVoiceLaunchProductExperience();
16387
+ const chat = experience === "chat";
16296
16388
  const model2 = backendModelName(options.headers);
16297
- const work = !chat && (isWorkBackendModel(model2) || workSurface());
16389
+ const work = !chat && (experience === "work" || isWorkBackendModel(model2) || workSurface());
16298
16390
  const external = !chat && (model2.startsWith("codexhost/") || externalHarness());
16299
16391
  const gateway = external || (work ? workOverride() : chatOverride());
16300
16392
  chatVoiceDebug("wham-create", {
16301
16393
  work,
16302
16394
  external,
16303
16395
  route: gateway ? "gateway" : "desktop",
16304
- productExperience: lastVoiceLaunchProductExperience() ?? "unset"
16396
+ productExperience: experience ?? "unset"
16305
16397
  });
16306
16398
  if (!gateway) {
16307
16399
  if (!external && !work)
@@ -16317,12 +16409,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16317
16409
  const cancel = () => {
16318
16410
  if (cancelled) return;
16319
16411
  cancelled = true;
16320
- void requestHost(bridge, { operation: "cancel", requestId: requestId2 }).catch(() => void 0);
16412
+ void requestVoiceHost(bridge, { operation: "cancel", requestId: requestId2 }).catch(() => void 0);
16321
16413
  };
16322
16414
  options.signal?.addEventListener("abort", cancel, { once: true });
16323
16415
  try {
16324
16416
  const result = realtimeCallResponseSchema.parse(
16325
- await requestHost(bridge, {
16417
+ await requestVoiceHost(bridge, {
16326
16418
  operation: "create",
16327
16419
  requestId: requestId2,
16328
16420
  body: options.body,
@@ -16334,7 +16426,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16334
16426
  if (options.signal?.aborted) {
16335
16427
  const callId = realtimeCallIdFromLocation(result.headers.location ?? "");
16336
16428
  if (result.status >= 200 && result.status < 300 && isRealtimeCallId(callId))
16337
- await requestHost(bridge, { operation: "hangup", callId });
16429
+ await requestVoiceHost(bridge, { operation: "hangup", callId });
16338
16430
  options.signal.throwIfAborted();
16339
16431
  }
16340
16432
  const response = new Response(result.status === 204 ? null : result.body, {
@@ -16362,7 +16454,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16362
16454
  const config2 = readCpaLiveVoiceHookConfig(target);
16363
16455
  if (!config2) return { status: "disabled", dispose() {
16364
16456
  } };
16365
- if (config2.desktopVersion !== void 0 && config2.desktopVersion !== CLIENT_OWNED_VOICE_VERSION)
16457
+ if (!supportsVoiceVersion(CLIENT_OWNED_VOICE_ASSETS, config2.desktopVersion))
16366
16458
  return { status: "unsupported", dispose() {
16367
16459
  } };
16368
16460
  const importModule = options.importModule ?? ((url2) => import(url2));
@@ -16383,25 +16475,26 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16383
16475
  const attempt = async () => {
16384
16476
  if (disposed) return;
16385
16477
  const names = loadedAssetNames(target.document, target.performance);
16386
- if (auditedAppInitialAssetPresent(names, CLIENT_OWNED_VOICE_INITIAL_ASSET) && auditedAppInitialAssetPresent(names, CLIENT_OWNED_VOICE_SHARED_ASSET)) {
16478
+ const assets = selectVoiceAssets(CLIENT_OWNED_VOICE_ASSETS, names, config2.desktopVersion);
16479
+ if (assets) {
16387
16480
  try {
16388
- const module = await importModule(`app://-/assets/${CLIENT_OWNED_VOICE_SHARED_ASSET}`);
16481
+ const module = await importModule(`app://-/assets/${assets.shared}`);
16389
16482
  if (disposed) return;
16390
- if (typeof module.frt !== "function") throw new Error();
16391
- module.frt();
16392
- const fetchClass = module.urt;
16393
- const bridgeClass = module.mPt;
16483
+ if (typeof module[SHARED_INIT] !== "function") throw new Error();
16484
+ module[SHARED_INIT]();
16485
+ const fetchClass = module[SHARED_FETCH];
16486
+ const bridgeClass = module[SHARED_BRIDGE];
16394
16487
  if (!object2(fetchClass) && typeof fetchClass !== "function") throw new Error();
16395
16488
  if (!object2(bridgeClass) && typeof bridgeClass !== "function") throw new Error();
16396
16489
  const client = Reflect.get(fetchClass, "getInstance").call(fetchClass);
16397
16490
  const bridge = Reflect.get(bridgeClass, "getInstance").call(bridgeClass);
16398
- if (typeof client?.fetch !== "function" || typeof bridge?.dispatchMessage !== "function" || typeof bridge?.subscribe !== "function" || typeof module.grt !== "function")
16491
+ if (typeof client?.fetch !== "function" || typeof bridge?.dispatchMessage !== "function" || typeof bridge?.subscribe !== "function" || typeof module[SHARED_RESPONSE_ERROR] !== "function")
16399
16492
  throw new Error();
16400
16493
  restore = wrapClientOwnedVoiceFetch(
16401
16494
  client,
16402
16495
  bridge,
16403
16496
  () => cpaLiveVoicePreferenceAllowsInstall(target),
16404
- module.grt,
16497
+ module[SHARED_RESPONSE_ERROR],
16405
16498
  () => chatLiveVoicePreferenceAllowsOverride(target),
16406
16499
  () => isWorkComposerSurface(target),
16407
16500
  () => isExternalHarnessComposer(target)
@@ -16489,8 +16582,432 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16489
16582
  };
16490
16583
  }
16491
16584
 
16585
+ // ../desktop-control/dist/renderer-react-ownership.js
16586
+ function committedReactAncestors(value) {
16587
+ const MAX_VISITED_FIBERS = 2e5;
16588
+ const fiber = (value2) => typeof value2 === "object" && value2 !== null ? value2 : null;
16589
+ const exhausted = () => {
16590
+ const target = globalThis;
16591
+ if (typeof target.dispatchEvent === "function" && typeof CustomEvent === "function")
16592
+ target.dispatchEvent(new CustomEvent("codexhost:react-fiber-walk-limit", {
16593
+ detail: { limit: MAX_VISITED_FIBERS }
16594
+ }));
16595
+ return [];
16596
+ };
16597
+ const first = fiber(value);
16598
+ if (!first)
16599
+ return [];
16600
+ const previous = [];
16601
+ const seen = /* @__PURE__ */ new Set();
16602
+ for (let node = first; node; node = fiber(node.return)) {
16603
+ if (seen.has(node))
16604
+ return [];
16605
+ if (seen.size >= MAX_VISITED_FIBERS)
16606
+ return exhausted();
16607
+ seen.add(node);
16608
+ previous.push(node);
16609
+ }
16610
+ const rootState = fiber(previous.at(-1)?.stateNode);
16611
+ if (!rootState || !("current" in rootState))
16612
+ return previous;
16613
+ const current = fiber(rootState.current);
16614
+ if (!current)
16615
+ return [];
16616
+ const alternate = fiber(first.alternate);
16617
+ const path = [current];
16618
+ seen.clear();
16619
+ seen.add(current);
16620
+ for (let index = previous.length - 2; index >= 0; index -= 1) {
16621
+ const expected = previous[index];
16622
+ const expectedAlternate = fiber(expected?.alternate);
16623
+ let child = fiber(path.at(-1)?.child);
16624
+ let matched = false;
16625
+ while (child && !seen.has(child) && seen.size < MAX_VISITED_FIBERS) {
16626
+ seen.add(child);
16627
+ if (child === expected || child === expectedAlternate) {
16628
+ matched = true;
16629
+ break;
16630
+ }
16631
+ child = fiber(child.sibling);
16632
+ }
16633
+ if (!matched || !child)
16634
+ break;
16635
+ path.push(child);
16636
+ }
16637
+ if (path.length === previous.length && (path.at(-1) === first || path.at(-1) === alternate)) {
16638
+ return path.reverse();
16639
+ }
16640
+ const stack = [{ node: current, parent: null }];
16641
+ seen.clear();
16642
+ while (stack.length > 0 && seen.size < MAX_VISITED_FIBERS) {
16643
+ const entry = stack.pop();
16644
+ if (!entry)
16645
+ break;
16646
+ if (seen.has(entry.node))
16647
+ return [];
16648
+ seen.add(entry.node);
16649
+ if (entry.node === first || entry.node === alternate) {
16650
+ const ancestors = [];
16651
+ for (let cursor = entry; cursor; cursor = cursor.parent)
16652
+ ancestors.push(cursor.node);
16653
+ return ancestors;
16654
+ }
16655
+ const sibling = entry.parent && fiber(entry.node.sibling);
16656
+ if (sibling)
16657
+ stack.push({ node: sibling, parent: entry.parent });
16658
+ const child = fiber(entry.node.child);
16659
+ if (child)
16660
+ stack.push({ node: child, parent: entry });
16661
+ }
16662
+ return stack.length > 0 ? exhausted() : [];
16663
+ }
16664
+
16665
+ // src/renderer-voice-capability.ts
16666
+ var INFERENCE_GATE = "3683713372";
16667
+ var record2 = (value) => value !== null && typeof value === "object";
16668
+ var capable = (value) => record2(value) && typeof value.isLoading === "boolean" && typeof value.isError === "boolean" && typeof value.isCapable === "boolean";
16669
+ var equal = (a, b) => a.isLoading === b.isLoading && a.isError === b.isError && a.isCapable === b.isCapable;
16670
+ function replayVoiceCapability(store, atom, gate) {
16671
+ const evaluate = (override) => {
16672
+ const visiting = /* @__PURE__ */ new Set();
16673
+ let remaining = 512;
16674
+ let hits = 0;
16675
+ const read = (dependency) => {
16676
+ if (--remaining < 0) throw new Error("Voice capability dependency limit");
16677
+ const value = store.get(dependency);
16678
+ if (dependency === gate) {
16679
+ hits += 1;
16680
+ if (typeof value !== "boolean") throw new Error("Voice inference gate unavailable");
16681
+ return override ? false : value;
16682
+ }
16683
+ if (dependency.write || visiting.has(dependency)) return value;
16684
+ if (typeof dependency.read !== "function") throw new Error("Voice dependency unavailable");
16685
+ visiting.add(dependency);
16686
+ try {
16687
+ return dependency.read(read);
16688
+ } finally {
16689
+ visiting.delete(dependency);
16690
+ }
16691
+ };
16692
+ return { value: read(atom), hits };
16693
+ };
16694
+ try {
16695
+ const native = store.get(atom);
16696
+ if (!capable(native) || native.isLoading || native.isError) return null;
16697
+ const before = evaluate(false);
16698
+ if (!capable(before.value) || !equal(native, before.value)) return null;
16699
+ const after = evaluate(true);
16700
+ return after.hits > 0 && capable(after.value) && !after.value.isLoading && !after.value.isError ? after.value : null;
16701
+ } catch {
16702
+ return null;
16703
+ }
16704
+ }
16705
+ function hooks(fiber) {
16706
+ const result = [];
16707
+ const seen = /* @__PURE__ */ new Set();
16708
+ let hook = fiber.memoizedState;
16709
+ while (record2(hook) && result.length < 4096 && !seen.has(hook)) {
16710
+ seen.add(hook);
16711
+ result.push(hook);
16712
+ hook = hook.next;
16713
+ }
16714
+ return hook == null ? result : [];
16715
+ }
16716
+ function bindVoiceCapabilitySubscriptions(currentFibers, family, gates, allowed, realtimeOnly = false) {
16717
+ const fibers = currentFibers();
16718
+ const restores = [];
16719
+ const bindings = [];
16720
+ try {
16721
+ for (const fiber of fibers) {
16722
+ const list = hooks(fiber);
16723
+ for (const memo of list) {
16724
+ const [signal, deps] = Array.isArray(memo.memoizedState) ? memo.memoizedState : [];
16725
+ if (!record2(signal) || !Array.isArray(deps) || deps.length !== 5 || deps[3] !== family || !(deps[1] instanceof Map) || deps[2] !== void 0)
16726
+ continue;
16727
+ const chain = deps[1];
16728
+ const node = chain.get(family.scope.id);
16729
+ const members = node?.familyBindings?.get(family);
16730
+ if (!node || !(members instanceof Map) || node.store !== signal.store) continue;
16731
+ const matches = [...members].filter(([, member]) => member.cacheKey === deps[0]);
16732
+ if (matches.length !== 1 || typeof matches[0]?.[0] !== "string") continue;
16733
+ const parameter = JSON.parse(matches[0][0]);
16734
+ if (!record2(parameter) || Object.keys(parameter).some((key) => key !== "name" && key !== "hostId") || parameter.name !== "voice.realtime" && parameter.name !== "voice.thread" || realtimeOnly && parameter.name !== "voice.realtime" || parameter.hostId !== void 0 && parameter.hostId !== "local" || parameter.name === "voice.thread" && parameter.hostId !== "local")
16735
+ continue;
16736
+ const subscriptions = list.filter((hook2) => {
16737
+ const state = hook2.memoizedState;
16738
+ return Array.isArray(state) && Array.isArray(state[1]) && state[1].length === 2 && state[1][0] === signal && state[1][1] === void 0 && typeof state[0]?.getSnapshot === "function";
16739
+ });
16740
+ if (subscriptions.length !== 1) throw new Error("Ambiguous voice subscription");
16741
+ const hook = subscriptions[0];
16742
+ const subscriber = hook.memoizedState[0];
16743
+ const instance = hook.next?.queue;
16744
+ const effect = hook.next?.next?.memoizedState;
16745
+ const store = signal.store;
16746
+ const gate = gates.resolve(node, chain, INFERENCE_GATE)?.atom;
16747
+ if (!gate || !instance || !record2(effect) || !Array.isArray(effect.deps) || effect.deps[0] !== subscriber.subscribe || typeof effect.create !== "function" || typeof instance.getSnapshot !== "function" || !capable(store.get(signal.atom)) || !capable(subscriber.getSnapshot()) || !capable(instance.getSnapshot()) || !equal(
16748
+ store.get(signal.atom),
16749
+ subscriber.getSnapshot()
16750
+ ) || !equal(subscriber.getSnapshot(), instance.getSnapshot()) || subscriber.createRender?.() != null)
16751
+ throw new Error("Unsupported voice subscription");
16752
+ for (const [object3, key] of [
16753
+ [store, "sub"],
16754
+ [subscriber, "getSnapshot"],
16755
+ [instance, "getSnapshot"]
16756
+ ])
16757
+ if (Object.getOwnPropertyDescriptor(object3, key)?.writable !== true)
16758
+ throw new Error("Voice subscription is not writable");
16759
+ let notify;
16760
+ const sub = store.sub;
16761
+ try {
16762
+ store.sub = (atom, listener) => {
16763
+ if (atom !== signal.atom || notify) throw new Error("Unexpected voice subscription");
16764
+ notify = listener;
16765
+ return () => {
16766
+ };
16767
+ };
16768
+ effect.create();
16769
+ } finally {
16770
+ store.sub = sub;
16771
+ }
16772
+ if (!notify) throw new Error("Voice listener unavailable");
16773
+ const original = subscriber.getSnapshot;
16774
+ const originalInstance = instance.getSnapshot;
16775
+ let previous;
16776
+ const snapshot = () => {
16777
+ const native = original.call(subscriber);
16778
+ if (!allowed()) return native;
16779
+ const projected = replayVoiceCapability(store, signal.atom, gate);
16780
+ if (!projected || !projected.isCapable) return native;
16781
+ if (!previous || !equal(previous, projected)) previous = projected;
16782
+ return previous;
16783
+ };
16784
+ subscriber.getSnapshot = snapshot;
16785
+ instance.getSnapshot = snapshot;
16786
+ const onChange = notify;
16787
+ restores.push(() => {
16788
+ if (subscriber.getSnapshot === snapshot) subscriber.getSnapshot = original;
16789
+ if (instance.getSnapshot === snapshot) instance.getSnapshot = originalInstance;
16790
+ onChange();
16791
+ });
16792
+ bindings.push({ subscriber, signal, instance });
16793
+ onChange();
16794
+ }
16795
+ }
16796
+ if (!restores.length) throw new Error("Owned voice capability unavailable");
16797
+ if (realtimeOnly && restores.length !== 1) throw new Error("Ambiguous voice starter");
16798
+ } catch (error51) {
16799
+ for (const restore of restores.reverse()) restore();
16800
+ throw error51;
16801
+ }
16802
+ return {
16803
+ dispose() {
16804
+ for (const restore of restores.splice(0).reverse()) restore();
16805
+ },
16806
+ current() {
16807
+ const current = [...currentFibers()].flatMap(hooks);
16808
+ return bindings.every(
16809
+ ({ subscriber, signal, instance }) => current.some(
16810
+ (hook) => Array.isArray(hook.memoizedState) && hook.memoizedState[0] === subscriber && hook.memoizedState[1]?.[0] === signal && hook.next?.queue === instance && (!realtimeOnly || capable(hook.next?.memoizedState) && hook.next.memoizedState.isCapable)
16811
+ )
16812
+ );
16813
+ }
16814
+ };
16815
+ }
16816
+
16817
+ // src/renderer-voice-start-capability.ts
16818
+ var GLOBAL = "__codexhostVoiceStartCapabilityV1";
16819
+ var record3 = (v) => v !== null && typeof v === "object";
16820
+ function gatewayVoiceStartRequest(request, workGateway, chatGateway = false) {
16821
+ if (!record3(request) || request.productExperience !== "work" && request.productExperience !== "chat")
16822
+ return false;
16823
+ if (request.source === "composer_button_existing_thread") {
16824
+ if (!record3(request.locator) || request.locator.hostId !== "local") return false;
16825
+ } else if (request.source !== "composer_button_new_thread" || (request.hostId ?? "local") !== "local")
16826
+ return false;
16827
+ if (request.productExperience === "chat") return chatGateway;
16828
+ const mode = request.activeCollaborationMode;
16829
+ const settings = record3(mode) ? mode.settings : void 0;
16830
+ const model2 = record3(settings) ? settings.model : void 0;
16831
+ return workGateway || typeof model2 === "string" && model2.startsWith("codexhost/");
16832
+ }
16833
+ function wrapGatewayVoiceStarter(start, options) {
16834
+ let active;
16835
+ return {
16836
+ async start(...args) {
16837
+ if (!options.qualifies(args[0])) return start(...args);
16838
+ if (active) throw new Error("Voice gateway start is already pending");
16839
+ const attempt = {};
16840
+ active = attempt;
16841
+ const allowed = () => active === attempt && options.qualifies(args[0]);
16842
+ try {
16843
+ if (!await options.ready()) throw new Error("Voice gateway is not ready");
16844
+ if (!allowed()) throw new Error("Voice gateway start was cancelled");
16845
+ attempt.binding = await options.prepare(allowed);
16846
+ await options.committed(attempt.binding);
16847
+ if (!allowed()) throw new Error("Voice gateway start was cancelled");
16848
+ if (!attempt.binding.current()) throw new Error("Voice starter subscription changed");
16849
+ rememberVoiceProductExperience(args[0]);
16850
+ return await start(...args);
16851
+ } finally {
16852
+ attempt.binding?.dispose();
16853
+ if (active === attempt) active = void 0;
16854
+ }
16855
+ },
16856
+ cancel() {
16857
+ active?.binding?.dispose();
16858
+ active = void 0;
16859
+ }
16860
+ };
16861
+ }
16862
+ function overlayVoiceStarterFibers(document, page) {
16863
+ const fibers = /* @__PURE__ */ new Set();
16864
+ for (const element of document.querySelectorAll("[data-avatar-overlay-native-surface-id]")) {
16865
+ const key = Object.getOwnPropertyNames(element).find((key2) => key2.startsWith("__reactFiber$"));
16866
+ const ancestors = committedReactAncestors(
16867
+ key && Object.getOwnPropertyDescriptor(element, key)?.value
16868
+ );
16869
+ const boundary = ancestors.findIndex((fiber) => record3(fiber) && fiber.type === page);
16870
+ if (boundary < 0) continue;
16871
+ for (const fiber of ancestors.slice(0, boundary)) if (record3(fiber)) fibers.add(fiber);
16872
+ }
16873
+ return fibers;
16874
+ }
16875
+ function installVoiceStartCapabilityHook(options = {}) {
16876
+ const target = options.target ?? globalThis;
16877
+ if (target[GLOBAL]) return target[GLOBAL];
16878
+ const config2 = readCpaLiveVoiceHookConfig(target);
16879
+ if (!config2 || !isAvatarOverlayHref(target.location?.href ?? ""))
16880
+ return { status: "disabled", dispose() {
16881
+ } };
16882
+ if (!supportsVoiceVersion(CLIENT_OWNED_VOICE_ASSETS, config2.desktopVersion))
16883
+ return { status: "unsupported", dispose() {
16884
+ } };
16885
+ const importModule = options.importModule ?? ((url2) => import(url2));
16886
+ let disposed = false;
16887
+ let timer;
16888
+ let restore;
16889
+ const wrappers = /* @__PURE__ */ new Set();
16890
+ const started = Date.now();
16891
+ const handle = {
16892
+ status: "pending",
16893
+ dispose() {
16894
+ disposed = true;
16895
+ target.clearTimeout(timer);
16896
+ for (const wrapper of wrappers) wrapper.cancel();
16897
+ restore?.();
16898
+ if (target[GLOBAL] === handle) Reflect.deleteProperty(target, GLOBAL);
16899
+ }
16900
+ };
16901
+ target[GLOBAL] = handle;
16902
+ const attempt = async () => {
16903
+ if (disposed) return;
16904
+ try {
16905
+ const names = loadedAssetNames(target.document, target.performance);
16906
+ const assets = selectVoiceAssets(CLIENT_OWNED_VOICE_ASSETS, names, config2.desktopVersion);
16907
+ if (assets) {
16908
+ const shared = await importModule(`app://-/assets/${assets.shared}`);
16909
+ if (typeof shared.Oit !== "function") throw new Error("Voice bridge unavailable");
16910
+ shared.Oit();
16911
+ const services = shared[CLIENT_OWNED_VOICE_SERVICES];
16912
+ if (record3(services) && (record3(services.realtimeVoiceRuntime) || typeof services.realtimeVoiceRuntime === "function")) {
16913
+ const original = services.realtimeVoiceRuntime;
16914
+ const register = Reflect.get(original, "registerRealtimeStarter");
16915
+ if (typeof register !== "function") throw new Error("Voice starter unavailable");
16916
+ const wrapped = new Proxy(original, {
16917
+ get(service, key, receiver) {
16918
+ if (key === "registerRealtimeStarter")
16919
+ return (start, cancel, ...rest) => {
16920
+ if (typeof start !== "function" || typeof cancel !== "function")
16921
+ throw new Error("Voice starter callback unavailable");
16922
+ const wrapper = wrapGatewayVoiceStarter(start, {
16923
+ qualifies: (request) => !disposed && !!readCpaLiveVoiceHookConfig(target) && gatewayVoiceStartRequest(
16924
+ request,
16925
+ cpaLiveVoicePreferenceAllowsInstall(target),
16926
+ chatLiveVoicePreferenceAllowsOverride(target)
16927
+ ),
16928
+ ready: async () => {
16929
+ const hook = target.__codexhostClientOwnedVoiceV1;
16930
+ if (!record3(hook) || hook.status !== "active") return false;
16931
+ const bridgeClass = shared.AFt;
16932
+ const result = await requestVoiceHost(
16933
+ bridgeClass.getInstance(),
16934
+ {},
16935
+ VOICE_GATEWAY_STATUS_METHOD
16936
+ );
16937
+ return result === true;
16938
+ },
16939
+ prepare: async (allowed) => {
16940
+ const names2 = loadedAssetNames(target.document, target.performance);
16941
+ if (!auditedAppInitialAssetPresent(names2, assets.overlay))
16942
+ throw new Error("Unaudited voice starter");
16943
+ const [initial, overlay] = await Promise.all([
16944
+ importModule(`app://-/assets/${assets.initial}`),
16945
+ importModule(`app://-/assets/${assets.overlay}`)
16946
+ ]);
16947
+ if (typeof initial.njr !== "function" || typeof overlay.AvatarOverlayNativePage !== "function" || !target.document)
16948
+ throw new Error("Voice starter owner unavailable");
16949
+ const document = target.document;
16950
+ initial.njr();
16951
+ return bindVoiceCapabilitySubscriptions(
16952
+ () => overlayVoiceStarterFibers(document, overlay.AvatarOverlayNativePage),
16953
+ initial.tjr,
16954
+ initial.uBr,
16955
+ allowed,
16956
+ true
16957
+ );
16958
+ },
16959
+ // Wait for React's committed snapshot, including when the
16960
+ // persistent overlay is hidden. A stale closure fails closed.
16961
+ committed: async (binding) => {
16962
+ for (let i = 0; i < 40 && !disposed && !binding.current(); i += 1)
16963
+ await new Promise((resolve) => target.setTimeout(resolve, 50));
16964
+ }
16965
+ });
16966
+ wrappers.add(wrapper);
16967
+ return Reflect.apply(register, original, [
16968
+ wrapper.start,
16969
+ (...args) => {
16970
+ wrapper.cancel();
16971
+ return cancel(...args);
16972
+ },
16973
+ ...rest
16974
+ ]);
16975
+ };
16976
+ if (key === "unregisterRealtimeStarter")
16977
+ return (...args) => {
16978
+ for (const wrapper of wrappers) wrapper.cancel();
16979
+ wrappers.clear();
16980
+ return Reflect.apply(Reflect.get(service, key), service, args);
16981
+ };
16982
+ return Reflect.get(service, key, receiver);
16983
+ }
16984
+ });
16985
+ if (disposed) return;
16986
+ if (!Reflect.set(services, "realtimeVoiceRuntime", wrapped))
16987
+ throw new Error("Voice service is not writable");
16988
+ restore = () => {
16989
+ if (services.realtimeVoiceRuntime === wrapped) services.realtimeVoiceRuntime = original;
16990
+ };
16991
+ handle.status = "active";
16992
+ return;
16993
+ }
16994
+ }
16995
+ if (Date.now() - started >= 6e4) {
16996
+ handle.status = "unsupported";
16997
+ return;
16998
+ }
16999
+ timer = target.setTimeout(() => void attempt(), 25);
17000
+ } catch {
17001
+ handle.status = "unsupported";
17002
+ }
17003
+ };
17004
+ void attempt();
17005
+ return handle;
17006
+ }
17007
+
16492
17008
  // src/cpa-live-voice-entry.ts
16493
17009
  installCpaLiveVoiceHook();
16494
17010
  installClientOwnedVoiceHook();
17011
+ installVoiceStartCapabilityHook();
16495
17012
  installOverlayThreadIsolation();
16496
17013
  })();