/** * Shared Cosmos DB client for the Platform Service. */ import { CosmosClient, Container } from "@azure/cosmos"; let client: CosmosClient | null = null; function getClient(): CosmosClient { if (!client) { const endpoint = process.env.COSMOS_ENDPOINT; const key = process.env.COSMOS_KEY; if (!endpoint || !key) { throw new Error("COSMOS_ENDPOINT and COSMOS_KEY must be set"); } client = new CosmosClient({ endpoint, key }); } return client; } export function getContainer(name: string): Container { const database = process.env.COSMOS_DATABASE || "lysnrai"; return getClient().database(database).container(name); }