refactor(agent): 将 Summary Model 改造为内置 Sub Agent
- 扩展 AgentMode 类型添加 'internal' 模式 - 新增 summary agent preset (claude-3-5-haiku) - AgentRegistry 添加 getInternal/listInternalAgents 方法 - CompressionManager 添加 setSummaryModelFromAgentConfig - Agent 构造函数改用 Registry 配置初始化 Summary 模型 - 清理旧的 SummaryConfig 配置系统 - UI AgentsPanel 分离显示 System/Preset/Custom agents - UI AgentEditor 为 internal agent 显示简化编辑界面
This commit is contained in:
@@ -76,16 +76,6 @@ interface PermissionManager {
|
||||
setAskCallback(callback: (ctx: unknown) => Promise<{ allow: boolean; remember?: boolean }>): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary 配置接口
|
||||
*/
|
||||
export interface SummaryConfig {
|
||||
provider: string;
|
||||
apiKey: string;
|
||||
model: string;
|
||||
baseUrl?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Core 模块接口
|
||||
*/
|
||||
@@ -94,7 +84,6 @@ interface CoreModule {
|
||||
toolRegistry: ToolRegistry;
|
||||
loadConfig: () => unknown;
|
||||
saveConfig: (config: Record<string, unknown>) => void;
|
||||
loadSummaryConfig: () => SummaryConfig | null;
|
||||
getPermissionManager: (projectRoot?: string) => PermissionManager;
|
||||
}
|
||||
|
||||
@@ -443,71 +432,3 @@ export async function compressContext(
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 摘要配置 API
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* 摘要配置(不含 API Key 明文)
|
||||
*/
|
||||
export interface SummaryConfigInfo {
|
||||
provider?: string;
|
||||
model?: string;
|
||||
hasApiKey: boolean;
|
||||
baseUrl?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取摘要配置
|
||||
*/
|
||||
export function getSummaryConfig(): SummaryConfigInfo | null {
|
||||
if (!coreModule) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const config = coreModule.loadSummaryConfig();
|
||||
if (!config) {
|
||||
return {
|
||||
hasApiKey: false,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
provider: config.provider,
|
||||
model: config.model,
|
||||
hasApiKey: !!config.apiKey,
|
||||
baseUrl: config.baseUrl,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新摘要配置
|
||||
*/
|
||||
export function updateSummaryConfig(config: {
|
||||
provider?: string;
|
||||
model?: string;
|
||||
apiKey?: string;
|
||||
baseUrl?: string;
|
||||
}): boolean {
|
||||
if (!coreModule) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 构建要保存的配置
|
||||
const saveData: Record<string, unknown> = {};
|
||||
if (config.provider !== undefined) {
|
||||
saveData.summaryProvider = config.provider;
|
||||
}
|
||||
if (config.model !== undefined) {
|
||||
saveData.summaryModel = config.model;
|
||||
}
|
||||
if (config.apiKey !== undefined) {
|
||||
saveData.summaryApiKey = config.apiKey;
|
||||
}
|
||||
if (config.baseUrl !== undefined) {
|
||||
saveData.summaryBaseUrl = config.baseUrl;
|
||||
}
|
||||
|
||||
coreModule.saveConfig(saveData);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,12 +15,8 @@ export {
|
||||
// 上下文压缩相关
|
||||
getContextUsage,
|
||||
compressContext,
|
||||
getSummaryConfig,
|
||||
updateSummaryConfig,
|
||||
// 类型导出
|
||||
type TokenUsage,
|
||||
type CompressionResult,
|
||||
type ContextUsageInfo,
|
||||
type SummaryConfigInfo,
|
||||
type SummaryConfig,
|
||||
} from './adapter.js';
|
||||
|
||||
@@ -258,12 +258,9 @@ export {
|
||||
cancelProcessing,
|
||||
getContextUsage,
|
||||
compressContext,
|
||||
getSummaryConfig,
|
||||
updateSummaryConfig,
|
||||
type TokenUsage,
|
||||
type CompressionResult,
|
||||
type ContextUsageInfo,
|
||||
type SummaryConfigInfo,
|
||||
} from './agent/index.js';
|
||||
export {
|
||||
initAuth,
|
||||
|
||||
@@ -5,11 +5,6 @@
|
||||
*/
|
||||
|
||||
import { Hono } from 'hono';
|
||||
import {
|
||||
getSummaryConfig,
|
||||
updateSummaryConfig,
|
||||
type SummaryConfigInfo,
|
||||
} from '../agent/adapter.js';
|
||||
|
||||
export const configRouter = new Hono();
|
||||
|
||||
@@ -102,70 +97,3 @@ export function getConfig(): ServerConfig {
|
||||
export function setConfig(config: Partial<ServerConfig>): void {
|
||||
serverConfig = { ...serverConfig, ...config };
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 摘要配置 API
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* GET /config/summary - 获取摘要模型配置
|
||||
*/
|
||||
configRouter.get('/summary', (c) => {
|
||||
const config = getSummaryConfig();
|
||||
|
||||
if (!config) {
|
||||
// Core 模块不可用
|
||||
return c.json({
|
||||
success: true,
|
||||
data: {
|
||||
hasApiKey: false,
|
||||
} as SummaryConfigInfo,
|
||||
});
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
data: config,
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* PUT /config/summary - 更新摘要模型配置
|
||||
*/
|
||||
configRouter.put('/summary', async (c) => {
|
||||
try {
|
||||
const body = await c.req.json();
|
||||
|
||||
const success = updateSummaryConfig({
|
||||
provider: body.provider,
|
||||
model: body.model,
|
||||
apiKey: body.apiKey,
|
||||
baseUrl: body.baseUrl,
|
||||
});
|
||||
|
||||
if (!success) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Core module not available',
|
||||
},
|
||||
500
|
||||
);
|
||||
}
|
||||
|
||||
// 返回更新后的配置(不含 API Key)
|
||||
const config = getSummaryConfig();
|
||||
return c.json({
|
||||
success: true,
|
||||
data: config,
|
||||
});
|
||||
} catch (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Invalid input',
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user