fix: harden identity, live access, drafts and setup (review only)

Source-reviewed hardening changes and regression tests. UNBUILT / UNTESTED: not a deployable release. Go formatting, compilation, automated regression tests, full frontend validation and staging acceptance remain required. See docs/hardening/VALIDATION.md. Main remains the original clean snapshot; no upstream Git history imported.
This commit is contained in:
2026-10-16 12:15:20 +00:00
parent e57610a27c
commit 63e0457886
86 changed files with 5174 additions and 1929 deletions

View File

@@ -1,3 +1,5 @@
// Modified in the independent hardening fork; see docs/hardening/README.md.
// Modified for AgentDeskFixes: capture operator recipients and preserve failed message drafts.
"use client";
import {
@@ -61,6 +63,7 @@ import {
type AIWorkflowRun,
} from "@/lib/api/admin";
import { readSession } from "@/lib/auth";
import { createMessageEditorDraftStore } from "@/lib/message-editor-drafts";
import { renderIMMessageHTML } from "@/lib/im-message";
import {
agentConversationSelectors,
@@ -177,6 +180,8 @@ export function ChatPanel() {
null,
);
const shouldStickToBottomRef = useRef(true);
const [draftStore] = useState(createMessageEditorDraftStore);
useEffect(() => () => draftStore.clear(), [draftStore]);
const [claiming, setClaiming] = useState(false);
const [claimDialogOpen, setClaimDialogOpen] = useState(false);
const [transferDialogOpen, setTransferDialogOpen] = useState(false);
@@ -314,12 +319,19 @@ export function ChatPanel() {
};
const handleSend = async (html: string) => {
if (!conversation || sending || isClosedConversation) return;
// Bind the displayed draft to its recipient before the store reads selection.
const recipientId = conversation?.id;
try {
if (!recipientId || sending || isClosedConversation ||
useAgentConversationsStore.getState().selectedConversationId !== recipientId) {
throw new Error(t("conversation.sendMessageFailed"));
}
shouldStickToBottomRef.current = true;
await sendMessage(html);
const message = await sendMessage(html, recipientId);
if (!message) throw new Error(t("conversation.sendMessageFailed"));
} catch (error) {
toast.error(error instanceof Error ? error.message : t("conversation.sendMessageFailed"));
throw error;
}
};
@@ -495,20 +507,28 @@ export function ChatPanel() {
<div className="flex h-full min-h-0 flex-col">
<div className="min-h-0 flex-1">
<AgentMessageEditor
disabled={!conversation || sending}
draftStore={draftStore}
disabled={!conversation}
sending={sending}
uploadingAsset={uploadingAsset}
onSend={handleSend}
onUploadImage={async (file) => {
shouldStickToBottomRef.current = true;
const uploaded = await uploadImage(file);
return uploaded;
try {
return await uploadImage(file, conversation.id);
} catch (error) {
toast.error(error instanceof Error ? error.message : t("upload.imageUploadFailed"));
throw error;
}
}}
onSendAttachment={async (file) => {
shouldStickToBottomRef.current = true;
try {
await sendAttachment(file);
const message = await sendAttachment(file, conversation.id);
if (!message) throw new Error(t("conversation.sendAttachmentFailed"));
} catch (error) {
toast.error(error instanceof Error ? error.message : t("conversation.sendAttachmentFailed"));
throw error;
}
}}
/>