mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 06:55:51 +00:00
ci: auto build & obfuscate [2026-04-26 23:26:32] (Jenkins #18)
This commit is contained in:
@@ -9,20 +9,20 @@ import {
|
||||
buildGoogleEmbeddingApiUrl
|
||||
} from './utils/googleAdapter.js';
|
||||
import { getSlotProfile } from './api/api-resolver.js';
|
||||
import { extensionName } from '../utils/settings.js';
|
||||
|
||||
const MODULE_NAME = 'hanlinyuan-rag-core';
|
||||
const GOOGLE_API_BASE_URL = 'https://generativelanguage.googleapis.com';
|
||||
|
||||
function getSettings() {
|
||||
const context = SillyTavern.getContext();
|
||||
if (!context || !context.extensionSettings || !context.extensionSettings[MODULE_NAME]) {
|
||||
console.error('[翰林院-API] 无法获取设置,API调用可能失败。');
|
||||
return {
|
||||
retrieval: {},
|
||||
rerank: {}
|
||||
};
|
||||
}
|
||||
return context.extensionSettings[MODULE_NAME];
|
||||
const root = extension_settings[extensionName];
|
||||
const nested = root && root[MODULE_NAME];
|
||||
if (nested) return nested;
|
||||
// 读侧兼容:若迁移尚未触发(极早期调用),回退至旧顶层位置,避免空配置。
|
||||
const legacy = extension_settings[MODULE_NAME];
|
||||
if (legacy) return legacy;
|
||||
console.error('[翰林院-API] 无法获取设置,API调用可能失败。');
|
||||
return { retrieval: {}, rerank: {} };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,14 +4,17 @@ import {
|
||||
extension_prompt_roles,
|
||||
setExtensionPrompt,
|
||||
eventSource,
|
||||
event_types
|
||||
event_types,
|
||||
saveSettingsDebounced
|
||||
} from '/script.js';
|
||||
import { extension_settings } from '/scripts/extensions.js';
|
||||
|
||||
import * as ContextUtils from './utils/context-utils.js';
|
||||
import { getCollectionIdInfo, getCharacterId, getCharacterStableId } from './utils/context-utils.js';
|
||||
import { defaultSettings as ragDefaultSettings } from './rag-settings.js';
|
||||
import { extractBlocksByTags, applyExclusionRules } from './utils/rag-tag-extractor.js';
|
||||
import { resolveQueryPreprocessingRuleConfig } from '../utils/config/RuleProfileManager.js';
|
||||
import { extensionName } from '../utils/settings.js';
|
||||
import * as IngestionManager from './ingestion-manager.js';
|
||||
import {
|
||||
getEmbeddings,
|
||||
@@ -148,6 +151,7 @@ function initialize() {
|
||||
console.error('[翰林院] 未能获取SillyTavern上下文,初始化失败。');
|
||||
return;
|
||||
}
|
||||
migrateLegacyRagSettings();
|
||||
settings = getSettings();
|
||||
if (!window.hanlinyuanRagProcessor) {
|
||||
window.hanlinyuanRagProcessor = {};
|
||||
@@ -296,17 +300,16 @@ async function ingestTextToHanlinyuan(text, source = 'manual', metadata = {}, pr
|
||||
}
|
||||
|
||||
function getSettings() {
|
||||
if (!context || !context.extensionSettings) {
|
||||
|
||||
return structuredClone(ragDefaultSettings);
|
||||
if (!extension_settings[extensionName]) {
|
||||
extension_settings[extensionName] = {};
|
||||
}
|
||||
|
||||
const root = extension_settings[extensionName];
|
||||
|
||||
let s = context.extensionSettings[MODULE_NAME];
|
||||
let s = root[MODULE_NAME];
|
||||
|
||||
if (!s) {
|
||||
s = {};
|
||||
context.extensionSettings[MODULE_NAME] = s;
|
||||
root[MODULE_NAME] = s;
|
||||
}
|
||||
|
||||
if (s.condensationHistory === undefined) {
|
||||
@@ -343,16 +346,49 @@ function getSettings() {
|
||||
}
|
||||
|
||||
function saveSettings() {
|
||||
|
||||
if (context) context.saveSettingsDebounced();
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
function resetSettings() {
|
||||
|
||||
if (context) {
|
||||
context.extensionSettings[MODULE_NAME] = structuredClone(ragDefaultSettings);
|
||||
saveSettings();
|
||||
if (!extension_settings[extensionName]) {
|
||||
extension_settings[extensionName] = {};
|
||||
}
|
||||
extension_settings[extensionName][MODULE_NAME] = structuredClone(ragDefaultSettings);
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function migrateLegacyRagSettings() {
|
||||
const legacy = extension_settings[MODULE_NAME];
|
||||
if (!legacy || typeof legacy !== 'object') return;
|
||||
|
||||
if (!extension_settings[extensionName]) {
|
||||
extension_settings[extensionName] = {};
|
||||
}
|
||||
const root = extension_settings[extensionName];
|
||||
|
||||
// legacy 是用户此前实际交互过的真数据来源;nested 可能已被 super-memory 等模块用默认值填过,
|
||||
// 因此采用 legacy-优先的深合并:legacy 中的叶子值覆盖 nested,nested 中 legacy 没有的键保留。
|
||||
if (!root[MODULE_NAME] || typeof root[MODULE_NAME] !== 'object') {
|
||||
root[MODULE_NAME] = legacy;
|
||||
console.log(`[翰林院] 已迁移旧版 '${MODULE_NAME}' 设置到 extension_settings['${extensionName}']。`);
|
||||
} else {
|
||||
const merged = root[MODULE_NAME];
|
||||
const overlayLegacy = (src, dst) => {
|
||||
for (const key of Object.keys(src)) {
|
||||
const sv = src[key];
|
||||
if (sv && typeof sv === 'object' && !Array.isArray(sv) && dst[key] && typeof dst[key] === 'object' && !Array.isArray(dst[key])) {
|
||||
overlayLegacy(sv, dst[key]);
|
||||
} else {
|
||||
dst[key] = sv;
|
||||
}
|
||||
}
|
||||
};
|
||||
overlayLegacy(legacy, merged);
|
||||
console.log(`[翰林院] 发现新旧两处配置;已将顶层 '${MODULE_NAME}' 深合并覆盖到 extension_settings['${extensionName}']。`);
|
||||
}
|
||||
|
||||
delete extension_settings[MODULE_NAME];
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
function showNotification(message, type = 'info') {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getContext, extension_settings } from "/scripts/extensions.js";
|
||||
import { saveSettingsDebounced } from "/script.js";
|
||||
import { getCharacterStableId } from "../utils/context-utils.js";
|
||||
import { getMemoryState } from "../table-system/manager.js";
|
||||
import { extensionName } from "../../utils/settings.js";
|
||||
@@ -160,26 +161,62 @@ export function getRelatedNodes(nodeId, maxDepth = 1) {
|
||||
return related;
|
||||
}
|
||||
|
||||
function getGraphStore(create = false) {
|
||||
if (!extension_settings[extensionName]) {
|
||||
if (!create) return null;
|
||||
extension_settings[extensionName] = {};
|
||||
}
|
||||
const root = extension_settings[extensionName];
|
||||
if (!root.relationship_graphs) {
|
||||
if (!create) return null;
|
||||
root.relationship_graphs = {};
|
||||
}
|
||||
return root.relationship_graphs;
|
||||
}
|
||||
|
||||
function migrateLegacyRelationshipGraphs() {
|
||||
const legacy = extension_settings.relationship_graphs;
|
||||
if (!legacy || typeof legacy !== 'object') return;
|
||||
|
||||
if (!extension_settings[extensionName]) {
|
||||
extension_settings[extensionName] = {};
|
||||
}
|
||||
const root = extension_settings[extensionName];
|
||||
|
||||
if (!root.relationship_graphs) {
|
||||
root.relationship_graphs = legacy;
|
||||
console.log(`[关系图谱] 已迁移旧版 'relationship_graphs' 到 extension_settings['${extensionName}']。`);
|
||||
} else {
|
||||
console.log(`[关系图谱] 发现遗留顶层 'relationship_graphs',但新位置已存在;合并遗留数据并清理顶层。`);
|
||||
for (const [cid, data] of Object.entries(legacy)) {
|
||||
if (!root.relationship_graphs[cid]) {
|
||||
root.relationship_graphs[cid] = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete extension_settings.relationship_graphs;
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
export async function saveGraph() {
|
||||
const context = getContext();
|
||||
const charId = getCharacterStableId();
|
||||
if (!charId) return;
|
||||
|
||||
if (!context.extensionSettings.relationship_graphs) {
|
||||
context.extensionSettings.relationship_graphs = {};
|
||||
}
|
||||
|
||||
context.extensionSettings.relationship_graphs[charId] = graphData;
|
||||
context.saveSettingsDebounced();
|
||||
const store = getGraphStore(true);
|
||||
if (!store) return;
|
||||
|
||||
store[charId] = graphData;
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
export async function loadGraph() {
|
||||
const context = getContext();
|
||||
const charId = getCharacterStableId();
|
||||
if (!charId) return;
|
||||
|
||||
if (context.extensionSettings.relationship_graphs && context.extensionSettings.relationship_graphs[charId]) {
|
||||
graphData = context.extensionSettings.relationship_graphs[charId];
|
||||
const store = getGraphStore(false);
|
||||
if (store && store[charId]) {
|
||||
graphData = store[charId];
|
||||
console.log(`[关系图谱] 已加载角色 ${charId} 的图谱: ${graphData.nodes.length} 个节点, ${graphData.edges.length} 条边。`);
|
||||
} else {
|
||||
graphData = { nodes: [], edges: [] };
|
||||
@@ -188,6 +225,7 @@ export async function loadGraph() {
|
||||
|
||||
const context = getContext();
|
||||
if (context) {
|
||||
migrateLegacyRelationshipGraphs();
|
||||
loadGraph();
|
||||
document.addEventListener('AMILY2_TABLE_UPDATED', (e) => {
|
||||
const { tableName } = e.detail;
|
||||
|
||||
Reference in New Issue
Block a user