fixed reasoning

This commit is contained in:
2026-06-10 14:56:18 +03:00
parent 89158930ee
commit e9762d7921
7 changed files with 143 additions and 23 deletions
+37 -4
View File
@@ -38,6 +38,9 @@ export default function Chat() {
const [input, setInput] = useState("");
const [loading, setLoading] = useState(false);
const [streaming, setStreaming] = useState("");
const [pendingPhase, setPendingPhase] = useState<"thinking" | "preparing" | "generating">(
"thinking",
);
const [liveNotices, setLiveNotices] = useState<string[]>([]);
const bottomRef = useRef<HTMLDivElement>(null);
const { status: pomodoroStatus, refresh: refreshPomodoro } = usePomodoro();
@@ -71,7 +74,14 @@ export default function Chat() {
}, [messages, streaming, liveNotices, loading]);
const waitingForStream = loading && !streaming;
const pendingLabel = liveNotices.length > 0 ? "Обрабатываю…" : "Думаю…";
const pendingLabel =
liveNotices.length > 0
? "Обрабатываю…"
: pendingPhase === "preparing"
? "Собираю контекст…"
: pendingPhase === "generating"
? "Генерирую ответ…"
: "Думаю…";
useEffect(() => {
const seq = pomodoroStatus?.cycle?.chat_notify_seq ?? 0;
@@ -111,6 +121,7 @@ export default function Chat() {
setInput("");
setLoading(true);
setStreaming("");
setPendingPhase("thinking");
setLiveNotices([]);
const tempUser: ChatMessage = {
@@ -122,9 +133,19 @@ export default function Chat() {
setMessages((prev) => [...prev, tempUser]);
try {
let assistantText = "";
for await (const chunk of api.sendMessage(activeId, text)) {
if (chunk.event === "status") {
if (chunk.data.phase === "preparing") {
setPendingPhase("preparing");
}
if (chunk.data.phase === "generating") {
setPendingPhase("generating");
}
}
if (chunk.event === "token") {
setStreaming((prev) => prev + chunk.data.content);
assistantText += chunk.data.content;
setStreaming(assistantText);
}
if (chunk.event === "notice") {
setLiveNotices((prev) => [...prev, chunk.data.content]);
@@ -136,10 +157,22 @@ export default function Chat() {
refreshPomodoro();
}
if (chunk.event === "done") {
await loadMessages(activeId);
await loadSessions();
setStreaming("");
setLiveNotices([]);
setLoading(false);
if (assistantText.trim()) {
setMessages((prev) => [
...prev,
{
id: Date.now(),
role: "assistant",
content: assistantText,
created_at: new Date().toISOString(),
},
]);
}
void loadMessages(activeId);
void loadSessions();
}
if (chunk.event === "error") {
throw new Error(chunk.data.message);