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,39 @@
1
+ export class CursorRequestBlobOwnershipError extends Error {
2
+ constructor() {
3
+ super("Cursor request blob ownership could not acquire content");
4
+ this.name = "CursorRequestBlobOwnershipError";
5
+ }
6
+ }
7
+ export function createCursorRequestBlobCollector(store) {
8
+ const blobIds = [];
9
+ let state = "collecting";
10
+ const release = () => {
11
+ if (state === "released")
12
+ return;
13
+ state = "released";
14
+ for (const blobId of blobIds)
15
+ store.release(blobId);
16
+ };
17
+ return {
18
+ acquire: (blobId) => {
19
+ if (state !== "collecting")
20
+ throw new CursorRequestBlobOwnershipError();
21
+ if (blobIds.includes(blobId))
22
+ return;
23
+ if (!store.pin(blobId))
24
+ throw new CursorRequestBlobOwnershipError();
25
+ blobIds.push(blobId);
26
+ },
27
+ finish: () => {
28
+ if (state !== "collecting")
29
+ throw new CursorRequestBlobOwnershipError();
30
+ state = "owned";
31
+ return Object.freeze({
32
+ blobIds: Object.freeze([...blobIds]),
33
+ release,
34
+ [Symbol.dispose]: release,
35
+ });
36
+ },
37
+ rollback: release,
38
+ };
39
+ }
@@ -0,0 +1,18 @@
1
+ import type { CursorBlobId, CursorBlobStore } from "./blob-store";
2
+ import type { CursorCheckpointStore } from "./checkpoint-store";
3
+ import { type CursorRequestBlobOwnership } from "./request-blob-ownership";
4
+ export type CursorAgentRunBuildDependencies = {
5
+ readonly blobStore: CursorBlobStore;
6
+ readonly checkpointStore: CursorCheckpointStore;
7
+ readonly createId: () => string;
8
+ readonly input: unknown;
9
+ };
10
+ export type CursorAgentRunBuildResult = {
11
+ readonly kind: "fresh" | "checkpoint";
12
+ readonly bytes: Uint8Array;
13
+ readonly blobIds: readonly CursorBlobId[];
14
+ readonly conversationId: string;
15
+ readonly ownership: CursorRequestBlobOwnership;
16
+ };
17
+ export declare function normalizeCursorRootPrompt(prompt: string): Uint8Array;
18
+ export declare function buildCursorAgentRunRequest(dependencies: CursorAgentRunBuildDependencies): CursorAgentRunBuildResult;
@@ -0,0 +1,123 @@
1
+ // Derived from Rahularya01/pi-cursor v1.4.26 request-build.ts. Licensed under MIT.
2
+ // See THIRD_PARTY_NOTICES.md.
3
+ import { InvalidArgumentError } from "../../core/errors";
4
+ import { decodeConversationCheckpoint } from "./proto/checkpoint";
5
+ import { encodeAgentClientMessage } from "./proto/request";
6
+ import { createCursorRequestBlobCollector, } from "./request-blob-ownership";
7
+ import { buildCursorSelectedContextBlob, buildCursorUserMessage, normalizeCursorRootPromptBytes, storeCursorHistory, storeCursorRequestBlob, } from "./request-history";
8
+ import { parseCursorRunBuildInput } from "./request-input";
9
+ function emptyCheckpoint(rootPromptBlobIds, turnBlobIds) {
10
+ return {
11
+ rootPromptMessageBlobIds: rootPromptBlobIds,
12
+ legacyTurnBlobIds: [],
13
+ todoBlobIds: [],
14
+ pendingToolCalls: [],
15
+ turnBlobIds,
16
+ previousWorkspaceUris: [],
17
+ mode: 1,
18
+ fileStates: [],
19
+ summaryArchiveBlobIds: [],
20
+ turnTimingMessages: [],
21
+ fileStatesV2: [],
22
+ subagentStates: [],
23
+ selfSummaryCount: 0,
24
+ readPaths: [],
25
+ trackedGitRepoBranches: [],
26
+ clientName: "opencode",
27
+ };
28
+ }
29
+ function buildAction(input, context) {
30
+ switch (input.action.kind) {
31
+ case "user":
32
+ return {
33
+ kind: "user-message",
34
+ userMessage: buildCursorUserMessage(input.action, context),
35
+ };
36
+ case "resume":
37
+ return { kind: "resume", payload: new Uint8Array() };
38
+ case "cancel":
39
+ return { kind: "cancel", payload: new Uint8Array() };
40
+ }
41
+ }
42
+ function checkpointState(input, checkpointStore, store, ownership) {
43
+ const checkpoint = checkpointStore.resume(input.sessionId);
44
+ if (checkpoint === null)
45
+ throw new InvalidArgumentError("checkpoint");
46
+ for (const blobId of checkpoint.blobIds)
47
+ ownership.acquire(blobId);
48
+ const state = decodeConversationCheckpoint(checkpoint.bytes);
49
+ const systemBytes = new TextEncoder().encode(JSON.stringify({
50
+ role: "system",
51
+ content: input.rootSystemPrompt.replace(/\r\n?/g, "\n").trim(),
52
+ }));
53
+ const systemBlobId = storeCursorRequestBlob(store, ownership, systemBytes);
54
+ const selectedContextBlob = storeCursorRequestBlob(store, ownership, buildCursorSelectedContextBlob(systemBlobId));
55
+ if (input.refreshRootPrompt !== true)
56
+ return { state, selectedContextBlob };
57
+ return {
58
+ state: {
59
+ ...state,
60
+ rootPromptMessageBlobIds: [
61
+ ...state.rootPromptMessageBlobIds,
62
+ storeCursorRequestBlob(store, ownership, normalizeCursorRootPromptBytes(input.rootSystemPrompt)),
63
+ ],
64
+ },
65
+ selectedContextBlob,
66
+ };
67
+ }
68
+ export function normalizeCursorRootPrompt(prompt) {
69
+ return normalizeCursorRootPromptBytes(prompt);
70
+ }
71
+ export function buildCursorAgentRunRequest(dependencies) {
72
+ const input = parseCursorRunBuildInput(dependencies.input);
73
+ const ownership = createCursorRequestBlobCollector(dependencies.blobStore);
74
+ const ids = { create: dependencies.createId };
75
+ try {
76
+ const prepared = input.mode === "fresh"
77
+ ? (() => {
78
+ const history = storeCursorHistory({
79
+ turns: input.history,
80
+ systemPrompt: input.rootSystemPrompt.replace(/\r\n?/g, "\n").trim(),
81
+ store: dependencies.blobStore,
82
+ ownership,
83
+ ids,
84
+ });
85
+ return {
86
+ state: emptyCheckpoint(history.rootPromptBlobIds, history.turnBlobIds),
87
+ selectedContextBlob: history.selectedContextBlob,
88
+ };
89
+ })()
90
+ : checkpointState(input, dependencies.checkpointStore, dependencies.blobStore, ownership);
91
+ const bytes = encodeAgentClientMessage({
92
+ kind: "run-request",
93
+ request: {
94
+ conversationState: prepared.state,
95
+ action: buildAction(input, {
96
+ selectedContextBlob: prepared.selectedContextBlob,
97
+ store: dependencies.blobStore,
98
+ ownership,
99
+ ids,
100
+ }),
101
+ mcpTools: input.mcpTools,
102
+ conversationId: input.conversationId,
103
+ requestedModel: {
104
+ modelId: input.modelId,
105
+ maxMode: input.maxMode ?? false,
106
+ parameters: input.modelParameters,
107
+ },
108
+ },
109
+ });
110
+ const owned = ownership.finish();
111
+ return Object.freeze({
112
+ kind: input.mode,
113
+ bytes: new Uint8Array(bytes),
114
+ blobIds: owned.blobIds,
115
+ conversationId: input.conversationId,
116
+ ownership: owned,
117
+ });
118
+ }
119
+ catch (error) {
120
+ ownership.rollback();
121
+ throw error;
122
+ }
123
+ }
@@ -0,0 +1,32 @@
1
+ import type { CursorBlobStore } from "./blob-store";
2
+ import type { UserMessage } from "./proto/context";
3
+ import type { CursorRequestBlobCollector } from "./request-blob-ownership";
4
+ import type { CursorRunMessage, CursorRunTurn } from "./request-input";
5
+ export type CursorRequestIds = {
6
+ readonly create: () => string;
7
+ };
8
+ export type CursorStoredHistory = {
9
+ readonly rootPromptBlobIds: readonly Uint8Array[];
10
+ readonly turnBlobIds: readonly Uint8Array[];
11
+ };
12
+ export declare function storeCursorRequestBlob(store: CursorBlobStore, ownership: CursorRequestBlobCollector, bytes: Uint8Array): Uint8Array;
13
+ export declare class CursorRequestBlobError extends Error {
14
+ constructor();
15
+ }
16
+ export declare function normalizeCursorRootPromptBytes(prompt: string): Uint8Array;
17
+ export declare function buildCursorSelectedContextBlob(systemBlobId: Uint8Array): Uint8Array;
18
+ export declare function buildCursorUserMessage(message: CursorRunMessage, context: {
19
+ readonly selectedContextBlob: Uint8Array;
20
+ readonly store: CursorBlobStore;
21
+ readonly ownership: CursorRequestBlobCollector;
22
+ readonly ids: CursorRequestIds;
23
+ }): UserMessage;
24
+ export declare function storeCursorHistory(input: {
25
+ readonly turns: readonly CursorRunTurn[];
26
+ readonly systemPrompt: string;
27
+ readonly store: CursorBlobStore;
28
+ readonly ownership: CursorRequestBlobCollector;
29
+ readonly ids: CursorRequestIds;
30
+ }): CursorStoredHistory & {
31
+ readonly selectedContextBlob: Uint8Array;
32
+ };
@@ -0,0 +1,163 @@
1
+ // Derived from Rahularya01/pi-cursor v1.4.26 request-build.ts. Licensed under MIT.
2
+ // See THIRD_PARTY_NOTICES.md.
3
+ import { encodeMcpArgs, encodeMcpResult } from "./proto/mcp";
4
+ import { concatBytes, encodeBytesField, encodeStringField } from "./proto-wire";
5
+ function wireId(blobId) {
6
+ return new Uint8Array(Buffer.from(blobId, "hex"));
7
+ }
8
+ export function storeCursorRequestBlob(store, ownership, bytes) {
9
+ const blobId = store.put(bytes);
10
+ if (blobId === null)
11
+ throw new CursorRequestBlobError();
12
+ ownership.acquire(blobId);
13
+ return wireId(blobId);
14
+ }
15
+ export class CursorRequestBlobError extends Error {
16
+ constructor() {
17
+ super("Cursor request blob store rejected content");
18
+ this.name = "CursorRequestBlobError";
19
+ }
20
+ }
21
+ export function normalizeCursorRootPromptBytes(prompt) {
22
+ const normalized = prompt.replace(/\r\n?/g, "\n").trim();
23
+ const message = {
24
+ role: "user",
25
+ content: [{ type: "text", text: `<rules>\n${normalized}\n</rules>` }],
26
+ };
27
+ return new TextEncoder().encode(JSON.stringify(message));
28
+ }
29
+ export function buildCursorSelectedContextBlob(systemBlobId) {
30
+ return concatBytes([encodeBytesField(1, systemBlobId), encodeStringField(22, "opencode")]);
31
+ }
32
+ export function buildCursorUserMessage(message, context) {
33
+ const messageId = context.ids.create();
34
+ return {
35
+ text: message.text,
36
+ messageId,
37
+ selectedContext: {
38
+ selectedImages: message.images.map((image) => ({
39
+ uuid: context.ids.create(),
40
+ path: "",
41
+ mimeType: image.mimeType,
42
+ data: {
43
+ kind: "blob-id",
44
+ bytes: storeCursorRequestBlob(context.store, context.ownership, image.data),
45
+ },
46
+ })),
47
+ extraContext: [...(message.selectedContext ?? [])],
48
+ },
49
+ mode: 1,
50
+ selectedContextBlob: context.selectedContextBlob,
51
+ correlationId: messageId,
52
+ };
53
+ }
54
+ function encodeStep(step) {
55
+ switch (step.kind) {
56
+ case "assistant":
57
+ return encodeBytesField(1, encodeStringField(1, step.text));
58
+ case "thinking":
59
+ return encodeBytesField(3, encodeStringField(1, step.text));
60
+ case "tool": {
61
+ const args = encodeBytesField(1, encodeMcpArgs({
62
+ name: step.toolName,
63
+ args: step.arguments,
64
+ toolCallId: step.toolCallId,
65
+ providerIdentifier: "opencode",
66
+ toolName: step.toolName,
67
+ }));
68
+ const result = step.result === undefined
69
+ ? []
70
+ : [
71
+ encodeBytesField(2, encodeMcpResult(step.result.kind === "success" ? { ...step.result, isError: false } : step.result)),
72
+ ];
73
+ return encodeBytesField(2, encodeBytesField(15, concatBytes([args, ...result])));
74
+ }
75
+ }
76
+ }
77
+ function rootMessages(turn) {
78
+ const messages = [{ role: "user", content: [{ type: "text", text: turn.user.text }] }];
79
+ for (const step of turn.steps) {
80
+ switch (step.kind) {
81
+ case "assistant":
82
+ messages.push({ role: "assistant", content: [{ type: "text", text: step.text }] });
83
+ break;
84
+ case "thinking":
85
+ break;
86
+ case "tool":
87
+ messages.push({
88
+ role: "assistant",
89
+ content: [
90
+ {
91
+ type: "tool-call",
92
+ toolCallId: step.toolCallId,
93
+ toolName: `mcp_opencode_${step.toolName}`,
94
+ args: step.arguments,
95
+ },
96
+ ],
97
+ });
98
+ if (step.result !== undefined)
99
+ messages.push({
100
+ role: "tool",
101
+ content: [
102
+ {
103
+ type: "tool-result",
104
+ toolCallId: step.toolCallId,
105
+ toolName: `mcp_opencode_${step.toolName}`,
106
+ result: step.result,
107
+ },
108
+ ],
109
+ });
110
+ break;
111
+ }
112
+ }
113
+ return messages;
114
+ }
115
+ export function storeCursorHistory(input) {
116
+ const systemBytes = new TextEncoder().encode(JSON.stringify({ role: "system", content: input.systemPrompt }));
117
+ const systemBlobId = storeCursorRequestBlob(input.store, input.ownership, systemBytes);
118
+ const selectedContextBlob = storeCursorRequestBlob(input.store, input.ownership, buildCursorSelectedContextBlob(systemBlobId));
119
+ const rootPromptBlobIds = [
120
+ systemBlobId,
121
+ storeCursorRequestBlob(input.store, input.ownership, normalizeCursorRootPromptBytes(input.systemPrompt)),
122
+ ];
123
+ const turnBlobIds = input.turns.map((turn) => {
124
+ const userMessage = buildCursorUserMessage(turn.user, {
125
+ selectedContextBlob,
126
+ store: input.store,
127
+ ownership: input.ownership,
128
+ ids: input.ids,
129
+ });
130
+ const userBlob = storeCursorRequestBlob(input.store, input.ownership, encodeCursorUserMessage(userMessage));
131
+ const steps = turn.steps.map((step) => storeCursorRequestBlob(input.store, input.ownership, encodeStep(step)));
132
+ for (const message of rootMessages(turn))
133
+ rootPromptBlobIds.push(storeCursorRequestBlob(input.store, input.ownership, new TextEncoder().encode(JSON.stringify(message))));
134
+ return storeCursorRequestBlob(input.store, input.ownership, encodeBytesField(1, concatBytes([
135
+ encodeBytesField(1, userBlob),
136
+ ...steps.map((value) => encodeBytesField(2, value)),
137
+ encodeStringField(3, input.ids.create()),
138
+ ])));
139
+ });
140
+ return { rootPromptBlobIds, turnBlobIds, selectedContextBlob };
141
+ }
142
+ function encodeCursorUserMessage(message) {
143
+ const selected = message.selectedContext;
144
+ return concatBytes([
145
+ encodeStringField(1, message.text),
146
+ encodeStringField(2, message.messageId),
147
+ ...(selected === undefined
148
+ ? []
149
+ : [
150
+ encodeBytesField(3, concatBytes([
151
+ ...selected.selectedImages.map((image) => encodeBytesField(1, concatBytes([
152
+ encodeBytesField(1, image.data.kind === "blob-id" ? image.data.bytes : new Uint8Array()),
153
+ encodeStringField(2, image.uuid),
154
+ encodeStringField(7, image.mimeType),
155
+ ]))),
156
+ ...selected.extraContext.map((value) => encodeStringField(3, value)),
157
+ ])),
158
+ ]),
159
+ new Uint8Array([0x20, 0x01]),
160
+ encodeBytesField(10, message.selectedContextBlob),
161
+ encodeStringField(17, message.correlationId),
162
+ ]);
163
+ }
@@ -0,0 +1,75 @@
1
+ import { z } from "zod";
2
+ import { type ModelId } from "../../core/ids";
3
+ import type { McpToolDefinition } from "./proto/mcp";
4
+ import type { RequestedModelParameter } from "./proto/model";
5
+ import { type CursorSessionId } from "./session-state";
6
+ type CursorJson = string | number | boolean | null | readonly CursorJson[] | {
7
+ readonly [key: string]: CursorJson;
8
+ };
9
+ export type CursorRunImage = {
10
+ readonly data: Uint8Array;
11
+ readonly mimeType: string;
12
+ };
13
+ export type CursorRunMessage = {
14
+ readonly text: string;
15
+ readonly images: readonly CursorRunImage[];
16
+ readonly selectedContext?: readonly string[] | undefined;
17
+ };
18
+ export type CursorRunResultContent = {
19
+ readonly kind: "text";
20
+ readonly text: string;
21
+ } | (CursorRunImage & {
22
+ readonly kind: "image";
23
+ });
24
+ export type CursorRunToolResult = {
25
+ readonly kind: "success";
26
+ readonly content: readonly CursorRunResultContent[];
27
+ } | {
28
+ readonly kind: "error";
29
+ readonly error: string;
30
+ };
31
+ export type CursorRunStep = {
32
+ readonly kind: "assistant";
33
+ readonly text: string;
34
+ } | {
35
+ readonly kind: "thinking";
36
+ readonly text: string;
37
+ } | {
38
+ readonly kind: "tool";
39
+ readonly arguments: Readonly<Record<string, CursorJson>>;
40
+ readonly result?: CursorRunToolResult | undefined;
41
+ readonly toolCallId: string;
42
+ readonly toolName: string;
43
+ };
44
+ export type CursorRunTurn = {
45
+ readonly user: CursorRunMessage;
46
+ readonly steps: readonly CursorRunStep[];
47
+ };
48
+ type CursorRunBase = {
49
+ readonly conversationId: CursorSessionId;
50
+ readonly history: readonly CursorRunTurn[];
51
+ readonly maxMode?: boolean | undefined;
52
+ readonly mcpTools: readonly McpToolDefinition[];
53
+ readonly modelId: ModelId;
54
+ readonly modelParameters: readonly RequestedModelParameter[];
55
+ readonly refreshRootPrompt?: boolean | undefined;
56
+ readonly rootSystemPrompt: string;
57
+ };
58
+ type CursorUserAction = CursorRunMessage & {
59
+ readonly kind: "user";
60
+ };
61
+ export type CursorRunBuildInput = (CursorRunBase & {
62
+ readonly mode: "fresh";
63
+ readonly action: CursorUserAction;
64
+ }) | (CursorRunBase & {
65
+ readonly mode: "checkpoint";
66
+ readonly sessionId: CursorSessionId;
67
+ readonly action: CursorUserAction | {
68
+ readonly kind: "resume";
69
+ } | {
70
+ readonly kind: "cancel";
71
+ };
72
+ });
73
+ export declare const CursorRunBuildInputSchema: z.ZodType<CursorRunBuildInput>;
74
+ export declare function parseCursorRunBuildInput(input: unknown): CursorRunBuildInput;
75
+ export {};
@@ -0,0 +1,123 @@
1
+ import { z } from "zod";
2
+ import { ModelIdSchema } from "../../core/ids";
3
+ import { CursorSessionIdSchema } from "./session-state";
4
+ const BytesSchema = z.instanceof(Uint8Array);
5
+ const ImageSchema = z
6
+ .object({ data: BytesSchema, mimeType: z.string().min(1).max(256) })
7
+ .strict()
8
+ .readonly();
9
+ const SelectedContextSchema = z
10
+ .array(z.string().min(1))
11
+ .max(128)
12
+ .readonly();
13
+ const MessageSchema = z
14
+ .object({
15
+ text: z.string(),
16
+ images: z.array(ImageSchema).max(32).readonly(),
17
+ selectedContext: SelectedContextSchema.optional(),
18
+ })
19
+ .strict()
20
+ .readonly();
21
+ const ResultContentSchema = z.discriminatedUnion("kind", [
22
+ z
23
+ .object({ kind: z.literal("text"), text: z.string() })
24
+ .strict()
25
+ .readonly(),
26
+ z
27
+ .object({ kind: z.literal("image"), data: BytesSchema, mimeType: z.string().min(1) })
28
+ .strict()
29
+ .readonly(),
30
+ ]);
31
+ const ToolResultSchema = z.discriminatedUnion("kind", [
32
+ z
33
+ .object({ kind: z.literal("success"), content: z.array(ResultContentSchema).readonly() })
34
+ .strict()
35
+ .readonly(),
36
+ z
37
+ .object({ kind: z.literal("error"), error: z.string() })
38
+ .strict()
39
+ .readonly(),
40
+ ]);
41
+ const StepSchema = z.discriminatedUnion("kind", [
42
+ z
43
+ .object({ kind: z.literal("assistant"), text: z.string() })
44
+ .strict()
45
+ .readonly(),
46
+ z
47
+ .object({ kind: z.literal("thinking"), text: z.string() })
48
+ .strict()
49
+ .readonly(),
50
+ z
51
+ .object({
52
+ kind: z.literal("tool"),
53
+ arguments: z.record(z.string(), z.json()),
54
+ result: ToolResultSchema.optional(),
55
+ toolCallId: z.string().min(1),
56
+ toolName: z.string().min(1),
57
+ })
58
+ .strict()
59
+ .readonly(),
60
+ ]);
61
+ const TurnSchema = z
62
+ .object({ user: MessageSchema, steps: z.array(StepSchema).readonly() })
63
+ .strict()
64
+ .readonly();
65
+ const McpToolSchema = z
66
+ .object({
67
+ name: z.string().min(1),
68
+ description: z.string(),
69
+ inputSchema: z.json(),
70
+ providerIdentifier: z.string().min(1),
71
+ toolName: z.string().min(1),
72
+ })
73
+ .strict()
74
+ .readonly();
75
+ const UserActionSchema = z
76
+ .object({
77
+ kind: z.literal("user"),
78
+ text: z.string(),
79
+ images: z.array(ImageSchema).max(32).readonly(),
80
+ selectedContext: SelectedContextSchema.optional(),
81
+ })
82
+ .strict()
83
+ .readonly();
84
+ const BaseShape = {
85
+ conversationId: CursorSessionIdSchema,
86
+ history: z.array(TurnSchema).readonly(),
87
+ maxMode: z.boolean().optional(),
88
+ mcpTools: z.array(McpToolSchema).readonly(),
89
+ modelId: ModelIdSchema,
90
+ modelParameters: z
91
+ .array(z.object({ id: z.string(), value: z.string() }).strict().readonly())
92
+ .readonly(),
93
+ refreshRootPrompt: z.boolean().optional(),
94
+ rootSystemPrompt: z.string(),
95
+ };
96
+ export const CursorRunBuildInputSchema = z.discriminatedUnion("mode", [
97
+ z
98
+ .object({ ...BaseShape, mode: z.literal("fresh"), action: UserActionSchema })
99
+ .strict()
100
+ .readonly(),
101
+ z
102
+ .object({
103
+ ...BaseShape,
104
+ mode: z.literal("checkpoint"),
105
+ sessionId: CursorSessionIdSchema,
106
+ action: z.union([
107
+ UserActionSchema,
108
+ z
109
+ .object({ kind: z.literal("resume") })
110
+ .strict()
111
+ .readonly(),
112
+ z
113
+ .object({ kind: z.literal("cancel") })
114
+ .strict()
115
+ .readonly(),
116
+ ]),
117
+ })
118
+ .strict()
119
+ .readonly(),
120
+ ]);
121
+ export function parseCursorRunBuildInput(input) {
122
+ return CursorRunBuildInputSchema.parse(input);
123
+ }
@@ -0,0 +1,15 @@
1
+ export type CursorRunEvent = {
2
+ readonly kind: "text";
3
+ readonly text: string;
4
+ } | {
5
+ readonly kind: "thinking";
6
+ readonly text: string;
7
+ } | {
8
+ readonly kind: "turn-ended";
9
+ } | {
10
+ readonly kind: "tool";
11
+ readonly callId: string;
12
+ readonly name: string;
13
+ readonly args: unknown;
14
+ };
15
+ export declare function extractCursorRunEvents(bytes: Uint8Array): readonly CursorRunEvent[];
@@ -0,0 +1,43 @@
1
+ // Derived from Rahularya01/pi-cursor AgentServerMessage interaction updates.
2
+ // Licensed under MIT. See THIRD_PARTY_NOTICES.md.
3
+ import { decodeAgentServerMessage } from "./proto/server";
4
+ function eventFromUpdate(update) {
5
+ switch (update.kind) {
6
+ case "text-delta":
7
+ return update.text === "" ? null : { kind: "text", text: update.text };
8
+ case "thinking-delta":
9
+ return update.text === "" ? null : { kind: "thinking", text: update.text };
10
+ case "turn-ended":
11
+ return { kind: "turn-ended" };
12
+ case "tool-call-started": {
13
+ const name = update.args.toolName || update.args.name;
14
+ return update.callId === "" || name === ""
15
+ ? null
16
+ : { kind: "tool", callId: update.callId, name, args: update.args.args };
17
+ }
18
+ case "tool-call-completed":
19
+ case "thinking-completed":
20
+ case "user-message-appended":
21
+ case "partial-tool-call":
22
+ case "token-delta":
23
+ case "summary":
24
+ case "summary-started":
25
+ case "summary-completed":
26
+ case "shell-output-delta":
27
+ case "heartbeat":
28
+ case "tool-call-delta":
29
+ case "step-started":
30
+ case "step-completed":
31
+ case "field-25":
32
+ return null;
33
+ default:
34
+ return update;
35
+ }
36
+ }
37
+ export function extractCursorRunEvents(bytes) {
38
+ const message = decodeAgentServerMessage(bytes);
39
+ if (message.kind !== "interaction-update")
40
+ return [];
41
+ const event = eventFromUpdate(message.update);
42
+ return event === null ? [] : [event];
43
+ }
@@ -0,0 +1,15 @@
1
+ import type { CursorRunSessionIdentity } from "./run-session";
2
+ export type CursorRunSessionBackgroundCleanupErrorHandler = (error: CursorRunSessionTtlCleanupError) => void | Promise<void>;
3
+ export declare class CursorRunSessionTtlCleanupError extends Error {
4
+ readonly identity: CursorRunSessionIdentity;
5
+ readonly cause: AggregateError;
6
+ readonly name = "CursorRunSessionTtlCleanupError";
7
+ readonly code = "CURSOR_RUN_SESSION_TTL_CLEANUP_ERROR";
8
+ readonly operation = "ttl-expiration";
9
+ constructor(identity: CursorRunSessionIdentity, cause: AggregateError);
10
+ }
11
+ export declare function settleCursorRunSessionExpiry(options: {
12
+ readonly identity: CursorRunSessionIdentity;
13
+ readonly terminate: (identity: CursorRunSessionIdentity) => Promise<void>;
14
+ readonly onBackgroundCleanupError: CursorRunSessionBackgroundCleanupErrorHandler;
15
+ }): void;
@@ -0,0 +1,21 @@
1
+ export class CursorRunSessionTtlCleanupError extends Error {
2
+ identity;
3
+ cause;
4
+ name = "CursorRunSessionTtlCleanupError";
5
+ code = "CURSOR_RUN_SESSION_TTL_CLEANUP_ERROR";
6
+ operation = "ttl-expiration";
7
+ constructor(identity, cause) {
8
+ super("Cursor Run session TTL cleanup failed", { cause });
9
+ this.identity = identity;
10
+ this.cause = cause;
11
+ }
12
+ }
13
+ export function settleCursorRunSessionExpiry(options) {
14
+ const reported = options.terminate(options.identity).catch((cause) => {
15
+ const aggregateCause = cause instanceof AggregateError
16
+ ? cause
17
+ : new AggregateError([cause], "Cursor Run session TTL cleanup failed");
18
+ return options.onBackgroundCleanupError(new CursorRunSessionTtlCleanupError(options.identity, aggregateCause));
19
+ });
20
+ void Promise.allSettled([reported]);
21
+ }