mirror of
https://github.com/samanhappy/mcphub.git
synced 2025-12-24 10:49:35 -05:00
Compare commits
2 Commits
copilot/fi
...
v0.11.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d8f5ba370 | ||
|
|
764959eaca |
@@ -4,6 +4,7 @@ import { AuthProvider } from './contexts/AuthContext';
|
||||
import { ToastProvider } from './contexts/ToastContext';
|
||||
import { ThemeProvider } from './contexts/ThemeContext';
|
||||
import { ServerProvider } from './contexts/ServerContext';
|
||||
import { SettingsProvider } from './contexts/SettingsContext';
|
||||
import MainLayout from './layouts/MainLayout';
|
||||
import ProtectedRoute from './components/ProtectedRoute';
|
||||
import LoginPage from './pages/LoginPage';
|
||||
@@ -27,42 +28,41 @@ function App() {
|
||||
return (
|
||||
<ThemeProvider>
|
||||
<AuthProvider>
|
||||
<ServerProvider>
|
||||
<ToastProvider>
|
||||
<Router basename={basename}>
|
||||
<Routes>
|
||||
{/* 公共路由 */}
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<ServerProvider>
|
||||
<ToastProvider>
|
||||
<SettingsProvider>
|
||||
<Router basename={basename}>
|
||||
<Routes>
|
||||
{/* 公共路由 */}
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
|
||||
{/* 受保护的路由,使用 MainLayout 作为布局容器 */}
|
||||
<Route element={<ProtectedRoute />}>
|
||||
<Route element={<MainLayout />}>
|
||||
<Route path="/" element={<DashboardPage />} />
|
||||
<Route path="/servers" element={<ServersPage />} />
|
||||
<Route path="/groups" element={<GroupsPage />} />
|
||||
<Route path="/users" element={<UsersPage />} />
|
||||
<Route path="/market" element={<MarketPage />} />
|
||||
<Route path="/market/:serverName" element={<MarketPage />} />
|
||||
{/* Legacy cloud routes redirect to market with cloud tab */}
|
||||
<Route path="/cloud" element={<Navigate to="/market?tab=cloud" replace />} />
|
||||
<Route
|
||||
path="/cloud/:serverName"
|
||||
element={<CloudRedirect />}
|
||||
/>
|
||||
<Route path="/logs" element={<LogsPage />} />
|
||||
<Route path="/settings" element={<SettingsPage />} />
|
||||
</Route>
|
||||
</Route>
|
||||
{/* 受保护的路由,使用 MainLayout 作为布局容器 */}
|
||||
<Route element={<ProtectedRoute />}>
|
||||
<Route element={<MainLayout />}>
|
||||
<Route path="/" element={<DashboardPage />} />
|
||||
<Route path="/servers" element={<ServersPage />} />
|
||||
<Route path="/groups" element={<GroupsPage />} />
|
||||
<Route path="/users" element={<UsersPage />} />
|
||||
<Route path="/market" element={<MarketPage />} />
|
||||
<Route path="/market/:serverName" element={<MarketPage />} />
|
||||
{/* Legacy cloud routes redirect to market with cloud tab */}
|
||||
<Route path="/cloud" element={<Navigate to="/market?tab=cloud" replace />} />
|
||||
<Route path="/cloud/:serverName" element={<CloudRedirect />} />
|
||||
<Route path="/logs" element={<LogsPage />} />
|
||||
<Route path="/settings" element={<SettingsPage />} />
|
||||
</Route>
|
||||
</Route>
|
||||
|
||||
{/* 未匹配的路由重定向到首页 */}
|
||||
<Route path="*" element={<Navigate to="/" />} />
|
||||
</Routes>
|
||||
</Router>
|
||||
</ToastProvider>
|
||||
{/* 未匹配的路由重定向到首页 */}
|
||||
<Route path="*" element={<Navigate to="/" />} />
|
||||
</Routes>
|
||||
</Router>
|
||||
</SettingsProvider>
|
||||
</ToastProvider>
|
||||
</ServerProvider>
|
||||
</AuthProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
export default App;
|
||||
|
||||
@@ -106,6 +106,10 @@ const ServerCard = ({ server, onRemove, onEdit, onToggle, onRefresh }: ServerCar
|
||||
e.stopPropagation();
|
||||
try {
|
||||
const result = await exportMCPSettings(server.name);
|
||||
if (!result || !result.success || !result.data) {
|
||||
showToast(result?.message || t('common.copyFailed') || 'Copy failed', 'error');
|
||||
return;
|
||||
}
|
||||
const configJson = JSON.stringify(result.data, null, 2);
|
||||
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
|
||||
@@ -1,152 +1,174 @@
|
||||
import { useState, useCallback, useRef, useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Prompt } from '@/types'
|
||||
import { ChevronDown, ChevronRight, Play, Loader, Edit, Check } from '@/components/icons/LucideIcons'
|
||||
import { Switch } from './ToggleGroup'
|
||||
import { getPrompt, PromptCallResult } from '@/services/promptService'
|
||||
import { useSettingsData } from '@/hooks/useSettingsData'
|
||||
import DynamicForm from './DynamicForm'
|
||||
import PromptResult from './PromptResult'
|
||||
import { useState, useCallback, useRef, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Prompt } from '@/types';
|
||||
import {
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
Play,
|
||||
Loader,
|
||||
Edit,
|
||||
Check,
|
||||
} from '@/components/icons/LucideIcons';
|
||||
import { Switch } from './ToggleGroup';
|
||||
import { getPrompt, updatePromptDescription, PromptCallResult } from '@/services/promptService';
|
||||
import { useSettingsData } from '@/hooks/useSettingsData';
|
||||
import DynamicForm from './DynamicForm';
|
||||
import PromptResult from './PromptResult';
|
||||
import { useToast } from '@/contexts/ToastContext';
|
||||
|
||||
interface PromptCardProps {
|
||||
server: string
|
||||
prompt: Prompt
|
||||
onToggle?: (promptName: string, enabled: boolean) => void
|
||||
onDescriptionUpdate?: (promptName: string, description: string) => void
|
||||
server: string;
|
||||
prompt: Prompt;
|
||||
onToggle?: (promptName: string, enabled: boolean) => void;
|
||||
onDescriptionUpdate?: (promptName: string, description: string) => void;
|
||||
}
|
||||
|
||||
const PromptCard = ({ prompt, server, onToggle, onDescriptionUpdate }: PromptCardProps) => {
|
||||
const { t } = useTranslation()
|
||||
const { nameSeparator } = useSettingsData()
|
||||
const [isExpanded, setIsExpanded] = useState(false)
|
||||
const [showRunForm, setShowRunForm] = useState(false)
|
||||
const [isRunning, setIsRunning] = useState(false)
|
||||
const [result, setResult] = useState<PromptCallResult | null>(null)
|
||||
const [isEditingDescription, setIsEditingDescription] = useState(false)
|
||||
const [customDescription, setCustomDescription] = useState(prompt.description || '')
|
||||
const descriptionInputRef = useRef<HTMLInputElement>(null)
|
||||
const descriptionTextRef = useRef<HTMLSpanElement>(null)
|
||||
const [textWidth, setTextWidth] = useState<number>(0)
|
||||
const { t } = useTranslation();
|
||||
const { showToast } = useToast();
|
||||
const { nameSeparator } = useSettingsData();
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const [showRunForm, setShowRunForm] = useState(false);
|
||||
const [isRunning, setIsRunning] = useState(false);
|
||||
const [result, setResult] = useState<PromptCallResult | null>(null);
|
||||
const [isEditingDescription, setIsEditingDescription] = useState(false);
|
||||
const [customDescription, setCustomDescription] = useState(prompt.description || '');
|
||||
const descriptionInputRef = useRef<HTMLInputElement>(null);
|
||||
const descriptionTextRef = useRef<HTMLSpanElement>(null);
|
||||
const [textWidth, setTextWidth] = useState<number>(0);
|
||||
|
||||
// Focus the input when editing mode is activated
|
||||
useEffect(() => {
|
||||
if (isEditingDescription && descriptionInputRef.current) {
|
||||
descriptionInputRef.current.focus()
|
||||
descriptionInputRef.current.focus();
|
||||
// Set input width to match text width
|
||||
if (textWidth > 0) {
|
||||
descriptionInputRef.current.style.width = `${textWidth + 20}px` // Add some padding
|
||||
descriptionInputRef.current.style.width = `${textWidth + 20}px`; // Add some padding
|
||||
}
|
||||
}
|
||||
}, [isEditingDescription, textWidth])
|
||||
}, [isEditingDescription, textWidth]);
|
||||
|
||||
// Measure text width when not editing
|
||||
useEffect(() => {
|
||||
if (!isEditingDescription && descriptionTextRef.current) {
|
||||
setTextWidth(descriptionTextRef.current.offsetWidth)
|
||||
setTextWidth(descriptionTextRef.current.offsetWidth);
|
||||
}
|
||||
}, [isEditingDescription, customDescription])
|
||||
}, [isEditingDescription, customDescription]);
|
||||
|
||||
// Generate a unique key for localStorage based on prompt name and server
|
||||
const getStorageKey = useCallback(() => {
|
||||
return `mcphub_prompt_form_${server ? `${server}_` : ''}${prompt.name}`
|
||||
}, [prompt.name, server])
|
||||
return `mcphub_prompt_form_${server ? `${server}_` : ''}${prompt.name}`;
|
||||
}, [prompt.name, server]);
|
||||
|
||||
// Clear form data from localStorage
|
||||
const clearStoredFormData = useCallback(() => {
|
||||
localStorage.removeItem(getStorageKey())
|
||||
}, [getStorageKey])
|
||||
localStorage.removeItem(getStorageKey());
|
||||
}, [getStorageKey]);
|
||||
|
||||
const handleToggle = (enabled: boolean) => {
|
||||
if (onToggle) {
|
||||
onToggle(prompt.name, enabled)
|
||||
onToggle(prompt.name, enabled);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleDescriptionEdit = () => {
|
||||
setIsEditingDescription(true)
|
||||
}
|
||||
setIsEditingDescription(true);
|
||||
};
|
||||
|
||||
const handleDescriptionSave = async () => {
|
||||
// For now, we'll just update the local state
|
||||
// In a real implementation, you would call an API to update the description
|
||||
setIsEditingDescription(false)
|
||||
if (onDescriptionUpdate) {
|
||||
onDescriptionUpdate(prompt.name, customDescription)
|
||||
setIsEditingDescription(false);
|
||||
try {
|
||||
const result = await updatePromptDescription(server, prompt.name, customDescription);
|
||||
if (result.success) {
|
||||
showToast(t('prompt.descriptionUpdateSuccess'), 'success');
|
||||
if (onDescriptionUpdate) {
|
||||
onDescriptionUpdate(prompt.name, customDescription);
|
||||
}
|
||||
} else {
|
||||
showToast(result.error || t('prompt.descriptionUpdateFailed'), 'error');
|
||||
// Revert to original description on failure
|
||||
setCustomDescription(prompt.description || '');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error updating prompt description:', error);
|
||||
showToast(t('prompt.descriptionUpdateFailed'), 'error');
|
||||
// Revert to original description on failure
|
||||
setCustomDescription(prompt.description || '');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleDescriptionChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setCustomDescription(e.target.value)
|
||||
}
|
||||
setCustomDescription(e.target.value);
|
||||
};
|
||||
|
||||
const handleDescriptionKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleDescriptionSave()
|
||||
handleDescriptionSave();
|
||||
} else if (e.key === 'Escape') {
|
||||
setCustomDescription(prompt.description || '')
|
||||
setIsEditingDescription(false)
|
||||
setCustomDescription(prompt.description || '');
|
||||
setIsEditingDescription(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleGetPrompt = async (arguments_: Record<string, any>) => {
|
||||
setIsRunning(true)
|
||||
setIsRunning(true);
|
||||
try {
|
||||
const result = await getPrompt({ promptName: prompt.name, arguments: arguments_ }, server)
|
||||
console.log('GetPrompt result:', result)
|
||||
const result = await getPrompt({ promptName: prompt.name, arguments: arguments_ }, server);
|
||||
console.log('GetPrompt result:', result);
|
||||
setResult({
|
||||
success: result.success,
|
||||
data: result.data,
|
||||
error: result.error
|
||||
})
|
||||
error: result.error,
|
||||
});
|
||||
// Clear form data on successful submission
|
||||
// clearStoredFormData()
|
||||
} catch (error) {
|
||||
setResult({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
||||
})
|
||||
});
|
||||
} finally {
|
||||
setIsRunning(false)
|
||||
setIsRunning(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancelRun = () => {
|
||||
setShowRunForm(false)
|
||||
setShowRunForm(false);
|
||||
// Clear form data when cancelled
|
||||
clearStoredFormData()
|
||||
setResult(null)
|
||||
}
|
||||
clearStoredFormData();
|
||||
setResult(null);
|
||||
};
|
||||
|
||||
const handleCloseResult = () => {
|
||||
setResult(null)
|
||||
}
|
||||
setResult(null);
|
||||
};
|
||||
|
||||
// Convert prompt arguments to ToolInputSchema format for DynamicForm
|
||||
const convertToSchema = () => {
|
||||
if (!prompt.arguments || prompt.arguments.length === 0) {
|
||||
return { type: 'object', properties: {}, required: [] }
|
||||
return { type: 'object', properties: {}, required: [] };
|
||||
}
|
||||
|
||||
const properties: Record<string, any> = {}
|
||||
const required: string[] = []
|
||||
const properties: Record<string, any> = {};
|
||||
const required: string[] = [];
|
||||
|
||||
prompt.arguments.forEach(arg => {
|
||||
prompt.arguments.forEach((arg) => {
|
||||
properties[arg.name] = {
|
||||
type: 'string', // Default to string for prompts
|
||||
description: arg.description || ''
|
||||
}
|
||||
description: arg.description || '',
|
||||
};
|
||||
|
||||
if (arg.required) {
|
||||
required.push(arg.name)
|
||||
required.push(arg.name);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
return {
|
||||
type: 'object',
|
||||
properties,
|
||||
required
|
||||
}
|
||||
}
|
||||
required,
|
||||
};
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-white border border-gray-200 shadow rounded-lg p-4 mb-4">
|
||||
@@ -158,9 +180,7 @@ const PromptCard = ({ prompt, server, onToggle, onDescriptionUpdate }: PromptCar
|
||||
<h3 className="text-lg font-medium text-gray-900">
|
||||
{prompt.name.replace(server + nameSeparator, '')}
|
||||
{prompt.title && (
|
||||
<span className="ml-2 text-sm font-normal text-gray-600">
|
||||
{prompt.title}
|
||||
</span>
|
||||
<span className="ml-2 text-sm font-normal text-gray-600">{prompt.title}</span>
|
||||
)}
|
||||
<span className="ml-2 text-sm font-normal text-gray-500 inline-flex items-center">
|
||||
{isEditingDescription ? (
|
||||
@@ -175,14 +195,14 @@ const PromptCard = ({ prompt, server, onToggle, onDescriptionUpdate }: PromptCar
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
style={{
|
||||
minWidth: '100px',
|
||||
width: textWidth > 0 ? `${textWidth + 20}px` : 'auto'
|
||||
width: textWidth > 0 ? `${textWidth + 20}px` : 'auto',
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
className="ml-2 p-1 text-green-600 hover:text-green-800 cursor-pointer transition-colors"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleDescriptionSave()
|
||||
e.stopPropagation();
|
||||
handleDescriptionSave();
|
||||
}}
|
||||
>
|
||||
<Check size={16} />
|
||||
@@ -190,12 +210,14 @@ const PromptCard = ({ prompt, server, onToggle, onDescriptionUpdate }: PromptCar
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<span ref={descriptionTextRef}>{customDescription || t('tool.noDescription')}</span>
|
||||
<span ref={descriptionTextRef}>
|
||||
{customDescription || t('tool.noDescription')}
|
||||
</span>
|
||||
<button
|
||||
className="ml-2 p-1 text-gray-500 hover:text-blue-600 cursor-pointer transition-colors"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleDescriptionEdit()
|
||||
e.stopPropagation();
|
||||
handleDescriptionEdit();
|
||||
}}
|
||||
>
|
||||
<Edit size={14} />
|
||||
@@ -206,10 +228,7 @@ const PromptCard = ({ prompt, server, onToggle, onDescriptionUpdate }: PromptCar
|
||||
</h3>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<div
|
||||
className="flex items-center space-x-2"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<div className="flex items-center space-x-2" onClick={(e) => e.stopPropagation()}>
|
||||
{prompt.enabled !== undefined && (
|
||||
<Switch
|
||||
checked={prompt.enabled}
|
||||
@@ -220,18 +239,14 @@ const PromptCard = ({ prompt, server, onToggle, onDescriptionUpdate }: PromptCar
|
||||
</div>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
setIsExpanded(true) // Ensure card is expanded when showing run form
|
||||
setShowRunForm(true)
|
||||
e.stopPropagation();
|
||||
setIsExpanded(true); // Ensure card is expanded when showing run form
|
||||
setShowRunForm(true);
|
||||
}}
|
||||
className="flex items-center space-x-1 px-3 py-1 text-sm text-blue-600 bg-blue-50 hover:bg-blue-100 rounded-md transition-colors btn-primary"
|
||||
disabled={isRunning || !prompt.enabled}
|
||||
>
|
||||
{isRunning ? (
|
||||
<Loader size={14} className="animate-spin" />
|
||||
) : (
|
||||
<Play size={14} />
|
||||
)}
|
||||
{isRunning ? <Loader size={14} className="animate-spin" /> : <Play size={14} />}
|
||||
<span>{isRunning ? t('tool.running') : t('tool.run')}</span>
|
||||
</button>
|
||||
<button className="text-gray-400 hover:text-gray-600">
|
||||
@@ -251,7 +266,9 @@ const PromptCard = ({ prompt, server, onToggle, onDescriptionUpdate }: PromptCar
|
||||
onCancel={handleCancelRun}
|
||||
loading={isRunning}
|
||||
storageKey={getStorageKey()}
|
||||
title={t('prompt.runPromptWithName', { name: prompt.name.replace(server + nameSeparator, '') })}
|
||||
title={t('prompt.runPromptWithName', {
|
||||
name: prompt.name.replace(server + nameSeparator, ''),
|
||||
})}
|
||||
/>
|
||||
{/* Prompt Result */}
|
||||
{result && (
|
||||
@@ -278,9 +295,7 @@ const PromptCard = ({ prompt, server, onToggle, onDescriptionUpdate }: PromptCar
|
||||
<p className="text-sm text-gray-600 mt-1">{arg.description}</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-xs text-gray-500 ml-2">
|
||||
{arg.title || ''}
|
||||
</div>
|
||||
<div className="text-xs text-gray-500 ml-2">{arg.title || ''}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -296,7 +311,7 @@ const PromptCard = ({ prompt, server, onToggle, onDescriptionUpdate }: PromptCar
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default PromptCard
|
||||
export default PromptCard;
|
||||
|
||||
705
frontend/src/contexts/SettingsContext.tsx
Normal file
705
frontend/src/contexts/SettingsContext.tsx
Normal file
@@ -0,0 +1,705 @@
|
||||
import React, {
|
||||
createContext,
|
||||
useContext,
|
||||
useState,
|
||||
useCallback,
|
||||
useEffect,
|
||||
ReactNode,
|
||||
} from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ApiResponse } from '@/types';
|
||||
import { useToast } from '@/contexts/ToastContext';
|
||||
import { apiGet, apiPut } from '@/utils/fetchInterceptor';
|
||||
|
||||
// Define types for the settings data
|
||||
interface RoutingConfig {
|
||||
enableGlobalRoute: boolean;
|
||||
enableGroupNameRoute: boolean;
|
||||
enableBearerAuth: boolean;
|
||||
bearerAuthKey: string;
|
||||
skipAuth: boolean;
|
||||
}
|
||||
|
||||
interface InstallConfig {
|
||||
pythonIndexUrl: string;
|
||||
npmRegistry: string;
|
||||
baseUrl: string;
|
||||
}
|
||||
|
||||
interface SmartRoutingConfig {
|
||||
enabled: boolean;
|
||||
dbUrl: string;
|
||||
openaiApiBaseUrl: string;
|
||||
openaiApiKey: string;
|
||||
openaiApiEmbeddingModel: string;
|
||||
}
|
||||
|
||||
interface MCPRouterConfig {
|
||||
apiKey: string;
|
||||
referer: string;
|
||||
title: string;
|
||||
baseUrl: string;
|
||||
}
|
||||
|
||||
interface OAuthServerConfig {
|
||||
enabled: boolean;
|
||||
accessTokenLifetime: number;
|
||||
refreshTokenLifetime: number;
|
||||
authorizationCodeLifetime: number;
|
||||
requireClientSecret: boolean;
|
||||
allowedScopes: string[];
|
||||
requireState: boolean;
|
||||
dynamicRegistration: {
|
||||
enabled: boolean;
|
||||
allowedGrantTypes: string[];
|
||||
requiresAuthentication: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface SystemSettings {
|
||||
systemConfig?: {
|
||||
routing?: RoutingConfig;
|
||||
install?: InstallConfig;
|
||||
smartRouting?: SmartRoutingConfig;
|
||||
mcpRouter?: MCPRouterConfig;
|
||||
nameSeparator?: string;
|
||||
oauthServer?: OAuthServerConfig;
|
||||
enableSessionRebuild?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface TempRoutingConfig {
|
||||
bearerAuthKey: string;
|
||||
}
|
||||
|
||||
interface SettingsContextValue {
|
||||
routingConfig: RoutingConfig;
|
||||
tempRoutingConfig: TempRoutingConfig;
|
||||
setTempRoutingConfig: React.Dispatch<React.SetStateAction<TempRoutingConfig>>;
|
||||
installConfig: InstallConfig;
|
||||
smartRoutingConfig: SmartRoutingConfig;
|
||||
mcpRouterConfig: MCPRouterConfig;
|
||||
oauthServerConfig: OAuthServerConfig;
|
||||
nameSeparator: string;
|
||||
enableSessionRebuild: boolean;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
setError: React.Dispatch<React.SetStateAction<string | null>>;
|
||||
triggerRefresh: () => void;
|
||||
fetchSettings: () => Promise<void>;
|
||||
updateRoutingConfig: (key: keyof RoutingConfig, value: any) => Promise<boolean | undefined>;
|
||||
updateInstallConfig: (key: keyof InstallConfig, value: any) => Promise<boolean | undefined>;
|
||||
updateSmartRoutingConfig: (
|
||||
key: keyof SmartRoutingConfig,
|
||||
value: any,
|
||||
) => Promise<boolean | undefined>;
|
||||
updateSmartRoutingConfigBatch: (
|
||||
updates: Partial<SmartRoutingConfig>,
|
||||
) => Promise<boolean | undefined>;
|
||||
updateRoutingConfigBatch: (updates: Partial<RoutingConfig>) => Promise<boolean | undefined>;
|
||||
updateMCPRouterConfig: (key: keyof MCPRouterConfig, value: any) => Promise<boolean | undefined>;
|
||||
updateMCPRouterConfigBatch: (updates: Partial<MCPRouterConfig>) => Promise<boolean | undefined>;
|
||||
updateOAuthServerConfig: (
|
||||
key: keyof OAuthServerConfig,
|
||||
value: any,
|
||||
) => Promise<boolean | undefined>;
|
||||
updateOAuthServerConfigBatch: (
|
||||
updates: Partial<OAuthServerConfig>,
|
||||
) => Promise<boolean | undefined>;
|
||||
updateNameSeparator: (value: string) => Promise<boolean | undefined>;
|
||||
updateSessionRebuild: (value: boolean) => Promise<boolean | undefined>;
|
||||
exportMCPSettings: (serverName?: string) => Promise<any>;
|
||||
}
|
||||
|
||||
const getDefaultOAuthServerConfig = (): OAuthServerConfig => ({
|
||||
enabled: true,
|
||||
accessTokenLifetime: 3600,
|
||||
refreshTokenLifetime: 1209600,
|
||||
authorizationCodeLifetime: 300,
|
||||
requireClientSecret: false,
|
||||
allowedScopes: ['read', 'write'],
|
||||
requireState: false,
|
||||
dynamicRegistration: {
|
||||
enabled: true,
|
||||
allowedGrantTypes: ['authorization_code', 'refresh_token'],
|
||||
requiresAuthentication: false,
|
||||
},
|
||||
});
|
||||
|
||||
const SettingsContext = createContext<SettingsContextValue | undefined>(undefined);
|
||||
|
||||
export const useSettings = () => {
|
||||
const context = useContext(SettingsContext);
|
||||
if (!context) {
|
||||
throw new Error('useSettings must be used within a SettingsProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
interface SettingsProviderProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const SettingsProvider: React.FC<SettingsProviderProps> = ({ children }) => {
|
||||
const { t } = useTranslation();
|
||||
const { showToast } = useToast();
|
||||
|
||||
const [routingConfig, setRoutingConfig] = useState<RoutingConfig>({
|
||||
enableGlobalRoute: true,
|
||||
enableGroupNameRoute: true,
|
||||
enableBearerAuth: false,
|
||||
bearerAuthKey: '',
|
||||
skipAuth: false,
|
||||
});
|
||||
|
||||
const [tempRoutingConfig, setTempRoutingConfig] = useState<TempRoutingConfig>({
|
||||
bearerAuthKey: '',
|
||||
});
|
||||
|
||||
const [installConfig, setInstallConfig] = useState<InstallConfig>({
|
||||
pythonIndexUrl: '',
|
||||
npmRegistry: '',
|
||||
baseUrl: 'http://localhost:3000',
|
||||
});
|
||||
|
||||
const [smartRoutingConfig, setSmartRoutingConfig] = useState<SmartRoutingConfig>({
|
||||
enabled: false,
|
||||
dbUrl: '',
|
||||
openaiApiBaseUrl: '',
|
||||
openaiApiKey: '',
|
||||
openaiApiEmbeddingModel: '',
|
||||
});
|
||||
|
||||
const [mcpRouterConfig, setMCPRouterConfig] = useState<MCPRouterConfig>({
|
||||
apiKey: '',
|
||||
referer: 'https://www.mcphubx.com',
|
||||
title: 'MCPHub',
|
||||
baseUrl: 'https://api.mcprouter.to/v1',
|
||||
});
|
||||
|
||||
const [oauthServerConfig, setOAuthServerConfig] = useState<OAuthServerConfig>(
|
||||
getDefaultOAuthServerConfig(),
|
||||
);
|
||||
|
||||
const [nameSeparator, setNameSeparator] = useState<string>('-');
|
||||
const [enableSessionRebuild, setEnableSessionRebuild] = useState<boolean>(false);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [refreshKey, setRefreshKey] = useState(0);
|
||||
|
||||
// Trigger a refresh of the settings data
|
||||
const triggerRefresh = useCallback(() => {
|
||||
setRefreshKey((prev) => prev + 1);
|
||||
}, []);
|
||||
|
||||
// Fetch current settings
|
||||
const fetchSettings = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data: ApiResponse<SystemSettings> = await apiGet('/settings');
|
||||
|
||||
if (data.success && data.data?.systemConfig?.routing) {
|
||||
setRoutingConfig({
|
||||
enableGlobalRoute: data.data.systemConfig.routing.enableGlobalRoute ?? true,
|
||||
enableGroupNameRoute: data.data.systemConfig.routing.enableGroupNameRoute ?? true,
|
||||
enableBearerAuth: data.data.systemConfig.routing.enableBearerAuth ?? false,
|
||||
bearerAuthKey: data.data.systemConfig.routing.bearerAuthKey || '',
|
||||
skipAuth: data.data.systemConfig.routing.skipAuth ?? false,
|
||||
});
|
||||
}
|
||||
if (data.success && data.data?.systemConfig?.install) {
|
||||
setInstallConfig({
|
||||
pythonIndexUrl: data.data.systemConfig.install.pythonIndexUrl || '',
|
||||
npmRegistry: data.data.systemConfig.install.npmRegistry || '',
|
||||
baseUrl: data.data.systemConfig.install.baseUrl || 'http://localhost:3000',
|
||||
});
|
||||
}
|
||||
if (data.success && data.data?.systemConfig?.smartRouting) {
|
||||
setSmartRoutingConfig({
|
||||
enabled: data.data.systemConfig.smartRouting.enabled ?? false,
|
||||
dbUrl: data.data.systemConfig.smartRouting.dbUrl || '',
|
||||
openaiApiBaseUrl: data.data.systemConfig.smartRouting.openaiApiBaseUrl || '',
|
||||
openaiApiKey: data.data.systemConfig.smartRouting.openaiApiKey || '',
|
||||
openaiApiEmbeddingModel:
|
||||
data.data.systemConfig.smartRouting.openaiApiEmbeddingModel || '',
|
||||
});
|
||||
}
|
||||
if (data.success && data.data?.systemConfig?.mcpRouter) {
|
||||
setMCPRouterConfig({
|
||||
apiKey: data.data.systemConfig.mcpRouter.apiKey || '',
|
||||
referer: data.data.systemConfig.mcpRouter.referer || 'https://www.mcphubx.com',
|
||||
title: data.data.systemConfig.mcpRouter.title || 'MCPHub',
|
||||
baseUrl: data.data.systemConfig.mcpRouter.baseUrl || 'https://api.mcprouter.to/v1',
|
||||
});
|
||||
}
|
||||
if (data.success) {
|
||||
if (data.data?.systemConfig?.oauthServer) {
|
||||
const oauth = data.data.systemConfig.oauthServer;
|
||||
const defaultOauthConfig = getDefaultOAuthServerConfig();
|
||||
const defaultDynamic = defaultOauthConfig.dynamicRegistration;
|
||||
const allowedScopes = Array.isArray(oauth.allowedScopes)
|
||||
? [...oauth.allowedScopes]
|
||||
: [...defaultOauthConfig.allowedScopes];
|
||||
const dynamicAllowedGrantTypes = Array.isArray(
|
||||
oauth.dynamicRegistration?.allowedGrantTypes,
|
||||
)
|
||||
? [...oauth.dynamicRegistration!.allowedGrantTypes!]
|
||||
: [...defaultDynamic.allowedGrantTypes];
|
||||
|
||||
setOAuthServerConfig({
|
||||
enabled: oauth.enabled ?? defaultOauthConfig.enabled,
|
||||
accessTokenLifetime:
|
||||
oauth.accessTokenLifetime ?? defaultOauthConfig.accessTokenLifetime,
|
||||
refreshTokenLifetime:
|
||||
oauth.refreshTokenLifetime ?? defaultOauthConfig.refreshTokenLifetime,
|
||||
authorizationCodeLifetime:
|
||||
oauth.authorizationCodeLifetime ?? defaultOauthConfig.authorizationCodeLifetime,
|
||||
requireClientSecret:
|
||||
oauth.requireClientSecret ?? defaultOauthConfig.requireClientSecret,
|
||||
requireState: oauth.requireState ?? defaultOauthConfig.requireState,
|
||||
allowedScopes,
|
||||
dynamicRegistration: {
|
||||
enabled: oauth.dynamicRegistration?.enabled ?? defaultDynamic.enabled,
|
||||
allowedGrantTypes: dynamicAllowedGrantTypes,
|
||||
requiresAuthentication:
|
||||
oauth.dynamicRegistration?.requiresAuthentication ??
|
||||
defaultDynamic.requiresAuthentication,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
setOAuthServerConfig(getDefaultOAuthServerConfig());
|
||||
}
|
||||
}
|
||||
if (data.success && data.data?.systemConfig?.nameSeparator !== undefined) {
|
||||
setNameSeparator(data.data.systemConfig.nameSeparator);
|
||||
}
|
||||
if (data.success && data.data?.systemConfig?.enableSessionRebuild !== undefined) {
|
||||
setEnableSessionRebuild(data.data.systemConfig.enableSessionRebuild);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch settings:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to fetch settings');
|
||||
showToast(t('errors.failedToFetchSettings'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [t, showToast]);
|
||||
|
||||
// Update routing configuration
|
||||
const updateRoutingConfig = async (key: keyof RoutingConfig, value: any) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
routing: {
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setRoutingConfig({
|
||||
...routingConfig,
|
||||
[key]: value,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update routing config');
|
||||
showToast(data.error || t('errors.failedToUpdateRoutingConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update routing config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update routing config');
|
||||
showToast(t('errors.failedToUpdateRoutingConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update install configuration
|
||||
const updateInstallConfig = async (key: keyof InstallConfig, value: any) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
install: {
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setInstallConfig({
|
||||
...installConfig,
|
||||
[key]: value,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update install config');
|
||||
showToast(data.error || t('errors.failedToUpdateInstallConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update install config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update install config');
|
||||
showToast(t('errors.failedToUpdateInstallConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update smart routing configuration
|
||||
const updateSmartRoutingConfig = async (key: keyof SmartRoutingConfig, value: any) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
smartRouting: {
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setSmartRoutingConfig({
|
||||
...smartRoutingConfig,
|
||||
[key]: value,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update smart routing config');
|
||||
showToast(data.error || t('errors.failedToUpdateSmartRoutingConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update smart routing config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update smart routing config');
|
||||
showToast(t('errors.failedToUpdateSmartRoutingConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Batch update smart routing configuration
|
||||
const updateSmartRoutingConfigBatch = async (updates: Partial<SmartRoutingConfig>) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
smartRouting: updates,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setSmartRoutingConfig({
|
||||
...smartRoutingConfig,
|
||||
...updates,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update smart routing config');
|
||||
showToast(data.error || t('errors.failedToUpdateSmartRoutingConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update smart routing config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update smart routing config');
|
||||
showToast(t('errors.failedToUpdateSmartRoutingConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Batch update routing configuration
|
||||
const updateRoutingConfigBatch = async (updates: Partial<RoutingConfig>) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
routing: updates,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setRoutingConfig({
|
||||
...routingConfig,
|
||||
...updates,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update routing config');
|
||||
showToast(data.error || t('errors.failedToUpdateRoutingConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update routing config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update routing config');
|
||||
showToast(t('errors.failedToUpdateRoutingConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update MCP Router configuration
|
||||
const updateMCPRouterConfig = async (key: keyof MCPRouterConfig, value: any) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
mcpRouter: {
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setMCPRouterConfig({
|
||||
...mcpRouterConfig,
|
||||
[key]: value,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update MCP Router config');
|
||||
showToast(data.error || t('errors.failedToUpdateMCPRouterConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update MCP Router config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update MCP Router config');
|
||||
showToast(t('errors.failedToUpdateMCPRouterConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Batch update MCP Router configuration
|
||||
const updateMCPRouterConfigBatch = async (updates: Partial<MCPRouterConfig>) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
mcpRouter: updates,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setMCPRouterConfig({
|
||||
...mcpRouterConfig,
|
||||
...updates,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update MCP Router config');
|
||||
showToast(data.error || t('errors.failedToUpdateMCPRouterConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update MCP Router config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update MCP Router config');
|
||||
showToast(t('errors.failedToUpdateMCPRouterConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update OAuth server configuration
|
||||
const updateOAuthServerConfig = async (key: keyof OAuthServerConfig, value: any) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
oauthServer: {
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setOAuthServerConfig({
|
||||
...oauthServerConfig,
|
||||
[key]: value,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update OAuth server config');
|
||||
showToast(data.error || t('errors.failedToUpdateOAuthServerConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update OAuth server config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update OAuth server config');
|
||||
showToast(t('errors.failedToUpdateOAuthServerConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Batch update OAuth server configuration
|
||||
const updateOAuthServerConfigBatch = async (updates: Partial<OAuthServerConfig>) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
oauthServer: updates,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setOAuthServerConfig({
|
||||
...oauthServerConfig,
|
||||
...updates,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update OAuth server config');
|
||||
showToast(data.error || t('errors.failedToUpdateOAuthServerConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update OAuth server config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update OAuth server config');
|
||||
showToast(t('errors.failedToUpdateOAuthServerConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update name separator
|
||||
const updateNameSeparator = async (value: string) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
nameSeparator: value,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setNameSeparator(value);
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update name separator');
|
||||
showToast(data.error || t('errors.failedToUpdateNameSeparator'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update name separator:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update name separator');
|
||||
showToast(t('errors.failedToUpdateNameSeparator'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update session rebuild flag
|
||||
const updateSessionRebuild = async (value: boolean) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
enableSessionRebuild: value,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setEnableSessionRebuild(value);
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
setError(data.error || 'Failed to update session rebuild setting');
|
||||
showToast(data.error || t('errors.failedToUpdateSessionRebuild'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update session rebuild setting:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update session rebuild setting');
|
||||
showToast(t('errors.failedToUpdateSessionRebuild'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const exportMCPSettings = async (serverName?: string) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
return await apiGet(`/mcp-settings/export?serverName=${serverName ? serverName : ''}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to export MCP settings:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : 'Failed to export MCP settings';
|
||||
setError(errorMessage);
|
||||
showToast(errorMessage);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Fetch settings when the component mounts or refreshKey changes
|
||||
useEffect(() => {
|
||||
fetchSettings();
|
||||
}, [fetchSettings, refreshKey]);
|
||||
|
||||
useEffect(() => {
|
||||
if (routingConfig) {
|
||||
setTempRoutingConfig({
|
||||
bearerAuthKey: routingConfig.bearerAuthKey,
|
||||
});
|
||||
}
|
||||
}, [routingConfig]);
|
||||
|
||||
const value: SettingsContextValue = {
|
||||
routingConfig,
|
||||
tempRoutingConfig,
|
||||
setTempRoutingConfig,
|
||||
installConfig,
|
||||
smartRoutingConfig,
|
||||
mcpRouterConfig,
|
||||
oauthServerConfig,
|
||||
nameSeparator,
|
||||
enableSessionRebuild,
|
||||
loading,
|
||||
error,
|
||||
setError,
|
||||
triggerRefresh,
|
||||
fetchSettings,
|
||||
updateRoutingConfig,
|
||||
updateInstallConfig,
|
||||
updateSmartRoutingConfig,
|
||||
updateSmartRoutingConfigBatch,
|
||||
updateRoutingConfigBatch,
|
||||
updateMCPRouterConfig,
|
||||
updateMCPRouterConfigBatch,
|
||||
updateOAuthServerConfig,
|
||||
updateOAuthServerConfigBatch,
|
||||
updateNameSeparator,
|
||||
updateSessionRebuild,
|
||||
exportMCPSettings,
|
||||
};
|
||||
|
||||
return <SettingsContext.Provider value={value}>{children}</SettingsContext.Provider>;
|
||||
};
|
||||
@@ -1,658 +1,10 @@
|
||||
import { useState, useCallback, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ApiResponse } from '@/types';
|
||||
import { useToast } from '@/contexts/ToastContext';
|
||||
import { apiGet, apiPut } from '../utils/fetchInterceptor';
|
||||
|
||||
// Define types for the settings data
|
||||
interface RoutingConfig {
|
||||
enableGlobalRoute: boolean;
|
||||
enableGroupNameRoute: boolean;
|
||||
enableBearerAuth: boolean;
|
||||
bearerAuthKey: string;
|
||||
skipAuth: boolean;
|
||||
}
|
||||
|
||||
interface InstallConfig {
|
||||
pythonIndexUrl: string;
|
||||
npmRegistry: string;
|
||||
baseUrl: string;
|
||||
}
|
||||
|
||||
interface SmartRoutingConfig {
|
||||
enabled: boolean;
|
||||
dbUrl: string;
|
||||
openaiApiBaseUrl: string;
|
||||
openaiApiKey: string;
|
||||
openaiApiEmbeddingModel: string;
|
||||
}
|
||||
|
||||
interface MCPRouterConfig {
|
||||
apiKey: string;
|
||||
referer: string;
|
||||
title: string;
|
||||
baseUrl: string;
|
||||
}
|
||||
|
||||
interface OAuthServerConfig {
|
||||
enabled: boolean;
|
||||
accessTokenLifetime: number;
|
||||
refreshTokenLifetime: number;
|
||||
authorizationCodeLifetime: number;
|
||||
requireClientSecret: boolean;
|
||||
allowedScopes: string[];
|
||||
requireState: boolean;
|
||||
dynamicRegistration: {
|
||||
enabled: boolean;
|
||||
allowedGrantTypes: string[];
|
||||
requiresAuthentication: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface SystemSettings {
|
||||
systemConfig?: {
|
||||
routing?: RoutingConfig;
|
||||
install?: InstallConfig;
|
||||
smartRouting?: SmartRoutingConfig;
|
||||
mcpRouter?: MCPRouterConfig;
|
||||
nameSeparator?: string;
|
||||
oauthServer?: OAuthServerConfig;
|
||||
enableSessionRebuild?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface TempRoutingConfig {
|
||||
bearerAuthKey: string;
|
||||
}
|
||||
|
||||
const getDefaultOAuthServerConfig = (): OAuthServerConfig => ({
|
||||
enabled: true,
|
||||
accessTokenLifetime: 3600,
|
||||
refreshTokenLifetime: 1209600,
|
||||
authorizationCodeLifetime: 300,
|
||||
requireClientSecret: false,
|
||||
allowedScopes: ['read', 'write'],
|
||||
requireState: false,
|
||||
dynamicRegistration: {
|
||||
enabled: true,
|
||||
allowedGrantTypes: ['authorization_code', 'refresh_token'],
|
||||
requiresAuthentication: false,
|
||||
},
|
||||
});
|
||||
import { useSettings } from '@/contexts/SettingsContext';
|
||||
|
||||
/**
|
||||
* Hook that provides access to settings data via SettingsContext.
|
||||
* This hook is a thin wrapper around useSettings to maintain backward compatibility.
|
||||
* The actual data fetching happens once in SettingsProvider, avoiding duplicate API calls.
|
||||
*/
|
||||
export const useSettingsData = () => {
|
||||
const { t } = useTranslation();
|
||||
const { showToast } = useToast();
|
||||
|
||||
const [routingConfig, setRoutingConfig] = useState<RoutingConfig>({
|
||||
enableGlobalRoute: true,
|
||||
enableGroupNameRoute: true,
|
||||
enableBearerAuth: false,
|
||||
bearerAuthKey: '',
|
||||
skipAuth: false,
|
||||
});
|
||||
|
||||
const [tempRoutingConfig, setTempRoutingConfig] = useState<TempRoutingConfig>({
|
||||
bearerAuthKey: '',
|
||||
});
|
||||
|
||||
const [installConfig, setInstallConfig] = useState<InstallConfig>({
|
||||
pythonIndexUrl: '',
|
||||
npmRegistry: '',
|
||||
baseUrl: 'http://localhost:3000',
|
||||
});
|
||||
|
||||
const [smartRoutingConfig, setSmartRoutingConfig] = useState<SmartRoutingConfig>({
|
||||
enabled: false,
|
||||
dbUrl: '',
|
||||
openaiApiBaseUrl: '',
|
||||
openaiApiKey: '',
|
||||
openaiApiEmbeddingModel: '',
|
||||
});
|
||||
|
||||
const [mcpRouterConfig, setMCPRouterConfig] = useState<MCPRouterConfig>({
|
||||
apiKey: '',
|
||||
referer: 'https://www.mcphubx.com',
|
||||
title: 'MCPHub',
|
||||
baseUrl: 'https://api.mcprouter.to/v1',
|
||||
});
|
||||
|
||||
const [oauthServerConfig, setOAuthServerConfig] = useState<OAuthServerConfig>(
|
||||
getDefaultOAuthServerConfig(),
|
||||
);
|
||||
|
||||
const [nameSeparator, setNameSeparator] = useState<string>('-');
|
||||
const [enableSessionRebuild, setEnableSessionRebuild] = useState<boolean>(false);
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [refreshKey, setRefreshKey] = useState(0);
|
||||
|
||||
// Trigger a refresh of the settings data
|
||||
const triggerRefresh = useCallback(() => {
|
||||
setRefreshKey((prev) => prev + 1);
|
||||
}, []);
|
||||
|
||||
// Fetch current settings
|
||||
const fetchSettings = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data: ApiResponse<SystemSettings> = await apiGet('/settings');
|
||||
|
||||
if (data.success && data.data?.systemConfig?.routing) {
|
||||
setRoutingConfig({
|
||||
enableGlobalRoute: data.data.systemConfig.routing.enableGlobalRoute ?? true,
|
||||
enableGroupNameRoute: data.data.systemConfig.routing.enableGroupNameRoute ?? true,
|
||||
enableBearerAuth: data.data.systemConfig.routing.enableBearerAuth ?? false,
|
||||
bearerAuthKey: data.data.systemConfig.routing.bearerAuthKey || '',
|
||||
skipAuth: data.data.systemConfig.routing.skipAuth ?? false,
|
||||
});
|
||||
}
|
||||
if (data.success && data.data?.systemConfig?.install) {
|
||||
setInstallConfig({
|
||||
pythonIndexUrl: data.data.systemConfig.install.pythonIndexUrl || '',
|
||||
npmRegistry: data.data.systemConfig.install.npmRegistry || '',
|
||||
baseUrl: data.data.systemConfig.install.baseUrl || 'http://localhost:3000',
|
||||
});
|
||||
}
|
||||
if (data.success && data.data?.systemConfig?.smartRouting) {
|
||||
setSmartRoutingConfig({
|
||||
enabled: data.data.systemConfig.smartRouting.enabled ?? false,
|
||||
dbUrl: data.data.systemConfig.smartRouting.dbUrl || '',
|
||||
openaiApiBaseUrl: data.data.systemConfig.smartRouting.openaiApiBaseUrl || '',
|
||||
openaiApiKey: data.data.systemConfig.smartRouting.openaiApiKey || '',
|
||||
openaiApiEmbeddingModel:
|
||||
data.data.systemConfig.smartRouting.openaiApiEmbeddingModel || '',
|
||||
});
|
||||
}
|
||||
if (data.success && data.data?.systemConfig?.mcpRouter) {
|
||||
setMCPRouterConfig({
|
||||
apiKey: data.data.systemConfig.mcpRouter.apiKey || '',
|
||||
referer: data.data.systemConfig.mcpRouter.referer || 'https://www.mcphubx.com',
|
||||
title: data.data.systemConfig.mcpRouter.title || 'MCPHub',
|
||||
baseUrl: data.data.systemConfig.mcpRouter.baseUrl || 'https://api.mcprouter.to/v1',
|
||||
});
|
||||
}
|
||||
if (data.success) {
|
||||
if (data.data?.systemConfig?.oauthServer) {
|
||||
const oauth = data.data.systemConfig.oauthServer;
|
||||
const defaultOauthConfig = getDefaultOAuthServerConfig();
|
||||
const defaultDynamic = defaultOauthConfig.dynamicRegistration;
|
||||
const allowedScopes = Array.isArray(oauth.allowedScopes)
|
||||
? [...oauth.allowedScopes]
|
||||
: [...defaultOauthConfig.allowedScopes];
|
||||
const dynamicAllowedGrantTypes = Array.isArray(
|
||||
oauth.dynamicRegistration?.allowedGrantTypes,
|
||||
)
|
||||
? [...oauth.dynamicRegistration!.allowedGrantTypes!]
|
||||
: [...defaultDynamic.allowedGrantTypes];
|
||||
|
||||
setOAuthServerConfig({
|
||||
enabled: oauth.enabled ?? defaultOauthConfig.enabled,
|
||||
accessTokenLifetime:
|
||||
oauth.accessTokenLifetime ?? defaultOauthConfig.accessTokenLifetime,
|
||||
refreshTokenLifetime:
|
||||
oauth.refreshTokenLifetime ?? defaultOauthConfig.refreshTokenLifetime,
|
||||
authorizationCodeLifetime:
|
||||
oauth.authorizationCodeLifetime ?? defaultOauthConfig.authorizationCodeLifetime,
|
||||
requireClientSecret:
|
||||
oauth.requireClientSecret ?? defaultOauthConfig.requireClientSecret,
|
||||
requireState: oauth.requireState ?? defaultOauthConfig.requireState,
|
||||
allowedScopes,
|
||||
dynamicRegistration: {
|
||||
enabled: oauth.dynamicRegistration?.enabled ?? defaultDynamic.enabled,
|
||||
allowedGrantTypes: dynamicAllowedGrantTypes,
|
||||
requiresAuthentication:
|
||||
oauth.dynamicRegistration?.requiresAuthentication ??
|
||||
defaultDynamic.requiresAuthentication,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
setOAuthServerConfig(getDefaultOAuthServerConfig());
|
||||
}
|
||||
}
|
||||
if (data.success && data.data?.systemConfig?.nameSeparator !== undefined) {
|
||||
setNameSeparator(data.data.systemConfig.nameSeparator);
|
||||
}
|
||||
if (data.success && data.data?.systemConfig?.enableSessionRebuild !== undefined) {
|
||||
setEnableSessionRebuild(data.data.systemConfig.enableSessionRebuild);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch settings:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to fetch settings');
|
||||
// 使用一个稳定的 showToast 引用,避免将其加入依赖数组
|
||||
showToast(t('errors.failedToFetchSettings'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [t]); // 移除 showToast 依赖
|
||||
|
||||
// Update routing configuration
|
||||
const updateRoutingConfig = async (key: keyof RoutingConfig, value: any) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
routing: {
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setRoutingConfig({
|
||||
...routingConfig,
|
||||
[key]: value,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateRouteConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update routing config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update routing config');
|
||||
showToast(t('errors.failedToUpdateRouteConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update install configuration
|
||||
const updateInstallConfig = async (key: keyof InstallConfig, value: string) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
install: {
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setInstallConfig({
|
||||
...installConfig,
|
||||
[key]: value,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateSystemConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update system config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update system config');
|
||||
showToast(t('errors.failedToUpdateSystemConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update smart routing configuration
|
||||
const updateSmartRoutingConfig = async <T extends keyof SmartRoutingConfig>(
|
||||
key: T,
|
||||
value: SmartRoutingConfig[T],
|
||||
) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
smartRouting: {
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setSmartRoutingConfig({
|
||||
...smartRoutingConfig,
|
||||
[key]: value,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateSmartRoutingConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update smart routing config:', error);
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : 'Failed to update smart routing config';
|
||||
setError(errorMessage);
|
||||
showToast(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update multiple smart routing configuration fields at once
|
||||
const updateSmartRoutingConfigBatch = async (updates: Partial<SmartRoutingConfig>) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
smartRouting: updates,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setSmartRoutingConfig({
|
||||
...smartRoutingConfig,
|
||||
...updates,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateSmartRoutingConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update smart routing config:', error);
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : 'Failed to update smart routing config';
|
||||
setError(errorMessage);
|
||||
showToast(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update multiple routing configuration fields at once
|
||||
const updateRoutingConfigBatch = async (updates: Partial<RoutingConfig>) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
routing: updates,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setRoutingConfig({
|
||||
...routingConfig,
|
||||
...updates,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateRouteConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update routing config:', error);
|
||||
setError(error instanceof Error ? error.message : 'Failed to update routing config');
|
||||
showToast(t('errors.failedToUpdateRouteConfig'));
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update MCPRouter configuration
|
||||
const updateMCPRouterConfig = async <T extends keyof MCPRouterConfig>(
|
||||
key: T,
|
||||
value: MCPRouterConfig[T],
|
||||
) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
mcpRouter: {
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setMCPRouterConfig({
|
||||
...mcpRouterConfig,
|
||||
[key]: value,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateSystemConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update MCPRouter config:', error);
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : 'Failed to update MCPRouter config';
|
||||
setError(errorMessage);
|
||||
showToast(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update multiple MCPRouter configuration fields at once
|
||||
const updateMCPRouterConfigBatch = async (updates: Partial<MCPRouterConfig>) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
mcpRouter: updates,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setMCPRouterConfig({
|
||||
...mcpRouterConfig,
|
||||
...updates,
|
||||
});
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateSystemConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update MCPRouter config:', error);
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : 'Failed to update MCPRouter config';
|
||||
setError(errorMessage);
|
||||
showToast(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update OAuth server configuration
|
||||
const updateOAuthServerConfig = async <T extends keyof OAuthServerConfig>(
|
||||
key: T,
|
||||
value: OAuthServerConfig[T],
|
||||
) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
oauthServer: {
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setOAuthServerConfig((prev) => ({
|
||||
...prev,
|
||||
[key]: value,
|
||||
}));
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateSystemConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update OAuth server config:', error);
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : 'Failed to update OAuth server config';
|
||||
setError(errorMessage);
|
||||
showToast(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update multiple OAuth server config fields
|
||||
const updateOAuthServerConfigBatch = async (updates: Partial<OAuthServerConfig>) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
oauthServer: updates,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setOAuthServerConfig((prev) => ({
|
||||
...prev,
|
||||
...updates,
|
||||
}));
|
||||
showToast(t('settings.systemConfigUpdated'));
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateSystemConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update OAuth server config:', error);
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : 'Failed to update OAuth server config';
|
||||
setError(errorMessage);
|
||||
showToast(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update name separator
|
||||
const updateNameSeparator = async (value: string) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
nameSeparator: value,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setNameSeparator(value);
|
||||
showToast(t('settings.restartRequired'), 'info');
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateSystemConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update name separator:', error);
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : 'Failed to update name separator';
|
||||
setError(errorMessage);
|
||||
showToast(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Update session rebuild setting
|
||||
const updateSessionRebuild = async (value: boolean) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const data = await apiPut('/system-config', {
|
||||
enableSessionRebuild: value,
|
||||
});
|
||||
|
||||
if (data.success) {
|
||||
setEnableSessionRebuild(value);
|
||||
showToast(t('settings.restartRequired'), 'info');
|
||||
return true;
|
||||
} else {
|
||||
showToast(data.message || t('errors.failedToUpdateSystemConfig'));
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update session rebuild setting:', error);
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : 'Failed to update session rebuild setting';
|
||||
setError(errorMessage);
|
||||
showToast(errorMessage);
|
||||
return false;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const exportMCPSettings = async (serverName?: string) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
return await apiGet(`/mcp-settings/export?serverName=${serverName ? serverName : ''}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to export MCP settings:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : 'Failed to export MCP settings';
|
||||
setError(errorMessage);
|
||||
showToast(errorMessage);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Fetch settings when the component mounts or refreshKey changes
|
||||
useEffect(() => {
|
||||
fetchSettings();
|
||||
}, [fetchSettings, refreshKey]);
|
||||
|
||||
useEffect(() => {
|
||||
if (routingConfig) {
|
||||
setTempRoutingConfig({
|
||||
bearerAuthKey: routingConfig.bearerAuthKey,
|
||||
});
|
||||
}
|
||||
}, [routingConfig]);
|
||||
|
||||
return {
|
||||
routingConfig,
|
||||
tempRoutingConfig,
|
||||
setTempRoutingConfig,
|
||||
installConfig,
|
||||
smartRoutingConfig,
|
||||
mcpRouterConfig,
|
||||
oauthServerConfig,
|
||||
nameSeparator,
|
||||
enableSessionRebuild,
|
||||
loading,
|
||||
error,
|
||||
setError,
|
||||
triggerRefresh,
|
||||
fetchSettings,
|
||||
updateRoutingConfig,
|
||||
updateInstallConfig,
|
||||
updateSmartRoutingConfig,
|
||||
updateSmartRoutingConfigBatch,
|
||||
updateRoutingConfigBatch,
|
||||
updateMCPRouterConfig,
|
||||
updateMCPRouterConfigBatch,
|
||||
updateOAuthServerConfig,
|
||||
updateOAuthServerConfigBatch,
|
||||
updateNameSeparator,
|
||||
updateSessionRebuild,
|
||||
exportMCPSettings,
|
||||
};
|
||||
return useSettings();
|
||||
};
|
||||
|
||||
@@ -536,7 +536,9 @@
|
||||
"description": "Description",
|
||||
"messages": "Messages",
|
||||
"noDescription": "No description available",
|
||||
"runPromptWithName": "Get Prompt: {{name}}"
|
||||
"runPromptWithName": "Get Prompt: {{name}}",
|
||||
"descriptionUpdateSuccess": "Prompt description updated successfully",
|
||||
"descriptionUpdateFailed": "Failed to update prompt description"
|
||||
},
|
||||
"settings": {
|
||||
"enableGlobalRoute": "Enable Global Route",
|
||||
|
||||
@@ -536,7 +536,9 @@
|
||||
"description": "Description",
|
||||
"messages": "Messages",
|
||||
"noDescription": "Aucune description disponible",
|
||||
"runPromptWithName": "Obtenir l'invite : {{name}}"
|
||||
"runPromptWithName": "Obtenir l'invite : {{name}}",
|
||||
"descriptionUpdateSuccess": "Description de l'invite mise à jour avec succès",
|
||||
"descriptionUpdateFailed": "Échec de la mise à jour de la description de l'invite"
|
||||
},
|
||||
"settings": {
|
||||
"enableGlobalRoute": "Activer la route globale",
|
||||
|
||||
@@ -536,7 +536,9 @@
|
||||
"description": "Açıklama",
|
||||
"messages": "Mesajlar",
|
||||
"noDescription": "Kullanılabilir açıklama yok",
|
||||
"runPromptWithName": "İsteği Getir: {{name}}"
|
||||
"runPromptWithName": "İsteği Getir: {{name}}",
|
||||
"descriptionUpdateSuccess": "İstek açıklaması başarıyla güncellendi",
|
||||
"descriptionUpdateFailed": "İstek açıklaması güncellenemedi"
|
||||
},
|
||||
"settings": {
|
||||
"enableGlobalRoute": "Global Yönlendirmeyi Etkinleştir",
|
||||
|
||||
@@ -537,7 +537,9 @@
|
||||
"description": "描述",
|
||||
"messages": "消息",
|
||||
"noDescription": "无描述信息",
|
||||
"runPromptWithName": "获取提示词: {{name}}"
|
||||
"runPromptWithName": "获取提示词: {{name}}",
|
||||
"descriptionUpdateSuccess": "提示词描述更新成功",
|
||||
"descriptionUpdateFailed": "更新提示词描述失败"
|
||||
},
|
||||
"settings": {
|
||||
"enableGlobalRoute": "启用全局路由",
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
"jest-environment-node": "^30.0.5",
|
||||
"jest-mock-extended": "4.0.0",
|
||||
"lucide-react": "^0.552.0",
|
||||
"next": "^15.5.6",
|
||||
"next": "^15.5.0",
|
||||
"postcss": "^8.5.6",
|
||||
"prettier": "^3.6.2",
|
||||
"react": "19.1.1",
|
||||
|
||||
384
pnpm-lock.yaml
generated
384
pnpm-lock.yaml
generated
@@ -194,8 +194,8 @@ importers:
|
||||
specifier: ^0.552.0
|
||||
version: 0.552.0(react@19.1.1)
|
||||
next:
|
||||
specifier: ^15.5.6
|
||||
version: 15.5.6(@babel/core@7.28.4)(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||
specifier: ^15.5.0
|
||||
version: 15.5.2(@babel/core@7.28.4)(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||
postcss:
|
||||
specifier: ^8.5.6
|
||||
version: 8.5.6
|
||||
@@ -484,8 +484,8 @@ packages:
|
||||
'@emnapi/core@1.5.0':
|
||||
resolution: {integrity: sha512-sbP8GzB1WDzacS8fgNPpHlp6C9VZe+SJP3F90W9rLemaQj2PzIuTEl1qDOYQf58YIpyjViI24y9aPWCjEzY2cg==}
|
||||
|
||||
'@emnapi/runtime@1.7.1':
|
||||
resolution: {integrity: sha512-PVtJr5CmLwYAU9PZDMITZoR5iAOShYREoR45EyyLrbntV50mdePTgUn4AmOw90Ifcj+x2kRjdzr1HP3RrNiHGA==}
|
||||
'@emnapi/runtime@1.5.0':
|
||||
resolution: {integrity: sha512-97/BJ3iXHww3djw6hYIfErCZFee7qCtrneuLa20UXFCOTCfBM2cvQHjWJ2EG0s0MtdNwInarqCTz35i4wWXHsQ==}
|
||||
|
||||
'@emnapi/wasi-threads@1.1.0':
|
||||
resolution: {integrity: sha512-WI0DdZ8xFSbgMjR1sFsKABJ/C5OnRrjT06JXbZKexJGrDuPTzZdDYfFlsgcCXCyf+suG5QU2e/y1Wo2V/OapLQ==}
|
||||
@@ -833,139 +833,124 @@ packages:
|
||||
resolution: {integrity: sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==}
|
||||
deprecated: Use @eslint/object-schema instead
|
||||
|
||||
'@img/colour@1.0.0':
|
||||
resolution: {integrity: sha512-A5P/LfWGFSl6nsckYtjw9da+19jB8hkJ6ACTGcDfEJ0aE+l2n2El7dsVM7UVHZQ9s2lmYMWlrS21YLy2IR1LUw==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
'@img/sharp-darwin-arm64@0.34.5':
|
||||
resolution: {integrity: sha512-imtQ3WMJXbMY4fxb/Ndp6HBTNVtWCUI0WdobyheGf5+ad6xX8VIDO8u2xE4qc/fr08CKG/7dDseFtn6M6g/r3w==}
|
||||
'@img/sharp-darwin-arm64@0.34.3':
|
||||
resolution: {integrity: sha512-ryFMfvxxpQRsgZJqBd4wsttYQbCxsJksrv9Lw/v798JcQ8+w84mBWuXwl+TT0WJ/WrYOLaYpwQXi3sA9nTIaIg==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
|
||||
'@img/sharp-darwin-x64@0.34.5':
|
||||
resolution: {integrity: sha512-YNEFAF/4KQ/PeW0N+r+aVVsoIY0/qxxikF2SWdp+NRkmMB7y9LBZAVqQ4yhGCm/H3H270OSykqmQMKLBhBJDEw==}
|
||||
'@img/sharp-darwin-x64@0.34.3':
|
||||
resolution: {integrity: sha512-yHpJYynROAj12TA6qil58hmPmAwxKKC7reUqtGLzsOHfP7/rniNGTL8tjWX6L3CTV4+5P4ypcS7Pp+7OB+8ihA==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [x64]
|
||||
os: [darwin]
|
||||
|
||||
'@img/sharp-libvips-darwin-arm64@1.2.4':
|
||||
resolution: {integrity: sha512-zqjjo7RatFfFoP0MkQ51jfuFZBnVE2pRiaydKJ1G/rHZvnsrHAOcQALIi9sA5co5xenQdTugCvtb1cuf78Vf4g==}
|
||||
'@img/sharp-libvips-darwin-arm64@1.2.0':
|
||||
resolution: {integrity: sha512-sBZmpwmxqwlqG9ueWFXtockhsxefaV6O84BMOrhtg/YqbTaRdqDE7hxraVE3y6gVM4eExmfzW4a8el9ArLeEiQ==}
|
||||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
|
||||
'@img/sharp-libvips-darwin-x64@1.2.4':
|
||||
resolution: {integrity: sha512-1IOd5xfVhlGwX+zXv2N93k0yMONvUlANylbJw1eTah8K/Jtpi15KC+WSiaX/nBmbm2HxRM1gZ0nSdjSsrZbGKg==}
|
||||
'@img/sharp-libvips-darwin-x64@1.2.0':
|
||||
resolution: {integrity: sha512-M64XVuL94OgiNHa5/m2YvEQI5q2cl9d/wk0qFTDVXcYzi43lxuiFTftMR1tOnFQovVXNZJ5TURSDK2pNe9Yzqg==}
|
||||
cpu: [x64]
|
||||
os: [darwin]
|
||||
|
||||
'@img/sharp-libvips-linux-arm64@1.2.4':
|
||||
resolution: {integrity: sha512-excjX8DfsIcJ10x1Kzr4RcWe1edC9PquDRRPx3YVCvQv+U5p7Yin2s32ftzikXojb1PIFc/9Mt28/y+iRklkrw==}
|
||||
'@img/sharp-libvips-linux-arm64@1.2.0':
|
||||
resolution: {integrity: sha512-RXwd0CgG+uPRX5YYrkzKyalt2OJYRiJQ8ED/fi1tq9WQW2jsQIn0tqrlR5l5dr/rjqq6AHAxURhj2DVjyQWSOA==}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-libvips-linux-arm@1.2.4':
|
||||
resolution: {integrity: sha512-bFI7xcKFELdiNCVov8e44Ia4u2byA+l3XtsAj+Q8tfCwO6BQ8iDojYdvoPMqsKDkuoOo+X6HZA0s0q11ANMQ8A==}
|
||||
'@img/sharp-libvips-linux-arm@1.2.0':
|
||||
resolution: {integrity: sha512-mWd2uWvDtL/nvIzThLq3fr2nnGfyr/XMXlq8ZJ9WMR6PXijHlC3ksp0IpuhK6bougvQrchUAfzRLnbsen0Cqvw==}
|
||||
cpu: [arm]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-libvips-linux-ppc64@1.2.4':
|
||||
resolution: {integrity: sha512-FMuvGijLDYG6lW+b/UvyilUWu5Ayu+3r2d1S8notiGCIyYU/76eig1UfMmkZ7vwgOrzKzlQbFSuQfgm7GYUPpA==}
|
||||
'@img/sharp-libvips-linux-ppc64@1.2.0':
|
||||
resolution: {integrity: sha512-Xod/7KaDDHkYu2phxxfeEPXfVXFKx70EAFZ0qyUdOjCcxbjqyJOEUpDe6RIyaunGxT34Anf9ue/wuWOqBW2WcQ==}
|
||||
cpu: [ppc64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-libvips-linux-riscv64@1.2.4':
|
||||
resolution: {integrity: sha512-oVDbcR4zUC0ce82teubSm+x6ETixtKZBh/qbREIOcI3cULzDyb18Sr/Wcyx7NRQeQzOiHTNbZFF1UwPS2scyGA==}
|
||||
cpu: [riscv64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-libvips-linux-s390x@1.2.4':
|
||||
resolution: {integrity: sha512-qmp9VrzgPgMoGZyPvrQHqk02uyjA0/QrTO26Tqk6l4ZV0MPWIW6LTkqOIov+J1yEu7MbFQaDpwdwJKhbJvuRxQ==}
|
||||
'@img/sharp-libvips-linux-s390x@1.2.0':
|
||||
resolution: {integrity: sha512-eMKfzDxLGT8mnmPJTNMcjfO33fLiTDsrMlUVcp6b96ETbnJmd4uvZxVJSKPQfS+odwfVaGifhsB07J1LynFehw==}
|
||||
cpu: [s390x]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-libvips-linux-x64@1.2.4':
|
||||
resolution: {integrity: sha512-tJxiiLsmHc9Ax1bz3oaOYBURTXGIRDODBqhveVHonrHJ9/+k89qbLl0bcJns+e4t4rvaNBxaEZsFtSfAdquPrw==}
|
||||
'@img/sharp-libvips-linux-x64@1.2.0':
|
||||
resolution: {integrity: sha512-ZW3FPWIc7K1sH9E3nxIGB3y3dZkpJlMnkk7z5tu1nSkBoCgw2nSRTFHI5pB/3CQaJM0pdzMF3paf9ckKMSE9Tg==}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-libvips-linuxmusl-arm64@1.2.4':
|
||||
resolution: {integrity: sha512-FVQHuwx1IIuNow9QAbYUzJ+En8KcVm9Lk5+uGUQJHaZmMECZmOlix9HnH7n1TRkXMS0pGxIJokIVB9SuqZGGXw==}
|
||||
'@img/sharp-libvips-linuxmusl-arm64@1.2.0':
|
||||
resolution: {integrity: sha512-UG+LqQJbf5VJ8NWJ5Z3tdIe/HXjuIdo4JeVNADXBFuG7z9zjoegpzzGIyV5zQKi4zaJjnAd2+g2nna8TZvuW9Q==}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-libvips-linuxmusl-x64@1.2.4':
|
||||
resolution: {integrity: sha512-+LpyBk7L44ZIXwz/VYfglaX/okxezESc6UxDSoyo2Ks6Jxc4Y7sGjpgU9s4PMgqgjj1gZCylTieNamqA1MF7Dg==}
|
||||
'@img/sharp-libvips-linuxmusl-x64@1.2.0':
|
||||
resolution: {integrity: sha512-SRYOLR7CXPgNze8akZwjoGBoN1ThNZoqpOgfnOxmWsklTGVfJiGJoC/Lod7aNMGA1jSsKWM1+HRX43OP6p9+6Q==}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-linux-arm64@0.34.5':
|
||||
resolution: {integrity: sha512-bKQzaJRY/bkPOXyKx5EVup7qkaojECG6NLYswgktOZjaXecSAeCWiZwwiFf3/Y+O1HrauiE3FVsGxFg8c24rZg==}
|
||||
'@img/sharp-linux-arm64@0.34.3':
|
||||
resolution: {integrity: sha512-QdrKe3EvQrqwkDrtuTIjI0bu6YEJHTgEeqdzI3uWJOH6G1O8Nl1iEeVYRGdj1h5I21CqxSvQp1Yv7xeU3ZewbA==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-linux-arm@0.34.5':
|
||||
resolution: {integrity: sha512-9dLqsvwtg1uuXBGZKsxem9595+ujv0sJ6Vi8wcTANSFpwV/GONat5eCkzQo/1O6zRIkh0m/8+5BjrRr7jDUSZw==}
|
||||
'@img/sharp-linux-arm@0.34.3':
|
||||
resolution: {integrity: sha512-oBK9l+h6KBN0i3dC8rYntLiVfW8D8wH+NPNT3O/WBHeW0OQWCjfWksLUaPidsrDKpJgXp3G3/hkmhptAW0I3+A==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [arm]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-linux-ppc64@0.34.5':
|
||||
resolution: {integrity: sha512-7zznwNaqW6YtsfrGGDA6BRkISKAAE1Jo0QdpNYXNMHu2+0dTrPflTLNkpc8l7MUP5M16ZJcUvysVWWrMefZquA==}
|
||||
'@img/sharp-linux-ppc64@0.34.3':
|
||||
resolution: {integrity: sha512-GLtbLQMCNC5nxuImPR2+RgrviwKwVql28FWZIW1zWruy6zLgA5/x2ZXk3mxj58X/tszVF69KK0Is83V8YgWhLA==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [ppc64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-linux-riscv64@0.34.5':
|
||||
resolution: {integrity: sha512-51gJuLPTKa7piYPaVs8GmByo7/U7/7TZOq+cnXJIHZKavIRHAP77e3N2HEl3dgiqdD/w0yUfiJnII77PuDDFdw==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [riscv64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-linux-s390x@0.34.5':
|
||||
resolution: {integrity: sha512-nQtCk0PdKfho3eC5MrbQoigJ2gd1CgddUMkabUj+rBevs8tZ2cULOx46E7oyX+04WGfABgIwmMC0VqieTiR4jg==}
|
||||
'@img/sharp-linux-s390x@0.34.3':
|
||||
resolution: {integrity: sha512-3gahT+A6c4cdc2edhsLHmIOXMb17ltffJlxR0aC2VPZfwKoTGZec6u5GrFgdR7ciJSsHT27BD3TIuGcuRT0KmQ==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [s390x]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-linux-x64@0.34.5':
|
||||
resolution: {integrity: sha512-MEzd8HPKxVxVenwAa+JRPwEC7QFjoPWuS5NZnBt6B3pu7EG2Ge0id1oLHZpPJdn3OQK+BQDiw9zStiHBTJQQQQ==}
|
||||
'@img/sharp-linux-x64@0.34.3':
|
||||
resolution: {integrity: sha512-8kYso8d806ypnSq3/Ly0QEw90V5ZoHh10yH0HnrzOCr6DKAPI6QVHvwleqMkVQ0m+fc7EH8ah0BB0QPuWY6zJQ==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-linuxmusl-arm64@0.34.5':
|
||||
resolution: {integrity: sha512-fprJR6GtRsMt6Kyfq44IsChVZeGN97gTD331weR1ex1c1rypDEABN6Tm2xa1wE6lYb5DdEnk03NZPqA7Id21yg==}
|
||||
'@img/sharp-linuxmusl-arm64@0.34.3':
|
||||
resolution: {integrity: sha512-vAjbHDlr4izEiXM1OTggpCcPg9tn4YriK5vAjowJsHwdBIdx0fYRsURkxLG2RLm9gyBq66gwtWI8Gx0/ov+JKQ==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-linuxmusl-x64@0.34.5':
|
||||
resolution: {integrity: sha512-Jg8wNT1MUzIvhBFxViqrEhWDGzqymo3sV7z7ZsaWbZNDLXRJZoRGrjulp60YYtV4wfY8VIKcWidjojlLcWrd8Q==}
|
||||
'@img/sharp-linuxmusl-x64@0.34.3':
|
||||
resolution: {integrity: sha512-gCWUn9547K5bwvOn9l5XGAEjVTTRji4aPTqLzGXHvIr6bIDZKNTA34seMPgM0WmSf+RYBH411VavCejp3PkOeQ==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@img/sharp-wasm32@0.34.5':
|
||||
resolution: {integrity: sha512-OdWTEiVkY2PHwqkbBI8frFxQQFekHaSSkUIJkwzclWZe64O1X4UlUjqqqLaPbUpMOQk6FBu/HtlGXNblIs0huw==}
|
||||
'@img/sharp-wasm32@0.34.3':
|
||||
resolution: {integrity: sha512-+CyRcpagHMGteySaWos8IbnXcHgfDn7pO2fiC2slJxvNq9gDipYBN42/RagzctVRKgxATmfqOSulgZv5e1RdMg==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [wasm32]
|
||||
|
||||
'@img/sharp-win32-arm64@0.34.5':
|
||||
resolution: {integrity: sha512-WQ3AgWCWYSb2yt+IG8mnC6Jdk9Whs7O0gxphblsLvdhSpSTtmu69ZG1Gkb6NuvxsNACwiPV6cNSZNzt0KPsw7g==}
|
||||
'@img/sharp-win32-arm64@0.34.3':
|
||||
resolution: {integrity: sha512-MjnHPnbqMXNC2UgeLJtX4XqoVHHlZNd+nPt1kRPmj63wURegwBhZlApELdtxM2OIZDRv/DFtLcNhVbd1z8GYXQ==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [arm64]
|
||||
os: [win32]
|
||||
|
||||
'@img/sharp-win32-ia32@0.34.5':
|
||||
resolution: {integrity: sha512-FV9m/7NmeCmSHDD5j4+4pNI8Cp3aW+JvLoXcTUo0IqyjSfAZJ8dIUmijx1qaJsIiU+Hosw6xM5KijAWRJCSgNg==}
|
||||
'@img/sharp-win32-ia32@0.34.3':
|
||||
resolution: {integrity: sha512-xuCdhH44WxuXgOM714hn4amodJMZl3OEvf0GVTm0BEyMeA2to+8HEdRPShH0SLYptJY1uBw+SCFP9WVQi1Q/cw==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [ia32]
|
||||
os: [win32]
|
||||
|
||||
'@img/sharp-win32-x64@0.34.5':
|
||||
resolution: {integrity: sha512-+29YMsqY2/9eFEiW93eqWnuLcWcufowXewwSNIT6UwZdUUCrM3oFjMWH/Z6/TMmb4hlFenmfAVbpWeup2jryCw==}
|
||||
'@img/sharp-win32-x64@0.34.3':
|
||||
resolution: {integrity: sha512-OWwz05d++TxzLEv4VnsTz5CmZ6mI6S05sfQGEMrNrQcOEERbX46332IvE7pO/EUiw7jUrrS40z/M7kPyjfl04g==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
cpu: [x64]
|
||||
os: [win32]
|
||||
@@ -1117,53 +1102,53 @@ packages:
|
||||
'@napi-rs/wasm-runtime@0.2.12':
|
||||
resolution: {integrity: sha512-ZVWUcfwY4E/yPitQJl481FjFo3K22D6qF0DuFH6Y/nbnE11GY5uguDxZMGXPQ8WQ0128MXQD7TnfHyK4oWoIJQ==}
|
||||
|
||||
'@next/env@15.5.6':
|
||||
resolution: {integrity: sha512-3qBGRW+sCGzgbpc5TS1a0p7eNxnOarGVQhZxfvTdnV0gFI61lX7QNtQ4V1TSREctXzYn5NetbUsLvyqwLFJM6Q==}
|
||||
'@next/env@15.5.2':
|
||||
resolution: {integrity: sha512-Qe06ew4zt12LeO6N7j8/nULSOe3fMXE4dM6xgpBQNvdzyK1sv5y4oAP3bq4LamrvGCZtmRYnW8URFCeX5nFgGg==}
|
||||
|
||||
'@next/swc-darwin-arm64@15.5.6':
|
||||
resolution: {integrity: sha512-ES3nRz7N+L5Umz4KoGfZ4XX6gwHplwPhioVRc25+QNsDa7RtUF/z8wJcbuQ2Tffm5RZwuN2A063eapoJ1u4nPg==}
|
||||
'@next/swc-darwin-arm64@15.5.2':
|
||||
resolution: {integrity: sha512-8bGt577BXGSd4iqFygmzIfTYizHb0LGWqH+qgIF/2EDxS5JsSdERJKA8WgwDyNBZgTIIA4D8qUtoQHmxIIquoQ==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
|
||||
'@next/swc-darwin-x64@15.5.6':
|
||||
resolution: {integrity: sha512-JIGcytAyk9LQp2/nuVZPAtj8uaJ/zZhsKOASTjxDug0SPU9LAM3wy6nPU735M1OqacR4U20LHVF5v5Wnl9ptTA==}
|
||||
'@next/swc-darwin-x64@15.5.2':
|
||||
resolution: {integrity: sha512-2DjnmR6JHK4X+dgTXt5/sOCu/7yPtqpYt8s8hLkHFK3MGkka2snTv3yRMdHvuRtJVkPwCGsvBSwmoQCHatauFQ==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [darwin]
|
||||
|
||||
'@next/swc-linux-arm64-gnu@15.5.6':
|
||||
resolution: {integrity: sha512-qvz4SVKQ0P3/Im9zcS2RmfFL/UCQnsJKJwQSkissbngnB/12c6bZTCB0gHTexz1s6d/mD0+egPKXAIRFVS7hQg==}
|
||||
'@next/swc-linux-arm64-gnu@15.5.2':
|
||||
resolution: {integrity: sha512-3j7SWDBS2Wov/L9q0mFJtEvQ5miIqfO4l7d2m9Mo06ddsgUK8gWfHGgbjdFlCp2Ek7MmMQZSxpGFqcC8zGh2AA==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@next/swc-linux-arm64-musl@15.5.6':
|
||||
resolution: {integrity: sha512-FsbGVw3SJz1hZlvnWD+T6GFgV9/NYDeLTNQB2MXoPN5u9VA9OEDy6fJEfePfsUKAhJufFbZLgp0cPxMuV6SV0w==}
|
||||
'@next/swc-linux-arm64-musl@15.5.2':
|
||||
resolution: {integrity: sha512-s6N8k8dF9YGc5T01UPQ08yxsK6fUow5gG1/axWc1HVVBYQBgOjca4oUZF7s4p+kwhkB1bDSGR8QznWrFZ/Rt5g==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@next/swc-linux-x64-gnu@15.5.6':
|
||||
resolution: {integrity: sha512-3QnHGFWlnvAgyxFxt2Ny8PTpXtQD7kVEeaFat5oPAHHI192WKYB+VIKZijtHLGdBBvc16tiAkPTDmQNOQ0dyrA==}
|
||||
'@next/swc-linux-x64-gnu@15.5.2':
|
||||
resolution: {integrity: sha512-o1RV/KOODQh6dM6ZRJGZbc+MOAHww33Vbs5JC9Mp1gDk8cpEO+cYC/l7rweiEalkSm5/1WGa4zY7xrNwObN4+Q==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@next/swc-linux-x64-musl@15.5.6':
|
||||
resolution: {integrity: sha512-OsGX148sL+TqMK9YFaPFPoIaJKbFJJxFzkXZljIgA9hjMjdruKht6xDCEv1HLtlLNfkx3c5w2GLKhj7veBQizQ==}
|
||||
'@next/swc-linux-x64-musl@15.5.2':
|
||||
resolution: {integrity: sha512-/VUnh7w8RElYZ0IV83nUcP/J4KJ6LLYliiBIri3p3aW2giF+PAVgZb6mk8jbQSB3WlTai8gEmCAr7kptFa1H6g==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@next/swc-win32-arm64-msvc@15.5.6':
|
||||
resolution: {integrity: sha512-ONOMrqWxdzXDJNh2n60H6gGyKed42Ieu6UTVPZteXpuKbLZTH4G4eBMsr5qWgOBA+s7F+uB4OJbZnrkEDnZ5Fg==}
|
||||
'@next/swc-win32-arm64-msvc@15.5.2':
|
||||
resolution: {integrity: sha512-sMPyTvRcNKXseNQ/7qRfVRLa0VhR0esmQ29DD6pqvG71+JdVnESJaHPA8t7bc67KD5spP3+DOCNLhqlEI2ZgQg==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [win32]
|
||||
|
||||
'@next/swc-win32-x64-msvc@15.5.6':
|
||||
resolution: {integrity: sha512-pxK4VIjFRx1MY92UycLOOw7dTdvccWsNETQ0kDHkBlcFH1GrTLUjSiHU1ohrznnux6TqRHgv5oflhfIWZwVROQ==}
|
||||
'@next/swc-win32-x64-msvc@15.5.2':
|
||||
resolution: {integrity: sha512-W5VvyZHnxG/2ukhZF/9Ikdra5fdNftxI6ybeVKYvBPDtyx7x4jPPSNduUkfH5fo3zG0JQ0bPxgy41af2JX5D4Q==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [win32]
|
||||
@@ -2311,8 +2296,8 @@ packages:
|
||||
caniuse-lite@1.0.30001737:
|
||||
resolution: {integrity: sha512-BiloLiXtQNrY5UyF0+1nSJLXUENuhka2pzy2Fx5pGxqavdrxSCW4U6Pn/PoG3Efspi2frRbHpBV2XsrPE6EDlw==}
|
||||
|
||||
caniuse-lite@1.0.30001757:
|
||||
resolution: {integrity: sha512-r0nnL/I28Zi/yjk1el6ilj27tKcdjLsNqAOZr0yVjWPrSQyHgKI2INaEWw21bAQSv2LXRt1XuCS/GomNpWOxsQ==}
|
||||
caniuse-lite@1.0.30001739:
|
||||
resolution: {integrity: sha512-y+j60d6ulelrNSwpPyrHdl+9mJnQzHBr08xm48Qno0nSk4h3Qojh+ziv2qE6rXf4k3tadF4o1J/1tAbVm1NtnA==}
|
||||
|
||||
chalk@4.1.2:
|
||||
resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==}
|
||||
@@ -2381,6 +2366,13 @@ packages:
|
||||
color-name@1.1.4:
|
||||
resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==}
|
||||
|
||||
color-string@1.9.1:
|
||||
resolution: {integrity: sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==}
|
||||
|
||||
color@4.2.3:
|
||||
resolution: {integrity: sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==}
|
||||
engines: {node: '>=12.5.0'}
|
||||
|
||||
combined-stream@1.0.8:
|
||||
resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==}
|
||||
engines: {node: '>= 0.8'}
|
||||
@@ -2530,10 +2522,6 @@ packages:
|
||||
resolution: {integrity: sha512-ecqj/sy1jcK1uWrwpR67UhYrIFQ+5WlGxth34WquCbamhFA6hkkwiu37o6J5xCHdo1oixJRfVRw+ywV+Hq/0Aw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
detect-libc@2.1.2:
|
||||
resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
detect-newline@3.1.0:
|
||||
resolution: {integrity: sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -3018,6 +3006,9 @@ packages:
|
||||
is-arrayish@0.2.1:
|
||||
resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==}
|
||||
|
||||
is-arrayish@0.3.2:
|
||||
resolution: {integrity: sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==}
|
||||
|
||||
is-binary-path@2.1.0:
|
||||
resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -3617,8 +3608,8 @@ packages:
|
||||
neo-async@2.6.2:
|
||||
resolution: {integrity: sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==}
|
||||
|
||||
next@15.5.6:
|
||||
resolution: {integrity: sha512-zTxsnI3LQo3c9HSdSf91O1jMNsEzIXDShXd4wVdg9y5shwLqBXi4ZtUUJyB86KGVSJLZx0PFONvO54aheGX8QQ==}
|
||||
next@15.5.2:
|
||||
resolution: {integrity: sha512-H8Otr7abj1glFhbGnvUt3gz++0AF1+QoCXEBmd/6aKbfdFwrn0LpA836Ed5+00va/7HQSDD+mOoVhn3tNy3e/Q==}
|
||||
engines: {node: ^18.18.0 || ^19.8.0 || >= 20.0.0}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
@@ -4094,11 +4085,6 @@ packages:
|
||||
engines: {node: '>=10'}
|
||||
hasBin: true
|
||||
|
||||
semver@7.7.3:
|
||||
resolution: {integrity: sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==}
|
||||
engines: {node: '>=10'}
|
||||
hasBin: true
|
||||
|
||||
send@0.19.0:
|
||||
resolution: {integrity: sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==}
|
||||
engines: {node: '>= 0.8.0'}
|
||||
@@ -4130,8 +4116,8 @@ packages:
|
||||
engines: {node: '>= 0.10'}
|
||||
hasBin: true
|
||||
|
||||
sharp@0.34.5:
|
||||
resolution: {integrity: sha512-Ou9I5Ft9WNcCbXrU9cMgPBcCK8LiwLqcbywW3t4oDV37n1pzpuNLsYiAV8eODnjbtQlSDwZ2cUEeQz4E54Hltg==}
|
||||
sharp@0.34.3:
|
||||
resolution: {integrity: sha512-eX2IQ6nFohW4DbvHIOLRB3MHFpYqaqvXd3Tp5e/T/dSH83fxaNJQRvDMhASmkNTsNTVF2/OOopzRCt7xokgPfg==}
|
||||
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
|
||||
|
||||
shebang-command@2.0.0:
|
||||
@@ -4169,6 +4155,9 @@ packages:
|
||||
resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==}
|
||||
engines: {node: '>=14'}
|
||||
|
||||
simple-swizzle@0.2.2:
|
||||
resolution: {integrity: sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==}
|
||||
|
||||
sisteransi@1.0.5:
|
||||
resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==}
|
||||
|
||||
@@ -5012,7 +5001,7 @@ snapshots:
|
||||
tslib: 2.8.1
|
||||
optional: true
|
||||
|
||||
'@emnapi/runtime@1.7.1':
|
||||
'@emnapi/runtime@1.5.0':
|
||||
dependencies:
|
||||
tslib: 2.8.1
|
||||
optional: true
|
||||
@@ -5213,101 +5202,90 @@ snapshots:
|
||||
|
||||
'@humanwhocodes/object-schema@2.0.3': {}
|
||||
|
||||
'@img/colour@1.0.0':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-darwin-arm64@0.34.5':
|
||||
'@img/sharp-darwin-arm64@0.34.3':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-darwin-arm64': 1.2.4
|
||||
'@img/sharp-libvips-darwin-arm64': 1.2.0
|
||||
optional: true
|
||||
|
||||
'@img/sharp-darwin-x64@0.34.5':
|
||||
'@img/sharp-darwin-x64@0.34.3':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-darwin-x64': 1.2.4
|
||||
'@img/sharp-libvips-darwin-x64': 1.2.0
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-darwin-arm64@1.2.4':
|
||||
'@img/sharp-libvips-darwin-arm64@1.2.0':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-darwin-x64@1.2.4':
|
||||
'@img/sharp-libvips-darwin-x64@1.2.0':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-arm64@1.2.4':
|
||||
'@img/sharp-libvips-linux-arm64@1.2.0':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-arm@1.2.4':
|
||||
'@img/sharp-libvips-linux-arm@1.2.0':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-ppc64@1.2.4':
|
||||
'@img/sharp-libvips-linux-ppc64@1.2.0':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-riscv64@1.2.4':
|
||||
'@img/sharp-libvips-linux-s390x@1.2.0':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-s390x@1.2.4':
|
||||
'@img/sharp-libvips-linux-x64@1.2.0':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linux-x64@1.2.4':
|
||||
'@img/sharp-libvips-linuxmusl-arm64@1.2.0':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linuxmusl-arm64@1.2.4':
|
||||
'@img/sharp-libvips-linuxmusl-x64@1.2.0':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-libvips-linuxmusl-x64@1.2.4':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-arm64@0.34.5':
|
||||
'@img/sharp-linux-arm64@0.34.3':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-arm64': 1.2.4
|
||||
'@img/sharp-libvips-linux-arm64': 1.2.0
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-arm@0.34.5':
|
||||
'@img/sharp-linux-arm@0.34.3':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-arm': 1.2.4
|
||||
'@img/sharp-libvips-linux-arm': 1.2.0
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-ppc64@0.34.5':
|
||||
'@img/sharp-linux-ppc64@0.34.3':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-ppc64': 1.2.4
|
||||
'@img/sharp-libvips-linux-ppc64': 1.2.0
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-riscv64@0.34.5':
|
||||
'@img/sharp-linux-s390x@0.34.3':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-riscv64': 1.2.4
|
||||
'@img/sharp-libvips-linux-s390x': 1.2.0
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-s390x@0.34.5':
|
||||
'@img/sharp-linux-x64@0.34.3':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-s390x': 1.2.4
|
||||
'@img/sharp-libvips-linux-x64': 1.2.0
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linux-x64@0.34.5':
|
||||
'@img/sharp-linuxmusl-arm64@0.34.3':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linux-x64': 1.2.4
|
||||
'@img/sharp-libvips-linuxmusl-arm64': 1.2.0
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linuxmusl-arm64@0.34.5':
|
||||
'@img/sharp-linuxmusl-x64@0.34.3':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linuxmusl-arm64': 1.2.4
|
||||
'@img/sharp-libvips-linuxmusl-x64': 1.2.0
|
||||
optional: true
|
||||
|
||||
'@img/sharp-linuxmusl-x64@0.34.5':
|
||||
optionalDependencies:
|
||||
'@img/sharp-libvips-linuxmusl-x64': 1.2.4
|
||||
optional: true
|
||||
|
||||
'@img/sharp-wasm32@0.34.5':
|
||||
'@img/sharp-wasm32@0.34.3':
|
||||
dependencies:
|
||||
'@emnapi/runtime': 1.7.1
|
||||
'@emnapi/runtime': 1.5.0
|
||||
optional: true
|
||||
|
||||
'@img/sharp-win32-arm64@0.34.5':
|
||||
'@img/sharp-win32-arm64@0.34.3':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-win32-ia32@0.34.5':
|
||||
'@img/sharp-win32-ia32@0.34.3':
|
||||
optional: true
|
||||
|
||||
'@img/sharp-win32-x64@0.34.5':
|
||||
'@img/sharp-win32-x64@0.34.3':
|
||||
optional: true
|
||||
|
||||
'@isaacs/cliui@8.0.2':
|
||||
@@ -5593,34 +5571,34 @@ snapshots:
|
||||
'@napi-rs/wasm-runtime@0.2.12':
|
||||
dependencies:
|
||||
'@emnapi/core': 1.5.0
|
||||
'@emnapi/runtime': 1.7.1
|
||||
'@emnapi/runtime': 1.5.0
|
||||
'@tybys/wasm-util': 0.10.1
|
||||
optional: true
|
||||
|
||||
'@next/env@15.5.6': {}
|
||||
'@next/env@15.5.2': {}
|
||||
|
||||
'@next/swc-darwin-arm64@15.5.6':
|
||||
'@next/swc-darwin-arm64@15.5.2':
|
||||
optional: true
|
||||
|
||||
'@next/swc-darwin-x64@15.5.6':
|
||||
'@next/swc-darwin-x64@15.5.2':
|
||||
optional: true
|
||||
|
||||
'@next/swc-linux-arm64-gnu@15.5.6':
|
||||
'@next/swc-linux-arm64-gnu@15.5.2':
|
||||
optional: true
|
||||
|
||||
'@next/swc-linux-arm64-musl@15.5.6':
|
||||
'@next/swc-linux-arm64-musl@15.5.2':
|
||||
optional: true
|
||||
|
||||
'@next/swc-linux-x64-gnu@15.5.6':
|
||||
'@next/swc-linux-x64-gnu@15.5.2':
|
||||
optional: true
|
||||
|
||||
'@next/swc-linux-x64-musl@15.5.6':
|
||||
'@next/swc-linux-x64-musl@15.5.2':
|
||||
optional: true
|
||||
|
||||
'@next/swc-win32-arm64-msvc@15.5.6':
|
||||
'@next/swc-win32-arm64-msvc@15.5.2':
|
||||
optional: true
|
||||
|
||||
'@next/swc-win32-x64-msvc@15.5.6':
|
||||
'@next/swc-win32-x64-msvc@15.5.2':
|
||||
optional: true
|
||||
|
||||
'@noble/hashes@1.8.0': {}
|
||||
@@ -6715,7 +6693,7 @@ snapshots:
|
||||
|
||||
caniuse-lite@1.0.30001737: {}
|
||||
|
||||
caniuse-lite@1.0.30001757: {}
|
||||
caniuse-lite@1.0.30001739: {}
|
||||
|
||||
chalk@4.1.2:
|
||||
dependencies:
|
||||
@@ -6776,6 +6754,18 @@ snapshots:
|
||||
|
||||
color-name@1.1.4: {}
|
||||
|
||||
color-string@1.9.1:
|
||||
dependencies:
|
||||
color-name: 1.1.4
|
||||
simple-swizzle: 0.2.2
|
||||
optional: true
|
||||
|
||||
color@4.2.3:
|
||||
dependencies:
|
||||
color-convert: 2.0.1
|
||||
color-string: 1.9.1
|
||||
optional: true
|
||||
|
||||
combined-stream@1.0.8:
|
||||
dependencies:
|
||||
delayed-stream: 1.0.0
|
||||
@@ -6884,9 +6874,6 @@ snapshots:
|
||||
|
||||
detect-libc@2.1.1: {}
|
||||
|
||||
detect-libc@2.1.2:
|
||||
optional: true
|
||||
|
||||
detect-newline@3.1.0: {}
|
||||
|
||||
dezalgo@1.0.4:
|
||||
@@ -7519,6 +7506,9 @@ snapshots:
|
||||
|
||||
is-arrayish@0.2.1: {}
|
||||
|
||||
is-arrayish@0.3.2:
|
||||
optional: true
|
||||
|
||||
is-binary-path@2.1.0:
|
||||
dependencies:
|
||||
binary-extensions: 2.3.0
|
||||
@@ -8246,25 +8236,25 @@ snapshots:
|
||||
|
||||
neo-async@2.6.2: {}
|
||||
|
||||
next@15.5.6(@babel/core@7.28.4)(react-dom@19.1.1(react@19.1.1))(react@19.1.1):
|
||||
next@15.5.2(@babel/core@7.28.4)(react-dom@19.1.1(react@19.1.1))(react@19.1.1):
|
||||
dependencies:
|
||||
'@next/env': 15.5.6
|
||||
'@next/env': 15.5.2
|
||||
'@swc/helpers': 0.5.15
|
||||
caniuse-lite: 1.0.30001757
|
||||
caniuse-lite: 1.0.30001739
|
||||
postcss: 8.4.31
|
||||
react: 19.1.1
|
||||
react-dom: 19.1.1(react@19.1.1)
|
||||
styled-jsx: 5.1.6(@babel/core@7.28.4)(react@19.1.1)
|
||||
optionalDependencies:
|
||||
'@next/swc-darwin-arm64': 15.5.6
|
||||
'@next/swc-darwin-x64': 15.5.6
|
||||
'@next/swc-linux-arm64-gnu': 15.5.6
|
||||
'@next/swc-linux-arm64-musl': 15.5.6
|
||||
'@next/swc-linux-x64-gnu': 15.5.6
|
||||
'@next/swc-linux-x64-musl': 15.5.6
|
||||
'@next/swc-win32-arm64-msvc': 15.5.6
|
||||
'@next/swc-win32-x64-msvc': 15.5.6
|
||||
sharp: 0.34.5
|
||||
'@next/swc-darwin-arm64': 15.5.2
|
||||
'@next/swc-darwin-x64': 15.5.2
|
||||
'@next/swc-linux-arm64-gnu': 15.5.2
|
||||
'@next/swc-linux-arm64-musl': 15.5.2
|
||||
'@next/swc-linux-x64-gnu': 15.5.2
|
||||
'@next/swc-linux-x64-musl': 15.5.2
|
||||
'@next/swc-win32-arm64-msvc': 15.5.2
|
||||
'@next/swc-win32-x64-msvc': 15.5.2
|
||||
sharp: 0.34.3
|
||||
transitivePeerDependencies:
|
||||
- '@babel/core'
|
||||
- babel-plugin-macros
|
||||
@@ -8682,9 +8672,6 @@ snapshots:
|
||||
|
||||
semver@7.7.2: {}
|
||||
|
||||
semver@7.7.3:
|
||||
optional: true
|
||||
|
||||
send@0.19.0:
|
||||
dependencies:
|
||||
debug: 2.6.9
|
||||
@@ -8756,36 +8743,34 @@ snapshots:
|
||||
safe-buffer: 5.2.1
|
||||
to-buffer: 1.2.2
|
||||
|
||||
sharp@0.34.5:
|
||||
sharp@0.34.3:
|
||||
dependencies:
|
||||
'@img/colour': 1.0.0
|
||||
detect-libc: 2.1.2
|
||||
semver: 7.7.3
|
||||
color: 4.2.3
|
||||
detect-libc: 2.0.4
|
||||
semver: 7.7.2
|
||||
optionalDependencies:
|
||||
'@img/sharp-darwin-arm64': 0.34.5
|
||||
'@img/sharp-darwin-x64': 0.34.5
|
||||
'@img/sharp-libvips-darwin-arm64': 1.2.4
|
||||
'@img/sharp-libvips-darwin-x64': 1.2.4
|
||||
'@img/sharp-libvips-linux-arm': 1.2.4
|
||||
'@img/sharp-libvips-linux-arm64': 1.2.4
|
||||
'@img/sharp-libvips-linux-ppc64': 1.2.4
|
||||
'@img/sharp-libvips-linux-riscv64': 1.2.4
|
||||
'@img/sharp-libvips-linux-s390x': 1.2.4
|
||||
'@img/sharp-libvips-linux-x64': 1.2.4
|
||||
'@img/sharp-libvips-linuxmusl-arm64': 1.2.4
|
||||
'@img/sharp-libvips-linuxmusl-x64': 1.2.4
|
||||
'@img/sharp-linux-arm': 0.34.5
|
||||
'@img/sharp-linux-arm64': 0.34.5
|
||||
'@img/sharp-linux-ppc64': 0.34.5
|
||||
'@img/sharp-linux-riscv64': 0.34.5
|
||||
'@img/sharp-linux-s390x': 0.34.5
|
||||
'@img/sharp-linux-x64': 0.34.5
|
||||
'@img/sharp-linuxmusl-arm64': 0.34.5
|
||||
'@img/sharp-linuxmusl-x64': 0.34.5
|
||||
'@img/sharp-wasm32': 0.34.5
|
||||
'@img/sharp-win32-arm64': 0.34.5
|
||||
'@img/sharp-win32-ia32': 0.34.5
|
||||
'@img/sharp-win32-x64': 0.34.5
|
||||
'@img/sharp-darwin-arm64': 0.34.3
|
||||
'@img/sharp-darwin-x64': 0.34.3
|
||||
'@img/sharp-libvips-darwin-arm64': 1.2.0
|
||||
'@img/sharp-libvips-darwin-x64': 1.2.0
|
||||
'@img/sharp-libvips-linux-arm': 1.2.0
|
||||
'@img/sharp-libvips-linux-arm64': 1.2.0
|
||||
'@img/sharp-libvips-linux-ppc64': 1.2.0
|
||||
'@img/sharp-libvips-linux-s390x': 1.2.0
|
||||
'@img/sharp-libvips-linux-x64': 1.2.0
|
||||
'@img/sharp-libvips-linuxmusl-arm64': 1.2.0
|
||||
'@img/sharp-libvips-linuxmusl-x64': 1.2.0
|
||||
'@img/sharp-linux-arm': 0.34.3
|
||||
'@img/sharp-linux-arm64': 0.34.3
|
||||
'@img/sharp-linux-ppc64': 0.34.3
|
||||
'@img/sharp-linux-s390x': 0.34.3
|
||||
'@img/sharp-linux-x64': 0.34.3
|
||||
'@img/sharp-linuxmusl-arm64': 0.34.3
|
||||
'@img/sharp-linuxmusl-x64': 0.34.3
|
||||
'@img/sharp-wasm32': 0.34.3
|
||||
'@img/sharp-win32-arm64': 0.34.3
|
||||
'@img/sharp-win32-ia32': 0.34.3
|
||||
'@img/sharp-win32-x64': 0.34.3
|
||||
optional: true
|
||||
|
||||
shebang-command@2.0.0:
|
||||
@@ -8828,6 +8813,11 @@ snapshots:
|
||||
|
||||
signal-exit@4.1.0: {}
|
||||
|
||||
simple-swizzle@0.2.2:
|
||||
dependencies:
|
||||
is-arrayish: 0.3.2
|
||||
optional: true
|
||||
|
||||
sisteransi@1.0.5: {}
|
||||
|
||||
slash@3.0.0: {}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { loadSettings, loadOriginalSettings } from '../config/index.js';
|
||||
import { getDataService } from '../services/services.js';
|
||||
import { DataService } from '../services/dataService.js';
|
||||
import { IUser } from '../types/index.js';
|
||||
import { getServerDao } from '../dao/DaoFactory.js';
|
||||
|
||||
const dataService: DataService = getDataService();
|
||||
|
||||
@@ -73,17 +74,39 @@ export const getPublicConfig = (req: Request, res: Response): void => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Recursively remove null values from an object
|
||||
*/
|
||||
const removeNullValues = <T>(obj: T): T => {
|
||||
if (obj === null || obj === undefined) {
|
||||
return obj;
|
||||
}
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map((item) => removeNullValues(item)) as T;
|
||||
}
|
||||
if (typeof obj === 'object') {
|
||||
const result: Record<string, unknown> = {};
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (value !== null) {
|
||||
result[key] = removeNullValues(value);
|
||||
}
|
||||
}
|
||||
return result as T;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get MCP settings in JSON format for export/copy
|
||||
* Supports both full settings and individual server configuration
|
||||
*/
|
||||
export const getMcpSettingsJson = (req: Request, res: Response): void => {
|
||||
export const getMcpSettingsJson = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { serverName } = req.query;
|
||||
const settings = loadOriginalSettings();
|
||||
if (serverName && typeof serverName === 'string') {
|
||||
// Return individual server configuration
|
||||
const serverConfig = settings.mcpServers[serverName];
|
||||
// Return individual server configuration using DAO
|
||||
const serverDao = getServerDao();
|
||||
const serverConfig = await serverDao.findById(serverName);
|
||||
if (!serverConfig) {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
@@ -92,16 +115,21 @@ export const getMcpSettingsJson = (req: Request, res: Response): void => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the 'name' field from config as it's used as the key
|
||||
const { name, ...configWithoutName } = serverConfig;
|
||||
// Remove null values from the config
|
||||
const cleanedConfig = removeNullValues(configWithoutName);
|
||||
res.json({
|
||||
success: true,
|
||||
data: {
|
||||
mcpServers: {
|
||||
[serverName]: serverConfig,
|
||||
[name]: cleanedConfig,
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// Return full settings
|
||||
const settings = loadOriginalSettings();
|
||||
res.json({
|
||||
success: true,
|
||||
data: settings,
|
||||
|
||||
@@ -14,10 +14,10 @@ import { IOAuthClient } from '../types/index.js';
|
||||
* GET /api/oauth/clients
|
||||
* Get all OAuth clients
|
||||
*/
|
||||
export const getAllClients = (req: Request, res: Response): void => {
|
||||
export const getAllClients = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const clients = getOAuthClients();
|
||||
|
||||
const clients = await getOAuthClients();
|
||||
|
||||
// Don't expose client secrets in the list
|
||||
const sanitizedClients = clients.map((client) => ({
|
||||
clientId: client.clientId,
|
||||
@@ -45,10 +45,10 @@ export const getAllClients = (req: Request, res: Response): void => {
|
||||
* GET /api/oauth/clients/:clientId
|
||||
* Get a specific OAuth client
|
||||
*/
|
||||
export const getClient = (req: Request, res: Response): void => {
|
||||
export const getClient = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { clientId } = req.params;
|
||||
const client = findOAuthClientById(clientId);
|
||||
const client = await findOAuthClientById(clientId);
|
||||
|
||||
if (!client) {
|
||||
res.status(404).json({
|
||||
@@ -85,7 +85,7 @@ export const getClient = (req: Request, res: Response): void => {
|
||||
* POST /api/oauth/clients
|
||||
* Create a new OAuth client
|
||||
*/
|
||||
export const createClient = (req: Request, res: Response): void => {
|
||||
export const createClient = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
// Validate request
|
||||
const errors = validationResult(req);
|
||||
@@ -105,7 +105,8 @@ export const createClient = (req: Request, res: Response): void => {
|
||||
const clientId = crypto.randomBytes(16).toString('hex');
|
||||
|
||||
// Generate client secret if required
|
||||
const clientSecret = requireSecret !== false ? crypto.randomBytes(32).toString('hex') : undefined;
|
||||
const clientSecret =
|
||||
requireSecret !== false ? crypto.randomBytes(32).toString('hex') : undefined;
|
||||
|
||||
// Create client
|
||||
const client: IOAuthClient = {
|
||||
@@ -118,7 +119,7 @@ export const createClient = (req: Request, res: Response): void => {
|
||||
owner: user?.username || 'admin',
|
||||
};
|
||||
|
||||
const createdClient = createOAuthClient(client);
|
||||
const createdClient = await createOAuthClient(client);
|
||||
|
||||
// Return client with secret (only shown once)
|
||||
res.status(201).json({
|
||||
@@ -139,7 +140,7 @@ export const createClient = (req: Request, res: Response): void => {
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Create OAuth client error:', error);
|
||||
|
||||
|
||||
if (error instanceof Error && error.message.includes('already exists')) {
|
||||
res.status(409).json({
|
||||
success: false,
|
||||
@@ -158,18 +159,19 @@ export const createClient = (req: Request, res: Response): void => {
|
||||
* PUT /api/oauth/clients/:clientId
|
||||
* Update an OAuth client
|
||||
*/
|
||||
export const updateClient = (req: Request, res: Response): void => {
|
||||
export const updateClient = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { clientId } = req.params;
|
||||
const { name, redirectUris, grants, scopes } = req.body;
|
||||
|
||||
const updates: Partial<IOAuthClient> = {};
|
||||
if (name) updates.name = name;
|
||||
if (redirectUris) updates.redirectUris = Array.isArray(redirectUris) ? redirectUris : [redirectUris];
|
||||
if (redirectUris)
|
||||
updates.redirectUris = Array.isArray(redirectUris) ? redirectUris : [redirectUris];
|
||||
if (grants) updates.grants = grants;
|
||||
if (scopes) updates.scopes = scopes;
|
||||
|
||||
const updatedClient = updateOAuthClient(clientId, updates);
|
||||
const updatedClient = await updateOAuthClient(clientId, updates);
|
||||
|
||||
if (!updatedClient) {
|
||||
res.status(404).json({
|
||||
@@ -205,10 +207,10 @@ export const updateClient = (req: Request, res: Response): void => {
|
||||
* DELETE /api/oauth/clients/:clientId
|
||||
* Delete an OAuth client
|
||||
*/
|
||||
export const deleteClient = (req: Request, res: Response): void => {
|
||||
export const deleteClient = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { clientId } = req.params;
|
||||
const deleted = deleteOAuthClient(clientId);
|
||||
const deleted = await deleteOAuthClient(clientId);
|
||||
|
||||
if (!deleted) {
|
||||
res.status(404).json({
|
||||
@@ -235,10 +237,10 @@ export const deleteClient = (req: Request, res: Response): void => {
|
||||
* POST /api/oauth/clients/:clientId/regenerate-secret
|
||||
* Regenerate client secret
|
||||
*/
|
||||
export const regenerateSecret = (req: Request, res: Response): void => {
|
||||
export const regenerateSecret = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { clientId } = req.params;
|
||||
const client = findOAuthClientById(clientId);
|
||||
const client = await findOAuthClientById(clientId);
|
||||
|
||||
if (!client) {
|
||||
res.status(404).json({
|
||||
@@ -250,7 +252,7 @@ export const regenerateSecret = (req: Request, res: Response): void => {
|
||||
|
||||
// Generate new secret
|
||||
const newSecret = crypto.randomBytes(32).toString('hex');
|
||||
const updatedClient = updateOAuthClient(clientId, { clientSecret: newSecret });
|
||||
const updatedClient = await updateOAuthClient(clientId, { clientSecret: newSecret });
|
||||
|
||||
if (!updatedClient) {
|
||||
res.status(500).json({
|
||||
|
||||
@@ -48,7 +48,7 @@ const verifyRegistrationToken = (token: string): string | null => {
|
||||
* RFC 7591 Dynamic Client Registration
|
||||
* Public endpoint for registering new OAuth clients
|
||||
*/
|
||||
export const registerClient = (req: Request, res: Response): void => {
|
||||
export const registerClient = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const settings = loadSettings();
|
||||
const oauthConfig = settings.systemConfig?.oauthServer;
|
||||
@@ -183,7 +183,7 @@ export const registerClient = (req: Request, res: Response): void => {
|
||||
},
|
||||
};
|
||||
|
||||
const createdClient = createOAuthClient(client);
|
||||
const createdClient = await createOAuthClient(client);
|
||||
|
||||
// Build response according to RFC 7591
|
||||
const response: any = {
|
||||
@@ -238,7 +238,7 @@ export const registerClient = (req: Request, res: Response): void => {
|
||||
* RFC 7591 Client Configuration Endpoint
|
||||
* Read client configuration
|
||||
*/
|
||||
export const getClientConfiguration = (req: Request, res: Response): void => {
|
||||
export const getClientConfiguration = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { clientId } = req.params;
|
||||
const authHeader = req.headers.authorization;
|
||||
@@ -262,7 +262,7 @@ export const getClientConfiguration = (req: Request, res: Response): void => {
|
||||
return;
|
||||
}
|
||||
|
||||
const client = findOAuthClientById(clientId);
|
||||
const client = await findOAuthClientById(clientId);
|
||||
if (!client) {
|
||||
res.status(404).json({
|
||||
error: 'invalid_client',
|
||||
@@ -311,7 +311,7 @@ export const getClientConfiguration = (req: Request, res: Response): void => {
|
||||
* RFC 7591 Client Update Endpoint
|
||||
* Update client configuration
|
||||
*/
|
||||
export const updateClientConfiguration = (req: Request, res: Response): void => {
|
||||
export const updateClientConfiguration = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { clientId } = req.params;
|
||||
const authHeader = req.headers.authorization;
|
||||
@@ -335,7 +335,7 @@ export const updateClientConfiguration = (req: Request, res: Response): void =>
|
||||
return;
|
||||
}
|
||||
|
||||
const client = findOAuthClientById(clientId);
|
||||
const client = await findOAuthClientById(clientId);
|
||||
if (!client) {
|
||||
res.status(404).json({
|
||||
error: 'invalid_client',
|
||||
@@ -443,7 +443,7 @@ export const updateClientConfiguration = (req: Request, res: Response): void =>
|
||||
};
|
||||
}
|
||||
|
||||
const updatedClient = updateOAuthClient(clientId, updates);
|
||||
const updatedClient = await updateOAuthClient(clientId, updates);
|
||||
|
||||
if (!updatedClient) {
|
||||
res.status(500).json({
|
||||
@@ -495,7 +495,7 @@ export const updateClientConfiguration = (req: Request, res: Response): void =>
|
||||
* RFC 7591 Client Delete Endpoint
|
||||
* Delete client registration
|
||||
*/
|
||||
export const deleteClientRegistration = (req: Request, res: Response): void => {
|
||||
export const deleteClientRegistration = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { clientId } = req.params;
|
||||
const authHeader = req.headers.authorization;
|
||||
@@ -519,7 +519,7 @@ export const deleteClientRegistration = (req: Request, res: Response): void => {
|
||||
return;
|
||||
}
|
||||
|
||||
const deleted = deleteOAuthClient(clientId);
|
||||
const deleted = await deleteOAuthClient(clientId);
|
||||
|
||||
if (!deleted) {
|
||||
res.status(404).json({
|
||||
|
||||
@@ -212,7 +212,7 @@ export const getAuthorize = async (req: Request, res: Response): Promise<void> =
|
||||
}
|
||||
|
||||
// Verify client
|
||||
const client = findOAuthClientById(client_id as string);
|
||||
const client = await findOAuthClientById(client_id as string);
|
||||
if (!client) {
|
||||
res.status(400).json({ error: 'invalid_client', error_description: 'Client not found' });
|
||||
return;
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
syncToolEmbedding,
|
||||
toggleServerStatus,
|
||||
} from '../services/mcpService.js';
|
||||
import { loadSettings, saveSettings } from '../config/index.js';
|
||||
import { loadSettings } from '../config/index.js';
|
||||
import { syncAllServerToolsEmbeddings } from '../services/vectorSearchService.js';
|
||||
import { createSafeJSON } from '../utils/serialization.js';
|
||||
import { cloneDefaultOAuthServerConfig } from '../constants/oauthServerDefaults.js';
|
||||
@@ -439,8 +439,10 @@ export const toggleTool = async (req: Request, res: Response): Promise<void> =>
|
||||
return;
|
||||
}
|
||||
|
||||
const settings = loadSettings();
|
||||
if (!settings.mcpServers[serverName]) {
|
||||
const serverDao = getServerDao();
|
||||
const server = await serverDao.findById(serverName);
|
||||
|
||||
if (!server) {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
message: 'Server not found',
|
||||
@@ -449,14 +451,15 @@ export const toggleTool = async (req: Request, res: Response): Promise<void> =>
|
||||
}
|
||||
|
||||
// Initialize tools config if it doesn't exist
|
||||
if (!settings.mcpServers[serverName].tools) {
|
||||
settings.mcpServers[serverName].tools = {};
|
||||
}
|
||||
const tools = server.tools || {};
|
||||
|
||||
// Set the tool's enabled state
|
||||
settings.mcpServers[serverName].tools![toolName] = { enabled };
|
||||
// Set the tool's enabled state (preserve existing description if any)
|
||||
tools[toolName] = { ...tools[toolName], enabled };
|
||||
|
||||
if (!saveSettings(settings)) {
|
||||
// Update via DAO (supports both file and database modes)
|
||||
const result = await serverDao.updateTools(serverName, tools);
|
||||
|
||||
if (!result) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'Failed to save settings',
|
||||
@@ -503,8 +506,10 @@ export const updateToolDescription = async (req: Request, res: Response): Promis
|
||||
return;
|
||||
}
|
||||
|
||||
const settings = loadSettings();
|
||||
if (!settings.mcpServers[serverName]) {
|
||||
const serverDao = getServerDao();
|
||||
const server = await serverDao.findById(serverName);
|
||||
|
||||
if (!server) {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
message: 'Server not found',
|
||||
@@ -513,18 +518,18 @@ export const updateToolDescription = async (req: Request, res: Response): Promis
|
||||
}
|
||||
|
||||
// Initialize tools config if it doesn't exist
|
||||
if (!settings.mcpServers[serverName].tools) {
|
||||
settings.mcpServers[serverName].tools = {};
|
||||
}
|
||||
const tools = server.tools || {};
|
||||
|
||||
// Set the tool's description
|
||||
if (!settings.mcpServers[serverName].tools![toolName]) {
|
||||
settings.mcpServers[serverName].tools![toolName] = { enabled: true };
|
||||
if (!tools[toolName]) {
|
||||
tools[toolName] = { enabled: true };
|
||||
}
|
||||
tools[toolName].description = description;
|
||||
|
||||
settings.mcpServers[serverName].tools![toolName].description = description;
|
||||
// Update via DAO (supports both file and database modes)
|
||||
const result = await serverDao.updateTools(serverName, tools);
|
||||
|
||||
if (!saveSettings(settings)) {
|
||||
if (!result) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'Failed to save settings',
|
||||
@@ -939,8 +944,10 @@ export const togglePrompt = async (req: Request, res: Response): Promise<void> =
|
||||
return;
|
||||
}
|
||||
|
||||
const settings = loadSettings();
|
||||
if (!settings.mcpServers[serverName]) {
|
||||
const serverDao = getServerDao();
|
||||
const server = await serverDao.findById(serverName);
|
||||
|
||||
if (!server) {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
message: 'Server not found',
|
||||
@@ -949,14 +956,15 @@ export const togglePrompt = async (req: Request, res: Response): Promise<void> =
|
||||
}
|
||||
|
||||
// Initialize prompts config if it doesn't exist
|
||||
if (!settings.mcpServers[serverName].prompts) {
|
||||
settings.mcpServers[serverName].prompts = {};
|
||||
}
|
||||
const prompts = server.prompts || {};
|
||||
|
||||
// Set the prompt's enabled state
|
||||
settings.mcpServers[serverName].prompts![promptName] = { enabled };
|
||||
// Set the prompt's enabled state (preserve existing description if any)
|
||||
prompts[promptName] = { ...prompts[promptName], enabled };
|
||||
|
||||
if (!saveSettings(settings)) {
|
||||
// Update via DAO (supports both file and database modes)
|
||||
const result = await serverDao.updatePrompts(serverName, prompts);
|
||||
|
||||
if (!result) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'Failed to save settings',
|
||||
@@ -1003,8 +1011,10 @@ export const updatePromptDescription = async (req: Request, res: Response): Prom
|
||||
return;
|
||||
}
|
||||
|
||||
const settings = loadSettings();
|
||||
if (!settings.mcpServers[serverName]) {
|
||||
const serverDao = getServerDao();
|
||||
const server = await serverDao.findById(serverName);
|
||||
|
||||
if (!server) {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
message: 'Server not found',
|
||||
@@ -1013,18 +1023,18 @@ export const updatePromptDescription = async (req: Request, res: Response): Prom
|
||||
}
|
||||
|
||||
// Initialize prompts config if it doesn't exist
|
||||
if (!settings.mcpServers[serverName].prompts) {
|
||||
settings.mcpServers[serverName].prompts = {};
|
||||
}
|
||||
const prompts = server.prompts || {};
|
||||
|
||||
// Set the prompt's description
|
||||
if (!settings.mcpServers[serverName].prompts![promptName]) {
|
||||
settings.mcpServers[serverName].prompts![promptName] = { enabled: true };
|
||||
if (!prompts[promptName]) {
|
||||
prompts[promptName] = { enabled: true };
|
||||
}
|
||||
prompts[promptName].description = description;
|
||||
|
||||
settings.mcpServers[serverName].prompts![promptName].description = description;
|
||||
// Update via DAO (supports both file and database modes)
|
||||
const result = await serverDao.updatePrompts(serverName, prompts);
|
||||
|
||||
if (!saveSettings(settings)) {
|
||||
if (!result) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'Failed to save settings',
|
||||
|
||||
@@ -3,6 +3,8 @@ import { ServerDao, ServerDaoImpl } from './ServerDao.js';
|
||||
import { GroupDao, GroupDaoImpl } from './GroupDao.js';
|
||||
import { SystemConfigDao, SystemConfigDaoImpl } from './SystemConfigDao.js';
|
||||
import { UserConfigDao, UserConfigDaoImpl } from './UserConfigDao.js';
|
||||
import { OAuthClientDao, OAuthClientDaoImpl } from './OAuthClientDao.js';
|
||||
import { OAuthTokenDao, OAuthTokenDaoImpl } from './OAuthTokenDao.js';
|
||||
|
||||
/**
|
||||
* DAO Factory interface for creating DAO instances
|
||||
@@ -13,6 +15,8 @@ export interface DaoFactory {
|
||||
getGroupDao(): GroupDao;
|
||||
getSystemConfigDao(): SystemConfigDao;
|
||||
getUserConfigDao(): UserConfigDao;
|
||||
getOAuthClientDao(): OAuthClientDao;
|
||||
getOAuthTokenDao(): OAuthTokenDao;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,6 +30,8 @@ export class JsonFileDaoFactory implements DaoFactory {
|
||||
private groupDao: GroupDao | null = null;
|
||||
private systemConfigDao: SystemConfigDao | null = null;
|
||||
private userConfigDao: UserConfigDao | null = null;
|
||||
private oauthClientDao: OAuthClientDao | null = null;
|
||||
private oauthTokenDao: OAuthTokenDao | null = null;
|
||||
|
||||
/**
|
||||
* Get singleton instance
|
||||
@@ -76,6 +82,20 @@ export class JsonFileDaoFactory implements DaoFactory {
|
||||
return this.userConfigDao;
|
||||
}
|
||||
|
||||
getOAuthClientDao(): OAuthClientDao {
|
||||
if (!this.oauthClientDao) {
|
||||
this.oauthClientDao = new OAuthClientDaoImpl();
|
||||
}
|
||||
return this.oauthClientDao;
|
||||
}
|
||||
|
||||
getOAuthTokenDao(): OAuthTokenDao {
|
||||
if (!this.oauthTokenDao) {
|
||||
this.oauthTokenDao = new OAuthTokenDaoImpl();
|
||||
}
|
||||
return this.oauthTokenDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cached DAO instances (useful for testing)
|
||||
*/
|
||||
@@ -85,6 +105,8 @@ export class JsonFileDaoFactory implements DaoFactory {
|
||||
this.groupDao = null;
|
||||
this.systemConfigDao = null;
|
||||
this.userConfigDao = null;
|
||||
this.oauthClientDao = null;
|
||||
this.oauthTokenDao = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,3 +171,11 @@ export function getSystemConfigDao(): SystemConfigDao {
|
||||
export function getUserConfigDao(): UserConfigDao {
|
||||
return getDaoFactory().getUserConfigDao();
|
||||
}
|
||||
|
||||
export function getOAuthClientDao(): OAuthClientDao {
|
||||
return getDaoFactory().getOAuthClientDao();
|
||||
}
|
||||
|
||||
export function getOAuthTokenDao(): OAuthTokenDao {
|
||||
return getDaoFactory().getOAuthTokenDao();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import { DaoFactory, UserDao, ServerDao, GroupDao, SystemConfigDao, UserConfigDao } from './index.js';
|
||||
import {
|
||||
DaoFactory,
|
||||
UserDao,
|
||||
ServerDao,
|
||||
GroupDao,
|
||||
SystemConfigDao,
|
||||
UserConfigDao,
|
||||
OAuthClientDao,
|
||||
OAuthTokenDao,
|
||||
} from './index.js';
|
||||
import { UserDaoDbImpl } from './UserDaoDbImpl.js';
|
||||
import { ServerDaoDbImpl } from './ServerDaoDbImpl.js';
|
||||
import { GroupDaoDbImpl } from './GroupDaoDbImpl.js';
|
||||
import { SystemConfigDaoDbImpl } from './SystemConfigDaoDbImpl.js';
|
||||
import { UserConfigDaoDbImpl } from './UserConfigDaoDbImpl.js';
|
||||
import { OAuthClientDaoDbImpl } from './OAuthClientDaoDbImpl.js';
|
||||
import { OAuthTokenDaoDbImpl } from './OAuthTokenDaoDbImpl.js';
|
||||
|
||||
/**
|
||||
* Database-backed DAO factory implementation
|
||||
@@ -16,6 +27,8 @@ export class DatabaseDaoFactory implements DaoFactory {
|
||||
private groupDao: GroupDao | null = null;
|
||||
private systemConfigDao: SystemConfigDao | null = null;
|
||||
private userConfigDao: UserConfigDao | null = null;
|
||||
private oauthClientDao: OAuthClientDao | null = null;
|
||||
private oauthTokenDao: OAuthTokenDao | null = null;
|
||||
|
||||
/**
|
||||
* Get singleton instance
|
||||
@@ -66,6 +79,20 @@ export class DatabaseDaoFactory implements DaoFactory {
|
||||
return this.userConfigDao!;
|
||||
}
|
||||
|
||||
getOAuthClientDao(): OAuthClientDao {
|
||||
if (!this.oauthClientDao) {
|
||||
this.oauthClientDao = new OAuthClientDaoDbImpl();
|
||||
}
|
||||
return this.oauthClientDao!;
|
||||
}
|
||||
|
||||
getOAuthTokenDao(): OAuthTokenDao {
|
||||
if (!this.oauthTokenDao) {
|
||||
this.oauthTokenDao = new OAuthTokenDaoDbImpl();
|
||||
}
|
||||
return this.oauthTokenDao!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cached DAO instances (useful for testing)
|
||||
*/
|
||||
@@ -75,5 +102,7 @@ export class DatabaseDaoFactory implements DaoFactory {
|
||||
this.groupDao = null;
|
||||
this.systemConfigDao = null;
|
||||
this.userConfigDao = null;
|
||||
this.oauthClientDao = null;
|
||||
this.oauthTokenDao = null;
|
||||
}
|
||||
}
|
||||
|
||||
146
src/dao/OAuthClientDao.ts
Normal file
146
src/dao/OAuthClientDao.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
import { IOAuthClient } from '../types/index.js';
|
||||
import { BaseDao } from './base/BaseDao.js';
|
||||
import { JsonFileBaseDao } from './base/JsonFileBaseDao.js';
|
||||
|
||||
/**
|
||||
* OAuth Client DAO interface with OAuth client-specific operations
|
||||
*/
|
||||
export interface OAuthClientDao extends BaseDao<IOAuthClient, string> {
|
||||
/**
|
||||
* Find OAuth client by client ID
|
||||
*/
|
||||
findByClientId(clientId: string): Promise<IOAuthClient | null>;
|
||||
|
||||
/**
|
||||
* Find OAuth clients by owner
|
||||
*/
|
||||
findByOwner(owner: string): Promise<IOAuthClient[]>;
|
||||
|
||||
/**
|
||||
* Validate client credentials
|
||||
*/
|
||||
validateCredentials(clientId: string, clientSecret?: string): Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON file-based OAuth Client DAO implementation
|
||||
*/
|
||||
export class OAuthClientDaoImpl extends JsonFileBaseDao implements OAuthClientDao {
|
||||
protected async getAll(): Promise<IOAuthClient[]> {
|
||||
const settings = await this.loadSettings();
|
||||
return settings.oauthClients || [];
|
||||
}
|
||||
|
||||
protected async saveAll(clients: IOAuthClient[]): Promise<void> {
|
||||
const settings = await this.loadSettings();
|
||||
settings.oauthClients = clients;
|
||||
await this.saveSettings(settings);
|
||||
}
|
||||
|
||||
protected getEntityId(client: IOAuthClient): string {
|
||||
return client.clientId;
|
||||
}
|
||||
|
||||
protected createEntity(_data: Omit<IOAuthClient, 'clientId'>): IOAuthClient {
|
||||
throw new Error('clientId must be provided');
|
||||
}
|
||||
|
||||
protected updateEntity(existing: IOAuthClient, updates: Partial<IOAuthClient>): IOAuthClient {
|
||||
return {
|
||||
...existing,
|
||||
...updates,
|
||||
clientId: existing.clientId, // clientId should not be updated
|
||||
};
|
||||
}
|
||||
|
||||
async findAll(): Promise<IOAuthClient[]> {
|
||||
return this.getAll();
|
||||
}
|
||||
|
||||
async findById(clientId: string): Promise<IOAuthClient | null> {
|
||||
return this.findByClientId(clientId);
|
||||
}
|
||||
|
||||
async findByClientId(clientId: string): Promise<IOAuthClient | null> {
|
||||
const clients = await this.getAll();
|
||||
return clients.find((client) => client.clientId === clientId) || null;
|
||||
}
|
||||
|
||||
async findByOwner(owner: string): Promise<IOAuthClient[]> {
|
||||
const clients = await this.getAll();
|
||||
return clients.filter((client) => client.owner === owner);
|
||||
}
|
||||
|
||||
async create(data: IOAuthClient): Promise<IOAuthClient> {
|
||||
const clients = await this.getAll();
|
||||
|
||||
// Check if client already exists
|
||||
if (clients.find((client) => client.clientId === data.clientId)) {
|
||||
throw new Error(`OAuth client ${data.clientId} already exists`);
|
||||
}
|
||||
|
||||
const newClient: IOAuthClient = {
|
||||
...data,
|
||||
owner: data.owner || 'admin',
|
||||
};
|
||||
|
||||
clients.push(newClient);
|
||||
await this.saveAll(clients);
|
||||
|
||||
return newClient;
|
||||
}
|
||||
|
||||
async update(clientId: string, updates: Partial<IOAuthClient>): Promise<IOAuthClient | null> {
|
||||
const clients = await this.getAll();
|
||||
const index = clients.findIndex((client) => client.clientId === clientId);
|
||||
|
||||
if (index === -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Don't allow clientId changes
|
||||
const { clientId: _, ...allowedUpdates } = updates;
|
||||
const updatedClient = this.updateEntity(clients[index], allowedUpdates);
|
||||
clients[index] = updatedClient;
|
||||
|
||||
await this.saveAll(clients);
|
||||
return updatedClient;
|
||||
}
|
||||
|
||||
async delete(clientId: string): Promise<boolean> {
|
||||
const clients = await this.getAll();
|
||||
const index = clients.findIndex((client) => client.clientId === clientId);
|
||||
if (index === -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
clients.splice(index, 1);
|
||||
await this.saveAll(clients);
|
||||
return true;
|
||||
}
|
||||
|
||||
async exists(clientId: string): Promise<boolean> {
|
||||
const client = await this.findByClientId(clientId);
|
||||
return client !== null;
|
||||
}
|
||||
|
||||
async count(): Promise<number> {
|
||||
const clients = await this.getAll();
|
||||
return clients.length;
|
||||
}
|
||||
|
||||
async validateCredentials(clientId: string, clientSecret?: string): Promise<boolean> {
|
||||
const client = await this.findByClientId(clientId);
|
||||
if (!client) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If client has no secret (public client), accept if no secret provided
|
||||
if (!client.clientSecret) {
|
||||
return !clientSecret;
|
||||
}
|
||||
|
||||
// If client has a secret, it must match
|
||||
return client.clientSecret === clientSecret;
|
||||
}
|
||||
}
|
||||
109
src/dao/OAuthClientDaoDbImpl.ts
Normal file
109
src/dao/OAuthClientDaoDbImpl.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import { OAuthClientDao } from './OAuthClientDao.js';
|
||||
import { OAuthClientRepository } from '../db/repositories/OAuthClientRepository.js';
|
||||
import { IOAuthClient } from '../types/index.js';
|
||||
|
||||
/**
|
||||
* Database-backed implementation of OAuthClientDao
|
||||
*/
|
||||
export class OAuthClientDaoDbImpl implements OAuthClientDao {
|
||||
private repository: OAuthClientRepository;
|
||||
|
||||
constructor() {
|
||||
this.repository = new OAuthClientRepository();
|
||||
}
|
||||
|
||||
async findAll(): Promise<IOAuthClient[]> {
|
||||
const clients = await this.repository.findAll();
|
||||
return clients.map((c) => this.mapToOAuthClient(c));
|
||||
}
|
||||
|
||||
async findById(clientId: string): Promise<IOAuthClient | null> {
|
||||
const client = await this.repository.findByClientId(clientId);
|
||||
return client ? this.mapToOAuthClient(client) : null;
|
||||
}
|
||||
|
||||
async findByClientId(clientId: string): Promise<IOAuthClient | null> {
|
||||
return this.findById(clientId);
|
||||
}
|
||||
|
||||
async findByOwner(owner: string): Promise<IOAuthClient[]> {
|
||||
const clients = await this.repository.findByOwner(owner);
|
||||
return clients.map((c) => this.mapToOAuthClient(c));
|
||||
}
|
||||
|
||||
async create(entity: IOAuthClient): Promise<IOAuthClient> {
|
||||
const client = await this.repository.create({
|
||||
clientId: entity.clientId,
|
||||
clientSecret: entity.clientSecret,
|
||||
name: entity.name,
|
||||
redirectUris: entity.redirectUris,
|
||||
grants: entity.grants,
|
||||
scopes: entity.scopes,
|
||||
owner: entity.owner || 'admin',
|
||||
metadata: entity.metadata,
|
||||
});
|
||||
return this.mapToOAuthClient(client);
|
||||
}
|
||||
|
||||
async update(clientId: string, entity: Partial<IOAuthClient>): Promise<IOAuthClient | null> {
|
||||
const client = await this.repository.update(clientId, {
|
||||
clientSecret: entity.clientSecret,
|
||||
name: entity.name,
|
||||
redirectUris: entity.redirectUris,
|
||||
grants: entity.grants,
|
||||
scopes: entity.scopes,
|
||||
owner: entity.owner,
|
||||
metadata: entity.metadata,
|
||||
});
|
||||
return client ? this.mapToOAuthClient(client) : null;
|
||||
}
|
||||
|
||||
async delete(clientId: string): Promise<boolean> {
|
||||
return await this.repository.delete(clientId);
|
||||
}
|
||||
|
||||
async exists(clientId: string): Promise<boolean> {
|
||||
return await this.repository.exists(clientId);
|
||||
}
|
||||
|
||||
async count(): Promise<number> {
|
||||
return await this.repository.count();
|
||||
}
|
||||
|
||||
async validateCredentials(clientId: string, clientSecret?: string): Promise<boolean> {
|
||||
const client = await this.findByClientId(clientId);
|
||||
if (!client) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If client has no secret (public client), accept if no secret provided
|
||||
if (!client.clientSecret) {
|
||||
return !clientSecret;
|
||||
}
|
||||
|
||||
// If client has a secret, it must match
|
||||
return client.clientSecret === clientSecret;
|
||||
}
|
||||
|
||||
private mapToOAuthClient(client: {
|
||||
clientId: string;
|
||||
clientSecret?: string;
|
||||
name: string;
|
||||
redirectUris: string[];
|
||||
grants: string[];
|
||||
scopes?: string[];
|
||||
owner?: string;
|
||||
metadata?: Record<string, any>;
|
||||
}): IOAuthClient {
|
||||
return {
|
||||
clientId: client.clientId,
|
||||
clientSecret: client.clientSecret,
|
||||
name: client.name,
|
||||
redirectUris: client.redirectUris,
|
||||
grants: client.grants,
|
||||
scopes: client.scopes,
|
||||
owner: client.owner,
|
||||
metadata: client.metadata as IOAuthClient['metadata'],
|
||||
};
|
||||
}
|
||||
}
|
||||
259
src/dao/OAuthTokenDao.ts
Normal file
259
src/dao/OAuthTokenDao.ts
Normal file
@@ -0,0 +1,259 @@
|
||||
import { IOAuthToken } from '../types/index.js';
|
||||
import { BaseDao } from './base/BaseDao.js';
|
||||
import { JsonFileBaseDao } from './base/JsonFileBaseDao.js';
|
||||
|
||||
/**
|
||||
* OAuth Token DAO interface with OAuth token-specific operations
|
||||
*/
|
||||
export interface OAuthTokenDao extends BaseDao<IOAuthToken, string> {
|
||||
/**
|
||||
* Find token by access token
|
||||
*/
|
||||
findByAccessToken(accessToken: string): Promise<IOAuthToken | null>;
|
||||
|
||||
/**
|
||||
* Find token by refresh token
|
||||
*/
|
||||
findByRefreshToken(refreshToken: string): Promise<IOAuthToken | null>;
|
||||
|
||||
/**
|
||||
* Find tokens by client ID
|
||||
*/
|
||||
findByClientId(clientId: string): Promise<IOAuthToken[]>;
|
||||
|
||||
/**
|
||||
* Find tokens by username
|
||||
*/
|
||||
findByUsername(username: string): Promise<IOAuthToken[]>;
|
||||
|
||||
/**
|
||||
* Revoke token (delete by access token or refresh token)
|
||||
*/
|
||||
revokeToken(token: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Revoke all tokens for a user
|
||||
*/
|
||||
revokeUserTokens(username: string): Promise<number>;
|
||||
|
||||
/**
|
||||
* Revoke all tokens for a client
|
||||
*/
|
||||
revokeClientTokens(clientId: string): Promise<number>;
|
||||
|
||||
/**
|
||||
* Clean up expired tokens
|
||||
*/
|
||||
cleanupExpired(): Promise<number>;
|
||||
|
||||
/**
|
||||
* Check if access token is valid (exists and not expired)
|
||||
*/
|
||||
isAccessTokenValid(accessToken: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Check if refresh token is valid (exists and not expired)
|
||||
*/
|
||||
isRefreshTokenValid(refreshToken: string): Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON file-based OAuth Token DAO implementation
|
||||
*/
|
||||
export class OAuthTokenDaoImpl extends JsonFileBaseDao implements OAuthTokenDao {
|
||||
protected async getAll(): Promise<IOAuthToken[]> {
|
||||
const settings = await this.loadSettings();
|
||||
// Convert stored dates back to Date objects
|
||||
return (settings.oauthTokens || []).map((token) => ({
|
||||
...token,
|
||||
accessTokenExpiresAt: new Date(token.accessTokenExpiresAt),
|
||||
refreshTokenExpiresAt: token.refreshTokenExpiresAt
|
||||
? new Date(token.refreshTokenExpiresAt)
|
||||
: undefined,
|
||||
}));
|
||||
}
|
||||
|
||||
protected async saveAll(tokens: IOAuthToken[]): Promise<void> {
|
||||
const settings = await this.loadSettings();
|
||||
settings.oauthTokens = tokens;
|
||||
await this.saveSettings(settings);
|
||||
}
|
||||
|
||||
protected getEntityId(token: IOAuthToken): string {
|
||||
return token.accessToken;
|
||||
}
|
||||
|
||||
protected createEntity(_data: Omit<IOAuthToken, 'accessToken'>): IOAuthToken {
|
||||
throw new Error('accessToken must be provided');
|
||||
}
|
||||
|
||||
protected updateEntity(existing: IOAuthToken, updates: Partial<IOAuthToken>): IOAuthToken {
|
||||
return {
|
||||
...existing,
|
||||
...updates,
|
||||
accessToken: existing.accessToken, // accessToken should not be updated
|
||||
};
|
||||
}
|
||||
|
||||
async findAll(): Promise<IOAuthToken[]> {
|
||||
return this.getAll();
|
||||
}
|
||||
|
||||
async findById(accessToken: string): Promise<IOAuthToken | null> {
|
||||
return this.findByAccessToken(accessToken);
|
||||
}
|
||||
|
||||
async findByAccessToken(accessToken: string): Promise<IOAuthToken | null> {
|
||||
const tokens = await this.getAll();
|
||||
return tokens.find((token) => token.accessToken === accessToken) || null;
|
||||
}
|
||||
|
||||
async findByRefreshToken(refreshToken: string): Promise<IOAuthToken | null> {
|
||||
const tokens = await this.getAll();
|
||||
return tokens.find((token) => token.refreshToken === refreshToken) || null;
|
||||
}
|
||||
|
||||
async findByClientId(clientId: string): Promise<IOAuthToken[]> {
|
||||
const tokens = await this.getAll();
|
||||
return tokens.filter((token) => token.clientId === clientId);
|
||||
}
|
||||
|
||||
async findByUsername(username: string): Promise<IOAuthToken[]> {
|
||||
const tokens = await this.getAll();
|
||||
return tokens.filter((token) => token.username === username);
|
||||
}
|
||||
|
||||
async create(data: IOAuthToken): Promise<IOAuthToken> {
|
||||
const tokens = await this.getAll();
|
||||
|
||||
// Remove any existing tokens with the same access token or refresh token
|
||||
const filteredTokens = tokens.filter(
|
||||
(t) => t.accessToken !== data.accessToken && t.refreshToken !== data.refreshToken,
|
||||
);
|
||||
|
||||
const newToken: IOAuthToken = {
|
||||
...data,
|
||||
};
|
||||
|
||||
filteredTokens.push(newToken);
|
||||
await this.saveAll(filteredTokens);
|
||||
|
||||
return newToken;
|
||||
}
|
||||
|
||||
async update(accessToken: string, updates: Partial<IOAuthToken>): Promise<IOAuthToken | null> {
|
||||
const tokens = await this.getAll();
|
||||
const index = tokens.findIndex((token) => token.accessToken === accessToken);
|
||||
|
||||
if (index === -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Don't allow accessToken changes
|
||||
const { accessToken: _, ...allowedUpdates } = updates;
|
||||
const updatedToken = this.updateEntity(tokens[index], allowedUpdates);
|
||||
tokens[index] = updatedToken;
|
||||
|
||||
await this.saveAll(tokens);
|
||||
return updatedToken;
|
||||
}
|
||||
|
||||
async delete(accessToken: string): Promise<boolean> {
|
||||
const tokens = await this.getAll();
|
||||
const index = tokens.findIndex((token) => token.accessToken === accessToken);
|
||||
if (index === -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tokens.splice(index, 1);
|
||||
await this.saveAll(tokens);
|
||||
return true;
|
||||
}
|
||||
|
||||
async exists(accessToken: string): Promise<boolean> {
|
||||
const token = await this.findByAccessToken(accessToken);
|
||||
return token !== null;
|
||||
}
|
||||
|
||||
async count(): Promise<number> {
|
||||
const tokens = await this.getAll();
|
||||
return tokens.length;
|
||||
}
|
||||
|
||||
async revokeToken(token: string): Promise<boolean> {
|
||||
const tokens = await this.getAll();
|
||||
const tokenData = tokens.find((t) => t.accessToken === token || t.refreshToken === token);
|
||||
|
||||
if (!tokenData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const filteredTokens = tokens.filter(
|
||||
(t) => t.accessToken !== tokenData.accessToken && t.refreshToken !== tokenData.refreshToken,
|
||||
);
|
||||
|
||||
await this.saveAll(filteredTokens);
|
||||
return true;
|
||||
}
|
||||
|
||||
async revokeUserTokens(username: string): Promise<number> {
|
||||
const tokens = await this.getAll();
|
||||
const userTokens = tokens.filter((token) => token.username === username);
|
||||
const remainingTokens = tokens.filter((token) => token.username !== username);
|
||||
|
||||
await this.saveAll(remainingTokens);
|
||||
return userTokens.length;
|
||||
}
|
||||
|
||||
async revokeClientTokens(clientId: string): Promise<number> {
|
||||
const tokens = await this.getAll();
|
||||
const clientTokens = tokens.filter((token) => token.clientId === clientId);
|
||||
const remainingTokens = tokens.filter((token) => token.clientId !== clientId);
|
||||
|
||||
await this.saveAll(remainingTokens);
|
||||
return clientTokens.length;
|
||||
}
|
||||
|
||||
async cleanupExpired(): Promise<number> {
|
||||
const tokens = await this.getAll();
|
||||
const now = new Date();
|
||||
|
||||
const validTokens = tokens.filter((token) => {
|
||||
// Keep if access token is still valid
|
||||
if (token.accessTokenExpiresAt > now) {
|
||||
return true;
|
||||
}
|
||||
// Or if refresh token exists and is still valid
|
||||
if (token.refreshToken && token.refreshTokenExpiresAt && token.refreshTokenExpiresAt > now) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
const expiredCount = tokens.length - validTokens.length;
|
||||
if (expiredCount > 0) {
|
||||
await this.saveAll(validTokens);
|
||||
}
|
||||
|
||||
return expiredCount;
|
||||
}
|
||||
|
||||
async isAccessTokenValid(accessToken: string): Promise<boolean> {
|
||||
const token = await this.findByAccessToken(accessToken);
|
||||
if (!token) {
|
||||
return false;
|
||||
}
|
||||
return token.accessTokenExpiresAt > new Date();
|
||||
}
|
||||
|
||||
async isRefreshTokenValid(refreshToken: string): Promise<boolean> {
|
||||
const token = await this.findByRefreshToken(refreshToken);
|
||||
if (!token) {
|
||||
return false;
|
||||
}
|
||||
if (!token.refreshTokenExpiresAt) {
|
||||
return true; // No expiration means always valid
|
||||
}
|
||||
return token.refreshTokenExpiresAt > new Date();
|
||||
}
|
||||
}
|
||||
122
src/dao/OAuthTokenDaoDbImpl.ts
Normal file
122
src/dao/OAuthTokenDaoDbImpl.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
import { OAuthTokenDao } from './OAuthTokenDao.js';
|
||||
import { OAuthTokenRepository } from '../db/repositories/OAuthTokenRepository.js';
|
||||
import { IOAuthToken } from '../types/index.js';
|
||||
|
||||
/**
|
||||
* Database-backed implementation of OAuthTokenDao
|
||||
*/
|
||||
export class OAuthTokenDaoDbImpl implements OAuthTokenDao {
|
||||
private repository: OAuthTokenRepository;
|
||||
|
||||
constructor() {
|
||||
this.repository = new OAuthTokenRepository();
|
||||
}
|
||||
|
||||
async findAll(): Promise<IOAuthToken[]> {
|
||||
const tokens = await this.repository.findAll();
|
||||
return tokens.map((t) => this.mapToOAuthToken(t));
|
||||
}
|
||||
|
||||
async findById(accessToken: string): Promise<IOAuthToken | null> {
|
||||
const token = await this.repository.findByAccessToken(accessToken);
|
||||
return token ? this.mapToOAuthToken(token) : null;
|
||||
}
|
||||
|
||||
async findByAccessToken(accessToken: string): Promise<IOAuthToken | null> {
|
||||
return this.findById(accessToken);
|
||||
}
|
||||
|
||||
async findByRefreshToken(refreshToken: string): Promise<IOAuthToken | null> {
|
||||
const token = await this.repository.findByRefreshToken(refreshToken);
|
||||
return token ? this.mapToOAuthToken(token) : null;
|
||||
}
|
||||
|
||||
async findByClientId(clientId: string): Promise<IOAuthToken[]> {
|
||||
const tokens = await this.repository.findByClientId(clientId);
|
||||
return tokens.map((t) => this.mapToOAuthToken(t));
|
||||
}
|
||||
|
||||
async findByUsername(username: string): Promise<IOAuthToken[]> {
|
||||
const tokens = await this.repository.findByUsername(username);
|
||||
return tokens.map((t) => this.mapToOAuthToken(t));
|
||||
}
|
||||
|
||||
async create(entity: IOAuthToken): Promise<IOAuthToken> {
|
||||
const token = await this.repository.create({
|
||||
accessToken: entity.accessToken,
|
||||
accessTokenExpiresAt: entity.accessTokenExpiresAt,
|
||||
refreshToken: entity.refreshToken,
|
||||
refreshTokenExpiresAt: entity.refreshTokenExpiresAt,
|
||||
scope: entity.scope,
|
||||
clientId: entity.clientId,
|
||||
username: entity.username,
|
||||
});
|
||||
return this.mapToOAuthToken(token);
|
||||
}
|
||||
|
||||
async update(accessToken: string, entity: Partial<IOAuthToken>): Promise<IOAuthToken | null> {
|
||||
const token = await this.repository.update(accessToken, {
|
||||
accessTokenExpiresAt: entity.accessTokenExpiresAt,
|
||||
refreshToken: entity.refreshToken,
|
||||
refreshTokenExpiresAt: entity.refreshTokenExpiresAt,
|
||||
scope: entity.scope,
|
||||
});
|
||||
return token ? this.mapToOAuthToken(token) : null;
|
||||
}
|
||||
|
||||
async delete(accessToken: string): Promise<boolean> {
|
||||
return await this.repository.delete(accessToken);
|
||||
}
|
||||
|
||||
async exists(accessToken: string): Promise<boolean> {
|
||||
return await this.repository.exists(accessToken);
|
||||
}
|
||||
|
||||
async count(): Promise<number> {
|
||||
return await this.repository.count();
|
||||
}
|
||||
|
||||
async revokeToken(token: string): Promise<boolean> {
|
||||
return await this.repository.revokeToken(token);
|
||||
}
|
||||
|
||||
async revokeUserTokens(username: string): Promise<number> {
|
||||
return await this.repository.revokeUserTokens(username);
|
||||
}
|
||||
|
||||
async revokeClientTokens(clientId: string): Promise<number> {
|
||||
return await this.repository.revokeClientTokens(clientId);
|
||||
}
|
||||
|
||||
async cleanupExpired(): Promise<number> {
|
||||
return await this.repository.cleanupExpired();
|
||||
}
|
||||
|
||||
async isAccessTokenValid(accessToken: string): Promise<boolean> {
|
||||
return await this.repository.isAccessTokenValid(accessToken);
|
||||
}
|
||||
|
||||
async isRefreshTokenValid(refreshToken: string): Promise<boolean> {
|
||||
return await this.repository.isRefreshTokenValid(refreshToken);
|
||||
}
|
||||
|
||||
private mapToOAuthToken(token: {
|
||||
accessToken: string;
|
||||
accessTokenExpiresAt: Date;
|
||||
refreshToken?: string;
|
||||
refreshTokenExpiresAt?: Date;
|
||||
scope?: string;
|
||||
clientId: string;
|
||||
username: string;
|
||||
}): IOAuthToken {
|
||||
return {
|
||||
accessToken: token.accessToken,
|
||||
accessTokenExpiresAt: token.accessTokenExpiresAt,
|
||||
refreshToken: token.refreshToken,
|
||||
refreshTokenExpiresAt: token.refreshTokenExpiresAt,
|
||||
scope: token.scope,
|
||||
clientId: token.clientId,
|
||||
username: token.username,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ export * from './ServerDao.js';
|
||||
export * from './GroupDao.js';
|
||||
export * from './SystemConfigDao.js';
|
||||
export * from './UserConfigDao.js';
|
||||
export * from './OAuthClientDao.js';
|
||||
export * from './OAuthTokenDao.js';
|
||||
|
||||
// Export database implementations
|
||||
export * from './UserDaoDbImpl.js';
|
||||
@@ -13,6 +15,8 @@ export * from './ServerDaoDbImpl.js';
|
||||
export * from './GroupDaoDbImpl.js';
|
||||
export * from './SystemConfigDaoDbImpl.js';
|
||||
export * from './UserConfigDaoDbImpl.js';
|
||||
export * from './OAuthClientDaoDbImpl.js';
|
||||
export * from './OAuthTokenDaoDbImpl.js';
|
||||
|
||||
// Export the DAO factory and convenience functions
|
||||
export * from './DaoFactory.js';
|
||||
|
||||
60
src/db/entities/OAuthClient.ts
Normal file
60
src/db/entities/OAuthClient.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
/**
|
||||
* OAuth Client entity for database storage
|
||||
* Represents OAuth clients registered with MCPHub's authorization server
|
||||
*/
|
||||
@Entity({ name: 'oauth_clients' })
|
||||
export class OAuthClient {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'client_id', type: 'varchar', length: 255, unique: true })
|
||||
clientId: string;
|
||||
|
||||
@Column({ name: 'client_secret', type: 'varchar', length: 255, nullable: true })
|
||||
clientSecret?: string;
|
||||
|
||||
@Column({ type: 'varchar', length: 255 })
|
||||
name: string;
|
||||
|
||||
@Column({ name: 'redirect_uris', type: 'simple-json' })
|
||||
redirectUris: string[];
|
||||
|
||||
@Column({ type: 'simple-json' })
|
||||
grants: string[];
|
||||
|
||||
@Column({ type: 'simple-json', nullable: true })
|
||||
scopes?: string[];
|
||||
|
||||
@Column({ type: 'varchar', length: 255, nullable: true })
|
||||
owner?: string;
|
||||
|
||||
@Column({ type: 'simple-json', nullable: true })
|
||||
metadata?: {
|
||||
application_type?: 'web' | 'native';
|
||||
response_types?: string[];
|
||||
token_endpoint_auth_method?: string;
|
||||
contacts?: string[];
|
||||
logo_uri?: string;
|
||||
client_uri?: string;
|
||||
policy_uri?: string;
|
||||
tos_uri?: string;
|
||||
jwks_uri?: string;
|
||||
jwks?: object;
|
||||
};
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamp' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export default OAuthClient;
|
||||
51
src/db/entities/OAuthToken.ts
Normal file
51
src/db/entities/OAuthToken.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
Index,
|
||||
} from 'typeorm';
|
||||
|
||||
/**
|
||||
* OAuth Token entity for database storage
|
||||
* Represents OAuth tokens issued by MCPHub's authorization server
|
||||
*/
|
||||
@Entity({ name: 'oauth_tokens' })
|
||||
export class OAuthToken {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Index()
|
||||
@Column({ name: 'access_token', type: 'varchar', length: 512, unique: true })
|
||||
accessToken: string;
|
||||
|
||||
@Column({ name: 'access_token_expires_at', type: 'timestamp' })
|
||||
accessTokenExpiresAt: Date;
|
||||
|
||||
@Index()
|
||||
@Column({ name: 'refresh_token', type: 'varchar', length: 512, nullable: true, unique: true })
|
||||
refreshToken?: string;
|
||||
|
||||
@Column({ name: 'refresh_token_expires_at', type: 'timestamp', nullable: true })
|
||||
refreshTokenExpiresAt?: Date;
|
||||
|
||||
@Column({ type: 'varchar', length: 512, nullable: true })
|
||||
scope?: string;
|
||||
|
||||
@Index()
|
||||
@Column({ name: 'client_id', type: 'varchar', length: 255 })
|
||||
clientId: string;
|
||||
|
||||
@Index()
|
||||
@Column({ type: 'varchar', length: 255 })
|
||||
username: string;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamp' })
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp' })
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export default OAuthToken;
|
||||
@@ -4,9 +4,20 @@ import Server from './Server.js';
|
||||
import Group from './Group.js';
|
||||
import SystemConfig from './SystemConfig.js';
|
||||
import UserConfig from './UserConfig.js';
|
||||
import OAuthClient from './OAuthClient.js';
|
||||
import OAuthToken from './OAuthToken.js';
|
||||
|
||||
// Export all entities
|
||||
export default [VectorEmbedding, User, Server, Group, SystemConfig, UserConfig];
|
||||
export default [
|
||||
VectorEmbedding,
|
||||
User,
|
||||
Server,
|
||||
Group,
|
||||
SystemConfig,
|
||||
UserConfig,
|
||||
OAuthClient,
|
||||
OAuthToken,
|
||||
];
|
||||
|
||||
// Export individual entities for direct use
|
||||
export { VectorEmbedding, User, Server, Group, SystemConfig, UserConfig };
|
||||
export { VectorEmbedding, User, Server, Group, SystemConfig, UserConfig, OAuthClient, OAuthToken };
|
||||
|
||||
@@ -16,7 +16,7 @@ export class GroupRepository {
|
||||
* Find all groups
|
||||
*/
|
||||
async findAll(): Promise<Group[]> {
|
||||
return await this.repository.find();
|
||||
return await this.repository.find({ order: { createdAt: 'ASC' } });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,7 +88,7 @@ export class GroupRepository {
|
||||
* Find groups by owner
|
||||
*/
|
||||
async findByOwner(owner: string): Promise<Group[]> {
|
||||
return await this.repository.find({ where: { owner } });
|
||||
return await this.repository.find({ where: { owner }, order: { createdAt: 'ASC' } });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
80
src/db/repositories/OAuthClientRepository.ts
Normal file
80
src/db/repositories/OAuthClientRepository.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Repository } from 'typeorm';
|
||||
import { OAuthClient } from '../entities/OAuthClient.js';
|
||||
import { getAppDataSource } from '../connection.js';
|
||||
|
||||
/**
|
||||
* Repository for OAuthClient entity
|
||||
*/
|
||||
export class OAuthClientRepository {
|
||||
private repository: Repository<OAuthClient>;
|
||||
|
||||
constructor() {
|
||||
this.repository = getAppDataSource().getRepository(OAuthClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all OAuth clients
|
||||
*/
|
||||
async findAll(): Promise<OAuthClient[]> {
|
||||
return await this.repository.find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find OAuth client by client ID
|
||||
*/
|
||||
async findByClientId(clientId: string): Promise<OAuthClient | null> {
|
||||
return await this.repository.findOne({ where: { clientId } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Find OAuth clients by owner
|
||||
*/
|
||||
async findByOwner(owner: string): Promise<OAuthClient[]> {
|
||||
return await this.repository.find({ where: { owner } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new OAuth client
|
||||
*/
|
||||
async create(client: Omit<OAuthClient, 'id' | 'createdAt' | 'updatedAt'>): Promise<OAuthClient> {
|
||||
const newClient = this.repository.create(client);
|
||||
return await this.repository.save(newClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing OAuth client
|
||||
*/
|
||||
async update(clientId: string, clientData: Partial<OAuthClient>): Promise<OAuthClient | null> {
|
||||
const client = await this.findByClientId(clientId);
|
||||
if (!client) {
|
||||
return null;
|
||||
}
|
||||
const updated = this.repository.merge(client, clientData);
|
||||
return await this.repository.save(updated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an OAuth client
|
||||
*/
|
||||
async delete(clientId: string): Promise<boolean> {
|
||||
const result = await this.repository.delete({ clientId });
|
||||
return (result.affected ?? 0) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if OAuth client exists
|
||||
*/
|
||||
async exists(clientId: string): Promise<boolean> {
|
||||
const count = await this.repository.count({ where: { clientId } });
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count total OAuth clients
|
||||
*/
|
||||
async count(): Promise<number> {
|
||||
return await this.repository.count();
|
||||
}
|
||||
}
|
||||
|
||||
export default OAuthClientRepository;
|
||||
183
src/db/repositories/OAuthTokenRepository.ts
Normal file
183
src/db/repositories/OAuthTokenRepository.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
import { Repository, MoreThan } from 'typeorm';
|
||||
import { OAuthToken } from '../entities/OAuthToken.js';
|
||||
import { getAppDataSource } from '../connection.js';
|
||||
|
||||
/**
|
||||
* Repository for OAuthToken entity
|
||||
*/
|
||||
export class OAuthTokenRepository {
|
||||
private repository: Repository<OAuthToken>;
|
||||
|
||||
constructor() {
|
||||
this.repository = getAppDataSource().getRepository(OAuthToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all OAuth tokens
|
||||
*/
|
||||
async findAll(): Promise<OAuthToken[]> {
|
||||
return await this.repository.find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find OAuth token by access token
|
||||
*/
|
||||
async findByAccessToken(accessToken: string): Promise<OAuthToken | null> {
|
||||
return await this.repository.findOne({ where: { accessToken } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Find OAuth token by refresh token
|
||||
*/
|
||||
async findByRefreshToken(refreshToken: string): Promise<OAuthToken | null> {
|
||||
return await this.repository.findOne({ where: { refreshToken } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Find OAuth tokens by client ID
|
||||
*/
|
||||
async findByClientId(clientId: string): Promise<OAuthToken[]> {
|
||||
return await this.repository.find({ where: { clientId } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Find OAuth tokens by username
|
||||
*/
|
||||
async findByUsername(username: string): Promise<OAuthToken[]> {
|
||||
return await this.repository.find({ where: { username } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new OAuth token
|
||||
*/
|
||||
async create(token: Omit<OAuthToken, 'id' | 'createdAt' | 'updatedAt'>): Promise<OAuthToken> {
|
||||
// Remove any existing tokens with the same access token or refresh token
|
||||
if (token.accessToken) {
|
||||
await this.repository.delete({ accessToken: token.accessToken });
|
||||
}
|
||||
if (token.refreshToken) {
|
||||
await this.repository.delete({ refreshToken: token.refreshToken });
|
||||
}
|
||||
|
||||
const newToken = this.repository.create(token);
|
||||
return await this.repository.save(newToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing OAuth token
|
||||
*/
|
||||
async update(accessToken: string, tokenData: Partial<OAuthToken>): Promise<OAuthToken | null> {
|
||||
const token = await this.findByAccessToken(accessToken);
|
||||
if (!token) {
|
||||
return null;
|
||||
}
|
||||
const updated = this.repository.merge(token, tokenData);
|
||||
return await this.repository.save(updated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an OAuth token by access token
|
||||
*/
|
||||
async delete(accessToken: string): Promise<boolean> {
|
||||
const result = await this.repository.delete({ accessToken });
|
||||
return (result.affected ?? 0) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if OAuth token exists by access token
|
||||
*/
|
||||
async exists(accessToken: string): Promise<boolean> {
|
||||
const count = await this.repository.count({ where: { accessToken } });
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count total OAuth tokens
|
||||
*/
|
||||
async count(): Promise<number> {
|
||||
return await this.repository.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke token by access token or refresh token
|
||||
*/
|
||||
async revokeToken(token: string): Promise<boolean> {
|
||||
// Try to find by access token first
|
||||
let tokenEntity = await this.findByAccessToken(token);
|
||||
if (!tokenEntity) {
|
||||
// Try to find by refresh token
|
||||
tokenEntity = await this.findByRefreshToken(token);
|
||||
}
|
||||
|
||||
if (!tokenEntity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const result = await this.repository.delete({ id: tokenEntity.id });
|
||||
return (result.affected ?? 0) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke all tokens for a user
|
||||
*/
|
||||
async revokeUserTokens(username: string): Promise<number> {
|
||||
const result = await this.repository.delete({ username });
|
||||
return result.affected ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke all tokens for a client
|
||||
*/
|
||||
async revokeClientTokens(clientId: string): Promise<number> {
|
||||
const result = await this.repository.delete({ clientId });
|
||||
return result.affected ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up expired tokens
|
||||
*/
|
||||
async cleanupExpired(): Promise<number> {
|
||||
const now = new Date();
|
||||
|
||||
// Delete tokens where both access token and refresh token are expired
|
||||
// (or refresh token doesn't exist)
|
||||
const result = await this.repository
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(OAuthToken)
|
||||
.where('access_token_expires_at < :now', { now })
|
||||
.andWhere('(refresh_token_expires_at IS NULL OR refresh_token_expires_at < :now)', { now })
|
||||
.execute();
|
||||
|
||||
return result.affected ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if access token is valid (exists and not expired)
|
||||
*/
|
||||
async isAccessTokenValid(accessToken: string): Promise<boolean> {
|
||||
const count = await this.repository.count({
|
||||
where: {
|
||||
accessToken,
|
||||
accessTokenExpiresAt: MoreThan(new Date()),
|
||||
},
|
||||
});
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if refresh token is valid (exists and not expired)
|
||||
*/
|
||||
async isRefreshTokenValid(refreshToken: string): Promise<boolean> {
|
||||
const token = await this.findByRefreshToken(refreshToken);
|
||||
if (!token) {
|
||||
return false;
|
||||
}
|
||||
if (!token.refreshTokenExpiresAt) {
|
||||
return true; // No expiration means always valid
|
||||
}
|
||||
return token.refreshTokenExpiresAt > new Date();
|
||||
}
|
||||
}
|
||||
|
||||
export default OAuthTokenRepository;
|
||||
@@ -16,7 +16,7 @@ export class ServerRepository {
|
||||
* Find all servers
|
||||
*/
|
||||
async findAll(): Promise<Server[]> {
|
||||
return await this.repository.find();
|
||||
return await this.repository.find({ order: { createdAt: 'ASC' } });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,14 +73,14 @@ export class ServerRepository {
|
||||
* Find servers by owner
|
||||
*/
|
||||
async findByOwner(owner: string): Promise<Server[]> {
|
||||
return await this.repository.find({ where: { owner } });
|
||||
return await this.repository.find({ where: { owner }, order: { createdAt: 'ASC' } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Find enabled servers
|
||||
*/
|
||||
async findEnabled(): Promise<Server[]> {
|
||||
return await this.repository.find({ where: { enabled: true } });
|
||||
return await this.repository.find({ where: { enabled: true }, order: { createdAt: 'ASC' } });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@ export class UserRepository {
|
||||
* Find all users
|
||||
*/
|
||||
async findAll(): Promise<User[]> {
|
||||
return await this.repository.find();
|
||||
return await this.repository.find({ order: { createdAt: 'ASC' } });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +73,7 @@ export class UserRepository {
|
||||
* Find all admin users
|
||||
*/
|
||||
async findAdmins(): Promise<User[]> {
|
||||
return await this.repository.find({ where: { isAdmin: true } });
|
||||
return await this.repository.find({ where: { isAdmin: true }, order: { createdAt: 'ASC' } });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import { ServerRepository } from './ServerRepository.js';
|
||||
import { GroupRepository } from './GroupRepository.js';
|
||||
import { SystemConfigRepository } from './SystemConfigRepository.js';
|
||||
import { UserConfigRepository } from './UserConfigRepository.js';
|
||||
import { OAuthClientRepository } from './OAuthClientRepository.js';
|
||||
import { OAuthTokenRepository } from './OAuthTokenRepository.js';
|
||||
|
||||
// Export all repositories
|
||||
export {
|
||||
@@ -13,4 +15,6 @@ export {
|
||||
GroupRepository,
|
||||
SystemConfigRepository,
|
||||
UserConfigRepository,
|
||||
OAuthClientRepository,
|
||||
OAuthTokenRepository,
|
||||
};
|
||||
|
||||
@@ -67,7 +67,7 @@ export const auth = async (req: Request, res: Response, next: NextFunction): Pro
|
||||
const authHeader = req.headers.authorization;
|
||||
if (authHeader && authHeader.startsWith('Bearer ') && isOAuthServerEnabled()) {
|
||||
const accessToken = authHeader.substring(7);
|
||||
const oauthToken = getToken(accessToken);
|
||||
const oauthToken = await getToken(accessToken);
|
||||
|
||||
if (oauthToken && oauthToken.accessToken === accessToken) {
|
||||
// Valid OAuth token - look up user to get admin status
|
||||
|
||||
@@ -1,112 +1,89 @@
|
||||
import crypto from 'crypto';
|
||||
import { loadSettings, saveSettings } from '../config/index.js';
|
||||
import { getOAuthClientDao, getOAuthTokenDao } from '../dao/index.js';
|
||||
import { IOAuthClient, IOAuthAuthorizationCode, IOAuthToken } from '../types/index.js';
|
||||
|
||||
// In-memory storage for authorization codes and tokens
|
||||
// Authorization codes are short-lived and kept in memory only.
|
||||
// Tokens are mirrored to settings (mcp_settings.json) for persistence.
|
||||
// In-memory storage for authorization codes (short-lived, no persistence needed)
|
||||
const authorizationCodes = new Map<string, IOAuthAuthorizationCode>();
|
||||
const tokens = new Map<string, IOAuthToken>();
|
||||
|
||||
// Initialize token store from settings on first import
|
||||
(() => {
|
||||
// In-memory cache for tokens (also persisted via DAO)
|
||||
const tokensCache = new Map<string, IOAuthToken>();
|
||||
|
||||
// Flag to track if we've initialized from DAO
|
||||
let initialized = false;
|
||||
|
||||
/**
|
||||
* Initialize token cache from DAO (async)
|
||||
*/
|
||||
const initializeTokenCache = async (): Promise<void> => {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
||||
try {
|
||||
const settings = loadSettings();
|
||||
if (Array.isArray(settings.oauthTokens)) {
|
||||
for (const stored of settings.oauthTokens) {
|
||||
const token: IOAuthToken = {
|
||||
...stored,
|
||||
accessTokenExpiresAt: new Date(stored.accessTokenExpiresAt),
|
||||
refreshTokenExpiresAt: stored.refreshTokenExpiresAt
|
||||
? new Date(stored.refreshTokenExpiresAt)
|
||||
: undefined,
|
||||
};
|
||||
tokens.set(token.accessToken, token);
|
||||
if (token.refreshToken) {
|
||||
tokens.set(token.refreshToken, token);
|
||||
}
|
||||
const tokenDao = getOAuthTokenDao();
|
||||
const allTokens = await tokenDao.findAll();
|
||||
for (const token of allTokens) {
|
||||
tokensCache.set(token.accessToken, token);
|
||||
if (token.refreshToken) {
|
||||
tokensCache.set(token.refreshToken, token);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize OAuth tokens from settings:', error);
|
||||
console.error('Failed to initialize OAuth tokens from DAO:', error);
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
// Initialize on module load (fire and forget for backward compatibility)
|
||||
initializeTokenCache().catch(console.error);
|
||||
|
||||
/**
|
||||
* Get all OAuth clients from configuration
|
||||
*/
|
||||
export const getOAuthClients = (): IOAuthClient[] => {
|
||||
const settings = loadSettings();
|
||||
return settings.oauthClients || [];
|
||||
export const getOAuthClients = async (): Promise<IOAuthClient[]> => {
|
||||
const clientDao = getOAuthClientDao();
|
||||
return clientDao.findAll();
|
||||
};
|
||||
|
||||
/**
|
||||
* Find OAuth client by client ID
|
||||
*/
|
||||
export const findOAuthClientById = (clientId: string): IOAuthClient | undefined => {
|
||||
const clients = getOAuthClients();
|
||||
return clients.find((c) => c.clientId === clientId);
|
||||
export const findOAuthClientById = async (clientId: string): Promise<IOAuthClient | undefined> => {
|
||||
const clientDao = getOAuthClientDao();
|
||||
const client = await clientDao.findByClientId(clientId);
|
||||
return client || undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new OAuth client
|
||||
*/
|
||||
export const createOAuthClient = (client: IOAuthClient): IOAuthClient => {
|
||||
const settings = loadSettings();
|
||||
if (!settings.oauthClients) {
|
||||
settings.oauthClients = [];
|
||||
}
|
||||
export const createOAuthClient = async (client: IOAuthClient): Promise<IOAuthClient> => {
|
||||
const clientDao = getOAuthClientDao();
|
||||
|
||||
// Check if client already exists
|
||||
const existing = settings.oauthClients.find((c) => c.clientId === client.clientId);
|
||||
const existing = await clientDao.findByClientId(client.clientId);
|
||||
if (existing) {
|
||||
throw new Error(`OAuth client with ID ${client.clientId} already exists`);
|
||||
}
|
||||
|
||||
settings.oauthClients.push(client);
|
||||
saveSettings(settings);
|
||||
return client;
|
||||
return clientDao.create(client);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update an existing OAuth client
|
||||
*/
|
||||
export const updateOAuthClient = (
|
||||
export const updateOAuthClient = async (
|
||||
clientId: string,
|
||||
updates: Partial<IOAuthClient>,
|
||||
): IOAuthClient | null => {
|
||||
const settings = loadSettings();
|
||||
if (!settings.oauthClients) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const index = settings.oauthClients.findIndex((c) => c.clientId === clientId);
|
||||
if (index === -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
settings.oauthClients[index] = { ...settings.oauthClients[index], ...updates };
|
||||
saveSettings(settings);
|
||||
return settings.oauthClients[index];
|
||||
): Promise<IOAuthClient | null> => {
|
||||
const clientDao = getOAuthClientDao();
|
||||
return clientDao.update(clientId, updates);
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete an OAuth client
|
||||
*/
|
||||
export const deleteOAuthClient = (clientId: string): boolean => {
|
||||
const settings = loadSettings();
|
||||
if (!settings.oauthClients) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const index = settings.oauthClients.findIndex((c) => c.clientId === clientId);
|
||||
if (index === -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
settings.oauthClients.splice(index, 1);
|
||||
saveSettings(settings);
|
||||
return true;
|
||||
export const deleteOAuthClient = async (clientId: string): Promise<boolean> => {
|
||||
const clientDao = getOAuthClientDao();
|
||||
return clientDao.delete(clientId);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -163,11 +140,11 @@ export const revokeAuthorizationCode = (code: string): void => {
|
||||
/**
|
||||
* Save access token and optionally refresh token
|
||||
*/
|
||||
export const saveToken = (
|
||||
export const saveToken = async (
|
||||
tokenData: Omit<IOAuthToken, 'accessToken' | 'accessTokenExpiresAt'>,
|
||||
accessTokenLifetime: number = 3600,
|
||||
refreshTokenLifetime?: number,
|
||||
): IOAuthToken => {
|
||||
): Promise<IOAuthToken> => {
|
||||
const accessToken = generateToken();
|
||||
const accessTokenExpiresAt = new Date(Date.now() + accessTokenLifetime * 1000);
|
||||
|
||||
@@ -187,30 +164,18 @@ export const saveToken = (
|
||||
...tokenData,
|
||||
};
|
||||
|
||||
tokens.set(accessToken, token);
|
||||
// Update cache
|
||||
tokensCache.set(accessToken, token);
|
||||
if (refreshToken) {
|
||||
tokens.set(refreshToken, token);
|
||||
tokensCache.set(refreshToken, token);
|
||||
}
|
||||
|
||||
// Persist tokens to settings
|
||||
// Persist to DAO
|
||||
try {
|
||||
const settings = loadSettings();
|
||||
const existing = settings.oauthTokens || [];
|
||||
const filtered = existing.filter(
|
||||
(t) => t.accessToken !== token.accessToken && t.refreshToken !== token.refreshToken,
|
||||
);
|
||||
const updated = [
|
||||
...filtered,
|
||||
{
|
||||
...token,
|
||||
accessTokenExpiresAt: token.accessTokenExpiresAt,
|
||||
refreshTokenExpiresAt: token.refreshTokenExpiresAt,
|
||||
},
|
||||
];
|
||||
settings.oauthTokens = updated;
|
||||
saveSettings(settings);
|
||||
const tokenDao = getOAuthTokenDao();
|
||||
await tokenDao.create(token);
|
||||
} catch (error) {
|
||||
console.error('Failed to persist OAuth token to settings:', error);
|
||||
console.error('Failed to persist OAuth token to DAO:', error);
|
||||
}
|
||||
|
||||
return token;
|
||||
@@ -219,8 +184,27 @@ export const saveToken = (
|
||||
/**
|
||||
* Get token by access token or refresh token
|
||||
*/
|
||||
export const getToken = (token: string): IOAuthToken | undefined => {
|
||||
const tokenData = tokens.get(token);
|
||||
export const getToken = async (token: string): Promise<IOAuthToken | undefined> => {
|
||||
// First check cache
|
||||
let tokenData = tokensCache.get(token);
|
||||
|
||||
// If not in cache, try DAO
|
||||
if (!tokenData) {
|
||||
const tokenDao = getOAuthTokenDao();
|
||||
tokenData =
|
||||
(await tokenDao.findByAccessToken(token)) ||
|
||||
(await tokenDao.findByRefreshToken(token)) ||
|
||||
undefined;
|
||||
|
||||
// Update cache if found
|
||||
if (tokenData) {
|
||||
tokensCache.set(tokenData.accessToken, tokenData);
|
||||
if (tokenData.refreshToken) {
|
||||
tokensCache.set(tokenData.refreshToken, tokenData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!tokenData) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -245,34 +229,28 @@ export const getToken = (token: string): IOAuthToken | undefined => {
|
||||
/**
|
||||
* Revoke token (both access and refresh tokens)
|
||||
*/
|
||||
export const revokeToken = (token: string): void => {
|
||||
const tokenData = tokens.get(token);
|
||||
export const revokeToken = async (token: string): Promise<void> => {
|
||||
const tokenData = tokensCache.get(token);
|
||||
if (tokenData) {
|
||||
tokens.delete(tokenData.accessToken);
|
||||
tokensCache.delete(tokenData.accessToken);
|
||||
if (tokenData.refreshToken) {
|
||||
tokens.delete(tokenData.refreshToken);
|
||||
tokensCache.delete(tokenData.refreshToken);
|
||||
}
|
||||
}
|
||||
|
||||
// Also remove from persisted settings
|
||||
try {
|
||||
const settings = loadSettings();
|
||||
if (Array.isArray(settings.oauthTokens)) {
|
||||
settings.oauthTokens = settings.oauthTokens.filter(
|
||||
(t) =>
|
||||
t.accessToken !== tokenData.accessToken && t.refreshToken !== tokenData.refreshToken,
|
||||
);
|
||||
saveSettings(settings);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to remove OAuth token from settings:', error);
|
||||
}
|
||||
// Also remove from DAO
|
||||
try {
|
||||
const tokenDao = getOAuthTokenDao();
|
||||
await tokenDao.revokeToken(token);
|
||||
} catch (error) {
|
||||
console.error('Failed to remove OAuth token from DAO:', error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up expired codes and tokens (should be called periodically)
|
||||
*/
|
||||
export const cleanupExpired = (): void => {
|
||||
export const cleanupExpired = async (): Promise<void> => {
|
||||
const now = new Date();
|
||||
|
||||
// Clean up expired authorization codes
|
||||
@@ -282,9 +260,9 @@ export const cleanupExpired = (): void => {
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up expired tokens
|
||||
// Clean up expired tokens from cache
|
||||
const processedTokens = new Set<string>();
|
||||
for (const [_key, token] of tokens.entries()) {
|
||||
for (const [_key, token] of tokensCache.entries()) {
|
||||
// Skip if we've already processed this token
|
||||
if (processedTokens.has(token.accessToken)) {
|
||||
continue;
|
||||
@@ -294,35 +272,19 @@ export const cleanupExpired = (): void => {
|
||||
const accessExpired = token.accessTokenExpiresAt < now;
|
||||
const refreshExpired = token.refreshTokenExpiresAt && token.refreshTokenExpiresAt < now;
|
||||
|
||||
// If both are expired, remove the token
|
||||
// If both are expired, remove from cache
|
||||
if (accessExpired && (!token.refreshToken || refreshExpired)) {
|
||||
tokens.delete(token.accessToken);
|
||||
tokensCache.delete(token.accessToken);
|
||||
if (token.refreshToken) {
|
||||
tokens.delete(token.refreshToken);
|
||||
tokensCache.delete(token.refreshToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sync persisted tokens: keep only non-expired ones
|
||||
// Clean up expired tokens from DAO
|
||||
try {
|
||||
const settings = loadSettings();
|
||||
if (Array.isArray(settings.oauthTokens)) {
|
||||
const validTokens: IOAuthToken[] = [];
|
||||
for (const stored of settings.oauthTokens) {
|
||||
const accessExpiresAt = new Date(stored.accessTokenExpiresAt);
|
||||
const refreshExpiresAt = stored.refreshTokenExpiresAt
|
||||
? new Date(stored.refreshTokenExpiresAt)
|
||||
: undefined;
|
||||
const accessExpired = accessExpiresAt < now;
|
||||
const refreshExpired = refreshExpiresAt && refreshExpiresAt < now;
|
||||
|
||||
if (!accessExpired || (stored.refreshToken && !refreshExpired)) {
|
||||
validTokens.push(stored);
|
||||
}
|
||||
}
|
||||
settings.oauthTokens = validTokens;
|
||||
saveSettings(settings);
|
||||
}
|
||||
const tokenDao = getOAuthTokenDao();
|
||||
await tokenDao.cleanupExpired();
|
||||
} catch (error) {
|
||||
console.error('Failed to cleanup persisted OAuth tokens:', error);
|
||||
}
|
||||
@@ -331,7 +293,12 @@ export const cleanupExpired = (): void => {
|
||||
// Run cleanup every 5 minutes in production
|
||||
let cleanupIntervalId: NodeJS.Timeout | null = null;
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
cleanupIntervalId = setInterval(cleanupExpired, 5 * 60 * 1000);
|
||||
cleanupIntervalId = setInterval(
|
||||
() => {
|
||||
cleanupExpired().catch(console.error);
|
||||
},
|
||||
5 * 60 * 1000,
|
||||
);
|
||||
// Allow the interval to not keep the process alive
|
||||
cleanupIntervalId.unref();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ const oauthModel: OAuth2Server.AuthorizationCodeModel & OAuth2Server.RefreshToke
|
||||
* Get client by client ID
|
||||
*/
|
||||
getClient: async (clientId: string, clientSecret?: string) => {
|
||||
const client = findOAuthClientById(clientId);
|
||||
const client = await findOAuthClientById(clientId);
|
||||
if (!client) {
|
||||
return false;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ const oauthModel: OAuth2Server.AuthorizationCodeModel & OAuth2Server.RefreshToke
|
||||
return false;
|
||||
}
|
||||
|
||||
const client = findOAuthClientById(code.clientId);
|
||||
const client = await findOAuthClientById(code.clientId);
|
||||
if (!client) {
|
||||
return false;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ const oauthModel: OAuth2Server.AuthorizationCodeModel & OAuth2Server.RefreshToke
|
||||
|
||||
const scopeString = Array.isArray(token.scope) ? token.scope.join(' ') : token.scope;
|
||||
|
||||
const savedToken = saveToken(
|
||||
const savedToken = await saveToken(
|
||||
{
|
||||
scope: scopeString,
|
||||
clientId: client.id,
|
||||
@@ -172,12 +172,12 @@ const oauthModel: OAuth2Server.AuthorizationCodeModel & OAuth2Server.RefreshToke
|
||||
* Get access token
|
||||
*/
|
||||
getAccessToken: async (accessToken: string) => {
|
||||
const token = getToken(accessToken);
|
||||
const token = await getToken(accessToken);
|
||||
if (!token) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const client = findOAuthClientById(token.clientId);
|
||||
const client = await findOAuthClientById(token.clientId);
|
||||
if (!client) {
|
||||
return false;
|
||||
}
|
||||
@@ -205,12 +205,12 @@ const oauthModel: OAuth2Server.AuthorizationCodeModel & OAuth2Server.RefreshToke
|
||||
* Get refresh token
|
||||
*/
|
||||
getRefreshToken: async (refreshToken: string) => {
|
||||
const token = getToken(refreshToken);
|
||||
const token = await getToken(refreshToken);
|
||||
if (!token || token.refreshToken !== refreshToken) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const client = findOAuthClientById(token.clientId);
|
||||
const client = await findOAuthClientById(token.clientId);
|
||||
if (!client) {
|
||||
return false;
|
||||
}
|
||||
@@ -240,7 +240,7 @@ const oauthModel: OAuth2Server.AuthorizationCodeModel & OAuth2Server.RefreshToke
|
||||
revokeToken: async (token: OAuth2Server.Token | OAuth2Server.RefreshToken) => {
|
||||
const refreshToken = 'refreshToken' in token ? token.refreshToken : undefined;
|
||||
if (refreshToken) {
|
||||
revokeToken(refreshToken);
|
||||
await revokeToken(refreshToken);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
@@ -7,6 +7,8 @@ import { ServerRepository } from '../db/repositories/ServerRepository.js';
|
||||
import { GroupRepository } from '../db/repositories/GroupRepository.js';
|
||||
import { SystemConfigRepository } from '../db/repositories/SystemConfigRepository.js';
|
||||
import { UserConfigRepository } from '../db/repositories/UserConfigRepository.js';
|
||||
import { OAuthClientRepository } from '../db/repositories/OAuthClientRepository.js';
|
||||
import { OAuthTokenRepository } from '../db/repositories/OAuthTokenRepository.js';
|
||||
|
||||
/**
|
||||
* Migrate from file-based configuration to database
|
||||
@@ -29,6 +31,8 @@ export async function migrateToDatabase(): Promise<boolean> {
|
||||
const groupRepo = new GroupRepository();
|
||||
const systemConfigRepo = new SystemConfigRepository();
|
||||
const userConfigRepo = new UserConfigRepository();
|
||||
const oauthClientRepo = new OAuthClientRepository();
|
||||
const oauthTokenRepo = new OAuthTokenRepository();
|
||||
|
||||
// Migrate users
|
||||
if (settings.users && settings.users.length > 0) {
|
||||
@@ -129,6 +133,53 @@ export async function migrateToDatabase(): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate OAuth clients
|
||||
if (settings.oauthClients && settings.oauthClients.length > 0) {
|
||||
console.log(`Migrating ${settings.oauthClients.length} OAuth clients...`);
|
||||
for (const client of settings.oauthClients) {
|
||||
const exists = await oauthClientRepo.exists(client.clientId);
|
||||
if (!exists) {
|
||||
await oauthClientRepo.create({
|
||||
clientId: client.clientId,
|
||||
clientSecret: client.clientSecret,
|
||||
name: client.name,
|
||||
redirectUris: client.redirectUris,
|
||||
grants: client.grants,
|
||||
scopes: client.scopes,
|
||||
owner: client.owner,
|
||||
metadata: client.metadata,
|
||||
});
|
||||
console.log(` - Created OAuth client: ${client.clientId}`);
|
||||
} else {
|
||||
console.log(` - OAuth client already exists: ${client.clientId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate OAuth tokens
|
||||
if (settings.oauthTokens && settings.oauthTokens.length > 0) {
|
||||
console.log(`Migrating ${settings.oauthTokens.length} OAuth tokens...`);
|
||||
for (const token of settings.oauthTokens) {
|
||||
const exists = await oauthTokenRepo.exists(token.accessToken);
|
||||
if (!exists) {
|
||||
await oauthTokenRepo.create({
|
||||
accessToken: token.accessToken,
|
||||
refreshToken: token.refreshToken,
|
||||
accessTokenExpiresAt: new Date(token.accessTokenExpiresAt),
|
||||
refreshTokenExpiresAt: token.refreshTokenExpiresAt
|
||||
? new Date(token.refreshTokenExpiresAt)
|
||||
: undefined,
|
||||
scope: token.scope,
|
||||
clientId: token.clientId,
|
||||
username: token.username,
|
||||
});
|
||||
console.log(` - Created OAuth token for client: ${token.clientId}`);
|
||||
} else {
|
||||
console.log(` - OAuth token already exists: ${token.accessToken.substring(0, 8)}...`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('✅ Migration completed successfully');
|
||||
return true;
|
||||
} catch (error) {
|
||||
|
||||
@@ -11,7 +11,7 @@ export const resolveOAuthUserFromToken = async (token?: string): Promise<IUser |
|
||||
return null;
|
||||
}
|
||||
|
||||
const oauthToken = getOAuthStoredToken(token);
|
||||
const oauthToken = await getOAuthStoredToken(token);
|
||||
if (!oauthToken || oauthToken.accessToken !== token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,43 @@
|
||||
import { getMcpSettingsJson } from '../../src/controllers/configController.js'
|
||||
import * as config from '../../src/config/index.js'
|
||||
import { Request, Response } from 'express'
|
||||
import { getMcpSettingsJson } from '../../src/controllers/configController.js';
|
||||
import * as config from '../../src/config/index.js';
|
||||
import * as DaoFactory from '../../src/dao/DaoFactory.js';
|
||||
import { Request, Response } from 'express';
|
||||
|
||||
// Mock the config module
|
||||
jest.mock('../../src/config/index.js')
|
||||
jest.mock('../../src/config/index.js');
|
||||
// Mock the DaoFactory module
|
||||
jest.mock('../../src/dao/DaoFactory.js');
|
||||
|
||||
describe('ConfigController - getMcpSettingsJson', () => {
|
||||
let mockRequest: Partial<Request>
|
||||
let mockResponse: Partial<Response>
|
||||
let mockJson: jest.Mock
|
||||
let mockStatus: jest.Mock
|
||||
let mockRequest: Partial<Request>;
|
||||
let mockResponse: Partial<Response>;
|
||||
let mockJson: jest.Mock;
|
||||
let mockStatus: jest.Mock;
|
||||
let mockServerDao: { findById: jest.Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
mockJson = jest.fn()
|
||||
mockStatus = jest.fn().mockReturnThis()
|
||||
mockJson = jest.fn();
|
||||
mockStatus = jest.fn().mockReturnThis();
|
||||
mockRequest = {
|
||||
query: {},
|
||||
}
|
||||
};
|
||||
mockResponse = {
|
||||
json: mockJson,
|
||||
status: mockStatus,
|
||||
}
|
||||
};
|
||||
mockServerDao = {
|
||||
findById: jest.fn(),
|
||||
};
|
||||
|
||||
// Setup ServerDao mock
|
||||
(DaoFactory.getServerDao as jest.Mock).mockReturnValue(mockServerDao);
|
||||
|
||||
// Reset mocks
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('Full Settings Export', () => {
|
||||
it('should handle settings without users array', () => {
|
||||
it('should handle settings without users array', async () => {
|
||||
const mockSettings = {
|
||||
mcpServers: {
|
||||
'test-server': {
|
||||
@@ -35,11 +45,11 @@ describe('ConfigController - getMcpSettingsJson', () => {
|
||||
args: ['--test'],
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
;(config.loadOriginalSettings as jest.Mock).mockReturnValue(mockSettings)
|
||||
(config.loadOriginalSettings as jest.Mock).mockReturnValue(mockSettings);
|
||||
|
||||
getMcpSettingsJson(mockRequest as Request, mockResponse as Response)
|
||||
await getMcpSettingsJson(mockRequest as Request, mockResponse as Response);
|
||||
|
||||
expect(mockJson).toHaveBeenCalledWith({
|
||||
success: true,
|
||||
@@ -47,40 +57,27 @@ describe('ConfigController - getMcpSettingsJson', () => {
|
||||
mcpServers: mockSettings.mcpServers,
|
||||
users: undefined,
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Individual Server Export', () => {
|
||||
it('should return individual server configuration when serverName is specified', () => {
|
||||
const mockSettings = {
|
||||
mcpServers: {
|
||||
'test-server': {
|
||||
command: 'test',
|
||||
args: ['--test'],
|
||||
env: {
|
||||
TEST_VAR: 'test-value',
|
||||
},
|
||||
},
|
||||
'another-server': {
|
||||
command: 'another',
|
||||
args: ['--another'],
|
||||
},
|
||||
it('should return individual server configuration when serverName is specified', async () => {
|
||||
const serverConfig = {
|
||||
name: 'test-server',
|
||||
command: 'test',
|
||||
args: ['--test'],
|
||||
env: {
|
||||
TEST_VAR: 'test-value',
|
||||
},
|
||||
users: [
|
||||
{
|
||||
username: 'admin',
|
||||
password: '$2b$10$hashedpassword',
|
||||
isAdmin: true,
|
||||
},
|
||||
],
|
||||
}
|
||||
};
|
||||
|
||||
mockRequest.query = { serverName: 'test-server' }
|
||||
;(config.loadOriginalSettings as jest.Mock).mockReturnValue(mockSettings)
|
||||
mockRequest.query = { serverName: 'test-server' };
|
||||
mockServerDao.findById.mockResolvedValue(serverConfig);
|
||||
|
||||
getMcpSettingsJson(mockRequest as Request, mockResponse as Response)
|
||||
await getMcpSettingsJson(mockRequest as Request, mockResponse as Response);
|
||||
|
||||
expect(mockServerDao.findById).toHaveBeenCalledWith('test-server');
|
||||
expect(mockJson).toHaveBeenCalledWith({
|
||||
success: true,
|
||||
data: {
|
||||
@@ -94,46 +91,73 @@ describe('ConfigController - getMcpSettingsJson', () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 404 when server does not exist', () => {
|
||||
const mockSettings = {
|
||||
mcpServers: {
|
||||
'test-server': {
|
||||
command: 'test',
|
||||
args: ['--test'],
|
||||
},
|
||||
},
|
||||
}
|
||||
it('should return 404 when server does not exist', async () => {
|
||||
mockRequest.query = { serverName: 'non-existent-server' };
|
||||
mockServerDao.findById.mockResolvedValue(null);
|
||||
|
||||
mockRequest.query = { serverName: 'non-existent-server' }
|
||||
;(config.loadOriginalSettings as jest.Mock).mockReturnValue(mockSettings)
|
||||
await getMcpSettingsJson(mockRequest as Request, mockResponse as Response);
|
||||
|
||||
getMcpSettingsJson(mockRequest as Request, mockResponse as Response)
|
||||
|
||||
expect(mockStatus).toHaveBeenCalledWith(404)
|
||||
expect(mockServerDao.findById).toHaveBeenCalledWith('non-existent-server');
|
||||
expect(mockStatus).toHaveBeenCalledWith(404);
|
||||
expect(mockJson).toHaveBeenCalledWith({
|
||||
success: false,
|
||||
message: "Server 'non-existent-server' not found",
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove null values from server configuration', async () => {
|
||||
const serverConfig = {
|
||||
name: 'test-server',
|
||||
command: 'test',
|
||||
args: ['--test'],
|
||||
url: null,
|
||||
env: null,
|
||||
headers: null,
|
||||
options: {
|
||||
timeout: 30,
|
||||
retries: null,
|
||||
},
|
||||
};
|
||||
|
||||
mockRequest.query = { serverName: 'test-server' };
|
||||
mockServerDao.findById.mockResolvedValue(serverConfig);
|
||||
|
||||
await getMcpSettingsJson(mockRequest as Request, mockResponse as Response);
|
||||
|
||||
expect(mockJson).toHaveBeenCalledWith({
|
||||
success: true,
|
||||
data: {
|
||||
mcpServers: {
|
||||
'test-server': {
|
||||
command: 'test',
|
||||
args: ['--test'],
|
||||
options: {
|
||||
timeout: 30,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Error Handling', () => {
|
||||
it('should handle errors gracefully and return 500', () => {
|
||||
const errorMessage = 'Failed to load settings'
|
||||
;(config.loadOriginalSettings as jest.Mock).mockImplementation(() => {
|
||||
throw new Error(errorMessage)
|
||||
})
|
||||
it('should handle errors gracefully and return 500', async () => {
|
||||
const errorMessage = 'Failed to load settings';
|
||||
(config.loadOriginalSettings as jest.Mock).mockImplementation(() => {
|
||||
throw new Error(errorMessage);
|
||||
});
|
||||
|
||||
getMcpSettingsJson(mockRequest as Request, mockResponse as Response)
|
||||
await getMcpSettingsJson(mockRequest as Request, mockResponse as Response);
|
||||
|
||||
expect(mockStatus).toHaveBeenCalledWith(500)
|
||||
expect(mockStatus).toHaveBeenCalledWith(500);
|
||||
expect(mockJson).toHaveBeenCalledWith({
|
||||
success: false,
|
||||
message: 'Failed to get MCP settings',
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,29 +10,86 @@ import {
|
||||
getToken,
|
||||
revokeToken,
|
||||
} from '../../src/models/OAuth.js';
|
||||
import { IOAuthClient, IOAuthToken } from '../../src/types/index.js';
|
||||
|
||||
// Mock the config module to use in-memory storage for tests
|
||||
let mockSettings = { mcpServers: {}, users: [], oauthClients: [] };
|
||||
// Mock in-memory storage for OAuth clients and tokens
|
||||
let mockOAuthClients: IOAuthClient[] = [];
|
||||
let mockOAuthTokens: IOAuthToken[] = [];
|
||||
|
||||
jest.mock('../../src/config/index.js', () => ({
|
||||
loadSettings: jest.fn(() => ({ ...mockSettings })),
|
||||
saveSettings: jest.fn((settings: any) => {
|
||||
mockSettings = { ...settings };
|
||||
return true;
|
||||
}),
|
||||
loadOriginalSettings: jest.fn(() => ({ ...mockSettings })),
|
||||
}));
|
||||
// Mock the DAO factory to use in-memory storage for tests
|
||||
jest.mock('../../src/dao/index.js', () => {
|
||||
const originalModule = jest.requireActual('../../src/dao/index.js');
|
||||
|
||||
return {
|
||||
...originalModule,
|
||||
getOAuthClientDao: jest.fn(() => ({
|
||||
findAll: jest.fn(async () => [...mockOAuthClients]),
|
||||
findByClientId: jest.fn(
|
||||
async (clientId: string) => mockOAuthClients.find((c) => c.clientId === clientId) || null,
|
||||
),
|
||||
create: jest.fn(async (client: IOAuthClient) => {
|
||||
mockOAuthClients.push(client);
|
||||
return client;
|
||||
}),
|
||||
update: jest.fn(async (clientId: string, updates: Partial<IOAuthClient>) => {
|
||||
const index = mockOAuthClients.findIndex((c) => c.clientId === clientId);
|
||||
if (index === -1) return null;
|
||||
mockOAuthClients[index] = { ...mockOAuthClients[index], ...updates };
|
||||
return mockOAuthClients[index];
|
||||
}),
|
||||
delete: jest.fn(async (clientId: string) => {
|
||||
const index = mockOAuthClients.findIndex((c) => c.clientId === clientId);
|
||||
if (index === -1) return false;
|
||||
mockOAuthClients.splice(index, 1);
|
||||
return true;
|
||||
}),
|
||||
})),
|
||||
getOAuthTokenDao: jest.fn(() => ({
|
||||
findAll: jest.fn(async () => [...mockOAuthTokens]),
|
||||
findByAccessToken: jest.fn(
|
||||
async (accessToken: string) =>
|
||||
mockOAuthTokens.find((t) => t.accessToken === accessToken) || null,
|
||||
),
|
||||
findByRefreshToken: jest.fn(
|
||||
async (refreshToken: string) =>
|
||||
mockOAuthTokens.find((t) => t.refreshToken === refreshToken) || null,
|
||||
),
|
||||
create: jest.fn(async (token: IOAuthToken) => {
|
||||
mockOAuthTokens.push(token);
|
||||
return token;
|
||||
}),
|
||||
revokeToken: jest.fn(async (token: string) => {
|
||||
const index = mockOAuthTokens.findIndex(
|
||||
(t) => t.accessToken === token || t.refreshToken === token,
|
||||
);
|
||||
if (index === -1) return false;
|
||||
mockOAuthTokens.splice(index, 1);
|
||||
return true;
|
||||
}),
|
||||
cleanupExpired: jest.fn(async () => {
|
||||
const now = new Date();
|
||||
mockOAuthTokens = mockOAuthTokens.filter((t) => {
|
||||
const accessExpired = t.accessTokenExpiresAt < now;
|
||||
const refreshExpired =
|
||||
!t.refreshToken || (t.refreshTokenExpiresAt && t.refreshTokenExpiresAt < now);
|
||||
return !accessExpired || !refreshExpired;
|
||||
});
|
||||
}),
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
describe('OAuth Model', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
// Reset mock settings before each test
|
||||
mockSettings = { mcpServers: {}, users: [], oauthClients: [] };
|
||||
// Reset mock storage before each test
|
||||
mockOAuthClients = [];
|
||||
mockOAuthTokens = [];
|
||||
});
|
||||
|
||||
describe('OAuth Client Management', () => {
|
||||
test('should create a new OAuth client', () => {
|
||||
const client = {
|
||||
test('should create a new OAuth client', async () => {
|
||||
const client: IOAuthClient = {
|
||||
clientId: 'test-client',
|
||||
clientSecret: 'test-secret',
|
||||
name: 'Test Client',
|
||||
@@ -41,15 +98,15 @@ describe('OAuth Model', () => {
|
||||
scopes: ['read', 'write'],
|
||||
};
|
||||
|
||||
const created = createOAuthClient(client);
|
||||
const created = await createOAuthClient(client);
|
||||
expect(created).toEqual(client);
|
||||
|
||||
const found = findOAuthClientById('test-client');
|
||||
const found = await findOAuthClientById('test-client');
|
||||
expect(found).toEqual(client);
|
||||
});
|
||||
|
||||
test('should not create duplicate OAuth client', () => {
|
||||
const client = {
|
||||
test('should not create duplicate OAuth client', async () => {
|
||||
const client: IOAuthClient = {
|
||||
clientId: 'test-client',
|
||||
clientSecret: 'test-secret',
|
||||
name: 'Test Client',
|
||||
@@ -58,12 +115,12 @@ describe('OAuth Model', () => {
|
||||
scopes: ['read'],
|
||||
};
|
||||
|
||||
createOAuthClient(client);
|
||||
expect(() => createOAuthClient(client)).toThrow();
|
||||
await createOAuthClient(client);
|
||||
await expect(createOAuthClient(client)).rejects.toThrow();
|
||||
});
|
||||
|
||||
test('should update an OAuth client', () => {
|
||||
const client = {
|
||||
test('should update an OAuth client', async () => {
|
||||
const client: IOAuthClient = {
|
||||
clientId: 'test-client',
|
||||
clientSecret: 'test-secret',
|
||||
name: 'Test Client',
|
||||
@@ -72,9 +129,9 @@ describe('OAuth Model', () => {
|
||||
scopes: ['read'],
|
||||
};
|
||||
|
||||
createOAuthClient(client);
|
||||
await createOAuthClient(client);
|
||||
|
||||
const updated = updateOAuthClient('test-client', {
|
||||
const updated = await updateOAuthClient('test-client', {
|
||||
name: 'Updated Client',
|
||||
scopes: ['read', 'write'],
|
||||
});
|
||||
@@ -83,8 +140,8 @@ describe('OAuth Model', () => {
|
||||
expect(updated?.scopes).toEqual(['read', 'write']);
|
||||
});
|
||||
|
||||
test('should delete an OAuth client', () => {
|
||||
const client = {
|
||||
test('should delete an OAuth client', async () => {
|
||||
const client: IOAuthClient = {
|
||||
clientId: 'test-client',
|
||||
clientSecret: 'test-secret',
|
||||
name: 'Test Client',
|
||||
@@ -93,12 +150,12 @@ describe('OAuth Model', () => {
|
||||
scopes: ['read'],
|
||||
};
|
||||
|
||||
createOAuthClient(client);
|
||||
expect(findOAuthClientById('test-client')).toBeDefined();
|
||||
await createOAuthClient(client);
|
||||
expect(await findOAuthClientById('test-client')).toBeDefined();
|
||||
|
||||
const deleted = deleteOAuthClient('test-client');
|
||||
const deleted = await deleteOAuthClient('test-client');
|
||||
expect(deleted).toBe(true);
|
||||
expect(findOAuthClientById('test-client')).toBeUndefined();
|
||||
expect(await findOAuthClientById('test-client')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -157,8 +214,8 @@ describe('OAuth Model', () => {
|
||||
});
|
||||
|
||||
describe('Token Management', () => {
|
||||
test('should save and retrieve token', () => {
|
||||
const token = saveToken(
|
||||
test('should save and retrieve token', async () => {
|
||||
const token = await saveToken(
|
||||
{
|
||||
scope: 'read write',
|
||||
clientId: 'test-client',
|
||||
@@ -172,14 +229,14 @@ describe('OAuth Model', () => {
|
||||
expect(token.refreshToken).toBeDefined();
|
||||
expect(token.accessTokenExpiresAt).toBeInstanceOf(Date);
|
||||
|
||||
const retrieved = getToken(token.accessToken);
|
||||
const retrieved = await getToken(token.accessToken);
|
||||
expect(retrieved).toBeDefined();
|
||||
expect(retrieved?.clientId).toBe('test-client');
|
||||
expect(retrieved?.username).toBe('testuser');
|
||||
});
|
||||
|
||||
test('should retrieve token by refresh token', () => {
|
||||
const token = saveToken(
|
||||
test('should retrieve token by refresh token', async () => {
|
||||
const token = await saveToken(
|
||||
{
|
||||
scope: 'read',
|
||||
clientId: 'test-client',
|
||||
@@ -191,13 +248,13 @@ describe('OAuth Model', () => {
|
||||
|
||||
expect(token.refreshToken).toBeDefined();
|
||||
|
||||
const retrieved = getToken(token.refreshToken!);
|
||||
const retrieved = await getToken(token.refreshToken!);
|
||||
expect(retrieved).toBeDefined();
|
||||
expect(retrieved?.accessToken).toBe(token.accessToken);
|
||||
});
|
||||
|
||||
test('should not retrieve expired access token', async () => {
|
||||
const token = saveToken(
|
||||
const token = await saveToken(
|
||||
{
|
||||
scope: 'read',
|
||||
clientId: 'test-client',
|
||||
@@ -208,12 +265,12 @@ describe('OAuth Model', () => {
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
const retrieved = getToken(token.accessToken);
|
||||
const retrieved = await getToken(token.accessToken);
|
||||
expect(retrieved).toBeUndefined();
|
||||
});
|
||||
|
||||
test('should revoke token', () => {
|
||||
const token = saveToken(
|
||||
test('should revoke token', async () => {
|
||||
const token = await saveToken(
|
||||
{
|
||||
scope: 'read',
|
||||
clientId: 'test-client',
|
||||
@@ -223,13 +280,13 @@ describe('OAuth Model', () => {
|
||||
86400,
|
||||
);
|
||||
|
||||
expect(getToken(token.accessToken)).toBeDefined();
|
||||
expect(await getToken(token.accessToken)).toBeDefined();
|
||||
|
||||
revokeToken(token.accessToken);
|
||||
expect(getToken(token.accessToken)).toBeUndefined();
|
||||
await revokeToken(token.accessToken);
|
||||
expect(await getToken(token.accessToken)).toBeUndefined();
|
||||
|
||||
if (token.refreshToken) {
|
||||
expect(getToken(token.refreshToken)).toBeUndefined();
|
||||
expect(await getToken(token.refreshToken)).toBeUndefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user