@harperfast/harper 5.2.9 → 5.3.0-alpha.1

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 (668) hide show
  1. package/agent/mcpTools.ts +1 -1
  2. package/agent/session.ts +25 -14
  3. package/bin/cliOperations.ts +46 -9
  4. package/bin/copyDb.ts +282 -59
  5. package/bin/deploySetup.ts +16 -5
  6. package/bin/harper.ts +1 -1
  7. package/bin/help.ts +4 -1
  8. package/bin/lite.ts +4 -1
  9. package/bin/restart.ts +59 -3
  10. package/bin/run.ts +6 -11
  11. package/bin/upgrade.js +7 -3
  12. package/bin/workloadIdentity.ts +119 -0
  13. package/components/Application.ts +2414 -242
  14. package/components/ApplicationScope.ts +8 -0
  15. package/components/EntryHandler.ts +59 -39
  16. package/components/OptionsWatcher.ts +150 -74
  17. package/components/RuntimeModuleTracker.ts +38 -7
  18. package/components/Scope.ts +37 -15
  19. package/components/awaitRestart.ts +84 -0
  20. package/components/componentLoader.ts +340 -30
  21. package/components/componentPreparationLock.ts +16 -5
  22. package/components/mcp/adapters/harperHttp.ts +4 -0
  23. package/components/mcp/listChanged.ts +4 -0
  24. package/components/mcp/toolRegistry.ts +2 -0
  25. package/components/mcp/tools/operations.ts +9 -0
  26. package/components/mcp/tools/schemas/operationDescriptions.ts +2 -2
  27. package/components/operations.js +270 -78
  28. package/components/operationsValidation.js +49 -1
  29. package/components/status/ComponentStatusRegistry.ts +59 -0
  30. package/config/RootConfigWatcher.ts +80 -34
  31. package/config/configUtils.ts +291 -34
  32. package/config/harperConfigEnvVars.ts +170 -27
  33. package/config-root.schema.json +29 -0
  34. package/dataLayer/blobBackup.ts +160 -50
  35. package/dataLayer/delete.ts +6 -1
  36. package/dataLayer/harperBridge/ResourceBridge.ts +52 -8
  37. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.js +3 -1
  38. package/dataLayer/hdbInfoController.ts +34 -1
  39. package/dataLayer/insert.ts +44 -1
  40. package/dataLayer/rocksdbBackup.ts +53 -10
  41. package/dataLayer/schema.ts +11 -1
  42. package/dataLayer/schemaDescribe.ts +8 -1
  43. package/dist/agent/mcpTools.js +1 -1
  44. package/dist/agent/mcpTools.js.map +1 -1
  45. package/dist/agent/session.d.ts +22 -0
  46. package/dist/agent/session.js +26 -15
  47. package/dist/agent/session.js.map +1 -1
  48. package/dist/bin/cliOperations.js +48 -9
  49. package/dist/bin/cliOperations.js.map +1 -1
  50. package/dist/bin/copyDb.d.ts +12 -1
  51. package/dist/bin/copyDb.js +248 -60
  52. package/dist/bin/copyDb.js.map +1 -1
  53. package/dist/bin/deploySetup.d.ts +2 -0
  54. package/dist/bin/deploySetup.js +11 -3
  55. package/dist/bin/deploySetup.js.map +1 -1
  56. package/dist/bin/harper.js +1 -1
  57. package/dist/bin/harper.js.map +1 -1
  58. package/dist/bin/help.js +4 -1
  59. package/dist/bin/help.js.map +1 -1
  60. package/dist/bin/lite.js +4 -1
  61. package/dist/bin/lite.js.map +1 -1
  62. package/dist/bin/restart.js +54 -5
  63. package/dist/bin/restart.js.map +1 -1
  64. package/dist/bin/run.js +4 -10
  65. package/dist/bin/run.js.map +1 -1
  66. package/dist/bin/upgrade.js +4 -3
  67. package/dist/bin/upgrade.js.map +1 -1
  68. package/dist/bin/workloadIdentity.d.ts +18 -0
  69. package/dist/bin/workloadIdentity.js +100 -0
  70. package/dist/bin/workloadIdentity.js.map +1 -0
  71. package/dist/components/Application.d.ts +139 -16
  72. package/dist/components/Application.js +2215 -267
  73. package/dist/components/Application.js.map +1 -1
  74. package/dist/components/ApplicationScope.d.ts +8 -0
  75. package/dist/components/ApplicationScope.js +7 -0
  76. package/dist/components/ApplicationScope.js.map +1 -1
  77. package/dist/components/EntryHandler.js +26 -10
  78. package/dist/components/EntryHandler.js.map +1 -1
  79. package/dist/components/OptionsWatcher.d.ts +1 -0
  80. package/dist/components/OptionsWatcher.js +141 -74
  81. package/dist/components/OptionsWatcher.js.map +1 -1
  82. package/dist/components/RuntimeModuleTracker.js +40 -6
  83. package/dist/components/RuntimeModuleTracker.js.map +1 -1
  84. package/dist/components/Scope.js +38 -13
  85. package/dist/components/Scope.js.map +1 -1
  86. package/dist/components/awaitRestart.d.ts +33 -0
  87. package/dist/components/awaitRestart.js +61 -0
  88. package/dist/components/awaitRestart.js.map +1 -0
  89. package/dist/components/componentLoader.d.ts +38 -1
  90. package/dist/components/componentLoader.js +279 -22
  91. package/dist/components/componentLoader.js.map +1 -1
  92. package/dist/components/componentPreparationLock.d.ts +5 -0
  93. package/dist/components/componentPreparationLock.js +14 -6
  94. package/dist/components/componentPreparationLock.js.map +1 -1
  95. package/dist/components/mcp/adapters/harperHttp.js +4 -0
  96. package/dist/components/mcp/adapters/harperHttp.js.map +1 -1
  97. package/dist/components/mcp/listChanged.js +5 -0
  98. package/dist/components/mcp/listChanged.js.map +1 -1
  99. package/dist/components/mcp/toolRegistry.d.ts +1 -0
  100. package/dist/components/mcp/toolRegistry.js.map +1 -1
  101. package/dist/components/mcp/tools/operations.d.ts +5 -0
  102. package/dist/components/mcp/tools/operations.js +9 -0
  103. package/dist/components/mcp/tools/operations.js.map +1 -1
  104. package/dist/components/mcp/tools/schemas/operationDescriptions.js +2 -2
  105. package/dist/components/mcp/tools/schemas/operationDescriptions.js.map +1 -1
  106. package/dist/components/operations.js +231 -77
  107. package/dist/components/operations.js.map +1 -1
  108. package/dist/components/operationsValidation.js +49 -1
  109. package/dist/components/operationsValidation.js.map +1 -1
  110. package/dist/components/status/ComponentStatusRegistry.d.ts +0 -4
  111. package/dist/components/status/ComponentStatusRegistry.js +63 -0
  112. package/dist/components/status/ComponentStatusRegistry.js.map +1 -1
  113. package/dist/config/RootConfigWatcher.d.ts +7 -1
  114. package/dist/config/RootConfigWatcher.js +64 -27
  115. package/dist/config/RootConfigWatcher.js.map +1 -1
  116. package/dist/config/configUtils.d.ts +9 -1
  117. package/dist/config/configUtils.js +254 -33
  118. package/dist/config/configUtils.js.map +1 -1
  119. package/dist/config/harperConfigEnvVars.d.ts +16 -0
  120. package/dist/config/harperConfigEnvVars.js +162 -25
  121. package/dist/config/harperConfigEnvVars.js.map +1 -1
  122. package/dist/dataLayer/blobBackup.d.ts +49 -20
  123. package/dist/dataLayer/blobBackup.js +139 -50
  124. package/dist/dataLayer/blobBackup.js.map +1 -1
  125. package/dist/dataLayer/delete.js +1 -1
  126. package/dist/dataLayer/delete.js.map +1 -1
  127. package/dist/dataLayer/harperBridge/ResourceBridge.d.ts +14 -1
  128. package/dist/dataLayer/harperBridge/ResourceBridge.js +51 -10
  129. package/dist/dataLayer/harperBridge/ResourceBridge.js.map +1 -1
  130. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.d.ts +3 -1
  131. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.js +3 -1
  132. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.js.map +1 -1
  133. package/dist/dataLayer/hdbInfoController.d.ts +10 -0
  134. package/dist/dataLayer/hdbInfoController.js +30 -1
  135. package/dist/dataLayer/hdbInfoController.js.map +1 -1
  136. package/dist/dataLayer/insert.d.ts +9 -1
  137. package/dist/dataLayer/insert.js +30 -0
  138. package/dist/dataLayer/insert.js.map +1 -1
  139. package/dist/dataLayer/rocksdbBackup.d.ts +2 -2
  140. package/dist/dataLayer/rocksdbBackup.js +45 -8
  141. package/dist/dataLayer/rocksdbBackup.js.map +1 -1
  142. package/dist/dataLayer/schema.js +8 -0
  143. package/dist/dataLayer/schema.js.map +1 -1
  144. package/dist/dataLayer/schemaDescribe.js +8 -1
  145. package/dist/dataLayer/schemaDescribe.js.map +1 -1
  146. package/dist/index.d.ts +1 -1
  147. package/dist/index.js.map +1 -1
  148. package/dist/json/systemSchema.json +52 -0
  149. package/dist/resources/DatabaseTransaction.d.ts +55 -0
  150. package/dist/resources/DatabaseTransaction.js +459 -45
  151. package/dist/resources/DatabaseTransaction.js.map +1 -1
  152. package/dist/resources/LMDBTransaction.js +22 -4
  153. package/dist/resources/LMDBTransaction.js.map +1 -1
  154. package/dist/resources/PrimaryRocksDatabase.d.ts +1 -0
  155. package/dist/resources/PrimaryRocksDatabase.js +29 -0
  156. package/dist/resources/PrimaryRocksDatabase.js.map +1 -1
  157. package/dist/resources/RecordEncoder.d.ts +20 -0
  158. package/dist/resources/RecordEncoder.js +94 -9
  159. package/dist/resources/RecordEncoder.js.map +1 -1
  160. package/dist/resources/RequestTarget.d.ts +2 -0
  161. package/dist/resources/RequestTarget.js.map +1 -1
  162. package/dist/resources/Resource.js +20 -11
  163. package/dist/resources/Resource.js.map +1 -1
  164. package/dist/resources/ResourceInterface.d.ts +20 -1
  165. package/dist/resources/ResourceInterface.js.map +1 -1
  166. package/dist/resources/RocksIndexStore.d.ts +6 -1
  167. package/dist/resources/RocksIndexStore.js +24 -9
  168. package/dist/resources/RocksIndexStore.js.map +1 -1
  169. package/dist/resources/RocksTransactionLogStore.d.ts +14 -1
  170. package/dist/resources/RocksTransactionLogStore.js +57 -17
  171. package/dist/resources/RocksTransactionLogStore.js.map +1 -1
  172. package/dist/resources/Table.d.ts +112 -8
  173. package/dist/resources/Table.js +1073 -191
  174. package/dist/resources/Table.js.map +1 -1
  175. package/dist/resources/auditStore.d.ts +11 -2
  176. package/dist/resources/auditStore.js +325 -71
  177. package/dist/resources/auditStore.js.map +1 -1
  178. package/dist/resources/blob.d.ts +129 -9
  179. package/dist/resources/blob.js +992 -114
  180. package/dist/resources/blob.js.map +1 -1
  181. package/dist/resources/branchDatabase.d.ts +48 -0
  182. package/dist/resources/branchDatabase.js +892 -0
  183. package/dist/resources/branchDatabase.js.map +1 -0
  184. package/dist/resources/crdt.js +50 -12
  185. package/dist/resources/crdt.js.map +1 -1
  186. package/dist/resources/databases.d.ts +150 -0
  187. package/dist/resources/databases.js +1200 -239
  188. package/dist/resources/databases.js.map +1 -1
  189. package/dist/resources/defineTable.d.ts +10 -2
  190. package/dist/resources/defineTable.js +9 -1
  191. package/dist/resources/defineTable.js.map +1 -1
  192. package/dist/resources/graphql.d.ts +1 -1
  193. package/dist/resources/graphql.js +50 -15
  194. package/dist/resources/graphql.js.map +1 -1
  195. package/dist/resources/indexes/HierarchicalNavigableSmallWorld.d.ts +1 -0
  196. package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js +6 -2
  197. package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js.map +1 -1
  198. package/dist/resources/longLivedTransactions.d.ts +71 -0
  199. package/dist/resources/longLivedTransactions.js +358 -0
  200. package/dist/resources/longLivedTransactions.js.map +1 -0
  201. package/dist/resources/models/backendRegistry.d.ts +26 -0
  202. package/dist/resources/models/backendRegistry.js +60 -2
  203. package/dist/resources/models/backendRegistry.js.map +1 -1
  204. package/dist/resources/models/bootstrap.d.ts +33 -1
  205. package/dist/resources/models/bootstrap.js +416 -31
  206. package/dist/resources/models/bootstrap.js.map +1 -1
  207. package/dist/resources/recordLock.d.ts +80 -0
  208. package/dist/resources/recordLock.js +184 -0
  209. package/dist/resources/recordLock.js.map +1 -0
  210. package/dist/resources/replayLogs.d.ts +14 -1
  211. package/dist/resources/replayLogs.js +152 -24
  212. package/dist/resources/replayLogs.js.map +1 -1
  213. package/dist/resources/replayLogsGuards.d.ts +94 -7
  214. package/dist/resources/replayLogsGuards.js +111 -7
  215. package/dist/resources/replayLogsGuards.js.map +1 -1
  216. package/dist/resources/search.js +158 -6
  217. package/dist/resources/search.js.map +1 -1
  218. package/dist/resources/transactionBroadcast.d.ts +1 -1
  219. package/dist/resources/transactionBroadcast.js +2 -2
  220. package/dist/resources/transactionBroadcast.js.map +1 -1
  221. package/dist/security/auth.js +61 -30
  222. package/dist/security/auth.js.map +1 -1
  223. package/dist/security/authn/oidc/claims.d.ts +22 -0
  224. package/dist/security/authn/oidc/claims.js +71 -0
  225. package/dist/security/authn/oidc/claims.js.map +1 -0
  226. package/dist/security/authn/oidc/identityToken.d.ts +27 -0
  227. package/dist/security/authn/oidc/identityToken.js +111 -0
  228. package/dist/security/authn/oidc/identityToken.js.map +1 -0
  229. package/dist/security/authn/oidc/jwks.d.ts +25 -0
  230. package/dist/security/authn/oidc/jwks.js +261 -0
  231. package/dist/security/authn/oidc/jwks.js.map +1 -0
  232. package/dist/security/authn/oidc/providers/generic.d.ts +13 -0
  233. package/dist/security/authn/oidc/providers/generic.js +34 -0
  234. package/dist/security/authn/oidc/providers/generic.js.map +1 -0
  235. package/dist/security/authn/oidc/providers/githubActions.d.ts +11 -0
  236. package/dist/security/authn/oidc/providers/githubActions.js +129 -0
  237. package/dist/security/authn/oidc/providers/githubActions.js.map +1 -0
  238. package/dist/security/authn/oidc/providers/index.d.ts +37 -0
  239. package/dist/security/authn/oidc/providers/index.js +24 -0
  240. package/dist/security/authn/oidc/providers/index.js.map +1 -0
  241. package/dist/security/authn/oidc/tokenExchange.d.ts +12 -0
  242. package/dist/security/authn/oidc/tokenExchange.js +306 -0
  243. package/dist/security/authn/oidc/tokenExchange.js.map +1 -0
  244. package/dist/security/authn/oidc/trustPolicyOperations.d.ts +49 -0
  245. package/dist/security/authn/oidc/trustPolicyOperations.js +358 -0
  246. package/dist/security/authn/oidc/trustPolicyOperations.js.map +1 -0
  247. package/dist/security/authn/oidc/types.d.ts +38 -0
  248. package/dist/security/authn/oidc/types.js +6 -0
  249. package/dist/security/authn/oidc/types.js.map +1 -0
  250. package/dist/security/certificateVerification/index.js +40 -11
  251. package/dist/security/certificateVerification/index.js.map +1 -1
  252. package/dist/security/certificateVerification/trustedIssuers.d.ts +24 -0
  253. package/dist/security/certificateVerification/trustedIssuers.js +79 -0
  254. package/dist/security/certificateVerification/trustedIssuers.js.map +1 -0
  255. package/dist/security/certificateVerification/types.d.ts +1 -0
  256. package/dist/security/credentialProvenance.d.ts +35 -0
  257. package/dist/security/credentialProvenance.js +51 -0
  258. package/dist/security/credentialProvenance.js.map +1 -0
  259. package/dist/security/credentialRejection.d.ts +4 -0
  260. package/dist/security/credentialRejection.js +24 -0
  261. package/dist/security/credentialRejection.js.map +1 -0
  262. package/dist/security/deferredAuthentication.d.ts +36 -0
  263. package/dist/security/deferredAuthentication.js +70 -0
  264. package/dist/security/deferredAuthentication.js.map +1 -0
  265. package/dist/security/impersonation.d.ts +21 -0
  266. package/dist/security/impersonation.js +108 -9
  267. package/dist/security/impersonation.js.map +1 -1
  268. package/dist/security/jsLoader.d.ts +6 -0
  269. package/dist/security/jsLoader.js +75 -15
  270. package/dist/security/jsLoader.js.map +1 -1
  271. package/dist/security/keys.js +301 -71
  272. package/dist/security/keys.js.map +1 -1
  273. package/dist/security/operationScope.d.ts +21 -0
  274. package/dist/security/operationScope.js +36 -0
  275. package/dist/security/operationScope.js.map +1 -0
  276. package/dist/security/permissionsTranslator.js +21 -0
  277. package/dist/security/permissionsTranslator.js.map +1 -1
  278. package/dist/security/tokenAuthentication.d.ts +19 -1
  279. package/dist/security/tokenAuthentication.js +191 -10
  280. package/dist/security/tokenAuthentication.js.map +1 -1
  281. package/dist/security/user.js +4 -3
  282. package/dist/security/user.js.map +1 -1
  283. package/dist/server/DurableSubscriptionsSession.d.ts +2 -2
  284. package/dist/server/DurableSubscriptionsSession.js +67 -10
  285. package/dist/server/DurableSubscriptionsSession.js.map +1 -1
  286. package/dist/server/REST.js +73 -0
  287. package/dist/server/REST.js.map +1 -1
  288. package/dist/server/graphqlQuerying.js +4 -0
  289. package/dist/server/graphqlQuerying.js.map +1 -1
  290. package/dist/server/http.d.ts +11 -0
  291. package/dist/server/http.js +88 -15
  292. package/dist/server/http.js.map +1 -1
  293. package/dist/server/itc/serverHandlers.js +8 -1
  294. package/dist/server/itc/serverHandlers.js.map +1 -1
  295. package/dist/server/jobs/jobProcess.js +6 -2
  296. package/dist/server/jobs/jobProcess.js.map +1 -1
  297. package/dist/server/jobs/jobs.js +4 -1
  298. package/dist/server/jobs/jobs.js.map +1 -1
  299. package/dist/server/liveSubscriptionAuth.d.ts +26 -4
  300. package/dist/server/liveSubscriptionAuth.js +105 -39
  301. package/dist/server/liveSubscriptionAuth.js.map +1 -1
  302. package/dist/server/loadRootComponents.js +49 -10
  303. package/dist/server/loadRootComponents.js.map +1 -1
  304. package/dist/server/mqtt.d.ts +2 -0
  305. package/dist/server/mqtt.js +165 -30
  306. package/dist/server/mqtt.js.map +1 -1
  307. package/dist/server/nodeName.d.ts +2 -0
  308. package/dist/server/nodeName.js +107 -23
  309. package/dist/server/nodeName.js.map +1 -1
  310. package/dist/server/serverHelpers/Headers.d.ts +25 -0
  311. package/dist/server/serverHelpers/Headers.js +139 -1
  312. package/dist/server/serverHelpers/Headers.js.map +1 -1
  313. package/dist/server/serverHelpers/contentTypes.d.ts +9 -0
  314. package/dist/server/serverHelpers/contentTypes.js +32 -25
  315. package/dist/server/serverHelpers/contentTypes.js.map +1 -1
  316. package/dist/server/serverHelpers/deployValidationState.d.ts +3 -0
  317. package/dist/server/serverHelpers/deployValidationState.js +9 -19
  318. package/dist/server/serverHelpers/deployValidationState.js.map +1 -1
  319. package/dist/server/serverHelpers/operationAuthorizationState.d.ts +12 -0
  320. package/dist/server/serverHelpers/operationAuthorizationState.js +24 -2
  321. package/dist/server/serverHelpers/operationAuthorizationState.js.map +1 -1
  322. package/dist/server/serverHelpers/registeredOperations.d.ts +5 -4
  323. package/dist/server/serverHelpers/registeredOperations.js +74 -21
  324. package/dist/server/serverHelpers/registeredOperations.js.map +1 -1
  325. package/dist/server/serverHelpers/requestSanitization.d.ts +11 -0
  326. package/dist/server/serverHelpers/requestSanitization.js +20 -0
  327. package/dist/server/serverHelpers/requestSanitization.js.map +1 -0
  328. package/dist/server/serverHelpers/serverHandlers.js +6 -3
  329. package/dist/server/serverHelpers/serverHandlers.js.map +1 -1
  330. package/dist/server/serverHelpers/serverUtilities.d.ts +18 -0
  331. package/dist/server/serverHelpers/serverUtilities.js +90 -20
  332. package/dist/server/serverHelpers/serverUtilities.js.map +1 -1
  333. package/dist/server/serverHelpers/sharedMessageEncoding.d.ts +67 -0
  334. package/dist/server/serverHelpers/sharedMessageEncoding.js +280 -0
  335. package/dist/server/serverHelpers/sharedMessageEncoding.js.map +1 -0
  336. package/dist/server/serverHelpers/uwsServer.js +19 -1
  337. package/dist/server/serverHelpers/uwsServer.js.map +1 -1
  338. package/dist/server/static.js +24 -28
  339. package/dist/server/static.js.map +1 -1
  340. package/dist/server/storageReclamation.d.ts +12 -0
  341. package/dist/server/storageReclamation.js +26 -0
  342. package/dist/server/storageReclamation.js.map +1 -1
  343. package/dist/server/threads/itc.d.ts +7 -2
  344. package/dist/server/threads/itc.js +5 -1
  345. package/dist/server/threads/itc.js.map +1 -1
  346. package/dist/server/threads/manageThreads.d.ts +26 -3
  347. package/dist/server/threads/manageThreads.js +517 -65
  348. package/dist/server/threads/manageThreads.js.map +1 -1
  349. package/dist/server/threads/socketRouter.js +89 -26
  350. package/dist/server/threads/socketRouter.js.map +1 -1
  351. package/dist/server/threads/threadHeapMemory.d.ts +2 -0
  352. package/dist/server/threads/threadHeapMemory.js +31 -0
  353. package/dist/server/threads/threadHeapMemory.js.map +1 -0
  354. package/dist/server/threads/threadServer.js +46 -15
  355. package/dist/server/threads/threadServer.js.map +1 -1
  356. package/dist/sqlEngine/config.d.ts +1 -3
  357. package/dist/sqlEngine/config.js +19 -16
  358. package/dist/sqlEngine/config.js.map +1 -1
  359. package/dist/sqlTranslator/index.d.ts +1 -1
  360. package/dist/sqlTranslator/index.js +30 -7
  361. package/dist/sqlTranslator/index.js.map +1 -1
  362. package/dist/upgrade/directives/5-3-0.d.ts +7 -0
  363. package/dist/upgrade/directives/5-3-0.js +148 -0
  364. package/dist/upgrade/directives/5-3-0.js.map +1 -0
  365. package/dist/upgrade/directives/directivesController.js +2 -1
  366. package/dist/upgrade/directives/directivesController.js.map +1 -1
  367. package/dist/utility/OperationFunctionCaller.js +2 -1
  368. package/dist/utility/OperationFunctionCaller.js.map +1 -1
  369. package/dist/utility/common_utils.d.ts +16 -0
  370. package/dist/utility/common_utils.js +32 -6
  371. package/dist/utility/common_utils.js.map +1 -1
  372. package/dist/utility/componentNames.d.ts +8 -0
  373. package/dist/utility/componentNames.js +12 -1
  374. package/dist/utility/componentNames.js.map +1 -1
  375. package/dist/utility/environment/environmentManager.js +3 -6
  376. package/dist/utility/environment/environmentManager.js.map +1 -1
  377. package/dist/utility/environment/systemInformation.d.ts +1 -0
  378. package/dist/utility/environment/systemInformation.js +1 -0
  379. package/dist/utility/environment/systemInformation.js.map +1 -1
  380. package/dist/utility/errors/commonErrors.d.ts +2 -0
  381. package/dist/utility/errors/commonErrors.js +2 -0
  382. package/dist/utility/errors/commonErrors.js.map +1 -1
  383. package/dist/utility/errors/hdbError.d.ts +17 -0
  384. package/dist/utility/errors/hdbError.js +30 -1
  385. package/dist/utility/errors/hdbError.js.map +1 -1
  386. package/dist/utility/globalSchema.d.ts +18 -0
  387. package/dist/utility/hdbTerms.d.ts +16 -0
  388. package/dist/utility/hdbTerms.js +18 -2
  389. package/dist/utility/hdbTerms.js.map +1 -1
  390. package/dist/utility/logging/harper_logger.d.ts +2 -0
  391. package/dist/utility/logging/harper_logger.js +91 -14
  392. package/dist/utility/logging/harper_logger.js.map +1 -1
  393. package/dist/utility/logging/logRotator.js +76 -49
  394. package/dist/utility/logging/logRotator.js.map +1 -1
  395. package/dist/utility/nodeIdentity.d.ts +9 -0
  396. package/dist/utility/nodeIdentity.js +58 -0
  397. package/dist/utility/nodeIdentity.js.map +1 -0
  398. package/dist/utility/npmUtilities.js +9 -7
  399. package/dist/utility/npmUtilities.js.map +1 -1
  400. package/dist/utility/operationPermissions.d.ts +3 -1
  401. package/dist/utility/operationPermissions.js +16 -1
  402. package/dist/utility/operationPermissions.js.map +1 -1
  403. package/dist/utility/operation_authorization.d.ts +10 -7
  404. package/dist/utility/operation_authorization.js +212 -41
  405. package/dist/utility/operation_authorization.js.map +1 -1
  406. package/dist/utility/watchPath.d.ts +29 -0
  407. package/dist/utility/watchPath.js +68 -0
  408. package/dist/utility/watchPath.js.map +1 -0
  409. package/dist/utility/watcherFallback.d.ts +86 -0
  410. package/dist/utility/watcherFallback.js +278 -1
  411. package/dist/utility/watcherFallback.js.map +1 -1
  412. package/dist/validation/configValidator.d.ts +12 -0
  413. package/dist/validation/configValidator.js +199 -72
  414. package/dist/validation/configValidator.js.map +1 -1
  415. package/dist/validation/installValidator.js +12 -0
  416. package/dist/validation/installValidator.js.map +1 -1
  417. package/dist/validation/validationWrapper.d.ts +11 -0
  418. package/dist/validation/validationWrapper.js +16 -3
  419. package/dist/validation/validationWrapper.js.map +1 -1
  420. package/index.ts +2 -0
  421. package/json/systemSchema.json +52 -0
  422. package/npm-shrinkwrap.json +196 -194
  423. package/package.json +7 -6
  424. package/resources/DESIGN.md +114 -52
  425. package/resources/DatabaseTransaction.ts +521 -43
  426. package/resources/LMDBTransaction.ts +26 -4
  427. package/resources/PrimaryRocksDatabase.ts +28 -1
  428. package/resources/RecordEncoder.ts +103 -8
  429. package/resources/RequestTarget.ts +2 -0
  430. package/resources/Resource.ts +17 -9
  431. package/resources/ResourceInterface.ts +23 -0
  432. package/resources/RocksIndexStore.ts +30 -9
  433. package/resources/RocksTransactionLogStore.ts +78 -21
  434. package/resources/Table.ts +1110 -159
  435. package/resources/auditStore.ts +331 -73
  436. package/resources/blob.ts +1029 -110
  437. package/resources/branchDatabase.ts +941 -0
  438. package/resources/crdt.ts +76 -12
  439. package/resources/databases.ts +1310 -252
  440. package/resources/defineTable.ts +18 -2
  441. package/resources/graphql.ts +70 -16
  442. package/resources/indexes/HierarchicalNavigableSmallWorld.ts +6 -2
  443. package/resources/longLivedTransactions.ts +360 -0
  444. package/resources/models/backendRegistry.ts +84 -2
  445. package/resources/models/bootstrap.ts +473 -28
  446. package/resources/recordLock.ts +253 -0
  447. package/resources/replayLogs.ts +147 -26
  448. package/resources/replayLogsGuards.ts +171 -8
  449. package/resources/search.ts +154 -7
  450. package/resources/transactionBroadcast.ts +3 -3
  451. package/security/auth.ts +68 -29
  452. package/security/authn/oidc/claims.ts +72 -0
  453. package/security/authn/oidc/identityToken.ts +129 -0
  454. package/security/authn/oidc/jwks.ts +260 -0
  455. package/security/authn/oidc/providers/generic.ts +40 -0
  456. package/security/authn/oidc/providers/githubActions.ts +137 -0
  457. package/security/authn/oidc/providers/index.ts +52 -0
  458. package/security/authn/oidc/tokenExchange.ts +300 -0
  459. package/security/authn/oidc/trustPolicyOperations.ts +343 -0
  460. package/security/authn/oidc/types.ts +41 -0
  461. package/security/certificateVerification/index.ts +54 -13
  462. package/security/certificateVerification/trustedIssuers.ts +76 -0
  463. package/security/certificateVerification/types.ts +1 -0
  464. package/security/credentialProvenance.ts +47 -0
  465. package/security/credentialRejection.ts +22 -0
  466. package/security/deferredAuthentication.ts +71 -0
  467. package/security/impersonation.ts +117 -12
  468. package/security/jsLoader.ts +81 -18
  469. package/security/keys.ts +298 -72
  470. package/security/operationScope.ts +33 -0
  471. package/security/permissionsTranslator.js +23 -0
  472. package/security/tokenAuthentication.ts +233 -12
  473. package/security/user.ts +4 -3
  474. package/server/DESIGN.md +183 -16
  475. package/server/DurableSubscriptionsSession.ts +71 -11
  476. package/server/REST.ts +79 -1
  477. package/server/graphqlQuerying.ts +4 -0
  478. package/server/http.ts +99 -18
  479. package/server/itc/serverHandlers.js +8 -1
  480. package/server/jobs/jobProcess.ts +8 -2
  481. package/server/jobs/jobs.ts +4 -1
  482. package/server/liveSubscriptionAuth.ts +129 -46
  483. package/server/loadRootComponents.js +50 -8
  484. package/server/mqtt.ts +179 -38
  485. package/server/nodeName.ts +103 -21
  486. package/server/serverHelpers/Headers.ts +131 -0
  487. package/server/serverHelpers/contentTypes.ts +29 -21
  488. package/server/serverHelpers/deployValidationState.ts +24 -13
  489. package/server/serverHelpers/operationAuthorizationState.ts +34 -3
  490. package/server/serverHelpers/registeredOperations.ts +79 -22
  491. package/server/serverHelpers/requestSanitization.ts +15 -0
  492. package/server/serverHelpers/serverHandlers.js +6 -3
  493. package/server/serverHelpers/serverUtilities.ts +104 -31
  494. package/server/serverHelpers/sharedMessageEncoding.ts +307 -0
  495. package/server/serverHelpers/uwsServer.ts +17 -2
  496. package/server/static.ts +23 -29
  497. package/server/storageReclamation.ts +23 -0
  498. package/server/threads/itc.js +11 -1
  499. package/server/threads/manageThreads.js +526 -56
  500. package/server/threads/socketRouter.ts +81 -26
  501. package/server/threads/threadHeapMemory.ts +26 -0
  502. package/server/threads/threadServer.js +43 -15
  503. package/sqlTranslator/index.ts +31 -8
  504. package/studio/web/assets/Chat-BnCBegQz.js +2267 -0
  505. package/studio/web/assets/FloatingChat-CoDW1ySS.js +23 -0
  506. package/studio/web/assets/{abnfDiagram-VCTEODGH-C0_BAZyO.js → abnfDiagram-VCTEODGH-B0BebmD2.js} +1 -1
  507. package/studio/web/assets/{alertDialog-DIHt7Z0r.js → alertDialog-CQyAJJhl.js} +1 -1
  508. package/studio/web/assets/{apiToken-c3Rd-w6g.js → apiToken-Bwk5BLXW.js} +1 -1
  509. package/studio/web/assets/applications-DHxGi7JH.js +296 -0
  510. package/studio/web/assets/architecture-7GRP2DOG-LB-MLAAb.js +1 -0
  511. package/studio/web/assets/{architectureDiagram-5GKGNRK7-BWzrASgm.js → architectureDiagram-5GKGNRK7-7SW3GD-K.js} +1 -1
  512. package/studio/web/assets/authStore-C3Nfubqr.js +3 -0
  513. package/studio/web/assets/{blockDiagram-NRAW4CY4-BdJX9Khj.js → blockDiagram-I7D4REHJ-BqguiadH.js} +2 -2
  514. package/studio/web/assets/{button-DhiX-njv.js → button-BIsUKRZq.js} +2 -2
  515. package/studio/web/assets/{c4Diagram-UCG6FXSJ-CI6MzGmQ.js → c4Diagram-7LVT6UL2-LBNf8t_X.js} +1 -1
  516. package/studio/web/assets/channel-yictG-U-.js +1 -0
  517. package/studio/web/assets/{chevron-up-Df2c8uoU.js → chevron-up-DtKGqDn3.js} +1 -1
  518. package/studio/web/assets/{chunk-TEH6E4GO-P87k5mNi.js → chunk-4HAMMTFA-DWtTut21.js} +1 -1
  519. package/studio/web/assets/{chunk-75Z2AOVW-BT8tVmks.js → chunk-75Z2AOVW-QGQD6th2.js} +1 -1
  520. package/studio/web/assets/{chunk-DU6HZSFF-9kAOOmI6.js → chunk-DU6HZSFF-Chq20Ba5.js} +1 -1
  521. package/studio/web/assets/{chunk-F27PBJKO-BW7ao8AY.js → chunk-F27PBJKO-BVA5EPhV.js} +1 -1
  522. package/studio/web/assets/{chunk-GMAD6QVW-BNyXpoQO.js → chunk-GMAD6QVW-BeS7S07A.js} +1 -1
  523. package/studio/web/assets/{chunk-OBVCFTLP-D4wWOqDQ.js → chunk-GVQU2GXP-sbwVIQ8i.js} +1 -1
  524. package/studio/web/assets/{chunk-G27WJ6UU-COyLMcgK.js → chunk-IMKFNOWR-Bnh3tAVd.js} +1 -1
  525. package/studio/web/assets/{chunk-JQ64N6SF-Cyz1IeLf.js → chunk-L3NEJ4N5-COfUyKII.js} +1 -1
  526. package/studio/web/assets/chunk-OSK3NFVY-ByciRftO.js +10 -0
  527. package/studio/web/assets/{chunk-P2QGCYS3-DmIFY4d7.js → chunk-P2QGCYS3-CP1VhG_c.js} +1 -1
  528. package/studio/web/assets/{chunk-POPQ4Y6H-BPrvMyKz.js → chunk-POPQ4Y6H-ClWhhkwW.js} +1 -1
  529. package/studio/web/assets/{chunk-PWAF6VOD-2zB6IW9i.js → chunk-PWAF6VOD-1z1THyS5.js} +1 -1
  530. package/studio/web/assets/{chunk-RHFEMEQ7-2FgyI8YU.js → chunk-SHT3W25Y-LpQkMsah.js} +2 -2
  531. package/studio/web/assets/{chunk-SVP7TREG-FwtbH2QC.js → chunk-SVP7TREG-jtdAHw0S.js} +1 -1
  532. package/studio/web/assets/{chunk-LCL6LL3I-HOzK_ppE.js → chunk-TICWLB2K-VOwzetX-.js} +1 -1
  533. package/studio/web/assets/classDiagram-ZZMXUADV-VaEwSy_g.js +1 -0
  534. package/studio/web/assets/classDiagram-v2-VYDZK3BY-VaEwSy_g.js +1 -0
  535. package/studio/web/assets/{createLucideIcon-BKGPfjm2.js → createLucideIcon-CzW9508A.js} +1 -1
  536. package/studio/web/assets/{cssMode-CEN2mzSA.js → cssMode-s0cWI-_M.js} +1 -1
  537. package/studio/web/assets/{cynefin-OW5HDTMX-BRkpLFQV.js → cynefin-OW5HDTMX-BbdbCvub.js} +1 -1
  538. package/studio/web/assets/{cynefinDiagram-5FMLGOSQ-CHT1DaX6.js → cynefinDiagram-5FMLGOSQ-TP-aIqbt.js} +1 -1
  539. package/studio/web/assets/{dagre-3AP2YEHR-DpUXBh63.js → dagre-GXQ25YYZ-DShnGpGo.js} +1 -1
  540. package/studio/web/assets/{diagram-S7CK7UJ4-BuymVFZT.js → diagram-S7CK7UJ4-aoCVTtcy.js} +1 -1
  541. package/studio/web/assets/{diagram-UQ7AKVKN-CyP148RM.js → diagram-UQ7AKVKN-DglXtQ6x.js} +1 -1
  542. package/studio/web/assets/{diagram-VSXAHHWV-CoCAg3M9.js → diagram-VSXAHHWV-fhEdmkwM.js} +1 -1
  543. package/studio/web/assets/{diagram-VX7I27RA-BpOqCFca.js → diagram-VX7I27RA-DccVJet6.js} +1 -1
  544. package/studio/web/assets/{diagram-Z3DM3KII-Bfpw7Vbj.js → diagram-Z3DM3KII-D-RyJJb7.js} +1 -1
  545. package/studio/web/assets/{dialog-CBf0Mr1d.js → dialog-Cn2uWgD4.js} +1 -1
  546. package/studio/web/assets/{dist-lkA3O3eM.js → dist-DP8UjMB_.js} +1 -1
  547. package/studio/web/assets/{download-BtTOBem-.js → download-B5T5r7ss.js} +1 -1
  548. package/studio/web/assets/{ebnfDiagram-PWID7BFC-DS_6aWqL.js → ebnfDiagram-PWID7BFC-DJGpIpz_.js} +1 -1
  549. package/studio/web/assets/{editor-D8oDeCTL.js → editor-DNcRHK54.js} +1 -1
  550. package/studio/web/assets/{erDiagram-SSCWMZ5O-DJNk6Fgw.js → erDiagram-RLTQ6QDP-CIfNlgkC.js} +1 -1
  551. package/studio/web/assets/eventmodeling-NTZA5JFV-CLxnp2CR.js +1 -0
  552. package/studio/web/assets/flowDiagram-HODETNUW-BIbhmz9f.js +1 -0
  553. package/studio/web/assets/{ganttDiagram-EL5Y4UJY-2pOExxMY.js → ganttDiagram-EL5Y4UJY-BxToTzzD.js} +1 -1
  554. package/studio/web/assets/{getAnalytics-D4LKGeVy.js → getAnalytics-GHK8ORfM.js} +1 -1
  555. package/studio/web/assets/{gitGraph-4MIJSDKK-CH5ZxwzF.js → gitGraph-4MIJSDKK-D2s2w8lE.js} +1 -1
  556. package/studio/web/assets/{gitGraphDiagram-WWUBYQGX-DVIsIhbO.js → gitGraphDiagram-WWUBYQGX-Dwntd4-x.js} +1 -1
  557. package/studio/web/assets/{html-u3vOg7LJ.js → html-Bdssedlg.js} +1 -1
  558. package/studio/web/assets/{htmlMode-DyO31v-P.js → htmlMode-CoDlJ3fw.js} +1 -1
  559. package/studio/web/assets/{index-Cxj2_wsl.css → index-7RMEgVG1.css} +1 -1
  560. package/studio/web/assets/index-D6sxmFLR.js +824 -0
  561. package/studio/web/assets/index.lazy-tmU5BS8s.js +2 -0
  562. package/studio/web/assets/{info-A6RAGUB7-CPQfTnaG.js → info-A6RAGUB7-DYjkvb0C.js} +1 -1
  563. package/studio/web/assets/{infoDiagram-RXCK75RN-DlwLYlwm.js → infoDiagram-27XIBGKW-Bnp1FJE5.js} +1 -1
  564. package/studio/web/assets/{ishikawaDiagram-5VMMS53U-BRXRp29U.js → ishikawaDiagram-5VMMS53U-D9Xh2r6X.js} +1 -1
  565. package/studio/web/assets/{javascript-CUvxOyTC.js → javascript-B8meVSTH.js} +1 -1
  566. package/studio/web/assets/{journeyDiagram-EYS64GPL-B0ou8k0n.js → journeyDiagram-3NMN7TZE-CokIi6ll.js} +2 -2
  567. package/studio/web/assets/{jsonMode-f_IwbF3D.js → jsonMode-DpIPd35T.js} +1 -1
  568. package/studio/web/assets/{kanban-definition-3QL26DDD-uYg7iYzp.js → kanban-definition-UXKFOSKX-CukSFJfX.js} +1 -1
  569. package/studio/web/assets/{languageServices-DXtZ6rEF.js → languageServices-C_5FMJzQ.js} +1 -1
  570. package/studio/web/assets/{lspLanguageFeatures-B4pCF1zO.js → lspLanguageFeatures-BIzNBzPK.js} +1 -1
  571. package/studio/web/assets/{mermaid-parser.core-Ck-fC8b7.js → mermaid-parser.core-BlEsOWNO.js} +3 -3
  572. package/studio/web/assets/{mermaid.core-CP8aNNYm.js → mermaid.core-BlkGaMIH.js} +5 -5
  573. package/studio/web/assets/{mindmap-definition-FBJOCRG2-CgTZ-rit.js → mindmap-definition-YA3MSWOX-IprMc_0j.js} +1 -1
  574. package/studio/web/assets/{notifications-D3tIQ4sg.js → notifications-CQf18QKb.js} +1 -1
  575. package/studio/web/assets/notifications-CvZivSbh.js +1 -0
  576. package/studio/web/assets/{packet-AYTQ26CC-DEyoPtPb.js → packet-AYTQ26CC-Bi3V04Zi.js} +1 -1
  577. package/studio/web/assets/{pegDiagram-XKGWAZYB-DrD-7sD9.js → pegDiagram-XKGWAZYB-BNuPDLZY.js} +1 -1
  578. package/studio/web/assets/{pie-WAS4IAKB-wjj-EI1d.js → pie-WAS4IAKB-_6DoDbng.js} +1 -1
  579. package/studio/web/assets/{pieDiagram-E7YTZNPT-GntqDCzv.js → pieDiagram-E7YTZNPT-DqNb6Ht2.js} +1 -1
  580. package/studio/web/assets/{profile-DZWU7MgT.js → profile-DdOwtntb.js} +1 -1
  581. package/studio/web/assets/{quadrantDiagram-AXDQQJYC-0UeqXQGd.js → quadrantDiagram-AXDQQJYC-BGH9E2YR.js} +1 -1
  582. package/studio/web/assets/{radar-RG4KPBEZ-DFSA5h7k.js → radar-RG4KPBEZ-DDdVczcL.js} +1 -1
  583. package/studio/web/assets/{railroad-74A4TZTK-CaOUG9wR.js → railroad-74A4TZTK-BJUP4Jds.js} +1 -1
  584. package/studio/web/assets/railroad-abnf-HS5TGJTU-Bm3L1L0h.js +1 -0
  585. package/studio/web/assets/railroad-ebnf-LZEXJU2U-CKzLGlkw.js +1 -0
  586. package/studio/web/assets/railroad-peg-WCYAUIDC-S8xLjslx.js +1 -0
  587. package/studio/web/assets/{railroadDiagram-O6MQD6OU-yHUELZaV.js → railroadDiagram-O6MQD6OU-DGTPh2KZ.js} +1 -1
  588. package/studio/web/assets/{regions-CkyurXzE.js → regions-n69fwagr.js} +1 -1
  589. package/studio/web/assets/{register-BUyhWjBO.js → register-PfWTCXWB.js} +3 -3
  590. package/studio/web/assets/{requirementDiagram-EFPCY7ZU-DNEGFjuW.js → requirementDiagram-BXWQKSXE-BJnO6uLz.js} +1 -1
  591. package/studio/web/assets/{sankeyDiagram-P5KCCOFB-DpyAmSVR.js → sankeyDiagram-P5KCCOFB-0vSOdymH.js} +1 -1
  592. package/studio/web/assets/{sequenceDiagram-WJ2MYXX4-TyaT7xNk.js → sequenceDiagram-WJ2MYXX4-hETizDWE.js} +1 -1
  593. package/studio/web/assets/{setComponentFile-CeyKSZAa.js → setComponentFile-Bg6O7X0S.js} +1 -1
  594. package/studio/web/assets/{setup-D2kn7cAA.js → setup-CUx_aUDl.js} +2 -2
  595. package/studio/web/assets/{stateDiagram-HBIQ2CUA-CeEdTArZ.js → stateDiagram-D77RDMKH-CdYQ_KtC.js} +1 -1
  596. package/studio/web/assets/stateDiagram-v2-MP3YSRHH-CdKuzQMT.js +1 -0
  597. package/studio/web/assets/status-D7BVKqX9.js +61 -0
  598. package/studio/web/assets/{swimlanes-XN3QIQJK-B54FmF46.js → swimlanes-42K2YHIH-B8cHIpU4.js} +1 -1
  599. package/studio/web/assets/swimlanesDiagram-VR7AAH4N-DmOSJwaH.js +8 -0
  600. package/studio/web/assets/{tabs-B_G5zscN.js → tabs-BrHu7gJi.js} +1 -1
  601. package/studio/web/assets/{timeline-definition-24CTP7MA-D-a9ujbo.js → timeline-definition-24CTP7MA-BJWYSXqF.js} +1 -1
  602. package/studio/web/assets/{toggleHighContrast-C0UW6rI2.js → toggleHighContrast-DBSyXzMr.js} +1 -1
  603. package/studio/web/assets/{treeView-Q6P3EWNA-CrW_6JnS.js → treeView-Q6P3EWNA-qxe_v6CQ.js} +1 -1
  604. package/studio/web/assets/{treemap-WGGIJYW6-BxyYLdP_.js → treemap-WGGIJYW6-dDo97XXF.js} +1 -1
  605. package/studio/web/assets/{tsMode-DBC0zmDx.js → tsMode-BByKCjBS.js} +1 -1
  606. package/studio/web/assets/{typescript-DApRQir3.js → typescript-DDLnLpw9.js} +1 -1
  607. package/studio/web/assets/{useEntityRestURL-DB6JStU1.js → useEntityRestURL-31CHGaHk.js} +1 -1
  608. package/studio/web/assets/{useLocalStorage-Dtj1QS8_.js → useLocalStorage-BqMR3D8_.js} +1 -1
  609. package/studio/web/assets/vendor-core-c2JRRJpV.js +58 -0
  610. package/studio/web/assets/vendor-datadog-CLUcJXOo.js +6 -0
  611. package/studio/web/assets/{vendor-react-Dyj4O3HE.js → vendor-react-CJV_K1u4.js} +1 -1
  612. package/studio/web/assets/vendor-tanstack-DxzraizX.js +1 -0
  613. package/studio/web/assets/{vendor-ui-vhu-UHhF.js → vendor-ui-BUjK0h8a.js} +2 -2
  614. package/studio/web/assets/{vennDiagram-4TSXK5OY-Cy7s7Mpy.js → vennDiagram-4TSXK5OY-A3i-lCdl.js} +1 -1
  615. package/studio/web/assets/{wardley-WFR3VGLG-BeBL35g2.js → wardley-WFR3VGLG-B0ik-_6g.js} +1 -1
  616. package/studio/web/assets/{wardleyDiagram-VM6X3IG4-BylmIGSg.js → wardleyDiagram-VM6X3IG4-CjrkKWUR.js} +1 -1
  617. package/studio/web/assets/{workers-C0bFIedw.js → workers-pR3jRY9D.js} +1 -1
  618. package/studio/web/assets/x-DIzaLEdK.js +1 -0
  619. package/studio/web/assets/{xml-HWd01lU-.js → xml-2iRnMhQO.js} +1 -1
  620. package/studio/web/assets/{xychartDiagram-S5SC5T6Z-CoKALMXr.js → xychartDiagram-S5SC5T6Z-Biok4GYV.js} +1 -1
  621. package/studio/web/assets/{yaml-CIH0Nt-h.js → yaml-Bf92gJpd.js} +1 -1
  622. package/studio/web/index.html +14 -14
  623. package/upgrade/directives/5-3-0.ts +132 -0
  624. package/upgrade/directives/directivesController.ts +2 -1
  625. package/utility/OperationFunctionCaller.ts +2 -1
  626. package/utility/common_utils.ts +30 -5
  627. package/utility/componentNames.ts +12 -0
  628. package/utility/environment/environmentManager.ts +3 -7
  629. package/utility/environment/systemInformation.ts +7 -0
  630. package/utility/errors/commonErrors.ts +4 -0
  631. package/utility/errors/hdbError.ts +29 -0
  632. package/utility/hdbTerms.ts +17 -0
  633. package/utility/logging/harper_logger.ts +87 -14
  634. package/utility/logging/logRotator.ts +72 -45
  635. package/utility/nodeIdentity.ts +45 -0
  636. package/utility/npmUtilities.ts +10 -8
  637. package/utility/operationPermissions.ts +18 -1
  638. package/utility/operation_authorization.ts +231 -42
  639. package/utility/watchPath.ts +63 -0
  640. package/utility/watcherFallback.ts +270 -0
  641. package/validation/configValidator.ts +209 -72
  642. package/validation/installValidator.ts +15 -0
  643. package/validation/validationWrapper.ts +18 -4
  644. package/studio/web/assets/Chat-JpO8EtUu.js +0 -2067
  645. package/studio/web/assets/FloatingChat-Bcj3xSZu.js +0 -23
  646. package/studio/web/assets/applications-ByqLRKyZ.js +0 -296
  647. package/studio/web/assets/architecture-7GRP2DOG-DNdx5tEU.js +0 -1
  648. package/studio/web/assets/authStore-qKmCZcaf.js +0 -3
  649. package/studio/web/assets/channel-DtCV8PTL.js +0 -1
  650. package/studio/web/assets/chunk-R7TYR2AO-Irip67yr.js +0 -10
  651. package/studio/web/assets/classDiagram-DTDB5LWJ-DbO_dCNE.js +0 -1
  652. package/studio/web/assets/classDiagram-v2-JRS7N3AN-DbO_dCNE.js +0 -1
  653. package/studio/web/assets/eventmodeling-NTZA5JFV-5jbe4A5P.js +0 -1
  654. package/studio/web/assets/flowDiagram-A5DVABFB-Dp9Ezlow.js +0 -1
  655. package/studio/web/assets/index-aSt5tY-L.js +0 -824
  656. package/studio/web/assets/index.lazy-B9jiPwT8.js +0 -2
  657. package/studio/web/assets/notifications-CUoYgU98.js +0 -1
  658. package/studio/web/assets/railroad-abnf-HS5TGJTU-Bc0Qi0WH.js +0 -1
  659. package/studio/web/assets/railroad-ebnf-LZEXJU2U-G8rVVZ2C.js +0 -1
  660. package/studio/web/assets/railroad-peg-WCYAUIDC-CrehKBhC.js +0 -1
  661. package/studio/web/assets/stateDiagram-v2-4QOOHH4V-D4tuw9Su.js +0 -1
  662. package/studio/web/assets/status-D7Xn5ePA.js +0 -61
  663. package/studio/web/assets/swimlanesDiagram-VK2B7HYN-XOhmNEvq.js +0 -8
  664. package/studio/web/assets/vendor-core-RCcadM3e.js +0 -73
  665. package/studio/web/assets/vendor-datadog-BRv-mOv1.js +0 -6
  666. package/studio/web/assets/vendor-tanstack-BiFWSB3W.js +0 -1
  667. package/studio/web/assets/x-B9o9hsep.js +0 -1
  668. /package/studio/web/assets/{sizeCapture-X5ZJPWSS-B0uUizjq.js → sizeCapture-INFHLROL-B0uUizjq.js} +0 -0
