import { type Database } from "./database.js"; import { type RecordEventDeliveryInput, type RecordEventDeliveryResult } from "./event-triggers.js"; export type EventSourceFeedRecord = { sourceId: string; accountId: string; workspaceId: string; cursor: string | null; gapPending: boolean; nextActionAt: Date; failures: number; failingSince: Date | null; lastError: string | null; lastSuccessAt: Date | null; }; /** Identity-only inventory of feeds whose next read is due; every read after it is workspace-scoped. */ export declare function listDueEventSourceFeeds(db: Database, limit?: number): Promise>; export type ClaimedEventSourceFeed = { feed: EventSourceFeedRecord; /** False when no runnable automation listens to the source: do not read it. */ wanted: boolean; }; /** * Lease a due feed for one read. Another pump holding the lease, or a read * that is no longer due, makes this a no-op (null). */ export declare function claimEventSourceFeed(db: Database, workspaceId: string, sourceId: string, leaseMs: number): Promise; /** * The event types and conditions of the runnable triggers listening to a * source (see automationsListenTo), for a feed that reads only what its * triggers name: "GitHub (your connection)" polls just the pull requests and * repositories they ask about. */ export declare function listListeningEventTriggers(db: Database, workspaceId: string, sourceId: string): Promise>; export type EventSourceFeedStepResult = { /** Undefined keeps the stored value. */ cursor?: string | null; gapPending?: boolean; nextActionAt: Date; outcome: { kind: "success"; } | { kind: "failure"; error: string; }; }; /** Store a read's result and release the lease. */ export declare function finishEventSourceFeedStep(db: Database, workspaceId: string, sourceId: string, result: EventSourceFeedStepResult): Promise; export type RecordEventSourceFeedDeliveryInput = { workspaceId: string; sourceId: string; delivery: Omit; /** The position after this delivery. */ cursor: string; }; /** * Record what a read found and advance the feed's position in one * transaction, so a crash never stores events without their position or the * reverse. A pending gap marks the first newly stored event. */ export declare function recordEventSourceFeedDelivery(db: Database, input: RecordEventSourceFeedDeliveryInput): Promise<(RecordEventDeliveryResult & { feed: EventSourceFeedRecord; }) | null>; /** A source's feed, for its owner's view of how reading it goes. */ export declare function getEventSourceFeed(db: Database, workspaceId: string, sourceId: string): Promise; /** One recording fact as a "This workspace" source reads it. */ export type WorkspaceRecordingEvent = { id: string; recordingId: string; type: string; /** What workspace webhooks send as `data`: ids, states and counts. */ data: Record; occurredAt: Date; /** The recording's title and purpose; null once the recording is deleted. */ title: string | null; purpose: string | null; }; export type WorkspaceRecordingEventsRead = { events: WorkspaceRecordingEvent[]; /** The database clock when it read, the next read's position. */ readAt: Date; }; /** * The recording events a person may see that a source has not stored yet, * oldest first, written after `since`. It reads as that person, so their own * recordings and those shared with the workspace are all it ever sees. * Events are stamped when they are written rather than when they commit, so * callers pass a `since` well before their last read and rely on the * "not stored yet" filter for what they already have. */ export declare function listWorkspaceRecordingEventsForSource(db: Database, input: { workspaceId: string; sourceId: string; subjectId: string; since: Date; limit: number; }): Promise; /** One fact about what happened in Opengeni itself, as the reading person may see it. */ export type WorkspaceActivityEvent = { id: string; type: string; occurredAt: Date; createdAt: Date; sessionId: string | null; turnId: string | null; subjectId: string | null; automationId: string | null; automationRunId: string | null; chainDepth: number; data: Record; /** The chat's title, when the reader may see the chat and it has one. */ chatTitle: string | null; /** The causing automation's name, when the reader may see it. */ automationName: string | null; /** How the workspace names the person the turn ran for. */ subjectLabel: string | null; /** The App an app.* fact is about (migration 1519), and its title. */ appId: string | null; appTitle: string | null; }; export type WorkspaceActivityEventsRead = { events: WorkspaceActivityEvent[]; /** The database clock when it read, the next read's position. */ readAt: Date; }; /** * Migration 1105. The activity facts (chats finishing, failing, waiting; * usage thresholds; App data changes since 1519) a person may see that a source has not stored yet, * oldest first, written after `since`. It reads as that person, so row * security keeps out other people's private chats and usage, exactly as * chat history does. Like recording events, facts are stamped when written, * so callers look back and rely on the "not stored yet" filter. */ export declare function listWorkspaceActivityEventsForSource(db: Database, input: { workspaceId: string; sourceId: string; subjectId: string; since: Date; limit: number; }): Promise;