feat: implement AI agent for flowme-life interactions

- 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.
This commit is contained in:
2026-03-11 01:44:29 +08:00
parent 027cbecab6
commit 66a19139b7
22 changed files with 5190 additions and 676 deletions

View File

@@ -0,0 +1,44 @@
import { schema, app, cnb, models } from '@/app.ts'
import z from 'zod';
import { runAgent } from '@kevisual/ai/agent'
app.route({
path: 'flowme-life',
key: 'chat',
description: `聊天接口, 对自己的数据进行操作,参数是 question或messagesquestion是用户的提问messages是对话消息列表优先级高于 question`,
middleware: ['auth']
, metadata: {
args: {
question: z.string().describe('用户的提问'),
messages: z.any().optional().describe('对话消息列表,优先级高于 question'),
}
}
}).define(async (ctx) => {
const question = ctx.query.question || '';
const _messages = ctx.query.messages;
const token = ctx.query.token || '';
if (!question && !_messages) {
ctx.throw(400, '缺少参数 question 或 messages');
}
const routes = ctx.app.getList().filter(r => r.path.startsWith('flowme-life') && r.key !== 'chat');
const messages = _messages || [
{
"role": "system" as const,
"content": `你是我的智能助手,协助我操作我的数据, 请根据我的提问选择合适的接口进行调用。`
},
{
"role": "user" as const,
"content": question
}
]
const res = await runAgent({
app: app,
messages: messages,
languageModel: cnb(models['auto']),
// query: 'WHERE path LIKE 'flowme-life%',
routes,
token,
});
ctx.body = res
}).addTo(app);