feat: synchronous replay endpoint with agent response status
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:
@@ -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>
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user