Spaces:
Building
Building
Update flare-ui/src/app/components/chat/chat.component.ts
Browse files
flare-ui/src/app/components/chat/chat.component.ts
CHANGED
@@ -30,55 +30,55 @@ interface ChatMessage {
|
|
30 |
templateUrl: './chat.component.html',
|
31 |
styleUrls: ['./chat.component.scss']
|
32 |
})
|
33 |
-
export class ChatComponent implements OnDestroy {
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
|
38 |
messages: ChatMessage[] = [];
|
39 |
-
|
40 |
-
/** Kullanıcı metni */
|
41 |
input = this.fb.control('', Validators.required);
|
42 |
-
|
43 |
-
/** Arkaplan istekleri için abonelikleri tutuyoruz */
|
44 |
private subs = new Subscription();
|
45 |
|
46 |
constructor(private fb: FormBuilder, private api: ApiService) {}
|
47 |
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
startChat(): void {
|
50 |
-
|
51 |
-
|
|
|
52 |
this.sessionId = res.session_id;
|
|
|
53 |
},
|
54 |
-
error: () =>
|
55 |
-
alert('Chat başlatılamadı - tekrar deneyin.');
|
56 |
-
}
|
57 |
});
|
58 |
this.subs.add(sub);
|
59 |
}
|
60 |
|
61 |
-
/**
|
62 |
send(): void {
|
63 |
if (!this.sessionId || this.input.invalid) return;
|
64 |
-
|
65 |
const text = this.input.value!.trim();
|
66 |
if (!text) return;
|
67 |
|
68 |
-
// Önce kullanıcı mesajını ekranda göster
|
69 |
this.messages.push({ author: 'user', text });
|
70 |
this.input.reset();
|
71 |
|
72 |
const sub = this.api.chat(this.sessionId, text).subscribe({
|
73 |
-
next: (
|
74 |
-
|
75 |
-
},
|
76 |
-
error: () => {
|
77 |
this.messages.push({
|
78 |
author: 'assistant',
|
79 |
-
text: '
|
80 |
-
})
|
81 |
-
}
|
82 |
});
|
83 |
this.subs.add(sub);
|
84 |
}
|
|
|
30 |
templateUrl: './chat.component.html',
|
31 |
styleUrls: ['./chat.component.scss']
|
32 |
})
|
33 |
+
export class ChatComponent implements OnInit, OnDestroy {
|
34 |
+
projects: string[] = [];
|
35 |
+
selectedProject!: string | null;
|
36 |
|
37 |
+
sessionId: string | null = null;
|
38 |
messages: ChatMessage[] = [];
|
|
|
|
|
39 |
input = this.fb.control('', Validators.required);
|
|
|
|
|
40 |
private subs = new Subscription();
|
41 |
|
42 |
constructor(private fb: FormBuilder, private api: ApiService) {}
|
43 |
|
44 |
+
ngOnInit(): void {
|
45 |
+
/* Proje isimlerini çek → comboya doldur */
|
46 |
+
const sub = this.api.getChatProjects().subscribe({
|
47 |
+
next: p => (this.projects = p),
|
48 |
+
error: () => alert('Projeler yüklenemedi')
|
49 |
+
});
|
50 |
+
this.subs.add(sub);
|
51 |
+
}
|
52 |
+
|
53 |
+
/** Start Chat → /start_session */
|
54 |
startChat(): void {
|
55 |
+
if (!this.selectedProject) return;
|
56 |
+
const sub = this.api.startChat(this.selectedProject).subscribe({
|
57 |
+
next: res => {
|
58 |
this.sessionId = res.session_id;
|
59 |
+
this.messages = [{ author: 'assistant', text: res.answer }];
|
60 |
},
|
61 |
+
error: () => alert('Oturum açılamadı')
|
|
|
|
|
62 |
});
|
63 |
this.subs.add(sub);
|
64 |
}
|
65 |
|
66 |
+
/** Send → /chat */
|
67 |
send(): void {
|
68 |
if (!this.sessionId || this.input.invalid) return;
|
|
|
69 |
const text = this.input.value!.trim();
|
70 |
if (!text) return;
|
71 |
|
|
|
72 |
this.messages.push({ author: 'user', text });
|
73 |
this.input.reset();
|
74 |
|
75 |
const sub = this.api.chat(this.sessionId, text).subscribe({
|
76 |
+
next: res => this.messages.push({ author: 'assistant', text: res.answer }),
|
77 |
+
error: () =>
|
|
|
|
|
78 |
this.messages.push({
|
79 |
author: 'assistant',
|
80 |
+
text: '⚠️ Mesaj iletilemedi, tekrar deneyin.'
|
81 |
+
})
|
|
|
82 |
});
|
83 |
this.subs.add(sub);
|
84 |
}
|