import type { WorkspaceInsightsSnapshot } from "@opengeni/contracts"; import type { Database } from "./database.js"; import type { ModelCallFactAggregateRow, ModelCallFactSeriesAggregate, ModelCallFacetRow, ModelContextContributionAggregate, RecentModelCallRow, RootSessionDriverRow, ScheduleFactAggregate } from "./insights.js"; export type WorkspaceInsightsModelBundleInput = { workspaceId: string; since: Date; until: Date; priorSince: Date; priorUntil: Date; granularity: "day" | "hour"; provider?: string | null; model?: string | null; rootSessionId?: string | null; sessionId?: string | null; }; export declare const INSIGHTS_ROOT_DRIVER_LIMIT = 8; /** Projects listed by name; the rest fold into one exact `other` row. */ export declare const INSIGHTS_PROJECT_LIMIT = 24; export type InsightsProjectAggregateRow = { kind: "project" | "other" | "unfiled" | "unavailable"; channelId: string | null; name: string | null; /** Projects folded into this row: 1 for a named project, N for `other`. */ projects: number; rootSessions: number; calls: number; totalTokens: number; cachedTokens: number; cacheInputTokens: number; pricedCostMicros: number; estimatedProviderCostMicros: number; estimatedProviderCostKnownCalls: number; }; export declare const INSIGHTS_FACET_LIMIT = 500; export declare const INSIGHTS_RECENT_CALL_LIMIT = 50; export type WorkspaceInsightsModelBundle = { /** Newest `recorded_at` among visible facts in the unfiltered current window. */ dataThrough: Date | null; /** Distinct root-session groups before the driver limit is applied. */ driverGroups: number; driversTruncated: boolean; facetsTruncated: boolean; recentCallsTruncated: boolean; modelRows: ModelCallFactAggregateRow[]; priorModelRows: ModelCallFactAggregateRow[]; factBuckets: Map; rootDrivers: RootSessionDriverRow[]; priorRootDrivers: RootSessionDriverRow[]; /** Every root group in the window, grouped by project; sums to the totals. */ projects: InsightsProjectAggregateRow[]; privateChats: WorkspaceInsightsSnapshot["privateChats"]; privateChatsTruncated: boolean; scheduleFacts: ScheduleFactAggregate[]; facets: ModelCallFacetRow[]; recentCalls: RecentModelCallRow[]; promptContributions: ModelContextContributionAggregate; }; /** * One bounded model-fact query for the Workspace Insights response. Each UTC * window is read once through the narrow scoped projection (migration 0541) and * aggregated in one grouping-sets pass. A filtered or session-scoped request adds * one unfiltered current-window read because facets and the freshness watermark * are deliberately workspace-wide; an unfiltered request reuses current_visible. * Every bounded list reads one row past its limit so truncation is reported * rather than silent. */ export declare function readWorkspaceInsightsModelBundle(db: Database, input: WorkspaceInsightsModelBundleInput): Promise;