@karlorz/codexhost-cli-darwin-x64 0.22.0-0 → 0.22.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-web.js +1 -1
- package/app/cpa-live-voice-hook.js +1 -1
- package/app/desktop-controller.mjs +502 -186
- package/app/host-runtime.mjs +389 -127
- package/app/overlay-voice-bootstrap.js +1 -1
- package/app/renderer-extension.js +1 -1
- package/app/voice-qualification.json +10 -10
- package/app/web/codexhost-settings.js +1 -1
- package/app/web-modules/server.mjs +268 -97
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
|
@@ -21209,6 +21209,7 @@ var RENDERER_VOICE_HOST_MAX_PAYLOAD_BYTES = 256 * 1024;
|
|
|
21209
21209
|
var RENDERER_VOICE_HOST_SETTINGS_TIMEOUT_MS = 1e4;
|
|
21210
21210
|
var RENDERER_VOICE_HOST_GATEWAY_TIMEOUT_MS = 2e3;
|
|
21211
21211
|
var RENDERER_VOICE_HOST_REALTIME_TIMEOUT_MS = 3e4;
|
|
21212
|
+
var RENDERER_VOICE_HOST_PUBLISH_RETRY_MS = 1e3;
|
|
21212
21213
|
var RENDERER_VOICE_HOST_METHODS = [
|
|
21213
21214
|
VOICE_SETTINGS_METHOD,
|
|
21214
21215
|
VOICE_GATEWAY_STATUS_METHOD,
|
|
@@ -21232,7 +21233,7 @@ function cleanupUnconfirmedError(error51) {
|
|
|
21232
21233
|
if (error51 instanceof Error && error51.message === RENDERER_VOICE_HOST_CLEANUP_UNCONFIRMED && allowlistedStage(Reflect.get(error51, "stage")) === "cancel")
|
|
21233
21234
|
return error51;
|
|
21234
21235
|
}
|
|
21235
|
-
function rendererVoiceHostCapabilitySource(owner, generation) {
|
|
21236
|
+
function rendererVoiceHostCapabilitySource(owner, generation, instanceId = "", installationOrder = 0, publisherId2 = "") {
|
|
21236
21237
|
const guard = rendererVoiceHostDocumentGuardExpression();
|
|
21237
21238
|
return `(() => {
|
|
21238
21239
|
if (!${guard}) return true;
|
|
@@ -21244,6 +21245,9 @@ function rendererVoiceHostCapabilitySource(owner, generation) {
|
|
|
21244
21245
|
const maxBytes = ${RENDERER_VOICE_HOST_MAX_PAYLOAD_BYTES};
|
|
21245
21246
|
const ownerId = ${JSON.stringify(owner)};
|
|
21246
21247
|
const generation = ${generation};
|
|
21248
|
+
const instance = ${JSON.stringify(instanceId)};
|
|
21249
|
+
const order = ${installationOrder};
|
|
21250
|
+
const publisher = ${JSON.stringify(publisherId2)};
|
|
21247
21251
|
const settingsTimeout = ${RENDERER_VOICE_HOST_SETTINGS_TIMEOUT_MS};
|
|
21248
21252
|
const gatewayTimeout = ${RENDERER_VOICE_HOST_GATEWAY_TIMEOUT_MS};
|
|
21249
21253
|
const realtimeTimeout = ${RENDERER_VOICE_HOST_REALTIME_TIMEOUT_MS};
|
|
@@ -21261,6 +21265,8 @@ function rendererVoiceHostCapabilitySource(owner, generation) {
|
|
|
21261
21265
|
}
|
|
21262
21266
|
};
|
|
21263
21267
|
const previous = globalThis[cap];
|
|
21268
|
+
// A publish that outlived its installation must leave a newer installation's state intact.
|
|
21269
|
+
if (previous && previous.publisher === publisher && typeof previous.order === "number" && previous.order > order) return true;
|
|
21264
21270
|
if (previous && previous.generation !== generation) settleAll(${JSON.stringify(UNAVAILABLE)});
|
|
21265
21271
|
globalThis[deliver] = (message) => {
|
|
21266
21272
|
if (!message || typeof message !== "object" || typeof message.id !== "string") return;
|
|
@@ -21285,6 +21291,9 @@ function rendererVoiceHostCapabilitySource(owner, generation) {
|
|
|
21285
21291
|
value: Object.freeze({
|
|
21286
21292
|
owner: ownerId,
|
|
21287
21293
|
generation,
|
|
21294
|
+
instance,
|
|
21295
|
+
order,
|
|
21296
|
+
publisher,
|
|
21288
21297
|
request(method, params) {
|
|
21289
21298
|
try {
|
|
21290
21299
|
if (!${guard}) return unavailable();
|
|
@@ -21316,7 +21325,7 @@ function rendererVoiceHostCapabilitySource(owner, generation) {
|
|
|
21316
21325
|
} catch (e) {}
|
|
21317
21326
|
reject(new Error(${JSON.stringify(UNAVAILABLE)}));
|
|
21318
21327
|
}, timeoutMs);
|
|
21319
|
-
pending.set(id, { resolve, reject, timer, generation });
|
|
21328
|
+
pending.set(id, { resolve, reject, timer, generation, instance });
|
|
21320
21329
|
try {
|
|
21321
21330
|
globalThis[binding](payload);
|
|
21322
21331
|
} catch {
|
|
@@ -21345,20 +21354,6 @@ function callIdFromCreateResult(result) {
|
|
|
21345
21354
|
const callId = realtimeCallIdFromLocation(location);
|
|
21346
21355
|
return isRealtimeCallId(callId) ? callId : void 0;
|
|
21347
21356
|
}
|
|
21348
|
-
async function cleanupAbandonedCreate(execution, params, result) {
|
|
21349
|
-
let unconfirmed;
|
|
21350
|
-
const note = (error51) => {
|
|
21351
|
-
unconfirmed ??= cleanupUnconfirmedError(error51);
|
|
21352
|
-
};
|
|
21353
|
-
const requestId2 = typeof params.requestId === "string" ? params.requestId : void 0;
|
|
21354
|
-
if (requestId2) {
|
|
21355
|
-
await execution.request(REALTIME_CALL_METHOD, { operation: "cancel", requestId: requestId2 }).catch(note);
|
|
21356
|
-
}
|
|
21357
|
-
const callId = callIdFromCreateResult(result);
|
|
21358
|
-
if (!callId) return unconfirmed;
|
|
21359
|
-
await execution.request(REALTIME_CALL_METHOD, { operation: "hangup", callId }).catch(note);
|
|
21360
|
-
return unconfirmed;
|
|
21361
|
-
}
|
|
21362
21357
|
function captureExecution(host) {
|
|
21363
21358
|
return host.bindExecution?.() ?? {
|
|
21364
21359
|
generation: host.generation,
|
|
@@ -21394,22 +21389,48 @@ async function deliver(renderer, executionContextId, message) {
|
|
|
21394
21389
|
returnByValue: true
|
|
21395
21390
|
}).catch(() => void 0);
|
|
21396
21391
|
}
|
|
21397
|
-
async function
|
|
21398
|
-
if (previousId) {
|
|
21399
|
-
await renderer.command("Page.removeScriptToEvaluateOnNewDocument", { identifier: previousId }).catch(() => void 0);
|
|
21400
|
-
}
|
|
21392
|
+
async function addFutureScript(renderer, source) {
|
|
21401
21393
|
const added = await renderer.command("Page.addScriptToEvaluateOnNewDocument", { source });
|
|
21402
|
-
|
|
21394
|
+
if (!isRecord2(added) || typeof added.identifier !== "string")
|
|
21395
|
+
throw new Error("Voice Host future script registration failed");
|
|
21396
|
+
return added.identifier;
|
|
21403
21397
|
}
|
|
21404
21398
|
async function removeFutureScript(renderer, identifier) {
|
|
21405
21399
|
if (!identifier) return;
|
|
21406
21400
|
await renderer.command("Page.removeScriptToEvaluateOnNewDocument", { identifier }).catch(() => void 0);
|
|
21407
21401
|
}
|
|
21402
|
+
function rendererVoiceHostCleanupSource(instanceId) {
|
|
21403
|
+
return `(() => {
|
|
21404
|
+
const instance = ${JSON.stringify(instanceId)};
|
|
21405
|
+
const pending = globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}];
|
|
21406
|
+
if (pending && typeof pending.forEach === "function") {
|
|
21407
|
+
for (const [id, wait] of [...pending.entries()]) {
|
|
21408
|
+
if (!wait || wait.instance !== instance) continue;
|
|
21409
|
+
pending.delete(id);
|
|
21410
|
+
try { clearTimeout(wait.timer); } catch (e) {}
|
|
21411
|
+
try { wait.reject(new Error(${JSON.stringify(UNKNOWN_OUTCOME)})); } catch (e) {}
|
|
21412
|
+
}
|
|
21413
|
+
}
|
|
21414
|
+
const capability = globalThis[${JSON.stringify(RENDERER_VOICE_HOST_CAPABILITY_GLOBAL)}];
|
|
21415
|
+
if (capability && capability.instance === instance) {
|
|
21416
|
+
delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_CAPABILITY_GLOBAL)}];
|
|
21417
|
+
delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_DELIVER_GLOBAL)}];
|
|
21418
|
+
if (globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}] === pending)
|
|
21419
|
+
delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}];
|
|
21420
|
+
}
|
|
21421
|
+
return true;
|
|
21422
|
+
})()`;
|
|
21423
|
+
}
|
|
21424
|
+
var publisherId = crypto.randomUUID();
|
|
21425
|
+
var installationSequence = 0;
|
|
21408
21426
|
async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
21427
|
+
const instance = crypto.randomUUID();
|
|
21428
|
+
const installationOrder = installationSequence += 1;
|
|
21409
21429
|
let disposed = false;
|
|
21430
|
+
let ready = false;
|
|
21410
21431
|
let scriptId;
|
|
21432
|
+
let publishedGeneration;
|
|
21411
21433
|
let publishing = Promise.resolve();
|
|
21412
|
-
const inflight = /* @__PURE__ */ new Set();
|
|
21413
21434
|
const works = /* @__PURE__ */ new Map();
|
|
21414
21435
|
const abandonedIds = /* @__PURE__ */ new Set();
|
|
21415
21436
|
const contexts = /* @__PURE__ */ new Map();
|
|
@@ -21432,20 +21453,47 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
|
21432
21453
|
stage: "cancel"
|
|
21433
21454
|
});
|
|
21434
21455
|
};
|
|
21435
|
-
const
|
|
21436
|
-
|
|
21456
|
+
const reportCleanupUnconfirmed = (item, error51) => {
|
|
21457
|
+
const create = item.create;
|
|
21458
|
+
const unconfirmed = cleanupUnconfirmedError(error51);
|
|
21459
|
+
if (!create || !unconfirmed || create.cleanupReported) return;
|
|
21460
|
+
create.cleanupReported = true;
|
|
21461
|
+
void observeCleanupUnconfirmed(item.contextId, item.pageId, unconfirmed);
|
|
21462
|
+
};
|
|
21463
|
+
const requestCleanup = (item, params) => {
|
|
21464
|
+
try {
|
|
21465
|
+
void item.execution.request(REALTIME_CALL_METHOD, params).catch((error51) => reportCleanupUnconfirmed(item, error51));
|
|
21466
|
+
} catch (error51) {
|
|
21467
|
+
reportCleanupUnconfirmed(item, error51);
|
|
21468
|
+
}
|
|
21469
|
+
};
|
|
21470
|
+
const hangUpLateCreate = (item) => {
|
|
21471
|
+
const create = item.create;
|
|
21472
|
+
if (!create || create.hangupIssued) return;
|
|
21473
|
+
const callId = callIdFromCreateResult(create.result);
|
|
21474
|
+
if (!callId) return;
|
|
21475
|
+
create.hangupIssued = true;
|
|
21476
|
+
requestCleanup(item, { operation: "hangup", callId });
|
|
21477
|
+
};
|
|
21478
|
+
const retireWork = (item) => {
|
|
21437
21479
|
item.abandoned = true;
|
|
21438
|
-
|
|
21439
|
-
|
|
21440
|
-
|
|
21441
|
-
|
|
21442
|
-
|
|
21443
|
-
|
|
21480
|
+
const create = item.create;
|
|
21481
|
+
if (!create) return;
|
|
21482
|
+
if (create.settled) {
|
|
21483
|
+
hangUpLateCreate(item);
|
|
21484
|
+
return;
|
|
21485
|
+
}
|
|
21486
|
+
if (create.cancelIssued) return;
|
|
21487
|
+
create.cancelIssued = true;
|
|
21488
|
+
requestCleanup(item, { operation: "cancel", requestId: create.requestId });
|
|
21489
|
+
};
|
|
21490
|
+
const retireInflight = () => {
|
|
21491
|
+
for (const item of works.values()) retireWork(item);
|
|
21444
21492
|
};
|
|
21445
21493
|
const abandonMatching = (contextId, uniqueId) => {
|
|
21446
21494
|
for (const item of works.values()) {
|
|
21447
21495
|
if (contextId !== void 0 && item.contextId === contextId || uniqueId !== void 0 && item.uniqueId === uniqueId)
|
|
21448
|
-
|
|
21496
|
+
retireWork(item);
|
|
21449
21497
|
}
|
|
21450
21498
|
};
|
|
21451
21499
|
const forgetContext = (params) => {
|
|
@@ -21471,7 +21519,7 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
|
21471
21519
|
const unsubscribeDestroyed = renderer.on("Runtime.executionContextDestroyed", forgetContext);
|
|
21472
21520
|
const unsubscribeCleared = renderer.on("Runtime.executionContextsCleared", () => {
|
|
21473
21521
|
contexts.clear();
|
|
21474
|
-
for (const item of works.values())
|
|
21522
|
+
for (const item of works.values()) retireWork(item);
|
|
21475
21523
|
});
|
|
21476
21524
|
const contextIsVerified = async (executionContextId, uniqueId) => {
|
|
21477
21525
|
const tracked = contexts.get(executionContextId);
|
|
@@ -21482,39 +21530,71 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
|
21482
21530
|
if (!document?.top) return false;
|
|
21483
21531
|
return isEligibleVoiceHostUrl(document.href);
|
|
21484
21532
|
};
|
|
21485
|
-
|
|
21486
|
-
|
|
21487
|
-
|
|
21488
|
-
|
|
21489
|
-
|
|
21490
|
-
if (disposed || host.generation !== startedGeneration) {
|
|
21491
|
-
await removeFutureScript(renderer, addedId);
|
|
21492
|
-
return;
|
|
21493
|
-
}
|
|
21494
|
-
scriptId = addedId;
|
|
21495
|
-
await renderer.evaluate(source);
|
|
21533
|
+
let publishRetry;
|
|
21534
|
+
const clearPublishRetry = () => {
|
|
21535
|
+
if (publishRetry === void 0) return;
|
|
21536
|
+
clearTimeout(publishRetry);
|
|
21537
|
+
publishRetry = void 0;
|
|
21496
21538
|
};
|
|
21497
|
-
const
|
|
21498
|
-
|
|
21539
|
+
const schedulePublishRetry = () => {
|
|
21540
|
+
if (disposed || publishRetry !== void 0) return;
|
|
21541
|
+
publishRetry = setTimeout(() => {
|
|
21542
|
+
publishRetry = void 0;
|
|
21543
|
+
if (disposed) return;
|
|
21544
|
+
void enqueuePublish().catch(() => schedulePublishRetry());
|
|
21545
|
+
}, RENDERER_VOICE_HOST_PUBLISH_RETRY_MS);
|
|
21499
21546
|
};
|
|
21500
|
-
const
|
|
21501
|
-
|
|
21502
|
-
|
|
21503
|
-
|
|
21504
|
-
|
|
21547
|
+
const cleanupPageState = async () => {
|
|
21548
|
+
try {
|
|
21549
|
+
await renderer.evaluate(rendererVoiceHostCleanupSource(instance));
|
|
21550
|
+
} catch {
|
|
21551
|
+
}
|
|
21552
|
+
};
|
|
21553
|
+
const publishGeneration = async () => {
|
|
21554
|
+
for (let attempt = 0; !disposed && attempt < 3; attempt += 1) {
|
|
21555
|
+
const startedGeneration = host.generation;
|
|
21556
|
+
if (startedGeneration === publishedGeneration) return;
|
|
21557
|
+
const source = rendererVoiceHostCapabilitySource(
|
|
21558
|
+
host.owner,
|
|
21559
|
+
startedGeneration,
|
|
21560
|
+
instance,
|
|
21561
|
+
installationOrder,
|
|
21562
|
+
publisherId
|
|
21505
21563
|
);
|
|
21564
|
+
const addedId = await addFutureScript(renderer, source);
|
|
21565
|
+
if (disposed || host.generation !== startedGeneration) {
|
|
21566
|
+
await removeFutureScript(renderer, addedId);
|
|
21567
|
+
continue;
|
|
21568
|
+
}
|
|
21569
|
+
const previousId = scriptId;
|
|
21570
|
+
scriptId = addedId;
|
|
21571
|
+
await removeFutureScript(renderer, previousId);
|
|
21572
|
+
if (disposed) return;
|
|
21573
|
+
await renderer.evaluate(source);
|
|
21574
|
+
if (disposed) {
|
|
21575
|
+
await cleanupPageState();
|
|
21576
|
+
return;
|
|
21577
|
+
}
|
|
21578
|
+
publishedGeneration = startedGeneration;
|
|
21579
|
+
if (host.generation === startedGeneration) return;
|
|
21506
21580
|
}
|
|
21507
21581
|
};
|
|
21508
|
-
|
|
21509
|
-
|
|
21510
|
-
|
|
21511
|
-
|
|
21582
|
+
const enqueuePublish = () => {
|
|
21583
|
+
const next = publishing.catch(() => void 0).then(async () => {
|
|
21584
|
+
await publishGeneration();
|
|
21585
|
+
if (!disposed && host.generation !== publishedGeneration) schedulePublishRetry();
|
|
21586
|
+
else clearPublishRetry();
|
|
21587
|
+
});
|
|
21588
|
+
publishing = next.catch(() => void 0);
|
|
21589
|
+
return next;
|
|
21590
|
+
};
|
|
21512
21591
|
const refresh = () => {
|
|
21513
21592
|
if (disposed) return;
|
|
21514
|
-
|
|
21515
|
-
|
|
21593
|
+
retireInflight();
|
|
21594
|
+
if (!ready) return;
|
|
21595
|
+
void enqueuePublish().catch(() => schedulePublishRetry());
|
|
21516
21596
|
};
|
|
21517
|
-
|
|
21597
|
+
let unsubscribeGeneration;
|
|
21518
21598
|
const unsubscribe = renderer.on("Runtime.bindingCalled", (params) => {
|
|
21519
21599
|
if (disposed || !isRecord2(params) || params.name !== RENDERER_VOICE_HOST_BINDING_NAME) return;
|
|
21520
21600
|
if (typeof params.executionContextId !== "number" || typeof params.payload !== "string") return;
|
|
@@ -21522,7 +21602,7 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
|
21522
21602
|
const contextId = params.executionContextId;
|
|
21523
21603
|
const payloadText = params.payload;
|
|
21524
21604
|
const startedGeneration = host.generation;
|
|
21525
|
-
|
|
21605
|
+
void (async () => {
|
|
21526
21606
|
let parsed;
|
|
21527
21607
|
try {
|
|
21528
21608
|
parsed = JSON.parse(payloadText);
|
|
@@ -21534,7 +21614,7 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
|
21534
21614
|
const requestId2 = parsed.id;
|
|
21535
21615
|
if (parsed.abandon === true) {
|
|
21536
21616
|
const existing = works.get(requestId2);
|
|
21537
|
-
if (existing)
|
|
21617
|
+
if (existing) retireWork(existing);
|
|
21538
21618
|
else abandonedIds.add(requestId2);
|
|
21539
21619
|
return;
|
|
21540
21620
|
}
|
|
@@ -21555,22 +21635,21 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
|
21555
21635
|
generation: startedGeneration,
|
|
21556
21636
|
execution,
|
|
21557
21637
|
abandoned: abandonedIds.has(requestId2),
|
|
21558
|
-
...isCreateOperation(parsed.method, parsed.params) && typeof parsed.params.requestId === "string" ? {
|
|
21638
|
+
...isCreateOperation(parsed.method, parsed.params) && typeof parsed.params.requestId === "string" ? {
|
|
21639
|
+
create: {
|
|
21640
|
+
requestId: parsed.params.requestId,
|
|
21641
|
+
settled: false,
|
|
21642
|
+
cancelIssued: false,
|
|
21643
|
+
hangupIssued: false,
|
|
21644
|
+
cleanupReported: false
|
|
21645
|
+
}
|
|
21646
|
+
} : {}
|
|
21559
21647
|
};
|
|
21560
21648
|
works.set(requestId2, item);
|
|
21561
21649
|
abandonedIds.delete(requestId2);
|
|
21562
21650
|
try {
|
|
21563
21651
|
if (item.abandoned) {
|
|
21564
|
-
|
|
21565
|
-
await observeCleanupUnconfirmed(
|
|
21566
|
-
contextId,
|
|
21567
|
-
requestId2,
|
|
21568
|
-
await cleanupAbandonedCreate(
|
|
21569
|
-
item.execution,
|
|
21570
|
-
{ requestId: item.create.requestId, operation: "create" },
|
|
21571
|
-
item.create.result
|
|
21572
|
-
)
|
|
21573
|
-
);
|
|
21652
|
+
retireWork(item);
|
|
21574
21653
|
return;
|
|
21575
21654
|
}
|
|
21576
21655
|
const method = parsed.method;
|
|
@@ -21578,12 +21657,7 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
|
21578
21657
|
const verified = await contextIsVerified(contextId, uniqueId);
|
|
21579
21658
|
const still = contexts.get(contextId);
|
|
21580
21659
|
if (disposed || item.abandoned || host.generation !== startedGeneration || still?.uniqueId !== uniqueId) {
|
|
21581
|
-
|
|
21582
|
-
await observeCleanupUnconfirmed(
|
|
21583
|
-
contextId,
|
|
21584
|
-
requestId2,
|
|
21585
|
-
await cleanupAbandonedCreate(item.execution, requestParams, item.create.result)
|
|
21586
|
-
);
|
|
21660
|
+
retireWork(item);
|
|
21587
21661
|
return;
|
|
21588
21662
|
}
|
|
21589
21663
|
if (!verified) {
|
|
@@ -21597,21 +21671,21 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
|
21597
21671
|
}
|
|
21598
21672
|
try {
|
|
21599
21673
|
const result = await item.execution.request(method, requestParams);
|
|
21600
|
-
if (item.create)
|
|
21674
|
+
if (item.create) {
|
|
21675
|
+
item.create.result = result;
|
|
21676
|
+
item.create.settled = true;
|
|
21677
|
+
}
|
|
21601
21678
|
const after = contexts.get(contextId);
|
|
21602
21679
|
if (disposed || item.abandoned || host.generation !== startedGeneration || after?.uniqueId !== uniqueId) {
|
|
21603
|
-
|
|
21604
|
-
await observeCleanupUnconfirmed(
|
|
21605
|
-
contextId,
|
|
21606
|
-
requestId2,
|
|
21607
|
-
await cleanupAbandonedCreate(item.execution, requestParams, result)
|
|
21608
|
-
);
|
|
21680
|
+
retireWork(item);
|
|
21609
21681
|
return;
|
|
21610
21682
|
}
|
|
21611
21683
|
await deliver(renderer, contextId, { id: requestId2, ok: true, result });
|
|
21612
21684
|
} catch (error51) {
|
|
21685
|
+
if (item.create) item.create.settled = true;
|
|
21613
21686
|
const unconfirmed = cleanupUnconfirmedError(error51);
|
|
21614
21687
|
if (unconfirmed && !disposed) {
|
|
21688
|
+
if (item.create) item.create.cleanupReported = true;
|
|
21615
21689
|
await deliver(renderer, contextId, {
|
|
21616
21690
|
id: requestId2,
|
|
21617
21691
|
ok: false,
|
|
@@ -21633,52 +21707,33 @@ async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
|
21633
21707
|
works.delete(requestId2);
|
|
21634
21708
|
}
|
|
21635
21709
|
})();
|
|
21636
|
-
inflight.add(work);
|
|
21637
|
-
void work.finally(() => inflight.delete(work));
|
|
21638
21710
|
});
|
|
21639
|
-
|
|
21711
|
+
const dispose = () => {
|
|
21640
21712
|
if (disposed) return;
|
|
21641
21713
|
disposed = true;
|
|
21714
|
+
clearPublishRetry();
|
|
21642
21715
|
unsubscribeGeneration?.();
|
|
21643
21716
|
unsubscribe();
|
|
21644
21717
|
unsubscribeCreated();
|
|
21645
21718
|
unsubscribeDestroyed();
|
|
21646
21719
|
unsubscribeCleared();
|
|
21647
|
-
|
|
21648
|
-
const outstanding = [...inflight];
|
|
21649
|
-
const leftover = [...works.values()];
|
|
21650
|
-
void Promise.allSettled(outstanding).then(async () => {
|
|
21651
|
-
for (const item of leftover)
|
|
21652
|
-
if (item.create)
|
|
21653
|
-
await observeCleanupUnconfirmed(
|
|
21654
|
-
item.contextId,
|
|
21655
|
-
item.pageId,
|
|
21656
|
-
await cleanupAbandonedCreate(
|
|
21657
|
-
item.execution,
|
|
21658
|
-
{ requestId: item.create.requestId, operation: "create" },
|
|
21659
|
-
item.create.result
|
|
21660
|
-
)
|
|
21661
|
-
);
|
|
21662
|
-
});
|
|
21720
|
+
retireInflight();
|
|
21663
21721
|
void removeFutureScript(renderer, scriptId);
|
|
21664
21722
|
void renderer.command("Runtime.removeBinding", { name: RENDERER_VOICE_HOST_BINDING_NAME }).catch(() => void 0);
|
|
21665
|
-
void
|
|
21666
|
-
`(() => {
|
|
21667
|
-
const pending = globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}];
|
|
21668
|
-
if (pending && typeof pending.forEach === "function") {
|
|
21669
|
-
for (const [id, wait] of [...pending.entries()]) {
|
|
21670
|
-
pending.delete(id);
|
|
21671
|
-
try { clearTimeout(wait.timer); } catch (e) {}
|
|
21672
|
-
try { wait.reject(new Error(${JSON.stringify(UNKNOWN_OUTCOME)})); } catch (e) {}
|
|
21673
|
-
}
|
|
21674
|
-
}
|
|
21675
|
-
delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_CAPABILITY_GLOBAL)}];
|
|
21676
|
-
delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_DELIVER_GLOBAL)}];
|
|
21677
|
-
delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}];
|
|
21678
|
-
return true;
|
|
21679
|
-
})()`
|
|
21680
|
-
).catch(() => void 0);
|
|
21723
|
+
void cleanupPageState();
|
|
21681
21724
|
};
|
|
21725
|
+
try {
|
|
21726
|
+
unsubscribeGeneration = host.onGenerationChange?.(refresh);
|
|
21727
|
+
if (options?.enableRuntime !== false) await renderer.command("Runtime.enable");
|
|
21728
|
+
await renderer.command("Page.enable");
|
|
21729
|
+
await renderer.command("Runtime.addBinding", { name: RENDERER_VOICE_HOST_BINDING_NAME });
|
|
21730
|
+
ready = true;
|
|
21731
|
+
await enqueuePublish();
|
|
21732
|
+
} catch (error51) {
|
|
21733
|
+
dispose();
|
|
21734
|
+
throw error51;
|
|
21735
|
+
}
|
|
21736
|
+
return dispose;
|
|
21682
21737
|
}
|
|
21683
21738
|
|
|
21684
21739
|
// packages/desktop-control/src/renderer-cdp-control-session.ts
|
|
@@ -21695,6 +21750,9 @@ function discoveryTimeoutSignal(timeoutMs, signal) {
|
|
|
21695
21750
|
function abortFailure(signal, fallback) {
|
|
21696
21751
|
return signal.reason instanceof Error ? signal.reason : new Error(fallback);
|
|
21697
21752
|
}
|
|
21753
|
+
function throwIfCdpAborted(signal, fallback) {
|
|
21754
|
+
if (signal.aborted) throw abortFailure(signal, fallback);
|
|
21755
|
+
}
|
|
21698
21756
|
function awaitWithSignal(promise2, signal, timeoutMessage) {
|
|
21699
21757
|
if (signal.aborted) return Promise.reject(abortFailure(signal, timeoutMessage));
|
|
21700
21758
|
return new Promise((resolve, reject) => {
|
|
@@ -21808,6 +21866,40 @@ function unbindRendererVoiceHost(renderer, disposals) {
|
|
|
21808
21866
|
disposals.get(renderer)?.();
|
|
21809
21867
|
disposals.delete(renderer);
|
|
21810
21868
|
}
|
|
21869
|
+
var VOICE_HOST_ATTACH_TIMEOUT_MS = 15e3;
|
|
21870
|
+
var VOICE_HOST_OVERLAY_RETRY_MS = 5e3;
|
|
21871
|
+
var VOICE_HOST_LIVENESS_INTERVAL_MS = 5e3;
|
|
21872
|
+
var VOICE_HOST_LIVENESS_TIMEOUT_MS = 3e3;
|
|
21873
|
+
async function bindVoiceHostOnNewConnection(target2, voiceHost, operations, timeoutMs, signal) {
|
|
21874
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
21875
|
+
const deadline = signal ? AbortSignal.any([timeout, signal]) : timeout;
|
|
21876
|
+
const timeoutMessage = "Voice Host attachment timed out";
|
|
21877
|
+
const client = await connectRendererTarget(target2, operations, deadline, timeoutMessage);
|
|
21878
|
+
const installing = installRendererVoiceHostBinding(client, voiceHost);
|
|
21879
|
+
try {
|
|
21880
|
+
const dispose = await awaitWithSignal(installing, deadline, timeoutMessage);
|
|
21881
|
+
return { targetId: target2.id, client, dispose, verifiedAt: Date.now() };
|
|
21882
|
+
} catch (error51) {
|
|
21883
|
+
client.close();
|
|
21884
|
+
throw error51;
|
|
21885
|
+
}
|
|
21886
|
+
}
|
|
21887
|
+
async function lateVoiceBindingIsLive(binding, signal) {
|
|
21888
|
+
if (Date.now() - binding.verifiedAt < VOICE_HOST_LIVENESS_INTERVAL_MS) return true;
|
|
21889
|
+
if (signal.aborted) return false;
|
|
21890
|
+
const deadline = AbortSignal.any([AbortSignal.timeout(VOICE_HOST_LIVENESS_TIMEOUT_MS), signal]);
|
|
21891
|
+
try {
|
|
21892
|
+
await awaitWithSignal(
|
|
21893
|
+
binding.client.evaluate("1", VOICE_HOST_LIVENESS_TIMEOUT_MS),
|
|
21894
|
+
deadline,
|
|
21895
|
+
"Voice Host binding liveness check timed out"
|
|
21896
|
+
);
|
|
21897
|
+
binding.verifiedAt = Date.now();
|
|
21898
|
+
return true;
|
|
21899
|
+
} catch {
|
|
21900
|
+
return false;
|
|
21901
|
+
}
|
|
21902
|
+
}
|
|
21811
21903
|
async function evaluateSource(renderer, source) {
|
|
21812
21904
|
const response = await renderer.command("Runtime.evaluate", {
|
|
21813
21905
|
expression: source,
|
|
@@ -21989,6 +22081,7 @@ async function installOverlayHook(target2, overlayHookSource, overlayClients, op
|
|
|
21989
22081
|
);
|
|
21990
22082
|
await run(() => connected.command("Runtime.enable"));
|
|
21991
22083
|
await run(() => connected.command("Page.enable"));
|
|
22084
|
+
throwIfCdpAborted(signal, timeoutMessage);
|
|
21992
22085
|
overlayClients.set(target2.id, connected);
|
|
21993
22086
|
} else if (voiceHost && voiceHostDisposals && !voiceHostDisposals.has(connected)) {
|
|
21994
22087
|
await run(
|
|
@@ -22081,6 +22174,7 @@ async function installBrowserAnnotationStyles(target2, browserClients, operation
|
|
|
22081
22174
|
source: BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE
|
|
22082
22175
|
})
|
|
22083
22176
|
);
|
|
22177
|
+
throwIfCdpAborted(signal, timeoutMessage);
|
|
22084
22178
|
browserClients.set(target2.id, connected);
|
|
22085
22179
|
}
|
|
22086
22180
|
const installed = await run(
|
|
@@ -22114,7 +22208,7 @@ async function installLocalThreadRenderer(target2, source, enabledAgents, operat
|
|
|
22114
22208
|
renderer.close();
|
|
22115
22209
|
}
|
|
22116
22210
|
}
|
|
22117
|
-
async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, operations, signal, voiceHost, voiceHostDisposals) {
|
|
22211
|
+
async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, operations, signal, voiceHost, voiceHostDisposals, lateVoiceBindings) {
|
|
22118
22212
|
try {
|
|
22119
22213
|
const targets = await awaitWithSignal(
|
|
22120
22214
|
operations.listTargets(endpoint, signal),
|
|
@@ -22131,6 +22225,13 @@ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents
|
|
|
22131
22225
|
}
|
|
22132
22226
|
}
|
|
22133
22227
|
}
|
|
22228
|
+
if (lateVoiceBindings)
|
|
22229
|
+
for (const [id, binding] of lateVoiceBindings) {
|
|
22230
|
+
if (liveTargets.has(id)) continue;
|
|
22231
|
+
binding.dispose();
|
|
22232
|
+
binding.client.close();
|
|
22233
|
+
lateVoiceBindings.delete(id);
|
|
22234
|
+
}
|
|
22134
22235
|
await Promise.allSettled([
|
|
22135
22236
|
...targets.filter(isBrowserPage).map(
|
|
22136
22237
|
(target2) => installBrowserAnnotationStyles(target2, browserStyleClients, operations, signal)
|
|
@@ -22154,20 +22255,32 @@ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents
|
|
|
22154
22255
|
} catch {
|
|
22155
22256
|
}
|
|
22156
22257
|
}
|
|
22157
|
-
async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, voiceHost, voiceHostDisposals) {
|
|
22158
|
-
const
|
|
22258
|
+
async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, voiceHost, voiceHostDisposals, signal) {
|
|
22259
|
+
const timeoutMessage = "Primary Renderer installation timed out";
|
|
22260
|
+
const run = (operation) => signal ? runWithCdpSignal(signal, timeoutMessage, operation) : operation();
|
|
22261
|
+
const renderer = signal ? await connectRendererTarget(target2, operations, signal, timeoutMessage) : await operations.connect(target2.webSocketDebuggerUrl);
|
|
22159
22262
|
let disposeModules;
|
|
22160
22263
|
try {
|
|
22161
22264
|
if (voiceHost && voiceHostDisposals)
|
|
22162
|
-
await
|
|
22163
|
-
|
|
22164
|
-
|
|
22165
|
-
|
|
22166
|
-
|
|
22167
|
-
await
|
|
22168
|
-
await
|
|
22169
|
-
|
|
22170
|
-
|
|
22265
|
+
await run(
|
|
22266
|
+
() => bindRendererVoiceHost(renderer, voiceHost, voiceHostDisposals, {
|
|
22267
|
+
enableRuntime: false
|
|
22268
|
+
})
|
|
22269
|
+
);
|
|
22270
|
+
disposeModules = await run(() => installRendererLoadedModules(renderer));
|
|
22271
|
+
await run(() => renderer.command("Page.enable"));
|
|
22272
|
+
await run(
|
|
22273
|
+
() => renderer.command("Page.addScriptToEvaluateOnNewDocument", { source: rendererSource })
|
|
22274
|
+
);
|
|
22275
|
+
await run(() => evaluateSource(renderer, rendererSource));
|
|
22276
|
+
const draftPrewarmPolicy = await run(() => operations.installDraftPrewarmPolicy(renderer));
|
|
22277
|
+
const binding = await waitForBinding(
|
|
22278
|
+
renderer,
|
|
22279
|
+
enabledAgents,
|
|
22280
|
+
timeoutMs,
|
|
22281
|
+
pollIntervalMs,
|
|
22282
|
+
signal
|
|
22283
|
+
);
|
|
22171
22284
|
return { renderer, snapshot: { target: target2, draftPrewarmPolicy, binding }, disposeModules };
|
|
22172
22285
|
} catch (error51) {
|
|
22173
22286
|
disposeModules?.();
|
|
@@ -22210,65 +22323,33 @@ var InstalledRendererCdpControlSession = class {
|
|
|
22210
22323
|
voiceHost;
|
|
22211
22324
|
voiceHostDisposals;
|
|
22212
22325
|
#closed = false;
|
|
22326
|
+
#lateVoiceHost;
|
|
22327
|
+
#lateVoicePrimaryId;
|
|
22328
|
+
#lateVoiceAttach;
|
|
22329
|
+
#lateVoiceBindings = /* @__PURE__ */ new Map();
|
|
22330
|
+
#overlayVoiceRetryAt = /* @__PURE__ */ new Map();
|
|
22331
|
+
// close() aborts this deadline, so discovery, connects, installs, and
|
|
22332
|
+
// liveness probes in flight stop instead of running to their own timeouts.
|
|
22333
|
+
#shutdown = new AbortController();
|
|
22213
22334
|
get snapshot() {
|
|
22214
22335
|
return this.currentSnapshot;
|
|
22215
22336
|
}
|
|
22216
22337
|
async ensureInstalled() {
|
|
22217
|
-
|
|
22338
|
+
this.#assertOpen();
|
|
22218
22339
|
const target2 = await waitForPrimaryTarget(
|
|
22219
22340
|
this.rendererCdpEndpoint,
|
|
22220
22341
|
this.operations,
|
|
22221
22342
|
this.timeoutMs,
|
|
22222
22343
|
this.pollIntervalMs,
|
|
22223
|
-
this.currentSnapshot.target.id
|
|
22344
|
+
this.currentSnapshot.target.id,
|
|
22345
|
+
this.#shutdown.signal
|
|
22224
22346
|
);
|
|
22347
|
+
this.#assertOpen();
|
|
22225
22348
|
if (target2.id !== this.currentSnapshot.target.id) {
|
|
22226
|
-
|
|
22227
|
-
|
|
22228
|
-
this.rendererSource,
|
|
22229
|
-
this.enabledAgents,
|
|
22230
|
-
this.timeoutMs,
|
|
22231
|
-
this.pollIntervalMs,
|
|
22232
|
-
this.operations,
|
|
22233
|
-
this.voiceHost,
|
|
22234
|
-
this.voiceHostDisposals
|
|
22235
|
-
);
|
|
22236
|
-
this.disposeModules();
|
|
22237
|
-
unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals);
|
|
22238
|
-
this.renderer.close();
|
|
22239
|
-
this.renderer = replacement.renderer;
|
|
22240
|
-
this.disposeModules = replacement.disposeModules;
|
|
22241
|
-
this.currentSnapshot = replacement.snapshot;
|
|
22349
|
+
this.#disposeLateVoiceBinding(this.currentSnapshot.target.id);
|
|
22350
|
+
await this.#replacePrimary(target2);
|
|
22242
22351
|
} else {
|
|
22243
|
-
|
|
22244
|
-
const existing = await readBinding(this.renderer);
|
|
22245
|
-
if (existing === null) await evaluateSource(this.renderer, this.rendererSource);
|
|
22246
|
-
const draftPrewarmPolicy = await this.operations.installDraftPrewarmPolicy(this.renderer);
|
|
22247
|
-
const binding = await waitForBinding(
|
|
22248
|
-
this.renderer,
|
|
22249
|
-
this.enabledAgents,
|
|
22250
|
-
this.timeoutMs,
|
|
22251
|
-
this.pollIntervalMs
|
|
22252
|
-
);
|
|
22253
|
-
this.currentSnapshot = { target: target2, draftPrewarmPolicy, binding };
|
|
22254
|
-
} catch {
|
|
22255
|
-
const replacement = await installTarget(
|
|
22256
|
-
target2,
|
|
22257
|
-
this.rendererSource,
|
|
22258
|
-
this.enabledAgents,
|
|
22259
|
-
this.timeoutMs,
|
|
22260
|
-
this.pollIntervalMs,
|
|
22261
|
-
this.operations,
|
|
22262
|
-
this.voiceHost,
|
|
22263
|
-
this.voiceHostDisposals
|
|
22264
|
-
);
|
|
22265
|
-
this.disposeModules();
|
|
22266
|
-
unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals);
|
|
22267
|
-
this.renderer.close();
|
|
22268
|
-
this.renderer = replacement.renderer;
|
|
22269
|
-
this.disposeModules = replacement.disposeModules;
|
|
22270
|
-
this.currentSnapshot = replacement.snapshot;
|
|
22271
|
-
}
|
|
22352
|
+
await this.#reconcilePrimary(target2);
|
|
22272
22353
|
}
|
|
22273
22354
|
await installAuxiliaryRenderers(
|
|
22274
22355
|
this.rendererCdpEndpoint,
|
|
@@ -22279,14 +22360,177 @@ var InstalledRendererCdpControlSession = class {
|
|
|
22279
22360
|
this.browserStyleClients,
|
|
22280
22361
|
this.overlayClients,
|
|
22281
22362
|
this.operations,
|
|
22282
|
-
discoveryTimeoutSignal(this.timeoutMs),
|
|
22363
|
+
discoveryTimeoutSignal(this.timeoutMs, this.#shutdown.signal),
|
|
22283
22364
|
this.voiceHost,
|
|
22284
|
-
this.voiceHostDisposals
|
|
22365
|
+
this.voiceHostDisposals,
|
|
22366
|
+
this.#lateVoiceBindings
|
|
22285
22367
|
);
|
|
22368
|
+
this.#assertOpen();
|
|
22286
22369
|
return this.currentSnapshot;
|
|
22287
22370
|
}
|
|
22288
|
-
async
|
|
22371
|
+
async #reconcilePrimary(target2) {
|
|
22372
|
+
try {
|
|
22373
|
+
const existing = await this.#runWhileOpen(() => readBinding(this.renderer));
|
|
22374
|
+
if (existing === null)
|
|
22375
|
+
await this.#runWhileOpen(() => evaluateSource(this.renderer, this.rendererSource));
|
|
22376
|
+
const draftPrewarmPolicy = await this.#runWhileOpen(
|
|
22377
|
+
() => this.operations.installDraftPrewarmPolicy(this.renderer)
|
|
22378
|
+
);
|
|
22379
|
+
const binding = await waitForBinding(
|
|
22380
|
+
this.renderer,
|
|
22381
|
+
this.enabledAgents,
|
|
22382
|
+
this.timeoutMs,
|
|
22383
|
+
this.pollIntervalMs,
|
|
22384
|
+
this.#shutdown.signal
|
|
22385
|
+
);
|
|
22386
|
+
this.#assertOpen();
|
|
22387
|
+
this.currentSnapshot = { target: target2, draftPrewarmPolicy, binding };
|
|
22388
|
+
} catch {
|
|
22389
|
+
this.#assertOpen();
|
|
22390
|
+
this.#disposeLateVoiceBinding(this.currentSnapshot.target.id);
|
|
22391
|
+
await this.#replacePrimary(target2);
|
|
22392
|
+
}
|
|
22393
|
+
}
|
|
22394
|
+
async #replacePrimary(target2) {
|
|
22395
|
+
const replacement = await installTarget(
|
|
22396
|
+
target2,
|
|
22397
|
+
this.rendererSource,
|
|
22398
|
+
this.enabledAgents,
|
|
22399
|
+
this.timeoutMs,
|
|
22400
|
+
this.pollIntervalMs,
|
|
22401
|
+
this.operations,
|
|
22402
|
+
this.voiceHost,
|
|
22403
|
+
this.voiceHostDisposals,
|
|
22404
|
+
this.#shutdown.signal
|
|
22405
|
+
);
|
|
22406
|
+
if (this.#closed) {
|
|
22407
|
+
replacement.disposeModules();
|
|
22408
|
+
unbindRendererVoiceHost(replacement.renderer, this.voiceHostDisposals);
|
|
22409
|
+
replacement.renderer.close();
|
|
22410
|
+
throw new Error("Renderer CDP Control Session is closed");
|
|
22411
|
+
}
|
|
22412
|
+
this.disposeModules();
|
|
22413
|
+
unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals);
|
|
22414
|
+
this.renderer.close();
|
|
22415
|
+
this.renderer = replacement.renderer;
|
|
22416
|
+
this.disposeModules = replacement.disposeModules;
|
|
22417
|
+
this.currentSnapshot = replacement.snapshot;
|
|
22418
|
+
}
|
|
22419
|
+
#assertOpen() {
|
|
22289
22420
|
if (this.#closed) throw new Error("Renderer CDP Control Session is closed");
|
|
22421
|
+
}
|
|
22422
|
+
#runWhileOpen(operation) {
|
|
22423
|
+
return runWithCdpSignal(
|
|
22424
|
+
this.#shutdown.signal,
|
|
22425
|
+
"Renderer CDP Control Session is closed",
|
|
22426
|
+
operation
|
|
22427
|
+
);
|
|
22428
|
+
}
|
|
22429
|
+
async attachVoiceHost(voiceHost) {
|
|
22430
|
+
this.#assertOpen();
|
|
22431
|
+
if (this.voiceHost) return;
|
|
22432
|
+
this.#lateVoiceAttach ??= this.#reconcileVoiceHost(voiceHost).finally(() => {
|
|
22433
|
+
this.#lateVoiceAttach = void 0;
|
|
22434
|
+
});
|
|
22435
|
+
return this.#lateVoiceAttach;
|
|
22436
|
+
}
|
|
22437
|
+
async #reconcileVoiceHost(voiceHost) {
|
|
22438
|
+
const timeoutMs = Math.min(this.timeoutMs, VOICE_HOST_ATTACH_TIMEOUT_MS);
|
|
22439
|
+
if (this.#lateVoiceHost !== void 0 && this.#lateVoiceHost !== voiceHost)
|
|
22440
|
+
this.#disposeLateVoiceBindings();
|
|
22441
|
+
const primaryTarget = this.currentSnapshot.target;
|
|
22442
|
+
if (this.#lateVoicePrimaryId !== void 0 && this.#lateVoicePrimaryId !== primaryTarget.id)
|
|
22443
|
+
this.#disposeLateVoiceBinding(this.#lateVoicePrimaryId);
|
|
22444
|
+
const existingPrimary = this.#lateVoiceBindings.get(primaryTarget.id);
|
|
22445
|
+
if (existingPrimary && !await lateVoiceBindingIsLive(existingPrimary, this.#shutdown.signal))
|
|
22446
|
+
this.#disposeLateVoiceBinding(primaryTarget.id);
|
|
22447
|
+
this.#assertOpen();
|
|
22448
|
+
if (!this.#lateVoiceBindings.has(primaryTarget.id)) {
|
|
22449
|
+
this.#disposeLateVoiceBinding(primaryTarget.id);
|
|
22450
|
+
const binding = await bindVoiceHostOnNewConnection(
|
|
22451
|
+
primaryTarget,
|
|
22452
|
+
voiceHost,
|
|
22453
|
+
this.operations,
|
|
22454
|
+
timeoutMs,
|
|
22455
|
+
this.#shutdown.signal
|
|
22456
|
+
);
|
|
22457
|
+
if (this.#closed) {
|
|
22458
|
+
binding.dispose();
|
|
22459
|
+
binding.client.close();
|
|
22460
|
+
throw new Error("Renderer CDP Control Session is closed");
|
|
22461
|
+
}
|
|
22462
|
+
this.#lateVoiceBindings.set(binding.targetId, binding);
|
|
22463
|
+
}
|
|
22464
|
+
this.#lateVoicePrimaryId = primaryTarget.id;
|
|
22465
|
+
this.#lateVoiceHost = voiceHost;
|
|
22466
|
+
await this.#reconcileOverlayVoiceHost(voiceHost, timeoutMs);
|
|
22467
|
+
this.#assertOpen();
|
|
22468
|
+
}
|
|
22469
|
+
async #reconcileOverlayVoiceHost(voiceHost, timeoutMs) {
|
|
22470
|
+
if (this.#closed || !this.overlayHookSource) return;
|
|
22471
|
+
const deadline = AbortSignal.any([AbortSignal.timeout(timeoutMs), this.#shutdown.signal]);
|
|
22472
|
+
let targets;
|
|
22473
|
+
try {
|
|
22474
|
+
targets = await awaitWithSignal(
|
|
22475
|
+
this.operations.listTargets(this.rendererCdpEndpoint, deadline),
|
|
22476
|
+
deadline,
|
|
22477
|
+
"Late overlay CDP target discovery timed out"
|
|
22478
|
+
);
|
|
22479
|
+
} catch {
|
|
22480
|
+
return;
|
|
22481
|
+
}
|
|
22482
|
+
const overlays = selectAvatarOverlayRendererTargets(targets);
|
|
22483
|
+
const live = new Set(overlays.map((target2) => target2.id));
|
|
22484
|
+
for (const id of [...this.#lateVoiceBindings.keys()])
|
|
22485
|
+
if (id !== this.#lateVoicePrimaryId && !live.has(id)) this.#disposeLateVoiceBinding(id);
|
|
22486
|
+
for (const id of [...this.#overlayVoiceRetryAt.keys()])
|
|
22487
|
+
if (!live.has(id)) this.#overlayVoiceRetryAt.delete(id);
|
|
22488
|
+
await Promise.allSettled(
|
|
22489
|
+
overlays.map(async (target2) => {
|
|
22490
|
+
if (this.#closed) return;
|
|
22491
|
+
const existing = this.#lateVoiceBindings.get(target2.id);
|
|
22492
|
+
if (existing) {
|
|
22493
|
+
if (await lateVoiceBindingIsLive(existing, this.#shutdown.signal)) return;
|
|
22494
|
+
if (this.#closed) return;
|
|
22495
|
+
this.#disposeLateVoiceBinding(target2.id);
|
|
22496
|
+
}
|
|
22497
|
+
if ((this.#overlayVoiceRetryAt.get(target2.id) ?? 0) > Date.now()) return;
|
|
22498
|
+
try {
|
|
22499
|
+
const binding = await bindVoiceHostOnNewConnection(
|
|
22500
|
+
target2,
|
|
22501
|
+
voiceHost,
|
|
22502
|
+
this.operations,
|
|
22503
|
+
timeoutMs,
|
|
22504
|
+
this.#shutdown.signal
|
|
22505
|
+
);
|
|
22506
|
+
if (this.#closed) {
|
|
22507
|
+
binding.dispose();
|
|
22508
|
+
binding.client.close();
|
|
22509
|
+
return;
|
|
22510
|
+
}
|
|
22511
|
+
this.#lateVoiceBindings.set(binding.targetId, binding);
|
|
22512
|
+
this.#overlayVoiceRetryAt.delete(binding.targetId);
|
|
22513
|
+
} catch {
|
|
22514
|
+
this.#overlayVoiceRetryAt.set(target2.id, Date.now() + VOICE_HOST_OVERLAY_RETRY_MS);
|
|
22515
|
+
}
|
|
22516
|
+
})
|
|
22517
|
+
);
|
|
22518
|
+
}
|
|
22519
|
+
#disposeLateVoiceBinding(targetId) {
|
|
22520
|
+
const binding = this.#lateVoiceBindings.get(targetId);
|
|
22521
|
+
if (!binding) return;
|
|
22522
|
+
binding.dispose();
|
|
22523
|
+
binding.client.close();
|
|
22524
|
+
this.#lateVoiceBindings.delete(targetId);
|
|
22525
|
+
if (this.#lateVoicePrimaryId === targetId) this.#lateVoicePrimaryId = void 0;
|
|
22526
|
+
this.#overlayVoiceRetryAt.delete(targetId);
|
|
22527
|
+
}
|
|
22528
|
+
#disposeLateVoiceBindings() {
|
|
22529
|
+
for (const targetId of [...this.#lateVoiceBindings.keys()])
|
|
22530
|
+
this.#disposeLateVoiceBinding(targetId);
|
|
22531
|
+
}
|
|
22532
|
+
async activateDesktop() {
|
|
22533
|
+
this.#assertOpen();
|
|
22290
22534
|
await this.renderer.command("Page.bringToFront");
|
|
22291
22535
|
return 1;
|
|
22292
22536
|
}
|
|
@@ -22297,6 +22541,7 @@ var InstalledRendererCdpControlSession = class {
|
|
|
22297
22541
|
close() {
|
|
22298
22542
|
if (this.#closed) return;
|
|
22299
22543
|
this.#closed = true;
|
|
22544
|
+
this.#shutdown.abort(new Error("Renderer CDP Control Session is closed"));
|
|
22300
22545
|
this.disposeModules();
|
|
22301
22546
|
unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals);
|
|
22302
22547
|
this.renderer.close();
|
|
@@ -22309,6 +22554,7 @@ var InstalledRendererCdpControlSession = class {
|
|
|
22309
22554
|
this.overlayClients.clear();
|
|
22310
22555
|
for (const dispose of this.voiceHostDisposals.values()) dispose();
|
|
22311
22556
|
this.voiceHostDisposals.clear();
|
|
22557
|
+
this.#disposeLateVoiceBindings();
|
|
22312
22558
|
}
|
|
22313
22559
|
};
|
|
22314
22560
|
var defaultOperations = {
|
|
@@ -22777,6 +23023,8 @@ var TRANSIENT_INSTALL_RETRY_MS = 250;
|
|
|
22777
23023
|
var RECOVERY_RETRY_INITIAL_MS = 3e4;
|
|
22778
23024
|
var RECOVERY_RETRY_MAX_MS = 3e5;
|
|
22779
23025
|
var REMOTE_CONNECTION_RECOVERY_INTERVAL_MS = 5e3;
|
|
23026
|
+
var VOICE_HOST_RETRY_INITIAL_MS = 1e3;
|
|
23027
|
+
var VOICE_HOST_RETRY_MAX_MS = 3e4;
|
|
22780
23028
|
var SHUTDOWN_OPERATION_WAIT_MS = 3e3;
|
|
22781
23029
|
async function settleWithin(promise2, milliseconds) {
|
|
22782
23030
|
let timer;
|
|
@@ -22929,6 +23177,8 @@ async function runDesktopController(options, signal, dependencies = defaultDepen
|
|
|
22929
23177
|
const now = dependencies.now ?? Date.now;
|
|
22930
23178
|
let session;
|
|
22931
23179
|
let voiceHost;
|
|
23180
|
+
let nextVoiceHostAt = 0;
|
|
23181
|
+
let voiceHostDelayMs = VOICE_HOST_RETRY_INITIAL_MS;
|
|
22932
23182
|
let nextRecoveryAt = 0;
|
|
22933
23183
|
let recoveryDelayMs = RECOVERY_RETRY_INITIAL_MS;
|
|
22934
23184
|
const overlayDir = path6.dirname(options.rendererPath);
|
|
@@ -22990,10 +23240,14 @@ ${bootstrap}${overlayBundle}` : void 0;
|
|
|
22990
23240
|
${bootstrap}${overlayBootstrapBundle}` : void 0;
|
|
22991
23241
|
startupTrace("installing Renderer Session");
|
|
22992
23242
|
if (!voiceHost && options.hostDataDirectory && !skipReason) {
|
|
22993
|
-
for (let attempt = 0; attempt < 8 && !voiceHost; attempt += 1) {
|
|
23243
|
+
for (let attempt = 0; attempt < 8 && !voiceHost && !signal.aborted; attempt += 1) {
|
|
22994
23244
|
if (attempt > 0) await dependencies.sleep(250);
|
|
22995
23245
|
voiceHost = await connectControllerVoiceHost(options.hostDataDirectory);
|
|
22996
23246
|
}
|
|
23247
|
+
if (signal.aborted && voiceHost) {
|
|
23248
|
+
voiceHost.close();
|
|
23249
|
+
voiceHost = void 0;
|
|
23250
|
+
}
|
|
22997
23251
|
}
|
|
22998
23252
|
const installed = await installProductionSession(
|
|
22999
23253
|
{
|
|
@@ -23012,6 +23266,51 @@ ${bootstrap}${rendererSource}`,
|
|
|
23012
23266
|
startupTrace("Renderer Session installed");
|
|
23013
23267
|
return installed;
|
|
23014
23268
|
};
|
|
23269
|
+
const ensureVoiceHost = async (current) => {
|
|
23270
|
+
if (skipReason || !options.hostDataDirectory || signal.aborted) return;
|
|
23271
|
+
let connectedNow = false;
|
|
23272
|
+
if (!voiceHost) {
|
|
23273
|
+
if (now() < nextVoiceHostAt) return;
|
|
23274
|
+
const connected = await connectControllerVoiceHost(options.hostDataDirectory).catch(
|
|
23275
|
+
() => void 0
|
|
23276
|
+
);
|
|
23277
|
+
if (signal.aborted) {
|
|
23278
|
+
connected?.close();
|
|
23279
|
+
return;
|
|
23280
|
+
}
|
|
23281
|
+
if (!connected) {
|
|
23282
|
+
nextVoiceHostAt = now() + voiceHostDelayMs;
|
|
23283
|
+
voiceHostDelayMs = Math.min(voiceHostDelayMs * 2, VOICE_HOST_RETRY_MAX_MS);
|
|
23284
|
+
return;
|
|
23285
|
+
}
|
|
23286
|
+
voiceHost = connected;
|
|
23287
|
+
connectedNow = true;
|
|
23288
|
+
}
|
|
23289
|
+
const host = voiceHost;
|
|
23290
|
+
try {
|
|
23291
|
+
await current.attachVoiceHost(host);
|
|
23292
|
+
} catch (error51) {
|
|
23293
|
+
if (voiceHost === host) {
|
|
23294
|
+
host.close();
|
|
23295
|
+
voiceHost = void 0;
|
|
23296
|
+
}
|
|
23297
|
+
if (signal.aborted) return;
|
|
23298
|
+
nextVoiceHostAt = now() + voiceHostDelayMs;
|
|
23299
|
+
voiceHostDelayMs = Math.min(voiceHostDelayMs * 2, VOICE_HOST_RETRY_MAX_MS);
|
|
23300
|
+
startupTrace("Voice Host attachment deferred", error51);
|
|
23301
|
+
return;
|
|
23302
|
+
}
|
|
23303
|
+
if (signal.aborted || voiceHost !== host) {
|
|
23304
|
+
if (voiceHost === host) {
|
|
23305
|
+
host.close();
|
|
23306
|
+
voiceHost = void 0;
|
|
23307
|
+
}
|
|
23308
|
+
return;
|
|
23309
|
+
}
|
|
23310
|
+
nextVoiceHostAt = 0;
|
|
23311
|
+
voiceHostDelayMs = VOICE_HOST_RETRY_INITIAL_MS;
|
|
23312
|
+
if (connectedNow) startupTrace("Voice Host attached to the installed Renderer Session");
|
|
23313
|
+
};
|
|
23015
23314
|
startupTrace("initialization started");
|
|
23016
23315
|
let operation = Promise.resolve(void 0);
|
|
23017
23316
|
const useSession = (callback) => {
|
|
@@ -23037,10 +23336,19 @@ ${bootstrap}${rendererSource}`,
|
|
|
23037
23336
|
remoteRecovery = void 0;
|
|
23038
23337
|
});
|
|
23039
23338
|
};
|
|
23339
|
+
const releasedSessions = /* @__PURE__ */ new WeakSet();
|
|
23040
23340
|
const resetSession = () => {
|
|
23041
|
-
session
|
|
23341
|
+
if (session && !releasedSessions.has(session)) {
|
|
23342
|
+
releasedSessions.add(session);
|
|
23343
|
+
session.close();
|
|
23344
|
+
}
|
|
23042
23345
|
session = void 0;
|
|
23043
23346
|
};
|
|
23347
|
+
const releaseOwnedResources = () => {
|
|
23348
|
+
resetSession();
|
|
23349
|
+
voiceHost?.close();
|
|
23350
|
+
voiceHost = void 0;
|
|
23351
|
+
};
|
|
23044
23352
|
const ensureSession = async () => {
|
|
23045
23353
|
if (skipReason) throw new Error(skipReason);
|
|
23046
23354
|
if (!session) session = await createSession();
|
|
@@ -23061,6 +23369,8 @@ ${bootstrap}${rendererSource}`,
|
|
|
23061
23369
|
};
|
|
23062
23370
|
let attachmentServer;
|
|
23063
23371
|
try {
|
|
23372
|
+
signal.addEventListener("abort", releaseOwnedResources, { once: true });
|
|
23373
|
+
if (signal.aborted) releaseOwnedResources();
|
|
23064
23374
|
startupTrace("starting attachment server");
|
|
23065
23375
|
attachmentServer = await dependencies.startAttachmentServer({
|
|
23066
23376
|
port: options.attachmentPort,
|
|
@@ -23100,6 +23410,10 @@ ${bootstrap}${rendererSource}`,
|
|
|
23100
23410
|
if (session || skipReason) return;
|
|
23101
23411
|
try {
|
|
23102
23412
|
session = await createSession();
|
|
23413
|
+
if (signal.aborted) {
|
|
23414
|
+
resetSession();
|
|
23415
|
+
return;
|
|
23416
|
+
}
|
|
23103
23417
|
recordRecoverySuccess();
|
|
23104
23418
|
restoreRemoteConnections(session);
|
|
23105
23419
|
} catch (error51) {
|
|
@@ -23114,17 +23428,19 @@ ${bootstrap}${rendererSource}`,
|
|
|
23114
23428
|
await useSession(async () => {
|
|
23115
23429
|
if (!session && now() < nextRecoveryAt) return;
|
|
23116
23430
|
try {
|
|
23117
|
-
|
|
23431
|
+
const current = await recoverSession();
|
|
23432
|
+
restoreRemoteConnections(current);
|
|
23433
|
+
await ensureVoiceHost(current);
|
|
23118
23434
|
} catch {
|
|
23119
23435
|
}
|
|
23120
23436
|
});
|
|
23121
23437
|
}
|
|
23122
23438
|
} finally {
|
|
23439
|
+
signal.removeEventListener("abort", releaseOwnedResources);
|
|
23123
23440
|
await attachmentServer?.close();
|
|
23124
23441
|
await settleWithin(operation, SHUTDOWN_OPERATION_WAIT_MS);
|
|
23125
|
-
|
|
23126
|
-
|
|
23127
|
-
void operation.then(resetSession);
|
|
23442
|
+
releaseOwnedResources();
|
|
23443
|
+
void operation.then(releaseOwnedResources);
|
|
23128
23444
|
}
|
|
23129
23445
|
}
|
|
23130
23446
|
|