// What the chat sends with a follow-up: the earlier turns that got an answer, each with // the question as the system understood it (a rewritten follow-up, not the raw words), // so the next rewrite builds on resolved questions. The server reads only the last few // (config.WEB_HISTORY_TURNS = 4); sending just those keeps the request small. import type { RunState } from './run' import type { HistoryTurn } from './sse' export const HISTORY_TURNS = 4 // mirrors config.WEB_HISTORY_TURNS export function historyOf(turns: { question: string; run: RunState }[]): HistoryTurn[] { return turns .filter((t) => t.run.answer !== null) .slice(-HISTORY_TURNS) .map((t) => ({ question: t.run.rewrite?.question ?? t.question, answer: t.run.answer!.answer })) }