huskies: merge 950
This commit is contained in:
+12
-57
@@ -40,60 +40,19 @@ export interface AgentConfigInfo {
|
||||
max_budget_usd: number | null;
|
||||
}
|
||||
|
||||
const DEFAULT_API_BASE = "/api";
|
||||
|
||||
function buildApiUrl(path: string, baseUrl = DEFAULT_API_BASE): string {
|
||||
return `${baseUrl}${path}`;
|
||||
}
|
||||
|
||||
async function requestJson<T>(
|
||||
path: string,
|
||||
options: RequestInit = {},
|
||||
baseUrl = DEFAULT_API_BASE,
|
||||
): Promise<T> {
|
||||
const res = await fetch(buildApiUrl(path, baseUrl), {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(options.headers ?? {}),
|
||||
},
|
||||
...options,
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error(text || `Request failed (${res.status})`);
|
||||
}
|
||||
|
||||
return res.json() as Promise<T>;
|
||||
}
|
||||
|
||||
export const agentsApi = {
|
||||
startAgent(storyId: string, agentName?: string, baseUrl?: string) {
|
||||
return requestJson<AgentInfo>(
|
||||
"/agents/start",
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
story_id: storyId,
|
||||
agent_name: agentName,
|
||||
}),
|
||||
},
|
||||
baseUrl,
|
||||
);
|
||||
startAgent(storyId: string, agentName?: string) {
|
||||
return rpcCall<AgentInfo>("agents.start", {
|
||||
story_id: storyId,
|
||||
agent_name: agentName,
|
||||
});
|
||||
},
|
||||
|
||||
stopAgent(storyId: string, agentName: string, baseUrl?: string) {
|
||||
return requestJson<boolean>(
|
||||
"/agents/stop",
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
story_id: storyId,
|
||||
agent_name: agentName,
|
||||
}),
|
||||
},
|
||||
baseUrl,
|
||||
);
|
||||
stopAgent(storyId: string, agentName: string) {
|
||||
return rpcCall<boolean>("agents.stop", {
|
||||
story_id: storyId,
|
||||
agent_name: agentName,
|
||||
});
|
||||
},
|
||||
|
||||
listAgents(_baseUrl?: string) {
|
||||
@@ -104,12 +63,8 @@ export const agentsApi = {
|
||||
return rpcCall<AgentConfigInfo[]>("agent_config.list");
|
||||
},
|
||||
|
||||
reloadConfig(baseUrl?: string) {
|
||||
return requestJson<AgentConfigInfo[]>(
|
||||
"/agents/config/reload",
|
||||
{ method: "POST" },
|
||||
baseUrl,
|
||||
);
|
||||
reloadConfig() {
|
||||
return rpcCall<AgentConfigInfo[]>("agent_config.list");
|
||||
},
|
||||
|
||||
getAgentOutput(storyId: string, agentName: string, _baseUrl?: string) {
|
||||
|
||||
Reference in New Issue
Block a user