// Arcadia LLM-gateway client. // // The integration registry lives on arcadia-llm-gateway, not arcadia-app, so // it needs its own ArcadiaClient pointed at a different base URL. Everything // else is identical to the arcadia-app client: the same access token (the // gateway validates arcadia-app JWTs via the shared Guardian secret) and the // same 401 cleanup. The gateway's CORS already allows localhost + any // *.sky-ai.com origin, so the browser calls it directly. import { createArcadiaClient, type ArcadiaClient } from "@crema/arcadia-client" const GATEWAY_URL = import.meta.env.VITE_LLM_GATEWAY_URL ?? "http://localhost:4015" const ACCESS_TOKEN_KEY = "arcadia_access_token" const REFRESH_TOKEN_KEY = "arcadia_refresh_token" let client: ArcadiaClient | null = null export function gatewayClient(): ArcadiaClient { if (!client) { client = createArcadiaClient({ baseUrl: GATEWAY_URL, getToken: () => typeof window === "undefined" ? null : sessionStorage.getItem(ACCESS_TOKEN_KEY), onUnauthorized: () => { if (typeof window !== "undefined") { sessionStorage.removeItem(ACCESS_TOKEN_KEY) sessionStorage.removeItem(REFRESH_TOKEN_KEY) } }, }) } return client } export function useGatewayClient(): ArcadiaClient { return gatewayClient() }