/** * Cursor API Client * * Implements the Cursor API communication using the Connect-RPC protocol. * This is a simplified implementation that handles chat completions. */ export declare const CURSOR_API_URL = "https://api2.cursor.sh"; export declare const CURSOR_CHAT_ENDPOINT = "/aiserver.v1.AiService/StreamChat"; export interface ChatMessage { role: "user" | "assistant" | "system"; content: string; } export interface ChatRequest { model: string; messages: ChatMessage[]; stream?: boolean; temperature?: number; maxTokens?: number; } export interface ChatResponseDelta { content: string; finishReason?: string; } export interface StreamChunk { type: "delta" | "done" | "error"; content?: string; error?: string; } /** * Encode a complete ChatMessage for the Cursor API * * ChatMessage structure: * - messages: field 2 (repeated UserMessage) * - instructions: field 4 (Instructions) * - projectPath: field 5 (string) * - model: field 7 (Model) * - requestId: field 9 (string) * - summary: field 11 (string) * - conversationId: field 15 (string) */ export declare function encodeChatRequest(request: ChatRequest): Uint8Array; /** * Add Connect-RPC envelope (5-byte header) * Format: [flags: 1 byte][length: 4 bytes big-endian][payload] */ export declare function addConnectEnvelope(data: Uint8Array, flags?: number): Uint8Array; /** * Parse Connect-RPC streaming response chunks */ export declare function parseStreamChunks(buffer: Uint8Array): StreamChunk[]; /** * Generate checksum for Cursor API requests * Based on OpenCursor's implementation */ export declare function generateChecksum(token: string): string; export interface CursorClientOptions { baseUrl?: string; headers?: Record; } export declare class CursorClient { private baseUrl; private accessToken; private headers; constructor(accessToken: string, options?: CursorClientOptions); /** * Expose the configured base URL (needed for ancillary Cursor calls). */ getBaseUrl(): string; /** * Get request headers for Cursor API * * IMPORTANT: Cursor's API requires `application/grpc-web+proto` content-type. * Using `application/connect+proto` returns 415 Unsupported Media Type. */ private getHeaders; /** * Build request headers with optional overrides. */ buildHeaders(extra?: Record): Record; /** * Send a chat completion request (non-streaming) */ chat(request: ChatRequest): Promise; /** * Send a streaming chat completion request */ chatStream(request: ChatRequest): AsyncGenerator; /** * Fetch available models from the Cursor API. * This is a working endpoint that returns the list of models available to the user. */ getModels(): Promise<{ models: any[]; }>; /** * Fetch the default model for CLI usage. */ getDefaultModel(): Promise<{ model: any | null; }>; /** * Health check endpoint. */ healthCheck(): Promise; } /** * Create a Cursor API client * * NOTE: As of late 2024, Cursor has deprecated the legacy StreamChat endpoint. * Chat functionality now requires the AgentService with bidirectional streaming. * The client currently supports: * - getModels() - Fetch available models * - getDefaultModel() - Get default model for CLI * - healthCheck() - Check API health * * For chat completions, you need to use the AgentService endpoints which require * proper proto message construction and bidirectional streaming support. */ export declare function createCursorClient(accessToken: string, options?: CursorClientOptions): CursorClient;