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.

feat: hide file attachments properly (#6895)

Dinh Long Nguyenbb84c159f393
diff --git a/web-app/src/containers/ChatInput.tsx b/web-app/src/containers/ChatInput.tsx
index 0bad8c9b4..76f1cfd57 100644
--- a/web-app/src/containers/ChatInput.tsx
+++ b/web-app/src/containers/ChatInput.tsx
@@ -113,7 +113,7 @@ const ChatInput = ({
const attachmentsEnabled = useAttachments((s) => s.enabled)
// Determine whether to show the Attach documents button (simple gating)
const showAttachmentButton =
- attachmentsEnabled && PlatformFeatures[PlatformFeature.ATTACHMENTS]
+ attachmentsEnabled && PlatformFeatures[PlatformFeature.FILE_ATTACHMENTS]
// Derived: any document currently processing (ingestion in progress)
const ingestingDocs = attachments.some(
(a) => a.type === 'document' && a.processing
@@ -329,6 +329,10 @@ const ChatInput = ({
toast.info('Attachments are disabled in Settings')
return
}
+ if (!PlatformFeatures[PlatformFeature.FILE_ATTACHMENTS]) {
+ toast.info('File attachments are unavailable on this platform')
+ return
+ }
const selection = await serviceHub.dialog().open({
multiple: true,
filters: [
diff --git a/web-app/src/containers/SettingsMenu.tsx b/web-app/src/containers/SettingsMenu.tsx
index a0c434b67..e04836650 100644
--- a/web-app/src/containers/SettingsMenu.tsx
+++ b/web-app/src/containers/SettingsMenu.tsx
@@ -77,7 +77,7 @@ const SettingsMenu = () => {
title: 'common:attachments',
route: route.settings.attachments,
hasSubMenu: false,
- isEnabled: PlatformFeatures[PlatformFeature.ATTACHMENTS],
+ isEnabled: PlatformFeatures[PlatformFeature.FILE_ATTACHMENTS],
},
{
title: 'common:interface',
diff --git a/web-app/src/hooks/useAttachments.ts b/web-app/src/hooks/useAttachments.ts
index 4407fa26b..ae2e1918e 100644
--- a/web-app/src/hooks/useAttachments.ts
+++ b/web-app/src/hooks/useAttachments.ts
@@ -1,5 +1,7 @@
import { create } from 'zustand'
import { ExtensionManager } from '@/lib/extension'
+import { PlatformFeatures } from '@/lib/platform/const'
+import { PlatformFeature } from '@/lib/platform/types'
import { ExtensionTypeEnum, type RAGExtension, type SettingComponentProps } from '@janhq/core'
export type AttachmentsSettings = {
@@ -33,8 +35,11 @@ const getRagExtension = (): RAGExtension | undefined => {
}
}
+const fileAttachmentsFeatureEnabled =
+ PlatformFeatures[PlatformFeature.FILE_ATTACHMENTS]
+
export const useAttachments = create<AttachmentsStore>()((set) => ({
- enabled: true,
+ enabled: fileAttachmentsFeatureEnabled,
maxFileSizeMB: 20,
retrievalLimit: 3,
retrievalThreshold: 0.3,
@@ -53,6 +58,20 @@ export const useAttachments = create<AttachmentsStore>()((set) => ({
}
},
setEnabled: async (v) => {
+ if (!fileAttachmentsFeatureEnabled) {
+ set((s) => ({
+ enabled: false,
+ settingsDefs: s.settingsDefs.map((d) =>
+ d.key === 'enabled'
+ ? ({
+ ...d,
+ controllerProps: { ...d.controllerProps, value: false },
+ } as SettingComponentProps)
+ : d
+ ),
+ }))
+ return
+ }
const ext = getRagExtension()
if (ext?.updateSettings) {
await ext.updateSettings([
@@ -69,6 +88,7 @@ export const useAttachments = create<AttachmentsStore>()((set) => ({
}))
},
setMaxFileSizeMB: async (val) => {
+ if (!fileAttachmentsFeatureEnabled) return
const ext = getRagExtension()
if (ext?.updateSettings) {
await ext.updateSettings([
@@ -85,6 +105,7 @@ export const useAttachments = create<AttachmentsStore>()((set) => ({
}))
},
setRetrievalLimit: async (val) => {
+ if (!fileAttachmentsFeatureEnabled) return
const ext = getRagExtension()
if (ext?.updateSettings) {
await ext.updateSettings([
@@ -101,6 +122,7 @@ export const useAttachments = create<AttachmentsStore>()((set) => ({
}))
},
setRetrievalThreshold: async (val) => {
+ if (!fileAttachmentsFeatureEnabled) return
const ext = getRagExtension()
if (ext?.updateSettings) {
await ext.updateSettings([
@@ -117,6 +139,7 @@ export const useAttachments = create<AttachmentsStore>()((set) => ({
}))
},
setChunkSizeTokens: async (val) => {
+ if (!fileAttachmentsFeatureEnabled) return
const ext = getRagExtension()
if (ext?.updateSettings) {
await ext.updateSettings([
@@ -133,6 +156,7 @@ export const useAttachments = create<AttachmentsStore>()((set) => ({
}))
},
setOverlapTokens: async (val) => {
+ if (!fileAttachmentsFeatureEnabled) return
const ext = getRagExtension()
if (ext?.updateSettings) {
await ext.updateSettings([
@@ -149,6 +173,7 @@ export const useAttachments = create<AttachmentsStore>()((set) => ({
}))
},
setSearchMode: async (v) => {
+ if (!fileAttachmentsFeatureEnabled) return
const ext = getRagExtension()
if (ext?.updateSettings) {
await ext.updateSettings([
@@ -178,7 +203,9 @@ export const useAttachments = create<AttachmentsStore>()((set) => ({
// seed defs and values
useAttachments.setState((prev) => ({
settingsDefs: settings,
- enabled: (map.get('enabled') as boolean | undefined) ?? prev.enabled,
+ enabled:
+ fileAttachmentsFeatureEnabled &&
+ ((map.get('enabled') as boolean | undefined) ?? prev.enabled),
maxFileSizeMB: (map.get('max_file_size_mb') as number | undefined) ?? prev.maxFileSizeMB,
retrievalLimit: (map.get('retrieval_limit') as number | undefined) ?? prev.retrievalLimit,
retrievalThreshold:
diff --git a/web-app/src/hooks/useChat.ts b/web-app/src/hooks/useChat.ts
index 6743816c2..35df9f5ac 100644
--- a/web-app/src/hooks/useChat.ts
+++ b/web-app/src/hooks/useChat.ts
@@ -468,8 +468,14 @@ export const useChat = () => {
if (!activeThread || !activeProvider) return
// Separate images and documents
- const images = attachments?.filter((a) => a.type === 'image') || []
- const documents = attachments?.filter((a) => a.type === 'document') || []
+ const fileAttachmentsFeatureEnabled =
+ PlatformFeatures[PlatformFeature.FILE_ATTACHMENTS]
+ const allAttachments = attachments ?? []
+
+ const images = allAttachments.filter((a) => a.type === 'image')
+ const documents = fileAttachmentsFeatureEnabled
+ ? allAttachments.filter((a) => a.type === 'document')
+ : []
// Process attachments BEFORE sending
const processedAttachments: Attachment[] = []
@@ -649,7 +655,7 @@ export const useChat = () => {
// Conditionally inject RAG if tools are supported and documents are attached
const ragFeatureAvailable =
useAttachments.getState().enabled &&
- PlatformFeatures[PlatformFeature.ATTACHMENTS]
+ PlatformFeatures[PlatformFeature.FILE_ATTACHMENTS]
// Check if documents were attached in the current thread
const hasDocuments = useThreads.getState().getThreadById(activeThread.id)?.metadata?.hasDocuments
if (hasDocuments && ragFeatureAvailable) {
diff --git a/web-app/src/lib/__tests__/completion.test.ts b/web-app/src/lib/__tests__/completion.test.ts
index f8fed4fec..833ebadb8 100644
--- a/web-app/src/lib/__tests__/completion.test.ts
+++ b/web-app/src/lib/__tests__/completion.test.ts
@@ -111,13 +111,13 @@ vi.mock('@/hooks/useAppState', () => ({
vi.mock('@/lib/platform/const', () => ({
PlatformFeatures: {
- ATTACHMENTS: true,
+ FILE_ATTACHMENTS: true,
},
}))
vi.mock('@/lib/platform/types', () => ({
PlatformFeature: {
- ATTACHMENTS: 'ATTACHMENTS',
+ FILE_ATTACHMENTS: 'FILE_ATTACHMENTS',
},
}))
diff --git a/web-app/src/lib/completion.ts b/web-app/src/lib/completion.ts
index f0dc5f5ef..d30c4435d 100644
--- a/web-app/src/lib/completion.ts
+++ b/web-app/src/lib/completion.ts
@@ -529,7 +529,8 @@ export const postMessageProcessing = async (
console.error('Failed to load RAG tool names:', e)
}
const ragFeatureAvailable =
- useAttachments.getState().enabled && PlatformFeatures[PlatformFeature.ATTACHMENTS]
+ useAttachments.getState().enabled &&
+ PlatformFeatures[PlatformFeature.FILE_ATTACHMENTS]
for (const toolCall of calls) {
if (abortController.signal.aborted) break
const toolId = ulid()
diff --git a/web-app/src/lib/platform/const.ts b/web-app/src/lib/platform/const.ts
index 881448f3d..1d057ad26 100644
--- a/web-app/src/lib/platform/const.ts
+++ b/web-app/src/lib/platform/const.ts
@@ -85,7 +85,6 @@ export const PlatformFeatures: Record<PlatformFeature, boolean> = {
// Temporary chat mode - enabled for web only
[PlatformFeature.TEMPORARY_CHAT]: !isPlatformTauri(),
- // Attachments/RAG UI and tooling - desktop only for now
- [PlatformFeature.ATTACHMENTS]:
- isPlatformTauri() && !isPlatformIOS() && !isPlatformAndroid(),
+ // File attachments/RAG UI and tooling - disabled until feature release
+ [PlatformFeature.FILE_ATTACHMENTS]: false,
}
diff --git a/web-app/src/lib/platform/types.ts b/web-app/src/lib/platform/types.ts
index 01cb305d1..fc14b80ff 100644
--- a/web-app/src/lib/platform/types.ts
+++ b/web-app/src/lib/platform/types.ts
@@ -74,6 +74,6 @@ export enum PlatformFeature {
// Temporary chat mode - web-only feature for ephemeral conversations like ChatGPT
TEMPORARY_CHAT = 'temporaryChat',
- // Attachments/RAG UI and tooling (desktop-only for now)
- ATTACHMENTS = 'attachments',
+ // File attachments/RAG UI and tooling (desktop-only for now)
+ FILE_ATTACHMENTS = 'fileAttachments',
}
diff --git a/web-app/src/routes/settings/attachments.tsx b/web-app/src/routes/settings/attachments.tsx
index 342db2a70..27c0b56f4 100644
--- a/web-app/src/routes/settings/attachments.tsx
+++ b/web-app/src/routes/settings/attachments.tsx
@@ -147,7 +147,7 @@ function AttachmentsSettings() {
}, [sel])
return (
- <PlatformGuard feature={PlatformFeature.ATTACHMENTS}>
+ <PlatformGuard feature={PlatformFeature.FILE_ATTACHMENTS}>
<div className="flex flex-col h-full pb-[calc(env(safe-area-inset-bottom)+env(safe-area-inset-top))]">
<HeaderPage>
<h1 className="font-medium">{t('common:settings')}</h1>