fix(workspace-selector-kb): fix selector for assigning workspaces for kbs (#1567)

This commit is contained in:
Vikhyath Mondreti
2025-10-07 15:31:04 -07:00
committed by GitHub
parent 872e034312
commit 2d7ba91c0e
6 changed files with 31 additions and 4 deletions

View File

@@ -234,6 +234,7 @@ describe('Knowledge Base By ID API Route', () => {
{
name: validUpdateData.name,
description: validUpdateData.description,
workspaceId: undefined,
chunkingConfig: undefined,
},
expect.any(String)

View File

@@ -103,6 +103,7 @@ export async function PUT(req: NextRequest, { params }: { params: Promise<{ id:
{
name: validatedData.name,
description: validatedData.description,
workspaceId: validatedData.workspaceId,
chunkingConfig: validatedData.chunkingConfig,
},
requestId

View File

@@ -698,10 +698,6 @@ export function KnowledgeBase({
options={{
knowledgeBaseId: id,
currentWorkspaceId: knowledgeBase?.workspaceId || null,
onWorkspaceChange: () => {
// Refresh the page to reflect the workspace change
window.location.reload()
},
onDeleteKnowledgeBase: () => setShowDeleteDialog(true),
}}
/>

View File

@@ -11,6 +11,7 @@ import {
} from '@/components/ui/dropdown-menu'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
import { createLogger } from '@/lib/logs/console/logger'
import { useKnowledgeStore } from '@/stores/knowledge/store'
const logger = createLogger('WorkspaceSelector')
@@ -33,6 +34,7 @@ export function WorkspaceSelector({
onWorkspaceChange,
disabled = false,
}: WorkspaceSelectorProps) {
const { updateKnowledgeBase } = useKnowledgeStore()
const [workspaces, setWorkspaces] = useState<Workspace[]>([])
const [isLoading, setIsLoading] = useState(false)
const [isUpdating, setIsUpdating] = useState(false)
@@ -95,6 +97,11 @@ export function WorkspaceSelector({
if (result.success) {
logger.info(`Knowledge base workspace updated: ${knowledgeBaseId} -> ${workspaceId}`)
// Update the store immediately to reflect the change without page reload
updateKnowledgeBase(knowledgeBaseId, { workspaceId: workspaceId || undefined })
// Notify parent component of the change
onWorkspaceChange?.(workspaceId)
} else {
throw new Error(result.error || 'Failed to update workspace')

View File

@@ -135,6 +135,7 @@ export async function updateKnowledgeBase(
updates: {
name?: string
description?: string
workspaceId?: string | null
chunkingConfig?: {
maxSize: number
minSize: number
@@ -148,6 +149,7 @@ export async function updateKnowledgeBase(
updatedAt: Date
name?: string
description?: string | null
workspaceId?: string | null
chunkingConfig?: {
maxSize: number
minSize: number
@@ -161,6 +163,7 @@ export async function updateKnowledgeBase(
if (updates.name !== undefined) updateData.name = updates.name
if (updates.description !== undefined) updateData.description = updates.description
if (updates.workspaceId !== undefined) updateData.workspaceId = updates.workspaceId
if (updates.chunkingConfig !== undefined) {
updateData.chunkingConfig = updates.chunkingConfig
updateData.embeddingModel = 'text-embedding-3-small'

View File

@@ -159,6 +159,7 @@ interface KnowledgeStore {
updateChunk: (documentId: string, chunkId: string, updates: Partial<ChunkData>) => void
addPendingDocuments: (knowledgeBaseId: string, documents: DocumentData[]) => void
addKnowledgeBase: (knowledgeBase: KnowledgeBaseData) => void
updateKnowledgeBase: (id: string, updates: Partial<KnowledgeBaseData>) => void
removeKnowledgeBase: (id: string) => void
removeDocument: (knowledgeBaseId: string, documentId: string) => void
clearDocuments: (knowledgeBaseId: string) => void
@@ -796,6 +797,24 @@ export const useKnowledgeStore = create<KnowledgeStore>((set, get) => ({
logger.info(`Knowledge base added: ${knowledgeBase.id}`)
},
updateKnowledgeBase: (id: string, updates: Partial<KnowledgeBaseData>) => {
set((state) => {
const existingKb = state.knowledgeBases[id]
if (!existingKb) return state
const updatedKb = { ...existingKb, ...updates }
return {
knowledgeBases: {
...state.knowledgeBases,
[id]: updatedKb,
},
knowledgeBasesList: state.knowledgeBasesList.map((kb) => (kb.id === id ? updatedKb : kb)),
}
})
logger.info(`Knowledge base updated: ${id}`)
},
removeKnowledgeBase: (id: string) => {
set((state) => {
const newKnowledgeBases = { ...state.knowledgeBases }