Files
ST-Amily2-Chat-Optimisation/assets/amily-hanlinyuan-system/hanlinyuan.html
Jenkins CI 0d7e3b799e release: v2.2.6 [2026-06-13 01:02:05]
### 新功能
- **翰林院向量化质量升级**:
  - **边界感知切块**:替换四个来源(聊天记录/小说/世界书/手动)的纯字符硬切——优先在段落边界断开,其次句末标点(含中文引号闭合),极端长串才硬切;句子/对话不再被拦腰截断,embedding 质量同步受益。仅影响新录入,已有向量无需重建
  - **注入时序重排**:检索结果注入提示词前按时序重排(聊天记录按楼层、小说按卷/章/节——中文数字章节号可解析),rerank 只决定"选哪些块",不再决定呈现顺序;修复"不打不相识的剧情之后紧跟关系亲密"这类因按相关度排序导致的认知时间错乱
  - **断层提示**:聊天记录相邻块楼层跳跃时自动插入"与上文相隔约 N 楼,并非连续发生"提示行,消除中间剧情缺失造成的割裂感
  - **时间标识**:新录入的聊天记录块在来源标识中带上消息发送时间(ST 向量存储不持久化元数据,时间必须写入块文本才能在检索后取回;旧格式块兼容解析)
- **记忆块工作流(memory-blocks)**:剧情优化新增"自定义记忆块"体系——占位符驱动的并发工作流框架
  - 在剧情优化面板「匹配替换 (sulv)」下方可增删自定义块:每个块定义一个占位符,执行剧情优化时主/拦截提示词中的占位符会被块的产出替换
  - **静态块**:直接输出固定内容;**AI 调用块**:用所选 API 功能槽独立请求一次,把回复(或其中指定 `<标签>` 的内容)作为替换值
  - 原有 sulv1-4 速率占位符迁入同一框架,行为与旧版逐字节一致
  - 块定义为纯 JSON、随设置持久化,为后续导入导出与战斗系统接入预留扩展点
  - 框架层新增**顺序拼接式 Chain**(`composeChain`):与占位符替换并列的第二种组合范式——同链的块并发执行后按 `order` 排序、以 `separator` 拼接并可选 `header/footer` 包裹,产出一个完整注入块;为记忆注入合成块与战斗系统"底部战报块"预留的承载结构,本版本暂无 UI 入口
- **API 连接配置**:
  - 角色世界书(cwb)与一键生卡(autoCharCard)纳入旧配置自动迁移:老用户首次加载会把旧 URL / Key / 模型自动迁移为连接配置并分配槽位(一键生卡仅在规划者与执行者配置一致或规划者为空时迁移,避免悄悄改变行为)
  - **profile 已分配时参数控件 informational 化**:主面板 / 并发剧情优化 / 角色世界书 / 术语表的温度、maxTokens 控件在槽位分配 profile 后自动禁用并显示"由连接配置控制"提示,消除"改了没效果"的用户陷阱
  - **profile 状态卡新增"本设备无 Key"警示**:API Key 仅保存在最初填写它的设备/浏览器上(安全设计,不随云端设置同步),换设备后状态卡会直接亮出警示徽标,不必等到调用报错才发现
### 修复
- **独立聊天记忆从摆设变真功能(原作遗留坑)**:此前向量数据"随卡不随聊天"——开启"独立聊天记忆"后录入仍存进角色库、查询却去查一个从未被写入过的聊天集合、计数恒为 0,整体静默失效。现已重构为聊天级分桶:
  - 独立模式下,聊天记录类向量按当前聊天隔离存储与检索,同一张卡开多个聊天(不同剧情线)的记忆互不污染
  - 小说 / 世界书 / 手动录入属于"知识",仍随角色卡跨聊天共享;全局库不受影响
  - 知识管理列表为聊天专属库显示"聊天级"徽标;聊天级库禁止移动到全局
  - 统一模式(默认关闭独立记忆)的存量数据与行为完全不变
  - 已知限制:聊天专属记忆跟随聊天文件,重命名聊天文件会使其失联(与 ST 官方向量扩展同等限制)
