import { n as OpenClawConfig } from "./types-BrRP_qay.js";
import "./manifest-registry.types-DV1wX_0e.js";
import { a as OpenKeyedStoreOptions, o as PluginStateEntry, s as PluginStateKeyedStore, t as ChannelIngressQueue } from "./ingress-queue-fiz0xVBA.js";
import "./dangerous-name-matching-BGwAtdin.js";
import "./legacy-private-network-migration-zoexiq0w.js";
import { DatabaseSync } from "node:sqlite";
//#region src/plugin-state/plugin-state-store.sqlite.d.ts
type PluginDoctorRawStateEntry = Omit<PluginStateEntry<unknown>, "value" | "expiresAt"> & {
  valueJson: string;
  value?: unknown;
  expiresAt: number | null;
};
//#endregion
//#region src/plugins/doctor-contract-module.d.ts
type PluginDoctorStateMigrationDetection = {
  preview: string[];
};
type PluginDoctorStateMigrationContext = {
  openPluginStateKeyedStore: <T>(options: OpenKeyedStoreOptions) => PluginStateKeyedStore<T>;
  /** Doctor-only batch import preserving source age and remaining retention. */
  importPluginStateEntries?: (options: OpenKeyedStoreOptions, entries: readonly {
    key: string;
    value: unknown;
    createdAt: number;
    ttlMs?: number;
  }[]) => void;
  /** Plugin-wide live-row capacity for import preflight. Older test hosts may omit it. */
  getPluginStateCapacity?: () => {
    liveEntries: number;
    maxEntries: number;
  };
  readPluginStateEntriesInKeyRange?: (namespace: string, range: {
    prefix: string;
    after?: string;
    limit: number;
  }) => PluginDoctorRawStateEntry[];
  readSessionIdentityEvidenceBatch?: (requests: readonly {
    agentId: string;
    sessionId: string;
  }[]) => Promise<({
    agentId: string;
    sessionId: string;
    state: "current";
    sessionKey: string;
  } | {
    agentId: string;
    sessionId: string;
    state: "absent" | "unknown";
  })[]>;
  /** Present only while the host owns the offline SQLite maintenance lock. */
  deletePluginStateEntriesIfUnchanged?: (namespace: string, entries: readonly PluginDoctorRawStateEntry[]) => {
    deleted: number;
    changed: number;
  };
  /** Owner-bound ingress queue access, one entry per manifest-declared channel;
   *  the host fixes the channel identity and doctor state directory. Older test
   *  hosts may omit it. */
  channelIngressQueues?: readonly PluginDoctorChannelIngressQueueAccess[];
};
/** Read-only projection of a durable ingress queue. Detection runs before the host
    holds exclusive state ownership, so it is never handed anything wider. */
type PluginDoctorChannelIngressQueueInspection<TPayload, TMetadata = unknown> = Pick<ChannelIngressQueue<TPayload, TMetadata>, "listPending" | "listClaims" | "listFailed">;
/** Doctor access to one host-bound channel's durable ingress queues. It mirrors
 *  the runtime proxy's accessor, minus the state-dir override the host fixes. */
type PluginDoctorChannelIngressQueueAccess = {
  channelId: string;
  /** Inspection-only access, available in every phase including detection. */
  openChannelIngressQueueForInspection: <TPayload, TMetadata = unknown>(options?: {
    accountId?: string;
  }) => PluginDoctorChannelIngressQueueInspection<TPayload, TMetadata>;
  /** Account ids currently holding ingress rows, so migrations also sweep
   *  accounts retired from config. Async because detection resolves it through the
   *  non-creating read-only path. */
  listChannelIngressQueueAccountIds: () => Promise<string[]>;
  /** Present only while the host owns the exclusive Doctor maintenance lock. Every
   *  call re-asserts that authority, so a handle retained past the repair section
   *  fails instead of writing. */
  openChannelIngressQueue?: <TPayload, TMetadata = unknown, TCompletedMetadata = unknown>(options?: {
    accountId?: string;
  }) => ChannelIngressQueue<TPayload, TMetadata, TCompletedMetadata>;
};
type PluginDoctorStateMigrationInput = {
  config: OpenClawConfig;
  env: NodeJS.ProcessEnv;
  stateDir: string;
  oauthDir: string;
  context: PluginDoctorStateMigrationContext;
};
type PluginDoctorStateMigration = {
  id: string;
  label: string;
  /** Import retired file state only during explicit `doctor --fix` repair. */
  doctorOnly?: boolean;
  phase?: "after-session-repair";
  detectLegacyState: (params: PluginDoctorStateMigrationInput) => Promise<PluginDoctorStateMigrationDetection | null> | PluginDoctorStateMigrationDetection | null;
  migrateLegacyState: (params: PluginDoctorStateMigrationInput) => Promise<{
    changes: string[];
    warnings: string[];
    notices?: string[];
  }> | {
    changes: string[];
    warnings: string[];
    notices?: string[];
  };
};
//#endregion
export { PluginDoctorStateMigration as t };