mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-07-12 16:01:56 +08:00
feat(hermes): add quick commands config form
This commit is contained in:
@@ -49,6 +49,15 @@ test('Hermes 配置页会暴露 Skills 结构化配置字段', () => {
|
||||
}
|
||||
})
|
||||
|
||||
test('Hermes 配置页会暴露快捷命令结构化配置字段', () => {
|
||||
for (const id of [
|
||||
'hm-quick-commands-save',
|
||||
'hm-quick-commands-json',
|
||||
]) {
|
||||
assert.match(source, new RegExp(`id="${id}"`), `缺少 ${id}`)
|
||||
}
|
||||
})
|
||||
|
||||
test('Hermes 配置页会暴露网关流式结构化配置字段', () => {
|
||||
for (const id of [
|
||||
'hm-streaming-save',
|
||||
@@ -108,6 +117,7 @@ test('Hermes 配置页新增结构化配置不会暴露翻译 key', () => {
|
||||
key.includes('ToolGuardrails') ||
|
||||
key.includes('MemoryConfig') ||
|
||||
key.includes('SkillsConfig') ||
|
||||
key.includes('QuickCommandsConfig') ||
|
||||
key.includes('StreamingConfig') ||
|
||||
key.includes('ExecutionLimits') ||
|
||||
key.includes('TerminalConfig')
|
||||
|
||||
86
tests/hermes-quick-commands-config.test.js
Normal file
86
tests/hermes-quick-commands-config.test.js
Normal file
@@ -0,0 +1,86 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import {
|
||||
buildHermesQuickCommandsConfigValues,
|
||||
mergeHermesQuickCommandsConfig,
|
||||
} from '../scripts/dev-api.js'
|
||||
|
||||
test('Hermes 快捷命令配置读取会提供空对象默认值', () => {
|
||||
const values = buildHermesQuickCommandsConfigValues({})
|
||||
|
||||
assert.equal(values.quickCommandsJson, '{}')
|
||||
})
|
||||
|
||||
test('Hermes 快捷命令配置读取会格式化已有映射', () => {
|
||||
const values = buildHermesQuickCommandsConfigValues({
|
||||
quick_commands: {
|
||||
status: { type: 'exec', command: 'systemctl status hermes-agent' },
|
||||
restart: { type: 'alias', target: '/gateway restart' },
|
||||
},
|
||||
})
|
||||
|
||||
assert.deepEqual(JSON.parse(values.quickCommandsJson), {
|
||||
status: { type: 'exec', command: 'systemctl status hermes-agent' },
|
||||
restart: { type: 'alias', target: '/gateway restart' },
|
||||
})
|
||||
})
|
||||
|
||||
test('Hermes 快捷命令配置保存会保留无关 YAML 并写入顶层映射', () => {
|
||||
const next = mergeHermesQuickCommandsConfig({
|
||||
model: { provider: 'anthropic' },
|
||||
quick_commands: {
|
||||
old: { type: 'exec', command: 'uptime', custom_flag: 'drop-with-replace' },
|
||||
},
|
||||
memory: { memory_enabled: true },
|
||||
}, {
|
||||
quickCommandsJson: JSON.stringify({
|
||||
status: { type: 'exec', command: 'systemctl status hermes-agent', timeout: 10 },
|
||||
restart: { type: 'alias', target: '/gateway restart' },
|
||||
}),
|
||||
})
|
||||
|
||||
assert.deepEqual(next.model, { provider: 'anthropic' })
|
||||
assert.deepEqual(next.memory, { memory_enabled: true })
|
||||
assert.deepEqual(next.quick_commands, {
|
||||
status: { type: 'exec', command: 'systemctl status hermes-agent', timeout: 10 },
|
||||
restart: { type: 'alias', target: '/gateway restart' },
|
||||
})
|
||||
})
|
||||
|
||||
test('Hermes 快捷命令配置保存空对象会移除 quick_commands', () => {
|
||||
const next = mergeHermesQuickCommandsConfig({
|
||||
quick_commands: {
|
||||
status: { type: 'exec', command: 'uptime' },
|
||||
},
|
||||
streaming: { enabled: true },
|
||||
}, {
|
||||
quickCommandsJson: '{}',
|
||||
})
|
||||
|
||||
assert.equal(next.quick_commands, undefined)
|
||||
assert.deepEqual(next.streaming, { enabled: true })
|
||||
})
|
||||
|
||||
test('Hermes 快捷命令配置保存会拒绝非法 JSON 和非法命令结构', () => {
|
||||
assert.throws(
|
||||
() => mergeHermesQuickCommandsConfig({}, { quickCommandsJson: '[' }),
|
||||
/quick_commands/,
|
||||
)
|
||||
assert.throws(
|
||||
() => mergeHermesQuickCommandsConfig({}, { quickCommandsJson: '[]' }),
|
||||
/quick_commands/,
|
||||
)
|
||||
assert.throws(
|
||||
() => mergeHermesQuickCommandsConfig({}, { quickCommandsJson: JSON.stringify({ bad: 'uptime' }) }),
|
||||
/quick_commands\.bad/,
|
||||
)
|
||||
assert.throws(
|
||||
() => mergeHermesQuickCommandsConfig({}, { quickCommandsJson: JSON.stringify({ status: { type: 'exec', command: '' } }) }),
|
||||
/quick_commands\.status\.command/,
|
||||
)
|
||||
assert.throws(
|
||||
() => mergeHermesQuickCommandsConfig({}, { quickCommandsJson: JSON.stringify({ restart: { type: 'alias', target: 'gateway restart' } }) }),
|
||||
/quick_commands\.restart\.target/,
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user