mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-02 10:29:02 +08:00
✨ feat: initialize AgentService in ApiServer and improve ID generation logic
This commit is contained in:
parent
5eaa90a7a2
commit
9c956a30ea
@ -1,5 +1,6 @@
|
||||
import { createServer } from 'node:http'
|
||||
|
||||
import { agentService } from '../services/agents/AgentService'
|
||||
import { loggerService } from '../services/LoggerService'
|
||||
import { app } from './app'
|
||||
import { config } from './config'
|
||||
@ -18,6 +19,11 @@ export class ApiServer {
|
||||
// Load config
|
||||
const { port, host, apiKey } = await config.load()
|
||||
|
||||
// Initialize AgentService
|
||||
logger.info('Initializing AgentService...')
|
||||
await agentService.initialize()
|
||||
logger.info('AgentService initialized successfully')
|
||||
|
||||
// Create server with Express app
|
||||
this.server = createServer(app)
|
||||
|
||||
|
||||
@ -202,7 +202,7 @@ export class AgentService {
|
||||
async createAgent(agentData: CreateAgentRequest): Promise<AgentEntity> {
|
||||
this.ensureInitialized()
|
||||
|
||||
const id = `agent_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
|
||||
const id = `agent_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`
|
||||
const now = new Date().toISOString()
|
||||
|
||||
const serializedData = this.serializeJsonFields(agentData)
|
||||
@ -382,7 +382,7 @@ export class AgentService {
|
||||
throw new Error(`Agent with id ${sessionData.main_agent_id} does not exist`)
|
||||
}
|
||||
|
||||
const id = `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
|
||||
const id = `session_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`
|
||||
const now = new Date().toISOString()
|
||||
|
||||
const serializedData = this.serializeJsonFields(sessionData)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user