@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 @@
1
+ {"version":3,"file":"model-providers-service.d.ts","sourceRoot":"","sources":["../../../src/modules/model-providers/model-providers-service.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAElF,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;CACxC;AAED,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,4BAA4B;IAC3C,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,2BAA2B,EAAE,MAAM,CAAC;IACpC,UAAU,EAAE,uBAAuB,CAAC;CACrC;AAED,MAAM,WAAW,qBAAqB;IACpC,yBAAyB,EAAE,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,KACZ,0BAA0B,CAAC;IAChC,yBAAyB,EAAE,CACzB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,GAAG,UAAU,CAAC,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAC/D,YAAY,CAAC;IAClB,yBAAyB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IACzD,yBAAyB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IAC1E,6BAA6B,EAAE,CAC7B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,KACZ;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,YAAY,CAAC;KACrB,GAAG,IAAI,CAAC;IACT,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IAC3C,qBAAqB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,YAAY,EAAE,CAAC;IAC5D,kBAAkB,EAAE,MAAM,oBAAoB,EAAE,CAAC;IACjD,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,oBAAoB,CAAC;IAChF,yBAAyB,EAAE,CACzB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,KACZ,0BAA0B,GAAG,IAAI,CAAC;IACvC,yBAAyB,EAAE,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,GAAG,UAAU,CAAC,KACzC,YAAY,GAAG,IAAI,CAAC;CAC1B;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,4BAA4B,GACpC,qBAAqB,CA6NvB"}
@@ -0,0 +1,239 @@
1
+ import { getModels, getProviders } from "@earendil-works/pi-ai";
2
+ import { decryptProviderApiKey, encryptProviderApiKey } from "./model-provider-api-key-crypto.js";
3
+ export function createModelProvidersService(options) {
4
+ const { modelProxiesService, providerApiKeyEncryptionKey, repository } = options;
5
+ const listModelsForProvider = (provider) => {
6
+ if (provider === "local") {
7
+ return modelProxiesService?.listProxyModels() ?? [];
8
+ }
9
+ if (hasBuiltInProvider(provider)) {
10
+ return getModels(provider).map(mapBuiltInModel);
11
+ }
12
+ const customProvider = repository.findCustomModelProviderByProvider(provider);
13
+ if (!customProvider) {
14
+ return [];
15
+ }
16
+ return repository
17
+ .listCustomProviderModelsByProviderId(customProvider.id)
18
+ .map((model) => ({
19
+ api: model.api,
20
+ contextWindow: model.contextWindow,
21
+ id: model.modelId,
22
+ input: JSON.parse(model.input),
23
+ maxTokens: model.maxTokens,
24
+ name: model.name && model.name.trim().length > 0 ? model.name : model.modelId,
25
+ provider: customProvider.provider,
26
+ reasoning: model.reasoning
27
+ }));
28
+ };
29
+ return {
30
+ createCustomModelProvider: (provider, baseUrl) => {
31
+ const normalizedProvider = provider.trim();
32
+ const normalizedBaseUrl = baseUrl.trim();
33
+ if (hasBuiltInProvider(normalizedProvider)) {
34
+ throw new Error("Provider conflicts with built-in provider");
35
+ }
36
+ if (hasCustomProvider(normalizedProvider, repository)) {
37
+ throw new Error("Provider already exists");
38
+ }
39
+ return repository.createCustomModelProvider({
40
+ baseUrl: normalizedBaseUrl,
41
+ provider: normalizedProvider
42
+ });
43
+ },
44
+ createCustomProviderModel: (provider, input) => {
45
+ const customProvider = repository.findCustomModelProviderByProvider(provider);
46
+ if (!customProvider) {
47
+ throw new Error("Unknown custom provider");
48
+ }
49
+ const row = repository.createCustomProviderModel({
50
+ api: input.api,
51
+ contextWindow: input.contextWindow,
52
+ input: input.input,
53
+ maxTokens: input.maxTokens,
54
+ modelId: input.modelId.trim(),
55
+ name: normalizeCustomModelName(input.name, input.modelId),
56
+ providerId: customProvider.id,
57
+ reasoning: input.reasoning
58
+ });
59
+ return mapCustomProviderModel(customProvider.provider, row);
60
+ },
61
+ deleteCustomModelProvider: (provider) => {
62
+ if (hasBuiltInProvider(provider)) {
63
+ return false;
64
+ }
65
+ return repository.deleteCustomModelProvider(provider);
66
+ },
67
+ deleteCustomProviderModel: (provider, modelId) => {
68
+ const customProvider = repository.findCustomModelProviderByProvider(provider);
69
+ if (!customProvider) {
70
+ return false;
71
+ }
72
+ return repository.deleteCustomProviderModel(customProvider.id, modelId);
73
+ },
74
+ getConfiguredModelForProvider: (provider, modelId) => {
75
+ if (provider === "local") {
76
+ return null;
77
+ }
78
+ const model = findModel(provider, modelId, repository);
79
+ const baseUrl = findModelBaseUrl(provider, modelId, repository);
80
+ if (!model || baseUrl === null) {
81
+ return null;
82
+ }
83
+ const encryptedApiKey = repository.findProviderApiKeyByProvider(provider);
84
+ return {
85
+ baseUrl,
86
+ ...(encryptedApiKey
87
+ ? {
88
+ apiKey: decryptProviderApiKey({
89
+ ciphertext: encryptedApiKey.apiKeyCiphertext,
90
+ iv: encryptedApiKey.apiKeyIv,
91
+ tag: encryptedApiKey.apiKeyTag
92
+ }, providerApiKeyEncryptionKey)
93
+ }
94
+ : {}),
95
+ model
96
+ };
97
+ },
98
+ hasProvider: (provider) => provider === "local"
99
+ ? (modelProxiesService?.listProxies().length ?? 0) > 0
100
+ : hasBuiltInProvider(provider) || hasCustomProvider(provider, repository),
101
+ listModelsForProvider,
102
+ listModelProviders: () => {
103
+ const builtInProviders = getProviders().map((provider) => ({
104
+ hasApiKey: repository.findProviderApiKeyByProvider(provider) !== undefined,
105
+ id: provider,
106
+ modelCount: getModels(provider).length,
107
+ source: "builtin"
108
+ }));
109
+ const customProviders = repository.listCustomModelProviders().map((provider) => ({
110
+ baseUrl: provider.baseUrl,
111
+ hasApiKey: repository.findProviderApiKeyByProvider(provider.provider) !== undefined,
112
+ id: provider.provider,
113
+ modelCount: repository.listCustomProviderModelsByProviderId(provider.id).length,
114
+ source: "custom"
115
+ }));
116
+ const proxyProviders = (modelProxiesService?.listProxies().length ?? 0) > 0
117
+ ? [
118
+ {
119
+ hasApiKey: true,
120
+ id: "local",
121
+ modelCount: modelProxiesService?.listProxies().length ?? 0,
122
+ source: "proxy"
123
+ }
124
+ ]
125
+ : [];
126
+ return [...builtInProviders, ...customProviders, ...proxyProviders];
127
+ },
128
+ storeProviderApiKey: (provider, apiKey) => {
129
+ if (!hasBuiltInProvider(provider) && !hasCustomProvider(provider, repository)) {
130
+ throw new Error("Unknown provider");
131
+ }
132
+ const encryptedApiKey = encryptProviderApiKey(apiKey.trim(), providerApiKeyEncryptionKey);
133
+ repository.saveProviderApiKey({
134
+ apiKeyCiphertext: encryptedApiKey.ciphertext,
135
+ apiKeyIv: encryptedApiKey.iv,
136
+ apiKeyTag: encryptedApiKey.tag,
137
+ provider
138
+ });
139
+ return {
140
+ hasApiKey: true,
141
+ id: provider,
142
+ modelCount: listModelsForProvider(provider).length,
143
+ source: hasBuiltInProvider(provider) ? "builtin" : "custom"
144
+ };
145
+ },
146
+ updateCustomModelProvider: (provider, nextProvider, baseUrl) => {
147
+ const normalizedProvider = nextProvider.trim();
148
+ const normalizedBaseUrl = baseUrl.trim();
149
+ if (normalizedProvider !== provider &&
150
+ hasBuiltInProvider(normalizedProvider)) {
151
+ throw new Error("Provider conflicts with built-in provider");
152
+ }
153
+ const existingWithNextProvider = normalizedProvider === provider
154
+ ? undefined
155
+ : repository.findCustomModelProviderByProvider(normalizedProvider);
156
+ if (existingWithNextProvider) {
157
+ throw new Error("Provider already exists");
158
+ }
159
+ return (repository.updateCustomModelProvider(provider, {
160
+ baseUrl: normalizedBaseUrl,
161
+ provider: normalizedProvider
162
+ }) ?? null);
163
+ },
164
+ updateCustomProviderModel: (provider, modelId, input) => {
165
+ const customProvider = repository.findCustomModelProviderByProvider(provider);
166
+ if (!customProvider) {
167
+ return null;
168
+ }
169
+ const row = repository.updateCustomProviderModel(customProvider.id, modelId, {
170
+ api: input.api,
171
+ contextWindow: input.contextWindow,
172
+ input: input.input,
173
+ maxTokens: input.maxTokens,
174
+ name: normalizeCustomModelName(input.name, modelId),
175
+ reasoning: input.reasoning
176
+ });
177
+ return row ? mapCustomProviderModel(customProvider.provider, row) : null;
178
+ }
179
+ };
180
+ }
181
+ function findModelBaseUrl(provider, modelId, repository) {
182
+ if (hasBuiltInProvider(provider)) {
183
+ return getModels(provider).find((model) => model.id === modelId)?.baseUrl ?? null;
184
+ }
185
+ return repository.findCustomModelProviderByProvider(provider)?.baseUrl ?? null;
186
+ }
187
+ function findModel(provider, modelId, repository) {
188
+ if (hasBuiltInProvider(provider)) {
189
+ const model = getModels(provider).find((item) => item.id === modelId);
190
+ return model ? mapBuiltInModel(model) : null;
191
+ }
192
+ const customProvider = repository.findCustomModelProviderByProvider(provider);
193
+ if (!customProvider) {
194
+ return null;
195
+ }
196
+ const model = repository
197
+ .listCustomProviderModelsByProviderId(customProvider.id)
198
+ .find((item) => item.modelId === modelId);
199
+ if (!model) {
200
+ return null;
201
+ }
202
+ return {
203
+ ...mapCustomProviderModel(customProvider.provider, model)
204
+ };
205
+ }
206
+ function hasBuiltInProvider(provider) {
207
+ return getProviders().includes(provider);
208
+ }
209
+ function hasCustomProvider(provider, repository) {
210
+ return repository.findCustomModelProviderByProvider(provider) !== undefined;
211
+ }
212
+ function mapBuiltInModel(model) {
213
+ return {
214
+ api: model.api,
215
+ contextWindow: model.contextWindow,
216
+ id: model.id,
217
+ input: [...model.input],
218
+ maxTokens: model.maxTokens,
219
+ name: model.name,
220
+ provider: model.provider,
221
+ reasoning: model.reasoning
222
+ };
223
+ }
224
+ function mapCustomProviderModel(provider, model) {
225
+ return {
226
+ api: model.api,
227
+ contextWindow: model.contextWindow,
228
+ id: model.modelId,
229
+ input: JSON.parse(model.input),
230
+ maxTokens: model.maxTokens,
231
+ name: model.name && model.name.trim().length > 0 ? model.name : model.modelId,
232
+ provider,
233
+ reasoning: model.reasoning
234
+ };
235
+ }
236
+ function normalizeCustomModelName(name, modelId) {
237
+ const normalizedName = name.trim();
238
+ return normalizedName.length > 0 ? normalizedName : modelId.trim();
239
+ }
@@ -0,0 +1,3 @@
1
+ import { type ModelProxiesService } from "./model-proxies-service";
2
+ export declare function getDefaultModelProxiesService(): ModelProxiesService;
3
+ //# sourceMappingURL=default-model-proxies-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-model-proxies-service.d.ts","sourceRoot":"","sources":["../../../src/modules/model-proxies/default-model-proxies-service.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAC;AAKjC,wBAAgB,6BAA6B,IAAI,mBAAmB,CAanE"}
@@ -0,0 +1,22 @@
1
+ import { DB_FILE } from "../../config/const.js";
2
+ import { loadApiEnv } from "../../config/env.js";
3
+ import { createDatabase, migrateDatabase } from "../../db/index.js";
4
+ import { getDefaultModelProvidersService } from "../model-providers/index.js";
5
+ import { createSqliteModelProxyRepository } from "./model-proxy-repository.js";
6
+ import { createModelProxiesService } from "./model-proxies-service.js";
7
+ let repository;
8
+ let service;
9
+ export function getDefaultModelProxiesService() {
10
+ if (service)
11
+ return service;
12
+ loadApiEnv();
13
+ const database = createDatabase(process.env.SQLITE_DB_PATH ?? DB_FILE);
14
+ migrateDatabase(database.sqlite);
15
+ repository = createSqliteModelProxyRepository(database);
16
+ service = createModelProxiesService({
17
+ modelProvidersService: getDefaultModelProvidersService(),
18
+ repository,
19
+ usageRepository: repository
20
+ });
21
+ return service;
22
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./default-model-proxies-service";
2
+ export * from "./model-proxy-repository";
3
+ export * from "./model-proxies-router";
4
+ export * from "./model-proxies-service";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/model-proxies/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./default-model-proxies-service.js";
2
+ export * from "./model-proxy-repository.js";
3
+ export * from "./model-proxies-router.js";
4
+ export * from "./model-proxies-service.js";
@@ -0,0 +1,7 @@
1
+ import { Router } from "express";
2
+ import type { ModelProxiesService } from "./model-proxies-service";
3
+ export interface CreateModelProxiesRouterOptions {
4
+ modelProxiesService?: ModelProxiesService;
5
+ }
6
+ export declare function createModelProxiesRouter(options?: CreateModelProxiesRouterOptions): Router;
7
+ //# sourceMappingURL=model-proxies-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-proxies-router.d.ts","sourceRoot":"","sources":["../../../src/modules/model-proxies/model-proxies-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA+B,MAAM,SAAS,CAAC;AAM9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,WAAW,+BAA+B;IAC9C,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;CAC3C;AAED,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,+BAAoC,GAC5C,MAAM,CAkER"}
@@ -0,0 +1,55 @@
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 { getDefaultModelProxiesService } from "./default-model-proxies-service.js";
5
+ export function createModelProxiesRouter(options = {}) {
6
+ const router = Router();
7
+ const getService = () => options.modelProxiesService ?? getDefaultModelProxiesService();
8
+ router.get("/model-proxies", (_request, response) => {
9
+ const service = getService();
10
+ sendSuccess(response, service.listProxies());
11
+ });
12
+ router.post("/model-proxies", (request, response) => {
13
+ const service = getService();
14
+ try {
15
+ sendSuccess(response, service.createProxy(request.body));
16
+ }
17
+ catch (error) {
18
+ sendError(response, RESPONSE_CODE_DEFINITIONS.badRequest, toErrorMessage(error));
19
+ }
20
+ });
21
+ router.get("/model-proxies/:modelId", (request, response) => {
22
+ const proxy = getService()?.findProxy(String(request.params.modelId ?? ""));
23
+ if (!proxy) {
24
+ sendError(response, RESPONSE_CODE_DEFINITIONS.notFound, "Unknown proxy model");
25
+ return;
26
+ }
27
+ sendSuccess(response, proxy);
28
+ });
29
+ router.put("/model-proxies/:modelId", (request, response) => {
30
+ const service = getService();
31
+ try {
32
+ const proxy = service.updateProxy(String(request.params.modelId ?? ""), request.body);
33
+ if (!proxy) {
34
+ sendError(response, RESPONSE_CODE_DEFINITIONS.notFound, "Unknown proxy model");
35
+ return;
36
+ }
37
+ sendSuccess(response, proxy);
38
+ }
39
+ catch (error) {
40
+ sendError(response, RESPONSE_CODE_DEFINITIONS.badRequest, toErrorMessage(error));
41
+ }
42
+ });
43
+ router.delete("/model-proxies/:modelId", (request, response) => {
44
+ const modelId = String(request.params.modelId ?? "");
45
+ if (!getService()?.deleteProxy(modelId)) {
46
+ sendError(response, RESPONSE_CODE_DEFINITIONS.notFound, "Unknown proxy model");
47
+ return;
48
+ }
49
+ sendSuccess(response, { modelId });
50
+ });
51
+ return router;
52
+ }
53
+ function toErrorMessage(error) {
54
+ return error instanceof Error ? error.message : "Model proxy request failed";
55
+ }
@@ -0,0 +1,26 @@
1
+ import type { ModelSummary, ModelProvidersService } from "../model-providers/model-providers-service";
2
+ import type { ModelProxyCandidateInput, ModelProxyDetails, ModelProxyRequestInput, ModelProxyRepository, ModelProxyUsageRepository } from "./model-proxy-repository";
3
+ export interface PendingProxyUsage {
4
+ inputToken: number;
5
+ modelId: string;
6
+ outputToken: number;
7
+ provider: string;
8
+ }
9
+ export interface ModelProxiesService {
10
+ createProxy: (input: ModelProxyRequestInput) => ModelProxyDetails;
11
+ deleteProxy: (modelId: string) => boolean;
12
+ findProxy: (modelId: string) => ModelProxyDetails | undefined;
13
+ hasProxy: (modelId: string) => boolean;
14
+ listProxies: () => ModelProxyDetails[];
15
+ listProxyModels: () => ModelSummary[];
16
+ selectCandidate: (modelId: string, pendingUsage?: Record<string, PendingProxyUsage>) => ModelProxyCandidateInput | null;
17
+ updateProxy: (modelId: string, input: ModelProxyRequestInput) => ModelProxyDetails | undefined;
18
+ }
19
+ export interface CreateModelProxiesServiceOptions {
20
+ modelProvidersService: ModelProvidersService;
21
+ now?: () => Date;
22
+ repository: ModelProxyRepository;
23
+ usageRepository: ModelProxyUsageRepository;
24
+ }
25
+ export declare function createModelProxiesService(options: CreateModelProxiesServiceOptions): ModelProxiesService;
26
+ //# sourceMappingURL=model-proxies-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-proxies-service.d.ts","sourceRoot":"","sources":["../../../src/modules/model-proxies/model-proxies-service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AACtG,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EAEjB,sBAAsB,EACtB,oBAAoB,EACpB,yBAAyB,EAE1B,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,iBAAiB,CAAC;IAClE,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IAC1C,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,iBAAiB,GAAG,SAAS,CAAC;IAC9D,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IACvC,WAAW,EAAE,MAAM,iBAAiB,EAAE,CAAC;IACvC,eAAe,EAAE,MAAM,YAAY,EAAE,CAAC;IACtC,eAAe,EAAE,CACf,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,KAC7C,wBAAwB,GAAG,IAAI,CAAC;IACrC,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,sBAAsB,KAAK,iBAAiB,GAAG,SAAS,CAAC;CAChG;AAED,MAAM,WAAW,gCAAgC;IAC/C,qBAAqB,EAAE,qBAAqB,CAAC;IAC7C,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,UAAU,EAAE,oBAAoB,CAAC;IACjC,eAAe,EAAE,yBAAyB,CAAC;CAC5C;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,gCAAgC,GACxC,mBAAmB,CA+FrB"}
@@ -0,0 +1,107 @@
1
+ import { randomUUID } from "node:crypto";
2
+ export function createModelProxiesService(options) {
3
+ const now = options.now ?? (() => new Date());
4
+ const validate = (input, existingModelId) => {
5
+ if (input.modelId.trim().length === 0 || input.name.trim().length === 0) {
6
+ throw new Error("Proxy model id and name are required");
7
+ }
8
+ if (input.modelId !== existingModelId && options.repository.findProxyByModelId(input.modelId)) {
9
+ throw new Error("Proxy model id already exists");
10
+ }
11
+ if (input.candidates.length === 0)
12
+ throw new Error("Proxy requires candidates");
13
+ for (const candidate of input.candidates)
14
+ validateCandidate(candidate);
15
+ };
16
+ const validateCandidate = (candidate) => {
17
+ const configured = options.modelProvidersService.getConfiguredModelForProvider(candidate.provider, candidate.modelId);
18
+ if (!configured)
19
+ throw new Error("Unknown candidate provider or model");
20
+ if (!configured.apiKey)
21
+ throw new Error("Candidate provider has no API key");
22
+ if (candidate.limits.length === 0)
23
+ throw new Error("Candidate requires limits");
24
+ for (const limit of candidate.limits) {
25
+ if (!Number.isFinite(limit.maxTokens) || limit.maxTokens <= 0) {
26
+ throw new Error("Token limits must be positive");
27
+ }
28
+ if (limit.windowType === "hours" && (!limit.windowHours || limit.windowHours <= 0)) {
29
+ throw new Error("Hour windows require positive windowHours");
30
+ }
31
+ }
32
+ };
33
+ return {
34
+ createProxy: (input) => {
35
+ const normalized = normalizeProxyInput(input, allocateProxyModelId());
36
+ validate(normalized);
37
+ return options.repository.createProxy(normalized);
38
+ },
39
+ deleteProxy: options.repository.deleteProxy,
40
+ findProxy: options.repository.findProxyByModelId,
41
+ hasProxy: (modelId) => options.repository.findProxyByModelId(modelId) !== undefined,
42
+ listProxies: options.repository.listProxies,
43
+ listProxyModels: () => options.repository.listProxies().map((proxy) => ({
44
+ api: "responses",
45
+ contextWindow: 0,
46
+ id: proxy.modelId,
47
+ input: ["text"],
48
+ maxTokens: 0,
49
+ name: proxy.name,
50
+ provider: "local",
51
+ reasoning: false
52
+ })),
53
+ selectCandidate: (modelId, pendingUsage = {}) => {
54
+ const proxy = options.repository.findProxyByModelId(modelId);
55
+ if (!proxy)
56
+ throw new Error("Unknown proxy model");
57
+ return proxy.candidates.find((candidate) => candidate.limits.every((limit) => hasCapacity(candidate, limit.windowType, limit.windowHours, limit.maxTokens, pendingUsage))) ?? null;
58
+ },
59
+ updateProxy: (modelId, input) => {
60
+ const normalized = normalizeProxyInput(input);
61
+ validate(normalized, modelId);
62
+ return options.repository.updateProxy(modelId, normalized);
63
+ }
64
+ };
65
+ function hasCapacity(candidate, windowType, windowHours, maxTokens, pendingUsage) {
66
+ const from = windowStart(windowType, windowHours).toISOString();
67
+ const flushed = options.usageRepository
68
+ .listModelTokenUsageSince(from)
69
+ .filter((row) => row.provider === candidate.provider && row.modelName === candidate.modelId)
70
+ .reduce((sum, row) => sum + row.inputToken + row.outputToken, 0);
71
+ const pending = Object.values(pendingUsage)
72
+ .filter((usage) => usage.provider === candidate.provider && usage.modelId === candidate.modelId)
73
+ .reduce((sum, usage) => sum + usage.inputToken + usage.outputToken, 0);
74
+ return flushed + pending < maxTokens;
75
+ }
76
+ function windowStart(type, hours) {
77
+ const current = now();
78
+ if (type === "hours")
79
+ return new Date(current.getTime() - (hours ?? 0) * 60 * 60 * 1000);
80
+ const start = new Date(current);
81
+ start.setUTCHours(0, 0, 0, 0);
82
+ if (type === "week")
83
+ start.setUTCDate(start.getUTCDate() - start.getUTCDay());
84
+ return start;
85
+ }
86
+ }
87
+ function allocateProxyModelId() {
88
+ return `local-${randomUUID()}`;
89
+ }
90
+ function normalizeProxyInput(input, fallbackModelId) {
91
+ return {
92
+ candidates: input.candidates
93
+ .map((candidate) => ({
94
+ limits: candidate.limits.map((limit) => ({
95
+ maxTokens: limit.maxTokens,
96
+ ...(limit.windowHours === undefined ? {} : { windowHours: limit.windowHours }),
97
+ windowType: limit.windowType
98
+ })),
99
+ modelId: candidate.modelId.trim(),
100
+ priority: candidate.priority,
101
+ provider: candidate.provider.trim()
102
+ }))
103
+ .sort((left, right) => left.priority - right.priority),
104
+ modelId: (input.modelId ?? fallbackModelId ?? "").trim(),
105
+ name: input.name.trim()
106
+ };
107
+ }
@@ -0,0 +1,39 @@
1
+ import type { AppDatabase, ModelProxyCandidateLimitRow, ModelProxyCandidateRow, ModelProxyRow, ModelTokenUsageHourlyRow } from "../../db";
2
+ export type ModelProxyWindowType = "hours" | "day" | "week";
3
+ export interface ModelProxyLimitInput {
4
+ maxTokens: number;
5
+ windowHours?: number | null;
6
+ windowType: ModelProxyWindowType;
7
+ }
8
+ export interface ModelProxyCandidateInput {
9
+ limits: ModelProxyLimitInput[];
10
+ modelId: string;
11
+ priority: number;
12
+ provider: string;
13
+ }
14
+ export interface ModelProxyInput {
15
+ candidates: ModelProxyCandidateInput[];
16
+ modelId: string;
17
+ name: string;
18
+ }
19
+ export interface ModelProxyRequestInput extends Omit<ModelProxyInput, "modelId"> {
20
+ modelId?: string;
21
+ }
22
+ export interface ModelProxyDetails extends ModelProxyRow {
23
+ candidates: (ModelProxyCandidateRow & {
24
+ limits: ModelProxyCandidateLimitRow[];
25
+ })[];
26
+ }
27
+ export interface ModelProxyRepository {
28
+ createProxy: (input: ModelProxyInput) => ModelProxyDetails;
29
+ deleteProxy: (modelId: string) => boolean;
30
+ findProxyByModelId: (modelId: string) => ModelProxyDetails | undefined;
31
+ listProxies: () => ModelProxyDetails[];
32
+ updateProxy: (modelId: string, input: ModelProxyInput) => ModelProxyDetails | undefined;
33
+ }
34
+ export interface ModelProxyUsageRepository {
35
+ listModelTokenUsageSince: (from: string) => ModelTokenUsageHourlyRow[];
36
+ }
37
+ export declare function createInMemoryModelProxyRepository(): ModelProxyRepository;
38
+ export declare function createSqliteModelProxyRepository(database: AppDatabase): ModelProxyRepository & ModelProxyUsageRepository;
39
+ //# sourceMappingURL=model-proxy-repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-proxy-repository.d.ts","sourceRoot":"","sources":["../../../src/modules/model-proxies/model-proxy-repository.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,WAAW,EACX,2BAA2B,EAC3B,sBAAsB,EACtB,aAAa,EACb,wBAAwB,EACzB,MAAM,UAAU,CAAC;AAQlB,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;AAE5D,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,oBAAoB,CAAC;CAClC;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,wBAAwB,EAAE,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC;IAC9E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,UAAU,EAAE,CAAC,sBAAsB,GAAG;QAAE,MAAM,EAAE,2BAA2B,EAAE,CAAA;KAAE,CAAC,EAAE,CAAC;CACpF;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,iBAAiB,CAAC;IAC3D,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IAC1C,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,iBAAiB,GAAG,SAAS,CAAC;IACvE,WAAW,EAAE,MAAM,iBAAiB,EAAE,CAAC;IACvC,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,iBAAiB,GAAG,SAAS,CAAC;CACzF;AAED,MAAM,WAAW,yBAAyB;IACxC,wBAAwB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,wBAAwB,EAAE,CAAC;CACxE;AAED,wBAAgB,kCAAkC,IAAI,oBAAoB,CAsDzE;AAED,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,WAAW,GACpB,oBAAoB,GAAG,yBAAyB,CA8ElD"}