opencode-ext-connector 0.3.0

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 (332) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/LICENSE +29 -0
  3. package/README.md +207 -0
  4. package/THIRD_PARTY_NOTICES.md +201 -0
  5. package/dist/catalog/parse-ids.d.ts +2 -0
  6. package/dist/catalog/parse-ids.js +49 -0
  7. package/dist/core/adapter.d.ts +16 -0
  8. package/dist/core/adapter.js +20 -0
  9. package/dist/core/clock.d.ts +7 -0
  10. package/dist/core/clock.js +1 -0
  11. package/dist/core/deadline.d.ts +13 -0
  12. package/dist/core/deadline.js +54 -0
  13. package/dist/core/errors.d.ts +57 -0
  14. package/dist/core/errors.js +81 -0
  15. package/dist/core/health.d.ts +22 -0
  16. package/dist/core/health.js +30 -0
  17. package/dist/core/http.d.ts +28 -0
  18. package/dist/core/http.js +1 -0
  19. package/dist/core/ids.d.ts +7 -0
  20. package/dist/core/ids.js +23 -0
  21. package/dist/core/lifecycle.d.ts +4 -0
  22. package/dist/core/lifecycle.js +16 -0
  23. package/dist/core/logger.d.ts +21 -0
  24. package/dist/core/logger.js +61 -0
  25. package/dist/core/models.d.ts +41 -0
  26. package/dist/core/models.js +59 -0
  27. package/dist/core/options.d.ts +31 -0
  28. package/dist/core/options.js +62 -0
  29. package/dist/core/process.d.ts +20 -0
  30. package/dist/core/process.js +1 -0
  31. package/dist/http/fetch-transport.d.ts +2 -0
  32. package/dist/http/fetch-transport.js +75 -0
  33. package/dist/http/package-version.d.ts +7 -0
  34. package/dist/http/package-version.js +46 -0
  35. package/dist/http/read-body.d.ts +9 -0
  36. package/dist/http/read-body.js +22 -0
  37. package/dist/index.d.ts +6 -0
  38. package/dist/index.js +5 -0
  39. package/dist/logging/logger.d.ts +4 -0
  40. package/dist/logging/logger.js +11 -0
  41. package/dist/opencode/auth-store.d.ts +19 -0
  42. package/dist/opencode/auth-store.js +107 -0
  43. package/dist/opencode/beta-api.d.ts +3 -0
  44. package/dist/opencode/beta-api.js +1 -0
  45. package/dist/opencode/catalog-bridge.d.ts +3 -0
  46. package/dist/opencode/catalog-bridge.js +85 -0
  47. package/dist/opencode/health-refresh.d.ts +16 -0
  48. package/dist/opencode/health-refresh.js +49 -0
  49. package/dist/opencode/host-options.d.ts +2 -0
  50. package/dist/opencode/host-options.js +49 -0
  51. package/dist/opencode/language-factory.d.ts +13 -0
  52. package/dist/opencode/language-factory.js +37 -0
  53. package/dist/opencode/ollama-probe.d.ts +2 -0
  54. package/dist/opencode/ollama-probe.js +15 -0
  55. package/dist/opencode/ollama-production.d.ts +4 -0
  56. package/dist/opencode/ollama-production.js +10 -0
  57. package/dist/opencode/plugin.d.ts +33 -0
  58. package/dist/opencode/plugin.js +40 -0
  59. package/dist/opencode/process-exit.d.ts +4 -0
  60. package/dist/opencode/process-exit.js +22 -0
  61. package/dist/opencode/provider-entry.d.ts +25 -0
  62. package/dist/opencode/provider-entry.js +1 -0
  63. package/dist/opencode/providers.d.ts +16 -0
  64. package/dist/opencode/providers.js +140 -0
  65. package/dist/opencode/register-integrations.d.ts +3 -0
  66. package/dist/opencode/register-integrations.js +8 -0
  67. package/dist/opencode/reload.d.ts +9 -0
  68. package/dist/opencode/reload.js +30 -0
  69. package/dist/opencode/v1-anthropic-auth.d.ts +9 -0
  70. package/dist/opencode/v1-anthropic-auth.js +55 -0
  71. package/dist/opencode/v1-catalog.d.ts +13 -0
  72. package/dist/opencode/v1-catalog.js +80 -0
  73. package/dist/opencode/v1-language.d.ts +3 -0
  74. package/dist/opencode/v1-language.js +64 -0
  75. package/dist/opencode/v1-module.d.ts +23 -0
  76. package/dist/opencode/v1-module.js +74 -0
  77. package/dist/opencode/v1-session-auth.d.ts +5 -0
  78. package/dist/opencode/v1-session-auth.js +98 -0
  79. package/dist/providers/claude/adapter.d.ts +7 -0
  80. package/dist/providers/claude/adapter.js +37 -0
  81. package/dist/providers/claude/atomic-private-file.d.ts +13 -0
  82. package/dist/providers/claude/atomic-private-file.js +94 -0
  83. package/dist/providers/claude/auth-json.d.ts +2 -0
  84. package/dist/providers/claude/auth-json.js +14 -0
  85. package/dist/providers/claude/auth.d.ts +24 -0
  86. package/dist/providers/claude/auth.js +200 -0
  87. package/dist/providers/claude/cli-version.d.ts +10 -0
  88. package/dist/providers/claude/cli-version.js +36 -0
  89. package/dist/providers/claude/compat-betas.d.ts +5 -0
  90. package/dist/providers/claude/compat-betas.js +54 -0
  91. package/dist/providers/claude/compat-config.d.ts +8 -0
  92. package/dist/providers/claude/compat-config.js +31 -0
  93. package/dist/providers/claude/compat-request.d.ts +12 -0
  94. package/dist/providers/claude/compat-request.js +151 -0
  95. package/dist/providers/claude/compat-response.d.ts +1 -0
  96. package/dist/providers/claude/compat-response.js +54 -0
  97. package/dist/providers/claude/compat-signing.d.ts +9 -0
  98. package/dist/providers/claude/compat-signing.js +24 -0
  99. package/dist/providers/claude/compat-transform.d.ts +3 -0
  100. package/dist/providers/claude/compat-transform.js +224 -0
  101. package/dist/providers/claude/credentials.d.ts +7 -0
  102. package/dist/providers/claude/credentials.js +37 -0
  103. package/dist/providers/claude/emit-stream.d.ts +2 -0
  104. package/dist/providers/claude/emit-stream.js +62 -0
  105. package/dist/providers/claude/keychain-account.d.ts +1 -0
  106. package/dist/providers/claude/keychain-account.js +14 -0
  107. package/dist/providers/claude/language-model.d.ts +8 -0
  108. package/dist/providers/claude/language-model.js +109 -0
  109. package/dist/providers/claude/models.d.ts +9 -0
  110. package/dist/providers/claude/models.js +24 -0
  111. package/dist/providers/claude/prompt.d.ts +42 -0
  112. package/dist/providers/claude/prompt.js +134 -0
  113. package/dist/providers/claude/refresh.d.ts +19 -0
  114. package/dist/providers/claude/refresh.js +85 -0
  115. package/dist/providers/claude/sse-convert.d.ts +6 -0
  116. package/dist/providers/claude/sse-convert.js +74 -0
  117. package/dist/providers/claude/sse.d.ts +71 -0
  118. package/dist/providers/claude/sse.js +123 -0
  119. package/dist/providers/claude/transform.d.ts +32 -0
  120. package/dist/providers/claude/transform.js +52 -0
  121. package/dist/providers/claude/writeback.d.ts +18 -0
  122. package/dist/providers/claude/writeback.js +140 -0
  123. package/dist/providers/command-code/adapter.d.ts +7 -0
  124. package/dist/providers/command-code/adapter.js +37 -0
  125. package/dist/providers/command-code/auth.d.ts +5 -0
  126. package/dist/providers/command-code/auth.js +88 -0
  127. package/dist/providers/command-code/cli-version.d.ts +10 -0
  128. package/dist/providers/command-code/cli-version.js +36 -0
  129. package/dist/providers/command-code/emit-stream.d.ts +2 -0
  130. package/dist/providers/command-code/emit-stream.js +226 -0
  131. package/dist/providers/command-code/errors.d.ts +33 -0
  132. package/dist/providers/command-code/errors.js +105 -0
  133. package/dist/providers/command-code/language-model.d.ts +15 -0
  134. package/dist/providers/command-code/language-model.js +203 -0
  135. package/dist/providers/command-code/models.d.ts +3 -0
  136. package/dist/providers/command-code/models.js +18 -0
  137. package/dist/providers/command-code/record-stream.d.ts +1 -0
  138. package/dist/providers/command-code/record-stream.js +61 -0
  139. package/dist/providers/command-code/request-lifecycle.d.ts +8 -0
  140. package/dist/providers/command-code/request-lifecycle.js +33 -0
  141. package/dist/providers/command-code/request.d.ts +14 -0
  142. package/dist/providers/command-code/request.js +167 -0
  143. package/dist/providers/command-code/session.d.ts +5 -0
  144. package/dist/providers/command-code/session.js +9 -0
  145. package/dist/providers/cursor/adapter.d.ts +7 -0
  146. package/dist/providers/cursor/adapter.js +37 -0
  147. package/dist/providers/cursor/auth.d.ts +6 -0
  148. package/dist/providers/cursor/auth.js +56 -0
  149. package/dist/providers/cursor/blob-store.d.ts +26 -0
  150. package/dist/providers/cursor/blob-store.js +119 -0
  151. package/dist/providers/cursor/bridge-client.d.ts +33 -0
  152. package/dist/providers/cursor/bridge-client.js +200 -0
  153. package/dist/providers/cursor/bridge-event-sanitize.d.ts +3 -0
  154. package/dist/providers/cursor/bridge-event-sanitize.js +49 -0
  155. package/dist/providers/cursor/bridge-limits.d.ts +3 -0
  156. package/dist/providers/cursor/bridge-limits.js +10 -0
  157. package/dist/providers/cursor/bridge-process.d.ts +45 -0
  158. package/dist/providers/cursor/bridge-process.js +211 -0
  159. package/dist/providers/cursor/bridge-protocol.d.ts +68 -0
  160. package/dist/providers/cursor/bridge-protocol.js +49 -0
  161. package/dist/providers/cursor/bridge-serialize.d.ts +3 -0
  162. package/dist/providers/cursor/bridge-serialize.js +53 -0
  163. package/dist/providers/cursor/bridge-wire.d.ts +3 -0
  164. package/dist/providers/cursor/bridge-wire.js +163 -0
  165. package/dist/providers/cursor/checkpoint-store.d.ts +28 -0
  166. package/dist/providers/cursor/checkpoint-store.js +94 -0
  167. package/dist/providers/cursor/connect-frame-stream.d.ts +19 -0
  168. package/dist/providers/cursor/connect-frame-stream.js +160 -0
  169. package/dist/providers/cursor/connect-frame.d.ts +31 -0
  170. package/dist/providers/cursor/connect-frame.js +121 -0
  171. package/dist/providers/cursor/credentials.d.ts +5 -0
  172. package/dist/providers/cursor/credentials.js +22 -0
  173. package/dist/providers/cursor/direct-run-types.d.ts +33 -0
  174. package/dist/providers/cursor/direct-run-types.js +1 -0
  175. package/dist/providers/cursor/direct-run.d.ts +5 -0
  176. package/dist/providers/cursor/direct-run.js +213 -0
  177. package/dist/providers/cursor/direct-runtime.d.ts +23 -0
  178. package/dist/providers/cursor/direct-runtime.js +111 -0
  179. package/dist/providers/cursor/direct-stream.d.ts +28 -0
  180. package/dist/providers/cursor/direct-stream.js +190 -0
  181. package/dist/providers/cursor/exec-reply.d.ts +13 -0
  182. package/dist/providers/cursor/exec-reply.js +102 -0
  183. package/dist/providers/cursor/h2-bridge-response.d.ts +9 -0
  184. package/dist/providers/cursor/h2-bridge-response.js +51 -0
  185. package/dist/providers/cursor/h2-bridge-session.d.ts +24 -0
  186. package/dist/providers/cursor/h2-bridge-session.js +197 -0
  187. package/dist/providers/cursor/h2-bridge.d.ts +2 -0
  188. package/dist/providers/cursor/h2-bridge.js +12865 -0
  189. package/dist/providers/cursor/http2.d.ts +18 -0
  190. package/dist/providers/cursor/http2.js +144 -0
  191. package/dist/providers/cursor/interaction-reply.d.ts +6 -0
  192. package/dist/providers/cursor/interaction-reply.js +52 -0
  193. package/dist/providers/cursor/language-generate.d.ts +2 -0
  194. package/dist/providers/cursor/language-generate.js +35 -0
  195. package/dist/providers/cursor/language-model.d.ts +13 -0
  196. package/dist/providers/cursor/language-model.js +77 -0
  197. package/dist/providers/cursor/legacy-stream.d.ts +11 -0
  198. package/dist/providers/cursor/legacy-stream.js +115 -0
  199. package/dist/providers/cursor/mcp-tools.d.ts +7 -0
  200. package/dist/providers/cursor/mcp-tools.js +15 -0
  201. package/dist/providers/cursor/models.d.ts +14 -0
  202. package/dist/providers/cursor/models.js +116 -0
  203. package/dist/providers/cursor/ndjson.d.ts +3 -0
  204. package/dist/providers/cursor/ndjson.js +100 -0
  205. package/dist/providers/cursor/prompt.d.ts +4 -0
  206. package/dist/providers/cursor/prompt.js +142 -0
  207. package/dist/providers/cursor/proto/checkpoint.d.ts +35 -0
  208. package/dist/providers/cursor/proto/checkpoint.js +114 -0
  209. package/dist/providers/cursor/proto/context.d.ts +64 -0
  210. package/dist/providers/cursor/proto/context.js +178 -0
  211. package/dist/providers/cursor/proto/errors.d.ts +16 -0
  212. package/dist/providers/cursor/proto/errors.js +26 -0
  213. package/dist/providers/cursor/proto/exec-control.d.ts +20 -0
  214. package/dist/providers/cursor/proto/exec-control.js +54 -0
  215. package/dist/providers/cursor/proto/exec.d.ts +47 -0
  216. package/dist/providers/cursor/proto/exec.js +154 -0
  217. package/dist/providers/cursor/proto/fields.d.ts +22 -0
  218. package/dist/providers/cursor/proto/fields.js +97 -0
  219. package/dist/providers/cursor/proto/interaction-query.d.ts +15 -0
  220. package/dist/providers/cursor/proto/interaction-query.js +79 -0
  221. package/dist/providers/cursor/proto/interaction-tool-update.d.ts +10 -0
  222. package/dist/providers/cursor/proto/interaction-tool-update.js +58 -0
  223. package/dist/providers/cursor/proto/interaction-turn-ended.d.ts +6 -0
  224. package/dist/providers/cursor/proto/interaction-turn-ended.js +18 -0
  225. package/dist/providers/cursor/proto/interaction.d.ts +65 -0
  226. package/dist/providers/cursor/proto/interaction.js +185 -0
  227. package/dist/providers/cursor/proto/kv.d.ts +25 -0
  228. package/dist/providers/cursor/proto/kv.js +109 -0
  229. package/dist/providers/cursor/proto/mcp-result.d.ts +40 -0
  230. package/dist/providers/cursor/proto/mcp-result.js +150 -0
  231. package/dist/providers/cursor/proto/mcp.d.ts +19 -0
  232. package/dist/providers/cursor/proto/mcp.js +78 -0
  233. package/dist/providers/cursor/proto/model.d.ts +11 -0
  234. package/dist/providers/cursor/proto/model.js +36 -0
  235. package/dist/providers/cursor/proto/output-location.d.ts +7 -0
  236. package/dist/providers/cursor/proto/output-location.js +53 -0
  237. package/dist/providers/cursor/proto/prewarm.d.ts +16 -0
  238. package/dist/providers/cursor/proto/prewarm.js +68 -0
  239. package/dist/providers/cursor/proto/request-context.d.ts +16 -0
  240. package/dist/providers/cursor/proto/request-context.js +58 -0
  241. package/dist/providers/cursor/proto/request.d.ts +44 -0
  242. package/dist/providers/cursor/proto/request.js +111 -0
  243. package/dist/providers/cursor/proto/run-request.d.ts +19 -0
  244. package/dist/providers/cursor/proto/run-request.js +68 -0
  245. package/dist/providers/cursor/proto/server.d.ts +35 -0
  246. package/dist/providers/cursor/proto/server.js +93 -0
  247. package/dist/providers/cursor/proto/unknown-field.d.ts +1 -0
  248. package/dist/providers/cursor/proto/unknown-field.js +22 -0
  249. package/dist/providers/cursor/proto-value.d.ts +3 -0
  250. package/dist/providers/cursor/proto-value.js +170 -0
  251. package/dist/providers/cursor/proto-wire.d.ts +22 -0
  252. package/dist/providers/cursor/proto-wire.js +224 -0
  253. package/dist/providers/cursor/protocol-failure.d.ts +18 -0
  254. package/dist/providers/cursor/protocol-failure.js +45 -0
  255. package/dist/providers/cursor/recovery.d.ts +48 -0
  256. package/dist/providers/cursor/recovery.js +102 -0
  257. package/dist/providers/cursor/request-blob-ownership.d.ts +15 -0
  258. package/dist/providers/cursor/request-blob-ownership.js +39 -0
  259. package/dist/providers/cursor/request-build.d.ts +18 -0
  260. package/dist/providers/cursor/request-build.js +123 -0
  261. package/dist/providers/cursor/request-history.d.ts +32 -0
  262. package/dist/providers/cursor/request-history.js +163 -0
  263. package/dist/providers/cursor/request-input.d.ts +75 -0
  264. package/dist/providers/cursor/request-input.js +123 -0
  265. package/dist/providers/cursor/run-events.d.ts +15 -0
  266. package/dist/providers/cursor/run-events.js +43 -0
  267. package/dist/providers/cursor/run-session-expiry.d.ts +15 -0
  268. package/dist/providers/cursor/run-session-expiry.js +21 -0
  269. package/dist/providers/cursor/run-session.d.ts +50 -0
  270. package/dist/providers/cursor/run-session.js +205 -0
  271. package/dist/providers/cursor/run.d.ts +9 -0
  272. package/dist/providers/cursor/run.js +151 -0
  273. package/dist/providers/cursor/runner.d.ts +1 -0
  274. package/dist/providers/cursor/runner.js +55 -0
  275. package/dist/providers/cursor/server-dispatch-types.d.ts +83 -0
  276. package/dist/providers/cursor/server-dispatch-types.js +1 -0
  277. package/dist/providers/cursor/server-dispatch.d.ts +3 -0
  278. package/dist/providers/cursor/server-dispatch.js +178 -0
  279. package/dist/providers/cursor/session-state.d.ts +21 -0
  280. package/dist/providers/cursor/session-state.js +118 -0
  281. package/dist/providers/cursor/session.d.ts +1 -0
  282. package/dist/providers/cursor/session.js +26 -0
  283. package/dist/providers/cursor/settle-cleanup.d.ts +1 -0
  284. package/dist/providers/cursor/settle-cleanup.js +11 -0
  285. package/dist/providers/cursor/stream-adapter.d.ts +17 -0
  286. package/dist/providers/cursor/stream-adapter.js +99 -0
  287. package/dist/providers/cursor/tool-continuation.d.ts +14 -0
  288. package/dist/providers/cursor/tool-continuation.js +134 -0
  289. package/dist/providers/cursor/tool-stream.d.ts +2 -0
  290. package/dist/providers/cursor/tool-stream.js +220 -0
  291. package/dist/providers/cursor/usage.d.ts +3 -0
  292. package/dist/providers/cursor/usage.js +35 -0
  293. package/dist/providers/ollama/adapter.d.ts +8 -0
  294. package/dist/providers/ollama/adapter.js +65 -0
  295. package/dist/providers/ollama/catalog-state.d.ts +17 -0
  296. package/dist/providers/ollama/catalog-state.js +40 -0
  297. package/dist/providers/ollama/cloud-catalog.d.ts +3 -0
  298. package/dist/providers/ollama/cloud-catalog.js +82 -0
  299. package/dist/providers/ollama/errors.d.ts +14 -0
  300. package/dist/providers/ollama/errors.js +19 -0
  301. package/dist/providers/ollama/generate.d.ts +2 -0
  302. package/dist/providers/ollama/generate.js +49 -0
  303. package/dist/providers/ollama/html-links.d.ts +1 -0
  304. package/dist/providers/ollama/html-links.js +30 -0
  305. package/dist/providers/ollama/http.d.ts +12 -0
  306. package/dist/providers/ollama/http.js +67 -0
  307. package/dist/providers/ollama/index.d.ts +8 -0
  308. package/dist/providers/ollama/index.js +8 -0
  309. package/dist/providers/ollama/language-model.d.ts +11 -0
  310. package/dist/providers/ollama/language-model.js +62 -0
  311. package/dist/providers/ollama/local-catalog.d.ts +3 -0
  312. package/dist/providers/ollama/local-catalog.js +38 -0
  313. package/dist/providers/ollama/ndjson.d.ts +3 -0
  314. package/dist/providers/ollama/ndjson.js +51 -0
  315. package/dist/providers/ollama/prompt.d.ts +8 -0
  316. package/dist/providers/ollama/prompt.js +141 -0
  317. package/dist/providers/ollama/protocol.d.ts +56 -0
  318. package/dist/providers/ollama/protocol.js +26 -0
  319. package/dist/providers/ollama/runtime.d.ts +11 -0
  320. package/dist/providers/ollama/runtime.js +128 -0
  321. package/dist/providers/ollama/stream.d.ts +8 -0
  322. package/dist/providers/ollama/stream.js +110 -0
  323. package/dist/sdk/command-code.d.ts +5 -0
  324. package/dist/sdk/command-code.js +6 -0
  325. package/dist/sdk/cursor.d.ts +5 -0
  326. package/dist/sdk/cursor.js +6 -0
  327. package/dist/sdk/ollama.d.ts +5 -0
  328. package/dist/sdk/ollama.js +6 -0
  329. package/dist/server.d.ts +12 -0
  330. package/dist/server.js +94 -0
  331. package/docs/README.ko.md +189 -0
  332. package/package.json +75 -0
