@liberseek/boft-cli-win32-arm64 0.8.4 → 0.8.5
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 +59 -8
- package/app/console-web.js +278 -63
- package/app/desktop-controller.mjs +641 -33
- package/app/host-runtime.mjs +1811 -685
- package/app/plugins/antigravity/plugin.mjs +346 -54
- package/app/plugins/claude-code/plugin.mjs +391 -259
- package/app/plugins/codebuddy/plugin.mjs +231 -134
- package/app/plugins/codex-usage/plugin.mjs +82 -32
- package/app/plugins/copilot/plugin.mjs +107 -57
- package/app/plugins/cursor-cli/plugin.mjs +193 -131
- package/app/plugins/deepseek-harness/plugin.mjs +112 -42
- package/app/plugins/grok/plugin.mjs +371 -115
- package/app/plugins/hermes/plugin.mjs +54 -4
- package/app/plugins/kimi-code/plugin.mjs +69 -19
- package/app/plugins/kiro-cli/plugin.mjs +69 -19
- package/app/plugins/muse/plugin.mjs +59 -9
- package/app/plugins/omp/plugin.mjs +89 -39
- package/app/plugins/opencode/plugin.mjs +111 -61
- package/app/plugins/pi/plugin.mjs +185 -68
- package/app/plugins/qoder/plugin.mjs +79 -29
- package/app/plugins/qoder-cn/plugin.mjs +79 -29
- package/app/plugins/workbuddy/plugin.mjs +231 -134
- package/app/plugins/zcode/plugin.mjs +108 -33
- package/app/renderer-extension.js +2634 -329
- package/bin/boft.exe +0 -0
- package/libexec/boft-node-repl.exe +0 -0
- package/libexec/boft-shim.exe +0 -0
- package/libexec/boft-updater.exe +0 -0
- package/package.json +1 -1
|
@@ -3686,10 +3686,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
3686
3686
|
const shape = def.shape;
|
|
3687
3687
|
const propValues = {};
|
|
3688
3688
|
for (const key in shape) {
|
|
3689
|
-
const
|
|
3690
|
-
if (
|
|
3689
|
+
const field2 = shape[key]._zod;
|
|
3690
|
+
if (field2.values) {
|
|
3691
3691
|
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
3692
|
-
for (const v of
|
|
3692
|
+
for (const v of field2.values)
|
|
3693
3693
|
propValues[key].add(v);
|
|
3694
3694
|
}
|
|
3695
3695
|
}
|
|
@@ -19438,6 +19438,8 @@ var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
|
19438
19438
|
cachedInputTokens: count2,
|
|
19439
19439
|
cacheWriteInputTokens: count2,
|
|
19440
19440
|
cacheKnownInputTokens: count2,
|
|
19441
|
+
cacheHitCachedInputTokens: count2,
|
|
19442
|
+
cacheHitInputTokens: count2,
|
|
19441
19443
|
outputTokens: count2,
|
|
19442
19444
|
reasoningOutputTokens: count2,
|
|
19443
19445
|
/** USD at the public price, summed over the priced requests only. */
|
|
@@ -19545,6 +19547,51 @@ var hostInteractionIdSchema = opaqueIdSchema.brand();
|
|
|
19545
19547
|
var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
|
|
19546
19548
|
var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
|
|
19547
19549
|
|
|
19550
|
+
// ../../shared-contracts/dist/thread-questions.js
|
|
19551
|
+
var field = external_exports.discriminatedUnion("type", [
|
|
19552
|
+
external_exports.object({
|
|
19553
|
+
id: external_exports.string().min(1),
|
|
19554
|
+
type: external_exports.literal("choice"),
|
|
19555
|
+
prompt: external_exports.string(),
|
|
19556
|
+
options: external_exports.array(external_exports.object({
|
|
19557
|
+
value: external_exports.string().min(1),
|
|
19558
|
+
label: external_exports.string(),
|
|
19559
|
+
description: external_exports.string().optional()
|
|
19560
|
+
})).min(1),
|
|
19561
|
+
multiple: external_exports.boolean(),
|
|
19562
|
+
allowOther: external_exports.boolean(),
|
|
19563
|
+
optional: external_exports.boolean()
|
|
19564
|
+
}),
|
|
19565
|
+
external_exports.object({
|
|
19566
|
+
id: external_exports.string().min(1),
|
|
19567
|
+
type: external_exports.literal("text"),
|
|
19568
|
+
prompt: external_exports.string(),
|
|
19569
|
+
multiline: external_exports.boolean(),
|
|
19570
|
+
secret: external_exports.literal(false),
|
|
19571
|
+
optional: external_exports.boolean(),
|
|
19572
|
+
placeholder: external_exports.string().optional(),
|
|
19573
|
+
prefill: external_exports.string().optional()
|
|
19574
|
+
})
|
|
19575
|
+
]);
|
|
19576
|
+
var threadQuestionSchema = external_exports.object({
|
|
19577
|
+
interactionId: external_exports.string().min(1),
|
|
19578
|
+
turnId: external_exports.string().min(1),
|
|
19579
|
+
title: external_exports.string().optional(),
|
|
19580
|
+
questions: external_exports.array(field).min(1)
|
|
19581
|
+
}).refine(({ questions }) => questions.some((q) => q.type === "choice" && q.multiple), {
|
|
19582
|
+
message: "Shared cards require at least one multi-select question"
|
|
19583
|
+
});
|
|
19584
|
+
var threadQuestionsListParamsSchema = external_exports.strictObject({ threadId: external_exports.string().min(1) });
|
|
19585
|
+
var threadQuestionsResultSchema = external_exports.object({ questions: external_exports.array(threadQuestionSchema) });
|
|
19586
|
+
var threadQuestionRespondParamsSchema = external_exports.strictObject({
|
|
19587
|
+
threadId: external_exports.string().min(1),
|
|
19588
|
+
turnId: external_exports.string().min(1),
|
|
19589
|
+
interactionId: external_exports.string().min(1),
|
|
19590
|
+
answers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
|
|
19591
|
+
cancelled: external_exports.boolean().default(false)
|
|
19592
|
+
});
|
|
19593
|
+
var threadQuestionRespondResultSchema = external_exports.object({ accepted: external_exports.literal(true) });
|
|
19594
|
+
|
|
19548
19595
|
// ../../shared-contracts/dist/harness-plugins.js
|
|
19549
19596
|
var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
|
|
19550
19597
|
var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
|
|
@@ -20314,7 +20361,10 @@ var harnessPluginRouteSchema = external_exports.object({
|
|
|
20314
20361
|
harnessId: harnessPluginIdSchema,
|
|
20315
20362
|
model: harnessModelRefSchema.optional(),
|
|
20316
20363
|
thinkingOptionId: harnessThinkingOptionIdSchema.optional(),
|
|
20317
|
-
permissionModeId: harnessPermissionModeIdSchema.optional()
|
|
20364
|
+
permissionModeId: harnessPermissionModeIdSchema.optional(),
|
|
20365
|
+
/** A draft prewarm create: stays unsubmitted until the user's first Turn.
|
|
20366
|
+
* Desktop forwards only the Model of a main-process prewarm to thread/start. */
|
|
20367
|
+
prewarm: external_exports.literal(true).optional()
|
|
20318
20368
|
}).strict();
|
|
20319
20369
|
|
|
20320
20370
|
// ../../shared-contracts/dist/harness-launch-settings.js
|
|
@@ -20925,26 +20975,26 @@ function parseHostUsage(value) {
|
|
|
20925
20975
|
}
|
|
20926
20976
|
}
|
|
20927
20977
|
const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
|
|
20928
|
-
for (const
|
|
20978
|
+
for (const field2 of [
|
|
20929
20979
|
"totalCredits",
|
|
20930
20980
|
"contextUsagePercent",
|
|
20931
20981
|
"apiOutputTokensPerSecond"
|
|
20932
20982
|
]) {
|
|
20933
|
-
const candidate = value[
|
|
20983
|
+
const candidate = value[field2];
|
|
20934
20984
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
20935
|
-
throw new Error(`Harness Usage '${
|
|
20985
|
+
throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
|
|
20936
20986
|
}
|
|
20937
20987
|
}
|
|
20938
|
-
for (const
|
|
20939
|
-
const candidate = value[
|
|
20988
|
+
for (const field2 of tokenFields) {
|
|
20989
|
+
const candidate = value[field2];
|
|
20940
20990
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
20941
|
-
throw new Error(`Harness Usage '${
|
|
20991
|
+
throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
|
|
20942
20992
|
}
|
|
20943
20993
|
}
|
|
20944
|
-
for (const
|
|
20945
|
-
const candidate = value[
|
|
20994
|
+
for (const field2 of safeIntegerFields) {
|
|
20995
|
+
const candidate = value[field2];
|
|
20946
20996
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
20947
|
-
throw new Error(`Harness Usage '${
|
|
20997
|
+
throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
|
|
20948
20998
|
}
|
|
20949
20999
|
}
|
|
20950
21000
|
if (value.outputTokensPerSecond !== void 0 && (typeof value.outputTokensPerSecond !== "number" || !Number.isFinite(value.outputTokensPerSecond) || value.outputTokensPerSecond < 0)) {
|
|
@@ -20953,16 +21003,16 @@ function parseHostUsage(value) {
|
|
|
20953
21003
|
if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
|
|
20954
21004
|
throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
|
|
20955
21005
|
}
|
|
20956
|
-
for (const
|
|
20957
|
-
const candidate = value[
|
|
21006
|
+
for (const field2 of ["totalCredits", "contextUsagePercent"]) {
|
|
21007
|
+
const candidate = value[field2];
|
|
20958
21008
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
20959
|
-
throw new Error(`Harness Usage '${
|
|
21009
|
+
throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
|
|
20960
21010
|
}
|
|
20961
21011
|
}
|
|
20962
|
-
for (const
|
|
20963
|
-
const candidate = value[
|
|
21012
|
+
for (const field2 of percentFields) {
|
|
21013
|
+
const candidate = value[field2];
|
|
20964
21014
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
|
|
20965
|
-
throw new Error(`Harness Usage '${
|
|
21015
|
+
throw new Error(`Harness Usage '${field2}' must be between 0 and 100`);
|
|
20966
21016
|
}
|
|
20967
21017
|
}
|
|
20968
21018
|
if (value.sessionCacheUsage !== void 0) {
|
|
@@ -22026,10 +22076,10 @@ function stringField(value, key) {
|
|
|
22026
22076
|
function numberField(value, key) {
|
|
22027
22077
|
if (!isRecord6(value))
|
|
22028
22078
|
return void 0;
|
|
22029
|
-
const
|
|
22030
|
-
if (
|
|
22079
|
+
const field2 = value[key];
|
|
22080
|
+
if (field2 === null)
|
|
22031
22081
|
return null;
|
|
22032
|
-
return typeof
|
|
22082
|
+
return typeof field2 === "number" && Number.isFinite(field2) ? field2 : void 0;
|
|
22033
22083
|
}
|
|
22034
22084
|
function decodeBytes(value) {
|
|
22035
22085
|
if (!Array.isArray(value) || value.length === 0)
|
|
@@ -22228,13 +22278,13 @@ function isRecord7(value) {
|
|
|
22228
22278
|
function idField(value, key) {
|
|
22229
22279
|
if (!isRecord7(value))
|
|
22230
22280
|
return void 0;
|
|
22231
|
-
const
|
|
22232
|
-
if (typeof
|
|
22233
|
-
const trimmed =
|
|
22281
|
+
const field2 = value[key];
|
|
22282
|
+
if (typeof field2 === "string") {
|
|
22283
|
+
const trimmed = field2.trim();
|
|
22234
22284
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
22235
22285
|
}
|
|
22236
|
-
if (typeof
|
|
22237
|
-
return String(
|
|
22286
|
+
if (typeof field2 === "number" && Number.isFinite(field2))
|
|
22287
|
+
return String(field2);
|
|
22238
22288
|
return void 0;
|
|
22239
22289
|
}
|
|
22240
22290
|
function stringField2(value, key) {
|
|
@@ -23407,9 +23457,9 @@ function isRecord12(value) {
|
|
|
23407
23457
|
}
|
|
23408
23458
|
function stringField3(value, ...keys) {
|
|
23409
23459
|
for (const key of keys) {
|
|
23410
|
-
const
|
|
23411
|
-
if (typeof
|
|
23412
|
-
return
|
|
23460
|
+
const field2 = value[key];
|
|
23461
|
+
if (typeof field2 === "string" && field2.length > 0)
|
|
23462
|
+
return field2;
|
|
23413
23463
|
}
|
|
23414
23464
|
return void 0;
|
|
23415
23465
|
}
|
|
@@ -23493,17 +23543,17 @@ function isRecord13(value) {
|
|
|
23493
23543
|
}
|
|
23494
23544
|
function stringField4(value, ...keys) {
|
|
23495
23545
|
for (const key of keys) {
|
|
23496
|
-
const
|
|
23497
|
-
if (typeof
|
|
23498
|
-
return
|
|
23546
|
+
const field2 = value[key];
|
|
23547
|
+
if (typeof field2 === "string" && field2.length > 0)
|
|
23548
|
+
return field2;
|
|
23499
23549
|
}
|
|
23500
23550
|
return void 0;
|
|
23501
23551
|
}
|
|
23502
23552
|
function optionalTimeoutMs(value) {
|
|
23503
23553
|
for (const key of ["timeoutMs", "timeout_ms", "timeoutSecs", "timeout_secs"]) {
|
|
23504
|
-
const
|
|
23505
|
-
if (typeof
|
|
23506
|
-
return key.endsWith("secs") || key.endsWith("Secs") ?
|
|
23554
|
+
const field2 = value[key];
|
|
23555
|
+
if (typeof field2 === "number" && Number.isFinite(field2) && field2 > 0) {
|
|
23556
|
+
return key.endsWith("secs") || key.endsWith("Secs") ? field2 * 1e3 : field2;
|
|
23507
23557
|
}
|
|
23508
23558
|
}
|
|
23509
23559
|
return void 0;
|
|
@@ -23723,6 +23773,163 @@ var GrokPermissionConfirmation = class {
|
|
|
23723
23773
|
}
|
|
23724
23774
|
};
|
|
23725
23775
|
|
|
23776
|
+
// dist/grok-questions.js
|
|
23777
|
+
var GROK_ASK_USER_QUESTION_METHOD = "_x.ai/ask_user_question";
|
|
23778
|
+
function isRecord14(value) {
|
|
23779
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23780
|
+
}
|
|
23781
|
+
function nonEmptyString(value) {
|
|
23782
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
23783
|
+
}
|
|
23784
|
+
function parseGrokQuestionRequest(value) {
|
|
23785
|
+
if (!isRecord14(value) || !nonEmptyString(value.sessionId) || !nonEmptyString(value.toolCallId) || value.mode !== "default" && value.mode !== "plan" || !Array.isArray(value.questions) || value.questions.length === 0)
|
|
23786
|
+
throw new Error("Grok question requires sessionId, toolCallId, mode and nonempty questions");
|
|
23787
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23788
|
+
const questions = value.questions.map((question) => {
|
|
23789
|
+
if (!isRecord14(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")
|
|
23790
|
+
throw new Error("Grok question text must be unique and options/multiSelect must be valid");
|
|
23791
|
+
if (question.multiSelect != null && question.multi_select != null && question.multiSelect !== question.multi_select)
|
|
23792
|
+
throw new Error("Grok question contains conflicting multi-select flags");
|
|
23793
|
+
seen.add(question.question);
|
|
23794
|
+
const labels = /* @__PURE__ */ new Set();
|
|
23795
|
+
const options = question.options.map((option) => {
|
|
23796
|
+
if (!isRecord14(option) || !nonEmptyString(option.label) || labels.has(option.label) || typeof option.description !== "string" || option.preview != null && typeof option.preview !== "string")
|
|
23797
|
+
throw new Error("Grok question options require unique labels and text descriptions/previews");
|
|
23798
|
+
labels.add(option.label);
|
|
23799
|
+
return {
|
|
23800
|
+
label: option.label,
|
|
23801
|
+
description: option.description,
|
|
23802
|
+
...typeof option.preview === "string" ? { preview: option.preview } : {}
|
|
23803
|
+
};
|
|
23804
|
+
});
|
|
23805
|
+
return {
|
|
23806
|
+
question: question.question,
|
|
23807
|
+
options,
|
|
23808
|
+
multiple: question.multiSelect === true || question.multi_select === true
|
|
23809
|
+
};
|
|
23810
|
+
});
|
|
23811
|
+
return { sessionId: value.sessionId, toolCallId: value.toolCallId, mode: value.mode, questions };
|
|
23812
|
+
}
|
|
23813
|
+
var GrokQuestions = class {
|
|
23814
|
+
turnId;
|
|
23815
|
+
randomUUID;
|
|
23816
|
+
emit;
|
|
23817
|
+
#pending = /* @__PURE__ */ new Map();
|
|
23818
|
+
#seenToolCalls = /* @__PURE__ */ new Set();
|
|
23819
|
+
#closed = false;
|
|
23820
|
+
constructor(turnId, randomUUID2, emit) {
|
|
23821
|
+
this.turnId = turnId;
|
|
23822
|
+
this.randomUUID = randomUUID2;
|
|
23823
|
+
this.emit = emit;
|
|
23824
|
+
}
|
|
23825
|
+
has(interactionId) {
|
|
23826
|
+
return this.#pending.has(interactionId);
|
|
23827
|
+
}
|
|
23828
|
+
ask(request) {
|
|
23829
|
+
if (this.#closed || this.#seenToolCalls.has(request.toolCallId))
|
|
23830
|
+
return Promise.resolve({ outcome: "cancelled" });
|
|
23831
|
+
this.#seenToolCalls.add(request.toolCallId);
|
|
23832
|
+
const interaction = {
|
|
23833
|
+
type: "question",
|
|
23834
|
+
interactionId: hostInteractionIdSchema.parse(this.randomUUID()),
|
|
23835
|
+
turnId: this.turnId,
|
|
23836
|
+
title: "Grok",
|
|
23837
|
+
questions: request.questions.map((question, index) => question.options.length ? {
|
|
23838
|
+
id: `q${index}`,
|
|
23839
|
+
type: "choice",
|
|
23840
|
+
prompt: question.question,
|
|
23841
|
+
options: question.options.map(({ label, description, preview }) => ({
|
|
23842
|
+
value: label,
|
|
23843
|
+
label,
|
|
23844
|
+
description: [description, preview].filter(Boolean).join("\n\n")
|
|
23845
|
+
})),
|
|
23846
|
+
multiple: question.multiple,
|
|
23847
|
+
allowOther: true,
|
|
23848
|
+
optional: true
|
|
23849
|
+
} : {
|
|
23850
|
+
id: `q${index}`,
|
|
23851
|
+
type: "text",
|
|
23852
|
+
prompt: question.question,
|
|
23853
|
+
multiline: true,
|
|
23854
|
+
secret: false,
|
|
23855
|
+
optional: true
|
|
23856
|
+
})
|
|
23857
|
+
};
|
|
23858
|
+
return new Promise((resolve) => {
|
|
23859
|
+
this.#pending.set(interaction.interactionId, { request, interaction, resolve });
|
|
23860
|
+
this.emit({ kind: "interaction", interaction });
|
|
23861
|
+
});
|
|
23862
|
+
}
|
|
23863
|
+
respond(command) {
|
|
23864
|
+
const pending = this.#pending.get(command.interactionId);
|
|
23865
|
+
if (!pending)
|
|
23866
|
+
return this.#error("invalidState", "Grok Question is not pending");
|
|
23867
|
+
if (command.response.type !== "question")
|
|
23868
|
+
return this.#error("invalidRequest", "Grok Question requires a Question Response");
|
|
23869
|
+
const response = command.response;
|
|
23870
|
+
const error53 = validateHostQuestionResponse(pending.interaction, response);
|
|
23871
|
+
if (error53)
|
|
23872
|
+
return { ok: false, error: error53 };
|
|
23873
|
+
if (response.cancelled) {
|
|
23874
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
23875
|
+
return { ok: true, value: { accepted: true } };
|
|
23876
|
+
}
|
|
23877
|
+
const answers = /* @__PURE__ */ new Map();
|
|
23878
|
+
const annotations = /* @__PURE__ */ new Map();
|
|
23879
|
+
for (const [index, question] of pending.request.questions.entries()) {
|
|
23880
|
+
const values = response.answers[`q${index}`];
|
|
23881
|
+
if (!values?.length)
|
|
23882
|
+
continue;
|
|
23883
|
+
if (values.some((answer) => !nonEmptyString(answer)) || new Set(values).size !== values.length)
|
|
23884
|
+
return this.#error("invalidRequest", "Grok answers must be nonempty and unique");
|
|
23885
|
+
const selected = values.map((answer) => question.options.find(({ label }) => label === answer));
|
|
23886
|
+
const other = values.filter((_, position) => !selected[position]);
|
|
23887
|
+
if (other.length > 1)
|
|
23888
|
+
return this.#error("invalidRequest", "Grok question accepts only one Other response");
|
|
23889
|
+
answers.set(question.question, selected.map((option) => option?.label ?? "Other"));
|
|
23890
|
+
const previews = selected.flatMap((option) => option?.preview !== void 0 ? [option.preview] : []);
|
|
23891
|
+
if (previews.length || other.length)
|
|
23892
|
+
annotations.set(question.question, {
|
|
23893
|
+
...previews.length ? { preview: previews.join("\n\n") } : {},
|
|
23894
|
+
...other.length ? { notes: other[0] } : {}
|
|
23895
|
+
});
|
|
23896
|
+
}
|
|
23897
|
+
this.#settle(pending, {
|
|
23898
|
+
outcome: "accepted",
|
|
23899
|
+
answers: Object.fromEntries(answers),
|
|
23900
|
+
...annotations.size ? { annotations: Object.fromEntries(annotations) } : {}
|
|
23901
|
+
}, "responded");
|
|
23902
|
+
return { ok: true, value: { accepted: true } };
|
|
23903
|
+
}
|
|
23904
|
+
withdraw(toolCallId) {
|
|
23905
|
+
for (const pending of this.#pending.values()) {
|
|
23906
|
+
if (pending.request.toolCallId === toolCallId)
|
|
23907
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
23908
|
+
}
|
|
23909
|
+
}
|
|
23910
|
+
cancel() {
|
|
23911
|
+
this.#closed = true;
|
|
23912
|
+
for (const pending of this.#pending.values())
|
|
23913
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
23914
|
+
}
|
|
23915
|
+
#settle(pending, response, reason) {
|
|
23916
|
+
this.#pending.delete(pending.interaction.interactionId);
|
|
23917
|
+
pending.resolve(response);
|
|
23918
|
+
this.emit({
|
|
23919
|
+
kind: "event",
|
|
23920
|
+
event: {
|
|
23921
|
+
type: "interaction.closed",
|
|
23922
|
+
interactionId: pending.interaction.interactionId,
|
|
23923
|
+
turnId: this.turnId,
|
|
23924
|
+
reason
|
|
23925
|
+
}
|
|
23926
|
+
});
|
|
23927
|
+
}
|
|
23928
|
+
#error(code, message) {
|
|
23929
|
+
return { ok: false, error: { code, message, retryable: false } };
|
|
23930
|
+
}
|
|
23931
|
+
};
|
|
23932
|
+
|
|
23726
23933
|
// dist/acp-transport.js
|
|
23727
23934
|
var GrokTransportError = class extends Error {
|
|
23728
23935
|
kind;
|
|
@@ -23734,16 +23941,16 @@ var GrokTransportError = class extends Error {
|
|
|
23734
23941
|
this.name = "GrokTransportError";
|
|
23735
23942
|
}
|
|
23736
23943
|
};
|
|
23737
|
-
function
|
|
23944
|
+
function isRecord15(value) {
|
|
23738
23945
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23739
23946
|
}
|
|
23740
23947
|
function acpToolName(update, metadata) {
|
|
23741
|
-
if (!
|
|
23948
|
+
if (!isRecord15(update))
|
|
23742
23949
|
return void 0;
|
|
23743
23950
|
if (typeof update.name === "string" && update.name.length > 0)
|
|
23744
23951
|
return update.name;
|
|
23745
|
-
const meta3 =
|
|
23746
|
-
const tool = meta3 &&
|
|
23952
|
+
const meta3 = isRecord15(update._meta) ? update._meta : metadata;
|
|
23953
|
+
const tool = meta3 && isRecord15(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
23747
23954
|
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
23748
23955
|
}
|
|
23749
23956
|
function errorText(error53) {
|
|
@@ -23799,7 +24006,7 @@ function signalProcessTree(child, signal) {
|
|
|
23799
24006
|
try {
|
|
23800
24007
|
process.kill(-child.pid, signal);
|
|
23801
24008
|
} catch (error53) {
|
|
23802
|
-
if (!
|
|
24009
|
+
if (!isRecord15(error53) || error53.code !== "ESRCH")
|
|
23803
24010
|
throw error53;
|
|
23804
24011
|
}
|
|
23805
24012
|
}
|
|
@@ -23842,6 +24049,10 @@ function transportEvent(update, metadata) {
|
|
|
23842
24049
|
const subagent = grokSubagentEventFromUpdate(extension);
|
|
23843
24050
|
if (subagent)
|
|
23844
24051
|
return subagent;
|
|
24052
|
+
if (extension.sessionUpdate === "interaction_resolved") {
|
|
24053
|
+
const toolCallId = extension.tool_call_id ?? extension.toolCallId;
|
|
24054
|
+
return typeof toolCallId === "string" && toolCallId.trim().length > 0 ? { type: "interaction.resolved", toolCallId, ...metadata ? { metadata } : {} } : null;
|
|
24055
|
+
}
|
|
23845
24056
|
switch (update.sessionUpdate) {
|
|
23846
24057
|
case "user_message_chunk":
|
|
23847
24058
|
case "agent_message_chunk":
|
|
@@ -23909,7 +24120,7 @@ async function readNativeSignals(options, sessionId) {
|
|
|
23909
24120
|
}
|
|
23910
24121
|
}
|
|
23911
24122
|
function isMissingFile(error53) {
|
|
23912
|
-
return
|
|
24123
|
+
return isRecord15(error53) && error53.code === "ENOENT";
|
|
23913
24124
|
}
|
|
23914
24125
|
async function locateGrokNativeSession(options, sessionId) {
|
|
23915
24126
|
if (sessionId.length === 0)
|
|
@@ -23932,7 +24143,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23932
24143
|
try {
|
|
23933
24144
|
summaryRaw = await readFile3(path12.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
23934
24145
|
} catch (error53) {
|
|
23935
|
-
if (isMissingFile(error53) ||
|
|
24146
|
+
if (isMissingFile(error53) || isRecord15(error53) && error53.code === "ENOTDIR")
|
|
23936
24147
|
continue;
|
|
23937
24148
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
23938
24149
|
cause: error53
|
|
@@ -23944,10 +24155,10 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23944
24155
|
} catch {
|
|
23945
24156
|
continue;
|
|
23946
24157
|
}
|
|
23947
|
-
if (!
|
|
24158
|
+
if (!isRecord15(parsed))
|
|
23948
24159
|
continue;
|
|
23949
24160
|
const info = parsed.info;
|
|
23950
|
-
const cwd =
|
|
24161
|
+
const cwd = isRecord15(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path12.resolve(info.cwd) : path12.resolve(decodeURIComponent(entry.name));
|
|
23951
24162
|
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path12.resolve(parsed.source_workspace_dir) : void 0;
|
|
23952
24163
|
matches.push({
|
|
23953
24164
|
cwd,
|
|
@@ -23980,12 +24191,12 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
23980
24191
|
} catch {
|
|
23981
24192
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
23982
24193
|
}
|
|
23983
|
-
if (!
|
|
24194
|
+
if (!isRecord15(record2) || !isRecord15(record2.params))
|
|
23984
24195
|
continue;
|
|
23985
24196
|
const params = record2.params;
|
|
23986
|
-
if (params.sessionId !== sessionId || !
|
|
24197
|
+
if (params.sessionId !== sessionId || !isRecord15(params.update))
|
|
23987
24198
|
continue;
|
|
23988
|
-
const metadata =
|
|
24199
|
+
const metadata = isRecord15(params._meta) ? params._meta : void 0;
|
|
23989
24200
|
const event = transportEvent(params.update, metadata);
|
|
23990
24201
|
if (event)
|
|
23991
24202
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -24049,7 +24260,7 @@ var GrokAcpTransport = class {
|
|
|
24049
24260
|
if (!this.#connection)
|
|
24050
24261
|
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
24051
24262
|
const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
|
|
24052
|
-
return
|
|
24263
|
+
return isRecord15(result) ? result.usage : void 0;
|
|
24053
24264
|
}
|
|
24054
24265
|
async readHistory(sessionId, cwd = this.#options.cwd) {
|
|
24055
24266
|
return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
|
|
@@ -24244,7 +24455,7 @@ var GrokAcpTransport = class {
|
|
|
24244
24455
|
this.#initialize = initialize;
|
|
24245
24456
|
return initialize;
|
|
24246
24457
|
}
|
|
24247
|
-
async runTurn(text, onEvent, onPermission, onExtension) {
|
|
24458
|
+
async runTurn(text, onEvent, onPermission, onQuestion, onExtension = async ({ method }) => isGrokExitPlanModeMethod(method) ? grokPlanRejectedResponse() : grokSkipInterviewResponse()) {
|
|
24248
24459
|
const connection = this.#connection;
|
|
24249
24460
|
if (!connection || !this.#sessionId || this.#closed || this.#closing) {
|
|
24250
24461
|
throw new GrokTransportError("unavailable", "Grok ACP Session is unavailable");
|
|
@@ -24253,7 +24464,7 @@ var GrokAcpTransport = class {
|
|
|
24253
24464
|
throw new Error("Grok ACP Session already has an active Prompt");
|
|
24254
24465
|
if (this.#permissionConfirmation)
|
|
24255
24466
|
throw new GrokTransportError("unavailable", "Grok ACP Session has an active operation");
|
|
24256
|
-
const active = { onEvent, onPermission, onExtension };
|
|
24467
|
+
const active = { onEvent, onPermission, onExtension, onQuestion };
|
|
24257
24468
|
this.#activePrompt = active;
|
|
24258
24469
|
try {
|
|
24259
24470
|
return await connection.prompt({
|
|
@@ -24312,7 +24523,7 @@ var GrokAcpTransport = class {
|
|
|
24312
24523
|
...reasoningEffort ? { reasoningEffort } : {},
|
|
24313
24524
|
...contextWindowTokens !== void 0 ? { _meta: { contextWindow: contextWindowTokens } } : {}
|
|
24314
24525
|
});
|
|
24315
|
-
if (!
|
|
24526
|
+
if (!isRecord15(response) || !isRecord15(response._meta) || !isRecord15(response._meta.model)) {
|
|
24316
24527
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
24317
24528
|
}
|
|
24318
24529
|
const selected = response._meta.model.Ok;
|
|
@@ -24352,7 +24563,7 @@ var GrokAcpTransport = class {
|
|
|
24352
24563
|
permission_mode: mode
|
|
24353
24564
|
});
|
|
24354
24565
|
const response = await connection.request("_x.ai/session/info", { sessionId });
|
|
24355
|
-
if (!
|
|
24566
|
+
if (!isRecord15(response) || !isRecord15(response.result) || response.result.sessionId !== sessionId) {
|
|
24356
24567
|
throw new Error("Grok did not confirm the target Session");
|
|
24357
24568
|
}
|
|
24358
24569
|
})()
|
|
@@ -24407,7 +24618,7 @@ var GrokAcpTransport = class {
|
|
|
24407
24618
|
this.#availableCommands = parseGrokAvailableCommands(update.availableCommands);
|
|
24408
24619
|
return;
|
|
24409
24620
|
}
|
|
24410
|
-
const metadata =
|
|
24621
|
+
const metadata = isRecord15(notification._meta) ? notification._meta : void 0;
|
|
24411
24622
|
const event = transportEvent(notification.update, metadata);
|
|
24412
24623
|
if (!event)
|
|
24413
24624
|
return;
|
|
@@ -24422,7 +24633,7 @@ var GrokAcpTransport = class {
|
|
|
24422
24633
|
#handleExtensionNotification(method, params) {
|
|
24423
24634
|
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
24424
24635
|
return;
|
|
24425
|
-
if (typeof params.sessionId !== "string" || !
|
|
24636
|
+
if (typeof params.sessionId !== "string" || !isRecord15(params.update))
|
|
24426
24637
|
return;
|
|
24427
24638
|
this.#handleUpdate(params);
|
|
24428
24639
|
}
|
|
@@ -24432,8 +24643,34 @@ var GrokAcpTransport = class {
|
|
|
24432
24643
|
}
|
|
24433
24644
|
return this.#activePrompt.onPermission({ request: params, options: params.options });
|
|
24434
24645
|
}
|
|
24435
|
-
#handleExtensionRequest(method, params) {
|
|
24436
|
-
if (
|
|
24646
|
+
async #handleExtensionRequest(method, params) {
|
|
24647
|
+
if (method === GROK_ASK_USER_QUESTION_METHOD) {
|
|
24648
|
+
const active = this.#activePrompt;
|
|
24649
|
+
let request = null;
|
|
24650
|
+
let parseError;
|
|
24651
|
+
try {
|
|
24652
|
+
request = parseGrokQuestionRequest(params);
|
|
24653
|
+
} catch (error53) {
|
|
24654
|
+
parseError = error53;
|
|
24655
|
+
}
|
|
24656
|
+
if (request) {
|
|
24657
|
+
if (!active || this.#closed || this.#closing || this.#replay !== null || this.#activeCompact !== null || request.sessionId !== this.#sessionId)
|
|
24658
|
+
return { outcome: "cancelled" };
|
|
24659
|
+
return { ...await active.onQuestion(request) };
|
|
24660
|
+
}
|
|
24661
|
+
if (!isRecord15(params) || "toolCallId" in params && "mode" in params) {
|
|
24662
|
+
throw RequestError.invalidParams(void 0, errorText(parseError));
|
|
24663
|
+
}
|
|
24664
|
+
const legacy = parseGrokAskUserQuestionParams(params);
|
|
24665
|
+
if (!legacy)
|
|
24666
|
+
throw RequestError.invalidParams(params, "Grok Question is invalid");
|
|
24667
|
+
if (legacy.sessionId && legacy.sessionId !== this.#sessionId)
|
|
24668
|
+
return { outcome: "cancelled" };
|
|
24669
|
+
if (active && !this.#closed && !this.#closing && this.#replay === null)
|
|
24670
|
+
return active.onExtension({ method, params });
|
|
24671
|
+
return grokSkipInterviewResponse();
|
|
24672
|
+
}
|
|
24673
|
+
if (this.#activePrompt && (isGrokAskUserQuestionMethod(method) || isGrokExitPlanModeMethod(method))) {
|
|
24437
24674
|
return this.#activePrompt.onExtension({ method, params });
|
|
24438
24675
|
}
|
|
24439
24676
|
if (isGrokAskUserQuestionMethod(method))
|
|
@@ -24574,7 +24811,7 @@ var SessionImportScope = class {
|
|
|
24574
24811
|
// dist/session-import.js
|
|
24575
24812
|
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
24576
24813
|
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
24577
|
-
function
|
|
24814
|
+
function isRecord16(value) {
|
|
24578
24815
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24579
24816
|
}
|
|
24580
24817
|
async function readJson(file2, signal) {
|
|
@@ -24587,7 +24824,7 @@ function processAlive(pid) {
|
|
|
24587
24824
|
process.kill(pid, 0);
|
|
24588
24825
|
return true;
|
|
24589
24826
|
} catch (error53) {
|
|
24590
|
-
return
|
|
24827
|
+
return isRecord16(error53) && error53.code === "EPERM";
|
|
24591
24828
|
}
|
|
24592
24829
|
}
|
|
24593
24830
|
async function firstUserText(file2, signal) {
|
|
@@ -24604,10 +24841,10 @@ async function firstUserText(file2, signal) {
|
|
|
24604
24841
|
} catch {
|
|
24605
24842
|
continue;
|
|
24606
24843
|
}
|
|
24607
|
-
const update =
|
|
24608
|
-
if (!
|
|
24844
|
+
const update = isRecord16(entry) && isRecord16(entry.params) ? entry.params.update : null;
|
|
24845
|
+
if (!isRecord16(update) || update.sessionUpdate !== "user_message_chunk")
|
|
24609
24846
|
continue;
|
|
24610
|
-
const text =
|
|
24847
|
+
const text = isRecord16(update.content) ? update.content.text : null;
|
|
24611
24848
|
return typeof text === "string" ? text : "";
|
|
24612
24849
|
}
|
|
24613
24850
|
return null;
|
|
@@ -24684,7 +24921,7 @@ var GrokSessionImport = class {
|
|
|
24684
24921
|
if (!Array.isArray(entries))
|
|
24685
24922
|
return active;
|
|
24686
24923
|
for (const entry of entries) {
|
|
24687
|
-
if (
|
|
24924
|
+
if (isRecord16(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
24688
24925
|
active.add(entry.session_id);
|
|
24689
24926
|
}
|
|
24690
24927
|
return active;
|
|
@@ -24733,7 +24970,7 @@ var GrokSessionImport = class {
|
|
|
24733
24970
|
return null;
|
|
24734
24971
|
try {
|
|
24735
24972
|
const summary = await readJson(files[0], signal);
|
|
24736
|
-
if (!
|
|
24973
|
+
if (!isRecord16(summary) || !isRecord16(summary.info) || summary.info.id !== nativeSessionId)
|
|
24737
24974
|
return null;
|
|
24738
24975
|
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
24739
24976
|
return null;
|
|
@@ -24960,7 +25197,7 @@ var GrokSubagentLifecycle = class {
|
|
|
24960
25197
|
};
|
|
24961
25198
|
|
|
24962
25199
|
// dist/grok-models.js
|
|
24963
|
-
function
|
|
25200
|
+
function isRecord17(value) {
|
|
24964
25201
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24965
25202
|
}
|
|
24966
25203
|
function nonBlank(value) {
|
|
@@ -24993,7 +25230,7 @@ function thinkingOptions(value) {
|
|
|
24993
25230
|
const seen = /* @__PURE__ */ new Set();
|
|
24994
25231
|
const options = [];
|
|
24995
25232
|
for (const candidate of value) {
|
|
24996
|
-
if (!
|
|
25233
|
+
if (!isRecord17(candidate) || !nonBlank(candidate.label))
|
|
24997
25234
|
continue;
|
|
24998
25235
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
24999
25236
|
if (!id.success || seen.has(id.data))
|
|
@@ -25004,7 +25241,7 @@ function thinkingOptions(value) {
|
|
|
25004
25241
|
return options;
|
|
25005
25242
|
}
|
|
25006
25243
|
function parseGrokModelState(value) {
|
|
25007
|
-
if (!
|
|
25244
|
+
if (!isRecord17(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
25008
25245
|
return null;
|
|
25009
25246
|
}
|
|
25010
25247
|
const currentModel = encodeGrokModelRef(value.currentModelId);
|
|
@@ -25016,12 +25253,12 @@ function parseGrokModelState(value) {
|
|
|
25016
25253
|
const models = [];
|
|
25017
25254
|
let currentThinkingOptionId;
|
|
25018
25255
|
for (const candidate of value.availableModels) {
|
|
25019
|
-
if (!
|
|
25256
|
+
if (!isRecord17(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
25020
25257
|
continue;
|
|
25021
25258
|
const ref = encodeGrokModelRef(candidate.modelId);
|
|
25022
25259
|
if (!ref)
|
|
25023
25260
|
continue;
|
|
25024
|
-
const metadata =
|
|
25261
|
+
const metadata = isRecord17(candidate._meta) ? candidate._meta : {};
|
|
25025
25262
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
25026
25263
|
if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
|
|
25027
25264
|
defaultContextWindowTokensByModel.set(ref.id, 5e5);
|
|
@@ -25060,10 +25297,10 @@ function parseGrokModelState(value) {
|
|
|
25060
25297
|
};
|
|
25061
25298
|
}
|
|
25062
25299
|
function modelStateFromInitialize(response) {
|
|
25063
|
-
return parseGrokModelState(
|
|
25300
|
+
return parseGrokModelState(isRecord17(response._meta) ? response._meta.modelState : void 0);
|
|
25064
25301
|
}
|
|
25065
25302
|
function modelStateFromSessionResponse(response) {
|
|
25066
|
-
return parseGrokModelState(
|
|
25303
|
+
return parseGrokModelState(isRecord17(response) ? response.models : void 0);
|
|
25067
25304
|
}
|
|
25068
25305
|
function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
25069
25306
|
const selectedModel = model2;
|
|
@@ -25086,8 +25323,16 @@ import { readFile as readFile5 } from "node:fs/promises";
|
|
|
25086
25323
|
import os6 from "node:os";
|
|
25087
25324
|
import path14 from "node:path";
|
|
25088
25325
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
25326
|
+
var GROK_SETTINGS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/settings";
|
|
25089
25327
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
25090
|
-
|
|
25328
|
+
var PLAN_TIMEOUT_MS = 2e3;
|
|
25329
|
+
function parseGrokPlan(value) {
|
|
25330
|
+
if (!isRecord18(value) || typeof value.subscription_tier_display !== "string")
|
|
25331
|
+
return void 0;
|
|
25332
|
+
const plan = value.subscription_tier_display.trim();
|
|
25333
|
+
return plan && plan.length <= 128 && !/[\u0000-\u001f\u007f]/u.test(plan) ? plan : void 0;
|
|
25334
|
+
}
|
|
25335
|
+
function isRecord18(value) {
|
|
25091
25336
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25092
25337
|
}
|
|
25093
25338
|
function finitePercent(value) {
|
|
@@ -25096,7 +25341,7 @@ function finitePercent(value) {
|
|
|
25096
25341
|
return Math.min(100, Math.max(0, value));
|
|
25097
25342
|
}
|
|
25098
25343
|
function nonNegativeCentValue(value) {
|
|
25099
|
-
if (!
|
|
25344
|
+
if (!isRecord18(value))
|
|
25100
25345
|
return void 0;
|
|
25101
25346
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
25102
25347
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
@@ -25120,7 +25365,7 @@ function productUsageFrom(value) {
|
|
|
25120
25365
|
if (!Array.isArray(value))
|
|
25121
25366
|
return void 0;
|
|
25122
25367
|
const products = value.flatMap((entry) => {
|
|
25123
|
-
if (!
|
|
25368
|
+
if (!isRecord18(entry) || typeof entry.product !== "string")
|
|
25124
25369
|
return [];
|
|
25125
25370
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
25126
25371
|
const labels = {
|
|
@@ -25141,10 +25386,10 @@ function productUsageFrom(value) {
|
|
|
25141
25386
|
return products.length > 0 ? products : void 0;
|
|
25142
25387
|
}
|
|
25143
25388
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
25144
|
-
if (!
|
|
25389
|
+
if (!isRecord18(value) || !isRecord18(value.config))
|
|
25145
25390
|
return null;
|
|
25146
25391
|
const config2 = value.config;
|
|
25147
|
-
const period =
|
|
25392
|
+
const period = isRecord18(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
25148
25393
|
const periodType = periodTypeFrom(period?.type);
|
|
25149
25394
|
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);
|
|
25150
25395
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -25171,11 +25416,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
25171
25416
|
};
|
|
25172
25417
|
}
|
|
25173
25418
|
function selectAccessToken(auth, now) {
|
|
25174
|
-
if (!
|
|
25419
|
+
if (!isRecord18(auth))
|
|
25175
25420
|
return null;
|
|
25176
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
25421
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord18(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")));
|
|
25177
25422
|
for (const [, value] of entries) {
|
|
25178
|
-
if (!
|
|
25423
|
+
if (!isRecord18(value) || typeof value.key !== "string")
|
|
25179
25424
|
continue;
|
|
25180
25425
|
if (typeof value.expires_at === "string") {
|
|
25181
25426
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -25202,20 +25447,24 @@ async function fetchGrokAccount(input = {}) {
|
|
|
25202
25447
|
if (!token)
|
|
25203
25448
|
return null;
|
|
25204
25449
|
const fetchImpl = input.fetch ?? fetch;
|
|
25205
|
-
const
|
|
25450
|
+
const request = (url2, timeoutMs) => fetchImpl(url2, {
|
|
25206
25451
|
method: "GET",
|
|
25207
25452
|
headers: {
|
|
25208
25453
|
Authorization: `Bearer ${token.key}`,
|
|
25209
25454
|
"x-xai-token-auth": "xai-grok-cli",
|
|
25210
25455
|
Accept: "application/json"
|
|
25211
25456
|
},
|
|
25212
|
-
signal: input.signal ? AbortSignal.any([input.signal, AbortSignal.timeout(
|
|
25457
|
+
signal: input.signal ? AbortSignal.any([input.signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs)
|
|
25213
25458
|
});
|
|
25459
|
+
const credits = request(GROK_CREDITS_ENDPOINT, REQUEST_TIMEOUT_MS);
|
|
25460
|
+
const plan = input.includePlan === false ? Promise.resolve(void 0) : request(GROK_SETTINGS_ENDPOINT, input.planTimeoutMs ?? PLAN_TIMEOUT_MS).then(async (response2) => response2.ok ? parseGrokPlan(await response2.json()) : void 0).catch(() => void 0);
|
|
25461
|
+
const response = await credits;
|
|
25214
25462
|
if (!response.ok)
|
|
25215
25463
|
return null;
|
|
25216
25464
|
const snapshot = parseGrokCreditsResponse(await response.json(), now.toISOString());
|
|
25217
25465
|
if (!snapshot)
|
|
25218
25466
|
return null;
|
|
25467
|
+
const planName = await plan;
|
|
25219
25468
|
return {
|
|
25220
25469
|
credits: {
|
|
25221
25470
|
usedPercent: snapshot.usedPercent,
|
|
@@ -25224,14 +25473,15 @@ async function fetchGrokAccount(input = {}) {
|
|
|
25224
25473
|
...snapshot.productUsage ? { productUsage: [...snapshot.productUsage] } : {}
|
|
25225
25474
|
},
|
|
25226
25475
|
...token.email ? { email: token.email } : {},
|
|
25227
|
-
...token.label ? { label: token.label } : {}
|
|
25476
|
+
...token.label ? { label: token.label } : {},
|
|
25477
|
+
...planName ? { plan: planName } : {}
|
|
25228
25478
|
};
|
|
25229
25479
|
} catch {
|
|
25230
25480
|
return null;
|
|
25231
25481
|
}
|
|
25232
25482
|
}
|
|
25233
25483
|
async function fetchGrokCredits(input = {}) {
|
|
25234
|
-
const account = await fetchGrokAccount(input);
|
|
25484
|
+
const account = await fetchGrokAccount({ ...input, includePlan: false });
|
|
25235
25485
|
const usedPercent = account?.credits?.usedPercent;
|
|
25236
25486
|
if (!account?.credits || usedPercent === void 0)
|
|
25237
25487
|
return null;
|
|
@@ -25247,7 +25497,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
25247
25497
|
|
|
25248
25498
|
// dist/grok-usage.js
|
|
25249
25499
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
25250
|
-
function
|
|
25500
|
+
function isRecord19(value) {
|
|
25251
25501
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25252
25502
|
}
|
|
25253
25503
|
function optionalToken(value) {
|
|
@@ -25264,7 +25514,7 @@ function combineUsage(base, next) {
|
|
|
25264
25514
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
25265
25515
|
}
|
|
25266
25516
|
function usageFromNative(value) {
|
|
25267
|
-
if (!
|
|
25517
|
+
if (!isRecord19(value))
|
|
25268
25518
|
return null;
|
|
25269
25519
|
const nativeInputTokens = optionalToken(value.inputTokens);
|
|
25270
25520
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -25290,7 +25540,7 @@ function usageFromNative(value) {
|
|
|
25290
25540
|
}
|
|
25291
25541
|
}
|
|
25292
25542
|
function usageFromResponse(value) {
|
|
25293
|
-
if (!
|
|
25543
|
+
if (!isRecord19(value))
|
|
25294
25544
|
return null;
|
|
25295
25545
|
const buckets = [
|
|
25296
25546
|
value.input_tokens,
|
|
@@ -25320,10 +25570,10 @@ var GrokTurnUsage = class {
|
|
|
25320
25570
|
#latestCacheHit;
|
|
25321
25571
|
#sessionInputTokens = 0;
|
|
25322
25572
|
constructor(base, emptySession = false) {
|
|
25323
|
-
for (const
|
|
25324
|
-
const value = base?.[
|
|
25573
|
+
for (const field2 of summedUsageFields) {
|
|
25574
|
+
const value = base?.[field2];
|
|
25325
25575
|
if (value !== void 0)
|
|
25326
|
-
this.#totals[
|
|
25576
|
+
this.#totals[field2] = value;
|
|
25327
25577
|
}
|
|
25328
25578
|
this.#cacheComplete = base?.sessionCacheUsage !== void 0 || emptySession;
|
|
25329
25579
|
this.#sessionInputTokens = base?.sessionCacheUsage?.inputTokens ?? 0;
|
|
@@ -25364,10 +25614,10 @@ var GrokTurnUsage = class {
|
|
|
25364
25614
|
this.#cacheComplete = false;
|
|
25365
25615
|
if (usage) {
|
|
25366
25616
|
this.#sessionInputTokens += (usage.inputTokens ?? 0) + (usage.cachedInputTokens ?? 0) + (usage.cacheWriteInputTokens ?? 0);
|
|
25367
|
-
for (const
|
|
25368
|
-
const value = usage[
|
|
25617
|
+
for (const field2 of summedUsageFields) {
|
|
25618
|
+
const value = usage[field2];
|
|
25369
25619
|
if (value !== void 0)
|
|
25370
|
-
this.#totals[
|
|
25620
|
+
this.#totals[field2] = (this.#totals[field2] ?? 0) + value;
|
|
25371
25621
|
}
|
|
25372
25622
|
if (duration3 > 0 && usage.outputTokens !== void 0) {
|
|
25373
25623
|
this.#outputTokens += usage.outputTokens;
|
|
@@ -25393,7 +25643,7 @@ var GrokTurnUsage = class {
|
|
|
25393
25643
|
}
|
|
25394
25644
|
};
|
|
25395
25645
|
function usageFromSignals(value) {
|
|
25396
|
-
if (!
|
|
25646
|
+
if (!isRecord19(value))
|
|
25397
25647
|
return null;
|
|
25398
25648
|
try {
|
|
25399
25649
|
return parseHostUsage({
|
|
@@ -25413,7 +25663,7 @@ var summedUsageFields = [
|
|
|
25413
25663
|
"totalTokens"
|
|
25414
25664
|
];
|
|
25415
25665
|
function nativeCostTicks(value) {
|
|
25416
|
-
if (!
|
|
25666
|
+
if (!isRecord19(value))
|
|
25417
25667
|
return void 0;
|
|
25418
25668
|
const ticks = value.costUsdTicks;
|
|
25419
25669
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -25421,7 +25671,7 @@ function nativeCostTicks(value) {
|
|
|
25421
25671
|
return ticks;
|
|
25422
25672
|
}
|
|
25423
25673
|
function sessionCostFromNative(value, initialCostUsd) {
|
|
25424
|
-
if (!
|
|
25674
|
+
if (!isRecord19(value))
|
|
25425
25675
|
return void 0;
|
|
25426
25676
|
if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
|
|
25427
25677
|
return void 0;
|
|
@@ -25450,7 +25700,7 @@ function sessionUsageFromHistory(events) {
|
|
|
25450
25700
|
continue;
|
|
25451
25701
|
const usage = usageFromNative(event.usage);
|
|
25452
25702
|
const ticks2 = nativeCostTicks(event.usage);
|
|
25453
|
-
const complete =
|
|
25703
|
+
const complete = isRecord19(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && typeof event.usage.inputTokens === "number" && usage.cachedInputTokens + (usage.cacheWriteInputTokens ?? 0) <= event.usage.inputTokens;
|
|
25454
25704
|
latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
|
|
25455
25705
|
}
|
|
25456
25706
|
if (latestByKey.size === 0)
|
|
@@ -25462,11 +25712,11 @@ function sessionUsageFromHistory(events) {
|
|
|
25462
25712
|
for (const entry of latestByKey.values()) {
|
|
25463
25713
|
if (!entry.usage)
|
|
25464
25714
|
continue;
|
|
25465
|
-
for (const
|
|
25466
|
-
const value = entry.usage[
|
|
25715
|
+
for (const field2 of summedUsageFields) {
|
|
25716
|
+
const value = entry.usage[field2];
|
|
25467
25717
|
if (value === void 0)
|
|
25468
25718
|
continue;
|
|
25469
|
-
totals2[
|
|
25719
|
+
totals2[field2] = (totals2[field2] ?? 0) + value;
|
|
25470
25720
|
}
|
|
25471
25721
|
sessionInputTokens += (entry.usage.inputTokens ?? 0) + (entry.usage.cachedInputTokens ?? 0) + (entry.usage.cacheWriteInputTokens ?? 0);
|
|
25472
25722
|
if (entry.ticks === void 0)
|
|
@@ -25506,7 +25756,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
25506
25756
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
25507
25757
|
try {
|
|
25508
25758
|
if (update?.sessionUpdate === "usage_update") {
|
|
25509
|
-
const cost =
|
|
25759
|
+
const cost = isRecord19(update.cost) ? update.cost : null;
|
|
25510
25760
|
return parseHostUsage({
|
|
25511
25761
|
contextUsedTokens: update.used,
|
|
25512
25762
|
contextWindowTokens: update.size,
|
|
@@ -25745,6 +25995,7 @@ var GrokHarnessSession = class {
|
|
|
25745
25995
|
});
|
|
25746
25996
|
const active = {
|
|
25747
25997
|
command,
|
|
25998
|
+
questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
25748
25999
|
usage: new GrokTurnUsage(this.#usage, this.#snapshot.turns.length === 0),
|
|
25749
26000
|
agent: null,
|
|
25750
26001
|
agentMessageId: null,
|
|
@@ -25759,7 +26010,7 @@ var GrokHarnessSession = class {
|
|
|
25759
26010
|
subagents: this.#createSubagents(),
|
|
25760
26011
|
completedItems: [],
|
|
25761
26012
|
approvals: /* @__PURE__ */ new Map(),
|
|
25762
|
-
|
|
26013
|
+
legacyQuestions: /* @__PURE__ */ new Map(),
|
|
25763
26014
|
cancellationRequested: false,
|
|
25764
26015
|
beforeNativeTurnKeys: new Set(this.#snapshot.turns.map((turn) => turn.nativeTurnRef.nativeTurnKey)),
|
|
25765
26016
|
completion,
|
|
@@ -25767,7 +26018,7 @@ var GrokHarnessSession = class {
|
|
|
25767
26018
|
};
|
|
25768
26019
|
this.#active = active;
|
|
25769
26020
|
this.#event({ type: "turn.started", turnId: command.turnId });
|
|
25770
|
-
void this.#transport.runTurn(text, (event) => this.#handleEvent(active, event), (request) => this.#requestPermission(active, request), (request) => this.#requestExtension(active, request)).then((response) => this.#settleFromHistory(active, terminalOutcome2(response, active.cancellationRequested), response), (error53) => this.#settleFromHistory(active, {
|
|
26021
|
+
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" }), (request) => this.#requestExtension(active, request)).finally(() => active.questions.cancel()).then((response) => this.#settleFromHistory(active, terminalOutcome2(response, active.cancellationRequested), response), (error53) => this.#settleFromHistory(active, {
|
|
25771
26022
|
status: "failed",
|
|
25772
26023
|
error: normalizeError(error53, "nativeFailure")
|
|
25773
26024
|
}));
|
|
@@ -25836,6 +26087,7 @@ var GrokHarnessSession = class {
|
|
|
25836
26087
|
});
|
|
25837
26088
|
const active = {
|
|
25838
26089
|
command: { type: "turn.start", turnId: command.turnId, input: [] },
|
|
26090
|
+
questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
25839
26091
|
agent: null,
|
|
25840
26092
|
agentMessageId: null,
|
|
25841
26093
|
rawAgentText: "",
|
|
@@ -25849,7 +26101,7 @@ var GrokHarnessSession = class {
|
|
|
25849
26101
|
subagents: this.#createSubagents(),
|
|
25850
26102
|
completedItems: [],
|
|
25851
26103
|
approvals: /* @__PURE__ */ new Map(),
|
|
25852
|
-
|
|
26104
|
+
legacyQuestions: /* @__PURE__ */ new Map(),
|
|
25853
26105
|
cancellationRequested: false,
|
|
25854
26106
|
beforeNativeTurnKeys: /* @__PURE__ */ new Set(),
|
|
25855
26107
|
completion,
|
|
@@ -26016,6 +26268,7 @@ var GrokHarnessSession = class {
|
|
|
26016
26268
|
if (active.cancellationRequested)
|
|
26017
26269
|
return { ok: true, value: { cancellationRequested: true } };
|
|
26018
26270
|
active.cancellationRequested = true;
|
|
26271
|
+
active.questions.cancel();
|
|
26019
26272
|
this.#closePendingInteractions(active, "cancelled");
|
|
26020
26273
|
try {
|
|
26021
26274
|
await this.#transport.cancel();
|
|
@@ -26026,10 +26279,12 @@ var GrokHarnessSession = class {
|
|
|
26026
26279
|
}
|
|
26027
26280
|
async #respond(command) {
|
|
26028
26281
|
const active = this.#active;
|
|
26282
|
+
if (active?.questions.has(command.interactionId))
|
|
26283
|
+
return active.questions.respond(command);
|
|
26029
26284
|
const approval = active?.approvals.get(command.interactionId);
|
|
26030
26285
|
if (active && approval)
|
|
26031
26286
|
return this.#respondApproval(active, approval, command);
|
|
26032
|
-
const question = active?.
|
|
26287
|
+
const question = active?.legacyQuestions.get(command.interactionId);
|
|
26033
26288
|
if (active && question)
|
|
26034
26289
|
return this.#respondQuestion(active, question, command);
|
|
26035
26290
|
return { ok: false, error: invalidState("Grok Interaction is not pending") };
|
|
@@ -26083,7 +26338,7 @@ var GrokHarnessSession = class {
|
|
|
26083
26338
|
if (validation)
|
|
26084
26339
|
return { ok: false, error: validation };
|
|
26085
26340
|
const native = pending.type === "planApproval" ? grokExitPlanModeResponse(pending.request, command.response) : grokAskUserQuestionResponse(pending.request, command.response);
|
|
26086
|
-
active.
|
|
26341
|
+
active.legacyQuestions.delete(command.interactionId);
|
|
26087
26342
|
pending.resolve(native);
|
|
26088
26343
|
this.#event({
|
|
26089
26344
|
type: "interaction.closed",
|
|
@@ -26141,7 +26396,7 @@ var GrokHarnessSession = class {
|
|
|
26141
26396
|
const interactionId = hostInteractionIdSchema.parse(this.#randomUUID());
|
|
26142
26397
|
const interaction = createGrokQuestionInteraction(request, interactionId, active.command.turnId);
|
|
26143
26398
|
return new Promise((resolve) => {
|
|
26144
|
-
active.
|
|
26399
|
+
active.legacyQuestions.set(interactionId, {
|
|
26145
26400
|
type: "question",
|
|
26146
26401
|
interaction,
|
|
26147
26402
|
request,
|
|
@@ -26157,7 +26412,7 @@ var GrokHarnessSession = class {
|
|
|
26157
26412
|
const interactionId = hostInteractionIdSchema.parse(this.#randomUUID());
|
|
26158
26413
|
const interaction = createGrokPlanReview(request, interactionId, active.command.turnId);
|
|
26159
26414
|
return new Promise((resolve) => {
|
|
26160
|
-
active.
|
|
26415
|
+
active.legacyQuestions.set(interactionId, {
|
|
26161
26416
|
type: "planApproval",
|
|
26162
26417
|
interaction,
|
|
26163
26418
|
request,
|
|
@@ -26177,8 +26432,8 @@ var GrokHarnessSession = class {
|
|
|
26177
26432
|
reason
|
|
26178
26433
|
});
|
|
26179
26434
|
}
|
|
26180
|
-
for (const [interactionId, pending] of active.
|
|
26181
|
-
active.
|
|
26435
|
+
for (const [interactionId, pending] of active.legacyQuestions) {
|
|
26436
|
+
active.legacyQuestions.delete(interactionId);
|
|
26182
26437
|
pending.resolve(pending.type === "planApproval" ? grokPlanRejectedResponse() : grokSkipInterviewResponse());
|
|
26183
26438
|
this.#event({
|
|
26184
26439
|
type: "interaction.closed",
|
|
@@ -26191,6 +26446,10 @@ var GrokHarnessSession = class {
|
|
|
26191
26446
|
#handleEvent(active, event) {
|
|
26192
26447
|
if (this.#active !== active || this.#phase !== "open")
|
|
26193
26448
|
return;
|
|
26449
|
+
if (event.type === "interaction.resolved") {
|
|
26450
|
+
active.questions.withdraw(event.toolCallId);
|
|
26451
|
+
return;
|
|
26452
|
+
}
|
|
26194
26453
|
const requestUsage = active.usage?.observe(event);
|
|
26195
26454
|
if (requestUsage) {
|
|
26196
26455
|
this.#publishUsage(requestUsage, active.command.turnId, true);
|
|
@@ -26587,6 +26846,7 @@ var GrokHarnessSession = class {
|
|
|
26587
26846
|
#finish(active, outcome, usage = null, nativeTurnRef) {
|
|
26588
26847
|
if (this.#active !== active)
|
|
26589
26848
|
return;
|
|
26849
|
+
active.questions.cancel();
|
|
26590
26850
|
const itemOutcome = outcome;
|
|
26591
26851
|
this.#completeReasoning(active, itemOutcome);
|
|
26592
26852
|
this.#completeAgent(active, itemOutcome);
|
|
@@ -26634,12 +26894,8 @@ var GrokHarnessSession = class {
|
|
|
26634
26894
|
const active = this.#active;
|
|
26635
26895
|
if (active) {
|
|
26636
26896
|
active.cancellationRequested = true;
|
|
26637
|
-
|
|
26638
|
-
|
|
26639
|
-
}
|
|
26640
|
-
for (const question of active.questions.values()) {
|
|
26641
|
-
question.resolve(question.type === "planApproval" ? grokPlanRejectedResponse() : grokSkipInterviewResponse());
|
|
26642
|
-
}
|
|
26897
|
+
active.questions.cancel();
|
|
26898
|
+
this.#closePendingInteractions(active, "cancelled");
|
|
26643
26899
|
await this.#transport.cancel().catch(() => void 0);
|
|
26644
26900
|
await Promise.race([
|
|
26645
26901
|
active.completion,
|