// src/models/ai-provider.ts // Copyright (C) 2026 Robert Colbert // All Rights Reserved import { Schema, model } from "mongoose"; import { IAiModel, IAiModelCapabilities, IAiModelSettings, IAiProvider, } from "@gadget/api"; export const AiModelCapabilitiesSchema = new Schema( { canCallTools: { type: Boolean, default: false }, hasVision: { type: Boolean, default: false }, hasEmbedding: { type: Boolean, default: false }, hasThinking: { type: Boolean, default: false }, isInstructTuned: { type: Boolean, default: false }, }, { _id: false }, ); export const AiModelSettingsSchema = new Schema( { temperature: { type: Number }, topP: { type: Number }, topK: { type: Number }, numCtx: { type: Number }, }, { _id: false }, ); export const AiModelSchema = new Schema( { id: { type: String, required: true }, name: { type: String, required: true }, parameterCount: { type: Number }, parameterLabel: { type: String }, contextWindow: { type: Number }, capabilities: { type: AiModelCapabilitiesSchema, default: () => ({ canCallTools: false, hasVision: false, hasEmbedding: false, hasThinking: false, isInstructTuned: false, }), }, settings: { type: AiModelSettingsSchema, default: undefined, }, }, { _id: false }, ); export const AiProviderSchema = new Schema({ name: { type: String, required: true }, apiType: { type: String, enum: ["ollama", "openai"], required: true }, baseUrl: { type: String, required: true }, apiKey: { type: String, required: false, select: false, default: "" }, enabled: { type: Boolean, default: true, required: true }, models: { type: [AiModelSchema], default: [], required: true }, lastModelRefresh: { type: Date, default: Date.now }, }); AiProviderSchema.index({ name: 1 }, { unique: true }); export const AiProvider = model("AiProvider", AiProviderSchema); export default AiProvider;