31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
// Dispatches one attempt to the agent CLI its profile names.
|
|
import { runClaude } from "./agent-claude.ts";
|
|
import { runCodex } from "./agent-codex.ts";
|
|
import { runOpenCode } from "./agent-opencode.ts";
|
|
import { codexAuthentication } from "./auth.ts";
|
|
import type { CodexAuthentication } from "./auth.ts";
|
|
import type { RuntimeProfile } from "./runtime.ts";
|
|
|
|
export interface AgentAnswer {
|
|
body?: string;
|
|
resultPath?: string;
|
|
}
|
|
|
|
// Runs the selected agent; Codex leaves its answer in a file, the others return it.
|
|
export async function runAgent(
|
|
profile: RuntimeProfile,
|
|
token: string | undefined,
|
|
prompt: string,
|
|
authentication: CodexAuthentication | null,
|
|
): Promise<AgentAnswer> {
|
|
if (profile.type === "claude") {
|
|
return { body: await runClaude(profile, token ?? "", prompt) };
|
|
}
|
|
if (profile.type === "codex") {
|
|
return {
|
|
resultPath: await runCodex(profile, prompt, authentication ?? codexAuthentication(token)),
|
|
};
|
|
}
|
|
return { body: await runOpenCode(profile, token ?? "", prompt) };
|
|
}
|