import type { MountedMastraCode } from '@mastra/code-sdk'; import type { NotificationPriority } from '@mastra/core/notifications'; import type { SubscriptionSessionLookup } from '../subscription-session.js'; import type { GitLabSignalSubscriptionRow, GitLabSubscriptionStorage, GitLabWebhookMergeRequestTarget } from './subscriptions.js'; import type { ParsedGitLabWebhook } from './webhook.js'; export interface GitLabWebhookNotificationMetadata { event: string; action: string; host: string; projectId: number; projectPath: string; mergeRequestIid: number; sender?: string; senderId?: number; deliveryId: string; } export interface GitLabWebhookNotification { action: string; kind: string; priority: NotificationPriority; summary: string; terminal: boolean; metadata: GitLabWebhookNotificationMetadata; payload: Record; } /** * The integration surface this dispatch uses. Narrow on purpose so the direct * and Platform-backed integrations, and tests, can satisfy it. */ export interface GitLabWebhookDispatchIntegration { readonly integrationStorage: GitLabSubscriptionStorage; readonly sourceControlStorage?: SubscriptionSessionLookup; getProjectMemberAccessLevel(connectionId: string, projectId: string, username: string): Promise; resolveActiveConnectionForHost?(storedConnectionId: string, host: string): Promise; } export interface GitLabWebhookDispatchDependencies { controller: MountedMastraCode['controller']; gitlab?: GitLabWebhookDispatchIntegration; listSubscriptions?: (target: GitLabWebhookMergeRequestTarget, options?: { includeTerminal?: boolean; }) => Promise; retireSubscription?: (id: string, status: 'open' | 'closed' | 'merged') => Promise; /** * Author gate override. The default requires the sender to be a trusted * project member through the subscription's connection. */ isAuthorizedSender?: (notification: GitLabWebhookNotification, subscription: GitLabSignalSubscriptionRow) => Promise; /** Called when the sender gate drops a notification, so the drop is observable. */ onSenderRejected?: (notification: GitLabWebhookNotification) => void; onTargetError?: (subscription: GitLabSignalSubscriptionRow, error: unknown) => void; /** Called when a subscription names a thread this deployment does not hold. */ onTargetSkipped?: (subscription: GitLabSignalSubscriptionRow) => void; /** * The connection the event arrived through. When set, only subscriptions * created under that connection are delivered; a direct project webhook * leaves it unset because GitLab does not say which connection it belongs to. */ sourceConnectionId?: string; /** Called when a subscription is skipped because it belongs to another connection. */ onConnectionMismatch?: (subscription: GitLabSignalSubscriptionRow) => void; } /** * The GitLab instance a delivery came from: the project's `web_url` host, which * must agree with the `X-Gitlab-Instance` header when one was sent. A mismatch * yields no host, so the delivery matches no subscription. */ export declare function gitlabWebhookHost(parsed: ParsedGitLabWebhook): string | undefined; export declare function classifyGitLabWebhook(parsed: ParsedGitLabWebhook): GitLabWebhookNotification | undefined; export declare function dispatchGitLabWebhook(parsed: ParsedGitLabWebhook, dependencies: GitLabWebhookDispatchDependencies): Promise<{ delivered: number; failed: number; skipped: number; ignored: boolean; }>; //# sourceMappingURL=webhook-dispatch.d.ts.map