Skip to content

The agent that grows with you

fix(desktop): reset lazy previews, queue pasted uploads, refresh list after disband

unsupportedpastels6dca67ed4dc5
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-attachments.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-attachments.tsx
index bd5cc32e4c8..cce14acdb27 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-attachments.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-attachments.tsx
@@ -40,6 +40,8 @@ export function CanonicalGroupAttachments({ binding, attachments, onChange, onUp
const [error, setError] = useState('')
const [busy, setBusy] = useState(false)
const lifetime = useRef<AbortController | null>(null)
+ // Files still to upload in the running batch; a paste or drop during it joins instead of being lost.
+ const queued = useRef<File[] | null>(null)
useLayoutEffect(() => {
const controller = new AbortController()
@@ -54,11 +56,20 @@ export function CanonicalGroupAttachments({ binding, attachments, onChange, onUp
useImperativeHandle(ref, () => ({ upload: files => void upload(files) }))
async function upload(files: File[]) {
- if (readOnly || busy) {return}
+ if (readOnly) {return}
+
+ if (queued.current) {
+ queued.current.push(...files)
+
+ return
+ }
+
+ const pending = [...files]
+ queued.current = pending
setBusy(true); setError(''); onUploadingChange?.(true)
let next = attachments
- try { for (const file of files) {
+ try { for (let file = pending.shift(); file; file = pending.shift()) {
const data = await new Promise<string>((resolve, reject) => {
const reader = new FileReader()
reader.onload = () => resolve(String(reader.result).split(',', 2)[1])
@@ -76,7 +87,7 @@ export function CanonicalGroupAttachments({ binding, attachments, onChange, onUp
next = [...next, { attachment_id, kind, name, mime, size }]
onChange?.(next)
} } catch (e) { setError(e instanceof Error ? e.message : String(e)) }
- finally { setBusy(false); onUploadingChange?.(false) }
+ finally { queued.current = null; setBusy(false); onUploadingChange?.(false) }
}
async function download(attachment: Attachment) {
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-download-lifetime.test.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-download-lifetime.test.tsx
index fed7cfd2fee..f91486a0a9d 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-download-lifetime.test.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-download-lifetime.test.tsx
@@ -9,7 +9,7 @@ vi.mock('@hermes/plugin-sdk', async () => {
const { en } = await import('@/i18n/en')
const { Textarea } = await import('@/components/ui/textarea')
- return { Textarea, MessageTextContent: undefined, Streamdown: undefined, host: { requestProfile: request }, useI18n: () => ({ locale: 'en', t: en }),
+ return { Textarea, atom: (await import('nanostores')).atom, MessageTextContent: undefined, Streamdown: undefined, host: { requestProfile: request }, useI18n: () => ({ locale: 'en', t: en }),
Button: (props: ComponentProps<'button'>) => <button {...props} />,
Codicon: () => <span />, Tip: ({ children }: { children: ReactNode }) => <>{children}</> }
})
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-history.test.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-history.test.tsx
index 3da18d2cfa6..2ec34e15647 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-history.test.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-history.test.tsx
@@ -9,7 +9,7 @@ vi.mock('@hermes/plugin-sdk', async () => {
const { en } = await import('@/i18n/en')
const { Textarea } = await import('@/components/ui/textarea')
- return { Textarea, host: { requestProfile: request }, useI18n: () => ({ locale: 'en', t: en }),
+ return { Textarea, atom: (await import('nanostores')).atom, host: { requestProfile: request }, useI18n: () => ({ locale: 'en', t: en }),
Button: (props: ComponentProps<'button'>) => <button {...props} />,
MessageTextContent: ({ text }: { text: string }) => <div data-testid="markdown">{text}</div>,
Streamdown: ({ children }: { children: ReactNode }) => <div data-testid="markdown">{children}</div>,
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-history.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-history.tsx
index cf1f8c56519..2f38699bc9a 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-history.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-history.tsx
@@ -83,12 +83,12 @@ function ImagePreview({ binding, eventId, attachment, disabled }: {
useEffect(() => {
const el = box.current
- if (near || !el) {return}
+ if (near || disabled || !el) {return}
const observer = new IntersectionObserver(entries => { if (entries.some(entry => entry.isIntersecting)) {setNear(true)} }, { rootMargin: '200px' })
observer.observe(el)
return () => observer.disconnect()
- }, [near])
+ }, [near, disabled])
useEffect(() => {
if (disabled || !near || !attachmentId || !previewable) {return}
@@ -101,7 +101,8 @@ function ImagePreview({ binding, eventId, attachment, disabled }: {
setSrc(url)
}, () => undefined)
- return () => { cancelled = true; URL.revokeObjectURL(url); setSrc('') }
+ // Dropping `near` makes a re-shown room wait on the observer again, not refetch every preview seen so far at once.
+ return () => { cancelled = true; URL.revokeObjectURL(url); setSrc(''); setNear(false) }
}, [connectionId, profile, roomId, eventId, attachmentId, disabled, near, previewable])
return previewable ? <div ref={box}>{src && <img alt={attachment.name} className="max-h-64 max-w-full rounded object-contain" src={src} />}</div> : null
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-labels.ts b/apps/desktop/src/plugins/hermes-bots/canonical-group-labels.ts
index 55c348fe622..50124ab7515 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-labels.ts
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-labels.ts
@@ -23,6 +23,7 @@ export function useCanonicalGroupLabels() {
disband: group.disbandAction,
disbanding: group.disbanding,
disbandDone: group.disbandDone,
+ disbanded: group.disbanded,
disbandDescPrefix: group.disbandDescPrefix,
disbandDescSuffix: group.disbandDescSuffix,
disbandTitle: group.disbandTitle
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-registry.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-registry.tsx
index 1318f9d2baf..e9007699133 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-registry.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-registry.tsx
@@ -6,6 +6,15 @@ import { captureCanonicalGroupRoute, discoverCanonicalGroups } from './canonical
import type { CanonicalGroupBinding, CanonicalGroupRoute, CanonicalRoom } from './canonical-groups'
export const $canonicalGroupBindings = atom<Record<string, CanonicalGroupBinding>>({})
+// Bumped when a room leaves outside the list's own Refresh, so the sidebar re-reads `groups.list`.
+const $canonicalGroupListRevision = atom(0)
+
+/** Drop a disbanded room's key and every alias to it, then re-read the sidebar list. */
+export function forgetCanonicalGroup({ connectionId, profile, roomId }: CanonicalGroupBinding): void {
+ $canonicalGroupBindings.set(Object.fromEntries(Object.entries($canonicalGroupBindings.get()).filter(([, binding]) =>
+ binding.connectionId !== connectionId || binding.profile !== profile || binding.roomId !== roomId)))
+ $canonicalGroupListRevision.set($canonicalGroupListRevision.get() + 1)
+}
export function registerCanonicalGroup(route: CanonicalGroupRoute, room: CanonicalRoom): string {
const key = `canonical:${encodeURIComponent(route.connectionId)}:${encodeURIComponent(route.profile)}:${room.room_id}`
@@ -104,6 +113,7 @@ export function CanonicalGroupList({ onOpen }: { onOpen: (key: string, origin: C
const [rooms, setRooms] = useState<Array<{ key: string; name: string }>>([])
const [error, setError] = useState('')
const [refresh, setRefresh] = useState(0)
+ const revision = useValue($canonicalGroupListRevision)
useEffect(() => {
let cancelled = false
setRooms([])
@@ -116,7 +126,7 @@ export function CanonicalGroupList({ onOpen }: { onOpen: (key: string, origin: C
})().catch(e => { if (!cancelled) {setError(e instanceof Error ? e.message : String(e))} })
return () => { cancelled = true }
- }, [connectionId, profile, refresh])
+ }, [connectionId, profile, refresh, revision])
return <div className="grid gap-1 px-2">
<Button onClick={() => setRefresh(value => value + 1)} variant="ghost">{labels.refreshGroups}</Button>
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx
index 697cad8d222..4a70fb835e3 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx
@@ -20,7 +20,9 @@ vi.mock('@hermes/plugin-sdk', async () => {
RowButton: (p: ComponentProps<'button'>) => <button type="button" {...p} />,
host: { ...gateway.host, requestProfile: request } }
})
-import { registerCanonicalGroup } from './canonical-group-registry'
+import { host } from '@hermes/plugin-sdk'
+
+import { $canonicalGroupBindings, CanonicalGroupList, registerCanonicalGroup } from './canonical-group-registry'
import { prepareCanonicalGroupSend, readCanonicalGroupSend } from './canonical-group-send'
import { CanonicalGroupWorkspace } from './canonical-group-workspace'
import { $groupChatWorkspace } from './group-chat'
@@ -263,6 +265,28 @@ it('leaves the in-panel room after a disband even though no tab supplies onBack'
await waitFor(() => expect($groupChatWorkspace.get()).toBeNull())
})
+it('drops a disbanded room from the sidebar list and its bindings, with the disbanded toast', async () => {
+ vi.mocked(host.notify).mockClear()
+ let disbanded = false
+ const room = { room_id: 'gone', name: 'Doomed', members: [] }
+ request.mockImplementation(async (_route, method) => method === 'groups.disband' ? (disbanded = true, {})
+ : method === 'groups.capabilities' ? { driver: true } : method === 'groups.list' ? { rooms: disbanded ? [] : [room], next_offset: null }
+ : roomReads()(method) ?? {})
+ render(<CanonicalGroupList onOpen={vi.fn()} />)
+ await screen.findByRole('button', { name: 'Doomed' })
+ const binding = { connectionId: 'remote', profile: 'team', roomId: 'gone', roomName: 'Doomed' }
+ const key = registerCanonicalGroup(binding, room)
+ render(<CanonicalGroupWorkspace binding={binding} onBack={vi.fn()} />)
+ const disband = await screen.findByRole('button', { name: /disband/i }) as HTMLButtonElement
+ await waitFor(() => expect(disband.disabled).toBe(false))
+ fireEvent.click(disband)
+ fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: /disband/i }))
+ await waitFor(() => expect(screen.queryByRole('button', { name: 'Doomed' })).toBeNull())
+ expect($canonicalGroupBindings.get()[key]).toBeUndefined()
+ // This fixture's plugin i18n mock answers with the key: the legacy view's `group.disbanded` toast.
+ expect(host.notify).toHaveBeenCalledExactlyOnceWith({ kind: 'success', message: 'group.disbanded' })
+})
+
it('@-completes room members with the exact handle the gateway resolves', async () => {
request.mockImplementation(async (_route, method) => roomReads([{ member_id: 'm1', profile: 'ops', handle: 'ops-2', display_name: 'Ops Bot' }])(method) ?? {})
render(<CanonicalGroupWorkspace binding={{ connectionId: 'local', profile: 'team', roomId: 'mentions' }} />)
@@ -301,3 +325,44 @@ it('uploads pasted and dropped files through the room upload and previews commit
await screen.findByText('b.txt')
expect(request.mock.calls.filter(c => c[1] === 'groups.attachment.upload').map(c => [c[2].name, c[2].kind])).toEqual([['a.png', 'image'], ['b.txt', 'file']])
})
+
+it('re-gates previews on the observer after the room is hidden and shown, instead of refetching them all at once', async () => {
+ Object.defineProperty(URL, 'createObjectURL', { configurable: true, value: vi.fn(() => 'blob:preview') })
+ Object.defineProperty(URL, 'revokeObjectURL', { configurable: true, value: vi.fn() })
+ const image = { attachment_id: 'img', kind: 'image', name: 'shot.png', mime: 'image/png', size: 1 }
+ const events = [{ seq: 1, room_id: 'toggle', event_id: 'e1', kind: 'message.member', payload: { attachments: [image] } }]
+ request.mockImplementation(async (_route, method) => roomReads([], events)(method)
+ ?? (method === 'groups.attachment.download' ? { ...image, data_base64: 'QQ==' } : {}))
+ const observers: IntersectionObserverCallback[] = []
+ vi.stubGlobal('IntersectionObserver', class { constructor(callback: IntersectionObserverCallback) { observers.push(callback) } observe() {} disconnect() {} })
+ const downloads = () => request.mock.calls.filter(c => c[1] === 'groups.attachment.download').length
+ const binding = { connectionId: 'local', profile: 'team', roomId: 'toggle' }
+ const view = render(<CanonicalGroupWorkspace binding={binding} />)
+ await waitFor(() => expect(observers).toHaveLength(1))
+ act(() => observers[0]([{ isIntersecting: true }] as IntersectionObserverEntry[], {} as IntersectionObserver))
+ await screen.findByRole('img', { name: 'shot.png' })
+ view.rerender(<CanonicalGroupWorkspace binding={binding} visible={false} />)
+ view.rerender(<CanonicalGroupWorkspace binding={binding} />)
+ await waitFor(() => expect(observers).toHaveLength(2))
+ expect(downloads()).toBe(1)
+ act(() => observers[1]([{ isIntersecting: true }] as IntersectionObserverEntry[], {} as IntersectionObserver))
+ await waitFor(() => expect(downloads()).toBe(2))
+})
+
+it('uploads a file pasted while another upload runs once that one finishes, instead of dropping it', async () => {
+ let release!: () => void
+ const receipt = (params: Record<string, string>) => ({ attachment_id: `att-${params.name}`, kind: params.kind, name: params.name, mime: params.mime, size: 1 })
+ request.mockImplementation(async (_route, method, params) => roomReads()(method) ?? (method !== 'groups.attachment.upload' ? {}
+ : params.name === 'first.png' ? new Promise(resolve => { release = () => resolve(receipt(params)) }) : receipt(params)))
+ const uploads = () => request.mock.calls.filter(c => c[1] === 'groups.attachment.upload').map(c => c[2].name)
+ render(<CanonicalGroupWorkspace binding={{ connectionId: 'local', profile: 'team', roomId: 'queue' }} />)
+ const box = screen.getByRole('textbox')
+ await waitFor(() => expect((box as HTMLTextAreaElement).disabled).toBe(false))
+ fireEvent.paste(box, { clipboardData: { files: [new File(['a'], 'first.png', { type: 'image/png' })], types: ['Files'] } })
+ await waitFor(() => expect(uploads()).toEqual(['first.png']))
+ fireEvent.paste(box, { clipboardData: { files: [new File(['b'], 'second.txt', { type: 'text/plain' })], types: ['Files'] } })
+ await act(async () => release())
+ await screen.findByText('second.txt')
+ expect(screen.getByText('first.png')).toBeTruthy()
+ expect(uploads()).toEqual(['first.png', 'second.txt'])
+})
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
index 20280fc1210..3607e8e26e2 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
@@ -1,4 +1,4 @@
-import { Button } from '@hermes/plugin-sdk'
+import { Button, host } from '@hermes/plugin-sdk'
import { type ClipboardEvent, type DragEvent, useEffect, useRef, useState } from 'react'
import { type CanonicalDriverActivity, CanonicalGroupWorkingLine, canonicalMemberPhases } from './canonical-group-activity'
@@ -6,6 +6,7 @@ import { CanonicalGroupAttachments, type CanonicalGroupUploader } from './canoni
import { CanonicalGroupHeader } from './canonical-group-header'
import { type CanonicalGroupEvent, CanonicalGroupHistory } from './canonical-group-history'
import { useCanonicalGroupLabels } from './canonical-group-labels'
+import { forgetCanonicalGroup } from './canonical-group-registry'
import { prepareCanonicalGroupSend, readCanonicalGroupSend, retireCanonicalGroupSend } from './canonical-group-send'
import type { PreparedCanonicalGroupSend } from './canonical-group-send'
import { actCanonicalGroup, canonicalGroupRequest } from './canonical-groups'
@@ -170,6 +171,8 @@ function CanonicalRoomView({ binding: initialBinding, visible, onBack }: {
await canonicalGroupRequest(binding, 'groups.disband', { room_id: binding.roomId, cancel_id: crypto.randomUUID() })
if (alive.current) {onBack?.()}
+ forgetCanonicalGroup(binding)
+ host.notify({ kind: 'success', message: labels.disbanded(state?.room.name || binding.roomName || '') })
}
const composerLocked = !restored || busy || !!pending
@@ -183,7 +186,7 @@ function CanonicalRoomView({ binding: initialBinding, visible, onBack }: {
if (!files.length) {return}
event.preventDefault()
- if (!composerLocked && !uploading) {uploader.current?.upload(files)}
+ if (!composerLocked) {uploader.current?.upload(files)}
}
return <section className="flex h-full min-h-0 flex-col gap-3 p-3">