Files
ST-Amily2-Chat-Optimisation/core/memory-blocks/generator-handlers.js
Jenkins CI 1a4a10d42d release: v2.2.5 [2026-06-10 12:41:11]
### 修复
- **翰林院(RAG)API Key 污染**:
  - 修复 `saveSettingsFromUI` 无差别遍历翰林院面板内全部 `[data-setting-key]` 输入(包含被 `profile-sync` 接管隐藏的字段),导致掩码占位符 `••••••••` 被当作真值写回 `settings.rerank.apiKey` / `settings.retrieval.apiKey`,URL / model 也被 Profile 值覆盖到 legacy 字段。修复后会跳过祖先带 `data-profile-hidden` 的输入
  - `getRerankSettings` / `getEmbedRetrievalSettings` 同时加入防御性还原:识别历史污染留下的 `••••••••` 时归为空字符串,避免取消 Profile 分配后实际请求带占位符 token 被 401
---
2026-06-10 12:41:11 +08:00

47 lines
1.6 KiB
JavaScript
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.
/**
* core/memory-blocks/generator-handlers.js
*
* type → handler 函数 的注册表。BlockDefinition.generator.type 在这里查表后执行。
*
* Handler 签名async (block, ctx) => string | null
* - block: BlockDefinition
* - ctx: ExecuteContext { settings, signal, context, extras }
* - 返回 string替换值返回 null/undefined视为"无内容,保留占位符"
*
* 当前内置 'static''ai_call'/'plugin' 在后续 Phase 注册(保留接口)。
*/
const handlers = new Map();
export function registerHandler(type, fn) {
if (!type || typeof fn !== 'function') {
throw new Error('[MemoryBlocks] registerHandler 需要 type 字符串 + 函数 fn。');
}
handlers.set(type, fn);
}
export function unregisterHandler(type) {
handlers.delete(type);
}
export function getHandler(type) {
return handlers.get(type) ?? null;
}
export function listHandlerTypes() {
return [...handlers.keys()];
}
// ── 内置 handlerstatic ──────────────────────────────────────────────────────
registerHandler('static', async (block, ctx) => {
const gen = block.generator || {};
// 优先级:硬编码 value > settings[valueKey] > defaultValue > ''
if (gen.value !== undefined) return String(gen.value);
if (gen.valueKey != null) {
const v = ctx?.settings?.[gen.valueKey];
if (v !== undefined && v !== null && v !== '') return String(v);
}
if (gen.defaultValue !== undefined) return String(gen.defaultValue);
return '';
});