@liberseek/boft-cli-win32-arm64 0.7.8 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES.txt +8 -0
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +16801 -16440
- package/app/console-web.js +9774 -3685
- package/app/desktop-controller.mjs +16475 -374
- package/app/host-runtime.mjs +9052 -1793
- package/app/plugins/antigravity/manifest.json +18 -1
- package/app/plugins/antigravity/plugin.mjs +357 -42
- package/app/plugins/claude-code/manifest.json +28 -0
- package/app/plugins/claude-code/plugin.mjs +1448 -491
- package/app/plugins/codebuddy/manifest.json +17 -0
- package/app/plugins/codebuddy/plugin.mjs +6589 -5423
- package/app/plugins/codex-usage/manifest.json +9 -0
- package/app/plugins/codex-usage/plugin.mjs +16750 -0
- package/app/plugins/cursor-cli/manifest.json +18 -1
- package/app/plugins/cursor-cli/plugin.mjs +782 -197
- package/app/plugins/deepseek-harness/assets/icon.svg +1 -0
- package/app/plugins/deepseek-harness/manifest.json +35 -2
- package/app/plugins/deepseek-harness/plugin.mjs +879 -242
- package/app/plugins/enabled.json +3 -1
- package/app/plugins/grok/manifest.json +21 -1
- package/app/plugins/grok/plugin.mjs +1274 -241
- package/app/plugins/hermes/assets/icon.png +0 -0
- package/app/plugins/hermes/manifest.json +30 -2
- package/app/plugins/hermes/plugin.mjs +3493 -7686
- package/app/plugins/kimi-code/assets/icon.svg +5 -0
- package/app/plugins/kimi-code/manifest.json +25 -2
- package/app/plugins/kimi-code/plugin.mjs +922 -76
- package/app/plugins/kiro-cli/assets/kiro-agent.svg +11 -0
- package/app/plugins/kiro-cli/manifest.json +18 -1
- package/app/plugins/kiro-cli/plugin.mjs +658 -57
- package/app/plugins/muse/manifest.json +18 -1
- package/app/plugins/muse/plugin.mjs +332 -17
- package/app/plugins/omp/manifest.json +21 -1
- package/app/plugins/omp/plugin.mjs +2320 -1131
- package/app/plugins/opencode/manifest.json +18 -1
- package/app/plugins/opencode/plugin.mjs +979 -184
- package/app/plugins/pi/manifest.json +32 -0
- package/app/plugins/pi/plugin.mjs +2785 -2090
- package/app/plugins/qoder/manifest.json +18 -1
- package/app/plugins/qoder/plugin.mjs +832 -82
- package/app/plugins/qoder-cn/manifest.json +18 -1
- package/app/plugins/qoder-cn/plugin.mjs +832 -82
- package/app/plugins/workbuddy/manifest.json +18 -0
- package/app/plugins/workbuddy/plugin.mjs +6947 -5773
- package/app/plugins/zcode/assets/icon.svg +8 -0
- package/app/plugins/zcode/manifest.json +32 -0
- package/app/plugins/zcode/plugin.mjs +20110 -0
- package/app/renderer-extension.js +4762 -2470
- package/bin/boft.exe +0 -0
- package/libexec/boft-node-repl.exe +0 -0
- package/libexec/boft-shim.exe +0 -0
- package/libexec/boft-updater.exe +0 -0
- package/licenses/Cordis-LICENSE.txt +21 -0
- package/licenses/Cosmokit-LICENSE.txt +21 -0
- package/package.json +1 -1
- package/app/plugins/kiro-cli/assets/icon.svg +0 -5
|
@@ -372,20 +372,180 @@ function createHarnessInstaller(environment, source) {
|
|
|
372
372
|
};
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
// dist/usage-statistics.js
|
|
376
|
+
import os2 from "node:os";
|
|
377
|
+
import path5 from "node:path";
|
|
378
|
+
import { readFile } from "node:fs/promises";
|
|
379
|
+
|
|
380
|
+
// ../../harness-adapter/dist/usage-statistics.js
|
|
381
|
+
import { createReadStream } from "node:fs";
|
|
382
|
+
import { lstat, opendir } from "node:fs/promises";
|
|
383
|
+
import path4 from "node:path";
|
|
384
|
+
import { createInterface } from "node:readline";
|
|
385
|
+
var MAX_SESSION_ID_LENGTH = 512;
|
|
386
|
+
var MAX_CWD_LENGTH = 4096;
|
|
387
|
+
function sessionIdOk(value) {
|
|
388
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
389
|
+
}
|
|
390
|
+
function cwdOk(value) {
|
|
391
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
|
|
392
|
+
}
|
|
393
|
+
function withUsageSession(entry, session) {
|
|
394
|
+
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
395
|
+
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
396
|
+
if (sessionId === void 0 && cwd === void 0)
|
|
397
|
+
return entry;
|
|
398
|
+
return {
|
|
399
|
+
...entry,
|
|
400
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
401
|
+
...cwd !== void 0 ? { cwd } : {}
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
async function jsonlUsageSources(root, maxDepth, signal) {
|
|
405
|
+
const sources = [];
|
|
406
|
+
const visit = async (directory, depth) => {
|
|
407
|
+
signal.throwIfAborted();
|
|
408
|
+
const entries = await opendir(directory).catch((error53) => {
|
|
409
|
+
if (error53.code === "ENOENT")
|
|
410
|
+
return null;
|
|
411
|
+
throw error53;
|
|
412
|
+
});
|
|
413
|
+
if (!entries)
|
|
414
|
+
return;
|
|
415
|
+
for await (const entry of entries) {
|
|
416
|
+
signal.throwIfAborted();
|
|
417
|
+
const file2 = path4.join(directory, entry.name);
|
|
418
|
+
if (entry.isDirectory()) {
|
|
419
|
+
if (depth < maxDepth)
|
|
420
|
+
await visit(file2, depth + 1);
|
|
421
|
+
} else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
422
|
+
const info = await lstat(file2).catch(() => null);
|
|
423
|
+
if (info?.isFile() && info.size > 0) {
|
|
424
|
+
sources.push({ id: file2, fingerprint: `${info.ino}:${info.size}:${info.mtimeMs}` });
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
await visit(root, 0);
|
|
430
|
+
return sources;
|
|
431
|
+
}
|
|
432
|
+
async function* jsonlRecords(file2, marker, signal) {
|
|
433
|
+
const lines = createInterface({
|
|
434
|
+
input: createReadStream(file2, { encoding: "utf8", signal }),
|
|
435
|
+
crlfDelay: Infinity
|
|
436
|
+
});
|
|
437
|
+
for await (const line of lines) {
|
|
438
|
+
if (!line.includes(marker))
|
|
439
|
+
continue;
|
|
440
|
+
let value;
|
|
441
|
+
try {
|
|
442
|
+
value = JSON.parse(line);
|
|
443
|
+
} catch {
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
447
|
+
yield value;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function nativeTimeMs(value) {
|
|
452
|
+
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
453
|
+
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// dist/usage-statistics.js
|
|
457
|
+
function isRecord(value) {
|
|
458
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
459
|
+
}
|
|
460
|
+
var USD_TICKS = 1e10;
|
|
461
|
+
function count(value) {
|
|
462
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
463
|
+
}
|
|
464
|
+
function grokHome(environment) {
|
|
465
|
+
return environment.GROK_HOME || path5.join(environment.HOME || os2.homedir(), ".grok");
|
|
466
|
+
}
|
|
467
|
+
async function forkedAtMs(directory) {
|
|
468
|
+
try {
|
|
469
|
+
const summary = JSON.parse(await readFile(path5.join(directory, "summary.json"), "utf8"));
|
|
470
|
+
return isRecord(summary) && typeof summary.parent_session_id === "string" ? nativeTimeMs(summary.created_at) : null;
|
|
471
|
+
} catch {
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function grokSession(file2) {
|
|
476
|
+
const directory = path5.dirname(file2);
|
|
477
|
+
let cwd;
|
|
478
|
+
try {
|
|
479
|
+
cwd = decodeURIComponent(path5.basename(path5.dirname(directory)));
|
|
480
|
+
} catch {
|
|
481
|
+
cwd = void 0;
|
|
482
|
+
}
|
|
483
|
+
return { sessionId: path5.basename(directory), cwd };
|
|
484
|
+
}
|
|
485
|
+
async function readGrokUsage(file2, signal) {
|
|
486
|
+
const forkedAt = await forkedAtMs(path5.dirname(file2));
|
|
487
|
+
const session = grokSession(file2);
|
|
488
|
+
const entries = [];
|
|
489
|
+
for await (const line of jsonlRecords(file2, '"turn_completed"', signal)) {
|
|
490
|
+
const params = isRecord(line.params) ? line.params : {};
|
|
491
|
+
const update = isRecord(params.update) ? params.update : {};
|
|
492
|
+
const usage = isRecord(update.usage) ? update.usage : {};
|
|
493
|
+
if (update.sessionUpdate !== "turn_completed" || typeof update.prompt_id !== "string")
|
|
494
|
+
continue;
|
|
495
|
+
const meta3 = isRecord(params._meta) ? params._meta : {};
|
|
496
|
+
const at = nativeTimeMs(meta3.agentTimestampMs) ?? (typeof line.timestamp === "number" ? nativeTimeMs(line.timestamp * 1e3) : null);
|
|
497
|
+
if (at === null || forkedAt !== null && at <= forkedAt)
|
|
498
|
+
continue;
|
|
499
|
+
for (const [model2, value] of Object.entries(isRecord(usage.modelUsage) ? usage.modelUsage : {})) {
|
|
500
|
+
if (!isRecord(value))
|
|
501
|
+
continue;
|
|
502
|
+
const input = count(value.inputTokens);
|
|
503
|
+
const output = count(value.outputTokens);
|
|
504
|
+
const cached2 = count(value.cachedReadTokens);
|
|
505
|
+
const written = count(value.cacheCreationTokens ?? 0);
|
|
506
|
+
const reasoning = count(value.reasoningTokens);
|
|
507
|
+
const ticks = count(value.costUsdTicks);
|
|
508
|
+
if (input === null || output === null || value.totalTokens !== input + output)
|
|
509
|
+
continue;
|
|
510
|
+
const cacheKnown = cached2 !== null && cached2 <= input && written === 0;
|
|
511
|
+
entries.push(withUsageSession({
|
|
512
|
+
id: `${update.prompt_id}:${model2}`,
|
|
513
|
+
occurredAtMs: at,
|
|
514
|
+
model: model2,
|
|
515
|
+
inputTokens: input,
|
|
516
|
+
...cacheKnown ? { cachedInputTokens: cached2, cacheWriteInputTokens: 0 } : {},
|
|
517
|
+
outputTokens: output,
|
|
518
|
+
...reasoning !== null && reasoning <= output ? { reasoningOutputTokens: reasoning } : {},
|
|
519
|
+
// A turn Grok marks incomplete has no cost of its own; it counts as free rather
|
|
520
|
+
// than as a model without a price.
|
|
521
|
+
...ticks !== null ? { costUsd: ticks / USD_TICKS } : usage.usageIsIncomplete === true ? { costUsd: 0 } : {}
|
|
522
|
+
}, session));
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return entries;
|
|
526
|
+
}
|
|
527
|
+
function createGrokUsageStatistics(environment) {
|
|
528
|
+
return Object.freeze({
|
|
529
|
+
// sessions/<url-encoded cwd>/<session>/updates.jsonl; subagents are sessions of their own.
|
|
530
|
+
listSources: async (signal) => (await jsonlUsageSources(path5.join(grokHome(environment), "sessions"), 2, signal)).filter((source) => path5.basename(source.id) === "updates.jsonl"),
|
|
531
|
+
readSource: (id, signal) => readGrokUsage(id, signal)
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
|
|
375
535
|
// dist/grok-adapter.js
|
|
376
536
|
import { randomUUID } from "node:crypto";
|
|
377
537
|
|
|
378
538
|
// dist/grok-credential-export.js
|
|
379
539
|
import { createHash } from "node:crypto";
|
|
380
|
-
import { readFile } from "node:fs/promises";
|
|
381
|
-
import
|
|
382
|
-
import
|
|
540
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
541
|
+
import os3 from "node:os";
|
|
542
|
+
import path6 from "node:path";
|
|
383
543
|
async function readGrokCredentials(environment) {
|
|
384
544
|
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((v) => v?.trim()))
|
|
385
545
|
return [];
|
|
386
546
|
try {
|
|
387
|
-
const home = environment.GROK_HOME ??
|
|
388
|
-
const auth = JSON.parse(await
|
|
547
|
+
const home = environment.GROK_HOME ?? path6.join(environment.HOME ?? os3.homedir(), ".grok");
|
|
548
|
+
const auth = JSON.parse(await readFile2(path6.join(home, "auth.json"), "utf8"));
|
|
389
549
|
const client2 = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
390
550
|
const entry = auth[`https://auth.x.ai::${client2}`] ?? auth["https://auth.x.ai"];
|
|
391
551
|
if (!entry || entry.oidc_issuer !== "https://auth.x.ai" || entry.oidc_client_id !== client2)
|
|
@@ -412,7 +572,7 @@ async function readGrokCredentials(environment) {
|
|
|
412
572
|
}
|
|
413
573
|
|
|
414
574
|
// dist/grok-adapter.js
|
|
415
|
-
import
|
|
575
|
+
import path15 from "node:path";
|
|
416
576
|
|
|
417
577
|
// ../../../node_modules/@agentclientprotocol/sdk/dist/schema/index.js
|
|
418
578
|
var AGENT_METHODS = {
|
|
@@ -1232,10 +1392,10 @@ function mergeDefs(...defs) {
|
|
|
1232
1392
|
function cloneDef(schema) {
|
|
1233
1393
|
return mergeDefs(schema._zod.def);
|
|
1234
1394
|
}
|
|
1235
|
-
function getElementAtPath(obj,
|
|
1236
|
-
if (!
|
|
1395
|
+
function getElementAtPath(obj, path16) {
|
|
1396
|
+
if (!path16)
|
|
1237
1397
|
return obj;
|
|
1238
|
-
return
|
|
1398
|
+
return path16.reduce((acc, key) => acc?.[key], obj);
|
|
1239
1399
|
}
|
|
1240
1400
|
function promiseAllObject(promisesObj) {
|
|
1241
1401
|
const keys = Object.keys(promisesObj);
|
|
@@ -1644,11 +1804,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1644
1804
|
}
|
|
1645
1805
|
return false;
|
|
1646
1806
|
}
|
|
1647
|
-
function prefixIssues(
|
|
1807
|
+
function prefixIssues(path16, issues) {
|
|
1648
1808
|
return issues.map((iss) => {
|
|
1649
1809
|
var _a3;
|
|
1650
1810
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1651
|
-
iss.path.unshift(
|
|
1811
|
+
iss.path.unshift(path16);
|
|
1652
1812
|
return iss;
|
|
1653
1813
|
});
|
|
1654
1814
|
}
|
|
@@ -1795,16 +1955,16 @@ function flattenError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1795
1955
|
}
|
|
1796
1956
|
function formatError(error53, mapper = (issue2) => issue2.message) {
|
|
1797
1957
|
const fieldErrors = { _errors: [] };
|
|
1798
|
-
const processError = (error54,
|
|
1958
|
+
const processError = (error54, path16 = []) => {
|
|
1799
1959
|
for (const issue2 of error54.issues) {
|
|
1800
1960
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1801
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1961
|
+
issue2.errors.map((issues) => processError({ issues }, [...path16, ...issue2.path]));
|
|
1802
1962
|
} else if (issue2.code === "invalid_key") {
|
|
1803
|
-
processError({ issues: issue2.issues }, [...
|
|
1963
|
+
processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
|
|
1804
1964
|
} else if (issue2.code === "invalid_element") {
|
|
1805
|
-
processError({ issues: issue2.issues }, [...
|
|
1965
|
+
processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
|
|
1806
1966
|
} else {
|
|
1807
|
-
const fullpath = [...
|
|
1967
|
+
const fullpath = [...path16, ...issue2.path];
|
|
1808
1968
|
if (fullpath.length === 0) {
|
|
1809
1969
|
fieldErrors._errors.push(mapper(issue2));
|
|
1810
1970
|
} else {
|
|
@@ -1831,17 +1991,17 @@ function formatError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1831
1991
|
}
|
|
1832
1992
|
function treeifyError(error53, mapper = (issue2) => issue2.message) {
|
|
1833
1993
|
const result = { errors: [] };
|
|
1834
|
-
const processError = (error54,
|
|
1994
|
+
const processError = (error54, path16 = []) => {
|
|
1835
1995
|
var _a3, _b;
|
|
1836
1996
|
for (const issue2 of error54.issues) {
|
|
1837
1997
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1838
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1998
|
+
issue2.errors.map((issues) => processError({ issues }, [...path16, ...issue2.path]));
|
|
1839
1999
|
} else if (issue2.code === "invalid_key") {
|
|
1840
|
-
processError({ issues: issue2.issues }, [...
|
|
2000
|
+
processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
|
|
1841
2001
|
} else if (issue2.code === "invalid_element") {
|
|
1842
|
-
processError({ issues: issue2.issues }, [...
|
|
2002
|
+
processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
|
|
1843
2003
|
} else {
|
|
1844
|
-
const fullpath = [...
|
|
2004
|
+
const fullpath = [...path16, ...issue2.path];
|
|
1845
2005
|
if (fullpath.length === 0) {
|
|
1846
2006
|
result.errors.push(mapper(issue2));
|
|
1847
2007
|
continue;
|
|
@@ -1873,8 +2033,8 @@ function treeifyError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1873
2033
|
}
|
|
1874
2034
|
function toDotPath(_path) {
|
|
1875
2035
|
const segs = [];
|
|
1876
|
-
const
|
|
1877
|
-
for (const seg of
|
|
2036
|
+
const path16 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
2037
|
+
for (const seg of path16) {
|
|
1878
2038
|
if (typeof seg === "number")
|
|
1879
2039
|
segs.push(`[${seg}]`);
|
|
1880
2040
|
else if (typeof seg === "symbol")
|
|
@@ -5102,8 +5262,8 @@ function az_default() {
|
|
|
5102
5262
|
}
|
|
5103
5263
|
|
|
5104
5264
|
// ../../../node_modules/zod/v4/locales/be.js
|
|
5105
|
-
function getBelarusianPlural(
|
|
5106
|
-
const absCount = Math.abs(
|
|
5265
|
+
function getBelarusianPlural(count3, one, few, many) {
|
|
5266
|
+
const absCount = Math.abs(count3);
|
|
5107
5267
|
const lastDigit = absCount % 10;
|
|
5108
5268
|
const lastTwoDigits = absCount % 100;
|
|
5109
5269
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -7181,8 +7341,8 @@ function hu_default() {
|
|
|
7181
7341
|
}
|
|
7182
7342
|
|
|
7183
7343
|
// ../../../node_modules/zod/v4/locales/hy.js
|
|
7184
|
-
function getArmenianPlural(
|
|
7185
|
-
return Math.abs(
|
|
7344
|
+
function getArmenianPlural(count3, one, many) {
|
|
7345
|
+
return Math.abs(count3) === 1 ? one : many;
|
|
7186
7346
|
}
|
|
7187
7347
|
function withDefiniteArticle(word) {
|
|
7188
7348
|
if (!word)
|
|
@@ -9310,8 +9470,8 @@ function ro_default() {
|
|
|
9310
9470
|
}
|
|
9311
9471
|
|
|
9312
9472
|
// ../../../node_modules/zod/v4/locales/ru.js
|
|
9313
|
-
function getRussianPlural(
|
|
9314
|
-
const absCount = Math.abs(
|
|
9473
|
+
function getRussianPlural(count3, one, few, many) {
|
|
9474
|
+
const absCount = Math.abs(count3);
|
|
9315
9475
|
const lastDigit = absCount % 10;
|
|
9316
9476
|
const lastTwoDigits = absCount % 100;
|
|
9317
9477
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -14566,13 +14726,13 @@ function resolveRef(ref, ctx) {
|
|
|
14566
14726
|
if (!ref.startsWith("#")) {
|
|
14567
14727
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14568
14728
|
}
|
|
14569
|
-
const
|
|
14570
|
-
if (
|
|
14729
|
+
const path16 = ref.slice(1).split("/").filter(Boolean);
|
|
14730
|
+
if (path16.length === 0) {
|
|
14571
14731
|
return ctx.rootSchema;
|
|
14572
14732
|
}
|
|
14573
14733
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14574
|
-
if (
|
|
14575
|
-
const key =
|
|
14734
|
+
if (path16[0] === defsKey) {
|
|
14735
|
+
const key = path16[1];
|
|
14576
14736
|
if (!key || !ctx.defs[key]) {
|
|
14577
14737
|
throw new Error(`Reference not found: ${ref}`);
|
|
14578
14738
|
}
|
|
@@ -16663,17 +16823,17 @@ function isResponseMessage(value) {
|
|
|
16663
16823
|
function isNotificationMessage(value) {
|
|
16664
16824
|
return isJsonRpcEnvelope(value) && !("id" in value) && typeof value["method"] === "string";
|
|
16665
16825
|
}
|
|
16666
|
-
function
|
|
16826
|
+
function isRecord2(value) {
|
|
16667
16827
|
return typeof value === "object" && value !== null;
|
|
16668
16828
|
}
|
|
16669
16829
|
function isJsonRpcEnvelope(value) {
|
|
16670
|
-
return
|
|
16830
|
+
return isRecord2(value) && value["jsonrpc"] === "2.0";
|
|
16671
16831
|
}
|
|
16672
16832
|
function isJsonRpcId(value) {
|
|
16673
16833
|
return value === null || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
16674
16834
|
}
|
|
16675
16835
|
function isResponseShapedMessage(value) {
|
|
16676
|
-
return
|
|
16836
|
+
return isRecord2(value) && !("method" in value) && ("id" in value || "result" in value || "error" in value);
|
|
16677
16837
|
}
|
|
16678
16838
|
function isResponseBatch(batch) {
|
|
16679
16839
|
let hasValidCall = false;
|
|
@@ -16683,7 +16843,7 @@ function isResponseBatch(batch) {
|
|
|
16683
16843
|
for (const entry of batch) {
|
|
16684
16844
|
hasValidCall ||= isRequestMessage(entry) || isNotificationMessage(entry);
|
|
16685
16845
|
hasValidResponse ||= isResponseMessage(entry);
|
|
16686
|
-
if (!
|
|
16846
|
+
if (!isRecord2(entry)) {
|
|
16687
16847
|
continue;
|
|
16688
16848
|
}
|
|
16689
16849
|
hasCallShape ||= "method" in entry;
|
|
@@ -16698,13 +16858,13 @@ function isResponseBatch(batch) {
|
|
|
16698
16858
|
return hasResponseShape && !hasCallShape;
|
|
16699
16859
|
}
|
|
16700
16860
|
function cancelRequestId(params) {
|
|
16701
|
-
if (!
|
|
16861
|
+
if (!isRecord2(params) || !isJsonRpcId(params["requestId"])) {
|
|
16702
16862
|
return void 0;
|
|
16703
16863
|
}
|
|
16704
16864
|
return params["requestId"];
|
|
16705
16865
|
}
|
|
16706
16866
|
function isErrorResponse(value) {
|
|
16707
|
-
return
|
|
16867
|
+
return isRecord2(value) && typeof value["code"] === "number" && Number.isInteger(value["code"]) && typeof value["message"] === "string";
|
|
16708
16868
|
}
|
|
16709
16869
|
var Handled = {
|
|
16710
16870
|
/**
|
|
@@ -17195,7 +17355,7 @@ var Connection = class {
|
|
|
17195
17355
|
this.receiveBatch(message);
|
|
17196
17356
|
return;
|
|
17197
17357
|
}
|
|
17198
|
-
if (!
|
|
17358
|
+
if (!isRecord2(message)) {
|
|
17199
17359
|
console.error("Invalid message", { message });
|
|
17200
17360
|
return;
|
|
17201
17361
|
}
|
|
@@ -17212,9 +17372,9 @@ var Connection = class {
|
|
|
17212
17372
|
return;
|
|
17213
17373
|
}
|
|
17214
17374
|
const responseBatch = isResponseBatch(batch);
|
|
17215
|
-
const responseCount = responseBatch ? 0 : batch.reduce((
|
|
17375
|
+
const responseCount = responseBatch ? 0 : batch.reduce((count3, message) => count3 + (isNotificationMessage(message) ? 0 : 1), 0);
|
|
17216
17376
|
let remaining = responseCount;
|
|
17217
|
-
let remainingNotifications = batch.reduce((
|
|
17377
|
+
let remainingNotifications = batch.reduce((count3, message) => count3 + (isNotificationMessage(message) ? 1 : 0), 0);
|
|
17218
17378
|
let responseSent = false;
|
|
17219
17379
|
const responses = [];
|
|
17220
17380
|
const sendResponsesIfReady = async () => {
|
|
@@ -17258,7 +17418,7 @@ var Connection = class {
|
|
|
17258
17418
|
if (this.abortController.signal.aborted) {
|
|
17259
17419
|
return Promise.resolve();
|
|
17260
17420
|
}
|
|
17261
|
-
if (!
|
|
17421
|
+
if (!isRecord2(message)) {
|
|
17262
17422
|
console.error("Invalid message", { message });
|
|
17263
17423
|
return Promise.resolve();
|
|
17264
17424
|
}
|
|
@@ -17628,7 +17788,7 @@ function ndJsonStream(output, input) {
|
|
|
17628
17788
|
if (trimmedLine) {
|
|
17629
17789
|
try {
|
|
17630
17790
|
const message = JSON.parse(trimmedLine);
|
|
17631
|
-
if (
|
|
17791
|
+
if (isRecord2(message) || Array.isArray(message)) {
|
|
17632
17792
|
controller.enqueue(message);
|
|
17633
17793
|
} else {
|
|
17634
17794
|
console.warn("Skipping JSON line that is not an object:", trimmedLine);
|
|
@@ -19089,6 +19249,15 @@ var ClientSideConnection = class {
|
|
|
19089
19249
|
}
|
|
19090
19250
|
};
|
|
19091
19251
|
|
|
19252
|
+
// ../../shared-contracts/dist/delegation-read.js
|
|
19253
|
+
var REMOTE_THREAD_REPLY_MAX_BYTES = 16 * 1024 * 1024;
|
|
19254
|
+
var delegationReadParamsSchema = external_exports.strictObject({
|
|
19255
|
+
threadId: external_exports.string().min(1).max(1024),
|
|
19256
|
+
view: external_exports.enum(["result", "messages"]),
|
|
19257
|
+
cursor: external_exports.string().min(1).max(8192).optional(),
|
|
19258
|
+
limit: external_exports.number().int().min(1).max(100).optional()
|
|
19259
|
+
});
|
|
19260
|
+
|
|
19092
19261
|
// ../../shared-contracts/dist/credential-imports.js
|
|
19093
19262
|
var credentialSourceSchema = external_exports.object({
|
|
19094
19263
|
id: external_exports.string().min(1).max(256),
|
|
@@ -19159,6 +19328,153 @@ var harnessDisplaySetSchema = external_exports.strictObject({
|
|
|
19159
19328
|
initializeOnly: external_exports.boolean().optional()
|
|
19160
19329
|
});
|
|
19161
19330
|
|
|
19331
|
+
// ../../shared-contracts/dist/model-price-overrides.js
|
|
19332
|
+
var usdPerMillionTokens = external_exports.number().finite().nonnegative();
|
|
19333
|
+
var modelPriceOverrideSchema = external_exports.strictObject({
|
|
19334
|
+
input: usdPerMillionTokens,
|
|
19335
|
+
output: usdPerMillionTokens,
|
|
19336
|
+
cacheRead: usdPerMillionTokens.optional(),
|
|
19337
|
+
cacheWrite: usdPerMillionTokens.optional(),
|
|
19338
|
+
cacheWrite1h: usdPerMillionTokens.optional()
|
|
19339
|
+
});
|
|
19340
|
+
var modelPriceKeySchema = external_exports.string().max(512).refine((key) => key.trim() === key && key.length > 0, "Model ID is required");
|
|
19341
|
+
var modelPriceOverridesSchema = external_exports.strictObject({
|
|
19342
|
+
/** Absolute path of the Host's `pricing.json`. */
|
|
19343
|
+
path: external_exports.string(),
|
|
19344
|
+
entries: external_exports.array(external_exports.strictObject({ key: external_exports.string(), price: modelPriceOverrideSchema })),
|
|
19345
|
+
/** Why the existing file is unusable; the Host then ignores it and refuses to overwrite it. */
|
|
19346
|
+
error: external_exports.string().nullable()
|
|
19347
|
+
});
|
|
19348
|
+
var modelPriceOverridesGetSchema = external_exports.strictObject({});
|
|
19349
|
+
var modelPriceOverridesSetSchema = external_exports.strictObject({
|
|
19350
|
+
key: modelPriceKeySchema,
|
|
19351
|
+
price: modelPriceOverrideSchema.nullable(),
|
|
19352
|
+
previousKey: modelPriceKeySchema.optional()
|
|
19353
|
+
});
|
|
19354
|
+
var modelPriceDefaultParamsSchema = external_exports.strictObject({
|
|
19355
|
+
model: modelPriceKeySchema
|
|
19356
|
+
});
|
|
19357
|
+
var modelPriceSuggestionSchema = external_exports.strictObject({
|
|
19358
|
+
/** Verified from catalog canonical links, not inferred from names or equal prices. */
|
|
19359
|
+
official: external_exports.boolean().optional(),
|
|
19360
|
+
canonicalModelId: external_exports.string().min(1).optional(),
|
|
19361
|
+
provider: external_exports.string().min(1).max(512),
|
|
19362
|
+
model: external_exports.string().min(1).max(512),
|
|
19363
|
+
price: modelPriceOverrideSchema
|
|
19364
|
+
});
|
|
19365
|
+
var modelPriceDefaultResultSchema = external_exports.strictObject({
|
|
19366
|
+
price: modelPriceOverrideSchema.nullable(),
|
|
19367
|
+
/** Local catalog suggestions only; never used automatically for pricing. */
|
|
19368
|
+
suggestions: external_exports.array(modelPriceSuggestionSchema).max(6).optional()
|
|
19369
|
+
});
|
|
19370
|
+
|
|
19371
|
+
// ../../shared-contracts/dist/usage-statistics.js
|
|
19372
|
+
var USAGE_STATISTICS_RANGES = ["today", "7d", "30d", "90d", "all"];
|
|
19373
|
+
var count2 = external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
19374
|
+
var localDate = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/u);
|
|
19375
|
+
var harness = external_exports.string().min(1).max(128);
|
|
19376
|
+
var model = external_exports.string().min(1).max(512);
|
|
19377
|
+
var project = external_exports.string().min(1).max(4096);
|
|
19378
|
+
var usageStatisticsParamsSchema = external_exports.strictObject({
|
|
19379
|
+
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
19380
|
+
harness: harness.optional(),
|
|
19381
|
+
model: model.nullable().optional(),
|
|
19382
|
+
project: project.nullable().optional(),
|
|
19383
|
+
/** One local date inside the range. */
|
|
19384
|
+
date: localDate.optional()
|
|
19385
|
+
});
|
|
19386
|
+
var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
19387
|
+
requests: count2,
|
|
19388
|
+
inputTokens: count2,
|
|
19389
|
+
cachedInputTokens: count2,
|
|
19390
|
+
cacheWriteInputTokens: count2,
|
|
19391
|
+
cacheKnownInputTokens: count2,
|
|
19392
|
+
outputTokens: count2,
|
|
19393
|
+
reasoningOutputTokens: count2,
|
|
19394
|
+
/** USD at the public price, summed over the priced requests only. */
|
|
19395
|
+
costUsd: external_exports.number().finite().min(0),
|
|
19396
|
+
/** Requests without a price (or the cache data the price needs); not in `costUsd`. */
|
|
19397
|
+
unpricedRequests: count2,
|
|
19398
|
+
/**
|
|
19399
|
+
* Requests whose storage gave no token counts: counted as requests, with neither tokens nor
|
|
19400
|
+
* cost, and not as unpriced.
|
|
19401
|
+
*/
|
|
19402
|
+
unmeteredRequests: count2
|
|
19403
|
+
});
|
|
19404
|
+
var totals = usageStatisticsTotalsSchema.shape;
|
|
19405
|
+
var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
19406
|
+
harness,
|
|
19407
|
+
sessionId: external_exports.string().min(1).max(512),
|
|
19408
|
+
project: project.nullable(),
|
|
19409
|
+
/** Models the session used, most requests first. */
|
|
19410
|
+
models: external_exports.array(model).max(16),
|
|
19411
|
+
firstAtMs: count2,
|
|
19412
|
+
lastAtMs: count2,
|
|
19413
|
+
...totals
|
|
19414
|
+
});
|
|
19415
|
+
var usageStatisticsResultSchema = external_exports.strictObject({
|
|
19416
|
+
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
19417
|
+
/** First local date of the range; null for all time. */
|
|
19418
|
+
from: localDate.nullable(),
|
|
19419
|
+
to: localDate,
|
|
19420
|
+
/** The filters these figures apply, echoed so a late answer to older filters is recognised. */
|
|
19421
|
+
filters: external_exports.strictObject({
|
|
19422
|
+
harness: harness.nullable(),
|
|
19423
|
+
model: model.nullable(),
|
|
19424
|
+
unknownModel: external_exports.boolean(),
|
|
19425
|
+
project: project.nullable(),
|
|
19426
|
+
unknownProject: external_exports.boolean(),
|
|
19427
|
+
date: localDate.nullable()
|
|
19428
|
+
}),
|
|
19429
|
+
/** Reading of native storage: incomplete while the first read, or a refresh, is under way. */
|
|
19430
|
+
reading: external_exports.strictObject({ complete: external_exports.boolean(), sources: count2, read: count2 }),
|
|
19431
|
+
/** Harnesses whose storage could not be read; their part is missing, the rest is complete. */
|
|
19432
|
+
failures: external_exports.array(external_exports.strictObject({ harness, message: external_exports.string().max(2048) })).max(256),
|
|
19433
|
+
/** Every value seen in the range, ignoring the filters, to choose filters from. */
|
|
19434
|
+
options: external_exports.strictObject({
|
|
19435
|
+
harnesses: external_exports.array(harness).max(256),
|
|
19436
|
+
models: external_exports.array(model.nullable()).max(4096),
|
|
19437
|
+
projects: external_exports.array(project.nullable()).max(4096)
|
|
19438
|
+
}),
|
|
19439
|
+
/** Current display metadata, scoped by Harness. Never a pricing or filter identity.
|
|
19440
|
+
* Optional for older Hosts; missing/conflicting labels fall back to the native model ID.
|
|
19441
|
+
*/
|
|
19442
|
+
modelLabels: external_exports.array(external_exports.strictObject({ harness, model, label: model })).max(4096).optional(),
|
|
19443
|
+
/** Native credits, all filters applied, never combined across Harnesses or treated as USD.
|
|
19444
|
+
* Only groups with at least one reported value appear; reportedRequests exposes partial data.
|
|
19445
|
+
*/
|
|
19446
|
+
credits: external_exports.array(external_exports.strictObject({
|
|
19447
|
+
harness,
|
|
19448
|
+
model: model.nullable(),
|
|
19449
|
+
credits: external_exports.number().finite().min(0),
|
|
19450
|
+
reportedRequests: count2,
|
|
19451
|
+
requests: count2
|
|
19452
|
+
})).max(4096).optional(),
|
|
19453
|
+
/** All filters applied. */
|
|
19454
|
+
totals: usageStatisticsTotalsSchema,
|
|
19455
|
+
/** Each date and Harness of the range: every filter except the day. */
|
|
19456
|
+
daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
|
|
19457
|
+
/** Local weekday (0 = Sunday) and hour, all filters applied. */
|
|
19458
|
+
hourly: external_exports.array(external_exports.strictObject({
|
|
19459
|
+
weekday: external_exports.number().int().min(0).max(6),
|
|
19460
|
+
hour: external_exports.number().int().min(0).max(23),
|
|
19461
|
+
...totals
|
|
19462
|
+
})).max(168),
|
|
19463
|
+
byHarness: external_exports.array(external_exports.strictObject({ harness, ...totals })).max(256),
|
|
19464
|
+
byModel: external_exports.array(external_exports.strictObject({
|
|
19465
|
+
model: model.nullable(),
|
|
19466
|
+
...totals,
|
|
19467
|
+
/** Requests priced by what the Harness recorded they cost, not by a price list. */
|
|
19468
|
+
harnessPricedRequests: count2
|
|
19469
|
+
})).max(4096),
|
|
19470
|
+
byProject: external_exports.array(external_exports.strictObject({ project: project.nullable(), ...totals })).max(4096),
|
|
19471
|
+
/**
|
|
19472
|
+
* The sessions that spent the most, by cost and by tokens without cache, all filters applied;
|
|
19473
|
+
* requests without a native session are not listed here but count everywhere else.
|
|
19474
|
+
*/
|
|
19475
|
+
sessions: external_exports.array(usageStatisticsSessionSchema).max(100)
|
|
19476
|
+
});
|
|
19477
|
+
|
|
19162
19478
|
// ../../shared-contracts/dist/ids.js
|
|
19163
19479
|
var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
19164
19480
|
message: "Identifier must not be empty or whitespace"
|
|
@@ -19169,6 +19485,10 @@ var hostTurnIdSchema = opaqueIdSchema.brand();
|
|
|
19169
19485
|
var hostItemIdSchema = opaqueIdSchema.brand();
|
|
19170
19486
|
var hostInteractionIdSchema = opaqueIdSchema.brand();
|
|
19171
19487
|
|
|
19488
|
+
// ../../shared-contracts/dist/thread-prewarm.js
|
|
19489
|
+
var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
|
|
19490
|
+
var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
|
|
19491
|
+
|
|
19172
19492
|
// ../../shared-contracts/dist/harness-plugins.js
|
|
19173
19493
|
var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
|
|
19174
19494
|
var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
|
|
@@ -19176,13 +19496,40 @@ var HARNESS_PLUGIN_LIMIT = 128;
|
|
|
19176
19496
|
var harnessPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u).refine((id) => id !== "codex", "The official Codex identity is reserved").pipe(harnessIdSchema);
|
|
19177
19497
|
var relativeResourceSchema = external_exports.string().min(1).max(512).refine((value) => !/[\\\u0000:#?]/u.test(value) && !value.startsWith("/") && !value.split("/").some((part) => part === ".." || part === ""), "Plugin resources must be relative paths inside the plugin");
|
|
19178
19498
|
var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
|
|
19499
|
+
var localizedTextSchema = external_exports.object({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).strict();
|
|
19500
|
+
var harnessInstallationGuideSchema = external_exports.object({
|
|
19501
|
+
commands: external_exports.array(external_exports.object({ terminal: external_exports.string().max(256), command: external_exports.string().max(4096) }).strict()).max(8),
|
|
19502
|
+
before: localizedTextSchema.optional(),
|
|
19503
|
+
after: localizedTextSchema.optional(),
|
|
19504
|
+
downloads: external_exports.array(external_exports.object({ label: external_exports.string().max(128), url: documentationUrlSchema }).strict()).max(8).optional()
|
|
19505
|
+
}).strict();
|
|
19179
19506
|
var pluginPresentationShape = {
|
|
19180
19507
|
id: harnessPluginIdSchema,
|
|
19181
19508
|
name: external_exports.string().trim().min(1).max(128),
|
|
19182
19509
|
version: external_exports.string().min(1).max(128),
|
|
19510
|
+
/** Capability-only plugin; omitted for existing session-capable plugins. */
|
|
19511
|
+
kind: external_exports.literal("usage").optional(),
|
|
19512
|
+
/** Original image styling or bounded vector paths; never arbitrary CSS/SVG markup. */
|
|
19513
|
+
iconStyle: external_exports.object({
|
|
19514
|
+
vector: external_exports.object({
|
|
19515
|
+
viewBox: external_exports.string().max(128).regex(/^-?\d+(?:\.\d+)?(?: +-?\d+(?:\.\d+)?){3}$/u),
|
|
19516
|
+
color: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu),
|
|
19517
|
+
paths: external_exports.array(external_exports.object({
|
|
19518
|
+
d: external_exports.string().min(1).max(32768).regex(/^[MmLlHhVvCcSsQqTtAaZz\d.,+eE\s-]+$/u),
|
|
19519
|
+
fillRule: external_exports.enum(["evenodd", "nonzero"]).optional(),
|
|
19520
|
+
fill: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu).optional()
|
|
19521
|
+
}).strict()).min(1).max(32)
|
|
19522
|
+
}).strict().optional(),
|
|
19523
|
+
background: external_exports.string().regex(/^#[a-f0-9]{6}$/iu).optional(),
|
|
19524
|
+
borderRadius: external_exports.number().min(0).max(50).optional(),
|
|
19525
|
+
paddingRatio: external_exports.number().min(0).max(0.25).optional()
|
|
19526
|
+
}).strict().optional(),
|
|
19527
|
+
installation: harnessInstallationGuideSchema.optional(),
|
|
19528
|
+
notice: localizedTextSchema.optional(),
|
|
19183
19529
|
/** The factory accepts a persisted local entrypoint through its construction context. */
|
|
19184
19530
|
launchCommand: external_exports.literal(true).optional(),
|
|
19185
19531
|
links: external_exports.object({
|
|
19532
|
+
website: documentationUrlSchema.optional(),
|
|
19186
19533
|
documentation: documentationUrlSchema.optional(),
|
|
19187
19534
|
installation: documentationUrlSchema.optional()
|
|
19188
19535
|
}).strict().optional()
|
|
@@ -19236,6 +19583,9 @@ var consoleOpenResultSchema = external_exports.strictObject({
|
|
|
19236
19583
|
url: external_exports.string().max(2048).regex(/^http:\/\/(?:127\.0\.0\.1|localhost):\d{1,5}\/(?:\?.*)?$/u)
|
|
19237
19584
|
});
|
|
19238
19585
|
var CONSOLE_HOST_METHODS = Object.freeze([
|
|
19586
|
+
"codexhost/console/remote-connections",
|
|
19587
|
+
"codexhost/runtime/status",
|
|
19588
|
+
"codexhost/remote/ssh-setup",
|
|
19239
19589
|
"codexhost/harness/plugins/list",
|
|
19240
19590
|
"codexhost/harness/display-settings/get",
|
|
19241
19591
|
"codexhost/harness/display-settings/set",
|
|
@@ -19256,6 +19606,10 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
19256
19606
|
"codexhost/account/list",
|
|
19257
19607
|
"codexhost/account/refresh",
|
|
19258
19608
|
"codexhost/account/usage/inspect",
|
|
19609
|
+
"codexhost/usage/model-prices/get",
|
|
19610
|
+
"codexhost/usage/model-prices/set",
|
|
19611
|
+
"codexhost/usage/model-prices/default",
|
|
19612
|
+
"codexhost/usage/statistics/get",
|
|
19259
19613
|
"codexhost/update/check",
|
|
19260
19614
|
"codexhost/update/start",
|
|
19261
19615
|
"codexhost/update/status"
|
|
@@ -19320,6 +19674,7 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
19320
19674
|
cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
19321
19675
|
outputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
19322
19676
|
outputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
19677
|
+
apiOutputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
19323
19678
|
reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
19324
19679
|
totalTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
19325
19680
|
totalCostUsd: finiteNonNegativeNumberSchema.optional(),
|
|
@@ -19331,7 +19686,11 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
19331
19686
|
planFiveHourUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
19332
19687
|
planFiveHourResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
19333
19688
|
planSevenDayUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
19334
|
-
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional()
|
|
19689
|
+
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
19690
|
+
sessionCacheHitRatePercent: cacheHitRatePercentSchema.optional(),
|
|
19691
|
+
timeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
|
|
19692
|
+
costSource: external_exports.enum(["publicPrice", "native"]).optional(),
|
|
19693
|
+
unpricedModels: external_exports.array(external_exports.string().min(1)).min(1).optional()
|
|
19335
19694
|
}).strict().superRefine((usage, context) => {
|
|
19336
19695
|
if (Object.keys(usage).length === 0) {
|
|
19337
19696
|
context.addIssue({ code: "custom", message: "Thread Usage must contain a reliable field" });
|
|
@@ -19352,6 +19711,20 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
19352
19711
|
path: ["contextWindowTokens"]
|
|
19353
19712
|
});
|
|
19354
19713
|
}
|
|
19714
|
+
if (usage.costSource !== void 0 && usage.totalCostUsd === void 0) {
|
|
19715
|
+
context.addIssue({
|
|
19716
|
+
code: "custom",
|
|
19717
|
+
message: "Thread Usage costSource must be provided with totalCostUsd",
|
|
19718
|
+
path: ["costSource"]
|
|
19719
|
+
});
|
|
19720
|
+
}
|
|
19721
|
+
if (usage.unpricedModels !== void 0 && usage.costSource !== "publicPrice") {
|
|
19722
|
+
context.addIssue({
|
|
19723
|
+
code: "custom",
|
|
19724
|
+
message: "Thread Usage unpricedModels must be provided with a publicPrice cost",
|
|
19725
|
+
path: ["unpricedModels"]
|
|
19726
|
+
});
|
|
19727
|
+
}
|
|
19355
19728
|
if (usage.planFiveHourResetsAtUnix !== void 0 && usage.planFiveHourUsedPercent === void 0) {
|
|
19356
19729
|
context.addIssue({
|
|
19357
19730
|
code: "custom",
|
|
@@ -19621,27 +19994,27 @@ var harnessModelCatalogSchema = external_exports.object({
|
|
|
19621
19994
|
}).strict().superRefine((catalog, context) => {
|
|
19622
19995
|
const refs = /* @__PURE__ */ new Set();
|
|
19623
19996
|
const thinkingIds = new Set(catalog.thinkingOptions.map(({ id }) => id));
|
|
19624
|
-
for (const [index,
|
|
19625
|
-
if (refs.has(
|
|
19997
|
+
for (const [index, model2] of catalog.models.entries()) {
|
|
19998
|
+
if (refs.has(model2.ref.id)) {
|
|
19626
19999
|
context.addIssue({
|
|
19627
20000
|
code: "custom",
|
|
19628
20001
|
message: "Model Catalog refs must be unique",
|
|
19629
20002
|
path: ["models", index, "ref", "id"]
|
|
19630
20003
|
});
|
|
19631
20004
|
}
|
|
19632
|
-
refs.add(
|
|
19633
|
-
if (
|
|
19634
|
-
if (refs.has(
|
|
20005
|
+
refs.add(model2.ref.id);
|
|
20006
|
+
if (model2.fastModel) {
|
|
20007
|
+
if (refs.has(model2.fastModel.id) || catalog.models.some((entry) => entry.ref.id === model2.fastModel?.id)) {
|
|
19635
20008
|
context.addIssue({
|
|
19636
20009
|
code: "custom",
|
|
19637
20010
|
message: "Fast Model refs must be distinct and unique",
|
|
19638
20011
|
path: ["models", index, "fastModel"]
|
|
19639
20012
|
});
|
|
19640
20013
|
}
|
|
19641
|
-
refs.add(
|
|
20014
|
+
refs.add(model2.fastModel.id);
|
|
19642
20015
|
}
|
|
19643
20016
|
const supportedThinkingIds = /* @__PURE__ */ new Set();
|
|
19644
|
-
for (const [optionIndex, optionId] of (
|
|
20017
|
+
for (const [optionIndex, optionId] of (model2.supportedThinkingOptionIds ?? []).entries()) {
|
|
19645
20018
|
if (supportedThinkingIds.has(optionId)) {
|
|
19646
20019
|
context.addIssue({
|
|
19647
20020
|
code: "custom",
|
|
@@ -20181,6 +20554,85 @@ var updateStatusResultSchema = external_exports.strictObject({
|
|
|
20181
20554
|
status: updateStatusSchema.nullable()
|
|
20182
20555
|
});
|
|
20183
20556
|
|
|
20557
|
+
// ../../shared-contracts/dist/remote-runtime.js
|
|
20558
|
+
var remoteUpdatePhaseSchema = external_exports.enum([
|
|
20559
|
+
"idle",
|
|
20560
|
+
"installing",
|
|
20561
|
+
"restarting",
|
|
20562
|
+
"succeeded",
|
|
20563
|
+
"failed"
|
|
20564
|
+
]);
|
|
20565
|
+
var runtimeStatusSchema = external_exports.object({
|
|
20566
|
+
runningVersion: external_exports.string().nullable(),
|
|
20567
|
+
installedVersion: external_exports.string().nullable(),
|
|
20568
|
+
restartRequired: external_exports.boolean(),
|
|
20569
|
+
remote: external_exports.boolean(),
|
|
20570
|
+
updateSupported: external_exports.boolean(),
|
|
20571
|
+
update: external_exports.object({
|
|
20572
|
+
phase: remoteUpdatePhaseSchema,
|
|
20573
|
+
targetVersion: external_exports.string().nullable(),
|
|
20574
|
+
error: external_exports.string().nullable()
|
|
20575
|
+
})
|
|
20576
|
+
});
|
|
20577
|
+
var remoteUpdateParamsSchema = external_exports.object({
|
|
20578
|
+
version: external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u)
|
|
20579
|
+
}).strict();
|
|
20580
|
+
var remoteSshSetupParamsSchema = external_exports.object({
|
|
20581
|
+
hostname: external_exports.string().min(1).max(1024).refine((value) => !value.startsWith("-") && !/\s/u.test(value)),
|
|
20582
|
+
port: external_exports.number().int().min(1).max(65535).nullable(),
|
|
20583
|
+
identity: external_exports.string().max(4096).nullable(),
|
|
20584
|
+
action: external_exports.enum(["inspect", "install", "update", "repair", "uninstall"]),
|
|
20585
|
+
uninstallPackage: external_exports.boolean().optional(),
|
|
20586
|
+
version: external_exports.string().regex(/^\d+\.\d+\.\d+$/u).nullable()
|
|
20587
|
+
}).strict();
|
|
20588
|
+
var remoteSshSetupResultSchema = external_exports.object({ state: external_exports.enum(["installed", "not-installed"]) }).strict();
|
|
20589
|
+
|
|
20590
|
+
// ../../shared-contracts/dist/remote-connections.js
|
|
20591
|
+
var hostId = external_exports.string().min(1).max(1024);
|
|
20592
|
+
var codexSshConnectionSchema = external_exports.object({
|
|
20593
|
+
hostId,
|
|
20594
|
+
displayName: external_exports.string().min(1).max(1024),
|
|
20595
|
+
source: external_exports.enum(["codex-managed", "discovered"]),
|
|
20596
|
+
sshAlias: external_exports.string().max(1024).nullable(),
|
|
20597
|
+
sshHost: external_exports.string().min(1).max(1024),
|
|
20598
|
+
sshPort: external_exports.number().int().min(1).max(65535).nullable(),
|
|
20599
|
+
identity: external_exports.string().max(4096).nullable(),
|
|
20600
|
+
autoConnect: external_exports.boolean(),
|
|
20601
|
+
connectionAnalyticsId: external_exports.string().max(1024).optional()
|
|
20602
|
+
});
|
|
20603
|
+
var codexSshDraftSchema = external_exports.strictObject({
|
|
20604
|
+
displayName: external_exports.string().min(1).max(1024),
|
|
20605
|
+
hostname: external_exports.string().min(1).max(1024),
|
|
20606
|
+
sshPort: external_exports.number().int().min(1).max(65535).nullable(),
|
|
20607
|
+
identity: external_exports.string().max(4096).nullable()
|
|
20608
|
+
});
|
|
20609
|
+
var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
|
|
20610
|
+
external_exports.strictObject({ action: external_exports.literal("list") }),
|
|
20611
|
+
external_exports.strictObject({
|
|
20612
|
+
action: external_exports.literal("read-thread"),
|
|
20613
|
+
hostId: hostId.refine((id) => id !== "local"),
|
|
20614
|
+
input: delegationReadParamsSchema
|
|
20615
|
+
}),
|
|
20616
|
+
external_exports.strictObject({
|
|
20617
|
+
action: external_exports.literal("save"),
|
|
20618
|
+
draft: codexSshDraftSchema,
|
|
20619
|
+
previous: codexSshConnectionSchema.nullable()
|
|
20620
|
+
}),
|
|
20621
|
+
external_exports.strictObject({ action: external_exports.literal("remove"), previous: codexSshConnectionSchema }),
|
|
20622
|
+
external_exports.strictObject({ action: external_exports.literal("connect"), hostId, enabled: external_exports.boolean() }),
|
|
20623
|
+
external_exports.strictObject({ action: external_exports.literal("state"), hostId }),
|
|
20624
|
+
external_exports.strictObject({ action: external_exports.literal("runtime"), hostId }),
|
|
20625
|
+
external_exports.strictObject({
|
|
20626
|
+
action: external_exports.literal("update"),
|
|
20627
|
+
hostId: hostId.refine((id) => id !== "local"),
|
|
20628
|
+
version: remoteUpdateParamsSchema.shape.version
|
|
20629
|
+
})
|
|
20630
|
+
]);
|
|
20631
|
+
var remoteConnectionsReplySchema = external_exports.union([
|
|
20632
|
+
external_exports.strictObject({ result: jsonValueSchema }),
|
|
20633
|
+
external_exports.strictObject({ error: external_exports.strictObject({ code: external_exports.number().int(), message: external_exports.string() }) })
|
|
20634
|
+
]);
|
|
20635
|
+
|
|
20184
20636
|
// ../../shared-contracts/dist/index.js
|
|
20185
20637
|
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
20186
20638
|
|
|
@@ -20292,7 +20744,6 @@ var tokenFields = [
|
|
|
20292
20744
|
"cachedInputTokens",
|
|
20293
20745
|
"cacheWriteInputTokens",
|
|
20294
20746
|
"outputTokens",
|
|
20295
|
-
"outputTokensPerSecond",
|
|
20296
20747
|
"reasoningOutputTokens",
|
|
20297
20748
|
"totalTokens",
|
|
20298
20749
|
"contextWindowTokens",
|
|
@@ -20300,10 +20751,12 @@ var tokenFields = [
|
|
|
20300
20751
|
];
|
|
20301
20752
|
var safeIntegerFields = [
|
|
20302
20753
|
"planFiveHourResetsAtUnix",
|
|
20303
|
-
"planSevenDayResetsAtUnix"
|
|
20754
|
+
"planSevenDayResetsAtUnix",
|
|
20755
|
+
"timeToFirstOutputMs"
|
|
20304
20756
|
];
|
|
20305
20757
|
var percentFields = [
|
|
20306
20758
|
"cacheHitRatePercent",
|
|
20759
|
+
"sessionCacheHitRatePercent",
|
|
20307
20760
|
"planFiveHourUsedPercent",
|
|
20308
20761
|
"planSevenDayUsedPercent"
|
|
20309
20762
|
];
|
|
@@ -20311,15 +20764,20 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
20311
20764
|
...tokenFields,
|
|
20312
20765
|
...safeIntegerFields,
|
|
20313
20766
|
...percentFields,
|
|
20767
|
+
"sessionCacheUsage",
|
|
20314
20768
|
"totalCostUsd",
|
|
20315
20769
|
"totalCredits",
|
|
20316
|
-
"contextUsagePercent"
|
|
20770
|
+
"contextUsagePercent",
|
|
20771
|
+
"outputTokensPerSecond",
|
|
20772
|
+
"apiOutputTokensPerSecond",
|
|
20773
|
+
"costSource",
|
|
20774
|
+
"unpricedModels"
|
|
20317
20775
|
]);
|
|
20318
|
-
function
|
|
20776
|
+
function isRecord3(value) {
|
|
20319
20777
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20320
20778
|
}
|
|
20321
20779
|
function parseHostUsage(value) {
|
|
20322
|
-
if (!
|
|
20780
|
+
if (!isRecord3(value))
|
|
20323
20781
|
throw new Error("Harness Usage must be an object");
|
|
20324
20782
|
const keys = Object.keys(value);
|
|
20325
20783
|
if (keys.length === 0)
|
|
@@ -20329,7 +20787,11 @@ function parseHostUsage(value) {
|
|
|
20329
20787
|
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
20330
20788
|
}
|
|
20331
20789
|
}
|
|
20332
|
-
for (const field of [
|
|
20790
|
+
for (const field of [
|
|
20791
|
+
"totalCredits",
|
|
20792
|
+
"contextUsagePercent",
|
|
20793
|
+
"apiOutputTokensPerSecond"
|
|
20794
|
+
]) {
|
|
20333
20795
|
const candidate = value[field];
|
|
20334
20796
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
20335
20797
|
throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
|
|
@@ -20365,6 +20827,12 @@ function parseHostUsage(value) {
|
|
|
20365
20827
|
throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
|
|
20366
20828
|
}
|
|
20367
20829
|
}
|
|
20830
|
+
if (value.sessionCacheUsage !== void 0) {
|
|
20831
|
+
const totals2 = value.sessionCacheUsage;
|
|
20832
|
+
if (!isRecord3(totals2) || Object.keys(totals2).some((key) => key !== "inputTokens" && key !== "cachedInputTokens") || typeof totals2.inputTokens !== "number" || !Number.isSafeInteger(totals2.inputTokens) || totals2.inputTokens < 0 || typeof totals2.cachedInputTokens !== "number" || !Number.isSafeInteger(totals2.cachedInputTokens) || totals2.cachedInputTokens < 0 || totals2.cachedInputTokens > totals2.inputTokens) {
|
|
20833
|
+
throw new Error("Harness Usage 'sessionCacheUsage' must contain complete bounded token totals");
|
|
20834
|
+
}
|
|
20835
|
+
}
|
|
20368
20836
|
const hasContextUsed = value.contextUsedTokens !== void 0;
|
|
20369
20837
|
const hasContextWindow = value.contextWindowTokens !== void 0;
|
|
20370
20838
|
if (hasContextUsed !== hasContextWindow) {
|
|
@@ -20379,8 +20847,43 @@ function parseHostUsage(value) {
|
|
|
20379
20847
|
if (value.planSevenDayResetsAtUnix !== void 0 && value.planSevenDayUsedPercent === void 0) {
|
|
20380
20848
|
throw new Error("Harness Usage 'planSevenDayResetsAtUnix' must be provided with 'planSevenDayUsedPercent'");
|
|
20381
20849
|
}
|
|
20850
|
+
if (value.costSource !== void 0) {
|
|
20851
|
+
if (value.costSource !== "publicPrice" && value.costSource !== "native") {
|
|
20852
|
+
throw new Error("Harness Usage 'costSource' must be 'publicPrice' or 'native'");
|
|
20853
|
+
}
|
|
20854
|
+
if (value.totalCostUsd === void 0) {
|
|
20855
|
+
throw new Error("Harness Usage 'costSource' must be provided with 'totalCostUsd'");
|
|
20856
|
+
}
|
|
20857
|
+
}
|
|
20858
|
+
if (value.unpricedModels !== void 0) {
|
|
20859
|
+
const models = value.unpricedModels;
|
|
20860
|
+
if (!Array.isArray(models) || models.length === 0 || !models.every((model2) => typeof model2 === "string" && model2.length > 0)) {
|
|
20861
|
+
throw new Error("Harness Usage 'unpricedModels' must be a non-empty list of Model IDs");
|
|
20862
|
+
}
|
|
20863
|
+
if (value.costSource !== "publicPrice") {
|
|
20864
|
+
throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
|
|
20865
|
+
}
|
|
20866
|
+
return { ...value, unpricedModels: [...models] };
|
|
20867
|
+
}
|
|
20382
20868
|
return { ...value };
|
|
20383
20869
|
}
|
|
20870
|
+
var requestTokenFields = [
|
|
20871
|
+
"inputTokens",
|
|
20872
|
+
"cachedInputTokens",
|
|
20873
|
+
"cacheWriteInputTokens",
|
|
20874
|
+
"cacheWrite1hInputTokens",
|
|
20875
|
+
"outputTokens",
|
|
20876
|
+
"reasoningOutputTokens",
|
|
20877
|
+
"startedAtMs",
|
|
20878
|
+
"completedAtMs"
|
|
20879
|
+
];
|
|
20880
|
+
var requestFields = /* @__PURE__ */ new Set([
|
|
20881
|
+
...requestTokenFields,
|
|
20882
|
+
"requestId",
|
|
20883
|
+
"historical",
|
|
20884
|
+
"model",
|
|
20885
|
+
"provider"
|
|
20886
|
+
]);
|
|
20384
20887
|
|
|
20385
20888
|
// ../../harness-adapter/dist/live-command-catalog.js
|
|
20386
20889
|
var COMMON_EXCLUDED_LIVE_COMMANDS = /* @__PURE__ */ new Set([
|
|
@@ -20502,21 +21005,21 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
|
|
|
20502
21005
|
|
|
20503
21006
|
// dist/acp-transport.js
|
|
20504
21007
|
import { spawn, spawnSync } from "node:child_process";
|
|
20505
|
-
import { readdir, readFile as
|
|
20506
|
-
import
|
|
20507
|
-
import
|
|
21008
|
+
import { readdir, readFile as readFile3 } from "node:fs/promises";
|
|
21009
|
+
import os5 from "node:os";
|
|
21010
|
+
import path12 from "node:path";
|
|
20508
21011
|
import { Readable, Writable } from "node:stream";
|
|
20509
21012
|
|
|
20510
21013
|
// dist/grok-slash-commands.js
|
|
20511
21014
|
var GROK_LIVE_COMMAND_ID_PREFIX = "grok.slash.";
|
|
20512
|
-
function
|
|
21015
|
+
function isRecord4(value) {
|
|
20513
21016
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20514
21017
|
}
|
|
20515
21018
|
function parseGrokAvailableCommands(value) {
|
|
20516
21019
|
if (!Array.isArray(value))
|
|
20517
21020
|
return [];
|
|
20518
21021
|
return value.flatMap((entry) => {
|
|
20519
|
-
if (!
|
|
21022
|
+
if (!isRecord4(entry))
|
|
20520
21023
|
return [];
|
|
20521
21024
|
const name = typeof entry.name === "string" ? entry.name.trim().replace(/^\//u, "") : "";
|
|
20522
21025
|
if (!name)
|
|
@@ -20525,14 +21028,14 @@ function parseGrokAvailableCommands(value) {
|
|
|
20525
21028
|
{
|
|
20526
21029
|
name,
|
|
20527
21030
|
description: typeof entry.description === "string" ? entry.description : "",
|
|
20528
|
-
meta:
|
|
21031
|
+
meta: isRecord4(entry._meta) ? entry._meta : null
|
|
20529
21032
|
}
|
|
20530
21033
|
];
|
|
20531
21034
|
});
|
|
20532
21035
|
}
|
|
20533
21036
|
function isGrokSkill(command) {
|
|
20534
|
-
const
|
|
20535
|
-
return typeof
|
|
21037
|
+
const path16 = command.meta?.path;
|
|
21038
|
+
return typeof path16 === "string" && /(^|[\\/])SKILL\.md$/u.test(path16) || typeof command.meta?.qualifiedName === "string";
|
|
20536
21039
|
}
|
|
20537
21040
|
function grokLiveCommands(native) {
|
|
20538
21041
|
return native.map((command) => ({
|
|
@@ -20543,7 +21046,7 @@ function grokLiveCommands(native) {
|
|
|
20543
21046
|
}
|
|
20544
21047
|
|
|
20545
21048
|
// dist/command.js
|
|
20546
|
-
import
|
|
21049
|
+
import path7 from "node:path";
|
|
20547
21050
|
var GrokExecutableError = class extends Error {
|
|
20548
21051
|
code = "GROK_NOT_FOUND";
|
|
20549
21052
|
};
|
|
@@ -20572,7 +21075,7 @@ function resolveGrokExecutable(input = {}) {
|
|
|
20572
21075
|
});
|
|
20573
21076
|
if (!resolution)
|
|
20574
21077
|
throw new GrokExecutableError("Grok CLI is not installed");
|
|
20575
|
-
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable :
|
|
21078
|
+
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path7.resolve(resolution.executable);
|
|
20576
21079
|
}
|
|
20577
21080
|
function grokInvocation(command, platform = process.platform, modelId) {
|
|
20578
21081
|
const arguments_ = ["agent", "--no-leader"];
|
|
@@ -20585,11 +21088,11 @@ function grokInvocation(command, platform = process.platform, modelId) {
|
|
|
20585
21088
|
|
|
20586
21089
|
// dist/grok-fork.js
|
|
20587
21090
|
import { isDeepStrictEqual } from "node:util";
|
|
20588
|
-
import
|
|
21091
|
+
import path10 from "node:path";
|
|
20589
21092
|
|
|
20590
21093
|
// dist/grok-file-change.js
|
|
20591
21094
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
20592
|
-
import
|
|
21095
|
+
import path8 from "node:path";
|
|
20593
21096
|
|
|
20594
21097
|
// ../../../node_modules/diff/libesm/diff/base.js
|
|
20595
21098
|
var Diff = class {
|
|
@@ -20691,16 +21194,16 @@ var Diff = class {
|
|
|
20691
21194
|
}
|
|
20692
21195
|
}
|
|
20693
21196
|
}
|
|
20694
|
-
addToPath(
|
|
20695
|
-
const last =
|
|
21197
|
+
addToPath(path16, added, removed, oldPosInc, options) {
|
|
21198
|
+
const last = path16.lastComponent;
|
|
20696
21199
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
20697
21200
|
return {
|
|
20698
|
-
oldPos:
|
|
21201
|
+
oldPos: path16.oldPos + oldPosInc,
|
|
20699
21202
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
20700
21203
|
};
|
|
20701
21204
|
} else {
|
|
20702
21205
|
return {
|
|
20703
|
-
oldPos:
|
|
21206
|
+
oldPos: path16.oldPos + oldPosInc,
|
|
20704
21207
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
20705
21208
|
};
|
|
20706
21209
|
}
|
|
@@ -21009,17 +21512,17 @@ function splitLines(text) {
|
|
|
21009
21512
|
// dist/grok-file-change.js
|
|
21010
21513
|
var DEFAULT_GROK_FILE_CHANGE_TEXT_LIMIT = 4 * 1024 * 1024;
|
|
21011
21514
|
var MAX_GROK_FILE_CHANGES_PER_TOOL = 32;
|
|
21012
|
-
function
|
|
21515
|
+
function isRecord5(value) {
|
|
21013
21516
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21014
21517
|
}
|
|
21015
21518
|
function validAbsolutePath(value) {
|
|
21016
|
-
return typeof value === "string" &&
|
|
21519
|
+
return typeof value === "string" && path8.isAbsolute(value) && value.trim().length > 0 && !value.includes("\0") && !value.includes("\n") && !value.includes("\r");
|
|
21017
21520
|
}
|
|
21018
21521
|
function displayPath(nativePath, cwd) {
|
|
21019
|
-
const resolvedCwd =
|
|
21020
|
-
const resolvedPath =
|
|
21021
|
-
const relative =
|
|
21022
|
-
const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${
|
|
21522
|
+
const resolvedCwd = path8.resolve(cwd);
|
|
21523
|
+
const resolvedPath = path8.resolve(nativePath);
|
|
21524
|
+
const relative = path8.relative(resolvedCwd, resolvedPath);
|
|
21525
|
+
const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path8.sep}`);
|
|
21023
21526
|
const selected = inside ? relative : resolvedPath;
|
|
21024
21527
|
const normalized = selected.replaceAll("\\", "/");
|
|
21025
21528
|
if (normalized.length === 0 || normalized === ".")
|
|
@@ -21060,7 +21563,7 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
|
|
|
21060
21563
|
return null;
|
|
21061
21564
|
const candidates = [];
|
|
21062
21565
|
for (const entry of content) {
|
|
21063
|
-
if (
|
|
21566
|
+
if (isRecord5(entry) && entry.type === "diff")
|
|
21064
21567
|
candidates.push(entry);
|
|
21065
21568
|
}
|
|
21066
21569
|
if (candidates.length === 0 || candidates.length > MAX_GROK_FILE_CHANGES_PER_TOOL)
|
|
@@ -21081,8 +21584,8 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
|
|
|
21081
21584
|
|
|
21082
21585
|
// dist/local-media-markdown.js
|
|
21083
21586
|
import { existsSync, statSync } from "node:fs";
|
|
21084
|
-
import
|
|
21085
|
-
import
|
|
21587
|
+
import os4 from "node:os";
|
|
21588
|
+
import path9 from "node:path";
|
|
21086
21589
|
var MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
21087
21590
|
".aac",
|
|
21088
21591
|
".gif",
|
|
@@ -21101,14 +21604,14 @@ var MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
21101
21604
|
".webp"
|
|
21102
21605
|
]);
|
|
21103
21606
|
function grokMediaResolveRoots(cwd, sessionDirectory) {
|
|
21104
|
-
const roots = [
|
|
21607
|
+
const roots = [path9.resolve(cwd)];
|
|
21105
21608
|
if (sessionDirectory) {
|
|
21106
|
-
const session =
|
|
21107
|
-
roots.push(session,
|
|
21609
|
+
const session = path9.resolve(sessionDirectory);
|
|
21610
|
+
roots.push(session, path9.join(session, "videos"), path9.join(session, "images"));
|
|
21108
21611
|
}
|
|
21109
|
-
const home = process.env.HOME ?? process.env.USERPROFILE ??
|
|
21612
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? os4.homedir();
|
|
21110
21613
|
if (home)
|
|
21111
|
-
roots.push(
|
|
21614
|
+
roots.push(path9.join(home, "Downloads"));
|
|
21112
21615
|
return roots;
|
|
21113
21616
|
}
|
|
21114
21617
|
function rewriteLocalMediaMarkdown(text, roots, options = {}) {
|
|
@@ -21209,7 +21712,7 @@ function parseInlineCode(text, start) {
|
|
|
21209
21712
|
return { closed: false, content: text.slice(start + 1), end: text.length };
|
|
21210
21713
|
}
|
|
21211
21714
|
function mediaMarkdownImage(absolutePath) {
|
|
21212
|
-
const name =
|
|
21715
|
+
const name = path9.basename(absolutePath).replaceAll("]", "\\]");
|
|
21213
21716
|
return `})`;
|
|
21214
21717
|
}
|
|
21215
21718
|
function parseMarkdownImage(text, start) {
|
|
@@ -21334,11 +21837,11 @@ function resolveLocalMediaPath(raw, roots, exists = mediaFileExists) {
|
|
|
21334
21837
|
if (!hasMediaExtension(stripped))
|
|
21335
21838
|
return null;
|
|
21336
21839
|
if (isAbsoluteMediaPath(stripped)) {
|
|
21337
|
-
const absolute =
|
|
21840
|
+
const absolute = path9.resolve(stripped);
|
|
21338
21841
|
return exists(absolute) ? absolute : null;
|
|
21339
21842
|
}
|
|
21340
21843
|
for (const root of roots) {
|
|
21341
|
-
const absolute =
|
|
21844
|
+
const absolute = path9.resolve(root, stripped);
|
|
21342
21845
|
if (exists(absolute))
|
|
21343
21846
|
return absolute;
|
|
21344
21847
|
}
|
|
@@ -21360,11 +21863,11 @@ function stripFileUrl(value) {
|
|
|
21360
21863
|
}
|
|
21361
21864
|
}
|
|
21362
21865
|
function isAbsoluteMediaPath(value) {
|
|
21363
|
-
return
|
|
21866
|
+
return path9.isAbsolute(value) || /^[a-zA-Z]:[\\/]/.test(value);
|
|
21364
21867
|
}
|
|
21365
21868
|
function hasMediaExtension(value) {
|
|
21366
21869
|
const pathname = value.split(/[?#]/, 1)[0] ?? value;
|
|
21367
|
-
return MEDIA_EXTENSIONS.has(
|
|
21870
|
+
return MEDIA_EXTENSIONS.has(path9.extname(pathname).toLowerCase());
|
|
21368
21871
|
}
|
|
21369
21872
|
function mediaFileExists(absolutePath) {
|
|
21370
21873
|
try {
|
|
@@ -21377,14 +21880,14 @@ function mediaFileExists(absolutePath) {
|
|
|
21377
21880
|
// dist/grok-tool-output.js
|
|
21378
21881
|
var DEFAULT_GROK_TOOL_OUTPUT_LIMIT = 64e3;
|
|
21379
21882
|
var EXECUTE_TOOL_NAMES = /* @__PURE__ */ new Set(["bash", "run_terminal_command", "shell", "cursor_shell"]);
|
|
21380
|
-
function
|
|
21883
|
+
function isRecord6(value) {
|
|
21381
21884
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21382
21885
|
}
|
|
21383
21886
|
function stringField(value, key) {
|
|
21384
|
-
return
|
|
21887
|
+
return isRecord6(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
|
|
21385
21888
|
}
|
|
21386
21889
|
function numberField(value, key) {
|
|
21387
|
-
if (!
|
|
21890
|
+
if (!isRecord6(value))
|
|
21388
21891
|
return void 0;
|
|
21389
21892
|
const field = value[key];
|
|
21390
21893
|
if (field === null)
|
|
@@ -21407,7 +21910,7 @@ function firstReadableText(...candidates) {
|
|
|
21407
21910
|
for (const candidate of candidates) {
|
|
21408
21911
|
if (typeof candidate === "string" && candidate.length > 0)
|
|
21409
21912
|
return candidate;
|
|
21410
|
-
if (
|
|
21913
|
+
if (isRecord6(candidate)) {
|
|
21411
21914
|
const nested = stringField(candidate, "content") ?? stringField(candidate, "text") ?? stringField(candidate, "tool_result") ?? stringField(candidate, "raw_output");
|
|
21412
21915
|
if (nested)
|
|
21413
21916
|
return nested;
|
|
@@ -21430,7 +21933,7 @@ function grokToolArguments(rawInput) {
|
|
|
21430
21933
|
if (!parsed.success)
|
|
21431
21934
|
return {};
|
|
21432
21935
|
const argumentsValue = parsed.data;
|
|
21433
|
-
if (!
|
|
21936
|
+
if (!isRecord6(argumentsValue) || stringField(argumentsValue, "path"))
|
|
21434
21937
|
return argumentsValue;
|
|
21435
21938
|
const targetFile = stringField(argumentsValue, "target_file");
|
|
21436
21939
|
return targetFile ? { ...argumentsValue, path: targetFile } : argumentsValue;
|
|
@@ -21443,7 +21946,7 @@ function grokCommand(name, kind, rawInput) {
|
|
|
21443
21946
|
return command;
|
|
21444
21947
|
if (name && EXECUTE_TOOL_NAMES.has(name))
|
|
21445
21948
|
return command;
|
|
21446
|
-
return
|
|
21949
|
+
return isRecord6(rawInput) && rawInput.variant === "Bash" ? command : void 0;
|
|
21447
21950
|
}
|
|
21448
21951
|
function grokCommandCwd(rawInput, fallback) {
|
|
21449
21952
|
return stringField(rawInput, "cwd") ?? fallback;
|
|
@@ -21470,11 +21973,11 @@ function acpContentText(content) {
|
|
|
21470
21973
|
if (!Array.isArray(content))
|
|
21471
21974
|
return "";
|
|
21472
21975
|
return content.flatMap((entry) => {
|
|
21473
|
-
if (!
|
|
21976
|
+
if (!isRecord6(entry))
|
|
21474
21977
|
return [];
|
|
21475
21978
|
if (entry.type === "text" && typeof entry.text === "string")
|
|
21476
21979
|
return [entry.text];
|
|
21477
|
-
if (entry.type !== "content" || !
|
|
21980
|
+
if (entry.type !== "content" || !isRecord6(entry.content))
|
|
21478
21981
|
return [];
|
|
21479
21982
|
return entry.content.type === "text" && typeof entry.content.text === "string" ? [entry.content.text] : [];
|
|
21480
21983
|
}).join("\n");
|
|
@@ -21485,10 +21988,10 @@ function acpContentImages(content, remainingBytes) {
|
|
|
21485
21988
|
const images = [];
|
|
21486
21989
|
let remaining = remainingBytes;
|
|
21487
21990
|
for (const entry of content) {
|
|
21488
|
-
if (!
|
|
21991
|
+
if (!isRecord6(entry))
|
|
21489
21992
|
continue;
|
|
21490
21993
|
const image = entry.type === "image" ? entry : entry.type === "content" ? entry.content : null;
|
|
21491
|
-
if (!
|
|
21994
|
+
if (!isRecord6(image) || image.type !== "image")
|
|
21492
21995
|
continue;
|
|
21493
21996
|
const mimeType = stringField(image, "mimeType") ?? stringField(image, "mime_type");
|
|
21494
21997
|
const data = stringField(image, "data");
|
|
@@ -21511,14 +22014,14 @@ function bashOutput(rawOutput) {
|
|
|
21511
22014
|
function rawOutputProjection(rawOutput) {
|
|
21512
22015
|
if (typeof rawOutput === "string")
|
|
21513
22016
|
return rawOutput.length > 0 ? { text: rawOutput } : {};
|
|
21514
|
-
if (!
|
|
22017
|
+
if (!isRecord6(rawOutput))
|
|
21515
22018
|
return {};
|
|
21516
22019
|
if (rawOutput.type === "Bash" || rawOutput.variant === "Bash" || numberField(rawOutput, "exit_code") !== void 0 || numberField(rawOutput, "exitCode") !== void 0) {
|
|
21517
22020
|
const bash = bashOutput(rawOutput);
|
|
21518
22021
|
if (bash.text !== void 0 || bash.exitCode !== void 0)
|
|
21519
22022
|
return bash;
|
|
21520
22023
|
}
|
|
21521
|
-
const text = firstReadableText(rawOutput.content, rawOutput.text, rawOutput.tool_result, rawOutput.raw_output,
|
|
22024
|
+
const text = firstReadableText(rawOutput.content, rawOutput.text, rawOutput.tool_result, rawOutput.raw_output, isRecord6(rawOutput.FileContent) ? rawOutput.FileContent : void 0, isRecord6(rawOutput.Content) ? rawOutput.Content : void 0);
|
|
21522
22025
|
if (text)
|
|
21523
22026
|
return { text };
|
|
21524
22027
|
if (typeof rawOutput.match_count === "number" && Number.isFinite(rawOutput.match_count)) {
|
|
@@ -21582,11 +22085,11 @@ var WAIT_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
21582
22085
|
var KILL_TOOL_NAMES = /* @__PURE__ */ new Set(["kill_command_or_subagent", "kill_task"]);
|
|
21583
22086
|
var DESCRIPTION_LIMIT = 500;
|
|
21584
22087
|
var SUMMARY_LIMIT = 2e3;
|
|
21585
|
-
function
|
|
22088
|
+
function isRecord7(value) {
|
|
21586
22089
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21587
22090
|
}
|
|
21588
22091
|
function idField(value, key) {
|
|
21589
|
-
if (!
|
|
22092
|
+
if (!isRecord7(value))
|
|
21590
22093
|
return void 0;
|
|
21591
22094
|
const field = value[key];
|
|
21592
22095
|
if (typeof field === "string") {
|
|
@@ -21598,7 +22101,7 @@ function idField(value, key) {
|
|
|
21598
22101
|
return void 0;
|
|
21599
22102
|
}
|
|
21600
22103
|
function stringField2(value, key) {
|
|
21601
|
-
if (!
|
|
22104
|
+
if (!isRecord7(value) || typeof value[key] !== "string")
|
|
21602
22105
|
return void 0;
|
|
21603
22106
|
const trimmed = value[key].trim();
|
|
21604
22107
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
@@ -21621,7 +22124,7 @@ function collectIds(value) {
|
|
|
21621
22124
|
};
|
|
21622
22125
|
push(idField(value, "task_id"));
|
|
21623
22126
|
push(idField(value, "subagent_id"));
|
|
21624
|
-
if (
|
|
22127
|
+
if (isRecord7(value)) {
|
|
21625
22128
|
const list = value.task_ids ?? value.subagent_ids;
|
|
21626
22129
|
if (Array.isArray(list)) {
|
|
21627
22130
|
for (const entry of list)
|
|
@@ -21640,7 +22143,7 @@ function grokSubagentOperation(name, title, rawInput) {
|
|
|
21640
22143
|
return "send";
|
|
21641
22144
|
if (SPAWN_TOOL_NAMES.has(id))
|
|
21642
22145
|
return "spawn";
|
|
21643
|
-
if (
|
|
22146
|
+
if (isRecord7(rawInput) && rawInput.variant === "Task")
|
|
21644
22147
|
return "spawn";
|
|
21645
22148
|
return null;
|
|
21646
22149
|
}
|
|
@@ -21663,7 +22166,7 @@ function grokSubagentRole(rawInput) {
|
|
|
21663
22166
|
return bounded(stringField2(rawInput, "subagent_type") ?? stringField2(rawInput, "agent_type") ?? stringField2(rawInput, "type"), DESCRIPTION_LIMIT);
|
|
21664
22167
|
}
|
|
21665
22168
|
function grokSubagentBackground(rawInput) {
|
|
21666
|
-
if (!
|
|
22169
|
+
if (!isRecord7(rawInput))
|
|
21667
22170
|
return true;
|
|
21668
22171
|
if (rawInput.background === false || rawInput.run_in_background === false)
|
|
21669
22172
|
return false;
|
|
@@ -21701,7 +22204,7 @@ function grokSubagentResultSummary(...candidates) {
|
|
|
21701
22204
|
return void 0;
|
|
21702
22205
|
}
|
|
21703
22206
|
function grokSubagentEventFromUpdate(update) {
|
|
21704
|
-
if (!
|
|
22207
|
+
if (!isRecord7(update) || typeof update.sessionUpdate !== "string")
|
|
21705
22208
|
return null;
|
|
21706
22209
|
const nativeSubagentId = idField(update, "subagent_id") ?? idField(update, "child_session_id");
|
|
21707
22210
|
if (!nativeSubagentId)
|
|
@@ -21709,13 +22212,13 @@ function grokSubagentEventFromUpdate(update) {
|
|
|
21709
22212
|
if (update.sessionUpdate === "subagent_spawned") {
|
|
21710
22213
|
const description = bounded(stringField2(update, "description"), DESCRIPTION_LIMIT);
|
|
21711
22214
|
const role = bounded(stringField2(update, "subagent_type") ?? stringField2(update, "role"), DESCRIPTION_LIMIT);
|
|
21712
|
-
const
|
|
22215
|
+
const model2 = bounded(stringField2(update, "model"), DESCRIPTION_LIMIT);
|
|
21713
22216
|
return {
|
|
21714
22217
|
type: "subagent.spawned",
|
|
21715
22218
|
nativeSubagentId,
|
|
21716
22219
|
...description ? { description } : {},
|
|
21717
22220
|
...role ? { role } : {},
|
|
21718
|
-
...
|
|
22221
|
+
...model2 ? { model: model2 } : {}
|
|
21719
22222
|
};
|
|
21720
22223
|
}
|
|
21721
22224
|
if (update.sessionUpdate === "subagent_finished") {
|
|
@@ -21762,14 +22265,14 @@ function grokSubagentWaitSettlements(input) {
|
|
|
21762
22265
|
return ids.map((id) => ({ id, status: overall }));
|
|
21763
22266
|
}
|
|
21764
22267
|
function taskOutputResults(rawOutput) {
|
|
21765
|
-
if (!
|
|
22268
|
+
if (!isRecord7(rawOutput))
|
|
21766
22269
|
return [];
|
|
21767
22270
|
if (Array.isArray(rawOutput.results)) {
|
|
21768
|
-
return rawOutput.results.filter(
|
|
22271
|
+
return rawOutput.results.filter(isRecord7);
|
|
21769
22272
|
}
|
|
21770
22273
|
const nested = firstRecord(rawOutput.MultiResult, rawOutput.multiResult, rawOutput.multi_result);
|
|
21771
22274
|
if (nested && Array.isArray(nested.results)) {
|
|
21772
|
-
return nested.results.filter(
|
|
22275
|
+
return nested.results.filter(isRecord7);
|
|
21773
22276
|
}
|
|
21774
22277
|
const single = firstRecord(rawOutput.Result, rawOutput.result);
|
|
21775
22278
|
if (single)
|
|
@@ -21780,7 +22283,7 @@ function taskOutputResults(rawOutput) {
|
|
|
21780
22283
|
}
|
|
21781
22284
|
function firstRecord(...values) {
|
|
21782
22285
|
for (const value of values) {
|
|
21783
|
-
if (
|
|
22286
|
+
if (isRecord7(value))
|
|
21784
22287
|
return value;
|
|
21785
22288
|
}
|
|
21786
22289
|
return void 0;
|
|
@@ -21803,7 +22306,7 @@ function taskOutputTextSettlements(rawOutput, content, ids) {
|
|
|
21803
22306
|
return settled;
|
|
21804
22307
|
}
|
|
21805
22308
|
function taskOutputStatus(rawOutput, content) {
|
|
21806
|
-
if (
|
|
22309
|
+
if (isRecord7(rawOutput) && typeof rawOutput.status === "string")
|
|
21807
22310
|
return rawOutput.status;
|
|
21808
22311
|
const text = extractText(content) ?? extractText(rawOutput);
|
|
21809
22312
|
if (!text)
|
|
@@ -21862,7 +22365,7 @@ function extractText(value, depth = 0) {
|
|
|
21862
22365
|
const joined = parts.join("\n").trim();
|
|
21863
22366
|
return joined.length > 0 ? joined : void 0;
|
|
21864
22367
|
}
|
|
21865
|
-
if (!
|
|
22368
|
+
if (!isRecord7(value))
|
|
21866
22369
|
return void 0;
|
|
21867
22370
|
if (typeof value.text === "string" && value.text.trim().length > 0)
|
|
21868
22371
|
return value.text.trim();
|
|
@@ -22221,7 +22724,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
22221
22724
|
rememberSubagentAlias(event.callId, nativeSubagentId);
|
|
22222
22725
|
const prompt = grokSubagentPrompt(event.rawInput);
|
|
22223
22726
|
const role = grokSubagentRole(event.rawInput);
|
|
22224
|
-
const
|
|
22727
|
+
const model2 = grokSubagentModel(event.rawInput);
|
|
22225
22728
|
subagents.set(event.callId, {
|
|
22226
22729
|
type: "subagentDelegation",
|
|
22227
22730
|
itemId: stableId("subagent", turnIndex, ++messageIndex),
|
|
@@ -22233,7 +22736,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
22233
22736
|
...nativeSubagentId ? { nativeSubagentId } : {},
|
|
22234
22737
|
description: grokSubagentDescription(event.rawInput, event.title),
|
|
22235
22738
|
...role ? { role } : {},
|
|
22236
|
-
...
|
|
22739
|
+
...model2 ? { model: model2 } : {},
|
|
22237
22740
|
background: grokSubagentBackground(event.rawInput),
|
|
22238
22741
|
status: "running"
|
|
22239
22742
|
}
|
|
@@ -22332,11 +22835,11 @@ var GROK_SESSION_DELETE_METHOD = "_x.ai/session/delete";
|
|
|
22332
22835
|
function error51(code, message, retryable = false) {
|
|
22333
22836
|
return { code, message, retryable };
|
|
22334
22837
|
}
|
|
22335
|
-
function
|
|
22838
|
+
function isRecord8(value) {
|
|
22336
22839
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22337
22840
|
}
|
|
22338
22841
|
function isGrokMethodNotFound(error53) {
|
|
22339
|
-
if (
|
|
22842
|
+
if (isRecord8(error53) && error53.code === -32601)
|
|
22340
22843
|
return true;
|
|
22341
22844
|
const message = error53 instanceof Error ? error53.message : String(error53);
|
|
22342
22845
|
return /method not found/iu.test(message);
|
|
@@ -22354,10 +22857,10 @@ function buildGrokForkParams(input) {
|
|
|
22354
22857
|
};
|
|
22355
22858
|
}
|
|
22356
22859
|
function parseGrokForkResponse(value) {
|
|
22357
|
-
if (!
|
|
22860
|
+
if (!isRecord8(value) || value.error !== void 0)
|
|
22358
22861
|
return null;
|
|
22359
|
-
const payload = typeof value.newSessionId !== "string" &&
|
|
22360
|
-
if (!
|
|
22862
|
+
const payload = typeof value.newSessionId !== "string" && isRecord8(value.result) ? value.result : value;
|
|
22863
|
+
if (!isRecord8(payload) || payload.error !== void 0)
|
|
22361
22864
|
return null;
|
|
22362
22865
|
if (typeof payload.newSessionId !== "string" || payload.newSessionId.length === 0)
|
|
22363
22866
|
return null;
|
|
@@ -22373,11 +22876,11 @@ function parseGrokForkResponse(value) {
|
|
|
22373
22876
|
}
|
|
22374
22877
|
function projectRelativePath(value, cwds) {
|
|
22375
22878
|
const normalized = value.replaceAll("\\", "/");
|
|
22376
|
-
if (!
|
|
22879
|
+
if (!path10.isAbsolute(value))
|
|
22377
22880
|
return normalized;
|
|
22378
22881
|
for (const cwd of cwds) {
|
|
22379
|
-
const relative =
|
|
22380
|
-
if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${
|
|
22882
|
+
const relative = path10.relative(path10.resolve(cwd), path10.resolve(value));
|
|
22883
|
+
if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path10.sep}`)) {
|
|
22381
22884
|
return relative.replaceAll("\\", "/");
|
|
22382
22885
|
}
|
|
22383
22886
|
}
|
|
@@ -22442,8 +22945,8 @@ async function forkGrokSession(input) {
|
|
|
22442
22945
|
error: error51("sessionNotFound", "Grok Native Session is unavailable")
|
|
22443
22946
|
};
|
|
22444
22947
|
}
|
|
22445
|
-
const sourceCwd =
|
|
22446
|
-
const targetCwd =
|
|
22948
|
+
const sourceCwd = path10.resolve(located.cwd);
|
|
22949
|
+
const targetCwd = path10.resolve(input.cwd);
|
|
22447
22950
|
const source = await readSnapshot({ ...input, cwd: sourceCwd }, sourceRef.data.nativeSessionId);
|
|
22448
22951
|
if (!source.ok)
|
|
22449
22952
|
return source;
|
|
@@ -22518,9 +23021,10 @@ async function forkGrokSession(input) {
|
|
|
22518
23021
|
// dist/grok-compaction.js
|
|
22519
23022
|
var GROK_SESSION_UPDATE_EXTENSION_METHODS = [
|
|
22520
23023
|
"_x.ai/session/update",
|
|
22521
|
-
"x.ai/session_notification"
|
|
23024
|
+
"x.ai/session_notification",
|
|
23025
|
+
"_x.ai/session_notification"
|
|
22522
23026
|
];
|
|
22523
|
-
function
|
|
23027
|
+
function isRecord9(value) {
|
|
22524
23028
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22525
23029
|
}
|
|
22526
23030
|
function optionalNonNegativeInt(value) {
|
|
@@ -22541,7 +23045,7 @@ function isGrokExtensionSessionUpdateMethod(method) {
|
|
|
22541
23045
|
return GROK_SESSION_UPDATE_EXTENSION_METHODS.includes(method);
|
|
22542
23046
|
}
|
|
22543
23047
|
function grokCompactionEventFromUpdate(update) {
|
|
22544
|
-
if (!
|
|
23048
|
+
if (!isRecord9(update) || typeof update.sessionUpdate !== "string")
|
|
22545
23049
|
return null;
|
|
22546
23050
|
const tokensUsed = optionalNonNegativeInt(firstPresent(update, ["tokensUsed", "tokens_used"]));
|
|
22547
23051
|
const contextWindowTokens = optionalNonNegativeInt(firstPresent(update, ["contextWindowTokens", "contextWindow", "context_window"]));
|
|
@@ -22580,7 +23084,7 @@ function grokCompactionEventFromUpdate(update) {
|
|
|
22580
23084
|
// dist/grok-manual-compaction.js
|
|
22581
23085
|
var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
|
|
22582
23086
|
var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
|
|
22583
|
-
function
|
|
23087
|
+
function isRecord10(value) {
|
|
22584
23088
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22585
23089
|
}
|
|
22586
23090
|
function optionalNonNegativeInt2(value) {
|
|
@@ -22592,7 +23096,7 @@ function optionalErrorMessage2(value) {
|
|
|
22592
23096
|
function parseGrokCompactResult(value, cancelled = false) {
|
|
22593
23097
|
if (cancelled)
|
|
22594
23098
|
return { outcome: "cancelled" };
|
|
22595
|
-
if (!
|
|
23099
|
+
if (!isRecord10(value))
|
|
22596
23100
|
return { outcome: "succeeded" };
|
|
22597
23101
|
const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
|
|
22598
23102
|
const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
|
|
@@ -22625,12 +23129,12 @@ function parseGrokCompactResult(value, cancelled = false) {
|
|
|
22625
23129
|
}
|
|
22626
23130
|
|
|
22627
23131
|
// dist/grok-rewind.js
|
|
22628
|
-
import
|
|
23132
|
+
import path11 from "node:path";
|
|
22629
23133
|
var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
|
|
22630
23134
|
function error52(code, message, retryable = false) {
|
|
22631
23135
|
return { code, message, retryable };
|
|
22632
23136
|
}
|
|
22633
|
-
function
|
|
23137
|
+
function isRecord11(value) {
|
|
22634
23138
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22635
23139
|
}
|
|
22636
23140
|
function buildGrokRewindParams(input) {
|
|
@@ -22642,10 +23146,10 @@ function buildGrokRewindParams(input) {
|
|
|
22642
23146
|
};
|
|
22643
23147
|
}
|
|
22644
23148
|
function parseGrokRewindResponse(value) {
|
|
22645
|
-
if (!
|
|
23149
|
+
if (!isRecord11(value))
|
|
22646
23150
|
return null;
|
|
22647
|
-
const payload = typeof value.success !== "boolean" &&
|
|
22648
|
-
if (!
|
|
23151
|
+
const payload = typeof value.success !== "boolean" && isRecord11(value.result) ? value.result : value;
|
|
23152
|
+
if (!isRecord11(payload) || typeof payload.success !== "boolean")
|
|
22649
23153
|
return null;
|
|
22650
23154
|
return rewindPayload(payload);
|
|
22651
23155
|
}
|
|
@@ -22698,8 +23202,8 @@ async function rewindGrokLastTurn(input) {
|
|
|
22698
23202
|
error: error52("sessionNotFound", "Grok Native Session is unavailable")
|
|
22699
23203
|
};
|
|
22700
23204
|
}
|
|
22701
|
-
const sourceCwd =
|
|
22702
|
-
const targetCwd =
|
|
23205
|
+
const sourceCwd = path11.resolve(located.cwd);
|
|
23206
|
+
const targetCwd = path11.resolve(input.cwd);
|
|
22703
23207
|
if (sourceCwd !== targetCwd) {
|
|
22704
23208
|
return {
|
|
22705
23209
|
ok: false,
|
|
@@ -22761,7 +23265,7 @@ var GROK_PLAN_STAY_VALUE = "stay";
|
|
|
22761
23265
|
var GROK_PLAN_STAY_LABEL = "Stay in plan mode";
|
|
22762
23266
|
var GROK_PLAN_OUTCOME_APPROVED = "approved";
|
|
22763
23267
|
var GROK_PLAN_OUTCOME_CANCELLED = "cancelled";
|
|
22764
|
-
function
|
|
23268
|
+
function isRecord12(value) {
|
|
22765
23269
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22766
23270
|
}
|
|
22767
23271
|
function stringField3(value, ...keys) {
|
|
@@ -22773,9 +23277,9 @@ function stringField3(value, ...keys) {
|
|
|
22773
23277
|
return void 0;
|
|
22774
23278
|
}
|
|
22775
23279
|
function parseGrokExitPlanModeParams(params) {
|
|
22776
|
-
if (!
|
|
23280
|
+
if (!isRecord12(params))
|
|
22777
23281
|
return null;
|
|
22778
|
-
const nested =
|
|
23282
|
+
const nested = isRecord12(params.input) ? params.input : params;
|
|
22779
23283
|
const plan = stringField3(nested, "planContent", "plan_content", "plan") ?? stringField3(params, "planContent", "plan_content", "plan") ?? null;
|
|
22780
23284
|
const planFilePath = stringField3(nested, "planFilePath", "plan_file_path") ?? stringField3(params, "planFilePath", "plan_file_path");
|
|
22781
23285
|
const sessionId = stringField3(params, "sessionId", "session_id");
|
|
@@ -22847,7 +23351,7 @@ var GROK_ACP_CLIENT_CAPABILITIES = {
|
|
|
22847
23351
|
"x.ai/exit_plan_mode": true
|
|
22848
23352
|
}
|
|
22849
23353
|
};
|
|
22850
|
-
function
|
|
23354
|
+
function isRecord13(value) {
|
|
22851
23355
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22852
23356
|
}
|
|
22853
23357
|
function stringField4(value, ...keys) {
|
|
@@ -22876,15 +23380,15 @@ function isGrokExitPlanModeMethod(method) {
|
|
|
22876
23380
|
function questionsPayload(params) {
|
|
22877
23381
|
if (Array.isArray(params.questions))
|
|
22878
23382
|
return params.questions;
|
|
22879
|
-
if (
|
|
23383
|
+
if (isRecord13(params.input) && Array.isArray(params.input.questions))
|
|
22880
23384
|
return params.input.questions;
|
|
22881
|
-
if (
|
|
23385
|
+
if (isRecord13(params.askUserQuestion) && Array.isArray(params.askUserQuestion.questions)) {
|
|
22882
23386
|
return params.askUserQuestion.questions;
|
|
22883
23387
|
}
|
|
22884
23388
|
return void 0;
|
|
22885
23389
|
}
|
|
22886
23390
|
function parseOption(value, labels) {
|
|
22887
|
-
if (!
|
|
23391
|
+
if (!isRecord13(value))
|
|
22888
23392
|
return null;
|
|
22889
23393
|
const label = stringField4(value, "label");
|
|
22890
23394
|
if (!label || labels.has(label))
|
|
@@ -22899,7 +23403,7 @@ function parseOption(value, labels) {
|
|
|
22899
23403
|
};
|
|
22900
23404
|
}
|
|
22901
23405
|
function parseQuestion(value, questions) {
|
|
22902
|
-
if (!
|
|
23406
|
+
if (!isRecord13(value))
|
|
22903
23407
|
return null;
|
|
22904
23408
|
const question = stringField4(value, "question");
|
|
22905
23409
|
if (!question || questions.has(question))
|
|
@@ -22924,7 +23428,7 @@ function parseQuestion(value, questions) {
|
|
|
22924
23428
|
};
|
|
22925
23429
|
}
|
|
22926
23430
|
function parseGrokAskUserQuestionParams(params) {
|
|
22927
|
-
if (!
|
|
23431
|
+
if (!isRecord13(params))
|
|
22928
23432
|
return null;
|
|
22929
23433
|
const rawQuestions = questionsPayload(params);
|
|
22930
23434
|
if (!Array.isArray(rawQuestions) || rawQuestions.length === 0)
|
|
@@ -23039,16 +23543,16 @@ var GrokTransportError = class extends Error {
|
|
|
23039
23543
|
this.name = "GrokTransportError";
|
|
23040
23544
|
}
|
|
23041
23545
|
};
|
|
23042
|
-
function
|
|
23546
|
+
function isRecord14(value) {
|
|
23043
23547
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23044
23548
|
}
|
|
23045
23549
|
function acpToolName(update, metadata) {
|
|
23046
|
-
if (!
|
|
23550
|
+
if (!isRecord14(update))
|
|
23047
23551
|
return void 0;
|
|
23048
23552
|
if (typeof update.name === "string" && update.name.length > 0)
|
|
23049
23553
|
return update.name;
|
|
23050
|
-
const meta3 =
|
|
23051
|
-
const tool = meta3 &&
|
|
23554
|
+
const meta3 = isRecord14(update._meta) ? update._meta : metadata;
|
|
23555
|
+
const tool = meta3 && isRecord14(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
23052
23556
|
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
23053
23557
|
}
|
|
23054
23558
|
function errorText(error53) {
|
|
@@ -23104,12 +23608,27 @@ function signalProcessTree(child, signal) {
|
|
|
23104
23608
|
try {
|
|
23105
23609
|
process.kill(-child.pid, signal);
|
|
23106
23610
|
} catch (error53) {
|
|
23107
|
-
if (!
|
|
23611
|
+
if (!isRecord14(error53) || error53.code !== "ESRCH")
|
|
23108
23612
|
throw error53;
|
|
23109
23613
|
}
|
|
23110
23614
|
}
|
|
23111
23615
|
function transportEvent(update, metadata) {
|
|
23112
23616
|
const extension = update;
|
|
23617
|
+
if (extension.sessionUpdate === "response_completed") {
|
|
23618
|
+
return {
|
|
23619
|
+
type: "response.completed",
|
|
23620
|
+
...extension.usage !== void 0 ? { usage: extension.usage } : {},
|
|
23621
|
+
...typeof extension.message_id === "string" && extension.message_id ? { messageId: extension.message_id } : {},
|
|
23622
|
+
...metadata ? { metadata } : {}
|
|
23623
|
+
};
|
|
23624
|
+
}
|
|
23625
|
+
if (extension.sessionUpdate === "tool_call_delta_chunk" && typeof extension.arguments_delta === "string") {
|
|
23626
|
+
return {
|
|
23627
|
+
type: "tool.input.delta",
|
|
23628
|
+
text: extension.arguments_delta,
|
|
23629
|
+
...metadata ? { metadata } : {}
|
|
23630
|
+
};
|
|
23631
|
+
}
|
|
23113
23632
|
if (extension.sessionUpdate === "turn_completed" && typeof extension.prompt_id === "string" && extension.prompt_id.length > 0 && typeof extension.stop_reason === "string") {
|
|
23114
23633
|
return {
|
|
23115
23634
|
type: "turn.completed",
|
|
@@ -23179,34 +23698,34 @@ function transportEvent(update, metadata) {
|
|
|
23179
23698
|
}
|
|
23180
23699
|
function grokHomeDir(options) {
|
|
23181
23700
|
const environment = { ...process.env, ...options.environment };
|
|
23182
|
-
const home = environment.HOME ?? environment.USERPROFILE ??
|
|
23183
|
-
return environment.GROK_HOME ??
|
|
23701
|
+
const home = environment.HOME ?? environment.USERPROFILE ?? os5.homedir();
|
|
23702
|
+
return environment.GROK_HOME ?? path12.join(home, ".grok");
|
|
23184
23703
|
}
|
|
23185
23704
|
function grokNativeSessionDirectory(options, sessionId) {
|
|
23186
|
-
return
|
|
23705
|
+
return path12.join(grokHomeDir(options), "sessions", encodeURIComponent(path12.resolve(options.cwd)), sessionId);
|
|
23187
23706
|
}
|
|
23188
23707
|
function nativeSessionFile(options, sessionId, fileName) {
|
|
23189
|
-
return
|
|
23708
|
+
return path12.join(grokNativeSessionDirectory(options, sessionId), fileName);
|
|
23190
23709
|
}
|
|
23191
23710
|
function nativeHistoryPath(options, sessionId) {
|
|
23192
23711
|
return nativeSessionFile(options, sessionId, "updates.jsonl");
|
|
23193
23712
|
}
|
|
23194
23713
|
async function readNativeSignals(options, sessionId) {
|
|
23195
23714
|
try {
|
|
23196
|
-
return JSON.parse(await
|
|
23715
|
+
return JSON.parse(await readFile3(nativeSessionFile(options, sessionId, "signals.json"), "utf8"));
|
|
23197
23716
|
} catch {
|
|
23198
23717
|
return void 0;
|
|
23199
23718
|
}
|
|
23200
23719
|
}
|
|
23201
23720
|
function isMissingFile(error53) {
|
|
23202
|
-
return
|
|
23721
|
+
return isRecord14(error53) && error53.code === "ENOENT";
|
|
23203
23722
|
}
|
|
23204
23723
|
async function locateGrokNativeSession(options, sessionId) {
|
|
23205
23724
|
if (sessionId.length === 0)
|
|
23206
23725
|
return null;
|
|
23207
23726
|
let entries;
|
|
23208
23727
|
try {
|
|
23209
|
-
entries = await readdir(
|
|
23728
|
+
entries = await readdir(path12.join(grokHomeDir(options), "sessions"), { withFileTypes: true });
|
|
23210
23729
|
} catch (error53) {
|
|
23211
23730
|
if (isMissingFile(error53))
|
|
23212
23731
|
return null;
|
|
@@ -23220,9 +23739,9 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23220
23739
|
continue;
|
|
23221
23740
|
let summaryRaw;
|
|
23222
23741
|
try {
|
|
23223
|
-
summaryRaw = await
|
|
23742
|
+
summaryRaw = await readFile3(path12.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
23224
23743
|
} catch (error53) {
|
|
23225
|
-
if (isMissingFile(error53) ||
|
|
23744
|
+
if (isMissingFile(error53) || isRecord14(error53) && error53.code === "ENOTDIR")
|
|
23226
23745
|
continue;
|
|
23227
23746
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
23228
23747
|
cause: error53
|
|
@@ -23234,11 +23753,11 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23234
23753
|
} catch {
|
|
23235
23754
|
continue;
|
|
23236
23755
|
}
|
|
23237
|
-
if (!
|
|
23756
|
+
if (!isRecord14(parsed))
|
|
23238
23757
|
continue;
|
|
23239
23758
|
const info = parsed.info;
|
|
23240
|
-
const cwd =
|
|
23241
|
-
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ?
|
|
23759
|
+
const cwd = isRecord14(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path12.resolve(info.cwd) : path12.resolve(decodeURIComponent(entry.name));
|
|
23760
|
+
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path12.resolve(parsed.source_workspace_dir) : void 0;
|
|
23242
23761
|
matches.push({
|
|
23243
23762
|
cwd,
|
|
23244
23763
|
...sourceWorkspaceDir ? { sourceWorkspaceDir } : {}
|
|
@@ -23248,7 +23767,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23248
23767
|
}
|
|
23249
23768
|
async function readGrokNativeHistory(options, sessionId) {
|
|
23250
23769
|
try {
|
|
23251
|
-
return parseNativeHistory(await
|
|
23770
|
+
return parseNativeHistory(await readFile3(nativeHistoryPath({ ...options, cwd: path12.resolve(options.cwd) }, sessionId), "utf8"), sessionId);
|
|
23252
23771
|
} catch (error53) {
|
|
23253
23772
|
if (isMissingFile(error53))
|
|
23254
23773
|
return [];
|
|
@@ -23270,12 +23789,12 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
23270
23789
|
} catch {
|
|
23271
23790
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
23272
23791
|
}
|
|
23273
|
-
if (!
|
|
23792
|
+
if (!isRecord14(record2) || !isRecord14(record2.params))
|
|
23274
23793
|
continue;
|
|
23275
23794
|
const params = record2.params;
|
|
23276
|
-
if (params.sessionId !== sessionId || !
|
|
23795
|
+
if (params.sessionId !== sessionId || !isRecord14(params.update))
|
|
23277
23796
|
continue;
|
|
23278
|
-
const metadata =
|
|
23797
|
+
const metadata = isRecord14(params._meta) ? params._meta : void 0;
|
|
23279
23798
|
const event = transportEvent(params.update, metadata);
|
|
23280
23799
|
if (event)
|
|
23281
23800
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -23332,6 +23851,13 @@ var GrokAcpTransport = class {
|
|
|
23332
23851
|
async getHistory() {
|
|
23333
23852
|
return this.readHistory(this.sessionId);
|
|
23334
23853
|
}
|
|
23854
|
+
/** Native cumulative usage since this process attached, not persisted Session totals. */
|
|
23855
|
+
async getUsage() {
|
|
23856
|
+
if (!this.#connection)
|
|
23857
|
+
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
23858
|
+
const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
|
|
23859
|
+
return isRecord14(result) ? result.usage : void 0;
|
|
23860
|
+
}
|
|
23335
23861
|
async readHistory(sessionId, cwd = this.#options.cwd) {
|
|
23336
23862
|
return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
|
|
23337
23863
|
}
|
|
@@ -23535,6 +24061,7 @@ var GrokAcpTransport = class {
|
|
|
23535
24061
|
prompt: [{ type: "text", text }]
|
|
23536
24062
|
});
|
|
23537
24063
|
} finally {
|
|
24064
|
+
await yieldToEventLoop();
|
|
23538
24065
|
if (this.#activePrompt === active)
|
|
23539
24066
|
this.#activePrompt = null;
|
|
23540
24067
|
}
|
|
@@ -23573,16 +24100,17 @@ var GrokAcpTransport = class {
|
|
|
23573
24100
|
this.#activeCompact = null;
|
|
23574
24101
|
}
|
|
23575
24102
|
}
|
|
23576
|
-
async setModel(modelId, reasoningEffort) {
|
|
24103
|
+
async setModel(modelId, reasoningEffort, contextWindowTokens) {
|
|
23577
24104
|
const connection = this.#connection;
|
|
23578
24105
|
if (!connection || !this.#sessionId)
|
|
23579
24106
|
throw new Error("Grok ACP Session is unavailable");
|
|
23580
24107
|
const response = await connection.request("session/set_model", {
|
|
23581
24108
|
sessionId: this.#sessionId,
|
|
23582
24109
|
modelId,
|
|
23583
|
-
...reasoningEffort ? { reasoningEffort } : {}
|
|
24110
|
+
...reasoningEffort ? { reasoningEffort } : {},
|
|
24111
|
+
...contextWindowTokens !== void 0 ? { _meta: { contextWindow: contextWindowTokens } } : {}
|
|
23584
24112
|
});
|
|
23585
|
-
if (!
|
|
24113
|
+
if (!isRecord14(response) || !isRecord14(response._meta) || !isRecord14(response._meta.model)) {
|
|
23586
24114
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
23587
24115
|
}
|
|
23588
24116
|
const selected = response._meta.model.Ok;
|
|
@@ -23634,7 +24162,7 @@ var GrokAcpTransport = class {
|
|
|
23634
24162
|
this.#availableCommands = parseGrokAvailableCommands(update.availableCommands);
|
|
23635
24163
|
return;
|
|
23636
24164
|
}
|
|
23637
|
-
const metadata =
|
|
24165
|
+
const metadata = isRecord14(notification._meta) ? notification._meta : void 0;
|
|
23638
24166
|
const event = transportEvent(notification.update, metadata);
|
|
23639
24167
|
if (!event)
|
|
23640
24168
|
return;
|
|
@@ -23649,7 +24177,7 @@ var GrokAcpTransport = class {
|
|
|
23649
24177
|
#handleExtensionNotification(method, params) {
|
|
23650
24178
|
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
23651
24179
|
return;
|
|
23652
|
-
if (typeof params.sessionId !== "string" || !
|
|
24180
|
+
if (typeof params.sessionId !== "string" || !isRecord14(params.update))
|
|
23653
24181
|
return;
|
|
23654
24182
|
this.#handleUpdate(params);
|
|
23655
24183
|
}
|
|
@@ -23676,6 +24204,323 @@ var GrokAcpTransport = class {
|
|
|
23676
24204
|
}
|
|
23677
24205
|
};
|
|
23678
24206
|
|
|
24207
|
+
// dist/session-import.js
|
|
24208
|
+
import { createReadStream as createReadStream2 } from "node:fs";
|
|
24209
|
+
import { opendir as opendir2, readFile as readFile4, stat } from "node:fs/promises";
|
|
24210
|
+
import path13 from "node:path";
|
|
24211
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
24212
|
+
|
|
24213
|
+
// ../../harness-adapter/dist/session-import.js
|
|
24214
|
+
import { lstat as lstat2 } from "node:fs/promises";
|
|
24215
|
+
var SessionImportChangedError = class extends Error {
|
|
24216
|
+
constructor(message = "Native Session changed during discovery; refresh and retry") {
|
|
24217
|
+
super(message);
|
|
24218
|
+
this.name = "SessionImportChangedError";
|
|
24219
|
+
}
|
|
24220
|
+
};
|
|
24221
|
+
function isMissingFileError(error53) {
|
|
24222
|
+
return typeof error53 === "object" && error53 !== null && "code" in error53 && error53.code === "ENOENT";
|
|
24223
|
+
}
|
|
24224
|
+
function sameFileFingerprint(left, right) {
|
|
24225
|
+
return left === null || right === null ? left === right : left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
24226
|
+
}
|
|
24227
|
+
var STORAGE_ACCESS_ERRORS = /* @__PURE__ */ new Set(["EACCES", "EPERM", "EIO", "EMFILE", "ENFILE"]);
|
|
24228
|
+
function isStorageAccessError(error53) {
|
|
24229
|
+
return typeof error53 === "object" && error53 !== null && "code" in error53 && typeof error53.code === "string" && STORAGE_ACCESS_ERRORS.has(error53.code);
|
|
24230
|
+
}
|
|
24231
|
+
async function optionalLstat(file2) {
|
|
24232
|
+
try {
|
|
24233
|
+
return await lstat2(file2);
|
|
24234
|
+
} catch (error53) {
|
|
24235
|
+
if (isMissingFileError(error53))
|
|
24236
|
+
return null;
|
|
24237
|
+
throw error53;
|
|
24238
|
+
}
|
|
24239
|
+
}
|
|
24240
|
+
async function readStableFiles(files, read) {
|
|
24241
|
+
const before = await Promise.all(files.map(optionalLstat));
|
|
24242
|
+
const value = await read(before);
|
|
24243
|
+
const after = await Promise.all(files.map(optionalLstat));
|
|
24244
|
+
if (before.some((info, index) => !sameFileFingerprint(info, after[index] ?? null)))
|
|
24245
|
+
throw new SessionImportChangedError();
|
|
24246
|
+
return value;
|
|
24247
|
+
}
|
|
24248
|
+
function sessionImportTitle(value, maxLength = HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) {
|
|
24249
|
+
if (typeof value !== "string")
|
|
24250
|
+
return null;
|
|
24251
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
24252
|
+
if (!normalized)
|
|
24253
|
+
return null;
|
|
24254
|
+
if (normalized.length <= maxLength)
|
|
24255
|
+
return normalized;
|
|
24256
|
+
const characters = [...normalized];
|
|
24257
|
+
if (characters.length <= maxLength)
|
|
24258
|
+
return normalized;
|
|
24259
|
+
return `${characters.slice(0, maxLength - 1).join("").trimEnd()}…`;
|
|
24260
|
+
}
|
|
24261
|
+
function sessionImportCandidate(input) {
|
|
24262
|
+
const time3 = typeof input.updatedAt === "number" ? input.updatedAt : typeof input.updatedAt === "string" ? Date.parse(input.updatedAt) : Number.NaN;
|
|
24263
|
+
const parsed = harnessSessionImportCandidateSchema.safeParse({
|
|
24264
|
+
nativeSessionId: input.nativeSessionId,
|
|
24265
|
+
cwd: input.cwd,
|
|
24266
|
+
title: typeof input.title === "string" && input.title.trim().length > 0 ? input.title : null,
|
|
24267
|
+
updatedAt: Math.floor(time3),
|
|
24268
|
+
// Unknown must stay unknown; only an explicit boolean is a native statement.
|
|
24269
|
+
running: typeof input.running === "boolean" ? input.running : null
|
|
24270
|
+
});
|
|
24271
|
+
return parsed.success ? parsed.data : null;
|
|
24272
|
+
}
|
|
24273
|
+
var SessionImportScope = class {
|
|
24274
|
+
#abort = new AbortController();
|
|
24275
|
+
#options;
|
|
24276
|
+
#pending = /* @__PURE__ */ new Set();
|
|
24277
|
+
constructor(options) {
|
|
24278
|
+
this.#options = options;
|
|
24279
|
+
}
|
|
24280
|
+
#closed() {
|
|
24281
|
+
return {
|
|
24282
|
+
ok: false,
|
|
24283
|
+
error: { code: "invalidState", message: this.#options.closedMessage, retryable: false }
|
|
24284
|
+
};
|
|
24285
|
+
}
|
|
24286
|
+
read(operation) {
|
|
24287
|
+
const signal = this.#abort.signal;
|
|
24288
|
+
if (signal.aborted)
|
|
24289
|
+
return Promise.resolve(this.#closed());
|
|
24290
|
+
let started;
|
|
24291
|
+
try {
|
|
24292
|
+
started = operation(signal);
|
|
24293
|
+
} catch (error53) {
|
|
24294
|
+
started = Promise.reject(error53 instanceof Error ? error53 : new Error("Session read failed"));
|
|
24295
|
+
}
|
|
24296
|
+
const request = started.then((value) => signal.aborted ? this.#closed() : { ok: true, value }).catch(() => signal.aborted ? this.#closed() : {
|
|
24297
|
+
ok: false,
|
|
24298
|
+
error: {
|
|
24299
|
+
code: "unavailable",
|
|
24300
|
+
message: this.#options.unavailableMessage,
|
|
24301
|
+
retryable: true
|
|
24302
|
+
}
|
|
24303
|
+
}).finally(() => this.#pending.delete(request));
|
|
24304
|
+
this.#pending.add(request);
|
|
24305
|
+
return request;
|
|
24306
|
+
}
|
|
24307
|
+
/** `read` for `resolveCandidate`: a null source is the selected Session having disappeared. */
|
|
24308
|
+
async resolve(operation) {
|
|
24309
|
+
const result = await this.read(operation);
|
|
24310
|
+
if (!result.ok)
|
|
24311
|
+
return result;
|
|
24312
|
+
return result.value ? { ok: true, value: result.value } : {
|
|
24313
|
+
ok: false,
|
|
24314
|
+
error: {
|
|
24315
|
+
code: "sessionNotFound",
|
|
24316
|
+
message: this.#options.notFoundMessage,
|
|
24317
|
+
retryable: false
|
|
24318
|
+
}
|
|
24319
|
+
};
|
|
24320
|
+
}
|
|
24321
|
+
/** Idempotent. Resolves after every started read has settled. */
|
|
24322
|
+
async close() {
|
|
24323
|
+
this.#abort.abort();
|
|
24324
|
+
await Promise.allSettled(this.#pending);
|
|
24325
|
+
}
|
|
24326
|
+
};
|
|
24327
|
+
|
|
24328
|
+
// dist/session-import.js
|
|
24329
|
+
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
24330
|
+
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
24331
|
+
function isRecord15(value) {
|
|
24332
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24333
|
+
}
|
|
24334
|
+
async function readJson(file2, signal) {
|
|
24335
|
+
return JSON.parse(await readFile4(file2, { encoding: "utf8", signal }));
|
|
24336
|
+
}
|
|
24337
|
+
function processAlive(pid) {
|
|
24338
|
+
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0)
|
|
24339
|
+
return false;
|
|
24340
|
+
try {
|
|
24341
|
+
process.kill(pid, 0);
|
|
24342
|
+
return true;
|
|
24343
|
+
} catch (error53) {
|
|
24344
|
+
return isRecord15(error53) && error53.code === "EPERM";
|
|
24345
|
+
}
|
|
24346
|
+
}
|
|
24347
|
+
async function firstUserText(file2, signal) {
|
|
24348
|
+
const stream = createReadStream2(file2, { encoding: "utf8", signal });
|
|
24349
|
+
const lines = createInterface2({ input: stream, crlfDelay: Infinity });
|
|
24350
|
+
try {
|
|
24351
|
+
for await (const line of lines) {
|
|
24352
|
+
signal.throwIfAborted();
|
|
24353
|
+
if (!line.includes("user_message_chunk"))
|
|
24354
|
+
continue;
|
|
24355
|
+
let entry;
|
|
24356
|
+
try {
|
|
24357
|
+
entry = JSON.parse(line);
|
|
24358
|
+
} catch {
|
|
24359
|
+
continue;
|
|
24360
|
+
}
|
|
24361
|
+
const update = isRecord15(entry) && isRecord15(entry.params) ? entry.params.update : null;
|
|
24362
|
+
if (!isRecord15(update) || update.sessionUpdate !== "user_message_chunk")
|
|
24363
|
+
continue;
|
|
24364
|
+
const text = isRecord15(update.content) ? update.content.text : null;
|
|
24365
|
+
return typeof text === "string" ? text : "";
|
|
24366
|
+
}
|
|
24367
|
+
return null;
|
|
24368
|
+
} finally {
|
|
24369
|
+
lines.close();
|
|
24370
|
+
stream.destroy();
|
|
24371
|
+
}
|
|
24372
|
+
}
|
|
24373
|
+
var GrokSessionImport = class {
|
|
24374
|
+
#environment;
|
|
24375
|
+
#scope = new SessionImportScope({
|
|
24376
|
+
closedMessage: "Grok Session import is closed",
|
|
24377
|
+
unavailableMessage: "Grok sessions could not be read; close native clients, check storage access and retry",
|
|
24378
|
+
notFoundMessage: "Grok Session is no longer importable"
|
|
24379
|
+
});
|
|
24380
|
+
constructor(environment) {
|
|
24381
|
+
this.#environment = environment ? { ...environment } : void 0;
|
|
24382
|
+
}
|
|
24383
|
+
listCandidates() {
|
|
24384
|
+
return this.#scope.read(async (signal) => {
|
|
24385
|
+
const active = await this.#activeSessions(signal);
|
|
24386
|
+
const candidates = [];
|
|
24387
|
+
for (const [, directories] of await this.#sessionDirectories(signal)) {
|
|
24388
|
+
if (directories.length !== 1 || !directories[0])
|
|
24389
|
+
continue;
|
|
24390
|
+
try {
|
|
24391
|
+
const candidate = await this.#candidate(directories[0], active, signal);
|
|
24392
|
+
if (candidate)
|
|
24393
|
+
candidates.push(candidate);
|
|
24394
|
+
} catch (error53) {
|
|
24395
|
+
if (!(error53 instanceof SessionImportChangedError))
|
|
24396
|
+
throw error53;
|
|
24397
|
+
}
|
|
24398
|
+
}
|
|
24399
|
+
return candidates;
|
|
24400
|
+
});
|
|
24401
|
+
}
|
|
24402
|
+
resolveCandidate(nativeSessionId) {
|
|
24403
|
+
return this.#scope.resolve(async (signal) => {
|
|
24404
|
+
const directories = (await this.#sessionDirectories(signal)).get(nativeSessionId);
|
|
24405
|
+
if (directories?.length !== 1 || !directories[0])
|
|
24406
|
+
return null;
|
|
24407
|
+
const candidate = await this.#candidate(directories[0], await this.#activeSessions(signal), signal);
|
|
24408
|
+
if (!candidate)
|
|
24409
|
+
return null;
|
|
24410
|
+
return {
|
|
24411
|
+
candidate,
|
|
24412
|
+
nativeRef: nativeSessionRefSchema.parse({
|
|
24413
|
+
harnessId: "grok",
|
|
24414
|
+
nativeSessionId,
|
|
24415
|
+
formatVersion: 1
|
|
24416
|
+
})
|
|
24417
|
+
};
|
|
24418
|
+
});
|
|
24419
|
+
}
|
|
24420
|
+
close() {
|
|
24421
|
+
return this.#scope.close();
|
|
24422
|
+
}
|
|
24423
|
+
#home() {
|
|
24424
|
+
return grokHomeDir(this.#environment ? { environment: this.#environment } : {});
|
|
24425
|
+
}
|
|
24426
|
+
/** IDs a live Grok process currently holds open, from Grok's own registry. */
|
|
24427
|
+
async #activeSessions(signal) {
|
|
24428
|
+
const active = /* @__PURE__ */ new Set();
|
|
24429
|
+
let entries;
|
|
24430
|
+
try {
|
|
24431
|
+
entries = await readJson(path13.join(this.#home(), "active_sessions.json"), signal);
|
|
24432
|
+
} catch (error53) {
|
|
24433
|
+
signal.throwIfAborted();
|
|
24434
|
+
if (isStorageAccessError(error53))
|
|
24435
|
+
throw error53;
|
|
24436
|
+
return active;
|
|
24437
|
+
}
|
|
24438
|
+
if (!Array.isArray(entries))
|
|
24439
|
+
return active;
|
|
24440
|
+
for (const entry of entries) {
|
|
24441
|
+
if (isRecord15(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
24442
|
+
active.add(entry.session_id);
|
|
24443
|
+
}
|
|
24444
|
+
return active;
|
|
24445
|
+
}
|
|
24446
|
+
/** Session ID to every directory claiming it. Enumerated links are not followed. */
|
|
24447
|
+
async #sessionDirectories(signal) {
|
|
24448
|
+
const root = path13.join(this.#home(), "sessions");
|
|
24449
|
+
const found = /* @__PURE__ */ new Map();
|
|
24450
|
+
const info = await optionalLstat(root);
|
|
24451
|
+
if (!info)
|
|
24452
|
+
return found;
|
|
24453
|
+
if (!info.isDirectory())
|
|
24454
|
+
throw new Error("Grok Session store is not a directory");
|
|
24455
|
+
for await (const workspace of await opendir2(root)) {
|
|
24456
|
+
signal.throwIfAborted();
|
|
24457
|
+
if (!workspace.isDirectory())
|
|
24458
|
+
continue;
|
|
24459
|
+
const workspaceDirectory = path13.join(root, workspace.name);
|
|
24460
|
+
const sessions = await opendir2(workspaceDirectory).catch((error53) => {
|
|
24461
|
+
if (isMissingFileError(error53))
|
|
24462
|
+
return null;
|
|
24463
|
+
throw error53;
|
|
24464
|
+
});
|
|
24465
|
+
if (!sessions)
|
|
24466
|
+
continue;
|
|
24467
|
+
for await (const session of sessions) {
|
|
24468
|
+
signal.throwIfAborted();
|
|
24469
|
+
if (!session.isDirectory())
|
|
24470
|
+
continue;
|
|
24471
|
+
const directories = found.get(session.name) ?? [];
|
|
24472
|
+
directories.push(path13.join(workspaceDirectory, session.name));
|
|
24473
|
+
found.set(session.name, directories);
|
|
24474
|
+
}
|
|
24475
|
+
}
|
|
24476
|
+
return found;
|
|
24477
|
+
}
|
|
24478
|
+
async #candidate(sessionDirectory, active, signal) {
|
|
24479
|
+
signal.throwIfAborted();
|
|
24480
|
+
const nativeSessionId = path13.basename(sessionDirectory);
|
|
24481
|
+
const files = [
|
|
24482
|
+
path13.join(sessionDirectory, "summary.json"),
|
|
24483
|
+
path13.join(sessionDirectory, "updates.jsonl")
|
|
24484
|
+
];
|
|
24485
|
+
return readStableFiles(files, async ([summaryInfo, updates]) => {
|
|
24486
|
+
if (!summaryInfo?.isFile() || !updates?.isFile() || summaryInfo.size > MAX_METADATA_BYTES)
|
|
24487
|
+
return null;
|
|
24488
|
+
try {
|
|
24489
|
+
const summary = await readJson(files[0], signal);
|
|
24490
|
+
if (!isRecord15(summary) || !isRecord15(summary.info) || summary.info.id !== nativeSessionId)
|
|
24491
|
+
return null;
|
|
24492
|
+
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
24493
|
+
return null;
|
|
24494
|
+
const nativeCwd = summary.info.cwd;
|
|
24495
|
+
if (typeof nativeCwd !== "string" || !path13.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
|
|
24496
|
+
return null;
|
|
24497
|
+
const cwd = path13.resolve(nativeCwd);
|
|
24498
|
+
if (encodeURIComponent(cwd) !== path13.basename(path13.dirname(sessionDirectory)))
|
|
24499
|
+
return null;
|
|
24500
|
+
if (!(await stat(cwd)).isDirectory())
|
|
24501
|
+
return null;
|
|
24502
|
+
const prompt = await firstUserText(files[1], signal);
|
|
24503
|
+
if (prompt === null)
|
|
24504
|
+
return null;
|
|
24505
|
+
const updatedAt = [summary.last_active_at, summary.updated_at].map((value) => typeof value === "string" ? Date.parse(value) : Number.NaN).find((value) => Number.isFinite(value) && value >= 0);
|
|
24506
|
+
return sessionImportCandidate({
|
|
24507
|
+
nativeSessionId,
|
|
24508
|
+
cwd,
|
|
24509
|
+
title: sessionImportTitle(summary.generated_title) ?? sessionImportTitle(summary.session_summary) ?? sessionImportTitle(prompt),
|
|
24510
|
+
updatedAt: updatedAt ?? updates.mtimeMs,
|
|
24511
|
+
// Grok registers open Sessions with their process. Absence is not proof of idleness.
|
|
24512
|
+
running: active.has(nativeSessionId) ? true : null
|
|
24513
|
+
});
|
|
24514
|
+
} catch (error53) {
|
|
24515
|
+
signal.throwIfAborted();
|
|
24516
|
+
if (isStorageAccessError(error53))
|
|
24517
|
+
throw error53;
|
|
24518
|
+
return null;
|
|
24519
|
+
}
|
|
24520
|
+
});
|
|
24521
|
+
}
|
|
24522
|
+
};
|
|
24523
|
+
|
|
23679
24524
|
// dist/grok-subagent-lifecycle.js
|
|
23680
24525
|
function subagentFailure() {
|
|
23681
24526
|
return {
|
|
@@ -23869,7 +24714,7 @@ var GrokSubagentLifecycle = class {
|
|
|
23869
24714
|
};
|
|
23870
24715
|
|
|
23871
24716
|
// dist/grok-models.js
|
|
23872
|
-
function
|
|
24717
|
+
function isRecord16(value) {
|
|
23873
24718
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23874
24719
|
}
|
|
23875
24720
|
function nonBlank(value) {
|
|
@@ -23881,7 +24726,7 @@ function thinkingOptions(value) {
|
|
|
23881
24726
|
const seen = /* @__PURE__ */ new Set();
|
|
23882
24727
|
const options = [];
|
|
23883
24728
|
for (const candidate of value) {
|
|
23884
|
-
if (!
|
|
24729
|
+
if (!isRecord16(candidate) || !nonBlank(candidate.label))
|
|
23885
24730
|
continue;
|
|
23886
24731
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
23887
24732
|
if (!id.success || seen.has(id.data))
|
|
@@ -23892,7 +24737,7 @@ function thinkingOptions(value) {
|
|
|
23892
24737
|
return options;
|
|
23893
24738
|
}
|
|
23894
24739
|
function parseGrokModelState(value) {
|
|
23895
|
-
if (!
|
|
24740
|
+
if (!isRecord16(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
23896
24741
|
return null;
|
|
23897
24742
|
}
|
|
23898
24743
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -23900,16 +24745,20 @@ function parseGrokModelState(value) {
|
|
|
23900
24745
|
return null;
|
|
23901
24746
|
const allThinking = /* @__PURE__ */ new Map();
|
|
23902
24747
|
const contextWindowTokensByModel = /* @__PURE__ */ new Map();
|
|
24748
|
+
const defaultContextWindowTokensByModel = /* @__PURE__ */ new Map();
|
|
23903
24749
|
const models = [];
|
|
23904
24750
|
let currentThinkingOptionId;
|
|
23905
24751
|
for (const candidate of value.availableModels) {
|
|
23906
|
-
if (!
|
|
24752
|
+
if (!isRecord16(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
23907
24753
|
continue;
|
|
23908
24754
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
23909
24755
|
if (!ref.success)
|
|
23910
24756
|
continue;
|
|
23911
|
-
const metadata =
|
|
24757
|
+
const metadata = isRecord16(candidate._meta) ? candidate._meta : {};
|
|
23912
24758
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
24759
|
+
if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
|
|
24760
|
+
defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
|
|
24761
|
+
}
|
|
23913
24762
|
if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
|
|
23914
24763
|
contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
|
|
23915
24764
|
}
|
|
@@ -23933,6 +24782,7 @@ function parseGrokModelState(value) {
|
|
|
23933
24782
|
return {
|
|
23934
24783
|
currentModel: currentModel.data,
|
|
23935
24784
|
contextWindowTokensByModel,
|
|
24785
|
+
defaultContextWindowTokensByModel,
|
|
23936
24786
|
...currentThinkingOptionId ? { currentThinkingOptionId } : {},
|
|
23937
24787
|
catalog: {
|
|
23938
24788
|
models,
|
|
@@ -23943,13 +24793,13 @@ function parseGrokModelState(value) {
|
|
|
23943
24793
|
};
|
|
23944
24794
|
}
|
|
23945
24795
|
function modelStateFromInitialize(response) {
|
|
23946
|
-
return parseGrokModelState(
|
|
24796
|
+
return parseGrokModelState(isRecord16(response._meta) ? response._meta.modelState : void 0);
|
|
23947
24797
|
}
|
|
23948
24798
|
function modelStateFromSessionResponse(response) {
|
|
23949
|
-
return parseGrokModelState(
|
|
24799
|
+
return parseGrokModelState(isRecord16(response) ? response.models : void 0);
|
|
23950
24800
|
}
|
|
23951
|
-
function stateForGrokModel(modelState, nativeState,
|
|
23952
|
-
const selectedModel =
|
|
24801
|
+
function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
24802
|
+
const selectedModel = model2;
|
|
23953
24803
|
const catalogModel = modelState.catalog.models.find(({ ref }) => ref.id === selectedModel.id);
|
|
23954
24804
|
const availableThinkingOptions = catalogModel?.supportedThinkingOptionIds?.flatMap((id) => {
|
|
23955
24805
|
const option = modelState.catalog.thinkingOptions.find((candidate) => candidate.id === id);
|
|
@@ -23965,12 +24815,12 @@ function stateForGrokModel(modelState, nativeState, model = modelState.currentMo
|
|
|
23965
24815
|
}
|
|
23966
24816
|
|
|
23967
24817
|
// dist/grok-credits.js
|
|
23968
|
-
import { readFile as
|
|
23969
|
-
import
|
|
23970
|
-
import
|
|
24818
|
+
import { readFile as readFile5 } from "node:fs/promises";
|
|
24819
|
+
import os6 from "node:os";
|
|
24820
|
+
import path14 from "node:path";
|
|
23971
24821
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
23972
24822
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
23973
|
-
function
|
|
24823
|
+
function isRecord17(value) {
|
|
23974
24824
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23975
24825
|
}
|
|
23976
24826
|
function finitePercent(value) {
|
|
@@ -23979,15 +24829,15 @@ function finitePercent(value) {
|
|
|
23979
24829
|
return Math.min(100, Math.max(0, value));
|
|
23980
24830
|
}
|
|
23981
24831
|
function nonNegativeCentValue(value) {
|
|
23982
|
-
if (!
|
|
24832
|
+
if (!isRecord17(value))
|
|
23983
24833
|
return void 0;
|
|
23984
24834
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
23985
24835
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
23986
24836
|
return void 0;
|
|
23987
24837
|
return amount;
|
|
23988
24838
|
}
|
|
23989
|
-
function
|
|
23990
|
-
return environment.GROK_HOME ??
|
|
24839
|
+
function grokHome2(environment) {
|
|
24840
|
+
return environment.GROK_HOME ?? path14.join(environment.HOME ?? environment.USERPROFILE ?? os6.homedir(), ".grok");
|
|
23991
24841
|
}
|
|
23992
24842
|
function periodTypeFrom(value) {
|
|
23993
24843
|
if (typeof value !== "string")
|
|
@@ -24003,7 +24853,7 @@ function productUsageFrom(value) {
|
|
|
24003
24853
|
if (!Array.isArray(value))
|
|
24004
24854
|
return void 0;
|
|
24005
24855
|
const products = value.flatMap((entry) => {
|
|
24006
|
-
if (!
|
|
24856
|
+
if (!isRecord17(entry) || typeof entry.product !== "string")
|
|
24007
24857
|
return [];
|
|
24008
24858
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
24009
24859
|
return usagePercent === void 0 ? [] : [{ product: entry.product, usagePercent }];
|
|
@@ -24011,10 +24861,10 @@ function productUsageFrom(value) {
|
|
|
24011
24861
|
return products.length > 0 ? products : void 0;
|
|
24012
24862
|
}
|
|
24013
24863
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
24014
|
-
if (!
|
|
24864
|
+
if (!isRecord17(value) || !isRecord17(value.config))
|
|
24015
24865
|
return null;
|
|
24016
24866
|
const config2 = value.config;
|
|
24017
|
-
const period =
|
|
24867
|
+
const period = isRecord17(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
24018
24868
|
const periodType = periodTypeFrom(period?.type);
|
|
24019
24869
|
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);
|
|
24020
24870
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -24041,11 +24891,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
24041
24891
|
};
|
|
24042
24892
|
}
|
|
24043
24893
|
function selectAccessToken(auth, now) {
|
|
24044
|
-
if (!
|
|
24894
|
+
if (!isRecord17(auth))
|
|
24045
24895
|
return null;
|
|
24046
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
24896
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord17(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")));
|
|
24047
24897
|
for (const [, value] of entries) {
|
|
24048
|
-
if (!
|
|
24898
|
+
if (!isRecord17(value) || typeof value.key !== "string")
|
|
24049
24899
|
continue;
|
|
24050
24900
|
if (typeof value.expires_at === "string") {
|
|
24051
24901
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -24066,8 +24916,8 @@ async function fetchGrokAccount(input = {}) {
|
|
|
24066
24916
|
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((value) => value?.trim()))
|
|
24067
24917
|
return null;
|
|
24068
24918
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
24069
|
-
const authPath =
|
|
24070
|
-
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await
|
|
24919
|
+
const authPath = path14.join(grokHome2(environment), "auth.json");
|
|
24920
|
+
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile5(authPath, "utf8");
|
|
24071
24921
|
const token = selectAccessToken(JSON.parse(raw), now);
|
|
24072
24922
|
if (!token)
|
|
24073
24923
|
return null;
|
|
@@ -24117,7 +24967,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
24117
24967
|
|
|
24118
24968
|
// dist/grok-usage.js
|
|
24119
24969
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
24120
|
-
function
|
|
24970
|
+
function isRecord18(value) {
|
|
24121
24971
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24122
24972
|
}
|
|
24123
24973
|
function optionalToken(value) {
|
|
@@ -24134,7 +24984,7 @@ function combineUsage(base, next) {
|
|
|
24134
24984
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
24135
24985
|
}
|
|
24136
24986
|
function usageFromNative(value) {
|
|
24137
|
-
if (!
|
|
24987
|
+
if (!isRecord18(value))
|
|
24138
24988
|
return null;
|
|
24139
24989
|
const nativeInputTokens = optionalToken(value.inputTokens);
|
|
24140
24990
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -24159,11 +25009,111 @@ function usageFromNative(value) {
|
|
|
24159
25009
|
return null;
|
|
24160
25010
|
}
|
|
24161
25011
|
}
|
|
24162
|
-
function
|
|
24163
|
-
|
|
25012
|
+
function usageFromResponse(value) {
|
|
25013
|
+
if (!isRecord18(value))
|
|
25014
|
+
return null;
|
|
25015
|
+
const buckets = [
|
|
25016
|
+
value.input_tokens,
|
|
25017
|
+
value.cache_read_input_tokens,
|
|
25018
|
+
value.cache_creation_input_tokens
|
|
25019
|
+
];
|
|
25020
|
+
const inputTokens = buckets.every((n) => typeof n === "number" && Number.isSafeInteger(n) && n >= 0) ? buckets.reduce((sum, n) => sum + n, 0) : void 0;
|
|
25021
|
+
const outputTokens = optionalToken(value.output_tokens);
|
|
25022
|
+
return usageFromNative({
|
|
25023
|
+
inputTokens,
|
|
25024
|
+
outputTokens,
|
|
25025
|
+
cachedReadTokens: value.cache_read_input_tokens,
|
|
25026
|
+
cacheCreationTokens: value.cache_creation_input_tokens,
|
|
25027
|
+
reasoningTokens: value.reasoning_tokens,
|
|
25028
|
+
...inputTokens !== void 0 && outputTokens !== void 0 ? { totalTokens: inputTokens + outputTokens } : {}
|
|
25029
|
+
});
|
|
24164
25030
|
}
|
|
25031
|
+
var GrokTurnUsage = class {
|
|
25032
|
+
#totals = {};
|
|
25033
|
+
#seen = /* @__PURE__ */ new Set();
|
|
25034
|
+
#cacheComplete;
|
|
25035
|
+
#compacting = false;
|
|
25036
|
+
#startedAtMs;
|
|
25037
|
+
#streamKey;
|
|
25038
|
+
#outputTokens = 0;
|
|
25039
|
+
#durationMs = 0;
|
|
25040
|
+
#latestCacheHit;
|
|
25041
|
+
#sessionInputTokens = 0;
|
|
25042
|
+
constructor(base, emptySession = false) {
|
|
25043
|
+
for (const field of summedUsageFields) {
|
|
25044
|
+
const value = base?.[field];
|
|
25045
|
+
if (value !== void 0)
|
|
25046
|
+
this.#totals[field] = value;
|
|
25047
|
+
}
|
|
25048
|
+
this.#cacheComplete = base?.sessionCacheUsage !== void 0 || emptySession;
|
|
25049
|
+
this.#sessionInputTokens = base?.sessionCacheUsage?.inputTokens ?? 0;
|
|
25050
|
+
}
|
|
25051
|
+
observe(event) {
|
|
25052
|
+
if (event.type === "compaction.started" || event.type === "compaction.completed") {
|
|
25053
|
+
this.#startedAtMs = void 0;
|
|
25054
|
+
this.#streamKey = void 0;
|
|
25055
|
+
this.#compacting = event.type === "compaction.started";
|
|
25056
|
+
}
|
|
25057
|
+
if (this.#compacting)
|
|
25058
|
+
return null;
|
|
25059
|
+
if (event.type === "subagent.spawned")
|
|
25060
|
+
this.#cacheComplete = false;
|
|
25061
|
+
if (event.type === "agent.text" || event.type === "agent.thought" || event.type === "tool.input.delta") {
|
|
25062
|
+
if (!event.text)
|
|
25063
|
+
return null;
|
|
25064
|
+
const key = event.metadata?.streamStartMs;
|
|
25065
|
+
if (key !== void 0 && this.#streamKey !== void 0 && key !== this.#streamKey)
|
|
25066
|
+
this.#startedAtMs = void 0;
|
|
25067
|
+
if (key !== void 0)
|
|
25068
|
+
this.#streamKey = key;
|
|
25069
|
+
this.#startedAtMs ??= Date.now();
|
|
25070
|
+
}
|
|
25071
|
+
if (event.type !== "response.completed")
|
|
25072
|
+
return null;
|
|
25073
|
+
if (event.messageId) {
|
|
25074
|
+
if (this.#seen.has(event.messageId))
|
|
25075
|
+
return null;
|
|
25076
|
+
this.#seen.add(event.messageId);
|
|
25077
|
+
}
|
|
25078
|
+
const duration3 = this.#startedAtMs === void 0 ? 0 : Date.now() - this.#startedAtMs;
|
|
25079
|
+
this.#startedAtMs = void 0;
|
|
25080
|
+
this.#streamKey = void 0;
|
|
25081
|
+
const usage = usageFromResponse(event.usage);
|
|
25082
|
+
this.#latestCacheHit = usage?.cacheHitRatePercent;
|
|
25083
|
+
if (usage?.inputTokens === void 0 || usage.cachedInputTokens === void 0)
|
|
25084
|
+
this.#cacheComplete = false;
|
|
25085
|
+
if (usage) {
|
|
25086
|
+
this.#sessionInputTokens += (usage.inputTokens ?? 0) + (usage.cachedInputTokens ?? 0) + (usage.cacheWriteInputTokens ?? 0);
|
|
25087
|
+
for (const field of summedUsageFields) {
|
|
25088
|
+
const value = usage[field];
|
|
25089
|
+
if (value !== void 0)
|
|
25090
|
+
this.#totals[field] = (this.#totals[field] ?? 0) + value;
|
|
25091
|
+
}
|
|
25092
|
+
if (duration3 > 0 && usage.outputTokens !== void 0) {
|
|
25093
|
+
this.#outputTokens += usage.outputTokens;
|
|
25094
|
+
this.#durationMs += duration3;
|
|
25095
|
+
}
|
|
25096
|
+
}
|
|
25097
|
+
return this.snapshot();
|
|
25098
|
+
}
|
|
25099
|
+
metrics() {
|
|
25100
|
+
return {
|
|
25101
|
+
...this.#durationMs > 0 ? { outputTokensPerSecond: this.#outputTokens * 1e3 / this.#durationMs } : {},
|
|
25102
|
+
...this.#latestCacheHit !== void 0 ? { cacheHitRatePercent: this.#latestCacheHit } : {}
|
|
25103
|
+
};
|
|
25104
|
+
}
|
|
25105
|
+
snapshot() {
|
|
25106
|
+
const inputTokens = this.#totals.inputTokens;
|
|
25107
|
+
const cachedInputTokens = this.#totals.cachedInputTokens;
|
|
25108
|
+
return {
|
|
25109
|
+
...this.#totals,
|
|
25110
|
+
...this.metrics(),
|
|
25111
|
+
...this.#cacheComplete && inputTokens !== void 0 && cachedInputTokens !== void 0 ? { sessionCacheUsage: { inputTokens: this.#sessionInputTokens, cachedInputTokens } } : {}
|
|
25112
|
+
};
|
|
25113
|
+
}
|
|
25114
|
+
};
|
|
24165
25115
|
function usageFromSignals(value) {
|
|
24166
|
-
if (!
|
|
25116
|
+
if (!isRecord18(value))
|
|
24167
25117
|
return null;
|
|
24168
25118
|
try {
|
|
24169
25119
|
return parseHostUsage({
|
|
@@ -24183,13 +25133,23 @@ var summedUsageFields = [
|
|
|
24183
25133
|
"totalTokens"
|
|
24184
25134
|
];
|
|
24185
25135
|
function nativeCostTicks(value) {
|
|
24186
|
-
if (!
|
|
25136
|
+
if (!isRecord18(value))
|
|
24187
25137
|
return void 0;
|
|
24188
25138
|
const ticks = value.costUsdTicks;
|
|
24189
25139
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
24190
25140
|
return void 0;
|
|
24191
25141
|
return ticks;
|
|
24192
25142
|
}
|
|
25143
|
+
function sessionCostFromNative(value, initialCostUsd) {
|
|
25144
|
+
if (!isRecord18(value))
|
|
25145
|
+
return void 0;
|
|
25146
|
+
if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
|
|
25147
|
+
return void 0;
|
|
25148
|
+
if (value.usageIsIncomplete !== void 0 && value.usageIsIncomplete !== false)
|
|
25149
|
+
return void 0;
|
|
25150
|
+
const ticks = nativeCostTicks(value);
|
|
25151
|
+
return ticks === void 0 ? void 0 : optionalCostUsd(Math.round(initialCostUsd * USD_TICKS_PER_DOLLAR) + ticks);
|
|
25152
|
+
}
|
|
24193
25153
|
function historyTurnKey(event, index) {
|
|
24194
25154
|
const key = event.nativeTurnKey;
|
|
24195
25155
|
if (typeof key === "string" && key.startsWith("task-completed-"))
|
|
@@ -24198,7 +25158,6 @@ function historyTurnKey(event, index) {
|
|
|
24198
25158
|
}
|
|
24199
25159
|
function sessionUsageFromHistory(events) {
|
|
24200
25160
|
const latestByKey = /* @__PURE__ */ new Map();
|
|
24201
|
-
let lastCacheHitRatePercent;
|
|
24202
25161
|
let index = 0;
|
|
24203
25162
|
for (const event of events) {
|
|
24204
25163
|
if (event?.type !== "turn.completed")
|
|
@@ -24207,27 +25166,29 @@ function sessionUsageFromHistory(events) {
|
|
|
24207
25166
|
index += 1;
|
|
24208
25167
|
if (key === null)
|
|
24209
25168
|
continue;
|
|
24210
|
-
|
|
24211
|
-
if (!usage)
|
|
25169
|
+
if (event.usage === void 0 && latestByKey.has(key))
|
|
24212
25170
|
continue;
|
|
25171
|
+
const usage = usageFromNative(event.usage);
|
|
24213
25172
|
const ticks2 = nativeCostTicks(event.usage);
|
|
24214
|
-
|
|
24215
|
-
|
|
24216
|
-
lastCacheHitRatePercent = usage.cacheHitRatePercent;
|
|
24217
|
-
}
|
|
25173
|
+
const complete = isRecord18(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && typeof event.usage.inputTokens === "number" && usage.cachedInputTokens + (usage.cacheWriteInputTokens ?? 0) <= event.usage.inputTokens;
|
|
25174
|
+
latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
|
|
24218
25175
|
}
|
|
24219
25176
|
if (latestByKey.size === 0)
|
|
24220
25177
|
return null;
|
|
24221
|
-
const
|
|
25178
|
+
const totals2 = {};
|
|
25179
|
+
let sessionInputTokens = 0;
|
|
24222
25180
|
let ticks = 0;
|
|
24223
25181
|
let hasTicks = false;
|
|
24224
25182
|
for (const entry of latestByKey.values()) {
|
|
25183
|
+
if (!entry.usage)
|
|
25184
|
+
continue;
|
|
24225
25185
|
for (const field of summedUsageFields) {
|
|
24226
25186
|
const value = entry.usage[field];
|
|
24227
25187
|
if (value === void 0)
|
|
24228
25188
|
continue;
|
|
24229
|
-
|
|
25189
|
+
totals2[field] = (totals2[field] ?? 0) + value;
|
|
24230
25190
|
}
|
|
25191
|
+
sessionInputTokens += (entry.usage.inputTokens ?? 0) + (entry.usage.cachedInputTokens ?? 0) + (entry.usage.cacheWriteInputTokens ?? 0);
|
|
24231
25192
|
if (entry.ticks === void 0)
|
|
24232
25193
|
continue;
|
|
24233
25194
|
ticks += entry.ticks;
|
|
@@ -24236,9 +25197,14 @@ function sessionUsageFromHistory(events) {
|
|
|
24236
25197
|
const totalCostUsd = hasTicks ? optionalCostUsd(ticks) : void 0;
|
|
24237
25198
|
try {
|
|
24238
25199
|
return parseHostUsage({
|
|
24239
|
-
...
|
|
25200
|
+
...totals2,
|
|
24240
25201
|
...totalCostUsd !== void 0 ? { totalCostUsd } : {},
|
|
24241
|
-
...
|
|
25202
|
+
...[...latestByKey.values()].every((entry) => entry.complete) && totals2.inputTokens !== void 0 && totals2.cachedInputTokens !== void 0 ? {
|
|
25203
|
+
sessionCacheUsage: {
|
|
25204
|
+
inputTokens: sessionInputTokens,
|
|
25205
|
+
cachedInputTokens: totals2.cachedInputTokens
|
|
25206
|
+
}
|
|
25207
|
+
} : {}
|
|
24242
25208
|
});
|
|
24243
25209
|
} catch {
|
|
24244
25210
|
return null;
|
|
@@ -24260,7 +25226,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
24260
25226
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
24261
25227
|
try {
|
|
24262
25228
|
if (update?.sessionUpdate === "usage_update") {
|
|
24263
|
-
const cost =
|
|
25229
|
+
const cost = isRecord18(update.cost) ? update.cost : null;
|
|
24264
25230
|
return parseHostUsage({
|
|
24265
25231
|
contextUsedTokens: update.used,
|
|
24266
25232
|
contextWindowTokens: update.size,
|
|
@@ -24392,6 +25358,8 @@ var GrokHarnessSession = class {
|
|
|
24392
25358
|
#phase = "open";
|
|
24393
25359
|
#state;
|
|
24394
25360
|
#usage = null;
|
|
25361
|
+
#initialCostUsd;
|
|
25362
|
+
#costRequest = 0;
|
|
24395
25363
|
constructor(cwd, transport, opened, modelState, onClosed, options) {
|
|
24396
25364
|
this.#cwd = cwd;
|
|
24397
25365
|
this.#sessionDirectory = options.sessionDirectory;
|
|
@@ -24405,6 +25373,7 @@ var GrokHarnessSession = class {
|
|
|
24405
25373
|
this.#toolOutputLimit = options.toolOutputLimit;
|
|
24406
25374
|
this.initialUsage = options.initialUsage ?? null;
|
|
24407
25375
|
this.#usage = this.initialUsage;
|
|
25376
|
+
this.#initialCostUsd = this.initialUsage?.totalCostUsd ?? 0;
|
|
24408
25377
|
this.capabilities = capabilitiesForModels(modelState);
|
|
24409
25378
|
this.commands = {
|
|
24410
25379
|
list: async () => ({ ok: true, value: this.#liveCommandCatalog() }),
|
|
@@ -24493,6 +25462,7 @@ var GrokHarnessSession = class {
|
|
|
24493
25462
|
});
|
|
24494
25463
|
const active = {
|
|
24495
25464
|
command,
|
|
25465
|
+
usage: new GrokTurnUsage(this.#usage, this.#snapshot.turns.length === 0),
|
|
24496
25466
|
agent: null,
|
|
24497
25467
|
agentMessageId: null,
|
|
24498
25468
|
rawAgentText: "",
|
|
@@ -24670,9 +25640,9 @@ var GrokHarnessSession = class {
|
|
|
24670
25640
|
}
|
|
24671
25641
|
async #selectThinking(command) {
|
|
24672
25642
|
const parsed = harnessThinkingOptionIdSchema.safeParse(command.thinkingOptionId);
|
|
24673
|
-
const
|
|
24674
|
-
const available = this.#modelState.catalog.models.find(({ ref }) => ref.id ===
|
|
24675
|
-
if (!parsed.success || !
|
|
25643
|
+
const model2 = this.#state.effectiveModel;
|
|
25644
|
+
const available = this.#modelState.catalog.models.find(({ ref }) => ref.id === model2?.id);
|
|
25645
|
+
if (!parsed.success || !model2 || !available?.supportedThinkingOptionIds?.includes(parsed.data)) {
|
|
24676
25646
|
return {
|
|
24677
25647
|
ok: false,
|
|
24678
25648
|
error: {
|
|
@@ -24682,9 +25652,9 @@ var GrokHarnessSession = class {
|
|
|
24682
25652
|
}
|
|
24683
25653
|
};
|
|
24684
25654
|
}
|
|
24685
|
-
return this.#configure(
|
|
25655
|
+
return this.#configure(model2, parsed.data);
|
|
24686
25656
|
}
|
|
24687
|
-
async #configure(
|
|
25657
|
+
async #configure(model2, thinkingOptionId) {
|
|
24688
25658
|
if (this.#configuring) {
|
|
24689
25659
|
return {
|
|
24690
25660
|
ok: false,
|
|
@@ -24697,9 +25667,20 @@ var GrokHarnessSession = class {
|
|
|
24697
25667
|
}
|
|
24698
25668
|
this.#configuring = true;
|
|
24699
25669
|
try {
|
|
24700
|
-
|
|
24701
|
-
|
|
25670
|
+
const contextWindow = this.#modelState.defaultContextWindowTokensByModel.get(model2.id);
|
|
25671
|
+
await this.#transport.setModel(model2.id, thinkingOptionId, contextWindow);
|
|
25672
|
+
if (contextWindow !== void 0) {
|
|
25673
|
+
this.#modelState.contextWindowTokensByModel = new Map([
|
|
25674
|
+
...this.#modelState.contextWindowTokensByModel,
|
|
25675
|
+
[model2.id, contextWindow]
|
|
25676
|
+
]);
|
|
25677
|
+
}
|
|
25678
|
+
this.#state = stateForGrokModel(this.#modelState, { nativeRef: nativeRef(this.#transport.sessionId) }, model2, thinkingOptionId, this.#state.effectivePermissionModeId);
|
|
24702
25679
|
this.#event({ type: "session.state.changed", state: this.#state });
|
|
25680
|
+
const selectedWindow = this.#modelState.contextWindowTokensByModel.get(model2.id);
|
|
25681
|
+
if (selectedWindow !== void 0 && this.#usage?.contextUsedTokens !== void 0) {
|
|
25682
|
+
this.#publishUsage({ contextWindowTokens: selectedWindow });
|
|
25683
|
+
}
|
|
24703
25684
|
return { ok: true, value: { completed: true } };
|
|
24704
25685
|
} catch (error53) {
|
|
24705
25686
|
return { ok: false, error: normalizeError(error53, "nativeFailure") };
|
|
@@ -24912,6 +25893,11 @@ var GrokHarnessSession = class {
|
|
|
24912
25893
|
#handleEvent(active, event) {
|
|
24913
25894
|
if (this.#active !== active || this.#phase !== "open")
|
|
24914
25895
|
return;
|
|
25896
|
+
const requestUsage = active.usage?.observe(event);
|
|
25897
|
+
if (requestUsage) {
|
|
25898
|
+
this.#publishUsage(requestUsage, active.command.turnId, true);
|
|
25899
|
+
void this.#refreshCost(active);
|
|
25900
|
+
}
|
|
24915
25901
|
const contextUsage = usageFromUpdate(event.type === "usage" ? event.update : void 0, event.metadata, this.#state.effectiveModel ? this.#modelState.contextWindowTokensByModel.get(this.#state.effectiveModel.id) : void 0);
|
|
24916
25902
|
if (contextUsage)
|
|
24917
25903
|
this.#publishUsage(contextUsage, active.command.turnId);
|
|
@@ -24935,6 +25921,17 @@ var GrokHarnessSession = class {
|
|
|
24935
25921
|
} else if (event.type === "usage" || event.type === "turn.completed")
|
|
24936
25922
|
return;
|
|
24937
25923
|
}
|
|
25924
|
+
async #refreshCost(active) {
|
|
25925
|
+
const request = ++this.#costRequest;
|
|
25926
|
+
try {
|
|
25927
|
+
const totalCostUsd = sessionCostFromNative(await this.#transport.getUsage(), this.#initialCostUsd);
|
|
25928
|
+
if (this.#active !== active || this.#phase !== "open" || request !== this.#costRequest)
|
|
25929
|
+
return;
|
|
25930
|
+
if (totalCostUsd !== void 0)
|
|
25931
|
+
this.#publishUsage({ totalCostUsd }, active.command.turnId);
|
|
25932
|
+
} catch {
|
|
25933
|
+
}
|
|
25934
|
+
}
|
|
24938
25935
|
#startCompaction(active, event) {
|
|
24939
25936
|
if (active.compactionItem)
|
|
24940
25937
|
return;
|
|
@@ -25047,14 +26044,14 @@ var GrokHarnessSession = class {
|
|
|
25047
26044
|
const prompt = grokSubagentPrompt(event.rawInput);
|
|
25048
26045
|
const role = grokSubagentRole(event.rawInput);
|
|
25049
26046
|
const nativeSubagentId = grokNativeSubagentId(event.rawInput);
|
|
25050
|
-
const
|
|
26047
|
+
const model2 = grokSubagentModel(event.rawInput);
|
|
25051
26048
|
active.subagents.start(active.command.turnId, {
|
|
25052
26049
|
callId: event.callId,
|
|
25053
26050
|
operation,
|
|
25054
26051
|
description: grokSubagentDescription(event.rawInput, event.title),
|
|
25055
26052
|
...prompt ? { prompt } : {},
|
|
25056
26053
|
...role ? { role } : {},
|
|
25057
|
-
...
|
|
26054
|
+
...model2 ? { model: model2 } : {},
|
|
25058
26055
|
background: grokSubagentBackground(event.rawInput),
|
|
25059
26056
|
...nativeSubagentId ? { nativeSubagentId } : {}
|
|
25060
26057
|
});
|
|
@@ -25276,7 +26273,17 @@ var GrokHarnessSession = class {
|
|
|
25276
26273
|
checkpoint = created[0]?.checkpoint;
|
|
25277
26274
|
} catch {
|
|
25278
26275
|
}
|
|
25279
|
-
|
|
26276
|
+
const promptUsage = response?.usage ?? response?._meta?.usage;
|
|
26277
|
+
if (nativeTurnRef && promptUsage !== void 0 && !history.some((event) => event.type === "turn.completed" && event.nativeTurnKey === nativeTurnRef.nativeTurnKey && event.usage !== void 0)) {
|
|
26278
|
+
history.push({
|
|
26279
|
+
type: "turn.completed",
|
|
26280
|
+
nativeTurnKey: nativeTurnRef.nativeTurnKey,
|
|
26281
|
+
stopReason: response?.stopReason ?? "end_turn",
|
|
26282
|
+
usage: promptUsage
|
|
26283
|
+
});
|
|
26284
|
+
}
|
|
26285
|
+
const usage = sessionUsageFromHistory(history) ?? usageFromNative(promptUsage);
|
|
26286
|
+
this.#finish(active, checkpoint ? { ...outcome, checkpoint } : outcome, usage, nativeTurnRef);
|
|
25280
26287
|
void this.#refreshCredits().catch(() => void 0);
|
|
25281
26288
|
}
|
|
25282
26289
|
#finish(active, outcome, usage = null, nativeTurnRef) {
|
|
@@ -25295,8 +26302,8 @@ var GrokHarnessSession = class {
|
|
|
25295
26302
|
active.tools.clear();
|
|
25296
26303
|
this.#closePendingInteractions(active, "cancelled");
|
|
25297
26304
|
this.#active = null;
|
|
25298
|
-
if (usage)
|
|
25299
|
-
this.#publishUsage(usage, active.command.turnId);
|
|
26305
|
+
if (usage || this.#usage)
|
|
26306
|
+
this.#publishUsage({ ...usage, ...active.usage?.metrics() }, active.command.turnId, true);
|
|
25300
26307
|
this.#event({
|
|
25301
26308
|
type: "turn.completed",
|
|
25302
26309
|
turnId: active.command.turnId,
|
|
@@ -25305,8 +26312,14 @@ var GrokHarnessSession = class {
|
|
|
25305
26312
|
});
|
|
25306
26313
|
active.resolveCompletion();
|
|
25307
26314
|
}
|
|
25308
|
-
#publishUsage(usage, observedForTurnId) {
|
|
25309
|
-
const
|
|
26315
|
+
#publishUsage(usage, observedForTurnId, replaceMetrics = false) {
|
|
26316
|
+
const base = this.#usage ? { ...this.#usage } : null;
|
|
26317
|
+
if (base && replaceMetrics) {
|
|
26318
|
+
delete base.outputTokensPerSecond;
|
|
26319
|
+
delete base.cacheHitRatePercent;
|
|
26320
|
+
delete base.sessionCacheUsage;
|
|
26321
|
+
}
|
|
26322
|
+
const merged = combineUsage(base, usage);
|
|
25310
26323
|
if (merged === null || JSON.stringify(merged) === JSON.stringify(this.#usage))
|
|
25311
26324
|
return;
|
|
25312
26325
|
this.#usage = merged;
|
|
@@ -25367,6 +26380,8 @@ var GrokAdapter = class {
|
|
|
25367
26380
|
commandCatalog = grokCommandCatalog;
|
|
25368
26381
|
liveCommandCatalog = true;
|
|
25369
26382
|
harnessId = grokHarnessId;
|
|
26383
|
+
sessionImport;
|
|
26384
|
+
usageStatistics;
|
|
25370
26385
|
subagents = {
|
|
25371
26386
|
readSnapshot: async (input) => {
|
|
25372
26387
|
if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
|
|
@@ -25415,6 +26430,8 @@ var GrokAdapter = class {
|
|
|
25415
26430
|
constructor(options = {}, dependencies) {
|
|
25416
26431
|
this.#closeTimeoutMs = options.closeTimeoutMs ?? DEFAULT_CLOSE_TIMEOUT_MS;
|
|
25417
26432
|
this.#environment = options.environment;
|
|
26433
|
+
this.sessionImport = new GrokSessionImport(options.environment);
|
|
26434
|
+
this.usageStatistics = createGrokUsageStatistics(options.environment ?? process.env);
|
|
25418
26435
|
this.#toolOutputLimit = options.toolOutputLimit ?? DEFAULT_GROK_TOOL_OUTPUT_LIMIT;
|
|
25419
26436
|
this.#dependencies = dependencies ?? {
|
|
25420
26437
|
randomUUID,
|
|
@@ -25463,7 +26480,7 @@ var GrokAdapter = class {
|
|
|
25463
26480
|
async inspect(input = {}) {
|
|
25464
26481
|
if (this.#closePromise)
|
|
25465
26482
|
return { status: "unavailable", error: invalidState("Grok Adapter is closed") };
|
|
25466
|
-
const cwd =
|
|
26483
|
+
const cwd = path15.resolve(input.cwd ?? process.cwd());
|
|
25467
26484
|
if (!input.refresh) {
|
|
25468
26485
|
const cached2 = this.#inspectionCache.get(cwd);
|
|
25469
26486
|
if (cached2)
|
|
@@ -25525,7 +26542,7 @@ var GrokAdapter = class {
|
|
|
25525
26542
|
}
|
|
25526
26543
|
};
|
|
25527
26544
|
}
|
|
25528
|
-
const cwd =
|
|
26545
|
+
const cwd = path15.resolve(input.cwd);
|
|
25529
26546
|
const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
|
|
25530
26547
|
if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
|
|
25531
26548
|
return {
|
|
@@ -25629,6 +26646,8 @@ var GrokAdapter = class {
|
|
|
25629
26646
|
const modelState = modelStateFromSessionResponse(opened.session) ?? modelStateFromInitialize(opened.initialize);
|
|
25630
26647
|
if (!modelState)
|
|
25631
26648
|
throw new GrokTransportError("protocolError", "Grok returned an invalid Model catalog");
|
|
26649
|
+
const nativeModelId = modelState.currentModel.id;
|
|
26650
|
+
const nativeThinkingOptionId = modelState.currentThinkingOptionId;
|
|
25632
26651
|
const retainedConfiguration = sourceConfiguration;
|
|
25633
26652
|
if ((input.kind === "rollbackLastTurn" || input.kind === "fork") && retainedConfiguration) {
|
|
25634
26653
|
const operation = input.kind === "rollbackLastTurn" ? "Rewind" : "Fork";
|
|
@@ -25641,7 +26660,6 @@ var GrokAdapter = class {
|
|
|
25641
26660
|
throw new GrokTransportError("protocolError", `Grok Thinking option is unavailable after ${operation}`);
|
|
25642
26661
|
}
|
|
25643
26662
|
if (retainedConfiguration.model.id !== modelState.currentModel.id || retainedConfiguration.thinkingOptionId !== modelState.currentThinkingOptionId) {
|
|
25644
|
-
await transport.setModel(retainedConfiguration.model.id, retainedConfiguration.thinkingOptionId);
|
|
25645
26663
|
modelState.currentModel = retainedConfiguration.model;
|
|
25646
26664
|
if (retainedConfiguration.thinkingOptionId) {
|
|
25647
26665
|
modelState.currentThinkingOptionId = retainedConfiguration.thinkingOptionId;
|
|
@@ -25660,7 +26678,6 @@ var GrokAdapter = class {
|
|
|
25660
26678
|
throw new GrokTransportError("protocolError", "Requested Grok Thinking option is unavailable");
|
|
25661
26679
|
}
|
|
25662
26680
|
if (selectedModel.id !== modelState.currentModel.id || selectedThinking !== modelState.currentThinkingOptionId) {
|
|
25663
|
-
await transport.setModel(selectedModel.id, selectedThinking);
|
|
25664
26681
|
modelState.currentModel = selectedModel;
|
|
25665
26682
|
if (selectedThinking)
|
|
25666
26683
|
modelState.currentThinkingOptionId = selectedThinking;
|
|
@@ -25668,8 +26685,21 @@ var GrokAdapter = class {
|
|
|
25668
26685
|
delete modelState.currentThinkingOptionId;
|
|
25669
26686
|
}
|
|
25670
26687
|
}
|
|
26688
|
+
const contextWindow = modelState.defaultContextWindowTokensByModel.get(modelState.currentModel.id);
|
|
26689
|
+
if (modelState.currentModel.id !== nativeModelId || modelState.currentThinkingOptionId !== nativeThinkingOptionId || contextWindow !== void 0 && modelState.contextWindowTokensByModel.get(modelState.currentModel.id) !== contextWindow) {
|
|
26690
|
+
await transport.setModel(modelState.currentModel.id, modelState.currentThinkingOptionId, contextWindow);
|
|
26691
|
+
if (contextWindow !== void 0) {
|
|
26692
|
+
modelState.contextWindowTokensByModel = new Map([
|
|
26693
|
+
...modelState.contextWindowTokensByModel,
|
|
26694
|
+
[modelState.currentModel.id, contextWindow]
|
|
26695
|
+
]);
|
|
26696
|
+
}
|
|
26697
|
+
}
|
|
25671
26698
|
const history = await transport.getHistory();
|
|
25672
|
-
|
|
26699
|
+
let initialUsage = input.kind === "resume" || input.kind === "fork" || input.kind === "rollbackLastTurn" ? combineUsage(sessionUsageFromHistory(history), usageFromSignals(opened.signals)) : null;
|
|
26700
|
+
if (contextWindow !== void 0 && initialUsage?.contextUsedTokens !== void 0) {
|
|
26701
|
+
initialUsage = combineUsage(initialUsage, { contextWindowTokens: contextWindow });
|
|
26702
|
+
}
|
|
25673
26703
|
const environment = input.environment ?? this.#environment;
|
|
25674
26704
|
const sessionDirectory = grokNativeSessionDirectory(environment ? { cwd, environment } : { cwd }, opened.sessionId);
|
|
25675
26705
|
const openedSession = new GrokHarnessSession(cwd, transport, opened, modelState, () => this.#sessions.delete(openedSession), {
|
|
@@ -25696,7 +26726,10 @@ var GrokAdapter = class {
|
|
|
25696
26726
|
if (!this.#closePromise) {
|
|
25697
26727
|
this.#accountAbort.abort();
|
|
25698
26728
|
this.#inspectionCache.clear();
|
|
25699
|
-
this.#closePromise = Promise.all([
|
|
26729
|
+
this.#closePromise = Promise.all([
|
|
26730
|
+
this.sessionImport.close(),
|
|
26731
|
+
...[...this.#sessions].map((session) => session.close())
|
|
26732
|
+
]).then(() => void 0);
|
|
25700
26733
|
}
|
|
25701
26734
|
return this.#closePromise;
|
|
25702
26735
|
}
|