import type { SecretRequestView, SecretSubmissionPayload } from '@xopcai/gateway-contract'; import { type SecretRef } from './secret-ref.js'; import { SecretResolver } from './secret-resolver.js'; export interface SecretRequestsOptions { rootDir?: string; resolver?: SecretResolver; now?: () => number; unlinkFile?: (path: string) => Promise; writeStoreEntryHook?: (storeName: string) => Promise; } export type SecretAnswerRecordResult = { ok: true; request: SecretRequestView; } | { ok: false; reason: 'agent_stopped' | 'already_answered' | 'not_found' | 'record_failed'; }; export type SecretAnswerInput = { request: SecretRequestView; loadRequest?: () => Promise | SecretRequestView | undefined; submission: SecretSubmissionPayload; canUseReference: boolean; /** When true and `request.delivery === 'file'`, write 0o600 files before `recordAnswer` and clean up `.bin` on commit. */ materializeFiles?: boolean; recordAnswer: (outcome: { status: 'saved' | 'declined'; ref?: SecretRef; refs?: Record; filePaths?: { file?: string; files?: Record; }; }) => Promise | SecretAnswerRecordResult; }; export type SecretAnswerResult = { status: 'saved'; request: SecretRequestView; ref?: SecretRef; refs?: Record; file?: string; files?: Record; } | { status: 'declined'; request: SecretRequestView; }; export declare class SecretRequests { readonly rootDir: string; readonly storeDir: string; readonly filesDir: string; readonly saltPath: string; readonly resolver: SecretResolver; private readonly now; private readonly unlinkFile; private readonly writeStoreEntryHook?; private readonly saltLock; private readonly answerLocks; private readonly consumeLock; private readonly registeredPaths; private cachedSalt; private sweepTimer; constructor(options?: SecretRequestsOptions); hasConfiguredProviders(): boolean; private storePath; private getOrCreateSalt; refFor(input: { conversationId: string; requestId: string; fieldId?: string; }): Promise; filePathFor(input: { conversationId: string; requestId: string; fieldId?: string; }): Promise; private writeStoreEntry; private readStoreEntry; private removeStoreEntry; private registerPathSecret; private unregisterPathSecret; private transferPathRegistration; private removeStagedRefs; private resolveSubmissionFields; private withAnswerLock; answer(input: SecretAnswerInput): Promise; private readVerifiedStoreRef; /** Strictly one-use consume: deletes the `.bin` entry BEFORE returning the plaintext value. */ consume(input: { ref: string; conversationId: string; }): Promise; private writePrivateDeliveryFile; private fileExists; saveToFile(input: { conversationId: string; request: Pick; }): Promise<{ file: string; } | { files: Record; }>; /** Write a user-pasted value directly to an owner-only 24h file (preserving exact whitespace). */ savePasted(input: { conversationId: string; requestNamespace: string; requestKey: string; value: string; }): Promise; /** Sweep expired `.bin` store entries and 24h private delivery files (`> 24h`). */ sweepExpired(): Promise<{ removedStoreEntries: number; removedFiles: number; }>; startSweepTimer(): void; stopSweepTimer(): void; }