feat(api): port Fase 5 REST API — Bun.serve router + JWT middleware + auth/session/conversation/chat handlers + composition root

This commit is contained in:
asepharyana
2026-09-02 22:50:38 +07:00
parent 1b130e69b3
commit 49e79322b4
14 changed files with 1007 additions and 0 deletions
+120
View File
@@ -0,0 +1,120 @@
/**
* Data Transfer Objects for the REST API.
* Wire format for request/response bodies — independent of domain entities.
* Mirrors `apps/interfaces/api/src/dto/*.rs`.
*/
/* -------------------------------------------------------------------------- */
/* Auth DTOs */
/* -------------------------------------------------------------------------- */
export interface LoginRequest {
username: string;
password: string;
}
export interface RegisterRequest {
username: string;
password: string;
/** Optional display name. */
display_name?: string;
}
export interface RefreshRequest {
refresh_token: string;
}
export interface AuthResponse {
access_token: string;
refresh_token: string;
token_type: string;
expires_in: number;
}
/* -------------------------------------------------------------------------- */
/* Session DTOs */
/* -------------------------------------------------------------------------- */
export interface CreateSessionRequest {
title: string;
}
export interface SessionResponse {
id: string;
created_at: number;
updated_at: number;
title: string;
model: string;
message_count: number;
archived: boolean;
summary?: string;
}
export interface SessionListResponse {
sessions: SessionResponse[];
total: number;
}
/* -------------------------------------------------------------------------- */
/* Conversation DTOs */
/* -------------------------------------------------------------------------- */
export interface AddMessageRequest {
role: string;
content: string;
}
export interface ToolFunctionResponse {
name: string;
arguments: string;
}
export interface ToolCallResponse {
id: string;
function: ToolFunctionResponse;
}
export interface MessageResponse {
role: string;
content?: string;
tool_calls?: ToolCallResponse[];
tool_call_id?: string;
}
export interface ConversationResponse {
session_id: string;
messages: MessageResponse[];
message_count: number;
model: string;
system_prompt: string;
max_tokens?: number;
temperature?: number;
}
export interface ChatCompletionRequest {
session_id: string;
message: string;
model?: string;
max_tokens?: number;
temperature?: number;
}
export interface ChatCompletionResponse {
reply: string;
prompt_tokens: number;
completion_tokens: number;
}
/* -------------------------------------------------------------------------- */
/* Error DTO */
/* -------------------------------------------------------------------------- */
export interface ErrorResponse {
message: string;
code: number;
}
/** Build a standardised error response body. */
export function errorBody(message: string, code: number): ErrorResponse {
return { message, code };
}