import type { Config, Redacted } from "effect" import { Auth } from "./auth" export type ApiKeyMode = "optional" | "required" export type AuthOverride = { readonly auth: Auth readonly apiKey?: never } export type OptionalApiKeyAuth = { readonly apiKey?: string | Redacted.Redacted | Config.Config> readonly auth?: never } export type RequiredApiKeyAuth = { readonly apiKey: string | Redacted.Redacted | Config.Config> readonly auth?: never } export type ProviderAuthOption = | AuthOverride | (Mode extends "optional" ? OptionalApiKeyAuth : RequiredApiKeyAuth) export type ModelOptions = Omit & ProviderAuthOption export type ModelArgs = Mode extends "optional" ? readonly [options?: ModelOptions] : readonly [options: ModelOptions] export type ModelFactory = (id: string, ...args: ModelArgs) => Model /** * Require at least one of the keys in `T`. Use for option shapes where any * subset of fields is acceptable but at least one must be present (e.g. Azure * accepts `resourceName` or `baseURL`). */ export type AtLeastOne = { [K in keyof T]: Required> & Partial> }[keyof T] /** * Standard bearer-auth resolution for providers: honor an explicit `auth` * override, otherwise resolve `apiKey` (option > config var) and apply it as * a bearer token. */ export const bearer = (options: ProviderAuthOption<"optional">, envVar: string | ReadonlyArray): Auth => { if ("auth" in options && options.auth) return options.auth return (Array.isArray(envVar) ? envVar : [envVar]) .reduce( (auth, name) => auth.orElse(Auth.config(name)), Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey"), ) .bearer() } export * as AuthOptions from "./auth-options"