Spaces:
Configuration error
Configuration error
File size: 5,546 Bytes
3a65265 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
import type { Command } from "commander";
import { agentsListCommand } from "../../commands/agents.js";
import { healthCommand } from "../../commands/health.js";
import { sessionsCommand } from "../../commands/sessions.js";
import { statusCommand } from "../../commands/status.js";
import { defaultRuntime } from "../../runtime.js";
import { getFlagValue, getPositiveIntFlagValue, getVerboseFlag, hasFlag } from "../argv.js";
import { registerBrowserCli } from "../browser-cli.js";
import { registerConfigCli } from "../config-cli.js";
import { registerMemoryCli, runMemoryStatus } from "../memory-cli.js";
import { registerAgentCommands } from "./register.agent.js";
import { registerConfigureCommand } from "./register.configure.js";
import { registerMaintenanceCommands } from "./register.maintenance.js";
import { registerMessageCommands } from "./register.message.js";
import { registerOnboardCommand } from "./register.onboard.js";
import { registerSetupCommand } from "./register.setup.js";
import { registerStatusHealthSessionsCommands } from "./register.status-health-sessions.js";
import { registerSubCliCommands } from "./register.subclis.js";
import type { ProgramContext } from "./context.js";
type CommandRegisterParams = {
program: Command;
ctx: ProgramContext;
argv: string[];
};
type RouteSpec = {
match: (path: string[]) => boolean;
loadPlugins?: boolean;
run: (argv: string[]) => Promise<boolean>;
};
export type CommandRegistration = {
id: string;
register: (params: CommandRegisterParams) => void;
routes?: RouteSpec[];
};
const routeHealth: RouteSpec = {
match: (path) => path[0] === "health",
loadPlugins: true,
run: async (argv) => {
const json = hasFlag(argv, "--json");
const verbose = getVerboseFlag(argv, { includeDebug: true });
const timeoutMs = getPositiveIntFlagValue(argv, "--timeout");
if (timeoutMs === null) return false;
await healthCommand({ json, timeoutMs, verbose }, defaultRuntime);
return true;
},
};
const routeStatus: RouteSpec = {
match: (path) => path[0] === "status",
loadPlugins: true,
run: async (argv) => {
const json = hasFlag(argv, "--json");
const deep = hasFlag(argv, "--deep");
const all = hasFlag(argv, "--all");
const usage = hasFlag(argv, "--usage");
const verbose = getVerboseFlag(argv, { includeDebug: true });
const timeoutMs = getPositiveIntFlagValue(argv, "--timeout");
if (timeoutMs === null) return false;
await statusCommand({ json, deep, all, usage, timeoutMs, verbose }, defaultRuntime);
return true;
},
};
const routeSessions: RouteSpec = {
match: (path) => path[0] === "sessions",
run: async (argv) => {
const json = hasFlag(argv, "--json");
const store = getFlagValue(argv, "--store");
if (store === null) return false;
const active = getFlagValue(argv, "--active");
if (active === null) return false;
await sessionsCommand({ json, store, active }, defaultRuntime);
return true;
},
};
const routeAgentsList: RouteSpec = {
match: (path) => path[0] === "agents" && path[1] === "list",
run: async (argv) => {
const json = hasFlag(argv, "--json");
const bindings = hasFlag(argv, "--bindings");
await agentsListCommand({ json, bindings }, defaultRuntime);
return true;
},
};
const routeMemoryStatus: RouteSpec = {
match: (path) => path[0] === "memory" && path[1] === "status",
run: async (argv) => {
const agent = getFlagValue(argv, "--agent");
if (agent === null) return false;
const json = hasFlag(argv, "--json");
const deep = hasFlag(argv, "--deep");
const index = hasFlag(argv, "--index");
const verbose = hasFlag(argv, "--verbose");
await runMemoryStatus({ agent, json, deep, index, verbose });
return true;
},
};
export const commandRegistry: CommandRegistration[] = [
{
id: "setup",
register: ({ program }) => registerSetupCommand(program),
},
{
id: "onboard",
register: ({ program }) => registerOnboardCommand(program),
},
{
id: "configure",
register: ({ program }) => registerConfigureCommand(program),
},
{
id: "config",
register: ({ program }) => registerConfigCli(program),
},
{
id: "maintenance",
register: ({ program }) => registerMaintenanceCommands(program),
},
{
id: "message",
register: ({ program, ctx }) => registerMessageCommands(program, ctx),
},
{
id: "memory",
register: ({ program }) => registerMemoryCli(program),
routes: [routeMemoryStatus],
},
{
id: "agent",
register: ({ program, ctx }) =>
registerAgentCommands(program, { agentChannelOptions: ctx.agentChannelOptions }),
routes: [routeAgentsList],
},
{
id: "subclis",
register: ({ program, argv }) => registerSubCliCommands(program, argv),
},
{
id: "status-health-sessions",
register: ({ program }) => registerStatusHealthSessionsCommands(program),
routes: [routeHealth, routeStatus, routeSessions],
},
{
id: "browser",
register: ({ program }) => registerBrowserCli(program),
},
];
export function registerProgramCommands(
program: Command,
ctx: ProgramContext,
argv: string[] = process.argv,
) {
for (const entry of commandRegistry) {
entry.register({ program, ctx, argv });
}
}
export function findRoutedCommand(path: string[]): RouteSpec | null {
for (const entry of commandRegistry) {
if (!entry.routes) continue;
for (const route of entry.routes) {
if (route.match(path)) return route;
}
}
return null;
}
|