feat(hermes): add openrouter cache config

This commit is contained in:
晴天
2026-05-26 02:36:37 +08:00
parent a52b70ade7
commit fb7ae3f15c
8 changed files with 399 additions and 27 deletions

View File

@@ -3743,6 +3743,29 @@ export function mergeHermesPromptCachingConfig(config = {}, form = {}) {
return next
}
export function buildHermesOpenrouterCacheConfigValues(config = {}) {
const root = config && typeof config === 'object' && !Array.isArray(config) ? config : {}
const openrouter = root.openrouter && typeof root.openrouter === 'object' && !Array.isArray(root.openrouter)
? root.openrouter
: {}
return {
openrouterResponseCache: readHermesBool(openrouter.response_cache, true),
openrouterResponseCacheTtl: parseHermesInteger(openrouter.response_cache_ttl, 'openrouter.response_cache_ttl', 300, 1, 86400, false),
}
}
export function mergeHermesOpenrouterCacheConfig(config = {}, form = {}) {
const next = mergeConfigsPreservingFields({}, config && typeof config === 'object' && !Array.isArray(config) ? config : {})
const currentValues = buildHermesOpenrouterCacheConfigValues(next)
const openrouter = next.openrouter && typeof next.openrouter === 'object' && !Array.isArray(next.openrouter)
? mergeConfigsPreservingFields(next.openrouter, {})
: {}
openrouter.response_cache = formHermesBool(form, 'openrouterResponseCache', currentValues.openrouterResponseCache)
openrouter.response_cache_ttl = parseHermesInteger(Object.hasOwn(form, 'openrouterResponseCacheTtl') ? form.openrouterResponseCacheTtl : currentValues.openrouterResponseCacheTtl, 'openrouter.response_cache_ttl', 300, 1, 86400, true)
next.openrouter = openrouter
return next
}
function hermesAuxiliaryTask(root, key) {
const auxiliary = root.auxiliary && typeof root.auxiliary === 'object' && !Array.isArray(root.auxiliary)
? root.auxiliary
@@ -10908,6 +10931,27 @@ const handlers = {
}
},
hermes_openrouter_cache_config_read() {
const { configPath, exists, config } = readHermesConfigYamlObject()
return {
exists,
configPath,
values: buildHermesOpenrouterCacheConfigValues(config),
}
},
hermes_openrouter_cache_config_save({ form } = {}) {
const { configPath, config } = readHermesConfigYamlObject()
const next = mergeHermesOpenrouterCacheConfig(config, form || {})
const backup = writeHermesConfigYamlObject(configPath, next)
return {
ok: true,
configPath,
backup,
values: buildHermesOpenrouterCacheConfigValues(next),
}
},
hermes_auxiliary_config_read() {
const { configPath, exists, config } = readHermesConfigYamlObject()
return {