Conversation Model - Implementation Summary
Changes Implemented
✅ 1. Use isArchived instead of isActive
- Before:
isActive: boolean(derived from!isArchived) - After:
isArchived: boolean(direct field) - Files Updated:
toto-app/src/services/conversationService.ts- UpdatedTotoConversationinterface andtransformConversationDoctoto-docs/app/docs/architecture/conversation-base-model.ts- Base model usesisArchived
✅ 2. Added updatedAt Field
- Added:
updatedAt: string(ISO 8601) to track when conversation metadata was last updated - Files Updated:
toto-app/src/services/conversationService.ts- Added toTotoConversationinterface,transformConversationDoc, andsaveConversationtoto-docs/app/docs/architecture/conversation-base-model.ts- Added toBaseConversation
✅ 3. Standardized Timestamps to ISO 8601 Strings
- Before: Mixed types (
Dateobjects, FirestoreTimestamp, ISO strings) - After: All timestamps are
string(ISO 8601) in model, converted to FirestoreTimestamponly for storage - Files Updated:
toto-app/src/services/conversationService.ts- UpdatedTotoMessage.timestamptostring, updated conversion logictoto-app/src/components/cases/CaseChatModal.tsx- Updated timestamp conversion
✅ 4. Added actionTaken to Base Model
- Added:
actionTaken?: stringto track what user did (donate, share, etc.) - Files Updated:
toto-app/src/services/conversationService.ts- Added toTotoConversationinterface (optional), made optional inConversationDatatoto-docs/app/docs/architecture/conversation-base-model.ts- Added toBaseConversation
✅ 5. Removed platform from Messages
- Before:
platformfield at both conversation and message level - After:
platformonly at conversation level (array) - Files Updated:
toto-app/src/services/conversationService.ts- Removed fromTotoMessage, removed from message creation/merging logictoto-app/src/components/cases/CaseChatModal.tsx- Removed platform references when mapping messages
✅ 6. Always Generate Message IDs
- Before: Message ID optional, auto-generated inconsistently
- After: Message ID always generated if missing, consistent generation function
- Files Updated:
toto-app/src/services/conversationService.ts- AddedgenerateMessageId()function, always generate IDs insaveConversationandtransformConversationDoc
Files Modified
-
toto-docs/app/docs/architecture/conversation-base-model.ts(NEW)- Created base conversation model as single source of truth
- Defined
BaseConversation,BaseMessage,TotoConversation,ConversationData
-
toto-app/src/services/conversationService.ts- Updated
TotoMessageinterface: removedplatform, changedtimestamptostring - Updated
TotoConversationinterface: addedupdatedAt,actionTaken, changedisActivetoisArchived - Updated
ConversationDatainterface: madeactionTakenoptional, addedplatformat conversation level - Updated
transformConversationDoc: useisArchived, addupdatedAt, removeplatformfrom messages, ensure message IDs - Updated
saveConversation: always generate message IDs, addupdatedAt, removeplatformfrom messages
- Updated
-
toto-app/src/components/cases/CaseChatModal.tsx- Removed
platformreferences when mapping messages - Updated timestamp conversion (ISO string to Date)
- Removed
Model Structure
BaseConversation
{
id: string;
userId: string;
caseId: string;
caseName: string;
caseImageUrl?: string;
messages: BaseMessage[];
platform?: string[];
isArchived: boolean;
actionTaken?: string;
createdAt: string;
lastMessageAt: string;
updatedAt: string;
}
BaseMessage
{
id: string; // Always required
type: 'user' | 'system';
message: string;
timestamp: string; // ISO 8601
metadata?: {
actionTaken?: string;
agentType?: string;
intent?: string;
[key: string]: any;
};
}
Breaking Changes
⚠️ Note: These changes may require updates in other parts of the codebase:
isActive→isArchived: Any code usingconversation.isActiveneeds to use!conversation.isArchivedor update to useisArchiveddirectly- Message
platformremoved: Any code accessingmessage.platformneeds to useconversation.platforminstead - Message
timestamptype: Changed fromDatetostring(ISO 8601), may need conversion in some places updatedAtadded: New required field, existing conversations will need migration
Migration Notes
When migrating existing conversations:
- Set
isArchived: falseifisActivewastrue(or vice versa) - Add
updatedAtfield (set tocreatedAtif not available) - Remove
platformfrom message objects - Ensure all messages have IDs (generate if missing)
- Convert message timestamps to ISO 8601 strings if stored as Date/Timestamp
Next Steps
- Update any remaining code that uses
isActive(check legacy code) - Create migration script for existing conversations
- Update AI Hub conversation interfaces if needed
- Update backoffice conversation interfaces if needed
- Test conversation creation, reading, and updating