Skip to content

Commit 90a9027

Browse files
authored
refactor(workboard): consolidate gateway and schema helpers (#128307)
1 parent f256c63 commit 90a9027

5 files changed

Lines changed: 582 additions & 935 deletions

File tree

‎extensions/workboard/src/gateway-helpers.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export type GatewayMethodContext = Parameters<
1919
Parameters<OpenClawPluginApi["registerGatewayMethod"]>[1]
2020
>[0];
2121
type GatewayRespond = GatewayMethodContext["respond"];
22+
type WorkboardGatewayResultHandler = (context: GatewayMethodContext) => unknown;
23+
type WorkboardGatewayScope = NonNullable<
24+
NonNullable<Parameters<OpenClawPluginApi["registerGatewayMethod"]>[2]>["scope"]
25+
>;
2226

2327
export function respondError(respond: GatewayRespond, error: unknown) {
2428
respond(false, undefined, {
@@ -27,6 +31,27 @@ export function respondError(respond: GatewayRespond, error: unknown) {
2731
});
2832
}
2933

34+
export function registerWorkboardResultMethods(
35+
api: OpenClawPluginApi,
36+
methods: ReadonlyArray<
37+
readonly [method: string, scope: WorkboardGatewayScope, handler: WorkboardGatewayResultHandler]
38+
>,
39+
): void {
40+
for (const [method, scope, handler] of methods) {
41+
api.registerGatewayMethod(
42+
method,
43+
async (context) => {
44+
try {
45+
context.respond(true, await handler(context));
46+
} catch (error) {
47+
respondError(context.respond, error);
48+
}
49+
},
50+
{ scope },
51+
);
52+
}
53+
}
54+
3055
export function readId(params: Record<string, unknown>): string {
3156
const value = params.id;
3257
if (typeof value === "string" && value.trim()) {

0 commit comments

Comments
 (0)