feat(hermes): add unauthorized dm policy form

This commit is contained in:
晴天
2026-05-24 21:41:17 +08:00
parent 2de5d1e38a
commit 7be0ec66cc
8 changed files with 347 additions and 6 deletions

View File

@@ -3675,6 +3675,30 @@ export function mergeHermesQuickCommandsConfig(config = {}, form = {}) {
return next
}
function normalizeHermesUnauthorizedDmBehavior(value, strict = false) {
const normalized = String(value ?? '').trim().toLowerCase()
if (['pair', 'ignore'].includes(normalized)) return normalized
if (strict) throw new Error('unauthorized_dm_behavior 必须是 pair 或 ignore')
return 'pair'
}
export function buildHermesUnauthorizedDmConfigValues(config = {}) {
const root = config && typeof config === 'object' && !Array.isArray(config) ? config : {}
return {
unauthorizedDmBehavior: normalizeHermesUnauthorizedDmBehavior(root.unauthorized_dm_behavior, false),
}
}
export function mergeHermesUnauthorizedDmConfig(config = {}, form = {}) {
const next = mergeConfigsPreservingFields({}, config && typeof config === 'object' && !Array.isArray(config) ? config : {})
const currentValues = buildHermesUnauthorizedDmConfigValues(next)
next.unauthorized_dm_behavior = normalizeHermesUnauthorizedDmBehavior(
Object.hasOwn(form, 'unauthorizedDmBehavior') ? form.unauthorizedDmBehavior : currentValues.unauthorizedDmBehavior,
true,
)
return next
}
export function buildHermesStreamingConfigValues(config = {}) {
const root = config && typeof config === 'object' && !Array.isArray(config) ? config : {}
const streaming = hermesStreamingConfigSource(root)
@@ -10181,6 +10205,27 @@ const handlers = {
}
},
hermes_unauthorized_dm_config_read() {
const { configPath, exists, config } = readHermesConfigYamlObject()
return {
exists,
configPath,
values: buildHermesUnauthorizedDmConfigValues(config),
}
},
hermes_unauthorized_dm_config_save({ form } = {}) {
const { configPath, config } = readHermesConfigYamlObject()
const next = mergeHermesUnauthorizedDmConfig(config, form || {})
const backup = writeHermesConfigYamlObject(configPath, next)
return {
ok: true,
configPath,
backup,
values: buildHermesUnauthorizedDmConfigValues(next),
}
},
hermes_streaming_config_read() {
const { configPath, exists, config } = readHermesConfigYamlObject()
return {