feat: add API config system, FilePipe backend, and ConfigManager

- ConfigManager: route sensitive keys (API keys) to localStorage,
  migrate existing values out of extension_settings on startup
- ApiKeyStore: local/cloud storage modes with RSA+AES hybrid encryption
- ApiProfileManager: named connection profiles (chat/embedding/rerank)
  with per-slot type-validated assignments
- FilePipe: complete IndexedDB backend (read/write/delete/list/stat)
- Amily2Bus: inject FilePipe via forPlugin() capability token
- UI: api-config-panel with profile CRUD and slot assignment
- TableSystemService: initial service layer scaffold
- logger.js: XSS fix
This commit is contained in:
2026-03-10 22:07:15 +08:00
parent ed3f52a568
commit 0be6a86e94
17 changed files with 1970 additions and 110 deletions

View File

@@ -1,75 +1,19 @@
import { getContext, extension_settings } from "/scripts/extensions.js";
import { saveChatConditional } from "/script.js";
import { extensionName } from "../utils/settings.js";
import * as TableManager from './table-system/manager.js';
import * as Executor from './table-system/executor.js';
import { renderTables } from '../ui/table-bindings.js';
import { log } from "./table-system/logger.js";
async function handleTableUpdate(messageId) {
TableManager.clearHighlights();
const settings = extension_settings[extensionName];
const tableSystemEnabled = settings.table_system_enabled !== false;
if (!tableSystemEnabled) {
log('【监察系统】表格系统总开关已关闭,跳过所有表格处理。', 'info');
return;
}
const fillingMode = settings.filling_mode || 'main-api';
if (fillingMode === 'secondary-api' || fillingMode === 'optimized') {
log('【监察系统】检测到"分步填表"或"优化中填表"模式已启用主API填表逻辑已自动禁用。', 'info');
return;
}
log(`【监察系统】接到圣旨,开始处理消息 ID: ${messageId}`, 'warn');
const context = getContext();
const message = context.chat[messageId];
if (!message) {
log(`【监察系统】错误:未找到消息 ID: ${messageId},流程中止。`, 'error');
return;
}
if (message.is_user) {
log(`【监察系统】消息 ID: ${messageId} 是用户消息,无需处理。`, 'info');
return;
}
log(`【监察系统】正在处理的奏折内容: "${message.mes.substring(0, 50)}..."`, 'info');
const initialState = TableManager.loadTables(messageId);
log(`【监察系统-步骤1】为消息 ${messageId} 加载了基准状态。`, 'info', initialState);
const { finalState, hasChanges, changes } = Executor.executeCommands(message.mes, initialState);
log(`【监察系统-步骤2】推演完毕。是否有变化: ${hasChanges}`, 'info', finalState);
if (hasChanges) {
if (changes && changes.length > 0) {
changes.forEach(change => {
TableManager.addHighlight(change.tableIndex, change.rowIndex, change.colIndex);
});
}
TableManager.saveStateToMessage(finalState, message);
TableManager.setMemoryState(finalState);
await saveChatConditional();
log(`【监察系统-步骤3】检测到变化已将新状态写入消息 ${messageId} 并保存。`, 'success');
} else {
log(`【监察系统-步骤3】未检测到有效指令或变化无需写入。`, 'info');
}
if (hasChanges) {
renderTables();
}
}
import { processMessageUpdate, fillWithSecondaryApi } from './table-system/TableSystemService.js';
import { processOptimization } from "./summarizer.js";
import { executeAutoHide } from './autoHideManager.js';
import { checkAndTriggerAutoSummary } from './historiographer.js';
import { fillWithSecondaryApi } from './table-system/secondary-filler.js';
import { amilyHelper } from './tavern-helper/main.js';
async function handleTableUpdate(messageId) {
await processMessageUpdate(messageId);
}
export async function onMessageReceived(data) {
window.lastPreOptimizationResult = null;
document.dispatchEvent(new CustomEvent('preOptimizationTextUpdated'));
document.dispatchEvent(new CustomEvent('preOptimizationTextUpdated'));
const context = getContext();
if ((data && data.is_user) || context.isWaitingForUserInput) { return; }
@@ -81,9 +25,10 @@ export async function onMessageReceived(data) {
const latestMessage = chat[chat.length - 1];
if (latestMessage.is_user) { return; }
const tableSystemEnabled = settings.table_system_enabled !== false;
const tableSystemEnabled = settings.table_system_enabled !== false;
await executeAutoHide();
const isOptimizationEnabled = settings.optimizationEnabled && settings.apiUrl;
if (isOptimizationEnabled) {
if (chat.length >= 2 && chat[chat.length - 2].is_user) {
@@ -109,13 +54,14 @@ export async function onMessageReceived(data) {
console.log("[Amily2号-正文优化] 检测到消息并非AI对用户的直接回复已跳过优化。");
}
}
if (tableSystemEnabled) {
const fillingMode = settings.filling_mode || 'main-api';
if (fillingMode === 'secondary-api') {
fillWithSecondaryApi(latestMessage);
}
} else {
log('[分步填表] 表格系统总开关已关闭,跳过分步填表处理。', 'info');
console.log('[分步填表] 表格系统总开关已关闭,跳过分步填表处理。');
}
(async () => {