




























@@ -1,4 +1,4 @@
1-import type { Server as HttpServer } from "node:http";
1+import type { IncomingMessage, Server as HttpServer, ServerResponse } from "node:http";
22import { WebSocketServer } from "ws";
33import { CANVAS_HOST_PATH } from "../canvas-host/a2ui.js";
44import { type CanvasHostHandler, createCanvasHostHandler } from "../canvas-host/server.js";
@@ -18,6 +18,7 @@ import type { ResolvedGatewayAuth } from "./auth.js";
1818import type { ChatAbortControllerEntry } from "./chat-abort.js";
1919import type { ControlUiRootState } from "./control-ui.js";
2020import type { HooksConfigResolved } from "./hooks.js";
21+import type { AuthorizedGatewayHttpRequest } from "./http-auth-utils.js";
2122import { isLoopbackHost, resolveGatewayListenHosts } from "./net.js";
2223import type { GatewayBroadcastFn, GatewayBroadcastToConnIdsFn } from "./server-broadcast-types.js";
2324import { createGatewayBroadcaster } from "./server-broadcast.js";
@@ -35,11 +36,8 @@ import {
3536import type { DedupeEntry } from "./server-shared.js";
3637import { createGatewayHooksRequestHandler } from "./server/hooks.js";
3738import { listenGatewayHttpServer } from "./server/http-listen.js";
38-import {
39-createGatewayPluginRequestHandler,
40-shouldEnforceGatewayAuthForPluginPath,
41-type PluginRoutePathContext,
42-} from "./server/plugins-http.js";
39+import type { PluginRoutePathContext } from "./server/plugins-http/path-context.js";
40+import { shouldEnforceGatewayAuthForPluginPath } from "./server/plugins-http/route-auth.js";
4341import {
4442createPreauthConnectionBudget,
4543type PreauthConnectionBudget,
@@ -48,6 +46,17 @@ import type { ReadinessChecker } from "./server/readiness.js";
4846import type { GatewayTlsRuntime } from "./server/tls.js";
4947import type { GatewayWsClient } from "./server/ws-types.js";
504849+type GatewayPluginRequestHandler = (
50+req: IncomingMessage,
51+res: ServerResponse,
52+pathContext?: PluginRoutePathContext,
53+dispatchContext?: {
54+gatewayAuthSatisfied?: boolean;
55+gatewayRequestAuth?: AuthorizedGatewayHttpRequest;
56+gatewayRequestOperatorScopes?: readonly string[];
57+},
58+) => Promise<boolean>;
59+5160export async function createGatewayRuntimeState(params: {
5261cfg: import("../config/config.js").OpenClawConfig;
5362bindHost: string;
@@ -145,10 +154,26 @@ export async function createGatewayRuntimeState(params: {
145154logHooks: params.logHooks,
146155});
147156148-const handlePluginRequest = createGatewayPluginRequestHandler({
149-registry: params.pluginRegistry,
150-log: params.logPlugins,
151-});
157+let loadedPluginRequestHandler: GatewayPluginRequestHandler | null = null;
158+const handlePluginRequest: GatewayPluginRequestHandler = async (
159+req,
160+res,
161+pathContext,
162+dispatchContext,
163+) => {
164+const registry = resolveActivePluginHttpRouteRegistry(params.pluginRegistry);
165+if ((registry.httpRoutes ?? []).length === 0) {
166+return false;
167+}
168+if (!loadedPluginRequestHandler) {
169+const { createGatewayPluginRequestHandler } = await import("./server/plugins-http.js");
170+loadedPluginRequestHandler = createGatewayPluginRequestHandler({
171+registry: params.pluginRegistry,
172+log: params.logPlugins,
173+});
174+}
175+return await loadedPluginRequestHandler(req, res, pathContext, dispatchContext);
176+};
152177const shouldEnforcePluginGatewayAuth = (pathContext: PluginRoutePathContext): boolean => {
153178return shouldEnforceGatewayAuthForPluginPath(
154179resolveActivePluginHttpRouteRegistry(params.pluginRegistry),
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。