import type { HistorySource } from './source-contracts.js'; /** Portable export/delivery wire types. Field names match the versioned Rust contract. */ export type HistoryEvidenceKind = 'history' | 'session_event' | 'tool_call' | 'file_edit' | 'session' | 'presence' | 'relationship' | 'commit_link' | 'source_observation' | 'observation_evidence' | 'session_marker'; export interface HistorySessionIdentity { source: string; session_id: string; } export interface HistoryExportSelection { all_sources: boolean; sources: string[]; sessions: HistorySessionIdentity[]; kinds: HistoryEvidenceKind[]; excluded_sessions: HistorySessionIdentity[]; } export interface DeliveryLimits { max_batch_records: number; max_batch_bytes: number; max_scan_records: number; max_prepared_bytes: number; } export declare const DEFAULT_DELIVERY_LIMITS: Readonly; export interface DeliveryJobConfig { destination_id: string; instance_id: string; account_id: string; mapping_version: string; selection: HistoryExportSelection; limits: DeliveryLimits; } export interface HistoryExportRecord { schema_version: number; origin_id: string; record_id: string; revision_id: string; revision: number; kind: HistoryEvidenceKind; source: string; session_id: string | null; operation: 'upsert' | 'delete'; /** Original stored fields, timestamps, and raw evidence strings; null for tombstones. */ payload: unknown; } export interface HistoryExportBatch { schema_version: number; origin_id: string; batch_id: string; job_id: string; generation: number; destination_id: string; instance_id: string; account_id: string; mapping_version: string; records: HistoryExportRecord[]; } export interface DeliveryLease { job_id: string; batch_id: string; worker_id: string; fence: number; expires_at_ms: number; } export interface PreparedHistoryPayload { mapping_version: string; content_type: string; body: string; sha256: string; } export interface ClaimedHistoryBatch { lease: DeliveryLease; batch: HistoryExportBatch; prepared: PreparedHistoryPayload | null; } export interface DeliveryAcknowledgment { batch_id: string; accepted_revision_ids: string[]; unsupported_revision_ids: string[]; /** A receipt for future processing is not durable acceptance. */ acceptance_level: 'durable' | 'indexed'; } /** A 409 `delivery_conflict` is actionable only when the receiver identifies * the exact submitted and comparison identities that disagree. The comparison * is either durable or an earlier identity in the same submitted batch. The * authenticated tenant is intentionally absent: transport authentication, * not an error body, establishes that scope. */ export interface DeliveryRecordRevisionConflict { type: 'record_revision'; originId: string; recordId: string; submittedRevisionId: string; submittedRevision: number; submittedDigest: string; currentRevisionId: string; currentRevision: number; currentDigest: string; } export interface DeliveryBatchIdConflict { type: 'batch_id'; originId: string; batchId: string; submittedDigest: string; currentDigest: string; } export type DeliveryConflict = DeliveryRecordRevisionConflict | DeliveryBatchIdConflict; export interface DeliveryConflictResponse { error: ({ code: 'delivery_conflict'; message: string; } & ({ conflict: DeliveryRecordRevisionConflict; /** First bounded page of conflicts in deterministic order. */ conflicts: DeliveryRecordRevisionConflict[]; /** Total conflicts, including any beyond the bounded list. */ conflictCount: number; } | { conflict: DeliveryBatchIdConflict; })); /** Receiver-generated diagnostic only; never part of conflict identity. */ correlationId?: string; } export interface DeliveryConflictRecovery { /** Records that may be skipped only because the receiver proved their exact * identity and submitted digest conflicted. Empty for batch-ID reuse. */ quarantinedRevisionIds: string[]; /** A deterministic retry with a new batch identity, or null when the only * submitted record was quarantined. */ retryBatch: HistoryExportBatch | null; } export type DeliveryFailure = 'transient' | 'rate_limited' | 'authentication_required' | 'permission_denied' | 'invalid_payload' | 'unsupported_evidence' | 'mapping_version_mismatch' | 'delivery_conflict'; export interface DeliveryStatus { job_id: string; config: DeliveryJobConfig; generation: number; state: 'active' | 'paused' | 'blocked' | 'cancelled'; bootstrap_complete: boolean; journal_cursor: number; acknowledged_cursor: number; pending_records: number; pending_bytes: number; oldest_pending_ms: number | null; unqueued_changes: number; next_attempt_ms: number; last_attempt_ms: number | null; last_acknowledged_ms: number | null; acceptance_level: 'durable' | 'indexed' | null; failure: DeliveryFailure | null; suppressed_records: number; acknowledged_records: number; } export interface DeliveryPrepareResult { batch_id: string | null; scanned_records: number; bootstrap_complete: boolean; } /** Destination implementations are trusted application code, not a sandbox. */ export interface HistoryDestination { id: string; mappingVersion: string; /** 'none' honestly allows duplicate remote effects after uncertain outcomes. */ idempotency: 'revision' | 'none'; /** Required: the receiver must reject stale revisions or apply them in order. */ orderedRevisions: true; supportedKinds: readonly HistoryEvidenceKind[]; supportsTombstones: boolean; /** Pure payload mapping. Never include credentials in the persisted body. */ prepare(batch: Readonly, context: { signal: AbortSignal; }): Promise<{ content_type: string; body: string; }>; /** Send precisely the stored body. Authentication headers may rotate. Verify * the remote account matches batch.account_id before writing. Do not launch * interactive login; report authentication_required when user action is needed. */ send(payload: Readonly, context: { signal: AbortSignal; batch: Readonly; idempotencyKey: string; }): Promise; } export interface HistoryPlugin { sources?: readonly HistorySource[]; destinations?: ReadonlyArray<{ instanceId: string; destination: HistoryDestination; }>; } //# sourceMappingURL=delivery-contracts.d.ts.map