Fix production TypeScript builds and add DEPLOY.md so the app can be hosted from this repo. Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { Hono } from 'hono';
|
|
import { jsonValidator, queryValidator } from '../../shared/validation/index.js';
|
|
import { created, success } from '../../lib/response.js';
|
|
import { requireAuth } from '../../middleware/auth.js';
|
|
import {
|
|
createChatSessionSchema,
|
|
listChatSessionsQuerySchema,
|
|
sendChatMessageSchema,
|
|
} from './chat.schemas.js';
|
|
import {
|
|
createChatSession,
|
|
listChatMessages,
|
|
listChatSessions,
|
|
sendChatMessage,
|
|
startChatSession,
|
|
} from './chat.service.js';
|
|
|
|
export function createChatRoutes() {
|
|
const routes = new Hono();
|
|
|
|
routes.get('/sessions', requireAuth, queryValidator(listChatSessionsQuerySchema), async (c) => {
|
|
const authUser = c.get('authUser');
|
|
const { sessionOrder } = c.req.valid('query');
|
|
const result = await listChatSessions(authUser.id, sessionOrder);
|
|
return success(c, result);
|
|
});
|
|
|
|
routes.post('/sessions', requireAuth, jsonValidator(createChatSessionSchema), async (c) => {
|
|
const authUser = c.get('authUser');
|
|
const { sessionOrder } = c.req.valid('json');
|
|
const result = await createChatSession(authUser.id, sessionOrder);
|
|
return created(c, result);
|
|
});
|
|
|
|
routes.get('/sessions/:id/messages', requireAuth, async (c) => {
|
|
const authUser = c.get('authUser');
|
|
const result = await listChatMessages(authUser.id, BigInt(c.req.param('id')));
|
|
return success(c, result);
|
|
});
|
|
|
|
routes.post(
|
|
'/sessions/:id/messages',
|
|
requireAuth,
|
|
jsonValidator(sendChatMessageSchema),
|
|
async (c) => {
|
|
const authUser = c.get('authUser');
|
|
const { content } = c.req.valid('json');
|
|
const result = await sendChatMessage(authUser.id, BigInt(c.req.param('id')), content);
|
|
return created(c, result);
|
|
},
|
|
);
|
|
|
|
routes.post('/sessions/:id/start', requireAuth, async (c) => {
|
|
const authUser = c.get('authUser');
|
|
const result = await startChatSession(authUser.id, BigInt(c.req.param('id')));
|
|
return success(c, result);
|
|
});
|
|
|
|
return routes;
|
|
}
|