class LlmProviderRegistryImpl {
  constructor() {
    // Preserves registration order via Map iteration semantics.
    this.providers = /* @__PURE__ */ new Map();
  }
  register(provider) {
    if (!provider || typeof provider.id !== "string" || provider.id.length === 0) {
      throw new Error("[LlmProviderRegistry] Provider must have a non-empty id");
    }
    this.providers.set(provider.id, provider);
  }
  get(id) {
    return this.providers.get(id) ?? null;
  }
  list() {
    return Array.from(this.providers.values());
  }
  listConfigured(env) {
    const lookup = env ?? process.env;
    return this.list().filter((provider) => provider.isConfigured(lookup));
  }
  resolveFirstConfigured(options) {
    const env = options?.env ?? process.env;
    const order = options?.order;
    if (order && order.length > 0) {
      for (const id of order) {
        const provider = this.providers.get(id);
        if (provider && provider.isConfigured(env)) {
          return provider;
        }
      }
      const listed = new Set(order);
      for (const provider of this.providers.values()) {
        if (listed.has(provider.id)) continue;
        if (provider.isConfigured(env)) {
          return provider;
        }
      }
      return null;
    }
    for (const provider of this.providers.values()) {
      if (provider.isConfigured(env)) {
        return provider;
      }
    }
    return null;
  }
  reset() {
    this.providers.clear();
  }
}
const llmProviderRegistry = new LlmProviderRegistryImpl();
export {
  llmProviderRegistry
};
//# sourceMappingURL=llm-provider-registry.js.map
