Credential readiness information for a provider. Args: state: Provider auth state. provider: Provider name. env_var: Env var name associated with the state, when applicable. source: For `CONFIGURED` states, where the credential value came from. `None`
| 247 | |
| 248 | @dataclass(frozen=True) |
| 249 | class ProviderAuthStatus: |
| 250 | """Credential readiness information for a provider. |
| 251 | |
| 252 | Args: |
| 253 | state: Provider auth state. |
| 254 | provider: Provider name. |
| 255 | env_var: Env var name associated with the state, when applicable. |
| 256 | source: For `CONFIGURED` states, where the credential value came |
| 257 | from. `None` for non-configured states or when the source is |
| 258 | not meaningful (e.g., implicit/managed auth). |
| 259 | detail: Short user-facing context for selectors and logs. |
| 260 | """ |
| 261 | |
| 262 | state: ProviderAuthState |
| 263 | provider: str |
| 264 | env_var: str | None = None |
| 265 | source: ProviderAuthSource | None = None |
| 266 | detail: str | None = None |
| 267 | |
| 268 | def __post_init__(self) -> None: |
| 269 | """Enforce the source-vs-state invariant. |
| 270 | |
| 271 | Raises: |
| 272 | ValueError: If `source` is set but `state` is not `CONFIGURED`, |
| 273 | or if `state` is `CONFIGURED` but no `source` is recorded. |
| 274 | """ |
| 275 | is_configured = self.state is ProviderAuthState.CONFIGURED |
| 276 | has_source = self.source is not None |
| 277 | if is_configured != has_source: |
| 278 | msg = ( |
| 279 | f"ProviderAuthStatus invariant violated: " |
| 280 | f"state={self.state!r} requires " |
| 281 | f"{'a source' if is_configured else 'source=None'}, " |
| 282 | f"got source={self.source!r}" |
| 283 | ) |
| 284 | raise ValueError(msg) |
| 285 | |
| 286 | @property |
| 287 | def blocks_start(self) -> bool: |
| 288 | """Whether this status should block model creation or switching.""" |
| 289 | return self.state is ProviderAuthState.MISSING |
| 290 | |
| 291 | def as_legacy_bool(self) -> bool | None: |
| 292 | """Return the historic `has_provider_credentials` tri-state value.""" |
| 293 | if self.state is ProviderAuthState.MISSING: |
| 294 | return False |
| 295 | if self.state is ProviderAuthState.UNKNOWN: |
| 296 | return None |
| 297 | return True |
| 298 | |
| 299 | def missing_detail(self) -> str: |
| 300 | """Return a user-facing reason for a missing-credential status.""" |
| 301 | if self.env_var: |
| 302 | return f"{self.env_var} is not set or is empty" |
| 303 | if self.detail: |
| 304 | return self.detail |
| 305 | return ( |
| 306 | f"provider '{self.provider}' is not recognized. " |
no outgoing calls