import type { SpeechBinding, SpeechConfigurationReference, SpeechTarget } from '@sentropic/llm-mesh'; import type { CostContext } from '../ports/cost-context.js'; import { type SpeechPrice, type SpeechUsage, type SpeechUsageState } from './usage.js'; import type { SpeechSettlementEntry } from './settlement.js'; export declare const SPEECH_DAILY_MICRO_USD = 5000000; export declare const SPEECH_CAMPAIGN_MICRO_USD = 20000000; export interface SpeechOperation { readonly operationId: string; readonly sessionId: string; readonly attemptId: string; readonly backendOperationRef: string; readonly nativeTurnRef?: string; readonly submitKey: string; readonly coordinatorEpoch: number; readonly allocatorReceiptRef: string; readonly stage: 'stt' | 'tts' | 'duplex'; readonly cost: CostContext; readonly binding: SpeechBinding & { readonly accountRef: string; readonly region: string; }; readonly configuration: SpeechConfigurationReference; readonly target: SpeechTarget; readonly ceiling: SpeechUsage; readonly maxDurationMs: number; readonly maxConcurrent: number; } export interface SpeechAllocatorReceipt { readonly receiptRef: string; readonly tenantId: string; readonly workspaceId?: string; readonly principalId: string; readonly targetSessionId: string; readonly nativeTurnRef?: string; readonly submitKey: string; readonly coordinatorEpoch: number; readonly countedUnits: 0 | 1; readonly backendOperationRef: string; } export interface SpeechHold { operation: SpeechOperation; campaignRef: string; utcDay: string; price: SpeechPrice; liabilityMicroUsd: number; expiresAtMs: number; dispatched: boolean; state: 'reserved' | 'estimated' | 'settled'; chargedMicroUsd: number; settlementRevision: number; rootEntryRef?: string; providerRevision?: number; usage?: SpeechUsageState; settledUsage?: SpeechUsage; settledOutcome?: SpeechSettlementEntry['outcome']; } export interface SpeechBudgetSnapshot { readonly spentMicroUsd: number; readonly reservedMicroUsd: number; } /** Views over existing owner tables, not a second speech ledger or quota counter. */ export interface SpeechLedgerTransaction { /** Acquire owner locks for hold + all budget buckets in the owner's common lock order. */ lock(campaignRef: string, operationId: string, utcDay: string): Promise; getHold(operationId: string): Promise; /** Persists in existing budget_holds; retains the pool lease while reserved and dispatched. */ putHold(hold: SpeechHold): Promise; budgets(campaignRef: string, utcDay: string): Promise<{ daily: SpeechBudgetSnapshot; campaign: SpeechBudgetSnapshot; }>; /** Update the SAME owner buckets used by admission, settlement and reaping, including tighter policies. */ adjustBudgets(campaignRef: string, utcDay: string, reservedDelta: number, spentDelta: number): Promise; allocatorReceipt(receiptRef: string): Promise; price(binding: SpeechOperation['binding'], nowMs: number): Promise; /** Existing pool admission/lease count; expired but unreconciled holds must retain budget liability. */ activeConnections(accountRef: string, nowMs: number): Promise; appendSettlement(entry: SpeechSettlementEntry): Promise; } export interface SpeechLedgerPort { readonly durability: 'durable'; /** Atomic commit/rollback, serializable across processes and restarts, using the established ledger DB. */ transaction(change: (tx: SpeechLedgerTransaction) => Promise): Promise; } export interface SpeechAccountingOptions { /** Trusted host campaign identity, shared across providers, accounts, reconnects and retries. */ readonly campaignRef: string; readonly ledger?: SpeechLedgerPort; readonly now?: () => number; readonly dailyCapMicroUsd?: number; readonly campaignCapMicroUsd?: number; } export declare class SpeechAccountingError extends Error { readonly code: 'unavailable' | 'cap' | 'invalid' | 'conflict' | 'allocator' | 'expired' | 'concurrency'; constructor(code: 'unavailable' | 'cap' | 'invalid' | 'conflict' | 'allocator' | 'expired' | 'concurrency'); } export declare const speechTransaction: (options: SpeechAccountingOptions, change: (tx: SpeechLedgerTransaction, nowMs: number, campaignRef: string) => Promise) => Promise; export declare const utcSpeechDay: (nowMs: number) => string; export declare const sameSpeechIdentity: (a: unknown, b: unknown) => boolean; /** Called only with auth-derived CostContext and the server's selected configuration/engine bounds. */ export declare const admitSpeech: (options: SpeechAccountingOptions, input: SpeechOperation) => Promise; /** Durable, one-shot dispatch claim. An ambiguous acknowledgement never allows replay. */ export declare const markSpeechDispatched: (options: SpeechAccountingOptions, operationId: string) => Promise; //# sourceMappingURL=admission.d.ts.map