refactor: 清理未使用的类型定义和接口字段

- 移除 Provider 相关的 apiKeyEnvVar 字段(未实现的功能)
- 清理 Server routes 中未使用的 Core 类型导入
- 清理 UI Message 接口中未使用的 metadata 字段
This commit is contained in:
2025-12-30 10:41:38 +08:00
parent 243f8dc860
commit 5f38753f6d
16 changed files with 9 additions and 98 deletions
@@ -10,7 +10,6 @@ export const anthropicProvider: ProviderInfo = {
name: 'Anthropic', name: 'Anthropic',
description: 'Claude AI models by Anthropic', description: 'Claude AI models by Anthropic',
builtin: true, builtin: true,
apiKeyEnvVar: 'ANTHROPIC_API_KEY',
models: [ models: [
{ {
id: 'claude-sonnet-4-20250514', id: 'claude-sonnet-4-20250514',
@@ -10,7 +10,6 @@ export const deepseekProvider: ProviderInfo = {
name: 'DeepSeek', name: 'DeepSeek',
description: 'DeepSeek AI models', description: 'DeepSeek AI models',
builtin: true, builtin: true,
apiKeyEnvVar: 'DEEPSEEK_API_KEY',
models: [ models: [
{ {
id: 'deepseek-chat', id: 'deepseek-chat',
@@ -11,7 +11,6 @@ export const openaiProvider: ProviderInfo = {
name: 'OpenAI', name: 'OpenAI',
description: 'GPT models by OpenAI (also supports OpenAI-compatible APIs)', description: 'GPT models by OpenAI (also supports OpenAI-compatible APIs)',
builtin: true, builtin: true,
apiKeyEnvVar: 'OPENAI_API_KEY',
models: [ models: [
{ {
id: 'gpt-4o', id: 'gpt-4o',
-2
View File
@@ -168,7 +168,6 @@ export class ProviderRegistry {
description: provider.info.description, description: provider.info.description,
builtin: provider.info.builtin, builtin: provider.info.builtin,
baseUrl: config?.baseUrl ?? provider.info.baseUrl, baseUrl: config?.baseUrl ?? provider.info.baseUrl,
apiKeyEnvVar: provider.info.apiKeyEnvVar,
models: provider.info.models, models: provider.info.models,
allowCustomModels: provider.info.allowCustomModels ?? false, allowCustomModels: provider.info.allowCustomModels ?? false,
config: { config: {
@@ -200,7 +199,6 @@ export class ProviderRegistry {
description: definition.description, description: definition.description,
builtin: false, builtin: false,
baseUrl: definition.baseUrl, baseUrl: definition.baseUrl,
apiKeyEnvVar: definition.apiKeyEnvVar,
models: definition.models ?? [], models: definition.models ?? [],
allowCustomModels: definition.allowCustomModels ?? true, allowCustomModels: definition.allowCustomModels ?? true,
}; };
+1 -8
View File
@@ -48,8 +48,6 @@ export interface ProviderInfo {
builtin: boolean; builtin: boolean;
/** API 基础 URL */ /** API 基础 URL */
baseUrl?: string; baseUrl?: string;
/** API Key 环境变量名 */
apiKeyEnvVar?: string;
/** 可用模型列表 */ /** 可用模型列表 */
models: ModelInfo[]; models: ModelInfo[];
/** 是否允许自定义模型 */ /** 是否允许自定义模型 */
@@ -60,10 +58,8 @@ export interface ProviderInfo {
export interface ProviderConfig { export interface ProviderConfig {
/** 提供商 ID */ /** 提供商 ID */
id: string; id: string;
/** API Key(直接存储,不推荐) */ /** API Key */
apiKey?: string; apiKey?: string;
/** API Key 环境变量名 */
apiKeyEnvVar?: string;
/** 自定义 Base URL */ /** 自定义 Base URL */
baseUrl?: string; baseUrl?: string;
/** 是否启用 */ /** 是否启用 */
@@ -82,8 +78,6 @@ export interface CustomProviderDefinition {
description?: string; description?: string;
/** API 基础 URL(必填) */ /** API 基础 URL(必填) */
baseUrl: string; baseUrl: string;
/** API Key 环境变量名 */
apiKeyEnvVar?: string;
/** 可用模型列表 */ /** 可用模型列表 */
models?: ModelInfo[]; models?: ModelInfo[];
/** 是否允许自定义模型 */ /** 是否允许自定义模型 */
@@ -157,7 +151,6 @@ export interface ProviderDetail {
description?: string; description?: string;
builtin: boolean; builtin: boolean;
baseUrl?: string; baseUrl?: string;
apiKeyEnvVar?: string;
models: ModelInfo[]; models: ModelInfo[];
allowCustomModels: boolean; allowCustomModels: boolean;
config?: { config?: {
-1
View File
@@ -9,7 +9,6 @@ import { getConfig } from './config.js';
import type { import type {
AgentMode, AgentMode,
AgentInfo, AgentInfo,
AgentConfigFile,
AgentModelConfig, AgentModelConfig,
AgentPermission, AgentPermission,
} from '@ai-assistant/core'; } from '@ai-assistant/core';
+1 -14
View File
@@ -6,20 +6,7 @@
import { Hono } from 'hono'; import { Hono } from 'hono';
import { getConfig } from './config.js'; import { getConfig } from './config.js';
import type { import type { CheckpointMetadata } from '@ai-assistant/core';
CheckpointMetadata,
CheckpointConfig,
CheckpointTrigger,
FileChange,
FileChangeType,
DiffInfo,
FileDiff,
RollbackOptions,
RollbackResult,
RollbackRecord,
SafetyCheckResult,
UnrevertResult,
} from '@ai-assistant/core';
import { import {
CheckpointManager, CheckpointManager,
getCheckpointManager, getCheckpointManager,
+1 -5
View File
@@ -7,11 +7,7 @@
import { Hono } from 'hono'; import { Hono } from 'hono';
import { z } from 'zod'; import { z } from 'zod';
import { getConfig } from './config.js'; import { getConfig } from './config.js';
import type { // Command, CommandInput, CommandExecutionResult 类型由函数自动推断
Command,
CommandInput,
CommandExecutionResult,
} from '@ai-assistant/core';
import { import {
getCommandRegistry, getCommandRegistry,
createCommandExecutor, createCommandExecutor,
+1 -4
View File
@@ -6,10 +6,7 @@
import { Hono } from 'hono'; import { Hono } from 'hono';
import { getConfig } from './config.js'; import { getConfig } from './config.js';
import type { import type { FileDiagnostic } from '@ai-assistant/core';
FileDiagnostic,
ServerStatus,
} from '@ai-assistant/core';
import { import {
initLSP, initLSP,
listServers, listServers,
+1 -6
View File
@@ -6,12 +6,7 @@
import { Hono } from 'hono'; import { Hono } from 'hono';
import { getConfig } from './config.js'; import { getConfig } from './config.js';
import type { import type { MCPConfig } from '@ai-assistant/core';
MCPConfig,
MCPServerConfig,
MCPServerStatus,
MCPTool,
} from '@ai-assistant/core';
import { import {
getMCPManager, getMCPManager,
loadMCPConfig, loadMCPConfig,
+1 -1
View File
@@ -5,7 +5,7 @@
*/ */
import { Hono } from 'hono'; import { Hono } from 'hono';
import type { ServiceConfig, ServiceType } from '@ai-assistant/core'; import type { ServiceType } from '@ai-assistant/core';
import { import {
loadProvidersConfig, loadProvidersConfig,
getServiceConfig, getServiceConfig,
+1 -1
View File
@@ -11,7 +11,7 @@ import {
type Message, type Message,
type MessagePart, type MessagePart,
} from '../types.js'; } from '../types.js';
import type { MessageInfo, Part, ApiPart } from '@ai-assistant/core'; // MessageInfo, Part, ApiPart 从 Core 导入但仅用于类型推导
import { MessageStorage, PartStorage, partsToApiFormat } from '@ai-assistant/core'; import { MessageStorage, PartStorage, partsToApiFormat } from '@ai-assistant/core';
export const sessionsRouter = new Hono(); export const sessionsRouter = new Hono();
-5
View File
@@ -365,11 +365,6 @@ export interface Message {
parts: MessagePart[]; parts: MessagePart[];
/** 所有文本拼接(兼容字段) */ /** 所有文本拼接(兼容字段) */
content?: string; content?: string;
metadata?: {
model?: string;
stepCount?: number;
totalTokens?: number;
};
} }
/** @deprecated 使用 Message 代替 */ /** @deprecated 使用 Message 代替 */
+2 -13
View File
@@ -175,19 +175,14 @@ export interface Message {
parts: MessagePart[]; parts: MessagePart[];
/** 所有文本拼接(兼容字段) */ /** 所有文本拼接(兼容字段) */
content?: string; content?: string;
/** 是否包含推理过程 */
hasReasoning?: boolean;
/** 推理内容 */
reasoning?: string;
/** 元数据 */ /** 元数据 */
metadata?: { metadata?: {
model?: string;
stepCount?: number;
totalTokens?: number;
/** 输入 Token 数 */ /** 输入 Token 数 */
inputTokens?: number; inputTokens?: number;
/** 输出 Token 数 */ /** 输出 Token 数 */
outputTokens?: number; outputTokens?: number;
/** 总 Token 数 */
totalTokens?: number;
/** 生成此消息的 Agent 名称 */ /** 生成此消息的 Agent 名称 */
agentName?: string; agentName?: string;
}; };
@@ -842,8 +837,6 @@ export interface ProviderDetail {
builtin: boolean; builtin: boolean;
/** API 基础 URL */ /** API 基础 URL */
baseUrl?: string; baseUrl?: string;
/** API Key 环境变量名 */
apiKeyEnvVar?: string;
/** 可用模型列表 */ /** 可用模型列表 */
models: ModelInfo[]; models: ModelInfo[];
/** 是否允许自定义模型 */ /** 是否允许自定义模型 */
@@ -867,8 +860,6 @@ export interface CustomProviderDefinition {
description?: string; description?: string;
/** API 基础 URL(必填) */ /** API 基础 URL(必填) */
baseUrl: string; baseUrl: string;
/** API Key 环境变量名 */
apiKeyEnvVar?: string;
/** 预设模型列表 */ /** 预设模型列表 */
models?: ModelInfo[]; models?: ModelInfo[];
/** 是否允许自定义模型 */ /** 是否允许自定义模型 */
@@ -881,8 +872,6 @@ export interface ProviderConfig {
id?: string; id?: string;
/** API Key */ /** API Key */
apiKey?: string; apiKey?: string;
/** API Key 环境变量名 */
apiKeyEnvVar?: string;
/** 自定义 API 基础 URL */ /** 自定义 API 基础 URL */
baseUrl?: string; baseUrl?: string;
/** 是否启用 */ /** 是否启用 */
@@ -54,7 +54,6 @@ export function ProviderEditor({
// Form state // Form state
const [apiKey, setApiKey] = useState(''); const [apiKey, setApiKey] = useState('');
const [apiKeyEnvVar, setApiKeyEnvVar] = useState('');
const [baseUrl, setBaseUrl] = useState(''); const [baseUrl, setBaseUrl] = useState('');
const [enabled, setEnabled] = useState(true); const [enabled, setEnabled] = useState(true);
@@ -84,7 +83,6 @@ export function ProviderEditor({
const config = result.data.config; const config = result.data.config;
// API key is not returned for security, but we show if it's configured via hasApiKey // API key is not returned for security, but we show if it's configured via hasApiKey
setApiKey(''); setApiKey('');
setApiKeyEnvVar(result.data.apiKeyEnvVar || '');
setBaseUrl(config.baseUrl || result.data.baseUrl || ''); setBaseUrl(config.baseUrl || result.data.baseUrl || '');
setEnabled(config.enabled !== false); setEnabled(config.enabled !== false);
} else { } else {
@@ -114,9 +112,6 @@ export function ProviderEditor({
if (apiKey.trim()) { if (apiKey.trim()) {
config.apiKey = apiKey; config.apiKey = apiKey;
} }
if (apiKeyEnvVar.trim() && apiKeyEnvVar !== provider?.apiKeyEnvVar) {
config.apiKeyEnvVar = apiKeyEnvVar;
}
if (baseUrl.trim() && baseUrl !== provider?.baseUrl) { if (baseUrl.trim() && baseUrl !== provider?.baseUrl) {
config.baseUrl = baseUrl; config.baseUrl = baseUrl;
} }
@@ -336,20 +331,6 @@ export function ProviderEditor({
)} )}
</div> </div>
{/* API Key Env Var */}
<div>
<label className="block text-xs text-fg-muted mb-1">
Environment Variable (alternative)
</label>
<Input
value={apiKeyEnvVar}
onChange={(e) => setApiKeyEnvVar(e.target.value)}
placeholder={provider?.apiKeyEnvVar || 'PROVIDER_API_KEY'}
/>
<p className="text-xs text-fg-subtle mt-1">
If no API key is set, this env var will be used
</p>
</div>
</div> </div>
{/* Base URL Section */} {/* Base URL Section */}
@@ -406,14 +406,6 @@ export function ProvidersPanel({ onClose, responsive = false }: ProvidersPanelPr
</div> </div>
)} )}
{/* API Key Env Var */}
{detail.apiKeyEnvVar && (
<div className="text-xs">
<span className="text-fg-muted">API Key Env:</span>{' '}
<code className="text-fg-secondary bg-surface-subtle px-1 rounded">{detail.apiKeyEnvVar}</code>
</div>
)}
{/* Models */} {/* Models */}
<div className="space-y-2"> <div className="space-y-2">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
@@ -688,14 +680,6 @@ export function ProvidersPanel({ onClose, responsive = false }: ProvidersPanelPr
placeholder="http://localhost:11434/v1" placeholder="http://localhost:11434/v1"
/> />
</div> </div>
<div>
<label className="text-xs text-fg-muted">API Key Env Var (optional)</label>
<Input
value={newProvider.apiKeyEnvVar || ''}
onChange={(e) => setNewProvider((p) => ({ ...p, apiKeyEnvVar: e.target.value }))}
placeholder="OLLAMA_API_KEY"
/>
</div>
</div> </div>
<div className="flex justify-end gap-2 pt-2"> <div className="flex justify-end gap-2 pt-2">
<Button variant="ghost" onClick={() => setShowAddProvider(false)}> <Button variant="ghost" onClick={() => setShowAddProvider(false)}>