/** * ui/profile-sync.js — API Profile → 子面板 UI 同步 * * 当某功能槽分配了 Profile 时: * 1. 隐藏对应功能区的 API 连接配置字段(保留温度/Token 等生成参数) * 2. 注入一张状态卡,显示 Profile 信息 + 测试连接 / 获取模型按钮 * * 当槽位未分配时:恢复旧字段显示,移除状态卡。 * * 用法: * import { syncAllSlots, syncSlot } from './profile-sync.js'; * await syncAllSlots(); // 面板初始化时全量同步 * await syncSlot('main'); // 单个槽位分配变更时调用 * * 外部事件: * document 上监听 'amily2:slotAssigned',detail = { slot } * 由 api-config-bindings.js 在分配变更后 dispatch。 */ import { apiProfileManager } from '../utils/config/ApiProfileManager.js'; import { getRequestHeaders } from '/script.js'; import { testApiConnection } from '../core/api.js'; import { testConcurrentApiConnection } from '../core/api/ConcurrentApi.js'; import { testNgmsApiConnection } from '../core/api/Ngms_api.js'; import { testNccsApiConnection } from '../core/api/NccsApi.js'; // ── 常量 ────────────────────────────────────────────────────────────────────── // 用于通过子元素定位父 block 的选择器 const BLOCK_SEL = '.amily2_settings_block, .control-group, .amily2_opt_settings_block'; const CARD_CLASS = 'amily2_profile_status_card'; const CARD_SLOT_ATTR = 'data-card-slot'; const HIDDEN_ATTR = 'data-profile-hidden'; // ── 槽位 → DOM 映射 ─────────────────────────────────────────────────────────── // // container : 状态卡注入的父容器(CSS 选择器或 'closest-fieldset:xxx') // hideParentBlock: 通过子元素选择器找到其最近的 BLOCK_SEL 父元素并隐藏 // hideDirectly : 直接隐藏的元素选择器 // hideWithLabel : 隐藏元素(上溯到容器直接子元素)+ 前一个兄弟