@karlorz/codexhost-cli-win32-x64 0.17.4-0 → 0.17.4-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/host-runtime.mjs +2087 -945
- package/app/plugins/grok/plugin.mjs +207 -153
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +0 -0
- package/package.json +1 -1
|
@@ -17132,6 +17132,60 @@ function grokTextItemId(sessionId, turnIndex, kind, ordinal) {
|
|
|
17132
17132
|
return hostItemIdSchema.parse(`grok-text-${createHash("sha256").update(identity).digest("hex")}`);
|
|
17133
17133
|
}
|
|
17134
17134
|
|
|
17135
|
+
// dist/grok-stop-diagnostic.js
|
|
17136
|
+
function isRecord2(value) {
|
|
17137
|
+
return typeof value === "object" && value !== null && Array.isArray(value) === false;
|
|
17138
|
+
}
|
|
17139
|
+
function collectText(value, into, depth = 0) {
|
|
17140
|
+
if (depth > 4)
|
|
17141
|
+
return;
|
|
17142
|
+
if (typeof value === "string") {
|
|
17143
|
+
const text = value.trim();
|
|
17144
|
+
if (text.length > 0 && !into.includes(text))
|
|
17145
|
+
into.push(text);
|
|
17146
|
+
return;
|
|
17147
|
+
}
|
|
17148
|
+
if (Array.isArray(value)) {
|
|
17149
|
+
for (const entry of value)
|
|
17150
|
+
collectText(entry, into, depth + 1);
|
|
17151
|
+
return;
|
|
17152
|
+
}
|
|
17153
|
+
if (!isRecord2(value))
|
|
17154
|
+
return;
|
|
17155
|
+
for (const key of [
|
|
17156
|
+
"message",
|
|
17157
|
+
"error",
|
|
17158
|
+
"reason",
|
|
17159
|
+
"detail",
|
|
17160
|
+
"details",
|
|
17161
|
+
"diagnostic",
|
|
17162
|
+
"cause",
|
|
17163
|
+
"err"
|
|
17164
|
+
]) {
|
|
17165
|
+
if (Object.hasOwn(value, key))
|
|
17166
|
+
collectText(value[key], into, depth + 1);
|
|
17167
|
+
}
|
|
17168
|
+
}
|
|
17169
|
+
function grokStopDetail(source, stopReason) {
|
|
17170
|
+
const parts = [];
|
|
17171
|
+
collectText(source, parts);
|
|
17172
|
+
const useful = parts.filter((part) => part !== stopReason && part.toLowerCase() !== "error" && part.length > 1);
|
|
17173
|
+
return useful.length > 0 ? useful.join(": ") : void 0;
|
|
17174
|
+
}
|
|
17175
|
+
function grokTurnStopError(stopReason, source) {
|
|
17176
|
+
const detail = grokStopDetail(source, stopReason);
|
|
17177
|
+
const diagnostic = source !== void 0 && source !== null ? JSON.stringify(source) : void 0;
|
|
17178
|
+
return {
|
|
17179
|
+
code: "nativeFailure",
|
|
17180
|
+
message: detail ? `Grok stopped the Turn: ${stopReason}: ${detail}` : `Grok stopped the Turn: ${stopReason}`,
|
|
17181
|
+
retryable: stopReason === "max_tokens" || stopReason === "max_turn_requests",
|
|
17182
|
+
...diagnostic && diagnostic !== "{}" && diagnostic !== "null" ? { diagnostic } : {}
|
|
17183
|
+
};
|
|
17184
|
+
}
|
|
17185
|
+
function grokPromptStopError(response) {
|
|
17186
|
+
return grokTurnStopError(response.stopReason, response._meta ?? void 0);
|
|
17187
|
+
}
|
|
17188
|
+
|
|
17135
17189
|
// dist/grok-agent-messages.js
|
|
17136
17190
|
function settledGrokAgentMessages(persisted, completedItems) {
|
|
17137
17191
|
const messages = persisted.flatMap(({ item }) => item.type === "agentMessage" ? [item] : []);
|
|
@@ -17650,11 +17704,11 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
17650
17704
|
"costSource",
|
|
17651
17705
|
"unpricedModels"
|
|
17652
17706
|
]);
|
|
17653
|
-
function
|
|
17707
|
+
function isRecord3(value) {
|
|
17654
17708
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17655
17709
|
}
|
|
17656
17710
|
function parseHostUsage(value) {
|
|
17657
|
-
if (!
|
|
17711
|
+
if (!isRecord3(value))
|
|
17658
17712
|
throw new Error("Harness Usage must be an object");
|
|
17659
17713
|
const keys = Object.keys(value);
|
|
17660
17714
|
if (keys.length === 0)
|
|
@@ -17701,7 +17755,7 @@ function parseHostUsage(value) {
|
|
|
17701
17755
|
}
|
|
17702
17756
|
if (value.sessionCacheUsage !== void 0) {
|
|
17703
17757
|
const totals2 = value.sessionCacheUsage;
|
|
17704
|
-
if (!
|
|
17758
|
+
if (!isRecord3(totals2) || Object.keys(totals2).some((key) => key !== "inputTokens" && key !== "cachedInputTokens") || typeof totals2.inputTokens !== "number" || !Number.isSafeInteger(totals2.inputTokens) || totals2.inputTokens < 0 || typeof totals2.cachedInputTokens !== "number" || !Number.isSafeInteger(totals2.cachedInputTokens) || totals2.cachedInputTokens < 0 || totals2.cachedInputTokens > totals2.inputTokens) {
|
|
17705
17759
|
throw new Error("Harness Usage 'sessionCacheUsage' must contain complete bounded token totals");
|
|
17706
17760
|
}
|
|
17707
17761
|
}
|
|
@@ -19978,17 +20032,17 @@ function isResponseMessage(value) {
|
|
|
19978
20032
|
function isNotificationMessage(value) {
|
|
19979
20033
|
return isJsonRpcEnvelope(value) && !("id" in value) && typeof value["method"] === "string";
|
|
19980
20034
|
}
|
|
19981
|
-
function
|
|
20035
|
+
function isRecord4(value) {
|
|
19982
20036
|
return typeof value === "object" && value !== null;
|
|
19983
20037
|
}
|
|
19984
20038
|
function isJsonRpcEnvelope(value) {
|
|
19985
|
-
return
|
|
20039
|
+
return isRecord4(value) && value["jsonrpc"] === "2.0";
|
|
19986
20040
|
}
|
|
19987
20041
|
function isJsonRpcId(value) {
|
|
19988
20042
|
return value === null || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
19989
20043
|
}
|
|
19990
20044
|
function isResponseShapedMessage(value) {
|
|
19991
|
-
return
|
|
20045
|
+
return isRecord4(value) && !("method" in value) && ("id" in value || "result" in value || "error" in value);
|
|
19992
20046
|
}
|
|
19993
20047
|
function isResponseBatch(batch) {
|
|
19994
20048
|
let hasValidCall = false;
|
|
@@ -19998,7 +20052,7 @@ function isResponseBatch(batch) {
|
|
|
19998
20052
|
for (const entry of batch) {
|
|
19999
20053
|
hasValidCall ||= isRequestMessage(entry) || isNotificationMessage(entry);
|
|
20000
20054
|
hasValidResponse ||= isResponseMessage(entry);
|
|
20001
|
-
if (!
|
|
20055
|
+
if (!isRecord4(entry)) {
|
|
20002
20056
|
continue;
|
|
20003
20057
|
}
|
|
20004
20058
|
hasCallShape ||= "method" in entry;
|
|
@@ -20013,13 +20067,13 @@ function isResponseBatch(batch) {
|
|
|
20013
20067
|
return hasResponseShape && !hasCallShape;
|
|
20014
20068
|
}
|
|
20015
20069
|
function cancelRequestId(params) {
|
|
20016
|
-
if (!
|
|
20070
|
+
if (!isRecord4(params) || !isJsonRpcId(params["requestId"])) {
|
|
20017
20071
|
return void 0;
|
|
20018
20072
|
}
|
|
20019
20073
|
return params["requestId"];
|
|
20020
20074
|
}
|
|
20021
20075
|
function isErrorResponse(value) {
|
|
20022
|
-
return
|
|
20076
|
+
return isRecord4(value) && typeof value["code"] === "number" && Number.isInteger(value["code"]) && typeof value["message"] === "string";
|
|
20023
20077
|
}
|
|
20024
20078
|
var Handled = {
|
|
20025
20079
|
/**
|
|
@@ -20510,7 +20564,7 @@ var Connection = class {
|
|
|
20510
20564
|
this.receiveBatch(message);
|
|
20511
20565
|
return;
|
|
20512
20566
|
}
|
|
20513
|
-
if (!
|
|
20567
|
+
if (!isRecord4(message)) {
|
|
20514
20568
|
console.error("Invalid message", { message });
|
|
20515
20569
|
return;
|
|
20516
20570
|
}
|
|
@@ -20573,7 +20627,7 @@ var Connection = class {
|
|
|
20573
20627
|
if (this.abortController.signal.aborted) {
|
|
20574
20628
|
return Promise.resolve();
|
|
20575
20629
|
}
|
|
20576
|
-
if (!
|
|
20630
|
+
if (!isRecord4(message)) {
|
|
20577
20631
|
console.error("Invalid message", { message });
|
|
20578
20632
|
return Promise.resolve();
|
|
20579
20633
|
}
|
|
@@ -20943,7 +20997,7 @@ function ndJsonStream(output, input) {
|
|
|
20943
20997
|
if (trimmedLine) {
|
|
20944
20998
|
try {
|
|
20945
20999
|
const message = JSON.parse(trimmedLine);
|
|
20946
|
-
if (
|
|
21000
|
+
if (isRecord4(message) || Array.isArray(message)) {
|
|
20947
21001
|
controller.enqueue(message);
|
|
20948
21002
|
} else {
|
|
20949
21003
|
console.warn("Skipping JSON line that is not an object:", trimmedLine);
|
|
@@ -22406,14 +22460,14 @@ var ClientSideConnection = class {
|
|
|
22406
22460
|
|
|
22407
22461
|
// dist/grok-slash-commands.js
|
|
22408
22462
|
var GROK_LIVE_COMMAND_ID_PREFIX = "grok.slash.";
|
|
22409
|
-
function
|
|
22463
|
+
function isRecord5(value) {
|
|
22410
22464
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22411
22465
|
}
|
|
22412
22466
|
function parseGrokAvailableCommands(value) {
|
|
22413
22467
|
if (!Array.isArray(value))
|
|
22414
22468
|
return [];
|
|
22415
22469
|
return value.flatMap((entry) => {
|
|
22416
|
-
if (!
|
|
22470
|
+
if (!isRecord5(entry))
|
|
22417
22471
|
return [];
|
|
22418
22472
|
const name = typeof entry.name === "string" ? entry.name.trim().replace(/^\//u, "") : "";
|
|
22419
22473
|
if (!name)
|
|
@@ -22422,7 +22476,7 @@ function parseGrokAvailableCommands(value) {
|
|
|
22422
22476
|
{
|
|
22423
22477
|
name,
|
|
22424
22478
|
description: typeof entry.description === "string" ? entry.description : "",
|
|
22425
|
-
meta:
|
|
22479
|
+
meta: isRecord5(entry._meta) ? entry._meta : null
|
|
22426
22480
|
}
|
|
22427
22481
|
];
|
|
22428
22482
|
});
|
|
@@ -23073,7 +23127,7 @@ function splitLines(text) {
|
|
|
23073
23127
|
// dist/grok-file-change.js
|
|
23074
23128
|
var DEFAULT_GROK_FILE_CHANGE_TEXT_LIMIT = 4 * 1024 * 1024;
|
|
23075
23129
|
var MAX_GROK_FILE_CHANGES_PER_TOOL = 32;
|
|
23076
|
-
function
|
|
23130
|
+
function isRecord6(value) {
|
|
23077
23131
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23078
23132
|
}
|
|
23079
23133
|
function validAbsolutePath(value) {
|
|
@@ -23124,7 +23178,7 @@ function projectGrokFileChanges(content, cwd, textLimit = DEFAULT_GROK_FILE_CHAN
|
|
|
23124
23178
|
return null;
|
|
23125
23179
|
const candidates = [];
|
|
23126
23180
|
for (const entry of content) {
|
|
23127
|
-
if (
|
|
23181
|
+
if (isRecord6(entry) && entry.type === "diff")
|
|
23128
23182
|
candidates.push(entry);
|
|
23129
23183
|
}
|
|
23130
23184
|
if (candidates.length === 0 || candidates.length > MAX_GROK_FILE_CHANGES_PER_TOOL)
|
|
@@ -23154,14 +23208,14 @@ function mediaFileExists2(absolutePath) {
|
|
|
23154
23208
|
}
|
|
23155
23209
|
}
|
|
23156
23210
|
var GENERATED_IMAGE_TYPES = /* @__PURE__ */ new Set(["ImageGen", "ImageEdit"]);
|
|
23157
|
-
function
|
|
23211
|
+
function isRecord7(value) {
|
|
23158
23212
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23159
23213
|
}
|
|
23160
23214
|
function stringField(value, key) {
|
|
23161
|
-
return
|
|
23215
|
+
return isRecord7(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
|
|
23162
23216
|
}
|
|
23163
23217
|
function fromNativeRecord(value, exists) {
|
|
23164
|
-
if (!
|
|
23218
|
+
if (!isRecord7(value))
|
|
23165
23219
|
return null;
|
|
23166
23220
|
const type = stringField(value, "type");
|
|
23167
23221
|
const sessionFolder = stringField(value, "session_folder");
|
|
@@ -23198,10 +23252,10 @@ function projectGrokGeneratedImage(content, rawOutput, exists = mediaFileExists2
|
|
|
23198
23252
|
if (!Array.isArray(content))
|
|
23199
23253
|
return null;
|
|
23200
23254
|
for (const entry of content) {
|
|
23201
|
-
if (!
|
|
23255
|
+
if (!isRecord7(entry))
|
|
23202
23256
|
continue;
|
|
23203
|
-
const nested = entry.type === "content" &&
|
|
23204
|
-
if (
|
|
23257
|
+
const nested = entry.type === "content" && isRecord7(entry.content) ? entry.content : entry;
|
|
23258
|
+
if (isRecord7(nested) && nested.type === "text" && typeof nested.text === "string") {
|
|
23205
23259
|
const parsed = fromNativeRecord(parseJsonObject(nested.text), exists);
|
|
23206
23260
|
if (parsed)
|
|
23207
23261
|
return parsed;
|
|
@@ -23249,14 +23303,14 @@ var EXECUTE_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
23249
23303
|
"cursor_shell",
|
|
23250
23304
|
"monitor"
|
|
23251
23305
|
]);
|
|
23252
|
-
function
|
|
23306
|
+
function isRecord8(value) {
|
|
23253
23307
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23254
23308
|
}
|
|
23255
23309
|
function stringField2(value, key) {
|
|
23256
|
-
return
|
|
23310
|
+
return isRecord8(value) && typeof value[key] === "string" && value[key].length > 0 ? value[key] : void 0;
|
|
23257
23311
|
}
|
|
23258
23312
|
function numberField(value, key) {
|
|
23259
|
-
if (!
|
|
23313
|
+
if (!isRecord8(value))
|
|
23260
23314
|
return void 0;
|
|
23261
23315
|
const field2 = value[key];
|
|
23262
23316
|
if (field2 === null)
|
|
@@ -23279,7 +23333,7 @@ function firstReadableText(...candidates) {
|
|
|
23279
23333
|
for (const candidate of candidates) {
|
|
23280
23334
|
if (typeof candidate === "string" && candidate.length > 0)
|
|
23281
23335
|
return candidate;
|
|
23282
|
-
if (
|
|
23336
|
+
if (isRecord8(candidate)) {
|
|
23283
23337
|
const nested = stringField2(candidate, "content") ?? stringField2(candidate, "text") ?? stringField2(candidate, "tool_result") ?? stringField2(candidate, "raw_output");
|
|
23284
23338
|
if (nested)
|
|
23285
23339
|
return nested;
|
|
@@ -23302,7 +23356,7 @@ function grokToolArguments(rawInput) {
|
|
|
23302
23356
|
if (!parsed.success)
|
|
23303
23357
|
return {};
|
|
23304
23358
|
const argumentsValue = parsed.data;
|
|
23305
|
-
if (!
|
|
23359
|
+
if (!isRecord8(argumentsValue) || stringField2(argumentsValue, "path"))
|
|
23306
23360
|
return argumentsValue;
|
|
23307
23361
|
const targetFile = stringField2(argumentsValue, "target_file");
|
|
23308
23362
|
return targetFile ? { ...argumentsValue, path: targetFile } : argumentsValue;
|
|
@@ -23315,7 +23369,7 @@ function grokCommand(name, kind, rawInput) {
|
|
|
23315
23369
|
return command;
|
|
23316
23370
|
if (name && EXECUTE_TOOL_NAMES.has(name))
|
|
23317
23371
|
return command;
|
|
23318
|
-
return
|
|
23372
|
+
return isRecord8(rawInput) && rawInput.variant === "Bash" ? command : void 0;
|
|
23319
23373
|
}
|
|
23320
23374
|
function grokCommandCwd(rawInput, fallback) {
|
|
23321
23375
|
return stringField2(rawInput, "cwd") ?? fallback;
|
|
@@ -23342,11 +23396,11 @@ function acpContentText(content) {
|
|
|
23342
23396
|
if (!Array.isArray(content))
|
|
23343
23397
|
return "";
|
|
23344
23398
|
return content.flatMap((entry) => {
|
|
23345
|
-
if (!
|
|
23399
|
+
if (!isRecord8(entry))
|
|
23346
23400
|
return [];
|
|
23347
23401
|
if (entry.type === "text" && typeof entry.text === "string")
|
|
23348
23402
|
return [entry.text];
|
|
23349
|
-
if (entry.type !== "content" || !
|
|
23403
|
+
if (entry.type !== "content" || !isRecord8(entry.content))
|
|
23350
23404
|
return [];
|
|
23351
23405
|
return entry.content.type === "text" && typeof entry.content.text === "string" ? [entry.content.text] : [];
|
|
23352
23406
|
}).join("\n");
|
|
@@ -23357,10 +23411,10 @@ function acpContentImages(content, remainingBytes) {
|
|
|
23357
23411
|
const images = [];
|
|
23358
23412
|
let remaining = remainingBytes;
|
|
23359
23413
|
for (const entry of content) {
|
|
23360
|
-
if (!
|
|
23414
|
+
if (!isRecord8(entry))
|
|
23361
23415
|
continue;
|
|
23362
23416
|
const image = entry.type === "image" ? entry : entry.type === "content" ? entry.content : null;
|
|
23363
|
-
if (!
|
|
23417
|
+
if (!isRecord8(image) || image.type !== "image")
|
|
23364
23418
|
continue;
|
|
23365
23419
|
const mimeType = stringField2(image, "mimeType") ?? stringField2(image, "mime_type");
|
|
23366
23420
|
const data = stringField2(image, "data");
|
|
@@ -23383,14 +23437,14 @@ function bashOutput(rawOutput) {
|
|
|
23383
23437
|
function rawOutputProjection(rawOutput) {
|
|
23384
23438
|
if (typeof rawOutput === "string")
|
|
23385
23439
|
return rawOutput.length > 0 ? { text: rawOutput } : {};
|
|
23386
|
-
if (!
|
|
23440
|
+
if (!isRecord8(rawOutput))
|
|
23387
23441
|
return {};
|
|
23388
23442
|
if (rawOutput.type === "Bash" || rawOutput.variant === "Bash" || numberField(rawOutput, "exit_code") !== void 0 || numberField(rawOutput, "exitCode") !== void 0) {
|
|
23389
23443
|
const bash = bashOutput(rawOutput);
|
|
23390
23444
|
if (bash.text !== void 0 || bash.exitCode !== void 0)
|
|
23391
23445
|
return bash;
|
|
23392
23446
|
}
|
|
23393
|
-
const text = firstReadableText(rawOutput.content, rawOutput.text, rawOutput.tool_result, rawOutput.raw_output,
|
|
23447
|
+
const text = firstReadableText(rawOutput.content, rawOutput.text, rawOutput.tool_result, rawOutput.raw_output, isRecord8(rawOutput.FileContent) ? rawOutput.FileContent : void 0, isRecord8(rawOutput.Content) ? rawOutput.Content : void 0);
|
|
23394
23448
|
if (text)
|
|
23395
23449
|
return { text };
|
|
23396
23450
|
if (typeof rawOutput.match_count === "number" && Number.isFinite(rawOutput.match_count)) {
|
|
@@ -23454,11 +23508,11 @@ var WAIT_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
|
23454
23508
|
var KILL_TOOL_NAMES = /* @__PURE__ */ new Set(["kill_command_or_subagent", "kill_task"]);
|
|
23455
23509
|
var DESCRIPTION_LIMIT = 500;
|
|
23456
23510
|
var SUMMARY_LIMIT = 2e3;
|
|
23457
|
-
function
|
|
23511
|
+
function isRecord9(value) {
|
|
23458
23512
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23459
23513
|
}
|
|
23460
23514
|
function idField(value, key) {
|
|
23461
|
-
if (!
|
|
23515
|
+
if (!isRecord9(value))
|
|
23462
23516
|
return void 0;
|
|
23463
23517
|
const field2 = value[key];
|
|
23464
23518
|
if (typeof field2 === "string") {
|
|
@@ -23470,7 +23524,7 @@ function idField(value, key) {
|
|
|
23470
23524
|
return void 0;
|
|
23471
23525
|
}
|
|
23472
23526
|
function stringField3(value, key) {
|
|
23473
|
-
if (!
|
|
23527
|
+
if (!isRecord9(value) || typeof value[key] !== "string")
|
|
23474
23528
|
return void 0;
|
|
23475
23529
|
const trimmed = value[key].trim();
|
|
23476
23530
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
@@ -23493,7 +23547,7 @@ function collectIds(value) {
|
|
|
23493
23547
|
};
|
|
23494
23548
|
push(idField(value, "task_id"));
|
|
23495
23549
|
push(idField(value, "subagent_id"));
|
|
23496
|
-
if (
|
|
23550
|
+
if (isRecord9(value)) {
|
|
23497
23551
|
const list = value.task_ids ?? value.subagent_ids;
|
|
23498
23552
|
if (Array.isArray(list)) {
|
|
23499
23553
|
for (const entry of list)
|
|
@@ -23512,7 +23566,7 @@ function grokSubagentOperation(name, title, rawInput) {
|
|
|
23512
23566
|
return "send";
|
|
23513
23567
|
if (SPAWN_TOOL_NAMES.has(id))
|
|
23514
23568
|
return "spawn";
|
|
23515
|
-
if (
|
|
23569
|
+
if (isRecord9(rawInput) && rawInput.variant === "Task")
|
|
23516
23570
|
return "spawn";
|
|
23517
23571
|
return null;
|
|
23518
23572
|
}
|
|
@@ -23535,7 +23589,7 @@ function grokSubagentRole(rawInput) {
|
|
|
23535
23589
|
return bounded(stringField3(rawInput, "subagent_type") ?? stringField3(rawInput, "agent_type") ?? stringField3(rawInput, "type"), DESCRIPTION_LIMIT);
|
|
23536
23590
|
}
|
|
23537
23591
|
function grokSubagentBackground(rawInput) {
|
|
23538
|
-
if (!
|
|
23592
|
+
if (!isRecord9(rawInput))
|
|
23539
23593
|
return true;
|
|
23540
23594
|
if (rawInput.background === false || rawInput.run_in_background === false)
|
|
23541
23595
|
return false;
|
|
@@ -23573,7 +23627,7 @@ function grokSubagentResultSummary(...candidates) {
|
|
|
23573
23627
|
return void 0;
|
|
23574
23628
|
}
|
|
23575
23629
|
function grokSubagentEventFromUpdate(update) {
|
|
23576
|
-
if (!
|
|
23630
|
+
if (!isRecord9(update) || typeof update.sessionUpdate !== "string")
|
|
23577
23631
|
return null;
|
|
23578
23632
|
const nativeSubagentId = idField(update, "subagent_id") ?? idField(update, "child_session_id");
|
|
23579
23633
|
if (!nativeSubagentId)
|
|
@@ -23642,14 +23696,14 @@ function grokSubagentWaitSettlements(input) {
|
|
|
23642
23696
|
return ids.map((id) => ({ id, status: overall }));
|
|
23643
23697
|
}
|
|
23644
23698
|
function taskOutputResults(rawOutput) {
|
|
23645
|
-
if (!
|
|
23699
|
+
if (!isRecord9(rawOutput))
|
|
23646
23700
|
return [];
|
|
23647
23701
|
if (Array.isArray(rawOutput.results)) {
|
|
23648
|
-
return rawOutput.results.filter(
|
|
23702
|
+
return rawOutput.results.filter(isRecord9);
|
|
23649
23703
|
}
|
|
23650
23704
|
const nested = firstRecord(rawOutput.MultiResult, rawOutput.multiResult, rawOutput.multi_result);
|
|
23651
23705
|
if (nested && Array.isArray(nested.results)) {
|
|
23652
|
-
return nested.results.filter(
|
|
23706
|
+
return nested.results.filter(isRecord9);
|
|
23653
23707
|
}
|
|
23654
23708
|
const single = firstRecord(rawOutput.Result, rawOutput.result);
|
|
23655
23709
|
if (single)
|
|
@@ -23660,7 +23714,7 @@ function taskOutputResults(rawOutput) {
|
|
|
23660
23714
|
}
|
|
23661
23715
|
function firstRecord(...values) {
|
|
23662
23716
|
for (const value of values) {
|
|
23663
|
-
if (
|
|
23717
|
+
if (isRecord9(value))
|
|
23664
23718
|
return value;
|
|
23665
23719
|
}
|
|
23666
23720
|
return void 0;
|
|
@@ -23683,7 +23737,7 @@ function taskOutputTextSettlements(rawOutput, content, ids) {
|
|
|
23683
23737
|
return settled;
|
|
23684
23738
|
}
|
|
23685
23739
|
function taskOutputStatus(rawOutput, content) {
|
|
23686
|
-
if (
|
|
23740
|
+
if (isRecord9(rawOutput) && typeof rawOutput.status === "string")
|
|
23687
23741
|
return rawOutput.status;
|
|
23688
23742
|
const text = extractText(content) ?? extractText(rawOutput);
|
|
23689
23743
|
if (!text)
|
|
@@ -23742,7 +23796,7 @@ function extractText(value, depth = 0) {
|
|
|
23742
23796
|
const joined = parts.join("\n").trim();
|
|
23743
23797
|
return joined.length > 0 ? joined : void 0;
|
|
23744
23798
|
}
|
|
23745
|
-
if (!
|
|
23799
|
+
if (!isRecord9(value))
|
|
23746
23800
|
return void 0;
|
|
23747
23801
|
if (typeof value.text === "string" && value.text.trim().length > 0)
|
|
23748
23802
|
return value.text.trim();
|
|
@@ -23758,18 +23812,14 @@ function extractText(value, depth = 0) {
|
|
|
23758
23812
|
function stableId(kind, turn, index) {
|
|
23759
23813
|
return hostItemIdSchema.parse(`grok-history-${kind}-${turn}-${index}`);
|
|
23760
23814
|
}
|
|
23761
|
-
function terminalOutcome(stopReason) {
|
|
23815
|
+
function terminalOutcome(stopReason, source) {
|
|
23762
23816
|
if (stopReason === "end_turn")
|
|
23763
23817
|
return { status: "succeeded" };
|
|
23764
23818
|
if (stopReason === "cancelled")
|
|
23765
23819
|
return { status: "cancelled", reason: "Cancelled by user" };
|
|
23766
23820
|
return {
|
|
23767
23821
|
status: "failed",
|
|
23768
|
-
error:
|
|
23769
|
-
code: "nativeFailure",
|
|
23770
|
-
message: `Grok stopped the Turn: ${stopReason}`,
|
|
23771
|
-
retryable: stopReason === "max_tokens" || stopReason === "max_turn_requests"
|
|
23772
|
-
}
|
|
23822
|
+
error: grokTurnStopError(stopReason, source)
|
|
23773
23823
|
};
|
|
23774
23824
|
}
|
|
23775
23825
|
function userEventIdentity(event) {
|
|
@@ -24106,7 +24156,7 @@ function mapGrokReplay(replay, harnessId, sessionId, cwd, knownTurnRefs = [], to
|
|
|
24106
24156
|
if (input.length === 0)
|
|
24107
24157
|
continue;
|
|
24108
24158
|
if (event.type === "turn.completed") {
|
|
24109
|
-
completeTurn(terminalOutcome(event.stopReason), event.nativeTurnKey, grokEventTimestamp(event));
|
|
24159
|
+
completeTurn(terminalOutcome(event.stopReason, event.metadata), event.nativeTurnKey, grokEventTimestamp(event));
|
|
24110
24160
|
} else if (event.type === "compaction.started") {
|
|
24111
24161
|
completeReasoning();
|
|
24112
24162
|
completeAgent();
|
|
@@ -24299,11 +24349,11 @@ var GROK_SESSION_DELETE_METHOD = "_x.ai/session/delete";
|
|
|
24299
24349
|
function error51(code, message, retryable = false) {
|
|
24300
24350
|
return { code, message, retryable };
|
|
24301
24351
|
}
|
|
24302
|
-
function
|
|
24352
|
+
function isRecord10(value) {
|
|
24303
24353
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24304
24354
|
}
|
|
24305
24355
|
function isGrokMethodNotFound(error53) {
|
|
24306
|
-
if (
|
|
24356
|
+
if (isRecord10(error53) && error53.code === -32601)
|
|
24307
24357
|
return true;
|
|
24308
24358
|
const message = error53 instanceof Error ? error53.message : String(error53);
|
|
24309
24359
|
return /method not found/iu.test(message);
|
|
@@ -24321,10 +24371,10 @@ function buildGrokForkParams(input) {
|
|
|
24321
24371
|
};
|
|
24322
24372
|
}
|
|
24323
24373
|
function parseGrokForkResponse(value) {
|
|
24324
|
-
if (!
|
|
24374
|
+
if (!isRecord10(value) || value.error !== void 0)
|
|
24325
24375
|
return null;
|
|
24326
|
-
const payload = typeof value.newSessionId !== "string" &&
|
|
24327
|
-
if (!
|
|
24376
|
+
const payload = typeof value.newSessionId !== "string" && isRecord10(value.result) ? value.result : value;
|
|
24377
|
+
if (!isRecord10(payload) || payload.error !== void 0)
|
|
24328
24378
|
return null;
|
|
24329
24379
|
if (typeof payload.newSessionId !== "string" || payload.newSessionId.length === 0)
|
|
24330
24380
|
return null;
|
|
@@ -24488,7 +24538,7 @@ var GROK_SESSION_UPDATE_EXTENSION_METHODS = [
|
|
|
24488
24538
|
"x.ai/session_notification",
|
|
24489
24539
|
"_x.ai/session_notification"
|
|
24490
24540
|
];
|
|
24491
|
-
function
|
|
24541
|
+
function isRecord11(value) {
|
|
24492
24542
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24493
24543
|
}
|
|
24494
24544
|
function optionalNonNegativeInt(value) {
|
|
@@ -24509,7 +24559,7 @@ function isGrokExtensionSessionUpdateMethod(method) {
|
|
|
24509
24559
|
return GROK_SESSION_UPDATE_EXTENSION_METHODS.includes(method);
|
|
24510
24560
|
}
|
|
24511
24561
|
function grokCompactionEventFromUpdate(update) {
|
|
24512
|
-
if (!
|
|
24562
|
+
if (!isRecord11(update) || typeof update.sessionUpdate !== "string")
|
|
24513
24563
|
return null;
|
|
24514
24564
|
const tokensUsed = optionalNonNegativeInt(firstPresent(update, ["tokensUsed", "tokens_used"]));
|
|
24515
24565
|
const contextWindowTokens = optionalNonNegativeInt(firstPresent(update, ["contextWindowTokens", "contextWindow", "context_window"]));
|
|
@@ -24571,7 +24621,7 @@ var BACKGROUND_SESSION_UPDATES = /* @__PURE__ */ new Set([
|
|
|
24571
24621
|
"scheduled_task_fired",
|
|
24572
24622
|
"scheduled_task_deleted"
|
|
24573
24623
|
]);
|
|
24574
|
-
function
|
|
24624
|
+
function isRecord12(value) {
|
|
24575
24625
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24576
24626
|
}
|
|
24577
24627
|
function firstPresent2(record3, keys) {
|
|
@@ -24600,10 +24650,10 @@ function booleanField(record3, keys) {
|
|
|
24600
24650
|
return typeof value === "boolean" ? value : void 0;
|
|
24601
24651
|
}
|
|
24602
24652
|
function snapshotRecord(value) {
|
|
24603
|
-
if (!
|
|
24653
|
+
if (!isRecord12(value))
|
|
24604
24654
|
return void 0;
|
|
24605
24655
|
const nested = value.task_snapshot ?? value.taskSnapshot;
|
|
24606
|
-
return
|
|
24656
|
+
return isRecord12(nested) ? nested : value;
|
|
24607
24657
|
}
|
|
24608
24658
|
function backgroundKind(value, monitorDescription) {
|
|
24609
24659
|
if (monitorDescription)
|
|
@@ -24619,7 +24669,7 @@ function fields(value) {
|
|
|
24619
24669
|
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0));
|
|
24620
24670
|
}
|
|
24621
24671
|
function grokBackgroundEventFromUpdate(update) {
|
|
24622
|
-
if (!
|
|
24672
|
+
if (!isRecord12(update) || typeof update.sessionUpdate !== "string" || !BACKGROUND_SESSION_UPDATES.has(update.sessionUpdate))
|
|
24623
24673
|
return null;
|
|
24624
24674
|
const taskId = stringField4(update, ["task_id", "taskId"]);
|
|
24625
24675
|
if (update.sessionUpdate === "task_backgrounded") {
|
|
@@ -24703,22 +24753,22 @@ function grokBackgroundEventFromUpdate(update) {
|
|
|
24703
24753
|
return null;
|
|
24704
24754
|
}
|
|
24705
24755
|
function grokToolIsBackgrounded(rawOutput, rawInput) {
|
|
24706
|
-
const exitCode =
|
|
24756
|
+
const exitCode = isRecord12(rawOutput) ? numberField2(rawOutput, ["exit_code", "exitCode"]) : void 0;
|
|
24707
24757
|
if (exitCode !== void 0 && exitCode !== null)
|
|
24708
24758
|
return false;
|
|
24709
|
-
if (
|
|
24759
|
+
if (isRecord12(rawOutput) && optionalString(rawOutput, ["signal"]) === "backgrounded")
|
|
24710
24760
|
return true;
|
|
24711
24761
|
if (grokBackgroundTaskId(rawOutput, rawInput))
|
|
24712
24762
|
return true;
|
|
24713
|
-
return Boolean(
|
|
24763
|
+
return Boolean(isRecord12(rawInput) && (rawInput.background === true || rawInput.is_background === true));
|
|
24714
24764
|
}
|
|
24715
24765
|
function grokBackgroundTaskId(rawOutput, rawInput) {
|
|
24716
|
-
if (
|
|
24766
|
+
if (isRecord12(rawOutput)) {
|
|
24717
24767
|
const id = stringField4(rawOutput, ["task_id", "taskId"]);
|
|
24718
24768
|
if (id)
|
|
24719
24769
|
return id;
|
|
24720
24770
|
}
|
|
24721
|
-
if (
|
|
24771
|
+
if (isRecord12(rawInput))
|
|
24722
24772
|
return stringField4(rawInput, ["task_id", "taskId"]);
|
|
24723
24773
|
return void 0;
|
|
24724
24774
|
}
|
|
@@ -24766,7 +24816,7 @@ function collectGrokScheduledLoops(events) {
|
|
|
24766
24816
|
// dist/grok-manual-compaction.js
|
|
24767
24817
|
var GROK_COMPACT_CONVERSATION_METHOD = "x.ai/compact_conversation";
|
|
24768
24818
|
var GROK_COMPACT_CONVERSATION_FALLBACK_METHOD = "_x.ai/compact_conversation";
|
|
24769
|
-
function
|
|
24819
|
+
function isRecord13(value) {
|
|
24770
24820
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24771
24821
|
}
|
|
24772
24822
|
function optionalNonNegativeInt2(value) {
|
|
@@ -24778,7 +24828,7 @@ function optionalErrorMessage2(value) {
|
|
|
24778
24828
|
function parseGrokCompactResult(value, cancelled = false) {
|
|
24779
24829
|
if (cancelled)
|
|
24780
24830
|
return { outcome: "cancelled" };
|
|
24781
|
-
if (!
|
|
24831
|
+
if (!isRecord13(value))
|
|
24782
24832
|
return { outcome: "succeeded" };
|
|
24783
24833
|
const tokensBefore = optionalNonNegativeInt2(value.tokensBefore ?? value.tokens_before);
|
|
24784
24834
|
const tokensAfter = optionalNonNegativeInt2(value.tokensAfter ?? value.tokens_after);
|
|
@@ -24816,7 +24866,7 @@ var GROK_REWIND_EXECUTE_METHOD = "_x.ai/rewind/execute";
|
|
|
24816
24866
|
function error52(code, message, retryable = false) {
|
|
24817
24867
|
return { code, message, retryable };
|
|
24818
24868
|
}
|
|
24819
|
-
function
|
|
24869
|
+
function isRecord14(value) {
|
|
24820
24870
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24821
24871
|
}
|
|
24822
24872
|
function buildGrokRewindParams(input) {
|
|
@@ -24828,10 +24878,10 @@ function buildGrokRewindParams(input) {
|
|
|
24828
24878
|
};
|
|
24829
24879
|
}
|
|
24830
24880
|
function parseGrokRewindResponse(value) {
|
|
24831
|
-
if (!
|
|
24881
|
+
if (!isRecord14(value))
|
|
24832
24882
|
return null;
|
|
24833
|
-
const payload = typeof value.success !== "boolean" &&
|
|
24834
|
-
if (!
|
|
24883
|
+
const payload = typeof value.success !== "boolean" && isRecord14(value.result) ? value.result : value;
|
|
24884
|
+
if (!isRecord14(payload) || typeof payload.success !== "boolean")
|
|
24835
24885
|
return null;
|
|
24836
24886
|
return rewindPayload(payload);
|
|
24837
24887
|
}
|
|
@@ -24997,7 +25047,7 @@ var GROK_CLOCK_ELICIT_PERSIST_FIXTURE = {
|
|
|
24997
25047
|
...GROK_CLOCK_ELICIT_FIXTURE,
|
|
24998
25048
|
persist: ["session", "always"]
|
|
24999
25049
|
};
|
|
25000
|
-
function
|
|
25050
|
+
function isRecord15(value) {
|
|
25001
25051
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25002
25052
|
}
|
|
25003
25053
|
function nonEmptyString(value) {
|
|
@@ -25038,11 +25088,11 @@ function parsePersistOffer(value) {
|
|
|
25038
25088
|
return out.length > 0 ? out : "invalid";
|
|
25039
25089
|
}
|
|
25040
25090
|
function schemaIsSupportedEmptyObject(schema) {
|
|
25041
|
-
if (!
|
|
25091
|
+
if (!isRecord15(schema) || !hasOnlyKeys(schema, SCHEMA_KEYS) || schema.type !== "object") {
|
|
25042
25092
|
return false;
|
|
25043
25093
|
}
|
|
25044
25094
|
if (schema.properties !== void 0) {
|
|
25045
|
-
if (!
|
|
25095
|
+
if (!isRecord15(schema.properties) || Object.keys(schema.properties).length !== 0)
|
|
25046
25096
|
return false;
|
|
25047
25097
|
}
|
|
25048
25098
|
if (schema.required !== void 0) {
|
|
@@ -25052,7 +25102,7 @@ function schemaIsSupportedEmptyObject(schema) {
|
|
|
25052
25102
|
return true;
|
|
25053
25103
|
}
|
|
25054
25104
|
function parseGrokMcpElicitParams(params) {
|
|
25055
|
-
if (!
|
|
25105
|
+
if (!isRecord15(params))
|
|
25056
25106
|
return { status: "invalid", message: "elicitation params must be an object" };
|
|
25057
25107
|
const sessionId = nonEmptyString(params.sessionId);
|
|
25058
25108
|
const toolCallId = nonEmptyString(params.toolCallId);
|
|
@@ -25080,7 +25130,7 @@ function parseGrokMcpElicitParams(params) {
|
|
|
25080
25130
|
return { status: "invalid", message: "form elicitation contains unreviewed fields" };
|
|
25081
25131
|
}
|
|
25082
25132
|
if (params.requestedSchema !== void 0) {
|
|
25083
|
-
if (!
|
|
25133
|
+
if (!isRecord15(params.requestedSchema)) {
|
|
25084
25134
|
return { status: "invalid", message: "requestedSchema must be an object" };
|
|
25085
25135
|
}
|
|
25086
25136
|
if (!schemaIsSupportedEmptyObject(params.requestedSchema))
|
|
@@ -25147,7 +25197,7 @@ function projectGrokMcpElicitApproval(input) {
|
|
|
25147
25197
|
};
|
|
25148
25198
|
}
|
|
25149
25199
|
function grokElicitationResolvedToolCallId(update) {
|
|
25150
|
-
if (!
|
|
25200
|
+
if (!isRecord15(update) || update.sessionUpdate !== "interaction_resolved")
|
|
25151
25201
|
return void 0;
|
|
25152
25202
|
return nonEmptyString(update.tool_call_id) ?? nonEmptyString(update.toolCallId);
|
|
25153
25203
|
}
|
|
@@ -25302,19 +25352,19 @@ var GrokPermissionConfirmation = class {
|
|
|
25302
25352
|
// dist/grok-questions.js
|
|
25303
25353
|
var GROK_ASK_USER_QUESTION_METHOD = "_x.ai/ask_user_question";
|
|
25304
25354
|
var GROK_QUESTION_ACTIVITY_METHOD = "_x.ai/ask_user_question_activity";
|
|
25305
|
-
function
|
|
25355
|
+
function isRecord16(value) {
|
|
25306
25356
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25307
25357
|
}
|
|
25308
25358
|
function nonEmptyString2(value) {
|
|
25309
25359
|
return typeof value === "string" && value.trim().length > 0;
|
|
25310
25360
|
}
|
|
25311
25361
|
function parseGrokQuestionRequest(value) {
|
|
25312
|
-
if (!
|
|
25362
|
+
if (!isRecord16(value) || !nonEmptyString2(value.sessionId) || !nonEmptyString2(value.toolCallId) || value.mode !== "default" && value.mode !== "plan" || !Array.isArray(value.questions) || value.questions.length === 0) {
|
|
25313
25363
|
throw new Error("Grok question requires sessionId, toolCallId, mode and nonempty questions");
|
|
25314
25364
|
}
|
|
25315
25365
|
const seen = /* @__PURE__ */ new Set();
|
|
25316
25366
|
const questions = value.questions.map((question) => {
|
|
25317
|
-
if (!
|
|
25367
|
+
if (!isRecord16(question) || !nonEmptyString2(question.question) || seen.has(question.question) || !Array.isArray(question.options) || question.multiSelect != null && typeof question.multiSelect !== "boolean" || question.multi_select != null && typeof question.multi_select !== "boolean") {
|
|
25318
25368
|
throw new Error("Grok question text must be unique and options/multiSelect must be valid");
|
|
25319
25369
|
}
|
|
25320
25370
|
if (question.multiSelect != null && question.multi_select != null && question.multiSelect !== question.multi_select)
|
|
@@ -25322,7 +25372,7 @@ function parseGrokQuestionRequest(value) {
|
|
|
25322
25372
|
seen.add(question.question);
|
|
25323
25373
|
const labels = /* @__PURE__ */ new Set();
|
|
25324
25374
|
const options = question.options.map((option) => {
|
|
25325
|
-
if (!
|
|
25375
|
+
if (!isRecord16(option) || !nonEmptyString2(option.label) || labels.has(option.label) || typeof option.description !== "string" || option.preview != null && typeof option.preview !== "string") {
|
|
25326
25376
|
throw new Error("Grok question options require unique labels and text descriptions/previews");
|
|
25327
25377
|
}
|
|
25328
25378
|
labels.add(option.label);
|
|
@@ -25483,7 +25533,7 @@ var GrokQuestions = class {
|
|
|
25483
25533
|
var GROK_EXIT_PLAN_MODE_METHODS = ["_x.ai/exit_plan_mode", "x.ai/exit_plan_mode"];
|
|
25484
25534
|
var DECISION_ID = "plan-decision";
|
|
25485
25535
|
var FEEDBACK_ID = "plan-feedback";
|
|
25486
|
-
function
|
|
25536
|
+
function isRecord17(value) {
|
|
25487
25537
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25488
25538
|
}
|
|
25489
25539
|
function nonEmptyString3(value) {
|
|
@@ -25493,7 +25543,7 @@ function isGrokExitPlanModeMethod(method) {
|
|
|
25493
25543
|
return GROK_EXIT_PLAN_MODE_METHODS.includes(method);
|
|
25494
25544
|
}
|
|
25495
25545
|
function parseGrokPlanApprovalRequest(value) {
|
|
25496
|
-
if (!
|
|
25546
|
+
if (!isRecord17(value) || !nonEmptyString3(value.sessionId) || !nonEmptyString3(value.toolCallId)) {
|
|
25497
25547
|
throw new Error("Grok plan approval requires sessionId and toolCallId");
|
|
25498
25548
|
}
|
|
25499
25549
|
const raw = value.planContent ?? value.plan_content;
|
|
@@ -25669,16 +25719,16 @@ var GrokTransportError = class extends Error {
|
|
|
25669
25719
|
this.name = "GrokTransportError";
|
|
25670
25720
|
}
|
|
25671
25721
|
};
|
|
25672
|
-
function
|
|
25722
|
+
function isRecord18(value) {
|
|
25673
25723
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25674
25724
|
}
|
|
25675
25725
|
function acpToolName(update, metadata) {
|
|
25676
|
-
if (!
|
|
25726
|
+
if (!isRecord18(update))
|
|
25677
25727
|
return void 0;
|
|
25678
25728
|
if (typeof update.name === "string" && update.name.length > 0)
|
|
25679
25729
|
return update.name;
|
|
25680
|
-
const meta3 =
|
|
25681
|
-
const tool = meta3 &&
|
|
25730
|
+
const meta3 = isRecord18(update._meta) ? update._meta : metadata;
|
|
25731
|
+
const tool = meta3 && isRecord18(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
25682
25732
|
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
25683
25733
|
}
|
|
25684
25734
|
function errorText(error53) {
|
|
@@ -25734,20 +25784,20 @@ function signalProcessTree(child, signal) {
|
|
|
25734
25784
|
try {
|
|
25735
25785
|
process.kill(-child.pid, signal);
|
|
25736
25786
|
} catch (error53) {
|
|
25737
|
-
if (!
|
|
25787
|
+
if (!isRecord18(error53) || error53.code === "ESRCH")
|
|
25738
25788
|
return;
|
|
25739
25789
|
try {
|
|
25740
25790
|
child.kill(signal);
|
|
25741
25791
|
} catch (fallback) {
|
|
25742
|
-
if (!
|
|
25792
|
+
if (!isRecord18(fallback) || fallback.code !== "ESRCH")
|
|
25743
25793
|
throw fallback;
|
|
25744
25794
|
}
|
|
25745
25795
|
}
|
|
25746
25796
|
}
|
|
25747
25797
|
function grokNotificationMetadata(envelope, update) {
|
|
25748
|
-
if (!
|
|
25798
|
+
if (!isRecord18(envelope) && !isRecord18(update))
|
|
25749
25799
|
return void 0;
|
|
25750
|
-
return { ...
|
|
25800
|
+
return { ...isRecord18(update) ? update : {}, ...isRecord18(envelope) ? envelope : {} };
|
|
25751
25801
|
}
|
|
25752
25802
|
function transportEvent(update, metadata) {
|
|
25753
25803
|
const extension = update;
|
|
@@ -25876,7 +25926,7 @@ async function readNativeSignals(options, sessionId) {
|
|
|
25876
25926
|
}
|
|
25877
25927
|
}
|
|
25878
25928
|
function isMissingFile(error53) {
|
|
25879
|
-
return
|
|
25929
|
+
return isRecord18(error53) && error53.code === "ENOENT";
|
|
25880
25930
|
}
|
|
25881
25931
|
async function locateGrokNativeSession(options, sessionId) {
|
|
25882
25932
|
if (sessionId.length === 0)
|
|
@@ -25899,7 +25949,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
25899
25949
|
try {
|
|
25900
25950
|
summaryRaw = await readFile5(path17.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
25901
25951
|
} catch (error53) {
|
|
25902
|
-
if (isMissingFile(error53) ||
|
|
25952
|
+
if (isMissingFile(error53) || isRecord18(error53) && error53.code === "ENOTDIR")
|
|
25903
25953
|
continue;
|
|
25904
25954
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
25905
25955
|
cause: error53
|
|
@@ -25911,10 +25961,10 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
25911
25961
|
} catch {
|
|
25912
25962
|
continue;
|
|
25913
25963
|
}
|
|
25914
|
-
if (!
|
|
25964
|
+
if (!isRecord18(parsed))
|
|
25915
25965
|
continue;
|
|
25916
25966
|
const info = parsed.info;
|
|
25917
|
-
const cwd =
|
|
25967
|
+
const cwd = isRecord18(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path17.resolve(info.cwd) : path17.resolve(decodeURIComponent(entry.name));
|
|
25918
25968
|
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path17.resolve(parsed.source_workspace_dir) : void 0;
|
|
25919
25969
|
matches.push({
|
|
25920
25970
|
cwd,
|
|
@@ -25947,10 +25997,10 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
25947
25997
|
} catch {
|
|
25948
25998
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
25949
25999
|
}
|
|
25950
|
-
if (!
|
|
26000
|
+
if (!isRecord18(record3) || !isRecord18(record3.params))
|
|
25951
26001
|
continue;
|
|
25952
26002
|
const params = record3.params;
|
|
25953
|
-
if (params.sessionId !== sessionId || !
|
|
26003
|
+
if (params.sessionId !== sessionId || !isRecord18(params.update))
|
|
25954
26004
|
continue;
|
|
25955
26005
|
let metadata = grokNotificationMetadata(params._meta, params.update._meta);
|
|
25956
26006
|
if (typeof record3.timestamp === "number" && Number.isFinite(record3.timestamp))
|
|
@@ -26020,7 +26070,7 @@ var GrokAcpTransport = class {
|
|
|
26020
26070
|
if (!this.#connection)
|
|
26021
26071
|
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
26022
26072
|
const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
|
|
26023
|
-
return
|
|
26073
|
+
return isRecord18(result) ? result.usage : void 0;
|
|
26024
26074
|
}
|
|
26025
26075
|
async readHistory(sessionId, cwd = this.#options.cwd) {
|
|
26026
26076
|
return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
|
|
@@ -26125,7 +26175,7 @@ var GrokAcpTransport = class {
|
|
|
26125
26175
|
sessionId: this.#sessionId,
|
|
26126
26176
|
toolCallId
|
|
26127
26177
|
}), 3e3, "Grok question activity");
|
|
26128
|
-
if (!
|
|
26178
|
+
if (!isRecord18(raw) || !("timeout" in raw))
|
|
26129
26179
|
throw new GrokTransportError("protocolError", "Invalid Grok activity acknowledgement");
|
|
26130
26180
|
return raw.timeout === null ? null : questionAutoResolutionSchema.parse(raw.timeout);
|
|
26131
26181
|
} catch (error53) {
|
|
@@ -26397,7 +26447,7 @@ var GrokAcpTransport = class {
|
|
|
26397
26447
|
}
|
|
26398
26448
|
} : {}
|
|
26399
26449
|
});
|
|
26400
|
-
if (!
|
|
26450
|
+
if (!isRecord18(response) || !isRecord18(response._meta) || !isRecord18(response._meta.model)) {
|
|
26401
26451
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
26402
26452
|
}
|
|
26403
26453
|
const selected = response._meta.model.Ok;
|
|
@@ -26437,7 +26487,7 @@ var GrokAcpTransport = class {
|
|
|
26437
26487
|
permission_mode: mode
|
|
26438
26488
|
});
|
|
26439
26489
|
const response = await connection.request("_x.ai/session/info", { sessionId });
|
|
26440
|
-
if (!
|
|
26490
|
+
if (!isRecord18(response) || !isRecord18(response.result) || response.result.sessionId !== sessionId) {
|
|
26441
26491
|
throw new Error("Grok did not confirm the target Session");
|
|
26442
26492
|
}
|
|
26443
26493
|
})()
|
|
@@ -26523,7 +26573,7 @@ var GrokAcpTransport = class {
|
|
|
26523
26573
|
if (!isGrokExtensionSessionUpdateMethod(method) && !isGrokBackgroundNotificationMethod(method)) {
|
|
26524
26574
|
return;
|
|
26525
26575
|
}
|
|
26526
|
-
if (typeof params.sessionId !== "string" || !
|
|
26576
|
+
if (typeof params.sessionId !== "string" || !isRecord18(params.update))
|
|
26527
26577
|
return;
|
|
26528
26578
|
this.#handleUpdate(params);
|
|
26529
26579
|
}
|
|
@@ -26533,7 +26583,7 @@ var GrokAcpTransport = class {
|
|
|
26533
26583
|
taskId,
|
|
26534
26584
|
source
|
|
26535
26585
|
});
|
|
26536
|
-
if (!
|
|
26586
|
+
if (!isRecord18(result) || result.taskId !== taskId || !["killed", "already_exited", "not_found"].includes(String(result.outcome)))
|
|
26537
26587
|
throw new GrokTransportError("protocolError", "Malformed Grok task kill response");
|
|
26538
26588
|
return result.outcome;
|
|
26539
26589
|
}
|
|
@@ -26548,7 +26598,7 @@ var GrokAcpTransport = class {
|
|
|
26548
26598
|
sessionId: this.sessionId,
|
|
26549
26599
|
taskId
|
|
26550
26600
|
});
|
|
26551
|
-
if (!
|
|
26601
|
+
if (!isRecord18(result) || result.taskId !== taskId || typeof result.deleted !== "boolean")
|
|
26552
26602
|
throw new GrokTransportError("protocolError", "Malformed Grok scheduler delete response");
|
|
26553
26603
|
return result.deleted;
|
|
26554
26604
|
}
|
|
@@ -26560,21 +26610,21 @@ var GrokAcpTransport = class {
|
|
|
26560
26610
|
try {
|
|
26561
26611
|
raw = await withTimeout(this.#connection.request(method, params), this.#options.commandTimeoutMs, `Grok ${method}`);
|
|
26562
26612
|
} catch (error53) {
|
|
26563
|
-
if (!
|
|
26613
|
+
if (!isRecord18(error53) || error53.code !== -32601)
|
|
26564
26614
|
throw error53;
|
|
26565
26615
|
try {
|
|
26566
26616
|
raw = await withTimeout(this.#connection.request(`_${method}`, params), this.#options.commandTimeoutMs, `Grok _${method}`);
|
|
26567
26617
|
} catch (fallback) {
|
|
26568
|
-
if (
|
|
26618
|
+
if (isRecord18(fallback) && fallback.code === -32601)
|
|
26569
26619
|
throw new GrokTransportError("unsupported", `Grok does not support ${method}`);
|
|
26570
26620
|
throw fallback;
|
|
26571
26621
|
}
|
|
26572
26622
|
}
|
|
26573
|
-
if (
|
|
26574
|
-
const message = typeof raw.error === "string" ? raw.error :
|
|
26623
|
+
if (isRecord18(raw) && raw.error !== void 0 && raw.error !== null) {
|
|
26624
|
+
const message = typeof raw.error === "string" ? raw.error : isRecord18(raw.error) && typeof raw.error.message === "string" ? raw.error.message : `Grok ${method} failed`;
|
|
26575
26625
|
throw new GrokTransportError("unavailable", message);
|
|
26576
26626
|
}
|
|
26577
|
-
return
|
|
26627
|
+
return isRecord18(raw) && "result" in raw ? raw.result : raw;
|
|
26578
26628
|
}
|
|
26579
26629
|
#handlePermission(params) {
|
|
26580
26630
|
const observer = this.#activePrompt ?? this.#background;
|
|
@@ -26759,7 +26809,7 @@ var SessionImportScope = class {
|
|
|
26759
26809
|
// dist/session-import.js
|
|
26760
26810
|
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
26761
26811
|
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
26762
|
-
function
|
|
26812
|
+
function isRecord19(value) {
|
|
26763
26813
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26764
26814
|
}
|
|
26765
26815
|
async function readJson(file2, signal) {
|
|
@@ -26772,7 +26822,7 @@ function processAlive(pid) {
|
|
|
26772
26822
|
process.kill(pid, 0);
|
|
26773
26823
|
return true;
|
|
26774
26824
|
} catch (error53) {
|
|
26775
|
-
return
|
|
26825
|
+
return isRecord19(error53) && error53.code === "EPERM";
|
|
26776
26826
|
}
|
|
26777
26827
|
}
|
|
26778
26828
|
async function firstUserText(file2, signal) {
|
|
@@ -26789,10 +26839,10 @@ async function firstUserText(file2, signal) {
|
|
|
26789
26839
|
} catch {
|
|
26790
26840
|
continue;
|
|
26791
26841
|
}
|
|
26792
|
-
const update =
|
|
26793
|
-
if (!
|
|
26842
|
+
const update = isRecord19(entry) && isRecord19(entry.params) ? entry.params.update : null;
|
|
26843
|
+
if (!isRecord19(update) || update.sessionUpdate !== "user_message_chunk")
|
|
26794
26844
|
continue;
|
|
26795
|
-
const text =
|
|
26845
|
+
const text = isRecord19(update.content) ? update.content.text : null;
|
|
26796
26846
|
return typeof text === "string" ? text : "";
|
|
26797
26847
|
}
|
|
26798
26848
|
return null;
|
|
@@ -26869,7 +26919,7 @@ var GrokSessionImport = class {
|
|
|
26869
26919
|
if (!Array.isArray(entries))
|
|
26870
26920
|
return active;
|
|
26871
26921
|
for (const entry of entries) {
|
|
26872
|
-
if (
|
|
26922
|
+
if (isRecord19(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
26873
26923
|
active.add(entry.session_id);
|
|
26874
26924
|
}
|
|
26875
26925
|
return active;
|
|
@@ -26918,7 +26968,7 @@ var GrokSessionImport = class {
|
|
|
26918
26968
|
return null;
|
|
26919
26969
|
try {
|
|
26920
26970
|
const summary = await readJson(files[0], signal);
|
|
26921
|
-
if (!
|
|
26971
|
+
if (!isRecord19(summary) || !isRecord19(summary.info) || summary.info.id !== nativeSessionId)
|
|
26922
26972
|
return null;
|
|
26923
26973
|
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
26924
26974
|
return null;
|
|
@@ -27640,17 +27690,17 @@ var GrokBackgroundItems = class {
|
|
|
27640
27690
|
await handle.close();
|
|
27641
27691
|
}
|
|
27642
27692
|
} catch (error53) {
|
|
27643
|
-
if (
|
|
27693
|
+
if (isRecord20(error53) && error53.code === "ENOENT")
|
|
27644
27694
|
return;
|
|
27645
27695
|
}
|
|
27646
27696
|
}
|
|
27647
27697
|
};
|
|
27648
|
-
function
|
|
27698
|
+
function isRecord20(value) {
|
|
27649
27699
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27650
27700
|
}
|
|
27651
27701
|
|
|
27652
27702
|
// dist/grok-models.js
|
|
27653
|
-
function
|
|
27703
|
+
function isRecord21(value) {
|
|
27654
27704
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27655
27705
|
}
|
|
27656
27706
|
function nonBlank(value) {
|
|
@@ -27662,7 +27712,7 @@ function thinkingOptions(value) {
|
|
|
27662
27712
|
const seen = /* @__PURE__ */ new Set();
|
|
27663
27713
|
const options = [];
|
|
27664
27714
|
for (const candidate of value) {
|
|
27665
|
-
if (!
|
|
27715
|
+
if (!isRecord21(candidate) || !nonBlank(candidate.label))
|
|
27666
27716
|
continue;
|
|
27667
27717
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
27668
27718
|
if (!id.success || seen.has(id.data))
|
|
@@ -27673,7 +27723,7 @@ function thinkingOptions(value) {
|
|
|
27673
27723
|
return options;
|
|
27674
27724
|
}
|
|
27675
27725
|
function parseGrokModelState(value) {
|
|
27676
|
-
if (!
|
|
27726
|
+
if (!isRecord21(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
27677
27727
|
return null;
|
|
27678
27728
|
}
|
|
27679
27729
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -27685,12 +27735,12 @@ function parseGrokModelState(value) {
|
|
|
27685
27735
|
const models = [];
|
|
27686
27736
|
let currentThinkingOptionId;
|
|
27687
27737
|
for (const candidate of value.availableModels) {
|
|
27688
|
-
if (!
|
|
27738
|
+
if (!isRecord21(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
27689
27739
|
continue;
|
|
27690
27740
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
27691
27741
|
if (!ref.success)
|
|
27692
27742
|
continue;
|
|
27693
|
-
const metadata =
|
|
27743
|
+
const metadata = isRecord21(candidate._meta) ? candidate._meta : {};
|
|
27694
27744
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
27695
27745
|
if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
|
|
27696
27746
|
defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
|
|
@@ -27729,10 +27779,10 @@ function parseGrokModelState(value) {
|
|
|
27729
27779
|
};
|
|
27730
27780
|
}
|
|
27731
27781
|
function modelStateFromInitialize(response) {
|
|
27732
|
-
return parseGrokModelState(
|
|
27782
|
+
return parseGrokModelState(isRecord21(response._meta) ? response._meta.modelState : void 0);
|
|
27733
27783
|
}
|
|
27734
27784
|
function modelStateFromSessionResponse(response) {
|
|
27735
|
-
return parseGrokModelState(
|
|
27785
|
+
return parseGrokModelState(isRecord21(response) ? response.models : void 0);
|
|
27736
27786
|
}
|
|
27737
27787
|
function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
27738
27788
|
const selectedModel = model2;
|
|
@@ -27759,12 +27809,12 @@ var GROK_SETTINGS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/settings";
|
|
|
27759
27809
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
27760
27810
|
var PLAN_TIMEOUT_MS = 2e3;
|
|
27761
27811
|
function parseGrokPlan(value) {
|
|
27762
|
-
if (!
|
|
27812
|
+
if (!isRecord22(value) || typeof value.subscription_tier_display !== "string")
|
|
27763
27813
|
return void 0;
|
|
27764
27814
|
const plan = value.subscription_tier_display.trim();
|
|
27765
27815
|
return plan && plan.length <= 128 && !/[\u0000-\u001f\u007f]/u.test(plan) ? plan : void 0;
|
|
27766
27816
|
}
|
|
27767
|
-
function
|
|
27817
|
+
function isRecord22(value) {
|
|
27768
27818
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27769
27819
|
}
|
|
27770
27820
|
function finitePercent(value) {
|
|
@@ -27773,7 +27823,7 @@ function finitePercent(value) {
|
|
|
27773
27823
|
return Math.min(100, Math.max(0, value));
|
|
27774
27824
|
}
|
|
27775
27825
|
function nonNegativeCentValue(value) {
|
|
27776
|
-
if (!
|
|
27826
|
+
if (!isRecord22(value))
|
|
27777
27827
|
return void 0;
|
|
27778
27828
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
27779
27829
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
@@ -27797,7 +27847,7 @@ function productUsageFrom(value) {
|
|
|
27797
27847
|
if (!Array.isArray(value))
|
|
27798
27848
|
return void 0;
|
|
27799
27849
|
const products = value.flatMap((entry) => {
|
|
27800
|
-
if (!
|
|
27850
|
+
if (!isRecord22(entry) || typeof entry.product !== "string")
|
|
27801
27851
|
return [];
|
|
27802
27852
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
27803
27853
|
const labels = {
|
|
@@ -27818,10 +27868,10 @@ function productUsageFrom(value) {
|
|
|
27818
27868
|
return products.length > 0 ? products : void 0;
|
|
27819
27869
|
}
|
|
27820
27870
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
27821
|
-
if (!
|
|
27871
|
+
if (!isRecord22(value) || !isRecord22(value.config))
|
|
27822
27872
|
return null;
|
|
27823
27873
|
const config2 = value.config;
|
|
27824
|
-
const period =
|
|
27874
|
+
const period = isRecord22(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
27825
27875
|
const periodType = periodTypeFrom(period?.type);
|
|
27826
27876
|
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);
|
|
27827
27877
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -27848,11 +27898,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
27848
27898
|
};
|
|
27849
27899
|
}
|
|
27850
27900
|
function selectAccessToken(auth, now) {
|
|
27851
|
-
if (!
|
|
27901
|
+
if (!isRecord22(auth))
|
|
27852
27902
|
return null;
|
|
27853
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
27903
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord22(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")));
|
|
27854
27904
|
for (const [, value] of entries) {
|
|
27855
|
-
if (!
|
|
27905
|
+
if (!isRecord22(value) || typeof value.key !== "string")
|
|
27856
27906
|
continue;
|
|
27857
27907
|
if (typeof value.expires_at === "string") {
|
|
27858
27908
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -27928,7 +27978,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
27928
27978
|
|
|
27929
27979
|
// dist/grok-usage.js
|
|
27930
27980
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
27931
|
-
function
|
|
27981
|
+
function isRecord23(value) {
|
|
27932
27982
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27933
27983
|
}
|
|
27934
27984
|
function optionalToken(value) {
|
|
@@ -27945,7 +27995,7 @@ function combineUsage(base, next) {
|
|
|
27945
27995
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
27946
27996
|
}
|
|
27947
27997
|
function usageFromNative(value) {
|
|
27948
|
-
if (!
|
|
27998
|
+
if (!isRecord23(value))
|
|
27949
27999
|
return null;
|
|
27950
28000
|
const inputTokens = optionalToken(value.inputTokens);
|
|
27951
28001
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -27969,7 +28019,7 @@ function usageFromNative(value) {
|
|
|
27969
28019
|
}
|
|
27970
28020
|
}
|
|
27971
28021
|
function usageFromResponse(value) {
|
|
27972
|
-
if (!
|
|
28022
|
+
if (!isRecord23(value))
|
|
27973
28023
|
return null;
|
|
27974
28024
|
const buckets = [
|
|
27975
28025
|
value.input_tokens,
|
|
@@ -28069,7 +28119,7 @@ var GrokTurnUsage = class {
|
|
|
28069
28119
|
}
|
|
28070
28120
|
};
|
|
28071
28121
|
function usageFromSignals(value) {
|
|
28072
|
-
if (!
|
|
28122
|
+
if (!isRecord23(value))
|
|
28073
28123
|
return null;
|
|
28074
28124
|
try {
|
|
28075
28125
|
return parseHostUsage({
|
|
@@ -28089,7 +28139,7 @@ var summedUsageFields = [
|
|
|
28089
28139
|
"totalTokens"
|
|
28090
28140
|
];
|
|
28091
28141
|
function nativeCostTicks(value) {
|
|
28092
|
-
if (!
|
|
28142
|
+
if (!isRecord23(value))
|
|
28093
28143
|
return void 0;
|
|
28094
28144
|
const ticks = value.costUsdTicks;
|
|
28095
28145
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -28097,7 +28147,7 @@ function nativeCostTicks(value) {
|
|
|
28097
28147
|
return ticks;
|
|
28098
28148
|
}
|
|
28099
28149
|
function sessionCostFromNative(value, initialCostUsd) {
|
|
28100
|
-
if (!
|
|
28150
|
+
if (!isRecord23(value))
|
|
28101
28151
|
return void 0;
|
|
28102
28152
|
if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
|
|
28103
28153
|
return void 0;
|
|
@@ -28128,7 +28178,7 @@ function sessionUsageFromHistory(events) {
|
|
|
28128
28178
|
continue;
|
|
28129
28179
|
const usage = usageFromNative(event.usage);
|
|
28130
28180
|
const ticks2 = nativeCostTicks(event.usage);
|
|
28131
|
-
const complete =
|
|
28181
|
+
const complete = isRecord23(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && usage.cachedInputTokens <= usage.inputTokens;
|
|
28132
28182
|
latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
|
|
28133
28183
|
}
|
|
28134
28184
|
if (latestByKey.size === 0)
|
|
@@ -28182,7 +28232,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
28182
28232
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
28183
28233
|
try {
|
|
28184
28234
|
if (update?.sessionUpdate === "usage_update") {
|
|
28185
|
-
const cost =
|
|
28235
|
+
const cost = isRecord23(update.cost) ? update.cost : null;
|
|
28186
28236
|
return parseHostUsage({
|
|
28187
28237
|
contextUsedTokens: update.used,
|
|
28188
28238
|
contextWindowTokens: update.size,
|
|
@@ -28275,11 +28325,7 @@ function terminalOutcome2(response, cancelled) {
|
|
|
28275
28325
|
return { status: "succeeded" };
|
|
28276
28326
|
return {
|
|
28277
28327
|
status: "failed",
|
|
28278
|
-
error:
|
|
28279
|
-
code: "nativeFailure",
|
|
28280
|
-
message: `Grok stopped the Turn: ${response.stopReason}`,
|
|
28281
|
-
retryable: response.stopReason === "max_tokens" || response.stopReason === "max_turn_requests"
|
|
28282
|
-
}
|
|
28328
|
+
error: grokPromptStopError(response)
|
|
28283
28329
|
};
|
|
28284
28330
|
}
|
|
28285
28331
|
var GrokHarnessSession = class {
|
|
@@ -30076,6 +30122,14 @@ var GrokAdapter = class {
|
|
|
30076
30122
|
delete credits.productUsage;
|
|
30077
30123
|
return { ...account, credits };
|
|
30078
30124
|
}
|
|
30125
|
+
async isModelUsable(input) {
|
|
30126
|
+
void input;
|
|
30127
|
+
return {
|
|
30128
|
+
usable: true,
|
|
30129
|
+
checked: false,
|
|
30130
|
+
reason: "Grok does not expose per-model entitlement before spawn; catalog membership is necessary, not sufficient."
|
|
30131
|
+
};
|
|
30132
|
+
}
|
|
30079
30133
|
credits() {
|
|
30080
30134
|
return this.#credits;
|
|
30081
30135
|
}
|