/** * Cursor Agent Service Client * * Implements the AgentService API for chat functionality. * Uses the BidiSse pattern: * - RunSSE (server-streaming) to receive responses * - BidiAppend (unary) to send client messages * * Proto structure: * AgentClientMessage: * field 1: run_request (AgentRunRequest) * field 2: exec_client_message (ExecClientMessage) * field 3: kv_client_message (KvClientMessage) * field 4: conversation_action (ConversationAction) * field 5: exec_client_control_message * field 6: interaction_response * * AgentServerMessage: * field 1: interaction_update (InteractionUpdate) * field 2: exec_server_message (ExecServerMessage) * field 3: conversation_checkpoint_update (completion signal) * field 4: kv_server_message (KvServerMessage) * field 5: exec_server_control_message * field 7: interaction_query * * InteractionUpdate.message: * field 1: text_delta * field 4: thinking_delta * field 8: token_delta * field 13: heartbeat * field 14: turn_ended */ import { AgentMode } from "./proto"; import type { OpenAIToolDefinition, McpExecRequest, ExecRequest, AgentServiceOptions, AgentChatRequest, ToolCallInfo, AgentStreamChunk as AgentStreamChunkType } from "./proto/types"; export { AgentMode }; export type AgentStreamChunk = AgentStreamChunkType; export type { ExecRequest, McpExecRequest, ToolCallInfo, OpenAIToolDefinition }; export declare const CURSOR_API_URL = "https://api2.cursor.sh"; export declare const AGENT_PRIVACY_URL = "https://agent.api5.cursor.sh"; export declare const AGENT_NON_PRIVACY_URL = "https://agentn.api5.cursor.sh"; export declare class AgentServiceClient { private baseUrl; private accessToken; private workspacePath; private blobStore; private currentRequestId; private currentAppendSeqno; private pendingAssistantBlobs; constructor(accessToken: string, options?: AgentServiceOptions); private getHeaders; private blobIdToKey; /** * Build the AgentClientMessage for a chat request */ private buildChatMessage; /** * Call BidiAppend to send a client message */ private bidiAppend; private handleKvMessage; /** * Send a tool result back to the server (for MCP tools only) * This must be called during an active chat stream when an exec_request chunk is received */ sendToolResult(execRequest: McpExecRequest & { type: 'mcp'; }, result: { success?: { content: string; isError?: boolean; }; error?: string; }): Promise; /** * Send a shell execution result back to the server */ sendShellResult(id: number, execId: string | undefined, command: string, cwd: string, stdout: string, stderr: string, exitCode: number, executionTimeMs?: number): Promise; /** * Send an LS result back to the server */ sendLsResult(id: number, execId: string | undefined, filesString: string): Promise; /** * Send a request context result back to the server */ sendRequestContextResult(id: number, execId: string | undefined): Promise; /** * Send a file read result back to the server */ sendReadResult(id: number, execId: string | undefined, content: string, path: string, totalLines?: number, fileSize?: bigint, truncated?: boolean): Promise; /** * Send a grep/glob result back to the server */ sendGrepResult(id: number, execId: string | undefined, pattern: string, path: string, files: string[]): Promise; /** * Send a file write result back to the server */ sendWriteResult(id: number, execId: string | undefined, result: { success?: { path: string; linesCreated: number; fileSize: number; fileContentAfterWrite?: string; }; error?: { path: string; error: string; }; }): Promise; /** * Send a ResumeAction to signal the server to continue after tool results * Based on Cursor CLI analysis: after sending tool results, send ConversationAction with resume_action * to tell the server to resume streaming instead of storing responses in KV blobs */ sendResumeAction(): Promise; /** * Send a streaming chat request using BidiSse pattern */ chatStream(request: AgentChatRequest): AsyncGenerator; /** * Send a non-streaming chat request (collects all chunks) */ chat(request: AgentChatRequest): Promise; } /** * Create an Agent Service client */ export declare function createAgentServiceClient(accessToken: string, options?: AgentServiceOptions): AgentServiceClient;