Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(projects): use project assistant for new chats (#8652)

Thinh Le4f99e3c896cb
diff --git a/web-app/src/containers/ChatInput.tsx b/web-app/src/containers/ChatInput.tsx
index 3ce850e8d..64c24b6c3 100644
--- a/web-app/src/containers/ChatInput.tsx
+++ b/web-app/src/containers/ChatInput.tsx
@@ -108,6 +108,7 @@ type ChatInputProps = {
model?: ThreadModel
initialMessage?: boolean
projectId?: string
+ projectAssistantId?: string
onSubmit?: (
text: string,
files?: Array<{ type: string; mediaType: string; url: string }>
@@ -138,6 +139,7 @@ const ChatInput = memo(function ChatInput({
className,
initialMessage,
projectId,
+ projectAssistantId,
onSubmit,
onStop,
chatStatus,
@@ -232,12 +234,12 @@ const ChatInput = memo(function ChatInput({
})
const [selectedAssistantId, setSelectedAssistantId] = useState<
string | undefined
- >(loading ? undefined : currentAssistant?.id || '')
+ >(loading ? undefined : projectAssistantId || currentAssistant?.id || '')
useEffect(() => {
- setSelectedAssistantId(currentAssistant?.id || '')
+ setSelectedAssistantId(projectAssistantId || currentAssistant?.id || '')
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [loading])
+ }, [loading, projectAssistantId])
// Jan Browser Extension hook
const {
diff --git a/web-app/src/containers/__tests__/ChatInput.test.tsx b/web-app/src/containers/__tests__/ChatInput.test.tsx
index 1f64e1395..c866cb511 100644
--- a/web-app/src/containers/__tests__/ChatInput.test.tsx
+++ b/web-app/src/containers/__tests__/ChatInput.test.tsx
@@ -96,9 +96,12 @@ vi.mock('@/hooks/useTokensCount', () => ({
vi.mock('@/hooks/useAssistant', () => ({
useAssistant: () => ({
loading: false,
- currentAssistant: { id: 'a1', avatar: '' },
+ currentAssistant: { id: 'a1', name: 'Global assistant', avatar: '' },
setCurrentAssistant: vi.fn(),
- assistants: [{ id: 'a1', avatar: '' }],
+ assistants: [
+ { id: 'a1', name: 'Global assistant', avatar: '' },
+ { id: 'a2', name: 'Project assistant', avatar: '' },
+ ],
}),
}))
@@ -338,6 +341,14 @@ describe('ChatInput', () => {
expect(document.querySelector('[data-test-id="send-message-button"]')).toBeTruthy()
})
+ it('shows the project assistant for a new conversation', () => {
+ renderInput({ projectId: 'project-1', projectAssistantId: 'a2' })
+
+ expect(
+ screen.getByRole('button', { name: 'Switch assistant' })
+ ).toHaveTextContent('Project assistant')
+ })
+
it('disables the send button when prompt is empty', () => {
renderInput()
const btn = document.querySelector(
diff --git a/web-app/src/routes/project/$projectId.tsx b/web-app/src/routes/project/$projectId.tsx
index a7a840b22..b22f52639 100644
--- a/web-app/src/routes/project/$projectId.tsx
+++ b/web-app/src/routes/project/$projectId.tsx
@@ -130,6 +130,7 @@ function ProjectPageContent() {
showSpeedToken={false}
initialMessage={true}
projectId={projectId}
+ projectAssistantId={project.assistantId}
/>
</div>