2026-02-20 07:10:58 -06:00
|
|
|
import { Command } from "commander";
|
2026-03-03 08:45:26 -06:00
|
|
|
import type { Agent } from "@paperclipai/shared";
|
2026-02-20 07:10:58 -06:00
|
|
|
import {
|
|
|
|
|
addCommonClientOptions,
|
|
|
|
|
formatInlineRecord,
|
|
|
|
|
handleCommandError,
|
|
|
|
|
printOutput,
|
|
|
|
|
resolveCommandContext,
|
|
|
|
|
type BaseClientOptions,
|
|
|
|
|
} from "./common.js";
|
|
|
|
|
|
|
|
|
|
interface AgentListOptions extends BaseClientOptions {
|
|
|
|
|
companyId?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function registerAgentCommands(program: Command): void {
|
|
|
|
|
const agent = program.command("agent").description("Agent operations");
|
|
|
|
|
|
|
|
|
|
addCommonClientOptions(
|
|
|
|
|
agent
|
|
|
|
|
.command("list")
|
|
|
|
|
.description("List agents for a company")
|
|
|
|
|
.requiredOption("-C, --company-id <id>", "Company ID")
|
|
|
|
|
.action(async (opts: AgentListOptions) => {
|
|
|
|
|
try {
|
|
|
|
|
const ctx = resolveCommandContext(opts, { requireCompany: true });
|
|
|
|
|
const rows = (await ctx.api.get<Agent[]>(`/api/companies/${ctx.companyId}/agents`)) ?? [];
|
|
|
|
|
|
|
|
|
|
if (ctx.json) {
|
|
|
|
|
printOutput(rows, { json: true });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rows.length === 0) {
|
|
|
|
|
printOutput([], { json: false });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const row of rows) {
|
|
|
|
|
console.log(
|
|
|
|
|
formatInlineRecord({
|
|
|
|
|
id: row.id,
|
|
|
|
|
name: row.name,
|
|
|
|
|
role: row.role,
|
|
|
|
|
status: row.status,
|
|
|
|
|
reportsTo: row.reportsTo,
|
|
|
|
|
budgetMonthlyCents: row.budgetMonthlyCents,
|
|
|
|
|
spentMonthlyCents: row.spentMonthlyCents,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
handleCommandError(err);
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
{ includeCompany: false },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
addCommonClientOptions(
|
|
|
|
|
agent
|
|
|
|
|
.command("get")
|
|
|
|
|
.description("Get one agent")
|
|
|
|
|
.argument("<agentId>", "Agent ID")
|
|
|
|
|
.action(async (agentId: string, opts: BaseClientOptions) => {
|
|
|
|
|
try {
|
|
|
|
|
const ctx = resolveCommandContext(opts);
|
|
|
|
|
const row = await ctx.api.get<Agent>(`/api/agents/${agentId}`);
|
|
|
|
|
printOutput(row, { json: ctx.json });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
handleCommandError(err);
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|