// ==================== 文件粘贴 / 附件发送配置面板 ==================== 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: `
把图片、文档或音视频交给 AI。网站本身也需要支持这些文件。
最多 {{ resolvedAttachments.max_count }} 个文件 · 单个 {{ resolvedAttachments.max_file_mb }} MB · 合计 {{ resolvedAttachments.max_total_mb }} MB
已关闭附件上传;长文本也不能转为文件发送。普通文本仍可使用。
{{ transport.description }}
已启用有损图片剪贴板兼容。需要原文件保真时,请停用此方式。
支持 image_url、OpenAI file / Responses input_file、Anthropic document、input_audio 与音视频 URL。文件 ID、本地路径和 file:// 暂不支持;原始附件内容不会降级为提示词。
{"type":"file","file":{"filename":"notes.txt","file_data":"data:text/plain;base64,aGVsbG8="}}
通用附件管线的配置存储在当前预设的 file_paste.attachments 中,旧配置无需手动迁移。选择器仍在「元素选择器」,就绪探针在下方「高级附件规则」。MB 按 1024² 字节计算。
文字太长、网页放不下时,选择转成文件、分段发送或中止请求。
{{ resolvedFilePaste.enabled ? '超过 ' + resolvedFilePaste.threshold + ' 字符时处理' : '当前不启用额外的长文本处理' }} · {{ longTextStrategy === 'attachment' ? '转成文件' : longTextStrategy === 'chunk' ? '分段发送' : '中止并报错' }}
转成文件需要先允许附件上传。分段发送会逐轮等待,只返回最后一轮回复。
这些规则会影响所有附件。先确认网页上是否真的发出了消息,再调整等待或重试。
某些站点二次点击会把“发送”变成“停止”,这时更适合改成按键发送。
仅在“按键发送”时生效,支持 Enter、Ctrl+Enter、Shift+Enter 等组合。
像 Gemini 这类站点,可以在这里补发送按钮灰态 token、附件预览 selector 和 pending 文案。即使文件粘贴没开,这块也会继续影响图片上传和发送前的附件 gate。
每行一个 selector,选择独立附件卡片,不要选择包含输入框的大容器;嵌套图片不会重复计数。
每行一个 selector,命中后会继续等待,不会急着发送。
只匹配附件状态提示和发送按钮,不扫描提示词、文件名或文件预览正文。
填发送按钮 class / title / aria-label 里会出现的关键字,命中后视为按钮不可发。
仅用于排除站点特有的状态词。正文与文件名会自动排除,不需要在这里逐个添加。
当通用根容器猜错时再填。这里会限制附件节点和 pending 节点的查找范围。
探针会收到一个参数对象,包含 stage 和 monitorState。返回结构建议包含 uploading、ready、accepted、confirmed、retry、shouldRetry、summary 这些字段。