@@ -1,3 +1,4 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
1
2
  import { ServerError } from '../../utility/errors/hdbError.ts';
2
3
  import type { DefineBackendSpec, GenerateResult, ModelBackend, ModelCapabilities, ToolCall } from './types.ts';
3
4
 
@@ -24,14 +25,95 @@ type ModelKind = 'embedding' | 'generative';
24
25
  const embedding: Map<string, ModelBackend> = new Map();
25
26
  const generative: Map<string, ModelBackend> = new Map();
26
27
 
28
+ /** A registration a factory made during construction, deferred to the caller. */
29
+ export interface CapturedInstall {
30
+ kind: ModelKind;
31
+ logicalName: string;
32
+ backend: ModelBackend;
33
+ }
34
+
35
+ interface CaptureSlot {
36
+ kind: ModelKind;
37
+ logicalName: string;
38
+ backend?: ModelBackend;
39
+ /** Deferred with the primary, so no request observes a new helper next to an old primary. */
40
+ extras: CapturedInstall[];
41
+ /** Async work spawned by a factory retains the ALS context past construction; once construction
42
+ * ends the scope deactivates so a late same-slot registration installs normally. */
43
+ active: boolean;
44
+ }
45
+
46
+ // Async-context scoped: a module-global slot would divert unrelated registrations and collide
47
+ // concurrent constructions.
48
+ const captureScope = new AsyncLocalStorage<CaptureSlot>();
49
+
50
+ function install(kind: ModelKind, logicalName: string, backend: ModelBackend): void {
51
+ const slot = captureScope.getStore();
52
+ if (slot?.active) {
53
+ if (slot.kind === kind && slot.logicalName === logicalName) slot.backend = backend;
54
+ else slot.extras.push({ kind, logicalName, backend });
55
+ return;
56
+ }
57
+ (kind === 'embedding' ? embedding : generative).set(logicalName, backend);
58
+ }
59
+
27
60
  /** Map `logicalName` to a backend for embedding calls. Re-set replaces. */
