/** * Durable provider-local reservations for Telegram topic adoption. * * A reservation is keyed by the stable provider request identity, never by a * preallocated Broker SessionId. Broker allocates the SessionId; the daemon * CAS-binds that opaque value only after the lifecycle service returns it. * This store owns only presentation mappings and pending-topic authorization. */ import type { SessionCreateTarget } from "./index"; export declare const TELEGRAM_ADOPTION_INTENT_VERSION = 2; export type TelegramAdoptionTarget = Extract; export declare const DEFAULT_ADOPTION_INTENT_TTL_MS: number; export interface AdoptionIntentFs { mkdir(directory: string, options: { recursive: true; mode: number; }): Promise; chmod(target: string, mode: number): Promise; readFile(file: string, encoding: "utf8"): Promise; writeFile(file: string, data: string, options: { mode: number; }): Promise; rename(from: string, to: string): Promise; unlink(file: string): Promise; readdir(directory: string): Promise; open(file: string, flags: string): Promise; } export interface AdoptionIntentFileHandle { sync(): Promise; close(): Promise; } /** Persisted before create; `sessionId` is added only by bindSession. */ export interface TelegramAdoptionIntent { readonly providerRequestKey: string; readonly topicId: number; readonly chatId: string; readonly target: TelegramAdoptionTarget; readonly createdAt: number; readonly expiresAt: number; readonly sessionId?: string; } export interface TelegramPendingTopic { readonly topicId: number; readonly chatId: string; readonly createdAt: number; readonly expiresAt: number; } export declare function adoptionIntentFilePath(agentDir: string, providerRequestKey: string): string; export declare function pendingTopicFilePath(agentDir: string, topicId: number): string; export declare function buildAdoptionIntent(input: { providerRequestKey: string; topicId: number; chatId: string; target: TelegramAdoptionTarget; now?: number; ttlMs?: number; }): TelegramAdoptionIntent; export declare const ADOPTION_INTENT_FILENAME_SUFFIX = ".adoption-intent.json"; export declare const PENDING_TOPIC_FILENAME_SUFFIX = ".pending-topic.json"; export declare class TelegramAdoptionIntentStore { #private; constructor(input: { agentDir: string; fs?: AdoptionIntentFs; now?: () => number; platform?: NodeJS.Platform; }); get directory(): string; byProviderRequestKey(providerRequestKey: string): TelegramAdoptionIntent | undefined; /** Only a post-create CAS binding makes a reservation visible by SessionId. */ bySession(sessionId: string): TelegramAdoptionIntent | undefined; byTopic(topicId: number): TelegramAdoptionIntent | undefined; hasNonExpiredTopic(topicId: number): boolean; pendingTopic(topicId: number): TelegramPendingTopic | undefined; hasPendingTopic(topicId: number, chatId: string): boolean; /** Synchronous fail-closed topic claim keyed by provider request identity. */ tryClaim(topicId: number, providerRequestKey: string): boolean; releaseClaim(topicId: number, providerRequestKey: string): void; put(intent: TelegramAdoptionIntent): Promise; /** CAS-bind the Broker-returned opaque SessionId exactly once. */ bindSession(providerRequestKey: string, sessionId: string): Promise; putPendingTopic(pendingTopic: TelegramPendingTopic): Promise; readIntent(providerRequestKey: string): Promise; readPendingTopic(topicId: number): Promise; rehydrate(): Promise; remove(providerRequestKey: string): Promise; removePendingTopic(topicId: number): Promise; sweepExpired(): Promise; }