@hold-rein/cli 0.0.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 (420) hide show
  1. package/dist/cli.js +3 -0
  2. package/dist/cli.js.map +1 -0
  3. package/dist/index.js +139 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/runtime/api/app.d.ts +7 -0
  6. package/dist/runtime/api/app.d.ts.map +1 -0
  7. package/dist/runtime/api/app.js +41 -0
  8. package/dist/runtime/api/config/const.d.ts +8 -0
  9. package/dist/runtime/api/config/const.d.ts.map +1 -0
  10. package/dist/runtime/api/config/const.js +9 -0
  11. package/dist/runtime/api/config/env.d.ts +10 -0
  12. package/dist/runtime/api/config/env.d.ts.map +1 -0
  13. package/dist/runtime/api/config/env.js +32 -0
  14. package/dist/runtime/api/db/connection.d.ts +11 -0
  15. package/dist/runtime/api/db/connection.d.ts.map +1 -0
  16. package/dist/runtime/api/db/connection.js +21 -0
  17. package/dist/runtime/api/db/index.d.ts +4 -0
  18. package/dist/runtime/api/db/index.d.ts.map +1 -0
  19. package/dist/runtime/api/db/index.js +3 -0
  20. package/dist/runtime/api/db/migrate.d.ts +4 -0
  21. package/dist/runtime/api/db/migrate.d.ts.map +1 -0
  22. package/dist/runtime/api/db/migrate.js +308 -0
  23. package/dist/runtime/api/db/schema.d.ts +1610 -0
  24. package/dist/runtime/api/db/schema.d.ts.map +1 -0
  25. package/dist/runtime/api/db/schema.js +148 -0
  26. package/dist/runtime/api/middleware/error-middleware.d.ts +3 -0
  27. package/dist/runtime/api/middleware/error-middleware.d.ts.map +1 -0
  28. package/dist/runtime/api/middleware/error-middleware.js +5 -0
  29. package/dist/runtime/api/middleware/not-found-middleware.d.ts +3 -0
  30. package/dist/runtime/api/middleware/not-found-middleware.d.ts.map +1 -0
  31. package/dist/runtime/api/middleware/not-found-middleware.js +4 -0
  32. package/dist/runtime/api/modules/agents/active-task-run-registry.d.ts +10 -0
  33. package/dist/runtime/api/modules/agents/active-task-run-registry.d.ts.map +1 -0
  34. package/dist/runtime/api/modules/agents/active-task-run-registry.js +20 -0
  35. package/dist/runtime/api/modules/agents/agent-approval-store.d.ts +7 -0
  36. package/dist/runtime/api/modules/agents/agent-approval-store.d.ts.map +1 -0
  37. package/dist/runtime/api/modules/agents/agent-approval-store.js +23 -0
  38. package/dist/runtime/api/modules/agents/agent-event-bus.d.ts +8 -0
  39. package/dist/runtime/api/modules/agents/agent-event-bus.d.ts.map +1 -0
  40. package/dist/runtime/api/modules/agents/agent-event-bus.js +40 -0
  41. package/dist/runtime/api/modules/agents/agent-message-repository.d.ts +22 -0
  42. package/dist/runtime/api/modules/agents/agent-message-repository.d.ts.map +1 -0
  43. package/dist/runtime/api/modules/agents/agent-message-repository.js +60 -0
  44. package/dist/runtime/api/modules/agents/agent-message-storage.d.ts +4 -0
  45. package/dist/runtime/api/modules/agents/agent-message-storage.d.ts.map +1 -0
  46. package/dist/runtime/api/modules/agents/agent-message-storage.js +11 -0
  47. package/dist/runtime/api/modules/agents/agent-model-resolver.d.ts +4 -0
  48. package/dist/runtime/api/modules/agents/agent-model-resolver.d.ts.map +1 -0
  49. package/dist/runtime/api/modules/agents/agent-model-resolver.js +17 -0
  50. package/dist/runtime/api/modules/agents/agent-runtime-messages.d.ts +12 -0
  51. package/dist/runtime/api/modules/agents/agent-runtime-messages.d.ts.map +1 -0
  52. package/dist/runtime/api/modules/agents/agent-runtime-messages.js +19 -0
  53. package/dist/runtime/api/modules/agents/agent-runtime-support.d.ts +12 -0
  54. package/dist/runtime/api/modules/agents/agent-runtime-support.d.ts.map +1 -0
  55. package/dist/runtime/api/modules/agents/agent-runtime-support.js +38 -0
  56. package/dist/runtime/api/modules/agents/agent-runtime.d.ts +25 -0
  57. package/dist/runtime/api/modules/agents/agent-runtime.d.ts.map +1 -0
  58. package/dist/runtime/api/modules/agents/agent-runtime.js +371 -0
  59. package/dist/runtime/api/modules/agents/agent-subagents.d.ts +32 -0
  60. package/dist/runtime/api/modules/agents/agent-subagents.d.ts.map +1 -0
  61. package/dist/runtime/api/modules/agents/agent-subagents.js +65 -0
  62. package/dist/runtime/api/modules/agents/agent-task-actions.d.ts +9 -0
  63. package/dist/runtime/api/modules/agents/agent-task-actions.d.ts.map +1 -0
  64. package/dist/runtime/api/modules/agents/agent-task-actions.js +33 -0
  65. package/dist/runtime/api/modules/agents/agent-task-title-generator.d.ts +15 -0
  66. package/dist/runtime/api/modules/agents/agent-task-title-generator.d.ts.map +1 -0
  67. package/dist/runtime/api/modules/agents/agent-task-title-generator.js +61 -0
  68. package/dist/runtime/api/modules/agents/agent-tool-approval.d.ts +12 -0
  69. package/dist/runtime/api/modules/agents/agent-tool-approval.d.ts.map +1 -0
  70. package/dist/runtime/api/modules/agents/agent-tool-approval.js +40 -0
  71. package/dist/runtime/api/modules/agents/agent-types.d.ts +198 -0
  72. package/dist/runtime/api/modules/agents/agent-types.d.ts.map +1 -0
  73. package/dist/runtime/api/modules/agents/agent-types.js +1 -0
  74. package/dist/runtime/api/modules/agents/agents-router.d.ts +7 -0
  75. package/dist/runtime/api/modules/agents/agents-router.d.ts.map +1 -0
  76. package/dist/runtime/api/modules/agents/agents-router.js +210 -0
  77. package/dist/runtime/api/modules/agents/agents-service.d.ts +52 -0
  78. package/dist/runtime/api/modules/agents/agents-service.d.ts.map +1 -0
  79. package/dist/runtime/api/modules/agents/agents-service.js +282 -0
  80. package/dist/runtime/api/modules/agents/approval/store.d.ts +7 -0
  81. package/dist/runtime/api/modules/agents/approval/store.d.ts.map +1 -0
  82. package/dist/runtime/api/modules/agents/approval/store.js +23 -0
  83. package/dist/runtime/api/modules/agents/approval/tool-approval.d.ts +14 -0
  84. package/dist/runtime/api/modules/agents/approval/tool-approval.d.ts.map +1 -0
  85. package/dist/runtime/api/modules/agents/approval/tool-approval.js +43 -0
  86. package/dist/runtime/api/modules/agents/custom-agent-model.d.ts +16 -0
  87. package/dist/runtime/api/modules/agents/custom-agent-model.d.ts.map +1 -0
  88. package/dist/runtime/api/modules/agents/custom-agent-model.js +21 -0
  89. package/dist/runtime/api/modules/agents/default-agents-service.d.ts +3 -0
  90. package/dist/runtime/api/modules/agents/default-agents-service.d.ts.map +1 -0
  91. package/dist/runtime/api/modules/agents/default-agents-service.js +52 -0
  92. package/dist/runtime/api/modules/agents/event/event-bus.d.ts +8 -0
  93. package/dist/runtime/api/modules/agents/event/event-bus.d.ts.map +1 -0
  94. package/dist/runtime/api/modules/agents/event/event-bus.js +40 -0
  95. package/dist/runtime/api/modules/agents/index.d.ts +11 -0
  96. package/dist/runtime/api/modules/agents/index.d.ts.map +1 -0
  97. package/dist/runtime/api/modules/agents/index.js +9 -0
  98. package/dist/runtime/api/modules/agents/message/storage.d.ts +4 -0
  99. package/dist/runtime/api/modules/agents/message/storage.d.ts.map +1 -0
  100. package/dist/runtime/api/modules/agents/message/storage.js +11 -0
  101. package/dist/runtime/api/modules/agents/model/custom-model.d.ts +16 -0
  102. package/dist/runtime/api/modules/agents/model/custom-model.d.ts.map +1 -0
  103. package/dist/runtime/api/modules/agents/model/custom-model.js +21 -0
  104. package/dist/runtime/api/modules/agents/model/resolver.d.ts +4 -0
  105. package/dist/runtime/api/modules/agents/model/resolver.d.ts.map +1 -0
  106. package/dist/runtime/api/modules/agents/model/resolver.js +17 -0
  107. package/dist/runtime/api/modules/agents/router/browser-tool-result.d.ts +8 -0
  108. package/dist/runtime/api/modules/agents/router/browser-tool-result.d.ts.map +1 -0
  109. package/dist/runtime/api/modules/agents/router/browser-tool-result.js +35 -0
  110. package/dist/runtime/api/modules/agents/router/index.d.ts +10 -0
  111. package/dist/runtime/api/modules/agents/router/index.d.ts.map +1 -0
  112. package/dist/runtime/api/modules/agents/router/index.js +210 -0
  113. package/dist/runtime/api/modules/agents/router/request-parsing.d.ts +24 -0
  114. package/dist/runtime/api/modules/agents/router/request-parsing.d.ts.map +1 -0
  115. package/dist/runtime/api/modules/agents/router/request-parsing.js +78 -0
  116. package/dist/runtime/api/modules/agents/runtime/browser-runtime-contributions.d.ts +5 -0
  117. package/dist/runtime/api/modules/agents/runtime/browser-runtime-contributions.d.ts.map +1 -0
  118. package/dist/runtime/api/modules/agents/runtime/browser-runtime-contributions.js +115 -0
  119. package/dist/runtime/api/modules/agents/runtime/browser-runtime-tools.d.ts +13 -0
  120. package/dist/runtime/api/modules/agents/runtime/browser-runtime-tools.d.ts.map +1 -0
  121. package/dist/runtime/api/modules/agents/runtime/browser-runtime-tools.js +31 -0
  122. package/dist/runtime/api/modules/agents/runtime/browser-tool-call-store.d.ts +21 -0
  123. package/dist/runtime/api/modules/agents/runtime/browser-tool-call-store.d.ts.map +1 -0
  124. package/dist/runtime/api/modules/agents/runtime/browser-tool-call-store.js +69 -0
  125. package/dist/runtime/api/modules/agents/runtime/continuation-subagent.d.ts +26 -0
  126. package/dist/runtime/api/modules/agents/runtime/continuation-subagent.d.ts.map +1 -0
  127. package/dist/runtime/api/modules/agents/runtime/continuation-subagent.js +67 -0
  128. package/dist/runtime/api/modules/agents/runtime/index.d.ts +3 -0
  129. package/dist/runtime/api/modules/agents/runtime/index.d.ts.map +1 -0
  130. package/dist/runtime/api/modules/agents/runtime/index.js +432 -0
  131. package/dist/runtime/api/modules/agents/runtime/messages.d.ts +12 -0
  132. package/dist/runtime/api/modules/agents/runtime/messages.d.ts.map +1 -0
  133. package/dist/runtime/api/modules/agents/runtime/messages.js +19 -0
  134. package/dist/runtime/api/modules/agents/runtime/subagent-results.d.ts +22 -0
  135. package/dist/runtime/api/modules/agents/runtime/subagent-results.d.ts.map +1 -0
  136. package/dist/runtime/api/modules/agents/runtime/subagent-results.js +39 -0
  137. package/dist/runtime/api/modules/agents/runtime/subagent-tools.d.ts +49 -0
  138. package/dist/runtime/api/modules/agents/runtime/subagent-tools.d.ts.map +1 -0
  139. package/dist/runtime/api/modules/agents/runtime/subagent-tools.js +195 -0
  140. package/dist/runtime/api/modules/agents/runtime/support.d.ts +19 -0
  141. package/dist/runtime/api/modules/agents/runtime/support.d.ts.map +1 -0
  142. package/dist/runtime/api/modules/agents/runtime/support.js +106 -0
  143. package/dist/runtime/api/modules/agents/runtime/token-collection.d.ts +28 -0
  144. package/dist/runtime/api/modules/agents/runtime/token-collection.d.ts.map +1 -0
  145. package/dist/runtime/api/modules/agents/runtime/token-collection.js +131 -0
  146. package/dist/runtime/api/modules/agents/runtime/token-usage-sync.d.ts +15 -0
  147. package/dist/runtime/api/modules/agents/runtime/token-usage-sync.d.ts.map +1 -0
  148. package/dist/runtime/api/modules/agents/runtime/token-usage-sync.js +46 -0
  149. package/dist/runtime/api/modules/agents/runtime/type.d.ts +62 -0
  150. package/dist/runtime/api/modules/agents/runtime/type.d.ts.map +1 -0
  151. package/dist/runtime/api/modules/agents/runtime/type.js +1 -0
  152. package/dist/runtime/api/modules/agents/runtime/workspace-agent-instructions.d.ts +3 -0
  153. package/dist/runtime/api/modules/agents/runtime/workspace-agent-instructions.d.ts.map +1 -0
  154. package/dist/runtime/api/modules/agents/runtime/workspace-agent-instructions.js +31 -0
  155. package/dist/runtime/api/modules/agents/service/default.d.ts +3 -0
  156. package/dist/runtime/api/modules/agents/service/default.d.ts.map +1 -0
  157. package/dist/runtime/api/modules/agents/service/default.js +65 -0
  158. package/dist/runtime/api/modules/agents/service/index.d.ts +56 -0
  159. package/dist/runtime/api/modules/agents/service/index.d.ts.map +1 -0
  160. package/dist/runtime/api/modules/agents/service/index.js +296 -0
  161. package/dist/runtime/api/modules/agents/service/interrupt-task.d.ts +14 -0
  162. package/dist/runtime/api/modules/agents/service/interrupt-task.d.ts.map +1 -0
  163. package/dist/runtime/api/modules/agents/service/interrupt-task.js +34 -0
  164. package/dist/runtime/api/modules/agents/service/startup-recovery.d.ts +14 -0
  165. package/dist/runtime/api/modules/agents/service/startup-recovery.d.ts.map +1 -0
  166. package/dist/runtime/api/modules/agents/service/startup-recovery.js +15 -0
  167. package/dist/runtime/api/modules/agents/shell-command-risk.d.ts +3 -0
  168. package/dist/runtime/api/modules/agents/shell-command-risk.d.ts.map +1 -0
  169. package/dist/runtime/api/modules/agents/shell-command-risk.js +24 -0
  170. package/dist/runtime/api/modules/agents/shell-exec-tool.d.ts +4 -0
  171. package/dist/runtime/api/modules/agents/shell-exec-tool.d.ts.map +1 -0
  172. package/dist/runtime/api/modules/agents/shell-exec-tool.js +71 -0
  173. package/dist/runtime/api/modules/agents/subagent/index.d.ts +45 -0
  174. package/dist/runtime/api/modules/agents/subagent/index.d.ts.map +1 -0
  175. package/dist/runtime/api/modules/agents/subagent/index.js +143 -0
  176. package/dist/runtime/api/modules/agents/subagent/lifecycle.d.ts +13 -0
  177. package/dist/runtime/api/modules/agents/subagent/lifecycle.d.ts.map +1 -0
  178. package/dist/runtime/api/modules/agents/subagent/lifecycle.js +36 -0
  179. package/dist/runtime/api/modules/agents/subagent/repository.d.ts +12 -0
  180. package/dist/runtime/api/modules/agents/subagent/repository.d.ts.map +1 -0
  181. package/dist/runtime/api/modules/agents/subagent/repository.js +93 -0
  182. package/dist/runtime/api/modules/agents/subagent-repository.d.ts +11 -0
  183. package/dist/runtime/api/modules/agents/subagent-repository.d.ts.map +1 -0
  184. package/dist/runtime/api/modules/agents/subagent-repository.js +65 -0
  185. package/dist/runtime/api/modules/agents/task/actions.d.ts +10 -0
  186. package/dist/runtime/api/modules/agents/task/actions.d.ts.map +1 -0
  187. package/dist/runtime/api/modules/agents/task/actions.js +37 -0
  188. package/dist/runtime/api/modules/agents/task/active-run-registry.d.ts +10 -0
  189. package/dist/runtime/api/modules/agents/task/active-run-registry.d.ts.map +1 -0
  190. package/dist/runtime/api/modules/agents/task/active-run-registry.js +20 -0
  191. package/dist/runtime/api/modules/agents/task/run-monitor.d.ts +14 -0
  192. package/dist/runtime/api/modules/agents/task/run-monitor.d.ts.map +1 -0
  193. package/dist/runtime/api/modules/agents/task/run-monitor.js +42 -0
  194. package/dist/runtime/api/modules/agents/task/title-generator.d.ts +15 -0
  195. package/dist/runtime/api/modules/agents/task/title-generator.d.ts.map +1 -0
  196. package/dist/runtime/api/modules/agents/task/title-generator.js +61 -0
  197. package/dist/runtime/api/modules/agents/task-run-monitor.d.ts +14 -0
  198. package/dist/runtime/api/modules/agents/task-run-monitor.d.ts.map +1 -0
  199. package/dist/runtime/api/modules/agents/task-run-monitor.js +42 -0
  200. package/dist/runtime/api/modules/file-system/file-system-router.d.ts +6 -0
  201. package/dist/runtime/api/modules/file-system/file-system-router.d.ts.map +1 -0
  202. package/dist/runtime/api/modules/file-system/file-system-router.js +119 -0
  203. package/dist/runtime/api/modules/file-system/file-system-service.d.ts +30 -0
  204. package/dist/runtime/api/modules/file-system/file-system-service.d.ts.map +1 -0
  205. package/dist/runtime/api/modules/file-system/file-system-service.js +209 -0
  206. package/dist/runtime/api/modules/file-system/index.d.ts +4 -0
  207. package/dist/runtime/api/modules/file-system/index.d.ts.map +1 -0
  208. package/dist/runtime/api/modules/file-system/index.js +1 -0
  209. package/dist/runtime/api/modules/health/health-router.d.ts +3 -0
  210. package/dist/runtime/api/modules/health/health-router.d.ts.map +1 -0
  211. package/dist/runtime/api/modules/health/health-router.js +10 -0
  212. package/dist/runtime/api/modules/health/index.d.ts +2 -0
  213. package/dist/runtime/api/modules/health/index.d.ts.map +1 -0
  214. package/dist/runtime/api/modules/health/index.js +1 -0
  215. package/dist/runtime/api/modules/model-providers/default-model-provider-service.d.ts +3 -0
  216. package/dist/runtime/api/modules/model-providers/default-model-provider-service.d.ts.map +1 -0
  217. package/dist/runtime/api/modules/model-providers/default-model-provider-service.js +21 -0
  218. package/dist/runtime/api/modules/model-providers/index.d.ts +5 -0
  219. package/dist/runtime/api/modules/model-providers/index.d.ts.map +1 -0
  220. package/dist/runtime/api/modules/model-providers/index.js +4 -0
  221. package/dist/runtime/api/modules/model-providers/model-provider-api-key-crypto.d.ts +8 -0
  222. package/dist/runtime/api/modules/model-providers/model-provider-api-key-crypto.d.ts.map +1 -0
  223. package/dist/runtime/api/modules/model-providers/model-provider-api-key-crypto.js +35 -0
  224. package/dist/runtime/api/modules/model-providers/model-provider-repository.d.ts +51 -0
  225. package/dist/runtime/api/modules/model-providers/model-provider-repository.d.ts.map +1 -0
  226. package/dist/runtime/api/modules/model-providers/model-provider-repository.js +314 -0
  227. package/dist/runtime/api/modules/model-providers/model-providers-router.d.ts +9 -0
  228. package/dist/runtime/api/modules/model-providers/model-providers-router.d.ts.map +1 -0
  229. package/dist/runtime/api/modules/model-providers/model-providers-router.js +188 -0
  230. package/dist/runtime/api/modules/model-providers/model-providers-service.d.ts +52 -0
  231. package/dist/runtime/api/modules/model-providers/model-providers-service.d.ts.map +1 -0
  232. package/dist/runtime/api/modules/model-providers/model-providers-service.js +239 -0
  233. package/dist/runtime/api/modules/model-proxies/default-model-proxies-service.d.ts +3 -0
  234. package/dist/runtime/api/modules/model-proxies/default-model-proxies-service.d.ts.map +1 -0
  235. package/dist/runtime/api/modules/model-proxies/default-model-proxies-service.js +22 -0
  236. package/dist/runtime/api/modules/model-proxies/index.d.ts +5 -0
  237. package/dist/runtime/api/modules/model-proxies/index.d.ts.map +1 -0
  238. package/dist/runtime/api/modules/model-proxies/index.js +4 -0
  239. package/dist/runtime/api/modules/model-proxies/model-proxies-router.d.ts +7 -0
  240. package/dist/runtime/api/modules/model-proxies/model-proxies-router.d.ts.map +1 -0
  241. package/dist/runtime/api/modules/model-proxies/model-proxies-router.js +55 -0
  242. package/dist/runtime/api/modules/model-proxies/model-proxies-service.d.ts +26 -0
  243. package/dist/runtime/api/modules/model-proxies/model-proxies-service.d.ts.map +1 -0
  244. package/dist/runtime/api/modules/model-proxies/model-proxies-service.js +107 -0
  245. package/dist/runtime/api/modules/model-proxies/model-proxy-repository.d.ts +39 -0
  246. package/dist/runtime/api/modules/model-proxies/model-proxy-repository.d.ts.map +1 -0
  247. package/dist/runtime/api/modules/model-proxies/model-proxy-repository.js +146 -0
  248. package/dist/runtime/api/modules/model-proxies/model-proxy-runtime.d.ts +20 -0
  249. package/dist/runtime/api/modules/model-proxies/model-proxy-runtime.d.ts.map +1 -0
  250. package/dist/runtime/api/modules/model-proxies/model-proxy-runtime.js +45 -0
  251. package/dist/runtime/api/modules/plugins/plugins-router.d.ts +7 -0
  252. package/dist/runtime/api/modules/plugins/plugins-router.d.ts.map +1 -0
  253. package/dist/runtime/api/modules/plugins/plugins-router.js +11 -0
  254. package/dist/runtime/api/modules/skills/default-skills-service.d.ts +3 -0
  255. package/dist/runtime/api/modules/skills/default-skills-service.d.ts.map +1 -0
  256. package/dist/runtime/api/modules/skills/default-skills-service.js +9 -0
  257. package/dist/runtime/api/modules/skills/index.d.ts +5 -0
  258. package/dist/runtime/api/modules/skills/index.d.ts.map +1 -0
  259. package/dist/runtime/api/modules/skills/index.js +3 -0
  260. package/dist/runtime/api/modules/skills/skills-router.d.ts +7 -0
  261. package/dist/runtime/api/modules/skills/skills-router.d.ts.map +1 -0
  262. package/dist/runtime/api/modules/skills/skills-router.js +56 -0
  263. package/dist/runtime/api/modules/skills/skills-service.d.ts +7 -0
  264. package/dist/runtime/api/modules/skills/skills-service.d.ts.map +1 -0
  265. package/dist/runtime/api/modules/skills/skills-service.js +264 -0
  266. package/dist/runtime/api/modules/skills/skills-types.d.ts +22 -0
  267. package/dist/runtime/api/modules/skills/skills-types.d.ts.map +1 -0
  268. package/dist/runtime/api/modules/skills/skills-types.js +1 -0
  269. package/dist/runtime/api/modules/usage-stats/default-usage-stats-service.d.ts +3 -0
  270. package/dist/runtime/api/modules/usage-stats/default-usage-stats-service.d.ts.map +1 -0
  271. package/dist/runtime/api/modules/usage-stats/default-usage-stats-service.js +17 -0
  272. package/dist/runtime/api/modules/usage-stats/index.d.ts +4 -0
  273. package/dist/runtime/api/modules/usage-stats/index.d.ts.map +1 -0
  274. package/dist/runtime/api/modules/usage-stats/index.js +2 -0
  275. package/dist/runtime/api/modules/usage-stats/usage-stats-router.d.ts +7 -0
  276. package/dist/runtime/api/modules/usage-stats/usage-stats-router.d.ts.map +1 -0
  277. package/dist/runtime/api/modules/usage-stats/usage-stats-router.js +42 -0
  278. package/dist/runtime/api/modules/usage-stats/usage-stats-service.d.ts +40 -0
  279. package/dist/runtime/api/modules/usage-stats/usage-stats-service.d.ts.map +1 -0
  280. package/dist/runtime/api/modules/usage-stats/usage-stats-service.js +144 -0
  281. package/dist/runtime/api/modules/usage-stats/usage-stats-types.d.ts +39 -0
  282. package/dist/runtime/api/modules/usage-stats/usage-stats-types.d.ts.map +1 -0
  283. package/dist/runtime/api/modules/usage-stats/usage-stats-types.js +1 -0
  284. package/dist/runtime/api/modules/workspaces/default-workspaces-service.d.ts +3 -0
  285. package/dist/runtime/api/modules/workspaces/default-workspaces-service.d.ts.map +1 -0
  286. package/dist/runtime/api/modules/workspaces/default-workspaces-service.js +20 -0
  287. package/dist/runtime/api/modules/workspaces/index.d.ts +6 -0
  288. package/dist/runtime/api/modules/workspaces/index.d.ts.map +1 -0
  289. package/dist/runtime/api/modules/workspaces/index.js +5 -0
  290. package/dist/runtime/api/modules/workspaces/workspace-repository.d.ts +41 -0
  291. package/dist/runtime/api/modules/workspaces/workspace-repository.d.ts.map +1 -0
  292. package/dist/runtime/api/modules/workspaces/workspace-repository.js +326 -0
  293. package/dist/runtime/api/modules/workspaces/workspace-types.d.ts +33 -0
  294. package/dist/runtime/api/modules/workspaces/workspace-types.d.ts.map +1 -0
  295. package/dist/runtime/api/modules/workspaces/workspace-types.js +1 -0
  296. package/dist/runtime/api/modules/workspaces/workspaces-router.d.ts +7 -0
  297. package/dist/runtime/api/modules/workspaces/workspaces-router.d.ts.map +1 -0
  298. package/dist/runtime/api/modules/workspaces/workspaces-router.js +71 -0
  299. package/dist/runtime/api/modules/workspaces/workspaces-service.d.ts +24 -0
  300. package/dist/runtime/api/modules/workspaces/workspaces-service.d.ts.map +1 -0
  301. package/dist/runtime/api/modules/workspaces/workspaces-service.js +109 -0
  302. package/dist/runtime/api/plugin.d.ts +5 -0
  303. package/dist/runtime/api/plugin.d.ts.map +1 -0
  304. package/dist/runtime/api/plugin.js +48 -0
  305. package/dist/runtime/api/response/api-response.d.ts +11 -0
  306. package/dist/runtime/api/response/api-response.d.ts.map +1 -0
  307. package/dist/runtime/api/response/api-response.js +18 -0
  308. package/dist/runtime/api/response/index.d.ts +3 -0
  309. package/dist/runtime/api/response/index.d.ts.map +1 -0
  310. package/dist/runtime/api/response/index.js +2 -0
  311. package/dist/runtime/api/response/response-codes.d.ts +52 -0
  312. package/dist/runtime/api/response/response-codes.d.ts.map +1 -0
  313. package/dist/runtime/api/response/response-codes.js +44 -0
  314. package/dist/runtime/api/router/v1/index.d.ts +12 -0
  315. package/dist/runtime/api/router/v1/index.d.ts.map +1 -0
  316. package/dist/runtime/api/router/v1/index.js +26 -0
  317. package/dist/runtime/api/runtime.d.ts +15 -0
  318. package/dist/runtime/api/runtime.d.ts.map +1 -0
  319. package/dist/runtime/api/runtime.js +30 -0
  320. package/dist/runtime/api/server.d.ts +2 -0
  321. package/dist/runtime/api/server.d.ts.map +1 -0
  322. package/dist/runtime/api/server.js +14 -0
  323. package/dist/runtime/api/service/health-service.d.ts +7 -0
  324. package/dist/runtime/api/service/health-service.d.ts.map +1 -0
  325. package/dist/runtime/api/service/health-service.js +7 -0
  326. package/dist/runtime/web/assets/abap-DLDM7-KI.js +1 -0
  327. package/dist/runtime/web/assets/apex-DNDY2TF8.js +1 -0
  328. package/dist/runtime/web/assets/azcli-Y6nb8tq_.js +1 -0
  329. package/dist/runtime/web/assets/bat-BwHxbl9M.js +1 -0
  330. package/dist/runtime/web/assets/bicep-CFznDFnq.js +2 -0
  331. package/dist/runtime/web/assets/cameligo-Bf6VGUru.js +1 -0
  332. package/dist/runtime/web/assets/clojure-Dnu-v4kV.js +1 -0
  333. package/dist/runtime/web/assets/codicon-ngg6Pgfi.ttf +0 -0
  334. package/dist/runtime/web/assets/coffee-Bd8akH9Z.js +1 -0
  335. package/dist/runtime/web/assets/cpp-BbWJElDN.js +1 -0
  336. package/dist/runtime/web/assets/csharp-Co3qMtFm.js +1 -0
  337. package/dist/runtime/web/assets/csp-D-4FJmMZ.js +1 -0
  338. package/dist/runtime/web/assets/css-DdJfP1eB.js +3 -0
  339. package/dist/runtime/web/assets/css.worker-B4z49cGk.js +93 -0
  340. package/dist/runtime/web/assets/cssMode-w2xbbUEW.js +1 -0
  341. package/dist/runtime/web/assets/cypher-cTPe9QuQ.js +1 -0
  342. package/dist/runtime/web/assets/dart-BOtBlQCF.js +1 -0
  343. package/dist/runtime/web/assets/dockerfile-BG73LgW2.js +1 -0
  344. package/dist/runtime/web/assets/ecl-BEgZUVRK.js +1 -0
  345. package/dist/runtime/web/assets/elixir-BkW5O-1t.js +1 -0
  346. package/dist/runtime/web/assets/flow9-BeJ5waoc.js +1 -0
  347. package/dist/runtime/web/assets/freemarker2-mywz2bob.js +3 -0
  348. package/dist/runtime/web/assets/fsharp-PahG7c26.js +1 -0
  349. package/dist/runtime/web/assets/go-acbASCJo.js +1 -0
  350. package/dist/runtime/web/assets/graphql-BxJiqAUM.js +1 -0
  351. package/dist/runtime/web/assets/handlebars-Cy-2QN_R.js +1 -0
  352. package/dist/runtime/web/assets/hcl-DtV1sZF8.js +1 -0
  353. package/dist/runtime/web/assets/html-2WQMGvns.js +1 -0
  354. package/dist/runtime/web/assets/html.worker-DtiGdgqp.js +470 -0
  355. package/dist/runtime/web/assets/htmlMode-BznIdxOy.js +1 -0
  356. package/dist/runtime/web/assets/index-CQ_mZUpS.css +1 -0
  357. package/dist/runtime/web/assets/index-CtZcItCu.js +1512 -0
  358. package/dist/runtime/web/assets/ini-Kd9XrMLS.js +1 -0
  359. package/dist/runtime/web/assets/java-CXBNlu9o.js +1 -0
  360. package/dist/runtime/web/assets/javascript-BK6G_5BV.js +1 -0
  361. package/dist/runtime/web/assets/json.worker-leyajbqV.js +58 -0
  362. package/dist/runtime/web/assets/jsonMode-DI8_Cj0K.js +7 -0
  363. package/dist/runtime/web/assets/julia-cl7-CwDS.js +1 -0
  364. package/dist/runtime/web/assets/kotlin-s7OhZKlX.js +1 -0
  365. package/dist/runtime/web/assets/less-9HpZscsL.js +2 -0
  366. package/dist/runtime/web/assets/lexon-OrD6JF1K.js +1 -0
  367. package/dist/runtime/web/assets/liquid-CE7Qnc0w.js +1 -0
  368. package/dist/runtime/web/assets/lspLanguageFeatures-DKvGiYOU.js +4 -0
  369. package/dist/runtime/web/assets/lua-Cyyb5UIc.js +1 -0
  370. package/dist/runtime/web/assets/m3-B8OfTtLu.js +1 -0
  371. package/dist/runtime/web/assets/markdown-BFxVWTOG.js +1 -0
  372. package/dist/runtime/web/assets/mdx-Fk0ZjYeT.js +1 -0
  373. package/dist/runtime/web/assets/mips-CiqrrVzr.js +1 -0
  374. package/dist/runtime/web/assets/msdax-DmeGPVcC.js +1 -0
  375. package/dist/runtime/web/assets/mysql-C_tMU-Nz.js +1 -0
  376. package/dist/runtime/web/assets/objective-c-BDtDVThU.js +1 -0
  377. package/dist/runtime/web/assets/pascal-vHIfCaH5.js +1 -0
  378. package/dist/runtime/web/assets/pascaligo-DtZ0uQbO.js +1 -0
  379. package/dist/runtime/web/assets/perl-Ub6l9XKa.js +1 -0
  380. package/dist/runtime/web/assets/pgsql-BlNEE0v7.js +1 -0
  381. package/dist/runtime/web/assets/php-BBUBE1dy.js +1 -0
  382. package/dist/runtime/web/assets/pla-DSh2-awV.js +1 -0
  383. package/dist/runtime/web/assets/postiats-CocnycG-.js +1 -0
  384. package/dist/runtime/web/assets/powerquery-tScXyioY.js +1 -0
  385. package/dist/runtime/web/assets/powershell-COWaemsV.js +1 -0
  386. package/dist/runtime/web/assets/protobuf-Brw8urJB.js +2 -0
  387. package/dist/runtime/web/assets/pug-8SOpv6rk.js +1 -0
  388. package/dist/runtime/web/assets/python-xn7eKnQc.js +1 -0
  389. package/dist/runtime/web/assets/qsharp-Bw9ernYp.js +1 -0
  390. package/dist/runtime/web/assets/r-j7ic8hl3.js +1 -0
  391. package/dist/runtime/web/assets/razor-BjC5fot0.js +1 -0
  392. package/dist/runtime/web/assets/redis-Bu5POkcn.js +1 -0
  393. package/dist/runtime/web/assets/redshift-Bs9aos_-.js +1 -0
  394. package/dist/runtime/web/assets/restructuredtext-CqXO7rUv.js +1 -0
  395. package/dist/runtime/web/assets/ruby-zBfavPgS.js +1 -0
  396. package/dist/runtime/web/assets/rust-BzKRNQWT.js +1 -0
  397. package/dist/runtime/web/assets/sb-BBc9UKZt.js +1 -0
  398. package/dist/runtime/web/assets/scala-D9hQfWCl.js +1 -0
  399. package/dist/runtime/web/assets/scheme-BPhDTwHR.js +1 -0
  400. package/dist/runtime/web/assets/scss-CBJaRo0y.js +3 -0
  401. package/dist/runtime/web/assets/shell-DiJ1NA_G.js +1 -0
  402. package/dist/runtime/web/assets/solidity-Db0IVjzk.js +1 -0
  403. package/dist/runtime/web/assets/sophia-CnS9iZB_.js +1 -0
  404. package/dist/runtime/web/assets/sparql-CJmd_6j2.js +1 -0
  405. package/dist/runtime/web/assets/sql-ClhHkBeG.js +1 -0
  406. package/dist/runtime/web/assets/st-CHwy0fLd.js +1 -0
  407. package/dist/runtime/web/assets/swift-Bqt4WxQ4.js +3 -0
  408. package/dist/runtime/web/assets/systemverilog-Bs9z6M-B.js +1 -0
  409. package/dist/runtime/web/assets/tcl-Dm6ycUr_.js +1 -0
  410. package/dist/runtime/web/assets/ts.worker-59MjiAqk.js +67731 -0
  411. package/dist/runtime/web/assets/tsMode-8t6AIduV.js +11 -0
  412. package/dist/runtime/web/assets/twig-Csy3S7wG.js +1 -0
  413. package/dist/runtime/web/assets/typescript-DvPPogGC.js +1 -0
  414. package/dist/runtime/web/assets/typespec-Btyra-wh.js +1 -0
  415. package/dist/runtime/web/assets/vb-Db0cS2oM.js +1 -0
  416. package/dist/runtime/web/assets/wgsl-BTesnYfV.js +298 -0
  417. package/dist/runtime/web/assets/xml-CB8xdh8u.js +1 -0
  418. package/dist/runtime/web/assets/yaml-B4sXC4FA.js +1 -0
  419. package/dist/runtime/web/index.html +13 -0
  420. package/package.json +42 -0
