P3C — the last data/query wave of the taxonomy migration. Every user-
facing read endpoint that was keyed on env-as-query-param is now under
the env-scoped URL, making env impossible to omit and unambiguous in
server-side tenant+env filtering.
Server:
- SearchController: /api/v1/search/** → /api/v1/environments/{envSlug}/...
Endpoints: /executions (GET), /executions/search (POST), /stats,
/stats/timeseries, /stats/timeseries/by-app, /stats/timeseries/by-route,
/stats/punchcard, /attributes/keys, /errors/top. Env comes from path.
- LogQueryController: /api/v1/logs → /api/v1/environments/{envSlug}/logs.
- RouteCatalogController: /api/v1/routes/catalog → /api/v1/environments/
{envSlug}/routes. Env filter unconditional (path).
- RouteMetricsController: /api/v1/routes/metrics →
/api/v1/environments/{envSlug}/routes/metrics (and /metrics/processors).
- DiagramRenderController: /{contentHash}/render stays flat (hashes are
globally unique). Find-by-route moved to /api/v1/environments/{envSlug}/
apps/{appSlug}/routes/{routeId}/diagram — the old GET /diagrams?...
handler is removed.
- Agent views split cleanly:
- AgentListController (new): /api/v1/environments/{envSlug}/agents
- AgentEventsController: /api/v1/environments/{envSlug}/agents/events
- AgentMetricsController: /api/v1/environments/{envSlug}/agents/
{agentId}/metrics — now also rejects cross-env agents (404) as a
defense-in-depth check, fulfilling B3.
Agent self-service endpoints (register/refresh/heartbeat/deregister)
remain flat at /api/v1/agents/** — JWT-authoritative.
SPA:
- queries/agents.ts, agent-metrics.ts, logs.ts, catalog.ts (route
metrics only; /catalog stays flat), processor-metrics.ts,
executions.ts (attributes/keys, stats, timeseries, search),
dashboard.ts (all stats/errors/punchcard), correlation.ts,
diagrams.ts (by-route) — all rewritten to env-scoped URLs.
- Hooks now either read env from useEnvironmentStore internally or
require it as an argument. Query keys include env so switching env
invalidates caches.
- useAgents/useAgentEvents signature simplified — env is no longer a
parameter; it's read from the store. Callers (LayoutShell,
AgentHealth, AgentInstance) updated accordingly.
- LogTab and useStartupLogs thread env through to useLogs.
- envFetch helper introduced in executions.ts for env-prefixed raw
fetch until schema.d.ts is regenerated against the new backend.
BREAKING CHANGE: All these flat paths are removed:
/api/v1/search/**, /api/v1/logs, /api/v1/routes/catalog,
/api/v1/routes/metrics (and /processors), /api/v1/diagrams
(lookup), /api/v1/agents (list), /api/v1/agents/events-log,
/api/v1/agents/{id}/metrics, /api/v1/agent-events.
Clients must use the /api/v1/environments/{envSlug}/... equivalents.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
114 lines
3.6 KiB
TypeScript
114 lines
3.6 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { config } from '../../config';
|
|
import { useAuthStore } from '../../auth/auth-store';
|
|
import { useRefreshInterval } from './use-refresh-interval';
|
|
|
|
export interface CatalogRoute {
|
|
routeId: string;
|
|
exchangeCount: number;
|
|
lastSeen: string | null;
|
|
fromEndpointUri: string | null;
|
|
routeState: string | null;
|
|
}
|
|
|
|
export interface CatalogAgent {
|
|
instanceId: string;
|
|
displayName: string;
|
|
state: string;
|
|
tps: number;
|
|
}
|
|
|
|
export interface DeploymentSummary {
|
|
status: string;
|
|
replicas: string;
|
|
version: number;
|
|
}
|
|
|
|
export interface CatalogApp {
|
|
slug: string;
|
|
displayName: string;
|
|
managed: boolean;
|
|
environmentSlug: string;
|
|
health: 'live' | 'stale' | 'dead' | 'offline' | 'running' | 'error';
|
|
healthTooltip: string;
|
|
agentCount: number;
|
|
routes: CatalogRoute[];
|
|
agents: CatalogAgent[];
|
|
exchangeCount: number;
|
|
deployment: DeploymentSummary | null;
|
|
}
|
|
|
|
export function useCatalog(environment?: string) {
|
|
const refetchInterval = useRefreshInterval(15_000);
|
|
return useQuery({
|
|
queryKey: ['catalog', environment],
|
|
queryFn: async () => {
|
|
const token = useAuthStore.getState().accessToken;
|
|
const params = new URLSearchParams();
|
|
if (environment) params.set('environment', environment);
|
|
const qs = params.toString();
|
|
const res = await fetch(`${config.apiBaseUrl}/catalog${qs ? `?${qs}` : ''}`, {
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'X-Cameleer-Protocol-Version': '1',
|
|
},
|
|
});
|
|
if (!res.ok) throw new Error('Failed to load catalog');
|
|
return res.json() as Promise<CatalogApp[]>;
|
|
},
|
|
placeholderData: (prev) => prev,
|
|
refetchInterval,
|
|
});
|
|
}
|
|
|
|
export function useDismissApp() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: async (applicationId: string) => {
|
|
const token = useAuthStore.getState().accessToken;
|
|
const res = await fetch(`${config.apiBaseUrl}/catalog/${applicationId}`, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'X-Cameleer-Protocol-Version': '1',
|
|
},
|
|
});
|
|
if (res.status === 409) throw new Error('Cannot dismiss — live agents are still connected');
|
|
if (!res.ok) throw new Error(`Failed to dismiss: ${res.status}`);
|
|
},
|
|
onSuccess: (_data, applicationId) => {
|
|
// Optimistically remove from cache before refetch
|
|
qc.setQueriesData<CatalogApp[]>({ queryKey: ['catalog'] }, (old) =>
|
|
old ? old.filter((a) => a.slug !== applicationId) : old
|
|
);
|
|
qc.invalidateQueries({ queryKey: ['catalog'] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useRouteMetrics(from?: string, to?: string, appId?: string, environment?: string) {
|
|
const refetchInterval = useRefreshInterval(30_000);
|
|
return useQuery({
|
|
queryKey: ['routes', 'metrics', environment, from, to, appId],
|
|
queryFn: async () => {
|
|
const token = useAuthStore.getState().accessToken;
|
|
const params = new URLSearchParams();
|
|
if (from) params.set('from', from);
|
|
if (to) params.set('to', to);
|
|
if (appId) params.set('appId', appId);
|
|
const res = await fetch(
|
|
`${config.apiBaseUrl}/environments/${encodeURIComponent(environment!)}/routes/metrics?${params}`, {
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
'X-Cameleer-Protocol-Version': '1',
|
|
},
|
|
});
|
|
if (!res.ok) throw new Error('Failed to load route metrics');
|
|
return res.json();
|
|
},
|
|
enabled: !!environment,
|
|
placeholderData: (prev: unknown) => prev,
|
|
refetchInterval,
|
|
});
|
|
}
|