This repository has been archived on 2026-06-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
master-ai/vibn-agent-runner/src/tools/agent-api.ts

47 lines
1.8 KiB
TypeScript

// =============================================================================
// Pure sub-agent orchestration API. Wraps the vibn-agent-runner HTTP endpoints
// so the same logic is usable from the in-process tool and from an MCP server.
// =============================================================================
export interface AgentRunnerConfig {
runnerUrl: string;
}
export interface SpawnAgentInput {
agent: string; // "Coder" | "PM" | "Marketing"
task: string;
repo: string; // "owner/name"
}
export async function spawnAgent(cfg: AgentRunnerConfig, input: SpawnAgentInput): Promise<unknown> {
try {
const res = await fetch(`${cfg.runnerUrl}/api/agent/run`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Internal': 'true' },
body: JSON.stringify({ agent: input.agent, task: input.task, repo: input.repo }),
});
const data = (await res.json()) as any;
return { jobId: data.jobId, agent: input.agent, status: 'dispatched' };
} catch (err) {
return { error: `Failed to spawn agent: ${err instanceof Error ? err.message : String(err)}` };
}
}
export async function getJobStatus(cfg: AgentRunnerConfig, jobId: string): Promise<unknown> {
try {
const res = await fetch(`${cfg.runnerUrl}/api/jobs/${jobId}`);
const job = (await res.json()) as any;
return {
id: job.id,
agent: job.agent,
status: job.status,
progress: job.progress,
toolCalls: job.toolCalls?.length,
result: job.result,
error: job.error,
};
} catch (err) {
return { error: `Failed to get job: ${err instanceof Error ? err.message : String(err)}` };
}
}