import { getRuntimeEnv } from "./env"; import { HttpClient } from "./http"; import { SessionClient } from "./session-client"; import type { AgentId } from "./data-sources"; import { AGENT_SOURCE_REGISTRY, buildLiveSourcePlan, validateSourceRegistry } from "./data-sources"; export type PlatformRuntime = { bootedAt: string; env: ReturnType; backendStatus: "unknown" | "healthy" | "unreachable"; sessionClient: SessionClient; sourceRegistry: typeof AGENT_SOURCE_REGISTRY; sourceValidation: ReturnType; liveSourcePlans: Record>; }; export async function createPlatformRuntime(): Promise { const env = getRuntimeEnv(); const sessionClient = new SessionClient(new HttpClient(env.apiBaseUrl)); let backendStatus: PlatformRuntime["backendStatus"] = "unknown"; try { await sessionClient.health(); backendStatus = "healthy"; } catch { backendStatus = "unreachable"; } return { liveSourcePlans: Object.fromEntries( Object.keys(AGENT_SOURCE_REGISTRY).map((agentId) => [agentId, buildLiveSourcePlan(agentId as AgentId)]), ) as Record>, bootedAt: new Date().toISOString(), env, backendStatus, sessionClient, sourceRegistry: AGENT_SOURCE_REGISTRY, sourceValidation: validateSourceRegistry(), }; }