refactor(gateway): dedupe wizard and exec approval handler paths

This commit is contained in:
Peter Steinberger
2026-02-16 17:21:57 +00:00
parent 16327f21da
commit 94a4dd0189
2 changed files with 28 additions and 27 deletions

View File

@@ -77,6 +77,15 @@ function redactExecApprovals(file: ExecApprovalsFile): ExecApprovalsFile {
};
}
function toExecApprovalsPayload(snapshot: ExecApprovalsSnapshot) {
return {
path: snapshot.path,
exists: snapshot.exists,
hash: snapshot.hash,
file: redactExecApprovals(snapshot.file),
};
}
export const execApprovalsHandlers: GatewayRequestHandlers = {
"exec.approvals.get": ({ params, respond }) => {
if (!assertValidParams(params, validateExecApprovalsGetParams, "exec.approvals.get", respond)) {
@@ -84,16 +93,7 @@ export const execApprovalsHandlers: GatewayRequestHandlers = {
}
ensureExecApprovals();
const snapshot = readExecApprovalsSnapshot();
respond(
true,
{
path: snapshot.path,
exists: snapshot.exists,
hash: snapshot.hash,
file: redactExecApprovals(snapshot.file),
},
undefined,
);
respond(true, toExecApprovalsPayload(snapshot), undefined);
},
"exec.approvals.set": ({ params, respond }) => {
if (!assertValidParams(params, validateExecApprovalsSetParams, "exec.approvals.set", respond)) {
@@ -117,16 +117,7 @@ export const execApprovalsHandlers: GatewayRequestHandlers = {
const next = mergeExecApprovalsSocketDefaults({ normalized, current: snapshot.file });
saveExecApprovals(next);
const nextSnapshot = readExecApprovalsSnapshot();
respond(
true,
{
path: nextSnapshot.path,
exists: nextSnapshot.exists,
hash: nextSnapshot.hash,
file: redactExecApprovals(nextSnapshot.file),
},
undefined,
);
respond(true, toExecApprovalsPayload(nextSnapshot), undefined);
},
"exec.approvals.node.get": async ({ params, respond, context }) => {
if (