refactor(knowledge-base): 统一默认目录并简化目录类型映射
- 将默认目录从"收集"和"笔记"调整为"笔记"和"Skill" - 移除"收集"、"AI收藏"和"知识提炼"目录类型,统一使用"笔记" - 更新知识提炼存储服务使用"笔记"目录 - 修改MCP工具默认目录为"笔记" - 优化默认目录初始化逻辑,确保目录状态正确同步
This commit is contained in:
1 parent
093dd25df8
commit
bf7a367d35
5 files changed
+38
-19
No files matched your search
@@ -209,7 +209,7 @@ export const kbCreateNoteTool: MCPTool = {
|
||||
},
|
||||
directoryName: {
|
||||
type: 'string',
|
||||
description: '目录名称(不存在则自动创建),默认为"默认"',
|
||||
description: '目录名称(不存在则自动创建),默认为"笔记"',
|
||||
},
|
||||
tags: {
|
||||
type: 'array',
|
||||
@@ -252,7 +252,7 @@ export const kbCreateNoteTool: MCPTool = {
|
||||
execute: async (params: Record<string, unknown>): Promise<MCPResult> => {
|
||||
const title = params.title as string;
|
||||
const content = params.content as string;
|
||||
const directoryName = (params.directoryName as string) || '默认';
|
||||
const directoryName = (params.directoryName as string) || '笔记';
|
||||
const tags = params.tags as string[] | undefined;
|
||||
const sourceUrl = params.sourceUrl as string | undefined;
|
||||
|
||||
|
||||
@@ -72,9 +72,9 @@ function mergeKnowledgeToMarkdown(
|
||||
/** 获取或创建"知识提炼"目录 */
|
||||
export async function getKnowledgeExtractionDirectory(): Promise<{ id: string; name: string }> {
|
||||
const dirs = await getAllDirectories();
|
||||
const existing = dirs.find((d) => d.name === '知识提炼');
|
||||
const existing = dirs.find((d) => d.name === '笔记');
|
||||
if (existing) return { id: existing.id, name: existing.name };
|
||||
const newDir = await createDirectory('知识提炼');
|
||||
const newDir = await createDirectory('笔记');
|
||||
return { id: newDir.id, name: newDir.name };
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,11 @@ import type { KBNoteMeta, KBNoteMetadata } from '../types/knowledge-base.types';
|
||||
// ============================================
|
||||
|
||||
/** 目录类型 */
|
||||
export type DirectoryType = 'collection' | 'note' | 'ai_chat' | 'knowledge_extraction';
|
||||
export type DirectoryType = 'note';
|
||||
|
||||
/** 目录名称映射 */
|
||||
export const DIRECTORY_NAMES: Record<DirectoryType, string> = {
|
||||
collection: '收集',
|
||||
note: '笔记',
|
||||
ai_chat: 'AI收藏',
|
||||
knowledge_extraction: '知识提炼',
|
||||
};
|
||||
|
||||
/** 保存历史最大记录数 */
|
||||
@@ -246,8 +243,7 @@ class KnowledgeSaveManager {
|
||||
// ============================================
|
||||
|
||||
private _inferDirectoryType(item: SaveContentItem): DirectoryType {
|
||||
if (item.contentType === 'ai_response') return 'ai_chat';
|
||||
return 'collection';
|
||||
return 'note';
|
||||
}
|
||||
|
||||
private async _ensureDirectory(type: DirectoryType): Promise<string> {
|
||||
@@ -445,7 +441,7 @@ class KnowledgeSaveManager {
|
||||
noteName: '',
|
||||
isNewNote: false,
|
||||
isDuplicate: false,
|
||||
directoryType: 'collection',
|
||||
directoryType: 'note',
|
||||
message,
|
||||
fingerprint: '',
|
||||
savedAt: Date.now(),
|
||||
|
||||
@@ -88,21 +88,44 @@ async function ensureDefaultDirectories(): Promise<void> {
|
||||
if (defaultDirsInitialized) return;
|
||||
|
||||
const dirs = await getAllDirectories();
|
||||
const hasDefaults = dirs.some((d) => d.isDefault);
|
||||
if (!hasDefaults) {
|
||||
const now = Date.now();
|
||||
for (const def of KB_DEFAULT_DIRECTORIES) {
|
||||
const dir: KBDirectory = {
|
||||
const defaultDirNames = new Set(KB_DEFAULT_DIRECTORIES.map((d) => d.name));
|
||||
const existingMap = new Map(dirs.map((d) => [d.name, d]));
|
||||
const now = Date.now();
|
||||
|
||||
// 1. 确保默认目录存在且状态正确
|
||||
for (const def of KB_DEFAULT_DIRECTORIES) {
|
||||
const existing = existingMap.get(def.name);
|
||||
if (existing) {
|
||||
// 如果已存在但不是默认,更新为默认
|
||||
if (!existing.isDefault) {
|
||||
existing.isDefault = true;
|
||||
existing.order = def.order; // 更新排序
|
||||
existing.updatedAt = now;
|
||||
await directoriesStore.setItem(existing.id, existing);
|
||||
}
|
||||
} else {
|
||||
// 创建不存在的默认目录
|
||||
const newDir: KBDirectory = {
|
||||
id: generateId(),
|
||||
name: def.name,
|
||||
isDefault: def.isDefault,
|
||||
isDefault: true,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
order: def.order,
|
||||
};
|
||||
await directoriesStore.setItem(newDir.id, newDir);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 将不再是默认的目录(如"收集")取消默认状态
|
||||
for (const dir of dirs) {
|
||||
if (dir.isDefault && !defaultDirNames.has(dir.name)) {
|
||||
dir.isDefault = false;
|
||||
dir.updatedAt = now;
|
||||
await directoriesStore.setItem(dir.id, dir);
|
||||
}
|
||||
}
|
||||
|
||||
defaultDirsInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -166,8 +166,8 @@ export const KB_DEFAULT_SORT: KBSortOptions = {
|
||||
* 默认目录列表
|
||||
*/
|
||||
export const KB_DEFAULT_DIRECTORIES: Array<{ name: string; isDefault: boolean; order: number }> = [
|
||||
{ name: '收集', isDefault: true, order: 0 },
|
||||
{ name: '笔记', isDefault: true, order: 1 },
|
||||
{ name: '笔记', isDefault: true, order: 0 },
|
||||
{ name: 'Skill', isDefault: true, order: 1 },
|
||||
];
|
||||
|
||||
// ==================== 保存状态类型 ====================
|
||||
|
||||
Reference in new issue
Block a user