Files
code-center/src/routes/flowme-life/life.services.ts
abearxiong 66a19139b7 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.
2026-03-11 01:44:29 +08:00

39 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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}` };
}
}