@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
61 lines • 4.08 kB
TypeScript
import type { CredentialAuthResult, CredentialModel, CredentialResolver, ProviderCredential } from "../../../runtime/credential-resolver.ts";
export type ImageGenAuthModel = CredentialModel;
export type ImageGenRegistryAuthResult = CredentialAuthResult;
export type ImageGenProviderAuthResult = ProviderCredential;
export type ImageGenAuthRegistry<TModel extends ImageGenAuthModel = ImageGenAuthModel> = Pick<CredentialResolver<TModel>, "authStorage" | "getAll" | "getApiKeyAndHeaders" | "getProviderAuth" | "getProviderAuthStatus" | "providerAuthIsHeaderOnly">;
export interface ResolveImageGenAuthDeps<TModel extends ImageGenAuthModel = ImageGenAuthModel> {
modelRegistry: ImageGenAuthRegistry<TModel>;
env?: Readonly<Record<string, string | undefined>>;
}
export interface ImageGenResolvedAuth {
kind: "native-openai" | "gateway";
apiKey: string | undefined;
baseUrl: string;
headers?: Record<string, string>;
provenance: "store" | "env" | "provider-config";
providerId?: string;
}
export type ImageGenAuthResolution = ImageGenResolvedAuth | {
kind: "none";
reason: string;
};
/**
* One source the tool may send the request to. `fallthrough` is true only for a gateway found by
* scanning models.json: when it has no images endpoint (404/405) the tool tries the next candidate.
* A source the user chose (a stored or overridden `openai`, the PI_IMAGE_GEN_PROVIDER pin, or
* OPENAI_API_KEY) never falls through, so its failure is reported as is.
*/
export interface ImageGenCandidate extends ImageGenResolvedAuth {
fallthrough: boolean;
}
export declare const SETUP_REASON = "Image generation is not configured. Store an OpenAI API key for provider \"openai\", configure an OpenAI-compatible gateway in models.json and optionally pin it with PI_IMAGE_GEN_PROVIDER, or set OPENAI_API_KEY.";
/**
* Yields the image sources in precedence order, resolving each one's credentials only when the
* previous candidate fell through: a stored `openai` key, the PI_IMAGE_GEN_PROVIDER pin, a
* models.json `openai` override, scanned gateways, then OPENAI_API_KEY.
*/
export declare function imageGenCandidates<TModel extends ImageGenAuthModel>(deps: ResolveImageGenAuthDeps<TModel>): AsyncGenerator<ImageGenCandidate>;
export type ImageGenAvailability = Pick<ImageGenResolvedAuth, "kind" | "provenance" | "providerId"> | {
kind: "none";
reason: string;
};
/**
* Whether image generation has a source, in the precedence `imageGenCandidates` uses, read from
* configuration only (senpi#5707). Session open and every request ask this, so it never resolves a
* key: a `!command` key helper, an OAuth refresh or a token mint runs when the tool actually sends
* a request, where `imageGenCandidates` still falls through a source that fails and a configured
* source that resolves to nothing is reported as `credential_unavailable`. Without resolving,
* placeholder keys are recognized only where their value is readable here (a stored credential,
* OPENAI_API_KEY); one inside a models.json key or a provider env var counts as configured and
* fails at use. A registry that cannot report provider auth status statically is resolved as before.
*/
export declare function imageGenAvailability<TModel extends ImageGenAuthModel>(deps: ResolveImageGenAuthDeps<TModel>): Promise<ImageGenAvailability>;
/**
* The logged-in built-in providers that scanning passed over because their API serves no OpenAI Images
* endpoint, so a setup failure can say why they were not used. Only called once no candidate remains.
*/
export declare function unsupportedImageGateways<TModel extends ImageGenAuthModel>(deps: ResolveImageGenAuthDeps<TModel>): Promise<string[]>;
/** The setup guidance, naming any logged-in providers that were not used because they cannot generate images. */
export declare function setupReason(unsupported: readonly string[]): string;
export declare function resolveImageGenAuth<TModel extends ImageGenAuthModel>(deps: ResolveImageGenAuthDeps<TModel>): Promise<ImageGenAuthResolution>;
//# sourceMappingURL=auth.d.ts.map