116 lines
3.9 KiB
Markdown
116 lines
3.9 KiB
Markdown
# Persona Engine Bug Fix
|
||
|
||
## Sorun Tanımı
|
||
|
||
Persona motoru aktivite sinyallerini okuyamıyordu. İki kritik bug vardı:
|
||
|
||
1. **Interface Uyumsuzluğu**: `PersonaDetectionInput` interface'inde `planned_activities` tipi `string[]` olarak tanımlanmışken, dışarıdan `{ name, type, time_block, date }` şeklinde obje array'i geçiliyordu. Bu yüzden `allInterests` içinde `[object Object]` string'leri oluşuyor ve "balloon", "wine", "drone" gibi hiçbir keyword eşleşmiyordu.
|
||
|
||
2. **Eksik time_block Alanı**: `useTripEvents.ts` dosyasında `plannedActivities` oluşturulurken `time_block` alanı eksikti, bu yüzden "dawn" (gündoğumu) gibi önemli zaman bilgileri persona motoruna iletilmiyordu.
|
||
|
||
## Uygulanan Düzeltmeler
|
||
|
||
### DEĞİŞİKLİK 1: Interface Güncellemesi (persona-engine.ts)
|
||
|
||
`src/utils/persona-engine.ts` dosyasında yeni bir `ActivityInput` interface'i eklendi ve `PersonaDetectionInput` güncellendi:
|
||
|
||
```typescript
|
||
interface ActivityInput {
|
||
name?: string;
|
||
type?: string;
|
||
time_block?: string;
|
||
[key: string]: any;
|
||
}
|
||
|
||
interface PersonaDetectionInput {
|
||
interests?: string[];
|
||
planned_activities?: string[] | ActivityInput[]; // ✅ Hem string hem obje kabul ediyor
|
||
number_of_travelers: number;
|
||
start_date: string;
|
||
end_date: string;
|
||
}
|
||
```
|
||
|
||
### DEĞİŞİKLİK 1: analyzeSignals Fonksiyonu Güncellendi
|
||
|
||
`allInterests` oluşturma bloğu yeniden yazıldı:
|
||
|
||
```typescript
|
||
// planned_activities'i normalize et: string veya obje olabilir
|
||
const activityStrings = (input.planned_activities || []).map(a => {
|
||
if (typeof a === 'string') return a.toLowerCase();
|
||
// Obje ise: name + type + time_block bilgisini birleştir
|
||
const timeBlockKeyword = a.time_block === 'dawn' ? 'sunrise dawn gündoğumu sabah' : '';
|
||
return `${a.name || ''} ${a.type || ''} ${timeBlockKeyword}`.toLowerCase();
|
||
});
|
||
|
||
const allInterests = [
|
||
...(input.interests || []).map(i => i.toLowerCase()),
|
||
...activityStrings,
|
||
];
|
||
```
|
||
|
||
### DEĞİŞİKLİK 2: time_block Alanı Eklendi (useTripEvents.ts)
|
||
|
||
`src/pages/TripPlanner/hooks/useTripEvents.ts` dosyasında iki yerde `plannedActivities` oluşturulurken `time_block` alanı eklendi:
|
||
|
||
**Konum 1: handleLeadSubmit fonksiyonu (~352. satır)**
|
||
```typescript
|
||
const plannedActivities = trip.days?.flatMap((day: any) =>
|
||
day.places?.map((place: any) => ({
|
||
name: place.name,
|
||
type: place.type,
|
||
date: day.date,
|
||
time_block: place.time_block, // ✅ Eklendi
|
||
})) || []
|
||
) || [];
|
||
```
|
||
|
||
**Konum 2: handleCreateLead fonksiyonu (~430. satır)**
|
||
```typescript
|
||
const plannedActivities = trip.days?.flatMap((day: any) =>
|
||
day.places?.map((place: any) => ({
|
||
name: place.name,
|
||
type: place.type,
|
||
date: day.date,
|
||
time_block: place.time_block, // ✅ Eklendi
|
||
})) || []
|
||
) || [];
|
||
```
|
||
|
||
## Sonuç
|
||
|
||
✅ Persona motoru artık aktivite objelerini doğru şekilde parse edebiliyor
|
||
✅ "balloon", "wine", "drone" gibi keyword'ler artık eşleşiyor
|
||
✅ `time_block === 'dawn'` durumunda "sunrise dawn gündoğumu sabah" keyword'leri ekleniyor
|
||
✅ Gündoğumu balon turları gibi özel zaman dilimli aktiviteler artık doğru algılanıyor
|
||
✅ Geriye dönük uyumluluk korundu (string array'ler de çalışıyor)
|
||
✅ Lint kontrolü başarılı
|
||
|
||
## Test Senaryosu
|
||
|
||
```typescript
|
||
// Örnek kullanım
|
||
const result = detectPersona({
|
||
number_of_travelers: 2,
|
||
interests: ['fotoğraf', 'doğa'],
|
||
planned_activities: [
|
||
{ name: 'Balon Turu', type: 'activity', time_block: 'dawn' },
|
||
{ name: 'Şarap Tadımı', type: 'wine_tasting' },
|
||
{ name: 'Drone Çekimi', type: 'photography' }
|
||
],
|
||
start_date: '2026-03-01',
|
||
end_date: '2026-03-03'
|
||
});
|
||
|
||
// Artık şu keyword'ler eşleşecek:
|
||
// - "balon turu activity sunrise dawn gündoğumu sabah"
|
||
// - "şarap tadımı wine_tasting"
|
||
// - "drone çekimi photography"
|
||
```
|
||
|
||
## Etkilenen Dosyalar
|
||
|
||
- ✅ `src/utils/persona-engine.ts` - Interface ve parsing logic güncellendi
|
||
- ✅ `src/pages/TripPlanner/hooks/useTripEvents.ts` - İki yerde `time_block` alanı eklendi (handleLeadSubmit ve handleCreateLead fonksiyonları)
|