mirror of https://github.com/openclaw/openclaw.git
refactor: share system run command resolution
This commit is contained in:
parent
fc408bba37
commit
06bdfc403e
|
|
@ -167,52 +167,23 @@ export function resolveSystemRunCommand(params: {
|
|||
command?: unknown;
|
||||
rawCommand?: unknown;
|
||||
}): ResolvedSystemRunCommand {
|
||||
const raw = normalizeRawCommandText(params.rawCommand);
|
||||
const command = Array.isArray(params.command) ? params.command : [];
|
||||
if (command.length === 0) {
|
||||
if (raw) {
|
||||
return {
|
||||
ok: false,
|
||||
message: "rawCommand requires params.command",
|
||||
details: { code: "MISSING_COMMAND" },
|
||||
};
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
argv: [],
|
||||
commandText: "",
|
||||
shellPayload: null,
|
||||
previewText: null,
|
||||
};
|
||||
}
|
||||
|
||||
const argv = command.map((v) => String(v));
|
||||
const validation = validateSystemRunCommandConsistency({
|
||||
argv,
|
||||
rawCommand: raw,
|
||||
allowLegacyShellText: false,
|
||||
});
|
||||
if (!validation.ok) {
|
||||
return {
|
||||
ok: false,
|
||||
message: validation.message,
|
||||
details: validation.details ?? { code: "RAW_COMMAND_MISMATCH" },
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
argv,
|
||||
commandText: validation.commandText,
|
||||
shellPayload: validation.shellPayload,
|
||||
previewText: validation.previewText,
|
||||
};
|
||||
return resolveSystemRunCommandWithMode(params, false);
|
||||
}
|
||||
|
||||
export function resolveSystemRunCommandRequest(params: {
|
||||
command?: unknown;
|
||||
rawCommand?: unknown;
|
||||
}): ResolvedSystemRunCommand {
|
||||
return resolveSystemRunCommandWithMode(params, true);
|
||||
}
|
||||
|
||||
function resolveSystemRunCommandWithMode(
|
||||
params: {
|
||||
command?: unknown;
|
||||
rawCommand?: unknown;
|
||||
},
|
||||
allowLegacyShellText: boolean,
|
||||
): ResolvedSystemRunCommand {
|
||||
const raw = normalizeRawCommandText(params.rawCommand);
|
||||
const command = Array.isArray(params.command) ? params.command : [];
|
||||
if (command.length === 0) {
|
||||
|
|
@ -236,7 +207,7 @@ export function resolveSystemRunCommandRequest(params: {
|
|||
const validation = validateSystemRunCommandConsistency({
|
||||
argv,
|
||||
rawCommand: raw,
|
||||
allowLegacyShellText: true,
|
||||
allowLegacyShellText,
|
||||
});
|
||||
if (!validation.ok) {
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in New Issue