mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
18 lines
660 B
TypeScript
18 lines
660 B
TypeScript
"use server";
|
|
|
|
import { userAction } from "@/lib/safe-actions/actions";
|
|
import { z } from "zod";
|
|
import { getAgentAction } from "@/features/agents/agents.action";
|
|
|
|
export const getAgentStatusAction = userAction
|
|
.schema(z.object({ agentId: z.string() }))
|
|
.action(async ({ parsedInput }) => {
|
|
const result = await getAgentAction(parsedInput.agentId);
|
|
if (!result?.data?.data) return { connected: false };
|
|
const agent = result.data.data;
|
|
const lastContact = agent.lastContact ? new Date(agent.lastContact) : null;
|
|
const connected =
|
|
lastContact !== null && Date.now() - lastContact.getTime() < 60_000;
|
|
return { connected };
|
|
});
|