2026-03-18 20:06:25 +01:00
|
|
|
import type { SearchResult } from '../design-system/composites/CommandPalette/types'
|
|
|
|
|
import { exchanges, type Exchange } from './exchanges'
|
|
|
|
|
import { routes } from './routes'
|
|
|
|
|
import { agents } from './agents'
|
refactor: unify /apps routing with application and route filtering
- Table columns: Status, Route, Application, Started (yyyy-mm-dd hh:mm:ss),
Duration, Agent (removed Order ID and Customer)
- /apps shows all exchanges, /apps/:id filters by application,
/apps/:id/:routeId filters by application and route
- Route paths changed from /routes/:id to /apps/:appId/:routeId across
sidebar, search, breadcrumbs, metrics, and exchange detail
- Added buildRouteToAppMap utility for route→application lookup
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 12:39:45 +01:00
|
|
|
import { SIDEBAR_APPS, buildRouteToAppMap, type SidebarApp } from './sidebar'
|
2026-03-18 20:06:25 +01:00
|
|
|
|
|
|
|
|
function formatDuration(ms: number): string {
|
|
|
|
|
if (ms >= 60_000) return `${(ms / 1000).toFixed(0)}s`
|
|
|
|
|
if (ms >= 1000) return `${(ms / 1000).toFixed(2)}s`
|
|
|
|
|
return `${ms}ms`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function statusLabel(status: Exchange['status']): string {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case 'completed': return 'OK'
|
|
|
|
|
case 'failed': return 'ERR'
|
|
|
|
|
case 'running': return 'RUN'
|
|
|
|
|
case 'warning': return 'WARN'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function statusToVariant(status: Exchange['status']): string {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case 'completed': return 'success'
|
|
|
|
|
case 'failed': return 'error'
|
|
|
|
|
case 'running': return 'running'
|
|
|
|
|
case 'warning': return 'warning'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatTimestamp(date: Date): string {
|
|
|
|
|
return date.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function healthToColor(health: SidebarApp['health']): string {
|
|
|
|
|
switch (health) {
|
|
|
|
|
case 'live': return 'success'
|
|
|
|
|
case 'stale': return 'warning'
|
|
|
|
|
case 'dead': return 'error'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function buildSearchData(
|
|
|
|
|
exs: Exchange[] = exchanges,
|
|
|
|
|
rts: typeof routes = routes,
|
|
|
|
|
ags: typeof agents = agents,
|
|
|
|
|
apps: SidebarApp[] = SIDEBAR_APPS,
|
|
|
|
|
): SearchResult[] {
|
|
|
|
|
const results: SearchResult[] = []
|
|
|
|
|
|
|
|
|
|
for (const app of apps) {
|
|
|
|
|
const liveAgents = app.agents.filter((a) => a.status === 'live').length
|
|
|
|
|
results.push({
|
|
|
|
|
id: app.id,
|
|
|
|
|
category: 'application',
|
|
|
|
|
title: app.name,
|
|
|
|
|
badges: [{ label: app.health.toUpperCase(), color: healthToColor(app.health) }],
|
|
|
|
|
meta: `${app.routes.length} routes · ${app.agents.length} agents (${liveAgents} live) · ${app.exchangeCount.toLocaleString()} exchanges`,
|
|
|
|
|
path: `/apps/${app.id}`,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const exec of exs) {
|
|
|
|
|
results.push({
|
|
|
|
|
id: exec.id,
|
|
|
|
|
category: 'exchange',
|
|
|
|
|
title: `${exec.orderId} — ${exec.route}`,
|
|
|
|
|
badges: [{ label: statusLabel(exec.status), color: statusToVariant(exec.status) }],
|
|
|
|
|
meta: `${exec.correlationId} · ${formatDuration(exec.durationMs)} · ${exec.customer}`,
|
|
|
|
|
timestamp: formatTimestamp(exec.timestamp),
|
|
|
|
|
path: `/exchanges/${exec.id}`,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
refactor: unify /apps routing with application and route filtering
- Table columns: Status, Route, Application, Started (yyyy-mm-dd hh:mm:ss),
Duration, Agent (removed Order ID and Customer)
- /apps shows all exchanges, /apps/:id filters by application,
/apps/:id/:routeId filters by application and route
- Route paths changed from /routes/:id to /apps/:appId/:routeId across
sidebar, search, breadcrumbs, metrics, and exchange detail
- Added buildRouteToAppMap utility for route→application lookup
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 12:39:45 +01:00
|
|
|
const routeToApp = buildRouteToAppMap(apps)
|
2026-03-18 20:06:25 +01:00
|
|
|
for (const route of rts) {
|
refactor: unify /apps routing with application and route filtering
- Table columns: Status, Route, Application, Started (yyyy-mm-dd hh:mm:ss),
Duration, Agent (removed Order ID and Customer)
- /apps shows all exchanges, /apps/:id filters by application,
/apps/:id/:routeId filters by application and route
- Route paths changed from /routes/:id to /apps/:appId/:routeId across
sidebar, search, breadcrumbs, metrics, and exchange detail
- Added buildRouteToAppMap utility for route→application lookup
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 12:39:45 +01:00
|
|
|
const appIdForRoute = routeToApp.get(route.id)
|
2026-03-18 20:06:25 +01:00
|
|
|
results.push({
|
|
|
|
|
id: route.id,
|
|
|
|
|
category: 'route',
|
|
|
|
|
title: route.name,
|
|
|
|
|
badges: [{ label: route.group }],
|
|
|
|
|
meta: `${route.exchangeCount.toLocaleString()} exchanges · ${route.successRate}% success`,
|
refactor: unify /apps routing with application and route filtering
- Table columns: Status, Route, Application, Started (yyyy-mm-dd hh:mm:ss),
Duration, Agent (removed Order ID and Customer)
- /apps shows all exchanges, /apps/:id filters by application,
/apps/:id/:routeId filters by application and route
- Route paths changed from /routes/:id to /apps/:appId/:routeId across
sidebar, search, breadcrumbs, metrics, and exchange detail
- Added buildRouteToAppMap utility for route→application lookup
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 12:39:45 +01:00
|
|
|
path: appIdForRoute ? `/apps/${appIdForRoute}/${route.id}` : `/apps/${route.id}`,
|
2026-03-18 20:06:25 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const agent of ags) {
|
|
|
|
|
results.push({
|
|
|
|
|
id: agent.id,
|
|
|
|
|
category: 'agent',
|
|
|
|
|
title: agent.name,
|
|
|
|
|
badges: [{ label: agent.status }],
|
|
|
|
|
meta: `${agent.service} ${agent.version} · ${agent.tps} · ${agent.lastSeen}`,
|
|
|
|
|
path: `/agents/${agent.appId}/${agent.id}`,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results
|
|
|
|
|
}
|