@@ -0,0 +1,50 @@
1
+ import type { Clock } from "../../core/clock";
2
+ import type { CursorBridgeStream } from "./bridge-client";
3
+ import type { CursorRequestBlobOwnership } from "./request-blob-ownership";
4
+ import { type CursorRunSessionBackgroundCleanupErrorHandler } from "./run-session-expiry";
5
+ import type { CursorServerDispatcher } from "./server-dispatch";
6
+ import type { CursorSessionId } from "./session-state";
7
+ export type CursorRunSessionIdentity = {
8
+ readonly sessionId: CursorSessionId;
9
+ readonly modelId: string;
10
+ };
11
+ export type CursorRunSessionResources = CursorRunSessionIdentity & {
12
+ readonly stream: CursorBridgeStream;
13
+ readonly ownership: CursorRequestBlobOwnership;
14
+ readonly dispatcher: CursorServerDispatcher;
15
+ readonly disposeStores: () => void;
16
+ };
17
+ export type CursorRunSessionErrorReason = "duplicate-session" | "missing-session" | "mismatched-result" | "duplicate-result" | "ambiguous-result" | "retry-boundary";
18
+ export declare class CursorRunSessionError extends Error {
19
+ readonly reason: CursorRunSessionErrorReason;
20
+ readonly name = "CursorRunSessionError";
21
+ readonly code = "CURSOR_RUN_SESSION_ERROR";
22
+ constructor(reason: CursorRunSessionErrorReason);
23
+ }
24
+ export type CursorRunSession = {
25
+ readonly identity: CursorRunSessionIdentity;
26
+ readonly dispatcher: CursorServerDispatcher;
27
+ readonly stream: CursorBridgeStream;
28
+ readonly write: (frame: Uint8Array, signal?: AbortSignal) => Promise<void>;
29
+ readonly writeContinuations: (continuations: readonly {
30
+ readonly callId: string;
31
+ readonly frame: Uint8Array;
32
+ }[], signal?: AbortSignal) => Promise<void>;
33
+ readonly touch: () => void;
34
+ readonly abort: () => Promise<void>;
35
+ readonly retireForRetry?: () => Promise<void>;
36
+ readonly dispose: () => Promise<void>;
37
+ };
38
+ export type CursorRunSessionRegistry = {
39
+ readonly register: (resources: CursorRunSessionResources) => CursorRunSession;
40
+ readonly find: (identity: CursorRunSessionIdentity) => CursorRunSession | null;
41
+ readonly resolveParkedCalls: (callIds: readonly string[], modelId: string) => CursorRunSession;
42
+ readonly terminate: (identity: CursorRunSessionIdentity) => Promise<void>;
43
+ readonly size: () => number;
44
+ readonly dispose: () => Promise<void>;
45
+ };
46
+ export declare function createCursorRunSessionRegistry(_options: {
47
+ readonly clock: Clock;
48
+ readonly ttlMs: number;
49
+ readonly onBackgroundCleanupError: CursorRunSessionBackgroundCleanupErrorHandler;
50
+ }): CursorRunSessionRegistry;
@@ -0,0 +1,205 @@
1
+ import { InvalidArgumentError } from "../../core/errors";
2
+ import { createAsyncDisposable } from "../../core/lifecycle";
3
+ import { settleCursorRunSessionExpiry, } from "./run-session-expiry";
4
+ import { settleCursorCleanup } from "./settle-cleanup";
5
+ export class CursorRunSessionError extends Error {
6
+ reason;
7
+ name = "CursorRunSessionError";
8
+ code = "CURSOR_RUN_SESSION_ERROR";
9
+ constructor(reason) {
10
+ super("Cursor run session continuation failed");
11
+ this.reason = reason;
12
+ }
13
+ }
14
+ export function createCursorRunSessionRegistry(_options) {
15
+ const options = _options;
16
+ if (!Number.isSafeInteger(options.ttlMs) || options.ttlMs < 0) {
17
+ throw new InvalidArgumentError("ttlMs");
18
+ }
19
+ const sessions = new Map();
20
+ const ownersByModel = new Map();
21
+ let disposed = false;
22
+ const removeOwnership = (sessionId) => {
23
+ for (const [modelId, ownersByCallId] of ownersByModel) {
24
+ for (const [callId, owners] of ownersByCallId) {
25
+ owners.delete(sessionId);
26
+ if (owners.size === 0)
27
+ ownersByCallId.delete(callId);
28
+ }
29
+ if (ownersByCallId.size === 0)
30
+ ownersByModel.delete(modelId);
31
+ }
32
+ };
33
+ const terminate = async (identity) => {
34
+ const session = sessions.get(identity.sessionId);
35
+ if (session === undefined)
36
+ return;
37
+ sessions.delete(identity.sessionId);
38
+ removeOwnership(identity.sessionId);
39
+ await session.dispose();
40
+ };
41
+ const register = (resources) => {
42
+ if (disposed)
43
+ throw new CursorRunSessionError("missing-session");
44
+ const identity = {
45
+ sessionId: resources.sessionId,
46
+ modelId: resources.modelId,
47
+ };
48
+ if (sessions.has(identity.sessionId))
49
+ throw new CursorRunSessionError("duplicate-session");
50
+ const consumed = new Set();
51
+ const reserved = new Set();
52
+ let writes = Promise.resolve();
53
+ let timer;
54
+ let streamSettlement = "close";
55
+ let retired = false;
56
+ const cancelTimer = () => {
57
+ timer?.cancel();
58
+ timer = undefined;
59
+ };
60
+ const disposal = createAsyncDisposable(() => {
61
+ cancelTimer();
62
+ removeOwnership(identity.sessionId);
63
+ resources.dispatcher.parkedCalls.clear();
64
+ if (retired)
65
+ return;
66
+ return settleCursorCleanup([
67
+ streamSettlement === "abort" ? resources.stream.abort : resources.stream.close,
68
+ resources.ownership.release,
69
+ resources.disposeStores,
70
+ ]);
71
+ });
72
+ const touch = () => {
73
+ cancelTimer();
74
+ removeOwnership(identity.sessionId);
75
+ const ownersByCallId = ownersByModel.get(identity.modelId) ?? new Map();
76
+ for (const callId of resources.dispatcher.parkedCalls.keys()) {
77
+ const owners = ownersByCallId.get(callId) ?? new Set();
78
+ owners.add(identity.sessionId);
79
+ ownersByCallId.set(callId, owners);
80
+ }
81
+ ownersByModel.set(identity.modelId, ownersByCallId);
82
+ timer = options.clock.schedule(options.ttlMs, () => {
83
+ settleCursorRunSessionExpiry({
84
+ identity,
85
+ terminate,
86
+ onBackgroundCleanupError: options.onBackgroundCleanupError,
87
+ });
88
+ });
89
+ };
90
+ const session = {
91
+ identity,
92
+ dispatcher: resources.dispatcher,
93
+ stream: resources.stream,
94
+ write: (frame, signal) => {
95
+ const operation = writes.then(() => resources.stream.write(frame, signal));
96
+ writes = operation.then(() => undefined, () => undefined);
97
+ return operation;
98
+ },
99
+ writeContinuations: (continuations, signal) => {
100
+ const transactionIds = new Set();
101
+ for (const continuation of continuations) {
102
+ if (consumed.has(continuation.callId) || reserved.has(continuation.callId)) {
103
+ return Promise.reject(new CursorRunSessionError("duplicate-result"));
104
+ }
105
+ if (!resources.dispatcher.parkedCalls.has(continuation.callId)) {
106
+ return Promise.reject(new CursorRunSessionError("mismatched-result"));
107
+ }
108
+ if (transactionIds.has(continuation.callId)) {
109
+ return Promise.reject(new CursorRunSessionError("duplicate-result"));
110
+ }
111
+ transactionIds.add(continuation.callId);
112
+ }
113
+ for (const callId of transactionIds)
114
+ reserved.add(callId);
115
+ cancelTimer();
116
+ removeOwnership(identity.sessionId);
117
+ const operation = writes.then(async () => {
118
+ for (const continuation of continuations) {
119
+ await resources.stream.write(continuation.frame, signal);
120
+ }
121
+ });
122
+ const transaction = operation.then(() => {
123
+ for (const callId of transactionIds) {
124
+ resources.dispatcher.parkedCalls.delete(callId);
125
+ reserved.delete(callId);
126
+ consumed.add(callId);
127
+ }
128
+ }, async (error) => {
129
+ for (const callId of transactionIds)
130
+ reserved.delete(callId);
131
+ try {
132
+ await terminate(identity);
133
+ }
134
+ catch (cleanupError) {
135
+ const message = error instanceof Error ? error.message : "Continuation write failed";
136
+ throw new AggregateError([error, cleanupError], message);
137
+ }
138
+ throw error;
139
+ });
140
+ writes = transaction.then(() => undefined, () => undefined);
141
+ return transaction;
142
+ },
143
+ touch,
144
+ abort: () => {
145
+ streamSettlement = "abort";
146
+ sessions.delete(identity.sessionId);
147
+ removeOwnership(identity.sessionId);
148
+ return disposal.dispose();
149
+ },
150
+ retireForRetry: async () => {
151
+ if (resources.dispatcher.parkedCalls.size > 0 || reserved.size > 0)
152
+ throw new CursorRunSessionError("retry-boundary");
153
+ retired = true;
154
+ cancelTimer();
155
+ sessions.delete(identity.sessionId);
156
+ removeOwnership(identity.sessionId);
157
+ resources.dispatcher.parkedCalls.clear();
158
+ await settleCursorCleanup([resources.stream.abort, resources.ownership.release]);
159
+ },
160
+ dispose: disposal.dispose,
161
+ };
162
+ sessions.set(identity.sessionId, session);
163
+ return session;
164
+ };
165
+ const resolveParkedCalls = (callIds, modelId) => {
166
+ let resolved = null;
167
+ const ownersByCallId = ownersByModel.get(modelId);
168
+ for (const callId of callIds) {
169
+ const owners = ownersByCallId?.get(callId);
170
+ if (owners === undefined)
171
+ throw new CursorRunSessionError("missing-session");
172
+ if (owners.size !== 1)
173
+ throw new CursorRunSessionError("ambiguous-result");
174
+ const sessionId = owners.values().next().value;
175
+ const candidate = sessionId === undefined ? undefined : sessions.get(sessionId);
176
+ if (candidate === undefined)
177
+ throw new CursorRunSessionError("missing-session");
178
+ if (candidate.identity.modelId !== modelId) {
179
+ throw new CursorRunSessionError("mismatched-result");
180
+ }
181
+ if (resolved !== null && resolved !== candidate) {
182
+ throw new CursorRunSessionError("mismatched-result");
183
+ }
184
+ resolved = candidate;
185
+ }
186
+ if (resolved === null)
187
+ throw new CursorRunSessionError("missing-session");
188
+ return resolved;
189
+ };
190
+ const disposal = createAsyncDisposable(async () => {
191
+ disposed = true;
192
+ const active = [...sessions.values()];
193
+ sessions.clear();
194
+ ownersByModel.clear();
195
+ await settleCursorCleanup(active.map((session) => session.dispose));
196
+ });
197
+ return {
198
+ register,
199
+ find: (identity) => sessions.get(identity.sessionId) ?? null,
200
+ resolveParkedCalls,
201
+ terminate,
202
+ size: () => sessions.size,
203
+ dispose: disposal.dispose,
204
+ };
205
+ }
@@ -0,0 +1,9 @@
1
+ import { type CursorHttp2Post } from "./http2";
2
+ import { type CursorMcpTool } from "./mcp-tools";
3
+ export declare function buildCursorRunMessage(modelId: string, prompt: string, tools?: readonly CursorMcpTool[]): Uint8Array;
4
+ export declare function extractCursorTextDeltas(message: Uint8Array): readonly string[];
5
+ export type CursorRunPost = (request: CursorHttp2Post) => Promise<{
6
+ readonly status: number;
7
+ readonly body: Uint8Array;
8
+ }>;
9
+ export declare function streamCursorAssistantNdjson(modelId: string, prompt: string, token: string, signal: AbortSignal, post?: CursorRunPost, tools?: readonly CursorMcpTool[]): AsyncIterable<string>;
@@ -0,0 +1,151 @@
1
+ // Derived from Rahularya01/pi-cursor AgentService/Run Connect framing.
2
+ // Licensed under MIT. See THIRD_PARTY_NOTICES.md.
3
+ import { randomUUID } from "node:crypto";
4
+ import { AdapterError } from "../../core/errors";
5
+ import { parseProviderId } from "../../core/ids";
6
+ import { decodeConnectFrames, decodeConnectFramesWithRest, encodeConnectFrame, } from "./connect-frame";
7
+ import { cursorServerReplies } from "./exec-reply";
8
+ import { cursorHttp2Post, cursorHttp2Stream } from "./http2";
9
+ import { encodeCursorMcpTools } from "./mcp-tools";
10
+ import { concatBytes, decodeUtf8, encodeBytesField, encodeInt32Field, encodeStringField, } from "./proto-wire";
11
+ import { extractCursorRunEvents } from "./run-events";
12
+ export function buildCursorRunMessage(modelId, prompt, tools = []) {
13
+ const messageId = randomUUID();
14
+ const userMessage = concatBytes([
15
+ encodeStringField(1, prompt),
16
+ encodeStringField(2, messageId),
17
+ encodeInt32Field(4, 1),
18
+ encodeStringField(17, messageId),
19
+ ]);
20
+ const action = encodeBytesField(1, encodeBytesField(1, userMessage));
21
+ const conversationState = concatBytes([
22
+ encodeInt32Field(10, 1),
23
+ encodeStringField(22, "opencode"),
24
+ ]);
25
+ const parts = [
26
+ encodeBytesField(1, conversationState),
27
+ encodeBytesField(2, action),
28
+ encodeBytesField(3, encodeStringField(1, modelId)),
29
+ encodeBytesField(4, encodeCursorMcpTools(tools)),
30
+ encodeStringField(5, randomUUID()),
31
+ encodeBytesField(9, encodeStringField(1, modelId)),
32
+ ];
33
+ return encodeBytesField(1, concatBytes(parts));
34
+ }
35
+ export function extractCursorTextDeltas(message) {
36
+ const deltas = [];
37
+ for (const event of extractCursorRunEvents(message)) {
38
+ if (event.kind === "text") {
39
+ deltas.push(event.text);
40
+ }
41
+ }
42
+ return deltas;
43
+ }
44
+ function connectErrorMessage(bytes) {
45
+ const text = decodeUtf8(bytes).trim();
46
+ if (!text.startsWith("{")) {
47
+ return null;
48
+ }
49
+ try {
50
+ const parsed = JSON.parse(text);
51
+ if (typeof parsed !== "object" || parsed === null || !("error" in parsed)) {
52
+ return null;
53
+ }
54
+ const error = Reflect.get(parsed, "error");
55
+ if (typeof error === "object" && error !== null && "message" in error) {
56
+ const message = Reflect.get(error, "message");
57
+ if (typeof message === "string" && message.length > 0) {
58
+ return message;
59
+ }
60
+ }
61
+ }
62
+ catch {
63
+ return null;
64
+ }
65
+ return text.includes('"error"') ? text : null;
66
+ }
67
+ function* ndjsonFromFrames(frames) {
68
+ for (const frame of frames) {
69
+ const errorMessage = connectErrorMessage(frame.bytes);
70
+ if (errorMessage !== null) {
71
+ throw new Error(errorMessage);
72
+ }
73
+ for (const event of extractCursorRunEvents(frame.bytes)) {
74
+ switch (event.kind) {
75
+ case "text":
76
+ yield JSON.stringify({
77
+ type: "assistant",
78
+ message: { content: [{ type: "text", text: event.text }] },
79
+ });
80
+ break;
81
+ case "thinking":
82
+ yield JSON.stringify({ type: "thinking", text: event.text });
83
+ break;
84
+ case "tool":
85
+ yield JSON.stringify({
86
+ type: "tool_call",
87
+ subtype: "started",
88
+ call_id: event.callId,
89
+ name: event.name,
90
+ arguments: event.args,
91
+ });
92
+ break;
93
+ case "turn-ended":
94
+ break;
95
+ }
96
+ }
97
+ }
98
+ }
99
+ export async function* streamCursorAssistantNdjson(modelId, prompt, token, signal, post = cursorHttp2Post, tools = []) {
100
+ let writeFrame = () => undefined;
101
+ const request = {
102
+ path: "/agent.v1.AgentService/Run",
103
+ token,
104
+ body: encodeConnectFrame(buildCursorRunMessage(modelId, prompt, tools)),
105
+ headers: {
106
+ "content-type": "application/connect+proto",
107
+ "connect-protocol-version": "1",
108
+ },
109
+ signal,
110
+ keepOpen: true,
111
+ heartbeat: encodeConnectFrame(encodeBytesField(7, new Uint8Array())),
112
+ onWriter: (write) => {
113
+ writeFrame = write;
114
+ },
115
+ };
116
+ if (post !== cursorHttp2Post) {
117
+ const response = await post(request);
118
+ if (response.status < 200 || response.status >= 300) {
119
+ throw new AdapterError({
120
+ operation: "cursor-run-http",
121
+ retryable: response.status >= 500,
122
+ cause: null,
123
+ providerId: parseProviderId("cursor"),
124
+ });
125
+ }
126
+ yield* ndjsonFromFrames(decodeConnectFrames(response.body));
127
+ yield JSON.stringify({ type: "result", result: "" });
128
+ return;
129
+ }
130
+ let rest = new Uint8Array();
131
+ stream: for await (const chunk of cursorHttp2Stream(request)) {
132
+ const split = decodeConnectFramesWithRest(concatBytes([rest, chunk]));
133
+ rest = new Uint8Array(split.rest);
134
+ for (const frame of split.frames) {
135
+ for (const reply of cursorServerReplies(frame.bytes, tools)) {
136
+ writeFrame(reply);
137
+ }
138
+ }
139
+ for (const line of ndjsonFromFrames(split.frames)) {
140
+ yield line;
141
+ }
142
+ for (const frame of split.frames) {
143
+ for (const event of extractCursorRunEvents(frame.bytes)) {
144
+ if (event.kind === "turn-ended") {
145
+ break stream;
146
+ }
147
+ }
148
+ }
149
+ }
150
+ yield JSON.stringify({ type: "result", result: "" });
151
+ }
@@ -0,0 +1 @@
1
+ export declare function runCursorAgentPrompt(env: Readonly<Record<string, string | undefined>>, prompt: string, signal: AbortSignal, cwd: string, model: string): Promise<string | null>;
@@ -0,0 +1,55 @@
1
+ // Derived from Nomadcxx/opencode-cursor@8e14a26c1e080382f471a729436092ef72edf34e.
2
+ // Licensed under BSD-3-Clause. See THIRD_PARTY_NOTICES.md.
3
+ import { spawn } from "node:child_process";
4
+ import { OperationCancelledError } from "../../core/errors";
5
+ import { resolveCursorAgent } from "./auth";
6
+ import { extractCursorNdjsonText } from "./ndjson";
7
+ export async function runCursorAgentPrompt(env, prompt, signal, cwd, model) {
8
+ if (signal.aborted) {
9
+ throw new OperationCancelledError("cursor-run-prompt");
10
+ }
11
+ const agent = await resolveCursorAgent(env, signal);
12
+ if (agent === null) {
13
+ return null;
14
+ }
15
+ return await new Promise((resolve, reject) => {
16
+ const child = spawn(agent, [
17
+ "--print",
18
+ "--output-format",
19
+ "stream-json",
20
+ "--stream-partial-output",
21
+ "--workspace",
22
+ cwd,
23
+ "--model",
24
+ model,
25
+ ...(env["CURSOR_ACP_FORCE"] === "false" ? [] : ["--force"]),
26
+ ], {
27
+ signal,
28
+ stdio: ["pipe", "pipe", "pipe"],
29
+ });
30
+ const chunks = [];
31
+ child.stdout.on("data", (chunk) => {
32
+ chunks.push(chunk);
33
+ });
34
+ child.once("error", (error) => {
35
+ if (signal.aborted) {
36
+ reject(new OperationCancelledError("cursor-run-prompt"));
37
+ return;
38
+ }
39
+ reject(error);
40
+ });
41
+ child.once("close", (code) => {
42
+ if (signal.aborted) {
43
+ reject(new OperationCancelledError("cursor-run-prompt"));
44
+ return;
45
+ }
46
+ if (code !== 0) {
47
+ resolve(null);
48
+ return;
49
+ }
50
+ resolve(extractCursorNdjsonText(Buffer.concat(chunks).toString("utf8")));
51
+ });
52
+ child.stdin.write(prompt);
53
+ child.stdin.end();
54
+ });
55
+ }
@@ -0,0 +1,83 @@
1
+ import type { CursorBlobStore } from "./blob-store";
2
+ import type { CursorCheckpointStore } from "./checkpoint-store";
3
+ import type { CursorMcpTool } from "./mcp-tools";
4
+ import type { McpArgs } from "./proto/mcp";
5
+ import type { AgentServerMessage } from "./proto/server";
6
+ import type { CursorSessionId } from "./session-state";
7
+ export type ParkedMcpCall = {
8
+ readonly callId: string;
9
+ readonly execId: string;
10
+ readonly execMessageId: number;
11
+ readonly args: McpArgs;
12
+ };
13
+ export type CursorDispatchOutcome = {
14
+ readonly kind: "text";
15
+ readonly text: string;
16
+ } | {
17
+ readonly kind: "thinking";
18
+ readonly text: string;
19
+ } | {
20
+ readonly kind: "tokens";
21
+ readonly tokens: number;
22
+ } | {
23
+ readonly kind: "turn-ended";
24
+ } | {
25
+ readonly kind: "heartbeat";
26
+ } | {
27
+ readonly kind: "telemetry";
28
+ readonly name: string;
29
+ } | {
30
+ readonly kind: "kv-get";
31
+ readonly id: number;
32
+ readonly found: boolean;
33
+ } | {
34
+ readonly kind: "kv-set";
35
+ readonly id: number;
36
+ readonly stored: boolean;
37
+ } | {
38
+ readonly kind: "checkpoint";
39
+ readonly stored: boolean;
40
+ } | {
41
+ readonly kind: "request-context-replied";
42
+ readonly id: number;
43
+ readonly execId: string;
44
+ } | {
45
+ readonly kind: "mcp-parked";
46
+ readonly parked: ParkedMcpCall;
47
+ } | {
48
+ readonly kind: "mcp-rejected";
49
+ readonly callId: string;
50
+ } | {
51
+ readonly kind: "native-rejected";
52
+ readonly operation: string;
53
+ } | {
54
+ readonly kind: "interaction-replied";
55
+ readonly id: number;
56
+ readonly action: "rejected" | "acked";
57
+ } | {
58
+ readonly kind: "control";
59
+ readonly control: "abort";
60
+ readonly id: number;
61
+ } | {
62
+ readonly kind: "drift";
63
+ readonly area: "server-message" | "mcp-call";
64
+ readonly detail: string;
65
+ readonly stranding: boolean;
66
+ };
67
+ export type CursorDispatchResult = {
68
+ readonly outcome: CursorDispatchOutcome;
69
+ readonly replyFrames: readonly Uint8Array[];
70
+ readonly closeStream: boolean;
71
+ };
72
+ export type CursorServerDispatcherOptions = {
73
+ readonly blobStore: CursorBlobStore;
74
+ readonly checkpointStore: CursorCheckpointStore;
75
+ readonly sessionId: CursorSessionId;
76
+ readonly tools: readonly CursorMcpTool[];
77
+ };
78
+ export type CursorServerDispatcher = {
79
+ readonly dispatch: (message: AgentServerMessage) => CursorDispatchResult;
80
+ readonly dispatchBytes: (bytes: Uint8Array) => CursorDispatchResult;
81
+ /** Mutable unresolved-call state; retirement is part of successful continuation commit. */
82
+ readonly parkedCalls: Map<string, ParkedMcpCall>;
83
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { CursorServerDispatcher, CursorServerDispatcherOptions } from "./server-dispatch-types";
2
+ export type { CursorDispatchOutcome, CursorDispatchResult, CursorServerDispatcher, CursorServerDispatcherOptions, ParkedMcpCall, } from "./server-dispatch-types";
3
+ export declare function createCursorServerDispatcher(options: CursorServerDispatcherOptions): CursorServerDispatcher;