feat: synchronous replay endpoint with agent response status
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 1m8s
CI / docker (push) Successful in 56s
CI / deploy-feature (push) Has been skipped
CI / deploy (push) Successful in 38s

Add dedicated POST /agents/{id}/replay endpoint that uses
addCommandWithReply to wait for the agent ACK (30s timeout).
Returns the actual replay result (status, message, data) instead
of just a delivery confirmation.

Frontend toast now reflects the agent's response: "Replay completed"
on success, agent error message on failure, timeout message if the
agent doesn't respond.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-03-30 22:48:02 +02:00
parent dd398178f0
commit 715cbc1894
6 changed files with 123 additions and 16 deletions

View File

@@ -175,6 +175,12 @@ export function useSendRouteCommand() {
// ── Replay Exchange ───────────────────────────────────────────────────────
export interface ReplayResult {
status: string
message: string
data?: string
}
export function useReplayExchange() {
return useMutation({
mutationFn: async ({
@@ -189,21 +195,18 @@ export function useReplayExchange() {
headers?: Record<string, string>
body: string
originalExchangeId?: string
}) => {
const { data, error } = await api.POST('/agents/{id}/commands', {
params: { path: { id: agentId } },
body: {
type: 'replay',
payload: {
routeId,
exchange: { body, headers: headers ?? {} },
originalExchangeId,
nonce: crypto.randomUUID(),
},
} as any,
}): Promise<ReplayResult> => {
const res = await authFetch(`/api/v1/agents/${encodeURIComponent(agentId)}/replay`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ routeId, body, headers: headers ?? {}, originalExchangeId }),
})
if (error) throw new Error('Failed to send replay command')
return data!
if (!res.ok) {
if (res.status === 404) throw new Error('Agent not found')
if (res.status === 504) throw new Error('Replay timed out — agent did not respond')
throw new Error('Failed to send replay command')
}
return res.json() as Promise<ReplayResult>
},
})
}

View File

@@ -57,8 +57,12 @@ export function RouteControlBar({ application, routeId, hasRouteControl, hasRepl
replayExchange.mutate(
{ agentId, routeId, headers, body: inputBody ?? '', originalExchangeId: exchangeId },
{
onSuccess: () => {
toast({ title: 'Replay sent', description: `${routeId} on ${agentId}`, variant: 'success' });
onSuccess: (result) => {
if (result.status === 'SUCCESS') {
toast({ title: 'Replay completed', description: result.message ?? `${routeId} on ${agentId}`, variant: 'success' });
} else {
toast({ title: 'Replay failed', description: result.message ?? 'Agent reported failure', variant: 'error' });
}
setSendingAction(null);
},
onError: (err) => {