// ============================================================================= // 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 { 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 { 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)}` }; } }