The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: submit Desktop images through canonical admissions
Tekniumc93382c0a1dc
diff --git a/apps/desktop/src/app/chat/session-tile-actions.ts b/apps/desktop/src/app/chat/session-tile-actions.tsindex b71b0614997..7bc6a461ffa 100644--- a/apps/desktop/src/app/chat/session-tile-actions.ts+++ b/apps/desktop/src/app/chat/session-tile-actions.ts@@ -252,6 +252,7 @@ export function useSessionTileActions({ requestGateway, runtimeId, scope, storedattachedSessionId: next.attachedSessionId,label: next.label,path: next.path,+ mime: next.mime,refText: next.refText,uploadState: next.uploadState})diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.tsindex 821895026a3..48bff9ca128 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts@@ -3,6 +3,7 @@ import { JsonRpcGatewayError } from '@hermes/shared'import { useStore } from '@nanostores/react'import { type MutableRefObject, useCallback, useEffect, useRef } from 'react'+import { hermesApi } from '@/api/client'import { transcribeAudio } from '@/hermes'import { useI18n } from '@/i18n'import { stripAnsi } from '@/lib/ansi'@@ -21,12 +22,15 @@ import {setComposerAttachmentUploadState,updateComposerAttachment} from '@/store/composer'+import { serverOwnsComposerQueue } from '@/store/composer-queue'import { resetSessionBackground } from '@/store/composer-status'import { clearNotifications, notify, notifyError } from '@/store/notifications'import { clearPreviewArtifacts } from '@/store/preview-status'+import { $activeGatewayProfile } from '@/store/profile'import { clearAllPrompts } from '@/store/prompts'import {$busy,+ $connection,$currentCwd,$messages,$terminalBackend,@@ -134,15 +138,34 @@ export async function uploadComposerAttachment(): Promise<ComposerAttachment> {const { backendCwd, remote, storedSessionId, onSessionRecovered, terminalBackend } = opts- const requestGateway = captureSubmissionDestination(- storedSessionId ?? opts.sessionId,- opts.requestGateway- ).requestGateway+ const destination = captureSubmissionDestination(storedSessionId ?? opts.sessionId, opts.requestGateway)+ const requestGateway = destination.requestGatewayconst path = attachment.path ?? ''const label = attachment.label || pathLabel(path)const uploadBytes = remote || attachmentPathNeedsUpload(path, backendCwd, terminalBackend)+ if (attachment.kind === 'image' && serverOwnsComposerQueue(storedSessionId ?? opts.sessionId)) {+ // Pin HTTP to the same owner before the native byte read yields. Images+ // are immutable admission payloads, never legacy agent.pending_images.+ const owner = destination.owner+ const connectionId = typeof owner === 'object' && owner ? owner.connectionId : $connection.get()?.connectionId+ const profile = typeof owner === 'object' && owner ? owner.targetProfile || owner.profile : owner || $activeGatewayProfile.get()++ const dataUrl = attachment.previewUrl?.includes(';base64,')+ ? attachment.previewUrl+ : await window.hermesDesktop?.readFileDataUrl(path)++ if (!dataUrl) { throw new Error(`Could not read ${label}`) }++ const result = await hermesApi<{ path: string; mime_type: string }>({+ method: 'POST', path: '/api/chat/image-upload', connectionId: connectionId ?? 'local', profile,+ body: { data_url: dataUrl, filename: label }+ })++ return { ...attachment, path: result.path, mime: result.mime_type, attachedSessionId: opts.sessionId, uploadState: undefined }+ }+// Read bytes/paths ONCE, outside the retry. Only the session-scoped RPC is// replayed on recovery — re-reading a multi-MB file to retry a dead session// id would double the disk/IPC cost of every recovered attach. For images,@@ -419,6 +442,7 @@ export function usePromptActions({attachedSessionId: nextAttachment.attachedSessionId,label: nextAttachment.label,path: nextAttachment.path,+ mime: nextAttachment.mime,refText: nextAttachment.refText,uploadState: nextAttachment.uploadState})diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsxindex 32f6f7c51f7..57d94edf5ca 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submission-destination.test.tsx@@ -79,6 +79,48 @@ afterEach(() => {})describe('submission intent destinations', () => {+ it('stages canonical images on the captured owner without a legacy image RPC', async () => {+ const { uploadComposerAttachment } = await import('.')+ const original = window.hermesDesktop+ const gate = deferred<string>()+ const api = vi.fn(async () => ({ path: '/owner/cache/images/exact.png', mime_type: 'image/png' }))+ window.hermesDesktop = { ...original, readFileDataUrl: () => gate.promise, api } as never+ $connection.set({ connectionId: 'local', wsUrl: 'ws://localhost/ws?native_dial=1' } as never)+ $activeGatewayProfile.set('alice')+ const request = vi.fn() as GatewayRequest++ try {+ const pending = uploadComposerAttachment({ id: 'img', kind: 'image', label: 'exact.png', path: '/native/exact.png' },+ { remote: false, sessionId: 'runtime-a', requestGateway: request })++ $activeGatewayProfile.set('bob')+ gate.resolve('data:image/png;base64,aGVsbG8=')+ const staged = await pending+ expect(staged).toMatchObject({ path: '/owner/cache/images/exact.png', mime: 'image/png', attachedSessionId: 'runtime-a' })+ expect(api).toHaveBeenCalledWith(expect.objectContaining({ method: 'POST', path: '/api/chat/image-upload', connectionId: 'local', profile: 'alice', body: { data_url: 'data:image/png;base64,aGVsbG8=', filename: 'exact.png' } }))+ expect(request).not.toHaveBeenCalled()+ } finally { window.hermesDesktop = original }+ })++ it('retains exact canonical image parameters and identity through ambiguous submit and remount', async () => {+ const { deps, requestGateway } = setup()+ $connection.set({ connectionId: 'local', wsUrl: 'ws://localhost/ws?native_dial=1' } as never)+ const image = { id: 'image-retry', kind: 'image' as const, label: 'exact.png', path: '/owner/cache/images/exact.png', mime: 'image/png' }+ deps.syncAttachmentsForSubmit.mockResolvedValue({ sessionId: 'runtime-a', attachments: [image] } as never)+ requestGateway.mockRejectedValueOnce(new Error('connection closed'))+ let hook = renderHook(() => useSubmitPrompt(deps))+ await act(async () => { expect(await hook.result.current('image retry', { attachments: [image] })).toBe(false) })+ const first = requestGateway.mock.calls.find(call => call[0] === 'prompt.submit')![1]+ expect(first?.attachments).toEqual([{ path: image.path, mime: image.mime }])+ hook.unmount()+ hook = renderHook(() => useSubmitPrompt(deps))+ await act(async () => { expect(await hook.result.current('image retry', { attachments: [image] })).toBe(true) })+ expect(requestGateway.mock.calls.filter(call => call[0] === 'prompt.submit')[1][1]).toEqual(first)+ expect(deps.syncAttachmentsForSubmit).toHaveBeenCalledOnce()+ expect(window.localStorage.getItem('hermes.desktop.preparedSubmissions.v1')).not.toContain('image retry')+ })++it('allows presentation and registry metadata replacement on the same authority', async () => {const connection = {baseUrl: 'http://localhost:1',diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.tsindex 7fa9692906c..3d1cc65119a 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts@@ -808,10 +808,14 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {displayText: options?.displayText})+ const imageAttachments = syncedAttachments.filter(attachment => attachment.kind === 'image' && attachment.mime)+ .map(attachment => ({ path: attachment.path!, mime: attachment.mime! }))+const submitParams = (targetId: string) => ({session_id: targetId,text,submission_id: submissionId,+ ...(imageAttachments.length && { attachments: imageAttachments }),...(interrupted && { interrupted }),// Off-screen widget intent: the gateway types the persisted user// row display_kind=hidden so no client renders it as a bubble.diff --git a/apps/desktop/src/store/composer.ts b/apps/desktop/src/store/composer.tsindex 81cb6e51293..d0c36684b3c 100644--- a/apps/desktop/src/store/composer.ts+++ b/apps/desktop/src/store/composer.ts@@ -19,6 +19,8 @@ export interface ComposerAttachment {/** Downscaled data URL for the attachment card and optimistic bubble only. */thumbnailUrl?: stringpath?: string+ /** Validated MIME returned by canonical owner staging. */+ mime?: stringattachedSessionId?: string/** Set while the file/image bytes are being staged into the session* workspace (remote upload or local stage), and 'error' if that failed.