feat(hermes): add streaming config form

This commit is contained in:
晴天
2026-05-24 08:40:53 +08:00
parent 1883e18f02
commit a1307716dd
9 changed files with 656 additions and 6 deletions

View File

@@ -3321,6 +3321,7 @@ function normalizeHermesPlatform(platform) {
}
const HERMES_SESSION_RESET_MODES = new Set(['both', 'idle', 'daily', 'none'])
const HERMES_STREAMING_TRANSPORTS = new Set(['auto', 'draft', 'edit', 'off'])
function parseHermesInteger(value, key, fallback, min, max, strict = false) {
const raw = String(value ?? '').trim()
@@ -3372,6 +3373,25 @@ function formHermesBool(form, key, fallback) {
return readHermesBool(form?.[key], fallback)
}
function normalizeHermesStreamingTransport(value, strict = false) {
const transport = String(value ?? '').trim().toLowerCase() || 'edit'
if (HERMES_STREAMING_TRANSPORTS.has(transport)) return transport
if (strict) throw new Error('streaming.transport 必须是 auto、draft、edit 或 off')
return 'edit'
}
function hermesStreamingConfigSource(root) {
if (root.streaming && typeof root.streaming === 'object' && !Array.isArray(root.streaming)) {
return root.streaming
}
const gateway = root.gateway && typeof root.gateway === 'object' && !Array.isArray(root.gateway)
? root.gateway
: {}
return gateway.streaming && typeof gateway.streaming === 'object' && !Array.isArray(gateway.streaming)
? gateway.streaming
: {}
}
export function buildHermesCompressionConfigValues(config = {}) {
const root = config && typeof config === 'object' && !Array.isArray(config) ? config : {}
const compression = root.compression && typeof root.compression === 'object' && !Array.isArray(root.compression)
@@ -3482,6 +3502,35 @@ export function mergeHermesMemoryConfig(config = {}, form = {}) {
return next
}
export function buildHermesStreamingConfigValues(config = {}) {
const root = config && typeof config === 'object' && !Array.isArray(config) ? config : {}
const streaming = hermesStreamingConfigSource(root)
return {
enabled: readHermesBool(streaming.enabled, false),
transport: normalizeHermesStreamingTransport(streaming.transport, false),
editInterval: parseHermesFloat(streaming.edit_interval, 'streaming.edit_interval', 0.8, 0.05, 60, false),
bufferThreshold: parseHermesInteger(streaming.buffer_threshold, 'streaming.buffer_threshold', 24, 1, 5000, false),
cursor: typeof streaming.cursor === 'string' ? streaming.cursor : ' ▉',
freshFinalAfterSeconds: parseHermesFloat(streaming.fresh_final_after_seconds, 'streaming.fresh_final_after_seconds', 60, 0, 86400, false),
}
}
export function mergeHermesStreamingConfig(config = {}, form = {}) {
const next = mergeConfigsPreservingFields({}, config && typeof config === 'object' && !Array.isArray(config) ? config : {})
const currentValues = buildHermesStreamingConfigValues(next)
const streaming = next.streaming && typeof next.streaming === 'object' && !Array.isArray(next.streaming)
? mergeConfigsPreservingFields(next.streaming, {})
: {}
streaming.enabled = formHermesBool(form, 'enabled', currentValues.enabled)
streaming.transport = normalizeHermesStreamingTransport(Object.hasOwn(form, 'transport') ? form.transport : currentValues.transport, true)
streaming.edit_interval = parseHermesFloat(Object.hasOwn(form, 'editInterval') ? form.editInterval : currentValues.editInterval, 'streaming.edit_interval', 0.8, 0.05, 60, true)
streaming.buffer_threshold = parseHermesInteger(Object.hasOwn(form, 'bufferThreshold') ? form.bufferThreshold : currentValues.bufferThreshold, 'streaming.buffer_threshold', 24, 1, 5000, true)
streaming.cursor = Object.hasOwn(form, 'cursor') ? String(form.cursor ?? '') : currentValues.cursor
streaming.fresh_final_after_seconds = parseHermesFloat(Object.hasOwn(form, 'freshFinalAfterSeconds') ? form.freshFinalAfterSeconds : currentValues.freshFinalAfterSeconds, 'streaming.fresh_final_after_seconds', 60, 0, 86400, true)
next.streaming = streaming
return next
}
export function buildHermesSessionRuntimeConfigValues(config = {}) {
const root = config && typeof config === 'object' && !Array.isArray(config) ? config : {}
const sessionReset = root.session_reset && typeof root.session_reset === 'object' && !Array.isArray(root.session_reset)
@@ -9767,6 +9816,27 @@ const handlers = {
}
},
hermes_streaming_config_read() {
const { configPath, exists, config } = readHermesConfigYamlObject()
return {
exists,
configPath,
values: buildHermesStreamingConfigValues(config),
}
},
hermes_streaming_config_save({ form } = {}) {
const { configPath, config } = readHermesConfigYamlObject()
const next = mergeHermesStreamingConfig(config, form || {})
const backup = writeHermesConfigYamlObject(configPath, next)
return {
ok: true,
configPath,
backup,
values: buildHermesStreamingConfigValues(next),
}
},
// P1-3 lazy_deps: Web 模式下不能调 venv python但仍提供 feature 列表 + 提示用户走桌面端装
hermes_lazy_deps_features() {
const features = [