feat: add initial backend and frontend structure with models, DTOs, and WebSocket events
This commit is contained in:
86
packages/shared/src/api/dto.ts
Normal file
86
packages/shared/src/api/dto.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Shared API DTOs
|
||||
* Used by backend for validation and frontend for type safety
|
||||
*/
|
||||
|
||||
// Character DTOs
|
||||
export interface CreateCharacterDto {
|
||||
name: string;
|
||||
personalityPrompt: string;
|
||||
backstory?: string;
|
||||
attributes?: Record<string, unknown>;
|
||||
avatarUrl?: string;
|
||||
config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface UpdateCharacterDto extends Partial<CreateCharacterDto> {}
|
||||
|
||||
export interface CharacterResponseDto {
|
||||
id: string;
|
||||
name: string;
|
||||
avatarUrl?: string;
|
||||
personalityPrompt: string;
|
||||
backstory?: string;
|
||||
attributes: Record<string, unknown>;
|
||||
config: Record<string, unknown>;
|
||||
isPublic: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
// Conversation DTOs
|
||||
export interface CreateConversationDto {
|
||||
characterId: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
export interface ConversationResponseDto {
|
||||
id: string;
|
||||
title?: string;
|
||||
characterId: string;
|
||||
messageCount: number;
|
||||
totalTokens: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
// Message DTOs
|
||||
export interface CreateMessageDto {
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface MessageResponseDto {
|
||||
id: string;
|
||||
role: 'user' | 'assistant' | 'system';
|
||||
content: string;
|
||||
tokensUsed?: number;
|
||||
model?: string;
|
||||
metadata?: Record<string, unknown>;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
// Auth DTOs
|
||||
export interface LoginDto {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface RegisterDto {
|
||||
email: string;
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface AuthResponseDto {
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
expiresIn: number;
|
||||
user: UserResponseDto;
|
||||
}
|
||||
|
||||
export interface UserResponseDto {
|
||||
id: string;
|
||||
email: string;
|
||||
username: string;
|
||||
role: 'USER' | 'ADMIN';
|
||||
}
|
||||
1
packages/shared/src/api/index.ts
Normal file
1
packages/shared/src/api/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './dto.js';
|
||||
2
packages/shared/src/index.ts
Normal file
2
packages/shared/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './websocket/index.js';
|
||||
export * from './api/index.js';
|
||||
84
packages/shared/src/websocket/events.ts
Normal file
84
packages/shared/src/websocket/events.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* WebSocket Event Types
|
||||
* Shared between frontend and backend for type-safe communication
|
||||
*/
|
||||
|
||||
export enum WebSocketEventType {
|
||||
// Client -> Server
|
||||
JOIN_CONVERSATION = 'JOIN_CONVERSATION',
|
||||
LEAVE_CONVERSATION = 'LEAVE_CONVERSATION',
|
||||
SEND_MESSAGE = 'SEND_MESSAGE',
|
||||
STOP_GENERATION = 'STOP_GENERATION',
|
||||
|
||||
// Server -> Client
|
||||
CONVERSATION_JOINED = 'CONVERSATION_JOINED',
|
||||
MESSAGE_ACK = 'MESSAGE_ACK',
|
||||
STREAM_CHUNK = 'STREAM_CHUNK',
|
||||
STREAM_COMPLETE = 'STREAM_COMPLETE',
|
||||
ERROR = 'ERROR',
|
||||
}
|
||||
|
||||
// Base message interface
|
||||
export interface WebSocketMessage<T = unknown> {
|
||||
type: WebSocketEventType;
|
||||
payload: T;
|
||||
timestamp: string;
|
||||
requestId?: string;
|
||||
}
|
||||
|
||||
// Client -> Server payloads
|
||||
export interface JoinConversationPayload {
|
||||
conversationId: string;
|
||||
}
|
||||
|
||||
export interface LeaveConversationPayload {
|
||||
conversationId: string;
|
||||
}
|
||||
|
||||
export interface SendMessagePayload {
|
||||
conversationId: string;
|
||||
content: string;
|
||||
streaming?: boolean;
|
||||
}
|
||||
|
||||
export interface StopGenerationPayload {
|
||||
conversationId: string;
|
||||
}
|
||||
|
||||
// Server -> Client payloads
|
||||
export interface ConversationJoinedPayload {
|
||||
conversationId: string;
|
||||
history: MessageHistoryItem[];
|
||||
}
|
||||
|
||||
export interface MessageHistoryItem {
|
||||
id: string;
|
||||
role: 'user' | 'assistant' | 'system';
|
||||
content: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface MessageAckPayload {
|
||||
messageId: string;
|
||||
status: 'received' | 'processing' | 'error';
|
||||
}
|
||||
|
||||
export interface StreamChunkPayload {
|
||||
conversationId: string;
|
||||
chunk: string;
|
||||
isComplete: boolean;
|
||||
}
|
||||
|
||||
export interface StreamCompletePayload {
|
||||
conversationId: string;
|
||||
messageId: string;
|
||||
content: string;
|
||||
tokensUsed?: number;
|
||||
model?: string;
|
||||
}
|
||||
|
||||
export interface ErrorPayload {
|
||||
code: string;
|
||||
message: string;
|
||||
details?: Record<string, unknown>;
|
||||
}
|
||||
1
packages/shared/src/websocket/index.ts
Normal file
1
packages/shared/src/websocket/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './events.js';
|
||||
Reference in New Issue
Block a user