Initial commit
This commit is contained in:
commit
57fc3525eb
7311 files changed
+1291398
No files matched your search
@@ -0,0 +1,212 @@
|
||||
// R2-8:站点适配器维护面板——健康巡检(R1-6)、选择器脆弱度(R1-7)、适配器在线更新(R1-3)。
|
||||
// 由 ConfigTab 以 <adapter-panel> 使用;request 为带鉴权与超时的请求函数(返回解析后的 JSON,出错抛异常)。
|
||||
window.AdapterPanel = {
|
||||
name: 'AdapterPanel',
|
||||
props: {
|
||||
domain: { type: String, default: '' },
|
||||
presetName: { type: String, default: '' },
|
||||
request: { type: Function, required: true }
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
health: null, healthLoading: false, healthError: '',
|
||||
lint: null, lintLoading: false, lintError: '',
|
||||
updates: null, updatesLoading: false, updatesError: '',
|
||||
applyResult: null, applying: false
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
healthTab() {
|
||||
return (this.health && Array.isArray(this.health.tabs) && this.health.tabs[0]) || null;
|
||||
},
|
||||
lintRows() {
|
||||
const presets = (this.lint && this.lint.presets) || {};
|
||||
const rows = presets[this.presetName] || Object.values(presets)[0] || [];
|
||||
return rows.filter(row => row.score < 100 || (row.issues || []).length);
|
||||
},
|
||||
updateRows() {
|
||||
return ((this.updates && this.updates.sites) || []).filter(row => row.status !== 'up_to_date');
|
||||
},
|
||||
safeUpdateCount() {
|
||||
return this.updateRows.filter(row => row.status === 'update_available' || row.status === 'new_site').length;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
domain() {
|
||||
this.health = null; this.healthError = '';
|
||||
this.lint = null; this.lintError = '';
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
statusLabel(status) {
|
||||
return ({
|
||||
healthy: '健康', degraded: '部分缺失', broken: '异常', unreachable: '无可用页面',
|
||||
ok: '命中', missing: '未命中', invalid: '语法无效',
|
||||
up_to_date: '已是最新', update_available: '可安全更新', conflict: '本地已修改',
|
||||
new_site: '新站点', local_only: '仅本地', requires_newer_app: '需要更新程序'
|
||||
})[status] || status;
|
||||
},
|
||||
statusClass(status) {
|
||||
if (['healthy', 'ok', 'up_to_date'].includes(status)) return 'adapter-badge is-good';
|
||||
if (['degraded', 'missing', 'update_available', 'new_site', 'conflict'].includes(status)) return 'adapter-badge is-warn';
|
||||
if (['broken', 'invalid', 'requires_newer_app'].includes(status)) return 'adapter-badge is-bad';
|
||||
return 'adapter-badge';
|
||||
},
|
||||
async runHealth() {
|
||||
if (!this.domain) return;
|
||||
this.healthLoading = true; this.healthError = '';
|
||||
try {
|
||||
const query = new URLSearchParams({ site: this.domain });
|
||||
if (this.presetName) query.set('preset', this.presetName);
|
||||
this.health = await this.request('/api/adapters/health?' + query.toString());
|
||||
} catch (error) {
|
||||
this.healthError = error.message || String(error);
|
||||
} finally {
|
||||
this.healthLoading = false;
|
||||
}
|
||||
},
|
||||
async runLint() {
|
||||
if (!this.domain) return;
|
||||
this.lintLoading = true; this.lintError = '';
|
||||
try {
|
||||
this.lint = await this.request('/api/adapters/lint?' + new URLSearchParams({ site: this.domain }).toString());
|
||||
} catch (error) {
|
||||
this.lintError = error.message || String(error);
|
||||
} finally {
|
||||
this.lintLoading = false;
|
||||
}
|
||||
},
|
||||
async checkUpdates(keepApplyResult = false) {
|
||||
// 应用更新后会自动刷新列表:这时要保留“已更新 N 个站点”的结果提示,不能被清掉
|
||||
this.updatesLoading = true; this.updatesError = '';
|
||||
if (!keepApplyResult) this.applyResult = null;
|
||||
try {
|
||||
this.updates = await this.request('/api/adapters/updates');
|
||||
} catch (error) {
|
||||
this.updatesError = error.message || String(error);
|
||||
} finally {
|
||||
this.updatesLoading = false;
|
||||
}
|
||||
},
|
||||
async applyUpdates(sites = null, includeConflicts = false) {
|
||||
if (includeConflicts && !window.confirm('该站点的本地配置改过:将按「本地优先」与官方新版合并(保留你的修改,补入新增字段)。继续?')) {
|
||||
return;
|
||||
}
|
||||
this.applying = true; this.updatesError = '';
|
||||
try {
|
||||
const body = { include_conflicts: includeConflicts };
|
||||
if (sites) body.sites = sites;
|
||||
this.applyResult = await this.request('/api/adapters/updates/apply', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body)
|
||||
});
|
||||
this.$emit('updated', this.applyResult);
|
||||
await this.checkUpdates(true);
|
||||
} catch (error) {
|
||||
this.updatesError = error.message || String(error);
|
||||
} finally {
|
||||
this.applying = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="adapter-panel">
|
||||
<section class="cap-card adapter-card" aria-label="健康巡检">
|
||||
<div class="adapter-card-header">
|
||||
<div>
|
||||
<h4>健康巡检</h4>
|
||||
<p>在浏览器里已打开的 {{ domain || '当前站点' }} 页面上检查各选择器能否命中。只读取页面,不会输入、点击或发送消息。</p>
|
||||
</div>
|
||||
<button type="button" class="adapter-btn" :disabled="!domain || healthLoading" @click="runHealth()">
|
||||
{{ healthLoading ? '巡检中…' : '开始巡检' }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="healthError" class="adapter-error">{{ healthError }}</p>
|
||||
<div v-if="health" class="adapter-result">
|
||||
<p>结果:<span :class="statusClass(health.status)">{{ statusLabel(health.status) }}</span>
|
||||
<span v-if="health.preset" class="adapter-muted">预设:{{ health.preset }}</span></p>
|
||||
<ul v-if="health.problems && health.problems.length" class="adapter-problems">
|
||||
<li v-for="problem in health.problems" :key="problem">{{ problem }}</li>
|
||||
</ul>
|
||||
<table v-if="healthTab" class="adapter-table">
|
||||
<thead><tr><th>元素</th><th>状态</th><th>命中数</th><th>稳健度</th><th>说明</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="row in healthTab.selectors" :key="row.key">
|
||||
<td><code>{{ row.key }}</code></td>
|
||||
<td><span :class="statusClass(row.status)">{{ statusLabel(row.status) }}</span></td>
|
||||
<td>{{ row.count }}</td>
|
||||
<td>{{ row.quality ? row.quality.score : '-' }}</td>
|
||||
<td>
|
||||
<span v-if="row.hint">{{ row.hint }}</span>
|
||||
<span v-if="row.suggestions && row.suggestions.length">可尝试:<code>{{ row.suggestions[0].selector }}</code></span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="cap-card adapter-card" aria-label="选择器稳健度">
|
||||
<div class="adapter-card-header">
|
||||
<div>
|
||||
<h4>选择器稳健度</h4>
|
||||
<p>静态检查当前预设的选择器:生成的哈希类名、依赖元素顺序或界面文字的写法,在站点改版时容易失效。</p>
|
||||
</div>
|
||||
<button type="button" class="adapter-btn" :disabled="!domain || lintLoading" @click="runLint()">
|
||||
{{ lintLoading ? '检查中…' : '检查' }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="lintError" class="adapter-error">{{ lintError }}</p>
|
||||
<div v-if="lint" class="adapter-result">
|
||||
<p v-if="!lintRows.length" class="adapter-good">当前预设的选择器没有发现明显问题。</p>
|
||||
<table v-else class="adapter-table">
|
||||
<thead><tr><th>元素</th><th>得分</th><th>问题</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="row in lintRows" :key="row.key">
|
||||
<td><code>{{ row.key }}</code></td>
|
||||
<td>{{ row.score }}</td>
|
||||
<td>{{ (row.issues || []).map(issue => issue.message).join(';') || '—' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="cap-card adapter-card" aria-label="适配器更新">
|
||||
<div class="adapter-card-header">
|
||||
<div>
|
||||
<h4>适配器更新(全部站点)</h4>
|
||||
<p>与官方仓库的站点配置比较。没改过的站点可以一键更新;改过的站点会单独标出,需要你确认后按「本地优先」合并。</p>
|
||||
</div>
|
||||
<button type="button" class="adapter-btn" :disabled="updatesLoading || applying" @click="checkUpdates()">
|
||||
{{ updatesLoading ? '检查中…' : '检查更新' }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="updatesError" class="adapter-error">{{ updatesError }}</p>
|
||||
<div v-if="updates" class="adapter-result">
|
||||
<p v-if="!updateRows.length" class="adapter-good">所有站点配置都是最新的。</p>
|
||||
<template v-else>
|
||||
<table class="adapter-table">
|
||||
<thead><tr><th>站点</th><th>状态</th><th>本地版本</th><th>官方版本</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="row in updateRows" :key="row.site">
|
||||
<td><code>{{ row.site }}</code></td>
|
||||
<td><span :class="statusClass(row.status)">{{ statusLabel(row.status) }}</span></td>
|
||||
<td>{{ row.local_version || '—' }}</td>
|
||||
<td>{{ row.official_version || '—' }}</td>
|
||||
<td>
|
||||
<button v-if="row.status === 'conflict'" type="button" class="adapter-btn is-small" :disabled="applying"
|
||||
@click="applyUpdates([row.site], true)">合并</button>
|
||||
<span v-else-if="row.status === 'requires_newer_app'" class="adapter-muted">需要 {{ row.min_app_version }}+</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<button type="button" class="adapter-btn" :disabled="applying || !safeUpdateCount" @click="applyUpdates()">
|
||||
{{ applying ? '更新中…' : ('应用 ' + safeUpdateCount + ' 个安全更新') }}
|
||||
</button>
|
||||
</template>
|
||||
<p v-if="applyResult" class="adapter-good">已更新 {{ (applyResult.applied || []).length }} 个站点<span v-if="(applyResult.skipped || []).length">,跳过 {{ applyResult.skipped.length }} 个</span>。</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>`
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
// ==================== 提取器显示面板 ====================
|
||||
|
||||
window.ExtractorPanel = {
|
||||
name: 'ExtractorPanel',
|
||||
props: {
|
||||
extractorId: { type: String, default: null },
|
||||
extractorVerified: { type: Boolean, default: false },
|
||||
collapsed: { type: Boolean, default: true }
|
||||
},
|
||||
emits: ['update:collapsed'],
|
||||
methods: {
|
||||
toggle() {
|
||||
this.$emit('update:collapsed', !this.collapsed);
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="bg-white dark:bg-gray-800 border dark:border-gray-700 rounded-lg shadow-sm">
|
||||
<div class="px-4 py-3 border-b dark:border-gray-700 flex justify-between items-center cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors"
|
||||
@click="toggle">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="w-4 inline-flex justify-center text-gray-500 dark:text-gray-400" v-html="collapsed ? $icons.chevronDown : $icons.chevronUp"></span>
|
||||
<h3 class="font-semibold text-gray-900 dark:text-white">🧩 提取器</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div v-show="!collapsed" class="p-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<div class="text-sm text-gray-600 dark:text-gray-300">
|
||||
当前: <span class="font-medium">{{ extractorId || '默认' }}</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 mt-1">
|
||||
<span v-if="extractorVerified"
|
||||
class="px-2 py-0.5 text-xs bg-green-100 dark:bg-green-900/50 text-green-700 dark:text-green-300 rounded">
|
||||
✓ 已验证
|
||||
</span>
|
||||
<span v-else
|
||||
class="px-2 py-0.5 text-xs bg-yellow-100 dark:bg-yellow-900/50 text-yellow-700 dark:text-yellow-300 rounded">
|
||||
⚠ 未验证
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-sm text-gray-500 dark:text-gray-400">
|
||||
前往「提取器」Tab 管理
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
};
|
||||
|
||||
@@ -0,0 +1,812 @@
|
||||
// ==================== 文件粘贴 / 附件发送配置面板 ====================
|
||||
|
||||
window.FilePastePanel = {
|
||||
name: 'FilePastePanel',
|
||||
props: {
|
||||
filePasteConfig: { type: Object, required: true },
|
||||
currentDomain: { type: String, default: null },
|
||||
selectedPreset: { type: String, default: null },
|
||||
collapsed: { type: Boolean, default: true }
|
||||
},
|
||||
emits: ['update:collapsed'],
|
||||
data() {
|
||||
return {
|
||||
// 内部分区折叠状态:高级附件规则默认收起,其余默认展开
|
||||
sectionCollapsed: {
|
||||
attachments: false,
|
||||
pasteMode: false,
|
||||
sendConfirm: false,
|
||||
advancedRules: true
|
||||
},
|
||||
defaultAttachments: {
|
||||
enabled: true, max_count: 8, max_file_mb: 20, max_total_mb: 50,
|
||||
allowed_types: [], error_selectors: [], ready_timeout: 30,
|
||||
transport_order: ['file_input', 'cdp_drop', 'js_drop', 'file_clipboard']
|
||||
},
|
||||
transportOptions: [
|
||||
{ value: 'file_input', label: '文件输入框', description: '优先上传原文件;使用 file_input 选择器或自动查找。' },
|
||||
{ value: 'cdp_drop', label: '浏览器原生拖拽', description: '需要 drop_zone;不通过 base64 传输大文件。' },
|
||||
{ value: 'js_drop', label: '网页拖拽事件', description: '需要 drop_zone;仅用于不超过 4 MB 的文件。' },
|
||||
{ value: 'file_clipboard', label: '原生文件剪贴板', description: '需要系统支持与已确认的输入框焦点。' },
|
||||
{ value: 'image_clipboard', label: '图片像素剪贴板(有损)', description: '仅用于图片兼容;可能丢失透明度、动画帧和元数据。' }
|
||||
],
|
||||
defaultFilePaste: {
|
||||
enabled: false,
|
||||
threshold: 50000,
|
||||
temp_file_type: 'txt',
|
||||
hint_text: '完全专注于文件内容',
|
||||
txt_hint_text: '完全专注于文件内容',
|
||||
pdf_hint_text: '完全专注于文件内容',
|
||||
error_hint_text: '输入文本长度超过限制,已中止发送',
|
||||
reacquire_input_after_upload: false,
|
||||
post_upload_input_selector: '',
|
||||
post_upload_settle: 0.0,
|
||||
upload_signal_timeout: 2.5,
|
||||
upload_signal_grace: 3.0,
|
||||
state_probe: {
|
||||
enabled: false,
|
||||
code: ''
|
||||
}
|
||||
},
|
||||
tempFileTypeOptions: [
|
||||
{ value: 'txt', label: 'TXT' },
|
||||
{ value: 'pdf', label: 'PDF' },
|
||||
{ value: 'chunk', label: '分块' },
|
||||
{ value: 'error', label: 'ERROR' }
|
||||
],
|
||||
// 修复:补齐后端 get_default_send_confirmation_config() 的 7 个缺失键,
|
||||
// 否则未配过这些项的预设打开面板时对应输入框为空(如 pre_retry_probe_window)
|
||||
defaultSendConfirmation: {
|
||||
attachment_sensitivity: 'medium',
|
||||
post_click_observe_window: 1.8,
|
||||
pre_retry_probe_window: 0.12,
|
||||
retry_observe_window: 0.9,
|
||||
attachment_observe_window: 6.0,
|
||||
max_retry_count: 2,
|
||||
retry_interval: 0.6,
|
||||
retry_cooldown_window: 1.5,
|
||||
retry_action: 'click_send_btn',
|
||||
retry_key_combo: 'Enter',
|
||||
retry_on_unconfirmed_send: true,
|
||||
accept_attachment_change: false,
|
||||
accept_attachment_disappear: false,
|
||||
accept_probe_confirmation: true,
|
||||
retry_block_on_stop_button: true,
|
||||
retry_block_if_generating: true,
|
||||
trust_network_activity: true,
|
||||
trust_generating_indicator: true,
|
||||
trust_send_disabled_with_input_shrink: true
|
||||
},
|
||||
defaultAttachmentMonitor: {
|
||||
root_selectors: [],
|
||||
attachment_selectors: [],
|
||||
pending_selectors: [],
|
||||
status_selectors: [],
|
||||
content_exclusion_selectors: [],
|
||||
busy_text_markers: [],
|
||||
ignored_busy_text_markers: [],
|
||||
send_button_disabled_markers: [],
|
||||
require_attachment_present: false,
|
||||
require_upload_signal_before_ready: false,
|
||||
continue_once_on_unconfirmed_send: true,
|
||||
idle_timeout: 8.0,
|
||||
hard_max_wait: 90.0
|
||||
},
|
||||
attachmentSensitivityOptions: [
|
||||
{
|
||||
value: 'low',
|
||||
label: '低',
|
||||
description: '只认更强的发送信号,适合按钮状态经常乱跳的站点。'
|
||||
},
|
||||
{
|
||||
value: 'medium',
|
||||
label: '中',
|
||||
description: '平衡等待时间和识别速度,适合作为大多数站点的默认值。'
|
||||
},
|
||||
{
|
||||
value: 'high',
|
||||
label: '高',
|
||||
description: '更早接受附件发送成功信号,适合附件反馈慢、预览挂得晚的站点。'
|
||||
}
|
||||
],
|
||||
attachmentMonitorDrafts: {}
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
filePasteConfig: {
|
||||
handler() {
|
||||
this.syncAttachmentMonitorDrafts();
|
||||
},
|
||||
deep: true,
|
||||
immediate: true
|
||||
},
|
||||
currentDomain() {
|
||||
this.syncAttachmentMonitorDrafts(true);
|
||||
},
|
||||
selectedPreset() {
|
||||
this.syncAttachmentMonitorDrafts(true);
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.syncAttachmentMonitorDrafts(true);
|
||||
},
|
||||
computed: {
|
||||
resolvedAttachments() {
|
||||
return { ...this.defaultAttachments, ...((this.filePasteConfig || {}).attachments || {}) };
|
||||
},
|
||||
orderedTransports() {
|
||||
return (this.resolvedAttachments.transport_order || [])
|
||||
.map(value => this.transportOptions.find(option => option.value === value)).filter(Boolean);
|
||||
},
|
||||
longTextStrategy() {
|
||||
return ['chunk', 'error'].includes(this.resolvedFilePaste.temp_file_type)
|
||||
? this.resolvedFilePaste.temp_file_type : 'attachment';
|
||||
},
|
||||
resolvedFilePaste() {
|
||||
const raw = this.filePasteConfig || {};
|
||||
return {
|
||||
...this.defaultFilePaste,
|
||||
...raw,
|
||||
send_confirmation: {
|
||||
...this.defaultSendConfirmation,
|
||||
...((raw && raw.send_confirmation) || {})
|
||||
},
|
||||
attachment_monitor: {
|
||||
...this.defaultAttachmentMonitor,
|
||||
...((raw && raw.attachment_monitor) || {})
|
||||
},
|
||||
state_probe: {
|
||||
...(this.defaultFilePaste.state_probe || {}),
|
||||
...((raw && raw.state_probe) || {})
|
||||
},
|
||||
};
|
||||
},
|
||||
currentPresetLabel() {
|
||||
return String(this.selectedPreset || '').trim() || '主预设';
|
||||
},
|
||||
statusText() {
|
||||
return (this.resolvedAttachments.enabled ? '附件允许' : '附件禁止') + ' · ' + (this.resolvedFilePaste.enabled ? '长文本处理开启' : '长文本处理关闭');
|
||||
},
|
||||
attachmentSensitivityMeta() {
|
||||
const value = this.resolvedFilePaste.send_confirmation.attachment_sensitivity;
|
||||
return this.attachmentSensitivityOptions.find(option => option.value === value) || this.attachmentSensitivityOptions[1];
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
updateAttachmentField(key, value) {
|
||||
const config = this.getMutableFilePaste();
|
||||
config.attachments = { ...(config.attachments || {}), [key]: value };
|
||||
},
|
||||
updateAttachmentLimit(key, value, ceiling) {
|
||||
const number = Number(value);
|
||||
if (!Number.isFinite(number) || value === '') return;
|
||||
this.updateAttachmentField(key, Math.max(1, Math.min(ceiling, Math.trunc(number))));
|
||||
},
|
||||
updateAllowedTypes(value) {
|
||||
this.updateAttachmentField('allowed_types', [...new Set(String(value || '').toLowerCase().split(/[\s,;]+/).filter(Boolean))]);
|
||||
},
|
||||
toggleTransport(value) {
|
||||
const current = [...(this.resolvedAttachments.transport_order || [])];
|
||||
const next = current.includes(value) ? current.filter(item => item !== value) : [...current, value];
|
||||
this.updateAttachmentField('transport_order', next);
|
||||
},
|
||||
moveTransport(index, direction) {
|
||||
const current = [...(this.resolvedAttachments.transport_order || [])];
|
||||
const next = index + direction;
|
||||
if (next < 0 || next >= current.length) return;
|
||||
[current[index], current[next]] = [current[next], current[index]];
|
||||
this.updateAttachmentField('transport_order', current);
|
||||
},
|
||||
updateLongTextStrategy(value) {
|
||||
this.updateTempFileType(value === 'attachment' ? 'txt' : value);
|
||||
},
|
||||
toggle() {
|
||||
this.$emit('update:collapsed', !this.collapsed);
|
||||
},
|
||||
|
||||
toggleSection(key) {
|
||||
this.sectionCollapsed[key] = !this.sectionCollapsed[key];
|
||||
},
|
||||
|
||||
getMutableFilePaste() {
|
||||
return this.filePasteConfig || {};
|
||||
},
|
||||
|
||||
ensureSendConfirmation() {
|
||||
const fp = this.getMutableFilePaste();
|
||||
if (!fp.send_confirmation || typeof fp.send_confirmation !== 'object') {
|
||||
fp.send_confirmation = {};
|
||||
}
|
||||
return fp.send_confirmation;
|
||||
},
|
||||
|
||||
ensureAttachmentMonitor() {
|
||||
const fp = this.getMutableFilePaste();
|
||||
if (!fp.attachment_monitor || typeof fp.attachment_monitor !== 'object') {
|
||||
fp.attachment_monitor = {};
|
||||
}
|
||||
return fp.attachment_monitor;
|
||||
},
|
||||
|
||||
ensureStateProbe() {
|
||||
const fp = this.getMutableFilePaste();
|
||||
if (!fp.state_probe || typeof fp.state_probe !== 'object') {
|
||||
fp.state_probe = {};
|
||||
}
|
||||
return fp.state_probe;
|
||||
},
|
||||
|
||||
toggleEnabled() {
|
||||
const fp = this.getMutableFilePaste();
|
||||
fp.enabled = !this.resolvedFilePaste.enabled;
|
||||
},
|
||||
|
||||
updateThreshold(value) {
|
||||
// 修复:此前 <1000 直接丢弃,DOM 与模型脱节;改为与后端一致的夹取
|
||||
const num = parseInt(value);
|
||||
this.getMutableFilePaste().threshold = Number.isFinite(num)
|
||||
? Math.max(1000, Math.min(num, 10000000))
|
||||
: 50000;
|
||||
},
|
||||
|
||||
updateTempFileType(value) {
|
||||
const normalized = String(value || '').trim().toLowerCase();
|
||||
this.getMutableFilePaste().temp_file_type = ['txt', 'pdf', 'chunk', 'error'].includes(normalized) ? normalized : 'txt';
|
||||
},
|
||||
|
||||
updateHintText(value) {
|
||||
const fp = this.getMutableFilePaste();
|
||||
const type = this.resolvedFilePaste.temp_file_type;
|
||||
if (type === 'txt') {
|
||||
fp.txt_hint_text = value;
|
||||
} else if (type === 'pdf') {
|
||||
fp.pdf_hint_text = value;
|
||||
} else if (type === 'error') {
|
||||
fp.error_hint_text = value;
|
||||
}
|
||||
fp.hint_text = value;
|
||||
},
|
||||
|
||||
updateNumberField(field, value, fallback) {
|
||||
const parsed = parseFloat(value);
|
||||
this.getMutableFilePaste()[field] = Number.isFinite(parsed) ? parsed : fallback;
|
||||
},
|
||||
|
||||
updateBooleanField(field, value) {
|
||||
this.getMutableFilePaste()[field] = !!value;
|
||||
},
|
||||
|
||||
updateTextField(field, value) {
|
||||
this.getMutableFilePaste()[field] = value;
|
||||
},
|
||||
|
||||
updateSendConfirmationField(field, value) {
|
||||
this.ensureSendConfirmation()[field] = value;
|
||||
},
|
||||
|
||||
updateAttachmentMonitorField(field, value) {
|
||||
this.ensureAttachmentMonitor()[field] = value;
|
||||
},
|
||||
|
||||
updateStateProbeField(field, value) {
|
||||
this.ensureStateProbe()[field] = value;
|
||||
},
|
||||
|
||||
normalizeRuleList(value) {
|
||||
const lines = String(value || '')
|
||||
.split(/\r?\n/)
|
||||
.map(item => item.trim())
|
||||
.filter(Boolean);
|
||||
return [...new Set(lines)];
|
||||
},
|
||||
|
||||
syncAttachmentMonitorDrafts(force = false) {
|
||||
const monitor = this.resolvedFilePaste?.attachment_monitor || {};
|
||||
const listFields = [
|
||||
'attachment_selectors',
|
||||
'pending_selectors',
|
||||
'status_selectors',
|
||||
'content_exclusion_selectors',
|
||||
'busy_text_markers',
|
||||
'send_button_disabled_markers',
|
||||
'ignored_busy_text_markers',
|
||||
'root_selectors'
|
||||
];
|
||||
if (!this.attachmentMonitorDrafts) {
|
||||
this.attachmentMonitorDrafts = {};
|
||||
}
|
||||
const nextDrafts = { ...this.attachmentMonitorDrafts };
|
||||
let hasChange = false;
|
||||
for (const field of listFields) {
|
||||
const propArr = Array.isArray(monitor[field]) ? monitor[field] : [];
|
||||
const curDraftArr = this.normalizeRuleList(nextDrafts[field]);
|
||||
if (force || JSON.stringify(propArr) !== JSON.stringify(curDraftArr) || nextDrafts[field] === undefined || nextDrafts[field] === null) {
|
||||
nextDrafts[field] = propArr.join('\n');
|
||||
hasChange = true;
|
||||
}
|
||||
}
|
||||
if (hasChange) {
|
||||
this.attachmentMonitorDrafts = nextDrafts;
|
||||
}
|
||||
},
|
||||
|
||||
updateAttachmentMonitorListField(field, value) {
|
||||
if (!this.attachmentMonitorDrafts) {
|
||||
this.attachmentMonitorDrafts = {};
|
||||
}
|
||||
this.attachmentMonitorDrafts[field] = value;
|
||||
this.updateAttachmentMonitorField(field, this.normalizeRuleList(value));
|
||||
},
|
||||
|
||||
formatRuleList(value) {
|
||||
return Array.isArray(value) ? value.join('\n') : '';
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="cap-panel cap-input-panel bg-white dark:bg-gray-800 border dark:border-gray-700 rounded-lg shadow-sm">
|
||||
<div class="px-4 py-3 border-b dark:border-gray-700 flex justify-between items-center cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors"
|
||||
@click="toggle">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="w-4 inline-flex justify-center text-gray-500 dark:text-gray-400" v-html="collapsed ? $icons.chevronDown : $icons.chevronUp"></span>
|
||||
<h3 class="font-semibold text-gray-900 dark:text-white">发送内容</h3>
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">({{ statusText }})</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-show="!collapsed" class="p-4 space-y-4">
|
||||
|
||||
|
||||
<section class="cap-card" :class="{ 'is-enabled': resolvedAttachments.enabled }" aria-label="发送附件"><div class="cap-card-header"><span class="cap-icon" v-html="$icons.arrowUpTray"></span><div class="cap-copy"><div class="cap-title-row"><h4>发送附件</h4><span class="cap-scope">当前预设</span></div><p>把图片、文档或音视频交给 AI。网站本身也需要支持这些文件。</p></div><label class="cap-switch"><span class="cap-state" :class="{ 'is-on': resolvedAttachments.enabled }">{{ resolvedAttachments.enabled ? '已开启' : '已关闭' }}</span><input role="switch" aria-label="发送附件" type="checkbox" :checked="resolvedAttachments.enabled" @change="updateAttachmentField('enabled', $event.target.checked)" class="cap-switch-input"><i aria-hidden="true"></i></label></div><p class="cap-facts">最多 {{ resolvedAttachments.max_count }} 个文件 <i>·</i> 单个 {{ resolvedAttachments.max_file_mb }} MB <i>·</i> 合计 {{ resolvedAttachments.max_total_mb }} MB</p><p v-if="!resolvedAttachments.enabled" class="cap-warning">已关闭附件上传;长文本也不能转为文件发送。普通文本仍可使用。</p><details class="cap-settings"><summary><span><strong>调整文件限制</strong><small>文件数量、大小与类型</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><div class="cap-form-grid">
|
||||
<label class="text-xs text-gray-700 dark:text-gray-300">一次最多几个文件
|
||||
<input type="number" min="1" max="32" :value="resolvedAttachments.max_count" @change="updateAttachmentLimit('max_count', $event.target.value, 32)" class="mt-1 w-full border dark:border-gray-600 rounded-md px-3 py-2 bg-white dark:bg-gray-700">
|
||||
</label>
|
||||
<label class="text-xs text-gray-700 dark:text-gray-300">单个文件大小(MB)
|
||||
<input type="number" min="1" max="100" :value="resolvedAttachments.max_file_mb" @change="updateAttachmentLimit('max_file_mb', $event.target.value, 100)" class="mt-1 w-full border dark:border-gray-600 rounded-md px-3 py-2 bg-white dark:bg-gray-700">
|
||||
</label>
|
||||
<label class="text-xs text-gray-700 dark:text-gray-300">全部文件总大小(MB)
|
||||
<input type="number" min="1" max="200" :value="resolvedAttachments.max_total_mb" @change="updateAttachmentLimit('max_total_mb', $event.target.value, 200)" class="mt-1 w-full border dark:border-gray-600 rounded-md px-3 py-2 bg-white dark:bg-gray-700">
|
||||
</label>
|
||||
|
||||
</div><label class="block text-sm text-gray-700 dark:text-gray-300">允许哪些文件(可选)
|
||||
<input type="text" :value="(resolvedAttachments.allowed_types || []).join(', ')" @change="updateAllowedTypes($event.target.value)" placeholder="例如 .pdf, .docx, image/*" class="mt-1 w-full border dark:border-gray-600 rounded-md px-3 py-2 text-sm font-mono bg-white dark:bg-gray-700">
|
||||
<span class="block mt-1 text-xs text-gray-500 dark:text-gray-400">用逗号分隔文件扩展名或 MIME 类型;留空不额外限制。网站本身仍需支持这些文件。</span>
|
||||
</label><details class="cap-technical"><summary><span><strong>上传兼容与错误识别</strong><small>只有上传失败、需要拖拽或网站提示错误时再调整。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><label class="text-xs text-gray-700 dark:text-gray-300">单附件确认预算(秒)
|
||||
<input type="number" min="1" max="180" :value="resolvedAttachments.ready_timeout" @change="updateAttachmentLimit('ready_timeout', $event.target.value, 180)" class="mt-1 w-full border dark:border-gray-600 rounded-md px-3 py-2 bg-white dark:bg-gray-700">
|
||||
</label>
|
||||
<label class="block text-sm text-gray-700 dark:text-gray-300">网页上的上传错误提示(CSS 选择器)(可选,一行一个)
|
||||
<textarea :value="(resolvedAttachments.error_selectors || []).join('\\n')" @change="updateAttachmentField('error_selectors', $event.target.value.split(/\\n/).map(v => v.trim()).filter(Boolean))" placeholder=".upload-card[data-state=error]" rows="2" class="mt-1 w-full border dark:border-gray-600 rounded-md px-3 py-2 text-sm font-mono bg-white dark:bg-gray-700"></textarea>
|
||||
<span class="block text-xs text-gray-500 dark:text-gray-400">只匹配编辑区内可见的错误节点;命中后立即停止,不把错误预览视为上传成功。</span>
|
||||
</label>
|
||||
<div class="space-y-2">
|
||||
<div class="text-sm font-medium text-gray-800 dark:text-gray-200">尝试上传的顺序 <span class="text-xs font-normal text-gray-500">仅在确认尚未投递时回退</span></div>
|
||||
<div v-for="(transport, index) in orderedTransports" :key="transport.value" class="flex items-center gap-3 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 p-3">
|
||||
<span class="text-xs text-blue-600 dark:text-blue-400">{{ index + 1 }}</span>
|
||||
<div class="flex-1 min-w-0"><div class="text-sm text-gray-800 dark:text-gray-200">{{ transport.label }}</div><p class="text-xs text-gray-500 dark:text-gray-400 mt-1">{{ transport.description }}</p></div>
|
||||
<button type="button" :disabled="index === 0" @click="moveTransport(index, -1)" :aria-label="transport.label + '上移'" class="px-2 py-1 border rounded disabled:opacity-30">↑</button>
|
||||
<button type="button" :disabled="index === orderedTransports.length - 1" @click="moveTransport(index, 1)" :aria-label="transport.label + '下移'" class="px-2 py-1 border rounded disabled:opacity-30">↓</button>
|
||||
<button type="button" @click="toggleTransport(transport.value)" :aria-label="'停用' + transport.label" class="text-xs text-red-600 dark:text-red-400 px-2 py-1">停用</button>
|
||||
</div>
|
||||
<div v-if="!orderedTransports.length" class="text-xs text-red-600 dark:text-red-400">没有启用上传方式,附件将被明确拒绝,不会自动启用其他方式。</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<template v-for="option in transportOptions" :key="option.value">
|
||||
<button v-if="!resolvedAttachments.transport_order.includes(option.value)" type="button" @click="toggleTransport(option.value)" class="border border-dashed border-gray-400 rounded-md text-xs px-3 py-2 text-gray-600 dark:text-gray-300">+ {{ option.label }}</button>
|
||||
</template>
|
||||
</div>
|
||||
<p v-if="resolvedAttachments.transport_order.includes('image_clipboard')" class="text-xs text-amber-700 dark:text-amber-300">已启用有损图片剪贴板兼容。需要原文件保真时,请停用此方式。</p>
|
||||
</div>
|
||||
<details class="text-xs text-gray-600 dark:text-gray-400">
|
||||
<summary class="cursor-pointer font-medium">API 附件格式与兼容说明</summary>
|
||||
<div class="mt-2 space-y-2 leading-5">
|
||||
<p>支持 image_url、OpenAI file / Responses input_file、Anthropic document、input_audio 与音视频 URL。文件 ID、本地路径和 file:// 暂不支持;原始附件内容不会降级为提示词。</p>
|
||||
<pre class="overflow-x-auto p-3 rounded bg-gray-900 text-gray-100">{"type":"file","file":{"filename":"notes.txt","file_data":"data:text/plain;base64,aGVsbG8="}}</pre>
|
||||
<p>通用附件管线的配置存储在当前预设的 file_paste.attachments 中,旧配置无需手动迁移。选择器仍在「元素选择器」,就绪探针在下方「高级附件规则」。MB 按 1024² 字节计算。</p>
|
||||
</div>
|
||||
</details>
|
||||
</div></details></div></details></section>
|
||||
|
||||
<section class="cap-card" :class="{ 'is-enabled': resolvedFilePaste.enabled }" aria-label="长文本处理"><div class="cap-card-header"><span class="cap-icon" v-html="$icons.documentArrowDown"></span><div class="cap-copy"><div class="cap-title-row"><h4>长文本处理</h4><span class="cap-scope">当前预设</span></div><p>文字太长、网页放不下时,选择转成文件、分段发送或中止请求。</p></div><label class="cap-switch"><span class="cap-state" :class="{ 'is-on': resolvedFilePaste.enabled }">{{ resolvedFilePaste.enabled ? '已开启' : '已关闭' }}</span><input role="switch" aria-label="长文本处理" type="checkbox" :checked="resolvedFilePaste.enabled" @change="toggleEnabled" class="cap-switch-input"><i aria-hidden="true"></i></label></div><p class="cap-facts">{{ resolvedFilePaste.enabled ? '超过 ' + resolvedFilePaste.threshold + ' 字符时处理' : '当前不启用额外的长文本处理' }}<template v-if="resolvedFilePaste.enabled"> <i>·</i> {{ longTextStrategy === 'attachment' ? '转成文件' : longTextStrategy === 'chunk' ? '分段发送' : '中止并报错' }}</template></p><details class="cap-settings"><summary><span><strong>设置长文本处理方式</strong><small>长度阈值与超长后的行为</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><p class="cap-inline-help">转成文件需要先允许附件上传。分段发送会逐轮等待,只返回最后一轮回复。</p>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">超过多少字符开始处理</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="resolvedFilePaste.threshold"
|
||||
@input="updateThreshold($event.target.value)"
|
||||
min="1000"
|
||||
max="10000000"
|
||||
step="1000"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm text-right bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">字符</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">超长处理方式</label>
|
||||
<select :value="longTextStrategy"
|
||||
@change="updateLongTextStrategy($event.target.value)"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<option value="attachment">转为附件(共用上传管线)</option>
|
||||
<option value="chunk">分块连续发送</option>
|
||||
<option value="error">直接返回错误</option>
|
||||
</select>
|
||||
<label v-if="longTextStrategy === 'attachment'" class="mt-2 block text-xs text-gray-600 dark:text-gray-400">生成格式
|
||||
<select :value="resolvedFilePaste.temp_file_type" @change="updateTempFileType($event.target.value)" class="ml-2 border rounded px-2 py-1 bg-white dark:bg-gray-700">
|
||||
<option value="txt">TXT(推荐,保留原文)</option><option value="pdf">PDF</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label v-if="resolvedFilePaste.temp_file_type !== 'chunk'" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
||||
{{ resolvedFilePaste.temp_file_type === 'error' ? '错误信息' : '引导文本' }}
|
||||
</label>
|
||||
<input v-if="resolvedFilePaste.temp_file_type !== 'chunk'"
|
||||
type="text"
|
||||
:value="resolvedFilePaste.temp_file_type === 'txt' ? resolvedFilePaste.txt_hint_text : (resolvedFilePaste.temp_file_type === 'pdf' ? resolvedFilePaste.pdf_hint_text : resolvedFilePaste.error_hint_text)"
|
||||
@input="updateHintText($event.target.value)"
|
||||
:placeholder="resolvedFilePaste.temp_file_type === 'error' ? '超过阈值时返回给客户端的错误信息' : '粘贴文件后追加的文字,留空则不追加'"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<div v-else class="min-h-[38px] flex items-center rounded-md border border-blue-200 dark:border-blue-800 bg-blue-50/70 dark:bg-blue-900/20 px-3 py-2 text-xs leading-5 text-blue-700 dark:text-blue-300">
|
||||
自动使用最少块数,并把分块说明计入阈值。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
|
||||
</div>
|
||||
|
||||
<details class="cap-technical"><summary><span><strong>上传后的输入适配</strong><small>只有文件上传后输入框发生变化时再设置。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">上传后稳定等待</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="resolvedFilePaste.post_upload_settle"
|
||||
@input="updateNumberField('post_upload_settle', $event.target.value, 0)"
|
||||
min="0"
|
||||
max="30"
|
||||
step="0.5"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
</div><label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.reacquire_input_after_upload"
|
||||
@change="updateBooleanField('reacquire_input_after_upload', $event.target.checked)">
|
||||
<span>上传完成后重新定位输入框</span>
|
||||
</label>
|
||||
|
||||
<div >
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">上传后输入框的位置(选择器)</label>
|
||||
<input type="text"
|
||||
:value="resolvedFilePaste.post_upload_input_selector"
|
||||
@input="updateTextField('post_upload_input_selector', $event.target.value)"
|
||||
placeholder=".composer textarea"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
</div>
|
||||
</div></details></div></details></section>
|
||||
|
||||
<details class="cap-troubleshoot"><summary><span><strong>附件上传了,但没有发出去?</strong><small>排查发送确认、重试和网页识别规则。正常发送时无需调整。</small></span><span class="cap-summary-value">敏感度:{{ attachmentSensitivityMeta.label }}</span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><p class="cap-inline-help">这些规则会影响所有附件。先确认网页上是否真的发出了消息,再调整等待或重试。</p>
|
||||
|
||||
<div class="mt-3 grid grid-cols-1 md:grid-cols-3 gap-3 items-start">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">敏感度</label>
|
||||
<select :value="resolvedFilePaste.send_confirmation.attachment_sensitivity"
|
||||
@change="updateSendConfirmationField('attachment_sensitivity', $event.target.value)"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<option v-for="option in attachmentSensitivityOptions"
|
||||
:key="option.value"
|
||||
:value="option.value">
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="md:col-span-2 text-xs leading-6 text-gray-600 dark:text-gray-300 bg-white/70 dark:bg-gray-900/40 rounded-lg border border-blue-100 dark:border-blue-900/60 px-3 py-2">
|
||||
{{ attachmentSensitivityMeta.description }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">最大重试次数</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="resolvedFilePaste.send_confirmation.max_retry_count"
|
||||
@input="updateSendConfirmationField('max_retry_count', parseInt($event.target.value) || 0)"
|
||||
min="0"
|
||||
max="10"
|
||||
step="1"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">次</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">重试间隔</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="resolvedFilePaste.send_confirmation.retry_interval"
|
||||
@input="updateSendConfirmationField('retry_interval', parseFloat($event.target.value) || 0)"
|
||||
min="0"
|
||||
max="30"
|
||||
step="0.1"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">最小冷却窗</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="resolvedFilePaste.send_confirmation.retry_cooldown_window"
|
||||
@input="updateSendConfirmationField('retry_cooldown_window', parseFloat($event.target.value) || 0)"
|
||||
min="0"
|
||||
max="30"
|
||||
step="0.1"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">重试前短探测</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="resolvedFilePaste.send_confirmation.pre_retry_probe_window"
|
||||
@input="updateSendConfirmationField('pre_retry_probe_window', parseFloat($event.target.value) || 0)"
|
||||
min="0"
|
||||
max="5"
|
||||
step="0.05"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">自动重试动作</label>
|
||||
<select :value="resolvedFilePaste.send_confirmation.retry_action"
|
||||
@change="updateSendConfirmationField('retry_action', $event.target.value)"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<option value="click_send_btn">点击发送按钮</option>
|
||||
<option value="key_press">按键发送</option>
|
||||
</select>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
某些站点二次点击会把“发送”变成“停止”,这时更适合改成按键发送。
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">重试按键组合</label>
|
||||
<input type="text"
|
||||
:value="resolvedFilePaste.send_confirmation.retry_key_combo"
|
||||
@input="updateSendConfirmationField('retry_key_combo', $event.target.value)"
|
||||
placeholder="Enter / Ctrl+Enter"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
仅在“按键发送”时生效,支持 Enter、Ctrl+Enter、Shift+Enter 等组合。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 border-t border-blue-100 dark:border-blue-900/60 pt-4"
|
||||
:class="sectionCollapsed.advancedRules ? '' : 'space-y-4'">
|
||||
<div class="cursor-pointer select-none -m-2 p-2 rounded-md hover:bg-blue-100/50 dark:hover:bg-blue-900/30 transition-colors" role="button" tabindex="0" :aria-expanded="!sectionCollapsed.advancedRules" @keydown.enter.prevent="toggleSection('advancedRules')" @keydown.space.prevent="toggleSection('advancedRules')" @click="toggleSection('advancedRules')">
|
||||
<div class="flex items-center gap-2 text-sm font-medium text-gray-800 dark:text-gray-100">
|
||||
<span class="w-4 inline-flex justify-center text-gray-400 dark:text-gray-500" v-html="sectionCollapsed.advancedRules ? $icons.chevronDown : $icons.chevronUp"></span>
|
||||
<span>高级附件规则</span>
|
||||
<span v-show="sectionCollapsed.advancedRules" class="text-xs font-normal text-gray-400 dark:text-gray-500">(点击展开)</span>
|
||||
</div>
|
||||
<p v-show="!sectionCollapsed.advancedRules" class="mt-1 text-xs leading-5 text-gray-600 dark:text-gray-300">
|
||||
像 Gemini 这类站点,可以在这里补发送按钮灰态 token、附件预览 selector 和 pending 文案。即使文件粘贴没开,这块也会继续影响图片上传和发送前的附件 gate。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div v-show="!sectionCollapsed.advancedRules" class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.attachment_monitor.require_attachment_present"
|
||||
@change="updateAttachmentMonitorField('require_attachment_present', $event.target.checked)">
|
||||
<span>发送前必须看到附件已挂上页面</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.attachment_monitor.require_upload_signal_before_ready"
|
||||
@change="updateAttachmentMonitorField('require_upload_signal_before_ready', $event.target.checked)">
|
||||
<span>没有观察到上传启动前,不允许判定 ready</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.attachment_monitor.continue_once_on_unconfirmed_send"
|
||||
@change="updateAttachmentMonitorField('continue_once_on_unconfirmed_send', $event.target.checked)">
|
||||
<span>未确认时仍允许继续点一次发送</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.send_confirmation.retry_on_unconfirmed_send"
|
||||
@change="updateSendConfirmationField('retry_on_unconfirmed_send', $event.target.checked)">
|
||||
<span>发送未确认时允许自动重试</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.send_confirmation.retry_block_on_stop_button"
|
||||
@change="updateSendConfirmationField('retry_block_on_stop_button', $event.target.checked)">
|
||||
<span>发送按钮变成 stop 时禁止重试</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.send_confirmation.retry_block_if_generating"
|
||||
@change="updateSendConfirmationField('retry_block_if_generating', $event.target.checked)">
|
||||
<span>页面进入生成态时禁止重试</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.send_confirmation.accept_attachment_change"
|
||||
@change="updateSendConfirmationField('accept_attachment_change', $event.target.checked)">
|
||||
<span>发送后附件区发生变化时可视为已接受</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.send_confirmation.accept_attachment_disappear"
|
||||
@change="updateSendConfirmationField('accept_attachment_disappear', $event.target.checked)">
|
||||
<span>发送后附件区消失时可视为已接受</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.send_confirmation.accept_probe_confirmation"
|
||||
@change="updateSendConfirmationField('accept_probe_confirmation', $event.target.checked)">
|
||||
<span>允许 JS probe 直接确认发送成功</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div v-show="!sectionCollapsed.advancedRules" class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">空闲超时</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="resolvedFilePaste.attachment_monitor.idle_timeout"
|
||||
@input="updateAttachmentMonitorField('idle_timeout', parseFloat($event.target.value) || 8)"
|
||||
min="0.5"
|
||||
max="60"
|
||||
step="0.5"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">附件最长等待</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="resolvedFilePaste.attachment_monitor.hard_max_wait"
|
||||
@input="updateAttachmentMonitorField('hard_max_wait', parseFloat($event.target.value) || 90)"
|
||||
min="1"
|
||||
max="300"
|
||||
step="1"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-show="!sectionCollapsed.advancedRules" class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">附件预览 selector</label>
|
||||
<textarea
|
||||
:value="attachmentMonitorDrafts ? (attachmentMonitorDrafts.attachment_selectors ?? '') : ''"
|
||||
@input="updateAttachmentMonitorListField('attachment_selectors', $event.target.value)"
|
||||
rows="5"
|
||||
placeholder="[class*='attachment'] .upload-preview"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent"></textarea>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">每行一个 selector,选择独立附件卡片,不要选择包含输入框的大容器;嵌套图片不会重复计数。</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">上传中 selector</label>
|
||||
<textarea
|
||||
:value="attachmentMonitorDrafts ? (attachmentMonitorDrafts.pending_selectors ?? '') : ''"
|
||||
@input="updateAttachmentMonitorListField('pending_selectors', $event.target.value)"
|
||||
rows="5"
|
||||
placeholder="[aria-busy='true'] .uploading"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent"></textarea>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">每行一个 selector,命中后会继续等待,不会急着发送。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-show="!sectionCollapsed.advancedRules" class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">忙碌文本 / token</label>
|
||||
<textarea
|
||||
:value="attachmentMonitorDrafts ? (attachmentMonitorDrafts.busy_text_markers ?? '') : ''"
|
||||
@input="updateAttachmentMonitorListField('busy_text_markers', $event.target.value)"
|
||||
rows="5"
|
||||
placeholder="uploading 处理中 解析中"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent"></textarea>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">只匹配附件状态提示和发送按钮,不扫描提示词、文件名或文件预览正文。</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">发送按钮灰态 token</label>
|
||||
<textarea
|
||||
:value="attachmentMonitorDrafts ? (attachmentMonitorDrafts.send_button_disabled_markers ?? '') : ''"
|
||||
@input="updateAttachmentMonitorListField('send_button_disabled_markers', $event.target.value)"
|
||||
rows="5"
|
||||
placeholder="is-disabled cursor-not-allowed upload failed"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent"></textarea>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">填发送按钮 class / title / aria-label 里会出现的关键字,命中后视为按钮不可发。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-show="!sectionCollapsed.advancedRules" class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">附件状态提示区域(可选)
|
||||
<textarea :value="attachmentMonitorDrafts ? (attachmentMonitorDrafts.status_selectors ?? '') : ''"
|
||||
@input="updateAttachmentMonitorListField('status_selectors', $event.target.value)" rows="3" placeholder=".attachment-status"
|
||||
class="mt-1 w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700"></textarea>
|
||||
<span class="block mt-1 text-xs font-normal text-gray-500">只选择显示“读取中 / 上传中”等状态的小区域,不要选择整张卡片或输入框。</span>
|
||||
</label>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">不参与附件检测的内容区域(可选)
|
||||
<textarea :value="attachmentMonitorDrafts ? (attachmentMonitorDrafts.content_exclusion_selectors ?? '') : ''"
|
||||
@input="updateAttachmentMonitorListField('content_exclusion_selectors', $event.target.value)" rows="3" placeholder=".document-preview-content"
|
||||
class="mt-1 w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700"></textarea>
|
||||
<span class="block mt-1 text-xs font-normal text-gray-500">补充站点特有的正文镜像或文件内容预览区域;隐藏内容、输入框和常见文件名区域已自动排除。</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div v-show="!sectionCollapsed.advancedRules">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">忽略忙碌文本 / token</label>
|
||||
<textarea
|
||||
:value="attachmentMonitorDrafts ? (attachmentMonitorDrafts.ignored_busy_text_markers ?? '') : ''"
|
||||
@input="updateAttachmentMonitorListField('ignored_busy_text_markers', $event.target.value)"
|
||||
rows="3"
|
||||
placeholder="thinking"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent"></textarea>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">仅用于排除站点特有的状态词。正文与文件名会自动排除,不需要在这里逐个添加。</p>
|
||||
</div>
|
||||
|
||||
<div v-show="!sectionCollapsed.advancedRules">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">根容器 selector</label>
|
||||
<textarea
|
||||
:value="attachmentMonitorDrafts ? (attachmentMonitorDrafts.root_selectors ?? '') : ''"
|
||||
@input="updateAttachmentMonitorListField('root_selectors', $event.target.value)"
|
||||
rows="4"
|
||||
placeholder=".composer-shell .input-area"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent"></textarea>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">当通用根容器猜错时再填。这里会限制附件节点和 pending 节点的查找范围。</p>
|
||||
</div>
|
||||
|
||||
<div v-show="!sectionCollapsed.advancedRules" class="border-t border-blue-100 dark:border-blue-900/60 pt-4 space-y-3">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-800 dark:text-gray-100">JS 状态探针</div>
|
||||
<p class="mt-1 text-xs leading-5 text-gray-600 dark:text-gray-300">
|
||||
探针会收到一个参数对象,包含 stage 和 monitorState。返回结构建议包含 uploading、ready、accepted、confirmed、retry、shouldRetry、summary 这些字段。
|
||||
</p>
|
||||
</div>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="resolvedFilePaste.state_probe.enabled"
|
||||
@change="updateStateProbeField('enabled', $event.target.checked)">
|
||||
<span>启用</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">探针代码</label>
|
||||
<textarea
|
||||
:value="resolvedFilePaste.state_probe.code"
|
||||
@input="updateStateProbeField('code', $event.target.value)"
|
||||
rows="10"
|
||||
placeholder="return (() => { const { stage, monitorState } = arguments[0] || {}; return { accepted: false, shouldRetry: false, summary: stage }; })();"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div></details>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
};
|
||||
@@ -0,0 +1,749 @@
|
||||
// ==================== 多模态提取配置面板 ====================
|
||||
|
||||
window.ImageConfigPanel = {
|
||||
name: 'ImageConfigPanel',
|
||||
props: {
|
||||
imageConfig: { type: Object, required: true },
|
||||
currentDomain: { type: String, default: null },
|
||||
collapsed: { type: Boolean, default: true }
|
||||
},
|
||||
emits: ['update:collapsed', 'update-image-config', 'reload-config'],
|
||||
data() {
|
||||
return {
|
||||
showPresetMenu: false,
|
||||
availablePresets: [],
|
||||
currentPreset: null,
|
||||
loadingPresets: false,
|
||||
imagePresetRequestSeq: 0,
|
||||
srcAllowPatternsDraft: '',
|
||||
audioNetworkUrlPatternsDraft: ''
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
modalityPolicies() {
|
||||
return {
|
||||
image: this.normalizeModalityPolicy('image', (this.imageConfig.modalities || {}).image),
|
||||
audio: this.normalizeModalityPolicy('audio', (this.imageConfig.modalities || {}).audio),
|
||||
video: this.normalizeModalityPolicy('video', (this.imageConfig.modalities || {}).video)
|
||||
};
|
||||
},
|
||||
modalities() {
|
||||
return {
|
||||
image: !!this.modalityPolicies.image.enabled,
|
||||
audio: !!this.modalityPolicies.audio.enabled,
|
||||
video: !!this.modalityPolicies.video.enabled
|
||||
};
|
||||
},
|
||||
isEnabled() {
|
||||
return ['image', 'audio', 'video'].some(key => !!this.modalities[key]);
|
||||
},
|
||||
enabledLabels() {
|
||||
const labels = [];
|
||||
if (this.modalities.image) labels.push('图片');
|
||||
if (this.modalities.audio) labels.push('音频');
|
||||
if (this.modalities.video) labels.push('视频');
|
||||
return labels;
|
||||
},
|
||||
srcAllowPatternsText() {
|
||||
const patterns = Array.isArray(this.imageConfig.src_allow_patterns)
|
||||
? this.imageConfig.src_allow_patterns
|
||||
: [];
|
||||
return patterns.join('\n');
|
||||
},
|
||||
audioNetworkCapture() {
|
||||
return {
|
||||
enabled: false,
|
||||
timeout_seconds: 2.5,
|
||||
transport: 'page_websocket_probe',
|
||||
url_patterns: ['voicegenie', 'speech', 'audio', 'tts'],
|
||||
// 修复:默认值与后端 get_default_*(voicegenie_binary_stream)对齐
|
||||
extractor: 'voicegenie_binary_stream',
|
||||
settle_seconds: 0.35,
|
||||
max_payload_bytes: 10 * 1024 * 1024,
|
||||
...((this.imageConfig && this.imageConfig.audio_network_capture) || {})
|
||||
};
|
||||
},
|
||||
audioNetworkMaxPayloadMb() {
|
||||
const raw = Number(this.audioNetworkCapture.max_payload_bytes || 0);
|
||||
const fallback = Number(this.imageConfig.max_size_mb || 10);
|
||||
if (!Number.isFinite(raw) || raw <= 0) return fallback;
|
||||
return Math.round((raw / 1024 / 1024) * 10) / 10;
|
||||
},
|
||||
audioNetworkUrlPatternsText() {
|
||||
const patterns = Array.isArray(this.audioNetworkCapture.url_patterns)
|
||||
? this.audioNetworkCapture.url_patterns
|
||||
: [];
|
||||
return patterns.join('\n');
|
||||
},
|
||||
audioCaptureEnabled() {
|
||||
return this.imageConfig.audio_capture_enabled !== false;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
imageConfig: {
|
||||
handler() {
|
||||
this.syncDraftsFromProps();
|
||||
},
|
||||
deep: true,
|
||||
immediate: true
|
||||
},
|
||||
currentDomain(newVal) {
|
||||
this.imagePresetRequestSeq += 1;
|
||||
this.currentPreset = null;
|
||||
if (newVal) this.checkCurrentPreset();
|
||||
this.syncDraftsFromProps(true);
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.loadPresets();
|
||||
if (this.currentDomain) this.checkCurrentPreset();
|
||||
this.syncDraftsFromProps(true);
|
||||
},
|
||||
methods: {
|
||||
mediaPolicyLabel(type) {
|
||||
const labels = { disabled: '不提取', generic_only: '读取现成媒体', on_signal: '发现媒体信号时提取', probe_if_trigger_found: '发现播放入口后探测', always_probe: '每次主动探测' };
|
||||
return labels[this.modalityPolicies[type].run_policy] || this.modalityPolicies[type].run_policy;
|
||||
},
|
||||
buildAuthHeaders(extraHeaders = {}) {
|
||||
const token = String(window.getDashboardAuthToken ? window.getDashboardAuthToken() : '').trim();
|
||||
const headers = { ...extraHeaders };
|
||||
if (token) {
|
||||
headers['Authorization'] = 'Bearer ' + token;
|
||||
}
|
||||
return headers;
|
||||
},
|
||||
|
||||
toggle() {
|
||||
this.$emit('update:collapsed', !this.collapsed);
|
||||
},
|
||||
|
||||
buildNextConfig(patch = {}) {
|
||||
const nextModalities = {
|
||||
...this.modalityPolicies
|
||||
};
|
||||
if (patch && patch.modalities && typeof patch.modalities === 'object') {
|
||||
for (const type of ['image', 'audio', 'video']) {
|
||||
if (Object.prototype.hasOwnProperty.call(patch.modalities, type)) {
|
||||
nextModalities[type] = this.normalizeModalityPolicy(
|
||||
type,
|
||||
patch.modalities[type],
|
||||
nextModalities[type]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
const next = {
|
||||
...this.imageConfig,
|
||||
...patch,
|
||||
modalities: nextModalities
|
||||
};
|
||||
next.enabled = ['image', 'audio', 'video'].some(key => !!(next.modalities[key] && next.modalities[key].enabled));
|
||||
return next;
|
||||
},
|
||||
|
||||
updateField(field, value) {
|
||||
const newConfig = this.buildNextConfig({ [field]: value });
|
||||
this.$emit('update-image-config', newConfig);
|
||||
},
|
||||
|
||||
numberOrFallback(value, fallback) {
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : fallback;
|
||||
},
|
||||
|
||||
defaultModalityPolicy(type, enabled = false) {
|
||||
const base = {
|
||||
enabled: !!enabled,
|
||||
run_policy: enabled ? 'on_signal' : 'disabled',
|
||||
quick_probe_timeout_seconds: 1.0
|
||||
};
|
||||
if (type === 'audio') {
|
||||
return {
|
||||
...base,
|
||||
run_policy: enabled ? 'probe_if_trigger_found' : 'disabled',
|
||||
capture_timeout_seconds: 12.0
|
||||
};
|
||||
}
|
||||
if (type === 'video') {
|
||||
return {
|
||||
...base,
|
||||
late_wait_timeout_seconds: 90.0
|
||||
};
|
||||
}
|
||||
return {
|
||||
...base,
|
||||
late_wait_timeout_seconds: 45.0,
|
||||
blind_wait_timeout_seconds: 1.0
|
||||
};
|
||||
},
|
||||
|
||||
normalizeModalityPolicy(type, value, fallback = null) {
|
||||
const current = fallback || this.defaultModalityPolicy(type, false);
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
const enabled = !!value.enabled;
|
||||
const allowedPolicies = ['disabled', 'generic_only', 'on_signal', 'probe_if_trigger_found', 'always_probe'];
|
||||
let runPolicy = String(value.run_policy || current.run_policy || '').trim();
|
||||
if (!allowedPolicies.includes(runPolicy)) {
|
||||
runPolicy = enabled ? this.defaultModalityPolicy(type, true).run_policy : 'disabled';
|
||||
}
|
||||
if (!enabled) {
|
||||
runPolicy = 'disabled';
|
||||
}
|
||||
return {
|
||||
...this.defaultModalityPolicy(type, enabled),
|
||||
...current,
|
||||
...value,
|
||||
enabled,
|
||||
run_policy: runPolicy
|
||||
};
|
||||
}
|
||||
return this.defaultModalityPolicy(type, !!value);
|
||||
},
|
||||
|
||||
updateModalityPolicy(type, patch = {}) {
|
||||
const current = this.modalityPolicies[type] || this.defaultModalityPolicy(type, false);
|
||||
const nextPolicy = this.normalizeModalityPolicy(type, { ...current, ...(patch || {}) }, current);
|
||||
this.updateField('modalities', {
|
||||
...this.modalityPolicies,
|
||||
[type]: nextPolicy
|
||||
});
|
||||
},
|
||||
|
||||
parsePatternLines(text) {
|
||||
return String(text || '')
|
||||
.split(/\r?\n/)
|
||||
.map(line => line.trim())
|
||||
.filter(Boolean);
|
||||
},
|
||||
|
||||
syncDraftsFromProps(force = false) {
|
||||
const srcArr = Array.isArray(this.imageConfig?.src_allow_patterns)
|
||||
? this.imageConfig.src_allow_patterns
|
||||
: [];
|
||||
const curSrcArr = this.parsePatternLines(this.srcAllowPatternsDraft);
|
||||
if (force || JSON.stringify(srcArr) !== JSON.stringify(curSrcArr) || this.srcAllowPatternsDraft === undefined || this.srcAllowPatternsDraft === null) {
|
||||
this.srcAllowPatternsDraft = srcArr.join('\n');
|
||||
}
|
||||
|
||||
const audioArr = Array.isArray(this.audioNetworkCapture?.url_patterns)
|
||||
? this.audioNetworkCapture.url_patterns
|
||||
: [];
|
||||
const curAudioArr = this.parsePatternLines(this.audioNetworkUrlPatternsDraft);
|
||||
if (force || JSON.stringify(audioArr) !== JSON.stringify(curAudioArr) || this.audioNetworkUrlPatternsDraft === undefined || this.audioNetworkUrlPatternsDraft === null) {
|
||||
this.audioNetworkUrlPatternsDraft = audioArr.join('\n');
|
||||
}
|
||||
},
|
||||
|
||||
updateSrcAllowPatterns(text) {
|
||||
this.srcAllowPatternsDraft = text;
|
||||
const patterns = this.parsePatternLines(text);
|
||||
this.updateField('src_allow_patterns', patterns);
|
||||
},
|
||||
|
||||
updateAudioNetworkCapture(patch = {}) {
|
||||
const nextConfig = {
|
||||
...this.audioNetworkCapture,
|
||||
...(patch || {})
|
||||
};
|
||||
this.updateField('audio_network_capture', nextConfig);
|
||||
},
|
||||
|
||||
updateAudioNetworkUrlPatterns(text) {
|
||||
this.audioNetworkUrlPatternsDraft = text;
|
||||
const patterns = this.parsePatternLines(text);
|
||||
this.updateAudioNetworkCapture({ url_patterns: patterns });
|
||||
},
|
||||
|
||||
toggleModality(type) {
|
||||
const enabled = !this.modalities[type];
|
||||
this.updateModalityPolicy(type, {
|
||||
enabled,
|
||||
run_policy: enabled ? this.defaultModalityPolicy(type, true).run_policy : 'disabled'
|
||||
});
|
||||
},
|
||||
|
||||
modalityCardClass(type) {
|
||||
return this.modalities[type]
|
||||
? 'border-blue-400 bg-blue-50 dark:bg-blue-900/20 dark:border-blue-500/50'
|
||||
: 'border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/40';
|
||||
},
|
||||
|
||||
inputWrapClass(enabled) {
|
||||
return enabled ? '' : 'opacity-50';
|
||||
},
|
||||
|
||||
async loadPresets() {
|
||||
if (this.loadingPresets) return;
|
||||
this.loadingPresets = true;
|
||||
try {
|
||||
const response = await fetch('/api/image-presets', {
|
||||
headers: this.buildAuthHeaders()
|
||||
});
|
||||
if (!response.ok) {
|
||||
const err = await response.json().catch(() => ({}));
|
||||
throw new Error(err.detail || ('HTTP ' + response.status));
|
||||
}
|
||||
const data = await response.json();
|
||||
this.availablePresets = data.presets || [];
|
||||
} catch (e) {
|
||||
console.error('加载预设失败:', e);
|
||||
} finally {
|
||||
this.loadingPresets = false;
|
||||
}
|
||||
},
|
||||
|
||||
async checkCurrentPreset() {
|
||||
const domain = String(this.currentDomain || '').trim();
|
||||
const requestSeq = Number(this.imagePresetRequestSeq || 0) + 1;
|
||||
this.imagePresetRequestSeq = requestSeq;
|
||||
if (!domain) {
|
||||
this.currentPreset = null;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch('/api/sites/' + encodeURIComponent(domain) + '/image-preset', {
|
||||
headers: this.buildAuthHeaders()
|
||||
});
|
||||
if (!response.ok) {
|
||||
const err = await response.json().catch(() => ({}));
|
||||
throw new Error(err.detail || ('HTTP ' + response.status));
|
||||
}
|
||||
const data = await response.json();
|
||||
if (requestSeq !== this.imagePresetRequestSeq || String(this.currentDomain || '').trim() !== domain) {
|
||||
return;
|
||||
}
|
||||
this.currentPreset = data.available ? data : null;
|
||||
} catch (e) {
|
||||
if (requestSeq !== this.imagePresetRequestSeq || String(this.currentDomain || '').trim() !== domain) {
|
||||
return;
|
||||
}
|
||||
console.error('读取当前图片预设失败:', e);
|
||||
this.currentPreset = null;
|
||||
}
|
||||
},
|
||||
|
||||
async applyPreset(presetDomain) {
|
||||
if (!this.currentDomain) return;
|
||||
try {
|
||||
const response = await fetch('/api/sites/' + encodeURIComponent(this.currentDomain) + '/apply-image-preset', {
|
||||
method: 'POST',
|
||||
headers: this.buildAuthHeaders({ 'Content-Type': 'application/json' }),
|
||||
body: JSON.stringify({ preset_domain: presetDomain })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const err = await response.json().catch(() => ({}));
|
||||
throw new Error(err.detail || ('HTTP ' + response.status));
|
||||
}
|
||||
|
||||
this.showPresetMenu = false;
|
||||
this.$emit('reload-config');
|
||||
await this.checkCurrentPreset();
|
||||
} catch (e) {
|
||||
alert('应用预设失败: ' + e.message);
|
||||
}
|
||||
},
|
||||
|
||||
togglePresetMenu(e) {
|
||||
e.stopPropagation();
|
||||
this.showPresetMenu = !this.showPresetMenu;
|
||||
if (this.showPresetMenu && this.availablePresets.length === 0) {
|
||||
this.loadPresets();
|
||||
}
|
||||
},
|
||||
|
||||
closeMenu() {
|
||||
this.showPresetMenu = false;
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="cap-panel cap-media-panel bg-white dark:bg-gray-800 border dark:border-gray-700 rounded-lg shadow-sm" @click="closeMenu">
|
||||
<div class="px-4 py-3 border-b dark:border-gray-700 flex justify-between items-center cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors"
|
||||
@click="toggle">
|
||||
<div class="flex items-center gap-2 flex-wrap">
|
||||
<span class="w-4 inline-flex justify-center text-gray-500 dark:text-gray-400" v-html="collapsed ? $icons.chevronDown : $icons.chevronUp"></span>
|
||||
<h3 class="font-semibold text-gray-900 dark:text-white">更改会自动保存</h3>
|
||||
<span v-if="isEnabled" class="px-2 py-0.5 text-xs bg-green-100 dark:bg-green-900/50 text-green-700 dark:text-green-300 rounded font-medium">已启用</span>
|
||||
<span v-else class="px-2 py-0.5 text-xs bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400 rounded">未启用</span>
|
||||
<span v-for="label in enabledLabels" :key="label"
|
||||
class="px-2 py-0.5 text-xs bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-300 rounded font-medium">
|
||||
{{ label }}
|
||||
</span>
|
||||
<span v-if="currentPreset && currentPreset.available"
|
||||
class="px-2 py-0.5 text-xs bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-300 rounded font-medium flex items-center gap-1">
|
||||
<svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20"><path d="M10 2a6 6 0 00-6 6v3.586l-.707.707A1 1 0 004 14h12a1 1 0 00.707-1.707L16 11.586V8a6 6 0 00-6-6zM10 18a3 3 0 01-3-3h6a3 3 0 01-3 3z"/></svg>
|
||||
预设
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2" @click.stop>
|
||||
<div class="relative">
|
||||
<button @click="togglePresetMenu"
|
||||
class="px-3 py-1.5 text-sm font-medium text-gray-700 dark:text-gray-200 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors flex items-center gap-1">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
||||
</svg>
|
||||
站点规则模板
|
||||
</button>
|
||||
|
||||
<div v-if="showPresetMenu" class="absolute right-0 mt-1 w-80 max-h-96 overflow-y-auto bg-white dark:bg-gray-800 border dark:border-gray-700 rounded-lg shadow-lg z-10">
|
||||
<div v-if="currentPreset && currentPreset.available" class="px-3 py-2 bg-blue-50 dark:bg-blue-900/30 border-b dark:border-gray-700 text-xs text-blue-700 dark:text-blue-300">
|
||||
<div class="font-medium">当前使用的媒体规则模板</div>
|
||||
<div class="mt-0.5">{{ currentPreset.name }}</div>
|
||||
</div>
|
||||
<div v-if="loadingPresets" class="px-3 py-6 text-center text-sm text-gray-400">加载中...</div>
|
||||
<div v-else-if="availablePresets.length > 0" class="divide-y dark:divide-gray-700">
|
||||
<div class="px-3 py-1.5 bg-gray-50 dark:bg-gray-900/50 text-xs font-medium text-gray-500">站点预设</div>
|
||||
<button v-for="preset in availablePresets" :key="preset.domain"
|
||||
@click="applyPreset(preset.domain)"
|
||||
class="w-full text-left px-3 py-2.5 hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors">
|
||||
<div class="font-medium text-sm text-gray-900 dark:text-white truncate">{{ preset.name }}</div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400 mt-0.5">{{ preset.domain }}</div>
|
||||
</button>
|
||||
</div>
|
||||
<div v-else class="px-3 py-6 text-center text-sm text-gray-400">暂无可用预设</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-show="!collapsed" class="p-4 space-y-4">
|
||||
<div>
|
||||
|
||||
<div class="cap-feature-stack">
|
||||
<section class="cap-card" :class="{ 'is-enabled': modalities.image }" aria-label="接收图片"><div class="cap-card-header"><span class="cap-icon" v-html="$icons.photo"></span><div class="cap-copy"><div class="cap-title-row"><h4>接收图片</h4><span class="cap-scope">当前预设</span></div><p>把 AI 回复里的图片带回客户端。</p></div><label class="cap-switch"><span class="cap-state" :class="{ 'is-on': modalities.image }">{{ modalities.image ? '已开启' : '已关闭' }}</span><input role="switch" aria-label="接收图片" type="checkbox" :checked="modalities.image" @change="toggleModality('image')" class="cap-switch-input"><i aria-hidden="true"></i></label></div><p v-if="modalities.image" class="cap-facts">{{ modalities.image ? '当前方式:' + mediaPolicyLabel('image') : '已关闭,不提取这类媒体' }}</p><details class="cap-settings"><summary><span><strong>配置图片提取</strong><small>识别位置与提取时机</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><p class="cap-inline-help">开启上方开关后,可调整识别位置与提取方式。关闭不会清空识别位置和等待参数。</p><div class="cap-form-grid"><div :class="inputWrapClass(modalities.image)">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">图片选择器</label>
|
||||
<input type="text" :value="imageConfig.selector" @input="updateField('selector', $event.target.value)" placeholder="img"
|
||||
:disabled="!modalities.image"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed">
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">默认 <code>img</code></p>
|
||||
</div><div>
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">什么时候提取</label>
|
||||
<select :disabled="!modalities.image" :value="modalityPolicies.image.run_policy"
|
||||
@change="updateModalityPolicy('image', { run_policy: $event.target.value, enabled: $event.target.value !== 'disabled' })"
|
||||
class="w-full border dark:border-gray-600 px-2 py-1.5 rounded-md text-xs bg-white dark:bg-gray-700 text-gray-900 dark:text-white">
|
||||
<option value="disabled">不提取</option>
|
||||
<option value="generic_only">只读取现成的媒体</option>
|
||||
<option value="on_signal">发现媒体信号时提取</option>
|
||||
<!-- 修复:补齐后端 MODALITY_RUN_POLICY_VALUES 的第 5 个枚举 -->
|
||||
<option value="probe_if_trigger_found">发现播放入口后探测</option>
|
||||
<option value="always_probe">每次主动探测</option>
|
||||
</select>
|
||||
</div></div><details class="cap-technical"><summary><span><strong>提取不完整或等待太久?</strong><small>调整等待时间与特殊站点的兼容规则。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><div class="cap-form-grid">
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">快速查找时长(秒)</label>
|
||||
<input type="number"
|
||||
:value="modalityPolicies.image.quick_probe_timeout_seconds"
|
||||
@input="updateModalityPolicy('image', { quick_probe_timeout_seconds: numberOrFallback($event.target.value, 1) })"
|
||||
min="0.1" max="10" step="0.1"
|
||||
:disabled="!modalities.image"
|
||||
class="w-full border dark:border-gray-600 px-2 py-1.5 rounded-md text-xs bg-white dark:bg-gray-700 text-gray-900 dark:text-white disabled:opacity-50">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">最长等待(秒)</label>
|
||||
<input type="number"
|
||||
:value="modalityPolicies.image.late_wait_timeout_seconds"
|
||||
@input="updateModalityPolicy('image', { late_wait_timeout_seconds: numberOrFallback($event.target.value, 45) })"
|
||||
min="0.2" max="300" step="1"
|
||||
:disabled="!modalities.image || modalityPolicies.image.run_policy === 'generic_only'"
|
||||
class="w-full border dark:border-gray-600 px-2 py-1.5 rounded-md text-xs bg-white dark:bg-gray-700 text-gray-900 dark:text-white disabled:opacity-50">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">没有加载提示时等待(秒)</label>
|
||||
<input type="number"
|
||||
:value="modalityPolicies.image.blind_wait_timeout_seconds"
|
||||
@input="updateModalityPolicy('image', { blind_wait_timeout_seconds: numberOrFallback($event.target.value, 1) })"
|
||||
min="0" max="300" step="0.5"
|
||||
:disabled="!modalities.image || modalityPolicies.image.run_policy === 'generic_only'"
|
||||
class="w-full border dark:border-gray-600 px-2 py-1.5 rounded-md text-xs bg-white dark:bg-gray-700 text-gray-900 dark:text-white disabled:opacity-50">
|
||||
</div>
|
||||
<div :class="inputWrapClass(modalities.image)">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">图片来源白名单 <span class="text-gray-400 font-normal">(可选)</span></label>
|
||||
<textarea :value="srcAllowPatternsDraft" @input="updateSrcAllowPatterns($event.target.value)" rows="5"
|
||||
placeholder="^data:image/ ^blob: ^https?://[^/]*oaiusercontent\.com/ ^https?://[^/]*oaistatic\.com/ ^https?://cdn\.openai\.com/"
|
||||
:disabled="!modalities.image"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed"></textarea>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">每行一个正则,仅提取匹配这些 <code>src</code> 的图片。留空表示不过滤。</p>
|
||||
</div><div :class="inputWrapClass(modalities.image)" class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Canvas 导出格式</label>
|
||||
<select :value="imageConfig.canvas_export_mime || 'image/jpeg'"
|
||||
@change="updateField('canvas_export_mime', $event.target.value)"
|
||||
:disabled="!modalities.image"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed">
|
||||
<option value="image/jpeg">JPEG</option>
|
||||
<option value="image/webp">WebP</option>
|
||||
<option value="image/png">PNG</option>
|
||||
</select>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">用于 blob 图片 Canvas 兜底导出。JPEG/WebP 体积更小。</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">Canvas 导出质量</label>
|
||||
<input type="number"
|
||||
:value="imageConfig.canvas_export_quality === undefined ? 0.88 : imageConfig.canvas_export_quality"
|
||||
@input="updateField('canvas_export_quality', numberOrFallback($event.target.value, 0.88))"
|
||||
min="0.1" max="1" step="0.01"
|
||||
:disabled="!modalities.image || (imageConfig.canvas_export_mime || 'image/jpeg') === 'image/png'"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:opacity-50 disabled:cursor-not-allowed">
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">仅 JPEG/WebP 生效,建议 0.80-0.92。</p>
|
||||
</div>
|
||||
</div></div></details></div></details></section>
|
||||
|
||||
<section class="cap-card" :class="{ 'is-enabled': modalities.audio }" aria-label="接收音频"><div class="cap-card-header"><span class="cap-icon" v-html="$icons.activity"></span><div class="cap-copy"><div class="cap-title-row"><h4>接收音频</h4><span class="cap-scope">当前预设</span></div><p>把 AI 回复里的声音文件带回客户端。</p></div><label class="cap-switch"><span class="cap-state" :class="{ 'is-on': modalities.audio }">{{ modalities.audio ? '已开启' : '已关闭' }}</span><input role="switch" aria-label="接收音频" type="checkbox" :checked="modalities.audio" @change="toggleModality('audio')" class="cap-switch-input"><i aria-hidden="true"></i></label></div><p v-if="modalities.audio" class="cap-facts">{{ modalities.audio ? '当前方式:' + mediaPolicyLabel('audio') : '已关闭,不提取这类媒体' }}</p><details class="cap-settings"><summary><span><strong>配置音频提取</strong><small>识别位置与提取时机</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><p class="cap-inline-help">开启上方开关后,可调整识别位置与提取方式。关闭不会清空识别位置和等待参数。</p><div class="cap-form-grid"><div :class="inputWrapClass(modalities.audio)">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">音频选择器</label>
|
||||
<input type="text" :value="imageConfig.audio_selector" @input="updateField('audio_selector', $event.target.value)" placeholder="audio, audio source"
|
||||
:disabled="!modalities.audio"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed">
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">默认 <code>audio, audio source</code></p>
|
||||
</div><div>
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">什么时候提取</label>
|
||||
<select :disabled="!modalities.audio" :value="modalityPolicies.audio.run_policy"
|
||||
@change="updateModalityPolicy('audio', { run_policy: $event.target.value, enabled: $event.target.value !== 'disabled' })"
|
||||
class="w-full border dark:border-gray-600 px-2 py-1.5 rounded-md text-xs bg-white dark:bg-gray-700 text-gray-900 dark:text-white">
|
||||
<option value="disabled">不提取</option>
|
||||
<option value="generic_only">只读取现成的媒体</option>
|
||||
<option value="on_signal">发现媒体信号时提取</option>
|
||||
<option value="probe_if_trigger_found">发现播放入口后探测</option>
|
||||
<option value="always_probe">每次主动探测</option>
|
||||
</select>
|
||||
</div></div><details class="cap-technical"><summary><span><strong>提取不完整或等待太久?</strong><small>调整等待时间与特殊站点的兼容规则。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><div class="cap-form-grid">
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">快速查找时长(秒)</label>
|
||||
<input type="number"
|
||||
:value="modalityPolicies.audio.quick_probe_timeout_seconds"
|
||||
@input="updateModalityPolicy('audio', { quick_probe_timeout_seconds: numberOrFallback($event.target.value, 1) })"
|
||||
min="0.1" max="10" step="0.1"
|
||||
:disabled="!modalities.audio"
|
||||
class="w-full border dark:border-gray-600 px-2 py-1.5 rounded-md text-xs bg-white dark:bg-gray-700 text-gray-900 dark:text-white disabled:opacity-50">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">最长录制时间(秒)</label>
|
||||
<input type="number"
|
||||
:value="modalityPolicies.audio.capture_timeout_seconds"
|
||||
@input="updateModalityPolicy('audio', { capture_timeout_seconds: numberOrFallback($event.target.value, 12) })"
|
||||
min="0.2" max="180" step="0.5"
|
||||
:disabled="!modalities.audio || !['probe_if_trigger_found', 'always_probe', 'on_signal'].includes(modalityPolicies.audio.run_policy)"
|
||||
class="w-full border dark:border-gray-600 px-2 py-1.5 rounded-md text-xs bg-white dark:bg-gray-700 text-gray-900 dark:text-white disabled:opacity-50">
|
||||
</div>
|
||||
</div>
|
||||
<details class="cap-technical"><summary><span><strong>没有音频文件时,尝试捕获声音</strong><small>可能触发页面播放或录音;Gemini 直连提取预设应保持播放录音回退关闭。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><div v-if="modalities.audio" class="border-t dark:border-gray-700 pt-4">
|
||||
<div class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">音频捕获</div>
|
||||
|
||||
<div class="flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-900/50 rounded-lg mb-3">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-700 dark:text-gray-300">页面播放音频捕获回退</div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400">直接提取不到音频时,允许触发页面播放并录制音频。Gemini 直连提取预设应保持关闭。</div>
|
||||
</div>
|
||||
<label class="toggle-label scale-90">
|
||||
<input type="checkbox" aria-label="允许播放并录制音频" :checked="audioCaptureEnabled" @change="updateField('audio_capture_enabled', $event.target.checked)" class="sr-only peer">
|
||||
<div class="toggle-bg"></div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-900/50 rounded-lg">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-700 dark:text-gray-300">启用网络音频捕获</div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400">优先尝试从页面内 WebSocket / 网络流直接提取音频;是否继续回退到页面录音由上方开关控制。</div>
|
||||
</div>
|
||||
<label class="toggle-label scale-90">
|
||||
<input type="checkbox" aria-label="从网络捕获音频" :checked="audioNetworkCapture.enabled" @change="updateAudioNetworkCapture({ enabled: $event.target.checked })" class="sr-only peer">
|
||||
<div class="toggle-bg"></div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div :class="['mt-4 space-y-4', audioNetworkCapture.enabled ? '' : 'opacity-50']">
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">捕获超时 (秒)</label>
|
||||
<input type="number"
|
||||
:value="audioNetworkCapture.timeout_seconds"
|
||||
@input="updateAudioNetworkCapture({ timeout_seconds: numberOrFallback($event.target.value, 2.5) })"
|
||||
min="0.1" max="15" step="0.1"
|
||||
:disabled="!audioNetworkCapture.enabled"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">传输类型</label>
|
||||
<select :value="audioNetworkCapture.transport"
|
||||
@change="updateAudioNetworkCapture({ transport: $event.target.value })"
|
||||
:disabled="!audioNetworkCapture.enabled"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed">
|
||||
<option value="page_websocket_probe">页面 WebSocket Probe</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">提取器</label>
|
||||
<select :value="audioNetworkCapture.extractor"
|
||||
@change="updateAudioNetworkCapture({ extractor: $event.target.value })"
|
||||
:disabled="!audioNetworkCapture.enabled"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed">
|
||||
<option value="voicegenie_ogg_pages">voicegenie_ogg_pages</option>
|
||||
<!-- 修复:补齐后端合法枚举,否则已存该值的预设会渲染成空白 -->
|
||||
<option value="voicegenie_binary_stream">voicegenie_binary_stream</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">稳定等待窗口 (秒)</label>
|
||||
<input type="number"
|
||||
:value="audioNetworkCapture.settle_seconds"
|
||||
@input="updateAudioNetworkCapture({ settle_seconds: numberOrFallback($event.target.value, 0.35) })"
|
||||
min="0.05" max="5" step="0.05"
|
||||
:disabled="!audioNetworkCapture.enabled"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">单条载荷上限 (MB)</label>
|
||||
<input type="number"
|
||||
:value="audioNetworkMaxPayloadMb"
|
||||
@input="updateAudioNetworkCapture({ max_payload_bytes: Math.round(numberOrFallback($event.target.value, 10) * 1024 * 1024) })"
|
||||
min="0.1" max="100" step="0.5"
|
||||
:disabled="!audioNetworkCapture.enabled"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed">
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">超过上限的二进制帧只记录摘要,不回传 Base64。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">URL 匹配关键字</label>
|
||||
<textarea :value="audioNetworkUrlPatternsDraft"
|
||||
@input="updateAudioNetworkUrlPatterns($event.target.value)"
|
||||
rows="4"
|
||||
:disabled="!audioNetworkCapture.enabled"
|
||||
placeholder="voicegenie speech audio tts"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed"></textarea>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">每行一个关键字,命中对应 WebSocket / 网络请求 URL 时才会参与音频聚合。</p>
|
||||
</div>
|
||||
</div>
|
||||
</div></div></details></div></details></div></details></section>
|
||||
|
||||
<section class="cap-card" :class="{ 'is-enabled': modalities.video }" aria-label="接收视频"><div class="cap-card-header"><span class="cap-icon" v-html="$icons.play"></span><div class="cap-copy"><div class="cap-title-row"><h4>接收视频</h4><span class="cap-scope">当前预设</span></div><p>把 AI 回复里的视频文件带回客户端。</p></div><label class="cap-switch"><span class="cap-state" :class="{ 'is-on': modalities.video }">{{ modalities.video ? '已开启' : '已关闭' }}</span><input role="switch" aria-label="接收视频" type="checkbox" :checked="modalities.video" @change="toggleModality('video')" class="cap-switch-input"><i aria-hidden="true"></i></label></div><p v-if="modalities.video" class="cap-facts">{{ modalities.video ? '当前方式:' + mediaPolicyLabel('video') : '已关闭,不提取这类媒体' }}</p><details class="cap-settings"><summary><span><strong>配置视频提取</strong><small>识别位置与提取时机</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><p class="cap-inline-help">开启上方开关后,可调整识别位置与提取方式。关闭不会清空识别位置和等待参数。</p><div class="cap-form-grid"><div :class="inputWrapClass(modalities.video)">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">视频选择器</label>
|
||||
<input type="text" :value="imageConfig.video_selector" @input="updateField('video_selector', $event.target.value)" placeholder="video, video source"
|
||||
:disabled="!modalities.video"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent disabled:cursor-not-allowed">
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">默认 <code>video, video source</code></p>
|
||||
</div><div>
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">什么时候提取</label>
|
||||
<select :disabled="!modalities.video" :value="modalityPolicies.video.run_policy"
|
||||
@change="updateModalityPolicy('video', { run_policy: $event.target.value, enabled: $event.target.value !== 'disabled' })"
|
||||
class="w-full border dark:border-gray-600 px-2 py-1.5 rounded-md text-xs bg-white dark:bg-gray-700 text-gray-900 dark:text-white">
|
||||
<option value="disabled">不提取</option>
|
||||
<option value="generic_only">只读取现成的媒体</option>
|
||||
<option value="on_signal">发现媒体信号时提取</option>
|
||||
<!-- 修复:补齐后端 MODALITY_RUN_POLICY_VALUES 的第 5 个枚举 -->
|
||||
<option value="probe_if_trigger_found">发现播放入口后探测</option>
|
||||
<option value="always_probe">每次主动探测</option>
|
||||
</select>
|
||||
</div></div><details class="cap-technical"><summary><span><strong>提取不完整或等待太久?</strong><small>调整等待时间与特殊站点的兼容规则。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><div class="cap-form-grid">
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">快速查找时长(秒)</label>
|
||||
<input type="number"
|
||||
:value="modalityPolicies.video.quick_probe_timeout_seconds"
|
||||
@input="updateModalityPolicy('video', { quick_probe_timeout_seconds: numberOrFallback($event.target.value, 1) })"
|
||||
min="0.1" max="10" step="0.1"
|
||||
:disabled="!modalities.video"
|
||||
class="w-full border dark:border-gray-600 px-2 py-1.5 rounded-md text-xs bg-white dark:bg-gray-700 text-gray-900 dark:text-white disabled:opacity-50">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1">最长等待(秒)</label>
|
||||
<input type="number"
|
||||
:value="modalityPolicies.video.late_wait_timeout_seconds"
|
||||
@input="updateModalityPolicy('video', { late_wait_timeout_seconds: numberOrFallback($event.target.value, 90) })"
|
||||
min="0.2" max="300" step="1"
|
||||
:disabled="!modalities.video || modalityPolicies.video.run_policy === 'generic_only'"
|
||||
class="w-full border dark:border-gray-600 px-2 py-1.5 rounded-md text-xs bg-white dark:bg-gray-700 text-gray-900 dark:text-white disabled:opacity-50">
|
||||
</div>
|
||||
</div>
|
||||
</div></details></div></details></section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!isEnabled" class="bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 rounded-lg p-3 text-center">
|
||||
<div class="text-gray-500 dark:text-gray-400 text-sm">当前只处理文字回复;需要接收图片、声音或视频时,再开启对应能力。</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<details class="cap-troubleshoot"><summary><span><strong>通用识别与下载规则</strong><small>范围、文件大小和资源转换。现有提取正常时无需改动。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">容器选择器 <span class="text-gray-400 font-normal">(可选)</span></label>
|
||||
<input type="text" :value="imageConfig.container_selector || ''" @input="updateField('container_selector', $event.target.value || null)" placeholder="留空则使用响应容器"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">统一限定媒体查找范围</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">提取模式</label>
|
||||
<select :value="imageConfig.mode" @change="updateField('mode', $event.target.value)"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<option value="all">全部提取</option>
|
||||
<option value="first">仅第一项</option>
|
||||
<option value="last">仅最后一项</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">最大大小 (MB)</label>
|
||||
<!-- 修复:后端取值域是连续区间 1..100,原下拉只有 5/10/20/50,存 100 的预设会渲染空白并被砍到 ≤50 -->
|
||||
<input type="number" :value="imageConfig.max_size_mb"
|
||||
@input="updateField('max_size_mb', numberOrFallback($event.target.value, 10))"
|
||||
min="1" max="100" step="1"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">防抖延迟 (秒)</label>
|
||||
<!-- 修复:parseFloat("0") || 2 恒为 2,用户输 0 关防抖会被写成 2 秒;后端下限是 0 -->
|
||||
<input type="number" :value="imageConfig.debounce_seconds" @input="updateField('debounce_seconds', numberOrFallback($event.target.value, 2))" min="0" max="30" step="0.5"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">加载超时时间 (秒)</label>
|
||||
<input type="number" :value="imageConfig.load_timeout_seconds" @input="updateField('load_timeout_seconds', parseFloat($event.target.value) || 5)"
|
||||
min="1" max="60" step="1" :disabled="!imageConfig.wait_for_load"
|
||||
:class="['w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent', !imageConfig.wait_for_load ? 'opacity-50 cursor-not-allowed' : '']">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="border-t dark:border-gray-700 pt-4">
|
||||
<div class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">高级选项</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div class="flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-900/50 rounded-lg">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-700 dark:text-gray-300">等待媒体加载</div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400">等待音视频或图片完成加载后再提取</div>
|
||||
</div>
|
||||
<label class="toggle-label scale-90">
|
||||
<input type="checkbox" aria-label="等待媒体加载完成" :checked="imageConfig.wait_for_load" @change="updateField('wait_for_load', $event.target.checked)" class="sr-only peer">
|
||||
<div class="toggle-bg"></div>
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-900/50 rounded-lg">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-700 dark:text-gray-300">转换 Blob 媒体</div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400">将 blob: 资源转为可返回的数据 URI 或本地文件</div>
|
||||
</div>
|
||||
<label class="toggle-label scale-90">
|
||||
<input type="checkbox" aria-label="转换临时媒体资源" :checked="imageConfig.download_blobs" @change="updateField('download_blobs', $event.target.checked)" class="sr-only peer">
|
||||
<div class="toggle-bg"></div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div></details> </div>
|
||||
</div>
|
||||
`
|
||||
};
|
||||
@@ -0,0 +1,388 @@
|
||||
/* Scoped transfers: importing never writes the server or touches another site. */
|
||||
(() => {
|
||||
const copy = (x) => JSON.parse(JSON.stringify(x));
|
||||
const object = (x) => !!x && typeof x === "object" && !Array.isArray(x);
|
||||
const safeName = (x) =>
|
||||
typeof x === "string" &&
|
||||
!!x.trim() &&
|
||||
x.length <= 100 &&
|
||||
!["__proto__", "prototype", "constructor"].includes(x);
|
||||
function sources(data, fallbackDomain) {
|
||||
if (!object(data))
|
||||
throw Error("请选择站点或预设 JSON 文件,不是动作数组。");
|
||||
if (data.kind === "workflow")
|
||||
throw Error("这是工作流片段。请在「请求工作流 → 导入工作流」中使用它。");
|
||||
const result = [];
|
||||
const add = (domain, site) => {
|
||||
if (!object(site)) return;
|
||||
const presets = object(site.presets)
|
||||
? site.presets
|
||||
: "workflow" in site || "selectors" in site
|
||||
? { [site.preset_name || "主预设"]: site }
|
||||
: null;
|
||||
if (!presets) return;
|
||||
const clean = {};
|
||||
for (const [name, config] of Object.entries(presets)) {
|
||||
if (!safeName(name) || !object(config))
|
||||
throw Error("文件中存在无效的预设名称或配置对象。");
|
||||
if ("workflow" in config && !Array.isArray(config.workflow))
|
||||
throw Error(name + " 的 workflow 必须是数组。");
|
||||
if ("selectors" in config && !object(config.selectors))
|
||||
throw Error(name + " 的 selectors 必须是对象。");
|
||||
const value = copy(config);
|
||||
if (!object(site.presets)) {
|
||||
delete value.domain;
|
||||
delete value.preset_name;
|
||||
}
|
||||
Object.defineProperty(clean, name, {
|
||||
value,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
if (Object.keys(clean).length)
|
||||
result.push({
|
||||
domain: domain || fallbackDomain,
|
||||
presets: clean,
|
||||
settings: object(site.presets)
|
||||
? Object.fromEntries(
|
||||
Object.entries(site).filter(
|
||||
([k]) =>
|
||||
![
|
||||
"presets",
|
||||
"default_preset",
|
||||
"domain",
|
||||
"preset_name",
|
||||
"format",
|
||||
"version",
|
||||
].includes(k) &&
|
||||
!k.startsWith("_") &&
|
||||
safeName(k),
|
||||
),
|
||||
)
|
||||
: {},
|
||||
});
|
||||
};
|
||||
if (data.format === "universal-web-api/preset" && object(data.config))
|
||||
add(data.domain, {
|
||||
presets: { [data.preset_name || "主预设"]: data.config },
|
||||
});
|
||||
else if ("presets" in data || "workflow" in data || "selectors" in data)
|
||||
add(data.domain, data);
|
||||
else
|
||||
for (const [domain, site] of Object.entries(data))
|
||||
if (!domain.startsWith("_")) add(domain, site);
|
||||
if (!result.length)
|
||||
throw Error("没有找到可导入的站点预设。请选择站点配置或单预设文件。");
|
||||
return result;
|
||||
}
|
||||
window.PresetTransferSupport = { sources, safeName, copy };
|
||||
window.PresetTransfer = {
|
||||
name: "PresetTransfer",
|
||||
props: {
|
||||
domain: String,
|
||||
site: Object,
|
||||
preset: String,
|
||||
prepare: Function,
|
||||
disabled: Boolean,
|
||||
},
|
||||
emits: ["apply"],
|
||||
data: () => ({
|
||||
open: false,
|
||||
mode: "preset",
|
||||
fileName: "",
|
||||
sourceSites: [],
|
||||
sourceIndex: 0,
|
||||
sourcePreset: "",
|
||||
targetName: "",
|
||||
overwrite: false,
|
||||
includeSettings: false,
|
||||
busy: false,
|
||||
error: "",
|
||||
message: "",
|
||||
generation: 0,
|
||||
requestAbort: null,
|
||||
}),
|
||||
computed: {
|
||||
source() {
|
||||
return this.sourceSites[this.sourceIndex] || null;
|
||||
},
|
||||
names() {
|
||||
return Object.keys(this.source?.presets || {});
|
||||
},
|
||||
existing() {
|
||||
return this.site?.presets || { 主预设: this.site };
|
||||
},
|
||||
conflicts() {
|
||||
return this.names.filter((n) => Object.hasOwn(this.existing, n));
|
||||
},
|
||||
importCount() {
|
||||
return this.mode === "preset"
|
||||
? this.sourcePreset
|
||||
? 1
|
||||
: 0
|
||||
: this.names.filter(
|
||||
(n) => this.overwrite || !Object.hasOwn(this.existing, n),
|
||||
).length;
|
||||
},
|
||||
},
|
||||
beforeUnmount() {
|
||||
this.requestAbort?.abort();
|
||||
this.generation++;
|
||||
},
|
||||
watch: {
|
||||
domain() {
|
||||
this.reset();
|
||||
this.open = false;
|
||||
this.message = "";
|
||||
},
|
||||
sourceIndex() {
|
||||
this.selectSource();
|
||||
},
|
||||
sourcePreset() {
|
||||
if (this.mode === "preset") this.suggestName();
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
trapFocus(e) {
|
||||
const items = [
|
||||
...e.currentTarget.querySelectorAll(
|
||||
"button:not(:disabled),input:not(:disabled),select:not(:disabled)",
|
||||
),
|
||||
].filter((n) => n.offsetParent !== null);
|
||||
if (e.shiftKey && document.activeElement === items[0]) {
|
||||
e.preventDefault();
|
||||
items.at(-1)?.focus();
|
||||
} else if (!e.shiftKey && document.activeElement === items.at(-1)) {
|
||||
e.preventDefault();
|
||||
items[0]?.focus();
|
||||
}
|
||||
},
|
||||
reset() {
|
||||
this.requestAbort?.abort();
|
||||
this.generation++;
|
||||
this.fileName = "";
|
||||
this.sourceSites = [];
|
||||
this.error = "";
|
||||
this.busy = false;
|
||||
this.sourcePreset = "";
|
||||
this.targetName = "";
|
||||
this.overwrite = false;
|
||||
this.includeSettings = false;
|
||||
},
|
||||
launch(mode) {
|
||||
this.reset();
|
||||
this.mode = mode;
|
||||
this.open = true;
|
||||
this.$refs.menu.open = false;
|
||||
this.$nextTick(() => this.$refs.choose.focus());
|
||||
},
|
||||
close() {
|
||||
this.requestAbort?.abort();
|
||||
this.generation++;
|
||||
this.open = false;
|
||||
this.busy = false;
|
||||
this.$nextTick(() => this.$refs.menu.querySelector("summary").focus());
|
||||
},
|
||||
suggestName() {
|
||||
let name = this.sourcePreset || "导入预设";
|
||||
if (Object.hasOwn(this.existing, name)) {
|
||||
const base = name.slice(0, 86) + " · 导入";
|
||||
name = base;
|
||||
let i = 2;
|
||||
while (Object.hasOwn(this.existing, name)) name = base + " " + i++;
|
||||
}
|
||||
this.targetName = name;
|
||||
},
|
||||
selectSource() {
|
||||
this.sourcePreset = this.names[0] || "";
|
||||
this.suggestName();
|
||||
},
|
||||
async read(event) {
|
||||
const file = event.target.files[0];
|
||||
event.target.value = "";
|
||||
if (!file) return;
|
||||
const generation = ++this.generation;
|
||||
this.error = "";
|
||||
try {
|
||||
if (file.size > 4 * 1024 * 1024)
|
||||
throw Error("配置文件不能超过 4 MiB。");
|
||||
const data = JSON.parse(await file.text());
|
||||
if (generation !== this.generation) return;
|
||||
this.sourceSites = sources(data, this.domain);
|
||||
this.sourceIndex = Math.max(
|
||||
0,
|
||||
this.sourceSites.findIndex((s) => s.domain === this.domain),
|
||||
);
|
||||
this.fileName = file.name;
|
||||
this.selectSource();
|
||||
} catch (e) {
|
||||
if (generation === this.generation) {
|
||||
this.sourceSites = [];
|
||||
this.fileName = "";
|
||||
this.error = e.message || "文件无法读取";
|
||||
}
|
||||
}
|
||||
},
|
||||
async validate(config) {
|
||||
const headers = { "Content-Type": "application/json" },
|
||||
token = window.getDashboardAuthToken?.();
|
||||
if (token) headers.Authorization = "Bearer " + token;
|
||||
const controller = new AbortController();
|
||||
this.requestAbort = controller;
|
||||
const timeout = setTimeout(() => controller.abort(), 30000);
|
||||
try {
|
||||
const response = await fetch("/api/workflow/validate", {
|
||||
method: "POST",
|
||||
headers,
|
||||
signal: controller.signal,
|
||||
body: JSON.stringify({ workflow: config.workflow || [] }),
|
||||
});
|
||||
const result = await response.json();
|
||||
if (!response.ok)
|
||||
throw Error(
|
||||
typeof result.detail === "string"
|
||||
? result.detail
|
||||
: "工作流校验失败",
|
||||
);
|
||||
} catch (e) {
|
||||
if (e.name === "AbortError")
|
||||
throw Error("校验已取消或超过 30 秒,请稍后再试。");
|
||||
throw e;
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
if (this.requestAbort === controller) this.requestAbort = null;
|
||||
}
|
||||
},
|
||||
async apply() {
|
||||
if (!this.source || this.busy) return;
|
||||
const domain = this.domain,
|
||||
generation = this.generation;
|
||||
this.error = "";
|
||||
try {
|
||||
const updates = {};
|
||||
if (this.mode === "preset") {
|
||||
const name = this.targetName.trim();
|
||||
if (!safeName(name)) throw Error("请输入 1–100 字的有效预设名称。");
|
||||
if (
|
||||
Object.hasOwn(this.existing, name) &&
|
||||
!confirm(
|
||||
"将替换当前站点的「" +
|
||||
name +
|
||||
"」预设。其他预设不变,是否继续?",
|
||||
)
|
||||
)
|
||||
return;
|
||||
updates[name] = copy(this.source.presets[this.sourcePreset]);
|
||||
} else {
|
||||
for (const n of this.names)
|
||||
if (this.overwrite || !Object.hasOwn(this.existing, n))
|
||||
updates[n] = copy(this.source.presets[n]);
|
||||
if (
|
||||
this.overwrite &&
|
||||
this.conflicts.length &&
|
||||
!confirm(
|
||||
"将覆盖 " +
|
||||
this.conflicts.length +
|
||||
" 个同名预设,其他预设保留。继续?",
|
||||
)
|
||||
)
|
||||
return;
|
||||
}
|
||||
if (!Object.keys(updates).length)
|
||||
throw Error(
|
||||
"没有可导入的预设。同名预设默认跳过,可选择覆盖或改为导入单个预设。",
|
||||
);
|
||||
this.busy = true;
|
||||
for (const config of Object.values(updates)) {
|
||||
if (domain !== this.domain || generation !== this.generation)
|
||||
return;
|
||||
await this.validate(config);
|
||||
}
|
||||
if (domain !== this.domain || generation !== this.generation) return;
|
||||
this.prepare?.();
|
||||
this.$emit("apply", {
|
||||
domain,
|
||||
presets: updates,
|
||||
settings:
|
||||
this.mode === "site" && this.includeSettings
|
||||
? copy(this.source.settings)
|
||||
: null,
|
||||
select: this.mode === "preset" ? this.targetName.trim() : null,
|
||||
});
|
||||
this.message =
|
||||
"已导入 " +
|
||||
Object.keys(updates).length +
|
||||
" 个预设为草稿,请点击「保存配置」。";
|
||||
this.close();
|
||||
} catch (e) {
|
||||
if (generation === this.generation) this.error = e.message;
|
||||
} finally {
|
||||
if (generation === this.generation) this.busy = false;
|
||||
}
|
||||
},
|
||||
download(scope) {
|
||||
this.prepare?.();
|
||||
const site = copy(this.site || {}),
|
||||
preset = this.preset;
|
||||
let payload, file;
|
||||
if (scope === "preset") {
|
||||
const config =
|
||||
site.presets?.[preset] || (!site.presets ? site : null);
|
||||
if (!config) {
|
||||
this.message = "当前预设不存在,请重新选择。";
|
||||
return;
|
||||
}
|
||||
payload = {
|
||||
domain: this.domain,
|
||||
default_preset: preset,
|
||||
presets: { [preset]: config },
|
||||
};
|
||||
file = this.domain + "__" + preset + "__preset.json";
|
||||
} else {
|
||||
payload = { ...site, domain: this.domain };
|
||||
file = this.domain + "__site.json";
|
||||
}
|
||||
const url = URL.createObjectURL(
|
||||
new Blob([JSON.stringify(payload, null, 2)], {
|
||||
type: "application/json",
|
||||
}),
|
||||
),
|
||||
a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = file.replace(/[\\/:*?"<>|]/g, "_");
|
||||
a.click();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
this.$refs.menu.open = false;
|
||||
this.message =
|
||||
scope === "preset"
|
||||
? "已导出当前预设「" + preset + "」,不含其他预设和站点级设置。"
|
||||
: "已导出本站点全部预设与站点级设置。";
|
||||
},
|
||||
},
|
||||
template: `<div class="preset-transfer">
|
||||
<details ref="menu" class="preset-more transfer-menu"><summary class="preset-btn" :aria-disabled="disabled" @click="disabled && $event.preventDefault()"><span v-html="$icons.arrowUpTray"></span>导入 / 导出<span v-html="$icons.chevronDown"></span></summary>
|
||||
<div class="preset-more-pop"><div class="transfer-menu-caption">当前站点 · {{ domain }}</div>
|
||||
<button type="button" @click="launch('preset')"><span v-html="$icons.documentArrowDown"></span><span>导入一个预设<small>新建一份,或明确选择替换</small></span></button>
|
||||
<button type="button" @click="launch('site')"><span v-html="$icons.folderOpen"></span><span>合并站点配置<small>从文件导入本站点的多套预设</small></span></button>
|
||||
<hr class="preset-more-sep">
|
||||
<button type="button" @click="download('preset')"><span v-html="$icons.arrowUpTray"></span><span>导出当前预设<small>仅「{{ preset }}」,方便分享与迁移</small></span></button>
|
||||
<button type="button" @click="download('site')"><span v-html="$icons.globe"></span><span>导出整个站点<small>全部预设 + 站点级设置</small></span></button>
|
||||
</div>
|
||||
</details>
|
||||
<div v-if="message" class="transfer-feedback" role="status">{{ message }}<button type="button" @click="message=''" aria-label="关闭导入导出提示">×</button></div>
|
||||
<teleport to="body"><div v-if="open" class="preset-transfer-overlay" @click.self="close()" @keydown.esc.stop="close()">
|
||||
<section class="preset-transfer-dialog" role="dialog" aria-modal="true" aria-labelledby="preset-transfer-title" @keydown.tab="trapFocus">
|
||||
<header><div><span class="transfer-kicker">导入到当前站点</span><h3 id="preset-transfer-title">{{ mode==='preset'?'导入一个预设':'合并站点配置' }}</h3><p>{{ domain }} · 不会影响其他站点</p></div><button type="button" @click="close" aria-label="关闭导入对话框">×</button></header>
|
||||
<div class="transfer-body"><button ref="choose" type="button" class="transfer-file" @click="$refs.file.click()" :disabled="busy"><span v-html="$icons.documentArrowDown"></span><strong>{{ fileName || '选择配置 JSON 文件' }}</strong><small>支持单预设、单站点和多站点文件 · 最大 4 MiB</small></button><input ref="file" type="file" accept=".json,application/json" hidden @change="read">
|
||||
<template v-if="source"><label v-if="sourceSites.length>1">从文件选择来源站点<select v-model.number="sourceIndex" :disabled="busy"><option v-for="(s,i) in sourceSites" :value="i">{{ s.domain }} · {{ Object.keys(s.presets).length }} 个预设</option></select></label><p v-if="source.domain!==domain" class="transfer-note">来源 {{ source.domain }} → 导入到 {{ domain }}。请确认定位器适用于当前站点。</p>
|
||||
<template v-if="mode==='preset'"><label>文件中的预设<select v-model="sourcePreset" :disabled="busy"><option v-for="n in names" :value="n">{{ n }}</option></select></label><label>在本站点保存为<input v-model="targetName" maxlength="100" :disabled="busy"></label><p class="transfer-note">{{ Object.hasOwn(existing,targetName.trim())?'将替换同名预设;确认时会再次提醒。':'将新建预设;现有预设和默认选择均保持不变。' }}</p></template>
|
||||
<template v-else><div class="transfer-preview"><strong>{{ names.length }} 个来源预设 · {{ conflicts.length }} 个同名</strong><div v-for="n in names"><span>{{ n }}</span><small>{{ conflicts.includes(n)?(overwrite?'将覆盖':'保留已有,跳过'):'新增' }}</small></div></div><label class="transfer-check"><input type="checkbox" v-model="overwrite" :disabled="busy">覆盖同名预设(默认保留已有)</label><label v-if="Object.keys(source.settings).length" class="transfer-check"><input type="checkbox" v-model="includeSettings" :disabled="busy">同时导入站点级设置</label><p class="transfer-note">保留其他已有预设,不改变默认预设。{{ includeSettings?'文件中的站点级字段将替换当前同名字段。':'站点级设置保持不变。' }}</p></template>
|
||||
</template><p v-if="error" class="transfer-error" role="alert">{{ error }}</p>
|
||||
</div><footer><span>先校验并载入草稿,再由你保存。</span><button type="button" @click="close">取消</button><button type="button" class="transfer-primary" @click="apply" :disabled="busy||!source||!importCount">{{ busy?'校验中…':'导入为草稿' }}</button></footer>
|
||||
</section>
|
||||
</div></teleport>
|
||||
</div>`,
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,180 @@
|
||||
// ==================== 提示词开头注入面板 ====================
|
||||
|
||||
window.PromptPaddingPanel = {
|
||||
name: 'PromptPaddingPanel',
|
||||
props: {
|
||||
promptPaddingConfig: { type: Object, required: true },
|
||||
currentDomain: { type: String, default: null },
|
||||
selectedPreset: { type: String, default: null },
|
||||
collapsed: { type: Boolean, default: true }
|
||||
},
|
||||
emits: ['update:collapsed'],
|
||||
data() {
|
||||
return {
|
||||
defaultPromptPadding: {
|
||||
enabled: false,
|
||||
marker_text: '测试号,无实际意义',
|
||||
segments_per_side: 12,
|
||||
random_insert_enabled: false,
|
||||
random_insert_chars: ''
|
||||
}
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
resolvedPromptPadding() {
|
||||
const raw = this.promptPaddingConfig || {};
|
||||
return {
|
||||
...this.defaultPromptPadding,
|
||||
...raw
|
||||
};
|
||||
},
|
||||
currentPresetLabel() {
|
||||
return String(this.selectedPreset || '').trim() || '主预设';
|
||||
},
|
||||
statusText() {
|
||||
return (this.resolvedPromptPadding.enabled || this.resolvedPromptPadding.random_insert_enabled)
|
||||
? '已启用'
|
||||
: '未启用';
|
||||
},
|
||||
markerPreview() {
|
||||
const markerText = String(this.resolvedPromptPadding.marker_text || '').trim();
|
||||
const segmentCount = Math.max(0, parseInt(this.resolvedPromptPadding.segments_per_side, 10) || 0);
|
||||
if (segmentCount === 0) {
|
||||
return markerText || '不注入内容';
|
||||
}
|
||||
if (!markerText) {
|
||||
return '随机片段';
|
||||
}
|
||||
if (markerText.endsWith(':') || markerText.endsWith(':')) {
|
||||
return markerText + '随机片段';
|
||||
}
|
||||
return markerText + ':随机片段';
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggle() {
|
||||
this.$emit('update:collapsed', !this.collapsed);
|
||||
},
|
||||
|
||||
getMutablePromptPadding() {
|
||||
return this.promptPaddingConfig || {};
|
||||
},
|
||||
|
||||
toggleEnabled() {
|
||||
const cfg = this.getMutablePromptPadding();
|
||||
cfg.enabled = !this.resolvedPromptPadding.enabled;
|
||||
},
|
||||
|
||||
updateMarkerText(value) {
|
||||
this.getMutablePromptPadding().marker_text = String(value || '');
|
||||
},
|
||||
|
||||
updateSegmentsPerSide(value) {
|
||||
const parsed = parseInt(value, 10);
|
||||
if (!Number.isFinite(parsed)) {
|
||||
return;
|
||||
}
|
||||
this.getMutablePromptPadding().segments_per_side = Math.max(0, Math.min(parsed, 64));
|
||||
},
|
||||
|
||||
toggleRandomInsertEnabled() {
|
||||
const cfg = this.getMutablePromptPadding();
|
||||
cfg.random_insert_enabled = !this.resolvedPromptPadding.random_insert_enabled;
|
||||
},
|
||||
|
||||
updateRandomInsertChars(value) {
|
||||
this.getMutablePromptPadding().random_insert_chars = String(value || '');
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="cap-panel cap-padding-panel bg-white dark:bg-gray-800 border dark:border-gray-700 rounded-lg shadow-sm">
|
||||
<div class="px-4 py-3 border-b dark:border-gray-700 flex justify-between items-center cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors"
|
||||
@click="toggle">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="w-4 inline-flex justify-center text-gray-500 dark:text-gray-400" v-html="collapsed ? $icons.chevronDown : $icons.chevronUp"></span>
|
||||
<h3 class="font-semibold text-gray-900 dark:text-white">特殊输入适配</h3>
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">({{ statusText }})</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-show="!collapsed" class="p-4"><details class="cap-troubleshoot"><summary><span><strong>特殊站点:调整提示词</strong><small>会在原消息中加入额外内容,普通对话通常无需修改。</small></span><span class="cap-summary-value">{{ resolvedPromptPadding.enabled || resolvedPromptPadding.random_insert_enabled ? '有功能已开启' : '未开启' }}</span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><p class="cap-warning">随机插入字符会改变原文。处理代码、结构化数据或需要精确措辞时请谨慎使用。</p>
|
||||
|
||||
|
||||
<div class="rounded-lg border border-gray-200 dark:border-gray-700 bg-gray-50/60 dark:bg-gray-900/30 p-4 space-y-4">
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-800 dark:text-gray-100">发送前在开头追加随机占位片段</div>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400 leading-5">
|
||||
开启后,只在提示词开头追加一段随机片段,不改动后面的原始消息主体。修改会跟随当前站点配置一起保存。
|
||||
</p>
|
||||
</div>
|
||||
<label class="toggle-label scale-90 flex-shrink-0">
|
||||
<input type="checkbox" aria-label="启用开头占位片段" :checked="resolvedPromptPadding.enabled" @change="toggleEnabled" class="sr-only peer">
|
||||
<div class="toggle-bg"></div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">开头片段数</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="resolvedPromptPadding.segments_per_side"
|
||||
@input="updateSegmentsPerSide($event.target.value)"
|
||||
min="0"
|
||||
max="64"
|
||||
step="1"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm text-right bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">个</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">说明文本</label>
|
||||
<input type="text"
|
||||
:value="resolvedPromptPadding.marker_text"
|
||||
@input="updateMarkerText($event.target.value)"
|
||||
placeholder="留空则只追加随机片段"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-lg border border-slate-200 dark:border-slate-700 bg-white/80 dark:bg-slate-900/40 px-4 py-3">
|
||||
<div class="text-sm font-medium text-gray-800 dark:text-gray-100">发送效果</div>
|
||||
<p class="mt-1 text-xs leading-5 text-gray-500 dark:text-gray-400">
|
||||
实际发送时,会在提示词开头生成一段类似
|
||||
<code class="font-mono">{{ markerPreview }}</code>
|
||||
的文本。随机片段会混合数字和单字符字母,尽量贴近当前需求的样式。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-gray-200 dark:border-gray-700 pt-4 space-y-3">
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-800 dark:text-gray-100">提示词内随机插入一个字符</div>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400 leading-5">
|
||||
每次发送时,从候选字符中随机选择一个,并插入到用户提示词的随机位置。
|
||||
</p>
|
||||
</div>
|
||||
<label class="toggle-label scale-90 flex-shrink-0">
|
||||
<input type="checkbox"
|
||||
aria-label="在提示词中随机插入字符" :checked="resolvedPromptPadding.random_insert_enabled"
|
||||
@change="toggleRandomInsertEnabled"
|
||||
class="sr-only peer">
|
||||
<div class="toggle-bg"></div>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">候选字符</label>
|
||||
<input type="text"
|
||||
:value="resolvedPromptPadding.random_insert_chars"
|
||||
@input="updateRandomInsertChars($event.target.value)"
|
||||
placeholder="例如:abc123※☆"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">候选框中的每个字符都有机会被选中;留空时不会插入。</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div></details></div>
|
||||
</div>
|
||||
`
|
||||
};
|
||||
@@ -0,0 +1,508 @@
|
||||
// ==================== 选择器管理面板 ====================
|
||||
|
||||
window.SelectorPanel = {
|
||||
name: 'SelectorPanel',
|
||||
props: {
|
||||
selectors: { type: Object, required: true },
|
||||
collapsed: { type: Boolean, default: true }
|
||||
},
|
||||
emits: [
|
||||
'update:collapsed',
|
||||
'add-selector',
|
||||
'remove-selector',
|
||||
'update-selector-key',
|
||||
'update-selector-value',
|
||||
'test-selector'
|
||||
],
|
||||
data() {
|
||||
return {
|
||||
showMenu: false,
|
||||
fieldQuery: '',
|
||||
fieldFilter: 'all',
|
||||
editingSelectorKey: '',
|
||||
expandedField: 'input_box',
|
||||
auxiliaryExpanded: false,
|
||||
guideExpanded: false,
|
||||
openRenameKey: '',
|
||||
renameDrafts: {},
|
||||
coreSelectorKeys: ['input_box', 'send_btn', 'result_container']
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
count() {
|
||||
return Object.keys(this.selectors || {}).length;
|
||||
},
|
||||
|
||||
selectorEntries() {
|
||||
const query = this.fieldQuery.trim().toLowerCase();
|
||||
return Object.entries(this.selectors || {}).filter(([key, value]) => {
|
||||
// Keep the active field mounted while typing, even when its value stops matching.
|
||||
if (key === this.editingSelectorKey) return true;
|
||||
if (this.fieldFilter === 'core' && !this.coreSelectorKeys.includes(key)) return false;
|
||||
if (this.fieldFilter === 'empty' && this.isSelectorFilled(key)) return false;
|
||||
const meta = this.getSelectorMeta(key);
|
||||
return !query || [key, value, meta.title, meta.description].join(' ').toLowerCase().includes(query);
|
||||
});
|
||||
},
|
||||
|
||||
selectorGroups() {
|
||||
return [
|
||||
{ id: 'core', title: '核心定位', note: '一次对话的三个关键位置', entries: this.selectorEntries.filter(([key]) => this.coreSelectorKeys.includes(key)) },
|
||||
{ id: 'auxiliary', title: '辅助与扩展', note: '对话管理、上传入口及自定义字段', entries: this.selectorEntries.filter(([key]) => !this.coreSelectorKeys.includes(key)) }
|
||||
];
|
||||
},
|
||||
coreChecklist() {
|
||||
return this.coreSelectorKeys.map(key => ({
|
||||
key,
|
||||
...this.getSelectorMeta(key),
|
||||
ready: this.isSelectorFilled(key)
|
||||
}));
|
||||
},
|
||||
|
||||
coreReadyCount() {
|
||||
return this.coreChecklist.filter(item => item.ready).length;
|
||||
},
|
||||
|
||||
missingQuickAdds() {
|
||||
return this.coreChecklist.filter(item => !Object.prototype.hasOwnProperty.call(this.selectors || {}, item.key));
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
selectors() {
|
||||
this.fieldQuery = '';
|
||||
this.fieldFilter = 'all';
|
||||
this.editingSelectorKey = '';
|
||||
this.expandedField = Object.prototype.hasOwnProperty.call(this.selectors || {}, 'input_box') ? 'input_box' : Object.keys(this.selectors || {})[0] || '';
|
||||
this.auxiliaryExpanded = false;
|
||||
this.closeRenameEditor();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
openCoreField(key) {
|
||||
this.fieldFilter = 'all'; this.fieldQuery = '';
|
||||
if (!Object.prototype.hasOwnProperty.call(this.selectors || {}, key)) {
|
||||
this.addSelector(key);
|
||||
return;
|
||||
}
|
||||
this.expandedField = key;
|
||||
this.$nextTick(() => {
|
||||
const field = document.getElementById('selector-expression-' + key);
|
||||
if (field) { field.focus({ preventScroll: true }); field.scrollIntoView({ block: 'nearest' }); }
|
||||
});
|
||||
},
|
||||
toggle() {
|
||||
this.$emit('update:collapsed', !this.collapsed);
|
||||
},
|
||||
|
||||
toggleMenu(e) {
|
||||
e.stopPropagation();
|
||||
this.showMenu = !this.showMenu;
|
||||
},
|
||||
|
||||
addSelector(type) {
|
||||
this.showMenu = false;
|
||||
const previous = Object.keys(this.selectors || {});
|
||||
this.$emit('add-selector', type);
|
||||
this.$nextTick(() => {
|
||||
const key = Object.keys(this.selectors || {}).find(key => !previous.includes(key));
|
||||
if (!key) return;
|
||||
this.fieldFilter = 'all'; this.fieldQuery = '';
|
||||
this.expandedField = key;
|
||||
this.auxiliaryExpanded = !this.coreSelectorKeys.includes(key);
|
||||
});
|
||||
},
|
||||
|
||||
closeMenu() {
|
||||
this.showMenu = false;
|
||||
},
|
||||
|
||||
openInNewTab(url) {
|
||||
const target = String(url || '').trim();
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
window.open(target, '_blank', 'noopener,noreferrer');
|
||||
},
|
||||
|
||||
openTutorial(anchor = 'selector-basics') {
|
||||
this.openInNewTab('/static/tutorial/index.html#' + encodeURIComponent(anchor));
|
||||
},
|
||||
|
||||
openPracticeLab() {
|
||||
this.openInNewTab('/static/selector-practice.html');
|
||||
},
|
||||
|
||||
isSelectorFilled(key) {
|
||||
return String((this.selectors || {})[key] || '').trim().length > 0;
|
||||
},
|
||||
|
||||
isBuiltInSelectorKey(key) {
|
||||
return [
|
||||
'input_box',
|
||||
'send_btn',
|
||||
'result_container',
|
||||
'new_chat_btn',
|
||||
'message_wrapper',
|
||||
'generating_indicator',
|
||||
'retry_send_btn',
|
||||
'upload_btn',
|
||||
'file_input',
|
||||
'drop_zone',
|
||||
'composer_root'
|
||||
].includes(String(key || '').trim());
|
||||
},
|
||||
|
||||
canRenameSelectorKey(key) {
|
||||
return !this.isBuiltInSelectorKey(key);
|
||||
},
|
||||
|
||||
openRenameEditor(key) {
|
||||
this.openRenameKey = key;
|
||||
this.renameDrafts = {
|
||||
...this.renameDrafts,
|
||||
[key]: key
|
||||
};
|
||||
|
||||
this.$nextTick(() => {
|
||||
const ref = this.$refs['renameInput-' + key];
|
||||
const input = Array.isArray(ref) ? ref[0] : ref;
|
||||
if (input && typeof input.focus === 'function') {
|
||||
input.focus();
|
||||
if (typeof input.select === 'function') {
|
||||
input.select();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
closeRenameEditor() {
|
||||
this.openRenameKey = '';
|
||||
},
|
||||
|
||||
submitRenameKey(key) {
|
||||
const nextKey = String((this.renameDrafts || {})[key] || '').trim();
|
||||
this.openRenameKey = '';
|
||||
if (!nextKey || nextKey === key) {
|
||||
return;
|
||||
}
|
||||
this.$emit('update-selector-key', key, nextKey);
|
||||
this.$nextTick(() => {
|
||||
if (Object.prototype.hasOwnProperty.call(this.selectors || {}, nextKey) && !Object.prototype.hasOwnProperty.call(this.selectors || {}, key)) this.expandedField = nextKey;
|
||||
});
|
||||
},
|
||||
|
||||
getSelectorMeta(key) {
|
||||
const metaMap = {
|
||||
input_box: {
|
||||
title: '输入框',
|
||||
description: '用户真正打字的地方。常见是 textarea、contenteditable 或 role=textbox。',
|
||||
hint: '先右键输入区域点“检查”。看到 textarea,或者看到可编辑的 div,通常就离答案很近了。',
|
||||
required: true,
|
||||
chip: '必填',
|
||||
placeholder: '例如:textarea, div[contenteditable="true"]'
|
||||
},
|
||||
send_btn: {
|
||||
title: '发送按钮',
|
||||
description: '点一下就会把消息发出去的按钮,常见是纸飞机、箭头或“发送”字样。',
|
||||
hint: '优先找 button 上比较稳的属性,比如 type、aria-label、data-testid;只靠一串随机 class 往往不稳。',
|
||||
required: true,
|
||||
chip: '必填',
|
||||
placeholder: '例如:button[type="submit"], button[data-testid="send"]'
|
||||
},
|
||||
result_container: {
|
||||
title: '回复容器',
|
||||
description: '包住 AI 回复正文的区域。尽量选整段回复的外层,不要只选某个 p 或 span。',
|
||||
hint: '看到整条 AI 回复后,先选能完整包住这条内容的外层块。范围太小,后面很容易漏字、漏代码块。',
|
||||
required: true,
|
||||
chip: '必填',
|
||||
placeholder: '例如:main article .markdown-body'
|
||||
},
|
||||
new_chat_btn: {
|
||||
title: '新建对话按钮',
|
||||
description: '每次开始新会话前需要点的按钮,没有也可以先留空。',
|
||||
hint: '如果页面左上角有“新聊天”“新建对话”“清空上下文”之类的入口,这个字段通常就该填它。',
|
||||
required: false,
|
||||
chip: '选填',
|
||||
placeholder: '例如:button[aria-label*="新"], button.new-chat'
|
||||
},
|
||||
message_wrapper: {
|
||||
title: '消息外层容器',
|
||||
description: '一条消息最外层的盒子。长回复、分段节点、复杂样式场景里很有帮助。',
|
||||
hint: '如果一条回复里有很多段落、代码块、图片,给它补上最外层容器,提取结果通常会稳很多。',
|
||||
required: false,
|
||||
chip: '辅助',
|
||||
placeholder: '例如:article[data-role="assistant-message"]'
|
||||
},
|
||||
generating_indicator: {
|
||||
title: '生成中指示器',
|
||||
description: '能表明“模型还在继续输出”的元素,比如停止按钮、转圈、typing 提示。',
|
||||
hint: '有“停止生成”按钮时,这个字段通常很好找。它出现时代表还在生成,消失后通常代表结束。',
|
||||
required: false,
|
||||
chip: '辅助',
|
||||
placeholder: '例如:button[aria-label*="停止"], .typing-indicator'
|
||||
},
|
||||
retry_send_btn: {
|
||||
title: '重试/重新运行按钮',
|
||||
description: '用于重新运行当前回复或把停止后的回复重新拉起,常见是圆形箭头按钮。',
|
||||
hint: 'Battle 或双栏对比模式里,通常需要先点这个按钮,再点右下角发送/停止态按钮完成本轮发送。',
|
||||
required: false,
|
||||
chip: '辅助',
|
||||
placeholder: '例如:button[aria-label="Rerun stopped messages"]'
|
||||
},
|
||||
upload_btn: {
|
||||
title: '上传按钮',
|
||||
description: '点一下会弹出上传面板或系统文件选择窗口的按钮。',
|
||||
hint: '页面里有加号、回形针、图片图标时,先看那个按钮。很多站点把上传入口藏在工具栏里。',
|
||||
required: false,
|
||||
chip: '上传',
|
||||
placeholder: '例如:button[aria-label*="上传"], .toolbar-upload'
|
||||
},
|
||||
file_input: {
|
||||
title: '原生文件输入框',
|
||||
description: '真正的 input[type=file] 元素,适合直接写入文件。',
|
||||
hint: '很多站点会把它藏起来。开发者工具里搜索 type="file" 往往最快。',
|
||||
required: false,
|
||||
chip: '上传',
|
||||
placeholder: '例如:input[type="file"]'
|
||||
},
|
||||
composer_root: {
|
||||
title: '消息编辑区根节点',
|
||||
description: '限定自动查找文件输入框和附件观察的范围,避免匹配页面历史消息。',
|
||||
hint: '通常是包围输入框、附件预览和发送按钮的容器。配置 file_input 时仍优先使用指定入口。',
|
||||
required: false, chip: '上传', placeholder: '例如:.composer, form.chat-input'
|
||||
},
|
||||
drop_zone: {
|
||||
title: '拖拽上传区域',
|
||||
description: '支持把文件拖到页面里的区域,适合不吃粘贴的网站。',
|
||||
hint: '拖一张图到页面上时,哪个区域会高亮、变色、出现提示,那个区域通常就是它。',
|
||||
required: false,
|
||||
chip: '上传',
|
||||
placeholder: '例如:div[data-dropzone="true"]'
|
||||
}
|
||||
};
|
||||
|
||||
const presetMeta = metaMap[key];
|
||||
if (presetMeta) {
|
||||
return presetMeta;
|
||||
}
|
||||
|
||||
return {
|
||||
title: '自定义字段',
|
||||
description: '你自己补的额外选择器,常用于临时按钮、模式切换、弹窗确认之类的操作。',
|
||||
hint: '自定义字段也建议优先用稳定属性。页面每次刷新都会变的随机 class,后面维护起来会很痛苦。',
|
||||
required: false,
|
||||
chip: '自定义',
|
||||
placeholder: '例如:button[data-role="mode-switch"]'
|
||||
};
|
||||
},
|
||||
|
||||
getChipClass(key) {
|
||||
const chip = this.getSelectorMeta(key).chip;
|
||||
if (chip === '必填') {
|
||||
return 'dashboard-field-chip';
|
||||
}
|
||||
if (chip === '自定义') {
|
||||
return 'dashboard-field-chip dashboard-field-chip--custom';
|
||||
}
|
||||
return 'dashboard-field-chip dashboard-field-chip--optional';
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="studio-selector-panel bg-white dark:bg-gray-800 border dark:border-gray-700 rounded-lg shadow-sm" @click="closeMenu">
|
||||
<!-- 标题栏 -->
|
||||
<div class="px-4 py-3 border-b dark:border-gray-700 flex justify-between items-center cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors"
|
||||
@click="toggle">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="w-4 inline-flex justify-center text-gray-500 dark:text-gray-400" v-html="collapsed ? $icons.chevronDown : $icons.chevronUp"></span>
|
||||
<h3 class="font-semibold text-gray-900 dark:text-white">字段配置</h3>
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">({{ count }})</span>
|
||||
</div>
|
||||
|
||||
<div class="relative" @click.stop>
|
||||
<button @click="toggleMenu"
|
||||
class="selector-add-btn">
|
||||
<span v-html="$icons.plusCircle"></span> 新增 <span v-html="$icons.chevronDown"></span>
|
||||
</button>
|
||||
|
||||
<div v-if="showMenu"
|
||||
class="absolute right-0 mt-1 w-56 bg-white dark:bg-gray-800 border dark:border-gray-700 rounded-lg shadow-lg z-10 overflow-hidden">
|
||||
<button @click="addSelector('custom')"
|
||||
class="w-full text-left px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-700 text-gray-900 dark:text-white text-sm border-b dark:border-gray-700 transition-colors">
|
||||
自定义字段
|
||||
</button>
|
||||
<div class="px-3 py-1.5 text-xs text-gray-500 dark:text-gray-400 bg-gray-50 dark:bg-gray-900/50 font-medium">
|
||||
辅助字段
|
||||
</div>
|
||||
<button @click="addSelector('message_wrapper')"
|
||||
class="w-full text-left px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-700 text-xs transition-colors">
|
||||
<div class="font-semibold text-gray-900 dark:text-white">message_wrapper</div>
|
||||
<div class="text-gray-500 dark:text-gray-400">消息完整容器,适合多节点回复</div>
|
||||
</button>
|
||||
<button @click="addSelector('generating_indicator')"
|
||||
class="w-full text-left px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-700 text-xs transition-colors">
|
||||
<div class="font-semibold text-gray-900 dark:text-white">generating_indicator</div>
|
||||
<div class="text-gray-500 dark:text-gray-400">生成中提示,适合辅助判断结束</div>
|
||||
</button>
|
||||
<button @click="addSelector('retry_send_btn')"
|
||||
class="w-full text-left px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-700 text-xs transition-colors">
|
||||
<div class="font-semibold text-gray-900 dark:text-white">retry_send_btn</div>
|
||||
<div class="text-gray-500 dark:text-gray-400">重新运行或重试当前回复</div>
|
||||
</button>
|
||||
<button @click="addSelector('upload_btn')"
|
||||
class="w-full text-left px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-700 text-xs transition-colors">
|
||||
<div class="font-semibold text-gray-900 dark:text-white">upload_btn</div>
|
||||
<div class="text-gray-500 dark:text-gray-400">打开上传入口的按钮</div>
|
||||
</button>
|
||||
<button @click="addSelector('file_input')"
|
||||
class="w-full text-left px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-700 text-xs transition-colors">
|
||||
<div class="font-semibold text-gray-900 dark:text-white">file_input</div>
|
||||
<div class="text-gray-500 dark:text-gray-400">原生 input[type=file]</div>
|
||||
</button>
|
||||
<button @click="addSelector('composer_root')" class="w-full text-left px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-700 text-xs transition-colors">
|
||||
<div class="font-semibold text-gray-900 dark:text-white">composer_root</div>
|
||||
<div class="text-gray-500 dark:text-gray-400">限定附件操作的消息编辑区根节点</div>
|
||||
</button>
|
||||
<button @click="addSelector('drop_zone')"
|
||||
class="w-full text-left px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-700 text-xs transition-colors">
|
||||
<div class="font-semibold text-gray-900 dark:text-white">drop_zone</div>
|
||||
<div class="text-gray-500 dark:text-gray-400">支持拖拽上传的区域</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 内容 -->
|
||||
<div v-show="!collapsed" class="p-4 space-y-4 max-h-[44rem] overflow-auto">
|
||||
<div v-if="count === 0" class="dashboard-empty-state text-center text-sm text-slate-500 dark:text-slate-400">
|
||||
<div class="text-3xl mb-3">🧭</div>
|
||||
<p class="leading-6">
|
||||
现在还是空白很正常。先把 <code>input_box</code>、<code>send_btn</code>、<code>result_container</code> 加出来,再开始一项一项测试。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="site-core-path" aria-label="核心字段填写进度">
|
||||
<button type="button" v-for="(item, index) in coreChecklist" :key="item.key" :class="{ 'is-filled': item.ready }" :aria-label="'配置' + item.title" @click="openCoreField(item.key)"><span class="site-path-node" v-html="item.ready ? $icons.check : $icons.minus"></span><span><strong>{{ item.title }}</strong><small>{{ item.ready ? '已填写' : '待配置' }}</small></span><i v-if="index < 2" v-html="$icons.arrowRight"></i></button>
|
||||
</div>
|
||||
<div v-if="missingQuickAdds.length" class="site-missing-fields"><span>缺少核心字段</span><button v-for="item in missingQuickAdds" :key="item.key" type="button" @click="addSelector(item.key)"><span v-html="$icons.plusCircle"></span>添加{{ item.title }}</button></div>
|
||||
<div class="studio-field-toolbar">
|
||||
<div class="studio-field-filters" aria-label="筛选选择器">
|
||||
<button type="button" :class="{ 'is-active': fieldFilter === 'all' }" :aria-pressed="fieldFilter === 'all'" @click="fieldFilter = 'all'">全部字段 <span>{{ count }}</span></button>
|
||||
<button type="button" :class="{ 'is-active': fieldFilter === 'core' }" :aria-pressed="fieldFilter === 'core'" @click="fieldFilter = 'core'">核心字段</button>
|
||||
<button type="button" :class="{ 'is-active': fieldFilter === 'empty' }" :aria-pressed="fieldFilter === 'empty'" @click="fieldFilter = 'empty'">未填写</button>
|
||||
</div>
|
||||
<label class="studio-field-search"><span v-html="$icons.magnifyingGlass"></span><input v-model="fieldQuery" type="search" aria-label="搜索选择器字段" placeholder="搜索字段…" @keyup.escape="fieldQuery = ''"></label>
|
||||
</div>
|
||||
<div v-if="count > 0 && !selectorEntries.length" class="studio-fields-empty"><span v-html="$icons.magnifyingGlass"></span><strong>{{ fieldFilter === 'empty' && !fieldQuery ? '当前字段均已填写' : '没有匹配的字段' }}</strong><p>{{ fieldFilter === 'empty' && !fieldQuery ? '接下来可以逐项测试,确认网页元素能被正确定位。' : '试试其他关键词,或切换到全部字段。' }}</p><button type="button" @click="fieldQuery = ''; fieldFilter = 'all'">查看全部字段</button></div>
|
||||
<section v-for="group in selectorGroups" :key="group.id" v-show="group.entries.length" :class="['site-field-group', 'is-' + group.id]">
|
||||
<div class="site-field-group-heading"><div><h4>{{ group.title }} <span>{{ group.entries.length }}</span></h4><p>{{ group.note }}</p></div><button v-if="group.id === 'auxiliary'" type="button" :aria-expanded="auxiliaryExpanded || !!fieldQuery || fieldFilter !== 'all'" @click="auxiliaryExpanded = !auxiliaryExpanded; fieldQuery = ''; fieldFilter = 'all'">{{ auxiliaryExpanded || fieldQuery || fieldFilter !== 'all' ? '收起' : '展开' }}<span v-html="auxiliaryExpanded ? $icons.chevronUp : $icons.chevronDown"></span></button></div>
|
||||
<div v-show="group.id === 'core' || auxiliaryExpanded || fieldQuery || fieldFilter !== 'all'" class="site-field-group-list">
|
||||
<article v-for="([key, val], index) in group.entries" :key="key" :class="['studio-selector-card', { 'is-expanded': expandedField === key }]">
|
||||
<button type="button" class="site-field-toggle" :aria-label="'编辑字段 ' + key" :aria-expanded="expandedField === key" @click="expandedField = expandedField === key ? '' : key">
|
||||
<span class="site-field-index">{{ String(index + 1).padStart(2, '0') }}</span><span class="site-field-heading"><span><strong>{{ getSelectorMeta(key).title }}</strong><code>{{ key }}</code></span><small v-if="expandedField !== key">{{ val || '尚未填写定位表达式' }}</small></span><span :class="['site-field-state', { 'is-filled': isSelectorFilled(key) }]">{{ isSelectorFilled(key) ? '已填写' : '待填写' }}</span><span class="site-field-chevron" v-html="expandedField === key ? $icons.chevronUp : $icons.chevronDown"></span>
|
||||
</button>
|
||||
<div v-show="expandedField === key" class="site-field-expanded">
|
||||
<div v-if="openRenameKey === key"
|
||||
class="mb-2 flex flex-col md:flex-row gap-2 rounded-xl border border-blue-200/80 dark:border-blue-800/70 bg-blue-50/70 dark:bg-blue-900/20 p-2.5">
|
||||
<input :ref="'renameInput-' + key"
|
||||
v-model="renameDrafts[key]"
|
||||
@keyup.enter="submitRenameKey(key)"
|
||||
@keyup.esc="closeRenameEditor()"
|
||||
class="flex-1 border dark:border-gray-600 px-2.5 py-2 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent font-semibold text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white"
|
||||
placeholder="新的字段键名">
|
||||
<div class="flex items-center gap-2">
|
||||
<button @click="submitRenameKey(key)"
|
||||
type="button"
|
||||
class="px-3 py-1.5 rounded-md text-xs font-medium text-blue-600 dark:text-blue-300 border border-blue-300 dark:border-blue-700 hover:bg-blue-100/80 dark:hover:bg-blue-900/40 transition-colors">
|
||||
保存
|
||||
</button>
|
||||
<button @click="closeRenameEditor()"
|
||||
type="button"
|
||||
class="px-3 py-1.5 rounded-md text-xs font-medium text-slate-500 dark:text-slate-300 border border-slate-200 dark:border-slate-700 hover:bg-white/80 dark:hover:bg-slate-800/70 transition-colors">
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="site-field-edit-row"><div class="site-field-expression"><label :for="'selector-expression-' + key">定位表达式</label><textarea :id="'selector-expression-' + key" rows="3" :value="selectors[key]" :aria-label="getSelectorMeta(key).title + '选择器'" @focus="editingSelectorKey = key" @blur="editingSelectorKey = ''" @input="$emit('update-selector-value', key, $event.target.value)" :placeholder="getSelectorMeta(key).placeholder || '输入选择器'"></textarea></div><aside class="site-field-context"><span>如何定位</span><p>{{ getSelectorMeta(key).description }}</p><small>{{ getSelectorMeta(key).hint }}</small></aside></div>
|
||||
<div class="studio-field-actions"><span>填写后,请在目标网页上验证。</span><button v-if="canRenameSelectorKey(key)" type="button" @click="openRenameEditor(key)" class="site-rename-field"><span v-html="$icons.pencil"></span>改名</button><button type="button" class="site-delete-field" :aria-label="'删除选择器 ' + key" @click="$emit('remove-selector', key)"><span v-html="$icons.trash"></span></button><button type="button" class="site-test-field" @click="$emit('test-selector', key, val)"><span v-html="$icons.play"></span>测试选择器</button></div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
<div v-if="!guideExpanded" class="studio-guide-entry">
|
||||
<button @click="guideExpanded = true" type="button" class="dashboard-guide-toggle">
|
||||
<span v-html="$icons.bookOpen"></span><span>不知道怎么填写?查看选择器指南</span>
|
||||
<span v-html="$icons.chevronDown"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-else class="dashboard-guide-card dashboard-guide-card--blue">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<span class="dashboard-guide-badge">零基础也能开始</span>
|
||||
<button @click="guideExpanded = false" type="button" class="dashboard-guide-toggle">
|
||||
<span>收起</span>
|
||||
<span v-html="$icons.chevronUp"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<div class="text-base font-semibold text-slate-900 dark:text-slate-50">
|
||||
先把 3 个核心字段补齐,页面就能有基础可用性
|
||||
</div>
|
||||
<p class="mt-1.5 text-sm leading-6 text-slate-600 dark:text-slate-300">
|
||||
先找输入框、发送按钮、AI 回复容器。上传按钮、消息外层、生成中提示这些字段可以后面再慢慢补。第一轮目标很简单:先让页面能发、能收、能测。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-guide-steps">
|
||||
<div class="dashboard-guide-step">
|
||||
<strong>第 1 步</strong>
|
||||
<span>打开教程章节,先看字段各自负责什么。</span>
|
||||
</div>
|
||||
<div class="dashboard-guide-step">
|
||||
<strong>第 2 步</strong>
|
||||
<span>打开本地选择器工作台,先在模拟页面里练一遍,再直接看候选写法和命中详情。</span>
|
||||
</div>
|
||||
<div class="dashboard-guide-step">
|
||||
<strong>第 3 步</strong>
|
||||
<span>回到真实站点,填一个测一个。测试工作台会直接告诉你命中了几个、为什么不稳、有没有更好的候选。</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-checklist">
|
||||
<div v-for="item in coreChecklist"
|
||||
:key="item.key"
|
||||
:class="['dashboard-checklist-item', item.ready ? 'is-ready' : 'is-missing']">
|
||||
<span>{{ item.ready ? '✓' : '•' }}</span>
|
||||
<span>{{ item.key }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="mt-3 text-xs text-slate-500 dark:text-slate-400">
|
||||
当前核心字段进度:{{ coreReadyCount }}/3
|
||||
</p>
|
||||
|
||||
<div v-if="missingQuickAdds.length" class="mt-3 flex flex-wrap gap-2">
|
||||
<button v-for="item in missingQuickAdds"
|
||||
:key="item.key"
|
||||
@click="addSelector(item.key)"
|
||||
class="px-3 py-1.5 rounded-full text-xs font-medium border border-slate-300 dark:border-slate-600 text-slate-700 dark:text-slate-200 hover:bg-white/80 dark:hover:bg-slate-800/80 transition">
|
||||
新增 {{ item.key }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-guide-actions">
|
||||
<button @click="openTutorial('selector-basics')" class="dashboard-guide-btn">
|
||||
<span v-html="$icons.arrowTopRightOnSquare"></span>
|
||||
打开选择器教程
|
||||
</button>
|
||||
<button @click="openPracticeLab()" class="dashboard-guide-btn dashboard-guide-btn--secondary">
|
||||
<span v-html="$icons.folderOpen"></span>
|
||||
打开选择器工作台
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
};
|
||||
@@ -0,0 +1,772 @@
|
||||
// ==================== 流式配置面板 ====================
|
||||
|
||||
window.StreamConfigPanel = {
|
||||
name: 'StreamConfigPanel',
|
||||
props: {
|
||||
streamConfig: { type: Object, required: true },
|
||||
currentDomain: { type: String, default: null },
|
||||
collapsed: { type: Boolean, default: true }
|
||||
},
|
||||
emits: ['update:collapsed', 'save-stream-config'],
|
||||
data() {
|
||||
return {
|
||||
availableParsers: [],
|
||||
loadingParsers: false,
|
||||
loadingTransportProfiles: false,
|
||||
guideExpanded: false,
|
||||
networkStepsExpanded: false,
|
||||
requestTransportMeta: {
|
||||
defaults: {
|
||||
mode: 'workflow',
|
||||
profile: '',
|
||||
options: {}
|
||||
},
|
||||
mode_options: ['workflow', 'page_fetch'],
|
||||
profiles: []
|
||||
},
|
||||
streamMatchModeOptions: [
|
||||
{
|
||||
value: 'keyword',
|
||||
label: '关键词',
|
||||
description: '直接判断 URL 是否包含指定文本,适合大多数站点。'
|
||||
},
|
||||
{
|
||||
value: 'regex',
|
||||
label: '正则',
|
||||
description: '用正则精确筛选目标 URL,适合需要排除 prepare 之类噪音请求的站点。'
|
||||
}
|
||||
],
|
||||
defaultNetworkConfig: {
|
||||
listen_pattern: '',
|
||||
stream_match_mode: 'keyword',
|
||||
stream_match_pattern: '',
|
||||
parser: '',
|
||||
silence_threshold: 3.0,
|
||||
response_interval: 0.5
|
||||
}
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isNetworkMode() {
|
||||
return this.streamConfig.mode === 'network';
|
||||
},
|
||||
|
||||
requestTransportConfig() {
|
||||
const defaults = (this.requestTransportMeta && this.requestTransportMeta.defaults) || {
|
||||
mode: 'workflow',
|
||||
profile: '',
|
||||
options: {}
|
||||
};
|
||||
const current = (this.streamConfig && this.streamConfig.request_transport) || {};
|
||||
return {
|
||||
...defaults,
|
||||
...current,
|
||||
options: {
|
||||
...((defaults && defaults.options) || {}),
|
||||
...((current && current.options) || {})
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
requestTransportModeOptions() {
|
||||
const options = (this.requestTransportMeta && this.requestTransportMeta.mode_options) || ['workflow', 'page_fetch'];
|
||||
return options.map(value => ({
|
||||
value,
|
||||
label: value === 'page_fetch' ? '页面直发' : '工作流模拟'
|
||||
}));
|
||||
},
|
||||
|
||||
availableRequestTransportProfiles() {
|
||||
const profiles = (this.requestTransportMeta && this.requestTransportMeta.profiles) || [];
|
||||
const parserId = String(this.networkConfig.parser || '').trim().toLowerCase();
|
||||
const domain = String(this.currentDomain || '').trim().toLowerCase();
|
||||
return profiles.filter(profile => {
|
||||
const supportedParsers = Array.isArray(profile.supported_parsers) ? profile.supported_parsers : [];
|
||||
const supportedDomains = Array.isArray(profile.supported_domains) ? profile.supported_domains : [];
|
||||
const parserOkay = supportedParsers.length === 0 || supportedParsers.includes(parserId);
|
||||
const domainOkay = supportedDomains.length === 0 || supportedDomains.includes(domain);
|
||||
return parserOkay && domainOkay;
|
||||
});
|
||||
},
|
||||
|
||||
selectedRequestTransportProfileMeta() {
|
||||
const currentProfile = String(this.requestTransportConfig.profile || '').trim();
|
||||
return this.availableRequestTransportProfiles.find(profile => profile.id === currentProfile) || null;
|
||||
},
|
||||
|
||||
networkConfig() {
|
||||
return {
|
||||
...this.defaultNetworkConfig,
|
||||
...(this.streamConfig.network || {})
|
||||
};
|
||||
},
|
||||
|
||||
sendConfirmationConfig() {
|
||||
const defaults = {
|
||||
max_retry_count: 2,
|
||||
retry_interval: 0.6,
|
||||
retry_cooldown_window: 1.5,
|
||||
post_click_observe_window: 1.8,
|
||||
pre_retry_probe_window: 0.12,
|
||||
retry_observe_window: 0.9,
|
||||
retry_action: 'click_send_btn',
|
||||
retry_key_combo: 'Enter',
|
||||
retry_on_unconfirmed_send: true,
|
||||
retry_block_on_stop_button: true,
|
||||
retry_block_if_generating: true,
|
||||
trust_network_activity: true,
|
||||
trust_generating_indicator: true,
|
||||
trust_send_disabled_with_input_shrink: true,
|
||||
pre_send_interrupt_existing_generation: true
|
||||
};
|
||||
return {
|
||||
...defaults,
|
||||
...((this.streamConfig && this.streamConfig.send_confirmation) || {})
|
||||
};
|
||||
},
|
||||
|
||||
sendConfirmationSummary() {
|
||||
if (!this.sendConfirmationConfig.retry_on_unconfirmed_send || Number(this.sendConfirmationConfig.max_retry_count) <= 0) {
|
||||
return '不自动补点';
|
||||
}
|
||||
return '最多重试 ' + Number(this.sendConfirmationConfig.max_retry_count || 0) + ' 次';
|
||||
},
|
||||
|
||||
selectedParserMeta() {
|
||||
return this.findParserMeta(this.networkConfig.parser);
|
||||
},
|
||||
|
||||
preferredPattern() {
|
||||
const parserId = String(this.networkConfig.parser || '').trim();
|
||||
if (!parserId) {
|
||||
return '';
|
||||
}
|
||||
return this.getPreferredListenPattern(parserId);
|
||||
},
|
||||
|
||||
selectedStreamMatchModeMeta() {
|
||||
return this.streamMatchModeOptions.find(
|
||||
option => option.value === this.networkConfig.stream_match_mode
|
||||
) || this.streamMatchModeOptions[0];
|
||||
},
|
||||
|
||||
networkChecklist() {
|
||||
return [
|
||||
{
|
||||
label: 'listen_pattern',
|
||||
ready: String(this.networkConfig.listen_pattern || '').trim().length > 0
|
||||
},
|
||||
{
|
||||
label: 'parser',
|
||||
ready: String(this.networkConfig.parser || '').trim().length > 0
|
||||
},
|
||||
{
|
||||
label: '超时参数',
|
||||
ready: Number(this.streamConfig.hard_timeout) > 0 && Number(this.networkConfig.silence_threshold) > 0
|
||||
}
|
||||
];
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
// 修复:组件被 v-show 复用时不会重新 mounted,切到 network 模式的站点后
|
||||
// availableParsers 仍为空,导致已配置的解析器在下拉里匹配不到 option
|
||||
isNetworkMode: {
|
||||
immediate: true,
|
||||
handler(value) {
|
||||
if (value && !(this.availableParsers || []).length && !this.loadingParsers) {
|
||||
this.loadParsers();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.loadTransportProfiles();
|
||||
if (this.isNetworkMode) {
|
||||
this.loadParsers();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
buildAuthHeaders(extraHeaders = {}) {
|
||||
const token = String(window.getDashboardAuthToken ? window.getDashboardAuthToken() : '').trim();
|
||||
const headers = { ...extraHeaders };
|
||||
if (token) {
|
||||
headers['Authorization'] = 'Bearer ' + token;
|
||||
}
|
||||
return headers;
|
||||
},
|
||||
|
||||
toggle() {
|
||||
this.$emit('update:collapsed', !this.collapsed);
|
||||
},
|
||||
|
||||
updateField(field, value) {
|
||||
const newConfig = { ...this.streamConfig, [field]: value };
|
||||
this.$emit('save-stream-config', newConfig);
|
||||
},
|
||||
|
||||
updateRequestTransportField(field, value) {
|
||||
const request_transport = {
|
||||
...this.requestTransportConfig,
|
||||
[field]: value
|
||||
};
|
||||
if (field === 'mode' && value !== 'page_fetch') {
|
||||
request_transport.profile = '';
|
||||
request_transport.options = {};
|
||||
}
|
||||
if (field === 'profile') {
|
||||
const profile = this.availableRequestTransportProfiles.find(item => item.id === value);
|
||||
const nextOptions = {};
|
||||
(profile && Array.isArray(profile.options) ? profile.options : []).forEach(option => {
|
||||
nextOptions[option.key] = option.default;
|
||||
});
|
||||
request_transport.options = nextOptions;
|
||||
}
|
||||
const newConfig = { ...this.streamConfig, request_transport };
|
||||
this.$emit('save-stream-config', newConfig);
|
||||
},
|
||||
|
||||
updateRequestTransportOption(key, value) {
|
||||
const request_transport = {
|
||||
...this.requestTransportConfig,
|
||||
options: {
|
||||
...(this.requestTransportConfig.options || {}),
|
||||
[key]: value
|
||||
}
|
||||
};
|
||||
const newConfig = { ...this.streamConfig, request_transport };
|
||||
this.$emit('save-stream-config', newConfig);
|
||||
},
|
||||
|
||||
updateNetworkField(field, value) {
|
||||
const network = { ...this.networkConfig, [field]: value };
|
||||
const newConfig = { ...this.streamConfig, network };
|
||||
this.$emit('save-stream-config', newConfig);
|
||||
},
|
||||
|
||||
updateSendConfirmationField(field, value) {
|
||||
const send_confirmation = {
|
||||
...this.sendConfirmationConfig,
|
||||
[field]: value
|
||||
};
|
||||
const newConfig = { ...this.streamConfig, send_confirmation };
|
||||
this.$emit('save-stream-config', newConfig);
|
||||
},
|
||||
|
||||
openInNewTab(url) {
|
||||
const target = String(url || '').trim();
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
window.open(target, '_blank', 'noopener,noreferrer');
|
||||
},
|
||||
|
||||
openTutorial(anchor = 'non-stream-listener-basics') {
|
||||
this.openInNewTab('/static/tutorial/index.html#' + encodeURIComponent(anchor));
|
||||
},
|
||||
|
||||
findParserMeta(parserId) {
|
||||
return this.availableParsers.find(parser => parser.id === parserId) || null;
|
||||
},
|
||||
|
||||
getPreferredListenPattern(parserId) {
|
||||
const parser = this.findParserMeta(parserId);
|
||||
if (!parser || !Array.isArray(parser.patterns) || parser.patterns.length === 0) {
|
||||
return '';
|
||||
}
|
||||
return String(parser.patterns[0] || '').replace(/^\*\*\//, '');
|
||||
},
|
||||
|
||||
usePreferredPattern() {
|
||||
if (!this.preferredPattern) {
|
||||
return;
|
||||
}
|
||||
this.updateNetworkField('listen_pattern', this.preferredPattern);
|
||||
},
|
||||
|
||||
handleParserChange(parserId) {
|
||||
const currentPattern = (this.networkConfig.listen_pattern || '').trim();
|
||||
const nextPattern = currentPattern || this.getPreferredListenPattern(parserId);
|
||||
const network = {
|
||||
...this.networkConfig,
|
||||
parser: parserId,
|
||||
listen_pattern: nextPattern
|
||||
};
|
||||
const newConfig = { ...this.streamConfig, network };
|
||||
this.$emit('save-stream-config', newConfig);
|
||||
},
|
||||
|
||||
autofillListenPatternFromCurrentParser() {
|
||||
const parserId = (this.networkConfig.parser || '').trim();
|
||||
const currentPattern = (this.networkConfig.listen_pattern || '').trim();
|
||||
if (!parserId || currentPattern) {
|
||||
return;
|
||||
}
|
||||
|
||||
const suggestedPattern = this.getPreferredListenPattern(parserId);
|
||||
if (!suggestedPattern) {
|
||||
return;
|
||||
}
|
||||
|
||||
const network = {
|
||||
...this.networkConfig,
|
||||
listen_pattern: suggestedPattern
|
||||
};
|
||||
const newConfig = { ...this.streamConfig, network };
|
||||
this.$emit('save-stream-config', newConfig);
|
||||
},
|
||||
|
||||
toggleNetworkMode() {
|
||||
if (this.isNetworkMode) {
|
||||
this.updateField('mode', 'dom');
|
||||
} else {
|
||||
const newConfig = {
|
||||
...this.streamConfig,
|
||||
mode: 'network',
|
||||
network: this.streamConfig.network || { ...this.defaultNetworkConfig }
|
||||
};
|
||||
this.$emit('save-stream-config', newConfig);
|
||||
if (this.availableParsers.length === 0) {
|
||||
this.loadParsers();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async loadParsers() {
|
||||
if (this.loadingParsers) return;
|
||||
this.loadingParsers = true;
|
||||
try {
|
||||
const response = await fetch('/api/parsers', {
|
||||
headers: this.buildAuthHeaders()
|
||||
});
|
||||
if (!response.ok) {
|
||||
const err = await response.json().catch(() => ({}));
|
||||
throw new Error(err.detail || ('HTTP ' + response.status));
|
||||
}
|
||||
const data = await response.json();
|
||||
this.availableParsers = data.parsers || [];
|
||||
this.autofillListenPatternFromCurrentParser();
|
||||
} catch (e) {
|
||||
console.error('加载解析器失败:', e);
|
||||
} finally {
|
||||
this.loadingParsers = false;
|
||||
}
|
||||
},
|
||||
|
||||
async loadTransportProfiles() {
|
||||
if (this.loadingTransportProfiles) return;
|
||||
this.loadingTransportProfiles = true;
|
||||
try {
|
||||
const response = await fetch('/api/settings/stream-config-defaults', {
|
||||
headers: this.buildAuthHeaders()
|
||||
});
|
||||
if (!response.ok) {
|
||||
const err = await response.json().catch(() => ({}));
|
||||
throw new Error(err.detail || ('HTTP ' + response.status));
|
||||
}
|
||||
const data = await response.json();
|
||||
const requestTransport = data.request_transport || {};
|
||||
this.requestTransportMeta = {
|
||||
defaults: requestTransport.defaults || {
|
||||
mode: 'workflow',
|
||||
profile: '',
|
||||
options: {}
|
||||
},
|
||||
mode_options: requestTransport.mode_options || ['workflow', 'page_fetch'],
|
||||
profiles: requestTransport.profiles || []
|
||||
};
|
||||
} catch (e) {
|
||||
console.error('加载发送方式配置失败:', e);
|
||||
} finally {
|
||||
this.loadingTransportProfiles = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="cap-panel cap-response-panel bg-white dark:bg-gray-800 border dark:border-gray-700 rounded-lg shadow-sm">
|
||||
<!-- 标题栏 -->
|
||||
<div class="px-4 py-3 border-b dark:border-gray-700 flex justify-between items-center cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors"
|
||||
@click="toggle">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="w-4 inline-flex justify-center text-gray-500 dark:text-gray-400" v-html="collapsed ? $icons.chevronDown : $icons.chevronUp"></span>
|
||||
<h3 class="font-semibold text-gray-900 dark:text-white">从哪里读取回复</h3>
|
||||
<span v-if="isNetworkMode" class="text-xs font-medium px-2 py-0.5 rounded bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-400">已启用</span>
|
||||
<span v-else class="text-xs font-medium px-2 py-0.5 rounded bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-400">DOM 流式</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 内容 -->
|
||||
<div v-show="!collapsed" class="p-4 space-y-4"><div class="cap-response-explainer"><span class="cap-icon" v-html="$icons.documentArrowDown"></span><div><h4>{{ isNetworkMode ? '正在读取网络响应' : '正在读取网页上显示的回复' }}</h4><p>{{ isNetworkMode ? '适合保留代码、公式等原始内容,需要正确的请求匹配和解析器。' : '观察页面文字的变化来返回回复。首次适配站点时,可以先沿用这种方式。' }}</p><small>开启开关后读取网络响应,关闭则读取页面内容;切换可能影响现有回复解析。</small></div><label class="cap-switch"><span class="cap-state">{{ isNetworkMode ? '网络读取' : '网页读取' }}</span><input role="switch" type="checkbox" aria-label="从网络读取回复" :checked="isNetworkMode" @change="toggleNetworkMode" class="cap-switch-input"><i aria-hidden="true"></i></label></div>
|
||||
<div v-if="!guideExpanded">
|
||||
<button @click="guideExpanded = true" type="button" class="dashboard-guide-toggle dashboard-guide-toggle--violet">
|
||||
<span>网络模式引导</span>
|
||||
<span v-html="$icons.chevronDown"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-else class="dashboard-guide-card dashboard-guide-card--violet">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<span class="dashboard-guide-badge">先判断场景,再动开关</span>
|
||||
<button @click="guideExpanded = false" type="button" class="dashboard-guide-toggle dashboard-guide-toggle--violet">
|
||||
<span>收起</span>
|
||||
<span v-html="$icons.chevronUp"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<div class="text-base font-semibold text-slate-900 dark:text-slate-50">
|
||||
DOM 模式与网络监听模式
|
||||
</div>
|
||||
<p class="mt-1.5 text-sm leading-6 text-slate-600 dark:text-slate-300">
|
||||
网络监听会优先读取底层请求响应;如果站点走的是 <strong>fetch/xhr 流式</strong>,现在可以直接增量输出;如果站点本身返回的是整包 JSON / 文本,那它看起来仍会像一次性完成。DOM 模式则是盯着页面展示内容变化来输出。遇到复杂 JSON、代码块或 LaTeX 数学公式时,网络监听通常更容易拿到干净原文。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-checklist">
|
||||
<div v-for="item in networkChecklist"
|
||||
:key="item.label"
|
||||
:class="['dashboard-checklist-item', item.ready ? 'is-ready' : 'is-missing']">
|
||||
<span>{{ item.ready ? '✓' : '•' }}</span>
|
||||
<span>{{ item.label }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-guide-actions">
|
||||
<button @click="openTutorial('non-stream-listener-basics')" class="dashboard-guide-btn">
|
||||
<span v-html="$icons.arrowTopRightOnSquare"></span>
|
||||
DOM 和网络监听区别
|
||||
</button>
|
||||
<button @click="openTutorial('non-stream-parser-guide')" class="dashboard-guide-btn dashboard-guide-btn--secondary">
|
||||
<span v-html="$icons.folderOpen"></span>
|
||||
网络解析器教程
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 网络模式配置 -->
|
||||
<details v-if="isNetworkMode" class="cap-settings"><summary><span><strong>配置网络响应识别</strong><small>先指定请求关键词,再选择解析器。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body">
|
||||
<details class="cap-technical"><summary><span><strong>请求发送方式(高级)</strong><small>网页工作流或页面接口直发;仅在明确需要更换发送方式时设置。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><div class="rounded-lg border border-slate-200/70 bg-slate-50/80 p-4 dark:border-slate-700 dark:bg-slate-900/40 space-y-4">
|
||||
<div class="text-sm font-medium text-gray-700 dark:text-gray-300 flex items-center gap-2">
|
||||
<span>🚀</span>
|
||||
<span>发送方式</span>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">发送模式</label>
|
||||
<select :value="requestTransportConfig.mode"
|
||||
@change="updateRequestTransportField('mode', $event.target.value)"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-400 focus:border-transparent">
|
||||
<option v-for="option in requestTransportModeOptions" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div v-if="requestTransportConfig.mode === 'page_fetch'">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">发送 Profile</label>
|
||||
<select :value="requestTransportConfig.profile"
|
||||
@change="updateRequestTransportField('profile', $event.target.value)"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-400 focus:border-transparent">
|
||||
<option value="" disabled>{{ loadingTransportProfiles ? '加载中...' : '选择发送 profile...' }}</option>
|
||||
<option v-for="profile in availableRequestTransportProfiles" :key="profile.id" :value="profile.id">{{ profile.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedRequestTransportProfileMeta" class="space-y-4">
|
||||
<p class="text-xs leading-5 text-slate-500 dark:text-slate-400">
|
||||
{{ selectedRequestTransportProfileMeta.description }}
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<template v-for="option in selectedRequestTransportProfileMeta.options" :key="option.key">
|
||||
<div v-if="option.type === 'enum'">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{{ option.label }}</label>
|
||||
<select :value="requestTransportConfig.options[option.key]"
|
||||
@change="updateRequestTransportOption(option.key, $event.target.value)"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-400 focus:border-transparent">
|
||||
<option v-for="choice in option.choices" :key="choice.value" :value="choice.value">{{ choice.label }}</option>
|
||||
</select>
|
||||
<p v-if="option.description" class="mt-1 text-xs text-gray-500 dark:text-gray-400">{{ option.description }}</p>
|
||||
</div>
|
||||
<div v-else-if="option.type === 'string'">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{{ option.label }}</label>
|
||||
<input type="text"
|
||||
:value="requestTransportConfig.options[option.key]"
|
||||
@input="updateRequestTransportOption(option.key, $event.target.value)"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-400 focus:border-transparent">
|
||||
<p v-if="option.description" class="mt-1 text-xs text-gray-500 dark:text-gray-400">{{ option.description }}</p>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div></div></details>
|
||||
|
||||
<div>
|
||||
<button v-if="!networkStepsExpanded"
|
||||
@click="networkStepsExpanded = true"
|
||||
type="button"
|
||||
class="dashboard-guide-toggle dashboard-guide-toggle--violet">
|
||||
<span>配置步骤</span>
|
||||
<span v-html="$icons.chevronDown"></span>
|
||||
</button>
|
||||
<div v-else class="space-y-3">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div class="text-xs font-medium uppercase tracking-[0.18em] text-slate-400 dark:text-slate-500">
|
||||
三步看完再填
|
||||
</div>
|
||||
<button @click="networkStepsExpanded = false"
|
||||
type="button"
|
||||
class="dashboard-guide-toggle dashboard-guide-toggle--violet">
|
||||
<span>收起</span>
|
||||
<span v-html="$icons.chevronUp"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||||
<div class="dashboard-mini-card">
|
||||
<div class="dashboard-mini-card-title">第 1 步:锁定请求关键词</div>
|
||||
<div class="dashboard-mini-card-copy">先找目标请求 URL 里最稳定的一小段路径,填进 <code>listen_pattern</code>。</div>
|
||||
</div>
|
||||
<div class="dashboard-mini-card">
|
||||
<div class="dashboard-mini-card-title">第 2 步:选对解析器</div>
|
||||
<div class="dashboard-mini-card-copy">有内置解析器就直接选;没有时先按教程导出请求,让 AI 帮你写 parser。</div>
|
||||
</div>
|
||||
<div class="dashboard-mini-card">
|
||||
<div class="dashboard-mini-card-title">第 3 步:补超时</div>
|
||||
<div class="dashboard-mini-card-copy">慢站点先把全局硬超时和静默超时调高;流式站点主要看静默超时,整包返回站点则更依赖整体等待窗口。</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-sm font-medium text-gray-700 dark:text-gray-300 flex items-center gap-2">
|
||||
<svg class="w-4 h-4 text-purple-500" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z"/>
|
||||
</svg>
|
||||
网络拦截配置
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<div class="flex items-center justify-between gap-3 mb-1">
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">URL 匹配模式 <span class="text-red-500">*</span></label>
|
||||
<button v-if="preferredPattern"
|
||||
@click="usePreferredPattern"
|
||||
type="button"
|
||||
class="text-xs font-medium text-purple-600 dark:text-purple-300 hover:underline">
|
||||
一键填入推荐值
|
||||
</button>
|
||||
</div>
|
||||
<input type="text"
|
||||
:value="networkConfig.listen_pattern"
|
||||
@input="updateNetworkField('listen_pattern', $event.target.value)"
|
||||
placeholder="例如:GenerateContent"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-400 focus:border-transparent">
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
只要 URL 里包含这段字符串,监听器就会尝试拦截。先写窄一点,调通后再看要不要放宽。
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">响应解析器 <span class="text-red-500">*</span></label>
|
||||
<select :value="networkConfig.parser"
|
||||
@change="handleParserChange($event.target.value)"
|
||||
@focus="loadParsers"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-400 focus:border-transparent">
|
||||
<option value="" disabled>{{ loadingParsers ? '加载解析器中...' : '选择解析器...' }}</option>
|
||||
<option v-for="parser in availableParsers" :key="parser.id" :value="parser.id">{{ parser.name }}</option>
|
||||
</select>
|
||||
<p v-if="selectedParserMeta && Array.isArray(selectedParserMeta.patterns) && selectedParserMeta.patterns.length"
|
||||
class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
这个解析器常见监听关键词:<code>{{ preferredPattern }}</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<details class="cap-technical"><summary><span><strong>响应不完整、等待太久或重复发送?</strong><small>流匹配、超时与重试的排查参数。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body"><div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">流目标匹配模式</label>
|
||||
<select :value="networkConfig.stream_match_mode"
|
||||
@change="updateNetworkField('stream_match_mode', $event.target.value)"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-400 focus:border-transparent">
|
||||
<option v-for="option in streamMatchModeOptions" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
{{ selectedStreamMatchModeMeta.description }}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">流目标匹配表达式</label>
|
||||
<input type="text"
|
||||
:value="networkConfig.stream_match_pattern"
|
||||
@input="updateNetworkField('stream_match_pattern', $event.target.value)"
|
||||
placeholder="留空时默认沿用 listen_pattern"
|
||||
class="w-full border dark:border-gray-600 px-3 py-2 rounded-md text-sm font-mono bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-400 focus:border-transparent">
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
<code>keyword</code> 模式下填 URL 子串,<code>regex</code> 模式下填正则;留空时回退到 <code>listen_pattern</code>。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">静默超时</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number" :value="networkConfig.silence_threshold" @input="updateNetworkField('silence_threshold', parseFloat($event.target.value) || 3)"
|
||||
min="0.5" max="30" step="0.5" class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">轮询间隔</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number" :value="networkConfig.response_interval" @input="updateNetworkField('response_interval', parseFloat($event.target.value) || 0.5)"
|
||||
min="0.1" max="5" step="0.1" class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-purple-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-xl border border-amber-200/80 dark:border-amber-800/70 bg-amber-50/70 dark:bg-amber-900/20 p-4">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-gray-800 dark:text-gray-100">发送确认与重试</div>
|
||||
<p class="mt-1 text-xs leading-5 text-gray-600 dark:text-gray-300">
|
||||
控制点击 <code>send_btn</code> 后,如果没有马上观察到输入框清空、网络活动或生成态,是否自动再点一次。Battle 模式里通常应关闭自动重试,避免第二次点击方形按钮变成中断输出。
|
||||
</p>
|
||||
</div>
|
||||
<span class="px-2 py-0.5 text-xs rounded-full bg-white/80 dark:bg-gray-800/80 text-amber-700 dark:text-amber-300 border border-amber-200 dark:border-amber-700">
|
||||
{{ sendConfirmationSummary }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">首次点击观察窗</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="sendConfirmationConfig.post_click_observe_window"
|
||||
@input="updateSendConfirmationField('post_click_observe_window', parseFloat($event.target.value) || 0)"
|
||||
min="0"
|
||||
max="15"
|
||||
step="0.1"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-amber-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">最大重试次数</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="sendConfirmationConfig.max_retry_count"
|
||||
@input="updateSendConfirmationField('max_retry_count', parseInt($event.target.value) || 0)"
|
||||
min="0"
|
||||
max="10"
|
||||
step="1"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-amber-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">次</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">重试间隔</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number"
|
||||
:value="sendConfirmationConfig.retry_interval"
|
||||
@input="updateSendConfirmationField('retry_interval', parseFloat($event.target.value) || 0)"
|
||||
min="0"
|
||||
max="30"
|
||||
step="0.1"
|
||||
class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-amber-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="sendConfirmationConfig.retry_on_unconfirmed_send"
|
||||
@change="updateSendConfirmationField('retry_on_unconfirmed_send', $event.target.checked)">
|
||||
<span>发送未确认时允许自动重试</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="sendConfirmationConfig.retry_block_on_stop_button"
|
||||
@change="updateSendConfirmationField('retry_block_on_stop_button', $event.target.checked)">
|
||||
<span>发送按钮变成 stop 时禁止重试</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="sendConfirmationConfig.retry_block_if_generating"
|
||||
@change="updateSendConfirmationField('retry_block_if_generating', $event.target.checked)">
|
||||
<span>页面进入生成态时禁止重试</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="sendConfirmationConfig.trust_generating_indicator"
|
||||
@change="updateSendConfirmationField('trust_generating_indicator', $event.target.checked)">
|
||||
<span>生成态可作为发送成功信号</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-3 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||||
<input type="checkbox"
|
||||
class="rounded"
|
||||
:checked="sendConfirmationConfig.pre_send_interrupt_existing_generation"
|
||||
@change="updateSendConfirmationField('pre_send_interrupt_existing_generation', $event.target.checked)">
|
||||
<span>发送前主动打断旧生成态 (Arena)</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!networkConfig.listen_pattern || !networkConfig.parser"
|
||||
class="bg-yellow-50 dark:bg-yellow-900/30 border border-yellow-200 dark:border-yellow-800 rounded-xl p-3">
|
||||
<div class="flex items-start gap-2">
|
||||
<svg class="w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/>
|
||||
</svg>
|
||||
<div class="text-sm text-yellow-700 dark:text-yellow-300">
|
||||
<span class="font-medium">还差关键字段</span>
|
||||
<p class="mt-0.5 text-xs leading-5">
|
||||
先把 <code>listen_pattern</code> 和 <code>parser</code> 补齐,再开始调超时参数。当前直接测试,基本只会得到空结果或回退。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div></details></div></details>
|
||||
|
||||
<!-- DOM 模式说明 -->
|
||||
<div v-else class="dashboard-mini-card">
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<div class="dashboard-mini-card-title">DOM 轮询模式</div>
|
||||
<div class="dashboard-mini-card-copy">
|
||||
这个模式会盯着页面元素变化来判断回复是否结束。兼容性最好,第一次适配新站点时也更容易跑通。
|
||||
</div>
|
||||
</div>
|
||||
<button @click="openTutorial('response-detection')"
|
||||
type="button"
|
||||
class="text-xs font-medium text-blue-600 dark:text-blue-300 hover:underline shrink-0">
|
||||
打开章节
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 通用配置 -->
|
||||
<details class="cap-troubleshoot"><summary><span><strong>回复一直不结束?</strong><small>调整一次对话最多允许等待的时间。</small></span><span class="cap-chevron" v-html="$icons.chevronDown"></span></summary><div class="cap-settings-body">
|
||||
<div class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">通用配置</div>
|
||||
<div class="grid grid-cols-1 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">全局硬超时</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="number" :value="streamConfig.hard_timeout" @input="updateField('hard_timeout', parseInt($event.target.value) || 300)"
|
||||
min="10" max="600" step="10" class="flex-1 border dark:border-gray-600 px-3 py-2 rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-blue-400 focus:border-transparent">
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">秒</span>
|
||||
</div>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
网络监听里,这就是一次完整对话允许等待的最长时间。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div></details>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
};
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user