feat: initialize new React application structure with TypeScript, ESLint, and Prettier configurations, while removing legacy files and adding new components and pages for enhanced functionality

This commit is contained in:
Supra4E8C
2025-12-07 11:32:31 +08:00
parent 8e4132200d
commit 450964fb1a
144 changed files with 14223 additions and 21647 deletions

36
src/types/api.ts Normal file
View File

@@ -0,0 +1,36 @@
/**
* API 相关类型定义
* 基于原项目 src/core/api-client.js 和各模块 API
*/
// HTTP 方法
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
// API 客户端配置
export interface ApiClientConfig {
apiBase: string;
managementKey: string;
timeout?: number;
}
// 请求选项
export interface RequestOptions {
method?: HttpMethod;
headers?: Record<string, string>;
params?: Record<string, any>;
data?: any;
}
// 服务器版本信息
export interface ServerVersion {
version: string;
buildDate?: string;
}
// API 错误
export type ApiError = Error & {
status?: number;
code?: string;
details?: any;
data?: any;
};

28
src/types/auth.ts Normal file
View File

@@ -0,0 +1,28 @@
/**
* 认证相关类型定义
* 基于原项目 src/modules/login.js 和 src/core/connection.js
*/
// 登录凭据
export interface LoginCredentials {
apiBase: string;
managementKey: string;
}
// 认证状态
export interface AuthState {
isAuthenticated: boolean;
apiBase: string;
managementKey: string;
serverVersion: string | null;
serverBuildDate: string | null;
}
// 连接状态
export type ConnectionStatus = 'connected' | 'disconnected' | 'connecting' | 'error';
export interface ConnectionInfo {
status: ConnectionStatus;
lastCheck: Date | null;
error: string | null;
}

34
src/types/authFile.ts Normal file
View File

@@ -0,0 +1,34 @@
/**
* 认证文件相关类型
* 基于原项目 src/modules/auth-files.js
*/
export type AuthFileType =
| 'qwen'
| 'gemini'
| 'gemini-cli'
| 'aistudio'
| 'claude'
| 'codex'
| 'antigravity'
| 'iflow'
| 'vertex'
| 'empty'
| 'unknown';
export interface AuthFileItem {
name: string;
type?: AuthFileType | string;
provider?: string;
size?: number;
authIndex?: string | number | null;
runtimeOnly?: boolean | string;
disabled?: boolean;
modified?: number;
[key: string]: any;
}
export interface AuthFilesResponse {
files: AuthFileItem[];
total?: number;
}

39
src/types/common.ts Normal file
View File

@@ -0,0 +1,39 @@
/**
* 通用类型定义
*/
export type Theme = 'light' | 'dark';
export type Language = 'zh-CN' | 'en';
export type NotificationType = 'info' | 'success' | 'warning' | 'error';
export interface Notification {
id: string;
message: string;
type: NotificationType;
duration?: number;
}
export interface ApiResponse<T = any> {
data?: T;
error?: string;
message?: string;
}
export interface PaginationState {
currentPage: number;
pageSize: number;
totalPages: number;
totalItems?: number;
}
export interface LoadingState {
isLoading: boolean;
error: Error | null;
}
// 泛型异步状态
export interface AsyncState<T> extends LoadingState {
data: T | null;
}

50
src/types/config.ts Normal file
View File

@@ -0,0 +1,50 @@
/**
* 配置相关类型定义
* 与基线 /config 返回结构保持一致(内部使用驼峰形式)
*/
import type { GeminiKeyConfig, ProviderKeyConfig, OpenAIProviderConfig } from './provider';
export interface QuotaExceededConfig {
switchProject?: boolean;
switchPreviewModel?: boolean;
}
export interface Config {
debug?: boolean;
proxyUrl?: string;
requestRetry?: number;
quotaExceeded?: QuotaExceededConfig;
usageStatisticsEnabled?: boolean;
requestLog?: boolean;
loggingToFile?: boolean;
wsAuth?: boolean;
apiKeys?: string[];
geminiApiKeys?: GeminiKeyConfig[];
codexApiKeys?: ProviderKeyConfig[];
claudeApiKeys?: ProviderKeyConfig[];
openaiCompatibility?: OpenAIProviderConfig[];
oauthExcludedModels?: Record<string, string[]>;
raw?: Record<string, any>;
}
export type RawConfigSection =
| 'debug'
| 'proxy-url'
| 'request-retry'
| 'quota-exceeded'
| 'usage-statistics-enabled'
| 'request-log'
| 'logging-to-file'
| 'ws-auth'
| 'api-keys'
| 'gemini-api-key'
| 'codex-api-key'
| 'claude-api-key'
| 'openai-compatibility'
| 'oauth-excluded-models';
export interface ConfigCache {
data: Config;
timestamp: number;
}

