feat: 重构为 Monorepo 架构并实现 HTTP Server
架构变更: - 采用 pnpm workspaces 实现 Monorepo 结构 - 将现有代码迁移到 packages/core - 新增 packages/server HTTP 服务层 Server 功能: - REST API: 会话管理、工具管理、配置管理 - WebSocket: 实时双向通信支持 - SSE: 服务端事件推送 - Hono + Bun 作为运行时 API 端点: - GET/POST /api/sessions - 会话 CRUD - GET/POST /api/sessions/:id/messages - 消息管理 - GET /api/sessions/:id/events - SSE 事件流 - WS /api/ws/:sessionId - WebSocket 连接 - GET/POST /api/tools - 工具管理 - GET/PUT /api/config - 配置管理
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
presetAgents,
|
||||
getPresetAgentNames,
|
||||
isPresetAgent,
|
||||
generalAgent,
|
||||
exploreAgent,
|
||||
codeReviewerAgent,
|
||||
buildAgent,
|
||||
planAgent,
|
||||
visionAgent,
|
||||
} from '../../../../src/agent/presets/index.js';
|
||||
|
||||
describe('Agent Presets - 预设 Agent', () => {
|
||||
describe('presetAgents 集合', () => {
|
||||
it('包含所有预设 Agent', () => {
|
||||
expect(Object.keys(presetAgents)).toHaveLength(6);
|
||||
});
|
||||
|
||||
it('包含 general Agent', () => {
|
||||
expect(presetAgents['general']).toBeDefined();
|
||||
expect(presetAgents['general']).toBe(generalAgent);
|
||||
});
|
||||
|
||||
it('包含 explore Agent', () => {
|
||||
expect(presetAgents['explore']).toBeDefined();
|
||||
expect(presetAgents['explore']).toBe(exploreAgent);
|
||||
});
|
||||
|
||||
it('包含 code-reviewer Agent', () => {
|
||||
expect(presetAgents['code-reviewer']).toBeDefined();
|
||||
expect(presetAgents['code-reviewer']).toBe(codeReviewerAgent);
|
||||
});
|
||||
|
||||
it('包含 build Agent', () => {
|
||||
expect(presetAgents['build']).toBeDefined();
|
||||
expect(presetAgents['build']).toBe(buildAgent);
|
||||
});
|
||||
|
||||
it('包含 plan Agent', () => {
|
||||
expect(presetAgents['plan']).toBeDefined();
|
||||
expect(presetAgents['plan']).toBe(planAgent);
|
||||
});
|
||||
|
||||
it('包含 vision Agent', () => {
|
||||
expect(presetAgents['vision']).toBeDefined();
|
||||
expect(presetAgents['vision']).toBe(visionAgent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPresetAgentNames - 获取预设名称', () => {
|
||||
it('返回所有预设 Agent 名称', () => {
|
||||
const names = getPresetAgentNames();
|
||||
|
||||
expect(names).toContain('general');
|
||||
expect(names).toContain('explore');
|
||||
expect(names).toContain('code-reviewer');
|
||||
expect(names).toContain('build');
|
||||
expect(names).toContain('plan');
|
||||
expect(names).toContain('vision');
|
||||
});
|
||||
|
||||
it('返回数组类型', () => {
|
||||
const names = getPresetAgentNames();
|
||||
expect(Array.isArray(names)).toBe(true);
|
||||
});
|
||||
|
||||
it('返回正确数量', () => {
|
||||
const names = getPresetAgentNames();
|
||||
expect(names).toHaveLength(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPresetAgent - 检查是否为预设', () => {
|
||||
it('识别 general', () => {
|
||||
expect(isPresetAgent('general')).toBe(true);
|
||||
});
|
||||
|
||||
it('识别 explore', () => {
|
||||
expect(isPresetAgent('explore')).toBe(true);
|
||||
});
|
||||
|
||||
it('识别 code-reviewer', () => {
|
||||
expect(isPresetAgent('code-reviewer')).toBe(true);
|
||||
});
|
||||
|
||||
it('识别 build', () => {
|
||||
expect(isPresetAgent('build')).toBe(true);
|
||||
});
|
||||
|
||||
it('识别 plan', () => {
|
||||
expect(isPresetAgent('plan')).toBe(true);
|
||||
});
|
||||
|
||||
it('识别 vision', () => {
|
||||
expect(isPresetAgent('vision')).toBe(true);
|
||||
});
|
||||
|
||||
it('不识别未知 Agent', () => {
|
||||
expect(isPresetAgent('unknown')).toBe(false);
|
||||
});
|
||||
|
||||
it('不识别空字符串', () => {
|
||||
expect(isPresetAgent('')).toBe(false);
|
||||
});
|
||||
|
||||
it('区分大小写', () => {
|
||||
expect(isPresetAgent('General')).toBe(false);
|
||||
expect(isPresetAgent('GENERAL')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('generalAgent - 通用 Agent', () => {
|
||||
it('有正确的描述', () => {
|
||||
expect(generalAgent.description).toContain('通用');
|
||||
});
|
||||
|
||||
it('mode 为 subagent', () => {
|
||||
expect(generalAgent.mode).toBe('subagent');
|
||||
});
|
||||
|
||||
it('禁止嵌套 Task', () => {
|
||||
expect(generalAgent.tools?.noTask).toBe(true);
|
||||
});
|
||||
|
||||
it('有 maxSteps 限制', () => {
|
||||
expect(generalAgent.maxSteps).toBeDefined();
|
||||
expect(generalAgent.maxSteps).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('exploreAgent - 探索 Agent', () => {
|
||||
it('有描述', () => {
|
||||
expect(exploreAgent.description).toBeDefined();
|
||||
});
|
||||
|
||||
it('mode 为 subagent', () => {
|
||||
expect(exploreAgent.mode).toBe('subagent');
|
||||
});
|
||||
});
|
||||
|
||||
describe('codeReviewerAgent - 代码审查 Agent', () => {
|
||||
it('有描述', () => {
|
||||
expect(codeReviewerAgent.description).toBeDefined();
|
||||
});
|
||||
|
||||
it('mode 为 subagent', () => {
|
||||
expect(codeReviewerAgent.mode).toBe('subagent');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildAgent - 构建 Agent', () => {
|
||||
it('有描述', () => {
|
||||
expect(buildAgent.description).toBeDefined();
|
||||
});
|
||||
|
||||
it('mode 为 primary(主模式)', () => {
|
||||
expect(buildAgent.mode).toBe('primary');
|
||||
});
|
||||
});
|
||||
|
||||
describe('planAgent - 计划 Agent', () => {
|
||||
it('有描述', () => {
|
||||
expect(planAgent.description).toBeDefined();
|
||||
});
|
||||
|
||||
it('mode 为 primary(主模式)', () => {
|
||||
expect(planAgent.mode).toBe('primary');
|
||||
});
|
||||
});
|
||||
|
||||
describe('visionAgent - 视觉 Agent', () => {
|
||||
it('有描述', () => {
|
||||
expect(visionAgent.description).toBeDefined();
|
||||
});
|
||||
|
||||
it('mode 为 subagent', () => {
|
||||
expect(visionAgent.mode).toBe('subagent');
|
||||
});
|
||||
});
|
||||
|
||||
describe('所有预设 Agent 共同特性', () => {
|
||||
it('都有 description', () => {
|
||||
Object.entries(presetAgents).forEach(([name, agent]) => {
|
||||
expect(agent.description, `${name} 缺少 description`).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('都有 mode', () => {
|
||||
Object.entries(presetAgents).forEach(([name, agent]) => {
|
||||
expect(agent.mode, `${name} 缺少 mode`).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('mode 值是 subagent 或 primary', () => {
|
||||
Object.entries(presetAgents).forEach(([name, agent]) => {
|
||||
expect(['subagent', 'primary'], `${name} mode 无效`).toContain(agent.mode);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user