Phase 3.5: Automation & Agents Plugin

Neues automation Plugin (app/plugins/builtins/automation/):
- 7 DB-Modelle: AgentDefinition, AgentVersion, AutomationDefinition,
  AutomationVersion, AutomationCronJob, AgentRun, AutomationRun
- Migration 0001_initial.sql mit allen Tabellen + RLS
- PluginManifest erweitert: agent_definitions, automation_templates,
  cron_jobs, heartbeat_configs, miniapps Contribution-Felder
- 21 API-Endpoints: /api/v1/automation (CRUD, execute, dry-run,
  runs, versions, restore, settings, miniapps) + /api/v1/agents
  (CRUD, execute, test-run, runs, versions, restore, tools, send-message)

Backend Features:
- Cron-Scheduler (scheduler.py): ARQ-basiert, liest CronJob-Tabelle,
  enqueued run_agent/run_automation, croniter fuer next_run_at
- Workflow-Timeout-Worker (workflow_timeout.py): prueft abgelaufene
  WorkflowInstances, setzt cancelled, sendet Notification
- Agent Runner (agent_runner.py): LiteLLM + ToolRegistry, proactive/
  reactive mode, Rate-Limiting, Budget-Limit, Infinite-Loop-Detection
- Automation Execution Engine (execution_engine.py): Condition
  evaluation (eq/ne/gt/lt/contains/exists), Actions (api_call/
  notification/workflow_start), Dry-Run mode
- Agent-to-Agent Communication (agent_comm.py): send_agent_message
  tool, kommunikation plugin integration
- Plugin-Beitraege: register/unregister on activate/deactivate,
  Konfliktloesung mit Plugin-Name als Prefix
- Heartbeat-Migration: ai_proactive heartbeat als Cron-Job
- Versionshistorie: Auto-Versioning bei Updates, Restore-Endpoint
- Settings: GET/PATCH /api/v1/automation/settings
- ARQ Worker: 11 functions, 2 cron_jobs (scheduler_tick 30s,
  check_workflow_timeouts 5min)

Frontend:
- AutomationDashboard.tsx: Automation Builder UI mit Trigger,
  Conditions, Actions, Execute, Dry-Run, Run-History, Versions
- AgentDashboard.tsx: Agent Builder UI mit Model, Tools, Prompt,
  Heartbeat, Rate-Limits, Execute, Test-Run, Agent-Chat
- AutomationSettings.tsx: Settings + MiniApp-Builder
- automation.ts: 24 React Query Hooks
- automation.ts types: TypeScript Interfaces
- routes/index.tsx: /automation, /agents, /settings/automation

