import { inject, injectable } from "@codemation/core"; import type { Hono } from "hono"; import { InternalHmacAuthMiddleware } from "../../../../pairing/InternalHmacAuthMiddleware"; import { HitlCallbackHandler } from "../../../../application/hitl/HitlCallbackHandler"; import type { InternalHonoApiRouteRegistrar } from "../InternalHonoApiRouteRegistrar"; @injectable() export class HitlInternalCallbackHonoApiRouteRegistrar implements InternalHonoApiRouteRegistrar { constructor( @inject(InternalHmacAuthMiddleware) private readonly hmacMiddleware: InternalHmacAuthMiddleware, @inject(HitlCallbackHandler) private readonly callbackHandler: HitlCallbackHandler, ) {} register(app: Hono): void { app.post("/internal/hitl/tasks/:taskId/callback", this.hmacMiddleware.handle(), async (c) => { const taskId = c.req.param("taskId"); const rawBody = c.get("body" as never) as string | undefined; const body = rawBody ? JSON.parse(rawBody) : await c.req.json(); const result = await this.callbackHandler.handle(taskId, body); return c.json(result.body, result.status); }); } }