Skip to content

The agent that grows with you

fix(webapp): save a relative image from a chat not stored yet through its runtime session

unsupportedpastels64e7702fc6e1
diff --git a/apps/desktop/src/components/chat/generated-image-open.test.tsx b/apps/desktop/src/components/chat/generated-image-open.test.tsx
index 07ccdc14d4a..a543359d39f 100644
--- a/apps/desktop/src/components/chat/generated-image-open.test.tsx
+++ b/apps/desktop/src/components/chat/generated-image-open.test.tsx
@@ -6,7 +6,7 @@ import { I18nProvider } from '@/i18n'
import { createBrowserFilesBridge } from '@/lib/browser-files'
import type { BrowserBootstrap } from '@/lib/browser-transport'
import { $notifications } from '@/store/notifications'
-import { $connection, $selectedStoredSessionId, $sessions } from '@/store/session'
+import { $activeSessionId, $connection, $selectedStoredSessionId, $sessions } from '@/store/session'
import type { SessionInfo } from '@/types/hermes'
import { GeneratedImage } from './generated-image-result'
@@ -37,6 +37,7 @@ afterEach(() => {
$connection.set(null)
$sessions.set([])
$selectedStoredSessionId.set(null)
+ $activeSessionId.set(null)
$notifications.set([])
window.document.documentElement.removeAttribute('data-hermes-desktop-host')
delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
@@ -101,6 +102,33 @@ it.each([
expect(openExternal).not.toHaveBeenCalled()
})
+// A chat with no stored id yet names its live runtime session, as the chat's other file opens do.
+it('saves a relative gateway image from a chat not stored yet through its runtime session', async () => {
+ saveGatewayFile.mockResolvedValue({ path: '/srv/project/renders/out.png', saved: true })
+ window.document.documentElement.dataset.hermesDesktopHost = 'browser'
+ $connection.set({
+ baseUrl: 'https://gateway.example',
+ connectionId: 'remote-1',
+ mode: 'remote',
+ token: 'secret-token'
+ } as unknown as HermesConnection)
+ $activeSessionId.set('runtime-1')
+
+ const link = openImageLink('renders/out.png')
+ await act(async () => {
+ fireEvent.click(link)
+ })
+
+ await vi.waitFor(
+ () =>
+ expect(saveGatewayFile).toHaveBeenCalledWith(
+ expect.objectContaining({ path: 'renders/out.png', sessionId: 'runtime-1' })
+ ),
+ { timeout: 2000 }
+ )
+ expect($notifications.get().map(({ title }) => title)).not.toContain('Image download failed')
+})
+
// Anything else opens as on main: a web image's own URL.
it('opens a web image\'s URL with the system handler in native Desktop', async () => {
$connection.set({ baseUrl: 'https://gateway.example', mode: 'remote', token: 'secret-token' } as unknown as HermesConnection)
diff --git a/apps/desktop/src/components/chat/generated-image-result.tsx b/apps/desktop/src/components/chat/generated-image-result.tsx
index 6fac1db33f4..06f3f8e15fe 100644
--- a/apps/desktop/src/components/chat/generated-image-result.tsx
+++ b/apps/desktop/src/components/chat/generated-image-result.tsx
@@ -42,9 +42,14 @@ function hintedRatio(aspectRatio?: string): number {
}
/** A relative path names a file in the producing session's working directory, on its profile. The
- * gateway resolves it there only for a save that names that session, and in its own cwd otherwise. */
-async function sessionFileOrigin(storedSessionId: null | string): Promise<GatewayFileOrigin> {
+ * gateway resolves it there only for a save that names that session, and in its own cwd otherwise.
+ * A chat not stored yet names its live runtime session, as the chat's other file opens do. */
+async function sessionFileOrigin(storedSessionId: null | string, runtimeId: null | string): Promise<GatewayFileOrigin> {
if (!storedSessionId) {
+ if (runtimeId) {
+ return { sessionId: runtimeId }
+ }
+
throw new Error('No session to resolve a relative image path in')
}
@@ -70,7 +75,9 @@ export const GeneratedImage: FC<{ aspectRatio?: string; result?: unknown }> = ({
const [canvasGone, setCanvasGone] = useState<string | null>(null)
const [lightboxOpen, setLightboxOpen] = useState<string | null>(null)
const { download, saving } = useImageDownload(src)
- const storedSessionId = useStore(useSessionView().$storedId)
+ const view = useSessionView()
+ const storedSessionId = useStore(view.$storedId)
+ const runtimeId = useStore(view.$runtimeId)
// Completed but no usable image (generation failed): the agent's prose carries
// the explanation, so render nothing here.
@@ -98,7 +105,7 @@ export const GeneratedImage: FC<{ aspectRatio?: string; result?: unknown }> = ({
} else if (isRemoteGateway() && isFileMediaPath(image)) {
void downloadGatewayMediaFile(image).catch(error => notifyError(error, copy.imageDownloadFailed))
} else if (isRemoteGateway() && !isInlineMediaSrc(image)) {
- void sessionFileOrigin(storedSessionId)
+ void sessionFileOrigin(storedSessionId, runtimeId)
.then(origin => downloadGatewayMediaFile(image, origin))
.catch(error => notifyError(error, copy.imageDownloadFailed))
} else {