/** * OpenCode Plugin Types * * Type definitions for the OpenCode plugin system. * These types mirror the @opencode-ai/plugin interface. */ export interface OAuthAuthDetails { type: "oauth"; refresh: string; access?: string; expires?: number; } export interface ApiKeyAuthDetails { type: "api"; apiKey: string; } export interface TokenAuthDetails { type: "token"; token: string; } export type AuthDetails = OAuthAuthDetails | ApiKeyAuthDetails | TokenAuthDetails | { type: string; [key: string]: unknown; }; export type GetAuth = () => Promise; export interface ProviderModel { cost?: { input: number; output: number; }; [key: string]: unknown; } export interface Provider { id?: string; name?: string; models?: Record; } /** * RequestInfo type for fetch-like functions */ export type FetchInput = Request | string | URL; export interface LoaderResult { apiKey?: string; baseURL?: string; fetch?(input: FetchInput, init?: RequestInit): Promise; } export interface TokenExchangeSuccess { type: "success"; refresh: string; access: string; expires: number; } export interface TokenExchangeFailure { type: "failed"; error?: string; } export type TokenExchangeResult = TokenExchangeSuccess | TokenExchangeFailure; export interface OAuthAuthMethod { label: string; type: "oauth"; prompts?: AuthPrompt[]; authorize: (inputs?: Record) => Promise<{ url: string; instructions: string; method: "auto" | "code"; callback: (callbackUrl?: string) => Promise; }>; } export interface AuthPrompt { type: "text" | "select"; key: string; message: string; placeholder?: string; validate?: (value: string) => string | undefined; condition?: (inputs: Record) => boolean; options?: Array<{ label: string; value: string; hint?: string; }>; } export interface ApiKeyAuthMethod { label: string; type: "api"; prompts?: AuthPrompt[]; authorize?: (inputs?: Record) => Promise<{ type: "success"; key: string; provider?: string; } | { type: "failed"; }>; } export type AuthMethod = OAuthAuthMethod | ApiKeyAuthMethod; export interface PluginClient { auth: { set(input: { path: { id: string; }; body: AuthDetails; }): Promise; }; } export interface PluginContext { client: PluginClient; } export interface PluginResult { auth: { provider: string; loader: (getAuth: GetAuth, provider: Provider) => Promise; methods: AuthMethod[]; }; } export type Plugin = (context: PluginContext) => Promise; export interface CursorAuthRecord { accessToken: string; refreshToken: string; expires?: number; }