Expand description
Provider credentials: one type-tagged credential per provider, one write path, and one resolution result that names its source.
§Attribution
The design of this module is ported from pi-mono by Mario Zechner (https://github.com/earendil-works/pi-mono), MIT licensed, specifically:
| pi-mono file | ported into |
|---|---|
packages/ai/src/auth/types.ts | Credential, CredentialStore, AuthContext |
packages/ai/src/auth/credential-store.ts | store::InMemoryCredentialStore |
packages/ai/src/auth/context.ts | context::ProcessAuthContext |
packages/ai/src/auth/resolve.ts | codewhale_tui::config::credential_resolve |
This is a design port into idiomatic Rust, not a line-for-line copy.
pi’s module is async TypeScript over a Provider record with a single
auth.json; CodeWhale’s is synchronous Rust over ProviderKind and the
several pre-existing on-disk stores (secret store, config file, ambient
environment, externally consented CLI credential files). The four ideas
taken verbatim in spirit are: one type-tagged credential per provider,
modify as the only serialized write path, one stated precedence rule in
one place, and every resolution carrying a human-readable source label.
Several doc comments are adapted closely enough that the MIT permission
notice travels with them, reproduced below.
MIT License
Copyright (c) 2025 Mario Zechner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.§Redaction
Nothing in this module renders or logs secret material. Credential
deliberately has a hand-written std::fmt::Debug that prints only the
variant tag, so a credential cannot reach a log line through {:?} on a
surrounding struct.
Re-exports§
pub use context::AuthContext;pub use store::CredentialInfo;pub use store::CredentialStore;
Modules§
- context
- Injectable ambient-environment access for credential resolution.
- store
- App-owned credential storage:
modifyis the only write path.
Structs§
- Credential
Probe - One place credential resolution looked, and what would put a credential there. Labels only; never a value.
- Credential
Resolution - A resolution plus its source. Deliberately does not carry the credential: readiness surfaces need the source, and the request path already has its own resolver that returns the secret.
Enums§
- Credential
- One type-tagged credential per provider — pi’s
Credentialunion. - Credential
Kind - Credential
Source - The place a credential was resolved from, or the fact that no place had one. This is the single value every readiness surface should render.