28
61
  export function setEmbedding(logicalName: string, backend: ModelBackend): void {
29
- embedding.set(logicalName, backend);
62
+ install('embedding', logicalName, backend);
30
63
  }
31
64
 
32
65
  /** Map `logicalName` to a backend for generative calls. Re-set replaces. */
33
66
  export function setGenerative(logicalName: string, backend: ModelBackend): void {
34
- generative.set(logicalName, backend);
67
+ install('generative', logicalName, backend);
68
+ }
69
+
70
+ /**
71
+ * Build a backend through its normal registration path but return it instead of installing it, so a
72
+ * config reload can install it conditionally. A scratch logical name would be briefly visible
73
+ * through `listBackends`, which backs the public `GET /v1/models`.
74
+ */
75
+ export async function constructBackend(
76
+ kind: ModelKind,
77
+ logicalName: string,
78
+ register: () => void | Promise<void>
79
+ ): Promise<{ backend?: ModelBackend; extras: CapturedInstall[] }> {
80
+ const slot: CaptureSlot = { kind, logicalName, extras: [], active: true };
81
+ try {
82
+ await captureScope.run(slot, async () => {
83
+ await register();
84
+ });
85
+ } finally {
86
+ slot.active = false;
87
+ }
88
+ return { backend: slot.backend, extras: slot.extras };
89
+ }
90
+
91
+ /**
92
+ * Replace `logicalName`'s backend for `kind` only if it is still `expected`. A plain `set` is atomic
93
+ * but unconditional, so concurrent writers resolve by arrival order rather than by which value is
94
+ * newer. A caller that loses the swap must re-derive from current state rather than overwrite.
95
+ */
96
+ export function replaceIfCurrent(
97
+ kind: ModelKind,
98
+ logicalName: string,
99
+ expected: ModelBackend | undefined,
100
+ next: ModelBackend
101
+ ): boolean {
102
+ const map = kind === 'embedding' ? embedding : generative;
103
+ if (map.get(logicalName) !== expected) return false;
104
+ map.set(logicalName, next);
105
+ return true;
106
+ }
107
+
108
+ /**
109
+ * Remove `logicalName`'s backend for `kind` only if it is still `expected`, returning whether it was
110
+ * removed. Withdrawing a credential must not delete a slot another writer has since taken over.
111
+ */
112
+ export function removeIfCurrent(kind: ModelKind, logicalName: string, expected: ModelBackend | undefined): boolean {
113
+ const map = kind === 'embedding' ? embedding : generative;
114
+ if (map.get(logicalName) !== expected) return false;
115
+ map.delete(logicalName);
116
+ return true;
35
117
  }