- **超级排序截断顺序修正**:开启"超级排序"时,时序重排发生在 top_n 截断之前,导致保留的是"时序最早"而非"最相关"的块,检索结果长期偏向最旧的聊天记录。现改为先按相关度截取 top_n、再做时序排序
- **翰林院向量化失败("向量化块数量不识别"反馈)**:
  - 一次性清洗 profile-sync 历史污染:`retrieval/rerank.apiKey` 中的掩码占位符在持久层根治(此前仅读取侧防御);`apiEndpoint` / `rerank.apiMode` 的非法值(如被旧版写入的空字符串)归一化为 `custom`
  - 修复 `apiEndpoint` 为空/非法时请求被硬定向到 `api.openai.com`、无视用户自定义 URL 的问题(CSP 拦截 / 401 的元凶)
  - 修复**本地代理(LM Studio/Ollama)模式**自始就缺少 URL 分支、同样被错误定向到 openai.com 的问题
  - API 模式下拉补全 `OpenAI 官方` / `Azure` 选项;默认 API 模式改为 `custom`(与默认 URL 配套),新用户不再因选项缺失导致首次保存写入空值
  - profile-sync 给下拉框赋不存在选项值的污染源头修复(影响所有模块面板,不止翰林院)
- **Rerank "API Key 未提供"报错升级**:当原因是"连接配置在本设备没有可用 Key"时,报错会直接说明 Key 的设备本地性并指引到 API 连接配置重新填写(向量化 Google 直连、获取模型列表同步处理)
- **旧配置迁移**:一键生卡迁移时排除掩码占位符,避免把历史污染的假 Key 迁入新连接配置
- **超级记忆稳定性专项**(针对"工作不大稳定"反馈,4 处根因一次修复):
  - **切聊天竞态污染**:CHAT_CHANGED 时超级记忆立即全量同步,而表格系统延迟 100ms 才加载新聊天的表格,导致【旧聊天】的表格内容被写进【新角色】的记忆世界书;两边表名不同时旧表条目无 GC 兜底会**永久残留**("记忆串台"元凶)。现 CHAT_CHANGED 只确保世界书存在,新状态同步交由 `loadTables()` 完成后的自动推送,单次且时序正确
  - **死代码双轨存储拆除**:`saveStateToMetadata` / `tryRestoreStateFromMetadata` 把表格状态写到 `msg.metadata`——该字段非 ST 持久化位(同 v2.2.5 二次填表修过的坑),写入即蒸发、恢复永远为空,且每次同步还白调一次 `saveChat()`。整条链路删除,表格状态唯一信源为表格系统的 `msg.extra.amily2_tables_data`
  - **`awaitSync()` 穿透**:同步队列正忙时 `pushUpdate` 会用一个立即 resolve 的空 Promise 覆盖 `_syncPromise`,Pipeline Stage 4 等待形同虚设、后续阶段在同步未完成时被放行。现忙时不覆盖,正在运行的 drain 循环自然吃掉新入队项
  - **开关打开不生效**:启动时若总开关为关,初始化早退且不注册监听器;此后在 UI 勾选开关只写设置,超级记忆直到刷新页面前都是死的。现勾选即触发初始化(幂等)
  - 附带:`forceSyncAll` 的表格角色推断改为复用 `events-schema.inferTableRole`,消除两处重复逻辑漂移风险;每次切聊天的双倍全量同步(restore 路径一次 + 显式一次)随死代码移除归一
### 重构
- 表格核心 `manager.js` 瘦身(约 1050 → 600 行):19 个 UI 突变操作拆分至 `actions/ui-mutations.js`,SuperMemory 事件分发拆分至 `events-dispatch.js`;全部经 re-export 保持兼容,外部调用路径零改动
- 角色世界书最后 2 处散乱的厂商 URL 判断迁移至 `detectVendor` 统一入口,业务路径上不再有硬编码的 URL substring 判断
2026-06-13 01:02:05 +08:00

