File size: 7,043 Bytes
8f9c4ef | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// @codesync/shared β Shared types and constants
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// User colors for cursor presence
export const USER_COLORS = [
'#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4',
'#FFEAA7', '#DDA0DD', '#98D8C8', '#F7DC6F',
'#BB8FCE', '#85C1E9', '#F8C471', '#82E0AA',
] as const;
// Rate limiting configuration
export const RATE_LIMITS = {
AUTH: { windowMs: 15 * 60 * 1000, max: 10 },
API: { windowMs: 60 * 1000, max: 100 },
EXECUTION: { windowMs: 60 * 1000, max: 10 },
AI: { windowMs: 60 * 1000, max: 20 },
WEBSOCKET: { windowMs: 1000, max: 50 },
} as const;
// Room constraints
export const ROOM_LIMITS = {
MAX_MEMBERS: 10,
MAX_FILES: 20,
MAX_FILE_SIZE: 1024 * 1024,
MAX_MESSAGE_LENGTH: 4096,
MAX_ROOM_NAME_LENGTH: 64,
INVITE_CODE_LENGTH: 8,
} as const;
// Execution constraints
export const EXECUTION_LIMITS = {
MAX_CODE_SIZE: 64 * 1024,
MAX_TIMEOUT: 30000,
DEFAULT_TIMEOUT: 10000,
MAX_OUTPUT_SIZE: 1024 * 1024,
MAX_CONCURRENT: 5,
} as const;
// Language configurations
export const LANGUAGE_CONFIG = {
javascript: {
name: 'JavaScript', extension: '.js', monacoId: 'javascript',
dockerImage: 'codesync-sandbox-js', runCommand: 'node',
timeout: 10000, memoryLimit: '128m',
},
typescript: {
name: 'TypeScript', extension: '.ts', monacoId: 'typescript',
dockerImage: 'codesync-sandbox-js', runCommand: 'npx tsx',
timeout: 15000, memoryLimit: '128m',
},
python: {
name: 'Python', extension: '.py', monacoId: 'python',
dockerImage: 'codesync-sandbox-python', runCommand: 'python3',
timeout: 10000, memoryLimit: '128m',
},
cpp: {
name: 'C++', extension: '.cpp', monacoId: 'cpp',
dockerImage: 'codesync-sandbox-cpp', runCommand: 'g++',
timeout: 15000, memoryLimit: '256m',
},
java: {
name: 'Java', extension: '.java', monacoId: 'java',
dockerImage: 'codesync-sandbox-java', runCommand: 'javac',
timeout: 20000, memoryLimit: '256m',
},
} as const;
// βββ Shared Types ββββββββββββββββββββββββββββββββββββββββββββ
export interface User {
id: string;
email: string;
name: string;
avatar: string | null;
provider: string;
createdAt: string;
}
export interface AuthTokens {
accessToken: string;
refreshToken: string;
}
export interface Room {
id: string;
name: string;
ownerId: string;
language: string;
isPublic: boolean;
inviteCode: string;
maxMembers: number;
createdAt: string;
updatedAt: string;
}
export interface RoomMember {
userId: string;
roomId: string;
role: string;
joinedAt: string;
lastActive: string;
user: User;
}
export interface RoomFile {
id: string;
roomId: string;
name: string;
path: string;
content: string;
language: string;
createdAt: string;
updatedAt: string;
}
export type ProgrammingLanguage = 'javascript' | 'typescript' | 'python' | 'cpp' | 'java';
export type RoomRole = 'owner' | 'editor' | 'viewer';
export type MessageType = 'text' | 'code' | 'file' | 'system';
export type AIAction = 'explain' | 'fix' | 'optimize' | 'comment' | 'debug';
export interface ChatMessage {
id: string;
content: string;
userId: string;
userName: string;
userAvatar: string | null;
roomId: string;
type: MessageType;
metadata?: any;
createdAt: string;
}
export interface UserCursor {
userId: string;
userName: string;
userColor: string;
position: { lineNumber: number; column: number };
selection?: {
startLineNumber: number;
startColumn: number;
endLineNumber: number;
endColumn: number;
};
}
export interface UserPresence {
userId: string;
userName: string;
userColor: string;
isOnline: boolean;
lastSeen: string;
isTyping: boolean;
}
export interface ExecutionRequest {
code: string;
language: ProgrammingLanguage;
stdin?: string;
timeout?: number;
}
export interface ExecutionResult {
id: string;
stdout: string;
stderr: string;
exitCode: number;
duration: number;
memoryUsed: number;
timedOut: boolean;
}
export interface CreateRoomPayload {
name: string;
language: ProgrammingLanguage;
isPublic: boolean;
maxMembers?: number;
}
export interface AIRequest {
action: AIAction;
code: string;
language: ProgrammingLanguage;
prompt?: string;
error?: string;
}
export interface AIResponse {
content: string;
suggestions?: Array<{ description: string; code: string }>;
}
export interface AIMessage {
id: string;
role: 'user' | 'assistant';
content: string;
timestamp: string;
}
export interface WebRTCSignal {
type: 'offer' | 'answer' | 'ice-candidate';
from: string;
to: string;
payload: any;
}
export interface PeerConnection {
peerId: string;
peerName: string;
isAudioEnabled: boolean;
isVideoEnabled: boolean;
isScreenSharing: boolean;
}
export interface DashboardStats {
totalRooms: number;
totalExecutions: number;
totalCollaborationTime: number;
recentActivity: any[];
}
export interface Snippet {
id: string;
userId: string;
title: string;
code: string;
language: string;
description?: string;
isPublic: boolean;
createdAt: string;
updatedAt: string;
}
// Socket event interfaces
export interface ServerToClientEvents {
'room:joined': (data: any) => void;
'room:member-joined': (data: any) => void;
'room:member-left': (data: any) => void;
'doc:sync': (data: any) => void;
'doc:state': (data: any) => void;
'presence:update': (data: any) => void;
'cursor:update': (data: any) => void;
'chat:message': (data: any) => void;
'chat:typing': (data: any) => void;
'chat:history': (data: any) => void;
'exec:output': (data: any) => void;
'exec:complete': (data: any) => void;
'exec:error': (data: any) => void;
'webrtc:offer': (data: any) => void;
'webrtc:answer': (data: any) => void;
'webrtc:ice-candidate': (data: any) => void;
'webrtc:peer-joined': (data: any) => void;
'webrtc:peer-left': (data: any) => void;
'error': (data: any) => void;
}
export interface ClientToServerEvents {
'room:join': (data: any) => void;
'room:leave': (data: any) => void;
'doc:update': (data: any) => void;
'doc:request-state': (data: any) => void;
'presence:update': (data: any) => void;
'cursor:move': (data: any) => void;
'chat:send': (data: any) => void;
'chat:typing': (data: any) => void;
'chat:history': (data: any) => void;
'exec:run': (data: any) => void;
'exec:kill': (data: any) => void;
'webrtc:join': () => void;
'webrtc:leave': () => void;
'webrtc:offer': (data: any) => void;
'webrtc:answer': (data: any) => void;
'webrtc:ice-candidate': (data: any) => void;
}
|