Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"test": "node --test tests/*.test.js",
"preview": "vite preview"
},
"dependencies": {
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/api/agents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { api } from './client'
import { api } from './client.js'

function qs(params = {}) {
const filtered = Object.entries(params).filter(([, value]) => value !== undefined && value !== null && value !== '')
Expand All @@ -7,11 +7,12 @@ function qs(params = {}) {
}

export const agents = {
list: () => api.get('/registry/agents/'),
list: (params = {}) => api.get(`/registry/agents/${qs(params)}`),
create: (data) => api.post('/registry/agents/', data),
get: (id) => api.get(`/registry/agents/${id}/`),
blueprints: () => api.get('/registry/blueprints/'),
pendingActions: (params = {}) => api.get(`/intelligence/pending-actions/${qs(params)}`).then(d => Array.isArray(d) ? { results: d, count: d.length } : d),
pendingAction: (id) => api.get(`/intelligence/pending-actions/${id}/`),
approve: (id, data) => api.post(`/intelligence/pending-actions/${id}/approve/`, data || { decision: 'APPROVED' }),
reject: (id, data) => api.post(`/intelligence/pending-actions/${id}/approve/`, data || { decision: 'DENIED' }),
escalations: () => api.get('/intelligence/escalations/'),
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const DEFAULT_API_URL = "https://aos-api.viewdns.net/api";
const BASE = (import.meta.env.VITE_API_URL || DEFAULT_API_URL).replace(
const BASE = (import.meta.env?.VITE_API_URL || DEFAULT_API_URL).replace(
/\/+$/,
"",
);
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/api/ops.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { api } from './client'
import { api } from './client.js'

function qs(params = {}) {
const filtered = Object.entries(params).filter(([, value]) => value !== undefined && value !== null && value !== '')
Expand All @@ -10,7 +10,7 @@ export const ops = {
overview: (params = {}) => {
return api.get(`/ops/overview/${qs(params)}`)
},
connectors: () => api.get('/ops/connectors/'),
connectors: (params = {}) => api.get(`/ops/connectors/${qs(params)}`),
accounts: {
list: (params = {}) => api.get(`/ops/accounts/${qs(params)}`),
create: (data) => api.post('/ops/accounts/', data),
Expand Down Expand Up @@ -39,6 +39,6 @@ export const ops = {
queue: {
list: (params = {}) => api.get(`/ops/queue/${qs(params)}`),
process: (limit = 25, params = {}) => api.post('/ops/queue/process/', { limit, ...params }),
retry: (id) => api.post(`/ops/queue/${id}/retry/`),
retry: (id, params = {}) => api.post(`/ops/queue/${id}/retry/`, params),
},
}
10 changes: 9 additions & 1 deletion frontend/src/api/projects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { api } from './client'
import { api } from './client.js'

function qs(params = {}) {
const filtered = Object.entries(params).filter(([, value]) => value !== undefined && value !== null && value !== '')
Expand All @@ -14,6 +14,14 @@ export const projects = {
update: (id, data) => api.patch(`/projects/projects/${id}/`, data),
delete: (id) => api.delete(`/projects/projects/${id}/`),
archive: (id) => api.post(`/projects/projects/${id}/archive/`, {}),
pauseAutomation: (id) => api.patch(`/projects/projects/${id}/`, { status: 'PAUSED' }),
resumeAutomation: (id) => api.patch(`/projects/projects/${id}/`, { status: 'ACTIVE' }),
intervene: (id, data) => api.post(`/projects/projects/${id}/activity/`, {
kind: 'operator.intervention',
summary: data.action,
body: data.reason,
metadata: { action: data.action, source: 'command-center' },
}),
addMember: (id, data) => api.post(`/projects/projects/${id}/add_member/`, data),
activity: (id, data) => api.post(`/projects/projects/${id}/activity/`, data),
goals: {
Expand Down
81 changes: 81 additions & 0 deletions frontend/src/hooks/useProjectControls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { useCallback, useState } from 'react'
import { agents } from '../api/agents'
import { ops } from '../api/ops'
import { projects } from '../api/projects'
import { swarm } from '../api/swarm'

export function useProjectControls(projectId, onRefresh) {
const [busy, setBusy] = useState('')
const [error, setError] = useState('')
const [message, setMessage] = useState('')

const execute = useCallback(async (key, operation, successMessage) => {
setBusy(key)
setError('')
setMessage('')
try {
const result = await operation()
setMessage(successMessage)
await onRefresh?.()
return { ok: true, data: result }
} catch (err) {
setError(err?.data?.detail || err?.data?.error || err.message || 'The control action failed')
return { ok: false, error: err }
} finally {
setBusy('')
}
}, [onRefresh])

const setAutomationPaused = useCallback((paused) => execute(
'automation',
() => paused ? projects.pauseAutomation(projectId) : projects.resumeAutomation(projectId),
paused ? 'Project automation paused safely.' : 'Project automation resumed.',
), [execute, projectId])

const intervene = useCallback((payload, context = {}) => execute(
'intervention',
async () => {
if (payload.action === 'STOP_CURRENT_RUNS') {
const running = (context.runs || []).filter((run) => String(run.status).toLowerCase() === 'running')
await Promise.all(running.map((run) => swarm.cancelRun(run.id)))
} else if (payload.action === 'RECOVER_FAILED_QUEUE') {
await Promise.all((context.failedQueue || []).map((item) => ops.queue.retry(item.id)))
} else if (payload.action === 'ESCALATE_TO_OPERATOR') {
await projects.pauseAutomation(projectId)
}
return projects.intervene(projectId, payload)
},
'Manual intervention completed and recorded in project activity.',
), [execute, projectId])

const decideApproval = useCallback((actionId, decision) => execute(
`approval-${actionId}`,
() => decision === 'APPROVED'
? agents.approve(actionId, { decision })
: agents.reject(actionId, { decision }),
`Action ${decision === 'APPROVED' ? 'approved' : 'rejected'}.`,
), [execute])

const retryQueueItem = useCallback((itemId) => execute(
`queue-${itemId}`,
() => ops.queue.retry(itemId),
'Queue item scheduled for retry.',
), [execute])

const recoverQueue = useCallback((items) => execute(
'recovery',
() => Promise.all(items.map((item) => ops.queue.retry(item.id))),
`${items.length} failed queue item${items.length === 1 ? '' : 's'} scheduled for retry.`,
), [execute])

return {
busy,
error,
message,
setAutomationPaused,
intervene,
decideApproval,
retryQueueItem,
recoverQueue,
}
}
11 changes: 7 additions & 4 deletions frontend/src/pages/app/AppShell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ export default function AppShell() {
const params = new URLSearchParams(location.search)
const prompt = params.get('prompt')
if (prompt && location.pathname === '/app/swarm') {
setSwarmInitialGoal(decodeURIComponent(prompt))
setSwarmProjectId(params.get('project_id') || '')
setSwarmOpen(true)
navigate('/app', { replace: true })
const timer = window.setTimeout(() => {
setSwarmInitialGoal(decodeURIComponent(prompt))
setSwarmProjectId(params.get('project_id') || '')
setSwarmOpen(true)
navigate('/app', { replace: true })
}, 0)
return () => window.clearTimeout(timer)
}
}, [location.search, location.pathname, navigate])

Expand Down
Loading
Loading