diff --git a/core/src/browser/extensions/engines/OAIEngine.ts b/core/src/browser/extensions/engines/OAIEngine.ts index df51d37bb0..0ed34c8db3 100644 --- a/core/src/browser/extensions/engines/OAIEngine.ts +++ b/core/src/browser/extensions/engines/OAIEngine.ts @@ -80,8 +80,8 @@ export abstract class OAIEngine extends AIEngine { role: ChatCompletionRole.Assistant, content: [], status: MessageStatus.Pending, - created: timestamp, - updated: timestamp, + created_at: timestamp, + completed_at: timestamp, object: 'thread.message', } diff --git a/core/src/node/api/restful/helper/builder.ts b/core/src/node/api/restful/helper/builder.ts index 230eb64ab0..31eb649a3c 100644 --- a/core/src/node/api/restful/helper/builder.ts +++ b/core/src/node/api/restful/helper/builder.ts @@ -194,8 +194,8 @@ export const createMessage = async (threadId: string, message: any) => { id: msgId, thread_id: threadId, status: MessageStatus.Ready, - created: createdAt, - updated: createdAt, + created_at: createdAt, + completed_at: createdAt, object: 'thread.message', role: message.role, content: [ diff --git a/core/src/types/message/messageEntity.ts b/core/src/types/message/messageEntity.ts index 7c2774da6d..302b824ee5 100644 --- a/core/src/types/message/messageEntity.ts +++ b/core/src/types/message/messageEntity.ts @@ -27,9 +27,9 @@ export type ThreadMessage = { /** The status of this message. **/ status: MessageStatus /** The timestamp indicating when this message was created. Represented in Unix time. **/ - created: number + created_at: number /** The timestamp indicating when this message was updated. Represented in Unix time. **/ - updated: number + completed_at: number /** The additional metadata of this message. **/ metadata?: Record diff --git a/web/hooks/usePath.ts b/web/hooks/usePath.ts index afdafe11ff..315072000a 100644 --- a/web/hooks/usePath.ts +++ b/web/hooks/usePath.ts @@ -1,6 +1,8 @@ -import { openFileExplorer, joinPath, baseName } from '@janhq/core' +import { openFileExplorer, joinPath, baseName, fs } from '@janhq/core' import { useAtomValue } from 'jotai' +import { getFileInfo } from '@/utils/file' + import { janDataFolderPathAtom } from '@/helpers/atoms/AppConfig.atom' import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom' import { selectedModelAtom } from '@/helpers/atoms/Model.atom' @@ -47,13 +49,23 @@ export const usePath = () => { const onViewFile = async (id: string) => { if (!activeThread) return - let filePath = undefined - id = await baseName(id) - filePath = await joinPath(['threads', `${activeThread.id}/files`, `${id}`]) - if (!filePath) return - const fullPath = await joinPath([janDataFolderPath, filePath]) - openFileExplorer(fullPath) + + // New ID System + if (!id.startsWith('file-')) { + const threadFilePath = await joinPath([ + janDataFolderPath, + 'threads', + `${activeThread.id}/files`, + id, + ]) + openFileExplorer(threadFilePath) + } else { + id = id.split('.')[0] + const fileName = (await getFileInfo(id)).filename + const filesPath = await joinPath([janDataFolderPath, 'files', fileName]) + openFileExplorer(filesPath) + } } const onViewFileContainer = async () => { diff --git a/web/hooks/useSendChatMessage.ts b/web/hooks/useSendChatMessage.ts index bbe5e3cd71..68db97c2a8 100644 --- a/web/hooks/useSendChatMessage.ts +++ b/web/hooks/useSendChatMessage.ts @@ -181,7 +181,7 @@ export default function useSendChatMessage() { // Update thread state const updatedThread: Thread = { ...activeThreadRef.current, - updated: newMessage.created, + updated: newMessage.created_at, metadata: { ...activeThreadRef.current.metadata, lastMessage: prompt, diff --git a/web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx b/web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx index b3246a26b7..4f00bbc595 100644 --- a/web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx @@ -126,7 +126,7 @@ const ChatInput = () => { const renderPreview = (fileUpload: any) => { if (fileUpload) { if (fileUpload.type === 'image') { - return + return } else { return } diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/DocMessage.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/DocMessage.tsx index 69d61d0d58..0051f832e3 100644 --- a/web/screens/Thread/ThreadCenterPanel/TextMessage/DocMessage.tsx +++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/DocMessage.tsx @@ -1,44 +1,39 @@ -import { memo } from 'react' - -import { Tooltip } from '@janhq/joi' - -import { FolderOpenIcon } from 'lucide-react' +import { memo, useEffect, useState } from 'react' import { usePath } from '@/hooks/usePath' -import { toGibibytes } from '@/utils/converter' -import { openFileTitle } from '@/utils/titleUtils' +import { getFileInfo } from '@/utils/file' import Icon from '../FileUploadPreview/Icon' -const DocMessage = ({ id, name }: { id: string; name?: string }) => { - const { onViewFile, onViewFileContainer } = usePath() +const DocMessage = ({ id }: { id: string }) => { + const { onViewFile } = usePath() + const [fileInfo, setFileInfo] = useState< + { filename: string; id: string } | undefined + >() + useEffect(() => { + if (!fileInfo) { + getFileInfo(id).then((data) => { + setFileInfo(data) + }) + } + }, [fileInfo, id]) return (
onViewFile(`${id}.pdf`)} /> - - -
- } - content={{openFileTitle()}} - /> +
-
- {name?.replaceAll(/[-._]/g, ' ')} +
+ {fileInfo?.filename}
- {/*

- {toGibibytes(Number(size))} -

*/} +

+ {fileInfo?.id ?? id} +

) diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/ImageMessage.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/ImageMessage.tsx index e83d35fbbb..14041721bb 100644 --- a/web/screens/Thread/ThreadCenterPanel/TextMessage/ImageMessage.tsx +++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/ImageMessage.tsx @@ -1,34 +1,11 @@ import { memo } from 'react' -import { Tooltip } from '@janhq/joi' - -import { FolderOpenIcon } from 'lucide-react' - -import { usePath } from '@/hooks/usePath' - -import { openFileTitle } from '@/utils/titleUtils' - import { RelativeImage } from '../TextMessage/RelativeImage' const ImageMessage = ({ image }: { image: string }) => { - const { onViewFile, onViewFileContainer } = usePath() - return ( -
-
- onViewFile(image)} /> -
- - -
- } - content={{openFileTitle()}} - /> +
+
) } diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/RelativeImage.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/RelativeImage.tsx index 72d2a9365b..bfd13b0efc 100644 --- a/web/screens/Thread/ThreadCenterPanel/TextMessage/RelativeImage.tsx +++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/RelativeImage.tsx @@ -7,7 +7,7 @@ export const RelativeImage = ({ onClick, }: { src: string - onClick: () => void + onClick?: () => void }) => { const [path, setPath] = useState('') @@ -17,9 +17,12 @@ export const RelativeImage = ({ }) }, []) return ( -