13
src/types/index.ts Normal file
View File

@@ -0,0 +1,13 @@
/**
* 类型定义统一导出
*/
export * from './common';
export * from './api';
export * from './config';
export * from './auth';
export * from './provider';
export * from './authFile';
export * from './oauth';
export * from './usage';
export * from './log';

23
src/types/log.ts Normal file
View File

@@ -0,0 +1,23 @@
/**
* 日志相关类型
* 基于原项目 src/modules/logs.js
*/
// 日志级别
export type LogLevel = 'info' | 'warn' | 'error' | 'debug';
// 日志条目
export interface LogEntry {
timestamp: string;
level: LogLevel;
message: string;
details?: any;
}
// 日志筛选
export interface LogFilter {
level?: LogLevel;
searchQuery: string;
startTime?: Date;
endTime?: Date;
}

36
src/types/oauth.ts Normal file
View File

@@ -0,0 +1,36 @@
/**
* OAuth 相关类型
* 基于原项目 src/modules/oauth.js
*/
// OAuth 提供商类型
export type OAuthProvider =
| 'codex'
| 'anthropic'
| 'antigravity'
| 'gemini-cli'
| 'qwen'
| 'iflow';
// OAuth 流程状态
export interface OAuthFlow {
provider: OAuthProvider;
deviceCode: string;
userCode: string;
verificationUrl: string;
expiresAt: Date;
interval: number;
status: 'pending' | 'authorized' | 'expired' | 'error';
}
// OAuth 配置
export interface OAuthConfig {
clientId?: string;
clientSecret?: string;
redirectUri?: string;
}
// OAuth 排除模型列表
export interface OAuthExcludedModels {
models: string[];
}

43
src/types/provider.ts Normal file
View File

@@ -0,0 +1,43 @@
/**
* AI 提供商相关类型
* 基于原项目 src/modules/ai-providers.js
*/
export interface ModelAlias {
name: string;
alias?: string;
priority?: number;
testModel?: string;
}
export interface ApiKeyEntry {
apiKey: string;
proxyUrl?: string;
headers?: Record<string, string>;
}
export interface GeminiKeyConfig {
apiKey: string;
baseUrl?: string;
headers?: Record<string, string>;
excludedModels?: string[];
}
export interface ProviderKeyConfig {
apiKey: string;
baseUrl?: string;
proxyUrl?: string;
headers?: Record<string, string>;
models?: ModelAlias[];
}
export interface OpenAIProviderConfig {
name: string;
baseUrl: string;
apiKeyEntries: ApiKeyEntry[];
headers?: Record<string, string>;
models?: ModelAlias[];
priority?: number;
testModel?: string;
[key: string]: any;
}

52
src/types/usage.ts Normal file
View File

@@ -0,0 +1,52 @@
/**
* 使用统计相关类型
* 基于原项目 src/modules/usage.js
*/
// 时间段类型
export type TimePeriod = 'hour' | 'day';
// 数据点
export interface DataPoint {
timestamp: string;
value: number;
}
// 模型使用统计
export interface ModelUsage {
modelName: string;
requests: number;
inputTokens: number;
outputTokens: number;
totalTokens: number;
cost: number;
}
// 使用统计数据
export interface UsageStats {
overview: {
totalRequests: number;
totalTokens: number;
totalCost: number;
};
requestsData: {
hour: DataPoint[];
day: DataPoint[];
};
tokensData: {
hour: DataPoint[];
day: DataPoint[];
};
costData: {
hour: DataPoint[];
day: DataPoint[];
};
modelStats: ModelUsage[];
}
// 模型价格
export interface ModelPrice {
modelName: string;
inputPricePer1M: number;
outputPricePer1M: number;
}