@karlorz/codexhost-cli-win32-x64 0.18.0-0 → 0.18.0-1
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 +258 -57
- package/app/console-web.js +1813 -137
- package/app/cpa-live-voice-hook.js +1879 -426
- package/app/desktop-controller.mjs +1783 -192
- package/app/host-runtime.mjs +2595 -1088
- package/app/overlay-voice-bootstrap.js +1616 -0
- package/app/plugins/antigravity/plugin.mjs +257 -56
- package/app/plugins/claude-code/plugin.mjs +257 -56
- package/app/plugins/codebuddy/plugin.mjs +257 -56
- package/app/plugins/codex-usage/plugin.mjs +257 -56
- package/app/plugins/copilot/plugin.mjs +257 -56
- package/app/plugins/cursor-cli/plugin.mjs +257 -56
- package/app/plugins/deepseek-harness/plugin.mjs +257 -56
- package/app/plugins/devin/plugin.mjs +257 -56
- package/app/plugins/grok/plugin.mjs +257 -56
- package/app/plugins/hermes/plugin.mjs +257 -56
- package/app/plugins/kimi-code/plugin.mjs +257 -56
- package/app/plugins/kiro-cli/plugin.mjs +257 -56
- package/app/plugins/omp/plugin.mjs +257 -56
- package/app/plugins/opencode/plugin.mjs +257 -56
- package/app/plugins/pi/plugin.mjs +257 -56
- package/app/plugins/qoder/plugin.mjs +257 -56
- package/app/plugins/qoder-cn/plugin.mjs +257 -56
- package/app/plugins/qwen-code/plugin.mjs +257 -56
- package/app/plugins/workbuddy/plugin.mjs +257 -56
- package/app/plugins/zcode/plugin.mjs +257 -56
- package/app/renderer-extension.js +22195 -19283
- package/app/voice-profile-pins.json +25 -0
- package/app/voice-qualification.json +4 -0
- package/app/web/assets/index-py6Ho-Dy.js +199 -0
- package/app/web/codexhost-settings.js +1762 -129
- package/app/web/index.html +1 -1
- package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +69 -69
- package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +63 -63
- package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +79 -79
- package/app/web-modules/server.mjs +956 -180
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +0 -0
- package/package.json +1 -1
- package/app/web/assets/index-Bs17Kuah.js +0 -199
|
@@ -6,7 +6,7 @@ var __export = (target2, all) => {
|
|
|
6
6
|
|
|
7
7
|
// packages/desktop-control/src/production-controller.ts
|
|
8
8
|
import { readFile } from "node:fs/promises";
|
|
9
|
-
import
|
|
9
|
+
import path6 from "node:path";
|
|
10
10
|
|
|
11
11
|
// packages/desktop-control/src/renderer-local-page.ts
|
|
12
12
|
import { randomUUID } from "node:crypto";
|
|
@@ -217,8 +217,7 @@ var CdpClient = class _CdpClient {
|
|
|
217
217
|
const id = this.#nextId++;
|
|
218
218
|
return new Promise((resolve, reject) => {
|
|
219
219
|
const timeout = setTimeout(() => {
|
|
220
|
-
this.#
|
|
221
|
-
reject(new Error(`CDP command '${method}' timed out`));
|
|
220
|
+
this.#disconnect(new CdpConnectionClosedError(`CDP command '${method}' timed out`));
|
|
222
221
|
}, this.#commandTimeoutMs);
|
|
223
222
|
this.#pending.set(id, { resolve, reject, timeout });
|
|
224
223
|
try {
|
|
@@ -1189,10 +1188,10 @@ function mergeDefs(...defs) {
|
|
|
1189
1188
|
function cloneDef(schema) {
|
|
1190
1189
|
return mergeDefs(schema._zod.def);
|
|
1191
1190
|
}
|
|
1192
|
-
function getElementAtPath(obj,
|
|
1193
|
-
if (!
|
|
1191
|
+
function getElementAtPath(obj, path7) {
|
|
1192
|
+
if (!path7)
|
|
1194
1193
|
return obj;
|
|
1195
|
-
return
|
|
1194
|
+
return path7.reduce((acc, key) => acc?.[key], obj);
|
|
1196
1195
|
}
|
|
1197
1196
|
function promiseAllObject(promisesObj) {
|
|
1198
1197
|
const keys = Object.keys(promisesObj);
|
|
@@ -1601,11 +1600,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1601
1600
|
}
|
|
1602
1601
|
return false;
|
|
1603
1602
|
}
|
|
1604
|
-
function prefixIssues(
|
|
1603
|
+
function prefixIssues(path7, issues) {
|
|
1605
1604
|
return issues.map((iss) => {
|
|
1606
1605
|
var _a3;
|
|
1607
1606
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1608
|
-
iss.path.unshift(
|
|
1607
|
+
iss.path.unshift(path7);
|
|
1609
1608
|
return iss;
|
|
1610
1609
|
});
|
|
1611
1610
|
}
|
|
@@ -1752,16 +1751,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1752
1751
|
}
|
|
1753
1752
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
1754
1753
|
const fieldErrors = { _errors: [] };
|
|
1755
|
-
const processError = (error52,
|
|
1754
|
+
const processError = (error52, path7 = []) => {
|
|
1756
1755
|
for (const issue2 of error52.issues) {
|
|
1757
1756
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1758
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1757
|
+
issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
|
|
1759
1758
|
} else if (issue2.code === "invalid_key") {
|
|
1760
|
-
processError({ issues: issue2.issues }, [...
|
|
1759
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1761
1760
|
} else if (issue2.code === "invalid_element") {
|
|
1762
|
-
processError({ issues: issue2.issues }, [...
|
|
1761
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1763
1762
|
} else {
|
|
1764
|
-
const fullpath = [...
|
|
1763
|
+
const fullpath = [...path7, ...issue2.path];
|
|
1765
1764
|
if (fullpath.length === 0) {
|
|
1766
1765
|
fieldErrors._errors.push(mapper(issue2));
|
|
1767
1766
|
} else {
|
|
@@ -1788,17 +1787,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1788
1787
|
}
|
|
1789
1788
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
1790
1789
|
const result = { errors: [] };
|
|
1791
|
-
const processError = (error52,
|
|
1790
|
+
const processError = (error52, path7 = []) => {
|
|
1792
1791
|
var _a3, _b;
|
|
1793
1792
|
for (const issue2 of error52.issues) {
|
|
1794
1793
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1795
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1794
|
+
issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
|
|
1796
1795
|
} else if (issue2.code === "invalid_key") {
|
|
1797
|
-
processError({ issues: issue2.issues }, [...
|
|
1796
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1798
1797
|
} else if (issue2.code === "invalid_element") {
|
|
1799
|
-
processError({ issues: issue2.issues }, [...
|
|
1798
|
+
processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
|
|
1800
1799
|
} else {
|
|
1801
|
-
const fullpath = [...
|
|
1800
|
+
const fullpath = [...path7, ...issue2.path];
|
|
1802
1801
|
if (fullpath.length === 0) {
|
|
1803
1802
|
result.errors.push(mapper(issue2));
|
|
1804
1803
|
continue;
|
|
@@ -1830,8 +1829,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
1830
1829
|
}
|
|
1831
1830
|
function toDotPath(_path) {
|
|
1832
1831
|
const segs = [];
|
|
1833
|
-
const
|
|
1834
|
-
for (const seg of
|
|
1832
|
+
const path7 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1833
|
+
for (const seg of path7) {
|
|
1835
1834
|
if (typeof seg === "number")
|
|
1836
1835
|
segs.push(`[${seg}]`);
|
|
1837
1836
|
else if (typeof seg === "symbol")
|
|
@@ -14523,13 +14522,13 @@ function resolveRef(ref, ctx) {
|
|
|
14523
14522
|
if (!ref.startsWith("#")) {
|
|
14524
14523
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14525
14524
|
}
|
|
14526
|
-
const
|
|
14527
|
-
if (
|
|
14525
|
+
const path7 = ref.slice(1).split("/").filter(Boolean);
|
|
14526
|
+
if (path7.length === 0) {
|
|
14528
14527
|
return ctx.rootSchema;
|
|
14529
14528
|
}
|
|
14530
14529
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14531
|
-
if (
|
|
14532
|
-
const key =
|
|
14530
|
+
if (path7[0] === defsKey) {
|
|
14531
|
+
const key = path7[1];
|
|
14533
14532
|
if (!key || !ctx.defs[key]) {
|
|
14534
14533
|
throw new Error(`Reference not found: ${ref}`);
|
|
14535
14534
|
}
|
|
@@ -14964,7 +14963,8 @@ var harnessGoalSetSchema = external_exports.object({
|
|
|
14964
14963
|
origin: goalOriginSchema
|
|
14965
14964
|
});
|
|
14966
14965
|
|
|
14967
|
-
// packages/shared-contracts/dist/realtime-call.js
|
|
14966
|
+
// packages/shared-contracts/dist/realtime-call-core.js
|
|
14967
|
+
var REALTIME_CALL_METHOD = "codexhost/realtime/call";
|
|
14968
14968
|
var REALTIME_CALL_FORWARDED_HEADERS = [
|
|
14969
14969
|
"openai-alpha",
|
|
14970
14970
|
"thread-id",
|
|
@@ -14973,7 +14973,18 @@ var REALTIME_CALL_FORWARDED_HEADERS = [
|
|
|
14973
14973
|
"x-codex-turn-metadata"
|
|
14974
14974
|
];
|
|
14975
14975
|
var FORWARDED_HEADERS = new Set(REALTIME_CALL_FORWARDED_HEADERS);
|
|
14976
|
-
var REALTIME_CALL_ID_PATTERN = /^
|
|
14976
|
+
var REALTIME_CALL_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/u;
|
|
14977
|
+
function isRealtimeCallId(value) {
|
|
14978
|
+
return typeof value === "string" && REALTIME_CALL_ID_PATTERN.test(value);
|
|
14979
|
+
}
|
|
14980
|
+
function realtimeCallIdFromLocation(location) {
|
|
14981
|
+
const path7 = location.split(/[?#]/u)[0] ?? "";
|
|
14982
|
+
if (/^[A-Za-z0-9_-]{1,128}$/u.test(path7))
|
|
14983
|
+
return path7;
|
|
14984
|
+
return /\/(?:calls|live)\/([A-Za-z0-9_-]{1,128})$/u.exec(path7)?.[1];
|
|
14985
|
+
}
|
|
14986
|
+
|
|
14987
|
+
// packages/shared-contracts/dist/realtime-call.js
|
|
14977
14988
|
var requestId = external_exports.string().min(1).max(128);
|
|
14978
14989
|
var realtimeCallParamsSchema = external_exports.discriminatedUnion("operation", [
|
|
14979
14990
|
external_exports.object({
|
|
@@ -15028,12 +15039,6 @@ var RELAY_PUBLIC_ORIGIN = "https://codexhost.karldigi.dev";
|
|
|
15028
15039
|
var RELAY_PUBLIC_RESOURCE = `${RELAY_PUBLIC_ORIGIN}/mcp`;
|
|
15029
15040
|
var RELAY_WAIT_TIMEOUT_MAX_MS = 25e3;
|
|
15030
15041
|
var RELAY_MAX_BODY_BYTES = 2 * 1024 * 1024;
|
|
15031
|
-
var RELAY_ALLOWED_ROUTES = [
|
|
15032
|
-
"/v1/enroll/status",
|
|
15033
|
-
"/v1/thread/read",
|
|
15034
|
-
"/v1/thread/wait",
|
|
15035
|
-
"/v1/thread/send"
|
|
15036
|
-
];
|
|
15037
15042
|
var relayLinkHelloSchema = external_exports.strictObject({
|
|
15038
15043
|
v: external_exports.literal(RELAY_LINK_PROTOCOL_VERSION),
|
|
15039
15044
|
secret: external_exports.string().min(1).max(4096)
|
|
@@ -15045,8 +15050,11 @@ var relayLinkHelloAckSchema = external_exports.strictObject({
|
|
|
15045
15050
|
var relayLinkRequestSchema = external_exports.strictObject({
|
|
15046
15051
|
requestId: external_exports.string().min(1).max(128),
|
|
15047
15052
|
deadlineMs: external_exports.number().int().positive(),
|
|
15048
|
-
route: external_exports.
|
|
15049
|
-
body: external_exports.record(external_exports.string(), external_exports.unknown())
|
|
15053
|
+
route: external_exports.string().min(1).max(128),
|
|
15054
|
+
body: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
15055
|
+
operationalClient: external_exports.string().min(1).max(64).optional(),
|
|
15056
|
+
oauthClientId: external_exports.string().min(1).max(128).optional(),
|
|
15057
|
+
dispatchGrant: external_exports.enum(["legacy-four", "full-dispatch"]).optional()
|
|
15050
15058
|
});
|
|
15051
15059
|
var relayLinkErrorSchema = external_exports.strictObject({
|
|
15052
15060
|
code: external_exports.string().min(1).max(64),
|
|
@@ -15090,6 +15098,204 @@ var relayEnrollStatusResultSchema = external_exports.strictObject({
|
|
|
15090
15098
|
runtime: external_exports.enum(["reachable", "unreachable"])
|
|
15091
15099
|
});
|
|
15092
15100
|
|
|
15101
|
+
// packages/shared-contracts/dist/external-clients.js
|
|
15102
|
+
var EXTERNAL_CLIENT_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/u;
|
|
15103
|
+
var externalClientNameSchema = external_exports.string().trim().min(1).max(64).regex(EXTERNAL_CLIENT_NAME_PATTERN);
|
|
15104
|
+
var externalClientAccessSchema = external_exports.enum(["all-threads", "selected-workspaces"]);
|
|
15105
|
+
var externalClientConnectionModeSchema = external_exports.enum(["public-relay", "local", "direct"]);
|
|
15106
|
+
var externalClientDispatchGrantSchema = external_exports.enum(["legacy-four", "full-dispatch"]);
|
|
15107
|
+
var workspacePathSchema = external_exports.string().trim().min(1).max(4096);
|
|
15108
|
+
var directUrlSchema = external_exports.string().trim().max(2048);
|
|
15109
|
+
var externalClientPublicViewSchema = external_exports.strictObject({
|
|
15110
|
+
name: externalClientNameSchema,
|
|
15111
|
+
createdAt: external_exports.string().min(1).max(64),
|
|
15112
|
+
access: externalClientAccessSchema,
|
|
15113
|
+
workspaces: external_exports.array(workspacePathSchema).max(64),
|
|
15114
|
+
connectionMode: externalClientConnectionModeSchema,
|
|
15115
|
+
dispatchGrant: externalClientDispatchGrantSchema,
|
|
15116
|
+
oauthClientId: external_exports.string().trim().min(1).max(128).optional(),
|
|
15117
|
+
directUrl: directUrlSchema.optional(),
|
|
15118
|
+
mcpUrl: external_exports.string().min(1).max(2048).optional(),
|
|
15119
|
+
mcpUrlNote: external_exports.string().min(1).max(512).optional()
|
|
15120
|
+
});
|
|
15121
|
+
var externalClientListParamsSchema = external_exports.strictObject({});
|
|
15122
|
+
var externalClientListResultSchema = external_exports.strictObject({
|
|
15123
|
+
clients: external_exports.array(externalClientPublicViewSchema).max(256)
|
|
15124
|
+
});
|
|
15125
|
+
var externalClientWriteFieldsSchema = external_exports.strictObject({
|
|
15126
|
+
access: externalClientAccessSchema.optional(),
|
|
15127
|
+
workspaces: external_exports.array(workspacePathSchema).max(64).optional(),
|
|
15128
|
+
connectionMode: externalClientConnectionModeSchema.optional(),
|
|
15129
|
+
dispatchGrant: externalClientDispatchGrantSchema.optional(),
|
|
15130
|
+
oauthClientId: external_exports.string().trim().min(1).max(128).optional(),
|
|
15131
|
+
directUrl: directUrlSchema.optional()
|
|
15132
|
+
});
|
|
15133
|
+
var externalClientCreateParamsSchema = externalClientWriteFieldsSchema.extend({
|
|
15134
|
+
name: externalClientNameSchema
|
|
15135
|
+
});
|
|
15136
|
+
var externalClientCreateResultSchema = externalClientPublicViewSchema.extend({
|
|
15137
|
+
token: external_exports.string().min(1).max(256).optional()
|
|
15138
|
+
});
|
|
15139
|
+
var externalClientUpdateParamsSchema = externalClientWriteFieldsSchema.extend({
|
|
15140
|
+
name: externalClientNameSchema,
|
|
15141
|
+
clearOauthClientId: external_exports.literal(true).optional()
|
|
15142
|
+
});
|
|
15143
|
+
var externalClientRevokeParamsSchema = external_exports.strictObject({
|
|
15144
|
+
name: externalClientNameSchema
|
|
15145
|
+
});
|
|
15146
|
+
var externalClientRevokeResultSchema = external_exports.strictObject({
|
|
15147
|
+
name: externalClientNameSchema,
|
|
15148
|
+
revoked: external_exports.literal(true)
|
|
15149
|
+
});
|
|
15150
|
+
var stringProp = (description) => ({ type: "string", description });
|
|
15151
|
+
var integerProp = (description) => ({
|
|
15152
|
+
type: "integer",
|
|
15153
|
+
minimum: 0,
|
|
15154
|
+
description
|
|
15155
|
+
});
|
|
15156
|
+
var threadProp = stringProp("Thread id or codex://threads/<id> link");
|
|
15157
|
+
var EXTERNAL_MCP_TOOL_DESCRIPTORS = [
|
|
15158
|
+
{
|
|
15159
|
+
name: "harness_list",
|
|
15160
|
+
description: "List the Harnesses this codexhost can delegate to.",
|
|
15161
|
+
inputSchema: { type: "object", properties: {} }
|
|
15162
|
+
},
|
|
15163
|
+
{
|
|
15164
|
+
name: "harness_inspect",
|
|
15165
|
+
description: "Read a Harness's Models, Thinking options and defaults; use the returned ids when delegating.",
|
|
15166
|
+
inputSchema: {
|
|
15167
|
+
type: "object",
|
|
15168
|
+
properties: {
|
|
15169
|
+
harnessId: stringProp("Harness id from harness_list"),
|
|
15170
|
+
cwd: stringProp("Absolute workspace path"),
|
|
15171
|
+
refresh: { type: "boolean" }
|
|
15172
|
+
},
|
|
15173
|
+
required: ["harnessId"]
|
|
15174
|
+
}
|
|
15175
|
+
},
|
|
15176
|
+
{
|
|
15177
|
+
name: "delegate_start",
|
|
15178
|
+
description: "Start a task in a new Thread and return at once. Without parentThread the work belongs to this client and cwd is required. watch=true records an event for this client when the Thread stops (read it with events_poll or the SSE stream).",
|
|
15179
|
+
inputSchema: {
|
|
15180
|
+
type: "object",
|
|
15181
|
+
properties: {
|
|
15182
|
+
harnessId: stringProp("Harness id from harness_list"),
|
|
15183
|
+
task: stringProp("The full task text"),
|
|
15184
|
+
taskName: stringProp("Short display name"),
|
|
15185
|
+
cwd: stringProp("Absolute workspace path"),
|
|
15186
|
+
model: stringProp("Model id from harness_inspect"),
|
|
15187
|
+
thinking: stringProp("Thinking option id from harness_inspect"),
|
|
15188
|
+
parentThread: stringProp("Optional parent Thread"),
|
|
15189
|
+
requestId: stringProp("Reuse to retry idempotently"),
|
|
15190
|
+
refs: {
|
|
15191
|
+
type: "array",
|
|
15192
|
+
items: { type: "string" },
|
|
15193
|
+
description: "Absolute URIs of where the work came from"
|
|
15194
|
+
},
|
|
15195
|
+
watch: { type: "boolean", description: "Record an event when the Thread stops" },
|
|
15196
|
+
watchTimeoutMs: integerProp("How long to watch; default 29 minutes")
|
|
15197
|
+
},
|
|
15198
|
+
required: ["harnessId", "task"]
|
|
15199
|
+
}
|
|
15200
|
+
},
|
|
15201
|
+
{
|
|
15202
|
+
name: "thread_read",
|
|
15203
|
+
description: "Read a Thread's status and latest result, or page its visible messages (view=messages). Never changes the Thread.",
|
|
15204
|
+
inputSchema: {
|
|
15205
|
+
type: "object",
|
|
15206
|
+
properties: {
|
|
15207
|
+
thread: threadProp,
|
|
15208
|
+
view: { type: "string", enum: ["result", "messages"] },
|
|
15209
|
+
cursor: stringProp("Message cursor"),
|
|
15210
|
+
limit: integerProp("Messages per page, at most 100")
|
|
15211
|
+
},
|
|
15212
|
+
required: ["thread"]
|
|
15213
|
+
}
|
|
15214
|
+
},
|
|
15215
|
+
{
|
|
15216
|
+
name: "thread_wait",
|
|
15217
|
+
description: "Wait up to timeoutMs (at most 60000) for a Thread to stop, then return the same snapshot as thread_read plus timedOut.",
|
|
15218
|
+
inputSchema: {
|
|
15219
|
+
type: "object",
|
|
15220
|
+
properties: {
|
|
15221
|
+
thread: threadProp,
|
|
15222
|
+
timeoutMs: integerProp("At most 60000; default 30000"),
|
|
15223
|
+
view: { type: "string", enum: ["result", "messages"] }
|
|
15224
|
+
},
|
|
15225
|
+
required: ["thread"]
|
|
15226
|
+
}
|
|
15227
|
+
},
|
|
15228
|
+
{
|
|
15229
|
+
name: "thread_list",
|
|
15230
|
+
description: "List Threads: by workspace (cwd), by parent Thread, by the client that started them, or by reference.",
|
|
15231
|
+
inputSchema: {
|
|
15232
|
+
type: "object",
|
|
15233
|
+
properties: {
|
|
15234
|
+
cwd: stringProp("Absolute workspace path"),
|
|
15235
|
+
parent: stringProp("Parent Thread"),
|
|
15236
|
+
client: stringProp("Client name"),
|
|
15237
|
+
ref: stringProp("Reference URI"),
|
|
15238
|
+
limit: integerProp("At most 100; default 25"),
|
|
15239
|
+
cursor: stringProp("Cursor from a previous page"),
|
|
15240
|
+
sort: {
|
|
15241
|
+
type: "string",
|
|
15242
|
+
enum: [
|
|
15243
|
+
"created-asc",
|
|
15244
|
+
"created-desc",
|
|
15245
|
+
"updated-asc",
|
|
15246
|
+
"updated-desc",
|
|
15247
|
+
"recency-asc",
|
|
15248
|
+
"recency-desc"
|
|
15249
|
+
]
|
|
15250
|
+
}
|
|
15251
|
+
}
|
|
15252
|
+
}
|
|
15253
|
+
},
|
|
15254
|
+
{
|
|
15255
|
+
name: "thread_send",
|
|
15256
|
+
description: "Start a new Turn in an idle Thread. THREAD_BUSY means its current Turn is still running; messages are not queued.",
|
|
15257
|
+
inputSchema: {
|
|
15258
|
+
type: "object",
|
|
15259
|
+
properties: { thread: threadProp, message: stringProp("Message text") },
|
|
15260
|
+
required: ["thread", "message"]
|
|
15261
|
+
}
|
|
15262
|
+
},
|
|
15263
|
+
{
|
|
15264
|
+
name: "thread_cancel",
|
|
15265
|
+
description: "Cancel a Thread's active Turn, keeping the Thread and its history.",
|
|
15266
|
+
inputSchema: { type: "object", properties: { thread: threadProp }, required: ["thread"] }
|
|
15267
|
+
},
|
|
15268
|
+
{
|
|
15269
|
+
name: "thread_watch",
|
|
15270
|
+
description: "Record one event for this client when the Thread stops or the watch expires.",
|
|
15271
|
+
inputSchema: {
|
|
15272
|
+
type: "object",
|
|
15273
|
+
properties: { thread: threadProp, timeoutMs: integerProp("Default 29 minutes") },
|
|
15274
|
+
required: ["thread"]
|
|
15275
|
+
}
|
|
15276
|
+
},
|
|
15277
|
+
{
|
|
15278
|
+
name: "thread_watches",
|
|
15279
|
+
description: "List watches that have not been delivered yet.",
|
|
15280
|
+
inputSchema: { type: "object", properties: {} }
|
|
15281
|
+
},
|
|
15282
|
+
{
|
|
15283
|
+
name: "events_poll",
|
|
15284
|
+
description: "Read this client's events after a cursor (0 for all retained). Waits up to timeoutMs (at most 60000) for the first one. Pass the returned cursor back next time. CURSOR_EXPIRED: reconcile with thread_list client=<this client>.",
|
|
15285
|
+
inputSchema: {
|
|
15286
|
+
type: "object",
|
|
15287
|
+
properties: {
|
|
15288
|
+
after: integerProp("Cursor; 0 for all retained"),
|
|
15289
|
+
timeoutMs: integerProp("At most 60000; default 0"),
|
|
15290
|
+
limit: integerProp("At most 100")
|
|
15291
|
+
}
|
|
15292
|
+
}
|
|
15293
|
+
}
|
|
15294
|
+
];
|
|
15295
|
+
|
|
15296
|
+
// packages/shared-contracts/dist/external-mcp-map.js
|
|
15297
|
+
var DEFAULT_WATCH_MS = 29 * 6e4;
|
|
15298
|
+
|
|
15093
15299
|
// packages/shared-contracts/dist/grok-computer-use.js
|
|
15094
15300
|
var grokComputerUseGetSchema = external_exports.object({}).strict();
|
|
15095
15301
|
var grokComputerUseSetSchema = external_exports.object({
|
|
@@ -15686,6 +15892,54 @@ var threadSteeringInspectResultSchema = external_exports.object({
|
|
|
15686
15892
|
delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
|
|
15687
15893
|
}).strict();
|
|
15688
15894
|
|
|
15895
|
+
// packages/shared-contracts/dist/voice-settings.js
|
|
15896
|
+
var VOICE_SETTINGS_METHOD = "codexhost/voice/settings";
|
|
15897
|
+
var VOICE_GATEWAY_STATUS_METHOD = "codexhost/voice/gateway-status";
|
|
15898
|
+
var voiceRoutesSchema = external_exports.strictObject({
|
|
15899
|
+
chatExperience: external_exports.enum(["chatgpt", "codex"]),
|
|
15900
|
+
chatConnection: external_exports.enum(["desktop", "gateway"]),
|
|
15901
|
+
workConnection: external_exports.enum(["desktop", "gateway"])
|
|
15902
|
+
});
|
|
15903
|
+
var DEFAULT_VOICE_ROUTES = Object.freeze({
|
|
15904
|
+
chatExperience: "chatgpt",
|
|
15905
|
+
chatConnection: "desktop",
|
|
15906
|
+
workConnection: "gateway"
|
|
15907
|
+
});
|
|
15908
|
+
var voiceSettingsSchema = voiceRoutesSchema.extend({ inject: external_exports.boolean() });
|
|
15909
|
+
var voiceSettingsRequestSchema = external_exports.discriminatedUnion("operation", [
|
|
15910
|
+
external_exports.strictObject({
|
|
15911
|
+
operation: external_exports.literal("get"),
|
|
15912
|
+
runtime: external_exports.strictObject({
|
|
15913
|
+
id: external_exports.string().uuid(),
|
|
15914
|
+
revision: external_exports.string().max(64),
|
|
15915
|
+
activeCall: external_exports.boolean()
|
|
15916
|
+
}).optional()
|
|
15917
|
+
}),
|
|
15918
|
+
external_exports.strictObject({ operation: external_exports.literal("migrate"), routes: voiceRoutesSchema }),
|
|
15919
|
+
external_exports.strictObject({
|
|
15920
|
+
operation: external_exports.literal("set"),
|
|
15921
|
+
settings: voiceSettingsSchema,
|
|
15922
|
+
revision: external_exports.string().max(64)
|
|
15923
|
+
}),
|
|
15924
|
+
external_exports.strictObject({ operation: external_exports.literal("restart"), confirm: external_exports.literal(true) })
|
|
15925
|
+
]);
|
|
15926
|
+
var voiceSettingsStateSchema = external_exports.strictObject({
|
|
15927
|
+
settings: voiceSettingsSchema,
|
|
15928
|
+
initialized: external_exports.boolean(),
|
|
15929
|
+
revision: external_exports.string(),
|
|
15930
|
+
activeInject: external_exports.boolean().nullable(),
|
|
15931
|
+
envOverride: external_exports.enum(["0", "1"]).nullable(),
|
|
15932
|
+
activeEnvOverride: external_exports.enum(["0", "1"]).nullable(),
|
|
15933
|
+
routesActive: external_exports.boolean().nullable(),
|
|
15934
|
+
activeCall: external_exports.boolean().nullable(),
|
|
15935
|
+
gatewayReady: external_exports.boolean().nullable(),
|
|
15936
|
+
restartAvailable: external_exports.boolean(),
|
|
15937
|
+
restart: external_exports.strictObject({
|
|
15938
|
+
phase: external_exports.enum(["idle", "restarting", "succeeded", "failed"]),
|
|
15939
|
+
error: external_exports.string().nullable()
|
|
15940
|
+
})
|
|
15941
|
+
});
|
|
15942
|
+
|
|
15689
15943
|
// packages/shared-contracts/dist/client-channel.js
|
|
15690
15944
|
var CLIENT_CHANNEL_VERSION = 1;
|
|
15691
15945
|
var CLIENT_REQUEST_LIMIT_BYTES = 128 * 1024 * 1024;
|
|
@@ -16463,6 +16717,10 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
16463
16717
|
"codexhost/voice/gateway-status",
|
|
16464
16718
|
"codexhost/enrollment/list",
|
|
16465
16719
|
"codexhost/enrollment/revoke",
|
|
16720
|
+
"codexhost/external-clients/list",
|
|
16721
|
+
"codexhost/external-clients/create",
|
|
16722
|
+
"codexhost/external-clients/update",
|
|
16723
|
+
"codexhost/external-clients/revoke",
|
|
16466
16724
|
"codexhost/console/remote-connections",
|
|
16467
16725
|
"codexhost/runtime/status",
|
|
16468
16726
|
"codexhost/remote/ssh-setup",
|
|
@@ -16671,10 +16929,20 @@ var harnessLaunchSettingsSchema = external_exports.object({
|
|
|
16671
16929
|
}).strict();
|
|
16672
16930
|
|
|
16673
16931
|
// packages/shared-contracts/dist/harness-installation.js
|
|
16932
|
+
var HARNESS_INSTALLATION_METHOD = "codexhost/harness/installation";
|
|
16933
|
+
var HARNESS_INSTALLATION_MUTATION_TIMEOUT_MS = 66e4;
|
|
16674
16934
|
var harnessInstallationParamsSchema = external_exports.object({
|
|
16675
16935
|
harnessId: harnessIdSchema,
|
|
16676
16936
|
action: external_exports.enum(["check", "update", "install"])
|
|
16677
16937
|
}).strict();
|
|
16938
|
+
function harnessInstallationRequestTimeoutMs(method, params) {
|
|
16939
|
+
if (method !== HARNESS_INSTALLATION_METHOD)
|
|
16940
|
+
return;
|
|
16941
|
+
const parsed = harnessInstallationParamsSchema.safeParse(params);
|
|
16942
|
+
if (!parsed.success || parsed.data.action === "check")
|
|
16943
|
+
return;
|
|
16944
|
+
return HARNESS_INSTALLATION_MUTATION_TIMEOUT_MS;
|
|
16945
|
+
}
|
|
16678
16946
|
var harnessInstallationStateSchema = external_exports.object({
|
|
16679
16947
|
currentVersion: external_exports.string().min(1).max(128),
|
|
16680
16948
|
latestVersion: external_exports.string().min(1).max(128),
|
|
@@ -17163,52 +17431,6 @@ var webUiExtensionInstallSchema = external_exports.object({
|
|
|
17163
17431
|
var webUiExtensionEnabledSchema = external_exports.object({ id: webUiExtensionIdSchema, enabled: external_exports.boolean() }).strict();
|
|
17164
17432
|
var webUiExtensionRemoveSchema = external_exports.object({ id: webUiExtensionIdSchema }).strict();
|
|
17165
17433
|
|
|
17166
|
-
// packages/shared-contracts/dist/voice-settings.js
|
|
17167
|
-
var voiceRoutesSchema = external_exports.strictObject({
|
|
17168
|
-
chatExperience: external_exports.enum(["chatgpt", "codex"]),
|
|
17169
|
-
chatConnection: external_exports.enum(["desktop", "gateway"]),
|
|
17170
|
-
workConnection: external_exports.enum(["desktop", "gateway"])
|
|
17171
|
-
});
|
|
17172
|
-
var DEFAULT_VOICE_ROUTES = Object.freeze({
|
|
17173
|
-
chatExperience: "chatgpt",
|
|
17174
|
-
chatConnection: "desktop",
|
|
17175
|
-
workConnection: "gateway"
|
|
17176
|
-
});
|
|
17177
|
-
var voiceSettingsSchema = voiceRoutesSchema.extend({ inject: external_exports.boolean() });
|
|
17178
|
-
var voiceSettingsRequestSchema = external_exports.discriminatedUnion("operation", [
|
|
17179
|
-
external_exports.strictObject({
|
|
17180
|
-
operation: external_exports.literal("get"),
|
|
17181
|
-
runtime: external_exports.strictObject({
|
|
17182
|
-
id: external_exports.string().uuid(),
|
|
17183
|
-
revision: external_exports.string().max(64),
|
|
17184
|
-
activeCall: external_exports.boolean()
|
|
17185
|
-
}).optional()
|
|
17186
|
-
}),
|
|
17187
|
-
external_exports.strictObject({ operation: external_exports.literal("migrate"), routes: voiceRoutesSchema }),
|
|
17188
|
-
external_exports.strictObject({
|
|
17189
|
-
operation: external_exports.literal("set"),
|
|
17190
|
-
settings: voiceSettingsSchema,
|
|
17191
|
-
revision: external_exports.string().max(64)
|
|
17192
|
-
}),
|
|
17193
|
-
external_exports.strictObject({ operation: external_exports.literal("restart"), confirm: external_exports.literal(true) })
|
|
17194
|
-
]);
|
|
17195
|
-
var voiceSettingsStateSchema = external_exports.strictObject({
|
|
17196
|
-
settings: voiceSettingsSchema,
|
|
17197
|
-
initialized: external_exports.boolean(),
|
|
17198
|
-
revision: external_exports.string(),
|
|
17199
|
-
activeInject: external_exports.boolean().nullable(),
|
|
17200
|
-
envOverride: external_exports.enum(["0", "1"]).nullable(),
|
|
17201
|
-
activeEnvOverride: external_exports.enum(["0", "1"]).nullable(),
|
|
17202
|
-
routesActive: external_exports.boolean().nullable(),
|
|
17203
|
-
activeCall: external_exports.boolean().nullable(),
|
|
17204
|
-
gatewayReady: external_exports.boolean().nullable(),
|
|
17205
|
-
restartAvailable: external_exports.boolean(),
|
|
17206
|
-
restart: external_exports.strictObject({
|
|
17207
|
-
phase: external_exports.enum(["idle", "restarting", "succeeded", "failed"]),
|
|
17208
|
-
error: external_exports.string().nullable()
|
|
17209
|
-
})
|
|
17210
|
-
});
|
|
17211
|
-
|
|
17212
17434
|
// packages/shared-contracts/dist/background-activity.js
|
|
17213
17435
|
var backgroundActivitySchema = external_exports.strictObject({
|
|
17214
17436
|
id: external_exports.string().min(1),
|
|
@@ -17272,7 +17494,7 @@ function isLocalPageUrl(value) {
|
|
|
17272
17494
|
return false;
|
|
17273
17495
|
}
|
|
17274
17496
|
}
|
|
17275
|
-
async function serveLocalPage(socket, url2,
|
|
17497
|
+
async function serveLocalPage(socket, url2, open2) {
|
|
17276
17498
|
let page;
|
|
17277
17499
|
let buffer = "";
|
|
17278
17500
|
let operation = Promise.resolve();
|
|
@@ -17304,7 +17526,7 @@ async function serveLocalPage(socket, url2, open) {
|
|
|
17304
17526
|
}
|
|
17305
17527
|
};
|
|
17306
17528
|
try {
|
|
17307
|
-
page = await
|
|
17529
|
+
page = await open2(url2);
|
|
17308
17530
|
if (socket.destroyed) return;
|
|
17309
17531
|
socket.on("data", receive);
|
|
17310
17532
|
socket.write("ready\n");
|
|
@@ -17563,7 +17785,7 @@ function createControllerStatusPublisher(filePath = defaultControllerStatusPath(
|
|
|
17563
17785
|
}
|
|
17564
17786
|
|
|
17565
17787
|
// packages/desktop-control/src/cpa-live-voice-hook.ts
|
|
17566
|
-
import { existsSync } from "node:fs";
|
|
17788
|
+
import { existsSync, readFileSync as readFileSync2, unlinkSync } from "node:fs";
|
|
17567
17789
|
import { execFileSync } from "node:child_process";
|
|
17568
17790
|
import os3 from "node:os";
|
|
17569
17791
|
import path3 from "node:path";
|
|
@@ -17591,6 +17813,145 @@ var CPA_LIVE_VOICE_HOOK_GLOBAL = "__codexhostCpaLiveVoiceHookV1";
|
|
|
17591
17813
|
var AUDITED_CPA_LIVE_VOICE_DESKTOP_VERSION = "26.1007.30912";
|
|
17592
17814
|
var AUDITED_CPA_LIVE_VOICE_APP_INITIAL_ASSET = "app-initial-6350d04672d0.js";
|
|
17593
17815
|
var DESKTOP_VERSION_ENV = "CODEXHOST_DESKTOP_VERSION";
|
|
17816
|
+
var DESKTOP_BUILD_ENV = "CODEXHOST_DESKTOP_BUILD";
|
|
17817
|
+
var DESKTOP_ASAR_DIGEST_ENV = "CODEXHOST_DESKTOP_ASAR_DIGEST";
|
|
17818
|
+
var DESKTOP_APP_PATH_ENV = "CODEXHOST_DESKTOP_APP_PATH";
|
|
17819
|
+
var VOICE_ISOLATED_QUALIFICATION_FILE = "voice-isolated-qualification.json";
|
|
17820
|
+
var HASHED_WEBPACK_OVERLAY_VOICE_DESKTOP_VERSION = "26.1106.51428";
|
|
17821
|
+
var OVERLAY_VOICE_HOOK_DESKTOP_VERSIONS = [
|
|
17822
|
+
AUDITED_CPA_LIVE_VOICE_DESKTOP_VERSION,
|
|
17823
|
+
"26.1016.61520",
|
|
17824
|
+
"26.1016.62342",
|
|
17825
|
+
"26.1021.31345",
|
|
17826
|
+
"26.1023.51421",
|
|
17827
|
+
"26.1027.30824",
|
|
17828
|
+
"26.1027.61615",
|
|
17829
|
+
HASHED_WEBPACK_OVERLAY_VOICE_DESKTOP_VERSION
|
|
17830
|
+
];
|
|
17831
|
+
var ISOLATED_VOICE_PATHS = ["chat", "work-codex", "work-grok"];
|
|
17832
|
+
var PRODUCTION_DESKTOP_APP_PATH = "/Applications/ChatGPT.app";
|
|
17833
|
+
var PRODUCTION_WINDOWS_APPX_PATH = /(?:^|[\\/])WindowsApps[\\/]OpenAI\.(?:Codex|ChatGPT)_/i;
|
|
17834
|
+
function isProductionDesktopAppPath(appPath) {
|
|
17835
|
+
if (typeof appPath !== "string" || appPath.length === 0) return false;
|
|
17836
|
+
if (appPath === PRODUCTION_DESKTOP_APP_PATH) return true;
|
|
17837
|
+
return PRODUCTION_WINDOWS_APPX_PATH.test(appPath);
|
|
17838
|
+
}
|
|
17839
|
+
function isNonEmptyString(value) {
|
|
17840
|
+
return typeof value === "string" && value.length > 0;
|
|
17841
|
+
}
|
|
17842
|
+
function envNonEmpty(environment, key) {
|
|
17843
|
+
const value = environment[key]?.trim();
|
|
17844
|
+
return value ? value : void 0;
|
|
17845
|
+
}
|
|
17846
|
+
function isIsolatedVoicePath(value) {
|
|
17847
|
+
return value === "chat" || value === "work-codex" || value === "work-grok";
|
|
17848
|
+
}
|
|
17849
|
+
function isIsolatedDesktopPlatform(value) {
|
|
17850
|
+
return value === "darwin" || value === "win32" || value === "linux";
|
|
17851
|
+
}
|
|
17852
|
+
function isolatedQualificationExpiresAtMs(expiresAt) {
|
|
17853
|
+
if (typeof expiresAt !== "string" || expiresAt.length === 0) return void 0;
|
|
17854
|
+
const parsed = Date.parse(expiresAt);
|
|
17855
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
17856
|
+
}
|
|
17857
|
+
function isolatedQualificationPathSet(value) {
|
|
17858
|
+
if (value === null || typeof value !== "object") return void 0;
|
|
17859
|
+
const record4 = value;
|
|
17860
|
+
const pathsPresent = record4.paths !== void 0;
|
|
17861
|
+
const pathPresent = record4.path !== void 0;
|
|
17862
|
+
let listed;
|
|
17863
|
+
if (pathsPresent) {
|
|
17864
|
+
const rawPaths = record4.paths;
|
|
17865
|
+
if (!Array.isArray(rawPaths) || rawPaths.length === 0) return void 0;
|
|
17866
|
+
if (rawPaths.some((path7) => !isIsolatedVoicePath(path7))) return void 0;
|
|
17867
|
+
if (new Set(rawPaths).size !== rawPaths.length) return void 0;
|
|
17868
|
+
listed = ISOLATED_VOICE_PATHS.filter((path7) => rawPaths.includes(path7));
|
|
17869
|
+
if (listed.length !== rawPaths.length) return void 0;
|
|
17870
|
+
} else if (pathPresent) {
|
|
17871
|
+
if (!isIsolatedVoicePath(record4.path)) return void 0;
|
|
17872
|
+
listed = [record4.path];
|
|
17873
|
+
} else {
|
|
17874
|
+
return void 0;
|
|
17875
|
+
}
|
|
17876
|
+
if (pathPresent) {
|
|
17877
|
+
if (!isIsolatedVoicePath(record4.path) || !listed.includes(record4.path)) return void 0;
|
|
17878
|
+
}
|
|
17879
|
+
return listed;
|
|
17880
|
+
}
|
|
17881
|
+
function isIsolatedVoiceQualification(value, now = Date.now()) {
|
|
17882
|
+
if (value === null || typeof value !== "object") return false;
|
|
17883
|
+
const parsed = value;
|
|
17884
|
+
const paths = isolatedQualificationPathSet(parsed);
|
|
17885
|
+
if (!paths || paths.length === 0) return false;
|
|
17886
|
+
if (isProductionDesktopAppPath(parsed.appPath)) return false;
|
|
17887
|
+
const expiresAtMs = isolatedQualificationExpiresAtMs(parsed.expiresAt);
|
|
17888
|
+
if (expiresAtMs === void 0 || expiresAtMs <= now) return false;
|
|
17889
|
+
return isNonEmptyString(parsed.run) && isIsolatedDesktopPlatform(parsed.desktopPlatform) && isNonEmptyString(parsed.desktopVersion) && isNonEmptyString(parsed.desktopBuild) && isNonEmptyString(parsed.asarDigest) && isNonEmptyString(parsed.appPath) && isNonEmptyString(parsed.implementationRevision) && parsed.label === "unqualified-isolated";
|
|
17890
|
+
}
|
|
17891
|
+
function readVoiceProfilePins(overlayDir) {
|
|
17892
|
+
const file2 = path3.join(overlayDir, "voice-profile-pins.json");
|
|
17893
|
+
try {
|
|
17894
|
+
const parsed = JSON.parse(readFileSync2(file2, "utf8"));
|
|
17895
|
+
if (!isNonEmptyString(parsed.hashedVersion) || !Array.isArray(parsed.overlayHookDesktopVersions) || parsed.overlayHookDesktopVersions.some((version2) => !isNonEmptyString(version2))) {
|
|
17896
|
+
return void 0;
|
|
17897
|
+
}
|
|
17898
|
+
return parsed;
|
|
17899
|
+
} catch {
|
|
17900
|
+
return void 0;
|
|
17901
|
+
}
|
|
17902
|
+
}
|
|
17903
|
+
function readVoiceQualification(overlayDir) {
|
|
17904
|
+
const file2 = path3.join(overlayDir, "voice-qualification.json");
|
|
17905
|
+
try {
|
|
17906
|
+
const parsed = JSON.parse(readFileSync2(file2, "utf8"));
|
|
17907
|
+
if (!isNonEmptyString(parsed.implementationRevision) || !Array.isArray(parsed.reviewedEvidence)) {
|
|
17908
|
+
return void 0;
|
|
17909
|
+
}
|
|
17910
|
+
return parsed;
|
|
17911
|
+
} catch {
|
|
17912
|
+
return void 0;
|
|
17913
|
+
}
|
|
17914
|
+
}
|
|
17915
|
+
function readVoiceIsolatedQualification(overlayDir, now = Date.now()) {
|
|
17916
|
+
const file2 = path3.join(overlayDir, VOICE_ISOLATED_QUALIFICATION_FILE);
|
|
17917
|
+
try {
|
|
17918
|
+
const parsed = JSON.parse(readFileSync2(file2, "utf8"));
|
|
17919
|
+
if (parsed !== null && typeof parsed === "object") {
|
|
17920
|
+
const expiresAtMs = isolatedQualificationExpiresAtMs(
|
|
17921
|
+
parsed.expiresAt
|
|
17922
|
+
);
|
|
17923
|
+
if (expiresAtMs !== void 0 && expiresAtMs <= now) {
|
|
17924
|
+
try {
|
|
17925
|
+
unlinkSync(file2);
|
|
17926
|
+
} catch {
|
|
17927
|
+
}
|
|
17928
|
+
return void 0;
|
|
17929
|
+
}
|
|
17930
|
+
}
|
|
17931
|
+
if (!isIsolatedVoiceQualification(parsed, now)) return void 0;
|
|
17932
|
+
return parsed;
|
|
17933
|
+
} catch {
|
|
17934
|
+
return void 0;
|
|
17935
|
+
}
|
|
17936
|
+
}
|
|
17937
|
+
function isolatedQualificationMatchesRuntime(isolated, identity2) {
|
|
17938
|
+
if (isProductionDesktopAppPath(isolated.appPath) || isProductionDesktopAppPath(identity2.appPath))
|
|
17939
|
+
return false;
|
|
17940
|
+
if (!isIsolatedDesktopPlatform(isolated.desktopPlatform) || isolated.desktopPlatform !== identity2.desktopPlatform)
|
|
17941
|
+
return false;
|
|
17942
|
+
return isolated.desktopVersion === identity2.desktopVersion && isolated.desktopBuild === identity2.desktopBuild && isolated.asarDigest === identity2.asarDigest && isolated.appPath === identity2.appPath && isolated.implementationRevision === identity2.implementationRevision;
|
|
17943
|
+
}
|
|
17944
|
+
function overlayHookDesktopVersions(overlayDir) {
|
|
17945
|
+
if (!overlayDir) return OVERLAY_VOICE_HOOK_DESKTOP_VERSIONS;
|
|
17946
|
+
return readVoiceProfilePins(overlayDir)?.overlayHookDesktopVersions ?? [];
|
|
17947
|
+
}
|
|
17948
|
+
function hashedOverlayDesktopVersion(overlayDir) {
|
|
17949
|
+
if (!overlayDir) return HASHED_WEBPACK_OVERLAY_VOICE_DESKTOP_VERSION;
|
|
17950
|
+
return readVoiceProfilePins(overlayDir)?.hashedVersion ?? "";
|
|
17951
|
+
}
|
|
17952
|
+
function overlayVoiceBootstrapPreferred(environment = process.env, overlayDir) {
|
|
17953
|
+
return environment[DESKTOP_VERSION_ENV]?.trim() === hashedOverlayDesktopVersion(overlayDir);
|
|
17954
|
+
}
|
|
17594
17955
|
function cpaLiveVoiceHookEnabled(environment = process.env) {
|
|
17595
17956
|
const value = environment[CPA_LIVE_VOICE_ENV];
|
|
17596
17957
|
if (value === "0") return false;
|
|
@@ -17627,19 +17988,72 @@ function detectInstalledDesktopVersion(environment = process.env) {
|
|
|
17627
17988
|
}
|
|
17628
17989
|
return void 0;
|
|
17629
17990
|
}
|
|
17630
|
-
function
|
|
17991
|
+
function detectInstalledDesktopBuild(environment = process.env) {
|
|
17992
|
+
const fromEnv = envNonEmpty(environment, DESKTOP_BUILD_ENV);
|
|
17993
|
+
if (fromEnv) return fromEnv;
|
|
17994
|
+
const appPath = envNonEmpty(environment, DESKTOP_APP_PATH_ENV);
|
|
17995
|
+
if (!appPath || process.platform !== "darwin") return void 0;
|
|
17996
|
+
const plist = path3.join(appPath, "Contents/Info.plist");
|
|
17997
|
+
if (!existsSync(plist)) return void 0;
|
|
17998
|
+
try {
|
|
17999
|
+
const build = execFileSync("/usr/bin/defaults", ["read", plist, "CFBundleVersion"], {
|
|
18000
|
+
encoding: "utf8",
|
|
18001
|
+
timeout: 2e3
|
|
18002
|
+
}).trim();
|
|
18003
|
+
return build || void 0;
|
|
18004
|
+
} catch {
|
|
18005
|
+
return void 0;
|
|
18006
|
+
}
|
|
18007
|
+
}
|
|
18008
|
+
function detectInstalledDesktopAsarDigest(environment = process.env) {
|
|
18009
|
+
return envNonEmpty(environment, DESKTOP_ASAR_DIGEST_ENV);
|
|
18010
|
+
}
|
|
18011
|
+
function detectLaunchedDesktopAppPath(environment = process.env) {
|
|
18012
|
+
return envNonEmpty(environment, DESKTOP_APP_PATH_ENV);
|
|
18013
|
+
}
|
|
18014
|
+
function cpaLiveVoiceOverlayHookAllowed(environment = process.env, overlayDir) {
|
|
18015
|
+
if (!cpaLiveVoiceHookEnabled(environment)) return false;
|
|
18016
|
+
const version2 = environment[DESKTOP_VERSION_ENV]?.trim();
|
|
18017
|
+
if (!version2) return true;
|
|
18018
|
+
return overlayHookDesktopVersions(overlayDir).some((pin) => pin === version2);
|
|
18019
|
+
}
|
|
18020
|
+
function cpaLiveVoiceHookBootstrap(environment = process.env, desktopVersion, overlayDir) {
|
|
17631
18021
|
if (!cpaLiveVoiceHookEnabled(environment)) return "";
|
|
17632
18022
|
const version2 = environment[DESKTOP_VERSION_ENV]?.trim() || desktopVersion || detectInstalledDesktopVersion(environment);
|
|
18023
|
+
const desktopBuild = detectInstalledDesktopBuild(environment);
|
|
18024
|
+
const asarDigest = detectInstalledDesktopAsarDigest(environment);
|
|
18025
|
+
const desktopAppPath = detectLaunchedDesktopAppPath(environment);
|
|
18026
|
+
const qualification = overlayDir ? readVoiceQualification(overlayDir) : void 0;
|
|
18027
|
+
const isolated = overlayDir ? readVoiceIsolatedQualification(overlayDir) : void 0;
|
|
18028
|
+
const isolatedQualification = isolated && isolatedQualificationMatchesRuntime(isolated, {
|
|
18029
|
+
desktopPlatform: process.platform,
|
|
18030
|
+
...version2 === void 0 ? {} : { desktopVersion: version2 },
|
|
18031
|
+
...desktopBuild === void 0 ? {} : { desktopBuild },
|
|
18032
|
+
...asarDigest === void 0 ? {} : { asarDigest },
|
|
18033
|
+
...desktopAppPath === void 0 ? {} : { appPath: desktopAppPath },
|
|
18034
|
+
...qualification === void 0 ? {} : { implementationRevision: qualification.implementationRevision }
|
|
18035
|
+
}) ? isolated : void 0;
|
|
17633
18036
|
return `globalThis.${CPA_LIVE_VOICE_HOOK_GLOBAL} = Object.freeze(${JSON.stringify({
|
|
17634
18037
|
enabled: true,
|
|
17635
18038
|
desktopPlatform: process.platform,
|
|
17636
18039
|
auditedDesktopVersion: AUDITED_CPA_LIVE_VOICE_DESKTOP_VERSION,
|
|
17637
18040
|
auditedAppInitialAsset: AUDITED_CPA_LIVE_VOICE_APP_INITIAL_ASSET,
|
|
17638
|
-
...version2 ? { desktopVersion: version2 } : {}
|
|
18041
|
+
...version2 ? { desktopVersion: version2 } : {},
|
|
18042
|
+
...desktopBuild ? { desktopBuild } : {},
|
|
18043
|
+
...asarDigest ? { asarDigest } : {},
|
|
18044
|
+
...desktopAppPath ? { desktopAppPath } : {},
|
|
18045
|
+
...qualification ? {
|
|
18046
|
+
implementationRevision: qualification.implementationRevision,
|
|
18047
|
+
voiceEvidence: qualification.reviewedEvidence
|
|
18048
|
+
} : {},
|
|
18049
|
+
...isolatedQualification ? { isolatedQualification } : {}
|
|
17639
18050
|
})});
|
|
17640
18051
|
`;
|
|
17641
18052
|
}
|
|
17642
18053
|
|
|
18054
|
+
// packages/desktop-control/src/renderer-cdp-control-session.ts
|
|
18055
|
+
import { createHash } from "node:crypto";
|
|
18056
|
+
|
|
17643
18057
|
// packages/desktop-control/src/browser-annotation-style-compat.ts
|
|
17644
18058
|
var BROWSER_ANNOTATION_STYLE_COMPAT_SOURCE = String.raw`(() => {
|
|
17645
18059
|
const key = '__codexhostBrowserAnnotationStylesV1';
|
|
@@ -17742,13 +18156,13 @@ function committedReactAncestors(value) {
|
|
|
17742
18156
|
const current = fiber(rootState.current);
|
|
17743
18157
|
if (!current) return [];
|
|
17744
18158
|
const alternate = fiber(first.alternate);
|
|
17745
|
-
const
|
|
18159
|
+
const path7 = [current];
|
|
17746
18160
|
seen.clear();
|
|
17747
18161
|
seen.add(current);
|
|
17748
18162
|
for (let index = previous.length - 2; index >= 0; index -= 1) {
|
|
17749
18163
|
const expected = previous[index];
|
|
17750
18164
|
const expectedAlternate = fiber(expected?.alternate);
|
|
17751
|
-
let child = fiber(
|
|
18165
|
+
let child = fiber(path7.at(-1)?.child);
|
|
17752
18166
|
let matched = false;
|
|
17753
18167
|
while (child && !seen.has(child) && seen.size < MAX_VISITED_FIBERS) {
|
|
17754
18168
|
seen.add(child);
|
|
@@ -17759,10 +18173,10 @@ function committedReactAncestors(value) {
|
|
|
17759
18173
|
child = fiber(child.sibling);
|
|
17760
18174
|
}
|
|
17761
18175
|
if (!matched || !child) break;
|
|
17762
|
-
|
|
18176
|
+
path7.push(child);
|
|
17763
18177
|
}
|
|
17764
|
-
if (
|
|
17765
|
-
return
|
|
18178
|
+
if (path7.length === previous.length && (path7.at(-1) === first || path7.at(-1) === alternate)) {
|
|
18179
|
+
return path7.reverse();
|
|
17766
18180
|
}
|
|
17767
18181
|
const stack = [{ node: current, parent: null }];
|
|
17768
18182
|
seen.clear();
|
|
@@ -17790,7 +18204,7 @@ function retainRendererHostResponses(client, hostId2, target2) {
|
|
|
17790
18204
|
if (typeof client.addRequestLifecycleListener !== "function" || typeof target2.addEventListener !== "function" || typeof target2.removeEventListener !== "function")
|
|
17791
18205
|
return () => {
|
|
17792
18206
|
};
|
|
17793
|
-
const
|
|
18207
|
+
const isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17794
18208
|
const pending = /* @__PURE__ */ new Set();
|
|
17795
18209
|
let retired = false;
|
|
17796
18210
|
let unsubscribe = () => {
|
|
@@ -17804,12 +18218,12 @@ function retainRendererHostResponses(client, hostId2, target2) {
|
|
|
17804
18218
|
if (source != null && source !== target2) return;
|
|
17805
18219
|
const ownOrigin = target2.location?.origin;
|
|
17806
18220
|
if (source === target2 && ownOrigin && ownOrigin !== "null" && origin !== ownOrigin) return;
|
|
17807
|
-
if (!
|
|
18221
|
+
if (!isRecord4(data) || data.type !== "mcp-response" || data.hostId !== hostId2) return;
|
|
17808
18222
|
const message = data.message;
|
|
17809
|
-
if (!
|
|
18223
|
+
if (!isRecord4(message)) return;
|
|
17810
18224
|
const id = message.id;
|
|
17811
18225
|
if (typeof id !== "string" && typeof id !== "number" || !pending.has(id)) return;
|
|
17812
|
-
const hasError =
|
|
18226
|
+
const hasError = isRecord4(message.error);
|
|
17813
18227
|
if (!hasError && !Object.prototype.hasOwnProperty.call(message, "result")) return;
|
|
17814
18228
|
queueMicrotask(() => {
|
|
17815
18229
|
if (!pending.has(id)) return;
|
|
@@ -17819,7 +18233,7 @@ function retainRendererHostResponses(client, hostId2, target2) {
|
|
|
17819
18233
|
};
|
|
17820
18234
|
target2.addEventListener("message", receive);
|
|
17821
18235
|
unsubscribe = client.addRequestLifecycleListener((event) => {
|
|
17822
|
-
if (!
|
|
18236
|
+
if (!isRecord4(event) || event.hostId !== hostId2) return;
|
|
17823
18237
|
const id = event.id;
|
|
17824
18238
|
if (typeof id !== "string" && typeof id !== "number") return;
|
|
17825
18239
|
if (!retired && event.type === "started" && typeof event.method === "string" && event.method.startsWith("codexhost/"))
|
|
@@ -17937,13 +18351,13 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
17937
18351
|
let selectedModel = null;
|
|
17938
18352
|
let prewarmGeneration = 0;
|
|
17939
18353
|
const externalPrewarms = /* @__PURE__ */ new Set();
|
|
17940
|
-
const
|
|
18354
|
+
const isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17941
18355
|
const isUnsupportedPosixBridgeSpawn = (value) => {
|
|
17942
18356
|
const marker = "AbsolutePathBuf deserialized without a base path";
|
|
17943
18357
|
if (typeof value === "string") {
|
|
17944
18358
|
return value.startsWith("Invalid request:") && value.includes(marker);
|
|
17945
18359
|
}
|
|
17946
|
-
if (!
|
|
18360
|
+
if (!isRecord4(value)) return false;
|
|
17947
18361
|
if (typeof value.message === "string" && value.message.includes(marker)) {
|
|
17948
18362
|
if (value.code === -32600 || value.message.startsWith("Invalid request:")) return true;
|
|
17949
18363
|
}
|
|
@@ -18034,14 +18448,14 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18034
18448
|
bridgeState = "idle";
|
|
18035
18449
|
};
|
|
18036
18450
|
const rememberExternalThread = (value) => {
|
|
18037
|
-
if (!
|
|
18451
|
+
if (!isRecord4(value) || typeof value.id !== "string") return;
|
|
18038
18452
|
if (value.modelProvider === "codexhost" || value.cliVersion === "codexhost") {
|
|
18039
18453
|
knownExternalThreadIds.add(value.id);
|
|
18040
18454
|
knownOfficialThreadIds.delete(value.id);
|
|
18041
18455
|
}
|
|
18042
18456
|
};
|
|
18043
18457
|
const observeBridgeResult = (request, result) => {
|
|
18044
|
-
if (!request || !
|
|
18458
|
+
if (!request || !isRecord4(result)) return;
|
|
18045
18459
|
if (request.method === "thread/list" && Array.isArray(result.data)) {
|
|
18046
18460
|
for (const thread2 of result.data) rememberExternalThread(thread2);
|
|
18047
18461
|
return;
|
|
@@ -18050,7 +18464,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18050
18464
|
rememberExternalThread(result.thread);
|
|
18051
18465
|
return;
|
|
18052
18466
|
}
|
|
18053
|
-
if (request.method === "codexhost/thread/inspect" &&
|
|
18467
|
+
if (request.method === "codexhost/thread/inspect" && isRecord4(request.parameters) && typeof request.parameters.threadId === "string") {
|
|
18054
18468
|
if (result.owner === "external") {
|
|
18055
18469
|
knownExternalThreadIds.add(request.parameters.threadId);
|
|
18056
18470
|
knownOfficialThreadIds.delete(request.parameters.threadId);
|
|
@@ -18060,18 +18474,18 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18060
18474
|
}
|
|
18061
18475
|
return;
|
|
18062
18476
|
}
|
|
18063
|
-
if (request.method === "thread/delete" &&
|
|
18477
|
+
if (request.method === "thread/delete" && isRecord4(request.parameters) && typeof request.parameters.threadId === "string") {
|
|
18064
18478
|
knownExternalThreadIds.delete(request.parameters.threadId);
|
|
18065
18479
|
knownOfficialThreadIds.delete(request.parameters.threadId);
|
|
18066
18480
|
}
|
|
18067
18481
|
};
|
|
18068
18482
|
const handleBridgeFrame = (value) => {
|
|
18069
|
-
if (!
|
|
18483
|
+
if (!isRecord4(value)) {
|
|
18070
18484
|
failBridge("received a non-object app-server frame");
|
|
18071
18485
|
return;
|
|
18072
18486
|
}
|
|
18073
18487
|
if (value.method === bridgeReadyMethod && value.id === void 0) {
|
|
18074
|
-
if (
|
|
18488
|
+
if (isRecord4(value.params) && value.params.protocolVersion === 1) {
|
|
18075
18489
|
bridgeState = "ready";
|
|
18076
18490
|
if (bridgeReadyTimeout !== null) globalThis.clearTimeout(bridgeReadyTimeout);
|
|
18077
18491
|
bridgeReadyTimeout = null;
|
|
@@ -18084,7 +18498,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18084
18498
|
return;
|
|
18085
18499
|
}
|
|
18086
18500
|
if (typeof value.method === "string" && value.id === void 0) {
|
|
18087
|
-
if (value.method === "thread/started" &&
|
|
18501
|
+
if (value.method === "thread/started" && isRecord4(value.params)) {
|
|
18088
18502
|
rememberExternalThread(value.params.thread);
|
|
18089
18503
|
}
|
|
18090
18504
|
originalOnNotification.call(manager, value.method, value.params);
|
|
@@ -18135,7 +18549,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18135
18549
|
}
|
|
18136
18550
|
};
|
|
18137
18551
|
const handleOuterNotification = (method, parameters) => {
|
|
18138
|
-
if (method === "process/exited" &&
|
|
18552
|
+
if (method === "process/exited" && isRecord4(parameters) && parameters.processHandle === bridgeProcessHandle) {
|
|
18139
18553
|
const exitCode = typeof parameters.exitCode === "number" ? parameters.exitCode : "unknown";
|
|
18140
18554
|
const stderr = typeof parameters.stderr === "string" ? parameters.stderr.trim() : "";
|
|
18141
18555
|
failBridge(
|
|
@@ -18144,7 +18558,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18144
18558
|
);
|
|
18145
18559
|
return true;
|
|
18146
18560
|
}
|
|
18147
|
-
if (method !== "process/outputDelta" || !
|
|
18561
|
+
if (method !== "process/outputDelta" || !isRecord4(parameters) || parameters.processHandle !== bridgeProcessHandle || parameters.stream !== "stdout" && parameters.stream !== "stderr" || typeof parameters.deltaBase64 !== "string") {
|
|
18148
18562
|
return false;
|
|
18149
18563
|
}
|
|
18150
18564
|
if (parameters.capReached === true) {
|
|
@@ -18249,7 +18663,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18249
18663
|
return bridgeInitialization;
|
|
18250
18664
|
};
|
|
18251
18665
|
const threadIdFromParameters = (parameters) => {
|
|
18252
|
-
if (!
|
|
18666
|
+
if (!isRecord4(parameters)) return null;
|
|
18253
18667
|
const value = parameters.threadId ?? parameters.conversationId;
|
|
18254
18668
|
return typeof value === "string" ? value : null;
|
|
18255
18669
|
};
|
|
@@ -18264,9 +18678,9 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18264
18678
|
threadIds: [threadId]
|
|
18265
18679
|
})
|
|
18266
18680
|
).then((value) => {
|
|
18267
|
-
const ownerships =
|
|
18681
|
+
const ownerships = isRecord4(value) && Array.isArray(value.threads) ? value.threads : null;
|
|
18268
18682
|
const ownership = ownerships?.[0];
|
|
18269
|
-
if (!ownerships || !
|
|
18683
|
+
if (!ownerships || !isRecord4(ownership) || ownerships.length !== 1 || ownership.threadId !== threadId || ownership.owner !== "external" && ownership.owner !== "codex") {
|
|
18270
18684
|
throw transportError("Thread ownership lookup returned an invalid result");
|
|
18271
18685
|
}
|
|
18272
18686
|
if (ownership.owner === "external") {
|
|
@@ -18302,7 +18716,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18302
18716
|
if (method.startsWith("codexhost/")) return true;
|
|
18303
18717
|
if (method === "thread/list") return true;
|
|
18304
18718
|
if (method === "thread/start") {
|
|
18305
|
-
return
|
|
18719
|
+
return isRecord4(parameters) && typeof parameters.model === "string" && parameters.model.startsWith("codexhost/");
|
|
18306
18720
|
}
|
|
18307
18721
|
const threadId = threadIdFromParameters(parameters);
|
|
18308
18722
|
if (threadId && knownExternalThreadIds.has(threadId)) return true;
|
|
@@ -18337,10 +18751,10 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18337
18751
|
return shouldUseBridge(method, parameters) ? sendBridged() : sendDirect();
|
|
18338
18752
|
};
|
|
18339
18753
|
const publishDraftWorkspace = (parameters) => {
|
|
18340
|
-
if (!
|
|
18754
|
+
if (!isRecord4(parameters) || parameters.ephemeral === true) return;
|
|
18341
18755
|
const cwd = parameters.cwd;
|
|
18342
18756
|
if (typeof cwd !== "string" || cwd.length === 0) return;
|
|
18343
|
-
const drafts =
|
|
18757
|
+
const drafts = isRecord4(target2.__codexhostDraftWorkspacesV1) ? target2.__codexhostDraftWorkspacesV1 : {};
|
|
18344
18758
|
drafts[hostId2] = cwd;
|
|
18345
18759
|
Object.defineProperty(target2, "__codexhostDraftWorkspacesV1", {
|
|
18346
18760
|
configurable: true,
|
|
@@ -18366,16 +18780,16 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18366
18780
|
};
|
|
18367
18781
|
const restoreConsumption = isolateConsumption(manager, discardExternalPrewarm);
|
|
18368
18782
|
const routedPrewarm = (parameters, options) => {
|
|
18369
|
-
const external =
|
|
18783
|
+
const external = isRecord4(parameters) && parameters.ephemeral !== true && typeof parameters.model === "string" && parameters.model.startsWith("codexhost/");
|
|
18370
18784
|
const routedParameters = external ? { ...parameters, codexhostPrewarm: true } : parameters;
|
|
18371
18785
|
const generation = prewarmGeneration;
|
|
18372
18786
|
publishDraftWorkspace(routedParameters);
|
|
18373
18787
|
const pending = shouldUseBridge("thread/start", routedParameters) ? routedSend("thread/start", routedParameters, options) : options === void 0 ? originalPrewarm.call(bridge, routedParameters) : originalPrewarm.call(bridge, routedParameters, options);
|
|
18374
|
-
if (
|
|
18788
|
+
if (isRecord4(parameters) && parameters.ephemeral === true || typeof pending !== "object" && typeof pending !== "function" || pending === null || typeof Reflect.get(pending, "then") !== "function") {
|
|
18375
18789
|
return pending;
|
|
18376
18790
|
}
|
|
18377
18791
|
return Promise.resolve(pending).then((result) => {
|
|
18378
|
-
const threadId = external &&
|
|
18792
|
+
const threadId = external && isRecord4(result) && isRecord4(result.thread) && typeof result.thread.id === "string" ? result.thread.id : null;
|
|
18379
18793
|
if (disposed || generation !== prewarmGeneration) {
|
|
18380
18794
|
if (threadId) discardExternalPrewarm(threadId);
|
|
18381
18795
|
throw new Error("Renderer draft prewarm was invalidated by a configuration change");
|
|
@@ -18389,7 +18803,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
18389
18803
|
bridge.prewarmThreadStart = routedPrewarm;
|
|
18390
18804
|
const routedWindowMessage = (event) => {
|
|
18391
18805
|
const message = event.data;
|
|
18392
|
-
if (!
|
|
18806
|
+
if (!isRecord4(message) || message.type !== "mcp-notification" || message.hostId !== hostId2 || typeof message.method !== "string") {
|
|
18393
18807
|
return;
|
|
18394
18808
|
}
|
|
18395
18809
|
handleOuterNotification(message.method, message.params);
|
|
@@ -18871,15 +19285,15 @@ function installRendererExternalQueuePolicy(root, target2, dependencies) {
|
|
|
18871
19285
|
const expression = message[1];
|
|
18872
19286
|
if (!Array.isArray(expression) || expression.length !== 4 || expression[0] !== "pipeline")
|
|
18873
19287
|
return message;
|
|
18874
|
-
const [, importId,
|
|
18875
|
-
if (!Array.isArray(
|
|
19288
|
+
const [, importId, path7, args] = expression;
|
|
19289
|
+
if (!Array.isArray(path7) || path7.length !== 1 || path7[0] !== "sendMessage" || !Array.isArray(args))
|
|
18876
19290
|
return message;
|
|
18877
19291
|
const input = args[0];
|
|
18878
19292
|
if (!record4(input) || typeof input.conversationId !== "string" || !record4(input.message) || !dependencies.usesExternalQueue(store, input.conversationId))
|
|
18879
19293
|
return message;
|
|
18880
19294
|
return [
|
|
18881
19295
|
"push",
|
|
18882
|
-
["pipeline", importId,
|
|
19296
|
+
["pipeline", importId, path7, [{ ...input, queueModeOverride: "queue" }, ...args.slice(1)]]
|
|
18883
19297
|
];
|
|
18884
19298
|
};
|
|
18885
19299
|
const port = dependencies.portPrototype;
|
|
@@ -18946,7 +19360,7 @@ function installRendererHostRpcRouting(root, target2, dependencies) {
|
|
|
18946
19360
|
}
|
|
18947
19361
|
};
|
|
18948
19362
|
const sameConnection = (previous, current) => previous === void 0 ? current === void 0 : current?.owner === previous.owner && current.revision === previous.revision;
|
|
18949
|
-
const
|
|
19363
|
+
const isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18950
19364
|
const externalDrafts = /* @__PURE__ */ new Map();
|
|
18951
19365
|
const selectedModels = /* @__PURE__ */ new Map();
|
|
18952
19366
|
const prewarmCarrier = (carrier) => {
|
|
@@ -18955,7 +19369,7 @@ function installRendererHostRpcRouting(root, target2, dependencies) {
|
|
|
18955
19369
|
try {
|
|
18956
19370
|
const json2 = carrier.slice(prefix.length).replace(/[a-f0-9]{2}/gu, (byte) => String.fromCharCode(Number.parseInt(byte, 16)));
|
|
18957
19371
|
const route = JSON.parse(json2);
|
|
18958
|
-
if (!
|
|
19372
|
+
if (!isRecord4(route)) return null;
|
|
18959
19373
|
const payload = [...JSON.stringify({ ...route, prewarm: true })].map((character) => character.charCodeAt(0).toString(16).padStart(2, "0")).join("");
|
|
18960
19374
|
return `${prefix}${payload}`;
|
|
18961
19375
|
} catch {
|
|
@@ -18964,7 +19378,7 @@ function installRendererHostRpcRouting(root, target2, dependencies) {
|
|
|
18964
19378
|
};
|
|
18965
19379
|
const publishDraftWorkspace = (hostId2, cwd) => {
|
|
18966
19380
|
if (typeof cwd !== "string" || cwd.length === 0) return;
|
|
18967
|
-
const drafts =
|
|
19381
|
+
const drafts = isRecord4(target2.__codexhostDraftWorkspacesV1) ? target2.__codexhostDraftWorkspacesV1 : {};
|
|
18968
19382
|
if (drafts[hostId2] === cwd) return;
|
|
18969
19383
|
drafts[hostId2] = cwd;
|
|
18970
19384
|
Object.defineProperty(target2, "__codexhostDraftWorkspacesV1", {
|
|
@@ -18982,32 +19396,32 @@ function installRendererHostRpcRouting(root, target2, dependencies) {
|
|
|
18982
19396
|
const expression = message[1];
|
|
18983
19397
|
if (!Array.isArray(expression) || expression.length !== 4 || expression[0] !== "pipeline")
|
|
18984
19398
|
return message;
|
|
18985
|
-
const [, importId,
|
|
18986
|
-
if (!Array.isArray(
|
|
19399
|
+
const [, importId, path7, args] = expression;
|
|
19400
|
+
if (!Array.isArray(path7) || path7.length !== 1 || !Array.isArray(args)) return message;
|
|
18987
19401
|
const [input, options] = args;
|
|
18988
|
-
if (!
|
|
19402
|
+
if (!isRecord4(input) || !isRecord4(input.collaborationMode)) return message;
|
|
18989
19403
|
const settings = input.collaborationMode.settings;
|
|
18990
|
-
if (!
|
|
19404
|
+
if (!isRecord4(settings)) return message;
|
|
18991
19405
|
const nativeModel = typeof settings.model === "string" ? settings.model : null;
|
|
18992
19406
|
let model2 = null;
|
|
18993
|
-
if (
|
|
18994
|
-
const draftId =
|
|
19407
|
+
if (path7[0] === "startConversation") {
|
|
19408
|
+
const draftId = isRecord4(options) ? options.clientThreadId : null;
|
|
18995
19409
|
model2 = typeof draftId === "string" ? externalDrafts.get(draftId)?.model ?? null : null;
|
|
18996
|
-
} else if (
|
|
19410
|
+
} else if (path7[0] === "prewarmConversation") {
|
|
18997
19411
|
if (input.ephemeral !== true) publishDraftWorkspace("local", input.cwd);
|
|
18998
19412
|
const selected = selectedModels.get("local") ?? null;
|
|
18999
19413
|
const carrier = nativeModel?.startsWith("codexhost/") ? nativeModel : selected;
|
|
19000
19414
|
model2 = carrier ? prewarmCarrier(carrier) : null;
|
|
19001
19415
|
}
|
|
19002
19416
|
if (!model2) return message;
|
|
19003
|
-
if (
|
|
19417
|
+
if (path7[0] === "startConversation" && nativeModel?.startsWith("codexhost/") && nativeModel !== model2)
|
|
19004
19418
|
return message;
|
|
19005
19419
|
return [
|
|
19006
19420
|
"push",
|
|
19007
19421
|
[
|
|
19008
19422
|
"pipeline",
|
|
19009
19423
|
importId,
|
|
19010
|
-
|
|
19424
|
+
path7,
|
|
19011
19425
|
[
|
|
19012
19426
|
{
|
|
19013
19427
|
...input,
|
|
@@ -19075,7 +19489,7 @@ function installRendererHostRpcRouting(root, target2, dependencies) {
|
|
|
19075
19489
|
const onMessage = (event) => {
|
|
19076
19490
|
const { source, data } = event;
|
|
19077
19491
|
if (source != null && source !== target2) return;
|
|
19078
|
-
if (!
|
|
19492
|
+
if (!isRecord4(data) || data.type !== "mcp-notification" || data.hostId !== hostId2 || typeof data.method !== "string" || !accepted.has(data.method) || !isCurrent())
|
|
19079
19493
|
return;
|
|
19080
19494
|
listener({ method: data.method, params: data.params });
|
|
19081
19495
|
};
|
|
@@ -20269,7 +20683,7 @@ async function installRendererRpcSteeringDirect(client, now = Date.now) {
|
|
|
20269
20683
|
try {
|
|
20270
20684
|
const needed = await client.evaluate(`(() => {
|
|
20271
20685
|
const steering = window.__codexhostRpcSteeringV1;
|
|
20272
|
-
if (steering && steering.controller.forHost === steering.forHost) return false;
|
|
20686
|
+
if (steering && (steering.owns?.() ?? steering.controller.forHost === steering.forHost)) return false;
|
|
20273
20687
|
steering?.release();
|
|
20274
20688
|
const routing=window.__codexhostHostRoutingV1;
|
|
20275
20689
|
return ['local', ...(routing?.knownHostIds?.() ?? [])].some(id => routing?.forHost(id)?.manager.kind === 'main-process-rpc');
|
|
@@ -20372,10 +20786,525 @@ async function discoverAndInstall(client) {
|
|
|
20372
20786
|
}
|
|
20373
20787
|
}
|
|
20374
20788
|
|
|
20375
|
-
// packages/desktop-control/src/renderer-
|
|
20789
|
+
// packages/desktop-control/src/renderer-app-url.ts
|
|
20790
|
+
function parseCodexAppUrl(value) {
|
|
20791
|
+
try {
|
|
20792
|
+
const url2 = new URL(value);
|
|
20793
|
+
return url2.protocol === "app:" && url2.hostname === "-" ? url2 : null;
|
|
20794
|
+
} catch {
|
|
20795
|
+
return null;
|
|
20796
|
+
}
|
|
20797
|
+
}
|
|
20798
|
+
function isPrimaryRendererUrl(value) {
|
|
20799
|
+
const url2 = parseCodexAppUrl(value);
|
|
20800
|
+
return url2 !== null && url2.pathname === "/index.html" && url2.search === "" && url2.hash === "";
|
|
20801
|
+
}
|
|
20802
|
+
function isAvatarOverlayRendererUrl(value) {
|
|
20803
|
+
const url2 = parseCodexAppUrl(value);
|
|
20804
|
+
if (!url2) return false;
|
|
20805
|
+
if (url2.pathname === "/avatar-overlay.html") return true;
|
|
20806
|
+
return url2.pathname === "/index.html" && url2.searchParams.get("initialRoute") === "/avatar-overlay";
|
|
20807
|
+
}
|
|
20808
|
+
function isEligibleVoiceHostUrl(value) {
|
|
20809
|
+
return isPrimaryRendererUrl(value) || isAvatarOverlayRendererUrl(value);
|
|
20810
|
+
}
|
|
20811
|
+
function rendererVoiceHostDocumentGuardExpression() {
|
|
20812
|
+
return `(function(){try{
|
|
20813
|
+
if (window.top !== window) return false;
|
|
20814
|
+
var url = new URL(location.href);
|
|
20815
|
+
if (url.protocol !== "app:" || url.hostname !== "-") return false;
|
|
20816
|
+
if (url.pathname === "/avatar-overlay.html") return true;
|
|
20817
|
+
if (url.pathname !== "/index.html") return false;
|
|
20818
|
+
if (url.search === "" && url.hash === "") return true;
|
|
20819
|
+
return url.searchParams.get("initialRoute") === "/avatar-overlay";
|
|
20820
|
+
}catch(e){return false;}})()`;
|
|
20821
|
+
}
|
|
20822
|
+
|
|
20823
|
+
// packages/desktop-control/src/renderer-voice-host-binding.ts
|
|
20824
|
+
var RENDERER_VOICE_HOST_BINDING_NAME = "__codexhostVoiceHostBindingV1";
|
|
20825
|
+
var RENDERER_VOICE_HOST_CAPABILITY_GLOBAL = "__codexhostVoiceHostV1";
|
|
20826
|
+
var RENDERER_VOICE_HOST_DELIVER_GLOBAL = "__codexhostVoiceHostDeliverV1";
|
|
20827
|
+
var RENDERER_VOICE_HOST_PENDING_GLOBAL = "__codexhostVoiceHostPendingV1";
|
|
20828
|
+
var RENDERER_VOICE_HOST_MAX_PAYLOAD_BYTES = 256 * 1024;
|
|
20829
|
+
var RENDERER_VOICE_HOST_SETTINGS_TIMEOUT_MS = 1e4;
|
|
20830
|
+
var RENDERER_VOICE_HOST_GATEWAY_TIMEOUT_MS = 2e3;
|
|
20831
|
+
var RENDERER_VOICE_HOST_REALTIME_TIMEOUT_MS = 3e4;
|
|
20832
|
+
var RENDERER_VOICE_HOST_METHODS = [
|
|
20833
|
+
VOICE_SETTINGS_METHOD,
|
|
20834
|
+
VOICE_GATEWAY_STATUS_METHOD,
|
|
20835
|
+
REALTIME_CALL_METHOD
|
|
20836
|
+
];
|
|
20837
|
+
var ALLOWED_METHODS = new Set(RENDERER_VOICE_HOST_METHODS);
|
|
20838
|
+
var STALE_CONTEXT = /uniqueContextId not found|Cannot find context with specified id|Execution context was destroyed|Cannot find default execution context/i;
|
|
20839
|
+
var UNAVAILABLE = "Local Host connection is unavailable";
|
|
20840
|
+
var UNKNOWN_OUTCOME = "Host request outcome is unknown. Do not retry automatically.";
|
|
20841
|
+
var RENDERER_VOICE_HOST_CLEANUP_UNCONFIRMED = "Original Host owner is unreachable; cleanup is unconfirmed. Do not retry automatically.";
|
|
20376
20842
|
function isRecord2(value) {
|
|
20377
20843
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20378
20844
|
}
|
|
20845
|
+
function allowlistedStage(value) {
|
|
20846
|
+
return value === "config" || value === "request" || value === "transport" || value === "identity" || value === "cancel" ? value : void 0;
|
|
20847
|
+
}
|
|
20848
|
+
function isCreateOperation(method, params) {
|
|
20849
|
+
return method === REALTIME_CALL_METHOD && params.operation === "create";
|
|
20850
|
+
}
|
|
20851
|
+
function cleanupUnconfirmedError(error51) {
|
|
20852
|
+
if (error51 instanceof Error && error51.message === RENDERER_VOICE_HOST_CLEANUP_UNCONFIRMED && allowlistedStage(Reflect.get(error51, "stage")) === "cancel")
|
|
20853
|
+
return error51;
|
|
20854
|
+
}
|
|
20855
|
+
function rendererVoiceHostCapabilitySource(owner, generation) {
|
|
20856
|
+
const guard = rendererVoiceHostDocumentGuardExpression();
|
|
20857
|
+
return `(() => {
|
|
20858
|
+
if (!${guard}) return true;
|
|
20859
|
+
const binding = ${JSON.stringify(RENDERER_VOICE_HOST_BINDING_NAME)};
|
|
20860
|
+
const cap = ${JSON.stringify(RENDERER_VOICE_HOST_CAPABILITY_GLOBAL)};
|
|
20861
|
+
const deliver = ${JSON.stringify(RENDERER_VOICE_HOST_DELIVER_GLOBAL)};
|
|
20862
|
+
const pendingKey = ${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)};
|
|
20863
|
+
const allowed = ${JSON.stringify([...RENDERER_VOICE_HOST_METHODS])};
|
|
20864
|
+
const maxBytes = ${RENDERER_VOICE_HOST_MAX_PAYLOAD_BYTES};
|
|
20865
|
+
const ownerId = ${JSON.stringify(owner)};
|
|
20866
|
+
const generation = ${generation};
|
|
20867
|
+
const settingsTimeout = ${RENDERER_VOICE_HOST_SETTINGS_TIMEOUT_MS};
|
|
20868
|
+
const gatewayTimeout = ${RENDERER_VOICE_HOST_GATEWAY_TIMEOUT_MS};
|
|
20869
|
+
const realtimeTimeout = ${RENDERER_VOICE_HOST_REALTIME_TIMEOUT_MS};
|
|
20870
|
+
const pending = globalThis[pendingKey] instanceof Map ? globalThis[pendingKey] : new Map();
|
|
20871
|
+
globalThis[pendingKey] = pending;
|
|
20872
|
+
const unavailable = () => Promise.reject(new Error(${JSON.stringify(UNAVAILABLE)}));
|
|
20873
|
+
const settleWait = (wait, message) => {
|
|
20874
|
+
try { clearTimeout(wait.timer); } catch (e) {}
|
|
20875
|
+
try { wait.reject(new Error(message)); } catch (e) {}
|
|
20876
|
+
};
|
|
20877
|
+
const settleAll = (message) => {
|
|
20878
|
+
for (const [id, wait] of [...pending.entries()]) {
|
|
20879
|
+
pending.delete(id);
|
|
20880
|
+
settleWait(wait, message);
|
|
20881
|
+
}
|
|
20882
|
+
};
|
|
20883
|
+
const previous = globalThis[cap];
|
|
20884
|
+
if (previous && previous.generation !== generation) settleAll(${JSON.stringify(UNAVAILABLE)});
|
|
20885
|
+
globalThis[deliver] = (message) => {
|
|
20886
|
+
if (!message || typeof message !== "object" || typeof message.id !== "string") return;
|
|
20887
|
+
const wait = pending.get(message.id);
|
|
20888
|
+
if (!wait) return;
|
|
20889
|
+
pending.delete(message.id);
|
|
20890
|
+
try { clearTimeout(wait.timer); } catch (e) {}
|
|
20891
|
+
if (message.ok) {
|
|
20892
|
+
wait.resolve(message.result);
|
|
20893
|
+
return;
|
|
20894
|
+
}
|
|
20895
|
+
const error = new Error(
|
|
20896
|
+
typeof message.error === "string" && message.error.length > 0 && message.error.length <= 500
|
|
20897
|
+
? message.error
|
|
20898
|
+
: "Host request failed",
|
|
20899
|
+
);
|
|
20900
|
+
if (typeof message.stage === "string") error.stage = message.stage;
|
|
20901
|
+
wait.reject(error);
|
|
20902
|
+
};
|
|
20903
|
+
Object.defineProperty(globalThis, cap, {
|
|
20904
|
+
configurable: true,
|
|
20905
|
+
value: Object.freeze({
|
|
20906
|
+
owner: ownerId,
|
|
20907
|
+
generation,
|
|
20908
|
+
request(method, params) {
|
|
20909
|
+
try {
|
|
20910
|
+
if (!${guard}) return unavailable();
|
|
20911
|
+
if (typeof method !== "string" || !allowed.includes(method)) return unavailable();
|
|
20912
|
+
const body = params !== null && typeof params === "object" && !Array.isArray(params) ? params : {};
|
|
20913
|
+
const id = crypto.randomUUID();
|
|
20914
|
+
const payload = JSON.stringify({ v: 1, id, owner: ownerId, generation, method, params: body });
|
|
20915
|
+
if (payload.length > maxBytes) return Promise.reject(new Error("Voice request is too large"));
|
|
20916
|
+
const timeoutMs =
|
|
20917
|
+
method === ${JSON.stringify(VOICE_GATEWAY_STATUS_METHOD)}
|
|
20918
|
+
? gatewayTimeout
|
|
20919
|
+
: method === ${JSON.stringify(REALTIME_CALL_METHOD)}
|
|
20920
|
+
? realtimeTimeout
|
|
20921
|
+
: settingsTimeout;
|
|
20922
|
+
return new Promise((resolve, reject) => {
|
|
20923
|
+
const timer = setTimeout(() => {
|
|
20924
|
+
if (!pending.has(id)) return;
|
|
20925
|
+
pending.delete(id);
|
|
20926
|
+
try {
|
|
20927
|
+
globalThis[binding](JSON.stringify({
|
|
20928
|
+
v: 1,
|
|
20929
|
+
id,
|
|
20930
|
+
owner: ownerId,
|
|
20931
|
+
generation,
|
|
20932
|
+
abandon: true,
|
|
20933
|
+
method,
|
|
20934
|
+
params: body,
|
|
20935
|
+
}));
|
|
20936
|
+
} catch (e) {}
|
|
20937
|
+
reject(new Error(${JSON.stringify(UNAVAILABLE)}));
|
|
20938
|
+
}, timeoutMs);
|
|
20939
|
+
pending.set(id, { resolve, reject, timer, generation });
|
|
20940
|
+
try {
|
|
20941
|
+
globalThis[binding](payload);
|
|
20942
|
+
} catch {
|
|
20943
|
+
pending.delete(id);
|
|
20944
|
+
try { clearTimeout(timer); } catch (e) {}
|
|
20945
|
+
reject(new Error(${JSON.stringify(UNAVAILABLE)}));
|
|
20946
|
+
}
|
|
20947
|
+
});
|
|
20948
|
+
} catch {
|
|
20949
|
+
return unavailable();
|
|
20950
|
+
}
|
|
20951
|
+
},
|
|
20952
|
+
}),
|
|
20953
|
+
});
|
|
20954
|
+
return true;
|
|
20955
|
+
})()`;
|
|
20956
|
+
}
|
|
20957
|
+
function evaluateResultValue(response) {
|
|
20958
|
+
if (!isRecord2(response) || isRecord2(response.exceptionDetails)) return;
|
|
20959
|
+
return isRecord2(response.result) ? response.result.value : void 0;
|
|
20960
|
+
}
|
|
20961
|
+
function callIdFromCreateResult(result) {
|
|
20962
|
+
if (!isRecord2(result) || !isRecord2(result.headers)) return;
|
|
20963
|
+
const location = result.headers.location;
|
|
20964
|
+
if (typeof location !== "string") return;
|
|
20965
|
+
const callId = realtimeCallIdFromLocation(location);
|
|
20966
|
+
return isRealtimeCallId(callId) ? callId : void 0;
|
|
20967
|
+
}
|
|
20968
|
+
async function cleanupAbandonedCreate(execution, params, result) {
|
|
20969
|
+
let unconfirmed;
|
|
20970
|
+
const note = (error51) => {
|
|
20971
|
+
unconfirmed ??= cleanupUnconfirmedError(error51);
|
|
20972
|
+
};
|
|
20973
|
+
const requestId2 = typeof params.requestId === "string" ? params.requestId : void 0;
|
|
20974
|
+
if (requestId2) {
|
|
20975
|
+
await execution.request(REALTIME_CALL_METHOD, { operation: "cancel", requestId: requestId2 }).catch(note);
|
|
20976
|
+
}
|
|
20977
|
+
const callId = callIdFromCreateResult(result);
|
|
20978
|
+
if (!callId) return unconfirmed;
|
|
20979
|
+
await execution.request(REALTIME_CALL_METHOD, { operation: "hangup", callId }).catch(note);
|
|
20980
|
+
return unconfirmed;
|
|
20981
|
+
}
|
|
20982
|
+
function captureExecution(host) {
|
|
20983
|
+
return host.bindExecution?.() ?? {
|
|
20984
|
+
generation: host.generation,
|
|
20985
|
+
request: (method, params) => host.request(method, params)
|
|
20986
|
+
};
|
|
20987
|
+
}
|
|
20988
|
+
async function readContextDocument(renderer, executionContextId) {
|
|
20989
|
+
try {
|
|
20990
|
+
const response = await renderer.command("Runtime.evaluate", {
|
|
20991
|
+
expression: "(function(){try{return {href:String(location.href),top:window.top===window};}catch(e){return {href:'',top:false};}})()",
|
|
20992
|
+
contextId: executionContextId,
|
|
20993
|
+
returnByValue: true
|
|
20994
|
+
});
|
|
20995
|
+
const value = evaluateResultValue(response);
|
|
20996
|
+
if (!isRecord2(value) || typeof value.href !== "string" || typeof value.top !== "boolean")
|
|
20997
|
+
return;
|
|
20998
|
+
return { href: value.href, top: value.top };
|
|
20999
|
+
} catch (error51) {
|
|
21000
|
+
if (error51 instanceof Error && STALE_CONTEXT.test(error51.message)) return;
|
|
21001
|
+
return;
|
|
21002
|
+
}
|
|
21003
|
+
}
|
|
21004
|
+
async function deliver(renderer, executionContextId, message) {
|
|
21005
|
+
const encoded = JSON.stringify(message);
|
|
21006
|
+
const payload = encoded.length > RENDERER_VOICE_HOST_MAX_PAYLOAD_BYTES ? JSON.stringify({
|
|
21007
|
+
id: message.id,
|
|
21008
|
+
ok: false,
|
|
21009
|
+
error: "Host request failed"
|
|
21010
|
+
}) : encoded;
|
|
21011
|
+
await renderer.command("Runtime.evaluate", {
|
|
21012
|
+
expression: `typeof globalThis[${JSON.stringify(RENDERER_VOICE_HOST_DELIVER_GLOBAL)}]==='function'&&globalThis[${JSON.stringify(RENDERER_VOICE_HOST_DELIVER_GLOBAL)}](${payload})`,
|
|
21013
|
+
contextId: executionContextId,
|
|
21014
|
+
returnByValue: true
|
|
21015
|
+
}).catch(() => void 0);
|
|
21016
|
+
}
|
|
21017
|
+
async function registerFutureScript(renderer, source, previousId) {
|
|
21018
|
+
if (previousId) {
|
|
21019
|
+
await renderer.command("Page.removeScriptToEvaluateOnNewDocument", { identifier: previousId }).catch(() => void 0);
|
|
21020
|
+
}
|
|
21021
|
+
const added = await renderer.command("Page.addScriptToEvaluateOnNewDocument", { source });
|
|
21022
|
+
return isRecord2(added) && typeof added.identifier === "string" ? added.identifier : void 0;
|
|
21023
|
+
}
|
|
21024
|
+
async function removeFutureScript(renderer, identifier) {
|
|
21025
|
+
if (!identifier) return;
|
|
21026
|
+
await renderer.command("Page.removeScriptToEvaluateOnNewDocument", { identifier }).catch(() => void 0);
|
|
21027
|
+
}
|
|
21028
|
+
async function installRendererVoiceHostBinding(renderer, host, options) {
|
|
21029
|
+
let disposed = false;
|
|
21030
|
+
let scriptId;
|
|
21031
|
+
let publishing = Promise.resolve();
|
|
21032
|
+
const inflight = /* @__PURE__ */ new Set();
|
|
21033
|
+
const works = /* @__PURE__ */ new Map();
|
|
21034
|
+
const abandonedIds = /* @__PURE__ */ new Set();
|
|
21035
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
21036
|
+
const rememberContext = (params) => {
|
|
21037
|
+
if (!isRecord2(params) || !isRecord2(params.context)) return;
|
|
21038
|
+
const context = params.context;
|
|
21039
|
+
if (typeof context.id !== "number" || typeof context.uniqueId !== "string") return;
|
|
21040
|
+
const aux = isRecord2(context.auxData) ? context.auxData : void 0;
|
|
21041
|
+
contexts.set(context.id, {
|
|
21042
|
+
uniqueId: context.uniqueId,
|
|
21043
|
+
isDefault: aux?.isDefault === true
|
|
21044
|
+
});
|
|
21045
|
+
};
|
|
21046
|
+
const observeCleanupUnconfirmed = async (contextId, pageId, unconfirmed) => {
|
|
21047
|
+
if (!unconfirmed || disposed) return;
|
|
21048
|
+
await deliver(renderer, contextId, {
|
|
21049
|
+
id: pageId,
|
|
21050
|
+
ok: false,
|
|
21051
|
+
error: unconfirmed.message,
|
|
21052
|
+
stage: "cancel"
|
|
21053
|
+
});
|
|
21054
|
+
};
|
|
21055
|
+
const abandonWork = (item) => {
|
|
21056
|
+
if (item.abandoned) return;
|
|
21057
|
+
item.abandoned = true;
|
|
21058
|
+
if (!item.create) return;
|
|
21059
|
+
void cleanupAbandonedCreate(
|
|
21060
|
+
item.execution,
|
|
21061
|
+
{ requestId: item.create.requestId, operation: "create" },
|
|
21062
|
+
item.create.result
|
|
21063
|
+
).then((unconfirmed) => observeCleanupUnconfirmed(item.contextId, item.pageId, unconfirmed));
|
|
21064
|
+
};
|
|
21065
|
+
const abandonMatching = (contextId, uniqueId) => {
|
|
21066
|
+
for (const item of works.values()) {
|
|
21067
|
+
if (contextId !== void 0 && item.contextId === contextId || uniqueId !== void 0 && item.uniqueId === uniqueId)
|
|
21068
|
+
abandonWork(item);
|
|
21069
|
+
}
|
|
21070
|
+
};
|
|
21071
|
+
const forgetContext = (params) => {
|
|
21072
|
+
if (!isRecord2(params)) return;
|
|
21073
|
+
let contextId;
|
|
21074
|
+
let uniqueId;
|
|
21075
|
+
if (typeof params.executionContextId === "number") {
|
|
21076
|
+
contextId = params.executionContextId;
|
|
21077
|
+
uniqueId = contexts.get(contextId)?.uniqueId;
|
|
21078
|
+
contexts.delete(contextId);
|
|
21079
|
+
}
|
|
21080
|
+
if (typeof params.executionContextUniqueId === "string") {
|
|
21081
|
+
uniqueId = params.executionContextUniqueId;
|
|
21082
|
+
for (const [id, record4] of contexts)
|
|
21083
|
+
if (record4.uniqueId === uniqueId) {
|
|
21084
|
+
contextId = id;
|
|
21085
|
+
contexts.delete(id);
|
|
21086
|
+
}
|
|
21087
|
+
}
|
|
21088
|
+
abandonMatching(contextId, uniqueId);
|
|
21089
|
+
};
|
|
21090
|
+
const unsubscribeCreated = renderer.on("Runtime.executionContextCreated", rememberContext);
|
|
21091
|
+
const unsubscribeDestroyed = renderer.on("Runtime.executionContextDestroyed", forgetContext);
|
|
21092
|
+
const unsubscribeCleared = renderer.on("Runtime.executionContextsCleared", () => {
|
|
21093
|
+
contexts.clear();
|
|
21094
|
+
for (const item of works.values()) abandonWork(item);
|
|
21095
|
+
});
|
|
21096
|
+
const contextIsVerified = async (executionContextId, uniqueId) => {
|
|
21097
|
+
const tracked = contexts.get(executionContextId);
|
|
21098
|
+
if (!tracked?.isDefault || tracked.uniqueId !== uniqueId) return false;
|
|
21099
|
+
const document = await readContextDocument(renderer, executionContextId);
|
|
21100
|
+
const still = contexts.get(executionContextId);
|
|
21101
|
+
if (still?.uniqueId !== uniqueId || !still.isDefault) return false;
|
|
21102
|
+
if (!document?.top) return false;
|
|
21103
|
+
return isEligibleVoiceHostUrl(document.href);
|
|
21104
|
+
};
|
|
21105
|
+
const publishGeneration = async () => {
|
|
21106
|
+
if (disposed) return;
|
|
21107
|
+
const startedGeneration = host.generation;
|
|
21108
|
+
const source = rendererVoiceHostCapabilitySource(host.owner, startedGeneration);
|
|
21109
|
+
const addedId = await registerFutureScript(renderer, source, scriptId);
|
|
21110
|
+
if (disposed || host.generation !== startedGeneration) {
|
|
21111
|
+
await removeFutureScript(renderer, addedId);
|
|
21112
|
+
return;
|
|
21113
|
+
}
|
|
21114
|
+
scriptId = addedId;
|
|
21115
|
+
await renderer.evaluate(source);
|
|
21116
|
+
};
|
|
21117
|
+
const enqueuePublish = () => {
|
|
21118
|
+
publishing = publishing.catch(() => void 0).then(() => publishGeneration()).catch(() => void 0);
|
|
21119
|
+
};
|
|
21120
|
+
const cancelInflightCreates = () => {
|
|
21121
|
+
for (const item of works.values()) {
|
|
21122
|
+
if (!item.create || item.abandoned) continue;
|
|
21123
|
+
void item.execution.request(REALTIME_CALL_METHOD, { operation: "cancel", requestId: item.create.requestId }).catch(
|
|
21124
|
+
(error51) => observeCleanupUnconfirmed(item.contextId, item.pageId, cleanupUnconfirmedError(error51))
|
|
21125
|
+
);
|
|
21126
|
+
}
|
|
21127
|
+
};
|
|
21128
|
+
if (options?.enableRuntime !== false) await renderer.command("Runtime.enable");
|
|
21129
|
+
await renderer.command("Page.enable");
|
|
21130
|
+
await renderer.command("Runtime.addBinding", { name: RENDERER_VOICE_HOST_BINDING_NAME });
|
|
21131
|
+
await publishGeneration();
|
|
21132
|
+
const refresh = () => {
|
|
21133
|
+
if (disposed) return;
|
|
21134
|
+
cancelInflightCreates();
|
|
21135
|
+
enqueuePublish();
|
|
21136
|
+
};
|
|
21137
|
+
const unsubscribeGeneration = host.onGenerationChange?.(refresh);
|
|
21138
|
+
const unsubscribe = renderer.on("Runtime.bindingCalled", (params) => {
|
|
21139
|
+
if (disposed || !isRecord2(params) || params.name !== RENDERER_VOICE_HOST_BINDING_NAME) return;
|
|
21140
|
+
if (typeof params.executionContextId !== "number" || typeof params.payload !== "string") return;
|
|
21141
|
+
if (params.payload.length > RENDERER_VOICE_HOST_MAX_PAYLOAD_BYTES) return;
|
|
21142
|
+
const contextId = params.executionContextId;
|
|
21143
|
+
const payloadText = params.payload;
|
|
21144
|
+
const startedGeneration = host.generation;
|
|
21145
|
+
const work = (async () => {
|
|
21146
|
+
let parsed;
|
|
21147
|
+
try {
|
|
21148
|
+
parsed = JSON.parse(payloadText);
|
|
21149
|
+
} catch {
|
|
21150
|
+
return;
|
|
21151
|
+
}
|
|
21152
|
+
if (!isRecord2(parsed) || parsed.v !== 1 || typeof parsed.id !== "string" || parsed.id.length === 0 || parsed.id.length > 128 || parsed.owner !== host.owner)
|
|
21153
|
+
return;
|
|
21154
|
+
const requestId2 = parsed.id;
|
|
21155
|
+
if (parsed.abandon === true) {
|
|
21156
|
+
const existing = works.get(requestId2);
|
|
21157
|
+
if (existing) abandonWork(existing);
|
|
21158
|
+
else abandonedIds.add(requestId2);
|
|
21159
|
+
return;
|
|
21160
|
+
}
|
|
21161
|
+
if (parsed.generation !== startedGeneration || parsed.generation !== host.generation || typeof parsed.method !== "string" || !isRecord2(parsed.params)) {
|
|
21162
|
+
await deliver(renderer, contextId, { id: requestId2, ok: false, error: UNAVAILABLE });
|
|
21163
|
+
return;
|
|
21164
|
+
}
|
|
21165
|
+
const tracked = contexts.get(contextId);
|
|
21166
|
+
if (!tracked?.isDefault) {
|
|
21167
|
+
return;
|
|
21168
|
+
}
|
|
21169
|
+
const uniqueId = tracked.uniqueId;
|
|
21170
|
+
const execution = captureExecution(host);
|
|
21171
|
+
const item = {
|
|
21172
|
+
pageId: requestId2,
|
|
21173
|
+
contextId,
|
|
21174
|
+
uniqueId,
|
|
21175
|
+
generation: startedGeneration,
|
|
21176
|
+
execution,
|
|
21177
|
+
abandoned: abandonedIds.has(requestId2),
|
|
21178
|
+
...isCreateOperation(parsed.method, parsed.params) && typeof parsed.params.requestId === "string" ? { create: { requestId: parsed.params.requestId } } : {}
|
|
21179
|
+
};
|
|
21180
|
+
works.set(requestId2, item);
|
|
21181
|
+
abandonedIds.delete(requestId2);
|
|
21182
|
+
try {
|
|
21183
|
+
if (item.abandoned) {
|
|
21184
|
+
if (item.create)
|
|
21185
|
+
await observeCleanupUnconfirmed(
|
|
21186
|
+
contextId,
|
|
21187
|
+
requestId2,
|
|
21188
|
+
await cleanupAbandonedCreate(
|
|
21189
|
+
item.execution,
|
|
21190
|
+
{ requestId: item.create.requestId, operation: "create" },
|
|
21191
|
+
item.create.result
|
|
21192
|
+
)
|
|
21193
|
+
);
|
|
21194
|
+
return;
|
|
21195
|
+
}
|
|
21196
|
+
const method = parsed.method;
|
|
21197
|
+
const requestParams = parsed.params;
|
|
21198
|
+
const verified = await contextIsVerified(contextId, uniqueId);
|
|
21199
|
+
const still = contexts.get(contextId);
|
|
21200
|
+
if (disposed || item.abandoned || host.generation !== startedGeneration || still?.uniqueId !== uniqueId) {
|
|
21201
|
+
if (item.create)
|
|
21202
|
+
await observeCleanupUnconfirmed(
|
|
21203
|
+
contextId,
|
|
21204
|
+
requestId2,
|
|
21205
|
+
await cleanupAbandonedCreate(item.execution, requestParams, item.create.result)
|
|
21206
|
+
);
|
|
21207
|
+
return;
|
|
21208
|
+
}
|
|
21209
|
+
if (!verified) {
|
|
21210
|
+
if (still?.isDefault)
|
|
21211
|
+
await deliver(renderer, contextId, { id: requestId2, ok: false, error: UNAVAILABLE });
|
|
21212
|
+
return;
|
|
21213
|
+
}
|
|
21214
|
+
if (!ALLOWED_METHODS.has(method)) {
|
|
21215
|
+
await deliver(renderer, contextId, { id: requestId2, ok: false, error: UNAVAILABLE });
|
|
21216
|
+
return;
|
|
21217
|
+
}
|
|
21218
|
+
try {
|
|
21219
|
+
const result = await item.execution.request(method, requestParams);
|
|
21220
|
+
if (item.create) item.create.result = result;
|
|
21221
|
+
const after = contexts.get(contextId);
|
|
21222
|
+
if (disposed || item.abandoned || host.generation !== startedGeneration || after?.uniqueId !== uniqueId) {
|
|
21223
|
+
if (item.create)
|
|
21224
|
+
await observeCleanupUnconfirmed(
|
|
21225
|
+
contextId,
|
|
21226
|
+
requestId2,
|
|
21227
|
+
await cleanupAbandonedCreate(item.execution, requestParams, result)
|
|
21228
|
+
);
|
|
21229
|
+
return;
|
|
21230
|
+
}
|
|
21231
|
+
await deliver(renderer, contextId, { id: requestId2, ok: true, result });
|
|
21232
|
+
} catch (error51) {
|
|
21233
|
+
const unconfirmed = cleanupUnconfirmedError(error51);
|
|
21234
|
+
if (unconfirmed && !disposed) {
|
|
21235
|
+
await deliver(renderer, contextId, {
|
|
21236
|
+
id: requestId2,
|
|
21237
|
+
ok: false,
|
|
21238
|
+
error: unconfirmed.message,
|
|
21239
|
+
stage: "cancel"
|
|
21240
|
+
});
|
|
21241
|
+
return;
|
|
21242
|
+
}
|
|
21243
|
+
if (disposed || item.abandoned || host.generation !== startedGeneration) return;
|
|
21244
|
+
const stage = error51 instanceof Error ? allowlistedStage(Reflect.get(error51, "stage")) : void 0;
|
|
21245
|
+
await deliver(renderer, contextId, {
|
|
21246
|
+
id: requestId2,
|
|
21247
|
+
ok: false,
|
|
21248
|
+
error: error51 instanceof Error && error51.message.length > 0 && error51.message.length <= 500 && !/bearer|token|authorization|sdp/i.test(error51.message) ? error51.message : "Host request failed",
|
|
21249
|
+
...stage ? { stage } : {}
|
|
21250
|
+
});
|
|
21251
|
+
}
|
|
21252
|
+
} finally {
|
|
21253
|
+
works.delete(requestId2);
|
|
21254
|
+
}
|
|
21255
|
+
})();
|
|
21256
|
+
inflight.add(work);
|
|
21257
|
+
void work.finally(() => inflight.delete(work));
|
|
21258
|
+
});
|
|
21259
|
+
return () => {
|
|
21260
|
+
if (disposed) return;
|
|
21261
|
+
disposed = true;
|
|
21262
|
+
unsubscribeGeneration?.();
|
|
21263
|
+
unsubscribe();
|
|
21264
|
+
unsubscribeCreated();
|
|
21265
|
+
unsubscribeDestroyed();
|
|
21266
|
+
unsubscribeCleared();
|
|
21267
|
+
cancelInflightCreates();
|
|
21268
|
+
const outstanding = [...inflight];
|
|
21269
|
+
const leftover = [...works.values()];
|
|
21270
|
+
void Promise.allSettled(outstanding).then(async () => {
|
|
21271
|
+
for (const item of leftover)
|
|
21272
|
+
if (item.create)
|
|
21273
|
+
await observeCleanupUnconfirmed(
|
|
21274
|
+
item.contextId,
|
|
21275
|
+
item.pageId,
|
|
21276
|
+
await cleanupAbandonedCreate(
|
|
21277
|
+
item.execution,
|
|
21278
|
+
{ requestId: item.create.requestId, operation: "create" },
|
|
21279
|
+
item.create.result
|
|
21280
|
+
)
|
|
21281
|
+
);
|
|
21282
|
+
});
|
|
21283
|
+
void removeFutureScript(renderer, scriptId);
|
|
21284
|
+
void renderer.command("Runtime.removeBinding", { name: RENDERER_VOICE_HOST_BINDING_NAME }).catch(() => void 0);
|
|
21285
|
+
void renderer.evaluate(
|
|
21286
|
+
`(() => {
|
|
21287
|
+
const pending = globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}];
|
|
21288
|
+
if (pending && typeof pending.forEach === "function") {
|
|
21289
|
+
for (const [id, wait] of [...pending.entries()]) {
|
|
21290
|
+
pending.delete(id);
|
|
21291
|
+
try { clearTimeout(wait.timer); } catch (e) {}
|
|
21292
|
+
try { wait.reject(new Error(${JSON.stringify(UNKNOWN_OUTCOME)})); } catch (e) {}
|
|
21293
|
+
}
|
|
21294
|
+
}
|
|
21295
|
+
delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_CAPABILITY_GLOBAL)}];
|
|
21296
|
+
delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_DELIVER_GLOBAL)}];
|
|
21297
|
+
delete globalThis[${JSON.stringify(RENDERER_VOICE_HOST_PENDING_GLOBAL)}];
|
|
21298
|
+
return true;
|
|
21299
|
+
})()`
|
|
21300
|
+
).catch(() => void 0);
|
|
21301
|
+
};
|
|
21302
|
+
}
|
|
21303
|
+
|
|
21304
|
+
// packages/desktop-control/src/renderer-cdp-control-session.ts
|
|
21305
|
+
function isRecord3(value) {
|
|
21306
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21307
|
+
}
|
|
20379
21308
|
function sleep(milliseconds) {
|
|
20380
21309
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
20381
21310
|
}
|
|
@@ -20426,24 +21355,6 @@ function sameAgents(actual, expected) {
|
|
|
20426
21355
|
const expectedSet = new Set(expected);
|
|
20427
21356
|
return actual.length === expected.length && actual.every((agent) => expectedSet.has(agent));
|
|
20428
21357
|
}
|
|
20429
|
-
function parseCodexAppUrl(value) {
|
|
20430
|
-
try {
|
|
20431
|
-
const url2 = new URL(value);
|
|
20432
|
-
return url2.protocol === "app:" && url2.hostname === "-" ? url2 : null;
|
|
20433
|
-
} catch {
|
|
20434
|
-
return null;
|
|
20435
|
-
}
|
|
20436
|
-
}
|
|
20437
|
-
function isPrimaryRendererUrl(value) {
|
|
20438
|
-
const url2 = parseCodexAppUrl(value);
|
|
20439
|
-
return url2 !== null && url2.pathname === "/index.html" && url2.search === "" && url2.hash === "";
|
|
20440
|
-
}
|
|
20441
|
-
function isAvatarOverlayRendererUrl(value) {
|
|
20442
|
-
const url2 = parseCodexAppUrl(value);
|
|
20443
|
-
if (!url2) return false;
|
|
20444
|
-
if (url2.pathname === "/avatar-overlay.html") return true;
|
|
20445
|
-
return url2.pathname === "/index.html" && url2.searchParams.get("initialRoute") === "/avatar-overlay";
|
|
20446
|
-
}
|
|
20447
21358
|
function selectPrimaryRendererTarget(targets, preferredTargetId) {
|
|
20448
21359
|
const candidates = targets.filter(
|
|
20449
21360
|
(target2) => target2.type === "page" && isPrimaryRendererUrl(target2.url)
|
|
@@ -20464,7 +21375,7 @@ var RendererAdapterReadinessError = class extends Error {
|
|
|
20464
21375
|
reason;
|
|
20465
21376
|
};
|
|
20466
21377
|
function validateBindingStatus(value, expectedAgents) {
|
|
20467
|
-
if (!
|
|
21378
|
+
if (!isRecord3(value) || value.version !== 2 || !Array.isArray(value.enabledAgents) || value.enabledAgents.some((agent) => typeof agent !== "string") || !sameAgents(value.enabledAgents, expectedAgents) || !isRecord3(value.adapter)) {
|
|
20468
21379
|
throw new Error("Production Renderer binding returned an invalid status");
|
|
20469
21380
|
}
|
|
20470
21381
|
if (value.adapter.state !== "ready" || typeof value.adapter.reason !== "string") {
|
|
@@ -20508,13 +21419,22 @@ async function waitForPrimaryTarget(endpoint, operations, timeoutMs, pollInterva
|
|
|
20508
21419
|
const detail = lastError instanceof Error ? `: ${lastError.message}` : "";
|
|
20509
21420
|
throw new Error(`Primary Codex Renderer CDP target did not become ready${detail}`);
|
|
20510
21421
|
}
|
|
21422
|
+
async function bindRendererVoiceHost(renderer, voiceHost, disposals, options) {
|
|
21423
|
+
if (!voiceHost) return;
|
|
21424
|
+
disposals.get(renderer)?.();
|
|
21425
|
+
disposals.set(renderer, await installRendererVoiceHostBinding(renderer, voiceHost, options));
|
|
21426
|
+
}
|
|
21427
|
+
function unbindRendererVoiceHost(renderer, disposals) {
|
|
21428
|
+
disposals.get(renderer)?.();
|
|
21429
|
+
disposals.delete(renderer);
|
|
21430
|
+
}
|
|
20511
21431
|
async function evaluateSource(renderer, source) {
|
|
20512
21432
|
const response = await renderer.command("Runtime.evaluate", {
|
|
20513
21433
|
expression: source,
|
|
20514
21434
|
awaitPromise: true
|
|
20515
21435
|
});
|
|
20516
|
-
if (!
|
|
20517
|
-
if (
|
|
21436
|
+
if (!isRecord3(response)) throw new Error("Renderer source evaluation returned an invalid result");
|
|
21437
|
+
if (isRecord3(response.exceptionDetails)) {
|
|
20518
21438
|
throw new Error(
|
|
20519
21439
|
cdpExceptionMessage(response.exceptionDetails, "Renderer source evaluation failed")
|
|
20520
21440
|
);
|
|
@@ -20547,30 +21467,208 @@ async function waitForBinding(renderer, enabledAgents, timeoutMs, pollIntervalMs
|
|
|
20547
21467
|
const detail = lastError instanceof Error ? `: ${lastError.message}` : "";
|
|
20548
21468
|
throw new Error(`Production Renderer binding did not become ready${detail}`);
|
|
20549
21469
|
}
|
|
20550
|
-
|
|
21470
|
+
var overlayInstallState = /* @__PURE__ */ new WeakMap();
|
|
21471
|
+
var OVERLAY_HOOK_SNAPSHOT_EXPRESSION = `(() => { /*__codexhostOverlayHookSnapshot*/
|
|
21472
|
+
const cpa = globalThis.${CPA_LIVE_VOICE_HOOK_GLOBAL};
|
|
21473
|
+
const native = globalThis.__codexhostNativeChatVoiceV1;
|
|
21474
|
+
const labels =
|
|
21475
|
+
typeof document !== "undefined" && document.querySelectorAll
|
|
21476
|
+
? [...document.querySelectorAll("button")].map((button) =>
|
|
21477
|
+
(button.getAttribute("aria-label") || "").toLowerCase(),
|
|
21478
|
+
)
|
|
21479
|
+
: [];
|
|
21480
|
+
let call = "unknown";
|
|
21481
|
+
if (native && native.activeCall === true) call = "active";
|
|
21482
|
+
else if (labels.some((label) => label === "end voice" || label === "end voice chat"))
|
|
21483
|
+
call = "active";
|
|
21484
|
+
else if (native && native.activeCall === false) call = "idle";
|
|
21485
|
+
else if (labels.some((label) => label.includes("start voice"))) call = "idle";
|
|
21486
|
+
const isolated =
|
|
21487
|
+
cpa && typeof cpa === "object" && "isolatedQualification" in cpa
|
|
21488
|
+
? cpa.isolatedQualification
|
|
21489
|
+
: undefined;
|
|
21490
|
+
return {
|
|
21491
|
+
enabled: Boolean(cpa && typeof cpa === "object" && cpa.enabled === true),
|
|
21492
|
+
revision: typeof cpa?.implementationRevision === "string" ? cpa.implementationRevision : null,
|
|
21493
|
+
isolatedPath:
|
|
21494
|
+
isolated && typeof isolated === "object" && typeof isolated.path === "string"
|
|
21495
|
+
? isolated.path
|
|
21496
|
+
: null,
|
|
21497
|
+
isolatedPaths: (() => {
|
|
21498
|
+
if (!isolated || typeof isolated !== "object") return null;
|
|
21499
|
+
const listed = Array.isArray(isolated.paths)
|
|
21500
|
+
? isolated.paths
|
|
21501
|
+
: typeof isolated.path === "string"
|
|
21502
|
+
? [isolated.path]
|
|
21503
|
+
: [];
|
|
21504
|
+
const unique = ["chat", "work-codex", "work-grok"].filter((path) => listed.includes(path));
|
|
21505
|
+
return unique.length ? unique : null;
|
|
21506
|
+
})(),
|
|
21507
|
+
isolatedRun:
|
|
21508
|
+
isolated && typeof isolated === "object" && typeof isolated.run === "string"
|
|
21509
|
+
? isolated.run
|
|
21510
|
+
: null,
|
|
21511
|
+
isolatedExpiresAt:
|
|
21512
|
+
isolated && typeof isolated === "object" && typeof isolated.expiresAt === "string"
|
|
21513
|
+
? isolated.expiresAt
|
|
21514
|
+
: null,
|
|
21515
|
+
isolatedPlatform:
|
|
21516
|
+
isolated && typeof isolated === "object" && typeof isolated.desktopPlatform === "string"
|
|
21517
|
+
? isolated.desktopPlatform
|
|
21518
|
+
: null,
|
|
21519
|
+
appPath: typeof cpa?.desktopAppPath === "string" ? cpa.desktopAppPath : null,
|
|
21520
|
+
call,
|
|
21521
|
+
};
|
|
21522
|
+
})()`;
|
|
21523
|
+
function overlaySourceDigest(source) {
|
|
21524
|
+
return createHash("sha256").update(source).digest("hex");
|
|
21525
|
+
}
|
|
21526
|
+
function emptyOverlaySnapshot(enabled, call = "unknown") {
|
|
21527
|
+
return {
|
|
21528
|
+
enabled,
|
|
21529
|
+
revision: null,
|
|
21530
|
+
isolatedPath: null,
|
|
21531
|
+
isolatedPaths: null,
|
|
21532
|
+
isolatedRun: null,
|
|
21533
|
+
isolatedExpiresAt: null,
|
|
21534
|
+
isolatedPlatform: null,
|
|
21535
|
+
appPath: null,
|
|
21536
|
+
call
|
|
21537
|
+
};
|
|
21538
|
+
}
|
|
21539
|
+
function overlayIdentityFromSource(source) {
|
|
21540
|
+
const needle = `globalThis.${CPA_LIVE_VOICE_HOOK_GLOBAL} = Object.freeze(`;
|
|
21541
|
+
const start = source.indexOf(needle);
|
|
21542
|
+
if (start < 0) return;
|
|
21543
|
+
const json2 = source.slice(start + needle.length);
|
|
21544
|
+
const end = json2.indexOf(");");
|
|
21545
|
+
if (end < 0) return;
|
|
20551
21546
|
try {
|
|
20552
|
-
const
|
|
20553
|
-
|
|
20554
|
-
|
|
20555
|
-
return
|
|
21547
|
+
const parsed = JSON.parse(json2.slice(0, end));
|
|
21548
|
+
if (!isRecord3(parsed)) return;
|
|
21549
|
+
const isolated = parsed.isolatedQualification;
|
|
21550
|
+
return {
|
|
21551
|
+
enabled: parsed.enabled === true,
|
|
21552
|
+
revision: typeof parsed.implementationRevision === "string" ? parsed.implementationRevision : null,
|
|
21553
|
+
isolatedPath: isRecord3(isolated) && typeof isolated.path === "string" ? isolated.path : null,
|
|
21554
|
+
isolatedPaths: (() => {
|
|
21555
|
+
if (!isRecord3(isolated)) return null;
|
|
21556
|
+
const listed = Array.isArray(isolated.paths) ? isolated.paths : typeof isolated.path === "string" ? [isolated.path] : [];
|
|
21557
|
+
const unique = ["chat", "work-codex", "work-grok"].filter((path7) => listed.includes(path7));
|
|
21558
|
+
return unique.length ? unique : null;
|
|
21559
|
+
})(),
|
|
21560
|
+
isolatedRun: isRecord3(isolated) && typeof isolated.run === "string" ? isolated.run : null,
|
|
21561
|
+
isolatedExpiresAt: isRecord3(isolated) && typeof isolated.expiresAt === "string" ? isolated.expiresAt : null,
|
|
21562
|
+
isolatedPlatform: isRecord3(isolated) && typeof isolated.desktopPlatform === "string" ? isolated.desktopPlatform : null,
|
|
21563
|
+
appPath: typeof parsed.desktopAppPath === "string" ? parsed.desktopAppPath : null,
|
|
21564
|
+
call: "idle"
|
|
21565
|
+
};
|
|
20556
21566
|
} catch {
|
|
20557
|
-
return
|
|
21567
|
+
return;
|
|
20558
21568
|
}
|
|
20559
21569
|
}
|
|
20560
|
-
|
|
21570
|
+
function overlayIsolatedPaths(snapshot) {
|
|
21571
|
+
if (snapshot.isolatedPaths && snapshot.isolatedPaths.length > 0) return snapshot.isolatedPaths;
|
|
21572
|
+
return snapshot.isolatedPath ? [snapshot.isolatedPath] : null;
|
|
21573
|
+
}
|
|
21574
|
+
function overlayIdentitiesMatch(live, desired) {
|
|
21575
|
+
return live.enabled === true && live.revision === desired.revision && live.isolatedPath === desired.isolatedPath && JSON.stringify(overlayIsolatedPaths(live)) === JSON.stringify(overlayIsolatedPaths(desired)) && live.isolatedRun === desired.isolatedRun && live.isolatedExpiresAt === desired.isolatedExpiresAt && live.isolatedPlatform === desired.isolatedPlatform && live.appPath === desired.appPath;
|
|
21576
|
+
}
|
|
21577
|
+
function readOverlayHookSnapshot(value) {
|
|
21578
|
+
if (value === true) return emptyOverlaySnapshot(true);
|
|
21579
|
+
if (value === false || value == null) return emptyOverlaySnapshot(false);
|
|
21580
|
+
if (!isRecord3(value) || typeof value.enabled !== "boolean") return;
|
|
21581
|
+
const call = value.call === "active" || value.call === "idle" ? value.call : "unknown";
|
|
21582
|
+
return {
|
|
21583
|
+
enabled: value.enabled,
|
|
21584
|
+
revision: typeof value.revision === "string" ? value.revision : null,
|
|
21585
|
+
isolatedPath: typeof value.isolatedPath === "string" ? value.isolatedPath : null,
|
|
21586
|
+
isolatedPaths: Array.isArray(value.isolatedPaths) ? value.isolatedPaths.filter((path7) => typeof path7 === "string") : typeof value.isolatedPath === "string" ? [value.isolatedPath] : null,
|
|
21587
|
+
isolatedRun: typeof value.isolatedRun === "string" ? value.isolatedRun : null,
|
|
21588
|
+
isolatedExpiresAt: typeof value.isolatedExpiresAt === "string" ? value.isolatedExpiresAt : null,
|
|
21589
|
+
isolatedPlatform: typeof value.isolatedPlatform === "string" ? value.isolatedPlatform : null,
|
|
21590
|
+
appPath: typeof value.appPath === "string" ? value.appPath : null,
|
|
21591
|
+
call
|
|
21592
|
+
};
|
|
21593
|
+
}
|
|
21594
|
+
async function installOverlayHook(target2, overlayHookSource, overlayClients, operations, signal, overlayVoiceBootstrapSource, voiceHost, voiceHostDisposals) {
|
|
20561
21595
|
const timeoutMessage = "Overlay hook installation timed out";
|
|
21596
|
+
const currentDocumentSource = overlayVoiceBootstrapSource ?? overlayHookSource;
|
|
21597
|
+
const desiredDigest = overlaySourceDigest(currentDocumentSource);
|
|
21598
|
+
const desiredIdentity = overlayIdentityFromSource(currentDocumentSource);
|
|
20562
21599
|
const run = (operation) => runWithCdpSignal(signal, timeoutMessage, operation);
|
|
20563
|
-
|
|
21600
|
+
let renderer = overlayClients.get(target2.id);
|
|
21601
|
+
const registered = renderer !== void 0;
|
|
21602
|
+
renderer ??= await connectRendererTarget(target2, operations, signal, timeoutMessage);
|
|
21603
|
+
const connected = renderer;
|
|
20564
21604
|
try {
|
|
20565
|
-
|
|
20566
|
-
|
|
20567
|
-
|
|
20568
|
-
|
|
20569
|
-
|
|
21605
|
+
if (!registered) {
|
|
21606
|
+
if (voiceHost && voiceHostDisposals && !voiceHostDisposals.has(connected))
|
|
21607
|
+
await run(
|
|
21608
|
+
() => bindRendererVoiceHost(connected, voiceHost, voiceHostDisposals, { enableRuntime: false })
|
|
21609
|
+
);
|
|
21610
|
+
await run(() => connected.command("Runtime.enable"));
|
|
21611
|
+
await run(() => connected.command("Page.enable"));
|
|
21612
|
+
overlayClients.set(target2.id, connected);
|
|
21613
|
+
} else if (voiceHost && voiceHostDisposals && !voiceHostDisposals.has(connected)) {
|
|
21614
|
+
await run(
|
|
21615
|
+
() => bindRendererVoiceHost(connected, voiceHost, voiceHostDisposals, { enableRuntime: false })
|
|
21616
|
+
);
|
|
21617
|
+
}
|
|
21618
|
+
let inspected = true;
|
|
21619
|
+
const snapshot = readOverlayHookSnapshot(
|
|
21620
|
+
await run(async () => {
|
|
21621
|
+
try {
|
|
21622
|
+
return await connected.evaluate(OVERLAY_HOOK_SNAPSHOT_EXPRESSION);
|
|
21623
|
+
} catch {
|
|
21624
|
+
inspected = false;
|
|
21625
|
+
return void 0;
|
|
21626
|
+
}
|
|
21627
|
+
})
|
|
20570
21628
|
);
|
|
20571
|
-
|
|
20572
|
-
|
|
20573
|
-
|
|
21629
|
+
const applied = overlayInstallState.get(connected);
|
|
21630
|
+
const identityMatches = inspected && desiredIdentity !== void 0 && snapshot !== void 0 && overlayIdentitiesMatch(snapshot, desiredIdentity);
|
|
21631
|
+
const digestMatches = applied?.currentDigest === desiredDigest;
|
|
21632
|
+
const currentMatches = inspected && snapshot?.enabled === true && identityMatches && digestMatches;
|
|
21633
|
+
const callKnownIdle = inspected && snapshot?.call === "idle";
|
|
21634
|
+
const futureDocumentMissing = !registered || applied?.futureDigest !== desiredDigest;
|
|
21635
|
+
if (futureDocumentMissing) {
|
|
21636
|
+
if (applied?.scriptId) {
|
|
21637
|
+
try {
|
|
21638
|
+
await run(
|
|
21639
|
+
() => connected.command("Page.removeScriptToEvaluateOnNewDocument", {
|
|
21640
|
+
identifier: applied.scriptId
|
|
21641
|
+
})
|
|
21642
|
+
);
|
|
21643
|
+
} catch {
|
|
21644
|
+
}
|
|
21645
|
+
}
|
|
21646
|
+
const added = await run(
|
|
21647
|
+
() => connected.command("Page.addScriptToEvaluateOnNewDocument", {
|
|
21648
|
+
source: currentDocumentSource
|
|
21649
|
+
})
|
|
21650
|
+
);
|
|
21651
|
+
const addedId = isRecord3(added) && typeof added.identifier === "string" ? added.identifier : void 0;
|
|
21652
|
+
overlayInstallState.set(connected, {
|
|
21653
|
+
futureDigest: desiredDigest,
|
|
21654
|
+
...applied?.currentDigest ? { currentDigest: applied.currentDigest } : {},
|
|
21655
|
+
...addedId ? { scriptId: addedId } : {}
|
|
21656
|
+
});
|
|
21657
|
+
}
|
|
21658
|
+
if (currentMatches) return;
|
|
21659
|
+
if (!callKnownIdle) return;
|
|
21660
|
+
await run(() => evaluateSource(connected, currentDocumentSource));
|
|
21661
|
+
const evaluated = overlayInstallState.get(connected);
|
|
21662
|
+
overlayInstallState.set(connected, {
|
|
21663
|
+
futureDigest: desiredDigest,
|
|
21664
|
+
currentDigest: desiredDigest,
|
|
21665
|
+
...evaluated?.scriptId ? { scriptId: evaluated.scriptId } : {}
|
|
21666
|
+
});
|
|
21667
|
+
} catch (error51) {
|
|
21668
|
+
overlayClients.delete(target2.id);
|
|
21669
|
+
if (voiceHostDisposals) unbindRendererVoiceHost(connected, voiceHostDisposals);
|
|
21670
|
+
connected.close();
|
|
21671
|
+
throw error51;
|
|
20574
21672
|
}
|
|
20575
21673
|
}
|
|
20576
21674
|
function isLocalThreadRenderer(target2) {
|
|
@@ -20636,7 +21734,7 @@ async function installLocalThreadRenderer(target2, source, enabledAgents, operat
|
|
|
20636
21734
|
renderer.close();
|
|
20637
21735
|
}
|
|
20638
21736
|
}
|
|
20639
|
-
async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, browserStyleClients, operations, signal) {
|
|
21737
|
+
async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, operations, signal, voiceHost, voiceHostDisposals) {
|
|
20640
21738
|
try {
|
|
20641
21739
|
const targets = await awaitWithSignal(
|
|
20642
21740
|
operations.listTargets(endpoint, signal),
|
|
@@ -20644,10 +21742,13 @@ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents
|
|
|
20644
21742
|
"Auxiliary Renderer CDP target discovery timed out"
|
|
20645
21743
|
);
|
|
20646
21744
|
const liveTargets = new Set(targets.map((target2) => target2.id));
|
|
20647
|
-
for (const [
|
|
20648
|
-
|
|
20649
|
-
|
|
20650
|
-
|
|
21745
|
+
for (const clients of [browserStyleClients, overlayClients]) {
|
|
21746
|
+
for (const [id, client] of clients) {
|
|
21747
|
+
if (!liveTargets.has(id)) {
|
|
21748
|
+
if (voiceHostDisposals) unbindRendererVoiceHost(client, voiceHostDisposals);
|
|
21749
|
+
client.close();
|
|
21750
|
+
clients.delete(id);
|
|
21751
|
+
}
|
|
20651
21752
|
}
|
|
20652
21753
|
}
|
|
20653
21754
|
await Promise.allSettled([
|
|
@@ -20655,7 +21756,16 @@ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents
|
|
|
20655
21756
|
(target2) => installBrowserAnnotationStyles(target2, browserStyleClients, operations, signal)
|
|
20656
21757
|
),
|
|
20657
21758
|
...overlayHookSource ? selectAvatarOverlayRendererTargets(targets).map(
|
|
20658
|
-
(overlay) => installOverlayHook(
|
|
21759
|
+
(overlay) => installOverlayHook(
|
|
21760
|
+
overlay,
|
|
21761
|
+
overlayHookSource,
|
|
21762
|
+
overlayClients,
|
|
21763
|
+
operations,
|
|
21764
|
+
signal,
|
|
21765
|
+
overlayVoiceBootstrapSource,
|
|
21766
|
+
voiceHost,
|
|
21767
|
+
voiceHostDisposals
|
|
21768
|
+
)
|
|
20659
21769
|
) : [],
|
|
20660
21770
|
...targets.filter(isLocalThreadRenderer).map(
|
|
20661
21771
|
(target2) => installLocalThreadRenderer(target2, rendererSource, enabledAgents, operations, signal)
|
|
@@ -20664,10 +21774,14 @@ async function installAuxiliaryRenderers(endpoint, rendererSource, enabledAgents
|
|
|
20664
21774
|
} catch {
|
|
20665
21775
|
}
|
|
20666
21776
|
}
|
|
20667
|
-
async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations) {
|
|
21777
|
+
async function installTarget(target2, rendererSource, enabledAgents, timeoutMs, pollIntervalMs, operations, voiceHost, voiceHostDisposals) {
|
|
20668
21778
|
const renderer = await operations.connect(target2.webSocketDebuggerUrl);
|
|
20669
21779
|
let disposeModules;
|
|
20670
21780
|
try {
|
|
21781
|
+
if (voiceHost && voiceHostDisposals)
|
|
21782
|
+
await bindRendererVoiceHost(renderer, voiceHost, voiceHostDisposals, {
|
|
21783
|
+
enableRuntime: false
|
|
21784
|
+
});
|
|
20671
21785
|
disposeModules = await installRendererLoadedModules(renderer);
|
|
20672
21786
|
await renderer.command("Page.enable");
|
|
20673
21787
|
await renderer.command("Page.addScriptToEvaluateOnNewDocument", { source: rendererSource });
|
|
@@ -20677,35 +21791,44 @@ async function installTarget(target2, rendererSource, enabledAgents, timeoutMs,
|
|
|
20677
21791
|
return { renderer, snapshot: { target: target2, draftPrewarmPolicy, binding }, disposeModules };
|
|
20678
21792
|
} catch (error51) {
|
|
20679
21793
|
disposeModules?.();
|
|
21794
|
+
if (voiceHostDisposals) unbindRendererVoiceHost(renderer, voiceHostDisposals);
|
|
20680
21795
|
renderer.close();
|
|
20681
21796
|
throw error51;
|
|
20682
21797
|
}
|
|
20683
21798
|
}
|
|
20684
21799
|
var InstalledRendererCdpControlSession = class {
|
|
20685
|
-
constructor(renderer, rendererCdpEndpoint2, rendererSource, overlayHookSource, browserStyleClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules) {
|
|
21800
|
+
constructor(renderer, rendererCdpEndpoint2, rendererSource, overlayHookSource, overlayVoiceBootstrapSource, browserStyleClients, overlayClients, enabledAgents, timeoutMs, pollIntervalMs, operations, currentSnapshot, disposeModules, voiceHost, voiceHostDisposals) {
|
|
20686
21801
|
this.renderer = renderer;
|
|
20687
21802
|
this.rendererCdpEndpoint = rendererCdpEndpoint2;
|
|
20688
21803
|
this.rendererSource = rendererSource;
|
|
20689
21804
|
this.overlayHookSource = overlayHookSource;
|
|
21805
|
+
this.overlayVoiceBootstrapSource = overlayVoiceBootstrapSource;
|
|
20690
21806
|
this.browserStyleClients = browserStyleClients;
|
|
21807
|
+
this.overlayClients = overlayClients;
|
|
20691
21808
|
this.enabledAgents = enabledAgents;
|
|
20692
21809
|
this.timeoutMs = timeoutMs;
|
|
20693
21810
|
this.pollIntervalMs = pollIntervalMs;
|
|
20694
21811
|
this.operations = operations;
|
|
20695
21812
|
this.currentSnapshot = currentSnapshot;
|
|
20696
21813
|
this.disposeModules = disposeModules;
|
|
21814
|
+
this.voiceHost = voiceHost;
|
|
21815
|
+
this.voiceHostDisposals = voiceHostDisposals;
|
|
20697
21816
|
}
|
|
20698
21817
|
renderer;
|
|
20699
21818
|
rendererCdpEndpoint;
|
|
20700
21819
|
rendererSource;
|
|
20701
21820
|
overlayHookSource;
|
|
21821
|
+
overlayVoiceBootstrapSource;
|
|
20702
21822
|
browserStyleClients;
|
|
21823
|
+
overlayClients;
|
|
20703
21824
|
enabledAgents;
|
|
20704
21825
|
timeoutMs;
|
|
20705
21826
|
pollIntervalMs;
|
|
20706
21827
|
operations;
|
|
20707
21828
|
currentSnapshot;
|
|
20708
21829
|
disposeModules;
|
|
21830
|
+
voiceHost;
|
|
21831
|
+
voiceHostDisposals;
|
|
20709
21832
|
#closed = false;
|
|
20710
21833
|
get snapshot() {
|
|
20711
21834
|
return this.currentSnapshot;
|
|
@@ -20726,9 +21849,12 @@ var InstalledRendererCdpControlSession = class {
|
|
|
20726
21849
|
this.enabledAgents,
|
|
20727
21850
|
this.timeoutMs,
|
|
20728
21851
|
this.pollIntervalMs,
|
|
20729
|
-
this.operations
|
|
21852
|
+
this.operations,
|
|
21853
|
+
this.voiceHost,
|
|
21854
|
+
this.voiceHostDisposals
|
|
20730
21855
|
);
|
|
20731
21856
|
this.disposeModules();
|
|
21857
|
+
unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals);
|
|
20732
21858
|
this.renderer.close();
|
|
20733
21859
|
this.renderer = replacement.renderer;
|
|
20734
21860
|
this.disposeModules = replacement.disposeModules;
|
|
@@ -20752,9 +21878,12 @@ var InstalledRendererCdpControlSession = class {
|
|
|
20752
21878
|
this.enabledAgents,
|
|
20753
21879
|
this.timeoutMs,
|
|
20754
21880
|
this.pollIntervalMs,
|
|
20755
|
-
this.operations
|
|
21881
|
+
this.operations,
|
|
21882
|
+
this.voiceHost,
|
|
21883
|
+
this.voiceHostDisposals
|
|
20756
21884
|
);
|
|
20757
21885
|
this.disposeModules();
|
|
21886
|
+
unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals);
|
|
20758
21887
|
this.renderer.close();
|
|
20759
21888
|
this.renderer = replacement.renderer;
|
|
20760
21889
|
this.disposeModules = replacement.disposeModules;
|
|
@@ -20766,9 +21895,13 @@ var InstalledRendererCdpControlSession = class {
|
|
|
20766
21895
|
this.rendererSource,
|
|
20767
21896
|
this.enabledAgents,
|
|
20768
21897
|
this.overlayHookSource,
|
|
21898
|
+
this.overlayVoiceBootstrapSource,
|
|
20769
21899
|
this.browserStyleClients,
|
|
21900
|
+
this.overlayClients,
|
|
20770
21901
|
this.operations,
|
|
20771
|
-
discoveryTimeoutSignal(this.timeoutMs)
|
|
21902
|
+
discoveryTimeoutSignal(this.timeoutMs),
|
|
21903
|
+
this.voiceHost,
|
|
21904
|
+
this.voiceHostDisposals
|
|
20772
21905
|
);
|
|
20773
21906
|
return this.currentSnapshot;
|
|
20774
21907
|
}
|
|
@@ -20785,9 +21918,17 @@ var InstalledRendererCdpControlSession = class {
|
|
|
20785
21918
|
if (this.#closed) return;
|
|
20786
21919
|
this.#closed = true;
|
|
20787
21920
|
this.disposeModules();
|
|
21921
|
+
unbindRendererVoiceHost(this.renderer, this.voiceHostDisposals);
|
|
20788
21922
|
this.renderer.close();
|
|
20789
21923
|
for (const client of this.browserStyleClients.values()) client.close();
|
|
20790
21924
|
this.browserStyleClients.clear();
|
|
21925
|
+
for (const client of this.overlayClients.values()) {
|
|
21926
|
+
unbindRendererVoiceHost(client, this.voiceHostDisposals);
|
|
21927
|
+
client.close();
|
|
21928
|
+
}
|
|
21929
|
+
this.overlayClients.clear();
|
|
21930
|
+
for (const dispose of this.voiceHostDisposals.values()) dispose();
|
|
21931
|
+
this.voiceHostDisposals.clear();
|
|
20791
21932
|
}
|
|
20792
21933
|
};
|
|
20793
21934
|
var defaultOperations = {
|
|
@@ -20813,42 +21954,440 @@ async function createRendererCdpControlSession(options) {
|
|
|
20813
21954
|
void 0,
|
|
20814
21955
|
options.signal
|
|
20815
21956
|
);
|
|
21957
|
+
const voiceHostDisposals = /* @__PURE__ */ new Map();
|
|
20816
21958
|
const installed = await installTarget(
|
|
20817
21959
|
target2,
|
|
20818
21960
|
options.rendererSource,
|
|
20819
21961
|
enabledAgents,
|
|
20820
21962
|
timeoutMs,
|
|
20821
21963
|
pollIntervalMs,
|
|
20822
|
-
operations
|
|
21964
|
+
operations,
|
|
21965
|
+
options.voiceHost,
|
|
21966
|
+
voiceHostDisposals
|
|
20823
21967
|
);
|
|
20824
21968
|
const browserStyleClients = /* @__PURE__ */ new Map();
|
|
21969
|
+
const overlayClients = /* @__PURE__ */ new Map();
|
|
20825
21970
|
await installAuxiliaryRenderers(
|
|
20826
21971
|
options.rendererCdpEndpoint,
|
|
20827
21972
|
options.rendererSource,
|
|
20828
21973
|
enabledAgents,
|
|
20829
21974
|
options.overlayHookSource,
|
|
21975
|
+
options.overlayVoiceBootstrapSource,
|
|
20830
21976
|
browserStyleClients,
|
|
21977
|
+
overlayClients,
|
|
20831
21978
|
operations,
|
|
20832
|
-
discoveryTimeoutSignal(timeoutMs, options.signal)
|
|
21979
|
+
discoveryTimeoutSignal(timeoutMs, options.signal),
|
|
21980
|
+
options.voiceHost,
|
|
21981
|
+
voiceHostDisposals
|
|
20833
21982
|
);
|
|
20834
21983
|
return new InstalledRendererCdpControlSession(
|
|
20835
21984
|
installed.renderer,
|
|
20836
21985
|
options.rendererCdpEndpoint,
|
|
20837
21986
|
options.rendererSource,
|
|
20838
21987
|
options.overlayHookSource,
|
|
21988
|
+
options.overlayVoiceBootstrapSource,
|
|
20839
21989
|
browserStyleClients,
|
|
21990
|
+
overlayClients,
|
|
20840
21991
|
enabledAgents,
|
|
20841
21992
|
timeoutMs,
|
|
20842
21993
|
pollIntervalMs,
|
|
20843
21994
|
operations,
|
|
20844
21995
|
installed.snapshot,
|
|
20845
|
-
installed.disposeModules
|
|
21996
|
+
installed.disposeModules,
|
|
21997
|
+
options.voiceHost,
|
|
21998
|
+
voiceHostDisposals
|
|
20846
21999
|
);
|
|
20847
22000
|
}
|
|
20848
22001
|
function installRendererCdpControlSession(options) {
|
|
20849
22002
|
return createRendererCdpControlSession(options);
|
|
20850
22003
|
}
|
|
20851
22004
|
|
|
22005
|
+
// packages/desktop-control/src/renderer-injection-skip.ts
|
|
22006
|
+
var SKIPPED_DESKTOP_VERSION_PREFIXES = ["26.1103.", "26.1106."];
|
|
22007
|
+
var HASHED_RENDERER_CANDIDATE_VERSION = "26.1106.51428";
|
|
22008
|
+
function rendererInjectionSkipReason(desktopVersion, platform = process.platform, options) {
|
|
22009
|
+
const version2 = desktopVersion?.trim();
|
|
22010
|
+
if (!version2) return null;
|
|
22011
|
+
if (platform === "darwin" && version2 === HASHED_RENDERER_CANDIDATE_VERSION) return null;
|
|
22012
|
+
if (SKIPPED_DESKTOP_VERSION_PREFIXES.some((prefix) => version2.startsWith(prefix))) {
|
|
22013
|
+
if (allowsIsolatedHashedInjection(version2, platform, options)) return null;
|
|
22014
|
+
return `Desktop ${version2} is skipped until hashed Renderer bindings are requalified`;
|
|
22015
|
+
}
|
|
22016
|
+
return null;
|
|
22017
|
+
}
|
|
22018
|
+
function suppliedIdentityConflicts(version2, platform, identity2) {
|
|
22019
|
+
if (!identity2) return false;
|
|
22020
|
+
if (identity2.desktopPlatform !== void 0 && identity2.desktopPlatform !== platform) return true;
|
|
22021
|
+
if (identity2.desktopVersion !== void 0 && identity2.desktopVersion.trim() !== version2) {
|
|
22022
|
+
return true;
|
|
22023
|
+
}
|
|
22024
|
+
return false;
|
|
22025
|
+
}
|
|
22026
|
+
function allowsIsolatedHashedInjection(version2, platform, options) {
|
|
22027
|
+
if (!options?.isolated || !options.identity) return false;
|
|
22028
|
+
if (suppliedIdentityConflicts(version2, platform, options.identity)) return false;
|
|
22029
|
+
if (version2 !== HASHED_RENDERER_CANDIDATE_VERSION) return false;
|
|
22030
|
+
if (platform !== "win32") return false;
|
|
22031
|
+
if (!isIsolatedVoiceQualification(options.isolated)) return false;
|
|
22032
|
+
if (isProductionDesktopAppPath(options.identity.appPath) || isProductionDesktopAppPath(options.isolated.appPath)) {
|
|
22033
|
+
return false;
|
|
22034
|
+
}
|
|
22035
|
+
return isolatedQualificationMatchesRuntime(options.isolated, {
|
|
22036
|
+
desktopPlatform: platform,
|
|
22037
|
+
desktopVersion: version2,
|
|
22038
|
+
...options.identity.desktopBuild ? { desktopBuild: options.identity.desktopBuild } : {},
|
|
22039
|
+
...options.identity.asarDigest ? { asarDigest: options.identity.asarDigest } : {},
|
|
22040
|
+
...options.identity.appPath ? { appPath: options.identity.appPath } : {},
|
|
22041
|
+
...options.identity.implementationRevision ? { implementationRevision: options.identity.implementationRevision } : {}
|
|
22042
|
+
});
|
|
22043
|
+
}
|
|
22044
|
+
|
|
22045
|
+
// packages/desktop-control/src/controller-voice-host.ts
|
|
22046
|
+
import path5 from "node:path";
|
|
22047
|
+
|
|
22048
|
+
// packages/desktop-control/src/host-client-channel.ts
|
|
22049
|
+
import { readdir, open } from "node:fs/promises";
|
|
22050
|
+
import { constants } from "node:fs";
|
|
22051
|
+
import path4 from "node:path";
|
|
22052
|
+
var VOICE_SETTINGS_TIMEOUT_MS = 1e4;
|
|
22053
|
+
var VOICE_GATEWAY_STATUS_TIMEOUT_MS = 2e3;
|
|
22054
|
+
var REALTIME_CALL_TIMEOUT_MS = 3e4;
|
|
22055
|
+
var VOICE_GATEWAY_STAGES = /* @__PURE__ */ new Set(["config", "request", "transport", "identity", "cancel"]);
|
|
22056
|
+
function voiceGatewayStage(value) {
|
|
22057
|
+
return typeof value === "string" && VOICE_GATEWAY_STAGES.has(value) ? value : void 0;
|
|
22058
|
+
}
|
|
22059
|
+
async function discoverHostClientChannel(directory) {
|
|
22060
|
+
const candidates = [];
|
|
22061
|
+
for (const name of await readdir(directory).catch(() => [])) {
|
|
22062
|
+
if (!/^host-\d+(?:-[0-9a-f-]+)?\.json$/u.test(name)) continue;
|
|
22063
|
+
try {
|
|
22064
|
+
const handle = await open(
|
|
22065
|
+
path4.join(directory, name),
|
|
22066
|
+
constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0)
|
|
22067
|
+
);
|
|
22068
|
+
try {
|
|
22069
|
+
const stat = await handle.stat();
|
|
22070
|
+
if (!stat.isFile() || stat.size > 4096 || process.platform !== "win32" && (stat.uid !== process.getuid?.() || (stat.mode & 63) !== 0))
|
|
22071
|
+
continue;
|
|
22072
|
+
const descriptor = clientChannelDescriptorSchema.parse(
|
|
22073
|
+
JSON.parse(await handle.readFile("utf8"))
|
|
22074
|
+
);
|
|
22075
|
+
process.kill(descriptor.pid, 0);
|
|
22076
|
+
candidates.push(descriptor);
|
|
22077
|
+
} finally {
|
|
22078
|
+
await handle.close();
|
|
22079
|
+
}
|
|
22080
|
+
} catch {
|
|
22081
|
+
}
|
|
22082
|
+
}
|
|
22083
|
+
return candidates.sort((a, b) => b.startedAt - a.startedAt)[0] ?? null;
|
|
22084
|
+
}
|
|
22085
|
+
var HostClientChannel = class {
|
|
22086
|
+
constructor(directory, descriptor, ensureOwner) {
|
|
22087
|
+
this.directory = directory;
|
|
22088
|
+
this.ensureOwner = ensureOwner;
|
|
22089
|
+
this.descriptor = descriptor;
|
|
22090
|
+
}
|
|
22091
|
+
directory;
|
|
22092
|
+
ensureOwner;
|
|
22093
|
+
descriptor;
|
|
22094
|
+
cursor;
|
|
22095
|
+
history = [];
|
|
22096
|
+
controller;
|
|
22097
|
+
retry;
|
|
22098
|
+
listeners = /* @__PURE__ */ new Set();
|
|
22099
|
+
stopped = false;
|
|
22100
|
+
online = false;
|
|
22101
|
+
generation = 0;
|
|
22102
|
+
ready = Promise.withResolvers();
|
|
22103
|
+
started = false;
|
|
22104
|
+
subscribe(listener, after) {
|
|
22105
|
+
listener({ type: "connection", online: this.online });
|
|
22106
|
+
const cursor = this.cursor;
|
|
22107
|
+
if (this.online && cursor) {
|
|
22108
|
+
const oldest = this.history[0]?.cursor.sequence ?? cursor.sequence + 1;
|
|
22109
|
+
const replay = after?.epoch === cursor.epoch && after.sequence >= oldest - 1 && after.sequence <= cursor.sequence;
|
|
22110
|
+
listener({ type: "hello", version: 1, cursor, reset: !replay });
|
|
22111
|
+
if (replay) {
|
|
22112
|
+
for (const event of this.history)
|
|
22113
|
+
if (event.cursor.sequence > after.sequence) listener(event);
|
|
22114
|
+
}
|
|
22115
|
+
}
|
|
22116
|
+
this.listeners.add(listener);
|
|
22117
|
+
return () => this.listeners.delete(listener);
|
|
22118
|
+
}
|
|
22119
|
+
publish(update) {
|
|
22120
|
+
for (const listener of this.listeners) {
|
|
22121
|
+
try {
|
|
22122
|
+
listener(update);
|
|
22123
|
+
} catch {
|
|
22124
|
+
this.listeners.delete(listener);
|
|
22125
|
+
}
|
|
22126
|
+
}
|
|
22127
|
+
}
|
|
22128
|
+
start() {
|
|
22129
|
+
if (!this.started) {
|
|
22130
|
+
this.started = true;
|
|
22131
|
+
void this.connect();
|
|
22132
|
+
}
|
|
22133
|
+
return this.ready.promise;
|
|
22134
|
+
}
|
|
22135
|
+
async connect() {
|
|
22136
|
+
if (this.stopped) return;
|
|
22137
|
+
const controller = new AbortController();
|
|
22138
|
+
this.controller = controller;
|
|
22139
|
+
this.generation++;
|
|
22140
|
+
let deadline;
|
|
22141
|
+
try {
|
|
22142
|
+
await this.ensureOwner?.();
|
|
22143
|
+
if (this.stopped) return;
|
|
22144
|
+
deadline = setTimeout(() => controller.abort(), 5e3);
|
|
22145
|
+
const descriptor = await discoverHostClientChannel(this.directory);
|
|
22146
|
+
if (!descriptor) throw new Error("Host unavailable");
|
|
22147
|
+
this.descriptor = descriptor;
|
|
22148
|
+
const url2 = new URL(`http://127.0.0.1:${descriptor.port}/v1/events`);
|
|
22149
|
+
if (this.cursor) {
|
|
22150
|
+
url2.searchParams.set("epoch", this.cursor.epoch);
|
|
22151
|
+
url2.searchParams.set("after", String(this.cursor.sequence));
|
|
22152
|
+
}
|
|
22153
|
+
const response = await fetch(url2, {
|
|
22154
|
+
redirect: "error",
|
|
22155
|
+
headers: { authorization: `Bearer ${descriptor.token}` },
|
|
22156
|
+
signal: controller.signal
|
|
22157
|
+
});
|
|
22158
|
+
clearTimeout(deadline);
|
|
22159
|
+
deadline = setTimeout(() => controller.abort(), 45e3);
|
|
22160
|
+
if (!response.ok || !response.body) throw new Error("Host event channel refused");
|
|
22161
|
+
const reader = response.body.getReader();
|
|
22162
|
+
const decoder = new TextDecoder();
|
|
22163
|
+
let buffer = "";
|
|
22164
|
+
for (; ; ) {
|
|
22165
|
+
const chunk = await reader.read();
|
|
22166
|
+
if (chunk.done) throw new Error("Host event channel ended");
|
|
22167
|
+
clearTimeout(deadline);
|
|
22168
|
+
deadline = setTimeout(() => controller.abort(), 45e3);
|
|
22169
|
+
buffer += decoder.decode(chunk.value, { stream: true });
|
|
22170
|
+
if (buffer.length > 256 * 1024) throw new Error("Host event frame exceeds limit");
|
|
22171
|
+
let end;
|
|
22172
|
+
while ((end = buffer.indexOf("\n")) !== -1) {
|
|
22173
|
+
const line = buffer.slice(0, end);
|
|
22174
|
+
buffer = buffer.slice(end + 1);
|
|
22175
|
+
if (!line.trim()) continue;
|
|
22176
|
+
const event = clientChannelEventSchema.parse(JSON.parse(line));
|
|
22177
|
+
if (event.type === "hello") {
|
|
22178
|
+
if (event.cursor.epoch !== descriptor.epoch)
|
|
22179
|
+
throw new Error("Host descriptor generation changed");
|
|
22180
|
+
if (event.reset || !this.cursor) {
|
|
22181
|
+
this.cursor = event.cursor;
|
|
22182
|
+
this.history = [];
|
|
22183
|
+
}
|
|
22184
|
+
this.online = true;
|
|
22185
|
+
this.ready.resolve(void 0);
|
|
22186
|
+
this.publish({ type: "connection", online: true });
|
|
22187
|
+
this.publish(event);
|
|
22188
|
+
} else {
|
|
22189
|
+
if (!this.cursor || event.cursor.epoch !== this.cursor.epoch || event.cursor.sequence !== this.cursor.sequence + 1)
|
|
22190
|
+
throw new Error("Host event sequence gap");
|
|
22191
|
+
this.cursor = event.cursor;
|
|
22192
|
+
this.history.push(event);
|
|
22193
|
+
if (this.history.length > 512) this.history.shift();
|
|
22194
|
+
this.publish(event);
|
|
22195
|
+
}
|
|
22196
|
+
}
|
|
22197
|
+
}
|
|
22198
|
+
} catch {
|
|
22199
|
+
this.ready.reject(new Error("Host event connection unavailable"));
|
|
22200
|
+
if (!this.stopped) {
|
|
22201
|
+
this.online = false;
|
|
22202
|
+
this.publish({ type: "connection", online: false });
|
|
22203
|
+
}
|
|
22204
|
+
} finally {
|
|
22205
|
+
clearTimeout(deadline);
|
|
22206
|
+
controller.abort();
|
|
22207
|
+
if (!this.stopped) {
|
|
22208
|
+
this.retry = setTimeout(() => {
|
|
22209
|
+
void this.connect();
|
|
22210
|
+
}, 1e3);
|
|
22211
|
+
this.retry.unref();
|
|
22212
|
+
}
|
|
22213
|
+
}
|
|
22214
|
+
}
|
|
22215
|
+
bindVoiceExecution() {
|
|
22216
|
+
const generation = this.generation;
|
|
22217
|
+
const port = this.descriptor.port;
|
|
22218
|
+
const token = this.descriptor.token;
|
|
22219
|
+
return {
|
|
22220
|
+
generation,
|
|
22221
|
+
request: (method, params) => this.post(
|
|
22222
|
+
"/v1/rpc",
|
|
22223
|
+
{ method, params },
|
|
22224
|
+
method === VOICE_GATEWAY_STATUS_METHOD ? VOICE_GATEWAY_STATUS_TIMEOUT_MS : method === REALTIME_CALL_METHOD ? REALTIME_CALL_TIMEOUT_MS : VOICE_SETTINGS_TIMEOUT_MS,
|
|
22225
|
+
{ port, token }
|
|
22226
|
+
)
|
|
22227
|
+
};
|
|
22228
|
+
}
|
|
22229
|
+
async post(route, body, timeoutMs = 12e4, bound) {
|
|
22230
|
+
if (!bound && (this.stopped || !this.online))
|
|
22231
|
+
throw new Error("CH is disconnected; reconnect before submitting an operation");
|
|
22232
|
+
const generation = this.generation;
|
|
22233
|
+
const port = bound?.port ?? this.descriptor.port;
|
|
22234
|
+
const token = bound?.token ?? this.descriptor.token;
|
|
22235
|
+
let response;
|
|
22236
|
+
let value;
|
|
22237
|
+
try {
|
|
22238
|
+
response = await fetch(`http://127.0.0.1:${port}${route}`, {
|
|
22239
|
+
redirect: "error",
|
|
22240
|
+
method: "POST",
|
|
22241
|
+
headers: {
|
|
22242
|
+
authorization: `Bearer ${token}`,
|
|
22243
|
+
"content-type": "application/json"
|
|
22244
|
+
},
|
|
22245
|
+
body: JSON.stringify(body),
|
|
22246
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
22247
|
+
});
|
|
22248
|
+
const parsed = await response.json();
|
|
22249
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
22250
|
+
throw new Error("Invalid Host reply");
|
|
22251
|
+
value = parsed;
|
|
22252
|
+
} catch (error51) {
|
|
22253
|
+
if (bound)
|
|
22254
|
+
throw Object.assign(new Error(RENDERER_VOICE_HOST_CLEANUP_UNCONFIRMED), {
|
|
22255
|
+
code: -32093,
|
|
22256
|
+
stage: "cancel"
|
|
22257
|
+
});
|
|
22258
|
+
if (error51 && typeof error51 === "object" && "stage" in error51) throw error51;
|
|
22259
|
+
throw Object.assign(
|
|
22260
|
+
new Error(
|
|
22261
|
+
"CH connection lost; operation outcome may be unknown. Do not retry automatically."
|
|
22262
|
+
),
|
|
22263
|
+
{ code: -32093 }
|
|
22264
|
+
);
|
|
22265
|
+
}
|
|
22266
|
+
if (!bound && (generation !== this.generation || !this.online || this.stopped))
|
|
22267
|
+
throw Object.assign(new Error("Obsolete Host reply; resynchronize after reconnecting"), {
|
|
22268
|
+
code: -32094
|
|
22269
|
+
});
|
|
22270
|
+
if (value.error || !response.ok) {
|
|
22271
|
+
const error51 = value.error;
|
|
22272
|
+
const data = error51 && typeof error51 === "object" && "data" in error51 ? error51.data : void 0;
|
|
22273
|
+
const stage = data && typeof data === "object" && data !== null && "stage" in data ? voiceGatewayStage(data.stage) : void 0;
|
|
22274
|
+
throw Object.assign(new Error(error51?.message ?? "Host request failed"), {
|
|
22275
|
+
code: error51?.code ?? -32603,
|
|
22276
|
+
...stage ? { stage } : {}
|
|
22277
|
+
});
|
|
22278
|
+
}
|
|
22279
|
+
if (!Object.hasOwn(value, "result"))
|
|
22280
|
+
throw new Error("Invalid Host reply; operation outcome may be unknown");
|
|
22281
|
+
return value.result;
|
|
22282
|
+
}
|
|
22283
|
+
request(method, params) {
|
|
22284
|
+
return this.post(
|
|
22285
|
+
"/v1/rpc",
|
|
22286
|
+
{ method, params },
|
|
22287
|
+
harnessInstallationRequestTimeoutMs(method, params) ?? 12e4
|
|
22288
|
+
);
|
|
22289
|
+
}
|
|
22290
|
+
requestVoiceSettings(params) {
|
|
22291
|
+
return this.post(
|
|
22292
|
+
"/v1/rpc",
|
|
22293
|
+
{ method: VOICE_SETTINGS_METHOD, params },
|
|
22294
|
+
VOICE_SETTINGS_TIMEOUT_MS
|
|
22295
|
+
);
|
|
22296
|
+
}
|
|
22297
|
+
requestVoiceGatewayStatus() {
|
|
22298
|
+
return this.post(
|
|
22299
|
+
"/v1/rpc",
|
|
22300
|
+
{ method: VOICE_GATEWAY_STATUS_METHOD, params: {} },
|
|
22301
|
+
VOICE_GATEWAY_STATUS_TIMEOUT_MS
|
|
22302
|
+
);
|
|
22303
|
+
}
|
|
22304
|
+
requestRealtimeCall(params) {
|
|
22305
|
+
return this.post("/v1/rpc", { method: REALTIME_CALL_METHOD, params }, REALTIME_CALL_TIMEOUT_MS);
|
|
22306
|
+
}
|
|
22307
|
+
get epoch() {
|
|
22308
|
+
return this.descriptor.epoch;
|
|
22309
|
+
}
|
|
22310
|
+
get channelGeneration() {
|
|
22311
|
+
return this.generation;
|
|
22312
|
+
}
|
|
22313
|
+
/** Options are opt-in; an older Host ignores them and returns full Turns. */
|
|
22314
|
+
async snapshot(threadId, options = {}) {
|
|
22315
|
+
const generation = this.generation;
|
|
22316
|
+
const snapshot = clientThreadSnapshotSchema.parse(
|
|
22317
|
+
await this.post("/v1/snapshot", { ...options, threadId })
|
|
22318
|
+
);
|
|
22319
|
+
if (snapshot.thread.id !== threadId || snapshot.interactions.some((request) => request.threadId !== threadId))
|
|
22320
|
+
throw new Error("Host snapshot belongs to another Thread");
|
|
22321
|
+
if (generation !== this.generation || !this.online || snapshot.cursor.epoch !== this.descriptor.epoch)
|
|
22322
|
+
throw Object.assign(new Error("Obsolete Host snapshot; resynchronize after reconnecting"), {
|
|
22323
|
+
code: -32094
|
|
22324
|
+
});
|
|
22325
|
+
return snapshot;
|
|
22326
|
+
}
|
|
22327
|
+
respond(input) {
|
|
22328
|
+
return this.post("/v1/respond", input);
|
|
22329
|
+
}
|
|
22330
|
+
close() {
|
|
22331
|
+
this.stopped = true;
|
|
22332
|
+
this.online = false;
|
|
22333
|
+
clearTimeout(this.retry);
|
|
22334
|
+
this.controller?.abort();
|
|
22335
|
+
this.publish({ type: "connection", online: false });
|
|
22336
|
+
this.listeners.clear();
|
|
22337
|
+
}
|
|
22338
|
+
};
|
|
22339
|
+
|
|
22340
|
+
// packages/desktop-control/src/controller-voice-host.ts
|
|
22341
|
+
var ControllerVoiceHost = class {
|
|
22342
|
+
constructor(channel) {
|
|
22343
|
+
this.channel = channel;
|
|
22344
|
+
this.generation = Math.max(1, channel.channelGeneration);
|
|
22345
|
+
channel.subscribe((update) => {
|
|
22346
|
+
if (update.type !== "connection") return;
|
|
22347
|
+
const next = Math.max(1, channel.channelGeneration);
|
|
22348
|
+
if (next === this.generation) return;
|
|
22349
|
+
this.generation = next;
|
|
22350
|
+
for (const listener of this.#listeners) listener();
|
|
22351
|
+
});
|
|
22352
|
+
}
|
|
22353
|
+
channel;
|
|
22354
|
+
owner = crypto.randomUUID();
|
|
22355
|
+
generation = 1;
|
|
22356
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
22357
|
+
onGenerationChange(listener) {
|
|
22358
|
+
this.#listeners.add(listener);
|
|
22359
|
+
return () => this.#listeners.delete(listener);
|
|
22360
|
+
}
|
|
22361
|
+
bindExecution() {
|
|
22362
|
+
return this.channel.bindVoiceExecution();
|
|
22363
|
+
}
|
|
22364
|
+
request(method, params) {
|
|
22365
|
+
if (method === VOICE_SETTINGS_METHOD) return this.channel.requestVoiceSettings(params);
|
|
22366
|
+
if (method === VOICE_GATEWAY_STATUS_METHOD) return this.channel.requestVoiceGatewayStatus();
|
|
22367
|
+
if (method === REALTIME_CALL_METHOD) return this.channel.requestRealtimeCall(params);
|
|
22368
|
+
return Promise.reject(
|
|
22369
|
+
Object.assign(new Error("Voice method is not available"), { code: -32601 })
|
|
22370
|
+
);
|
|
22371
|
+
}
|
|
22372
|
+
close() {
|
|
22373
|
+
this.#listeners.clear();
|
|
22374
|
+
this.channel.close();
|
|
22375
|
+
}
|
|
22376
|
+
};
|
|
22377
|
+
async function connectControllerVoiceHost(dataDirectory) {
|
|
22378
|
+
const directory = path5.join(dataDirectory, "client-hosts");
|
|
22379
|
+
const descriptor = await discoverHostClientChannel(directory);
|
|
22380
|
+
if (!descriptor) return;
|
|
22381
|
+
const channel = new HostClientChannel(directory, descriptor);
|
|
22382
|
+
try {
|
|
22383
|
+
await channel.start();
|
|
22384
|
+
return new ControllerVoiceHost(channel);
|
|
22385
|
+
} catch {
|
|
22386
|
+
channel.close();
|
|
22387
|
+
return;
|
|
22388
|
+
}
|
|
22389
|
+
}
|
|
22390
|
+
|
|
20852
22391
|
// packages/desktop-control/src/production-controller.ts
|
|
20853
22392
|
var PRODUCTION_INSTALL_TIMEOUT_MS = 9e4;
|
|
20854
22393
|
var RENDERER_CSP_BOOTSTRAP = "globalThis.__zod_globalConfig ??= {}; globalThis.__zod_globalConfig.jitless = true;";
|
|
@@ -20899,6 +22438,7 @@ function parseDesktopControllerArguments(arguments_) {
|
|
|
20899
22438
|
let rendererPath;
|
|
20900
22439
|
let attachmentPort;
|
|
20901
22440
|
let attachmentNonce;
|
|
22441
|
+
let hostDataDirectory;
|
|
20902
22442
|
for (let index = 0; index < arguments_.length; index += 1) {
|
|
20903
22443
|
const argument = arguments_[index];
|
|
20904
22444
|
const value = arguments_[index + 1];
|
|
@@ -20914,8 +22454,8 @@ function parseDesktopControllerArguments(arguments_) {
|
|
|
20914
22454
|
if (argument === "--renderer") {
|
|
20915
22455
|
if (rendererPath !== void 0) throw new Error("--renderer may only be provided once");
|
|
20916
22456
|
if (!value) throw new Error("--renderer requires a value");
|
|
20917
|
-
if (!
|
|
20918
|
-
rendererPath =
|
|
22457
|
+
if (!path6.isAbsolute(value)) throw new Error("--renderer must be an absolute path");
|
|
22458
|
+
rendererPath = path6.normalize(value);
|
|
20919
22459
|
index += 1;
|
|
20920
22460
|
continue;
|
|
20921
22461
|
}
|
|
@@ -20942,6 +22482,14 @@ function parseDesktopControllerArguments(arguments_) {
|
|
|
20942
22482
|
index += 1;
|
|
20943
22483
|
continue;
|
|
20944
22484
|
}
|
|
22485
|
+
if (argument === "--host-data") {
|
|
22486
|
+
if (hostDataDirectory !== void 0) throw new Error("--host-data may only be provided once");
|
|
22487
|
+
if (!value) throw new Error("--host-data requires a value");
|
|
22488
|
+
if (!path6.isAbsolute(value)) throw new Error("--host-data must be an absolute path");
|
|
22489
|
+
hostDataDirectory = path6.normalize(value);
|
|
22490
|
+
index += 1;
|
|
22491
|
+
continue;
|
|
22492
|
+
}
|
|
20945
22493
|
throw new Error(`unknown Desktop Controller option: ${argument}`);
|
|
20946
22494
|
}
|
|
20947
22495
|
if (endpoint === void 0) throw new Error("--renderer-cdp-endpoint is required");
|
|
@@ -20952,7 +22500,8 @@ function parseDesktopControllerArguments(arguments_) {
|
|
|
20952
22500
|
rendererCdpEndpoint: endpoint,
|
|
20953
22501
|
rendererPath,
|
|
20954
22502
|
attachmentPort,
|
|
20955
|
-
attachmentNonce
|
|
22503
|
+
attachmentNonce,
|
|
22504
|
+
...hostDataDirectory ? { hostDataDirectory } : {}
|
|
20956
22505
|
};
|
|
20957
22506
|
}
|
|
20958
22507
|
function isTransientRendererInstallError(error51) {
|
|
@@ -20984,9 +22533,32 @@ async function installProductionSession(options, dependencies) {
|
|
|
20984
22533
|
async function runDesktopController(options, signal, dependencies = defaultDependencies) {
|
|
20985
22534
|
const now = dependencies.now ?? Date.now;
|
|
20986
22535
|
let session;
|
|
22536
|
+
let voiceHost;
|
|
20987
22537
|
let nextRecoveryAt = 0;
|
|
20988
22538
|
let recoveryDelayMs = RECOVERY_RETRY_INITIAL_MS;
|
|
20989
|
-
const
|
|
22539
|
+
const overlayDir = path6.dirname(options.rendererPath);
|
|
22540
|
+
const isolated = readVoiceIsolatedQualification(overlayDir);
|
|
22541
|
+
const qualification = readVoiceQualification(overlayDir);
|
|
22542
|
+
const desktopVersion = process.env.CODEXHOST_DESKTOP_VERSION?.trim();
|
|
22543
|
+
const desktopBuild = process.env.CODEXHOST_DESKTOP_BUILD?.trim();
|
|
22544
|
+
const asarDigest = process.env.CODEXHOST_DESKTOP_ASAR_DIGEST?.trim();
|
|
22545
|
+
const appPath = process.env.CODEXHOST_DESKTOP_APP_PATH?.trim();
|
|
22546
|
+
const skipReason = rendererInjectionSkipReason(
|
|
22547
|
+
process.env.CODEXHOST_DESKTOP_VERSION,
|
|
22548
|
+
process.platform,
|
|
22549
|
+
{
|
|
22550
|
+
...isolated ? { isolated } : {},
|
|
22551
|
+
identity: {
|
|
22552
|
+
desktopPlatform: process.platform,
|
|
22553
|
+
...desktopVersion ? { desktopVersion } : {},
|
|
22554
|
+
...desktopBuild ? { desktopBuild } : {},
|
|
22555
|
+
...asarDigest ? { asarDigest } : {},
|
|
22556
|
+
...appPath ? { appPath } : {},
|
|
22557
|
+
...qualification ? { implementationRevision: qualification.implementationRevision } : {}
|
|
22558
|
+
}
|
|
22559
|
+
}
|
|
22560
|
+
);
|
|
22561
|
+
const bootstrap = cpaLiveVoiceHookBootstrap(process.env, void 0, overlayDir);
|
|
20990
22562
|
const status = createRendererStatusReporter(
|
|
20991
22563
|
(document) => dependencies.publishStatus?.({
|
|
20992
22564
|
...document,
|
|
@@ -21009,18 +22581,30 @@ async function runDesktopController(options, signal, dependencies = defaultDepen
|
|
|
21009
22581
|
status.installing();
|
|
21010
22582
|
startupTrace("reading Renderer bundle");
|
|
21011
22583
|
const rendererRead = dependencies.readRenderer(options.rendererPath);
|
|
21012
|
-
const overlayPath = bootstrap ?
|
|
21013
|
-
const
|
|
22584
|
+
const overlayPath = bootstrap && cpaLiveVoiceOverlayHookAllowed(process.env, overlayDir) ? path6.join(overlayDir, "cpa-live-voice-hook.js") : void 0;
|
|
22585
|
+
const overlayBootstrapPath = overlayPath && overlayVoiceBootstrapPreferred(process.env, overlayDir) ? path6.join(overlayDir, "overlay-voice-bootstrap.js") : void 0;
|
|
22586
|
+
const [rendererSource, overlayBundle, overlayBootstrapBundle] = overlayPath ? await Promise.all([
|
|
22587
|
+
rendererRead,
|
|
22588
|
+
dependencies.readRenderer(overlayPath),
|
|
22589
|
+
overlayBootstrapPath ? dependencies.readRenderer(overlayBootstrapPath).catch(() => "") : Promise.resolve("")
|
|
22590
|
+
]) : [await rendererRead, void 0, ""];
|
|
21014
22591
|
if (rendererSource.trim().length === 0) throw new Error("production Renderer Bundle is empty");
|
|
21015
22592
|
const overlayHookSource = bootstrap && overlayBundle && overlayBundle.trim().length > 0 ? `${RENDERER_CSP_BOOTSTRAP}
|
|
21016
22593
|
${bootstrap}${overlayBundle}` : void 0;
|
|
22594
|
+
const overlayVoiceBootstrapSource = overlayHookSource && overlayBootstrapBundle.trim().length > 0 ? `${RENDERER_CSP_BOOTSTRAP}
|
|
22595
|
+
${bootstrap}${overlayBootstrapBundle}` : void 0;
|
|
21017
22596
|
startupTrace("installing Renderer Session");
|
|
22597
|
+
if (!voiceHost && options.hostDataDirectory && !skipReason) {
|
|
22598
|
+
voiceHost = await connectControllerVoiceHost(options.hostDataDirectory);
|
|
22599
|
+
}
|
|
21018
22600
|
const installed = await installProductionSession(
|
|
21019
22601
|
{
|
|
21020
22602
|
rendererCdpEndpoint: options.rendererCdpEndpoint,
|
|
21021
22603
|
rendererSource: `${RENDERER_CSP_BOOTSTRAP}
|
|
21022
22604
|
${bootstrap}${rendererSource}`,
|
|
21023
22605
|
...overlayHookSource ? { overlayHookSource } : {},
|
|
22606
|
+
...overlayVoiceBootstrapSource ? { overlayVoiceBootstrapSource } : {},
|
|
22607
|
+
...voiceHost ? { voiceHost } : {},
|
|
21024
22608
|
// External Agents are discovered from each target Host after installation.
|
|
21025
22609
|
timeoutMs: PRODUCTION_INSTALL_TIMEOUT_MS,
|
|
21026
22610
|
signal
|
|
@@ -21045,11 +22629,13 @@ ${bootstrap}${rendererSource}`,
|
|
|
21045
22629
|
session = void 0;
|
|
21046
22630
|
};
|
|
21047
22631
|
const ensureSession = async () => {
|
|
22632
|
+
if (skipReason) throw new Error(skipReason);
|
|
21048
22633
|
if (!session) session = await createSession();
|
|
21049
22634
|
else await session.ensureInstalled();
|
|
21050
22635
|
return session;
|
|
21051
22636
|
};
|
|
21052
22637
|
const recoverSession = async () => {
|
|
22638
|
+
if (skipReason) throw new Error(skipReason);
|
|
21053
22639
|
try {
|
|
21054
22640
|
const current = await ensureSession();
|
|
21055
22641
|
recordRecoverySuccess();
|
|
@@ -21090,8 +22676,12 @@ ${bootstrap}${rendererSource}`,
|
|
|
21090
22676
|
state: "compatible",
|
|
21091
22677
|
issues: []
|
|
21092
22678
|
});
|
|
22679
|
+
if (skipReason) {
|
|
22680
|
+
nextRecoveryAt = Number.POSITIVE_INFINITY;
|
|
22681
|
+
status.failed(new Error(skipReason));
|
|
22682
|
+
}
|
|
21093
22683
|
await useSession(async () => {
|
|
21094
|
-
if (session) return;
|
|
22684
|
+
if (session || skipReason) return;
|
|
21095
22685
|
try {
|
|
21096
22686
|
session = await createSession();
|
|
21097
22687
|
recordRecoverySuccess();
|
|
@@ -21116,6 +22706,7 @@ ${bootstrap}${rendererSource}`,
|
|
|
21116
22706
|
await attachmentServer?.close();
|
|
21117
22707
|
await operation;
|
|
21118
22708
|
resetSession();
|
|
22709
|
+
voiceHost?.close();
|
|
21119
22710
|
}
|
|
21120
22711
|
}
|
|
21121
22712
|
|