diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMessageIdContext.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMessageIdContext.tsx
index e57924eab..272b440ee 100644
--- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMessageIdContext.tsx
+++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/AIMessageIdContext.tsx
@@ -9,3 +9,8 @@ export const useAIMessageId = () => {
}
return ctx
}
+
+export const useAIMessageOptionalId = () => {
+ const ctx = use(AIMessageIdContext)
+ return ctx
+}
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/file-upload/FileAttachmentNode.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/file-upload/FileAttachmentNode.tsx
index 82d354ab2..5bc5b52aa 100644
--- a/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/file-upload/FileAttachmentNode.tsx
+++ b/apps/desktop/layer/renderer/src/modules/ai-chat/editor/plugins/file-upload/FileAttachmentNode.tsx
@@ -1,3 +1,4 @@
+/* eslint-disable react-refresh/only-export-components */
import type {
DOMConversionMap,
DOMConversionOutput,
@@ -10,8 +11,9 @@ import type {
import { DecoratorNode } from "lexical"
import * as React from "react"
-import { useAIMessageId } from "~/modules/ai-chat/components/message/AIMessageIdContext"
-import { useMessageByIdSelector } from "~/modules/ai-chat/store/hooks"
+import { useAIMessageOptionalId } from "~/modules/ai-chat/components/message/AIMessageIdContext"
+import { useChatBlockSelector, useMessageByIdSelector } from "~/modules/ai-chat/store/hooks"
+import type { FileAttachment } from "~/modules/ai-chat/store/types"
import { findFileAttachmentBlock, isDataBlockPart } from "~/modules/ai-chat/utils/extractor"
export type SerializedFileAttachmentNode = Spread<
@@ -110,31 +112,7 @@ interface FileAttachmentComponentProps {
node: FileAttachmentNode
}
-function FileAttachmentComponent({ node }: FileAttachmentComponentProps) {
- const attachmentId = node.getAttachmentId()
-
- const messageId = useAIMessageId()!
-
- const fileAttachment = useMessageByIdSelector(messageId, (message) => {
- for (const part of message.parts) {
- if (!isDataBlockPart(part)) continue
-
- const block = findFileAttachmentBlock(part, attachmentId)
- if (block) {
- return block.attachment
- }
- }
- })
-
- if (!fileAttachment) {
- return (
-
-
- File not found
-
- )
- }
-
+function FileAttachmentPill({ attachment }: { attachment: FileAttachment }) {
return (
-
- {fileAttachment.name}
+
+ {attachment.name}
- {fileAttachment.uploadStatus === "uploading" && (
+ {attachment.uploadStatus === "uploading" && (
)}
- {fileAttachment.uploadStatus === "processing" && (
+ {attachment.uploadStatus === "processing" && (
)}
- {fileAttachment.uploadStatus === "error" && }
- {fileAttachment.uploadStatus === "completed" && (
-
- )}
+ {attachment.uploadStatus === "error" && }
+ {attachment.uploadStatus === "completed" && }
)
}
+function MissingFilePill() {
+ return (
+
+
+ File not found
+
+ )
+}
+
+function BlockBasedAttachment({ attachmentId }: { attachmentId: string }) {
+ const block = useChatBlockSelector((state) =>
+ state.blocks.find(
+ (block) => block.type === "fileAttachment" && block.attachment.id === attachmentId,
+ ),
+ )
+
+ if (!block || block.type !== "fileAttachment") {
+ return
+ }
+
+ return
+}
+
+function MessageBasedAttachment({
+ attachmentId,
+ messageId,
+}: {
+ attachmentId: string
+ messageId: string
+}) {
+ const attachment = useMessageByIdSelector(messageId, (message) => {
+ for (const part of message.parts) {
+ if (!isDataBlockPart(part)) continue
+ const block = findFileAttachmentBlock(part, attachmentId)
+ if (block) return block.attachment
+ }
+ })
+
+ if (attachment) return
+ // Fallback to block-based when message-based lookup fails
+ return
+}
+
+function FileAttachmentComponent({ node }: FileAttachmentComponentProps) {
+ const attachmentId = node.getAttachmentId()
+
+ const messageId = useAIMessageOptionalId()
+
+ if (messageId) {
+ return
+ }
+ return
+}
+
export function $createFileAttachmentNode(attachmentId: string): FileAttachmentNode {
return new FileAttachmentNode(attachmentId)
}
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/store/hooks.ts b/apps/desktop/layer/renderer/src/modules/ai-chat/store/hooks.ts
index ea94e86dd..c75110017 100644
--- a/apps/desktop/layer/renderer/src/modules/ai-chat/store/hooks.ts
+++ b/apps/desktop/layer/renderer/src/modules/ai-chat/store/hooks.ts
@@ -2,6 +2,7 @@ import type { BizUIMessage } from "@folo-services/ai-tools"
import { useShallow } from "zustand/shallow"
import { useAIChatStore } from "./AIChatContext"
+import type { BlockSlice } from "./slices/block.slice"
/**
* Hook to get the current room ID (chat ID) from the AI chat store
@@ -88,3 +89,8 @@ export const useChatScene = () => {
const store = useAIChatStore()
return store((state) => state.scene)
}
+
+export const useChatBlockSelector = (selector: (state: Pick) => T) => {
+ const store = useAIChatStore()
+ return store(useShallow((state) => selector(state)))
+}
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/utils/file-validation.ts b/apps/desktop/layer/renderer/src/modules/ai-chat/utils/file-validation.ts
index 3eb4372d2..150a9bb87 100644
--- a/apps/desktop/layer/renderer/src/modules/ai-chat/utils/file-validation.ts
+++ b/apps/desktop/layer/renderer/src/modules/ai-chat/utils/file-validation.ts
@@ -114,17 +114,16 @@ export function getFileCategoryFromMimeType(mimeType: string): FileCategory {
export function getFileIconName(category: FileCategory): string {
switch (category) {
case "image": {
- return "i-mgc-pic-cute-re"
+ return tw`i-mgc-pic-cute-re`
}
case "document": {
- return "i-mgc-file-cute-re"
+ return tw`i-mingcute-file-line`
}
case "text": {
- return "i-mgc-document-cute-re"
+ return tw`i-mingcute-text-line`
}
-
default: {
- return "i-mgc-attachment-cute-re"
+ return tw`i-mgc-attachment-cute-re`
}
}
}