Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

add local models UI

Forhad Hosain29e25a2592c3
diff --git a/packages/app/src/react/features/vault/components/create-local-model-modal.tsx b/packages/app/src/react/features/vault/components/create-local-model-modal.tsx
new file mode 100644
index 00000000..49290e30
--- /dev/null
+++ b/packages/app/src/react/features/vault/components/create-local-model-modal.tsx
@@ -0,0 +1,263 @@
+import {
+ Dialog,
+ DialogContent,
+ DialogHeader,
+ DialogTitle,
+} from '@src/react/shared/components/ui/dialog';
+import { Input } from '@src/react/shared/components/ui/input';
+import { Label } from '@src/react/shared/components/ui/label';
+import ConfirmModal from '@src/react/shared/components/ui/modals/ConfirmModal';
+import { Button as CustomButton } from '@src/react/shared/components/ui/newDesign/button';
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from '@src/react/shared/components/ui/select';
+import { Spinner } from '@src/react/shared/components/ui/spinner';
+import { LLMRegistry } from '@src/shared/services/LLMRegistry.service';
+import React, { useEffect, useState } from 'react';
+import type { LocalModel } from '../types/types';
+
+interface CreateLocalModelModalProps {
+ isOpen: boolean;
+ onClose: () => void;
+ onSubmit: (data: Omit<LocalModel, 'id'>) => void;
+ editModel?: LocalModel;
+ isProcessing: boolean;
+}
+
+export function CreateLocalModelModal({
+ isOpen,
+ onClose,
+ onSubmit,
+ editModel,
+ isProcessing,
+}: CreateLocalModelModalProps) {
+ const [formData, setFormData] = useState({
+ name: '',
+ modelId: '',
+ baseUrl: '',
+ fallbackLLM: '',
+ });
+
+ // Get available fallback models from LLMRegistry (same as Default LLM section)
+ const TEMP_BADGES = {
+ enterprise: true,
+ smythos: true,
+ personal: true,
+ limited: true,
+ };
+
+ const getTempBadge = (tags: string[]) => {
+ return tags.filter((tag) => TEMP_BADGES?.[tag?.toLowerCase()]).join(' ');
+ };
+
+ const fallbackOptions = LLMRegistry.getSortedModelsByFeatures('tools').map((model) => {
+ let badge = getTempBadge(model.tags);
+ badge = badge ? ' (' + badge + ')' : '';
+ return {
+ id: model.entryId,
+ name: model.label + badge, // Add tags like "(Personal)" as shown in Default LLM section
+ };
+ });
+
+ useEffect(() => {
+ if (editModel) {
+ setFormData({
+ name: editModel.name,
+ modelId: editModel.modelId,
+ baseUrl: editModel.baseUrl,
+ fallbackLLM: editModel.fallbackLLM,
+ });
+ } else {
+ setFormData({
+ name: '',
+ modelId: '',
+ baseUrl: '',
+ fallbackLLM: '',
+ });
+ }
+ }, [editModel, isOpen]);
+
+ const handleSubmit = (e: React.FormEvent) => {
+ e.preventDefault();
+
+ if (
+ !formData.name.trim() ||
+ !formData.modelId.trim() ||
+ !formData.baseUrl.trim() ||
+ !formData.fallbackLLM.trim()
+ ) {
+ return;
+ }
+
+ onSubmit(formData);
+ };
+
+ const handleInputChange = (field: string, value: string) => {
+ setFormData((prev) => ({
+ ...prev,
+ [field]: value,
+ }));
+ };
+
+ const isFormValid =
+ formData.name.trim() &&
+ formData.modelId.trim() &&
+ formData.baseUrl.trim() &&
+ formData.fallbackLLM.trim();
+
+ return (
+ <Dialog
+ open={isOpen}
+ onOpenChange={(open) => {
+ if (!open && !isProcessing) {
+ onClose();
+ }
+ }}
+ >
+ <DialogContent className="sm:max-w-[600px] max-h-[90vh] overflow-y-auto">
+ <DialogHeader>
+ <DialogTitle className="text-xl text-[#1E1E1E]">
+ {editModel ? 'Edit Local Model' : 'Setup Local Model'}
+ </DialogTitle>
+ </DialogHeader>
+ <form onSubmit={handleSubmit} className="space-y-4">
+ <div className="space-y-2">
+ <Label htmlFor="name" className="text-base font-normal mr-2 text-[#1E1E1E]">
+ Name <span className="text-red-500">*</span>
+ </Label>
+ <Input
+ id="name"
+ type="text"
+ value={formData.name}
+ onChange={(e) => handleInputChange('name', e.target.value)}
+ placeholder="Local Model example v1.3"
+ fullWidth
+ className="w-full"
+ />
+ </div>
+
+ <div className="space-y-2">
+ <Label htmlFor="modelId" className="text-base font-normal mr-2 text-[#1E1E1E]">
+ Model ID <span className="text-red-500">*</span>
+ </Label>
+ <Input
+ id="modelId"
+ type="text"
+ value={formData.modelId}
+ onChange={(e) => handleInputChange('modelId', e.target.value)}
+ placeholder="qwen2.5-7b-instruct-1m"
+ fullWidth
+ className="w-full"
+ />
+ </div>
+
+ <div className="space-y-2">
+ <Label htmlFor="baseUrl" className="text-base font-normal mr-2 text-[#1E1E1E]">
+ Base URL <span className="text-red-500">*</span>
+ </Label>
+ <Input
+ id="baseUrl"
+ type="url"
+ value={formData.baseUrl}
+ onChange={(e) => handleInputChange('baseUrl', e.target.value)}
+ placeholder="https://api.smythos.com/example"
+ fullWidth
+ className="w-full"
+ />
+ </div>
+
+ <div className="space-y-2">
+ <Label htmlFor="fallbackLLM">
+ Fallback Model <span className="text-red-500">*</span>
+ </Label>
+ <p className="text-xs text-gray-500">
+ Select a model from the same options available in Default LLM settings
+ </p>
+ <Select
+ value={formData.fallbackLLM}
+ onValueChange={(value) => handleInputChange('fallbackLLM', value)}
+ >
+ <SelectTrigger>
+ <SelectValue placeholder="Select a model" />
+ </SelectTrigger>
+ <SelectContent>
+ {fallbackOptions.map((model) => (
+ <SelectItem key={model.id} value={model.id}>
+ {model.name}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </div>
+
+ <div className="flex justify-between gap-4 pt-4">
+ <CustomButton
+ type="button"
+ variant="secondary"
+ handleClick={onClose}
+ disabled={isProcessing}
+ className="flex-1"
+ label="Cancel"
+ />
+ <CustomButton
+ className="flex-1"
+ type="submit"
+ variant="primary"
+ disabled={!isFormValid || isProcessing}
+ addIcon={isProcessing}
+ Icon={<Spinner size="sm" />}
+ label={
+ isProcessing
+ ? editModel
+ ? 'Updating...'
+ : 'Creating...'
+ : editModel
+ ? 'Update Model'
+ : 'Create Model'
+ }
+ />
+ </div>
+ </form>
+ </DialogContent>
+ </Dialog>
+ );
+}
+
+interface DeleteLocalModelModalProps {
+ isOpen: boolean;
+ onClose: () => void;
+ onConfirm: () => void;
+ model?: LocalModel;
+ isProcessing: boolean;
+}
+
+export function DeleteLocalModelModal({
+ isOpen,
+ onClose,
+ onConfirm,
+ model,
+ isProcessing,
+}: DeleteLocalModelModalProps) {
+ if (!model) return null;
+
+ if (!isOpen) {
+ return null;
+ }
+
+ return (
+ <ConfirmModal
+ onClose={onClose}
+ label={isProcessing ? 'Deleting...' : 'Delete'}
+ handleConfirm={onConfirm}
+ message="Delete Local Model"
+ lowMsg={`Are you sure you want to delete the local model "${model.name}"? This action cannot be undone.`}
+ isLoading={isProcessing}
+ width="max-w-[600px] w-[calc(100vw_-_-20px)]"
+ confirmBtnClasses="bg-red-600 hover:bg-red-700 text-white"
+ />
+ );
+}
diff --git a/packages/app/src/react/features/vault/components/local-models.tsx b/packages/app/src/react/features/vault/components/local-models.tsx
new file mode 100644
index 00000000..151d1aa1
--- /dev/null
+++ b/packages/app/src/react/features/vault/components/local-models.tsx
@@ -0,0 +1,246 @@
+import { Button } from '@src/react/shared/components/ui/button';
+import { Button as CustomButton } from '@src/react/shared/components/ui/newDesign/button';
+import { errorToast, successToast } from '@src/shared/components/toast';
+import { Tooltip } from 'flowbite-react';
+import { Info, Pencil, PlusCircle, Trash2 } from 'lucide-react';
+import { useState } from 'react';
+import {
+ useCreateLocalModel,
+ useDeleteLocalModel,
+ useLocalModels,
+ useUpdateLocalModel,
+} from '../hooks/use-vault';
+import type { LocalModel } from '../types/types';
+import { CreateLocalModelModal, DeleteLocalModelModal } from './create-local-model-modal';
+
+export function LocalModels({ pageAccess }: { pageAccess: { write: boolean } }) {
+ const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
+ const [editingModel, setEditingModel] = useState<LocalModel | undefined>();
+ const [isProcessing, setIsProcessing] = useState(false);
+ const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
+ const [modelToDelete, setModelToDelete] = useState<LocalModel | undefined>();
+
+ // Fetch models
+ const { data: models = [], isLoading, error } = useLocalModels();
+
+ // Mutations
+ const createModel = useCreateLocalModel();
+ const updateModel = useUpdateLocalModel();
+ const deleteModel = useDeleteLocalModel();
+
+ const handleCreateModel = async (data: Omit<LocalModel, 'id'>) => {
+ // Check for duplicate names (case-insensitive)
+ const existingModel = models.find(
+ (model) =>
+ model.name.toLowerCase() === data.name.toLowerCase() &&
+ // When editing, exclude the current model from duplicate check
+ (!editingModel || model.id !== editingModel.id),
+ );
+
+ if (existingModel) {
+ errorToast('A local model with this name already exists. Please choose a different name.');
+ return;
+ }
+
+ setIsProcessing(true);
+ try {
+ await createModel.mutateAsync(data);
+ successToast('Local model created successfully');
+ setIsCreateModalOpen(false);
+ } catch (error) {
+ console.error('Error creating local model:', error);
+ errorToast('Failed to create local model');
+ } finally {
+ setIsProcessing(false);
+ }
+ };
+
+ const handleUpdateModel = async (data: Omit<LocalModel, 'id'>) => {
+ if (!editingModel) return;
+
+ // Check for duplicate names (case-insensitive)
+ const existingModel = models.find(
+ (model) =>
+ model.name.toLowerCase() === data.name.toLowerCase() &&
+ // When editing, exclude the current model from duplicate check
+ model.id !== editingModel.id,
+ );
+
+ if (existingModel) {
+ errorToast('A local model with this name already exists. Please choose a different name.');
+ return;
+ }
+
+ setIsProcessing(true);
+ try {
+ await updateModel.mutateAsync({
+ modelId: editingModel.id,
+ updatedFields: data,
+ });
+ successToast('Local model updated successfully');
+ setEditingModel(undefined);
+ } catch (error) {
+ console.error('Error updating local model:', error);
+ errorToast('Failed to update local model');
+ } finally {
+ setIsProcessing(false);
+ }
+ };
+
+ const handleDeleteModel = async () => {
+ if (!modelToDelete) return;
+
+ setIsProcessing(true);
+ try {
+ await deleteModel.mutateAsync({ modelId: modelToDelete.id });
+ successToast('Local model deleted successfully');
+ setIsDeleteModalOpen(false);
+ setModelToDelete(undefined);
+ } catch (error) {
+ console.error('Error deleting local model:', error);
+ errorToast('Failed to delete local model');
+ } finally {
+ setIsProcessing(false);
+ }
+ };
+
+ const handleEditModel = (model: LocalModel) => {
+ setEditingModel(model);
+ };
+
+ const handleDeleteClick = (model: LocalModel) => {
+ setModelToDelete(model);
+ setIsDeleteModalOpen(true);
+ };
+
+ const handleCloseCreateModal = () => {
+ setIsCreateModalOpen(false);
+ };
+
+ const handleCloseEditModal = () => {
+ setEditingModel(undefined);
+ };
+
+ const handleCloseDeleteModal = () => {
+ setIsDeleteModalOpen(false);
+ setModelToDelete(undefined);
+ };
+
+ if (error) {
+ return (
+ <div className="rounded-lg border border-red-200 bg-red-50 p-4">
+ <div className="flex items-center gap-2 text-red-800">
+ <Info className="h-4 w-4" />
+ <span className="font-medium">Error loading local models</span>
+ </div>
+ <p className="mt-1 text-sm text-red-600">
+ {error instanceof Error ? error.message : 'An unexpected error occurred'}
+ </p>
+ </div>
+ );
+ }
+
+ return (
+ <div className="w-full p-6 rounded-lg border border-solid border-[#d9d9d9] flex-col justify-start items-start gap-3 flex">
+ <div className="flex items-center gap-3">
+ <div className="flex items-center gap-2 self-stretch text-[#1e1e1e] text-lg font-semibold font-['Inter'] leading-snug">
+ Local Models
+ <Tooltip
+ className="w-72 text-center"
+ content="Local models allow you to connect to your own LLM instances running locally or on your infrastructure"
+ >
+ <Info className="w-4 h-4" />
+ </Tooltip>
+ </div>
+ </div>
+
+ <div className="w-full space-y-4">
+ {isLoading ? (
+ <div className="py-4 text-center text-gray-500">Loading models...</div>
+ ) : (
+ <>
+ {models.length === 0 ? (
+ <div className="py-4 text-center text-gray-500">No local models found</div>
+ ) : (
+ <div className="overflow-x-auto">
+ <div className="min-w-[500px]">
+ {models.map((model) => (
+ <div key={model.id} className="flex items-center justify-between">
+ <div className="flex items-center gap-2">
+ <span className="inline-flex h-5 items-center rounded-md bg-blue-100 px-2 text-xs font-medium text-blue-800">
+ Local
+ </span>
+ <span className="font-medium text-[#374151] max-w-[200px] truncate">
+ {model.name}
+ </span>
+ <span className="inline-flex h-5 items-center rounded-md bg-[#f3f4f6] px-2 text-xs font-medium text-[#6b7280] whitespace-nowrap">
+ {model.modelId}
+ </span>
+ <span className="inline-flex h-5 items-center rounded-md bg-[#f3f4f6] px-2 text-xs font-medium text-[#6b7280] whitespace-nowrap">
+ {model.baseUrl}
+ </span>
+ </div>
+ <div className="flex items-center gap-2 ml-2">
+ {pageAccess.write && (
+ <>
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => handleEditModel(model)}
+ className="h-8 w-8 p-0"
+ >
+ <Pencil className="h-4 w-4" />
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => handleDeleteClick(model)}
+ className="h-8 w-8 p-0"
+ >
+ <Trash2 className="h-4 w-4 hover:text-red-500" />
+ </Button>
+ </>
+ )}
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+ {pageAccess.write && (
+ <div className="pt-4 flex justify-center">
+ <CustomButton
+ variant="secondary"
+ addIcon
+ Icon={<PlusCircle className="mr-2 h-4 w-4" />}
+ handleClick={() => setIsCreateModalOpen(true)}
+ label="Add Local Model"
+ />
+ </div>
+ )}
+ </>
+ )}
+ </div>
+
+ {/* Create/Edit Modal */}
+ <CreateLocalModelModal
+ isOpen={isCreateModalOpen || !!editingModel}
+ onClose={editingModel ? handleCloseEditModal : handleCloseCreateModal}
+ onSubmit={editingModel ? handleUpdateModel : handleCreateModel}
+ editModel={editingModel}
+ isProcessing={isProcessing}
+ />
+
+ {/* Delete Modal */}
+ <DeleteLocalModelModal
+ isOpen={isDeleteModalOpen}
+ onClose={handleCloseDeleteModal}
+ onConfirm={handleDeleteModel}
+ model={modelToDelete}
+ isProcessing={isProcessing}
+ />
+ </div>
+ );
+}
+
+export default LocalModels;
diff --git a/packages/app/src/react/features/vault/hooks/use-vault.tsx b/packages/app/src/react/features/vault/hooks/use-vault.tsx
index 748ec08b..cc83f9b9 100644
--- a/packages/app/src/react/features/vault/hooks/use-vault.tsx
+++ b/packages/app/src/react/features/vault/hooks/use-vault.tsx
@@ -2,11 +2,14 @@ import type {
ApiKey,
ApiKeysResponse,
EnterpriseModel,
+ LocalModel,
UserModel,
} from '@react/features/vault/types/types';
import {
apiKeyService,
enterpriseModelService,
+ localModelService,
+ recommendedModelsService,
userModelService,
vaultService,
} from '@react/features/vault/vault-business-logic';
@@ -262,3 +265,72 @@ export function useDeleteEnterpriseModel() {
},
});
}
+
+export function useRecommendedModels() {
+ return useQuery({
+ queryKey: ['recommendedModels'],
+ queryFn: () => recommendedModelsService.getRecommendedModels(),
+ });
+}
+
+export function useUpdateRecommendedModel() {
+ return useMutation({
+ mutationFn: ({ providerId, enabled }: { providerId: string; enabled: boolean }) =>
+ recommendedModelsService.updateRecommendedModels(providerId, enabled),
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: ['recommendedModels'] });
+ },
+ });
+}
+
+// Local Model Hooks
+const LOCAL_MODEL_QUERY_KEYS = {
+ LOCAL_MODELS: ['localModels'],
+} as const;
+
+export function useLocalModels() {
+ return useQuery({
+ queryKey: LOCAL_MODEL_QUERY_KEYS.LOCAL_MODELS,
+ queryFn: () => localModelService.getLocalModels(),
+ });
+}
+
+export function useCreateLocalModel() {
+ const queryClient = useQueryClient();
+
+ return useMutation({
+ mutationFn: (modelDetails: Omit<LocalModel, 'id'>) =>
+ localModelService.createLocalModel(modelDetails),
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: LOCAL_MODEL_QUERY_KEYS.LOCAL_MODELS });
+ },
+ });
+}
+
+export function useUpdateLocalModel() {
+ const queryClient = useQueryClient();
+
+ return useMutation({
+ mutationFn: ({
+ modelId,
+ updatedFields,
+ }: {
+ modelId: string;
+ updatedFields: Partial<LocalModel>;
+ }) => localModelService.updateLocalModel(modelId, updatedFields),
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: LOCAL_MODEL_QUERY_KEYS.LOCAL_MODELS });
+ },
+ });
+}
+
+export function useDeleteLocalModel() {
+ const queryClient = useQueryClient();
+
+ return useMutation<void, Error, { modelId: string }>({
+ mutationFn: ({ modelId }) => localModelService.deleteLocalModel(modelId),
+ onSuccess: () => {
+ queryClient.invalidateQueries({ queryKey: LOCAL_MODEL_QUERY_KEYS.LOCAL_MODELS });
+ },
+ });
+}
diff --git a/packages/app/src/react/features/vault/pages/VaultPage.tsx b/packages/app/src/react/features/vault/pages/VaultPage.tsx
index 364a5307..042fc2a6 100644
--- a/packages/app/src/react/features/vault/pages/VaultPage.tsx
+++ b/packages/app/src/react/features/vault/pages/VaultPage.tsx
@@ -9,7 +9,9 @@ import React, { useMemo } from 'react';
import { CiExport } from 'react-icons/ci';
import { ApiKeys } from '../components/api-keys';
import { EnterpriseModels } from '../components/enterprise-models';
+import LocalModels from '../components/local-models';
import { OAuthConnections } from '../components/oauth-connections';
+import { RecommendedModels } from '../components/recommended-models';
import { UserModels } from '../components/user-models';
import { useVault } from '../hooks/use-vault';
@@ -81,6 +83,7 @@ export default function VaultPage() {
)}
<UserModels pageAccess={pageAccess} />
+ <LocalModels pageAccess={pageAccess} />
<EnterpriseModels pageAccess={pageAccess} />
<OAuthConnections />
diff --git a/packages/app/src/react/features/vault/types/types.ts b/packages/app/src/react/features/vault/types/types.ts
index 7932dad7..902ee74b 100644
--- a/packages/app/src/react/features/vault/types/types.ts
+++ b/packages/app/src/react/features/vault/types/types.ts
@@ -162,4 +162,34 @@ export interface UserModel {
export interface ApiKeysResponse {
keys?: ApiKey[];
error?: string;
-}
\ No newline at end of file
+}
+
+/**
+ * Represents a local LLM model in the system
+ */
+export interface LocalModel {
+ /**
+ * Unique identifier for the model
+ */
+ id: string;
+
+ /**
+ * Display name of the model
+ */
+ name: string;
+
+ /**
+ * The model ID entered by the user
+ */
+ modelId: string;
+
+ /**
+ * Base URL for the local model API
+ */
+ baseUrl: string;
+
+ /**
+ * Fallback LLM ID from builtin LLMs
+ */
+ fallbackLLM: string;
+}
diff --git a/packages/app/src/react/features/vault/vault-business-logic.ts b/packages/app/src/react/features/vault/vault-business-logic.ts
index b2125773..ea8bd417 100644
--- a/packages/app/src/react/features/vault/vault-business-logic.ts
+++ b/packages/app/src/react/features/vault/vault-business-logic.ts
@@ -4,7 +4,7 @@ import {
} from '@src/shared/constants/custom-llm.constants';
import { VAULT_SCOPE_AGENT_LLM } from '@src/shared/constants/general';
import { customModels } from '@src/shared/custom-models';
-import type { ApiKey, BuiltInModel, EnterpriseModel, UserModel } from './types/types';
+import type { ApiKey, BuiltInModel, EnterpriseModel, LocalModel, UserModel } from './types/types';
export interface Provider {
id: string;
@@ -610,3 +610,145 @@ export const providerService = {
return providerService.providers.find((p) => p.id === providerId) || null;
},
};
+
+export const localModelService = {
+ localModels: [],
+
+ /**
+ * Fetches all local LLM models for the current team
+ */
+ getLocalModels: async (): Promise<LocalModel[]> => {
+ try {
+ const response = await fetch('/api/page/vault/local-llm', {
+ method: 'GET',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to fetch local models');
+ }
+
+ const result = await response.json();
+ if (!result.success) {
+ throw new Error(result.error || 'Failed to fetch local models');
+ }
+
+ // Convert the local LLM data to our LocalModel format
+ const models = Object.entries(result.data || {}).map(([id, value]: [string, any]) => ({
+ id: value.id || id,
+ name: value.name,
+ modelId: value.modelId,
+ baseUrl: value.baseUrl,
+ fallbackLLM: value.fallbackLLM,
+ }));
+
+ return models;
+ } catch (error) {
+ console.error('Error fetching local models:', error);
+ return [];
+ }
+ },
+
+ /**
+ * Creates a new local LLM model
+ */
+ createLocalModel: async (modelDetails: Omit<LocalModel, 'id'>): Promise<LocalModel> => {
+ try {
+ const response = await fetch('/api/page/vault/local-llm/', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(modelDetails),
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to create local model');
+ }
+
+ const result = await response.json();
+ if (!result.success) {
+ throw new Error(result.error || 'Failed to create local model');
+ }
+
+ // Return the created model with the generated ID
+ return {
+ id: result.data.id,
+ name: result.data.name,
+ modelId: modelDetails.modelId,
+ baseUrl: modelDetails.baseUrl,
+ fallbackLLM: modelDetails.fallbackLLM,
+ };
+ } catch (error) {
+ console.error('Error creating local model:', error);
+ throw new Error(error.error || error.message || 'Failed to create local model');
+ }
+ },
+
+ /**
+ * Updates an existing local LLM model
+ */
+ updateLocalModel: async (
+ modelId: string,
+ updatedFields: Partial<LocalModel>,
+ ): Promise<LocalModel> => {
+ try {
+ const response = await fetch(`/api/page/vault/local-llm/${modelId}`, {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(updatedFields),
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to update local model');
+ }
+
+ const result = await response.json();
+ if (!result.success) {
+ throw new Error(result.error || 'Failed to update local model');
+ }
+
+ // Return the updated model
+ return {
+ id: modelId,
+ name: result.data.name,
+ modelId: updatedFields.modelId || '',
+ baseUrl: updatedFields.baseUrl || '',
+ fallbackLLM: updatedFields.fallbackLLM || '',
+ };
+ } catch (error) {
+ console.error('Error updating local model:', error);
+ throw new Error(error.error || error.message || 'Failed to update local model');
+ }
+ },
+
+ /**
+ * Deletes a local LLM model
+ */
+ deleteLocalModel: async (modelId: string): Promise<void> => {
+ try {
+ const response = await fetch(`/api/page/vault/local-llm/${modelId}`, {
+ method: 'DELETE',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to delete local model');
+ }
+
+ const result = await response.json();
+ if (!result.success) {
+ throw new Error(result.error || 'Failed to delete local model');
+ }
+ } catch (error) {
+ console.error('Error deleting local model:', error);
+ throw new Error(error.error || error.message || 'Failed to delete local model');
+ }
+ },
+};