import { type Database } from "./database.js"; import { type SiteDataAccessMode } from "./site-data-policy.js"; /** App event types, in the order the webhook and trigger catalogs list them. */ export declare const APP_ACTIVITY_EVENT_TYPES: readonly ["app.record.added", "app.record.changed", "app.record.removed", "app.sql.changed"]; export type AppActivityEventType = (typeof APP_ACTIVITY_EVENT_TYPES)[number]; /** Record data kept on a fact; larger records set `recordTruncated` instead. */ export declare const APP_ACTIVITY_RECORD_BYTES = 4096; /** Facts one write transaction records at most (a batch has at most 100 operations). */ export declare const APP_ACTIVITY_FACTS_PER_WRITE = 100; export type AppActivityScope = { accountId: string; workspaceId: string; siteId: string; }; /** * What caused a write: the person it ran for (null for none), the writer's * coarse kind, and the automation run behind it, whose chain depth the fact * carries so a loop of automations stops at the chain limit. */ export type AppActivityCause = { principal: string; writerKind: string; automationId?: string | null | undefined; automationRunId?: string | null | undefined; chainDepth?: number | undefined; }; export type AppRecordChange = { change: "added" | "changed" | "removed"; collection: { name: string; accessMode: SiteDataAccessMode; privateRecords: boolean; }; record: { id: string; key: string | null; owner: string; version: number; data: Record | null; }; }; /** * Whether anyone listens for App facts in this workspace: an active "This * workspace" source or an enabled workspace webhook subscribed to an app type. */ export declare function appActivityListening(tx: Database, workspaceId: string): Promise; /** * Record one fact per changed App Data record, inside the write's * transaction, when someone listens. Never throws: a fact that can't be * written must not fail the write (a savepoint keeps the transaction usable). */ export declare function recordAppRecordChangesInTransaction(tx: Database, scope: AppActivityScope, cause: AppActivityCause, changes: readonly AppRecordChange[]): Promise; /** * Record that an App SQL write committed (`app.sql.changed`). The App's * database commits outside Postgres, so this is written after it, best * effort: a crash between the two loses the fact, never the write. */ export declare function recordAppSqlChange(db: Database, scope: AppActivityScope, cause: AppActivityCause, change: { query: string | null; rowsWritten: number; }): Promise; export type AppAutomationCause = { taskId: string; runId: string; chainDepth: number; }; /** * The automation run behind an agent's turn, followed like the chat facts of * migration 1105: the turn's own run; for a later turn Opengeni started in an * automation's chat, that chat's run; or for a chat an agent started inside * another chat's turn, the nearest run up the chain (at most 8 chats up). */ export declare function getAppAutomationCause(db: Database, scope: { accountId: string; workspaceId: string; }, input: { sessionId: string; turnId: string | null; }): Promise;