huskies: merge 769
This commit is contained in:
@@ -73,6 +73,39 @@ async function gatewayRequest<T>(
|
||||
return res.json() as Promise<T>;
|
||||
}
|
||||
|
||||
let _mcpRequestId = 1;
|
||||
|
||||
/// Call a gateway MCP tool via JSON-RPC and return the result.
|
||||
async function gatewayMcpCall<T>(
|
||||
toolName: string,
|
||||
args: Record<string, unknown> = {},
|
||||
): Promise<T> {
|
||||
const id = _mcpRequestId++;
|
||||
const body = JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
method: "tools/call",
|
||||
params: { name: toolName, arguments: args },
|
||||
});
|
||||
const res = await fetch("/mcp", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error(text || `MCP request failed (${res.status})`);
|
||||
}
|
||||
const json = (await res.json()) as {
|
||||
result?: Record<string, unknown>;
|
||||
error?: { message: string };
|
||||
};
|
||||
if (json.error) {
|
||||
throw new Error(json.error.message);
|
||||
}
|
||||
return json.result as T;
|
||||
}
|
||||
|
||||
export const gatewayApi = {
|
||||
/// Returns `{ mode: "gateway" }` if this server is a gateway, otherwise rejects.
|
||||
getServerMode(): Promise<ServerMode> {
|
||||
@@ -88,7 +121,9 @@ export const gatewayApi = {
|
||||
|
||||
/// List all build agents that have registered with this gateway.
|
||||
listAgents(): Promise<JoinedAgent[]> {
|
||||
return gatewayRequest<JoinedAgent[]>("/gateway/agents");
|
||||
return gatewayMcpCall<{ agents: JoinedAgent[] }>("agents.list").then(
|
||||
(result) => result.agents ?? [],
|
||||
);
|
||||
},
|
||||
|
||||
/// Remove a registered build agent by its ID.
|
||||
|
||||
Reference in New Issue
Block a user