@liberseek/boft-cli-win32-arm64 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +59 -8
- package/app/console-web.js +278 -63
- package/app/desktop-controller.mjs +641 -33
- package/app/host-runtime.mjs +1811 -685
- package/app/plugins/antigravity/plugin.mjs +346 -54
- package/app/plugins/claude-code/plugin.mjs +391 -259
- package/app/plugins/codebuddy/plugin.mjs +231 -134
- package/app/plugins/codex-usage/plugin.mjs +82 -32
- package/app/plugins/copilot/plugin.mjs +107 -57
- package/app/plugins/cursor-cli/plugin.mjs +193 -131
- package/app/plugins/deepseek-harness/plugin.mjs +112 -42
- package/app/plugins/grok/plugin.mjs +371 -115
- package/app/plugins/hermes/plugin.mjs +54 -4
- package/app/plugins/kimi-code/plugin.mjs +69 -19
- package/app/plugins/kiro-cli/plugin.mjs +69 -19
- package/app/plugins/muse/plugin.mjs +59 -9
- package/app/plugins/omp/plugin.mjs +89 -39
- package/app/plugins/opencode/plugin.mjs +111 -61
- package/app/plugins/pi/plugin.mjs +185 -68
- package/app/plugins/qoder/plugin.mjs +79 -29
- package/app/plugins/qoder-cn/plugin.mjs +79 -29
- package/app/plugins/workbuddy/plugin.mjs +231 -134
- package/app/plugins/zcode/plugin.mjs +108 -33
- package/app/renderer-extension.js +2634 -329
- package/bin/boft.exe +0 -0
- package/libexec/boft-node-repl.exe +0 -0
- package/libexec/boft-shim.exe +0 -0
- package/libexec/boft-updater.exe +0 -0
- package/package.json +1 -1
|
@@ -3308,10 +3308,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
3308
3308
|
const shape = def.shape;
|
|
3309
3309
|
const propValues = {};
|
|
3310
3310
|
for (const key in shape) {
|
|
3311
|
-
const
|
|
3312
|
-
if (
|
|
3311
|
+
const field2 = shape[key]._zod;
|
|
3312
|
+
if (field2.values) {
|
|
3313
3313
|
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
3314
|
-
for (const v of
|
|
3314
|
+
for (const v of field2.values)
|
|
3315
3315
|
propValues[key].add(v);
|
|
3316
3316
|
}
|
|
3317
3317
|
}
|
|
@@ -14952,6 +14952,8 @@ var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
|
14952
14952
|
cachedInputTokens: count,
|
|
14953
14953
|
cacheWriteInputTokens: count,
|
|
14954
14954
|
cacheKnownInputTokens: count,
|
|
14955
|
+
cacheHitCachedInputTokens: count,
|
|
14956
|
+
cacheHitInputTokens: count,
|
|
14955
14957
|
outputTokens: count,
|
|
14956
14958
|
reasoningOutputTokens: count,
|
|
14957
14959
|
/** USD at the public price, summed over the priced requests only. */
|
|
@@ -15059,6 +15061,51 @@ var hostInteractionIdSchema = opaqueIdSchema.brand();
|
|
|
15059
15061
|
var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
|
|
15060
15062
|
var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
|
|
15061
15063
|
|
|
15064
|
+
// packages/shared-contracts/dist/thread-questions.js
|
|
15065
|
+
var field = external_exports.discriminatedUnion("type", [
|
|
15066
|
+
external_exports.object({
|
|
15067
|
+
id: external_exports.string().min(1),
|
|
15068
|
+
type: external_exports.literal("choice"),
|
|
15069
|
+
prompt: external_exports.string(),
|
|
15070
|
+
options: external_exports.array(external_exports.object({
|
|
15071
|
+
value: external_exports.string().min(1),
|
|
15072
|
+
label: external_exports.string(),
|
|
15073
|
+
description: external_exports.string().optional()
|
|
15074
|
+
})).min(1),
|
|
15075
|
+
multiple: external_exports.boolean(),
|
|
15076
|
+
allowOther: external_exports.boolean(),
|
|
15077
|
+
optional: external_exports.boolean()
|
|
15078
|
+
}),
|
|
15079
|
+
external_exports.object({
|
|
15080
|
+
id: external_exports.string().min(1),
|
|
15081
|
+
type: external_exports.literal("text"),
|
|
15082
|
+
prompt: external_exports.string(),
|
|
15083
|
+
multiline: external_exports.boolean(),
|
|
15084
|
+
secret: external_exports.literal(false),
|
|
15085
|
+
optional: external_exports.boolean(),
|
|
15086
|
+
placeholder: external_exports.string().optional(),
|
|
15087
|
+
prefill: external_exports.string().optional()
|
|
15088
|
+
})
|
|
15089
|
+
]);
|
|
15090
|
+
var threadQuestionSchema = external_exports.object({
|
|
15091
|
+
interactionId: external_exports.string().min(1),
|
|
15092
|
+
turnId: external_exports.string().min(1),
|
|
15093
|
+
title: external_exports.string().optional(),
|
|
15094
|
+
questions: external_exports.array(field).min(1)
|
|
15095
|
+
}).refine(({ questions }) => questions.some((q) => q.type === "choice" && q.multiple), {
|
|
15096
|
+
message: "Shared cards require at least one multi-select question"
|
|
15097
|
+
});
|
|
15098
|
+
var threadQuestionsListParamsSchema = external_exports.strictObject({ threadId: external_exports.string().min(1) });
|
|
15099
|
+
var threadQuestionsResultSchema = external_exports.object({ questions: external_exports.array(threadQuestionSchema) });
|
|
15100
|
+
var threadQuestionRespondParamsSchema = external_exports.strictObject({
|
|
15101
|
+
threadId: external_exports.string().min(1),
|
|
15102
|
+
turnId: external_exports.string().min(1),
|
|
15103
|
+
interactionId: external_exports.string().min(1),
|
|
15104
|
+
answers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
|
|
15105
|
+
cancelled: external_exports.boolean().default(false)
|
|
15106
|
+
});
|
|
15107
|
+
var threadQuestionRespondResultSchema = external_exports.object({ accepted: external_exports.literal(true) });
|
|
15108
|
+
|
|
15062
15109
|
// packages/shared-contracts/dist/harness-plugins.js
|
|
15063
15110
|
var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
|
|
15064
15111
|
var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
|
|
@@ -15828,7 +15875,10 @@ var harnessPluginRouteSchema = external_exports.object({
|
|
|
15828
15875
|
harnessId: harnessPluginIdSchema,
|
|
15829
15876
|
model: harnessModelRefSchema.optional(),
|
|
15830
15877
|
thinkingOptionId: harnessThinkingOptionIdSchema.optional(),
|
|
15831
|
-
permissionModeId: harnessPermissionModeIdSchema.optional()
|
|
15878
|
+
permissionModeId: harnessPermissionModeIdSchema.optional(),
|
|
15879
|
+
/** A draft prewarm create: stays unsubmitted until the user's first Turn.
|
|
15880
|
+
* Desktop forwards only the Model of a main-process prewarm to thread/start. */
|
|
15881
|
+
prewarm: external_exports.literal(true).optional()
|
|
15832
15882
|
}).strict();
|
|
15833
15883
|
|
|
15834
15884
|
// packages/shared-contracts/dist/harness-launch-settings.js
|
|
@@ -16704,8 +16754,99 @@ function retainRendererHostResponses(client, hostId2, target) {
|
|
|
16704
16754
|
};
|
|
16705
16755
|
}
|
|
16706
16756
|
|
|
16757
|
+
// packages/desktop-control/src/renderer-prewarm-consumption.ts
|
|
16758
|
+
function isolateRendererPrewarmConsumption(manager, discardExternal) {
|
|
16759
|
+
const record3 = (value) => value !== null && typeof value === "object";
|
|
16760
|
+
if (!record3(manager) || !record3(manager.threadCreation)) return null;
|
|
16761
|
+
const creation = manager.threadCreation;
|
|
16762
|
+
const originalStart = manager.startConversation;
|
|
16763
|
+
const original = creation.createConversation;
|
|
16764
|
+
const params = creation.params;
|
|
16765
|
+
if (typeof originalStart !== "function" || typeof original !== "function" || !record3(params))
|
|
16766
|
+
return null;
|
|
16767
|
+
const prototype = Object.getPrototypeOf(creation);
|
|
16768
|
+
if (!record3(prototype) || typeof prototype.constructor !== "function") return null;
|
|
16769
|
+
if (Object.keys(creation).some((key) => key !== "params" && typeof creation[key] !== "function") || /#[A-Za-z_$]/u.test(Function.prototype.toString.call(prototype.constructor)))
|
|
16770
|
+
return null;
|
|
16771
|
+
const pool = params.prewarmedThreadManager;
|
|
16772
|
+
if (!record3(pool) || typeof pool.hasPrewarmedThread !== "function" || typeof pool.consumePrewarmedThread !== "function" || typeof pool.deletePrewarmedThread !== "function")
|
|
16773
|
+
return null;
|
|
16774
|
+
const consume = pool.consumePrewarmedThread;
|
|
16775
|
+
const hasPrewarm = pool.hasPrewarmedThread;
|
|
16776
|
+
const draftModels = /* @__PURE__ */ new Map();
|
|
16777
|
+
const draftIdentity = /* @__PURE__ */ Symbol("codexhost draft creation");
|
|
16778
|
+
const external = (model2) => typeof model2 === "string" && model2.startsWith("codexhost/");
|
|
16779
|
+
const routedStart = function(input, options, ...args) {
|
|
16780
|
+
const draftId = record3(options) ? options.clientThreadId : null;
|
|
16781
|
+
const mode = record3(input) && record3(input.collaborationMode) ? input.collaborationMode : null;
|
|
16782
|
+
const origin = mode ? Reflect.get(mode, draftIdentity) : void 0;
|
|
16783
|
+
if (mode && record3(mode.settings) && external(mode.settings.model))
|
|
16784
|
+
return originalStart.call(this, input, options, ...args);
|
|
16785
|
+
const model2 = (typeof draftId === "string" ? draftModels.get(draftId) : void 0) ?? (typeof origin === "string" ? draftModels.get(origin) : void 0);
|
|
16786
|
+
if (!model2) return originalStart.call(this, input, options, ...args);
|
|
16787
|
+
if (!record3(input) || !record3(input.collaborationMode) || !record3(input.collaborationMode.settings))
|
|
16788
|
+
throw new Error("External draft creation is missing its native Model settings");
|
|
16789
|
+
const routed = {
|
|
16790
|
+
...input,
|
|
16791
|
+
collaborationMode: {
|
|
16792
|
+
...input.collaborationMode,
|
|
16793
|
+
settings: { ...input.collaborationMode.settings, model: model2 }
|
|
16794
|
+
}
|
|
16795
|
+
};
|
|
16796
|
+
return originalStart.call(this, routed, options, ...args);
|
|
16797
|
+
};
|
|
16798
|
+
const wrapped = function(input, ...args) {
|
|
16799
|
+
const mode = record3(input) && record3(input.collaborationMode) ? input.collaborationMode : null;
|
|
16800
|
+
const expected = mode && record3(mode.settings) ? mode.settings.model : null;
|
|
16801
|
+
const scopedPool = Object.create(pool);
|
|
16802
|
+
scopedPool.hasPrewarmedThread = (...parameters) => hasPrewarm.apply(pool, parameters);
|
|
16803
|
+
scopedPool.consumePrewarmedThread = async (...consumeArgs) => {
|
|
16804
|
+
const warmed = await consume.apply(pool, consumeArgs);
|
|
16805
|
+
if (!record3(warmed) || !record3(warmed.response)) return warmed;
|
|
16806
|
+
const response = warmed.response;
|
|
16807
|
+
if (!external(expected) && !external(response.model)) return warmed;
|
|
16808
|
+
if (external(expected) && expected === response.model) return warmed;
|
|
16809
|
+
if (record3(response.thread) && typeof response.thread.id === "string") {
|
|
16810
|
+
const threadId = response.thread.id;
|
|
16811
|
+
if (external(response.model)) discardExternal(threadId);
|
|
16812
|
+
else
|
|
16813
|
+
void Promise.resolve().then(() => pool.deletePrewarmedThread(threadId)).catch(() => void 0);
|
|
16814
|
+
}
|
|
16815
|
+
return null;
|
|
16816
|
+
};
|
|
16817
|
+
const invocation = Object.create(creation);
|
|
16818
|
+
invocation.params = { ...params, prewarmedThreadManager: scopedPool };
|
|
16819
|
+
return original.call(invocation, input, ...args);
|
|
16820
|
+
};
|
|
16821
|
+
creation.createConversation = wrapped;
|
|
16822
|
+
manager.startConversation = routedStart;
|
|
16823
|
+
return {
|
|
16824
|
+
selectDraft(draftId, model2, creationModes = []) {
|
|
16825
|
+
if (draftId === void 0) {
|
|
16826
|
+
if (model2 === null) draftModels.clear();
|
|
16827
|
+
} else if (model2 === null) draftModels.delete(draftId);
|
|
16828
|
+
else {
|
|
16829
|
+
if (!draftId.startsWith("client-new-thread:") || !external(model2))
|
|
16830
|
+
throw new Error("External draft route is missing its client Thread identity");
|
|
16831
|
+
draftModels.set(draftId, model2);
|
|
16832
|
+
for (const mode of creationModes)
|
|
16833
|
+
Object.defineProperty(mode, draftIdentity, {
|
|
16834
|
+
configurable: true,
|
|
16835
|
+
enumerable: true,
|
|
16836
|
+
value: draftId
|
|
16837
|
+
});
|
|
16838
|
+
}
|
|
16839
|
+
},
|
|
16840
|
+
dispose() {
|
|
16841
|
+
draftModels.clear();
|
|
16842
|
+
if (manager.startConversation === routedStart) manager.startConversation = originalStart;
|
|
16843
|
+
if (creation.createConversation === wrapped) creation.createConversation = original;
|
|
16844
|
+
}
|
|
16845
|
+
};
|
|
16846
|
+
}
|
|
16847
|
+
|
|
16707
16848
|
// packages/desktop-control/src/renderer-draft-prewarm-runtime.ts
|
|
16708
|
-
function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewarmedThreadManager, isCurrentManager, retainResponses = retainRendererHostResponses) {
|
|
16849
|
+
function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewarmedThreadManager, isCurrentManager, retainResponses = retainRendererHostResponses, isolateConsumption = isolateRendererPrewarmConsumption) {
|
|
16709
16850
|
let disposed = false;
|
|
16710
16851
|
const originalSend = bridge.sendRequest;
|
|
16711
16852
|
const originalPrewarm = bridge.prewarmThreadStart;
|
|
@@ -17086,26 +17227,16 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17086
17227
|
if (threadId && knownOfficialThreadIds.has(threadId)) return false;
|
|
17087
17228
|
return selectedModel !== null && (method.startsWith("thread/") || method.startsWith("turn/") || method.startsWith("review/"));
|
|
17088
17229
|
};
|
|
17089
|
-
const routeThreadStart = (parameters) => {
|
|
17090
|
-
if (!isRecord3(parameters) || parameters.ephemeral === true) {
|
|
17091
|
-
return parameters;
|
|
17092
|
-
}
|
|
17093
|
-
return {
|
|
17094
|
-
...parameters,
|
|
17095
|
-
...selectedModel === null ? {} : { model: selectedModel }
|
|
17096
|
-
};
|
|
17097
|
-
};
|
|
17098
17230
|
const routedSend = (method, parameters, options) => {
|
|
17099
17231
|
if (method === "turn/start" || method === "thread/resume" || method === "codexhost/thread/command/execute") {
|
|
17100
17232
|
const threadId = threadIdFromParameters(parameters);
|
|
17101
17233
|
if (threadId) externalPrewarms.delete(threadId);
|
|
17102
17234
|
}
|
|
17103
|
-
const routedParameters = method === "thread/start" ? routeThreadStart(parameters) : parameters;
|
|
17104
17235
|
const sendBridged = () => initializeBridge().then(
|
|
17105
|
-
() => enqueueBridgeRequest(method,
|
|
17236
|
+
() => enqueueBridgeRequest(method, parameters, options)
|
|
17106
17237
|
);
|
|
17107
|
-
const sendDirect = () => options === void 0 ? originalSend.call(bridge, method,
|
|
17108
|
-
const unresolvedThreadId = shouldResolveThreadOwnership(method,
|
|
17238
|
+
const sendDirect = () => options === void 0 ? originalSend.call(bridge, method, parameters) : originalSend.call(bridge, method, parameters, options);
|
|
17239
|
+
const unresolvedThreadId = shouldResolveThreadOwnership(method, parameters);
|
|
17109
17240
|
if (unresolvedThreadId) {
|
|
17110
17241
|
return resolveThreadOwnership(unresolvedThreadId).then(
|
|
17111
17242
|
(owner) => owner === "external" ? sendBridged() : sendDirect(),
|
|
@@ -17121,7 +17252,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17121
17252
|
}
|
|
17122
17253
|
);
|
|
17123
17254
|
}
|
|
17124
|
-
return shouldUseBridge(method,
|
|
17255
|
+
return shouldUseBridge(method, parameters) ? sendBridged() : sendDirect();
|
|
17125
17256
|
};
|
|
17126
17257
|
const publishDraftWorkspace = (parameters) => {
|
|
17127
17258
|
if (!isRecord3(parameters) || parameters.ephemeral === true) return;
|
|
@@ -17151,10 +17282,10 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17151
17282
|
const discardExternalPrewarms = () => {
|
|
17152
17283
|
for (const threadId of externalPrewarms) discardExternalPrewarm(threadId);
|
|
17153
17284
|
};
|
|
17285
|
+
const restoreConsumption = isolateConsumption(manager, discardExternalPrewarm);
|
|
17154
17286
|
const routedPrewarm = (parameters, options) => {
|
|
17155
|
-
const
|
|
17156
|
-
const
|
|
17157
|
-
const routedParameters = external ? { ...routed, codexhostPrewarm: true } : routed;
|
|
17287
|
+
const external = isRecord3(parameters) && parameters.ephemeral !== true && typeof parameters.model === "string" && parameters.model.startsWith("codexhost/");
|
|
17288
|
+
const routedParameters = external ? { ...parameters, codexhostPrewarm: true } : parameters;
|
|
17158
17289
|
const generation = prewarmGeneration;
|
|
17159
17290
|
publishDraftWorkspace(routedParameters);
|
|
17160
17291
|
const pending = shouldUseBridge("thread/start", routedParameters) ? routedSend("thread/start", routedParameters, options) : options === void 0 ? originalPrewarm.call(bridge, routedParameters) : originalPrewarm.call(bridge, routedParameters, options);
|
|
@@ -17207,6 +17338,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17207
17338
|
const policy = Object.freeze({
|
|
17208
17339
|
state: "ready",
|
|
17209
17340
|
hostId: hostId2,
|
|
17341
|
+
scopedCreation: restoreConsumption !== null,
|
|
17210
17342
|
owns(candidateManager, candidate, candidateHostId, candidatePrewarmedThreadManager, requiresCurrentManager) {
|
|
17211
17343
|
return !disposed && candidateManager === manager && candidate === bridge && candidateHostId === hostId2 && candidatePrewarmedThreadManager === prewarmedThreadManager && requiresCurrentManager === !!isCurrentManager;
|
|
17212
17344
|
},
|
|
@@ -17215,12 +17347,13 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17215
17347
|
throw new Error("Renderer request manager is retired");
|
|
17216
17348
|
return manager;
|
|
17217
17349
|
},
|
|
17218
|
-
select(model2) {
|
|
17350
|
+
select(model2, draftId, creationModes) {
|
|
17219
17351
|
if (disposed || isCurrentManager && !isCurrentManager())
|
|
17220
17352
|
throw new Error("Renderer request manager is retired");
|
|
17221
17353
|
if (model2 !== null && (typeof model2 !== "string" || !model2.startsWith("codexhost/"))) {
|
|
17222
17354
|
throw new Error("Draft route Model must be a codexhost transport carrier");
|
|
17223
17355
|
}
|
|
17356
|
+
restoreConsumption?.selectDraft(draftId, model2, creationModes);
|
|
17224
17357
|
if (selectedModel === model2) return false;
|
|
17225
17358
|
selectedModel = model2;
|
|
17226
17359
|
prewarmGeneration += 1;
|
|
@@ -17241,6 +17374,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17241
17374
|
disposed = true;
|
|
17242
17375
|
prewarmGeneration += 1;
|
|
17243
17376
|
retireResponses();
|
|
17377
|
+
restoreConsumption?.dispose();
|
|
17244
17378
|
if (bridge.sendRequest === routedSend) bridge.sendRequest = originalSend;
|
|
17245
17379
|
if (bridge.prewarmThreadStart === routedPrewarm) {
|
|
17246
17380
|
bridge.prewarmThreadStart = originalPrewarm;
|
|
@@ -17277,14 +17411,14 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17277
17411
|
|
|
17278
17412
|
// packages/desktop-control/src/renderer-host-discovery.ts
|
|
17279
17413
|
function requestManagerFromHookState(value, hostId2) {
|
|
17280
|
-
const
|
|
17414
|
+
const record3 = (candidate) => typeof candidate === "object" && candidate !== null;
|
|
17281
17415
|
const manager = (candidate) => {
|
|
17282
|
-
if (!
|
|
17416
|
+
if (!record3(candidate) || !record3(candidate.requestClient) || !record3(candidate.prewarmedThreadManager))
|
|
17283
17417
|
return null;
|
|
17284
17418
|
const bridge = candidate.requestClient;
|
|
17285
17419
|
return typeof candidate.sendRequest === "function" && typeof bridge.sendRequest === "function" && typeof bridge.prewarmThreadStart === "function" && typeof bridge.enqueueRequest === "function" && typeof candidate.prewarmedThreadManager.discardAllPrewarmedThreads === "function" ? candidate : null;
|
|
17286
17420
|
};
|
|
17287
|
-
if (!
|
|
17421
|
+
if (!record3(value)) return null;
|
|
17288
17422
|
const direct = manager(value) ?? manager(value.manager);
|
|
17289
17423
|
if (direct) return direct;
|
|
17290
17424
|
if (!hostId2 || typeof value.addManager !== "function" || typeof value.getForHostId !== "function")
|
|
@@ -17494,6 +17628,335 @@ function installRendererHostRouting(root, target, discover, resolve, createPolic
|
|
|
17494
17628
|
return routing;
|
|
17495
17629
|
}
|
|
17496
17630
|
|
|
17631
|
+
// packages/desktop-control/src/renderer-host-rpc-discovery.ts
|
|
17632
|
+
function findRendererAppScopeStore(root) {
|
|
17633
|
+
const MAX_VISITED_FIBERS = 5e4;
|
|
17634
|
+
const record3 = (value) => typeof value === "object" && value !== null;
|
|
17635
|
+
const container = root.getElementById?.("root");
|
|
17636
|
+
if (!record3(container)) return null;
|
|
17637
|
+
const key = Object.getOwnPropertyNames(container).find(
|
|
17638
|
+
(name) => name.startsWith("__reactContainer$")
|
|
17639
|
+
);
|
|
17640
|
+
const first = key ? container[key] : null;
|
|
17641
|
+
if (!record3(first)) return null;
|
|
17642
|
+
const isScopeHandle = (value) => record3(value) && record3(value.node) && "chain" in value && "scope" in value && typeof value.get === "function" && typeof value.set === "function" && typeof value.watch === "function";
|
|
17643
|
+
const stack = [first];
|
|
17644
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17645
|
+
while (stack.length && seen.size < MAX_VISITED_FIBERS) {
|
|
17646
|
+
const fiber = stack.pop();
|
|
17647
|
+
if (seen.has(fiber)) continue;
|
|
17648
|
+
seen.add(fiber);
|
|
17649
|
+
let hook = fiber.memoizedState;
|
|
17650
|
+
for (let index = 0; record3(hook) && "next" in hook && index < 150; index += 1) {
|
|
17651
|
+
const state = hook.memoizedState;
|
|
17652
|
+
const handle = record3(state) ? state.current : null;
|
|
17653
|
+
if (isScopeHandle(handle)) {
|
|
17654
|
+
let node = handle.node;
|
|
17655
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
17656
|
+
while (record3(node.parent) && !nodes.has(node.parent)) {
|
|
17657
|
+
nodes.add(node);
|
|
17658
|
+
node = node.parent;
|
|
17659
|
+
}
|
|
17660
|
+
const bindings = node.familyBindings;
|
|
17661
|
+
return record3(bindings) && typeof bindings.get === "function" && typeof bindings.entries === "function" ? node : null;
|
|
17662
|
+
}
|
|
17663
|
+
hook = hook.next;
|
|
17664
|
+
}
|
|
17665
|
+
if (record3(fiber.sibling)) stack.push(fiber.sibling);
|
|
17666
|
+
if (record3(fiber.child)) stack.push(fiber.child);
|
|
17667
|
+
}
|
|
17668
|
+
return null;
|
|
17669
|
+
}
|
|
17670
|
+
function findRendererHostRpcFamily(store) {
|
|
17671
|
+
const record3 = (value) => typeof value === "object" && value !== null;
|
|
17672
|
+
const families = /* @__PURE__ */ new Set();
|
|
17673
|
+
for (const [definition, members] of store.familyBindings) {
|
|
17674
|
+
if (!record3(definition) || definition.kind !== "signal-family") continue;
|
|
17675
|
+
if (!record3(members) || typeof members.get !== "function") continue;
|
|
17676
|
+
for (const [hostId2, member] of members) {
|
|
17677
|
+
if (typeof hostId2 !== "string" || !record3(member)) continue;
|
|
17678
|
+
const signal = member.value;
|
|
17679
|
+
if (!record3(signal) || typeof signal.get !== "function") continue;
|
|
17680
|
+
let value;
|
|
17681
|
+
try {
|
|
17682
|
+
value = signal.get();
|
|
17683
|
+
} catch {
|
|
17684
|
+
continue;
|
|
17685
|
+
}
|
|
17686
|
+
if (record3(value) && Object.keys(value).length === 2 && typeof value.status === "string" && record3(value.client) && value.client.hostId === hostId2 && "rpc" in value.client) {
|
|
17687
|
+
families.add(members);
|
|
17688
|
+
break;
|
|
17689
|
+
}
|
|
17690
|
+
}
|
|
17691
|
+
}
|
|
17692
|
+
if (families.size !== 1) return null;
|
|
17693
|
+
return { store, family: families.values().next().value };
|
|
17694
|
+
}
|
|
17695
|
+
function resolveRendererHostRpc(discovery, hostId2) {
|
|
17696
|
+
const record3 = (value2) => typeof value2 === "object" && value2 !== null;
|
|
17697
|
+
const signal = discovery.family.get(hostId2)?.value;
|
|
17698
|
+
if (!record3(signal) || typeof signal.get !== "function") return null;
|
|
17699
|
+
let value;
|
|
17700
|
+
try {
|
|
17701
|
+
value = signal.get();
|
|
17702
|
+
} catch {
|
|
17703
|
+
return null;
|
|
17704
|
+
}
|
|
17705
|
+
if (!record3(value) || value.status !== "ready" || !record3(value.client) || value.client.hostId !== hostId2)
|
|
17706
|
+
return null;
|
|
17707
|
+
const rpc = value.client.rpc;
|
|
17708
|
+
return typeof rpc === "function" || record3(rpc) ? rpc : null;
|
|
17709
|
+
}
|
|
17710
|
+
function rendererHostRpcHostIds(discovery) {
|
|
17711
|
+
return [...discovery.family.keys()].filter(
|
|
17712
|
+
(hostId2) => typeof hostId2 === "string"
|
|
17713
|
+
);
|
|
17714
|
+
}
|
|
17715
|
+
|
|
17716
|
+
// packages/desktop-control/src/renderer-host-rpc-routing.ts
|
|
17717
|
+
function installRendererHostRpcRouting(root, target, dependencies) {
|
|
17718
|
+
const existing = target.__codexhostHostRoutingV1;
|
|
17719
|
+
if (existing) return existing;
|
|
17720
|
+
let disposed = false;
|
|
17721
|
+
let discovery = null;
|
|
17722
|
+
const routes = /* @__PURE__ */ new Map();
|
|
17723
|
+
const read = () => {
|
|
17724
|
+
if (disposed) return null;
|
|
17725
|
+
if (!discovery) {
|
|
17726
|
+
const store = dependencies.findStore(root);
|
|
17727
|
+
discovery = store ? dependencies.findFamily(store) : null;
|
|
17728
|
+
}
|
|
17729
|
+
return discovery;
|
|
17730
|
+
};
|
|
17731
|
+
if (!read()) return null;
|
|
17732
|
+
const isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17733
|
+
const externalDrafts = /* @__PURE__ */ new Map();
|
|
17734
|
+
const selectedModels = /* @__PURE__ */ new Map();
|
|
17735
|
+
const prewarmCarrier = (carrier) => {
|
|
17736
|
+
const prefix = "codexhost/plugin-v1@";
|
|
17737
|
+
if (!carrier.startsWith(prefix)) return null;
|
|
17738
|
+
try {
|
|
17739
|
+
const json2 = carrier.slice(prefix.length).replace(/[a-f0-9]{2}/gu, (byte) => String.fromCharCode(Number.parseInt(byte, 16)));
|
|
17740
|
+
const route = JSON.parse(json2);
|
|
17741
|
+
if (!isRecord3(route)) return null;
|
|
17742
|
+
const payload = [...JSON.stringify({ ...route, prewarm: true })].map((character) => character.charCodeAt(0).toString(16).padStart(2, "0")).join("");
|
|
17743
|
+
return `${prefix}${payload}`;
|
|
17744
|
+
} catch {
|
|
17745
|
+
return null;
|
|
17746
|
+
}
|
|
17747
|
+
};
|
|
17748
|
+
const publishDraftWorkspace = (hostId2, cwd) => {
|
|
17749
|
+
if (typeof cwd !== "string" || cwd.length === 0) return;
|
|
17750
|
+
const drafts = isRecord3(target.__codexhostDraftWorkspacesV1) ? target.__codexhostDraftWorkspacesV1 : {};
|
|
17751
|
+
if (drafts[hostId2] === cwd) return;
|
|
17752
|
+
drafts[hostId2] = cwd;
|
|
17753
|
+
Object.defineProperty(target, "__codexhostDraftWorkspacesV1", {
|
|
17754
|
+
configurable: true,
|
|
17755
|
+
value: drafts
|
|
17756
|
+
});
|
|
17757
|
+
if (typeof target.dispatchEvent === "function" && typeof CustomEvent === "function") {
|
|
17758
|
+
target.dispatchEvent(
|
|
17759
|
+
new CustomEvent("codexhost:draft-workspace", { detail: { hostId: hostId2, cwd } })
|
|
17760
|
+
);
|
|
17761
|
+
}
|
|
17762
|
+
};
|
|
17763
|
+
const routeCreationCall = (message) => {
|
|
17764
|
+
if (!Array.isArray(message) || message.length !== 2 || message[0] !== "push") return message;
|
|
17765
|
+
const expression = message[1];
|
|
17766
|
+
if (!Array.isArray(expression) || expression.length !== 4 || expression[0] !== "pipeline")
|
|
17767
|
+
return message;
|
|
17768
|
+
const [, importId, path3, args] = expression;
|
|
17769
|
+
if (!Array.isArray(path3) || path3.length !== 1 || !Array.isArray(args)) return message;
|
|
17770
|
+
const [input, options] = args;
|
|
17771
|
+
if (!isRecord3(input) || !isRecord3(input.collaborationMode)) return message;
|
|
17772
|
+
const settings = input.collaborationMode.settings;
|
|
17773
|
+
if (!isRecord3(settings)) return message;
|
|
17774
|
+
let model2 = null;
|
|
17775
|
+
if (path3[0] === "startConversation") {
|
|
17776
|
+
const draftId = isRecord3(options) ? options.clientThreadId : null;
|
|
17777
|
+
model2 = typeof draftId === "string" ? externalDrafts.get(draftId)?.model ?? null : null;
|
|
17778
|
+
} else if (path3[0] === "prewarmConversation") {
|
|
17779
|
+
if (input.ephemeral !== true) publishDraftWorkspace("local", input.cwd);
|
|
17780
|
+
const selected = selectedModels.get("local");
|
|
17781
|
+
model2 = selected ? prewarmCarrier(selected) : null;
|
|
17782
|
+
}
|
|
17783
|
+
if (!model2) return message;
|
|
17784
|
+
return [
|
|
17785
|
+
"push",
|
|
17786
|
+
[
|
|
17787
|
+
"pipeline",
|
|
17788
|
+
importId,
|
|
17789
|
+
path3,
|
|
17790
|
+
[
|
|
17791
|
+
{
|
|
17792
|
+
...input,
|
|
17793
|
+
collaborationMode: { ...input.collaborationMode, settings: { ...settings, model: model2 } }
|
|
17794
|
+
},
|
|
17795
|
+
...args.slice(1)
|
|
17796
|
+
]
|
|
17797
|
+
]
|
|
17798
|
+
];
|
|
17799
|
+
};
|
|
17800
|
+
const port = dependencies.portPrototype;
|
|
17801
|
+
const originalPostMessage = port.postMessage;
|
|
17802
|
+
const postMessage = function(message, ...rest) {
|
|
17803
|
+
let routed = message;
|
|
17804
|
+
try {
|
|
17805
|
+
routed = disposed ? message : routeCreationCall(message);
|
|
17806
|
+
} catch {
|
|
17807
|
+
routed = message;
|
|
17808
|
+
}
|
|
17809
|
+
return originalPostMessage.call(this, routed, ...rest);
|
|
17810
|
+
};
|
|
17811
|
+
port.postMessage = postMessage;
|
|
17812
|
+
const createRoute = (hostId2, rpc) => {
|
|
17813
|
+
let retired = false;
|
|
17814
|
+
const isCurrent = () => !retired && !disposed && routes.get(hostId2)?.rpc === rpc;
|
|
17815
|
+
const manager = Object.freeze({
|
|
17816
|
+
kind: "main-process-rpc",
|
|
17817
|
+
getHostId: () => hostId2,
|
|
17818
|
+
sendRequest(method, params, options) {
|
|
17819
|
+
if (!isCurrent())
|
|
17820
|
+
return Promise.reject(new Error(`Renderer request manager is retired for ${hostId2}`));
|
|
17821
|
+
return options === void 0 ? rpc.sendRequest(method, params) : rpc.sendRequest(method, params, options);
|
|
17822
|
+
},
|
|
17823
|
+
// The main process broadcasts every app-server notification to its windows,
|
|
17824
|
+
// including codexhost methods Desktop's own notification table drops.
|
|
17825
|
+
addNotificationCallback(methods, listener) {
|
|
17826
|
+
const accepted = new Set(typeof methods === "string" ? [methods] : methods);
|
|
17827
|
+
const onMessage = (event) => {
|
|
17828
|
+
const { source, data } = event;
|
|
17829
|
+
if (source != null && source !== target) return;
|
|
17830
|
+
if (!isRecord3(data) || data.type !== "mcp-notification" || data.hostId !== hostId2 || typeof data.method !== "string" || !accepted.has(data.method) || !isCurrent())
|
|
17831
|
+
return;
|
|
17832
|
+
listener({ method: data.method, params: data.params });
|
|
17833
|
+
};
|
|
17834
|
+
target.addEventListener?.("message", onMessage);
|
|
17835
|
+
return () => target.removeEventListener?.("message", onMessage);
|
|
17836
|
+
}
|
|
17837
|
+
});
|
|
17838
|
+
const clearDrafts = () => {
|
|
17839
|
+
for (const [draftId, draft] of externalDrafts) {
|
|
17840
|
+
if (draft.owner === policy) externalDrafts.delete(draftId);
|
|
17841
|
+
}
|
|
17842
|
+
};
|
|
17843
|
+
const clear = () => isCurrent() ? Promise.resolve(rpc.clearPrewarmedThreads()).then(() => void 0) : Promise.reject(new Error("Renderer request manager is retired"));
|
|
17844
|
+
const policy = Object.freeze({
|
|
17845
|
+
state: "ready",
|
|
17846
|
+
hostId: hostId2,
|
|
17847
|
+
scopedCreation: true,
|
|
17848
|
+
requestTarget: () => {
|
|
17849
|
+
if (!isCurrent()) throw new Error("Renderer request manager is retired");
|
|
17850
|
+
return manager;
|
|
17851
|
+
},
|
|
17852
|
+
select(model2, draftId) {
|
|
17853
|
+
if (!isCurrent()) throw new Error("Renderer request manager is retired");
|
|
17854
|
+
if (model2 !== null && (typeof model2 !== "string" || !model2.startsWith("codexhost/"))) {
|
|
17855
|
+
throw new Error("Draft route Model must be a codexhost transport carrier");
|
|
17856
|
+
}
|
|
17857
|
+
if (draftId === void 0) {
|
|
17858
|
+
if (model2 === null) clearDrafts();
|
|
17859
|
+
} else if (model2 === null) {
|
|
17860
|
+
if (externalDrafts.get(draftId)?.owner === policy) externalDrafts.delete(draftId);
|
|
17861
|
+
} else {
|
|
17862
|
+
if (!draftId.startsWith("client-new-thread:"))
|
|
17863
|
+
throw new Error("External draft route is missing its client Thread identity");
|
|
17864
|
+
externalDrafts.set(draftId, { model: model2, owner: policy });
|
|
17865
|
+
}
|
|
17866
|
+
if ((selectedModels.get(hostId2) ?? null) === model2) return false;
|
|
17867
|
+
if (model2 === null) selectedModels.delete(hostId2);
|
|
17868
|
+
else selectedModels.set(hostId2, model2);
|
|
17869
|
+
void clear().catch(() => void 0);
|
|
17870
|
+
return true;
|
|
17871
|
+
},
|
|
17872
|
+
clear,
|
|
17873
|
+
dispose() {
|
|
17874
|
+
if (retired) return;
|
|
17875
|
+
retired = true;
|
|
17876
|
+
clearDrafts();
|
|
17877
|
+
selectedModels.delete(hostId2);
|
|
17878
|
+
}
|
|
17879
|
+
});
|
|
17880
|
+
return { hostId: hostId2, manager, policy };
|
|
17881
|
+
};
|
|
17882
|
+
const retire = (hostId2) => {
|
|
17883
|
+
const entry = routes.get(hostId2);
|
|
17884
|
+
routes.delete(hostId2);
|
|
17885
|
+
entry?.route.policy.dispose();
|
|
17886
|
+
};
|
|
17887
|
+
const routeFor = (hostId2) => {
|
|
17888
|
+
const current = read();
|
|
17889
|
+
const rpc = current ? dependencies.resolve(current, hostId2) : null;
|
|
17890
|
+
const previous = routes.get(hostId2);
|
|
17891
|
+
if (rpc && previous?.rpc === rpc) return previous.route;
|
|
17892
|
+
retire(hostId2);
|
|
17893
|
+
if (!rpc) return null;
|
|
17894
|
+
const route = createRoute(hostId2, rpc);
|
|
17895
|
+
routes.set(hostId2, { route, rpc });
|
|
17896
|
+
return route;
|
|
17897
|
+
};
|
|
17898
|
+
const publish = (route) => {
|
|
17899
|
+
const policy = route?.policy;
|
|
17900
|
+
if (target.__codexhostDraftPrewarmPolicyV1 === policy) return;
|
|
17901
|
+
Object.defineProperty(target, "__codexhostDraftPrewarmPolicyV1", {
|
|
17902
|
+
configurable: true,
|
|
17903
|
+
value: policy
|
|
17904
|
+
});
|
|
17905
|
+
if (typeof target.dispatchEvent === "function" && typeof CustomEvent === "function") {
|
|
17906
|
+
target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
|
|
17907
|
+
}
|
|
17908
|
+
};
|
|
17909
|
+
const composerHostId = (composer) => {
|
|
17910
|
+
const hostIds = new Set(dependencies.composerHostIds(composer).hostIds);
|
|
17911
|
+
const hostId2 = hostIds.size === 1 ? hostIds.values().next().value : null;
|
|
17912
|
+
return typeof hostId2 === "string" && hostId2 ? hostId2 : null;
|
|
17913
|
+
};
|
|
17914
|
+
const routing = {
|
|
17915
|
+
knownHostIds() {
|
|
17916
|
+
const current = read();
|
|
17917
|
+
return current ? dependencies.hostIds(current) : [];
|
|
17918
|
+
},
|
|
17919
|
+
forHost(hostId2) {
|
|
17920
|
+
return hostId2 && !disposed ? routeFor(hostId2) : null;
|
|
17921
|
+
},
|
|
17922
|
+
hostIdForComposer(composer) {
|
|
17923
|
+
if (disposed) return null;
|
|
17924
|
+
try {
|
|
17925
|
+
return composerHostId(composer);
|
|
17926
|
+
} catch {
|
|
17927
|
+
return null;
|
|
17928
|
+
}
|
|
17929
|
+
},
|
|
17930
|
+
forComposer(composer) {
|
|
17931
|
+
if (disposed) return null;
|
|
17932
|
+
let hostId2;
|
|
17933
|
+
try {
|
|
17934
|
+
hostId2 = composerHostId(composer);
|
|
17935
|
+
} catch {
|
|
17936
|
+
hostId2 = null;
|
|
17937
|
+
}
|
|
17938
|
+
const route = hostId2 ? routeFor(hostId2) : null;
|
|
17939
|
+
if (!composer) publish(route);
|
|
17940
|
+
return route;
|
|
17941
|
+
},
|
|
17942
|
+
dispose() {
|
|
17943
|
+
if (disposed) return;
|
|
17944
|
+
disposed = true;
|
|
17945
|
+
for (const hostId2 of [...routes.keys()]) retire(hostId2);
|
|
17946
|
+
discovery = null;
|
|
17947
|
+
externalDrafts.clear();
|
|
17948
|
+
selectedModels.clear();
|
|
17949
|
+
if (port.postMessage === postMessage) port.postMessage = originalPostMessage;
|
|
17950
|
+
if (target.__codexhostHostRoutingV1 === routing) {
|
|
17951
|
+
delete target.__codexhostHostRoutingV1;
|
|
17952
|
+
publish(null);
|
|
17953
|
+
}
|
|
17954
|
+
}
|
|
17955
|
+
};
|
|
17956
|
+
Object.defineProperty(target, "__codexhostHostRoutingV1", { configurable: true, value: routing });
|
|
17957
|
+
return routing;
|
|
17958
|
+
}
|
|
17959
|
+
|
|
17497
17960
|
// packages/desktop-control/src/renderer-draft-prewarm-policy.ts
|
|
17498
17961
|
var REQUEST_MANAGER_WAIT_TIMEOUT_MS = 6e4;
|
|
17499
17962
|
var REQUEST_MANAGER_POLL_INTERVAL_MS = 25;
|
|
@@ -17505,14 +17968,41 @@ function directRendererInstaller() {
|
|
|
17505
17968
|
const resolveRendererHostManager = ${resolveRendererHostManager.toString()};
|
|
17506
17969
|
const retainRendererHostResponses = ${retainRendererHostResponses.toString()};
|
|
17507
17970
|
const createDraftPrewarmPolicyBridge = ${createDraftPrewarmPolicyBridge.toString()};
|
|
17508
|
-
const
|
|
17509
|
-
|
|
17510
|
-
|
|
17971
|
+
const isolateRendererPrewarmConsumption = ${isolateRendererPrewarmConsumption.toString()};
|
|
17972
|
+
const discover = (root) =>
|
|
17973
|
+
discoverRendererHosts(root, committedReactAncestors, requestManagerFromHookState);
|
|
17974
|
+
const installNative = () => (${installRendererHostRouting.toString()})(
|
|
17975
|
+
document, window, discover,
|
|
17511
17976
|
(discovery, hostId) => resolveRendererHostManager(discovery, hostId, requestManagerFromHookState),
|
|
17512
17977
|
(manager, bridge, hostId, target, prewarmed, isCurrent) => createDraftPrewarmPolicyBridge(
|
|
17513
17978
|
manager, bridge, hostId, target, prewarmed, isCurrent, retainRendererHostResponses,
|
|
17979
|
+
isolateRendererPrewarmConsumption,
|
|
17514
17980
|
),
|
|
17515
17981
|
);
|
|
17982
|
+
const installRpc = () => typeof MessagePort !== 'function' ? null : (${installRendererHostRpcRouting.toString()})(document, window, {
|
|
17983
|
+
findStore: ${findRendererAppScopeStore.toString()},
|
|
17984
|
+
findFamily: ${findRendererHostRpcFamily.toString()},
|
|
17985
|
+
resolve: ${resolveRendererHostRpc.toString()},
|
|
17986
|
+
hostIds: ${rendererHostRpcHostIds.toString()},
|
|
17987
|
+
composerHostIds: (composer) => {
|
|
17988
|
+
const source = composer?.matches?.('[data-codex-composer], [contenteditable="true"][role="textbox"]')
|
|
17989
|
+
? { querySelectorAll: () => [composer] }
|
|
17990
|
+
: (composer ?? document);
|
|
17991
|
+
return discover(source);
|
|
17992
|
+
},
|
|
17993
|
+
portPrototype: MessagePort.prototype,
|
|
17994
|
+
});
|
|
17995
|
+
// Desktop 26.1027 moved AppServerManagers to the main process. Older builds
|
|
17996
|
+
// expose native managers in Renderer hook state; the main-process mode only
|
|
17997
|
+
// applies when none is visible and its per-Host RPC store is identified.
|
|
17998
|
+
const routing = (() => {
|
|
17999
|
+
if (window.__codexhostHostRoutingV1) return window.__codexhostHostRoutingV1;
|
|
18000
|
+
const native = discover(document);
|
|
18001
|
+
if (native.managers.length || native.registries.length) return installNative();
|
|
18002
|
+
const rpc = installRpc();
|
|
18003
|
+
if (rpc) return rpc;
|
|
18004
|
+
throw new Error('Renderer Host request manager is unavailable');
|
|
18005
|
+
})();
|
|
17516
18006
|
// Publish a default draft policy only when its Host is unambiguous. Host
|
|
17517
18007
|
// connections can be ready even when multiple Composers coexist.
|
|
17518
18008
|
const composerRoute = routing.forComposer();
|
|
@@ -17549,6 +18039,114 @@ function installRendererDraftPrewarmPolicyDirect(renderer) {
|
|
|
17549
18039
|
);
|
|
17550
18040
|
}
|
|
17551
18041
|
|
|
18042
|
+
// packages/desktop-control/src/renderer-loaded-modules.ts
|
|
18043
|
+
var record2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18044
|
+
var MAX_MODULES = 4096;
|
|
18045
|
+
function nativeModuleCatalogExpression(urls, complete, owner) {
|
|
18046
|
+
return `Object.defineProperty(globalThis, '__codexhostLoadedModulesV1', {
|
|
18047
|
+
configurable: true,
|
|
18048
|
+
value: Object.freeze({ owner: ${JSON.stringify(owner)}, documentUrl: location.href, complete: ${complete}, urls: Object.freeze(${JSON.stringify(urls)}) })
|
|
18049
|
+
}); void 0`;
|
|
18050
|
+
}
|
|
18051
|
+
async function installRendererLoadedModules(renderer) {
|
|
18052
|
+
const owner = crypto.randomUUID();
|
|
18053
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
18054
|
+
const contextIds = /* @__PURE__ */ new Map();
|
|
18055
|
+
const dirty = /* @__PURE__ */ new Set();
|
|
18056
|
+
let ready = false;
|
|
18057
|
+
let disposed = false;
|
|
18058
|
+
let timer;
|
|
18059
|
+
let publishing = Promise.resolve();
|
|
18060
|
+
const flush = () => {
|
|
18061
|
+
clearTimeout(timer);
|
|
18062
|
+
timer = void 0;
|
|
18063
|
+
const pending = [...dirty];
|
|
18064
|
+
dirty.clear();
|
|
18065
|
+
publishing = publishing.catch(() => void 0).then(async () => {
|
|
18066
|
+
for (const uniqueId of pending) {
|
|
18067
|
+
const context = contexts.get(uniqueId);
|
|
18068
|
+
if (!context || disposed) continue;
|
|
18069
|
+
const response = await renderer.command("Runtime.evaluate", {
|
|
18070
|
+
expression: nativeModuleCatalogExpression([...context.urls], context.complete, owner),
|
|
18071
|
+
uniqueContextId: uniqueId
|
|
18072
|
+
});
|
|
18073
|
+
if (record2(response) && record2(response.exceptionDetails))
|
|
18074
|
+
throw new Error("Loaded Renderer module catalog publication failed");
|
|
18075
|
+
}
|
|
18076
|
+
});
|
|
18077
|
+
return publishing;
|
|
18078
|
+
};
|
|
18079
|
+
const schedule = (uniqueId) => {
|
|
18080
|
+
dirty.add(uniqueId);
|
|
18081
|
+
if (ready && timer === void 0)
|
|
18082
|
+
timer = setTimeout(() => {
|
|
18083
|
+
void flush().catch((error51) => {
|
|
18084
|
+
console.error("Could not publish loaded Renderer modules", error51);
|
|
18085
|
+
});
|
|
18086
|
+
}, 10);
|
|
18087
|
+
};
|
|
18088
|
+
const remove = (id) => {
|
|
18089
|
+
const uniqueId = contextIds.get(id);
|
|
18090
|
+
contextIds.delete(id);
|
|
18091
|
+
if (uniqueId) {
|
|
18092
|
+
contexts.delete(uniqueId);
|
|
18093
|
+
dirty.delete(uniqueId);
|
|
18094
|
+
}
|
|
18095
|
+
};
|
|
18096
|
+
const listeners = [
|
|
18097
|
+
renderer.on("Runtime.executionContextCreated", (params) => {
|
|
18098
|
+
const context = record2(params) ? params.context : null;
|
|
18099
|
+
if (!record2(context) || typeof context.id !== "number" || typeof context.uniqueId !== "string" || !record2(context.auxData) || context.auxData.isDefault !== true)
|
|
18100
|
+
return;
|
|
18101
|
+
contextIds.set(context.id, context.uniqueId);
|
|
18102
|
+
contexts.set(context.uniqueId, { urls: /* @__PURE__ */ new Set(), complete: true });
|
|
18103
|
+
schedule(context.uniqueId);
|
|
18104
|
+
}),
|
|
18105
|
+
renderer.on("Runtime.executionContextDestroyed", (params) => {
|
|
18106
|
+
if (record2(params) && typeof params.executionContextId === "number")
|
|
18107
|
+
remove(params.executionContextId);
|
|
18108
|
+
}),
|
|
18109
|
+
renderer.on("Runtime.executionContextsCleared", () => {
|
|
18110
|
+
contextIds.clear();
|
|
18111
|
+
contexts.clear();
|
|
18112
|
+
dirty.clear();
|
|
18113
|
+
}),
|
|
18114
|
+
renderer.on("Debugger.scriptParsed", (params) => {
|
|
18115
|
+
if (!record2(params) || params.isModule !== true || params.hasSourceURL === true || typeof params.url !== "string" || typeof params.executionContextId !== "number")
|
|
18116
|
+
return;
|
|
18117
|
+
const uniqueId = contextIds.get(params.executionContextId);
|
|
18118
|
+
const context = uniqueId ? contexts.get(uniqueId) : null;
|
|
18119
|
+
if (!context || !uniqueId || context.urls.has(params.url)) return;
|
|
18120
|
+
if (context.urls.size >= MAX_MODULES) context.complete = false;
|
|
18121
|
+
else context.urls.add(params.url);
|
|
18122
|
+
schedule(uniqueId);
|
|
18123
|
+
})
|
|
18124
|
+
];
|
|
18125
|
+
const dispose = () => {
|
|
18126
|
+
disposed = true;
|
|
18127
|
+
clearTimeout(timer);
|
|
18128
|
+
for (const unsubscribe of listeners) unsubscribe();
|
|
18129
|
+
for (const uniqueId of contexts.keys())
|
|
18130
|
+
void renderer.command("Runtime.evaluate", {
|
|
18131
|
+
expression: `if (globalThis.__codexhostLoadedModulesV1 === undefined || globalThis.__codexhostLoadedModulesV1?.owner === ${JSON.stringify(owner)}) { ${nativeModuleCatalogExpression([], false, owner)} }`,
|
|
18132
|
+
uniqueContextId: uniqueId
|
|
18133
|
+
}).catch(() => void 0);
|
|
18134
|
+
contexts.clear();
|
|
18135
|
+
contextIds.clear();
|
|
18136
|
+
dirty.clear();
|
|
18137
|
+
};
|
|
18138
|
+
try {
|
|
18139
|
+
await renderer.command("Runtime.enable");
|
|
18140
|
+
await renderer.command("Debugger.enable");
|
|
18141
|
+
ready = true;
|
|
18142
|
+
await flush();
|
|
18143
|
+
return dispose;
|
|
18144
|
+
} catch (error51) {
|
|
18145
|
+
dispose();
|
|
18146
|
+
throw error51;
|
|
18147
|
+
}
|
|
18148
|
+
}
|
|
18149
|
+
|
|
17552
18150
|
// packages/desktop-control/src/renderer-cdp-control-session.ts
|
|
17553
18151
|
function isRecord2(value) {
|
|
17554
18152
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -17693,21 +18291,23 @@ async function waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs
|
|
|
17693
18291
|
}
|
|
17694
18292
|
async function installTarget(target, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations) {
|
|
17695
18293
|
const renderer = await operations.connect(target.webSocketDebuggerUrl);
|
|
18294
|
+
let disposeModules;
|
|
17696
18295
|
try {
|
|
17697
|
-
await renderer
|
|
18296
|
+
disposeModules = await installRendererLoadedModules(renderer);
|
|
17698
18297
|
await renderer.command("Page.enable");
|
|
17699
18298
|
await renderer.command("Page.addScriptToEvaluateOnNewDocument", { source: rendererSource });
|
|
17700
18299
|
await evaluateSource(renderer, rendererSource);
|
|
17701
18300
|
const draftPrewarmPolicy = await operations.installDraftPrewarmPolicy(renderer);
|
|
17702
18301
|
const binding = await waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs);
|
|
17703
|
-
return { renderer, snapshot: { target, draftPrewarmPolicy, binding } };
|
|
18302
|
+
return { renderer, snapshot: { target, draftPrewarmPolicy, binding }, disposeModules };
|
|
17704
18303
|
} catch (error51) {
|
|
18304
|
+
disposeModules?.();
|
|
17705
18305
|
renderer.close();
|
|
17706
18306
|
throw error51;
|
|
17707
18307
|
}
|
|
17708
18308
|
}
|
|
17709
18309
|
var InstalledRendererCdpControlSession = class {
|
|
17710
|
-
constructor(renderer, rendererCdpEndpoint2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot) {
|
|
18310
|
+
constructor(renderer, rendererCdpEndpoint2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules) {
|
|
17711
18311
|
this.renderer = renderer;
|
|
17712
18312
|
this.rendererCdpEndpoint = rendererCdpEndpoint2;
|
|
17713
18313
|
this.rendererSource = rendererSource;
|
|
@@ -17716,6 +18316,7 @@ var InstalledRendererCdpControlSession = class {
|
|
|
17716
18316
|
this.pollIntervalMs = pollIntervalMs;
|
|
17717
18317
|
this.operations = operations;
|
|
17718
18318
|
this.currentSnapshot = currentSnapshot;
|
|
18319
|
+
this.disposeModules = disposeModules;
|
|
17719
18320
|
}
|
|
17720
18321
|
renderer;
|
|
17721
18322
|
rendererCdpEndpoint;
|
|
@@ -17725,6 +18326,7 @@ var InstalledRendererCdpControlSession = class {
|
|
|
17725
18326
|
pollIntervalMs;
|
|
17726
18327
|
operations;
|
|
17727
18328
|
currentSnapshot;
|
|
18329
|
+
disposeModules;
|
|
17728
18330
|
#closed = false;
|
|
17729
18331
|
get snapshot() {
|
|
17730
18332
|
return this.currentSnapshot;
|
|
@@ -17747,8 +18349,10 @@ var InstalledRendererCdpControlSession = class {
|
|
|
17747
18349
|
this.pollIntervalMs,
|
|
17748
18350
|
this.operations
|
|
17749
18351
|
);
|
|
18352
|
+
this.disposeModules();
|
|
17750
18353
|
this.renderer.close();
|
|
17751
18354
|
this.renderer = replacement.renderer;
|
|
18355
|
+
this.disposeModules = replacement.disposeModules;
|
|
17752
18356
|
this.currentSnapshot = replacement.snapshot;
|
|
17753
18357
|
return this.currentSnapshot;
|
|
17754
18358
|
}
|
|
@@ -17773,8 +18377,10 @@ var InstalledRendererCdpControlSession = class {
|
|
|
17773
18377
|
this.pollIntervalMs,
|
|
17774
18378
|
this.operations
|
|
17775
18379
|
);
|
|
18380
|
+
this.disposeModules();
|
|
17776
18381
|
this.renderer.close();
|
|
17777
18382
|
this.renderer = replacement.renderer;
|
|
18383
|
+
this.disposeModules = replacement.disposeModules;
|
|
17778
18384
|
this.currentSnapshot = replacement.snapshot;
|
|
17779
18385
|
return this.currentSnapshot;
|
|
17780
18386
|
}
|
|
@@ -17791,6 +18397,7 @@ var InstalledRendererCdpControlSession = class {
|
|
|
17791
18397
|
close() {
|
|
17792
18398
|
if (this.#closed) return;
|
|
17793
18399
|
this.#closed = true;
|
|
18400
|
+
this.disposeModules();
|
|
17794
18401
|
this.renderer.close();
|
|
17795
18402
|
}
|
|
17796
18403
|
};
|
|
@@ -17828,7 +18435,8 @@ async function createRendererCdpControlSession(options) {
|
|
|
17828
18435
|
timeoutMs,
|
|
17829
18436
|
pollIntervalMs,
|
|
17830
18437
|
operations,
|
|
17831
|
-
installed.snapshot
|
|
18438
|
+
installed.snapshot,
|
|
18439
|
+
installed.disposeModules
|
|
17832
18440
|
);
|
|
17833
18441
|
}
|
|
17834
18442
|
function installRendererCdpControlSession(options) {
|