feat(api): expose REST-only agent routes
Agent CI/CD / docker-image (push) Failing after 35s
Agent CI/CD / deploy-fallback-log (push) Successful in 1s

This commit is contained in:
2026-07-30 20:38:52 +08:00
parent 2415f75841
commit 94529cb141
29 changed files with 3525 additions and 378 deletions
+10 -11
View File
@@ -1,7 +1,6 @@
import { CliError } from "../core/errors.js";
import { emitApi } from "../core/http.js";
import { optionalString, parseOptions, requiredString, validateChoice } from "../core/options.js";
import { requireNetwork } from "../core/runtime.js";
import type { HandlerMap, RuntimeContext } from "../core/types.js";
type ComponentKind = "time" | "energy" | "pump-energy" | "network";
@@ -10,22 +9,22 @@ function componentOption(ctx: RuntimeContext, argv: string[], schema: boolean):
const { values } = parseOptions(argv);
const kind = validateChoice(requiredString(values, "kind"), ["time", "energy", "pump-energy", "network"] as const, "--kind");
const routes: Record<`${ComponentKind}:${boolean}`, string> = {
"time:true": "/gettimeschema",
"time:false": "/gettimeproperties/",
"energy:true": "/getenergyschema/",
"energy:false": "/getenergyproperties/",
"pump-energy:true": "/getpumpenergyschema/",
"pump-energy:false": "/getpumpenergyproperties//",
"network:true": "/getoptionschema/",
"network:false": "/getoptionproperties/",
"time:true": "/network-schemas/time",
"time:false": "/network-options/time",
"energy:true": "/network-schemas/energy",
"energy:false": "/network-options/energy",
"pump-energy:true": "/network-schemas/pump-energy",
"pump-energy:false": "/network-options/pump-energy",
"network:true": "/network-schemas/option",
"network:false": "/network-options",
};
const params: Record<string, unknown> = { network: requireNetwork(ctx) };
const params: Record<string, unknown> = {};
const pump = optionalString(values, "pump");
if (kind === "pump-energy") {
if (!schema && !pump) throw new CliError("CLI 参数错误", "PUMP_REQUIRED", "--pump is required when --kind pump-energy", 2);
if (pump) params.pump = pump;
}
return emitApi(ctx, schema ? "读取选项 schema 成功" : "读取选项属性成功", { method: "GET", path: routes[`${kind}:${schema}`], params, requireNetworkCtx: true });
return emitApi(ctx, schema ? "读取选项 schema 成功" : "读取选项属性成功", { method: "GET", path: routes[`${kind}:${schema}`], params, requireProject: true });
}
export const componentHandlers: HandlerMap = {