@clinebot/core 0.0.20 → 0.0.22

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 (356) hide show
  1. package/dist/account/cline-account-service.d.ts +3 -2
  2. package/dist/account/cline-account-service.d.ts.map +1 -0
  3. package/dist/account/index.d.ts +1 -0
  4. package/dist/account/index.d.ts.map +1 -0
  5. package/dist/account/rpc.d.ts +1 -0
  6. package/dist/account/rpc.d.ts.map +1 -0
  7. package/dist/account/types.d.ts +1 -0
  8. package/dist/account/types.d.ts.map +1 -0
  9. package/dist/agents/agent-config-loader.d.ts +1 -0
  10. package/dist/agents/agent-config-loader.d.ts.map +1 -0
  11. package/dist/agents/agent-config-parser.d.ts +1 -0
  12. package/dist/agents/agent-config-parser.d.ts.map +1 -0
  13. package/dist/agents/hooks-config-loader.d.ts +1 -0
  14. package/dist/agents/hooks-config-loader.d.ts.map +1 -0
  15. package/dist/agents/index.d.ts +1 -0
  16. package/dist/agents/index.d.ts.map +1 -0
  17. package/dist/agents/plugin-config-loader.d.ts +1 -0
  18. package/dist/agents/plugin-config-loader.d.ts.map +1 -0
  19. package/dist/agents/plugin-loader.d.ts +1 -0
  20. package/dist/agents/plugin-loader.d.ts.map +1 -0
  21. package/dist/agents/plugin-sandbox.d.ts +1 -0
  22. package/dist/agents/plugin-sandbox.d.ts.map +1 -0
  23. package/dist/agents/unified-config-file-watcher.d.ts +1 -0
  24. package/dist/agents/unified-config-file-watcher.d.ts.map +1 -0
  25. package/dist/agents/user-instruction-config-loader.d.ts +1 -0
  26. package/dist/agents/user-instruction-config-loader.d.ts.map +1 -0
  27. package/dist/auth/client.d.ts +1 -0
  28. package/dist/auth/client.d.ts.map +1 -0
  29. package/dist/auth/cline.d.ts +1 -0
  30. package/dist/auth/cline.d.ts.map +1 -0
  31. package/dist/auth/codex.d.ts +1 -0
  32. package/dist/auth/codex.d.ts.map +1 -0
  33. package/dist/auth/oca.d.ts +1 -0
  34. package/dist/auth/oca.d.ts.map +1 -0
  35. package/dist/auth/server.d.ts +1 -0
  36. package/dist/auth/server.d.ts.map +1 -0
  37. package/dist/auth/types.d.ts +1 -0
  38. package/dist/auth/types.d.ts.map +1 -0
  39. package/dist/auth/utils.d.ts +1 -0
  40. package/dist/auth/utils.d.ts.map +1 -0
  41. package/dist/chat/chat-schema.d.ts +13 -12
  42. package/dist/chat/chat-schema.d.ts.map +1 -0
  43. package/dist/index.d.ts +3 -1
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.node.d.ts +2 -0
  46. package/dist/index.node.d.ts.map +1 -0
  47. package/dist/index.node.js +303 -302
  48. package/dist/input/file-indexer.d.ts +1 -0
  49. package/dist/input/file-indexer.d.ts.map +1 -0
  50. package/dist/input/index.d.ts +1 -0
  51. package/dist/input/index.d.ts.map +1 -0
  52. package/dist/input/mention-enricher.d.ts +1 -0
  53. package/dist/input/mention-enricher.d.ts.map +1 -0
  54. package/dist/mcp/config-loader.d.ts +1 -0
  55. package/dist/mcp/config-loader.d.ts.map +1 -0
  56. package/dist/mcp/index.d.ts +1 -0
  57. package/dist/mcp/index.d.ts.map +1 -0
  58. package/dist/mcp/manager.d.ts +1 -0
  59. package/dist/mcp/manager.d.ts.map +1 -0
  60. package/dist/mcp/types.d.ts +1 -0
  61. package/dist/mcp/types.d.ts.map +1 -0
  62. package/dist/providers/local-provider-registry.d.ts +36 -0
  63. package/dist/providers/local-provider-registry.d.ts.map +1 -0
  64. package/dist/providers/local-provider-service.d.ts +2 -1
  65. package/dist/providers/local-provider-service.d.ts.map +1 -0
  66. package/dist/runtime/commands.d.ts +1 -0
  67. package/dist/runtime/commands.d.ts.map +1 -0
  68. package/dist/runtime/hook-file-hooks.d.ts +1 -0
  69. package/dist/runtime/hook-file-hooks.d.ts.map +1 -0
  70. package/dist/runtime/rules.d.ts +1 -0
  71. package/dist/runtime/rules.d.ts.map +1 -0
  72. package/dist/runtime/runtime-builder.d.ts +1 -0
  73. package/dist/runtime/runtime-builder.d.ts.map +1 -0
  74. package/dist/runtime/sandbox/subprocess-sandbox.d.ts +1 -0
  75. package/dist/runtime/sandbox/subprocess-sandbox.d.ts.map +1 -0
  76. package/dist/runtime/session-runtime.d.ts +2 -0
  77. package/dist/runtime/session-runtime.d.ts.map +1 -0
  78. package/dist/runtime/skills.d.ts +1 -0
  79. package/dist/runtime/skills.d.ts.map +1 -0
  80. package/dist/runtime/tool-approval.d.ts +1 -0
  81. package/dist/runtime/tool-approval.d.ts.map +1 -0
  82. package/dist/runtime/workflows.d.ts +1 -0
  83. package/dist/runtime/workflows.d.ts.map +1 -0
  84. package/dist/session/default-session-manager.d.ts +4 -0
  85. package/dist/session/default-session-manager.d.ts.map +1 -0
  86. package/dist/session/file-session-service.d.ts +1 -0
  87. package/dist/session/file-session-service.d.ts.map +1 -0
  88. package/dist/session/rpc-session-service.d.ts +1 -0
  89. package/dist/session/rpc-session-service.d.ts.map +1 -0
  90. package/dist/session/rpc-spawn-lease.d.ts +1 -0
  91. package/dist/session/rpc-spawn-lease.d.ts.map +1 -0
  92. package/dist/session/runtime-oauth-token-manager.d.ts +1 -0
  93. package/dist/session/runtime-oauth-token-manager.d.ts.map +1 -0
  94. package/dist/session/session-agent-events.d.ts +20 -1
  95. package/dist/session/session-agent-events.d.ts.map +1 -0
  96. package/dist/session/session-artifacts.d.ts +1 -0
  97. package/dist/session/session-artifacts.d.ts.map +1 -0
  98. package/dist/session/session-config-builder.d.ts +1 -0
  99. package/dist/session/session-config-builder.d.ts.map +1 -0
  100. package/dist/session/session-graph.d.ts +1 -0
  101. package/dist/session/session-graph.d.ts.map +1 -0
  102. package/dist/session/session-host.d.ts +1 -0
  103. package/dist/session/session-host.d.ts.map +1 -0
  104. package/dist/session/session-manager.d.ts +1 -0
  105. package/dist/session/session-manager.d.ts.map +1 -0
  106. package/dist/session/session-manifest.d.ts +2 -1
  107. package/dist/session/session-manifest.d.ts.map +1 -0
  108. package/dist/session/session-service.d.ts +1 -0
  109. package/dist/session/session-service.d.ts.map +1 -0
  110. package/dist/session/session-team-coordination.d.ts +1 -0
  111. package/dist/session/session-team-coordination.d.ts.map +1 -0
  112. package/dist/session/session-telemetry.d.ts +3 -1
  113. package/dist/session/session-telemetry.d.ts.map +1 -0
  114. package/dist/session/sqlite-rpc-session-backend.d.ts +1 -0
  115. package/dist/session/sqlite-rpc-session-backend.d.ts.map +1 -0
  116. package/dist/session/unified-session-persistence-service.d.ts +1 -0
  117. package/dist/session/unified-session-persistence-service.d.ts.map +1 -0
  118. package/dist/session/utils/helpers.d.ts +1 -0
  119. package/dist/session/utils/helpers.d.ts.map +1 -0
  120. package/dist/session/utils/types.d.ts +1 -0
  121. package/dist/session/utils/types.d.ts.map +1 -0
  122. package/dist/session/utils/usage.d.ts +1 -0
  123. package/dist/session/utils/usage.d.ts.map +1 -0
  124. package/dist/session/workspace-manager.d.ts +1 -0
  125. package/dist/session/workspace-manager.d.ts.map +1 -0
  126. package/dist/session/workspace-manifest.d.ts +1 -0
  127. package/dist/session/workspace-manifest.d.ts.map +1 -0
  128. package/dist/storage/file-team-store.d.ts +1 -0
  129. package/dist/storage/file-team-store.d.ts.map +1 -0
  130. package/dist/storage/provider-settings-legacy-migration.d.ts +1 -0
  131. package/dist/storage/provider-settings-legacy-migration.d.ts.map +1 -0
  132. package/dist/storage/provider-settings-manager.d.ts +1 -0
  133. package/dist/storage/provider-settings-manager.d.ts.map +1 -0
  134. package/dist/storage/sqlite-session-store.d.ts +1 -0
  135. package/dist/storage/sqlite-session-store.d.ts.map +1 -0
  136. package/dist/storage/sqlite-team-store.d.ts +1 -0
  137. package/dist/storage/sqlite-team-store.d.ts.map +1 -0
  138. package/dist/storage/team-store.d.ts +1 -0
  139. package/dist/storage/team-store.d.ts.map +1 -0
  140. package/dist/team/index.d.ts +1 -0
  141. package/dist/team/index.d.ts.map +1 -0
  142. package/dist/team/projections.d.ts +1 -0
  143. package/dist/team/projections.d.ts.map +1 -0
  144. package/dist/telemetry/ITelemetryAdapter.d.ts +1 -0
  145. package/dist/telemetry/ITelemetryAdapter.d.ts.map +1 -0
  146. package/dist/telemetry/LoggerTelemetryAdapter.d.ts +1 -0
  147. package/dist/telemetry/LoggerTelemetryAdapter.d.ts.map +1 -0
  148. package/dist/telemetry/OpenTelemetryAdapter.d.ts +1 -0
  149. package/dist/telemetry/OpenTelemetryAdapter.d.ts.map +1 -0
  150. package/dist/telemetry/OpenTelemetryProvider.d.ts +1 -0
  151. package/dist/telemetry/OpenTelemetryProvider.d.ts.map +1 -0
  152. package/dist/telemetry/TelemetryService.d.ts +1 -0
  153. package/dist/telemetry/TelemetryService.d.ts.map +1 -0
  154. package/dist/telemetry/core-events.d.ts +55 -22
  155. package/dist/telemetry/core-events.d.ts.map +1 -0
  156. package/dist/telemetry/opentelemetry.d.ts +1 -0
  157. package/dist/telemetry/opentelemetry.d.ts.map +1 -0
  158. package/dist/tools/constants.d.ts +1 -0
  159. package/dist/tools/constants.d.ts.map +1 -0
  160. package/dist/tools/definitions.d.ts +8 -1
  161. package/dist/tools/definitions.d.ts.map +1 -0
  162. package/dist/tools/executors/apply-patch-parser.d.ts +1 -0
  163. package/dist/tools/executors/apply-patch-parser.d.ts.map +1 -0
  164. package/dist/tools/executors/apply-patch.d.ts +1 -0
  165. package/dist/tools/executors/apply-patch.d.ts.map +1 -0
  166. package/dist/tools/executors/bash.d.ts +2 -1
  167. package/dist/tools/executors/bash.d.ts.map +1 -0
  168. package/dist/tools/executors/editor.d.ts +1 -0
  169. package/dist/tools/executors/editor.d.ts.map +1 -0
  170. package/dist/tools/executors/file-read.d.ts +1 -0
  171. package/dist/tools/executors/file-read.d.ts.map +1 -0
  172. package/dist/tools/executors/index.d.ts +14 -7
  173. package/dist/tools/executors/index.d.ts.map +1 -0
  174. package/dist/tools/executors/search.d.ts +1 -0
  175. package/dist/tools/executors/search.d.ts.map +1 -0
  176. package/dist/tools/executors/web-fetch.d.ts +1 -0
  177. package/dist/tools/executors/web-fetch.d.ts.map +1 -0
  178. package/dist/tools/helpers.d.ts +15 -0
  179. package/dist/tools/helpers.d.ts.map +1 -0
  180. package/dist/tools/index.d.ts +2 -1
  181. package/dist/tools/index.d.ts.map +1 -0
  182. package/dist/tools/model-tool-routing.d.ts +1 -0
  183. package/dist/tools/model-tool-routing.d.ts.map +1 -0
  184. package/dist/tools/presets.d.ts +1 -0
  185. package/dist/tools/presets.d.ts.map +1 -0
  186. package/dist/tools/schemas.d.ts +41 -0
  187. package/dist/tools/schemas.d.ts.map +1 -0
  188. package/dist/tools/types.d.ts +3 -2
  189. package/dist/tools/types.d.ts.map +1 -0
  190. package/dist/types/common.d.ts +1 -0
  191. package/dist/types/common.d.ts.map +1 -0
  192. package/dist/types/config.d.ts +1 -0
  193. package/dist/types/config.d.ts.map +1 -0
  194. package/dist/types/events.d.ts +1 -0
  195. package/dist/types/events.d.ts.map +1 -0
  196. package/dist/types/provider-settings.d.ts +1 -0
  197. package/dist/types/provider-settings.d.ts.map +1 -0
  198. package/dist/types/sessions.d.ts +1 -0
  199. package/dist/types/sessions.d.ts.map +1 -0
  200. package/dist/types/storage.d.ts +1 -0
  201. package/dist/types/storage.d.ts.map +1 -0
  202. package/dist/types/workspace.d.ts +1 -0
  203. package/dist/types/workspace.d.ts.map +1 -0
  204. package/dist/types.d.ts +1 -0
  205. package/dist/types.d.ts.map +1 -0
  206. package/package.json +8 -6
  207. package/src/account/cline-account-service.test.ts +0 -101
  208. package/src/account/cline-account-service.ts +0 -287
  209. package/src/account/index.ts +0 -22
  210. package/src/account/rpc.test.ts +0 -62
  211. package/src/account/rpc.ts +0 -172
  212. package/src/account/types.ts +0 -98
  213. package/src/agents/agent-config-loader.test.ts +0 -236
  214. package/src/agents/agent-config-loader.ts +0 -108
  215. package/src/agents/agent-config-parser.ts +0 -198
  216. package/src/agents/hooks-config-loader.test.ts +0 -20
  217. package/src/agents/hooks-config-loader.ts +0 -118
  218. package/src/agents/index.ts +0 -85
  219. package/src/agents/plugin-config-loader.test.ts +0 -140
  220. package/src/agents/plugin-config-loader.ts +0 -97
  221. package/src/agents/plugin-loader.test.ts +0 -228
  222. package/src/agents/plugin-loader.ts +0 -172
  223. package/src/agents/plugin-sandbox-bootstrap.ts +0 -445
  224. package/src/agents/plugin-sandbox.test.ts +0 -317
  225. package/src/agents/plugin-sandbox.ts +0 -341
  226. package/src/agents/unified-config-file-watcher.test.ts +0 -196
  227. package/src/agents/unified-config-file-watcher.ts +0 -483
  228. package/src/agents/user-instruction-config-loader.test.ts +0 -158
  229. package/src/agents/user-instruction-config-loader.ts +0 -438
  230. package/src/auth/client.test.ts +0 -40
  231. package/src/auth/client.ts +0 -25
  232. package/src/auth/cline.test.ts +0 -130
  233. package/src/auth/cline.ts +0 -420
  234. package/src/auth/codex.test.ts +0 -170
  235. package/src/auth/codex.ts +0 -491
  236. package/src/auth/oca.test.ts +0 -215
  237. package/src/auth/oca.ts +0 -573
  238. package/src/auth/server.ts +0 -216
  239. package/src/auth/types.ts +0 -81
  240. package/src/auth/utils.test.ts +0 -128
  241. package/src/auth/utils.ts +0 -247
  242. package/src/chat/chat-schema.ts +0 -82
  243. package/src/index.node.ts +0 -285
  244. package/src/index.ts +0 -211
  245. package/src/input/file-indexer.d.ts +0 -11
  246. package/src/input/file-indexer.test.ts +0 -127
  247. package/src/input/file-indexer.ts +0 -327
  248. package/src/input/index.ts +0 -7
  249. package/src/input/mention-enricher.test.ts +0 -85
  250. package/src/input/mention-enricher.ts +0 -122
  251. package/src/mcp/config-loader.test.ts +0 -238
  252. package/src/mcp/config-loader.ts +0 -219
  253. package/src/mcp/index.ts +0 -26
  254. package/src/mcp/manager.test.ts +0 -106
  255. package/src/mcp/manager.ts +0 -262
  256. package/src/mcp/types.ts +0 -88
  257. package/src/providers/local-provider-service.ts +0 -608
  258. package/src/runtime/commands.test.ts +0 -98
  259. package/src/runtime/commands.ts +0 -83
  260. package/src/runtime/hook-file-hooks.test.ts +0 -237
  261. package/src/runtime/hook-file-hooks.ts +0 -859
  262. package/src/runtime/index.ts +0 -37
  263. package/src/runtime/rules.ts +0 -34
  264. package/src/runtime/runtime-builder.team-persistence.test.ts +0 -202
  265. package/src/runtime/runtime-builder.test.ts +0 -371
  266. package/src/runtime/runtime-builder.ts +0 -589
  267. package/src/runtime/runtime-parity.test.ts +0 -143
  268. package/src/runtime/sandbox/subprocess-sandbox.ts +0 -231
  269. package/src/runtime/session-runtime.ts +0 -46
  270. package/src/runtime/skills.ts +0 -44
  271. package/src/runtime/tool-approval.ts +0 -104
  272. package/src/runtime/workflows.test.ts +0 -119
  273. package/src/runtime/workflows.ts +0 -45
  274. package/src/session/default-session-manager.e2e.test.ts +0 -384
  275. package/src/session/default-session-manager.test.ts +0 -1741
  276. package/src/session/default-session-manager.ts +0 -1233
  277. package/src/session/file-session-service.ts +0 -280
  278. package/src/session/index.ts +0 -42
  279. package/src/session/rpc-session-service.ts +0 -107
  280. package/src/session/rpc-spawn-lease.test.ts +0 -49
  281. package/src/session/rpc-spawn-lease.ts +0 -122
  282. package/src/session/runtime-oauth-token-manager.test.ts +0 -137
  283. package/src/session/runtime-oauth-token-manager.ts +0 -272
  284. package/src/session/session-agent-events.ts +0 -159
  285. package/src/session/session-artifacts.ts +0 -106
  286. package/src/session/session-config-builder.ts +0 -113
  287. package/src/session/session-graph.ts +0 -92
  288. package/src/session/session-host.test.ts +0 -29
  289. package/src/session/session-host.ts +0 -242
  290. package/src/session/session-manager.ts +0 -69
  291. package/src/session/session-manifest.ts +0 -29
  292. package/src/session/session-service.team-persistence.test.ts +0 -48
  293. package/src/session/session-service.ts +0 -673
  294. package/src/session/session-team-coordination.ts +0 -229
  295. package/src/session/session-telemetry.ts +0 -95
  296. package/src/session/sqlite-rpc-session-backend.ts +0 -303
  297. package/src/session/unified-session-persistence-service.test.ts +0 -85
  298. package/src/session/unified-session-persistence-service.ts +0 -996
  299. package/src/session/utils/helpers.ts +0 -139
  300. package/src/session/utils/types.ts +0 -57
  301. package/src/session/utils/usage.ts +0 -32
  302. package/src/session/workspace-manager.ts +0 -98
  303. package/src/session/workspace-manifest.ts +0 -100
  304. package/src/storage/artifact-store.ts +0 -1
  305. package/src/storage/file-team-store.ts +0 -257
  306. package/src/storage/index.ts +0 -11
  307. package/src/storage/provider-settings-legacy-migration.test.ts +0 -307
  308. package/src/storage/provider-settings-legacy-migration.ts +0 -689
  309. package/src/storage/provider-settings-manager.test.ts +0 -145
  310. package/src/storage/provider-settings-manager.ts +0 -150
  311. package/src/storage/session-store.ts +0 -1
  312. package/src/storage/sqlite-session-store.ts +0 -275
  313. package/src/storage/sqlite-team-store.ts +0 -454
  314. package/src/storage/team-store.ts +0 -40
  315. package/src/team/index.ts +0 -4
  316. package/src/team/projections.ts +0 -285
  317. package/src/telemetry/ITelemetryAdapter.ts +0 -94
  318. package/src/telemetry/LoggerTelemetryAdapter.test.ts +0 -42
  319. package/src/telemetry/LoggerTelemetryAdapter.ts +0 -114
  320. package/src/telemetry/OpenTelemetryAdapter.test.ts +0 -157
  321. package/src/telemetry/OpenTelemetryAdapter.ts +0 -348
  322. package/src/telemetry/OpenTelemetryProvider.test.ts +0 -113
  323. package/src/telemetry/OpenTelemetryProvider.ts +0 -322
  324. package/src/telemetry/TelemetryService.test.ts +0 -134
  325. package/src/telemetry/TelemetryService.ts +0 -141
  326. package/src/telemetry/core-events.ts +0 -344
  327. package/src/telemetry/opentelemetry.ts +0 -20
  328. package/src/tools/constants.ts +0 -35
  329. package/src/tools/definitions.test.ts +0 -658
  330. package/src/tools/definitions.ts +0 -726
  331. package/src/tools/executors/apply-patch-parser.ts +0 -520
  332. package/src/tools/executors/apply-patch.ts +0 -359
  333. package/src/tools/executors/bash.ts +0 -205
  334. package/src/tools/executors/editor.test.ts +0 -35
  335. package/src/tools/executors/editor.ts +0 -219
  336. package/src/tools/executors/file-read.test.ts +0 -49
  337. package/src/tools/executors/file-read.ts +0 -110
  338. package/src/tools/executors/index.ts +0 -75
  339. package/src/tools/executors/search.ts +0 -278
  340. package/src/tools/executors/web-fetch.ts +0 -259
  341. package/src/tools/index.ts +0 -168
  342. package/src/tools/model-tool-routing.test.ts +0 -86
  343. package/src/tools/model-tool-routing.ts +0 -132
  344. package/src/tools/presets.test.ts +0 -62
  345. package/src/tools/presets.ts +0 -168
  346. package/src/tools/schemas.ts +0 -284
  347. package/src/tools/types.ts +0 -328
  348. package/src/types/common.ts +0 -14
  349. package/src/types/config.ts +0 -84
  350. package/src/types/events.ts +0 -74
  351. package/src/types/index.ts +0 -24
  352. package/src/types/provider-settings.ts +0 -43
  353. package/src/types/sessions.ts +0 -16
  354. package/src/types/storage.ts +0 -64
  355. package/src/types/workspace.ts +0 -7
  356. package/src/types.ts +0 -128
