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:
38
src/routes/flowme-life/life.services.ts
Normal file
38
src/routes/flowme-life/life.services.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { schema, db } from '@/app.ts';
|
||||
|
||||
export type LifeItem = typeof schema.life.$inferSelect;
|
||||
|
||||
/**
|
||||
* 根据 id 获取 life 记录
|
||||
*/
|
||||
export async function getLifeItem(id: string): Promise<{ code: number; data?: LifeItem; message?: string }> {
|
||||
try {
|
||||
const result = await db.select().from(schema.life).where(eq(schema.life.id, id)).limit(1);
|
||||
if (result.length === 0) {
|
||||
return { code: 404, message: `记录 ${id} 不存在` };
|
||||
}
|
||||
return { code: 200, data: result[0] };
|
||||
} catch (e) {
|
||||
return { code: 500, message: `获取记录 ${id} 失败: ${e?.message || e}` };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新 life 记录的 effectiveAt(下次执行时间)
|
||||
*/
|
||||
export async function updateLifeEffectiveAt(id: string, effectiveAt: string | Date): Promise<{ code: number; data?: LifeItem; message?: string }> {
|
||||
try {
|
||||
const result = await db
|
||||
.update(schema.life)
|
||||
.set({ effectiveAt: new Date(effectiveAt) })
|
||||
.where(eq(schema.life.id, id))
|
||||
.returning();
|
||||
if (result.length === 0) {
|
||||
return { code: 404, message: `记录 ${id} 不存在` };
|
||||
}
|
||||
return { code: 200, data: result[0] };
|
||||
} catch (e) {
|
||||
return { code: 500, message: `更新记录 ${id} 失败: ${e?.message || e}` };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user