import type { H3Event } from "h3"; export type AutomationResponseMode = "synchronous" | "asynchronous"; export type AutomationInvocationStatus = "completed" | "accepted"; export type JsonSchema = Readonly>; export interface AutomationRetryPolicy { /** Total request attempts, including the first. Bounded to three. */ readonly maxAttempts?: number; readonly retryDelayMs?: number; } export interface AutomationWorkflowCapabilities { readonly invokesExternalWorkflow: boolean; readonly receivesCallback: boolean; readonly supportsIdempotency: boolean; readonly supportsSynchronousResponse: boolean; readonly supportsAsynchronousResponse: boolean; readonly mayCauseExternalSideEffects: boolean; } export interface AutomationOutboundDefinition { /** An explicit, static HTTPS origin such as https://automations.example.com. */ readonly baseUrl: string; /** Additional explicit origins allowed for this workflow, if any. */ readonly allowedOrigins?: readonly string[]; /** A static path below baseUrl. It is never supplied by an agent. */ readonly path: string; readonly method?: "POST" | "PUT" | "PATCH"; /** * Static headers may use `${keys.NAME}` references. They are resolved only * after an action call reaches the server and are redacted from all results. */ readonly headers?: Readonly>; readonly credentialRequirements?: readonly string[]; readonly timeoutMs?: number; readonly retry?: AutomationRetryPolicy; readonly maxRequestBytes?: number; readonly maxResponseBytes?: number; readonly idempotencyHeader?: string; } export type AutomationCallbackAuthentication = { readonly kind: "shared-secret"; readonly secretRef: string; readonly header: string; readonly prefix?: string; } | { readonly kind: "hmac-sha256"; readonly secretRef: string; readonly header: string; readonly prefix?: string; } | { readonly kind: "provider-auth"; /** * Provider verification stays in the app adapter; the shared runtime * never pretends every provider uses the same signature protocol. */ readonly verify: (input: { readonly rawBody: string; readonly headers: Headers; }) => Promise; }; export interface AutomationInboundDefinition { readonly authentication: AutomationCallbackAuthentication; readonly eventIdHeader?: string; readonly maxRequestBytes?: number; /** * Receiving a callback that starts agent work requires both durable callbacks * below. The runtime rejects configurations that omit either one. */ readonly triggersAgentExecution?: boolean; } export interface AutomationWorkflowDefinition { /** Stable app-owned ID; callers use this rather than a URL. */ readonly id: string; readonly connectorId: string; readonly name: string; readonly inputSchema: JsonSchema; readonly outputSchema?: JsonSchema; readonly response: { readonly mode: AutomationResponseMode; }; readonly capabilities: AutomationWorkflowCapabilities; readonly outbound?: AutomationOutboundDefinition; readonly inbound?: AutomationInboundDefinition; } export interface AutomationInvocation { readonly workflowId: string; readonly input: Record; readonly idempotencyKey?: string; readonly userEmail: string; } export interface AutomationInvocationResult { readonly workflowId: string; readonly connectorId: string; readonly status: AutomationInvocationStatus; readonly responseMode: AutomationResponseMode; readonly attempts: number; readonly httpStatus: number; readonly output?: unknown; readonly responseTruncated: boolean; } export interface AutomationCallbackInput { readonly workflowId: string; readonly rawBody: string; readonly headers: Headers; } export interface AutomationCallbackResult { readonly accepted: boolean; readonly duplicate: boolean; readonly eventId: string; } export declare class AutomationConnectorError extends Error { readonly code: "unknown_workflow" | "unsupported_direction" | "invalid_configuration" | "blocked_target" | "payload_too_large" | "authentication_failed" | "missing_idempotency" | "timeout" | "request_failed"; constructor(code: "unknown_workflow" | "unsupported_direction" | "invalid_configuration" | "blocked_target" | "payload_too_large" | "authentication_failed" | "missing_idempotency" | "timeout" | "request_failed", message: string); } export interface AutomationRuntimeOptions { readonly workflows: readonly AutomationWorkflowDefinition[]; /** * Test-only transport injection. Production calls always use the framework * SSRF-safe fetch path. */ readonly fetch?: typeof fetch; /** * The caller receives the raw secret only inside this server-side callback. * Return a value for a configured secret reference; never log or return it. */ readonly resolveSecret?: (secretRef: string, context: { readonly userEmail?: string; }) => Promise; /** * Durable, SQL-backed idempotency claim. Return false for an already-seen * event. It is required when callbacks trigger agent execution. */ readonly claimInboundEvent?: (input: { readonly workflow: AutomationWorkflowDefinition; readonly eventId: string; }) => Promise; /** * Release a claim acquired by claimInboundEvent when durable enqueueing * throws. It is required when callbacks trigger agent execution so a * provider retry can claim the event again. */ readonly releaseInboundEvent?: (input: { readonly workflow: AutomationWorkflowDefinition; readonly eventId: string; }) => Promise; /** * Persist and dispatch agent work using the app's established durable queue. * This must be idempotent for the workflow/event ID pair because a transport * failure can make enqueue success ambiguous. Do not run an agent loop in a * callback request. */ readonly enqueueInboundEvent?: (input: { readonly workflow: AutomationWorkflowDefinition; readonly eventId: string; readonly payload: unknown; }) => Promise; } export interface AutomationRuntime { readonly listWorkflows: () => readonly AutomationWorkflowDefinition[]; readonly getWorkflow: (workflowId: string) => AutomationWorkflowDefinition | undefined; readonly invoke: (input: AutomationInvocation) => Promise; readonly receiveCallback: (input: AutomationCallbackInput) => Promise; } export declare function createAutomationRuntime(options: AutomationRuntimeOptions): AutomationRuntime; /** * Creates the narrow action applications expose to their agent and UI. The * workflow identity resolves to static server configuration; callers cannot * supply arbitrary target URLs or credentials. */ export declare function createInvokeAutomationWorkflowAction(runtime: AutomationRuntime, options?: { readonly description?: string; readonly requireApproval?: boolean; }): import("../action.js").ActionDefinition<{ workflowId: string; input: Record; idempotencyKey?: string | undefined; }, AutomationInvocationResult>; /** * Builds a route-only H3 callback handler. Mount it at * `/_agent-native/automations/callback/:workflowId`; ordinary app operations * still use actions. The callback only authenticates, deduplicates, and * durably enqueues work before returning a quick acknowledgement. */ export declare function createAutomationCallbackHandler(runtime: AutomationRuntime): (event: H3Event) => Promise<{ error: string; accepted?: undefined; duplicate?: undefined; eventId?: undefined; } | { error?: undefined; accepted: boolean; duplicate: boolean; eventId: string; }>; //# sourceMappingURL=index.d.ts.map