@codexhost/cli-win32-x64 0.30.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +62 -5
- package/app/console-web.js +236 -30
- package/app/desktop-controller.mjs +68 -9
- package/app/host-runtime.mjs +3653 -1136
- package/app/plugins/antigravity/plugin.mjs +64 -27
- package/app/plugins/claude-code/plugin.mjs +73 -13
- package/app/plugins/codebuddy/plugin.mjs +261 -93
- package/app/plugins/codex-usage/plugin.mjs +62 -5
- package/app/plugins/copilot/plugin.mjs +62 -5
- package/app/plugins/cursor-cli/plugin.mjs +62 -5
- package/app/plugins/deepseek-harness/plugin.mjs +62 -5
- package/app/plugins/devin/plugin.mjs +62 -5
- package/app/plugins/grok/plugin.mjs +62 -5
- package/app/plugins/hermes/plugin.mjs +62 -5
- package/app/plugins/kimi-code/plugin.mjs +62 -5
- package/app/plugins/kiro-cli/plugin.mjs +62 -5
- package/app/plugins/omp/plugin.mjs +62 -5
- package/app/plugins/opencode/plugin.mjs +62 -5
- package/app/plugins/pi/plugin.mjs +62 -5
- package/app/plugins/qoder/plugin.mjs +62 -5
- package/app/plugins/qoder-cn/plugin.mjs +62 -5
- package/app/plugins/qwen-code/plugin.mjs +62 -5
- package/app/plugins/workbuddy/plugin.mjs +261 -93
- package/app/plugins/zcode/plugin.mjs +62 -5
- package/app/renderer-extension.js +950 -538
- package/app/web/assets/{abnfDiagram-XWFEHMT6-BdinLox4.js → abnfDiagram-XWFEHMT6-CnJyN70L.js} +1 -1
- package/app/web/assets/{architectureDiagram-CSQXQB3N-DgPBbtvP.js → architectureDiagram-CSQXQB3N-DH0ITYVE.js} +1 -1
- package/app/web/assets/{blockDiagram-BEDRHYPZ-B4ENdwtZ.js → blockDiagram-BEDRHYPZ-WL3ZKoKg.js} +1 -1
- package/app/web/assets/{c4Diagram-M2UUVUY5-DA6Owfyu.js → c4Diagram-M2UUVUY5-XwSPKj5H.js} +1 -1
- package/app/web/assets/{chunk-2Q5K7J3B-Dvh3qOmo.js → chunk-2Q5K7J3B-CKEzexjg.js} +1 -1
- package/app/web/assets/{chunk-3GCGMST5-VIkqueym.js → chunk-3GCGMST5-BdEgLpab.js} +1 -1
- package/app/web/assets/{chunk-5VM5RSS4-DTYof_OI.js → chunk-5VM5RSS4-DyxL5-Ts.js} +1 -1
- package/app/web/assets/{chunk-7U7NFRK5-Dp7s2dg0.js → chunk-7U7NFRK5-FXLb4tYa.js} +1 -1
- package/app/web/assets/{chunk-CNRTWJTD-TKBKxZLU.js → chunk-CNRTWJTD-DcdC1OYr.js} +1 -1
- package/app/web/assets/{chunk-D5HYT7QG-BRZDovSS.js → chunk-D5HYT7QG-BOz9vBX9.js} +1 -1
- package/app/web/assets/{chunk-EBZ3SEQC-C9USZ3tT.js → chunk-EBZ3SEQC-Dmc_Z53x.js} +2 -2
- package/app/web/assets/{chunk-JWPE2WC7-BrdvVNVo.js → chunk-JWPE2WC7-CrFwSwYi.js} +1 -1
- package/app/web/assets/{chunk-KTR4FSNJ-C7qwjGba.js → chunk-KTR4FSNJ-BY3AzFaI.js} +1 -1
- package/app/web/assets/{chunk-XXDRQBXY-DlSrRuwN.js → chunk-XXDRQBXY-CHgNy82n.js} +1 -1
- package/app/web/assets/{classDiagram-v2-KXABOMEV-BFvB4kwX.js → classDiagram-v2-KXABOMEV-ClM3-y5Z.js} +1 -1
- package/app/web/assets/{cose-bilkent-JH36ORCC-UyCAqNvj.js → cose-bilkent-JH36ORCC-I7nd8GgO.js} +1 -1
- package/app/web/assets/{cynefin-EF2NZ3EQ-CwawUbjJ.js → cynefin-EF2NZ3EQ-DzsXmyBH.js} +1 -1
- package/app/web/assets/{cynefinDiagram-NJNITYFG-BaWEIQJ0.js → cynefinDiagram-NJNITYFG-DLHq6igy.js} +1 -1
- package/app/web/assets/{dagre-KIHZ2IZ3-B7ENIjLG.js → dagre-KIHZ2IZ3-BK991Mno.js} +1 -1
- package/app/web/assets/{diagram-7YQZDPLS-CxRMU8xq.js → diagram-7YQZDPLS-C4qiWdQU.js} +1 -1
- package/app/web/assets/{diagram-QBROCOUO-qo7sxm4K.js → diagram-QBROCOUO-C_ZyBohC.js} +1 -1
- package/app/web/assets/{diagram-RJJCUUZO-CQiGMCMe.js → diagram-RJJCUUZO-C5Aezm94.js} +1 -1
- package/app/web/assets/{diagram-WERXNKYE-D0Jps1As.js → diagram-WERXNKYE-Ckc_umlF.js} +1 -1
- package/app/web/assets/{diagram-YHHI257C-p4AB8cqK.js → diagram-YHHI257C-BHjReoZZ.js} +1 -1
- package/app/web/assets/{diagram-YR4HJLHV-Bh6JKT04.js → diagram-YR4HJLHV-DVTGi_y9.js} +1 -1
- package/app/web/assets/{ebnfDiagram-N527522P-DRac0k4W.js → ebnfDiagram-N527522P-getuz1AR.js} +1 -1
- package/app/web/assets/{elk-O5DQBFGD-CWTz5SZP.js → elk-O5DQBFGD-C7mhTIuK.js} +1 -1
- package/app/web/assets/{erDiagram-K3K3BIDK-DE3w4BEY.js → erDiagram-K3K3BIDK-sV-HZvUV.js} +1 -1
- package/app/web/assets/{flowDiagram-Z6JWZHQI-NYs8bi5t.js → flowDiagram-Z6JWZHQI-D0L4wXUs.js} +1 -1
- package/app/web/assets/{ganttDiagram-3PRQTZWP-Bspp9btW.js → ganttDiagram-3PRQTZWP-BNt9Bjjo.js} +1 -1
- package/app/web/assets/{gitGraphDiagram-VXDFKS5L-ByGW1uvv.js → gitGraphDiagram-VXDFKS5L-BABZzhHw.js} +1 -1
- package/app/web/assets/{grid-E2QIVN74-CegebiIw.js → grid-E2QIVN74-DLe2FQ_d.js} +1 -1
- package/app/web/assets/{index-DFPOGLS4.js → index-BLmkBEoq.js} +100 -100
- package/app/web/assets/index-Dwdnvinl.css +1 -0
- package/app/web/assets/{infoDiagram-EZ3ZOAHP-CexmsdZx.js → infoDiagram-EZ3ZOAHP-BKDuUqcr.js} +1 -1
- package/app/web/assets/{ishikawaDiagram-S3EKX5GW-BbWqKhg6.js → ishikawaDiagram-S3EKX5GW-C75EGghg.js} +1 -1
- package/app/web/assets/{journeyDiagram-POQNLL5X-27YlCe-1.js → journeyDiagram-POQNLL5X-q7Obruqa.js} +1 -1
- package/app/web/assets/{kanban-definition-BH5XI6FM-BAhOdeck.js → kanban-definition-BH5XI6FM-CzAqhFED.js} +1 -1
- package/app/web/assets/{mermaid.core-sGgCbv5y.js → mermaid.core-Bysx44LR.js} +4 -4
- package/app/web/assets/{mindmap-definition-WVAN44T4-CsMIX0Lj.js → mindmap-definition-WVAN44T4-Ds5rXTrF.js} +1 -1
- package/app/web/assets/{pegDiagram-D4NLKWP3-Cs3LXqn_.js → pegDiagram-D4NLKWP3-hmdERwtT.js} +1 -1
- package/app/web/assets/{pieDiagram-36ENHN4W-DdQsQX9I.js → pieDiagram-36ENHN4W-DfTnyG8D.js} +1 -1
- package/app/web/assets/{quadrantDiagram-ZQUDMS73-D1jOKqx_.js → quadrantDiagram-ZQUDMS73-CreQWjZQ.js} +1 -1
- package/app/web/assets/{railroadDiagram-JIZHGYPL-XulrgX5n.js → railroadDiagram-JIZHGYPL-Bhc_eO9G.js} +1 -1
- package/app/web/assets/{render-VIF2ZAQL-CSsGw-0I.js → render-VIF2ZAQL-BS1Zgk8K.js} +2 -2
- package/app/web/assets/{requirementDiagram-AXW2TVFA-CT66GXLN.js → requirementDiagram-AXW2TVFA-Dlp7d6QT.js} +1 -1
- package/app/web/assets/{sankeyDiagram-FBCJTAIF-CNRKebNY.js → sankeyDiagram-FBCJTAIF-DGBchL30.js} +1 -1
- package/app/web/assets/{sequenceDiagram-3LA2ROMG-DVl5y64e.js → sequenceDiagram-3LA2ROMG-DauFg5_R.js} +1 -1
- package/app/web/assets/{sizeCapture-2Q2CQKSF-Kg0XxSga.js → sizeCapture-2Q2CQKSF-DR-zy7an.js} +1 -1
- package/app/web/assets/{stateDiagram-v2-ATKHQDJO-DYQnfMsS.js → stateDiagram-v2-ATKHQDJO-BSRBSGUi.js} +1 -1
- package/app/web/assets/{swimlanes-YQL5WMAO-Chqt7pxD.js → swimlanes-YQL5WMAO-BwzOr5Dv.js} +1 -1
- package/app/web/assets/swimlanesDiagram-UCCPES4V-CNV63-us.js +8 -0
- package/app/web/assets/{timeline-definition-7Z437IG3-aHFxjIT6.js → timeline-definition-7Z437IG3-BoZ-mNKc.js} +1 -1
- package/app/web/assets/{usecaseDiagram-RDK6N6HP-DsC5tFe4.js → usecaseDiagram-RDK6N6HP-DikhgH2m.js} +1 -1
- package/app/web/assets/{vennDiagram-SHRQU5PJ-C65oZxFn.js → vennDiagram-SHRQU5PJ-DY_oIxwl.js} +1 -1
- package/app/web/assets/{wardleyDiagram-F3OXNVQS-HTkq7DT0.js → wardleyDiagram-F3OXNVQS-DrRIiB_M.js} +1 -1
- package/app/web/assets/{xychartDiagram-GDYJKCDI-p1LpQ9MH.js → xychartDiagram-GDYJKCDI-CzSPgHV7.js} +1 -1
- package/app/web/codexhost-settings.js +126 -58
- package/app/web/index.html +2 -2
- package/app/web/plugins/deepseek-ai__dsh-api-gateway/client.js +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 +8 -8
- package/app/web/plugins/deepseek-ai__dsh-api-workspace-controller/client.js +3 -3
- package/app/web/plugins/deepseek-ai__dsh-client-locale/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-attachment/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +75 -75
- package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +12 -12
- package/app/web/plugins/deepseek-ai__dsh-client-ui-commands/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +18 -18
- package/app/web/plugins/deepseek-ai__dsh-client-ui-plan/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-settings-general/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.js +7 -7
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-right/client.js +2 -2
- package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +18 -18
- package/app/web/plugins/deepseek-ai__dsh-client-ui-user-questions/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +64 -66
- package/app/web/sw.js +230 -16
- package/app/web-modules/node_modules/@deepseek-ai/dsh-client-modules/index.js +7 -7
- package/app/web-modules/server.mjs +1482 -325
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-screenshot.exe +0 -0
- package/libexec/codexhost-shell.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-BbmB5VLj.css +0 -1
- package/app/web/assets/swimlanesDiagram-UCCPES4V-BfREktNP.js +0 -8
|
@@ -1707,7 +1707,7 @@ var require_extension = __commonJS({
|
|
|
1707
1707
|
var require_websocket = __commonJS({
|
|
1708
1708
|
"node_modules/ws/lib/websocket.js"(exports, module) {
|
|
1709
1709
|
"use strict";
|
|
1710
|
-
var EventEmitter3 = __require("events"), https = __require("https"), http = __require("http"), net2 = __require("net"), tls3 = __require("tls"), { randomBytes: randomBytes12, createHash: createHash18 } = __require("crypto"), { Duplex, Readable:
|
|
1710
|
+
var EventEmitter3 = __require("events"), https = __require("https"), http = __require("http"), net2 = __require("net"), tls3 = __require("tls"), { randomBytes: randomBytes12, createHash: createHash18 } = __require("crypto"), { Duplex, Readable: Readable6 } = __require("stream"), { URL: URL2 } = __require("url"), PerMessageDeflate3 = require_permessage_deflate(), Receiver3 = require_receiver(), Sender3 = require_sender(), { isBlob } = require_validation(), {
|
|
1711
1711
|
BINARY_TYPES,
|
|
1712
1712
|
CLOSE_TIMEOUT,
|
|
1713
1713
|
EMPTY_BUFFER,
|
|
@@ -2093,8 +2093,8 @@ var require_websocket = __commonJS({
|
|
|
2093
2093
|
emitErrorAndClose(websocket, err5);
|
|
2094
2094
|
return;
|
|
2095
2095
|
}
|
|
2096
|
-
let
|
|
2097
|
-
if (opts.createConnection = opts.createConnection || (isSecure ?
|
|
2096
|
+
let defaultPort3 = isSecure ? 443 : 80, key = randomBytes12(16).toString("base64"), request3 = isSecure ? https.request : http.request, protocolSet = /* @__PURE__ */ new Set(), perMessageDeflate;
|
|
2097
|
+
if (opts.createConnection = opts.createConnection || (isSecure ? tlsConnect2 : netConnect), opts.defaultPort = opts.defaultPort || defaultPort3, opts.port = parsedUrl.port || defaultPort3, opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname, opts.headers = {
|
|
2098
2098
|
...opts.headers,
|
|
2099
2099
|
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
2100
2100
|
"Sec-WebSocket-Key": key,
|
|
@@ -2222,7 +2222,7 @@ var require_websocket = __commonJS({
|
|
|
2222
2222
|
function netConnect(options) {
|
|
2223
2223
|
return options.path = options.socketPath, net2.connect(options);
|
|
2224
2224
|
}
|
|
2225
|
-
function
|
|
2225
|
+
function tlsConnect2(options) {
|
|
2226
2226
|
return options.path = void 0, !options.servername && options.servername !== "" && (options.servername = net2.isIP(options.host) ? "" : options.host), tls3.connect(options);
|
|
2227
2227
|
}
|
|
2228
2228
|
function abortHandshake(websocket, stream, message2) {
|
|
@@ -5442,7 +5442,7 @@ var require_extension2 = __commonJS({
|
|
|
5442
5442
|
var require_websocket2 = __commonJS({
|
|
5443
5443
|
"packages/web-server/node_modules/ws/lib/websocket.js"(exports, module) {
|
|
5444
5444
|
"use strict";
|
|
5445
|
-
var EventEmitter3 = __require("events"), https = __require("https"), http = __require("http"), net2 = __require("net"), tls3 = __require("tls"), { randomBytes: randomBytes12, createHash: createHash18 } = __require("crypto"), { Duplex, Readable:
|
|
5445
|
+
var EventEmitter3 = __require("events"), https = __require("https"), http = __require("http"), net2 = __require("net"), tls3 = __require("tls"), { randomBytes: randomBytes12, createHash: createHash18 } = __require("crypto"), { Duplex, Readable: Readable6 } = __require("stream"), { URL: URL2 } = __require("url"), PerMessageDeflate3 = require_permessage_deflate2(), Receiver3 = require_receiver2(), Sender3 = require_sender2(), { isBlob } = require_validation2(), {
|
|
5446
5446
|
BINARY_TYPES,
|
|
5447
5447
|
CLOSE_TIMEOUT,
|
|
5448
5448
|
EMPTY_BUFFER,
|
|
@@ -5828,8 +5828,8 @@ var require_websocket2 = __commonJS({
|
|
|
5828
5828
|
emitErrorAndClose(websocket, err5);
|
|
5829
5829
|
return;
|
|
5830
5830
|
}
|
|
5831
|
-
let
|
|
5832
|
-
if (opts.createConnection = opts.createConnection || (isSecure ?
|
|
5831
|
+
let defaultPort3 = isSecure ? 443 : 80, key = randomBytes12(16).toString("base64"), request3 = isSecure ? https.request : http.request, protocolSet = /* @__PURE__ */ new Set(), perMessageDeflate;
|
|
5832
|
+
if (opts.createConnection = opts.createConnection || (isSecure ? tlsConnect2 : netConnect), opts.defaultPort = opts.defaultPort || defaultPort3, opts.port = parsedUrl.port || defaultPort3, opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname, opts.headers = {
|
|
5833
5833
|
...opts.headers,
|
|
5834
5834
|
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
5835
5835
|
"Sec-WebSocket-Key": key,
|
|
@@ -5957,7 +5957,7 @@ var require_websocket2 = __commonJS({
|
|
|
5957
5957
|
function netConnect(options) {
|
|
5958
5958
|
return options.path = options.socketPath, net2.connect(options);
|
|
5959
5959
|
}
|
|
5960
|
-
function
|
|
5960
|
+
function tlsConnect2(options) {
|
|
5961
5961
|
return options.path = void 0, !options.servername && options.servername !== "" && (options.servername = net2.isIP(options.host) ? "" : options.host), tls3.connect(options);
|
|
5962
5962
|
}
|
|
5963
5963
|
function abortHandshake(websocket, stream, message2) {
|
|
@@ -73161,7 +73161,39 @@ var NATIVE_CODEX_GOAL_METHOD = "codexhost/thread/goal", nativeCodexGoalInvocatio
|
|
|
73161
73161
|
|
|
73162
73162
|
// packages/shared-contracts/dist/client-channel.js
|
|
73163
73163
|
var CLIENT_CHANNEL_VERSION = 1, CLIENT_REQUEST_LIMIT_BYTES = 128 * 1024 * 1024;
|
|
73164
|
-
var
|
|
73164
|
+
var THREAD_SECTION_CAPABILITY = "threadSectionsV1", threadSectionName = external_exports.string().trim().min(1), threadSectionId = external_exports.string().min(1), threadSectionAppearance = external_exports.object({
|
|
73165
|
+
icon: external_exports.string().nullable(),
|
|
73166
|
+
color: external_exports.string().nullable()
|
|
73167
|
+
}), clientThreadSectionAppearanceSchema = threadSectionAppearance.nullable(), CLIENT_THREAD_SECTION_MUTATIONS = {
|
|
73168
|
+
create: {
|
|
73169
|
+
method: "codexhost/thread/sections/create",
|
|
73170
|
+
params: external_exports.object({ name: threadSectionName }).strict()
|
|
73171
|
+
},
|
|
73172
|
+
update: {
|
|
73173
|
+
method: "codexhost/thread/sections/update",
|
|
73174
|
+
params: external_exports.object({
|
|
73175
|
+
sectionId: threadSectionId,
|
|
73176
|
+
name: threadSectionName,
|
|
73177
|
+
appearance: threadSectionAppearance.strict().nullable().optional()
|
|
73178
|
+
}).strict()
|
|
73179
|
+
},
|
|
73180
|
+
delete: {
|
|
73181
|
+
method: "codexhost/thread/sections/delete",
|
|
73182
|
+
params: external_exports.object({ sectionId: threadSectionId }).strict()
|
|
73183
|
+
}
|
|
73184
|
+
}, clientThreadSectionMutationResultSchema = external_exports.discriminatedUnion("status", [
|
|
73185
|
+
external_exports.object({ status: external_exports.literal("unknown") }),
|
|
73186
|
+
external_exports.object({
|
|
73187
|
+
status: external_exports.literal("confirmed"),
|
|
73188
|
+
sectionId: threadSectionId,
|
|
73189
|
+
section: external_exports.object({
|
|
73190
|
+
id: threadSectionId,
|
|
73191
|
+
name: external_exports.string().min(1),
|
|
73192
|
+
appearance: clientThreadSectionAppearanceSchema
|
|
73193
|
+
}).nullable(),
|
|
73194
|
+
syncPending: external_exports.boolean()
|
|
73195
|
+
})
|
|
73196
|
+
]), CLIENT_CHANNEL_METHODS = [
|
|
73165
73197
|
"codexhost/skills/list",
|
|
73166
73198
|
"codexhost/voice/status",
|
|
73167
73199
|
"codexhost/voice/transcribe",
|
|
@@ -73171,6 +73203,8 @@ var CLIENT_CHANNEL_METHODS = [
|
|
|
73171
73203
|
"codexhost/harness/preferences/get",
|
|
73172
73204
|
"codexhost/harness/preferences/patch",
|
|
73173
73205
|
"experimentalFeature/list",
|
|
73206
|
+
"collaborationMode/list",
|
|
73207
|
+
"codexhost/thread/collaboration-mode/select",
|
|
73174
73208
|
"thread/list",
|
|
73175
73209
|
"thread/metadata/update",
|
|
73176
73210
|
"codexhost/thread/catalog/read",
|
|
@@ -73207,6 +73241,9 @@ var CLIENT_CHANNEL_METHODS = [
|
|
|
73207
73241
|
"codexhost/thread/pins/list",
|
|
73208
73242
|
"codexhost/thread/sections/list",
|
|
73209
73243
|
"codexhost/thread/sections/move",
|
|
73244
|
+
CLIENT_THREAD_SECTION_MUTATIONS.create.method,
|
|
73245
|
+
CLIENT_THREAD_SECTION_MUTATIONS.update.method,
|
|
73246
|
+
CLIENT_THREAD_SECTION_MUTATIONS.delete.method,
|
|
73210
73247
|
"codexhost/thread/pins/set",
|
|
73211
73248
|
"codexhost/harness/plugins/list",
|
|
73212
73249
|
"codexhost/harness/inspect",
|
|
@@ -73256,15 +73293,20 @@ var CLIENT_CHANNEL_METHODS = [
|
|
|
73256
73293
|
PRODUCT_TELEMETRY_SIGNAL_METHOD,
|
|
73257
73294
|
"codexhost/sessions/loaded/list"
|
|
73258
73295
|
], clientThreadSectionsSchema = external_exports.object({
|
|
73296
|
+
[THREAD_SECTION_CAPABILITY]: external_exports.literal(!0).optional(),
|
|
73297
|
+
complete: external_exports.literal(!1).optional(),
|
|
73259
73298
|
sections: external_exports.array(external_exports.object({
|
|
73260
73299
|
id: external_exports.string().min(1),
|
|
73261
73300
|
name: external_exports.string().min(1),
|
|
73301
|
+
appearance: clientThreadSectionAppearanceSchema.optional(),
|
|
73262
73302
|
threads: external_exports.array(jsonObjectSchema)
|
|
73263
|
-
})
|
|
73264
|
-
})
|
|
73303
|
+
}))
|
|
73304
|
+
}), clientThreadSectionMoveSchema = external_exports.object({
|
|
73265
73305
|
threadId: external_exports.string().min(1).max(1024),
|
|
73266
|
-
sectionId: external_exports.string().min(1).max(1024).nullable()
|
|
73267
|
-
|
|
73306
|
+
sectionId: external_exports.string().min(1).max(1024).nullable(),
|
|
73307
|
+
beforeThreadId: external_exports.string().min(1).max(1024).nullable().optional(),
|
|
73308
|
+
expectedSourceSectionId: external_exports.string().min(1).max(1024).optional()
|
|
73309
|
+
}).refine((move) => move.expectedSourceSectionId === void 0 || move.sectionId === null), clientThreadPinsSchema = external_exports.object({ threadIds: external_exports.array(external_exports.string().min(1)) }).strict(), clientThreadPinParamsSchema = external_exports.object({ threadId: external_exports.string().min(1).max(1024), pinned: external_exports.boolean() }).strict(), clientThreadTreeReadParamsSchema = external_exports.object({}).strict(), clientThreadTreeSchema = external_exports.object({
|
|
73268
73310
|
parents: external_exports.record(external_exports.string().min(1), external_exports.string().min(1))
|
|
73269
73311
|
}).strict(), clientProjectlessWorkspaceSchema = external_exports.object({
|
|
73270
73312
|
prompt: external_exports.string().max(16384).optional()
|
|
@@ -73302,6 +73344,7 @@ var CLIENT_CHANNEL_METHODS = [
|
|
|
73302
73344
|
harnessId: external_exports.string().min(1)
|
|
73303
73345
|
}),
|
|
73304
73346
|
external_exports.object({ type: external_exports.literal("display-settings-changed"), cursor: clientChannelCursorSchema }),
|
|
73347
|
+
external_exports.object({ type: external_exports.literal("sections-changed"), cursor: clientChannelCursorSchema }),
|
|
73305
73348
|
external_exports.object({
|
|
73306
73349
|
type: external_exports.literal("preferences-changed"),
|
|
73307
73350
|
cursor: clientChannelCursorSchema,
|
|
@@ -73432,6 +73475,7 @@ var CLIENT_CHANNEL_METHODS = [
|
|
|
73432
73475
|
nextCursor: external_exports.string().nullable()
|
|
73433
73476
|
}),
|
|
73434
73477
|
configuration: external_exports.object({
|
|
73478
|
+
codexCollaborationMode: external_exports.enum(["plan", "default"]).optional(),
|
|
73435
73479
|
/** Native Codex model names are not external Harness transport refs. */
|
|
73436
73480
|
native: external_exports.object({
|
|
73437
73481
|
model: external_exports.string().min(1).max(1024).optional(),
|
|
@@ -73456,7 +73500,8 @@ var CLIENT_CHANNEL_METHODS = [
|
|
|
73456
73500
|
startedAt: external_exports.number(),
|
|
73457
73501
|
epoch: external_exports.string().uuid(),
|
|
73458
73502
|
capabilities: external_exports.object({
|
|
73459
|
-
peerDelegation: external_exports.literal(1).optional()
|
|
73503
|
+
peerDelegation: external_exports.literal(1).optional(),
|
|
73504
|
+
threadReferenceContext: external_exports.literal(1).optional()
|
|
73460
73505
|
}).optional()
|
|
73461
73506
|
}), clientChannelResponseSchema = external_exports.object({
|
|
73462
73507
|
epoch: external_exports.string().uuid(),
|
|
@@ -74103,7 +74148,11 @@ var harnessPreferenceScopeSchema = external_exports.string().regex(/^external$/u
|
|
|
74103
74148
|
model: harnessModelRefSchema.optional(),
|
|
74104
74149
|
thinkingOptionId: harnessThinkingOptionIdSchema.optional(),
|
|
74105
74150
|
permissionModeId: harnessPermissionModeIdSchema.optional()
|
|
74106
|
-
}).refine((value) => !!(value.model || value.thinkingOptionId || value.permissionModeId), "A default configuration must contain a preference"),
|
|
74151
|
+
}).refine((value) => !!(value.model || value.thinkingOptionId || value.permissionModeId), "A default configuration must contain a preference"), projectHarnessSelectionSchema = external_exports.discriminatedUnion("mode", [
|
|
74152
|
+
external_exports.strictObject({ mode: external_exports.literal("global") }),
|
|
74153
|
+
external_exports.strictObject({ mode: external_exports.literal("last") }),
|
|
74154
|
+
external_exports.strictObject({ mode: external_exports.literal("manual"), harnessId: harnessIdSchema })
|
|
74155
|
+
]), newThreadDefaultsSchema = external_exports.strictObject({
|
|
74107
74156
|
lastHarness: harnessIdSchema.optional(),
|
|
74108
74157
|
byHarness: external_exports.record(preferenceHarnessKey, harnessDefaultConfigurationSchema)
|
|
74109
74158
|
}), harnessDelegationDefaultSchema = external_exports.strictObject({
|
|
@@ -75287,7 +75336,7 @@ var HostClientChannel = class {
|
|
|
75287
75336
|
throw new Error("Host unavailable");
|
|
75288
75337
|
this.descriptor = descriptor;
|
|
75289
75338
|
let url2 = new URL(`http://127.0.0.1:${descriptor.port}/v1/events`);
|
|
75290
|
-
this.cursor && (url2.searchParams.set("epoch", this.cursor.epoch), url2.searchParams.set("after", String(this.cursor.sequence)));
|
|
75339
|
+
url2.searchParams.set(THREAD_SECTION_CAPABILITY, "1"), this.cursor && (url2.searchParams.set("epoch", this.cursor.epoch), url2.searchParams.set("after", String(this.cursor.sequence)));
|
|
75291
75340
|
let response = await fetch(url2, {
|
|
75292
75341
|
redirect: "error",
|
|
75293
75342
|
headers: { authorization: `Bearer ${descriptor.token}` },
|
|
@@ -75354,12 +75403,15 @@ var HostClientChannel = class {
|
|
|
75354
75403
|
throw Object.assign(new Error("Obsolete Host reply; resynchronize after reconnecting"), {
|
|
75355
75404
|
code: -32094
|
|
75356
75405
|
});
|
|
75357
|
-
if (value
|
|
75358
|
-
|
|
75359
|
-
|
|
75406
|
+
if (Object.hasOwn(value, "error") && !Object.hasOwn(value, "result")) {
|
|
75407
|
+
let error62 = jsonRpcErrorSchema.safeParse(value.error);
|
|
75408
|
+
if (error62.success)
|
|
75409
|
+
throw Object.assign(new Error(error62.data.message), { code: error62.data.code });
|
|
75410
|
+
}
|
|
75411
|
+
if (!response.ok || Object.hasOwn(value, "error") || !Object.hasOwn(value, "result"))
|
|
75412
|
+
throw Object.assign(new Error("Invalid Host reply; operation outcome may be unknown"), {
|
|
75413
|
+
code: -32093
|
|
75360
75414
|
});
|
|
75361
|
-
if (!Object.hasOwn(value, "result"))
|
|
75362
|
-
throw new Error("Invalid Host reply; operation outcome may be unknown");
|
|
75363
75415
|
return value.result;
|
|
75364
75416
|
}
|
|
75365
75417
|
request(method2, params, timeoutMs) {
|
|
@@ -77072,9 +77124,6 @@ var PeerChHostClient = class {
|
|
|
77072
77124
|
};
|
|
77073
77125
|
|
|
77074
77126
|
// packages/web-server/src/peer-host-client.ts
|
|
77075
|
-
import { request as httpRequest } from "node:http";
|
|
77076
|
-
import { request as httpsRequest } from "node:https";
|
|
77077
|
-
import { isIP as isIP2 } from "node:net";
|
|
77078
77127
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
77079
77128
|
|
|
77080
77129
|
// packages/web-server/src/peer-host-store.ts
|
|
@@ -77213,6 +77262,594 @@ var PeerHostStore = class {
|
|
|
77213
77262
|
}
|
|
77214
77263
|
};
|
|
77215
77264
|
|
|
77265
|
+
// packages/web-server/src/peer-outbound-proxy.ts
|
|
77266
|
+
import { lookup as osDnsLookup } from "node:dns/promises";
|
|
77267
|
+
import {
|
|
77268
|
+
Agent as HttpAgent,
|
|
77269
|
+
request as httpRequest
|
|
77270
|
+
} from "node:http";
|
|
77271
|
+
import {
|
|
77272
|
+
Agent as HttpsAgent,
|
|
77273
|
+
request as httpsRequest
|
|
77274
|
+
} from "node:https";
|
|
77275
|
+
import { BlockList, isIP as isIP2, isIPv4 as isIPv42 } from "node:net";
|
|
77276
|
+
import { Readable } from "node:stream";
|
|
77277
|
+
import { checkServerIdentity, connect as tlsConnect } from "node:tls";
|
|
77278
|
+
var BUILTIN_FETCH = globalThis.fetch, CONNECT_TIMEOUT_MS = 15e3, MAX_CACHED_PROXY_AGENTS = 16, CONNECT_SIGNAL = /* @__PURE__ */ Symbol("peerConnectSignal"), CONNECT_TIMEOUT = /* @__PURE__ */ Symbol("peerConnectTimeoutMs"), directHttpAgent = new HttpAgent({ keepAlive: !0, proxyEnv: {} }), directHttpsAgent = new HttpsAgent({ keepAlive: !0, proxyEnv: {} }), directNoKeepAliveHttpAgent = new HttpAgent({ keepAlive: !1, proxyEnv: {} }), directNoKeepAliveHttpsAgent = new HttpsAgent({ keepAlive: !1, proxyEnv: {} }), proxyHttpsAgents = /* @__PURE__ */ new Map(), DNS_RESOLUTION_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
77279
|
+
"ENOTFOUND",
|
|
77280
|
+
"EAI_AGAIN",
|
|
77281
|
+
"EAI_NONAME",
|
|
77282
|
+
"EAI_NODATA",
|
|
77283
|
+
"EAI_FAIL",
|
|
77284
|
+
"ESERVFAIL",
|
|
77285
|
+
"ETIMEOUT"
|
|
77286
|
+
]);
|
|
77287
|
+
function isDnsResolutionError(err5) {
|
|
77288
|
+
if (!(err5 instanceof Error) || err5 instanceof PeerHostPolicyError) return !1;
|
|
77289
|
+
if (err5.message === "Peer host address could not be resolved") return !0;
|
|
77290
|
+
let code = "code" in err5 && typeof err5.code == "string" ? err5.code : void 0;
|
|
77291
|
+
return code !== void 0 && DNS_RESOLUTION_ERROR_CODES.has(code);
|
|
77292
|
+
}
|
|
77293
|
+
var PeerProxyConfigError = class extends Error {
|
|
77294
|
+
constructor(message2) {
|
|
77295
|
+
super(message2), this.name = "PeerProxyConfigError";
|
|
77296
|
+
}
|
|
77297
|
+
};
|
|
77298
|
+
function toAbortError(signal) {
|
|
77299
|
+
let reason = signal?.reason;
|
|
77300
|
+
return reason instanceof Error ? reason : new DOMException("The operation was aborted.", "AbortError");
|
|
77301
|
+
}
|
|
77302
|
+
function stripBrackets(hostname5) {
|
|
77303
|
+
let bare = hostname5.startsWith("[") && hostname5.endsWith("]") ? hostname5.slice(1, -1) : hostname5.replace(/\.$/u, ""), zoneIndex = bare.indexOf("%");
|
|
77304
|
+
return (zoneIndex >= 0 ? bare.slice(0, zoneIndex) : bare).toLowerCase();
|
|
77305
|
+
}
|
|
77306
|
+
function normalizeIpv4Candidate(bare) {
|
|
77307
|
+
if (isIPv42(bare)) return bare;
|
|
77308
|
+
if (!bare.startsWith("::ffff:")) return;
|
|
77309
|
+
let suffix = bare.slice(7);
|
|
77310
|
+
if (isIPv42(suffix)) return suffix;
|
|
77311
|
+
let hex3 = /^([0-9a-f]{1,4}):([0-9a-f]{1,4})$/iu.exec(suffix);
|
|
77312
|
+
if (!hex3?.[1] || !hex3[2]) return;
|
|
77313
|
+
let hi = Number.parseInt(hex3[1], 16), lo = Number.parseInt(hex3[2], 16);
|
|
77314
|
+
return `${hi >> 8 & 255}.${hi & 255}.${lo >> 8 & 255}.${lo & 255}`;
|
|
77315
|
+
}
|
|
77316
|
+
function isLoopbackHost2(hostname5) {
|
|
77317
|
+
let bare = stripBrackets(hostname5);
|
|
77318
|
+
if (bare === "localhost" || bare.endsWith(".localhost") || bare === "::1" || bare === "0:0:0:0:0:0:0:1")
|
|
77319
|
+
return !0;
|
|
77320
|
+
let ipv43 = normalizeIpv4Candidate(bare);
|
|
77321
|
+
return ipv43 !== void 0 && ipv43.startsWith("127.");
|
|
77322
|
+
}
|
|
77323
|
+
function isAlwaysDirectPeerHost(hostname5) {
|
|
77324
|
+
let bare = stripBrackets(hostname5);
|
|
77325
|
+
if (isLoopbackHost2(bare) || bare.endsWith(".local"))
|
|
77326
|
+
return !0;
|
|
77327
|
+
let ipv43 = normalizeIpv4Candidate(bare);
|
|
77328
|
+
return !!(ipv43 !== void 0 && /^100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7])\./u.test(ipv43) || bare.startsWith("fd7a:115c:a1e0:") || /^fe[89ab][0-9a-f]:/iu.test(bare));
|
|
77329
|
+
}
|
|
77330
|
+
function readEnvValue(env, lowerKey) {
|
|
77331
|
+
let upperKey = lowerKey.toUpperCase(), lower = env[lowerKey];
|
|
77332
|
+
if (lower !== void 0) return lower;
|
|
77333
|
+
let upper = env[upperKey];
|
|
77334
|
+
if (upper !== void 0) return upper;
|
|
77335
|
+
for (let [key, value] of Object.entries(env))
|
|
77336
|
+
if (value !== void 0 && key.toLowerCase() === lowerKey) return value;
|
|
77337
|
+
}
|
|
77338
|
+
function readNonEmptyEnvValue(env, lowerKey) {
|
|
77339
|
+
let upperKey = lowerKey.toUpperCase(), lower = env[lowerKey]?.trim();
|
|
77340
|
+
if (lower) return lower;
|
|
77341
|
+
let upper = env[upperKey]?.trim();
|
|
77342
|
+
if (upper) return upper;
|
|
77343
|
+
for (let [key, value] of Object.entries(env))
|
|
77344
|
+
if (key.toLowerCase() === lowerKey) {
|
|
77345
|
+
let trimmed = value?.trim();
|
|
77346
|
+
if (trimmed) return trimmed;
|
|
77347
|
+
}
|
|
77348
|
+
}
|
|
77349
|
+
function parseNoProxyBlockList(noProxyValue) {
|
|
77350
|
+
let list2;
|
|
77351
|
+
for (let rawToken of noProxyValue.split(/[,\s]+/u)) {
|
|
77352
|
+
let token = rawToken.trim(), slash = token.indexOf("/");
|
|
77353
|
+
if (slash <= 0) continue;
|
|
77354
|
+
let prefixText = token.slice(slash + 1);
|
|
77355
|
+
if (!/^\d+$/u.test(prefixText)) continue;
|
|
77356
|
+
let address = stripBrackets(token.slice(0, slash)), prefix = Number.parseInt(prefixText, 10), family = isIP2(address);
|
|
77357
|
+
family === 4 && prefix >= 0 && prefix <= 32 ? (list2 ??= new BlockList(), list2.addSubnet(address, prefix, "ipv4")) : family === 6 && prefix >= 0 && prefix <= 128 && (list2 ??= new BlockList(), list2.addSubnet(address, prefix, "ipv6"));
|
|
77358
|
+
}
|
|
77359
|
+
return list2;
|
|
77360
|
+
}
|
|
77361
|
+
function matchesNoProxyCidr(hostname5, blockList) {
|
|
77362
|
+
if (!blockList) return !1;
|
|
77363
|
+
let bare = stripBrackets(hostname5), ipv43 = normalizeIpv4Candidate(bare);
|
|
77364
|
+
return ipv43 !== void 0 ? blockList.check(ipv43, "ipv4") : isIP2(bare) === 6 ? blockList.check(bare, "ipv6") : !1;
|
|
77365
|
+
}
|
|
77366
|
+
function parseNoProxyHostToken(token) {
|
|
77367
|
+
if (!token || token.includes("/")) return;
|
|
77368
|
+
if (token.startsWith("[")) {
|
|
77369
|
+
let bracketed = /^\[([^\]]+)\](?::(\d+))?$/u.exec(token);
|
|
77370
|
+
return bracketed?.[1] ? {
|
|
77371
|
+
host: stripBrackets(bracketed[1]),
|
|
77372
|
+
...bracketed[2] ? { port: Number.parseInt(bracketed[2], 10) } : {}
|
|
77373
|
+
} : void 0;
|
|
77374
|
+
}
|
|
77375
|
+
if (token.indexOf(":") !== token.lastIndexOf(":"))
|
|
77376
|
+
return { host: stripBrackets(token) };
|
|
77377
|
+
let hostPort = /^([^:]+):(\d+)$/u.exec(token);
|
|
77378
|
+
return hostPort?.[1] && hostPort[2] ? {
|
|
77379
|
+
host: stripBrackets(hostPort[1]),
|
|
77380
|
+
port: Number.parseInt(hostPort[2], 10)
|
|
77381
|
+
} : { host: stripBrackets(token) };
|
|
77382
|
+
}
|
|
77383
|
+
function matchesNoProxyHostname(target2, noProxyRaw) {
|
|
77384
|
+
if (!noProxyRaw) return !1;
|
|
77385
|
+
let bareTarget = stripBrackets(target2.hostname), targetIpv4 = normalizeIpv4Candidate(bareTarget), targetPort = Number(target2.port || defaultPort(target2.protocol));
|
|
77386
|
+
for (let rawToken of noProxyRaw.split(/[,\s]+/u)) {
|
|
77387
|
+
let token = rawToken.trim().toLowerCase();
|
|
77388
|
+
if (!token) continue;
|
|
77389
|
+
if (token === "*") return !0;
|
|
77390
|
+
let parsed = parseNoProxyHostToken(token);
|
|
77391
|
+
if (!(!parsed || !parsed.host) && !(parsed.port !== void 0 && parsed.port !== targetPort)) {
|
|
77392
|
+
if (parsed.host.startsWith("*") || parsed.host.startsWith(".")) {
|
|
77393
|
+
let suffix = parsed.host.startsWith("*") ? parsed.host.slice(1) : parsed.host;
|
|
77394
|
+
if (!suffix || bareTarget.endsWith(suffix)) return !0;
|
|
77395
|
+
continue;
|
|
77396
|
+
}
|
|
77397
|
+
if (bareTarget === parsed.host || targetIpv4 !== void 0 && normalizeIpv4Candidate(parsed.host) === targetIpv4)
|
|
77398
|
+
return !0;
|
|
77399
|
+
}
|
|
77400
|
+
}
|
|
77401
|
+
return !1;
|
|
77402
|
+
}
|
|
77403
|
+
function resolveRawEnvProxy(target2, env, noProxyRaw) {
|
|
77404
|
+
if (target2.protocol !== "http:" && target2.protocol !== "https:" || matchesNoProxyHostname(target2, noProxyRaw)) return "";
|
|
77405
|
+
let protoKey = target2.protocol === "https:" ? "https_proxy" : "http_proxy";
|
|
77406
|
+
return readNonEmptyEnvValue(env, protoKey) ?? readNonEmptyEnvValue(env, "all_proxy") ?? "";
|
|
77407
|
+
}
|
|
77408
|
+
var SCHEMELESS_PROXY_HOST_PORT = /^(?:[^/@\s]+@)?(?:\[[^\]]+\]|[^:/@\s]+):(\d{1,5})\/?$/u;
|
|
77409
|
+
function parseConfiguredProxyUrl(rawProxy) {
|
|
77410
|
+
let candidate = rawProxy;
|
|
77411
|
+
if (!rawProxy.includes("://")) {
|
|
77412
|
+
let match = SCHEMELESS_PROXY_HOST_PORT.exec(rawProxy), portNum = match?.[1] ? Number.parseInt(match[1], 10) : 0;
|
|
77413
|
+
if (!match || portNum < 1 || portNum > 65535)
|
|
77414
|
+
throw new PeerProxyConfigError("Invalid outbound proxy URL configured in environment");
|
|
77415
|
+
candidate = `http://${rawProxy}`;
|
|
77416
|
+
}
|
|
77417
|
+
let parsed = URL.parse(candidate);
|
|
77418
|
+
if (!parsed || !parsed.hostname || parsed.port === "0")
|
|
77419
|
+
throw new PeerProxyConfigError("Invalid outbound proxy URL configured in environment");
|
|
77420
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
77421
|
+
throw new PeerProxyConfigError(`Unsupported outbound proxy protocol: ${parsed.protocol}`);
|
|
77422
|
+
try {
|
|
77423
|
+
parsed.username && decodeURIComponent(parsed.username), parsed.password && decodeURIComponent(parsed.password);
|
|
77424
|
+
} catch {
|
|
77425
|
+
throw new PeerProxyConfigError("Invalid percent-encoding in outbound proxy credentials");
|
|
77426
|
+
}
|
|
77427
|
+
return parsed;
|
|
77428
|
+
}
|
|
77429
|
+
function resolvePeerProxyUrl(target2, options = {}) {
|
|
77430
|
+
let env = options.env ?? process.env;
|
|
77431
|
+
if (readEnvValue(env, "node_use_env_proxy")?.trim() === "0" || isAlwaysDirectPeerHost(target2.hostname)) return;
|
|
77432
|
+
let noProxyRaw = readNonEmptyEnvValue(env, "no_proxy") ?? "", cidrBlockList = noProxyRaw ? parseNoProxyBlockList(noProxyRaw) : void 0;
|
|
77433
|
+
if (matchesNoProxyCidr(target2.hostname, cidrBlockList)) return;
|
|
77434
|
+
if (options.resolvedAddresses) {
|
|
77435
|
+
for (let entry of options.resolvedAddresses)
|
|
77436
|
+
if (isAlwaysDirectPeerHost(entry.address) || matchesNoProxyCidr(entry.address, cidrBlockList))
|
|
77437
|
+
return;
|
|
77438
|
+
}
|
|
77439
|
+
let rawProxy = resolveRawEnvProxy(target2, env, noProxyRaw);
|
|
77440
|
+
if (rawProxy)
|
|
77441
|
+
return parseConfiguredProxyUrl(rawProxy);
|
|
77442
|
+
}
|
|
77443
|
+
function createPinnedLookup(addresses) {
|
|
77444
|
+
return (_hostname, lookupOptions, callback) => {
|
|
77445
|
+
let opts = typeof lookupOptions == "object" && lookupOptions !== null ? lookupOptions : {};
|
|
77446
|
+
if (opts.all) {
|
|
77447
|
+
callback(
|
|
77448
|
+
null,
|
|
77449
|
+
addresses.map((entry) => ({ address: entry.address, family: entry.family }))
|
|
77450
|
+
);
|
|
77451
|
+
return;
|
|
77452
|
+
}
|
|
77453
|
+
let family = typeof lookupOptions == "number" ? lookupOptions : opts.family, match = family === 4 || family === 6 ? addresses.find((entry) => entry.family === family) : addresses[0];
|
|
77454
|
+
if (!match) {
|
|
77455
|
+
callback(
|
|
77456
|
+
Object.assign(new Error("No verified address matches requested IP family"), {
|
|
77457
|
+
code: "ENOTFOUND"
|
|
77458
|
+
}),
|
|
77459
|
+
"",
|
|
77460
|
+
4
|
|
77461
|
+
);
|
|
77462
|
+
return;
|
|
77463
|
+
}
|
|
77464
|
+
callback(null, match.address, match.family);
|
|
77465
|
+
};
|
|
77466
|
+
}
|
|
77467
|
+
function proxyAuthorizationHeader(proxy) {
|
|
77468
|
+
if (!proxy.username && !proxy.password) return;
|
|
77469
|
+
let credentials;
|
|
77470
|
+
try {
|
|
77471
|
+
credentials = `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`;
|
|
77472
|
+
} catch {
|
|
77473
|
+
throw new PeerProxyConfigError("Invalid percent-encoding in outbound proxy credentials");
|
|
77474
|
+
}
|
|
77475
|
+
return `Basic ${Buffer.from(credentials, "utf8").toString("base64")}`;
|
|
77476
|
+
}
|
|
77477
|
+
function httpsProxyTlsOptions(bareProxy) {
|
|
77478
|
+
return {
|
|
77479
|
+
// Explicit empty string prevents Node from deriving outer TLS SNI from the inner target Host header.
|
|
77480
|
+
servername: isIP2(bareProxy) === 0 ? bareProxy : "",
|
|
77481
|
+
checkServerIdentity: (_host, cert) => checkServerIdentity(bareProxy, cert)
|
|
77482
|
+
};
|
|
77483
|
+
}
|
|
77484
|
+
function defaultPort(protocol) {
|
|
77485
|
+
return protocol === "https:" ? 443 : 80;
|
|
77486
|
+
}
|
|
77487
|
+
var ProxyHttpsAgent = class extends HttpsAgent {
|
|
77488
|
+
constructor(proxy, keepAlive = !0) {
|
|
77489
|
+
super({ keepAlive, autoSelectFamilyAttemptTimeout: 2e3, proxyEnv: {} });
|
|
77490
|
+
this.proxy = proxy;
|
|
77491
|
+
}
|
|
77492
|
+
proxy;
|
|
77493
|
+
createConnection(options, callback) {
|
|
77494
|
+
let connectSignal = options[CONNECT_SIGNAL];
|
|
77495
|
+
if (connectSignal?.aborted) {
|
|
77496
|
+
callback?.(toAbortError(connectSignal), void 0);
|
|
77497
|
+
return;
|
|
77498
|
+
}
|
|
77499
|
+
let connectTimeoutMs = options[CONNECT_TIMEOUT] ?? CONNECT_TIMEOUT_MS, targetHost = String(options.hostname || options.host || "localhost"), targetPort = Number(options.port || 443), bareTarget = stripBrackets(targetHost), authority = bareTarget.includes(":") ? `[${bareTarget}]:${targetPort}` : `${bareTarget}:${targetPort}`, proxyAuth;
|
|
77500
|
+
try {
|
|
77501
|
+
proxyAuth = proxyAuthorizationHeader(this.proxy);
|
|
77502
|
+
} catch (err5) {
|
|
77503
|
+
callback?.(
|
|
77504
|
+
err5 instanceof Error ? err5 : new Error(String(err5)),
|
|
77505
|
+
void 0
|
|
77506
|
+
);
|
|
77507
|
+
return;
|
|
77508
|
+
}
|
|
77509
|
+
let bareProxy = stripBrackets(this.proxy.hostname), connectReq = (this.proxy.protocol === "https:" ? httpsRequest : httpRequest)({
|
|
77510
|
+
protocol: this.proxy.protocol,
|
|
77511
|
+
hostname: bareProxy,
|
|
77512
|
+
port: Number(this.proxy.port || defaultPort(this.proxy.protocol)),
|
|
77513
|
+
method: "CONNECT",
|
|
77514
|
+
path: authority,
|
|
77515
|
+
agent: this.proxy.protocol === "https:" ? directNoKeepAliveHttpsAgent : directNoKeepAliveHttpAgent,
|
|
77516
|
+
headers: {
|
|
77517
|
+
host: authority,
|
|
77518
|
+
...proxyAuth ? { "proxy-authorization": proxyAuth } : {}
|
|
77519
|
+
},
|
|
77520
|
+
...this.proxy.protocol === "https:" ? httpsProxyTlsOptions(bareProxy) : {},
|
|
77521
|
+
timeout: connectTimeoutMs
|
|
77522
|
+
}), settled2 = !1, activeTlsSocket, connectTimer, handshakeTimer, clearConnectTimer = () => {
|
|
77523
|
+
connectTimer !== void 0 && (clearTimeout(connectTimer), connectTimer = void 0);
|
|
77524
|
+
}, cleanup = () => {
|
|
77525
|
+
clearConnectTimer(), handshakeTimer !== void 0 && (clearTimeout(handshakeTimer), handshakeTimer = void 0), connectSignal?.removeEventListener("abort", onAbort);
|
|
77526
|
+
}, fail = (err5) => {
|
|
77527
|
+
settled2 || (settled2 = !0, cleanup(), activeTlsSocket?.destroy(), connectReq.destroy(), callback?.(err5, void 0));
|
|
77528
|
+
}, onAbort = () => {
|
|
77529
|
+
fail(toAbortError(connectSignal));
|
|
77530
|
+
};
|
|
77531
|
+
connectTimer = setTimeout(() => fail(new Error("Proxy CONNECT timed out")), connectTimeoutMs), connectSignal?.addEventListener("abort", onAbort, { once: !0 }), connectReq.once("close", clearConnectTimer), connectReq.once("timeout", () => fail(new Error("Proxy CONNECT timed out"))), connectReq.once("error", fail), connectReq.once("connect", (res, socket, head) => {
|
|
77532
|
+
if (clearConnectTimer(), settled2) {
|
|
77533
|
+
socket.destroy();
|
|
77534
|
+
return;
|
|
77535
|
+
}
|
|
77536
|
+
if (res.statusCode !== 200) {
|
|
77537
|
+
socket.destroy(), fail(new Error(`Proxy CONNECT returned HTTP ${res.statusCode ?? 0}`));
|
|
77538
|
+
return;
|
|
77539
|
+
}
|
|
77540
|
+
connectReq.setTimeout(0), socket.setTimeout(0), head.length > 0 && socket.unshift(head);
|
|
77541
|
+
let isIpTarget = isIP2(bareTarget) !== 0, customCheck = options.checkServerIdentity, tlsSocket = tlsConnect({
|
|
77542
|
+
socket,
|
|
77543
|
+
...isIpTarget ? {
|
|
77544
|
+
host: bareTarget,
|
|
77545
|
+
checkServerIdentity: (_host, cert) => customCheck ? customCheck(bareTarget, cert) : checkServerIdentity(bareTarget, cert)
|
|
77546
|
+
} : {
|
|
77547
|
+
servername: options.servername || bareTarget,
|
|
77548
|
+
...customCheck ? {
|
|
77549
|
+
checkServerIdentity: (host, cert) => customCheck(host, cert)
|
|
77550
|
+
} : {}
|
|
77551
|
+
},
|
|
77552
|
+
...options.rejectUnauthorized === void 0 ? {} : { rejectUnauthorized: options.rejectUnauthorized }
|
|
77553
|
+
});
|
|
77554
|
+
activeTlsSocket = tlsSocket, handshakeTimer = setTimeout(
|
|
77555
|
+
() => tlsSocket.destroy(new Error("Proxy TLS handshake timed out")),
|
|
77556
|
+
connectTimeoutMs
|
|
77557
|
+
), tlsSocket.once("error", (err5) => {
|
|
77558
|
+
fail(err5);
|
|
77559
|
+
}), tlsSocket.once("secureConnect", () => {
|
|
77560
|
+
if (settled2 || connectSignal?.aborted) {
|
|
77561
|
+
tlsSocket.destroy(), settled2 || fail(toAbortError(connectSignal));
|
|
77562
|
+
return;
|
|
77563
|
+
}
|
|
77564
|
+
settled2 = !0, cleanup(), tlsSocket.setTimeout(0), callback?.(null, tlsSocket);
|
|
77565
|
+
});
|
|
77566
|
+
}), connectReq.end();
|
|
77567
|
+
}
|
|
77568
|
+
};
|
|
77569
|
+
function getProxyHttpsAgent(proxy) {
|
|
77570
|
+
let key = proxy.href, agent = proxyHttpsAgents.get(key);
|
|
77571
|
+
if (!agent) {
|
|
77572
|
+
if (proxyHttpsAgents.size >= MAX_CACHED_PROXY_AGENTS) {
|
|
77573
|
+
let oldest = proxyHttpsAgents.keys().next().value;
|
|
77574
|
+
oldest !== void 0 && (proxyHttpsAgents.get(oldest)?.destroy(), proxyHttpsAgents.delete(oldest));
|
|
77575
|
+
}
|
|
77576
|
+
agent = new ProxyHttpsAgent(proxy, !0), proxyHttpsAgents.set(key, agent);
|
|
77577
|
+
}
|
|
77578
|
+
return agent;
|
|
77579
|
+
}
|
|
77580
|
+
function openPeerHttpRequest(target2, options) {
|
|
77581
|
+
let bareTarget = stripBrackets(target2.hostname), targetPort = Number(target2.port || defaultPort(target2.protocol)), proxy = options.proxy;
|
|
77582
|
+
if (proxy && target2.protocol === "http:") {
|
|
77583
|
+
let proxyAuth = proxyAuthorizationHeader(proxy), bareProxy = stripBrackets(proxy.hostname);
|
|
77584
|
+
return (proxy.protocol === "https:" ? httpsRequest : httpRequest)({
|
|
77585
|
+
protocol: proxy.protocol,
|
|
77586
|
+
hostname: bareProxy,
|
|
77587
|
+
port: Number(proxy.port || defaultPort(proxy.protocol)),
|
|
77588
|
+
method: options.method,
|
|
77589
|
+
path: target2.href,
|
|
77590
|
+
headers: {
|
|
77591
|
+
...options.headers,
|
|
77592
|
+
host: target2.host,
|
|
77593
|
+
...proxyAuth ? { "proxy-authorization": proxyAuth } : {}
|
|
77594
|
+
},
|
|
77595
|
+
agent: options.keepAlive === !1 ? proxy.protocol === "https:" ? directNoKeepAliveHttpsAgent : directNoKeepAliveHttpAgent : proxy.protocol === "https:" ? directHttpsAgent : directHttpAgent,
|
|
77596
|
+
...proxy.protocol === "https:" ? httpsProxyTlsOptions(bareProxy) : {},
|
|
77597
|
+
...options.signal ? { signal: options.signal } : {}
|
|
77598
|
+
});
|
|
77599
|
+
}
|
|
77600
|
+
if (proxy && target2.protocol === "https:") {
|
|
77601
|
+
let ephemeralAgent = options.keepAlive === !1 ? new ProxyHttpsAgent(proxy, !1) : void 0, reqOptions = {
|
|
77602
|
+
protocol: "https:",
|
|
77603
|
+
hostname: bareTarget,
|
|
77604
|
+
port: targetPort,
|
|
77605
|
+
method: options.method,
|
|
77606
|
+
path: `${target2.pathname}${target2.search}`,
|
|
77607
|
+
headers: {
|
|
77608
|
+
...options.headers,
|
|
77609
|
+
host: target2.host
|
|
77610
|
+
},
|
|
77611
|
+
agent: ephemeralAgent ?? getProxyHttpsAgent(proxy),
|
|
77612
|
+
...isIP2(bareTarget) === 0 ? { servername: bareTarget } : {},
|
|
77613
|
+
...options.signal ? { signal: options.signal, [CONNECT_SIGNAL]: options.signal } : {},
|
|
77614
|
+
...options.connectTimeoutMs !== void 0 ? { [CONNECT_TIMEOUT]: options.connectTimeoutMs } : {}
|
|
77615
|
+
}, req = httpsRequest(reqOptions);
|
|
77616
|
+
return ephemeralAgent && (req.once("error", () => ephemeralAgent.destroy()), req.once("response", (res) => {
|
|
77617
|
+
res.once("close", () => ephemeralAgent.destroy());
|
|
77618
|
+
})), req;
|
|
77619
|
+
}
|
|
77620
|
+
let useNoKeepAlive = !!options.lookup || options.keepAlive === !1, directOptions = {
|
|
77621
|
+
protocol: target2.protocol,
|
|
77622
|
+
hostname: bareTarget,
|
|
77623
|
+
port: targetPort,
|
|
77624
|
+
method: options.method,
|
|
77625
|
+
path: `${target2.pathname}${target2.search}`,
|
|
77626
|
+
headers: {
|
|
77627
|
+
...options.headers,
|
|
77628
|
+
host: target2.host
|
|
77629
|
+
},
|
|
77630
|
+
agent: useNoKeepAlive ? target2.protocol === "https:" ? directNoKeepAliveHttpsAgent : directNoKeepAliveHttpAgent : target2.protocol === "https:" ? directHttpsAgent : directHttpAgent,
|
|
77631
|
+
...options.lookup ? { lookup: options.lookup } : {},
|
|
77632
|
+
...options.signal ? { signal: options.signal } : {}
|
|
77633
|
+
};
|
|
77634
|
+
return target2.protocol === "https:" ? httpsRequest({
|
|
77635
|
+
...directOptions,
|
|
77636
|
+
...isIP2(bareTarget) === 0 ? { servername: bareTarget } : {}
|
|
77637
|
+
}) : httpRequest(directOptions);
|
|
77638
|
+
}
|
|
77639
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
77640
|
+
async function prepareFetchBody(body) {
|
|
77641
|
+
if (body == null) return { kind: "empty" };
|
|
77642
|
+
if (typeof body == "string") return { kind: "buffer", buffer: Buffer.from(body, "utf8") };
|
|
77643
|
+
if (body instanceof URLSearchParams)
|
|
77644
|
+
return {
|
|
77645
|
+
kind: "buffer",
|
|
77646
|
+
buffer: Buffer.from(body.toString(), "utf8"),
|
|
77647
|
+
contentType: "application/x-www-form-urlencoded;charset=UTF-8"
|
|
77648
|
+
};
|
|
77649
|
+
if (body instanceof FormData) {
|
|
77650
|
+
let encoded = new Response(body), contentType = encoded.headers.get("content-type") ?? void 0;
|
|
77651
|
+
return { kind: "buffer", buffer: Buffer.from(await encoded.arrayBuffer()), ...contentType ? { contentType } : {} };
|
|
77652
|
+
}
|
|
77653
|
+
return body instanceof Uint8Array ? { kind: "buffer", buffer: Buffer.from(body.buffer, body.byteOffset, body.byteLength) } : body instanceof ArrayBuffer ? { kind: "buffer", buffer: Buffer.from(body) } : ArrayBuffer.isView(body) ? { kind: "buffer", buffer: Buffer.from(body.buffer, body.byteOffset, body.byteLength) } : body instanceof Blob ? {
|
|
77654
|
+
kind: "buffer",
|
|
77655
|
+
buffer: Buffer.from(await body.arrayBuffer()),
|
|
77656
|
+
...body.type ? { contentType: body.type } : {}
|
|
77657
|
+
} : { kind: "stream", stream: body };
|
|
77658
|
+
}
|
|
77659
|
+
function toFetchResponse(res, method2, signal) {
|
|
77660
|
+
let status = res.statusCode;
|
|
77661
|
+
if (typeof status != "number" || !Number.isInteger(status) || status < 200 || status > 599)
|
|
77662
|
+
throw new RangeError(
|
|
77663
|
+
`The status provided (${String(status)}) is outside the range [200, 599].`
|
|
77664
|
+
);
|
|
77665
|
+
let headers2 = new Headers();
|
|
77666
|
+
for (let [key, value] of Object.entries(res.headers))
|
|
77667
|
+
if (value !== void 0)
|
|
77668
|
+
if (Array.isArray(value))
|
|
77669
|
+
for (let item of value) headers2.append(key, item);
|
|
77670
|
+
else
|
|
77671
|
+
headers2.set(key, value);
|
|
77672
|
+
if (method2.toUpperCase() === "HEAD" || status === 204 || status === 205 || status === 304) {
|
|
77673
|
+
let response2 = new Response(null, { status, statusText: res.statusMessage ?? "", headers: headers2 });
|
|
77674
|
+
return res.resume(), response2;
|
|
77675
|
+
}
|
|
77676
|
+
let response = new Response(Readable.toWeb(res), {
|
|
77677
|
+
status,
|
|
77678
|
+
statusText: res.statusMessage ?? "",
|
|
77679
|
+
headers: headers2
|
|
77680
|
+
});
|
|
77681
|
+
if (signal) {
|
|
77682
|
+
let onAbort = () => res.destroy(signal.reason instanceof Error ? signal.reason : void 0);
|
|
77683
|
+
signal.aborted ? onAbort() : (signal.addEventListener("abort", onAbort, { once: !0 }), res.once("close", () => signal.removeEventListener("abort", onAbort)));
|
|
77684
|
+
}
|
|
77685
|
+
return response;
|
|
77686
|
+
}
|
|
77687
|
+
function waitForDrain(req, signal) {
|
|
77688
|
+
return req.destroyed || req.writableEnded || signal?.aborted ? Promise.resolve(!1) : new Promise((resolve26) => {
|
|
77689
|
+
let cleanup = () => {
|
|
77690
|
+
req.off("drain", onDrain), req.off("close", onStop), req.off("error", onStop), signal?.removeEventListener("abort", onStop);
|
|
77691
|
+
}, onDrain = () => {
|
|
77692
|
+
cleanup(), resolve26(!0);
|
|
77693
|
+
}, onStop = () => {
|
|
77694
|
+
cleanup(), resolve26(!1);
|
|
77695
|
+
};
|
|
77696
|
+
req.once("drain", onDrain), req.once("close", onStop), req.once("error", onStop), signal?.addEventListener("abort", onStop, { once: !0 });
|
|
77697
|
+
});
|
|
77698
|
+
}
|
|
77699
|
+
async function resolveHostAddresses(bareHost, dnsLookup2, signal) {
|
|
77700
|
+
if (signal?.aborted)
|
|
77701
|
+
throw toAbortError(signal);
|
|
77702
|
+
let lookupPromise = (dnsLookup2 ? dnsLookup2(bareHost) : osDnsLookup(bareHost, { all: !0, verbatim: !0 }).then(
|
|
77703
|
+
(entries) => entries.map((entry) => ({
|
|
77704
|
+
address: entry.address,
|
|
77705
|
+
family: entry.family === 6 ? 6 : 4
|
|
77706
|
+
}))
|
|
77707
|
+
)).then((entries) => {
|
|
77708
|
+
let validated = [];
|
|
77709
|
+
for (let entry of entries) {
|
|
77710
|
+
let family = typeof entry?.address == "string" ? isIP2(entry.address) : 0;
|
|
77711
|
+
if (family !== 4 && family !== 6)
|
|
77712
|
+
throw new PeerHostPolicyError("Peer host address is not allowed");
|
|
77713
|
+
validated.push({ address: entry.address, family });
|
|
77714
|
+
}
|
|
77715
|
+
if (validated.length === 0)
|
|
77716
|
+
throw new Error("Peer host address could not be resolved");
|
|
77717
|
+
return validated;
|
|
77718
|
+
});
|
|
77719
|
+
return signal ? await new Promise((resolve26, reject) => {
|
|
77720
|
+
let onAbort = () => reject(toAbortError(signal));
|
|
77721
|
+
signal.addEventListener("abort", onAbort, { once: !0 }), lookupPromise.then(
|
|
77722
|
+
(resolved) => {
|
|
77723
|
+
signal.removeEventListener("abort", onAbort), resolve26(resolved);
|
|
77724
|
+
},
|
|
77725
|
+
(err5) => {
|
|
77726
|
+
signal.removeEventListener("abort", onAbort), signal.aborted ? reject(toAbortError(signal)) : reject(err5);
|
|
77727
|
+
}
|
|
77728
|
+
);
|
|
77729
|
+
}) : await lookupPromise;
|
|
77730
|
+
}
|
|
77731
|
+
async function resolvePeerOutboundRoute(target2, options = {}) {
|
|
77732
|
+
let effectiveAllowLoopback = options.allowLoopback ?? isLoopbackHost2(target2.hostname);
|
|
77733
|
+
assertAllowedPeerHost(target2.hostname, { allowLoopback: effectiveAllowLoopback });
|
|
77734
|
+
let candidateProxy = resolvePeerProxyUrl(target2), bareTarget = stripBrackets(target2.hostname);
|
|
77735
|
+
if (isIP2(bareTarget) !== 0)
|
|
77736
|
+
return candidateProxy ? { proxy: candidateProxy } : {};
|
|
77737
|
+
let resolvedAddresses = options.resolvedAddresses;
|
|
77738
|
+
if (resolvedAddresses === void 0)
|
|
77739
|
+
try {
|
|
77740
|
+
resolvedAddresses = await resolveHostAddresses(bareTarget, options.dnsLookup, options.signal);
|
|
77741
|
+
} catch (err5) {
|
|
77742
|
+
if (candidateProxy && isDnsResolutionError(err5))
|
|
77743
|
+
return { proxy: candidateProxy };
|
|
77744
|
+
throw err5;
|
|
77745
|
+
}
|
|
77746
|
+
for (let entry of resolvedAddresses)
|
|
77747
|
+
assertAllowedPeerHost(entry.address, { allowLoopback: effectiveAllowLoopback });
|
|
77748
|
+
let finalProxy = candidateProxy ? resolvePeerProxyUrl(target2, { resolvedAddresses }) : void 0;
|
|
77749
|
+
return finalProxy ? { proxy: finalProxy } : resolvedAddresses.length > 0 ? { lookup: createPinnedLookup(resolvedAddresses) } : {};
|
|
77750
|
+
}
|
|
77751
|
+
function cancelUploadBodyIfStream(body, reason) {
|
|
77752
|
+
body instanceof ReadableStream && body.cancel(reason).catch(() => {
|
|
77753
|
+
});
|
|
77754
|
+
}
|
|
77755
|
+
async function nodeFetchViaAdapter(target2, init, route) {
|
|
77756
|
+
let signal = init?.signal ?? void 0;
|
|
77757
|
+
if (signal?.aborted)
|
|
77758
|
+
throw await cancelUploadBodyIfStream(init?.body, signal.reason), toAbortError(signal);
|
|
77759
|
+
let method2 = init?.method ?? "GET", headersObj = {};
|
|
77760
|
+
init?.headers && new Headers(init.headers).forEach((value, key) => {
|
|
77761
|
+
headersObj[key] = value;
|
|
77762
|
+
});
|
|
77763
|
+
let preparedBody = await prepareFetchBody(init?.body);
|
|
77764
|
+
if (preparedBody.kind === "buffer" && (preparedBody.contentType && headersObj["content-type"] === void 0 && (headersObj["content-type"] = preparedBody.contentType), headersObj["content-length"] === void 0 && headersObj["transfer-encoding"] === void 0 && (headersObj["content-length"] = String(preparedBody.buffer.byteLength))), signal?.aborted)
|
|
77765
|
+
throw preparedBody.kind === "stream" && await preparedBody.stream.cancel(signal.reason).catch(() => {
|
|
77766
|
+
}), toAbortError(signal);
|
|
77767
|
+
return new Promise((resolve26, reject) => {
|
|
77768
|
+
let settled2 = !1, fail = (err5) => {
|
|
77769
|
+
settled2 || (settled2 = !0, reject(err5 instanceof Error ? err5 : new Error(String(err5))));
|
|
77770
|
+
}, req = openPeerHttpRequest(target2, {
|
|
77771
|
+
method: method2,
|
|
77772
|
+
headers: headersObj,
|
|
77773
|
+
...route.proxy ? { proxy: route.proxy } : {},
|
|
77774
|
+
...!route.proxy && route.lookup ? { lookup: route.lookup } : {},
|
|
77775
|
+
...signal ? { signal } : {}
|
|
77776
|
+
});
|
|
77777
|
+
if (req.once("error", fail), req.once("upgrade", (_res, socket) => {
|
|
77778
|
+
socket.destroy(), req.destroy(), fail(new Error("Unexpected HTTP protocol upgrade response"));
|
|
77779
|
+
}), req.once("response", (res) => {
|
|
77780
|
+
let status = res.statusCode ?? 0;
|
|
77781
|
+
if (init?.redirect === "error" && REDIRECT_STATUSES.has(status)) {
|
|
77782
|
+
res.resume(), req.destroy(), fail(new TypeError("redirect mode is set to error"));
|
|
77783
|
+
return;
|
|
77784
|
+
}
|
|
77785
|
+
if (settled2) {
|
|
77786
|
+
res.destroy();
|
|
77787
|
+
return;
|
|
77788
|
+
}
|
|
77789
|
+
let response;
|
|
77790
|
+
try {
|
|
77791
|
+
response = toFetchResponse(res, method2, signal);
|
|
77792
|
+
} catch (err5) {
|
|
77793
|
+
res.destroy(), req.destroy(), fail(err5);
|
|
77794
|
+
return;
|
|
77795
|
+
}
|
|
77796
|
+
settled2 = !0, resolve26(response);
|
|
77797
|
+
}), preparedBody.kind === "empty")
|
|
77798
|
+
req.end();
|
|
77799
|
+
else if (preparedBody.kind === "buffer")
|
|
77800
|
+
req.end(preparedBody.buffer);
|
|
77801
|
+
else {
|
|
77802
|
+
let reader = preparedBody.stream.getReader(), streamDone = !1, cancelUpload = (reason) => {
|
|
77803
|
+
streamDone || (streamDone = !0, reader.cancel(reason).catch(() => {
|
|
77804
|
+
}));
|
|
77805
|
+
}, onReqClose = () => cancelUpload(signal?.aborted ? signal.reason : void 0), onReqError = (err5) => cancelUpload(err5), onSignalAbort = () => cancelUpload(signal?.reason);
|
|
77806
|
+
req.once("close", onReqClose), req.once("error", onReqError), signal?.addEventListener("abort", onSignalAbort, { once: !0 }), (async () => {
|
|
77807
|
+
try {
|
|
77808
|
+
for (; !(req.destroyed || signal?.aborted); ) {
|
|
77809
|
+
let { done, value } = await reader.read();
|
|
77810
|
+
if (done) {
|
|
77811
|
+
streamDone = !0;
|
|
77812
|
+
break;
|
|
77813
|
+
}
|
|
77814
|
+
if (req.destroyed || signal?.aborted || !req.write(value) && !await waitForDrain(req, signal))
|
|
77815
|
+
break;
|
|
77816
|
+
}
|
|
77817
|
+
!req.destroyed && !req.writableEnded && !signal?.aborted && req.end();
|
|
77818
|
+
} catch (err5) {
|
|
77819
|
+
streamDone = !0, req.destroy(), fail(err5);
|
|
77820
|
+
} finally {
|
|
77821
|
+
streamDone || (streamDone = !0, await reader.cancel(signal?.aborted ? signal.reason : void 0).catch(() => {
|
|
77822
|
+
})), reader.releaseLock(), req.off("close", onReqClose), req.off("error", onReqError), signal?.removeEventListener("abort", onSignalAbort);
|
|
77823
|
+
}
|
|
77824
|
+
})();
|
|
77825
|
+
}
|
|
77826
|
+
});
|
|
77827
|
+
}
|
|
77828
|
+
async function peerOutboundFetch(input3, init) {
|
|
77829
|
+
if (globalThis.fetch !== BUILTIN_FETCH) {
|
|
77830
|
+
if (!init) return globalThis.fetch(input3);
|
|
77831
|
+
let {
|
|
77832
|
+
allowLoopback: _allowLoopback,
|
|
77833
|
+
dnsLookup: _dnsLookup,
|
|
77834
|
+
resolvedAddresses: _resolvedAddresses,
|
|
77835
|
+
...fetchInit
|
|
77836
|
+
} = init;
|
|
77837
|
+
return globalThis.fetch(input3, fetchInit);
|
|
77838
|
+
}
|
|
77839
|
+
let target2, route;
|
|
77840
|
+
try {
|
|
77841
|
+
target2 = typeof input3 == "string" ? new URL(input3) : input3, route = await resolvePeerOutboundRoute(target2, {
|
|
77842
|
+
allowLoopback: init?.allowLoopback,
|
|
77843
|
+
dnsLookup: init?.dnsLookup,
|
|
77844
|
+
resolvedAddresses: init?.resolvedAddresses,
|
|
77845
|
+
signal: init?.signal ?? void 0
|
|
77846
|
+
});
|
|
77847
|
+
} catch (err5) {
|
|
77848
|
+
throw cancelUploadBodyIfStream(init?.body, init?.signal?.aborted ? init.signal.reason : err5), err5;
|
|
77849
|
+
}
|
|
77850
|
+
return nodeFetchViaAdapter(target2, init, route);
|
|
77851
|
+
}
|
|
77852
|
+
|
|
77216
77853
|
// packages/web-server/src/peer-request-error.ts
|
|
77217
77854
|
var TIMEOUT_CODES = /* @__PURE__ */ new Set([
|
|
77218
77855
|
"ETIMEDOUT",
|
|
@@ -77308,8 +77945,11 @@ async function peerFetch(record6, path7, init = {}) {
|
|
|
77308
77945
|
headers: headers2,
|
|
77309
77946
|
...requestBody === void 0 ? {} : { body: requestBody },
|
|
77310
77947
|
...init.duplex === void 0 ? {} : { duplex: init.duplex },
|
|
77311
|
-
...signal === void 0 ? {} : { signal }
|
|
77312
|
-
|
|
77948
|
+
...signal === void 0 ? {} : { signal },
|
|
77949
|
+
...init.allowLoopback === void 0 ? {} : { allowLoopback: init.allowLoopback },
|
|
77950
|
+
...init.dnsLookup === void 0 ? {} : { dnsLookup: init.dnsLookup },
|
|
77951
|
+
...init.resolvedAddresses === void 0 ? {} : { resolvedAddresses: init.resolvedAddresses }
|
|
77952
|
+
}, res = await peerOutboundFetch(record6.origin + path7, requestInit);
|
|
77313
77953
|
if (res.ok || res.status === 304 && headers2.has("if-none-match")) return res;
|
|
77314
77954
|
let failure3 = await res.json().then((payload) => {
|
|
77315
77955
|
if (!payload || typeof payload != "object" || !("error" in payload)) return;
|
|
@@ -77360,54 +78000,33 @@ async function pinnedPeerGetJson(record6, path7, options = {}) {
|
|
|
77360
78000
|
if (!record6.enabled) throw new SessionRuntimeError("remote/offline", "Remote peer is disabled");
|
|
77361
78001
|
let url2 = parsePeerUrl(record6.origin + path7, {
|
|
77362
78002
|
allowLoopback: options.allowLoopback === !0
|
|
77363
|
-
}),
|
|
77364
|
-
|
|
77365
|
-
|
|
77366
|
-
|
|
77367
|
-
|
|
77368
|
-
|
|
77369
|
-
|
|
77370
|
-
|
|
77371
|
-
|
|
77372
|
-
|
|
77373
|
-
|
|
77374
|
-
|
|
77375
|
-
let family = typeof lookupOptions == "number" ? lookupOptions : opts.family, match = family === 4 || family === 6 ? verified.find((entry) => entry.family === family) : verified[0];
|
|
77376
|
-
if (!match) {
|
|
77377
|
-
callback(
|
|
77378
|
-
Object.assign(new Error("No verified address matches requested IP family"), {
|
|
77379
|
-
code: "ENOTFOUND"
|
|
77380
|
-
}),
|
|
77381
|
-
"",
|
|
77382
|
-
4
|
|
77383
|
-
);
|
|
77384
|
-
return;
|
|
77385
|
-
}
|
|
77386
|
-
callback(null, match.address, match.family);
|
|
77387
|
-
};
|
|
78003
|
+
}), candidateProxy = resolvePeerProxyUrl(url2), verified;
|
|
78004
|
+
try {
|
|
78005
|
+
verified = await resolveAndValidatePeerHost(url2, {
|
|
78006
|
+
allowLoopback: options.allowLoopback === !0,
|
|
78007
|
+
dnsLookup: options.dnsLookup
|
|
78008
|
+
});
|
|
78009
|
+
} catch (err5) {
|
|
78010
|
+
if (err5 instanceof PeerHostPolicyError || !candidateProxy || options.dnsLookup !== void 0 || !isDnsResolutionError(err5))
|
|
78011
|
+
throw err5;
|
|
78012
|
+
}
|
|
78013
|
+
options.onResolved?.(verified);
|
|
78014
|
+
let proxy = verified ? resolvePeerProxyUrl(url2, { resolvedAddresses: verified }) : candidateProxy, timeoutSignal = AbortSignal.timeout(options.timeoutMs ?? 8e3), signal = options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal, pinnedLookup = verified ? createPinnedLookup(verified) : void 0;
|
|
77388
78015
|
return await new Promise((resolve26, reject) => {
|
|
77389
78016
|
let settled2 = !1, fail = (err5) => {
|
|
77390
78017
|
settled2 || (settled2 = !0, reject(err5));
|
|
77391
78018
|
}, succeed = (value) => {
|
|
77392
78019
|
settled2 || (settled2 = !0, resolve26(value));
|
|
77393
|
-
},
|
|
77394
|
-
protocol: url2.protocol,
|
|
77395
|
-
hostname: bareHostname,
|
|
77396
|
-
...url2.port ? { port: Number(url2.port) } : {},
|
|
77397
|
-
path: `${url2.pathname}${url2.search}`,
|
|
78020
|
+
}, req = openPeerHttpRequest(url2, {
|
|
77398
78021
|
method: "GET",
|
|
77399
78022
|
headers: {
|
|
77400
|
-
host: url2.host,
|
|
77401
78023
|
authorization: "Bearer " + record6.token,
|
|
77402
78024
|
"content-type": "application/json"
|
|
77403
78025
|
},
|
|
77404
|
-
|
|
77405
|
-
lookup: pinnedLookup,
|
|
78026
|
+
...proxy ? { proxy } : {},
|
|
78027
|
+
...!proxy && pinnedLookup ? { lookup: pinnedLookup } : {},
|
|
77406
78028
|
signal
|
|
77407
|
-
}
|
|
77408
|
-
...requestOptions,
|
|
77409
|
-
...isIP2(bareHostname) === 0 ? { servername: bareHostname } : {}
|
|
77410
|
-
}) : httpRequest(requestOptions);
|
|
78029
|
+
});
|
|
77411
78030
|
req.on("error", () => {
|
|
77412
78031
|
fail(new SessionRuntimeError("remote/offline", "Remote peer is unreachable"));
|
|
77413
78032
|
}), req.on("response", (res) => {
|
|
@@ -77488,6 +78107,7 @@ var INITIAL_CONNECTION_WAIT_MS = 2e3, MAX_TRACKED_SNAPSHOT_THREADS = 64, MAX_TRA
|
|
|
77488
78107
|
rejectNodeId;
|
|
77489
78108
|
allowLoopback;
|
|
77490
78109
|
dnsLookup;
|
|
78110
|
+
probedAddresses;
|
|
77491
78111
|
fullKnownTurns = /* @__PURE__ */ new Map();
|
|
77492
78112
|
truncatedKnownTurns = /* @__PURE__ */ new Map();
|
|
77493
78113
|
knownTurnsEpoch;
|
|
@@ -77596,11 +78216,18 @@ var INITIAL_CONNECTION_WAIT_MS = 2e3, MAX_TRACKED_SNAPSHOT_THREADS = 64, MAX_TRA
|
|
|
77596
78216
|
manifest: () => this.manifest
|
|
77597
78217
|
};
|
|
77598
78218
|
}
|
|
78219
|
+
outboundFetchOptions() {
|
|
78220
|
+
return {
|
|
78221
|
+
allowLoopback: this.allowLoopback,
|
|
78222
|
+
...this.probedAddresses !== void 0 ? { resolvedAddresses: this.probedAddresses } : this.dnsLookup !== void 0 ? { dnsLookup: this.dnsLookup } : {}
|
|
78223
|
+
};
|
|
78224
|
+
}
|
|
77599
78225
|
fetch(path7, method2 = "GET", body, streamSignal) {
|
|
77600
78226
|
return peerFetch(this.record, path7, {
|
|
77601
78227
|
method: method2,
|
|
77602
78228
|
...body === void 0 ? {} : { body },
|
|
77603
|
-
...streamSignal ? { stream: !0, signal: AbortSignal.any([streamSignal, this.life.signal]) } : { signal: this.life.signal }
|
|
78229
|
+
...streamSignal ? { stream: !0, signal: AbortSignal.any([streamSignal, this.life.signal]) } : { signal: this.life.signal },
|
|
78230
|
+
...this.outboundFetchOptions()
|
|
77604
78231
|
});
|
|
77605
78232
|
}
|
|
77606
78233
|
async waitForInitialConnection() {
|
|
@@ -77618,18 +78245,21 @@ var INITIAL_CONNECTION_WAIT_MS = 2e3, MAX_TRACKED_SNAPSHOT_THREADS = 64, MAX_TRA
|
|
|
77618
78245
|
async probe() {
|
|
77619
78246
|
let start = Date.now();
|
|
77620
78247
|
try {
|
|
77621
|
-
let manifest2 = remotePeerManifestSchema.parse(
|
|
78248
|
+
let resolvedAddresses, manifest2 = remotePeerManifestSchema.parse(
|
|
77622
78249
|
await pinnedPeerGetJson(this.record, "/api/peer/v1/manifest", {
|
|
77623
78250
|
allowLoopback: this.allowLoopback,
|
|
77624
78251
|
dnsLookup: this.dnsLookup,
|
|
77625
|
-
signal: this.life.signal
|
|
78252
|
+
signal: this.life.signal,
|
|
78253
|
+
onResolved: (addresses) => {
|
|
78254
|
+
resolvedAddresses = addresses;
|
|
78255
|
+
}
|
|
77626
78256
|
})
|
|
77627
78257
|
);
|
|
77628
78258
|
if (this.rejectNodeId !== void 0 && manifest2.nodeId === this.rejectNodeId)
|
|
77629
78259
|
throw Error(SELF_PAIR_ERROR);
|
|
77630
|
-
this.manifest = manifest2, this.manifestVerified = !0, this.latencyMs = Date.now() - start, delete this.lastError, this.state = this.streamOnline ? "connected" : "connecting";
|
|
78260
|
+
this.probedAddresses = resolvedAddresses, this.manifest = manifest2, this.manifestVerified = !0, this.latencyMs = Date.now() - start, delete this.lastError, this.state = this.streamOnline ? "connected" : "connecting";
|
|
77631
78261
|
} catch (e) {
|
|
77632
|
-
if (this.manifestVerified = !1, e instanceof PeerHostPolicyError || e instanceof Error && e.message === SELF_PAIR_ERROR)
|
|
78262
|
+
if (this.manifestVerified = !1, this.probedAddresses = void 0, e instanceof PeerHostPolicyError || e instanceof PeerProxyConfigError || e instanceof Error && e.message === SELF_PAIR_ERROR)
|
|
77633
78263
|
throw delete this.manifest, this.state = "offline", this.lastError = e.message, this.setStreamOffline(), this.initialConnection.resolve(void 0), e;
|
|
77634
78264
|
this.state = e instanceof SessionRuntimeError && e.code === "remote/auth-error" ? "auth-error" : "offline";
|
|
77635
78265
|
let message2 = this.state === "auth-error" ? "Remote peer rejected the access token" : "Remote peer manifest unavailable";
|
|
@@ -77651,8 +78281,10 @@ var INITIAL_CONNECTION_WAIT_MS = 2e3, MAX_TRACKED_SNAPSHOT_THREADS = 64, MAX_TRA
|
|
|
77651
78281
|
this.changed(this.hostId);
|
|
77652
78282
|
}
|
|
77653
78283
|
if (this.life.signal.aborted) return;
|
|
77654
|
-
let query =
|
|
77655
|
-
|
|
78284
|
+
let query = new URLSearchParams({ [THREAD_SECTION_CAPABILITY]: "1" });
|
|
78285
|
+
this.cursor && (query.set("epoch", this.cursor.epoch), query.set("after", String(this.cursor.sequence)));
|
|
78286
|
+
let response = await this.fetch(
|
|
78287
|
+
`/api/ch/v1/events?${query}`,
|
|
77656
78288
|
"GET",
|
|
77657
78289
|
void 0,
|
|
77658
78290
|
streamAbort.signal
|
|
@@ -77703,7 +78335,7 @@ var INITIAL_CONNECTION_WAIT_MS = 2e3, MAX_TRACKED_SNAPSHOT_THREADS = 64, MAX_TRA
|
|
|
77703
78335
|
}
|
|
77704
78336
|
}
|
|
77705
78337
|
close() {
|
|
77706
|
-
this.life.abort(), this.manifestVerified = !1, this.record = { ...this.record, token: "" }, this.initialConnection.resolve(void 0), this.setStreamOffline(), this.listeners.clear(), this.fullKnownTurns.clear(), this.truncatedKnownTurns.clear(), this.knownTurnsEpoch = void 0;
|
|
78338
|
+
this.life.abort(), this.manifestVerified = !1, this.probedAddresses = void 0, this.record = { ...this.record, token: "" }, this.initialConnection.resolve(void 0), this.setStreamOffline(), this.listeners.clear(), this.fullKnownTurns.clear(), this.truncatedKnownTurns.clear(), this.knownTurnsEpoch = void 0;
|
|
77707
78339
|
}
|
|
77708
78340
|
async introduce(params) {
|
|
77709
78341
|
if (!this.isHttpReady)
|
|
@@ -77714,7 +78346,8 @@ var INITIAL_CONNECTION_WAIT_MS = 2e3, MAX_TRACKED_SNAPSHOT_THREADS = 64, MAX_TRA
|
|
|
77714
78346
|
method: "POST",
|
|
77715
78347
|
body: params,
|
|
77716
78348
|
timeoutMs: 15e3,
|
|
77717
|
-
signal: this.life.signal
|
|
78349
|
+
signal: this.life.signal,
|
|
78350
|
+
...this.outboundFetchOptions()
|
|
77718
78351
|
}), result = remotePeerIntroduceResultSchema.safeParse(
|
|
77719
78352
|
await response.json().catch(() => {
|
|
77720
78353
|
})
|
|
@@ -77770,7 +78403,8 @@ var INITIAL_CONNECTION_WAIT_MS = 2e3, MAX_TRACKED_SNAPSHOT_THREADS = 64, MAX_TRA
|
|
|
77770
78403
|
sourceId: request3.sourceId ?? this.record.peerId
|
|
77771
78404
|
},
|
|
77772
78405
|
signal,
|
|
77773
|
-
timeoutMs: options.timeoutMs ?? defaultTimeoutMs
|
|
78406
|
+
timeoutMs: options.timeoutMs ?? defaultTimeoutMs,
|
|
78407
|
+
...this.outboundFetchOptions()
|
|
77774
78408
|
}), payload;
|
|
77775
78409
|
try {
|
|
77776
78410
|
payload = await res.json();
|
|
@@ -78461,9 +79095,9 @@ var DEFAULT_MODEL_INSPECT_TIMEOUT_MS = 5e3, INSPECT_TIMED_OUT = /* @__PURE__ */
|
|
|
78461
79095
|
}
|
|
78462
79096
|
return inspection;
|
|
78463
79097
|
}
|
|
78464
|
-
async models(refresh = !1, harnessId, preferences2) {
|
|
79098
|
+
async models(refresh = !1, harnessId, preferences2, projectHarnessId2) {
|
|
78465
79099
|
if (!refresh)
|
|
78466
|
-
return await Promise.allSettled(this.refreshing.values()), this.readModels(!1, void 0, preferences2);
|
|
79100
|
+
return await Promise.allSettled(this.refreshing.values()), this.readModels(!1, void 0, preferences2, projectHarnessId2);
|
|
78467
79101
|
let pending = this.refreshing.get(harnessId);
|
|
78468
79102
|
if (pending) return pending;
|
|
78469
79103
|
let operation = this.readModels(!0, harnessId).finally(() => {
|
|
@@ -78512,7 +79146,7 @@ var DEFAULT_MODEL_INSPECT_TIMEOUT_MS = 5e3, INSPECT_TIMED_OUT = /* @__PURE__ */
|
|
|
78512
79146
|
}
|
|
78513
79147
|
)), id2 === "codex" ? void 0 : timedOutInspection();
|
|
78514
79148
|
}
|
|
78515
|
-
async readModels(refresh, harnessId, preferences2) {
|
|
79149
|
+
async readModels(refresh, harnessId, preferences2, projectHarnessId2) {
|
|
78516
79150
|
let shouldRefresh = (id2) => refresh && (harnessId === void 0 || harnessId === id2), plugins2 = await this.list(), values2 = (await Promise.all(
|
|
78517
79151
|
plugins2.map(async ({ id: id2, name: name2, links }) => ({
|
|
78518
79152
|
id: id2,
|
|
@@ -78538,9 +79172,9 @@ var DEFAULT_MODEL_INSPECT_TIMEOUT_MS = 5e3, INSPECT_TIMED_OUT = /* @__PURE__ */
|
|
|
78538
79172
|
}
|
|
78539
79173
|
let groups = values2.flatMap(
|
|
78540
79174
|
({ id: id2, name: name2, inspection }) => inspection.status === "ready" ? [groupOf(id2, name2, inspection)] : []
|
|
78541
|
-
),
|
|
79175
|
+
), ready = values2.filter(
|
|
78542
79176
|
(value) => value.inspection.status === "ready" && value.inspection.catalog.models.length
|
|
78543
|
-
), failures = values2.flatMap(
|
|
79177
|
+
), projectHarness = ready.find((value) => value.id === projectHarnessId2), first = projectHarness ?? ready[0], failures = values2.flatMap(
|
|
78544
79178
|
({ id: id2, name: name2, inspection }) => inspection.status !== "ready" && inspection.status !== "notInstalled" ? [
|
|
78545
79179
|
{
|
|
78546
79180
|
id: id2,
|
|
@@ -78570,7 +79204,11 @@ var DEFAULT_MODEL_INSPECT_TIMEOUT_MS = 5e3, INSPECT_TIMED_OUT = /* @__PURE__ */
|
|
|
78570
79204
|
},
|
|
78571
79205
|
await this.displayEntries()
|
|
78572
79206
|
);
|
|
78573
|
-
return this.preferences && selection2 ? this.preferences.decorate(
|
|
79207
|
+
return this.preferences && selection2 ? this.preferences.decorate(
|
|
79208
|
+
{ ...catalog, default: selection2 },
|
|
79209
|
+
preferences2,
|
|
79210
|
+
projectHarness?.id
|
|
79211
|
+
) : catalog;
|
|
78574
79212
|
}
|
|
78575
79213
|
async name(id2) {
|
|
78576
79214
|
return id2 === "codex" ? "Codex" : (await this.list()).find((plugin) => plugin.id === id2)?.name ?? id2;
|
|
@@ -78596,6 +79234,10 @@ var permissionCommand = {
|
|
|
78596
79234
|
name: "permission",
|
|
78597
79235
|
description: "Select a native permission mode",
|
|
78598
79236
|
input: { hint: "<mode>" }
|
|
79237
|
+
}, codexPlanCommand = {
|
|
79238
|
+
definitionId: "@deepseek-ai/dsh-plan-mode",
|
|
79239
|
+
name: "plan",
|
|
79240
|
+
description: "Enter or leave native Codex Plan Mode"
|
|
78599
79241
|
};
|
|
78600
79242
|
function requireDirectCommand(catalog, commandId) {
|
|
78601
79243
|
let command = catalog.commands.find((item) => item.id === commandId);
|
|
@@ -78666,9 +79308,10 @@ var ChRealtime = class {
|
|
|
78666
79308
|
urgent = /* @__PURE__ */ new Set();
|
|
78667
79309
|
running = /* @__PURE__ */ new Set();
|
|
78668
79310
|
timers = /* @__PURE__ */ new Map();
|
|
78669
|
-
catalogReason
|
|
79311
|
+
catalogReason;
|
|
78670
79312
|
threadDebounceMs;
|
|
78671
79313
|
closed = !1;
|
|
79314
|
+
sectionsDirty = !1;
|
|
78672
79315
|
online = !1;
|
|
78673
79316
|
unsubscribe;
|
|
78674
79317
|
invalidate(id2) {
|
|
@@ -78692,9 +79335,11 @@ var ChRealtime = class {
|
|
|
78692
79335
|
if (event.type === "hello") {
|
|
78693
79336
|
this.callbacks.reset(event.cursor.epoch, event.reset);
|
|
78694
79337
|
for (let id2 of this.watched.keys()) this.schedule(id2, 100);
|
|
78695
|
-
this.
|
|
79338
|
+
this.catalogReason ??= "hello", this.schedule("", 100);
|
|
78696
79339
|
} else if (event.type === "projects-changed")
|
|
78697
|
-
this.schedule("", 100);
|
|
79340
|
+
this.catalogReason = "changed", this.schedule("", 100);
|
|
79341
|
+
else if (event.type === "sections-changed" && this.callbacks.sections)
|
|
79342
|
+
this.sectionsDirty = !0, this.schedule("", 100);
|
|
78698
79343
|
else if (event.type === "changed") {
|
|
78699
79344
|
if (event.method === "codexhost/thread/usage/updated" || event.method === "thread/tokenUsage/updated") {
|
|
78700
79345
|
this.online && this.watched.has(event.threadId) && this.callbacks.usage(event.threadId);
|
|
@@ -78733,12 +79378,14 @@ var ChRealtime = class {
|
|
|
78733
79378
|
if (this.dirty.delete(id2), this.urgent.delete(id2), this.closed || !this.online || id2 && !this.watched.has(id2)) return;
|
|
78734
79379
|
this.running.add(id2);
|
|
78735
79380
|
let catalogReason = id2 ? void 0 : this.catalogReason;
|
|
78736
|
-
id2 || (this.catalogReason =
|
|
79381
|
+
id2 || (this.catalogReason = void 0);
|
|
79382
|
+
let sections = !id2 && this.sectionsDirty ? this.callbacks.sections : void 0;
|
|
79383
|
+
sections && (this.sectionsDirty = !1);
|
|
78737
79384
|
let retryDelay2;
|
|
78738
79385
|
try {
|
|
78739
|
-
id2 ? await this.callbacks.thread(id2) : await this.callbacks.catalog(catalogReason);
|
|
79386
|
+
id2 ? await this.callbacks.thread(id2) : catalogReason ? await this.callbacks.catalog(catalogReason, !!sections) : sections && await sections();
|
|
78740
79387
|
} catch (error62) {
|
|
78741
|
-
this.callbacks.error(id2, error62), this.dirty.add(id2),
|
|
79388
|
+
sections && (this.sectionsDirty = !0), this.callbacks.error(id2, error62), this.dirty.add(id2), catalogReason && (this.catalogReason ??= catalogReason), retryDelay2 = 1e3;
|
|
78742
79389
|
} finally {
|
|
78743
79390
|
if (this.running.delete(id2), this.dirty.has(id2)) {
|
|
78744
79391
|
let nextDelay = retryDelay2 ?? (id2 ? this.urgent.has(id2) ? 100 : this.threadDebounceMs : 100);
|
|
@@ -80261,6 +80908,8 @@ function markdownImageAlt(path7) {
|
|
|
80261
80908
|
function itemOf(item, reasoningPreviewIds, projectImage, projectionKey, projectText) {
|
|
80262
80909
|
let itemId = item.id;
|
|
80263
80910
|
switch (item.type) {
|
|
80911
|
+
case "plan":
|
|
80912
|
+
return typeof item.text != "string" || !item.text.trim() ? void 0 : { type: "agentMessage", itemId, text: projectText(item.text) };
|
|
80264
80913
|
case "agentMessage":
|
|
80265
80914
|
return {
|
|
80266
80915
|
type: "agentMessage",
|
|
@@ -83523,7 +84172,16 @@ import { dirname as dirname5, isAbsolute as isAbsolute6, join as join9, parse as
|
|
|
83523
84172
|
// packages/web-server/src/compression.ts
|
|
83524
84173
|
import { promisify as promisify2 } from "node:util";
|
|
83525
84174
|
import { brotliCompress, constants as constants3, gzip } from "node:zlib";
|
|
83526
|
-
var COMPRESSION_THRESHOLD = 1024, brotliAsync = promisify2(brotliCompress), gzipAsync = promisify2(gzip), compressedAssets = /* @__PURE__ */ new Map();
|
|
84175
|
+
var COMPRESSION_THRESHOLD = 1024, brotliAsync = promisify2(brotliCompress), gzipAsync = promisify2(gzip), MAX_COMPRESSED_CACHE_ENTRIES = 64, MAX_COMPRESSED_CACHE_BYTES = 8 * 1024 * 1024, MAX_CACHED_UNCOMPRESSED_BYTES = 512 * 1024, compressedAssets = /* @__PURE__ */ new Map(), inFlightCompressed = /* @__PURE__ */ new Map(), compressedAssetBytes = 0;
|
|
84176
|
+
function cacheCompressedAsset(key, buffer3) {
|
|
84177
|
+
if (buffer3.byteLength > MAX_COMPRESSED_CACHE_BYTES) return;
|
|
84178
|
+
let existing = compressedAssets.get(key);
|
|
84179
|
+
for (existing !== void 0 && (compressedAssetBytes -= existing.byteLength, compressedAssets.delete(key)), compressedAssets.set(key, buffer3), compressedAssetBytes += buffer3.byteLength; compressedAssets.size > MAX_COMPRESSED_CACHE_ENTRIES || compressedAssetBytes > MAX_COMPRESSED_CACHE_BYTES; ) {
|
|
84180
|
+
let oldest = compressedAssets.entries().next().value;
|
|
84181
|
+
if (!oldest) break;
|
|
84182
|
+
compressedAssets.delete(oldest[0]), compressedAssetBytes -= oldest[1].byteLength;
|
|
84183
|
+
}
|
|
84184
|
+
}
|
|
83527
84185
|
function isCompressible(contentType) {
|
|
83528
84186
|
let type2 = contentType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
|
|
83529
84187
|
return type2.startsWith("text/") || [
|
|
@@ -83546,12 +84204,27 @@ async function compressResponse(body, contentType, acceptEncoding, cacheKey) {
|
|
|
83546
84204
|
headers2.vary = "Accept-Encoding";
|
|
83547
84205
|
let encoding = negotiate(acceptEncoding);
|
|
83548
84206
|
if (encoding === void 0 || body.length < COMPRESSION_THRESHOLD) return { body, headers: headers2 };
|
|
83549
|
-
let key = cacheKey === void 0 ? void 0 : `${encoding}:${cacheKey}
|
|
83550
|
-
|
|
84207
|
+
let key = cacheKey === void 0 ? void 0 : `${encoding}:${cacheKey}`;
|
|
84208
|
+
if (key !== void 0) {
|
|
84209
|
+
let cached3 = compressedAssets.get(key);
|
|
84210
|
+
if (cached3 !== void 0)
|
|
84211
|
+
return compressedAssets.delete(key), compressedAssets.set(key, cached3), headers2["content-encoding"] = encoding, { body: cached3, headers: headers2 };
|
|
84212
|
+
}
|
|
84213
|
+
let compressed = key === void 0 ? void 0 : inFlightCompressed.get(key);
|
|
84214
|
+
if (compressed === void 0) {
|
|
84215
|
+
let shouldCache = key !== void 0 && body.byteLength <= MAX_CACHED_UNCOMPRESSED_BYTES;
|
|
84216
|
+
if (compressed = (encoding === "br" ? brotliAsync(body, { params: { [constants3.BROTLI_PARAM_QUALITY]: 5 } }) : gzipAsync(body, { level: 6 })).then((result) => (shouldCache && key !== void 0 && cacheCompressedAsset(key, result), result)), key !== void 0) {
|
|
84217
|
+
let pending = compressed, cleanup = () => {
|
|
84218
|
+
inFlightCompressed.get(key) === pending && inFlightCompressed.delete(key);
|
|
84219
|
+
};
|
|
84220
|
+
inFlightCompressed.set(key, pending), pending.then(cleanup, cleanup);
|
|
84221
|
+
}
|
|
84222
|
+
}
|
|
84223
|
+
return headers2["content-encoding"] = encoding, { body: await compressed, headers: headers2 };
|
|
83551
84224
|
}
|
|
83552
84225
|
|
|
83553
84226
|
// packages/web-server/src/peer-image-http.ts
|
|
83554
|
-
import { Readable } from "node:stream";
|
|
84227
|
+
import { Readable as Readable2 } from "node:stream";
|
|
83555
84228
|
import { pipeline } from "node:stream/promises";
|
|
83556
84229
|
|
|
83557
84230
|
// packages/web-server/src/http-content-length.ts
|
|
@@ -83637,7 +84310,7 @@ async function servePeerImageBody(upstream, response, etag, length) {
|
|
|
83637
84310
|
async function* body() {
|
|
83638
84311
|
yield* parts, yield* chunks;
|
|
83639
84312
|
}
|
|
83640
|
-
await pipeline(
|
|
84313
|
+
await pipeline(Readable2.from(body(), { objectMode: !1 }), response);
|
|
83641
84314
|
return;
|
|
83642
84315
|
}
|
|
83643
84316
|
for await (let chunk of chunks) parts.push(chunk);
|
|
@@ -84491,7 +85164,7 @@ async function startPeerDelegationBridge(options) {
|
|
|
84491
85164
|
|
|
84492
85165
|
// packages/web-server/src/peer-workspace-files-http.ts
|
|
84493
85166
|
import { extname as extname6, posix as posix3, win32 as win327 } from "node:path";
|
|
84494
|
-
import { Readable as
|
|
85167
|
+
import { Readable as Readable5 } from "node:stream";
|
|
84495
85168
|
import { pipeline as pipeline2 } from "node:stream/promises";
|
|
84496
85169
|
|
|
84497
85170
|
// apps/web-ui/packages/host/dsh-web-backend/src/index.ts
|
|
@@ -89608,7 +90281,7 @@ var clientRequestSchema = external_exports.object({
|
|
|
89608
90281
|
]);
|
|
89609
90282
|
|
|
89610
90283
|
// apps/web-ui/packages/client/connection/src/http-bridge.ts
|
|
89611
|
-
import { Readable as
|
|
90284
|
+
import { Readable as Readable3 } from "node:stream";
|
|
89612
90285
|
var DEFAULT_MAX_REQUEST_BODY_BYTES = 300 * 1024 * 1024;
|
|
89613
90286
|
async function bridge(req, res, apiHandler, maxRequestBodyBytes = DEFAULT_MAX_REQUEST_BODY_BYTES) {
|
|
89614
90287
|
let abort = new AbortController();
|
|
@@ -89643,7 +90316,7 @@ async function bridge(req, res, apiHandler, maxRequestBodyBytes = DEFAULT_MAX_RE
|
|
|
89643
90316
|
request3 = new Request(url2, {
|
|
89644
90317
|
method: method2,
|
|
89645
90318
|
headers: headers2,
|
|
89646
|
-
body:
|
|
90319
|
+
body: Readable3.toWeb(req),
|
|
89647
90320
|
signal: abort.signal,
|
|
89648
90321
|
duplex: "half"
|
|
89649
90322
|
});
|
|
@@ -89935,7 +90608,7 @@ import * as sysPath2 from "path";
|
|
|
89935
90608
|
|
|
89936
90609
|
// node_modules/readdirp/esm/index.js
|
|
89937
90610
|
import { stat as stat4, lstat as lstat4, readdir as readdir3, realpath as realpath3 } from "node:fs/promises";
|
|
89938
|
-
import { Readable as
|
|
90611
|
+
import { Readable as Readable4 } from "node:stream";
|
|
89939
90612
|
import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from "node:path";
|
|
89940
90613
|
var EntryTypes = {
|
|
89941
90614
|
FILE_TYPE: "files",
|
|
@@ -89980,7 +90653,7 @@ var RECURSIVE_ERROR_CODE = "READDIRP_RECURSIVE_ERROR", NORMAL_FLOW_ERRORS = /* @
|
|
|
89980
90653
|
return (entry) => trItems.some((f) => entry.basename === f);
|
|
89981
90654
|
}
|
|
89982
90655
|
return emptyFn;
|
|
89983
|
-
}, ReaddirpStream = class extends
|
|
90656
|
+
}, ReaddirpStream = class extends Readable4 {
|
|
89984
90657
|
constructor(options = {}) {
|
|
89985
90658
|
super({
|
|
89986
90659
|
objectMode: !0,
|
|
@@ -101411,39 +102084,64 @@ function waitForPromise(promise2, signal) {
|
|
|
101411
102084
|
function errorReason(reason, fallback) {
|
|
101412
102085
|
return reason instanceof Error ? reason : new Error(fallback, { cause: reason });
|
|
101413
102086
|
}
|
|
101414
|
-
var DEFAULT_CACHE_MAX_ROOTS =
|
|
102087
|
+
var DEFAULT_CACHE_MAX_ROOTS = 8, DEFAULT_CACHE_REFRESH_INTERVAL_MS = 2e3, DEFAULT_CACHE_IDLE_TTL_MS = 10 * 6e4, DEFAULT_CACHE_SWEEP_INTERVAL_MS = 6e4, WorkspaceFileSearchCache = class {
|
|
101415
102088
|
searches = /* @__PURE__ */ new Map();
|
|
101416
102089
|
maxRoots;
|
|
101417
102090
|
refreshIntervalMs;
|
|
102091
|
+
idleTtlMs;
|
|
101418
102092
|
config;
|
|
102093
|
+
sweepTimer;
|
|
101419
102094
|
disposed = !1;
|
|
101420
102095
|
constructor(options = {}) {
|
|
101421
|
-
this.maxRoots = options.maxRoots ?? DEFAULT_CACHE_MAX_ROOTS, this.refreshIntervalMs = options.refreshIntervalMs ?? DEFAULT_CACHE_REFRESH_INTERVAL_MS, this.config = options.config ?? {
|
|
102096
|
+
this.maxRoots = options.maxRoots ?? DEFAULT_CACHE_MAX_ROOTS, this.refreshIntervalMs = options.refreshIntervalMs ?? DEFAULT_CACHE_REFRESH_INTERVAL_MS, this.idleTtlMs = options.idleTtlMs ?? DEFAULT_CACHE_IDLE_TTL_MS, this.config = options.config ?? {
|
|
101422
102097
|
maxResults: DEFAULT_FILE_SEARCH_MAX_RESULTS,
|
|
101423
102098
|
maxEntries: DEFAULT_FILE_SEARCH_MAX_ENTRIES,
|
|
101424
102099
|
excludedDirectories: DEFAULT_FILE_SEARCH_EXCLUDED_DIRECTORIES
|
|
101425
102100
|
};
|
|
101426
102101
|
}
|
|
102102
|
+
ensureSweepTimer() {
|
|
102103
|
+
if (this.sweepTimer || this.disposed || this.idleTtlMs <= 0) return;
|
|
102104
|
+
let intervalMs = Math.min(DEFAULT_CACHE_SWEEP_INTERVAL_MS, Math.max(1e3, this.idleTtlMs));
|
|
102105
|
+
this.sweepTimer = setInterval(() => {
|
|
102106
|
+
this.sweepIdle(Date.now());
|
|
102107
|
+
}, intervalMs), this.sweepTimer.unref();
|
|
102108
|
+
}
|
|
102109
|
+
stopSweepTimer() {
|
|
102110
|
+
this.sweepTimer && (clearInterval(this.sweepTimer), this.sweepTimer = void 0);
|
|
102111
|
+
}
|
|
102112
|
+
sweepIdle(now) {
|
|
102113
|
+
if (!(this.idleTtlMs <= 0)) {
|
|
102114
|
+
for (let [root, entry] of this.searches)
|
|
102115
|
+
entry.inFlight === 0 && now - entry.lastAccessedAt >= this.idleTtlMs && (entry.search.dispose(), this.searches.delete(root));
|
|
102116
|
+
this.searches.size === 0 && this.stopSweepTimer();
|
|
102117
|
+
}
|
|
102118
|
+
}
|
|
102119
|
+
evictOverflow() {
|
|
102120
|
+
for (let [candidateRoot, candidate] of this.searches) {
|
|
102121
|
+
if (this.searches.size <= this.maxRoots) break;
|
|
102122
|
+
candidate.inFlight > 0 || (candidate.search.dispose(), this.searches.delete(candidateRoot));
|
|
102123
|
+
}
|
|
102124
|
+
}
|
|
101427
102125
|
async list(root, query, signal) {
|
|
101428
102126
|
if (signal.throwIfAborted(), this.disposed) return [];
|
|
101429
|
-
let now = Date.now()
|
|
101430
|
-
|
|
101431
|
-
|
|
101432
|
-
|
|
101433
|
-
|
|
101434
|
-
|
|
101435
|
-
|
|
101436
|
-
|
|
101437
|
-
|
|
101438
|
-
|
|
101439
|
-
|
|
101440
|
-
|
|
102127
|
+
let now = Date.now();
|
|
102128
|
+
this.sweepIdle(now);
|
|
102129
|
+
let entry = this.searches.get(root);
|
|
102130
|
+
entry ? (now - entry.refreshedAt >= this.refreshIntervalMs && (entry.search.invalidate(), entry.refreshedAt = now), entry.lastAccessedAt = now) : entry = {
|
|
102131
|
+
search: new WorkspaceFileSearch(root, this.config),
|
|
102132
|
+
refreshedAt: now,
|
|
102133
|
+
lastAccessedAt: now,
|
|
102134
|
+
inFlight: 0
|
|
102135
|
+
}, this.searches.delete(root), this.searches.set(root, entry), entry.inFlight += 1, this.evictOverflow(), this.ensureSweepTimer();
|
|
102136
|
+
try {
|
|
102137
|
+
return await entry.search.list(query, signal);
|
|
102138
|
+
} finally {
|
|
102139
|
+
entry.inFlight -= 1, entry.lastAccessedAt = Date.now(), this.searches.size > this.maxRoots && this.evictOverflow();
|
|
101441
102140
|
}
|
|
101442
|
-
return this.searches.delete(root), this.searches.set(root, entry), entry.search.list(query, signal);
|
|
101443
102141
|
}
|
|
101444
102142
|
close() {
|
|
101445
102143
|
if (!this.disposed) {
|
|
101446
|
-
this.disposed = !0;
|
|
102144
|
+
this.disposed = !0, this.stopSweepTimer();
|
|
101447
102145
|
for (let { search } of this.searches.values()) search.dispose();
|
|
101448
102146
|
this.searches.clear();
|
|
101449
102147
|
}
|
|
@@ -101457,7 +102155,11 @@ var PEER_WORKSPACE_FILES_HEADER = "x-codexhost-peer-workspace-files", MAX_PEER_S
|
|
|
101457
102155
|
"workspaceFiles/stat",
|
|
101458
102156
|
"workspaceFiles/list",
|
|
101459
102157
|
"officeToPdf/render"
|
|
101460
|
-
]), defaultPeerSearchCache
|
|
102158
|
+
]), defaultPeerSearchCache;
|
|
102159
|
+
function getDefaultPeerSearchCache() {
|
|
102160
|
+
return defaultPeerSearchCache ??= new WorkspaceFileSearchCache();
|
|
102161
|
+
}
|
|
102162
|
+
var MAX_RPC_BODY_BYTES = 1024 * 1024, MAX_OFFICE_INPUT_BYTES = 50 * 1024 * 1024, OFFICE_EXTENSIONS = /* @__PURE__ */ new Set(["doc", "docx", "xls", "xlsx", "ppt", "pptx"]), SAFE_DOWNLOAD_HEADERS = {
|
|
101461
102163
|
"Cache-Control": "private, no-store",
|
|
101462
102164
|
"X-Content-Type-Options": "nosniff",
|
|
101463
102165
|
"Content-Security-Policy": "sandbox; default-src 'none'",
|
|
@@ -101524,7 +102226,7 @@ async function sendTypertMultipart(response, rpcId, value, bytes, signal) {
|
|
|
101524
102226
|
response.end();
|
|
101525
102227
|
return;
|
|
101526
102228
|
}
|
|
101527
|
-
await pipeline2(
|
|
102229
|
+
await pipeline2(Readable5.fromWeb(encoded.body), response);
|
|
101528
102230
|
}
|
|
101529
102231
|
function sendPlain2(response, status, message2, isHead = !1) {
|
|
101530
102232
|
response.destroyed || response.writableEnded || response.headersSent || response.writeHead(status, {
|
|
@@ -101937,7 +102639,7 @@ async function handleSearch(request3, response, deps, signal) {
|
|
|
101937
102639
|
);
|
|
101938
102640
|
return;
|
|
101939
102641
|
}
|
|
101940
|
-
let cache2 = deps.searchCache ??
|
|
102642
|
+
let cache2 = deps.searchCache ?? getDefaultPeerSearchCache();
|
|
101941
102643
|
try {
|
|
101942
102644
|
let items = await cache2.list(validated.realRoot, query, signal);
|
|
101943
102645
|
if (signal.aborted || response.destroyed) return;
|
|
@@ -102093,7 +102795,8 @@ var RemotePeerAttachments = class {
|
|
|
102093
102795
|
},
|
|
102094
102796
|
body: toReadableStream(chunks),
|
|
102095
102797
|
duplex: "half",
|
|
102096
|
-
timeoutMs: this.uploadTimeoutMs
|
|
102798
|
+
timeoutMs: this.uploadTimeoutMs,
|
|
102799
|
+
...activePeer.outboundFetchOptions?.()
|
|
102097
102800
|
}
|
|
102098
102801
|
), payload = await readPeerJson(
|
|
102099
102802
|
response,
|
|
@@ -102185,7 +102888,8 @@ var RemotePeerAttachments = class {
|
|
|
102185
102888
|
try {
|
|
102186
102889
|
response = await peerFetch(activePeer.record, `/api/peer/v1/file?${query.toString()}`, {
|
|
102187
102890
|
method: "GET",
|
|
102188
|
-
timeoutMs: this.requestTimeoutMs
|
|
102891
|
+
timeoutMs: this.requestTimeoutMs,
|
|
102892
|
+
...activePeer.outboundFetchOptions?.()
|
|
102189
102893
|
});
|
|
102190
102894
|
} catch (error62) {
|
|
102191
102895
|
if (error62 instanceof SessionRuntimeError) {
|
|
@@ -102265,7 +102969,8 @@ var RemotePeerAttachments = class {
|
|
|
102265
102969
|
...condition === void 0 ? {} : { "if-none-match": condition }
|
|
102266
102970
|
},
|
|
102267
102971
|
signal: abort.signal,
|
|
102268
|
-
timeoutMs: this.requestTimeoutMs
|
|
102972
|
+
timeoutMs: this.requestTimeoutMs,
|
|
102973
|
+
...peer.outboundFetchOptions?.()
|
|
102269
102974
|
}), etag = peerImageETag(upstream.headers.get("etag"));
|
|
102270
102975
|
if (upstream.status === 304 && etag && matchesImageETag(condition, etag)) {
|
|
102271
102976
|
response.writeHead(304, peerImageCacheHeaders(etag)).end();
|
|
@@ -106052,13 +106757,14 @@ var RemotePeerWorkspaceFiles = class {
|
|
|
106052
106757
|
this.searchTimeoutMs
|
|
106053
106758
|
), combinedSignal = signal ? AbortSignal.any([signal, timeoutController.signal]) : timeoutController.signal, params = new URLSearchParams({ threadId: resolved.threadId, q: query });
|
|
106054
106759
|
try {
|
|
106055
|
-
let upstream = await
|
|
106760
|
+
let upstream = await peerOutboundFetch(
|
|
106056
106761
|
`${resolved.peer.record.origin}/api/peer/v1/workspace-files/search?${params.toString()}`,
|
|
106057
106762
|
{
|
|
106058
106763
|
method: "GET",
|
|
106059
106764
|
redirect: "error",
|
|
106060
106765
|
headers: { authorization: `Bearer ${resolved.peer.record.token}` },
|
|
106061
|
-
signal: combinedSignal
|
|
106766
|
+
signal: combinedSignal,
|
|
106767
|
+
...resolved.peer.outboundFetchOptions?.()
|
|
106062
106768
|
}
|
|
106063
106769
|
);
|
|
106064
106770
|
if (upstream.status === 401)
|
|
@@ -106157,7 +106863,7 @@ var RemotePeerWorkspaceFiles = class {
|
|
|
106157
106863
|
idleController.signal
|
|
106158
106864
|
]);
|
|
106159
106865
|
try {
|
|
106160
|
-
let upstream = await
|
|
106866
|
+
let upstream = await peerOutboundFetch(
|
|
106161
106867
|
`${resolved.peer.record.origin}/api/peer/v1/workspace-files/rpc`,
|
|
106162
106868
|
{
|
|
106163
106869
|
method: "POST",
|
|
@@ -106167,7 +106873,8 @@ var RemotePeerWorkspaceFiles = class {
|
|
|
106167
106873
|
"content-type": "application/json"
|
|
106168
106874
|
},
|
|
106169
106875
|
body: rewrittenBody,
|
|
106170
|
-
signal
|
|
106876
|
+
signal,
|
|
106877
|
+
...resolved.peer.outboundFetchOptions?.()
|
|
106171
106878
|
}
|
|
106172
106879
|
);
|
|
106173
106880
|
if (browserAbort.signal.aborted || response.destroyed)
|
|
@@ -106288,13 +106995,14 @@ var RemotePeerWorkspaceFiles = class {
|
|
|
106288
106995
|
return writePlainError(response, 429, "too many concurrent remote file requests"), !0;
|
|
106289
106996
|
let query = new URLSearchParams({ threadId: resolved.threadId, path: path7 }), { controller: browserAbort, detach } = attachBrowserDisconnectAbort(response, request3), timeoutController = new AbortController(), timer = setTimeout(() => timeoutController.abort(), this.downloadHandshakeTimeoutMs), signal = AbortSignal.any([browserAbort.signal, timeoutController.signal]);
|
|
106290
106997
|
try {
|
|
106291
|
-
let upstream = await
|
|
106998
|
+
let upstream = await peerOutboundFetch(
|
|
106292
106999
|
`${resolved.peer.record.origin}/api/peer/v1/workspace-files/download?${query.toString()}`,
|
|
106293
107000
|
{
|
|
106294
107001
|
method: "HEAD",
|
|
106295
107002
|
redirect: "error",
|
|
106296
107003
|
headers: { authorization: `Bearer ${resolved.peer.record.token}` },
|
|
106297
|
-
signal
|
|
107004
|
+
signal,
|
|
107005
|
+
...resolved.peer.outboundFetchOptions?.()
|
|
106298
107006
|
}
|
|
106299
107007
|
);
|
|
106300
107008
|
if (browserAbort.signal.aborted || response.destroyed) return !0;
|
|
@@ -106344,13 +107052,14 @@ var RemotePeerWorkspaceFiles = class {
|
|
|
106344
107052
|
return writePlainError(response, 429, "too many concurrent remote file requests", isHead), !0;
|
|
106345
107053
|
let { controller: browserAbort, detach } = attachBrowserDisconnectAbort(response, request3), handshakeAbort = new AbortController(), idleAbort = new AbortController(), timer = setTimeout(() => handshakeAbort.abort(), this.downloadHandshakeTimeoutMs), signal = AbortSignal.any([browserAbort.signal, handshakeAbort.signal, idleAbort.signal]), query = new URLSearchParams({ threadId: resolved.threadId, path: path7 });
|
|
106346
107054
|
try {
|
|
106347
|
-
let upstream = await
|
|
107055
|
+
let upstream = await peerOutboundFetch(
|
|
106348
107056
|
`${resolved.peer.record.origin}/api/peer/v1/workspace-files/download?${query.toString()}`,
|
|
106349
107057
|
{
|
|
106350
107058
|
method: isHead ? "HEAD" : "GET",
|
|
106351
107059
|
redirect: "error",
|
|
106352
107060
|
headers: { authorization: `Bearer ${resolved.peer.record.token}` },
|
|
106353
|
-
signal
|
|
107061
|
+
signal,
|
|
107062
|
+
...resolved.peer.outboundFetchOptions?.()
|
|
106354
107063
|
}
|
|
106355
107064
|
);
|
|
106356
107065
|
if (clearTimeout(timer), browserAbort.signal.aborted || response.destroyed)
|
|
@@ -106510,6 +107219,13 @@ async function sendAsset(request3, response, asset, cacheControl = "no-cache", r
|
|
|
106510
107219
|
...compressed.headers
|
|
106511
107220
|
}).end(compressed.body);
|
|
106512
107221
|
}
|
|
107222
|
+
async function sendShellIndex(request3, response, sources) {
|
|
107223
|
+
let builtInOnly = new URL(sources.url, "http://localhost").searchParams.get("extensions") === "off", source = (builtInOnly ? sources.recoveryAssets : sources.assets).index(), rendered = !builtInOnly && sources.renderIndex !== void 0 ? { ...source, body: Buffer.from(sources.renderIndex(source.body.toString())) } : source, document2 = sources.headScript === void 0 ? rendered : {
|
|
107224
|
+
...rendered,
|
|
107225
|
+
body: Buffer.from(String(rendered.body).replace("<head>", `<head>${sources.headScript}`))
|
|
107226
|
+
};
|
|
107227
|
+
await sendAsset(request3, response, document2, void 0, !0);
|
|
107228
|
+
}
|
|
106513
107229
|
|
|
106514
107230
|
// packages/web-server/src/tailscale-serve.ts
|
|
106515
107231
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -108323,7 +109039,7 @@ var VIRTUAL_INTERFACE = /^(?:docker|br-|virbr|vmnet|vboxnet|veth|lxcbr|cni|flann
|
|
|
108323
109039
|
function isWildcardHost(host) {
|
|
108324
109040
|
return host === "0.0.0.0" || host === "::";
|
|
108325
109041
|
}
|
|
108326
|
-
function
|
|
109042
|
+
function isLoopbackHost3(host) {
|
|
108327
109043
|
return host === "localhost" || host === "::1" || host.startsWith("127.");
|
|
108328
109044
|
}
|
|
108329
109045
|
function kindOf(address, interfaceName) {
|
|
@@ -108332,7 +109048,7 @@ function kindOf(address, interfaceName) {
|
|
|
108332
109048
|
function networkAccessUrls(host, port, interfaces = networkInterfaces()) {
|
|
108333
109049
|
return (isWildcardHost(host) ? Object.entries(interfaces).flatMap(
|
|
108334
109050
|
([name2, entries]) => (entries ?? []).filter((entry) => entry.family === "IPv4" && !entry.internal).map((entry) => ({ address: entry.address, name: name2 }))
|
|
108335
|
-
) :
|
|
109051
|
+
) : isLoopbackHost3(host) ? [] : [{ address: host }]).map(({ address, name: name2 }) => ({
|
|
108336
109052
|
kind: kindOf(address, name2),
|
|
108337
109053
|
url: `http://${address}:${String(port)}/`
|
|
108338
109054
|
})).sort((a, b) => KIND_ORDER[a.kind] - KIND_ORDER[b.kind]);
|
|
@@ -109755,7 +110471,7 @@ import { promisify as promisify6 } from "node:util";
|
|
|
109755
110471
|
import { randomBytes as randomBytes32, sign as sign2 } from "node:crypto";
|
|
109756
110472
|
import { randomBytes as randomBytes42 } from "crypto";
|
|
109757
110473
|
import { createHash as createHash22, randomUUID as randomUUID22 } from "crypto";
|
|
109758
|
-
import { isIPv4 as
|
|
110474
|
+
import { isIPv4 as isIPv43 } from "net";
|
|
109759
110475
|
import * as timers2 from "node:timers/promises";
|
|
109760
110476
|
import { randomBytes as randomBytes7 } from "crypto";
|
|
109761
110477
|
import { isIPv4 as isIPv44, isIPv6 as isIPv64 } from "net";
|
|
@@ -109765,7 +110481,7 @@ import { isIPv4 as isIPv422, isIPv6 } from "node:net";
|
|
|
109765
110481
|
import { createSocket as createSocket3 } from "node:dgram";
|
|
109766
110482
|
import * as dns from "node:dns/promises";
|
|
109767
110483
|
import { isIP as isIP22, isIPv6 as isIPv62 } from "node:net";
|
|
109768
|
-
import { isIPv4 as
|
|
110484
|
+
import { isIPv4 as isIPv432, isIPv6 as isIPv63 } from "node:net";
|
|
109769
110485
|
import { promises as dns2 } from "node:dns";
|
|
109770
110486
|
import { isIP as isIP32, SocketAddress } from "node:net";
|
|
109771
110487
|
import { connect as connect32, createServer as createServer4 } from "node:net";
|
|
@@ -116037,7 +116753,7 @@ var log18 = debug("werift-dtls : packages/dtls/src/server.ts : log"), DtlsServer
|
|
|
116037
116753
|
);
|
|
116038
116754
|
}
|
|
116039
116755
|
canPairWith(other) {
|
|
116040
|
-
let a =
|
|
116756
|
+
let a = isIPv43(this.host), b = isIPv43(other.host);
|
|
116041
116757
|
return this.component === other.component && this.transport.toLowerCase() === other.transport.toLowerCase() && canPairTcpCandidates(this, other) && a === b;
|
|
116042
116758
|
}
|
|
116043
116759
|
toSdp() {
|
|
@@ -117054,7 +117770,7 @@ var HostAddressBind = {
|
|
|
117054
117770
|
let normalized = normalizeIp(address);
|
|
117055
117771
|
return normalized === "0.0.0.0" || normalized === "::";
|
|
117056
117772
|
};
|
|
117057
|
-
function
|
|
117773
|
+
function resolveHostAddresses2({
|
|
117058
117774
|
enumerated,
|
|
117059
117775
|
assigned = [],
|
|
117060
117776
|
interfaceAddresses,
|
|
@@ -117075,7 +117791,7 @@ function resolveHostAddresses({
|
|
|
117075
117791
|
map3.has(key) || map3.set(key, { address, bindAddress, costly });
|
|
117076
117792
|
}
|
|
117077
117793
|
return map3;
|
|
117078
|
-
}, locals = toMap(enumerated), assignedLocals = toMap(assigned), udp4 = interfaceAddresses?.udp4, udp6 = interfaceAddresses?.udp6, explicitOf = (address) =>
|
|
117794
|
+
}, locals = toMap(enumerated), assignedLocals = toMap(assigned), udp4 = interfaceAddresses?.udp4, udp6 = interfaceAddresses?.udp6, explicitOf = (address) => isIPv432(address) ? udp4 : udp6, resolved = /* @__PURE__ */ new Map(), add = (host) => {
|
|
117079
117795
|
let key = normalizeIp(host.address);
|
|
117080
117796
|
resolved.has(key) || resolved.set(key, host);
|
|
117081
117797
|
}, localOrWildcard = (address) => {
|
|
@@ -118391,12 +119107,12 @@ async function createStunOverTurnClient(config2, options = {}) {
|
|
|
118391
119107
|
return new StunOverTurnProtocol(turn);
|
|
118392
119108
|
}
|
|
118393
119109
|
function alternateTlsOptions(configured, alternateDomain, tlsOptions = {}) {
|
|
118394
|
-
let identity2 = alternateDomain ?? tlsOptions.servername ?? configured[0],
|
|
119110
|
+
let identity2 = alternateDomain ?? tlsOptions.servername ?? configured[0], checkServerIdentity22 = tlsOptions.checkServerIdentity ?? tls2.checkServerIdentity;
|
|
118395
119111
|
return {
|
|
118396
119112
|
...tlsOptions,
|
|
118397
119113
|
// SNI cannot carry an IP literal.
|
|
118398
119114
|
servername: isIP42(identity2) ? void 0 : identity2,
|
|
118399
|
-
checkServerIdentity: (_host, cert) =>
|
|
119115
|
+
checkServerIdentity: (_host, cert) => checkServerIdentity22(identity2, cert)
|
|
118400
119116
|
};
|
|
118401
119117
|
}
|
|
118402
119118
|
function tryAlternateOf(error62, addressFamily) {
|
|
@@ -120214,7 +120930,7 @@ var log26 = debug(
|
|
|
120214
120930
|
) ?? [])
|
|
120215
120931
|
this.appendLocalCandidate(this.withGeneration(reflexive));
|
|
120216
120932
|
}
|
|
120217
|
-
let address =
|
|
120933
|
+
let address = resolveHostAddresses2({
|
|
120218
120934
|
enumerated: getHostInterfaceAddresses(
|
|
120219
120935
|
this.options.useIpv4,
|
|
120220
120936
|
this.options.useIpv6,
|
|
@@ -123377,7 +124093,7 @@ function parseIceServerUrl(url2) {
|
|
|
123377
124093
|
let matched = /^(stun|stuns|turn|turns):(.+)$/i.exec(url2.trim());
|
|
123378
124094
|
if (!matched)
|
|
123379
124095
|
return;
|
|
123380
|
-
let [, rawScheme, rawRest] = matched, scheme = rawScheme.toLowerCase(), [authority] = rawRest.split("?", 1), [, query = ""] = rawRest.split("?"), address = parseAddress(authority,
|
|
124096
|
+
let [, rawScheme, rawRest] = matched, scheme = rawScheme.toLowerCase(), [authority] = rawRest.split("?", 1), [, query = ""] = rawRest.split("?"), address = parseAddress(authority, defaultPort2(scheme));
|
|
123381
124097
|
if (!address)
|
|
123382
124098
|
return;
|
|
123383
124099
|
if (scheme === "stun" || scheme === "stuns")
|
|
@@ -123399,7 +124115,7 @@ function resolveParsedTurnTransport({
|
|
|
123399
124115
|
}) {
|
|
123400
124116
|
return transportParam == null ? scheme === "turns" ? "tls" : void 0 : transportParam === "udp" ? scheme === "turns" ? "invalid" : "udp" : transportParam === "tcp" ? scheme === "turns" ? "tls" : "tcp" : "invalid";
|
|
123401
124117
|
}
|
|
123402
|
-
function
|
|
124118
|
+
function defaultPort2(scheme) {
|
|
123403
124119
|
return scheme === "stuns" || scheme === "turns" ? 5349 : 3478;
|
|
123404
124120
|
}
|
|
123405
124121
|
function parseAddress(value, fallbackPort) {
|
|
@@ -139449,6 +140165,33 @@ var CLIENT_PLUGINS = [
|
|
|
139449
140165
|
}
|
|
139450
140166
|
};
|
|
139451
140167
|
|
|
140168
|
+
// packages/web-server/src/project-harness-default.ts
|
|
140169
|
+
function projectHarnessId(workspaces2, workspaceId) {
|
|
140170
|
+
let { selection: selection2, lastHarnessId } = workspaces2.harnessPreference(workspaceId);
|
|
140171
|
+
return selection2.mode === "manual" ? selection2.harnessId : selection2.mode === "last" ? lastHarnessId : void 0;
|
|
140172
|
+
}
|
|
140173
|
+
function registerProjectHarnessDefault(rpc2, workspaces2, catalog) {
|
|
140174
|
+
rpc2.register("workspace/defaultHarness", async (args) => {
|
|
140175
|
+
let request3 = requestOf(args);
|
|
140176
|
+
if (typeof request3?.workspaceId != "string" || !request3.workspaceId)
|
|
140177
|
+
throw new SessionRuntimeError("workspace/invalid-request", "Choose a project.");
|
|
140178
|
+
let { workspaceId } = request3, current = workspaces2.harnessPreference(workspaceId), harnesses = (await catalog.models().catch((error62) => {
|
|
140179
|
+
if (!(error62 instanceof SessionRuntimeError && error62.code === "host/no-harness"))
|
|
140180
|
+
throw error62;
|
|
140181
|
+
}))?.groups.filter((group) => group.models.length > 0).map(({ id: id2, name: name2 }) => ({ id: id2, name: name2 })) ?? [];
|
|
140182
|
+
if (request3.selection !== void 0) {
|
|
140183
|
+
let selection2 = projectHarnessSelectionSchema.safeParse(request3.selection);
|
|
140184
|
+
if (!selection2.success)
|
|
140185
|
+
throw new SessionRuntimeError("workspace/invalid-request", "Choose a valid project default.");
|
|
140186
|
+
let next = selection2.data;
|
|
140187
|
+
if (next.mode === "manual" && !harnesses.some(({ id: id2 }) => id2 === next.harnessId))
|
|
140188
|
+
throw new SessionRuntimeError("workspace/harness-unavailable", "This Harness is unavailable.");
|
|
140189
|
+
return workspaces2.setHarnessSelection(workspaceId, next), {};
|
|
140190
|
+
}
|
|
140191
|
+
return { selection: current.selection, harnesses };
|
|
140192
|
+
});
|
|
140193
|
+
}
|
|
140194
|
+
|
|
139452
140195
|
// packages/web-server/src/draft-configuration.ts
|
|
139453
140196
|
function draftPermissionMode(harnessId, inspection, preferred) {
|
|
139454
140197
|
if (inspection.status !== "ready") return;
|
|
@@ -139498,8 +140241,9 @@ import { randomUUID as randomUUID19 } from "node:crypto";
|
|
|
139498
140241
|
import { existsSync as existsSync12, mkdirSync as mkdirSync7, statSync as statSync8 } from "node:fs";
|
|
139499
140242
|
import { basename as basename11, isAbsolute as isAbsolute20, join as join26, relative as relative11, resolve as resolve16, sep as sep9 } from "node:path";
|
|
139500
140243
|
import { homedir as homedir6 } from "node:os";
|
|
140244
|
+
var NATIVE_PROJECT_WORKSPACE_PREFIX = "codex-project:";
|
|
139501
140245
|
function nativeProjectWorkspaceId(projectId) {
|
|
139502
|
-
return
|
|
140246
|
+
return `${NATIVE_PROJECT_WORKSPACE_PREFIX}${projectId}`;
|
|
139503
140247
|
}
|
|
139504
140248
|
function insertSessionId(ids, sessionId, beforeId) {
|
|
139505
140249
|
let rest = ids.filter((id2) => id2 !== sessionId), index = beforeId === void 0 ? rest.length : rest.indexOf(beforeId);
|
|
@@ -139633,7 +140377,7 @@ var Workspaces = class {
|
|
|
139633
140377
|
nativeRoots = /* @__PURE__ */ new Map();
|
|
139634
140378
|
nativeRootOwners = /* @__PURE__ */ new Map();
|
|
139635
140379
|
legacyAssignments = {};
|
|
139636
|
-
followers = /* @__PURE__ */ new
|
|
140380
|
+
followers = /* @__PURE__ */ new Map();
|
|
139637
140381
|
referenceGroups;
|
|
139638
140382
|
referenceProjectless = /* @__PURE__ */ new Set();
|
|
139639
140383
|
referencePins;
|
|
@@ -139684,8 +140428,9 @@ var Workspaces = class {
|
|
|
139684
140428
|
remoteProjectId(sessionId) {
|
|
139685
140429
|
return this.state.remoteProjectIds?.[sessionId];
|
|
139686
140430
|
}
|
|
139687
|
-
broadcast(frame) {
|
|
139688
|
-
for (let sink of this.followers)
|
|
140431
|
+
broadcast(frame, sectionCapability) {
|
|
140432
|
+
for (let [sink, capable] of this.followers)
|
|
140433
|
+
(sectionCapability === void 0 || capable === sectionCapability) && sink.push(frame);
|
|
139689
140434
|
}
|
|
139690
140435
|
touch(workspace) {
|
|
139691
140436
|
workspace.updatedAt = (/* @__PURE__ */ new Date()).toISOString(), this.save();
|
|
@@ -139788,7 +140533,19 @@ var Workspaces = class {
|
|
|
139788
140533
|
updatedAt: previous.get(project2.id)?.updatedAt ?? now,
|
|
139789
140534
|
origin: "codexhost"
|
|
139790
140535
|
};
|
|
139791
|
-
})
|
|
140536
|
+
});
|
|
140537
|
+
let registeredNative = new Set(this.nativeWorkspaces.map((item) => item.workspaceId)), existingPreferences = this.harnessPreferencesRecord();
|
|
140538
|
+
if (Object.keys(existingPreferences).some(
|
|
140539
|
+
(id2) => id2.startsWith(NATIVE_PROJECT_WORKSPACE_PREFIX) && !registeredNative.has(id2)
|
|
140540
|
+
)) {
|
|
140541
|
+
let remaining = Object.fromEntries(
|
|
140542
|
+
Object.entries(existingPreferences).filter(
|
|
140543
|
+
([id2]) => !id2.startsWith(NATIVE_PROJECT_WORKSPACE_PREFIX) || registeredNative.has(id2)
|
|
140544
|
+
)
|
|
140545
|
+
);
|
|
140546
|
+
this.saveHarnessPreferences(remaining);
|
|
140547
|
+
}
|
|
140548
|
+
this.publishWorkspaceChanges(before), this.publishPinnedWorkspaces();
|
|
139792
140549
|
}
|
|
139793
140550
|
updateNativeProjectMember(sessionId, projectId) {
|
|
139794
140551
|
if (!this.nativeWorkspaces || !projectId) return;
|
|
@@ -139873,44 +140630,44 @@ var Workspaces = class {
|
|
|
139873
140630
|
}
|
|
139874
140631
|
/** Unmodified official snapshot and the projection delivered to Web clients. */
|
|
139875
140632
|
officialThreadSections;
|
|
139876
|
-
|
|
139877
|
-
projectSectionCoverage = /* @__PURE__ */ new Map();
|
|
140633
|
+
officialThreadSectionsV1;
|
|
139878
140634
|
referenceThreadSections = [];
|
|
140635
|
+
legacyThreadSections = [];
|
|
140636
|
+
referenceThreadSectionsV1;
|
|
140637
|
+
referenceSectionWorkspaceIdsDirty = !1;
|
|
139879
140638
|
hasThreadSection(id2) {
|
|
139880
140639
|
return this.referenceThreadSections.some((section) => section.id === id2);
|
|
139881
140640
|
}
|
|
140641
|
+
sectionMemberIds() {
|
|
140642
|
+
return new Set(this.referenceThreadSections.flatMap(({ threadIds }) => threadIds));
|
|
140643
|
+
}
|
|
139882
140644
|
/**
|
|
139883
140645
|
* Publish native sections. Desktop's project members become the Workspaces of their root
|
|
139884
140646
|
* folders, so call this after the project roots are synced into Workspaces.
|
|
139885
140647
|
*/
|
|
139886
|
-
setReferenceThreadSections(sections, projects = [], sectionProjects = {}) {
|
|
139887
|
-
|
|
140648
|
+
setReferenceThreadSections(sections, projects = [], sectionProjects = {}, threadSectionsV1) {
|
|
140649
|
+
if (!sections) {
|
|
140650
|
+
this.officialThreadSectionsV1 = void 0, this.publishProjectSections();
|
|
140651
|
+
return;
|
|
140652
|
+
}
|
|
140653
|
+
let paths2 = this.nativeWorkspaces ? void 0 : sectionRootPaths(
|
|
139888
140654
|
projects,
|
|
139889
140655
|
sectionProjects,
|
|
139890
140656
|
sections.map((section) => section.id)
|
|
139891
140657
|
), next = sections.map((section) => {
|
|
139892
|
-
|
|
139893
|
-
let
|
|
139894
|
-
|
|
139895
|
-
|
|
139896
|
-
});
|
|
139897
|
-
return workspaceIds2.length > 0 ? { ...section, workspaceIds: workspaceIds2 } : { ...section };
|
|
139898
|
-
}
|
|
139899
|
-
let workspaceIds = (paths2.get(section.id) ?? []).flatMap((path7) => {
|
|
140658
|
+
let workspaceIds = this.nativeWorkspaces ? (sectionProjects[section.id] ?? []).flatMap((id2) => {
|
|
140659
|
+
let workspace = this.nativeWorkspaces?.find((item) => item.projectId === id2);
|
|
140660
|
+
return workspace ? [workspace.workspaceId] : [];
|
|
140661
|
+
}) : (paths2?.get(section.id) ?? []).flatMap((path7) => {
|
|
139900
140662
|
let workspace = this.byPath(path7);
|
|
139901
140663
|
return workspace ? [workspace.workspaceId] : [];
|
|
139902
140664
|
});
|
|
139903
140665
|
return workspaceIds.length > 0 ? { ...section, workspaceIds } : { ...section };
|
|
139904
|
-
}), saved = this.state.projectSectionOverrides, registered = this.nativeWorkspaces && new Set(this.nativeWorkspaces.map((item) => item.workspaceId))
|
|
140666
|
+
}), saved = this.state.projectSectionOverrides, registered = this.nativeWorkspaces && new Set(this.nativeWorkspaces.map((item) => item.workspaceId));
|
|
139905
140667
|
if (registered) {
|
|
139906
140668
|
let located = new Set(next.flatMap((section) => section.workspaceIds ?? []));
|
|
139907
140669
|
for (let section of next) {
|
|
139908
|
-
if (Object.hasOwn(sectionProjects, section.id))
|
|
139909
|
-
coverage.set(section.id, registered);
|
|
139910
|
-
continue;
|
|
139911
|
-
}
|
|
139912
|
-
let lastRead = this.projectSectionCoverage.get(section.id);
|
|
139913
|
-
lastRead && coverage.set(section.id, lastRead);
|
|
140670
|
+
if (Object.hasOwn(sectionProjects, section.id)) continue;
|
|
139914
140671
|
let previous = this.officialThreadSections?.find((item) => item.id === section.id)?.workspaceIds ?? [], anchors = Object.entries(saved ?? {}).flatMap(
|
|
139915
140672
|
([id2, placement]) => placement.official === section.id ? [id2] : []
|
|
139916
140673
|
), retained = [.../* @__PURE__ */ new Set([...previous, ...anchors])].filter(
|
|
@@ -139930,7 +140687,7 @@ var Workspaces = class {
|
|
|
139930
140687
|
);
|
|
139931
140688
|
Object.keys(valid2).length !== Object.keys(saved).length && this.saveProjectSections(valid2);
|
|
139932
140689
|
}
|
|
139933
|
-
this.officialThreadSections = next, this.
|
|
140690
|
+
this.officialThreadSections = next, this.referenceSectionWorkspaceIdsDirty = !1, this.officialThreadSectionsV1 = threadSectionsV1, this.publishProjectSections();
|
|
139934
140691
|
}
|
|
139935
140692
|
projectSection(sections, workspaceId) {
|
|
139936
140693
|
return sections.find((section) => section.workspaceIds?.includes(workspaceId))?.id ?? null;
|
|
@@ -139939,26 +140696,56 @@ var Workspaces = class {
|
|
|
139939
140696
|
let state2 = { ...this.state };
|
|
139940
140697
|
Object.keys(overrides).length ? state2.projectSectionOverrides = overrides : delete state2.projectSectionOverrides, this.data.writeJson(FILE2, state2), this.state = state2;
|
|
139941
140698
|
}
|
|
140699
|
+
/** A move cannot change definitions or project membership. */
|
|
140700
|
+
applyThreadSectionMove(sections, threadSectionsV1, movedId) {
|
|
140701
|
+
let current = this.officialThreadSections ?? [];
|
|
140702
|
+
if (this.referenceSectionWorkspaceIdsDirty || threadSectionsV1 !== this.officialThreadSectionsV1 || sections.length !== current.length || !sections.every((section, i) => {
|
|
140703
|
+
let previous = current[i];
|
|
140704
|
+
return previous?.id === section.id && previous.name === section.name && JSON.stringify(previous.appearance) === JSON.stringify(section.appearance);
|
|
140705
|
+
}))
|
|
140706
|
+
return !1;
|
|
140707
|
+
let remaining = /* @__PURE__ */ new Set();
|
|
140708
|
+
if (movedId !== void 0)
|
|
140709
|
+
for (let { threadIds } of current)
|
|
140710
|
+
for (let id2 of threadIds) id2 !== movedId && remaining.add(id2);
|
|
140711
|
+
let seen = /* @__PURE__ */ new Set();
|
|
140712
|
+
for (let { threadIds } of sections)
|
|
140713
|
+
for (let id2 of threadIds) {
|
|
140714
|
+
if (seen.has(id2) || movedId !== void 0 && id2 !== movedId && !remaining.delete(id2))
|
|
140715
|
+
return !1;
|
|
140716
|
+
seen.add(id2);
|
|
140717
|
+
}
|
|
140718
|
+
return remaining.size !== 0 ? !1 : (this.officialThreadSections = sections.map((section, i) => {
|
|
140719
|
+
let workspaceIds = current[i]?.workspaceIds;
|
|
140720
|
+
return workspaceIds === void 0 ? section : { ...section, workspaceIds };
|
|
140721
|
+
}), this.publishProjectSections(), !0);
|
|
140722
|
+
}
|
|
139942
140723
|
publishProjectSections() {
|
|
139943
140724
|
let official = this.officialThreadSections ?? [], overrides = this.nativeWorkspaces ? this.state.projectSectionOverrides : void 0, next = overrides ? official.map(({ workspaceIds, ...section }) => {
|
|
139944
140725
|
let ids = (workspaceIds ?? []).filter((id2) => !Object.hasOwn(overrides, id2));
|
|
139945
140726
|
for (let [id2, placement] of Object.entries(overrides))
|
|
139946
140727
|
placement.target === section.id && ids.push(id2);
|
|
139947
140728
|
return ids.length ? { ...section, workspaceIds: ids } : section;
|
|
139948
|
-
}) : official
|
|
139949
|
-
|
|
140729
|
+
}) : official, threadSectionsV1 = this.officialThreadSectionsV1, legacy2 = next.some((section) => section.appearance !== void 0) ? next.map((section) => {
|
|
140730
|
+
let legacySection = { ...section };
|
|
140731
|
+
return delete legacySection.appearance, legacySection;
|
|
140732
|
+
}) : next, projected = threadSectionsV1 ? next : legacy2;
|
|
140733
|
+
if (threadSectionsV1 === this.referenceThreadSectionsV1 && JSON.stringify(projected) === JSON.stringify(this.referenceThreadSections))
|
|
140734
|
+
return;
|
|
140735
|
+
let legacyChanged = JSON.stringify(legacy2) !== JSON.stringify(this.legacyThreadSections);
|
|
140736
|
+
this.referenceThreadSections = projected, this.referenceThreadSectionsV1 = threadSectionsV1, this.legacyThreadSections = legacy2, this.broadcast(
|
|
140737
|
+
{
|
|
140738
|
+
type: "threadSections",
|
|
140739
|
+
threadSections: projected,
|
|
140740
|
+
...threadSectionsV1 ? { [THREAD_SECTION_CAPABILITY]: !0 } : {}
|
|
140741
|
+
},
|
|
140742
|
+
!0
|
|
140743
|
+
), legacyChanged && this.broadcast({ type: "threadSections", threadSections: legacy2 }, !1);
|
|
139950
140744
|
}
|
|
139951
140745
|
moveWorkspaceToSection(workspaceId, sectionId) {
|
|
139952
140746
|
if (typeof workspaceId != "string" || !this.officialThreadSections || !this.nativeWorkspaces?.some((workspace) => workspace.workspaceId === workspaceId) || !(sectionId === null || typeof sectionId == "string" && this.hasThreadSection(sectionId)))
|
|
139953
140747
|
throw new SessionRuntimeError("workspace/section-invalid", "Unknown local project or sidebar section.");
|
|
139954
140748
|
let official = this.projectSection(this.officialThreadSections, workspaceId);
|
|
139955
|
-
if (official === null && !this.state.projectSectionOverrides?.[workspaceId] && this.officialThreadSections.some(
|
|
139956
|
-
(section) => !this.projectSectionCoverage.get(section.id)?.has(workspaceId)
|
|
139957
|
-
))
|
|
139958
|
-
throw new SessionRuntimeError(
|
|
139959
|
-
"workspace/section-invalid",
|
|
139960
|
-
"The project's current sidebar section is unknown. Refresh the sidebar and try again."
|
|
139961
|
-
);
|
|
139962
140749
|
if (this.projectSection(this.referenceThreadSections, workspaceId) !== sectionId) {
|
|
139963
140750
|
let overrides = Object.fromEntries(
|
|
139964
140751
|
Object.entries(this.state.projectSectionOverrides ?? {}).filter(
|
|
@@ -140092,10 +140879,80 @@ var Workspaces = class {
|
|
|
140092
140879
|
(item) => item.workspaceId === workspaceId
|
|
140093
140880
|
);
|
|
140094
140881
|
}
|
|
140882
|
+
harnessPreference(workspaceId) {
|
|
140883
|
+
this.require(workspaceId);
|
|
140884
|
+
let raw = this.harnessPreferencesRecord();
|
|
140885
|
+
return Object.hasOwn(raw, workspaceId) ? this.parseHarnessPreference(raw[workspaceId]) : { selection: { mode: "global" } };
|
|
140886
|
+
}
|
|
140887
|
+
setHarnessSelection(workspaceId, selection2) {
|
|
140888
|
+
let current = this.harnessPreference(workspaceId);
|
|
140889
|
+
this.saveHarnessPreference(workspaceId, { ...current, selection: selection2 });
|
|
140890
|
+
}
|
|
140891
|
+
rememberHarness(workspaceId, harnessId) {
|
|
140892
|
+
let current = this.harnessPreference(workspaceId);
|
|
140893
|
+
current.lastHarnessId !== harnessId && this.saveHarnessPreference(workspaceId, { ...current, lastHarnessId: harnessId });
|
|
140894
|
+
}
|
|
140895
|
+
removeHarnessPreference(workspaceId) {
|
|
140896
|
+
let existing = this.harnessPreferencesRecord();
|
|
140897
|
+
if (!Object.hasOwn(existing, workspaceId)) return;
|
|
140898
|
+
let preferences2 = Object.fromEntries(
|
|
140899
|
+
Object.entries(existing).filter(([id2]) => id2 !== workspaceId)
|
|
140900
|
+
);
|
|
140901
|
+
this.saveHarnessPreferences(preferences2);
|
|
140902
|
+
}
|
|
140903
|
+
harnessPreferencesRecord() {
|
|
140904
|
+
let raw = this.state.harnessPreferences;
|
|
140905
|
+
return !raw || typeof raw != "object" || Array.isArray(raw) ? {} : raw;
|
|
140906
|
+
}
|
|
140907
|
+
parseHarnessPreference(raw) {
|
|
140908
|
+
if (!raw || typeof raw != "object" || Array.isArray(raw))
|
|
140909
|
+
return { selection: { mode: "global" } };
|
|
140910
|
+
let record6 = raw, selection2 = projectHarnessSelectionSchema.safeParse(record6.selection);
|
|
140911
|
+
if (!selection2.success) return { selection: { mode: "global" } };
|
|
140912
|
+
let lastHarnessId = harnessIdSchema.safeParse(record6.lastHarnessId);
|
|
140913
|
+
return lastHarnessId.success ? { selection: selection2.data, lastHarnessId: String(lastHarnessId.data) } : { selection: selection2.data };
|
|
140914
|
+
}
|
|
140915
|
+
saveHarnessPreferences(preferences2) {
|
|
140916
|
+
let state2 = { ...this.state };
|
|
140917
|
+
Object.keys(preferences2).length > 0 ? state2.harnessPreferences = preferences2 : delete state2.harnessPreferences, this.data.writeJson(FILE2, state2), this.state = state2;
|
|
140918
|
+
}
|
|
140919
|
+
saveHarnessPreference(workspaceId, preference) {
|
|
140920
|
+
this.saveHarnessPreferences({ ...this.harnessPreferencesRecord(), [workspaceId]: preference });
|
|
140921
|
+
}
|
|
140922
|
+
byExactPath(path7) {
|
|
140923
|
+
if (this.nativeWorkspaces) {
|
|
140924
|
+
let multiRootMatch;
|
|
140925
|
+
for (let item of this.nativeWorkspaces) {
|
|
140926
|
+
if (!item.projectId) continue;
|
|
140927
|
+
let roots = this.nativeRoots.get(item.projectId);
|
|
140928
|
+
if (roots?.includes(path7)) {
|
|
140929
|
+
if (roots.length === 1) return item;
|
|
140930
|
+
multiRootMatch ??= item;
|
|
140931
|
+
}
|
|
140932
|
+
}
|
|
140933
|
+
return multiRootMatch;
|
|
140934
|
+
}
|
|
140935
|
+
return this.state.items.find((item) => item.path === path7);
|
|
140936
|
+
}
|
|
140095
140937
|
byPath(path7) {
|
|
140096
|
-
|
|
140097
|
-
(
|
|
140098
|
-
|
|
140938
|
+
if (this.nativeWorkspaces) {
|
|
140939
|
+
let key = desktopProjectPathKey(path7), owner = this.nativeRootOwners.get(key);
|
|
140940
|
+
if (owner) return this.byProjectId(owner.projectId);
|
|
140941
|
+
if (this.nativeRootOwners.size > 0) return;
|
|
140942
|
+
let fallback = nativeProjectRootOwners(
|
|
140943
|
+
this.nativeWorkspaces.flatMap(
|
|
140944
|
+
(item) => item.projectId ? [
|
|
140945
|
+
{
|
|
140946
|
+
id: item.projectId,
|
|
140947
|
+
name: item.title,
|
|
140948
|
+
rootPaths: this.nativeRoots.get(item.projectId) ?? []
|
|
140949
|
+
}
|
|
140950
|
+
] : []
|
|
140951
|
+
)
|
|
140952
|
+
).get(key);
|
|
140953
|
+
return fallback ? this.byProjectId(fallback.projectId) : void 0;
|
|
140954
|
+
}
|
|
140955
|
+
return this.state.items.find((item) => item.path === path7);
|
|
140099
140956
|
}
|
|
140100
140957
|
/**
|
|
140101
140958
|
* The folder whose Threads a local Workspace lists, without the folders of nested local
|
|
@@ -140119,6 +140976,10 @@ var Workspaces = class {
|
|
|
140119
140976
|
ownerOf(sessionId) {
|
|
140120
140977
|
return this.list().find((item) => item.sessionIds.includes(sessionId));
|
|
140121
140978
|
}
|
|
140979
|
+
/** The native-project Workspace of a Thread whose sidebar membership has not caught up. */
|
|
140980
|
+
byProjectId(projectId) {
|
|
140981
|
+
return projectId == null ? void 0 : this.nativeWorkspaces?.find((item) => item.projectId === projectId);
|
|
140982
|
+
}
|
|
140122
140983
|
isArchived(sessionId) {
|
|
140123
140984
|
return this.archivedSessionIds().includes(sessionId);
|
|
140124
140985
|
}
|
|
@@ -140156,7 +141017,7 @@ var Workspaces = class {
|
|
|
140156
141017
|
),
|
|
140157
141018
|
...displayOrder !== void 0 ? { displayOrder } : {}
|
|
140158
141019
|
};
|
|
140159
|
-
return this.data.writeJson(FILE2, state2), this.state = state2, this.broadcast({ type: "upsert", workspace }), this.broadcast({
|
|
141020
|
+
return this.data.writeJson(FILE2, state2), this.state = state2, this.referenceProjectRoots.has(absolute2) && (this.referenceSectionWorkspaceIdsDirty = !0), this.broadcast({ type: "upsert", workspace }), this.broadcast({
|
|
140160
141021
|
type: "order",
|
|
140161
141022
|
workspaceIds: this.list().map((item) => item.workspaceId)
|
|
140162
141023
|
}), { workspace, created: !0 };
|
|
@@ -140299,19 +141160,31 @@ var Workspaces = class {
|
|
|
140299
141160
|
let workspace = this.require(request3.workspaceId), {
|
|
140300
141161
|
displayOrder: currentDisplayOrder,
|
|
140301
141162
|
pinnedWorkspaceOverrides: currentPinnedOverrides,
|
|
141163
|
+
harnessPreferences: currentHarnessPreferences,
|
|
140302
141164
|
...stateWithoutOrderOrPins
|
|
140303
141165
|
} = this.state, nextDisplayOrder = currentDisplayOrder?.filter((id2) => id2 !== request3.workspaceId), nextPinnedOverrides = Object.fromEntries(
|
|
140304
141166
|
Object.entries(this.pinnedWorkspaceOverrides()).filter(
|
|
140305
141167
|
([id2]) => id2 !== request3.workspaceId
|
|
140306
141168
|
)
|
|
141169
|
+
), nextHarnessPreferences = Object.fromEntries(
|
|
141170
|
+
Object.entries(this.harnessPreferencesRecord()).filter(
|
|
141171
|
+
([id2]) => id2 !== request3.workspaceId
|
|
141172
|
+
)
|
|
140307
141173
|
), state2 = {
|
|
140308
141174
|
...stateWithoutOrderOrPins,
|
|
140309
141175
|
items: this.state.items.filter((item) => item.workspaceId !== request3.workspaceId),
|
|
140310
141176
|
deletedPaths: [...this.state.deletedPaths ?? [], workspace.path],
|
|
140311
141177
|
...nextDisplayOrder && nextDisplayOrder.length > 0 ? { displayOrder: nextDisplayOrder } : {},
|
|
140312
|
-
...Object.keys(nextPinnedOverrides).length > 0 ? { pinnedWorkspaceOverrides: nextPinnedOverrides } : {}
|
|
141178
|
+
...Object.keys(nextPinnedOverrides).length > 0 ? { pinnedWorkspaceOverrides: nextPinnedOverrides } : {},
|
|
141179
|
+
...Object.keys(nextHarnessPreferences).length > 0 ? { harnessPreferences: nextHarnessPreferences } : {}
|
|
140313
141180
|
};
|
|
140314
|
-
return this.data.writeJson(FILE2, state2), this.state = state2, this.broadcast({ type: "remove", workspaceId: request3.workspaceId }), this.publishPinnedWorkspaces(),
|
|
141181
|
+
return this.data.writeJson(FILE2, state2), this.state = state2, this.broadcast({ type: "remove", workspaceId: request3.workspaceId }), this.publishPinnedWorkspaces(), this.officialThreadSections?.some(
|
|
141182
|
+
({ workspaceIds }) => workspaceIds?.includes(workspace.workspaceId)
|
|
141183
|
+
) && (this.officialThreadSections = this.officialThreadSections.map((section) => {
|
|
141184
|
+
if (!section.workspaceIds?.includes(workspace.workspaceId)) return section;
|
|
141185
|
+
let { workspaceIds, ...rest } = section, remaining = workspaceIds.filter((id2) => id2 !== workspace.workspaceId);
|
|
141186
|
+
return remaining.length ? { ...rest, workspaceIds: remaining } : rest;
|
|
141187
|
+
}), this.publishProjectSections()), { deleted: !0 };
|
|
140315
141188
|
}), rpc2.register("workspace/moveWorkspaceToSection", async (args) => {
|
|
140316
141189
|
let request3 = requestOf(args);
|
|
140317
141190
|
return this.moveWorkspaceToSection(request3?.workspaceId, request3?.sectionId);
|
|
@@ -140349,14 +141222,16 @@ var Workspaces = class {
|
|
|
140349
141222
|
), rpc2.register("workspace/deleteSession", (args) => {
|
|
140350
141223
|
let sessionId = String(requestOf(args).sessionId ?? "");
|
|
140351
141224
|
return sessionId && this.forgetSession(sessionId), {};
|
|
140352
|
-
}), rpc2.register("workspace/pinSession", setMembership("pinnedSessionIds", "pinned", !0)), rpc2.register("workspace/unpinSession", setMembership("pinnedSessionIds", "pinned", !1)), streams2.register("workspace/follow", (
|
|
140353
|
-
|
|
141225
|
+
}), rpc2.register("workspace/pinSession", setMembership("pinnedSessionIds", "pinned", !0)), rpc2.register("workspace/unpinSession", setMembership("pinnedSessionIds", "pinned", !1)), streams2.register("workspace/follow", (args, sink) => {
|
|
141226
|
+
let capable = Object.hasOwn(args, THREAD_SECTION_CAPABILITY) && args[THREAD_SECTION_CAPABILITY] === !0;
|
|
141227
|
+
this.followers.set(sink, capable), sink.onClose(() => this.followers.delete(sink)), sink.push({
|
|
140354
141228
|
type: "baseline",
|
|
140355
141229
|
value: {
|
|
140356
141230
|
items: this.list(),
|
|
140357
141231
|
pinnedSessionIds: this.pinnedSessionIds(),
|
|
140358
141232
|
pinnedWorkspaceIds: this.pinnedWorkspaceIds(),
|
|
140359
|
-
threadSections: this.referenceThreadSections,
|
|
141233
|
+
threadSections: capable ? this.referenceThreadSections : this.legacyThreadSections,
|
|
141234
|
+
...capable && this.referenceThreadSectionsV1 ? { [THREAD_SECTION_CAPABILITY]: !0 } : {},
|
|
140360
141235
|
archivedSessionIds: this.archivedSessionIds(),
|
|
140361
141236
|
...this.referenceOnlyDefault ? { canStartProjectless: !0 } : {}
|
|
140362
141237
|
}
|
|
@@ -141015,13 +141890,15 @@ ${request3}`
|
|
|
141015
141890
|
|
|
141016
141891
|
// packages/web-server/src/file-references.ts
|
|
141017
141892
|
var WebFileReferences = class {
|
|
141018
|
-
constructor(workspace, remoteSearch) {
|
|
141893
|
+
constructor(workspace, remoteSearch, cache2) {
|
|
141019
141894
|
this.workspace = workspace;
|
|
141020
141895
|
this.remoteSearch = remoteSearch;
|
|
141896
|
+
this.cache = cache2 ?? new WorkspaceFileSearchCache(), this.ownsCache = cache2 === void 0;
|
|
141021
141897
|
}
|
|
141022
141898
|
workspace;
|
|
141023
141899
|
remoteSearch;
|
|
141024
|
-
cache
|
|
141900
|
+
cache;
|
|
141901
|
+
ownsCache;
|
|
141025
141902
|
lifetime = new AbortController();
|
|
141026
141903
|
setRemoteSearch(search) {
|
|
141027
141904
|
this.remoteSearch = search;
|
|
@@ -141047,7 +141924,7 @@ var WebFileReferences = class {
|
|
|
141047
141924
|
});
|
|
141048
141925
|
}
|
|
141049
141926
|
close() {
|
|
141050
|
-
this.lifetime.abort(), this.cache.close();
|
|
141927
|
+
this.lifetime.abort(), this.ownsCache && this.cache.close();
|
|
141051
141928
|
}
|
|
141052
141929
|
};
|
|
141053
141930
|
|
|
@@ -141265,7 +142142,7 @@ function globalProjectionValues(values2) {
|
|
|
141265
142142
|
);
|
|
141266
142143
|
}
|
|
141267
142144
|
var ChSessions = class {
|
|
141268
|
-
constructor(host, workspaces2, events2, images2, files2, displayEntries2, preferences2, harnesses, openFile) {
|
|
142145
|
+
constructor(host, workspaces2, events2, images2, files2, displayEntries2, preferences2, harnesses, openFile, fileSearchCache) {
|
|
141269
142146
|
this.host = host;
|
|
141270
142147
|
this.workspaces = workspaces2;
|
|
141271
142148
|
this.events = events2;
|
|
@@ -141273,7 +142150,11 @@ var ChSessions = class {
|
|
|
141273
142150
|
this.files = files2;
|
|
141274
142151
|
this.preferences = preferences2;
|
|
141275
142152
|
this.openFile = openFile;
|
|
141276
|
-
this.
|
|
142153
|
+
this.fileReferences = new WebFileReferences(
|
|
142154
|
+
(id2) => this.fileWorkspaceRoot(id2),
|
|
142155
|
+
void 0,
|
|
142156
|
+
fileSearchCache
|
|
142157
|
+
), this.nativeGoals = new ChNativeGoals(host), this.catalog = new ChHarnessCatalog(host, events2, displayEntries2, preferences2, harnesses), this.attachments = images2 ? new ChAttachments(images2, files2) : void 0, this.fileInputs = files2 && images2 ? new ChFileInputs(files2, images2, async (id2) => {
|
|
141277
142158
|
if (id2 = this.id(id2), this.closed) throw new SessionRuntimeError("host/offline", "The Web connection is closed.");
|
|
141278
142159
|
if (this.drafts.has(id2)) return id2;
|
|
141279
142160
|
await this.owner(id2), this.rows.has(id2) || await this.refresh();
|
|
@@ -141305,9 +142186,11 @@ var ChSessions = class {
|
|
|
141305
142186
|
let view = this.threads.view(id2);
|
|
141306
142187
|
view && this.loadUsage(view, !0);
|
|
141307
142188
|
},
|
|
141308
|
-
catalog: async () => {
|
|
141309
|
-
await this.
|
|
142189
|
+
catalog: async (_reason, requireSections) => {
|
|
142190
|
+
await this.refreshing?.catch(() => {
|
|
142191
|
+
}), await this.refresh(void 0, !1, void 0, void 0, requireSections);
|
|
141310
142192
|
},
|
|
142193
|
+
sections: () => this.refreshSectionMove(),
|
|
141311
142194
|
archived: (id2, archived) => {
|
|
141312
142195
|
this.archiveOperations.delete(id2), this.updateArchive(id2, archived);
|
|
141313
142196
|
},
|
|
@@ -141343,7 +142226,7 @@ var ChSessions = class {
|
|
|
141343
142226
|
files;
|
|
141344
142227
|
preferences;
|
|
141345
142228
|
openFile;
|
|
141346
|
-
fileReferences
|
|
142229
|
+
fileReferences;
|
|
141347
142230
|
catalog;
|
|
141348
142231
|
editing = new ChThreadEditing();
|
|
141349
142232
|
pins;
|
|
@@ -141351,7 +142234,6 @@ var ChSessions = class {
|
|
|
141351
142234
|
attachments;
|
|
141352
142235
|
fileInputs;
|
|
141353
142236
|
rows = /* @__PURE__ */ new Map();
|
|
141354
|
-
workspacePageRows = /* @__PURE__ */ new Set();
|
|
141355
142237
|
publishedCatalog;
|
|
141356
142238
|
handoffs = /* @__PURE__ */ new Map();
|
|
141357
142239
|
/** Loaded rows accumulate across partial official pages; drafts are not Host Threads. */
|
|
@@ -141359,11 +142241,13 @@ var ChSessions = class {
|
|
|
141359
142241
|
nativeGoals;
|
|
141360
142242
|
drafts = /* @__PURE__ */ new Map();
|
|
141361
142243
|
controls = /* @__PURE__ */ new Set();
|
|
142244
|
+
planChanges = /* @__PURE__ */ new Set();
|
|
141362
142245
|
refreshing;
|
|
141363
142246
|
refreshingCatalog = !1;
|
|
141364
142247
|
refreshingArchives = !1;
|
|
141365
142248
|
refreshingArchiveChanges;
|
|
141366
142249
|
refreshingDeletedIds;
|
|
142250
|
+
archiveRevision = 0;
|
|
141367
142251
|
refreshingProjectAssignments;
|
|
141368
142252
|
archiveOperations = /* @__PURE__ */ new Map();
|
|
141369
142253
|
queueOperations = /* @__PURE__ */ new Map();
|
|
@@ -141430,12 +142314,12 @@ var ChSessions = class {
|
|
|
141430
142314
|
row && (row.projectId = projectId);
|
|
141431
142315
|
}
|
|
141432
142316
|
/** A `scope` reads an explicit page on until it reaches a Thread of that folder. */
|
|
141433
|
-
async refresh(timing, includeArchived = !1, cursor, workspace) {
|
|
142317
|
+
async refresh(timing, includeArchived = !1, cursor, workspace, requireSections = !1, sectionSnapshot) {
|
|
141434
142318
|
if (this.closed) return;
|
|
141435
142319
|
if (this.refreshing && (cursor !== void 0 || !this.refreshingCatalog || includeArchived !== this.refreshingArchives)) {
|
|
141436
142320
|
let stage = this.refreshingCatalog ? "catalog_wait" : "workspace_wait", pending2 = this.refreshing.catch(() => {
|
|
141437
142321
|
});
|
|
141438
|
-
return await (timing ? timing.measure(stage, () => pending2) : pending2), this.refresh(timing, includeArchived, cursor, workspace);
|
|
142322
|
+
return await (timing ? timing.measure(stage, () => pending2) : pending2), this.refresh(timing, includeArchived, cursor, workspace, requireSections);
|
|
141439
142323
|
}
|
|
141440
142324
|
let mode = this.refreshing ? "joined" : "started";
|
|
141441
142325
|
if (!this.refreshing) {
|
|
@@ -141451,18 +142335,83 @@ var ChSessions = class {
|
|
|
141451
142335
|
deletedIds,
|
|
141452
142336
|
cursor,
|
|
141453
142337
|
workspace
|
|
141454
|
-
) : this.listAll(
|
|
142338
|
+
) : this.listAll(
|
|
142339
|
+
this.refreshingTiming,
|
|
142340
|
+
includeArchived,
|
|
142341
|
+
archiveChanges,
|
|
142342
|
+
deletedIds,
|
|
142343
|
+
cursor,
|
|
142344
|
+
sectionSnapshot
|
|
142345
|
+
);
|
|
141455
142346
|
this.refreshing = load2.finally(() => {
|
|
141456
142347
|
this.refreshing = void 0, this.refreshingCatalog = !1, this.refreshingArchives = !1, this.refreshingArchiveChanges = void 0, this.refreshingDeletedIds = void 0, this.refreshingProjectAssignments = void 0, this.refreshingTiming = void 0;
|
|
141457
142348
|
});
|
|
141458
142349
|
}
|
|
141459
142350
|
let pending = this.refreshing, catalogTiming = this.refreshingTiming;
|
|
141460
142351
|
try {
|
|
141461
|
-
|
|
142352
|
+
let result = await (timing ? timing.measure("catalog_wait", () => pending) : pending);
|
|
142353
|
+
if (requireSections && result?.sectionFailure) throw result.sectionFailure.error;
|
|
142354
|
+
return result;
|
|
141462
142355
|
} finally {
|
|
141463
142356
|
timing && catalogTiming && (timing.catalog = { mode, ...catalogTiming.snapshot() });
|
|
141464
142357
|
}
|
|
141465
142358
|
}
|
|
142359
|
+
/** An invalidation cannot join a catalog read that began before it. */
|
|
142360
|
+
async refreshAfterCurrent() {
|
|
142361
|
+
await this.refreshing?.catch(() => {
|
|
142362
|
+
}), await this.refresh();
|
|
142363
|
+
}
|
|
142364
|
+
async readThreadSections() {
|
|
142365
|
+
let snapshot = clientThreadSectionsSchema.parse(
|
|
142366
|
+
await this.host.request("codexhost/thread/sections/list", {
|
|
142367
|
+
[THREAD_SECTION_CAPABILITY]: !0,
|
|
142368
|
+
requireComplete: !0
|
|
142369
|
+
})
|
|
142370
|
+
);
|
|
142371
|
+
if (snapshot.complete === !1)
|
|
142372
|
+
throw new SessionRuntimeError("host/sections-incomplete", "Complete Thread sections are unavailable.");
|
|
142373
|
+
return snapshot;
|
|
142374
|
+
}
|
|
142375
|
+
async refreshSectionMove(move) {
|
|
142376
|
+
for (; this.refreshing; ) await this.refreshing.catch(() => {
|
|
142377
|
+
});
|
|
142378
|
+
if (this.closed) return;
|
|
142379
|
+
let archiveRevision = this.archiveRevision, read2 = this.readThreadSections();
|
|
142380
|
+
this.refreshing = read2.then(
|
|
142381
|
+
() => {
|
|
142382
|
+
},
|
|
142383
|
+
() => {
|
|
142384
|
+
}
|
|
142385
|
+
);
|
|
142386
|
+
let snapshot;
|
|
142387
|
+
try {
|
|
142388
|
+
if (snapshot = await read2, this.closed) return;
|
|
142389
|
+
if (this.archiveRevision !== archiveRevision) snapshot = void 0;
|
|
142390
|
+
else if (this.applySectionMove(snapshot, move)) return;
|
|
142391
|
+
} catch (error62) {
|
|
142392
|
+
if (error62 instanceof SessionRuntimeError && (error62.code === "host/method-unavailable" || "hostCode" in error62.details && error62.details.hostCode === -32601)) snapshot = null;
|
|
142393
|
+
else if (!move) throw error62;
|
|
142394
|
+
} finally {
|
|
142395
|
+
this.refreshing = void 0;
|
|
142396
|
+
}
|
|
142397
|
+
await this.refresh(void 0, !1, void 0, void 0, !move, snapshot);
|
|
142398
|
+
}
|
|
142399
|
+
applySectionMove(snapshot, move) {
|
|
142400
|
+
let archived = new Set(this.workspaces.localArchivedSessionIds()), sections = [], capability = snapshot[THREAD_SECTION_CAPABILITY], referenced = this.workspaces.sectionMemberIds(), destination = null;
|
|
142401
|
+
for (let { id: id2, name: name2, appearance, threads } of snapshot.sections) {
|
|
142402
|
+
let threadIds = [];
|
|
142403
|
+
for (let thread3 of threads)
|
|
142404
|
+
if (thread3.archived !== !0) {
|
|
142405
|
+
if (typeof thread3.id != "string" || archived.has(thread3.id) || !referenced.has(thread3.id) || !this.publishedCatalog?.has(thread3.id) || !this.threads.hasHarness(thread3.id))
|
|
142406
|
+
return !1;
|
|
142407
|
+
threadIds.push(thread3.id), thread3.id === move?.threadId && (destination = id2);
|
|
142408
|
+
}
|
|
142409
|
+
sections.push(
|
|
142410
|
+
capability && appearance !== void 0 ? { id: id2, name: name2, appearance, threadIds } : { id: id2, name: name2, threadIds }
|
|
142411
|
+
);
|
|
142412
|
+
}
|
|
142413
|
+
return (!move || destination === move.sectionId) && this.workspaces.applyThreadSectionMove(sections, capability, move?.threadId);
|
|
142414
|
+
}
|
|
141466
142415
|
refreshPins() {
|
|
141467
142416
|
return this.pins.refresh().catch((error62) => (console.error("[session/list] native pins unavailable", error62), this.workspaces.localPinnedSessionIds()));
|
|
141468
142417
|
}
|
|
@@ -141509,7 +142458,7 @@ var ChSessions = class {
|
|
|
141509
142458
|
continue;
|
|
141510
142459
|
}
|
|
141511
142460
|
let harnessId = ownership.get(id2);
|
|
141512
|
-
harnessId && (this.rows.
|
|
142461
|
+
harnessId && (this.rows.set(id2, row), this.threads.setHarness(id2, harnessId));
|
|
141513
142462
|
}
|
|
141514
142463
|
this.workspaces.addCatalogMembers(workspaceId, [...members2.keys()]);
|
|
141515
142464
|
let localArchives = new Set(this.workspaces.localArchivedSessionIds()), included = this.tree.withAncestors(members2.keys());
|
|
@@ -141530,36 +142479,46 @@ var ChSessions = class {
|
|
|
141530
142479
|
);
|
|
141531
142480
|
return { ...page, workspaceItems };
|
|
141532
142481
|
}
|
|
141533
|
-
async listAll(timing, includeArchived, archiveChanges, deletedIds, cursor) {
|
|
141534
|
-
let known = new Set(this.rows.keys()), [{ page: snapshot }, definitions, , sections] = await Promise.all([
|
|
142482
|
+
async listAll(timing, includeArchived, archiveChanges, deletedIds, cursor, sectionSnapshot) {
|
|
142483
|
+
let known = new Set(this.rows.keys()), sectionFailure, sectionsUnsupported = !1, [{ page: snapshot }, definitions, , sections] = await Promise.all([
|
|
141535
142484
|
readSessionPage(this.host, timing, includeArchived, cursor, () => this.refreshPins()),
|
|
141536
142485
|
timing.measure("project_definitions", () => this.host.projects([])),
|
|
141537
142486
|
timing.measure("thread_tree", () => this.tree.refresh()),
|
|
141538
142487
|
timing.measure("thread_sections", async () => {
|
|
142488
|
+
if (sectionSnapshot === null) {
|
|
142489
|
+
sectionsUnsupported = !0;
|
|
142490
|
+
return;
|
|
142491
|
+
}
|
|
141539
142492
|
try {
|
|
141540
|
-
return
|
|
141541
|
-
|
|
141542
|
-
)
|
|
141543
|
-
} catch {
|
|
142493
|
+
return sectionSnapshot ?? await this.readThreadSections();
|
|
142494
|
+
} catch (error62) {
|
|
142495
|
+
sectionsUnsupported = error62 instanceof SessionRuntimeError && (error62.code === "host/method-unavailable" || "hostCode" in error62.details && error62.details.hostCode === -32601), sectionsUnsupported || (sectionFailure = { error: error62 });
|
|
141544
142496
|
return;
|
|
141545
142497
|
}
|
|
141546
142498
|
})
|
|
141547
142499
|
]);
|
|
141548
142500
|
if (this.closed) return;
|
|
141549
|
-
let found = new Map(snapshot.threads.map((row) => [row.id, row])), snapshotArchives = new Set(snapshot.archivedThreadIds), archivedIds = new Set(this.workspaces.localArchivedSessionIds());
|
|
142501
|
+
let found = new Map(snapshot.threads.map((row) => [row.id, row])), headIds = cursor === void 0 && !includeArchived ? this.tree.withAncestors(found.keys()) : null, snapshotArchives = new Set(snapshot.archivedThreadIds), archivedIds = new Set(this.workspaces.localArchivedSessionIds());
|
|
141550
142502
|
for (let id2 of snapshotArchives) archivedIds.add(id2);
|
|
141551
142503
|
for (let id2 of found.keys()) snapshotArchives.has(id2) || archivedIds.delete(id2);
|
|
141552
|
-
let ownership = catalogOwnership(snapshot, found),
|
|
142504
|
+
let ownership = catalogOwnership(snapshot, found), threadSectionsV1 = sections?.[THREAD_SECTION_CAPABILITY], threadSections = sections?.sections.map(({ id: id2, name: name2, appearance, threads }) => {
|
|
141553
142505
|
let threadIds = [];
|
|
141554
|
-
for (let thread3 of threads)
|
|
141555
|
-
|
|
141556
|
-
|
|
142506
|
+
for (let thread3 of threads) {
|
|
142507
|
+
let threadId = thread3.id;
|
|
142508
|
+
if (!(typeof threadId != "string" || thread3.archived === !0)) {
|
|
142509
|
+
if (found.has(threadId)) {
|
|
142510
|
+
if (!ownership.has(threadId)) continue;
|
|
142511
|
+
} else if (thread3.modelProvider === "codexhost") {
|
|
142512
|
+
let harnessId = cursor === void 0 ? void 0 : this.threads.harnessId(threadId);
|
|
142513
|
+
if (!harnessId || harnessId === "codex") continue;
|
|
142514
|
+
} else {
|
|
141557
142515
|
let row = thread3;
|
|
141558
|
-
found.set(
|
|
142516
|
+
found.set(threadId, row), ownership.set(threadId, "codex");
|
|
141559
142517
|
}
|
|
141560
|
-
|
|
142518
|
+
thread3.archived === !1 && !snapshotArchives.has(threadId) && archivedIds.delete(threadId), threadIds.push(threadId);
|
|
141561
142519
|
}
|
|
141562
|
-
|
|
142520
|
+
}
|
|
142521
|
+
return threadSectionsV1 && appearance !== void 0 ? { id: id2, name: name2, threadIds, appearance } : { id: id2, name: name2, threadIds };
|
|
141563
142522
|
});
|
|
141564
142523
|
timing.count("ownershipIds", ownership.size), timing.count(
|
|
141565
142524
|
"archivedRows",
|
|
@@ -141577,8 +142536,6 @@ var ChSessions = class {
|
|
|
141577
142536
|
let { thread: thread3, harnessId } = await this.readThread(id2);
|
|
141578
142537
|
return ownership.set(id2, harnessId), thread3.archived === !0 && archivedIds.add(id2), thread3;
|
|
141579
142538
|
});
|
|
141580
|
-
for (let id2 of deletedIds)
|
|
141581
|
-
rows.delete(id2), ownership.delete(id2), archivedIds.delete(id2);
|
|
141582
142539
|
let assignments = await timing.measure(
|
|
141583
142540
|
"projects",
|
|
141584
142541
|
() => this.host.projects([...rows.keys()])
|
|
@@ -141587,28 +142544,48 @@ var ChSessions = class {
|
|
|
141587
142544
|
projects: definitions.projects,
|
|
141588
142545
|
...pinnedProjects !== void 0 ? { pinnedProjects } : {}
|
|
141589
142546
|
};
|
|
141590
|
-
if (
|
|
141591
|
-
|
|
141592
|
-
|
|
141593
|
-
|
|
141594
|
-
|
|
141595
|
-
|
|
141596
|
-
|
|
141597
|
-
|
|
141598
|
-
|
|
141599
|
-
|
|
141600
|
-
|
|
141601
|
-
|
|
141602
|
-
|
|
141603
|
-
|
|
141604
|
-
timing
|
|
141605
|
-
|
|
141606
|
-
|
|
141607
|
-
|
|
141608
|
-
|
|
141609
|
-
|
|
141610
|
-
|
|
142547
|
+
if (this.closed) return;
|
|
142548
|
+
for (let id2 of deletedIds)
|
|
142549
|
+
rows.delete(id2), ownership.delete(id2), archivedIds.delete(id2);
|
|
142550
|
+
for (let [id2, projectId] of this.refreshingProjectAssignments ?? []) {
|
|
142551
|
+
let row = rows.get(id2);
|
|
142552
|
+
row && (row.projectId = projectId);
|
|
142553
|
+
}
|
|
142554
|
+
if (this.threads.replaceHarnesses(ownership), this.rows = rows, this.host.realtime && this.hostOnline && !this.closed && this.syncBackgroundRunningInteractions(), timing.count("visibleRows", rows.size), await this.syncWorkspace(timing, projects), this.closed) return;
|
|
142555
|
+
let projectedSections = threadSections && (!this.workspaces.usesNativeProjects || projects.nativeProjects) ? threadSections : void 0, before = this.publishedCatalog, sectionIds = projectedSections ? new Set(projectedSections.flatMap(({ threadIds }) => threadIds)) : this.workspaces.sectionMemberIds();
|
|
142556
|
+
if (!projectedSections)
|
|
142557
|
+
for (let id2 of sectionIds) before?.has(id2) || sectionIds.delete(id2);
|
|
142558
|
+
if (await timing.measure(
|
|
142559
|
+
"catalog_publish",
|
|
142560
|
+
() => this.publishCatalogChanges(
|
|
142561
|
+
timing,
|
|
142562
|
+
headIds,
|
|
142563
|
+
sectionIds,
|
|
142564
|
+
archivedIds,
|
|
142565
|
+
archiveChanges,
|
|
142566
|
+
deletedIds
|
|
142567
|
+
)
|
|
142568
|
+
), this.closed) return;
|
|
142569
|
+
if (projectedSections) {
|
|
142570
|
+
let archived = new Set(this.workspaces.localArchivedSessionIds());
|
|
142571
|
+
this.workspaces.setReferenceThreadSections(
|
|
142572
|
+
projectedSections.map((section) => ({
|
|
142573
|
+
...section,
|
|
142574
|
+
threadIds: section.threadIds.filter(
|
|
142575
|
+
(id2) => !archived.has(id2) && !deletedIds.has(id2) && this.publishedCatalog?.has(id2)
|
|
142576
|
+
)
|
|
142577
|
+
})),
|
|
142578
|
+
definitions.projects,
|
|
142579
|
+
definitions.sectionProjects,
|
|
142580
|
+
threadSectionsV1
|
|
142581
|
+
);
|
|
142582
|
+
} else (sectionsUnsupported || threadSections && !threadSectionsV1) && this.workspaces.setReferenceThreadSections(void 0);
|
|
142583
|
+
let pageIds = new Set(snapshot.threads.map(({ id: id2 }) => id2));
|
|
142584
|
+
for (let id2 of sectionIds) {
|
|
142585
|
+
let row = rows.get(id2);
|
|
142586
|
+
row && this.publishedCatalog?.has(id2) && (cursor === void 0 || !before?.has(id2)) && !pageIds.has(id2) && snapshot.threads.push(row);
|
|
141611
142587
|
}
|
|
142588
|
+
return this.catalogReadAt = Date.now(), { ...snapshot, sectionFailure };
|
|
141612
142589
|
}
|
|
141613
142590
|
async syncWorkspace(timing = new SessionListTiming(), snapshot) {
|
|
141614
142591
|
let projects = snapshot ?? await timing.measure("projects", () => this.host.projects([...this.rows.keys()]));
|
|
@@ -141679,33 +142656,51 @@ var ChSessions = class {
|
|
|
141679
142656
|
codexhostImportSource: row.codexhostImportSource ?? null
|
|
141680
142657
|
};
|
|
141681
142658
|
}
|
|
141682
|
-
async publishCatalogChanges(
|
|
141683
|
-
let before = this.publishedCatalog, next = new Map(
|
|
141684
|
-
|
|
141685
|
-
|
|
141686
|
-
|
|
141687
|
-
|
|
141688
|
-
|
|
141689
|
-
|
|
141690
|
-
|
|
141691
|
-
|
|
141692
|
-
let
|
|
141693
|
-
|
|
141694
|
-
|
|
141695
|
-
|
|
141696
|
-
|
|
141697
|
-
|
|
141698
|
-
|
|
141699
|
-
|
|
141700
|
-
|
|
142659
|
+
async publishCatalogChanges(timing, headIds, sectionIds, archivedIds, archiveChanges, deletedIds) {
|
|
142660
|
+
let before = this.publishedCatalog, next = /* @__PURE__ */ new Map(), changed = [];
|
|
142661
|
+
for (let row of this.rows.values()) {
|
|
142662
|
+
let priorKey = before?.get(row.id), sectionMember = sectionIds.has(row.id);
|
|
142663
|
+
if (!sectionMember) {
|
|
142664
|
+
if (headIds === null) {
|
|
142665
|
+
if (priorKey === void 0) continue;
|
|
142666
|
+
} else if (!headIds.has(row.id))
|
|
142667
|
+
continue;
|
|
142668
|
+
}
|
|
142669
|
+
let key = this.catalogKey(row);
|
|
142670
|
+
next.set(row.id, key), priorKey !== key && (before || sectionMember) && changed.push(row);
|
|
142671
|
+
}
|
|
142672
|
+
let summaries = await Promise.all(changed.map((row) => this.summary(row)));
|
|
142673
|
+
if (!this.closed) {
|
|
142674
|
+
for (let [id2, archived] of archiveChanges)
|
|
142675
|
+
archived ? archivedIds.add(id2) : archivedIds.delete(id2);
|
|
142676
|
+
for (let id2 of deletedIds)
|
|
142677
|
+
archivedIds.delete(id2), next.delete(id2);
|
|
142678
|
+
for (let id2 of archivedIds) next.delete(id2);
|
|
142679
|
+
timing.measureSync(
|
|
142680
|
+
"archive_sync",
|
|
142681
|
+
() => this.workspaces.setReferenceArchives([...archivedIds].sort())
|
|
142682
|
+
), this.publishedCatalog = next;
|
|
142683
|
+
for (let [id2, row] of this.rows) {
|
|
142684
|
+
let log46 = this.threads.view(id2)?.log;
|
|
142685
|
+
if (log46)
|
|
141701
142686
|
for (let [key, value] of Object.entries(this.catalogProjections(row)))
|
|
141702
|
-
|
|
141703
|
-
sink.push({ type: "projection", sessionId, key, value, seq: seq2 });
|
|
142687
|
+
log46.setProjection(key, value);
|
|
141704
142688
|
}
|
|
141705
|
-
|
|
141706
|
-
|
|
141707
|
-
|
|
141708
|
-
|
|
142689
|
+
if (this.controls.size > 0)
|
|
142690
|
+
for (let { sessionId } of summaries) {
|
|
142691
|
+
if (!next.has(sessionId)) continue;
|
|
142692
|
+
let row = this.rows.get(sessionId), seq2 = row ? this.threads.reserveDroppedProjectionSeq(sessionId) : void 0;
|
|
142693
|
+
if (!(!row || seq2 === void 0))
|
|
142694
|
+
for (let [key, value] of Object.entries(this.catalogProjections(row)))
|
|
142695
|
+
for (let sink of this.controls)
|
|
142696
|
+
sink.push({ type: "projection", sessionId, key, value, seq: seq2 });
|
|
142697
|
+
}
|
|
142698
|
+
for (let row of summaries)
|
|
142699
|
+
next.has(row.sessionId) && this.events.emit("api-session/added", row);
|
|
142700
|
+
if (before)
|
|
142701
|
+
for (let id2 of before.keys())
|
|
142702
|
+
this.rows.has(id2) || (this.handoffs.delete(id2), this.events.emit("api-session/removed", id2));
|
|
142703
|
+
}
|
|
141709
142704
|
}
|
|
141710
142705
|
async owner(id2) {
|
|
141711
142706
|
let resolved = this.id(id2);
|
|
@@ -141786,13 +142781,20 @@ var ChSessions = class {
|
|
|
141786
142781
|
}
|
|
141787
142782
|
if (this.threads.view(id2) !== view)
|
|
141788
142783
|
throw new SessionRuntimeError("host/resync", "Host snapshot was superseded by a new generation");
|
|
141789
|
-
view.log.setProjection(
|
|
142784
|
+
if (view.log.setProjection(
|
|
141790
142785
|
"archiveForkParent",
|
|
141791
142786
|
this.archiveForkParent(this.rows.get(id2) ?? view.thread)
|
|
141792
142787
|
), view.log.setProjection(
|
|
141793
142788
|
"nativeDiscovery",
|
|
141794
142789
|
!view.thread.parentThreadId && view.thread.canAcceptDirectInput !== !1
|
|
141795
|
-
), view.ownerSnapshot ? (this.handoffs.set(id2, view.ownerSnapshot.handoff ?? null), view.log.setProjection(WEB_HANDOFF_PROJECTION, view.ownerSnapshot.handoff ?? null)) : this.handoffs.has(id2) && view.log.setProjection(WEB_HANDOFF_PROJECTION, this.handoffs.get(id2) ?? null),
|
|
142790
|
+
), view.ownerSnapshot ? (this.handoffs.set(id2, view.ownerSnapshot.handoff ?? null), view.log.setProjection(WEB_HANDOFF_PROJECTION, view.ownerSnapshot.handoff ?? null)) : this.handoffs.has(id2) && view.log.setProjection(WEB_HANDOFF_PROJECTION, this.handoffs.get(id2) ?? null), (this.threads.get(id2)?.configurationRevision ?? 0) === configurationRevision) {
|
|
142791
|
+
let mode = view.ownerSnapshot?.configuration.codexCollaborationMode;
|
|
142792
|
+
this.projectCodexPlanMode(
|
|
142793
|
+
view,
|
|
142794
|
+
harnessId === "codex" && !view.thread.parentThreadId && view.thread.canAcceptDirectInput !== !1 && mode !== void 0 ? mode === "plan" : null
|
|
142795
|
+
);
|
|
142796
|
+
}
|
|
142797
|
+
view.ownerSnapshot && this.hostOnline && !this.closed && (this.syncedRunningInteractions.add(id2), this.interactions?.update(view.ownerSnapshot)), this.realtime && view.log.setProjection("nativeConnection", {
|
|
141796
142798
|
state: this.hostOnline ? "connected" : "reconnecting"
|
|
141797
142799
|
}), this.threads.ensure(id2).historyReadAt = Date.now();
|
|
141798
142800
|
let name2 = await this.catalog.name(harnessId);
|
|
@@ -141897,8 +142899,56 @@ var ChSessions = class {
|
|
|
141897
142899
|
projections: { kind: "cached", asOfSeq: 0, values: values2 }
|
|
141898
142900
|
};
|
|
141899
142901
|
}
|
|
142902
|
+
async supportsCodexPlanMode() {
|
|
142903
|
+
if (!this.realtime) return !1;
|
|
142904
|
+
let result = await this.host.request("collaborationMode/list", {}).catch(() => {
|
|
142905
|
+
});
|
|
142906
|
+
return Array.isArray(result?.data) && result.data.some((entry) => entry?.mode === "plan") && result.data.some((entry) => entry?.mode === "default");
|
|
142907
|
+
}
|
|
142908
|
+
codexPlanSelection(sessionId) {
|
|
142909
|
+
let draft = this.drafts.get(sessionId);
|
|
142910
|
+
if (draft && !draft.canonicalId)
|
|
142911
|
+
return draft.selection.provider === "codex" ? draft.codexPlanMode === !0 : void 0;
|
|
142912
|
+
let projected = this.threads.view(this.id(sessionId))?.log.projections.codexPlanMode;
|
|
142913
|
+
return typeof projected == "boolean" ? projected : void 0;
|
|
142914
|
+
}
|
|
142915
|
+
projectCodexPlanMode(view, active3) {
|
|
142916
|
+
let previous = view.log.projections.codexPlanMode;
|
|
142917
|
+
view.log.setProjection("codexPlanMode", active3), previous !== void 0 && typeof previous == "boolean" != (active3 !== null) && this.events.emit("commands/change", view.thread.id);
|
|
142918
|
+
}
|
|
142919
|
+
async selectCodexPlanMode(id2, active3) {
|
|
142920
|
+
let mode = active3 ? "plan" : "default";
|
|
142921
|
+
if (this.planChanges.has(id2))
|
|
142922
|
+
throw new SessionRuntimeError("session/busy", "Codex is already changing plan mode.");
|
|
142923
|
+
this.planChanges.add(id2);
|
|
142924
|
+
let epoch = this.hostEpoch;
|
|
142925
|
+
try {
|
|
142926
|
+
let confirmed = await this.host.request(
|
|
142927
|
+
"codexhost/thread/collaboration-mode/select",
|
|
142928
|
+
{ threadId: id2, mode }
|
|
142929
|
+
);
|
|
142930
|
+
if (this.closed || epoch !== this.hostEpoch || confirmed?.mode !== mode)
|
|
142931
|
+
throw new SessionRuntimeError(
|
|
142932
|
+
"session/plan-unconfirmed",
|
|
142933
|
+
"Codex did not confirm the mode. Refresh the conversation."
|
|
142934
|
+
);
|
|
142935
|
+
let state2 = this.threads.ensure(id2);
|
|
142936
|
+
state2.configurationRevision = (state2.configurationRevision ?? 0) + 1, state2.view && this.projectCodexPlanMode(state2.view, active3);
|
|
142937
|
+
} finally {
|
|
142938
|
+
this.planChanges.delete(id2), this.realtime?.invalidate(id2);
|
|
142939
|
+
}
|
|
142940
|
+
}
|
|
141900
142941
|
async draftSummary(draft, includeControls = !0) {
|
|
141901
|
-
let
|
|
142942
|
+
let controls;
|
|
142943
|
+
do {
|
|
142944
|
+
let provider = draft.selection.provider, [inspection2, supportsPlan2, name3] = await Promise.all([
|
|
142945
|
+
includeControls ? this.catalog.inspect(provider, draft.cwd) : void 0,
|
|
142946
|
+
includeControls && provider === "codex" ? this.supportsCodexPlanMode() : !1,
|
|
142947
|
+
this.catalog.name(provider)
|
|
142948
|
+
]);
|
|
142949
|
+
controls = { provider, inspection: inspection2, supportsPlan: supportsPlan2, name: name3 };
|
|
142950
|
+
} while (controls.provider !== draft.selection.provider);
|
|
142951
|
+
let { inspection, supportsPlan, name: name2 } = controls;
|
|
141902
142952
|
return {
|
|
141903
142953
|
sessionId: draft.id,
|
|
141904
142954
|
cwd: draft.cwd,
|
|
@@ -141916,11 +142966,12 @@ var ChSessions = class {
|
|
|
141916
142966
|
attachmentInput: this.files ? WEB_FILE_INPUT : WEB_IMAGE_INPUT,
|
|
141917
142967
|
imageLimits: WEB_IMAGE_LIMITS
|
|
141918
142968
|
} : {},
|
|
141919
|
-
modelSelection: { lastUsed: null, next: draft.selection }
|
|
142969
|
+
modelSelection: { lastUsed: null, next: draft.selection },
|
|
142970
|
+
codexPlanMode: draft.selection.provider === "codex" && supportsPlan ? draft.codexPlanMode === !0 : null
|
|
141920
142971
|
} : {},
|
|
141921
142972
|
harnessIdentity: {
|
|
141922
142973
|
id: draft.selection.provider,
|
|
141923
|
-
name:
|
|
142974
|
+
name: name2
|
|
141924
142975
|
},
|
|
141925
142976
|
...inspection ? {
|
|
141926
142977
|
nativePermissions: nativePermissionView(
|
|
@@ -141937,16 +142988,36 @@ var ChSessions = class {
|
|
|
141937
142988
|
};
|
|
141938
142989
|
}
|
|
141939
142990
|
async create(args, configuration) {
|
|
141940
|
-
let request3 = requestOf(args), workspace = request3.workspaceId ? this.workspaces.get(request3.workspaceId) : void 0, cwd = request3.cwd ?? workspace?.path, projectId = workspace?.projectId ?? (cwd && this.workspaces.usesNativeProjects ? this.workspaces.
|
|
142991
|
+
let request3 = requestOf(args), workspace = request3.workspaceId ? this.workspaces.get(request3.workspaceId) : void 0, cwd = request3.cwd ?? workspace?.path, byCwd = cwd ? this.workspaces.byPath(resolve19(cwd)) : void 0, projectId = workspace?.projectId ?? (cwd && this.workspaces.usesNativeProjects ? byCwd?.projectId : void 0), project2 = workspace ?? byCwd, projectHarnessId2 = !configuration && project2 ? projectHarnessId(this.workspaces, project2.workspaceId) : void 0;
|
|
141941
142992
|
if ((request3.workspaceId !== void 0 || request3.cwd !== void 0) && !cwd)
|
|
141942
142993
|
throw new SessionRuntimeError("workspace/invalid-path", "Choose a valid computer working directory.");
|
|
141943
142994
|
let id2 = request3.sessionId ?? `draft-${randomUUID23()}`, existing = this.drafts.get(id2);
|
|
141944
|
-
if (existing && !existing.canonicalId && !existing.creating && !existing.started && existing.cwd === cwd && existing.projectId === projectId)
|
|
142995
|
+
if (existing && !existing.canonicalId && !existing.creating && !existing.started && existing.cwd === cwd && existing.projectId === projectId) {
|
|
142996
|
+
if (!configuration && request3.matchProjectDefault) {
|
|
142997
|
+
if (existing.projectHarnessId !== projectHarnessId2)
|
|
142998
|
+
throw new SessionRuntimeError("session/writer-held", "Start a new draft with the project default.", {
|
|
142999
|
+
sessionId: id2
|
|
143000
|
+
});
|
|
143001
|
+
if (projectHarnessId2 !== void 0) {
|
|
143002
|
+
let preferences3 = this.preferences?.get().catch(() => {
|
|
143003
|
+
}), expected = (await this.catalog.models(!1, void 0, preferences3, projectHarnessId2)).default;
|
|
143004
|
+
if (this.closed) throw new SessionRuntimeError("session/closed", "Web sessions are closing.");
|
|
143005
|
+
if (this.drafts.get(id2) !== existing || existing.canonicalId || existing.creating || existing.started)
|
|
143006
|
+
throw new SessionRuntimeError("session/busy", "This Session already exists; start a new draft.");
|
|
143007
|
+
if ((project2 ? projectHarnessId(this.workspaces, project2.workspaceId) : void 0) !== projectHarnessId2 || existing.selection.provider !== expected?.provider)
|
|
143008
|
+
throw new SessionRuntimeError(
|
|
143009
|
+
"session/writer-held",
|
|
143010
|
+
"Start a new draft with the project default.",
|
|
143011
|
+
{ sessionId: id2 }
|
|
143012
|
+
);
|
|
143013
|
+
}
|
|
143014
|
+
}
|
|
141945
143015
|
return { sessionId: id2, agentPreset: "standard" };
|
|
143016
|
+
}
|
|
141946
143017
|
if (existing || this.rows.has(id2))
|
|
141947
143018
|
throw new SessionRuntimeError("session/busy", "This Session already exists; start a new draft.");
|
|
141948
143019
|
let preferences2 = configuration ? void 0 : this.preferences?.get().catch(() => {
|
|
141949
|
-
}), selection2 = configuration?.selection ?? (await this.catalog.models(!1, void 0, preferences2)).default;
|
|
143020
|
+
}), selection2 = configuration?.selection ?? (await this.catalog.models(!1, void 0, preferences2, projectHarnessId2)).default;
|
|
141950
143021
|
if (!selection2)
|
|
141951
143022
|
throw new SessionRuntimeError(
|
|
141952
143023
|
"host/no-harness",
|
|
@@ -141956,6 +143027,7 @@ var ChSessions = class {
|
|
|
141956
143027
|
id: id2,
|
|
141957
143028
|
...cwd ? { cwd } : {},
|
|
141958
143029
|
...projectId ? { projectId } : {},
|
|
143030
|
+
...projectHarnessId2 ? { projectHarnessId: projectHarnessId2 } : {},
|
|
141959
143031
|
selection: selection2,
|
|
141960
143032
|
createdAt: Date.now()
|
|
141961
143033
|
};
|
|
@@ -142038,7 +143110,7 @@ var ChSessions = class {
|
|
|
142038
143110
|
);
|
|
142039
143111
|
thread3.projectId = updated.thread.projectId, this.refreshingProjectAssignments?.set(thread3.id, draft.projectId);
|
|
142040
143112
|
}
|
|
142041
|
-
return draft.canonicalId = thread3.id, this.files?.bind(draft.id, thread3.id), this.rows.set(thread3.id, thread3), this.threads.setHarness(thread3.id, harnessId), this.workspaces.detachSession(draft.id), this.workspaces.usesNativeProjects ? this.workspaces.updateNativeProjectMember(thread3.id, draft.projectId) : draft.cwd ? (this.workspaces.selectReferenceWorkspace(draft.cwd), this.workspaces.attachReferencedSession(thread3.id, thread3.cwd), this.workspaces.addDraftReference(thread3.id, draft.cwd)) : this.workspaces.addDraftReference(thread3.id, void 0), this.events.emit("api-session/added", await this.summary(thread3)), this.publishedCatalog?.set(thread3.id, this.catalogKey(thread3)), this.events.emit("codexhost/session-bound", draft.id, thread3.id), this.events.emit("api-session/removed", draft.id), thread3.id;
|
|
143113
|
+
return draft.codexPlanMode !== void 0 && (await this.selectCodexPlanMode(thread3.id, draft.codexPlanMode), delete draft.codexPlanMode), draft.canonicalId = thread3.id, this.files?.bind(draft.id, thread3.id), this.rows.set(thread3.id, thread3), this.threads.setHarness(thread3.id, harnessId), this.workspaces.detachSession(draft.id), this.workspaces.usesNativeProjects ? this.workspaces.updateNativeProjectMember(thread3.id, draft.projectId) : draft.cwd ? (this.workspaces.selectReferenceWorkspace(draft.cwd), this.workspaces.attachReferencedSession(thread3.id, thread3.cwd), this.workspaces.addDraftReference(thread3.id, draft.cwd)) : this.workspaces.addDraftReference(thread3.id, void 0), this.events.emit("api-session/added", await this.summary(thread3)), this.workspaces.isArchived(thread3.id) || this.publishedCatalog?.set(thread3.id, this.catalogKey(thread3)), this.events.emit("codexhost/session-bound", draft.id, thread3.id), this.events.emit("api-session/removed", draft.id), thread3.id;
|
|
142042
143114
|
}
|
|
142043
143115
|
/**
|
|
142044
143116
|
* Working directory of one Host-confirmed local Thread.
|
|
@@ -142147,7 +143219,7 @@ var ChSessions = class {
|
|
|
142147
143219
|
forgetDeleted(id2) {
|
|
142148
143220
|
this.refreshingDeletedIds?.add(id2), this.archiveOperations.delete(id2), this.queueOperations.delete(id2), this.titleRequests.delete(id2), this.syncedRunningInteractions.delete(id2);
|
|
142149
143221
|
let activeRead = this.interactionReads.get(id2);
|
|
142150
|
-
activeRead && (activeRead.cancelled = !0, activeRead.dirty = !1, this.interactionReads.delete(id2)), this.interactions?.clearSession(id2), this.
|
|
143222
|
+
activeRead && (activeRead.cancelled = !0, activeRead.dirty = !1, this.interactionReads.delete(id2)), this.interactions?.clearSession(id2), this.rows.delete(id2), this.handoffs.delete(id2), this.threads.delete(id2), this.tree.forget(id2);
|
|
142151
143223
|
let archived = this.workspaces.localArchivedSessionIds();
|
|
142152
143224
|
archived.includes(id2) && this.workspaces.setReferenceArchives(archived.filter((item) => item !== id2));
|
|
142153
143225
|
let pinned = this.workspaces.localPinnedSessionIds();
|
|
@@ -142164,9 +143236,9 @@ var ChSessions = class {
|
|
|
142164
143236
|
});
|
|
142165
143237
|
}
|
|
142166
143238
|
updateArchive(id2, archived) {
|
|
142167
|
-
this.refreshingArchiveChanges?.set(id2, archived);
|
|
143239
|
+
this.archiveRevision++, this.refreshingArchiveChanges?.set(id2, archived);
|
|
142168
143240
|
let ids = new Set(this.workspaces.localArchivedSessionIds());
|
|
142169
|
-
archived ? ids.add(id2) : ids.delete(id2), this.workspaces.setReferenceArchives([...ids].sort());
|
|
143241
|
+
archived ? (ids.add(id2), this.publishedCatalog?.delete(id2)) : ids.delete(id2), this.workspaces.setReferenceArchives([...ids].sort());
|
|
142170
143242
|
}
|
|
142171
143243
|
async setArchived(sessionId, archived) {
|
|
142172
143244
|
let id2 = this.id(sessionId), operation = /* @__PURE__ */ Symbol();
|
|
@@ -142255,21 +143327,49 @@ var ChSessions = class {
|
|
|
142255
143327
|
return await this.pins.sync({ threadId: id2, pinned }), await this.refresh().catch(() => {
|
|
142256
143328
|
}), { pinnedSessionIds: this.workspaces.pinnedSessionIds() };
|
|
142257
143329
|
});
|
|
143330
|
+
for (let [method2, mutation] of [
|
|
143331
|
+
["workspace/createThreadSection", CLIENT_THREAD_SECTION_MUTATIONS.create],
|
|
143332
|
+
["workspace/updateThreadSection", CLIENT_THREAD_SECTION_MUTATIONS.update],
|
|
143333
|
+
["workspace/deleteThreadSection", CLIENT_THREAD_SECTION_MUTATIONS.delete]
|
|
143334
|
+
])
|
|
143335
|
+
rpc2.register(method2, async (args) => {
|
|
143336
|
+
let params = mutation.params.safeParse(requestOf(args));
|
|
143337
|
+
if (!params.success)
|
|
143338
|
+
throw new SessionRuntimeError("workspace/section-invalid", "Invalid Thread section request.");
|
|
143339
|
+
let value = await this.host.request(mutation.method, params.data).catch((error62) => {
|
|
143340
|
+
if (error62 instanceof SessionRuntimeError) {
|
|
143341
|
+
let { code, details } = error62, hostCode = "hostCode" in details ? details.hostCode : void 0;
|
|
143342
|
+
if (code === "host/disconnected" || code === "host/resync" || code === "remote/offline" || code === "host/rejected" && (hostCode === -32093 || hostCode === -32094))
|
|
143343
|
+
return { status: "unknown" };
|
|
143344
|
+
}
|
|
143345
|
+
throw error62;
|
|
143346
|
+
}), result = clientThreadSectionMutationResultSchema.safeParse(value);
|
|
143347
|
+
return await this.refreshAfterCurrent().catch(() => {
|
|
143348
|
+
}), result.success ? result.data : { status: "unknown" };
|
|
143349
|
+
});
|
|
142258
143350
|
rpc2.register("workspace/moveSessionToSection", async (args) => {
|
|
142259
143351
|
let input3 = requestOf(args), move = clientThreadSectionMoveSchema.safeParse({
|
|
142260
143352
|
threadId: input3.sessionId,
|
|
142261
|
-
sectionId: input3.sectionId
|
|
143353
|
+
sectionId: input3.sectionId,
|
|
143354
|
+
beforeThreadId: input3.beforeSessionId,
|
|
143355
|
+
expectedSourceSectionId: input3.expectedSourceSectionId
|
|
142262
143356
|
});
|
|
142263
143357
|
if (!move.success)
|
|
142264
143358
|
throw new SessionRuntimeError("workspace/section-invalid", "Invalid Thread section move.");
|
|
142265
|
-
let {
|
|
142266
|
-
if (
|
|
143359
|
+
let { sectionId, beforeThreadId, expectedSourceSectionId } = move.data, id2 = this.id(move.data.threadId), before = typeof beforeThreadId == "string" ? this.id(beforeThreadId) : beforeThreadId;
|
|
143360
|
+
if (typeof before == "string" && (sectionId === null || before === id2))
|
|
143361
|
+
throw new SessionRuntimeError("workspace/section-invalid", "Invalid Thread section anchor.");
|
|
143362
|
+
if (this.drafts.has(id2) || !this.threads.hasHarness(id2) || this.rows.get(id2)?.parentThreadId || this.workspaces.isArchived(id2) || this.workspaces.pinnedSessionIds().includes(id2) || sectionId !== null && !this.workspaces.hasThreadSection(sectionId))
|
|
142267
143363
|
throw new SessionRuntimeError(
|
|
142268
143364
|
"workspace/section-unavailable",
|
|
142269
143365
|
"This Thread or section is unavailable for a move."
|
|
142270
143366
|
);
|
|
142271
|
-
return await this.host.request("codexhost/thread/sections/move",
|
|
142272
|
-
|
|
143367
|
+
return await this.host.request("codexhost/thread/sections/move", {
|
|
143368
|
+
threadId: id2,
|
|
143369
|
+
sectionId,
|
|
143370
|
+
...before === void 0 ? {} : { beforeThreadId: before },
|
|
143371
|
+
...expectedSourceSectionId === void 0 ? {} : { expectedSourceSectionId }
|
|
143372
|
+
}), await this.refreshSectionMove({ threadId: id2, sectionId }).catch(() => {
|
|
142273
143373
|
}), { sectionId };
|
|
142274
143374
|
}), rpc2.register("session/list", async (args, context) => {
|
|
142275
143375
|
let {
|
|
@@ -142343,7 +143443,7 @@ var ChSessions = class {
|
|
|
142343
143443
|
archivedSessionIds,
|
|
142344
143444
|
nextCursor: page ? nextCatalogCursor(page, includeArchived) : null
|
|
142345
143445
|
};
|
|
142346
|
-
}), rpc2.register("session/create", (args) => this.create(args)), rpc2.register("session/fork", async (args) => {
|
|
143446
|
+
}), rpc2.register("session/create", (args) => this.create(args)), registerProjectHarnessDefault(rpc2, this.workspaces, this.catalog), rpc2.register("session/fork", async (args) => {
|
|
142347
143447
|
let request3 = requestOf(args);
|
|
142348
143448
|
if (typeof request3.sessionId != "string" || !request3.sessionId || request3.atSeq !== void 0 && (!Number.isSafeInteger(request3.atSeq) || request3.atSeq < 0))
|
|
142349
143449
|
throw new SessionRuntimeError("session/fork-invalid", "Invalid fork request.");
|
|
@@ -142399,9 +143499,9 @@ var ChSessions = class {
|
|
|
142399
143499
|
inspection,
|
|
142400
143500
|
config2?.permissionModeId
|
|
142401
143501
|
);
|
|
142402
|
-
delete draft.permissionModeId, permissionModeId && (draft.permissionModeId = permissionModeId);
|
|
143502
|
+
delete draft.codexPlanMode, delete draft.permissionModeId, permissionModeId && (draft.permissionModeId = permissionModeId);
|
|
142403
143503
|
}
|
|
142404
|
-
draft.selection = request3, await this.preferences?.remember(request3.provider, {
|
|
143504
|
+
draft.selection = request3, before.provider !== request3.provider && this.events.emit("commands/change"), await this.preferences?.remember(request3.provider, {
|
|
142405
143505
|
model: model2,
|
|
142406
143506
|
thinkingOptionId: request3.reasoningEffort,
|
|
142407
143507
|
permissionModeId: draft.permissionModeId
|
|
@@ -142471,6 +143571,8 @@ var ChSessions = class {
|
|
|
142471
143571
|
"goal/command-required",
|
|
142472
143572
|
"Submit /goal as a command on a local Codex Thread with native goals enabled."
|
|
142473
143573
|
);
|
|
143574
|
+
if (this.planChanges.has(this.id(request3.sessionId)))
|
|
143575
|
+
throw new SessionRuntimeError("session/busy", "Wait for Codex to confirm plan mode before sending.");
|
|
142474
143576
|
let existingOwner = !draft || draft.canonicalId ? await this.owner(request3.sessionId) : void 0, steerTurnId;
|
|
142475
143577
|
if (request3.mode === "steer") {
|
|
142476
143578
|
let view = existingOwner && await this.view(request3.sessionId, !0), activeTurnId = view ? view.log.projections[WEB_ACTIVE_TURN_PROJECTION] : null;
|
|
@@ -142493,7 +143595,9 @@ var ChSessions = class {
|
|
|
142493
143595
|
request3.content.filter((part) => part.type === "text").map((part) => part.text ?? "").join(`
|
|
142494
143596
|
`)
|
|
142495
143597
|
) : this.id(request3.sessionId), owner = existingOwner ?? await this.owner(threadId);
|
|
142496
|
-
if (
|
|
143598
|
+
if (this.planChanges.has(threadId))
|
|
143599
|
+
throw new SessionRuntimeError("session/busy", "Wait for Codex to confirm plan mode before sending.");
|
|
143600
|
+
steerTurnId ? await this.host.request("turn/steer", {
|
|
142497
143601
|
threadId,
|
|
142498
143602
|
expectedTurnId: steerTurnId,
|
|
142499
143603
|
input: input3,
|
|
@@ -142504,16 +143608,27 @@ var ChSessions = class {
|
|
|
142504
143608
|
input: input3,
|
|
142505
143609
|
...request3.mode === "queue" ? { delivery: "queue", presentationInput: presentation2 } : {},
|
|
142506
143610
|
...request3.requestId ? { clientUserMessageId: request3.requestId } : {}
|
|
142507
|
-
})
|
|
143611
|
+
});
|
|
143612
|
+
let row = this.rows.get(threadId), confirmedProjectId = row?.projectId, project2 = row?.workspaceKind === "projectless" ? void 0 : (this.workspaces.usesNativeProjects && confirmedProjectId ? this.workspaces.byProjectId(confirmedProjectId) : void 0) ?? this.workspaces.ownerOf(threadId);
|
|
143613
|
+
if (project2)
|
|
143614
|
+
try {
|
|
143615
|
+
this.workspaces.rememberHarness(project2.workspaceId, owner.harnessId);
|
|
143616
|
+
} catch {
|
|
143617
|
+
this.events.emit(
|
|
143618
|
+
"codexhost/preferences-error",
|
|
143619
|
+
"The project's last Harness could not be saved."
|
|
143620
|
+
);
|
|
143621
|
+
}
|
|
143622
|
+
if (draft && !draft.titleRequested) {
|
|
142508
143623
|
draft.titleRequested = !0;
|
|
142509
|
-
let
|
|
142510
|
-
if (
|
|
143624
|
+
let row2 = this.rows.get(threadId);
|
|
143625
|
+
if (row2) {
|
|
142511
143626
|
this.titleRequests.add(threadId);
|
|
142512
143627
|
let prompt = request3.content.filter((part) => part.type === "text").map((part) => part.text ?? "").join(`
|
|
142513
143628
|
`);
|
|
142514
143629
|
tryGenerateThreadTitle(
|
|
142515
143630
|
this.host,
|
|
142516
|
-
|
|
143631
|
+
row2,
|
|
142517
143632
|
prompt,
|
|
142518
143633
|
owner.owner === "external",
|
|
142519
143634
|
() => !this.closed && this.titleRequests.has(threadId)
|
|
@@ -142867,23 +143982,61 @@ var ChSessions = class {
|
|
|
142867
143982
|
defaultOptions: [],
|
|
142868
143983
|
defaultPreset: ""
|
|
142869
143984
|
})), rpc2.register("commands/list", async (args) => {
|
|
142870
|
-
let id2 = String(args.agentId ?? "");
|
|
143985
|
+
let id2 = String(args.agentId ?? ""), commands = this.codexPlanSelection(id2) !== void 0 && !this.closed && this.hostOnline && await this.supportsCodexPlanMode() && this.codexPlanSelection(id2) !== void 0 ? [permissionCommand, codexPlanCommand] : [permissionCommand];
|
|
142871
143986
|
try {
|
|
142872
143987
|
let scope2 = await this.goalScope(id2);
|
|
142873
143988
|
if (scope2 === "draft" && await this.supportsDraftGoals() && await this.goalScope(id2) === "draft")
|
|
142874
|
-
return [
|
|
143989
|
+
return [...commands, goalCommand];
|
|
142875
143990
|
if (scope2 === "local" && nativeCodexGoalResultSchema.safeParse(
|
|
142876
143991
|
await this.host.request(NATIVE_CODEX_GOAL_METHOD, {
|
|
142877
143992
|
threadId: this.id(id2),
|
|
142878
143993
|
action: "get"
|
|
142879
143994
|
})
|
|
142880
143995
|
).success)
|
|
142881
|
-
return [
|
|
143996
|
+
return [...commands, goalCommand];
|
|
142882
143997
|
} catch {
|
|
142883
143998
|
}
|
|
142884
|
-
return
|
|
143999
|
+
return commands;
|
|
142885
144000
|
}), rpc2.register("commands/execute", async (args) => {
|
|
142886
|
-
let id2 = String(args.agentId ?? ""), line = String(args.line ?? "").trim();
|
|
144001
|
+
let id2 = String(args.agentId ?? ""), line = String(args.line ?? "").trim(), draft = this.drafts.get(id2), plan = /^\/plan(?:\s+([\s\S]*))?$/u.exec(line.trim());
|
|
144002
|
+
if (plan) {
|
|
144003
|
+
let threadId = this.id(id2), unboundDraft = draft && !draft.canonicalId ? draft : void 0, current = this.codexPlanSelection(id2);
|
|
144004
|
+
if (current === void 0) return;
|
|
144005
|
+
if (Array.isArray(args.submittedAttachments) && args.submittedAttachments.length > 0)
|
|
144006
|
+
throw new SessionRuntimeError("session/plan-attachments", "Remove attachments before using /plan.");
|
|
144007
|
+
if (!this.realtime || this.closed || !this.hostOnline)
|
|
144008
|
+
throw new SessionRuntimeError(
|
|
144009
|
+
"session/plan-unavailable",
|
|
144010
|
+
"The native Codex connection is unavailable."
|
|
144011
|
+
);
|
|
144012
|
+
let action = plan[1];
|
|
144013
|
+
if (action !== void 0 && action !== "on" && action !== "off")
|
|
144014
|
+
throw new SessionRuntimeError("session/plan-argument", "Use /plan, /plan on, or /plan off.");
|
|
144015
|
+
if (unboundDraft) {
|
|
144016
|
+
if (!await this.supportsCodexPlanMode())
|
|
144017
|
+
throw new SessionRuntimeError(
|
|
144018
|
+
"session/plan-unavailable",
|
|
144019
|
+
"This Codex version does not support plan mode."
|
|
144020
|
+
);
|
|
144021
|
+
if (this.drafts.get(id2) !== unboundDraft || this.closed || !this.hostOnline || unboundDraft.creating || unboundDraft.canonicalId || unboundDraft.selection.provider !== "codex")
|
|
144022
|
+
throw new SessionRuntimeError("session/busy", "Draft selection changed.");
|
|
144023
|
+
let active3 = action === void 0 ? !unboundDraft.codexPlanMode : action === "on";
|
|
144024
|
+
unboundDraft.codexPlanMode = active3;
|
|
144025
|
+
for (let sink of this.controls)
|
|
144026
|
+
sink.push({
|
|
144027
|
+
type: "projection",
|
|
144028
|
+
sessionId: id2,
|
|
144029
|
+
key: "codexPlanMode",
|
|
144030
|
+
value: active3,
|
|
144031
|
+
seq: 0
|
|
144032
|
+
});
|
|
144033
|
+
} else
|
|
144034
|
+
await this.selectCodexPlanMode(
|
|
144035
|
+
threadId,
|
|
144036
|
+
action === void 0 ? !current : action === "on"
|
|
144037
|
+
);
|
|
144038
|
+
return { commandId: randomUUID23(), result: { kind: "success" } };
|
|
144039
|
+
}
|
|
142887
144040
|
if (nativeCodexGoalInvocation.test(line)) {
|
|
142888
144041
|
let scope2 = await this.goalScope(id2);
|
|
142889
144042
|
if (scope2 === "other") return;
|
|
@@ -142930,7 +144083,7 @@ var ChSessions = class {
|
|
|
142930
144083
|
}
|
|
142931
144084
|
let match = /^\/permission\s+(.+)$/u.exec(line);
|
|
142932
144085
|
if (!match) return;
|
|
142933
|
-
let modeId = match[1] ?? "",
|
|
144086
|
+
let modeId = match[1] ?? "", harnessId = draft && !draft.canonicalId ? draft.selection.provider : (await this.owner(id2)).harnessId, inspection = await this.catalog.inspect(
|
|
142934
144087
|
harnessId,
|
|
142935
144088
|
draft?.cwd ?? this.rows.get(this.id(id2))?.cwd
|
|
142936
144089
|
), mode = inspection.status === "ready" ? inspection.permissionModes?.modes.find((value) => value.id === modeId) : void 0;
|
|
@@ -143164,10 +144317,12 @@ var WebHarnessPreferences = class {
|
|
|
143164
144317
|
await this.patch([operation]), await this.patch([{ kind: "newThread", lastHarness: id2 }]);
|
|
143165
144318
|
}
|
|
143166
144319
|
async decorate(catalog, snapshot = this.get().catch(() => {
|
|
143167
|
-
})) {
|
|
144320
|
+
}), projectHarnessId2) {
|
|
143168
144321
|
let external = await snapshot;
|
|
143169
144322
|
if (external) {
|
|
143170
|
-
let favorites = external.values.favorites, configurationFor = (harnessId) => external.values.newThread?.byHarness[harnessId], preferred = catalog.groups.find(
|
|
144323
|
+
let favorites = external.values.favorites, configurationFor = (harnessId) => external.values.newThread?.byHarness[harnessId], preferred = catalog.groups.find(
|
|
144324
|
+
(group) => group.id === (projectHarnessId2 ?? external.values.newThread?.lastHarness)
|
|
144325
|
+
) ?? catalog.groups.find((group) => group.id === catalog.default.provider), selectionFor = (group, fallbackModelId) => {
|
|
143171
144326
|
let configuration = configurationFor(group.id), modelRef = configuration?.model, model2 = (
|
|
143172
144327
|
// A remembered speed variant restores its base Model.
|
|
143173
144328
|
group.models.find(
|
|
@@ -143250,6 +144405,9 @@ var exec3 = promisify7(execFile6), METHODS = /* @__PURE__ */ new Set([
|
|
|
143250
144405
|
"codexhost/thread/pins/list",
|
|
143251
144406
|
"codexhost/thread/sections/list",
|
|
143252
144407
|
"codexhost/thread/sections/move",
|
|
144408
|
+
CLIENT_THREAD_SECTION_MUTATIONS.create.method,
|
|
144409
|
+
CLIENT_THREAD_SECTION_MUTATIONS.update.method,
|
|
144410
|
+
CLIENT_THREAD_SECTION_MUTATIONS.delete.method,
|
|
143253
144411
|
"codexhost/thread/pins/set",
|
|
143254
144412
|
"codexhost/harness/display-settings/get",
|
|
143255
144413
|
"codexhost/harness/display-settings/set",
|
|
@@ -143502,7 +144660,7 @@ async function serveChClientGateway(host, request3, response, { authenticated =
|
|
|
143502
144660
|
let after = url2.searchParams.has("epoch") ? clientChannelCursorSchema.parse({
|
|
143503
144661
|
epoch: url2.searchParams.get("epoch"),
|
|
143504
144662
|
sequence: Number(url2.searchParams.get("after"))
|
|
143505
|
-
}) : void 0, stop = channel.subscribe((event) => {
|
|
144663
|
+
}) : void 0, supportsSections = url2.searchParams.get(THREAD_SECTION_CAPABILITY) === "1", stop = channel.subscribe((event) => {
|
|
143506
144664
|
if (event.type === "connection") {
|
|
143507
144665
|
!event.online && !response.writableEnded && !response.destroyed && (response.headersSent ? response.end() : response.writeHead(503, {
|
|
143508
144666
|
"content-type": "application/json; charset=utf-8",
|
|
@@ -143510,17 +144668,17 @@ async function serveChClientGateway(host, request3, response, { authenticated =
|
|
|
143510
144668
|
}).end(JSON.stringify({ error: { code: -32090, message: "CH is reconnecting" } })));
|
|
143511
144669
|
return;
|
|
143512
144670
|
}
|
|
143513
|
-
if (
|
|
143514
|
-
|
|
143515
|
-
|
|
143516
|
-
|
|
143517
|
-
|
|
143518
|
-
|
|
143519
|
-
|
|
143520
|
-
}
|
|
143521
|
-
response.write(JSON.stringify(event) + `
|
|
143522
|
-
`);
|
|
144671
|
+
if (response.destroyed || response.writableEnded) return;
|
|
144672
|
+
if (response.headersSent || response.writeHead(200, {
|
|
144673
|
+
"content-type": "application/x-ndjson",
|
|
144674
|
+
"cache-control": "no-store"
|
|
144675
|
+
}), response.writableLength > 256 * 1024) {
|
|
144676
|
+
response.destroy();
|
|
144677
|
+
return;
|
|
143523
144678
|
}
|
|
144679
|
+
let frame = event.type === "sections-changed" && !supportsSections ? { type: "hello", version: 1, cursor: event.cursor, reset: !0 } : event;
|
|
144680
|
+
response.write(JSON.stringify(frame) + `
|
|
144681
|
+
`);
|
|
143524
144682
|
}, after), heartbeat = setInterval(() => {
|
|
143525
144683
|
response.headersSent && !response.writableEnded && response.write(`
|
|
143526
144684
|
`);
|
|
@@ -144712,7 +145870,7 @@ function nativeProjectCommands(host, workspaces2, refresh, assignSession) {
|
|
|
144712
145870
|
throw new SessionRuntimeError("workspace/invalid-path", "Choose an existing absolute folder.", {
|
|
144713
145871
|
path: path7
|
|
144714
145872
|
});
|
|
144715
|
-
let absolute2 = resolve23(expanded), existing = workspaces2.
|
|
145873
|
+
let absolute2 = resolve23(expanded), existing = workspaces2.byExactPath(absolute2);
|
|
144716
145874
|
if (existing) return { workspace: existing, created: !1 };
|
|
144717
145875
|
let { project: project2 } = await host.request("project/create", {
|
|
144718
145876
|
name: basename14(absolute2) || absolute2,
|
|
@@ -144741,7 +145899,7 @@ function nativeProjectCommands(host, workspaces2, refresh, assignSession) {
|
|
|
144741
145899
|
"workspace/refresh-failed",
|
|
144742
145900
|
"Codex confirmed the removal. Refresh the project list."
|
|
144743
145901
|
);
|
|
144744
|
-
return workspaces2.removeFromDisplayOrder(workspaceId), workspaces2.removePinnedWorkspaceOverride(workspaceId), { deleted: !0 };
|
|
145902
|
+
return workspaces2.removeFromDisplayOrder(workspaceId), workspaces2.removePinnedWorkspaceOverride(workspaceId), workspaces2.removeHarnessPreference(workspaceId), { deleted: !0 };
|
|
144745
145903
|
}),
|
|
144746
145904
|
insertBefore: (workspaceId, beforeWorkspaceId) => mutate(async () => {
|
|
144747
145905
|
if (!(workspaces2.isRemote(workspaceId) || beforeWorkspaceId !== void 0 && workspaces2.isRemote(beforeWorkspaceId)))
|
|
@@ -144939,7 +146097,7 @@ async function snapshotPackagedHost(distribution, data2) {
|
|
|
144939
146097
|
|
|
144940
146098
|
// packages/web-server/src/main.ts
|
|
144941
146099
|
var RELEASE_WEB = !0, DISTRIBUTION_ROOT = resolve25(import.meta.dirname, ".."), PACKED_WEB = join36(DISTRIBUTION_ROOT, "web"), PACKED = existsSync16(join36(PACKED_WEB, "plugins.json")), REPO_ROOT = resolve25(import.meta.dirname, "../../.."), SERVER_VERSION = resolveServerVersion(
|
|
144942
|
-
"0.
|
|
146100
|
+
"0.32.0",
|
|
144943
146101
|
[join36(DISTRIBUTION_ROOT, "package.json"), join36(REPO_ROOT, "package.json")]
|
|
144944
146102
|
);
|
|
144945
146103
|
if (PACKED) {
|
|
@@ -145032,7 +146190,7 @@ var publicUrl = background ? background.publicUrl : values["public-url"] ?? proc
|
|
|
145032
146190
|
chHost,
|
|
145033
146191
|
displayDirectory,
|
|
145034
146192
|
events
|
|
145035
|
-
), preferences = new WebHarnessPreferences(chHost, events), images = new WebImages(data), files = new WebFiles(data, images), sessions = new ChSessions(
|
|
146193
|
+
), preferences = new WebHarnessPreferences(chHost, events), images = new WebImages(data), files = new WebFiles(data, images), sharedWorkspaceSearchCache = new WorkspaceFileSearchCache(), sessions = new ChSessions(
|
|
145036
146194
|
chHost,
|
|
145037
146195
|
workspaces,
|
|
145038
146196
|
events,
|
|
@@ -145041,7 +146199,8 @@ var publicUrl = background ? background.publicUrl : values["public-url"] ?? proc
|
|
|
145041
146199
|
displayEntries,
|
|
145042
146200
|
preferences,
|
|
145043
146201
|
enabledHarnesses,
|
|
145044
|
-
(path7, action) => openWorkspaceFile(launcher, path7, action)
|
|
146202
|
+
(path7, action) => openWorkspaceFile(launcher, path7, action),
|
|
146203
|
+
sharedWorkspaceSearchCache
|
|
145045
146204
|
), dsh = await DshWebServices.open({
|
|
145046
146205
|
workspaceRoot: resolve25(values.workspace),
|
|
145047
146206
|
threadWorkspace: (id2) => sessions.terminalWorkspaceRoot(id2),
|
|
@@ -145076,7 +146235,7 @@ var broadcastNotification = (message2) => {
|
|
|
145076
146235
|
plugins: CLIENT_PLUGINS,
|
|
145077
146236
|
globals: { ...CLIENT_GLOBALS, __CODEXHOST_DEV_WEB_UI__: devWebUi !== void 0 },
|
|
145078
146237
|
title: "CodexHost"
|
|
145079
|
-
}, builtInAssets = new WebAssets(assetOptions),
|
|
146238
|
+
}, builtInAssets = values["safe-mode"] ? void 0 : new WebAssets(assetOptions), cachedRecoveryAssets, getRecoveryAssets = () => cachedRecoveryAssets ??= new WebAssets({
|
|
145080
146239
|
...assetOptions,
|
|
145081
146240
|
plugins: CLIENT_PLUGINS.filter((id2) => id2 !== HMR_CLIENT_PLUGIN)
|
|
145082
146241
|
}), extensions2 = new WebUiExtensions(data, {
|
|
@@ -145090,7 +146249,7 @@ var broadcastNotification = (message2) => {
|
|
|
145090
146249
|
}
|
|
145091
146250
|
});
|
|
145092
146251
|
await extensions2.cleanup();
|
|
145093
|
-
var assets = values["safe-mode"] ?
|
|
146252
|
+
var assets = values["safe-mode"] ? getRecoveryAssets() : builtInAssets, pluginRuntime, listeningPort = Number(values.port);
|
|
145094
146253
|
if (!values["safe-mode"])
|
|
145095
146254
|
try {
|
|
145096
146255
|
if (dsh === void 0) throw new Error("The DSH Web backend is unavailable");
|
|
@@ -145119,7 +146278,9 @@ if (!values["safe-mode"])
|
|
|
145119
146278
|
SIDEBAR_BROWSER_PATH
|
|
145120
146279
|
].map((path7) => ({ kind: "exact", path: path7 }))
|
|
145121
146280
|
]
|
|
145122
|
-
}), assets = new WebAssets({ ...assetOptions, clients: pluginRuntime.clients }),
|
|
146281
|
+
}), assets = new WebAssets({ ...assetOptions, clients: pluginRuntime.clients }), builtInAssets = void 0;
|
|
146282
|
+
let savedExternalPlugins = extensions2.plugins();
|
|
146283
|
+
savedExternalPlugins.length > 0 && new WebAssets({ ...assetOptions, externalPlugins: savedExternalPlugins }), await extensions2.restore();
|
|
145123
146284
|
} catch (error62) {
|
|
145124
146285
|
extensions2.composed(
|
|
145125
146286
|
[],
|
|
@@ -145218,7 +146379,7 @@ peerManager.onPeerRemoved = (hostId2) => {
|
|
|
145218
146379
|
workspaces.removeRemoteHostOrder(hostId2);
|
|
145219
146380
|
};
|
|
145220
146381
|
remoteSessions.install(rpc, streams);
|
|
145221
|
-
var remoteWorkspaceFiles = new RemotePeerWorkspaceFiles(remoteSessions)
|
|
146382
|
+
var remoteWorkspaceFiles = new RemotePeerWorkspaceFiles(remoteSessions);
|
|
145222
146383
|
sessions.setRemoteFileSearch(
|
|
145223
146384
|
(sessionId, query, signal) => remoteWorkspaceFiles.searchFiles(sessionId, query, signal)
|
|
145224
146385
|
);
|
|
@@ -145429,7 +146590,7 @@ var server = createWebServer((request3, response) => {
|
|
|
145429
146590
|
await servePeerWorkspaceFiles(request3, response, peerRoute === "workspace-files/rpc" ? "rpc" : peerRoute === "workspace-files/download" ? "download" : "search", {
|
|
145430
146591
|
resolveWorkspaceRoot: (threadId, signal) => sessions.ensureLocalWorkspaceRoot(threadId, signal),
|
|
145431
146592
|
...dsh ? { dsh } : {},
|
|
145432
|
-
searchCache:
|
|
146593
|
+
searchCache: sharedWorkspaceSearchCache
|
|
145433
146594
|
});
|
|
145434
146595
|
return;
|
|
145435
146596
|
}
|
|
@@ -145561,17 +146722,13 @@ var server = createWebServer((request3, response) => {
|
|
|
145561
146722
|
return;
|
|
145562
146723
|
}
|
|
145563
146724
|
if (pathname === "/" || pathname === "/index.html") {
|
|
145564
|
-
|
|
145565
|
-
|
|
145566
|
-
|
|
145567
|
-
|
|
145568
|
-
|
|
145569
|
-
|
|
145570
|
-
|
|
145571
|
-
String(index.body).replace("<head>", `<head>${SWITCH_TOKEN_SCRIPT}`)
|
|
145572
|
-
)
|
|
145573
|
-
}
|
|
145574
|
-
);
|
|
146725
|
+
await sendShellIndex(request3, response, {
|
|
146726
|
+
url: url2,
|
|
146727
|
+
assets,
|
|
146728
|
+
recoveryAssets: { index: () => getRecoveryAssets().index() },
|
|
146729
|
+
...pluginRuntime === void 0 ? {} : { renderIndex: (html) => pluginRuntime.renderIndex(html) },
|
|
146730
|
+
...auth === void 0 ? {} : { headScript: SWITCH_TOKEN_SCRIPT }
|
|
146731
|
+
});
|
|
145575
146732
|
return;
|
|
145576
146733
|
}
|
|
145577
146734
|
if (pathname === "/plugins/events" && pluginRuntime !== void 0) {
|
|
@@ -145586,7 +146743,7 @@ var server = createWebServer((request3, response) => {
|
|
|
145586
146743
|
await sendAsset(
|
|
145587
146744
|
request3,
|
|
145588
146745
|
response,
|
|
145589
|
-
assets.plugin(url2) ??
|
|
146746
|
+
assets.plugin(url2) ?? cachedRecoveryAssets?.plugin(url2),
|
|
145590
146747
|
url2.includes("rev=") ? IMMUTABLE_CACHE : void 0
|
|
145591
146748
|
);
|
|
145592
146749
|
return;
|
|
@@ -145635,7 +146792,7 @@ var server = createWebServer((request3, response) => {
|
|
|
145635
146792
|
response,
|
|
145636
146793
|
assets.dist(pathname),
|
|
145637
146794
|
pathname.startsWith("/assets/") ? IMMUTABLE_CACHE : void 0,
|
|
145638
|
-
pathname === "/codexhost-settings.js"
|
|
146795
|
+
pathname === "/sw.js" || pathname === "/manifest.webmanifest" || pathname === "/codexhost-settings.js"
|
|
145639
146796
|
);
|
|
145640
146797
|
})().catch((error62) => {
|
|
145641
146798
|
console.error("[http] request failed", error62), response.headersSent ? response.destroy() : response.writeHead(500).end("internal error");
|
|
@@ -145679,7 +146836,7 @@ background && server.once("error", (error62) => {
|
|
|
145679
146836
|
server.listen(Number(values.port), values.host, async () => {
|
|
145680
146837
|
let port = server.address().port;
|
|
145681
146838
|
listeningPort = port;
|
|
145682
|
-
let host = values.host, wildcard = isWildcardHost(host), local = wildcard ||
|
|
146839
|
+
let host = values.host, wildcard = isWildcardHost(host), local = wildcard || isLoopbackHost3(host), query = accessTokens !== void 0 && local ? `?token=${accessTokens.localToken}` : "", localUrl = `http://${wildcard ? "127.0.0.1" : host}:${String(port)}/${query}`;
|
|
145683
146840
|
if (background) {
|
|
145684
146841
|
let readyFile = values["ready-file"];
|
|
145685
146842
|
readyFile !== void 0 && new DataDir(dirname19(readyFile)).writeJson(
|
|
@@ -145717,7 +146874,7 @@ var shuttingDown;
|
|
|
145717
146874
|
function shutdown(exitCode = 0) {
|
|
145718
146875
|
return shuttingDown ??= (async () => {
|
|
145719
146876
|
try {
|
|
145720
|
-
stopEpoch?.(), webTelemetry.close(), await peerDelegationBridge?.close(), peerManager.close(), relay.close(), shellReload?.close(), accessTokens?.close(), server.close(), desktopScreenshots.close(), await sidebarBrowser.close(), await dsh?.close(), await extensions2.cleanup(!0), pushNotifications?.close(), await sessions.close(),
|
|
146877
|
+
stopEpoch?.(), webTelemetry.close(), await peerDelegationBridge?.close(), peerManager.close(), relay.close(), shellReload?.close(), accessTokens?.close(), server.close(), desktopScreenshots.close(), await sidebarBrowser.close(), await dsh?.close(), await extensions2.cleanup(!0), pushNotifications?.close(), await sessions.close(), sharedWorkspaceSearchCache.close(), remoteSessions.close(), await preferences?.close(), displaySettings.close();
|
|
145721
146878
|
} catch (error62) {
|
|
145722
146879
|
console.error("[web] shutdown failed", error62), exitCode ||= 1;
|
|
145723
146880
|
} finally {
|