import { AiSemaphore } from './AiSemaphore'; let sharedSemaphore: AiSemaphore | undefined; let configuredCapacity: number | undefined; export function getAiSemaphore(capacity: number): AiSemaphore { if (!sharedSemaphore) { configuredCapacity = capacity; sharedSemaphore = new AiSemaphore(capacity); } else if (configuredCapacity !== capacity) { throw new Error('AI concurrency configuration changed after runtime initialization'); } return sharedSemaphore; }