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,33 @@
1
+ import { OperationCancelledError } from "../../core/errors";
2
+ import { commandCodeResponseBodyTooLargeError } from "./errors";
3
+ export { commandCodeHttpError } from "./errors";
4
+ const MAX_ERROR_BODY_BYTES = 64 * 1024;
5
+ export function createCommandCodeRequestLifecycle(parent, timeoutMs) {
6
+ const controller = new AbortController();
7
+ const abort = () => {
8
+ if (!controller.signal.aborted) {
9
+ controller.abort(new OperationCancelledError("command-code-stream"));
10
+ }
11
+ };
12
+ parent?.addEventListener("abort", abort, { once: true });
13
+ const handle = setTimeout(abort, timeoutMs);
14
+ handle.unref();
15
+ const dispose = () => {
16
+ clearTimeout(handle);
17
+ parent?.removeEventListener("abort", abort);
18
+ };
19
+ return { signal: controller.signal, abort, dispose };
20
+ }
21
+ export async function readCommandCodeErrorBody(chunks) {
22
+ const decoder = new TextDecoder();
23
+ let result = "";
24
+ let byteLength = 0;
25
+ for await (const chunk of chunks) {
26
+ byteLength += chunk.byteLength;
27
+ if (byteLength > MAX_ERROR_BODY_BYTES) {
28
+ throw commandCodeResponseBodyTooLargeError();
29
+ }
30
+ result += decoder.decode(chunk, { stream: true });
31
+ }
32
+ return result + decoder.decode();
33
+ }
@@ -0,0 +1,14 @@
1
+ import type { LanguageModelV3CallOptions } from "@ai-sdk/provider";
2
+ import type { CommandCodeSessionId } from "./session";
3
+ export type BuildHeadersOptions = {
4
+ readonly token: string;
5
+ readonly cliVersion: string;
6
+ readonly sessionId: CommandCodeSessionId;
7
+ };
8
+ export type BuildBodyOptions = {
9
+ readonly modelId: string;
10
+ readonly call: LanguageModelV3CallOptions;
11
+ readonly sessionId: CommandCodeSessionId;
12
+ };
13
+ export declare function buildHeaders(options: BuildHeadersOptions): Record<string, string>;
14
+ export declare function buildBody(options: BuildBodyOptions): Record<string, unknown>;
@@ -0,0 +1,167 @@
1
+ // Derived from brent-weatherall/opencode-commandcode-provider src/convert.ts.
2
+ // Licensed under MIT. See THIRD_PARTY_NOTICES.md.
3
+ import { randomBytes } from "node:crypto";
4
+ export function buildHeaders(options) {
5
+ const { token, cliVersion, sessionId } = options;
6
+ return {
7
+ accept: "application/json, */*",
8
+ "accept-encoding": "gzip, deflate, br",
9
+ "accept-language": "en-US,en;q=0.9",
10
+ authorization: `Bearer ${token}`,
11
+ connection: "keep-alive",
12
+ "content-type": "application/json",
13
+ traceparent: `00-${randomBytes(16).toString("hex")}-${randomBytes(8).toString("hex")}-01`,
14
+ "user-agent": `commandcode-cli/${cliVersion} Node.js/${process.version}`,
15
+ "x-cli-environment": "production",
16
+ "x-co-flag": "false",
17
+ "x-command-code-version": cliVersion,
18
+ "x-project-slug": "opencode",
19
+ "x-session-id": sessionId,
20
+ "x-taste-learning": "false",
21
+ };
22
+ }
23
+ function imageData(data, mediaType) {
24
+ if (data instanceof URL) {
25
+ return data.toString();
26
+ }
27
+ const encoded = typeof data === "string" ? data : Buffer.from(data).toString("base64");
28
+ return `data:${mediaType};base64,${encoded}`;
29
+ }
30
+ function toolResultOutput(output) {
31
+ switch (output.type) {
32
+ case "text":
33
+ case "error-text":
34
+ return { type: output.type, value: output.value };
35
+ case "json":
36
+ return { type: "text", value: JSON.stringify(output.value) };
37
+ case "error-json":
38
+ return { type: "error-text", value: JSON.stringify(output.value) };
39
+ case "execution-denied":
40
+ return { type: "error-text", value: output.reason ?? "Execution denied" };
41
+ case "content":
42
+ return {
43
+ type: "text",
44
+ value: output.value
45
+ .map((part) => "text" in part && typeof part.text === "string" ? part.text : JSON.stringify(part))
46
+ .join("\n"),
47
+ };
48
+ }
49
+ }
50
+ function messagesFromCall(call) {
51
+ const messages = [];
52
+ const system = [];
53
+ for (const message of call.prompt) {
54
+ if (message.role === "system") {
55
+ system.push(message.content);
56
+ continue;
57
+ }
58
+ if (message.role === "user") {
59
+ const content = [];
60
+ for (const part of message.content) {
61
+ switch (part.type) {
62
+ case "text":
63
+ content.push({ type: "text", text: part.text });
64
+ break;
65
+ case "file":
66
+ if (part.mediaType.startsWith("image/")) {
67
+ content.push({
68
+ type: "image",
69
+ image: imageData(part.data, part.mediaType),
70
+ mimeType: part.mediaType,
71
+ });
72
+ }
73
+ break;
74
+ }
75
+ }
76
+ messages.push({ role: "user", content });
77
+ continue;
78
+ }
79
+ if (message.role === "assistant") {
80
+ const content = [];
81
+ for (const part of message.content) {
82
+ if (part.type === "text" || part.type === "reasoning") {
83
+ content.push({ type: part.type, text: part.text });
84
+ }
85
+ if (part.type === "tool-call") {
86
+ content.push({
87
+ type: "tool-call",
88
+ toolCallId: part.toolCallId,
89
+ toolName: part.toolName,
90
+ input: part.input,
91
+ });
92
+ }
93
+ }
94
+ messages.push({ role: "assistant", content });
95
+ continue;
96
+ }
97
+ const content = [];
98
+ for (const part of message.content) {
99
+ if (part.type !== "tool-result") {
100
+ continue;
101
+ }
102
+ content.push({
103
+ type: "tool-result",
104
+ toolCallId: part.toolCallId,
105
+ toolName: part.toolName,
106
+ output: toolResultOutput(part.output),
107
+ });
108
+ }
109
+ messages.push({ role: "tool", content });
110
+ }
111
+ return { messages, system: system.join("\n\n") };
112
+ }
113
+ function toolsFromCall(call) {
114
+ const tools = [];
115
+ for (const tool of call.tools ?? []) {
116
+ if (tool.type !== "function") {
117
+ continue;
118
+ }
119
+ tools.push({
120
+ type: "function",
121
+ name: tool.name,
122
+ ...(tool.description === undefined ? {} : { description: tool.description }),
123
+ input_schema: tool.inputSchema,
124
+ });
125
+ }
126
+ return tools;
127
+ }
128
+ export function buildBody(options) {
129
+ const converted = messagesFromCall(options.call);
130
+ const workingDir = process.cwd();
131
+ const params = {
132
+ model: options.modelId,
133
+ messages: converted.messages,
134
+ tools: toolsFromCall(options.call),
135
+ system: converted.system,
136
+ max_tokens: options.call.maxOutputTokens ?? 16_384,
137
+ stream: true,
138
+ };
139
+ if (options.call.temperature !== undefined) {
140
+ params["temperature"] = options.call.temperature;
141
+ }
142
+ if (options.call.topP !== undefined) {
143
+ params["top_p"] = options.call.topP;
144
+ }
145
+ if (options.call.topK !== undefined) {
146
+ params["top_k"] = options.call.topK;
147
+ }
148
+ return {
149
+ config: {
150
+ workingDir,
151
+ date: new Date().toISOString().slice(0, 10),
152
+ environment: `${process.platform}-${process.arch}`,
153
+ structure: [],
154
+ isGitRepo: false,
155
+ currentBranch: "",
156
+ mainBranch: "",
157
+ gitStatus: "",
158
+ recentCommits: [],
159
+ },
160
+ memory: "",
161
+ taste: "",
162
+ skills: null,
163
+ permissionMode: "standard",
164
+ threadId: options.sessionId,
165
+ params,
166
+ };
167
+ }
@@ -0,0 +1,5 @@
1
+ import { z } from "zod";
2
+ declare const commandCodeSessionIdSchema: z.core.$ZodBranded<z.ZodString, "CommandCodeSessionId">;
3
+ export type CommandCodeSessionId = z.infer<typeof commandCodeSessionIdSchema>;
4
+ export declare function createCommandCodeSessionId(generate?: () => string): CommandCodeSessionId;
5
+ export {};
@@ -0,0 +1,9 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { z } from "zod";
3
+ const commandCodeSessionIdSchema = z
4
+ .string()
5
+ .uuid()
6
+ .brand();
7
+ export function createCommandCodeSessionId(generate = randomUUID) {
8
+ return commandCodeSessionIdSchema.parse(generate());
9
+ }
@@ -0,0 +1,7 @@
1
+ import type { ProviderAdapter } from "../../core/adapter";
2
+ import type { AdapterModel } from "../../core/models";
3
+ export type CursorAdapterOptions = {
4
+ readonly readAccessToken: (signal: AbortSignal) => Promise<string | null>;
5
+ readonly listModels: (token: string, signal: AbortSignal) => Promise<readonly AdapterModel[]>;
6
+ };
7
+ export declare function createCursorAdapter(options: CursorAdapterOptions): ProviderAdapter;
@@ -0,0 +1,37 @@
1
+ import { OperationCancelledError } from "../../core/errors";
2
+ import { parseProviderId } from "../../core/ids";
3
+ import { createAsyncDisposable } from "../../core/lifecycle";
4
+ export function createCursorAdapter(options) {
5
+ const providerId = parseProviderId("cursor");
6
+ const disposal = createAsyncDisposable(() => undefined);
7
+ let lastModels = null;
8
+ return {
9
+ providerId,
10
+ snapshot: async (signal) => {
11
+ if (signal.aborted) {
12
+ throw new OperationCancelledError("cursor-snapshot");
13
+ }
14
+ const token = await options.readAccessToken(signal);
15
+ if (token === null) {
16
+ return { status: "unavailable", providerId, reason: "invalid-data" };
17
+ }
18
+ try {
19
+ const models = await options.listModels(token, signal);
20
+ if (models.length === 0) {
21
+ return lastModels === null
22
+ ? { status: "unavailable", providerId, reason: "invalid-data" }
23
+ : { status: "stale", providerId, models: lastModels, reason: "invalid-data" };
24
+ }
25
+ lastModels = models;
26
+ return { status: "ready", providerId, models };
27
+ }
28
+ catch {
29
+ return lastModels === null
30
+ ? { status: "unavailable", providerId, reason: "transport-error" }
31
+ : { status: "stale", providerId, models: lastModels, reason: "transport-error" };
32
+ }
33
+ },
34
+ dispose: disposal.dispose,
35
+ [Symbol.asyncDispose]: disposal[Symbol.asyncDispose],
36
+ };
37
+ }
@@ -0,0 +1,6 @@
1
+ import { type CursorCredentials } from "./credentials";
2
+ export type CursorAuthLookup = {
3
+ readonly readAuthFile?: (path: string, signal: AbortSignal) => Promise<CursorCredentials | null>;
4
+ };
5
+ export declare function readCursorAccessToken(env: Readonly<Record<string, string | undefined>>, signal: AbortSignal, lookup?: CursorAuthLookup): Promise<string | null>;
6
+ export declare function resolveCursorAgent(env: Readonly<Record<string, string | undefined>>, signal: AbortSignal): Promise<string | null>;
@@ -0,0 +1,56 @@
1
+ import { access, readFile } from "node:fs/promises";
2
+ import { delimiter, join } from "node:path";
3
+ import { OperationCancelledError } from "../../core/errors";
4
+ import { parseCursorCredentials } from "./credentials";
5
+ async function defaultReadAuthFile(path, signal) {
6
+ try {
7
+ const text = await readFile(path, { encoding: "utf8", signal });
8
+ return parseCursorCredentials(JSON.parse(text));
9
+ }
10
+ catch (error) {
11
+ if (error instanceof SyntaxError) {
12
+ return null;
13
+ }
14
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
15
+ return null;
16
+ }
17
+ throw error;
18
+ }
19
+ }
20
+ export async function readCursorAccessToken(env, signal, lookup = {}) {
21
+ if (signal.aborted) {
22
+ throw new OperationCancelledError("cursor-read-token");
23
+ }
24
+ const envToken = env["CURSOR_ACCESS_TOKEN"];
25
+ if (typeof envToken === "string" && envToken.length > 0) {
26
+ return envToken;
27
+ }
28
+ const home = env["HOME"];
29
+ if (home === undefined || home.length === 0) {
30
+ return null;
31
+ }
32
+ const readAuthFile = lookup.readAuthFile ?? defaultReadAuthFile;
33
+ const credentials = await readAuthFile(join(home, ".config/cursor/auth.json"), signal);
34
+ return credentials === null ? null : credentials.accessToken;
35
+ }
36
+ export async function resolveCursorAgent(env, signal) {
37
+ if (signal.aborted) {
38
+ throw new OperationCancelledError("cursor-resolve-agent");
39
+ }
40
+ const pathValue = env["PATH"];
41
+ if (pathValue === undefined || pathValue.length === 0) {
42
+ return null;
43
+ }
44
+ const names = ["cursor-agent", "cursor-agent.exe"];
45
+ for (const directory of pathValue.split(delimiter)) {
46
+ for (const name of names) {
47
+ const candidate = `${directory}/${name}`;
48
+ try {
49
+ await access(candidate);
50
+ return candidate;
51
+ }
52
+ catch { }
53
+ }
54
+ }
55
+ return null;
56
+ }
@@ -0,0 +1,26 @@
1
+ import { z } from "zod";
2
+ import type { Clock } from "../../core/clock";
3
+ export declare const CursorBlobIdSchema: z.core.$ZodBranded<z.ZodString, "CursorBlobId">;
4
+ export type CursorBlobId = z.output<typeof CursorBlobIdSchema>;
5
+ export type CursorBlobStoreOptions = {
6
+ readonly clock: Clock;
7
+ readonly maxBytes: number;
8
+ readonly maxEntries: number;
9
+ /** Logical milliseconds; zero expires content on the next store operation. */
10
+ readonly ttlMs: number;
11
+ };
12
+ export type CursorBlobStore = {
13
+ readonly get: (blobId: CursorBlobId) => Uint8Array | null;
14
+ readonly has: (blobId: CursorBlobId) => boolean;
15
+ readonly hash: (bytes: Uint8Array) => CursorBlobId;
16
+ readonly pin: (blobId: CursorBlobId) => boolean;
17
+ readonly put: (bytes: Uint8Array) => CursorBlobId | null;
18
+ readonly putVerified: (blobId: CursorBlobId, bytes: Uint8Array) => CursorBlobId | null;
19
+ readonly release: (blobId: CursorBlobId) => void;
20
+ readonly size: () => number;
21
+ };
22
+ export declare function hashCursorBlob(bytes: Uint8Array): CursorBlobId;
23
+ export declare function parseCursorWireBlobId(bytes: Uint8Array): CursorBlobId;
24
+ export declare function requirePositiveCursorStoreBound(value: number, argument: string): void;
25
+ export declare function requireCursorStoreTtl(value: number): void;
26
+ export declare function createCursorBlobStore(options: CursorBlobStoreOptions): CursorBlobStore;
@@ -0,0 +1,119 @@
1
+ import { createHash } from "node:crypto";
2
+ import { z } from "zod";
3
+ import { InvalidArgumentError } from "../../core/errors";
4
+ export const CursorBlobIdSchema = z
5
+ .string()
6
+ .regex(/^[a-f0-9]{64}$/)
7
+ .brand();
8
+ export function hashCursorBlob(bytes) {
9
+ return CursorBlobIdSchema.parse(createHash("sha256").update(bytes).digest("hex"));
10
+ }
11
+ export function parseCursorWireBlobId(bytes) {
12
+ if (bytes.byteLength !== 32) {
13
+ throw new InvalidArgumentError("blobId");
14
+ }
15
+ return CursorBlobIdSchema.parse(Buffer.from(bytes).toString("hex"));
16
+ }
17
+ export function requirePositiveCursorStoreBound(value, argument) {
18
+ if (!Number.isSafeInteger(value) || value < 1) {
19
+ throw new InvalidArgumentError(argument);
20
+ }
21
+ }
22
+ export function requireCursorStoreTtl(value) {
23
+ if (!Number.isSafeInteger(value) || value < 0) {
24
+ throw new InvalidArgumentError("ttlMs");
25
+ }
26
+ }
27
+ export function createCursorBlobStore(options) {
28
+ requirePositiveCursorStoreBound(options.maxBytes, "maxBytes");
29
+ requirePositiveCursorStoreBound(options.maxEntries, "maxEntries");
30
+ requireCursorStoreTtl(options.ttlMs);
31
+ const entries = new Map();
32
+ let totalBytes = 0;
33
+ const evictExpired = (nowMs) => {
34
+ for (const [blobId, entry] of entries) {
35
+ if (entry.pins === 0 && nowMs - entry.lastAccessMs >= options.ttlMs) {
36
+ entries.delete(blobId);
37
+ totalBytes -= entry.bytes.byteLength;
38
+ }
39
+ }
40
+ };
41
+ const evictToBounds = () => {
42
+ while (entries.size > options.maxEntries || totalBytes > options.maxBytes) {
43
+ let evicted = false;
44
+ for (const [blobId, entry] of entries) {
45
+ if (entry.pins === 0) {
46
+ entries.delete(blobId);
47
+ totalBytes -= entry.bytes.byteLength;
48
+ evicted = true;
49
+ break;
50
+ }
51
+ }
52
+ if (!evicted) {
53
+ return;
54
+ }
55
+ }
56
+ };
57
+ const touch = (blobId, entry, nowMs) => {
58
+ const updated = { bytes: entry.bytes, lastAccessMs: nowMs, pins: entry.pins };
59
+ entries.delete(blobId);
60
+ entries.set(blobId, updated);
61
+ return updated;
62
+ };
63
+ const activeEntry = (blobId) => {
64
+ const nowMs = options.clock.nowMs();
65
+ evictExpired(nowMs);
66
+ const entry = entries.get(blobId);
67
+ return entry === undefined ? null : touch(blobId, entry, nowMs);
68
+ };
69
+ const store = (blobId, bytes) => {
70
+ const nowMs = options.clock.nowMs();
71
+ evictExpired(nowMs);
72
+ if (bytes.byteLength > options.maxBytes) {
73
+ return null;
74
+ }
75
+ const existing = entries.get(blobId);
76
+ if (existing !== undefined) {
77
+ touch(blobId, existing, nowMs);
78
+ return blobId;
79
+ }
80
+ const snapshot = new Uint8Array(bytes);
81
+ entries.set(blobId, { bytes: snapshot, lastAccessMs: nowMs, pins: 0 });
82
+ totalBytes += snapshot.byteLength;
83
+ evictToBounds();
84
+ return entries.has(blobId) ? blobId : null;
85
+ };
86
+ return {
87
+ get: (blobId) => {
88
+ const entry = activeEntry(blobId);
89
+ return entry === null ? null : new Uint8Array(entry.bytes);
90
+ },
91
+ has: (blobId) => activeEntry(blobId) !== null,
92
+ hash: hashCursorBlob,
93
+ pin: (blobId) => {
94
+ const entry = activeEntry(blobId);
95
+ if (entry === null) {
96
+ return false;
97
+ }
98
+ entry.pins += 1;
99
+ return true;
100
+ },
101
+ put: (bytes) => store(hashCursorBlob(bytes), bytes),
102
+ putVerified: (blobId, bytes) => {
103
+ if (hashCursorBlob(bytes) !== blobId) {
104
+ throw new InvalidArgumentError("blobId");
105
+ }
106
+ return store(blobId, bytes);
107
+ },
108
+ release: (blobId) => {
109
+ const entry = entries.get(blobId);
110
+ if (entry !== undefined && entry.pins > 0) {
111
+ entry.pins -= 1;
112
+ }
113
+ },
114
+ size: () => {
115
+ evictExpired(options.clock.nowMs());
116
+ return entries.size;
117
+ },
118
+ };
119
+ }
@@ -0,0 +1,33 @@
1
+ import { type CursorBridgeProcessFactory } from "./bridge-process";
2
+ import { type BridgeEvent } from "./bridge-protocol";
3
+ export type CursorBridgeSessionErrorReason = "duplicate-stream" | "stream-closed";
4
+ export declare class CursorBridgeSessionError extends Error {
5
+ readonly reason: CursorBridgeSessionErrorReason;
6
+ readonly name = "CursorBridgeSessionError";
7
+ readonly code = "CURSOR_BRIDGE_SESSION_ERROR";
8
+ constructor(reason: CursorBridgeSessionErrorReason);
9
+ }
10
+ export type CursorBridgeOpenInput = {
11
+ readonly id: string;
12
+ readonly accessToken: string;
13
+ readonly path: string;
14
+ readonly headers: Readonly<Record<string, string>>;
15
+ readonly signal: AbortSignal;
16
+ };
17
+ export interface CursorBridgeStream {
18
+ readonly id: string;
19
+ write(payload: Uint8Array, signal?: AbortSignal): Promise<void>;
20
+ nextEvent(signal?: AbortSignal): Promise<BridgeEvent>;
21
+ abort(): Promise<void>;
22
+ close(): Promise<void>;
23
+ }
24
+ export interface CursorBridgeClient extends AsyncDisposable {
25
+ readonly pid: number;
26
+ open(input: CursorBridgeOpenInput): Promise<CursorBridgeStream>;
27
+ dispose(): Promise<void>;
28
+ }
29
+ export type CursorBridgeClientOptions = {
30
+ readonly processFactory?: CursorBridgeProcessFactory;
31
+ readonly signal?: AbortSignal;
32
+ };
33
+ export declare function createCursorBridgeClient(options?: CursorBridgeClientOptions): Promise<CursorBridgeClient>;