feat(agent): 增强 Agent 配置,新增结构化字段与聊天功能支持

This commit is contained in:
hugo committed 2026-07-07 11:10:32 +08:00
1 parent ac4262cd75
commit c8ce77199e
183 files changed
+11690 -2300

No files matched your search

@@ -0,0 +1,61 @@
/**
* shared/utils/agent-registry.utils.test.ts
*
* 用途:锁定 Agent Registry 前端读取契约,防止回退到名称白名单。
*/
import { describe, expect, it } from 'vitest';
import {
AGENT_CODE_SHIPPING_NOTICE,
agentHasIntentUiProfile,
agentHasTaskProgress,
canUseLeaveFeature,
isHrFocusedAgent,
isShippingNoticeAgent,
resolveAgentContentProfileKey,
resolveAgentCode,
resolveIntentRoutes,
} from './agent-registry.utils';
describe('agent-registry.utils', () => {
it('resolveAgentCode prefers column over name', () => {
expect(resolveAgentCode({ name: '货代发货通知 Agent', agent_code: AGENT_CODE_SHIPPING_NOTICE })).toBe(
AGENT_CODE_SHIPPING_NOTICE,
);
expect(resolveAgentCode({ name: '货代发货通知 Agent' })).toBe('generic');
});
it('isShippingNoticeAgent uses agent_code only', () => {
expect(isShippingNoticeAgent({ name: '智能发货通知Agent', agent_code: AGENT_CODE_SHIPPING_NOTICE })).toBe(true);
expect(isShippingNoticeAgent({ name: '货代发货通知 Agent' })).toBe(false);
});
it('agentHasTaskProgress requires strict true on capabilities column', () => {
expect(agentHasTaskProgress({ agent_code: 'file_check' })).toBe(false);
expect(agentHasTaskProgress({ capabilities: { task_progress: true } })).toBe(true);
expect(agentHasTaskProgress({ capabilities: { task_progress: false } })).toBe(false);
});
it('canUseLeaveFeature reads leave_feature_enabled from server', () => {
expect(canUseLeaveFeature({ leave_feature_enabled: true })).toBe(true);
expect(canUseLeaveFeature({ name: '人事规章' })).toBe(false);
});
it('isHrFocusedAgent reads hr_focused_avatar from server', () => {
expect(isHrFocusedAgent({ hr_focused_avatar: true })).toBe(true);
expect(isHrFocusedAgent({ hr_focused_avatar: false })).toBe(false);
});
it('resolveAgentContentProfileKey prefers content_profile_key from server', () => {
expect(resolveAgentContentProfileKey({ content_profile_key: 'generic_entrance' })).toBe('generic_entrance');
expect(resolveAgentContentProfileKey({ content_profile_key: 'hr_policy' })).toBe('hr_policy');
expect(resolveAgentContentProfileKey({
handler_config: { content_profile: 'hr_policy' },
})).toBe('hr_policy');
expect(resolveIntentRoutes({ handler_config: { intent_routes: ['text2sql'] } })).toEqual(new Set(['text2sql']));
});
it('agentHasIntentUiProfile checks intent_ui_profiles from server', () => {
expect(agentHasIntentUiProfile({ intent_ui_profiles: ['maintenance'] }, 'maintenance')).toBe(true);
expect(agentHasIntentUiProfile({ intent_ui_profiles: [] }, 'maintenance')).toBe(false);
});
});