ds-harness-remote 0.4.17 → 0.4.18
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/dist/client-runtime.d.ts.map +1 -1
- package/dist/client-runtime.js +2 -2
- package/dist/client-runtime.js.map +1 -1
- package/dist/client.github.js +20 -18
- package/dist/client.js +20 -18
- package/dist/client.js.map +1 -1
- package/dist/codex/codex-image-codec.d.ts +7 -0
- package/dist/codex/codex-image-codec.d.ts.map +1 -0
- package/dist/codex/codex-image-codec.js +288 -0
- package/dist/codex/codex-image-codec.js.map +1 -0
- package/dist/codex/virtual-harness.d.ts.map +1 -1
- package/dist/codex/virtual-harness.js +1 -267
- package/dist/codex/virtual-harness.js.map +1 -1
- package/dist/codex-workspace-bridge.d.ts.map +1 -1
- package/dist/codex-workspace-bridge.js +31 -5
- package/dist/codex-workspace-bridge.js.map +1 -1
- package/dist/config.d.ts +13 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +22 -2
- package/dist/config.js.map +1 -1
- package/dist/control-runtime.d.ts +17 -3
- package/dist/control-runtime.d.ts.map +1 -1
- package/dist/control-runtime.js +4 -2
- package/dist/control-runtime.js.map +1 -1
- package/dist/harness-api-bridge.d.ts.map +1 -1
- package/dist/harness-api-bridge.js +2 -53
- package/dist/harness-api-bridge.js.map +1 -1
- package/dist/harness-api-history.d.ts +3 -0
- package/dist/harness-api-history.d.ts.map +1 -0
- package/dist/harness-api-history.js +55 -0
- package/dist/harness-api-history.js.map +1 -0
- package/dist/harness-remote-bridge.d.ts.map +1 -1
- package/dist/harness-remote-bridge.js +40 -2
- package/dist/harness-remote-bridge.js.map +1 -1
- package/dist/index.d.ts +24 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +835 -583
- package/dist/index.js.map +4 -4
- package/dist/remote-api-proxy.d.ts +5 -1
- package/dist/remote-api-proxy.d.ts.map +1 -1
- package/dist/remote-api-proxy.js +74 -2
- package/dist/remote-api-proxy.js.map +1 -1
- package/dist/remote-typert-gateway.d.ts +6 -1
- package/dist/remote-typert-gateway.d.ts.map +1 -1
- package/dist/remote-typert-gateway.js +58 -1
- package/dist/remote-typert-gateway.js.map +1 -1
- package/dist/typert-gateway-contract.d.ts +11 -1
- package/dist/typert-gateway-contract.d.ts.map +1 -1
- package/dist/typert-gateway-switch.d.ts.map +1 -1
- package/dist/typert-gateway-switch.js +65 -4
- package/dist/typert-gateway-switch.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dsh-plugin.json +1 -1
- package/package.json +18 -18
- package/public.d.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -14693,14 +14693,14 @@ function requestSignal(req) {
|
|
|
14693
14693
|
}
|
|
14694
14694
|
function clientRequest(value) {
|
|
14695
14695
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
14696
|
-
const
|
|
14697
|
-
if (
|
|
14698
|
-
return { type: "client-request", rpcId:
|
|
14696
|
+
const record7 = value;
|
|
14697
|
+
if (record7.type !== "client-request" || typeof record7.rpcId !== "string" || typeof record7.method !== "string") return void 0;
|
|
14698
|
+
return { type: "client-request", rpcId: record7.rpcId, method: record7.method, payload: record7.payload };
|
|
14699
14699
|
}
|
|
14700
14700
|
function rpcId(value) {
|
|
14701
14701
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return INVALID_REQUEST_RPC_ID;
|
|
14702
|
-
const
|
|
14703
|
-
return typeof
|
|
14702
|
+
const record7 = value;
|
|
14703
|
+
return typeof record7.rpcId === "string" ? record7.rpcId : INVALID_REQUEST_RPC_ID;
|
|
14704
14704
|
}
|
|
14705
14705
|
function errorResponse(rpcId2, error) {
|
|
14706
14706
|
return fullResponse(rpcId2, { ok: false, error });
|
|
@@ -14780,9 +14780,13 @@ var AGENT_PRESET_SETTINGS_NS = "agent-presets";
|
|
|
14780
14780
|
var LEGACY_AGENT_PRESET_ALIASES = {
|
|
14781
14781
|
code: "ptc"
|
|
14782
14782
|
};
|
|
14783
|
+
var WELCOME_NOTICE_NAMESPACE = "ui-settings-general";
|
|
14784
|
+
var WELCOME_NOTICE_FIELD = "welcomeNoticeVersion";
|
|
14785
|
+
var WELCOME_NOTICE_VERSION = "2026-08-13.1";
|
|
14783
14786
|
var RemoteHarnessApiProxy = class {
|
|
14784
|
-
constructor(client) {
|
|
14787
|
+
constructor(client, harnessVersion) {
|
|
14785
14788
|
this.client = client;
|
|
14789
|
+
this.harnessVersion = harnessVersion;
|
|
14786
14790
|
const call = (method) => (request, signal) => this.call(method, request, signal);
|
|
14787
14791
|
this.api = {
|
|
14788
14792
|
sessions: {
|
|
@@ -14864,6 +14868,8 @@ var RemoteHarnessApiProxy = class {
|
|
|
14864
14868
|
};
|
|
14865
14869
|
}
|
|
14866
14870
|
api;
|
|
14871
|
+
legacyWelcomeAcknowledged = false;
|
|
14872
|
+
settingsDescribeValue;
|
|
14867
14873
|
async call(method, request, signal) {
|
|
14868
14874
|
const params = {
|
|
14869
14875
|
method,
|
|
@@ -14875,7 +14881,18 @@ var RemoteHarnessApiProxy = class {
|
|
|
14875
14881
|
if (String(response.rpcId) !== String(request.rpcId) || typeof response.result !== "object" || response.result === null) {
|
|
14876
14882
|
throw new Error("The remote Host returned an invalid Harness API response.");
|
|
14877
14883
|
}
|
|
14878
|
-
|
|
14884
|
+
const normalized = normalizeLegacyResponse(method, response);
|
|
14885
|
+
return this.normalizeLegacyWelcomeSettings(method, params.payload, normalized);
|
|
14886
|
+
}
|
|
14887
|
+
normalizeLegacyWelcomeSettings(method, payload, response) {
|
|
14888
|
+
if (!isLegacyRemoteHost(this.harnessVersion)) return response;
|
|
14889
|
+
if (method === "settings.describe" && response.result.ok && isRecord2(response.result.value)) {
|
|
14890
|
+
this.settingsDescribeValue = response.result.value;
|
|
14891
|
+
return this.legacyWelcomeAcknowledged ? patchWelcomeDescribe(response) : response;
|
|
14892
|
+
}
|
|
14893
|
+
if (method !== "settings.mutate" || !isWelcomeNoticeRequest(payload)) return response;
|
|
14894
|
+
this.legacyWelcomeAcknowledged = true;
|
|
14895
|
+
return patchWelcomeMutate(this.settingsDescribeValue ?? { namespaces: [] }, response.rpcId);
|
|
14879
14896
|
}
|
|
14880
14897
|
async callTransferred(encoded, signal) {
|
|
14881
14898
|
if (encoded.byteLength > MAX_HARNESS_API_TRANSFER_BYTES) {
|
|
@@ -15000,6 +15017,45 @@ function replaceAgentPresetSettings(payload) {
|
|
|
15000
15017
|
const patch = replaceAgentPreset(payload.patch, "default");
|
|
15001
15018
|
return patch === payload.patch ? payload : { ...payload, patch };
|
|
15002
15019
|
}
|
|
15020
|
+
function isLegacyRemoteHost(version) {
|
|
15021
|
+
if (version === void 0) return false;
|
|
15022
|
+
const match = /^(?:dsh-)?v?(\d+)\.(\d+)\.(\d+)(?:-|$)/u.exec(version.trim());
|
|
15023
|
+
return match !== null && Number(match[1]) === 0 && Number(match[2]) === 1 && Number(match[3]) < 7;
|
|
15024
|
+
}
|
|
15025
|
+
function isWelcomeNoticeRequest(payload) {
|
|
15026
|
+
if (!isRecord2(payload) || payload.ns !== WELCOME_NOTICE_NAMESPACE || !Array.isArray(payload.ops)) return false;
|
|
15027
|
+
return payload.ops.some((operation) => isRecord2(operation) && operation.op === "set" && Array.isArray(operation.path) && operation.path.length === 1 && operation.path[0] === WELCOME_NOTICE_FIELD && operation.value === WELCOME_NOTICE_VERSION);
|
|
15028
|
+
}
|
|
15029
|
+
function patchWelcomeDescribe(response) {
|
|
15030
|
+
if (!response.result.ok || !isRecord2(response.result.value) || !Array.isArray(response.result.value.namespaces)) return response;
|
|
15031
|
+
return {
|
|
15032
|
+
...response,
|
|
15033
|
+
result: {
|
|
15034
|
+
...response.result,
|
|
15035
|
+
value: {
|
|
15036
|
+
...response.result.value,
|
|
15037
|
+
namespaces: response.result.value.namespaces.map((namespace) => {
|
|
15038
|
+
if (!isRecord2(namespace) || namespace.ns !== WELCOME_NOTICE_NAMESPACE) return namespace;
|
|
15039
|
+
const value = isRecord2(namespace.value) ? namespace.value : {};
|
|
15040
|
+
return { ...namespace, value: { ...value, [WELCOME_NOTICE_FIELD]: WELCOME_NOTICE_VERSION } };
|
|
15041
|
+
})
|
|
15042
|
+
}
|
|
15043
|
+
}
|
|
15044
|
+
};
|
|
15045
|
+
}
|
|
15046
|
+
function patchWelcomeMutate(value, rpcId2) {
|
|
15047
|
+
const response = {
|
|
15048
|
+
rpcId: rpcId2,
|
|
15049
|
+
result: { ok: true, value: { ...value, namespaces: [] } }
|
|
15050
|
+
};
|
|
15051
|
+
const namespaces = Array.isArray(value.namespaces) ? value.namespaces : [];
|
|
15052
|
+
response.result.value.namespaces = namespaces.map((namespace) => {
|
|
15053
|
+
if (!isRecord2(namespace) || namespace.ns !== WELCOME_NOTICE_NAMESPACE) return namespace;
|
|
15054
|
+
const current = isRecord2(namespace.value) ? namespace.value : {};
|
|
15055
|
+
return { ...namespace, value: { ...current, [WELCOME_NOTICE_FIELD]: WELCOME_NOTICE_VERSION } };
|
|
15056
|
+
});
|
|
15057
|
+
return response;
|
|
15058
|
+
}
|
|
15003
15059
|
function isRemoteDisconnect(error) {
|
|
15004
15060
|
return error instanceof RemoteClientError && (error.code === "TRANSPORT_CLOSED" || error.code === "CLIENT_CLOSED");
|
|
15005
15061
|
}
|
|
@@ -15094,15 +15150,15 @@ function normalizeRecords(value) {
|
|
|
15094
15150
|
if (!Array.isArray(value)) return value;
|
|
15095
15151
|
const records = [];
|
|
15096
15152
|
let previousSeq;
|
|
15097
|
-
for (const
|
|
15098
|
-
if (!isEventEntry(
|
|
15099
|
-
const seq = entrySeq(
|
|
15153
|
+
for (const record7 of value) {
|
|
15154
|
+
if (!isEventEntry(record7)) continue;
|
|
15155
|
+
const seq = entrySeq(record7);
|
|
15100
15156
|
if (previousSeq !== void 0 && seq !== void 0 && seq > previousSeq + 1) {
|
|
15101
15157
|
for (let fillerSeq = previousSeq + 1; fillerSeq < seq; fillerSeq += 1) {
|
|
15102
|
-
records.push(createLegacyGapRecord(fillerSeq,
|
|
15158
|
+
records.push(createLegacyGapRecord(fillerSeq, record7));
|
|
15103
15159
|
}
|
|
15104
15160
|
}
|
|
15105
|
-
records.push(normalizeEntry(
|
|
15161
|
+
records.push(normalizeEntry(record7));
|
|
15106
15162
|
if (seq !== void 0) previousSeq = seq;
|
|
15107
15163
|
}
|
|
15108
15164
|
return records;
|
|
@@ -15226,10 +15282,14 @@ function isEventSeq(value) {
|
|
|
15226
15282
|
|
|
15227
15283
|
// src/remote-typert-gateway.ts
|
|
15228
15284
|
var DIRECT_REMOTE_CALL_BYTES2 = 2 * 1024 * 1024;
|
|
15285
|
+
var WELCOME_NOTICE_NAMESPACE2 = "ui-settings-general";
|
|
15286
|
+
var WELCOME_NOTICE_FIELD2 = "welcomeNoticeVersion";
|
|
15287
|
+
var WELCOME_NOTICE_VERSION2 = "2026-08-13.1";
|
|
15229
15288
|
var RemoteTypertGateway2 = class {
|
|
15230
|
-
constructor(client, compatibility) {
|
|
15289
|
+
constructor(client, compatibility, harnessVersion) {
|
|
15231
15290
|
this.client = client;
|
|
15232
15291
|
this.compatibility = compatibility;
|
|
15292
|
+
this.harnessVersion = harnessVersion;
|
|
15233
15293
|
}
|
|
15234
15294
|
async invoke(request) {
|
|
15235
15295
|
const result = await this.dispatch(
|
|
@@ -15255,11 +15315,29 @@ var RemoteTypertGateway2 = class {
|
|
|
15255
15315
|
}
|
|
15256
15316
|
}
|
|
15257
15317
|
const result = parseRpcResult(response);
|
|
15318
|
+
const settingsResult = this.normalizeLegacyWelcomeSettings(endpoint, payload, result);
|
|
15319
|
+
if (settingsResult !== void 0) return settingsResult;
|
|
15258
15320
|
if (result.ok && this.compatibility === "legacy-to-v3") {
|
|
15259
15321
|
return { ...result, value: normalizeLegacySessionGatewayValue(endpoint, result.value) };
|
|
15260
15322
|
}
|
|
15261
15323
|
return result;
|
|
15262
15324
|
}
|
|
15325
|
+
legacyWelcomeAcknowledged = false;
|
|
15326
|
+
settingsDescribeValue;
|
|
15327
|
+
/** DSH <=0.1.6 cannot persist the 0.1.7 welcome acknowledgement remotely. */
|
|
15328
|
+
normalizeLegacyWelcomeSettings(endpoint, payload, result) {
|
|
15329
|
+
if (!isLegacyRemoteHost2(this.harnessVersion)) return void 0;
|
|
15330
|
+
if (endpoint === "settings/describe" && result.ok && isRecord4(result.value)) {
|
|
15331
|
+
this.settingsDescribeValue = result.value;
|
|
15332
|
+
return this.legacyWelcomeAcknowledged ? { ...result, value: patchWelcomeDescribe2(result.value) } : void 0;
|
|
15333
|
+
}
|
|
15334
|
+
if (endpoint !== "settings/mutate" || !isRecord4(payload) || !isRecord4(payload.args)) return void 0;
|
|
15335
|
+
const args = payload.args;
|
|
15336
|
+
if (args.ns !== WELCOME_NOTICE_NAMESPACE2 || !isWelcomeNoticeOperation(args.ops)) return void 0;
|
|
15337
|
+
const value = patchWelcomeDescribe2(this.settingsDescribeValue ?? { namespaces: [] });
|
|
15338
|
+
this.legacyWelcomeAcknowledged = true;
|
|
15339
|
+
return { ok: true, value };
|
|
15340
|
+
}
|
|
15263
15341
|
async open(endpoint, payload, signal) {
|
|
15264
15342
|
const streamId = uuidV7();
|
|
15265
15343
|
const queue = new AsyncValueQueue();
|
|
@@ -15466,6 +15544,24 @@ function isRecord4(value) {
|
|
|
15466
15544
|
function hasErrorCode(error, code) {
|
|
15467
15545
|
return error instanceof Error && "code" in error && error.code === code;
|
|
15468
15546
|
}
|
|
15547
|
+
function isLegacyRemoteHost2(version) {
|
|
15548
|
+
if (version === void 0) return false;
|
|
15549
|
+
const match = /^(?:dsh-)?v?(\d+)\.(\d+)\.(\d+)(?:-|$)/u.exec(version.trim());
|
|
15550
|
+
if (match === null) return false;
|
|
15551
|
+
return Number(match[1]) === 0 && Number(match[2]) === 1 && Number(match[3]) < 7;
|
|
15552
|
+
}
|
|
15553
|
+
function isWelcomeNoticeOperation(value) {
|
|
15554
|
+
return Array.isArray(value) && value.some((operation) => isRecord4(operation) && operation.op === "set" && Array.isArray(operation.path) && operation.path.length === 1 && operation.path[0] === WELCOME_NOTICE_FIELD2 && operation.value === WELCOME_NOTICE_VERSION2);
|
|
15555
|
+
}
|
|
15556
|
+
function patchWelcomeDescribe2(value) {
|
|
15557
|
+
if (!Array.isArray(value.namespaces)) return value;
|
|
15558
|
+
const namespaces = value.namespaces.map((namespace) => {
|
|
15559
|
+
if (!isRecord4(namespace) || namespace.ns !== WELCOME_NOTICE_NAMESPACE2) return namespace;
|
|
15560
|
+
const current = isRecord4(namespace.value) ? namespace.value : {};
|
|
15561
|
+
return { ...namespace, value: { ...current, [WELCOME_NOTICE_FIELD2]: WELCOME_NOTICE_VERSION2 } };
|
|
15562
|
+
});
|
|
15563
|
+
return { ...value, namespaces };
|
|
15564
|
+
}
|
|
15469
15565
|
|
|
15470
15566
|
// src/codex/permissions.ts
|
|
15471
15567
|
function codexPermissionPresetFromResponse(value) {
|
|
@@ -15486,6 +15582,232 @@ function record(value) {
|
|
|
15486
15582
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
15487
15583
|
}
|
|
15488
15584
|
|
|
15585
|
+
// src/codex/codex-image-codec.ts
|
|
15586
|
+
var CODEX_IMAGE_MEDIA_TYPES2 = /* @__PURE__ */ new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
|
|
15587
|
+
var CODEX_IMAGE_ATTACHMENT_PREFIX = "codex-image:";
|
|
15588
|
+
var MAX_CODEX_IMAGE_BASE64 = 288 * 1024 * 1024;
|
|
15589
|
+
var DATA_IMAGE_URL2 = /^data:(image\/(?:png|jpeg|webp|gif));base64,([A-Za-z0-9+/]+={0,2})$/u;
|
|
15590
|
+
function string(value) {
|
|
15591
|
+
return typeof value === "string" ? value : void 0;
|
|
15592
|
+
}
|
|
15593
|
+
function isRecord5(value) {
|
|
15594
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15595
|
+
}
|
|
15596
|
+
function record2(value) {
|
|
15597
|
+
return isRecord5(value) ? value : {};
|
|
15598
|
+
}
|
|
15599
|
+
function toolOutputImageBlocks(item) {
|
|
15600
|
+
const candidates = [
|
|
15601
|
+
record2(item.result).content,
|
|
15602
|
+
record2(item.output).content,
|
|
15603
|
+
item.contentItems,
|
|
15604
|
+
Array.isArray(item.output) ? item.output : void 0
|
|
15605
|
+
];
|
|
15606
|
+
for (const candidate of candidates) {
|
|
15607
|
+
if (!Array.isArray(candidate)) continue;
|
|
15608
|
+
const images = candidate.flatMap((value) => {
|
|
15609
|
+
const block = record2(value);
|
|
15610
|
+
return isImageContent2(block) && parseImageBlock(block) !== void 0 ? [block] : [];
|
|
15611
|
+
});
|
|
15612
|
+
if (images.length > 0) return images;
|
|
15613
|
+
}
|
|
15614
|
+
return [];
|
|
15615
|
+
}
|
|
15616
|
+
function contentBlocks(value, attachmentSeed) {
|
|
15617
|
+
if (typeof value === "string") return [{ type: "text", text: value }];
|
|
15618
|
+
if (!Array.isArray(value)) return [];
|
|
15619
|
+
const blocks = [];
|
|
15620
|
+
let imageIndex = 0;
|
|
15621
|
+
for (const raw of value) {
|
|
15622
|
+
if (typeof raw === "string") {
|
|
15623
|
+
blocks.push({ type: "text", text: raw });
|
|
15624
|
+
continue;
|
|
15625
|
+
}
|
|
15626
|
+
const block = record2(raw);
|
|
15627
|
+
const image = imageContentBlock(block, attachmentSeed, imageIndex);
|
|
15628
|
+
if (image !== void 0) {
|
|
15629
|
+
imageIndex += 1;
|
|
15630
|
+
blocks.push(image);
|
|
15631
|
+
continue;
|
|
15632
|
+
}
|
|
15633
|
+
const text = string(block.text) ?? string(block.content);
|
|
15634
|
+
if (text !== void 0) blocks.push({ type: block.type === "reasoning" ? "reasoning" : "text", text });
|
|
15635
|
+
}
|
|
15636
|
+
return blocks;
|
|
15637
|
+
}
|
|
15638
|
+
function imageContentBlock(block, attachmentSeed, index) {
|
|
15639
|
+
if (!isImageContent2(block)) return void 0;
|
|
15640
|
+
const image = parseImageBlock(block);
|
|
15641
|
+
if (image === void 0) return void 0;
|
|
15642
|
+
const dimensions = imageDimensions(image.mediaType, image.data);
|
|
15643
|
+
const name2 = string(block.name);
|
|
15644
|
+
const attachment = {
|
|
15645
|
+
attachmentId: `${CODEX_IMAGE_ATTACHMENT_PREFIX}${hashString(`${attachmentSeed}:${index}`)}:${index}`,
|
|
15646
|
+
mediaType: image.mediaType,
|
|
15647
|
+
bytes: base64ByteLength(image.data),
|
|
15648
|
+
width: dimensions.width,
|
|
15649
|
+
height: dimensions.height,
|
|
15650
|
+
...name2 === void 0 ? {} : { name: name2 }
|
|
15651
|
+
};
|
|
15652
|
+
return {
|
|
15653
|
+
type: "image",
|
|
15654
|
+
attachment,
|
|
15655
|
+
mediaType: image.mediaType,
|
|
15656
|
+
data: image.data,
|
|
15657
|
+
url: image.url,
|
|
15658
|
+
...name2 === void 0 ? {} : { name: name2 }
|
|
15659
|
+
};
|
|
15660
|
+
}
|
|
15661
|
+
function isImageContent2(block) {
|
|
15662
|
+
return block.type === "image" || block.type === "input_image";
|
|
15663
|
+
}
|
|
15664
|
+
function parseImageBlock(block) {
|
|
15665
|
+
const url = string(block.url) ?? string(block.image_url) ?? string(record2(block.image_url).url);
|
|
15666
|
+
const parsed = url === void 0 ? void 0 : parseDataImageUrl2(url);
|
|
15667
|
+
if (parsed !== void 0) return parsed;
|
|
15668
|
+
const data2 = string(block.data);
|
|
15669
|
+
if (data2 === void 0 || !isCanonicalBase642(data2)) return void 0;
|
|
15670
|
+
if (data2.length > MAX_CODEX_IMAGE_BASE64) return void 0;
|
|
15671
|
+
const mediaType = string(block.mediaType) ?? string(block.mimeType) ?? sniffImageMediaType2(data2);
|
|
15672
|
+
return mediaType !== void 0 && CODEX_IMAGE_MEDIA_TYPES2.has(mediaType) ? { mediaType, data: data2, url: `data:${mediaType};base64,${data2}` } : void 0;
|
|
15673
|
+
}
|
|
15674
|
+
function parseDataImageUrl2(value) {
|
|
15675
|
+
const match = DATA_IMAGE_URL2.exec(value);
|
|
15676
|
+
if (match === null) return void 0;
|
|
15677
|
+
const mediaType = match[1];
|
|
15678
|
+
const data2 = match[2];
|
|
15679
|
+
if (!CODEX_IMAGE_MEDIA_TYPES2.has(mediaType) || !isCanonicalBase642(data2)) return void 0;
|
|
15680
|
+
return { mediaType, data: data2, url: `data:${mediaType};base64,${data2}` };
|
|
15681
|
+
}
|
|
15682
|
+
function collectImageBlocks(value, output = []) {
|
|
15683
|
+
if (Array.isArray(value)) {
|
|
15684
|
+
for (const item of value) collectImageBlocks(item, output);
|
|
15685
|
+
return output;
|
|
15686
|
+
}
|
|
15687
|
+
if (!isRecord5(value)) return output;
|
|
15688
|
+
if (value.type === "image") output.push(value);
|
|
15689
|
+
for (const [key, child] of Object.entries(value)) {
|
|
15690
|
+
if (key === "attachment") continue;
|
|
15691
|
+
if (key === "content" || key === "message" || key === "inserted" || key === "chunk" || key === "block") {
|
|
15692
|
+
collectImageBlocks(child, output);
|
|
15693
|
+
}
|
|
15694
|
+
}
|
|
15695
|
+
return output;
|
|
15696
|
+
}
|
|
15697
|
+
function base64ByteLength(value) {
|
|
15698
|
+
const padding = value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0;
|
|
15699
|
+
return Math.max(1, Math.floor(value.length * 3 / 4) - padding);
|
|
15700
|
+
}
|
|
15701
|
+
function imageDimensions(mediaType, data2) {
|
|
15702
|
+
const bytes = base64PrefixBytes2(data2, 256 * 1024);
|
|
15703
|
+
const parsed = mediaType === "image/png" ? pngDimensions(bytes) : mediaType === "image/jpeg" ? jpegDimensions(bytes) : mediaType === "image/gif" ? gifDimensions(bytes) : mediaType === "image/webp" ? webpDimensions(bytes) : void 0;
|
|
15704
|
+
return parsed ?? { width: 1, height: 1 };
|
|
15705
|
+
}
|
|
15706
|
+
function pngDimensions(bytes) {
|
|
15707
|
+
if (bytes.length < 24 || bytes[0] !== 137 || bytes[1] !== 80 || bytes[2] !== 78 || bytes[3] !== 71 || bytes[4] !== 13 || bytes[5] !== 10 || bytes[6] !== 26 || bytes[7] !== 10) return void 0;
|
|
15708
|
+
return positiveDimensions(readUint32BE(bytes, 16), readUint32BE(bytes, 20));
|
|
15709
|
+
}
|
|
15710
|
+
function jpegDimensions(bytes) {
|
|
15711
|
+
if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216) return void 0;
|
|
15712
|
+
let offset = 2;
|
|
15713
|
+
while (offset + 9 < bytes.length) {
|
|
15714
|
+
if (bytes[offset] !== 255) {
|
|
15715
|
+
offset += 1;
|
|
15716
|
+
continue;
|
|
15717
|
+
}
|
|
15718
|
+
const marker = bytes[offset + 1];
|
|
15719
|
+
offset += 2;
|
|
15720
|
+
if (marker === 216 || marker === 217) continue;
|
|
15721
|
+
if (offset + 2 > bytes.length) return void 0;
|
|
15722
|
+
const length = readUint16BE(bytes, offset);
|
|
15723
|
+
if (length < 2 || offset + length > bytes.length) return void 0;
|
|
15724
|
+
if (isJpegSof(marker) && length >= 7) {
|
|
15725
|
+
return positiveDimensions(readUint16BE(bytes, offset + 5), readUint16BE(bytes, offset + 3));
|
|
15726
|
+
}
|
|
15727
|
+
offset += length;
|
|
15728
|
+
}
|
|
15729
|
+
return void 0;
|
|
15730
|
+
}
|
|
15731
|
+
function gifDimensions(bytes) {
|
|
15732
|
+
if (bytes.length < 10 || bytes[0] !== 71 || bytes[1] !== 73 || bytes[2] !== 70 || bytes[3] !== 56 || bytes[4] !== 55 && bytes[4] !== 57 || bytes[5] !== 97) return void 0;
|
|
15733
|
+
return positiveDimensions(readUint16LE(bytes, 6), readUint16LE(bytes, 8));
|
|
15734
|
+
}
|
|
15735
|
+
function webpDimensions(bytes) {
|
|
15736
|
+
if (bytes.length < 30 || stringFromBytes(bytes, 0, 4) !== "RIFF" || stringFromBytes(bytes, 8, 12) !== "WEBP") return void 0;
|
|
15737
|
+
const chunk = stringFromBytes(bytes, 12, 16);
|
|
15738
|
+
if (chunk === "VP8X") {
|
|
15739
|
+
return positiveDimensions(1 + readUint24LE(bytes, 24), 1 + readUint24LE(bytes, 27));
|
|
15740
|
+
}
|
|
15741
|
+
if (chunk === "VP8L" && bytes[20] === 47) {
|
|
15742
|
+
const b0 = bytes[21];
|
|
15743
|
+
const b1 = bytes[22];
|
|
15744
|
+
const b2 = bytes[23];
|
|
15745
|
+
const b3 = bytes[24];
|
|
15746
|
+
const width = 1 + b0 + ((b1 & 63) << 8);
|
|
15747
|
+
const height = 1 + ((b1 & 192) >> 6) + (b2 << 2) + ((b3 & 15) << 10);
|
|
15748
|
+
return positiveDimensions(width, height);
|
|
15749
|
+
}
|
|
15750
|
+
if (chunk === "VP8 " && bytes[23] === 157 && bytes[24] === 1 && bytes[25] === 42) {
|
|
15751
|
+
return positiveDimensions(readUint16LE(bytes, 26) & 16383, readUint16LE(bytes, 28) & 16383);
|
|
15752
|
+
}
|
|
15753
|
+
return void 0;
|
|
15754
|
+
}
|
|
15755
|
+
function sniffImageMediaType2(data2) {
|
|
15756
|
+
const bytes = base64PrefixBytes2(data2, 32);
|
|
15757
|
+
if (pngDimensions(bytes) !== void 0) return "image/png";
|
|
15758
|
+
if (bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return "image/jpeg";
|
|
15759
|
+
if (gifDimensions(bytes) !== void 0) return "image/gif";
|
|
15760
|
+
if (bytes.length >= 12 && stringFromBytes(bytes, 0, 4) === "RIFF" && stringFromBytes(bytes, 8, 12) === "WEBP") return "image/webp";
|
|
15761
|
+
return void 0;
|
|
15762
|
+
}
|
|
15763
|
+
function base64PrefixBytes2(value, maxBytes) {
|
|
15764
|
+
const chars = value.slice(0, Math.ceil(maxBytes / 3) * 4);
|
|
15765
|
+
let binary;
|
|
15766
|
+
try {
|
|
15767
|
+
binary = atob(chars);
|
|
15768
|
+
} catch {
|
|
15769
|
+
return new Uint8Array();
|
|
15770
|
+
}
|
|
15771
|
+
const bytes = new Uint8Array(Math.min(binary.length, maxBytes));
|
|
15772
|
+
for (let index = 0; index < bytes.length; index += 1) bytes[index] = binary.charCodeAt(index);
|
|
15773
|
+
return bytes;
|
|
15774
|
+
}
|
|
15775
|
+
function readUint16BE(bytes, offset) {
|
|
15776
|
+
return (bytes[offset] << 8) + bytes[offset + 1];
|
|
15777
|
+
}
|
|
15778
|
+
function readUint16LE(bytes, offset) {
|
|
15779
|
+
return bytes[offset] + (bytes[offset + 1] << 8);
|
|
15780
|
+
}
|
|
15781
|
+
function readUint24LE(bytes, offset) {
|
|
15782
|
+
return bytes[offset] + (bytes[offset + 1] << 8) + (bytes[offset + 2] << 16);
|
|
15783
|
+
}
|
|
15784
|
+
function readUint32BE(bytes, offset) {
|
|
15785
|
+
return bytes[offset] * 16777216 + bytes[offset + 1] * 65536 + bytes[offset + 2] * 256 + bytes[offset + 3];
|
|
15786
|
+
}
|
|
15787
|
+
function positiveDimensions(width, height) {
|
|
15788
|
+
return width > 0 && height > 0 ? { width, height } : void 0;
|
|
15789
|
+
}
|
|
15790
|
+
function isJpegSof(marker) {
|
|
15791
|
+
return marker >= 192 && marker <= 195 || marker >= 197 && marker <= 199 || marker >= 201 && marker <= 203 || marker >= 205 && marker <= 207;
|
|
15792
|
+
}
|
|
15793
|
+
function stringFromBytes(bytes, start, end) {
|
|
15794
|
+
if (bytes.length < end) return "";
|
|
15795
|
+
let output = "";
|
|
15796
|
+
for (let index = start; index < end; index += 1) output += String.fromCharCode(bytes[index]);
|
|
15797
|
+
return output;
|
|
15798
|
+
}
|
|
15799
|
+
function isCanonicalBase642(value) {
|
|
15800
|
+
return value.length >= 4 && value.length % 4 === 0 && /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(value);
|
|
15801
|
+
}
|
|
15802
|
+
function hashString(value) {
|
|
15803
|
+
let hash = 2166136261;
|
|
15804
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
15805
|
+
hash ^= value.charCodeAt(index);
|
|
15806
|
+
hash = Math.imul(hash, 16777619);
|
|
15807
|
+
}
|
|
15808
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
15809
|
+
}
|
|
15810
|
+
|
|
15489
15811
|
// src/codex/virtual-harness.ts
|
|
15490
15812
|
var CODEX_SESSION_PREFIX = "codex:";
|
|
15491
15813
|
var CODEX_WORKSPACE_PREFIX = "codex-workspace:";
|
|
@@ -15500,10 +15822,9 @@ var SESSION_SEARCH_SNIPPET_CODE_POINTS = 240;
|
|
|
15500
15822
|
var CODEX_DEFAULT_PERMISSION = "workspace-write";
|
|
15501
15823
|
var MAX_CODEX_PROMPT_PARTS = 16;
|
|
15502
15824
|
var MAX_CODEX_PROMPT_TEXT = 256 * 1024;
|
|
15503
|
-
var
|
|
15504
|
-
var
|
|
15505
|
-
var
|
|
15506
|
-
var DATA_IMAGE_URL2 = /^data:(image\/(?:png|jpeg|webp|gif));base64,([A-Za-z0-9+/]+={0,2})$/u;
|
|
15825
|
+
var MAX_CODEX_IMAGE_BASE642 = 288 * 1024 * 1024;
|
|
15826
|
+
var CODEX_IMAGE_MEDIA_TYPES3 = /* @__PURE__ */ new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
|
|
15827
|
+
var CODEX_IMAGE_ATTACHMENT_PREFIX2 = "codex-image:";
|
|
15507
15828
|
var HOST_WORKSPACE_ENDPOINTS = /* @__PURE__ */ new Set([
|
|
15508
15829
|
"workspaceFiles/list",
|
|
15509
15830
|
"workspaceFiles/stat",
|
|
@@ -15828,7 +16149,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
15828
16149
|
nativeThreadId(sessionId);
|
|
15829
16150
|
const provider = requiredString(request.provider, "provider");
|
|
15830
16151
|
const model = requiredString(request.model, "model");
|
|
15831
|
-
const reasoningEffort =
|
|
16152
|
+
const reasoningEffort = string2(request.reasoningEffort);
|
|
15832
16153
|
const directory = await this.models(signal);
|
|
15833
16154
|
const available = directory.models.get(model);
|
|
15834
16155
|
if (provider !== CODEX_PROVIDER || available === void 0) {
|
|
@@ -15861,7 +16182,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
15861
16182
|
const pending = this.pendingThreads.get(threadId);
|
|
15862
16183
|
if (pending !== void 0) this.pendingThreads.set(threadId, { ...pending, name: name2 });
|
|
15863
16184
|
if (this.catalog === void 0) return;
|
|
15864
|
-
const threads = this.catalog.threads.map((thread) =>
|
|
16185
|
+
const threads = this.catalog.threads.map((thread) => string2(thread.id) === threadId ? { ...thread, name: name2 } : thread);
|
|
15865
16186
|
const sessions = this.catalog.sessions.map((session) => {
|
|
15866
16187
|
if (session.nativeId !== threadId) return session;
|
|
15867
16188
|
const { title: _title, ...rest } = session;
|
|
@@ -15948,7 +16269,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
15948
16269
|
return queue.iterate(() => this.eventStreams.delete(clientId));
|
|
15949
16270
|
}
|
|
15950
16271
|
async sessionFollow(request, signal) {
|
|
15951
|
-
const sessionId = sessionIdFromAddress(
|
|
16272
|
+
const sessionId = sessionIdFromAddress(record3(request.address));
|
|
15952
16273
|
const threadId = nativeThreadId(sessionId);
|
|
15953
16274
|
const history = await this.readHistoryPage(threadId, {
|
|
15954
16275
|
maxMessages: optionalPositiveInteger(request.maxMessages)
|
|
@@ -16013,9 +16334,9 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16013
16334
|
});
|
|
16014
16335
|
}
|
|
16015
16336
|
acceptCodexFrame(follow, frame) {
|
|
16016
|
-
const params =
|
|
16337
|
+
const params = record3(frame.params);
|
|
16017
16338
|
if (frame.method === "thread/name/updated") {
|
|
16018
|
-
const name2 =
|
|
16339
|
+
const name2 = string2(params.threadName);
|
|
16019
16340
|
if (name2 === void 0) return;
|
|
16020
16341
|
const seq = this.nextProjectionSeq();
|
|
16021
16342
|
this.updateThreadName(follow.threadId, name2);
|
|
@@ -16029,39 +16350,39 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16029
16350
|
return;
|
|
16030
16351
|
}
|
|
16031
16352
|
if (frame.method === "turn/started") {
|
|
16032
|
-
const turn =
|
|
16353
|
+
const turn = record3(params.turn);
|
|
16033
16354
|
this.endAssistantAttempt(follow, { kind: "abandoned" });
|
|
16034
16355
|
this.resetLiveTurn(follow);
|
|
16035
16356
|
follow.turn += 1;
|
|
16036
|
-
follow.activeTurnId =
|
|
16357
|
+
follow.activeTurnId = string2(turn.id);
|
|
16037
16358
|
follow.requestId = this.pendingRequestIds.get(follow.sessionId);
|
|
16038
16359
|
follow.stepOpen = true;
|
|
16039
16360
|
this.pushEvent(follow, "turn/start", { turn: follow.turn });
|
|
16040
16361
|
this.pushEvent(follow, "step/start", { turn: follow.turn, step: 1 });
|
|
16041
16362
|
this.emitRemoteEvent("api-session/status", [follow.sessionId, true]);
|
|
16042
|
-
for (const item of array(turn.items)) this.acceptCompletedItem(follow,
|
|
16363
|
+
for (const item of array(turn.items)) this.acceptCompletedItem(follow, record3(item), false);
|
|
16043
16364
|
return;
|
|
16044
16365
|
}
|
|
16045
16366
|
if (frame.method === "item/started" || frame.method === "item/completed") {
|
|
16046
|
-
const item =
|
|
16047
|
-
const itemId =
|
|
16367
|
+
const item = record3(params.item);
|
|
16368
|
+
const itemId = string2(item.id);
|
|
16048
16369
|
if (frame.method === "item/started" && itemId !== void 0) {
|
|
16049
16370
|
follow.startedItems.add(itemId);
|
|
16050
16371
|
follow.liveItems.set(itemId, item);
|
|
16051
|
-
if (isToolItemType2(
|
|
16372
|
+
if (isToolItemType2(string2(item.type))) this.ensureToolStarted(follow, item);
|
|
16052
16373
|
}
|
|
16053
16374
|
if (frame.method === "item/completed") this.acceptCompletedItem(follow, item, true);
|
|
16054
16375
|
return;
|
|
16055
16376
|
}
|
|
16056
16377
|
if (frame.method === "item/agentMessage/delta") {
|
|
16057
|
-
const itemId =
|
|
16058
|
-
const delta =
|
|
16378
|
+
const itemId = string2(params.itemId) ?? `assistant:${follow.turn}`;
|
|
16379
|
+
const delta = string2(params.delta);
|
|
16059
16380
|
if (delta === void 0) return;
|
|
16060
16381
|
this.appendStreamDelta(follow, `agent:${itemId}`, itemId, "text", delta);
|
|
16061
16382
|
return;
|
|
16062
16383
|
}
|
|
16063
16384
|
if (frame.method === "item/reasoning/summaryPartAdded") {
|
|
16064
|
-
const itemId =
|
|
16385
|
+
const itemId = string2(params.itemId);
|
|
16065
16386
|
if (itemId !== void 0) this.ensureStreamBlock(
|
|
16066
16387
|
follow,
|
|
16067
16388
|
`reasoning-summary:${itemId}:${integer(params.summaryIndex) ?? 0}`,
|
|
@@ -16071,8 +16392,8 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16071
16392
|
return;
|
|
16072
16393
|
}
|
|
16073
16394
|
if (frame.method === "item/reasoning/summaryTextDelta" || frame.method === "item/reasoning/textDelta" || frame.method === "item/plan/delta") {
|
|
16074
|
-
const itemId =
|
|
16075
|
-
const delta =
|
|
16395
|
+
const itemId = string2(params.itemId);
|
|
16396
|
+
const delta = string2(params.delta);
|
|
16076
16397
|
if (itemId === void 0 || delta === void 0) return;
|
|
16077
16398
|
const key = frame.method === "item/plan/delta" ? `plan:${itemId}` : frame.method === "item/reasoning/summaryTextDelta" ? `reasoning-summary:${itemId}:${integer(params.summaryIndex) ?? 0}` : `reasoning-content:${itemId}:${integer(params.contentIndex) ?? 0}`;
|
|
16078
16399
|
this.appendStreamDelta(follow, key, itemId, "reasoning", delta);
|
|
@@ -16080,8 +16401,8 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16080
16401
|
}
|
|
16081
16402
|
if (frame.method === "turn/plan/updated") {
|
|
16082
16403
|
const todos = array(params.plan).flatMap((value) => {
|
|
16083
|
-
const item =
|
|
16084
|
-
const content =
|
|
16404
|
+
const item = record3(value);
|
|
16405
|
+
const content = string2(item.step);
|
|
16085
16406
|
if (content === void 0) return [];
|
|
16086
16407
|
const status2 = item.status === "inProgress" ? "in_progress" : item.status === "completed" ? "completed" : "pending";
|
|
16087
16408
|
return [{ content, status: status2 }];
|
|
@@ -16090,8 +16411,8 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16090
16411
|
return;
|
|
16091
16412
|
}
|
|
16092
16413
|
if (frame.method === "item/commandExecution/outputDelta" || frame.method === "item/fileChange/outputDelta" || frame.method === "item/mcpToolCall/progress") {
|
|
16093
|
-
const itemId =
|
|
16094
|
-
const delta = frame.method === "item/mcpToolCall/progress" ?
|
|
16414
|
+
const itemId = string2(params.itemId);
|
|
16415
|
+
const delta = frame.method === "item/mcpToolCall/progress" ? string2(params.message) : string2(params.delta);
|
|
16095
16416
|
if (itemId === void 0 || delta === void 0) return;
|
|
16096
16417
|
const type = frame.method === "item/commandExecution/outputDelta" ? "commandExecution" : frame.method === "item/fileChange/outputDelta" ? "fileChange" : "mcpToolCall";
|
|
16097
16418
|
const item = follow.liveItems.get(itemId) ?? { id: itemId, type, status: "inProgress" };
|
|
@@ -16104,7 +16425,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16104
16425
|
return;
|
|
16105
16426
|
}
|
|
16106
16427
|
if (frame.method === "item/fileChange/patchUpdated") {
|
|
16107
|
-
const itemId =
|
|
16428
|
+
const itemId = string2(params.itemId);
|
|
16108
16429
|
if (itemId === void 0) return;
|
|
16109
16430
|
const previous = follow.liveItems.get(itemId) ?? { id: itemId, type: "fileChange", status: "inProgress" };
|
|
16110
16431
|
const item = { ...previous, changes: sanitizedFileChanges(params.changes) };
|
|
@@ -16114,7 +16435,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16114
16435
|
return;
|
|
16115
16436
|
}
|
|
16116
16437
|
if (frame.method === "thread/status/changed") {
|
|
16117
|
-
const status2 =
|
|
16438
|
+
const status2 = record3(params.status);
|
|
16118
16439
|
const running = status2.type === "active";
|
|
16119
16440
|
this.emitRemoteEvent("api-session/status", [follow.sessionId, running]);
|
|
16120
16441
|
if (status2.type === "systemError") {
|
|
@@ -16127,7 +16448,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16127
16448
|
return;
|
|
16128
16449
|
}
|
|
16129
16450
|
if (frame.method === "model/rerouted") {
|
|
16130
|
-
const model =
|
|
16451
|
+
const model = string2(params.toModel);
|
|
16131
16452
|
if (model === void 0) return;
|
|
16132
16453
|
const previous = this.selectedModels.get(follow.sessionId);
|
|
16133
16454
|
const selected = {
|
|
@@ -16141,8 +16462,8 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16141
16462
|
return;
|
|
16142
16463
|
}
|
|
16143
16464
|
if (frame.method === "turn/completed") {
|
|
16144
|
-
const turn =
|
|
16145
|
-
for (const item of array(turn.items)) this.acceptCompletedItem(follow,
|
|
16465
|
+
const turn = record3(params.turn);
|
|
16466
|
+
for (const item of array(turn.items)) this.acceptCompletedItem(follow, record3(item), true);
|
|
16146
16467
|
if (follow.stepOpen) {
|
|
16147
16468
|
this.closeAllStreamBlocks(follow);
|
|
16148
16469
|
if (follow.streamActive) this.finishStream(follow);
|
|
@@ -16162,7 +16483,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16162
16483
|
return;
|
|
16163
16484
|
}
|
|
16164
16485
|
if (frame.method === "item/commandExecution/requestApproval" || frame.method === "item/fileChange/requestApproval") {
|
|
16165
|
-
const requestHandle =
|
|
16486
|
+
const requestHandle = string2(params.requestHandle);
|
|
16166
16487
|
if (requestHandle === void 0) return;
|
|
16167
16488
|
const command = commandText(params.command);
|
|
16168
16489
|
this.pendingApprovals.set(requestHandle, { requestHandle, sessionId: follow.sessionId });
|
|
@@ -16177,9 +16498,9 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16177
16498
|
}
|
|
16178
16499
|
}
|
|
16179
16500
|
acceptCompletedItem(follow, item, settleAssistant) {
|
|
16180
|
-
const itemId =
|
|
16501
|
+
const itemId = string2(item.id) ?? `item:${follow.nextSeq}`;
|
|
16181
16502
|
if (follow.completedItems.has(itemId)) return;
|
|
16182
|
-
const type =
|
|
16503
|
+
const type = string2(item.type);
|
|
16183
16504
|
if (type === "agentMessage" && !settleAssistant) return;
|
|
16184
16505
|
follow.completedItems.add(itemId);
|
|
16185
16506
|
this.closeItemStreamBlocks(follow, itemId, itemText2(item));
|
|
@@ -16226,7 +16547,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16226
16547
|
time: Date.now(),
|
|
16227
16548
|
data: adaptEventData(
|
|
16228
16549
|
type,
|
|
16229
|
-
type === "assistant/message" && this.sessionGeneration === "v3" && follow.assistantAttempt !== void 0 ? { ...
|
|
16550
|
+
type === "assistant/message" && this.sessionGeneration === "v3" && follow.assistantAttempt !== void 0 ? { ...record3(data2), stream: follow.assistantAttempt.stream } : data2,
|
|
16230
16551
|
this.sessionGeneration
|
|
16231
16552
|
),
|
|
16232
16553
|
...isSurfaceEvent(type) ? placement === void 0 ? { surfaceOp: "append" } : {
|
|
@@ -16252,10 +16573,10 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16252
16573
|
}
|
|
16253
16574
|
cacheImageBlocks(sessionId, value) {
|
|
16254
16575
|
for (const block of collectImageBlocks(value)) {
|
|
16255
|
-
const attachment =
|
|
16256
|
-
const attachmentId =
|
|
16257
|
-
const data2 =
|
|
16258
|
-
if (attachmentId === void 0 || data2 === void 0 || !attachmentId.startsWith(
|
|
16576
|
+
const attachment = record3(block.attachment);
|
|
16577
|
+
const attachmentId = string2(attachment.attachmentId);
|
|
16578
|
+
const data2 = string2(block.data);
|
|
16579
|
+
if (attachmentId === void 0 || data2 === void 0 || !attachmentId.startsWith(CODEX_IMAGE_ATTACHMENT_PREFIX2)) continue;
|
|
16259
16580
|
this.imageAttachments.set(attachmentId, { sessionId, attachment, data: data2 });
|
|
16260
16581
|
}
|
|
16261
16582
|
}
|
|
@@ -16365,7 +16686,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16365
16686
|
}
|
|
16366
16687
|
}
|
|
16367
16688
|
ensureToolStarted(follow, item) {
|
|
16368
|
-
const itemId =
|
|
16689
|
+
const itemId = string2(item.id);
|
|
16369
16690
|
if (itemId === void 0) return;
|
|
16370
16691
|
if (!follow.startedItems.has(itemId)) follow.startedItems.add(itemId);
|
|
16371
16692
|
if (follow.liveItems.get(itemId) !== item) follow.liveItems.set(itemId, item);
|
|
@@ -16383,7 +16704,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16383
16704
|
}
|
|
16384
16705
|
}
|
|
16385
16706
|
emitToolResult(follow, item, resultText) {
|
|
16386
|
-
const itemId =
|
|
16707
|
+
const itemId = string2(item.id);
|
|
16387
16708
|
if (itemId === void 0) return;
|
|
16388
16709
|
const result = toolResultEvent(item, follow.turn, 1, itemId, resultText);
|
|
16389
16710
|
this.pushToolResult(follow, itemId, result);
|
|
@@ -16419,7 +16740,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16419
16740
|
this.broadcastRcHost({ type: "host/session-status", sessionId, running: args[1] });
|
|
16420
16741
|
} else if (event === "api-session/removed" && sessionId !== void 0) {
|
|
16421
16742
|
this.broadcastRcHost({ type: "host/session-removed", sessionId });
|
|
16422
|
-
} else if (event === "api-session/added" &&
|
|
16743
|
+
} else if (event === "api-session/added" && isRecord6(args[0])) {
|
|
16423
16744
|
const summary = args[0];
|
|
16424
16745
|
this.broadcastRcHost({
|
|
16425
16746
|
type: "host/session-added",
|
|
@@ -16441,13 +16762,13 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16441
16762
|
type: "approval/requested",
|
|
16442
16763
|
sessionId: input2.agentId,
|
|
16443
16764
|
approvalId: input2.eventId,
|
|
16444
|
-
toolName:
|
|
16765
|
+
toolName: string2(input2.request.toolName) ?? "CodeX",
|
|
16445
16766
|
...typeof input2.request.reason === "string" ? { reason: input2.request.reason } : {}
|
|
16446
16767
|
}, input2.eventId);
|
|
16447
16768
|
}
|
|
16448
16769
|
async answerRemoteEvent(args, signal) {
|
|
16449
|
-
const eventId =
|
|
16450
|
-
const outcome =
|
|
16770
|
+
const eventId = string2(args.eventId);
|
|
16771
|
+
const outcome = record3(args.outcome);
|
|
16451
16772
|
if (eventId === void 0) throw new Error("The CodeX approval result is missing its event id.");
|
|
16452
16773
|
const pending = this.pendingApprovals.get(eventId);
|
|
16453
16774
|
if (pending === void 0) return void 0;
|
|
@@ -16457,7 +16778,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16457
16778
|
return void 0;
|
|
16458
16779
|
}
|
|
16459
16780
|
async createWorkspace(request, signal) {
|
|
16460
|
-
const path =
|
|
16781
|
+
const path = string2(request.path);
|
|
16461
16782
|
if (path === void 0 || path.trim() === "") return failure("bad-request", "A CodeX working directory is required.");
|
|
16462
16783
|
const catalog = await this.currentCatalog(signal);
|
|
16463
16784
|
const existing = catalog.workspaces.find((item) => item.path === path);
|
|
@@ -16465,10 +16786,10 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16465
16786
|
return failure("workspace-not-found", "The selected directory is not visible to CodeX Remote.");
|
|
16466
16787
|
}
|
|
16467
16788
|
async renameWorkspace(request) {
|
|
16468
|
-
return failure("workspace-read-only", `CodeX virtual Workspace ${
|
|
16789
|
+
return failure("workspace-read-only", `CodeX virtual Workspace ${string2(request.workspaceId) ?? ""} cannot be renamed.`);
|
|
16469
16790
|
}
|
|
16470
16791
|
async workspaceForSession(request, signal) {
|
|
16471
|
-
const sessionId =
|
|
16792
|
+
const sessionId = string2(request.sessionId);
|
|
16472
16793
|
const catalog = await this.currentCatalog(signal);
|
|
16473
16794
|
const workspace = catalog.workspaces.find((item) => sessionId !== void 0 && item.sessionIds.includes(sessionId));
|
|
16474
16795
|
return workspace === void 0 ? failure("workspace-not-found", "The CodeX virtual Workspace was not found.") : success({ workspace: nativeWorkspace(workspace) });
|
|
@@ -16494,11 +16815,11 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16494
16815
|
const catalog = await this.currentCatalog(signal);
|
|
16495
16816
|
const workspace = this.selectedWorkspace(catalog);
|
|
16496
16817
|
if (workspace === void 0) return failure("workspace-not-found", "The CodeX virtual Workspace was not found.");
|
|
16497
|
-
const path =
|
|
16818
|
+
const path = string2(request.path) ?? workspace.path;
|
|
16498
16819
|
if (!containsPath(workspace.path, path)) {
|
|
16499
16820
|
return failure("workspace-not-found", "The selected directory is outside the current CodeX virtual Workspace.");
|
|
16500
16821
|
}
|
|
16501
|
-
const listing =
|
|
16822
|
+
const listing = record3(await this.client.request("dsh/directoryList", { path }, signal));
|
|
16502
16823
|
if (!isCodexDirectoryListing(listing)) {
|
|
16503
16824
|
return failure("internal", "CodeX Remote returned an invalid directory listing.");
|
|
16504
16825
|
}
|
|
@@ -16522,9 +16843,9 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16522
16843
|
}
|
|
16523
16844
|
async createSession(request, signal) {
|
|
16524
16845
|
const catalog = await this.currentCatalog(signal);
|
|
16525
|
-
const workspaceId =
|
|
16846
|
+
const workspaceId = string2(request.workspaceId) ?? this.selectedWorkspaceId;
|
|
16526
16847
|
const workspace = workspaceId === void 0 ? void 0 : catalog.workspaces.find((item) => item.workspaceId === workspaceId);
|
|
16527
|
-
const cwd =
|
|
16848
|
+
const cwd = string2(request.cwd) ?? workspace?.path;
|
|
16528
16849
|
if (cwd === void 0) return failure("workspace-not-found", "The CodeX virtual Workspace was not found.");
|
|
16529
16850
|
if (workspace !== void 0 && !containsPath(workspace.path, cwd)) {
|
|
16530
16851
|
return failure("workspace-not-found", "The selected directory is outside the current CodeX virtual Workspace.");
|
|
@@ -16532,13 +16853,13 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16532
16853
|
const directory = await this.models(signal);
|
|
16533
16854
|
const selection = directory.default;
|
|
16534
16855
|
const requestedPreset = CODEX_DEFAULT_PERMISSION;
|
|
16535
|
-
const result =
|
|
16856
|
+
const result = record3(await this.client.request("thread/start", {
|
|
16536
16857
|
cwd,
|
|
16537
16858
|
model: selection.model,
|
|
16538
16859
|
permissionPreset: requestedPreset
|
|
16539
16860
|
}, signal));
|
|
16540
16861
|
const permissionPreset2 = codexPermissionPresetFromResponse(result) ?? requestedPreset;
|
|
16541
|
-
const thread = { ...
|
|
16862
|
+
const thread = { ...record3(result.thread), cwd, turns: array(record3(result.thread).turns) };
|
|
16542
16863
|
const projected = projectCodexThread(thread);
|
|
16543
16864
|
if (projected === void 0) return failure("internal", "CodeX returned an invalid Thread.");
|
|
16544
16865
|
this.pendingThreads.set(projected.nativeId, thread);
|
|
@@ -16558,11 +16879,11 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16558
16879
|
}
|
|
16559
16880
|
async forkSession(request, signal) {
|
|
16560
16881
|
const sessionId = requiredString(request.sessionId, "sessionId");
|
|
16561
|
-
const result =
|
|
16882
|
+
const result = record3(await this.client.request("thread/fork", {
|
|
16562
16883
|
threadId: nativeThreadId(sessionId)
|
|
16563
16884
|
}, signal));
|
|
16564
16885
|
const permissionPreset2 = codexPermissionPresetFromResponse(result);
|
|
16565
|
-
const projected = projectCodexThread(
|
|
16886
|
+
const projected = projectCodexThread(record3(result.thread));
|
|
16566
16887
|
if (projected === void 0) return failure("internal", "CodeX returned an invalid forked Thread.");
|
|
16567
16888
|
this.selectedModels.set(projected.id, this.modelSelection(sessionId, await this.models(signal)));
|
|
16568
16889
|
this.setPermissionSelection(projected.id, permissionPreset2);
|
|
@@ -16590,7 +16911,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16590
16911
|
this.setPermissionSelection(sessionId, serverPreset);
|
|
16591
16912
|
}
|
|
16592
16913
|
}
|
|
16593
|
-
this.pendingRequestIds.set(sessionId,
|
|
16914
|
+
this.pendingRequestIds.set(sessionId, string2(request.requestId) ?? "");
|
|
16594
16915
|
const mode = request.mode === "steer" ? "turn/steer" : "turn/start";
|
|
16595
16916
|
if (mode === "turn/steer") {
|
|
16596
16917
|
const active = this.activeTurnId(threadId);
|
|
@@ -16609,7 +16930,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16609
16930
|
async attachment(request, signal) {
|
|
16610
16931
|
const sessionId = requiredString(request.sessionId, "sessionId");
|
|
16611
16932
|
const attachmentId = requiredString(request.attachmentId, "attachmentId");
|
|
16612
|
-
if (!attachmentId.startsWith(
|
|
16933
|
+
if (!attachmentId.startsWith(CODEX_IMAGE_ATTACHMENT_PREFIX2)) {
|
|
16613
16934
|
return failure("attachment-error", "The CodeX image is not available in this virtual Session.", { reason: "not-referenced" });
|
|
16614
16935
|
}
|
|
16615
16936
|
nativeThreadId(sessionId);
|
|
@@ -16621,9 +16942,9 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16621
16942
|
}
|
|
16622
16943
|
async hydrateImageAttachments(sessionId, signal) {
|
|
16623
16944
|
const threadId = nativeThreadId(sessionId);
|
|
16624
|
-
const result =
|
|
16625
|
-
const thread =
|
|
16626
|
-
if (
|
|
16945
|
+
const result = record3(await this.client.request("thread/read", { threadId, includeTurns: true }, signal));
|
|
16946
|
+
const thread = record3(result.thread);
|
|
16947
|
+
if (string2(thread.id) !== threadId) throw new Error("CodeX returned an invalid Thread history.");
|
|
16627
16948
|
this.cacheHistoryImages(projectCodexNativeHistory(thread, sessionId));
|
|
16628
16949
|
}
|
|
16629
16950
|
async cancel(request, signal) {
|
|
@@ -16644,7 +16965,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16644
16965
|
return success({ title, seq });
|
|
16645
16966
|
}
|
|
16646
16967
|
async sessionPage(request, signal) {
|
|
16647
|
-
const sessionId = sessionIdFromAddress(
|
|
16968
|
+
const sessionId = sessionIdFromAddress(record3(request.address));
|
|
16648
16969
|
const page = await this.readHistoryPage(nativeThreadId(sessionId), {
|
|
16649
16970
|
beforeSeq: optionalNonNegativeInteger(request.beforeSeq),
|
|
16650
16971
|
throughSeq: optionalInteger(request.throughSeq),
|
|
@@ -16657,15 +16978,15 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16657
16978
|
return void 0;
|
|
16658
16979
|
}
|
|
16659
16980
|
async fetchThread(threadId, signal) {
|
|
16660
|
-
const result =
|
|
16661
|
-
const thread =
|
|
16662
|
-
if (
|
|
16981
|
+
const result = record3(await this.client.request("thread/read", { threadId, includeTurns: false }, signal));
|
|
16982
|
+
const thread = record3(result.thread);
|
|
16983
|
+
if (string2(thread.id) !== threadId) throw new Error("CodeX returned an invalid Thread history.");
|
|
16663
16984
|
return thread;
|
|
16664
16985
|
}
|
|
16665
16986
|
async readHistoryPage(threadId, page, signal) {
|
|
16666
16987
|
let value;
|
|
16667
16988
|
try {
|
|
16668
|
-
value =
|
|
16989
|
+
value = record3(await this.client.request("dsh/sessionHistory", {
|
|
16669
16990
|
threadId,
|
|
16670
16991
|
...page.beforeSeq === void 0 ? {} : { beforeSeq: page.beforeSeq },
|
|
16671
16992
|
...page.throughSeq === void 0 ? {} : { throughSeq: page.throughSeq },
|
|
@@ -16673,9 +16994,9 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16673
16994
|
}, signal));
|
|
16674
16995
|
} catch (error) {
|
|
16675
16996
|
if (!isLegacySessionHistoryUnsupported(error)) throw error;
|
|
16676
|
-
const result =
|
|
16677
|
-
const thread =
|
|
16678
|
-
if (
|
|
16997
|
+
const result = record3(await this.client.request("thread/read", { threadId, includeTurns: true }, signal));
|
|
16998
|
+
const thread = record3(result.thread);
|
|
16999
|
+
if (string2(thread.id) !== threadId) throw new Error("CodeX returned an invalid Thread history.");
|
|
16679
17000
|
value = paginateCodexNativeHistory(
|
|
16680
17001
|
projectCodexNativeHistory(thread, `codex:${threadId}`, this.sessionGeneration),
|
|
16681
17002
|
{
|
|
@@ -16804,7 +17125,7 @@ var CodexVirtualHarness = class _CodexVirtualHarness {
|
|
|
16804
17125
|
}
|
|
16805
17126
|
createApiProxy() {
|
|
16806
17127
|
const call = (endpoint) => async (request, signal) => {
|
|
16807
|
-
const payload = endpoint === "session.prompt" &&
|
|
17128
|
+
const payload = endpoint === "session.prompt" && isRecord6(request.payload) ? { ...request.payload, requestId: String(request.rpcId) } : request.payload;
|
|
16808
17129
|
const result = await this.dispatch(rcEndpoint(endpoint), { args: { request: payload } }, signal ?? new AbortController().signal);
|
|
16809
17130
|
return {
|
|
16810
17131
|
rpcId: request.rpcId,
|
|
@@ -16901,7 +17222,7 @@ async function loadCatalog(client, signal, pendingThreads) {
|
|
|
16901
17222
|
const threads = [];
|
|
16902
17223
|
let cursor2;
|
|
16903
17224
|
for (let page = 0; page < MAX_CODEX_PAGES; page += 1) {
|
|
16904
|
-
const result =
|
|
17225
|
+
const result = record3(await client.request("thread/list", {
|
|
16905
17226
|
limit: CODEX_PAGE_LIMIT,
|
|
16906
17227
|
sortKey: "updated_at",
|
|
16907
17228
|
sortDirection: "desc",
|
|
@@ -16909,14 +17230,14 @@ async function loadCatalog(client, signal, pendingThreads) {
|
|
|
16909
17230
|
...cursor2 === void 0 ? {} : { cursor: cursor2 }
|
|
16910
17231
|
}, signal));
|
|
16911
17232
|
for (const value of array(result.data)) {
|
|
16912
|
-
const thread =
|
|
16913
|
-
if (
|
|
17233
|
+
const thread = record3(value);
|
|
17234
|
+
if (string2(thread.id) !== void 0) threads.push(thread);
|
|
16914
17235
|
}
|
|
16915
17236
|
cursor2 = typeof result.nextCursor === "string" && result.nextCursor.length > 0 ? result.nextCursor : void 0;
|
|
16916
17237
|
if (cursor2 === void 0) break;
|
|
16917
17238
|
}
|
|
16918
17239
|
if (pendingThreads !== void 0) {
|
|
16919
|
-
const listedIds = new Set(threads.map((thread) =>
|
|
17240
|
+
const listedIds = new Set(threads.map((thread) => string2(thread.id)).filter((id4) => id4 !== void 0));
|
|
16920
17241
|
for (const [threadId, thread] of pendingThreads) {
|
|
16921
17242
|
if (listedIds.has(threadId)) pendingThreads.delete(threadId);
|
|
16922
17243
|
else threads.unshift(thread);
|
|
@@ -16961,7 +17282,7 @@ async function loadCodexProjects(client, signal) {
|
|
|
16961
17282
|
let cursor2;
|
|
16962
17283
|
try {
|
|
16963
17284
|
for (let page = 0; page < MAX_CODEX_PAGES; page += 1) {
|
|
16964
|
-
const result =
|
|
17285
|
+
const result = record3(await client.request("project/list", {
|
|
16965
17286
|
limit: CODEX_PAGE_LIMIT,
|
|
16966
17287
|
...cursor2 === void 0 ? {} : { cursor: cursor2 }
|
|
16967
17288
|
}, signal));
|
|
@@ -16983,32 +17304,32 @@ async function loadModelDirectory(client, signal) {
|
|
|
16983
17304
|
let defaultModelId;
|
|
16984
17305
|
let cursor2;
|
|
16985
17306
|
for (let page = 0; page < MAX_CODEX_PAGES; page += 1) {
|
|
16986
|
-
const result =
|
|
17307
|
+
const result = record3(await client.request("model/list", {
|
|
16987
17308
|
limit: CODEX_PAGE_LIMIT,
|
|
16988
17309
|
includeHidden: false,
|
|
16989
17310
|
...cursor2 === void 0 ? {} : { cursor: cursor2 }
|
|
16990
17311
|
}, signal));
|
|
16991
17312
|
for (const value of array(result.data)) {
|
|
16992
|
-
const source =
|
|
17313
|
+
const source = record3(value);
|
|
16993
17314
|
if (source.hidden === true) continue;
|
|
16994
|
-
const id4 =
|
|
17315
|
+
const id4 = string2(source.model) ?? string2(source.id);
|
|
16995
17316
|
if (id4 === void 0 || models.has(id4)) continue;
|
|
16996
17317
|
const efforts = array(source.supportedReasoningEfforts).map((value2) => {
|
|
16997
|
-
const effort =
|
|
16998
|
-
const effortId =
|
|
17318
|
+
const effort = record3(value2);
|
|
17319
|
+
const effortId = string2(effort.reasoningEffort);
|
|
16999
17320
|
if (effortId === void 0) return void 0;
|
|
17000
|
-
const description2 =
|
|
17321
|
+
const description2 = string2(effort.description);
|
|
17001
17322
|
return {
|
|
17002
17323
|
id: effortId,
|
|
17003
17324
|
name: reasoningEffortName(effortId),
|
|
17004
17325
|
...description2 === void 0 ? {} : { description: description2 }
|
|
17005
17326
|
};
|
|
17006
17327
|
}).filter((value2) => value2 !== void 0);
|
|
17007
|
-
const defaultEffort2 =
|
|
17008
|
-
const description =
|
|
17328
|
+
const defaultEffort2 = string2(source.defaultReasoningEffort);
|
|
17329
|
+
const description = string2(source.description);
|
|
17009
17330
|
const model = {
|
|
17010
17331
|
id: id4,
|
|
17011
|
-
name:
|
|
17332
|
+
name: string2(source.displayName) ?? id4,
|
|
17012
17333
|
...description === void 0 ? {} : { description },
|
|
17013
17334
|
...efforts.length === 0 ? {} : {
|
|
17014
17335
|
reasoning: {
|
|
@@ -17058,8 +17379,8 @@ function projectCodexNativeHistory(thread, sessionId, sessionGeneration = "legac
|
|
|
17058
17379
|
return eventSeq;
|
|
17059
17380
|
};
|
|
17060
17381
|
for (const rawTurn of array(thread.turns)) {
|
|
17061
|
-
const turn =
|
|
17062
|
-
const turnItems = array(turn.items).map(
|
|
17382
|
+
const turn = record3(rawTurn);
|
|
17383
|
+
const turnItems = array(turn.items).map(record3);
|
|
17063
17384
|
const toolImages = turnItems.flatMap(toolOutputImageBlocks);
|
|
17064
17385
|
let imageOwner = -1;
|
|
17065
17386
|
for (let index = 0; index < turnItems.length; index += 1) {
|
|
@@ -17141,18 +17462,18 @@ function paginateCodexNativeHistory(history, request) {
|
|
|
17141
17462
|
}
|
|
17142
17463
|
function adaptEventData(type, data2, sessionGeneration) {
|
|
17143
17464
|
if (sessionGeneration !== "v3" || type !== "assistant/message") return data2;
|
|
17144
|
-
const value =
|
|
17465
|
+
const value = record3(data2);
|
|
17145
17466
|
return Array.isArray(value.stream) ? value : { ...value, stream: [] };
|
|
17146
17467
|
}
|
|
17147
17468
|
function adaptCodexHistoryPage(value, sessionGeneration) {
|
|
17148
17469
|
if (sessionGeneration !== "v3") return value;
|
|
17149
|
-
const page =
|
|
17150
|
-
const sourceHeader =
|
|
17470
|
+
const page = record3(value);
|
|
17471
|
+
const sourceHeader = record3(page.header);
|
|
17151
17472
|
const { seedLength: _seedLength, ...header } = sourceHeader;
|
|
17152
17473
|
const records = Array.isArray(page.records) ? page.records.map((raw) => {
|
|
17153
|
-
const entry =
|
|
17154
|
-
const sourceEvent =
|
|
17155
|
-
const sourceSurfaceOp =
|
|
17474
|
+
const entry = record3(raw);
|
|
17475
|
+
const sourceEvent = record3(entry.event);
|
|
17476
|
+
const sourceSurfaceOp = record3(sourceEvent.surfaceOp);
|
|
17156
17477
|
const surfaceOp = sourceEvent.surfaceOp === "append" ? "append" : sourceSurfaceOp.op === "replace" && integer(sourceSurfaceOp.startSeq) !== void 0 && integer(sourceSurfaceOp.endSeq) !== void 0 ? sourceSurfaceOp : sourceSurfaceOp.op === "replace" && integer(sourceSurfaceOp.start) !== void 0 && integer(sourceSurfaceOp.end) !== void 0 ? {
|
|
17157
17478
|
op: "replace",
|
|
17158
17479
|
startSeq: sourceSurfaceOp.start,
|
|
@@ -17162,7 +17483,7 @@ function adaptCodexHistoryPage(value, sessionGeneration) {
|
|
|
17162
17483
|
...entry,
|
|
17163
17484
|
event: {
|
|
17164
17485
|
...sourceEvent,
|
|
17165
|
-
data: adaptEventData(
|
|
17486
|
+
data: adaptEventData(string2(sourceEvent.type) ?? "", sourceEvent.data, sessionGeneration),
|
|
17166
17487
|
...surfaceOp === void 0 ? {} : { surfaceOp }
|
|
17167
17488
|
}
|
|
17168
17489
|
};
|
|
@@ -17174,8 +17495,8 @@ function adaptCodexHistoryPage(value, sessionGeneration) {
|
|
|
17174
17495
|
};
|
|
17175
17496
|
}
|
|
17176
17497
|
function itemEvents(item, turn, step, requestId, selection = modelSelection(), sessionId = CODEX_SESSION_PREFIX, supplementalImages = []) {
|
|
17177
|
-
const type =
|
|
17178
|
-
const id4 =
|
|
17498
|
+
const type = string2(item.type);
|
|
17499
|
+
const id4 = string2(item.id) ?? `${turn}:${step}:${hashString2(JSON.stringify(item))}`;
|
|
17179
17500
|
const text = itemText2(item);
|
|
17180
17501
|
if (type === "userMessage") return [{
|
|
17181
17502
|
type: "user/message",
|
|
@@ -17217,232 +17538,32 @@ function itemEvents(item, turn, step, requestId, selection = modelSelection(), s
|
|
|
17217
17538
|
toolResultEvent(item, turn, step, id4, toolResultText(item, type, text))
|
|
17218
17539
|
];
|
|
17219
17540
|
}
|
|
17220
|
-
if (type === "error") return [{
|
|
17221
|
-
type: "assistant/message",
|
|
17222
|
-
data: {
|
|
17223
|
-
turn,
|
|
17224
|
-
step,
|
|
17225
|
-
message: {
|
|
17226
|
-
id: id4,
|
|
17227
|
-
role: "assistant",
|
|
17228
|
-
content: [{ type: "text", text: text ?? "CodeX reported an error." }],
|
|
17229
|
-
source: { kind: "model", provider: selection.provider, model: selection.model }
|
|
17230
|
-
}
|
|
17231
|
-
}
|
|
17232
|
-
}];
|
|
17233
|
-
return [];
|
|
17234
|
-
}
|
|
17235
|
-
function messageContent(item, attachmentSeed, fallbackType, fallbackText, supplementalImages = []) {
|
|
17236
|
-
const source = item.content ?? item.input;
|
|
17237
|
-
const blocks = contentBlocks(source, attachmentSeed);
|
|
17238
|
-
const images = contentBlocks(supplementalImages, `${attachmentSeed}:tool-output`);
|
|
17239
|
-
if (blocks.length > 0 || images.length > 0) {
|
|
17240
|
-
return [...blocks.length > 0 ? blocks : [{ type: fallbackType, text: fallbackText ?? "" }], ...images];
|
|
17241
|
-
}
|
|
17242
|
-
return [{ type: fallbackType, text: fallbackText ?? "" }];
|
|
17243
|
-
}
|
|
17244
|
-
function toolOutputImageBlocks(item) {
|
|
17245
|
-
const candidates = [
|
|
17246
|
-
record2(item.result).content,
|
|
17247
|
-
record2(item.output).content,
|
|
17248
|
-
item.contentItems,
|
|
17249
|
-
Array.isArray(item.output) ? item.output : void 0
|
|
17250
|
-
];
|
|
17251
|
-
for (const candidate of candidates) {
|
|
17252
|
-
if (!Array.isArray(candidate)) continue;
|
|
17253
|
-
const images = candidate.flatMap((value) => {
|
|
17254
|
-
const block = record2(value);
|
|
17255
|
-
return isImageContent2(block) && parseImageBlock(block) !== void 0 ? [block] : [];
|
|
17256
|
-
});
|
|
17257
|
-
if (images.length > 0) return images;
|
|
17258
|
-
}
|
|
17259
|
-
return [];
|
|
17260
|
-
}
|
|
17261
|
-
function contentBlocks(value, attachmentSeed) {
|
|
17262
|
-
if (typeof value === "string") return [{ type: "text", text: value }];
|
|
17263
|
-
if (!Array.isArray(value)) return [];
|
|
17264
|
-
const blocks = [];
|
|
17265
|
-
let imageIndex = 0;
|
|
17266
|
-
for (const raw of value) {
|
|
17267
|
-
if (typeof raw === "string") {
|
|
17268
|
-
blocks.push({ type: "text", text: raw });
|
|
17269
|
-
continue;
|
|
17270
|
-
}
|
|
17271
|
-
const block = record2(raw);
|
|
17272
|
-
const image = imageContentBlock(block, attachmentSeed, imageIndex);
|
|
17273
|
-
if (image !== void 0) {
|
|
17274
|
-
imageIndex += 1;
|
|
17275
|
-
blocks.push(image);
|
|
17276
|
-
continue;
|
|
17277
|
-
}
|
|
17278
|
-
const text = string(block.text) ?? string(block.content);
|
|
17279
|
-
if (text !== void 0) blocks.push({ type: block.type === "reasoning" ? "reasoning" : "text", text });
|
|
17280
|
-
}
|
|
17281
|
-
return blocks;
|
|
17282
|
-
}
|
|
17283
|
-
function imageContentBlock(block, attachmentSeed, index) {
|
|
17284
|
-
if (!isImageContent2(block)) return void 0;
|
|
17285
|
-
const image = parseImageBlock(block);
|
|
17286
|
-
if (image === void 0) return void 0;
|
|
17287
|
-
const dimensions = imageDimensions(image.mediaType, image.data);
|
|
17288
|
-
const name2 = string(block.name);
|
|
17289
|
-
const attachment = {
|
|
17290
|
-
attachmentId: `${CODEX_IMAGE_ATTACHMENT_PREFIX}${hashString(`${attachmentSeed}:${index}`)}:${index}`,
|
|
17291
|
-
mediaType: image.mediaType,
|
|
17292
|
-
bytes: base64ByteLength(image.data),
|
|
17293
|
-
width: dimensions.width,
|
|
17294
|
-
height: dimensions.height,
|
|
17295
|
-
...name2 === void 0 ? {} : { name: name2 }
|
|
17296
|
-
};
|
|
17297
|
-
return {
|
|
17298
|
-
type: "image",
|
|
17299
|
-
attachment,
|
|
17300
|
-
mediaType: image.mediaType,
|
|
17301
|
-
data: image.data,
|
|
17302
|
-
url: image.url,
|
|
17303
|
-
...name2 === void 0 ? {} : { name: name2 }
|
|
17304
|
-
};
|
|
17305
|
-
}
|
|
17306
|
-
function isImageContent2(block) {
|
|
17307
|
-
return block.type === "image" || block.type === "input_image";
|
|
17308
|
-
}
|
|
17309
|
-
function parseImageBlock(block) {
|
|
17310
|
-
const url = string(block.url) ?? string(block.image_url) ?? string(record2(block.image_url).url);
|
|
17311
|
-
const parsed = url === void 0 ? void 0 : parseDataImageUrl2(url);
|
|
17312
|
-
if (parsed !== void 0) return parsed;
|
|
17313
|
-
const data2 = string(block.data);
|
|
17314
|
-
if (data2 === void 0 || !isCanonicalBase642(data2)) return void 0;
|
|
17315
|
-
if (data2.length > MAX_CODEX_IMAGE_BASE64) return void 0;
|
|
17316
|
-
const mediaType = string(block.mediaType) ?? string(block.mimeType) ?? sniffImageMediaType2(data2);
|
|
17317
|
-
return mediaType !== void 0 && CODEX_IMAGE_MEDIA_TYPES2.has(mediaType) ? { mediaType, data: data2, url: `data:${mediaType};base64,${data2}` } : void 0;
|
|
17318
|
-
}
|
|
17319
|
-
function parseDataImageUrl2(value) {
|
|
17320
|
-
const match = DATA_IMAGE_URL2.exec(value);
|
|
17321
|
-
if (match === null) return void 0;
|
|
17322
|
-
const mediaType = match[1];
|
|
17323
|
-
const data2 = match[2];
|
|
17324
|
-
if (!CODEX_IMAGE_MEDIA_TYPES2.has(mediaType) || !isCanonicalBase642(data2)) return void 0;
|
|
17325
|
-
return { mediaType, data: data2, url: `data:${mediaType};base64,${data2}` };
|
|
17326
|
-
}
|
|
17327
|
-
function collectImageBlocks(value, output = []) {
|
|
17328
|
-
if (Array.isArray(value)) {
|
|
17329
|
-
for (const item of value) collectImageBlocks(item, output);
|
|
17330
|
-
return output;
|
|
17331
|
-
}
|
|
17332
|
-
if (!isRecord5(value)) return output;
|
|
17333
|
-
if (value.type === "image") output.push(value);
|
|
17334
|
-
for (const [key, child] of Object.entries(value)) {
|
|
17335
|
-
if (key === "attachment") continue;
|
|
17336
|
-
if (key === "content" || key === "message" || key === "inserted" || key === "chunk" || key === "block") {
|
|
17337
|
-
collectImageBlocks(child, output);
|
|
17338
|
-
}
|
|
17339
|
-
}
|
|
17340
|
-
return output;
|
|
17341
|
-
}
|
|
17342
|
-
function base64ByteLength(value) {
|
|
17343
|
-
const padding = value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0;
|
|
17344
|
-
return Math.max(1, Math.floor(value.length * 3 / 4) - padding);
|
|
17345
|
-
}
|
|
17346
|
-
function imageDimensions(mediaType, data2) {
|
|
17347
|
-
const bytes = base64PrefixBytes2(data2, 256 * 1024);
|
|
17348
|
-
const parsed = mediaType === "image/png" ? pngDimensions(bytes) : mediaType === "image/jpeg" ? jpegDimensions(bytes) : mediaType === "image/gif" ? gifDimensions(bytes) : mediaType === "image/webp" ? webpDimensions(bytes) : void 0;
|
|
17349
|
-
return parsed ?? { width: 1, height: 1 };
|
|
17350
|
-
}
|
|
17351
|
-
function pngDimensions(bytes) {
|
|
17352
|
-
if (bytes.length < 24 || bytes[0] !== 137 || bytes[1] !== 80 || bytes[2] !== 78 || bytes[3] !== 71 || bytes[4] !== 13 || bytes[5] !== 10 || bytes[6] !== 26 || bytes[7] !== 10) return void 0;
|
|
17353
|
-
return positiveDimensions(readUint32BE(bytes, 16), readUint32BE(bytes, 20));
|
|
17354
|
-
}
|
|
17355
|
-
function jpegDimensions(bytes) {
|
|
17356
|
-
if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216) return void 0;
|
|
17357
|
-
let offset = 2;
|
|
17358
|
-
while (offset + 9 < bytes.length) {
|
|
17359
|
-
if (bytes[offset] !== 255) {
|
|
17360
|
-
offset += 1;
|
|
17361
|
-
continue;
|
|
17362
|
-
}
|
|
17363
|
-
const marker = bytes[offset + 1];
|
|
17364
|
-
offset += 2;
|
|
17365
|
-
if (marker === 216 || marker === 217) continue;
|
|
17366
|
-
if (offset + 2 > bytes.length) return void 0;
|
|
17367
|
-
const length = readUint16BE(bytes, offset);
|
|
17368
|
-
if (length < 2 || offset + length > bytes.length) return void 0;
|
|
17369
|
-
if (isJpegSof(marker) && length >= 7) {
|
|
17370
|
-
return positiveDimensions(readUint16BE(bytes, offset + 5), readUint16BE(bytes, offset + 3));
|
|
17371
|
-
}
|
|
17372
|
-
offset += length;
|
|
17373
|
-
}
|
|
17374
|
-
return void 0;
|
|
17375
|
-
}
|
|
17376
|
-
function gifDimensions(bytes) {
|
|
17377
|
-
if (bytes.length < 10 || bytes[0] !== 71 || bytes[1] !== 73 || bytes[2] !== 70 || bytes[3] !== 56 || bytes[4] !== 55 && bytes[4] !== 57 || bytes[5] !== 97) return void 0;
|
|
17378
|
-
return positiveDimensions(readUint16LE(bytes, 6), readUint16LE(bytes, 8));
|
|
17379
|
-
}
|
|
17380
|
-
function webpDimensions(bytes) {
|
|
17381
|
-
if (bytes.length < 30 || stringFromBytes(bytes, 0, 4) !== "RIFF" || stringFromBytes(bytes, 8, 12) !== "WEBP") return void 0;
|
|
17382
|
-
const chunk = stringFromBytes(bytes, 12, 16);
|
|
17383
|
-
if (chunk === "VP8X") {
|
|
17384
|
-
return positiveDimensions(1 + readUint24LE(bytes, 24), 1 + readUint24LE(bytes, 27));
|
|
17385
|
-
}
|
|
17386
|
-
if (chunk === "VP8L" && bytes[20] === 47) {
|
|
17387
|
-
const b0 = bytes[21];
|
|
17388
|
-
const b1 = bytes[22];
|
|
17389
|
-
const b2 = bytes[23];
|
|
17390
|
-
const b3 = bytes[24];
|
|
17391
|
-
const width = 1 + b0 + ((b1 & 63) << 8);
|
|
17392
|
-
const height = 1 + ((b1 & 192) >> 6) + (b2 << 2) + ((b3 & 15) << 10);
|
|
17393
|
-
return positiveDimensions(width, height);
|
|
17394
|
-
}
|
|
17395
|
-
if (chunk === "VP8 " && bytes[23] === 157 && bytes[24] === 1 && bytes[25] === 42) {
|
|
17396
|
-
return positiveDimensions(readUint16LE(bytes, 26) & 16383, readUint16LE(bytes, 28) & 16383);
|
|
17397
|
-
}
|
|
17398
|
-
return void 0;
|
|
17399
|
-
}
|
|
17400
|
-
function sniffImageMediaType2(data2) {
|
|
17401
|
-
const bytes = base64PrefixBytes2(data2, 32);
|
|
17402
|
-
if (pngDimensions(bytes) !== void 0) return "image/png";
|
|
17403
|
-
if (bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return "image/jpeg";
|
|
17404
|
-
if (gifDimensions(bytes) !== void 0) return "image/gif";
|
|
17405
|
-
if (bytes.length >= 12 && stringFromBytes(bytes, 0, 4) === "RIFF" && stringFromBytes(bytes, 8, 12) === "WEBP") return "image/webp";
|
|
17406
|
-
return void 0;
|
|
17407
|
-
}
|
|
17408
|
-
function base64PrefixBytes2(value, maxBytes) {
|
|
17409
|
-
const chars = value.slice(0, Math.ceil(maxBytes / 3) * 4);
|
|
17410
|
-
let binary;
|
|
17411
|
-
try {
|
|
17412
|
-
binary = atob(chars);
|
|
17413
|
-
} catch {
|
|
17414
|
-
return new Uint8Array();
|
|
17415
|
-
}
|
|
17416
|
-
const bytes = new Uint8Array(Math.min(binary.length, maxBytes));
|
|
17417
|
-
for (let index = 0; index < bytes.length; index += 1) bytes[index] = binary.charCodeAt(index);
|
|
17418
|
-
return bytes;
|
|
17419
|
-
}
|
|
17420
|
-
function readUint16BE(bytes, offset) {
|
|
17421
|
-
return (bytes[offset] << 8) + bytes[offset + 1];
|
|
17422
|
-
}
|
|
17423
|
-
function readUint16LE(bytes, offset) {
|
|
17424
|
-
return bytes[offset] + (bytes[offset + 1] << 8);
|
|
17425
|
-
}
|
|
17426
|
-
function readUint24LE(bytes, offset) {
|
|
17427
|
-
return bytes[offset] + (bytes[offset + 1] << 8) + (bytes[offset + 2] << 16);
|
|
17428
|
-
}
|
|
17429
|
-
function readUint32BE(bytes, offset) {
|
|
17430
|
-
return bytes[offset] * 16777216 + bytes[offset + 1] * 65536 + bytes[offset + 2] * 256 + bytes[offset + 3];
|
|
17431
|
-
}
|
|
17432
|
-
function positiveDimensions(width, height) {
|
|
17433
|
-
return width > 0 && height > 0 ? { width, height } : void 0;
|
|
17434
|
-
}
|
|
17435
|
-
function isJpegSof(marker) {
|
|
17436
|
-
return marker >= 192 && marker <= 195 || marker >= 197 && marker <= 199 || marker >= 201 && marker <= 203 || marker >= 205 && marker <= 207;
|
|
17541
|
+
if (type === "error") return [{
|
|
17542
|
+
type: "assistant/message",
|
|
17543
|
+
data: {
|
|
17544
|
+
turn,
|
|
17545
|
+
step,
|
|
17546
|
+
message: {
|
|
17547
|
+
id: id4,
|
|
17548
|
+
role: "assistant",
|
|
17549
|
+
content: [{ type: "text", text: text ?? "CodeX reported an error." }],
|
|
17550
|
+
source: { kind: "model", provider: selection.provider, model: selection.model }
|
|
17551
|
+
}
|
|
17552
|
+
}
|
|
17553
|
+
}];
|
|
17554
|
+
return [];
|
|
17437
17555
|
}
|
|
17438
|
-
function
|
|
17439
|
-
|
|
17440
|
-
|
|
17441
|
-
|
|
17442
|
-
|
|
17556
|
+
function messageContent(item, attachmentSeed, fallbackType, fallbackText, supplementalImages = []) {
|
|
17557
|
+
const source = item.content ?? item.input;
|
|
17558
|
+
const blocks = contentBlocks(source, attachmentSeed);
|
|
17559
|
+
const images = contentBlocks(supplementalImages, `${attachmentSeed}:tool-output`);
|
|
17560
|
+
if (blocks.length > 0 || images.length > 0) {
|
|
17561
|
+
return [...blocks.length > 0 ? blocks : [{ type: fallbackType, text: fallbackText ?? "" }], ...images];
|
|
17562
|
+
}
|
|
17563
|
+
return [{ type: fallbackType, text: fallbackText ?? "" }];
|
|
17443
17564
|
}
|
|
17444
17565
|
function toolResultEvent(item, turn, step, id4, resultText) {
|
|
17445
|
-
const type =
|
|
17566
|
+
const type = string2(item.type) ?? "unknown";
|
|
17446
17567
|
return {
|
|
17447
17568
|
type: "tool/result",
|
|
17448
17569
|
data: {
|
|
@@ -17464,10 +17585,10 @@ function toolResultEvent(item, turn, step, id4, resultText) {
|
|
|
17464
17585
|
};
|
|
17465
17586
|
}
|
|
17466
17587
|
function toolResultContentReplacement(event) {
|
|
17467
|
-
const data2 =
|
|
17468
|
-
const message =
|
|
17588
|
+
const data2 = record3(event.data);
|
|
17589
|
+
const message = record3(data2.message);
|
|
17469
17590
|
const content = array(message.content);
|
|
17470
|
-
const result =
|
|
17591
|
+
const result = record3(content[0]);
|
|
17471
17592
|
if (result.isError === void 0) return event;
|
|
17472
17593
|
const { isError: _isError, ...stableResult } = result;
|
|
17473
17594
|
return {
|
|
@@ -17497,19 +17618,19 @@ function toolResultText(item, type, text) {
|
|
|
17497
17618
|
const count = array(item.results).length;
|
|
17498
17619
|
return count === 0 ? "Web search completed." : `Web search returned ${count} result${count === 1 ? "" : "s"}.`;
|
|
17499
17620
|
}
|
|
17500
|
-
if (type === "imageView") return `Viewed image: ${
|
|
17621
|
+
if (type === "imageView") return `Viewed image: ${string2(item.path) ?? "image"}`;
|
|
17501
17622
|
if (type === "imageGeneration") {
|
|
17502
|
-
const savedPath =
|
|
17503
|
-
return savedPath === void 0 ? `Image generation ${
|
|
17623
|
+
const savedPath = string2(item.savedPath);
|
|
17624
|
+
return savedPath === void 0 ? `Image generation ${string2(item.status) ?? "completed"}.` : `Generated image: ${savedPath}`;
|
|
17504
17625
|
}
|
|
17505
17626
|
if (type === "contextCompaction") return "CodeX compacted the conversation context.";
|
|
17506
|
-
if (type === "enteredReviewMode") return `Entered review mode${
|
|
17507
|
-
if (type === "exitedReviewMode") return `Exited review mode${
|
|
17627
|
+
if (type === "enteredReviewMode") return `Entered review mode${string2(item.review) ? `: ${string2(item.review)}` : "."}`;
|
|
17628
|
+
if (type === "exitedReviewMode") return `Exited review mode${string2(item.review) ? `: ${string2(item.review)}` : "."}`;
|
|
17508
17629
|
if (type === "sleep") return `Waited ${integer(item.durationMs) ?? 0} ms.`;
|
|
17509
17630
|
if (type === "subAgentActivity") {
|
|
17510
|
-
return [
|
|
17631
|
+
return [string2(record3(item.kind).type) ?? string2(item.kind) ?? "Subagent activity", string2(item.agentPath)].filter((value) => value !== void 0).join(": ");
|
|
17511
17632
|
}
|
|
17512
|
-
return text ?? itemText2(
|
|
17633
|
+
return text ?? itemText2(record3(item.result)) ?? itemText2(record3(item.output)) ?? string2(item.status) ?? type;
|
|
17513
17634
|
}
|
|
17514
17635
|
function isSurfaceEvent(type) {
|
|
17515
17636
|
return type === "user/message" || type === "assistant/message" || type === "tool/result";
|
|
@@ -17535,13 +17656,13 @@ function toolCallView(item, type, args) {
|
|
|
17535
17656
|
if (type === "webSearch") {
|
|
17536
17657
|
return {
|
|
17537
17658
|
card: "generic",
|
|
17538
|
-
title:
|
|
17659
|
+
title: string2(item.query) ?? "CodeX web search",
|
|
17539
17660
|
kind: "search",
|
|
17540
17661
|
rawInput: args
|
|
17541
17662
|
};
|
|
17542
17663
|
}
|
|
17543
17664
|
if (type === "imageView" || type === "imageGeneration") {
|
|
17544
|
-
const path =
|
|
17665
|
+
const path = string2(item.path) ?? string2(item.savedPath);
|
|
17545
17666
|
return {
|
|
17546
17667
|
card: "generic",
|
|
17547
17668
|
title: type === "imageView" ? "View image" : "Generate image",
|
|
@@ -17552,7 +17673,7 @@ function toolCallView(item, type, args) {
|
|
|
17552
17673
|
if (type === "collabAgentToolCall" || type === "subAgentActivity") {
|
|
17553
17674
|
return {
|
|
17554
17675
|
card: "generic",
|
|
17555
|
-
title: type === "collabAgentToolCall" ? `Subagent: ${
|
|
17676
|
+
title: type === "collabAgentToolCall" ? `Subagent: ${string2(item.tool) ?? "collaboration"}` : `Subagent activity: ${string2(item.agentPath) ?? string2(item.agentThreadId) ?? "agent"}`,
|
|
17556
17677
|
kind: "other",
|
|
17557
17678
|
rawInput: args
|
|
17558
17679
|
};
|
|
@@ -17581,10 +17702,10 @@ function toolResultView(item, type, resultText) {
|
|
|
17581
17702
|
};
|
|
17582
17703
|
}
|
|
17583
17704
|
function toolDisplayName(item, type) {
|
|
17584
|
-
return
|
|
17705
|
+
return string2(item.name) ?? string2(item.tool) ?? string2(record3(item.tool).name) ?? (type === "mcpToolCall" ? "CodeX MCP tool" : humanizeItemType(type));
|
|
17585
17706
|
}
|
|
17586
17707
|
function fileLocations(item) {
|
|
17587
|
-
return array(item.changes).map((value) =>
|
|
17708
|
+
return array(item.changes).map((value) => string2(record3(value).path)).filter((path) => path !== void 0 && path.length > 0).map((path) => ({ path }));
|
|
17588
17709
|
}
|
|
17589
17710
|
function nativeWorkspace(view) {
|
|
17590
17711
|
const { sessionCount: _sessionCount, ...workspace } = view;
|
|
@@ -17606,14 +17727,14 @@ function projectWorkspace(project) {
|
|
|
17606
17727
|
};
|
|
17607
17728
|
}
|
|
17608
17729
|
function projectCodexProject(value, fallbackPosition) {
|
|
17609
|
-
const source =
|
|
17610
|
-
const id4 =
|
|
17730
|
+
const source = record3(value);
|
|
17731
|
+
const id4 = string2(source.id);
|
|
17611
17732
|
if (id4 === void 0) return void 0;
|
|
17612
|
-
const roots = array(source.roots).map((root) =>
|
|
17733
|
+
const roots = array(source.roots).map((root) => string2(record3(root).path)).filter((path) => path !== void 0 && path.length > 0).map((path) => ({ path }));
|
|
17613
17734
|
if (roots.length === 0) return void 0;
|
|
17614
17735
|
return {
|
|
17615
17736
|
id: id4,
|
|
17616
|
-
name:
|
|
17737
|
+
name: string2(source.name) ?? basename(roots[0].path),
|
|
17617
17738
|
roots,
|
|
17618
17739
|
position: finiteNumber(source.position) ?? fallbackPosition,
|
|
17619
17740
|
createdAt: normalizeTime(source.createdAt),
|
|
@@ -17621,7 +17742,7 @@ function projectCodexProject(value, fallbackPosition) {
|
|
|
17621
17742
|
};
|
|
17622
17743
|
}
|
|
17623
17744
|
function findProjectWorkspace(thread, session, projects, workspaceByProjectId) {
|
|
17624
|
-
const explicitProjectId =
|
|
17745
|
+
const explicitProjectId = string2(thread.projectId);
|
|
17625
17746
|
const explicitWorkspace = explicitProjectId === void 0 ? void 0 : workspaceByProjectId.get(explicitProjectId);
|
|
17626
17747
|
if (explicitWorkspace !== void 0) return explicitWorkspace;
|
|
17627
17748
|
if (session.cwd === void 0) return void 0;
|
|
@@ -17659,14 +17780,14 @@ function codexPromptInput(content) {
|
|
|
17659
17780
|
if (content.length === 0 || content.length > MAX_CODEX_PROMPT_PARTS) return void 0;
|
|
17660
17781
|
const input2 = [];
|
|
17661
17782
|
for (const value of content) {
|
|
17662
|
-
if (!
|
|
17783
|
+
if (!isRecord6(value)) return void 0;
|
|
17663
17784
|
if (value.type === "text") {
|
|
17664
17785
|
if (typeof value.text !== "string" || value.text.length === 0 || value.text.length > MAX_CODEX_PROMPT_TEXT) return void 0;
|
|
17665
17786
|
input2.push({ type: "text", text: value.text });
|
|
17666
17787
|
continue;
|
|
17667
17788
|
}
|
|
17668
17789
|
if (value.type === "image") {
|
|
17669
|
-
if (typeof value.mediaType !== "string" || !
|
|
17790
|
+
if (typeof value.mediaType !== "string" || !CODEX_IMAGE_MEDIA_TYPES3.has(value.mediaType) || typeof value.data !== "string" || value.data.length > MAX_CODEX_IMAGE_BASE642 || !isCanonicalBase642(value.data)) return void 0;
|
|
17670
17791
|
input2.push({ type: "image", mediaType: value.mediaType, data: value.data });
|
|
17671
17792
|
continue;
|
|
17672
17793
|
}
|
|
@@ -17674,9 +17795,6 @@ function codexPromptInput(content) {
|
|
|
17674
17795
|
}
|
|
17675
17796
|
return input2;
|
|
17676
17797
|
}
|
|
17677
|
-
function isCanonicalBase642(value) {
|
|
17678
|
-
return value.length >= 4 && value.length % 4 === 0 && /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(value);
|
|
17679
|
-
}
|
|
17680
17798
|
function modelSelectionProjection(selection) {
|
|
17681
17799
|
return { lastUsed: selection, next: selection };
|
|
17682
17800
|
}
|
|
@@ -17704,7 +17822,7 @@ function codexImageLimitsProjection() {
|
|
|
17704
17822
|
maxMessageImageBytes: 100 * 1024 * 1024,
|
|
17705
17823
|
maxImagePixels: 4e7,
|
|
17706
17824
|
maxImageDimension: 8192,
|
|
17707
|
-
mediaTypes: [...
|
|
17825
|
+
mediaTypes: [...CODEX_IMAGE_MEDIA_TYPES3]
|
|
17708
17826
|
};
|
|
17709
17827
|
}
|
|
17710
17828
|
function isCodexPermissionPreset(value) {
|
|
@@ -17748,8 +17866,8 @@ function itemText2(value) {
|
|
|
17748
17866
|
if (content !== void 0) {
|
|
17749
17867
|
const text = content.map((part) => {
|
|
17750
17868
|
if (typeof part === "string") return part;
|
|
17751
|
-
const block =
|
|
17752
|
-
return
|
|
17869
|
+
const block = record3(part);
|
|
17870
|
+
return string2(block.text) ?? string2(block.content) ?? "";
|
|
17753
17871
|
}).filter(Boolean).join("\n");
|
|
17754
17872
|
if (text !== "") return text;
|
|
17755
17873
|
}
|
|
@@ -17762,52 +17880,52 @@ function toolArguments(item) {
|
|
|
17762
17880
|
if (item.type === "commandExecution") return { command: commandText(item.command) ?? item.command ?? "" };
|
|
17763
17881
|
if (item.type === "fileChange") return {
|
|
17764
17882
|
changes: array(item.changes).map((value) => {
|
|
17765
|
-
const change =
|
|
17766
|
-
const kind = typeof change.kind === "string" ? change.kind :
|
|
17883
|
+
const change = record3(value);
|
|
17884
|
+
const kind = typeof change.kind === "string" ? change.kind : string2(record3(change.kind).type);
|
|
17767
17885
|
return {
|
|
17768
17886
|
...typeof change.path === "string" ? { path: change.path } : {},
|
|
17769
17887
|
...kind === void 0 ? {} : { kind }
|
|
17770
17888
|
};
|
|
17771
17889
|
})
|
|
17772
17890
|
};
|
|
17773
|
-
if (item.type === "webSearch") return { query:
|
|
17774
|
-
if (item.type === "imageView") return { path:
|
|
17891
|
+
if (item.type === "webSearch") return { query: string2(item.query) ?? "" };
|
|
17892
|
+
if (item.type === "imageView") return { path: string2(item.path) ?? "" };
|
|
17775
17893
|
if (item.type === "imageGeneration") return {
|
|
17776
|
-
...
|
|
17894
|
+
...string2(item.revisedPrompt) === void 0 ? {} : { prompt: string2(item.revisedPrompt) },
|
|
17777
17895
|
transparentBackground: item.transparentBackground === true
|
|
17778
17896
|
};
|
|
17779
17897
|
if (item.type === "collabAgentToolCall") return {
|
|
17780
|
-
tool:
|
|
17898
|
+
tool: string2(item.tool) ?? "collaboration",
|
|
17781
17899
|
receiverThreadIds: array(item.receiverThreadIds).filter((value) => typeof value === "string"),
|
|
17782
|
-
...
|
|
17900
|
+
...string2(item.model) === void 0 ? {} : { model: string2(item.model) }
|
|
17783
17901
|
};
|
|
17784
17902
|
if (item.type === "subAgentActivity") return {
|
|
17785
|
-
agentThreadId:
|
|
17786
|
-
agentPath:
|
|
17787
|
-
kind:
|
|
17903
|
+
agentThreadId: string2(item.agentThreadId) ?? "",
|
|
17904
|
+
agentPath: string2(item.agentPath) ?? "",
|
|
17905
|
+
kind: string2(record3(item.kind).type) ?? string2(item.kind) ?? "activity"
|
|
17788
17906
|
};
|
|
17789
17907
|
if (item.type === "sleep") return { durationMs: integer(item.durationMs) ?? 0 };
|
|
17790
17908
|
if (item.type === "enteredReviewMode" || item.type === "exitedReviewMode") return {
|
|
17791
|
-
review:
|
|
17909
|
+
review: string2(item.review) ?? ""
|
|
17792
17910
|
};
|
|
17793
17911
|
if (item.type === "contextCompaction") return {};
|
|
17794
17912
|
return { name: item.name ?? item.tool ?? item.type ?? "tool", arguments: item.arguments ?? item.input ?? {} };
|
|
17795
17913
|
}
|
|
17796
17914
|
function fileChangeSummary(item) {
|
|
17797
17915
|
const changes = array(item.changes).map((value) => {
|
|
17798
|
-
const change =
|
|
17799
|
-
const path =
|
|
17800
|
-
const kind = typeof change.kind === "string" ? change.kind :
|
|
17916
|
+
const change = record3(value);
|
|
17917
|
+
const path = string2(change.path);
|
|
17918
|
+
const kind = typeof change.kind === "string" ? change.kind : string2(record3(change.kind).type);
|
|
17801
17919
|
return [kind, path].filter((part) => part !== void 0 && part.length > 0).join(" ");
|
|
17802
17920
|
}).filter(Boolean);
|
|
17803
17921
|
return changes.length === 0 ? "File changes completed." : changes.join("\n");
|
|
17804
17922
|
}
|
|
17805
17923
|
function sanitizedFileChanges(value) {
|
|
17806
17924
|
return array(value).flatMap((raw) => {
|
|
17807
|
-
const change =
|
|
17808
|
-
const path =
|
|
17925
|
+
const change = record3(raw);
|
|
17926
|
+
const path = string2(change.path);
|
|
17809
17927
|
if (path === void 0) return [];
|
|
17810
|
-
const kind = typeof change.kind === "string" ? change.kind :
|
|
17928
|
+
const kind = typeof change.kind === "string" ? change.kind : string2(record3(change.kind).type);
|
|
17811
17929
|
return [{ path, ...kind === void 0 ? {} : { kind } }];
|
|
17812
17930
|
});
|
|
17813
17931
|
}
|
|
@@ -17837,8 +17955,8 @@ function humanizeItemType(type) {
|
|
|
17837
17955
|
function commandText(value) {
|
|
17838
17956
|
if (typeof value === "string") return value;
|
|
17839
17957
|
if (Array.isArray(value)) return value.filter((item) => typeof item === "string").join(" ");
|
|
17840
|
-
const source =
|
|
17841
|
-
return
|
|
17958
|
+
const source = record3(value);
|
|
17959
|
+
return string2(source.command) ?? string2(source.text);
|
|
17842
17960
|
}
|
|
17843
17961
|
function sessionIdFromAddress(address) {
|
|
17844
17962
|
if (address.kind === "session") return requiredString(address.sessionId, "sessionId");
|
|
@@ -17853,7 +17971,7 @@ function nativeThreadId(sessionId) {
|
|
|
17853
17971
|
function activeTurnId(value) {
|
|
17854
17972
|
if (!Array.isArray(value)) return void 0;
|
|
17855
17973
|
for (let index = value.length - 1; index >= 0; index -= 1) {
|
|
17856
|
-
const turn =
|
|
17974
|
+
const turn = record3(value[index]);
|
|
17857
17975
|
if (isActiveCodexTurn(turn) && typeof turn.id === "string" && turn.id.length > 0) return turn.id;
|
|
17858
17976
|
}
|
|
17859
17977
|
return void 0;
|
|
@@ -17862,10 +17980,10 @@ function isActiveCodexTurn(turn) {
|
|
|
17862
17980
|
return turn.status === "inProgress" || turn.status === "running";
|
|
17863
17981
|
}
|
|
17864
17982
|
function carrierArgs(payload) {
|
|
17865
|
-
return
|
|
17983
|
+
return record3(record3(payload).args);
|
|
17866
17984
|
}
|
|
17867
17985
|
function requestArg(args) {
|
|
17868
|
-
return
|
|
17986
|
+
return record3(args.request ?? args._request ?? args);
|
|
17869
17987
|
}
|
|
17870
17988
|
function rcEndpoint(endpoint) {
|
|
17871
17989
|
if (endpoint === "workspace.list") return "workspace/list";
|
|
@@ -17881,20 +17999,20 @@ function ok(value) {
|
|
|
17881
17999
|
return value === void 0 ? { ok: true } : { ok: true, value };
|
|
17882
18000
|
}
|
|
17883
18001
|
function business(value) {
|
|
17884
|
-
const result =
|
|
18002
|
+
const result = record3(value);
|
|
17885
18003
|
if (result.ok === true) return ok(result.value);
|
|
17886
18004
|
if (result.ok === false) {
|
|
17887
|
-
const error =
|
|
17888
|
-
return fail(
|
|
18005
|
+
const error = record3(result.error);
|
|
18006
|
+
return fail(string2(error.code) ?? "internal", string2(error.message) ?? "CodeX virtual Harness rejected the request.", record3(error.details));
|
|
17889
18007
|
}
|
|
17890
18008
|
return ok(value);
|
|
17891
18009
|
}
|
|
17892
18010
|
function isCodexDirectoryListing(value) {
|
|
17893
|
-
const listing =
|
|
18011
|
+
const listing = record3(value);
|
|
17894
18012
|
return typeof listing.path === "string" && typeof listing.home === "string" && Array.isArray(listing.crumbs) && listing.crumbs.every(isCodexDirectoryEntry) && Array.isArray(listing.entries) && listing.entries.every(isCodexDirectoryEntry) && typeof listing.truncated === "boolean";
|
|
17895
18013
|
}
|
|
17896
18014
|
function isCodexDirectoryEntry(value) {
|
|
17897
|
-
const entry =
|
|
18015
|
+
const entry = record3(value);
|
|
17898
18016
|
return typeof entry.name === "string" && typeof entry.path === "string" && typeof entry.hidden === "boolean";
|
|
17899
18017
|
}
|
|
17900
18018
|
function fail(code, message, details = {}) {
|
|
@@ -17912,18 +18030,18 @@ function errorCode(error) {
|
|
|
17912
18030
|
return "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
17913
18031
|
}
|
|
17914
18032
|
function errorDetails(error) {
|
|
17915
|
-
return "details" in error &&
|
|
18033
|
+
return "details" in error && isRecord6(error.details) ? error.details : {};
|
|
17916
18034
|
}
|
|
17917
|
-
function
|
|
17918
|
-
return
|
|
18035
|
+
function record3(value) {
|
|
18036
|
+
return isRecord6(value) ? value : {};
|
|
17919
18037
|
}
|
|
17920
|
-
function
|
|
18038
|
+
function isRecord6(value) {
|
|
17921
18039
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17922
18040
|
}
|
|
17923
18041
|
function array(value) {
|
|
17924
18042
|
return Array.isArray(value) ? value : [];
|
|
17925
18043
|
}
|
|
17926
|
-
function
|
|
18044
|
+
function string2(value) {
|
|
17927
18045
|
return typeof value === "string" ? value : void 0;
|
|
17928
18046
|
}
|
|
17929
18047
|
function integer(value) {
|
|
@@ -17949,8 +18067,8 @@ function optionalPositiveInteger(value) {
|
|
|
17949
18067
|
return parsed;
|
|
17950
18068
|
}
|
|
17951
18069
|
function isCodexNativeHistoryPage(value, sessionId) {
|
|
17952
|
-
const page =
|
|
17953
|
-
const header =
|
|
18070
|
+
const page = record3(value);
|
|
18071
|
+
const header = record3(page.header);
|
|
17954
18072
|
return header.id === sessionId && integer(page.cursor) !== void 0 && integer(page.nextTurn) !== void 0 && Array.isArray(page.records) && typeof page.hasMore === "boolean" && (page.activeTurnId === void 0 || typeof page.activeTurnId === "string");
|
|
17955
18073
|
}
|
|
17956
18074
|
function truncateCodePoints(value, maximum) {
|
|
@@ -17977,7 +18095,7 @@ function basename(path) {
|
|
|
17977
18095
|
const parts = normalized.split(/[\\/]/u);
|
|
17978
18096
|
return parts.at(-1) || path;
|
|
17979
18097
|
}
|
|
17980
|
-
function
|
|
18098
|
+
function hashString2(value) {
|
|
17981
18099
|
let hash = 2166136261;
|
|
17982
18100
|
for (let index = 0; index < value.length; index += 1) {
|
|
17983
18101
|
hash ^= value.charCodeAt(index);
|
|
@@ -18093,10 +18211,10 @@ var ServerCredentialStore = class {
|
|
|
18093
18211
|
return parsed.serverUrl === serverUrl && parsed.deviceId === deviceId ? parsed : void 0;
|
|
18094
18212
|
}
|
|
18095
18213
|
async save(credentials) {
|
|
18096
|
-
const
|
|
18097
|
-
await atomicWrite(this.path, `${JSON.stringify(
|
|
18214
|
+
const record7 = credentialSchema.parse({ schemaVersion: 1, ...credentials });
|
|
18215
|
+
await atomicWrite(this.path, `${JSON.stringify(record7, null, 2)}
|
|
18098
18216
|
`);
|
|
18099
|
-
return
|
|
18217
|
+
return record7;
|
|
18100
18218
|
}
|
|
18101
18219
|
async clear() {
|
|
18102
18220
|
await rm(this.path, { force: true });
|
|
@@ -18141,7 +18259,7 @@ function safeMessage(error) {
|
|
|
18141
18259
|
import { hostname } from "node:os";
|
|
18142
18260
|
import s from "@deepseek-ai/schemastery";
|
|
18143
18261
|
var DEFAULT_REMOTE_SERVER_URL = "https://dsh.r2049.cn";
|
|
18144
|
-
var
|
|
18262
|
+
var entryConfigSchema = s.object({
|
|
18145
18263
|
enabled: s.boolean(),
|
|
18146
18264
|
role: s.union(["host", "client", "both"]),
|
|
18147
18265
|
serverUrl: s.string(),
|
|
@@ -18164,6 +18282,11 @@ var Config = s.object({
|
|
|
18164
18282
|
}),
|
|
18165
18283
|
acp: s.object({ enabled: s.boolean(), backends: s.array(s.object({ id: s.string(), enabled: s.boolean(), command: s.string(), args: s.array(s.string()), cwd: s.string() })) })
|
|
18166
18284
|
});
|
|
18285
|
+
function withVolatileSchema(schema) {
|
|
18286
|
+
const volatile = schema.volatile;
|
|
18287
|
+
return typeof volatile === "function" ? volatile.call(schema) : schema;
|
|
18288
|
+
}
|
|
18289
|
+
var Config = withVolatileSchema(entryConfigSchema);
|
|
18167
18290
|
var reconnectSchema = external_exports.union([
|
|
18168
18291
|
external_exports.boolean(),
|
|
18169
18292
|
external_exports.object({
|
|
@@ -18243,7 +18366,7 @@ function normalizeServerUrl(value) {
|
|
|
18243
18366
|
}
|
|
18244
18367
|
|
|
18245
18368
|
// src/version.ts
|
|
18246
|
-
var PLUGIN_VERSION = "0.4.
|
|
18369
|
+
var PLUGIN_VERSION = "0.4.18";
|
|
18247
18370
|
|
|
18248
18371
|
// src/server-api.ts
|
|
18249
18372
|
var TERMINAL_CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
@@ -18699,7 +18822,7 @@ var TypertGatewaySwitch = class {
|
|
|
18699
18822
|
this.originalDispatch = this.runtime.dispatchRpc;
|
|
18700
18823
|
this.localDispatch = this.runtime.dispatchRpc?.bind(gateway);
|
|
18701
18824
|
this.originalOpen = this.runtime.openWireStream;
|
|
18702
|
-
this.localOpen =
|
|
18825
|
+
this.localOpen = createLocalOpen(gateway, this.runtime);
|
|
18703
18826
|
}
|
|
18704
18827
|
/** Original local dispatcher, used by the Host bridge without switch recursion. */
|
|
18705
18828
|
local() {
|
|
@@ -18740,7 +18863,16 @@ var TypertGatewaySwitch = class {
|
|
|
18740
18863
|
this.runtime.dispatchRpc = (endpoint, payload, signal) => this.remoteTarget === void 0 || isLocalOnlyEndpoint(endpoint) ? this.localDispatch(endpoint, payload, signal) : this.remoteTarget.dispatch(endpoint, payload, signal);
|
|
18741
18864
|
}
|
|
18742
18865
|
if (this.originalOpen !== void 0) {
|
|
18743
|
-
|
|
18866
|
+
const open = this.originalOpen;
|
|
18867
|
+
const rc1 = usesRc1Arity(open);
|
|
18868
|
+
this.runtime.openWireStream = (...callArgs) => {
|
|
18869
|
+
const endpoint = callArgs[0];
|
|
18870
|
+
if (this.remoteTarget === void 0 || isLocalOnlyEndpoint(endpoint)) {
|
|
18871
|
+
return rc1 ? Reflect.apply(open, this.runtime, callArgs) : open.call(this.runtime, endpoint, callArgs[1], callArgs[2]);
|
|
18872
|
+
}
|
|
18873
|
+
const signal = rc1 ? callArgs[4] : callArgs[2];
|
|
18874
|
+
return this.remoteTarget.open(endpoint, callArgs[1], signal ?? new AbortController().signal);
|
|
18875
|
+
};
|
|
18744
18876
|
}
|
|
18745
18877
|
this.installed = true;
|
|
18746
18878
|
}
|
|
@@ -18781,16 +18913,47 @@ var TypertGatewaySwitch = class {
|
|
|
18781
18913
|
if (normalized !== void 0) return normalized;
|
|
18782
18914
|
const source = error instanceof Error ? error : new Error("The Harness Gateway rejected the request.");
|
|
18783
18915
|
const code = "code" in source && typeof source.code === "string" ? source.code : "internal";
|
|
18784
|
-
const details = "details" in source &&
|
|
18916
|
+
const details = "details" in source && isRecord7(source.details) ? source.details : {};
|
|
18785
18917
|
return { code, message: source.message, details };
|
|
18786
18918
|
}
|
|
18787
18919
|
};
|
|
18920
|
+
function usesRc1Arity(open) {
|
|
18921
|
+
return open.length >= 5;
|
|
18922
|
+
}
|
|
18923
|
+
function endedUplink() {
|
|
18924
|
+
return {
|
|
18925
|
+
[Symbol.asyncIterator]() {
|
|
18926
|
+
return { next: () => Promise.resolve({ done: true, value: void 0 }) };
|
|
18927
|
+
}
|
|
18928
|
+
};
|
|
18929
|
+
}
|
|
18930
|
+
function linkControl(signal) {
|
|
18931
|
+
const control = new AbortController();
|
|
18932
|
+
if (signal.aborted) control.abort(signal.reason);
|
|
18933
|
+
else signal.addEventListener("abort", () => control.abort(signal.reason), { once: true });
|
|
18934
|
+
return control;
|
|
18935
|
+
}
|
|
18936
|
+
function createLocalOpen(gateway, runtime) {
|
|
18937
|
+
const open = runtime.openWireStream;
|
|
18938
|
+
if (open !== void 0) {
|
|
18939
|
+
return usesRc1Arity(open) ? (endpoint, payload, signal) => open.call(runtime, endpoint, payload, endedUplink(), void 0, signal, linkControl(signal)) : (endpoint, payload, signal) => open.call(runtime, endpoint, payload, signal);
|
|
18940
|
+
}
|
|
18941
|
+
const wire = gateway.wireStream;
|
|
18942
|
+
if (wire === void 0) return void 0;
|
|
18943
|
+
const wireOpen = wire.open;
|
|
18944
|
+
if (usesRc1Arity(wireOpen)) {
|
|
18945
|
+
const rc1 = wireOpen;
|
|
18946
|
+
return (endpoint, payload, signal) => rc1.call(wire, endpoint, payload, endedUplink(), void 0, signal);
|
|
18947
|
+
}
|
|
18948
|
+
const legacy = wireOpen;
|
|
18949
|
+
return (endpoint, payload, signal) => legacy.call(wire, endpoint, payload, signal);
|
|
18950
|
+
}
|
|
18788
18951
|
function requestFromCarrier(endpoint, payload, signal) {
|
|
18789
18952
|
const segments = endpoint.split("/");
|
|
18790
18953
|
if (segments.length !== 2 || segments.some((segment) => segment.length === 0)) {
|
|
18791
18954
|
throw new Error("The Harness Gateway endpoint is invalid.");
|
|
18792
18955
|
}
|
|
18793
|
-
if (!
|
|
18956
|
+
if (!isRecord7(payload) || !isRecord7(payload.args)) {
|
|
18794
18957
|
throw new Error("The Harness Gateway payload is invalid.");
|
|
18795
18958
|
}
|
|
18796
18959
|
return { namespace: segments[0], method: segments[1], args: payload.args, signal };
|
|
@@ -18805,7 +18968,7 @@ function isLocalOnlyEndpoint(endpoint) {
|
|
|
18805
18968
|
function isRemoteCommandMethod(method) {
|
|
18806
18969
|
return REMOTE_COMMAND_METHODS.includes(method);
|
|
18807
18970
|
}
|
|
18808
|
-
function
|
|
18971
|
+
function isRecord7(value) {
|
|
18809
18972
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18810
18973
|
}
|
|
18811
18974
|
|
|
@@ -20172,12 +20335,12 @@ var ClientModeRuntime = class {
|
|
|
20172
20335
|
throw new ClientModeError("FEATURE_NOT_SUPPORTED", "The selected Host does not provide CodeX workspaces.");
|
|
20173
20336
|
}
|
|
20174
20337
|
this.assertLocalHarnessCarrierAvailable();
|
|
20175
|
-
const result =
|
|
20338
|
+
const result = record4(await new CodexRemoteClient(remote.client).request("project/create", {
|
|
20176
20339
|
name: remoteWorkspaceTitle(trimmedPath),
|
|
20177
20340
|
roots: [{ path: trimmedPath }],
|
|
20178
20341
|
idempotencyKey: uuidV7()
|
|
20179
20342
|
}, signal));
|
|
20180
|
-
const project =
|
|
20343
|
+
const project = record4(result.project);
|
|
20181
20344
|
if (typeof project.id !== "string" || project.id.length === 0) {
|
|
20182
20345
|
throw new ClientModeError("INVALID_MESSAGE", "The Host returned an invalid CodeX project.");
|
|
20183
20346
|
}
|
|
@@ -20229,7 +20392,7 @@ var ClientModeRuntime = class {
|
|
|
20229
20392
|
}
|
|
20230
20393
|
async openCodexStream(payload, signal) {
|
|
20231
20394
|
const remote = this.activeCodexRemote();
|
|
20232
|
-
const value =
|
|
20395
|
+
const value = record4(payload);
|
|
20233
20396
|
if (typeof value.streamId !== "string" || value.streamId.length === 0 || value.streamId.length > 128 || typeof value.threadId !== "string" || value.threadId.length === 0) {
|
|
20234
20397
|
throw new ClientModeError("INVALID_MESSAGE", "A Codex stream and thread are required.");
|
|
20235
20398
|
}
|
|
@@ -20261,10 +20424,10 @@ var ClientModeRuntime = class {
|
|
|
20261
20424
|
}
|
|
20262
20425
|
}
|
|
20263
20426
|
stream.unsubscribe = remote.client.onEvent((event) => {
|
|
20264
|
-
if (event.event === "codex.app.frame" &&
|
|
20427
|
+
if (event.event === "codex.app.frame" && isRecord8(event.data) && event.data.streamId === value.streamId) {
|
|
20265
20428
|
this.appendCodexFrame(stream, event.data);
|
|
20266
20429
|
}
|
|
20267
|
-
if (event.event === "codex.app.stream.closed" &&
|
|
20430
|
+
if (event.event === "codex.app.stream.closed" && isRecord8(event.data) && event.data.streamId === value.streamId) {
|
|
20268
20431
|
stream.closed = typeof event.data.reason === "string" ? event.data.reason : "closed";
|
|
20269
20432
|
stream.wake();
|
|
20270
20433
|
}
|
|
@@ -20291,7 +20454,7 @@ var ClientModeRuntime = class {
|
|
|
20291
20454
|
stream.wake();
|
|
20292
20455
|
};
|
|
20293
20456
|
appendCodexFrame(stream, data2) {
|
|
20294
|
-
if (!
|
|
20457
|
+
if (!isRecord8(data2) || !isRecord8(data2.frame) || typeof data2.frame.method !== "string") return;
|
|
20295
20458
|
if (stream.frames.length >= 256) {
|
|
20296
20459
|
stream.closed = "overflow";
|
|
20297
20460
|
} else {
|
|
@@ -20314,7 +20477,7 @@ var ClientModeRuntime = class {
|
|
|
20314
20477
|
};
|
|
20315
20478
|
}
|
|
20316
20479
|
async nextCodexFrames(payload, signal) {
|
|
20317
|
-
const value =
|
|
20480
|
+
const value = record4(payload);
|
|
20318
20481
|
if (typeof value.streamId !== "string") throw new ClientModeError("INVALID_MESSAGE", "A Codex stream is required.");
|
|
20319
20482
|
const stream = this.codexStreams.get(value.streamId);
|
|
20320
20483
|
if (stream === void 0) throw new ClientModeError("STREAM_NOT_FOUND", "The Codex stream is not open.");
|
|
@@ -20328,7 +20491,7 @@ var ClientModeRuntime = class {
|
|
|
20328
20491
|
};
|
|
20329
20492
|
}
|
|
20330
20493
|
async closeCodexStream(payload) {
|
|
20331
|
-
const value =
|
|
20494
|
+
const value = record4(payload);
|
|
20332
20495
|
if (typeof value.streamId !== "string") throw new ClientModeError("INVALID_MESSAGE", "A Codex stream is required.");
|
|
20333
20496
|
const stream = this.codexStreams.get(value.streamId);
|
|
20334
20497
|
if (stream === void 0) return { closed: false, streamId: value.streamId };
|
|
@@ -20354,7 +20517,7 @@ var ClientModeRuntime = class {
|
|
|
20354
20517
|
this.gatewaySwitch.selectRemote(this.remoteTypertGateway(remote), void 0, target2);
|
|
20355
20518
|
return;
|
|
20356
20519
|
}
|
|
20357
|
-
this.proxySwitch?.selectRemote(new RemoteHarnessApiProxy(remote.client).api, target2);
|
|
20520
|
+
this.proxySwitch?.selectRemote(new RemoteHarnessApiProxy(remote.client, remote.harnessVersion).api, target2);
|
|
20358
20521
|
this.gatewaySwitch.selectRemote((request) => invokeRemoteCommand(remote.client, request), {
|
|
20359
20522
|
execute: true,
|
|
20360
20523
|
list: remote.features.commandList
|
|
@@ -20364,7 +20527,8 @@ var ClientModeRuntime = class {
|
|
|
20364
20527
|
const localSessionGeneration = harnessSessionGeneration(this.host?.localHarnessVersion?.());
|
|
20365
20528
|
return new RemoteTypertGateway2(
|
|
20366
20529
|
remote.client,
|
|
20367
|
-
localSessionGeneration === "v3" && remote.features.sessionFormat !== 3 ? "legacy-to-v3" : void 0
|
|
20530
|
+
localSessionGeneration === "v3" && remote.features.sessionFormat !== 3 ? "legacy-to-v3" : void 0,
|
|
20531
|
+
remote.harnessVersion
|
|
20368
20532
|
);
|
|
20369
20533
|
}
|
|
20370
20534
|
selectCodexTarget(virtual, remote) {
|
|
@@ -20580,14 +20744,14 @@ var ClientModeRuntime = class {
|
|
|
20580
20744
|
if (endpoint === "status") return ok2(await this.detailedStatus());
|
|
20581
20745
|
if (endpoint === "devices") return ok2(await this.devices());
|
|
20582
20746
|
if (endpoint === "client.account.login") {
|
|
20583
|
-
const value =
|
|
20747
|
+
const value = record4(payload);
|
|
20584
20748
|
if (typeof value.email !== "string" || typeof value.password !== "string") {
|
|
20585
20749
|
throw new ClientModeError("INVALID_MESSAGE", "Email and password are required.");
|
|
20586
20750
|
}
|
|
20587
20751
|
return ok2(await this.authorizeClientWithAccount(value.email, value.password));
|
|
20588
20752
|
}
|
|
20589
20753
|
if (endpoint === "client.account.qr.start") {
|
|
20590
|
-
const value =
|
|
20754
|
+
const value = record4(payload);
|
|
20591
20755
|
const provider = value.provider ?? "zhihu";
|
|
20592
20756
|
if (provider !== "zhihu" && provider !== "github") {
|
|
20593
20757
|
throw new ClientModeError("INVALID_MESSAGE", "A supported OAuth provider is required.");
|
|
@@ -20595,7 +20759,7 @@ var ClientModeRuntime = class {
|
|
|
20595
20759
|
return ok2(await this.startClientOAuthQrLogin(provider));
|
|
20596
20760
|
}
|
|
20597
20761
|
if (endpoint === "client.account.qr.poll") {
|
|
20598
|
-
const value =
|
|
20762
|
+
const value = record4(payload);
|
|
20599
20763
|
if (typeof value.qrId !== "string" || value.qrId.length < 20) {
|
|
20600
20764
|
throw new ClientModeError("INVALID_MESSAGE", "A QR login session is required.");
|
|
20601
20765
|
}
|
|
@@ -20605,10 +20769,10 @@ var ClientModeRuntime = class {
|
|
|
20605
20769
|
const remote = this.activeRemote();
|
|
20606
20770
|
if (remote === void 0) throw new ClientModeError("TRANSPORT_CLOSED", "Connect to a Remote Host first.");
|
|
20607
20771
|
this.preview ??= new LoopbackPreview(remote.client);
|
|
20608
|
-
return ok2(await this.preview.open(
|
|
20772
|
+
return ok2(await this.preview.open(record4(payload).port));
|
|
20609
20773
|
}
|
|
20610
20774
|
if (endpoint === "directory.list") {
|
|
20611
|
-
const value =
|
|
20775
|
+
const value = record4(payload);
|
|
20612
20776
|
if (typeof value.targetDeviceId !== "string") throw new ClientModeError("INVALID_MESSAGE", "A Host is required.");
|
|
20613
20777
|
return ok2(await this.listRemoteDirectory(
|
|
20614
20778
|
value.targetDeviceId,
|
|
@@ -20617,38 +20781,38 @@ var ClientModeRuntime = class {
|
|
|
20617
20781
|
));
|
|
20618
20782
|
}
|
|
20619
20783
|
if (endpoint === "workspaces.list") {
|
|
20620
|
-
const value =
|
|
20784
|
+
const value = record4(payload);
|
|
20621
20785
|
if (typeof value.targetDeviceId !== "string") throw new ClientModeError("INVALID_MESSAGE", "A Host is required.");
|
|
20622
20786
|
return ok2(await this.listRemoteWorkspaces(value.targetDeviceId, signal));
|
|
20623
20787
|
}
|
|
20624
20788
|
if (endpoint === "codex.workspaces.list") {
|
|
20625
|
-
const value =
|
|
20789
|
+
const value = record4(payload);
|
|
20626
20790
|
if (typeof value.targetDeviceId !== "string") throw new ClientModeError("INVALID_MESSAGE", "A Host is required.");
|
|
20627
20791
|
return ok2(await this.listCodexWorkspaces(value.targetDeviceId, signal));
|
|
20628
20792
|
}
|
|
20629
20793
|
if (endpoint === "workspace.open") {
|
|
20630
|
-
const value =
|
|
20794
|
+
const value = record4(payload);
|
|
20631
20795
|
if (typeof value.targetDeviceId !== "string" || typeof value.path !== "string") {
|
|
20632
20796
|
throw new ClientModeError("INVALID_MESSAGE", "A Host and working directory are required.");
|
|
20633
20797
|
}
|
|
20634
20798
|
return ok2(await this.openRemoteWorkspace(value.targetDeviceId, value.path, signal));
|
|
20635
20799
|
}
|
|
20636
20800
|
if (endpoint === "codex.workspace.open") {
|
|
20637
|
-
const value =
|
|
20801
|
+
const value = record4(payload);
|
|
20638
20802
|
if (typeof value.targetDeviceId !== "string" || typeof value.workspaceId !== "string") {
|
|
20639
20803
|
throw new ClientModeError("INVALID_MESSAGE", "A Host and CodeX Workspace are required.");
|
|
20640
20804
|
}
|
|
20641
20805
|
return ok2(await this.openCodexWorkspace(value.targetDeviceId, value.workspaceId, signal));
|
|
20642
20806
|
}
|
|
20643
20807
|
if (endpoint === "codex.workspace.create") {
|
|
20644
|
-
const value =
|
|
20808
|
+
const value = record4(payload);
|
|
20645
20809
|
if (typeof value.targetDeviceId !== "string" || typeof value.path !== "string") {
|
|
20646
20810
|
throw new ClientModeError("INVALID_MESSAGE", "A Host and CodeX project directory are required.");
|
|
20647
20811
|
}
|
|
20648
20812
|
return ok2(await this.createCodexWorkspace(value.targetDeviceId, value.path, signal));
|
|
20649
20813
|
}
|
|
20650
20814
|
if (endpoint === "workspace.selection.consume") {
|
|
20651
|
-
const value =
|
|
20815
|
+
const value = record4(payload);
|
|
20652
20816
|
if (typeof value.targetDeviceId !== "string" || typeof value.workspaceId !== "string") {
|
|
20653
20817
|
throw new ClientModeError("INVALID_MESSAGE", "A Host and Workspace are required.");
|
|
20654
20818
|
}
|
|
@@ -20664,7 +20828,7 @@ var ClientModeRuntime = class {
|
|
|
20664
20828
|
return ok2(await this.callRemoteFileViewer(method, payload, signal));
|
|
20665
20829
|
}
|
|
20666
20830
|
if (endpoint === "codex.call") {
|
|
20667
|
-
const value =
|
|
20831
|
+
const value = record4(payload);
|
|
20668
20832
|
if (typeof value.method !== "string" || !("params" in value)) {
|
|
20669
20833
|
throw new ClientModeError("INVALID_MESSAGE", "A Codex method and params are required.");
|
|
20670
20834
|
}
|
|
@@ -20688,7 +20852,7 @@ var ClientModeRuntime = class {
|
|
|
20688
20852
|
return ok2({ supported: local || remoteSupported, local, remote: remoteSupported });
|
|
20689
20853
|
}
|
|
20690
20854
|
if (endpoint === "codex.respond") {
|
|
20691
|
-
const value =
|
|
20855
|
+
const value = record4(payload);
|
|
20692
20856
|
const remote = this.activeCodexRemote();
|
|
20693
20857
|
if (remote !== void 0) return ok2(await remote.client.rpc("codex.app.respond", value, signal));
|
|
20694
20858
|
const host = this.requireLocalCodex();
|
|
@@ -20699,14 +20863,14 @@ var ClientModeRuntime = class {
|
|
|
20699
20863
|
if (endpoint === "codex.stream.close") return ok2(await this.closeCodexStream(payload));
|
|
20700
20864
|
if (endpoint === "host.account.login") {
|
|
20701
20865
|
if (this.host === void 0) throw new ClientModeError("METHOD_NOT_ALLOWED", "This plugin is not running as a Host.");
|
|
20702
|
-
const value =
|
|
20866
|
+
const value = record4(payload);
|
|
20703
20867
|
if (typeof value.email !== "string" || typeof value.password !== "string") {
|
|
20704
20868
|
throw new ClientModeError("INVALID_MESSAGE", "Email and password are required.");
|
|
20705
20869
|
}
|
|
20706
20870
|
return ok2(await this.host.authorizeHostWithAccount(value.email, value.password));
|
|
20707
20871
|
}
|
|
20708
20872
|
if (endpoint === "host.authorization.set") {
|
|
20709
|
-
const value =
|
|
20873
|
+
const value = record4(payload);
|
|
20710
20874
|
if (typeof value.enabled !== "boolean") {
|
|
20711
20875
|
throw new ClientModeError("INVALID_MESSAGE", "Host authorization state is required.");
|
|
20712
20876
|
}
|
|
@@ -20714,14 +20878,14 @@ var ClientModeRuntime = class {
|
|
|
20714
20878
|
}
|
|
20715
20879
|
if (endpoint === "host.registration-code.submit") {
|
|
20716
20880
|
if (this.host === void 0) throw new ClientModeError("METHOD_NOT_ALLOWED", "This plugin is not running as a Host.");
|
|
20717
|
-
const value =
|
|
20881
|
+
const value = record4(payload);
|
|
20718
20882
|
if (typeof value.code !== "string" || value.code.trim() === "") {
|
|
20719
20883
|
throw new ClientModeError("INVALID_MESSAGE", "A Host registration code is required.");
|
|
20720
20884
|
}
|
|
20721
20885
|
return ok2(await this.host.authorizeHostWithCode(value.code));
|
|
20722
20886
|
}
|
|
20723
20887
|
if (endpoint === "mode.set") {
|
|
20724
|
-
const value =
|
|
20888
|
+
const value = record4(payload);
|
|
20725
20889
|
if (value.mode !== "local" && value.mode !== "remote") throw new ClientModeError("INVALID_MESSAGE", "Mode must be local or remote.");
|
|
20726
20890
|
return ok2(await this.setMode(value.mode, typeof value.targetDeviceId === "string" ? value.targetDeviceId : void 0, signal));
|
|
20727
20891
|
}
|
|
@@ -20785,13 +20949,13 @@ function webrtcDiagnosticsLogFields(diagnostics) {
|
|
|
20785
20949
|
...diagnostics.selectedPath === void 0 ? {} : { rtcSelectedPath: diagnostics.selectedPath }
|
|
20786
20950
|
};
|
|
20787
20951
|
}
|
|
20788
|
-
function
|
|
20952
|
+
function record4(value) {
|
|
20789
20953
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
20790
20954
|
throw new ClientModeError("INVALID_MESSAGE", "The control request payload is invalid.");
|
|
20791
20955
|
}
|
|
20792
20956
|
return value;
|
|
20793
20957
|
}
|
|
20794
|
-
function
|
|
20958
|
+
function isRecord8(value) {
|
|
20795
20959
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20796
20960
|
}
|
|
20797
20961
|
function ok2(value) {
|
|
@@ -20816,11 +20980,11 @@ async function readRemoteWorkspaceBaseline(gateway, signal) {
|
|
|
20816
20980
|
const iterator = source[Symbol.asyncIterator]();
|
|
20817
20981
|
try {
|
|
20818
20982
|
const first = await iterator.next();
|
|
20819
|
-
if (first.done || !
|
|
20983
|
+
if (first.done || !isRecord8(first.value) || first.value.type !== "baseline" || !isRecord8(first.value.value) || !Array.isArray(first.value.value.items)) {
|
|
20820
20984
|
throw new ClientModeError("INVALID_MESSAGE", "The remote Host returned an invalid Workspace baseline.");
|
|
20821
20985
|
}
|
|
20822
20986
|
return first.value.value.items.map((item) => {
|
|
20823
|
-
if (!
|
|
20987
|
+
if (!isRecord8(item) || typeof item.workspaceId !== "string" || typeof item.path !== "string" || typeof item.title !== "string") {
|
|
20824
20988
|
throw new ClientModeError("INVALID_MESSAGE", "The remote Host returned an invalid Workspace row.");
|
|
20825
20989
|
}
|
|
20826
20990
|
return { workspaceId: item.workspaceId, path: item.path, title: item.title };
|
|
@@ -20886,7 +21050,7 @@ async function probeRemoteHostFeatures(client, clientVersion) {
|
|
|
20886
21050
|
if (error instanceof Error && "code" in error && error.code === "METHOD_NOT_FOUND") return fallback;
|
|
20887
21051
|
throw error;
|
|
20888
21052
|
}
|
|
20889
|
-
if (!
|
|
21053
|
+
if (!isRecord8(value) || !Array.isArray(value.capabilities) || value.capabilities.some((capability) => typeof capability !== "string")) {
|
|
20890
21054
|
throw new ClientModeError("INVALID_MESSAGE", "The remote Host returned invalid transport capabilities.");
|
|
20891
21055
|
}
|
|
20892
21056
|
const capabilities = new Set(value.capabilities);
|
|
@@ -21022,24 +21186,24 @@ var IdentityStore = class {
|
|
|
21022
21186
|
}
|
|
21023
21187
|
if (!hasDevice) {
|
|
21024
21188
|
const keys = generateKeyPair();
|
|
21025
|
-
const
|
|
21026
|
-
await atomicJsonWrite(devicePath,
|
|
21189
|
+
const record7 = { schemaVersion: 1, deviceId: uuidV7(), name: deviceName, publicKey: keys.publicKey };
|
|
21190
|
+
await atomicJsonWrite(devicePath, record7, 384);
|
|
21027
21191
|
await atomicTextWrite(keyPath, `${keys.privateKey}
|
|
21028
21192
|
`, 384);
|
|
21029
21193
|
}
|
|
21030
21194
|
await assertPrivateMode2(keyPath);
|
|
21031
21195
|
try {
|
|
21032
|
-
let
|
|
21196
|
+
let record7 = identitySchema.parse(JSON.parse(await readFile3(devicePath, "utf8")));
|
|
21033
21197
|
const privateKey = (await readFile3(keyPath, "utf8")).trim();
|
|
21034
21198
|
const regenerated = generateKeyPair(fromBase64Url2(privateKey));
|
|
21035
|
-
if (regenerated.publicKey !==
|
|
21199
|
+
if (regenerated.publicKey !== record7.publicKey) {
|
|
21036
21200
|
throw new IdentityInvalidError("device public and private keys do not match");
|
|
21037
21201
|
}
|
|
21038
|
-
if (
|
|
21039
|
-
|
|
21040
|
-
await atomicJsonWrite(devicePath,
|
|
21202
|
+
if (record7.name !== deviceName) {
|
|
21203
|
+
record7 = { ...record7, name: deviceName };
|
|
21204
|
+
await atomicJsonWrite(devicePath, record7, 384);
|
|
21041
21205
|
}
|
|
21042
|
-
this.identity = { ...
|
|
21206
|
+
this.identity = { ...record7, privateKey, fingerprint: fingerprint(record7.publicKey) };
|
|
21043
21207
|
await this.loadPeers();
|
|
21044
21208
|
return this.identity;
|
|
21045
21209
|
} catch (error) {
|
|
@@ -21343,7 +21507,7 @@ var PluginControlRuntime = class {
|
|
|
21343
21507
|
if (endpoint === "devices") return ok3([]);
|
|
21344
21508
|
if (endpoint === "host.account.login") {
|
|
21345
21509
|
if (this.host === void 0) throw new ClientModeError("METHOD_NOT_ALLOWED", "This plugin is not running as a Host.");
|
|
21346
|
-
const value =
|
|
21510
|
+
const value = record5(payload);
|
|
21347
21511
|
if (typeof value.email !== "string" || typeof value.password !== "string") {
|
|
21348
21512
|
throw new ClientModeError("INVALID_MESSAGE", "Email and password are required.");
|
|
21349
21513
|
}
|
|
@@ -21351,13 +21515,13 @@ var PluginControlRuntime = class {
|
|
|
21351
21515
|
}
|
|
21352
21516
|
if (endpoint === "host.registration-code.submit") {
|
|
21353
21517
|
if (this.host === void 0) throw new ClientModeError("METHOD_NOT_ALLOWED", "This plugin is not running as a Host.");
|
|
21354
|
-
const value =
|
|
21518
|
+
const value = record5(payload);
|
|
21355
21519
|
if (typeof value.code !== "string" || value.code.trim() === "") {
|
|
21356
21520
|
throw new ClientModeError("INVALID_MESSAGE", "A Host registration code is required.");
|
|
21357
21521
|
}
|
|
21358
21522
|
return ok3(await this.host.authorizeHostWithCode(value.code));
|
|
21359
21523
|
}
|
|
21360
|
-
if (endpoint === "mode.set" &&
|
|
21524
|
+
if (endpoint === "mode.set" && record5(payload).mode === "local") return ok3(this.hostOnlyStatus());
|
|
21361
21525
|
throw new ClientModeError("METHOD_NOT_ALLOWED", "Remote Client mode is disabled by the plugin role.");
|
|
21362
21526
|
} catch (error) {
|
|
21363
21527
|
return fail3(error);
|
|
@@ -21367,7 +21531,7 @@ var PluginControlRuntime = class {
|
|
|
21367
21531
|
if (this.settings === void 0) {
|
|
21368
21532
|
throw new ClientModeError("SETTINGS_UNAVAILABLE", "DSH user settings are unavailable in this profile.");
|
|
21369
21533
|
}
|
|
21370
|
-
const value =
|
|
21534
|
+
const value = record5(payload);
|
|
21371
21535
|
if (value.role !== "host" && value.role !== "client") {
|
|
21372
21536
|
throw new ClientModeError("INVALID_MESSAGE", "Role must be Host or Client.");
|
|
21373
21537
|
}
|
|
@@ -21402,7 +21566,7 @@ var PluginControlRuntime = class {
|
|
|
21402
21566
|
if (this.settings === void 0) {
|
|
21403
21567
|
throw new ClientModeError("SETTINGS_UNAVAILABLE", "DSH user settings are unavailable in this profile.");
|
|
21404
21568
|
}
|
|
21405
|
-
const value =
|
|
21569
|
+
const value = record5(payload);
|
|
21406
21570
|
if (typeof value.serverUrl !== "string") {
|
|
21407
21571
|
throw new ClientModeError("INVALID_MESSAGE", "Server URL is required.");
|
|
21408
21572
|
}
|
|
@@ -21415,7 +21579,7 @@ var PluginControlRuntime = class {
|
|
|
21415
21579
|
if (this.settings === void 0) {
|
|
21416
21580
|
throw new ClientModeError("SETTINGS_UNAVAILABLE", "DSH user settings are unavailable in this profile.");
|
|
21417
21581
|
}
|
|
21418
|
-
const role =
|
|
21582
|
+
const role = record5(payload).role;
|
|
21419
21583
|
if (role !== "host" && role !== "client") {
|
|
21420
21584
|
throw new ClientModeError("INVALID_MESSAGE", "Role must be Host or Client.");
|
|
21421
21585
|
}
|
|
@@ -21429,7 +21593,7 @@ var PluginControlRuntime = class {
|
|
|
21429
21593
|
}
|
|
21430
21594
|
async setDevelopment(payload) {
|
|
21431
21595
|
if (this.settings === void 0) throw new ClientModeError("SETTINGS_UNAVAILABLE", "DSH user settings are unavailable in this profile.");
|
|
21432
|
-
const value =
|
|
21596
|
+
const value = record5(payload);
|
|
21433
21597
|
if (value.terminalEnabled !== void 0 && typeof value.terminalEnabled !== "boolean") throw new ClientModeError("INVALID_MESSAGE", "The terminal switch must be a boolean.");
|
|
21434
21598
|
if (value.ports !== void 0 && (!Array.isArray(value.ports) || value.ports.some((port) => !Number.isInteger(port)))) throw new ClientModeError("INVALID_MESSAGE", "Loopback ports must be integers.");
|
|
21435
21599
|
if (value.terminalEnabled === void 0 && value.ports === void 0) throw new ClientModeError("INVALID_MESSAGE", "A terminal switch or loopback ports are required.");
|
|
@@ -21448,7 +21612,7 @@ var PluginControlRuntime = class {
|
|
|
21448
21612
|
if (this.settings === void 0) {
|
|
21449
21613
|
throw new ClientModeError("SETTINGS_UNAVAILABLE", "DSH user settings are unavailable in this profile.");
|
|
21450
21614
|
}
|
|
21451
|
-
const enabled =
|
|
21615
|
+
const enabled = record5(payload).enabled;
|
|
21452
21616
|
if (typeof enabled !== "boolean") {
|
|
21453
21617
|
throw new ClientModeError("INVALID_MESSAGE", "Codex Remote enabled must be a boolean.");
|
|
21454
21618
|
}
|
|
@@ -21462,16 +21626,18 @@ var PluginControlRuntime = class {
|
|
|
21462
21626
|
}
|
|
21463
21627
|
async setAcp(payload) {
|
|
21464
21628
|
if (this.settings === void 0) throw new ClientModeError("SETTINGS_UNAVAILABLE", "DSH user settings are unavailable in this profile.");
|
|
21465
|
-
const value =
|
|
21466
|
-
|
|
21629
|
+
const value = record5(payload);
|
|
21630
|
+
const backend = value.backend;
|
|
21631
|
+
const enabled = value.enabled;
|
|
21632
|
+
if (typeof backend !== "string" || typeof enabled !== "boolean") throw new ClientModeError("INVALID_MESSAGE", "ACP backend and enabled are required.");
|
|
21467
21633
|
const current = resolveConfig(this.settings.get());
|
|
21468
|
-
const backends = current.acp?.backends.map((item) => item.id ===
|
|
21634
|
+
const backends = current.acp?.backends.map((item) => item.id === backend ? { ...item, enabled } : item) ?? [];
|
|
21469
21635
|
await this.settings.replace({ ...editableConfig(current), acp: { enabled: current.acp?.enabled ?? true, backends } });
|
|
21470
21636
|
return this.settingsView();
|
|
21471
21637
|
}
|
|
21472
21638
|
async addAcp(payload) {
|
|
21473
21639
|
if (this.settings === void 0) throw new ClientModeError("SETTINGS_UNAVAILABLE", "DSH user settings are unavailable in this profile.");
|
|
21474
|
-
const value =
|
|
21640
|
+
const value = record5(payload);
|
|
21475
21641
|
if (typeof value.id !== "string" || typeof value.command !== "string" || !Array.isArray(value.args) || !value.args.every((item) => typeof item === "string")) {
|
|
21476
21642
|
throw new ClientModeError("INVALID_MESSAGE", "ACP name, command, and arguments are required.");
|
|
21477
21643
|
}
|
|
@@ -21484,7 +21650,7 @@ var PluginControlRuntime = class {
|
|
|
21484
21650
|
}
|
|
21485
21651
|
async removeAcp(payload) {
|
|
21486
21652
|
if (this.settings === void 0) throw new ClientModeError("SETTINGS_UNAVAILABLE", "DSH user settings are unavailable in this profile.");
|
|
21487
|
-
const id4 =
|
|
21653
|
+
const id4 = record5(payload).id;
|
|
21488
21654
|
if (typeof id4 !== "string" || ["codex", "cursor", "kimi"].includes(id4)) throw new ClientModeError("INVALID_MESSAGE", "Only custom ACP backends can be removed.");
|
|
21489
21655
|
const current = resolveConfig(this.settings.get());
|
|
21490
21656
|
const backends = (current.acp?.backends ?? []).filter((item) => item.id !== id4);
|
|
@@ -21597,11 +21763,11 @@ function editableConfig(config) {
|
|
|
21597
21763
|
...config.acp === void 0 ? {} : { acp: { enabled: config.acp.enabled, backends: config.acp.backends } }
|
|
21598
21764
|
};
|
|
21599
21765
|
}
|
|
21600
|
-
function
|
|
21766
|
+
function isRecord9(value) {
|
|
21601
21767
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21602
21768
|
}
|
|
21603
|
-
function
|
|
21604
|
-
if (!
|
|
21769
|
+
function record5(value) {
|
|
21770
|
+
if (!isRecord9(value)) throw new ClientModeError("INVALID_MESSAGE", "The control request payload is invalid.");
|
|
21605
21771
|
return value;
|
|
21606
21772
|
}
|
|
21607
21773
|
function ok3(value) {
|
|
@@ -23197,6 +23363,58 @@ function crumbs(path) {
|
|
|
23197
23363
|
return result;
|
|
23198
23364
|
}
|
|
23199
23365
|
|
|
23366
|
+
// src/harness-api-history.ts
|
|
23367
|
+
var SESSION_HISTORY_PAGE_SIZES = [50, 30, 20, 12, 6, 3, 1];
|
|
23368
|
+
function callSessionHistory(callWithTimeout, payload, rpcId2) {
|
|
23369
|
+
const fallbackPageSizes = sessionHistoryFallbackPageSizes(payloadMaxMessages(payload));
|
|
23370
|
+
return callHistoryWithRetry(callWithTimeout, payload, rpcId2, fallbackPageSizes);
|
|
23371
|
+
}
|
|
23372
|
+
async function callHistoryWithRetry(callWithTimeout, payload, rpcId2, pageSizes) {
|
|
23373
|
+
for (const maxMessages of pageSizes) {
|
|
23374
|
+
const requestPayload = historyRequestPayload(payload, maxMessages);
|
|
23375
|
+
const response = await callWithTimeout(requestPayload);
|
|
23376
|
+
const request = createRpcResponse(rpcId2, response.result);
|
|
23377
|
+
if (encodeMessage(request).byteLength <= MAX_SECURE_MESSAGE_BYTES) return response;
|
|
23378
|
+
if (maxMessages === pageSizes[pageSizes.length - 1]) {
|
|
23379
|
+
throw new RpcError(
|
|
23380
|
+
"RESPONSE_TOO_LARGE",
|
|
23381
|
+
"The Host response is too large for the remote channel. Request a smaller page.",
|
|
23382
|
+
{ maxBytes: MAX_SECURE_MESSAGE_BYTES },
|
|
23383
|
+
true
|
|
23384
|
+
);
|
|
23385
|
+
}
|
|
23386
|
+
}
|
|
23387
|
+
throw new RpcError("INTERNAL_ERROR", "Failed to load session history with a fallback page size.");
|
|
23388
|
+
}
|
|
23389
|
+
function sessionHistoryFallbackPageSizes(requestedMaxMessages) {
|
|
23390
|
+
const requested = normalizeSessionHistoryPageSize(requestedMaxMessages);
|
|
23391
|
+
const sizes = [];
|
|
23392
|
+
if (requested === void 0) {
|
|
23393
|
+
sizes.push(...SESSION_HISTORY_PAGE_SIZES);
|
|
23394
|
+
return sizes;
|
|
23395
|
+
}
|
|
23396
|
+
sizes.push(requested);
|
|
23397
|
+
for (const value of SESSION_HISTORY_PAGE_SIZES) {
|
|
23398
|
+
if (value < requested && !sizes.includes(value)) sizes.push(value);
|
|
23399
|
+
}
|
|
23400
|
+
return sizes;
|
|
23401
|
+
}
|
|
23402
|
+
function normalizeSessionHistoryPageSize(value) {
|
|
23403
|
+
if (value === void 0) return void 0;
|
|
23404
|
+
if (!Number.isInteger(value)) return void 0;
|
|
23405
|
+
if (value <= 0) return void 0;
|
|
23406
|
+
return Math.max(1, value);
|
|
23407
|
+
}
|
|
23408
|
+
function payloadMaxMessages(payload) {
|
|
23409
|
+
if (payload === null || typeof payload !== "object") return void 0;
|
|
23410
|
+
const value = payload.maxMessages;
|
|
23411
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
|
|
23412
|
+
}
|
|
23413
|
+
function historyRequestPayload(payload, maxMessages) {
|
|
23414
|
+
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) return { maxMessages };
|
|
23415
|
+
return { ...payload, maxMessages };
|
|
23416
|
+
}
|
|
23417
|
+
|
|
23200
23418
|
// src/harness-api-bridge.ts
|
|
23201
23419
|
var callSchema2 = external_exports.object({
|
|
23202
23420
|
method: external_exports.string().min(1).max(80),
|
|
@@ -23368,7 +23586,6 @@ var NATIVE_CALL_TIMEOUT_MS = 3e4;
|
|
|
23368
23586
|
var MAX_ACTIVE_API_TRANSFERS = MAX_ACTIVE_TRANSFERS_PER_DIRECTION;
|
|
23369
23587
|
var API_TRANSFER_IDLE_MS = TRANSFER_IDLE_MS;
|
|
23370
23588
|
var INLINE_TRANSFER_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
23371
|
-
var SESSION_HISTORY_PAGE_SIZES = [50, 30, 20, 12, 6, 3, 1];
|
|
23372
23589
|
var HarnessApiBridge = class {
|
|
23373
23590
|
constructor(api, publish, maxStreams = 8, logger, typertGateway, harnessVersion) {
|
|
23374
23591
|
this.api = api;
|
|
@@ -23926,55 +24143,6 @@ function frameSessionId(frame) {
|
|
|
23926
24143
|
const payload = frame.payload;
|
|
23927
24144
|
return typeof payload.sessionId === "string" && payload.sessionId.length > 0 ? payload.sessionId : void 0;
|
|
23928
24145
|
}
|
|
23929
|
-
function callSessionHistory(callWithTimeout, payload, rpcId2) {
|
|
23930
|
-
const fallbackPageSizes = sessionHistoryFallbackPageSizes(payloadMaxMessages(payload));
|
|
23931
|
-
return callHistoryWithRetry(callWithTimeout, payload, rpcId2, fallbackPageSizes);
|
|
23932
|
-
}
|
|
23933
|
-
async function callHistoryWithRetry(callWithTimeout, payload, rpcId2, pageSizes) {
|
|
23934
|
-
for (const maxMessages of pageSizes) {
|
|
23935
|
-
const requestPayload = historyRequestPayload(payload, maxMessages);
|
|
23936
|
-
const response = await callWithTimeout(requestPayload);
|
|
23937
|
-
const request = createRpcResponse(rpcId2, response.result);
|
|
23938
|
-
if (encodeMessage(request).byteLength <= MAX_SECURE_MESSAGE_BYTES) return response;
|
|
23939
|
-
if (maxMessages === pageSizes[pageSizes.length - 1]) {
|
|
23940
|
-
throw new RpcError(
|
|
23941
|
-
"RESPONSE_TOO_LARGE",
|
|
23942
|
-
"The Host response is too large for the remote channel. Request a smaller page.",
|
|
23943
|
-
{ maxBytes: MAX_SECURE_MESSAGE_BYTES },
|
|
23944
|
-
true
|
|
23945
|
-
);
|
|
23946
|
-
}
|
|
23947
|
-
}
|
|
23948
|
-
throw new RpcError("INTERNAL_ERROR", "Failed to load session history with a fallback page size.");
|
|
23949
|
-
}
|
|
23950
|
-
function sessionHistoryFallbackPageSizes(requestedMaxMessages) {
|
|
23951
|
-
const requested = normalizeSessionHistoryPageSize(requestedMaxMessages);
|
|
23952
|
-
const sizes = [];
|
|
23953
|
-
if (requested === void 0) {
|
|
23954
|
-
sizes.push(...SESSION_HISTORY_PAGE_SIZES);
|
|
23955
|
-
return sizes;
|
|
23956
|
-
}
|
|
23957
|
-
sizes.push(requested);
|
|
23958
|
-
for (const value of SESSION_HISTORY_PAGE_SIZES) {
|
|
23959
|
-
if (value < requested && !sizes.includes(value)) sizes.push(value);
|
|
23960
|
-
}
|
|
23961
|
-
return sizes;
|
|
23962
|
-
}
|
|
23963
|
-
function normalizeSessionHistoryPageSize(value) {
|
|
23964
|
-
if (value === void 0) return void 0;
|
|
23965
|
-
if (!Number.isInteger(value)) return void 0;
|
|
23966
|
-
if (value <= 0) return void 0;
|
|
23967
|
-
return Math.max(1, value);
|
|
23968
|
-
}
|
|
23969
|
-
function payloadMaxMessages(payload) {
|
|
23970
|
-
if (payload === null || typeof payload !== "object") return void 0;
|
|
23971
|
-
const value = payload.maxMessages;
|
|
23972
|
-
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
|
|
23973
|
-
}
|
|
23974
|
-
function historyRequestPayload(payload, maxMessages) {
|
|
23975
|
-
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) return { maxMessages };
|
|
23976
|
-
return { ...payload, maxMessages };
|
|
23977
|
-
}
|
|
23978
24146
|
function withTimeout(promise, ms, message) {
|
|
23979
24147
|
return new Promise((resolve4, reject) => {
|
|
23980
24148
|
const timer = setTimeout(() => {
|
|
@@ -24171,7 +24339,8 @@ var HarnessRemoteBridge = class {
|
|
|
24171
24339
|
const startedAt = performance.now();
|
|
24172
24340
|
const signal = AbortSignal.timeout(6e4);
|
|
24173
24341
|
try {
|
|
24174
|
-
const
|
|
24342
|
+
const nativePayload = normalizeWorkspaceRequestPayload(params.endpoint, params.payload, this.harnessVersion);
|
|
24343
|
+
const nativeResult = params.endpoint === "commands/execute" ? await dispatchCommandForHost(this.gateway, params.payload, signal, this.harnessVersion) : await this.gateway.dispatch(params.endpoint, nativePayload, signal);
|
|
24175
24344
|
const result = params.endpoint === "directoryPicker/list" && needsDirectoryFallback(nativeResult) ? await this.directoryList(params.payload, signal) : nativeResult;
|
|
24176
24345
|
this.logger?.debug("harness remote call ok", {
|
|
24177
24346
|
endpoint: params.endpoint,
|
|
@@ -24317,7 +24486,7 @@ var HarnessRemoteBridge = class {
|
|
|
24317
24486
|
this.streams.set(params.streamId, { controller });
|
|
24318
24487
|
let source;
|
|
24319
24488
|
try {
|
|
24320
|
-
source = (this.codexWorkspace === void 0 ? void 0 : await this.codexWorkspace.open(params.endpoint, params.payload, controller.signal)) ?? await this.gateway.open(params.endpoint, params.payload, controller.signal);
|
|
24489
|
+
source = (this.codexWorkspace === void 0 ? void 0 : await this.codexWorkspace.open(params.endpoint, params.payload, controller.signal)) ?? await this.gateway.open(params.endpoint, normalizeWorkspaceChangesPayload(params.endpoint, params.payload, this.harnessVersion), controller.signal);
|
|
24321
24490
|
controller.signal.throwIfAborted();
|
|
24322
24491
|
} catch (error) {
|
|
24323
24492
|
this.streams.delete(params.streamId);
|
|
@@ -24383,6 +24552,24 @@ var HarnessRemoteBridge = class {
|
|
|
24383
24552
|
for (const [id4, transfer] of this.outgoingTransfers) if (transfer.touchedAt < cutoff) this.outgoingTransfers.delete(id4);
|
|
24384
24553
|
}
|
|
24385
24554
|
};
|
|
24555
|
+
function normalizeWorkspaceChangesPayload(endpoint, payload, harnessVersion) {
|
|
24556
|
+
if (endpoint !== "workspaceFiles/changes" || !requiresWorkspaceChangePath(harnessVersion)) return payload;
|
|
24557
|
+
if (!isRecord10(payload) || !isRecord10(payload.args) || Object.hasOwn(payload.args, "path")) return payload;
|
|
24558
|
+
return { ...payload, args: { ...payload.args, path: "." } };
|
|
24559
|
+
}
|
|
24560
|
+
function normalizeWorkspaceRequestPayload(endpoint, payload, harnessVersion) {
|
|
24561
|
+
if (endpoint !== "workspaceFiles/readBytes" || !requiresWorkspaceChangePath(harnessVersion)) return payload;
|
|
24562
|
+
if (!isRecord10(payload) || !isRecord10(payload.args)) return payload;
|
|
24563
|
+
const args = payload.args;
|
|
24564
|
+
if (!Object.hasOwn(args, "range") || Object.hasOwn(args, "options")) return payload;
|
|
24565
|
+
const { range, ...rest } = args;
|
|
24566
|
+
return { ...payload, args: { ...rest, options: { range } } };
|
|
24567
|
+
}
|
|
24568
|
+
function requiresWorkspaceChangePath(version) {
|
|
24569
|
+
const match = /^(?:dsh-)?v?(\d+)\.(\d+)\.(\d+)(?:-|$)/u.exec(version?.trim() ?? "");
|
|
24570
|
+
if (match === null) return false;
|
|
24571
|
+
return Number(match[1]) === 0 && Number(match[2]) === 1 && Number(match[3]) >= 7;
|
|
24572
|
+
}
|
|
24386
24573
|
async function dispatchCommandForHost(gateway, payload, signal, harnessVersion) {
|
|
24387
24574
|
const parsed = commandExecutePayloadSchema.parse(payload);
|
|
24388
24575
|
const legacyPayload = {
|
|
@@ -24427,14 +24614,14 @@ function needsDirectoryFallback(result) {
|
|
|
24427
24614
|
return code.includes("capability") || code === "directory-picker/unavailable" || code === "directory-picker-unavailable" || message.includes("browse capability") || message.includes("browser capability") || message.includes("brower capability") || message.includes("directory-picker-unavailable");
|
|
24428
24615
|
}
|
|
24429
24616
|
function requestArgs(payload) {
|
|
24430
|
-
const root =
|
|
24431
|
-
const args =
|
|
24432
|
-
return
|
|
24617
|
+
const root = record6(payload);
|
|
24618
|
+
const args = isRecord10(root.args) ? root.args : root;
|
|
24619
|
+
return record6(args.request ?? args._request ?? args);
|
|
24433
24620
|
}
|
|
24434
|
-
function
|
|
24435
|
-
return
|
|
24621
|
+
function record6(value) {
|
|
24622
|
+
return isRecord10(value) ? value : {};
|
|
24436
24623
|
}
|
|
24437
|
-
function
|
|
24624
|
+
function isRecord10(value) {
|
|
24438
24625
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24439
24626
|
}
|
|
24440
24627
|
|
|
@@ -24628,7 +24815,7 @@ var CodexAppServerClient = class {
|
|
|
24628
24815
|
this.handleProcessFailure("CODEX_INVALID_RESPONSE", new Error("Codex App Server emitted invalid JSON."));
|
|
24629
24816
|
return;
|
|
24630
24817
|
}
|
|
24631
|
-
if (!
|
|
24818
|
+
if (!isRecord11(value)) {
|
|
24632
24819
|
this.handleProcessFailure("CODEX_INVALID_RESPONSE", new Error("Codex App Server emitted an invalid message."));
|
|
24633
24820
|
return;
|
|
24634
24821
|
}
|
|
@@ -24673,12 +24860,12 @@ var CodexAppServerClient = class {
|
|
|
24673
24860
|
}
|
|
24674
24861
|
};
|
|
24675
24862
|
function safeUpstreamError(value) {
|
|
24676
|
-
if (!
|
|
24863
|
+
if (!isRecord11(value) || typeof value.message !== "string") return "Codex App Server rejected the request.";
|
|
24677
24864
|
const message = value.message.toLowerCase();
|
|
24678
24865
|
if (message.includes("active writer")) return "Codex thread already has an active writer.";
|
|
24679
24866
|
return message.includes("not initialized") ? "Codex App Server is not initialized." : "Codex App Server rejected the request.";
|
|
24680
24867
|
}
|
|
24681
|
-
function
|
|
24868
|
+
function isRecord11(value) {
|
|
24682
24869
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24683
24870
|
}
|
|
24684
24871
|
|
|
@@ -25047,15 +25234,15 @@ function decodeCanonicalBase643(value) {
|
|
|
25047
25234
|
}
|
|
25048
25235
|
return decoded;
|
|
25049
25236
|
}
|
|
25050
|
-
function
|
|
25237
|
+
function isRecord12(value) {
|
|
25051
25238
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25052
25239
|
}
|
|
25053
25240
|
function safeErrorCode2(error) {
|
|
25054
|
-
if (
|
|
25241
|
+
if (isRecord12(error) && typeof error.code === "string") return error.code;
|
|
25055
25242
|
return "UNKNOWN";
|
|
25056
25243
|
}
|
|
25057
25244
|
function safeMethod(input2) {
|
|
25058
|
-
return
|
|
25245
|
+
return isRecord12(input2) && typeof input2.method === "string" ? input2.method : "invalid";
|
|
25059
25246
|
}
|
|
25060
25247
|
function concatChunks3(chunks, totalBytes) {
|
|
25061
25248
|
const output = new Uint8Array(totalBytes);
|
|
@@ -25485,14 +25672,14 @@ var CodexRemoteDomain = class {
|
|
|
25485
25672
|
await this.assertResultThreadAllowed(result);
|
|
25486
25673
|
if (codexPermissionPresetFromResponse(result) !== params.permissionPreset) {
|
|
25487
25674
|
await this.callUpstream("thread/settings/update", { threadId, ...settings });
|
|
25488
|
-
result = { ...
|
|
25675
|
+
result = { ...isRecord13(result) ? result : {}, ...settings, sandbox: settings.sandboxPolicy };
|
|
25489
25676
|
}
|
|
25490
25677
|
}
|
|
25491
25678
|
await this.publishPermission(threadId, result);
|
|
25492
25679
|
return result;
|
|
25493
25680
|
}
|
|
25494
25681
|
async publishPermission(threadId, value) {
|
|
25495
|
-
const source =
|
|
25682
|
+
const source = isRecord13(value) ? value : {};
|
|
25496
25683
|
const threadSettings = { approvalPolicy: source.approvalPolicy, sandboxPolicy: source.sandboxPolicy ?? source.sandbox };
|
|
25497
25684
|
await this.handleInbound({ kind: "notification", method: "thread/settings/updated", params: { threadId, threadSettings } });
|
|
25498
25685
|
}
|
|
@@ -25588,9 +25775,9 @@ var CodexRemoteDomain = class {
|
|
|
25588
25775
|
itemsView,
|
|
25589
25776
|
...cursor2 === void 0 ? {} : { cursor: cursor2 }
|
|
25590
25777
|
});
|
|
25591
|
-
const pageResult =
|
|
25778
|
+
const pageResult = isRecord13(result) ? result : {};
|
|
25592
25779
|
for (const rawTurn of array2(pageResult.data)) {
|
|
25593
|
-
if (!
|
|
25780
|
+
if (!isRecord13(rawTurn)) continue;
|
|
25594
25781
|
const turnId = typeof rawTurn.id === "string" ? rawTurn.id : void 0;
|
|
25595
25782
|
const items = rawTurn.itemsView === "full" || turnId === void 0 ? array2(rawTurn.items) : await this.readThreadItems(connectionId, threadId, turnId, array2(rawTurn.items));
|
|
25596
25783
|
turns.push({ ...rawTurn, items });
|
|
@@ -25612,9 +25799,9 @@ var CodexRemoteDomain = class {
|
|
|
25612
25799
|
sortDirection: "asc",
|
|
25613
25800
|
...cursor2 === void 0 ? {} : { cursor: cursor2 }
|
|
25614
25801
|
});
|
|
25615
|
-
const pageResult =
|
|
25802
|
+
const pageResult = isRecord13(result) ? result : {};
|
|
25616
25803
|
for (const entry of array2(pageResult.data)) {
|
|
25617
|
-
if (
|
|
25804
|
+
if (isRecord13(entry) && entry.item !== void 0) items.push(entry.item);
|
|
25618
25805
|
}
|
|
25619
25806
|
cursor2 = typeof pageResult.nextCursor === "string" && pageResult.nextCursor.length > 0 ? pageResult.nextCursor : void 0;
|
|
25620
25807
|
if (cursor2 === void 0) break;
|
|
@@ -25678,7 +25865,7 @@ var CodexRemoteDomain = class {
|
|
|
25678
25865
|
return [...this.peers.values()].some((peer) => peer.hasThreadSubscription(threadId));
|
|
25679
25866
|
}
|
|
25680
25867
|
resolveUpstreamApproval(params) {
|
|
25681
|
-
if (!
|
|
25868
|
+
if (!isRecord13(params) || typeof params.requestId !== "string" && typeof params.requestId !== "number") return;
|
|
25682
25869
|
for (const [handle, approval] of this.approvals) {
|
|
25683
25870
|
if (approval.upstreamId === params.requestId) this.approvals.delete(handle);
|
|
25684
25871
|
}
|
|
@@ -25895,24 +26082,24 @@ function codexBinaryCandidates(configured, hostPlatform = process.platform, user
|
|
|
25895
26082
|
])];
|
|
25896
26083
|
}
|
|
25897
26084
|
function parseCallEnvelope(input2) {
|
|
25898
|
-
if (!
|
|
26085
|
+
if (!isRecord13(input2) || typeof input2.method !== "string" || !("params" in input2) || Object.keys(input2).some((key) => key !== "method" && key !== "params")) {
|
|
25899
26086
|
throw new RpcError("INVALID_MESSAGE", "The Codex call envelope is invalid.");
|
|
25900
26087
|
}
|
|
25901
26088
|
return { method: input2.method, params: input2.params };
|
|
25902
26089
|
}
|
|
25903
26090
|
function parseRespond(input2) {
|
|
25904
|
-
if (!
|
|
26091
|
+
if (!isRecord13(input2) || typeof input2.requestHandle !== "string" || !["accept", "decline", "cancel"].includes(String(input2.decision)) || Object.keys(input2).some((key) => key !== "requestHandle" && key !== "decision")) {
|
|
25905
26092
|
throw new RpcError("INVALID_MESSAGE", "The Codex approval response is invalid.");
|
|
25906
26093
|
}
|
|
25907
26094
|
return input2;
|
|
25908
26095
|
}
|
|
25909
26096
|
function accountCanRun(result) {
|
|
25910
|
-
if (!
|
|
25911
|
-
return result.requiresOpenaiAuth === false ||
|
|
26097
|
+
if (!isRecord13(result) || typeof result.requiresOpenaiAuth !== "boolean") return false;
|
|
26098
|
+
return result.requiresOpenaiAuth === false || isRecord13(result.account);
|
|
25912
26099
|
}
|
|
25913
26100
|
function sanitizeAccount(result) {
|
|
25914
|
-
if (!
|
|
25915
|
-
const account =
|
|
26101
|
+
if (!isRecord13(result)) throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned invalid account state.");
|
|
26102
|
+
const account = isRecord13(result.account) ? result.account : void 0;
|
|
25916
26103
|
return {
|
|
25917
26104
|
authenticated: account !== void 0 || result.requiresOpenaiAuth === false,
|
|
25918
26105
|
requiresOpenaiAuth: result.requiresOpenaiAuth === true,
|
|
@@ -25925,11 +26112,11 @@ function sanitizeAccount(result) {
|
|
|
25925
26112
|
};
|
|
25926
26113
|
}
|
|
25927
26114
|
function sanitizeThreadList(result) {
|
|
25928
|
-
if (!
|
|
26115
|
+
if (!isRecord13(result) || !Array.isArray(result.data)) {
|
|
25929
26116
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid thread list.");
|
|
25930
26117
|
}
|
|
25931
26118
|
const data2 = result.data.flatMap((value) => {
|
|
25932
|
-
if (!
|
|
26119
|
+
if (!isRecord13(value) || typeof value.id !== "string") return [];
|
|
25933
26120
|
return [{
|
|
25934
26121
|
id: value.id,
|
|
25935
26122
|
...typeof value.sessionId === "string" ? { sessionId: value.sessionId } : {},
|
|
@@ -25941,7 +26128,7 @@ function sanitizeThreadList(result) {
|
|
|
25941
26128
|
...typeof value.updatedAt === "number" && Number.isFinite(value.updatedAt) ? { updatedAt: value.updatedAt } : {},
|
|
25942
26129
|
...typeof value.archived === "boolean" ? { archived: value.archived } : {},
|
|
25943
26130
|
...typeof value.isPinned === "boolean" ? { isPinned: value.isPinned } : {},
|
|
25944
|
-
...
|
|
26131
|
+
...isRecord13(value.status) ? { status: value.status } : {}
|
|
25945
26132
|
}];
|
|
25946
26133
|
});
|
|
25947
26134
|
return {
|
|
@@ -25951,18 +26138,18 @@ function sanitizeThreadList(result) {
|
|
|
25951
26138
|
};
|
|
25952
26139
|
}
|
|
25953
26140
|
function filterThreadListByWorkspaceAuthority(result, authority) {
|
|
25954
|
-
if (!
|
|
26141
|
+
if (!isRecord13(result) || !Array.isArray(result.data)) {
|
|
25955
26142
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid thread list.");
|
|
25956
26143
|
}
|
|
25957
26144
|
return {
|
|
25958
26145
|
...result,
|
|
25959
|
-
data: result.data.map((
|
|
26146
|
+
data: result.data.map((record7) => isRecord13(record7) ? record7 : void 0).filter((thread) => thread !== void 0 && isThreadAllowedByWorkspaceAuthority(thread, authority))
|
|
25960
26147
|
};
|
|
25961
26148
|
}
|
|
25962
26149
|
function sanitizeProject(value) {
|
|
25963
|
-
if (!
|
|
26150
|
+
if (!isRecord13(value) || typeof value.id !== "string" || typeof value.name !== "string") return void 0;
|
|
25964
26151
|
const roots = Array.isArray(value.roots) ? value.roots.flatMap((root) => {
|
|
25965
|
-
const path =
|
|
26152
|
+
const path = isRecord13(root) && typeof root.path === "string" && root.path.length > 0 ? root.path : void 0;
|
|
25966
26153
|
return path === void 0 || !isAbsolute3(path) ? [] : [{ path }];
|
|
25967
26154
|
}) : [];
|
|
25968
26155
|
if (roots.length === 0) return void 0;
|
|
@@ -25976,7 +26163,7 @@ function sanitizeProject(value) {
|
|
|
25976
26163
|
};
|
|
25977
26164
|
}
|
|
25978
26165
|
function sanitizeProjectList(result) {
|
|
25979
|
-
if (!
|
|
26166
|
+
if (!isRecord13(result) || !Array.isArray(result.data)) {
|
|
25980
26167
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid project list.");
|
|
25981
26168
|
}
|
|
25982
26169
|
const data2 = result.data.flatMap((value) => sanitizeProject(value) ?? []);
|
|
@@ -25986,7 +26173,7 @@ function sanitizeProjectList(result) {
|
|
|
25986
26173
|
};
|
|
25987
26174
|
}
|
|
25988
26175
|
function sanitizeProjectCreate(result) {
|
|
25989
|
-
const project =
|
|
26176
|
+
const project = isRecord13(result) ? sanitizeProject(result.project) : void 0;
|
|
25990
26177
|
if (project === void 0) {
|
|
25991
26178
|
throw new RpcError("CODEX_INVALID_RESPONSE", "Codex App Server returned an invalid created project.");
|
|
25992
26179
|
}
|
|
@@ -26018,19 +26205,19 @@ function codexDirectoryCrumbs(root, path) {
|
|
|
26018
26205
|
return crumbs2;
|
|
26019
26206
|
}
|
|
26020
26207
|
function extractThread(result) {
|
|
26021
|
-
return
|
|
26208
|
+
return isRecord13(result) && isRecord13(result.thread) ? result.thread : void 0;
|
|
26022
26209
|
}
|
|
26023
26210
|
function extractTurnId(result) {
|
|
26024
|
-
if (!
|
|
26211
|
+
if (!isRecord13(result)) return void 0;
|
|
26025
26212
|
if (typeof result.turnId === "string" && result.turnId.length > 0) return result.turnId;
|
|
26026
|
-
if (
|
|
26213
|
+
if (isRecord13(result.turn) && typeof result.turn.id === "string" && result.turn.id.length > 0) return result.turn.id;
|
|
26027
26214
|
return void 0;
|
|
26028
26215
|
}
|
|
26029
26216
|
function extractThreadId(params) {
|
|
26030
|
-
if (!
|
|
26217
|
+
if (!isRecord13(params)) return void 0;
|
|
26031
26218
|
if (typeof params.threadId === "string") return params.threadId;
|
|
26032
|
-
if (
|
|
26033
|
-
if (
|
|
26219
|
+
if (isRecord13(params.thread) && typeof params.thread.id === "string") return params.thread.id;
|
|
26220
|
+
if (isRecord13(params.turn) && typeof params.turn.threadId === "string") return params.turn.threadId;
|
|
26034
26221
|
return void 0;
|
|
26035
26222
|
}
|
|
26036
26223
|
function optionalInteger2(value) {
|
|
@@ -26072,13 +26259,13 @@ function mapCodexImageInputs(params) {
|
|
|
26072
26259
|
return {
|
|
26073
26260
|
...params,
|
|
26074
26261
|
input: params.input.map((value) => {
|
|
26075
|
-
if (!
|
|
26262
|
+
if (!isRecord13(value) || value.type !== "image" || typeof value.mediaType !== "string" || typeof value.data !== "string") return value;
|
|
26076
26263
|
return { type: "image", url: `data:${value.mediaType};base64,${value.data}` };
|
|
26077
26264
|
})
|
|
26078
26265
|
};
|
|
26079
26266
|
}
|
|
26080
26267
|
function sanitizeApprovalParams(params, requestHandle) {
|
|
26081
|
-
if (!
|
|
26268
|
+
if (!isRecord13(params)) return { requestHandle };
|
|
26082
26269
|
const safe = { ...params };
|
|
26083
26270
|
delete safe.proposedExecpolicyAmendment;
|
|
26084
26271
|
delete safe.additionalPermissions;
|
|
@@ -26109,7 +26296,7 @@ function isProjectListFallbackError(error) {
|
|
|
26109
26296
|
function canTryNextBinary(error) {
|
|
26110
26297
|
return !(error instanceof RpcError) || !["CODEX_AUTH_REQUIRED", "CODEX_CLOSED"].includes(error.code);
|
|
26111
26298
|
}
|
|
26112
|
-
function
|
|
26299
|
+
function isRecord13(value) {
|
|
26113
26300
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26114
26301
|
}
|
|
26115
26302
|
function array2(value) {
|
|
@@ -26337,7 +26524,11 @@ var CodexWorkspaceBridge = class {
|
|
|
26337
26524
|
return { ok: true, value: { path, entries: result, truncated: entries.length > 500 } };
|
|
26338
26525
|
}
|
|
26339
26526
|
const info = await stat5(target2);
|
|
26340
|
-
|
|
26527
|
+
const absolutePath = target2;
|
|
26528
|
+
const version = `${info.mtimeMs}:${info.size}`;
|
|
26529
|
+
if (endpoint === "workspaceFiles/stat") {
|
|
26530
|
+
return { ok: true, value: { absolutePath, version, bytes: info.size } };
|
|
26531
|
+
}
|
|
26341
26532
|
if (!info.isFile()) throw new RpcError("CODEX_WORKSPACE_INVALID_PATH", "The requested workspace path is not a file.");
|
|
26342
26533
|
const offset = readOffset(args);
|
|
26343
26534
|
const limit = readLimit(args);
|
|
@@ -26345,7 +26536,17 @@ var CodexWorkspaceBridge = class {
|
|
|
26345
26536
|
if (bytes.byteLength > MAX_READ_BYTES) throw new RpcError("CODEX_WORKSPACE_TOO_LARGE", "The requested workspace file is too large.");
|
|
26346
26537
|
if (endpoint === "workspaceFiles/readBytes") {
|
|
26347
26538
|
const slice2 = bytes.subarray(offset, Math.min(offset + limit, bytes.length));
|
|
26348
|
-
return {
|
|
26539
|
+
return {
|
|
26540
|
+
ok: true,
|
|
26541
|
+
value: {
|
|
26542
|
+
absolutePath,
|
|
26543
|
+
version,
|
|
26544
|
+
bytes: bytes.length,
|
|
26545
|
+
offset,
|
|
26546
|
+
data: slice2.toString("base64"),
|
|
26547
|
+
eof: offset + slice2.length >= bytes.length
|
|
26548
|
+
}
|
|
26549
|
+
};
|
|
26349
26550
|
}
|
|
26350
26551
|
const text = bytes.toString("utf8");
|
|
26351
26552
|
const slice = text.slice(offset, offset + limit);
|
|
@@ -26455,7 +26656,7 @@ var CodexWorkspaceBridge = class {
|
|
|
26455
26656
|
throw new RpcError("METHOD_NOT_FOUND", "The requested terminal method does not exist.");
|
|
26456
26657
|
}
|
|
26457
26658
|
async createTerminal(sessionId, cwd, args) {
|
|
26458
|
-
const request =
|
|
26659
|
+
const request = isRecord14(args.request) ? args.request : {};
|
|
26459
26660
|
const id4 = stringId(request.id);
|
|
26460
26661
|
if ([...this.terminals.values()].some((item) => item.sessionId === sessionId && item.id === id4)) throw new RpcError("REQUEST_CONFLICT", "The terminal id is already active.");
|
|
26461
26662
|
if (this.terminals.size >= MAX_TERMINALS) throw new RpcError("RATE_LIMITED", "Too many remote terminals are active.", void 0, true);
|
|
@@ -26657,10 +26858,10 @@ function screenOf(terminal) {
|
|
|
26657
26858
|
return (terminal.truncated ? "\x1Bc" : "") + terminal.screen.join("");
|
|
26658
26859
|
}
|
|
26659
26860
|
function argsOf(payload) {
|
|
26660
|
-
const value =
|
|
26661
|
-
return
|
|
26861
|
+
const value = isRecord14(payload) ? payload : {};
|
|
26862
|
+
return isRecord14(value.args) ? value.args : value;
|
|
26662
26863
|
}
|
|
26663
|
-
function
|
|
26864
|
+
function isRecord14(value) {
|
|
26664
26865
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26665
26866
|
}
|
|
26666
26867
|
function stringId(value) {
|
|
@@ -26670,13 +26871,19 @@ function stringId(value) {
|
|
|
26670
26871
|
function bounded(value, fallback, max) {
|
|
26671
26872
|
return typeof value === "number" && Number.isInteger(value) && value > 0 ? Math.min(value, max) : fallback;
|
|
26672
26873
|
}
|
|
26874
|
+
function byteOrLineRange(args) {
|
|
26875
|
+
const options = isRecord14(args.options) ? args.options : void 0;
|
|
26876
|
+
if (options !== void 0 && isRecord14(options.range)) return options.range;
|
|
26877
|
+
return isRecord14(args.range) ? args.range : args;
|
|
26878
|
+
}
|
|
26673
26879
|
function readOffset(args) {
|
|
26674
|
-
const range =
|
|
26880
|
+
const range = byteOrLineRange(args);
|
|
26675
26881
|
return typeof range.offset === "number" && Number.isInteger(range.offset) && range.offset >= 0 ? range.offset : 0;
|
|
26676
26882
|
}
|
|
26677
26883
|
function readLimit(args) {
|
|
26678
|
-
const range =
|
|
26679
|
-
|
|
26884
|
+
const range = byteOrLineRange(args);
|
|
26885
|
+
const value = typeof range.length === "number" ? range.length : range.limit;
|
|
26886
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? Math.min(value, MAX_READ_BYTES) : MAX_READ_BYTES;
|
|
26680
26887
|
}
|
|
26681
26888
|
|
|
26682
26889
|
// src/service.ts
|
|
@@ -27725,7 +27932,16 @@ var name = "ds-harness-remote";
|
|
|
27725
27932
|
var legacyLoaderModuleNames = /* @__PURE__ */ new Set(["dsh-remote", "@dsh-remote/plugin"]);
|
|
27726
27933
|
var pluginSettingsNamespace = "ds-harness-remote";
|
|
27727
27934
|
var legacySettingsNamespace = "dsh-remote";
|
|
27728
|
-
|
|
27935
|
+
var DEFAULT_ENTRY_ID = "ds-harness-remote";
|
|
27936
|
+
var INCLUDE_ENTRY_PREFIX = "include:";
|
|
27937
|
+
function apply(ctx, entry = void 0) {
|
|
27938
|
+
const readConfig = () => readEntryConfig(entry);
|
|
27939
|
+
const entryId = locateEntryId(ctx);
|
|
27940
|
+
ctx.inject(["settings"], (settingsContext) => {
|
|
27941
|
+
const settings = settingsContext.settings;
|
|
27942
|
+
if (isLegacySettingsProvider(settings)) return;
|
|
27943
|
+
settingsContext.effect(() => settings.configure({ auto: false }, ctx.fiber));
|
|
27944
|
+
});
|
|
27729
27945
|
const tuiCommandsAvailable = ctx.get("commands", false) !== void 0 && ctx.get("tuiScenes", false) !== void 0;
|
|
27730
27946
|
const tuiBinding = tuiCommandsAvailable ? {} : void 0;
|
|
27731
27947
|
if (tuiBinding !== void 0) installTuiRemoteCommand(ctx, () => tuiBinding.target);
|
|
@@ -27738,7 +27954,7 @@ function apply(ctx, input2 = {}) {
|
|
|
27738
27954
|
if (connection === void 0 || disposePendingControl !== void 0) return;
|
|
27739
27955
|
disposePendingControl = runtimeContext.effect(() => {
|
|
27740
27956
|
const control = new PluginControlRuntime(
|
|
27741
|
-
resolveConfig(
|
|
27957
|
+
resolveConfig(readConfig()),
|
|
27742
27958
|
new IdentityStore().directory,
|
|
27743
27959
|
void 0,
|
|
27744
27960
|
void 0,
|
|
@@ -27750,7 +27966,7 @@ function apply(ctx, input2 = {}) {
|
|
|
27750
27966
|
const startActiveRuntime = async (activeContext) => {
|
|
27751
27967
|
await disposePendingControl?.();
|
|
27752
27968
|
disposePendingControl = void 0;
|
|
27753
|
-
await activate(activeContext,
|
|
27969
|
+
await activate(activeContext, readConfig, entryId, tuiBinding);
|
|
27754
27970
|
};
|
|
27755
27971
|
if (tuiCommandsAvailable || runtimeContext.get("apiProxy") !== void 0 || new TypertGatewaySwitch(gateway).supportsCarrier()) {
|
|
27756
27972
|
return startActiveRuntime(runtimeContext);
|
|
@@ -27764,27 +27980,17 @@ function apply(ctx, input2 = {}) {
|
|
|
27764
27980
|
ctx.inject(["settings", "connection", "typertGateway"], activateWhenCarrierReady);
|
|
27765
27981
|
}
|
|
27766
27982
|
}
|
|
27767
|
-
async function activate(ctx,
|
|
27983
|
+
async function activate(ctx, readConfig, entryId, tuiBinding) {
|
|
27768
27984
|
const settings = ctx.get("settings");
|
|
27769
|
-
const
|
|
27770
|
-
base: input2,
|
|
27771
|
-
applies: "restart",
|
|
27772
|
-
validate: (value) => {
|
|
27773
|
-
resolveConfig(value);
|
|
27774
|
-
}
|
|
27775
|
-
});
|
|
27776
|
-
if (settings !== void 0 && settingsScope !== void 0) {
|
|
27777
|
-
const migration = migrateLegacySettings(settings, settingsScope);
|
|
27778
|
-
reportSettingsMigration(ctx, await migration);
|
|
27779
|
-
}
|
|
27985
|
+
const settingsBinding = await createSettingsBinding(ctx, settings, readConfig, entryId);
|
|
27780
27986
|
const connection = ctx.get("connection");
|
|
27781
27987
|
const webServer = ctx.get("webServer");
|
|
27782
|
-
const resolvedConfig = resolveConfig(
|
|
27988
|
+
const resolvedConfig = resolveConfig(settingsBinding?.get() ?? readConfig());
|
|
27783
27989
|
const config = connection === void 0 && resolvedConfig.serverUrl === void 0 ? { ...resolvedConfig, serverUrl: DEFAULT_REMOTE_SERVER_URL } : resolvedConfig;
|
|
27784
27990
|
const defaultIdentityDirectory = new IdentityStore().directory;
|
|
27785
27991
|
if (!config.enabled) {
|
|
27786
27992
|
if (connection !== void 0) {
|
|
27787
|
-
const controlRuntime2 = new PluginControlRuntime(config, defaultIdentityDirectory,
|
|
27993
|
+
const controlRuntime2 = new PluginControlRuntime(config, defaultIdentityDirectory, settingsBinding, void 0, void 0);
|
|
27788
27994
|
ctx.effect(() => controlRuntime2.register(connection, webServer), "dsh-remote disabled control");
|
|
27789
27995
|
}
|
|
27790
27996
|
return;
|
|
@@ -27839,7 +28045,7 @@ async function activate(ctx, input2, tuiBinding) {
|
|
|
27839
28045
|
hostControl
|
|
27840
28046
|
);
|
|
27841
28047
|
}
|
|
27842
|
-
const controlRuntime = connection === void 0 ? void 0 : new PluginControlRuntime(config, defaultIdentityDirectory,
|
|
28048
|
+
const controlRuntime = connection === void 0 ? void 0 : new PluginControlRuntime(config, defaultIdentityDirectory, settingsBinding, clientRuntime, hostControl);
|
|
27843
28049
|
ctx.provide("dshRemote", runtime);
|
|
27844
28050
|
if (clientRuntime !== void 0) ctx.provide("dshRemoteClient", clientRuntime);
|
|
27845
28051
|
const tuiTarget = { runtime, config };
|
|
@@ -27874,6 +28080,52 @@ async function activate(ctx, input2, tuiBinding) {
|
|
|
27874
28080
|
};
|
|
27875
28081
|
}, "dsh-remote lifecycle");
|
|
27876
28082
|
}
|
|
28083
|
+
function readEntryConfig(entry) {
|
|
28084
|
+
if (entry === void 0) return {};
|
|
28085
|
+
return isEntryConfig(entry) ? entry.get() : entry;
|
|
28086
|
+
}
|
|
28087
|
+
function isEntryConfig(value) {
|
|
28088
|
+
return typeof value.get === "function";
|
|
28089
|
+
}
|
|
28090
|
+
function locateEntryId(ctx) {
|
|
28091
|
+
const loader = ctx.get("loader");
|
|
28092
|
+
const located = loader?.locate?.(ctx.fiber);
|
|
28093
|
+
if (located === void 0) return DEFAULT_ENTRY_ID;
|
|
28094
|
+
if (typeof loader?.entries === "function") {
|
|
28095
|
+
for (const entry of loader.entries()) {
|
|
28096
|
+
if (entry.id === located) return entry.options.id;
|
|
28097
|
+
}
|
|
28098
|
+
}
|
|
28099
|
+
return located.startsWith(INCLUDE_ENTRY_PREFIX) ? located.slice(INCLUDE_ENTRY_PREFIX.length) : located;
|
|
28100
|
+
}
|
|
28101
|
+
async function createSettingsBinding(ctx, settings, readConfig, entryId) {
|
|
28102
|
+
if (settings === void 0) return void 0;
|
|
28103
|
+
if (!isLegacySettingsProvider(settings)) {
|
|
28104
|
+
return {
|
|
28105
|
+
get: readConfig,
|
|
28106
|
+
replace: async (section) => {
|
|
28107
|
+
await settings.replace(entryId, section);
|
|
28108
|
+
}
|
|
28109
|
+
};
|
|
28110
|
+
}
|
|
28111
|
+
const scope = settings.register(pluginSettingsNamespace, Config, {
|
|
28112
|
+
base: readConfig(),
|
|
28113
|
+
applies: "restart",
|
|
28114
|
+
validate: (value) => {
|
|
28115
|
+
resolveConfig(value);
|
|
28116
|
+
}
|
|
28117
|
+
});
|
|
28118
|
+
reportSettingsMigration(ctx, await migrateLegacySettings(settings, scope));
|
|
28119
|
+
return {
|
|
28120
|
+
get: () => scope.get(),
|
|
28121
|
+
replace: async (section) => {
|
|
28122
|
+
await scope.replace(section);
|
|
28123
|
+
}
|
|
28124
|
+
};
|
|
28125
|
+
}
|
|
28126
|
+
function isLegacySettingsProvider(value) {
|
|
28127
|
+
return typeof value === "object" && value !== null && typeof value.register === "function";
|
|
28128
|
+
}
|
|
27877
28129
|
function reportSettingsMigration(ctx, migration) {
|
|
27878
28130
|
if (migration === "migrated") ctx.logger.info("migrated legacy Remote settings namespace");
|
|
27879
28131
|
if (migration === "failed") ctx.logger.warn("failed to migrate legacy Remote settings namespace");
|
|
@@ -27902,6 +28154,9 @@ async function migrateLegacySettings(settings, currentScope) {
|
|
|
27902
28154
|
return "failed";
|
|
27903
28155
|
}
|
|
27904
28156
|
}
|
|
28157
|
+
function isPlainRecord2(value) {
|
|
28158
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28159
|
+
}
|
|
27905
28160
|
async function disableLegacyLoaderEntries(ctx, logger) {
|
|
27906
28161
|
const loader = ctx.get("loader");
|
|
27907
28162
|
if (!isLoaderLike(loader)) return;
|
|
@@ -27925,9 +28180,6 @@ async function disableLegacyLoaderEntries(ctx, logger) {
|
|
|
27925
28180
|
function isLoaderLike(value) {
|
|
27926
28181
|
return typeof value === "object" && value !== null && typeof value.entries === "function" && typeof value.update === "function";
|
|
27927
28182
|
}
|
|
27928
|
-
function isPlainRecord2(value) {
|
|
27929
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27930
|
-
}
|
|
27931
28183
|
export {
|
|
27932
28184
|
AcpGateway,
|
|
27933
28185
|
ApiProxySwitch,
|