diff --git a/lib/4nk/models/ChatData.ts b/lib/4nk/models/ChatData.ts new file mode 100644 index 0000000..de54568 --- /dev/null +++ b/lib/4nk/models/ChatData.ts @@ -0,0 +1,92 @@ +import type { RoleDefinition } from "./Roles"; + +export interface ChatData { + type: string; + content: string; + metadata: { + createdAt: string; + lastModified: string; + sender: string; + recipient: string; + }; +} + +export function isChatData(data: any): data is ChatData { + if (typeof data !== 'object' || data === null) return false; + + // Check required fields + if (typeof data.type !== 'string' || typeof data.content !== 'string') { + return false; + } + + const validTypes = ['text']; + if (!validTypes.includes(data.type)) { + return false; + } + + // Check metadata structure + if (typeof data.metadata !== 'object' || data.metadata === null) { + return false; + } + + const requiredMetadataFields = ['createdAt', 'lastModified', 'sender', 'recipient']; + for (const field of requiredMetadataFields) { + if (typeof data.metadata[field] !== 'string') { + return false; + } + } + + return true; +} + +const emptyChatData: ChatData = { + type: '', + content: '', + metadata: { + createdAt: '', + lastModified: '', + sender: '', + recipient: '', + } +}; + +const chatDataFields: string[] = Object.keys(emptyChatData); + +const ChatPublicFields: string[] = []; + +// Messages and metadata are private by default +export const ChatPrivateFields = [ + ...chatDataFields.filter(key => !ChatPublicFields.includes(key)) +]; + +export interface ChatCreated { + processId: string, + process: any, // Process + data: ChatData, +} + +export function setDefaultChatRoles(ownerId: string, recipientId: string): Record { + return { + demiurge: { + members: [ownerId, recipientId], + validation_rules: [], + storages: [] + }, + owner: { + members: [ownerId, recipientId], + validation_rules: [ + { + quorum: 0.5, + fields: [...chatDataFields, 'roles'], + min_sig_member: 1, + }, + ], + storages: [] + }, + apophis: { + members: [ownerId, recipientId], + validation_rules: [], + storages: [] + } + } +};