import { type Database } from "./database.js"; export type SlackAgentUpdateHome = { accountId: string; workspaceId: string; }; export type SlackAgentUpdateKind = "welcome" | "update" | "dormant"; export type SlackAgentUpdateProfileState = "eligible" | "guest" | "external" | "deactivated" | "bot"; export type SlackAgentUpdateSettingsRecord = { connectionId: string; updatesEnabled: boolean; channelPostsOnly: boolean; /** Where new agents are introduced by default, or null. */ announcementChannelId: string | null; updatesEnabledAt: Date | null; updatedBySubjectId: string | null; updatedAt: Date | null; }; /** Update messages are off until an organization admin turns them on. */ export declare function defaultSlackAgentUpdateSettings(connectionId: string): SlackAgentUpdateSettingsRecord; export declare function getSlackAgentUpdateSettings(db: Database, home: SlackAgentUpdateHome, input: { connectionId: string; }): Promise; /** * Save the organization admin's choices. Turning update messages on stamps * `updatesEnabledAt`, so people who linked Slack before that are never sent a * welcome. */ export declare function saveSlackAgentUpdateSettings(db: Database, home: SlackAgentUpdateHome, input: { connectionId: string; updatesEnabled: boolean; channelPostsOnly: boolean; /** Omitted keeps the current channel; null clears it. */ announcementChannelId?: string | null | undefined; subjectId: string; }): Promise; /** * Whether Opengeni may send direct messages about agents through this * installation. "Channel posts only" means agents are announced only through * channel intro posts. */ export declare function slackAgentDirectMessagesAllowed(db: Database, home: SlackAgentUpdateHome, connectionId: string): Promise; export type SlackAgentUpdateSweepInstallation = { accountId: string; workspaceId: string; connectionId: string; updatesEnabledAt: Date | null; }; /** * Whether the runtime may call the sweeper's inventory yet. False while its * EXECUTE grant is withheld (1153) or the routine is absent. A separate * statement: EXECUTE is checked when a statement starts. */ export declare function slackAgentUpdateSweepGranted(db: Pick): Promise; /** * The installations that send update messages, across every organization, * least recently swept first. Ids only, through the sweeper's definer; empty * until that definer is granted. */ export declare function listSlackAgentUpdateSweepInstallations(db: Database, input: { limit: number; }): Promise; /** * Take one installation's sweep for a while, so replicas never sweep the same * installation at once and one installation is swept at most every * `minIntervalMs`. False when another holder has it or it ran recently. */ export declare function claimSlackAgentUpdateSweep(db: Database, home: SlackAgentUpdateHome, input: { connectionId: string; holder: string; leaseMs: number; minIntervalMs: number; }): Promise; export declare function finishSlackAgentUpdateSweep(db: Database, home: SlackAgentUpdateHome, input: { connectionId: string; holder: string; }): Promise; export type SlackAgentUpdateAudienceMember = { linkId: string; slackUserId: string; subjectId: string; linkedAt: Date; updatesMutedAt: Date | null; }; export type SlackAgentUpdateRecipientRecord = { slackUserId: string; tz: string | null; tzOffset: number | null; profileState: SlackAgentUpdateProfileState | null; profileCheckedAt: Date | null; lastSentAt: Date | null; lastKind: SlackAgentUpdateKind | null; welcomeSentAt: Date | null; dormantSentAt: Date | null; announcedAgentIds: string[]; }; export type SlackAgentUseRecord = { slackUserId: string; slackAgentId: string; lastUsedAt: Date; }; /** * Everything one sweep of one installation needs, in one transaction: linked * people, what each was sent, and which agents each already used. */ export declare function loadSlackAgentUpdateAudience(db: Database, home: SlackAgentUpdateHome, input: { connectionId: string; }): Promise<{ members: SlackAgentUpdateAudienceMember[]; recipients: Map; uses: SlackAgentUseRecord[]; }>; /** Cache one person's Slack profile facts (time zone, guest, external, active). */ export declare function saveSlackAgentUpdateRecipientProfile(db: Database, home: SlackAgentUpdateHome, input: { connectionId: string; slackUserId: string; tz: string | null; tzOffset: number | null; profileState: SlackAgentUpdateProfileState; checkedAt: Date; }): Promise; export type SlackAgentUpdateDeliveryRecord = { id: string; connectionId: string; slackUserId: string; kind: SlackAgentUpdateKind; dedupeKey: string; operationId: string; agentIds: string[]; text: string; blocks: unknown[]; state: "pending" | "sent" | "failed"; attempts: number; slackChannelId: string | null; slackMessageTs: string | null; errorCode: string | null; createdAt: Date; sentAt: Date | null; }; export declare const SLACK_AGENT_UPDATE_MIN_GAP_MS: number; export type SlackAgentUpdateClaim = { kind: "claimed"; delivery: SlackAgentUpdateDeliveryRecord; } | { kind: "skipped"; reason: "muted" | "unlinked" | "already_sent" | "too_soon" | "not_dormant"; }; /** * Durably decide to send one update message, then record it, in one * transaction that holds the person's row. The limits are checked again * under that lock, so two sweepers (or a retry) never both send. The caller * posts afterwards with the delivery's stored operation id, text and blocks. */ export declare function claimSlackAgentUpdateDelivery(db: Database, home: SlackAgentUpdateHome, input: { connectionId: string; slackUserId: string; kind: SlackAgentUpdateKind; dedupeKey: string; operationId: string; agentIds: string[]; text: string; blocks: unknown[]; now: Date; /** For a dormant reminder: when the person last used an agent or linked Slack. */ dormantSince?: Date | null; /** An update to someone dormant also counts as their dormant reminder. */ alsoDormantReminder?: boolean; }): Promise; /** Recorded messages still waiting to go out (first attempt or a retry). */ export declare function listPendingSlackAgentUpdateDeliveries(db: Database, home: SlackAgentUpdateHome, input: { connectionId: string; now: Date; limit: number; }): Promise; export declare function markSlackAgentUpdateDeliverySent(db: Database, home: SlackAgentUpdateHome, input: { deliveryId: string; slackChannelId: string; slackMessageTs: string; }): Promise; /** * Record a failed attempt. With `retryAt` the message stays pending and is * sent again under the same operation id; without it, it is given up. */ export declare function markSlackAgentUpdateDeliveryFailed(db: Database, home: SlackAgentUpdateHome, input: { deliveryId: string; errorCode: string; retryAt: Date | null; }): Promise; /** The deliveries recorded for one person, newest first. */ export declare function listSlackAgentUpdateDeliveriesFor(db: Database, home: SlackAgentUpdateHome, input: { connectionId: string; slackUserId: string; }): Promise; /** The Slack person an Opengeni identity linked through one installation, if any. */ export declare function findSlackBotUserLinkForSubject(db: Database, home: SlackAgentUpdateHome, input: { connectionId: string; subjectId: string; }): Promise<{ slackUserId: string; updatesMutedAt: Date | null; } | null>;