fix: timestamp issue

This commit is contained in:
Louis 2024-12-17 17:12:03 +07:00
parent 66e37d80d6
commit 8613e35c15
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
6 changed files with 12 additions and 9 deletions

View File

@ -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',
}

View File

@ -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: [

View File

@ -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<string, unknown>

View File

@ -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,

View File

@ -91,7 +91,7 @@ const MessageContainer: React.FC<
: (activeAssistant?.assistant_name ?? props.role)}
</div>
<p className="text-xs font-medium text-gray-400">
{props.created && displayDate(props.created ?? new Date())}
{props.created_at && displayDate(props.created_at ?? new Date())}
</p>
</div>

View File

@ -6,7 +6,10 @@ export const isToday = (timestamp: number) => {
export const displayDate = (timestamp?: string | number | Date) => {
if (!timestamp) return 'N/A'
const date = new Date(timestamp)
const date =
typeof timestamp === 'number'
? new Date(timestamp * 1000)
: new Date(timestamp)
let displayDate = `${date.toLocaleDateString(undefined, {
day: '2-digit',