Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): preserve versioned resend references after dev merge
Me805417949d2
diff --git a/desktop-app/src/types.ts b/desktop-app/src/types.tsindex c1450500a..052c7a84b 100644--- a/desktop-app/src/types.ts+++ b/desktop-app/src/types.ts@@ -1306,6 +1306,9 @@ export interface ChatMessageAttachment {drive?: stringresourceId?: stringgfsUri?: string+ /** Listed GFS identity required to resend a structured global-file reference. */+ version?: number+ bytes?: number}export interface ChatFile {diff --git a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsxindex b0052cdc0..8d96d1424 100644--- a/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx+++ b/desktop-app/ui/src/__tests__/App.deepLinks.test.tsx@@ -1805,13 +1805,11 @@ describe('App deep-link orchestration', () => {// path the real app-picker uses — no deep-link confirm ceremony. Defaults to// `ns/app`; pass a distinct appRef to launch another app the sidebar offers.async function launchAppFromSidebar(appRef = 'ns/app'): Promise<void> {- await waitFor(() =>- expect(sidebarHarness.props?.availableSandboxUiApps?.some(a => a.appRef === appRef)).toBe(- true- )- )- const app = sidebarHarness.props?.availableSandboxUiApps?.find(a => a.appRef === appRef)- if (!app) throw new Error(`${appRef} was not available to the sidebar`)+ const app = await waitFor(() => {+ const available = sidebarHarness.props?.availableSandboxUiApps?.find(a => a.appRef === appRef)+ if (!available) throw new Error(`${appRef} was not available to the sidebar`)+ return available+ })await act(async () => {sidebarHarness.props?.onOpenSandboxUiApp?.(app)await Promise.resolve()@@ -2205,15 +2203,16 @@ describe('App deep-link orchestration', () => {const pendingLocation = createDeferred<{ appRef: string; routePath?: string }>()getSandboxUiLocation.mockReturnValueOnce(pendingLocation.promise)await launchAppFromSidebar('ns/app-b') // deactivates A, reads (deferred)- await waitFor(() => expect(getSandboxUiLocation).toHaveBeenCalledTimes(1))+ await waitFor(() => expect(getSandboxUiLocation).toHaveBeenCalled())await act(async () => {pendingLocation.resolve({ appRef: 'ns/app-b', routePath: '/b/route' })await Promise.resolve()await Promise.resolve()})- // Liveness witness (M4): A's deactivation read genuinely ran.- expect(getSandboxUiLocation).toHaveBeenCalledTimes(1)+ // Liveness witness (M4): A's deactivation read genuinely ran. A later+ // read may also occur while the incoming app activates.+ expect(getSandboxUiLocation).toHaveBeenCalled()// Observable: A keeps its OWN route — the foreign read must not clear it.// (Pre-fix, the mismatch fell back to undefined → setter CLEARED '/a/own'.)const appA = currentController.workspaceTabs.tabs.find(tab => tab.id === outgoingId)diff --git a/desktop-app/ui/src/hooks/__tests__/sessionAdapter.test.ts b/desktop-app/ui/src/hooks/__tests__/sessionAdapter.test.tsindex 91585acff..bb95a3e28 100644--- a/desktop-app/ui/src/hooks/__tests__/sessionAdapter.test.ts+++ b/desktop-app/ui/src/hooks/__tests__/sessionAdapter.test.ts@@ -162,7 +162,7 @@ describe('turnsToChatMessages', () => {expect(draft.unrestorable).toEqual([])})- it('retains agent and global file identity from a real server input through Resend', () => {+ it('retains agent file identity and flags a server global-file label without a URI', () => {const references: ComposerReferenceAttachment[] = [{id: 'agent-file',@@ -180,6 +180,8 @@ describe('turnsToChatMessages', () => {resourceId: 'res-9',gfsUri: 'gfs://drive-7/res-9',label: 'Report',+ version: 3,+ bytes: 4096,},]const [serverUser] = turnsToChatMessages([@@ -195,16 +197,14 @@ describe('turnsToChatMessages', () => {{type: 'global_file',label: 'Report',- drive: 'drive-7',- resourceId: 'res-9',- gfsUri: 'gfs://drive-7/res-9',},])const draft = buildComposerResendDraft(serverUser!)- expect(draft.unrestorable).toEqual([])- expect(buildComposerReferencesPromptSection(draft.referenceAttachments)).toBe(- buildComposerReferencesPromptSection(references)- )+ expect(draft.referenceAttachments).toMatchObject([+ { type: 'agent_file', filesystemName: 'shared-fs', path: 'notes/todo.md' },+ ])+ expect(draft.referenceAttachments).toHaveLength(1)+ expect(draft.unrestorable).toEqual([{ type: 'global_file', label: 'Report' }])})it('does not resend references from a same-text idle echo onto a context-free server turn', () => {diff --git a/desktop-app/ui/src/hooks/domain/desktopEnvironmentHandoff.ts b/desktop-app/ui/src/hooks/domain/desktopEnvironmentHandoff.tsindex 00a08344c..6a2f5ee48 100644--- a/desktop-app/ui/src/hooks/domain/desktopEnvironmentHandoff.ts+++ b/desktop-app/ui/src/hooks/domain/desktopEnvironmentHandoff.ts@@ -104,7 +104,7 @@ function decideSavedEnvironment(if (!linkedRpcOrigin) {if (sameRestOrigin.length > 1) return { kind: 'reject', reason: 'ambiguous' }- if (sameRestOrigin.length === 1) return { kind: 'select', option: sameRestOrigin[0] }+ if (sameRestOrigin.length === 1) return { kind: 'select', option: sameRestOrigin[0]! }return { kind: 'setup' }}diff --git a/desktop-app/ui/src/hooks/domain/useAuthController.ts b/desktop-app/ui/src/hooks/domain/useAuthController.tsindex 57bf8cf02..e837f00b9 100644--- a/desktop-app/ui/src/hooks/domain/useAuthController.ts+++ b/desktop-app/ui/src/hooks/domain/useAuthController.ts@@ -454,7 +454,7 @@ export function useAuthController({ setStatus, onSessionNeedsLoad }: UseAuthContreturn}- const selectedState = await handleSelectRuntimeConfig(restOriginMatches.saved[0].id)+ const selectedState = await handleSelectRuntimeConfig(restOriginMatches.saved[0]!.id)if (!selectedState) returnsetPendingDesktopEnvironmentSetup(null)try {diff --git a/desktop-app/ui/src/lib/__tests__/composerResend.test.ts b/desktop-app/ui/src/lib/__tests__/composerResend.test.tsindex 4a899ca25..038e249f6 100644--- a/desktop-app/ui/src/lib/__tests__/composerResend.test.ts+++ b/desktop-app/ui/src/lib/__tests__/composerResend.test.ts@@ -1,5 +1,6 @@import { describe, expect, it } from 'vitest'import type { ChatMessageAttachment } from '../../../../src/types'+import { buildChatMessageAttachments } from '../chatMessageAttachments'import {buildComposerResendDraft,findNearestPrecedingUserMessage,@@ -108,15 +109,48 @@ describe('buildComposerResendDraft', () => {kind: 'file',label: 'todo.md',},- {- id: 'global-file:resend:gfs://drive-7/res-9',- type: 'global_file',- resourceId: 'res-9',- drive: 'drive-7',- gfsUri: 'gfs://drive-7/res-9',- label: 'Report',- },])+ expect(draft.unrestorable).toEqual([{ type: 'global_file', label: 'Report' }])+ })++ it('restores a local global-file chip only with its versioned send identity', () => {+ const draft = buildComposerResendDraft({+ content: 'Read the report',+ attachments: buildChatMessageAttachments(+ [],+ [+ {+ id: 'global-local',+ type: 'global_file',+ label: 'Report',+ drive: 'drive-7',+ resourceId: 'res-9',+ gfsUri: 'gfs://drive-7/res-9',+ version: 3,+ bytes: 4096,+ },+ ]+ ),+ })+ expect(draft.referenceAttachments).toMatchObject([+ { type: 'global_file', gfsUri: 'gfs://drive-7/res-9', version: 3, bytes: 4096 },+ ])+ expect(draft.unrestorable).toEqual([])+ })++ it('does not combine a chip version with a URI found only in prompt text', () => {+ const draft = buildComposerResendDraft({+ content: [+ 'Read the report',+ 'USER-ATTACHED CONTEXT: The user selected these capabilities/files for this message.',+ 'Global Files: Report (gfs://drive-7/res-9). Resolve each gfs:// URI.',+ ].join('\n'),+ attachments: [+ { id: 'global-local', type: 'global_file', label: 'Report', version: 3, bytes: 4096 },+ ],+ })+ expect(draft.referenceAttachments).toEqual([])+ expect(draft.unrestorable).toEqual([{ type: 'global_file', label: 'Report' }])})it('keeps the structured plugin identity when the message also carries label chips', () => {diff --git a/desktop-app/ui/src/lib/chatMessageAttachments.ts b/desktop-app/ui/src/lib/chatMessageAttachments.tsindex fbe4d0fa6..4776a9b39 100644--- a/desktop-app/ui/src/lib/chatMessageAttachments.ts+++ b/desktop-app/ui/src/lib/chatMessageAttachments.ts@@ -177,6 +177,8 @@ export function buildChatMessageAttachments(gfsUri: attachment.gfsUri,drive: attachment.drive,resourceId: attachment.resourceId,+ version: attachment.version,+ bytes: attachment.bytes,}: {}),}diff --git a/desktop-app/ui/src/lib/composerResend.ts b/desktop-app/ui/src/lib/composerResend.tsindex bd069fd76..6512adc8d 100644--- a/desktop-app/ui/src/lib/composerResend.ts+++ b/desktop-app/ui/src/lib/composerResend.ts@@ -7,13 +7,12 @@* references.** Fidelity ladder (a message can carry its inputs in two places):- * 1. Persisted attachment chips carry uploaded image bytes and, for current- * messages, structured agent/global file identity from the composer or- * server-turn parser.- * 2. A legacy raw `USER-ATTACHED CONTEXT:` block can supply missing identity- * (plugin `ns/name`, agent-file `filesystem/path`, global-file URI).- * Bare labels without enough identity are reported as unrestorable so the- * composer never shows a chip that send will omit.+ * 1. Persisted attachment chips carry uploaded image bytes and structured+ * references. A global file also needs its listed version and byte size+ * for the current structured send contract.+ * 2. A legacy raw `USER-ATTACHED CONTEXT:` block can supply missing plugin+ * and agent-file identity. A global-file URI without version and size is+ * unrestorable, so the composer never shows a chip that send will omit.** `response_file` attachments are never re-applied: they are artifacts the* previous reply generated, not inputs of the resent prompt.@@ -229,17 +228,20 @@ function buildAgentFileReference(}function buildGlobalFileReference(- chip: ChatMessageAttachment,- structured: StructuredGlobalFile[]+ chip: ChatMessageAttachment): Extract<ComposerReferenceAttachment, { type: 'global_file' }> | null {const label = chip.label- const embedded = chip.gfsUri ? parseGlobalFileFromUri(label, chip.gfsUri) : null- const match =- (embedded?.drive && embedded.resourceId ? embedded : null) ??- structured.find(entry => entry.gfsUri && entry.label === label) ??- structured.find(entry => entry.gfsUri && pathBasename(entry.gfsUri) === label) ??- null- if (match) {+ const match = chip.gfsUri ? parseGlobalFileFromUri(label, chip.gfsUri) : null+ // URI, version, and size must come from the same persisted chip. Combining+ // a local version with a URI parsed from prompt text could name another file.+ if (+ match?.drive &&+ match.resourceId &&+ Number.isSafeInteger(chip.version) &&+ chip.version! >= 0 &&+ Number.isSafeInteger(chip.bytes) &&+ chip.bytes! >= 0+ ) {return {id: `global-file:resend:${match.gfsUri}`,type: 'global_file',@@ -247,6 +249,8 @@ function buildGlobalFileReference(drive: match.drive,gfsUri: match.gfsUri,label: match.label || pathBasename(match.gfsUri),+ version: chip.version!,+ bytes: chip.bytes!,}}return null@@ -296,7 +300,7 @@ export function buildComposerResendDraft(continue}if (chip.type === 'global_file') {- const reference = buildGlobalFileReference(chip, structured.globalFile)+ const reference = buildGlobalFileReference(chip)if (reference) referenceAttachments.push(reference)else unrestorable.push({ type: chip.type, label: chip.label })}