import type { H3Event } from "h3"; import { type A2AArtifactIdentity } from "../a2a/artifact-response.js"; import type { AgentEngine } from "../agent/engine/types.js"; import { type ActionEntry, type ResolvedOwnerApiKey } 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; principalType?: "user" | "service"; orgScope?: "personal"; placeholderRef?: string; strictTargetRef?: boolean; 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; systemPrompt: string; actions: Record; initialToolNames?: string[]; model?: string; apiKey: string; engine?: AgentEngine | string | { name: string; config: Record; }; appId?: string; ownerEmail: string; orgId?: string | null; principalType?: "user" | "service"; incoming?: IncomingMessage; beforeProcess?: (incoming: IncomingMessage, adapter: PlatformAdapter) => Promise<{ handled: true; responseText?: string; } | { handled: false; }>; } export type ResolvedIntegrationApiKey = ResolvedOwnerApiKey; export declare function integrationResponseIdempotencyKey(taskId: string): string; export declare function resolveIntegrationApiKey(engineOption: WebhookHandlerOptions["engine"], ownerEmail: string, fallbackApiKey: string): Promise; export declare function handleWebhook(event: H3Event, options: WebhookHandlerOptions): Promise<{ status: number; body: unknown; }>; export declare function resolveBaseUrl(event: H3Event): string; export declare function processIntegrationTask(task: PendingTask, options: WebhookHandlerOptions, campaignOptions?: { enabled?: boolean; continuationInvocation?: boolean; }): Promise; export declare function recordIntegrationResponseDelivery(payload: IntegrationResponseDeliveryTaskPayload, receipt: PlatformDeliveryReceipt): Promise;