@@ -1,130 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
- import type { ClineOAuthCredentials } from "./cline.js";
3
- import { getValidClineCredentials } from "./cline.js";
4
-
5
- const PROVIDER_OPTIONS = {
6
- apiBaseUrl: "https://auth.example.com",
7
- };
8
-
9
- function createCredentials(
10
- overrides: Partial<ClineOAuthCredentials> = {},
11
- ): ClineOAuthCredentials {
12
- return {
13
- access: "access-old",
14
- refresh: "refresh-old",
15
- expires: 0,
16
- accountId: "acct-1",
17
- email: "user@example.com",
18
- metadata: { provider: "google" },
19
- ...overrides,
20
- };
21
- }
22
-
23
- describe("auth/cline getValidClineCredentials", () => {
24
- afterEach(() => {
25
- vi.unstubAllGlobals();
26
- vi.restoreAllMocks();
27
- });
28
-
29
- it("returns existing credentials when not expired", async () => {
30
- const nowSpy = vi.spyOn(Date, "now").mockReturnValue(10_000);
31
- const current = createCredentials({ expires: 400_000 });
32
- const fetchMock = vi.fn();
33
- vi.stubGlobal("fetch", fetchMock);
34
-
35
- const result = await getValidClineCredentials(current, PROVIDER_OPTIONS);
36
- expect(result).toBe(current);
37
- expect(fetchMock).not.toHaveBeenCalled();
38
- nowSpy.mockRestore();
39
- });
40
-
41
- it("refreshes expired credentials", async () => {
42
- const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
43
- const current = createCredentials({ expires: 101_000 });
44
- const fetchMock = vi.fn(
45
- async () =>
46
- new Response(
47
- JSON.stringify({
48
- success: true,
49
- data: {
50
- accessToken: "access-new",
51
- refreshToken: "refresh-new",
52
- tokenType: "Bearer",
53
- expiresAt: "2030-01-01T00:00:00.000Z",
54
- userInfo: {
55
- subject: "sub-1",
56
- email: "new@example.com",
57
- name: "New User",
58
- clineUserId: "acct-2",
59
- accounts: [],
60
- },
61
- },
62
- }),
63
- { status: 200, headers: { "Content-Type": "application/json" } },
64
- ),
65
- );
66
- vi.stubGlobal("fetch", fetchMock);
67
-
68
- const result = await getValidClineCredentials(current, PROVIDER_OPTIONS);
69
- expect(result).toMatchObject({
70
- access: "access-new",
71
- refresh: "refresh-new",
72
- accountId: "acct-2",
73
- email: "new@example.com",
74
- });
75
- nowSpy.mockRestore();
76
- });
77
-
78
- it("returns null when refresh fails with invalid_grant", async () => {
79
- const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
80
- const current = createCredentials({ expires: 101_000 });
81
- vi.stubGlobal(
82
- "fetch",
83
- vi.fn(
84
- async () =>
85
- new Response(
86
- JSON.stringify({
87
- error: "invalid_grant",
88
- error_description: "refresh expired",
89
- }),
90
- {
91
- status: 401,
92
- headers: { "Content-Type": "application/json" },
93
- },
94
- ),
95
- ),
96
- );
97
-
98
- const result = await getValidClineCredentials(current, PROVIDER_OPTIONS);
99
- expect(result).toBeNull();
100
- nowSpy.mockRestore();
101
- });
102
-
103
- it("keeps current credentials on transient refresh error while token remains valid", async () => {
104
- const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
105
- const current = createCredentials({ expires: 150_000 });
106
- vi.stubGlobal(
107
- "fetch",
108
- vi.fn(
109
- async () =>
110
- new Response(
111
- JSON.stringify({
112
- error: "server_error",
113
- error_description: "temporary issue",
114
- }),
115
- {
116
- status: 500,
117
- headers: { "Content-Type": "application/json" },
118
- },
119
- ),
120
- ),
121
- );
122
-
123
- const result = await getValidClineCredentials(current, PROVIDER_OPTIONS, {
124
- refreshBufferMs: 60_000,
125
- retryableTokenGraceMs: 30_000,
126
- });
127
- expect(result).toBe(current);
128
- nowSpy.mockRestore();
129
- });
130
- });
package/src/auth/cline.ts DELETED
@@ -1,420 +0,0 @@
1
- import type { ITelemetryService } from "@clinebot/shared";
2
- import {
3
- captureAuthFailed,
4
- captureAuthLoggedOut,
5
- captureAuthStarted,
6
- captureAuthSucceeded,
7
- identifyAccount,
8
- } from "../telemetry/core-events";
9
- import { startLocalOAuthServer } from "./server.js";
10
- import type {
11
- OAuthCredentials,
12
- OAuthLoginCallbacks,
13
- OAuthProviderInterface,
14
- } from "./types.js";
15
- import {
16
- isCredentialLikelyExpired,
17
- parseAuthorizationInput,
18
- parseOAuthError,
19
- resolveAuthorizationCodeInput,
20
- resolveUrl,
21
- } from "./utils.js";
22
-
23
- const DEFAULT_AUTH_ENDPOINTS = {
24
- authorize: "/api/v1/auth/authorize",
25
- token: "/api/v1/auth/token",
26
- refresh: "/api/v1/auth/refresh",
27
- } as const;
28
-
29
- const DEFAULT_CALLBACK_PATH = "/auth";
30
- const DEFAULT_CALLBACK_PORTS = Array.from(
31
- { length: 11 },
32
- (_, index) => 48801 + index,
33
- );
34
- const DEFAULT_REFRESH_BUFFER_MS = 5 * 60 * 1000;
35
- const DEFAULT_RETRYABLE_TOKEN_GRACE_MS = 30 * 1000;
36
- const DEFAULT_HTTP_TIMEOUT_MS = 30 * 1000;
37
-
38
- export type ClineTokenResolution = {
39
- forceRefresh?: boolean;
40
- refreshBufferMs?: number;
41
- retryableTokenGraceMs?: number;
42
- };
43
-
44
- interface ClineAuthApiUser {
45
- subject: string | null;
46
- email: string;
47
- name: string;
48
- clineUserId: string | null;
49
- accounts: string[] | null;
50
- }
51
-
52
- interface ClineAuthResponseData {
53
- accessToken: string;
54
- refreshToken?: string;
55
- tokenType: string;
56
- expiresAt: string;
57
- userInfo: ClineAuthApiUser;
58
- }
59
-
60
- type ClineTokenResponse = {
61
- success: boolean;
62
- data: ClineAuthResponseData;
63
- };
64
-
65
- type HeaderMap = Record<string, string>;
66
- type HeaderInput = HeaderMap | (() => Promise<HeaderMap> | HeaderMap);
67
-
68
- export interface ClineOAuthProviderOptions {
69
- apiBaseUrl: string;
70
- headers?: HeaderInput;
71
- callbackPath?: string;
72
- callbackPorts?: number[];
73
- requestTimeoutMs?: number;
74
- telemetry?: ITelemetryService;
75
- /**
76
- * Optional identity provider name for token exchange.
77
- */
78
- provider?: string;
79
- }
80
-
81
- export interface ClineOAuthCredentials extends OAuthCredentials {
82
- metadata?: {
83
- provider?: string;
84
- tokenType?: string;
85
- userInfo?: ClineAuthApiUser;
86
- [key: string]: unknown;
87
- };
88
- }
89
-
90
- class ClineOAuthTokenError extends Error {
91
- public readonly status?: number;
92
- public readonly errorCode?: string;
93
-
94
- constructor(message: string, opts?: { status?: number; errorCode?: string }) {
95
- super(message);
96
- this.name = "ClineOAuthTokenError";
97
- this.status = opts?.status;
98
- this.errorCode = opts?.errorCode;
99
- }
100
-
101
- public isLikelyInvalidGrant(): boolean {
102
- if (
103
- this.errorCode &&
104
- /invalid_grant|invalid_token|unauthorized/i.test(this.errorCode)
105
- ) {
106
- return true;
107
- }
108
- if (this.status === 400 || this.status === 401 || this.status === 403) {
109
- return /invalid|expired|revoked|unauthorized/i.test(this.message);
110
- }
111
- return false;
112
- }
113
- }
114
-
115
- function createState(): string {
116
- const cryptoApi = globalThis.crypto;
117
- if (!cryptoApi) {
118
- return Math.random().toString(16).slice(2);
119
- }
120
- const bytes = new Uint8Array(16);
121
- cryptoApi.getRandomValues(bytes);
122
- return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(
123
- "",
124
- );
125
- }
126
-
127
- function toEpochMs(isoDateTime: string): number {
128
- const epoch = Date.parse(isoDateTime);
129
- if (Number.isNaN(epoch)) {
130
- throw new Error(`Invalid expiresAt value: ${isoDateTime}`);
131
- }
132
- return epoch;
133
- }
134
-
135
- function toClineCredentials(
136
- responseData: ClineAuthResponseData,
137
- provider: string | undefined,
138
- fallback: Partial<ClineOAuthCredentials> = {},
139
- ): ClineOAuthCredentials {
140
- const accountId = responseData.userInfo.clineUserId ?? fallback.accountId;
141
- const refreshToken = responseData.refreshToken ?? fallback.refresh;
142
-
143
- if (!refreshToken) {
144
- throw new Error("Token response did not include a refresh token");
145
- }
146
-
147
- return {
148
- access: responseData.accessToken,
149
- refresh: refreshToken,
150
- expires: toEpochMs(responseData.expiresAt),
151
- accountId: accountId ?? undefined,
152
- email: responseData.userInfo.email || fallback.email,
153
- metadata: {
154
- provider,
155
- tokenType: responseData.tokenType,
156
- userInfo: responseData.userInfo,
157
- },
158
- };
159
- }
160
-
161
- async function resolveHeaders(input?: HeaderInput): Promise<HeaderMap> {
162
- if (!input) {
163
- return {};
164
- }
165
- return typeof input === "function" ? await input() : input;
166
- }
167
-
168
- async function requestAuthorizationUrl(
169
- options: ClineOAuthProviderOptions,
170
- params: {
171
- callbackUrl: string;
172
- state: string;
173
- },
174
- ): Promise<string> {
175
- const authUrl = new URL(
176
- resolveUrl(options.apiBaseUrl, DEFAULT_AUTH_ENDPOINTS.authorize),
177
- );
178
- authUrl.searchParams.set("client_type", "extension");
179
- authUrl.searchParams.set("callback_url", params.callbackUrl);
180
- authUrl.searchParams.set("redirect_uri", params.callbackUrl);
181
- authUrl.searchParams.set("state", params.state);
182
-
183
- return authUrl.toString();
184
- }
185
-
186
- async function exchangeAuthorizationCode(
187
- code: string,
188
- callbackUrl: string,
189
- options: ClineOAuthProviderOptions,
190
- provider?: string,
191
- ): Promise<ClineOAuthCredentials> {
192
- const body = {
193
- grant_type: "authorization_code",
194
- code,
195
- client_type: "extension",
196
- redirect_uri: callbackUrl,
197
- provider: provider ?? options.provider,
198
- };
199
-
200
- const response = await fetch(
201
- resolveUrl(options.apiBaseUrl, DEFAULT_AUTH_ENDPOINTS.token),
202
- {
203
- method: "POST",
204
- headers: {
205
- "Content-Type": "application/json",
206
- ...(await resolveHeaders(options.headers)),
207
- },
208
- body: JSON.stringify(body),
209
- signal: AbortSignal.timeout(
210
- options.requestTimeoutMs ?? DEFAULT_HTTP_TIMEOUT_MS,
211
- ),
212
- },
213
- );
214
-
215
- if (!response.ok) {
216
- const text = await response.text().catch(() => "");
217
- const details = parseOAuthError(text);
218
- throw new ClineOAuthTokenError(
219
- `Token exchange failed: ${response.status}${details.message ? ` - ${details.message}` : ""}`,
220
- { status: response.status, errorCode: details.code },
221
- );
222
- }
223
-
224
- const json = (await response.json()) as ClineTokenResponse;
225
- if (!json.success || !json.data?.accessToken) {
226
- throw new Error("Invalid token exchange response");
227
- }
228
-
229
- return toClineCredentials(json.data, provider ?? options.provider);
230
- }
231
-
232
- export async function loginClineOAuth(
233
- options: ClineOAuthProviderOptions & {
234
- callbacks: OAuthLoginCallbacks;
235
- },
236
- ): Promise<ClineOAuthCredentials> {
237
- captureAuthStarted(options.telemetry, options.provider ?? "cline");
238
- const callbackPorts = options.callbackPorts?.length
239
- ? options.callbackPorts
240
- : DEFAULT_CALLBACK_PORTS;
241
- const callbackPath = options.callbackPath ?? DEFAULT_CALLBACK_PATH;
242
- const state = createState();
243
-
244
- const localServer = await startLocalOAuthServer({
245
- ports: callbackPorts,
246
- callbackPath,
247
- });
248
-
249
- const callbackUrl =
250
- localServer.callbackUrl ||
251
- `http://127.0.0.1:${callbackPorts[0] ?? DEFAULT_CALLBACK_PORTS[0]}${callbackPath}`;
252
-
253
- const authUrl = await requestAuthorizationUrl(options, {
254
- callbackUrl,
255
- state,
256
- });
257
- options.callbacks.onAuth({
258
- url: authUrl,
259
- instructions: "Continue the authentication process in your browser.",
260
- });
261
-
262
- try {
263
- let code: string | undefined;
264
- let provider = options.provider;
265
-
266
- const authResult = await resolveAuthorizationCodeInput({
267
- waitForCallback: localServer.waitForCallback,
268
- cancelWait: localServer.cancelWait,
269
- onManualCodeInput: options.callbacks.onManualCodeInput,
270
- parseOptions: { includeProvider: true },
271
- });
272
- if (authResult.error) {
273
- throw new Error(`OAuth error: ${authResult.error}`);
274
- }
275
- if (authResult.state && authResult.state !== state) {
276
- throw new Error("State mismatch");
277
- }
278
- code = authResult.code;
279
- provider = authResult.provider ?? provider;
280
-
281
- if (!code) {
282
- const input = await options.callbacks.onPrompt({
283
- message: "Paste the authorization code (or full redirect URL):",
284
- });
285
- const parsed = parseAuthorizationInput(input, { includeProvider: true });
286
- if (parsed.state && parsed.state !== state) {
287
- throw new Error("State mismatch");
288
- }
289
- code = parsed.code;
290
- provider = parsed.provider ?? provider;
291
- }
292
-
293
- if (!code) {
294
- throw new Error("Missing authorization code");
295
- }
296
-
297
- const credentials = await exchangeAuthorizationCode(
298
- code,
299
- callbackUrl,
300
- options,
301
- provider,
302
- );
303
- captureAuthSucceeded(options.telemetry, provider ?? "cline");
304
- identifyAccount(options.telemetry, {
305
- id: credentials.accountId,
306
- email: credentials.email,
307
- provider: provider ?? "cline",
308
- });
309
- return credentials;
310
- } catch (error) {
311
- captureAuthFailed(
312
- options.telemetry,
313
- options.provider ?? "cline",
314
- error instanceof Error ? error.message : String(error),
315
- );
316
- throw error;
317
- } finally {
318
- localServer.close();
319
- }
320
- }
321
-
322
- export async function refreshClineToken(
323
- current: ClineOAuthCredentials,
324
- options: ClineOAuthProviderOptions,
325
- ): Promise<ClineOAuthCredentials> {
326
- const response = await fetch(
327
- resolveUrl(options.apiBaseUrl, DEFAULT_AUTH_ENDPOINTS.refresh),
328
- {
329
- method: "POST",
330
- headers: {
331
- "Content-Type": "application/json",
332
- ...(await resolveHeaders(options.headers)),
333
- },
334
- body: JSON.stringify({
335
- refreshToken: current.refresh,
336
- grantType: "refresh_token",
337
- }),
338
- signal: AbortSignal.timeout(
339
- options.requestTimeoutMs ?? DEFAULT_HTTP_TIMEOUT_MS,
340
- ),
341
- },
342
- );
343
-
344
- if (!response.ok) {
345
- const text = await response.text().catch(() => "");
346
- const details = parseOAuthError(text);
347
- throw new ClineOAuthTokenError(
348
- `Token refresh failed: ${response.status}${details.message ? ` - ${details.message}` : ""}`,
349
- { status: response.status, errorCode: details.code },
350
- );
351
- }
352
-
353
- const json = (await response.json()) as ClineTokenResponse;
354
- if (!json.success || !json.data?.accessToken) {
355
- throw new Error("Invalid token refresh response");
356
- }
357
-
358
- const provider =
359
- (current.metadata?.provider as string | undefined) ?? options.provider;
360
- return toClineCredentials(json.data, provider, current);
361
- }
362
-
363
- export async function getValidClineCredentials(
364
- currentCredentials: ClineOAuthCredentials | null,
365
- providerOptions: ClineOAuthProviderOptions,
366
- options?: ClineTokenResolution,
367
- ): Promise<ClineOAuthCredentials | null> {
368
- if (!currentCredentials) {
369
- return null;
370
- }
371
-
372
- const refreshBufferMs = options?.refreshBufferMs ?? DEFAULT_REFRESH_BUFFER_MS;
373
- const retryableTokenGraceMs =
374
- options?.retryableTokenGraceMs ?? DEFAULT_RETRYABLE_TOKEN_GRACE_MS;
375
- const forceRefresh = options?.forceRefresh === true;
376
-
377
- if (
378
- !forceRefresh &&
379
- !isCredentialLikelyExpired(currentCredentials, refreshBufferMs)
380
- ) {
381
- return currentCredentials;
382
- }
383
-
384
- try {
385
- return await refreshClineToken(currentCredentials, providerOptions);
386
- } catch (error) {
387
- if (error instanceof ClineOAuthTokenError && error.isLikelyInvalidGrant()) {
388
- captureAuthLoggedOut(
389
- providerOptions.telemetry,
390
- providerOptions.provider ?? "cline",
391
- "invalid_grant",
392
- );
393
- return null;
394
- }
395
- if (currentCredentials.expires - Date.now() > retryableTokenGraceMs) {
396
- // Keep current token on transient refresh failures while still valid.
397
- return currentCredentials;
398
- }
399
- return null;
400
- }
401
- }
402
-
403
- export function createClineOAuthProvider(
404
- options: ClineOAuthProviderOptions,
405
- ): OAuthProviderInterface {
406
- return {
407
- id: "cline",
408
- name: "Cline Account",
409
- usesCallbackServer: true,
410
- async login(callbacks) {
411
- return loginClineOAuth({ ...options, callbacks });
412
- },
413
- async refreshToken(credentials) {
414
- return refreshClineToken(credentials as ClineOAuthCredentials, options);
415
- },
416
- getApiKey(credentials) {
417
- return `workos:${credentials.access}`;
418
- },
419
- };
420
- }
@@ -1,170 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
- import {
3
- getValidOpenAICodexCredentials,
4
- normalizeOpenAICodexCredentials,
5
- refreshOpenAICodexToken,
6
- } from "./codex.js";
7
- import type { OAuthCredentials } from "./types.js";
8
-
9
- function toBase64Url(value: string): string {
10
- return Buffer.from(value, "utf8").toString("base64url");
11
- }
12
-
13
- function createJwt(payload: Record<string, unknown>): string {
14
- return `${toBase64Url(JSON.stringify({ alg: "none", typ: "JWT" }))}.${toBase64Url(JSON.stringify(payload))}.sig`;
15
- }
16
-
17
- function createCredentials(
18
- overrides: Partial<OAuthCredentials> = {},
19
- ): OAuthCredentials {
20
- return {
21
- access: "access-old",
22
- refresh: "refresh-old",
23
- expires: 0,
24
- accountId: "acct-old",
25
- email: "old@example.com",
26
- metadata: { provider: "openai-codex" },
27
- ...overrides,
28
- };
29
- }
30
-
31
- describe("auth/codex token lifecycle", () => {
32
- afterEach(() => {
33
- vi.unstubAllGlobals();
34
- vi.restoreAllMocks();
35
- });
36
-
37
- it("returns current credentials when not expired", async () => {
38
- const nowSpy = vi.spyOn(Date, "now").mockReturnValue(10_000);
39
- const current = createCredentials({ expires: 400_000 });
40
- const fetchMock = vi.fn();
41
- vi.stubGlobal("fetch", fetchMock);
42
-
43
- const result = await getValidOpenAICodexCredentials(current);
44
- expect(result).toBe(current);
45
- expect(fetchMock).not.toHaveBeenCalled();
46
- nowSpy.mockRestore();
47
- });
48
-
49
- it("refreshes expired credentials and preserves provider metadata", async () => {
50
- const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
51
- const idToken = createJwt({
52
- "https://api.openai.com/auth": { chatgpt_account_id: "acct-new" },
53
- email: "new@example.com",
54
- });
55
- const accessToken = createJwt({
56
- "https://api.openai.com/auth": { chatgpt_account_id: "acct-new" },
57
- });
58
- vi.stubGlobal(
59
- "fetch",
60
- vi.fn(
61
- async () =>
62
- new Response(
63
- JSON.stringify({
64
- access_token: accessToken,
65
- refresh_token: "refresh-new",
66
- expires_in: 3600,
67
- email: "new@example.com",
68
- id_token: idToken,
69
- }),
70
- { status: 200, headers: { "Content-Type": "application/json" } },
71
- ),
72
- ),
73
- );
74
-
75
- const current = createCredentials({ expires: 110_000 });
76
- const result = await getValidOpenAICodexCredentials(current);
77
- expect(result).toMatchObject({
78
- access: accessToken,
79
- refresh: "refresh-new",
80
- accountId: "acct-new",
81
- email: "new@example.com",
82
- metadata: { provider: "openai-codex" },
83
- });
84
- nowSpy.mockRestore();
85
- });
86
-
87
- it("returns null on invalid_grant refresh errors", async () => {
88
- const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
89
- vi.stubGlobal(
90
- "fetch",
91
- vi.fn(
92
- async () =>
93
- new Response(
94
- JSON.stringify({
95
- error: "invalid_grant",
96
- error_description: "token revoked",
97
- }),
98
- {
99
- status: 400,
100
- headers: { "Content-Type": "application/json" },
101
- },
102
- ),
103
- ),
104
- );
105
-
106
- const result = await getValidOpenAICodexCredentials(
107
- createCredentials({ expires: 120_000 }),
108
- );
109
- expect(result).toBeNull();
110
- nowSpy.mockRestore();
111
- });
112
-
113
- it("keeps current credentials on non-invalid transient refresh failures when still valid", async () => {
114
- const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
115
- vi.stubGlobal(
116
- "fetch",
117
- vi.fn(
118
- async () =>
119
- new Response(
120
- JSON.stringify({
121
- error: "server_error",
122
- error_description: "try again",
123
- }),
124
- {
125
- status: 500,
126
- headers: { "Content-Type": "application/json" },
127
- },
128
- ),
129
- ),
130
- );
131
-
132
- const current = createCredentials({ expires: 150_000 });
133
- const result = await getValidOpenAICodexCredentials(current, {
134
- refreshBufferMs: 60_000,
135
- retryableTokenGraceMs: 30_000,
136
- });
137
- expect(result).toBe(current);
138
- nowSpy.mockRestore();
139
- });
140
-
141
- it("normalizes credentials by deriving accountId from access token", () => {
142
- const accessToken = createJwt({
143
- "https://api.openai.com/auth": { chatgpt_account_id: "acct-derived" },
144
- });
145
- const normalized = normalizeOpenAICodexCredentials({
146
- access: accessToken,
147
- refresh: "refresh",
148
- expires: 1,
149
- });
150
- expect(normalized.accountId).toBe("acct-derived");
151
- expect(normalized.metadata).toMatchObject({ provider: "openai-codex" });
152
- });
153
-
154
- it("refreshOpenAICodexToken throws when response is structurally invalid", async () => {
155
- vi.stubGlobal(
156
- "fetch",
157
- vi.fn(
158
- async () =>
159
- new Response(JSON.stringify({ access_token: "only-access" }), {
160
- status: 200,
161
- headers: { "Content-Type": "application/json" },
162
- }),
163
- ),
164
- );
165
-
166
- await expect(refreshOpenAICodexToken("refresh")).rejects.toThrow(
167
- "Failed to refresh OpenAI Codex token",
168
- );
169
- });
170
- });