// src/App.js import React, { useState, useMemo } from "react"; import { login, streamChat } from "./api"; import "./App.css"; import ReactMarkdown from "react-markdown"; import remarkMath from "remark-math"; import rehypeKatex from "rehype-katex"; import "katex/dist/katex.min.css"; import remarkGfm from "remark-gfm"; // --------------------------------------------------------------------------- // QUOTES // --------------------------------------------------------------------------- const LOGIC_SAYINGS = [ "Logic is the compass; reason is the journey.", "Logic doesn\u2019t tell you where to go\u2014only how not to get lost.", "Emotion starts the fire; logic builds the fireplace.", "Logic is truth with the noise removed.", "Where logic ends, belief begins.", "Logic is the discipline of refusing to lie to yourself.", "A logical mind fears no question.", "Logic is patience armed with structure.", "Without logic, intelligence is just decoration.", "Logic turns confusion into coordinates.", "Logic is thinking that survives inspection.", "Feelings persuade; logic convinces.", "Logic is the skeleton beneath every solid idea.", "Logic is humility formalized.", "Logic is the courage to follow conclusions you don\u2019t like.", "Logic is what remains when excuses are removed.", "Logic is slow thinking that wins.", "Logic is the art of necessary consequences.", "Logic is not cold\u2014it\u2019s honest.", "Logic asks \u2018must it be so?\u2019", "Logic is the bridge between assumptions and reality.", "Logic is doubt with a method.", "Logic is reason refusing shortcuts.", "Logic is clarity earned, not assumed.", "Logic is the enemy of convenient nonsense.", "Logic is freedom from contradiction.", "Logic is the courage to say \u2018I was wrong.\u2019", "Logic is precision applied to belief.", "Logic is the difference between opinion and argument.", "Logic is trust in structure over impulse.", "Logic is thought that can be audited.", "Logic is the firewall against self-deception.", "Logic is truth, step by step.", "Logic is thinking that welcomes scrutiny.", "Logic is the difference between sounding right and being right.", "Logic is belief with a warranty.", "Logic is calm thinking in loud situations.", "Logic is the architecture of understanding.", "Logic is the slow weapon against fast lies.", "Logic is consistency made explicit.", "Logic is explanation that doesn\u2019t flinch.", "Logic is truth under constraints.", "Logic is evidence wearing syntax.", "Logic is the guardrail of intelligence.", "Logic is the art of unavoidable conclusions.", "Logic is reasoning that respects reality.", "Logic is the structure beneath insight.", "Logic is understanding without shortcuts.", "Logic is thought with integrity.", "Logic is the science of consistency.", "Logic is respect\u2014for truth, for thought, and for consequence.", ]; // --------------------------------------------------------------------------- // HELPERS // --------------------------------------------------------------------------- function fixCurrencyInMath(text) { let result = ''; let i = 0; const len = text.length; while (i < len) { // Display math: $$...$$ if (text[i] === '$' && i + 1 < len && text[i + 1] === '$' && (i === 0 || text[i - 1] !== '\\')) { let j = i + 2, close = -1; while (j < len - 1) { if (text[j] === '$' && text[j + 1] === '$' && text[j - 1] !== '\\') { close = j; break; } j++; } if (close !== -1) { let c = text.slice(i + 2, close).replace(/\\\$/g, '\\dollar{}'); result += '$$' + c + '$$'; i = close + 2; continue; } } // Inline math: $...$ if (text[i] === '$' && (i === 0 || text[i - 1] !== '\\') && (i + 1 >= len || text[i + 1] !== '$')) { let j = i + 1, close = -1; while (j < len) { if (text[j] === '$' && text[j - 1] !== '\\' && (j + 1 >= len || text[j + 1] !== '$')) { close = j; break; } j++; } if (close !== -1) { let c = text.slice(i + 1, close).replace(/\\\$/g, '\\dollar{}'); result += '$' + c + '$'; i = close + 1; continue; } } result += text[i]; i++; } return result; } function normalizeLatex(text) { if (!text) return ""; let n = text; n = n.replace(/\\\[(.+?)\\\]/gs, (_, i) => `$$${i}$$`); n = n.replace(/\\\((.+?)\\\)/gs, (_, i) => `$${i}$`); n = n.replace(/\$\$\$\$/g, "$$"); n = n.replace(/\$\$\$/g, "$$"); n = n.replace(/\\begin\{align\*?\}/g, "\\begin{aligned}"); n = n.replace(/\\end\{align\*?\}/g, "\\end{aligned}"); n = n.replace(/\\begin\{equation\*?\}/g, ""); n = n.replace(/\\end\{equation\*?\}/g, ""); n = n.replace(/\\begin\{gather\*?\}/g, "\\begin{gathered}"); n = n.replace(/\\end\{gather\*?\}/g, "\\end{gathered}"); n = n.replace(/\\begin\{eqnarray\*?\}/g, "\\begin{aligned}"); n = n.replace(/\\end\{eqnarray\*?\}/g, "\\end{aligned}"); n = fixCurrencyInMath(n); n = n.replace(/\$\$([^$]+?)\$\$/gs, (match, inner) => { const t = inner.trim(); const hasAlign = /[^\\]&/.test(t) || t.startsWith("&"); const hasEnv = /\\begin\{/.test(t); if (hasAlign && !hasEnv) return `$$\\begin{aligned}\n${t}\n\\end{aligned}$$`; return `$$${t}$$`; }); return n; } // --------------------------------------------------------------------------- // COLLAPSIBLE DEBUG SECTION // --------------------------------------------------------------------------- function DebugExpander({ title, defaultOpen = false, children }) { const [open, setOpen] = useState(defaultOpen); return (
{stripFences(message.debug.llm_analysis)}
{q.query}{" "}
{"\u2192"} {q.results_count} result{q.results_count !== 1 ? "s" : ""}
{JSON.stringify(message.debug.evidence.fact_bindings, null, 2)}