36
118
 
37
119
  /** Non-throwing lookup of the backend mapped to `logicalName` for `kind`, or `undefined`. Used by the router to assemble + filter candidate lists without exceptions. */
@@ -1,5 +1,8 @@
1
1
  /**
2
- * YAML→registry boot bridge (#629 / #630 of #510).
2
+ * YAML→registry boot bridge (#629 / #630 of #510), plus hot reload of the
3
+ * `models` block when the root config file changes (#2344) — so an
4
+ * orchestrator can rotate a credential or re-point a baseUrl by rewriting
5
+ * harperdb-config.yaml, without a process restart.
3
6
  *
4
7
  * Reads the top-level `models` block from the root config and dispatches each
5
8
  * `models.embedding.<name>` / `models.generative.<name>` entry to the matching
@@ -22,7 +25,8 @@
22
25
  * convention from `@harperfast/oauth`'s config loader.
23
26
  *
24
27
  * Errors per entry are logged and skipped, not thrown — one misconfigured
25
- * backend should not block Harper boot.
28
+ * backend should not block Harper boot, and one bad entry in a rewritten file
29
+ * should not tear down the entries that were fine.
26
30
  */
27
31
  import harperLogger from '../../utility/logging/harper_logger.ts';
28
32
  import { expandEnvVarsDeep, isUnresolvedEnvVarPlaceholder } from '../../utility/expandEnvVar.ts';
