openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
332 lines (331 loc) • 10 kB
JavaScript
import { b as loadPrivateQaCliModule, v as getSubCliEntriesCore } from "./argv-DNjh_yaF.js";
import { t as resolveCliArgvInvocation } from "./argv-invocation-C1WhAkJL.js";
import { t as createLazyImportLoader } from "./lazy-promise-DGqyc4Y4.js";
import { i as shouldRegisterPrimarySubcommandOnly, n as shouldEagerRegisterSubcommands } from "./command-registration-policy-Crwwx_Cg.js";
import { t as resolveCliCommandPathPolicy } from "./command-path-policy-CYBY98jZ.js";
import { t as removeCommandByName } from "./command-tree-CA1ToIBK.js";
import { i as registerCommandGroups, r as registerCommandGroupByName } from "./register-command-groups-DO7oGkdB.js";
//#region src/cli/program/command-group-descriptors.ts
function buildDescriptorIndex(descriptors) {
return new Map(descriptors.map((descriptor) => [descriptor.name, descriptor]));
}
/** Resolve named command-group specs into descriptor-backed entries. */
function resolveCommandGroupEntries(descriptors, specs) {
const descriptorsByName = buildDescriptorIndex(descriptors);
return specs.map((spec) => ({
placeholders: spec.commandNames.map((name) => {
const descriptor = descriptorsByName.get(name);
if (!descriptor) throw new Error(`Unknown command descriptor: ${name}`);
return descriptor;
}),
register: spec.register
}));
}
/** Build lazy command-group entries with a mapped program registrar. */
function buildCommandGroupEntries(descriptors, specs, mapRegister) {
return resolveCommandGroupEntries(descriptors, specs).map((entry) => ({
placeholders: entry.placeholders,
register: mapRegister(entry.register)
}));
}
/** Define a lazy group that imports its module at registration time. */
function defineImportedCommandGroupSpec(commandNames, loadModule, register) {
return {
commandNames,
register: async (args) => {
await register(await loadModule(), args);
}
};
}
/** Map program-level imported command definitions to lazy specs with export validation. */
function defineImportedProgramCommandGroupSpecs(definitions) {
return definitions.map((definition) => ({
commandNames: definition.commandNames,
register: async (program) => {
const register = (await definition.loadModule())[definition.exportName];
if (typeof register !== "function") throw new Error(`Missing program command registrar: ${definition.exportName}`);
await register(program);
}
}));
}
//#endregion
//#region src/cli/program/register.subclis-core.ts
const pluginCliLoader = createLazyImportLoader(() => import("./cli-CSMlN8GD.js"));
function shouldRegisterGatewayRunOnly(name, argv) {
if (name !== "gateway") return false;
const invocation = resolveCliArgvInvocation(argv);
if (invocation.hasHelpOrVersion || invocation.commandPath[0] !== "gateway") return false;
return invocation.commandPath.length === 1 || invocation.commandPath[1] === "run";
}
async function registerGatewayRunOnly(program) {
const { addGatewayRunCommand } = await import("./run-command-CnJq_lHv.js");
removeCommandByName(program, "gateway");
addGatewayRunCommand(addGatewayRunCommand(program.command("gateway").description("Run, inspect, and query the WebSocket Gateway")).command("run").description("Run the WebSocket Gateway (foreground)"));
}
async function registerSubCliWithPluginCommands(program, argv, registerSubCli, pluginCliPosition) {
const invocation = resolveCliArgvInvocation(argv);
const shouldRegisterPluginCommands = !invocation.hasHelpOrVersion && resolveCliCommandPathPolicy(invocation.commandPath).loadPlugins !== "never";
if (pluginCliPosition === "before" && shouldRegisterPluginCommands) {
const { registerPluginCliCommandsFromValidatedConfig } = await pluginCliLoader.load();
await registerPluginCliCommandsFromValidatedConfig(program);
}
await registerSubCli();
if (pluginCliPosition === "after" && shouldRegisterPluginCommands) {
const { registerPluginCliCommandsFromValidatedConfig } = await pluginCliLoader.load();
await registerPluginCliCommandsFromValidatedConfig(program);
}
}
function defineImportedSubCliGroups(definitions) {
return defineImportedProgramCommandGroupSpecs(definitions.map(([commandNames, loadModule, exportName]) => ({
commandNames,
loadModule,
exportName
})));
}
const entrySpecs = [
...defineImportedSubCliGroups([
[
["acp"],
() => import("./acp-cli-DTp-vH7v.js"),
"registerAcpCli"
],
[
["gateway"],
() => import("./gateway-cli-BM_DvrpH.js"),
"registerGatewayCli"
],
[
["daemon"],
() => import("./cli/daemon-cli.js"),
"registerDaemonCli"
],
[
["logs"],
() => import("./logs-cli-C5Xa3L8_.js"),
"registerLogsCli"
],
[
["system"],
() => import("./system-cli-DSYiW6QF.js"),
"registerSystemCli"
],
[
["models"],
() => import("./models-cli-8P0F_9ZL.js"),
"registerModelsCli"
],
[
["promos"],
() => import("./promos-cli-ChhzkaFh.js"),
"registerPromosCli"
],
[
["telemetry"],
() => import("./telemetry-cli-DfuiBBR7.js"),
"registerTelemetryCli"
]
]),
{
commandNames: ["infer", "capability"],
register: async (program, argv) => {
await (await import("./capability-cli-sIappHhy.js")).registerCapabilityCli(program, argv);
}
},
...defineImportedSubCliGroups([[
["approvals", "exec-approvals"],
() => import("./exec-approvals-cli-RU98rV1n.js"),
"registerExecApprovalsCli"
], [
["exec-policy"],
() => import("./exec-policy-cli-DUHnuPSZ.js"),
"registerExecPolicyCli"
]]),
{
commandNames: ["nodes"],
register: async (program, argv) => {
await (await import("./nodes-cli-DnNZpWrr.js")).registerNodesCli(program, argv);
}
},
...defineImportedSubCliGroups([
[
["devices"],
() => import("./devices-cli-b9JLhQoK.js"),
"registerDevicesCli"
],
[
["users"],
() => import("./users-cli-DA519NUo.js"),
"registerUsersCli"
],
[
["node"],
() => import("./node-cli-B4XOVYeT.js"),
"registerNodeCli"
],
[
["connect"],
() => import("./connect-cli-CPs6MuZt.js"),
"registerConnectCli"
],
[
["worker"],
() => import("./worker-cli-D_Ux5vkK.js"),
"registerWorkerCli"
],
[
["sandbox"],
() => import("./sandbox-cli-C-tnQmk6.js"),
"registerSandboxCli"
],
[
["fleet"],
() => import("./fleet-cli-B5gPR_0O.js"),
"registerFleetCli"
],
[
["worktrees"],
() => import("./worktrees-cli-C-Rtj2k7.js"),
"registerWorktreesCli"
],
[
["attach"],
() => import("./attach-cli-CzSJlql_.js"),
"registerAttachCli"
],
[
[
"tui",
"terminal",
"chat"
],
() => import("./tui-cli-DIxfXjd4.js"),
"registerTuiCli"
],
[
["resume"],
() => import("./resume-cli-Clc-eRTt.js"),
"registerResumeCli"
],
[
["cron", "automations"],
() => import("./cron-cli-Bsuzh33J.js"),
"registerCronCli"
],
[
["dns"],
() => import("./dns-cli-DIGT7ydH.js"),
"registerDnsCli"
],
[
["docs"],
() => import("./docs-cli-O_NqajVa.js"),
"registerDocsCli"
],
[
["qa"],
loadPrivateQaCliModule,
"registerQaLabCli"
],
[
["proxy"],
() => import("./proxy-cli-CPBjGW74.js"),
"registerProxyCli"
],
[
["hooks"],
() => import("./hooks-cli-DvYrJJpK.js"),
"registerHooksCli"
],
[
["webhooks"],
() => import("./webhooks-cli-BmTMBGMo.js"),
"registerWebhooksCli"
],
[
["qr"],
() => import("./qr-cli-RDFg-Ruk.js"),
"registerQrCli"
],
[
["clawbot"],
() => import("./clawbot-cli-dkyuKdHP.js"),
"registerClawbotCli"
]
]),
{
commandNames: ["pairing"],
register: async (program, argv) => {
await registerSubCliWithPluginCommands(program, argv, async () => {
(await import("./pairing-cli-DxTs4enl.js")).registerPairingCli(program);
}, "before");
}
},
{
commandNames: ["plugins"],
register: async (program, argv) => {
await registerSubCliWithPluginCommands(program, argv, async () => {
(await import("./plugins-cli-BwEJAYVs.js")).registerPluginsCli(program);
}, "after");
}
},
{
commandNames: ["channels"],
register: async (program, argv, context) => {
await (await import("./channels-cli-Cq8hnd90.js")).registerChannelsCli(program, argv, { includeSetupOptions: context.purpose === "completion" });
}
},
...defineImportedSubCliGroups([
[
["directory"],
() => import("./directory-cli-VOOm3tEe.js"),
"registerDirectoryCli"
],
[
["security"],
() => import("./security-cli-BIZ9iUna.js"),
"registerSecurityCli"
],
[
["secrets"],
() => import("./secrets-cli-4bPDsGHy.js"),
"registerSecretsCli"
],
[
["skills"],
() => import("./skills-cli-vlwGRAOo.js"),
"registerSkillsCli"
],
[
["update"],
() => import("./update-cli-CPmLvs6u.js"),
"registerUpdateCli"
]
])
];
function resolveSubCliCommandGroups(argv, context = {}) {
const descriptors = getSubCliEntriesCore();
const descriptorNames = new Set(descriptors.map((descriptor) => descriptor.name));
return buildCommandGroupEntries(descriptors, entrySpecs.filter((spec) => spec.commandNames.every((name) => descriptorNames.has(name))), (register) => async (program) => {
await register(program, argv, context);
});
}
function getSubCliEntries() {
return getSubCliEntriesCore();
}
async function registerSubCliByNameCore(program, name, argv = process.argv, context = {}) {
if (shouldRegisterGatewayRunOnly(name, argv)) {
await registerGatewayRunOnly(program);
return true;
}
return registerCommandGroupByName(program, resolveSubCliCommandGroups(argv, context), name);
}
function registerSubCliCommandsCore(program, argv = process.argv) {
const { primary } = resolveCliArgvInvocation(argv);
registerCommandGroups(program, resolveSubCliCommandGroups(argv), {
eager: shouldEagerRegisterSubcommands(),
primary,
registerPrimaryOnly: Boolean(primary && shouldRegisterPrimarySubcommandOnly(argv))
});
}
//#endregion
export { defineImportedCommandGroupSpec as a, buildCommandGroupEntries as i, registerSubCliByNameCore as n, defineImportedProgramCommandGroupSpecs as o, registerSubCliCommandsCore as r, getSubCliEntries as t };