fix: commands respect selected environment
Backend: AgentRegistryService gains findByApplicationAndEnvironment() and environment-aware addGroupCommandWithReplies() overload. AgentCommandController and ApplicationConfigController accept optional environment query parameter. When set, commands only target agents in that environment. Backward compatible — null means all environments. Frontend: All command mutations (config update, route control, traced processors, tap config, route recording) now pass selectedEnv to the backend via query parameter. Prevents cross-environment command leakage — e.g., updating config for prod no longer pushes to dev agents. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -73,8 +73,9 @@ export interface ConfigUpdateResponse {
|
||||
export function useUpdateApplicationConfig() {
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: async (config: ApplicationConfig) => {
|
||||
const res = await authFetch(`/config/${config.application}`, {
|
||||
mutationFn: async ({ config, environment }: { config: ApplicationConfig; environment?: string }) => {
|
||||
const envParam = environment ? `?environment=${encodeURIComponent(environment)}` : ''
|
||||
const res = await authFetch(`/config/${config.application}${envParam}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(config),
|
||||
@@ -119,12 +120,14 @@ interface SendGroupCommandParams {
|
||||
group: string
|
||||
type: string
|
||||
payload: Record<string, unknown>
|
||||
environment?: string
|
||||
}
|
||||
|
||||
export function useSendGroupCommand() {
|
||||
return useMutation({
|
||||
mutationFn: async ({ group, type, payload }: SendGroupCommandParams) => {
|
||||
const res = await authFetch(`/agents/groups/${encodeURIComponent(group)}/commands`, {
|
||||
mutationFn: async ({ group, type, payload, environment }: SendGroupCommandParams) => {
|
||||
const envParam = environment ? `?environment=${encodeURIComponent(environment)}` : ''
|
||||
const res = await authFetch(`/agents/groups/${encodeURIComponent(group)}/commands${envParam}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ type, payload }),
|
||||
@@ -174,12 +177,14 @@ export function useTestExpression() {
|
||||
|
||||
export function useSendRouteCommand() {
|
||||
return useMutation({
|
||||
mutationFn: async ({ application, action, routeId }: {
|
||||
mutationFn: async ({ application, action, routeId, environment }: {
|
||||
application: string
|
||||
action: 'start' | 'stop' | 'suspend' | 'resume'
|
||||
routeId: string
|
||||
environment?: string
|
||||
}) => {
|
||||
const res = await authFetch(`/agents/groups/${encodeURIComponent(application)}/commands`, {
|
||||
const envParam = environment ? `?environment=${encodeURIComponent(environment)}` : ''
|
||||
const res = await authFetch(`/agents/groups/${encodeURIComponent(application)}/commands${envParam}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ type: 'route-control', payload: { routeId, action, nonce: crypto.randomUUID() } }),
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
import type { Column } from '@cameleer/design-system';
|
||||
import { useApplicationConfig, useUpdateApplicationConfig } from '../../api/queries/commands';
|
||||
import type { ApplicationConfig, TapDefinition, ConfigUpdateResponse } from '../../api/queries/commands';
|
||||
import { useEnvironmentStore } from '../../api/environment-store';
|
||||
import { useCatalog } from '../../api/queries/catalog';
|
||||
import type { CatalogApp, CatalogRoute } from '../../api/queries/catalog';
|
||||
import { applyTracedProcessorUpdate, applyRouteRecordingUpdate } from '../../utils/config-draft-utils';
|
||||
@@ -75,6 +76,7 @@ export default function AppConfigDetailPage() {
|
||||
const { appId } = useParams<{ appId: string }>();
|
||||
const navigate = useNavigate();
|
||||
const { toast } = useToast();
|
||||
const selectedEnv = useEnvironmentStore((s) => s.environment);
|
||||
const { data: config, isLoading } = useApplicationConfig(appId);
|
||||
const updateConfig = useUpdateApplicationConfig();
|
||||
const { data: catalog } = useCatalog();
|
||||
@@ -147,7 +149,7 @@ export default function AppConfigDetailPage() {
|
||||
tracedProcessors: tracedDraft,
|
||||
routeRecording: routeRecordingDraft,
|
||||
} as ApplicationConfig;
|
||||
updateConfig.mutate(updated, {
|
||||
updateConfig.mutate({ config: updated, environment: selectedEnv }, {
|
||||
onSuccess: (saved: ConfigUpdateResponse) => {
|
||||
setEditing(false);
|
||||
if (saved.pushResult.success) {
|
||||
|
||||
@@ -115,7 +115,7 @@ export default function AgentHealth() {
|
||||
const saveConfigEdit = useCallback(() => {
|
||||
if (!appConfig) return;
|
||||
const updated = { ...appConfig, ...configDraft };
|
||||
updateConfig.mutate(updated, {
|
||||
updateConfig.mutate({ config: updated, environment: selectedEnv }, {
|
||||
onSuccess: (saved: ConfigUpdateResponse) => {
|
||||
setConfigEditing(false);
|
||||
setConfigDraft({});
|
||||
|
||||
@@ -238,19 +238,22 @@ function CreateAppView({ environments, selectedEnv }: { environments: Environmen
|
||||
// 4. Save agent config (will be pushed to agent on first connect)
|
||||
setStep('Saving monitoring config...');
|
||||
await updateAgentConfig.mutateAsync({
|
||||
application: slug.trim(),
|
||||
version: 0,
|
||||
engineLevel,
|
||||
payloadCaptureMode: payloadCapture,
|
||||
applicationLogLevel: appLogLevel,
|
||||
agentLogLevel,
|
||||
metricsEnabled,
|
||||
samplingRate: parseFloat(samplingRate) || 1.0,
|
||||
compressSuccess,
|
||||
tracedProcessors: {},
|
||||
taps: [],
|
||||
tapVersion: 0,
|
||||
routeRecording: {},
|
||||
config: {
|
||||
application: slug.trim(),
|
||||
version: 0,
|
||||
engineLevel,
|
||||
payloadCaptureMode: payloadCapture,
|
||||
applicationLogLevel: appLogLevel,
|
||||
agentLogLevel,
|
||||
metricsEnabled,
|
||||
samplingRate: parseFloat(samplingRate) || 1.0,
|
||||
compressSuccess,
|
||||
tracedProcessors: {},
|
||||
taps: [],
|
||||
tapVersion: 0,
|
||||
routeRecording: {},
|
||||
},
|
||||
environment: selectedEnv,
|
||||
});
|
||||
|
||||
// 5. Deploy (if requested)
|
||||
@@ -814,13 +817,16 @@ function ConfigSubTab({ app, environment }: { app: App; environment?: Environmen
|
||||
if (agentConfig) {
|
||||
try {
|
||||
await updateAgentConfig.mutateAsync({
|
||||
...agentConfig,
|
||||
engineLevel, payloadCaptureMode: payloadCapture,
|
||||
applicationLogLevel: appLogLevel, agentLogLevel,
|
||||
metricsEnabled, samplingRate: parseFloat(samplingRate) || 1.0,
|
||||
compressSuccess,
|
||||
tracedProcessors: tracedDraft,
|
||||
routeRecording: routeRecordingDraft,
|
||||
config: {
|
||||
...agentConfig,
|
||||
engineLevel, payloadCaptureMode: payloadCapture,
|
||||
applicationLogLevel: appLogLevel, agentLogLevel,
|
||||
metricsEnabled, samplingRate: parseFloat(samplingRate) || 1.0,
|
||||
compressSuccess,
|
||||
tracedProcessors: tracedDraft,
|
||||
routeRecording: routeRecordingDraft,
|
||||
},
|
||||
environment: environment?.slug,
|
||||
});
|
||||
} catch { toast({ title: 'Failed to save agent config', variant: 'error', duration: 86_400_000 }); return; }
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useCatalog } from '../../api/queries/catalog';
|
||||
import { useAgents } from '../../api/queries/agents';
|
||||
import { useApplicationConfig, useUpdateApplicationConfig } from '../../api/queries/commands';
|
||||
import type { TapDefinition, ConfigUpdateResponse } from '../../api/queries/commands';
|
||||
import { useEnvironmentStore } from '../../api/environment-store';
|
||||
import { useCanControl } from '../../auth/auth-store';
|
||||
import { useTracingStore } from '../../stores/tracing-store';
|
||||
import type { NodeAction, NodeConfig } from '../../components/ProcessDiagram/types';
|
||||
@@ -23,6 +24,7 @@ import type { SelectedExchange } from '../Dashboard/Dashboard';
|
||||
export default function ExchangesPage() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const selectedEnv = useEnvironmentStore((s) => s.environment);
|
||||
const { appId: scopedAppId, routeId: scopedRouteId, exchangeId: scopedExchangeId } =
|
||||
useParams<{ appId?: string; routeId?: string; exchangeId?: string }>();
|
||||
|
||||
@@ -143,6 +145,7 @@ interface DiagramPanelProps {
|
||||
}
|
||||
|
||||
function DiagramPanel({ appId, routeId, exchangeId, onCorrelatedSelect, onClearSelection }: DiagramPanelProps) {
|
||||
const selectedEnv = useEnvironmentStore((s) => s.environment);
|
||||
const { timeRange } = useGlobalFilters();
|
||||
const timeFrom = timeRange.start.toISOString();
|
||||
const timeTo = timeRange.end.toISOString();
|
||||
@@ -240,7 +243,7 @@ function DiagramPanel({ appId, routeId, exchangeId, onCorrelatedSelect, onClearS
|
||||
|
||||
const handleTapSave = useCallback((updatedConfig: typeof appConfig) => {
|
||||
if (!updatedConfig) return;
|
||||
updateConfig.mutate(updatedConfig, {
|
||||
updateConfig.mutate({ config: updatedConfig, environment: selectedEnv }, {
|
||||
onSuccess: (saved: ConfigUpdateResponse) => {
|
||||
if (saved.pushResult.success) {
|
||||
toast({ title: 'Tap configuration saved', description: `Pushed to ${saved.pushResult.total}/${saved.pushResult.total} agents (v${saved.config.version})`, variant: 'success' });
|
||||
@@ -258,7 +261,7 @@ function DiagramPanel({ appId, routeId, exchangeId, onCorrelatedSelect, onClearS
|
||||
const handleTapDelete = useCallback((tap: TapDefinition) => {
|
||||
if (!appConfig) return;
|
||||
const taps = appConfig.taps.filter(t => t.tapId !== tap.tapId);
|
||||
updateConfig.mutate({ ...appConfig, taps }, {
|
||||
updateConfig.mutate({ config: { ...appConfig, taps }, environment: selectedEnv }, {
|
||||
onSuccess: (saved: ConfigUpdateResponse) => {
|
||||
if (saved.pushResult.success) {
|
||||
toast({ title: 'Tap deleted', description: `${tap.attributeName} removed — pushed to ${saved.pushResult.total}/${saved.pushResult.total} agents (v${saved.config.version})`, variant: 'success' });
|
||||
@@ -287,10 +290,10 @@ function DiagramPanel({ appId, routeId, exchangeId, onCorrelatedSelect, onClearS
|
||||
const enabled = nodeId in newMap;
|
||||
const tracedProcessors: Record<string, string> = {};
|
||||
for (const [k, v] of Object.entries(newMap)) tracedProcessors[k] = v;
|
||||
updateConfig.mutate({
|
||||
updateConfig.mutate({ config: {
|
||||
...appConfig,
|
||||
tracedProcessors,
|
||||
}, {
|
||||
}, environment: selectedEnv }, {
|
||||
onSuccess: (saved: ConfigUpdateResponse) => {
|
||||
if (saved.pushResult.success) {
|
||||
toast({ title: `Tracing ${enabled ? 'enabled' : 'disabled'}`, description: `${nodeId} — pushed to ${saved.pushResult.total}/${saved.pushResult.total} agents (v${saved.config.version})`, variant: 'success' });
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Play, Square, Pause, PlayCircle, RotateCcw, Loader2 } from 'lucide-reac
|
||||
import { useToast, ConfirmDialog } from '@cameleer/design-system';
|
||||
import { useSendRouteCommand, useReplayExchange } from '../../api/queries/commands';
|
||||
import type { CommandGroupResponse } from '../../api/queries/commands';
|
||||
import { useEnvironmentStore } from '../../api/environment-store';
|
||||
import styles from './RouteControlBar.module.css';
|
||||
|
||||
interface RouteControlBarProps {
|
||||
@@ -34,6 +35,7 @@ const ACTION_DISABLED: Record<string, Set<RouteAction>> = {
|
||||
|
||||
export function RouteControlBar({ application, routeId, routeState, hasRouteControl, hasReplay, agentId, exchangeId, inputHeaders, inputBody }: RouteControlBarProps) {
|
||||
const { toast } = useToast();
|
||||
const selectedEnv = useEnvironmentStore((s) => s.environment);
|
||||
const sendRouteCommand = useSendRouteCommand();
|
||||
const replayExchange = useReplayExchange();
|
||||
const [sendingAction, setSendingAction] = useState<string | null>(null);
|
||||
@@ -54,7 +56,7 @@ export function RouteControlBar({ application, routeId, routeState, hasRouteCont
|
||||
function handleRouteAction(action: RouteAction) {
|
||||
setSendingAction(action);
|
||||
sendRouteCommand.mutate(
|
||||
{ application, action, routeId },
|
||||
{ application, action, routeId, environment: selectedEnv },
|
||||
{
|
||||
onSuccess: (result: CommandGroupResponse) => {
|
||||
if (result.success) {
|
||||
|
||||
@@ -344,7 +344,7 @@ export default function RouteDetail() {
|
||||
function toggleRecording() {
|
||||
if (!config.data) return;
|
||||
const routeRecording = { ...config.data.routeRecording, [routeId!]: !isRecording };
|
||||
updateConfig.mutate({ ...config.data, routeRecording });
|
||||
updateConfig.mutate({ config: { ...config.data, routeRecording }, environment: selectedEnv });
|
||||
}
|
||||
|
||||
// ── Derived data ───────────────────────────────────────────────────────────
|
||||
@@ -545,14 +545,14 @@ export default function RouteDetail() {
|
||||
const taps = editingTap
|
||||
? config.data.taps.map(t => t.tapId === editingTap.tapId ? tap : t)
|
||||
: [...(config.data.taps || []), tap];
|
||||
updateConfig.mutate({ ...config.data, taps });
|
||||
updateConfig.mutate({ config: { ...config.data, taps }, environment: selectedEnv });
|
||||
setTapModalOpen(false);
|
||||
}
|
||||
|
||||
function deleteTap(tap: TapDefinition) {
|
||||
if (!config.data) return;
|
||||
const taps = config.data.taps.filter(t => t.tapId !== tap.tapId);
|
||||
updateConfig.mutate({ ...config.data, taps });
|
||||
updateConfig.mutate({ config: { ...config.data, taps }, environment: selectedEnv });
|
||||
setDeletingTap(null);
|
||||
}
|
||||
|
||||
@@ -561,7 +561,7 @@ export default function RouteDetail() {
|
||||
const taps = config.data.taps.map(t =>
|
||||
t.tapId === tap.tapId ? { ...t, enabled: !t.enabled } : t,
|
||||
);
|
||||
updateConfig.mutate({ ...config.data, taps });
|
||||
updateConfig.mutate({ config: { ...config.data, taps }, environment: selectedEnv });
|
||||
}
|
||||
|
||||
function runTestExpression() {
|
||||
|
||||
Reference in New Issue
Block a user