opencode-cursor-proxy 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +139 -0
  3. package/README.zh-CN.md +136 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +2 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/api/agent-service.d.ts +136 -0
  8. package/dist/lib/api/agent-service.js +938 -0
  9. package/dist/lib/api/agent-service.js.map +1 -0
  10. package/dist/lib/api/ai-service.d.ts +26 -0
  11. package/dist/lib/api/ai-service.js +38 -0
  12. package/dist/lib/api/ai-service.js.map +1 -0
  13. package/dist/lib/api/cursor-client.d.ts +119 -0
  14. package/dist/lib/api/cursor-client.js +511 -0
  15. package/dist/lib/api/cursor-client.js.map +1 -0
  16. package/dist/lib/api/cursor-models.d.ts +13 -0
  17. package/dist/lib/api/cursor-models.js +34 -0
  18. package/dist/lib/api/cursor-models.js.map +1 -0
  19. package/dist/lib/api/openai-compat.d.ts +10 -0
  20. package/dist/lib/api/openai-compat.js +262 -0
  21. package/dist/lib/api/openai-compat.js.map +1 -0
  22. package/dist/lib/api/proto/agent-messages.d.ts +25 -0
  23. package/dist/lib/api/proto/agent-messages.js +132 -0
  24. package/dist/lib/api/proto/agent-messages.js.map +1 -0
  25. package/dist/lib/api/proto/bidi.d.ts +17 -0
  26. package/dist/lib/api/proto/bidi.js +24 -0
  27. package/dist/lib/api/proto/bidi.js.map +1 -0
  28. package/dist/lib/api/proto/decoding.d.ts +19 -0
  29. package/dist/lib/api/proto/decoding.js +118 -0
  30. package/dist/lib/api/proto/decoding.js.map +1 -0
  31. package/dist/lib/api/proto/encoding.d.ts +64 -0
  32. package/dist/lib/api/proto/encoding.js +180 -0
  33. package/dist/lib/api/proto/encoding.js.map +1 -0
  34. package/dist/lib/api/proto/exec.d.ts +12 -0
  35. package/dist/lib/api/proto/exec.js +383 -0
  36. package/dist/lib/api/proto/exec.js.map +1 -0
  37. package/dist/lib/api/proto/index.d.ts +13 -0
  38. package/dist/lib/api/proto/index.js +10 -0
  39. package/dist/lib/api/proto/index.js.map +1 -0
  40. package/dist/lib/api/proto/interaction.d.ts +15 -0
  41. package/dist/lib/api/proto/interaction.js +99 -0
  42. package/dist/lib/api/proto/interaction.js.map +1 -0
  43. package/dist/lib/api/proto/kv.d.ts +52 -0
  44. package/dist/lib/api/proto/kv.js +156 -0
  45. package/dist/lib/api/proto/kv.js.map +1 -0
  46. package/dist/lib/api/proto/tool-calls.d.ts +9 -0
  47. package/dist/lib/api/proto/tool-calls.js +144 -0
  48. package/dist/lib/api/proto/tool-calls.js.map +1 -0
  49. package/dist/lib/api/proto/types.d.ts +201 -0
  50. package/dist/lib/api/proto/types.js +10 -0
  51. package/dist/lib/api/proto/types.js.map +1 -0
  52. package/dist/lib/auth/helpers.d.ts +40 -0
  53. package/dist/lib/auth/helpers.js +103 -0
  54. package/dist/lib/auth/helpers.js.map +1 -0
  55. package/dist/lib/auth/index.d.ts +7 -0
  56. package/dist/lib/auth/index.js +10 -0
  57. package/dist/lib/auth/index.js.map +1 -0
  58. package/dist/lib/auth/login.d.ts +55 -0
  59. package/dist/lib/auth/login.js +184 -0
  60. package/dist/lib/auth/login.js.map +1 -0
  61. package/dist/lib/config.d.ts +153 -0
  62. package/dist/lib/config.js +182 -0
  63. package/dist/lib/config.js.map +1 -0
  64. package/dist/lib/openai-compat/handler.d.ts +40 -0
  65. package/dist/lib/openai-compat/handler.js +808 -0
  66. package/dist/lib/openai-compat/handler.js.map +1 -0
  67. package/dist/lib/openai-compat/index.d.ts +9 -0
  68. package/dist/lib/openai-compat/index.js +13 -0
  69. package/dist/lib/openai-compat/index.js.map +1 -0
  70. package/dist/lib/openai-compat/types.d.ts +127 -0
  71. package/dist/lib/openai-compat/types.js +6 -0
  72. package/dist/lib/openai-compat/types.js.map +1 -0
  73. package/dist/lib/openai-compat/utils.d.ts +143 -0
  74. package/dist/lib/openai-compat/utils.js +348 -0
  75. package/dist/lib/openai-compat/utils.js.map +1 -0
  76. package/dist/lib/session-reuse.d.ts +88 -0
  77. package/dist/lib/session-reuse.js +198 -0
  78. package/dist/lib/session-reuse.js.map +1 -0
  79. package/dist/lib/storage.d.ts +55 -0
  80. package/dist/lib/storage.js +159 -0
  81. package/dist/lib/storage.js.map +1 -0
  82. package/dist/lib/utils/cache.d.ts +131 -0
  83. package/dist/lib/utils/cache.js +297 -0
  84. package/dist/lib/utils/cache.js.map +1 -0
  85. package/dist/lib/utils/fetch.d.ts +84 -0
  86. package/dist/lib/utils/fetch.js +261 -0
  87. package/dist/lib/utils/fetch.js.map +1 -0
  88. package/dist/lib/utils/index.d.ts +13 -0
  89. package/dist/lib/utils/index.js +22 -0
  90. package/dist/lib/utils/index.js.map +1 -0
  91. package/dist/lib/utils/jwt.d.ts +40 -0
  92. package/dist/lib/utils/jwt.js +102 -0
  93. package/dist/lib/utils/jwt.js.map +1 -0
  94. package/dist/lib/utils/logger.d.ts +107 -0
  95. package/dist/lib/utils/logger.js +227 -0
  96. package/dist/lib/utils/logger.js.map +1 -0
  97. package/dist/lib/utils/model-resolver.d.ts +49 -0
  98. package/dist/lib/utils/model-resolver.js +503 -0
  99. package/dist/lib/utils/model-resolver.js.map +1 -0
  100. package/dist/lib/utils/request-pool.d.ts +38 -0
  101. package/dist/lib/utils/request-pool.js +105 -0
  102. package/dist/lib/utils/request-pool.js.map +1 -0
  103. package/dist/lib/utils/request-transformer.d.ts +87 -0
  104. package/dist/lib/utils/request-transformer.js +154 -0
  105. package/dist/lib/utils/request-transformer.js.map +1 -0
  106. package/dist/lib/utils/tokenizer.d.ts +14 -0
  107. package/dist/lib/utils/tokenizer.js +76 -0
  108. package/dist/lib/utils/tokenizer.js.map +1 -0
  109. package/dist/plugin/index.d.ts +8 -0
  110. package/dist/plugin/index.js +9 -0
  111. package/dist/plugin/index.js.map +1 -0
  112. package/dist/plugin/plugin.d.ts +21 -0
  113. package/dist/plugin/plugin.js +309 -0
  114. package/dist/plugin/plugin.js.map +1 -0
  115. package/dist/plugin/types.d.ts +120 -0
  116. package/dist/plugin/types.js +7 -0
  117. package/dist/plugin/types.js.map +1 -0
  118. package/dist/server.d.ts +15 -0
  119. package/dist/server.js +95 -0
  120. package/dist/server.js.map +1 -0
  121. package/package.json +79 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Morse Wayne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # OpenCode Cursor Proxy
