41 lines
1.6 KiB
JavaScript
41 lines
1.6 KiB
JavaScript
"use strict";
|
|
// =============================================================================
|
|
// 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.
|
|
// =============================================================================
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.spawnAgent = spawnAgent;
|
|
exports.getJobStatus = getJobStatus;
|
|
async function spawnAgent(cfg, input) {
|
|
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());
|
|
return { jobId: data.jobId, agent: input.agent, status: 'dispatched' };
|
|
}
|
|
catch (err) {
|
|
return { error: `Failed to spawn agent: ${err instanceof Error ? err.message : String(err)}` };
|
|
}
|
|
}
|
|
async function getJobStatus(cfg, jobId) {
|
|
try {
|
|
const res = await fetch(`${cfg.runnerUrl}/api/jobs/${jobId}`);
|
|
const job = (await res.json());
|
|
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)}` };
|
|
}
|
|
}
|