diff --git a/apps/presentation/dashboard/src/data/chat.ts b/apps/presentation/dashboard/src/data/chat.ts index 74c2172e4c..85013ef8e7 100644 --- a/apps/presentation/dashboard/src/data/chat.ts +++ b/apps/presentation/dashboard/src/data/chat.ts @@ -1029,6 +1029,7 @@ const chatQueueSchema = z.object({ preview: z.string(), character_count: z.number().int().nonnegative(), attachment_count: z.number().int().nonnegative(), input_revision: z.number().int().nonnegative().default(0), + input_mutation_allowed: z.boolean().optional(), mutation: z.object({action: z.enum(["edit", "cancel"]), operation_id: z.string().min(1), expected_revision: z.number().int().nonnegative(), input_revision: z.number().int().positive(), message: z.string().optional()}).nullable().optional().default(null), diff --git a/apps/presentation/dashboard/src/features/personal-workspace/conversation-queue.css b/apps/presentation/dashboard/src/features/personal-workspace/conversation-queue.css index 3ba5f38670..20d00c1f7e 100644 --- a/apps/presentation/dashboard/src/features/personal-workspace/conversation-queue.css +++ b/apps/presentation/dashboard/src/features/personal-workspace/conversation-queue.css @@ -3,10 +3,10 @@ .personal-conversation-queue > ol { max-height: min(28dvh, 220px); overflow: auto; overscroll-behavior: contain; list-style: none; padding: 0; margin: 0; border: 1px solid var(--pw-line-strong); border-radius: 12px; background: #fff; } .personal-conversation-queue > ol > li + li { border-top: 1px solid var(--pw-line-strong); } .personal-queue-row { display: flex; align-items: start; gap: 8px; padding: 8px 10px; } -.personal-queue-row details { min-width: 0; flex: 1; } +.personal-queue-content { min-width: 0; flex: 1; } .personal-queue-row summary { cursor: pointer; } .personal-queue-row summary > span { display: -webkit-inline-box; max-width: calc(100% - 16px); vertical-align: top; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; white-space: pre-wrap; } -.personal-queue-row summary small { display: block; margin: 4px 0 0 16px; color: var(--pw-muted); } +.personal-queue-row summary small, .personal-queue-source { display: block; margin: 4px 0 0 16px; color: var(--pw-muted); overflow-wrap: anywhere; } .personal-conversation-queue button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-height: 32px; padding: 4px 6px; border: 0; border-radius: 6px; color: var(--pw-muted); background: transparent; cursor: pointer; } .personal-conversation-queue button:hover { background: var(--pw-blue-soft); color: var(--pw-blue-ink); } .personal-conversation-queue button:disabled { opacity: .45; cursor: default; } diff --git a/apps/presentation/dashboard/src/features/personal-workspace/conversation-queue.tsx b/apps/presentation/dashboard/src/features/personal-workspace/conversation-queue.tsx index 932271095d..42216432fd 100644 --- a/apps/presentation/dashboard/src/features/personal-workspace/conversation-queue.tsx +++ b/apps/presentation/dashboard/src/features/personal-workspace/conversation-queue.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from "react"; +import { useEffect, useId, useRef, useState } from "react"; import { CornerUpLeft, MoreHorizontal, Pencil, RefreshCw, X } from "lucide-react"; import { ChatApiError, chatQueueInputRequestSchema, fetchQueuedChatInput, mutateQueuedChatTurn, steerQueuedChatTurn, type ChatQueueInputRequest, type ChatQueuedInput, type ChatQueuedTurn } from "../../data/chat"; @@ -40,16 +40,21 @@ function QueuedMessage({sessionId, turn, index, targetTurnId, onChange, onInputC const [draft, setDraft] = useState(recovery.editor?.message ?? null); const [editRevision, setEditRevision] = useState(recovery.editor?.revision ?? null); const textarea = useRef(null), menuButton = useRef(null); + const summary = useRef(null); + const sourceDescriptionId = useId(); const composing = useRef(false); const held = turn.steering?.status === "pending" ? turn.steering : null; const steerLabel = held ? (zh ? "核对插入" : "Check insertion") : (zh ? "插入本轮" : "Steer"); - const canSteer = !unresolved && !editing && !recovery.failed && Boolean(held || (targetTurnId && !turn.attachment_count)); - const editable = !held && !unresolved && !recovery.failed && turn.origin === "web"; + const sourceEditable = turn.origin === "web" && turn.input_mutation_allowed !== false; + const canSteer = !unresolved && !(sourceEditable && editing) && !recovery.failed + && Boolean(held || (targetTurnId && !turn.attachment_count)); + const editable = !held && !unresolved && !recovery.failed && sourceEditable; useEffect(() => {setMessage(null);}, [turn.input_revision]); useEffect(() => {if (editing && message && draft === null) { setDraft(message.message); setEditRevision(message.input_revision); }}, [editing, message, draft]); - useEffect(() => {if (editing && draft !== null) textarea.current?.focus();}, [editing, draft === null]); + useEffect(() => {if (editing && sourceEditable && draft !== null) textarea.current?.focus();}, + [editing, sourceEditable, draft === null]); async function mutate(request: ChatQueueInputRequest) { if (lock.current) return; lock.current = true; setBusy(true); setActionError(""); setMenu(false); @@ -79,6 +84,7 @@ function QueuedMessage({sessionId, turn, index, targetTurnId, onChange, onInputC } finally {lock.current = false; setBusy(false); onInputChanged();} } function save() { + if (!sourceEditable) return; if (draft && [...draft].length > 12000) { setActionError(zh ? "待处理消息最多 12000 个字符,请缩短后保存。" : "Queued messages support up to 12000 characters. Shorten the text before saving."); return; } @@ -87,7 +93,13 @@ function QueuedMessage({sessionId, turn, index, targetTurnId, onChange, onInputC } function discard() { try {localStorage.removeItem(draftKey);} catch {setActionError(zh ? "草稿恢复信息无法清除,请保留文本。" : "Draft recovery could not be cleared. Retain the text."); return;} - setEditing(false); setDraft(null); setEditRevision(null); setMenu(false); menuButton.current?.focus(); + setEditing(false); setDraft(null); setEditRevision(null); setMenu(false); + if (sourceEditable) menuButton.current?.focus(); + else summary.current?.focus(); + } + function closeRetainedDraft() { + setEditing(false); + summary.current?.focus(); } async function steer() { if (lock.current || !canSteer) return; @@ -115,13 +127,14 @@ function QueuedMessage({sessionId, turn, index, targetTurnId, onChange, onInputC }, [open, editing, message, sessionId, turn.turn_id, turn.input_revision, retry]); return
  • { if (composing.current || event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) return; - if (event.key === "Escape" && !busy && !unresolved) { + if (event.key === "Escape" && !busy && !unresolved && (menu || editing)) { event.preventDefault(); event.stopPropagation(); if (menu) {setMenu(false); menuButton.current?.focus();} - else discard(); + else if (sourceEditable) discard(); + else closeRetainedDraft(); return; } - if (editing) { + if (editing && (sourceEditable || event.target === textarea.current)) { if (composerKeyAction({...event, isComposing: event.nativeEvent.isComposing, keyCode: event.nativeEvent.keyCode}, false) === "steer") { event.preventDefault(); event.stopPropagation(); save(); } @@ -130,8 +143,9 @@ function QueuedMessage({sessionId, turn, index, targetTurnId, onChange, onInputC if (composerKeyAction({...event, isComposing: event.nativeEvent.isComposing, keyCode: event.nativeEvent.keyCode}, false) === "steer" && canSteer) { event.preventDefault(); event.stopPropagation(); void steer(); } - }}>
    setOpen(event.currentTarget.open)}> - + }}>
    setOpen(event.currentTarget.open)}> + {turn.preview || (zh ? "附件消息" : "Attachments")} {turn.attachment_count ? {zh ? `${turn.attachment_count} 个附件` : `${turn.attachment_count} attachments`} : null} @@ -143,7 +157,15 @@ function QueuedMessage({sessionId, turn, index, targetTurnId, onChange, onInputC ? : {attachment.name}/)}}
    : null} -
    : null} +
    - {menu ?
    + aria-label={!sourceEditable + ? (zh ? `编辑或取消不可用:待处理消息 ${index + 1}` : `Editing or cancelling unavailable for queued message ${index + 1}`) + : (zh ? `更多操作:待处理消息 ${index + 1}` : `More actions for queued message ${index + 1}`)} + aria-describedby={sourceEditable ? undefined : sourceDescriptionId} + aria-expanded={menu && editable} onClick={() => setMenu(!menu)}> + {menu && editable ?
    : null}
    {editing ?
    {draft === null ?

    {failed ? (zh ? "完整消息读取失败" : "Full message unavailable") : (zh ? "正在读取…" : "Reading…")}

    - :