import type { TraceSpan, TraceSummary, FeedbackEntry, SatisfactionScore, EvalResult, EvalDataset, Experiment, ExperimentAssignment, ExperimentMetricResult, InstructionUpdate, HumanReviewSummary, ObservabilityReviewThreadScope, ObservabilityReviewRunScope } from "./types.js"; export declare const MAX_REVIEW_TOOL_SPANS = 20; export declare const observabilityStore: import("../db/store-registry.js").Store; export declare function ensureObservabilityTables(): Promise; export declare function insertTraceSpan(span: TraceSpan): Promise; export declare function upsertTraceSummary(summary: TraceSummary): Promise; /** * Purge trace spans, summaries, and eval results older than `cutoffMs` * (a Unix epoch in milliseconds — rows with `created_at < cutoffMs` are * deleted). Returns the per-table deletion counts. Satisfies the span * retention TTL noted in /tmp/security-audit/12-mcp-a2a-agent.md * (MEDIUM #14): trace metadata can hold sensitive tool inputs, so we * cap the storage horizon. Feedback rows are retained — they're * intentionally durable for product analytics. Experiments and * datasets are also retained because they are user-authored * configuration, not call telemetry. */ export declare function deleteOldTraceData(cutoffMs: number): Promise<{ spans: number; summaries: number; evals: number; }>; export declare function getTraceSpansForRun(runId: string, opts?: { userId?: string; orgId?: string; }): Promise; export declare function getSuccessfulToolSpansForReview(runId: string, orgId: string, limit: number): Promise | null; }>>; export declare function getTraceSummaries(opts: { sinceMs?: number; limit?: number; userId?: string; orgId?: string; excludeSpanName?: string; requireReviewContext?: boolean; }): Promise; export declare function getRecentReviewRunsForReviewGroups(opts: { runScopes: readonly ObservabilityReviewRunScope[]; sinceMs: number; }): Promise<{ runs: TraceSummary[]; runThreadScopes: Array; }>; export declare function getTraceSummary(runId: string, opts?: { userId?: string; orgId?: string; }): Promise; /** * A thread created on a path with no request org keeps `org_id` NULL, and every * review read requires `thread.org_id` to equal the trace's org, so its runs * never reach Human Review. The run that executed under an org is the proof of * which org the thread belongs to: adopt it, for the thread's own owner only * and only while `org_id` is NULL. * * A private thread's `org_id` grants nothing but that review access (owner * access ignores it, shares do not read it, and `visibility = 'org'` is the only * way it scopes sharing), while `thread_data` holds every run's conversation. So * a private thread whose owner's runs span more than one org belongs to none of * them: the second statement unassigns it. Org-visible threads keep their * `org_id`, which is an explicit sharing scope. * * Both statements run after this run's own summary is committed * (`upsertTraceSummary` is awaited first), so of two concurrent runs under * different orgs the one whose statements run later always sees the other's * committed org. If this run's adopt raced ahead of the other run's summary, the * other run's unassign undoes it, or, when that ran before this adopt * committed, this run's own unassign does, since it starts after the adopt. * No lock is needed. * * The multi-org signal is derived from `agent_trace_summaries`, so it is only * as durable as those rows: retention purges them, and a run that never wrote a * summary is invisible to it. A thread unassigned for spanning orgs can * therefore be re-adopted once the other org's summaries age out. */ export declare function adoptTraceOrgForThread(summary: Pick): Promise; export declare function getOrgScopedThreadData(orgId: string, ownerEmail: string, threadIds: readonly string[]): Promise>; export declare function getOrgScopedThreadTitles(orgId: string, ownerEmail: string, threadIds: readonly string[]): Promise>; export declare function getOrgScopedReviewThreads(requested: readonly (ObservabilityReviewThreadScope & { ownerEmail: string; })[]): Promise>; export declare function getHumanReviewSummaries(orgId: string, runIds?: readonly string[]): Promise>; export declare function getHumanReviewSummariesForThreads(scopes: readonly ObservabilityReviewThreadScope[], requestedRuns?: readonly { orgId: string; runId: string; }[]): Promise>; export declare function upsertHumanReviewSummary(summary: HumanReviewSummary): Promise; export declare function getLatestTraceSummaryForThread(threadId: string, opts: { userId: string; excludeRunId: string; }): Promise; export declare function insertFeedback(entry: FeedbackEntry): Promise; export declare function getFeedback(opts: { threadId?: string; sinceMs?: number; limit?: number; feedbackType?: string; userId?: string; orgId?: string; source?: FeedbackEntry["source"]; runIds?: readonly string[]; threadIds?: readonly string[]; threadScopes?: readonly ObservabilityReviewThreadScope[]; runScopes?: readonly ObservabilityReviewRunScope[]; perThreadLimit?: number; }): Promise; export declare function getFeedbackStats(sinceMs: number, opts?: { userId?: string; orgId?: string; }): Promise<{ total: number; thumbsUp: number; thumbsDown: number; categories: Record; }>; export declare function insertInstructionUpdate(update: InstructionUpdate): Promise; export declare function getInstructionUpdates(opts: { runId?: string; runIds?: readonly string[]; sinceMs?: number; limit?: number; userId?: string; orgId?: string; threadIds?: readonly string[]; threadScopes?: readonly ObservabilityReviewThreadScope[]; perThreadLimit?: number; }): Promise; export declare function upsertSatisfactionScore(score: SatisfactionScore): Promise; export declare function getSatisfactionScores(opts: { sinceMs?: number; limit?: number; minFrustration?: number; userId?: string; }): Promise; export declare function insertEvalResult(result: EvalResult): Promise; export declare function getEvalsForRun(runId: string, opts?: { userId?: string; }): Promise; export declare function getEvalStats(sinceMs: number, opts?: { userId?: string; }): Promise<{ totalEvals: number; avgScore: number; byCriteria: Array<{ criteria: string; avgScore: number; count: number; }>; }>; export declare function insertEvalDataset(dataset: EvalDataset): Promise; export declare function listEvalDatasetsPage(options?: { limit?: number; before?: { updatedAt: number; id: string; }; }): Promise; export declare function listEvalDatasets(): Promise; export declare function getEvalDataset(id: string): Promise; export declare function getEvalDatasetByName(name: string, opts?: { userId?: string; }): Promise; /** * The dataset already stored for this owner and source run, if any. * A legacy row (same description, no key) is claimed in place so a concurrent * insert cannot create a second promotion. */ export declare function findPromotedEvalDataset(args: { idempotencyKey: string; description: string; userId: string | null; }): Promise; /** * Insert a promoted dataset, or return the row that already owns its * idempotency key. Concurrent promotions of the same run cannot both insert. */ export declare function savePromotedEvalDataset(dataset: EvalDataset): Promise; export declare function updateEvalDataset(id: string, updates: Partial>): Promise; export declare function insertExperiment(exp: Experiment): Promise; export declare function updateExperiment(id: string, updates: Partial>): Promise; export declare function listExperimentsPageResult(options?: { status?: Experiment["status"]; limit?: number; before?: { createdAt: number; id: string; }; }): Promise<{ items: Experiment[]; nextCursor: { createdAt: number; id: string; } | null; hasMore: boolean; }>; export declare function listExperimentsPage(options?: { status?: Experiment["status"]; limit?: number; before?: { createdAt: number; id: string; }; }): Promise; export declare function listExperiments(): Promise; export declare function getExperiment(id: string): Promise; export declare function upsertAssignment(assignment: ExperimentAssignment): Promise; export declare function getAssignment(experimentId: string, userId: string): Promise; export declare function insertExperimentResult(result: ExperimentMetricResult): Promise; export declare function getExperimentResults(experimentId: string): Promise; export declare function getObservabilityOverview(sinceMs: number, opts?: { userId?: string; }): Promise<{ totalRuns: number; totalCostCents: number; avgDurationMs: number; toolSuccessRate: number; avgFrustrationScore: number; thumbsUpRate: number; avgEvalScore: number; }>;