@codexhost/cli-win32-arm64 0.13.3 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +109 -11
- package/app/console-web.js +649 -132
- package/app/desktop-controller.mjs +120 -12
- package/app/host-runtime.mjs +1124 -293
- package/app/plugins/antigravity/plugin.mjs +431 -66
- package/app/plugins/claude-code/plugin.mjs +761 -139
- package/app/plugins/codebuddy/plugin.mjs +322 -68
- package/app/plugins/codex-usage/plugin.mjs +249 -102
- package/app/plugins/copilot/assets/icon.png +0 -0
- package/app/plugins/copilot/manifest.json +26 -0
- package/app/plugins/copilot/plugin.mjs +34591 -0
- package/app/plugins/cursor-cli/plugin.mjs +21011 -44970
- package/app/plugins/deepseek-harness/plugin.mjs +160 -43
- package/app/plugins/enabled.json +1 -0
- package/app/plugins/grok/plugin.mjs +565 -107
- package/app/plugins/hermes/plugin.mjs +128 -12
- package/app/plugins/kimi-code/plugin.mjs +136 -22
- package/app/plugins/kiro-cli/plugin.mjs +136 -22
- package/app/plugins/omp/plugin.mjs +2236 -2036
- package/app/plugins/opencode/plugin.mjs +187 -68
- package/app/plugins/pi/plugin.mjs +2621 -2304
- package/app/plugins/qoder/plugin.mjs +153 -36
- package/app/plugins/qoder-cn/plugin.mjs +153 -36
- package/app/plugins/workbuddy/plugin.mjs +583 -92
- package/app/plugins/zcode/plugin.mjs +183 -40
- package/app/renderer-extension.js +1758 -392
- 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
|
@@ -393,10 +393,13 @@ function usageSessionTitle(value) {
|
|
|
393
393
|
return void 0;
|
|
394
394
|
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
395
395
|
return normalized;
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
396
|
+
let title = "";
|
|
397
|
+
for (const character of normalized) {
|
|
398
|
+
if (title.length + character.length >= MAX_SESSION_TITLE_LENGTH)
|
|
399
|
+
break;
|
|
400
|
+
title += character;
|
|
401
|
+
}
|
|
402
|
+
return `${title.trimEnd()}…`;
|
|
400
403
|
}
|
|
401
404
|
function sessionIdOk(value) {
|
|
402
405
|
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
@@ -3631,10 +3634,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
3631
3634
|
const shape = def.shape;
|
|
3632
3635
|
const propValues = {};
|
|
3633
3636
|
for (const key in shape) {
|
|
3634
|
-
const
|
|
3635
|
-
if (
|
|
3637
|
+
const field2 = shape[key]._zod;
|
|
3638
|
+
if (field2.values) {
|
|
3636
3639
|
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
3637
|
-
for (const v of
|
|
3640
|
+
for (const v of field2.values)
|
|
3638
3641
|
propValues[key].add(v);
|
|
3639
3642
|
}
|
|
3640
3643
|
}
|
|
@@ -15253,10 +15256,19 @@ var model = external_exports.string().min(1).max(512);
|
|
|
15253
15256
|
var project = external_exports.string().min(1).max(4096);
|
|
15254
15257
|
var usageStatisticsParamsSchema = external_exports.strictObject({
|
|
15255
15258
|
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
15259
|
+
/** Display timezone for ranges, dates and hourly buckets; omitted means the Host's local zone. */
|
|
15260
|
+
timeZone: external_exports.string().min(1).max(128).refine((value) => {
|
|
15261
|
+
try {
|
|
15262
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
15263
|
+
return true;
|
|
15264
|
+
} catch {
|
|
15265
|
+
return false;
|
|
15266
|
+
}
|
|
15267
|
+
}, "Unsupported usage statistics timezone").optional(),
|
|
15256
15268
|
harness: harness.optional(),
|
|
15257
15269
|
model: model.nullable().optional(),
|
|
15258
15270
|
project: project.nullable().optional(),
|
|
15259
|
-
/** One
|
|
15271
|
+
/** One date in the query timezone inside the range. */
|
|
15260
15272
|
date: localDate.optional()
|
|
15261
15273
|
});
|
|
15262
15274
|
var usageStatisticsTotalsSchema = external_exports.strictObject({
|
|
@@ -15292,7 +15304,7 @@ var usageStatisticsSessionSchema = external_exports.strictObject({
|
|
|
15292
15304
|
});
|
|
15293
15305
|
var usageStatisticsResultSchema = external_exports.strictObject({
|
|
15294
15306
|
range: external_exports.enum(USAGE_STATISTICS_RANGES),
|
|
15295
|
-
/** First
|
|
15307
|
+
/** First date in the query timezone (Host local when omitted); null for all time. */
|
|
15296
15308
|
from: localDate.nullable(),
|
|
15297
15309
|
to: localDate,
|
|
15298
15310
|
/** The filters these figures apply, echoed so a late answer to older filters is recognised. */
|
|
@@ -15332,7 +15344,7 @@ var usageStatisticsResultSchema = external_exports.strictObject({
|
|
|
15332
15344
|
totals: usageStatisticsTotalsSchema,
|
|
15333
15345
|
/** Each date and Harness of the range: every filter except the day. */
|
|
15334
15346
|
daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
|
|
15335
|
-
/**
|
|
15347
|
+
/** Weekday (0 = Sunday) and hour in the query timezone, all filters applied. */
|
|
15336
15348
|
hourly: external_exports.array(external_exports.strictObject({
|
|
15337
15349
|
weekday: external_exports.number().int().min(0).max(6),
|
|
15338
15350
|
hour: external_exports.number().int().min(0).max(23),
|
|
@@ -15372,6 +15384,51 @@ var hostInteractionIdSchema = opaqueIdSchema.brand();
|
|
|
15372
15384
|
var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
|
|
15373
15385
|
var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
|
|
15374
15386
|
|
|
15387
|
+
// ../../shared-contracts/dist/thread-questions.js
|
|
15388
|
+
var field = external_exports.discriminatedUnion("type", [
|
|
15389
|
+
external_exports.object({
|
|
15390
|
+
id: external_exports.string().min(1),
|
|
15391
|
+
type: external_exports.literal("choice"),
|
|
15392
|
+
prompt: external_exports.string(),
|
|
15393
|
+
options: external_exports.array(external_exports.object({
|
|
15394
|
+
value: external_exports.string().min(1),
|
|
15395
|
+
label: external_exports.string(),
|
|
15396
|
+
description: external_exports.string().optional()
|
|
15397
|
+
})).min(1),
|
|
15398
|
+
multiple: external_exports.boolean(),
|
|
15399
|
+
allowOther: external_exports.boolean(),
|
|
15400
|
+
optional: external_exports.boolean()
|
|
15401
|
+
}),
|
|
15402
|
+
external_exports.object({
|
|
15403
|
+
id: external_exports.string().min(1),
|
|
15404
|
+
type: external_exports.literal("text"),
|
|
15405
|
+
prompt: external_exports.string(),
|
|
15406
|
+
multiline: external_exports.boolean(),
|
|
15407
|
+
secret: external_exports.literal(false),
|
|
15408
|
+
optional: external_exports.boolean(),
|
|
15409
|
+
placeholder: external_exports.string().optional(),
|
|
15410
|
+
prefill: external_exports.string().optional()
|
|
15411
|
+
})
|
|
15412
|
+
]);
|
|
15413
|
+
var threadQuestionSchema = external_exports.object({
|
|
15414
|
+
interactionId: external_exports.string().min(1),
|
|
15415
|
+
turnId: external_exports.string().min(1),
|
|
15416
|
+
title: external_exports.string().optional(),
|
|
15417
|
+
questions: external_exports.array(field).min(1)
|
|
15418
|
+
}).refine(({ questions }) => questions.some((q) => q.type === "choice" && q.multiple), {
|
|
15419
|
+
message: "Shared cards require at least one multi-select question"
|
|
15420
|
+
});
|
|
15421
|
+
var threadQuestionsListParamsSchema = external_exports.strictObject({ threadId: external_exports.string().min(1) });
|
|
15422
|
+
var threadQuestionsResultSchema = external_exports.object({ questions: external_exports.array(threadQuestionSchema) });
|
|
15423
|
+
var threadQuestionRespondParamsSchema = external_exports.strictObject({
|
|
15424
|
+
threadId: external_exports.string().min(1),
|
|
15425
|
+
turnId: external_exports.string().min(1),
|
|
15426
|
+
interactionId: external_exports.string().min(1),
|
|
15427
|
+
answers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
|
|
15428
|
+
cancelled: external_exports.boolean().default(false)
|
|
15429
|
+
});
|
|
15430
|
+
var threadQuestionRespondResultSchema = external_exports.object({ accepted: external_exports.literal(true) });
|
|
15431
|
+
|
|
15375
15432
|
// ../../shared-contracts/dist/console.js
|
|
15376
15433
|
var consoleAnnouncementSchema = external_exports.strictObject({
|
|
15377
15434
|
title: external_exports.string().trim().min(1).max(200),
|
|
@@ -15392,6 +15449,8 @@ var CONSOLE_HOST_METHODS = Object.freeze([
|
|
|
15392
15449
|
"codexhost/harness/display-settings/set",
|
|
15393
15450
|
"codexhost/harness/inspect",
|
|
15394
15451
|
"codexhost/harness/installation",
|
|
15452
|
+
"codexhost/harness/installation/start",
|
|
15453
|
+
"codexhost/harness/installation/status",
|
|
15395
15454
|
"codexhost/harness/launch-settings/get",
|
|
15396
15455
|
"codexhost/harness/launch-settings/set",
|
|
15397
15456
|
"codexhost/harness/web-ui/open",
|
|
@@ -15467,7 +15526,18 @@ var threadManualCompactionStartedSchema = external_exports.strictObject({
|
|
|
15467
15526
|
var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonnegative();
|
|
15468
15527
|
var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
|
|
15469
15528
|
var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
|
|
15529
|
+
var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text) => text.length <= maximum));
|
|
15530
|
+
var composerIndicatorsSchema = external_exports.array(external_exports.object({
|
|
15531
|
+
kind: external_exports.literal("countdown"),
|
|
15532
|
+
id: external_exports.string().min(1).max(64),
|
|
15533
|
+
expiresAtUnix: nonNegativeSafeIntegerSchema,
|
|
15534
|
+
label: indicatorTextSchema(256).optional(),
|
|
15535
|
+
tooltip: indicatorTextSchema(1024).optional()
|
|
15536
|
+
}).strict()).max(2).refine((entries) => new Set(entries.map(({ id }) => id)).size === entries.length, {
|
|
15537
|
+
message: "Composer indicator IDs must be unique"
|
|
15538
|
+
});
|
|
15470
15539
|
var threadUsageSnapshotSchema = external_exports.object({
|
|
15540
|
+
composerIndicators: composerIndicatorsSchema.optional(),
|
|
15471
15541
|
inputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15472
15542
|
cachedInputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
15473
15543
|
cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
|
|
@@ -15875,7 +15945,9 @@ var harnessSessionCapabilitiesSchema = external_exports.object({
|
|
|
15875
15945
|
}).strict().optional(),
|
|
15876
15946
|
autonomousTurns: external_exports.object({
|
|
15877
15947
|
observe: external_exports.boolean()
|
|
15878
|
-
}).strict().optional()
|
|
15948
|
+
}).strict().optional(),
|
|
15949
|
+
/** True only when `turn.steer` delivers input into the active Turn through a native primitive. */
|
|
15950
|
+
steer: external_exports.boolean().optional()
|
|
15879
15951
|
}).strict();
|
|
15880
15952
|
var harnessConfigurationStateSchema = external_exports.object({
|
|
15881
15953
|
effectiveModel: harnessModelRefSchema.optional(),
|
|
@@ -15922,7 +15994,9 @@ var harnessInspectionSchema = external_exports.union([
|
|
|
15922
15994
|
var harnessInspectParamsSchema = external_exports.object({
|
|
15923
15995
|
harnessId: harnessIdSchema,
|
|
15924
15996
|
cwd: nonBlankTextSchema2.max(16384).optional(),
|
|
15925
|
-
refresh: external_exports.boolean().optional()
|
|
15997
|
+
refresh: external_exports.boolean().optional(),
|
|
15998
|
+
/** `availability` asks only whether the Harness can run; see `InspectHarnessInput.purpose`. */
|
|
15999
|
+
purpose: external_exports.literal("availability").optional()
|
|
15926
16000
|
}).strict();
|
|
15927
16001
|
var harnessWebUiOpenParamsSchema = external_exports.object({
|
|
15928
16002
|
harnessId: harnessIdSchema
|
|
@@ -16005,6 +16079,15 @@ var threadOwnershipListResultSchema = external_exports.object({
|
|
|
16005
16079
|
seen.add(thread.threadId);
|
|
16006
16080
|
}
|
|
16007
16081
|
});
|
|
16082
|
+
var threadSteeringInspectParamsSchema = external_exports.object({
|
|
16083
|
+
threadId: hostThreadIdSchema,
|
|
16084
|
+
/** The text about to be steered; a Harness command always stops and restarts. */
|
|
16085
|
+
text: external_exports.string().optional()
|
|
16086
|
+
}).strict();
|
|
16087
|
+
var threadSteerDeliverySchema = external_exports.enum(["activeTurn", "newTurn"]);
|
|
16088
|
+
var threadSteeringInspectResultSchema = external_exports.object({
|
|
16089
|
+
delivery: external_exports.enum(["official", "activeTurn", "newTurn"])
|
|
16090
|
+
}).strict();
|
|
16008
16091
|
|
|
16009
16092
|
// ../../shared-contracts/dist/harness-plugins.js
|
|
16010
16093
|
var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
|
|
@@ -16106,6 +16189,10 @@ var harnessInstallationStateSchema = external_exports.object({
|
|
|
16106
16189
|
latestVersion: external_exports.string().min(1).max(128),
|
|
16107
16190
|
updateAvailable: external_exports.boolean(),
|
|
16108
16191
|
canUpdate: external_exports.boolean(),
|
|
16192
|
+
/** Defaults to CLI; some Harnesses ship only inside a desktop application. */
|
|
16193
|
+
versionKind: external_exports.enum(["cli", "application"]).optional(),
|
|
16194
|
+
/** Official download opened by the user; does not imply an automatic installation. */
|
|
16195
|
+
manualUpdateUrl: external_exports.url().max(2048).refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Manual updates require a credential-free HTTPS URL").optional(),
|
|
16109
16196
|
// Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
|
|
16110
16197
|
message: external_exports.string().max(2048).optional(),
|
|
16111
16198
|
messageCode: external_exports.string().min(1).max(128).optional(),
|
|
@@ -16113,6 +16200,20 @@ var harnessInstallationStateSchema = external_exports.object({
|
|
|
16113
16200
|
notice: harnessLocalizedTextSchema.optional(),
|
|
16114
16201
|
latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
|
|
16115
16202
|
}).strict();
|
|
16203
|
+
var harnessInstallationTaskParamsSchema = external_exports.object({ taskId: external_exports.string().uuid() }).strict();
|
|
16204
|
+
var harnessInstallationTaskSchema = external_exports.discriminatedUnion("status", [
|
|
16205
|
+
external_exports.object({ taskId: external_exports.string().uuid(), status: external_exports.literal("running") }).strict(),
|
|
16206
|
+
external_exports.object({
|
|
16207
|
+
taskId: external_exports.string().uuid(),
|
|
16208
|
+
status: external_exports.literal("succeeded"),
|
|
16209
|
+
result: harnessInstallationStateSchema
|
|
16210
|
+
}).strict(),
|
|
16211
|
+
external_exports.object({
|
|
16212
|
+
taskId: external_exports.string().uuid(),
|
|
16213
|
+
status: external_exports.literal("failed"),
|
|
16214
|
+
error: external_exports.object({ code: external_exports.number().int(), message: external_exports.string().min(1).max(2048) }).strict()
|
|
16215
|
+
}).strict()
|
|
16216
|
+
]);
|
|
16116
16217
|
|
|
16117
16218
|
// ../../shared-contracts/dist/codex-accounts.js
|
|
16118
16219
|
var accountIdSchema = external_exports.string().min(1).max(256).regex(/^[A-Za-z0-9._~-]+$/u);
|
|
@@ -16504,6 +16605,42 @@ function validateHostApprovalResponse(interaction, response) {
|
|
|
16504
16605
|
return interaction.actions.some(({ id }) => id === response.actionId) ? null : invalidRequest("Approval Response contains an undeclared action ID");
|
|
16505
16606
|
}
|
|
16506
16607
|
|
|
16608
|
+
// ../../harness-adapter/dist/question.js
|
|
16609
|
+
function invalidRequest2(message) {
|
|
16610
|
+
return { code: "invalidRequest", message, retryable: false };
|
|
16611
|
+
}
|
|
16612
|
+
function validateHostQuestionResponse(interaction, response) {
|
|
16613
|
+
const questionIds = new Set(interaction.questions.map(({ id }) => id));
|
|
16614
|
+
if (response.cancelled) {
|
|
16615
|
+
return Object.keys(response.answers).length === 0 ? null : invalidRequest2("Cancelled Question Response must not contain answers");
|
|
16616
|
+
}
|
|
16617
|
+
for (const answerId of Object.keys(response.answers)) {
|
|
16618
|
+
if (!questionIds.has(answerId)) {
|
|
16619
|
+
return invalidRequest2("Question Response contains an unknown Question ID");
|
|
16620
|
+
}
|
|
16621
|
+
}
|
|
16622
|
+
for (const question of interaction.questions) {
|
|
16623
|
+
const answers = response.answers[question.id] ?? [];
|
|
16624
|
+
if (!question.optional && answers.length === 0) {
|
|
16625
|
+
return invalidRequest2("Question Response omits a required answer");
|
|
16626
|
+
}
|
|
16627
|
+
if (question.type === "text") {
|
|
16628
|
+
if (answers.length > 1) {
|
|
16629
|
+
return invalidRequest2("Text Question accepts at most one answer");
|
|
16630
|
+
}
|
|
16631
|
+
continue;
|
|
16632
|
+
}
|
|
16633
|
+
if (!question.multiple && answers.length > 1) {
|
|
16634
|
+
return invalidRequest2("Single-choice Question accepts at most one answer");
|
|
16635
|
+
}
|
|
16636
|
+
const declared = new Set(question.options.map(({ value }) => value));
|
|
16637
|
+
if (!question.allowOther && answers.some((answer) => !declared.has(answer))) {
|
|
16638
|
+
return invalidRequest2("Question Response contains an undeclared choice");
|
|
16639
|
+
}
|
|
16640
|
+
}
|
|
16641
|
+
return null;
|
|
16642
|
+
}
|
|
16643
|
+
|
|
16507
16644
|
// ../../harness-adapter/dist/output-channel.js
|
|
16508
16645
|
var HarnessOutputChannel = class {
|
|
16509
16646
|
outputs;
|
|
@@ -16562,6 +16699,18 @@ function sanitizeDiagnosticTail(value) {
|
|
|
16562
16699
|
return redacted.length <= DIAGNOSTIC_TAIL_MAX_LENGTH ? redacted : redacted.slice(-DIAGNOSTIC_TAIL_MAX_LENGTH);
|
|
16563
16700
|
}
|
|
16564
16701
|
|
|
16702
|
+
// ../../harness-adapter/dist/steer.js
|
|
16703
|
+
function unsupportedSteer(harnessLabel) {
|
|
16704
|
+
return {
|
|
16705
|
+
ok: false,
|
|
16706
|
+
error: {
|
|
16707
|
+
code: "unsupported",
|
|
16708
|
+
message: `${harnessLabel} cannot steer an active Turn natively`,
|
|
16709
|
+
retryable: false
|
|
16710
|
+
}
|
|
16711
|
+
};
|
|
16712
|
+
}
|
|
16713
|
+
|
|
16565
16714
|
// ../../harness-adapter/dist/usage.js
|
|
16566
16715
|
var tokenFields = [
|
|
16567
16716
|
"inputTokens",
|
|
@@ -16589,6 +16738,7 @@ var usageFields = /* @__PURE__ */ new Set([
|
|
|
16589
16738
|
...safeIntegerFields,
|
|
16590
16739
|
...percentFields,
|
|
16591
16740
|
"sessionCacheUsage",
|
|
16741
|
+
"composerIndicators",
|
|
16592
16742
|
"totalCostUsd",
|
|
16593
16743
|
"totalCredits",
|
|
16594
16744
|
"contextUsagePercent",
|
|
@@ -16611,26 +16761,27 @@ function parseHostUsage(value) {
|
|
|
16611
16761
|
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
16612
16762
|
}
|
|
16613
16763
|
}
|
|
16614
|
-
|
|
16764
|
+
const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
|
|
16765
|
+
for (const field2 of [
|
|
16615
16766
|
"totalCredits",
|
|
16616
16767
|
"contextUsagePercent",
|
|
16617
16768
|
"apiOutputTokensPerSecond"
|
|
16618
16769
|
]) {
|
|
16619
|
-
const candidate = value[
|
|
16770
|
+
const candidate = value[field2];
|
|
16620
16771
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
|
|
16621
|
-
throw new Error(`Harness Usage '${
|
|
16772
|
+
throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
|
|
16622
16773
|
}
|
|
16623
16774
|
}
|
|
16624
|
-
for (const
|
|
16625
|
-
const candidate = value[
|
|
16775
|
+
for (const field2 of tokenFields) {
|
|
16776
|
+
const candidate = value[field2];
|
|
16626
16777
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
16627
|
-
throw new Error(`Harness Usage '${
|
|
16778
|
+
throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
|
|
16628
16779
|
}
|
|
16629
16780
|
}
|
|
16630
|
-
for (const
|
|
16631
|
-
const candidate = value[
|
|
16781
|
+
for (const field2 of safeIntegerFields) {
|
|
16782
|
+
const candidate = value[field2];
|
|
16632
16783
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
16633
|
-
throw new Error(`Harness Usage '${
|
|
16784
|
+
throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
|
|
16634
16785
|
}
|
|
16635
16786
|
}
|
|
16636
16787
|
if (value.outputTokensPerSecond !== void 0 && (typeof value.outputTokensPerSecond !== "number" || !Number.isFinite(value.outputTokensPerSecond) || value.outputTokensPerSecond < 0)) {
|
|
@@ -16639,10 +16790,10 @@ function parseHostUsage(value) {
|
|
|
16639
16790
|
if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
|
|
16640
16791
|
throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
|
|
16641
16792
|
}
|
|
16642
|
-
for (const
|
|
16643
|
-
const candidate = value[
|
|
16793
|
+
for (const field2 of percentFields) {
|
|
16794
|
+
const candidate = value[field2];
|
|
16644
16795
|
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
|
|
16645
|
-
throw new Error(`Harness Usage '${
|
|
16796
|
+
throw new Error(`Harness Usage '${field2}' must be between 0 and 100`);
|
|
16646
16797
|
}
|
|
16647
16798
|
}
|
|
16648
16799
|
if (value.sessionCacheUsage !== void 0) {
|
|
@@ -16681,9 +16832,9 @@ function parseHostUsage(value) {
|
|
|
16681
16832
|
if (value.costSource !== "publicPrice") {
|
|
16682
16833
|
throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
|
|
16683
16834
|
}
|
|
16684
|
-
return { ...value, unpricedModels: [...models] };
|
|
16835
|
+
return { ...value, ...indicators, unpricedModels: [...models] };
|
|
16685
16836
|
}
|
|
16686
|
-
return { ...value };
|
|
16837
|
+
return { ...value, ...indicators };
|
|
16687
16838
|
}
|
|
16688
16839
|
var requestTokenFields = [
|
|
16689
16840
|
"inputTokens",
|
|
@@ -21868,10 +22019,10 @@ function stringField(value, key) {
|
|
|
21868
22019
|
function numberField(value, key) {
|
|
21869
22020
|
if (!isRecord6(value))
|
|
21870
22021
|
return void 0;
|
|
21871
|
-
const
|
|
21872
|
-
if (
|
|
22022
|
+
const field2 = value[key];
|
|
22023
|
+
if (field2 === null)
|
|
21873
22024
|
return null;
|
|
21874
|
-
return typeof
|
|
22025
|
+
return typeof field2 === "number" && Number.isFinite(field2) ? field2 : void 0;
|
|
21875
22026
|
}
|
|
21876
22027
|
function decodeBytes(value) {
|
|
21877
22028
|
if (!Array.isArray(value) || value.length === 0)
|
|
@@ -22070,13 +22221,13 @@ function isRecord7(value) {
|
|
|
22070
22221
|
function idField(value, key) {
|
|
22071
22222
|
if (!isRecord7(value))
|
|
22072
22223
|
return void 0;
|
|
22073
|
-
const
|
|
22074
|
-
if (typeof
|
|
22075
|
-
const trimmed =
|
|
22224
|
+
const field2 = value[key];
|
|
22225
|
+
if (typeof field2 === "string") {
|
|
22226
|
+
const trimmed = field2.trim();
|
|
22076
22227
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
22077
22228
|
}
|
|
22078
|
-
if (typeof
|
|
22079
|
-
return String(
|
|
22229
|
+
if (typeof field2 === "number" && Number.isFinite(field2))
|
|
22230
|
+
return String(field2);
|
|
22080
22231
|
return void 0;
|
|
22081
22232
|
}
|
|
22082
22233
|
function stringField2(value, key) {
|
|
@@ -23281,6 +23432,210 @@ function grokPermissionModeSessionMeta(permissionMode) {
|
|
|
23281
23432
|
};
|
|
23282
23433
|
}
|
|
23283
23434
|
|
|
23435
|
+
// dist/permission-confirmation.js
|
|
23436
|
+
import { stripVTControlCharacters } from "node:util";
|
|
23437
|
+
var GROK_PERMISSION_MODE_METHOD = "_x.ai/yolo_mode_changed";
|
|
23438
|
+
var permissionManagerLog = "xai_grok_workspace::permission::manager=info";
|
|
23439
|
+
function grokPermissionLogFilter(existing) {
|
|
23440
|
+
return existing ? `${existing},${permissionManagerLog}` : permissionManagerLog;
|
|
23441
|
+
}
|
|
23442
|
+
var GrokPermissionConfirmation = class {
|
|
23443
|
+
#expected;
|
|
23444
|
+
#completion = Promise.withResolvers();
|
|
23445
|
+
#yolo;
|
|
23446
|
+
#auto;
|
|
23447
|
+
#buffer = "";
|
|
23448
|
+
constructor(mode) {
|
|
23449
|
+
this.#expected = grokPermissionModeSessionMeta(mode);
|
|
23450
|
+
}
|
|
23451
|
+
get completed() {
|
|
23452
|
+
return this.#completion.promise;
|
|
23453
|
+
}
|
|
23454
|
+
accept(chunk) {
|
|
23455
|
+
this.#buffer += chunk;
|
|
23456
|
+
let newline2;
|
|
23457
|
+
while ((newline2 = this.#buffer.indexOf("\n")) !== -1) {
|
|
23458
|
+
const line = stripVTControlCharacters(this.#buffer.slice(0, newline2)).trimEnd();
|
|
23459
|
+
this.#buffer = this.#buffer.slice(newline2 + 1);
|
|
23460
|
+
const match = /^\d{4}-\d{2}-\d{2}T\S+\s+INFO\s+(?:.*?: )?(always-approve|auto permission mode) set to: (true|false)$/.exec(line);
|
|
23461
|
+
if (!match)
|
|
23462
|
+
continue;
|
|
23463
|
+
const value = match[2] === "true";
|
|
23464
|
+
if (match[1] === "always-approve")
|
|
23465
|
+
this.#yolo = value;
|
|
23466
|
+
else
|
|
23467
|
+
this.#auto = value;
|
|
23468
|
+
if (this.#yolo !== void 0 && this.#yolo !== this.#expected.yoloMode || this.#auto !== void 0 && this.#auto !== this.#expected.autoMode) {
|
|
23469
|
+
this.reject(new Error("Grok did not apply the requested Permission Mode"));
|
|
23470
|
+
} else if (this.#yolo !== void 0 && this.#auto !== void 0) {
|
|
23471
|
+
this.#completion.resolve(void 0);
|
|
23472
|
+
}
|
|
23473
|
+
}
|
|
23474
|
+
if (this.#buffer.length > 16384)
|
|
23475
|
+
this.#buffer = "";
|
|
23476
|
+
}
|
|
23477
|
+
reject(error53) {
|
|
23478
|
+
this.#completion.reject(error53);
|
|
23479
|
+
}
|
|
23480
|
+
};
|
|
23481
|
+
|
|
23482
|
+
// dist/grok-questions.js
|
|
23483
|
+
var GROK_ASK_USER_QUESTION_METHOD = "_x.ai/ask_user_question";
|
|
23484
|
+
function isRecord12(value) {
|
|
23485
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23486
|
+
}
|
|
23487
|
+
function nonEmptyString(value) {
|
|
23488
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
23489
|
+
}
|
|
23490
|
+
function parseGrokQuestionRequest(value) {
|
|
23491
|
+
if (!isRecord12(value) || !nonEmptyString(value.sessionId) || !nonEmptyString(value.toolCallId) || value.mode !== "default" && value.mode !== "plan" || !Array.isArray(value.questions) || value.questions.length === 0)
|
|
23492
|
+
throw new Error("Grok question requires sessionId, toolCallId, mode and nonempty questions");
|
|
23493
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23494
|
+
const questions = value.questions.map((question) => {
|
|
23495
|
+
if (!isRecord12(question) || !nonEmptyString(question.question) || seen.has(question.question) || !Array.isArray(question.options) || question.multiSelect != null && typeof question.multiSelect !== "boolean" || question.multi_select != null && typeof question.multi_select !== "boolean")
|
|
23496
|
+
throw new Error("Grok question text must be unique and options/multiSelect must be valid");
|
|
23497
|
+
if (question.multiSelect != null && question.multi_select != null && question.multiSelect !== question.multi_select)
|
|
23498
|
+
throw new Error("Grok question contains conflicting multi-select flags");
|
|
23499
|
+
seen.add(question.question);
|
|
23500
|
+
const labels = /* @__PURE__ */ new Set();
|
|
23501
|
+
const options = question.options.map((option) => {
|
|
23502
|
+
if (!isRecord12(option) || !nonEmptyString(option.label) || labels.has(option.label) || typeof option.description !== "string" || option.preview != null && typeof option.preview !== "string")
|
|
23503
|
+
throw new Error("Grok question options require unique labels and text descriptions/previews");
|
|
23504
|
+
labels.add(option.label);
|
|
23505
|
+
return {
|
|
23506
|
+
label: option.label,
|
|
23507
|
+
description: option.description,
|
|
23508
|
+
...typeof option.preview === "string" ? { preview: option.preview } : {}
|
|
23509
|
+
};
|
|
23510
|
+
});
|
|
23511
|
+
return {
|
|
23512
|
+
question: question.question,
|
|
23513
|
+
options,
|
|
23514
|
+
multiple: question.multiSelect === true || question.multi_select === true
|
|
23515
|
+
};
|
|
23516
|
+
});
|
|
23517
|
+
return { sessionId: value.sessionId, toolCallId: value.toolCallId, mode: value.mode, questions };
|
|
23518
|
+
}
|
|
23519
|
+
var GrokQuestions = class {
|
|
23520
|
+
turnId;
|
|
23521
|
+
randomUUID;
|
|
23522
|
+
emit;
|
|
23523
|
+
#pending = /* @__PURE__ */ new Map();
|
|
23524
|
+
#seenToolCalls = /* @__PURE__ */ new Set();
|
|
23525
|
+
#closed = false;
|
|
23526
|
+
constructor(turnId, randomUUID2, emit) {
|
|
23527
|
+
this.turnId = turnId;
|
|
23528
|
+
this.randomUUID = randomUUID2;
|
|
23529
|
+
this.emit = emit;
|
|
23530
|
+
}
|
|
23531
|
+
has(interactionId) {
|
|
23532
|
+
return this.#pending.has(interactionId);
|
|
23533
|
+
}
|
|
23534
|
+
ask(request) {
|
|
23535
|
+
if (this.#closed || this.#seenToolCalls.has(request.toolCallId))
|
|
23536
|
+
return Promise.resolve({ outcome: "cancelled" });
|
|
23537
|
+
this.#seenToolCalls.add(request.toolCallId);
|
|
23538
|
+
const interaction = {
|
|
23539
|
+
type: "question",
|
|
23540
|
+
interactionId: hostInteractionIdSchema.parse(this.randomUUID()),
|
|
23541
|
+
turnId: this.turnId,
|
|
23542
|
+
title: "Grok",
|
|
23543
|
+
questions: request.questions.map((question, index) => question.options.length ? {
|
|
23544
|
+
id: `q${index}`,
|
|
23545
|
+
type: "choice",
|
|
23546
|
+
prompt: question.question,
|
|
23547
|
+
options: question.options.map(({ label, description, preview }) => ({
|
|
23548
|
+
value: label,
|
|
23549
|
+
label,
|
|
23550
|
+
description: [description, preview].filter(Boolean).join("\n\n")
|
|
23551
|
+
})),
|
|
23552
|
+
multiple: question.multiple,
|
|
23553
|
+
allowOther: true,
|
|
23554
|
+
optional: true
|
|
23555
|
+
} : {
|
|
23556
|
+
id: `q${index}`,
|
|
23557
|
+
type: "text",
|
|
23558
|
+
prompt: question.question,
|
|
23559
|
+
multiline: true,
|
|
23560
|
+
secret: false,
|
|
23561
|
+
optional: true
|
|
23562
|
+
})
|
|
23563
|
+
};
|
|
23564
|
+
return new Promise((resolve) => {
|
|
23565
|
+
this.#pending.set(interaction.interactionId, { request, interaction, resolve });
|
|
23566
|
+
this.emit({ kind: "interaction", interaction });
|
|
23567
|
+
});
|
|
23568
|
+
}
|
|
23569
|
+
respond(command) {
|
|
23570
|
+
const pending = this.#pending.get(command.interactionId);
|
|
23571
|
+
if (!pending)
|
|
23572
|
+
return this.#error("invalidState", "Grok Question is not pending");
|
|
23573
|
+
if (command.response.type !== "question")
|
|
23574
|
+
return this.#error("invalidRequest", "Grok Question requires a Question Response");
|
|
23575
|
+
const response = command.response;
|
|
23576
|
+
const error53 = validateHostQuestionResponse(pending.interaction, response);
|
|
23577
|
+
if (error53)
|
|
23578
|
+
return { ok: false, error: error53 };
|
|
23579
|
+
if (response.cancelled) {
|
|
23580
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
23581
|
+
return { ok: true, value: { accepted: true } };
|
|
23582
|
+
}
|
|
23583
|
+
const answers = /* @__PURE__ */ new Map();
|
|
23584
|
+
const annotations = /* @__PURE__ */ new Map();
|
|
23585
|
+
for (const [index, question] of pending.request.questions.entries()) {
|
|
23586
|
+
const values = response.answers[`q${index}`];
|
|
23587
|
+
if (!values?.length)
|
|
23588
|
+
continue;
|
|
23589
|
+
if (values.some((answer) => !nonEmptyString(answer)) || new Set(values).size !== values.length)
|
|
23590
|
+
return this.#error("invalidRequest", "Grok answers must be nonempty and unique");
|
|
23591
|
+
const selected = values.map((answer) => question.options.find(({ label }) => label === answer));
|
|
23592
|
+
const other = values.filter((_, position) => !selected[position]);
|
|
23593
|
+
if (other.length > 1)
|
|
23594
|
+
return this.#error("invalidRequest", "Grok question accepts only one Other response");
|
|
23595
|
+
answers.set(question.question, selected.map((option) => option?.label ?? "Other"));
|
|
23596
|
+
const previews = selected.flatMap((option) => option?.preview !== void 0 ? [option.preview] : []);
|
|
23597
|
+
if (previews.length || other.length)
|
|
23598
|
+
annotations.set(question.question, {
|
|
23599
|
+
...previews.length ? { preview: previews.join("\n\n") } : {},
|
|
23600
|
+
...other.length ? { notes: other[0] } : {}
|
|
23601
|
+
});
|
|
23602
|
+
}
|
|
23603
|
+
this.#settle(pending, {
|
|
23604
|
+
outcome: "accepted",
|
|
23605
|
+
answers: Object.fromEntries(answers),
|
|
23606
|
+
...annotations.size ? { annotations: Object.fromEntries(annotations) } : {}
|
|
23607
|
+
}, "responded");
|
|
23608
|
+
return { ok: true, value: { accepted: true } };
|
|
23609
|
+
}
|
|
23610
|
+
withdraw(toolCallId) {
|
|
23611
|
+
for (const pending of this.#pending.values()) {
|
|
23612
|
+
if (pending.request.toolCallId === toolCallId)
|
|
23613
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
23614
|
+
}
|
|
23615
|
+
}
|
|
23616
|
+
cancel() {
|
|
23617
|
+
this.#closed = true;
|
|
23618
|
+
for (const pending of this.#pending.values())
|
|
23619
|
+
this.#settle(pending, { outcome: "cancelled" }, "cancelled");
|
|
23620
|
+
}
|
|
23621
|
+
#settle(pending, response, reason) {
|
|
23622
|
+
this.#pending.delete(pending.interaction.interactionId);
|
|
23623
|
+
pending.resolve(response);
|
|
23624
|
+
this.emit({
|
|
23625
|
+
kind: "event",
|
|
23626
|
+
event: {
|
|
23627
|
+
type: "interaction.closed",
|
|
23628
|
+
interactionId: pending.interaction.interactionId,
|
|
23629
|
+
turnId: this.turnId,
|
|
23630
|
+
reason
|
|
23631
|
+
}
|
|
23632
|
+
});
|
|
23633
|
+
}
|
|
23634
|
+
#error(code, message) {
|
|
23635
|
+
return { ok: false, error: { code, message, retryable: false } };
|
|
23636
|
+
}
|
|
23637
|
+
};
|
|
23638
|
+
|
|
23284
23639
|
// dist/acp-transport.js
|
|
23285
23640
|
var GrokTransportError = class extends Error {
|
|
23286
23641
|
kind;
|
|
@@ -23292,16 +23647,16 @@ var GrokTransportError = class extends Error {
|
|
|
23292
23647
|
this.name = "GrokTransportError";
|
|
23293
23648
|
}
|
|
23294
23649
|
};
|
|
23295
|
-
function
|
|
23650
|
+
function isRecord13(value) {
|
|
23296
23651
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23297
23652
|
}
|
|
23298
23653
|
function acpToolName(update, metadata) {
|
|
23299
|
-
if (!
|
|
23654
|
+
if (!isRecord13(update))
|
|
23300
23655
|
return void 0;
|
|
23301
23656
|
if (typeof update.name === "string" && update.name.length > 0)
|
|
23302
23657
|
return update.name;
|
|
23303
|
-
const meta3 =
|
|
23304
|
-
const tool = meta3 &&
|
|
23658
|
+
const meta3 = isRecord13(update._meta) ? update._meta : metadata;
|
|
23659
|
+
const tool = meta3 && isRecord13(meta3["x.ai/tool"]) ? meta3["x.ai/tool"] : void 0;
|
|
23305
23660
|
return tool && typeof tool.name === "string" && tool.name.length > 0 ? tool.name : void 0;
|
|
23306
23661
|
}
|
|
23307
23662
|
function errorText(error53) {
|
|
@@ -23357,7 +23712,7 @@ function signalProcessTree(child, signal) {
|
|
|
23357
23712
|
try {
|
|
23358
23713
|
process.kill(-child.pid, signal);
|
|
23359
23714
|
} catch (error53) {
|
|
23360
|
-
if (!
|
|
23715
|
+
if (!isRecord13(error53) || error53.code !== "ESRCH")
|
|
23361
23716
|
throw error53;
|
|
23362
23717
|
}
|
|
23363
23718
|
}
|
|
@@ -23400,6 +23755,10 @@ function transportEvent(update, metadata) {
|
|
|
23400
23755
|
const subagent = grokSubagentEventFromUpdate(extension);
|
|
23401
23756
|
if (subagent)
|
|
23402
23757
|
return subagent;
|
|
23758
|
+
if (extension.sessionUpdate === "interaction_resolved") {
|
|
23759
|
+
const toolCallId = extension.tool_call_id ?? extension.toolCallId;
|
|
23760
|
+
return typeof toolCallId === "string" && toolCallId.trim().length > 0 ? { type: "interaction.resolved", toolCallId, ...metadata ? { metadata } : {} } : null;
|
|
23761
|
+
}
|
|
23403
23762
|
switch (update.sessionUpdate) {
|
|
23404
23763
|
case "user_message_chunk":
|
|
23405
23764
|
case "agent_message_chunk":
|
|
@@ -23467,7 +23826,7 @@ async function readNativeSignals(options, sessionId) {
|
|
|
23467
23826
|
}
|
|
23468
23827
|
}
|
|
23469
23828
|
function isMissingFile(error53) {
|
|
23470
|
-
return
|
|
23829
|
+
return isRecord13(error53) && error53.code === "ENOENT";
|
|
23471
23830
|
}
|
|
23472
23831
|
async function locateGrokNativeSession(options, sessionId) {
|
|
23473
23832
|
if (sessionId.length === 0)
|
|
@@ -23490,7 +23849,7 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23490
23849
|
try {
|
|
23491
23850
|
summaryRaw = await readFile3(path12.join(grokHomeDir(options), "sessions", entry.name, sessionId, "summary.json"), "utf8");
|
|
23492
23851
|
} catch (error53) {
|
|
23493
|
-
if (isMissingFile(error53) ||
|
|
23852
|
+
if (isMissingFile(error53) || isRecord13(error53) && error53.code === "ENOTDIR")
|
|
23494
23853
|
continue;
|
|
23495
23854
|
throw new GrokTransportError("unavailable", "Grok Native Session metadata could not be read", {
|
|
23496
23855
|
cause: error53
|
|
@@ -23502,10 +23861,10 @@ async function locateGrokNativeSession(options, sessionId) {
|
|
|
23502
23861
|
} catch {
|
|
23503
23862
|
continue;
|
|
23504
23863
|
}
|
|
23505
|
-
if (!
|
|
23864
|
+
if (!isRecord13(parsed))
|
|
23506
23865
|
continue;
|
|
23507
23866
|
const info = parsed.info;
|
|
23508
|
-
const cwd =
|
|
23867
|
+
const cwd = isRecord13(info) && typeof info.cwd === "string" && info.cwd.length > 0 ? path12.resolve(info.cwd) : path12.resolve(decodeURIComponent(entry.name));
|
|
23509
23868
|
const sourceWorkspaceDir = typeof parsed.source_workspace_dir === "string" && parsed.source_workspace_dir.length > 0 ? path12.resolve(parsed.source_workspace_dir) : void 0;
|
|
23510
23869
|
matches.push({
|
|
23511
23870
|
cwd,
|
|
@@ -23538,12 +23897,12 @@ function parseNativeHistory(contents, sessionId) {
|
|
|
23538
23897
|
} catch {
|
|
23539
23898
|
throw new GrokTransportError("protocolError", "Grok Native history contains invalid JSON");
|
|
23540
23899
|
}
|
|
23541
|
-
if (!
|
|
23900
|
+
if (!isRecord13(record2) || !isRecord13(record2.params))
|
|
23542
23901
|
continue;
|
|
23543
23902
|
const params = record2.params;
|
|
23544
|
-
if (params.sessionId !== sessionId || !
|
|
23903
|
+
if (params.sessionId !== sessionId || !isRecord13(params.update))
|
|
23545
23904
|
continue;
|
|
23546
|
-
const metadata =
|
|
23905
|
+
const metadata = isRecord13(params._meta) ? params._meta : void 0;
|
|
23547
23906
|
const event = transportEvent(params.update, metadata);
|
|
23548
23907
|
if (event)
|
|
23549
23908
|
events.push(metadata ? { ...event, metadata } : event);
|
|
@@ -23557,6 +23916,8 @@ var GrokAcpTransport = class {
|
|
|
23557
23916
|
#child = null;
|
|
23558
23917
|
#closed = false;
|
|
23559
23918
|
#closing = false;
|
|
23919
|
+
#closePromise = null;
|
|
23920
|
+
#permissionConfirmation = null;
|
|
23560
23921
|
#connection = null;
|
|
23561
23922
|
#initialize = null;
|
|
23562
23923
|
#replay = null;
|
|
@@ -23605,7 +23966,7 @@ var GrokAcpTransport = class {
|
|
|
23605
23966
|
if (!this.#connection)
|
|
23606
23967
|
throw new GrokTransportError("unavailable", "Grok ACP is unavailable");
|
|
23607
23968
|
const result = await withTimeout(this.#connection.request("_x.ai/session/usage", { sessionId: this.sessionId }), this.#options.commandTimeoutMs, "Grok Session usage");
|
|
23608
|
-
return
|
|
23969
|
+
return isRecord13(result) ? result.usage : void 0;
|
|
23609
23970
|
}
|
|
23610
23971
|
async readHistory(sessionId, cwd = this.#options.cwd) {
|
|
23611
23972
|
return readGrokNativeHistory({ ...this.#options, cwd }, sessionId);
|
|
@@ -23756,7 +24117,11 @@ var GrokAcpTransport = class {
|
|
|
23756
24117
|
const invocation = grokInvocation(executable, process.platform, this.#startupModelId);
|
|
23757
24118
|
const child = spawn(invocation.command, invocation.arguments, {
|
|
23758
24119
|
cwd: this.#options.cwd,
|
|
23759
|
-
env: {
|
|
24120
|
+
env: {
|
|
24121
|
+
...process.env,
|
|
24122
|
+
...this.#options.environment,
|
|
24123
|
+
RUST_LOG: grokPermissionLogFilter(this.#options.environment?.RUST_LOG ?? process.env.RUST_LOG)
|
|
24124
|
+
},
|
|
23760
24125
|
detached: process.platform !== "win32",
|
|
23761
24126
|
stdio: ["pipe", "pipe", "pipe"],
|
|
23762
24127
|
windowsHide: true,
|
|
@@ -23765,6 +24130,7 @@ var GrokAcpTransport = class {
|
|
|
23765
24130
|
this.#child = child;
|
|
23766
24131
|
child.stderr.on("data", (chunk) => {
|
|
23767
24132
|
this.#stderrTail = sanitizeDiagnosticTail(`${this.#stderrTail}${chunk.toString()}`);
|
|
24133
|
+
this.#permissionConfirmation?.accept(chunk.toString());
|
|
23768
24134
|
});
|
|
23769
24135
|
await withTimeout(new Promise((resolve, reject) => {
|
|
23770
24136
|
child.once("spawn", resolve);
|
|
@@ -23774,7 +24140,8 @@ var GrokAcpTransport = class {
|
|
|
23774
24140
|
const connection = new ClientSideConnection(() => ({
|
|
23775
24141
|
sessionUpdate: (params) => this.#handleUpdate(params),
|
|
23776
24142
|
requestPermission: (params) => this.#handlePermission(params),
|
|
23777
|
-
extNotification: (method, params) => this.#handleExtensionNotification(method, params)
|
|
24143
|
+
extNotification: (method, params) => this.#handleExtensionNotification(method, params),
|
|
24144
|
+
extMethod: (method, params) => this.#handleExtMethod(method, params)
|
|
23778
24145
|
}), stream);
|
|
23779
24146
|
this.#connection = connection;
|
|
23780
24147
|
child.once("error", (error53) => this.#fault(new GrokTransportError("processExited", error53.message)));
|
|
@@ -23794,14 +24161,16 @@ var GrokAcpTransport = class {
|
|
|
23794
24161
|
this.#initialize = initialize;
|
|
23795
24162
|
return initialize;
|
|
23796
24163
|
}
|
|
23797
|
-
async runTurn(text, onEvent, onPermission) {
|
|
24164
|
+
async runTurn(text, onEvent, onPermission, onQuestion = async () => ({ outcome: "cancelled" })) {
|
|
23798
24165
|
const connection = this.#connection;
|
|
23799
24166
|
if (!connection || !this.#sessionId || this.#closed || this.#closing) {
|
|
23800
24167
|
throw new GrokTransportError("unavailable", "Grok ACP Session is unavailable");
|
|
23801
24168
|
}
|
|
23802
24169
|
if (this.#activePrompt)
|
|
23803
24170
|
throw new Error("Grok ACP Session already has an active Prompt");
|
|
23804
|
-
|
|
24171
|
+
if (this.#permissionConfirmation)
|
|
24172
|
+
throw new GrokTransportError("unavailable", "Grok ACP Session has an active operation");
|
|
24173
|
+
const active = { onEvent, onPermission, onQuestion };
|
|
23805
24174
|
this.#activePrompt = active;
|
|
23806
24175
|
try {
|
|
23807
24176
|
return await connection.prompt({
|
|
@@ -23819,7 +24188,7 @@ var GrokAcpTransport = class {
|
|
|
23819
24188
|
if (!connection || !this.#sessionId || this.#closed || this.#closing) {
|
|
23820
24189
|
throw new GrokTransportError("unavailable", "Grok ACP Session is unavailable");
|
|
23821
24190
|
}
|
|
23822
|
-
if (this.#activePrompt || this.#activeCompact) {
|
|
24191
|
+
if (this.#activePrompt || this.#activeCompact || this.#permissionConfirmation) {
|
|
23823
24192
|
throw new GrokTransportError("unavailable", "Grok ACP Session already has an active operation");
|
|
23824
24193
|
}
|
|
23825
24194
|
const active = { onEvent, cancellationRequested: false };
|
|
@@ -23852,13 +24221,15 @@ var GrokAcpTransport = class {
|
|
|
23852
24221
|
const connection = this.#connection;
|
|
23853
24222
|
if (!connection || !this.#sessionId)
|
|
23854
24223
|
throw new Error("Grok ACP Session is unavailable");
|
|
24224
|
+
if (this.#permissionConfirmation)
|
|
24225
|
+
throw new GrokTransportError("unavailable", "Grok ACP Session has an active operation");
|
|
23855
24226
|
const response = await connection.request("session/set_model", {
|
|
23856
24227
|
sessionId: this.#sessionId,
|
|
23857
24228
|
modelId,
|
|
23858
24229
|
...reasoningEffort ? { reasoningEffort } : {},
|
|
23859
24230
|
...contextWindowTokens !== void 0 ? { _meta: { contextWindow: contextWindowTokens } } : {}
|
|
23860
24231
|
});
|
|
23861
|
-
if (!
|
|
24232
|
+
if (!isRecord13(response) || !isRecord13(response._meta) || !isRecord13(response._meta.model)) {
|
|
23862
24233
|
throw new GrokTransportError("protocolError", "Grok rejected Model configuration");
|
|
23863
24234
|
}
|
|
23864
24235
|
const selected = response._meta.model.Ok;
|
|
@@ -23875,14 +24246,57 @@ var GrokAcpTransport = class {
|
|
|
23875
24246
|
this.#activeCompact.cancellationRequested = true;
|
|
23876
24247
|
return connection.cancel({ sessionId: this.#sessionId });
|
|
23877
24248
|
}
|
|
23878
|
-
async
|
|
24249
|
+
async setPermissionMode(permissionModeId) {
|
|
24250
|
+
const mode = decodeGrokPermissionModeId(permissionModeId);
|
|
24251
|
+
const connection = this.#connection;
|
|
24252
|
+
const sessionId = this.#sessionId;
|
|
24253
|
+
if (!connection || !sessionId || this.#closed || this.#closing) {
|
|
24254
|
+
throw new GrokTransportError("unavailable", "Grok ACP Session is unavailable");
|
|
24255
|
+
}
|
|
24256
|
+
if (this.#activePrompt || this.#activeCompact || this.#permissionConfirmation) {
|
|
24257
|
+
throw new GrokTransportError("unavailable", "Grok ACP Session has an active operation");
|
|
24258
|
+
}
|
|
24259
|
+
const confirmation = new GrokPermissionConfirmation(mode);
|
|
24260
|
+
this.#permissionConfirmation = confirmation;
|
|
24261
|
+
try {
|
|
24262
|
+
await withTimeout(Promise.all([
|
|
24263
|
+
confirmation.completed,
|
|
24264
|
+
(async () => {
|
|
24265
|
+
const flags = grokPermissionModeSessionMeta(mode);
|
|
24266
|
+
await connection.notify(GROK_PERMISSION_MODE_METHOD, {
|
|
24267
|
+
yolo_mode: flags.yoloMode,
|
|
24268
|
+
auto_mode: flags.autoMode,
|
|
24269
|
+
permission_mode: mode
|
|
24270
|
+
});
|
|
24271
|
+
const response = await connection.request("_x.ai/session/info", { sessionId });
|
|
24272
|
+
if (!isRecord13(response) || !isRecord13(response.result) || response.result.sessionId !== sessionId) {
|
|
24273
|
+
throw new Error("Grok did not confirm the target Session");
|
|
24274
|
+
}
|
|
24275
|
+
})()
|
|
24276
|
+
]), this.#options.commandTimeoutMs, "Grok Permission Mode confirmation");
|
|
24277
|
+
if (this.#closed || this.#closing)
|
|
24278
|
+
throw new Error("Grok Session closed during configuration");
|
|
24279
|
+
} catch (cause) {
|
|
24280
|
+
const error53 = new GrokTransportError("protocolError", "Grok Permission Mode could not be confirmed; reopen the Session to continue", { cause });
|
|
24281
|
+
this.#fault(error53);
|
|
24282
|
+
await this.close();
|
|
24283
|
+
throw error53;
|
|
24284
|
+
} finally {
|
|
24285
|
+
this.#permissionConfirmation = null;
|
|
24286
|
+
}
|
|
24287
|
+
}
|
|
24288
|
+
close() {
|
|
24289
|
+
return this.#closePromise ??= this.#close();
|
|
24290
|
+
}
|
|
24291
|
+
async #close() {
|
|
23879
24292
|
if (this.#closed)
|
|
23880
24293
|
return;
|
|
23881
24294
|
this.#closing = true;
|
|
24295
|
+
this.#permissionConfirmation?.reject(new Error("Grok Session closed during configuration"));
|
|
23882
24296
|
const child = this.#child;
|
|
23883
24297
|
const connection = this.#connection;
|
|
23884
24298
|
if (connection && this.#sessionId && this.#initialize?.agentCapabilities?.sessionCapabilities?.close) {
|
|
23885
|
-
await connection.closeSession({ sessionId: this.#sessionId }).catch(() => void 0);
|
|
24299
|
+
await withTimeout(connection.closeSession({ sessionId: this.#sessionId }), this.#options.closeTimeoutMs, "Grok Session close").catch(() => void 0);
|
|
23886
24300
|
}
|
|
23887
24301
|
if (child?.stdin.writable)
|
|
23888
24302
|
child.stdin.end();
|
|
@@ -23910,7 +24324,7 @@ var GrokAcpTransport = class {
|
|
|
23910
24324
|
this.#availableCommands = parseGrokAvailableCommands(update.availableCommands);
|
|
23911
24325
|
return;
|
|
23912
24326
|
}
|
|
23913
|
-
const metadata =
|
|
24327
|
+
const metadata = isRecord13(notification._meta) ? notification._meta : void 0;
|
|
23914
24328
|
const event = transportEvent(notification.update, metadata);
|
|
23915
24329
|
if (!event)
|
|
23916
24330
|
return;
|
|
@@ -23925,7 +24339,7 @@ var GrokAcpTransport = class {
|
|
|
23925
24339
|
#handleExtensionNotification(method, params) {
|
|
23926
24340
|
if (!isGrokExtensionSessionUpdateMethod(method))
|
|
23927
24341
|
return;
|
|
23928
|
-
if (typeof params.sessionId !== "string" || !
|
|
24342
|
+
if (typeof params.sessionId !== "string" || !isRecord13(params.update))
|
|
23929
24343
|
return;
|
|
23930
24344
|
this.#handleUpdate(params);
|
|
23931
24345
|
}
|
|
@@ -23935,7 +24349,22 @@ var GrokAcpTransport = class {
|
|
|
23935
24349
|
}
|
|
23936
24350
|
return this.#activePrompt.onPermission({ request: params, options: params.options });
|
|
23937
24351
|
}
|
|
24352
|
+
async #handleExtMethod(method, params) {
|
|
24353
|
+
if (method !== GROK_ASK_USER_QUESTION_METHOD)
|
|
24354
|
+
throw RequestError.methodNotFound(method);
|
|
24355
|
+
let request;
|
|
24356
|
+
try {
|
|
24357
|
+
request = parseGrokQuestionRequest(params);
|
|
24358
|
+
} catch (error53) {
|
|
24359
|
+
throw RequestError.invalidParams(void 0, errorText(error53));
|
|
24360
|
+
}
|
|
24361
|
+
const active = this.#activePrompt;
|
|
24362
|
+
if (!active || this.#closed || this.#closing || this.#replay !== null || this.#activeCompact !== null || request.sessionId !== this.#sessionId)
|
|
24363
|
+
return { outcome: "cancelled" };
|
|
24364
|
+
return { ...await active.onQuestion(request) };
|
|
24365
|
+
}
|
|
23938
24366
|
#fault(error53) {
|
|
24367
|
+
this.#permissionConfirmation?.reject(error53);
|
|
23939
24368
|
if (this.#closing || this.#closed)
|
|
23940
24369
|
return;
|
|
23941
24370
|
this.#options.onFault?.(error53);
|
|
@@ -24066,7 +24495,7 @@ var SessionImportScope = class {
|
|
|
24066
24495
|
// dist/session-import.js
|
|
24067
24496
|
var MAX_METADATA_BYTES = 4 * 1024 * 1024;
|
|
24068
24497
|
var SUBAGENT_SESSION_KINDS = /* @__PURE__ */ new Set(["subagent", "subagent_resume"]);
|
|
24069
|
-
function
|
|
24498
|
+
function isRecord14(value) {
|
|
24070
24499
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24071
24500
|
}
|
|
24072
24501
|
async function readJson(file2, signal) {
|
|
@@ -24079,7 +24508,7 @@ function processAlive(pid) {
|
|
|
24079
24508
|
process.kill(pid, 0);
|
|
24080
24509
|
return true;
|
|
24081
24510
|
} catch (error53) {
|
|
24082
|
-
return
|
|
24511
|
+
return isRecord14(error53) && error53.code === "EPERM";
|
|
24083
24512
|
}
|
|
24084
24513
|
}
|
|
24085
24514
|
async function firstUserText(file2, signal) {
|
|
@@ -24096,10 +24525,10 @@ async function firstUserText(file2, signal) {
|
|
|
24096
24525
|
} catch {
|
|
24097
24526
|
continue;
|
|
24098
24527
|
}
|
|
24099
|
-
const update =
|
|
24100
|
-
if (!
|
|
24528
|
+
const update = isRecord14(entry) && isRecord14(entry.params) ? entry.params.update : null;
|
|
24529
|
+
if (!isRecord14(update) || update.sessionUpdate !== "user_message_chunk")
|
|
24101
24530
|
continue;
|
|
24102
|
-
const text =
|
|
24531
|
+
const text = isRecord14(update.content) ? update.content.text : null;
|
|
24103
24532
|
return typeof text === "string" ? text : "";
|
|
24104
24533
|
}
|
|
24105
24534
|
return null;
|
|
@@ -24176,7 +24605,7 @@ var GrokSessionImport = class {
|
|
|
24176
24605
|
if (!Array.isArray(entries))
|
|
24177
24606
|
return active;
|
|
24178
24607
|
for (const entry of entries) {
|
|
24179
|
-
if (
|
|
24608
|
+
if (isRecord14(entry) && typeof entry.session_id === "string" && processAlive(entry.pid))
|
|
24180
24609
|
active.add(entry.session_id);
|
|
24181
24610
|
}
|
|
24182
24611
|
return active;
|
|
@@ -24225,7 +24654,7 @@ var GrokSessionImport = class {
|
|
|
24225
24654
|
return null;
|
|
24226
24655
|
try {
|
|
24227
24656
|
const summary = await readJson(files[0], signal);
|
|
24228
|
-
if (!
|
|
24657
|
+
if (!isRecord14(summary) || !isRecord14(summary.info) || summary.info.id !== nativeSessionId)
|
|
24229
24658
|
return null;
|
|
24230
24659
|
if (typeof summary.session_kind === "string" && SUBAGENT_SESSION_KINDS.has(summary.session_kind))
|
|
24231
24660
|
return null;
|
|
@@ -24452,7 +24881,7 @@ var GrokSubagentLifecycle = class {
|
|
|
24452
24881
|
};
|
|
24453
24882
|
|
|
24454
24883
|
// dist/grok-models.js
|
|
24455
|
-
function
|
|
24884
|
+
function isRecord15(value) {
|
|
24456
24885
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24457
24886
|
}
|
|
24458
24887
|
function nonBlank(value) {
|
|
@@ -24464,7 +24893,7 @@ function thinkingOptions(value) {
|
|
|
24464
24893
|
const seen = /* @__PURE__ */ new Set();
|
|
24465
24894
|
const options = [];
|
|
24466
24895
|
for (const candidate of value) {
|
|
24467
|
-
if (!
|
|
24896
|
+
if (!isRecord15(candidate) || !nonBlank(candidate.label))
|
|
24468
24897
|
continue;
|
|
24469
24898
|
const id = harnessThinkingOptionIdSchema.safeParse(candidate.id ?? candidate.value);
|
|
24470
24899
|
if (!id.success || seen.has(id.data))
|
|
@@ -24475,7 +24904,7 @@ function thinkingOptions(value) {
|
|
|
24475
24904
|
return options;
|
|
24476
24905
|
}
|
|
24477
24906
|
function parseGrokModelState(value) {
|
|
24478
|
-
if (!
|
|
24907
|
+
if (!isRecord15(value) || !nonBlank(value.currentModelId) || !Array.isArray(value.availableModels)) {
|
|
24479
24908
|
return null;
|
|
24480
24909
|
}
|
|
24481
24910
|
const currentModel = harnessModelRefSchema.safeParse({ id: value.currentModelId });
|
|
@@ -24487,12 +24916,12 @@ function parseGrokModelState(value) {
|
|
|
24487
24916
|
const models = [];
|
|
24488
24917
|
let currentThinkingOptionId;
|
|
24489
24918
|
for (const candidate of value.availableModels) {
|
|
24490
|
-
if (!
|
|
24919
|
+
if (!isRecord15(candidate) || !nonBlank(candidate.modelId) || !nonBlank(candidate.name))
|
|
24491
24920
|
continue;
|
|
24492
24921
|
const ref = harnessModelRefSchema.safeParse({ id: candidate.modelId });
|
|
24493
24922
|
if (!ref.success)
|
|
24494
24923
|
continue;
|
|
24495
|
-
const metadata =
|
|
24924
|
+
const metadata = isRecord15(candidate._meta) ? candidate._meta : {};
|
|
24496
24925
|
const options2 = thinkingOptions(metadata.reasoningEfforts);
|
|
24497
24926
|
if (Array.isArray(metadata.contextWindows) && metadata.contextWindows.includes(5e5)) {
|
|
24498
24927
|
defaultContextWindowTokensByModel.set(ref.data.id, 5e5);
|
|
@@ -24531,10 +24960,10 @@ function parseGrokModelState(value) {
|
|
|
24531
24960
|
};
|
|
24532
24961
|
}
|
|
24533
24962
|
function modelStateFromInitialize(response) {
|
|
24534
|
-
return parseGrokModelState(
|
|
24963
|
+
return parseGrokModelState(isRecord15(response._meta) ? response._meta.modelState : void 0);
|
|
24535
24964
|
}
|
|
24536
24965
|
function modelStateFromSessionResponse(response) {
|
|
24537
|
-
return parseGrokModelState(
|
|
24966
|
+
return parseGrokModelState(isRecord15(response) ? response.models : void 0);
|
|
24538
24967
|
}
|
|
24539
24968
|
function stateForGrokModel(modelState, nativeState, model2 = modelState.currentModel, thinkingOptionId = modelState.currentThinkingOptionId, permissionModeId) {
|
|
24540
24969
|
const selectedModel = model2;
|
|
@@ -24558,7 +24987,7 @@ import os6 from "node:os";
|
|
|
24558
24987
|
import path14 from "node:path";
|
|
24559
24988
|
var GROK_CREDITS_ENDPOINT = "https://cli-chat-proxy.grok.com/v1/billing?format=credits";
|
|
24560
24989
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
24561
|
-
function
|
|
24990
|
+
function isRecord16(value) {
|
|
24562
24991
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24563
24992
|
}
|
|
24564
24993
|
function finitePercent(value) {
|
|
@@ -24567,7 +24996,7 @@ function finitePercent(value) {
|
|
|
24567
24996
|
return Math.min(100, Math.max(0, value));
|
|
24568
24997
|
}
|
|
24569
24998
|
function nonNegativeCentValue(value) {
|
|
24570
|
-
if (!
|
|
24999
|
+
if (!isRecord16(value))
|
|
24571
25000
|
return void 0;
|
|
24572
25001
|
const amount = value.val === void 0 ? 0 : value.val;
|
|
24573
25002
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount < 0)
|
|
@@ -24591,7 +25020,7 @@ function productUsageFrom(value) {
|
|
|
24591
25020
|
if (!Array.isArray(value))
|
|
24592
25021
|
return void 0;
|
|
24593
25022
|
const products = value.flatMap((entry) => {
|
|
24594
|
-
if (!
|
|
25023
|
+
if (!isRecord16(entry) || typeof entry.product !== "string")
|
|
24595
25024
|
return [];
|
|
24596
25025
|
const usagePercent = finitePercent(entry.usagePercent);
|
|
24597
25026
|
const labels = {
|
|
@@ -24612,10 +25041,10 @@ function productUsageFrom(value) {
|
|
|
24612
25041
|
return products.length > 0 ? products : void 0;
|
|
24613
25042
|
}
|
|
24614
25043
|
function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
24615
|
-
if (!
|
|
25044
|
+
if (!isRecord16(value) || !isRecord16(value.config))
|
|
24616
25045
|
return null;
|
|
24617
25046
|
const config2 = value.config;
|
|
24618
|
-
const period =
|
|
25047
|
+
const period = isRecord16(config2.currentPeriod) ? config2.currentPeriod : void 0;
|
|
24619
25048
|
const periodType = periodTypeFrom(period?.type);
|
|
24620
25049
|
const resetsAt = (typeof period?.end === "string" && period.end.length > 0 ? period.end : void 0) ?? (typeof config2.billingPeriodEnd === "string" && config2.billingPeriodEnd.length > 0 ? config2.billingPeriodEnd : void 0);
|
|
24621
25050
|
let usedPercent = finitePercent(config2.creditUsagePercent);
|
|
@@ -24642,11 +25071,11 @@ function parseGrokCreditsResponse(value, fetchedAt = (/* @__PURE__ */ new Date()
|
|
|
24642
25071
|
};
|
|
24643
25072
|
}
|
|
24644
25073
|
function selectAccessToken(auth, now) {
|
|
24645
|
-
if (!
|
|
25074
|
+
if (!isRecord16(auth))
|
|
24646
25075
|
return null;
|
|
24647
|
-
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) &&
|
|
25076
|
+
const entries = Object.entries(auth).filter(([issuer, value]) => (issuer === "https://auth.x.ai" || issuer.startsWith("https://auth.x.ai::")) && isRecord16(value) && typeof value.key === "string" && value.key.length > 0).sort(([left], [right]) => Number(right.startsWith("https://auth.x.ai")) - Number(left.startsWith("https://auth.x.ai")));
|
|
24648
25077
|
for (const [, value] of entries) {
|
|
24649
|
-
if (!
|
|
25078
|
+
if (!isRecord16(value) || typeof value.key !== "string")
|
|
24650
25079
|
continue;
|
|
24651
25080
|
if (typeof value.expires_at === "string") {
|
|
24652
25081
|
const expiresAt = Date.parse(value.expires_at);
|
|
@@ -24717,7 +25146,7 @@ async function fetchGrokCredits(input = {}) {
|
|
|
24717
25146
|
|
|
24718
25147
|
// dist/grok-usage.js
|
|
24719
25148
|
var USD_TICKS_PER_DOLLAR = 1e10;
|
|
24720
|
-
function
|
|
25149
|
+
function isRecord17(value) {
|
|
24721
25150
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24722
25151
|
}
|
|
24723
25152
|
function optionalToken(value) {
|
|
@@ -24734,7 +25163,7 @@ function combineUsage(base, next) {
|
|
|
24734
25163
|
return base === null ? next : parseHostUsage({ ...base, ...next });
|
|
24735
25164
|
}
|
|
24736
25165
|
function usageFromNative(value) {
|
|
24737
|
-
if (!
|
|
25166
|
+
if (!isRecord17(value))
|
|
24738
25167
|
return null;
|
|
24739
25168
|
const inputTokens = optionalToken(value.inputTokens);
|
|
24740
25169
|
const cachedRead = optionalToken(value.cachedReadTokens);
|
|
@@ -24758,7 +25187,7 @@ function usageFromNative(value) {
|
|
|
24758
25187
|
}
|
|
24759
25188
|
}
|
|
24760
25189
|
function usageFromResponse(value) {
|
|
24761
|
-
if (!
|
|
25190
|
+
if (!isRecord17(value))
|
|
24762
25191
|
return null;
|
|
24763
25192
|
const buckets = [
|
|
24764
25193
|
value.input_tokens,
|
|
@@ -24787,10 +25216,10 @@ var GrokTurnUsage = class {
|
|
|
24787
25216
|
#durationMs = 0;
|
|
24788
25217
|
#latestCacheHit;
|
|
24789
25218
|
constructor(base, emptySession = false) {
|
|
24790
|
-
for (const
|
|
24791
|
-
const value = base?.[
|
|
25219
|
+
for (const field2 of summedUsageFields) {
|
|
25220
|
+
const value = base?.[field2];
|
|
24792
25221
|
if (value !== void 0)
|
|
24793
|
-
this.#totals[
|
|
25222
|
+
this.#totals[field2] = value;
|
|
24794
25223
|
}
|
|
24795
25224
|
this.#cacheComplete = base?.sessionCacheUsage !== void 0 || emptySession;
|
|
24796
25225
|
}
|
|
@@ -24829,10 +25258,10 @@ var GrokTurnUsage = class {
|
|
|
24829
25258
|
if (usage?.inputTokens === void 0 || usage.cachedInputTokens === void 0)
|
|
24830
25259
|
this.#cacheComplete = false;
|
|
24831
25260
|
if (usage) {
|
|
24832
|
-
for (const
|
|
24833
|
-
const value = usage[
|
|
25261
|
+
for (const field2 of summedUsageFields) {
|
|
25262
|
+
const value = usage[field2];
|
|
24834
25263
|
if (value !== void 0)
|
|
24835
|
-
this.#totals[
|
|
25264
|
+
this.#totals[field2] = (this.#totals[field2] ?? 0) + value;
|
|
24836
25265
|
}
|
|
24837
25266
|
if (duration3 > 0 && usage.outputTokens !== void 0) {
|
|
24838
25267
|
this.#outputTokens += usage.outputTokens;
|
|
@@ -24858,7 +25287,7 @@ var GrokTurnUsage = class {
|
|
|
24858
25287
|
}
|
|
24859
25288
|
};
|
|
24860
25289
|
function usageFromSignals(value) {
|
|
24861
|
-
if (!
|
|
25290
|
+
if (!isRecord17(value))
|
|
24862
25291
|
return null;
|
|
24863
25292
|
try {
|
|
24864
25293
|
return parseHostUsage({
|
|
@@ -24878,7 +25307,7 @@ var summedUsageFields = [
|
|
|
24878
25307
|
"totalTokens"
|
|
24879
25308
|
];
|
|
24880
25309
|
function nativeCostTicks(value) {
|
|
24881
|
-
if (!
|
|
25310
|
+
if (!isRecord17(value))
|
|
24882
25311
|
return void 0;
|
|
24883
25312
|
const ticks = value.costUsdTicks;
|
|
24884
25313
|
if (typeof ticks !== "number" || !Number.isSafeInteger(ticks) || ticks < 0)
|
|
@@ -24886,7 +25315,7 @@ function nativeCostTicks(value) {
|
|
|
24886
25315
|
return ticks;
|
|
24887
25316
|
}
|
|
24888
25317
|
function sessionCostFromNative(value, initialCostUsd) {
|
|
24889
|
-
if (!
|
|
25318
|
+
if (!isRecord17(value))
|
|
24890
25319
|
return void 0;
|
|
24891
25320
|
if (value.costIsPartial !== void 0 && value.costIsPartial !== false)
|
|
24892
25321
|
return void 0;
|
|
@@ -24915,7 +25344,7 @@ function sessionUsageFromHistory(events) {
|
|
|
24915
25344
|
continue;
|
|
24916
25345
|
const usage = usageFromNative(event.usage);
|
|
24917
25346
|
const ticks2 = nativeCostTicks(event.usage);
|
|
24918
|
-
const complete =
|
|
25347
|
+
const complete = isRecord17(event.usage) && (event.usage.usageIsIncomplete === void 0 || event.usage.usageIsIncomplete === false) && usage?.inputTokens !== void 0 && usage.cachedInputTokens !== void 0 && usage.cachedInputTokens <= usage.inputTokens;
|
|
24919
25348
|
latestByKey.set(key, { usage, complete, ...ticks2 !== void 0 ? { ticks: ticks2 } : {} });
|
|
24920
25349
|
}
|
|
24921
25350
|
if (latestByKey.size === 0)
|
|
@@ -24926,11 +25355,11 @@ function sessionUsageFromHistory(events) {
|
|
|
24926
25355
|
for (const entry of latestByKey.values()) {
|
|
24927
25356
|
if (!entry.usage)
|
|
24928
25357
|
continue;
|
|
24929
|
-
for (const
|
|
24930
|
-
const value = entry.usage[
|
|
25358
|
+
for (const field2 of summedUsageFields) {
|
|
25359
|
+
const value = entry.usage[field2];
|
|
24931
25360
|
if (value === void 0)
|
|
24932
25361
|
continue;
|
|
24933
|
-
totals2[
|
|
25362
|
+
totals2[field2] = (totals2[field2] ?? 0) + value;
|
|
24934
25363
|
}
|
|
24935
25364
|
if (entry.ticks === void 0)
|
|
24936
25365
|
continue;
|
|
@@ -24969,7 +25398,7 @@ function usageFromCompact(tokensAfter, contextWindowTokens) {
|
|
|
24969
25398
|
function usageFromUpdate(update, metadata, contextWindowTokens) {
|
|
24970
25399
|
try {
|
|
24971
25400
|
if (update?.sessionUpdate === "usage_update") {
|
|
24972
|
-
const cost =
|
|
25401
|
+
const cost = isRecord17(update.cost) ? update.cost : null;
|
|
24973
25402
|
return parseHostUsage({
|
|
24974
25403
|
contextUsedTokens: update.used,
|
|
24975
25404
|
contextWindowTokens: update.size,
|
|
@@ -25009,7 +25438,7 @@ function capabilitiesForModels(modelState) {
|
|
|
25009
25438
|
selectModel: modelState.catalog.models.length > 0,
|
|
25010
25439
|
selectThinkingOption: modelState.catalog.thinkingOptions.length > 0,
|
|
25011
25440
|
selectPermissionMode: true,
|
|
25012
|
-
permissionModeScope: "
|
|
25441
|
+
permissionModeScope: "live"
|
|
25013
25442
|
},
|
|
25014
25443
|
history: { fork: true, forkAcrossCwd: true, rollbackLastTurn: true },
|
|
25015
25444
|
subagents: { observe: true, readTranscript: true }
|
|
@@ -25163,6 +25592,8 @@ var GrokHarnessSession = class {
|
|
|
25163
25592
|
return { ok: false, error: invalidState("Grok Session is not open") };
|
|
25164
25593
|
if ("commandId" in command)
|
|
25165
25594
|
return this.#executeHarnessCommand(command);
|
|
25595
|
+
if (command.type === "turn.steer")
|
|
25596
|
+
return unsupportedSteer("Grok");
|
|
25166
25597
|
if (command.type === "turn.cancel")
|
|
25167
25598
|
return this.#cancel(command);
|
|
25168
25599
|
if (command.type === "interaction.respond")
|
|
@@ -25205,6 +25636,7 @@ var GrokHarnessSession = class {
|
|
|
25205
25636
|
});
|
|
25206
25637
|
const active = {
|
|
25207
25638
|
command,
|
|
25639
|
+
questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
25208
25640
|
usage: new GrokTurnUsage(this.#usage, this.#snapshot.turns.length === 0),
|
|
25209
25641
|
agent: null,
|
|
25210
25642
|
agentMessageId: null,
|
|
@@ -25226,7 +25658,7 @@ var GrokHarnessSession = class {
|
|
|
25226
25658
|
};
|
|
25227
25659
|
this.#active = active;
|
|
25228
25660
|
this.#event({ type: "turn.started", turnId: command.turnId });
|
|
25229
|
-
void this.#transport.runTurn(text, (event) => this.#handleEvent(active, event), (request) => this.#requestPermission(active, request)).then((response) => this.#settleFromHistory(active, terminalOutcome2(response, active.cancellationRequested), response), (error53) => this.#settleFromHistory(active, {
|
|
25661
|
+
void this.#transport.runTurn(text, (event) => this.#handleEvent(active, event), (request) => this.#requestPermission(active, request), (request) => this.#active === active && this.#phase === "open" && !active.cancellationRequested ? active.questions.ask(request) : Promise.resolve({ outcome: "cancelled" })).finally(() => active.questions.cancel()).then((response) => this.#settleFromHistory(active, terminalOutcome2(response, active.cancellationRequested), response), (error53) => this.#settleFromHistory(active, {
|
|
25230
25662
|
status: "failed",
|
|
25231
25663
|
error: normalizeError(error53, "nativeFailure")
|
|
25232
25664
|
}));
|
|
@@ -25295,6 +25727,7 @@ var GrokHarnessSession = class {
|
|
|
25295
25727
|
});
|
|
25296
25728
|
const active = {
|
|
25297
25729
|
command: { type: "turn.start", turnId: command.turnId, input: [] },
|
|
25730
|
+
questions: new GrokQuestions(command.turnId, this.#randomUUID, (output) => this.#channel.emit(output)),
|
|
25298
25731
|
agent: null,
|
|
25299
25732
|
agentMessageId: null,
|
|
25300
25733
|
rawAgentText: "",
|
|
@@ -25442,14 +25875,29 @@ var GrokHarnessSession = class {
|
|
|
25442
25875
|
}
|
|
25443
25876
|
};
|
|
25444
25877
|
}
|
|
25445
|
-
|
|
25446
|
-
|
|
25447
|
-
|
|
25448
|
-
|
|
25449
|
-
|
|
25450
|
-
|
|
25451
|
-
|
|
25452
|
-
|
|
25878
|
+
if (this.#active || this.#configuring) {
|
|
25879
|
+
return {
|
|
25880
|
+
ok: false,
|
|
25881
|
+
error: {
|
|
25882
|
+
code: "sessionBusy",
|
|
25883
|
+
message: "Grok Session cannot configure permissions during another operation",
|
|
25884
|
+
retryable: true
|
|
25885
|
+
}
|
|
25886
|
+
};
|
|
25887
|
+
}
|
|
25888
|
+
this.#configuring = true;
|
|
25889
|
+
try {
|
|
25890
|
+
await this.#transport.setPermissionMode(command.permissionModeId);
|
|
25891
|
+
if (this.#phase !== "open")
|
|
25892
|
+
return { ok: false, error: invalidState("Grok Session is closed") };
|
|
25893
|
+
this.#state = { ...this.#state, effectivePermissionModeId: command.permissionModeId };
|
|
25894
|
+
this.#event({ type: "session.state.changed", state: this.#state });
|
|
25895
|
+
return { ok: true, value: { completed: true } };
|
|
25896
|
+
} catch (error53) {
|
|
25897
|
+
return { ok: false, error: normalizeError(error53, "nativeFailure") };
|
|
25898
|
+
} finally {
|
|
25899
|
+
this.#configuring = false;
|
|
25900
|
+
}
|
|
25453
25901
|
}
|
|
25454
25902
|
async #cancel(command) {
|
|
25455
25903
|
const active = this.#active;
|
|
@@ -25459,6 +25907,7 @@ var GrokHarnessSession = class {
|
|
|
25459
25907
|
if (active.cancellationRequested)
|
|
25460
25908
|
return { ok: true, value: { cancellationRequested: true } };
|
|
25461
25909
|
active.cancellationRequested = true;
|
|
25910
|
+
active.questions.cancel();
|
|
25462
25911
|
for (const approval of active.approvals.values()) {
|
|
25463
25912
|
approval.resolve({ outcome: { outcome: "cancelled" } });
|
|
25464
25913
|
}
|
|
@@ -25471,9 +25920,11 @@ var GrokHarnessSession = class {
|
|
|
25471
25920
|
}
|
|
25472
25921
|
async #respond(command) {
|
|
25473
25922
|
const active = this.#active;
|
|
25923
|
+
if (active?.questions.has(command.interactionId))
|
|
25924
|
+
return active.questions.respond(command);
|
|
25474
25925
|
const pending = active?.approvals.get(command.interactionId);
|
|
25475
25926
|
if (!active || !pending)
|
|
25476
|
-
return { ok: false, error: invalidState("Grok
|
|
25927
|
+
return { ok: false, error: invalidState("Grok Interaction is not pending") };
|
|
25477
25928
|
if (command.response.type !== "approval") {
|
|
25478
25929
|
return {
|
|
25479
25930
|
ok: false,
|
|
@@ -25534,6 +25985,10 @@ var GrokHarnessSession = class {
|
|
|
25534
25985
|
#handleEvent(active, event) {
|
|
25535
25986
|
if (this.#active !== active || this.#phase !== "open")
|
|
25536
25987
|
return;
|
|
25988
|
+
if (event.type === "interaction.resolved") {
|
|
25989
|
+
active.questions.withdraw(event.toolCallId);
|
|
25990
|
+
return;
|
|
25991
|
+
}
|
|
25537
25992
|
const requestUsage = active.usage?.observe(event);
|
|
25538
25993
|
if (requestUsage) {
|
|
25539
25994
|
this.#publishUsage(requestUsage, active.command.turnId, true);
|
|
@@ -25933,6 +26388,7 @@ var GrokHarnessSession = class {
|
|
|
25933
26388
|
#finish(active, outcome, usage = null, nativeTurnRef) {
|
|
25934
26389
|
if (this.#active !== active)
|
|
25935
26390
|
return;
|
|
26391
|
+
active.questions.cancel();
|
|
25936
26392
|
const itemOutcome = outcome;
|
|
25937
26393
|
this.#completeReasoning(active, itemOutcome);
|
|
25938
26394
|
this.#completeAgent(active, itemOutcome);
|
|
@@ -25989,6 +26445,7 @@ var GrokHarnessSession = class {
|
|
|
25989
26445
|
const active = this.#active;
|
|
25990
26446
|
if (active) {
|
|
25991
26447
|
active.cancellationRequested = true;
|
|
26448
|
+
active.questions.cancel();
|
|
25992
26449
|
for (const approval of active.approvals.values())
|
|
25993
26450
|
approval.resolve({ outcome: { outcome: "cancelled" } });
|
|
25994
26451
|
await this.#transport.cancel().catch(() => void 0);
|
|
@@ -26343,6 +26800,7 @@ var GrokAdapter = class {
|
|
|
26343
26800
|
]);
|
|
26344
26801
|
}
|
|
26345
26802
|
}
|
|
26803
|
+
await transport.setPermissionMode(initialPermissionModeId);
|
|
26346
26804
|
const history = await transport.getHistory();
|
|
26347
26805
|
let initialUsage = input.kind === "resume" || input.kind === "fork" || input.kind === "rollbackLastTurn" ? combineUsage(sessionUsageFromHistory(history), usageFromSignals(opened.signals)) : null;
|
|
26348
26806
|
if (contextWindow !== void 0 && initialUsage?.contextUsedTokens !== void 0) {
|