219 lines
7.0 KiB
TypeScript
219 lines
7.0 KiB
TypeScript
import { handleAuthCommand } from "./commands/auth.js";
|
|
import { handleCorpsCommand } from "./commands/corps/index.js";
|
|
import { handleConfigCommand } from "./commands/config.js";
|
|
import { handleWorkflowCommand } from "./commands/workflow/index.js";
|
|
import { handlePlatformCommand } from "./commands/platform/index.js";
|
|
import { handleAppCommand } from "./commands/app.js";
|
|
import { handleMenuCommand } from "./commands/menu.js";
|
|
import { handleSkillCommand } from "./commands/skill.js";
|
|
import { handleProbeCommand } from "./commands/probe.js";
|
|
import { handleMcpCommand } from "./commands/mcp.js";
|
|
import { handleUpdateCommand } from "./commands/update/index.js";
|
|
import { handleOpenApiCommand } from "./commands/openapi.js";
|
|
import { handleBillCommand } from "./commands/bill/index.js";
|
|
import { handleFlowCommand } from "./commands/flow.js";
|
|
import { handleContactCommand } from "./commands/contact.js";
|
|
import { handleServiceCommand } from "./commands/service.js";
|
|
import { handleHttpCommand } from "./commands/http.js";
|
|
import { handleTaskCommand } from "./commands/task.js";
|
|
import { handleMessageCommand } from "./commands/message.js";
|
|
import { handleDimensionCommand } from "./commands/dimension.js";
|
|
import { handleRoleCommand } from "./commands/role.js";
|
|
import { handlePermissionCommand } from "./commands/permission.js";
|
|
import { handleRuleCommand } from "./commands/rule.js";
|
|
import { handleApprovalCommand } from "./commands/approval.js";
|
|
import { handleContextCommand } from "./commands/context.js";
|
|
import { handleKeysCommand } from "./commands/keys.js";
|
|
import { handleStoreCommand } from "./commands/store.js";
|
|
import { handleFeeTypeCommand } from "./commands/feetype.js";
|
|
import type { CliParsedArgs, CliResult, CliRunOptions, CliRuntime } from "./types.js";
|
|
|
|
export type CliCommandHandler = (
|
|
parsed: CliParsedArgs,
|
|
runtime: CliRuntime,
|
|
options: CliRunOptions
|
|
) => Promise<CliResult>;
|
|
|
|
export interface CliCommandDefinition {
|
|
area: string;
|
|
aliases: string[];
|
|
standing?: boolean | ((args: string[]) => boolean);
|
|
handler: CliCommandHandler;
|
|
}
|
|
|
|
export const CLI_COMMAND_REGISTRY: readonly CliCommandDefinition[] = [
|
|
{
|
|
area: "context",
|
|
aliases: ["status", "whoami", "env"],
|
|
handler: (parsed, runtime) => handleContextCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "aipro",
|
|
aliases: [],
|
|
handler: async (parsed) => {
|
|
const { runAiProCli } = await import("../aipro-cli.js");
|
|
const aiproIdx = parsed.raw.findIndex((a) => a.toLowerCase() === "aipro");
|
|
const subArgs = aiproIdx !== -1 ? parsed.raw.slice(aiproIdx + 1) : parsed.raw.slice(1);
|
|
return runAiProCli(subArgs);
|
|
},
|
|
},
|
|
{
|
|
area: "auth",
|
|
aliases: ["login"],
|
|
handler: (parsed, runtime) => handleAuthCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "corps",
|
|
aliases: ["corp"],
|
|
handler: (parsed, runtime) => handleCorpsCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "config",
|
|
aliases: ["mode"],
|
|
handler: (parsed, runtime) => handleConfigCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "workflow",
|
|
aliases: ["workflows", "wf"],
|
|
handler: (parsed, runtime) => handleWorkflowCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "bill",
|
|
aliases: ["bills", "fee", "fees", "invoice", "invoices"],
|
|
handler: (parsed, runtime) => handleBillCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "flow",
|
|
aliases: ["flows", "trace"],
|
|
handler: (parsed, runtime) => handleFlowCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "contact",
|
|
aliases: ["contacts", "staff", "staffs"],
|
|
handler: (parsed, runtime) => handleContactCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "task",
|
|
aliases: ["tasks", "todo"],
|
|
handler: (parsed, runtime) => handleTaskCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "dimension",
|
|
aliases: ["dimensions", "archive", "archives"],
|
|
handler: (parsed, runtime) => handleDimensionCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "feetype",
|
|
aliases: ["feetypes", "fee-type", "fee-types", "expense-type", "expense-types", "costtype"],
|
|
handler: (parsed, runtime) => handleFeeTypeCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "role",
|
|
aliases: ["roles"],
|
|
handler: (parsed, runtime) => handleRoleCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "permission",
|
|
aliases: ["permissions"],
|
|
handler: (parsed, runtime) => handlePermissionCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "rule",
|
|
aliases: ["rules"],
|
|
handler: (parsed, runtime) => handleRuleCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "approval",
|
|
aliases: ["approvals", "audit"],
|
|
handler: (parsed, runtime) => handleApprovalCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "message",
|
|
aliases: ["messages", "notify", "notifications"],
|
|
handler: (parsed, runtime) => handleMessageCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "platform",
|
|
aliases: ["platforms", "datalink", "data-link"],
|
|
handler: (parsed, runtime) => handlePlatformCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "app",
|
|
aliases: ["apps", "workbench"],
|
|
handler: (parsed, runtime) => handleAppCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "menu",
|
|
aliases: ["menus"],
|
|
handler: (parsed, runtime) => handleMenuCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "skill",
|
|
aliases: ["skills"],
|
|
handler: (parsed, runtime) => handleSkillCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "probe",
|
|
aliases: ["diagnose"],
|
|
handler: (parsed, runtime) => handleProbeCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "update",
|
|
aliases: ["upgrade", "self-update", "changelog"],
|
|
handler: (parsed, runtime, options) => handleUpdateCommand(parsed, runtime, options),
|
|
},
|
|
{
|
|
area: "openapi",
|
|
aliases: ["schema", "spec"],
|
|
handler: (parsed, runtime) => handleOpenApiCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "keys",
|
|
aliases: ["key", "secret", "secrets"],
|
|
handler: (parsed, runtime) => handleKeysCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "store",
|
|
aliases: ["market"],
|
|
handler: (parsed, runtime) => handleStoreCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "http",
|
|
aliases: ["server", "web"],
|
|
standing: true,
|
|
handler: (parsed, runtime) => handleHttpCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "service",
|
|
aliases: ["daemon"],
|
|
standing: (args) => args[1]?.toLowerCase() === "run",
|
|
handler: (parsed, runtime) => handleServiceCommand(parsed, runtime),
|
|
},
|
|
{
|
|
area: "mcp",
|
|
aliases: [],
|
|
standing: true,
|
|
handler: (parsed, _runtime, options) => handleMcpCommand(parsed, options),
|
|
},
|
|
];
|
|
|
|
const COMMAND_LOOKUP = new Map<string, CliCommandDefinition>();
|
|
for (const def of CLI_COMMAND_REGISTRY) {
|
|
COMMAND_LOOKUP.set(def.area.toLowerCase(), def);
|
|
for (const alias of def.aliases) {
|
|
COMMAND_LOOKUP.set(alias.toLowerCase(), def);
|
|
}
|
|
}
|
|
|
|
export function findCommandByArea(area?: string): CliCommandDefinition | undefined {
|
|
if (!area) return undefined;
|
|
return COMMAND_LOOKUP.get(area.toLowerCase());
|
|
}
|
|
|
|
export function isStandingCommand(args: string[]): boolean {
|
|
if (!args.length) return false;
|
|
const def = findCommandByArea(args[0]);
|
|
if (!def?.standing) return false;
|
|
return typeof def.standing === "function" ? def.standing(args) : def.standing;
|
|
}
|