Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mail): 恢复发送投递后的编辑并保留等待样式
Dash59d374a07e04
diff --git a/apps/desktop/src/renderer/components/chat/GhostToolCard.tsx b/apps/desktop/src/renderer/components/chat/GhostToolCard.tsxindex 4746042208..257ede3729 100644--- a/apps/desktop/src/renderer/components/chat/GhostToolCard.tsx+++ b/apps/desktop/src/renderer/components/chat/GhostToolCard.tsx@@ -254,16 +254,12 @@ function GhostCardCanvas({formState.current.values = mergeGhostCardFormValues(formState.current.values, formState.current.base, incoming);formState.current.base = incoming;useEffect(() => {- // Delivery acknowledgement is not send completion. Autosave echoes must- // not unlock a send while the provider is still preparing its countdown.- if (!mail || !['draft', 'syncing'].includes(mail.state)) {+ // Mail's local lock covers delivery only. After acknowledgement the mail+ // runtime owns cancellation, countdown and send deduplication; a draft echo+ // cannot tell this view whether another editor cancelled preparation.+ if (!mail) {formState.current.busy = false;setFormBusy(false);- if (mail) iframeRef.current?.contentDocument?.querySelectorAll<HTMLElement>('[data-ghost-submit]').forEach(el => {- el.removeAttribute('aria-disabled');- el.style.opacity = '';- el.style.pointerEvents = '';- });}}, [html, mail]);const [lightbox, setLightbox] = useState<{ src: string; galleryId: string } | null>(null);@@ -442,10 +438,11 @@ function GhostCardCanvas({// 动作元素上锁(防连点):锁到意识 card-update 换新卡(新文档),或 INFLIGHT// 窗口自动解禁(意识没换卡也不卡死)。普通按钮点击与输入面板发送共用。- const lockActionEl = useCallback((el: HTMLElement) => {+ const lockActionEl = useCallback((el: HTMLElement, untilDelivered = false) => {el.setAttribute('aria-disabled', 'true');el.style.opacity = '0.5';el.style.pointerEvents = 'none';+ if (untilDelivered) return;window.setTimeout(() => {el.removeAttribute('aria-disabled');el.style.opacity = '';@@ -552,7 +549,8 @@ function GhostCardCanvas({if (!readGhostCardForm(html) || formState.current.busy) return;formState.current.busy = true;setFormBusy(true);- lockActionEl(el);+ const mailSubmit = !!readMailCard(html);+ lockActionEl(el, mailSubmit);const unlock = () => {formState.current.busy = false;setFormBusy(false);@@ -569,7 +567,7 @@ function GhostCardCanvas({? mergeGhostCardFormValues(formState.current.values, formState.current.base, Object.fromEntries(latest.map(f => [f.name, f.value]))): formState.current.values;return window.electronAPI?.ghosts?.dispatchCardAction?.(callId, actionId, undefined, values) ?? { ok: false };- }).then(result => { if (!result.ok) unlock(); }).catch(unlock);+ }).then(result => { if (mailSubmit || !result.ok) unlock(); }).catch(unlock);return;}// data-ghost-prompt 类动作:先弹宿主输入框收集文字,发送时才派发diff --git a/apps/desktop/src/renderer/components/chat/__tests__/MailCardEditor.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/MailCardEditor.test.tsxindex 4f12e2682c..de4137c4af 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/MailCardEditor.test.tsx+++ b/apps/desktop/src/renderer/components/chat/__tests__/MailCardEditor.test.tsx@@ -34,22 +34,35 @@ it('keeps the send target and HTML preview alive across sync and send states', afireEvent.load(frame);const srcDoc = frame.srcdoc;const body = screen.getByTitle('chat.ghostCall.mailPreview');- const send = frame.contentDocument!.querySelector('[data-ghost-submit]')!;+ const send = frame.contentDocument!.querySelector<HTMLElement>('[data-ghost-submit]')!;fireEvent.pointerDown(send);view.rerender(<MailCardEditor {...props} html={renderMailCard({ ...mail, state: 'syncing', status: 'Syncing' })} />);expect(frame.contentDocument!.querySelector('[data-ghost-submit]')).toBe(send);fireEvent.click(send);await act(async () => {});expect(dispatch).toHaveBeenCalledTimes(1);- await act(async () => finish({ ok: true }));view.rerender(<MailCardEditor {...props} html={renderMailCard(mail)} />);+ // A save echo must retain both visual feedback and the delivery lock.+ expect(send.style.opacity).toBe('0.5');+ expect(send.style.pointerEvents).toBe('none');fireEvent.click(send);await act(async () => {});expect(dispatch).toHaveBeenCalledTimes(1);- view.rerender(<MailCardEditor {...props} html={renderMailCard({ ...mail, state: 'error', status: 'Save failed' })} />);+ await act(async () => finish({ ok: true }));+ // Another view can cancel preparation by editing. The acked view must+ // remain editable even if the provider only publishes syncing/draft again.+ const changed = { ...mail, fields: mail.fields.map(f => f.name === 'subject' ? { ...f, value: 'Other view edit' } : f) };+ view.rerender(<MailCardEditor {...props} html={renderMailCard({ ...changed, state: 'syncing' })} />);+ expect((screen.getByLabelText('subject') as HTMLInputElement).disabled).toBe(false);+ expect(send.getAttribute('aria-disabled')).toBeNull();fireEvent.click(send);await act(async () => {});expect(dispatch).toHaveBeenCalledTimes(2);+ await act(async () => finish({ ok: false }));+ view.rerender(<MailCardEditor {...props} html={renderMailCard({ ...mail, state: 'error', status: 'Save failed' })} />);+ fireEvent.click(send);+ await act(async () => {});+ expect(dispatch).toHaveBeenCalledTimes(3);await act(async () => finish({ ok: true }));const countdown: MailCardData = { ...mail, state: 'sending', status: 'sending', pendingSend: {deadline: Date.now() + 10000, label: 'sending in {seconds}', cancelLabel: 'Cancel', sendNowLabel: 'Now',diff --git a/apps/desktop/src/renderer/components/chat/mailCardFooter.ts b/apps/desktop/src/renderer/components/chat/mailCardFooter.tsindex cb2b9968e0..b48d916ed1 100644--- a/apps/desktop/src/renderer/components/chat/mailCardFooter.ts+++ b/apps/desktop/src/renderer/components/chat/mailCardFooter.ts@@ -25,6 +25,11 @@ export function updateMailCardDocument(doc: Document, srcDoc: string): void {for (const attr of (source as Element).attributes) {if (element.getAttribute(attr.name) !== attr.value) element.setAttribute(attr.name, attr.value);}+ // Authored styles must not erase the transient host delivery feedback.+ if (element.hasAttribute('data-ghost-submit') && element.getAttribute('aria-disabled') === 'true') {+ (element as HTMLElement).style.opacity = '0.5';+ (element as HTMLElement).style.pointerEvents = 'none';+ }}const children = [...source.childNodes];children.forEach((child, index) => {