headplane/app/routes/settings/local-agent.tsx

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-01-18 07:37:03 +00:00
import { useMemo } from 'react';
2025-02-19 18:09:42 -05:00
import { type LoaderFunctionArgs, useLoaderData } from 'react-router';
import { commitSession, getSession } from '~/utils/sessions.server';
import { queryAgent } from '~/utils/ws-agent';
import AgentManagement from './components/agent/manage';
2025-01-18 07:37:03 +00:00
export async function loader({ request, context }: LoaderFunctionArgs) {
const { ws, wsAuthKey } = context;
const session = await getSession(request.headers.get('Cookie'));
const onboarding = session.get('agent_onboarding') ?? false;
2025-02-19 18:09:42 -05:00
const nodeKey =
'nodekey:542dad28354eb8d51e240aada7adf0222ba3ecc74af0bbd56123f03eefdb391b';
2025-01-18 07:37:03 +00:00
const stats = await queryAgent([nodeKey]);
return {
configured: wsAuthKey !== undefined,
onboarding,
2025-02-19 18:09:42 -05:00
stats: stats?.[nodeKey],
};
2025-01-18 07:37:03 +00:00
}
export default function Page() {
const data = useLoaderData<typeof loader>();
// Whether we show the onboarding or management UI
const management = useMemo(() => {
2025-02-19 18:09:42 -05:00
return data.configured && data.onboarding === false;
2025-01-18 07:37:03 +00:00
}, [data.configured, data.onboarding]);
return (
2025-05-29 09:45:47 -04:00
<div className="flex flex-col gap-8 max-w-(--breakpoint-lg)">
2025-01-18 07:37:03 +00:00
{management ? (
2025-02-19 18:09:42 -05:00
<AgentManagement reachable={true} hostInfo={data.stats} />
2025-01-18 07:37:03 +00:00
) : (
2025-02-19 18:09:42 -05:00
<div>
<h1>Local Agent Coming Soon</h1>
</div>
2025-01-18 07:37:03 +00:00
)}
</div>
2025-02-19 18:09:42 -05:00
);
2025-01-18 07:37:03 +00:00
}