import { SerializerProtocol } from "./serde/base.js";
import { CheckpointMetadata, CheckpointPendingWrite, DeltaChannelHistory, PendingWrite } from "./types.js";
import { RunnableConfig } from "@langchain/core/runnables";

//#region src/base.d.ts
/** @inline */
type ChannelVersion = number | string;
type ChannelVersions = Record<string, ChannelVersion>;
interface Checkpoint<N extends string = string, C extends string = string> {
  /**
   * The version of the checkpoint format. Currently 4
   */
  v: number;
  /**
   * Checkpoint ID {uuid6}
   */
  id: string;
  /**
   * Timestamp {new Date().toISOString()}
   */
  ts: string;
  /**
   * @default {}
   */
  channel_values: Record<C, unknown>;
  /**
   * @default {}
   */
  channel_versions: Record<C, ChannelVersion>;
  /**
   * @default {}
   */
  versions_seen: Record<N, Record<C, ChannelVersion>>;
}
interface ReadonlyCheckpoint extends Readonly<Checkpoint> {
  readonly channel_values: Readonly<Record<string, unknown>>;
  readonly channel_versions: Readonly<Record<string, ChannelVersion>>;
  readonly versions_seen: Readonly<Record<string, Readonly<Record<string, ChannelVersion>>>>;
}
declare function deepCopy<T>(obj: T): T;
/** @hidden */
declare function emptyCheckpoint(): Checkpoint;
/** @hidden */
declare function copyCheckpoint(checkpoint: ReadonlyCheckpoint): Checkpoint;
interface CheckpointTuple {
  config: RunnableConfig;
  checkpoint: Checkpoint;
  metadata?: CheckpointMetadata;
  parentConfig?: RunnableConfig;
  pendingWrites?: CheckpointPendingWrite[];
}
type CheckpointListOptions = {
  limit?: number;
  before?: RunnableConfig;
  filter?: Record<string, any>;
};
declare abstract class BaseCheckpointSaver<V extends string | number = number> {
  serde: SerializerProtocol;
  constructor(serde?: SerializerProtocol);
  /**
   * Prevent `JSON.stringify` from traversing backend clients (e.g. pg Pool
   * timers) when a checkpointer is present in runnable `configurable`.
   */
  toJSON(): string;
  get(config: RunnableConfig): Promise<Checkpoint | undefined>;
  abstract getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
  abstract list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
  abstract put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata, newVersions: ChannelVersions): Promise<RunnableConfig>;
  /**
   * Store intermediate writes linked to a checkpoint.
   */
  abstract putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
  /**
   * Delete all checkpoints and writes associated with a specific thread ID.
   * @param threadId The thread ID whose checkpoints should be deleted.
   */
  abstract deleteThread(threadId: string): Promise<void>;
  /**
   * Walk the parent chain returning per-channel writes + seed, used to
   * reconstruct `DeltaChannel` state from `checkpoint_writes`.
   *
   * For each requested channel, walks ancestors of the checkpoint identified
   * by `config` (following `parentConfig`) and accumulates the pending writes
   * for that channel. The walk terminates per-channel at the nearest ancestor
   * whose `channel_values[ch]` is populated; that value is returned as `seed`.
   * If the walk reaches the root without finding a stored value, `seed` is
   * omitted from that channel's entry — the consumer treats the absence as
   * "start empty".
   *
   * Walks the parent chain (not `list({ before })`): for forked threads, only
   * on-path ancestors contribute.
   *
   * The default implementation walks `getTuple` + `parentConfig` once for all
   * channels — each ancestor visited once, not once per channel. Savers with
   * direct storage access (e.g. `MemorySaver`) override for performance; the
   * return contract is fixed here.
   *
   * @remarks Beta. The signature, return shape, and interaction with
   * `DeltaSnapshot` blobs may change. Override at your own risk; the default
   * implementation will continue to work against the public
   * `BaseCheckpointSaver` contract.
   *
   * @param options.config Configuration identifying the target checkpoint.
   * @param options.channels Channel names to walk for. Empty → empty mapping.
   * @returns Per-channel {@link DeltaChannelHistory} for every requested name.
   */
  getDeltaChannelHistory(options: {
    config: RunnableConfig;
    channels: string[];
  }): Promise<Record<string, DeltaChannelHistory>>;
  /**
   * Generate the next version ID for a channel.
   *
   * Default is to use integer versions, incrementing by 1. If you override, you can use str/int/float versions,
   * as long as they are monotonically increasing.
   */
  getNextVersion(current: V | undefined): V;
}
declare function compareChannelVersions(a: ChannelVersion, b: ChannelVersion): number;
declare function maxChannelVersion(...versions: ChannelVersion[]): ChannelVersion;
/**
 * Mapping from error type to error index.
 * Regular writes just map to their index in the list of writes being saved.
 * Special writes (e.g. errors) map to negative indices, to avoid those writes from
 * conflicting with regular writes.
 * Each Checkpointer implementation should use this mapping in put_writes.
 */
declare const WRITES_IDX_MAP: Record<string, number>;
/**
 * Metadata keys that are LangGraph's internal framework bookkeeping and
 * should not be surfaced as user-meaningful metadata.
 *
 * Consumed by stream handlers (e.g. the `tasks` debug stream) to drop
 * framework keys — which are redundant with a task's own fields and
 * namespace — while keeping keys like `lc_agent_name`, `ls_integration`,
 * and user-supplied metadata.
 */
declare const EXCLUDED_METADATA_KEYS: ReadonlySet<string>;
declare function getCheckpointId(config: RunnableConfig): string;
//#endregion
export { BaseCheckpointSaver, ChannelVersions, Checkpoint, CheckpointListOptions, CheckpointTuple, EXCLUDED_METADATA_KEYS, ReadonlyCheckpoint, WRITES_IDX_MAP, compareChannelVersions, copyCheckpoint, deepCopy, emptyCheckpoint, getCheckpointId, maxChannelVersion };
//# sourceMappingURL=base.d.ts.map