@codexhost/cli-darwin-x64 0.12.2 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES.txt +9 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +319 -64
- package/app/console-web.js +5089 -1367
- package/app/desktop-controller.mjs +259 -41
- package/app/host-runtime.mjs +5735 -1564
- package/app/plugins/antigravity/manifest.json +18 -1
- package/app/plugins/antigravity/plugin.mjs +282 -41
- package/app/plugins/claude-code/manifest.json +28 -0
- package/app/plugins/claude-code/plugin.mjs +35300 -23918
- package/app/plugins/codebuddy/manifest.json +17 -0
- package/app/plugins/codebuddy/plugin.mjs +5971 -5355
- package/app/plugins/codex-usage/manifest.json +9 -0
- package/app/plugins/codex-usage/plugin.mjs +17324 -0
- package/app/plugins/cursor-cli/manifest.json +17 -0
- package/app/plugins/cursor-cli/plugin.mjs +357 -76
- 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 +822 -241
- package/app/plugins/enabled.json +2 -1
- package/app/plugins/grok/manifest.json +21 -1
- package/app/plugins/grok/plugin.mjs +918 -258
- package/app/plugins/hermes/assets/icon.png +0 -0
- package/app/plugins/hermes/manifest.json +30 -2
- package/app/plugins/hermes/plugin.mjs +284 -32
- 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 +561 -35
- 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 +290 -21
- package/app/plugins/omp/manifest.json +21 -1
- package/app/plugins/omp/plugin.mjs +2765 -1960
- package/app/plugins/opencode/manifest.json +18 -1
- package/app/plugins/opencode/plugin.mjs +723 -146
- package/app/plugins/pi/manifest.json +32 -0
- package/app/plugins/pi/plugin.mjs +2908 -2312
- package/app/plugins/qoder/manifest.json +18 -1
- package/app/plugins/qoder/plugin.mjs +634 -80
- package/app/plugins/qoder-cn/manifest.json +18 -1
- package/app/plugins/qoder-cn/plugin.mjs +634 -80
- package/app/plugins/workbuddy/manifest.json +18 -0
- package/app/plugins/workbuddy/plugin.mjs +6361 -5747
- package/app/plugins/zcode/manifest.json +19 -1
- package/app/plugins/zcode/plugin.mjs +1098 -259
- package/app/renderer-extension.js +13080 -8884
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +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,208 @@ 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
|
+
var MAX_SESSION_TITLE_LENGTH = 200;
|
|
388
|
+
function usageSessionTitle(value) {
|
|
389
|
+
if (typeof value !== "string")
|
|
390
|
+
return void 0;
|
|
391
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
392
|
+
if (!normalized)
|
|
393
|
+
return void 0;
|
|
394
|
+
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
395
|
+
return normalized;
|
|
396
|
+
const characters = [...normalized];
|
|
397
|
+
if (characters.length <= MAX_SESSION_TITLE_LENGTH)
|
|
398
|
+
return normalized;
|
|
399
|
+
return `${characters.slice(0, MAX_SESSION_TITLE_LENGTH - 1).join("").trimEnd()}…`;
|
|
400
|
+
}
|
|
401
|
+
function sessionIdOk(value) {
|
|
402
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
403
|
+
}
|
|
404
|
+
function cwdOk(value) {
|
|
405
|
+
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("\\\\"));
|
|
406
|
+
}
|
|
407
|
+
function withUsageSession(entry, session) {
|
|
408
|
+
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
409
|
+
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
410
|
+
const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
|
|
411
|
+
if (sessionId === void 0 && cwd === void 0)
|
|
412
|
+
return entry;
|
|
413
|
+
return {
|
|
414
|
+
...entry,
|
|
415
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
416
|
+
...cwd !== void 0 ? { cwd } : {},
|
|
417
|
+
...sessionTitle !== void 0 ? { sessionTitle } : {}
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
async function jsonlUsageSources(root, maxDepth, signal) {
|
|
421
|
+
const sources = [];
|
|
422
|
+
const visit = async (directory, depth) => {
|
|
423
|
+
signal.throwIfAborted();
|
|
424
|
+
const entries = await opendir(directory).catch((error53) => {
|
|
425
|
+
if (error53.code === "ENOENT")
|
|
426
|
+
return null;
|
|
427
|
+
throw error53;
|
|
428
|
+
});
|
|
429
|
+
if (!entries)
|
|
430
|
+
return;
|
|
431
|
+
for await (const entry of entries) {
|
|
432
|
+
signal.throwIfAborted();
|
|
433
|
+
const file2 = path4.join(directory, entry.name);
|
|
434
|
+
if (entry.isDirectory()) {
|
|
435
|
+
if (depth < maxDepth)
|
|
436
|
+
await visit(file2, depth + 1);
|
|
437
|
+
} else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
438
|
+
const info = await lstat(file2).catch(() => null);
|
|
439
|
+
if (info?.isFile() && info.size > 0) {
|
|
440
|
+
sources.push({ id: file2, fingerprint: `${info.ino}:${info.size}:${info.mtimeMs}` });
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
await visit(root, 0);
|
|
446
|
+
return sources;
|
|
447
|
+
}
|
|
448
|
+
async function* jsonlRecords(file2, marker, signal) {
|
|
449
|
+
const lines = createInterface({
|
|
450
|
+
input: createReadStream(file2, { encoding: "utf8", signal }),
|
|
451
|
+
crlfDelay: Infinity
|
|
452
|
+
});
|
|
453
|
+
for await (const line of lines) {
|
|
454
|
+
if (!line.includes(marker))
|
|
455
|
+
continue;
|
|
456
|
+
let value;
|
|
457
|
+
try {
|
|
458
|
+
value = JSON.parse(line);
|
|
459
|
+
} catch {
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
463
|
+
yield value;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function nativeTimeMs(value) {
|
|
468
|
+
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
469
|
+
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// dist/usage-statistics.js
|
|
473
|
+
function isRecord(value) {
|
|
474
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
475
|
+
}
|
|
476
|
+
var USD_TICKS = 1e10;
|
|
477
|
+
function count(value) {
|
|
478
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
479
|
+
}
|
|
480
|
+
function grokHome(environment) {
|
|
481
|
+
return environment.GROK_HOME || path5.join(environment.HOME || os2.homedir(), ".grok");
|
|
482
|
+
}
|
|
483
|
+
async function grokSummary(directory) {
|
|
484
|
+
try {
|
|
485
|
+
const summary = JSON.parse(await readFile(path5.join(directory, "summary.json"), "utf8"));
|
|
486
|
+
if (!isRecord(summary))
|
|
487
|
+
return { forkedAt: null };
|
|
488
|
+
const title = usageSessionTitle(summary.generated_title) ?? usageSessionTitle(summary.session_summary);
|
|
489
|
+
return {
|
|
490
|
+
forkedAt: typeof summary.parent_session_id === "string" ? nativeTimeMs(summary.created_at) : null,
|
|
491
|
+
...title ? { title } : {}
|
|
492
|
+
};
|
|
493
|
+
} catch {
|
|
494
|
+
return { forkedAt: null };
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function grokSession(file2) {
|
|
498
|
+
const directory = path5.dirname(file2);
|
|
499
|
+
let cwd;
|
|
500
|
+
try {
|
|
501
|
+
cwd = decodeURIComponent(path5.basename(path5.dirname(directory)));
|
|
502
|
+
} catch {
|
|
503
|
+
cwd = void 0;
|
|
504
|
+
}
|
|
505
|
+
return { sessionId: path5.basename(directory), cwd };
|
|
506
|
+
}
|
|
507
|
+
async function readGrokUsage(file2, signal) {
|
|
508
|
+
const summary = await grokSummary(path5.dirname(file2));
|
|
509
|
+
const forkedAt = summary.forkedAt;
|
|
510
|
+
let title = summary.title;
|
|
511
|
+
const session = grokSession(file2);
|
|
512
|
+
const entries = [];
|
|
513
|
+
for await (const line of jsonlRecords(file2, '"sessionUpdate"', signal)) {
|
|
514
|
+
const params = isRecord(line.params) ? line.params : {};
|
|
515
|
+
const update = isRecord(params.update) ? params.update : {};
|
|
516
|
+
if (!title && update.sessionUpdate === "user_message_chunk") {
|
|
517
|
+
title = usageSessionTitle(isRecord(update.content) ? update.content.text : void 0);
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
const usage = isRecord(update.usage) ? update.usage : {};
|
|
521
|
+
if (update.sessionUpdate !== "turn_completed" || typeof update.prompt_id !== "string")
|
|
522
|
+
continue;
|
|
523
|
+
const meta3 = isRecord(params._meta) ? params._meta : {};
|
|
524
|
+
const at = nativeTimeMs(meta3.agentTimestampMs) ?? (typeof line.timestamp === "number" ? nativeTimeMs(line.timestamp * 1e3) : null);
|
|
525
|
+
if (at === null || forkedAt !== null && at <= forkedAt)
|
|
526
|
+
continue;
|
|
527
|
+
for (const [model2, value] of Object.entries(isRecord(usage.modelUsage) ? usage.modelUsage : {})) {
|
|
528
|
+
if (!isRecord(value))
|
|
529
|
+
continue;
|
|
530
|
+
const input = count(value.inputTokens);
|
|
531
|
+
const output = count(value.outputTokens);
|
|
532
|
+
const cached2 = count(value.cachedReadTokens);
|
|
533
|
+
const written = count(value.cacheCreationTokens ?? 0);
|
|
534
|
+
const reasoning = count(value.reasoningTokens);
|
|
535
|
+
const ticks = count(value.costUsdTicks);
|
|
536
|
+
if (input === null || output === null || value.totalTokens !== input + output)
|
|
537
|
+
continue;
|
|
538
|
+
const cacheKnown = cached2 !== null && cached2 <= input && written === 0;
|
|
539
|
+
entries.push(withUsageSession({
|
|
540
|
+
id: `${update.prompt_id}:${model2}`,
|
|
541
|
+
occurredAtMs: at,
|
|
542
|
+
model: model2,
|
|
543
|
+
inputTokens: input,
|
|
544
|
+
...cacheKnown ? { cachedInputTokens: cached2, cacheWriteInputTokens: 0 } : {},
|
|
545
|
+
outputTokens: output,
|
|
546
|
+
...reasoning !== null && reasoning <= output ? { reasoningOutputTokens: reasoning } : {},
|
|
547
|
+
// A turn Grok marks incomplete has no cost of its own; it counts as free rather
|
|
548
|
+
// than as a model without a price.
|
|
549
|
+
...ticks !== null ? { costUsd: ticks / USD_TICKS } : usage.usageIsIncomplete === true ? { costUsd: 0 } : {}
|
|
550
|
+
}, { ...session, ...title ? { title } : {} }));
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return entries;
|
|
554
|
+
}
|
|
555
|
+
function createGrokUsageStatistics(environment) {
|
|
556
|
+
return Object.freeze({
|
|
557
|
+
// sessions/<url-encoded cwd>/<session>/updates.jsonl; subagents are sessions of their own.
|
|
558
|
+
listSources: async (signal) => (await jsonlUsageSources(path5.join(grokHome(environment), "sessions"), 2, signal)).filter((source) => path5.basename(source.id) === "updates.jsonl"),
|
|
559
|
+
readSource: (id, signal) => readGrokUsage(id, signal)
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
375
563
|
// dist/grok-adapter.js
|
|
376
564
|
import { randomUUID } from "node:crypto";
|
|
377
565
|
|
|
378
566
|
// dist/grok-credential-export.js
|
|
379
567
|
import { createHash } from "node:crypto";
|
|
380
|
-
import { readFile } from "node:fs/promises";
|
|
381
|
-
import
|
|
382
|
-
import
|
|
568
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
569
|
+
import os3 from "node:os";
|
|
570
|
+
import path6 from "node:path";
|
|
383
571
|
async function readGrokCredentials(environment) {
|
|
384
572
|
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((v) => v?.trim()))
|
|
385
573
|
return [];
|
|
386
574
|
try {
|
|
387
|
-
const home = environment.GROK_HOME ??
|
|
388
|
-
const auth = JSON.parse(await
|
|
575
|
+
const home = environment.GROK_HOME ?? path6.join(environment.HOME ?? os3.homedir(), ".grok");
|
|
576
|
+
const auth = JSON.parse(await readFile2(path6.join(home, "auth.json"), "utf8"));
|
|
389
577
|
const client2 = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
390
578
|
const entry = auth[`https://auth.x.ai::${client2}`] ?? auth["https://auth.x.ai"];
|
|
391
579
|
if (!entry || entry.oidc_issuer !== "https://auth.x.ai" || entry.oidc_client_id !== client2)
|
|
@@ -412,7 +600,7 @@ async function readGrokCredentials(environment) {
|
|
|
412
600
|
}
|
|
413
601
|
|
|
414
602
|
// dist/grok-adapter.js
|
|
415
|
-
import
|
|
603
|
+
import path15 from "node:path";
|
|
416
604
|
|
|
417
605
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
418
606
|
var external_exports = {};
|
|
@@ -1180,10 +1368,10 @@ function mergeDefs(...defs) {
|
|
|
1180
1368
|
function cloneDef(schema) {
|
|
1181
1369
|
return mergeDefs(schema._zod.def);
|
|
1182
1370
|
}
|
|
1183
|
-
function getElementAtPath(obj,
|
|
1184
|
-
if (!
|
|
1371
|
+
function getElementAtPath(obj, path16) {
|
|
1372
|
+
if (!path16)
|
|
1185
1373
|
return obj;
|
|
1186
|
-
return
|
|
1374
|
+
return path16.reduce((acc, key) => acc?.[key], obj);
|
|
1187
1375
|
}
|
|
1188
1376
|
function promiseAllObject(promisesObj) {
|
|
1189
1377
|
const keys = Object.keys(promisesObj);
|
|
@@ -1592,11 +1780,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
1592
1780
|
}
|
|
1593
1781
|
return false;
|
|
1594
1782
|
}
|
|
1595
|
-
function prefixIssues(
|
|
1783
|
+
function prefixIssues(path16, issues) {
|
|
1596
1784
|
return issues.map((iss) => {
|
|
1597
1785
|
var _a3;
|
|
1598
1786
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
1599
|
-
iss.path.unshift(
|
|
1787
|
+
iss.path.unshift(path16);
|
|
1600
1788
|
return iss;
|
|
1601
1789
|
});
|
|
1602
1790
|
}
|
|
@@ -1743,16 +1931,16 @@ function flattenError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1743
1931
|
}
|
|
1744
1932
|
function formatError(error53, mapper = (issue2) => issue2.message) {
|
|
1745
1933
|
const fieldErrors = { _errors: [] };
|
|
1746
|
-
const processError = (error54,
|
|
1934
|
+
const processError = (error54, path16 = []) => {
|
|
1747
1935
|
for (const issue2 of error54.issues) {
|
|
1748
1936
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1749
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1937
|
+
issue2.errors.map((issues) => processError({ issues }, [...path16, ...issue2.path]));
|
|
1750
1938
|
} else if (issue2.code === "invalid_key") {
|
|
1751
|
-
processError({ issues: issue2.issues }, [...
|
|
1939
|
+
processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
|
|
1752
1940
|
} else if (issue2.code === "invalid_element") {
|
|
1753
|
-
processError({ issues: issue2.issues }, [...
|
|
1941
|
+
processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
|
|
1754
1942
|
} else {
|
|
1755
|
-
const fullpath = [...
|
|
1943
|
+
const fullpath = [...path16, ...issue2.path];
|
|
1756
1944
|
if (fullpath.length === 0) {
|
|
1757
1945
|
fieldErrors._errors.push(mapper(issue2));
|
|
1758
1946
|
} else {
|
|
@@ -1779,17 +1967,17 @@ function formatError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1779
1967
|
}
|
|
1780
1968
|
function treeifyError(error53, mapper = (issue2) => issue2.message) {
|
|
1781
1969
|
const result = { errors: [] };
|
|
1782
|
-
const processError = (error54,
|
|
1970
|
+
const processError = (error54, path16 = []) => {
|
|
1783
1971
|
var _a3, _b;
|
|
1784
1972
|
for (const issue2 of error54.issues) {
|
|
1785
1973
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1786
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1974
|
+
issue2.errors.map((issues) => processError({ issues }, [...path16, ...issue2.path]));
|
|
1787
1975
|
} else if (issue2.code === "invalid_key") {
|
|
1788
|
-
processError({ issues: issue2.issues }, [...
|
|
1976
|
+
processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
|
|
1789
1977
|
} else if (issue2.code === "invalid_element") {
|
|
1790
|
-
processError({ issues: issue2.issues }, [...
|
|
1978
|
+
processError({ issues: issue2.issues }, [...path16, ...issue2.path]);
|
|
1791
1979
|
} else {
|
|
1792
|
-
const fullpath = [...
|
|
1980
|
+
const fullpath = [...path16, ...issue2.path];
|
|
1793
1981
|
if (fullpath.length === 0) {
|
|
1794
1982
|
result.errors.push(mapper(issue2));
|
|
1795
1983
|
continue;
|
|
@@ -1821,8 +2009,8 @@ function treeifyError(error53, mapper = (issue2) => issue2.message) {
|
|
|
1821
2009
|
}
|
|
1822
2010
|
function toDotPath(_path) {
|
|
1823
2011
|
const segs = [];
|
|
1824
|
-
const
|
|
1825
|
-
for (const seg of
|
|
2012
|
+
const path16 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
2013
|
+
for (const seg of path16) {
|
|
1826
2014
|
if (typeof seg === "number")
|
|
1827
2015
|
segs.push(`[${seg}]`);
|
|
1828
2016
|
else if (typeof seg === "symbol")
|
|
@@ -5050,8 +5238,8 @@ function az_default() {
|
|
|
5050
5238
|
}
|
|
5051
5239
|
|
|
5052
5240
|
// ../../../node_modules/zod/v4/locales/be.js
|
|
5053
|
-
function getBelarusianPlural(
|
|
5054
|
-
const absCount = Math.abs(
|
|
5241
|
+
function getBelarusianPlural(count3, one, few, many) {
|
|
5242
|
+
const absCount = Math.abs(count3);
|
|
5055
5243
|
const lastDigit = absCount % 10;
|
|
5056
5244
|
const lastTwoDigits = absCount % 100;
|
|
5057
5245
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -7129,8 +7317,8 @@ function hu_default() {
|
|
|
7129
7317
|
}
|
|
7130
7318
|
|
|
7131
7319
|
// ../../../node_modules/zod/v4/locales/hy.js
|
|
7132
|
-
function getArmenianPlural(
|
|
7133
|
-
return Math.abs(
|
|
7320
|
+
function getArmenianPlural(count3, one, many) {
|
|
7321
|
+
return Math.abs(count3) === 1 ? one : many;
|
|
7134
7322
|
}
|
|
7135
7323
|
function withDefiniteArticle(word) {
|
|
7136
7324
|
if (!word)
|
|
@@ -9258,8 +9446,8 @@ function ro_default() {
|
|
|
9258
9446
|
}
|
|
9259
9447
|
|
|
9260
9448
|
// ../../../node_modules/zod/v4/locales/ru.js
|
|
9261
|
-
function getRussianPlural(
|
|
9262
|
-
const absCount = Math.abs(
|
|
9449
|
+
function getRussianPlural(count3, one, few, many) {
|
|
9450
|
+
const absCount = Math.abs(count3);
|
|
9263
9451
|
const lastDigit = absCount % 10;
|
|
9264
9452
|
const lastTwoDigits = absCount % 100;
|
|
9265
9453
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -14514,13 +14702,13 @@ function resolveRef(ref, ctx) {
|
|
|
14514
14702
|
if (!ref.startsWith("#")) {
|
|
14515
14703
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
14516
14704
|
}
|
|
14517
|
-
const
|
|
14518
|
-
if (
|
|
14705
|
+
const path16 = ref.slice(1).split("/").filter(Boolean);
|
|
14706
|
+
if (path16.length === 0) {
|
|
14519
14707
|
return ctx.rootSchema;
|
|
14520
14708
|
}
|
|
14521
14709
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
14522
|
-
if (
|
|
14523
|
-
const key =
|
|
14710
|
+
if (path16[0] === defsKey) {
|
|
14711
|
+
const key = path16[1];
|
|
14524
14712
|
if (!key || !ctx.defs[key]) {
|
|
14525
14713
|
throw new Error(`Reference not found: ${ref}`);
|
|
14526
14714
|
}
|
|
@@ -14928,6 +15116,15 @@ function date4(params) {
|
|
|
14928
15116
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
14929
15117
|
config(en_default());
|
|
14930
15118
|
|
|
15119
|
+
// ../../shared-contracts/dist/delegation-read.js
|
|
15120
|
+
var REMOTE_THREAD_REPLY_MAX_BYTES = 16 * 1024 * 1024;
|
|
15121
|
+
var delegationReadParamsSchema = external_exports.strictObject({
|
|
15122
|
+
threadId: external_exports.string().min(1).max(1024),
|
|
15123
|
+
view: external_exports.enum(["result", "messages"]),
|
|
15124
|
+
cursor: external_exports.string().min(1).max(8192).optional(),
|
|
15125
|
+
limit: external_exports.number().int().min(1).max(100).optional()
|
|
15126
|
+
});
|
|
15127
|
+
|
|
14931
15128
|
// ../../shared-contracts/dist/credential-imports.js
|
|
14932
15129
|
var credentialSourceSchema = external_exports.object({
|
|
14933
15130
|
id: external_exports.string().min(1).max(256),
|
|
@@ -14998,6 +15195,160 @@ var harnessDisplaySetSchema = external_exports.strictObject({
|
|
|
14998
15195
|
initializeOnly: external_exports.boolean().optional()
|
|
14999
15196
|
});
|
|
15000
15197
|
|
|
15198
|
+
// ../../shared-contracts/dist/model-price-overrides.js
|
|
15199
|
+
var usdPerMillionTokens = external_exports.number().finite().nonnegative();
|
|
15200
|
+
var modelPriceOverrideSchema = external_exports.strictObject({
|
|
15201
|
+
input: usdPerMillionTokens,
|
|
15202
|
+
output: usdPerMillionTokens,
|
|
15203
|
+
cacheRead: usdPerMillionTokens.optional(),
|
|
15204
|
+
cacheWrite: usdPerMillionTokens.optional(),
|
|
15205
|
+
cacheWrite1h: usdPerMillionTokens.optional()
|
|
15206
|
+
});
|
|
15207
|
+
var modelPriceKeySchema = external_exports.string().max(512).refine((key) => key.trim() === key && key.length > 0, "Model ID is required");
|
|
15208
|
+
var modelPriceOverridesSchema = external_exports.strictObject({
|
|
15209
|
+
/** Absolute path of the Host's `pricing.json`. */
|
|
15210
|
+
path: external_exports.string(),
|
|
15211
|
+
entries: external_exports.array(external_exports.strictObject({ key: external_exports.string(), price: modelPriceOverrideSchema })),
|
|
15212
|
+
/** Why the existing file is unusable; the Host then ignores it and refuses to overwrite it. */
|
|
15213
|
+
error: external_exports.string().nullable()
|
|
15214
|
+
});
|
|
15215
|
+
var modelPriceOverridesGetSchema = external_exports.strictObject({});
|
|
15216
|
+
var modelPriceOverridesSetSchema = external_exports.strictObject({
|
|
15217
|
+
key: modelPriceKeySchema,
|
|
15218
|
+
price: modelPriceOverrideSchema.nullable(),
|
|
15219
|
+
previousKey: modelPriceKeySchema.optional()
|
|
15220
|
+
});
|
|
15221
|
+
var modelPriceDefaultParamsSchema = external_exports.strictObject({
|
|
15222
|
+
model: modelPriceKeySchema
|
|
15223
|
+
});
|
|
15224
|
+
var modelPriceSuggestionSchema = external_exports.strictObject({
|
|
15225
|
+
/** Verified from catalog canonical links, not inferred from names or equal prices. */
|
|
15226
|
+
official: external_exports.boolean().optional(),
|
|
15227
|
+
canonicalModelId: external_exports.string().min(1).optional(),
|
|
15228
|
+
provider: external_exports.string().min(1).max(512),
|
|
15229
|
+
model: external_exports.string().min(1).max(512),
|
|
15230
|
+
price: modelPriceOverrideSchema
|
|
15231
|
+
});
|
|
15232
|
+
var modelPriceDefaultResultSchema = external_exports.strictObject({
|
|
15233
|
+
price: modelPriceOverrideSchema.nullable(),
|
|
15234
|
+
/** Local catalog suggestions only; never used automatically for pricing. */
|
|
15235
|
+
suggestions: external_exports.array(modelPriceSuggestionSchema).max(6).optional()
|
|
15236
|
+
});
|
|
15237
|
+
|
|
15238
|
+
// ../../shared-contracts/dist/usage-statistics.js
|
|
15239
|
+
var USAGE_STATISTICS_RANGES = ["today", "7d", "30d", "90d", "all"];
|
|
15240
|
+
var count2 = external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
15241
|
+
var localDate = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/u);
|
|
15242
|
+
var harness = external_exports.string().min(1).max(128);
|
|
15243
|
+
var model = external_exports.string().min(1).max(512);
|
|
15244
|
+
var project = external_exports.string().min(1).max(4096);
|
|
15245
|
+
var usageStatisticsParamsSchema = external_exports.strictObject({
|
|
15246
|
+
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
15247
|
+
harness: harness.optional(),
|
|
15248
|
+
model: model.nullable().optional(),
|
|
15249
|
+
project: project.nullable().optional(),
|
|
15250
|
+
/** One local date inside the range. */
|
|
15251
|
+
date: localDate.optional()
|
|
15252
|
+
});
|
|
15253
|
+
var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
15254
|
+
requests: count2,
|
|
15255
|
+
inputTokens: count2,
|
|
15256
|
+
cachedInputTokens: count2,
|
|
15257
|
+
cacheWriteInputTokens: count2,
|
|
15258
|
+
cacheKnownInputTokens: count2,
|
|
15259
|
+
outputTokens: count2,
|
|
15260
|
+
reasoningOutputTokens: count2,
|
|
15261
|
+
/** USD at the public price, summed over the priced requests only. */
|
|
15262
|
+
costUsd: external_exports.number().finite().min(0),
|
|
15263
|
+
/** Requests without a price (or the cache data the price needs); not in `costUsd`. */
|
|
15264
|
+
unpricedRequests: count2,
|
|
15265
|
+
/**
|
|
15266
|
+
* Requests whose storage gave no token counts: counted as requests, with neither tokens nor
|
|
15267
|
+
* cost, and not as unpriced.
|
|
15268
|
+
*/
|
|
15269
|
+
unmeteredRequests: count2
|
|
15270
|
+
});
|
|
15271
|
+
var totals = usageStatisticsTotalsSchema.shape;
|
|
15272
|
+
var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
15273
|
+
harness,
|
|
15274
|
+
sessionId: external_exports.string().min(1).max(512),
|
|
15275
|
+
project: project.nullable(),
|
|
15276
|
+
/** Persisted Desktop title for a mapped Session, otherwise its native name; may be absent. */
|
|
15277
|
+
title: external_exports.string().min(1).max(200).optional(),
|
|
15278
|
+
/** Models the session used, most requests first. */
|
|
15279
|
+
models: external_exports.array(model).max(16),
|
|
15280
|
+
firstAtMs: count2,
|
|
15281
|
+
lastAtMs: count2,
|
|
15282
|
+
...totals
|
|
15283
|
+
});
|
|
15284
|
+
var usageStatisticsResultSchema = external_exports.strictObject({
|
|
15285
|
+
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
15286
|
+
/** First local date of the range; null for all time. */
|
|
15287
|
+
from: localDate.nullable(),
|
|
15288
|
+
to: localDate,
|
|
15289
|
+
/** The filters these figures apply, echoed so a late answer to older filters is recognised. */
|
|
15290
|
+
filters: external_exports.strictObject({
|
|
15291
|
+
harness: harness.nullable(),
|
|
15292
|
+
model: model.nullable(),
|
|
15293
|
+
unknownModel: external_exports.boolean(),
|
|
15294
|
+
project: project.nullable(),
|
|
15295
|
+
unknownProject: external_exports.boolean(),
|
|
15296
|
+
date: localDate.nullable()
|
|
15297
|
+
}),
|
|
15298
|
+
/** Reading of native storage: incomplete while the first read, or a refresh, is under way. */
|
|
15299
|
+
reading: external_exports.strictObject({ complete: external_exports.boolean(), sources: count2, read: count2 }),
|
|
15300
|
+
/** Harnesses whose storage could not be read; their part is missing, the rest is complete. */
|
|
15301
|
+
failures: external_exports.array(external_exports.strictObject({ harness, message: external_exports.string().max(2048) })).max(256),
|
|
15302
|
+
/** Every value seen in the range, ignoring the filters, to choose filters from. */
|
|
15303
|
+
options: external_exports.strictObject({
|
|
15304
|
+
harnesses: external_exports.array(harness).max(256),
|
|
15305
|
+
models: external_exports.array(model.nullable()).max(4096),
|
|
15306
|
+
projects: external_exports.array(project.nullable()).max(4096)
|
|
15307
|
+
}),
|
|
15308
|
+
/** Current display metadata, scoped by Harness. Never a pricing or filter identity.
|
|
15309
|
+
* Optional for older Hosts; missing/conflicting labels fall back to the native model ID.
|
|
15310
|
+
*/
|
|
15311
|
+
modelLabels: external_exports.array(external_exports.strictObject({ harness, model, label: model })).max(4096).optional(),
|
|
15312
|
+
/** Native credits, all filters applied, never combined across Harnesses or treated as USD.
|
|
15313
|
+
* Only groups with at least one reported value appear; reportedRequests exposes partial data.
|
|
15314
|
+
*/
|
|
15315
|
+
credits: external_exports.array(external_exports.strictObject({
|
|
15316
|
+
harness,
|
|
15317
|
+
model: model.nullable(),
|
|
15318
|
+
credits: external_exports.number().finite().min(0),
|
|
15319
|
+
reportedRequests: count2,
|
|
15320
|
+
requests: count2
|
|
15321
|
+
})).max(4096).optional(),
|
|
15322
|
+
/** All filters applied. */
|
|
15323
|
+
totals: usageStatisticsTotalsSchema,
|
|
15324
|
+
/** Each date and Harness of the range: every filter except the day. */
|
|
15325
|
+
daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
|
|
15326
|
+
/** Local weekday (0 = Sunday) and hour, all filters applied. */
|
|
15327
|
+
hourly: external_exports.array(external_exports.strictObject({
|
|
15328
|
+
weekday: external_exports.number().int().min(0).max(6),
|
|
15329
|
+
hour: external_exports.number().int().min(0).max(23),
|
|
15330
|
+
...totals
|
|
15331
|
+
})).max(168),
|
|
15332
|
+
byHarness: external_exports.array(external_exports.strictObject({ harness, ...totals })).max(256),
|
|
15333
|
+
byModel: external_exports.array(external_exports.strictObject({
|
|
15334
|
+
model: model.nullable(),
|
|
15335
|
+
...totals,
|
|
15336
|
+
/** Requests priced by what the Harness recorded they cost, not by a price list. */
|
|
15337
|
+
harnessPricedRequests: count2
|
|
15338
|
+
})).max(4096),
|
|
15339
|
+
byProject: external_exports.array(external_exports.strictObject({ project: project.nullable(), ...totals })).max(4096),
|
|
15340
|
+
/**
|
|
15341
|
+
* The sessions that spent the most, by cost and by tokens without cache, all filters applied;
|
|
15342
|
+
* requests without a native session are not listed here but count everywhere else.
|
|
15343
|
+
*/
|
|
15344
|
+
sessions: external_exports.array(usageStatisticsSessionSchema).max(100),
|
|
15345
|
+
/**
|
|
15346
|
+
* The sessions last active in the range, newest first, all filters applied. Optional for older
|
|
15347
|
+
* Hosts; missing is treated as no list rather than no sessions.
|
|
15348
|
+
*/
|
|
15349
|
+
recentSessions: external_exports.array(usageStatisticsSessionSchema).max(100).optional()
|
|
15350
|
+
});
|
|
15351
|
+
|
|
15001
15352
|
// ../../shared-contracts/dist/ids.js
|
|
15002
15353
|
var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
|
|
15003
15354
|
message: "Identifier must not be empty or whitespace"
|
|
@@ -15045,6 +15396,10 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
15045
15396
|
"codexhost/account/list",
|
|
15046
15397
|
"codexhost/account/refresh",
|
|
15047
15398
|
"codexhost/account/usage/inspect",
|
|
15399
|
+
"codexhost/usage/model-prices/get",
|
|
15400
|
+
"codexhost/usage/model-prices/set",
|
|
15401
|
+
"codexhost/usage/model-prices/default",
|
|
15402
|
+
"codexhost/usage/statistics/get",
|
|
15048
15403
|
"codexhost/update/check",
|
|
15049
15404
|
"codexhost/update/start",
|
|
15050
15405
|
"codexhost/update/status"
|
|
@@ -15109,6 +15464,7 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
15109
15464
|
cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15110
15465
|
outputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15111
15466
|
outputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
15467
|
+
apiOutputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
|
|
15112
15468
|
reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15113
15469
|
totalTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15114
15470
|
totalCostUsd: finiteNonNegativeNumberSchema.optional(),
|
|
@@ -15120,7 +15476,11 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
15120
15476
|
planFiveHourUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
15121
15477
|
planFiveHourResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
15122
15478
|
planSevenDayUsedPercent: cacheHitRatePercentSchema.optional(),
|
|
15123
|
-
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional()
|
|
15479
|
+
planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
|
|
15480
|
+
sessionCacheHitRatePercent: cacheHitRatePercentSchema.optional(),
|
|
15481
|
+
timeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
|
|
15482
|
+
costSource: external_exports.enum(["publicPrice", "native"]).optional(),
|
|
15483
|
+
unpricedModels: external_exports.array(external_exports.string().min(1)).min(1).optional()
|
|
15124
15484
|
}).strict().superRefine((usage, context) => {
|
|
15125
15485
|
if (Object.keys(usage).length === 0) {
|
|
15126
15486
|
context.addIssue({ code: "custom", message: "Thread Usage must contain a reliable field" });
|
|
@@ -15141,6 +15501,20 @@ var threadUsageSnapshotSchema = external_exports.object({
|
|
|
15141
15501
|
path: ["contextWindowTokens"]
|
|
15142
15502
|
});
|
|
15143
15503
|
}
|
|
15504
|
+
if (usage.costSource !== void 0 && usage.totalCostUsd === void 0) {
|
|
15505
|
+
context.addIssue({
|
|
15506
|
+
code: "custom",
|
|
15507
|
+
message: "Thread Usage costSource must be provided with totalCostUsd",
|
|
15508
|
+
path: ["costSource"]
|
|
15509
|
+
});
|
|
15510
|
+
}
|
|
15511
|
+
if (usage.unpricedModels !== void 0 && usage.costSource !== "publicPrice") {
|
|
15512
|
+
context.addIssue({
|
|
15513
|
+
code: "custom",
|
|
15514
|
+
message: "Thread Usage unpricedModels must be provided with a publicPrice cost",
|
|
15515
|
+
path: ["unpricedModels"]
|
|
15516
|
+
});
|
|
15517
|
+
}
|
|
15144
15518
|
if (usage.planFiveHourResetsAtUnix !== void 0 && usage.planFiveHourUsedPercent === void 0) {
|
|
15145
15519
|
context.addIssue({
|
|
15146
15520
|
code: "custom",
|
|
@@ -15395,27 +15769,27 @@ var harnessModelCatalogSchema = external_exports.object({
|
|
|
15395
15769
|
}).strict().superRefine((catalog, context) => {
|
|
15396
15770
|
const refs = /* @__PURE__ */ new Set();
|
|
15397
15771
|
const thinkingIds = new Set(catalog.thinkingOptions.map(({ id }) => id));
|
|
15398
|
-
for (const [index,
|
|
15399
|
-
if (refs.has(
|
|
15772
|
+
for (const [index, model2] of catalog.models.entries()) {
|
|
15773
|
+
if (refs.has(model2.ref.id)) {
|
|
15400
15774
|
context.addIssue({
|
|
15401
15775
|
code: "custom",
|
|
15402
15776
|
message: "Model Catalog refs must be unique",
|
|
15403
15777
|
path: ["models", index, "ref", "id"]
|
|
15404
15778
|
});
|
|
15405
15779
|
}
|
|
15406
|
-
refs.add(
|
|
15407
|
-
if (
|
|
15408
|
-
if (refs.has(
|
|
15780
|
+
refs.add(model2.ref.id);
|
|
15781
|
+
if (model2.fastModel) {
|
|
15782
|
+
if (refs.has(model2.fastModel.id) || catalog.models.some((entry) => entry.ref.id === model2.fastModel?.id)) {
|
|
15409
15783
|
context.addIssue({
|
|
15410
15784
|
code: "custom",
|
|
15411
15785
|
message: "Fast Model refs must be distinct and unique",
|
|
15412
15786
|
path: ["models", index, "fastModel"]
|
|
15413
15787
|
});
|
|
15414
15788
|
}
|
|
15415
|
-
refs.add(
|
|
15789
|
+
refs.add(model2.fastModel.id);
|
|
15416
15790
|
}
|
|
15417
15791
|
const supportedThinkingIds = /* @__PURE__ */ new Set();
|
|
15418
|
-
for (const [optionIndex, optionId] of (
|
|
15792
|
+
for (const [optionIndex, optionId] of (model2.supportedThinkingOptionIds ?? []).entries()) {
|
|
15419
15793
|
if (supportedThinkingIds.has(optionId)) {
|
|
15420
15794
|
context.addIssue({
|
|
15421
15795
|
code: "custom",
|
|
@@ -15609,13 +15983,40 @@ var HARNESS_PLUGIN_LIMIT = 128;
|
|
|
15609
15983
|
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);
|
|
15610
15984
|
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");
|
|
15611
15985
|
var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
|
|
15986
|
+
var localizedTextSchema = external_exports.object({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).strict();
|
|
15987
|
+
var harnessInstallationGuideSchema = external_exports.object({
|
|
15988
|
+
commands: external_exports.array(external_exports.object({ terminal: external_exports.string().max(256), command: external_exports.string().max(4096) }).strict()).max(8),
|
|
15989
|
+
before: localizedTextSchema.optional(),
|
|
15990
|
+
after: localizedTextSchema.optional(),
|
|
15991
|
+
downloads: external_exports.array(external_exports.object({ label: external_exports.string().max(128), url: documentationUrlSchema }).strict()).max(8).optional()
|
|
15992
|
+
}).strict();
|
|
15612
15993
|
var pluginPresentationShape = {
|
|
15613
15994
|
id: harnessPluginIdSchema,
|
|
15614
15995
|
name: external_exports.string().trim().min(1).max(128),
|
|
15615
15996
|
version: external_exports.string().min(1).max(128),
|
|
15997
|
+
/** Capability-only plugin; omitted for existing session-capable plugins. */
|
|
15998
|
+
kind: external_exports.literal("usage").optional(),
|
|
15999
|
+
/** Original image styling or bounded vector paths; never arbitrary CSS/SVG markup. */
|
|
16000
|
+
iconStyle: external_exports.object({
|
|
16001
|
+
vector: external_exports.object({
|
|
16002
|
+
viewBox: external_exports.string().max(128).regex(/^-?\d+(?:\.\d+)?(?: +-?\d+(?:\.\d+)?){3}$/u),
|
|
16003
|
+
color: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu),
|
|
16004
|
+
paths: external_exports.array(external_exports.object({
|
|
16005
|
+
d: external_exports.string().min(1).max(32768).regex(/^[MmLlHhVvCcSsQqTtAaZz\d.,+eE\s-]+$/u),
|
|
16006
|
+
fillRule: external_exports.enum(["evenodd", "nonzero"]).optional(),
|
|
16007
|
+
fill: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu).optional()
|
|
16008
|
+
}).strict()).min(1).max(32)
|
|
16009
|
+
}).strict().optional(),
|
|
16010
|
+
background: external_exports.string().regex(/^#[a-f0-9]{6}$/iu).optional(),
|
|
16011
|
+
borderRadius: external_exports.number().min(0).max(50).optional(),
|
|
16012
|
+
paddingRatio: external_exports.number().min(0).max(0.25).optional()
|
|
16013
|
+
}).strict().optional(),
|
|
16014
|
+
installation: harnessInstallationGuideSchema.optional(),
|
|
16015
|
+
notice: localizedTextSchema.optional(),
|
|
15616
16016
|
/** The factory accepts a persisted local entrypoint through its construction context. */
|
|
15617
16017
|
launchCommand: external_exports.literal(true).optional(),
|
|
15618
16018
|
links: external_exports.object({
|
|
16019
|
+
website: documentationUrlSchema.optional(),
|
|
15619
16020
|
documentation: documentationUrlSchema.optional(),
|
|
15620
16021
|
installation: documentationUrlSchema.optional()
|
|
15621
16022
|
}).strict().optional()
|
|
@@ -16034,6 +16435,11 @@ var codexSshDraftSchema = external_exports.strictObject({
|
|
|
16034
16435
|
});
|
|
16035
16436
|
var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
|
|
16036
16437
|
external_exports.strictObject({ action: external_exports.literal("list") }),
|
|
16438
|
+
external_exports.strictObject({
|
|
16439
|
+
action: external_exports.literal("read-thread"),
|
|
16440
|
+
hostId: hostId.refine((id) => id !== "local"),
|
|
16441
|
+
input: delegationReadParamsSchema
|
|
16442
|
+
}),
|
|
16037
16443
|
external_exports.strictObject({
|
|
16038
16444
|
action: external_exports.literal("save"),
|
|
16039
16445
|
draft: codexSshDraftSchema,
|
|
@@ -16136,10 +16542,12 @@ var tokenFields = [
|
|
|
16136
16542
|
];
|
|
16137
16543
|
var safeIntegerFields = [
|
|
16138
16544
|
"planFiveHourResetsAtUnix",
|
|
16139
|
-
"planSevenDayResetsAtUnix"
|
|
16545
|
+
"planSevenDayResetsAtUnix",
|
|
16546
|
+
"timeToFirstOutputMs"
|
|
16140
16547
|
];
|
|
16141
16548
|
var percentFields = [
|
|
16142
16549
|
"cacheHitRatePercent",
|
|
16550
|
+
"sessionCacheHitRatePercent",
|
|
16143
16551
|
"planFiveHourUsedPercent",
|
|
16144
16552
|
"planSevenDayUsedPercent"
|
|
16145
16553
|
];
|
|
@@ -16147,16 +16555,20 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
16147
16555
|
...tokenFields,
|
|
16148
16556
|
...safeIntegerFields,
|
|
16149
16557
|
...percentFields,
|
|
16558
|
+
"sessionCacheUsage",
|
|
16150
16559
|
"totalCostUsd",
|
|
16151
16560
|
"totalCredits",
|
|
16152
16561
|
"contextUsagePercent",
|
|
16153
|
-
"outputTokensPerSecond"
|
|
16562
|
+
"outputTokensPerSecond",
|
|
16563
|
+
"apiOutputTokensPerSecond",
|
|
16564
|
+
"costSource",
|
|
16565
|
+
"unpricedModels"
|
|
16154
16566
|
]);
|
|
16155
|
-
function
|
|
16567
|
+
function isRecord2(value) {
|
|
16156
16568
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16157
16569
|
}
|
|
16158
16570
|
function parseHostUsage(value) {
|
|
16159
|
-
if (!
|
|
16571
|
+
if (!isRecord2(value))
|
|
16160
16572
|
throw new Error("Harness Usage must be an object");
|
|
16161
16573
|
const keys = Object.keys(value);
|
|
16162
16574
|
if (keys.length === 0)
|
|
@@ -16166,7 +16578,11 @@ function parseHostUsage(value) {
|
|
|
16166
16578
|
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
16167
16579
|
}
|
|
16168
16580
|
}
|
|
16169
|
-
for (const field of [
|
|
16581
|
+
for (const field of [
|
|
16582
|
+
"totalCredits",
|
|
16583
|
+
"contextUsagePercent",
|
|
16584
|
+
"apiOutputTokensPerSecond"
|
|
16585
|
+
]) {
|
|
16170
16586
|
const candidate = value[field];
|
|
16171
16587
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
16172
16588
|
throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
|
|
@@ -16196,6 +16612,12 @@ function parseHostUsage(value) {
|
|
|
16196
16612
|
throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
|
|
16197
16613
|
}
|
|
16198
16614
|
}
|
|
16615
|
+
if (value.sessionCacheUsage !== void 0) {
|
|
16616
|
+
const totals2 = value.sessionCacheUsage;
|
|
16617
|
+
if (!isRecord2(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) {
|
|
16618
|
+
throw new Error("Harness Usage 'sessionCacheUsage' must contain complete bounded token totals");
|
|
16619
|
+
}
|
|
16620
|
+
}
|
|
16199
16621
|
const hasContextUsed = value.contextUsedTokens !== void 0;
|
|
16200
16622
|
const hasContextWindow = value.contextWindowTokens !== void 0;
|
|
16201
16623
|
if (hasContextUsed !== hasContextWindow) {
|
|
@@ -16210,8 +16632,43 @@ function parseHostUsage(value) {
|
|
|
16210
16632
|
if (value.planSevenDayResetsAtUnix !== void 0 && value.planSevenDayUsedPercent === void 0) {
|
|
16211
16633
|
throw new Error("Harness Usage 'planSevenDayResetsAtUnix' must be provided with 'planSevenDayUsedPercent'");
|
|
16212
16634
|
}
|
|
16635
|
+
if (value.costSource !== void 0) {
|
|
16636
|
+
if (value.costSource !== "publicPrice" && value.costSource !== "native") {
|
|
16637
|
+
throw new Error("Harness Usage 'costSource' must be 'publicPrice' or 'native'");
|
|
16638
|
+
}
|
|
16639
|
+
if (value.totalCostUsd === void 0) {
|
|
16640
|
+
throw new Error("Harness Usage 'costSource' must be provided with 'totalCostUsd'");
|
|
16641
|
+
}
|
|
16642
|
+
}
|
|
16643
|
+
if (value.unpricedModels !== void 0) {
|
|
16644
|
+
const models = value.unpricedModels;
|
|
16645
|
+
if (!Array.isArray(models) || models.length === 0 || !models.every((model2) => typeof model2 === "string" && model2.length > 0)) {
|
|
16646
|
+
throw new Error("Harness Usage 'unpricedModels' must be a non-empty list of Model IDs");
|
|
16647
|
+
}
|
|
16648
|
+
if (value.costSource !== "publicPrice") {
|
|
16649
|
+
throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
|
|
16650
|
+
}
|
|
16651
|
+
return { ...value, unpricedModels: [...models] };
|
|
16652
|
+
}
|
|
16213
16653
|
return { ...value };
|
|
16214
16654
|
}
|
|
16655
|
+
var requestTokenFields = [
|
|
16656
|
+
"inputTokens",
|
|
16657
|
+
"cachedInputTokens",
|
|
16658
|
+
"cacheWriteInputTokens",
|
|
16659
|
+
"cacheWrite1hInputTokens",
|
|
16660
|
+
"outputTokens",
|
|
16661
|
+
"reasoningOutputTokens",
|
|
16662
|
+
"startedAtMs",
|
|
16663
|
+
"completedAtMs"
|
|
16664
|
+
];
|
|
16665
|
+
var requestFields = /* @__PURE__ */ new Set([
|
|
16666
|
+
...requestTokenFields,
|
|
16667
|
+
"requestId",
|
|
16668
|
+
"historical",
|
|
16669
|
+
"model",
|
|
16670
|
+
"provider"
|
|
16671
|
+
]);
|
|
16215
16672
|
|
|
16216
16673
|
// ../../harness-adapter/dist/live-command-catalog.js
|
|
16217
16674
|
var COMMON_EXCLUDED_LIVE_COMMANDS = /* @__PURE__ */ new Set([
|
|
@@ -16333,9 +16790,9 @@ function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
|
|
|
16333
16790
|
|
|
16334
16791
|
// dist/acp-transport.js
|
|
16335
16792
|
import { spawn, spawnSync } from "node:child_process";
|
|
16336
|
-
import { readdir, readFile as
|
|
16337
|
-
import
|
|
16338
|
-
import
|
|
16793
|
+
import { readdir, readFile as readFile3 } from "node:fs/promises";
|
|
16794
|
+
import os5 from "node:os";
|
|
16795
|
+
import path12 from "node:path";
|
|
16339
16796
|
import { Readable, Writable } from "node:stream";
|
|
16340
16797
|
|
|
16341
16798
|
// ../../../node_modules/@agentclientprotocol/sdk/dist/schema/index.js
|
|
@@ -18073,17 +18530,17 @@ function isResponseMessage(value) {
|
|
|
18073
18530
|
function isNotificationMessage(value) {
|
|
18074
18531
|
return isJsonRpcEnvelope(value) && !("id" in value) && typeof value["method"] === "string";
|
|
18075
18532
|
}
|
|
18076
|
-
function
|
|
18533
|
+
function isRecord3(value) {
|
|
18077
18534
|
return typeof value === "object" && value !== null;
|
|
18078
18535
|
}
|
|
18079
18536
|
function isJsonRpcEnvelope(value) {
|
|
18080
|
-
return
|
|
18537
|
+
return isRecord3(value) && value["jsonrpc"] === "2.0";
|
|
18081
18538
|
}
|
|
18082
18539
|
function isJsonRpcId(value) {
|
|
18083
18540
|
return value === null || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
18084
18541
|
}
|
|
18085
18542
|
function isResponseShapedMessage(value) {
|
|
18086
|
-
return
|
|
18543
|
+
return isRecord3(value) && !("method" in value) && ("id" in value || "result" in value || "error" in value);
|
|
18087
18544
|
}
|
|
18088
18545
|
function isResponseBatch(batch) {
|
|
18089
18546
|
let hasValidCall = false;
|
|
@@ -18093,7 +18550,7 @@ function isResponseBatch(batch) {
|
|
|
18093
18550
|
for (const entry of batch) {
|
|
18094
18551
|
hasValidCall ||= isRequestMessage(entry) || isNotificationMessage(entry);
|
|
18095
18552
|
hasValidResponse ||= isResponseMessage(entry);
|
|
18096
|
-
if (!
|
|
18553
|
+
if (!isRecord3(entry)) {
|
|
18097
18554
|
continue;
|
|
18098
18555
|
}
|
|
18099
18556
|
hasCallShape ||= "method" in entry;
|
|
@@ -18108,13 +18565,13 @@ function isResponseBatch(batch) {
|
|
|
18108
18565
|
return hasResponseShape && !hasCallShape;
|
|
18109
18566
|
}
|
|
18110
18567
|
function cancelRequestId(params) {
|
|
18111
|
-
if (!
|
|
18568
|
+
if (!isRecord3(params) || !isJsonRpcId(params["requestId"])) {
|
|
18112
18569
|
return void 0;
|
|
18113
18570
|
}
|
|
18114
18571
|
return params["requestId"];
|
|
18115
18572
|
}
|
|
18116
18573
|
function isErrorResponse(value) {
|
|
18117
|
-
return
|
|
18574
|
+
return isRecord3(value) && typeof value["code"] === "number" && Number.isInteger(value["code"]) && typeof value["message"] === "string";
|
|
18118
18575
|
}
|
|
18119
18576
|
var Handled = {
|
|
18120
18577
|
/**
|
|
@@ -18605,7 +19062,7 @@ var Connection = class {
|
|
|
18605
19062
|
this.receiveBatch(message);
|
|
18606
19063
|
return;
|
|
18607
19064
|
}
|
|
18608
|
-
if (!
|
|
19065
|
+
if (!isRecord3(message)) {
|
|
18609
19066
|
console.error("Invalid message", { message });
|
|
18610
19067
|
return;
|
|
18611
19068
|
}
|
|
@@ -18622,9 +19079,9 @@ var Connection = class {
|
|
|
18622
19079
|
return;
|
|
18623
19080
|
}
|
|
18624
19081
|
const responseBatch = isResponseBatch(batch);
|
|
18625
|
-
const responseCount = responseBatch ? 0 : batch.reduce((
|
|
19082
|
+
const responseCount = responseBatch ? 0 : batch.reduce((count3, message) => count3 + (isNotificationMessage(message) ? 0 : 1), 0);
|
|
18626
19083
|
let remaining = responseCount;
|
|
18627
|
-
let remainingNotifications = batch.reduce((
|
|
19084
|
+
let remainingNotifications = batch.reduce((count3, message) => count3 + (isNotificationMessage(message) ? 1 : 0), 0);
|
|
18628
19085
|
let responseSent = false;
|
|
18629
19086
|
const responses = [];
|
|
18630
19087
|
const sendResponsesIfReady = async () => {
|
|
@@ -18668,7 +19125,7 @@ var Connection = class {
|
|
|
18668
19125
|
if (this.abortController.signal.aborted) {
|
|
18669
19126
|
return Promise.resolve();
|
|
18670
19127
|
}
|
|
18671
|
-
if (!
|
|
19128
|
+
if (!isRecord3(message)) {
|
|
18672
19129
|
console.error("Invalid message", { message });
|
|
18673
19130
|
return Promise.resolve();
|
|
18674
19131
|
}
|
|
@@ -19038,7 +19495,7 @@ function ndJsonStream(output, input) {
|
|
|
19038
19495
|
if (trimmedLine) {
|
|
19039
19496
|
try {
|
|
19040
19497
|
const message = JSON.parse(trimmedLine);
|
|
19041
|
-
if (
|
|
19498
|
+
if (isRecord3(message) || Array.isArray(message)) {
|
|
19042
19499
|
controller.enqueue(message);
|
|
19043
19500
|
} else {
|
|
19044
19501
|
console.warn("Skipping JSON line that is not an object:", trimmedLine);
|
|
@@ -20501,14 +20958,14 @@ var ClientSideConnection = class {
|
|
|
20501
20958
|
|
|
20502
20959
|
// dist/grok-slash-commands.js
|
|
20503
20960
|
var GROK_LIVE_COMMAND_ID_PREFIX = "grok.slash.";
|
|
20504
|
-
function
|
|
20961
|
+
function isRecord4(value) {
|
|
20505
20962
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20506
20963
|
}
|
|
20507
20964
|
function parseGrokAvailableCommands(value) {
|
|
20508
20965
|
if (!Array.isArray(value))
|
|
20509
20966
|
return [];
|
|
20510
20967
|
return value.flatMap((entry) => {
|
|
20511
|
-
if (!
|
|
20968
|
+
if (!isRecord4(entry))
|
|
20512
20969
|
return [];
|
|
20513
20970
|
const name = typeof entry.name === "string" ? entry.name.trim().replace(/^\//u, "") : "";
|
|
20514
20971
|
if (!name)
|
|
@@ -20517,14 +20974,14 @@ function parseGrokAvailableCommands(value) {
|
|
|
20517
20974
|
{
|
|
20518
20975
|
name,
|
|
20519
20976
|
description: typeof entry.description === "string" ? entry.description : "",
|
|
20520
|
-
meta:
|
|
20977
|
+
meta: isRecord4(entry._meta) ? entry._meta : null
|
|
20521
20978
|
}
|
|
20522
20979
|
];
|
|
20523
20980
|
});
|
|
20524
20981
|
}
|
|
20525
20982
|
function isGrokSkill(command) {
|
|
20526
|
-
const
|
|
20527
|
-
return typeof
|
|
20983
|
+
const path16 = command.meta?.path;
|
|
20984
|
+
return typeof path16 === "string" && /(^|[\\/])SKILL\.md$/u.test(path16) || typeof command.meta?.qualifiedName === "string";
|
|
20528
20985
|
}
|
|
20529
20986
|
function grokLiveCommands(native) {
|
|
20530
20987
|
return native.map((command) => ({
|
|
@@ -20535,7 +20992,7 @@ function grokLiveCommands(native) {
|
|
|
20535
20992
|
}
|
|
20536
20993
|
|
|
20537
20994
|
// dist/command.js
|
|
20538
|
-
import
|
|
20995
|
+
import path7 from "node:path";
|
|
20539
20996
|
var GrokExecutableError = class extends Error {
|
|
20540
20997
|
code = "GROK_NOT_FOUND";
|
|
20541
20998
|
};
|
|
@@ -20564,7 +21021,7 @@ function resolveGrokExecutable(input = {}) {
|
|
|
20564
21021
|
});
|
|
20565
21022
|
if (!resolution)
|
|
20566
21023
|
throw new GrokExecutableError("Grok CLI is not installed");
|
|
20567
|
-
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable :
|
|
21024
|
+
return targetPath(platform).isAbsolute(resolution.executable) ? resolution.executable : path7.resolve(resolution.executable);
|
|
20568
21025
|
}
|
|
20569
21026
|
function grokInvocation(command, platform = process.platform, modelId) {
|
|
20570
21027
|
const arguments_ = ["agent", "--no-leader"];
|
|
@@ -20577,11 +21034,11 @@ function grokInvocation(command, platform = process.platform, modelId) {
|
|
|
20577
21034
|
|
|
20578
21035
|
// dist/grok-fork.js
|
|
20579
21036
|
import { isDeepStrictEqual } from "node:util";
|
|
20580
|
-
import
|
|
21037
|
+
import path10 from "node:path";
|
|
20581
21038
|
|
|
20582
21039
|
// dist/grok-file-change.js
|
|
20583
21040
|
import { Buffer as Buffer2 } from "node:buffer";
|
|
20584
|
-
import
|
|
21041
|
+
import path8 from "node:path";
|
|
20585
21042
|
|
|
20586
21043
|
// ../../../node_modules/diff/libesm/diff/base.js
|
|
20587
21044
|
var Diff = class {
|
|
@@ -20683,16 +21140,16 @@ var Diff = class {
|
|
|
20683
21140
|
}
|
|
20684
21141
|
}
|
|
20685
21142
|
}
|
|
20686
|
-
addToPath(
|
|
20687
|
-
const last =
|
|
21143
|
+
addToPath(path16, added, removed, oldPosInc, options) {
|
|
21144
|
+
const last = path16.lastComponent;
|
|
20688
21145
|
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
20689
21146
|
return {
|
|
20690
|
-
oldPos:
|
|
21147
|
+
oldPos: path16.oldPos + oldPosInc,
|
|
20691
21148
|
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
20692
21149
|
};
|
|
20693
21150
|
} else {
|
|
20694
21151
|
return {
|
|
20695
|
-
oldPos:
|
|
21152
|
+
oldPos: path16.oldPos + oldPosInc,
|
|
20696
21153
|
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
20697
21154
|
};
|
|
20698
21155
|
}
|
|
@@ -21001,17 +21458,17 @@ function splitLines(text) {
|
|
|
21001
21458
|
// dist/grok-file-change.js
|
|
21002
21459
|
var DEFAULT_GROK_FILE_CHANGE_TEXT_LIMIT = 4 * 1024 * 1024;
|
|
21003
21460
|
var MAX_GROK_FILE_CHANGES_PER_TOOL = 32;
|
|
21004
|
-
function
|
|
21461
|
+
function isRecord5(value) {
|
|
21005
21462
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21006
21463
|
}
|
|
21007
21464
|
function validAbsolutePath(value) {
|
|
21008
|
-
return typeof value === "string" &&
|
|
21465
|
+
return typeof value === "string" && path8.isAbsolute(value) && value.trim().length > 0 && !value.includes("\0") && !value.includes("\n") && !value.includes("\r");
|
|
21009
21466
|
}
|
|
21010
21467
|
function displayPath(nativePath, cwd) {
|
|
21011
|
-
const resolvedCwd =
|
|
21012
|
-
const resolvedPath =
|
|
21013
|
-
const relative =
|
|
21014
|
-
const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${
|
|
21468
|
+
const resolvedCwd = path8.resolve(cwd);
|
|
21469
|
+
const resolvedPath = path8.resolve(nativePath);
|
|
21470
|
+
const relative = path8.relative(resolvedCwd, resolvedPath);
|
|
21471
|
+
const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path8.sep}`);
|
|
21015
21472
|
const selected = inside ? relative : resolvedPath;
|
|
21016
21473
|
const normalized = selected.replaceAll("\\", "/");
|
|
21017
21474
|
if (normalized.length === 0 || normalized === ".")
|
|
@@ -21052,7 +21509,7 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
|
|
|
21052
21509
|
return null;
|
|
21053
21510
|
const candidates = [];
|
|
21054
21511
|
for (const entry of content) {
|
|
21055
|
-
if (
|
|
21512
|
+
if (isRecord5(entry) && entry.type === "diff")
|
|
21056
21513
|
candidates.push(entry);
|
|
21057
21514
|
}
|
|
21058
21515
|
if (candidates.length === 0 || candidates.length > MAX_GROK_FILE_CHANGES_PER_TOOL)
|
|
@@ -21073,8 +21530,8 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
|
|
|
21073
21530
|
|
|
21074
21531
|
// dist/local-media-markdown.js
|
|
21075
21532
|
import { existsSync, statSync } from "node:fs";
|
|
21076
|
-
import
|
|
21077
|
-
import
|
|
21533
|
+
import os4 from "node:os";
|
|
21534
|
+
import path9 from "node:path";
|
|
21078
21535
|
var MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
21079
21536
|
".aac",
|
|
21080
21537
|
".gif",
|
|
@@ -21093,14 +21550,14 @@ var MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
21093
21550
|
".webp"
|
|
21094
21551
|
]);
|
|
21095
21552
|
function grokMediaResolveRoots(cwd, sessionDirectory) {
|
|
21096
|
-
const roots = [
|
|
21553
|
+
const roots = [path9.resolve(cwd)];
|
|
21097
21554
|
if (sessionDirectory) {
|
|
21098
|
-
const session =
|
|
21099
|
-
roots.push(session,
|
|
21555
|
+
const session = path9.resolve(sessionDirectory);
|
|
21556
|
+
roots.push(session, path9.join(session, "videos"), path9.join(session, "images"));
|
|
21100
21557
|
}
|
|
21101
|
-
const home = process.env.HOME ?? process.env.USERPROFILE ??
|
|
21558
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? os4.homedir();
|
|
21102
21559
|
if (home)
|
|
21103
|
-
roots.push(
|
|
21560
|
+
roots.push(path9.join(home, "Downloads"));
|
|
21104
21561
|
return roots;
|
|
21105
21562
|
}
|
|
21106
21563
|
function rewriteLocalMediaMarkdown(text, roots, options = {}) {
|
|
@@ -21201,7 +21658,7 @@ function parseInlineCode(text, start) {
|
|
|
21201
21658
|
return { closed: false, content: text.slice(start + 1), end: text.length };
|
|
21202
21659
|
}
|
|
21203
21660
|
function mediaMarkdownImage(absolutePath) {
|
|
21204
|
-
const name =
|
|
21661
|
+
const name = path9.basename(absolutePath).replaceAll("]", "\\]");
|
|
21205
21662
|
return `})`;
|
|
21206
21663
|
}
|
|
21207
21664
|
function parseMarkdownImage(text, start) {
|
|
@@ -21326,11 +21783,11 @@ function resolveLocalMediaPath(raw, roots, exists = mediaFileExists) {
|
|
|
21326
21783
|
if (!hasMediaExtension(stripped))
|
|
21327
21784
|
return null;
|
|
21328
21785
|
if (isAbsoluteMediaPath(stripped)) {
|
|
21329
|
-
const absolute =
|
|
21786
|
+
const absolute = path9.resolve(stripped);
|
|
21330
21787
|
return exists(absolute) ? absolute : null;
|
|
21331
21788
|
}
|
|
21332
21789
|
for (const root of roots) {
|
|
21333
|
-
const absolute =
|
|
21790
|
+
const absolute = path9.resolve(root, stripped);
|
|
21334
21791
|
if (exists(absolute))
|
|
21335
21792
|
return absolute;
|
|
21336
21793
|
}
|
|
@@ -21352,11 +21809,11 @@ function stripFileUrl(value) {
|
|
|
21352
21809
|
}
|
|
21353
21810
|
}
|
|
21354
21811
|
function isAbsoluteMediaPath(value) {
|
|
21355
|
-
return
|
|
21812
|
+
return path9.isAbsolute(value) || /^[a-zA-Z]:[\\/]/.test(value);
|
|
21356
21813
|
}
|
|
21357
21814
|
function hasMediaExtension(value) {
|
|
21358
21815
|
const pathname = value.split(/[?#]/, 1)[0] ?? value;
|
|
21359
|
-
return MEDIA_EXTENSIONS.has(
|
|
21816
|
+
return MEDIA_EXTENSIONS.has(path9.extname(pathname).toLowerCase());
|
|
21360
21817
|
}
|
|
21361
21818
|
function mediaFileExists(absolutePath) {
|
|
21362
21819
|
try {
|
|
@@ -21369,14 +21826,14 @@ function mediaFileExists(absolutePath) {
|
|
|
21369
21826
|
// dist/grok-tool-output.js
|
|
21370
21827
|
var DEFAULT_GROK_TOOL_OUTPUT_LIMIT = 64e3;
|
|
21371
21828
|
var EXECUTE_TOOL_NAMES = /* @__PURE__ */ new Set(["bash", "run_terminal_command", "shell", "cursor_shell"]);
|
|
21372
|
-
function
|
|
21829
|
+
function isRecord6(value) {
|
|
21373
21830
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21374
21831
|
}
|
|
21375
21832
|
function stringField(value, key) {
|
|
21376
|
-
return
|
|
21833
|
+
return isRecord6(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
|
|
21377
21834
|
}
|
|
21378
21835
|
function numberField(value, key) {
|
|
21379
|
-
if (!
|
|
21836
|
+
if (!isRecord6(value))
|
|
21380
21837
|
return void 0;
|
|
21381
21838
|
const field = value[key];
|
|
21382
21839
|
if (field === null)
|
|
@@ -21399,7 +21856,7 @@ function firstReadableText(...candidates) {
|
|
|
21399
21856
|
for (const candidate of candidates) {
|
|
21400
21857
|
if (typeof candidate === "string" && candidate.length > 0)
|
|
21401
21858
|
return candidate;
|
|
21402
|
-
if (
|
|
21859
|
+
if (isRecord6(candidate)) {
|
|
21403
21860
|
const nested = stringField(candidate, "content") ?? stringField(candidate, "text") ?? stringField(candidate, "tool_result") ?? stringField(candidate, "raw_output");
|
|
21404
21861
|
if (nested)
|
|
21405
21862
|
return nested;
|
|
@@ -21422,7 +21879,7 @@ function grokToolArguments(rawInput) {
|
|
|
21422
21879
|
if (!parsed.success)
|
|
21423
21880
|
return {};
|
|
21424
21881
|
const argumentsValue = parsed.data;
|
|
21425
|
-
if (!
|
|
21882
|
+
if (!isRecord6(argumentsValue) || stringField(argumentsValue, "path"))
|
|
21426
21883
|
return argumentsValue;
|
|
21427
21884
|
const targetFile = stringField(argumentsValue, "target_file");
|
|
21428
21885
|
return targetFile ? { ...argumentsValue, path: targetFile } : argumentsValue;
|
|
@@ -21435,7 +21892,7 @@ function grokCommand(name, kind, rawInput) {
|
|
|
21435
21892
|
return command;
|
|
21436
21893
|
if (name && EXECUTE_TOOL_NAMES.has(name))
|
|
21437
21894
|
return command;
|
|
21438
|
-
return
|
|
21895
|
+
return isRecord6(rawInput) && rawInput.variant === "Bash" ? command : void 0;
|
|
21439
21896
|
}
|
|
21440
21897
|
function grokCommandCwd(rawInput, fallback) {
|
|
21441
21898
|
return stringField(rawInput, "cwd") ?? fallback;
|
|
@@ -21462,11 +21919,11 @@ function acpContentText(content) {
|
|
|
21462
21919
|
if (!Array.isArray(content))
|
|
21463
21920
|
return "";
|
|
21464
21921
|
return content.flatMap((entry) => {
|
|
21465
|
-
if (!
|
|
21922
|
+
if (!isRecord6(entry))
|
|
21466
21923
|
return [];
|
|
21467
21924
|
if (entry.type === "text" && typeof entry.text === "string")
|
|
21468
21925
|
return [entry.text];
|
|
21469
|
-
if (entry.type !== "content" || !
|
|
21926
|
+
if (entry.type !== "content" || !isRecord6(entry.content))
|
|
21470
21927
|
return [];
|
|
21471
21928
|
return entry.content.type === "text" && typeof entry.content.text === "string" ? [entry.content.text] : [];
|
|
21472
21929
|
}).join("\n");
|
|
@@ -21477,10 +21934,10 @@ function acpContentImages(content, remainingBytes) {
|
|
|
21477
21934
|
const images = [];
|
|
21478
21935
|
let remaining = remainingBytes;
|
|
21479
21936
|
for (const entry of content) {
|
|
21480
|
-
if (!
|
|
21937
|
+
if (!isRecord6(entry))
|
|
21481
21938
|
continue;
|
|
21482
21939
|
const image = entry.type === "image" ? entry : entry.type === "content" ? entry.content : null;
|
|
21483
|
-
if (!
|
|
21940
|
+
if (!isRecord6(image) || image.type !== "image")
|
|
21484
21941
|
continue;
|
|
21485
21942
|
const mimeType = stringField(image, "mimeType") ?? stringField(image, "mime_type");
|
|
21486
21943
|
const data = stringField(image, "data");
|
|
@@ -21503,14 +21960,14 @@ function bashOutput(rawOutput) {
|
|
|
21503
21960
|
function rawOutputProjection(rawOutput) {
|
|
21504
21961
|
if (typeof rawOutput === "string")
|
|
21505
21962
|
return rawOutput.length > 0 ? { text: rawOutput } : {};
|
|
21506
|
-
if (!
|
|
21963
|
+
if (!isRecord6(rawOutput))
|
|
21507
21964
|
return {};
|
|
21508
21965
|
if (rawOutput.type === "Bash" || rawOutput.variant === "Bash" || numberField(rawOutput, "exit_code") !== void 0 || numberField(rawOutput, "exitCode") !== void 0) {
|
|
21509
21966
|
const bash = bashOutput(rawOutput);
|
|
21510
21967
|
if (bash.text !== void 0 || bash.exitCode !== void 0)
|
|
21511
21968
|
return bash;
|
|
21512
21969
|
}
|
|
21513
|
-
const text = firstReadableText(rawOutput.content, rawOutput.text, rawOutput.tool_result, rawOutput.raw_output,
|
|
21970
|
+
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);
|
|
21514
21971
|
if (text)
|
|
21515
21972
|
return { text };
|
|
21516
21973
|
if (typeof rawOutput.match_count === "number" && Number.isFinite(rawOutput.match_count)) {
|
|
@@ -21574,11 +22031,11 @@ var WAIT_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
21574
22031
|
var KILL_TOOL_NAMES = /* @__PURE__ */ new Set(["kill_command_or_subagent", "kill_task"]);
|
|
21575
22032
|
var DESCRIPTION_LIMIT = 500;
|
|
21576
22033
|
var SUMMARY_LIMIT = 2e3;
|
|
21577
|
-
function
|
|
22034
|
+
function isRecord7(value) {
|
|
21578
22035
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21579
22036
|
}
|
|
21580
22037
|
function idField(value, key) {
|
|
21581
|
-
if (!
|
|
22038
|
+
if (!isRecord7(value))
|
|
21582
22039
|
return void 0;
|
|
21583
22040
|
const field = value[key];
|
|
21584
22041
|
if (typeof field === "string") {
|
|
@@ -21590,7 +22047,7 @@ function idField(value, key) {
|
|
|
21590
22047
|
return void 0;
|
|
21591
22048
|
}
|
|
21592
22049
|
function stringField2(value, key) {
|
|
21593
|
-
if (!
|
|
22050
|
+
if (!isRecord7(value) || typeof value[key] !== "string")
|
|
21594
22051
|
return void 0;
|
|
21595
22052
|
const trimmed = value[key].trim();
|
|
21596
22053
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
@@ -21613,7 +22070,7 @@ function collectIds(value) {
|
|
|
21613
22070
|
};
|
|
21614
22071
|
push(idField(value, "task_id"));
|
|
21615
22072
|
push(idField(value, "subagent_id"));
|
|
21616
|
-
if (
|
|
22073
|
+
if (isRecord7(value)) {
|
|
21617
22074
|
const list = value.task_ids ?? value.subagent_ids;
|
|
21618
22075
|
if (Array.isArray(list)) {
|
|
21619
22076
|
for (const entry of list)
|
|
@@ -21632,7 +22089,7 @@ function grokSubagentOperation(name, title, rawInput) {
|
|
|
21632
22089
|
return "send";
|
|
21633
22090
|
if (SPAWN_TOOL_NAMES.has(id))
|
|
21634
22091
|
return "spawn";
|
|
21635
|
-
if (
|
|
22092
|
+
if (isRecord7(rawInput) && rawInput.variant === "Task")
|
|
21636
22093
|
return "spawn";
|
|
21637
22094
|
return null;
|
|
21638
22095
|
}
|
|
@@ -21655,7 +22112,7 @@ function grokSubagentRole(rawInput) {
|
|
|
21655
22112
|
return bounded(stringField2(rawInput, "subagent_type") ?? stringField2(rawInput, "agent_type") ?? stringField2(rawInput, "type"), DESCRIPTION_LIMIT);
|
|
21656
22113
|
}
|
|
21657
22114
|
function grokSubagentBackground(rawInput) {
|
|
21658
|
-
if (!
|
|
22115
|
+
if (!isRecord7(rawInput))
|
|
21659
22116
|
return true;
|
|
21660
22117
|
if (rawInput.background === false || rawInput.run_in_background === false)
|
|
21661
22118
|
return false;
|
|
@@ -21693,7 +22150,7 @@ function grokSubagentResultSummary(...candidates) {
|
|
|
21693
22150
|
return void 0;
|
|
21694
22151
|
}
|
|
21695
22152
|
function grokSubagentEventFromUpdate(update) {
|
|
21696
|
-
if (!
|
|
22153
|
+
if (!isRecord7(update) || typeof update.sessionUpdate !== "string")
|
|
21697
22154
|
return null;
|
|
21698
22155
|
const nativeSubagentId = idField(update, "subagent_id") ?? idField(update, "child_session_id");
|
|
21699
22156
|
if (!nativeSubagentId)
|
|
@@ -21701,13 +22158,13 @@ function grokSubagentEventFromUpdate(update) {
|
|
|
21701
22158
|
if (update.sessionUpdate === "subagent_spawned") {
|
|
21702
22159
|
const description = bounded(stringField2(update, "description"), DESCRIPTION_LIMIT);
|
|
21703
22160
|
const role = bounded(stringField2(update, "subagent_type") ?? stringField2(update, "role"), DESCRIPTION_LIMIT);
|
|
21704
|
-
const
|
|
22161
|
+
const model2 = bounded(stringField2(update, "model"), DESCRIPTION_LIMIT);
|
|
21705
22162
|
return {
|
|
21706
22163
|
type: "subagent.spawned",
|
|
21707
22164
|
nativeSubagentId,
|
|
21708
22165
|
...description ? { description } : {},
|
|
21709
22166
|
...role ? { role } : {},
|
|
21710
|
-
...
|
|
22167
|
+
...model2 ? { model: model2 } : {}
|
|
21711
22168
|
};
|
|
21712
22169
|
}
|
|
21713
22170
|
if (update.sessionUpdate === "subagent_finished") {
|
|
@@ -21754,14 +22211,14 @@ function grokSubagentWaitSettlements(input) {
|
|
|
21754
22211
|
return ids.map((id) => ({ id, status: overall }));
|
|
21755
22212
|
}
|
|
21756
22213
|
function taskOutputResults(rawOutput) {
|
|
21757
|
-
if (!
|
|
22214
|
+
if (!isRecord7(rawOutput))
|
|
21758
22215
|
return [];
|
|
21759
22216
|
if (Array.isArray(rawOutput.results)) {
|
|
21760
|
-
return rawOutput.results.filter(
|
|
22217
|
+
return rawOutput.results.filter(isRecord7);
|
|
21761
22218
|
}
|
|
21762
22219
|
const nested = firstRecord(rawOutput.MultiResult, rawOutput.multiResult, rawOutput.multi_result);
|
|
21763
22220
|
if (nested && Array.isArray(nested.results)) {
|
|
21764
|
-
return nested.results.filter(
|
|
22221
|
+
return nested.results.filter(isRecord7);
|
|
21765
22222
|
}
|
|
21766
22223
|
const single = firstRecord(rawOutput.Result, rawOutput.result);
|
|
21767
22224
|
if (single)
|
|
@@ -21772,7 +22229,7 @@ function taskOutputResults(rawOutput) {
|
|
|
21772
22229
|
}
|
|
21773
22230
|
function firstRecord(...values) {
|
|
21774
22231
|
for (const value of values) {
|
|
21775
|
-
if (
|
|
22232
|
+
if (isRecord7(value))
|
|
21776
22233
|
return value;
|
|
21777
22234
|
}
|
|
21778
22235
|
return void 0;
|
|
@@ -21795,7 +22252,7 @@ function taskOutputTextSettlements(rawOutput, content, ids) {
|
|
|
21795
22252
|
return settled;
|
|
21796
22253
|
}
|
|
21797
22254
|
function taskOutputStatus(rawOutput, content) {
|
|
21798
|
-
if (
|
|
22255
|
+
if (isRecord7(rawOutput) && typeof rawOutput.status === "string")
|
|
21799
22256
|
return rawOutput.status;
|
|
21800
22257
|
const text = extractText(content) ?? extractText(rawOutput);
|
|
21801
22258
|
if (!text)
|
|
@@ -21854,7 +22311,7 @@ function extractText(value, depth = 0) {
|
|
|
21854
22311
|
const joined = parts.join("\n").trim();
|
|
21855
22312
|
return joined.length > 0 ? joined : void 0;
|
|
21856
22313
|
}
|
|
21857
|
-
if (!
|
|
22314
|
+
if (!isRecord7(value))
|
|
21858
22315
|
return void 0;
|
|
21859
22316
|
if (typeof value.text === "string" && value.text.trim().length > 0)
|
|
21860
22317
|
return value.text.trim();
|
|
@@ -22213,7 +22670,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
22213
22670
|
rememberSubagentAlias(event.callId, nativeSubagentId);
|
|
22214
22671
|
const prompt = grokSubagentPrompt(event.rawInput);
|
|
22215
22672
|
const role = grokSubagentRole(event.rawInput);
|
|
22216
|
-
const
|
|
22673
|
+
const model2 = grokSubagentModel(event.rawInput);
|
|
22217
22674
|
subagents.set(event.callId, {
|
|
22218
22675
|
type: "subagentDelegation",
|
|
22219
22676
|
itemId: stableId("subagent", turnIndex, ++messageIndex),
|
|
@@ -22225,7 +22682,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
22225
22682
|
...nativeSubagentId ? { nativeSubagentId } : {},
|
|
22226
22683
|
description: grokSubagentDescription(event.rawInput, event.title),
|
|
22227
22684
|
...role ? { role } : {},
|
|
22228
|
-
...
|
|
22685
|
+
...model2 ? { model: model2 } : {},
|
|
22229
22686
|
background: grokSubagentBackground(event.rawInput),
|
|
22230
22687
|
status: "running"
|
|
22231
22688
|
}
|
|
@@ -22324,11 +22781,11 @@ var GROK_SESSION_DELETE_METHOD = "_x.ai/session/delete";
|
|
|
22324
22781
|
function error51(code, message, retryable = false) {
|
|
22325
22782
|
return { code, message, retryable };
|
|
22326
22783
|
}
|
|
22327
|
-
function
|
|
22784
|
+
function isRecord8(value) {
|
|
22328
22785
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22329
22786
|
}
|
|
22330
22787
|
function isGrokMethodNotFound(error53) {
|
|
22331
|
-
if (
|
|
22788
|
+
if (isRecord8(error53) && error53.code === -32601)
|
|
22332
22789
|
return true;
|
|
22333
22790
|
const message = error53 instanceof Error ? error53.message : String(error53);
|
|
22334
22791
|
return /method not found/iu.test(message);
|
|
@@ -22346,10 +22803,10 @@ function buildGrokForkParams(input) {
|
|
|
22346
22803
|
};
|
|
22347
22804
|
}
|
|
22348
22805
|
function parseGrokForkResponse(value) {
|
|
22349
|
-
if (!
|
|
22806
|
+
if (!isRecord8(value) || value.error !== void 0)
|
|
22350
22807
|
return null;
|
|
22351
|
-
const payload = typeof value.newSessionId !== "string" &&
|
|
22352
|
-
if (!
|
|
22808
|
+
const payload = typeof value.newSessionId !== "string" && isRecord8(value.result) ? value.result : value;
|
|
22809
|
+
if (!isRecord8(payload) || payload.error !== void 0)
|
|
22353
22810
|
return null;
|
|
22354
22811
|
if (typeof payload.newSessionId !== "string" || payload.newSessionId.length === 0)
|
|
22355
22812
|
return null;
|
|
@@ -22365,11 +22822,11 @@ function parseGrokForkResponse(value) {
|
|
|
22365
22822
|
}
|
|
22366
22823
|
function projectRelativePath(value, cwds) {
|
|
22367
22824
|
const normalized = value.replaceAll("\\", "/");
|
|
22368
|
-
if (!
|
|
22825
|
+
if (!path10.isAbsolute(value))
|
|
22369
22826
|
return normalized;
|
|
22370
22827
|
for (const cwd of cwds) {
|
|
22371
|
-
const relative =
|
|
22372
|
-
if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${
|
|
22828
|
+
const relative = path10.relative(path10.resolve(cwd), path10.resolve(value));
|
|
22829
|
+
if (relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path10.sep}`)) {
|
|
22373
22830
|
return relative.replaceAll("\\", "/");
|
|
22374
22831
|
}
|
|
22375
22832
|
}
|
|
@@ -22434,8 +22891,8 @@ async function forkGrokSession(input) {
|
|
|
22434
22891
|
error: error51("sessionNotFound", "Grok Native Session is unavailable")
|
|
22435
22892
|
};
|
|
22436
22893
|
}
|
|
22437
|
-
const sourceCwd =
|
|
22438
|
-
const targetCwd =
|
|
22894
|
+
const sourceCwd = path10.resolve(located.cwd);
|
|
22895
|
+
const targetCwd = path10.resolve(input.cwd);
|
|
22439
22896
|
const source = await readSnapshot({ ...input, cwd: sourceCwd }, sourceRef.data.nativeSessionId);
|
|
22440
22897
|
if (!source.ok)
|
|
22441
22898
|
return source;
|
|
@@ -22510,9 +22967,10 @@ async function forkGrokSession(input) {
|
|
|
22510
22967
|
// dist/grok-compaction.js
|
|
22511
22968
|
var GROK_SESSION_UPDATE_EXTENSION_METHODS = [
|
|
22512
22969
|
"_x.ai/session/update",
|
|
22513
|
-
"x.ai/session_notification"
|
|
22970
|
+
"x.ai/session_notification",
|
|
22971
|
+
"_x.ai/session_notification"
|
|
22514
22972
|
];
|
|
22515
|
-
function
|
|
22973
|
+
function isRecord9(value) {
|
|
22516
22974
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22517
22975
|
}
|
|
22518
22976
|
function optionalNonNegativeInt(value) {
|
|
@@ -22533,7 +22991,7 @@ function isGrokExtensionSessionUpdateMethod(method) {
|
|
|
22533
22991
|
return GROK_SESSION_UPDATE_EXTENSION_METHODS.includes(method);
|
|
22534
22992
|
}
|
|
22535
22993
|
function grokCompactionEventFromUpdate(update) {
|
|
22536
|
-
if (!
|
|
22994
|
+
if (!isRecord9(update) || typeof update.sessionUpdate !== "string")
|
|
22537
22995
|
return null;
|
|
22538
22996
|
const tokensUsed = optionalNonNegativeInt(firstPresent(update, ["tokensUsed", "tokens_used"]));
|
|
22539
22997
|
const contextWindowTokens = optionalNonNegativeInt(firstPresent(update, ["contextWindowTokens", "contextWindow", "context_window"]));
|
|
@@ -22572,7 +23030,7 @@ function grokCompactionEventFromUpdate(update) {
|
|
|
22572
23030
|
// dist/grok-manual-compaction.js
|
|
22573
23031
|
var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
|
|
22574
23032
|
var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
|
|
22575
|
-
function
|
|
23033
|
+
function isRecord10(value) {
|
|
22576
23034
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22577
23035
|
}
|
|
22578
23036
|
function optionalNonNegativeInt2(value) {
|
|
@@ -22584,7 +23042,7 @@ function optionalErrorMessage2(value) {
|
|
|
22584
23042
|
function parseGrokCompactResult(value, cancelled = false) {
|
|
22585
23043
|
if (cancelled)
|
|
22586
23044
|
return { outcome: "cancelled" };
|
|
22587
|
-
if (!
|
|
23045
|
+
if (!isRecord10(value))
|
|
22588
23046
|
return { outcome: "succeeded" };
|
|
22589
23047
|
const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
|
|
22590
23048
|
const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
|
|
@@ -22617,12 +23075,12 @@ function parseGrokCompactResult(value, cancelled = false) {
|
|
|
22617
23075
|
}
|
|
22618
23076
|
|
|
22619
23077
|
// dist/grok-rewind.js
|
|
22620
|
-
import
|
|
23078
|
+
import path11 from "node:path";
|
|
22621
23079
|
var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
|
|
22622
23080
|
function error52(code, message, retryable = false) {
|
|
22623
23081
|
return { code, message, retryable };
|
|
22624
23082
|
}
|
|
22625
|
-
function
|
|
23083
|
+
function isRecord11(value) {
|
|
22626
23084
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22627
23085
|
}
|
|
22628
23086
|
function buildGrokRewindParams(input) {
|
|
@@ -22634,10 +23092,10 @@ function buildGrokRewindParams(input) {
|
|
|
22634
23092
|
};
|
|
22635
23093
|
}
|
|
22636
23094
|
function parseGrokRewindResponse(value) {
|
|
22637
|
-
if (!
|
|
23095
|
+
if (!isRecord11(value))
|
|
22638
23096
|
return null;
|
|
22639
|
-
const payload = typeof value.success !== "boolean" &&
|
|
22640
|
-
if (!
|
|
23097
|
+
const payload = typeof value.success !== "boolean" && isRecord11(value.result) ? value.result : value;
|
|
23098
|
+
if (!isRecord11(payload) || typeof payload.success !== "boolean")
|
|
22641
23099
|
return null;
|
|
22642
23100
|
return rewindPayload(payload);
|
|
22643
23101
|
}
|
|
@@ -22690,8 +23148,8 @@ async function rewindGrokLastTurn(input) {
|
|
|
22690
23148
|
error: error52("sessionNotFound", "Grok Native Session is unavailable")
|
|
22691
23149
|
};
|
|
22692
23150
|
}
|
|
22693
|
-
const sourceCwd =
|
|
22694
|
-
const targetCwd =
|
|
23151
|
+
const sourceCwd = path11.resolve(located.cwd);
|
|
23152
|
+
const targetCwd = path11.resolve(input.cwd);
|
|
22695
23153
|
if (sourceCwd !== targetCwd) {
|
|
22696
23154
|
return {
|
|
22697
23155
|
ok: false,
|
|
@@ -22794,16 +23252,16 @@ var GrokTransportError = class extends Error {
|
|
|
22794
23252
|
this.name = "GrokTransportError";
|
|
22795
23253
|
}
|
|
22796
23254
|
};
|
|
22797
|
-
function
|
|
23255
|
+
function isRecord12(value) {
|
|
22798
23256
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22799
23257
|
}
|
|
22800
23258
|
function acpToolName(update, metadata) {
|
|
22801
|
-
if (!
|
|
23259
|
+
if (!isRecord12(update))
|
|
22802
23260
|
return void 0;
|
|
22803
23261
|
if (typeof update.name === "string" && update.name.length > 0)
|
|
22804
23262
|
return update.name;
|
|
22805
|
-
const meta3 =
|
|
22806
|
-
const tool = meta3 &&
|
|
23263
|
+
const meta3 = isRecord12(update._meta) ? update._meta : metadata;
|
|
23264
|
+
const tool = meta3 && isRecord12(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
22807
23265
|
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
22808
23266
|
}
|
|
22809
23267
|
function errorText(error53) {
|
|
@@ -22859,12 +23317,27 @@ function signalProcessTree(child, signal) {
|
|
|
22859
23317
|
try {
|
|
22860
23318
|
process.kill(-child.pid, signal);
|
|
22861
23319
|
} catch (error53) {
|
|
22862
|
-
if (!
|
|
23320
|
+
if (!isRecord12(error53) || error53.code !== "ESRCH")
|
|
22863
23321
|
throw error53;
|
|
22864
23322
|
}
|
|
22865
23323
|
}
|
|
22866
23324
|
function transportEvent(update, metadata) {
|
|
22867
23325
|
const extension = update;
|
|
23326
|
+
if (extension.sessionUpdate === "response_completed") {
|
|
23327
|
+
return {
|
|
23328
|
+
type: "response.completed",
|
|
23329
|
+
...extension.usage !== void 0 ? { usage: extension.usage } : {},
|
|
23330
|
+
...typeof extension.message_id === "string" && extension.message_id ? { messageId: extension.message_id } : {},
|
|
23331
|
+
...metadata ? { metadata } : {}
|
|
23332
|
+
};
|
|
23333
|
+
}
|
|
23334
|
+
if (extension.sessionUpdate === "tool_call_delta_chunk" && typeof extension.arguments_delta === "string") {
|
|
23335
|
+
return {
|
|
23336
|
+
type: "tool.input.delta",
|
|
23337
|
+
text: extension.arguments_delta,
|
|
23338
|
+
...metadata ? { metadata } : {}
|
|
23339
|
+
};
|
|
23340
|
+
}
|
|
22868
23341
|
if (extension.sessionUpdate === "turn_completed" && typeof extension.prompt_id === "string" && extension.prompt_id.length > 0 && typeof extension.stop_reason === "string") {
|
|
22869
23342
|
return {
|
|
22870
23343
|
type: "turn.completed",
|
|
@@ -22934,34 +23407,34 @@ function transportEvent(update, metadata) {
|
|
|
22934
23407
|
}
|
|
22935
23408
|
function grokHomeDir(options) {
|
|
22936
23409
|
const environment = { ...process.env, ...options.environment };
|
|
22937
|
-
const home = environment.HOME ?? environment.USERPROFILE ??
|
|
22938
|
-
return environment.GROK_HOME ??
|
|
23410
|
+
const home = environment.HOME ?? environment.USERPROFILE ?? os5.homedir();
|
|
23411
|
+
return environment.GROK_HOME ?? path12.join(home, ".grok");
|
|
22939
23412
|
}
|
|
22940
23413
|
function grokNativeSessionDirectory(options, sessionId) {
|
|
22941
|
-
return
|
|
23414
|
+
return path12.join(grokHomeDir(options), "sessions", encodeURIComponent(path12.resolve(options.cwd)), sessionId);
|
|
22942
23415
|
}
|
|
22943
23416
|
function nativeSessionFile(options, sessionId, fileName) {
|
|
22944
|
-
return
|
|
23417
|
+
return path12.join(grokNativeSessionDirectory(options, sessionId), fileName);
|
|
22945
23418
|
}
|
|
22946
23419
|
function nativeHistoryPath(options, sessionId) {
|
|
22947
23420
|
return nativeSessionFile(options, sessionId, "updates.jsonl");
|
|
22948
23421
|
}
|
|
22949
23422
|
async function readNativeSignals(options, sessionId) {
|
|
22950
23423
|
try {
|
|
22951
|
-
return JSON.parse(await
|
|
23424
|
+
return JSON.parse(await readFile3(nativeSessionFile(options, sessionId, "signals.json"), "utf8"));
|
|
22952
23425
|
} catch {
|
|
22953
23426
|
return void 0;
|
|
22954
23427
|
}
|
|
22955
23428
|
}
|
|
22956
23429
|
function isMissingFile(error53) {
|
|
22957
|
-
return
|
|
23430
|
+
return isRecord12(error53) && error53.code === "ENOENT";
|
|
22958
23431
|
}
|
|
22959
23432
|
async function locateGrokNativeSession(options, sessionId) {
|
|
22960
23433
|
if (sessionId.length === 0)
|
|
22961
23434
|
return null;
|
|
22962
23435
|
let entries;
|
|
22963
23436
|
try {
|
|
22964
|
-
entries = await readdir(
|
|
23437
|
+
entries = await readdir(path12.join(grokHomeDir(options), "sessions"), { withFileTypes: true });
|
|
22965
23438
|
} catch (error53) {
|
|
22966
23439
|
if (isMissingFile(error53))
|
|
22967
23440
|
return null;
|
|
@@ -22975,9 +23448,9 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
22975
23448
|
continue;
|
|
22976
23449
|
let summaryRaw;
|
|
22977
23450
|
try {
|
|
22978
|
-
summaryRaw = await
|
|
23451
|
+
summaryRaw = await readFile3(path12.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
22979
23452
|
} catch (error53) {
|
|
22980
|
-
if (isMissingFile(error53) ||
|
|
23453
|
+
if (isMissingFile(error53) || isRecord12(error53) && error53.code === "ENOTDIR")
|
|
22981
23454
|
continue;
|
|
22982
23455
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
22983
23456
|
cause: error53
|
|
@@ -22989,11 +23462,11 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
22989
23462
|
} catch {
|
|
22990
23463
|
continue;
|
|
22991
23464
|
}
|
|
22992
|
-
if (!
|
|
23465
|
+
if (!isRecord12(parsed))
|
|
22993
23466
|
continue;
|
|
22994
23467
|
const info = parsed.info;
|
|
22995
|
-
const cwd =
|
|
22996
|
-
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ?
|
|
23468
|
+
const cwd = isRecord12(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path12.resolve(info.cwd) : path12.resolve(decodeURIComponent(entry.name));
|
|
23469
|
+
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path12.resolve(parsed.source_workspace_dir) : void 0;
|
|
22997
23470
|
matches.push({
|
|
22998
23471
|
cwd,
|
|
22999
23472
|
...sourceWorkspaceDir ? { sourceWorkspaceDir } : {}
|
|
@@ -23003,7 +23476,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23003
23476
|
}
|
|
23004
23477
|
async function readGrokNativeHistory(options, sessionId) {
|
|
23005
23478
|
try {
|
|
23006
|
-
return parseNativeHistory(await
|
|
23479
|
+
return parseNativeHistory(await readFile3(nativeHistoryPath({ ...options, cwd: path12.resolve(options.cwd) }, sessionId), "utf8"), sessionId);
|
|
23007
23480
|
} catch (error53) {
|
|
23008
23481
|
if (isMissingFile(error53))
|
|
23009
23482
|
return [];
|
|
@@ -23025,12 +23498,12 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
23025
23498
|
} catch {
|
|
23026
23499
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
23027
23500
|
}
|
|
23028
|
-
if (!
|
|
23501
|
+
if (!isRecord12(record2) || !isRecord12(record2.params))
|
|
23029
23502
|
continue;
|
|
23030
23503
|
const params = record2.params;
|
|
23031
|
-
if (params.sessionId !== sessionId || !
|
|
23504
|
+
if (params.sessionId !== sessionId || !isRecord12(params.update))
|
|
23032
23505
|
continue;
|
|
23033
|
-
const metadata =
|
|
23506
|
+
const metadata = isRecord12(params._meta) ? params._meta : void 0;
|
|
23034
23507
|
const event = transportEvent(params.update, metadata);
|
|
23035
23508
|
if (event)
|
|
23036
23509
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -23087,6 +23560,13 @@ var GrokAcpTransport = class {
|
|
|
23087
23560
|
async getHistory() {
|
|
23088
23561
|
return this.readHistory(this.sessionId);
|
|
23089
23562
|
}
|
|
23563
|
+
/** Native cumulative usage since this process attached, not persisted Session totals. */
|
|
23564
|
+
async getUsage() {
|
|
23565
|
+
if (!this.#connection)
|
|
23566
|
+
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
23567
|
+
const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
|
|
23568
|
+
return isRecord12(result) ? result.usage : void 0;
|
|
23569
|
+
}
|
|
23090
23570
|
async readHistory(sessionId, cwd = this.#options.cwd) {
|
|
23091
23571
|
return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
|
|
23092
23572
|
}
|
|
@@ -23289,6 +23769,7 @@ var GrokAcpTransport = class {
|
|
|
23289
23769
|
prompt: [{ type: "text", text }]
|
|
23290
23770
|
});
|
|
23291
23771
|
} finally {
|
|
23772
|
+
await yieldToEventLoop();
|
|
23292
23773
|
if (this.#activePrompt === active)
|
|
23293
23774
|
this.#activePrompt = null;
|
|
23294
23775
|
}
|
|
@@ -23327,16 +23808,17 @@ var GrokAcpTransport = class {
|
|
|
23327
23808
|
this.#activeCompact = null;
|
|
23328
23809
|
}
|
|
23329
23810
|
}
|
|
23330
|
-
async setModel(modelId, reasoningEffort) {
|
|
23811
|
+
async setModel(modelId, reasoningEffort, contextWindowTokens) {
|
|
23331
23812
|
const connection = this.#connection;
|
|
23332
23813
|
if (!connection || !this.#sessionId)
|
|
23333
23814
|
throw new Error("Grok ACP Session is unavailable");
|
|
23334
23815
|
const response = await connection.request("session/set_model", {
|
|
23335
23816
|
sessionId: this.#sessionId,
|
|
23336
23817
|
modelId,
|
|
23337
|
-
...reasoningEffort ? { reasoningEffort } : {}
|
|
23818
|
+
...reasoningEffort ? { reasoningEffort } : {},
|
|
23819
|
+
...contextWindowTokens !== void 0 ? { _meta: { contextWindow: contextWindowTokens } } : {}
|
|
23338
23820
|
});
|
|
23339
|
-
if (!
|
|
23821
|
+
if (!isRecord12(response) || !isRecord12(response._meta) || !isRecord12(response._meta.model)) {
|
|
23340
23822
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
23341
23823
|
}
|
|
23342
23824
|
const selected = response._meta.model.Ok;
|
|
@@ -23388,7 +23870,7 @@ var GrokAcpTransport = class {
|
|
|
23388
23870
|
this.#availableCommands = parseGrokAvailableCommands(update.availableCommands);
|
|
23389
23871
|
return;
|
|
23390
23872
|
}
|
|
23391
|
-
const metadata =
|
|
23873
|
+
const metadata = isRecord12(notification._meta) ? notification._meta : void 0;
|
|
23392
23874
|
const event = transportEvent(notification.update, metadata);
|
|
23393
23875
|
if (!event)
|
|
23394
23876
|
return;
|
|
@@ -23403,7 +23885,7 @@ var GrokAcpTransport = class {
|
|
|
23403
23885
|
#handleExtensionNotification(method, params) {
|
|
23404
23886
|
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
23405
23887
|
return;
|
|
23406
|
-
if (typeof params.sessionId !== "string" || !
|
|
23888
|
+
if (typeof params.sessionId !== "string" || !isRecord12(params.update))
|
|
23407
23889
|
return;
|
|
23408
23890
|
this.#handleUpdate(params);
|
|
23409
23891
|
}
|
|
@@ -23421,13 +23903,13 @@ var GrokAcpTransport = class {
|
|
|
23421
23903
|
};
|
|
23422
23904
|
|
|
23423
23905
|
// dist/session-import.js
|
|
23424
|
-
import { createReadStream } from "node:fs";
|
|
23425
|
-
import { opendir, readFile as
|
|
23426
|
-
import
|
|
23427
|
-
import { createInterface } from "node:readline";
|
|
23906
|
+
import { createReadStream as createReadStream2 } from "node:fs";
|
|
23907
|
+
import { opendir as opendir2, readFile as readFile4, stat } from "node:fs/promises";
|
|
23908
|
+
import path13 from "node:path";
|
|
23909
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
23428
23910
|
|
|
23429
23911
|
// ../../harness-adapter/dist/session-import.js
|
|
23430
|
-
import { lstat } from "node:fs/promises";
|
|
23912
|
+
import { lstat as lstat2 } from "node:fs/promises";
|
|
23431
23913
|
var SessionImportChangedError = class extends Error {
|
|
23432
23914
|
constructor(message = "Native Session changed during discovery; refresh and retry") {
|
|
23433
23915
|
super(message);
|
|
@@ -23446,7 +23928,7 @@ function isStorageAccessError(error53) {
|
|
|
23446
23928
|
}
|
|
23447
23929
|
async function optionalLstat(file2) {
|
|
23448
23930
|
try {
|
|
23449
|
-
return await
|
|
23931
|
+
return await lstat2(file2);
|
|
23450
23932
|
} catch (error53) {
|
|
23451
23933
|
if (isMissingFileError(error53))
|
|
23452
23934
|
return null;
|
|
@@ -23544,11 +24026,11 @@ var SessionImportScope = class {
|
|
|
23544
24026
|
// dist/session-import.js
|
|
23545
24027
|
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
23546
24028
|
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
23547
|
-
function
|
|
24029
|
+
function isRecord13(value) {
|
|
23548
24030
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23549
24031
|
}
|
|
23550
24032
|
async function readJson(file2, signal) {
|
|
23551
|
-
return JSON.parse(await
|
|
24033
|
+
return JSON.parse(await readFile4(file2, { encoding: "utf8", signal }));
|
|
23552
24034
|
}
|
|
23553
24035
|
function processAlive(pid) {
|
|
23554
24036
|
if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0)
|
|
@@ -23557,12 +24039,12 @@ function processAlive(pid) {
|
|
|
23557
24039
|
process.kill(pid, 0);
|
|
23558
24040
|
return true;
|
|
23559
24041
|
} catch (error53) {
|
|
23560
|
-
return
|
|
24042
|
+
return isRecord13(error53) && error53.code === "EPERM";
|
|
23561
24043
|
}
|
|
23562
24044
|
}
|
|
23563
24045
|
async function firstUserText(file2, signal) {
|
|
23564
|
-
const stream =
|
|
23565
|
-
const lines =
|
|
24046
|
+
const stream = createReadStream2(file2, { encoding: "utf8", signal });
|
|
24047
|
+
const lines = createInterface2({ input: stream, crlfDelay: Infinity });
|
|
23566
24048
|
try {
|
|
23567
24049
|
for await (const line of lines) {
|
|
23568
24050
|
signal.throwIfAborted();
|
|
@@ -23574,10 +24056,10 @@ async function firstUserText(file2, signal) {
|
|
|
23574
24056
|
} catch {
|
|
23575
24057
|
continue;
|
|
23576
24058
|
}
|
|
23577
|
-
const update =
|
|
23578
|
-
if (!
|
|
24059
|
+
const update = isRecord13(entry) && isRecord13(entry.params) ? entry.params.update : null;
|
|
24060
|
+
if (!isRecord13(update) || update.sessionUpdate !== "user_message_chunk")
|
|
23579
24061
|
continue;
|
|
23580
|
-
const text =
|
|
24062
|
+
const text = isRecord13(update.content) ? update.content.text : null;
|
|
23581
24063
|
return typeof text === "string" ? text : "";
|
|
23582
24064
|
}
|
|
23583
24065
|
return null;
|
|
@@ -23644,7 +24126,7 @@ var GrokSessionImport = class {
|
|
|
23644
24126
|
const active = /* @__PURE__ */ new Set();
|
|
23645
24127
|
let entries;
|
|
23646
24128
|
try {
|
|
23647
|
-
entries = await readJson(
|
|
24129
|
+
entries = await readJson(path13.join(this.#home(), "active_sessions.json"), signal);
|
|
23648
24130
|
} catch (error53) {
|
|
23649
24131
|
signal.throwIfAborted();
|
|
23650
24132
|
if (isStorageAccessError(error53))
|
|
@@ -23654,26 +24136,26 @@ var GrokSessionImport = class {
|
|
|
23654
24136
|
if (!Array.isArray(entries))
|
|
23655
24137
|
return active;
|
|
23656
24138
|
for (const entry of entries) {
|
|
23657
|
-
if (
|
|
24139
|
+
if (isRecord13(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
23658
24140
|
active.add(entry.session_id);
|
|
23659
24141
|
}
|
|
23660
24142
|
return active;
|
|
23661
24143
|
}
|
|
23662
24144
|
/** Session ID to every directory claiming it. Enumerated links are not followed. */
|
|
23663
24145
|
async #sessionDirectories(signal) {
|
|
23664
|
-
const root =
|
|
24146
|
+
const root = path13.join(this.#home(), "sessions");
|
|
23665
24147
|
const found = /* @__PURE__ */ new Map();
|
|
23666
24148
|
const info = await optionalLstat(root);
|
|
23667
24149
|
if (!info)
|
|
23668
24150
|
return found;
|
|
23669
24151
|
if (!info.isDirectory())
|
|
23670
24152
|
throw new Error("Grok Session store is not a directory");
|
|
23671
|
-
for await (const workspace of await
|
|
24153
|
+
for await (const workspace of await opendir2(root)) {
|
|
23672
24154
|
signal.throwIfAborted();
|
|
23673
24155
|
if (!workspace.isDirectory())
|
|
23674
24156
|
continue;
|
|
23675
|
-
const workspaceDirectory =
|
|
23676
|
-
const sessions = await
|
|
24157
|
+
const workspaceDirectory = path13.join(root, workspace.name);
|
|
24158
|
+
const sessions = await opendir2(workspaceDirectory).catch((error53) => {
|
|
23677
24159
|
if (isMissingFileError(error53))
|
|
23678
24160
|
return null;
|
|
23679
24161
|
throw error53;
|
|
@@ -23685,7 +24167,7 @@ var GrokSessionImport = class {
|
|
|
23685
24167
|
if (!session.isDirectory())
|
|
23686
24168
|
continue;
|
|
23687
24169
|
const directories = found.get(session.name) ?? [];
|
|
23688
|
-
directories.push(
|
|
24170
|
+
directories.push(path13.join(workspaceDirectory, session.name));
|
|
23689
24171
|
found.set(session.name, directories);
|
|
23690
24172
|
}
|
|
23691
24173
|
}
|
|
@@ -23693,25 +24175,25 @@ var GrokSessionImport = class {
|
|
|
23693
24175
|
}
|
|
23694
24176
|
async #candidate(sessionDirectory, active, signal) {
|
|
23695
24177
|
signal.throwIfAborted();
|
|
23696
|
-
const nativeSessionId =
|
|
24178
|
+
const nativeSessionId = path13.basename(sessionDirectory);
|
|
23697
24179
|
const files = [
|
|
23698
|
-
|
|
23699
|
-
|
|
24180
|
+
path13.join(sessionDirectory, "summary.json"),
|
|
24181
|
+
path13.join(sessionDirectory, "updates.jsonl")
|
|
23700
24182
|
];
|
|
23701
24183
|
return readStableFiles(files, async ([summaryInfo, updates]) => {
|
|
23702
24184
|
if (!summaryInfo?.isFile() || !updates?.isFile() || summaryInfo.size > MAX_METADATA_BYTES)
|
|
23703
24185
|
return null;
|
|
23704
24186
|
try {
|
|
23705
24187
|
const summary = await readJson(files[0], signal);
|
|
23706
|
-
if (!
|
|
24188
|
+
if (!isRecord13(summary) || !isRecord13(summary.info) || summary.info.id !== nativeSessionId)
|
|
23707
24189
|
return null;
|
|
23708
24190
|
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
23709
24191
|
return null;
|
|
23710
24192
|
const nativeCwd = summary.info.cwd;
|
|
23711
|
-
if (typeof nativeCwd !== "string" || !
|
|
24193
|
+
if (typeof nativeCwd !== "string" || !path13.isAbsolute(nativeCwd) || nativeCwd.includes("\0"))
|
|
23712
24194
|
return null;
|
|
23713
|
-
const cwd =
|
|
23714
|
-
if (encodeURIComponent(cwd) !==
|
|
24195
|
+
const cwd = path13.resolve(nativeCwd);
|
|
24196
|
+
if (encodeURIComponent(cwd) !== path13.basename(path13.dirname(sessionDirectory)))
|
|
23715
24197
|
return null;
|
|
23716
24198
|
if (!(await stat(cwd)).isDirectory())
|
|
23717
24199
|
return null;
|
|
@@ -23930,7 +24412,7 @@ var GrokSubagentLifecycle = class {
|
|
|
23930
24412
|
};
|
|
23931
24413
|
|
|
23932
24414
|
// dist/grok-models.js
|
|
23933
|
-
function
|
|
24415
|
+
function isRecord14(value) {
|
|
23934
24416
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23935
24417
|
}
|
|
23936
24418
|
function nonBlank(value) {
|
|
@@ -23942,7 +24424,7 @@ function thinkingOptions(value) {
|
|
|
23942
24424
|
const seen = /* @__PURE__ */ new Set();
|
|
23943
24425
|
const options = [];
|
|
23944
24426
|
for (const candidate of value) {
|
|
23945
|
-
if (!
|
|
24427
|
+
if (!isRecord14(candidate) || !nonBlank(candidate.label))
|
|
23946
24428
|
continue;
|
|
23947
24429
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
23948
24430
|
if (!id.success || seen.has(id.data))
|
|
@@ -23953,7 +24435,7 @@ function thinkingOptions(value) {
|
|
|
23953
24435
|
return options;
|
|
23954
24436
|
}
|
|
23955
24437
|
function parseGrokModelState(value) {
|
|
23956
|
-
if (!
|
|
24438
|
+
if (!isRecord14(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
23957
24439
|
return null;
|
|
23958
24440
|
}
|
|
23959
24441
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -23961,16 +24443,20 @@ function parseGrokModelState(value) {
|
|
|
23961
24443
|
return null;
|
|
23962
24444
|
const allThinking = /* @__PURE__ */ new Map();
|
|
23963
24445
|
const contextWindowTokensByModel = /* @__PURE__ */ new Map();
|
|
24446
|
+
const defaultContextWindowTokensByModel = /* @__PURE__ */ new Map();
|
|
23964
24447
|
const models = [];
|
|
23965
24448
|
let currentThinkingOptionId;
|
|
23966
24449
|
for (const candidate of value.availableModels) {
|
|
23967
|
-
if (!
|
|
24450
|
+
if (!isRecord14(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
23968
24451
|
continue;
|
|
23969
24452
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
23970
24453
|
if (!ref.success)
|
|
23971
24454
|
continue;
|
|
23972
|
-
const metadata =
|
|
24455
|
+
const metadata = isRecord14(candidate._meta) ? candidate._meta : {};
|
|
23973
24456
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
24457
|
+
if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
|
|
24458
|
+
defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
|
|
24459
|
+
}
|
|
23974
24460
|
if (typeof metadata.totalContextTokens === "number" && Number.isSafeInteger(metadata.totalContextTokens) && metadata.totalContextTokens > 0) {
|
|
23975
24461
|
contextWindowTokensByModel.set(ref.data.id, metadata.totalContextTokens);
|
|
23976
24462
|
}
|
|
@@ -23994,6 +24480,7 @@ function parseGrokModelState(value) {
|
|
|
23994
24480
|
return {
|
|
23995
24481
|
currentModel: currentModel.data,
|
|
23996
24482
|
contextWindowTokensByModel,
|
|
24483
|
+
defaultContextWindowTokensByModel,
|
|
23997
24484
|
...currentThinkingOptionId ? { currentThinkingOptionId } : {},
|
|
23998
24485
|
catalog: {
|
|
23999
24486
|
models,
|
|
@@ -24004,13 +24491,13 @@ function parseGrokModelState(value) {
|
|
|
24004
24491
|
};
|
|
24005
24492
|
}
|
|
24006
24493
|
function modelStateFromInitialize(response) {
|
|
24007
|
-
return parseGrokModelState(
|
|
24494
|
+
return parseGrokModelState(isRecord14(response._meta) ? response._meta.modelState : void 0);
|
|
24008
24495
|
}
|
|
24009
24496
|
function modelStateFromSessionResponse(response) {
|
|
24010
|
-
return parseGrokModelState(
|
|
24497
|
+
return parseGrokModelState(isRecord14(response) ? response.models : void 0);
|
|
24011
24498
|
}
|
|
24012
|
-
function stateForGrokModel(modelState, nativeState,
|
|
24013
|
-
const selectedModel =
|
|
24499
|
+
function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
24500
|
+
const selectedModel = model2;
|
|
24014
24501
|
const catalogModel = modelState.catalog.models.find(({ ref }) => ref.id === selectedModel.id);
|
|
24015
24502
|
const availableThinkingOptions = catalogModel?.supportedThinkingOptionIds?.flatMap((id) => {
|
|
24016
24503
|
const option = modelState.catalog.thinkingOptions.find((candidate) => candidate.id === id);
|
|
@@ -24026,12 +24513,12 @@ function stateForGrokModel(modelState, nativeState, model = modelState.currentMo
|
|
|
24026
24513
|
}
|
|
24027
24514
|
|
|
24028
24515
|
// dist/grok-credits.js
|
|
24029
|
-
import { readFile as
|
|
24030
|
-
import
|
|
24031
|
-
import
|
|
24516
|
+
import { readFile as readFile5 } from "node:fs/promises";
|
|
24517
|
+
import os6 from "node:os";
|
|
24518
|
+
import path14 from "node:path";
|
|
24032
24519
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
24033
24520
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
24034
|
-
function
|
|
24521
|
+
function isRecord15(value) {
|
|
24035
24522
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24036
24523
|
}
|
|
24037
24524
|
function finitePercent(value) {
|
|
@@ -24040,15 +24527,15 @@ function finitePercent(value) {
|
|
|
24040
24527
|
return Math.min(100, Math.max(0, value));
|
|
24041
24528
|
}
|
|
24042
24529
|
function nonNegativeCentValue(value) {
|
|
24043
|
-
if (!
|
|
24530
|
+
if (!isRecord15(value))
|
|
24044
24531
|
return void 0;
|
|
24045
24532
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
24046
24533
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
24047
24534
|
return void 0;
|
|
24048
24535
|
return amount;
|
|
24049
24536
|
}
|
|
24050
|
-
function
|
|
24051
|
-
return environment.GROK_HOME ??
|
|
24537
|
+
function grokHome2(environment) {
|
|
24538
|
+
return environment.GROK_HOME ?? path14.join(environment.HOME ?? environment.USERPROFILE ?? os6.homedir(), ".grok");
|
|
24052
24539
|
}
|
|
24053
24540
|
function periodTypeFrom(value) {
|
|
24054
24541
|
if (typeof value !== "string")
|
|
@@ -24064,7 +24551,7 @@ function productUsageFrom(value) {
|
|
|
24064
24551
|
if (!Array.isArray(value))
|
|
24065
24552
|
return void 0;
|
|
24066
24553
|
const products = value.flatMap((entry) => {
|
|
24067
|
-
if (!
|
|
24554
|
+
if (!isRecord15(entry) || typeof entry.product !== "string")
|
|
24068
24555
|
return [];
|
|
24069
24556
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
24070
24557
|
return usagePercent === void 0 ? [] : [{ product: entry.product, usagePercent }];
|
|
@@ -24072,10 +24559,10 @@ function productUsageFrom(value) {
|
|
|
24072
24559
|
return products.length > 0 ? products : void 0;
|
|
24073
24560
|
}
|
|
24074
24561
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
24075
|
-
if (!
|
|
24562
|
+
if (!isRecord15(value) || !isRecord15(value.config))
|
|
24076
24563
|
return null;
|
|
24077
24564
|
const config2 = value.config;
|
|
24078
|
-
const period =
|
|
24565
|
+
const period = isRecord15(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
24079
24566
|
const periodType = periodTypeFrom(period?.type);
|
|
24080
24567
|
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);
|
|
24081
24568
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -24102,11 +24589,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
24102
24589
|
};
|
|
24103
24590
|
}
|
|
24104
24591
|
function selectAccessToken(auth, now) {
|
|
24105
|
-
if (!
|
|
24592
|
+
if (!isRecord15(auth))
|
|
24106
24593
|
return null;
|
|
24107
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
24594
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord15(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")));
|
|
24108
24595
|
for (const [, value] of entries) {
|
|
24109
|
-
if (!
|
|
24596
|
+
if (!isRecord15(value) || typeof value.key !== "string")
|
|
24110
24597
|
continue;
|
|
24111
24598
|
if (typeof value.expires_at === "string") {
|
|
24112
24599
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -24127,8 +24614,8 @@ async function fetchGrokAccount(input = {}) {
|
|
|
24127
24614
|
if ([environment.XAI_API_KEY, environment.GROK_API_KEY, environment.GROK_TOKEN].some((value) => value?.trim()))
|
|
24128
24615
|
return null;
|
|
24129
24616
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
24130
|
-
const authPath =
|
|
24131
|
-
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await
|
|
24617
|
+
const authPath = path14.join(grokHome2(environment), "auth.json");
|
|
24618
|
+
const raw = input.readAuthFile ? await input.readAuthFile(authPath) : await readFile5(authPath, "utf8");
|
|
24132
24619
|
const token = selectAccessToken(JSON.parse(raw), now);
|
|
24133
24620
|
if (!token)
|
|
24134
24621
|
return null;
|
|
@@ -24177,7 +24664,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
24177
24664
|
|
|
24178
24665
|
// dist/grok-usage.js
|
|
24179
24666
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
24180
|
-
function
|
|
24667
|
+
function isRecord16(value) {
|
|
24181
24668
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24182
24669
|
}
|
|
24183
24670
|
function optionalToken(value) {
|
|
@@ -24194,7 +24681,7 @@ function combineUsage(base, next) {
|
|
|
24194
24681
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
24195
24682
|
}
|
|
24196
24683
|
function usageFromNative(value) {
|
|
24197
|
-
if (!
|
|
24684
|
+
if (!isRecord16(value))
|
|
24198
24685
|
return null;
|
|
24199
24686
|
const inputTokens = optionalToken(value.inputTokens);
|
|
24200
24687
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -24217,11 +24704,108 @@ function usageFromNative(value) {
|
|
|
24217
24704
|
return null;
|
|
24218
24705
|
}
|
|
24219
24706
|
}
|
|
24220
|
-
function
|
|
24221
|
-
|
|
24707
|
+
function usageFromResponse(value) {
|
|
24708
|
+
if (!isRecord16(value))
|
|
24709
|
+
return null;
|
|
24710
|
+
const buckets = [
|
|
24711
|
+
value.input_tokens,
|
|
24712
|
+
value.cache_read_input_tokens,
|
|
24713
|
+
value.cache_creation_input_tokens
|
|
24714
|
+
];
|
|
24715
|
+
const inputTokens = buckets.every((n) => typeof n === "number" && Number.isSafeInteger(n) && n >= 0) ? buckets.reduce((sum, n) => sum + n, 0) : void 0;
|
|
24716
|
+
const outputTokens = optionalToken(value.output_tokens);
|
|
24717
|
+
return usageFromNative({
|
|
24718
|
+
inputTokens,
|
|
24719
|
+
outputTokens,
|
|
24720
|
+
cachedReadTokens: value.cache_read_input_tokens,
|
|
24721
|
+
cacheCreationTokens: value.cache_creation_input_tokens,
|
|
24722
|
+
reasoningTokens: value.reasoning_tokens,
|
|
24723
|
+
...inputTokens !== void 0 && outputTokens !== void 0 ? { totalTokens: inputTokens + outputTokens } : {}
|
|
24724
|
+
});
|
|
24222
24725
|
}
|
|
24726
|
+
var GrokTurnUsage = class {
|
|
24727
|
+
#totals = {};
|
|
24728
|
+
#seen = /* @__PURE__ */ new Set();
|
|
24729
|
+
#cacheComplete;
|
|
24730
|
+
#compacting = false;
|
|
24731
|
+
#startedAtMs;
|
|
24732
|
+
#streamKey;
|
|
24733
|
+
#outputTokens = 0;
|
|
24734
|
+
#durationMs = 0;
|
|
24735
|
+
#latestCacheHit;
|
|
24736
|
+
constructor(base, emptySession = false) {
|
|
24737
|
+
for (const field of summedUsageFields) {
|
|
24738
|
+
const value = base?.[field];
|
|
24739
|
+
if (value !== void 0)
|
|
24740
|
+
this.#totals[field] = value;
|
|
24741
|
+
}
|
|
24742
|
+
this.#cacheComplete = base?.sessionCacheUsage !== void 0 || emptySession;
|
|
24743
|
+
}
|
|
24744
|
+
observe(event) {
|
|
24745
|
+
if (event.type === "compaction.started" || event.type === "compaction.completed") {
|
|
24746
|
+
this.#startedAtMs = void 0;
|
|
24747
|
+
this.#streamKey = void 0;
|
|
24748
|
+
this.#compacting = event.type === "compaction.started";
|
|
24749
|
+
}
|
|
24750
|
+
if (this.#compacting)
|
|
24751
|
+
return null;
|
|
24752
|
+
if (event.type === "subagent.spawned")
|
|
24753
|
+
this.#cacheComplete = false;
|
|
24754
|
+
if (event.type === "agent.text" || event.type === "agent.thought" || event.type === "tool.input.delta") {
|
|
24755
|
+
if (!event.text)
|
|
24756
|
+
return null;
|
|
24757
|
+
const key = event.metadata?.streamStartMs;
|
|
24758
|
+
if (key !== void 0 && this.#streamKey !== void 0 && key !== this.#streamKey)
|
|
24759
|
+
this.#startedAtMs = void 0;
|
|
24760
|
+
if (key !== void 0)
|
|
24761
|
+
this.#streamKey = key;
|
|
24762
|
+
this.#startedAtMs ??= Date.now();
|
|
24763
|
+
}
|
|
24764
|
+
if (event.type !== "response.completed")
|
|
24765
|
+
return null;
|
|
24766
|
+
if (event.messageId) {
|
|
24767
|
+
if (this.#seen.has(event.messageId))
|
|
24768
|
+
return null;
|
|
24769
|
+
this.#seen.add(event.messageId);
|
|
24770
|
+
}
|
|
24771
|
+
const duration3 = this.#startedAtMs === void 0 ? 0 : Date.now() - this.#startedAtMs;
|
|
24772
|
+
this.#startedAtMs = void 0;
|
|
24773
|
+
this.#streamKey = void 0;
|
|
24774
|
+
const usage = usageFromResponse(event.usage);
|
|
24775
|
+
this.#latestCacheHit = usage?.cacheHitRatePercent;
|
|
24776
|
+
if (usage?.inputTokens === void 0 || usage.cachedInputTokens === void 0)
|
|
24777
|
+
this.#cacheComplete = false;
|
|
24778
|
+
if (usage) {
|
|
24779
|
+
for (const field of summedUsageFields) {
|
|
24780
|
+
const value = usage[field];
|
|
24781
|
+
if (value !== void 0)
|
|
24782
|
+
this.#totals[field] = (this.#totals[field] ?? 0) + value;
|
|
24783
|
+
}
|
|
24784
|
+
if (duration3 > 0 && usage.outputTokens !== void 0) {
|
|
24785
|
+
this.#outputTokens += usage.outputTokens;
|
|
24786
|
+
this.#durationMs += duration3;
|
|
24787
|
+
}
|
|
24788
|
+
}
|
|
24789
|
+
return this.snapshot();
|
|
24790
|
+
}
|
|
24791
|
+
metrics() {
|
|
24792
|
+
return {
|
|
24793
|
+
...this.#durationMs > 0 ? { outputTokensPerSecond: this.#outputTokens * 1e3 / this.#durationMs } : {},
|
|
24794
|
+
...this.#latestCacheHit !== void 0 ? { cacheHitRatePercent: this.#latestCacheHit } : {}
|
|
24795
|
+
};
|
|
24796
|
+
}
|
|
24797
|
+
snapshot() {
|
|
24798
|
+
const inputTokens = this.#totals.inputTokens;
|
|
24799
|
+
const cachedInputTokens = this.#totals.cachedInputTokens;
|
|
24800
|
+
return {
|
|
24801
|
+
...this.#totals,
|
|
24802
|
+
...this.metrics(),
|
|
24803
|
+
...this.#cacheComplete && inputTokens !== void 0 && cachedInputTokens !== void 0 ? { sessionCacheUsage: { inputTokens, cachedInputTokens } } : {}
|
|
24804
|
+
};
|
|
24805
|
+
}
|
|
24806
|
+
};
|
|
24223
24807
|
function usageFromSignals(value) {
|
|
24224
|
-
if (!
|
|
24808
|
+
if (!isRecord16(value))
|
|
24225
24809
|
return null;
|
|
24226
24810
|
try {
|
|
24227
24811
|
return parseHostUsage({
|
|
@@ -24241,13 +24825,23 @@ var summedUsageFields = [
|
|
|
24241
24825
|
"totalTokens"
|
|
24242
24826
|
];
|
|
24243
24827
|
function nativeCostTicks(value) {
|
|
24244
|
-
if (!
|
|
24828
|
+
if (!isRecord16(value))
|
|
24245
24829
|
return void 0;
|
|
24246
24830
|
const ticks = value.costUsdTicks;
|
|
24247
24831
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
24248
24832
|
return void 0;
|
|
24249
24833
|
return ticks;
|
|
24250
24834
|
}
|
|
24835
|
+
function sessionCostFromNative(value, initialCostUsd) {
|
|
24836
|
+
if (!isRecord16(value))
|
|
24837
|
+
return void 0;
|
|
24838
|
+
if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
|
|
24839
|
+
return void 0;
|
|
24840
|
+
if (value.usageIsIncomplete !== void 0 && value.usageIsIncomplete !== false)
|
|
24841
|
+
return void 0;
|
|
24842
|
+
const ticks = nativeCostTicks(value);
|
|
24843
|
+
return ticks === void 0 ? void 0 : optionalCostUsd(Math.round(initialCostUsd * USD_TICKS_PER_DOLLAR) + ticks);
|
|
24844
|
+
}
|
|
24251
24845
|
function historyTurnKey(event, index) {
|
|
24252
24846
|
const key = event.nativeTurnKey;
|
|
24253
24847
|
if (typeof key === "string" && key.startsWith("task-completed-"))
|
|
@@ -24256,7 +24850,6 @@ function historyTurnKey(event, index) {
|
|
|
24256
24850
|
}
|
|
24257
24851
|
function sessionUsageFromHistory(events) {
|
|
24258
24852
|
const latestByKey = /* @__PURE__ */ new Map();
|
|
24259
|
-
let lastCacheHitRatePercent;
|
|
24260
24853
|
let index = 0;
|
|
24261
24854
|
for (const event of events) {
|
|
24262
24855
|
if (event?.type !== "turn.completed")
|
|
@@ -24265,26 +24858,26 @@ function sessionUsageFromHistory(events) {
|
|
|
24265
24858
|
index += 1;
|
|
24266
24859
|
if (key === null)
|
|
24267
24860
|
continue;
|
|
24268
|
-
|
|
24269
|
-
if (!usage)
|
|
24861
|
+
if (event.usage === void 0 && latestByKey.has(key))
|
|
24270
24862
|
continue;
|
|
24863
|
+
const usage = usageFromNative(event.usage);
|
|
24271
24864
|
const ticks2 = nativeCostTicks(event.usage);
|
|
24272
|
-
|
|
24273
|
-
|
|
24274
|
-
lastCacheHitRatePercent = usage.cacheHitRatePercent;
|
|
24275
|
-
}
|
|
24865
|
+
const complete = isRecord16(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && usage.cachedInputTokens <= usage.inputTokens;
|
|
24866
|
+
latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
|
|
24276
24867
|
}
|
|
24277
24868
|
if (latestByKey.size === 0)
|
|
24278
24869
|
return null;
|
|
24279
|
-
const
|
|
24870
|
+
const totals2 = {};
|
|
24280
24871
|
let ticks = 0;
|
|
24281
24872
|
let hasTicks = false;
|
|
24282
24873
|
for (const entry of latestByKey.values()) {
|
|
24874
|
+
if (!entry.usage)
|
|
24875
|
+
continue;
|
|
24283
24876
|
for (const field of summedUsageFields) {
|
|
24284
24877
|
const value = entry.usage[field];
|
|
24285
24878
|
if (value === void 0)
|
|
24286
24879
|
continue;
|
|
24287
|
-
|
|
24880
|
+
totals2[field] = (totals2[field] ?? 0) + value;
|
|
24288
24881
|
}
|
|
24289
24882
|
if (entry.ticks === void 0)
|
|
24290
24883
|
continue;
|
|
@@ -24294,9 +24887,14 @@ function sessionUsageFromHistory(events) {
|
|
|
24294
24887
|
const totalCostUsd = hasTicks ? optionalCostUsd(ticks) : void 0;
|
|
24295
24888
|
try {
|
|
24296
24889
|
return parseHostUsage({
|
|
24297
|
-
...
|
|
24890
|
+
...totals2,
|
|
24298
24891
|
...totalCostUsd !== void 0 ? { totalCostUsd } : {},
|
|
24299
|
-
...
|
|
24892
|
+
...[...latestByKey.values()].every((entry) => entry.complete) && totals2.inputTokens !== void 0 && totals2.cachedInputTokens !== void 0 ? {
|
|
24893
|
+
sessionCacheUsage: {
|
|
24894
|
+
inputTokens: totals2.inputTokens,
|
|
24895
|
+
cachedInputTokens: totals2.cachedInputTokens
|
|
24896
|
+
}
|
|
24897
|
+
} : {}
|
|
24300
24898
|
});
|
|
24301
24899
|
} catch {
|
|
24302
24900
|
return null;
|
|
@@ -24318,7 +24916,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
24318
24916
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
24319
24917
|
try {
|
|
24320
24918
|
if (update?.sessionUpdate === "usage_update") {
|
|
24321
|
-
const cost =
|
|
24919
|
+
const cost = isRecord16(update.cost) ? update.cost : null;
|
|
24322
24920
|
return parseHostUsage({
|
|
24323
24921
|
contextUsedTokens: update.used,
|
|
24324
24922
|
contextWindowTokens: update.size,
|
|
@@ -24449,6 +25047,8 @@ var GrokHarnessSession = class {
|
|
|
24449
25047
|
#phase = "open";
|
|
24450
25048
|
#state;
|
|
24451
25049
|
#usage = null;
|
|
25050
|
+
#initialCostUsd;
|
|
25051
|
+
#costRequest = 0;
|
|
24452
25052
|
constructor(cwd, transport, opened, modelState, onClosed, options) {
|
|
24453
25053
|
this.#cwd = cwd;
|
|
24454
25054
|
this.#sessionDirectory = options.sessionDirectory;
|
|
@@ -24462,6 +25062,7 @@ var GrokHarnessSession = class {
|
|
|
24462
25062
|
this.#toolOutputLimit = options.toolOutputLimit;
|
|
24463
25063
|
this.initialUsage = options.initialUsage ?? null;
|
|
24464
25064
|
this.#usage = this.initialUsage;
|
|
25065
|
+
this.#initialCostUsd = this.initialUsage?.totalCostUsd ?? 0;
|
|
24465
25066
|
this.capabilities = capabilitiesForModels(modelState);
|
|
24466
25067
|
this.commands = {
|
|
24467
25068
|
list: async () => ({ ok: true, value: this.#liveCommandCatalog() }),
|
|
@@ -24550,6 +25151,7 @@ var GrokHarnessSession = class {
|
|
|
24550
25151
|
});
|
|
24551
25152
|
const active = {
|
|
24552
25153
|
command,
|
|
25154
|
+
usage: new GrokTurnUsage(this.#usage, this.#snapshot.turns.length === 0),
|
|
24553
25155
|
agent: null,
|
|
24554
25156
|
agentMessageId: null,
|
|
24555
25157
|
rawAgentText: "",
|
|
@@ -24725,9 +25327,9 @@ var GrokHarnessSession = class {
|
|
|
24725
25327
|
}
|
|
24726
25328
|
async #selectThinking(command) {
|
|
24727
25329
|
const parsed = harnessThinkingOptionIdSchema.safeParse(command.thinkingOptionId);
|
|
24728
|
-
const
|
|
24729
|
-
const available = this.#modelState.catalog.models.find(({ ref }) => ref.id ===
|
|
24730
|
-
if (!parsed.success || !
|
|
25330
|
+
const model2 = this.#state.effectiveModel;
|
|
25331
|
+
const available = this.#modelState.catalog.models.find(({ ref }) => ref.id === model2?.id);
|
|
25332
|
+
if (!parsed.success || !model2 || !available?.supportedThinkingOptionIds?.includes(parsed.data)) {
|
|
24731
25333
|
return {
|
|
24732
25334
|
ok: false,
|
|
24733
25335
|
error: {
|
|
@@ -24737,9 +25339,9 @@ var GrokHarnessSession = class {
|
|
|
24737
25339
|
}
|
|
24738
25340
|
};
|
|
24739
25341
|
}
|
|
24740
|
-
return this.#configure(
|
|
25342
|
+
return this.#configure(model2, parsed.data);
|
|
24741
25343
|
}
|
|
24742
|
-
async #configure(
|
|
25344
|
+
async #configure(model2, thinkingOptionId) {
|
|
24743
25345
|
if (this.#configuring) {
|
|
24744
25346
|
return {
|
|
24745
25347
|
ok: false,
|
|
@@ -24752,9 +25354,20 @@ var GrokHarnessSession = class {
|
|
|
24752
25354
|
}
|
|
24753
25355
|
this.#configuring = true;
|
|
24754
25356
|
try {
|
|
24755
|
-
|
|
24756
|
-
|
|
25357
|
+
const contextWindow = this.#modelState.defaultContextWindowTokensByModel.get(model2.id);
|
|
25358
|
+
await this.#transport.setModel(model2.id, thinkingOptionId, contextWindow);
|
|
25359
|
+
if (contextWindow !== void 0) {
|
|
25360
|
+
this.#modelState.contextWindowTokensByModel = new Map([
|
|
25361
|
+
...this.#modelState.contextWindowTokensByModel,
|
|
25362
|
+
[model2.id, contextWindow]
|
|
25363
|
+
]);
|
|
25364
|
+
}
|
|
25365
|
+
this.#state = stateForGrokModel(this.#modelState, { nativeRef: nativeRef(this.#transport.sessionId) }, model2, thinkingOptionId, this.#state.effectivePermissionModeId);
|
|
24757
25366
|
this.#event({ type: "session.state.changed", state: this.#state });
|
|
25367
|
+
const selectedWindow = this.#modelState.contextWindowTokensByModel.get(model2.id);
|
|
25368
|
+
if (selectedWindow !== void 0 && this.#usage?.contextUsedTokens !== void 0) {
|
|
25369
|
+
this.#publishUsage({ contextWindowTokens: selectedWindow });
|
|
25370
|
+
}
|
|
24758
25371
|
return { ok: true, value: { completed: true } };
|
|
24759
25372
|
} catch (error53) {
|
|
24760
25373
|
return { ok: false, error: normalizeError(error53, "nativeFailure") };
|
|
@@ -24867,6 +25480,11 @@ var GrokHarnessSession = class {
|
|
|
24867
25480
|
#handleEvent(active, event) {
|
|
24868
25481
|
if (this.#active !== active || this.#phase !== "open")
|
|
24869
25482
|
return;
|
|
25483
|
+
const requestUsage = active.usage?.observe(event);
|
|
25484
|
+
if (requestUsage) {
|
|
25485
|
+
this.#publishUsage(requestUsage, active.command.turnId, true);
|
|
25486
|
+
void this.#refreshCost(active);
|
|
25487
|
+
}
|
|
24870
25488
|
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);
|
|
24871
25489
|
if (contextUsage)
|
|
24872
25490
|
this.#publishUsage(contextUsage, active.command.turnId);
|
|
@@ -24890,6 +25508,17 @@ var GrokHarnessSession = class {
|
|
|
24890
25508
|
} else if (event.type === "usage" || event.type === "turn.completed")
|
|
24891
25509
|
return;
|
|
24892
25510
|
}
|
|
25511
|
+
async #refreshCost(active) {
|
|
25512
|
+
const request = ++this.#costRequest;
|
|
25513
|
+
try {
|
|
25514
|
+
const totalCostUsd = sessionCostFromNative(await this.#transport.getUsage(), this.#initialCostUsd);
|
|
25515
|
+
if (this.#active !== active || this.#phase !== "open" || request !== this.#costRequest)
|
|
25516
|
+
return;
|
|
25517
|
+
if (totalCostUsd !== void 0)
|
|
25518
|
+
this.#publishUsage({ totalCostUsd }, active.command.turnId);
|
|
25519
|
+
} catch {
|
|
25520
|
+
}
|
|
25521
|
+
}
|
|
24893
25522
|
#startCompaction(active, event) {
|
|
24894
25523
|
if (active.compactionItem)
|
|
24895
25524
|
return;
|
|
@@ -25002,14 +25631,14 @@ var GrokHarnessSession = class {
|
|
|
25002
25631
|
const prompt = grokSubagentPrompt(event.rawInput);
|
|
25003
25632
|
const role = grokSubagentRole(event.rawInput);
|
|
25004
25633
|
const nativeSubagentId = grokNativeSubagentId(event.rawInput);
|
|
25005
|
-
const
|
|
25634
|
+
const model2 = grokSubagentModel(event.rawInput);
|
|
25006
25635
|
active.subagents.start(active.command.turnId, {
|
|
25007
25636
|
callId: event.callId,
|
|
25008
25637
|
operation,
|
|
25009
25638
|
description: grokSubagentDescription(event.rawInput, event.title),
|
|
25010
25639
|
...prompt ? { prompt } : {},
|
|
25011
25640
|
...role ? { role } : {},
|
|
25012
|
-
...
|
|
25641
|
+
...model2 ? { model: model2 } : {},
|
|
25013
25642
|
background: grokSubagentBackground(event.rawInput),
|
|
25014
25643
|
...nativeSubagentId ? { nativeSubagentId } : {}
|
|
25015
25644
|
});
|
|
@@ -25234,8 +25863,18 @@ var GrokHarnessSession = class {
|
|
|
25234
25863
|
outcome = { status: "failed", error: normalizeError(error53, "protocolError") };
|
|
25235
25864
|
}
|
|
25236
25865
|
}
|
|
25866
|
+
const promptUsage = response?.usage ?? response?._meta?.usage;
|
|
25867
|
+
if (nativeTurnRef && promptUsage !== void 0 && !history.some((event) => event.type === "turn.completed" && event.nativeTurnKey === nativeTurnRef.nativeTurnKey && event.usage !== void 0)) {
|
|
25868
|
+
history.push({
|
|
25869
|
+
type: "turn.completed",
|
|
25870
|
+
nativeTurnKey: nativeTurnRef.nativeTurnKey,
|
|
25871
|
+
stopReason: response?.stopReason ?? "end_turn",
|
|
25872
|
+
usage: promptUsage
|
|
25873
|
+
});
|
|
25874
|
+
}
|
|
25875
|
+
const usage = sessionUsageFromHistory(history);
|
|
25237
25876
|
await this.#refreshCredits().catch(() => void 0);
|
|
25238
|
-
this.#finish(active, checkpoint ? { ...outcome, checkpoint } : outcome,
|
|
25877
|
+
this.#finish(active, checkpoint ? { ...outcome, checkpoint } : outcome, usage, nativeTurnRef);
|
|
25239
25878
|
}
|
|
25240
25879
|
#finish(active, outcome, usage = null, nativeTurnRef) {
|
|
25241
25880
|
if (this.#active !== active)
|
|
@@ -25262,8 +25901,8 @@ var GrokHarnessSession = class {
|
|
|
25262
25901
|
});
|
|
25263
25902
|
}
|
|
25264
25903
|
this.#active = null;
|
|
25265
|
-
if (usage)
|
|
25266
|
-
this.#publishUsage(usage, active.command.turnId);
|
|
25904
|
+
if (usage || this.#usage)
|
|
25905
|
+
this.#publishUsage({ ...usage, ...active.usage?.metrics() }, active.command.turnId, true);
|
|
25267
25906
|
this.#event({
|
|
25268
25907
|
type: "turn.completed",
|
|
25269
25908
|
turnId: active.command.turnId,
|
|
@@ -25272,8 +25911,14 @@ var GrokHarnessSession = class {
|
|
|
25272
25911
|
});
|
|
25273
25912
|
active.resolveCompletion();
|
|
25274
25913
|
}
|
|
25275
|
-
#publishUsage(usage, observedForTurnId) {
|
|
25276
|
-
const
|
|
25914
|
+
#publishUsage(usage, observedForTurnId, replaceMetrics = false) {
|
|
25915
|
+
const base = this.#usage ? { ...this.#usage } : null;
|
|
25916
|
+
if (base && replaceMetrics) {
|
|
25917
|
+
delete base.outputTokensPerSecond;
|
|
25918
|
+
delete base.cacheHitRatePercent;
|
|
25919
|
+
delete base.sessionCacheUsage;
|
|
25920
|
+
}
|
|
25921
|
+
const merged = combineUsage(base, usage);
|
|
25277
25922
|
if (merged === null || JSON.stringify(merged) === JSON.stringify(this.#usage))
|
|
25278
25923
|
return;
|
|
25279
25924
|
this.#usage = merged;
|
|
@@ -25331,6 +25976,7 @@ var GrokAdapter = class {
|
|
|
25331
25976
|
liveCommandCatalog = true;
|
|
25332
25977
|
harnessId = grokHarnessId;
|
|
25333
25978
|
sessionImport;
|
|
25979
|
+
usageStatistics;
|
|
25334
25980
|
subagents = {
|
|
25335
25981
|
readSnapshot: async (input) => {
|
|
25336
25982
|
if (input.parent.harnessId !== this.harnessId || input.nativeSubagentId.trim().length === 0) {
|
|
@@ -25379,6 +26025,7 @@ var GrokAdapter = class {
|
|
|
25379
26025
|
this.#closeTimeoutMs = options.closeTimeoutMs ?? DEFAULT_CLOSE_TIMEOUT_MS;
|
|
25380
26026
|
this.#environment = options.environment;
|
|
25381
26027
|
this.sessionImport = new GrokSessionImport(options.environment);
|
|
26028
|
+
this.usageStatistics = createGrokUsageStatistics(options.environment ?? process.env);
|
|
25382
26029
|
this.#toolOutputLimit = options.toolOutputLimit ?? DEFAULT_GROK_TOOL_OUTPUT_LIMIT;
|
|
25383
26030
|
this.#dependencies = dependencies ?? {
|
|
25384
26031
|
randomUUID,
|
|
@@ -25422,7 +26069,7 @@ var GrokAdapter = class {
|
|
|
25422
26069
|
async inspect(input = {}) {
|
|
25423
26070
|
if (this.#closePromise)
|
|
25424
26071
|
return { status: "unavailable", error: invalidState("Grok Adapter is closed") };
|
|
25425
|
-
const cwd =
|
|
26072
|
+
const cwd = path15.resolve(input.cwd ?? process.cwd());
|
|
25426
26073
|
if (!input.refresh) {
|
|
25427
26074
|
const cached2 = this.#inspectionCache.get(cwd);
|
|
25428
26075
|
if (cached2)
|
|
@@ -25484,7 +26131,7 @@ var GrokAdapter = class {
|
|
|
25484
26131
|
}
|
|
25485
26132
|
};
|
|
25486
26133
|
}
|
|
25487
|
-
const cwd =
|
|
26134
|
+
const cwd = path15.resolve(input.cwd);
|
|
25488
26135
|
const parsedRef = input.kind === "resume" ? nativeSessionRefSchema.safeParse(input.nativeRef) : null;
|
|
25489
26136
|
if (parsedRef && (!parsedRef.success || parsedRef.data.harnessId !== this.harnessId)) {
|
|
25490
26137
|
return {
|
|
@@ -25588,6 +26235,8 @@ var GrokAdapter = class {
|
|
|
25588
26235
|
const modelState = modelStateFromSessionResponse(opened.session) ?? modelStateFromInitialize(opened.initialize);
|
|
25589
26236
|
if (!modelState)
|
|
25590
26237
|
throw new GrokTransportError("protocolError", "Grok returned an invalid Model catalog");
|
|
26238
|
+
const nativeModelId = modelState.currentModel.id;
|
|
26239
|
+
const nativeThinkingOptionId = modelState.currentThinkingOptionId;
|
|
25591
26240
|
const retainedConfiguration = sourceConfiguration;
|
|
25592
26241
|
if ((input.kind === "rollbackLastTurn" || input.kind === "fork") && retainedConfiguration) {
|
|
25593
26242
|
const operation = input.kind === "rollbackLastTurn" ? "Rewind" : "Fork";
|
|
@@ -25600,7 +26249,6 @@ var GrokAdapter = class {
|
|
|
25600
26249
|
throw new GrokTransportError("protocolError", `Grok Thinking option is unavailable after ${operation}`);
|
|
25601
26250
|
}
|
|
25602
26251
|
if (retainedConfiguration.model.id !== modelState.currentModel.id || retainedConfiguration.thinkingOptionId !== modelState.currentThinkingOptionId) {
|
|
25603
|
-
await transport.setModel(retainedConfiguration.model.id, retainedConfiguration.thinkingOptionId);
|
|
25604
26252
|
modelState.currentModel = retainedConfiguration.model;
|
|
25605
26253
|
if (retainedConfiguration.thinkingOptionId) {
|
|
25606
26254
|
modelState.currentThinkingOptionId = retainedConfiguration.thinkingOptionId;
|
|
@@ -25619,7 +26267,6 @@ var GrokAdapter = class {
|
|
|
25619
26267
|
throw new GrokTransportError("protocolError", "Requested Grok Thinking option is unavailable");
|
|
25620
26268
|
}
|
|
25621
26269
|
if (selectedModel.id !== modelState.currentModel.id || selectedThinking !== modelState.currentThinkingOptionId) {
|
|
25622
|
-
await transport.setModel(selectedModel.id, selectedThinking);
|
|
25623
26270
|
modelState.currentModel = selectedModel;
|
|
25624
26271
|
if (selectedThinking)
|
|
25625
26272
|
modelState.currentThinkingOptionId = selectedThinking;
|
|
@@ -25627,8 +26274,21 @@ var GrokAdapter = class {
|
|
|
25627
26274
|
delete modelState.currentThinkingOptionId;
|
|
25628
26275
|
}
|
|
25629
26276
|
}
|
|
26277
|
+
const contextWindow = modelState.defaultContextWindowTokensByModel.get(modelState.currentModel.id);
|
|
26278
|
+
if (modelState.currentModel.id !== nativeModelId || modelState.currentThinkingOptionId !== nativeThinkingOptionId || contextWindow !== void 0 && modelState.contextWindowTokensByModel.get(modelState.currentModel.id) !== contextWindow) {
|
|
26279
|
+
await transport.setModel(modelState.currentModel.id, modelState.currentThinkingOptionId, contextWindow);
|
|
26280
|
+
if (contextWindow !== void 0) {
|
|
26281
|
+
modelState.contextWindowTokensByModel = new Map([
|
|
26282
|
+
...modelState.contextWindowTokensByModel,
|
|
26283
|
+
[modelState.currentModel.id, contextWindow]
|
|
26284
|
+
]);
|
|
26285
|
+
}
|
|
26286
|
+
}
|
|
25630
26287
|
const history = await transport.getHistory();
|
|
25631
|
-
|
|
26288
|
+
let initialUsage = input.kind === "resume" || input.kind === "fork" || input.kind === "rollbackLastTurn" ? combineUsage(sessionUsageFromHistory(history), usageFromSignals(opened.signals)) : null;
|
|
26289
|
+
if (contextWindow !== void 0 && initialUsage?.contextUsedTokens !== void 0) {
|
|
26290
|
+
initialUsage = combineUsage(initialUsage, { contextWindowTokens: contextWindow });
|
|
26291
|
+
}
|
|
25632
26292
|
const environment = input.environment ?? this.#environment;
|
|
25633
26293
|
const sessionDirectory = grokNativeSessionDirectory(environment ? { cwd, environment } : { cwd }, opened.sessionId);
|
|
25634
26294
|
const openedSession = new GrokHarnessSession(cwd, transport, opened, modelState, () => this.#sessions.delete(openedSession), {
|