import type { H3Event } from "h3"; import { type A2AArtifactIdentity } from "../a2a/artifact-response.js"; import type { AgentEngine } from "../agent/engine/types.js"; import { type ActionEntry } from "../agent/production-agent.js"; import { type PendingTask } from "./pending-tasks-store.js"; import type { PlatformAdapter, IncomingMessage, OutgoingMessage, PlatformDeliveryReceipt } from "./types.js"; export type IntegrationResponseDeliveryTaskPayload = { kind: "response-delivery"; incoming: IncomingMessage; message: OutgoingMessage; placeholderRef?: string; internalThreadId?: string; userMessageId?: string; assistantMessageId?: string; deliveryReceipt?: PlatformDeliveryReceipt; deliveredAt?: string; artifacts?: A2AArtifactIdentity[]; campaignTerminalStatus?: "completed" | "failed"; awaitingA2ACompletion?: true; }; export type ProcessIntegrationTaskResult = { status: "completed"; } | { status: "campaign-pending" | "campaign-active"; } | { status: "campaign-failed"; } | { status: "delivery-pending"; payload: IntegrationResponseDeliveryTaskPayload; errorMessage: string; campaignLease?: { campaignId: string; runId: string; leaseToken: string; campaignStatus: "completed" | "failed" | "waiting-a2a"; }; }; export interface WebhookHandlerOptions { adapter: PlatformAdapter; /** Resolved system prompt string */ systemPrompt: string; /** Action entries for the agent */ actions: Record; /** * Tool names to expose on the FIRST engine request. When provided, every * other name in `actions` (framework additions such as * `list-integration-memory` / `call-agent` merged in by * `createIntegrationsPlugin`) is deferred behind the attached `tool-search` * entry instead of being serialized on every inbound message — the run * loop's mid-run tool expansion (`expandActiveTools` in `runAgentLoop`) * still lets the model discover and call them after a search. Omit to keep * the full `actions` set visible up front (current behavior). */ initialToolNames?: string[]; /** Model to use. Defaults to the resolved engine's default model. */ model?: string; /** Anthropic API key */ apiKey: string; /** Agent engine to use. Defaults to the same resolver as web chat. */ engine?: AgentEngine | string | { name: string; config: Record; }; /** App/template id used for org-scoped per-app model defaults. */ appId?: string; /** Thread owner for personal/shared resource loading */ ownerEmail: string; /** Explicit org for service principals that are not login users. */ orgId?: string | null; /** Durable execution identity kind, preserved across deferred processing. */ principalType?: "user" | "service"; /** * Pre-parsed incoming message. When provided, handleWebhook skips its own * verification + parsing steps. Required when the caller has already read * the request body (h3 doesn't reliably cache parsed bodies, so re-parsing * the same event hangs on streaming providers). */ incoming?: IncomingMessage; /** Optional hook to intercept inbound commands before agent execution */ beforeProcess?: (incoming: IncomingMessage, adapter: PlatformAdapter) => Promise<{ handled: true; responseText?: string; } | { handled: false; }>; } export declare function resolveIntegrationApiKey(engineOption: WebhookHandlerOptions["engine"], ownerEmail: string, fallbackApiKey: string): Promise; /** * Process an incoming webhook from a messaging platform. * * Flow: * 1. Handle verification challenges (Slack url_verification, etc.) * 2. Verify webhook signature * 3. Parse incoming message (null = ignored event) * 4. Persist task to SQL * 5. Dispatch the queued task through the configured processor handoff * (a fresh function execution with its own timeout budget) * 6. Return HTTP 200 immediately (within Slack's 3s SLA) * * The processor endpoint runs the actual agent loop. This split is essential * for serverless platforms (Netlify Lambda, Vercel, Cloudflare Workers) which * freeze the function as soon as the response is returned, killing any * lingering background promises. */ export declare function handleWebhook(event: H3Event, options: WebhookHandlerOptions): Promise<{ status: number; body: unknown; }>; /** * Resolve the base URL we should dispatch the processor request to. * Prefers explicit env vars (most reliable on serverless), falls back to the * inbound request's headers. */ export declare function resolveBaseUrl(event: H3Event): string; /** * Run the actual agent loop for a previously-enqueued task. Called by the * processor endpoint in `plugin.ts`. This is a fresh function execution, so * it gets its own timeout budget independent of the inbound webhook handler. */ export declare function processIntegrationTask(task: PendingTask, options: WebhookHandlerOptions, campaignOptions?: { enabled?: boolean; continuationInvocation?: boolean; }): Promise; export declare function recordIntegrationResponseDelivery(payload: IntegrationResponseDeliveryTaskPayload, receipt: PlatformDeliveryReceipt): Promise; //# sourceMappingURL=webhook-handler.d.ts.map