@@ -0,0 +1,146 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { asc, eq, gte } from "drizzle-orm";
3
+ import { modelProxies, modelProxyCandidateLimits, modelProxyCandidates, modelTokenUsageHourly } from "../../db/index.js";
4
+ export function createInMemoryModelProxyRepository() {
5
+ const proxies = new Map();
6
+ const save = (input, existing) => {
7
+ const now = new Date().toISOString();
8
+ const proxy = {
9
+ candidates: input.candidates
10
+ .map((candidate) => {
11
+ const candidateId = randomUUID();
12
+ return {
13
+ createdAt: now,
14
+ id: candidateId,
15
+ limits: candidate.limits.map((limit) => ({
16
+ candidateId,
17
+ createdAt: now,
18
+ id: randomUUID(),
19
+ maxTokens: limit.maxTokens,
20
+ updatedAt: now,
21
+ windowHours: limit.windowHours ?? null,
22
+ windowType: limit.windowType
23
+ })),
24
+ modelId: candidate.modelId,
25
+ priority: candidate.priority,
26
+ provider: candidate.provider,
27
+ proxyId: existing?.id ?? randomUUID(),
28
+ updatedAt: now
29
+ };
30
+ })
31
+ .sort((left, right) => left.priority - right.priority),
32
+ createdAt: existing?.createdAt ?? now,
33
+ id: existing?.id ?? randomUUID(),
34
+ modelId: input.modelId,
35
+ name: input.name,
36
+ updatedAt: now
37
+ };
38
+ proxy.candidates = proxy.candidates.map((candidate) => ({
39
+ ...candidate,
40
+ proxyId: proxy.id
41
+ }));
42
+ proxies.delete(existing?.modelId ?? input.modelId);
43
+ proxies.set(proxy.modelId, proxy);
44
+ return cloneProxy(proxy);
45
+ };
46
+ return {
47
+ createProxy: (input) => save(input),
48
+ deleteProxy: (modelId) => proxies.delete(modelId),
49
+ findProxyByModelId: (modelId) => cloneOptional(proxies.get(modelId)),
50
+ listProxies: () => [...proxies.values()].map(cloneProxy),
51
+ updateProxy: (modelId, input) => {
52
+ const existing = proxies.get(modelId);
53
+ return existing ? save(input, existing) : undefined;
54
+ }
55
+ };
56
+ }
57
+ export function createSqliteModelProxyRepository(database) {
58
+ const readProxy = (row) => ({
59
+ ...row,
60
+ candidates: database.db
61
+ .select()
62
+ .from(modelProxyCandidates)
63
+ .where(eq(modelProxyCandidates.proxyId, row.id))
64
+ .orderBy(asc(modelProxyCandidates.priority))
65
+ .all()
66
+ .map((candidate) => ({
67
+ ...candidate,
68
+ limits: database.db
69
+ .select()
70
+ .from(modelProxyCandidateLimits)
71
+ .where(eq(modelProxyCandidateLimits.candidateId, candidate.id))
72
+ .all()
73
+ }))
74
+ });
75
+ const insertProxy = (input, existing) => {
76
+ const now = new Date().toISOString();
77
+ const proxy = {
78
+ createdAt: existing?.createdAt ?? now,
79
+ id: existing?.id ?? randomUUID(),
80
+ modelId: input.modelId,
81
+ name: input.name,
82
+ updatedAt: now
83
+ };
84
+ if (existing) {
85
+ database.db.update(modelProxies).set(proxy).where(eq(modelProxies.id, existing.id)).run();
86
+ database.db.delete(modelProxyCandidates).where(eq(modelProxyCandidates.proxyId, proxy.id)).run();
87
+ }
88
+ else {
89
+ database.db.insert(modelProxies).values(proxy).run();
90
+ }
91
+ for (const candidate of input.candidates) {
92
+ const candidateRow = {
93
+ createdAt: now,
94
+ id: randomUUID(),
95
+ modelId: candidate.modelId,
96
+ priority: candidate.priority,
97
+ provider: candidate.provider,
98
+ proxyId: proxy.id,
99
+ updatedAt: now
100
+ };
101
+ database.db.insert(modelProxyCandidates).values(candidateRow).run();
102
+ database.db.insert(modelProxyCandidateLimits).values(candidate.limits.map((limit) => ({
103
+ candidateId: candidateRow.id,
104
+ createdAt: now,
105
+ id: randomUUID(),
106
+ maxTokens: limit.maxTokens,
107
+ updatedAt: now,
108
+ windowHours: limit.windowHours ?? null,
109
+ windowType: limit.windowType
110
+ }))).run();
111
+ }
112
+ return readProxy(proxy);
113
+ };
114
+ return {
115
+ createProxy: (input) => insertProxy(input),
116
+ deleteProxy: (modelId) => {
117
+ const row = database.db.select().from(modelProxies).where(eq(modelProxies.modelId, modelId)).get();
118
+ if (!row)
119
+ return false;
120
+ database.db.delete(modelProxies).where(eq(modelProxies.id, row.id)).run();
121
+ return true;
122
+ },
123
+ findProxyByModelId: (modelId) => {
124
+ const row = database.db.select().from(modelProxies).where(eq(modelProxies.modelId, modelId)).get();
125
+ return row ? readProxy(row) : undefined;
126
+ },
127
+ listModelTokenUsageSince: (from) => database.db.select().from(modelTokenUsageHourly).where(gte(modelTokenUsageHourly.hour, from)).all(),
128
+ listProxies: () => database.db.select().from(modelProxies).all().map(readProxy),
129
+ updateProxy: (modelId, input) => {
130
+ const row = database.db.select().from(modelProxies).where(eq(modelProxies.modelId, modelId)).get();
131
+ return row ? insertProxy(input, row) : undefined;
132
+ }
133
+ };
134
+ }
135
+ function cloneOptional(proxy) {
136
+ return proxy ? cloneProxy(proxy) : undefined;
137
+ }
138
+ function cloneProxy(proxy) {
139
+ return {
140
+ ...proxy,
141
+ candidates: proxy.candidates.map((candidate) => ({
142
+ ...candidate,
143
+ limits: candidate.limits.map((limit) => ({ ...limit }))
144
+ }))
145
+ };
146
+ }
@@ -0,0 +1,20 @@
1
+ import type { Api, Model } from "@earendil-works/pi-ai";
2
+ import type { ModelProxiesService, PendingProxyUsage } from "./model-proxies-service";
3
+ export interface ModelProxyRuntimeCandidate {
4
+ modelId: string;
5
+ provider: string;
6
+ }
7
+ export interface ModelProxyRuntimeController {
8
+ getActiveModel: () => Model<Api>;
9
+ recordAssistantUsage: (usage: PendingProxyUsage) => Promise<void>;
10
+ }
11
+ export interface CreateModelProxyRuntimeControllerOptions {
12
+ activeCandidate: ModelProxyRuntimeCandidate;
13
+ activeModel?: Model<Api>;
14
+ proxyModelId: string;
15
+ resolveModel: (provider: string, modelId: string) => Promise<Model<Api> | null>;
16
+ service: ModelProxiesService;
17
+ setModel: (model: Model<Api>) => Promise<void> | void;
18
+ }
19
+ export declare function createModelProxyRuntimeController(options: CreateModelProxyRuntimeControllerOptions): ModelProxyRuntimeController;
20
+ //# sourceMappingURL=model-proxy-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-proxy-runtime.d.ts","sourceRoot":"","sources":["../../../src/modules/model-proxies/model-proxy-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEtF,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,2BAA2B;IAC1C,cAAc,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,oBAAoB,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACnE;AAED,MAAM,WAAW,wCAAwC;IACvD,eAAe,EAAE,0BAA0B,CAAC;IAC5C,WAAW,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAChF,OAAO,EAAE,mBAAmB,CAAC;IAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACvD;AAED,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,wCAAwC,GAChD,2BAA2B,CAuD7B"}
@@ -0,0 +1,45 @@
1
+ export function createModelProxyRuntimeController(options) {
2
+ let activeCandidate = options.activeCandidate;
3
+ let activeModel = options.activeModel;
4
+ const pendingUsage = new Map();
5
+ return {
6
+ getActiveModel: () => {
7
+ if (!activeModel) {
8
+ throw new Error("Proxy active model is not initialized");
9
+ }
10
+ return activeModel;
11
+ },
12
+ recordAssistantUsage: async (usage) => {
13
+ if (usage.provider !== activeCandidate.provider ||
14
+ usage.modelId !== activeCandidate.modelId) {
15
+ return;
16
+ }
17
+ const key = usageKey(usage.provider, usage.modelId);
18
+ const existing = pendingUsage.get(key);
19
+ pendingUsage.set(key, {
20
+ inputToken: (existing?.inputToken ?? 0) + usage.inputToken,
21
+ modelId: usage.modelId,
22
+ outputToken: (existing?.outputToken ?? 0) + usage.outputToken,
23
+ provider: usage.provider
24
+ });
25
+ const nextCandidate = options.service.selectCandidate(options.proxyModelId, Object.fromEntries(pendingUsage));
26
+ if (!nextCandidate) {
27
+ throw new Error("Proxy fallback unavailable");
28
+ }
29
+ if (nextCandidate.provider === activeCandidate.provider &&
30
+ nextCandidate.modelId === activeCandidate.modelId) {
31
+ return;
32
+ }
33
+ const nextModel = await options.resolveModel(nextCandidate.provider, nextCandidate.modelId);
34
+ if (!nextModel) {
35
+ throw new Error("Unknown candidate provider or model");
36
+ }
37
+ activeCandidate = nextCandidate;
38
+ activeModel = nextModel;
39
+ await options.setModel(nextModel);
40
+ }
41
+ };
42
+ }
43
+ function usageKey(provider, modelId) {
44
+ return `${provider}\0${modelId}`;
45
+ }
@@ -0,0 +1,7 @@
1
+ import { Router } from "express";
2
+ import type { RuntimePluginManifest } from "@hold-rein/plugin-server";
3
+ export interface CreatePluginsRouterOptions {
4
+ readonly plugins: readonly RuntimePluginManifest[];
5
+ }
6
+ export declare function createPluginsRouter(options: CreatePluginsRouterOptions): Router;
7
+ //# sourceMappingURL=plugins-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins-router.d.ts","sourceRoot":"","sources":["../../../src/modules/plugins/plugins-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGjC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEtE,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACpD;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,MAAM,CAU/E"}
@@ -0,0 +1,11 @@
1
+ import { Router } from "express";
2
+ import { sendSuccess } from "../../response/index.js";
3
+ export function createPluginsRouter(options) {
4
+ const router = Router();
5
+ router.get("/", (_request, response) => {
6
+ sendSuccess(response, {
7
+ plugins: options.plugins
8
+ });
9
+ });
10
+ return router;
11
+ }
@@ -0,0 +1,3 @@
1
+ import type { SkillsService } from "./skills-types";
2
+ export declare function getDefaultSkillsService(): SkillsService;
3
+ //# sourceMappingURL=default-skills-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-skills-service.d.ts","sourceRoot":"","sources":["../../../src/modules/skills/default-skills-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIpD,wBAAgB,uBAAuB,IAAI,aAAa,CAOvD"}
@@ -0,0 +1,9 @@
1
+ import { createSkillsService } from "./skills-service.js";
2
+ let service;
3
+ export function getDefaultSkillsService() {
4
+ if (!service) {
5
+ service = createSkillsService();
6
+ void service.load();
7
+ }
8
+ return service;
9
+ }
@@ -0,0 +1,5 @@
1
+ export { getDefaultSkillsService } from "./default-skills-service";
2
+ export { createSkillsRouter, type CreateSkillsRouterOptions } from "./skills-router";
3
+ export { createSkillsService, type CreateSkillsServiceOptions } from "./skills-service";
4
+ export type { InstalledSkill, SkillsConfig, SkillsService } from "./skills-types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/skills/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,KAAK,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AACxF,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { getDefaultSkillsService } from "./default-skills-service.js";
2
+ export { createSkillsRouter } from "./skills-router.js";
3
+ export { createSkillsService } from "./skills-service.js";
@@ -0,0 +1,7 @@
1
+ import { Router } from "express";
2
+ import type { SkillsService } from "./skills-types";
3
+ export interface CreateSkillsRouterOptions {
4
+ skillsService?: SkillsService;
5
+ }
6
+ export declare function createSkillsRouter(options?: CreateSkillsRouterOptions): Router;
7
+ //# sourceMappingURL=skills-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skills-router.d.ts","sourceRoot":"","sources":["../../../src/modules/skills/skills-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA+B,MAAM,SAAS,CAAC;AAK9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,MAAM,WAAW,yBAAyB;IACxC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAUD,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,yBAA8B,GACtC,MAAM,CA4ER"}
@@ -0,0 +1,56 @@
1
+ import { Router } from "express";
2
+ import { sendError, sendSuccess } from "../../response/index.js";
3
+ import { RESPONSE_CODE_DEFINITIONS } from "../../response/response-codes.js";
4
+ import { getDefaultSkillsService } from "./default-skills-service.js";
5
+ export function createSkillsRouter(options = {}) {
6
+ const router = Router();
7
+ const getService = () => options.skillsService ?? getDefaultSkillsService();
8
+ router.get("/skills", (_request, response) => {
9
+ void getService()
10
+ .listSkills()
11
+ .then((skills) => sendSuccess(response, { skills }))
12
+ .catch((error) => sendRouteError(response, error, "Failed to list skills"));
13
+ });
14
+ router.post("/skills/install", (request, response) => {
15
+ if (typeof request.body.repositoryUrl !== "string") {
16
+ sendError(response, RESPONSE_CODE_DEFINITIONS.badRequest, "repositoryUrl must be a string");
17
+ return;
18
+ }
19
+ void getService()
20
+ .installSkill(request.body.repositoryUrl)
21
+ .then((skill) => sendSuccess(response, skill))
22
+ .catch((error) => sendRouteError(response, error, "Failed to install skill"));
23
+ });
24
+ router.patch("/skills/:skillId", (request, response) => {
25
+ if (typeof request.body.disabled !== "boolean") {
26
+ sendError(response, RESPONSE_CODE_DEFINITIONS.badRequest, "disabled must be a boolean");
27
+ return;
28
+ }
29
+ void getService()
30
+ .setSkillDisabled(request.params.skillId, request.body.disabled)
31
+ .then((skill) => {
32
+ if (!skill) {
33
+ sendError(response, RESPONSE_CODE_DEFINITIONS.notFound, "Unknown skill");
34
+ return;
35
+ }
36
+ sendSuccess(response, skill);
37
+ })
38
+ .catch((error) => sendRouteError(response, error, "Failed to update skill"));
39
+ });
40
+ router.delete("/skills/:skillId", (request, response) => {
41
+ void getService()
42
+ .uninstallSkill(request.params.skillId)
43
+ .then((deleted) => {
44
+ if (!deleted) {
45
+ sendError(response, RESPONSE_CODE_DEFINITIONS.notFound, "Unknown skill");
46
+ return;
47
+ }
48
+ sendSuccess(response, { id: request.params.skillId });
49
+ })
50
+ .catch((error) => sendRouteError(response, error, "Failed to uninstall skill"));
51
+ });
52
+ return router;
53
+ }
54
+ function sendRouteError(response, error, fallback) {
55
+ sendError(response, RESPONSE_CODE_DEFINITIONS.badRequest, error instanceof Error ? error.message : fallback);
56
+ }
@@ -0,0 +1,7 @@
1
+ import type { SkillsService } from "./skills-types";
2
+ export interface CreateSkillsServiceOptions {
3
+ installGitRepository?: (repositoryUrl: string, targetDir: string, ref?: string) => Promise<void>;
4
+ rootDir?: string;
5
+ }
6
+ export declare function createSkillsService(options?: CreateSkillsServiceOptions): SkillsService;
7
+ //# sourceMappingURL=skills-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skills-service.d.ts","sourceRoot":"","sources":["../../../src/modules/skills/skills-service.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAgC,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAKlF,MAAM,WAAW,0BAA0B;IACzC,oBAAoB,CAAC,EAAE,CACrB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,GAAG,CAAC,EAAE,MAAM,KACT,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AASD,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,0BAA+B,GACvC,aAAa,CA6Gf"}
@@ -0,0 +1,264 @@
1
+ import { execFile } from "node:child_process";
2
+ import { cp, mkdir, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { basename, join } from "node:path";
5
+ import { promisify } from "node:util";
6
+ import { SKILL_DIR } from "../../config/const.js";
7
+ const execFileAsync = promisify(execFile);
8
+ const CONFIG_FILE_NAME = "skills.json";
9
+ export function createSkillsService(options = {}) {
10
+ const rootDir = options.rootDir ?? SKILL_DIR;
11
+ const configPath = join(rootDir, CONFIG_FILE_NAME);
12
+ const installGitRepository = options.installGitRepository ?? cloneGitRepository;
13
+ let config = {};
14
+ let loaded = false;
15
+ const ensureLoaded = async () => {
16
+ if (loaded) {
17
+ return;
18
+ }
19
+ await mkdir(rootDir, { recursive: true });
20
+ config = await readConfig(configPath);
21
+ loaded = true;
22
+ };
23
+ const persistConfig = async () => {
24
+ await mkdir(rootDir, { recursive: true });
25
+ await writeFile(configPath, `${JSON.stringify(normalizeConfig(config), null, 2)}\n`, "utf8");
26
+ };
27
+ const listSkills = async () => {
28
+ await ensureLoaded();
29
+ const entries = await readSkillEntries(rootDir);
30
+ const skills = await Promise.all(entries.map((entry) => readInstalledSkill(rootDir, entry.name, config)));
31
+ return skills
32
+ .filter((skill) => skill !== null)
33
+ .sort((leftSkill, rightSkill) => leftSkill.name.localeCompare(rightSkill.name));
34
+ };
35
+ return {
36
+ installSkill: async (repositoryUrl) => {
37
+ await ensureLoaded();
38
+ const source = getSkillSourceFromGithubUrl(repositoryUrl);
39
+ const skillId = source.skillId;
40
+ const targetDir = join(rootDir, skillId);
41
+ const existing = await readInstalledSkill(rootDir, skillId, config);
42
+ if (existing) {
43
+ throw new Error("Skill is already installed");
44
+ }
45
+ await installSkillSource(source, targetDir, installGitRepository);
46
+ const installedSkill = await readInstalledSkill(rootDir, skillId, config);
47
+ if (!installedSkill) {
48
+ await rm(targetDir, { force: true, recursive: true });
49
+ throw new Error("Installed repository does not contain SKILL.md");
50
+ }
51
+ return installedSkill;
52
+ },
53
+ listEnabledSkillDirs: async () => {
54
+ const skills = await listSkills();
55
+ return skills
56
+ .filter((skill) => !skill.disabled)
57
+ .map((skill) => skill.path);
58
+ },
59
+ listSkills,
60
+ load: async () => {
61
+ await mkdir(rootDir, { recursive: true });
62
+ config = await readConfig(configPath);
63
+ loaded = true;
64
+ },
65
+ setSkillDisabled: async (skillId, disabled) => {
66
+ await ensureLoaded();
67
+ const skill = await readInstalledSkill(rootDir, skillId, config);
68
+ if (!skill) {
69
+ return null;
70
+ }
71
+ config = normalizeConfig({
72
+ ...config,
73
+ [skillId]: {
74
+ ...config[skillId],
75
+ disabled
76
+ }
77
+ });
78
+ await persistConfig();
79
+ return { ...skill, disabled };
80
+ },
81
+ uninstallSkill: async (skillId) => {
82
+ await ensureLoaded();
83
+ const skill = await readInstalledSkill(rootDir, skillId, config);
84
+ if (!skill) {
85
+ return false;
86
+ }
87
+ await rm(skill.path, { force: true, recursive: true });
88
+ const { [skillId]: _removed, ...remainingConfig } = config;
89
+ config = normalizeConfig(remainingConfig);
90
+ await persistConfig();
91
+ return true;
92
+ }
93
+ };
94
+ }
95
+ async function readConfig(configPath) {
96
+ try {
97
+ return normalizeConfig(JSON.parse(await readFile(configPath, "utf8")));
98
+ }
99
+ catch {
100
+ return {};
101
+ }
102
+ }
103
+ function normalizeConfig(value) {
104
+ if (!value || typeof value !== "object") {
105
+ return {};
106
+ }
107
+ const legacyDisabledSkillIds = value
108
+ .disabledSkillIds;
109
+ if (Array.isArray(legacyDisabledSkillIds)) {
110
+ return Object.fromEntries([...new Set(legacyDisabledSkillIds.filter(isNonEmptyString))]
111
+ .sort()
112
+ .map((skillId) => [skillId, { disabled: true }]));
113
+ }
114
+ return Object.fromEntries(Object.entries(value)
115
+ .filter(([skillId, entry]) => isNonEmptyString(skillId) && isPlainObject(entry))
116
+ .sort(([leftSkillId], [rightSkillId]) => leftSkillId.localeCompare(rightSkillId))
117
+ .map(([skillId, entry]) => [skillId, normalizeConfigEntry(entry)]));
118
+ }
119
+ function normalizeConfigEntry(entry) {
120
+ const normalizedEntry = { ...entry };
121
+ if (typeof normalizedEntry.disabled !== "boolean") {
122
+ delete normalizedEntry.disabled;
123
+ }
124
+ return normalizedEntry;
125
+ }
126
+ function isPlainObject(value) {
127
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
128
+ }
129
+ async function readSkillEntries(rootDir) {
130
+ try {
131
+ return (await readdir(rootDir, { withFileTypes: true })).filter((entry) => entry.isDirectory());
132
+ }
133
+ catch {
134
+ return [];
135
+ }
136
+ }
137
+ async function readInstalledSkill(rootDir, skillId, config) {
138
+ const skillPath = join(rootDir, skillId);
139
+ try {
140
+ const content = await readFile(join(skillPath, "SKILL.md"), "utf8");
141
+ return {
142
+ disabled: config[skillId]?.disabled === true,
143
+ id: skillId,
144
+ name: parseSkillName(content) ?? basename(skillPath),
145
+ path: skillPath
146
+ };
147
+ }
148
+ catch {
149
+ return null;
150
+ }
151
+ }
152
+ function parseSkillName(content) {
153
+ const frontmatterMatch = /^---\n(?<frontmatter>[\s\S]*?)\n---/u.exec(content);
154
+ const frontmatter = frontmatterMatch?.groups?.frontmatter;
155
+ if (!frontmatter) {
156
+ return undefined;
157
+ }
158
+ for (const line of frontmatter.split("\n")) {
159
+ const nameMatch = /^name:\s*(?<name>.+?)\s*$/u.exec(line);
160
+ const rawName = nameMatch?.groups?.name;
161
+ if (rawName) {
162
+ return rawName.replace(/^["']|["']$/gu, "");
163
+ }
164
+ }
165
+ return undefined;
166
+ }
167
+ async function installSkillSource(source, targetDir, installGitRepository) {
168
+ if (!source.skillSubdirectory) {
169
+ if (source.ref) {
170
+ await installGitRepository(source.repositoryUrl, targetDir, source.ref);
171
+ }
172
+ else {
173
+ await installGitRepository(source.repositoryUrl, targetDir);
174
+ }
175
+ return;
176
+ }
177
+ const cloneDir = await mkdtemp(join(tmpdir(), "hold-rein-skill-"));
178
+ try {
179
+ await installGitRepository(source.repositoryUrl, cloneDir, source.ref);
180
+ await cp(join(cloneDir, source.skillSubdirectory), targetDir, {
181
+ errorOnExist: true,
182
+ recursive: true
183
+ });
184
+ }
185
+ catch (error) {
186
+ await rm(targetDir, { force: true, recursive: true });
187
+ throw error;
188
+ }
189
+ finally {
190
+ await rm(cloneDir, { force: true, recursive: true });
191
+ }
192
+ }
193
+ function getSkillSourceFromGithubUrl(repositoryUrl) {
194
+ const trimmedUrl = repositoryUrl.trim();
195
+ const rootMatch = /^https:\/\/github\.com\/[^/\s]+\/(?<repo>[^/\s]+?)(?:\.git)?\/?$/u.exec(trimmedUrl) ??
196
+ /^git@github\.com:[^/\s]+\/(?<repo>[^/\s]+?)(?:\.git)?$/u.exec(trimmedUrl);
197
+ const rootRepo = rootMatch?.groups?.repo;
198
+ if (rootRepo && isValidRepositoryName(rootRepo)) {
199
+ return {
200
+ repositoryUrl: trimmedUrl,
201
+ skillId: rootRepo
202
+ };
203
+ }
204
+ const webMatch = /^https:\/\/github\.com\/[^/\s]+\/(?<repo>[^/\s]+)\/(?<kind>tree|blob)\/(?<ref>[^/\s]+)(?:\/(?<path>.*))?\/?$/u.exec(trimmedUrl);
205
+ const repo = webMatch?.groups?.repo;
206
+ const kind = webMatch?.groups?.kind;
207
+ const ref = webMatch?.groups?.ref;
208
+ const path = webMatch?.groups?.path;
209
+ if (!repo || !kind || !ref || !isValidRepositoryName(repo)) {
210
+ throw new Error("repositoryUrl must be a GitHub repository URL");
211
+ }
212
+ const pathSegments = normalizeGithubPathSegments(path);
213
+ const skillSubdirectory = kind === "blob"
214
+ ? getSkillDirectoryFromBlobPath(pathSegments)
215
+ : pathSegments.join("/");
216
+ const source = {
217
+ ref,
218
+ repositoryUrl: getHttpsGitRepositoryUrl(trimmedUrl, repo),
219
+ skillId: basename(skillSubdirectory || repo)
220
+ };
221
+ if (skillSubdirectory) {
222
+ source.skillSubdirectory = skillSubdirectory;
223
+ }
224
+ return source;
225
+ }
226
+ function getSkillDirectoryFromBlobPath(pathSegments) {
227
+ if (pathSegments.at(-1) !== "SKILL.md") {
228
+ throw new Error("repositoryUrl must be a GitHub repository URL");
229
+ }
230
+ return pathSegments.slice(0, -1).join("/");
231
+ }
232
+ function getHttpsGitRepositoryUrl(trimmedUrl, repo) {
233
+ const repositoryBaseMatch = new RegExp(`^(?<base>https://github\\.com/[^/\\s]+/${escapeRegExp(repo)})/`, "u").exec(trimmedUrl);
234
+ const repositoryBase = repositoryBaseMatch?.groups?.base;
235
+ if (!repositoryBase) {
236
+ throw new Error("repositoryUrl must be a GitHub repository URL");
237
+ }
238
+ return `${repositoryBase}.git`;
239
+ }
240
+ function normalizeGithubPathSegments(path) {
241
+ if (!path) {
242
+ return [];
243
+ }
244
+ const segments = path.split("/").filter((segment) => segment.length > 0);
245
+ if (segments.some((segment) => segment === "." || segment === "..")) {
246
+ throw new Error("repositoryUrl must be a GitHub repository URL");
247
+ }
248
+ return segments;
249
+ }
250
+ function isValidRepositoryName(repo) {
251
+ return /^[A-Za-z0-9._-]+$/u.test(repo);
252
+ }
253
+ function escapeRegExp(value) {
254
+ return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
255
+ }
256
+ async function cloneGitRepository(repositoryUrl, targetDir, ref) {
257
+ const args = ref
258
+ ? ["clone", "--depth", "1", "--branch", ref, repositoryUrl, targetDir]
259
+ : ["clone", "--depth", "1", repositoryUrl, targetDir];
260
+ await execFileAsync("git", args);
261
+ }
262
+ function isNonEmptyString(value) {
263
+ return typeof value === "string" && value.trim().length > 0;
264
+ }
@@ -0,0 +1,22 @@
1
+ export interface InstalledSkill {
2
+ disabled: boolean;
3
+ id: string;
4
+ name: string;
5
+ path: string;
6
+ }
7
+ export interface SkillsConfig {
8
+ [skillId: string]: SkillConfigEntry;
9
+ }
10
+ export interface SkillConfigEntry {
11
+ disabled?: boolean;
12
+ [property: string]: unknown;
13
+ }
14
+ export interface SkillsService {
15
+ installSkill: (repositoryUrl: string) => Promise<InstalledSkill>;
16
+ listEnabledSkillDirs: () => Promise<string[]>;
17
+ listSkills: () => Promise<InstalledSkill[]>;
18
+ load: () => Promise<void>;
19
+ setSkillDisabled: (skillId: string, disabled: boolean) => Promise<InstalledSkill | null>;
20
+ uninstallSkill: (skillId: string) => Promise<boolean>;
21
+ }
22
+ //# sourceMappingURL=skills-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skills-types.d.ts","sourceRoot":"","sources":["../../../src/modules/skills/skills-types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAC;CACrC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IACjE,oBAAoB,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9C,UAAU,EAAE,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAC5C,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,gBAAgB,EAAE,CAChB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,OAAO,KACd,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACpC,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACvD"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type UsageStatsService } from "./usage-stats-service";
2
+ export declare function getDefaultUsageStatsService(): UsageStatsService;
3
+ //# sourceMappingURL=default-usage-stats-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-usage-stats-service.d.ts","sourceRoot":"","sources":["../../../src/modules/usage-stats/default-usage-stats-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAI/B,wBAAgB,2BAA2B,IAAI,iBAAiB,CAc/D"}