@karlorz/codexhost-cli-win32-x64 0.17.0-1 → 0.17.3-0
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-server.mjs +15 -0
- package/app/console-web.js +16 -1
- package/app/cpa-live-voice-hook.js +51 -33
- package/app/desktop-controller.mjs +1182 -46
- package/app/host-runtime.mjs +1239 -59
- package/app/plugins/antigravity/plugin.mjs +42 -7
- package/app/plugins/claude-code/plugin.mjs +15 -0
- package/app/plugins/codebuddy/plugin.mjs +15 -0
- package/app/plugins/codex-usage/plugin.mjs +15 -0
- package/app/plugins/copilot/plugin.mjs +15 -0
- package/app/plugins/cursor-cli/plugin.mjs +34 -3
- package/app/plugins/deepseek-harness/plugin.mjs +15 -0
- package/app/plugins/devin/plugin.mjs +15 -0
- package/app/plugins/grok/plugin.mjs +383 -70
- package/app/plugins/hermes/plugin.mjs +15 -0
- package/app/plugins/kimi-code/plugin.mjs +65 -3
- package/app/plugins/kiro-cli/plugin.mjs +15 -0
- package/app/plugins/omp/plugin.mjs +15 -0
- package/app/plugins/opencode/plugin.mjs +15 -0
- package/app/plugins/pi/plugin.mjs +223 -88
- package/app/plugins/qoder/plugin.mjs +15 -0
- package/app/plugins/qoder-cn/plugin.mjs +15 -0
- package/app/plugins/qwen-code/plugin.mjs +15 -0
- package/app/plugins/workbuddy/plugin.mjs +15 -0
- package/app/plugins/zcode/plugin.mjs +157 -9
- package/app/renderer-extension.js +594 -251
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +0 -0
- package/package.json +1 -1
package/app/host-runtime.mjs
CHANGED
|
@@ -21099,6 +21099,22 @@ var threadSteeringInspectParamsSchema = external_exports.object({
|
|
|
21099
21099
|
text: external_exports.string().optional()
|
|
21100
21100
|
}).strict();
|
|
21101
21101
|
var THREAD_STEER_DELIVERY_PARAM = "codexhostSteerDelivery";
|
|
21102
|
+
var THREAD_STEERING_CONTEXT_PARAM = "codexhost_external_steering";
|
|
21103
|
+
var threadSteeringContextSchema = external_exports.object({
|
|
21104
|
+
kind: external_exports.literal("application"),
|
|
21105
|
+
value: external_exports.string().transform((text, context) => {
|
|
21106
|
+
try {
|
|
21107
|
+
return JSON.parse(text);
|
|
21108
|
+
} catch {
|
|
21109
|
+
context.addIssue({ code: "custom", message: "Invalid steering context JSON" });
|
|
21110
|
+
return external_exports.NEVER;
|
|
21111
|
+
}
|
|
21112
|
+
}).pipe(external_exports.object({
|
|
21113
|
+
expectedTurnId: hostTurnIdSchema,
|
|
21114
|
+
clientUserMessageId: external_exports.string().min(1),
|
|
21115
|
+
delivery: external_exports.enum(["newTurn", "activeTurn"])
|
|
21116
|
+
}).strict())
|
|
21117
|
+
}).strict().transform((context) => context.value);
|
|
21102
21118
|
var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
|
|
21103
21119
|
var threadSteeringInspectResultSchema = external_exports.object({
|
|
21104
21120
|
delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
|
|
@@ -29312,9 +29328,10 @@ function isolateRendererPrewarmConsumption(manager, discardExternal) {
|
|
|
29312
29328
|
}
|
|
29313
29329
|
|
|
29314
29330
|
// packages/desktop-control/dist/renderer-draft-prewarm-runtime.js
|
|
29315
|
-
function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewarmedThreadManager, isCurrentManager, retainResponses = retainRendererHostResponses, isolateConsumption = isolateRendererPrewarmConsumption) {
|
|
29331
|
+
function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewarmedThreadManager, isCurrentManager, retainResponses = retainRendererHostResponses, isolateConsumption = isolateRendererPrewarmConsumption, sendControlRequest) {
|
|
29316
29332
|
let disposed = false;
|
|
29317
29333
|
const originalSend = bridge.sendRequest;
|
|
29334
|
+
const controlSend = (method, parameters) => sendControlRequest ? sendControlRequest(method, parameters) : originalSend.call(bridge, method, parameters);
|
|
29318
29335
|
const originalPrewarm = bridge.prewarmThreadStart;
|
|
29319
29336
|
const originalOnNotification = manager.onNotification;
|
|
29320
29337
|
const originalDispatchAppServerResponse = manager.dispatchAppServerResponse;
|
|
@@ -29400,7 +29417,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
29400
29417
|
bridge.onError(requestId2, error51);
|
|
29401
29418
|
bridgeRequests.clear();
|
|
29402
29419
|
if (isRemoteControlHost && terminate) {
|
|
29403
|
-
void Promise.resolve(
|
|
29420
|
+
void Promise.resolve(controlSend("process/kill", { processHandle: failedProcessHandle })).catch(() => void 0);
|
|
29404
29421
|
}
|
|
29405
29422
|
};
|
|
29406
29423
|
const resetFailedBridge = () => {
|
|
@@ -29563,7 +29580,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
29563
29580
|
];
|
|
29564
29581
|
const startedProcessHandle = bridgeProcessHandle;
|
|
29565
29582
|
try {
|
|
29566
|
-
const started =
|
|
29583
|
+
const started = controlSend("process/spawn", {
|
|
29567
29584
|
command,
|
|
29568
29585
|
processHandle: startedProcessHandle,
|
|
29569
29586
|
cwd: "C:\\",
|
|
@@ -29586,7 +29603,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
29586
29603
|
await startBridge();
|
|
29587
29604
|
if (bridgeState !== "ready")
|
|
29588
29605
|
throw transportError("is not ready");
|
|
29589
|
-
await
|
|
29606
|
+
await controlSend("process/writeStdin", {
|
|
29590
29607
|
processHandle: bridgeProcessHandle,
|
|
29591
29608
|
deltaBase64: utf8Base64(`${JSON.stringify(value2)}
|
|
29592
29609
|
`)
|
|
@@ -29872,7 +29889,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
29872
29889
|
globalThis.clearTimeout(bridgeReadyTimeout);
|
|
29873
29890
|
bridgeReadyTimeout = null;
|
|
29874
29891
|
if (isRemoteControlHost && (bridgeState === "starting" || bridgeState === "ready")) {
|
|
29875
|
-
void Promise.resolve(
|
|
29892
|
+
void Promise.resolve(controlSend("process/kill", { processHandle: bridgeProcessHandle })).catch(() => void 0);
|
|
29876
29893
|
}
|
|
29877
29894
|
bridgeState = "disposed";
|
|
29878
29895
|
const disposedError = transportError("was disposed");
|
|
@@ -29974,11 +29991,12 @@ function resolveRendererHostManager(discovery, hostId2, managerFrom = requestMan
|
|
|
29974
29991
|
}
|
|
29975
29992
|
|
|
29976
29993
|
// packages/desktop-control/dist/renderer-host-routing.js
|
|
29977
|
-
function installRendererHostRouting(root, target, discover, resolve, createPolicy) {
|
|
29994
|
+
function installRendererHostRouting(root, target, discover, resolve, createPolicy, readConnection, publishRouting = true) {
|
|
29978
29995
|
const existing = target.__codexhostHostRoutingV1;
|
|
29979
|
-
if (existing)
|
|
29996
|
+
if (publishRouting && existing)
|
|
29980
29997
|
return existing;
|
|
29981
|
-
|
|
29998
|
+
if (publishRouting)
|
|
29999
|
+
target.__codexhostDraftPrewarmPolicyV1?.dispose?.();
|
|
29982
30000
|
let disposed = false;
|
|
29983
30001
|
let lastDiscovery = null;
|
|
29984
30002
|
const routes = /* @__PURE__ */ new Map();
|
|
@@ -30006,23 +30024,36 @@ function installRendererHostRouting(root, target, discover, resolve, createPolic
|
|
|
30006
30024
|
routes.delete(hostId2);
|
|
30007
30025
|
entry?.route.policy.dispose();
|
|
30008
30026
|
};
|
|
30027
|
+
const connectionFor = (hostId2) => {
|
|
30028
|
+
if (!hostId2.startsWith("remote-control:"))
|
|
30029
|
+
return void 0;
|
|
30030
|
+
try {
|
|
30031
|
+
return readConnection?.(hostId2);
|
|
30032
|
+
} catch {
|
|
30033
|
+
return null;
|
|
30034
|
+
}
|
|
30035
|
+
};
|
|
30036
|
+
const sameConnection = (expected, current) => expected === void 0 ? current === void 0 : current?.owner === expected.owner && current.revision === expected.revision;
|
|
30009
30037
|
const routeFor = (hostId2, discovery) => {
|
|
30010
30038
|
const manager = lookup(hostId2, discovery);
|
|
30039
|
+
const connection = connectionFor(hostId2);
|
|
30011
30040
|
const previous = routes.get(hostId2);
|
|
30012
|
-
if (manager && previous?.route.manager === manager && previous.bridge === manager.requestClient && previous.prewarmed === manager.prewarmedThreadManager && previous.route.policy.owns(manager, manager.requestClient, hostId2, manager.prewarmedThreadManager, true)) {
|
|
30041
|
+
if (manager && previous?.route.manager === manager && previous.bridge === manager.requestClient && previous.prewarmed === manager.prewarmedThreadManager && sameConnection(previous.connection, connection) && previous.route.policy.owns(manager, manager.requestClient, hostId2, manager.prewarmedThreadManager, true)) {
|
|
30013
30042
|
return previous.route;
|
|
30014
30043
|
}
|
|
30015
30044
|
retire(hostId2);
|
|
30016
|
-
if (!manager)
|
|
30045
|
+
if (!manager || connection === null)
|
|
30017
30046
|
return null;
|
|
30018
30047
|
const bridge = manager.requestClient;
|
|
30019
30048
|
const prewarmed = manager.prewarmedThreadManager;
|
|
30020
|
-
const policy = createPolicy(manager, bridge, hostId2, target, prewarmed, () => lookup(hostId2) === manager && manager.requestClient === bridge && manager.prewarmedThreadManager === prewarmed);
|
|
30049
|
+
const policy = createPolicy(manager, bridge, hostId2, target, prewarmed, () => lookup(hostId2) === manager && sameConnection(connection, connectionFor(hostId2)) && manager.requestClient === bridge && manager.prewarmedThreadManager === prewarmed);
|
|
30021
30050
|
const route = { hostId: hostId2, manager, policy };
|
|
30022
|
-
routes.set(hostId2, { route, bridge, prewarmed });
|
|
30051
|
+
routes.set(hostId2, { route, bridge, prewarmed, connection });
|
|
30023
30052
|
return route;
|
|
30024
30053
|
};
|
|
30025
30054
|
const publish = (route) => {
|
|
30055
|
+
if (!publishRouting)
|
|
30056
|
+
return;
|
|
30026
30057
|
const policy = route?.policy;
|
|
30027
30058
|
if (target.__codexhostDraftPrewarmPolicyV1 === policy)
|
|
30028
30059
|
return;
|
|
@@ -30076,7 +30107,7 @@ function installRendererHostRouting(root, target, discover, resolve, createPolic
|
|
|
30076
30107
|
if (!composer) {
|
|
30077
30108
|
for (const [hostId3, entry] of routes) {
|
|
30078
30109
|
const manager = lookup(hostId3, discovery);
|
|
30079
|
-
if (manager !== entry.route.manager || manager.requestClient !== entry.bridge || manager.prewarmedThreadManager !== entry.prewarmed)
|
|
30110
|
+
if (manager !== entry.route.manager || manager.requestClient !== entry.bridge || manager.prewarmedThreadManager !== entry.prewarmed || !sameConnection(entry.connection, connectionFor(hostId3)))
|
|
30080
30111
|
retire(hostId3);
|
|
30081
30112
|
}
|
|
30082
30113
|
}
|
|
@@ -30099,7 +30130,11 @@ function installRendererHostRouting(root, target, discover, resolve, createPolic
|
|
|
30099
30130
|
}
|
|
30100
30131
|
}
|
|
30101
30132
|
};
|
|
30102
|
-
|
|
30133
|
+
if (publishRouting)
|
|
30134
|
+
Object.defineProperty(target, "__codexhostHostRoutingV1", {
|
|
30135
|
+
configurable: true,
|
|
30136
|
+
value: routing
|
|
30137
|
+
});
|
|
30103
30138
|
return routing;
|
|
30104
30139
|
}
|
|
30105
30140
|
|
|
@@ -30154,7 +30189,9 @@ function findRendererHostRpcFamily(store) {
|
|
|
30154
30189
|
if (!record6(members) || typeof members.get !== "function")
|
|
30155
30190
|
continue;
|
|
30156
30191
|
for (const [hostId2, member] of members) {
|
|
30157
|
-
if (typeof hostId2 !== "string" ||
|
|
30192
|
+
if (typeof hostId2 !== "string" || !/^(?:local$|durable$|remote[-:]|ssh:)/u.test(hostId2))
|
|
30193
|
+
continue;
|
|
30194
|
+
if (!record6(member))
|
|
30158
30195
|
continue;
|
|
30159
30196
|
const signal = member.value;
|
|
30160
30197
|
if (!record6(signal) || typeof signal.get !== "function")
|
|
@@ -30276,20 +30313,45 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
|
|
|
30276
30313
|
return existing;
|
|
30277
30314
|
}
|
|
30278
30315
|
let disposed = false;
|
|
30316
|
+
let nativeRouting = null;
|
|
30279
30317
|
let discovery = null;
|
|
30280
30318
|
const routes = /* @__PURE__ */ new Map();
|
|
30281
30319
|
const read = () => {
|
|
30282
30320
|
if (disposed)
|
|
30283
30321
|
return null;
|
|
30284
|
-
|
|
30322
|
+
try {
|
|
30285
30323
|
const store = dependencies2.findStore(root);
|
|
30286
|
-
|
|
30324
|
+
const bound = store && discovery?.store === store ? [...store.familyBindings.values()].includes(discovery.family) : false;
|
|
30325
|
+
if (!bound)
|
|
30326
|
+
discovery = store ? dependencies2.findFamily(store) : null;
|
|
30327
|
+
} catch {
|
|
30328
|
+
discovery = null;
|
|
30287
30329
|
}
|
|
30288
30330
|
return discovery;
|
|
30289
30331
|
};
|
|
30290
30332
|
if (!read())
|
|
30291
30333
|
return null;
|
|
30292
30334
|
const queuePolicy = dependencies2.installQueuePolicy(root, target);
|
|
30335
|
+
const discoverComposer = (composer) => {
|
|
30336
|
+
const owners = dependencies2.discoverComposer(composer);
|
|
30337
|
+
if (!nativeRouting && (owners.managers.length || owners.registries.length)) {
|
|
30338
|
+
try {
|
|
30339
|
+
nativeRouting = dependencies2.installNativeRouting();
|
|
30340
|
+
} catch {
|
|
30341
|
+
}
|
|
30342
|
+
}
|
|
30343
|
+
return owners;
|
|
30344
|
+
};
|
|
30345
|
+
const connectionFor = (hostId2) => {
|
|
30346
|
+
if (!hostId2.startsWith("remote-control:"))
|
|
30347
|
+
return void 0;
|
|
30348
|
+
try {
|
|
30349
|
+
return dependencies2.readConnection?.(hostId2);
|
|
30350
|
+
} catch {
|
|
30351
|
+
return null;
|
|
30352
|
+
}
|
|
30353
|
+
};
|
|
30354
|
+
const sameConnection = (previous, current) => previous === void 0 ? current === void 0 : current?.owner === previous.owner && current.revision === previous.revision;
|
|
30293
30355
|
const isRecord22 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
30294
30356
|
const externalDrafts = /* @__PURE__ */ new Map();
|
|
30295
30357
|
const selectedModels = /* @__PURE__ */ new Map();
|
|
@@ -30375,16 +30437,25 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
|
|
|
30375
30437
|
const postMessage = function(message2, ...rest) {
|
|
30376
30438
|
let routed = message2;
|
|
30377
30439
|
try {
|
|
30378
|
-
routed = disposed ? message2 : routeCreationCall(message2);
|
|
30440
|
+
routed = disposed || routes.size === 0 ? message2 : routeCreationCall(message2);
|
|
30379
30441
|
} catch {
|
|
30380
30442
|
routed = message2;
|
|
30381
30443
|
}
|
|
30382
30444
|
return originalPostMessage.call(this, routed, ...rest);
|
|
30383
30445
|
};
|
|
30384
30446
|
port.postMessage = postMessage;
|
|
30385
|
-
const createRoute = (hostId2, rpc) => {
|
|
30447
|
+
const createRoute = (hostId2, rpc, connection) => {
|
|
30386
30448
|
let retired = false;
|
|
30387
|
-
const isCurrent = () =>
|
|
30449
|
+
const isCurrent = () => {
|
|
30450
|
+
if (retired || disposed || routes.get(hostId2)?.rpc !== rpc || !sameConnection(connection, connectionFor(hostId2)))
|
|
30451
|
+
return false;
|
|
30452
|
+
try {
|
|
30453
|
+
const current = read();
|
|
30454
|
+
return !!current && dependencies2.resolve(current, hostId2) === rpc;
|
|
30455
|
+
} catch {
|
|
30456
|
+
return false;
|
|
30457
|
+
}
|
|
30458
|
+
};
|
|
30388
30459
|
const manager = Object.freeze({
|
|
30389
30460
|
kind: "main-process-rpc",
|
|
30390
30461
|
getHostId: () => hostId2,
|
|
@@ -30472,17 +30543,25 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
|
|
|
30472
30543
|
routes.delete(hostId2);
|
|
30473
30544
|
entry?.route.policy.dispose();
|
|
30474
30545
|
};
|
|
30475
|
-
const routeFor = (hostId2) => {
|
|
30546
|
+
const routeFor = (hostId2, nativeRoute) => {
|
|
30547
|
+
if (disposed)
|
|
30548
|
+
return null;
|
|
30549
|
+
const connection = connectionFor(hostId2);
|
|
30550
|
+
const preferred = nativeRoute === void 0 ? nativeRouting?.forHost(hostId2) : nativeRoute;
|
|
30551
|
+
if (connection === null || preferred) {
|
|
30552
|
+
retire(hostId2);
|
|
30553
|
+
return connection === null ? null : preferred ?? null;
|
|
30554
|
+
}
|
|
30476
30555
|
const current = read();
|
|
30477
30556
|
const rpc = current ? dependencies2.resolve(current, hostId2) : null;
|
|
30478
30557
|
const previous = routes.get(hostId2);
|
|
30479
|
-
if (rpc && previous?.rpc === rpc)
|
|
30558
|
+
if (rpc && previous?.rpc === rpc && sameConnection(previous.connection, connection))
|
|
30480
30559
|
return previous.route;
|
|
30481
30560
|
retire(hostId2);
|
|
30482
30561
|
if (!rpc)
|
|
30483
30562
|
return null;
|
|
30484
|
-
const route = createRoute(hostId2, rpc);
|
|
30485
|
-
routes.set(hostId2, { route, rpc });
|
|
30563
|
+
const route = createRoute(hostId2, rpc, connection);
|
|
30564
|
+
routes.set(hostId2, { route, rpc, connection });
|
|
30486
30565
|
return route;
|
|
30487
30566
|
};
|
|
30488
30567
|
const publish = (route) => {
|
|
@@ -30497,15 +30576,30 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
|
|
|
30497
30576
|
target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
|
|
30498
30577
|
}
|
|
30499
30578
|
};
|
|
30500
|
-
const composerHostId = (composer) => {
|
|
30501
|
-
const
|
|
30579
|
+
const composerHostId = (owners, composer) => {
|
|
30580
|
+
const nativeHostId = nativeRouting?.hostIdForComposer(composer);
|
|
30581
|
+
if (nativeHostId)
|
|
30582
|
+
return nativeHostId;
|
|
30583
|
+
const hostIds = new Set((owners ?? discoverComposer(composer)).hostIds);
|
|
30502
30584
|
const hostId2 = hostIds.size === 1 ? hostIds.values().next().value : null;
|
|
30503
30585
|
return typeof hostId2 === "string" && hostId2 ? hostId2 : null;
|
|
30504
30586
|
};
|
|
30505
30587
|
const routing = {
|
|
30506
30588
|
knownHostIds() {
|
|
30589
|
+
if (disposed)
|
|
30590
|
+
return [];
|
|
30591
|
+
try {
|
|
30592
|
+
if (!nativeRouting)
|
|
30593
|
+
discoverComposer();
|
|
30594
|
+
} catch {
|
|
30595
|
+
}
|
|
30507
30596
|
const current = read();
|
|
30508
|
-
return
|
|
30597
|
+
return [
|
|
30598
|
+
.../* @__PURE__ */ new Set([
|
|
30599
|
+
...current ? dependencies2.hostIds(current) : [],
|
|
30600
|
+
...nativeRouting?.knownHostIds?.() ?? []
|
|
30601
|
+
])
|
|
30602
|
+
];
|
|
30509
30603
|
},
|
|
30510
30604
|
forHost(hostId2) {
|
|
30511
30605
|
return hostId2 && !disposed ? routeFor(hostId2) : null;
|
|
@@ -30514,7 +30608,7 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
|
|
|
30514
30608
|
if (disposed)
|
|
30515
30609
|
return null;
|
|
30516
30610
|
try {
|
|
30517
|
-
return composerHostId(composer);
|
|
30611
|
+
return composerHostId(nativeRouting ? null : discoverComposer(composer), composer);
|
|
30518
30612
|
} catch {
|
|
30519
30613
|
return null;
|
|
30520
30614
|
}
|
|
@@ -30523,12 +30617,15 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
|
|
|
30523
30617
|
if (disposed)
|
|
30524
30618
|
return null;
|
|
30525
30619
|
let hostId2;
|
|
30620
|
+
let preferred = null;
|
|
30526
30621
|
try {
|
|
30527
|
-
|
|
30622
|
+
const owners = nativeRouting ? null : discoverComposer(composer);
|
|
30623
|
+
preferred = nativeRouting?.forComposer(composer) ?? null;
|
|
30624
|
+
hostId2 = preferred?.hostId ?? composerHostId(owners, composer);
|
|
30528
30625
|
} catch {
|
|
30529
30626
|
hostId2 = null;
|
|
30530
30627
|
}
|
|
30531
|
-
const route = hostId2 ? routeFor(hostId2) : null;
|
|
30628
|
+
const route = hostId2 ? routeFor(hostId2, preferred) : null;
|
|
30532
30629
|
if (!composer)
|
|
30533
30630
|
publish(route);
|
|
30534
30631
|
return route;
|
|
@@ -30537,6 +30634,8 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
|
|
|
30537
30634
|
if (disposed)
|
|
30538
30635
|
return;
|
|
30539
30636
|
disposed = true;
|
|
30637
|
+
nativeRouting?.dispose();
|
|
30638
|
+
nativeRouting = null;
|
|
30540
30639
|
for (const hostId2 of [...routes.keys()])
|
|
30541
30640
|
retire(hostId2);
|
|
30542
30641
|
discovery = null;
|
|
@@ -30555,6 +30654,34 @@ function installRendererHostRpcRouting(root, target, dependencies2) {
|
|
|
30555
30654
|
return routing;
|
|
30556
30655
|
}
|
|
30557
30656
|
|
|
30657
|
+
// packages/desktop-control/dist/renderer-connection-generation.js
|
|
30658
|
+
function readRendererConnectionGeneration(store, hostId2) {
|
|
30659
|
+
if (!store)
|
|
30660
|
+
return void 0;
|
|
30661
|
+
const record6 = (value2) => value2 !== null && typeof value2 === "object";
|
|
30662
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
30663
|
+
for (const members of store.familyBindings.values()) {
|
|
30664
|
+
const value2 = members.get(hostId2)?.value;
|
|
30665
|
+
if (record6(value2) && record6(value2.state$) && record6(value2.revision$) && record6(value2.appServerVersion$) && typeof value2.state$.get === "function" && typeof value2.revision$.get === "function")
|
|
30666
|
+
candidates.add(value2);
|
|
30667
|
+
}
|
|
30668
|
+
if (!candidates.size)
|
|
30669
|
+
return void 0;
|
|
30670
|
+
if (candidates.size !== 1)
|
|
30671
|
+
return null;
|
|
30672
|
+
const owner = candidates.values().next().value;
|
|
30673
|
+
if (!owner)
|
|
30674
|
+
return null;
|
|
30675
|
+
const state = owner.state$;
|
|
30676
|
+
const revision = owner.revision$;
|
|
30677
|
+
try {
|
|
30678
|
+
const current = revision.get();
|
|
30679
|
+
return state.get() === "connected" && typeof current === "number" && Number.isSafeInteger(current) ? { owner, revision: current } : null;
|
|
30680
|
+
} catch {
|
|
30681
|
+
return null;
|
|
30682
|
+
}
|
|
30683
|
+
}
|
|
30684
|
+
|
|
30558
30685
|
// packages/desktop-control/dist/renderer-draft-prewarm-policy.js
|
|
30559
30686
|
var REQUEST_MANAGER_WAIT_TIMEOUT_MS = 6e4;
|
|
30560
30687
|
var REQUEST_MANAGER_POLL_INTERVAL_MS = 25;
|
|
@@ -30567,22 +30694,26 @@ function directRendererInstaller() {
|
|
|
30567
30694
|
const retainRendererHostResponses = ${retainRendererHostResponses.toString()};
|
|
30568
30695
|
const createDraftPrewarmPolicyBridge = ${createDraftPrewarmPolicyBridge.toString()};
|
|
30569
30696
|
const isolateRendererPrewarmConsumption = ${isolateRendererPrewarmConsumption.toString()};
|
|
30697
|
+
const findRendererAppScopeStore = ${findRendererAppScopeStore.toString()};
|
|
30698
|
+
const readRendererConnectionGeneration = ${readRendererConnectionGeneration.toString()};
|
|
30570
30699
|
const discover = (root) =>
|
|
30571
30700
|
discoverRendererHosts(root, committedReactAncestors, requestManagerFromHookState);
|
|
30572
|
-
const installNative = () => (${installRendererHostRouting.toString()})(
|
|
30701
|
+
const installNative = (publishRouting = true) => (${installRendererHostRouting.toString()})(
|
|
30573
30702
|
document, window, discover,
|
|
30574
30703
|
(discovery, hostId) => resolveRendererHostManager(discovery, hostId, requestManagerFromHookState),
|
|
30575
30704
|
(manager, bridge, hostId, target, prewarmed, isCurrent) => createDraftPrewarmPolicyBridge(
|
|
30576
30705
|
manager, bridge, hostId, target, prewarmed, isCurrent, retainRendererHostResponses,
|
|
30577
30706
|
isolateRendererPrewarmConsumption,
|
|
30578
30707
|
),
|
|
30708
|
+
(hostId) => readRendererConnectionGeneration(findRendererAppScopeStore(document), hostId),
|
|
30709
|
+
publishRouting,
|
|
30579
30710
|
);
|
|
30580
30711
|
const installRpc = () => typeof MessagePort !== 'function' ? null : (${installRendererHostRpcRouting.toString()})(document, window, {
|
|
30581
30712
|
findStore: ${findRendererAppScopeStore.toString()},
|
|
30582
30713
|
findFamily: ${findRendererHostRpcFamily.toString()},
|
|
30583
30714
|
resolve: ${resolveRendererHostRpc.toString()},
|
|
30584
30715
|
hostIds: ${rendererHostRpcHostIds.toString()},
|
|
30585
|
-
|
|
30716
|
+
discoverComposer: (composer) => {
|
|
30586
30717
|
const source = composer?.matches?.('[data-codex-composer], [contenteditable="true"][role="textbox"]')
|
|
30587
30718
|
? { querySelectorAll: () => [composer] }
|
|
30588
30719
|
: (composer ?? document);
|
|
@@ -30594,20 +30725,18 @@ function directRendererInstaller() {
|
|
|
30594
30725
|
portPrototype: MessagePort.prototype,
|
|
30595
30726
|
}),
|
|
30596
30727
|
portPrototype: MessagePort.prototype,
|
|
30728
|
+
installNativeRouting: () => installNative(false),
|
|
30729
|
+
readConnection: (hostId) => readRendererConnectionGeneration(findRendererAppScopeStore(document), hostId),
|
|
30597
30730
|
});
|
|
30598
30731
|
const connected = (routing) => routing.forComposer() !== null ||
|
|
30599
30732
|
['local', ...(routing.knownHostIds?.() ?? [])].some((hostId) => routing.forHost(hostId) !== null);
|
|
30600
30733
|
let nativeReady = false;
|
|
30601
|
-
//
|
|
30602
|
-
//
|
|
30734
|
+
// Mixed layouts can expose native managers for only some Hosts. Keep one
|
|
30735
|
+
// router that selects a native owner or the current ready RPC peer per Host.
|
|
30603
30736
|
const routing = (() => {
|
|
30604
|
-
if (window.__codexhostHostRoutingV1)
|
|
30605
|
-
|
|
30606
|
-
|
|
30607
|
-
hostId => existing.forHost(hostId)?.manager.kind === 'main-process-rpc'
|
|
30608
|
-
)) installRpc();
|
|
30609
|
-
return existing;
|
|
30610
|
-
}
|
|
30737
|
+
if (window.__codexhostHostRoutingV1) return window.__codexhostHostRoutingV1;
|
|
30738
|
+
const rpc = installRpc();
|
|
30739
|
+
if (rpc) return rpc;
|
|
30611
30740
|
const native = discover(document);
|
|
30612
30741
|
if (native.managers.length || native.registries.length) {
|
|
30613
30742
|
const routing = installNative();
|
|
@@ -30617,8 +30746,6 @@ function directRendererInstaller() {
|
|
|
30617
30746
|
}
|
|
30618
30747
|
routing.dispose();
|
|
30619
30748
|
}
|
|
30620
|
-
const rpc = installRpc();
|
|
30621
|
-
if (rpc) return rpc;
|
|
30622
30749
|
throw new Error('Renderer Host request manager is unavailable');
|
|
30623
30750
|
})();
|
|
30624
30751
|
// Publish a default draft policy only when its Host is unambiguous. Host
|
|
@@ -30655,6 +30782,79 @@ var startupTraceStartedAt = Date.now();
|
|
|
30655
30782
|
// packages/desktop-control/dist/cpa-live-voice-hook.js
|
|
30656
30783
|
var CPA_LIVE_VOICE_HOOK_GLOBAL = "__codexhostCpaLiveVoiceHookV1";
|
|
30657
30784
|
|
|
30785
|
+
// packages/desktop-control/dist/browser-annotation-style-compat.js
|
|
30786
|
+
var BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE = String.raw`(() => {
|
|
30787
|
+
const key = '__codexhostBrowserAnnotationStylesV1';
|
|
30788
|
+
if (globalThis[key]?.refresh() === true) return;
|
|
30789
|
+
if (typeof CSSStyleSheet !== 'function' ||
|
|
30790
|
+
typeof CSSStyleSheet.prototype.replaceSync !== 'function') return;
|
|
30791
|
+
let root = null;
|
|
30792
|
+
let shadow = null;
|
|
30793
|
+
let stylesObserver = null;
|
|
30794
|
+
const copies = new Map();
|
|
30795
|
+
function removeCopies() {
|
|
30796
|
+
if (shadow) {
|
|
30797
|
+
const owned = new Set(Array.from(copies.values(), copy => copy.sheet));
|
|
30798
|
+
shadow.adoptedStyleSheets = shadow.adoptedStyleSheets.filter(sheet => !owned.has(sheet));
|
|
30799
|
+
}
|
|
30800
|
+
copies.clear();
|
|
30801
|
+
}
|
|
30802
|
+
function syncStyles() {
|
|
30803
|
+
if (!shadow) return;
|
|
30804
|
+
const present = new Set();
|
|
30805
|
+
for (const style of shadow.querySelectorAll('style')) {
|
|
30806
|
+
const text = style.textContent || '';
|
|
30807
|
+
// Only repair Codex's cursor stylesheet when CSP rejected its style element.
|
|
30808
|
+
if (style.sheet || !text.includes('.annotation-selection-cursor')) continue;
|
|
30809
|
+
present.add(style);
|
|
30810
|
+
const previous = copies.get(style);
|
|
30811
|
+
if (previous?.text === text && shadow.adoptedStyleSheets.includes(previous.sheet)) continue;
|
|
30812
|
+
try {
|
|
30813
|
+
const sheet = previous?.sheet ?? new CSSStyleSheet();
|
|
30814
|
+
sheet.replaceSync(text);
|
|
30815
|
+
if (!shadow.adoptedStyleSheets.includes(sheet)) {
|
|
30816
|
+
shadow.adoptedStyleSheets = [...shadow.adoptedStyleSheets, sheet];
|
|
30817
|
+
}
|
|
30818
|
+
copies.set(style, { sheet, text });
|
|
30819
|
+
} catch { /* Unsupported annotation styles leave native behavior intact. */ }
|
|
30820
|
+
}
|
|
30821
|
+
for (const [style, copy] of copies) {
|
|
30822
|
+
if (present.has(style)) continue;
|
|
30823
|
+
shadow.adoptedStyleSheets = shadow.adoptedStyleSheets.filter(sheet => sheet !== copy.sheet);
|
|
30824
|
+
copies.delete(style);
|
|
30825
|
+
}
|
|
30826
|
+
}
|
|
30827
|
+
function refresh() {
|
|
30828
|
+
const nextRoot = document.documentElement;
|
|
30829
|
+
if (root !== nextRoot) {
|
|
30830
|
+
rootObserver.disconnect();
|
|
30831
|
+
rootObserver.observe(document, { childList: true });
|
|
30832
|
+
root = nextRoot;
|
|
30833
|
+
if (root) rootObserver.observe(root, { childList: true });
|
|
30834
|
+
}
|
|
30835
|
+
const host = document.getElementById('codex-browser-sidebar-comments-root');
|
|
30836
|
+
const nextShadow = host?.parentElement === root ? host?.shadowRoot ?? null : null;
|
|
30837
|
+
if (nextShadow !== shadow) {
|
|
30838
|
+
stylesObserver?.disconnect();
|
|
30839
|
+
removeCopies();
|
|
30840
|
+
shadow = nextShadow;
|
|
30841
|
+
stylesObserver = null;
|
|
30842
|
+
if (shadow && 'adoptedStyleSheets' in shadow) {
|
|
30843
|
+
stylesObserver = new MutationObserver(syncStyles);
|
|
30844
|
+
stylesObserver.observe(shadow, { childList: true, subtree: true, characterData: true });
|
|
30845
|
+
} else {
|
|
30846
|
+
shadow = null;
|
|
30847
|
+
}
|
|
30848
|
+
}
|
|
30849
|
+
syncStyles();
|
|
30850
|
+
return true;
|
|
30851
|
+
}
|
|
30852
|
+
const rootObserver = new MutationObserver(refresh);
|
|
30853
|
+
rootObserver.observe(document, { childList: true });
|
|
30854
|
+
globalThis[key] = { refresh };
|
|
30855
|
+
refresh();
|
|
30856
|
+
})();`;
|
|
30857
|
+
|
|
30658
30858
|
// packages/desktop-control/dist/renderer-loaded-modules.js
|
|
30659
30859
|
var record3 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
30660
30860
|
var MAX_MODULES = 4096;
|
|
@@ -30790,6 +30990,873 @@ async function installRendererLoadedModules(renderer) {
|
|
|
30790
30990
|
}
|
|
30791
30991
|
}
|
|
30792
30992
|
|
|
30993
|
+
// packages/desktop-control/dist/renderer-native-rpc-discovery.js
|
|
30994
|
+
function nativeManagerDependencies(factoryName, callers) {
|
|
30995
|
+
const identifier = "[$A-Z_a-z][$\\w]*";
|
|
30996
|
+
const escaped = factoryName.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
30997
|
+
const pattern = new RegExp(`${escaped}\\((${identifier}),(${identifier}),\\1\\.get\\((${identifier}),\\2\\),(${identifier})\\.bind\\(null,\\1\\),\\((${identifier}),(${identifier})\\)=>\\5\\((${identifier}),\\6\\)\\)`);
|
|
30998
|
+
const matches = callers.flatMap((source) => {
|
|
30999
|
+
const match = pattern.exec(source);
|
|
31000
|
+
return match?.[3] && match[4] && match[7] ? [
|
|
31001
|
+
{
|
|
31002
|
+
requestDefinition: match[3],
|
|
31003
|
+
isHostForConversation: match[4],
|
|
31004
|
+
imageDefinition: match[7]
|
|
31005
|
+
}
|
|
31006
|
+
] : [];
|
|
31007
|
+
});
|
|
31008
|
+
return matches.length === 1 ? matches[0] : void 0;
|
|
31009
|
+
}
|
|
31010
|
+
function nativeRpcRole(source) {
|
|
31011
|
+
if (["dispatchMessageFromView", "threadProjectAssignments", "queuedMessageCoordination"].every((part) => source.includes(part)))
|
|
31012
|
+
return "createManager";
|
|
31013
|
+
if (["collectAppStateSnapshot", "getReviewPaneSnapshotMetrics", "registerReplayAdmission"].every((part) => source.includes(part)))
|
|
31014
|
+
return "createController";
|
|
31015
|
+
if (["getWorkInProgress", "getCachedThreadSearchSnapshot", "registerReplayAdmission"].every((part) => source.includes(part)))
|
|
31016
|
+
return "RpcManager";
|
|
31017
|
+
if (["prewarmedThreadManager", "onNotification", "dispatchAppServerResponse"].every((part) => source.includes(part)))
|
|
31018
|
+
return "Manager";
|
|
31019
|
+
return void 0;
|
|
31020
|
+
}
|
|
31021
|
+
function nativeRpcObjectShape(value2) {
|
|
31022
|
+
if (value2 === null || typeof value2 !== "object")
|
|
31023
|
+
return { scope: false, services: false, controller: false };
|
|
31024
|
+
const candidate = value2;
|
|
31025
|
+
const own = (keys) => keys.every((key) => Object.hasOwn(candidate, key));
|
|
31026
|
+
const methods = (keys) => keys.every((key) => typeof candidate[key] === "function");
|
|
31027
|
+
return {
|
|
31028
|
+
scope: own(["node", "scope", "get", "set", "watch"]) && methods(["get", "set", "watch"]),
|
|
31029
|
+
services: own(["appServerManagers", "remoteConnections", "applicationMenu"]) && typeof candidate.appServerManagers?.subscribe === "function",
|
|
31030
|
+
controller: own(["forHost", "collectAppStateSnapshot", "getReviewPaneSnapshotMetrics", "dispose"]) && methods(["forHost", "collectAppStateSnapshot", "getReviewPaneSnapshotMetrics", "dispose"])
|
|
31031
|
+
};
|
|
31032
|
+
}
|
|
31033
|
+
async function withNativeRpcComponents(client, install) {
|
|
31034
|
+
const group = `codexhost-native-rpc-${crypto.randomUUID()}`;
|
|
31035
|
+
const command = async (method, params) => client.command(method, params);
|
|
31036
|
+
const evaluate = (expression) => command("Runtime.evaluate", { expression, awaitPromise: true, objectGroup: group });
|
|
31037
|
+
const properties = (objectId) => command("Runtime.getProperties", { objectId, ownProperties: true });
|
|
31038
|
+
const call = (objectId, functionDeclaration, args = []) => command("Runtime.callFunctionOn", {
|
|
31039
|
+
objectId,
|
|
31040
|
+
functionDeclaration,
|
|
31041
|
+
arguments: args,
|
|
31042
|
+
objectGroup: group,
|
|
31043
|
+
returnByValue: true
|
|
31044
|
+
});
|
|
31045
|
+
try {
|
|
31046
|
+
const initial = await evaluate(String.raw`(() => {
|
|
31047
|
+
const catalog = globalThis.__codexhostLoadedModulesV1;
|
|
31048
|
+
if (!catalog?.complete || catalog.documentUrl !== location.href) return null;
|
|
31049
|
+
const urls = catalog.urls.filter(url => /^app:\/\/-\/assets\/(?:renderer-app-server-managers|app-shared)-[^/]+\.js$/.test(url));
|
|
31050
|
+
return { document, urls };
|
|
31051
|
+
})()`);
|
|
31052
|
+
if (!initial.result.objectId)
|
|
31053
|
+
return false;
|
|
31054
|
+
const holder = initial.result.objectId;
|
|
31055
|
+
const catalog = await call(holder, "function(){return this.urls}");
|
|
31056
|
+
const urls = catalog.result.value;
|
|
31057
|
+
if (!Array.isArray(urls) || urls.length !== 2)
|
|
31058
|
+
return false;
|
|
31059
|
+
const managerUrl = urls.find((url2) => url2.includes("renderer-app-server-managers"));
|
|
31060
|
+
const sharedUrl = urls.find((url2) => url2.includes("app-shared"));
|
|
31061
|
+
if (!managerUrl || !sharedUrl)
|
|
31062
|
+
return false;
|
|
31063
|
+
const attach = async (name, objectId) => {
|
|
31064
|
+
const result = await call(holder, "function(name,value){if(this.document!==document)throw Error('Renderer Realm changed');this[name]=value;return true}", [{ value: name }, { objectId }]);
|
|
31065
|
+
if (result.exceptionDetails)
|
|
31066
|
+
throw new Error("Native RPC discovery lost its Renderer Realm");
|
|
31067
|
+
};
|
|
31068
|
+
const imported = await evaluate(`import(${JSON.stringify(managerUrl)})`);
|
|
31069
|
+
if (!imported.result.objectId)
|
|
31070
|
+
return false;
|
|
31071
|
+
const exports = (await properties(imported.result.objectId)).result.filter((entry) => entry.value?.type === "function");
|
|
31072
|
+
let bindings = [];
|
|
31073
|
+
for (const entry of exports.slice(0, 3)) {
|
|
31074
|
+
if (!entry.value?.objectId)
|
|
31075
|
+
continue;
|
|
31076
|
+
const scopes = (await properties(entry.value.objectId)).internalProperties?.find((entry2) => entry2.name === "[[Scopes]]")?.value?.objectId;
|
|
31077
|
+
if (!scopes)
|
|
31078
|
+
continue;
|
|
31079
|
+
const modules = (await properties(scopes)).result.filter((entry2) => entry2.value?.description?.startsWith("Module") && entry2.value.objectId);
|
|
31080
|
+
const moduleId = modules[0]?.value?.objectId;
|
|
31081
|
+
if (modules.length !== 1 || !moduleId)
|
|
31082
|
+
continue;
|
|
31083
|
+
bindings = (await properties(moduleId)).result;
|
|
31084
|
+
break;
|
|
31085
|
+
}
|
|
31086
|
+
const functions = bindings.filter((entry) => entry.value?.type === "function");
|
|
31087
|
+
const roles = /* @__PURE__ */ new Map();
|
|
31088
|
+
for (const entry of functions) {
|
|
31089
|
+
const role = nativeRpcRole(entry.value?.description ?? "");
|
|
31090
|
+
if (role)
|
|
31091
|
+
roles.set(role, [...roles.get(role) ?? [], entry]);
|
|
31092
|
+
}
|
|
31093
|
+
if (["createManager", "Manager", "RpcManager", "createController"].some((role) => roles.get(role)?.length !== 1))
|
|
31094
|
+
return false;
|
|
31095
|
+
const factory = roles.get("createManager")?.[0];
|
|
31096
|
+
if (!factory)
|
|
31097
|
+
return false;
|
|
31098
|
+
const dependencies2 = nativeManagerDependencies(factory.name, functions.map((entry) => entry.value?.description ?? ""));
|
|
31099
|
+
if (!dependencies2)
|
|
31100
|
+
return false;
|
|
31101
|
+
for (const [role, entries] of roles) {
|
|
31102
|
+
const id2 = entries[0]?.value?.objectId;
|
|
31103
|
+
if (!id2)
|
|
31104
|
+
return false;
|
|
31105
|
+
await attach(role, id2);
|
|
31106
|
+
}
|
|
31107
|
+
for (const [role, name] of Object.entries(dependencies2)) {
|
|
31108
|
+
const value2 = bindings.find((entry) => entry.name === name)?.value?.objectId;
|
|
31109
|
+
if (!value2)
|
|
31110
|
+
return false;
|
|
31111
|
+
await attach(role, value2);
|
|
31112
|
+
}
|
|
31113
|
+
const shared = await evaluate(`import(${JSON.stringify(sharedUrl)})`);
|
|
31114
|
+
if (!shared.result.objectId)
|
|
31115
|
+
return false;
|
|
31116
|
+
const sharedExports = (await properties(shared.result.objectId)).result;
|
|
31117
|
+
const sessions = sharedExports.filter((entry) => entry.value?.type === "function" && ["getRemoteMain", "getStats", "drain", "getMainImport"].every((word) => entry.value?.description?.includes(word)));
|
|
31118
|
+
const sessionId = sessions[0]?.value?.objectId;
|
|
31119
|
+
if (sessions.length !== 1 || !sessionId)
|
|
31120
|
+
return false;
|
|
31121
|
+
await attach("RpcSession", sessionId);
|
|
31122
|
+
const serviceMatches = await command("Runtime.callFunctionOn", {
|
|
31123
|
+
objectId: shared.result.objectId,
|
|
31124
|
+
functionDeclaration: `function(){return [...new Set(Object.values(this).filter(value => (${nativeRpcObjectShape.toString()})(value).services))]}`,
|
|
31125
|
+
objectGroup: group
|
|
31126
|
+
});
|
|
31127
|
+
if (!serviceMatches.result.objectId)
|
|
31128
|
+
return false;
|
|
31129
|
+
const services = (await properties(serviceMatches.result.objectId)).result.flatMap((entry) => entry.value?.type === "object" && entry.value.objectId ? [entry.value.objectId] : []);
|
|
31130
|
+
const serviceId = services[0];
|
|
31131
|
+
if (services.length !== 1 || !serviceId)
|
|
31132
|
+
return false;
|
|
31133
|
+
await attach("services", serviceId);
|
|
31134
|
+
const prototype = await evaluate("Object.getPrototypeOf(async function(){})");
|
|
31135
|
+
if (!prototype.result.objectId)
|
|
31136
|
+
return false;
|
|
31137
|
+
const objects = await command("Runtime.queryObjects", {
|
|
31138
|
+
prototypeObjectId: prototype.result.objectId,
|
|
31139
|
+
objectGroup: group
|
|
31140
|
+
});
|
|
31141
|
+
if (!objects.objects.objectId)
|
|
31142
|
+
return false;
|
|
31143
|
+
const filtered = await command("Runtime.callFunctionOn", {
|
|
31144
|
+
objectId: objects.objects.objectId,
|
|
31145
|
+
functionDeclaration: 'function(){return this.filter(fn=>fn.name==="collectAppStateSnapshot"&&String(fn).includes("collectSnapshot")).slice(0,9)}',
|
|
31146
|
+
objectGroup: group
|
|
31147
|
+
});
|
|
31148
|
+
if (!filtered.result.objectId)
|
|
31149
|
+
return false;
|
|
31150
|
+
const snapshots = (await properties(filtered.result.objectId)).result.filter((entry) => entry.value?.type === "function");
|
|
31151
|
+
if (snapshots.length > 8)
|
|
31152
|
+
return false;
|
|
31153
|
+
const owners = [];
|
|
31154
|
+
for (const snapshot2 of snapshots) {
|
|
31155
|
+
const fn = snapshot2.value?.objectId;
|
|
31156
|
+
if (!fn)
|
|
31157
|
+
continue;
|
|
31158
|
+
const scopes = (await properties(fn)).internalProperties?.find((entry) => entry.name === "[[Scopes]]")?.value?.objectId;
|
|
31159
|
+
if (!scopes)
|
|
31160
|
+
continue;
|
|
31161
|
+
for (const scope of (await properties(scopes)).result) {
|
|
31162
|
+
if (!scope.value?.description?.startsWith("Closure") || !scope.value.objectId)
|
|
31163
|
+
continue;
|
|
31164
|
+
const candidates = (await properties(scope.value.objectId)).result;
|
|
31165
|
+
const controllers = [], handles = [];
|
|
31166
|
+
for (const binding of candidates) {
|
|
31167
|
+
if (binding.value?.type !== "object" || !binding.value.objectId)
|
|
31168
|
+
continue;
|
|
31169
|
+
const id2 = binding.value.objectId;
|
|
31170
|
+
const response = await call(id2, `function(){return (${nativeRpcObjectShape.toString()})(this)}`);
|
|
31171
|
+
const shape = response.result.value;
|
|
31172
|
+
if (shape?.scope)
|
|
31173
|
+
handles.push(id2);
|
|
31174
|
+
if (shape?.controller && (await call(id2, "function(fn){return this.collectAppStateSnapshot===fn}", [
|
|
31175
|
+
{ objectId: fn }
|
|
31176
|
+
])).result.value === true)
|
|
31177
|
+
controllers.push(id2);
|
|
31178
|
+
}
|
|
31179
|
+
const controller = controllers[0], handle = handles[0];
|
|
31180
|
+
if (controllers.length === 1 && handles.length === 1 && controller && handle)
|
|
31181
|
+
owners.push({ controller, scope: handle });
|
|
31182
|
+
}
|
|
31183
|
+
}
|
|
31184
|
+
const owner = owners[0];
|
|
31185
|
+
if (owners.length !== 1 || !owner)
|
|
31186
|
+
return false;
|
|
31187
|
+
await attach("controller", owner.controller);
|
|
31188
|
+
await attach("scope", owner.scope);
|
|
31189
|
+
return await install(holder);
|
|
31190
|
+
} finally {
|
|
31191
|
+
await client.command("Runtime.releaseObjectGroup", { objectGroup: group }).catch(() => void 0);
|
|
31192
|
+
}
|
|
31193
|
+
}
|
|
31194
|
+
|
|
31195
|
+
// packages/desktop-control/dist/renderer-native-rpc-runtime.js
|
|
31196
|
+
function installNativeRpcRemoteControl(components, target, dependencies2) {
|
|
31197
|
+
if (target.__codexhostNativeRpcRemoteControlV1)
|
|
31198
|
+
return true;
|
|
31199
|
+
const routing = target.__codexhostHostRoutingV1;
|
|
31200
|
+
if (!routing)
|
|
31201
|
+
return false;
|
|
31202
|
+
const adapted = dependencies2.createService(components, (hostId2, upstream) => dependencies2.createManager(components, hostId2, upstream, target, dependencies2.createPolicy, dependencies2.createChannel, dependencies2.retainInteractions));
|
|
31203
|
+
const controller = components.controller;
|
|
31204
|
+
const originalHost = routing.forHost, originalComposer = routing.forComposer, originalDispose = routing.dispose;
|
|
31205
|
+
controller.dispose();
|
|
31206
|
+
let replacement;
|
|
31207
|
+
try {
|
|
31208
|
+
replacement = components.createController(components.scope, adapted.service);
|
|
31209
|
+
} catch (error51) {
|
|
31210
|
+
replacement = components.createController(components.scope, components.services.appServerManagers);
|
|
31211
|
+
throw error51;
|
|
31212
|
+
} finally {
|
|
31213
|
+
adapted.service[Symbol.dispose]();
|
|
31214
|
+
controller.forHost = (hostId2) => replacement.forHost(hostId2);
|
|
31215
|
+
controller.collectAppStateSnapshot = (hostId2, options) => replacement.collectAppStateSnapshot(hostId2, options);
|
|
31216
|
+
controller.getReviewPaneSnapshotMetrics = (hostId2) => replacement.getReviewPaneSnapshotMetrics(hostId2);
|
|
31217
|
+
controller.dispose = () => replacement.dispose();
|
|
31218
|
+
}
|
|
31219
|
+
const forHost = (hostId2) => {
|
|
31220
|
+
const route = adapted.route(hostId2);
|
|
31221
|
+
return route === void 0 ? originalHost.call(routing, hostId2) : route;
|
|
31222
|
+
};
|
|
31223
|
+
const forComposer = (composer) => {
|
|
31224
|
+
const hostId2 = routing.hostIdForComposer(composer);
|
|
31225
|
+
return hostId2 ? forHost(hostId2) : originalComposer.call(routing, composer);
|
|
31226
|
+
};
|
|
31227
|
+
routing.forHost = forHost;
|
|
31228
|
+
routing.forComposer = forComposer;
|
|
31229
|
+
const installation2 = {
|
|
31230
|
+
dispose() {
|
|
31231
|
+
if (target.__codexhostNativeRpcRemoteControlV1 !== installation2)
|
|
31232
|
+
return;
|
|
31233
|
+
delete target.__codexhostNativeRpcRemoteControlV1;
|
|
31234
|
+
replacement.dispose();
|
|
31235
|
+
replacement = components.createController(components.scope, components.services.appServerManagers);
|
|
31236
|
+
if (routing.forHost === forHost)
|
|
31237
|
+
routing.forHost = originalHost;
|
|
31238
|
+
if (routing.forComposer === forComposer)
|
|
31239
|
+
routing.forComposer = originalComposer;
|
|
31240
|
+
routing.dispose = originalDispose;
|
|
31241
|
+
}
|
|
31242
|
+
};
|
|
31243
|
+
routing.dispose = () => {
|
|
31244
|
+
installation2.dispose();
|
|
31245
|
+
originalDispose.call(routing);
|
|
31246
|
+
};
|
|
31247
|
+
target.__codexhostNativeRpcRemoteControlV1 = installation2;
|
|
31248
|
+
return true;
|
|
31249
|
+
}
|
|
31250
|
+
|
|
31251
|
+
// packages/desktop-control/dist/renderer-native-remote-manager.js
|
|
31252
|
+
function createNativeRemoteManager(components, hostId2, original, target, createPolicy, createChannel, retainInteractions) {
|
|
31253
|
+
const source = components.scope.get(components.requestDefinition, hostId2);
|
|
31254
|
+
const upstream = original.dup();
|
|
31255
|
+
let manager;
|
|
31256
|
+
let policy;
|
|
31257
|
+
let interactions;
|
|
31258
|
+
let disposed = false;
|
|
31259
|
+
const pending = /* @__PURE__ */ new Set();
|
|
31260
|
+
const send = (method, params, options) => {
|
|
31261
|
+
const request = upstream.sendRequest(method, params, options);
|
|
31262
|
+
const result = Promise.resolve(request).finally(() => {
|
|
31263
|
+
request[Symbol.dispose]();
|
|
31264
|
+
pending.delete(result);
|
|
31265
|
+
});
|
|
31266
|
+
pending.add(result);
|
|
31267
|
+
return result;
|
|
31268
|
+
};
|
|
31269
|
+
const record6 = (value2) => value2 !== null && typeof value2 === "object";
|
|
31270
|
+
const dispatch = (type, payload) => {
|
|
31271
|
+
if ((type === "mcp-request" || type === "thread-prewarm-start") && record6(payload) && record6(payload.request)) {
|
|
31272
|
+
const request = payload.request;
|
|
31273
|
+
const options = {};
|
|
31274
|
+
for (const key of ["priority", "timeoutMs", "source", "trace", "threadAccess"])
|
|
31275
|
+
if (payload[key] !== void 0)
|
|
31276
|
+
options[key] = payload[key];
|
|
31277
|
+
void send(String(request.method), request.params, options).then((result) => {
|
|
31278
|
+
if (!disposed)
|
|
31279
|
+
client.onResult(request.id, result);
|
|
31280
|
+
}, (error51) => {
|
|
31281
|
+
if (!disposed)
|
|
31282
|
+
client.onError(request.id, {
|
|
31283
|
+
code: record6(error51) ? error51.jsonRpcCode ?? error51.code ?? -32603 : -32603,
|
|
31284
|
+
message: error51 instanceof Error ? error51.message : String(error51)
|
|
31285
|
+
});
|
|
31286
|
+
});
|
|
31287
|
+
return;
|
|
31288
|
+
}
|
|
31289
|
+
return source.dispatchMessage(type, payload);
|
|
31290
|
+
};
|
|
31291
|
+
const Constructor = source.constructor;
|
|
31292
|
+
let client;
|
|
31293
|
+
try {
|
|
31294
|
+
client = new Constructor(hostId2, dispatch, false, (id2) => manager?.getConversation(id2)?.threadAccess);
|
|
31295
|
+
client.setAppServerVersion(source.getAppServerVersion());
|
|
31296
|
+
manager = components.createManager(components.scope, hostId2, client, components.isHostForConversation.bind(null, components.scope), (get, id2) => get(components.imageDefinition, id2), { dispatchMessageFromView: dispatch });
|
|
31297
|
+
manager.dispatchAppServerResponse = manager.sendAppServerResponse;
|
|
31298
|
+
const owned = manager;
|
|
31299
|
+
const ownedPolicy = createPolicy(owned, client, hostId2, target, owned.prewarmedThreadManager, () => !disposed, void 0, void 0, (method, params) => send(method, params, { priority: "critical" }));
|
|
31300
|
+
policy = ownedPolicy;
|
|
31301
|
+
owned.sendAppServerResponse = (...args) => owned.dispatchAppServerResponse(...args);
|
|
31302
|
+
const channel = createChannel(components, owned);
|
|
31303
|
+
const nativeInteractions = retainInteractions(upstream, owned, hostId2);
|
|
31304
|
+
interactions = nativeInteractions;
|
|
31305
|
+
const notify = (event) => {
|
|
31306
|
+
const { data, source: source2, origin } = event;
|
|
31307
|
+
if (disposed || source2 != null && source2 !== target || !record6(data) || data.hostId !== hostId2)
|
|
31308
|
+
return;
|
|
31309
|
+
const ownOrigin = record6(target.location) ? target.location.origin : void 0;
|
|
31310
|
+
if (source2 === target && ownOrigin && ownOrigin !== "null" && origin !== ownOrigin)
|
|
31311
|
+
return;
|
|
31312
|
+
if (data.type === "mcp-notification" && typeof data.method === "string" && !data.method.startsWith("process/"))
|
|
31313
|
+
owned.onNotification(data.method, data.params);
|
|
31314
|
+
if (data.type === "mcp-request")
|
|
31315
|
+
owned.onRequest(record6(data.request) ? data.request : data);
|
|
31316
|
+
};
|
|
31317
|
+
target.addEventListener?.("message", notify);
|
|
31318
|
+
return {
|
|
31319
|
+
route: { hostId: hostId2, manager: owned, policy: ownedPolicy },
|
|
31320
|
+
rpc: channel.rpc,
|
|
31321
|
+
ready: nativeInteractions.ready,
|
|
31322
|
+
dispose() {
|
|
31323
|
+
if (disposed)
|
|
31324
|
+
return;
|
|
31325
|
+
disposed = true;
|
|
31326
|
+
target.removeEventListener?.("message", notify);
|
|
31327
|
+
nativeInteractions.dispose();
|
|
31328
|
+
ownedPolicy.dispose();
|
|
31329
|
+
client.queuedRequests.length = 0;
|
|
31330
|
+
for (const id2 of [...client.requestPromises.keys()])
|
|
31331
|
+
client.onError(id2, new Error("Remote Control connection retired"));
|
|
31332
|
+
channel.dispose();
|
|
31333
|
+
components.Manager.dispose(owned);
|
|
31334
|
+
void Promise.allSettled([...pending]).then(() => upstream[Symbol.dispose]());
|
|
31335
|
+
}
|
|
31336
|
+
};
|
|
31337
|
+
} catch (error51) {
|
|
31338
|
+
interactions?.dispose();
|
|
31339
|
+
policy?.dispose();
|
|
31340
|
+
if (manager)
|
|
31341
|
+
components.Manager.dispose(manager);
|
|
31342
|
+
upstream[Symbol.dispose]();
|
|
31343
|
+
throw error51;
|
|
31344
|
+
}
|
|
31345
|
+
}
|
|
31346
|
+
|
|
31347
|
+
// packages/desktop-control/dist/renderer-native-rpc-channel.js
|
|
31348
|
+
function createNativeRpcChannel(components, manager) {
|
|
31349
|
+
const channel = new MessageChannel();
|
|
31350
|
+
const transports = [];
|
|
31351
|
+
const transport = (port) => {
|
|
31352
|
+
const values = [];
|
|
31353
|
+
const readers = [];
|
|
31354
|
+
let closed = false;
|
|
31355
|
+
let failure3;
|
|
31356
|
+
port.addEventListener("message", (event) => {
|
|
31357
|
+
const value2 = JSON.stringify(event.data);
|
|
31358
|
+
const reader = readers.shift();
|
|
31359
|
+
if (reader)
|
|
31360
|
+
reader.resolve(value2);
|
|
31361
|
+
else
|
|
31362
|
+
values.push(value2);
|
|
31363
|
+
});
|
|
31364
|
+
port.start();
|
|
31365
|
+
const result = {
|
|
31366
|
+
send(message2) {
|
|
31367
|
+
if (closed)
|
|
31368
|
+
throw failure3;
|
|
31369
|
+
port.postMessage(JSON.parse(message2));
|
|
31370
|
+
},
|
|
31371
|
+
receive() {
|
|
31372
|
+
if (closed)
|
|
31373
|
+
return Promise.reject(failure3);
|
|
31374
|
+
const value2 = values.shift();
|
|
31375
|
+
return value2 !== void 0 ? Promise.resolve(value2) : new Promise((resolve, reject) => readers.push({ resolve, reject }));
|
|
31376
|
+
},
|
|
31377
|
+
abort(error51) {
|
|
31378
|
+
if (closed)
|
|
31379
|
+
return;
|
|
31380
|
+
closed = true;
|
|
31381
|
+
failure3 = error51 ?? new Error("Remote Control RPC manager retired");
|
|
31382
|
+
values.length = 0;
|
|
31383
|
+
for (const reader of readers.splice(0))
|
|
31384
|
+
reader.reject(failure3);
|
|
31385
|
+
port.close();
|
|
31386
|
+
}
|
|
31387
|
+
};
|
|
31388
|
+
transports.push(result);
|
|
31389
|
+
return result;
|
|
31390
|
+
};
|
|
31391
|
+
try {
|
|
31392
|
+
new components.RpcSession(transport(channel.port1), new components.RpcManager(() => manager));
|
|
31393
|
+
const session = new components.RpcSession(transport(channel.port2));
|
|
31394
|
+
const rpc = session.getRemoteMain();
|
|
31395
|
+
return {
|
|
31396
|
+
rpc,
|
|
31397
|
+
dispose() {
|
|
31398
|
+
rpc[Symbol.dispose]();
|
|
31399
|
+
for (const transport2 of transports)
|
|
31400
|
+
transport2.abort();
|
|
31401
|
+
}
|
|
31402
|
+
};
|
|
31403
|
+
} catch (error51) {
|
|
31404
|
+
for (const transport2 of transports)
|
|
31405
|
+
transport2.abort(error51);
|
|
31406
|
+
channel.port1.close();
|
|
31407
|
+
channel.port2.close();
|
|
31408
|
+
throw error51;
|
|
31409
|
+
}
|
|
31410
|
+
}
|
|
31411
|
+
|
|
31412
|
+
// packages/desktop-control/dist/renderer-native-rpc-service.js
|
|
31413
|
+
function createNativeRpcService(components, createRemote) {
|
|
31414
|
+
const source = components.services.appServerManagers.dup();
|
|
31415
|
+
const routes = /* @__PURE__ */ new Map();
|
|
31416
|
+
const subscriptions = /* @__PURE__ */ new Set();
|
|
31417
|
+
let refs = 1;
|
|
31418
|
+
const record6 = (value2) => value2 !== null && typeof value2 === "object";
|
|
31419
|
+
const connectionSignals = (hostId2) => {
|
|
31420
|
+
let node = components.scope.node;
|
|
31421
|
+
const seen = /* @__PURE__ */ new Set();
|
|
31422
|
+
while (node.parent && !seen.has(node.parent) && seen.size < 100) {
|
|
31423
|
+
seen.add(node);
|
|
31424
|
+
node = node.parent;
|
|
31425
|
+
}
|
|
31426
|
+
const found = [];
|
|
31427
|
+
for (const members of node.familyBindings.values()) {
|
|
31428
|
+
const value2 = members.get(hostId2)?.value;
|
|
31429
|
+
if (record6(value2) && Object.hasOwn(value2, "state$") && Object.hasOwn(value2, "revision$") && Object.hasOwn(value2, "appServerVersion$"))
|
|
31430
|
+
found.push({ state$: value2.state$, revision$: value2.revision$ });
|
|
31431
|
+
}
|
|
31432
|
+
return found.length === 1 ? found[0] : void 0;
|
|
31433
|
+
};
|
|
31434
|
+
const service = {
|
|
31435
|
+
dup() {
|
|
31436
|
+
refs++;
|
|
31437
|
+
return service;
|
|
31438
|
+
},
|
|
31439
|
+
onRpcBroken(listener) {
|
|
31440
|
+
source.onRpcBroken(listener);
|
|
31441
|
+
},
|
|
31442
|
+
openAccount(hostId2) {
|
|
31443
|
+
return source.openAccount(hostId2);
|
|
31444
|
+
},
|
|
31445
|
+
subscribe(hostId2, listener) {
|
|
31446
|
+
if (!hostId2.startsWith("remote-control:"))
|
|
31447
|
+
return source.subscribe(hostId2, listener);
|
|
31448
|
+
let active = true;
|
|
31449
|
+
let generation = 0;
|
|
31450
|
+
let upstream;
|
|
31451
|
+
let platformRequest;
|
|
31452
|
+
let remote;
|
|
31453
|
+
let stopWatch;
|
|
31454
|
+
let previousRevision;
|
|
31455
|
+
let previousState;
|
|
31456
|
+
const retire = () => {
|
|
31457
|
+
generation++;
|
|
31458
|
+
platformRequest?.[Symbol.dispose]();
|
|
31459
|
+
platformRequest = void 0;
|
|
31460
|
+
remote?.dispose();
|
|
31461
|
+
remote = void 0;
|
|
31462
|
+
routes.set(hostId2, null);
|
|
31463
|
+
};
|
|
31464
|
+
const cleanup = () => {
|
|
31465
|
+
if (!active)
|
|
31466
|
+
return;
|
|
31467
|
+
active = false;
|
|
31468
|
+
stopWatch?.();
|
|
31469
|
+
retire();
|
|
31470
|
+
upstream?.[Symbol.dispose]();
|
|
31471
|
+
upstream = void 0;
|
|
31472
|
+
routes.delete(hostId2);
|
|
31473
|
+
subscriptions.delete(cleanup);
|
|
31474
|
+
};
|
|
31475
|
+
subscriptions.add(cleanup);
|
|
31476
|
+
const publish = async () => {
|
|
31477
|
+
const owner = upstream;
|
|
31478
|
+
const current = generation;
|
|
31479
|
+
if (!owner || !active)
|
|
31480
|
+
return;
|
|
31481
|
+
let request;
|
|
31482
|
+
try {
|
|
31483
|
+
request = owner.getCodexHome();
|
|
31484
|
+
platformRequest = request;
|
|
31485
|
+
const home = await request;
|
|
31486
|
+
if (!active || current !== generation || owner !== upstream)
|
|
31487
|
+
return;
|
|
31488
|
+
if (!/^(?:[A-Za-z]:[\\/]|\\\\)/u.test(home)) {
|
|
31489
|
+
routes.delete(hostId2);
|
|
31490
|
+
listener({ status: "ready", manager: owner });
|
|
31491
|
+
return;
|
|
31492
|
+
}
|
|
31493
|
+
const created = createRemote(hostId2, owner);
|
|
31494
|
+
remote = created;
|
|
31495
|
+
await created.ready;
|
|
31496
|
+
if (!active || current !== generation || owner !== upstream)
|
|
31497
|
+
return;
|
|
31498
|
+
routes.set(hostId2, created.route);
|
|
31499
|
+
listener({ status: "ready", manager: created.rpc });
|
|
31500
|
+
} catch {
|
|
31501
|
+
if (active && current === generation) {
|
|
31502
|
+
remote?.dispose();
|
|
31503
|
+
remote = void 0;
|
|
31504
|
+
routes.delete(hostId2);
|
|
31505
|
+
listener({ status: "ready", manager: owner });
|
|
31506
|
+
}
|
|
31507
|
+
} finally {
|
|
31508
|
+
if (platformRequest === request) {
|
|
31509
|
+
platformRequest = void 0;
|
|
31510
|
+
request?.[Symbol.dispose]();
|
|
31511
|
+
}
|
|
31512
|
+
}
|
|
31513
|
+
};
|
|
31514
|
+
const changed = (state) => {
|
|
31515
|
+
if (!active)
|
|
31516
|
+
return;
|
|
31517
|
+
stopWatch?.();
|
|
31518
|
+
stopWatch = void 0;
|
|
31519
|
+
retire();
|
|
31520
|
+
upstream?.[Symbol.dispose]();
|
|
31521
|
+
upstream = void 0;
|
|
31522
|
+
if (state.status !== "ready") {
|
|
31523
|
+
listener(state);
|
|
31524
|
+
return;
|
|
31525
|
+
}
|
|
31526
|
+
upstream = state.manager.dup();
|
|
31527
|
+
listener({ status: "connecting" });
|
|
31528
|
+
const signals = connectionSignals(hostId2);
|
|
31529
|
+
if (!signals) {
|
|
31530
|
+
void publish();
|
|
31531
|
+
return;
|
|
31532
|
+
}
|
|
31533
|
+
previousState = void 0;
|
|
31534
|
+
previousRevision = void 0;
|
|
31535
|
+
stopWatch = components.scope.watch(({ get }) => {
|
|
31536
|
+
const connection = get(signals.state$), revision = get(signals.revision$);
|
|
31537
|
+
if (connection === previousState && revision === previousRevision)
|
|
31538
|
+
return;
|
|
31539
|
+
previousState = connection;
|
|
31540
|
+
previousRevision = revision;
|
|
31541
|
+
retire();
|
|
31542
|
+
listener({ status: connection === "connected" ? "connecting" : "disconnected" });
|
|
31543
|
+
if (connection === "connected")
|
|
31544
|
+
void publish();
|
|
31545
|
+
});
|
|
31546
|
+
};
|
|
31547
|
+
const original = source.subscribe(hostId2, changed);
|
|
31548
|
+
const result = original.then((lease) => {
|
|
31549
|
+
if (!active)
|
|
31550
|
+
lease[Symbol.dispose]();
|
|
31551
|
+
return {
|
|
31552
|
+
onRpcBroken: (listener2) => lease.onRpcBroken(listener2),
|
|
31553
|
+
[Symbol.dispose]() {
|
|
31554
|
+
cleanup();
|
|
31555
|
+
lease[Symbol.dispose]();
|
|
31556
|
+
}
|
|
31557
|
+
};
|
|
31558
|
+
});
|
|
31559
|
+
Object.assign(result, {
|
|
31560
|
+
onRpcBroken: (listener2) => original.onRpcBroken(listener2),
|
|
31561
|
+
[Symbol.dispose]() {
|
|
31562
|
+
cleanup();
|
|
31563
|
+
original[Symbol.dispose]();
|
|
31564
|
+
}
|
|
31565
|
+
});
|
|
31566
|
+
return result;
|
|
31567
|
+
},
|
|
31568
|
+
[Symbol.dispose]() {
|
|
31569
|
+
if (--refs !== 0)
|
|
31570
|
+
return;
|
|
31571
|
+
for (const cleanup of [...subscriptions])
|
|
31572
|
+
cleanup();
|
|
31573
|
+
source[Symbol.dispose]();
|
|
31574
|
+
}
|
|
31575
|
+
};
|
|
31576
|
+
return { service, route: (hostId2) => routes.get(hostId2) };
|
|
31577
|
+
}
|
|
31578
|
+
|
|
31579
|
+
// packages/desktop-control/dist/renderer-native-rpc-interactions.js
|
|
31580
|
+
function retainNativeRpcInteractions(upstream, manager, hostId2) {
|
|
31581
|
+
let disposed = false;
|
|
31582
|
+
const retained = /* @__PURE__ */ new Set();
|
|
31583
|
+
const requests = /* @__PURE__ */ new Map();
|
|
31584
|
+
const reads = /* @__PURE__ */ new Map();
|
|
31585
|
+
const record6 = (value2) => value2 !== null && typeof value2 === "object";
|
|
31586
|
+
const read = (threadId2) => {
|
|
31587
|
+
const existing = reads.get(threadId2);
|
|
31588
|
+
if (existing) {
|
|
31589
|
+
existing.dirty = true;
|
|
31590
|
+
return existing.promise;
|
|
31591
|
+
}
|
|
31592
|
+
const entry = { promise: Promise.resolve(), dirty: false };
|
|
31593
|
+
reads.set(threadId2, entry);
|
|
31594
|
+
entry.promise = Promise.resolve().then(async () => {
|
|
31595
|
+
do {
|
|
31596
|
+
if (disposed)
|
|
31597
|
+
break;
|
|
31598
|
+
entry.dirty = false;
|
|
31599
|
+
const pending = upstream.getConversation(threadId2);
|
|
31600
|
+
retained.add(pending);
|
|
31601
|
+
try {
|
|
31602
|
+
const conversation = await pending;
|
|
31603
|
+
if (disposed || entry.dirty || !record6(conversation) || !Array.isArray(conversation.requests))
|
|
31604
|
+
continue;
|
|
31605
|
+
const previous = requests.get(threadId2) ?? /* @__PURE__ */ new Set();
|
|
31606
|
+
const next = /* @__PURE__ */ new Set();
|
|
31607
|
+
for (const request of conversation.requests) {
|
|
31608
|
+
if (!record6(request) || typeof request.method !== "string" || !record6(request.params) || (request.params.threadId ?? request.params.conversationId) !== threadId2 || typeof request.id !== "string" && typeof request.id !== "number")
|
|
31609
|
+
continue;
|
|
31610
|
+
next.add(request.id);
|
|
31611
|
+
if (!previous.has(request.id))
|
|
31612
|
+
manager.onRequest(request);
|
|
31613
|
+
}
|
|
31614
|
+
if (next.size)
|
|
31615
|
+
requests.set(threadId2, next);
|
|
31616
|
+
else
|
|
31617
|
+
requests.delete(threadId2);
|
|
31618
|
+
} finally {
|
|
31619
|
+
if (retained.delete(pending))
|
|
31620
|
+
pending[Symbol.dispose]();
|
|
31621
|
+
}
|
|
31622
|
+
} while (!disposed && entry.dirty);
|
|
31623
|
+
}).finally(() => {
|
|
31624
|
+
reads.delete(threadId2);
|
|
31625
|
+
});
|
|
31626
|
+
return entry.promise;
|
|
31627
|
+
};
|
|
31628
|
+
const event = (value2) => {
|
|
31629
|
+
if (disposed || !record6(value2) || typeof value2.conversationId !== "string")
|
|
31630
|
+
return;
|
|
31631
|
+
void read(value2.conversationId).catch(() => void 0);
|
|
31632
|
+
};
|
|
31633
|
+
const subscribe = (input) => {
|
|
31634
|
+
const pending = upstream.subscribe(input);
|
|
31635
|
+
retained.add(pending);
|
|
31636
|
+
return Promise.resolve(pending).then((lease) => {
|
|
31637
|
+
if (disposed)
|
|
31638
|
+
lease[Symbol.dispose]();
|
|
31639
|
+
else
|
|
31640
|
+
retained.add(lease);
|
|
31641
|
+
});
|
|
31642
|
+
};
|
|
31643
|
+
const subscriptions = [
|
|
31644
|
+
"approval-request",
|
|
31645
|
+
"user-input-request",
|
|
31646
|
+
"mcp-elicitation-request",
|
|
31647
|
+
"approval-resolved"
|
|
31648
|
+
].map((name) => subscribe({ type: "event", key: { hostId: hostId2 }, event: name, listener: event }));
|
|
31649
|
+
subscriptions.push(subscribe({
|
|
31650
|
+
type: "notification",
|
|
31651
|
+
key: { hostId: hostId2 },
|
|
31652
|
+
methods: ["serverRequest/resolved"],
|
|
31653
|
+
listener(value2) {
|
|
31654
|
+
if (record6(value2) && record6(value2.params) && typeof value2.params.threadId === "string")
|
|
31655
|
+
event({ conversationId: value2.params.threadId });
|
|
31656
|
+
}
|
|
31657
|
+
}));
|
|
31658
|
+
const ready = Promise.all(subscriptions).then(async () => {
|
|
31659
|
+
if (disposed)
|
|
31660
|
+
return;
|
|
31661
|
+
const pending = upstream.getWorkInProgress();
|
|
31662
|
+
retained.add(pending);
|
|
31663
|
+
try {
|
|
31664
|
+
const work = await pending;
|
|
31665
|
+
if (disposed)
|
|
31666
|
+
return;
|
|
31667
|
+
if (!Array.isArray(work))
|
|
31668
|
+
throw new Error("Native RPC interaction snapshot is unavailable");
|
|
31669
|
+
const threadIds = new Set(work.flatMap((item) => record6(item) && typeof item.conversationId === "string" ? [item.conversationId] : []));
|
|
31670
|
+
await Promise.all([...threadIds].map(read));
|
|
31671
|
+
} finally {
|
|
31672
|
+
if (retained.delete(pending))
|
|
31673
|
+
pending[Symbol.dispose]();
|
|
31674
|
+
}
|
|
31675
|
+
});
|
|
31676
|
+
return {
|
|
31677
|
+
ready,
|
|
31678
|
+
dispose() {
|
|
31679
|
+
if (disposed)
|
|
31680
|
+
return;
|
|
31681
|
+
disposed = true;
|
|
31682
|
+
for (const lease of retained)
|
|
31683
|
+
lease[Symbol.dispose]();
|
|
31684
|
+
retained.clear();
|
|
31685
|
+
requests.clear();
|
|
31686
|
+
}
|
|
31687
|
+
};
|
|
31688
|
+
}
|
|
31689
|
+
|
|
31690
|
+
// packages/desktop-control/dist/renderer-native-rpc-install.js
|
|
31691
|
+
async function installNativeRpcRemoteControlDirect(renderer) {
|
|
31692
|
+
let attempt;
|
|
31693
|
+
const probeId = crypto.randomUUID();
|
|
31694
|
+
try {
|
|
31695
|
+
attempt = await renderer.evaluate(`(() => {
|
|
31696
|
+
if (window.__codexhostNativeRpcRemoteControlV1) return null;
|
|
31697
|
+
const routing = window.__codexhostHostRoutingV1;
|
|
31698
|
+
const owner = routing?.forHost('local')?.manager;
|
|
31699
|
+
if (owner?.kind !== 'main-process-rpc') return null;
|
|
31700
|
+
const catalog = window.__codexhostLoadedModulesV1;
|
|
31701
|
+
if (!catalog?.complete) return null;
|
|
31702
|
+
const key = JSON.stringify([catalog.owner, catalog.urls.filter(url => /renderer-app-server-managers|app-shared/.test(url)).sort()]);
|
|
31703
|
+
const previous = window.__codexhostNativeRpcDiscoveryV1;
|
|
31704
|
+
const sameOwner = previous?.key === key && previous.owner === owner;
|
|
31705
|
+
if (sameOwner && (previous.state !== 'unavailable' || previous.attempts >= 3 || Date.now() < previous.nextRetryAt)) return null;
|
|
31706
|
+
const token = ${JSON.stringify(probeId)};
|
|
31707
|
+
window.__codexhostNativeRpcDiscoveryV1 = {
|
|
31708
|
+
key, owner, token, state: 'discovering', attempts: sameOwner ? previous.attempts + 1 : 1,
|
|
31709
|
+
};
|
|
31710
|
+
return token;
|
|
31711
|
+
})()`);
|
|
31712
|
+
} catch {
|
|
31713
|
+
return false;
|
|
31714
|
+
}
|
|
31715
|
+
if (attempt === null)
|
|
31716
|
+
return false;
|
|
31717
|
+
let installed = false;
|
|
31718
|
+
try {
|
|
31719
|
+
installed = await withNativeRpcComponents(renderer, async (objectId) => {
|
|
31720
|
+
const result = await renderer.command("Runtime.callFunctionOn", {
|
|
31721
|
+
objectId,
|
|
31722
|
+
functionDeclaration: `function() {
|
|
31723
|
+
if (this.document !== document) return false;
|
|
31724
|
+
const retainRendererHostResponses = ${retainRendererHostResponses.toString()};
|
|
31725
|
+
const isolateRendererPrewarmConsumption = ${isolateRendererPrewarmConsumption.toString()};
|
|
31726
|
+
return (${installNativeRpcRemoteControl.toString()})(this, window, {
|
|
31727
|
+
createPolicy: ${createDraftPrewarmPolicyBridge.toString()},
|
|
31728
|
+
createManager: ${createNativeRemoteManager.toString()},
|
|
31729
|
+
createChannel: ${createNativeRpcChannel.toString()},
|
|
31730
|
+
createService: ${createNativeRpcService.toString()},
|
|
31731
|
+
retainInteractions: ${retainNativeRpcInteractions.toString()},
|
|
31732
|
+
});
|
|
31733
|
+
}`,
|
|
31734
|
+
returnByValue: true
|
|
31735
|
+
});
|
|
31736
|
+
return !result.exceptionDetails && result.result?.value === true;
|
|
31737
|
+
});
|
|
31738
|
+
return installed;
|
|
31739
|
+
} catch {
|
|
31740
|
+
return false;
|
|
31741
|
+
} finally {
|
|
31742
|
+
await renderer.evaluate(`(() => {
|
|
31743
|
+
const status = window.__codexhostNativeRpcDiscoveryV1;
|
|
31744
|
+
if (status?.token === ${JSON.stringify(attempt)}) {
|
|
31745
|
+
status.state = ${JSON.stringify(installed ? "ready" : "unavailable")};
|
|
31746
|
+
status.nextRetryAt = Date.now() + 5000 * 2 ** (status.attempts - 1);
|
|
31747
|
+
}
|
|
31748
|
+
})()`).catch(() => void 0);
|
|
31749
|
+
}
|
|
31750
|
+
}
|
|
31751
|
+
|
|
31752
|
+
// packages/desktop-control/dist/renderer-rpc-steering.js
|
|
31753
|
+
var RETRY_BASE_MS = 5e3;
|
|
31754
|
+
var RETRY_MAX_MS = 3e5;
|
|
31755
|
+
var retries = /* @__PURE__ */ new WeakMap();
|
|
31756
|
+
async function installRendererRpcSteeringDirect(client, now = Date.now) {
|
|
31757
|
+
try {
|
|
31758
|
+
const needed = await client.evaluate(`(() => {
|
|
31759
|
+
const steering = window.__codexhostRpcSteeringV1;
|
|
31760
|
+
if (steering && steering.controller.forHost === steering.forHost) return false;
|
|
31761
|
+
steering?.release();
|
|
31762
|
+
const routing=window.__codexhostHostRoutingV1;
|
|
31763
|
+
return ['local', ...(routing?.knownHostIds?.() ?? [])].some(id => routing?.forHost(id)?.manager.kind === 'main-process-rpc');
|
|
31764
|
+
})()`);
|
|
31765
|
+
if (!needed)
|
|
31766
|
+
return false;
|
|
31767
|
+
const retry = retries.get(client);
|
|
31768
|
+
if (retry && now() < retry.nextAt)
|
|
31769
|
+
return false;
|
|
31770
|
+
try {
|
|
31771
|
+
await discoverAndInstall(client);
|
|
31772
|
+
retries.delete(client);
|
|
31773
|
+
return true;
|
|
31774
|
+
} catch (error51) {
|
|
31775
|
+
const attempts = (retry?.attempts ?? 0) + 1;
|
|
31776
|
+
const delay8 = Math.min(RETRY_BASE_MS * 2 ** (attempts - 1), RETRY_MAX_MS);
|
|
31777
|
+
retries.set(client, { attempts, nextAt: now() + delay8 });
|
|
31778
|
+
console.error(`codexhost native steering discovery failed (attempt ${attempts}):`, error51 instanceof Error ? error51.message : String(error51));
|
|
31779
|
+
return false;
|
|
31780
|
+
}
|
|
31781
|
+
} catch {
|
|
31782
|
+
return false;
|
|
31783
|
+
}
|
|
31784
|
+
}
|
|
31785
|
+
async function discoverAndInstall(client) {
|
|
31786
|
+
const group = `codexhost-rpc-steering-${crypto.randomUUID()}`;
|
|
31787
|
+
const command = (method, params) => client.command(method, params);
|
|
31788
|
+
const properties = (objectId) => command("Runtime.getProperties", { objectId, ownProperties: true });
|
|
31789
|
+
const call = (objectId, functionDeclaration, args = []) => command("Runtime.callFunctionOn", {
|
|
31790
|
+
objectId,
|
|
31791
|
+
functionDeclaration,
|
|
31792
|
+
arguments: args,
|
|
31793
|
+
objectGroup: group,
|
|
31794
|
+
returnByValue: true
|
|
31795
|
+
});
|
|
31796
|
+
try {
|
|
31797
|
+
const proto = await command("Runtime.evaluate", {
|
|
31798
|
+
expression: "Object.getPrototypeOf(async function(){})",
|
|
31799
|
+
objectGroup: group
|
|
31800
|
+
});
|
|
31801
|
+
if (!proto.result.objectId)
|
|
31802
|
+
throw new Error("Native RPC steering discovery is unavailable");
|
|
31803
|
+
const objects = await command("Runtime.queryObjects", {
|
|
31804
|
+
prototypeObjectId: proto.result.objectId,
|
|
31805
|
+
objectGroup: group
|
|
31806
|
+
});
|
|
31807
|
+
if (!objects.objects.objectId)
|
|
31808
|
+
throw new Error("Native RPC steering discovery is unavailable");
|
|
31809
|
+
const filtered = await command("Runtime.callFunctionOn", {
|
|
31810
|
+
objectId: objects.objects.objectId,
|
|
31811
|
+
functionDeclaration: 'function(){return this.filter(fn=>fn.name==="collectAppStateSnapshot"&&String(fn).includes("collectSnapshot")).slice(0,9)}',
|
|
31812
|
+
objectGroup: group
|
|
31813
|
+
});
|
|
31814
|
+
if (!filtered.result.objectId)
|
|
31815
|
+
throw new Error("Native RPC Controller is unavailable");
|
|
31816
|
+
const snapshots = (await properties(filtered.result.objectId)).result.flatMap((entry) => entry.value?.type === "function" && entry.value.objectId ? [entry.value.objectId] : []);
|
|
31817
|
+
if (snapshots.length > 8)
|
|
31818
|
+
throw new Error("Native RPC Controller is ambiguous");
|
|
31819
|
+
const controllers = [];
|
|
31820
|
+
for (const snapshot2 of snapshots) {
|
|
31821
|
+
const scopes = (await properties(snapshot2)).internalProperties?.find((entry) => entry.name === "[[Scopes]]")?.value?.objectId;
|
|
31822
|
+
if (!scopes)
|
|
31823
|
+
continue;
|
|
31824
|
+
for (const scope of (await properties(scopes)).result) {
|
|
31825
|
+
if (!scope.value?.objectId || !scope.value.description?.startsWith("Closure"))
|
|
31826
|
+
continue;
|
|
31827
|
+
const bindings = (await properties(scope.value.objectId)).result;
|
|
31828
|
+
const owners = [];
|
|
31829
|
+
let rootScope;
|
|
31830
|
+
for (const binding of bindings) {
|
|
31831
|
+
if (binding.value?.type !== "object" || !binding.value.objectId)
|
|
31832
|
+
continue;
|
|
31833
|
+
const id2 = binding.value.objectId;
|
|
31834
|
+
const result2 = await call(id2, `function(){return (${nativeRpcObjectShape.toString()})(this)}`);
|
|
31835
|
+
const shape = result2.result.value;
|
|
31836
|
+
if (shape?.scope)
|
|
31837
|
+
rootScope = id2;
|
|
31838
|
+
if (shape?.controller && (await call(id2, "function(fn){return this.collectAppStateSnapshot===fn}", [
|
|
31839
|
+
{ objectId: snapshot2 }
|
|
31840
|
+
])).result.value === true)
|
|
31841
|
+
owners.push(id2);
|
|
31842
|
+
}
|
|
31843
|
+
if (owners.length !== 1 || !rootScope)
|
|
31844
|
+
continue;
|
|
31845
|
+
const root = await call(rootScope, `function(){let node=this.node;const seen=new Set();while(node?.parent&&!seen.has(node.parent)&&seen.size<100){seen.add(node);node=node.parent}return (${findRendererAppScopeStore.toString()})(document)===node}`);
|
|
31846
|
+
if (root.result.value === true)
|
|
31847
|
+
controllers.push(owners[0]);
|
|
31848
|
+
}
|
|
31849
|
+
}
|
|
31850
|
+
if (controllers.length !== 1)
|
|
31851
|
+
throw new Error("Native RPC Controller is missing or ambiguous");
|
|
31852
|
+
const result = await call(controllers[0], "function(){return window.__codexhostInstallRpcSteeringV1?.(this) === true}");
|
|
31853
|
+
if (result.exceptionDetails || result.result.value !== true)
|
|
31854
|
+
throw new Error("Native RPC steering installation failed");
|
|
31855
|
+
} finally {
|
|
31856
|
+
await client.command("Runtime.releaseObjectGroup", { objectGroup: group }).catch(() => void 0);
|
|
31857
|
+
}
|
|
31858
|
+
}
|
|
31859
|
+
|
|
30793
31860
|
// packages/desktop-control/dist/renderer-cdp-control-session.js
|
|
30794
31861
|
function isRecord9(value2) {
|
|
30795
31862
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
@@ -30988,6 +32055,40 @@ function isLocalThreadRenderer(target) {
|
|
|
30988
32055
|
const route = url2.searchParams.get("initialRoute");
|
|
30989
32056
|
return [...url2.searchParams.keys()].length === 1 && (route === "/local" || route?.startsWith("/local/") === true);
|
|
30990
32057
|
}
|
|
32058
|
+
function isBrowserPage(target) {
|
|
32059
|
+
if (target.type !== "page")
|
|
32060
|
+
return false;
|
|
32061
|
+
try {
|
|
32062
|
+
return ["http:", "https:"].includes(new URL(target.url).protocol);
|
|
32063
|
+
} catch {
|
|
32064
|
+
return false;
|
|
32065
|
+
}
|
|
32066
|
+
}
|
|
32067
|
+
async function installBrowserAnnotationStyles(target, browserClients, operations, signal) {
|
|
32068
|
+
const timeoutMessage = "Browser annotation style compatibility installation timed out";
|
|
32069
|
+
const run = (operation) => runWithCdpSignal(signal, timeoutMessage, operation);
|
|
32070
|
+
let renderer = browserClients.get(target.id);
|
|
32071
|
+
const registered = renderer !== void 0;
|
|
32072
|
+
renderer ??= await connectRendererTarget(target, operations, signal, timeoutMessage);
|
|
32073
|
+
const connected = renderer;
|
|
32074
|
+
try {
|
|
32075
|
+
if (!registered) {
|
|
32076
|
+
await run(() => connected.command("Page.enable"));
|
|
32077
|
+
await run(() => connected.command("Page.addScriptToEvaluateOnNewDocument", {
|
|
32078
|
+
source: BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE
|
|
32079
|
+
}));
|
|
32080
|
+
browserClients.set(target.id, connected);
|
|
32081
|
+
}
|
|
32082
|
+
const installed = await run(() => connected.evaluate("globalThis.__codexhostBrowserAnnotationStylesV1?.refresh() === true"));
|
|
32083
|
+
if (installed !== true) {
|
|
32084
|
+
await run(() => evaluateSource(connected, BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE));
|
|
32085
|
+
}
|
|
32086
|
+
} catch (error51) {
|
|
32087
|
+
browserClients.delete(target.id);
|
|
32088
|
+
connected.close();
|
|
32089
|
+
throw error51;
|
|
32090
|
+
}
|
|
32091
|
+
}
|
|
30991
32092
|
async function installLocalThreadRenderer(target, source, enabledAgents, operations, signal) {
|
|
30992
32093
|
const timeoutMessage = "Local chat Renderer installation timed out";
|
|
30993
32094
|
const run = (operation) => runWithCdpSignal(signal, timeoutMessage, operation);
|
|
@@ -31005,10 +32106,18 @@ async function installLocalThreadRenderer(target, source, enabledAgents, operati
|
|
|
31005
32106
|
renderer.close();
|
|
31006
32107
|
}
|
|
31007
32108
|
}
|
|
31008
|
-
async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, operations, signal) {
|
|
32109
|
+
async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, browserStyleClients, operations, signal) {
|
|
31009
32110
|
try {
|
|
31010
32111
|
const targets = await awaitWithSignal(operations.listTargets(endpoint, signal), signal, "Auxiliary Renderer CDP target discovery timed out");
|
|
32112
|
+
const liveTargets = new Set(targets.map((target) => target.id));
|
|
32113
|
+
for (const [id2, client] of browserStyleClients) {
|
|
32114
|
+
if (!liveTargets.has(id2)) {
|
|
32115
|
+
client.close();
|
|
32116
|
+
browserStyleClients.delete(id2);
|
|
32117
|
+
}
|
|
32118
|
+
}
|
|
31011
32119
|
await Promise.allSettled([
|
|
32120
|
+
...targets.filter(isBrowserPage).map((target) => installBrowserAnnotationStyles(target, browserStyleClients, operations, signal)),
|
|
31012
32121
|
...overlayHookSource ? selectAvatarOverlayRendererTargets(targets).map((overlay) => installOverlayHook(overlay, overlayHookSource, operations, signal)) : [],
|
|
31013
32122
|
...targets.filter(isLocalThreadRenderer).map((target) => installLocalThreadRenderer(target, rendererSource, enabledAgents, operations, signal))
|
|
31014
32123
|
]);
|
|
@@ -31037,6 +32146,7 @@ var InstalledRendererCdpControlSession = class {
|
|
|
31037
32146
|
rendererCdpEndpoint;
|
|
31038
32147
|
rendererSource;
|
|
31039
32148
|
overlayHookSource;
|
|
32149
|
+
browserStyleClients;
|
|
31040
32150
|
enabledAgents;
|
|
31041
32151
|
timeoutMs;
|
|
31042
32152
|
pollIntervalMs;
|
|
@@ -31044,11 +32154,12 @@ var InstalledRendererCdpControlSession = class {
|
|
|
31044
32154
|
currentSnapshot;
|
|
31045
32155
|
disposeModules;
|
|
31046
32156
|
#closed = false;
|
|
31047
|
-
constructor(renderer, rendererCdpEndpoint, rendererSource, overlayHookSource, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules) {
|
|
32157
|
+
constructor(renderer, rendererCdpEndpoint, rendererSource, overlayHookSource, browserStyleClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules) {
|
|
31048
32158
|
this.renderer = renderer;
|
|
31049
32159
|
this.rendererCdpEndpoint = rendererCdpEndpoint;
|
|
31050
32160
|
this.rendererSource = rendererSource;
|
|
31051
32161
|
this.overlayHookSource = overlayHookSource;
|
|
32162
|
+
this.browserStyleClients = browserStyleClients;
|
|
31052
32163
|
this.enabledAgents = enabledAgents;
|
|
31053
32164
|
this.timeoutMs = timeoutMs;
|
|
31054
32165
|
this.pollIntervalMs = pollIntervalMs;
|
|
@@ -31087,7 +32198,7 @@ var InstalledRendererCdpControlSession = class {
|
|
|
31087
32198
|
this.currentSnapshot = replacement.snapshot;
|
|
31088
32199
|
}
|
|
31089
32200
|
}
|
|
31090
|
-
await installAuxiliaryRenderers(this.rendererCdpEndpoint, this.rendererSource, this.enabledAgents, this.overlayHookSource, this.operations, discoveryTimeoutSignal(this.timeoutMs));
|
|
32201
|
+
await installAuxiliaryRenderers(this.rendererCdpEndpoint, this.rendererSource, this.enabledAgents, this.overlayHookSource, this.browserStyleClients, this.operations, discoveryTimeoutSignal(this.timeoutMs));
|
|
31091
32202
|
return this.currentSnapshot;
|
|
31092
32203
|
}
|
|
31093
32204
|
async activateDesktop() {
|
|
@@ -31107,12 +32218,20 @@ var InstalledRendererCdpControlSession = class {
|
|
|
31107
32218
|
this.#closed = true;
|
|
31108
32219
|
this.disposeModules();
|
|
31109
32220
|
this.renderer.close();
|
|
32221
|
+
for (const client of this.browserStyleClients.values())
|
|
32222
|
+
client.close();
|
|
32223
|
+
this.browserStyleClients.clear();
|
|
31110
32224
|
}
|
|
31111
32225
|
};
|
|
31112
32226
|
var defaultOperations = {
|
|
31113
32227
|
listTargets: (endpoint, signal) => listCdpTargets(endpoint, fetch, signal),
|
|
31114
32228
|
connect: (webSocketDebuggerUrl) => CdpClient.connect(webSocketDebuggerUrl),
|
|
31115
|
-
installDraftPrewarmPolicy
|
|
32229
|
+
async installDraftPrewarmPolicy(renderer) {
|
|
32230
|
+
const status2 = await installRendererDraftPrewarmPolicyDirect(renderer);
|
|
32231
|
+
await installNativeRpcRemoteControlDirect(renderer);
|
|
32232
|
+
await installRendererRpcSteeringDirect(renderer);
|
|
32233
|
+
return status2;
|
|
32234
|
+
}
|
|
31116
32235
|
};
|
|
31117
32236
|
async function createRendererCdpControlSession(options) {
|
|
31118
32237
|
const enabledAgents = options.enabledAgents;
|
|
@@ -31121,8 +32240,9 @@ async function createRendererCdpControlSession(options) {
|
|
|
31121
32240
|
const operations = options.operations ?? defaultOperations;
|
|
31122
32241
|
const target = await waitForPrimaryTarget(options.rendererCdpEndpoint, operations, timeoutMs, pollIntervalMs, void 0, options.signal);
|
|
31123
32242
|
const installed = await installTarget(target, options.rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations);
|
|
31124
|
-
|
|
31125
|
-
|
|
32243
|
+
const browserStyleClients = /* @__PURE__ */ new Map();
|
|
32244
|
+
await installAuxiliaryRenderers(options.rendererCdpEndpoint, options.rendererSource, enabledAgents, options.overlayHookSource, browserStyleClients, operations, discoveryTimeoutSignal(timeoutMs, options.signal));
|
|
32245
|
+
return new InstalledRendererCdpControlSession(installed.renderer, options.rendererCdpEndpoint, options.rendererSource, options.overlayHookSource, browserStyleClients, enabledAgents, timeoutMs, pollIntervalMs, operations, installed.snapshot, installed.disposeModules);
|
|
31126
32246
|
}
|
|
31127
32247
|
function installRendererCdpControlSession(options) {
|
|
31128
32248
|
return createRendererCdpControlSession(options);
|
|
@@ -36640,12 +37760,13 @@ var ExternalThreadRuntime = class {
|
|
|
36640
37760
|
}
|
|
36641
37761
|
try {
|
|
36642
37762
|
const aligned = await this.#repository.alignSnapshot(thread.record, snapshot2.value);
|
|
37763
|
+
const turns = aligned.record.state === "creating" && !aligned.record.nativeSessionRef && snapshot2.value.turns.length === 0 ? thread.turns : aligned.turns;
|
|
36643
37764
|
thread.record = aligned.record;
|
|
36644
|
-
thread.turns =
|
|
37765
|
+
thread.turns = turns;
|
|
36645
37766
|
thread.historyHydrated = true;
|
|
36646
37767
|
thread.thread = externalThreadValue({
|
|
36647
37768
|
record: aligned.record,
|
|
36648
|
-
turns
|
|
37769
|
+
turns,
|
|
36649
37770
|
sessionId: thread.sessionId,
|
|
36650
37771
|
running: thread.running
|
|
36651
37772
|
});
|
|
@@ -36937,6 +38058,7 @@ var publicSubmission = ({
|
|
|
36937
38058
|
var DEFAULT_PAGE_SIZE3 = 50;
|
|
36938
38059
|
var ExternalThreadQueue = class {
|
|
36939
38060
|
#queues = /* @__PURE__ */ new Map();
|
|
38061
|
+
#acceptedSteers = /* @__PURE__ */ new Map();
|
|
36940
38062
|
#notifyChanged;
|
|
36941
38063
|
#createId;
|
|
36942
38064
|
constructor(options) {
|
|
@@ -36982,7 +38104,7 @@ var ExternalThreadQueue = class {
|
|
|
36982
38104
|
async delete(threadId2, id2) {
|
|
36983
38105
|
const items = this.#queues.get(threadId2);
|
|
36984
38106
|
const index = items?.findIndex((item) => item.id === id2) ?? -1;
|
|
36985
|
-
if (!items || index === -1) return
|
|
38107
|
+
if (!items || index === -1) return this.#acceptedSteers.get(id2) === threadId2;
|
|
36986
38108
|
items.splice(index, 1);
|
|
36987
38109
|
this.#prune(threadId2);
|
|
36988
38110
|
await this.#notifyChanged(threadId2);
|
|
@@ -37015,6 +38137,26 @@ var ExternalThreadQueue = class {
|
|
|
37015
38137
|
index
|
|
37016
38138
|
};
|
|
37017
38139
|
}
|
|
38140
|
+
/** Reserve the exact queued input before steering can finish a replacement Turn.
|
|
38141
|
+
* Otherwise automatic queue advancement can deliver that input a second time. */
|
|
38142
|
+
takeSteered(threadId2, clientUserMessageId, input) {
|
|
38143
|
+
if (typeof clientUserMessageId !== "string") return;
|
|
38144
|
+
const matches = (this.#queues.get(threadId2) ?? []).filter(
|
|
38145
|
+
(item2) => item2.clientUserMessageId === clientUserMessageId
|
|
38146
|
+
);
|
|
38147
|
+
if (matches.length === 0) return;
|
|
38148
|
+
const item = matches[0];
|
|
38149
|
+
if (matches.length !== 1 || externalTurnInputText(item.input) !== externalTurnInputText(input))
|
|
38150
|
+
throw new ExternalQueueError(-32602, "Queued steering input changed before delivery");
|
|
38151
|
+
return this.take(threadId2, item.id);
|
|
38152
|
+
}
|
|
38153
|
+
async acceptSteered(threadId2, taken) {
|
|
38154
|
+
this.#acceptedSteers.set(taken.submission.id, threadId2);
|
|
38155
|
+
while (this.#acceptedSteers.size > 128) {
|
|
38156
|
+
this.#acceptedSteers.delete(this.#acceptedSteers.keys().next().value);
|
|
38157
|
+
}
|
|
38158
|
+
await this.#notifyChanged(threadId2);
|
|
38159
|
+
}
|
|
37018
38160
|
restore(threadId2, taken) {
|
|
37019
38161
|
const items = this.#items(threadId2);
|
|
37020
38162
|
if (items.some((item) => item.id === taken.submission.id)) return;
|
|
@@ -37028,6 +38170,9 @@ var ExternalThreadQueue = class {
|
|
|
37028
38170
|
}
|
|
37029
38171
|
forget(threadId2) {
|
|
37030
38172
|
this.#queues.delete(threadId2);
|
|
38173
|
+
for (const [id2, owner] of this.#acceptedSteers) {
|
|
38174
|
+
if (owner === threadId2) this.#acceptedSteers.delete(id2);
|
|
38175
|
+
}
|
|
37031
38176
|
}
|
|
37032
38177
|
#items(threadId2) {
|
|
37033
38178
|
let items = this.#queues.get(threadId2);
|
|
@@ -44629,7 +45774,10 @@ var AppServerHost = class {
|
|
|
44629
45774
|
request,
|
|
44630
45775
|
location,
|
|
44631
45776
|
(hostThreadId) => this.#repository.setArchived(hostThreadId, archived),
|
|
44632
|
-
"External Thread archive state could not be persisted"
|
|
45777
|
+
"External Thread archive state could not be persisted",
|
|
45778
|
+
// A loaded Thread whose deferred native Session never arrived (its first Turn
|
|
45779
|
+
// failed first) is still on Desktop's list and must remain archivable.
|
|
45780
|
+
true
|
|
44633
45781
|
);
|
|
44634
45782
|
if (!updated) return;
|
|
44635
45783
|
await this.#writer.json(
|
|
@@ -45219,7 +46367,7 @@ var AppServerHost = class {
|
|
|
45219
46367
|
...arguments_2 ? { arguments: arguments_2 } : {}
|
|
45220
46368
|
});
|
|
45221
46369
|
if (!result.ok) throw new ExternalCommandError(-32073, result.error.message);
|
|
45222
|
-
return { turnId
|
|
46370
|
+
return { turnId, turn: projection.projector.pendingTurn(), gate };
|
|
45223
46371
|
} catch (error51) {
|
|
45224
46372
|
restoreExecutionHost();
|
|
45225
46373
|
thread.running = false;
|
|
@@ -46047,6 +47195,11 @@ var AppServerHost = class {
|
|
|
46047
47195
|
);
|
|
46048
47196
|
}
|
|
46049
47197
|
async #startExternalTurn(request, thread) {
|
|
47198
|
+
const context = routingParams(request).additionalContext;
|
|
47199
|
+
if (isRecord21(context) && Object.hasOwn(context, THREAD_STEERING_CONTEXT_PARAM)) {
|
|
47200
|
+
await this.#steerExternalTurn(request, thread, true);
|
|
47201
|
+
return;
|
|
47202
|
+
}
|
|
46050
47203
|
if (this.#externalThreadBusy(thread) || this.#pendingExternalCommandRequests.has(thread.id)) {
|
|
46051
47204
|
await this.#writer.json(
|
|
46052
47205
|
rpcError(request, -32072, "External Thread already has an active Turn")
|
|
@@ -46265,34 +47418,61 @@ var AppServerHost = class {
|
|
|
46265
47418
|
this.#diagnose(error51);
|
|
46266
47419
|
}
|
|
46267
47420
|
}
|
|
46268
|
-
async #steerExternalTurn(request, thread) {
|
|
47421
|
+
async #steerExternalTurn(request, thread, asStart = false) {
|
|
47422
|
+
let queued;
|
|
47423
|
+
let accepted = false;
|
|
46269
47424
|
try {
|
|
47425
|
+
let params = requestObject(request);
|
|
47426
|
+
const context = params.additionalContext;
|
|
47427
|
+
if (isRecord21(context) && Object.hasOwn(context, THREAD_STEERING_CONTEXT_PARAM)) {
|
|
47428
|
+
const marker = threadSteeringContextSchema.safeParse(
|
|
47429
|
+
context[THREAD_STEERING_CONTEXT_PARAM]
|
|
47430
|
+
);
|
|
47431
|
+
if (!marker.success || marker.data.clientUserMessageId !== params.clientUserMessageId || asStart && marker.data.delivery !== "newTurn")
|
|
47432
|
+
throw new ExternalSteerError(-32602, "Invalid native steering preparation context");
|
|
47433
|
+
if (!asStart && params.expectedTurnId !== marker.data.expectedTurnId)
|
|
47434
|
+
throw new ExternalSteerError(-32074, "Native steering target changed before submission");
|
|
47435
|
+
params = {
|
|
47436
|
+
...params,
|
|
47437
|
+
expectedTurnId: marker.data.expectedTurnId,
|
|
47438
|
+
[THREAD_STEER_DELIVERY_PARAM]: marker.data.delivery
|
|
47439
|
+
};
|
|
47440
|
+
}
|
|
47441
|
+
queued = this.#externalQueue.takeSteered(thread.id, params.clientUserMessageId, params.input);
|
|
46270
47442
|
const started = await this.#externalSteering.run(
|
|
46271
47443
|
thread,
|
|
46272
|
-
|
|
47444
|
+
params,
|
|
46273
47445
|
(text, assertActive) => this.#beginExternalInputTurn(
|
|
46274
47446
|
thread,
|
|
46275
47447
|
text,
|
|
46276
47448
|
assertActive,
|
|
46277
47449
|
typeof requestObject(request).clientUserMessageId === "string" ? requestObject(request).clientUserMessageId : void 0,
|
|
46278
|
-
requestObject(request)[THREAD_REFERENCE_SOURCE_HOST_PARAM]
|
|
47450
|
+
queued ? queued.sourceHostId : requestObject(request)[THREAD_REFERENCE_SOURCE_HOST_PARAM]
|
|
46279
47451
|
),
|
|
46280
47452
|
(input) => this.#insertExternalInput(thread, input)
|
|
46281
47453
|
);
|
|
47454
|
+
accepted = true;
|
|
47455
|
+
if (queued) {
|
|
47456
|
+
await this.#externalQueue.acceptSteered(thread.id, queued).catch((error51) => this.#diagnose(error51));
|
|
47457
|
+
}
|
|
46282
47458
|
try {
|
|
46283
47459
|
await this.#writer.json(
|
|
46284
47460
|
rpcEnvelope(request, {
|
|
46285
|
-
result: { turnId: started.turnId, delivery: started.delivery }
|
|
47461
|
+
result: asStart ? { turn: this.#projectedTurn(thread, started.turnId).projector.pendingTurn() } : { turnId: started.turnId, delivery: started.delivery }
|
|
46286
47462
|
})
|
|
46287
47463
|
);
|
|
46288
47464
|
} finally {
|
|
46289
47465
|
started.gate.resolve();
|
|
46290
47466
|
}
|
|
46291
47467
|
} catch (error51) {
|
|
47468
|
+
if (queued && !accepted) {
|
|
47469
|
+
this.#externalQueue.restore(thread.id, queued);
|
|
47470
|
+
await this.#externalQueue.notifyChanged(thread.id).catch((failure3) => this.#diagnose(failure3));
|
|
47471
|
+
}
|
|
46292
47472
|
await this.#writer.json(
|
|
46293
47473
|
rpcError(
|
|
46294
47474
|
request,
|
|
46295
|
-
error51 instanceof ExternalSteerError || error51 instanceof ExternalCommandError ? error51.code : -32074,
|
|
47475
|
+
error51 instanceof ExternalSteerError || error51 instanceof ExternalCommandError || error51 instanceof ExternalQueueError ? error51.code : -32074,
|
|
46296
47476
|
errorMessage4(error51)
|
|
46297
47477
|
)
|
|
46298
47478
|
);
|