2026-01-26 01:16:35 +08:00
|
|
|
import { extension_settings } from "../../../../../../extensions.js";
|
|
|
|
|
import { EXT_ID } from "../../../core/constants.js";
|
|
|
|
|
import { xbLog } from "../../../core/debug-core.js";
|
|
|
|
|
import { CommonSettingStorage } from "../../../core/server-storage.js";
|
|
|
|
|
|
2026-02-17 22:25:55 +08:00
|
|
|
const MODULE_ID = "summaryConfig";
|
|
|
|
|
const SUMMARY_CONFIG_KEY = "storySummaryPanelConfig";
|
|
|
|
|
|
|
|
|
|
const DEFAULT_FILTER_RULES = [
|
|
|
|
|
{ start: "<think>", end: "</think>" },
|
|
|
|
|
{ start: "<thinking>", end: "</thinking>" },
|
|
|
|
|
{ start: "```", end: "```" },
|
|
|
|
|
];
|
2026-01-26 01:16:35 +08:00
|
|
|
|
|
|
|
|
export function getSettings() {
|
2026-02-17 22:25:55 +08:00
|
|
|
const ext = (extension_settings[EXT_ID] ||= {});
|
2026-01-26 01:16:35 +08:00
|
|
|
ext.storySummary ||= { enabled: true };
|
|
|
|
|
return ext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getSummaryPanelConfig() {
|
2026-02-24 10:21:00 +08:00
|
|
|
const clampKeepVisibleCount = (value) => {
|
|
|
|
|
const n = Number.parseInt(value, 10);
|
|
|
|
|
if (!Number.isFinite(n)) return 6;
|
|
|
|
|
return Math.max(0, Math.min(50, n));
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-26 01:16:35 +08:00
|
|
|
const defaults = {
|
2026-02-17 22:25:55 +08:00
|
|
|
api: { provider: "st", url: "", key: "", model: "", modelCache: [] },
|
2026-01-26 01:16:35 +08:00
|
|
|
gen: { temperature: null, top_p: null, top_k: null, presence_penalty: null, frequency_penalty: null },
|
|
|
|
|
trigger: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
interval: 20,
|
2026-02-17 22:25:55 +08:00
|
|
|
timing: "before_user",
|
|
|
|
|
role: "system",
|
2026-01-26 01:16:35 +08:00
|
|
|
useStream: true,
|
|
|
|
|
maxPerRun: 100,
|
2026-02-17 22:25:55 +08:00
|
|
|
wrapperHead: "",
|
|
|
|
|
wrapperTail: "",
|
2026-01-26 01:16:35 +08:00
|
|
|
forceInsertAtEnd: false,
|
|
|
|
|
},
|
2026-02-24 10:21:00 +08:00
|
|
|
ui: {
|
|
|
|
|
hideSummarized: false,
|
|
|
|
|
keepVisibleCount: 6,
|
|
|
|
|
},
|
2026-02-17 22:25:55 +08:00
|
|
|
textFilterRules: [...DEFAULT_FILTER_RULES],
|
2026-01-29 17:02:51 +08:00
|
|
|
vector: null,
|
2026-01-26 01:16:35 +08:00
|
|
|
};
|
2026-02-06 11:22:02 +08:00
|
|
|
|
2026-01-26 01:16:35 +08:00
|
|
|
try {
|
2026-02-17 22:25:55 +08:00
|
|
|
const raw = localStorage.getItem("summary_panel_config");
|
2026-01-26 01:16:35 +08:00
|
|
|
if (!raw) return defaults;
|
|
|
|
|
const parsed = JSON.parse(raw);
|
|
|
|
|
|
2026-02-17 22:25:55 +08:00
|
|
|
const textFilterRules = Array.isArray(parsed.textFilterRules)
|
|
|
|
|
? parsed.textFilterRules
|
|
|
|
|
: (Array.isArray(parsed.vector?.textFilterRules)
|
|
|
|
|
? parsed.vector.textFilterRules
|
|
|
|
|
: defaults.textFilterRules);
|
|
|
|
|
|
2026-01-26 01:16:35 +08:00
|
|
|
const result = {
|
|
|
|
|
api: { ...defaults.api, ...(parsed.api || {}) },
|
|
|
|
|
gen: { ...defaults.gen, ...(parsed.gen || {}) },
|
|
|
|
|
trigger: { ...defaults.trigger, ...(parsed.trigger || {}) },
|
2026-02-24 10:21:00 +08:00
|
|
|
ui: { ...defaults.ui, ...(parsed.ui || {}) },
|
2026-02-17 22:25:55 +08:00
|
|
|
textFilterRules,
|
|
|
|
|
vector: parsed.vector || null,
|
2026-01-26 01:16:35 +08:00
|
|
|
};
|
|
|
|
|
|
2026-02-17 22:25:55 +08:00
|
|
|
if (result.trigger.timing === "manual") result.trigger.enabled = false;
|
2026-01-26 01:16:35 +08:00
|
|
|
if (result.trigger.useStream === undefined) result.trigger.useStream = true;
|
2026-02-24 10:21:00 +08:00
|
|
|
result.ui.hideSummarized = !!result.ui.hideSummarized;
|
|
|
|
|
result.ui.keepVisibleCount = clampKeepVisibleCount(result.ui.keepVisibleCount);
|
2026-01-26 01:16:35 +08:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
} catch {
|
|
|
|
|
return defaults;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function saveSummaryPanelConfig(config) {
|
|
|
|
|
try {
|
2026-02-17 22:25:55 +08:00
|
|
|
localStorage.setItem("summary_panel_config", JSON.stringify(config));
|
2026-01-26 01:16:35 +08:00
|
|
|
CommonSettingStorage.set(SUMMARY_CONFIG_KEY, config);
|
|
|
|
|
} catch (e) {
|
2026-02-17 22:25:55 +08:00
|
|
|
xbLog.error(MODULE_ID, "保存面板配置失败", e);
|
2026-01-26 01:16:35 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getVectorConfig() {
|
|
|
|
|
try {
|
2026-02-17 22:25:55 +08:00
|
|
|
const raw = localStorage.getItem("summary_panel_config");
|
2026-01-26 01:16:35 +08:00
|
|
|
if (!raw) return null;
|
2026-02-17 22:25:55 +08:00
|
|
|
|
2026-01-26 01:16:35 +08:00
|
|
|
const parsed = JSON.parse(raw);
|
2026-01-29 17:02:51 +08:00
|
|
|
const cfg = parsed.vector || null;
|
2026-02-17 22:25:55 +08:00
|
|
|
if (!cfg) return null;
|
2026-02-06 11:22:02 +08:00
|
|
|
|
2026-02-17 22:25:55 +08:00
|
|
|
// Keep vector side normalized to online + siliconflow.
|
|
|
|
|
cfg.engine = "online";
|
|
|
|
|
cfg.online = cfg.online || {};
|
|
|
|
|
cfg.online.provider = "siliconflow";
|
|
|
|
|
cfg.online.model = "BAAI/bge-m3";
|
2026-02-06 11:22:02 +08:00
|
|
|
|
2026-01-29 17:02:51 +08:00
|
|
|
return cfg;
|
2026-01-26 01:16:35 +08:00
|
|
|
} catch {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 17:02:51 +08:00
|
|
|
export function getTextFilterRules() {
|
2026-02-17 22:25:55 +08:00
|
|
|
const cfg = getSummaryPanelConfig();
|
|
|
|
|
return Array.isArray(cfg?.textFilterRules)
|
|
|
|
|
? cfg.textFilterRules
|
|
|
|
|
: DEFAULT_FILTER_RULES;
|
2026-01-29 17:02:51 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-26 01:16:35 +08:00
|
|
|
export function saveVectorConfig(vectorCfg) {
|
|
|
|
|
try {
|
2026-02-17 22:25:55 +08:00
|
|
|
const raw = localStorage.getItem("summary_panel_config") || "{}";
|
2026-01-26 01:16:35 +08:00
|
|
|
const parsed = JSON.parse(raw);
|
2026-02-06 11:22:02 +08:00
|
|
|
|
|
|
|
|
parsed.vector = {
|
2026-02-17 22:25:55 +08:00
|
|
|
enabled: !!vectorCfg?.enabled,
|
|
|
|
|
engine: "online",
|
2026-02-06 11:22:02 +08:00
|
|
|
online: {
|
2026-02-17 22:25:55 +08:00
|
|
|
provider: "siliconflow",
|
|
|
|
|
key: vectorCfg?.online?.key || "",
|
|
|
|
|
model: "BAAI/bge-m3",
|
2026-02-06 11:22:02 +08:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-17 22:25:55 +08:00
|
|
|
localStorage.setItem("summary_panel_config", JSON.stringify(parsed));
|
2026-01-26 01:16:35 +08:00
|
|
|
CommonSettingStorage.set(SUMMARY_CONFIG_KEY, parsed);
|
|
|
|
|
} catch (e) {
|
2026-02-17 22:25:55 +08:00
|
|
|
xbLog.error(MODULE_ID, "保存向量配置失败", e);
|
2026-01-26 01:16:35 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function loadConfigFromServer() {
|
|
|
|
|
try {
|
|
|
|
|
const savedConfig = await CommonSettingStorage.get(SUMMARY_CONFIG_KEY, null);
|
|
|
|
|
if (savedConfig) {
|
2026-02-17 22:25:55 +08:00
|
|
|
localStorage.setItem("summary_panel_config", JSON.stringify(savedConfig));
|
|
|
|
|
xbLog.info(MODULE_ID, "已从服务端加载面板配置");
|
2026-01-26 01:16:35 +08:00
|
|
|
return savedConfig;
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2026-02-17 22:25:55 +08:00
|
|
|
xbLog.warn(MODULE_ID, "加载面板配置失败", e);
|
2026-01-26 01:16:35 +08:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|