+48
-10
@@ -11,6 +11,7 @@
|
||||
* id: string,
|
||||
* label: string,
|
||||
* description: string,
|
||||
* activity?: string,
|
||||
* match?: (q: string) => boolean,
|
||||
* run: (tools: { run: (name: string, args?: object) => Promise<any> }) => Promise<any>,
|
||||
* summarize: (result: any) => string,
|
||||
@@ -22,7 +23,8 @@ export const AGENT_SPECS = [
|
||||
{
|
||||
id: 'host',
|
||||
label: 'Host investigator',
|
||||
description: 'KPIs, findings, health, top processes pack',
|
||||
description: 'KPIs, findings, health pack',
|
||||
activity: 'Calling investigate_host…',
|
||||
match: (q) =>
|
||||
!q ||
|
||||
/health|wrong|diagnos|investigat|summar|status|load|cpu|ram|memory|host|alert|anomal/.test(
|
||||
@@ -42,7 +44,8 @@ export const AGENT_SPECS = [
|
||||
{
|
||||
id: 'hot',
|
||||
label: 'Hot metrics',
|
||||
description: 'Charts with strongest recent change',
|
||||
description: 'Spiking / changing charts',
|
||||
activity: 'Scanning hot_metrics window…',
|
||||
match: (q) =>
|
||||
!q ||
|
||||
/hot|spik|unusual|metric|chart|cpu|disk|io|net|redis|docker|postgres|nginx/.test(q),
|
||||
@@ -58,7 +61,8 @@ export const AGENT_SPECS = [
|
||||
{
|
||||
id: 'processes',
|
||||
label: 'Process scout',
|
||||
description: 'Top CPU processes',
|
||||
description: 'Top CPU / RSS processes',
|
||||
activity: 'Listing top processes by CPU…',
|
||||
match: (q) =>
|
||||
!q || /process|top|cpu|load|rss|memory|pid|runaway|hung/.test(q),
|
||||
run: (tools) => tools.run('list_processes', { sort: 'cpu', limit: 12, filter: 'all' }),
|
||||
@@ -74,7 +78,8 @@ export const AGENT_SPECS = [
|
||||
{
|
||||
id: 'anomalies',
|
||||
label: 'Anomaly / alerts',
|
||||
description: 'Recent anomalies and open alerts',
|
||||
description: 'Anomalies + open alerts',
|
||||
activity: 'Fetching anomalies & alerts…',
|
||||
match: (q) =>
|
||||
!q || /anomal|alert|warn|crit|threshold|silence|page/.test(q),
|
||||
run: async (tools) => {
|
||||
@@ -99,7 +104,8 @@ export const AGENT_SPECS = [
|
||||
{
|
||||
id: 'fleet',
|
||||
label: 'Fleet scout',
|
||||
description: 'Parent/child fleet health',
|
||||
description: 'Parent / child fleet health',
|
||||
activity: 'Querying fleet_health…',
|
||||
match: (q) => /fleet|child|peer|parent|cluster|all hosts/.test(q),
|
||||
run: async (tools) => {
|
||||
const [health, children] = await Promise.all([
|
||||
@@ -117,7 +123,8 @@ export const AGENT_SPECS = [
|
||||
{
|
||||
id: 'storage',
|
||||
label: 'Storage / retention',
|
||||
description: 'Agent disk and retention config',
|
||||
description: 'Disk usage & retention config',
|
||||
activity: 'Reading storage_info…',
|
||||
match: (q) => /storage|retention|prune|disk|warm|history|size|hyperdb/.test(q),
|
||||
run: (tools) => tools.run('storage_info', {}),
|
||||
summarize: (r) => {
|
||||
@@ -228,10 +235,13 @@ export function pickAgents(userText, maxAgents = 3) {
|
||||
* query: string,
|
||||
* maxAgents?: number,
|
||||
* isAborted?: () => boolean,
|
||||
* onPlan?: (agents: AgentSpec[]) => void,
|
||||
* onAgent?: (ev: {
|
||||
* id: string,
|
||||
* label: string,
|
||||
* status: 'start'|'done'|'error',
|
||||
* description?: string,
|
||||
* status: 'queued'|'start'|'running'|'done'|'error'|'stopped',
|
||||
* activity?: string,
|
||||
* summary?: string,
|
||||
* error?: string,
|
||||
* }) => void,
|
||||
@@ -242,6 +252,8 @@ export async function runSubAgents(opts) {
|
||||
const tools = opts.tools
|
||||
const aborted = () => Boolean(opts.isAborted?.())
|
||||
|
||||
opts.onPlan?.(specs)
|
||||
|
||||
/** @type {Array<{ id: string, label: string, status: string, summary: string, result?: any, error?: string }>} */
|
||||
const agents = []
|
||||
|
||||
@@ -251,23 +263,45 @@ export async function runSubAgents(opts) {
|
||||
agents.push({
|
||||
id: spec.id,
|
||||
label: spec.label,
|
||||
status: 'error',
|
||||
status: 'stopped',
|
||||
summary: 'stopped',
|
||||
error: 'stopped',
|
||||
})
|
||||
opts.onAgent?.({
|
||||
id: spec.id,
|
||||
label: spec.label,
|
||||
description: spec.description,
|
||||
status: 'stopped',
|
||||
activity: 'Stopped',
|
||||
error: 'stopped',
|
||||
})
|
||||
return
|
||||
}
|
||||
opts.onAgent?.({ id: spec.id, label: spec.label, status: 'start' })
|
||||
opts.onAgent?.({
|
||||
id: spec.id,
|
||||
label: spec.label,
|
||||
description: spec.description,
|
||||
status: 'start',
|
||||
activity: spec.activity || `Running ${spec.label}…`,
|
||||
})
|
||||
try {
|
||||
const result = await spec.run(tools)
|
||||
if (aborted()) {
|
||||
agents.push({
|
||||
id: spec.id,
|
||||
label: spec.label,
|
||||
status: 'error',
|
||||
status: 'stopped',
|
||||
summary: 'stopped',
|
||||
error: 'stopped',
|
||||
})
|
||||
opts.onAgent?.({
|
||||
id: spec.id,
|
||||
label: spec.label,
|
||||
description: spec.description,
|
||||
status: 'stopped',
|
||||
activity: 'Stopped',
|
||||
error: 'stopped',
|
||||
})
|
||||
return
|
||||
}
|
||||
const summary = spec.summarize(result)
|
||||
@@ -283,7 +317,9 @@ export async function runSubAgents(opts) {
|
||||
opts.onAgent?.({
|
||||
id: spec.id,
|
||||
label: spec.label,
|
||||
description: spec.description,
|
||||
status: row.status === 'error' ? 'error' : 'done',
|
||||
activity: row.status === 'error' ? 'Failed' : 'Complete',
|
||||
summary,
|
||||
error: row.error,
|
||||
})
|
||||
@@ -299,7 +335,9 @@ export async function runSubAgents(opts) {
|
||||
opts.onAgent?.({
|
||||
id: spec.id,
|
||||
label: spec.label,
|
||||
description: spec.description,
|
||||
status: 'error',
|
||||
activity: 'Failed',
|
||||
error: msg,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user