@karlorz/codexhost-cli-linux-x64 0.22.0-1 → 0.22.0-5

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.
@@ -77080,8 +77080,12 @@ function itemOf(item, reasoningPreviewIds) {
77080
77080
  return;
77081
77081
  }
77082
77082
  }
77083
+ function userMessageContent(item) {
77084
+ let content = item.codexhostNativeInput ?? item.content;
77085
+ return Array.isArray(content) ? content : [];
77086
+ }
77083
77087
  function userMessageIdentity(item) {
77084
- return JSON.stringify([item.content, item.clientId ?? null]);
77088
+ return JSON.stringify([userMessageContent(item), item.clientId ?? null]);
77085
77089
  }
77086
77090
  function nativeTime(seconds) {
77087
77091
  return typeof seconds == "number" && Number.isFinite(seconds) && seconds >= 0 ? seconds * 1e3 : void 0;
@@ -77165,7 +77169,7 @@ var ChThreadView = class _ChThreadView {
77165
77169
  let currentTurn;
77166
77170
  for (let event of this.log.events)
77167
77171
  if (event.type === "turn/start" && (currentTurn = event.data.turn), currentTurn === view.projector.turn && event.type === "user/message")
77168
- return { seq: event.seq, turnId: turn.id, input: messages2[0].content };
77172
+ return { seq: event.seq, turnId: turn.id, input: userMessageContent(messages2[0]) };
77169
77173
  }
77170
77174
  /** Older native pages are projected separately, without changing the visible tail. */
77171
77175
  prepend(turns) {
@@ -77294,7 +77298,7 @@ var ChThreadView = class _ChThreadView {
77294
77298
  }
77295
77299
  }), opening = items[0]?.type === "userMessage" ? items[0] : void 0;
