Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update thread's title edge cases #4320

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions web/hooks/useCreateNewThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
ExtensionTypeEnum,
Thread,
ThreadAssistantInfo,
ThreadState,

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'ThreadState' is defined but never used

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'ThreadState' is defined but never used

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'ThreadState' is defined but never used

Check warning on line 8 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'ThreadState' is defined but never used
AssistantTool,
Model,
Assistant,
} from '@janhq/core'
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'atom' is defined but never used

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'atom' is defined but never used

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'atom' is defined but never used

Check warning on line 13 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

'atom' is defined but never used

import { useDebouncedCallback } from 'use-debounce'

Expand Down Expand Up @@ -144,19 +144,19 @@
//TODO: Why do we have thread list then thread states? Should combine them
try {
const createdThread = await persistNewThread(thread, assistantInfo)
if (!createdThread) throw 'Thread created failed.'
createNewThread(createdThread)

Check warning on line 148 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

147-148 lines are not covered with tests

setSelectedModel(defaultModel)
setThreadModelParams(createdThread.id, {

Check warning on line 151 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

150-151 lines are not covered with tests
...defaultModel?.settings,
...defaultModel?.parameters,
...overriddenSettings,
})

// Delete the file upload state
setFileUpload(undefined)
setActiveThread(createdThread)

Check warning on line 159 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

158-159 lines are not covered with tests
} catch (ex) {
return toaster({
title: 'Thread created failed.',
Expand All @@ -167,7 +167,7 @@
}

const updateThreadExtension = (thread: Thread) => {
return extensionManager

Check warning on line 170 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

170 line is not covered with tests
.get<ConversationalExtension>(ExtensionTypeEnum.Conversational)
?.modifyThread(thread)
}
Expand All @@ -176,7 +176,7 @@
threadId: string,
assistant: ThreadAssistantInfo
) => {
return extensionManager

Check warning on line 179 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

179 line is not covered with tests
.get<ConversationalExtension>(ExtensionTypeEnum.Conversational)
?.modifyThreadAssistant(threadId, assistant)
}
Expand All @@ -191,9 +191,11 @@
async (thread: Thread) => {
updateThread(thread)

setActiveAssistant(thread.assistants[0])
updateThreadCallback(thread)
updateAssistantCallback(thread.id, thread.assistants[0])
if (thread.assistants && thread.assistants?.length > 0) {
setActiveAssistant(thread.assistants[0])
updateAssistantCallback(thread.id, thread.assistants[0])
}
},
[
updateThread,
Expand All @@ -211,13 +213,13 @@
.get<ConversationalExtension>(ExtensionTypeEnum.Conversational)
?.createThread(thread)
.then(async (thread) => {
await extensionManager

Check warning on line 216 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

216 line is not covered with tests
.get<ConversationalExtension>(ExtensionTypeEnum.Conversational)
?.createThreadAssistant(thread.id, assistantInfo)
.catch(console.error)
return thread

Check warning on line 220 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

220 line is not covered with tests
})
.catch(() => undefined)

Check warning on line 222 in web/hooks/useCreateNewThread.ts

View workflow job for this annotation

GitHub Actions / coverage-check

222 line is not covered with tests
}

return {
Expand Down
Loading