Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(desktop): make the composer image total one structural budget
Alfredo Lopez2c9d1e205439
diff --git a/desktop-app/ui/src/components/agents/ComposerPanel.tsx b/desktop-app/ui/src/components/agents/ComposerPanel.tsxindex 3f8582245..17b1d0f49 100644--- a/desktop-app/ui/src/components/agents/ComposerPanel.tsx+++ b/desktop-app/ui/src/components/agents/ComposerPanel.tsx@@ -23,6 +23,7 @@ import {COMPOSER_ACCEPT_IMAGE_MIME_TYPES,COMPOSER_MAX_IMAGE_ATTACHMENTS,type ComposerImageBudget,+ type ComposerImageTotalBudget,composerImageBudget,} from '@constants/attachments'import { useContextsDataController } from '@hooks/domain/useContextsDataController'@@ -63,12 +64,12 @@ function formatComposerMebibytes(bytes: number): number {return Math.round(bytes / (1024 * 1024))}-/** Only reached for a budget with a composer total, which always carries its label. */-function composerTotalLimitLabel(budget: ComposerImageBudget): string {- if (budget.totalLimitLabelBytes === null) {- throw new Error('composer image budget has a total without a label')- }- return `${formatComposerMebibytes(budget.totalLimitLabelBytes)} ${budget.sizeUnit}`+/** The label bytes travel with the total, so the impossible state is not representable. */+function composerTotalLimitLabel(+ total: ComposerImageTotalBudget,+ sizeUnit: ComposerImageBudget['sizeUnit']+): string {+ return `${formatComposerMebibytes(total.labelBytes)} ${sizeUnit}`}function bytesFromBase64(data: string): Uint8Array | null {@@ -557,7 +558,8 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPr} not added.`)}- // Non-Codex images travel inline in one 10 MB body (#669). Codex leaves+ // General images travel inline in one 10 MB body (#669); Grok counts the+ // same inline bytes against the 16 MiB ingress total (#784). Codex leaves// the aggregate to the hop (#650).let totalBase64Bytes = composerImageAttachments.reduce((total, attachment) => total + attachment.dataBase64.length,@@ -599,12 +601,13 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPrcontinue}if (- imageBudget.maxTotalBase64Bytes != null &&- totalBase64Bytes + dataBase64.length > imageBudget.maxTotalBase64Bytes+ imageBudget.total != null &&+ totalBase64Bytes + dataBase64.length > imageBudget.total.maxBase64Bytes) {validationErrors.push(`${file.name || 'Image'} does not fit in this message: the images in one message are limited to ${composerTotalLimitLabel(- imageBudget+ imageBudget.total,+ imageBudget.sizeUnit)} in total. Send the attached images first or remove one.`)revokePreviewUrl(previewUrl)@@ -670,17 +673,6 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPrattachment.id === updated.id ? total : total + attachment.dataBase64.length,0)- const combinedOverflow =- imageBudget.maxTotalBase64Bytes != null &&- otherBase64Bytes + updated.dataBase64.length > imageBudget.maxTotalBase64Bytes- if (- !composerImageExceedsPerImageBudget(updated.sizeBytes, imageBudget.maxImageBytes) &&- !dimensionError &&- !combinedOverflow- ) {- onUpdateComposerImageAttachment(updated)- return- }if (composerImageExceedsPerImageBudget(updated.sizeBytes, imageBudget.maxImageBytes)) {throw new Error(`${updated.name || 'Image'} was kept unchanged. Max size is ${formatComposerMebibytes(@@ -693,11 +685,18 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPr`${updated.name || 'Image'} was kept unchanged. Max resolution is ${imageBudget.maxDimension} px.`)}- throw new Error(- `${updated.name || 'Image'} was kept unchanged. The images in one message are limited to ${composerTotalLimitLabel(- imageBudget- )} in total.`- )+ if (+ imageBudget.total != null &&+ otherBase64Bytes + updated.dataBase64.length > imageBudget.total.maxBase64Bytes+ ) {+ throw new Error(+ `${updated.name || 'Image'} was kept unchanged. The images in one message are limited to ${composerTotalLimitLabel(+ imageBudget.total,+ imageBudget.sizeUnit+ )} in total.`+ )+ }+ onUpdateComposerImageAttachment(updated)},[composerImageAttachments, imageBudget, onUpdateComposerImageAttachment])diff --git a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsxindex 7c0f79fad..ee033d594 100644--- a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx+++ b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx@@ -10,6 +10,8 @@ import {COMPOSER_MAX_IMAGE_ATTACHMENTS,COMPOSER_MAX_IMAGE_BYTES,COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,+ GROK_COMPOSER_MAX_IMAGE_BYTES,+ GROK_COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,} from '@constants/attachments'import type { HostModelsResult } from '@hooks/useChatStore'import {@@ -832,11 +834,12 @@ describe('ComposerPanel Grok image budget', () => {models: [{ name: 'grok-4.6', displayName: 'Grok 4.6' }],}composerModelState.effectiveModel = 'grok-4.6'+ Object.assign(composerModelState, SUPPORTED_CAPABILITY)})- // The picker counts base64 bytes (22369624 = 4 * ceil(16 MiB / 3)), but the- // limit it enforces is the ingress's 16 MiB decoded total, so the copy says- // 16 MiB, not the rounded base64 figure (21 MiB).+ // The budget enforces the base64 total (22369624 = 4 * ceil(16 MiB / 3))+ // while the copy names the ingress's 16 MiB decoded total, not the rounded+ // base64 figure (21 MiB).it('names the 16 MiB decoded total when an annotation save exceeds it', () => {const grokTotalBase64Bytes = 4 * Math.ceil((16 * 1024 * 1024) / 3)const already: ComposerImageAttachment = {@@ -870,6 +873,31 @@ describe('ComposerPanel Grok image budget', () => {)expect(actionsMock.handleUpdateComposerImageAttachment).not.toHaveBeenCalled()})++ it('refuses a picked image that would push the message past the 16 MiB ingress total', async () => {+ const { container } = render(<ComposerPanel inline />)+ const rawBytes = Math.floor(GROK_COMPOSER_MAX_IMAGE_BYTES / 2)+ const base64Bytes = Math.ceil(rawBytes / 3) * 4+ expect(base64Bytes * 2).toBeLessThanOrEqual(GROK_COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES)+ expect(base64Bytes * 3).toBeGreaterThan(GROK_COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES)+ const files = ['first.png', 'second.png', 'third.png'].map((name, index) => {+ const bytes = new Uint8Array(rawBytes)+ bytes.set(PNG_BYTES)+ bytes[PNG_BYTES.length] = index+ return imageFile(name, 'image/png', bytes)+ })++ fireEvent.change(pickerInput(container), { target: { files } })++ await waitFor(() =>+ expect(actionsMock.handleAddComposerImageAttachments).toHaveBeenCalledTimes(1)+ )+ const [batch] = addedBatches()+ expect(batch?.map(attachment => attachment.name)).toEqual(['first.png', 'second.png'])+ expect(screen.getByRole('alert').textContent).toBe(+ 'third.png does not fit in this message: the images in one message are limited to 16 MiB in total. Send the attached images first or remove one.'+ )+ })})describe('ComposerPanel with a pending image after a model switch', () => {diff --git a/desktop-app/ui/src/constants/__tests__/attachments.test.ts b/desktop-app/ui/src/constants/__tests__/attachments.test.tsindex 736efb6ec..c8d350131 100644--- a/desktop-app/ui/src/constants/__tests__/attachments.test.ts+++ b/desktop-app/ui/src/constants/__tests__/attachments.test.ts@@ -14,18 +14,20 @@ describe('composerImageBudget', () => {const budget = composerImageBudget('grok-subscription')expect(budget).toEqual({maxImageBytes: 16777216,- maxTotalBase64Bytes: 22369624,- totalLimitLabelBytes: 16777216,+ total: {+ maxBase64Bytes: 22369624,+ labelBytes: 16777216,+ },maxDimension: null,sizeUnit: 'MiB',})// 16 MiB decoded, expressed as base64: the total rpc-proxy and mcp-host// accept for one message, not the 20 MiB xAI allows per image.expect(budget.maxImageBytes).toBe(16 * MIB)- expect(budget.maxTotalBase64Bytes).toBe(4 * Math.ceil((16 * MIB) / 3))+ expect(budget.total?.maxBase64Bytes).toBe(4 * Math.ceil((16 * MIB) / 3))// The copy names the decoded total (16 MiB), not the base64 bytes the// picker counts (which would round to "21 MiB").- expect(budget.totalLimitLabelBytes).toBe(16 * MIB)+ expect(budget.total?.labelBytes).toBe(16 * MIB)expect(15 * MIB).toBeLessThanOrEqual(budget.maxImageBytes)expect(17 * MIB).toBeGreaterThan(budget.maxImageBytes)})@@ -33,8 +35,7 @@ describe('composerImageBudget', () => {it('keeps the Codex budget unchanged', () => {expect(composerImageBudget('codex-subscription')).toEqual({maxImageBytes: CODEX_COMPOSER_MAX_IMAGE_BYTES,- maxTotalBase64Bytes: null,- totalLimitLabelBytes: null,+ total: null,maxDimension: CODEX_COMPOSER_MAX_IMAGE_DIMENSION,sizeUnit: 'MiB',})@@ -47,8 +48,10 @@ describe('composerImageBudget', () => {provider => {expect(composerImageBudget(provider)).toEqual({maxImageBytes: COMPOSER_MAX_IMAGE_BYTES,- maxTotalBase64Bytes: COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,- totalLimitLabelBytes: COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,+ total: {+ maxBase64Bytes: COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,+ labelBytes: COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,+ },maxDimension: null,sizeUnit: 'MB',})diff --git a/desktop-app/ui/src/constants/attachments.ts b/desktop-app/ui/src/constants/attachments.tsindex 3251561ad..6a9e57459 100644--- a/desktop-app/ui/src/constants/attachments.ts+++ b/desktop-app/ui/src/constants/attachments.ts@@ -37,16 +37,25 @@ export const COMPOSER_ACCEPT_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png'] as cexport const CODEX_SUBSCRIPTION_PROVIDER = 'codex-subscription'export const GROK_SUBSCRIPTION_PROVIDER = 'grok-subscription'+/**+ * The composer aggregate one message must fit in. The general branch counts+ * and names base64 MB (#669); Grok enforces the base64 encoding of the shared+ * 16 MiB ingress total but names the decoded figure (#784).+ */+export type ComposerImageTotalBudget = {+ /** Combined base64 bytes the composer counts and enforces. */+ maxBase64Bytes: number+ /**+ * Bytes the total-limit copy names. For Grok this is the decoded ingress+ * total, not the base64 bytes the picker counts.+ */+ labelBytes: number+}+export type ComposerImageBudget = {maxImageBytes: number/** `null` → no composer aggregate; the Codex hop owns that ceiling. */- maxTotalBase64Bytes: number | null- /**- * Bytes the total-limit copy names. It is the base64 total for the general- * branch (#669 counts and names base64 MB) and the decoded ingress total for- * Grok, whose base64 total is exactly the encoding of 16 MiB.- */- totalLimitLabelBytes: number | null+ total: ComposerImageTotalBudget | null/** `null` → no composer pixel bound (Grok and general models). */maxDimension: number | nullsizeUnit: 'MB' | 'MiB'@@ -60,8 +69,7 @@ export function composerImageBudget(provider: string | null | undefined): Composif (provider === CODEX_SUBSCRIPTION_PROVIDER) {return {maxImageBytes: CODEX_COMPOSER_MAX_IMAGE_BYTES,- maxTotalBase64Bytes: null,- totalLimitLabelBytes: null,+ total: null,maxDimension: CODEX_COMPOSER_MAX_IMAGE_DIMENSION,sizeUnit: 'MiB',}@@ -69,16 +77,20 @@ export function composerImageBudget(provider: string | null | undefined): Composif (provider === GROK_SUBSCRIPTION_PROVIDER) {return {maxImageBytes: GROK_COMPOSER_MAX_IMAGE_BYTES,- maxTotalBase64Bytes: GROK_COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,- totalLimitLabelBytes: GROK_COMPOSER_MAX_IMAGE_BYTES,+ total: {+ maxBase64Bytes: GROK_COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,+ labelBytes: GROK_COMPOSER_MAX_IMAGE_BYTES,+ },maxDimension: null,sizeUnit: 'MiB',}}return {maxImageBytes: COMPOSER_MAX_IMAGE_BYTES,- maxTotalBase64Bytes: COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,- totalLimitLabelBytes: COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,+ total: {+ maxBase64Bytes: COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,+ labelBytes: COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,+ },maxDimension: null,sizeUnit: 'MB',}