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.

refactor(web-app): share one blank-folder check between chat folder helpers

thinhlpg6a46e4c6c15f
diff --git a/web-app/src/hooks/useChatFolder.ts b/web-app/src/hooks/useChatFolder.ts
index 80bc3807d..185f5074b 100644
--- a/web-app/src/hooks/useChatFolder.ts
+++ b/web-app/src/hooks/useChatFolder.ts
@@ -5,6 +5,7 @@ import { useModelProvider } from '@/hooks/useModelProvider'
import { useServiceHub } from '@/hooks/useServiceHub'
import { useThreads } from '@/hooks/useThreads'
import { TEMPORARY_CHAT_ID } from '@/constants/chat'
+import { folderOf } from '@/lib/chatFolder'
import { supportsCowork } from '@/lib/coworkSync'
import { isCoworkEnabled } from '@/lib/version'
@@ -23,7 +24,7 @@ export function useChatFolder(threadId: string) {
// ship the agent tools. A temporary chat keeps no folder.
const available =
supportsCowork() && isCoworkEnabled() && threadId !== TEMPORARY_CHAT_ID
- const folder = typeof stored === 'string' && stored.trim() ? stored : null
+ const folder = folderOf(stored)
const save = useCallback(
async (next: string | null) => {
diff --git a/web-app/src/hooks/useToolGrants.ts b/web-app/src/hooks/useToolGrants.ts
index c70b78fce..973dbc69a 100644
--- a/web-app/src/hooks/useToolGrants.ts
+++ b/web-app/src/hooks/useToolGrants.ts
@@ -15,7 +15,7 @@ type ToolGrantsState = SavedGrants & {
}
/**
- * The configuration-level tool grants ("Allow always" and "allow all MCP"), as
+ * The configuration-level tool grants ("Always allow" and "allow all MCP"), as
* the settings page shows them. A view only: Rust keeps and enforces them, so
* every change goes there and is read back.
*/
diff --git a/web-app/src/lib/chatFolder.ts b/web-app/src/lib/chatFolder.ts
index 960af1c79..3a6ec917e 100644
--- a/web-app/src/lib/chatFolder.ts
+++ b/web-app/src/lib/chatFolder.ts
@@ -20,6 +20,11 @@ export const CHAT_FOLDER_TOOL_NAMES = new Set([
*/
const ASKED_WITH_FOLDER = new Set(['write', 'edit', 'shell'])
+/** A stored folder value, or `null` when it is missing or blank. */
+export function folderOf(value: unknown): string | null {
+ return typeof value === 'string' && value.trim() ? value : null
+}
+
/**
* The folder attached to a chat thread, from its record. The record is the
* authority: Rust reads the same `thread.json` field when the tool runs, so
@@ -27,8 +32,7 @@ const ASKED_WITH_FOLDER = new Set(['write', 'edit', 'shell'])
*/
export function chatFolderOf(threadId: string | undefined): string | null {
if (!threadId) return null
- const folder = useThreads.getState().threads[threadId]?.metadata?.folder
- return typeof folder === 'string' && folder.trim() ? folder : null
+ return folderOf(useThreads.getState().threads[threadId]?.metadata?.folder)
}
/** Whether a built-in chat call must be asked for, given the thread's folder. */