fix(web): 会话列表合同跟着外壳搬家,无活跃会话不再静默吞发送
四条源码合同改到 (app)/layout 与注册载荷两端对断。列表只剩校正会话时普通输入框锁定,发送会打开校正或给出提示。
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
||||
resolveRectificationEntryAction,
|
||||
} from "@/lib/rectification-entry";
|
||||
import {
|
||||
dropRectificationStoredPending,
|
||||
composerLocksAsRectification, dropRectificationStoredPending,
|
||||
ordinaryComposerPlaceholder,
|
||||
rectificationOrdinaryComposerReopen,
|
||||
} from "@/lib/rectification-session-composer-guard";
|
||||
@@ -391,7 +391,7 @@ export default function Home() {
|
||||
|
||||
const activeSession = sessions.find((session) => session.id === activeSessionId)
|
||||
?? sessions.find((session) => session.sessionType !== "birth_time_rectification");
|
||||
const activeRectificationSession = activeSession?.sessionType === "birth_time_rectification";
|
||||
const activeRectificationSession = composerLocksAsRectification(activeSession, sessions);
|
||||
const rectificationSurfaceOpen = Boolean(activeRectificationSession && activeSession && activeSession.id === rectificationSessionId);
|
||||
const rectificationComposerLocked = Boolean(activeRectificationSession && !rectificationSurfaceOpen);
|
||||
const rectificationComposerReopen = rectificationOrdinaryComposerReopen({ activeRectificationSession, error: rectificationError, errorSessionId: rectificationErrorSessionId, sessionId: activeSession?.id });
|
||||
@@ -1745,7 +1745,7 @@ export default function Home() {
|
||||
{jumpToLatestVisible && (
|
||||
<JumpToLatestButton onClick={conversationAnchor.anchorToLatest} />
|
||||
)}
|
||||
{rectificationComposerReopen && activeSession ? <RectificationComposerReopen message={rectificationErrorMessage} onReopen={() => void reopenRectificationSession(activeSession.id)} /> : null}
|
||||
{rectificationComposerReopen ? <RectificationComposerReopen message={rectificationErrorMessage} onReopen={() => void reopenRectificationSession(activeSession?.id || rectificationErrorSessionId || "")} /> : null}
|
||||
<ChatComposer
|
||||
inputRef={composerInput}
|
||||
inputLabel={!profileComplete && onboardingStep === "name" ? "输入你的称呼" : "输入你的问题"}
|
||||
|
||||
@@ -64,6 +64,7 @@ import { completedOnboardingTranscript, isProfileComplete, selectedBirthPlace }
|
||||
import { pendingConsultationStorageKey, timestamp } from "@/lib/home-types";
|
||||
import {
|
||||
consultSendBlockedByRectificationSession,
|
||||
missingActiveSessionSendAction,
|
||||
SESSION_NOT_CONSULTATION_CODE,
|
||||
} from "@/lib/rectification-session-composer-guard";
|
||||
import type {
|
||||
@@ -514,7 +515,19 @@ export function useConsultationRun(params: ConsultationRunParams) {
|
||||
? sessions.find((session) => session.id === targetSessionId)
|
||||
: activeSession;
|
||||
const currentSession = options.sessionOverride ?? liveSession;
|
||||
if (!question || !currentSession || !modelCatalog || !account) return false;
|
||||
if (!question) return false;
|
||||
if (!currentSession) {
|
||||
const action = missingActiveSessionSendAction(sessions);
|
||||
if ("openSessionId" in action) {
|
||||
setDraft(originalQuestion);
|
||||
await openRectificationSession(action.openSessionId);
|
||||
setDraft(originalQuestion);
|
||||
return false;
|
||||
}
|
||||
setComposerNotice(action.notice);
|
||||
return false;
|
||||
}
|
||||
if (!modelCatalog || !account) return false;
|
||||
if (consultSendBlockedByRectificationSession(currentSession)) {
|
||||
if (resuming) {
|
||||
pendingConsultation.current = null;
|
||||
|
||||
@@ -23,6 +23,24 @@ export function consultSendBlockedByRectificationSession(
|
||||
return isRectificationChatSession(session);
|
||||
}
|
||||
|
||||
/** Empty active session with only rectification rows still occupies the ordinary composer. */
|
||||
export function composerLocksAsRectification(
|
||||
activeSession: { sessionType?: string } | null | undefined,
|
||||
sessions: readonly { sessionType: string }[],
|
||||
): boolean {
|
||||
if (isRectificationChatSession(activeSession)) return true;
|
||||
if (activeSession) return false;
|
||||
return sessions.some((session) => session.sessionType === "birth_time_rectification");
|
||||
}
|
||||
|
||||
export function missingActiveSessionSendAction(
|
||||
sessions: readonly { id: string; sessionType: string }[],
|
||||
): { openSessionId: string } | { notice: string } {
|
||||
const rectification = sessions.find((session) => session.sessionType === "birth_time_rectification");
|
||||
if (rectification) return { openSessionId: rectification.id };
|
||||
return { notice: "请先选一条对话,或点上方「新建对话」。" };
|
||||
}
|
||||
|
||||
export function dropRectificationStoredPending<
|
||||
S extends { sessionId: string },
|
||||
T extends { id: string; sessionType: string },
|
||||
@@ -63,5 +81,6 @@ export function rectificationOrdinaryComposerReopen(input: {
|
||||
if (!input.activeRectificationSession || !input.error || input.error === "profile_incomplete") {
|
||||
return false;
|
||||
}
|
||||
if (!input.sessionId) return true;
|
||||
return !input.errorSessionId || input.errorSessionId === input.sessionId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user