diff --git a/src/pages/Agent/AgentSessions/ChatSessionUI.tsx b/src/pages/Agent/AgentTabs/ChatSessionUI.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/ChatSessionUI.tsx
rename to src/pages/Agent/AgentTabs/ChatSessionUI.tsx
diff --git a/src/pages/Agent/AgentSessions/components/ChatInput.tsx b/src/pages/Agent/AgentTabs/components/ChatInput.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/ChatInput.tsx
rename to src/pages/Agent/AgentTabs/components/ChatInput.tsx
diff --git a/src/pages/Agent/AgentSessions/components/EmptyState.tsx b/src/pages/Agent/AgentTabs/components/EmptyState.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/EmptyState.tsx
rename to src/pages/Agent/AgentTabs/components/EmptyState.tsx
diff --git a/src/pages/Agent/AgentSessions/components/LoadingIndicator.tsx b/src/pages/Agent/AgentTabs/components/LoadingIndicator.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/LoadingIndicator.tsx
rename to src/pages/Agent/AgentTabs/components/LoadingIndicator.tsx
diff --git a/src/pages/Agent/AgentSessions/components/ModelConfigDialog.tsx b/src/pages/Agent/AgentTabs/components/ModelConfigDialog.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/ModelConfigDialog.tsx
rename to src/pages/Agent/AgentTabs/components/ModelConfigDialog.tsx
diff --git a/src/pages/Agent/AgentSessions/components/TaskListItem.tsx b/src/pages/Agent/AgentTabs/components/TaskListItem.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/TaskListItem.tsx
rename to src/pages/Agent/AgentTabs/components/TaskListItem.tsx
diff --git a/src/pages/Agent/AgentSessions/components/TaskMessage.tsx b/src/pages/Agent/AgentTabs/components/TaskMessage.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/TaskMessage.tsx
rename to src/pages/Agent/AgentTabs/components/TaskMessage.tsx
diff --git a/src/pages/Agent/AgentSessions/components/TaskMessages.tsx b/src/pages/Agent/AgentTabs/components/TaskMessages.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/TaskMessages.tsx
rename to src/pages/Agent/AgentTabs/components/TaskMessages.tsx
diff --git a/src/pages/Agent/AgentSessions/components/TaskMessagesHeader.tsx b/src/pages/Agent/AgentTabs/components/TaskMessagesHeader.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/TaskMessagesHeader.tsx
rename to src/pages/Agent/AgentTabs/components/TaskMessagesHeader.tsx
diff --git a/src/pages/Agent/AgentSessions/components/TasksGroup.tsx b/src/pages/Agent/AgentTabs/components/TasksGroup.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/TasksGroup.tsx
rename to src/pages/Agent/AgentTabs/components/TasksGroup.tsx
diff --git a/src/pages/Agent/AgentSessions/components/TasksList.tsx b/src/pages/Agent/AgentTabs/components/TasksList.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/TasksList.tsx
rename to src/pages/Agent/AgentTabs/components/TasksList.tsx
diff --git a/src/pages/Agent/AgentSessions/components/TasksListHeader.tsx b/src/pages/Agent/AgentTabs/components/TasksListHeader.tsx
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/TasksListHeader.tsx
rename to src/pages/Agent/AgentTabs/components/TasksListHeader.tsx
diff --git a/src/pages/Agent/AgentSessions/components/useAIConfigManagement.ts b/src/pages/Agent/AgentTabs/components/useAIConfigManagement.ts
similarity index 100%
rename from src/pages/Agent/AgentSessions/components/useAIConfigManagement.ts
rename to src/pages/Agent/AgentTabs/components/useAIConfigManagement.ts
diff --git a/src/pages/Agent/AgentSessions/index.tsx b/src/pages/Agent/AgentTabs/index.tsx
similarity index 98%
rename from src/pages/Agent/AgentSessions/index.tsx
rename to src/pages/Agent/AgentTabs/index.tsx
index eae78495..ee28790f 100644
--- a/src/pages/Agent/AgentSessions/index.tsx
+++ b/src/pages/Agent/AgentTabs/index.tsx
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect } from 'react';
import { ChatSessionUI } from './ChatSessionUI';
import { useAgentStore, useAgentStoreInitialization } from './store';
-export function AgentSessions(): React.JSX.Element {
+export function AgentTabs(): React.JSX.Element {
// 初始化store
useAgentStoreInitialization();
diff --git a/src/pages/Agent/AgentSessions/store.ts b/src/pages/Agent/AgentTabs/store.ts
similarity index 100%
rename from src/pages/Agent/AgentSessions/store.ts
rename to src/pages/Agent/AgentTabs/store.ts
diff --git a/src/pages/Agent/index.tsx b/src/pages/Agent/index.tsx
index c20d8109..05f3111d 100644
--- a/src/pages/Agent/index.tsx
+++ b/src/pages/Agent/index.tsx
@@ -1,16 +1,16 @@
import { Route, Switch } from 'wouter';
import React from 'react';
-import { AgentSessions } from './AgentSessions';
+import { AgentTabs } from './AgentTabs';
import { AgentsManage } from './AgentsManage';
export default function Agent(): React.JSX.Element {
return (
{/* 使用相对路径,因为我们已经在嵌套路由中 */}
-
+
-
+
);
}
diff --git a/src/pages/Preferences/sections/ExternalAPI/index.tsx b/src/pages/Preferences/sections/ExternalAPI/index.tsx
index dd060d19..be34110f 100644
--- a/src/pages/Preferences/sections/ExternalAPI/index.tsx
+++ b/src/pages/Preferences/sections/ExternalAPI/index.tsx
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
import { List } from '@mui/material';
import { ListItemText } from '@/components/ListItem';
-import { useTaskConfigManagement } from '@/pages/Agent/AgentSessions/components/useAIConfigManagement';
+import { useTaskConfigManagement } from '@/pages/Agent/AgentTabs/components/useAIConfigManagement';
import { AIProviderConfig, ModelInfo } from '@services/externalAPI/interface';
import { ListItemVertical, Paper, SectionTitle } from '../../PreferenceComponents';
import type { ISectionProps } from '../../useSections';
diff --git a/src/services/agent/defaultAgents/index.ts b/src/services/agent/defaultAgents/index.ts
new file mode 100644
index 00000000..74023de6
--- /dev/null
+++ b/src/services/agent/defaultAgents/index.ts
@@ -0,0 +1,92 @@
+import { logger } from '@services/libs/log';
+import { AgentDatabaseManager } from '../AgentDatabaseManager';
+import { AgentServerManager } from '../AgentServerManager';
+import { Agent } from '../interface';
+import { echoHandler } from './echo';
+import { exampleAgentHandler } from './exampleAgent';
+
+// Define default agent configurations
+const defaultAgents: Agent[] = [
+ // Echo agent
+ {
+ id: 'echo-agent',
+ name: 'Echo Agent',
+ description: 'Simple echo agent that returns user messages',
+ avatarUrl: 'https://example.com/echo-agent.png',
+ handler: echoHandler,
+ card: {
+ name: 'Echo Agent',
+ description: 'Simple echo agent',
+ url: 'http://localhost:41241/echo-agent',
+ version: '1.0.0',
+ capabilities: {
+ streaming: true,
+ },
+ skills: [
+ {
+ id: 'echo',
+ name: 'Echo',
+ description: 'Echo user input',
+ },
+ ],
+ },
+ },
+ // Example agent
+ {
+ id: 'example-agent',
+ name: 'Example Agent',
+ description: 'Example agent with prompt processing',
+ avatarUrl: 'https://example.com/example-agent.png',
+ handler: exampleAgentHandler,
+ card: {
+ name: 'Example Agent',
+ description: 'Example agent with prompt processing',
+ url: 'http://localhost:41241/example-agent',
+ version: '1.0.0',
+ capabilities: {
+ streaming: true,
+ },
+ skills: [
+ {
+ id: 'example',
+ name: 'Example Processing',
+ description: 'Process prompts with custom configuration',
+ },
+ ],
+ },
+ },
+];
+
+/**
+ * Register default agents
+ * Only store default agents when they don't exist in database to avoid overwriting user configurations
+ */
+export async function registerDefaultAgents(
+ agents: Map,
+ databaseManager: AgentDatabaseManager,
+): Promise {
+ try {
+ logger.info('Registering default agents');
+
+ for (const defaultAgent of defaultAgents) {
+ const existingAgent = await databaseManager.getAgent(defaultAgent.id);
+
+ if (!existingAgent) {
+ logger.info(`Creating default agent: ${defaultAgent.id}`);
+ agents.set(defaultAgent.id, defaultAgent);
+ await databaseManager.saveAgent({
+ id: defaultAgent.id,
+ name: defaultAgent.name,
+ description: defaultAgent.description,
+ avatarUrl: defaultAgent.avatarUrl,
+ card: defaultAgent.card,
+ });
+ }
+ }
+
+ logger.info('Default agents registered successfully');
+ } catch (error) {
+ logger.error('Error registering default agents:', error);
+ throw error;
+ }
+}
diff --git a/src/services/agent/index.ts b/src/services/agent/index.ts
index 6346f138..ec0e6810 100644
--- a/src/services/agent/index.ts
+++ b/src/services/agent/index.ts
@@ -9,11 +9,12 @@ import { logger } from '@services/libs/log';
import serviceIdentifier from '@services/serviceIdentifier';
import { IWikiService } from '@services/wiki/interface';
-import { echoHandler } from './defaultAgents/echo';
+// Import from the new centralized location
+import { registerDefaultAgents } from './defaultAgents';
import type { Agent, AgentServiceConfig, AgentTask, IAgentService } from './interface';
import * as schema from './server/schema';
-// Import the new manager classes
+// Import the manager classes
import { AgentConfigManager } from './AgentConfigManager';
import { AgentDatabaseManager } from './AgentDatabaseManager';
import { AgentServerManager } from './AgentServerManager';
@@ -60,8 +61,8 @@ export class AgentService implements IAgentService {
this.serverManager = new AgentServerManager(dataSource);
this.configManager = new AgentConfigManager(this.dbManager, this.externalAPIService);
- // Register default agents
- await this.registerDefaultAgents();
+ // Register default agents using the refactored function
+ await registerDefaultAgents(this.agents, this.dbManager);
this.initialized = true;
} catch (error) {
@@ -70,64 +71,6 @@ export class AgentService implements IAgentService {
}
}
- /**
- * Register default agents
- */
- private async registerDefaultAgents(): Promise {
- try {
- logger.info('Registering default agents');
-
- // Example: Register a simple echo agent
- const echoAgent: Agent = {
- id: 'echo-agent',
- name: 'Echo Agent',
- description: 'Simple echo agent that returns user messages',
- avatarUrl: 'https://example.com/echo-agent.png',
- handler: echoHandler,
- card: {
- name: 'Echo Agent',
- description: 'Simple echo agent',
- url: 'http://localhost:41241/echo-agent',
- version: '1.0.0',
- capabilities: {
- streaming: true,
- },
- skills: [
- {
- id: 'echo',
- name: 'Echo',
- description: 'Echo user input',
- },
- ],
- },
- };
-
- // Store agent in memory
- this.agents.set(echoAgent.id, echoAgent);
-
- // Store agent in database
- if (this.dbManager) {
- await this.dbManager.saveAgent({
- id: echoAgent.id,
- name: echoAgent.name,
- description: echoAgent.description,
- avatarUrl: echoAgent.avatarUrl,
- card: echoAgent.card,
- });
- }
-
- // Create server instance
- if (this.serverManager) {
- await this.serverManager.getOrCreateServer(echoAgent);
- }
-
- logger.info('Registered default agent:', echoAgent.id);
- } catch (error) {
- logger.error('Error registering default agents:', error);
- throw error;
- }
- }
-
/**
* Notify task update
*/