mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 08:30:21 +00:00
refactor: dedupe shared normalizer readers
This commit is contained in:
@@ -7,6 +7,7 @@ import type {
|
||||
PluginHookReplyDispatchEvent,
|
||||
PluginHookReplyDispatchResult,
|
||||
} from "../plugins/types.js";
|
||||
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||
|
||||
export { getAcpSessionManager };
|
||||
export { AcpRuntimeError, isAcpRuntimeError } from "../acp/runtime/errors.js";
|
||||
@@ -42,17 +43,12 @@ function loadDispatchAcpRuntime() {
|
||||
}
|
||||
|
||||
function hasExplicitCommandCandidate(ctx: PluginHookReplyDispatchEvent["ctx"]): boolean {
|
||||
const commandBody = ctx.CommandBody;
|
||||
if (typeof commandBody === "string" && commandBody.trim().length > 0) {
|
||||
const commandBody = normalizeOptionalString(ctx.CommandBody);
|
||||
if (commandBody) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const bodyForCommands = ctx.BodyForCommands;
|
||||
if (typeof bodyForCommands !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const normalized = bodyForCommands.trim();
|
||||
const normalized = normalizeOptionalString(ctx.BodyForCommands);
|
||||
if (!normalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { readFileSync, statSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||
|
||||
export type WindowsSpawnResolution =
|
||||
| "direct"
|
||||
@@ -129,7 +130,7 @@ function resolveBinEntry(
|
||||
binField: string | Record<string, string> | undefined,
|
||||
): string | null {
|
||||
if (typeof binField === "string") {
|
||||
const trimmed = binField.trim();
|
||||
const trimmed = normalizeOptionalString(binField);
|
||||
return trimmed || null;
|
||||
}
|
||||
if (!binField || typeof binField !== "object") {
|
||||
@@ -138,14 +139,17 @@ function resolveBinEntry(
|
||||
|
||||
if (packageName) {
|
||||
const preferred = binField[packageName];
|
||||
if (typeof preferred === "string" && preferred.trim()) {
|
||||
return preferred.trim();
|
||||
const normalizedPreferred =
|
||||
typeof preferred === "string" ? normalizeOptionalString(preferred) : undefined;
|
||||
if (normalizedPreferred) {
|
||||
return normalizedPreferred;
|
||||
}
|
||||
}
|
||||
|
||||
for (const value of Object.values(binField)) {
|
||||
if (typeof value === "string" && value.trim()) {
|
||||
return value.trim();
|
||||
const normalizedValue = typeof value === "string" ? normalizeOptionalString(value) : undefined;
|
||||
if (normalizedValue) {
|
||||
return normalizedValue;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user