/** * @license * Copyright 2025 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import { ITabularStorage } from "@workglow/storage"; import { EventEmitter, EventParameters } from "@workglow/util"; import type { DataPortSchemaObject } from "@workglow/util/schema"; import { ModelPrimaryKeyNames, ModelRecord, ModelRecordSchema } from "./ModelSchema"; export type ModelEventListeners = { model_added: (model: ModelRecord) => void; model_removed: (model: ModelRecord) => void; model_updated: (model: ModelRecord) => void; }; export type ModelEvents = keyof ModelEventListeners; export type ModelEventListener = ModelEventListeners[Event]; export type ModelEventParameters = EventParameters; /** * Base class for managing AI models and their relationships with tasks. */ export declare class ModelRepository { protected readonly modelTabularRepository: ITabularStorage; constructor(modelTabularRepository: ITabularStorage); protected events: EventEmitter; private compiledValidationSchema; /** * Returns the JSON schema used to validate model records before persistence. * Subclasses can override this to accept additional properties (for example, * owner/project IDs in repositories scoped to a user's workspace). */ protected getValidationSchema(): DataPortSchemaObject; /** * Validates a model record against {@link getValidationSchema}. * @throws if the record fails schema validation */ protected validateModelRecord(model: ModelRecord): void; /** * Sets up the database for the repository. * Must be called before using any other methods. */ setupDatabase(): Promise; on(name: Event, fn: ModelEventListener): void; off(name: Event, fn: ModelEventListener): void; once(name: Event, fn: ModelEventListener): void; waitOn(name: Event): Promise>; /** * Adds a new model to the repository. * Validates against the schema returned by {@link getValidationSchema} and rejects duplicates. * @param model - The model instance to add * @throws if the model fails schema validation or a model with the same model_id already exists */ addModel(model: ModelRecord): Promise; /** * Updates an existing model in the repository. * Validates against the schema returned by {@link getValidationSchema} and requires the model to already exist. * @param model - The model instance with updated fields * @throws if the model fails schema validation or the model_id does not exist */ updateModel(model: ModelRecord): Promise; /** * Removes a model from the repository * @param model_id - The model_id of the model to remove */ removeModel(model_id: string): Promise; findModelsByTask(task: string): Promise<{ capabilities: string[]; description: string; metadata: { [x: string]: unknown; }; model_id: string; provider: string; provider_config: { [x: string]: unknown; credential_key?: string | undefined; mrl?: boolean | undefined; native_dimensions?: number | undefined; }; title: string; }[] | undefined>; findTasksByModel(model_id: string): Promise; enumerateAllTasks(): Promise; enumerateAllModels(): Promise; findByName(model_id: string): Promise; size(): Promise; } //# sourceMappingURL=ModelRepository.d.ts.map