refactor(ena-planner): align API settings with story-summary and backend proxy flow

This commit is contained in:
2026-02-25 14:50:01 +08:00
parent 5272799b15
commit 841d5f0e1f
3 changed files with 177 additions and 109 deletions

View File

@@ -99,47 +99,38 @@
<div class="form-group">
<label class="form-label">渠道类型</label>
<select id="ep_api_channel" class="input">
<option value="openai">OpenAI 兼容</option>
<option value="gemini">Gemini 兼容</option>
<option value="claude">Claude 兼容</option>
<option value="st_main">ST Main API (no setup)</option>
<option value="openai">OpenAI compatible</option>
<option value="gemini">Gemini compatible</option>
<option value="claude">Claude compatible</option>
<option value="deepseek">DeepSeek compatible</option>
<option value="cohere">Cohere compatible</option>
<option value="custom">Custom compatible</option>
</select>
</div>
<div class="form-group">
<label class="form-label">路径前缀</label>
<select id="ep_prefix_mode" class="input">
<option value="auto">自动 (如 /v1)</option>
<option value="custom">自定义</option>
</select>
</div>
</div>
<div class="form-group">
<label class="form-label">API 地址</label>
<input id="ep_api_base" type="text" class="input" placeholder="https://api.openai.com">
</div>
<div class="form-group hidden" id="ep_custom_prefix_group">
<label class="form-label">自定义前缀</label>
<input id="ep_prefix_custom" type="text" class="input" placeholder="/v1">
</div>
<div class="form-row">
<div class="form-group">
<label class="form-label">API Key</label>
<div class="input-row">
<input id="ep_api_key" type="password" class="input" placeholder="sk-...">
<button id="ep_toggle_key" class="btn">显示</button>
</div>
</div>
<div class="form-group">
<div class="form-group hidden" id="ep_model_row">
<label class="form-label">模型</label>
<input id="ep_model" type="text" class="input" placeholder="gpt-4o, claude-3-5-sonnet...">
</div>
</div>
<div class="form-row hidden" id="ep_api_url_key_row">
<div class="form-group">
<label class="form-label">API URL</label>
<input id="ep_api_base" type="text" class="input" placeholder="https://api.openai.com 或代理地址">
</div>
<div class="form-group">
<label class="form-label">API KEY</label>
<input id="ep_api_key" type="password" class="input" placeholder="仅本地保存,不上传">
</div>
</div>
<div class="form-hint">不需要填写 /v1 前缀,后端会按渠道自动处理。</div>
<div id="ep_model_selector" class="hidden" style="margin-top:12px;">
<label class="form-label">选择模型</label>
<select id="ep_model_select" class="input">
<option value="">-- 从列表选择 --</option>
</select>
</div>
<div class="btn-group" style="margin-top:16px;">
<div class="btn-group" style="margin-top:16px;" id="ep_model_actions">
<button id="ep_fetch_models" class="btn">拉取模型列表</button>
<button id="ep_test_conn" class="btn">测试连接</button>
</div>
@@ -438,8 +429,18 @@
if (viewId === 'debug') post('xb-ena:logs-request');
}
function updatePrefixModeUI() {
$('ep_custom_prefix_group').classList.toggle('hidden', $('ep_prefix_mode').value !== 'custom');
function updateApiChannelUI() {
const isMain = $('ep_api_channel').value === 'st_main';
$('ep_api_url_key_row').classList.toggle('hidden', isMain);
$('ep_model_row').classList.toggle('hidden', isMain);
$('ep_model_actions').classList.toggle('hidden', isMain);
if (isMain) $('ep_model_selector').classList.add('hidden');
const model = $('ep_model');
if (model && isMain) {
model.placeholder = 'Empty = follow ST main model';
} else if (model) {
model.placeholder = 'gpt-4o, claude-3-5-sonnet...';
}
}
/* ── Type conversion ── */
@@ -650,11 +651,9 @@
$('ep_skip_plot').value = String(toBool(cfg.skipIfPlotPresent, true));
const api = cfg.api || {};
$('ep_api_channel').value = api.channel || 'openai';
$('ep_prefix_mode').value = api.prefixMode || 'auto';
$('ep_api_base').value = api.baseUrl || '';
$('ep_prefix_custom').value = api.customPrefix || '';
$('ep_api_key').value = api.apiKey || '';
$('ep_api_channel').value = api.channel || 'st_main';
$('ep_api_base').value = api.url || '';
$('ep_api_key').value = api.key || '';
$('ep_model').value = api.model || '';
$('ep_stream').value = String(toBool(api.stream, false));
$('ep_temp').value = String(toNum(api.temperature, 1));
@@ -674,7 +673,7 @@
$('ep_logs_max').value = String(toNum(cfg.logsMax, 20));
setBadge(toBool(cfg.enabled, true));
updatePrefixModeUI();
updateApiChannelUI();
renderTemplateSelect();
renderPromptList();
renderLogs();
@@ -688,10 +687,8 @@
p.api = {
channel: $('ep_api_channel').value,
prefixMode: $('ep_prefix_mode').value,
baseUrl: $('ep_api_base').value.trim(),
customPrefix: $('ep_prefix_custom').value.trim(),
apiKey: $('ep_api_key').value,
url: $('ep_api_base').value.trim(),
key: $('ep_api_key').value.trim(),
model: $('ep_model').value.trim(),
stream: toBool($('ep_stream').value, false),
temperature: toNum($('ep_temp').value, 1),
@@ -734,17 +731,7 @@
setLocalStatus('ep_test_status', '测试中…', 'loading');
});
$('ep_toggle_key').addEventListener('click', () => {
const input = $('ep_api_key');
const btn = $('ep_toggle_key');
if (input.type === 'password') {
input.type = 'text'; btn.textContent = '隐藏';
} else {
input.type = 'password'; btn.textContent = '显示';
}
});
$('ep_prefix_mode').addEventListener('change', updatePrefixModeUI);
$('ep_api_channel').addEventListener('change', () => { updateApiChannelUI(); scheduleSave(); });
$('ep_fetch_models').addEventListener('click', () => {
post('xb-ena:fetch-models');
@@ -916,4 +903,4 @@
</script>
</body>
</html>
</html>