fix(story-summary): polish vector api UX and lint

This commit is contained in:
2026-04-04 12:52:29 +08:00
parent 3d1f6dc274
commit 5daff85f3f
5 changed files with 19 additions and 34 deletions

View File

@@ -26,18 +26,6 @@ const PROVIDER_MAP = {
const JSON_PREFILL = DEFAULT_SUMMARY_ASSISTANT_PREFILL_PROMPT;
const LLM_PROMPT_CONFIG = {
topSystem: DEFAULT_SUMMARY_SYSTEM_PROMPT,
assistantDoc: DEFAULT_SUMMARY_ASSISTANT_DOC_PROMPT,
assistantAskSummary: DEFAULT_SUMMARY_ASSISTANT_ASK_SUMMARY_PROMPT,
assistantAskContent: DEFAULT_SUMMARY_ASSISTANT_ASK_CONTENT_PROMPT,
metaProtocolStart: DEFAULT_SUMMARY_META_PROTOCOL_START_PROMPT,
userJsonFormat: DEFAULT_SUMMARY_USER_JSON_FORMAT_PROMPT,
assistantCheck: DEFAULT_SUMMARY_ASSISTANT_CHECK_PROMPT,
userConfirm: DEFAULT_SUMMARY_USER_CONFIRM_PROMPT,
assistantPrefill: DEFAULT_SUMMARY_ASSISTANT_PREFILL_PROMPT,
};
// ═══════════════════════════════════════════════════════════════════════════
// 工具函数
// ═══════════════════════════════════════════════════════════════════════════

View File

@@ -806,11 +806,7 @@ function buildNonVectorPrompt(store) {
if (!sections.length) return "";
return (
`${buildSystemPreamble()}\n` +
`<剧情记忆>\n\n${sections.join("\n\n")}\n\n</剧情记忆>\n` +
`${buildPostscript()}`
);
return buildMemoryPromptText(sections.join("\n\n"));
}
/**

View File

@@ -611,9 +611,9 @@ All checks passed. Beginning incremental extraction...
updateVectorProviderUI(prefix, provider);
}
function saveCurrentVectorApiProfile(prefix) {
function saveCurrentVectorApiProfile(prefix, providerOverride = null) {
const apiCfg = config.vector[`${prefix}Api`] ||= {};
const provider = $(`${prefix}-api-provider`)?.value || apiCfg.provider || 'siliconflow';
const provider = providerOverride || $(`${prefix}-api-provider`)?.value || apiCfg.provider || 'siliconflow';
apiCfg.providers = normalizeProviderProfiles(prefix, apiCfg);
apiCfg.providers[provider] = {
url: $(`${prefix}-api-url`)?.value?.trim() || '',
@@ -661,6 +661,12 @@ All checks passed. Beginning incremental extraction...
$(`${prefix}-api-model-select`).value = cache.includes(profile.model) ? profile.model : '';
}
function saveVectorApiSection(prefix) {
saveCurrentVectorApiProfile(prefix);
saveConfig();
setStatusText($(`${prefix}-api-connect-status`), '此组配置已保存', 'success');
}
async function fetchVectorModels(prefix) {
const provider = $(`${prefix}-api-provider`).value;
const pv = VECTOR_PROVIDER_DEFAULTS[provider] || VECTOR_PROVIDER_DEFAULTS.custom;
@@ -927,8 +933,9 @@ All checks passed. Beginning incremental extraction...
};
$(`${prefix}-api-provider`).onchange = e => {
saveCurrentVectorApiProfile(prefix);
const target = config.vector[`${prefix}Api`] ||= {};
const previousProvider = target.provider || 'siliconflow';
saveCurrentVectorApiProfile(prefix, previousProvider);
target.providers = normalizeProviderProfiles(prefix, target);
target.provider = e.target.value;
target.providers[e.target.value] ||= createDefaultProviderProfile(e.target.value, VECTOR_API_DEFAULT_MODELS[prefix]);
@@ -940,6 +947,7 @@ All checks passed. Beginning incremental extraction...
};
$(`${prefix}-btn-connect`).onclick = () => fetchVectorModels(prefix);
$(`${prefix}-btn-save`).onclick = () => saveVectorApiSection(prefix);
$(`${prefix}-btn-test`).onclick = () => {
const btn = $(`${prefix}-btn-test`);
if (btn) btn.disabled = true;

View File

@@ -475,8 +475,9 @@
</div>
</div>
<div class="settings-btn-row" id="l0-api-connect-row" style="margin-bottom:8px;">
<button class="btn btn-sm" id="l0-btn-connect" style="flex:1">连接 / 拉取模型列表</button>
<button class="btn btn-sm" id="l0-btn-connect" style="flex:1">拉取</button>
<button class="btn btn-sm" id="l0-btn-test" style="flex:1">测试</button>
<button class="btn btn-sm btn-p" id="l0-btn-save" style="flex:1">保存</button>
</div>
<div class="settings-hint" id="l0-api-connect-status" style="margin-bottom:16px;"></div>
</div>
@@ -527,8 +528,9 @@
</div>
</div>
<div class="settings-btn-row" id="embedding-api-connect-row" style="margin-bottom:8px;">
<button class="btn btn-sm" id="embedding-btn-connect" style="flex:1">连接 / 拉取模型列表</button>
<button class="btn btn-sm" id="embedding-btn-connect" style="flex:1">拉取</button>
<button class="btn btn-sm" id="embedding-btn-test" style="flex:1">测试</button>
<button class="btn btn-sm btn-p" id="embedding-btn-save" style="flex:1">保存</button>
</div>
<div class="settings-hint" id="embedding-api-connect-status" style="margin-bottom:16px;"></div>
</div>
@@ -578,9 +580,10 @@
<select id="rerank-api-model-select"><option value="">请选择</option></select>
</div>
</div>
<div class="settings-btn-row" id="rerank-api-connect-row">
<button class="btn btn-sm" id="rerank-btn-connect" style="flex:1">连接 / 拉取模型列表</button>
<div class="settings-btn-row" id="rerank-api-connect-row" style="margin-bottom:8px;">
<button class="btn btn-sm" id="rerank-btn-connect" style="flex:1">拉取</button>
<button class="btn btn-sm" id="rerank-btn-test" style="flex:1">测试</button>
<button class="btn btn-sm btn-p" id="rerank-btn-save" style="flex:1">保存</button>
</div>
<div class="settings-hint" id="rerank-api-connect-status"></div>
</div>

View File

@@ -83,16 +83,6 @@ function uint8ToBase64(uint8) {
return btoa(result);
}
// base64 → Uint8Array
function base64ToUint8(base64) {
const binary = atob(base64);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) {
bytes[i] = binary.charCodeAt(i);
}
return bytes;
}
// 服务器备份文件名
function getBackupFilename(chatId) {
// chatId 可能含中文/特殊字符ST 只接受 [a-zA-Z0-9_-]