- Add agent-run module to handle AI interactions with tools and messages. - Create routes for proxying requests to OpenAI and Anthropic APIs. - Implement flowme-life chat route for user queries and task management. - Add services for retrieving and updating life records in the database. - Implement logic for fetching today's tasks and marking tasks as done with next execution time calculation. - Introduce tests for flowme-life functionalities.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import http from 'node:http';
|
|
import { router } from './router.ts';
|
|
import { handleRequest as PageProxy } from './page-proxy.ts';
|
|
|
|
import './routes/jwks.ts'
|
|
import './routes/ai/openai.ts'
|
|
|
|
const simpleAppsPrefixs = [
|
|
"/api/wxmsg",
|
|
"/api/convex/",
|
|
"/api/chat/completions"
|
|
];
|
|
|
|
|
|
export const handleRequest = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
|
if (req.url?.startsWith('/api/router')) {
|
|
// router自己管理
|
|
return;
|
|
}
|
|
// if (req.url === '/MP_verify_NGWvli5lGpEkByyt.txt') {
|
|
// res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
// res.end('NGWvli5lGpEkByyt');
|
|
// return;
|
|
// }
|
|
if (req.url && simpleAppsPrefixs.some(prefix => req.url!.startsWith(prefix))) {
|
|
// 简单应用路由处理
|
|
// 设置跨域
|
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST');
|
|
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
return router.parse(req, res);
|
|
}
|
|
// 其他请求交给页面代理处理
|
|
return PageProxy(req, res);
|
|
};
|