fix(ui/agents): rewrite cloud-agents API client to /v2/ namespace

The existing /v1/agents endpoint is reserved for the A2A registry. The new
VM-agent API used by this dashboard moves under /v2/.
This commit is contained in:
Ishaan Jaffer 2026-05-06 15:02:12 -07:00
parent d2601ee875
commit 214ff1a2a4
No known key found for this signature in database

View file

@ -5,8 +5,10 @@
* origin. When `NEXT_PUBLIC_USE_MOCK_AGENTS=true`, every method short-circuits
* to `mock-agents.ts` so the dashboard can develop without Epic A merged.
*
* When Epic A lands and exposes `/v1/agents`, `/v1/sessions`, etc., flip the
* env var off and the real fetches kick in. No component changes required.
* Backend namespace is `/v2/` `/v1/agents` is reserved for the existing A2A
* registry. When Epic A lands and exposes `/v2/agents`, `/v2/sessions`, etc.,
* flip the env var off and the real fetches kick in. No component changes
* required.
*/
import { getProxyBaseUrl } from "@/components/networking";
import {
@ -21,12 +23,7 @@ import {
mockListSessions,
mockSendFollowup,
} from "@/lib/mock-agents";
import type {
CloudAgent,
CloudAgentConversationMessage,
CloudAgentRun,
CloudAgentSession,
} from "@/types/cloud-agents";
import type { CloudAgent, CloudAgentConversationMessage, CloudAgentRun, CloudAgentSession } from "@/types/cloud-agents";
function authHeaders(accessToken: string | null): HeadersInit {
const headers: HeadersInit = { "Content-Type": "application/json" };
@ -48,17 +45,14 @@ async function jsonOrThrow<T>(res: Response, label: string): Promise<T> {
export async function listCloudAgents(accessToken: string | null): Promise<CloudAgent[]> {
if (isMockEnabled()) return mockListAgents();
const res = await fetch(`${getProxyBaseUrl()}/v1/agents`, { headers: authHeaders(accessToken) });
const res = await fetch(`${getProxyBaseUrl()}/v2/agents`, { headers: authHeaders(accessToken) });
const body = await jsonOrThrow<{ agents: CloudAgent[] }>(res, "listCloudAgents");
return body.agents;
}
export async function getCloudAgent(
accessToken: string | null,
agentId: string,
): Promise<CloudAgent | null> {
export async function getCloudAgent(accessToken: string | null, agentId: string): Promise<CloudAgent | null> {
if (isMockEnabled()) return mockGetAgent(agentId);
const res = await fetch(`${getProxyBaseUrl()}/v1/agents/${agentId}`, {
const res = await fetch(`${getProxyBaseUrl()}/v2/agents/${agentId}`, {
headers: authHeaders(accessToken),
});
if (res.status === 404) return null;
@ -70,7 +64,7 @@ export async function createCloudAgent(
input: { name: string; model: string; system_prompt?: string },
): Promise<CloudAgent> {
if (isMockEnabled()) return mockCreateAgent(input);
const res = await fetch(`${getProxyBaseUrl()}/v1/agents`, {
const res = await fetch(`${getProxyBaseUrl()}/v2/agents`, {
method: "POST",
headers: authHeaders(accessToken),
body: JSON.stringify(input),
@ -80,12 +74,9 @@ export async function createCloudAgent(
/* ---------- sessions ---------- */
export async function listCloudSessions(
accessToken: string | null,
agentId: string,
): Promise<CloudAgentSession[]> {
export async function listCloudSessions(accessToken: string | null, agentId: string): Promise<CloudAgentSession[]> {
if (isMockEnabled()) return mockListSessions(agentId);
const res = await fetch(`${getProxyBaseUrl()}/v1/sessions?agent_id=${encodeURIComponent(agentId)}`, {
const res = await fetch(`${getProxyBaseUrl()}/v2/sessions?agent_id=${encodeURIComponent(agentId)}`, {
headers: authHeaders(accessToken),
});
const body = await jsonOrThrow<{ sessions: CloudAgentSession[] }>(res, "listCloudSessions");
@ -97,7 +88,7 @@ export async function getCloudSession(
sessionId: string,
): Promise<CloudAgentSession | null> {
if (isMockEnabled()) return mockGetSession(sessionId);
const res = await fetch(`${getProxyBaseUrl()}/v1/sessions/${sessionId}`, {
const res = await fetch(`${getProxyBaseUrl()}/v2/sessions/${sessionId}`, {
headers: authHeaders(accessToken),
});
if (res.status === 404) return null;
@ -109,7 +100,7 @@ export async function createCloudSession(
input: { agent_id: string; repo_url: string },
): Promise<CloudAgentSession> {
if (isMockEnabled()) return mockCreateSession(input);
const res = await fetch(`${getProxyBaseUrl()}/v1/sessions`, {
const res = await fetch(`${getProxyBaseUrl()}/v2/sessions`, {
method: "POST",
headers: authHeaders(accessToken),
body: JSON.stringify(input),
@ -122,13 +113,10 @@ export async function getSessionConversation(
sessionId: string,
): Promise<CloudAgentConversationMessage[]> {
if (isMockEnabled()) return mockGetConversation(sessionId);
const res = await fetch(`${getProxyBaseUrl()}/v1/sessions/${sessionId}/conversation`, {
const res = await fetch(`${getProxyBaseUrl()}/v2/sessions/${sessionId}/conversation`, {
headers: authHeaders(accessToken),
});
const body = await jsonOrThrow<{ messages: CloudAgentConversationMessage[] }>(
res,
"getSessionConversation",
);
const body = await jsonOrThrow<{ messages: CloudAgentConversationMessage[] }>(res, "getSessionConversation");
return body.messages;
}
@ -138,7 +126,7 @@ export async function sendSessionFollowup(
content: string,
): Promise<CloudAgentConversationMessage> {
if (isMockEnabled()) return mockSendFollowup(sessionId, content);
const res = await fetch(`${getProxyBaseUrl()}/v1/sessions/${sessionId}/followup`, {
const res = await fetch(`${getProxyBaseUrl()}/v2/sessions/${sessionId}/followup`, {
method: "POST",
headers: authHeaders(accessToken),
body: JSON.stringify({ content }),
@ -148,12 +136,9 @@ export async function sendSessionFollowup(
/* ---------- runs ---------- */
export async function getCloudRun(
accessToken: string | null,
runId: string,
): Promise<CloudAgentRun | null> {
export async function getCloudRun(accessToken: string | null, runId: string): Promise<CloudAgentRun | null> {
if (isMockEnabled()) return mockGetRun(runId);
const res = await fetch(`${getProxyBaseUrl()}/v1/runs/${runId}`, {
const res = await fetch(`${getProxyBaseUrl()}/v2/runs/${runId}`, {
headers: authHeaders(accessToken),
});
if (res.status === 404) return null;
@ -166,6 +151,6 @@ export async function getCloudRun(
* so the route can change in one place.
*/
export function buildRunEventStreamUrl(sessionId: string, runId: string, sinceSeq?: number): string {
const base = `${getProxyBaseUrl()}/v1/sessions/${sessionId}/runs/${runId}/events`;
const base = `${getProxyBaseUrl()}/v2/sessions/${sessionId}/runs/${runId}/events`;
return sinceSeq !== undefined ? `${base}?since_seq=${sinceSeq}` : base;
}