Files
paseo/packages/cli/src/commands/agent/reload.ts
T
Mohamed Boudra 53c14d9855 Extract client SDK package (#1052)
* Extract client SDK package

* Polish SDK client identity defaults

* Build client before dependent CI jobs

* Restore daemon client server export

* Extract protocol and client SDK packages

* Fix provider override schema validation

* Fix app test daemon client imports

* Simplify workspace build targets

* Fix CLI test server build bootstrap

* Run SDK package tests in CI

* Fix rebase package split drift

* Restore lockfile registry metadata

* Update SDK config test for prompt default

* Move terminal stream router test to client package

* Fix rebase drift for protocol imports

* Fix SDK agent capability fixture

* Restore legacy server client exports

* Fix server export compatibility test

* Advertise custom mode icon client capability

* Remove server daemon-client exports

* Format rebased mode control import

* Fix rebase drift for protocol imports

Files added by upstream PRs (#893, #1147, #1154) referenced the pre-split
shared/ paths that this branch moves into @getpaseo/protocol. Redirect
those imports to the protocol package so typecheck stays green after the
rebase.
2026-05-28 01:58:18 +08:00

108 lines
2.9 KiB
TypeScript

import { Command } from "commander";
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
import { connectToDaemon, getDaemonHost, resolveAgentId } from "../../utils/client.js";
import type {
CommandOptions,
SingleResult,
OutputSchema,
CommandError,
} from "../../output/index.js";
export interface AgentReloadResult {
agentId: string;
status: "reloaded";
timelineSize: number;
}
export const reloadSchema: OutputSchema<AgentReloadResult> = {
idField: "agentId",
columns: [
{ header: "AGENT ID", field: "agentId" },
{ header: "STATUS", field: "status" },
{ header: "TIMELINE", field: "timelineSize" },
],
};
export function addReloadOptions(cmd: Command): Command {
return cmd
.description("Reload an agent (restarts the underlying process)")
.argument("<id>", "Agent ID, prefix, or name");
}
export interface AgentReloadOptions extends CommandOptions {
host?: string;
}
export type AgentReloadCommandResult = SingleResult<AgentReloadResult>;
export async function runReloadCommand(
agentIdArg: string,
options: AgentReloadOptions,
_command: Command,
): Promise<AgentReloadCommandResult> {
const host = getDaemonHost({ host: options.host });
if (!agentIdArg || agentIdArg.trim().length === 0) {
const error: CommandError = {
code: "MISSING_AGENT_ID",
message: "Agent ID is required",
details: "Usage: paseo agent reload <id-or-name>",
};
throw error;
}
let client: DaemonClient;
try {
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
code: "DAEMON_NOT_RUNNING",
message: `Cannot connect to daemon at ${host}: ${message}`,
details: "Start the daemon with: paseo daemon start",
};
throw error;
}
try {
const agentsPayload = await client.fetchAgents({ filter: { includeArchived: true } });
const agents = agentsPayload.entries.map((entry) => entry.agent);
const agentId = resolveAgentId(agentIdArg, agents);
if (!agentId) {
const error: CommandError = {
code: "AGENT_NOT_FOUND",
message: `Agent not found: ${agentIdArg}`,
details: 'Use "paseo ls" to list available agents',
};
throw error;
}
const result = await client.refreshAgent(agentId);
await client.close();
return {
type: "single",
data: {
agentId: result.agentId,
status: "reloaded",
timelineSize: result.timelineSize ?? 0,
},
schema: reloadSchema,
};
} catch (err) {
await client.close().catch(() => {});
if (err && typeof err === "object" && "code" in err) {
throw err;
}
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
code: "RELOAD_FAILED",
message: `Failed to reload agent: ${message}`,
};
throw error;
}
}