533 lines
35 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<div class="amily2-header">
<div id="amily2_open_hanlin_tutorial" class="additional-features-title interactable" title="查看翰林院使用教程" style="cursor: pointer;">
<i class="fas fa-landmark-dome"></i> 翰林院 · 忆识核心
</div>
<button id="amily2_back_to_main_from_hanlinyuan" class="menu_button secondary small_button interactable">
返回主殿 <i class="fas fa-arrow-right"></i>
</button>
</div>
<hr class="header-divider">
<div id="hly-modal-container">
<!-- 状态诏书 -->
<div class="hly-imperial-edict">
<fieldset class="hly-settings-group" style="margin-bottom: 10px;">
<legend><i class="fas fa-power-off"></i> 总开关</legend>
<div class="hly-control-block" style="flex-direction: row; justify-content: space-between; align-items: center;">
<label for="hly-retrieval-enabled-toggle">开启忆识检索之权</label>
<label class="hly-toggle-switch">
<input type="checkbox" id="hly-retrieval-enabled" data-setting-key="retrieval.enabled" data-type="boolean">
<span class="slider"></span>
</label>
</div>
<div class="hly-control-block" style="flex-direction: row; justify-content: space-between; align-items: center;">
<label for="hly-rerank-enabled-toggle">启用 Rerank</label>
<label class="hly-toggle-switch">
<input type="checkbox" id="hly-rerank-enabled" data-setting-key="rerank.enabled" data-type="boolean">
<span class="slider"></span>
</label>
</div>
<div class="hly-control-block" style="flex-direction: row; justify-content: space-between; align-items: center;">
<label for="hly-super-sort-enabled-toggle" title="启用后,排序不再依照分数,而是使用绝对正确的排序及分类。">超级排序</label>
<label class="hly-toggle-switch">
<input type="checkbox" id="hly-super-sort-enabled" data-setting-key="rerank.superSortEnabled" data-type="boolean">
<span class="slider"></span>
</label>
</div>
<div class="hly-control-block" style="flex-direction: row; justify-content: space-between; align-items: center;">
<label for="hly-independent-chat-memory-toggle" title="启用后,每个聊天文件都将拥有独立的知识库。关闭后,同一角色的所有聊天将共享同一个知识库。">独立聊天记忆</label>
<label class="hly-toggle-switch">
<input type="checkbox" id="hly-independent-chat-memory-enabled" data-setting-key="retrieval.independentChatMemoryEnabled" data-type="boolean">
<span class="slider"></span>
</label>
</div>
</fieldset>
<div class="hly-edict-row">
<div class="hly-edict-item">
<span class="hly-edict-label">当前会话:</span>
<span id="hly-current-chat-id" class="hly-edict-value">未开启</span>
</div>
<div class="hly-edict-item">
<span class="hly-edict-label">当前辅佐:</span>
<span id="hly-current-character-name" class="hly-edict-value">待命中...</span>
</div>
</div>
<div class="hly-edict-row">
<div class="hly-edict-item hly-memory-display">
<span class="hly-edict-label">忆识总数:</span>
<span id="hly-current-vector-count" class="hly-memory-count">0</span>
<button class="hly-action-button" onclick="updateHLYMemoryCount()" title="刷新忆识总数" style="padding: 4px 8px; font-size: 12px;">
🔄
</button>
</div>
<div class="hly-button-group" style="margin-left: auto;">
<button class="hly-action-button" onclick="purgeHLYStorage()" style="padding: 4px 8px; font-size: 12px;">清空宝库</button>
<button id="hly-session-lock-btn" class="hly-action-button" style="padding: 4px 8px; font-size: 12px;">
<i class="fas fa-lock"></i> <span>锁定会话</span>
</button>
</div>
</div>
</div>
<!-- 司南 -->
<div class="hly-navigation-deck">
<button class="hly-nav-item active" data-tab="retrieval">忆识检索</button>
<button class="hly-nav-item" data-tab="historiography">书库编纂</button>
<button class="hly-nav-item" data-tab="knowledge-bases">知识管理</button>
<button class="hly-nav-item" data-tab="rerank">忆识精炼</button>
<button class="hly-nav-item" data-tab="advanced">高级设定</button>
</div>
<div class="hly-scroll">
<div id="hly-retrieval-tab" class="hly-tab-pane active">
<fieldset class="hly-settings-group">
<legend><i class="fas fa-broadcast-tower"></i> 神力之源 (API)</legend>
<div class="hly-control-block">
<label for="hly-api-endpoint">API模式:</label>
<select id="hly-api-endpoint" class="hly-imperial-brush" data-setting-key="retrieval.apiEndpoint" data-type="string">
<option value="custom">自定义 (OpenAI/Azure 兼容)</option>
<option value="google_direct">Google 直连</option>
<option value="local_proxy">本地代理 (LM Studio/Ollama)</option>
<option value="openai">OpenAI 官方</option>
<option value="azure">Azure (api-key 头)</option>
</select>
</div>
<div class="hly-control-block" id="hly-custom-endpoint-docket">
<label for="hly-custom-api-url">API URL:</label>
<input type="text" id="hly-custom-api-url" class="hly-imperial-brush" placeholder="根据所选模式填写" data-setting-key="retrieval.customApiUrl" data-type="string">
</div>
<div class="hly-control-block" id="hly-api-key-group">
<label for="hly-api-key">通行令牌 (API Key):</label>
<input type="password" id="hly-api-key" class="hly-imperial-brush" placeholder="请在此输入您的通行令牌" data-setting-key="retrieval.apiKey" data-type="string">
</div>
<div class="hly-control-block">
<label for="hly-embedding-model">嵌入模型:</label>
<select id="hly-embedding-model" class="hly-imperial-brush" data-setting-key="retrieval.embeddingModel" data-type="string"></select>
</div>
<div class="hly-button-group">
<button class="hly-action-button" onclick="testHLYApi()">测试神力</button>
<button class="hly-action-button" onclick="fetchHLYEmbeddingModels()">获取模型</button>
<button class="hly-action-button danger" onclick="resetHLYSettings()">重置为初</button>
</div>
</fieldset>
</div>
<div id="hly-rerank-tab" class="hly-tab-pane">
<fieldset class="hly-settings-group">
<legend><i class="fas fa-wand-magic-sparkles"></i> Rerank 精炼</legend>
<div class="hly-control-block">
<label for="hly-rerank-api-mode">Rerank API 模式:</label>
<select id="hly-rerank-api-mode" class="hly-imperial-brush" data-setting-key="rerank.apiMode" data-type="string">
<option value="custom">自定义 (兼容API)</option>
<option value="local_proxy">本地代理</option>
</select>
</div>
<div class="hly-control-block">
<label for="hly-rerank-url">Rerank API 地址:</label>
<input type="text" id="hly-rerank-url" class="hly-imperial-brush" placeholder="根据所选模式填写" data-setting-key="rerank.url" data-type="string">
</div>
<div class="hly-control-block" id="hly-rerank-api-key-group">
<label for="hly-rerank-api-key">Rerank API Key:</label>
<input type="password" id="hly-rerank-api-key" class="hly-imperial-brush" placeholder="请输入您的 Rerank API Key" data-setting-key="rerank.apiKey" data-type="string">
</div>
<div class="hly-control-block">
<label for="hly-rerank-model">Rerank 模型:</label>
<div style="display: flex; width: 100%;">
<select id="hly-rerank-model" class="hly-imperial-brush" data-setting-key="rerank.model" data-type="string" style="flex-grow: 1;"></select>
<button class="hly-action-button" onclick="fetchHLYRerankModels()" style="margin-left: 10px; flex-shrink: 0;">获取模型</button>
</div>
</div>
<div class="hly-control-block">
<label for="hly-rerank-top-n">返回结果数 (top_n):</label>
<input type="number" id="hly-rerank-top-n" class="hly-imperial-brush" value="5" data-setting-key="rerank.top_n" data-type="integer">
</div>
<div class="hly-control-block">
<label for="hly-rerank-hybrid-alpha">混合分数权重 (Alpha):</label>
<input type="number" id="hly-rerank-hybrid-alpha" class="hly-imperial-brush" value="0.7" step="0.1" min="0" max="1" data-setting-key="rerank.hybrid_alpha" data-type="float">
<small class="hly-notes">Rerank分数权重。1.0表示只用Rerank分数0.0表示只用原始相似度分数。</small>
</div>
<div class="hly-control-block" style="flex-direction: row; justify-content: space-between; align-items: center;">
<label for="hly-rerank-notify-toggle">Rerank 时上奏</label>
<label class="hly-toggle-switch">
<input type="checkbox" id="hly-rerank-notify" data-setting-key="rerank.notify" data-type="boolean">
<span class="slider"></span>
</label>
</div>
</fieldset>
<fieldset class="hly-settings-group" style="position: relative; padding-bottom: 30px;">
<legend><i class="fas fa-star-of-life"></i> 优先检索</legend>
<div class="hly-control-block" style="flex-direction: row; justify-content: space-between; align-items: center;">
<label for="hly-priority-retrieval-enabled" title="启用后,您可以为特定来源设置固定的检索数量,这些结果将必定被注入。">启用优先检索</label>
<label class="hly-toggle-switch">
<input type="checkbox" id="hly-priority-retrieval-enabled" data-setting-key="rerank.priorityRetrieval.enabled" data-type="boolean">
<span class="slider"></span>
</label>
</div>
<small class="hly-notes">启用后可以为特定来源设置固定的检索数量这些结果将必定被注入不受后续Rerank和排序影响。未勾选的来源将共享剩余的检索名额。</small>
<!-- 来源配置 -->
<div class="hly-priority-source-config" style="margin-top: 15px;">
<!-- 小说 -->
<div class="hly-control-block" style="display: flex; justify-content: space-between; align-items: center;">
<label class="hly-checkbox-label" style="flex-grow: 1;">
<input type="checkbox" data-setting-key="rerank.priorityRetrieval.sources.novel.enabled" data-type="boolean">
<span>小说录入</span>
</label>
<label>固定检索: </label>
<input type="number" class="hly-imperial-brush" style="width: 60px; margin-left: 10px;" value="5" data-setting-key="rerank.priorityRetrieval.sources.novel.count" data-type="integer">
<span></span>
</div>
<!-- 聊天记录 -->
<div class="hly-control-block" style="display: flex; justify-content: space-between; align-items: center;">
<label class="hly-checkbox-label" style="flex-grow: 1;">
<input type="checkbox" data-setting-key="rerank.priorityRetrieval.sources.chat_history.enabled" data-type="boolean">
<span>聊天记录</span>
</label>
<label>固定检索: </label>
<input type="number" class="hly-imperial-brush" style="width: 60px; margin-left: 10px;" value="5" data-setting-key="rerank.priorityRetrieval.sources.chat_history.count" data-type="integer">
<span></span>
</div>
<!-- 世界书 -->
<div class="hly-control-block" style="display: flex; justify-content: space-between; align-items: center;">
<label class="hly-checkbox-label" style="flex-grow: 1;">
<input type="checkbox" data-setting-key="rerank.priorityRetrieval.sources.lorebook.enabled" data-type="boolean">
<span>世界书</span>
</label>
<label>固定检索: </label>
<input type="number" class="hly-imperial-brush" style="width: 60px; margin-left: 10px;" value="5" data-setting-key="rerank.priorityRetrieval.sources.lorebook.count" data-type="integer">
<span></span>
</div>
<!-- 手动录入 -->
<div class="hly-control-block" style="display: flex; justify-content: space-between; align-items: center;">
<label class="hly-checkbox-label" style="flex-grow: 1;">
<input type="checkbox" data-setting-key="rerank.priorityRetrieval.sources.manual.enabled" data-type="boolean">
<span>手动录入</span>
</label>
<label>固定检索: </label>
<input type="number" class="hly-imperial-brush" style="width: 60px; margin-left: 10px;" value="5" data-setting-key="rerank.priorityRetrieval.sources.manual.count" data-type="integer">
<span></span>
</div>
</div>
<div class="hly-feature-credit">感谢功能友情提供Silence_Lurker潜默</div>
</fieldset>
</div>
<div id="hly-historiography-tab" class="hly-tab-pane">
<fieldset class="hly-settings-group">
<legend><i class="fas fa-book-medical"></i> 凝识法则</legend>
<div class="hly-control-block" style="flex-direction: row; justify-content: space-between; align-items: center;">
<label for="hly-condensation-enabled-toggle">准许凝识</label>
<label class="hly-toggle-switch">
<input type="checkbox" id="hly-condensation-enabled" data-setting-key="condensation.enabled" data-type="boolean">
<span class="slider"></span>
</label>
</div>
<div class="hly-control-block" style="flex-direction: row; justify-content: space-between; align-items: center;">
<label for="hly-auto-condense-toggle" title="启用后AI回复后将自动对历史消息进行凝识。">自动凝识</label>
<label class="hly-toggle-switch">
<input type="checkbox" id="hly-auto-condense-toggle" data-setting-key="condensation.autoCondense" data-type="boolean">
<span class="slider"></span>
</label>
</div>
<div class="hly-control-block">
<label for="hly-preserve-floors" title="自动凝识时保留最近的X层楼不进行凝识。">保留楼层 (自动凝识):</label>
<input type="number" id="hly-preserve-floors" class="hly-imperial-brush" value="10" data-setting-key="condensation.preserveFloors" data-type="integer">
</div>
<div class="hly-control-block">
<label>凝识范围 (聊天楼层):</label>
<div style="display: flex; gap: 10px; align-items: center;">
<input type="number" id="hly-layer-start" class="hly-imperial-brush" value="1" data-setting-key="condensation.layerStart" data-type="integer">
<span>-</span>
<input type="number" id="hly-layer-end" class="hly-imperial-brush" value="10" data-setting-key="condensation.layerEnd" data-type="integer">
</div>
</div>
<div class="hly-control-block">
<label class="hly-label">消息来源:</label>
<div class="hly-checkbox-group">
<label><input type="checkbox" id="hly-include-user" data-setting-key="condensation.messageTypes.user" data-type="boolean"> 用户</label>
<label><input type="checkbox" id="hly-include-ai" data-setting-key="condensation.messageTypes.ai" data-type="boolean"> AI</label>
</div>
</div>
<div class="hly-control-block" style="margin-top: 8px;">
<label style="font-weight: bold;">提取规则配置</label>
<select id="hly-condensation-rule-profile-select" class="hly-imperial-brush" style="width: 100%;"></select>
<small class="hly-notes">选择在「规则配置中心」里创建的提取规则,应用于浓缩处理。</small>
</div>
<div class="hly-button-group">
<button class="hly-action-button success" onclick="startHLYCondensation()"> 开始凝识</button>
<button class="hly-action-button" onclick="previewHLYCondensation()"> 预览内容</button>
</div>
<div class="hly-control-block">
<label>凝识结果预览:</label>
<div id="hly-condensation-results" class="hly-results-display"></div>
</div>
</fieldset>
<fieldset class="hly-settings-group">
<legend><i class="fas fa-book"></i> 手动录入</legend>
<div class="hly-control-block">
<label for="hly-manual-text">在此处粘贴您要录入的知识文书:</label>
<textarea id="hly-manual-text" class="hly-imperial-brush" rows="8" placeholder="例如,您可以粘贴角色设定、世界观、背景故事等..."></textarea>
<small class="hly-notes">录入的文本将被分块、向量化并存入当前角色的忆识宝库中。</small>
</div>
<div class="hly-button-group">
<button class="hly-action-button success" onclick="ingestHLYManualText()">
<i class="fas fa-file-import"></i> 开始录入
</button>
</div>
</fieldset>
<!-- ================== 小说/文档导入模块 ================== -->
<fieldset class="hly-settings-group">
<legend><i class="fas fa-book-open"></i> 整本录入 (小说/文档)</legend>
<div class="hly-control-block">
<label for="hanlin_novel_uploader">选择一个 .txt 格式的文本文档:</label>
<div id="hanlinyuan-ingest-novel-controls" class="hly-button-group" style="align-items: center;">
<!-- 文件选择按钮 -->
<div class="file-input-container">
<label for="hanlinyuan-ingest-novel-file-input" class="hly-action-button">选择.txt文件</label>
<input type="file" id="hanlinyuan-ingest-novel-file-input" accept=".txt" style="display: none;">
</div>
<!-- 编码选择 -->
<div class="file-encoding-container">
<select id="hanlinyuan-ingest-novel-encoding" class="hly-imperial-brush" style="padding: 8px; height: auto;" title="选择您原始文件的编码格式系统将为您转换为标准的UTF-8格式进行处理。">
<option value="UTF-8" selected>UTF-8 (默认)</option>
<option value="GBK">GBK/GB2312 → UTF-8</option>
<option value="Big5">Big5 → UTF-8</option>
</select>
</div>
<!-- 开始按钮 -->
<button id="hanlinyuan-ingest-novel-start" class="hly-action-button success">开始录入</button>
</div>
<span id="hanlinyuan-ingest-novel-file-name" class="file-name" style="margin-top: 10px; color: #ccc; display: inline-block;">未选择文件</span>
<div id="hanlinyuan-ingest-progress-container" style="display: none; margin-top: 10px;">
<div id="hanlinyuan-ingest-status" style="margin-bottom: 5px;">正在准备...</div>
<div style="display: flex; align-items: center;">
<progress id="hanlinyuan-ingest-progress-bar" value="0" max="100" style="width: 100%;"></progress>
<button id="hanlinyuan-ingest-abort" class="hly-action-button danger" style="margin-left: 10px;">中止</button>
</div>
</div>
<small class="hly-notes" style="margin-top: 10px;">上传 .txt 文件,系统会自动分块并存入忆识核心。处理大文件时请耐心等待。</small>
</div>
</fieldset>
<fieldset class="hly-settings-group">
<legend><i class="fas fa-list-alt"></i> 按条目编纂</legend>
<div class="hly-control-block">
<label for="hly-hist-select-library">选择书库:</label>
<div class="hly-search-wrapper">
<input type="text" id="hly-worldbook-search" class="hly-search-input" placeholder="搜索世界书名称...">
<i class="fas fa-search hly-search-icon"></i>
</div>
<select id="hly-hist-select-library" class="hly-imperial-brush">
<option value="">请选择书库...</option>
</select>
</div>
<div class="hly-control-block">
<label for="hly-hist-select-entry">选择条目:</label>
<div class="hly-multiselect-container">
<div class="hly-entry-search-wrapper">
<input type="text" id="hly-entry-search" class="hly-search-input" placeholder="搜索条目名称、关键词...">
<i class="fas fa-search hly-search-icon"></i>
</div>
<button id="hly-hist-entry-multiselect-btn" class="hly-imperial-brush" disabled>
<span>请先选择书库...</span>
<i class="fas fa-chevron-down"></i>
</button>
<div id="hly-hist-entry-multiselect-options" class="hly-multiselect-options-container" style="display: none;">
<!-- Options will be populated by JS -->
</div>
</div>
</div>
<div class="hly-button-group">
<button class="hly-action-button success" onclick="startHLYHistoriography()">
<i class="fas fa-file-import"></i> 开始编纂
</button>
</div>
<div class="hly-control-block">
<label>编纂结果预览:</label>
<div id="hly-historiography-results" class="hly-results-display"></div>
</div>
</fieldset>
</div>
<!-- ================== Knowledge Base Management Tab ================== -->
<div id="hly-knowledge-bases-tab" class="hly-tab-pane">
<fieldset class="hly-settings-group">
<legend><i class="fas fa-globe"></i> 全局知识库 (全角色通用)</legend>
<div class="hly-kb-toolbar">
<label><input type="checkbox" id="hly-kb-select-all-global"> 全选</label>
<div id="hly-kb-bulk-actions-global" class="hly-kb-bulk-actions" style="display: none;">
<button class="hly-action-button" data-action="toggle">切换状态</button>
<button class="hly-action-button" data-action="move">移至局部</button>
<button class="hly-action-button danger" data-action="delete">删除</button>
</div>
</div>
<div id="hly-kb-list-global" class="hly-kb-list">
<p id="hly-kb-list-global-placeholder" style="color: #888;">尚无全局知识库。</p>
<!-- Global KBs will be populated here -->
</div>
</fieldset>
<div class="hly-kb-transfer-controls">
<button id="hly-kb-move-all-to-local" class="hly-action-button" title="将所有全局知识库移动到当前角色的局部列表">
<i class="fas fa-angles-down"></i> 全局移至局部
</button>
<button id="hly-kb-move-all-to-global" class="hly-action-button" title="将当前角色的所有局部知识库移动到全局列表">
<i class="fas fa-angles-up"></i> 局部移至全局
</button>
</div>
<fieldset class="hly-settings-group">
<legend><i class="fas fa-user"></i> <span id="hly-local-kb-char-name">当前角色</span>的局部知识库</legend>
<div class="hly-kb-toolbar">
<label><input type="checkbox" id="hly-kb-select-all-local"> 全选</label>
<div id="hly-kb-bulk-actions-local" class="hly-kb-bulk-actions" style="display: none;">
<button class="hly-action-button" data-action="toggle">切换状态</button>
<button class="hly-action-button" data-action="move">移至全局</button>
<button class="hly-action-button danger" data-action="delete">删除</button>
</div>
</div>
<div id="hly-kb-list-local" class="hly-kb-list">
<p id="hly-kb-list-local-placeholder" style="color: #888;">当前角色没有知识库。通过“书库编纂"中的功能可自动创建。</p>
<!-- Local KBs will be populated here -->
</div>
<div class="hly-button-group" style="margin-top: 15px;">
<button id="hly-kb-delete-local-btn" class="hly-action-button danger">
<i class="fas fa-skull-crossbones"></i> 删除该角色所有局部知识库
</button>
</div>
</fieldset>
</div>
<div id="hly-advanced-tab" class="hly-tab-pane">
<fieldset class="hly-settings-group">
<legend><i class="fas fa-cogs"></i> 检索微调</legend>
<div class="hly-control-block">
<label for="hly-chunk-size">书卷尺寸 (Chunk Size):</label>
<input type="number" id="hly-chunk-size" class="hly-imperial-brush" value="768" data-setting-key="advanced.chunkSize" data-type="integer">
</div>
<div class="hly-control-block">
<label for="hly-overlap-size">上下文关联度 (Overlap):</label>
<input type="number" id="hly-overlap-size" class="hly-imperial-brush" value="50" data-setting-key="advanced.overlap" data-type="integer">
</div>
<div class="hly-control-block">
<label for="hly-match-threshold">忆识匹配度 (Threshold):</label>
<input type="number" id="hly-match-threshold" class="hly-imperial-brush" value="0.5" step="0.1" data-setting-key="advanced.matchThreshold" data-type="float">
</div>
<div class="hly-control-block">
<label for="hly-query-message-count">检索参考的消息数量:</label>
<input type="number" id="hly-query-message-count" class="hly-imperial-brush" value="2" data-setting-key="advanced.queryMessageCount" data-type="integer">
</div>
<div class="hly-control-block">
<label for="hly-max-results">单次检索最大结果数:</label>
<input type="number" id="hly-max-results" class="hly-imperial-brush" value="10" data-setting-key="advanced.maxResults" data-type="integer">
</div>
<div class="hly-control-block">
<label for="hly-batch-size">批处理大小 (Batch Size):</label>
<input type="number" id="hly-batch-size" class="hly-imperial-brush" value="50" data-setting-key="retrieval.batchSize" data-type="integer">
<small class="hly-notes">每次调用API时处理的文本数量。</small>
</div>
</fieldset>
<fieldset class="hly-settings-group">
<legend><i class="fas fa-wand-magic-sparkles"></i> 检索预处理</legend>
<div class="hly-control-block" style="flex-direction: row; justify-content: space-between; align-items: center;">
<label for="hly-query-preprocessing-enabled" title="启用后,将在向量检索前对您的提问进行净化处理,以提高准确性。">启用检索预处理</label>
<label class="hly-toggle-switch">
<input type="checkbox" id="hly-query-preprocessing-enabled" data-setting-key="queryPreprocessing.enabled" data-type="boolean">
<span class="slider"></span>
</label>
</div>
<div class="hly-control-block" style="margin-top: 8px;">
<label style="font-weight: bold;">处理规则配置</label>
<select id="hly-query-preprocessing-rule-profile-select" class="hly-imperial-brush" style="width: 100%;"></select>
<small class="hly-notes">选择在「规则配置中心」里创建的提取规则,应用于查询预处理(标签提取 + 内容排除)。</small>
</div>
</fieldset>
<fieldset class="hly-settings-group">
<legend><i class="fas fa-wand-magic-sparkles"></i> 圣言注入 (按来源)</legend>
<div style="text-align: center; margin-bottom: 10px;">
<small style="font-style: italic; color: #05c3f3;">感谢功能友情提供Silence_Lurker潜默</small>
</div>
<!-- 【V12.0 重构】统一注入编辑器 -->
<div class="hly-control-block">
<label for="hly-injection-source-selector">选择要配置的注入来源:</label>
<select id="hly-injection-source-selector" class="hly-imperial-brush">
<option value="novel">小说</option>
<option value="chat">聊天记录</option>
<option value="lorebook">世界书</option>
<option value="manual">手动录入</option>
</select>
</div>
<div id="hly-unified-injection-editor">
<div class="hly-control-block">
<label for="hly-unified-template-editor">圣言模板:</label>
<textarea id="hly-unified-template-editor" class="hly-imperial-brush" rows="3"></textarea>
<small id="hly-unified-template-notes" class="hly-notes">以 {{placeholder}} 为占位符。</small>
</div>
<div class="hly-control-block">
<label>注入位置:</label>
<div class="hly-radio-group-vertical">
<label class="hly-radio-label">
<input type="radio" name="hly-unified-injection-position" value="2" /> <span>主提示前</span>
</label>
<label class="hly-radio-label">
<input type="radio" name="hly-unified-injection-position" value="0" /> <span>主提示后</span>
</label>
<label class="hly-radio-label">
<input type="radio" name="hly-unified-injection-position" value="1" />
<span>聊天内 @ 深度</span>
<input id="hly-unified-injection-depth" class="hly-imperial-brush" type="number" min="0" max="999" style="width: 60px; margin-left: 10px;" />
<span style="margin-left: 10px;">作为</span>
<select id="hly-unified-injection-role" class="hly-imperial-brush" style="width: auto; margin-left: 10px;">
<option value="0">系统</option>
<option value="1">用户</option>
<option value="2">助手</option>
</select>
</label>
</div>
</div>
</fieldset>
</fieldset>
<fieldset class="hly-settings-group">
<legend><i class="fas fa-bell"></i> 上奏设定</legend>
<div class="hly-control-block" style="flex-direction: row; justify-content: space-between; align-items: center;">
<label for="hly-retrieval-notify-toggle">检索成功时上奏</label>
<label class="hly-toggle-switch">
<input type="checkbox" id="hly-retrieval-notify" data-setting-key="retrieval.notify" data-type="boolean">
<span class="slider"></span>
</label>
</div>
</fieldset>
</div>
</div>
<div id="hly-log-container" style="border-top: 2px solid #444; padding-top: 10px; margin-top: 10px;">
<fieldset class="hly-settings-group">
<legend><i class="fas fa-scroll"></i> 起居注</legend>
<div id="hly-log-output" class="hly-log-display">
<p>翰林院运行日志将在此记录...</p>
</div>
</fieldset>
</div>
<div class="hly-footer">
</div>
</div>
<!-- 引入强大的文本解码库,确保编码转换万无一失 -->
<script src="https://cdn.jsdelivr.net/npm/text-encoding@0.7.0/lib/encoding.min.js"></script>