Skip to main content

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 - Updated TotoConversation interface and transformConversationDoc
    • toto-docs/app/docs/architecture/conversation-base-model.ts - Base model uses isArchived

✅ 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 to TotoConversation interface, transformConversationDoc, and saveConversation
    • toto-docs/app/docs/architecture/conversation-base-model.ts - Added to BaseConversation

✅ 3. Standardized Timestamps to ISO 8601 Strings

  • Before: Mixed types (Date objects, Firestore Timestamp, ISO strings)
  • After: All timestamps are string (ISO 8601) in model, converted to Firestore Timestamp only for storage
  • Files Updated:
    • toto-app/src/services/conversationService.ts - Updated TotoMessage.timestamp to string, updated conversion logic
    • toto-app/src/components/cases/CaseChatModal.tsx - Updated timestamp conversion

✅ 4. Added actionTaken to Base Model

  • Added: actionTaken?: string to track what user did (donate, share, etc.)
  • Files Updated:
    • toto-app/src/services/conversationService.ts - Added to TotoConversation interface (optional), made optional in ConversationData
    • toto-docs/app/docs/architecture/conversation-base-model.ts - Added to BaseConversation

✅ 5. Removed platform from Messages

  • Before: platform field at both conversation and message level
  • After: platform only at conversation level (array)
  • Files Updated:
    • toto-app/src/services/conversationService.ts - Removed from TotoMessage, removed from message creation/merging logic
    • toto-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 - Added generateMessageId() function, always generate IDs in saveConversation and transformConversationDoc

Files Modified

  1. toto-docs/app/docs/architecture/conversation-base-model.ts (NEW)

    • Created base conversation model as single source of truth
    • Defined BaseConversation, BaseMessage, TotoConversation, ConversationData
  2. toto-app/src/services/conversationService.ts

    • Updated TotoMessage interface: removed platform, changed timestamp to string
    • Updated TotoConversation interface: added updatedAt, actionTaken, changed isActive to isArchived
    • Updated ConversationData interface: made actionTaken optional, added platform at conversation level
    • Updated transformConversationDoc: use isArchived, add updatedAt, remove platform from messages, ensure message IDs
    • Updated saveConversation: always generate message IDs, add updatedAt, remove platform from messages
  3. toto-app/src/components/cases/CaseChatModal.tsx

    • Removed platform references when mapping messages
    • Updated timestamp conversion (ISO string to Date)

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:

  1. isActiveisArchived: Any code using conversation.isActive needs to use !conversation.isArchived or update to use isArchived directly
  2. Message platform removed: Any code accessing message.platform needs to use conversation.platform instead
  3. Message timestamp type: Changed from Date to string (ISO 8601), may need conversion in some places
  4. updatedAt added: New required field, existing conversations will need migration

Migration Notes

When migrating existing conversations:

  1. Set isArchived: false if isActive was true (or vice versa)
  2. Add updatedAt field (set to createdAt if not available)
  3. Remove platform from message objects
  4. Ensure all messages have IDs (generate if missing)
  5. 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