mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 21:10:21 +00:00
Gateway: add path-scoped config schema lookup (#37266)
Merged via squash.
Prepared head SHA: 0c4d187f6f
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
c5828cbc08
commit
ff97195500
@@ -17,7 +17,11 @@ import {
|
||||
redactConfigSnapshot,
|
||||
restoreRedactedValues,
|
||||
} from "../../config/redact-snapshot.js";
|
||||
import { buildConfigSchema, type ConfigSchemaResponse } from "../../config/schema.js";
|
||||
import {
|
||||
buildConfigSchema,
|
||||
lookupConfigSchema,
|
||||
type ConfigSchemaResponse,
|
||||
} from "../../config/schema.js";
|
||||
import { extractDeliveryInfo } from "../../config/sessions.js";
|
||||
import type { OpenClawConfig } from "../../config/types.openclaw.js";
|
||||
import {
|
||||
@@ -36,9 +40,12 @@ import {
|
||||
import {
|
||||
ErrorCodes,
|
||||
errorShape,
|
||||
formatValidationErrors,
|
||||
validateConfigApplyParams,
|
||||
validateConfigGetParams,
|
||||
validateConfigPatchParams,
|
||||
validateConfigSchemaLookupParams,
|
||||
validateConfigSchemaLookupResult,
|
||||
validateConfigSchemaParams,
|
||||
validateConfigSetParams,
|
||||
} from "../protocol/index.js";
|
||||
@@ -113,6 +120,14 @@ function parseRawConfigOrRespond(
|
||||
return rawValue;
|
||||
}
|
||||
|
||||
function sanitizeLookupPathForLog(path: string): string {
|
||||
const sanitized = Array.from(path, (char) => {
|
||||
const code = char.charCodeAt(0);
|
||||
return code < 0x20 || code === 0x7f ? "?" : char;
|
||||
}).join("");
|
||||
return sanitized.length > 120 ? `${sanitized.slice(0, 117)}...` : sanitized;
|
||||
}
|
||||
|
||||
function parseValidateConfigFromRawOrRespond(
|
||||
params: unknown,
|
||||
requestName: string,
|
||||
@@ -258,6 +273,39 @@ export const configHandlers: GatewayRequestHandlers = {
|
||||
}
|
||||
respond(true, loadSchemaWithPlugins(), undefined);
|
||||
},
|
||||
"config.schema.lookup": ({ params, respond, context }) => {
|
||||
if (
|
||||
!assertValidParams(params, validateConfigSchemaLookupParams, "config.schema.lookup", respond)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const path = (params as { path: string }).path;
|
||||
const schema = loadSchemaWithPlugins();
|
||||
const result = lookupConfigSchema(schema, path);
|
||||
if (!result) {
|
||||
respond(
|
||||
false,
|
||||
undefined,
|
||||
errorShape(ErrorCodes.INVALID_REQUEST, "config schema path not found"),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!validateConfigSchemaLookupResult(result)) {
|
||||
const errors = validateConfigSchemaLookupResult.errors ?? [];
|
||||
context.logGateway.warn(
|
||||
`config.schema.lookup produced invalid payload for ${sanitizeLookupPathForLog(path)}: ${formatValidationErrors(errors)}`,
|
||||
);
|
||||
respond(
|
||||
false,
|
||||
undefined,
|
||||
errorShape(ErrorCodes.UNAVAILABLE, "config.schema.lookup returned invalid payload", {
|
||||
details: { errors },
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
respond(true, result, undefined);
|
||||
},
|
||||
"config.set": async ({ params, respond }) => {
|
||||
if (!assertValidParams(params, validateConfigSetParams, "config.set", respond)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user