export declare const MAX_PENDING_TASK_ATTEMPTS = 3; export declare function ensurePendingTasksTable(): Promise; /** Status values for an integration pending task. */ export type PendingTaskStatus = "pending" | "processing" | "completed" | "failed"; export interface PendingTask { id: string; platform: string; externalThreadId: string; payload: string; ownerEmail: string; orgId: string | null; status: PendingTaskStatus; attempts: number; dispatchAttempts: number; lastDispatchAt: number | null; lastDispatchOutcome: string | null; dispatchScope: string | null; errorMessage: string | null; createdAt: number; updatedAt: number; completedAt: number | null; } /** * Whether a provider thread currently has queued or executing work. * * Messaging adapters use this to accept unmentioned replies only while an * agent task is active. This prevents broad message subscriptions from turning * every channel message into an agent invocation. */ export declare function hasActivePendingTask(platform: string, externalThreadId: string): Promise; /** * Insert a new pending task. Returns the generated task id. * * If `externalEventKey` is supplied, the unique index on * `(platform, external_event_key)` will reject duplicates — callers should * catch the resulting constraint-violation error and treat it as * "already enqueued" instead of a hard failure (H3 in the webhook security * audit). This is the SQL-backed replacement for the in-memory dedup map. */ export declare function insertPendingTask(input: { id: string; platform: string; externalThreadId: string; payload: string; ownerEmail: string; orgId?: string | null; externalEventKey?: string | null; dispatchScope?: string | null; }): Promise; /** * Returns whether a duplicate-event error from `insertPendingTask` looks * like a unique-constraint violation on `(platform, external_event_key)`. * * Postgres surfaces these as `error.code === "23505"`, while SQLite uses * a substring match on the error text. Used by the webhook handler to * distinguish "already enqueued" (silently OK) from genuine insert failures. */ export declare function isDuplicateEventError(err: unknown): boolean; /** Fetch a pending task by id. */ export declare function getPendingTask(id: string): Promise; export interface ResolvedIntegrationSourceContext { platform: "slack"; sourceUrl: string; } type PendingTaskSourceRow = Pick; export declare function sourceContextFromPendingTask(task: PendingTaskSourceRow | null, ownerEmail: string, orgId: string | null): ResolvedIntegrationSourceContext | null; /** Resolve trusted Slack provenance without exposing the stored task payload. */ export declare function resolveIntegrationSourceContext(id: string, ownerEmail: string, orgId: string | null): Promise; /** * Atomically claim a task: transition pending → processing and increment * attempts. Returns the updated task if the transition succeeded, otherwise * null (e.g. the task was already claimed by a concurrent worker). */ export declare function claimPendingTask(id: string, options?: { dispatchOutcome?: string; }): Promise; export declare function recordPendingTaskDispatchAttempt(id: string, outcome: string): Promise; /** Next queued turn for a provider thread after its current task completes. */ export declare function getNextPendingTaskForThread(platform: string, externalThreadId: string): Promise<{ id: string; dispatchScope: string | null; } | null>; /** Mark a task as completed. */ export declare function markTaskCompleted(id: string): Promise; /** * Return a transiently failed task to the retryable queue without erasing its * payload. The payload may contain the only copy of the inbound message and is * scrubbed only when the task reaches a permanent terminal state. */ export declare function markTaskRetryable(id: string, errorMessage: string): Promise; export declare function stageTaskDeliveryPayload(id: string, payload: string): Promise; export declare function markTaskDeliveryRetryable(id: string, payload: string, errorMessage: string): Promise; export declare function failTaskDeliveryTransition(id: string, errorMessage: string): Promise; /** Mark a task as failed and stash an error message. */ export declare function markTaskFailed(id: string, errorMessage: string): Promise; export {}; //# sourceMappingURL=pending-tasks-store.d.ts.map