@threadbase-sh/streamer 1.69.4 → 1.69.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9583,19 +9583,39 @@ var UnknownOptionError = class extends Error {
9583
9583
  question;
9584
9584
  value;
9585
9585
  };
9586
+ var UnsupportedPromptShapeError = class extends Error {
9587
+ constructor(detail) {
9588
+ super(`Unsupported prompt shape: ${detail}`);
9589
+ this.detail = detail;
9590
+ this.name = "UnsupportedPromptShapeError";
9591
+ }
9592
+ detail;
9593
+ };
9594
+ var IncompleteAnswerError = class extends Error {
9595
+ constructor(question) {
9596
+ super(`Missing answer for question "${question}"`);
9597
+ this.question = question;
9598
+ this.name = "IncompleteAnswerError";
9599
+ }
9600
+ question;
9601
+ };
9586
9602
  function answersToKeystrokes(questions, answers) {
9587
- let out = "";
9588
- for (const q of questions) {
9589
- const raw = answers[q.question];
9590
- if (raw === void 0) {
9591
- throw new Error(`Missing answer for question "${q.question}"`);
9592
- }
9593
- const label = Array.isArray(raw) ? raw[0] : raw;
9594
- const target = q.options.findIndex((o) => o.label === label);
9595
- if (target < 0) throw new UnknownOptionError(q.question, label);
9596
- out += DOWN.repeat(target) + ENTER3;
9603
+ if (questions.length !== 1) {
9604
+ throw new UnsupportedPromptShapeError(`${questions.length} questions`);
9597
9605
  }
9598
- return out;
9606
+ const q = questions[0];
9607
+ if (q.multiSelect) throw new UnsupportedPromptShapeError("multiSelect");
9608
+ const raw = answers[q.question];
9609
+ if (raw === void 0 || Array.isArray(raw) && raw.length === 0) {
9610
+ throw new IncompleteAnswerError(q.question);
9611
+ }
9612
+ if (Array.isArray(raw) && raw.length > 1) {
9613
+ throw new UnsupportedPromptShapeError(`${raw.length} labels for a single-select question`);
9614
+ }
9615
+ const label = Array.isArray(raw) ? raw[0] : raw;
9616
+ const target = q.options.findIndex((o) => o.label === label);
9617
+ if (target < 0) throw new UnknownOptionError(q.question, label);
9618
+ return DOWN.repeat(target) + ENTER3;
9599
9619
  }
9600
9620
 
9601
9621
  // src/services/questions/resolveAnswer.ts
@@ -9609,6 +9629,10 @@ function resolveAnswer(pending, body) {
9609
9629
  return { ok: true, keys: answersToKeystrokes(pending.questions, answers) };
9610
9630
  } catch (e) {
9611
9631
  if (e instanceof UnknownOptionError) return { ok: false, reason: "unknown_option" };
9632
+ if (e instanceof UnsupportedPromptShapeError) {
9633
+ return { ok: false, reason: "unsupported_prompt_shape" };
9634
+ }
9635
+ if (e instanceof IncompleteAnswerError) return { ok: false, reason: "incomplete_answer" };
9612
9636
  throw e;
9613
9637
  }
9614
9638
  }
@@ -10636,7 +10660,14 @@ var SessionHandlers = class {
10636
10660
  const pending = this.pendingQuestions.get(sessionId);
10637
10661
  const resolution = resolveAnswer(pending, body);
10638
10662
  if (!resolution.ok) {
10639
- json(res, 400, { ok: false, reason: resolution.reason });
10663
+ const unanswerable = resolution.reason === "unsupported_prompt_shape" || resolution.reason === "incomplete_answer";
10664
+ json(res, 400, {
10665
+ ok: false,
10666
+ reason: resolution.reason,
10667
+ ...unanswerable ? {
10668
+ error: "This prompt needs an answer the app cannot give yet; answer it in the terminal"
10669
+ } : {}
10670
+ });
10640
10671
  return;
10641
10672
  }
10642
10673
  const toolUseId = pending?.toolUseId ?? "";