Files
DeepTutor/web/components/chat/home/SimpleComposerInput.tsx
Bingxi Zhao (Frank) 90a2c14c81 chore: backend + frontend follow-ons for v1.4.0-beta
Wires the new memory / capability / settings / quiz subsystems into
existing surfaces and finishes the chat-pipeline follow-on work.

Backend:
- Session services pick up the cumulative source inventory + new tool
  tags (turn_runtime, sqlite_store, pocketbase_store, protocol,
  base_session_manager).
- LlamaIndex RAG pipeline config / document_loader / retrievers
  tightened; rag/service.py routed to match.
- Sessions / unified_ws / settings / notebook routers updated for
  delete-chat-turn, multi-user, and the new tool surface.
- TutorBot manager + Zulip channel + openai_compat_provider follow-on
  fixes layered on top of the v1.3.10 SSL/Zulip sweeps.
- runtime/{banner, launcher, orchestrator}, services/setup/init,
  prompt/manager, json_parser refined for the runtime-settings
  rewrite.

Frontend:
- Co-Learn pages and session-surfaces removed (folded into chat).
- Chat composer / messages / trace / session panels, sidebars,
  common modals, markdown renderers, and i18n updated for the new
  ask_user / write_note / source-inventory flow.
- Admin, agents, co-writer, playground, book pages picked up the
  shared updates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 18:08:22 +08:00

77 lines
2.4 KiB
TypeScript

"use client";
import { memo, useCallback, useRef, useState, type RefObject } from "react";
import { useTranslation } from "react-i18next";
import { shouldSubmitOnEnter } from "@/lib/composer-keyboard";
import { useAutoSizedTextarea } from "@/lib/use-auto-sized-textarea";
interface SimpleComposerInputProps {
textareaRef: RefObject<HTMLTextAreaElement | null>;
onSend: (content: string) => void;
disabled?: boolean;
}
export const SimpleComposerInput = memo(function SimpleComposerInput({
textareaRef,
onSend,
disabled,
}: SimpleComposerInputProps) {
const { t } = useTranslation();
const [input, setInput] = useState("");
const isComposingRef = useRef(false);
useAutoSizedTextarea(textareaRef, input, { min: 42, max: 200 });
const handleInputChange = useCallback(
(e: React.ChangeEvent<HTMLTextAreaElement>) => {
setInput(e.target.value);
},
[],
);
const handleKeyDown = useCallback(
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (shouldSubmitOnEnter(e, isComposingRef.current)) {
e.preventDefault();
const content = input.trim();
if (content && !disabled) {
onSend(content);
setInput("");
}
}
},
[input, onSend, disabled],
);
const handleCompositionStart = useCallback(() => {
isComposingRef.current = true;
}, []);
const handleCompositionEnd = useCallback(() => {
// Some IMEs fire compositionend before the Enter keydown that confirms
// a candidate, so keep the guard through the current event turn.
setTimeout(() => {
isComposingRef.current = false;
}, 0);
}, []);
return (
<textarea
ref={textareaRef}
value={input}
onChange={handleInputChange}
onKeyDown={handleKeyDown}
onCompositionStart={handleCompositionStart}
onCompositionEnd={handleCompositionEnd}
placeholder={t("Type a message...")}
rows={1}
// Defensive cap — see ComposerInput for the same guard. Anything beyond
// this size belongs in an attachment, not in the textarea body.
maxLength={32000}
disabled={disabled}
className="flex-1 resize-none rounded-xl border border-[var(--border)] bg-transparent px-4 py-2.5 text-[14px] text-[var(--foreground)] outline-none transition-colors focus:border-[var(--ring)] disabled:opacity-50 placeholder:text-[var(--muted-foreground)]/40"
style={{ minHeight: 42 }}
/>
);
});