77296
77300
  opening ? projector.begin(
77297
- this.projectInput(Array.isArray(opening.content) ? opening.content : []),
77301
+ this.projectInput(userMessageContent(opening)),
77298
77302
  typeof opening.clientId == "string" ? opening.clientId : void 0
77299
77303
  ) : projector.beginAutonomous([]), view = {
77300
77304
  projector,
@@ -77312,7 +77316,7 @@ var ChThreadView = class _ChThreadView {
77312
77316
  for (let item of items) {
77313
77317
  if (item.type === "userMessage") {
77314
77318
  view.userMessages.has(item.id) || (view.projector.steer(
77315
- this.projectInput(Array.isArray(item.content) ? item.content : []),
77319
+ this.projectInput(userMessageContent(item)),
77316
77320
  typeof item.clientId == "string" ? item.clientId : void 0
77317
77321
  ), view.userMessages.set(item.id, userMessageIdentity(item)), view.started.add(item.id));
77318
77322
  continue;
@@ -80544,7 +80548,7 @@ function rendererVoiceHostDocumentGuardExpression() {
80544
80548
  }
80545
80549
 
80546
80550
  // packages/desktop-control/dist/renderer-voice-host-binding.js
80547
- var RENDERER_VOICE_HOST_BINDING_NAME = "__codexhostVoiceHostBindingV1", RENDERER_VOICE_HOST_CAPABILITY_GLOBAL = "__codexhostVoiceHostV1", RENDERER_VOICE_HOST_DELIVER_GLOBAL = "__codexhostVoiceHostDeliverV1", RENDERER_VOICE_HOST_PENDING_GLOBAL = "__codexhostVoiceHostPendingV1", RENDERER_VOICE_HOST_MAX_PAYLOAD_BYTES = 256 * 1024, RENDERER_VOICE_HOST_SETTINGS_TIMEOUT_MS = 1e4, RENDERER_VOICE_HOST_GATEWAY_TIMEOUT_MS = 2e3, RENDERER_VOICE_HOST_REALTIME_TIMEOUT_MS = 3e4, RENDERER_VOICE_HOST_METHODS = [
80551
+ var RENDERER_VOICE_HOST_BINDING_NAME = "__codexhostVoiceHostBindingV1", RENDERER_VOICE_HOST_CAPABILITY_GLOBAL = "__codexhostVoiceHostV1", RENDERER_VOICE_HOST_DELIVER_GLOBAL = "__codexhostVoiceHostDeliverV1", RENDERER_VOICE_HOST_PENDING_GLOBAL = "__codexhostVoiceHostPendingV1", RENDERER_VOICE_HOST_MAX_PAYLOAD_BYTES = 256 * 1024, RENDERER_VOICE_HOST_SETTINGS_TIMEOUT_MS = 1e4, RENDERER_VOICE_HOST_GATEWAY_TIMEOUT_MS = 2e3, RENDERER_VOICE_HOST_REALTIME_TIMEOUT_MS = 3e4, RENDERER_VOICE_HOST_PUBLISH_RETRY_MS = 1e3, RENDERER_VOICE_HOST_METHODS = [
80548
80552
  VOICE_SETTINGS_METHOD,
80549
80553
  VOICE_GATEWAY_STATUS_METHOD,
80550
80554
  REALTIME_CALL_METHOD
@@ -80562,7 +80566,7 @@ function cleanupUnconfirmedError(error51) {
80562
80566
  if (error51 instanceof Error && error51.message === RENDERER_VOICE_HOST_CLEANUP_UNCONFIRMED && allowlistedStage(Reflect.get(error51, "stage")) === "cancel")
80563
80567
  return error51;
80564
80568
  }
80565
- function rendererVoiceHostCapabilitySource(owner, generation) {
80569
+ function rendererVoiceHostCapabilitySource(owner, generation, instanceId = "", installationOrder = 0, publisherId2 = "") {
80566
80570
  let guard = rendererVoiceHostDocumentGuardExpression();
80567
80571
  return `(() => {
80568
80572
  if (!${guard}) return true;
@@ -80574,6 +80578,9 @@ function rendererVoiceHostCapabilitySource(owner, generation) {
80574
80578
  const maxBytes = ${RENDERER_VOICE_HOST_MAX_PAYLOAD_BYTES};
80575
80579
  const ownerId = ${JSON.stringify(owner)};
80576
80580
  const generation = ${generation};
80581
+ const instance = ${JSON.stringify(instanceId)};
80582
+ const order = ${installationOrder};
80583
+ const publisher = ${JSON.stringify(publisherId2)};
80577
80584
  const settingsTimeout = ${RENDERER_VOICE_HOST_SETTINGS_TIMEOUT_MS};
80578
80585
  const gatewayTimeout = ${RENDERER_VOICE_HOST_GATEWAY_TIMEOUT_MS};
80579
80586
  const realtimeTimeout = ${RENDERER_VOICE_HOST_REALTIME_TIMEOUT_MS};
@@ -80591,6 +80598,8 @@ function rendererVoiceHostCapabilitySource(owner, generation) {
80591
80598
  }
80592
80599
  };
80593
80600
  const previous = globalThis[cap];
80601
+ // A publish that outlived its installation must leave a newer installation's state intact.
80602
+ if (previous && previous.publisher === publisher && typeof previous.order === "number" && previous.order > order) return true;
80594
80603
  if (previous && previous.generation !== generation) settleAll(${JSON.stringify(UNAVAILABLE)});
80595
80604
  globalThis[deliver] = (message) => {
80596
80605
  if (!message || typeof message !== "object" || typeof message.id !== "string") return;
@@ -80615,6 +80624,9 @@ function rendererVoiceHostCapabilitySource(owner, generation) {
80615
80624
  value: Object.freeze({
80616
80625
  owner: ownerId,
80617
80626
  generation,
80627
+ instance,
80628
+ order,
80629
+ publisher,
80618
80630
  request(method, params) {
80619
80631
  try {
80620
80632
  if (!${guard}) return unavailable();
@@ -80646,7 +80658,7 @@ function rendererVoiceHostCapabilitySource(owner, generation) {
80646
80658
  } catch (e) {}
80647
80659
  reject(new Error(${JSON.stringify(UNAVAILABLE)}));
80648
80660
  }, timeoutMs);
80649
- pending.set(id, { resolve, reject, timer, generation });
80661
+ pending.set(id, { resolve, reject, timer, generation, instance });
80650
80662
  try {
80651
80663
  globalThis[binding](payload);
80652
80664
  } catch {
@@ -80677,14 +80689,6 @@ function callIdFromCreateResult(result) {
80677
80689
  let callId = realtimeCallIdFromLocation(location);
80678
80690
  return isRealtimeCallId(callId) ? callId : void 0;
80679
80691
  }
80680
- async function cleanupAbandonedCreate(execution, params, result) {
80681
- let unconfirmed, note = (error51) => {
80682
- unconfirmed ??= cleanupUnconfirmedError(error51);
80683
- }, requestId2 = typeof params.requestId == "string" ? params.requestId : void 0;
80684
- requestId2 && await execution.request(REALTIME_CALL_METHOD, { operation: "cancel", requestId: requestId2 }).catch(note);
80685
- let callId = callIdFromCreateResult(result);
80686
- return callId && await execution.request(REALTIME_CALL_METHOD, { operation: "hangup", callId }).catch(note), unconfirmed;
80687
- }
80688
80692
  function captureExecution(host) {
80689
80693
  return host.bindExecution?.() ?? {
80690
80694
  generation: host.generation,
@@ -80716,18 +80720,41 @@ async function deliver(renderer, executionContextId, message2) {
80716
80720
  }).catch(() => {
80717
80721
  });
80718
80722
  }
80719
- async function registerFutureScript(renderer, source, previousId) {
80720
- previousId && await renderer.command("Page.removeScriptToEvaluateOnNewDocument", { identifier: previousId }).catch(() => {
80721
- });
80723
+ async function addFutureScript(renderer, source) {
80722
80724
  let added = await renderer.command("Page.addScriptToEvaluateOnNewDocument", { source });
80723
- return isRecord3(added) && typeof added.identifier == "string" ? added.identifier : void 0;
80725
+ if (!isRecord3(added) || typeof added.identifier != "string")
80726
+ throw new Error("Voice Host future script registration failed");
80727
+ return added.identifier;
80724
80728
  }
80725
80729
  async function removeFutureScript(renderer, identifier) {
80726
80730
  identifier && await renderer.command("Page.removeScriptToEvaluateOnNewDocument", { identifier }).catch(() => {
80727
80731
  });
80728
80732
  }
80733
+ function rendererVoiceHostCleanupSource(instanceId) {
80734
+ return `(() => {
80735
+ const instance = ${JSON.stringify(instanceId)};
80736
+ const pending = globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}];
80737
+ if (pending && typeof pending.forEach === "function") {
80738
+ for (const [id, wait] of [...pending.entries()]) {
80739
+ if (!wait || wait.instance !== instance) continue;
80740
+ pending.delete(id);
80741
+ try { clearTimeout(wait.timer); } catch (e) {}
80742
+ try { wait.reject(new Error(${JSON.stringify(UNKNOWN_OUTCOME)})); } catch (e) {}
80743
+ }
80744
+ }
80745
+ const capability = globalThis[${JSON.stringify(RENDERER_VOICE_HOST_CAPABILITY_GLOBAL)}];
80746
+ if (capability && capability.instance === instance) {
80747
+ delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_CAPABILITY_GLOBAL)}];
80748
+ delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_DELIVER_GLOBAL)}];
80749
+ if (globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}] === pending)
80750
+ delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}];
80751
+ }
80752
+ return true;
80753
+ })()`;
80754
+ }
80755
+ var publisherId = crypto.randomUUID(), installationSequence = 0;
80729
80756
  async function installRendererVoiceHostBinding(renderer, host, options) {
80730
- let disposed = !1, scriptId, publishing = Promise.resolve(), inflight = /* @__PURE__ */ new Set(), works = /* @__PURE__ */ new Map(), abandonedIds = /* @__PURE__ */ new Set(), contexts = /* @__PURE__ */ new Map(), rememberContext = (params) => {
80757
+ let instance = crypto.randomUUID(), installationOrder = installationSequence += 1, disposed = !1, ready = !1, scriptId, publishedGeneration, publishing = Promise.resolve(), works = /* @__PURE__ */ new Map(), abandonedIds = /* @__PURE__ */ new Set(), contexts = /* @__PURE__ */ new Map(), rememberContext = (params) => {
80731
80758
  if (!isRecord3(params) || !isRecord3(params.context))
80732
80759
  return;
80733
80760
  let context = params.context;
@@ -80745,11 +80772,37 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
80745
80772
  error: unconfirmed.message,
80746
80773
  stage: "cancel"
80747
80774
  });
80748
- }, abandonWork = (item) => {
80749
- item.abandoned || (item.abandoned = !0, item.create && cleanupAbandonedCreate(item.execution, { requestId: item.create.requestId, operation: "create" }, item.create.result).then((unconfirmed) => observeCleanupUnconfirmed(item.contextId, item.pageId, unconfirmed)));
80775
+ }, reportCleanupUnconfirmed = (item, error51) => {
80776
+ let create = item.create, unconfirmed = cleanupUnconfirmedError(error51);
80777
+ !create || !unconfirmed || create.cleanupReported || (create.cleanupReported = !0, observeCleanupUnconfirmed(item.contextId, item.pageId, unconfirmed));
80778
+ }, requestCleanup = (item, params) => {
80779
+ try {
80780
+ item.execution.request(REALTIME_CALL_METHOD, params).catch((error51) => reportCleanupUnconfirmed(item, error51));
80781
+ } catch (error51) {
80782
+ reportCleanupUnconfirmed(item, error51);
80783
+ }
80784
+ }, hangUpLateCreate = (item) => {
80785
+ let create = item.create;
80786
+ if (!create || create.hangupIssued)
80787
+ return;
80788
+ let callId = callIdFromCreateResult(create.result);
80789
+ callId && (create.hangupIssued = !0, requestCleanup(item, { operation: "hangup", callId }));
80790
+ }, retireWork = (item) => {
80791
+ item.abandoned = !0;
80792
+ let create = item.create;
80793
+ if (create) {
80794
+ if (create.settled) {
80795
+ hangUpLateCreate(item);
80796
+ return;
80797
+ }
80798
+ create.cancelIssued || (create.cancelIssued = !0, requestCleanup(item, { operation: "cancel", requestId: create.requestId }));
80799
+ }
80800
+ }, retireInflight = () => {
80801
+ for (let item of works.values())
80802
+ retireWork(item);
80750
80803
  }, abandonMatching = (contextId, uniqueId) => {
80751
80804
  for (let item of works.values())
80752
- (contextId !== void 0 && item.contextId === contextId || uniqueId !== void 0 && item.uniqueId === uniqueId) && abandonWork(item);
80805
+ (contextId !== void 0 && item.contextId === contextId || uniqueId !== void 0 && item.uniqueId === uniqueId) && retireWork(item);
80753
80806
  }, forgetContext = (params) => {
80754
80807
  if (!isRecord3(params))
80755
80808
  return;
@@ -80763,37 +80816,58 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
80763
80816
  }, unsubscribeCreated = renderer.on("Runtime.executionContextCreated", rememberContext), unsubscribeDestroyed = renderer.on("Runtime.executionContextDestroyed", forgetContext), unsubscribeCleared = renderer.on("Runtime.executionContextsCleared", () => {
80764
80817
  contexts.clear();
80765
80818
  for (let item of works.values())
80766
- abandonWork(item);
80819
+ retireWork(item);
80767
80820
  }), contextIsVerified = async (executionContextId, uniqueId) => {
80768
80821
  let tracked = contexts.get(executionContextId);
80769
80822
  if (!tracked?.isDefault || tracked.uniqueId !== uniqueId)
80770
80823
  return !1;
80771
80824
  let document2 = await readContextDocument(renderer, executionContextId), still = contexts.get(executionContextId);
80772
80825
  return still?.uniqueId !== uniqueId || !still.isDefault || !document2?.top ? !1 : isEligibleVoiceHostUrl(document2.href);
80826
+ }, publishRetry, clearPublishRetry = () => {
80827
+ publishRetry !== void 0 && (clearTimeout(publishRetry), publishRetry = void 0);
80828
+ }, schedulePublishRetry = () => {
80829
+ disposed || publishRetry !== void 0 || (publishRetry = setTimeout(() => {
80830
+ publishRetry = void 0, !disposed && enqueuePublish().catch(() => schedulePublishRetry());
80831
+ }, RENDERER_VOICE_HOST_PUBLISH_RETRY_MS));
80832
+ }, cleanupPageState = async () => {
80833
+ try {
80834
+ await renderer.evaluate(rendererVoiceHostCleanupSource(instance));
80835
+ } catch {
80836
+ }
80773
80837
  }, publishGeneration = async () => {
80774
- if (disposed)
80775
- return;
80776
- let startedGeneration = host.generation, source = rendererVoiceHostCapabilitySource(host.owner, startedGeneration), addedId = await registerFutureScript(renderer, source, scriptId);
80777
- if (disposed || host.generation !== startedGeneration) {
80778
- await removeFutureScript(renderer, addedId);
80779
- return;
80838
+ for (let attempt = 0; !disposed && attempt < 3; attempt += 1) {
80839
+ let startedGeneration = host.generation;
80840
+ if (startedGeneration === publishedGeneration)
80841
+ return;
80842
+ let source = rendererVoiceHostCapabilitySource(host.owner, startedGeneration, instance, installationOrder, publisherId), addedId = await addFutureScript(renderer, source);
80843
+ if (disposed || host.generation !== startedGeneration) {
80844
+ await removeFutureScript(renderer, addedId);
80845
+ continue;
80846
+ }
80847
+ let previousId = scriptId;
80848
+ if (scriptId = addedId, await removeFutureScript(renderer, previousId), disposed)
80849
+ return;
80850
+ if (await renderer.evaluate(source), disposed) {
80851
+ await cleanupPageState();
80852
+ return;
80853
+ }
80854
+ if (publishedGeneration = startedGeneration, host.generation === startedGeneration)
80855
+ return;
80780
80856
  }
80781
- scriptId = addedId, await renderer.evaluate(source);
80782
80857
  }, enqueuePublish = () => {
80783
- publishing = publishing.catch(() => {
80784
- }).then(() => publishGeneration()).catch(() => {
80858
+ let next = publishing.catch(() => {
80859
+ }).then(async () => {
80860
+ await publishGeneration(), !disposed && host.generation !== publishedGeneration ? schedulePublishRetry() : clearPublishRetry();
80785
80861
  });
80786
- }, cancelInflightCreates = () => {
80787
- for (let item of works.values())
80788
- !item.create || item.abandoned || item.execution.request(REALTIME_CALL_METHOD, { operation: "cancel", requestId: item.create.requestId }).catch((error51) => observeCleanupUnconfirmed(item.contextId, item.pageId, cleanupUnconfirmedError(error51)));
80789
- };
80790
- options?.enableRuntime !== !1 && await renderer.command("Runtime.enable"), await renderer.command("Page.enable"), await renderer.command("Runtime.addBinding", { name: RENDERER_VOICE_HOST_BINDING_NAME }), await publishGeneration();
80791
- let refresh = () => {
80792
- disposed || (cancelInflightCreates(), enqueuePublish());
80793
- }, unsubscribeGeneration = host.onGenerationChange?.(refresh), unsubscribe = renderer.on("Runtime.bindingCalled", (params) => {
80862
+ return publishing = next.catch(() => {
80863
+ }), next;
80864
+ }, refresh = () => {
80865
+ disposed || (retireInflight(), ready && enqueuePublish().catch(() => schedulePublishRetry()));
80866
+ }, unsubscribeGeneration, unsubscribe = renderer.on("Runtime.bindingCalled", (params) => {
80794
80867
  if (disposed || !isRecord3(params) || params.name !== RENDERER_VOICE_HOST_BINDING_NAME || typeof params.executionContextId != "number" || typeof params.payload != "string" || params.payload.length > RENDERER_VOICE_HOST_MAX_PAYLOAD_BYTES)
80795
80868
  return;
80796
- let contextId = params.executionContextId, payloadText = params.payload, startedGeneration = host.generation, work = (async () => {
80869
+ let contextId = params.executionContextId, payloadText = params.payload, startedGeneration = host.generation;
80870
+ (async () => {
80797
80871
  let parsed;
80798
80872
  try {
80799
80873
  parsed = JSON.parse(payloadText);
@@ -80805,7 +80879,7 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
80805
80879
  let requestId2 = parsed.id;
80806
80880
  if (parsed.abandon === !0) {
80807
80881
  let existing = works.get(requestId2);
80808
- existing ? abandonWork(existing) : abandonedIds.add(requestId2);
80882
+ existing ? retireWork(existing) : abandonedIds.add(requestId2);
80809
80883
  return;
80810
80884
  }
80811
80885
  if (parsed.generation !== startedGeneration || parsed.generation !== host.generation || typeof parsed.method != "string" || !isRecord3(parsed.params)) {
@@ -80822,17 +80896,25 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
80822
80896
  generation: startedGeneration,
80823
80897
  execution,
80824
80898
  abandoned: abandonedIds.has(requestId2),
80825
- ...isCreateOperation(parsed.method, parsed.params) && typeof parsed.params.requestId == "string" ? { create: { requestId: parsed.params.requestId } } : {}
80899
+ ...isCreateOperation(parsed.method, parsed.params) && typeof parsed.params.requestId == "string" ? {
80900
+ create: {
80901
+ requestId: parsed.params.requestId,
80902
+ settled: !1,
80903
+ cancelIssued: !1,
80904
+ hangupIssued: !1,
80905
+ cleanupReported: !1
80906
+ }
80907
+ } : {}
80826
80908
  };
80827
80909
  works.set(requestId2, item), abandonedIds.delete(requestId2);
80828
80910
  try {
80829
80911
  if (item.abandoned) {
80830
- item.create && await observeCleanupUnconfirmed(contextId, requestId2, await cleanupAbandonedCreate(item.execution, { requestId: item.create.requestId, operation: "create" }, item.create.result));
80912
+ retireWork(item);
80831
80913
  return;
80832
80914
  }
80833
80915
  let method2 = parsed.method, requestParams = parsed.params, verified = await contextIsVerified(contextId, uniqueId), still = contexts.get(contextId);
80834
80916
  if (disposed || item.abandoned || host.generation !== startedGeneration || still?.uniqueId !== uniqueId) {
80835
- item.create && await observeCleanupUnconfirmed(contextId, requestId2, await cleanupAbandonedCreate(item.execution, requestParams, item.create.result));
80917
+ retireWork(item);
80836
80918
  return;
80837
80919
  }
80838
80920
  if (!verified) {
@@ -80845,17 +80927,18 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
80845
80927
  }
80846
80928
  try {
80847
80929
  let result = await item.execution.request(method2, requestParams);
80848
- item.create && (item.create.result = result);
80930
+ item.create && (item.create.result = result, item.create.settled = !0);
80849
80931
  let after = contexts.get(contextId);
80850
80932
  if (disposed || item.abandoned || host.generation !== startedGeneration || after?.uniqueId !== uniqueId) {
80851
- item.create && await observeCleanupUnconfirmed(contextId, requestId2, await cleanupAbandonedCreate(item.execution, requestParams, result));
80933
+ retireWork(item);
80852
80934
  return;
80853
80935
  }
80854
80936
  await deliver(renderer, contextId, { id: requestId2, ok: !0, result });
80855
80937
  } catch (error51) {
80938
+ item.create && (item.create.settled = !0);
80856
80939
  let unconfirmed = cleanupUnconfirmedError(error51);
80857
80940
  if (unconfirmed && !disposed) {
80858
- await deliver(renderer, contextId, {
80941
+ item.create && (item.create.cleanupReported = !0), await deliver(renderer, contextId, {
80859
80942
  id: requestId2,
80860
80943
  ok: !1,
80861
80944
  error: unconfirmed.message,
@@ -80877,33 +80960,16 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
80877
80960
  works.delete(requestId2);
80878
80961
  }
80879
80962
  })();
80880
- inflight.add(work), work.finally(() => inflight.delete(work));
80881
- });
80882
- return () => {
80883
- if (disposed)
80884
- return;
80885
- disposed = !0, unsubscribeGeneration?.(), unsubscribe(), unsubscribeCreated(), unsubscribeDestroyed(), unsubscribeCleared(), cancelInflightCreates();
80886
- let outstanding = [...inflight], leftover = [...works.values()];
80887
- Promise.allSettled(outstanding).then(async () => {
80888
- for (let item of leftover)
80889
- item.create && await observeCleanupUnconfirmed(item.contextId, item.pageId, await cleanupAbandonedCreate(item.execution, { requestId: item.create.requestId, operation: "create" }, item.create.result));
80890
- }), removeFutureScript(renderer, scriptId), renderer.command("Runtime.removeBinding", { name: RENDERER_VOICE_HOST_BINDING_NAME }).catch(() => {
80891
- }), renderer.evaluate(`(() => {
80892
- const pending = globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}];
80893
- if (pending && typeof pending.forEach === "function") {
80894
- for (const [id, wait] of [...pending.entries()]) {
80895
- pending.delete(id);
80896
- try { clearTimeout(wait.timer); } catch (e) {}
80897
- try { wait.reject(new Error(${JSON.stringify(UNKNOWN_OUTCOME)})); } catch (e) {}
80898
- }
80899
- }
80900
- delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_CAPABILITY_GLOBAL)}];
80901
- delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_DELIVER_GLOBAL)}];
80902
- delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}];
80903
- return true;
80904
- })()`).catch(() => {
80905
- });
80963
+ }), dispose = () => {
80964
+ disposed || (disposed = !0, clearPublishRetry(), unsubscribeGeneration?.(), unsubscribe(), unsubscribeCreated(), unsubscribeDestroyed(), unsubscribeCleared(), retireInflight(), removeFutureScript(renderer, scriptId), renderer.command("Runtime.removeBinding", { name: RENDERER_VOICE_HOST_BINDING_NAME }).catch(() => {
80965
+ }), cleanupPageState());
80906
80966
  };
80967
+ try {
80968
+ unsubscribeGeneration = host.onGenerationChange?.(refresh), options?.enableRuntime !== !1 && await renderer.command("Runtime.enable"), await renderer.command("Page.enable"), await renderer.command("Runtime.addBinding", { name: RENDERER_VOICE_HOST_BINDING_NAME }), ready = !0, await enqueuePublish();
80969
+ } catch (error51) {
80970
+ throw dispose(), error51;
80971
+ }
80972
+ return dispose;
80907
80973
  }
80908
80974
 
80909
80975
  // packages/desktop-control/dist/host-client-channel.js
@@ -83494,6 +83560,24 @@ function discoveryTimeoutSignal(timeoutMs, signal) {
83494
83560
  function abortFailure(signal, fallback) {
83495
83561
  return signal.reason instanceof Error ? signal.reason : new Error(fallback);
83496
83562
  }
83563
+ function isRendererDocumentLoadEvent(params) {
83564
+ return !isRecord5(params) || typeof params.name != "string" ? !1 : params.name === "DOMContentLoaded" || params.name === "load" || params.name === "networkIdle";
83565
+ }
83566
+ async function waitForRendererDocumentLoad(renderer, run2, signal, timeoutMessage) {
83567
+ await run2(() => renderer.command("Page.enable"));
83568
+ let finished2 = !1, loaded = new Promise((resolve22) => {
83569
+ let complete = () => {
83570
+ finished2 || (finished2 = !0, unsubscribeLoad(), unsubscribeLifecycle(), resolve22());
83571
+ }, unsubscribeLoad = renderer.on("Page.loadEventFired", complete), unsubscribeLifecycle = renderer.on("Page.lifecycleEvent", (params) => {
83572
+ isRendererDocumentLoadEvent(params) && complete();
83573
+ });
83574
+ });
83575
+ await run2(() => renderer.command("Page.setLifecycleEventsEnabled", { enabled: !0 })), signal ? await awaitWithSignal(loaded, signal, timeoutMessage) : await loaded;
83576
+ }
83577
+ function throwIfCdpAborted(signal, fallback) {
83578
+ if (signal.aborted)
83579
+ throw abortFailure(signal, fallback);
83580
+ }
83497
83581
  function awaitWithSignal(promise2, signal, timeoutMessage) {
83498
83582
  return signal.aborted ? Promise.reject(abortFailure(signal, timeoutMessage)) : new Promise((resolve22, reject) => {
83499
83583
  let onAbort = () => {
@@ -83576,6 +83660,28 @@ async function bindRendererVoiceHost(renderer, voiceHost, disposals, options) {
83576
83660
  function unbindRendererVoiceHost(renderer, disposals) {
83577
83661
  disposals.get(renderer)?.(), disposals.delete(renderer);
83578
83662
  }
83663
+ var VOICE_HOST_ATTACH_TIMEOUT_MS = 15e3, VOICE_HOST_OVERLAY_RETRY_MS = 5e3, VOICE_HOST_LIVENESS_INTERVAL_MS = 5e3, VOICE_HOST_LIVENESS_TIMEOUT_MS = 3e3;
83664
+ async function bindVoiceHostOnNewConnection(target2, voiceHost, operations, timeoutMs, signal) {
83665
+ let timeout = AbortSignal.timeout(timeoutMs), deadline = signal ? AbortSignal.any([timeout, signal]) : timeout, timeoutMessage = "Voice Host attachment timed out", client = await connectRendererTarget(target2, operations, deadline, timeoutMessage), installing = installRendererVoiceHostBinding(client, voiceHost);
83666
+ try {
83667
+ let dispose = await awaitWithSignal(installing, deadline, timeoutMessage);
83668
+ return { targetId: target2.id, client, dispose, verifiedAt: Date.now() };
83669
+ } catch (error51) {
83670
+ throw client.close(), error51;
83671
+ }
83672
+ }
83673
+ async function lateVoiceBindingIsLive(binding, signal) {
83674
+ if (Date.now() - binding.verifiedAt < VOICE_HOST_LIVENESS_INTERVAL_MS)
83675
+ return !0;
83676
+ if (signal.aborted)
83677
+ return !1;
83678
+ let deadline = AbortSignal.any([AbortSignal.timeout(VOICE_HOST_LIVENESS_TIMEOUT_MS), signal]);
83679
+ try {
83680
+ return await awaitWithSignal(binding.client.evaluate("1", VOICE_HOST_LIVENESS_TIMEOUT_MS), deadline, "Voice Host binding liveness check timed out"), binding.verifiedAt = Date.now(), !0;
83681
+ } catch {
83682
+ return !1;
83683
+ }
83684
+ }
83579
83685
  async function evaluateSource(renderer, source) {
83580
83686
  let response = await renderer.command("Runtime.evaluate", {
83581
83687
  expression: source,
@@ -83737,7 +83843,7 @@ async function installOverlayHook(target2, overlayHookSource, overlayClients, op
83737
83843
  renderer ??= await connectRendererTarget(target2, operations, signal, timeoutMessage);
83738
83844
  let connected = renderer;
83739
83845
  try {
83740
- registered ? voiceHost && voiceHostDisposals && !voiceHostDisposals.has(connected) && await run2(() => bindRendererVoiceHost(connected, voiceHost, voiceHostDisposals, { enableRuntime: !1 })) : (voiceHost && voiceHostDisposals && !voiceHostDisposals.has(connected) && await run2(() => bindRendererVoiceHost(connected, voiceHost, voiceHostDisposals, { enableRuntime: !1 })), await run2(() => connected.command("Runtime.enable")), await run2(() => connected.command("Page.enable")), overlayClients.set(target2.id, connected));
83846
+ registered ? voiceHost && voiceHostDisposals && !voiceHostDisposals.has(connected) && await run2(() => bindRendererVoiceHost(connected, voiceHost, voiceHostDisposals, { enableRuntime: !1 })) : (voiceHost && voiceHostDisposals && !voiceHostDisposals.has(connected) && await run2(() => bindRendererVoiceHost(connected, voiceHost, voiceHostDisposals, { enableRuntime: !1 })), await run2(() => connected.command("Runtime.enable")), await run2(() => connected.command("Page.enable")), throwIfCdpAborted(signal, timeoutMessage), overlayClients.set(target2.id, connected));
83741
83847
  let inspected = !0, snapshot = readOverlayHookSnapshot(await run2(async () => {
83742
83848
  try {
83743
83849
  return await connected.evaluate(OVERLAY_HOOK_SNAPSHOT_EXPRESSION);
@@ -83801,7 +83907,7 @@ async function installBrowserAnnotationStyles(target2, browserClients, operation
83801
83907
  try {
83802
83908
  registered || (await run2(() => connected.command("Page.enable")), await run2(() => connected.command("Page.addScriptToEvaluateOnNewDocument", {
83803
83909
  source: BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE
83804
- })), browserClients.set(target2.id, connected)), await run2(() => connected.evaluate("globalThis.__codexhostBrowserAnnotationStylesV1?.refresh() === true")) !== !0 && await run2(() => evaluateSource(connected, BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE));
83910
+ })), throwIfCdpAborted(signal, timeoutMessage), browserClients.set(target2.id, connected)), await run2(() => connected.evaluate("globalThis.__codexhostBrowserAnnotationStylesV1?.refresh() === true")) !== !0 && await run2(() => evaluateSource(connected, BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE));
83805
83911
  } catch (error51) {
83806
83912
  throw browserClients.delete(target2.id), connected.close(), error51;
83807
83913
  }
@@ -83814,12 +83920,15 @@ async function installLocalThreadRenderer(target2, source, enabledAgents, operat
83814
83920
  renderer.close();
83815
83921
  }
83816
83922
  }
83817
- async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, operations, signal, voiceHost, voiceHostDisposals) {
83923
+ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, operations, signal, voiceHost, voiceHostDisposals, lateVoiceBindings) {
83818
83924
  try {
83819
83925
  let targets = await awaitWithSignal(operations.listTargets(endpoint, signal), signal, "Auxiliary Renderer CDP target discovery timed out"), liveTargets = new Set(targets.map((target2) => target2.id));
83820
83926
  for (let clients of [browserStyleClients, overlayClients])
83821
83927
  for (let [id, client] of clients)
83822
83928
  liveTargets.has(id) || (voiceHostDisposals && unbindRendererVoiceHost(client, voiceHostDisposals), client.close(), clients.delete(id));
83929
+ if (lateVoiceBindings)
83930
+ for (let [id, binding] of lateVoiceBindings)
83931
+ liveTargets.has(id) || (binding.dispose(), binding.client.close(), lateVoiceBindings.delete(id));
83823
83932
  await Promise.allSettled([
83824
83933
  ...targets.filter(isBrowserPage).map((target2) => installBrowserAnnotationStyles(target2, browserStyleClients, operations, signal)),
83825
83934
  ...overlayHookSource ? selectAvatarOverlayRendererTargets(targets).map((overlay) => installOverlayHook(overlay, overlayHookSource, overlayClients, operations, signal, overlayVoiceBootstrapSource, voiceHost, voiceHostDisposals)) : [],
@@ -83828,13 +83937,13 @@ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents
83828
83937
  } catch {
83829
83938
  }
83830
83939
  }
83831
- async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, voiceHost, voiceHostDisposals) {
83832
- let renderer = await operations.connect(target2.webSocketDebuggerUrl), disposeModules;
83940
+ async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, voiceHost, voiceHostDisposals, signal, waitForDocumentLoad) {
83941
+ let timeoutMessage = "Primary Renderer installation timed out", loadSignal = signal ?? (waitForDocumentLoad ? AbortSignal.timeout(timeoutMs) : void 0), run2 = (operation) => loadSignal ? runWithCdpSignal(loadSignal, timeoutMessage, operation) : operation(), renderer = loadSignal ? await connectRendererTarget(target2, operations, loadSignal, timeoutMessage) : await operations.connect(target2.webSocketDebuggerUrl), disposeModules;
83833
83942
  try {
83834
- voiceHost && voiceHostDisposals && await bindRendererVoiceHost(renderer, voiceHost, voiceHostDisposals, {
83943
+ voiceHost && voiceHostDisposals && await run2(() => bindRendererVoiceHost(renderer, voiceHost, voiceHostDisposals, {
83835
83944
  enableRuntime: !1
83836
- }), disposeModules = await installRendererLoadedModules(renderer), await renderer.command("Page.enable"), await renderer.command("Page.addScriptToEvaluateOnNewDocument", { source: rendererSource }), await evaluateSource(renderer, rendererSource);
83837
- let draftPrewarmPolicy = await operations.installDraftPrewarmPolicy(renderer), binding = await waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs);
83945
+ })), waitForDocumentLoad && await waitForRendererDocumentLoad(renderer, run2, loadSignal, timeoutMessage), disposeModules = await run2(() => installRendererLoadedModules(renderer)), await run2(() => renderer.command("Page.enable")), await run2(() => renderer.command("Page.addScriptToEvaluateOnNewDocument", { source: rendererSource })), await run2(() => evaluateSource(renderer, rendererSource));
83946
+ let draftPrewarmPolicy = await run2(() => operations.installDraftPrewarmPolicy(renderer)), binding = await waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs, signal);
83838
83947
  return { renderer, snapshot: { target: target2, draftPrewarmPolicy, binding }, disposeModules };
83839
83948
  } catch (error51) {
83840
83949
  throw disposeModules?.(), voiceHostDisposals && unbindRendererVoiceHost(renderer, voiceHostDisposals), renderer.close(), error51;
@@ -83856,42 +83965,123 @@ var InstalledRendererCdpControlSession = class {
83856
83965
  disposeModules;
83857
83966
  voiceHost;
83858
83967
  voiceHostDisposals;
83968
+ waitForDocumentLoad;
83859
83969
  #closed = !1;
83860
- constructor(renderer, rendererCdpEndpoint, rendererSource, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules, voiceHost, voiceHostDisposals) {
83861
- this.renderer = renderer, this.rendererCdpEndpoint = rendererCdpEndpoint, this.rendererSource = rendererSource, this.overlayHookSource = overlayHookSource, this.overlayVoiceBootstrapSource = overlayVoiceBootstrapSource, this.browserStyleClients = browserStyleClients, this.overlayClients = overlayClients, this.enabledAgents = enabledAgents, this.timeoutMs = timeoutMs, this.pollIntervalMs = pollIntervalMs, this.operations = operations, this.currentSnapshot = currentSnapshot, this.disposeModules = disposeModules, this.voiceHost = voiceHost, this.voiceHostDisposals = voiceHostDisposals;
83970
+ #lateVoiceHost;
83971
+ #lateVoicePrimaryId;
83972
+ #lateVoiceAttach;
83973
+ #lateVoiceBindings = /* @__PURE__ */ new Map();
83974
+ #overlayVoiceRetryAt = /* @__PURE__ */ new Map();
83975
+ // close() aborts this deadline, so discovery, connects, installs, and
83976
+ // liveness probes in flight stop instead of running to their own timeouts.
83977
+ #shutdown = new AbortController();
83978
+ constructor(renderer, rendererCdpEndpoint, rendererSource, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules, voiceHost, voiceHostDisposals, waitForDocumentLoad) {
83979
+ this.renderer = renderer, this.rendererCdpEndpoint = rendererCdpEndpoint, this.rendererSource = rendererSource, this.overlayHookSource = overlayHookSource, this.overlayVoiceBootstrapSource = overlayVoiceBootstrapSource, this.browserStyleClients = browserStyleClients, this.overlayClients = overlayClients, this.enabledAgents = enabledAgents, this.timeoutMs = timeoutMs, this.pollIntervalMs = pollIntervalMs, this.operations = operations, this.currentSnapshot = currentSnapshot, this.disposeModules = disposeModules, this.voiceHost = voiceHost, this.voiceHostDisposals = voiceHostDisposals, this.waitForDocumentLoad = waitForDocumentLoad;
83862
83980
  }
83863
83981
  get snapshot() {
83864
83982
  return this.currentSnapshot;
83865
83983
  }
83866
83984
  async ensureInstalled() {
83985
+ this.#assertOpen();
83986
+ let target2 = await waitForPrimaryTarget(this.rendererCdpEndpoint, this.operations, this.timeoutMs, this.pollIntervalMs, this.currentSnapshot.target.id, this.#shutdown.signal);
83987
+ return this.#assertOpen(), target2.id !== this.currentSnapshot.target.id ? (this.#disposeLateVoiceBinding(this.currentSnapshot.target.id), await this.#replacePrimary(target2)) : await this.#reconcilePrimary(target2), await installAuxiliaryRenderers(this.rendererCdpEndpoint, this.rendererSource, this.enabledAgents, this.overlayHookSource, this.overlayVoiceBootstrapSource, this.browserStyleClients, this.overlayClients, this.operations, discoveryTimeoutSignal(this.timeoutMs, this.#shutdown.signal), this.voiceHost, this.voiceHostDisposals, this.#lateVoiceBindings), this.#assertOpen(), this.currentSnapshot;
83988
+ }
83989
+ async #reconcilePrimary(target2) {
83990
+ try {
83991
+ await this.#runWhileOpen(() => readBinding(this.renderer)) === null && await this.#runWhileOpen(() => evaluateSource(this.renderer, this.rendererSource));
83992
+ let draftPrewarmPolicy = await this.#runWhileOpen(() => this.operations.installDraftPrewarmPolicy(this.renderer)), binding = await waitForBinding(this.renderer, this.enabledAgents, this.timeoutMs, this.pollIntervalMs, this.#shutdown.signal);
83993
+ this.#assertOpen(), this.currentSnapshot = { target: target2, draftPrewarmPolicy, binding };
83994
+ } catch {
83995
+ this.#assertOpen(), this.#disposeLateVoiceBinding(this.currentSnapshot.target.id), await this.#replacePrimary(target2);
83996
+ }
83997
+ }
83998
+ async #replacePrimary(target2) {
83999
+ let replacement = await installTarget(target2, this.rendererSource, this.enabledAgents, this.timeoutMs, this.pollIntervalMs, this.operations, this.voiceHost, this.voiceHostDisposals, this.#shutdown.signal, this.waitForDocumentLoad);
84000
+ if (this.#closed)
84001
+ throw replacement.disposeModules(), unbindRendererVoiceHost(replacement.renderer, this.voiceHostDisposals), replacement.renderer.close(), new Error("Renderer CDP Control Session is closed");
84002
+ this.disposeModules(), unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals), this.renderer.close(), this.renderer = replacement.renderer, this.disposeModules = replacement.disposeModules, this.currentSnapshot = replacement.snapshot;
84003
+ }
84004
+ #assertOpen() {
83867
84005
  if (this.#closed)
83868
84006
  throw new Error("Renderer CDP Control Session is closed");
83869
- let target2 = await waitForPrimaryTarget(this.rendererCdpEndpoint, this.operations, this.timeoutMs, this.pollIntervalMs, this.currentSnapshot.target.id);
83870
- if (target2.id !== this.currentSnapshot.target.id) {
83871
- let replacement = await installTarget(target2, this.rendererSource, this.enabledAgents, this.timeoutMs, this.pollIntervalMs, this.operations, this.voiceHost, this.voiceHostDisposals);
83872
- this.disposeModules(), unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals), this.renderer.close(), this.renderer = replacement.renderer, this.disposeModules = replacement.disposeModules, this.currentSnapshot = replacement.snapshot;
83873
- } else
83874
- try {
83875
- await readBinding(this.renderer) === null && await evaluateSource(this.renderer, this.rendererSource);
83876
- let draftPrewarmPolicy = await this.operations.installDraftPrewarmPolicy(this.renderer), binding = await waitForBinding(this.renderer, this.enabledAgents, this.timeoutMs, this.pollIntervalMs);
83877
- this.currentSnapshot = { target: target2, draftPrewarmPolicy, binding };
83878
- } catch {
83879
- let replacement = await installTarget(target2, this.rendererSource, this.enabledAgents, this.timeoutMs, this.pollIntervalMs, this.operations, this.voiceHost, this.voiceHostDisposals);
83880
- this.disposeModules(), unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals), this.renderer.close(), this.renderer = replacement.renderer, this.disposeModules = replacement.disposeModules, this.currentSnapshot = replacement.snapshot;
84007
+ }
84008
+ #runWhileOpen(operation) {
84009
+ return runWithCdpSignal(this.#shutdown.signal, "Renderer CDP Control Session is closed", operation);
84010
+ }
84011
+ async attachVoiceHost(voiceHost) {
84012
+ if (this.#assertOpen(), !this.voiceHost)
84013
+ return this.#lateVoiceAttach ??= this.#reconcileVoiceHost(voiceHost).finally(() => {
84014
+ this.#lateVoiceAttach = void 0;
84015
+ }), this.#lateVoiceAttach;
84016
+ }
84017
+ async #reconcileVoiceHost(voiceHost) {
84018
+ let timeoutMs = Math.min(this.timeoutMs, VOICE_HOST_ATTACH_TIMEOUT_MS);
84019
+ this.#lateVoiceHost !== void 0 && this.#lateVoiceHost !== voiceHost && this.#disposeLateVoiceBindings();
84020
+ let primaryTarget = this.currentSnapshot.target;
84021
+ this.#lateVoicePrimaryId !== void 0 && this.#lateVoicePrimaryId !== primaryTarget.id && this.#disposeLateVoiceBinding(this.#lateVoicePrimaryId);
84022
+ let existingPrimary = this.#lateVoiceBindings.get(primaryTarget.id);
84023
+ if (existingPrimary && !await lateVoiceBindingIsLive(existingPrimary, this.#shutdown.signal) && this.#disposeLateVoiceBinding(primaryTarget.id), this.#assertOpen(), !this.#lateVoiceBindings.has(primaryTarget.id)) {
84024
+ this.#disposeLateVoiceBinding(primaryTarget.id);
84025
+ let binding = await bindVoiceHostOnNewConnection(primaryTarget, voiceHost, this.operations, timeoutMs, this.#shutdown.signal);
84026
+ if (this.#closed)
84027
+ throw binding.dispose(), binding.client.close(), new Error("Renderer CDP Control Session is closed");
84028
+ this.#lateVoiceBindings.set(binding.targetId, binding);
84029
+ }
84030
+ this.#lateVoicePrimaryId = primaryTarget.id, this.#lateVoiceHost = voiceHost, await this.#reconcileOverlayVoiceHost(voiceHost, timeoutMs), this.#assertOpen();
84031
+ }
84032
+ async #reconcileOverlayVoiceHost(voiceHost, timeoutMs) {
84033
+ if (this.#closed || !this.overlayHookSource)
84034
+ return;
84035
+ let deadline = AbortSignal.any([AbortSignal.timeout(timeoutMs), this.#shutdown.signal]), targets;
84036
+ try {
84037
+ targets = await awaitWithSignal(this.operations.listTargets(this.rendererCdpEndpoint, deadline), deadline, "Late overlay CDP target discovery timed out");
84038
+ } catch {
84039
+ return;
84040
+ }
84041
+ let overlays = selectAvatarOverlayRendererTargets(targets), live = new Set(overlays.map((target2) => target2.id));
84042
+ for (let id of [...this.#lateVoiceBindings.keys()])
84043
+ id !== this.#lateVoicePrimaryId && !live.has(id) && this.#disposeLateVoiceBinding(id);
84044
+ for (let id of [...this.#overlayVoiceRetryAt.keys()])
84045
+ live.has(id) || this.#overlayVoiceRetryAt.delete(id);
84046
+ await Promise.allSettled(overlays.map(async (target2) => {
84047
+ if (this.#closed)
84048
+ return;
84049
+ let existing = this.#lateVoiceBindings.get(target2.id);
84050
+ if (existing) {
84051
+ if (await lateVoiceBindingIsLive(existing, this.#shutdown.signal) || this.#closed)
84052
+ return;
84053
+ this.#disposeLateVoiceBinding(target2.id);
83881
84054
  }
83882
- return await installAuxiliaryRenderers(this.rendererCdpEndpoint, this.rendererSource, this.enabledAgents, this.overlayHookSource, this.overlayVoiceBootstrapSource, this.browserStyleClients, this.overlayClients, this.operations, discoveryTimeoutSignal(this.timeoutMs), this.voiceHost, this.voiceHostDisposals), this.currentSnapshot;
84055
+ if (!((this.#overlayVoiceRetryAt.get(target2.id) ?? 0) > Date.now()))
84056
+ try {
84057
+ let binding = await bindVoiceHostOnNewConnection(target2, voiceHost, this.operations, timeoutMs, this.#shutdown.signal);
84058
+ if (this.#closed) {
84059
+ binding.dispose(), binding.client.close();
84060
+ return;
84061
+ }
84062
+ this.#lateVoiceBindings.set(binding.targetId, binding), this.#overlayVoiceRetryAt.delete(binding.targetId);
84063
+ } catch {
84064
+ this.#overlayVoiceRetryAt.set(target2.id, Date.now() + VOICE_HOST_OVERLAY_RETRY_MS);
84065
+ }
84066
+ }));
84067
+ }
84068
+ #disposeLateVoiceBinding(targetId) {
84069
+ let binding = this.#lateVoiceBindings.get(targetId);
84070
+ binding && (binding.dispose(), binding.client.close(), this.#lateVoiceBindings.delete(targetId), this.#lateVoicePrimaryId === targetId && (this.#lateVoicePrimaryId = void 0), this.#overlayVoiceRetryAt.delete(targetId));
84071
+ }
84072
+ #disposeLateVoiceBindings() {
84073
+ for (let targetId of [...this.#lateVoiceBindings.keys()])
84074
+ this.#disposeLateVoiceBinding(targetId);
83883
84075
  }
83884
84076
  async activateDesktop() {
83885
- if (this.#closed)
83886
- throw new Error("Renderer CDP Control Session is closed");
83887
- return await this.renderer.command("Page.bringToFront"), 1;
84077
+ return this.#assertOpen(), await this.renderer.command("Page.bringToFront"), 1;
83888
84078
  }
83889
84079
  executeRenderer(expression, timeoutMs) {
83890
84080
  return this.#closed ? Promise.reject(new Error("Renderer CDP Control Session is closed")) : this.renderer.evaluate(expression, timeoutMs);
83891
84081
  }
83892
84082
  close() {
83893
84083
  if (!this.#closed) {
83894
- this.#closed = !0, this.disposeModules(), unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals), this.renderer.close();
84084
+ this.#closed = !0, this.#shutdown.abort(new Error("Renderer CDP Control Session is closed")), this.disposeModules(), unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals), this.renderer.close();
83895
84085
  for (let client of this.browserStyleClients.values())
83896
84086
  client.close();
83897
84087
  this.browserStyleClients.clear();
@@ -83900,7 +84090,7 @@ var InstalledRendererCdpControlSession = class {
83900
84090
  this.overlayClients.clear();
83901
84091
  for (let dispose of this.voiceHostDisposals.values())
83902
84092
  dispose();
83903
- this.voiceHostDisposals.clear();
84093
+ this.voiceHostDisposals.clear(), this.#disposeLateVoiceBindings();
83904
84094
  }
83905
84095
  }
83906
84096
  }, defaultOperations = {
@@ -83912,8 +84102,8 @@ var InstalledRendererCdpControlSession = class {
83912
84102
  }
83913
84103
  };
83914
84104
  async function createRendererCdpControlSession(options) {
83915
- let enabledAgents = options.enabledAgents, timeoutMs = options.timeoutMs ?? 3e4, pollIntervalMs = options.pollIntervalMs ?? 250, operations = options.operations ?? defaultOperations, target2 = await waitForPrimaryTarget(options.rendererCdpEndpoint, operations, timeoutMs, pollIntervalMs, void 0, options.signal), voiceHostDisposals = /* @__PURE__ */ new Map(), installed = await installTarget(target2, options.rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, options.voiceHost, voiceHostDisposals), browserStyleClients = /* @__PURE__ */ new Map(), overlayClients = /* @__PURE__ */ new Map();
83916
- return await installAuxiliaryRenderers(options.rendererCdpEndpoint, options.rendererSource, enabledAgents, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, operations, discoveryTimeoutSignal(timeoutMs, options.signal), options.voiceHost, voiceHostDisposals), new InstalledRendererCdpControlSession(installed.renderer, options.rendererCdpEndpoint, options.rendererSource, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, installed.snapshot, installed.disposeModules, options.voiceHost, voiceHostDisposals);
84105
+ let enabledAgents = options.enabledAgents, timeoutMs = options.timeoutMs ?? 3e4, pollIntervalMs = options.pollIntervalMs ?? 250, operations = options.operations ?? defaultOperations, target2 = await waitForPrimaryTarget(options.rendererCdpEndpoint, operations, timeoutMs, pollIntervalMs, void 0, options.signal), voiceHostDisposals = /* @__PURE__ */ new Map(), installed = await installTarget(target2, options.rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, options.voiceHost, voiceHostDisposals, options.signal, options.waitForDocumentLoad), browserStyleClients = /* @__PURE__ */ new Map(), overlayClients = /* @__PURE__ */ new Map();
84106
+ return await installAuxiliaryRenderers(options.rendererCdpEndpoint, options.rendererSource, enabledAgents, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, operations, discoveryTimeoutSignal(timeoutMs, options.signal), options.voiceHost, voiceHostDisposals), new InstalledRendererCdpControlSession(installed.renderer, options.rendererCdpEndpoint, options.rendererSource, options.overlayHookSource, options.overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, installed.snapshot, installed.disposeModules, options.voiceHost, voiceHostDisposals, options.waitForDocumentLoad === !0);
83917
84107
  }
83918
84108
  function installRendererCdpControlSession(options) {
83919
84109
  return createRendererCdpControlSession(options);