Files
CatoandClaude e1380ee378 feat(ask): one row under an answer — suggested replies first, then follow-ups (#168)
An answer in Ask could carry two rows of buttons: chatkit's suggested replies
and Substrata's own follow-up questions (built by `followUpsFor` from the
records the answer read). Now it is one row, under the latest answer only.

- lib/ask-row.ts `answerRow`: replies first, then follow-ups; nothing twice
  (case, spacing and a trailing "?" ignored); at most five. chatkit caps
  replies at four, so at least one corpus follow-up always keeps a place.
- ResearchChat: every item sends text, so the row is chatkit's own
  `ChatReplies` via `message.replies` — not shown while a turn runs, only
  under the latest answer, a tap goes through `chat.ask` like the composer.
  One `role="group"`, named "Reply or ask next".
- AnswerFooter: the separate `answer-next` row (and its CSS) is gone; the
  footer is evidence only.
- test/ask-row.test.ts.


Claude-Session: https://claude.ai/code/session_01Mg5wrkfw95JWfmAz8yRT1j

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-09 07:32:12 -07:00

42 lines
1.5 KiB
TypeScript

/**
* The ONE row of one-tap questions under the latest answer in Ask.
*
* Two sources used to render two rows under the same answer: the model's
* suggested replies (chatkit's `quick_replies`, the conversation continuing
* in the reader's voice) and Substrata's follow-ups (`followUpsFor`, questions
* built from the records retrieval actually read). The decision was one row,
* replies first.
*
* 1. REPLIES FIRST, then the follow-ups, each in its own order.
* 2. NO SAME QUESTION TWICE, compared case-insensitively with the spacing
* and a trailing question mark ignored.
* 3. AT MOST `MAX_ROW`, so it stays one tidy wrap. chatkit caps replies at
* four, so at least one corpus follow-up always keeps a place — the
* question this assistant is sure it can answer from the records.
*
* Every item sends text exactly as the composer would, so the row is
* chatkit's own `ChatReplies`.
*/
export const MAX_ROW = 5;
function key(text: string): string {
return text.trim().replace(/\s+/g, ' ').replace(/\?+$/, '').toLowerCase();
}
export function answerRow(
replies: readonly string[] = [],
followUps: readonly string[] = [],
max: number = MAX_ROW,
): string[] {
const seen = new Set<string>();
const row: string[] = [];
for (const text of [...replies, ...followUps]) {
const k = key(text);
if (!k || seen.has(k)) continue;
seen.add(k);
row.push(text.trim());
if (row.length === max) break;
}
return row;
}