import {
  AiChatConversationAccessError,
  AiChatConversationDuplicateParticipantError,
  AiChatConversationOrgNotFoundError,
  AiChatParticipantNotFoundError,
  AiChatConversationRepository
} from "../data/repositories/AiChatConversationRepository.js";
function createConversationStorage(container) {
  const em = container.resolve("em");
  return new AiChatConversationRepository(em);
}
function serializeAiChatConversation(row, enrich = {}) {
  return {
    conversationId: row.conversationId,
    agentId: row.agentId,
    title: row.title ?? null,
    status: row.status,
    visibility: row.visibility,
    pageContext: row.pageContext ?? null,
    createdAt: row.createdAt.toISOString(),
    updatedAt: row.updatedAt.toISOString(),
    lastMessageAt: row.lastMessageAt ? row.lastMessageAt.toISOString() : null,
    importedFromLocalAt: row.importedFromLocalAt ? row.importedFromLocalAt.toISOString() : null,
    participantCount: enrich.participantCount ?? 0,
    isOwner: enrich.callerUserId != null ? row.ownerUserId === enrich.callerUserId : null
  };
}
function serializeAiChatMessage(row) {
  return {
    id: row.id,
    clientMessageId: row.clientMessageId ?? null,
    role: row.role,
    content: row.content,
    uiParts: Array.isArray(row.uiParts) ? row.uiParts : [],
    attachmentIds: Array.isArray(row.attachmentIds) ? row.attachmentIds : [],
    files: Array.isArray(row.filesMetadata) ? row.filesMetadata : [],
    model: row.model ?? null,
    metadata: row.metadata ?? null,
    createdAt: row.createdAt.toISOString(),
    senderUserId: row.createdByUserId ?? null
  };
}
export {
  AiChatConversationAccessError,
  AiChatConversationDuplicateParticipantError,
  AiChatConversationOrgNotFoundError,
  AiChatParticipantNotFoundError,
  createConversationStorage,
  serializeAiChatConversation,
  serializeAiChatMessage
};
//# sourceMappingURL=conversation-storage.js.map
