@karlorz/codexhost-cli-win32-x64 0.14.0-3 → 0.14.0-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 +62 -6
- package/app/console-web.js +90 -34
- package/app/cpa-live-voice-hook.js +187 -18
- package/app/desktop-controller.mjs +59 -3
- package/app/host-runtime.mjs +621 -405
- package/app/plugins/antigravity/plugin.mjs +62 -3
- package/app/plugins/claude-code/plugin.mjs +83 -24
- package/app/plugins/codebuddy/plugin.mjs +80 -21
- package/app/plugins/codex-usage/plugin.mjs +84 -28
- package/app/plugins/copilot/plugin.mjs +112 -53
- package/app/plugins/cursor-cli/plugin.mjs +80 -21
- package/app/plugins/deepseek-harness/plugin.mjs +91 -32
- package/app/plugins/grok/plugin.mjs +411 -87
- package/app/plugins/hermes/plugin.mjs +62 -3
- package/app/plugins/kimi-code/plugin.mjs +74 -15
- package/app/plugins/kiro-cli/plugin.mjs +74 -15
- package/app/plugins/omp/plugin.mjs +94 -35
- package/app/plugins/opencode/plugin.mjs +116 -57
- package/app/plugins/pi/plugin.mjs +96 -37
- package/app/plugins/qoder/plugin.mjs +84 -25
- package/app/plugins/qoder-cn/plugin.mjs +84 -25
- package/app/plugins/workbuddy/plugin.mjs +80 -21
- package/app/plugins/zcode/plugin.mjs +85 -26
- package/app/renderer-extension.js +916 -138
- 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
|
@@ -3613,10 +3613,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
3613
3613
|
const shape = def.shape;
|
|
3614
3614
|
const propValues = {};
|
|
3615
3615
|
for (const key in shape) {
|
|
3616
|
-
const
|
|
3617
|
-
if (
|
|
3616
|
+
const field2 = shape[key]._zod;
|
|
3617
|
+
if (field2.values) {
|
|
3618
3618
|
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
3619
|
-
for (const v of
|
|
3619
|
+
for (const v of field2.values)
|
|
3620
3620
|
propValues[key].add(v);
|
|
3621
3621
|
}
|
|
3622
3622
|
}
|
|
@@ -15443,6 +15443,62 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
15443
15443
|
// ../../shared-contracts/dist/version.js
|
|
15444
15444
|
var WORKSPACE_CONTRACT_VERSION = 1;
|
|
15445
15445
|
|
|
15446
|
+
// ../../shared-contracts/dist/thread-questions.js
|
|
15447
|
+
var threadQuestionsParamsSchema = external_exports.strictObject({ threadId: hostThreadIdSchema });
|
|
15448
|
+
var field = { id: external_exports.string().min(1), prompt: external_exports.string(), optional: external_exports.boolean() };
|
|
15449
|
+
var questionAutoResolutionSchema = external_exports.strictObject({
|
|
15450
|
+
deadlineUnixMs: external_exports.number().int().min(0).max(864e13),
|
|
15451
|
+
action: external_exports.enum(["recommended", "decline"]),
|
|
15452
|
+
resetOnActivity: external_exports.boolean().optional()
|
|
15453
|
+
});
|
|
15454
|
+
var threadQuestionSchema = external_exports.strictObject({
|
|
15455
|
+
interactionId: hostInteractionIdSchema,
|
|
15456
|
+
turnId: hostTurnIdSchema,
|
|
15457
|
+
title: external_exports.string().optional(),
|
|
15458
|
+
expiresAt: external_exports.string().optional(),
|
|
15459
|
+
autoResolution: questionAutoResolutionSchema.optional(),
|
|
15460
|
+
questions: external_exports.array(external_exports.discriminatedUnion("type", [
|
|
15461
|
+
external_exports.strictObject({
|
|
15462
|
+
...field,
|
|
15463
|
+
type: external_exports.literal("choice"),
|
|
15464
|
+
multiple: external_exports.boolean(),
|
|
15465
|
+
allowOther: external_exports.boolean(),
|
|
15466
|
+
options: external_exports.array(external_exports.strictObject({
|
|
15467
|
+
value: external_exports.string().min(1),
|
|
15468
|
+
label: external_exports.string(),
|
|
15469
|
+
description: external_exports.string().optional()
|
|
15470
|
+
})).min(1)
|
|
15471
|
+
}),
|
|
15472
|
+
external_exports.strictObject({
|
|
15473
|
+
...field,
|
|
15474
|
+
type: external_exports.literal("text"),
|
|
15475
|
+
multiline: external_exports.boolean(),
|
|
15476
|
+
secret: external_exports.literal(false),
|
|
15477
|
+
placeholder: external_exports.string().optional(),
|
|
15478
|
+
prefill: external_exports.string().optional()
|
|
15479
|
+
})
|
|
15480
|
+
])).min(1)
|
|
15481
|
+
});
|
|
15482
|
+
var threadQuestionsResultSchema = external_exports.strictObject({
|
|
15483
|
+
questions: external_exports.array(threadQuestionSchema)
|
|
15484
|
+
});
|
|
15485
|
+
var threadQuestionRespondParamsSchema = external_exports.strictObject({
|
|
15486
|
+
threadId: hostThreadIdSchema,
|
|
15487
|
+
interactionId: hostInteractionIdSchema,
|
|
15488
|
+
turnId: hostTurnIdSchema,
|
|
15489
|
+
answers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
|
|
15490
|
+
cancelled: external_exports.boolean().optional()
|
|
15491
|
+
});
|
|
15492
|
+
var threadQuestionRespondResultSchema = external_exports.strictObject({ accepted: external_exports.literal(true) });
|
|
15493
|
+
var threadQuestionActivityParamsSchema = external_exports.strictObject({
|
|
15494
|
+
threadId: hostThreadIdSchema,
|
|
15495
|
+
interactionId: hostInteractionIdSchema,
|
|
15496
|
+
turnId: hostTurnIdSchema
|
|
15497
|
+
});
|
|
15498
|
+
var threadQuestionActivityResultSchema = external_exports.strictObject({
|
|
15499
|
+
autoResolution: questionAutoResolutionSchema.nullable()
|
|
15500
|
+
});
|
|
15501
|
+
|
|
15446
15502
|
// ../../shared-contracts/dist/idle-release.js
|
|
15447
15503
|
var IDLE_RELEASE_TIMEOUT_MINUTES_MIN = 5;
|
|
15448
15504
|
var IDLE_RELEASE_TIMEOUT_MINUTES_MAX = 1440;
|
|
@@ -16997,6 +17053,45 @@ function validateHostApprovalResponse(interaction, response) {
|
|
|
16997
17053
|
return interaction.actions.some(({ id }) => id === response.actionId) ? null : invalidRequest("Approval Response contains an undeclared action ID");
|
|
16998
17054
|
}
|
|
16999
17055
|
|
|
17056
|
+
// ../../harness-adapter/dist/question.js
|
|
17057
|
+
function invalidRequest2(message) {
|
|
17058
|
+
return { code: "invalidRequest", message, retryable: false };
|
|
17059
|
+
}
|
|
17060
|
+
function validateHostQuestionResponse(interaction, response) {
|
|
17061
|
+
const questionIds = new Set(interaction.questions.map(({ id }) => id));
|
|
17062
|
+
if (response.cancelled) {
|
|
17063
|
+
return Object.keys(response.answers).length === 0 ? null : invalidRequest2("Cancelled Question Response must not contain answers");
|
|
17064
|
+
}
|
|
17065
|
+
for (const answerId of Object.keys(response.answers)) {
|
|
17066
|
+
if (!questionIds.has(answerId)) {
|
|
17067
|
+
return invalidRequest2("Question Response contains an unknown Question ID");
|
|
17068
|
+
}
|
|
17069
|
+
}
|
|
17070
|
+
for (const question of interaction.questions) {
|
|
17071
|
+
const answers = response.answers[question.id] ?? [];
|
|
17072
|
+
if (new Set(answers).size !== answers.length) {
|
|
17073
|
+
return invalidRequest2("Question Response contains duplicate answers");
|
|
17074
|
+
}
|
|
17075
|
+
if (!question.optional && answers.length === 0) {
|
|
17076
|
+
return invalidRequest2("Question Response omits a required answer");
|
|
17077
|
+
}
|
|
17078
|
+
if (question.type === "text") {
|
|
17079
|
+
if (answers.length > 1) {
|
|
17080
|
+
return invalidRequest2("Text Question accepts at most one answer");
|
|
17081
|
+
}
|
|
17082
|
+
continue;
|
|
17083
|
+
}
|
|
17084
|
+
if (!question.multiple && answers.length > 1) {
|
|
17085
|
+
return invalidRequest2("Single-choice Question accepts at most one answer");
|
|
17086
|
+
}
|
|
17087
|
+
const declared = new Set(question.options.map(({ value }) => value));
|
|
17088
|
+
if (!question.allowOther && answers.some((answer) => !declared.has(answer))) {
|
|
17089
|
+
return invalidRequest2("Question Response contains an undeclared choice");
|
|
17090
|
+
}
|
|
17091
|
+
}
|
|
17092
|
+
return null;
|
|
17093
|
+
}
|
|
17094
|
+
|
|
17000
17095
|
// ../../harness-adapter/dist/output-channel.js
|
|
17001
17096
|
var HarnessOutputChannel = class {
|
|
17002
17097
|
outputs;
|
|
@@ -17118,26 +17213,26 @@ function parseHostUsage(value) {
|
|
|
17118
17213
|
}
|
|
17119
17214
|
}
|
|
17120
17215
|
const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
|
|
17121
|
-
for (const
|
|
17216
|
+
for (const field2 of [
|
|
17122
17217
|
"totalCredits",
|
|
17123
17218
|
"contextUsagePercent",
|
|
17124
17219
|
"apiOutputTokensPerSecond"
|
|
17125
17220
|
]) {
|
|
17126
|
-
const candidate = value[
|
|
17221
|
+
const candidate = value[field2];
|
|
17127
17222
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
17128
|
-
throw new Error(`Harness Usage '${
|
|
17223
|
+
throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
|
|
17129
17224
|
}
|
|
17130
17225
|
}
|
|
17131
|
-
for (const
|
|
17132
|
-
const candidate = value[
|
|
17226
|
+
for (const field2 of tokenFields) {
|
|
17227
|
+
const candidate = value[field2];
|
|
17133
17228
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
17134
|
-
throw new Error(`Harness Usage '${
|
|
17229
|
+
throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
|
|
17135
17230
|
}
|
|
17136
17231
|
}
|
|
17137
|
-
for (const
|
|
17138
|
-
const candidate = value[
|
|
17232
|
+
for (const field2 of safeIntegerFields) {
|
|
17233
|
+
const candidate = value[field2];
|
|
17139
17234
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
17140
|
-
throw new Error(`Harness Usage '${
|
|
17235
|
+
throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
|
|
17141
17236
|
}
|
|
17142
17237
|
}
|
|
17143
17238
|
if (value.outputTokensPerSecond !== void 0 && (typeof value.outputTokensPerSecond !== "number" || !Number.isFinite(value.outputTokensPerSecond) || value.outputTokensPerSecond < 0)) {
|
|
@@ -17146,10 +17241,10 @@ function parseHostUsage(value) {
|
|
|
17146
17241
|
if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
|
|
17147
17242
|
throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
|
|
17148
17243
|
}
|
|
17149
|
-
for (const
|
|
17150
|
-
const candidate = value[
|
|
17244
|
+
for (const field2 of percentFields) {
|
|
17245
|
+
const candidate = value[field2];
|
|
17151
17246
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
|
|
17152
|
-
throw new Error(`Harness Usage '${
|
|
17247
|
+
throw new Error(`Harness Usage '${field2}' must be between 0 and 100`);
|
|
17153
17248
|
}
|
|
17154
17249
|
}
|
|
17155
17250
|
if (value.sessionCacheUsage !== void 0) {
|
|
@@ -22451,10 +22546,10 @@ function stringField2(value, key) {
|
|
|
22451
22546
|
function numberField(value, key) {
|
|
22452
22547
|
if (!isRecord7(value))
|
|
22453
22548
|
return void 0;
|
|
22454
|
-
const
|
|
22455
|
-
if (
|
|
22549
|
+
const field2 = value[key];
|
|
22550
|
+
if (field2 === null)
|
|
22456
22551
|
return null;
|
|
22457
|
-
return typeof
|
|
22552
|
+
return typeof field2 === "number" && Number.isFinite(field2) ? field2 : void 0;
|
|
22458
22553
|
}
|
|
22459
22554
|
function decodeBytes(value) {
|
|
22460
22555
|
if (!Array.isArray(value) || value.length === 0)
|
|
@@ -22653,13 +22748,13 @@ function isRecord8(value) {
|
|
|
22653
22748
|
function idField(value, key) {
|
|
22654
22749
|
if (!isRecord8(value))
|
|
22655
22750
|
return void 0;
|
|
22656
|
-
const
|
|
22657
|
-
if (typeof
|
|
22658
|
-
const trimmed =
|
|
22751
|
+
const field2 = value[key];
|
|
22752
|
+
if (typeof field2 === "string") {
|
|
22753
|
+
const trimmed = field2.trim();
|
|
22659
22754
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
22660
22755
|
}
|
|
22661
|
-
if (typeof
|
|
22662
|
-
return String(
|
|
22756
|
+
if (typeof field2 === "number" && Number.isFinite(field2))
|
|
22757
|
+
return String(field2);
|
|
22663
22758
|
return void 0;
|
|
22664
22759
|
}
|
|
22665
22760
|
function stringField3(value, key) {
|
|
@@ -24160,6 +24255,184 @@ var GrokPermissionConfirmation = class {
|
|
|
24160
24255
|
}
|
|
24161
24256
|
};
|
|
24162
24257
|
|
|
24258
|
+
// dist/grok-questions.js
|
|
24259
|
+
var GROK_ASK_USER_QUESTION_METHOD = "_x.ai/ask_user_question";
|
|
24260
|
+
var GROK_QUESTION_ACTIVITY_METHOD = "_x.ai/ask_user_question_activity";
|
|
24261
|
+
function isRecord14(value) {
|
|
24262
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24263
|
+
}
|
|
24264
|
+
function nonEmptyString2(value) {
|
|
24265
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
24266
|
+
}
|
|
24267
|
+
function parseGrokQuestionRequest(value) {
|
|
24268
|
+
if (!isRecord14(value) || !nonEmptyString2(value.sessionId) || !nonEmptyString2(value.toolCallId) || value.mode !== "default" && value.mode !== "plan" || !Array.isArray(value.questions) || value.questions.length === 0) {
|
|
24269
|
+
throw new Error("Grok question requires sessionId, toolCallId, mode and nonempty questions");
|
|
24270
|
+
}
|
|
24271
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24272
|
+
const questions = value.questions.map((question) => {
|
|
24273
|
+
if (!isRecord14(question) || !nonEmptyString2(question.question) || seen.has(question.question) || !Array.isArray(question.options) || question.multiSelect != null && typeof question.multiSelect !== "boolean" || question.multi_select != null && typeof question.multi_select !== "boolean") {
|
|
24274
|
+
throw new Error("Grok question text must be unique and options/multiSelect must be valid");
|
|
24275
|
+
}
|
|
24276
|
+
if (question.multiSelect != null && question.multi_select != null && question.multiSelect !== question.multi_select)
|
|
24277
|
+
throw new Error("Grok question contains conflicting multi-select flags");
|
|
24278
|
+
seen.add(question.question);
|
|
24279
|
+
const labels = /* @__PURE__ */ new Set();
|
|
24280
|
+
const options = question.options.map((option) => {
|
|
24281
|
+
if (!isRecord14(option) || !nonEmptyString2(option.label) || labels.has(option.label) || typeof option.description !== "string" || option.preview != null && typeof option.preview !== "string") {
|
|
24282
|
+
throw new Error("Grok question options require unique labels and text descriptions/previews");
|
|
24283
|
+
}
|
|
24284
|
+
labels.add(option.label);
|
|
24285
|
+
return {
|
|
24286
|
+
label: option.label,
|
|
24287
|
+
description: option.description,
|
|
24288
|
+
...typeof option.preview === "string" ? { preview: option.preview } : {}
|
|
24289
|
+
};
|
|
24290
|
+
});
|
|
24291
|
+
return {
|
|
24292
|
+
question: question.question,
|
|
24293
|
+
options,
|
|
24294
|
+
multiple: question.multiSelect === true || question.multi_select === true
|
|
24295
|
+
};
|
|
24296
|
+
});
|
|
24297
|
+
const timeout = value.timeout == null ? void 0 : questionAutoResolutionSchema.parse(value.timeout);
|
|
24298
|
+
return {
|
|
24299
|
+
sessionId: value.sessionId,
|
|
24300
|
+
toolCallId: value.toolCallId,
|
|
24301
|
+
mode: value.mode,
|
|
24302
|
+
questions,
|
|
24303
|
+
...timeout ? { timeout } : {}
|
|
24304
|
+
};
|
|
24305
|
+
}
|
|
24306
|
+
var GrokQuestions = class {
|
|
24307
|
+
turnId;
|
|
24308
|
+
randomUUID;
|
|
24309
|
+
emit;
|
|
24310
|
+
#pending = /* @__PURE__ */ new Map();
|
|
24311
|
+
#seenToolCalls = /* @__PURE__ */ new Set();
|
|
24312
|
+
constructor(turnId, randomUUID3, emit) {
|
|
24313
|
+
this.turnId = turnId;
|
|
24314
|
+
this.randomUUID = randomUUID3;
|
|
24315
|
+
this.emit = emit;
|
|
24316
|
+
}
|
|
24317
|
+
has(interactionId) {
|
|
24318
|
+
return this.#pending.has(interactionId);
|
|
24319
|
+
}
|
|
24320
|
+
async activity(interactionId, reset) {
|
|
24321
|
+
const pending = this.#pending.get(interactionId);
|
|
24322
|
+
if (!pending?.interaction.autoResolution?.resetOnActivity)
|
|
24323
|
+
return null;
|
|
24324
|
+
const timeout = await reset(pending.request.toolCallId);
|
|
24325
|
+
if (this.#pending.get(interactionId) !== pending)
|
|
24326
|
+
return null;
|
|
24327
|
+
return timeout;
|
|
24328
|
+
}
|
|
24329
|
+
ask(request) {
|
|
24330
|
+
if (this.#seenToolCalls.has(request.toolCallId))
|
|
24331
|
+
return Promise.resolve({ outcome: "cancelled" });
|
|
24332
|
+
this.#seenToolCalls.add(request.toolCallId);
|
|
24333
|
+
const interaction = {
|
|
24334
|
+
type: "question",
|
|
24335
|
+
interactionId: hostInteractionIdSchema.parse(this.randomUUID()),
|
|
24336
|
+
turnId: this.turnId,
|
|
24337
|
+
title: "Grok",
|
|
24338
|
+
...request.timeout ? { autoResolution: request.timeout } : {},
|
|
24339
|
+
questions: request.questions.map((question, index) => question.options.length ? {
|
|
24340
|
+
id: `q${index}`,
|
|
24341
|
+
type: "choice",
|
|
24342
|
+
prompt: question.question,
|
|
24343
|
+
options: question.options.map(({ label, description, preview }) => ({
|
|
24344
|
+
value: label,
|
|
24345
|
+
label,
|
|
24346
|
+
description: [description, preview].filter(Boolean).join("\n\n")
|
|
24347
|
+
})),
|
|
24348
|
+
multiple: question.multiple ?? false,
|
|
24349
|
+
allowOther: true,
|
|
24350
|
+
optional: true
|
|
24351
|
+
} : {
|
|
24352
|
+
id: `q${index}`,
|
|
24353
|
+
type: "text",
|
|
24354
|
+
prompt: question.question,
|
|
24355
|
+
multiline: true,
|
|
24356
|
+
secret: false,
|
|
24357
|
+
optional: true
|
|
24358
|
+
})
|
|
24359
|
+
};
|
|
24360
|
+
return new Promise((resolve) => {
|
|
24361
|
+
this.#pending.set(interaction.interactionId, { request, interaction, resolve });
|
|
24362
|
+
this.emit({ kind: "interaction", interaction });
|
|
24363
|
+
});
|
|
24364
|
+
}
|
|
24365
|
+
respond(command) {
|
|
24366
|
+
const pending = this.#pending.get(command.interactionId);
|
|
24367
|
+
if (!pending)
|
|
24368
|
+
return this.#error("invalidState", "Grok Question is not pending");
|
|
24369
|
+
if (command.response.type !== "question") {
|
|
24370
|
+
return this.#error("invalidRequest", "Grok Question requires a Question Response");
|
|
24371
|
+
}
|
|
24372
|
+
const response = command.response;
|
|
24373
|
+
const error53 = validateHostQuestionResponse(pending.interaction, response);
|
|
24374
|
+
if (error53)
|
|
24375
|
+
return { ok: false, error: error53 };
|
|
24376
|
+
if (response.cancelled) {
|
|
24377
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
24378
|
+
return { ok: true, value: { accepted: true } };
|
|
24379
|
+
}
|
|
24380
|
+
const answers = /* @__PURE__ */ new Map();
|
|
24381
|
+
const annotations = /* @__PURE__ */ new Map();
|
|
24382
|
+
for (const [index, question] of pending.request.questions.entries()) {
|
|
24383
|
+
const values = response.answers[`q${index}`];
|
|
24384
|
+
if (!values?.length)
|
|
24385
|
+
continue;
|
|
24386
|
+
if (values.some((answer) => !nonEmptyString2(answer)))
|
|
24387
|
+
return this.#error("invalidRequest", "Grok answer must not be empty");
|
|
24388
|
+
const selected = values.map((answer) => question.options.find(({ label }) => label === answer));
|
|
24389
|
+
const other = values.filter((_, position) => !selected[position]);
|
|
24390
|
+
if (other.length > 1)
|
|
24391
|
+
return this.#error("invalidRequest", "Grok question accepts only one Other response");
|
|
24392
|
+
answers.set(question.question, selected.map((option) => option?.label ?? "Other"));
|
|
24393
|
+
const previews = selected.flatMap((option) => option?.preview !== void 0 ? [option.preview] : []);
|
|
24394
|
+
if (previews.length || other.length)
|
|
24395
|
+
annotations.set(question.question, {
|
|
24396
|
+
...previews.length ? { preview: previews.join("\n\n") } : {},
|
|
24397
|
+
...other.length ? { notes: other[0] } : {}
|
|
24398
|
+
});
|
|
24399
|
+
}
|
|
24400
|
+
this.#settle(pending, {
|
|
24401
|
+
outcome: "accepted",
|
|
24402
|
+
answers: Object.fromEntries(answers),
|
|
24403
|
+
...annotations.size ? { annotations: Object.fromEntries(annotations) } : {}
|
|
24404
|
+
}, "responded");
|
|
24405
|
+
return { ok: true, value: { accepted: true } };
|
|
24406
|
+
}
|
|
24407
|
+
withdraw(toolCallId) {
|
|
24408
|
+
for (const pending of this.#pending.values()) {
|
|
24409
|
+
if (pending.request.toolCallId === toolCallId)
|
|
24410
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
24411
|
+
}
|
|
24412
|
+
}
|
|
24413
|
+
cancel() {
|
|
24414
|
+
for (const pending of this.#pending.values())
|
|
24415
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
24416
|
+
}
|
|
24417
|
+
#settle(pending, response, reason) {
|
|
24418
|
+
if (!this.#pending.delete(pending.interaction.interactionId))
|
|
24419
|
+
return;
|
|
24420
|
+
pending.resolve(response);
|
|
24421
|
+
this.emit({
|
|
24422
|
+
kind: "event",
|
|
24423
|
+
event: {
|
|
24424
|
+
type: "interaction.closed",
|
|
24425
|
+
interactionId: pending.interaction.interactionId,
|
|
24426
|
+
turnId: this.turnId,
|
|
24427
|
+
reason
|
|
24428
|
+
}
|
|
24429
|
+
});
|
|
24430
|
+
}
|
|
24431
|
+
#error(code, message) {
|
|
24432
|
+
return { ok: false, error: { code, message, retryable: false } };
|
|
24433
|
+
}
|
|
24434
|
+
};
|
|
24435
|
+
|
|
24163
24436
|
// dist/acp-transport.js
|
|
24164
24437
|
var GrokTransportError = class extends Error {
|
|
24165
24438
|
kind;
|
|
@@ -24171,16 +24444,16 @@ var GrokTransportError = class extends Error {
|
|
|
24171
24444
|
this.name = "GrokTransportError";
|
|
24172
24445
|
}
|
|
24173
24446
|
};
|
|
24174
|
-
function
|
|
24447
|
+
function isRecord15(value) {
|
|
24175
24448
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24176
24449
|
}
|
|
24177
24450
|
function acpToolName(update, metadata) {
|
|
24178
|
-
if (!
|
|
24451
|
+
if (!isRecord15(update))
|
|
24179
24452
|
return void 0;
|
|
24180
24453
|
if (typeof update.name === "string" && update.name.length > 0)
|
|
24181
24454
|
return update.name;
|
|
24182
|
-
const meta3 =
|
|
24183
|
-
const tool = meta3 &&
|
|
24455
|
+
const meta3 = isRecord15(update._meta) ? update._meta : metadata;
|
|
24456
|
+
const tool = meta3 && isRecord15(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
24184
24457
|
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
24185
24458
|
}
|
|
24186
24459
|
function errorText(error53) {
|
|
@@ -24236,7 +24509,7 @@ function signalProcessTree(child, signal) {
|
|
|
24236
24509
|
try {
|
|
24237
24510
|
process.kill(-child.pid, signal);
|
|
24238
24511
|
} catch (error53) {
|
|
24239
|
-
if (!
|
|
24512
|
+
if (!isRecord15(error53) || error53.code !== "ESRCH")
|
|
24240
24513
|
throw error53;
|
|
24241
24514
|
}
|
|
24242
24515
|
}
|
|
@@ -24282,7 +24555,7 @@ function transportEvent(update, metadata) {
|
|
|
24282
24555
|
const resolvedToolCallId = grokElicitationResolvedToolCallId(extension);
|
|
24283
24556
|
if (resolvedToolCallId) {
|
|
24284
24557
|
return {
|
|
24285
|
-
type: "
|
|
24558
|
+
type: "interaction.resolved",
|
|
24286
24559
|
toolCallId: resolvedToolCallId,
|
|
24287
24560
|
...metadata ? { metadata } : {}
|
|
24288
24561
|
};
|
|
@@ -24354,7 +24627,7 @@ async function readNativeSignals(options, sessionId) {
|
|
|
24354
24627
|
}
|
|
24355
24628
|
}
|
|
24356
24629
|
function isMissingFile(error53) {
|
|
24357
|
-
return
|
|
24630
|
+
return isRecord15(error53) && error53.code === "ENOENT";
|
|
24358
24631
|
}
|
|
24359
24632
|
async function locateGrokNativeSession(options, sessionId) {
|
|
24360
24633
|
if (sessionId.length === 0)
|
|
@@ -24377,7 +24650,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
24377
24650
|
try {
|
|
24378
24651
|
summaryRaw = await readFile4(path15.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
24379
24652
|
} catch (error53) {
|
|
24380
|
-
if (isMissingFile(error53) ||
|
|
24653
|
+
if (isMissingFile(error53) || isRecord15(error53) && error53.code === "ENOTDIR")
|
|
24381
24654
|
continue;
|
|
24382
24655
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
24383
24656
|
cause: error53
|
|
@@ -24389,10 +24662,10 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
24389
24662
|
} catch {
|
|
24390
24663
|
continue;
|
|
24391
24664
|
}
|
|
24392
|
-
if (!
|
|
24665
|
+
if (!isRecord15(parsed))
|
|
24393
24666
|
continue;
|
|
24394
24667
|
const info = parsed.info;
|
|
24395
|
-
const cwd =
|
|
24668
|
+
const cwd = isRecord15(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path15.resolve(info.cwd) : path15.resolve(decodeURIComponent(entry.name));
|
|
24396
24669
|
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path15.resolve(parsed.source_workspace_dir) : void 0;
|
|
24397
24670
|
matches.push({
|
|
24398
24671
|
cwd,
|
|
@@ -24425,12 +24698,12 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
24425
24698
|
} catch {
|
|
24426
24699
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
24427
24700
|
}
|
|
24428
|
-
if (!
|
|
24701
|
+
if (!isRecord15(record2) || !isRecord15(record2.params))
|
|
24429
24702
|
continue;
|
|
24430
24703
|
const params = record2.params;
|
|
24431
|
-
if (params.sessionId !== sessionId || !
|
|
24704
|
+
if (params.sessionId !== sessionId || !isRecord15(params.update))
|
|
24432
24705
|
continue;
|
|
24433
|
-
const metadata =
|
|
24706
|
+
const metadata = isRecord15(params._meta) ? params._meta : void 0;
|
|
24434
24707
|
const event = transportEvent(params.update, metadata);
|
|
24435
24708
|
if (event)
|
|
24436
24709
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -24494,7 +24767,7 @@ var GrokAcpTransport = class {
|
|
|
24494
24767
|
if (!this.#connection)
|
|
24495
24768
|
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
24496
24769
|
const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
|
|
24497
|
-
return
|
|
24770
|
+
return isRecord15(result) ? result.usage : void 0;
|
|
24498
24771
|
}
|
|
24499
24772
|
async readHistory(sessionId, cwd = this.#options.cwd) {
|
|
24500
24773
|
return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
|
|
@@ -24591,6 +24864,23 @@ var GrokAcpTransport = class {
|
|
|
24591
24864
|
throw classified;
|
|
24592
24865
|
}
|
|
24593
24866
|
}
|
|
24867
|
+
async questionActivity(toolCallId) {
|
|
24868
|
+
if (!this.#connection || !this.#sessionId || !this.#activePrompt || this.#closed || this.#closing)
|
|
24869
|
+
return null;
|
|
24870
|
+
try {
|
|
24871
|
+
const raw = await withTimeout(this.#connection.request(GROK_QUESTION_ACTIVITY_METHOD, {
|
|
24872
|
+
sessionId: this.#sessionId,
|
|
24873
|
+
toolCallId
|
|
24874
|
+
}), 3e3, "Grok question activity");
|
|
24875
|
+
if (!isRecord15(raw) || !("timeout" in raw))
|
|
24876
|
+
throw new GrokTransportError("protocolError", "Invalid Grok activity acknowledgement");
|
|
24877
|
+
return raw.timeout === null ? null : questionAutoResolutionSchema.parse(raw.timeout);
|
|
24878
|
+
} catch (error53) {
|
|
24879
|
+
if (isGrokMethodNotFound(error53))
|
|
24880
|
+
return null;
|
|
24881
|
+
throw error53;
|
|
24882
|
+
}
|
|
24883
|
+
}
|
|
24594
24884
|
async #rewindSession(params) {
|
|
24595
24885
|
if (!this.#connection)
|
|
24596
24886
|
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
@@ -24690,7 +24980,7 @@ var GrokAcpTransport = class {
|
|
|
24690
24980
|
this.#initialize = initialize;
|
|
24691
24981
|
return initialize;
|
|
24692
24982
|
}
|
|
24693
|
-
async runTurn(text, onEvent, onPermission, onElicitation) {
|
|
24983
|
+
async runTurn(text, onEvent, onPermission, onElicitation, onQuestion = async () => ({ outcome: "cancelled" })) {
|
|
24694
24984
|
const connection = this.#connection;
|
|
24695
24985
|
if (!connection || !this.#sessionId || this.#closed || this.#closing) {
|
|
24696
24986
|
throw new GrokTransportError("unavailable", "Grok ACP Session is unavailable");
|
|
@@ -24699,7 +24989,7 @@ var GrokAcpTransport = class {
|
|
|
24699
24989
|
throw new Error("Grok ACP Session already has an active Prompt");
|
|
24700
24990
|
if (this.#permissionConfirmation)
|
|
24701
24991
|
throw new GrokTransportError("unavailable", "Grok ACP Session has an active operation");
|
|
24702
|
-
const active = { onEvent, onPermission, onElicitation };
|
|
24992
|
+
const active = { onEvent, onPermission, onElicitation, onQuestion };
|
|
24703
24993
|
this.#activePrompt = active;
|
|
24704
24994
|
try {
|
|
24705
24995
|
return await connection.prompt({
|
|
@@ -24762,7 +25052,7 @@ var GrokAcpTransport = class {
|
|
|
24762
25052
|
}
|
|
24763
25053
|
} : {}
|
|
24764
25054
|
});
|
|
24765
|
-
if (!
|
|
25055
|
+
if (!isRecord15(response) || !isRecord15(response._meta) || !isRecord15(response._meta.model)) {
|
|
24766
25056
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
24767
25057
|
}
|
|
24768
25058
|
const selected = response._meta.model.Ok;
|
|
@@ -24802,7 +25092,7 @@ var GrokAcpTransport = class {
|
|
|
24802
25092
|
permission_mode: mode
|
|
24803
25093
|
});
|
|
24804
25094
|
const response = await connection.request("_x.ai/session/info", { sessionId });
|
|
24805
|
-
if (!
|
|
25095
|
+
if (!isRecord15(response) || !isRecord15(response.result) || response.result.sessionId !== sessionId) {
|
|
24806
25096
|
throw new Error("Grok did not confirm the target Session");
|
|
24807
25097
|
}
|
|
24808
25098
|
})()
|
|
@@ -24857,7 +25147,7 @@ var GrokAcpTransport = class {
|
|
|
24857
25147
|
this.#availableCommands = parseGrokAvailableCommands(update.availableCommands);
|
|
24858
25148
|
return;
|
|
24859
25149
|
}
|
|
24860
|
-
const metadata =
|
|
25150
|
+
const metadata = isRecord15(notification._meta) ? notification._meta : void 0;
|
|
24861
25151
|
const event = transportEvent(notification.update, metadata);
|
|
24862
25152
|
if (!event)
|
|
24863
25153
|
return;
|
|
@@ -24872,7 +25162,7 @@ var GrokAcpTransport = class {
|
|
|
24872
25162
|
#handleExtensionNotification(method, params) {
|
|
24873
25163
|
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
24874
25164
|
return;
|
|
24875
|
-
if (typeof params.sessionId !== "string" || !
|
|
25165
|
+
if (typeof params.sessionId !== "string" || !isRecord15(params.update))
|
|
24876
25166
|
return;
|
|
24877
25167
|
this.#handleUpdate(params);
|
|
24878
25168
|
}
|
|
@@ -24883,6 +25173,18 @@ var GrokAcpTransport = class {
|
|
|
24883
25173
|
return this.#activePrompt.onPermission({ request: params, options: params.options });
|
|
24884
25174
|
}
|
|
24885
25175
|
async #handleExtMethod(method, params) {
|
|
25176
|
+
const activePrompt = !this.#closed && !this.#closing && this.#replay === null && this.#activeCompact === null ? this.#activePrompt : null;
|
|
25177
|
+
if (method === GROK_ASK_USER_QUESTION_METHOD) {
|
|
25178
|
+
let request;
|
|
25179
|
+
try {
|
|
25180
|
+
request = parseGrokQuestionRequest(params);
|
|
25181
|
+
} catch (error53) {
|
|
25182
|
+
throw RequestError.invalidParams(void 0, error53 instanceof Error ? error53.message : "Invalid Grok question");
|
|
25183
|
+
}
|
|
25184
|
+
if (!activePrompt || request.sessionId !== this.#sessionId)
|
|
25185
|
+
return { outcome: "cancelled" };
|
|
25186
|
+
return { ...await activePrompt.onQuestion(request) };
|
|
25187
|
+
}
|
|
24886
25188
|
if (method !== GROK_MCP_ELICIT_METHOD) {
|
|
24887
25189
|
throw RequestError.methodNotFound(method);
|
|
24888
25190
|
}
|
|
@@ -24890,13 +25192,13 @@ var GrokAcpTransport = class {
|
|
|
24890
25192
|
if (parsed.status === "invalid") {
|
|
24891
25193
|
throw RequestError.invalidParams(void 0, parsed.message);
|
|
24892
25194
|
}
|
|
24893
|
-
if (parsed.status === "unsupported" ||
|
|
25195
|
+
if (parsed.status === "unsupported" || !activePrompt) {
|
|
24894
25196
|
return { ...grokMcpElicitCancel() };
|
|
24895
25197
|
}
|
|
24896
25198
|
if (parsed.request.sessionId !== this.#sessionId) {
|
|
24897
25199
|
return { ...grokMcpElicitCancel() };
|
|
24898
25200
|
}
|
|
24899
|
-
return { ...await
|
|
25201
|
+
return { ...await activePrompt.onElicitation(parsed.request) };
|
|
24900
25202
|
}
|
|
24901
25203
|
#fault(error53) {
|
|
24902
25204
|
this.#permissionConfirmation?.reject(error53);
|
|
@@ -25030,7 +25332,7 @@ var SessionImportScope = class {
|
|
|
25030
25332
|
// dist/session-import.js
|
|
25031
25333
|
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
25032
25334
|
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
25033
|
-
function
|
|
25335
|
+
function isRecord16(value) {
|
|
25034
25336
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25035
25337
|
}
|
|
25036
25338
|
async function readJson(file2, signal) {
|
|
@@ -25043,7 +25345,7 @@ function processAlive(pid) {
|
|
|
25043
25345
|
process.kill(pid, 0);
|
|
25044
25346
|
return true;
|
|
25045
25347
|
} catch (error53) {
|
|
25046
|
-
return
|
|
25348
|
+
return isRecord16(error53) && error53.code === "EPERM";
|
|
25047
25349
|
}
|
|
25048
25350
|
}
|
|
25049
25351
|
async function firstUserText(file2, signal) {
|
|
@@ -25060,10 +25362,10 @@ async function firstUserText(file2, signal) {
|
|
|
25060
25362
|
} catch {
|
|
25061
25363
|
continue;
|
|
25062
25364
|
}
|
|
25063
|
-
const update =
|
|
25064
|
-
if (!
|
|
25365
|
+
const update = isRecord16(entry) && isRecord16(entry.params) ? entry.params.update : null;
|
|
25366
|
+
if (!isRecord16(update) || update.sessionUpdate !== "user_message_chunk")
|
|
25065
25367
|
continue;
|
|
25066
|
-
const text =
|
|
25368
|
+
const text = isRecord16(update.content) ? update.content.text : null;
|
|
25067
25369
|
return typeof text === "string" ? text : "";
|
|
25068
25370
|
}
|
|
25069
25371
|
return null;
|
|
@@ -25140,7 +25442,7 @@ var GrokSessionImport = class {
|
|
|
25140
25442
|
if (!Array.isArray(entries))
|
|
25141
25443
|
return active;
|
|
25142
25444
|
for (const entry of entries) {
|
|
25143
|
-
if (
|
|
25445
|
+
if (isRecord16(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
25144
25446
|
active.add(entry.session_id);
|
|
25145
25447
|
}
|
|
25146
25448
|
return active;
|
|
@@ -25189,7 +25491,7 @@ var GrokSessionImport = class {
|
|
|
25189
25491
|
return null;
|
|
25190
25492
|
try {
|
|
25191
25493
|
const summary = await readJson(files[0], signal);
|
|
25192
|
-
if (!
|
|
25494
|
+
if (!isRecord16(summary) || !isRecord16(summary.info) || summary.info.id !== nativeSessionId)
|
|
25193
25495
|
return null;
|
|
25194
25496
|
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
25195
25497
|
return null;
|
|
@@ -25416,7 +25718,7 @@ var GrokSubagentLifecycle = class {
|
|
|
25416
25718
|
};
|
|
25417
25719
|
|
|
25418
25720
|
// dist/grok-models.js
|
|
25419
|
-
function
|
|
25721
|
+
function isRecord17(value) {
|
|
25420
25722
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25421
25723
|
}
|
|
25422
25724
|
function nonBlank(value) {
|
|
@@ -25428,7 +25730,7 @@ function thinkingOptions(value) {
|
|
|
25428
25730
|
const seen = /* @__PURE__ */ new Set();
|
|
25429
25731
|
const options = [];
|
|
25430
25732
|
for (const candidate of value) {
|
|
25431
|
-
if (!
|
|
25733
|
+
if (!isRecord17(candidate) || !nonBlank(candidate.label))
|
|
25432
25734
|
continue;
|
|
25433
25735
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
25434
25736
|
if (!id.success || seen.has(id.data))
|
|
@@ -25439,7 +25741,7 @@ function thinkingOptions(value) {
|
|
|
25439
25741
|
return options;
|
|
25440
25742
|
}
|
|
25441
25743
|
function parseGrokModelState(value) {
|
|
25442
|
-
if (!
|
|
25744
|
+
if (!isRecord17(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
25443
25745
|
return null;
|
|
25444
25746
|
}
|
|
25445
25747
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -25451,12 +25753,12 @@ function parseGrokModelState(value) {
|
|
|
25451
25753
|
const models = [];
|
|
25452
25754
|
let currentThinkingOptionId;
|
|
25453
25755
|
for (const candidate of value.availableModels) {
|
|
25454
|
-
if (!
|
|
25756
|
+
if (!isRecord17(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
25455
25757
|
continue;
|
|
25456
25758
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
25457
25759
|
if (!ref.success)
|
|
25458
25760
|
continue;
|
|
25459
|
-
const metadata =
|
|
25761
|
+
const metadata = isRecord17(candidate._meta) ? candidate._meta : {};
|
|
25460
25762
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
25461
25763
|
if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
|
|
25462
25764
|
defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
|
|
@@ -25495,10 +25797,10 @@ function parseGrokModelState(value) {
|
|
|
25495
25797
|
};
|
|
25496
25798
|
}
|
|
25497
25799
|
function modelStateFromInitialize(response) {
|
|
25498
|
-
return parseGrokModelState(
|
|
25800
|
+
return parseGrokModelState(isRecord17(response._meta) ? response._meta.modelState : void 0);
|
|
25499
25801
|
}
|
|
25500
25802
|
function modelStateFromSessionResponse(response) {
|
|
25501
|
-
return parseGrokModelState(
|
|
25803
|
+
return parseGrokModelState(isRecord17(response) ? response.models : void 0);
|
|
25502
25804
|
}
|
|
25503
25805
|
function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
25504
25806
|
const selectedModel = model2;
|
|
@@ -25522,7 +25824,7 @@ import os7 from "node:os";
|
|
|
25522
25824
|
import path17 from "node:path";
|
|
25523
25825
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
25524
25826
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
25525
|
-
function
|
|
25827
|
+
function isRecord18(value) {
|
|
25526
25828
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25527
25829
|
}
|
|
25528
25830
|
function finitePercent(value) {
|
|
@@ -25531,7 +25833,7 @@ function finitePercent(value) {
|
|
|
25531
25833
|
return Math.min(100, Math.max(0, value));
|
|
25532
25834
|
}
|
|
25533
25835
|
function nonNegativeCentValue(value) {
|
|
25534
|
-
if (!
|
|
25836
|
+
if (!isRecord18(value))
|
|
25535
25837
|
return void 0;
|
|
25536
25838
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
25537
25839
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
@@ -25555,7 +25857,7 @@ function productUsageFrom(value) {
|
|
|
25555
25857
|
if (!Array.isArray(value))
|
|
25556
25858
|
return void 0;
|
|
25557
25859
|
const products = value.flatMap((entry) => {
|
|
25558
|
-
if (!
|
|
25860
|
+
if (!isRecord18(entry) || typeof entry.product !== "string")
|
|
25559
25861
|
return [];
|
|
25560
25862
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
25561
25863
|
const labels = {
|
|
@@ -25576,10 +25878,10 @@ function productUsageFrom(value) {
|
|
|
25576
25878
|
return products.length > 0 ? products : void 0;
|
|
25577
25879
|
}
|
|
25578
25880
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
25579
|
-
if (!
|
|
25881
|
+
if (!isRecord18(value) || !isRecord18(value.config))
|
|
25580
25882
|
return null;
|
|
25581
25883
|
const config2 = value.config;
|
|
25582
|
-
const period =
|
|
25884
|
+
const period = isRecord18(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
25583
25885
|
const periodType = periodTypeFrom(period?.type);
|
|
25584
25886
|
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);
|
|
25585
25887
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -25606,11 +25908,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
25606
25908
|
};
|
|
25607
25909
|
}
|
|
25608
25910
|
function selectAccessToken(auth, now) {
|
|
25609
|
-
if (!
|
|
25911
|
+
if (!isRecord18(auth))
|
|
25610
25912
|
return null;
|
|
25611
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
25913
|
+
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")));
|
|
25612
25914
|
for (const [, value] of entries) {
|
|
25613
|
-
if (!
|
|
25915
|
+
if (!isRecord18(value) || typeof value.key !== "string")
|
|
25614
25916
|
continue;
|
|
25615
25917
|
if (typeof value.expires_at === "string") {
|
|
25616
25918
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -25681,7 +25983,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
25681
25983
|
|
|
25682
25984
|
// dist/grok-usage.js
|
|
25683
25985
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
25684
|
-
function
|
|
25986
|
+
function isRecord19(value) {
|
|
25685
25987
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25686
25988
|
}
|
|
25687
25989
|
function optionalToken(value) {
|
|
@@ -25698,7 +26000,7 @@ function combineUsage(base, next) {
|
|
|
25698
26000
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
25699
26001
|
}
|
|
25700
26002
|
function usageFromNative(value) {
|
|
25701
|
-
if (!
|
|
26003
|
+
if (!isRecord19(value))
|
|
25702
26004
|
return null;
|
|
25703
26005
|
const inputTokens = optionalToken(value.inputTokens);
|
|
25704
26006
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -25722,7 +26024,7 @@ function usageFromNative(value) {
|
|
|
25722
26024
|
}
|
|
25723
26025
|
}
|
|
25724
26026
|
function usageFromResponse(value) {
|
|
25725
|
-
if (!
|
|
26027
|
+
if (!isRecord19(value))
|
|
25726
26028
|
return null;
|
|
25727
26029
|
const buckets = [
|
|
25728
26030
|
value.input_tokens,
|
|
@@ -25751,10 +26053,10 @@ var GrokTurnUsage = class {
|
|
|
25751
26053
|
#durationMs = 0;
|
|
25752
26054
|
#latestCacheHit;
|
|
25753
26055
|
constructor(base, emptySession = false) {
|
|
25754
|
-
for (const
|
|
25755
|
-
const value = base?.[
|
|
26056
|
+
for (const field2 of summedUsageFields) {
|
|
26057
|
+
const value = base?.[field2];
|
|
25756
26058
|
if (value !== void 0)
|
|
25757
|
-
this.#totals[
|
|
26059
|
+
this.#totals[field2] = value;
|
|
25758
26060
|
}
|
|
25759
26061
|
this.#cacheComplete = base?.sessionCacheUsage !== void 0 || emptySession;
|
|
25760
26062
|
}
|
|
@@ -25793,10 +26095,10 @@ var GrokTurnUsage = class {
|
|
|
25793
26095
|
if (usage?.inputTokens === void 0 || usage.cachedInputTokens === void 0)
|
|
25794
26096
|
this.#cacheComplete = false;
|
|
25795
26097
|
if (usage) {
|
|
25796
|
-
for (const
|
|
25797
|
-
const value = usage[
|
|
26098
|
+
for (const field2 of summedUsageFields) {
|
|
26099
|
+
const value = usage[field2];
|
|
25798
26100
|
if (value !== void 0)
|
|
25799
|
-
this.#totals[
|
|
26101
|
+
this.#totals[field2] = (this.#totals[field2] ?? 0) + value;
|
|
25800
26102
|
}
|
|
25801
26103
|
if (duration3 > 0 && usage.outputTokens !== void 0) {
|
|
25802
26104
|
this.#outputTokens += usage.outputTokens;
|
|
@@ -25822,7 +26124,7 @@ var GrokTurnUsage = class {
|
|
|
25822
26124
|
}
|
|
25823
26125
|
};
|
|
25824
26126
|
function usageFromSignals(value) {
|
|
25825
|
-
if (!
|
|
26127
|
+
if (!isRecord19(value))
|
|
25826
26128
|
return null;
|
|
25827
26129
|
try {
|
|
25828
26130
|
return parseHostUsage({
|
|
@@ -25842,7 +26144,7 @@ var summedUsageFields = [
|
|
|
25842
26144
|
"totalTokens"
|
|
25843
26145
|
];
|
|
25844
26146
|
function nativeCostTicks(value) {
|
|
25845
|
-
if (!
|
|
26147
|
+
if (!isRecord19(value))
|
|
25846
26148
|
return void 0;
|
|
25847
26149
|
const ticks = value.costUsdTicks;
|
|
25848
26150
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -25850,7 +26152,7 @@ function nativeCostTicks(value) {
|
|
|
25850
26152
|
return ticks;
|
|
25851
26153
|
}
|
|
25852
26154
|
function sessionCostFromNative(value, initialCostUsd) {
|
|
25853
|
-
if (!
|
|
26155
|
+
if (!isRecord19(value))
|
|
25854
26156
|
return void 0;
|
|
25855
26157
|
if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
|
|
25856
26158
|
return void 0;
|
|
@@ -25879,7 +26181,7 @@ function sessionUsageFromHistory(events) {
|
|
|
25879
26181
|
continue;
|
|
25880
26182
|
const usage = usageFromNative(event.usage);
|
|
25881
26183
|
const ticks2 = nativeCostTicks(event.usage);
|
|
25882
|
-
const complete =
|
|
26184
|
+
const complete = isRecord19(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && usage.cachedInputTokens <= usage.inputTokens;
|
|
25883
26185
|
latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
|
|
25884
26186
|
}
|
|
25885
26187
|
if (latestByKey.size === 0)
|
|
@@ -25890,11 +26192,11 @@ function sessionUsageFromHistory(events) {
|
|
|
25890
26192
|
for (const entry of latestByKey.values()) {
|
|
25891
26193
|
if (!entry.usage)
|
|
25892
26194
|
continue;
|
|
25893
|
-
for (const
|
|
25894
|
-
const value = entry.usage[
|
|
26195
|
+
for (const field2 of summedUsageFields) {
|
|
26196
|
+
const value = entry.usage[field2];
|
|
25895
26197
|
if (value === void 0)
|
|
25896
26198
|
continue;
|
|
25897
|
-
totals2[
|
|
26199
|
+
totals2[field2] = (totals2[field2] ?? 0) + value;
|
|
25898
26200
|
}
|
|
25899
26201
|
if (entry.ticks === void 0)
|
|
25900
26202
|
continue;
|
|
@@ -25933,7 +26235,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
25933
26235
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
25934
26236
|
try {
|
|
25935
26237
|
if (update?.sessionUpdate === "usage_update") {
|
|
25936
|
-
const cost =
|
|
26238
|
+
const cost = isRecord19(update.cost) ? update.cost : null;
|
|
25937
26239
|
return parseHostUsage({
|
|
25938
26240
|
contextUsedTokens: update.used,
|
|
25939
26241
|
contextWindowTokens: update.size,
|
|
@@ -26094,6 +26396,20 @@ var GrokHarnessSession = class {
|
|
|
26094
26396
|
};
|
|
26095
26397
|
this.outputs = this.#channel.outputs;
|
|
26096
26398
|
}
|
|
26399
|
+
async questionActivity(interactionId) {
|
|
26400
|
+
const active = this.#active;
|
|
26401
|
+
if (this.#phase !== "open" || !active || active.cancellationRequested)
|
|
26402
|
+
return { ok: true, value: null };
|
|
26403
|
+
try {
|
|
26404
|
+
const timeout = await active.questions.activity(interactionId, (toolCallId) => this.#transport.questionActivity?.(toolCallId) ?? Promise.resolve(null));
|
|
26405
|
+
return {
|
|
26406
|
+
ok: true,
|
|
26407
|
+
value: this.#active === active && !active.cancellationRequested ? timeout : null
|
|
26408
|
+
};
|
|
26409
|
+
} catch (error53) {
|
|
26410
|
+
return { ok: false, error: normalizeError(error53, "nativeFailure") };
|
|
26411
|
+
}
|
|
26412
|
+
}
|
|
26097
26413
|
currentConfiguration() {
|
|
26098
26414
|
return {
|
|
26099
26415
|
model: this.#state.effectiveModel ?? this.#modelState.currentModel,
|
|
@@ -26187,6 +26503,7 @@ var GrokHarnessSession = class {
|
|
|
26187
26503
|
completedItems: [],
|
|
26188
26504
|
approvals: /* @__PURE__ */ new Map(),
|
|
26189
26505
|
elicitations: /* @__PURE__ */ new Map(),
|
|
26506
|
+
questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
26190
26507
|
cancellationRequested: false,
|
|
26191
26508
|
beforeNativeTurnKeys: new Set(this.#snapshot.turns.map((turn) => turn.nativeTurnRef.nativeTurnKey)),
|
|
26192
26509
|
completion,
|
|
@@ -26194,7 +26511,7 @@ var GrokHarnessSession = class {
|
|
|
26194
26511
|
};
|
|
26195
26512
|
this.#active = active;
|
|
26196
26513
|
this.#event({ type: "turn.started", turnId: command.turnId });
|
|
26197
|
-
void this.#transport.runTurn(text, (event) => this.#handleEvent(active, event), (request) => this.#requestPermission(active, request), (request) => this.#requestElicitation(active, request)).then((response) => this.#settleFromHistory(active, terminalOutcome2(response, active.cancellationRequested), response), (error53) => this.#settleFromHistory(active, {
|
|
26514
|
+
void this.#transport.runTurn(text, (event) => this.#handleEvent(active, event), (request) => this.#requestPermission(active, request), (request) => this.#requestElicitation(active, request), (request) => this.#active === active && this.#phase === "open" && !active.cancellationRequested ? active.questions.ask(request) : Promise.resolve({ outcome: "cancelled" })).then((response) => this.#settleFromHistory(active, terminalOutcome2(response, active.cancellationRequested), response), (error53) => this.#settleFromHistory(active, {
|
|
26198
26515
|
status: "failed",
|
|
26199
26516
|
error: normalizeError(error53, "nativeFailure")
|
|
26200
26517
|
}));
|
|
@@ -26278,6 +26595,7 @@ var GrokHarnessSession = class {
|
|
|
26278
26595
|
completedItems: [],
|
|
26279
26596
|
approvals: /* @__PURE__ */ new Map(),
|
|
26280
26597
|
elicitations: /* @__PURE__ */ new Map(),
|
|
26598
|
+
questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
26281
26599
|
cancellationRequested: false,
|
|
26282
26600
|
beforeNativeTurnKeys: /* @__PURE__ */ new Set(),
|
|
26283
26601
|
completion,
|
|
@@ -26448,6 +26766,7 @@ var GrokHarnessSession = class {
|
|
|
26448
26766
|
approval.resolve({ outcome: { outcome: "cancelled" } });
|
|
26449
26767
|
}
|
|
26450
26768
|
this.#cancelActiveElicitations(active);
|
|
26769
|
+
active.questions.cancel();
|
|
26451
26770
|
try {
|
|
26452
26771
|
await this.#transport.cancel();
|
|
26453
26772
|
return { ok: true, value: { cancellationRequested: true } };
|
|
@@ -26459,8 +26778,10 @@ var GrokHarnessSession = class {
|
|
|
26459
26778
|
const active = this.#active;
|
|
26460
26779
|
const permission = active?.approvals.get(command.interactionId);
|
|
26461
26780
|
const elicitation = active?.elicitations.get(command.interactionId);
|
|
26781
|
+
if (active?.questions.has(command.interactionId))
|
|
26782
|
+
return active.questions.respond(command);
|
|
26462
26783
|
if (!active || !permission && !elicitation)
|
|
26463
|
-
return { ok: false, error: invalidState("Grok
|
|
26784
|
+
return { ok: false, error: invalidState("Grok Interaction is not pending") };
|
|
26464
26785
|
if (command.response.type !== "approval") {
|
|
26465
26786
|
return {
|
|
26466
26787
|
ok: false,
|
|
@@ -26613,7 +26934,8 @@ var GrokHarnessSession = class {
|
|
|
26613
26934
|
else if (event.type === "compaction.completed") {
|
|
26614
26935
|
active.compactionTerminal = event;
|
|
26615
26936
|
this.#completeCompaction(active, event);
|
|
26616
|
-
} else if (event.type === "
|
|
26937
|
+
} else if (event.type === "interaction.resolved") {
|
|
26938
|
+
active.questions.withdraw(event.toolCallId);
|
|
26617
26939
|
for (const pending of [...active.elicitations.values()]) {
|
|
26618
26940
|
if (pending.nativeToolCallId === event.toolCallId) {
|
|
26619
26941
|
this.#settleElicitation(active, pending, grokMcpElicitCancel(), "cancelled");
|
|
@@ -27028,6 +27350,7 @@ var GrokHarnessSession = class {
|
|
|
27028
27350
|
});
|
|
27029
27351
|
}
|
|
27030
27352
|
this.#cancelActiveElicitations(active);
|
|
27353
|
+
active.questions.cancel();
|
|
27031
27354
|
this.#active = null;
|
|
27032
27355
|
if (usage || this.#usage)
|
|
27033
27356
|
this.#publishUsage({ ...usage, ...active.usage?.metrics() }, active.command.turnId, true);
|
|
@@ -27066,6 +27389,7 @@ var GrokHarnessSession = class {
|
|
|
27066
27389
|
for (const approval of active.approvals.values())
|
|
27067
27390
|
approval.resolve({ outcome: { outcome: "cancelled" } });
|
|
27068
27391
|
this.#cancelActiveElicitations(active);
|
|
27392
|
+
active.questions.cancel();
|
|
27069
27393
|
await this.#transport.cancel().catch(() => void 0);
|
|
27070
27394
|
await Promise.race([
|
|
27071
27395
|
active.completion,
|