@karlorz/codexhost-cli-win32-x64 0.15.0-1 → 0.16.1-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 +60 -25
- package/app/console-web.js +143 -57
- package/app/cpa-live-voice-hook.js +58 -24
- package/app/desktop-controller.mjs +649 -53
- package/app/host-runtime.mjs +10959 -10075
- package/app/plugins/antigravity/plugin.mjs +73 -29
- package/app/plugins/claude-code/plugin.mjs +104 -72
- package/app/plugins/codebuddy/plugin.mjs +113 -34
- package/app/plugins/codex-usage/plugin.mjs +65 -31
- package/app/plugins/copilot/plugin.mjs +73 -29
- package/app/plugins/cursor-cli/plugin.mjs +70 -26
- package/app/plugins/deepseek-harness/plugin.mjs +88 -34
- package/app/plugins/grok/plugin.mjs +1505 -502
- package/app/plugins/hermes/plugin.mjs +68 -24
- package/app/plugins/kimi-code/plugin.mjs +70 -26
- package/app/plugins/kiro-cli/plugin.mjs +70 -26
- package/app/plugins/omp/plugin.mjs +71 -27
- package/app/plugins/opencode/plugin.mjs +84 -30
- package/app/plugins/pi/plugin.mjs +87 -31
- package/app/plugins/qoder/plugin.mjs +96 -52
- package/app/plugins/qoder-cn/plugin.mjs +96 -52
- package/app/plugins/workbuddy/plugin.mjs +113 -34
- package/app/plugins/zcode/plugin.mjs +144 -47
- package/app/renderer-extension.js +1843 -213
- 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
|
@@ -4915,8 +4915,8 @@ function az_default() {
|
|
|
4915
4915
|
}
|
|
4916
4916
|
|
|
4917
4917
|
// node_modules/zod/v4/locales/be.js
|
|
4918
|
-
function getBelarusianPlural(
|
|
4919
|
-
const absCount = Math.abs(
|
|
4918
|
+
function getBelarusianPlural(count3, one, few, many) {
|
|
4919
|
+
const absCount = Math.abs(count3);
|
|
4920
4920
|
const lastDigit = absCount % 10;
|
|
4921
4921
|
const lastTwoDigits = absCount % 100;
|
|
4922
4922
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -6994,8 +6994,8 @@ function hu_default() {
|
|
|
6994
6994
|
}
|
|
6995
6995
|
|
|
6996
6996
|
// node_modules/zod/v4/locales/hy.js
|
|
6997
|
-
function getArmenianPlural(
|
|
6998
|
-
return Math.abs(
|
|
6997
|
+
function getArmenianPlural(count3, one, many) {
|
|
6998
|
+
return Math.abs(count3) === 1 ? one : many;
|
|
6999
6999
|
}
|
|
7000
7000
|
function withDefiniteArticle(word) {
|
|
7001
7001
|
if (!word)
|
|
@@ -9123,8 +9123,8 @@ function ro_default() {
|
|
|
9123
9123
|
}
|
|
9124
9124
|
|
|
9125
9125
|
// node_modules/zod/v4/locales/ru.js
|
|
9126
|
-
function getRussianPlural(
|
|
9127
|
-
const absCount = Math.abs(
|
|
9126
|
+
function getRussianPlural(count3, one, few, many) {
|
|
9127
|
+
const absCount = Math.abs(count3);
|
|
9128
9128
|
const lastDigit = absCount % 10;
|
|
9129
9129
|
const lastTwoDigits = absCount % 100;
|
|
9130
9130
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -14793,6 +14793,33 @@ function date4(params) {
|
|
|
14793
14793
|
// node_modules/zod/v4/classic/external.js
|
|
14794
14794
|
config(en_default());
|
|
14795
14795
|
|
|
14796
|
+
// packages/shared-contracts/dist/goals.js
|
|
14797
|
+
var harnessGoalStatusSchema = external_exports.enum([
|
|
14798
|
+
"active",
|
|
14799
|
+
"paused",
|
|
14800
|
+
"blocked",
|
|
14801
|
+
"usageLimited",
|
|
14802
|
+
"budgetLimited",
|
|
14803
|
+
"complete"
|
|
14804
|
+
]);
|
|
14805
|
+
var count = external_exports.number().int().nonnegative().safe();
|
|
14806
|
+
var harnessGoalSchema = external_exports.object({
|
|
14807
|
+
objective: external_exports.string().min(1),
|
|
14808
|
+
status: harnessGoalStatusSchema,
|
|
14809
|
+
tokenBudget: count.positive().nullable(),
|
|
14810
|
+
tokensUsed: count,
|
|
14811
|
+
timeUsedSeconds: count,
|
|
14812
|
+
createdAt: count,
|
|
14813
|
+
updatedAt: count
|
|
14814
|
+
});
|
|
14815
|
+
var goalOriginSchema = external_exports.enum(["user", "automatic"]).nullable();
|
|
14816
|
+
var harnessGoalSetSchema = external_exports.object({
|
|
14817
|
+
objective: external_exports.string().min(1).optional(),
|
|
14818
|
+
status: external_exports.enum(["active", "paused"]).optional(),
|
|
14819
|
+
tokenBudget: count.positive().nullable().optional(),
|
|
14820
|
+
origin: goalOriginSchema
|
|
14821
|
+
});
|
|
14822
|
+
|
|
14796
14823
|
// packages/shared-contracts/dist/delegation-read.js
|
|
14797
14824
|
var REMOTE_THREAD_REPLY_MAX_BYTES = 16 * 1024 * 1024;
|
|
14798
14825
|
var REMOTE_THREAD_CONTROL_TIMEOUT_MS = 4e4;
|
|
@@ -14924,7 +14951,7 @@ var modelPriceDefaultResultSchema = external_exports.strictObject({
|
|
|
14924
14951
|
|
|
14925
14952
|
// packages/shared-contracts/dist/usage-statistics.js
|
|
14926
14953
|
var USAGE_STATISTICS_RANGES = ["today", "7d", "30d", "90d", "all"];
|
|
14927
|
-
var
|
|
14954
|
+
var count2 = external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
14928
14955
|
var localDate = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/u);
|
|
14929
14956
|
var harness = external_exports.string().min(1).max(128);
|
|
14930
14957
|
var model = external_exports.string().min(1).max(512);
|
|
@@ -14947,22 +14974,24 @@ var usageStatisticsParamsSchema = external_exports.strictObject({
|
|
|
14947
14974
|
date: localDate.optional()
|
|
14948
14975
|
});
|
|
14949
14976
|
var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
14950
|
-
requests:
|
|
14951
|
-
inputTokens:
|
|
14952
|
-
cachedInputTokens:
|
|
14953
|
-
cacheWriteInputTokens:
|
|
14954
|
-
cacheKnownInputTokens:
|
|
14955
|
-
|
|
14956
|
-
|
|
14977
|
+
requests: count2,
|
|
14978
|
+
inputTokens: count2,
|
|
14979
|
+
cachedInputTokens: count2,
|
|
14980
|
+
cacheWriteInputTokens: count2,
|
|
14981
|
+
cacheKnownInputTokens: count2,
|
|
14982
|
+
cacheHitCachedInputTokens: count2,
|
|
14983
|
+
cacheHitInputTokens: count2,
|
|
14984
|
+
outputTokens: count2,
|
|
14985
|
+
reasoningOutputTokens: count2,
|
|
14957
14986
|
/** USD at the public price, summed over the priced requests only. */
|
|
14958
14987
|
costUsd: external_exports.number().finite().min(0),
|
|
14959
14988
|
/** Requests without a price (or the cache data the price needs); not in `costUsd`. */
|
|
14960
|
-
unpricedRequests:
|
|
14989
|
+
unpricedRequests: count2,
|
|
14961
14990
|
/**
|
|
14962
14991
|
* Requests whose storage gave no token counts: counted as requests, with neither tokens nor
|
|
14963
14992
|
* cost, and not as unpriced.
|
|
14964
14993
|
*/
|
|
14965
|
-
unmeteredRequests:
|
|
14994
|
+
unmeteredRequests: count2
|
|
14966
14995
|
});
|
|
14967
14996
|
var totals = usageStatisticsTotalsSchema.shape;
|
|
14968
14997
|
var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
@@ -14973,8 +15002,8 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
|
14973
15002
|
title: external_exports.string().min(1).max(200).optional(),
|
|
14974
15003
|
/** Models the session used, most requests first. */
|
|
14975
15004
|
models: external_exports.array(model).max(16),
|
|
14976
|
-
firstAtMs:
|
|
14977
|
-
lastAtMs:
|
|
15005
|
+
firstAtMs: count2,
|
|
15006
|
+
lastAtMs: count2,
|
|
14978
15007
|
...totals
|
|
14979
15008
|
});
|
|
14980
15009
|
var usageStatisticsResultSchema = external_exports.strictObject({
|
|
@@ -14992,7 +15021,7 @@ var usageStatisticsResultSchema = external_exports.strictObject({
|
|
|
14992
15021
|
date: localDate.nullable()
|
|
14993
15022
|
}),
|
|
14994
15023
|
/** Reading of native storage: incomplete while the first read, or a refresh, is under way. */
|
|
14995
|
-
reading: external_exports.strictObject({ complete: external_exports.boolean(), sources:
|
|
15024
|
+
reading: external_exports.strictObject({ complete: external_exports.boolean(), sources: count2, read: count2 }),
|
|
14996
15025
|
/** Harnesses whose storage could not be read; their part is missing, the rest is complete. */
|
|
14997
15026
|
failures: external_exports.array(external_exports.strictObject({ harness, message: external_exports.string().max(2048) })).max(256),
|
|
14998
15027
|
/** Every value seen in the range, ignoring the filters, to choose filters from. */
|
|
@@ -15012,8 +15041,8 @@ var usageStatisticsResultSchema = external_exports.strictObject({
|
|
|
15012
15041
|
harness,
|
|
15013
15042
|
model: model.nullable(),
|
|
15014
15043
|
credits: external_exports.number().finite().min(0),
|
|
15015
|
-
reportedRequests:
|
|
15016
|
-
requests:
|
|
15044
|
+
reportedRequests: count2,
|
|
15045
|
+
requests: count2
|
|
15017
15046
|
})).max(4096).optional(),
|
|
15018
15047
|
/** All filters applied. */
|
|
15019
15048
|
totals: usageStatisticsTotalsSchema,
|
|
@@ -15030,7 +15059,7 @@ var usageStatisticsResultSchema = external_exports.strictObject({
|
|
|
15030
15059
|
model: model.nullable(),
|
|
15031
15060
|
...totals,
|
|
15032
15061
|
/** Requests priced by what the Harness recorded they cost, not by a price list. */
|
|
15033
|
-
harnessPricedRequests:
|
|
15062
|
+
harnessPricedRequests: count2
|
|
15034
15063
|
})).max(4096),
|
|
15035
15064
|
byProject: external_exports.array(external_exports.strictObject({ project: project.nullable(), ...totals })).max(4096),
|
|
15036
15065
|
/**
|
|
@@ -15644,7 +15673,9 @@ var harnessModelCatalogSchema = external_exports.object({
|
|
|
15644
15673
|
var harnessHistoryCapabilitiesSchema = external_exports.object({
|
|
15645
15674
|
fork: external_exports.boolean(),
|
|
15646
15675
|
forkAcrossCwd: external_exports.boolean(),
|
|
15647
|
-
rollbackLastTurn: external_exports.boolean()
|
|
15676
|
+
rollbackLastTurn: external_exports.boolean(),
|
|
15677
|
+
/** Remove the selected checkpoint's Turn and every later Turn, without restoring files. */
|
|
15678
|
+
rollbackToCheckpoint: external_exports.boolean().optional()
|
|
15648
15679
|
}).strict().refine((history) => history.fork || !history.forkAcrossCwd, {
|
|
15649
15680
|
path: ["forkAcrossCwd"],
|
|
15650
15681
|
message: "Cross-cwd Fork requires exact history Fork support"
|
|
@@ -15882,7 +15913,10 @@ var harnessPluginRouteSchema = external_exports.object({
|
|
|
15882
15913
|
harnessId: harnessPluginIdSchema,
|
|
15883
15914
|
model: harnessModelRefSchema.optional(),
|
|
15884
15915
|
thinkingOptionId: harnessThinkingOptionIdSchema.optional(),
|
|
15885
|
-
permissionModeId: harnessPermissionModeIdSchema.optional()
|
|
15916
|
+
permissionModeId: harnessPermissionModeIdSchema.optional(),
|
|
15917
|
+
/** A draft prewarm create: stays unsubmitted until the user's first Turn.
|
|
15918
|
+
* Desktop forwards only the Model of a main-process prewarm to thread/start. */
|
|
15919
|
+
prewarm: external_exports.literal(true).optional()
|
|
15886
15920
|
}).strict();
|
|
15887
15921
|
|
|
15888
15922
|
// packages/shared-contracts/dist/harness-launch-settings.js
|
|
@@ -16894,8 +16928,99 @@ function retainRendererHostResponses(client, hostId2, target) {
|
|
|
16894
16928
|
};
|
|
16895
16929
|
}
|
|
16896
16930
|
|
|
16931
|
+
// packages/desktop-control/src/renderer-prewarm-consumption.ts
|
|
16932
|
+
function isolateRendererPrewarmConsumption(manager, discardExternal) {
|
|
16933
|
+
const record3 = (value) => value !== null && typeof value === "object";
|
|
16934
|
+
if (!record3(manager) || !record3(manager.threadCreation)) return null;
|
|
16935
|
+
const creation = manager.threadCreation;
|
|
16936
|
+
const originalStart = manager.startConversation;
|
|
16937
|
+
const original = creation.createConversation;
|
|
16938
|
+
const params = creation.params;
|
|
16939
|
+
if (typeof originalStart !== "function" || typeof original !== "function" || !record3(params))
|
|
16940
|
+
return null;
|
|
16941
|
+
const prototype = Object.getPrototypeOf(creation);
|
|
16942
|
+
if (!record3(prototype) || typeof prototype.constructor !== "function") return null;
|
|
16943
|
+
if (Object.keys(creation).some((key) => key !== "params" && typeof creation[key] !== "function") || /#[A-Za-z_$]/u.test(Function.prototype.toString.call(prototype.constructor)))
|
|
16944
|
+
return null;
|
|
16945
|
+
const pool = params.prewarmedThreadManager;
|
|
16946
|
+
if (!record3(pool) || typeof pool.hasPrewarmedThread !== "function" || typeof pool.consumePrewarmedThread !== "function" || typeof pool.deletePrewarmedThread !== "function")
|
|
16947
|
+
return null;
|
|
16948
|
+
const consume = pool.consumePrewarmedThread;
|
|
16949
|
+
const hasPrewarm = pool.hasPrewarmedThread;
|
|
16950
|
+
const draftModels = /* @__PURE__ */ new Map();
|
|
16951
|
+
const draftIdentity = /* @__PURE__ */ Symbol("codexhost draft creation");
|
|
16952
|
+
const external = (model2) => typeof model2 === "string" && model2.startsWith("codexhost/");
|
|
16953
|
+
const routedStart = function(input, options, ...args) {
|
|
16954
|
+
const draftId = record3(options) ? options.clientThreadId : null;
|
|
16955
|
+
const mode = record3(input) && record3(input.collaborationMode) ? input.collaborationMode : null;
|
|
16956
|
+
const origin = mode ? Reflect.get(mode, draftIdentity) : void 0;
|
|
16957
|
+
if (mode && record3(mode.settings) && external(mode.settings.model))
|
|
16958
|
+
return originalStart.call(this, input, options, ...args);
|
|
16959
|
+
const model2 = (typeof draftId === "string" ? draftModels.get(draftId) : void 0) ?? (typeof origin === "string" ? draftModels.get(origin) : void 0);
|
|
16960
|
+
if (!model2) return originalStart.call(this, input, options, ...args);
|
|
16961
|
+
if (!record3(input) || !record3(input.collaborationMode) || !record3(input.collaborationMode.settings))
|
|
16962
|
+
throw new Error("External draft creation is missing its native Model settings");
|
|
16963
|
+
const routed = {
|
|
16964
|
+
...input,
|
|
16965
|
+
collaborationMode: {
|
|
16966
|
+
...input.collaborationMode,
|
|
16967
|
+
settings: { ...input.collaborationMode.settings, model: model2 }
|
|
16968
|
+
}
|
|
16969
|
+
};
|
|
16970
|
+
return originalStart.call(this, routed, options, ...args);
|
|
16971
|
+
};
|
|
16972
|
+
const wrapped = function(input, ...args) {
|
|
16973
|
+
const mode = record3(input) && record3(input.collaborationMode) ? input.collaborationMode : null;
|
|
16974
|
+
const expected = mode && record3(mode.settings) ? mode.settings.model : null;
|
|
16975
|
+
const scopedPool = Object.create(pool);
|
|
16976
|
+
scopedPool.hasPrewarmedThread = (...parameters) => hasPrewarm.apply(pool, parameters);
|
|
16977
|
+
scopedPool.consumePrewarmedThread = async (...consumeArgs) => {
|
|
16978
|
+
const warmed = await consume.apply(pool, consumeArgs);
|
|
16979
|
+
if (!record3(warmed) || !record3(warmed.response)) return warmed;
|
|
16980
|
+
const response = warmed.response;
|
|
16981
|
+
if (!external(expected) && !external(response.model)) return warmed;
|
|
16982
|
+
if (external(expected) && expected === response.model) return warmed;
|
|
16983
|
+
if (record3(response.thread) && typeof response.thread.id === "string") {
|
|
16984
|
+
const threadId = response.thread.id;
|
|
16985
|
+
if (external(response.model)) discardExternal(threadId);
|
|
16986
|
+
else
|
|
16987
|
+
void Promise.resolve().then(() => pool.deletePrewarmedThread(threadId)).catch(() => void 0);
|
|
16988
|
+
}
|
|
16989
|
+
return null;
|
|
16990
|
+
};
|
|
16991
|
+
const invocation = Object.create(creation);
|
|
16992
|
+
invocation.params = { ...params, prewarmedThreadManager: scopedPool };
|
|
16993
|
+
return original.call(invocation, input, ...args);
|
|
16994
|
+
};
|
|
16995
|
+
creation.createConversation = wrapped;
|
|
16996
|
+
manager.startConversation = routedStart;
|
|
16997
|
+
return {
|
|
16998
|
+
selectDraft(draftId, model2, creationModes = []) {
|
|
16999
|
+
if (draftId === void 0) {
|
|
17000
|
+
if (model2 === null) draftModels.clear();
|
|
17001
|
+
} else if (model2 === null) draftModels.delete(draftId);
|
|
17002
|
+
else {
|
|
17003
|
+
if (!draftId.startsWith("client-new-thread:") || !external(model2))
|
|
17004
|
+
throw new Error("External draft route is missing its client Thread identity");
|
|
17005
|
+
draftModels.set(draftId, model2);
|
|
17006
|
+
for (const mode of creationModes)
|
|
17007
|
+
Object.defineProperty(mode, draftIdentity, {
|
|
17008
|
+
configurable: true,
|
|
17009
|
+
enumerable: true,
|
|
17010
|
+
value: draftId
|
|
17011
|
+
});
|
|
17012
|
+
}
|
|
17013
|
+
},
|
|
17014
|
+
dispose() {
|
|
17015
|
+
draftModels.clear();
|
|
17016
|
+
if (manager.startConversation === routedStart) manager.startConversation = originalStart;
|
|
17017
|
+
if (creation.createConversation === wrapped) creation.createConversation = original;
|
|
17018
|
+
}
|
|
17019
|
+
};
|
|
17020
|
+
}
|
|
17021
|
+
|
|
16897
17022
|
// packages/desktop-control/src/renderer-draft-prewarm-runtime.ts
|
|
16898
|
-
function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewarmedThreadManager, isCurrentManager, retainResponses = retainRendererHostResponses) {
|
|
17023
|
+
function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewarmedThreadManager, isCurrentManager, retainResponses = retainRendererHostResponses, isolateConsumption = isolateRendererPrewarmConsumption) {
|
|
16899
17024
|
let disposed = false;
|
|
16900
17025
|
const originalSend = bridge.sendRequest;
|
|
16901
17026
|
const originalPrewarm = bridge.prewarmThreadStart;
|
|
@@ -17276,26 +17401,16 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17276
17401
|
if (threadId && knownOfficialThreadIds.has(threadId)) return false;
|
|
17277
17402
|
return selectedModel !== null && (method.startsWith("thread/") || method.startsWith("turn/") || method.startsWith("review/"));
|
|
17278
17403
|
};
|
|
17279
|
-
const routeThreadStart = (parameters) => {
|
|
17280
|
-
if (!isRecord3(parameters) || parameters.ephemeral === true) {
|
|
17281
|
-
return parameters;
|
|
17282
|
-
}
|
|
17283
|
-
return {
|
|
17284
|
-
...parameters,
|
|
17285
|
-
...selectedModel === null ? {} : { model: selectedModel }
|
|
17286
|
-
};
|
|
17287
|
-
};
|
|
17288
17404
|
const routedSend = (method, parameters, options) => {
|
|
17289
17405
|
if (method === "turn/start" || method === "thread/resume" || method === "codexhost/thread/command/execute") {
|
|
17290
17406
|
const threadId = threadIdFromParameters(parameters);
|
|
17291
17407
|
if (threadId) externalPrewarms.delete(threadId);
|
|
17292
17408
|
}
|
|
17293
|
-
const routedParameters = method === "thread/start" ? routeThreadStart(parameters) : parameters;
|
|
17294
17409
|
const sendBridged = () => initializeBridge().then(
|
|
17295
|
-
() => enqueueBridgeRequest(method,
|
|
17410
|
+
() => enqueueBridgeRequest(method, parameters, options)
|
|
17296
17411
|
);
|
|
17297
|
-
const sendDirect = () => options === void 0 ? originalSend.call(bridge, method,
|
|
17298
|
-
const unresolvedThreadId = shouldResolveThreadOwnership(method,
|
|
17412
|
+
const sendDirect = () => options === void 0 ? originalSend.call(bridge, method, parameters) : originalSend.call(bridge, method, parameters, options);
|
|
17413
|
+
const unresolvedThreadId = shouldResolveThreadOwnership(method, parameters);
|
|
17299
17414
|
if (unresolvedThreadId) {
|
|
17300
17415
|
return resolveThreadOwnership(unresolvedThreadId).then(
|
|
17301
17416
|
(owner) => owner === "external" ? sendBridged() : sendDirect(),
|
|
@@ -17311,7 +17426,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17311
17426
|
}
|
|
17312
17427
|
);
|
|
17313
17428
|
}
|
|
17314
|
-
return shouldUseBridge(method,
|
|
17429
|
+
return shouldUseBridge(method, parameters) ? sendBridged() : sendDirect();
|
|
17315
17430
|
};
|
|
17316
17431
|
const publishDraftWorkspace = (parameters) => {
|
|
17317
17432
|
if (!isRecord3(parameters) || parameters.ephemeral === true) return;
|
|
@@ -17341,10 +17456,10 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17341
17456
|
const discardExternalPrewarms = () => {
|
|
17342
17457
|
for (const threadId of externalPrewarms) discardExternalPrewarm(threadId);
|
|
17343
17458
|
};
|
|
17459
|
+
const restoreConsumption = isolateConsumption(manager, discardExternalPrewarm);
|
|
17344
17460
|
const routedPrewarm = (parameters, options) => {
|
|
17345
|
-
const
|
|
17346
|
-
const
|
|
17347
|
-
const routedParameters = external ? { ...routed, codexhostPrewarm: true } : routed;
|
|
17461
|
+
const external = isRecord3(parameters) && parameters.ephemeral !== true && typeof parameters.model === "string" && parameters.model.startsWith("codexhost/");
|
|
17462
|
+
const routedParameters = external ? { ...parameters, codexhostPrewarm: true } : parameters;
|
|
17348
17463
|
const generation = prewarmGeneration;
|
|
17349
17464
|
publishDraftWorkspace(routedParameters);
|
|
17350
17465
|
const pending = shouldUseBridge("thread/start", routedParameters) ? routedSend("thread/start", routedParameters, options) : options === void 0 ? originalPrewarm.call(bridge, routedParameters) : originalPrewarm.call(bridge, routedParameters, options);
|
|
@@ -17397,6 +17512,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17397
17512
|
const policy = Object.freeze({
|
|
17398
17513
|
state: "ready",
|
|
17399
17514
|
hostId: hostId2,
|
|
17515
|
+
scopedCreation: restoreConsumption !== null,
|
|
17400
17516
|
owns(candidateManager, candidate, candidateHostId, candidatePrewarmedThreadManager, requiresCurrentManager) {
|
|
17401
17517
|
return !disposed && candidateManager === manager && candidate === bridge && candidateHostId === hostId2 && candidatePrewarmedThreadManager === prewarmedThreadManager && requiresCurrentManager === !!isCurrentManager;
|
|
17402
17518
|
},
|
|
@@ -17410,12 +17526,13 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17410
17526
|
throw new Error("Renderer request manager is retired");
|
|
17411
17527
|
return selectedModel;
|
|
17412
17528
|
},
|
|
17413
|
-
select(model2) {
|
|
17529
|
+
select(model2, draftId, creationModes) {
|
|
17414
17530
|
if (disposed || isCurrentManager && !isCurrentManager())
|
|
17415
17531
|
throw new Error("Renderer request manager is retired");
|
|
17416
17532
|
if (model2 !== null && (typeof model2 !== "string" || !model2.startsWith("codexhost/"))) {
|
|
17417
17533
|
throw new Error("Draft route Model must be a codexhost transport carrier");
|
|
17418
17534
|
}
|
|
17535
|
+
restoreConsumption?.selectDraft(draftId, model2, creationModes);
|
|
17419
17536
|
if (selectedModel === model2) return false;
|
|
17420
17537
|
selectedModel = model2;
|
|
17421
17538
|
prewarmGeneration += 1;
|
|
@@ -17436,6 +17553,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17436
17553
|
disposed = true;
|
|
17437
17554
|
prewarmGeneration += 1;
|
|
17438
17555
|
retireResponses();
|
|
17556
|
+
restoreConsumption?.dispose();
|
|
17439
17557
|
if (bridge.sendRequest === routedSend) bridge.sendRequest = originalSend;
|
|
17440
17558
|
if (bridge.prewarmThreadStart === routedPrewarm) {
|
|
17441
17559
|
bridge.prewarmThreadStart = originalPrewarm;
|
|
@@ -17472,14 +17590,14 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target, prewar
|
|
|
17472
17590
|
|
|
17473
17591
|
// packages/desktop-control/src/renderer-host-discovery.ts
|
|
17474
17592
|
function requestManagerFromHookState(value, hostId2) {
|
|
17475
|
-
const
|
|
17593
|
+
const record3 = (candidate) => typeof candidate === "object" && candidate !== null;
|
|
17476
17594
|
const manager = (candidate) => {
|
|
17477
|
-
if (!
|
|
17595
|
+
if (!record3(candidate) || !record3(candidate.requestClient) || !record3(candidate.prewarmedThreadManager))
|
|
17478
17596
|
return null;
|
|
17479
17597
|
const bridge = candidate.requestClient;
|
|
17480
17598
|
return typeof candidate.sendRequest === "function" && typeof bridge.sendRequest === "function" && typeof bridge.prewarmThreadStart === "function" && typeof bridge.enqueueRequest === "function" && typeof candidate.prewarmedThreadManager.discardAllPrewarmedThreads === "function" ? candidate : null;
|
|
17481
17599
|
};
|
|
17482
|
-
if (!
|
|
17600
|
+
if (!record3(value)) return null;
|
|
17483
17601
|
const direct = manager(value) ?? manager(value.manager);
|
|
17484
17602
|
if (direct) return direct;
|
|
17485
17603
|
if (!hostId2 || typeof value.addManager !== "function" || typeof value.getForHostId !== "function")
|
|
@@ -17689,6 +17807,339 @@ function installRendererHostRouting(root, target, discover, resolve, createPolic
|
|
|
17689
17807
|
return routing;
|
|
17690
17808
|
}
|
|
17691
17809
|
|
|
17810
|
+
// packages/desktop-control/src/renderer-host-rpc-discovery.ts
|
|
17811
|
+
function findRendererAppScopeStore(root) {
|
|
17812
|
+
const MAX_VISITED_FIBERS = 5e4;
|
|
17813
|
+
const record3 = (value) => typeof value === "object" && value !== null;
|
|
17814
|
+
const container = root.getElementById?.("root");
|
|
17815
|
+
if (!record3(container)) return null;
|
|
17816
|
+
const key = Object.getOwnPropertyNames(container).find(
|
|
17817
|
+
(name) => name.startsWith("__reactContainer$")
|
|
17818
|
+
);
|
|
17819
|
+
const first = key ? container[key] : null;
|
|
17820
|
+
if (!record3(first)) return null;
|
|
17821
|
+
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";
|
|
17822
|
+
const stack = [first];
|
|
17823
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17824
|
+
while (stack.length && seen.size < MAX_VISITED_FIBERS) {
|
|
17825
|
+
const fiber = stack.pop();
|
|
17826
|
+
if (seen.has(fiber)) continue;
|
|
17827
|
+
seen.add(fiber);
|
|
17828
|
+
let hook = fiber.memoizedState;
|
|
17829
|
+
for (let index = 0; record3(hook) && "next" in hook && index < 150; index += 1) {
|
|
17830
|
+
const state = hook.memoizedState;
|
|
17831
|
+
const handle = record3(state) ? state.current : null;
|
|
17832
|
+
if (isScopeHandle(handle)) {
|
|
17833
|
+
let node = handle.node;
|
|
17834
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
17835
|
+
while (record3(node.parent) && !nodes.has(node.parent)) {
|
|
17836
|
+
nodes.add(node);
|
|
17837
|
+
node = node.parent;
|
|
17838
|
+
}
|
|
17839
|
+
const bindings = node.familyBindings;
|
|
17840
|
+
return record3(bindings) && typeof bindings.get === "function" && typeof bindings.entries === "function" ? node : null;
|
|
17841
|
+
}
|
|
17842
|
+
hook = hook.next;
|
|
17843
|
+
}
|
|
17844
|
+
if (record3(fiber.sibling)) stack.push(fiber.sibling);
|
|
17845
|
+
if (record3(fiber.child)) stack.push(fiber.child);
|
|
17846
|
+
}
|
|
17847
|
+
return null;
|
|
17848
|
+
}
|
|
17849
|
+
function findRendererHostRpcFamily(store) {
|
|
17850
|
+
const record3 = (value) => typeof value === "object" && value !== null;
|
|
17851
|
+
const families = /* @__PURE__ */ new Set();
|
|
17852
|
+
for (const [definition, members] of store.familyBindings) {
|
|
17853
|
+
if (!record3(definition) || definition.kind !== "signal-family") continue;
|
|
17854
|
+
if (!record3(members) || typeof members.get !== "function") continue;
|
|
17855
|
+
for (const [hostId2, member] of members) {
|
|
17856
|
+
if (typeof hostId2 !== "string" || !record3(member)) continue;
|
|
17857
|
+
const signal = member.value;
|
|
17858
|
+
if (!record3(signal) || typeof signal.get !== "function") continue;
|
|
17859
|
+
let value;
|
|
17860
|
+
try {
|
|
17861
|
+
value = signal.get();
|
|
17862
|
+
} catch {
|
|
17863
|
+
continue;
|
|
17864
|
+
}
|
|
17865
|
+
if (record3(value) && Object.keys(value).length === 2 && typeof value.status === "string" && record3(value.client) && value.client.hostId === hostId2 && "rpc" in value.client) {
|
|
17866
|
+
families.add(members);
|
|
17867
|
+
break;
|
|
17868
|
+
}
|
|
17869
|
+
}
|
|
17870
|
+
}
|
|
17871
|
+
if (families.size !== 1) return null;
|
|
17872
|
+
return { store, family: families.values().next().value };
|
|
17873
|
+
}
|
|
17874
|
+
function resolveRendererHostRpc(discovery, hostId2) {
|
|
17875
|
+
const record3 = (value2) => typeof value2 === "object" && value2 !== null;
|
|
17876
|
+
const signal = discovery.family.get(hostId2)?.value;
|
|
17877
|
+
if (!record3(signal) || typeof signal.get !== "function") return null;
|
|
17878
|
+
let value;
|
|
17879
|
+
try {
|
|
17880
|
+
value = signal.get();
|
|
17881
|
+
} catch {
|
|
17882
|
+
return null;
|
|
17883
|
+
}
|
|
17884
|
+
if (!record3(value) || value.status !== "ready" || !record3(value.client) || value.client.hostId !== hostId2)
|
|
17885
|
+
return null;
|
|
17886
|
+
const rpc = value.client.rpc;
|
|
17887
|
+
return typeof rpc === "function" || record3(rpc) ? rpc : null;
|
|
17888
|
+
}
|
|
17889
|
+
function rendererHostRpcHostIds(discovery) {
|
|
17890
|
+
return [...discovery.family.keys()].filter(
|
|
17891
|
+
(hostId2) => typeof hostId2 === "string"
|
|
17892
|
+
);
|
|
17893
|
+
}
|
|
17894
|
+
|
|
17895
|
+
// packages/desktop-control/src/renderer-host-rpc-routing.ts
|
|
17896
|
+
function installRendererHostRpcRouting(root, target, dependencies) {
|
|
17897
|
+
const existing = target.__codexhostHostRoutingV1;
|
|
17898
|
+
if (existing) return existing;
|
|
17899
|
+
let disposed = false;
|
|
17900
|
+
let discovery = null;
|
|
17901
|
+
const routes = /* @__PURE__ */ new Map();
|
|
17902
|
+
const read = () => {
|
|
17903
|
+
if (disposed) return null;
|
|
17904
|
+
if (!discovery) {
|
|
17905
|
+
const store = dependencies.findStore(root);
|
|
17906
|
+
discovery = store ? dependencies.findFamily(store) : null;
|
|
17907
|
+
}
|
|
17908
|
+
return discovery;
|
|
17909
|
+
};
|
|
17910
|
+
if (!read()) return null;
|
|
17911
|
+
const isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17912
|
+
const externalDrafts = /* @__PURE__ */ new Map();
|
|
17913
|
+
const selectedModels = /* @__PURE__ */ new Map();
|
|
17914
|
+
const prewarmCarrier = (carrier) => {
|
|
17915
|
+
const prefix = "codexhost/plugin-v1@";
|
|
17916
|
+
if (!carrier.startsWith(prefix)) return null;
|
|
17917
|
+
try {
|
|
17918
|
+
const json2 = carrier.slice(prefix.length).replace(/[a-f0-9]{2}/gu, (byte) => String.fromCharCode(Number.parseInt(byte, 16)));
|
|
17919
|
+
const route = JSON.parse(json2);
|
|
17920
|
+
if (!isRecord3(route)) return null;
|
|
17921
|
+
const payload = [...JSON.stringify({ ...route, prewarm: true })].map((character) => character.charCodeAt(0).toString(16).padStart(2, "0")).join("");
|
|
17922
|
+
return `${prefix}${payload}`;
|
|
17923
|
+
} catch {
|
|
17924
|
+
return null;
|
|
17925
|
+
}
|
|
17926
|
+
};
|
|
17927
|
+
const publishDraftWorkspace = (hostId2, cwd) => {
|
|
17928
|
+
if (typeof cwd !== "string" || cwd.length === 0) return;
|
|
17929
|
+
const drafts = isRecord3(target.__codexhostDraftWorkspacesV1) ? target.__codexhostDraftWorkspacesV1 : {};
|
|
17930
|
+
if (drafts[hostId2] === cwd) return;
|
|
17931
|
+
drafts[hostId2] = cwd;
|
|
17932
|
+
Object.defineProperty(target, "__codexhostDraftWorkspacesV1", {
|
|
17933
|
+
configurable: true,
|
|
17934
|
+
value: drafts
|
|
17935
|
+
});
|
|
17936
|
+
if (typeof target.dispatchEvent === "function" && typeof CustomEvent === "function") {
|
|
17937
|
+
target.dispatchEvent(
|
|
17938
|
+
new CustomEvent("codexhost:draft-workspace", { detail: { hostId: hostId2, cwd } })
|
|
17939
|
+
);
|
|
17940
|
+
}
|
|
17941
|
+
};
|
|
17942
|
+
const routeCreationCall = (message) => {
|
|
17943
|
+
if (!Array.isArray(message) || message.length !== 2 || message[0] !== "push") return message;
|
|
17944
|
+
const expression = message[1];
|
|
17945
|
+
if (!Array.isArray(expression) || expression.length !== 4 || expression[0] !== "pipeline")
|
|
17946
|
+
return message;
|
|
17947
|
+
const [, importId, path5, args] = expression;
|
|
17948
|
+
if (!Array.isArray(path5) || path5.length !== 1 || !Array.isArray(args)) return message;
|
|
17949
|
+
const [input, options] = args;
|
|
17950
|
+
if (!isRecord3(input) || !isRecord3(input.collaborationMode)) return message;
|
|
17951
|
+
const settings = input.collaborationMode.settings;
|
|
17952
|
+
if (!isRecord3(settings)) return message;
|
|
17953
|
+
let model2 = null;
|
|
17954
|
+
if (path5[0] === "startConversation") {
|
|
17955
|
+
const draftId = isRecord3(options) ? options.clientThreadId : null;
|
|
17956
|
+
model2 = typeof draftId === "string" ? externalDrafts.get(draftId)?.model ?? null : null;
|
|
17957
|
+
} else if (path5[0] === "prewarmConversation") {
|
|
17958
|
+
if (input.ephemeral !== true) publishDraftWorkspace("local", input.cwd);
|
|
17959
|
+
const selected = selectedModels.get("local");
|
|
17960
|
+
model2 = selected ? prewarmCarrier(selected) : null;
|
|
17961
|
+
}
|
|
17962
|
+
if (!model2) return message;
|
|
17963
|
+
return [
|
|
17964
|
+
"push",
|
|
17965
|
+
[
|
|
17966
|
+
"pipeline",
|
|
17967
|
+
importId,
|
|
17968
|
+
path5,
|
|
17969
|
+
[
|
|
17970
|
+
{
|
|
17971
|
+
...input,
|
|
17972
|
+
collaborationMode: { ...input.collaborationMode, settings: { ...settings, model: model2 } }
|
|
17973
|
+
},
|
|
17974
|
+
...args.slice(1)
|
|
17975
|
+
]
|
|
17976
|
+
]
|
|
17977
|
+
];
|
|
17978
|
+
};
|
|
17979
|
+
const port = dependencies.portPrototype;
|
|
17980
|
+
const originalPostMessage = port.postMessage;
|
|
17981
|
+
const postMessage = function(message, ...rest) {
|
|
17982
|
+
let routed = message;
|
|
17983
|
+
try {
|
|
17984
|
+
routed = disposed ? message : routeCreationCall(message);
|
|
17985
|
+
} catch {
|
|
17986
|
+
routed = message;
|
|
17987
|
+
}
|
|
17988
|
+
return originalPostMessage.call(this, routed, ...rest);
|
|
17989
|
+
};
|
|
17990
|
+
port.postMessage = postMessage;
|
|
17991
|
+
const createRoute = (hostId2, rpc) => {
|
|
17992
|
+
let retired = false;
|
|
17993
|
+
const isCurrent = () => !retired && !disposed && routes.get(hostId2)?.rpc === rpc;
|
|
17994
|
+
const manager = Object.freeze({
|
|
17995
|
+
kind: "main-process-rpc",
|
|
17996
|
+
getHostId: () => hostId2,
|
|
17997
|
+
sendRequest(method, params, options) {
|
|
17998
|
+
if (!isCurrent())
|
|
17999
|
+
return Promise.reject(new Error(`Renderer request manager is retired for ${hostId2}`));
|
|
18000
|
+
return options === void 0 ? rpc.sendRequest(method, params) : rpc.sendRequest(method, params, options);
|
|
18001
|
+
},
|
|
18002
|
+
// The main process broadcasts every app-server notification to its windows,
|
|
18003
|
+
// including codexhost methods Desktop's own notification table drops.
|
|
18004
|
+
addNotificationCallback(methods, listener) {
|
|
18005
|
+
const accepted = new Set(typeof methods === "string" ? [methods] : methods);
|
|
18006
|
+
const onMessage = (event) => {
|
|
18007
|
+
const { source, data } = event;
|
|
18008
|
+
if (source != null && source !== target) return;
|
|
18009
|
+
if (!isRecord3(data) || data.type !== "mcp-notification" || data.hostId !== hostId2 || typeof data.method !== "string" || !accepted.has(data.method) || !isCurrent())
|
|
18010
|
+
return;
|
|
18011
|
+
listener({ method: data.method, params: data.params });
|
|
18012
|
+
};
|
|
18013
|
+
target.addEventListener?.("message", onMessage);
|
|
18014
|
+
return () => target.removeEventListener?.("message", onMessage);
|
|
18015
|
+
}
|
|
18016
|
+
});
|
|
18017
|
+
const clearDrafts = () => {
|
|
18018
|
+
for (const [draftId, draft] of externalDrafts) {
|
|
18019
|
+
if (draft.owner === policy) externalDrafts.delete(draftId);
|
|
18020
|
+
}
|
|
18021
|
+
};
|
|
18022
|
+
const clear = () => isCurrent() ? Promise.resolve(rpc.clearPrewarmedThreads()).then(() => void 0) : Promise.reject(new Error("Renderer request manager is retired"));
|
|
18023
|
+
const policy = Object.freeze({
|
|
18024
|
+
state: "ready",
|
|
18025
|
+
hostId: hostId2,
|
|
18026
|
+
scopedCreation: true,
|
|
18027
|
+
requestTarget: () => {
|
|
18028
|
+
if (!isCurrent()) throw new Error("Renderer request manager is retired");
|
|
18029
|
+
return manager;
|
|
18030
|
+
},
|
|
18031
|
+
selectedModel() {
|
|
18032
|
+
if (!isCurrent()) throw new Error("Renderer request manager is retired");
|
|
18033
|
+
return selectedModels.get(hostId2) ?? null;
|
|
18034
|
+
},
|
|
18035
|
+
select(model2, draftId) {
|
|
18036
|
+
if (!isCurrent()) throw new Error("Renderer request manager is retired");
|
|
18037
|
+
if (model2 !== null && (typeof model2 !== "string" || !model2.startsWith("codexhost/"))) {
|
|
18038
|
+
throw new Error("Draft route Model must be a codexhost transport carrier");
|
|
18039
|
+
}
|
|
18040
|
+
if (draftId === void 0) {
|
|
18041
|
+
if (model2 === null) clearDrafts();
|
|
18042
|
+
} else if (model2 === null) {
|
|
18043
|
+
if (externalDrafts.get(draftId)?.owner === policy) externalDrafts.delete(draftId);
|
|
18044
|
+
} else {
|
|
18045
|
+
if (!draftId.startsWith("client-new-thread:"))
|
|
18046
|
+
throw new Error("External draft route is missing its client Thread identity");
|
|
18047
|
+
externalDrafts.set(draftId, { model: model2, owner: policy });
|
|
18048
|
+
}
|
|
18049
|
+
if ((selectedModels.get(hostId2) ?? null) === model2) return false;
|
|
18050
|
+
if (model2 === null) selectedModels.delete(hostId2);
|
|
18051
|
+
else selectedModels.set(hostId2, model2);
|
|
18052
|
+
void clear().catch(() => void 0);
|
|
18053
|
+
return true;
|
|
18054
|
+
},
|
|
18055
|
+
clear,
|
|
18056
|
+
dispose() {
|
|
18057
|
+
if (retired) return;
|
|
18058
|
+
retired = true;
|
|
18059
|
+
clearDrafts();
|
|
18060
|
+
selectedModels.delete(hostId2);
|
|
18061
|
+
}
|
|
18062
|
+
});
|
|
18063
|
+
return { hostId: hostId2, manager, policy };
|
|
18064
|
+
};
|
|
18065
|
+
const retire = (hostId2) => {
|
|
18066
|
+
const entry = routes.get(hostId2);
|
|
18067
|
+
routes.delete(hostId2);
|
|
18068
|
+
entry?.route.policy.dispose();
|
|
18069
|
+
};
|
|
18070
|
+
const routeFor = (hostId2) => {
|
|
18071
|
+
const current = read();
|
|
18072
|
+
const rpc = current ? dependencies.resolve(current, hostId2) : null;
|
|
18073
|
+
const previous = routes.get(hostId2);
|
|
18074
|
+
if (rpc && previous?.rpc === rpc) return previous.route;
|
|
18075
|
+
retire(hostId2);
|
|
18076
|
+
if (!rpc) return null;
|
|
18077
|
+
const route = createRoute(hostId2, rpc);
|
|
18078
|
+
routes.set(hostId2, { route, rpc });
|
|
18079
|
+
return route;
|
|
18080
|
+
};
|
|
18081
|
+
const publish = (route) => {
|
|
18082
|
+
const policy = route?.policy;
|
|
18083
|
+
if (target.__codexhostDraftPrewarmPolicyV1 === policy) return;
|
|
18084
|
+
Object.defineProperty(target, "__codexhostDraftPrewarmPolicyV1", {
|
|
18085
|
+
configurable: true,
|
|
18086
|
+
value: policy
|
|
18087
|
+
});
|
|
18088
|
+
if (typeof target.dispatchEvent === "function" && typeof CustomEvent === "function") {
|
|
18089
|
+
target.dispatchEvent(new CustomEvent("codexhost:draft-prewarm-policy-changed"));
|
|
18090
|
+
}
|
|
18091
|
+
};
|
|
18092
|
+
const composerHostId = (composer) => {
|
|
18093
|
+
const hostIds = new Set(dependencies.composerHostIds(composer).hostIds);
|
|
18094
|
+
const hostId2 = hostIds.size === 1 ? hostIds.values().next().value : null;
|
|
18095
|
+
return typeof hostId2 === "string" && hostId2 ? hostId2 : null;
|
|
18096
|
+
};
|
|
18097
|
+
const routing = {
|
|
18098
|
+
knownHostIds() {
|
|
18099
|
+
const current = read();
|
|
18100
|
+
return current ? dependencies.hostIds(current) : [];
|
|
18101
|
+
},
|
|
18102
|
+
forHost(hostId2) {
|
|
18103
|
+
return hostId2 && !disposed ? routeFor(hostId2) : null;
|
|
18104
|
+
},
|
|
18105
|
+
hostIdForComposer(composer) {
|
|
18106
|
+
if (disposed) return null;
|
|
18107
|
+
try {
|
|
18108
|
+
return composerHostId(composer);
|
|
18109
|
+
} catch {
|
|
18110
|
+
return null;
|
|
18111
|
+
}
|
|
18112
|
+
},
|
|
18113
|
+
forComposer(composer) {
|
|
18114
|
+
if (disposed) return null;
|
|
18115
|
+
let hostId2;
|
|
18116
|
+
try {
|
|
18117
|
+
hostId2 = composerHostId(composer);
|
|
18118
|
+
} catch {
|
|
18119
|
+
hostId2 = null;
|
|
18120
|
+
}
|
|
18121
|
+
const route = hostId2 ? routeFor(hostId2) : null;
|
|
18122
|
+
if (!composer) publish(route);
|
|
18123
|
+
return route;
|
|
18124
|
+
},
|
|
18125
|
+
dispose() {
|
|
18126
|
+
if (disposed) return;
|
|
18127
|
+
disposed = true;
|
|
18128
|
+
for (const hostId2 of [...routes.keys()]) retire(hostId2);
|
|
18129
|
+
discovery = null;
|
|
18130
|
+
externalDrafts.clear();
|
|
18131
|
+
selectedModels.clear();
|
|
18132
|
+
if (port.postMessage === postMessage) port.postMessage = originalPostMessage;
|
|
18133
|
+
if (target.__codexhostHostRoutingV1 === routing) {
|
|
18134
|
+
delete target.__codexhostHostRoutingV1;
|
|
18135
|
+
publish(null);
|
|
18136
|
+
}
|
|
18137
|
+
}
|
|
18138
|
+
};
|
|
18139
|
+
Object.defineProperty(target, "__codexhostHostRoutingV1", { configurable: true, value: routing });
|
|
18140
|
+
return routing;
|
|
18141
|
+
}
|
|
18142
|
+
|
|
17692
18143
|
// packages/desktop-control/src/renderer-draft-prewarm-policy.ts
|
|
17693
18144
|
var REQUEST_MANAGER_WAIT_TIMEOUT_MS = 6e4;
|
|
17694
18145
|
var REQUEST_MANAGER_POLL_INTERVAL_MS = 25;
|
|
@@ -17700,14 +18151,41 @@ function directRendererInstaller() {
|
|
|
17700
18151
|
const resolveRendererHostManager = ${resolveRendererHostManager.toString()};
|
|
17701
18152
|
const retainRendererHostResponses = ${retainRendererHostResponses.toString()};
|
|
17702
18153
|
const createDraftPrewarmPolicyBridge = ${createDraftPrewarmPolicyBridge.toString()};
|
|
17703
|
-
const
|
|
17704
|
-
|
|
17705
|
-
|
|
18154
|
+
const isolateRendererPrewarmConsumption = ${isolateRendererPrewarmConsumption.toString()};
|
|
18155
|
+
const discover = (root) =>
|
|
18156
|
+
discoverRendererHosts(root, committedReactAncestors, requestManagerFromHookState);
|
|
18157
|
+
const installNative = () => (${installRendererHostRouting.toString()})(
|
|
18158
|
+
document, window, discover,
|
|
17706
18159
|
(discovery, hostId) => resolveRendererHostManager(discovery, hostId, requestManagerFromHookState),
|
|
17707
18160
|
(manager, bridge, hostId, target, prewarmed, isCurrent) => createDraftPrewarmPolicyBridge(
|
|
17708
18161
|
manager, bridge, hostId, target, prewarmed, isCurrent, retainRendererHostResponses,
|
|
18162
|
+
isolateRendererPrewarmConsumption,
|
|
17709
18163
|
),
|
|
17710
18164
|
);
|
|
18165
|
+
const installRpc = () => typeof MessagePort !== 'function' ? null : (${installRendererHostRpcRouting.toString()})(document, window, {
|
|
18166
|
+
findStore: ${findRendererAppScopeStore.toString()},
|
|
18167
|
+
findFamily: ${findRendererHostRpcFamily.toString()},
|
|
18168
|
+
resolve: ${resolveRendererHostRpc.toString()},
|
|
18169
|
+
hostIds: ${rendererHostRpcHostIds.toString()},
|
|
18170
|
+
composerHostIds: (composer) => {
|
|
18171
|
+
const source = composer?.matches?.('[data-codex-composer], [contenteditable="true"][role="textbox"]')
|
|
18172
|
+
? { querySelectorAll: () => [composer] }
|
|
18173
|
+
: (composer ?? document);
|
|
18174
|
+
return discover(source);
|
|
18175
|
+
},
|
|
18176
|
+
portPrototype: MessagePort.prototype,
|
|
18177
|
+
});
|
|
18178
|
+
// Desktop 26.1027 moved AppServerManagers to the main process. Older builds
|
|
18179
|
+
// expose native managers in Renderer hook state; the main-process mode only
|
|
18180
|
+
// applies when none is visible and its per-Host RPC store is identified.
|
|
18181
|
+
const routing = (() => {
|
|
18182
|
+
if (window.__codexhostHostRoutingV1) return window.__codexhostHostRoutingV1;
|
|
18183
|
+
const native = discover(document);
|
|
18184
|
+
if (native.managers.length || native.registries.length) return installNative();
|
|
18185
|
+
const rpc = installRpc();
|
|
18186
|
+
if (rpc) return rpc;
|
|
18187
|
+
throw new Error('Renderer Host request manager is unavailable');
|
|
18188
|
+
})();
|
|
17711
18189
|
// Publish a default draft policy only when its Host is unambiguous. Host
|
|
17712
18190
|
// connections can be ready even when multiple Composers coexist.
|
|
17713
18191
|
const composerRoute = routing.forComposer();
|
|
@@ -17744,6 +18222,114 @@ function installRendererDraftPrewarmPolicyDirect(renderer) {
|
|
|
17744
18222
|
);
|
|
17745
18223
|
}
|
|
17746
18224
|
|
|
18225
|
+
// packages/desktop-control/src/renderer-loaded-modules.ts
|
|
18226
|
+
var record2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18227
|
+
var MAX_MODULES = 4096;
|
|
18228
|
+
function nativeModuleCatalogExpression(urls, complete, owner) {
|
|
18229
|
+
return `Object.defineProperty(globalThis, '__codexhostLoadedModulesV1', {
|
|
18230
|
+
configurable: true,
|
|
18231
|
+
value: Object.freeze({ owner: ${JSON.stringify(owner)}, documentUrl: location.href, complete: ${complete}, urls: Object.freeze(${JSON.stringify(urls)}) })
|
|
18232
|
+
}); void 0`;
|
|
18233
|
+
}
|
|
18234
|
+
async function installRendererLoadedModules(renderer) {
|
|
18235
|
+
const owner = crypto.randomUUID();
|
|
18236
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
18237
|
+
const contextIds = /* @__PURE__ */ new Map();
|
|
18238
|
+
const dirty = /* @__PURE__ */ new Set();
|
|
18239
|
+
let ready = false;
|
|
18240
|
+
let disposed = false;
|
|
18241
|
+
let timer;
|
|
18242
|
+
let publishing = Promise.resolve();
|
|
18243
|
+
const flush = () => {
|
|
18244
|
+
clearTimeout(timer);
|
|
18245
|
+
timer = void 0;
|
|
18246
|
+
const pending = [...dirty];
|
|
18247
|
+
dirty.clear();
|
|
18248
|
+
publishing = publishing.catch(() => void 0).then(async () => {
|
|
18249
|
+
for (const uniqueId of pending) {
|
|
18250
|
+
const context = contexts.get(uniqueId);
|
|
18251
|
+
if (!context || disposed) continue;
|
|
18252
|
+
const response = await renderer.command("Runtime.evaluate", {
|
|
18253
|
+
expression: nativeModuleCatalogExpression([...context.urls], context.complete, owner),
|
|
18254
|
+
uniqueContextId: uniqueId
|
|
18255
|
+
});
|
|
18256
|
+
if (record2(response) && record2(response.exceptionDetails))
|
|
18257
|
+
throw new Error("Loaded Renderer module catalog publication failed");
|
|
18258
|
+
}
|
|
18259
|
+
});
|
|
18260
|
+
return publishing;
|
|
18261
|
+
};
|
|
18262
|
+
const schedule = (uniqueId) => {
|
|
18263
|
+
dirty.add(uniqueId);
|
|
18264
|
+
if (ready && timer === void 0)
|
|
18265
|
+
timer = setTimeout(() => {
|
|
18266
|
+
void flush().catch((error51) => {
|
|
18267
|
+
console.error("Could not publish loaded Renderer modules", error51);
|
|
18268
|
+
});
|
|
18269
|
+
}, 10);
|
|
18270
|
+
};
|
|
18271
|
+
const remove = (id) => {
|
|
18272
|
+
const uniqueId = contextIds.get(id);
|
|
18273
|
+
contextIds.delete(id);
|
|
18274
|
+
if (uniqueId) {
|
|
18275
|
+
contexts.delete(uniqueId);
|
|
18276
|
+
dirty.delete(uniqueId);
|
|
18277
|
+
}
|
|
18278
|
+
};
|
|
18279
|
+
const listeners = [
|
|
18280
|
+
renderer.on("Runtime.executionContextCreated", (params) => {
|
|
18281
|
+
const context = record2(params) ? params.context : null;
|
|
18282
|
+
if (!record2(context) || typeof context.id !== "number" || typeof context.uniqueId !== "string" || !record2(context.auxData) || context.auxData.isDefault !== true)
|
|
18283
|
+
return;
|
|
18284
|
+
contextIds.set(context.id, context.uniqueId);
|
|
18285
|
+
contexts.set(context.uniqueId, { urls: /* @__PURE__ */ new Set(), complete: true });
|
|
18286
|
+
schedule(context.uniqueId);
|
|
18287
|
+
}),
|
|
18288
|
+
renderer.on("Runtime.executionContextDestroyed", (params) => {
|
|
18289
|
+
if (record2(params) && typeof params.executionContextId === "number")
|
|
18290
|
+
remove(params.executionContextId);
|
|
18291
|
+
}),
|
|
18292
|
+
renderer.on("Runtime.executionContextsCleared", () => {
|
|
18293
|
+
contextIds.clear();
|
|
18294
|
+
contexts.clear();
|
|
18295
|
+
dirty.clear();
|
|
18296
|
+
}),
|
|
18297
|
+
renderer.on("Debugger.scriptParsed", (params) => {
|
|
18298
|
+
if (!record2(params) || params.isModule !== true || params.hasSourceURL === true || typeof params.url !== "string" || typeof params.executionContextId !== "number")
|
|
18299
|
+
return;
|
|
18300
|
+
const uniqueId = contextIds.get(params.executionContextId);
|
|
18301
|
+
const context = uniqueId ? contexts.get(uniqueId) : null;
|
|
18302
|
+
if (!context || !uniqueId || context.urls.has(params.url)) return;
|
|
18303
|
+
if (context.urls.size >= MAX_MODULES) context.complete = false;
|
|
18304
|
+
else context.urls.add(params.url);
|
|
18305
|
+
schedule(uniqueId);
|
|
18306
|
+
})
|
|
18307
|
+
];
|
|
18308
|
+
const dispose = () => {
|
|
18309
|
+
disposed = true;
|
|
18310
|
+
clearTimeout(timer);
|
|
18311
|
+
for (const unsubscribe of listeners) unsubscribe();
|
|
18312
|
+
for (const uniqueId of contexts.keys())
|
|
18313
|
+
void renderer.command("Runtime.evaluate", {
|
|
18314
|
+
expression: `if (globalThis.__codexhostLoadedModulesV1 === undefined || globalThis.__codexhostLoadedModulesV1?.owner === ${JSON.stringify(owner)}) { ${nativeModuleCatalogExpression([], false, owner)} }`,
|
|
18315
|
+
uniqueContextId: uniqueId
|
|
18316
|
+
}).catch(() => void 0);
|
|
18317
|
+
contexts.clear();
|
|
18318
|
+
contextIds.clear();
|
|
18319
|
+
dirty.clear();
|
|
18320
|
+
};
|
|
18321
|
+
try {
|
|
18322
|
+
await renderer.command("Runtime.enable");
|
|
18323
|
+
await renderer.command("Debugger.enable");
|
|
18324
|
+
ready = true;
|
|
18325
|
+
await flush();
|
|
18326
|
+
return dispose;
|
|
18327
|
+
} catch (error51) {
|
|
18328
|
+
dispose();
|
|
18329
|
+
throw error51;
|
|
18330
|
+
}
|
|
18331
|
+
}
|
|
18332
|
+
|
|
17747
18333
|
// packages/desktop-control/src/renderer-cdp-control-session.ts
|
|
17748
18334
|
function isRecord2(value) {
|
|
17749
18335
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -17988,21 +18574,23 @@ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents
|
|
|
17988
18574
|
}
|
|
17989
18575
|
async function installTarget(target, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations) {
|
|
17990
18576
|
const renderer = await operations.connect(target.webSocketDebuggerUrl);
|
|
18577
|
+
let disposeModules;
|
|
17991
18578
|
try {
|
|
17992
|
-
await renderer
|
|
18579
|
+
disposeModules = await installRendererLoadedModules(renderer);
|
|
17993
18580
|
await renderer.command("Page.enable");
|
|
17994
18581
|
await renderer.command("Page.addScriptToEvaluateOnNewDocument", { source: rendererSource });
|
|
17995
18582
|
await evaluateSource(renderer, rendererSource);
|
|
17996
18583
|
const draftPrewarmPolicy = await operations.installDraftPrewarmPolicy(renderer);
|
|
17997
18584
|
const binding = await waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs);
|
|
17998
|
-
return { renderer, snapshot: { target, draftPrewarmPolicy, binding } };
|
|
18585
|
+
return { renderer, snapshot: { target, draftPrewarmPolicy, binding }, disposeModules };
|
|
17999
18586
|
} catch (error51) {
|
|
18587
|
+
disposeModules?.();
|
|
18000
18588
|
renderer.close();
|
|
18001
18589
|
throw error51;
|
|
18002
18590
|
}
|
|
18003
18591
|
}
|
|
18004
18592
|
var InstalledRendererCdpControlSession = class {
|
|
18005
|
-
constructor(renderer, rendererCdpEndpoint2, rendererSource, overlayHookSource, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot) {
|
|
18593
|
+
constructor(renderer, rendererCdpEndpoint2, rendererSource, overlayHookSource, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules) {
|
|
18006
18594
|
this.renderer = renderer;
|
|
18007
18595
|
this.rendererCdpEndpoint = rendererCdpEndpoint2;
|
|
18008
18596
|
this.rendererSource = rendererSource;
|
|
@@ -18012,6 +18600,7 @@ var InstalledRendererCdpControlSession = class {
|
|
|
18012
18600
|
this.pollIntervalMs = pollIntervalMs;
|
|
18013
18601
|
this.operations = operations;
|
|
18014
18602
|
this.currentSnapshot = currentSnapshot;
|
|
18603
|
+
this.disposeModules = disposeModules;
|
|
18015
18604
|
}
|
|
18016
18605
|
renderer;
|
|
18017
18606
|
rendererCdpEndpoint;
|
|
@@ -18022,6 +18611,7 @@ var InstalledRendererCdpControlSession = class {
|
|
|
18022
18611
|
pollIntervalMs;
|
|
18023
18612
|
operations;
|
|
18024
18613
|
currentSnapshot;
|
|
18614
|
+
disposeModules;
|
|
18025
18615
|
#closed = false;
|
|
18026
18616
|
get snapshot() {
|
|
18027
18617
|
return this.currentSnapshot;
|
|
@@ -18044,8 +18634,10 @@ var InstalledRendererCdpControlSession = class {
|
|
|
18044
18634
|
this.pollIntervalMs,
|
|
18045
18635
|
this.operations
|
|
18046
18636
|
);
|
|
18637
|
+
this.disposeModules();
|
|
18047
18638
|
this.renderer.close();
|
|
18048
18639
|
this.renderer = replacement.renderer;
|
|
18640
|
+
this.disposeModules = replacement.disposeModules;
|
|
18049
18641
|
this.currentSnapshot = replacement.snapshot;
|
|
18050
18642
|
} else {
|
|
18051
18643
|
try {
|
|
@@ -18068,8 +18660,10 @@ var InstalledRendererCdpControlSession = class {
|
|
|
18068
18660
|
this.pollIntervalMs,
|
|
18069
18661
|
this.operations
|
|
18070
18662
|
);
|
|
18663
|
+
this.disposeModules();
|
|
18071
18664
|
this.renderer.close();
|
|
18072
18665
|
this.renderer = replacement.renderer;
|
|
18666
|
+
this.disposeModules = replacement.disposeModules;
|
|
18073
18667
|
this.currentSnapshot = replacement.snapshot;
|
|
18074
18668
|
}
|
|
18075
18669
|
}
|
|
@@ -18095,6 +18689,7 @@ var InstalledRendererCdpControlSession = class {
|
|
|
18095
18689
|
close() {
|
|
18096
18690
|
if (this.#closed) return;
|
|
18097
18691
|
this.#closed = true;
|
|
18692
|
+
this.disposeModules();
|
|
18098
18693
|
this.renderer.close();
|
|
18099
18694
|
}
|
|
18100
18695
|
};
|
|
@@ -18141,7 +18736,8 @@ async function createRendererCdpControlSession(options) {
|
|
|
18141
18736
|
timeoutMs,
|
|
18142
18737
|
pollIntervalMs,
|
|
18143
18738
|
operations,
|
|
18144
|
-
installed.snapshot
|
|
18739
|
+
installed.snapshot,
|
|
18740
|
+
installed.disposeModules
|
|
18145
18741
|
);
|
|
18146
18742
|
}
|
|
18147
18743
|
function installRendererCdpControlSession(options) {
|