@codexhost/cli-win32-arm64 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +51 -6
- package/app/console-web.js +212 -64
- package/app/desktop-controller.mjs +48 -3
- package/app/host-runtime.mjs +358 -79
- package/app/plugins/antigravity/plugin.mjs +340 -53
- package/app/plugins/claude-code/plugin.mjs +373 -132
- package/app/plugins/codebuddy/plugin.mjs +205 -46
- package/app/plugins/codex-usage/plugin.mjs +73 -28
- package/app/plugins/copilot/plugin.mjs +98 -53
- package/app/plugins/cursor-cli/plugin.mjs +205 -46
- package/app/plugins/deepseek-harness/plugin.mjs +77 -32
- package/app/plugins/grok/plugin.mjs +352 -84
- package/app/plugins/hermes/plugin.mjs +48 -3
- package/app/plugins/kimi-code/plugin.mjs +60 -15
- package/app/plugins/kiro-cli/plugin.mjs +60 -15
- package/app/plugins/omp/plugin.mjs +80 -35
- package/app/plugins/opencode/plugin.mjs +102 -57
- package/app/plugins/pi/plugin.mjs +113 -43
- package/app/plugins/qoder/plugin.mjs +70 -25
- package/app/plugins/qoder-cn/plugin.mjs +70 -25
- package/app/plugins/workbuddy/plugin.mjs +205 -46
- package/app/plugins/zcode/plugin.mjs +99 -29
- package/app/renderer-extension.js +944 -249
- 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
|
@@ -3634,10 +3634,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
3634
3634
|
const shape = def.shape;
|
|
3635
3635
|
const propValues = {};
|
|
3636
3636
|
for (const key in shape) {
|
|
3637
|
-
const
|
|
3638
|
-
if (
|
|
3637
|
+
const field2 = shape[key]._zod;
|
|
3638
|
+
if (field2.values) {
|
|
3639
3639
|
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
3640
|
-
for (const v of
|
|
3640
|
+
for (const v of field2.values)
|
|
3641
3641
|
propValues[key].add(v);
|
|
3642
3642
|
}
|
|
3643
3643
|
}
|
|
@@ -15384,6 +15384,51 @@ var hostInteractionIdSchema = opaqueIdSchema.brand();
|
|
|
15384
15384
|
var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
|
|
15385
15385
|
var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
|
|
15386
15386
|
|
|
15387
|
+
// ../../shared-contracts/dist/thread-questions.js
|
|
15388
|
+
var field = external_exports.discriminatedUnion("type", [
|
|
15389
|
+
external_exports.object({
|
|
15390
|
+
id: external_exports.string().min(1),
|
|
15391
|
+
type: external_exports.literal("choice"),
|
|
15392
|
+
prompt: external_exports.string(),
|
|
15393
|
+
options: external_exports.array(external_exports.object({
|
|
15394
|
+
value: external_exports.string().min(1),
|
|
15395
|
+
label: external_exports.string(),
|
|
15396
|
+
description: external_exports.string().optional()
|
|
15397
|
+
})).min(1),
|
|
15398
|
+
multiple: external_exports.boolean(),
|
|
15399
|
+
allowOther: external_exports.boolean(),
|
|
15400
|
+
optional: external_exports.boolean()
|
|
15401
|
+
}),
|
|
15402
|
+
external_exports.object({
|
|
15403
|
+
id: external_exports.string().min(1),
|
|
15404
|
+
type: external_exports.literal("text"),
|
|
15405
|
+
prompt: external_exports.string(),
|
|
15406
|
+
multiline: external_exports.boolean(),
|
|
15407
|
+
secret: external_exports.literal(false),
|
|
15408
|
+
optional: external_exports.boolean(),
|
|
15409
|
+
placeholder: external_exports.string().optional(),
|
|
15410
|
+
prefill: external_exports.string().optional()
|
|
15411
|
+
})
|
|
15412
|
+
]);
|
|
15413
|
+
var threadQuestionSchema = external_exports.object({
|
|
15414
|
+
interactionId: external_exports.string().min(1),
|
|
15415
|
+
turnId: external_exports.string().min(1),
|
|
15416
|
+
title: external_exports.string().optional(),
|
|
15417
|
+
questions: external_exports.array(field).min(1)
|
|
15418
|
+
}).refine(({ questions }) => questions.some((q) => q.type === "choice" && q.multiple), {
|
|
15419
|
+
message: "Shared cards require at least one multi-select question"
|
|
15420
|
+
});
|
|
15421
|
+
var threadQuestionsListParamsSchema = external_exports.strictObject({ threadId: external_exports.string().min(1) });
|
|
15422
|
+
var threadQuestionsResultSchema = external_exports.object({ questions: external_exports.array(threadQuestionSchema) });
|
|
15423
|
+
var threadQuestionRespondParamsSchema = external_exports.strictObject({
|
|
15424
|
+
threadId: external_exports.string().min(1),
|
|
15425
|
+
turnId: external_exports.string().min(1),
|
|
15426
|
+
interactionId: external_exports.string().min(1),
|
|
15427
|
+
answers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
|
|
15428
|
+
cancelled: external_exports.boolean().default(false)
|
|
15429
|
+
});
|
|
15430
|
+
var threadQuestionRespondResultSchema = external_exports.object({ accepted: external_exports.literal(true) });
|
|
15431
|
+
|
|
15387
15432
|
// ../../shared-contracts/dist/console.js
|
|
15388
15433
|
var consoleAnnouncementSchema = external_exports.strictObject({
|
|
15389
15434
|
title: external_exports.string().trim().min(1).max(200),
|
|
@@ -16560,6 +16605,42 @@ function validateHostApprovalResponse(interaction, response) {
|
|
|
16560
16605
|
return interaction.actions.some(({ id }) => id === response.actionId) ? null : invalidRequest("Approval Response contains an undeclared action ID");
|
|
16561
16606
|
}
|
|
16562
16607
|
|
|
16608
|
+
// ../../harness-adapter/dist/question.js
|
|
16609
|
+
function invalidRequest2(message) {
|
|
16610
|
+
return { code: "invalidRequest", message, retryable: false };
|
|
16611
|
+
}
|
|
16612
|
+
function validateHostQuestionResponse(interaction, response) {
|
|
16613
|
+
const questionIds = new Set(interaction.questions.map(({ id }) => id));
|
|
16614
|
+
if (response.cancelled) {
|
|
16615
|
+
return Object.keys(response.answers).length === 0 ? null : invalidRequest2("Cancelled Question Response must not contain answers");
|
|
16616
|
+
}
|
|
16617
|
+
for (const answerId of Object.keys(response.answers)) {
|
|
16618
|
+
if (!questionIds.has(answerId)) {
|
|
16619
|
+
return invalidRequest2("Question Response contains an unknown Question ID");
|
|
16620
|
+
}
|
|
16621
|
+
}
|
|
16622
|
+
for (const question of interaction.questions) {
|
|
16623
|
+
const answers = response.answers[question.id] ?? [];
|
|
16624
|
+
if (!question.optional && answers.length === 0) {
|
|
16625
|
+
return invalidRequest2("Question Response omits a required answer");
|
|
16626
|
+
}
|
|
16627
|
+
if (question.type === "text") {
|
|
16628
|
+
if (answers.length > 1) {
|
|
16629
|
+
return invalidRequest2("Text Question accepts at most one answer");
|
|
16630
|
+
}
|
|
16631
|
+
continue;
|
|
16632
|
+
}
|
|
16633
|
+
if (!question.multiple && answers.length > 1) {
|
|
16634
|
+
return invalidRequest2("Single-choice Question accepts at most one answer");
|
|
16635
|
+
}
|
|
16636
|
+
const declared = new Set(question.options.map(({ value }) => value));
|
|
16637
|
+
if (!question.allowOther && answers.some((answer) => !declared.has(answer))) {
|
|
16638
|
+
return invalidRequest2("Question Response contains an undeclared choice");
|
|
16639
|
+
}
|
|
16640
|
+
}
|
|
16641
|
+
return null;
|
|
16642
|
+
}
|
|
16643
|
+
|
|
16563
16644
|
// ../../harness-adapter/dist/output-channel.js
|
|
16564
16645
|
var HarnessOutputChannel = class {
|
|
16565
16646
|
outputs;
|
|
@@ -16681,26 +16762,26 @@ function parseHostUsage(value) {
|
|
|
16681
16762
|
}
|
|
16682
16763
|
}
|
|
16683
16764
|
const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
|
|
16684
|
-
for (const
|
|
16765
|
+
for (const field2 of [
|
|
16685
16766
|
"totalCredits",
|
|
16686
16767
|
"contextUsagePercent",
|
|
16687
16768
|
"apiOutputTokensPerSecond"
|
|
16688
16769
|
]) {
|
|
16689
|
-
const candidate = value[
|
|
16770
|
+
const candidate = value[field2];
|
|
16690
16771
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
16691
|
-
throw new Error(`Harness Usage '${
|
|
16772
|
+
throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
|
|
16692
16773
|
}
|
|
16693
16774
|
}
|
|
16694
|
-
for (const
|
|
16695
|
-
const candidate = value[
|
|
16775
|
+
for (const field2 of tokenFields) {
|
|
16776
|
+
const candidate = value[field2];
|
|
16696
16777
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
16697
|
-
throw new Error(`Harness Usage '${
|
|
16778
|
+
throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
|
|
16698
16779
|
}
|
|
16699
16780
|
}
|
|
16700
|
-
for (const
|
|
16701
|
-
const candidate = value[
|
|
16781
|
+
for (const field2 of safeIntegerFields) {
|
|
16782
|
+
const candidate = value[field2];
|
|
16702
16783
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
16703
|
-
throw new Error(`Harness Usage '${
|
|
16784
|
+
throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
|
|
16704
16785
|
}
|
|
16705
16786
|
}
|
|
16706
16787
|
if (value.outputTokensPerSecond !== void 0 && (typeof value.outputTokensPerSecond !== "number" || !Number.isFinite(value.outputTokensPerSecond) || value.outputTokensPerSecond < 0)) {
|
|
@@ -16709,10 +16790,10 @@ function parseHostUsage(value) {
|
|
|
16709
16790
|
if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
|
|
16710
16791
|
throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
|
|
16711
16792
|
}
|
|
16712
|
-
for (const
|
|
16713
|
-
const candidate = value[
|
|
16793
|
+
for (const field2 of percentFields) {
|
|
16794
|
+
const candidate = value[field2];
|
|
16714
16795
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
|
|
16715
|
-
throw new Error(`Harness Usage '${
|
|
16796
|
+
throw new Error(`Harness Usage '${field2}' must be between 0 and 100`);
|
|
16716
16797
|
}
|
|
16717
16798
|
}
|
|
16718
16799
|
if (value.sessionCacheUsage !== void 0) {
|
|
@@ -21938,10 +22019,10 @@ function stringField(value, key) {
|
|
|
21938
22019
|
function numberField(value, key) {
|
|
21939
22020
|
if (!isRecord6(value))
|
|
21940
22021
|
return void 0;
|
|
21941
|
-
const
|
|
21942
|
-
if (
|
|
22022
|
+
const field2 = value[key];
|
|
22023
|
+
if (field2 === null)
|
|
21943
22024
|
return null;
|
|
21944
|
-
return typeof
|
|
22025
|
+
return typeof field2 === "number" && Number.isFinite(field2) ? field2 : void 0;
|
|
21945
22026
|
}
|
|
21946
22027
|
function decodeBytes(value) {
|
|
21947
22028
|
if (!Array.isArray(value) || value.length === 0)
|
|
@@ -22140,13 +22221,13 @@ function isRecord7(value) {
|
|
|
22140
22221
|
function idField(value, key) {
|
|
22141
22222
|
if (!isRecord7(value))
|
|
22142
22223
|
return void 0;
|
|
22143
|
-
const
|
|
22144
|
-
if (typeof
|
|
22145
|
-
const trimmed =
|
|
22224
|
+
const field2 = value[key];
|
|
22225
|
+
if (typeof field2 === "string") {
|
|
22226
|
+
const trimmed = field2.trim();
|
|
22146
22227
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
22147
22228
|
}
|
|
22148
|
-
if (typeof
|
|
22149
|
-
return String(
|
|
22229
|
+
if (typeof field2 === "number" && Number.isFinite(field2))
|
|
22230
|
+
return String(field2);
|
|
22150
22231
|
return void 0;
|
|
22151
22232
|
}
|
|
22152
22233
|
function stringField2(value, key) {
|
|
@@ -23398,6 +23479,163 @@ var GrokPermissionConfirmation = class {
|
|
|
23398
23479
|
}
|
|
23399
23480
|
};
|
|
23400
23481
|
|
|
23482
|
+
// dist/grok-questions.js
|
|
23483
|
+
var GROK_ASK_USER_QUESTION_METHOD = "_x.ai/ask_user_question";
|
|
23484
|
+
function isRecord12(value) {
|
|
23485
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23486
|
+
}
|
|
23487
|
+
function nonEmptyString(value) {
|
|
23488
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
23489
|
+
}
|
|
23490
|
+
function parseGrokQuestionRequest(value) {
|
|
23491
|
+
if (!isRecord12(value) || !nonEmptyString(value.sessionId) || !nonEmptyString(value.toolCallId) || value.mode !== "default" && value.mode !== "plan" || !Array.isArray(value.questions) || value.questions.length === 0)
|
|
23492
|
+
throw new Error("Grok question requires sessionId, toolCallId, mode and nonempty questions");
|
|
23493
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23494
|
+
const questions = value.questions.map((question) => {
|
|
23495
|
+
if (!isRecord12(question) || !nonEmptyString(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")
|
|
23496
|
+
throw new Error("Grok question text must be unique and options/multiSelect must be valid");
|
|
23497
|
+
if (question.multiSelect != null && question.multi_select != null && question.multiSelect !== question.multi_select)
|
|
23498
|
+
throw new Error("Grok question contains conflicting multi-select flags");
|
|
23499
|
+
seen.add(question.question);
|
|
23500
|
+
const labels = /* @__PURE__ */ new Set();
|
|
23501
|
+
const options = question.options.map((option) => {
|
|
23502
|
+
if (!isRecord12(option) || !nonEmptyString(option.label) || labels.has(option.label) || typeof option.description !== "string" || option.preview != null && typeof option.preview !== "string")
|
|
23503
|
+
throw new Error("Grok question options require unique labels and text descriptions/previews");
|
|
23504
|
+
labels.add(option.label);
|
|
23505
|
+
return {
|
|
23506
|
+
label: option.label,
|
|
23507
|
+
description: option.description,
|
|
23508
|
+
...typeof option.preview === "string" ? { preview: option.preview } : {}
|
|
23509
|
+
};
|
|
23510
|
+
});
|
|
23511
|
+
return {
|
|
23512
|
+
question: question.question,
|
|
23513
|
+
options,
|
|
23514
|
+
multiple: question.multiSelect === true || question.multi_select === true
|
|
23515
|
+
};
|
|
23516
|
+
});
|
|
23517
|
+
return { sessionId: value.sessionId, toolCallId: value.toolCallId, mode: value.mode, questions };
|
|
23518
|
+
}
|
|
23519
|
+
var GrokQuestions = class {
|
|
23520
|
+
turnId;
|
|
23521
|
+
randomUUID;
|
|
23522
|
+
emit;
|
|
23523
|
+
#pending = /* @__PURE__ */ new Map();
|
|
23524
|
+
#seenToolCalls = /* @__PURE__ */ new Set();
|
|
23525
|
+
#closed = false;
|
|
23526
|
+
constructor(turnId, randomUUID2, emit) {
|
|
23527
|
+
this.turnId = turnId;
|
|
23528
|
+
this.randomUUID = randomUUID2;
|
|
23529
|
+
this.emit = emit;
|
|
23530
|
+
}
|
|
23531
|
+
has(interactionId) {
|
|
23532
|
+
return this.#pending.has(interactionId);
|
|
23533
|
+
}
|
|
23534
|
+
ask(request) {
|
|
23535
|
+
if (this.#closed || this.#seenToolCalls.has(request.toolCallId))
|
|
23536
|
+
return Promise.resolve({ outcome: "cancelled" });
|
|
23537
|
+
this.#seenToolCalls.add(request.toolCallId);
|
|
23538
|
+
const interaction = {
|
|
23539
|
+
type: "question",
|
|
23540
|
+
interactionId: hostInteractionIdSchema.parse(this.randomUUID()),
|
|
23541
|
+
turnId: this.turnId,
|
|
23542
|
+
title: "Grok",
|
|
23543
|
+
questions: request.questions.map((question, index) => question.options.length ? {
|
|
23544
|
+
id: `q${index}`,
|
|
23545
|
+
type: "choice",
|
|
23546
|
+
prompt: question.question,
|
|
23547
|
+
options: question.options.map(({ label, description, preview }) => ({
|
|
23548
|
+
value: label,
|
|
23549
|
+
label,
|
|
23550
|
+
description: [description, preview].filter(Boolean).join("\n\n")
|
|
23551
|
+
})),
|
|
23552
|
+
multiple: question.multiple,
|
|
23553
|
+
allowOther: true,
|
|
23554
|
+
optional: true
|
|
23555
|
+
} : {
|
|
23556
|
+
id: `q${index}`,
|
|
23557
|
+
type: "text",
|
|
23558
|
+
prompt: question.question,
|
|
23559
|
+
multiline: true,
|
|
23560
|
+
secret: false,
|
|
23561
|
+
optional: true
|
|
23562
|
+
})
|
|
23563
|
+
};
|
|
23564
|
+
return new Promise((resolve) => {
|
|
23565
|
+
this.#pending.set(interaction.interactionId, { request, interaction, resolve });
|
|
23566
|
+
this.emit({ kind: "interaction", interaction });
|
|
23567
|
+
});
|
|
23568
|
+
}
|
|
23569
|
+
respond(command) {
|
|
23570
|
+
const pending = this.#pending.get(command.interactionId);
|
|
23571
|
+
if (!pending)
|
|
23572
|
+
return this.#error("invalidState", "Grok Question is not pending");
|
|
23573
|
+
if (command.response.type !== "question")
|
|
23574
|
+
return this.#error("invalidRequest", "Grok Question requires a Question Response");
|
|
23575
|
+
const response = command.response;
|
|
23576
|
+
const error53 = validateHostQuestionResponse(pending.interaction, response);
|
|
23577
|
+
if (error53)
|
|
23578
|
+
return { ok: false, error: error53 };
|
|
23579
|
+
if (response.cancelled) {
|
|
23580
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
23581
|
+
return { ok: true, value: { accepted: true } };
|
|
23582
|
+
}
|
|
23583
|
+
const answers = /* @__PURE__ */ new Map();
|
|
23584
|
+
const annotations = /* @__PURE__ */ new Map();
|
|
23585
|
+
for (const [index, question] of pending.request.questions.entries()) {
|
|
23586
|
+
const values = response.answers[`q${index}`];
|
|
23587
|
+
if (!values?.length)
|
|
23588
|
+
continue;
|
|
23589
|
+
if (values.some((answer) => !nonEmptyString(answer)) || new Set(values).size !== values.length)
|
|
23590
|
+
return this.#error("invalidRequest", "Grok answers must be nonempty and unique");
|
|
23591
|
+
const selected = values.map((answer) => question.options.find(({ label }) => label === answer));
|
|
23592
|
+
const other = values.filter((_, position) => !selected[position]);
|
|
23593
|
+
if (other.length > 1)
|
|
23594
|
+
return this.#error("invalidRequest", "Grok question accepts only one Other response");
|
|
23595
|
+
answers.set(question.question, selected.map((option) => option?.label ?? "Other"));
|
|
23596
|
+
const previews = selected.flatMap((option) => option?.preview !== void 0 ? [option.preview] : []);
|
|
23597
|
+
if (previews.length || other.length)
|
|
23598
|
+
annotations.set(question.question, {
|
|
23599
|
+
...previews.length ? { preview: previews.join("\n\n") } : {},
|
|
23600
|
+
...other.length ? { notes: other[0] } : {}
|
|
23601
|
+
});
|
|
23602
|
+
}
|
|
23603
|
+
this.#settle(pending, {
|
|
23604
|
+
outcome: "accepted",
|
|
23605
|
+
answers: Object.fromEntries(answers),
|
|
23606
|
+
...annotations.size ? { annotations: Object.fromEntries(annotations) } : {}
|
|
23607
|
+
}, "responded");
|
|
23608
|
+
return { ok: true, value: { accepted: true } };
|
|
23609
|
+
}
|
|
23610
|
+
withdraw(toolCallId) {
|
|
23611
|
+
for (const pending of this.#pending.values()) {
|
|
23612
|
+
if (pending.request.toolCallId === toolCallId)
|
|
23613
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
23614
|
+
}
|
|
23615
|
+
}
|
|
23616
|
+
cancel() {
|
|
23617
|
+
this.#closed = true;
|
|
23618
|
+
for (const pending of this.#pending.values())
|
|
23619
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
23620
|
+
}
|
|
23621
|
+
#settle(pending, response, reason) {
|
|
23622
|
+
this.#pending.delete(pending.interaction.interactionId);
|
|
23623
|
+
pending.resolve(response);
|
|
23624
|
+
this.emit({
|
|
23625
|
+
kind: "event",
|
|
23626
|
+
event: {
|
|
23627
|
+
type: "interaction.closed",
|
|
23628
|
+
interactionId: pending.interaction.interactionId,
|
|
23629
|
+
turnId: this.turnId,
|
|
23630
|
+
reason
|
|
23631
|
+
}
|
|
23632
|
+
});
|
|
23633
|
+
}
|
|
23634
|
+
#error(code, message) {
|
|
23635
|
+
return { ok: false, error: { code, message, retryable: false } };
|
|
23636
|
+
}
|
|
23637
|
+
};
|
|
23638
|
+
|
|
23401
23639
|
// dist/acp-transport.js
|
|
23402
23640
|
var GrokTransportError = class extends Error {
|
|
23403
23641
|
kind;
|
|
@@ -23409,16 +23647,16 @@ var GrokTransportError = class extends Error {
|
|
|
23409
23647
|
this.name = "GrokTransportError";
|
|
23410
23648
|
}
|
|
23411
23649
|
};
|
|
23412
|
-
function
|
|
23650
|
+
function isRecord13(value) {
|
|
23413
23651
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23414
23652
|
}
|
|
23415
23653
|
function acpToolName(update, metadata) {
|
|
23416
|
-
if (!
|
|
23654
|
+
if (!isRecord13(update))
|
|
23417
23655
|
return void 0;
|
|
23418
23656
|
if (typeof update.name === "string" && update.name.length > 0)
|
|
23419
23657
|
return update.name;
|
|
23420
|
-
const meta3 =
|
|
23421
|
-
const tool = meta3 &&
|
|
23658
|
+
const meta3 = isRecord13(update._meta) ? update._meta : metadata;
|
|
23659
|
+
const tool = meta3 && isRecord13(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
23422
23660
|
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
23423
23661
|
}
|
|
23424
23662
|
function errorText(error53) {
|
|
@@ -23474,7 +23712,7 @@ function signalProcessTree(child, signal) {
|
|
|
23474
23712
|
try {
|
|
23475
23713
|
process.kill(-child.pid, signal);
|
|
23476
23714
|
} catch (error53) {
|
|
23477
|
-
if (!
|
|
23715
|
+
if (!isRecord13(error53) || error53.code !== "ESRCH")
|
|
23478
23716
|
throw error53;
|
|
23479
23717
|
}
|
|
23480
23718
|
}
|
|
@@ -23517,6 +23755,10 @@ function transportEvent(update, metadata) {
|
|
|
23517
23755
|
const subagent = grokSubagentEventFromUpdate(extension);
|
|
23518
23756
|
if (subagent)
|
|
23519
23757
|
return subagent;
|
|
23758
|
+
if (extension.sessionUpdate === "interaction_resolved") {
|
|
23759
|
+
const toolCallId = extension.tool_call_id ?? extension.toolCallId;
|
|
23760
|
+
return typeof toolCallId === "string" && toolCallId.trim().length > 0 ? { type: "interaction.resolved", toolCallId, ...metadata ? { metadata } : {} } : null;
|
|
23761
|
+
}
|
|
23520
23762
|
switch (update.sessionUpdate) {
|
|
23521
23763
|
case "user_message_chunk":
|
|
23522
23764
|
case "agent_message_chunk":
|
|
@@ -23584,7 +23826,7 @@ async function readNativeSignals(options, sessionId) {
|
|
|
23584
23826
|
}
|
|
23585
23827
|
}
|
|
23586
23828
|
function isMissingFile(error53) {
|
|
23587
|
-
return
|
|
23829
|
+
return isRecord13(error53) && error53.code === "ENOENT";
|
|
23588
23830
|
}
|
|
23589
23831
|
async function locateGrokNativeSession(options, sessionId) {
|
|
23590
23832
|
if (sessionId.length === 0)
|
|
@@ -23607,7 +23849,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23607
23849
|
try {
|
|
23608
23850
|
summaryRaw = await readFile3(path12.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
23609
23851
|
} catch (error53) {
|
|
23610
|
-
if (isMissingFile(error53) ||
|
|
23852
|
+
if (isMissingFile(error53) || isRecord13(error53) && error53.code === "ENOTDIR")
|
|
23611
23853
|
continue;
|
|
23612
23854
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
23613
23855
|
cause: error53
|
|
@@ -23619,10 +23861,10 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23619
23861
|
} catch {
|
|
23620
23862
|
continue;
|
|
23621
23863
|
}
|
|
23622
|
-
if (!
|
|
23864
|
+
if (!isRecord13(parsed))
|
|
23623
23865
|
continue;
|
|
23624
23866
|
const info = parsed.info;
|
|
23625
|
-
const cwd =
|
|
23867
|
+
const cwd = isRecord13(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path12.resolve(info.cwd) : path12.resolve(decodeURIComponent(entry.name));
|
|
23626
23868
|
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path12.resolve(parsed.source_workspace_dir) : void 0;
|
|
23627
23869
|
matches.push({
|
|
23628
23870
|
cwd,
|
|
@@ -23655,12 +23897,12 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
23655
23897
|
} catch {
|
|
23656
23898
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
23657
23899
|
}
|
|
23658
|
-
if (!
|
|
23900
|
+
if (!isRecord13(record2) || !isRecord13(record2.params))
|
|
23659
23901
|
continue;
|
|
23660
23902
|
const params = record2.params;
|
|
23661
|
-
if (params.sessionId !== sessionId || !
|
|
23903
|
+
if (params.sessionId !== sessionId || !isRecord13(params.update))
|
|
23662
23904
|
continue;
|
|
23663
|
-
const metadata =
|
|
23905
|
+
const metadata = isRecord13(params._meta) ? params._meta : void 0;
|
|
23664
23906
|
const event = transportEvent(params.update, metadata);
|
|
23665
23907
|
if (event)
|
|
23666
23908
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -23724,7 +23966,7 @@ var GrokAcpTransport = class {
|
|
|
23724
23966
|
if (!this.#connection)
|
|
23725
23967
|
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
23726
23968
|
const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
|
|
23727
|
-
return
|
|
23969
|
+
return isRecord13(result) ? result.usage : void 0;
|
|
23728
23970
|
}
|
|
23729
23971
|
async readHistory(sessionId, cwd = this.#options.cwd) {
|
|
23730
23972
|
return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
|
|
@@ -23898,7 +24140,8 @@ var GrokAcpTransport = class {
|
|
|
23898
24140
|
const connection = new ClientSideConnection(() => ({
|
|
23899
24141
|
sessionUpdate: (params) => this.#handleUpdate(params),
|
|
23900
24142
|
requestPermission: (params) => this.#handlePermission(params),
|
|
23901
|
-
extNotification: (method, params) => this.#handleExtensionNotification(method, params)
|
|
24143
|
+
extNotification: (method, params) => this.#handleExtensionNotification(method, params),
|
|
24144
|
+
extMethod: (method, params) => this.#handleExtMethod(method, params)
|
|
23902
24145
|
}), stream);
|
|
23903
24146
|
this.#connection = connection;
|
|
23904
24147
|
child.once("error", (error53) => this.#fault(new GrokTransportError("processExited", error53.message)));
|
|
@@ -23918,7 +24161,7 @@ var GrokAcpTransport = class {
|
|
|
23918
24161
|
this.#initialize = initialize;
|
|
23919
24162
|
return initialize;
|
|
23920
24163
|
}
|
|
23921
|
-
async runTurn(text, onEvent, onPermission) {
|
|
24164
|
+
async runTurn(text, onEvent, onPermission, onQuestion = async () => ({ outcome: "cancelled" })) {
|
|
23922
24165
|
const connection = this.#connection;
|
|
23923
24166
|
if (!connection || !this.#sessionId || this.#closed || this.#closing) {
|
|
23924
24167
|
throw new GrokTransportError("unavailable", "Grok ACP Session is unavailable");
|
|
@@ -23927,7 +24170,7 @@ var GrokAcpTransport = class {
|
|
|
23927
24170
|
throw new Error("Grok ACP Session already has an active Prompt");
|
|
23928
24171
|
if (this.#permissionConfirmation)
|
|
23929
24172
|
throw new GrokTransportError("unavailable", "Grok ACP Session has an active operation");
|
|
23930
|
-
const active = { onEvent, onPermission };
|
|
24173
|
+
const active = { onEvent, onPermission, onQuestion };
|
|
23931
24174
|
this.#activePrompt = active;
|
|
23932
24175
|
try {
|
|
23933
24176
|
return await connection.prompt({
|
|
@@ -23986,7 +24229,7 @@ var GrokAcpTransport = class {
|
|
|
23986
24229
|
...reasoningEffort ? { reasoningEffort } : {},
|
|
23987
24230
|
...contextWindowTokens !== void 0 ? { _meta: { contextWindow: contextWindowTokens } } : {}
|
|
23988
24231
|
});
|
|
23989
|
-
if (!
|
|
24232
|
+
if (!isRecord13(response) || !isRecord13(response._meta) || !isRecord13(response._meta.model)) {
|
|
23990
24233
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
23991
24234
|
}
|
|
23992
24235
|
const selected = response._meta.model.Ok;
|
|
@@ -24026,7 +24269,7 @@ var GrokAcpTransport = class {
|
|
|
24026
24269
|
permission_mode: mode
|
|
24027
24270
|
});
|
|
24028
24271
|
const response = await connection.request("_x.ai/session/info", { sessionId });
|
|
24029
|
-
if (!
|
|
24272
|
+
if (!isRecord13(response) || !isRecord13(response.result) || response.result.sessionId !== sessionId) {
|
|
24030
24273
|
throw new Error("Grok did not confirm the target Session");
|
|
24031
24274
|
}
|
|
24032
24275
|
})()
|
|
@@ -24081,7 +24324,7 @@ var GrokAcpTransport = class {
|
|
|
24081
24324
|
this.#availableCommands = parseGrokAvailableCommands(update.availableCommands);
|
|
24082
24325
|
return;
|
|
24083
24326
|
}
|
|
24084
|
-
const metadata =
|
|
24327
|
+
const metadata = isRecord13(notification._meta) ? notification._meta : void 0;
|
|
24085
24328
|
const event = transportEvent(notification.update, metadata);
|
|
24086
24329
|
if (!event)
|
|
24087
24330
|
return;
|
|
@@ -24096,7 +24339,7 @@ var GrokAcpTransport = class {
|
|
|
24096
24339
|
#handleExtensionNotification(method, params) {
|
|
24097
24340
|
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
24098
24341
|
return;
|
|
24099
|
-
if (typeof params.sessionId !== "string" || !
|
|
24342
|
+
if (typeof params.sessionId !== "string" || !isRecord13(params.update))
|
|
24100
24343
|
return;
|
|
24101
24344
|
this.#handleUpdate(params);
|
|
24102
24345
|
}
|
|
@@ -24106,6 +24349,20 @@ var GrokAcpTransport = class {
|
|
|
24106
24349
|
}
|
|
24107
24350
|
return this.#activePrompt.onPermission({ request: params, options: params.options });
|
|
24108
24351
|
}
|
|
24352
|
+
async #handleExtMethod(method, params) {
|
|
24353
|
+
if (method !== GROK_ASK_USER_QUESTION_METHOD)
|
|
24354
|
+
throw RequestError.methodNotFound(method);
|
|
24355
|
+
let request;
|
|
24356
|
+
try {
|
|
24357
|
+
request = parseGrokQuestionRequest(params);
|
|
24358
|
+
} catch (error53) {
|
|
24359
|
+
throw RequestError.invalidParams(void 0, errorText(error53));
|
|
24360
|
+
}
|
|
24361
|
+
const active = this.#activePrompt;
|
|
24362
|
+
if (!active || this.#closed || this.#closing || this.#replay !== null || this.#activeCompact !== null || request.sessionId !== this.#sessionId)
|
|
24363
|
+
return { outcome: "cancelled" };
|
|
24364
|
+
return { ...await active.onQuestion(request) };
|
|
24365
|
+
}
|
|
24109
24366
|
#fault(error53) {
|
|
24110
24367
|
this.#permissionConfirmation?.reject(error53);
|
|
24111
24368
|
if (this.#closing || this.#closed)
|
|
@@ -24238,7 +24495,7 @@ var SessionImportScope = class {
|
|
|
24238
24495
|
// dist/session-import.js
|
|
24239
24496
|
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
24240
24497
|
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
24241
|
-
function
|
|
24498
|
+
function isRecord14(value) {
|
|
24242
24499
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24243
24500
|
}
|
|
24244
24501
|
async function readJson(file2, signal) {
|
|
@@ -24251,7 +24508,7 @@ function processAlive(pid) {
|
|
|
24251
24508
|
process.kill(pid, 0);
|
|
24252
24509
|
return true;
|
|
24253
24510
|
} catch (error53) {
|
|
24254
|
-
return
|
|
24511
|
+
return isRecord14(error53) && error53.code === "EPERM";
|
|
24255
24512
|
}
|
|
24256
24513
|
}
|
|
24257
24514
|
async function firstUserText(file2, signal) {
|
|
@@ -24268,10 +24525,10 @@ async function firstUserText(file2, signal) {
|
|
|
24268
24525
|
} catch {
|
|
24269
24526
|
continue;
|
|
24270
24527
|
}
|
|
24271
|
-
const update =
|
|
24272
|
-
if (!
|
|
24528
|
+
const update = isRecord14(entry) && isRecord14(entry.params) ? entry.params.update : null;
|
|
24529
|
+
if (!isRecord14(update) || update.sessionUpdate !== "user_message_chunk")
|
|
24273
24530
|
continue;
|
|
24274
|
-
const text =
|
|
24531
|
+
const text = isRecord14(update.content) ? update.content.text : null;
|
|
24275
24532
|
return typeof text === "string" ? text : "";
|
|
24276
24533
|
}
|
|
24277
24534
|
return null;
|
|
@@ -24348,7 +24605,7 @@ var GrokSessionImport = class {
|
|
|
24348
24605
|
if (!Array.isArray(entries))
|
|
24349
24606
|
return active;
|
|
24350
24607
|
for (const entry of entries) {
|
|
24351
|
-
if (
|
|
24608
|
+
if (isRecord14(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
24352
24609
|
active.add(entry.session_id);
|
|
24353
24610
|
}
|
|
24354
24611
|
return active;
|
|
@@ -24397,7 +24654,7 @@ var GrokSessionImport = class {
|
|
|
24397
24654
|
return null;
|
|
24398
24655
|
try {
|
|
24399
24656
|
const summary = await readJson(files[0], signal);
|
|
24400
|
-
if (!
|
|
24657
|
+
if (!isRecord14(summary) || !isRecord14(summary.info) || summary.info.id !== nativeSessionId)
|
|
24401
24658
|
return null;
|
|
24402
24659
|
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
24403
24660
|
return null;
|
|
@@ -24624,7 +24881,7 @@ var GrokSubagentLifecycle = class {
|
|
|
24624
24881
|
};
|
|
24625
24882
|
|
|
24626
24883
|
// dist/grok-models.js
|
|
24627
|
-
function
|
|
24884
|
+
function isRecord15(value) {
|
|
24628
24885
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24629
24886
|
}
|
|
24630
24887
|
function nonBlank(value) {
|
|
@@ -24636,7 +24893,7 @@ function thinkingOptions(value) {
|
|
|
24636
24893
|
const seen = /* @__PURE__ */ new Set();
|
|
24637
24894
|
const options = [];
|
|
24638
24895
|
for (const candidate of value) {
|
|
24639
|
-
if (!
|
|
24896
|
+
if (!isRecord15(candidate) || !nonBlank(candidate.label))
|
|
24640
24897
|
continue;
|
|
24641
24898
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
24642
24899
|
if (!id.success || seen.has(id.data))
|
|
@@ -24647,7 +24904,7 @@ function thinkingOptions(value) {
|
|
|
24647
24904
|
return options;
|
|
24648
24905
|
}
|
|
24649
24906
|
function parseGrokModelState(value) {
|
|
24650
|
-
if (!
|
|
24907
|
+
if (!isRecord15(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
24651
24908
|
return null;
|
|
24652
24909
|
}
|
|
24653
24910
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -24659,12 +24916,12 @@ function parseGrokModelState(value) {
|
|
|
24659
24916
|
const models = [];
|
|
24660
24917
|
let currentThinkingOptionId;
|
|
24661
24918
|
for (const candidate of value.availableModels) {
|
|
24662
|
-
if (!
|
|
24919
|
+
if (!isRecord15(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
24663
24920
|
continue;
|
|
24664
24921
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
24665
24922
|
if (!ref.success)
|
|
24666
24923
|
continue;
|
|
24667
|
-
const metadata =
|
|
24924
|
+
const metadata = isRecord15(candidate._meta) ? candidate._meta : {};
|
|
24668
24925
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
24669
24926
|
if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
|
|
24670
24927
|
defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
|
|
@@ -24703,10 +24960,10 @@ function parseGrokModelState(value) {
|
|
|
24703
24960
|
};
|
|
24704
24961
|
}
|
|
24705
24962
|
function modelStateFromInitialize(response) {
|
|
24706
|
-
return parseGrokModelState(
|
|
24963
|
+
return parseGrokModelState(isRecord15(response._meta) ? response._meta.modelState : void 0);
|
|
24707
24964
|
}
|
|
24708
24965
|
function modelStateFromSessionResponse(response) {
|
|
24709
|
-
return parseGrokModelState(
|
|
24966
|
+
return parseGrokModelState(isRecord15(response) ? response.models : void 0);
|
|
24710
24967
|
}
|
|
24711
24968
|
function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
24712
24969
|
const selectedModel = model2;
|
|
@@ -24730,7 +24987,7 @@ import os6 from "node:os";
|
|
|
24730
24987
|
import path14 from "node:path";
|
|
24731
24988
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
24732
24989
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
24733
|
-
function
|
|
24990
|
+
function isRecord16(value) {
|
|
24734
24991
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24735
24992
|
}
|
|
24736
24993
|
function finitePercent(value) {
|
|
@@ -24739,7 +24996,7 @@ function finitePercent(value) {
|
|
|
24739
24996
|
return Math.min(100, Math.max(0, value));
|
|
24740
24997
|
}
|
|
24741
24998
|
function nonNegativeCentValue(value) {
|
|
24742
|
-
if (!
|
|
24999
|
+
if (!isRecord16(value))
|
|
24743
25000
|
return void 0;
|
|
24744
25001
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
24745
25002
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
@@ -24763,7 +25020,7 @@ function productUsageFrom(value) {
|
|
|
24763
25020
|
if (!Array.isArray(value))
|
|
24764
25021
|
return void 0;
|
|
24765
25022
|
const products = value.flatMap((entry) => {
|
|
24766
|
-
if (!
|
|
25023
|
+
if (!isRecord16(entry) || typeof entry.product !== "string")
|
|
24767
25024
|
return [];
|
|
24768
25025
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
24769
25026
|
const labels = {
|
|
@@ -24784,10 +25041,10 @@ function productUsageFrom(value) {
|
|
|
24784
25041
|
return products.length > 0 ? products : void 0;
|
|
24785
25042
|
}
|
|
24786
25043
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
24787
|
-
if (!
|
|
25044
|
+
if (!isRecord16(value) || !isRecord16(value.config))
|
|
24788
25045
|
return null;
|
|
24789
25046
|
const config2 = value.config;
|
|
24790
|
-
const period =
|
|
25047
|
+
const period = isRecord16(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
24791
25048
|
const periodType = periodTypeFrom(period?.type);
|
|
24792
25049
|
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);
|
|
24793
25050
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -24814,11 +25071,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
24814
25071
|
};
|
|
24815
25072
|
}
|
|
24816
25073
|
function selectAccessToken(auth, now) {
|
|
24817
|
-
if (!
|
|
25074
|
+
if (!isRecord16(auth))
|
|
24818
25075
|
return null;
|
|
24819
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
25076
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord16(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")));
|
|
24820
25077
|
for (const [, value] of entries) {
|
|
24821
|
-
if (!
|
|
25078
|
+
if (!isRecord16(value) || typeof value.key !== "string")
|
|
24822
25079
|
continue;
|
|
24823
25080
|
if (typeof value.expires_at === "string") {
|
|
24824
25081
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -24889,7 +25146,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
24889
25146
|
|
|
24890
25147
|
// dist/grok-usage.js
|
|
24891
25148
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
24892
|
-
function
|
|
25149
|
+
function isRecord17(value) {
|
|
24893
25150
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24894
25151
|
}
|
|
24895
25152
|
function optionalToken(value) {
|
|
@@ -24906,7 +25163,7 @@ function combineUsage(base, next) {
|
|
|
24906
25163
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
24907
25164
|
}
|
|
24908
25165
|
function usageFromNative(value) {
|
|
24909
|
-
if (!
|
|
25166
|
+
if (!isRecord17(value))
|
|
24910
25167
|
return null;
|
|
24911
25168
|
const inputTokens = optionalToken(value.inputTokens);
|
|
24912
25169
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -24930,7 +25187,7 @@ function usageFromNative(value) {
|
|
|
24930
25187
|
}
|
|
24931
25188
|
}
|
|
24932
25189
|
function usageFromResponse(value) {
|
|
24933
|
-
if (!
|
|
25190
|
+
if (!isRecord17(value))
|
|
24934
25191
|
return null;
|
|
24935
25192
|
const buckets = [
|
|
24936
25193
|
value.input_tokens,
|
|
@@ -24959,10 +25216,10 @@ var GrokTurnUsage = class {
|
|
|
24959
25216
|
#durationMs = 0;
|
|
24960
25217
|
#latestCacheHit;
|
|
24961
25218
|
constructor(base, emptySession = false) {
|
|
24962
|
-
for (const
|
|
24963
|
-
const value = base?.[
|
|
25219
|
+
for (const field2 of summedUsageFields) {
|
|
25220
|
+
const value = base?.[field2];
|
|
24964
25221
|
if (value !== void 0)
|
|
24965
|
-
this.#totals[
|
|
25222
|
+
this.#totals[field2] = value;
|
|
24966
25223
|
}
|
|
24967
25224
|
this.#cacheComplete = base?.sessionCacheUsage !== void 0 || emptySession;
|
|
24968
25225
|
}
|
|
@@ -25001,10 +25258,10 @@ var GrokTurnUsage = class {
|
|
|
25001
25258
|
if (usage?.inputTokens === void 0 || usage.cachedInputTokens === void 0)
|
|
25002
25259
|
this.#cacheComplete = false;
|
|
25003
25260
|
if (usage) {
|
|
25004
|
-
for (const
|
|
25005
|
-
const value = usage[
|
|
25261
|
+
for (const field2 of summedUsageFields) {
|
|
25262
|
+
const value = usage[field2];
|
|
25006
25263
|
if (value !== void 0)
|
|
25007
|
-
this.#totals[
|
|
25264
|
+
this.#totals[field2] = (this.#totals[field2] ?? 0) + value;
|
|
25008
25265
|
}
|
|
25009
25266
|
if (duration3 > 0 && usage.outputTokens !== void 0) {
|
|
25010
25267
|
this.#outputTokens += usage.outputTokens;
|
|
@@ -25030,7 +25287,7 @@ var GrokTurnUsage = class {
|
|
|
25030
25287
|
}
|
|
25031
25288
|
};
|
|
25032
25289
|
function usageFromSignals(value) {
|
|
25033
|
-
if (!
|
|
25290
|
+
if (!isRecord17(value))
|
|
25034
25291
|
return null;
|
|
25035
25292
|
try {
|
|
25036
25293
|
return parseHostUsage({
|
|
@@ -25050,7 +25307,7 @@ var summedUsageFields = [
|
|
|
25050
25307
|
"totalTokens"
|
|
25051
25308
|
];
|
|
25052
25309
|
function nativeCostTicks(value) {
|
|
25053
|
-
if (!
|
|
25310
|
+
if (!isRecord17(value))
|
|
25054
25311
|
return void 0;
|
|
25055
25312
|
const ticks = value.costUsdTicks;
|
|
25056
25313
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -25058,7 +25315,7 @@ function nativeCostTicks(value) {
|
|
|
25058
25315
|
return ticks;
|
|
25059
25316
|
}
|
|
25060
25317
|
function sessionCostFromNative(value, initialCostUsd) {
|
|
25061
|
-
if (!
|
|
25318
|
+
if (!isRecord17(value))
|
|
25062
25319
|
return void 0;
|
|
25063
25320
|
if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
|
|
25064
25321
|
return void 0;
|
|
@@ -25087,7 +25344,7 @@ function sessionUsageFromHistory(events) {
|
|
|
25087
25344
|
continue;
|
|
25088
25345
|
const usage = usageFromNative(event.usage);
|
|
25089
25346
|
const ticks2 = nativeCostTicks(event.usage);
|
|
25090
|
-
const complete =
|
|
25347
|
+
const complete = isRecord17(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && usage.cachedInputTokens <= usage.inputTokens;
|
|
25091
25348
|
latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
|
|
25092
25349
|
}
|
|
25093
25350
|
if (latestByKey.size === 0)
|
|
@@ -25098,11 +25355,11 @@ function sessionUsageFromHistory(events) {
|
|
|
25098
25355
|
for (const entry of latestByKey.values()) {
|
|
25099
25356
|
if (!entry.usage)
|
|
25100
25357
|
continue;
|
|
25101
|
-
for (const
|
|
25102
|
-
const value = entry.usage[
|
|
25358
|
+
for (const field2 of summedUsageFields) {
|
|
25359
|
+
const value = entry.usage[field2];
|
|
25103
25360
|
if (value === void 0)
|
|
25104
25361
|
continue;
|
|
25105
|
-
totals2[
|
|
25362
|
+
totals2[field2] = (totals2[field2] ?? 0) + value;
|
|
25106
25363
|
}
|
|
25107
25364
|
if (entry.ticks === void 0)
|
|
25108
25365
|
continue;
|
|
@@ -25141,7 +25398,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
25141
25398
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
25142
25399
|
try {
|
|
25143
25400
|
if (update?.sessionUpdate === "usage_update") {
|
|
25144
|
-
const cost =
|
|
25401
|
+
const cost = isRecord17(update.cost) ? update.cost : null;
|
|
25145
25402
|
return parseHostUsage({
|
|
25146
25403
|
contextUsedTokens: update.used,
|
|
25147
25404
|
contextWindowTokens: update.size,
|
|
@@ -25379,6 +25636,7 @@ var GrokHarnessSession = class {
|
|
|
25379
25636
|
});
|
|
25380
25637
|
const active = {
|
|
25381
25638
|
command,
|
|
25639
|
+
questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
25382
25640
|
usage: new GrokTurnUsage(this.#usage, this.#snapshot.turns.length === 0),
|
|
25383
25641
|
agent: null,
|
|
25384
25642
|
agentMessageId: null,
|
|
@@ -25400,7 +25658,7 @@ var GrokHarnessSession = class {
|
|
|
25400
25658
|
};
|
|
25401
25659
|
this.#active = active;
|
|
25402
25660
|
this.#event({ type: "turn.started", turnId: command.turnId });
|
|
25403
|
-
void this.#transport.runTurn(text, (event) => this.#handleEvent(active, event), (request) => this.#requestPermission(active, request)).then((response) => this.#settleFromHistory(active, terminalOutcome2(response, active.cancellationRequested), response), (error53) => this.#settleFromHistory(active, {
|
|
25661
|
+
void this.#transport.runTurn(text, (event) => this.#handleEvent(active, event), (request) => this.#requestPermission(active, request), (request) => this.#active === active && this.#phase === "open" && !active.cancellationRequested ? active.questions.ask(request) : Promise.resolve({ outcome: "cancelled" })).finally(() => active.questions.cancel()).then((response) => this.#settleFromHistory(active, terminalOutcome2(response, active.cancellationRequested), response), (error53) => this.#settleFromHistory(active, {
|
|
25404
25662
|
status: "failed",
|
|
25405
25663
|
error: normalizeError(error53, "nativeFailure")
|
|
25406
25664
|
}));
|
|
@@ -25469,6 +25727,7 @@ var GrokHarnessSession = class {
|
|
|
25469
25727
|
});
|
|
25470
25728
|
const active = {
|
|
25471
25729
|
command: { type: "turn.start", turnId: command.turnId, input: [] },
|
|
25730
|
+
questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
25472
25731
|
agent: null,
|
|
25473
25732
|
agentMessageId: null,
|
|
25474
25733
|
rawAgentText: "",
|
|
@@ -25648,6 +25907,7 @@ var GrokHarnessSession = class {
|
|
|
25648
25907
|
if (active.cancellationRequested)
|
|
25649
25908
|
return { ok: true, value: { cancellationRequested: true } };
|
|
25650
25909
|
active.cancellationRequested = true;
|
|
25910
|
+
active.questions.cancel();
|
|
25651
25911
|
for (const approval of active.approvals.values()) {
|
|
25652
25912
|
approval.resolve({ outcome: { outcome: "cancelled" } });
|
|
25653
25913
|
}
|
|
@@ -25660,9 +25920,11 @@ var GrokHarnessSession = class {
|
|
|
25660
25920
|
}
|
|
25661
25921
|
async #respond(command) {
|
|
25662
25922
|
const active = this.#active;
|
|
25923
|
+
if (active?.questions.has(command.interactionId))
|
|
25924
|
+
return active.questions.respond(command);
|
|
25663
25925
|
const pending = active?.approvals.get(command.interactionId);
|
|
25664
25926
|
if (!active || !pending)
|
|
25665
|
-
return { ok: false, error: invalidState("Grok
|
|
25927
|
+
return { ok: false, error: invalidState("Grok Interaction is not pending") };
|
|
25666
25928
|
if (command.response.type !== "approval") {
|
|
25667
25929
|
return {
|
|
25668
25930
|
ok: false,
|
|
@@ -25723,6 +25985,10 @@ var GrokHarnessSession = class {
|
|
|
25723
25985
|
#handleEvent(active, event) {
|
|
25724
25986
|
if (this.#active !== active || this.#phase !== "open")
|
|
25725
25987
|
return;
|
|
25988
|
+
if (event.type === "interaction.resolved") {
|
|
25989
|
+
active.questions.withdraw(event.toolCallId);
|
|
25990
|
+
return;
|
|
25991
|
+
}
|
|
25726
25992
|
const requestUsage = active.usage?.observe(event);
|
|
25727
25993
|
if (requestUsage) {
|
|
25728
25994
|
this.#publishUsage(requestUsage, active.command.turnId, true);
|
|
@@ -26122,6 +26388,7 @@ var GrokHarnessSession = class {
|
|
|
26122
26388
|
#finish(active, outcome, usage = null, nativeTurnRef) {
|
|
26123
26389
|
if (this.#active !== active)
|
|
26124
26390
|
return;
|
|
26391
|
+
active.questions.cancel();
|
|
26125
26392
|
const itemOutcome = outcome;
|
|
26126
26393
|
this.#completeReasoning(active, itemOutcome);
|
|
26127
26394
|
this.#completeAgent(active, itemOutcome);
|
|
@@ -26178,6 +26445,7 @@ var GrokHarnessSession = class {
|
|
|
26178
26445
|
const active = this.#active;
|
|
26179
26446
|
if (active) {
|
|
26180
26447
|
active.cancellationRequested = true;
|
|
26448
|
+
active.questions.cancel();
|
|
26181
26449
|
for (const approval of active.approvals.values())
|
|
26182
26450
|
approval.resolve({ outcome: { outcome: "cancelled" } });
|
|
26183
26451
|
await this.#transport.cancel().catch(() => void 0);
|