import { ResolvedRef } from "../validation/dolt-schemas.js"; import { AgentsManageDatabaseClient } from "../db/manage/manage-client.js"; import { Context, Next } from "hono"; //#region src/dolt/ref-middleware.d.ts declare function isMergeRoute(path: string): boolean; 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; /** * Creates a write protection middleware that prevents write operations on immutable refs. * * This middleware checks if the resolved ref is writable (branches are writable, * tags and commits are not) and rejects write operations on immutable refs. * * @returns Hono middleware function * * @example * ```typescript * import { createRefMiddleware, createWriteProtectionMiddleware } from '@inkeep/agents-core'; * * const refMiddleware = createRefMiddleware(db); * const writeProtection = createWriteProtectionMiddleware(); * * app.use('/tenants/*', refMiddleware, writeProtection); * ``` */ declare const createWriteProtectionMiddleware: () => (c: Context, next: Next) => Promise; /** * @deprecated Use createRefMiddleware instead. This is kept for backwards compatibility. */ declare const refMiddlewareFactory: (db: AgentsManageDatabaseClient, options?: RefMiddlewareOptions) => (c: Context, next: Next) => Promise; /** * @deprecated Use createWriteProtectionMiddleware instead. This is kept for backwards compatibility. */ declare const writeProtectionMiddlewareFactory: () => (c: Context, next: Next) => Promise; //#endregion export { RefContext, RefMiddlewareOptions, createRefMiddleware, createWriteProtectionMiddleware, isMergeRoute, refMiddlewareFactory, writeProtectionMiddlewareFactory };