(agentId: string)
| 124 | |
| 125 | // Chat management |
| 126 | async createChatSession(agentId: string): Promise<ChatSession> { |
| 127 | const agent = this.state.availableAgents.find(a => a.id === agentId); |
| 128 | if (!agent) { |
| 129 | throw new Error(`Agent not found: ${agentId}`); |
| 130 | } |
| 131 | |
| 132 | const session: ChatSession = { |
| 133 | id: `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`, |
| 134 | title: i18nService.t('flow-chat:session.chatWithAgent', { name: agent.name }), |
| 135 | messages: [], |
| 136 | agentId, |
| 137 | createdAt: new Date(), |
| 138 | updatedAt: new Date(), |
| 139 | isActive: true |
| 140 | }; |
| 141 | |
| 142 | // Add system message |
| 143 | if (agent.config?.systemPrompt) { |
| 144 | session.messages.push({ |
| 145 | id: `msg_${Date.now()}`, |
| 146 | role: 'system', |
| 147 | content: agent.config.systemPrompt, |
| 148 | timestamp: new Date(), |
| 149 | agentId |
| 150 | }); |
| 151 | } |
| 152 | |
| 153 | const updatedSessions = [...this.state.chatSessions, session]; |
| 154 | this.updateState({ |
| 155 | chatSessions: updatedSessions, |
| 156 | activeChatSession: session |
| 157 | }); |
| 158 | |
| 159 | this.emitEvent({ |
| 160 | type: 'chat:session:created', |
| 161 | payload: session |
| 162 | }); |
| 163 | |
| 164 | return session; |
| 165 | } |
| 166 | |
| 167 | selectChatSession(sessionId: string): void { |
| 168 | const session = this.state.chatSessions.find(s => s.id === sessionId); |
nothing calls this directly
no test coverage detected