mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 03:18:26 +00:00
refactor(gateway): dedupe wizard and exec approval handler paths
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import type { GatewayRequestHandlers } from "./types.js";
|
||||
import type { GatewayRequestContext, GatewayRequestHandlers, RespondFn } from "./types.js";
|
||||
import { defaultRuntime } from "../../runtime.js";
|
||||
import { WizardSession } from "../../wizard/session.js";
|
||||
import {
|
||||
@@ -20,6 +20,19 @@ function readWizardStatus(session: WizardSession) {
|
||||
};
|
||||
}
|
||||
|
||||
function findWizardSessionOrRespond(params: {
|
||||
context: GatewayRequestContext;
|
||||
respond: RespondFn;
|
||||
sessionId: string;
|
||||
}): WizardSession | null {
|
||||
const session = params.context.wizardSessions.get(params.sessionId);
|
||||
if (!session) {
|
||||
params.respond(false, undefined, errorShape(ErrorCodes.INVALID_REQUEST, "wizard not found"));
|
||||
return null;
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
export const wizardHandlers: GatewayRequestHandlers = {
|
||||
"wizard.start": async ({ params, respond, context }) => {
|
||||
if (!assertValidParams(params, validateWizardStartParams, "wizard.start", respond)) {
|
||||
@@ -50,9 +63,8 @@ export const wizardHandlers: GatewayRequestHandlers = {
|
||||
return;
|
||||
}
|
||||
const sessionId = params.sessionId;
|
||||
const session = context.wizardSessions.get(sessionId);
|
||||
const session = findWizardSessionOrRespond({ context, respond, sessionId });
|
||||
if (!session) {
|
||||
respond(false, undefined, errorShape(ErrorCodes.INVALID_REQUEST, "wizard not found"));
|
||||
return;
|
||||
}
|
||||
const answer = params.answer as { stepId?: string; value?: unknown } | undefined;
|
||||
@@ -79,9 +91,8 @@ export const wizardHandlers: GatewayRequestHandlers = {
|
||||
return;
|
||||
}
|
||||
const sessionId = params.sessionId;
|
||||
const session = context.wizardSessions.get(sessionId);
|
||||
const session = findWizardSessionOrRespond({ context, respond, sessionId });
|
||||
if (!session) {
|
||||
respond(false, undefined, errorShape(ErrorCodes.INVALID_REQUEST, "wizard not found"));
|
||||
return;
|
||||
}
|
||||
session.cancel();
|
||||
@@ -94,9 +105,8 @@ export const wizardHandlers: GatewayRequestHandlers = {
|
||||
return;
|
||||
}
|
||||
const sessionId = params.sessionId;
|
||||
const session = context.wizardSessions.get(sessionId);
|
||||
const session = findWizardSessionOrRespond({ context, respond, sessionId });
|
||||
if (!session) {
|
||||
respond(false, undefined, errorShape(ErrorCodes.INVALID_REQUEST, "wizard not found"));
|
||||
return;
|
||||
}
|
||||
const status = readWizardStatus(session);
|
||||
|
||||
Reference in New Issue
Block a user