Skip to content

Commit

Permalink
fix: timestamp issue
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Dec 17, 2024
1 parent 66e37d8 commit 8613e35
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/src/browser/extensions/engines/OAIEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/node/api/restful/helper/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions core/src/types/message/messageEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion web/hooks/useSendChatMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
5 changes: 4 additions & 1 deletion web/utils/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 8613e35

Please sign in to comment.