@clinebot/core 0.0.18 → 0.0.21

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,216 +0,0 @@
1
- export interface OAuthCallbackPayload {
2
- url: URL;
3
- code?: string;
4
- state?: string;
5
- provider?: string;
6
- error?: string;
7
- }
8
-
9
- type Deferred<T> = {
10
- promise: Promise<T>;
11
- resolve: (value: T) => void;
12
- };
13
-
14
- function createDeferred<T>(): Deferred<T> {
15
- let resolve!: (value: T) => void;
16
- const promise = new Promise<T>((res) => {
17
- resolve = res;
18
- });
19
- return { promise, resolve };
20
- }
21
-
22
- export interface LocalOAuthServerOptions {
23
- host?: string;
24
- ports: number[];
25
- callbackPath: string;
26
- timeoutMs?: number;
27
- expectedState?: string;
28
- successHtml?: string;
29
- }
30
-
31
- export interface LocalOAuthServer {
32
- callbackUrl: string;
33
- waitForCallback: () => Promise<OAuthCallbackPayload | null>;
34
- cancelWait: () => void;
35
- close: () => void;
36
- }
37
-
38
- export async function startLocalOAuthServer(
39
- options: LocalOAuthServerOptions,
40
- ): Promise<LocalOAuthServer> {
41
- const http = await import("node:http");
42
-
43
- const host = options.host ?? "127.0.0.1";
44
- const timeoutMs = options.timeoutMs ?? 5 * 60 * 1000;
45
- const successHtml = options.successHtml ?? HTML_CONTENT;
46
-
47
- const deferred = createDeferred<OAuthCallbackPayload | null>();
48
- let settled = false;
49
- let timeout: ReturnType<typeof setTimeout> | null = null;
50
- let activeServer: import("node:http").Server | null = null;
51
-
52
- const settle = (value: OAuthCallbackPayload | null) => {
53
- if (settled) return;
54
- settled = true;
55
- deferred.resolve(value);
56
- };
57
-
58
- const close = () => {
59
- if (timeout) {
60
- clearTimeout(timeout);
61
- timeout = null;
62
- }
63
- if (activeServer) {
64
- activeServer.close();
65
- activeServer = null;
66
- }
67
- };
68
-
69
- const waitForCallback = async () => {
70
- timeout = setTimeout(() => {
71
- close();
72
- settle(null);
73
- }, timeoutMs);
74
- return deferred.promise;
75
- };
76
-
77
- for (const port of options.ports) {
78
- const server = http.createServer((req, res) => {
79
- try {
80
- const requestUrl = new URL(req.url || "", `http://${host}:${port}`);
81
- if (requestUrl.pathname !== options.callbackPath) {
82
- res.statusCode = 404;
83
- res.end("Not found");
84
- return;
85
- }
86
-
87
- const payload: OAuthCallbackPayload = {
88
- url: requestUrl,
89
- code: requestUrl.searchParams.get("code") ?? undefined,
90
- state: requestUrl.searchParams.get("state") ?? undefined,
91
- provider: requestUrl.searchParams.get("provider") ?? undefined,
92
- error: requestUrl.searchParams.get("error") ?? undefined,
93
- };
94
-
95
- if (payload.error) {
96
- res.statusCode = 400;
97
- res.end(`Authentication failed: ${payload.error}`);
98
- close();
99
- settle(payload);
100
- return;
101
- }
102
-
103
- if (!payload.code) {
104
- res.statusCode = 400;
105
- res.end("Missing authorization code");
106
- return;
107
- }
108
-
109
- if (options.expectedState && payload.state !== options.expectedState) {
110
- res.statusCode = 400;
111
- res.end("State mismatch");
112
- return;
113
- }
114
-
115
- res.statusCode = 200;
116
- res.setHeader("Content-Type", "text/html; charset=utf-8");
117
- res.end(successHtml);
118
- close();
119
- settle(payload);
120
- } catch {
121
- res.statusCode = 500;
122
- res.end("Internal error");
123
- }
124
- });
125
-
126
- const bindResult = await new Promise<{
127
- bound: boolean;
128
- error?: NodeJS.ErrnoException;
129
- }>((resolve) => {
130
- const onError = (error: NodeJS.ErrnoException) => {
131
- server.off("error", onError);
132
- resolve({ bound: false, error });
133
- };
134
-
135
- server.once("error", onError);
136
- server.listen(port, host, () => {
137
- server.off("error", onError);
138
- activeServer = server;
139
- resolve({ bound: true });
140
- });
141
- });
142
-
143
- if (bindResult.error) {
144
- if (bindResult.error.code === "EADDRINUSE") {
145
- continue;
146
- }
147
- close();
148
- throw bindResult.error;
149
- }
150
-
151
- if (bindResult.bound) {
152
- return {
153
- callbackUrl: `http://${host}:${port}${options.callbackPath}`,
154
- waitForCallback,
155
- cancelWait: () => {
156
- close();
157
- settle(null);
158
- },
159
- close: () => {
160
- close();
161
- settle(null);
162
- },
163
- };
164
- }
165
- }
166
-
167
- return {
168
- callbackUrl: "",
169
- waitForCallback: async () => null,
170
- cancelWait: () => {},
171
- close: () => {},
172
- };
173
- }
174
-
175
- const HTML_CONTENT = `<!DOCTYPE html>
176
- <html lang="en">
177
- <head>
178
- <meta charset="utf-8">
179
- <meta name="viewport" content="width=device-width, initial-scale=1">
180
- <title>Authentication Successful</title>
181
- <style>
182
- * { margin: 0; padding: 0; box-sizing: border-box; }
183
- body {
184
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
185
- min-height: 100vh;
186
- display: flex;
187
- align-items: center;
188
- justify-content: center;
189
- background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
190
- color: #fff;
191
- }
192
- .container { text-align: center; padding: 48px; max-width: 420px; }
193
- .icon {
194
- width: 72px; height: 72px; margin: 0 auto 24px;
195
- background: linear-gradient(135deg, #10a37f 0%, #1a7f64 100%);
196
- border-radius: 50%;
197
- display: flex; align-items: center; justify-content: center;
198
- }
199
- .icon svg { width: 36px; height: 36px; stroke: #fff; stroke-width: 3; fill: none; }
200
- h1 { font-size: 24px; font-weight: 600; margin-bottom: 12px; }
201
- p { font-size: 15px; color: rgba(255,255,255,0.7); line-height: 1.5; }
202
- .closing { margin-top: 32px; font-size: 13px; color: rgba(255,255,255,0.5); }
203
- </style>
204
- </head>
205
- <body>
206
- <div class="container">
207
- <div class="icon">
208
- <svg viewBox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg>
209
- </div>
210
- <h1>Authentication Successful</h1>
211
- <p>You're now signed in. You can close this window.</p>
212
- <p class="closing">This window will close automatically...</p>
213
- </div>
214
- <script>setTimeout(() => window.close(), 3000);</script>
215
- </body>
216
- </html>`;
package/src/auth/types.ts DELETED
@@ -1,81 +0,0 @@
1
- import type { ITelemetryService } from "@clinebot/shared";
2
-
3
- export interface OAuthPrompt {
4
- message: string;
5
- defaultValue?: string;
6
- }
7
-
8
- export interface OAuthCredentials {
9
- access: string;
10
- refresh: string;
11
- /**
12
- * Expiration timestamp in milliseconds since epoch.
13
- */
14
- expires: number;
15
- /**
16
- * Optional provider-specific account identifier.
17
- */
18
- accountId?: string;
19
- /**
20
- * Optional email for display/telemetry.
21
- */
22
- email?: string;
23
- /**
24
- * Provider-specific metadata (user info, provider hint, etc).
25
- */
26
- metadata?: Record<string, unknown>;
27
- }
28
-
29
- export interface OAuthLoginCallbacks {
30
- onAuth: (info: { url: string; instructions?: string }) => void;
31
- onPrompt: (prompt: OAuthPrompt) => Promise<string>;
32
- onProgress?: (message: string) => void;
33
- onManualCodeInput?: () => Promise<string>;
34
- }
35
-
36
- export interface OAuthProviderInterface {
37
- id: string;
38
- name: string;
39
- usesCallbackServer: boolean;
40
- login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
41
- refreshToken(credentials: OAuthCredentials): Promise<OAuthCredentials>;
42
- getApiKey(credentials: OAuthCredentials): string;
43
- }
44
-
45
- export type OcaMode = "internal" | "external";
46
-
47
- export interface OcaOAuthEnvironmentConfig {
48
- clientId: string;
49
- idcsUrl: string;
50
- scopes: string;
51
- baseUrl: string;
52
- }
53
-
54
- export interface OcaOAuthConfig {
55
- internal: OcaOAuthEnvironmentConfig;
56
- external: OcaOAuthEnvironmentConfig;
57
- }
58
-
59
- export interface OcaClientMetadata {
60
- client?: string;
61
- clientVersion?: string;
62
- clientIde?: string;
63
- clientIdeVersion?: string;
64
- }
65
-
66
- export interface OcaOAuthProviderOptions {
67
- config?: Partial<OcaOAuthConfig>;
68
- mode?: OcaMode | (() => OcaMode);
69
- callbackPath?: string;
70
- callbackPorts?: number[];
71
- requestTimeoutMs?: number;
72
- refreshBufferMs?: number;
73
- retryableTokenGraceMs?: number;
74
- telemetry?: ITelemetryService;
75
- }
76
-
77
- export interface OcaTokenResolution {
78
- forceRefresh?: boolean;
79
- refreshBufferMs?: number;
80
- retryableTokenGraceMs?: number;
81
- }
@@ -1,128 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import {
3
- decodeJwtPayload,
4
- isCredentialLikelyExpired,
5
- parseAuthorizationInput,
6
- parseOAuthError,
7
- resolveAuthorizationCodeInput,
8
- resolveUrl,
9
- } from "./utils.js";
10
-
11
- function toBase64Url(value: string): string {
12
- return Buffer.from(value, "utf8").toString("base64url");
13
- }
14
-
15
- function createJwt(payload: Record<string, unknown>): string {
16
- return `${toBase64Url(JSON.stringify({ alg: "none", typ: "JWT" }))}.${toBase64Url(JSON.stringify(payload))}.sig`;
17
- }
18
-
19
- describe("auth/utils", () => {
20
- it("parses auth input from full URL with provider", () => {
21
- const parsed = parseAuthorizationInput(
22
- "http://localhost/callback?code=test-code&state=s1&provider=google",
23
- {
24
- includeProvider: true,
25
- },
26
- );
27
- expect(parsed).toEqual({
28
- code: "test-code",
29
- state: "s1",
30
- provider: "google",
31
- });
32
- });
33
-
34
- it("parses auth input from hash format when enabled", () => {
35
- const parsed = parseAuthorizationInput("abc123#state1", {
36
- allowHashCodeState: true,
37
- });
38
- expect(parsed).toEqual({ code: "abc123", state: "state1" });
39
- });
40
-
41
- it("builds resolved URLs from base + path", () => {
42
- expect(resolveUrl("https://example.com/", "/token")).toBe(
43
- "https://example.com/token",
44
- );
45
- });
46
-
47
- it("decodes JWT payload", () => {
48
- const token = createJwt({ sub: "account-1", exp: 123 });
49
- expect(decodeJwtPayload(token)).toMatchObject({
50
- sub: "account-1",
51
- exp: 123,
52
- });
53
- expect(decodeJwtPayload("invalid")).toBeNull();
54
- });
55
-
56
- it("parses OAuth error payloads from string and object forms", () => {
57
- expect(
58
- parseOAuthError(
59
- JSON.stringify({
60
- error: "invalid_grant",
61
- error_description: "expired",
62
- }),
63
- ),
64
- ).toEqual({
65
- code: "invalid_grant",
66
- message: "expired",
67
- });
68
- expect(
69
- parseOAuthError(
70
- JSON.stringify({ error: { type: "unauthorized", message: "denied" } }),
71
- ),
72
- ).toEqual({
73
- code: "unauthorized",
74
- message: "denied",
75
- });
76
- });
77
-
78
- it("resolves code from callback result", async () => {
79
- const result = await resolveAuthorizationCodeInput({
80
- waitForCallback: async () => ({
81
- url: new URL("http://localhost"),
82
- code: "from-callback",
83
- state: "s1",
84
- }),
85
- cancelWait: () => {},
86
- });
87
- expect(result).toEqual({
88
- code: "from-callback",
89
- state: "s1",
90
- provider: undefined,
91
- error: undefined,
92
- });
93
- });
94
-
95
- it("resolves code from manual input when callback does not provide one", async () => {
96
- const cancelWait = vi.fn();
97
- const result = await resolveAuthorizationCodeInput({
98
- waitForCallback: async () => null,
99
- cancelWait,
100
- onManualCodeInput: async () => "code=manual&state=manual-state",
101
- });
102
- expect(cancelWait).toHaveBeenCalled();
103
- expect(result).toEqual({
104
- code: "manual",
105
- state: "manual-state",
106
- provider: undefined,
107
- });
108
- });
109
-
110
- it("throws when manual input rejects", async () => {
111
- await expect(
112
- resolveAuthorizationCodeInput({
113
- waitForCallback: async () => null,
114
- cancelWait: () => {},
115
- onManualCodeInput: async () => {
116
- throw new Error("cancelled");
117
- },
118
- }),
119
- ).rejects.toThrow("cancelled");
120
- });
121
-
122
- it("checks token expiry with configurable buffer", () => {
123
- const nowSpy = vi.spyOn(Date, "now").mockReturnValue(1_000);
124
- expect(isCredentialLikelyExpired({ expires: 1_500 }, 600)).toBe(true);
125
- expect(isCredentialLikelyExpired({ expires: 3_000 }, 600)).toBe(false);
126
- nowSpy.mockRestore();
127
- });
128
- });
package/src/auth/utils.ts DELETED
@@ -1,247 +0,0 @@
1
- import type { OAuthCallbackPayload } from "./server.js";
2
- import type { OAuthCredentials } from "./types.js";
3
-
4
- function base64UrlEncode(input: Uint8Array): string {
5
- let binary = "";
6
- for (let i = 0; i < input.length; i += 1) {
7
- binary += String.fromCharCode(input[i] ?? 0);
8
- }
9
- return btoa(binary)
10
- .replace(/\+/g, "-")
11
- .replace(/\//g, "_")
12
- .replace(/=+$/g, "");
13
- }
14
-
15
- async function sha256(value: string): Promise<Uint8Array> {
16
- const encoder = new TextEncoder();
17
- const data = encoder.encode(value);
18
- const digest = await crypto.subtle.digest("SHA-256", data);
19
- return new Uint8Array(digest);
20
- }
21
-
22
- function createVerifier(byteLength = 32): string {
23
- const randomBytes = new Uint8Array(byteLength);
24
- crypto.getRandomValues(randomBytes);
25
- return base64UrlEncode(randomBytes);
26
- }
27
-
28
- export async function getProofKey(): Promise<{
29
- verifier: string;
30
- challenge: string;
31
- }> {
32
- const verifier = createVerifier();
33
- const challenge = base64UrlEncode(await sha256(verifier));
34
- return { verifier, challenge };
35
- }
36
-
37
- export function normalizeBaseUrl(value: string): string {
38
- return value.endsWith("/") ? value.slice(0, -1) : value;
39
- }
40
-
41
- export function resolveUrl(baseUrl: string, path: string): string {
42
- return new URL(path, `${normalizeBaseUrl(baseUrl)}/`).toString();
43
- }
44
-
45
- export type ParsedAuthorizationInput = {
46
- code?: string;
47
- state?: string;
48
- provider?: string;
49
- };
50
-
51
- export type ParseAuthorizationInputOptions = {
52
- includeProvider?: boolean;
53
- allowHashCodeState?: boolean;
54
- };
55
-
56
- export function parseAuthorizationInput(
57
- input: string,
58
- options: ParseAuthorizationInputOptions = {},
59
- ): ParsedAuthorizationInput {
60
- const value = input.trim();
61
- if (!value) {
62
- return {};
63
- }
64
-
65
- try {
66
- const url = new URL(value);
67
- return {
68
- code: url.searchParams.get("code") ?? undefined,
69
- state: url.searchParams.get("state") ?? undefined,
70
- provider: options.includeProvider
71
- ? (url.searchParams.get("provider") ?? undefined)
72
- : undefined,
73
- };
74
- } catch {
75
- // not a URL
76
- }
77
-
78
- if (options.allowHashCodeState && value.includes("#")) {
79
- const [code, state] = value.split("#", 2);
80
- return {
81
- code: code || undefined,
82
- state: state || undefined,
83
- };
84
- }
85
-
86
- if (value.includes("code=")) {
87
- const params = new URLSearchParams(value);
88
- return {
89
- code: params.get("code") ?? undefined,
90
- state: params.get("state") ?? undefined,
91
- provider: options.includeProvider
92
- ? (params.get("provider") ?? undefined)
93
- : undefined,
94
- };
95
- }
96
-
97
- return { code: value };
98
- }
99
-
100
- function decodeBase64(value: string): string | null {
101
- if (typeof atob === "function") {
102
- try {
103
- return atob(value);
104
- } catch {
105
- return null;
106
- }
107
- }
108
-
109
- if (typeof Buffer !== "undefined") {
110
- try {
111
- return Buffer.from(value, "base64").toString("utf8");
112
- } catch {
113
- return null;
114
- }
115
- }
116
-
117
- return null;
118
- }
119
-
120
- export function decodeJwtPayload(
121
- token?: string,
122
- ): Record<string, unknown> | null {
123
- if (!token) {
124
- return null;
125
- }
126
-
127
- try {
128
- const parts = token.split(".");
129
- if (parts.length !== 3) {
130
- return null;
131
- }
132
-
133
- const payload = parts[1];
134
- if (!payload) {
135
- return null;
136
- }
137
-
138
- const normalized = payload.replace(/-/g, "+").replace(/_/g, "/");
139
- const padded = normalized.padEnd(
140
- normalized.length + ((4 - (normalized.length % 4)) % 4),
141
- "=",
142
- );
143
- const decoded = decodeBase64(padded);
144
- if (!decoded) {
145
- return null;
146
- }
147
- return JSON.parse(decoded) as Record<string, unknown>;
148
- } catch {
149
- return null;
150
- }
151
- }
152
-
153
- export function parseOAuthError(text: string): {
154
- code?: string;
155
- message?: string;
156
- } {
157
- try {
158
- const json = JSON.parse(text) as Record<string, unknown>;
159
- const error = json.error;
160
- const code =
161
- typeof error === "string"
162
- ? error
163
- : error &&
164
- typeof error === "object" &&
165
- typeof (error as Record<string, unknown>).type === "string"
166
- ? ((error as Record<string, unknown>).type as string)
167
- : undefined;
168
- const message =
169
- typeof json.error_description === "string"
170
- ? json.error_description
171
- : typeof json.message === "string"
172
- ? json.message
173
- : error &&
174
- typeof error === "object" &&
175
- typeof (error as Record<string, unknown>).message === "string"
176
- ? ((error as Record<string, unknown>).message as string)
177
- : undefined;
178
- return { code, message };
179
- } catch {
180
- return {};
181
- }
182
- }
183
-
184
- export function isCredentialLikelyExpired(
185
- credentials: Pick<OAuthCredentials, "expires">,
186
- refreshBufferMs: number,
187
- ): boolean {
188
- return Date.now() >= credentials.expires - refreshBufferMs;
189
- }
190
-
191
- export async function resolveAuthorizationCodeInput(input: {
192
- waitForCallback: () => Promise<OAuthCallbackPayload | null>;
193
- cancelWait: () => void;
194
- onManualCodeInput?: () => Promise<string>;
195
- parseOptions?: ParseAuthorizationInputOptions;
196
- }): Promise<ParsedAuthorizationInput & { error?: string }> {
197
- if (!input.onManualCodeInput) {
198
- const callbackResult = await input.waitForCallback();
199
- return {
200
- code: callbackResult?.code,
201
- state: callbackResult?.state,
202
- provider: callbackResult?.provider,
203
- error: callbackResult?.error,
204
- };
205
- }
206
-
207
- let manualInput: string | undefined;
208
- let manualError: Error | undefined;
209
- const manualPromise = input
210
- .onManualCodeInput()
211
- .then((value) => {
212
- manualInput = value;
213
- input.cancelWait();
214
- })
215
- .catch((error: unknown) => {
216
- manualError = error instanceof Error ? error : new Error(String(error));
217
- input.cancelWait();
218
- });
219
-
220
- const callbackResult = await input.waitForCallback();
221
- if (manualError) {
222
- throw manualError;
223
- }
224
-
225
- if (callbackResult?.code || callbackResult?.error) {
226
- return {
227
- code: callbackResult.code,
228
- state: callbackResult.state,
229
- provider: callbackResult.provider,
230
- error: callbackResult.error,
231
- };
232
- }
233
-
234
- if (manualInput) {
235
- return parseAuthorizationInput(manualInput, input.parseOptions);
236
- }
237
-
238
- await manualPromise;
239
- if (manualError) {
240
- throw manualError;
241
- }
242
- if (manualInput) {
243
- return parseAuthorizationInput(manualInput, input.parseOptions);
244
- }
245
-
246
- return {};
247
- }