One turn: the question, the answer with its citations, and the evidence.
(props: {
turn: ChatTurn;
/** The depth the control is set to NOW. The turn carries the one it was asked with. */
depth: NeighborDepth;
/** True for the turn the offer may appear on: the last one that carries an answer. */
offerRerun: boolean;
onOpenCard: (source: CardSource) => void;
onPickCandidate: (turn: ChatTurn, candidate: SubjectCandidate) => void;
onAskAgain: (turn: ChatTurn) => void;
aiAvailable?: boolean;
modelName?: string;
requestModel?: string;
})
| 244 | |
| 245 | /** One turn: the question, the answer with its citations, and the evidence. */ |
| 246 | function Turn(props: { |
| 247 | turn: ChatTurn; |
| 248 | /** The depth the control is set to NOW. The turn carries the one it was asked with. */ |
| 249 | depth: NeighborDepth; |
| 250 | /** True for the turn the offer may appear on: the last one that carries an answer. */ |
| 251 | offerRerun: boolean; |
| 252 | onOpenCard: (source: CardSource) => void; |
| 253 | onPickCandidate: (turn: ChatTurn, candidate: SubjectCandidate) => void; |
| 254 | onAskAgain: (turn: ChatTurn) => void; |
| 255 | aiAvailable?: boolean; |
| 256 | modelName?: string; |
| 257 | requestModel?: string; |
| 258 | }): JSX.Element { |
| 259 | const { turn } = props; |
| 260 | const [open, setOpen] = useState(false); |
| 261 | const cardIds = turn.cards.map((card) => card.id); |
| 262 | const byId = new Map(turn.cards.map((card) => [card.id, card] as const)); |
| 263 | const lines = turn.answer.length === 0 ? [] : claimLines(turn.answer); |
| 264 | const shown = lines.length === 0 && turn.answer.trim().length > 0 |
| 265 | ? [turn.answer.trim()] |
| 266 | : lines; |
| 267 | const message = messageOf(turn); |
| 268 | const uncited = turn.check?.violations.filter((entry) => entry.reason === 'no-citation') ?? []; |
| 269 | const unknown = turn.check?.unknown ?? []; |
| 270 | |
| 271 | /* |
| 272 | * Das Angebot aus AC6b. |
| 273 | * |
| 274 | * Es steht nur an der LETZTEN Antwort, und nur, wenn die Einstellung seit |
| 275 | * ihr eine andere ist. An jeder Antwort waere es eine Zeile Rauschen unter |
| 276 | * jedem alten Zug; an keiner waere es der Satz im Kopf, den der Leser |
| 277 | * ueberlesen hat. |
| 278 | */ |
| 279 | const rerun = props.offerRerun && turn.depth !== props.depth; |
| 280 | const builtLines = readerLines(shown.map((text, index) => ({ id: `chat-${index}`, text }))); |
| 281 | const [aiLines, setAiLines] = useState<readonly string[] | undefined>(undefined); |
| 282 | const [aiState, setAiState] = useState<'idle' | 'running' | 'applied' | 'refused'>('idle'); |
| 283 | const [aiReason, setAiReason] = useState(''); |
| 284 | useEffect(() => { |
| 285 | globalThis.__atlasChatReader = { |
| 286 | subject: builtLines.map((line) => ({ id: line.id, text: line.text, facts: [...line.facts] })), |
| 287 | validateRewrite: (answer: string) => { |
| 288 | const outcome = applyReaderRewrite(builtLines, answer); |
| 289 | return outcome.kind === 'applied' |
| 290 | ? { applied: true, reason: '' } |
| 291 | : { applied: false, reason: outcome.reason }; |
| 292 | }, |
| 293 | }; |
| 294 | return () => { |
| 295 | globalThis.__atlasChatReader = undefined; |
| 296 | }; |
| 297 | }, [builtLines]); |
| 298 | const askAi = (): void => { |
| 299 | if (!props.aiAvailable || builtLines.length === 0) return; |
| 300 | setAiState('running'); |
| 301 | void askModel({ |
| 302 | origin: SIDECAR_ORIGIN, |
| 303 | system: READER_SYSTEM_PROMPT, |
nothing calls this directly
no test coverage detected