|
@@ -1,13 +1,13 @@
|
|
|
import { Component } from '@angular/core';
|
|
import { Component } from '@angular/core';
|
|
|
import { CommonModule } from '@angular/common';
|
|
import { CommonModule } from '@angular/common';
|
|
|
import { FormsModule } from '@angular/forms';
|
|
import { FormsModule } from '@angular/forms';
|
|
|
-import { HttpClient, HttpClientModule } from '@angular/common/http';
|
|
|
|
|
import { MatCardModule } from '@angular/material/card';
|
|
import { MatCardModule } from '@angular/material/card';
|
|
|
import { MatInputModule } from '@angular/material/input';
|
|
import { MatInputModule } from '@angular/material/input';
|
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
|
import { MatListModule } from '@angular/material/list';
|
|
import { MatListModule } from '@angular/material/list';
|
|
|
import { webConfig } from '../config';
|
|
import { webConfig } from '../config';
|
|
|
import { io, Socket } from 'socket.io-client';
|
|
import { io, Socket } from 'socket.io-client';
|
|
|
|
|
+
|
|
|
interface ChatMessage {
|
|
interface ChatMessage {
|
|
|
content: string;
|
|
content: string;
|
|
|
sender: 'user' | 'bot';
|
|
sender: 'user' | 'bot';
|
|
@@ -16,7 +16,7 @@ interface ChatMessage {
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'app-chat',
|
|
selector: 'app-chat',
|
|
|
standalone: true,
|
|
standalone: true,
|
|
|
- imports: [CommonModule, FormsModule, HttpClientModule, MatCardModule, MatInputModule, MatButtonModule, MatListModule],
|
|
|
|
|
|
|
+ imports: [CommonModule, FormsModule, MatCardModule, MatInputModule, MatButtonModule, MatListModule],
|
|
|
templateUrl: './chat.component.html',
|
|
templateUrl: './chat.component.html',
|
|
|
styleUrls: ['./chat.component.css']
|
|
styleUrls: ['./chat.component.css']
|
|
|
})
|
|
})
|
|
@@ -25,23 +25,33 @@ export class ChatComponent {
|
|
|
inputMessage: string = '';
|
|
inputMessage: string = '';
|
|
|
loading = false;
|
|
loading = false;
|
|
|
|
|
|
|
|
- plannerOutput: any = null;
|
|
|
|
|
- executorOutput: any = null;
|
|
|
|
|
|
|
+ agentThoughts: any[] = [];
|
|
|
|
|
|
|
|
private socket: Socket;
|
|
private socket: Socket;
|
|
|
|
|
|
|
|
- constructor(private http: HttpClient) {
|
|
|
|
|
|
|
+ constructor() {
|
|
|
// Connect to FFB socket namespace
|
|
// Connect to FFB socket namespace
|
|
|
this.socket = io(`${webConfig.exposedUrl}/ffb`);
|
|
this.socket = io(`${webConfig.exposedUrl}/ffb`);
|
|
|
|
|
|
|
|
- // Listen for planner output
|
|
|
|
|
- this.socket.on('planner.output', (payload) => {
|
|
|
|
|
- this.plannerOutput = payload;
|
|
|
|
|
|
|
+ this.socket.on('connect', () => {
|
|
|
|
|
+ console.log('Connected to FFB Gateway');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ this.socket.on('disconnect', () => {
|
|
|
|
|
+ console.log('Disconnected from FFB Gateway');
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // Listen for executor events
|
|
|
|
|
- this.socket.on('executor.result', (payload) => {
|
|
|
|
|
- this.executorOutput = { ...this.executorOutput, pipeline: payload.pipeline, results: payload.results, count: payload.count };
|
|
|
|
|
|
|
+ // Listen for agent output
|
|
|
|
|
+ this.socket.on('agent_thought', (payload) => {
|
|
|
|
|
+ console.log('Received agent thought:', payload);
|
|
|
|
|
+ this.agentThoughts.push(payload);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Listen for chat response
|
|
|
|
|
+ this.socket.on('chat_response', (payload: { message: string }) => {
|
|
|
|
|
+ console.log('Received chat response:', payload);
|
|
|
|
|
+ this.messages.push({ content: payload.message, sender: 'bot' });
|
|
|
|
|
+ this.loading = false;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Optional: handle errors
|
|
// Optional: handle errors
|
|
@@ -60,17 +70,10 @@ export class ChatComponent {
|
|
|
this.inputMessage = '';
|
|
this.inputMessage = '';
|
|
|
this.loading = true;
|
|
this.loading = true;
|
|
|
|
|
|
|
|
- this.http.post<{ answer: string }>(`${webConfig.exposedUrl}/api/ffb-production/query`, { message: messageToSend })
|
|
|
|
|
- .subscribe({
|
|
|
|
|
- next: (res) => {
|
|
|
|
|
- this.messages.push({ content: res.answer, sender: 'bot' });
|
|
|
|
|
- this.loading = false;
|
|
|
|
|
- },
|
|
|
|
|
- error: (err) => {
|
|
|
|
|
- console.error(err);
|
|
|
|
|
- this.messages.push({ content: 'Error: Could not get response.', sender: 'bot' });
|
|
|
|
|
- this.loading = false;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // Clear previous agent thoughts
|
|
|
|
|
+ this.agentThoughts = [];
|
|
|
|
|
+
|
|
|
|
|
+ // Emit chat event via socket
|
|
|
|
|
+ this.socket.emit('chat', { message: messageToSend });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|