mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 21:22:54 +00:00
refactor!: remove versioned system-run approval contract
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import type { SystemRunApprovalPlanV2 } from "./exec-approvals.js";
|
||||
import { normalizeSystemRunApprovalPlanV2 } from "./system-run-approval-binding.js";
|
||||
import type { SystemRunApprovalPlan } from "./exec-approvals.js";
|
||||
import { normalizeSystemRunApprovalPlan } from "./system-run-approval-binding.js";
|
||||
import { formatExecCommand, resolveSystemRunCommand } from "./system-run-command.js";
|
||||
|
||||
type PreparedRunPayload = {
|
||||
cmdText: string;
|
||||
plan: SystemRunApprovalPlanV2;
|
||||
plan: SystemRunApprovalPlan;
|
||||
};
|
||||
|
||||
type SystemRunApprovalRequestContext = {
|
||||
planV2: SystemRunApprovalPlanV2 | null;
|
||||
plan: SystemRunApprovalPlan | null;
|
||||
commandArgv: string[] | undefined;
|
||||
commandText: string;
|
||||
cwd: string | null;
|
||||
@@ -19,7 +19,7 @@ type SystemRunApprovalRequestContext = {
|
||||
type SystemRunApprovalRuntimeContext =
|
||||
| {
|
||||
ok: true;
|
||||
planV2: SystemRunApprovalPlanV2 | null;
|
||||
plan: SystemRunApprovalPlan | null;
|
||||
argv: string[];
|
||||
cwd: string | null;
|
||||
agentId: string | null;
|
||||
@@ -54,7 +54,7 @@ export function parsePreparedSystemRunPayload(payload: unknown): PreparedRunPayl
|
||||
}
|
||||
const raw = payload as { cmdText?: unknown; plan?: unknown };
|
||||
const cmdText = normalizeString(raw.cmdText);
|
||||
const plan = normalizeSystemRunApprovalPlanV2(raw.plan);
|
||||
const plan = normalizeSystemRunApprovalPlan(raw.plan);
|
||||
if (!cmdText || !plan) {
|
||||
return null;
|
||||
}
|
||||
@@ -65,38 +65,38 @@ export function resolveSystemRunApprovalRequestContext(params: {
|
||||
host?: unknown;
|
||||
command?: unknown;
|
||||
commandArgv?: unknown;
|
||||
systemRunPlanV2?: unknown;
|
||||
systemRunPlan?: unknown;
|
||||
cwd?: unknown;
|
||||
agentId?: unknown;
|
||||
sessionKey?: unknown;
|
||||
}): SystemRunApprovalRequestContext {
|
||||
const host = normalizeString(params.host) ?? "";
|
||||
const planV2 = host === "node" ? normalizeSystemRunApprovalPlanV2(params.systemRunPlanV2) : null;
|
||||
const plan = host === "node" ? normalizeSystemRunApprovalPlan(params.systemRunPlan) : null;
|
||||
const fallbackArgv = normalizeStringArray(params.commandArgv);
|
||||
const fallbackCommand = normalizeCommandText(params.command);
|
||||
return {
|
||||
planV2,
|
||||
commandArgv: planV2?.argv ?? (fallbackArgv.length > 0 ? fallbackArgv : undefined),
|
||||
commandText: planV2 ? (planV2.rawCommand ?? formatExecCommand(planV2.argv)) : fallbackCommand,
|
||||
cwd: planV2?.cwd ?? normalizeString(params.cwd),
|
||||
agentId: planV2?.agentId ?? normalizeString(params.agentId),
|
||||
sessionKey: planV2?.sessionKey ?? normalizeString(params.sessionKey),
|
||||
plan,
|
||||
commandArgv: plan?.argv ?? (fallbackArgv.length > 0 ? fallbackArgv : undefined),
|
||||
commandText: plan ? (plan.rawCommand ?? formatExecCommand(plan.argv)) : fallbackCommand,
|
||||
cwd: plan?.cwd ?? normalizeString(params.cwd),
|
||||
agentId: plan?.agentId ?? normalizeString(params.agentId),
|
||||
sessionKey: plan?.sessionKey ?? normalizeString(params.sessionKey),
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveSystemRunApprovalRuntimeContext(params: {
|
||||
planV2?: unknown;
|
||||
plan?: unknown;
|
||||
command?: unknown;
|
||||
rawCommand?: unknown;
|
||||
cwd?: unknown;
|
||||
agentId?: unknown;
|
||||
sessionKey?: unknown;
|
||||
}): SystemRunApprovalRuntimeContext {
|
||||
const normalizedPlan = normalizeSystemRunApprovalPlanV2(params.planV2 ?? null);
|
||||
const normalizedPlan = normalizeSystemRunApprovalPlan(params.plan ?? null);
|
||||
if (normalizedPlan) {
|
||||
return {
|
||||
ok: true,
|
||||
planV2: normalizedPlan,
|
||||
plan: normalizedPlan,
|
||||
argv: [...normalizedPlan.argv],
|
||||
cwd: normalizedPlan.cwd,
|
||||
agentId: normalizedPlan.agentId,
|
||||
@@ -113,7 +113,7 @@ export function resolveSystemRunApprovalRuntimeContext(params: {
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
planV2: null,
|
||||
plan: null,
|
||||
argv: command.argv,
|
||||
cwd: normalizeString(params.cwd),
|
||||
agentId: normalizeString(params.agentId),
|
||||
|
||||
Reference in New Issue
Block a user