import { type AskAnswerPayload, type AskCancelPayload, type AskCreatePayload, type UpdateQuestionPayload, type QuestionContentRevision, type QuestionEventHistory, type QuestionHistory, type AskQuestionDraft, type AskBatchQuestionDraft, type AskBatchReceipt, type AskRequestSnapshot, type AskResult, type AskStatus, type ProposeAnswerPayload, type ProposedAnswerOption, type QuestionTelemetryEvent } from "../protocol.js"; import type { SqliteDatabase } from "../db/database.js"; import type { SessionStore } from "./sessionStore.js"; type ResolutionListener = (result: AskResult) => void; export interface AnswerAvailable { questionId: string; question: string; answerId: string; ownerHarness: string; ownerId: string; } type AnswerAvailableListener = (answer: AnswerAvailable) => void; import { type ImageStore } from "./imageStore.js"; export interface RequestStoreOptions { imageStore?: ImageStore; generateProposedOptionValue?: () => string; recordTelemetry?: (event: QuestionTelemetryEvent) => void; } export interface ProposedAnswerAppend { option: ProposedAnswerOption; request: AskRequestSnapshot; } export interface QuestionDiscoveryCaller { owner: { harness: string; ownerId: string; }; repository: string; worktree: string; feature: string; } export type QuestionDiscoveryScope = "owner" | "feature" | "worktree" | "repository" | "global"; export interface QuestionDiscoveryFilters { caller: QuestionDiscoveryCaller; scope?: QuestionDiscoveryScope; owner?: { harness: string; ownerId: string; }; repository?: string; worktree?: string; feature?: string; status?: AskStatus; /** @deprecated Use scope: "global". */ global?: boolean; cursor?: string; pageSize?: number; } export interface QuestionStatusFilters extends QuestionDiscoveryFilters { readState?: "read" | "unread"; includeTerminal?: boolean; } export interface QuestionStatusPage { statuses: Array>; nextCursor?: string; } export interface QuestionHistoryPage { view: "events" | "full"; questionId: string; initial?: QuestionHistory["revisions"][number]; revisions: Array; events: QuestionHistory["events"]; nextCursor?: string; } export declare class RequestStore { private readonly db; private readonly now; private readonly options; private readonly listeners; private readonly globalResolutionListeners; private readonly answerAvailableListeners; private readonly ownerWaits; private closed; private readonly generateProposedOptionValue; private readonly recordTelemetry; constructor(db: SqliteDatabase, now: () => number, options?: RequestStoreOptions); close(): void; activeWaitCount(owner: { harness: string; ownerId: string; }): number; notifyOwnerTransfer(previousOwner: { harness: string; ownerId: string; }, nextOwner: { harness: string; ownerId: string; }, questionId: string): void; transferQuestionOwner(questionId: string, expectedOwner: { harness: string; ownerId: string; }, nextOwner: { harness: string; ownerId: string; }, reason?: "transfer" | "takeover", expectedRevision?: number, expectedOwnerRevision?: number): { revision: number; ownerRevision: number; }; takeoverQuestionOwner(questionId: string, expectedOwner: { harness: string; ownerId: string; }, nextOwner: { harness: string; ownerId: string; }, sessions: SessionStore, expectedRevision?: number, expectedOwnerRevision?: number): { revision: number; ownerRevision: number; }; getAnswerForRecovery(questionId: string, reader: { harness: string; ownerId: string; }, view?: "compact" | "full"): Record; waitForPostbox(input: { owner: { harness: string; ownerId: string; }; signal?: AbortSignal; publishSemanticState?: (state: string) => void; }): Promise>; create(payload: AskCreatePayload): AskRequestSnapshot; createOne(sessionId: string, draft: AskQuestionDraft): { questionId: string; revision: number; ownerRevision: number; status: "created"; questionStatus: AskStatus; nudge?: string; }; createBatch(sessionId: string, compactDrafts: AskBatchQuestionDraft[]): AskBatchReceipt; private validateHierarchy; list(filters?: { status?: AskStatus; }): AskRequestSnapshot[]; get(requestId: string): AskRequestSnapshot | undefined; listQuestions(filters: QuestionDiscoveryFilters): { questions: Array<{ questionId: string; question: string; }>; nextCursor?: string; }; getQuestions(input: { questionIds: string[]; view?: "control" | "full"; }): Array>; listQuestionStatus(filters: QuestionStatusFilters): Array>; listQuestionStatusPage(filters: QuestionStatusFilters): QuestionStatusPage; proposeAnswer(requestId: string, ownerSessionId: string, payload: ProposeAnswerPayload): ProposedAnswerAppend; updateQuestion(questionId: string, actor: { harness: string; ownerId: string; }, payload: UpdateQuestionPayload, sessions?: SessionStore, stagingSessionId?: string): Record; getQuestionHistory(questionId: string, view?: "events" | "full"): QuestionEventHistory | QuestionHistory; getQuestionHistoryPage(input: { questionId: string; view?: "events" | "full"; cursor?: string; pageSize?: number; }): QuestionHistoryPage; private loadQuestionHistory; private toEventHistory; private seedQuestionRevision; private recordQuestionEvent; private throwOwnerTransferConflict; private validateNewParent; answer(requestId: string, payload: AskAnswerPayload | (Omit & { expectedRevision?: number; })): AskResult; onAnswerAvailable(listener: AnswerAvailableListener): () => void; pendingOwnerNotifications(owner: { harness: string; ownerId: string; }): AnswerAvailable[]; claimProactiveAnswerNotifications(owner: { harness: string; ownerId: string; }, connectionToken: string, sessions?: SessionStore): AnswerAvailable[]; releaseProactiveNotificationClaims(owner: { harness: string; ownerId: string; }, connectionToken: string): number; acknowledgeOwnerNotification(answerId: string, owner: { harness: string; ownerId: string; }, connectionToken: string): boolean; getAnswer(questionId: string, reader: { harness: string; ownerId: string; }): Record; private compactAnswerRead; private readAnswer; cancel(requestId: string, payload?: AskCancelPayload): AskResult; cancelPendingForSession(sessionId: string, note: string): AskResult[]; expireDue(): AskResult[]; onAnyResolved(listener: ResolutionListener): () => void; onResolved(requestId: string, listener: ResolutionListener): () => void; private getPending; private validateSelectedValues; /** Compatibility snapshots are derived from the owner Question/Answer records. */ private snapshotSelect; private draftTelemetry; private toSnapshot; private openDescendantIds; private parseJson; private ownerKey; private nextUnreadQuestionId; private wakeOwnerWithAnswer; private wakeOwnerWithLifecycle; private abortError; private assertPageSize; private decodeQuestionCursor; private decodeKeysetCursor; private decodeCursorTuple; private toResult; private notify; } export declare class RequestStoreError extends Error { readonly code: string; constructor(code: string, message: string); } export {}; //# sourceMappingURL=requestStore.d.ts.map