feat: update SCSS imports to use new Sass module system, enhance SystemPage with model tags display and API key handling, and improve model fetching logic with better error handling and notifications

This commit is contained in:
Supra4E8C
2025-12-08 20:20:47 +08:00
parent 450964fb1a
commit 9d7db57c6a
10 changed files with 192 additions and 55 deletions

View File

@@ -5,25 +5,37 @@
import axios from 'axios';
import { normalizeModelList } from '@/utils/models';
const buildModelsEndpoint = (baseUrl: string): string => {
if (!baseUrl) return '';
const trimmed = String(baseUrl).trim().replace(/\/+$/g, '');
if (!trimmed) return '';
if (trimmed.endsWith('/v1')) {
return `${trimmed}/models`;
const normalizeBaseUrl = (baseUrl: string): string => {
let normalized = String(baseUrl || '').trim();
if (!normalized) return '';
normalized = normalized.replace(/\/?v0\/management\/?$/i, '');
normalized = normalized.replace(/\/+$/g, '');
if (!/^https?:\/\//i.test(normalized)) {
normalized = `http://${normalized}`;
}
return `${trimmed}/v1/models`;
return normalized;
};
const buildModelsEndpoint = (baseUrl: string): string => {
const normalized = normalizeBaseUrl(baseUrl);
if (!normalized) return '';
return normalized.endsWith('/v1') ? `${normalized}/models` : `${normalized}/v1/models`;
};
export const modelsApi = {
async fetchModels(baseUrl: string, apiKey?: string) {
async fetchModels(baseUrl: string, apiKey?: string, headers: Record<string, string> = {}) {
const endpoint = buildModelsEndpoint(baseUrl);
if (!endpoint) {
throw new Error('Invalid base url');
}
const resolvedHeaders = { ...headers };
if (apiKey) {
resolvedHeaders.Authorization = `Bearer ${apiKey}`;
}
const response = await axios.get(endpoint, {
headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : undefined
headers: Object.keys(resolvedHeaders).length ? resolvedHeaders : undefined
});
const payload = response.data?.data ?? response.data?.models ?? response.data;
return normalizeModelList(payload, { dedupe: true });