Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop-ui): sync PR #976 with latest dev

Josuéa0c23ab938cd
diff --cc desktop-app/ui/src/hooks/domain/useAgentChatController.ts
index 9545808f0,79394edf9..3ed0f5bf4
--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
@@@ -1445,27 -1429,8 +1483,15 @@@ export function useAgentChatController(
return () => {
cancelled = true
}
- }, [cancelOlderMessagesLoad, currentTeamId, navItem, selectedAgent, isHostAccessBlocked])
+ }, [
+ cancelOlderMessagesLoad,
+ currentTeamId,
+ navItem,
+ selectedAgent,
+ isHostAccessBlocked,
+ switchToChatForIntent,
+ ])
- const mapComposerAttachmentsToHostRequest = (
- attachments: ComposerImageAttachment[]
- ): HostMessageAttachment[] =>
- attachments.map(att => ({
- id: att.id,
- kind: 'image',
- mimeType: att.mimeType,
- encoding: 'base64',
- dataBase64: att.dataBase64,
- filename: att.name,
- }))
-
// ─── Activity / progress state updaters (hoisted from sendAgentMessage so the
// tracker subscription effect and tracker callbacks can share them) ───
@@@ -2887,12 -2858,60 +2920,66 @@@
releaseSendSetup()
return
}
+ // #678 — the content the Host receives is fixed before anything is created
+ // or cleared, so the shared per-message limits are checked against the
+ // exact request and a refusal leaves the composer as the user typed it.
+ const baseContentForRequest = composerRequestBaseContent(
+ trimmedContent,
+ effectiveAttachments.length,
+ effectiveFiles.length
+ )
+ const effectiveContentForRequest = buildComposerRequestContent(
+ baseContentForRequest,
+ effectiveReferences
+ )
+ // The limits rpc-proxy and mcp-host enforce, most specific first: the
+ // count, the file quota, the share left for text and attachment details,
+ // then the whole body (images included), so the reason names what to
+ // remove. The share and the whole body apply to every send, so images
+ // alone that fill the body are refused here rather than by the proxy;
+ // the count and the file quota only when files are attached.
+ const requestForBudget = {
+ content: effectiveContentForRequest,
+ fileReferences: fileReferencesForSend,
+ hostRef: sendAgent,
+ files: effectiveFiles,
+ images: effectiveAttachments,
+ }
+ const hasFiles = effectiveFiles.length > 0
+ let budgetBlocker: string | null = null
+ if (
+ hasFiles &&
+ effectiveAttachments.length + effectiveFiles.length > COMPOSER_MAX_ATTACHMENTS
+ ) {
+ budgetBlocker = `A message can carry at most ${COMPOSER_MAX_ATTACHMENTS} attachments.`
+ } else if (
+ hasFiles &&
+ composerFileBase64Bytes(effectiveFiles) > COMPOSER_MAX_TOTAL_FILE_BASE64_BYTES
+ ) {
+ budgetBlocker = `The attached files take more than ${formatFileSize(COMPOSER_MAX_TOTAL_FILE_BASE64_BYTES)} once encoded. Remove a file.`
+ } else if (composerNonImageShareBytes(requestForBudget) > COMPOSER_MAX_NON_IMAGE_BODY_BYTES) {
+ budgetBlocker = `The message text and attachment details take more than ${formatFileSize(COMPOSER_MAX_NON_IMAGE_BODY_BYTES)} once encoded. Shorten the message or remove an attachment.`
+ } else if (
+ composerRequestBodyBytes(
+ requestForBudget,
+ effectiveAttachments.reduce((total, image) => total + image.dataBase64.length, 0)
+ ) > COMPOSER_MAX_REQUEST_BODY_BYTES
+ ) {
+ budgetBlocker = `The attachments and text take more than ${formatFileSize(COMPOSER_MAX_REQUEST_BODY_BYTES)} once encoded. Remove an attachment or shorten the message.`
+ }
+ if (budgetBlocker) {
+ setAgentError(budgetBlocker)
+ pushToast(budgetBlocker, 'error')
+ releaseSendSetup()
+ return
+ }
- let sendChatId = currentChatId ?? activeChatId
+ // This ref is the synchronous authority for the send target. A blank
+ // composer send also supersedes a pending latest/blank selection so an old
- // list response cannot replace the chat created by this send.
++ // list response cannot replace the chat created by this send. Capture this
++ // intent only after validation has accepted the exact request.
+ let sendChatId = currentChatId
+ const sendSelectionIntentRevision = currentChatId ? null : beginSelectionIntent()
+ if (sendSelectionIntentRevision !== null) clearPendingSelection(sendAgent)
const sendStillAuthorized = () =>
sendScope === sendScopeGeneration.current &&
sendScopeIdentity === currentAuthScopeRef.current &&
@@@ -3452,11 -3521,14 +3601,13 @@@
isChatDeleted,
revokeHostAccess,
holdHostAccess,
- activeChatId,
composerImageAttachments,
+ readyComposerFiles,
composerReferenceAttachments,
chatList,
chatStore,
- clearComposerAfterSend,
+ resetComposerAttachments,
+ markRetainedSendReason,
fsm,
applyLocalTitleOnly,
pushToast,
diff --cc desktop-app/ui/src/hooks/domain/useComposerAttachments.ts
index 3fd7f81cb,55c5c401a..47506011e
--- a/desktop-app/ui/src/hooks/domain/useComposerAttachments.ts
+++ b/desktop-app/ui/src/hooks/domain/useComposerAttachments.ts
@@@ -1,7 -1,20 +1,20 @@@
import { useCallback, useEffect, useRef, useState } from 'react'
- import { COMPOSER_MAX_IMAGE_ATTACHMENTS } from '@constants/attachments'
+ import { COMPOSER_MAX_ATTACHMENTS } from '@constants/attachments'
-import { clearComposerDraft, clearComposerDraftAfterSend } from '@lib/composerDraftStore'
+import { clearComposerDraft } from '@lib/composerDraftStore'
- import type { ComposerImageAttachment, ComposerReferenceAttachment } from '../../uiTypes'
+ import {
+ composerFileAdmissionError,
+ composerFileName,
+ readComposerFile,
+ } from '@lib/composerFileAdmission'
+ import { buildComposerFileReferences } from '@lib/composerFileReferences'
+ import { composerRequestBaseContent } from '@lib/composerHostRequest'
+ import { buildComposerRequestContent } from '@lib/composerReferencesPrompt'
+ import type {
+ ComposerFileAttachment,
+ ComposerFileRefusal,
+ ComposerImageAttachment,
+ ComposerReferenceAttachment,
+ } from '../../uiTypes'
interface UseComposerAttachmentsParams {
/** Attachments are per-agent; switching agents clears the pending composer. */
@@@ -56,14 -100,32 +100,22 @@@ export function useComposerAttachments(
revokeComposerPreviewUrls(previous)
return []
})
- }, [revokeComposerPreviewUrls])
+ }, [commitComposerImages, revokeComposerPreviewUrls])
- /** Clear BOTH pending attachment kinds (revoking image blob URLs). */
+ const clearComposerFileAttachments = useCallback(() => {
+ composerAttachmentRevisionRef.current += 1
+ // A read still in flight finds no entry for its id and is dropped.
+ commitComposerFiles(() => [])
+ }, [commitComposerFiles])
+
+ /** Clear every pending attachment kind (revoking image blob URLs). */
const resetComposerAttachments = useCallback(() => {
clearComposerImageAttachments()
+ clearComposerFileAttachments()
+ setComposerFileRefusals([])
setComposerReferenceAttachments([])
- }, [clearComposerImageAttachments])
+ }, [clearComposerFileAttachments, clearComposerImageAttachments])
- /** Post-send cleanup: clear the persisted draft for this chat, then the pending
- * attachments. Combines the three original send-path calls into one. */
- const clearComposerAfterSend = useCallback(
- (chatId: string | null) => {
- clearComposerDraftAfterSend(chatId)
- resetComposerAttachments()
- },
- [resetComposerAttachments]
- )
-
// Clear pending attachments when the selected agent changes (attachments are
// per-agent). The parent clears its own error/resend banner on the same change.
useEffect(() => {