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.

chore: address PR comments

Vanalitea951e6d7d704
diff --git a/extensions/yarn.lock b/extensions/yarn.lock
index f4a58c14f..1c0f29872 100644
--- a/extensions/yarn.lock
+++ b/extensions/yarn.lock
@@ -342,41 +342,73 @@ __metadata:
"@janhq/core@file:../../core/package.tgz::locator=%40janhq%2Fassistant-extension%40workspace%3Aassistant-extension":
version: 0.1.10
- resolution: "@janhq/core@file:../../core/package.tgz#../../core/package.tgz::hash=f15485&locator=%40janhq%2Fassistant-extension%40workspace%3Aassistant-extension"
+ resolution: "@janhq/core@file:../../core/package.tgz#../../core/package.tgz::hash=16006d&locator=%40janhq%2Fassistant-extension%40workspace%3Aassistant-extension"
dependencies:
rxjs: "npm:^7.8.1"
ulidx: "npm:^2.3.0"
- checksum: 10c0/257621cb56db31a4dd3a2b509ec4c61217022e74bbd39cf6a1a172073654b9a65eee94ef9c1b4d4f5d2231d159c8818cb02846f3d88fe14f102f43169ad3737c
+ peerDependencies:
+ react: 19.0.0
+ checksum: 10c0/58a966e7f4aabfe7ee6c34958ca4b90c0de1d1210be9397e8f3fa77dbb4d744c4bc9814647652abd747cdbce630a0035be5e1eb748e38c354199110a5f3dc42f
languageName: node
linkType: hard
"@janhq/core@file:../../core/package.tgz::locator=%40janhq%2Fconversational-extension%40workspace%3Aconversational-extension":
version: 0.1.10
- resolution: "@janhq/core@file:../../core/package.tgz#../../core/package.tgz::hash=f15485&locator=%40janhq%2Fconversational-extension%40workspace%3Aconversational-extension"
+ resolution: "@janhq/core@file:../../core/package.tgz#../../core/package.tgz::hash=16006d&locator=%40janhq%2Fconversational-extension%40workspace%3Aconversational-extension"
dependencies:
rxjs: "npm:^7.8.1"
ulidx: "npm:^2.3.0"
- checksum: 10c0/257621cb56db31a4dd3a2b509ec4c61217022e74bbd39cf6a1a172073654b9a65eee94ef9c1b4d4f5d2231d159c8818cb02846f3d88fe14f102f43169ad3737c
+ peerDependencies:
+ react: 19.0.0
+ checksum: 10c0/58a966e7f4aabfe7ee6c34958ca4b90c0de1d1210be9397e8f3fa77dbb4d744c4bc9814647652abd747cdbce630a0035be5e1eb748e38c354199110a5f3dc42f
languageName: node
linkType: hard
"@janhq/core@file:../../core/package.tgz::locator=%40janhq%2Fdownload-extension%40workspace%3Adownload-extension":
version: 0.1.10
- resolution: "@janhq/core@file:../../core/package.tgz#../../core/package.tgz::hash=f15485&locator=%40janhq%2Fdownload-extension%40workspace%3Adownload-extension"
+ resolution: "@janhq/core@file:../../core/package.tgz#../../core/package.tgz::hash=16006d&locator=%40janhq%2Fdownload-extension%40workspace%3Adownload-extension"
dependencies:
rxjs: "npm:^7.8.1"
ulidx: "npm:^2.3.0"
- checksum: 10c0/257621cb56db31a4dd3a2b509ec4c61217022e74bbd39cf6a1a172073654b9a65eee94ef9c1b4d4f5d2231d159c8818cb02846f3d88fe14f102f43169ad3737c
+ peerDependencies:
+ react: 19.0.0
+ checksum: 10c0/58a966e7f4aabfe7ee6c34958ca4b90c0de1d1210be9397e8f3fa77dbb4d744c4bc9814647652abd747cdbce630a0035be5e1eb748e38c354199110a5f3dc42f
languageName: node
linkType: hard
"@janhq/core@file:../../core/package.tgz::locator=%40janhq%2Fllamacpp-extension%40workspace%3Allamacpp-extension":
version: 0.1.10
- resolution: "@janhq/core@file:../../core/package.tgz#../../core/package.tgz::hash=f15485&locator=%40janhq%2Fllamacpp-extension%40workspace%3Allamacpp-extension"
+ resolution: "@janhq/core@file:../../core/package.tgz#../../core/package.tgz::hash=16006d&locator=%40janhq%2Fllamacpp-extension%40workspace%3Allamacpp-extension"
+ dependencies:
+ rxjs: "npm:^7.8.1"
+ ulidx: "npm:^2.3.0"
+ peerDependencies:
+ react: 19.0.0
+ checksum: 10c0/58a966e7f4aabfe7ee6c34958ca4b90c0de1d1210be9397e8f3fa77dbb4d744c4bc9814647652abd747cdbce630a0035be5e1eb748e38c354199110a5f3dc42f
+ languageName: node
+ linkType: hard
+
+"@janhq/core@file:../../core/package.tgz::locator=%40janhq%2Frag-extension%40workspace%3Arag-extension":
+ version: 0.1.10
+ resolution: "@janhq/core@file:../../core/package.tgz#../../core/package.tgz::hash=16006d&locator=%40janhq%2Frag-extension%40workspace%3Arag-extension"
+ dependencies:
+ rxjs: "npm:^7.8.1"
+ ulidx: "npm:^2.3.0"
+ peerDependencies:
+ react: 19.0.0
+ checksum: 10c0/58a966e7f4aabfe7ee6c34958ca4b90c0de1d1210be9397e8f3fa77dbb4d744c4bc9814647652abd747cdbce630a0035be5e1eb748e38c354199110a5f3dc42f
+ languageName: node
+ linkType: hard
+
+"@janhq/core@file:../../core/package.tgz::locator=%40janhq%2Fvector-db-extension%40workspace%3Avector-db-extension":
+ version: 0.1.10
+ resolution: "@janhq/core@file:../../core/package.tgz#../../core/package.tgz::hash=16006d&locator=%40janhq%2Fvector-db-extension%40workspace%3Avector-db-extension"
dependencies:
rxjs: "npm:^7.8.1"
ulidx: "npm:^2.3.0"
- checksum: 10c0/257621cb56db31a4dd3a2b509ec4c61217022e74bbd39cf6a1a172073654b9a65eee94ef9c1b4d4f5d2231d159c8818cb02846f3d88fe14f102f43169ad3737c
+ peerDependencies:
+ react: 19.0.0
+ checksum: 10c0/58a966e7f4aabfe7ee6c34958ca4b90c0de1d1210be9397e8f3fa77dbb4d744c4bc9814647652abd747cdbce630a0035be5e1eb748e38c354199110a5f3dc42f
languageName: node
linkType: hard
@@ -418,6 +450,20 @@ __metadata:
languageName: unknown
linkType: soft
+"@janhq/rag-extension@workspace:rag-extension":
+ version: 0.0.0-use.local
+ resolution: "@janhq/rag-extension@workspace:rag-extension"
+ dependencies:
+ "@janhq/core": ../../core/package.tgz
+ "@janhq/tauri-plugin-rag-api": "link:../../src-tauri/plugins/tauri-plugin-rag"
+ "@janhq/tauri-plugin-vector-db-api": "link:../../src-tauri/plugins/tauri-plugin-vector-db"
+ cpx: "npm:1.5.0"
+ rimraf: "npm:6.0.1"
+ rolldown: "npm:1.0.0-beta.1"
+ typescript: "npm:5.9.2"
+ languageName: unknown
+ linkType: soft
+
"@janhq/tauri-plugin-hardware-api@link:../../src-tauri/plugins/tauri-plugin-hardware::locator=%40janhq%2Fllamacpp-extension%40workspace%3Allamacpp-extension":
version: 0.0.0-use.local
resolution: "@janhq/tauri-plugin-hardware-api@link:../../src-tauri/plugins/tauri-plugin-hardware::locator=%40janhq%2Fllamacpp-extension%40workspace%3Allamacpp-extension"
@@ -430,6 +476,44 @@ __metadata:
languageName: node
linkType: soft
+"@janhq/tauri-plugin-rag-api@link:../../src-tauri/plugins/tauri-plugin-rag::locator=%40janhq%2Frag-extension%40workspace%3Arag-extension":
+ version: 0.0.0-use.local
+ resolution: "@janhq/tauri-plugin-rag-api@link:../../src-tauri/plugins/tauri-plugin-rag::locator=%40janhq%2Frag-extension%40workspace%3Arag-extension"
+ languageName: node
+ linkType: soft
+
+"@janhq/tauri-plugin-rag-api@link:../../src-tauri/plugins/tauri-plugin-rag::locator=%40janhq%2Fvector-db-extension%40workspace%3Avector-db-extension":
+ version: 0.0.0-use.local
+ resolution: "@janhq/tauri-plugin-rag-api@link:../../src-tauri/plugins/tauri-plugin-rag::locator=%40janhq%2Fvector-db-extension%40workspace%3Avector-db-extension"
+ languageName: node
+ linkType: soft
+
+"@janhq/tauri-plugin-vector-db-api@link:../../src-tauri/plugins/tauri-plugin-vector-db::locator=%40janhq%2Frag-extension%40workspace%3Arag-extension":
+ version: 0.0.0-use.local
+ resolution: "@janhq/tauri-plugin-vector-db-api@link:../../src-tauri/plugins/tauri-plugin-vector-db::locator=%40janhq%2Frag-extension%40workspace%3Arag-extension"
+ languageName: node
+ linkType: soft
+
+"@janhq/tauri-plugin-vector-db-api@link:../../src-tauri/plugins/tauri-plugin-vector-db::locator=%40janhq%2Fvector-db-extension%40workspace%3Avector-db-extension":
+ version: 0.0.0-use.local
+ resolution: "@janhq/tauri-plugin-vector-db-api@link:../../src-tauri/plugins/tauri-plugin-vector-db::locator=%40janhq%2Fvector-db-extension%40workspace%3Avector-db-extension"
+ languageName: node
+ linkType: soft
+
+"@janhq/vector-db-extension@workspace:vector-db-extension":
+ version: 0.0.0-use.local
+ resolution: "@janhq/vector-db-extension@workspace:vector-db-extension"
+ dependencies:
+ "@janhq/core": ../../core/package.tgz
+ "@janhq/tauri-plugin-rag-api": "link:../../src-tauri/plugins/tauri-plugin-rag"
+ "@janhq/tauri-plugin-vector-db-api": "link:../../src-tauri/plugins/tauri-plugin-vector-db"
+ cpx: "npm:1.5.0"
+ rimraf: "npm:6.0.1"
+ rolldown: "npm:1.0.0-beta.1"
+ typescript: "npm:5.9.2"
+ languageName: unknown
+ linkType: soft
+
"@jridgewell/sourcemap-codec@npm:^1.5.0":
version: 1.5.0
resolution: "@jridgewell/sourcemap-codec@npm:1.5.0"
diff --git a/src-tauri/plugins/yarn.lock b/src-tauri/plugins/yarn.lock
index 3fba44fdc..7474ac631 100644
--- a/src-tauri/plugins/yarn.lock
+++ b/src-tauri/plugins/yarn.lock
@@ -52,6 +52,30 @@ __metadata:
languageName: unknown
linkType: soft
+"@janhq/tauri-plugin-rag-api@workspace:tauri-plugin-rag":
+ version: 0.0.0-use.local
+ resolution: "@janhq/tauri-plugin-rag-api@workspace:tauri-plugin-rag"
+ dependencies:
+ "@rollup/plugin-typescript": "npm:^12.0.0"
+ "@tauri-apps/api": "npm:>=2.0.0-beta.6"
+ rollup: "npm:^4.9.6"
+ tslib: "npm:^2.6.2"
+ typescript: "npm:^5.3.3"
+ languageName: unknown
+ linkType: soft
+
+"@janhq/tauri-plugin-vector-db-api@workspace:tauri-plugin-vector-db":
+ version: 0.0.0-use.local
+ resolution: "@janhq/tauri-plugin-vector-db-api@workspace:tauri-plugin-vector-db"
+ dependencies:
+ "@rollup/plugin-typescript": "npm:^12.0.0"
+ "@tauri-apps/api": "npm:>=2.0.0-beta.6"
+ rollup: "npm:^4.9.6"
+ tslib: "npm:^2.6.2"
+ typescript: "npm:^5.3.3"
+ languageName: unknown
+ linkType: soft
+
"@npmcli/agent@npm:^3.0.0":
version: 3.0.0
resolution: "@npmcli/agent@npm:3.0.0"
diff --git a/web-app/src/containers/ScrollToBottom.tsx b/web-app/src/containers/ScrollToBottom.tsx
index 856bf6ddc..281aec91e 100644
--- a/web-app/src/containers/ScrollToBottom.tsx
+++ b/web-app/src/containers/ScrollToBottom.tsx
@@ -1,5 +1,5 @@
import { useThreadScrolling } from '@/hooks/useThreadScrolling'
-import { memo } from 'react'
+import { memo, useEffect } from 'react'
import { GenerateResponseButton } from './GenerateResponseButton'
import { useMessages } from '@/hooks/useMessages'
import { useShallow } from 'zustand/react/shallow'
@@ -51,15 +51,17 @@ const ScrollToBottom = ({
const isModelMismatch = isPartialResponse && (currentModelMismatch || hasModelSwitchedFlag)
- if (currentModelMismatch && !hasModelSwitchedFlag && partialMessage) {
- updateMessage({
- ...partialMessage,
- metadata: {
- ...partialMessage.metadata,
- modelSwitched: true,
- },
- })
- }
+ useEffect(() => {
+ if (currentModelMismatch && !hasModelSwitchedFlag && partialMessage) {
+ updateMessage({
+ ...partialMessage,
+ metadata: {
+ ...partialMessage.metadata,
+ modelSwitched: true,
+ },
+ })
+ }
+ }, [currentModelMismatch, hasModelSwitchedFlag, partialMessage, updateMessage])
const showGenerateAIResponseBtn =
((messages[messages.length - 1]?.role === 'user' ||
diff --git a/web-app/src/hooks/__tests__/useChat.test.ts b/web-app/src/hooks/__tests__/useChat.test.ts
index 4141ff5e5..59eb97f89 100644
--- a/web-app/src/hooks/__tests__/useChat.test.ts
+++ b/web-app/src/hooks/__tests__/useChat.test.ts
@@ -1,4 +1,4 @@
-import { renderHook, act, waitFor } from '@testing-library/react'
+import { renderHook, act } from '@testing-library/react'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { MessageStatus, ContentType } from '@janhq/core'
@@ -387,7 +387,8 @@ describe('useChat', () => {
await result.current('', true, undefined, undefined, undefined, 'msg-123')
})
- // Should be called twice: once with partial message (line 517-521), once after completion (line 689)
+ // When continuing, should call addAssistantMessage with the partial message content,
+ // and then again after completion
const assistantCalls = mockCompletionMessagesBuilder.addAssistantMessage.mock.calls
expect(assistantCalls.length).toBeGreaterThanOrEqual(1)
// First call should be with the partial response content
@@ -420,8 +421,8 @@ describe('useChat', () => {
await result.current('', true, undefined, undefined, undefined, 'msg-123')
})
- // The CompletionMessagesBuilder is called with filtered messages (line 507-512)
- // The stopped message should be filtered out from the context
+ // When continuing, the CompletionMessagesBuilder should be called with messages
+ // that exclude the stopped message from the context
expect(messagesLib.CompletionMessagesBuilder).toHaveBeenCalled()
const builderCall = (messagesLib.CompletionMessagesBuilder as any).mock.calls[0]
expect(builderCall[0]).toEqual([userMsg]) // stopped message filtered out
@@ -445,7 +446,7 @@ describe('useChat', () => {
await result.current('', true, undefined, undefined, undefined, 'msg-123')
})
- // finalizeMessage is called at line 700-708, which should update the message
+ // When continuing, finalizeMessage should update the existing message
expect(mockUpdateMessage).toHaveBeenCalledWith(
expect.objectContaining({
id: 'msg-123',
@@ -480,9 +481,8 @@ describe('useChat', () => {
await result.current('', true, undefined, undefined, undefined, 'msg-123')
})
- // The accumulated text should contain the previous content plus new content
- // accumulatedTextRef starts with 'Partial response' (line 490)
- // Then gets ' continued' appended (line 585)
+ // When continuing, the accumulated text should start with the previous partial content
+ // and append new content from the completion
expect(mockUpdateMessage).toHaveBeenCalledWith(
expect.objectContaining({
id: 'msg-123',
@@ -538,7 +538,7 @@ describe('useChat', () => {
await result.current('', true, undefined, undefined, undefined, 'msg-123')
})
- // finalContent is created at line 678-683 with status Ready when continuing
+ // After continuation completes, the message status should be set to Ready
expect(mockUpdateMessage).toHaveBeenCalledWith(
expect.objectContaining({
id: 'msg-123',
diff --git a/web-app/src/hooks/useChat.ts b/web-app/src/hooks/useChat.ts
index fdf3eea2f..9784a2a5f 100644
--- a/web-app/src/hooks/useChat.ts
+++ b/web-app/src/hooks/useChat.ts
@@ -99,7 +99,7 @@ const processStreamingCompletion = async (
completion: AsyncIterable<any>,
abortController: AbortController,
activeThread: Thread,
- accumulatedText: { value: string },
+ accumulatedTextRef: { value: string },
toolCalls: ChatCompletionMessageToolCall[],
currentCall: ChatCompletionMessageToolCall | null,
updateStreamingContent: (content: ThreadMessage | undefined) => void,
@@ -121,7 +121,7 @@ const processStreamingCompletion = async (
const flushStreamingContent = () => {
const currentContent = createThreadContent(
activeThread.id,
- accumulatedText.value,
+ accumulatedTextRef.value,
toolCalls,
continueFromMessageId
)
@@ -206,14 +206,14 @@ const processStreamingCompletion = async (
}
const deltaReasoning = reasoningProcessor.processReasoningChunk(part)
if (deltaReasoning) {
- accumulatedText.value += deltaReasoning
+ accumulatedTextRef.value += deltaReasoning
pendingDeltaCount += 1
// Schedule flush for reasoning updates
scheduleFlush()
}
const deltaContent = part.choices[0]?.delta?.content || ''
if (deltaContent) {
- accumulatedText.value += deltaContent
+ accumulatedTextRef.value += deltaContent
pendingDeltaCount += 1
// Batch UI update on next animation frame
scheduleFlush()
@@ -226,7 +226,7 @@ const processStreamingCompletion = async (
rafScheduled = false
// Finalize reasoning (close any open think tags)
- accumulatedText.value += reasoningProcessor.finalize()
+ accumulatedTextRef.value += reasoningProcessor.finalize()
}
}
@@ -713,7 +713,7 @@ export const useChat = () => {
if (isCompletionResponse(completion)) {
const message = completion.choices[0]?.message
const newContent = (message?.content as string) || ''
- if (continueFromMessageId && accumulatedTextRef.value) {
+ if (continueFromMessageId && accumulatedTextRef.value.length > 0) {
accumulatedTextRef.value += newContent
} else {
accumulatedTextRef.value = newContent
diff --git a/yarn.lock b/yarn.lock
index 50010416c..7d31eb571 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3540,7 +3540,7 @@ __metadata:
"@tauri-apps/plugin-deep-link": "npm:2.4.3"
"@tauri-apps/plugin-dialog": "npm:2.2.2"
"@tauri-apps/plugin-http": "npm:2.5.0"
- "@tauri-apps/plugin-opener": "npm:2.3.0"
+ "@tauri-apps/plugin-opener": "npm:2.5.2"
"@tauri-apps/plugin-os": "npm:2.2.1"
"@tauri-apps/plugin-updater": "npm:2.8.1"
"@testing-library/dom": "npm:10.4.1"
@@ -3604,7 +3604,7 @@ __metadata:
sonner: "npm:2.0.5"
tailwind-merge: "npm:3.3.1"
tailwindcss: "npm:4.1.4"
- token.js: "npm:[email protected]"
+ token.js: "npm:[email protected]"
tw-animate-css: "npm:1.2.8"
typescript: "npm:5.9.2"
typescript-eslint: "npm:8.31.0"
@@ -7428,12 +7428,12 @@ __metadata:
languageName: node
linkType: hard
-"@tauri-apps/plugin-opener@npm:2.3.0":
- version: 2.3.0
- resolution: "@tauri-apps/plugin-opener@npm:2.3.0"
+"@tauri-apps/plugin-opener@npm:2.5.2":
+ version: 2.5.2
+ resolution: "@tauri-apps/plugin-opener@npm:2.5.2"
dependencies:
- "@tauri-apps/api": "npm:^2.0.0"
- checksum: 10c0/6b4e9cd572eb17e528e41814356bd2ea0c2ec5a5858e8087ba19f9e2bb769c513d4f262b222e4347555ec3ddc5289f11bc4e62e6860f2525840570789c45bf27
+ "@tauri-apps/api": "npm:^2.8.0"
+ checksum: 10c0/b10c39063c59ca71e5a5c43bb93da34387a7e707d1baf65a53110141f1a973ce2b73f19be9f63d9312c030760ba2b876ad3069b9a123abb4883e025059a15c3f
languageName: node
linkType: hard
@@ -19482,9 +19482,9 @@ __metadata:
languageName: node
linkType: hard
-"token.js@npm:[email protected]":
- version: 0.7.29
- resolution: "token.js-fork@npm:0.7.29"
+"token.js@npm:[email protected]":
+ version: 0.7.30
+ resolution: "token.js-fork@npm:0.7.30"
dependencies:
"@anthropic-ai/sdk": "npm:0.24.3"
"@aws-sdk/client-bedrock-runtime": "npm:3.609.0"
@@ -19495,7 +19495,7 @@ __metadata:
mime-types: "npm:^2.1.35"
nanoid: "npm:^5.0.7"
openai: "npm:4.91.1"
- checksum: 10c0/b045de56e06a1066b1fdfcca24bc57e7b10aa6cd1995b9ded27af699afcf0e72e216c3672cc3a85b10ce5b6ea81e7d1d453859f073861176b0c816e8f91e6627
+ checksum: 10c0/7d42d40b49ce2de1ac66f025a7a6b2068d3a38b6d57483d97c559fc9ca75adcace1c93ba05e17ab34a227f5187cb3634b16f55287a93e71ccdb70e7452c43c52
languageName: node
linkType: hard