@@ -35,6 +39,16 @@ import { pathToFileURL } from 'node:url';
35
39
  import { createRequire } from 'node:module';
36
40
  import { getHdbBasePath } from '../../utility/environment/environmentManager.ts';
37
41
  import { setFallbackGroup, clearFallbackGroups } from './routing.ts';
42
+ import {
43
+ constructBackend,
44
+ getBackend,
45
+ removeIfCurrent,
46
+ replaceIfCurrent,
47
+ type CapturedInstall,
48
+ } from './backendRegistry.ts';
49
+ import { getSharedRootConfigWatcher, RootConfigWatcher } from '../../config/RootConfigWatcher.ts';
50
+ import { validateModelsBlock } from '../../validation/configValidator.ts';
51
+ import type { ModelBackend } from './types.ts';
38
52
 
39
53
  /**
40
54
  * Field names treated as credentials. When present in config as a literal
@@ -79,36 +93,149 @@ const FACTORIES: Record<string, BackendRegisterFn> = {
79
93
  bedrock: (args) => registerBedrockBackend({ ...args, config: args.config as BedrockBackendConfig }),
80
94
  };
81
95
 
96
+ // What the config projection currently has installed, per kind+logicalName slot. `backend` is the
97
+ // exact instance this module put in the registry: reload swaps compare against it, so a
98
+ // programmatic `registerBackend` that overrode a config entry keeps its documented precedence, and
99
+ // removal can never delete a slot another writer has since taken over.
100
+ interface InstalledSlot {
101
+ kind: ModelKind;
102
+ logicalName: string;
103
+ /** The instance this projection installed; absent while an application override owns the slot. */
104
+ backend?: ModelBackend;
105
+ /** Raw entry as applied, for change detection — an unchanged entry is not reconstructed. */
106
+ entryJson: string;
107
+ /** The entry's fallback group as applied, so a retained backend keeps its routing. */
108
+ fallback?: string[];
109
+ /** Whether the entry's backend is a built-in. Module-backed entries are restart-managed: reload
110
+ * refuses to add, change, OR remove them, so a rename cannot half-apply as a bare removal. */
111
+ builtin?: boolean;
112
+ /** Helper registrations the entry's factory made, installed and removed with the entry.
113
+ * `suppressed`: a config entry claimed this helper's name; the record is kept so the helper is
114
+ * restored when that entry is removed — matching a restart with the final config. */
115
+ extras?: Array<CapturedInstall & { suppressed?: boolean }>;
116
+ }
117
+
118
+ const installedSlots = new Map<string, InstalledSlot>();
119
+
120
+ /**
121
+ * Let a config entry claim a name held by a projection-installed helper. The record is suppressed
122
+ * rather than deleted, so removing the claiming entry later restores the helper — the live
123
+ * registry then matches a restart with the same final config.
124
+ */
125
+ function claimHelperOccupant(kind: ModelKind, logicalName: string): ModelBackend | undefined {
126
+ for (const slot of installedSlots.values()) {
127
+ const extra = slot.extras?.find((e) => !e.suppressed && e.kind === kind && e.logicalName === logicalName);
128
+ if (extra) {
129
+ extra.suppressed = true;
130
+ return extra.backend;
131
+ }
132
+ }
133
+ return undefined;
134
+ }
135
+
136
+ /** Restore a suppressed helper once the entry that claimed its name is removed. */
137
+ function restoreSuppressedHelper(kind: ModelKind, logicalName: string): void {
138
+ for (const slot of installedSlots.values()) {
139
+ const extra = slot.extras?.find((e) => e.suppressed && e.kind === kind && e.logicalName === logicalName);
140
+ if (extra && replaceIfCurrent(extra.kind, extra.logicalName, undefined, extra.backend)) {
141
+ extra.suppressed = false;
142
+ return;
143
+ }
144
+ }
145
+ }
146
+
147
+ const slotKey = (kind: ModelKind, logicalName: string) => `${kind} ${logicalName}`;
148
+
82
149
  /**
83
150
  * Populate the model registry from `rootConfig.models`. No-op if the block
84
151
  * is absent or empty. Idempotent within a process: each entry overwrites any
85
- * prior registration under the same logical name (registry uses `.set()`).
152
+ * prior registration under the same logical name.
86
153
  */