2
+
3
+ **English** | [中文](README.zh-CN.md)
4
+
5
+ > **Disclaimer**
6
+ >
7
+ > This is an **experimental** community project that integrates with Cursor via **unofficial** interfaces.
8
+ >
9
+ > - **May break at any time** if Cursor changes upstream behavior
10
+ > - **No guarantees** on stability, compatibility, or long-term support
11
+ > - **Not affiliated with / endorsed by Cursor**
12
+ > - May violate [Cursor Terms of Service](https://www.cursor.com/terms-of-service); **your account could be suspended/terminated**
13
+ >
14
+ > By using this project, you acknowledge these risks and accept full responsibility. For educational and research purposes only.
15
+
16
+ An OpenCode plugin that lets you use Cursor's AI backend with **OAuth authentication**, **dynamic model discovery**, and **full tool-calling support**.
17
+
18
+ ## Documentation
19
+
20
+ - 🚀 [Getting Started](docs/getting-started.md) - Installation and setup guide
21
+ - ⚙️ [Configuration](docs/configuration.md) - All configuration options
22
+ - 🔧 [Troubleshooting](docs/troubleshooting.md) - Common issues and solutions
23
+ - 🏗️ [Architecture](docs/development/architecture.md) - Technical deep dive
24
+
25
+ ## Features
26
+
27
+ - **OpenCode plugin integration** via OAuth
28
+ - **Full tool-calling support** (bash/read/write/ls/glob/grep, etc.)
29
+ - **Dynamic model discovery** from Cursor APIs
30
+ - **Streaming support** via SSE
31
+
32
+ ## Quick start (OpenCode plugin)
33
+
34
+ ### 1) Configure `opencode.json`
35
+
36
+ Add the plugin and provider to your `opencode.json`:
37
+
38
+ ```json
39
+ {
40
+ "$schema": "https://opencode.ai/config.json",
41
+ "plugin": ["opencode-cursor-proxy@latest"],
42
+ "provider": {
43
+ "cursor": { "name": "Cursor" }
44
+ }
45
+ }
46
+ ```
47
+
48
+ ### 2) Authenticate
49
+
50
+ Run OpenCode and authenticate:
51
+
52
+ ```bash
53
+ opencode auth login
54
+ ```
55
+
56
+ Then:
57
+
58
+ 1. Select **"other"** from the provider list
59
+ 2. Enter **"cursor"** as the provider name
60
+ 3. Select **"OAuth with Cursor"**
61
+ 4. Complete the browser-based OAuth flow
62
+
63
+ ## Standalone proxy server (optional, for development)
64
+
65
+ > The standalone proxy server is primarily a dev artifact for testing/debugging. Most users should prefer the OpenCode plugin flow above.
66
+
67
+ ### Prerequisites
68
+
69
+ - [Bun](https://bun.sh)
70
+ - A Cursor account with valid credentials
71
+
72
+ ### Run
73
+
74
+ ```bash
75
+ git clone https://github.com/MorseWayne/opencode-cursor-proxy.git
76
+ cd opencode-cursor-proxy
77
+ bun install
78
+
79
+ # authenticate (script name is auth)
80
+ bun run auth:login
81
+
82
+ # start server
83
+ bun run server
84
+ ```
85
+
86
+ Default listen address: `http://localhost:18741`
87
+
88
+ ### Environment variables
89
+
90
+ #### Basic
91
+
92
+ | Variable | Description | Default |
93
+ |----------|-------------|---------|
94
+ | `PORT` | Server port | `18741` |
95
+ | `HOST` | Server host | `localhost` |
96
+ | `CURSOR_ACCESS_TOKEN` | Provide an access token directly | - |
97
+
98
+ #### Debug & Logging
99
+
100
+ | Variable | Description | Default |
101
+ |----------|-------------|---------|
102
+ | `CURSOR_DEBUG` | Enable debug logging | `0` |
103
+ | `CURSOR_TIMING` | Enable performance timing logs | `0` |
104
+ | `CURSOR_LOG_LEVEL` | Log level: `error`, `warn`, `info`, `debug` | `info` |
105
+ | `CURSOR_LOG_JSON` | Output logs in JSON format | `0` |
106
+ | `CURSOR_REQUEST_LOGGING` | Enable request/response logging | `0` |
107
+ | `CURSOR_LOG_FILTERED_IDS` | Log filtered message IDs | `0` |
108
+ | `CURSOR_LOG_MULTIMODAL` | Log multimodal content detection | `0` |
109
+
110
+ #### Session & Cache
111
+
112
+ | Variable | Description | Default |
113
+ |----------|-------------|---------|
114
+ | `CURSOR_SESSION_REUSE` | Enable session reuse for tool-calling | `1` |
115
+ | `CURSOR_SESSION_TIMEOUT_MS` | Session timeout (ms) | `900000` (15min) |
116
+ | `CURSOR_MAX_SESSIONS` | Maximum cached sessions | `100` |
117
+ | `CURSOR_MODEL_CACHE_TTL_MS` | Model cache TTL (ms) | `300000` (5min) |
118
+
119
+ #### Network
120
+
121
+ | Variable | Description | Default |
122
+ |----------|-------------|---------|
123
+ | `CURSOR_REQUEST_TIMEOUT_MS` | Request timeout (ms) | `120000` (2min) |
124
+ | `CURSOR_MAX_RETRIES` | Max retry attempts | `3` |
125
+ | `CURSOR_RETRY_ENABLED` | Enable automatic retry | `1` |
126
+ | `CURSOR_RETRY_BASE_DELAY_MS` | Base delay for exponential backoff (ms) | `1000` |
127
+ | `CURSOR_RETRY_MAX_DELAY_MS` | Max delay between retries (ms) | `30000` |
128
+
129
+ #### API
130
+
131
+ | Variable | Description | Default |
132
+ |----------|-------------|---------|
133
+ | `CURSOR_API_URL` | Cursor API base URL | `https://api2.cursor.sh` |
134
+ | `CURSOR_PRIVACY_MODE` | Enable privacy mode | `1` |
135
+ | `CURSOR_CLIENT_VERSION` | Override client version header | - |
136
+
137
+ ## License
138
+
139
+ MIT
@@ -0,0 +1,136 @@
1
+ # OpenCode Cursor Proxy
2
+
3
+ [English](README.md) | **中文**
4
+
5
+ > **免责声明**
6
+ >
7
+ > 这是一个**实验性**社区项目,通过 **非官方接口** 与 Cursor 服务集成。
8
+ >
9
+ > - **随时可能中断**:Cursor 上游变更可能导致不可用
10
+ > - **不提供任何保证**:稳定性、兼容性与长期可用性均不承诺
11
+ > - **与 Cursor 无关且未获认可**
12
+ > - 可能违反 [Cursor 的服务条款](https://www.cursor.com/terms-of-service),**存在封号/终止服务的风险**
13
+ >
14
+ > 使用本项目即表示您理解并自行承担全部风险。本项目仅用于教育与研究目的。
15
+
16
+ 一个 OpenCode 插件,支持在 OpenCode 中使用 Cursor 的 AI 后端,具备 OAuth 认证、动态模型发现和完整的工具调用支持。
17
+
18
+ ## 文档
19
+
20
+ - 🚀 [快速入门](docs/getting-started.md) - 安装和设置指南
21
+ - ⚙️ [配置说明](docs/configuration.md) - 所有配置选项
22
+ - 🔧 [故障排除](docs/troubleshooting.md) - 常见问题与解决方案
23
+ - 🏗️ [架构设计](docs/development/architecture.md) - 技术深度解析
24
+
25
+ ## 功能特性
26
+
27
+ - **OpenCode 插件**:通过 OAuth 认证实现与 OpenCode 的原生集成
28
+ - **完整的工具调用支持**:支持 bash、read、write、list、glob/grep 等函数调用
29
+ - **动态模型发现**:自动从 Cursor 的 API 获取可用模型
30
+ - **流式支持**:通过 SSE 实现实时流式响应
31
+
32
+ ## 快速开始(OpenCode 插件)
33
+
34
+ ### 1) 配置 `opencode.json`
35
+
36
+ 将插件和 Cursor 提供商添加到您的 `opencode.json`:
37
+
38
+ ```json
39
+ {
40
+ "$schema": "https://opencode.ai/config.json",
41
+ "plugin": ["opencode-cursor-proxy@latest"],
42
+ "provider": {
43
+ "cursor": { "name": "Cursor" }
44
+ }
45
+ }
46
+ ```
47
+
48
+ ### 2) 认证
49
+
50
+ 运行 OpenCode 并进行认证:
51
+
52
+ ```bash
53
+ opencode auth login
54
+ ```
55
+
56
+ 然后:
57
+
58
+ 1. 从提供商列表中选择 **"other"**
59
+ 2. 输入 **"cursor"** 作为提供商名称
60
+ 3. 选择 **"OAuth with Cursor"**
61
+ 4. 完成基于浏览器的 OAuth 流程
62
+
63
+ ## 开发:独立代理服务器(可选)
64
+
65
+ > 独立代理服务器主要是用于测试/调试的开发产物。大多数用户应该优先使用上面的 OpenCode 插件。
66
+
67
+ ### 先决条件
68
+
69
+ - [Bun](https://bun.sh)
70
+ - 一个具有有效凭据的 Cursor 账户
71
+
72
+ ### 运行
73
+
74
+ ```bash
75
+ git clone https://github.com/MorseWayne/opencode-cursor-proxy.git
76
+ cd opencode-cursor-proxy
77
+ bun install
78
+
79
+ # 先进行身份验证(脚本名为 auth)
80
+ bun run auth:login
81
+
82
+ # 启动服务器
83
+ bun run server
84
+ ```
85
+
86
+ 默认监听:`http://localhost:18741`
87
+
88
+ ### 环境变量
89
+
90
+ #### 基础配置
91
+
92
+ | 变量 | 说明 | 默认值 |
93
+ |------|------|--------|
94
+ | `PORT` | 服务器端口 | `18741` |
95
+ | `HOST` | 服务器主机 | `localhost` |
96
+ | `CURSOR_ACCESS_TOKEN` | 直接提供访问令牌 | - |
97
+
98
+ #### 调试与日志
99
+
100
+ | 变量 | 说明 | 默认值 |
101
+ |------|------|--------|
102
+ | `CURSOR_DEBUG` | 启用调试日志 | `0` |
103
+ | `CURSOR_TIMING` | 启用性能计时日志 | `0` |
104
+ | `CURSOR_LOG_LEVEL` | 日志级别:`error`, `warn`, `info`, `debug` | `info` |
105
+ | `CURSOR_LOG_JSON` | 以 JSON 格式输出日志 | `0` |
106
+
107
+ #### 会话与缓存
108
+
109
+ | 变量 | 说明 | 默认值 |
110
+ |------|------|--------|
111
+ | `CURSOR_SESSION_REUSE` | 启用工具调用的会话复用 | `1` |
112
+ | `CURSOR_SESSION_TIMEOUT_MS` | 会话超时时间 (毫秒) | `900000` (15分钟) |
113
+ | `CURSOR_MAX_SESSIONS` | 最大缓存会话数 | `100` |
114
+ | `CURSOR_MODEL_CACHE_TTL_MS` | 模型缓存 TTL (毫秒) | `300000` (5分钟) |
115
+
116
+ #### 网络
117
+
118
+ | 变量 | 说明 | 默认值 |
119
+ |------|------|--------|
120
+ | `CURSOR_REQUEST_TIMEOUT_MS` | 请求超时时间 (毫秒) | `120000` (2分钟) |
121
+ | `CURSOR_MAX_RETRIES` | 最大重试次数 | `3` |
122
+ | `CURSOR_RETRY_ENABLED` | 启用自动重试 | `1` |
123
+ | `CURSOR_RETRY_BASE_DELAY_MS` | 指数退避基础延迟 (毫秒) | `1000` |
124
+ | `CURSOR_RETRY_MAX_DELAY_MS` | 重试最大延迟 (毫秒) | `30000` |
125
+
126
+ #### API
127
+
128
+ | 变量 | 说明 | 默认值 |
129
+ |------|------|--------|
130
+ | `CURSOR_API_URL` | Cursor API 基础 URL | `https://api2.cursor.sh` |
131
+ | `CURSOR_PRIVACY_MODE` | 启用隐私模式 | `1` |
132
+ | `CURSOR_CLIENT_VERSION` | 覆盖客户端版本头 | - |
133
+
134
+ ## 许可证
135
+
136
+ MIT
@@ -0,0 +1 @@
1
+ export { CursorOAuthPlugin as default } from "./plugin/plugin.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { CursorOAuthPlugin as default } from "./plugin/plugin.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Cursor Agent Service Client
3
+ *
4
+ * Implements the AgentService API for chat functionality.
5
+ * Uses the BidiSse pattern:
6
+ * - RunSSE (server-streaming) to receive responses
7
+ * - BidiAppend (unary) to send client messages
8
+ *
9
+ * Proto structure:
10
+ * AgentClientMessage:
11
+ * field 1: run_request (AgentRunRequest)
12
+ * field 2: exec_client_message (ExecClientMessage)
13
+ * field 3: kv_client_message (KvClientMessage)
14
+ * field 4: conversation_action (ConversationAction)
15
+ * field 5: exec_client_control_message
16
+ * field 6: interaction_response
17
+ *
18
+ * AgentServerMessage:
19
+ * field 1: interaction_update (InteractionUpdate)
20
+ * field 2: exec_server_message (ExecServerMessage)
21
+ * field 3: conversation_checkpoint_update (completion signal)
22
+ * field 4: kv_server_message (KvServerMessage)
23
+ * field 5: exec_server_control_message
24
+ * field 7: interaction_query
25
+ *
26
+ * InteractionUpdate.message:
27
+ * field 1: text_delta
28
+ * field 4: thinking_delta
29
+ * field 8: token_delta
30
+ * field 13: heartbeat
31
+ * field 14: turn_ended
32
+ */
33
+ import { AgentMode } from "./proto";
34
+ import type { OpenAIToolDefinition, McpExecRequest, ExecRequest, AgentServiceOptions, AgentChatRequest, ToolCallInfo, AgentStreamChunk as AgentStreamChunkType } from "./proto/types";
35
+ export { AgentMode };
36
+ export type AgentStreamChunk = AgentStreamChunkType;
37
+ export type { ExecRequest, McpExecRequest, ToolCallInfo, OpenAIToolDefinition };
38
+ export declare const CURSOR_API_URL: string;
39
+ export declare const AGENT_PRIVACY_URL: string;
40
+ export declare const AGENT_NON_PRIVACY_URL: string;
41
+ export declare class AgentServiceClient {
42
+ private baseUrl;
43
+ private accessToken;
44
+ private workspacePath;
45
+ private blobStore;
46
+ private privacyMode;
47
+ private clientVersionHeader;
48
+ private baseUrlAttempts;
49
+ private currentRequestId;
50
+ private currentAppendSeqno;
51
+ private pendingAssistantBlobs;
52
+ constructor(accessToken: string, options?: AgentServiceOptions);
53
+ private getHeaders;
54
+ private getBaseUrlAttempts;
55
+ private blobIdToKey;
56
+ /**
57
+ * Build the AgentClientMessage for a chat request
58
+ */
59
+ private buildChatMessage;
60
+ /**
61
+ * Call BidiAppend to send a client message
62
+ */
63
+ private bidiAppend;
64
+ private handleKvMessage;
65
+ /**
66
+ * Send a tool result back to the server (for MCP tools only)
67
+ * This must be called during an active chat stream when an exec_request chunk is received
68
+ */
69
+ sendToolResult(execRequest: McpExecRequest & {
70
+ type: 'mcp';
71
+ }, result: {
72
+ success?: {
73
+ content: string;
74
+ isError?: boolean;
75
+ };
76
+ error?: string;
77
+ }): Promise<void>;
78
+ /**
79
+ * Send a shell execution result back to the server
80
+ */
81
+ sendShellResult(id: number, execId: string | undefined, command: string, cwd: string, stdout: string, stderr: string, exitCode: number, executionTimeMs?: number): Promise<void>;
82
+ /**
83
+ * Send an LS result back to the server
84
+ */
85
+ sendLsResult(id: number, execId: string | undefined, filesString: string): Promise<void>;
86
+ /**
87
+ * Send a request context result back to the server
88
+ */
89
+ sendRequestContextResult(id: number, execId: string | undefined): Promise<void>;
90
+ /**
91
+ * Send a file read result back to the server
92
+ */
93
+ sendReadResult(id: number, execId: string | undefined, content: string, path: string, totalLines?: number, fileSize?: bigint, truncated?: boolean): Promise<void>;
94
+ /**
95
+ * Send a grep/glob result back to the server
96
+ */
97
+ sendGrepResult(id: number, execId: string | undefined, pattern: string, path: string, files: string[]): Promise<void>;
98
+ /**
99
+ * Send a file write result back to the server
100
+ */
101
+ sendWriteResult(id: number, execId: string | undefined, result: {
102
+ success?: {
103
+ path: string;
104
+ linesCreated: number;
105
+ fileSize: number;
106
+ fileContentAfterWrite?: string;
107
+ };
108
+ error?: {
109
+ path: string;
110
+ error: string;
111
+ };
112
+ }): Promise<void>;
113
+ /**
114
+ * Send a ResumeAction to signal the server to continue after tool results
115
+ * Based on Cursor CLI analysis: after sending tool results, send ConversationAction with resume_action
116
+ * to tell the server to resume streaming instead of storing responses in KV blobs
117
+ */
118
+ sendResumeAction(): Promise<void>;
119
+ /**
120
+ * Send a streaming chat request.
121
+ *
122
+ * Cursor periodically migrates AgentService/BidiService to different backends.
123
+ * If a request fails before any meaningful output, retry against known agent
124
+ * backends before surfacing the error.
125
+ */
126
+ chatStream(request: AgentChatRequest): AsyncGenerator<AgentStreamChunkType>;
127
+ private chatStreamOnce;
128
+ /**
129
+ * Send a non-streaming chat request (collects all chunks)
130
+ */
131
+ chat(request: AgentChatRequest): Promise<string>;
132
+ }
133
+ /**
134
+ * Create an Agent Service client
135
+ */
136
+ export declare function createAgentServiceClient(accessToken: string, options?: AgentServiceOptions): AgentServiceClient;