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