mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
- Remove nested git repository from bugulma/frontend/.git - Add all frontend files to main repository tracking - Convert from separate frontend/backend repos to unified monorepo - Preserve all frontend code and development history as tracked files - Eliminate nested repository complexity for simpler development workflow This creates a proper monorepo structure with frontend and backend coexisting in the same repository for easier development and deployment.
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { z } from 'zod';
|
|
import { httpClient } from '@/lib/http-client';
|
|
import { validateDataStrict } from '@/lib/schema-validation';
|
|
import { reportError } from '@/lib/error-handling';
|
|
|
|
export interface SendMessageRequest {
|
|
message: string;
|
|
system_instruction?: string;
|
|
}
|
|
|
|
export interface SendMessageResponse {
|
|
response: string;
|
|
}
|
|
|
|
// Zod schemas for validation
|
|
const sendMessageRequestSchema = z.object({
|
|
message: z.string().min(1, 'Message cannot be empty'),
|
|
system_instruction: z.string().optional(),
|
|
});
|
|
|
|
const sendMessageResponseSchema = z.object({
|
|
response: z.string(),
|
|
});
|
|
|
|
/**
|
|
* Send a chat message (non-streaming) with enhanced error handling and validation
|
|
*/
|
|
export async function sendChatMessage(request: SendMessageRequest): Promise<string> {
|
|
try {
|
|
// Validate request
|
|
const validatedRequest = validateDataStrict(sendMessageRequestSchema, request, 'sendChatMessage request');
|
|
|
|
// Make API call
|
|
const response = await httpClient.post('/ai/chat', validatedRequest, {
|
|
timeout: 30000, // 30 seconds for chat
|
|
retries: 2,
|
|
});
|
|
|
|
// Validate response
|
|
const validatedResponse = validateDataStrict(sendMessageResponseSchema, response, 'sendChatMessage response');
|
|
|
|
return validatedResponse.response;
|
|
} catch (error) {
|
|
const appError = reportError(error, {
|
|
operation: 'sendChatMessage',
|
|
request: { messageLength: request.message?.length, hasSystemInstruction: !!request.system_instruction },
|
|
});
|
|
throw appError;
|
|
}
|
|
}
|
|
|