import type { ApiServer } from '../ApiServer'; import type { SolidAuthContext } from '../auth/AuthContext'; import type { PodLookupRepository } from '../../identity/drizzle/PodLookupRepository'; import { EmbeddingModelPolicy } from '../../ai/service/EmbeddingModelPolicy'; export type AiConfigModelAssignment = 'chatModel' | 'ocrModel' | 'readerModel' | 'embeddingModel' | 'indexerModel' | 'rerankerModel'; export interface AiConfigPolicy { schemaVersion: '1.0'; models: Partial>; documentProcessing: { ocrEnabled: boolean; automaticOcr: boolean; imageRecognition: boolean; pdfRecognition: boolean; tableRecognition: boolean; processingMode: 'auto' | 'on-demand'; ocrFallbackOrder: Array<'ocr' | 'reader' | 'plain-text'>; readerPolicy: 'auto' | 'always' | 'disabled'; readerPriority: 'structure-first' | 'speed-first'; maxFileSizeMb: number; maxPages: number; failureFallback: 'plain-text' | 'skip'; }; searchIndexing: { ftsEnabled: boolean; vectorEnabled: boolean; progressiveIndexingEnabled: boolean; textBackend: 'auto' | 'fts5' | 'postgres-fts'; vectorBackend: 'auto' | 'vec' | 'pgvector'; }; lifecycle: { automaticIndexing: boolean; refreshAfterSourceUpdate: boolean; removeAfterSourceDeletion: boolean; }; updatedAt?: string; } export type AiConfigPolicyPatch = { models?: Partial>; documentProcessing?: Partial; searchIndexing?: Partial; lifecycle?: Partial; }; export interface AiConfigCapabilities { textBackends: Array<'fts5' | 'postgres-fts'>; vectorBackends: Array<'vec' | 'pgvector'>; rebuildSupported: boolean; rebuildTargets?: AiConfigRebuildTarget[]; } export type AiConfigRebuildTarget = 'fts' | 'vector' | 'all'; export type AiConfigRebuildStatus = 'queued' | 'running' | 'succeeded' | 'failed'; export interface AiConfigRebuildJob { id: string; target: AiConfigRebuildTarget; status: AiConfigRebuildStatus; createdAt: string; startedAt?: string; completedAt?: string; progress?: number; error?: string; } export interface AiConfigLifecycleSnapshot { configurationVersion?: string; pending: number; recent: AiConfigRebuildJob[]; } export interface AiConfigOwner { webId: string; podUrl: string; /** The verified caller context is used only for the current Pod read/write. */ auth?: SolidAuthContext; } export interface AiConfigLifecycleService { supportedTargets(): AiConfigRebuildTarget[]; status(owner: AiConfigOwner): Promise; schedule(input: AiConfigOwner & { target: AiConfigRebuildTarget; }): Promise; } export interface AiConfigPolicyStore { read(input: { webId: string; podUrl: string; auth?: SolidAuthContext; }): Promise; update(input: { webId: string; podUrl: string; patch: AiConfigPolicyPatch; auth?: SolidAuthContext; }): Promise; } export interface AiConfigHandlerOptions { podLookupRepository: Pick; store: AiConfigPolicyStore; capabilities?: () => AiConfigCapabilities; lifecycle?: AiConfigLifecycleService; /** * Deployment policy for embedding assignments. Local runtimes allow any model; * Cloud runtimes only accept models the ai-gateway catalog provides. */ embeddingModelPolicy?: EmbeddingModelPolicy; } export declare function registerAiConfigRoutes(server: ApiServer, options: AiConfigHandlerOptions): void;