@codexhost/cli-linux-x64 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/app/codexhost-distribution.json +1 -1
- package/app/desktop-controller.mjs +107 -89
- package/app/host-runtime.mjs +353 -229
- package/app/renderer-extension.js +198 -14
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
package/app/host-runtime.mjs
CHANGED
|
@@ -773,10 +773,10 @@ function mergeDefs(...defs) {
|
|
|
773
773
|
function cloneDef(schema) {
|
|
774
774
|
return mergeDefs(schema._zod.def);
|
|
775
775
|
}
|
|
776
|
-
function getElementAtPath(obj,
|
|
777
|
-
if (!
|
|
776
|
+
function getElementAtPath(obj, path19) {
|
|
777
|
+
if (!path19)
|
|
778
778
|
return obj;
|
|
779
|
-
return
|
|
779
|
+
return path19.reduce((acc, key) => acc?.[key], obj);
|
|
780
780
|
}
|
|
781
781
|
function promiseAllObject(promisesObj) {
|
|
782
782
|
const keys = Object.keys(promisesObj);
|
|
@@ -1185,11 +1185,11 @@ function explicitlyAborted(x2, startIndex = 0) {
|
|
|
1185
1185
|
}
|
|
1186
1186
|
return false;
|
|
1187
1187
|
}
|
|
1188
|
-
function prefixIssues(
|
|
1188
|
+
function prefixIssues(path19, issues) {
|
|
1189
1189
|
return issues.map((iss) => {
|
|
1190
1190
|
var _a4;
|
|
1191
1191
|
(_a4 = iss).path ?? (_a4.path = []);
|
|
1192
|
-
iss.path.unshift(
|
|
1192
|
+
iss.path.unshift(path19);
|
|
1193
1193
|
return iss;
|
|
1194
1194
|
});
|
|
1195
1195
|
}
|
|
@@ -1336,16 +1336,16 @@ function flattenError(error52, mapper = (issue2) => issue2.message) {
|
|
|
1336
1336
|
}
|
|
1337
1337
|
function formatError(error52, mapper = (issue2) => issue2.message) {
|
|
1338
1338
|
const fieldErrors = { _errors: [] };
|
|
1339
|
-
const processError = (error53,
|
|
1339
|
+
const processError = (error53, path19 = []) => {
|
|
1340
1340
|
for (const issue2 of error53.issues) {
|
|
1341
1341
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1342
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1342
|
+
issue2.errors.map((issues) => processError({ issues }, [...path19, ...issue2.path]));
|
|
1343
1343
|
} else if (issue2.code === "invalid_key") {
|
|
1344
|
-
processError({ issues: issue2.issues }, [...
|
|
1344
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
1345
1345
|
} else if (issue2.code === "invalid_element") {
|
|
1346
|
-
processError({ issues: issue2.issues }, [...
|
|
1346
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
1347
1347
|
} else {
|
|
1348
|
-
const fullpath = [...
|
|
1348
|
+
const fullpath = [...path19, ...issue2.path];
|
|
1349
1349
|
if (fullpath.length === 0) {
|
|
1350
1350
|
fieldErrors._errors.push(mapper(issue2));
|
|
1351
1351
|
} else {
|
|
@@ -1372,17 +1372,17 @@ function formatError(error52, mapper = (issue2) => issue2.message) {
|
|
|
1372
1372
|
}
|
|
1373
1373
|
function treeifyError(error52, mapper = (issue2) => issue2.message) {
|
|
1374
1374
|
const result = { errors: [] };
|
|
1375
|
-
const processError = (error53,
|
|
1375
|
+
const processError = (error53, path19 = []) => {
|
|
1376
1376
|
var _a4, _b2;
|
|
1377
1377
|
for (const issue2 of error53.issues) {
|
|
1378
1378
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1379
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1379
|
+
issue2.errors.map((issues) => processError({ issues }, [...path19, ...issue2.path]));
|
|
1380
1380
|
} else if (issue2.code === "invalid_key") {
|
|
1381
|
-
processError({ issues: issue2.issues }, [...
|
|
1381
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
1382
1382
|
} else if (issue2.code === "invalid_element") {
|
|
1383
|
-
processError({ issues: issue2.issues }, [...
|
|
1383
|
+
processError({ issues: issue2.issues }, [...path19, ...issue2.path]);
|
|
1384
1384
|
} else {
|
|
1385
|
-
const fullpath = [...
|
|
1385
|
+
const fullpath = [...path19, ...issue2.path];
|
|
1386
1386
|
if (fullpath.length === 0) {
|
|
1387
1387
|
result.errors.push(mapper(issue2));
|
|
1388
1388
|
continue;
|
|
@@ -1414,8 +1414,8 @@ function treeifyError(error52, mapper = (issue2) => issue2.message) {
|
|
|
1414
1414
|
}
|
|
1415
1415
|
function toDotPath(_path) {
|
|
1416
1416
|
const segs = [];
|
|
1417
|
-
const
|
|
1418
|
-
for (const seg of
|
|
1417
|
+
const path19 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1418
|
+
for (const seg of path19) {
|
|
1419
1419
|
if (typeof seg === "number")
|
|
1420
1420
|
segs.push(`[${seg}]`);
|
|
1421
1421
|
else if (typeof seg === "symbol")
|
|
@@ -14107,13 +14107,13 @@ function resolveRef(ref, ctx) {
|
|
|
14107
14107
|
if (!ref.startsWith("#")) {
|
|
14108
14108
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14109
14109
|
}
|
|
14110
|
-
const
|
|
14111
|
-
if (
|
|
14110
|
+
const path19 = ref.slice(1).split("/").filter(Boolean);
|
|
14111
|
+
if (path19.length === 0) {
|
|
14112
14112
|
return ctx.rootSchema;
|
|
14113
14113
|
}
|
|
14114
14114
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14115
|
-
if (
|
|
14116
|
-
const key =
|
|
14115
|
+
if (path19[0] === defsKey) {
|
|
14116
|
+
const key = path19[1];
|
|
14117
14117
|
if (!key || !ctx.defs[key]) {
|
|
14118
14118
|
throw new Error(`Reference not found: ${ref}`);
|
|
14119
14119
|
}
|
|
@@ -44838,16 +44838,16 @@ var AbstractApiClient = class {
|
|
|
44838
44838
|
* Shared POST leg of both C→S carriers (callUnary/respond): JSON body,
|
|
44839
44839
|
* optional default timeout merged with the caller's external signal, non-2xx → transport throw.
|
|
44840
44840
|
*/
|
|
44841
|
-
async postJson(
|
|
44841
|
+
async postJson(path19, body, signal, timeoutPolicy = "default") {
|
|
44842
44842
|
const requestSignal = timeoutPolicy === "default" ? signal === void 0 ? AbortSignal.timeout(this.timeoutMs) : AbortSignal.any([AbortSignal.timeout(this.timeoutMs), signal]) : signal;
|
|
44843
|
-
const response = await this.doFetch(new URL(
|
|
44843
|
+
const response = await this.doFetch(new URL(path19, this.resolveBase()), {
|
|
44844
44844
|
method: "POST",
|
|
44845
44845
|
headers: { "content-type": "application/json" },
|
|
44846
44846
|
body: JSON.stringify(body),
|
|
44847
44847
|
...requestSignal === void 0 ? {} : { signal: requestSignal }
|
|
44848
44848
|
});
|
|
44849
44849
|
if (!response.ok)
|
|
44850
|
-
throw new Error(`transport failure for ${
|
|
44850
|
+
throw new Error(`transport failure for ${path19}: HTTP ${response.status}`);
|
|
44851
44851
|
return response;
|
|
44852
44852
|
}
|
|
44853
44853
|
/**
|
|
@@ -44883,10 +44883,10 @@ var AbstractApiClient = class {
|
|
|
44883
44883
|
* either parse level is reported and skipped (one corrupt frame must not kill the stream; the
|
|
44884
44884
|
* client's gap detection covers whatever the frame carried).
|
|
44885
44885
|
*/
|
|
44886
|
-
async *readSse(
|
|
44887
|
-
const response = await this.doFetch(new URL(
|
|
44886
|
+
async *readSse(path19, signal, frameSchema, onOpen) {
|
|
44887
|
+
const response = await this.doFetch(new URL(path19, this.resolveBase()), { signal });
|
|
44888
44888
|
if (!response.ok || response.body === null)
|
|
44889
|
-
throw new Error(`transport failure for ${
|
|
44889
|
+
throw new Error(`transport failure for ${path19}: HTTP ${response.status}`);
|
|
44890
44890
|
onOpen?.();
|
|
44891
44891
|
const reader = response.body.getReader();
|
|
44892
44892
|
const decoder2 = new TextDecoder();
|
|
@@ -44910,7 +44910,7 @@ var AbstractApiClient = class {
|
|
|
44910
44910
|
full = serverRequestSchema.parse(JSON.parse(data));
|
|
44911
44911
|
frame = frameSchema.parse(full.payload);
|
|
44912
44912
|
} catch (error52) {
|
|
44913
|
-
console.error(`[apiproxy] dropping malformed SSE frame on ${
|
|
44913
|
+
console.error(`[apiproxy] dropping malformed SSE frame on ${path19}:`, error52);
|
|
44914
44914
|
continue;
|
|
44915
44915
|
}
|
|
44916
44916
|
this.onEnvelope(full);
|
|
@@ -45148,13 +45148,13 @@ function resolveExecutable(command, environment) {
|
|
|
45148
45148
|
function resolveDeepSeekCommand(configured, environment) {
|
|
45149
45149
|
if (configured) {
|
|
45150
45150
|
const command = resolveExecutable(configured, environment);
|
|
45151
|
-
return command ? { command, arguments: [] } : null;
|
|
45151
|
+
return command ? { command, arguments: [], kind: "configured" } : null;
|
|
45152
45152
|
}
|
|
45153
45153
|
const dsh = resolveExecutable("dsh", environment);
|
|
45154
45154
|
if (dsh)
|
|
45155
|
-
return { command: dsh, arguments: [] };
|
|
45155
|
+
return { command: dsh, arguments: [], kind: "dsh" };
|
|
45156
45156
|
const npx = resolveExecutable(process.platform === "win32" ? "npx.cmd" : "npx", environment);
|
|
45157
|
-
return npx ? { command: npx, arguments: ["--no-install", "@deepseek-ai/dsh"] } : null;
|
|
45157
|
+
return npx ? { command: npx, arguments: ["--no-install", "@deepseek-ai/dsh"], kind: "npx" } : null;
|
|
45158
45158
|
}
|
|
45159
45159
|
function unwrap(response, operation) {
|
|
45160
45160
|
if (response.result.ok)
|
|
@@ -45247,6 +45247,9 @@ var DeepSeekHostConnection = class {
|
|
|
45247
45247
|
if (processError)
|
|
45248
45248
|
throw processError;
|
|
45249
45249
|
if (child.exitCode !== null || child.signalCode !== null) {
|
|
45250
|
+
if (invocation.kind === "npx") {
|
|
45251
|
+
throw new DeepSeekHarnessTransportError("notInstalled", "DeepSeek Harness package is not installed");
|
|
45252
|
+
}
|
|
45250
45253
|
throw new DeepSeekHarnessTransportError("processExited", "DeepSeek Harness Web exited during startup");
|
|
45251
45254
|
}
|
|
45252
45255
|
try {
|
|
@@ -45485,16 +45488,16 @@ var Diff = class {
|
|
|
45485
45488
|
}
|
|
45486
45489
|
}
|
|
45487
45490
|
}
|
|
45488
|
-
addToPath(
|
|
45489
|
-
const last =
|
|
45491
|
+
addToPath(path19, added, removed, oldPosInc, options) {
|
|
45492
|
+
const last = path19.lastComponent;
|
|
45490
45493
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
45491
45494
|
return {
|
|
45492
|
-
oldPos:
|
|
45495
|
+
oldPos: path19.oldPos + oldPosInc,
|
|
45493
45496
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
45494
45497
|
};
|
|
45495
45498
|
} else {
|
|
45496
45499
|
return {
|
|
45497
|
-
oldPos:
|
|
45500
|
+
oldPos: path19.oldPos + oldPosInc,
|
|
45498
45501
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
45499
45502
|
};
|
|
45500
45503
|
}
|
|
@@ -47246,7 +47249,7 @@ var packageMetadata3 = {
|
|
|
47246
47249
|
|
|
47247
47250
|
// packages/adapters/grok/dist/grok-adapter.js
|
|
47248
47251
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
47249
|
-
import
|
|
47252
|
+
import path11 from "node:path";
|
|
47250
47253
|
|
|
47251
47254
|
// packages/adapters/grok/dist/acp-transport.js
|
|
47252
47255
|
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
@@ -51877,6 +51880,81 @@ var GrokAcpTransport = class {
|
|
|
51877
51880
|
}
|
|
51878
51881
|
};
|
|
51879
51882
|
|
|
51883
|
+
// packages/adapters/grok/dist/grok-file-change.js
|
|
51884
|
+
import { Buffer as Buffer4 } from "node:buffer";
|
|
51885
|
+
import path9 from "node:path";
|
|
51886
|
+
var DEFAULT_GROK_FILE_CHANGE_TEXT_LIMIT = 4 * 1024 * 1024;
|
|
51887
|
+
var MAX_GROK_FILE_CHANGES_PER_TOOL = 32;
|
|
51888
|
+
function isRecord10(value) {
|
|
51889
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
51890
|
+
}
|
|
51891
|
+
function validAbsolutePath(value) {
|
|
51892
|
+
return typeof value === "string" && path9.isAbsolute(value) && value.trim().length > 0 && !value.includes("\0") && !value.includes("\n") && !value.includes("\r");
|
|
51893
|
+
}
|
|
51894
|
+
function displayPath2(nativePath, cwd) {
|
|
51895
|
+
const resolvedCwd = path9.resolve(cwd);
|
|
51896
|
+
const resolvedPath = path9.resolve(nativePath);
|
|
51897
|
+
const relative = path9.relative(resolvedCwd, resolvedPath);
|
|
51898
|
+
const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path9.sep}`);
|
|
51899
|
+
const selected = inside ? relative : resolvedPath;
|
|
51900
|
+
const normalized = selected.replaceAll("\\", "/");
|
|
51901
|
+
if (normalized.length === 0 || normalized === ".")
|
|
51902
|
+
return null;
|
|
51903
|
+
return { path: normalized, absolute: !inside };
|
|
51904
|
+
}
|
|
51905
|
+
function projectDiff(value, cwd, remainingTextBytes) {
|
|
51906
|
+
if (!validAbsolutePath(value.path) || typeof value.oldText !== "string" && value.oldText !== null || typeof value.newText !== "string") {
|
|
51907
|
+
return null;
|
|
51908
|
+
}
|
|
51909
|
+
const oldText = value.oldText;
|
|
51910
|
+
const newText = value.newText;
|
|
51911
|
+
if (typeof oldText === "string" && oldText === newText || oldText === null && newText === "") {
|
|
51912
|
+
return null;
|
|
51913
|
+
}
|
|
51914
|
+
const textBytes = Buffer4.byteLength(oldText ?? "", "utf8") + Buffer4.byteLength(newText, "utf8");
|
|
51915
|
+
if (textBytes > remainingTextBytes)
|
|
51916
|
+
return null;
|
|
51917
|
+
const displayed = displayPath2(value.path, cwd);
|
|
51918
|
+
if (!displayed)
|
|
51919
|
+
return null;
|
|
51920
|
+
const kind = oldText === null ? "add" : "update";
|
|
51921
|
+
const oldHeader = kind === "add" ? "/dev/null" : displayed.absolute ? displayed.path : `a/${displayed.path}`;
|
|
51922
|
+
const newHeader = displayed.absolute ? displayed.path : `b/${displayed.path}`;
|
|
51923
|
+
return {
|
|
51924
|
+
change: {
|
|
51925
|
+
path: displayed.path,
|
|
51926
|
+
kind,
|
|
51927
|
+
unifiedDiff: createTwoFilesPatch(oldHeader, newHeader, oldText ?? "", newText, "", "", {
|
|
51928
|
+
context: 3
|
|
51929
|
+
})
|
|
51930
|
+
},
|
|
51931
|
+
textBytes
|
|
51932
|
+
};
|
|
51933
|
+
}
|
|
51934
|
+
function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHANGE_TEXT_LIMIT) {
|
|
51935
|
+
if (!Number.isSafeInteger(textLimit) || textLimit <= 0 || !Array.isArray(content))
|
|
51936
|
+
return null;
|
|
51937
|
+
const candidates2 = [];
|
|
51938
|
+
for (const entry of content) {
|
|
51939
|
+
if (isRecord10(entry) && entry.type === "diff")
|
|
51940
|
+
candidates2.push(entry);
|
|
51941
|
+
}
|
|
51942
|
+
if (candidates2.length === 0 || candidates2.length > MAX_GROK_FILE_CHANGES_PER_TOOL)
|
|
51943
|
+
return null;
|
|
51944
|
+
const changes = [];
|
|
51945
|
+
const paths = /* @__PURE__ */ new Set();
|
|
51946
|
+
let textBytes = 0;
|
|
51947
|
+
for (const candidate of candidates2) {
|
|
51948
|
+
const projected = projectDiff(candidate, cwd, textLimit - textBytes);
|
|
51949
|
+
if (!projected || paths.has(projected.change.path))
|
|
51950
|
+
return null;
|
|
51951
|
+
textBytes += projected.textBytes;
|
|
51952
|
+
paths.add(projected.change.path);
|
|
51953
|
+
changes.push(projected.change);
|
|
51954
|
+
}
|
|
51955
|
+
return changes;
|
|
51956
|
+
}
|
|
51957
|
+
|
|
51880
51958
|
// packages/adapters/grok/dist/grok-history.js
|
|
51881
51959
|
function jsonValue(value) {
|
|
51882
51960
|
try {
|
|
@@ -51910,7 +51988,7 @@ function isSyntheticGrokUserText(text) {
|
|
|
51910
51988
|
function isSyntheticGrokTurnKey(nativeTurnKey3) {
|
|
51911
51989
|
return taskCompletedTurnKeyPattern.test(nativeTurnKey3);
|
|
51912
51990
|
}
|
|
51913
|
-
function mapGrokReplay(replay, harnessId, sessionId, knownTurnRefs = []) {
|
|
51991
|
+
function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = []) {
|
|
51914
51992
|
const knownByNativeKey = new Map(knownTurnRefs.filter((ref) => ref.harnessId === harnessId && ref.nativeSessionId === sessionId).map((ref) => [ref.nativeTurnKey, ref]));
|
|
51915
51993
|
const turns = [];
|
|
51916
51994
|
let input = "";
|
|
@@ -51939,6 +52017,32 @@ function mapGrokReplay(replay, harnessId, sessionId, knownTurnRefs = []) {
|
|
|
51939
52017
|
}
|
|
51940
52018
|
tools.clear();
|
|
51941
52019
|
};
|
|
52020
|
+
const completeTool = (callId, status, content) => {
|
|
52021
|
+
const tool = tools.get(callId);
|
|
52022
|
+
if (!tool)
|
|
52023
|
+
return;
|
|
52024
|
+
tools.delete(callId);
|
|
52025
|
+
const outcome = status === "failed" ? {
|
|
52026
|
+
status: "failed",
|
|
52027
|
+
error: {
|
|
52028
|
+
code: "nativeFailure",
|
|
52029
|
+
message: `Grok Tool '${tool.toolName}' failed`,
|
|
52030
|
+
retryable: false
|
|
52031
|
+
}
|
|
52032
|
+
} : { status: "succeeded" };
|
|
52033
|
+
items.push({ item: tool, outcome });
|
|
52034
|
+
if (status !== "completed")
|
|
52035
|
+
return;
|
|
52036
|
+
const changes = projectGrokFileChanges(content, cwd);
|
|
52037
|
+
if (!changes)
|
|
52038
|
+
return;
|
|
52039
|
+
const fileItem = {
|
|
52040
|
+
type: "fileChange",
|
|
52041
|
+
itemId: stableId("file-change", turnIndex, ++messageIndex),
|
|
52042
|
+
changes
|
|
52043
|
+
};
|
|
52044
|
+
items.push({ item: fileItem, outcome: { status: "succeeded" } });
|
|
52045
|
+
};
|
|
51942
52046
|
const completeTurn = (outcome, terminalKey) => {
|
|
51943
52047
|
if (input.length === 0)
|
|
51944
52048
|
return;
|
|
@@ -52021,6 +52125,9 @@ function mapGrokReplay(replay, harnessId, sessionId, knownTurnRefs = []) {
|
|
|
52021
52125
|
namespace: "grok",
|
|
52022
52126
|
arguments: jsonValue(event.rawInput)
|
|
52023
52127
|
});
|
|
52128
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
52129
|
+
completeTool(event.callId, event.status, event.content);
|
|
52130
|
+
}
|
|
52024
52131
|
} else if (event.type === "tool.update") {
|
|
52025
52132
|
const tool = tools.get(event.callId);
|
|
52026
52133
|
if (tool && event.rawOutput !== void 0) {
|
|
@@ -52029,6 +52136,9 @@ function mapGrokReplay(replay, harnessId, sessionId, knownTurnRefs = []) {
|
|
|
52029
52136
|
output: { content: [{ type: "text", text: String(event.rawOutput) }] }
|
|
52030
52137
|
});
|
|
52031
52138
|
}
|
|
52139
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
52140
|
+
completeTool(event.callId, event.status, event.content);
|
|
52141
|
+
}
|
|
52032
52142
|
}
|
|
52033
52143
|
}
|
|
52034
52144
|
completeTurn({ status: "unknown", reason: "Grok Native history has no terminal signal" });
|
|
@@ -52036,7 +52146,7 @@ function mapGrokReplay(replay, harnessId, sessionId, knownTurnRefs = []) {
|
|
|
52036
52146
|
}
|
|
52037
52147
|
|
|
52038
52148
|
// packages/adapters/grok/dist/grok-models.js
|
|
52039
|
-
function
|
|
52149
|
+
function isRecord11(value) {
|
|
52040
52150
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52041
52151
|
}
|
|
52042
52152
|
function nonBlank(value) {
|
|
@@ -52048,7 +52158,7 @@ function thinkingOptions(value) {
|
|
|
52048
52158
|
const seen = /* @__PURE__ */ new Set();
|
|
52049
52159
|
const options = [];
|
|
52050
52160
|
for (const candidate of value) {
|
|
52051
|
-
if (!
|
|
52161
|
+
if (!isRecord11(candidate) || !nonBlank(candidate.label))
|
|
52052
52162
|
continue;
|
|
52053
52163
|
const id2 = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
52054
52164
|
if (!id2.success || seen.has(id2.data))
|
|
@@ -52059,7 +52169,7 @@ function thinkingOptions(value) {
|
|
|
52059
52169
|
return options;
|
|
52060
52170
|
}
|
|
52061
52171
|
function parseGrokModelState(value) {
|
|
52062
|
-
if (!
|
|
52172
|
+
if (!isRecord11(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
52063
52173
|
return null;
|
|
52064
52174
|
}
|
|
52065
52175
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -52070,12 +52180,12 @@ function parseGrokModelState(value) {
|
|
|
52070
52180
|
const models = [];
|
|
52071
52181
|
let currentThinkingOptionId;
|
|
52072
52182
|
for (const candidate of value.availableModels) {
|
|
52073
|
-
if (!
|
|
52183
|
+
if (!isRecord11(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
52074
52184
|
continue;
|
|
52075
52185
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
52076
52186
|
if (!ref.success)
|
|
52077
52187
|
continue;
|
|
52078
|
-
const metadata =
|
|
52188
|
+
const metadata = isRecord11(candidate._meta) ? candidate._meta : {};
|
|
52079
52189
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
52080
52190
|
if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
|
|
52081
52191
|
contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
|
|
@@ -52110,10 +52220,10 @@ function parseGrokModelState(value) {
|
|
|
52110
52220
|
};
|
|
52111
52221
|
}
|
|
52112
52222
|
function modelStateFromInitialize(response) {
|
|
52113
|
-
return parseGrokModelState(
|
|
52223
|
+
return parseGrokModelState(isRecord11(response._meta) ? response._meta.modelState : void 0);
|
|
52114
52224
|
}
|
|
52115
52225
|
function modelStateFromSessionResponse(response) {
|
|
52116
|
-
return parseGrokModelState(
|
|
52226
|
+
return parseGrokModelState(isRecord11(response) ? response.models : void 0);
|
|
52117
52227
|
}
|
|
52118
52228
|
function stateForGrokModel(modelState, nativeState, model = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId) {
|
|
52119
52229
|
const selectedModel = model;
|
|
@@ -52133,10 +52243,10 @@ function stateForGrokModel(modelState, nativeState, model = modelState.currentMo
|
|
|
52133
52243
|
// packages/adapters/grok/dist/grok-credits.js
|
|
52134
52244
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
52135
52245
|
import os4 from "node:os";
|
|
52136
|
-
import
|
|
52246
|
+
import path10 from "node:path";
|
|
52137
52247
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
52138
52248
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
52139
|
-
function
|
|
52249
|
+
function isRecord12(value) {
|
|
52140
52250
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52141
52251
|
}
|
|
52142
52252
|
function finitePercent(value) {
|
|
@@ -52150,7 +52260,7 @@ function nonNegativeNumber(value) {
|
|
|
52150
52260
|
return value;
|
|
52151
52261
|
}
|
|
52152
52262
|
function grokHome(environment) {
|
|
52153
|
-
return environment.GROK_HOME ??
|
|
52263
|
+
return environment.GROK_HOME ?? path10.join(environment.HOME ?? environment.USERPROFILE ?? os4.homedir(), ".grok");
|
|
52154
52264
|
}
|
|
52155
52265
|
function periodTypeFrom(value) {
|
|
52156
52266
|
if (typeof value !== "string")
|
|
@@ -52166,7 +52276,7 @@ function productUsageFrom(value) {
|
|
|
52166
52276
|
if (!Array.isArray(value))
|
|
52167
52277
|
return void 0;
|
|
52168
52278
|
const products = value.flatMap((entry) => {
|
|
52169
|
-
if (!
|
|
52279
|
+
if (!isRecord12(entry) || typeof entry.product !== "string")
|
|
52170
52280
|
return [];
|
|
52171
52281
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
52172
52282
|
return usagePercent === void 0 ? [] : [{ product: entry.product, usagePercent }];
|
|
@@ -52174,13 +52284,13 @@ function productUsageFrom(value) {
|
|
|
52174
52284
|
return products.length > 0 ? products : void 0;
|
|
52175
52285
|
}
|
|
52176
52286
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
52177
|
-
if (!
|
|
52287
|
+
if (!isRecord12(value) || !isRecord12(value.config))
|
|
52178
52288
|
return null;
|
|
52179
52289
|
const config2 = value.config;
|
|
52180
|
-
const period =
|
|
52290
|
+
const period = isRecord12(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
52181
52291
|
const resetsAt = (typeof period?.end === "string" && period.end.length > 0 ? period.end : void 0) ?? (typeof config2.billingPeriodEnd === "string" && config2.billingPeriodEnd.length > 0 ? config2.billingPeriodEnd : void 0);
|
|
52182
|
-
const onDemandCap =
|
|
52183
|
-
const onDemandUsed =
|
|
52292
|
+
const onDemandCap = isRecord12(config2.onDemandCap) ? nonNegativeNumber(config2.onDemandCap.val) : void 0;
|
|
52293
|
+
const onDemandUsed = isRecord12(config2.onDemandUsed) ? nonNegativeNumber(config2.onDemandUsed.val) : void 0;
|
|
52184
52294
|
const usedPercent = finitePercent(config2.creditUsagePercent) ?? (onDemandCap !== void 0 && onDemandCap > 0 && onDemandUsed !== void 0 ? Math.min(100, Math.max(0, onDemandUsed / onDemandCap * 100)) : resetsAt ? 0 : void 0);
|
|
52185
52295
|
if (usedPercent === void 0)
|
|
52186
52296
|
return null;
|
|
@@ -52194,11 +52304,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
52194
52304
|
};
|
|
52195
52305
|
}
|
|
52196
52306
|
function selectAccessToken(auth, now) {
|
|
52197
|
-
if (!
|
|
52307
|
+
if (!isRecord12(auth))
|
|
52198
52308
|
return null;
|
|
52199
|
-
const entries = Object.entries(auth).filter(([, value]) =>
|
|
52309
|
+
const entries = Object.entries(auth).filter(([, value]) => isRecord12(value) && typeof value.key === "string" && value.key.length > 0).sort(([left], [right]) => Number(right.startsWith("https://auth.x.ai")) - Number(left.startsWith("https://auth.x.ai")));
|
|
52200
52310
|
for (const [, value] of entries) {
|
|
52201
|
-
if (!
|
|
52311
|
+
if (!isRecord12(value) || typeof value.key !== "string")
|
|
52202
52312
|
continue;
|
|
52203
52313
|
if (typeof value.expires_at === "string") {
|
|
52204
52314
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -52213,7 +52323,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
52213
52323
|
try {
|
|
52214
52324
|
const environment = input.environment ?? process.env;
|
|
52215
52325
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
52216
|
-
const authPath =
|
|
52326
|
+
const authPath = path10.join(grokHome(environment), "auth.json");
|
|
52217
52327
|
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile2(authPath, "utf8");
|
|
52218
52328
|
const token = selectAccessToken(JSON.parse(raw), now);
|
|
52219
52329
|
if (!token)
|
|
@@ -52238,7 +52348,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
52238
52348
|
|
|
52239
52349
|
// packages/adapters/grok/dist/grok-usage.js
|
|
52240
52350
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
52241
|
-
function
|
|
52351
|
+
function isRecord13(value) {
|
|
52242
52352
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52243
52353
|
}
|
|
52244
52354
|
function optionalToken(value) {
|
|
@@ -52255,7 +52365,7 @@ function combineUsage(base, next) {
|
|
|
52255
52365
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
52256
52366
|
}
|
|
52257
52367
|
function usageFromNative(value) {
|
|
52258
|
-
if (!
|
|
52368
|
+
if (!isRecord13(value))
|
|
52259
52369
|
return null;
|
|
52260
52370
|
const inputTokens = optionalToken(value.inputTokens);
|
|
52261
52371
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -52282,7 +52392,7 @@ function usageFromPrompt(response) {
|
|
|
52282
52392
|
return response.usage ? usageFromNative(response.usage) : null;
|
|
52283
52393
|
}
|
|
52284
52394
|
function usageFromSignals(value) {
|
|
52285
|
-
if (!
|
|
52395
|
+
if (!isRecord13(value))
|
|
52286
52396
|
return null;
|
|
52287
52397
|
try {
|
|
52288
52398
|
return parseHostUsage({
|
|
@@ -52302,7 +52412,7 @@ var summedUsageFields = [
|
|
|
52302
52412
|
"totalTokens"
|
|
52303
52413
|
];
|
|
52304
52414
|
function nativeCostTicks(value) {
|
|
52305
|
-
if (!
|
|
52415
|
+
if (!isRecord13(value))
|
|
52306
52416
|
return void 0;
|
|
52307
52417
|
const ticks = value.costUsdTicks;
|
|
52308
52418
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -52366,7 +52476,7 @@ function sessionUsageFromHistory(events) {
|
|
|
52366
52476
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
52367
52477
|
try {
|
|
52368
52478
|
if (update?.sessionUpdate === "usage_update") {
|
|
52369
|
-
const cost =
|
|
52479
|
+
const cost = isRecord13(update.cost) ? update.cost : null;
|
|
52370
52480
|
return parseHostUsage({
|
|
52371
52481
|
contextUsedTokens: update.used,
|
|
52372
52482
|
contextWindowTokens: update.size,
|
|
@@ -52400,7 +52510,7 @@ function capabilitiesForModels(modelState) {
|
|
|
52400
52510
|
}
|
|
52401
52511
|
var DEFAULT_CLOSE_TIMEOUT_MS3 = 2e3;
|
|
52402
52512
|
var DEFAULT_TOOL_OUTPUT_LIMIT3 = 64e3;
|
|
52403
|
-
function
|
|
52513
|
+
function isRecord14(value) {
|
|
52404
52514
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52405
52515
|
}
|
|
52406
52516
|
function invalidState3(message3) {
|
|
@@ -52432,10 +52542,10 @@ function jsonValue2(value) {
|
|
|
52432
52542
|
return parsed.success ? parsed.data : {};
|
|
52433
52543
|
}
|
|
52434
52544
|
function contentText2(content) {
|
|
52435
|
-
if (!content)
|
|
52545
|
+
if (!Array.isArray(content))
|
|
52436
52546
|
return "";
|
|
52437
52547
|
return content.flatMap((entry) => {
|
|
52438
|
-
if (!
|
|
52548
|
+
if (!isRecord14(entry) || entry.type !== "content" || !isRecord14(entry.content))
|
|
52439
52549
|
return [];
|
|
52440
52550
|
return entry.content.type === "text" && typeof entry.content.text === "string" ? [entry.content.text] : [];
|
|
52441
52551
|
}).join("\n");
|
|
@@ -52515,7 +52625,7 @@ var GrokHarnessSession = class {
|
|
|
52515
52625
|
this.#state = stateForGrokModel(modelState, { nativeRef: nativeRef(opened.sessionId) });
|
|
52516
52626
|
this.initialState = this.#state;
|
|
52517
52627
|
this.#snapshot = {
|
|
52518
|
-
...mapGrokReplay(options.history, this.harnessId, opened.sessionId, options.knownTurnRefs),
|
|
52628
|
+
...mapGrokReplay(options.history, this.harnessId, opened.sessionId, cwd, options.knownTurnRefs),
|
|
52519
52629
|
state: this.#state
|
|
52520
52630
|
};
|
|
52521
52631
|
this.outputs = this.#channel.outputs;
|
|
@@ -52625,7 +52735,7 @@ var GrokHarnessSession = class {
|
|
|
52625
52735
|
async #refreshSnapshot() {
|
|
52626
52736
|
const history = await this.#transport.getHistory();
|
|
52627
52737
|
const knownTurnRefs = this.#snapshot.turns.map((turn) => turn.nativeTurnRef);
|
|
52628
|
-
const refreshed = mapGrokReplay(history, this.harnessId, this.#transport.sessionId, knownTurnRefs);
|
|
52738
|
+
const refreshed = mapGrokReplay(history, this.harnessId, this.#transport.sessionId, this.#cwd, knownTurnRefs);
|
|
52629
52739
|
this.#snapshot.turns = refreshed.turns;
|
|
52630
52740
|
return history;
|
|
52631
52741
|
}
|
|
@@ -52834,8 +52944,9 @@ var GrokHarnessSession = class {
|
|
|
52834
52944
|
};
|
|
52835
52945
|
active.tools.set(event.callId, { item, ...event.status ? { status: event.status } : {} });
|
|
52836
52946
|
this.#event({ type: "item.started", turnId: active.command.turnId, item });
|
|
52837
|
-
if (event.status === "completed" || event.status === "failed")
|
|
52838
|
-
this.#completeTool(active, event.callId, event.status);
|
|
52947
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
52948
|
+
this.#completeTool(active, event.callId, event.status, event.content);
|
|
52949
|
+
}
|
|
52839
52950
|
}
|
|
52840
52951
|
#updateTool(active, event) {
|
|
52841
52952
|
const tool = active.tools.get(event.callId);
|
|
@@ -52853,10 +52964,11 @@ var GrokHarnessSession = class {
|
|
|
52853
52964
|
}
|
|
52854
52965
|
if (event.status)
|
|
52855
52966
|
tool.status = event.status;
|
|
52856
|
-
if (event.status === "completed" || event.status === "failed")
|
|
52857
|
-
this.#completeTool(active, event.callId, event.status);
|
|
52967
|
+
if (event.status === "completed" || event.status === "failed") {
|
|
52968
|
+
this.#completeTool(active, event.callId, event.status, event.content);
|
|
52969
|
+
}
|
|
52858
52970
|
}
|
|
52859
|
-
#completeTool(active, callId, status) {
|
|
52971
|
+
#completeTool(active, callId, status, content) {
|
|
52860
52972
|
const tool = active.tools.get(callId);
|
|
52861
52973
|
if (!tool)
|
|
52862
52974
|
return;
|
|
@@ -52870,6 +52982,18 @@ var GrokHarnessSession = class {
|
|
|
52870
52982
|
}
|
|
52871
52983
|
} : { status: "succeeded" };
|
|
52872
52984
|
this.#completeItem(active, tool.item, outcome);
|
|
52985
|
+
if (status !== "completed")
|
|
52986
|
+
return;
|
|
52987
|
+
const changes = projectGrokFileChanges(content, this.#cwd);
|
|
52988
|
+
if (!changes)
|
|
52989
|
+
return;
|
|
52990
|
+
const fileItem = {
|
|
52991
|
+
type: "fileChange",
|
|
52992
|
+
itemId: hostItemIdSchema.parse(this.#randomUUID()),
|
|
52993
|
+
changes
|
|
52994
|
+
};
|
|
52995
|
+
this.#event({ type: "item.started", turnId: active.command.turnId, item: fileItem });
|
|
52996
|
+
this.#completeItem(active, fileItem, { status: "succeeded" });
|
|
52873
52997
|
}
|
|
52874
52998
|
#completeAgent(active, outcome) {
|
|
52875
52999
|
const item = active.agent;
|
|
@@ -53043,7 +53167,7 @@ var GrokAdapter = class {
|
|
|
53043
53167
|
async inspect(input = {}) {
|
|
53044
53168
|
if (this.#closePromise)
|
|
53045
53169
|
return { status: "unavailable", error: invalidState3("Grok Adapter is closed") };
|
|
53046
|
-
const cwd =
|
|
53170
|
+
const cwd = path11.resolve(input.cwd ?? process.cwd());
|
|
53047
53171
|
if (!input.refresh) {
|
|
53048
53172
|
const cached2 = this.#inspectionCache.get(cwd);
|
|
53049
53173
|
if (cached2)
|
|
@@ -53102,7 +53226,7 @@ var GrokAdapter = class {
|
|
|
53102
53226
|
}
|
|
53103
53227
|
};
|
|
53104
53228
|
}
|
|
53105
|
-
const cwd =
|
|
53229
|
+
const cwd = path11.resolve(input.cwd);
|
|
53106
53230
|
const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
|
|
53107
53231
|
if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
|
|
53108
53232
|
return {
|
|
@@ -53290,7 +53414,7 @@ function normalizePiModelCatalog(nativeModels, effectiveModel, thinkingLevels, e
|
|
|
53290
53414
|
|
|
53291
53415
|
// packages/adapters/pi/dist/pi-history.js
|
|
53292
53416
|
var piHarnessId = harnessIdSchema.parse("pi");
|
|
53293
|
-
function
|
|
53417
|
+
function isRecord15(value) {
|
|
53294
53418
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53295
53419
|
}
|
|
53296
53420
|
function textContent(value) {
|
|
@@ -53298,12 +53422,12 @@ function textContent(value) {
|
|
|
53298
53422
|
return value;
|
|
53299
53423
|
if (!Array.isArray(value))
|
|
53300
53424
|
return "";
|
|
53301
|
-
return value.filter((part) =>
|
|
53425
|
+
return value.filter((part) => isRecord15(part) && part.type === "text" && typeof part.text === "string").map((part) => part.text).join("");
|
|
53302
53426
|
}
|
|
53303
53427
|
function thinkingContent(value) {
|
|
53304
53428
|
if (!Array.isArray(value))
|
|
53305
53429
|
return "";
|
|
53306
|
-
return value.filter((part) =>
|
|
53430
|
+
return value.filter((part) => isRecord15(part) && part.type === "thinking" && typeof part.thinking === "string").map((part) => part.thinking).join("");
|
|
53307
53431
|
}
|
|
53308
53432
|
function validatedEntry(value) {
|
|
53309
53433
|
if (typeof value.id !== "string" || value.id.length === 0 || value.parentId !== null && typeof value.parentId !== "string" || typeof value.type !== "string") {
|
|
@@ -53334,7 +53458,7 @@ function activePiEntries(history) {
|
|
|
53334
53458
|
return reversed.reverse();
|
|
53335
53459
|
}
|
|
53336
53460
|
function message(entry) {
|
|
53337
|
-
return entry.type === "message" &&
|
|
53461
|
+
return entry.type === "message" && isRecord15(entry.message) ? entry.message : null;
|
|
53338
53462
|
}
|
|
53339
53463
|
function messageRole(entry) {
|
|
53340
53464
|
const value = message(entry)?.role;
|
|
@@ -53396,7 +53520,7 @@ function snapshotItems(entries, outcome) {
|
|
|
53396
53520
|
let projectedText = false;
|
|
53397
53521
|
let projectedReasoning = false;
|
|
53398
53522
|
for (const [ordinal, part] of content.entries()) {
|
|
53399
|
-
if (!
|
|
53523
|
+
if (!isRecord15(part))
|
|
53400
53524
|
continue;
|
|
53401
53525
|
if (part.type === "thinking" && !projectedReasoning && reasoning.length > 0) {
|
|
53402
53526
|
const item2 = {
|
|
@@ -53588,12 +53712,12 @@ async function rollbackPiLastTurn(transport, sourceSessionId, cwd) {
|
|
|
53588
53712
|
// packages/adapters/pi/dist/pi-rpc-session.js
|
|
53589
53713
|
import { spawn as spawn4, spawnSync as spawnSync2 } from "node:child_process";
|
|
53590
53714
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
53591
|
-
import
|
|
53715
|
+
import path13 from "node:path";
|
|
53592
53716
|
|
|
53593
53717
|
// packages/adapters/pi/dist/command.js
|
|
53594
53718
|
import { accessSync as accessSync2, constants as constants2, readdirSync as readdirSync2, statSync as statSync3 } from "node:fs";
|
|
53595
53719
|
import os5 from "node:os";
|
|
53596
|
-
import
|
|
53720
|
+
import path12 from "node:path";
|
|
53597
53721
|
function environmentValue2(environment, name) {
|
|
53598
53722
|
return Object.entries(environment).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
|
|
53599
53723
|
}
|
|
@@ -53606,7 +53730,7 @@ function isExecutable3(filePath, platform) {
|
|
|
53606
53730
|
}
|
|
53607
53731
|
}
|
|
53608
53732
|
function pathCandidates(command, platform, environment) {
|
|
53609
|
-
const targetPath = platform === "win32" ?
|
|
53733
|
+
const targetPath = platform === "win32" ? path12.win32 : path12.posix;
|
|
53610
53734
|
if (targetPath.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
|
|
53611
53735
|
return [command];
|
|
53612
53736
|
}
|
|
@@ -53622,7 +53746,7 @@ function nvmCandidates2(homeDirectory, executableName, targetPath) {
|
|
|
53622
53746
|
}
|
|
53623
53747
|
}
|
|
53624
53748
|
function userInstallCandidates2(platform, environment, homeDirectory) {
|
|
53625
|
-
const targetPath = platform === "win32" ?
|
|
53749
|
+
const targetPath = platform === "win32" ? path12.win32 : path12.posix;
|
|
53626
53750
|
if (platform === "win32") {
|
|
53627
53751
|
const appData = environment.APPDATA ?? targetPath.join(homeDirectory, "AppData", "Roaming");
|
|
53628
53752
|
return [
|
|
@@ -53654,7 +53778,7 @@ function resolvePiExecutable(input, dependencies = {}) {
|
|
|
53654
53778
|
function withNodeRuntimeOnPath2(environment, runtimeExecutable = process.execPath, platform = process.platform) {
|
|
53655
53779
|
const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
|
|
53656
53780
|
const delimiter = platform === "win32" ? ";" : ":";
|
|
53657
|
-
const runtimeDirectory =
|
|
53781
|
+
const runtimeDirectory = path12.dirname(runtimeExecutable);
|
|
53658
53782
|
const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
|
|
53659
53783
|
const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
|
|
53660
53784
|
if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
|
|
@@ -53664,14 +53788,14 @@ function withNodeRuntimeOnPath2(environment, runtimeExecutable = process.execPat
|
|
|
53664
53788
|
}
|
|
53665
53789
|
|
|
53666
53790
|
// packages/adapters/pi/dist/pi-usage.js
|
|
53667
|
-
function
|
|
53791
|
+
function isRecord16(value) {
|
|
53668
53792
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53669
53793
|
}
|
|
53670
53794
|
function nonNegativeSafeInteger2(value) {
|
|
53671
53795
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
53672
53796
|
}
|
|
53673
53797
|
function optionalPiCacheHitRatePercent(value) {
|
|
53674
|
-
if (!
|
|
53798
|
+
if (!isRecord16(value) || value.role !== "assistant" || !isRecord16(value.usage))
|
|
53675
53799
|
return null;
|
|
53676
53800
|
const input = nonNegativeSafeInteger2(value.usage.input);
|
|
53677
53801
|
const cacheRead = nonNegativeSafeInteger2(value.usage.cacheRead);
|
|
@@ -53684,20 +53808,20 @@ function optionalPiCacheHitRatePercent(value) {
|
|
|
53684
53808
|
function latestPiCacheHitRatePercent(history) {
|
|
53685
53809
|
let latest = null;
|
|
53686
53810
|
for (const entry of activePiEntries(history)) {
|
|
53687
|
-
if (entry.type === "message" &&
|
|
53811
|
+
if (entry.type === "message" && isRecord16(entry.message) && entry.message.role === "assistant") {
|
|
53688
53812
|
latest = optionalPiCacheHitRatePercent(entry.message);
|
|
53689
53813
|
}
|
|
53690
53814
|
}
|
|
53691
53815
|
return latest;
|
|
53692
53816
|
}
|
|
53693
53817
|
function responseData(response, operation) {
|
|
53694
|
-
if (!
|
|
53818
|
+
if (!isRecord16(response.data)) {
|
|
53695
53819
|
throw new Error(`Pi RPC ${operation} response has no data`);
|
|
53696
53820
|
}
|
|
53697
53821
|
return response.data;
|
|
53698
53822
|
}
|
|
53699
53823
|
function contextUsage(value) {
|
|
53700
|
-
if (!
|
|
53824
|
+
if (!isRecord16(value))
|
|
53701
53825
|
throw new Error("Pi RPC context Usage is invalid");
|
|
53702
53826
|
return parseHostUsage({
|
|
53703
53827
|
contextUsedTokens: value.tokens,
|
|
@@ -53707,15 +53831,15 @@ function contextUsage(value) {
|
|
|
53707
53831
|
function parsePiSessionUsage(response) {
|
|
53708
53832
|
const data = responseData(response, "Session stats");
|
|
53709
53833
|
const tokens = data.tokens;
|
|
53710
|
-
if (tokens !== void 0 && !
|
|
53834
|
+
if (tokens !== void 0 && !isRecord16(tokens)) {
|
|
53711
53835
|
throw new Error("Pi RPC Session stats tokens are invalid");
|
|
53712
53836
|
}
|
|
53713
53837
|
return parseHostUsage({
|
|
53714
|
-
...
|
|
53715
|
-
...
|
|
53716
|
-
...
|
|
53717
|
-
...
|
|
53718
|
-
...
|
|
53838
|
+
...isRecord16(tokens) && tokens.input !== void 0 ? { inputTokens: tokens.input } : {},
|
|
53839
|
+
...isRecord16(tokens) && tokens.cacheRead !== void 0 ? { cachedInputTokens: tokens.cacheRead } : {},
|
|
53840
|
+
...isRecord16(tokens) && tokens.cacheWrite !== void 0 ? { cacheWriteInputTokens: tokens.cacheWrite } : {},
|
|
53841
|
+
...isRecord16(tokens) && tokens.output !== void 0 ? { outputTokens: tokens.output } : {},
|
|
53842
|
+
...isRecord16(tokens) && tokens.total !== void 0 ? { totalTokens: tokens.total } : {},
|
|
53719
53843
|
...data.cost !== void 0 ? { totalCostUsd: data.cost } : {},
|
|
53720
53844
|
...data.contextUsage !== void 0 ? contextUsage(data.contextUsage) : {}
|
|
53721
53845
|
});
|
|
@@ -53738,7 +53862,7 @@ function optionalPiStateContextUsage(value) {
|
|
|
53738
53862
|
import { open, realpath } from "node:fs/promises";
|
|
53739
53863
|
var MAX_SESSION_HEADER_BYTES = 64 * 1024;
|
|
53740
53864
|
var utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
53741
|
-
function
|
|
53865
|
+
function isRecord17(value) {
|
|
53742
53866
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53743
53867
|
}
|
|
53744
53868
|
async function readPiSessionHeader(sessionFile) {
|
|
@@ -53758,7 +53882,7 @@ async function readPiSessionHeader(sessionFile) {
|
|
|
53758
53882
|
} catch {
|
|
53759
53883
|
throw new Error("Pi Session header is not valid JSON");
|
|
53760
53884
|
}
|
|
53761
|
-
if (!
|
|
53885
|
+
if (!isRecord17(parsed) || parsed.type !== "session" || typeof parsed.id !== "string" || parsed.id.length === 0 || typeof parsed.cwd !== "string" || parsed.cwd.length === 0) {
|
|
53762
53886
|
throw new Error("Pi Session header is invalid");
|
|
53763
53887
|
}
|
|
53764
53888
|
return { type: "session", id: parsed.id, cwd: parsed.cwd };
|
|
@@ -53800,7 +53924,7 @@ var PiRpcUnsupportedCommandError = class extends Error {
|
|
|
53800
53924
|
}
|
|
53801
53925
|
};
|
|
53802
53926
|
var textDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
53803
|
-
function
|
|
53927
|
+
function isRecord18(value) {
|
|
53804
53928
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53805
53929
|
}
|
|
53806
53930
|
function message2(value) {
|
|
@@ -53812,13 +53936,13 @@ function nonBlankString2(value) {
|
|
|
53812
53936
|
function parseNativeModel(value, context) {
|
|
53813
53937
|
if (value === null || value === void 0)
|
|
53814
53938
|
return null;
|
|
53815
|
-
if (!
|
|
53939
|
+
if (!isRecord18(value) || !nonBlankString2(value.provider) || !nonBlankString2(value.id)) {
|
|
53816
53940
|
throw new PiRpcFaultError("protocolError", `Pi RPC returned an invalid ${context} Model`);
|
|
53817
53941
|
}
|
|
53818
53942
|
return { provider: value.provider, id: value.id };
|
|
53819
53943
|
}
|
|
53820
53944
|
function sessionStateData(response) {
|
|
53821
|
-
const data =
|
|
53945
|
+
const data = isRecord18(response.data) ? response.data : null;
|
|
53822
53946
|
if (!data)
|
|
53823
53947
|
throw new PiRpcFaultError("protocolError", "Pi RPC state response has no data");
|
|
53824
53948
|
return data;
|
|
@@ -53850,13 +53974,13 @@ function parseSessionStreaming(response) {
|
|
|
53850
53974
|
return isStreaming;
|
|
53851
53975
|
}
|
|
53852
53976
|
function parseSessionHistory(response) {
|
|
53853
|
-
const data =
|
|
53977
|
+
const data = isRecord18(response.data) ? response.data : null;
|
|
53854
53978
|
if (!data || !Array.isArray(data.entries)) {
|
|
53855
53979
|
throw new PiRpcFaultError("protocolError", "Pi RPC entries response has no Entries");
|
|
53856
53980
|
}
|
|
53857
53981
|
const entries = data.entries.map((entry) => {
|
|
53858
53982
|
const parsed = jsonValueSchema.safeParse(entry);
|
|
53859
|
-
if (!parsed.success || !
|
|
53983
|
+
if (!parsed.success || !isRecord18(parsed.data)) {
|
|
53860
53984
|
throw new PiRpcFaultError("protocolError", "Pi RPC entries response contains an invalid Entry");
|
|
53861
53985
|
}
|
|
53862
53986
|
return parsed.data;
|
|
@@ -53867,7 +53991,7 @@ function parseSessionHistory(response) {
|
|
|
53867
53991
|
return { entries, leafId: data.leafId };
|
|
53868
53992
|
}
|
|
53869
53993
|
function parseAvailableThinkingLevels(response) {
|
|
53870
|
-
const data =
|
|
53994
|
+
const data = isRecord18(response.data) ? response.data : null;
|
|
53871
53995
|
if (!data || !Array.isArray(data.levels) || data.levels.length === 0) {
|
|
53872
53996
|
throw new PiRpcFaultError("protocolError", "Pi RPC Thinking catalog response has no levels");
|
|
53873
53997
|
}
|
|
@@ -53884,35 +54008,35 @@ function parseAvailableThinkingLevels(response) {
|
|
|
53884
54008
|
return levels;
|
|
53885
54009
|
}
|
|
53886
54010
|
function parseAvailableModels(response) {
|
|
53887
|
-
const data =
|
|
54011
|
+
const data = isRecord18(response.data) ? response.data : null;
|
|
53888
54012
|
if (!data || !Array.isArray(data.models)) {
|
|
53889
54013
|
throw new PiRpcFaultError("protocolError", "Pi RPC Model catalog response has no models");
|
|
53890
54014
|
}
|
|
53891
54015
|
return data.models.map((model) => {
|
|
53892
54016
|
const parsed = parseNativeModel(model, "catalog");
|
|
53893
|
-
if (!parsed || !
|
|
54017
|
+
if (!parsed || !isRecord18(model) || typeof model.reasoning !== "boolean") {
|
|
53894
54018
|
throw new PiRpcFaultError("protocolError", "Pi RPC catalog contains a Model without reasoning capability");
|
|
53895
54019
|
}
|
|
53896
54020
|
return { ...parsed, reasoning: model.reasoning };
|
|
53897
54021
|
});
|
|
53898
54022
|
}
|
|
53899
54023
|
function assistantText2(value) {
|
|
53900
|
-
if (!
|
|
54024
|
+
if (!isRecord18(value) || value.role !== "assistant" || !Array.isArray(value.content))
|
|
53901
54025
|
return null;
|
|
53902
|
-
return value.content.filter((content) =>
|
|
54026
|
+
return value.content.filter((content) => isRecord18(content) && content.type === "text" && typeof content.text === "string").map((content) => content.text).join("");
|
|
53903
54027
|
}
|
|
53904
54028
|
function assistantMessageId(value) {
|
|
53905
|
-
if (!
|
|
54029
|
+
if (!isRecord18(value) || value.role !== "assistant")
|
|
53906
54030
|
return null;
|
|
53907
54031
|
return nonBlankString2(value.responseId) ? value.responseId : null;
|
|
53908
54032
|
}
|
|
53909
54033
|
function assistantReasoning(value) {
|
|
53910
|
-
if (!
|
|
54034
|
+
if (!isRecord18(value) || value.role !== "assistant" || !Array.isArray(value.content))
|
|
53911
54035
|
return null;
|
|
53912
|
-
return value.content.filter((content) =>
|
|
54036
|
+
return value.content.filter((content) => isRecord18(content) && content.type === "thinking" && typeof content.thinking === "string").map((content) => content.thinking).join("");
|
|
53913
54037
|
}
|
|
53914
54038
|
function assistantFailure(value) {
|
|
53915
|
-
if (!
|
|
54039
|
+
if (!isRecord18(value) || value.role !== "assistant")
|
|
53916
54040
|
return void 0;
|
|
53917
54041
|
if (value.stopReason !== "error" && value.stopReason !== "aborted")
|
|
53918
54042
|
return null;
|
|
@@ -53932,7 +54056,7 @@ function signalProcessTree2(child, signal) {
|
|
|
53932
54056
|
try {
|
|
53933
54057
|
process.kill(-child.pid, signal);
|
|
53934
54058
|
} catch (error52) {
|
|
53935
|
-
if (!
|
|
54059
|
+
if (!isRecord18(error52) || error52.code !== "ESRCH")
|
|
53936
54060
|
throw error52;
|
|
53937
54061
|
}
|
|
53938
54062
|
}
|
|
@@ -53963,7 +54087,7 @@ function piRpcProcessCommand(options, dependencies = {}) {
|
|
|
53963
54087
|
const sessionArguments = options.forkSessionFile ? ["--fork", options.forkSessionFile] : options.sessionFile ? ["--session", options.sessionFile] : [];
|
|
53964
54088
|
const modelArguments = options.model ? ["--provider", options.model.provider, "--model", options.model.id] : [];
|
|
53965
54089
|
const arguments_2 = ["--mode", "rpc", ...modelArguments, ...sessionArguments];
|
|
53966
|
-
const extension =
|
|
54090
|
+
const extension = path13.win32.extname(command).toLowerCase();
|
|
53967
54091
|
if (platform !== "win32" || ![".cmd", ".bat"].includes(extension)) {
|
|
53968
54092
|
return { command, arguments: arguments_2, windowsVerbatimArguments: false };
|
|
53969
54093
|
}
|
|
@@ -54046,7 +54170,7 @@ var PiRpcSession = class {
|
|
|
54046
54170
|
});
|
|
54047
54171
|
child.stderr.resume();
|
|
54048
54172
|
child.once("error", (error52) => {
|
|
54049
|
-
const kind =
|
|
54173
|
+
const kind = isRecord18(error52) && error52.code === "ENOENT" ? "notInstalled" : "unavailable";
|
|
54050
54174
|
this.#fail(new PiRpcFaultError(kind, `Pi RPC failed to start: ${error52.message}`));
|
|
54051
54175
|
});
|
|
54052
54176
|
child.once("exit", (code, signal) => {
|
|
@@ -54298,7 +54422,7 @@ var PiRpcSession = class {
|
|
|
54298
54422
|
this.#buffer = this.#buffer.subarray(newline3 + 1);
|
|
54299
54423
|
try {
|
|
54300
54424
|
const value = JSON.parse(textDecoder.decode(frame));
|
|
54301
|
-
if (!
|
|
54425
|
+
if (!isRecord18(value) || typeof value.type !== "string") {
|
|
54302
54426
|
throw new PiRpcFaultError("protocolError", "Pi RPC returned an invalid envelope");
|
|
54303
54427
|
}
|
|
54304
54428
|
this.#handle(value);
|
|
@@ -54337,7 +54461,7 @@ var PiRpcSession = class {
|
|
|
54337
54461
|
}
|
|
54338
54462
|
compactionTurn?.onEvent({
|
|
54339
54463
|
type: "compaction.completed",
|
|
54340
|
-
outcome: value.aborted === true ? "cancelled" :
|
|
54464
|
+
outcome: value.aborted === true ? "cancelled" : isRecord18(value.result) ? "succeeded" : "failed",
|
|
54341
54465
|
...nonBlankString2(value.errorMessage) ? { errorMessage: value.errorMessage } : {}
|
|
54342
54466
|
});
|
|
54343
54467
|
return;
|
|
@@ -54357,7 +54481,7 @@ var PiRpcSession = class {
|
|
|
54357
54481
|
this.#startAssistantMessage(active, value.message);
|
|
54358
54482
|
return;
|
|
54359
54483
|
}
|
|
54360
|
-
if (value.type === "message_update" &&
|
|
54484
|
+
if (value.type === "message_update" && isRecord18(value.assistantMessageEvent)) {
|
|
54361
54485
|
const event = value.assistantMessageEvent;
|
|
54362
54486
|
if (event.type === "text_delta" && typeof event.delta === "string") {
|
|
54363
54487
|
const messageId = this.#ensureAssistantMessage(active, value.message);
|
|
@@ -54751,7 +54875,7 @@ var PiRpcSession = class {
|
|
|
54751
54875
|
// packages/adapters/pi/dist/pi-adapter.js
|
|
54752
54876
|
var piHarnessId2 = harnessIdSchema.parse("pi");
|
|
54753
54877
|
var DEFAULT_TOOL_OUTPUT_LIMIT4 = 64e3;
|
|
54754
|
-
function
|
|
54878
|
+
function isRecord19(value) {
|
|
54755
54879
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
54756
54880
|
}
|
|
54757
54881
|
function errorMessage(error52) {
|
|
@@ -54825,7 +54949,7 @@ function nativeModelForHistory(state) {
|
|
|
54825
54949
|
return nativeModelFromState(state);
|
|
54826
54950
|
}
|
|
54827
54951
|
function sessionFileFromRef(ref) {
|
|
54828
|
-
if (ref.harnessId !== piHarnessId2 || !
|
|
54952
|
+
if (ref.harnessId !== piHarnessId2 || !isRecord19(ref.locator) || typeof ref.locator.sessionFile !== "string" || ref.locator.sessionFile.length === 0) {
|
|
54829
54953
|
throw new Error("Pi Native Session Ref has no resumable Session file");
|
|
54830
54954
|
}
|
|
54831
54955
|
return ref.locator.sessionFile;
|
|
@@ -54840,9 +54964,9 @@ function toolFailure2(toolName) {
|
|
|
54840
54964
|
function nativeText(value) {
|
|
54841
54965
|
if (typeof value === "string")
|
|
54842
54966
|
return value;
|
|
54843
|
-
if (!
|
|
54967
|
+
if (!isRecord19(value) || !Array.isArray(value.content))
|
|
54844
54968
|
return "";
|
|
54845
|
-
return value.content.filter((content) =>
|
|
54969
|
+
return value.content.filter((content) => isRecord19(content) && content.type === "text" && typeof content.text === "string").map(({ text }) => text).join("");
|
|
54846
54970
|
}
|
|
54847
54971
|
function boundedOutput(value, limit) {
|
|
54848
54972
|
const text = nativeText(value);
|
|
@@ -54858,19 +54982,19 @@ function outputText2(output) {
|
|
|
54858
54982
|
return output?.content.filter((content) => content.type === "text").map(({ text }) => text).join("") ?? "";
|
|
54859
54983
|
}
|
|
54860
54984
|
function stringField2(value, key) {
|
|
54861
|
-
return
|
|
54985
|
+
return isRecord19(value) && typeof value[key] === "string" ? value[key] : void 0;
|
|
54862
54986
|
}
|
|
54863
54987
|
function numberField(value, key) {
|
|
54864
|
-
if (!
|
|
54988
|
+
if (!isRecord19(value))
|
|
54865
54989
|
return void 0;
|
|
54866
54990
|
const field = value[key];
|
|
54867
54991
|
return typeof field === "number" || field === null ? field : void 0;
|
|
54868
54992
|
}
|
|
54869
|
-
function stripDiffPrefix(
|
|
54870
|
-
return
|
|
54993
|
+
function stripDiffPrefix(path19) {
|
|
54994
|
+
return path19.startsWith("a/") || path19.startsWith("b/") ? path19.slice(2) : path19;
|
|
54871
54995
|
}
|
|
54872
54996
|
function reliableFileChange(result) {
|
|
54873
|
-
if (!
|
|
54997
|
+
if (!isRecord19(result) || !isRecord19(result.details) || typeof result.details.patch !== "string") {
|
|
54874
54998
|
return null;
|
|
54875
54999
|
}
|
|
54876
55000
|
const patch = result.details.patch;
|
|
@@ -54886,10 +55010,10 @@ function reliableFileChange(result) {
|
|
|
54886
55010
|
const oldFile = file2.oldFileName;
|
|
54887
55011
|
const newFile = file2.newFileName;
|
|
54888
55012
|
const kind = oldFile === "/dev/null" ? "add" : newFile === "/dev/null" ? "delete" : "update";
|
|
54889
|
-
const
|
|
54890
|
-
if (!
|
|
55013
|
+
const path19 = stripDiffPrefix(kind === "delete" ? oldFile : newFile);
|
|
55014
|
+
if (!path19 || path19 === "/dev/null")
|
|
54891
55015
|
return null;
|
|
54892
|
-
return [{ path:
|
|
55016
|
+
return [{ path: path19, kind, unifiedDiff: patch }];
|
|
54893
55017
|
}
|
|
54894
55018
|
function delay3(milliseconds) {
|
|
54895
55019
|
return new Promise((resolve2) => setTimeout(resolve2, milliseconds));
|
|
@@ -56133,7 +56257,7 @@ import { execFileSync } from "node:child_process";
|
|
|
56133
56257
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
56134
56258
|
import { constants as constants3 } from "node:fs";
|
|
56135
56259
|
import { copyFile, mkdir, open as open2, readFile as readFile3, readdir, rename, rm as rm2, stat } from "node:fs/promises";
|
|
56136
|
-
import
|
|
56260
|
+
import path14 from "node:path";
|
|
56137
56261
|
|
|
56138
56262
|
// packages/mapping-store/dist/records.js
|
|
56139
56263
|
var nonBlankTextSchema3 = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
@@ -56350,11 +56474,11 @@ var MappingStore = class {
|
|
|
56350
56474
|
#initialized = false;
|
|
56351
56475
|
#lockHandle = null;
|
|
56352
56476
|
constructor(options) {
|
|
56353
|
-
this.#directory =
|
|
56354
|
-
this.#threadsDirectory =
|
|
56355
|
-
this.#backupsDirectory =
|
|
56356
|
-
this.#quarantineDirectory =
|
|
56357
|
-
this.#lockPath =
|
|
56477
|
+
this.#directory = path14.resolve(options.directory);
|
|
56478
|
+
this.#threadsDirectory = path14.join(this.#directory, "threads");
|
|
56479
|
+
this.#backupsDirectory = path14.join(this.#directory, "backups");
|
|
56480
|
+
this.#quarantineDirectory = path14.join(this.#directory, "quarantine");
|
|
56481
|
+
this.#lockPath = path14.join(this.#directory, "store.lock");
|
|
56358
56482
|
this.#instanceId = options.instanceId ?? randomUUID6();
|
|
56359
56483
|
this.#now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
56360
56484
|
this.#beforeReplace = options.beforeReplace;
|
|
@@ -56372,8 +56496,8 @@ var MappingStore = class {
|
|
|
56372
56496
|
await this.#cleanupTemps();
|
|
56373
56497
|
const names = (await readdir(this.#threadsDirectory)).filter((name) => name.endsWith(".json"));
|
|
56374
56498
|
for (const name of names) {
|
|
56375
|
-
const primary =
|
|
56376
|
-
const backup =
|
|
56499
|
+
const primary = path14.join(this.#threadsDirectory, name);
|
|
56500
|
+
const backup = path14.join(this.#backupsDirectory, name);
|
|
56377
56501
|
let record3 = null;
|
|
56378
56502
|
try {
|
|
56379
56503
|
record3 = await this.#readRecord(primary, name);
|
|
@@ -56382,7 +56506,7 @@ var MappingStore = class {
|
|
|
56382
56506
|
record3 = await this.#readRecord(backup, name);
|
|
56383
56507
|
await this.#replaceFile(primary, record3, false);
|
|
56384
56508
|
} catch (backupError) {
|
|
56385
|
-
const quarantine =
|
|
56509
|
+
const quarantine = path14.join(this.#quarantineDirectory, `${name}.${this.#now().getTime()}.invalid`);
|
|
56386
56510
|
await rename(primary, quarantine).catch(() => void 0);
|
|
56387
56511
|
void primaryError;
|
|
56388
56512
|
void backupError;
|
|
@@ -56665,7 +56789,7 @@ var MappingStore = class {
|
|
|
56665
56789
|
}
|
|
56666
56790
|
async #cleanupTemps() {
|
|
56667
56791
|
const names = await readdir(this.#threadsDirectory);
|
|
56668
|
-
await Promise.all(names.filter((name) => name.includes(".tmp-")).map((name) => rm2(
|
|
56792
|
+
await Promise.all(names.filter((name) => name.includes(".tmp-")).map((name) => rm2(path14.join(this.#threadsDirectory, name), { force: true })));
|
|
56669
56793
|
}
|
|
56670
56794
|
async #acquireLock() {
|
|
56671
56795
|
const attempt = async () => {
|
|
@@ -56758,10 +56882,10 @@ var MappingStore = class {
|
|
|
56758
56882
|
}
|
|
56759
56883
|
}
|
|
56760
56884
|
#recordPath(hostThreadId) {
|
|
56761
|
-
return
|
|
56885
|
+
return path14.join(this.#threadsDirectory, `${hostThreadId}.json`);
|
|
56762
56886
|
}
|
|
56763
56887
|
#backupPath(hostThreadId) {
|
|
56764
|
-
return
|
|
56888
|
+
return path14.join(this.#backupsDirectory, `${hostThreadId}.json`);
|
|
56765
56889
|
}
|
|
56766
56890
|
#requireInitialized() {
|
|
56767
56891
|
if (!this.#initialized) {
|
|
@@ -56780,7 +56904,7 @@ var packageMetadata5 = {
|
|
|
56780
56904
|
var TITLE_MAX_LENGTH = 120;
|
|
56781
56905
|
var DESCRIPTION_MAX_LENGTH = 500;
|
|
56782
56906
|
var SERVER_NAME_MAX_LENGTH = 80;
|
|
56783
|
-
function
|
|
56907
|
+
function isRecord20(value) {
|
|
56784
56908
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
56785
56909
|
}
|
|
56786
56910
|
function boundedText(value, field, maxLength) {
|
|
@@ -56824,7 +56948,7 @@ function responseError(message3) {
|
|
|
56824
56948
|
function responsePersist(value) {
|
|
56825
56949
|
if (value === void 0 || value === null)
|
|
56826
56950
|
return null;
|
|
56827
|
-
if (!
|
|
56951
|
+
if (!isRecord20(value) || Object.keys(value).length !== 1 || value.persist !== "session" && value.persist !== "always") {
|
|
56828
56952
|
throw responseError("contains malformed persist metadata");
|
|
56829
56953
|
}
|
|
56830
56954
|
return value.persist;
|
|
@@ -56867,7 +56991,7 @@ function projectCodexApprovalRequest(input) {
|
|
|
56867
56991
|
},
|
|
56868
56992
|
denyResponse,
|
|
56869
56993
|
parseResponse(result) {
|
|
56870
|
-
if (!
|
|
56994
|
+
if (!isRecord20(result) || typeof result.action !== "string") {
|
|
56871
56995
|
throw responseError("missing action");
|
|
56872
56996
|
}
|
|
56873
56997
|
if (Object.keys(result).some((key) => key !== "action" && key !== "content" && key !== "_meta")) {
|
|
@@ -56875,7 +56999,7 @@ function projectCodexApprovalRequest(input) {
|
|
|
56875
56999
|
}
|
|
56876
57000
|
const selectedPersist = responsePersist(result._meta);
|
|
56877
57001
|
if (result.action === "accept") {
|
|
56878
|
-
if ("content" in result && (!
|
|
57002
|
+
if ("content" in result && (!isRecord20(result.content) || Object.keys(result.content).length !== 0)) {
|
|
56879
57003
|
throw responseError("contains non-empty accepted content");
|
|
56880
57004
|
}
|
|
56881
57005
|
if (selectedPersist === "session") {
|
|
@@ -56902,7 +57026,7 @@ function projectCodexApprovalRequest(input) {
|
|
|
56902
57026
|
}
|
|
56903
57027
|
|
|
56904
57028
|
// packages/protocol-core/dist/codex-question.js
|
|
56905
|
-
function
|
|
57029
|
+
function isRecord21(value) {
|
|
56906
57030
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
56907
57031
|
}
|
|
56908
57032
|
function responseError2(message3) {
|
|
@@ -56971,7 +57095,7 @@ function projectCodexQuestionRequest(input) {
|
|
|
56971
57095
|
}
|
|
56972
57096
|
},
|
|
56973
57097
|
parseResponse(result) {
|
|
56974
|
-
if (!
|
|
57098
|
+
if (!isRecord21(result) || !isRecord21(result.answers)) {
|
|
56975
57099
|
throw responseError2("missing answers object");
|
|
56976
57100
|
}
|
|
56977
57101
|
const rawAnswers = result.answers;
|
|
@@ -56984,7 +57108,7 @@ function projectCodexQuestionRequest(input) {
|
|
|
56984
57108
|
const question = interaction.questions.find(({ id: id2 }) => id2 === questionId);
|
|
56985
57109
|
if (!question)
|
|
56986
57110
|
throw responseError2("contains an unknown Question ID");
|
|
56987
|
-
if (!
|
|
57111
|
+
if (!isRecord21(answerValue) || !Array.isArray(answerValue.answers)) {
|
|
56988
57112
|
throw responseError2("answer entry has no answers array");
|
|
56989
57113
|
}
|
|
56990
57114
|
const values = answerValue.answers;
|
|
@@ -57130,8 +57254,8 @@ function projectItem(item, outcome, defaultCwd, includeCommandOutput = true) {
|
|
|
57130
57254
|
return {
|
|
57131
57255
|
id: item.itemId,
|
|
57132
57256
|
type: "fileChange",
|
|
57133
|
-
changes: item.changes.map(({ path:
|
|
57134
|
-
path:
|
|
57257
|
+
changes: item.changes.map(({ path: path19, kind, unifiedDiff }) => ({
|
|
57258
|
+
path: path19,
|
|
57135
57259
|
kind,
|
|
57136
57260
|
diff: unifiedDiff
|
|
57137
57261
|
})),
|
|
@@ -57548,8 +57672,8 @@ var CodexTurnProjector = class {
|
|
|
57548
57672
|
return messages;
|
|
57549
57673
|
}
|
|
57550
57674
|
#fileChangeUpdates(itemId3, changes) {
|
|
57551
|
-
const projectedChanges = changes.map(({ path:
|
|
57552
|
-
path:
|
|
57675
|
+
const projectedChanges = changes.map(({ path: path19, kind, unifiedDiff }) => ({
|
|
57676
|
+
path: path19,
|
|
57553
57677
|
kind,
|
|
57554
57678
|
diff: unifiedDiff
|
|
57555
57679
|
}));
|
|
@@ -57594,7 +57718,7 @@ var CodexTurnProjector = class {
|
|
|
57594
57718
|
};
|
|
57595
57719
|
|
|
57596
57720
|
// packages/protocol-core/dist/thread-fork.js
|
|
57597
|
-
function
|
|
57721
|
+
function isRecord22(value) {
|
|
57598
57722
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
57599
57723
|
}
|
|
57600
57724
|
function optionalText(params, name, options = {}) {
|
|
@@ -57617,7 +57741,7 @@ function optionalBoolean(params, name) {
|
|
|
57617
57741
|
function decodeThreadForkRequest(request) {
|
|
57618
57742
|
if (request.method !== "thread/fork")
|
|
57619
57743
|
return null;
|
|
57620
|
-
if (!
|
|
57744
|
+
if (!isRecord22(request.params))
|
|
57621
57745
|
throw new Error("thread/fork params must be an object");
|
|
57622
57746
|
const params = request.params;
|
|
57623
57747
|
const threadId2 = optionalText(params, "threadId");
|
|
@@ -57632,13 +57756,13 @@ function decodeThreadForkRequest(request) {
|
|
|
57632
57756
|
if (runtimeWorkspaceRoots !== void 0 && runtimeWorkspaceRoots !== null && (!Array.isArray(runtimeWorkspaceRoots) || runtimeWorkspaceRoots.some((root) => typeof root !== "string" || root.length === 0))) {
|
|
57633
57757
|
throw new Error("thread/fork params.runtimeWorkspaceRoots must be text paths or null");
|
|
57634
57758
|
}
|
|
57635
|
-
const
|
|
57759
|
+
const path19 = optionalText(params, "path", { allowEmpty: true });
|
|
57636
57760
|
const ephemeral = optionalBoolean(params, "ephemeral");
|
|
57637
57761
|
return {
|
|
57638
57762
|
threadId: threadId2,
|
|
57639
57763
|
...lastTurnText ? { lastTurnId: hostTurnIdSchema.parse(lastTurnText) } : {},
|
|
57640
57764
|
...beforeTurnText ? { beforeTurnId: hostTurnIdSchema.parse(beforeTurnText) } : {},
|
|
57641
|
-
...
|
|
57765
|
+
...path19 ? { path: path19 } : {},
|
|
57642
57766
|
...optionalField(params, "model"),
|
|
57643
57767
|
...optionalField(params, "modelProvider"),
|
|
57644
57768
|
...optionalField(params, "cwd"),
|
|
@@ -57653,7 +57777,7 @@ function decodeThreadForkRequest(request) {
|
|
|
57653
57777
|
function decodeThreadRollbackRequest(request) {
|
|
57654
57778
|
if (request.method !== "thread/rollback")
|
|
57655
57779
|
return null;
|
|
57656
|
-
if (!
|
|
57780
|
+
if (!isRecord22(request.params))
|
|
57657
57781
|
throw new Error("thread/rollback params must be an object");
|
|
57658
57782
|
const { threadId: threadId2, numTurns } = request.params;
|
|
57659
57783
|
if (typeof threadId2 !== "string" || threadId2.length === 0) {
|
|
@@ -57747,13 +57871,13 @@ var THREAD_SOURCE_KINDS = /* @__PURE__ */ new Set([
|
|
|
57747
57871
|
"subAgentOther",
|
|
57748
57872
|
"unknown"
|
|
57749
57873
|
]);
|
|
57750
|
-
function
|
|
57874
|
+
function isRecord23(value) {
|
|
57751
57875
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
57752
57876
|
}
|
|
57753
57877
|
function paramsObject(request, method) {
|
|
57754
57878
|
if (request.params === void 0 && method === "thread/list")
|
|
57755
57879
|
return {};
|
|
57756
|
-
if (!
|
|
57880
|
+
if (!isRecord23(request.params))
|
|
57757
57881
|
throw new Error(`${method} params must be an object`);
|
|
57758
57882
|
return request.params;
|
|
57759
57883
|
}
|
|
@@ -57825,7 +57949,7 @@ function cursorPayload(value) {
|
|
|
57825
57949
|
};
|
|
57826
57950
|
}
|
|
57827
57951
|
function parseCursorPayload(value) {
|
|
57828
|
-
if (!
|
|
57952
|
+
if (!isRecord23(value) || value.formatVersion !== 1)
|
|
57829
57953
|
throw new Error("Host cursor is invalid");
|
|
57830
57954
|
const { queryFingerprint: fingerprint, sortDirection: sortDirection2, officialCursor, officialDone } = value;
|
|
57831
57955
|
const { externalAnchor: externalAnchor2, externalDone } = value;
|
|
@@ -57834,7 +57958,7 @@ function parseCursorPayload(value) {
|
|
|
57834
57958
|
}
|
|
57835
57959
|
let anchor = null;
|
|
57836
57960
|
if (externalAnchor2 !== null) {
|
|
57837
|
-
if (!
|
|
57961
|
+
if (!isRecord23(externalAnchor2) || !Number.isSafeInteger(externalAnchor2.timestamp) || typeof externalAnchor2.threadId !== "string" || externalAnchor2.threadId.length === 0) {
|
|
57838
57962
|
throw new Error("Host cursor is invalid");
|
|
57839
57963
|
}
|
|
57840
57964
|
anchor = {
|
|
@@ -57954,7 +58078,7 @@ function decodeThreadMetadataUpdateRequest(request) {
|
|
|
57954
58078
|
if (params.gitInfo === null) {
|
|
57955
58079
|
gitInfo = null;
|
|
57956
58080
|
} else if (params.gitInfo !== void 0) {
|
|
57957
|
-
if (!
|
|
58081
|
+
if (!isRecord23(params.gitInfo)) {
|
|
57958
58082
|
throw new Error("thread/metadata/update params.gitInfo must be an object or null");
|
|
57959
58083
|
}
|
|
57960
58084
|
gitInfo = {};
|
|
@@ -57982,7 +58106,7 @@ function optionalCursor(value, name) {
|
|
|
57982
58106
|
return value;
|
|
57983
58107
|
}
|
|
57984
58108
|
function decodeOfficialThreadListPage(value) {
|
|
57985
|
-
if (!
|
|
58109
|
+
if (!isRecord23(value) || !Array.isArray(value.data) || value.data.some((row) => !isRecord23(row))) {
|
|
57986
58110
|
throw new Error("Official thread/list response is invalid");
|
|
57987
58111
|
}
|
|
57988
58112
|
return {
|
|
@@ -58304,7 +58428,7 @@ var packageMetadata6 = {
|
|
|
58304
58428
|
// packages/host-runtime/src/external-thread-repository.ts
|
|
58305
58429
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
58306
58430
|
import os6 from "node:os";
|
|
58307
|
-
import
|
|
58431
|
+
import path15 from "node:path";
|
|
58308
58432
|
function nativeTurnKey2(ref) {
|
|
58309
58433
|
return `${ref.harnessId}\0${ref.nativeSessionId}\0${ref.nativeTurnKey}\0${ref.formatVersion}`;
|
|
58310
58434
|
}
|
|
@@ -58313,8 +58437,8 @@ function sameMapping(left, right) {
|
|
|
58313
58437
|
}
|
|
58314
58438
|
function defaultMappingStoreDirectory(environment) {
|
|
58315
58439
|
const dataDirectory = environment.CODEXHOST_DATA_DIR;
|
|
58316
|
-
return
|
|
58317
|
-
dataDirectory ?
|
|
58440
|
+
return path15.join(
|
|
58441
|
+
dataDirectory ? path15.resolve(dataDirectory) : path15.join(os6.homedir(), ".codexhost"),
|
|
58318
58442
|
"mapping-store"
|
|
58319
58443
|
);
|
|
58320
58444
|
}
|
|
@@ -59388,7 +59512,7 @@ var ExternalThreadRuntime = class {
|
|
|
59388
59512
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
59389
59513
|
var INTERNAL_REQUEST_PREFIX = "codexhost:official:";
|
|
59390
59514
|
var MAX_RETIRED_IDS = 1024;
|
|
59391
|
-
function
|
|
59515
|
+
function isRecord24(value) {
|
|
59392
59516
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59393
59517
|
}
|
|
59394
59518
|
var OfficialRequestBroker = class {
|
|
@@ -59431,7 +59555,7 @@ var OfficialRequestBroker = class {
|
|
|
59431
59555
|
});
|
|
59432
59556
|
}
|
|
59433
59557
|
handle(value) {
|
|
59434
|
-
if (!
|
|
59558
|
+
if (!isRecord24(value) || typeof value.id !== "string") return false;
|
|
59435
59559
|
const pending = this.#pending.get(value.id);
|
|
59436
59560
|
if (!pending) return this.#retired.has(value.id);
|
|
59437
59561
|
clearTimeout(pending.timeout);
|
|
@@ -59460,11 +59584,11 @@ var OfficialRequestBroker = class {
|
|
|
59460
59584
|
};
|
|
59461
59585
|
|
|
59462
59586
|
// packages/host-runtime/src/route-observation.ts
|
|
59463
|
-
function
|
|
59587
|
+
function isRecord25(value) {
|
|
59464
59588
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59465
59589
|
}
|
|
59466
59590
|
function classifyThreadPurpose(request) {
|
|
59467
|
-
return
|
|
59591
|
+
return isRecord25(request.params) && request.params.ephemeral === true ? "ephemeral" : "conversation";
|
|
59468
59592
|
}
|
|
59469
59593
|
var RequestRouteObservationTracker = class {
|
|
59470
59594
|
#nextCreateOrdinal = 0;
|
|
@@ -59489,13 +59613,13 @@ var RequestRouteObservationTracker = class {
|
|
|
59489
59613
|
this.#createByThreadId.set(threadId2, tracked);
|
|
59490
59614
|
}
|
|
59491
59615
|
bindOfficialResponse(response) {
|
|
59492
|
-
if (!
|
|
59616
|
+
if (!isRecord25(response) || !("id" in response)) return;
|
|
59493
59617
|
const tracked = this.#pendingByRequestId.get(response.id);
|
|
59494
59618
|
if (!tracked) return;
|
|
59495
59619
|
this.#pendingByRequestId.delete(response.id);
|
|
59496
59620
|
const result = response.result;
|
|
59497
|
-
const thread =
|
|
59498
|
-
if (
|
|
59621
|
+
const thread = isRecord25(result) ? result.thread : null;
|
|
59622
|
+
if (isRecord25(thread) && typeof thread.id === "string") {
|
|
59499
59623
|
this.#createByThreadId.set(thread.id, tracked);
|
|
59500
59624
|
}
|
|
59501
59625
|
}
|
|
@@ -59592,25 +59716,25 @@ function resolveExternalSessionTreeIds(records) {
|
|
|
59592
59716
|
const resolve2 = (start) => {
|
|
59593
59717
|
const cached2 = resolved.get(start.hostThreadId);
|
|
59594
59718
|
if (cached2) return cached2;
|
|
59595
|
-
const
|
|
59719
|
+
const path19 = [];
|
|
59596
59720
|
const visited = /* @__PURE__ */ new Set();
|
|
59597
59721
|
let current = start;
|
|
59598
59722
|
while (true) {
|
|
59599
59723
|
const known = resolved.get(current.hostThreadId);
|
|
59600
59724
|
if (known) {
|
|
59601
|
-
for (const record3 of
|
|
59725
|
+
for (const record3 of path19) resolved.set(record3.hostThreadId, known);
|
|
59602
59726
|
return known;
|
|
59603
59727
|
}
|
|
59604
59728
|
if (visited.has(current.hostThreadId)) {
|
|
59605
59729
|
throw new Error("External Thread Fork tree contains a cycle");
|
|
59606
59730
|
}
|
|
59607
59731
|
visited.add(current.hostThreadId);
|
|
59608
|
-
|
|
59732
|
+
path19.push(current);
|
|
59609
59733
|
const sourceId = current.forkSource?.hostThreadId;
|
|
59610
59734
|
const source = sourceId ? byId.get(sourceId) : void 0;
|
|
59611
59735
|
if (!source) {
|
|
59612
59736
|
const root = current.hostThreadId;
|
|
59613
|
-
for (const record3 of
|
|
59737
|
+
for (const record3 of path19) resolved.set(record3.hostThreadId, root);
|
|
59614
59738
|
return root;
|
|
59615
59739
|
}
|
|
59616
59740
|
current = source;
|
|
@@ -59661,11 +59785,11 @@ var OfficialThreadListError = class extends Error {
|
|
|
59661
59785
|
}
|
|
59662
59786
|
rpcError;
|
|
59663
59787
|
};
|
|
59664
|
-
function
|
|
59788
|
+
function isRecord26(value) {
|
|
59665
59789
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59666
59790
|
}
|
|
59667
59791
|
function officialThreadListPageFromResponse(response) {
|
|
59668
|
-
if (
|
|
59792
|
+
if (isRecord26(response.error)) {
|
|
59669
59793
|
if (!Number.isSafeInteger(response.error.code) || typeof response.error.message !== "string") {
|
|
59670
59794
|
throw new Error("Official thread/list error response is invalid");
|
|
59671
59795
|
}
|
|
@@ -59825,14 +59949,14 @@ async function aggregateThreadList(input) {
|
|
|
59825
59949
|
}
|
|
59826
59950
|
|
|
59827
59951
|
// packages/host-runtime/src/app-server-host.ts
|
|
59828
|
-
function
|
|
59952
|
+
function isRecord27(value) {
|
|
59829
59953
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59830
59954
|
}
|
|
59831
59955
|
function isCreditsAdapter(adapter) {
|
|
59832
59956
|
return typeof adapter.credits === "function" && typeof adapter.refreshCredits === "function";
|
|
59833
59957
|
}
|
|
59834
59958
|
function projectAccountCredits(value) {
|
|
59835
|
-
if (!
|
|
59959
|
+
if (!isRecord27(value)) return null;
|
|
59836
59960
|
const rest = { ...value };
|
|
59837
59961
|
delete rest.fetchedAt;
|
|
59838
59962
|
const parsed = accountCreditsSnapshotSchema.safeParse(rest);
|
|
@@ -59932,12 +60056,12 @@ function classifyCreateRequestRoute(request, defaultAgent2) {
|
|
|
59932
60056
|
};
|
|
59933
60057
|
}
|
|
59934
60058
|
function requestObject(request) {
|
|
59935
|
-
if (!
|
|
60059
|
+
if (!isRecord27(request.params)) throw new Error(`${request.method} params must be an object`);
|
|
59936
60060
|
return request.params;
|
|
59937
60061
|
}
|
|
59938
60062
|
function requestText(params) {
|
|
59939
60063
|
if (!Array.isArray(params.input)) throw new Error("turn/start input must be an array");
|
|
59940
|
-
const text = params.input.filter((item) =>
|
|
60064
|
+
const text = params.input.filter((item) => isRecord27(item) && item.type === "text").map((item) => item.text).filter((value) => typeof value === "string").join("\n");
|
|
59941
60065
|
if (!text) throw new Error("turn/start must contain text input");
|
|
59942
60066
|
return text;
|
|
59943
60067
|
}
|
|
@@ -60211,7 +60335,7 @@ var AppServerHost = class {
|
|
|
60211
60335
|
continue;
|
|
60212
60336
|
}
|
|
60213
60337
|
if (request.method === "thread/fork") {
|
|
60214
|
-
const params =
|
|
60338
|
+
const params = isRecord27(request.params) ? request.params : {};
|
|
60215
60339
|
const resolution = typeof params.threadId === "string" ? await this.#resolveExternalThread(params.threadId) : { kind: "official" };
|
|
60216
60340
|
if (resolution.kind === "error") {
|
|
60217
60341
|
await this.#writer.json(
|
|
@@ -60234,7 +60358,7 @@ var AppServerHost = class {
|
|
|
60234
60358
|
}
|
|
60235
60359
|
}
|
|
60236
60360
|
if (request.method === "thread/rollback") {
|
|
60237
|
-
const params =
|
|
60361
|
+
const params = isRecord27(request.params) ? request.params : {};
|
|
60238
60362
|
const resolution = typeof params.threadId === "string" ? await this.#resolveExternalThread(params.threadId) : { kind: "official" };
|
|
60239
60363
|
if (resolution.kind === "error") {
|
|
60240
60364
|
await this.#writer.json(
|
|
@@ -60374,7 +60498,7 @@ var AppServerHost = class {
|
|
|
60374
60498
|
continue;
|
|
60375
60499
|
}
|
|
60376
60500
|
}
|
|
60377
|
-
if (request.method.startsWith("thread/") && !EXPLICIT_EXTERNAL_THREAD_METHODS.has(request.method) &&
|
|
60501
|
+
if (request.method.startsWith("thread/") && !EXPLICIT_EXTERNAL_THREAD_METHODS.has(request.method) && isRecord27(request.params) && typeof request.params.threadId === "string") {
|
|
60378
60502
|
const location = await this.#locateExternalThread(request.params.threadId);
|
|
60379
60503
|
if (await this.#writeResolutionError(request, location)) continue;
|
|
60380
60504
|
if (location.kind === "external") {
|
|
@@ -61197,10 +61321,10 @@ var AppServerHost = class {
|
|
|
61197
61321
|
...typeof params.serviceTier === "string" ? { serviceTier: params.serviceTier } : {}
|
|
61198
61322
|
});
|
|
61199
61323
|
try {
|
|
61200
|
-
if (params.initialTurnsPage !== void 0 && params.initialTurnsPage !== null && !
|
|
61324
|
+
if (params.initialTurnsPage !== void 0 && params.initialTurnsPage !== null && !isRecord27(params.initialTurnsPage)) {
|
|
61201
61325
|
throw new ExternalHistoryRequestError("initialTurnsPage must be an object");
|
|
61202
61326
|
}
|
|
61203
|
-
const initialPageParams =
|
|
61327
|
+
const initialPageParams = isRecord27(params.initialTurnsPage) ? params.initialTurnsPage : null;
|
|
61204
61328
|
const initialTurnsPage = initialPageParams ? listExternalTurns(turns, initialPageParams) : null;
|
|
61205
61329
|
const paginated = thread.record.historyMode === "paginated";
|
|
61206
61330
|
const turnsBackwardsCursor = paginated ? listExternalTurns(turns, { limit: 1, itemsView: "notLoaded" }).backwardsCursor : null;
|
|
@@ -61452,7 +61576,7 @@ var AppServerHost = class {
|
|
|
61452
61576
|
}
|
|
61453
61577
|
}
|
|
61454
61578
|
async #handleDesktopApprovalResponse(value) {
|
|
61455
|
-
if (!
|
|
61579
|
+
if (!isRecord27(value) || !isHostApprovalRequestId(value.id)) return false;
|
|
61456
61580
|
const pending = this.#pendingDesktopApprovals.get(value.id);
|
|
61457
61581
|
if (!pending) return true;
|
|
61458
61582
|
this.#pendingDesktopApprovals.delete(value.id);
|
|
@@ -61574,7 +61698,7 @@ var AppServerHost = class {
|
|
|
61574
61698
|
}
|
|
61575
61699
|
}
|
|
61576
61700
|
async #handleDesktopQuestionResponse(value) {
|
|
61577
|
-
if (!
|
|
61701
|
+
if (!isRecord27(value) || !isHostQuestionRequestId(value.id)) return false;
|
|
61578
61702
|
const pending = this.#pendingDesktopQuestions.get(value.id);
|
|
61579
61703
|
if (!pending) return true;
|
|
61580
61704
|
this.#pendingDesktopQuestions.delete(value.id);
|
|
@@ -61686,7 +61810,7 @@ var AppServerHost = class {
|
|
|
61686
61810
|
|
|
61687
61811
|
// packages/update-manager/dist/distribution.js
|
|
61688
61812
|
import { lstat, readFile as readFile4 } from "node:fs/promises";
|
|
61689
|
-
import
|
|
61813
|
+
import path16 from "node:path";
|
|
61690
61814
|
|
|
61691
61815
|
// packages/update-manager/dist/status.js
|
|
61692
61816
|
var STATUS_SCHEMA_VERSION = 1;
|
|
@@ -61773,9 +61897,9 @@ function parseDistributionMetadata(value) {
|
|
|
61773
61897
|
}
|
|
61774
61898
|
function absoluteEnvironmentPath(environment, name) {
|
|
61775
61899
|
const value = environment[name];
|
|
61776
|
-
if (!value || !
|
|
61900
|
+
if (!value || !path16.isAbsolute(value))
|
|
61777
61901
|
throw new Error(`${name} must be an absolute path`);
|
|
61778
|
-
return
|
|
61902
|
+
return path16.normalize(value);
|
|
61779
61903
|
}
|
|
61780
61904
|
function positiveEnvironmentInteger(environment, name) {
|
|
61781
61905
|
const value = Number(environment[name]);
|
|
@@ -61799,29 +61923,29 @@ function expectedTarget(platform, architecture) {
|
|
|
61799
61923
|
function defaultUpdateStateDirectory(platform = process.platform, environment = process.env) {
|
|
61800
61924
|
if (platform === "win32") {
|
|
61801
61925
|
const root = environment.LOCALAPPDATA;
|
|
61802
|
-
if (!root || !
|
|
61926
|
+
if (!root || !path16.isAbsolute(root))
|
|
61803
61927
|
throw new Error("LOCALAPPDATA is unavailable");
|
|
61804
|
-
return
|
|
61928
|
+
return path16.join(root, "codexhost", "updates");
|
|
61805
61929
|
}
|
|
61806
61930
|
const home = environment.HOME;
|
|
61807
|
-
if (!home || !
|
|
61931
|
+
if (!home || !path16.isAbsolute(home))
|
|
61808
61932
|
throw new Error("HOME is unavailable");
|
|
61809
|
-
return platform === "darwin" ?
|
|
61933
|
+
return platform === "darwin" ? path16.join(home, "Library", "Application Support", "codexhost", "updates") : path16.join(home, ".codexhost", "updates");
|
|
61810
61934
|
}
|
|
61811
61935
|
async function resolveInstalledUpdateContext(options) {
|
|
61812
61936
|
const environment = options.environment ?? process.env;
|
|
61813
61937
|
const platform = options.platform ?? process.platform;
|
|
61814
61938
|
const architecture = options.architecture ?? process.arch;
|
|
61815
|
-
if (!
|
|
61939
|
+
if (!path16.isAbsolute(options.hostRuntimePath)) {
|
|
61816
61940
|
throw new Error("Host Runtime path must be absolute");
|
|
61817
61941
|
}
|
|
61818
|
-
const hostRuntimePath =
|
|
61942
|
+
const hostRuntimePath = path16.normalize(options.hostRuntimePath);
|
|
61819
61943
|
const runtimeMetadata = await lstat(hostRuntimePath);
|
|
61820
61944
|
if (!runtimeMetadata.isFile() || runtimeMetadata.isSymbolicLink()) {
|
|
61821
61945
|
throw new Error("Host Runtime must be a regular file");
|
|
61822
61946
|
}
|
|
61823
|
-
const appDirectory =
|
|
61824
|
-
const metadata = parseDistributionMetadata(JSON.parse(await readFile4(
|
|
61947
|
+
const appDirectory = path16.dirname(hostRuntimePath);
|
|
61948
|
+
const metadata = parseDistributionMetadata(JSON.parse(await readFile4(path16.join(appDirectory, "codexhost-distribution.json"), "utf8")));
|
|
61825
61949
|
const target = expectedTarget(platform, architecture);
|
|
61826
61950
|
if (metadata.target !== target) {
|
|
61827
61951
|
throw new Error(`installed target ${metadata.target} does not match ${target}`);
|
|
@@ -61829,10 +61953,10 @@ async function resolveInstalledUpdateContext(options) {
|
|
|
61829
61953
|
const launcherPid = positiveEnvironmentInteger(environment, UPDATE_RUNTIME_ENV.launcherPid);
|
|
61830
61954
|
const launcherExecutable = absoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.launcherExecutable);
|
|
61831
61955
|
const runtimeDescriptorPath = absoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.runtimeDescriptorPath);
|
|
61832
|
-
const stateDirectory =
|
|
61833
|
-
const resourcesRoot =
|
|
61834
|
-
const installationRoot = platform === "darwin" ?
|
|
61835
|
-
const updaterExecutable =
|
|
61956
|
+
const stateDirectory = path16.normalize(options.stateDirectory ?? defaultUpdateStateDirectory(platform, environment));
|
|
61957
|
+
const resourcesRoot = path16.dirname(appDirectory);
|
|
61958
|
+
const installationRoot = platform === "darwin" ? path16.dirname(path16.dirname(resourcesRoot)) : resourcesRoot;
|
|
61959
|
+
const updaterExecutable = path16.join(resourcesRoot, "libexec", platform === "win32" ? "codexhost-updater.exe" : "codexhost-updater");
|
|
61836
61960
|
const common = {
|
|
61837
61961
|
version: metadata.version,
|
|
61838
61962
|
launcherPid,
|
|
@@ -61856,7 +61980,7 @@ async function resolveInstalledUpdateContext(options) {
|
|
|
61856
61980
|
npmLauncherPath: absoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.npmLauncherPath),
|
|
61857
61981
|
packageRoot: absoluteEnvironmentPath(environment, UPDATE_RUNTIME_ENV.npmPackageRoot)
|
|
61858
61982
|
};
|
|
61859
|
-
if (
|
|
61983
|
+
if (path16.normalize(npmOptions.packageRoot) !== resourcesRoot) {
|
|
61860
61984
|
throw new Error("npm platform package root does not own the Host Runtime");
|
|
61861
61985
|
}
|
|
61862
61986
|
return { metadata, common, controller, installation: { kind: "npm", options: npmOptions } };
|
|
@@ -62019,7 +62143,7 @@ function selectInstallerReleaseArtifact(release, target) {
|
|
|
62019
62143
|
|
|
62020
62144
|
// packages/update-manager/dist/operation-state.js
|
|
62021
62145
|
import { lstat as lstat2, mkdir as mkdir2, open as open3, readFile as readFile5, readdir as readdir2, rm as rm3, writeFile } from "node:fs/promises";
|
|
62022
|
-
import
|
|
62146
|
+
import path17 from "node:path";
|
|
62023
62147
|
var LOCK_FILE = "active-update-v1.lock";
|
|
62024
62148
|
var STATUS_FILE = "status-v1.json";
|
|
62025
62149
|
var TERMINAL_PHASES = /* @__PURE__ */ new Set(["succeeded", "failed"]);
|
|
@@ -62034,12 +62158,12 @@ async function regularFile(filePath) {
|
|
|
62034
62158
|
}
|
|
62035
62159
|
}
|
|
62036
62160
|
async function isUpdateOperationActive(stateDirectory) {
|
|
62037
|
-
if (!
|
|
62161
|
+
if (!path17.isAbsolute(stateDirectory))
|
|
62038
62162
|
throw new Error("update state directory must be absolute");
|
|
62039
|
-
return regularFile(
|
|
62163
|
+
return regularFile(path17.join(stateDirectory, LOCK_FILE));
|
|
62040
62164
|
}
|
|
62041
62165
|
async function discoverLatestUpdateStatus(stateDirectory) {
|
|
62042
|
-
if (!
|
|
62166
|
+
if (!path17.isAbsolute(stateDirectory))
|
|
62043
62167
|
throw new Error("update state directory must be absolute");
|
|
62044
62168
|
let entries;
|
|
62045
62169
|
try {
|
|
@@ -62053,7 +62177,7 @@ async function discoverLatestUpdateStatus(stateDirectory) {
|
|
|
62053
62177
|
for (const entry of entries) {
|
|
62054
62178
|
if (!entry.isDirectory() || entry.isSymbolicLink() || !entry.name.startsWith("update-"))
|
|
62055
62179
|
continue;
|
|
62056
|
-
const statusPath =
|
|
62180
|
+
const statusPath = path17.join(stateDirectory, entry.name, STATUS_FILE);
|
|
62057
62181
|
if (!await regularFile(statusPath))
|
|
62058
62182
|
continue;
|
|
62059
62183
|
try {
|
|
@@ -62081,8 +62205,8 @@ async function cleanupTerminalUpdateState(stateDirectory, options = {}) {
|
|
|
62081
62205
|
for (const entry of entries) {
|
|
62082
62206
|
if (!entry.isDirectory() || entry.isSymbolicLink() || !entry.name.startsWith("update-"))
|
|
62083
62207
|
continue;
|
|
62084
|
-
const directory =
|
|
62085
|
-
const statusPath =
|
|
62208
|
+
const directory = path17.join(stateDirectory, entry.name);
|
|
62209
|
+
const statusPath = path17.join(directory, STATUS_FILE);
|
|
62086
62210
|
try {
|
|
62087
62211
|
const status = parseUpdateStatus(JSON.parse(await readFile5(statusPath, "utf8")));
|
|
62088
62212
|
if (TERMINAL_PHASES.has(status.phase) && now - status.updatedAt > retentionSeconds) {
|
|
@@ -62093,10 +62217,10 @@ async function cleanupTerminalUpdateState(stateDirectory, options = {}) {
|
|
|
62093
62217
|
}
|
|
62094
62218
|
}
|
|
62095
62219
|
async function acquireUpdateOperationLock(stateDirectory) {
|
|
62096
|
-
if (!
|
|
62220
|
+
if (!path17.isAbsolute(stateDirectory))
|
|
62097
62221
|
throw new Error("update state directory must be absolute");
|
|
62098
62222
|
await mkdir2(stateDirectory, { recursive: true, mode: 448 });
|
|
62099
|
-
const lockPath =
|
|
62223
|
+
const lockPath = path17.join(stateDirectory, LOCK_FILE);
|
|
62100
62224
|
let handle;
|
|
62101
62225
|
try {
|
|
62102
62226
|
handle = await open3(lockPath, "wx", 384);
|
|
@@ -62115,9 +62239,9 @@ async function acquireUpdateOperationLock(stateDirectory) {
|
|
|
62115
62239
|
async setStatusPath(statusPath) {
|
|
62116
62240
|
if (released)
|
|
62117
62241
|
throw new Error("update operation lock is released");
|
|
62118
|
-
if (!
|
|
62242
|
+
if (!path17.isAbsolute(statusPath))
|
|
62119
62243
|
throw new Error("update status path must be absolute");
|
|
62120
|
-
await writeFile(lockPath, `${JSON.stringify({ ownerPid: process.pid, statusPath:
|
|
62244
|
+
await writeFile(lockPath, `${JSON.stringify({ ownerPid: process.pid, statusPath: path17.normalize(statusPath) })}
|
|
62121
62245
|
`, { encoding: "utf8", mode: 384 });
|
|
62122
62246
|
},
|
|
62123
62247
|
async release() {
|
|
@@ -62139,7 +62263,7 @@ function processIsAlive(processId) {
|
|
|
62139
62263
|
}
|
|
62140
62264
|
}
|
|
62141
62265
|
async function recoverUpdateOperationLock(stateDirectory) {
|
|
62142
|
-
const lockPath =
|
|
62266
|
+
const lockPath = path17.join(stateDirectory, LOCK_FILE);
|
|
62143
62267
|
if (!await regularFile(lockPath))
|
|
62144
62268
|
return;
|
|
62145
62269
|
let ownerPid;
|
|
@@ -62151,7 +62275,7 @@ async function recoverUpdateOperationLock(stateDirectory) {
|
|
|
62151
62275
|
} catch {
|
|
62152
62276
|
return;
|
|
62153
62277
|
}
|
|
62154
|
-
if (typeof statusPath !== "string" || !
|
|
62278
|
+
if (typeof statusPath !== "string" || !path17.isAbsolute(statusPath))
|
|
62155
62279
|
return;
|
|
62156
62280
|
try {
|
|
62157
62281
|
const status = parseUpdateStatus(JSON.parse(await readFile5(statusPath, "utf8")));
|
|
@@ -62166,7 +62290,7 @@ async function recoverUpdateOperationLock(stateDirectory) {
|
|
|
62166
62290
|
import { spawn as spawn6 } from "node:child_process";
|
|
62167
62291
|
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
62168
62292
|
import { chmod, copyFile as copyFile2, lstat as lstat4, mkdir as mkdir3, readFile as readFile6, rename as rename2, rm as rm4, writeFile as writeFile2 } from "node:fs/promises";
|
|
62169
|
-
import
|
|
62293
|
+
import path18 from "node:path";
|
|
62170
62294
|
|
|
62171
62295
|
// packages/update-manager/dist/artifact.js
|
|
62172
62296
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -62287,9 +62411,9 @@ async function replaceStatusFile(temporaryPath, statusPath) {
|
|
|
62287
62411
|
}
|
|
62288
62412
|
}
|
|
62289
62413
|
function requireAbsolutePath(value, label) {
|
|
62290
|
-
if (!
|
|
62414
|
+
if (!path18.isAbsolute(value))
|
|
62291
62415
|
throw new Error(`${label} must be an absolute path`);
|
|
62292
|
-
return
|
|
62416
|
+
return path18.normalize(value);
|
|
62293
62417
|
}
|
|
62294
62418
|
async function requireRegularFile(value, label) {
|
|
62295
62419
|
const filePath = requireAbsolutePath(value, label);
|
|
@@ -62332,7 +62456,7 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
62332
62456
|
const now = dependencies.now ?? Date.now;
|
|
62333
62457
|
const preparedRequests = /* @__PURE__ */ new Set();
|
|
62334
62458
|
async function writeStatusSnapshot(statusPath, status) {
|
|
62335
|
-
const temporaryPath =
|
|
62459
|
+
const temporaryPath = path18.join(path18.dirname(statusPath), `.update-status-${randomId()}.tmp`);
|
|
62336
62460
|
try {
|
|
62337
62461
|
await writeFile2(temporaryPath, `${JSON.stringify(status)}
|
|
62338
62462
|
`, {
|
|
@@ -62392,15 +62516,15 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
62392
62516
|
const updaterExecutable = await requireRegularFile(options.updaterExecutable, "Updater executable");
|
|
62393
62517
|
const stateDirectory = requireAbsolutePath(options.stateDirectory, "update state directory");
|
|
62394
62518
|
await mkdir3(stateDirectory, { recursive: true, mode: 448 });
|
|
62395
|
-
const workDirectory =
|
|
62519
|
+
const workDirectory = path18.join(stateDirectory, `update-${version2}-${randomId()}`);
|
|
62396
62520
|
await mkdir3(workDirectory, { recursive: false, mode: 448 });
|
|
62397
62521
|
const executableSuffix = platform === "win32" ? ".exe" : "";
|
|
62398
|
-
const helperPath =
|
|
62522
|
+
const helperPath = path18.join(workDirectory, `codexhost-updater${executableSuffix}`);
|
|
62399
62523
|
await copyFile2(updaterExecutable, helperPath);
|
|
62400
62524
|
if (platform !== "win32")
|
|
62401
62525
|
await chmod(helperPath, 448);
|
|
62402
|
-
const requestPath =
|
|
62403
|
-
const statusPath =
|
|
62526
|
+
const requestPath = path18.join(workDirectory, "request-v1.json");
|
|
62527
|
+
const statusPath = path18.join(workDirectory, "status-v1.json");
|
|
62404
62528
|
await writePrivateJson(statusPath, preparedStatus(version2, installation, now()));
|
|
62405
62529
|
await options.onPrepared?.({ version: version2, installation, statusPath });
|
|
62406
62530
|
return {
|
|
@@ -62416,8 +62540,8 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
62416
62540
|
}
|
|
62417
62541
|
async function prepareArtifact(common, installation, sourceValue, fileName) {
|
|
62418
62542
|
const source = validateArtifact(sourceValue);
|
|
62419
|
-
const temporaryPath =
|
|
62420
|
-
const artifactPath =
|
|
62543
|
+
const temporaryPath = path18.join(common.workDirectory, `.${fileName}.download`);
|
|
62544
|
+
const artifactPath = path18.join(common.workDirectory, fileName);
|
|
62421
62545
|
const progress = progressReporter(common.statusPath, common.version, installation, source.size);
|
|
62422
62546
|
try {
|
|
62423
62547
|
const result = await download(source, temporaryPath, progress.update);
|
|
@@ -62491,7 +62615,7 @@ function createBackgroundUpdateManager(dependencies = {}) {
|
|
|
62491
62615
|
throw new Error("macOS DMG updates require macOS");
|
|
62492
62616
|
const common = await prepareCommon(options, "macos-dmg");
|
|
62493
62617
|
const appPath = requireAbsolutePath(options.appPath, "macOS application path");
|
|
62494
|
-
if (
|
|
62618
|
+
if (path18.extname(appPath) !== ".app") {
|
|
62495
62619
|
throw new Error("macOS application path must end in .app");
|
|
62496
62620
|
}
|
|
62497
62621
|
const artifact = await prepareArtifact(common, "macos-dmg", options.artifact, "update.dmg");
|