mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-29 04:10:00 +08:00
feat(hermes): add context engine controls
This commit is contained in:
@@ -4762,6 +4762,38 @@ export function mergeHermesXSearchConfig(config = {}, form = {}) {
|
||||
return next
|
||||
}
|
||||
|
||||
function normalizeHermesContextEngine(value, strict = false) {
|
||||
const text = String(value ?? '').trim()
|
||||
if (!text) {
|
||||
if (strict) throw new Error('context.engine 不能为空')
|
||||
return 'compressor'
|
||||
}
|
||||
if (/^[a-zA-Z0-9_.-]+$/.test(text)) return text
|
||||
if (strict) throw new Error('context.engine 只能包含字母、数字、下划线、点和短横线')
|
||||
return 'compressor'
|
||||
}
|
||||
|
||||
export function buildHermesContextConfigValues(config = {}) {
|
||||
const root = config && typeof config === 'object' && !Array.isArray(config) ? config : {}
|
||||
const context = root.context && typeof root.context === 'object' && !Array.isArray(root.context)
|
||||
? root.context
|
||||
: {}
|
||||
return {
|
||||
contextEngine: normalizeHermesContextEngine(context.engine, false),
|
||||
}
|
||||
}
|
||||
|
||||
export function mergeHermesContextConfig(config = {}, form = {}) {
|
||||
const next = mergeConfigsPreservingFields({}, config && typeof config === 'object' && !Array.isArray(config) ? config : {})
|
||||
const currentValues = buildHermesContextConfigValues(next)
|
||||
const context = next.context && typeof next.context === 'object' && !Array.isArray(next.context)
|
||||
? mergeConfigsPreservingFields(next.context, {})
|
||||
: {}
|
||||
context.engine = normalizeHermesContextEngine(Object.hasOwn(form, 'contextEngine') ? form.contextEngine : currentValues.contextEngine, true)
|
||||
next.context = context
|
||||
return next
|
||||
}
|
||||
|
||||
function isHermesModelAliasName(value) {
|
||||
return /^[a-zA-Z0-9_.-]+$/.test(String(value || '').trim())
|
||||
}
|
||||
@@ -12519,6 +12551,27 @@ const handlers = {
|
||||
}
|
||||
},
|
||||
|
||||
hermes_context_config_read() {
|
||||
const { configPath, exists, config } = readHermesConfigYamlObject()
|
||||
return {
|
||||
exists,
|
||||
configPath,
|
||||
values: buildHermesContextConfigValues(config),
|
||||
}
|
||||
},
|
||||
|
||||
hermes_context_config_save({ form } = {}) {
|
||||
const { configPath, config } = readHermesConfigYamlObject()
|
||||
const next = mergeHermesContextConfig(config, form || {})
|
||||
const backup = writeHermesConfigYamlObject(configPath, next)
|
||||
return {
|
||||
ok: true,
|
||||
configPath,
|
||||
backup,
|
||||
values: buildHermesContextConfigValues(next),
|
||||
}
|
||||
},
|
||||
|
||||
hermes_model_aliases_config_read() {
|
||||
const { configPath, exists, config } = readHermesConfigYamlObject()
|
||||
return {
|
||||
|
||||
@@ -8818,6 +8818,57 @@ fn merge_hermes_x_search_config(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn normalize_hermes_context_engine(value: Option<String>, strict: bool) -> Result<String, String> {
|
||||
let text = value.unwrap_or_default().trim().to_string();
|
||||
if text.is_empty() {
|
||||
if strict {
|
||||
return Err("context.engine 不能为空".to_string());
|
||||
}
|
||||
return Ok("compressor".to_string());
|
||||
}
|
||||
if text
|
||||
.chars()
|
||||
.all(|ch| ch.is_ascii_alphanumeric() || matches!(ch, '_' | '.' | '-'))
|
||||
{
|
||||
return Ok(text);
|
||||
}
|
||||
if strict {
|
||||
return Err("context.engine 只能包含字母、数字、下划线、点和短横线".to_string());
|
||||
}
|
||||
Ok("compressor".to_string())
|
||||
}
|
||||
|
||||
fn build_hermes_context_config_values(config: &serde_yaml::Value) -> Value {
|
||||
let root = config.as_mapping();
|
||||
let context = root.and_then(|map| yaml_get_mapping(map, "context"));
|
||||
let engine = normalize_hermes_context_engine(
|
||||
context.and_then(|map| yaml_string_field(map, "engine")),
|
||||
false,
|
||||
)
|
||||
.unwrap_or_else(|_| "compressor".to_string());
|
||||
|
||||
serde_json::json!({
|
||||
"contextEngine": engine,
|
||||
})
|
||||
}
|
||||
|
||||
fn merge_hermes_context_config(config: &mut serde_yaml::Value, form: &Value) -> Result<(), String> {
|
||||
let current = build_hermes_context_config_values(config);
|
||||
let engine = normalize_hermes_context_engine(
|
||||
if form.get("contextEngine").is_some() {
|
||||
form_string(form, "contextEngine")
|
||||
} else {
|
||||
current["contextEngine"].as_str().map(ToString::to_string)
|
||||
},
|
||||
true,
|
||||
)?;
|
||||
|
||||
let root = ensure_yaml_object(config)?;
|
||||
let context = yaml_child_object(root, "context")?;
|
||||
context.insert(yaml_key("engine"), serde_yaml::Value::String(engine));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_hermes_lsp_config_values(config: &serde_yaml::Value) -> Value {
|
||||
let root = config.as_mapping();
|
||||
let lsp = root.and_then(|map| yaml_get_mapping(map, "lsp"));
|
||||
@@ -11623,6 +11674,30 @@ pub fn hermes_x_search_config_save(form: Value) -> Result<Value, String> {
|
||||
}))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn hermes_context_config_read() -> Result<Value, String> {
|
||||
let (config_path, exists, config) = read_hermes_channel_yaml_config()?;
|
||||
ensure_yaml_object(&mut config.clone())?;
|
||||
Ok(serde_json::json!({
|
||||
"exists": exists,
|
||||
"configPath": config_path.to_string_lossy(),
|
||||
"values": build_hermes_context_config_values(&config),
|
||||
}))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn hermes_context_config_save(form: Value) -> Result<Value, String> {
|
||||
let (config_path, _exists, mut config) = read_hermes_channel_yaml_config()?;
|
||||
merge_hermes_context_config(&mut config, &form)?;
|
||||
let backup = write_hermes_yaml_config(&config_path, &config)?;
|
||||
Ok(serde_json::json!({
|
||||
"ok": true,
|
||||
"configPath": config_path.to_string_lossy(),
|
||||
"backup": backup,
|
||||
"values": build_hermes_context_config_values(&config),
|
||||
}))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn hermes_stt_config_read() -> Result<Value, String> {
|
||||
let (config_path, exists, config) = read_hermes_channel_yaml_config()?;
|
||||
@@ -18489,6 +18564,73 @@ streaming:
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod hermes_context_config_tests {
|
||||
use super::{build_hermes_context_config_values, merge_hermes_context_config};
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn context_values_have_upstream_defaults() {
|
||||
let config: serde_yaml::Value = serde_yaml::from_str("{}").unwrap();
|
||||
let values = build_hermes_context_config_values(&config);
|
||||
assert_eq!(values["contextEngine"], "compressor");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn context_values_read_yaml_fields() {
|
||||
let config: serde_yaml::Value = serde_yaml::from_str(
|
||||
r#"
|
||||
context:
|
||||
engine: lcm
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let values = build_hermes_context_config_values(&config);
|
||||
assert_eq!(values["contextEngine"], "lcm");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_context_config_preserves_unknown_fields() {
|
||||
let mut config: serde_yaml::Value = serde_yaml::from_str(
|
||||
r#"
|
||||
context:
|
||||
engine: compressor
|
||||
custom_flag: keep-context
|
||||
model:
|
||||
provider: anthropic
|
||||
streaming:
|
||||
enabled: true
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
merge_hermes_context_config(&mut config, &json!({ "contextEngine": "lcm" })).unwrap();
|
||||
|
||||
assert_eq!(config["model"]["provider"].as_str(), Some("anthropic"));
|
||||
assert_eq!(config["streaming"]["enabled"].as_bool(), Some(true));
|
||||
assert_eq!(config["context"]["engine"].as_str(), Some("lcm"));
|
||||
assert_eq!(
|
||||
config["context"]["custom_flag"].as_str(),
|
||||
Some("keep-context")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_context_config_rejects_invalid_values() {
|
||||
let mut config = serde_yaml::Value::Mapping(serde_yaml::Mapping::new());
|
||||
let err =
|
||||
merge_hermes_context_config(&mut config, &json!({ "contextEngine": "" })).unwrap_err();
|
||||
assert!(err.contains("context.engine"));
|
||||
let err =
|
||||
merge_hermes_context_config(&mut config, &json!({ "contextEngine": "bad engine" }))
|
||||
.unwrap_err();
|
||||
assert!(err.contains("context.engine"));
|
||||
let err = merge_hermes_context_config(&mut config, &json!({ "contextEngine": "中文" }))
|
||||
.unwrap_err();
|
||||
assert!(err.contains("context.engine"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod hermes_lsp_config_tests {
|
||||
use super::{build_hermes_lsp_config_values, merge_hermes_lsp_config};
|
||||
|
||||
@@ -335,6 +335,8 @@ pub fn run() {
|
||||
hermes::hermes_model_catalog_config_save,
|
||||
hermes::hermes_x_search_config_read,
|
||||
hermes::hermes_x_search_config_save,
|
||||
hermes::hermes_context_config_read,
|
||||
hermes::hermes_context_config_save,
|
||||
hermes::hermes_stt_config_read,
|
||||
hermes::hermes_stt_config_save,
|
||||
hermes::hermes_tts_voice_config_read,
|
||||
|
||||
@@ -132,6 +132,10 @@ const X_SEARCH_DEFAULTS = {
|
||||
xSearchRetries: 2,
|
||||
}
|
||||
|
||||
const CONTEXT_DEFAULTS = {
|
||||
contextEngine: 'compressor',
|
||||
}
|
||||
|
||||
const MODEL_ALIASES_DEFAULTS = {
|
||||
modelAliasesJson: '{}',
|
||||
}
|
||||
@@ -436,6 +440,7 @@ export function render() {
|
||||
let modelValues = { ...MODEL_DEFAULTS }
|
||||
let modelCatalogValues = { ...MODEL_CATALOG_DEFAULTS }
|
||||
let xSearchValues = { ...X_SEARCH_DEFAULTS }
|
||||
let contextValues = { ...CONTEXT_DEFAULTS }
|
||||
let modelAliasesValues = { ...MODEL_ALIASES_DEFAULTS }
|
||||
let hooksValues = { ...HOOKS_DEFAULTS }
|
||||
let providerOverridesValues = { ...PROVIDER_OVERRIDES_DEFAULTS }
|
||||
@@ -479,6 +484,7 @@ export function render() {
|
||||
let modelLoading = true
|
||||
let modelCatalogLoading = true
|
||||
let xSearchLoading = true
|
||||
let contextLoading = true
|
||||
let modelAliasesLoading = true
|
||||
let hooksLoading = true
|
||||
let providerOverridesLoading = true
|
||||
@@ -522,6 +528,7 @@ export function render() {
|
||||
let modelSaving = false
|
||||
let modelCatalogSaving = false
|
||||
let xSearchSaving = false
|
||||
let contextSaving = false
|
||||
let modelAliasesSaving = false
|
||||
let hooksSaving = false
|
||||
let providerOverridesSaving = false
|
||||
@@ -565,6 +572,7 @@ export function render() {
|
||||
let modelError = null
|
||||
let modelCatalogError = null
|
||||
let xSearchError = null
|
||||
let contextError = null
|
||||
let modelAliasesError = null
|
||||
let hooksError = null
|
||||
let providerOverridesError = null
|
||||
@@ -601,7 +609,7 @@ export function render() {
|
||||
}
|
||||
|
||||
function isBusy() {
|
||||
return loading || runtimeLoading || sessionsMaintenanceLoading || updatesLoading || compressionLoading || promptCachingLoading || openrouterCacheLoading || providerRoutingLoading || auxiliaryLoading || toolGuardrailsLoading || memoryLoading || skillsLoading || curatorLoading || quickCommandsLoading || modelLoading || modelCatalogLoading || xSearchLoading || modelAliasesLoading || hooksLoading || providerOverridesLoading || mcpServersLoading || agentToolsetsLoading || platformToolsetsLoading || agentRuntimeLoading || unauthorizedDmLoading || securityLoading || displayLoading || humanDelayLoading || kanbanLoading || streamingLoading || executionLimitsLoading || ioSafetyLoading || checkpointsLoading || cronLoading || loggingLoading || approvalsLoading || privacyLoading || browserLoading || webLoading || lspLoading || sttLoading || ttsVoiceLoading || terminalLoading || saving || runtimeSaving || sessionsMaintenanceSaving || updatesSaving || compressionSaving || promptCachingSaving || openrouterCacheSaving || providerRoutingSaving || auxiliarySaving || toolGuardrailsSaving || memorySaving || skillsSaving || curatorSaving || quickCommandsSaving || modelSaving || modelCatalogSaving || xSearchSaving || modelAliasesSaving || hooksSaving || providerOverridesSaving || mcpServersSaving || agentToolsetsSaving || platformToolsetsSaving || agentRuntimeSaving || unauthorizedDmSaving || securitySaving || displaySaving || humanDelaySaving || kanbanSaving || streamingSaving || executionLimitsSaving || ioSafetySaving || checkpointsSaving || cronSaving || loggingSaving || approvalsSaving || privacySaving || browserSaving || webSaving || lspSaving || sttSaving || ttsVoiceSaving || terminalSaving
|
||||
return loading || runtimeLoading || sessionsMaintenanceLoading || updatesLoading || compressionLoading || promptCachingLoading || openrouterCacheLoading || providerRoutingLoading || auxiliaryLoading || toolGuardrailsLoading || memoryLoading || skillsLoading || curatorLoading || quickCommandsLoading || modelLoading || modelCatalogLoading || xSearchLoading || contextLoading || modelAliasesLoading || hooksLoading || providerOverridesLoading || mcpServersLoading || agentToolsetsLoading || platformToolsetsLoading || agentRuntimeLoading || unauthorizedDmLoading || securityLoading || displayLoading || humanDelayLoading || kanbanLoading || streamingLoading || executionLimitsLoading || ioSafetyLoading || checkpointsLoading || cronLoading || loggingLoading || approvalsLoading || privacyLoading || browserLoading || webLoading || lspLoading || sttLoading || ttsVoiceLoading || terminalLoading || saving || runtimeSaving || sessionsMaintenanceSaving || updatesSaving || compressionSaving || promptCachingSaving || openrouterCacheSaving || providerRoutingSaving || auxiliarySaving || toolGuardrailsSaving || memorySaving || skillsSaving || curatorSaving || quickCommandsSaving || modelSaving || modelCatalogSaving || xSearchSaving || contextSaving || modelAliasesSaving || hooksSaving || providerOverridesSaving || mcpServersSaving || agentToolsetsSaving || platformToolsetsSaving || agentRuntimeSaving || unauthorizedDmSaving || securitySaving || displaySaving || humanDelaySaving || kanbanSaving || streamingSaving || executionLimitsSaving || ioSafetySaving || checkpointsSaving || cronSaving || loggingSaving || approvalsSaving || privacySaving || browserSaving || webSaving || lspSaving || sttSaving || ttsVoiceSaving || terminalSaving
|
||||
}
|
||||
|
||||
function option(labelKey, value, selected) {
|
||||
@@ -1366,6 +1374,34 @@ export function render() {
|
||||
`
|
||||
}
|
||||
|
||||
function renderContextConfigPanel() {
|
||||
const disabled = loading || saving || contextLoading || contextSaving || modelSaving || modelCatalogSaving || xSearchSaving || quickCommandsSaving || modelAliasesSaving || hooksSaving || providerOverridesSaving || mcpServersSaving || agentToolsetsSaving || agentRuntimeSaving || runtimeSaving || compressionSaving || promptCachingSaving || openrouterCacheSaving || providerRoutingSaving || auxiliarySaving || toolGuardrailsSaving || memorySaving || skillsSaving || streamingSaving || executionLimitsSaving || checkpointsSaving || cronSaving || loggingSaving || approvalsSaving || terminalSaving
|
||||
return `
|
||||
<div class="hm-panel hm-config-runtime-panel hm-config-context-panel">
|
||||
<div class="hm-panel-header">
|
||||
<div>
|
||||
<div class="hm-panel-title">${t('engine.hermesContextConfigTitle')}</div>
|
||||
<div class="hm-channel-panel-desc">${t('engine.hermesContextConfigDesc')}</div>
|
||||
</div>
|
||||
<div class="hm-panel-actions">
|
||||
<span class="hm-muted">${contextSaving ? t('engine.hermesConfigStatusSaving') : contextLoading ? t('engine.hermesConfigStatusLoading') : t('engine.hermesContextConfigStatusReady')}</span>
|
||||
<button class="hm-btn hm-btn--cta hm-btn--sm" id="hm-context-config-save" ${disabled ? 'disabled' : ''}>${t('engine.hermesContextConfigSave')}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hm-panel-body">
|
||||
${renderError(contextError)}
|
||||
<div class="hm-config-runtime-grid">
|
||||
<label class="hm-field hm-field--wide">
|
||||
<span class="hm-field-label">${t('engine.hermesContextConfigEngine')}</span>
|
||||
<input id="hm-context-engine" class="hm-input" value="${esc(contextValues.contextEngine)}" placeholder="compressor" ${disabled ? 'disabled' : ''}>
|
||||
</label>
|
||||
</div>
|
||||
<div class="hm-channel-footnote">${t('engine.hermesContextConfigFootnote')}</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
|
||||
function renderModelAliasesConfigPanel() {
|
||||
const disabled = loading || saving || modelAliasesLoading || modelAliasesSaving || quickCommandsSaving || modelSaving || modelCatalogSaving || xSearchSaving || hooksSaving || providerOverridesSaving || mcpServersSaving || agentToolsetsSaving || agentRuntimeSaving || runtimeSaving || compressionSaving || promptCachingSaving || openrouterCacheSaving || providerRoutingSaving || auxiliarySaving || toolGuardrailsSaving || memorySaving || skillsSaving || streamingSaving || executionLimitsSaving || checkpointsSaving || cronSaving || loggingSaving || approvalsSaving || terminalSaving
|
||||
return `
|
||||
@@ -2802,6 +2838,7 @@ export function render() {
|
||||
${renderModelConfigPanel()}
|
||||
${renderModelCatalogConfigPanel()}
|
||||
${renderXSearchConfigPanel()}
|
||||
${renderContextConfigPanel()}
|
||||
${renderModelAliasesConfigPanel()}
|
||||
${renderHooksConfigPanel()}
|
||||
${renderProviderOverridesConfigPanel()}
|
||||
@@ -2849,6 +2886,7 @@ export function render() {
|
||||
el.querySelector('#hm-model-config-save')?.addEventListener('click', saveModelConfig)
|
||||
el.querySelector('#hm-model-catalog-save')?.addEventListener('click', saveModelCatalogConfig)
|
||||
el.querySelector('#hm-x-search-save')?.addEventListener('click', saveXSearchConfig)
|
||||
el.querySelector('#hm-context-config-save')?.addEventListener('click', saveContextConfig)
|
||||
el.querySelector('#hm-model-aliases-save')?.addEventListener('click', saveModelAliasesConfig)
|
||||
el.querySelector('#hm-hooks-save')?.addEventListener('click', saveHooksConfig)
|
||||
el.querySelector('#hm-provider-overrides-save')?.addEventListener('click', saveProviderOverridesConfig)
|
||||
@@ -2962,6 +3000,11 @@ export function render() {
|
||||
xSearchValues = { ...X_SEARCH_DEFAULTS, ...(data?.values || {}) }
|
||||
}
|
||||
|
||||
async function loadContextConfig() {
|
||||
const data = await api.hermesContextConfigRead()
|
||||
contextValues = { ...CONTEXT_DEFAULTS, ...(data?.values || {}) }
|
||||
}
|
||||
|
||||
async function loadModelAliasesConfig() {
|
||||
const data = await api.hermesModelAliasesConfigRead()
|
||||
modelAliasesValues = { ...MODEL_ALIASES_DEFAULTS, ...(data?.values || {}) }
|
||||
@@ -3110,6 +3153,7 @@ export function render() {
|
||||
modelLoading = true
|
||||
modelCatalogLoading = true
|
||||
xSearchLoading = true
|
||||
contextLoading = true
|
||||
modelAliasesLoading = true
|
||||
hooksLoading = true
|
||||
providerOverridesLoading = true
|
||||
@@ -3153,6 +3197,7 @@ export function render() {
|
||||
modelError = null
|
||||
modelCatalogError = null
|
||||
xSearchError = null
|
||||
contextError = null
|
||||
modelAliasesError = null
|
||||
hooksError = null
|
||||
providerOverridesError = null
|
||||
@@ -3426,6 +3471,14 @@ export function render() {
|
||||
xSearchLoading = false
|
||||
draw()
|
||||
}
|
||||
try {
|
||||
await loadContextConfig()
|
||||
} catch (err) {
|
||||
contextError = humanizeError(err, t('engine.hermesContextConfigLoadFailed') || 'Load context config failed')
|
||||
} finally {
|
||||
contextLoading = false
|
||||
draw()
|
||||
}
|
||||
try {
|
||||
await loadModelAliasesConfig()
|
||||
} catch (err) {
|
||||
@@ -4119,6 +4172,31 @@ export function render() {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveContextConfig() {
|
||||
const form = {
|
||||
contextEngine: el.querySelector('#hm-context-engine')?.value || CONTEXT_DEFAULTS.contextEngine,
|
||||
}
|
||||
contextSaving = true
|
||||
contextError = null
|
||||
draw()
|
||||
try {
|
||||
const result = await api.hermesContextConfigSave(form)
|
||||
contextValues = { ...CONTEXT_DEFAULTS, ...(result?.values || form) }
|
||||
await refreshRawAfterStructuredSave()
|
||||
const backup = result?.backup || ''
|
||||
toast({
|
||||
message: t('engine.hermesContextConfigSaveSuccess'),
|
||||
hint: backup ? t('engine.hermesConfigBackupHint', { path: backup }) : '',
|
||||
}, 'success')
|
||||
} catch (err) {
|
||||
contextError = humanizeError(err, t('engine.hermesContextConfigSaveFailed') || 'Save context config failed')
|
||||
toast(contextError, 'error')
|
||||
} finally {
|
||||
contextSaving = false
|
||||
draw()
|
||||
}
|
||||
}
|
||||
|
||||
async function saveModelAliasesConfig() {
|
||||
const form = {
|
||||
modelAliasesJson: el.querySelector('#hm-model-aliases-json')?.value || '{}',
|
||||
|
||||
@@ -587,6 +587,8 @@ export const api = {
|
||||
hermesModelCatalogConfigSave: (form) => invoke('hermes_model_catalog_config_save', { form }),
|
||||
hermesXSearchConfigRead: () => invoke('hermes_x_search_config_read'),
|
||||
hermesXSearchConfigSave: (form) => invoke('hermes_x_search_config_save', { form }),
|
||||
hermesContextConfigRead: () => invoke('hermes_context_config_read'),
|
||||
hermesContextConfigSave: (form) => invoke('hermes_context_config_save', { form }),
|
||||
hermesSttConfigRead: () => invoke('hermes_stt_config_read'),
|
||||
hermesSttConfigSave: (form) => invoke('hermes_stt_config_save', { form }),
|
||||
hermesTtsVoiceConfigRead: () => invoke('hermes_tts_voice_config_read'),
|
||||
|
||||
@@ -762,6 +762,15 @@ export default {
|
||||
hermesXSearchConfigTimeoutSeconds: _('超时秒数', 'Timeout seconds', '逾時秒數'),
|
||||
hermesXSearchConfigRetries: _('重试次数', 'Retry count', '重試次數'),
|
||||
hermesXSearchConfigFootnote: _('这里写入 x_search.model、x_search.timeout_seconds 和 x_search.retries。xAI OAuth 或 XAI_API_KEY 仍由 Hermes 运行时读取;需要启用 x_search toolset 后才会调用该工具。未知 x_search 子字段会保留在 raw YAML 中。', 'This writes x_search.model, x_search.timeout_seconds, and x_search.retries. xAI OAuth or XAI_API_KEY is still read by the Hermes runtime; the x_search toolset must be enabled before the tool is called. Unknown x_search fields stay in raw YAML.', '這裡寫入 x_search.model、x_search.timeout_seconds 和 x_search.retries。xAI OAuth 或 XAI_API_KEY 仍由 Hermes 執行時讀取;需要啟用 x_search toolset 後才會呼叫該工具。未知 x_search 子欄位會保留在 raw YAML 中。'),
|
||||
hermesContextConfigTitle: _('上下文引擎', 'Context engine', '上下文引擎'),
|
||||
hermesContextConfigDesc: _('控制 Hermes 在接近上下文窗口上限时使用内置压缩器还是插件上下文引擎,适合长会话稳定性调优。', 'Control whether Hermes uses the built-in compressor or a plugin context engine when approaching the context window limit. Useful for long-session stability tuning.', '控制 Hermes 在接近上下文視窗上限時使用內建壓縮器還是外掛上下文引擎,適合長會話穩定性調校。'),
|
||||
hermesContextConfigStatusReady: _('结构化配置', 'structured settings', '結構化設定'),
|
||||
hermesContextConfigSave: _('保存上下文引擎配置', 'Save context engine settings', '儲存上下文引擎設定'),
|
||||
hermesContextConfigSaveSuccess: _('上下文引擎配置已保存,建议重启 Hermes Gateway 生效', 'Context engine settings saved. Restart Hermes Gateway to take effect.', '上下文引擎設定已儲存,建議重啟 Hermes Gateway 生效'),
|
||||
hermesContextConfigLoadFailed: _('加载上下文引擎配置失败', 'Load context engine settings failed', '載入上下文引擎設定失敗'),
|
||||
hermesContextConfigSaveFailed: _('保存上下文引擎配置失败', 'Save context engine settings failed', '儲存上下文引擎設定失敗'),
|
||||
hermesContextConfigEngine: _('引擎名称', 'Engine name', '引擎名稱'),
|
||||
hermesContextConfigFootnote: _('这里写入 context.engine。compressor 表示使用内置压缩器;填写插件名会让 Hermes 尝试加载 plugins/context_engine/<name>/ 或用户插件目录中的上下文引擎。未知 context 子字段会保留在 raw YAML 中。', 'This writes context.engine. compressor uses the built-in compressor; entering a plugin name makes Hermes try plugins/context_engine/<name>/ or user plugin directories. Unknown context fields stay in raw YAML.', '這裡寫入 context.engine。compressor 表示使用內建壓縮器;填寫外掛名稱會讓 Hermes 嘗試載入 plugins/context_engine/<name>/ 或使用者外掛目錄中的上下文引擎。未知 context 子欄位會保留在 raw YAML 中。'),
|
||||
hermesLspConfigTitle: _('LSP 语义诊断', 'LSP semantic diagnostics', 'LSP 語意診斷'),
|
||||
hermesLspConfigDesc: _('控制写文件和补丁后的语言服务器诊断等待、工作区扫描和缺失服务器自动安装策略。', 'Control language-server diagnostic waits, workspace scans, and missing-server install strategy after file writes and patches.', '控制寫檔和補丁後的語言伺服器診斷等待、工作區掃描和缺失伺服器自動安裝策略。'),
|
||||
hermesLspConfigStatusReady: _('结构化配置', 'structured settings', '結構化設定'),
|
||||
|
||||
@@ -150,6 +150,15 @@ test('Hermes 配置页会暴露 X 搜索结构化配置字段', () => {
|
||||
}
|
||||
})
|
||||
|
||||
test('Hermes 配置页会暴露上下文引擎结构化配置字段', () => {
|
||||
for (const id of [
|
||||
'hm-context-config-save',
|
||||
'hm-context-engine',
|
||||
]) {
|
||||
assert.match(source, new RegExp(`id="${id}"`), `缺少 ${id}`)
|
||||
}
|
||||
})
|
||||
|
||||
test('Hermes 配置页会暴露 provider 超时覆盖结构化配置字段', () => {
|
||||
for (const id of [
|
||||
'hm-provider-overrides-save',
|
||||
|
||||
58
tests/hermes-context-config.test.js
Normal file
58
tests/hermes-context-config.test.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import {
|
||||
buildHermesContextConfigValues,
|
||||
mergeHermesContextConfig,
|
||||
} from '../scripts/dev-api.js'
|
||||
|
||||
test('Hermes 上下文引擎配置读取会提供上游默认值', () => {
|
||||
const values = buildHermesContextConfigValues({})
|
||||
|
||||
assert.deepEqual(values, {
|
||||
contextEngine: 'compressor',
|
||||
})
|
||||
})
|
||||
|
||||
test('Hermes 上下文引擎配置读取会回显 YAML 字段', () => {
|
||||
const values = buildHermesContextConfigValues({
|
||||
context: {
|
||||
engine: 'lcm',
|
||||
},
|
||||
})
|
||||
|
||||
assert.equal(values.contextEngine, 'lcm')
|
||||
})
|
||||
|
||||
test('Hermes 上下文引擎配置保存会保留未知字段并写入上游结构', () => {
|
||||
const next = mergeHermesContextConfig({
|
||||
context: {
|
||||
engine: 'compressor',
|
||||
custom_flag: 'keep-context',
|
||||
},
|
||||
model: { provider: 'anthropic' },
|
||||
streaming: { enabled: true },
|
||||
}, {
|
||||
contextEngine: 'lcm',
|
||||
})
|
||||
|
||||
assert.deepEqual(next.model, { provider: 'anthropic' })
|
||||
assert.deepEqual(next.streaming, { enabled: true })
|
||||
assert.equal(next.context.engine, 'lcm')
|
||||
assert.equal(next.context.custom_flag, 'keep-context')
|
||||
})
|
||||
|
||||
test('Hermes 上下文引擎配置保存会拒绝非法引擎名', () => {
|
||||
assert.throws(
|
||||
() => mergeHermesContextConfig({}, { contextEngine: '' }),
|
||||
/context\.engine/,
|
||||
)
|
||||
assert.throws(
|
||||
() => mergeHermesContextConfig({}, { contextEngine: 'bad engine' }),
|
||||
/context\.engine/,
|
||||
)
|
||||
assert.throws(
|
||||
() => mergeHermesContextConfig({}, { contextEngine: '中文' }),
|
||||
/context\.engine/,
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user