87
154
  export async function bootstrapModels(rootConfig: RootConfig | undefined | null): Promise<void> {
88
- // Rebuild fallback groups from scratch each (re)load so a removed/changed `fallback:`
89
- // (or a removed `models:` block) doesn't leave stale routing behind (#1326).
90
- clearFallbackGroups();
91
- const block = rootConfig?.models;
92
- if (!block) return;
93
- await registerKind('embedding', block.embedding);
94
- await registerKind('generative', block.generative);
155
+ // The projection is NOT reset here: boot rides the same serialized queue as a reload, so a
156
+ // re-bootstrap in a long-lived process removes entries the new config dropped, keeps retained
157
+ // state (a malformed entry's routing), and cannot corrupt an in-flight apply's swaps.
158
+ return queueModelsApply(rootConfig?.models, true);
95
159
  }
96
160
 
97
- function warnOnLiteralCredentials(kind: ModelKind, logicalName: string, entry: ModelEntry): void {
98
- for (const field of CREDENTIAL_FIELDS) {
99
- const value = (entry as Record<string, unknown>)[field];
100
- if (typeof value !== 'string' || value.length === 0) continue;
101
- if (isUnresolvedEnvVarPlaceholder(value)) continue; // operator is using ${VAR} indirection
102
- harperLogger.warn(
103
- `models.${kind}.${logicalName}: '${field}' is a literal value in harperdb-config.yaml; ` +
104
- `prefer \${ENV_VAR} indirection for credentials to keep them off disk`
105
- );
161
+ /** Forget everything the projection installed. Test isolation only — never part of a reload. */
162
+ export function resetModelsProjection(): void {
163
+ installedSlots.clear();
164
+ }
165
+
166
+ /**
167
+ * Apply a `models:` block as a hot reload: changed entries are rebuilt through the same factories
168
+ * boot uses and swapped in atomically, removed entries stop serving, and programmatic
169
+ * registrations that overrode a config entry are left in place. Serialized and coalesced —
170
+ * concurrent calls settle on the latest block.
171
+ */
172
+ export function applyModelsConfig(models: ModelsConfig | undefined): Promise<void> {
173
+ return queueModelsApply(models, false);
174
+ }
175
+
176
+ // Interleaved applies could install an older credential last; serialized + coalesced, they cannot.
177
+ // Boot and reload coalesce SEPARATELY: merging them either loses boot's overwrite contract or
178
+ // launders a raw watcher block through boot semantics, past reload validation and the missing-key
179
+ // no-op. Boot drains first; the newest reload then refines it under its own rules.
180
+ let pendingBoot: { block: ModelsConfig | undefined } | undefined;
181
+ let pendingReload: { block: ModelsConfig | null | undefined } | undefined;
182
+ let applyChain: Promise<void> | undefined;
183
+
184
+ function queueModelsApply(block: ModelsConfig | null | undefined, isBoot: boolean): Promise<void> {
185
+ if (isBoot) {
186
+ pendingBoot = { block: block ?? undefined };
187
+ // A boot supersedes any reload queued before it — draining that older snapshot after the
188
+ // newer boot would refine it backwards. A reload queued after the boot still refines. The
189
+ // same applies one layer down: a watcher snapshot OBSERVED before this boot whose settle
190
+ // timer has not fired yet is also pre-boot content — boot read the same file, so dropping
191
+ // the timer loses nothing newer.
192
+ pendingReload = undefined;
193
+ clearTimeout(pendingSettle);
194
+ pendingSettle = undefined;
195
+ } else {
196
+ pendingReload = { block };
106
197
  }
198
+ applyChain ??= (async () => {
199
+ try {
200
+ while (pendingBoot || pendingReload) {
201
+ const isBootTurn = pendingBoot !== undefined;
202
+ const next = isBootTurn ? pendingBoot! : pendingReload!;
203
+ if (isBootTurn) pendingBoot = undefined;
204
+ else pendingReload = undefined;
205
+ try {
206
+ await applyModels(next.block, isBootTurn);
207
+ } catch (err) {
208
+ // Per-entry failures are handled inside applyModels; this catches a failure of the apply
209
+ // itself. The chain must not reject — the watcher calls fire-and-forget, so a rejection
210
+ // would be unhandled — and the loop continues so a newer pending snapshot still applies.
211
+ harperLogger.error(`models: config apply failed (${(err as Error)?.message ?? err})`);
212
+ }
213
+ }
214
+ } finally {
215
+ applyChain = undefined;
216
+ }
217
+ })();
218
+ return applyChain;
107
219
  }
108
220
 
109
- async function registerKind(kind: ModelKind, entries: Record<string, ModelEntry> | undefined): Promise<void> {
221
+ interface DesiredEntry {
222
+ kind: ModelKind;
223
+ logicalName: string;
224
+ entry: ModelEntry;
225
+ entryJson: string;
226
+ }
227
+
228
+ function collectKind(
229
+ kind: ModelKind,
230
+ entries: Record<string, ModelEntry> | undefined,
231
+ out: DesiredEntry[],
232
+ present: Set<string>
233
+ ): void {
110
234
  if (!entries) return;
111
235
  for (const [logicalName, entry] of Object.entries(entries)) {
236
+ // Present even when invalid: a malformed entry keeps its previously applied backend (like a
237
+ // failed rebuild does) rather than reading as removed. Only true absence removes.
238
+ present.add(slotKey(kind, logicalName));
112
239
  if (!entry || typeof entry !== 'object') {
113
240
  // Schema validation (configValidator.ts) catches this before bootstrap
114
241
  // runs, so reaching here means config was loaded by an unusual path
@@ -120,6 +247,125 @@ async function registerKind(kind: ModelKind, entries: Record<string, ModelEntry>
120
247
  harperLogger.error(`models.${kind}.${logicalName}: 'backend' must be a non-empty string; skipping`);
121
248
  continue;
122
249
  }
250
+ out.push({ kind, logicalName, entry, entryJson: JSON.stringify(entry) });
251
+ }
252
+ }
253
+
254
+ function publishEntry(
255
+ desiredEntry: DesiredEntry,
256
+ backend: ModelBackend,
257
+ extras: CapturedInstall[],
258
+ isBoot: boolean
259
+ ): void {
260
+ const { kind, logicalName, entry, entryJson } = desiredEntry;
261
+ const key = slotKey(kind, logicalName);
262
+ // Boot overwrites occupants (the documented contract); a reload replaces only what this
263
+ // projection installed — or a helper the projection installed under this name, which a config
264
+ // entry outranks — so genuine application overrides survive.
265
+ const previous = installedSlots.get(key);
266
+ let expected = isBoot ? getBackend(kind, logicalName) : previous?.backend;
267
+ // Claimed at boot too, or the parent record keeps an installable claim on a name it lost.
268
+ const claimedHelper = claimHelperOccupant(kind, logicalName);
269
+ if (!isBoot && expected === undefined && claimedHelper !== undefined) expected = claimedHelper;
270
+ // Helpers rotate and retire with their entry even when the primary swap is lost to an
271
+ // override — a frozen helper would keep serving a revoked credential.
272
+ const installedExtras: Array<CapturedInstall & { suppressed?: boolean }> = [];
273
+ for (const extra of extras) {
274
+ const extraExpected = isBoot
275
+ ? getBackend(extra.kind, extra.logicalName)
276
+ : previous?.extras?.find((e) => e.kind === extra.kind && e.logicalName === extra.logicalName)?.backend;
277
+ if (replaceIfCurrent(extra.kind, extra.logicalName, extraExpected, extra.backend)) {
278
+ installedExtras.push(extra);
279
+ } else {
280
+ harperLogger.warn(
281
+ `models.${kind}.${logicalName}: helper '${extra.logicalName}' is owned by another registration; leaving it in place`
282
+ );
283
+ }
284
+ }
285
+ for (const old of previous?.extras ?? []) {
286
+ if (old.suppressed) continue;
287
+ if (!extras.some((e) => e.kind === old.kind && e.logicalName === old.logicalName)) {
288
+ removeIfCurrent(old.kind, old.logicalName, old.backend);
289
+ }
290
+ }
291
+ const builtin = Boolean(FACTORIES[entry.backend as string]);
292
+ if (replaceIfCurrent(kind, logicalName, expected, backend)) {
293
+ installedSlots.set(key, {
294
+ kind,
295
+ logicalName,
296
+ backend,
297
+ entryJson,
298
+ builtin,
299
+ fallback: entry.fallback,
300
+ extras: installedExtras,
301
+ });
302
+ } else {
303
+ // Record the ask with no installed instance, so unchanged reloads skip instead of
304
+ // re-losing this swap every apply; installed helpers stay recorded and removable.
305
+ installedSlots.set(key, {
306
+ kind,
307
+ logicalName,
308
+ entryJson,
309
+ builtin,
310
+ fallback: entry.fallback,
311
+ extras: installedExtras,
312
+ });
313
+ harperLogger.warn(`models.${kind}.${logicalName}: another registration owns this entry; leaving it in place`);
314
+ }
315
+ }
316
+
317
+ async function applyModels(block: ModelsConfig | null | undefined, isBoot: boolean): Promise<void> {
318
+ if (!isBoot) {
319
+ if (block === undefined) {
320
+ // A snapshot with no `models` key is not evidence of intent: a non-atomic in-place rewrite
321
+ // can be observed as a valid YAML prefix that simply hasn't reached the block yet, and
322
+ // removing every backend on that would be catastrophic. Removal is expressed by an empty
323
+ // or shrunken block — `models: {}`. A bare `models:` key (null) is rejected by validation
324
+ // below, exactly as boot's validator rejects it, so reload cannot accept a file a restart
325
+ // would refuse.
326
+ harperLogger.debug?.('models: watched config has no models block; projection left as-is');
327
+ return;
328
+ }
329
+ // Boot validates the composed config (configValidator); a reload must enforce the same
330
+ // schema, or a typo boot would reject hot-applies silently (e.g. a misspelled baseUrl
331
+ // falling back to the public endpoint).
332
+ const { error } = validateModelsBlock(block);
333
+ if (error) {
334
+ harperLogger.error(`models: rejecting config reload (${error.message}); keeping the previous projection`);
335
+ return;
336
+ }
337
+ }
338
+ const desired: DesiredEntry[] = [];
339
+ const presentKeys = new Set<string>();
340
+ collectKind('embedding', block?.embedding, desired, presentKeys);
341
+ collectKind('generative', block?.generative, desired, presentKeys);
342
+
343
+ const staged = new Map<string, { desiredEntry: DesiredEntry; backend: ModelBackend; extras: CapturedInstall[] }>();
344
+ const failedKeys = new Set<string>();
345
+ for (const desiredEntry of desired) {
346
+ const { kind, logicalName, entry, entryJson } = desiredEntry;
347
+ const key = slotKey(kind, logicalName);
348
+ const slot = installedSlots.get(key);
349
+ // Unchanged: skip while ANY occupant serves (rebuilding under an override would run the factory
350
+ // only to lose the swap). Boot is stricter — it must overwrite occupants, so it only skips when
351
+ // the projection's own instance is installed; an emptied registry rebuilds either way.
352
+ const installed = getBackend(kind, logicalName);
353
+ if (slot && slot.entryJson === entryJson && (isBoot ? installed === slot.backend : installed !== undefined))
354
+ continue;
355
+ // Reload runs factories for built-ins only: they are independent, pure constructors. A module
356
+ // factory may compose with other entries (wrap an earlier backend), which staged construction
357
+ // cannot honor — changing one needs a restart, exactly as before this feature. The guard covers
358
+ // the incoming backend AND a currently-installed module-backed slot: a module→built-in rewrite
359
+ // is still a change of a restart-managed entry, so it must not live-replace the module (which
360
+ // would drop its helpers with none of the disposal a restart performs).
361
+ if (!isBoot && (!FACTORIES[entry.backend as string] || slot?.builtin === false)) {
362
+ harperLogger.warn(
363
+ `models.${kind}.${logicalName}: module-backed entries require a restart to add or change; ` +
364
+ `keeping the previous projection for this entry`
365
+ );
366
+ failedKeys.add(key);
367
+ continue;
368
+ }
123
369
  // Warn before expansion: literal credentials in `harperdb-config.yaml`
124
370
  // land on disk, in backups, and (depending on deployment) in replicated
125
371
  // config tables. The `${VAR}` indirection pattern from
@@ -132,19 +378,218 @@ async function registerKind(kind: ModelKind, entries: Record<string, ModelEntry>
132
378
  // (env var unset) pass through unchanged — backend's required-field
133
379
  // validation catches them with a meaningful error.
134
380
  const config = expandEnvVarsDeep(entry);
135
- const builtin = FACTORIES[entry.backend];
136
- if (builtin) {
137
- await builtin({ logicalName, kind, config });
138
- } else {
139
- // Not a built-in name: treat `backend` as a module specifier (#1471).
140
- await registerFromModule(kind, logicalName, entry.backend, config);
381
+ const { backend, extras } = await constructBackend(kind, logicalName, async () => {
382
+ const builtin = FACTORIES[entry.backend as string];
383
+ if (builtin) {
384
+ await builtin({ logicalName, kind, config });
385
+ } else {
386
+ // Not a built-in name: treat `backend` as a module specifier (#1471).
387
+ await registerFromModule(kind, logicalName, entry.backend as string, config);
388
+ }
389
+ });
390
+ if (!backend) {
391
+ harperLogger.error(
392
+ `models.${kind}.${logicalName}: registration installed no backend; skipping ` +
393
+ `(a factory must register before its returned promise resolves)`
394
+ );
395
+ failedKeys.add(key);
396
+ continue;
141
397
  }
142
- // Record the ordered fallback group (other logical names) for the router (#1326).
143
- if (entry.fallback?.length) setFallbackGroup(kind, logicalName, entry.fallback);
398
+ // Boot publishes each entry as it is built, in config order, so a later module factory
399
+ // observes earlier entries exactly as it always has (a wrapper resolves its base). Reload
400
+ // defers everything to one synchronous publish, so a request never sees a partial rebuild.
401
+ if (isBoot) publishEntry(desiredEntry, backend, extras, true);
402
+ else staged.set(key, { desiredEntry, backend, extras });
144
403
  } catch (err) {
404
+ failedKeys.add(key);
145
405
  harperLogger.error(`models.${kind}.${logicalName}: registration failed (${(err as Error)?.message ?? err})`);
146
406
  }
147
407
  }
408
+
409
+ for (const { desiredEntry, backend, extras } of staged.values()) {
410
+ publishEntry(desiredEntry, backend, extras, isBoot);
411
+ }
412
+ const desiredKeys = new Set(desired.map((d) => slotKey(d.kind, d.logicalName)));
413
+ // Module-backed slots retained across a removal are absent from both `desiredKeys` and `presentKeys`,
414
+ // so neither routing loop below would restore them after the clear; track them so their recorded
415
+ // fallback survives — else the primary keeps serving while its failover is silently dropped.
416
+ const retainedModuleKeys = new Set<string>();
417
+ for (const [key, slot] of [...installedSlots]) {
418
+ if (presentKeys.has(key)) continue;
419
+ // Module-backed entries are restart-managed on reload in BOTH directions: refusing an added
420
+ // rename target while removing its old name would turn the rename into a bare removal.
421
+ if (!isBoot && slot.builtin === false) {
422
+ harperLogger.warn(
423
+ `models.${slot.kind}.${slot.logicalName}: module-backed entries require a restart to remove; keeping it`
424
+ );
425
+ retainedModuleKeys.add(key);
426
+ continue;
427
+ }
428
+ if (slot.backend) removeIfCurrent(slot.kind, slot.logicalName, slot.backend);
429
+ for (const extra of slot.extras ?? []) {
430
+ if (!extra.suppressed) removeIfCurrent(extra.kind, extra.logicalName, extra.backend);
431
+ }
432
+ installedSlots.delete(key);
433
+ // A removed entry may have been shadowing a factory helper of the same name; put the
434
+ // helper back, so the live registry matches a restart with this final config. Not gated on
435
+ // slot.backend: the claim suppressed the helper before this entry's swap was known to win, so
436
+ // a lost swap must still release it (a no-op while the name is held or nothing is suppressed).
437
+ restoreSuppressedHelper(slot.kind, slot.logicalName);
438
+ }
439
+ // Rebuild fallback routing from scratch each apply so a removed/changed `fallback:` (or a
440
+ // removed `models:` block) doesn't leave stale routing behind (#1326).
441
+ clearFallbackGroups();
442
+ for (const { kind, logicalName, entry } of desired) {
443
+ // A failed rebuild keeps its previous backend serving, so it keeps the routing that was
444
+ // applied WITH that backend — not the new entry's group, which belongs to the build that
445
+ // did not happen.
446
+ const key = slotKey(kind, logicalName);
447
+ const group = failedKeys.has(key) ? installedSlots.get(key)?.fallback : entry.fallback;
448
+ if (group?.length && getBackend(kind, logicalName)) setFallbackGroup(kind, logicalName, group);
449
+ }
450
+ // Routing follows the name, not the instance.
451
+ for (const [key, slot] of installedSlots) {
452
+ if (desiredKeys.has(key) || !presentKeys.has(key)) continue;
453
+ if (slot.fallback?.length && getBackend(slot.kind, slot.logicalName)) {
454
+ setFallbackGroup(slot.kind, slot.logicalName, slot.fallback);
455
+ }
456
+ }
457
+ // Retained module-backed slots keep serving under their old name, so they keep the fallback group
458
+ // they were built with — a restart-managed removal must not half-apply as a silent failover loss.
459
+ for (const key of retainedModuleKeys) {
460
+ const slot = installedSlots.get(key);
461
+ if (slot?.fallback?.length && getBackend(slot.kind, slot.logicalName)) {
462
+ setFallbackGroup(slot.kind, slot.logicalName, slot.fallback);
463
+ }
464
+ }
465
+ }
466
+
467
+ // ── Hot reload wiring ─────────────────────────────────────────────────────────
468
+
469
+ let modelsConfigWatcher: RootConfigWatcher | undefined;
470
+ let ownsModelsConfigWatcher = false;
471
+ let modelsApplyListener: ((config: unknown) => void) | undefined;
472
+ let pendingSettle: NodeJS.Timeout | undefined;
473
+
474
+ /**
475
+ * Watch the root config file and hot-apply `models:` changes. Follows `harper_logger`'s
476
+ * root-config-watch pattern: one watcher per worker, each worker reprojecting its own registry.
477
+ *
478
+ * The watcher sees the FILE, but `HARPER_DEFAULT_CONFIG` / `HARPER_CONFIG` / `HARPER_SET_CONFIG`
479
+ * compose with it at boot — so if any of those names `models`, the file alone is not authoritative
480
+ * for the block and hot reload stays off, preserving boot semantics unchanged. (That is also the
481
+ * compatibility gate: an orchestrator still injecting models through `HARPER_SET_CONFIG` gets
482
+ * today's restart behavior; one that writes the file instead gets live reload.)
483
+ *
484
+ * Returns whether the watch is active.
485
+ */
486
+ export function startModelsConfigHotReload(options?: {
487
+ configFilePath?: string;
488
+ debounceMs?: number;
489
+ /** Test seam: invoked when a watcher snapshot is observed, before its settle timer is armed. */
490
+ onSnapshotObserved?: () => void;
491
+ /** Test seam: subscribe to this instance (caller-owned) instead of constructing or sharing. */
492
+ watcher?: RootConfigWatcher;
493
+ }): boolean {
494
+ if (modelsConfigWatcher) return true;
495
+ const pinnedBy = envLayerNamingModels();
496
+ if (pinnedBy) {
497
+ harperLogger.info(
498
+ `models: hot reload of the config file is disabled: ${pinnedBy} also defines 'models', so the file alone is not authoritative for it`
499
+ );
500
+ return false;
501
+ }
502
+ // One watcher per isolate: logging already opens one, and a second per worker doubles the
503
+ // native-watcher/FD footprint and the read+parse work on every config write. A test-supplied
504
+ // path gets a private instance, owned (and closed) by this module.
505
+ ownsModelsConfigWatcher = options?.watcher === undefined && options?.configFilePath !== undefined;
506
+ modelsConfigWatcher =
507
+ options?.watcher ??
508
+ (ownsModelsConfigWatcher ? new RootConfigWatcher(options?.configFilePath) : getSharedRootConfigWatcher());
509
+ // An 'error' event with no listener would take the worker down; and `ready` is an events.once
510
+ // promise that rejects on a pre-ready 'error', so it must be observed too.
511
+ modelsConfigWatcher.on('error', modelsWatcherErrorListener);
512
+ modelsConfigWatcher.ready.catch(() => {});
513
+ // 'ready' carries the file state at watch start: a rewrite that lands during the watcher's
514
+ // initial scan arrives there rather than as 'change', and an unchanged block is a no-op anyway.
515
+ // Settle window: a non-atomic in-place rewrite emits an event per write() and an early snapshot
516
+ // can be a schema-valid subset of the final file (a truncated map removes the unwritten
517
+ // entries). Applying only the last event in a quiet window adopts the completed file. The real
518
+ // contract for orchestrators remains an atomic tmp+rename.
519
+ const debounceMs = options?.debounceMs ?? 150;
520
+ const applyFromFile = (config: unknown) => {
521
+ const models = (config as RootConfig | undefined)?.models;
522
+ options?.onSnapshotObserved?.();
523
+ clearTimeout(pendingSettle);
524
+ pendingSettle = setTimeout(() => {
525
+ void queueModelsApply(models, false);
526
+ }, debounceMs);
527
+ pendingSettle.unref?.();
528
+ };
529
+ modelsConfigWatcher.on('ready', applyFromFile);
530
+ modelsConfigWatcher.on('change', applyFromFile);
531
+ modelsApplyListener = applyFromFile;
532
+ // The shared watcher's one-time 'ready' may predate this subscription (logging usually
533
+ // constructs the singleton first, and EventEmitter does not replay). A snapshot it already
534
+ // holds is applied directly, so a rewrite landing before this subscription is not invisible
535
+ // until the next write.
536
+ if (modelsConfigWatcher.config !== undefined) applyFromFile(modelsConfigWatcher.config);
537
+ return true;
538
+ }
539
+
540
+ /** Stop watching the config file. The current projection keeps serving. */
541
+ export function stopModelsConfigHotReload(): void {
542
+ clearTimeout(pendingSettle);
543
+ pendingSettle = undefined;
544
+ if (modelsConfigWatcher) {
545
+ if (modelsApplyListener) {
546
+ modelsConfigWatcher.off('ready', modelsApplyListener);
547
+ modelsConfigWatcher.off('change', modelsApplyListener);
548
+ }
549
+ modelsConfigWatcher.off('error', modelsWatcherErrorListener);
550
+ // The shared watcher belongs to the isolate (logging still consumes it); close only a
551
+ // private, test-supplied instance.
552
+ if (ownsModelsConfigWatcher) modelsConfigWatcher.close();
553
+ }
554
+ modelsApplyListener = undefined;
555
+ modelsConfigWatcher = undefined;
556
+ }
557
+
558
+ function modelsWatcherErrorListener(error: unknown): void {
559
+ harperLogger.warn(`models: config watcher error: ${(error as Error)?.message ?? error}`);
560
+ }
561
+
562
+ function envLayerNamingModels(): string | undefined {
563
+ for (const name of ['HARPER_SET_CONFIG', 'HARPER_CONFIG', 'HARPER_DEFAULT_CONFIG']) {
564
+ const raw = process.env[name];
565
+ if (!raw) continue;
566
+ try {
567
+ const parsed = JSON.parse(raw);
568
+ // Dotted top-level keys ("models.embedding.default") compose into the models block too
569
+ // (harperConfigEnvVars flattens/expands them), so they pin exactly like a nested key.
570
+ if (
571
+ parsed &&
572
+ typeof parsed === 'object' &&
573
+ Object.keys(parsed).some((k) => k === 'models' || k.startsWith('models.'))
574
+ )
575
+ return name;
576
+ } catch {
577
+ // Malformed env config is reported by config loading itself; not this watcher's job.
578
+ }
579
+ }
580
+ return undefined;
581
+ }
582
+
583
+ function warnOnLiteralCredentials(kind: ModelKind, logicalName: string, entry: ModelEntry): void {
584
+ for (const field of CREDENTIAL_FIELDS) {
585
+ const value = (entry as Record<string, unknown>)[field];
586
+ if (typeof value !== 'string' || value.length === 0) continue;
587
+ if (isUnresolvedEnvVarPlaceholder(value)) continue; // operator is using ${VAR} indirection
588
+ harperLogger.warn(
589
+ `models.${kind}.${logicalName}: '${field}' is a literal value in harperdb-config.yaml; ` +
590
+ `prefer \${ENV_VAR} indirection for credentials to keep them off disk`
591
+ );
592
+ }
148
593
  }
149
594
 
150
595
  /**