import type * as plugins from './plugins.js'; export type TSmartAiProviderId = string; export type TSmartAiProviderLoginFlow = 'browser' | 'device'; export type TSmartAiProviderInputModality = plugins.openAi.TOpenAiChatGptInputModality; export interface ISmartAiProviderDescriptor { providerId: TSmartAiProviderId; displayName: string; loginFlows: readonly TSmartAiProviderLoginFlow[]; supportsApiKey: boolean; } export interface ISmartAiProviderApiKeyCredential { kind: 'apiKey'; providerId: TSmartAiProviderId; apiKey: string; } export interface IOpenAiChatGptOAuthCredential { kind: 'chatgptOAuth'; providerId: 'openai'; accessToken: string; refreshToken: string; idToken: string; lastRefreshAt?: string; } /** A short-lived, authority-resolved access grant for read and inference operations. */ export interface IOpenAiChatGptAccessCredential { kind: 'chatgptAccess'; providerId: 'openai'; accessToken: string; /** The verified ChatGPT workspace/account ID, not an email address. */ accountId: string; isFedrampAccount: boolean; } /** Access grants are deliberately excluded from stored provider credential envelopes. */ export type TOpenAiChatGptReadCredential = IOpenAiChatGptOAuthCredential | IOpenAiChatGptAccessCredential; export type TSmartAiProviderCredential = ISmartAiProviderApiKeyCredential | IOpenAiChatGptOAuthCredential; export interface ISmartAiProviderAccountSummary { providerId: TSmartAiProviderId; authKind: TSmartAiProviderCredential['kind']; accountId?: string; email?: string; plan?: string; } export interface ISmartAiProviderLoginResult { credential: IOpenAiChatGptOAuthCredential; account: ISmartAiProviderAccountSummary; } export interface ISmartAiProviderBrowserLoginPrompt { flow: 'browser'; authUrl: string; } export interface ISmartAiProviderDeviceLoginPrompt { flow: 'device'; verificationUrl: string; userCode: string; } export type TSmartAiProviderLoginPrompt = ISmartAiProviderBrowserLoginPrompt | ISmartAiProviderDeviceLoginPrompt; export type TSmartAiProviderCancelStatus = 'canceled' | 'notFound'; export interface ISmartAiProviderLoginHandle { readonly prompt: TSmartAiProviderLoginPrompt; readonly completion: Promise; cancel(): Promise; close(): Promise; } export interface ISmartAiProviderOperationOptions { signal?: AbortSignal; timeoutMs?: number; } /** The catalog shapes are defined once, by the access-only catalog read in `/openai`. */ export interface ISmartAiProviderModelReasoningEffort extends plugins.openAi.IOpenAiChatGptModelReasoningEffort { } export interface ISmartAiProviderModelServiceTier extends plugins.openAi.IOpenAiChatGptModelServiceTier { } export interface ISmartAiProviderModel extends plugins.openAi.IOpenAiChatGptModel { } export interface ISmartAiProviderModelListOptions extends ISmartAiProviderOperationOptions { cursor?: string; limit?: number; includeHidden?: boolean; } export type TSmartAiProviderCredentialOperationErrorCode = 'ABORTED' | 'TIMEOUT'; export interface ISmartAiProviderRefreshSuccess { success: true; credential: IOpenAiChatGptOAuthCredential; account: ISmartAiProviderAccountSummary; } export interface ISmartAiProviderRefreshFailure { success: false; credential: IOpenAiChatGptOAuthCredential; errorCode: TSmartAiProviderCredentialOperationErrorCode | 'REFRESH_FAILED'; /** Never replay a rotating grant when this is outcomeUnknown. */ requestOutcome: plugins.TOpenAiChatGptRequestOutcome; /** The response status, when an HTTP response was observed. */ responseStatus?: number; /** Bounded Retry-After delay from the observed response. */ retryAfterMs?: number; } export type TSmartAiProviderRefreshResult = ISmartAiProviderRefreshSuccess | ISmartAiProviderRefreshFailure; export interface ISmartAiProviderModelListSuccess { success: true; models: ISmartAiProviderModel[]; nextCursor?: string; } export interface ISmartAiProviderModelListFailure { success: false; errorCode: TSmartAiProviderCredentialOperationErrorCode | 'CREDENTIAL_REFRESH_REQUIRED' | 'MODEL_LIST_FAILED'; } export type TSmartAiProviderModelListResult = ISmartAiProviderModelListSuccess | ISmartAiProviderModelListFailure; export interface ISmartAiProviderRateLimitWindow { usedPercent: number; limitWindowSeconds: number; resetAfterSeconds: number; /** Unix timestamp in seconds. */ resetsAt: number; } export interface ISmartAiProviderRateLimitDetails { allowed: boolean; limitReached: boolean; primaryWindow?: ISmartAiProviderRateLimitWindow; secondaryWindow?: ISmartAiProviderRateLimitWindow; } export interface ISmartAiProviderAdditionalRateLimit { limitName: string; meteredFeature: string; rateLimit?: ISmartAiProviderRateLimitDetails; } export interface ISmartAiProviderAccountRateLimits { providerId: 'openai'; plan: string; observedAt: string; rateLimit?: ISmartAiProviderRateLimitDetails; additionalRateLimits: ISmartAiProviderAdditionalRateLimit[]; rateLimitReachedType?: string; rateLimitResetCreditsAvailableCount?: number; } export interface ISmartAiProviderAccountRateLimitsSuccess { success: true; rateLimits: ISmartAiProviderAccountRateLimits; } export interface ISmartAiProviderAccountRateLimitsFailure { success: false; errorCode: TSmartAiProviderCredentialOperationErrorCode | 'CREDENTIAL_REFRESH_REQUIRED' | 'ACCOUNT_RATE_LIMITS_FAILED'; } export type TSmartAiProviderAccountRateLimitsResult = ISmartAiProviderAccountRateLimitsSuccess | ISmartAiProviderAccountRateLimitsFailure; export interface ISmartAiProviderLoginOptions extends ISmartAiProviderOperationOptions { flow: TSmartAiProviderLoginFlow; } export interface ISmartAiProviderAdapter { readonly descriptor: ISmartAiProviderDescriptor; createApiKeyCredential(apiKey: string): ISmartAiProviderApiKeyCredential; inspectCredential(credential: TSmartAiProviderCredential): ISmartAiProviderAccountSummary; beginLogin(options: ISmartAiProviderLoginOptions): Promise; refreshCredential(credential: IOpenAiChatGptOAuthCredential, options?: ISmartAiProviderOperationOptions): Promise; listModels(credential: TOpenAiChatGptReadCredential, options?: ISmartAiProviderModelListOptions): Promise; getAccountRateLimits(credential: TOpenAiChatGptReadCredential, options?: ISmartAiProviderOperationOptions): Promise; logoutCredential(credential: IOpenAiChatGptOAuthCredential, options?: ISmartAiProviderOperationOptions): Promise; dispose(): Promise; } export interface IOpenAiProviderAdapterOptions { fetch?: typeof fetch; originator?: string; now?: () => Date; }