mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-03-21 06:10:52 -07:00
refactor: rename to agent tabs
This commit is contained in:
parent
0eddb91ea3
commit
4e668d0929
19 changed files with 102 additions and 67 deletions
|
|
@ -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();
|
||||
|
||||
|
|
@ -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 (
|
||||
<Switch>
|
||||
{/* 使用相对路径,因为我们已经在嵌套路由中 */}
|
||||
<Route path='/session/:sessionID*' component={AgentSessions} />
|
||||
<Route path='/session/:sessionID*' component={AgentTabs} />
|
||||
<Route path='/agents' component={AgentsManage} />
|
||||
<Route path='/' component={AgentSessions} />
|
||||
<Route path='/' component={AgentTabs} />
|
||||
</Switch>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
92
src/services/agent/defaultAgents/index.ts
Normal file
92
src/services/agent/defaultAgents/index.ts
Normal file
|
|
@ -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<string, Agent>,
|
||||
databaseManager: AgentDatabaseManager,
|
||||
): Promise<void> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<void> {
|
||||
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
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue