mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-31 05:10:14 +08:00
feat(hermes): add memory config form
This commit is contained in:
@@ -34,6 +34,14 @@ const TOOL_GUARDRAILS_DEFAULTS = {
|
||||
hardStopNoProgress: 5,
|
||||
}
|
||||
|
||||
const MEMORY_DEFAULTS = {
|
||||
memoryEnabled: true,
|
||||
userProfileEnabled: true,
|
||||
memoryCharLimit: 2200,
|
||||
userCharLimit: 1375,
|
||||
nudgeInterval: 10,
|
||||
}
|
||||
|
||||
const SESSION_RESET_MODES = ['both', 'idle', 'daily', 'none']
|
||||
|
||||
export function render() {
|
||||
@@ -44,21 +52,25 @@ export function render() {
|
||||
let runtimeValues = { ...SESSION_RUNTIME_DEFAULTS }
|
||||
let compressionValues = { ...COMPRESSION_DEFAULTS }
|
||||
let toolGuardrailsValues = { ...TOOL_GUARDRAILS_DEFAULTS }
|
||||
let memoryValues = { ...MEMORY_DEFAULTS }
|
||||
let loading = true
|
||||
let runtimeLoading = true
|
||||
let compressionLoading = true
|
||||
let toolGuardrailsLoading = true
|
||||
let memoryLoading = true
|
||||
let saving = false
|
||||
let runtimeSaving = false
|
||||
let compressionSaving = false
|
||||
let toolGuardrailsSaving = false
|
||||
let memorySaving = false
|
||||
let error = null
|
||||
let runtimeError = null
|
||||
let compressionError = null
|
||||
let toolGuardrailsError = null
|
||||
let memoryError = null
|
||||
|
||||
function esc(value) {
|
||||
return String(value || '')
|
||||
return String(value ?? '')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
@@ -66,7 +78,7 @@ export function render() {
|
||||
}
|
||||
|
||||
function isBusy() {
|
||||
return loading || runtimeLoading || compressionLoading || toolGuardrailsLoading || saving || runtimeSaving || compressionSaving || toolGuardrailsSaving
|
||||
return loading || runtimeLoading || compressionLoading || toolGuardrailsLoading || memoryLoading || saving || runtimeSaving || compressionSaving || toolGuardrailsSaving || memorySaving
|
||||
}
|
||||
|
||||
function option(labelKey, value, selected) {
|
||||
@@ -83,7 +95,7 @@ export function render() {
|
||||
}
|
||||
|
||||
function renderRuntimePanel() {
|
||||
const disabled = loading || saving || runtimeLoading || runtimeSaving || compressionSaving || toolGuardrailsSaving
|
||||
const disabled = loading || saving || runtimeLoading || runtimeSaving || compressionSaving || toolGuardrailsSaving || memorySaving
|
||||
return `
|
||||
<div class="hm-panel hm-config-runtime-panel">
|
||||
<div class="hm-panel-header">
|
||||
@@ -131,7 +143,7 @@ export function render() {
|
||||
}
|
||||
|
||||
function renderCompressionPanel() {
|
||||
const disabled = loading || saving || compressionLoading || compressionSaving || runtimeSaving || toolGuardrailsSaving
|
||||
const disabled = loading || saving || compressionLoading || compressionSaving || runtimeSaving || toolGuardrailsSaving || memorySaving
|
||||
return `
|
||||
<div class="hm-panel hm-config-runtime-panel hm-config-compression-panel">
|
||||
<div class="hm-panel-header">
|
||||
@@ -181,7 +193,7 @@ export function render() {
|
||||
}
|
||||
|
||||
function renderToolGuardrailsPanel() {
|
||||
const disabled = loading || saving || toolGuardrailsLoading || toolGuardrailsSaving || runtimeSaving || compressionSaving
|
||||
const disabled = loading || saving || toolGuardrailsLoading || toolGuardrailsSaving || runtimeSaving || compressionSaving || memorySaving
|
||||
return `
|
||||
<div class="hm-panel hm-config-runtime-panel hm-config-guardrails-panel">
|
||||
<div class="hm-panel-header">
|
||||
@@ -242,6 +254,52 @@ export function render() {
|
||||
`
|
||||
}
|
||||
|
||||
function renderMemoryPanel() {
|
||||
const disabled = loading || saving || memoryLoading || memorySaving || runtimeSaving || compressionSaving || toolGuardrailsSaving
|
||||
return `
|
||||
<div class="hm-panel hm-config-runtime-panel hm-config-memory-panel">
|
||||
<div class="hm-panel-header">
|
||||
<div>
|
||||
<div class="hm-panel-title">${t('engine.hermesMemoryConfigTitle')}</div>
|
||||
<div class="hm-channel-panel-desc">${t('engine.hermesMemoryConfigDesc')}</div>
|
||||
</div>
|
||||
<div class="hm-panel-actions">
|
||||
<span class="hm-muted">${memorySaving ? t('engine.hermesConfigStatusSaving') : memoryLoading ? t('engine.hermesConfigStatusLoading') : t('engine.hermesMemoryConfigStatusReady')}</span>
|
||||
<button class="hm-btn hm-btn--cta hm-btn--sm" id="hm-memory-save" ${disabled ? 'disabled' : ''}>${t('engine.hermesMemoryConfigSave')}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hm-panel-body">
|
||||
${renderError(memoryError)}
|
||||
<div class="hm-config-check-grid">
|
||||
<label class="hm-channel-check">
|
||||
<input id="hm-memory-enabled" type="checkbox" ${memoryValues.memoryEnabled ? 'checked' : ''} ${disabled ? 'disabled' : ''}>
|
||||
<span>${t('engine.hermesMemoryConfigMemoryEnabled')}</span>
|
||||
</label>
|
||||
<label class="hm-channel-check">
|
||||
<input id="hm-memory-user-profile-enabled" type="checkbox" ${memoryValues.userProfileEnabled ? 'checked' : ''} ${disabled ? 'disabled' : ''}>
|
||||
<span>${t('engine.hermesMemoryConfigUserProfileEnabled')}</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="hm-config-runtime-grid hm-config-memory-grid">
|
||||
<label class="hm-field">
|
||||
<span class="hm-field-label">${t('engine.hermesMemoryConfigMemoryCharLimit')}</span>
|
||||
<input id="hm-memory-char-limit" class="hm-input" type="number" inputmode="numeric" min="100" max="200000" step="100" value="${esc(memoryValues.memoryCharLimit)}" ${disabled ? 'disabled' : ''}>
|
||||
</label>
|
||||
<label class="hm-field">
|
||||
<span class="hm-field-label">${t('engine.hermesMemoryConfigUserCharLimit')}</span>
|
||||
<input id="hm-memory-user-char-limit" class="hm-input" type="number" inputmode="numeric" min="100" max="200000" step="100" value="${esc(memoryValues.userCharLimit)}" ${disabled ? 'disabled' : ''}>
|
||||
</label>
|
||||
<label class="hm-field">
|
||||
<span class="hm-field-label">${t('engine.hermesMemoryConfigNudgeInterval')}</span>
|
||||
<input id="hm-memory-nudge-interval" class="hm-input" type="number" inputmode="numeric" min="0" max="1000" step="1" value="${esc(memoryValues.nudgeInterval)}" ${disabled ? 'disabled' : ''}>
|
||||
</label>
|
||||
</div>
|
||||
<div class="hm-channel-footnote">${t('engine.hermesMemoryConfigFootnote')}</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
|
||||
function draw() {
|
||||
el.innerHTML = `
|
||||
<div class="hm-hero">
|
||||
@@ -259,6 +317,7 @@ export function render() {
|
||||
${renderRuntimePanel()}
|
||||
${renderCompressionPanel()}
|
||||
${renderToolGuardrailsPanel()}
|
||||
${renderMemoryPanel()}
|
||||
|
||||
<div class="hm-panel">
|
||||
<div class="hm-panel-header">
|
||||
@@ -281,6 +340,7 @@ export function render() {
|
||||
el.querySelector('#hm-runtime-save')?.addEventListener('click', saveRuntime)
|
||||
el.querySelector('#hm-compression-save')?.addEventListener('click', saveCompression)
|
||||
el.querySelector('#hm-tool-guardrails-save')?.addEventListener('click', saveToolGuardrails)
|
||||
el.querySelector('#hm-memory-save')?.addEventListener('click', saveMemory)
|
||||
}
|
||||
|
||||
async function loadRaw() {
|
||||
@@ -303,15 +363,22 @@ export function render() {
|
||||
toolGuardrailsValues = { ...TOOL_GUARDRAILS_DEFAULTS, ...(data?.values || {}) }
|
||||
}
|
||||
|
||||
async function loadMemory() {
|
||||
const data = await api.hermesMemoryConfigRead()
|
||||
memoryValues = { ...MEMORY_DEFAULTS, ...(data?.values || {}) }
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading = true
|
||||
runtimeLoading = true
|
||||
compressionLoading = true
|
||||
toolGuardrailsLoading = true
|
||||
memoryLoading = true
|
||||
error = null
|
||||
runtimeError = null
|
||||
compressionError = null
|
||||
toolGuardrailsError = null
|
||||
memoryError = null
|
||||
draw()
|
||||
try {
|
||||
await loadRaw()
|
||||
@@ -344,6 +411,14 @@ export function render() {
|
||||
toolGuardrailsLoading = false
|
||||
draw()
|
||||
}
|
||||
try {
|
||||
await loadMemory()
|
||||
} catch (err) {
|
||||
memoryError = humanizeError(err, t('engine.hermesMemoryConfigLoadFailed') || 'Load memory config failed')
|
||||
} finally {
|
||||
memoryLoading = false
|
||||
draw()
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshRawAfterStructuredSave() {
|
||||
@@ -374,6 +449,9 @@ export function render() {
|
||||
try {
|
||||
await loadToolGuardrails()
|
||||
} catch {}
|
||||
try {
|
||||
await loadMemory()
|
||||
} catch {}
|
||||
} catch (err) {
|
||||
error = humanizeError(err, t('engine.hermesConfigSaveFailed') || 'Save failed')
|
||||
toast(error, 'error')
|
||||
@@ -474,6 +552,35 @@ export function render() {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveMemory() {
|
||||
const form = {
|
||||
memoryEnabled: !!el.querySelector('#hm-memory-enabled')?.checked,
|
||||
userProfileEnabled: !!el.querySelector('#hm-memory-user-profile-enabled')?.checked,
|
||||
memoryCharLimit: el.querySelector('#hm-memory-char-limit')?.value || '2200',
|
||||
userCharLimit: el.querySelector('#hm-memory-user-char-limit')?.value || '1375',
|
||||
nudgeInterval: el.querySelector('#hm-memory-nudge-interval')?.value || '10',
|
||||
}
|
||||
memorySaving = true
|
||||
memoryError = null
|
||||
draw()
|
||||
try {
|
||||
const result = await api.hermesMemoryConfigSave(form)
|
||||
memoryValues = { ...MEMORY_DEFAULTS, ...(result?.values || form) }
|
||||
await refreshRawAfterStructuredSave()
|
||||
const backup = result?.backup || ''
|
||||
toast({
|
||||
message: t('engine.hermesMemoryConfigSaveSuccess'),
|
||||
hint: backup ? t('engine.hermesConfigBackupHint', { path: backup }) : '',
|
||||
}, 'success')
|
||||
} catch (err) {
|
||||
memoryError = humanizeError(err, t('engine.hermesMemoryConfigSaveFailed') || 'Save memory config failed')
|
||||
toast(memoryError, 'error')
|
||||
} finally {
|
||||
memorySaving = false
|
||||
draw()
|
||||
}
|
||||
}
|
||||
|
||||
draw()
|
||||
load()
|
||||
return el
|
||||
|
||||
@@ -6761,6 +6761,10 @@ body[data-active-engine="hermes"][data-theme="dark"] {
|
||||
grid-template-columns: repeat(3, minmax(160px, 1fr));
|
||||
margin-top: 12px;
|
||||
}
|
||||
[data-engine="hermes"] .hm-config-memory-grid {
|
||||
grid-template-columns: repeat(3, minmax(160px, 1fr));
|
||||
margin-top: 18px;
|
||||
}
|
||||
[data-engine="hermes"] .hm-config-subtitle {
|
||||
margin-top: 20px;
|
||||
color: var(--hm-text-secondary);
|
||||
@@ -6893,6 +6897,7 @@ body[data-active-engine="hermes"][data-theme="dark"] {
|
||||
[data-engine="hermes"] .hm-config-runtime-grid,
|
||||
[data-engine="hermes"] .hm-config-compression-grid,
|
||||
[data-engine="hermes"] .hm-config-guardrails-grid,
|
||||
[data-engine="hermes"] .hm-config-memory-grid,
|
||||
[data-engine="hermes"] .hm-config-check-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@@ -515,6 +515,8 @@ export const api = {
|
||||
hermesCompressionConfigSave: (form) => invoke('hermes_compression_config_save', { form }),
|
||||
hermesToolLoopGuardrailsConfigRead: () => invoke('hermes_tool_loop_guardrails_config_read'),
|
||||
hermesToolLoopGuardrailsConfigSave: (form) => invoke('hermes_tool_loop_guardrails_config_save', { form }),
|
||||
hermesMemoryConfigRead: () => invoke('hermes_memory_config_read'),
|
||||
hermesMemoryConfigSave: (form) => invoke('hermes_memory_config_save', { form }),
|
||||
hermesLazyDepsFeatures: () => cachedInvoke('hermes_lazy_deps_features', {}, 600000),
|
||||
hermesLazyDepsStatus: (features) => invoke('hermes_lazy_deps_status', { features }),
|
||||
hermesLazyDepsEnsure: (feature) => invoke('hermes_lazy_deps_ensure', { feature }),
|
||||
|
||||
@@ -530,6 +530,19 @@ export default {
|
||||
hermesToolGuardrailsHardStopSameToolFailure: _('同工具失败停止', 'Same-tool failure stop', '同工具失敗停止'),
|
||||
hermesToolGuardrailsHardStopNoProgress: _('无进展停止', 'No-progress stop', '無進展停止'),
|
||||
hermesToolGuardrailsFootnote: _('默认只提示不拦截,适合交互式使用。硬停止更适合 cron、无人值守和长时间后台任务。', 'By default Hermes only warns and does not block, which fits interactive use. Hard stops are better for cron, unattended, and long-running background jobs.', '預設只提示不攔截,適合互動式使用。硬停止更適合 cron、無人值守和長時間背景任務。'),
|
||||
hermesMemoryConfigTitle: _('持久记忆', 'Persistent memory', '持久記憶'),
|
||||
hermesMemoryConfigDesc: _('控制 MEMORY.md 与 USER.md 是否注入系统提示,以及注入字符上限和定期整理提醒,避免长期上下文丢失重要偏好。', 'Control whether MEMORY.md and USER.md are injected, their character limits, and periodic review nudges so long-running sessions keep important preferences.', '控制 MEMORY.md 與 USER.md 是否注入系統提示,以及注入字元上限和定期整理提醒,避免長期上下文遺失重要偏好。'),
|
||||
hermesMemoryConfigStatusReady: _('结构化配置', 'structured settings', '結構化設定'),
|
||||
hermesMemoryConfigSave: _('保存记忆配置', 'Save memory settings', '儲存記憶設定'),
|
||||
hermesMemoryConfigSaveSuccess: _('记忆配置已保存,建议重启 Hermes Gateway 生效', 'Memory settings saved. Restart Hermes Gateway to take effect.', '記憶設定已儲存,建議重啟 Hermes Gateway 生效'),
|
||||
hermesMemoryConfigLoadFailed: _('加载记忆配置失败', 'Load memory settings failed', '載入記憶設定失敗'),
|
||||
hermesMemoryConfigSaveFailed: _('保存记忆配置失败', 'Save memory settings failed', '儲存記憶設定失敗'),
|
||||
hermesMemoryConfigMemoryEnabled: _('启用 Agent 记忆', 'Enable agent memory', '啟用 Agent 記憶'),
|
||||
hermesMemoryConfigUserProfileEnabled: _('启用用户画像', 'Enable user profile', '啟用使用者画像'),
|
||||
hermesMemoryConfigMemoryCharLimit: _('记忆字符上限', 'Memory character limit', '記憶字元上限'),
|
||||
hermesMemoryConfigUserCharLimit: _('用户画像字符上限', 'User profile character limit', '使用者画像字元上限'),
|
||||
hermesMemoryConfigNudgeInterval: _('整理提醒间隔', 'Review nudge interval', '整理提醒間隔'),
|
||||
hermesMemoryConfigFootnote: _('提醒间隔按用户消息轮数计算,设为 0 可关闭提醒。外部记忆 provider 等高级字段会保留在 raw YAML 中。', 'The nudge interval is counted in user turns. Set it to 0 to disable nudges. Advanced fields such as external memory provider are preserved in raw YAML.', '提醒間隔依使用者訊息輪數計算,設為 0 可關閉提醒。外部記憶 provider 等進階欄位會保留在 raw YAML 中。'),
|
||||
// Batch 1 §E: 会话导出
|
||||
sessionsExport: _('导出', 'Export', '匯出'),
|
||||
sessionsExportSuccess: _('已导出', 'Exported', '已匯出'),
|
||||
|
||||
Reference in New Issue
Block a user