From 432477341c65eba5f4a071ec20699e03cf6d23c6 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 19 Dec 2024 10:32:35 +0700 Subject: [PATCH 1/5] fix: new thread isn't automatically created on factory reset --- web/helpers/atoms/Assistant.atom.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/helpers/atoms/Assistant.atom.ts b/web/helpers/atoms/Assistant.atom.ts index cb50a0553e..29da581c34 100644 --- a/web/helpers/atoms/Assistant.atom.ts +++ b/web/helpers/atoms/Assistant.atom.ts @@ -4,9 +4,15 @@ import { atomWithStorage } from 'jotai/utils' export const assistantsAtom = atom([]) +export const cachedAssistantAtom = atomWithStorage< + ThreadAssistantInfo | undefined +>('activeAssistant', undefined, undefined, { getOnInit: true }) /** * Get the current active assistant */ -export const activeAssistantAtom = atomWithStorage< - ThreadAssistantInfo | undefined ->('activeAssistant', undefined, undefined, { getOnInit: true }) +export const activeAssistantAtom = atom( + (get) => get(cachedAssistantAtom) ?? get(assistantsAtom)[0], + (_get, set, newAssistant: ThreadAssistantInfo) => { + set(cachedAssistantAtom, newAssistant) + } +) From bdcc3ef48cd0206419668f54a181b792fd0017e5 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 19 Dec 2024 10:51:13 +0700 Subject: [PATCH 2/5] chore: fix role --- web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx index ddd82590bc..52b10b8270 100644 --- a/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx @@ -88,7 +88,9 @@ const MessageContainer: React.FC< > {isUser ? props.role - : (activeAssistant?.assistant_name ?? props.role)} + : 'assistant_name' in activeAssistant + ? activeAssistant?.assistant_name + : props.role}

{props.created_at && displayDate(props.created_at ?? new Date())} From 4cd0e63029a73e0d54be75fde3f3c3004461c783 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 19 Dec 2024 11:16:17 +0700 Subject: [PATCH 3/5] fix: create new thread with default assistant --- web/helpers/atoms/Assistant.atom.ts | 12 +++--------- .../Thread/ThreadCenterPanel/TextMessage/index.tsx | 4 +--- web/screens/Thread/ThreadLeftPanel/index.tsx | 5 +++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/web/helpers/atoms/Assistant.atom.ts b/web/helpers/atoms/Assistant.atom.ts index 29da581c34..cb50a0553e 100644 --- a/web/helpers/atoms/Assistant.atom.ts +++ b/web/helpers/atoms/Assistant.atom.ts @@ -4,15 +4,9 @@ import { atomWithStorage } from 'jotai/utils' export const assistantsAtom = atom([]) -export const cachedAssistantAtom = atomWithStorage< - ThreadAssistantInfo | undefined ->('activeAssistant', undefined, undefined, { getOnInit: true }) /** * Get the current active assistant */ -export const activeAssistantAtom = atom( - (get) => get(cachedAssistantAtom) ?? get(assistantsAtom)[0], - (_get, set, newAssistant: ThreadAssistantInfo) => { - set(cachedAssistantAtom, newAssistant) - } -) +export const activeAssistantAtom = atomWithStorage< + ThreadAssistantInfo | undefined +>('activeAssistant', undefined, undefined, { getOnInit: true }) diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx index 52b10b8270..ddd82590bc 100644 --- a/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx @@ -88,9 +88,7 @@ const MessageContainer: React.FC< > {isUser ? props.role - : 'assistant_name' in activeAssistant - ? activeAssistant?.assistant_name - : props.role} + : (activeAssistant?.assistant_name ?? props.role)}

