2026-04-11 21:33:04 +08:00
|
|
|
import Router from '@koa/router'
|
2026-04-17 16:48:24 +08:00
|
|
|
import { emitWebhook } from '../services/hermes/hermes'
|
2026-04-11 21:33:04 +08:00
|
|
|
|
|
|
|
|
export const webhookRoutes = new Router()
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* POST /webhook — receive callbacks from Hermes Agent
|
|
|
|
|
*
|
|
|
|
|
* Expected body:
|
|
|
|
|
* {
|
|
|
|
|
* "event": "run.completed" | "job.completed" | ...,
|
|
|
|
|
* "run_id": "...",
|
|
|
|
|
* "data": { ... }
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* TODO: Add signature verification when Hermes supports webhook signing
|
|
|
|
|
*/
|
|
|
|
|
webhookRoutes.post('/webhook', async (ctx) => {
|
|
|
|
|
const payload = ctx.request.body
|
|
|
|
|
|
|
|
|
|
if (!payload || !payload.event) {
|
|
|
|
|
ctx.status = 400
|
|
|
|
|
ctx.body = { error: 'Missing event field' }
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(`[Webhook] Received event: ${payload.event}`)
|
|
|
|
|
|
|
|
|
|
// Emit to registered callbacks
|
|
|
|
|
emitWebhook(payload)
|
|
|
|
|
|
|
|
|
|
ctx.body = { ok: true }
|
|
|
|
|
})
|