fix: Enable wiki_config updates in knowledge base configuration

Implemented three critical fixes to enable wiki_config persistence during
KB creation and updates:

1. Add WikiConfig field to KnowledgeBaseConfig struct
   - File: internal/types/knowledgebase.go
   - Enables JSON unmarshaling of wiki_config from update requests
   - Previously the field was silently dropped during deserialization

2. Update UpdateKnowledgeBase service to persist wiki_config
   - File: internal/application/service/knowledgebase.go
   - Added logic to apply wiki_config changes when config parameter is provided
   - Mirrors existing logic for FAQConfig persistence

3. Update frontend TypeScript types for IDE completion
   - File: frontend/src/api/knowledge-base/index.ts
   - Added WikiConfig type to createKnowledgeBase function signature
   - Added structured WikiConfig type to updateKnowledgeBase config parameter
   - Enables TypeScript IDE autocomplete and type checking

Flow:
- Frontend: updateKnowledgeBase({name, description, config: {wiki_config}})
- Handler: Parses into UpdateKnowledgeBaseRequest via KnowledgeBaseConfig
- Service: Applies wiki_config to KB entity via UpdateKnowledgeBase
- Database: Persists wiki_config JSONB field to postgres

Root cause analysis:
Previously, the KnowledgeBaseConfig struct was missing the WikiConfig field,
causing JSON unmarshaling to silently drop any wiki_config data sent in
PUT requests. KB creation worked because it used the full KnowledgeBase struct.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
wizardchen
2026-04-07 15:19:53 +08:00
parent 16a0bff7bd
commit e15adca0a6
3 changed files with 43 additions and 20 deletions
+24 -2
View File
@@ -11,7 +11,7 @@ export function listKnowledgeBases(params?: { agent_id?: string }) {
export function createKnowledgeBase(data: {
name: string;
description?: string;
type?: 'document' | 'faq' | 'wiki';
type?: 'document' | 'faq';
chunking_config?: any;
embedding_model_id?: string;
summary_model_id?: string;
@@ -28,6 +28,13 @@ export function createKnowledgeBase(data: {
};
extract_config?: any;
faq_config?: { index_mode: string; question_index_mode?: string };
wiki_config?: {
enabled: boolean;
auto_ingest?: boolean;
synthesis_model_id?: string;
wiki_language?: string;
max_pages_per_ingest?: number;
};
}) {
return post(`/api/v1/knowledge-bases`, data);
}
@@ -39,7 +46,22 @@ export function getKnowledgeBaseById(id: string, options?: { agent_id?: string }
return get(qs ? `/api/v1/knowledge-bases/${id}?${qs}` : `/api/v1/knowledge-bases/${id}`);
}
export function updateKnowledgeBase(id: string, data: { name: string; description?: string; config: any }) {
export function updateKnowledgeBase(id: string, data: {
name: string;
description?: string;
config?: {
chunking_config?: any;
image_processing_config?: any;
faq_config?: any;
wiki_config?: {
enabled: boolean;
auto_ingest?: boolean;
synthesis_model_id?: string;
wiki_language?: string;
max_pages_per_ingest?: number;
};
}
}) {
return put(`/api/v1/knowledge-bases/${id}` , data);
}