{props.created_at && displayDate(props.created_at ?? new Date())} diff --git a/web/screens/Thread/ThreadLeftPanel/index.tsx b/web/screens/Thread/ThreadLeftPanel/index.tsx index 46763e555c..64a272ca6a 100644 --- a/web/screens/Thread/ThreadLeftPanel/index.tsx +++ b/web/screens/Thread/ThreadLeftPanel/index.tsx @@ -71,7 +71,6 @@ const ThreadLeftPanel = () => { useEffect(() => { if ( threadDataReady && - activeAssistant && assistants.length > 0 && threads.length === 0 && downloadedModels.length > 0 @@ -81,7 +80,9 @@ const ThreadLeftPanel = () => { ) const selectedModel = model[0] || recommendedModel requestCreateNewThread( - { ...assistants[0], ...activeAssistant }, + activeAssistant + ? { ...assistants[0], ...activeAssistant } + : assistants[0], selectedModel ) } else if (threadDataReady && !activeThreadId) { From b81b008a9382915f258f03be8529b84349cc7d28 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 19 Dec 2024 11:38:10 +0700 Subject: [PATCH 4/5] chore: use seconds timestamp system --- core/src/browser/extensions/engines/OAIEngine.ts | 2 +- extensions/assistant-extension/src/index.ts | 2 +- web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx | 3 ++- web/utils/datetime.ts | 5 ++++- web/utils/messageRequestBuilder.ts | 2 +- web/utils/threadMessageBuilder.ts | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/browser/extensions/engines/OAIEngine.ts b/core/src/browser/extensions/engines/OAIEngine.ts index 0ed34c8db3..6b4c20a196 100644 --- a/core/src/browser/extensions/engines/OAIEngine.ts +++ b/core/src/browser/extensions/engines/OAIEngine.ts @@ -71,7 +71,7 @@ export abstract class OAIEngine extends AIEngine { return } - const timestamp = Date.now() + const timestamp = Date.now() / 1000 const message: ThreadMessage = { id: ulid(), thread_id: data.threadId, diff --git a/extensions/assistant-extension/src/index.ts b/extensions/assistant-extension/src/index.ts index 0b3a1ec403..621d8e2167 100644 --- a/extensions/assistant-extension/src/index.ts +++ b/extensions/assistant-extension/src/index.ts @@ -127,7 +127,7 @@ export default class JanAssistantExtension extends AssistantExtension { thread_location: undefined, id: 'jan', object: 'assistant', - created_at: Date.now(), + created_at: Date.now() / 1000, name: 'Jan', description: 'A default assistant that can use all downloaded models', model: '*', diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx index ddd82590bc..c029da74d7 100644 --- a/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx @@ -91,7 +91,8 @@ const MessageContainer: React.FC< : (activeAssistant?.assistant_name ?? props.role)}

- {props.created_at && displayDate(props.created_at ?? new Date())} + {props.created_at && + displayDate(props.created_at ?? Date.now() / 1000)}

diff --git a/web/utils/datetime.ts b/web/utils/datetime.ts index aec1c92ab8..f5fdf8226e 100644 --- a/web/utils/datetime.ts +++ b/web/utils/datetime.ts @@ -1,6 +1,9 @@ export const isToday = (timestamp: number) => { const today = new Date() - return today.setHours(0, 0, 0, 0) === new Date(timestamp).setHours(0, 0, 0, 0) + return ( + today.setHours(0, 0, 0, 0) === + new Date(timestamp * 1000).setHours(0, 0, 0, 0) + ) } export const displayDate = (timestamp?: string | number | Date) => { diff --git a/web/utils/messageRequestBuilder.ts b/web/utils/messageRequestBuilder.ts index 99560636ee..269dfcee4c 100644 --- a/web/utils/messageRequestBuilder.ts +++ b/web/utils/messageRequestBuilder.ts @@ -15,7 +15,7 @@ import { ulid } from 'ulidx' import { Stack } from '@/utils/Stack' -import { FileInfo, FileType } from '@/types/file' +import { FileInfo } from '@/types/file' export class MessageRequestBuilder { msgId: string diff --git a/web/utils/threadMessageBuilder.ts b/web/utils/threadMessageBuilder.ts index d10ef03c40..8a776d5df3 100644 --- a/web/utils/threadMessageBuilder.ts +++ b/web/utils/threadMessageBuilder.ts @@ -22,7 +22,7 @@ export class ThreadMessageBuilder { } build(): ThreadMessage { - const timestamp = Date.now() + const timestamp = Date.now() / 1000 return { id: this.messageRequest.msgId, thread_id: this.messageRequest.thread.id, From 5b9c1fc668c48118c7099460a3c230d8ce11ea7b Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 19 Dec 2024 12:10:14 +0700 Subject: [PATCH 5/5] fix: token speed disappear on complete --- web/containers/Providers/ModelHandler.tsx | 3 +++ web/utils/datetime.test.ts | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/web/containers/Providers/ModelHandler.tsx b/web/containers/Providers/ModelHandler.tsx index d72db4e8e0..8e5c3ca6b9 100644 --- a/web/containers/Providers/ModelHandler.tsx +++ b/web/containers/Providers/ModelHandler.tsx @@ -264,6 +264,9 @@ export default function ModelHandler() { if (updatedMessage) { deleteMessage(message.id) addNewMessage(updatedMessage) + setTokenSpeed((prev) => + prev ? { ...prev, message: updatedMessage.id } : undefined + ) } })() diff --git a/web/utils/datetime.test.ts b/web/utils/datetime.test.ts index e7e00ada98..605f98d24e 100644 --- a/web/utils/datetime.test.ts +++ b/web/utils/datetime.test.ts @@ -4,11 +4,7 @@ import { isToday } from './datetime' test("should return only time for today's timestamp", () => { const today = new Date() const timestamp = today.getTime() - const expectedTime = `${today.toLocaleDateString(undefined, { - day: '2-digit', - month: 'short', - year: 'numeric', - })}, ${today.toLocaleTimeString(undefined, { + const expectedTime = `${today.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit', @@ -24,5 +20,5 @@ test('should return N/A for undefined timestamp', () => { test("should return true for today's timestamp", () => { const today = new Date() const timestamp = today.setHours(0, 0, 0, 0) - expect(isToday(timestamp)).toBe(true) + expect(isToday(timestamp / 1000)).toBe(true) })