import { AgentsManageDatabaseClient, ResolvedRef } from "@inkeep/agents-core";
import { Context, Next } from "hono";

//#region src/middleware/ref.d.ts
type RefContext = {
  resolvedRef?: ResolvedRef;
};
interface RefMiddlewareOptions {
  /**
   * Extract tenantId from the request context.
   * Default implementation extracts from path using /tenants/{tenantId} pattern.
   */
  extractTenantId?: (c: Context) => string | undefined;
  /**
   * Extract projectId from the request context.
   * Default implementation extracts from path using /tenants/{tenantId}/projects/{projectId} pattern.
   */
  extractProjectId?: (c: Context) => string | undefined;
  /**
   * Whether to allow extracting projectId from request body for POST/PUT/PATCH.
   * Default: true
   */
  allowProjectIdFromBody?: boolean;
  /**
   * Custom path patterns that should skip ref validation.
   * Default: []
   */
  skipRefValidationPaths?: RegExp[];
}
/**
 * Creates a ref resolution middleware factory.
 *
 * This middleware:
 * 1. Extracts tenantId and projectId from the request
 * 2. Resolves the `ref` query parameter to a ResolvedRef
 * 3. Creates branches if needed (tenant_main, project_main)
 * 4. Sets `resolvedRef` in the Hono context for downstream handlers
 *
 * @param db - The Doltgres database client to use for ref resolution
 * @param options - Optional configuration for extraction and validation
 * @returns Hono middleware function
 *
 * @example
 * ```typescript
 * import { createRefMiddleware } from '@inkeep/agents-core';
 * import { manageDbClient } from './db';
 *
 * const refMiddleware = createRefMiddleware(manageDbClient);
 * app.use('/tenants/*', refMiddleware);
 * ```
 */
declare const createRefMiddleware: (db: AgentsManageDatabaseClient, options?: RefMiddlewareOptions) => (c: Context, next: Next) => Promise<void>;
declare const writeProtectionMiddleware: (c: Context, next: Next) => Promise<void>;
declare const manageRefMiddleware: (c: Context, next: Next) => Promise<void>;
declare const runRefMiddleware: (c: Context, next: Next) => Promise<void>;
/**
 * Ref middleware for OAuth routes - extracts tenant/project from query params
 */
declare const oauthRefMiddleware: (c: Context, next: Next) => Promise<void>;
//#endregion
export { RefContext, RefMiddlewareOptions, createRefMiddleware, manageRefMiddleware, oauthRefMiddleware, runRefMiddleware, writeProtectionMiddleware };