mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 04:31:10 +00:00
test: normalize command context text safely
This commit is contained in:
@@ -21,6 +21,16 @@ function firstText(values: Array<string | undefined>): string | undefined {
|
||||
return values.map((value) => value?.trim() ?? "").find(Boolean) || undefined;
|
||||
}
|
||||
|
||||
function normalizeCommandContextText(value: unknown): string {
|
||||
if (typeof value === "string") {
|
||||
return value.trim().toLowerCase();
|
||||
}
|
||||
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
||||
return String(value).trim().toLowerCase();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function resolveThreadTargetId(raw?: string): string | undefined {
|
||||
const trimmed = raw?.trim() ?? "";
|
||||
if (!trimmed) {
|
||||
@@ -289,17 +299,13 @@ function buildSessionCommandParams(
|
||||
SenderId: "user-1",
|
||||
...ctxOverrides,
|
||||
} as HandleCommandsParams["ctx"];
|
||||
const channel = String(ctx.Provider ?? ctx.Surface ?? "")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
const channel = normalizeCommandContextText(ctx.Provider ?? ctx.Surface);
|
||||
const senderId = typeof ctx.SenderId === "string" ? ctx.SenderId : undefined;
|
||||
return {
|
||||
ctx,
|
||||
cfg: baseCfg,
|
||||
command: {
|
||||
surface: String(ctx.Surface ?? ctx.Provider ?? "")
|
||||
.trim()
|
||||
.toLowerCase(),
|
||||
surface: normalizeCommandContextText(ctx.Surface ?? ctx.Provider),
|
||||
channel,
|
||||
channelId: channel,
|
||||
ownerList: [],
|
||||
|
||||
Reference in New Issue
Block a user