HEL-875: 接上真实主动留言,保全视觉总监原始补丁
Apply the exact eight-file HEL-875 patch from the visual director on 31970c4. Independently reran 49 frontend tests, typecheck/lint/build and original Python requirement checks. Candidate only; intake found pagination overflow dropping older reach-outs after >250 new records, requiring author repair before approval or deployment.
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -15,11 +15,14 @@ const START: Anchor = { mi: 0, offset: 0 };
|
||||
const metricsFor = (width: number): Metrics => { const compact = document.documentElement.classList.contains('compact'); return { width, font: compact ? 16 : innerWidth <= 720 ? 18 : 23, compact }; };
|
||||
const typingTarget = (el: Element | null) => !!el && (el.matches('textarea,input,select,[contenteditable="true"]'));
|
||||
|
||||
const NO_IDS: string[] = [];
|
||||
export function ChatPanel({ state, onChange, onPresence, onVoice, onObservation, onRecord, offline, fail, log, setLog, focusLife, focusIds = NO_IDS, real = false, onReceipt }: {
|
||||
const NO_IDS: string[] = [], NO_MESSAGES: Message[] = [];
|
||||
export function ChatPanel({ state, onChange, onPresence, onVoice, onObservation, onRecord, offline, fail, log, setLog, focusLife, focusIds = NO_IDS, real = false, onReceipt, incoming = NO_MESSAGES, onAdmit }: {
|
||||
real?: boolean;
|
||||
// Real only: the server accepted a complete-receipt confirmation (the life it may unlock is decided later).
|
||||
onReceipt?: () => void;
|
||||
// Real only: her own messages that reached the open page while you are here, not yet on the stage.
|
||||
incoming?: Message[];
|
||||
onAdmit?: (ids: string[]) => void;
|
||||
state: DemoState;
|
||||
onChange: (messages: Message[]) => void;
|
||||
onPresence: (p: string) => void;
|
||||
@@ -72,6 +75,11 @@ export function ChatPanel({ state, onChange, onPresence, onVoice, onObservation,
|
||||
if (cursor > headIndex) head.current = anchor;
|
||||
const held = useRef(new Set<string>()), clock = useRef(new ReadingClock());
|
||||
const reading = useRef({ pages, cursor, flow }); reading.current = { pages, cursor, flow };
|
||||
// Her own message that arrives while you are here waits its turn: never while she is answering you, a sheet is
|
||||
// open, you paused or went back, or the line on screen has not had its time. Then it comes in as a new turn.
|
||||
const waiting = useRef({ count: 0, busy: false, sheet: false }), admit = useRef(() => {});
|
||||
waiting.current = { count: incoming.length, busy, sheet: log || full };
|
||||
admit.current = () => { const add = incoming.filter(m => !live.current.some(k => k.id === m.id)); onAdmit?.(incoming.map(m => m.id)); if (add.length) change([...live.current, ...add]); };
|
||||
|
||||
function stop() { gate.current.cancel(); if (replyLive.current) setInterrupted({ text: replyLive.current, turn: turnLive.current }); replyLive.current = ''; setBusy(false); setReply(''); onPresence('停下来了'); change(live.current.map(m => m.status === 'pending' ? { ...m, status: 'cancelled' } : m)); }
|
||||
function endVoice() { stop(); voiceController.current?.abort(); setVoice(false); onVoice(false); onPresence('在你面前'); }
|
||||
@@ -119,8 +127,10 @@ export function ChatPanel({ state, onChange, onPresence, onVoice, onObservation,
|
||||
let raf = 0;
|
||||
const c = clock.current, away = () => c.pause();
|
||||
const tick = (now: number) => {
|
||||
const { pages: list, cursor: at, flow: on } = reading.current;
|
||||
if (c.tick(now, list[at], on && !held.current.size && !document.hidden) && at < list.length - 1) { how.current = 'advance'; setAnchor(anchorOf(list, at + 1) || START); }
|
||||
const { pages: list, cursor: at, flow: on } = reading.current, w = waiting.current;
|
||||
const running = on && !held.current.size && !document.hidden, done = c.tick(now, list[at], running);
|
||||
if (done && at < list.length - 1) { how.current = 'advance'; setAnchor(anchorOf(list, at + 1) || START); }
|
||||
else if (w.count && !w.busy && !w.sheet && running && at >= list.length - 1 && (done || !list.length)) { w.count = 0; admit.current(); }
|
||||
if (meter.current) meter.current.style.transform = `scaleX(${c.progress})`;
|
||||
raf = requestAnimationFrame(tick);
|
||||
};
|
||||
@@ -214,7 +224,9 @@ export function ChatPanel({ state, onChange, onPresence, onVoice, onObservation,
|
||||
}
|
||||
const setVoiceMode = () => { if (real) { setNotice('语音尚未接通,文字仍可使用。'); return; } if (voice) { endVoice(); return; } setPermission('mic'); };
|
||||
const lastUser = [...view.messages].reverse().find(m => m.role === 'user');
|
||||
const status = notice || flash || (busy ? (reply ? `${name}正在回应…` : `${name}在想…`) : !pages.length ? '你们还没有说过话。' : real ? '' : '演示回复 · 未连接真实模型');
|
||||
// Only says why her new words wait when it is your own reading that holds them; otherwise they simply come in.
|
||||
const queued = incoming.length && !busy ? (!flow ? `${name}刚又说了一句 · 继续后呈现` : !atEnd ? `${name}刚又说了一句 · 读完这段呈现` : '') : '';
|
||||
const status = notice || flash || (busy ? (reply ? `${name}正在回应…` : `${name}在想…`) : queued || (!pages.length ? '你们还没有说过话。' : real ? '' : '演示回复 · 未连接真实模型'));
|
||||
const unread = pages.length - 1 - cursor, single = pages.length <= 1 && !busy, fullMessage = page?.message;
|
||||
const textarea = useRef<HTMLTextAreaElement>(null);
|
||||
useLayoutEffect(() => { const t = textarea.current; if (!t) return; t.style.height = 'auto'; t.style.height = Math.min(t.scrollHeight, 88) + 'px'; }, [draft]);
|
||||
|
||||
Reference in New Issue
Block a user