/** * Inbound webhook handlers — routes external events (emails, forms, generic webhooks) * to cumulus threads via the existing inject infrastructure. * * POST /api/hooks/email — Resend inbound email parsing * POST /api/hooks/form — form submission * POST /api/hooks/webhook — generic JSON webhook */ import * as http from 'http'; import { type GatewayAgentsConfig } from '../lib/gateway.js'; import type { NamespaceConfig } from './config.js'; export interface HooksConfig { email?: EmailHookConfig; form?: FormHookConfig; /** Named webhook configs for generic webhooks */ webhooks?: Record; } export interface EmailHookConfig { enabled: boolean; provider: 'resend'; /** HMAC signing secret for Resend webhook verification */ signingSecret?: string; /** Thread name template — interpolated with event data. e.g., "prospect-{from}" */ threadMapping: string; /** Template to use when creating new threads */ defaultTemplate?: string; } export interface FormHookConfig { enabled: boolean; /** Thread name template — interpolated with form data. e.g., "intake-{email}" */ threadMapping: string; defaultTemplate?: string; } export interface WebhookConfig { /** Thread name template — interpolated with payload data */ thread: string; template?: string; } export interface HookPipelineOpts { basePath?: string; claudePath?: string; sharedMcpPort?: number; projectRoot?: string; /** Thread namespaces — the injected thread's extra MCP servers resolve from these (task 097 P5). */ namespaces?: NamespaceConfig[]; gatewayAgentsConfig?: GatewayAgentsConfig; broadcastToThread?: (threadName: string, event: Record) => void; /** Model/provider fields (tasks 113/118) — without these, webhook-triggered * turns silently diverge from every other spawn path (hardcoded Claude * fallback; non-Claude threads can't run at all). */ hfApiKey?: string; openaiApiKey?: string; customProviders?: import('./config.js').CustomProviderEntry[]; models?: import('../lib/gateway.js').MessagePipelineOptions['models']; claudeModels?: import('../lib/gateway.js').MessagePipelineOptions['claudeModels']; } /** * Verify Resend webhook signature using HMAC-SHA256. * Resend sends: `svix-id`, `svix-timestamp`, `svix-signature` headers. */ export declare function verifyResendSignature(body: string, headers: http.IncomingHttpHeaders, secret: string): boolean; /** * Interpolate a thread name template with event data. * Supports nested access: "prospect-{payload.email}" and simple: "prospect-{from}" */ export declare function interpolateThreadName(template: string, data: Record): string; /** * Normalize a value for use in a thread name — lowercase, replace non-alphanumeric with hyphens. */ export declare function normalizeThreadName(value: string): string; interface ResendInboundEmail { from: string; to: string; subject: string; text?: string; html?: string; attachments?: Array<{ filename: string; content_type: string; size: number; }>; } /** * Format a Resend inbound email as a structured message for thread injection. */ export declare function formatEmailMessage(email: ResendInboundEmail): string; /** * Handle an inbound email webhook from Resend. */ export declare function handleEmailHook(body: string, headers: http.IncomingHttpHeaders, config: EmailHookConfig, pipelineOpts: HookPipelineOpts): Promise<{ threadName: string; status: string; }>; /** * Handle a form submission webhook. */ export declare function handleFormHook(body: string, config: FormHookConfig, pipelineOpts: HookPipelineOpts): Promise<{ threadName: string; status: string; }>; /** * Handle a generic named webhook. */ export declare function handleGenericWebhook(webhookName: string, body: string, config: WebhookConfig, pipelineOpts: HookPipelineOpts): Promise<{ threadName: string; status: string; }>; export {}; //# sourceMappingURL=hooks.d.ts.map