Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { COMMANDS } from "./src/commands.js";
const controllerState = vi.hoisted(() => ({
createService: vi.fn(() => ({ start: vi.fn(), stop: vi.fn() })),
handleConversationBindingResolved: vi.fn(),
handleBeforeDispatch: vi.fn(),
handleInboundClaim: vi.fn(),
handleTelegramInteractive: vi.fn(),
handleDiscordInteractive: vi.fn(),
Expand All @@ -14,6 +15,7 @@ vi.mock("./src/controller.js", () => ({
CodexPluginController: class {
createService = controllerState.createService;
handleConversationBindingResolved = controllerState.handleConversationBindingResolved;
handleBeforeDispatch = controllerState.handleBeforeDispatch;
handleInboundClaim = controllerState.handleInboundClaim;
handleTelegramInteractive = controllerState.handleTelegramInteractive;
handleDiscordInteractive = controllerState.handleDiscordInteractive;
Expand All @@ -35,10 +37,11 @@ describe("plugin registration", () => {
expect(() => plugin.register(api as never)).not.toThrow();
expect(api.registerService).toHaveBeenCalledTimes(1);
expect(api.on).toHaveBeenCalledWith("inbound_claim", expect.any(Function));
expect(api.on).toHaveBeenCalledWith("before_dispatch", expect.any(Function));
expect(api.registerInteractiveHandler).toHaveBeenCalledTimes(2);
expect(api.registerCommand).toHaveBeenCalled();
expect(api.registerCommand.mock.calls.map(([params]) => params.name)).toEqual(
COMMANDS.map(([name]) => name),
[...COMMANDS.map(([name]) => name), "cas_click"],
);
});

Expand Down
18 changes: 18 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const plugin = {
description: "Independent OpenClaw plugin for the Codex App Server protocol.",
register(api: OpenClawPluginApi) {
const controller = new CodexPluginController(api);
const hookApi = api as OpenClawPluginApi & {
on?: (
hookName: string,
handler: (event: Record<string, unknown>, ctx?: Record<string, unknown>) => Promise<unknown> | unknown,
) => void;
};

api.registerService(controller.createService());

Expand All @@ -25,6 +31,9 @@ const plugin = {
api.on("inbound_claim", async (event) => {
return await controller.handleInboundClaim(event);
});
hookApi.on?.("before_dispatch", async (event, ctx) => {
return await controller.handleBeforeDispatch(event, ctx);
});

api.registerInteractiveHandler({
channel: "telegram",
Expand Down Expand Up @@ -54,6 +63,15 @@ const plugin = {
},
});
}

api.registerCommand({
name: "cas_click",
description: "Internal command for Feishu card callbacks.",
acceptsArgs: true,
handler: async (ctx) => {
return await controller.handleCommand("cas_click", ctx);
},
});
},
};

Expand Down
Loading