fix(安全): 修复HTML导出中的XSS漏洞并清理调试日志
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
refactor(日志): 替换console.log为tracing日志系统 style(代码): 移除未使用的代码和依赖项 feat(测试): 添加端到端测试文档和CI工作流 docs(变更日志): 更新CHANGELOG.md记录0.1.0版本变更 perf(构建): 更新依赖版本并优化CI流程
This commit is contained in:
@@ -29,6 +29,9 @@ import {
|
||||
extractAndStoreMemories,
|
||||
type ChatMessageForExtraction,
|
||||
} from './viking-client';
|
||||
import { createLogger } from './logger';
|
||||
|
||||
const log = createLogger('MemoryExtractor');
|
||||
|
||||
// === Types ===
|
||||
|
||||
@@ -108,7 +111,7 @@ export class MemoryExtractor {
|
||||
try {
|
||||
this.llmAdapter = getLLMAdapter();
|
||||
} catch (error) {
|
||||
console.warn('[MemoryExtractor] Failed to initialize LLM adapter:', error);
|
||||
log.warn('Failed to initialize LLM adapter:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,15 +128,15 @@ export class MemoryExtractor {
|
||||
): Promise<ExtractionResult> {
|
||||
// Cooldown check
|
||||
if (Date.now() - this.lastExtractionTime < this.config.extractionCooldownMs) {
|
||||
console.log('[MemoryExtractor] Skipping extraction: cooldown active');
|
||||
log.debug('Skipping extraction: cooldown active');
|
||||
return { items: [], saved: 0, skipped: 0, userProfileUpdated: false };
|
||||
}
|
||||
|
||||
// Minimum message threshold
|
||||
const chatMessages = messages.filter(m => m.role === 'user' || m.role === 'assistant');
|
||||
console.log(`[MemoryExtractor] Checking extraction: ${chatMessages.length} messages (min: ${this.config.minMessagesForExtraction})`);
|
||||
log.debug(`Checking extraction: ${chatMessages.length} messages (min: ${this.config.minMessagesForExtraction})`);
|
||||
if (chatMessages.length < this.config.minMessagesForExtraction) {
|
||||
console.log('[MemoryExtractor] Skipping extraction: not enough messages');
|
||||
log.debug('Skipping extraction: not enough messages');
|
||||
return { items: [], saved: 0, skipped: 0, userProfileUpdated: false };
|
||||
}
|
||||
|
||||
@@ -143,26 +146,26 @@ export class MemoryExtractor {
|
||||
let extracted: ExtractedItem[];
|
||||
if ((this.config.useLLM || options?.forceLLM) && this.llmAdapter?.isAvailable()) {
|
||||
try {
|
||||
console.log('[MemoryExtractor] Using LLM-powered semantic extraction');
|
||||
log.debug('Using LLM-powered semantic extraction');
|
||||
extracted = await this.llmBasedExtraction(chatMessages);
|
||||
} catch (error) {
|
||||
console.error('[MemoryExtractor] LLM extraction failed:', error);
|
||||
log.error('LLM extraction failed:', error);
|
||||
if (!this.config.llmFallbackToRules) {
|
||||
throw error;
|
||||
}
|
||||
console.log('[MemoryExtractor] Falling back to rule-based extraction');
|
||||
log.debug('Falling back to rule-based extraction');
|
||||
extracted = this.ruleBasedExtraction(chatMessages);
|
||||
}
|
||||
} else {
|
||||
// Rule-based extraction
|
||||
console.log('[MemoryExtractor] Using rule-based extraction');
|
||||
log.debug('Using rule-based extraction');
|
||||
extracted = this.ruleBasedExtraction(chatMessages);
|
||||
console.log(`[MemoryExtractor] Rule-based extracted ${extracted.length} items before filtering`);
|
||||
log.debug(`Rule-based extracted ${extracted.length} items before filtering`);
|
||||
}
|
||||
|
||||
// Filter by importance threshold
|
||||
extracted = extracted.filter(item => item.importance >= this.config.minImportanceThreshold);
|
||||
console.log(`[MemoryExtractor] After importance filtering (>= ${this.config.minImportanceThreshold}): ${extracted.length} items`);
|
||||
log.debug(`After importance filtering (>= ${this.config.minImportanceThreshold}): ${extracted.length} items`);
|
||||
|
||||
// Save to memory (dual storage: intelligenceClient + viking-client/SqliteStorage)
|
||||
let saved = 0;
|
||||
@@ -180,10 +183,10 @@ export class MemoryExtractor {
|
||||
chatMessagesForViking,
|
||||
agentId
|
||||
);
|
||||
console.log(`[MemoryExtractor] Viking storage result: ${vikingResult.summary}`);
|
||||
log.debug(`Viking storage result: ${vikingResult.summary}`);
|
||||
saved = vikingResult.memories.length;
|
||||
} catch (err) {
|
||||
console.warn('[MemoryExtractor] Viking storage failed, falling back to intelligenceClient:', err);
|
||||
log.warn('Viking storage failed, falling back to intelligenceClient:', err);
|
||||
|
||||
// Fallback: Store via intelligenceClient (in-memory/graph)
|
||||
for (const item of extracted) {
|
||||
@@ -214,12 +217,12 @@ export class MemoryExtractor {
|
||||
await intelligenceClient.identity.appendUserProfile(agentId, `### 自动发现的偏好 (${new Date().toLocaleDateString('zh-CN')})\n${prefSummary}`);
|
||||
userProfileUpdated = true;
|
||||
} catch (err) {
|
||||
console.warn('[MemoryExtractor] Failed to update USER.md:', err);
|
||||
log.warn('Failed to update USER.md:', err);
|
||||
}
|
||||
}
|
||||
|
||||
if (saved > 0) {
|
||||
console.log(`[MemoryExtractor] Extracted ${saved} memories from conversation (${skipped} skipped)`);
|
||||
log.debug(`Extracted ${saved} memories from conversation (${skipped} skipped)`);
|
||||
}
|
||||
|
||||
return { items: extracted, saved, skipped, userProfileUpdated };
|
||||
@@ -404,7 +407,7 @@ export class MemoryExtractor {
|
||||
tags: Array.isArray(item.tags) ? item.tags.map(String) : [],
|
||||
}));
|
||||
} catch {
|
||||
console.warn('[MemoryExtractor] Failed to parse LLM extraction response');
|
||||
log.warn('Failed to parse LLM extraction response');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user