headplane/server/context/app.ts

23 lines
638 B
TypeScript
Raw Normal View History

import type { HostInfo } from '~/types';
import { TimedCache } from '~server/ws/cache';
import { hp_agentRequest, hp_getAgentCache } from '~server/ws/data';
2025-03-06 17:37:41 -05:00
import { hp_getAgents } from '~server/ws/socket';
2025-02-19 18:09:42 -05:00
import { hp_getConfig } from './loader';
import type { HeadplaneConfig } from './parser';
2025-02-19 18:09:42 -05:00
export interface AppContext {
context: HeadplaneConfig;
hp_agentRequest: typeof hp_agentRequest;
2025-03-06 17:37:41 -05:00
agents: string[];
agentData?: TimedCache<HostInfo>;
2025-02-19 18:09:42 -05:00
}
2025-03-06 17:37:41 -05:00
export default function appContext(): AppContext {
2025-02-19 18:09:42 -05:00
return {
context: hp_getConfig(),
hp_agentRequest,
2025-03-06 17:37:41 -05:00
agents: [...hp_getAgents().keys()],
agentData: hp_getAgentCache(),
2025-02-19 18:09:42 -05:00
};
}