Tests:
- 22 Frontend-Tests (AutomationDashboard, AgentDashboard, API) — alle bestanden
- Backend-Tests: test_automation.py (CRUD, versions, conditions, dry-run, rate-limiting)
- TSC: keine neuen Errors (nur pre-existing Dms.tsx)
- croniter dependency installiert
This commit is contained in:
Agent Zero
2026-07-23 20:00:37 +02:00
parent fc96a2f86c
commit 5dc6f29ac1
28 changed files with 7397 additions and 0 deletions
@@ -0,0 +1,193 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
// Mock the API client
const mockApiGet = vi.fn();
const mockApiPost = vi.fn();
const mockApiPut = vi.fn();
const mockApiDelete = vi.fn();
vi.mock('@/api/client', () => ({
apiGet: (...args: any[]) => mockApiGet(...args),
apiPost: (...args: any[]) => mockApiPost(...args),
apiPut: (...args: any[]) => mockApiPut(...args),
apiDelete: (...args: any[]) => mockApiDelete(...args),
}));
// Mock react-query
vi.mock('@tanstack/react-query', () => ({
useQueryClient: () => ({
invalidateQueries: vi.fn(),
}),
useQuery: vi.fn(),
useMutation: vi.fn(({ mutationFn, onSuccess }) => ({
mutateAsync: async (args: any) => {
const result = await mutationFn(args);
if (onSuccess) onSuccess();
return result;
},
isPending: false,
})),
}));
describe('Automation API Hooks', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('useAutomations', () => {
it('calls apiGet with correct endpoint', async () => {
const { useAutomations } = await import('../automation');
const { useQuery } = await import('@tanstack/react-query');
(useQuery as any).mockImplementation(({ queryKey, queryFn }: any) => {
expect(queryKey).toEqual(['automations']);
queryFn();
return { data: [], isLoading: false };
});
useAutomations();
expect(mockApiGet).toHaveBeenCalledWith('/automation');
});
});
describe('useAgents', () => {
it('calls apiGet with correct endpoint', async () => {
const { useAgents } = await import('../automation');
const { useQuery } = await import('@tanstack/react-query');
(useQuery as any).mockImplementation(({ queryKey, queryFn }: any) => {
expect(queryKey).toEqual(['agents']);
queryFn();
return { data: [], isLoading: false };
});
useAgents();
expect(mockApiGet).toHaveBeenCalledWith('/agents');
});
});
describe('useCreateAutomation', () => {
it('calls apiPost with correct endpoint', async () => {
const { useCreateAutomation } = await import('../automation');
const hook = useCreateAutomation();
const data = { name: 'Test', trigger_type: 'manual' as const };
await hook.mutateAsync(data);
expect(mockApiPost).toHaveBeenCalledWith('/automation', data);
});
});
describe('useCreateAgent', () => {
it('calls apiPost with correct endpoint', async () => {
const { useCreateAgent } = await import('../automation');
const hook = useCreateAgent();
const data = { name: 'Test Agent', llm_model: 'gpt-4' };
await hook.mutateAsync(data);
expect(mockApiPost).toHaveBeenCalledWith('/agents', data);
});
});
describe('useExecuteAutomation', () => {
it('calls apiPost with correct endpoint', async () => {
const { useExecuteAutomation } = await import('../automation');
const hook = useExecuteAutomation();
await hook.mutateAsync('123');
expect(mockApiPost).toHaveBeenCalledWith('/automation/123/execute');
});
});
describe('useExecuteAgent', () => {
it('calls apiPost with correct endpoint', async () => {
const { useExecuteAgent } = await import('../automation');
const hook = useExecuteAgent();
await hook.mutateAsync('456');
expect(mockApiPost).toHaveBeenCalledWith('/agents/456/execute');
});
});
describe('useDeleteAutomation', () => {
it('calls apiDelete with correct endpoint', async () => {
const { useDeleteAutomation } = await import('../automation');
const hook = useDeleteAutomation();
await hook.mutateAsync('789');
expect(mockApiDelete).toHaveBeenCalledWith('/automation/789');
});
});
describe('useDeleteAgent', () => {
it('calls apiDelete with correct endpoint', async () => {
const { useDeleteAgent } = await import('../automation');
const hook = useDeleteAgent();
await hook.mutateAsync('012');
expect(mockApiDelete).toHaveBeenCalledWith('/agents/012');
});
});
describe('useSendAgentMessage', () => {
it('calls apiPost with correct endpoint and body', async () => {
const { useSendAgentMessage } = await import('../automation');
const hook = useSendAgentMessage();
await hook.mutateAsync({
id: 'agent-1',
toAgentName: 'target-agent',
message: 'Hello there',
});
expect(mockApiPost).toHaveBeenCalledWith('/agents/agent-1/send-message', {
to_agent_name: 'target-agent',
message: 'Hello there',
});
});
});
describe('useMiniApps', () => {
it('calls apiGet with correct endpoint', async () => {
const { useMiniApps } = await import('../automation');
const { useQuery } = await import('@tanstack/react-query');
(useQuery as any).mockImplementation(({ queryKey, queryFn }: any) => {
expect(queryKey).toEqual(['miniapps']);
queryFn();
return { data: [], isLoading: false };
});
useMiniApps();
expect(mockApiGet).toHaveBeenCalledWith('/automation/miniapps');
});
});
describe('useCreateMiniApp', () => {
it('calls apiPost with correct endpoint', async () => {
const { useCreateMiniApp } = await import('../automation');
const hook = useCreateMiniApp();
const data = { app_id: 'my-app', name: 'My App' };
await hook.mutateAsync(data);
expect(mockApiPost).toHaveBeenCalledWith('/automation/miniapps', data);
});
});
describe('useDeleteMiniApp', () => {
it('calls apiDelete with correct endpoint', async () => {
const { useDeleteMiniApp } = await import('../automation');
const hook = useDeleteMiniApp();
await hook.mutateAsync('my-app');
expect(mockApiDelete).toHaveBeenCalledWith('/automation/miniapps/my-app');
});
});
});