@noopolis/daimon 0.1.2 → 0.2.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 (422) hide show
  1. package/README.md +275 -51
  2. package/dist/contracts/attentionContract.d.ts +142 -0
  3. package/dist/contracts/attentionContract.d.ts.map +1 -0
  4. package/dist/contracts/attentionContract.js +21 -0
  5. package/dist/contracts/canonicalJson.d.ts +3 -0
  6. package/dist/contracts/canonicalJson.d.ts.map +1 -0
  7. package/dist/contracts/canonicalJson.js +54 -0
  8. package/dist/contracts/grokBrokerTaskClock.d.ts +18 -0
  9. package/dist/contracts/grokBrokerTaskClock.d.ts.map +1 -0
  10. package/dist/contracts/grokBrokerTaskClock.js +16 -0
  11. package/dist/contracts/grokWorkerContract.d.ts +74 -0
  12. package/dist/contracts/grokWorkerContract.d.ts.map +1 -0
  13. package/dist/contracts/grokWorkerContract.js +88 -0
  14. package/dist/contracts/organizationRuntimeContract.d.ts +841 -0
  15. package/dist/contracts/organizationRuntimeContract.d.ts.map +1 -0
  16. package/dist/contracts/organizationRuntimeContract.js +123 -0
  17. package/dist/contracts/runtimeContractManifest.d.ts +1822 -0
  18. package/dist/contracts/runtimeContractManifest.d.ts.map +1 -0
  19. package/dist/contracts/runtimeContractManifest.js +206 -0
  20. package/dist/contracts/shellEnvironmentPolicy.d.ts +3 -0
  21. package/dist/contracts/shellEnvironmentPolicy.d.ts.map +1 -0
  22. package/dist/contracts/shellEnvironmentPolicy.js +5 -0
  23. package/dist/contracts/wakeMomentContract.d.ts +61 -0
  24. package/dist/contracts/wakeMomentContract.d.ts.map +1 -0
  25. package/dist/contracts/wakeMomentContract.js +27 -0
  26. package/dist/core/credentialRedaction.d.ts +4 -0
  27. package/dist/core/credentialRedaction.d.ts.map +1 -0
  28. package/dist/core/credentialRedaction.js +28 -0
  29. package/dist/core/types.d.ts +2 -0
  30. package/dist/core/types.d.ts.map +1 -1
  31. package/dist/examples/jungianPlayAgent.d.ts +1 -0
  32. package/dist/examples/jungianPlayAgent.d.ts.map +1 -1
  33. package/dist/examples/jungianPlayAgent.js +6 -2
  34. package/dist/mcp/toolServer.d.ts +19 -2
  35. package/dist/mcp/toolServer.d.ts.map +1 -1
  36. package/dist/mcp/toolServer.js +57 -17
  37. package/dist/observability/causalEvents.d.ts +6 -6
  38. package/dist/observability/causalEvents.d.ts.map +1 -1
  39. package/dist/observability/causalEvents.js +107 -19
  40. package/dist/observability/orgObserver.d.ts.map +1 -1
  41. package/dist/observability/orgObserver.js +3 -3
  42. package/dist/pi/agyHeadlessResult.d.ts +60 -0
  43. package/dist/pi/agyHeadlessResult.d.ts.map +1 -0
  44. package/dist/pi/agyHeadlessResult.js +95 -0
  45. package/dist/pi/cliChildOutput.d.ts +67 -0
  46. package/dist/pi/cliChildOutput.d.ts.map +1 -0
  47. package/dist/pi/cliChildOutput.js +269 -0
  48. package/dist/pi/cliEngineRun.d.ts +16 -0
  49. package/dist/pi/cliEngineRun.d.ts.map +1 -0
  50. package/dist/pi/cliEngineRun.js +27 -0
  51. package/dist/pi/cliEngineSpawn.d.ts +55 -0
  52. package/dist/pi/cliEngineSpawn.d.ts.map +1 -0
  53. package/dist/pi/cliEngineSpawn.js +169 -0
  54. package/dist/pi/cliEnvironment.d.ts +12 -0
  55. package/dist/pi/cliEnvironment.d.ts.map +1 -0
  56. package/dist/pi/cliEnvironment.js +34 -0
  57. package/dist/pi/cliMcpRegistration.d.ts +61 -0
  58. package/dist/pi/cliMcpRegistration.d.ts.map +1 -0
  59. package/dist/pi/cliMcpRegistration.js +75 -0
  60. package/dist/pi/cliProcess.d.ts +7 -0
  61. package/dist/pi/cliProcess.d.ts.map +1 -0
  62. package/dist/pi/cliProcess.js +132 -0
  63. package/dist/pi/cliSession.d.ts +86 -24
  64. package/dist/pi/cliSession.d.ts.map +1 -1
  65. package/dist/pi/cliSession.js +251 -173
  66. package/dist/pi/cliSessionMcp.d.ts +9 -0
  67. package/dist/pi/cliSessionMcp.d.ts.map +1 -0
  68. package/dist/pi/cliSessionMcp.js +80 -0
  69. package/dist/pi/cliTurnMetering.d.ts +60 -0
  70. package/dist/pi/cliTurnMetering.d.ts.map +1 -0
  71. package/dist/pi/cliTurnMetering.js +60 -0
  72. package/dist/pi/codexFilesystemRules.d.ts +3 -0
  73. package/dist/pi/codexFilesystemRules.d.ts.map +1 -0
  74. package/dist/pi/codexFilesystemRules.js +28 -0
  75. package/dist/pi/codexHeadlessResult.d.ts +68 -0
  76. package/dist/pi/codexHeadlessResult.d.ts.map +1 -0
  77. package/dist/pi/codexHeadlessResult.js +122 -0
  78. package/dist/pi/codexRolloutUsage.d.ts +95 -0
  79. package/dist/pi/codexRolloutUsage.d.ts.map +1 -0
  80. package/dist/pi/codexRolloutUsage.js +221 -0
  81. package/dist/pi/engineTaskClock.d.ts +9 -0
  82. package/dist/pi/engineTaskClock.d.ts.map +1 -0
  83. package/dist/pi/engineTaskClock.js +28 -0
  84. package/dist/pi/engineWakeLimits.d.ts +39 -0
  85. package/dist/pi/engineWakeLimits.d.ts.map +1 -0
  86. package/dist/pi/engineWakeLimits.js +55 -0
  87. package/dist/pi/grokHeadlessResult.d.ts +36 -0
  88. package/dist/pi/grokHeadlessResult.d.ts.map +1 -0
  89. package/dist/pi/grokHeadlessResult.js +118 -0
  90. package/dist/pi/grokHomeMcpRegistration.d.ts +21 -0
  91. package/dist/pi/grokHomeMcpRegistration.d.ts.map +1 -0
  92. package/dist/pi/grokHomeMcpRegistration.js +58 -0
  93. package/dist/pi/grokSandbox.d.ts +11 -0
  94. package/dist/pi/grokSandbox.d.ts.map +1 -0
  95. package/dist/pi/grokSandbox.js +216 -0
  96. package/dist/pi/grokStreamUsage.d.ts +31 -0
  97. package/dist/pi/grokStreamUsage.d.ts.map +1 -0
  98. package/dist/pi/grokStreamUsage.js +51 -0
  99. package/dist/pi/memoryClock.d.ts +25 -0
  100. package/dist/pi/memoryClock.d.ts.map +1 -0
  101. package/dist/pi/memoryClock.js +18 -0
  102. package/dist/pi/piAgentHandle.d.ts +6 -3
  103. package/dist/pi/piAgentHandle.d.ts.map +1 -1
  104. package/dist/pi/piAgentHandle.js +42 -12
  105. package/dist/pi/piAgentWakeSupport.d.ts +35 -0
  106. package/dist/pi/piAgentWakeSupport.d.ts.map +1 -1
  107. package/dist/pi/piAgentWakeSupport.js +4 -0
  108. package/dist/pi/piHarness.d.ts +18 -3
  109. package/dist/pi/piHarness.d.ts.map +1 -1
  110. package/dist/pi/piHarness.js +83 -14
  111. package/dist/pi/prompts.d.ts +1 -0
  112. package/dist/pi/prompts.d.ts.map +1 -1
  113. package/dist/pi/prompts.js +24 -0
  114. package/dist/pi/taskClockProcess.d.ts +6 -0
  115. package/dist/pi/taskClockProcess.d.ts.map +1 -0
  116. package/dist/pi/taskClockProcess.js +8 -0
  117. package/dist/pi/turnCausal.d.ts +4 -2
  118. package/dist/pi/turnCausal.d.ts.map +1 -1
  119. package/dist/pi/turnCausal.js +4 -4
  120. package/dist/pi/turnTrace.d.ts.map +1 -1
  121. package/dist/pi/turnTrace.js +5 -8
  122. package/dist/pi/wakeAcceptance.d.ts +1 -1
  123. package/dist/pi/wakeAcceptance.d.ts.map +1 -1
  124. package/dist/pi/wakeAcceptance.js +2 -2
  125. package/dist/pi/worldTrajectory.d.ts +1 -1
  126. package/dist/pi/worldTrajectory.d.ts.map +1 -1
  127. package/dist/pi/worldTrajectory.js +3 -3
  128. package/dist/runtime/agySubscriptionBootstrap.d.ts +16 -0
  129. package/dist/runtime/agySubscriptionBootstrap.d.ts.map +1 -0
  130. package/dist/runtime/agySubscriptionBootstrap.js +80 -0
  131. package/dist/runtime/agySubscriptionRealm.d.ts +38 -0
  132. package/dist/runtime/agySubscriptionRealm.d.ts.map +1 -0
  133. package/dist/runtime/agySubscriptionRealm.js +242 -0
  134. package/dist/runtime/attention.d.ts +26 -0
  135. package/dist/runtime/attention.d.ts.map +1 -0
  136. package/dist/runtime/attention.js +49 -0
  137. package/dist/runtime/attentionDispatcher.d.ts +78 -0
  138. package/dist/runtime/attentionDispatcher.d.ts.map +1 -0
  139. package/dist/runtime/attentionDispatcher.js +365 -0
  140. package/dist/runtime/cli.d.ts +7 -0
  141. package/dist/runtime/cli.d.ts.map +1 -0
  142. package/dist/runtime/cli.js +256 -0
  143. package/dist/runtime/codexSandboxProjection.d.ts +17 -0
  144. package/dist/runtime/codexSandboxProjection.d.ts.map +1 -0
  145. package/dist/runtime/codexSandboxProjection.js +40 -0
  146. package/dist/runtime/contract-manifest.json +1 -0
  147. package/dist/runtime/contract-manifest.sha256 +1 -0
  148. package/dist/runtime/contractManifest.d.ts +8 -0
  149. package/dist/runtime/contractManifest.d.ts.map +1 -0
  150. package/dist/runtime/contractManifest.js +4 -0
  151. package/dist/runtime/engineBrokerCapabilities.d.ts +40 -0
  152. package/dist/runtime/engineBrokerCapabilities.d.ts.map +1 -0
  153. package/dist/runtime/engineBrokerCapabilities.js +69 -0
  154. package/dist/runtime/engineBrokerControlClient.d.ts +55 -0
  155. package/dist/runtime/engineBrokerControlClient.d.ts.map +1 -0
  156. package/dist/runtime/engineBrokerControlClient.js +228 -0
  157. package/dist/runtime/engineBrokerCredentialJournal.d.ts +12 -0
  158. package/dist/runtime/engineBrokerCredentialJournal.d.ts.map +1 -0
  159. package/dist/runtime/engineBrokerCredentialJournal.js +26 -0
  160. package/dist/runtime/engineBrokerInferenceProtocol.d.ts +53 -0
  161. package/dist/runtime/engineBrokerInferenceProtocol.d.ts.map +1 -0
  162. package/dist/runtime/engineBrokerInferenceProtocol.js +65 -0
  163. package/dist/runtime/engineBrokerMcpCallLog.d.ts +171 -0
  164. package/dist/runtime/engineBrokerMcpCallLog.d.ts.map +1 -0
  165. package/dist/runtime/engineBrokerMcpCallLog.js +231 -0
  166. package/dist/runtime/engineBrokerMcpFacade.d.ts +59 -0
  167. package/dist/runtime/engineBrokerMcpFacade.d.ts.map +1 -0
  168. package/dist/runtime/engineBrokerMcpFacade.js +346 -0
  169. package/dist/runtime/engineBrokerNativeClient.d.ts +52 -0
  170. package/dist/runtime/engineBrokerNativeClient.d.ts.map +1 -0
  171. package/dist/runtime/engineBrokerNativeClient.js +151 -0
  172. package/dist/runtime/engineBrokerProtocol.d.ts +167 -0
  173. package/dist/runtime/engineBrokerProtocol.d.ts.map +1 -0
  174. package/dist/runtime/engineBrokerProtocol.js +357 -0
  175. package/dist/runtime/engineBrokerSealLedger.d.ts +70 -0
  176. package/dist/runtime/engineBrokerSealLedger.d.ts.map +1 -0
  177. package/dist/runtime/engineBrokerSealLedger.js +132 -0
  178. package/dist/runtime/engineBrokerService.d.ts +43 -0
  179. package/dist/runtime/engineBrokerService.d.ts.map +1 -0
  180. package/dist/runtime/engineBrokerService.js +196 -0
  181. package/dist/runtime/engineBrokerServiceCli.d.ts +5 -0
  182. package/dist/runtime/engineBrokerServiceCli.d.ts.map +1 -0
  183. package/dist/runtime/engineBrokerServiceCli.js +32 -0
  184. package/dist/runtime/engineBrokerServiceConfig.d.ts +55 -0
  185. package/dist/runtime/engineBrokerServiceConfig.d.ts.map +1 -0
  186. package/dist/runtime/engineBrokerServiceConfig.js +130 -0
  187. package/dist/runtime/engineBrokerSingleflight.d.ts +13 -0
  188. package/dist/runtime/engineBrokerSingleflight.d.ts.map +1 -0
  189. package/dist/runtime/engineBrokerSingleflight.js +24 -0
  190. package/dist/runtime/engineBrokerTurnAccounting.d.ts +76 -0
  191. package/dist/runtime/engineBrokerTurnAccounting.d.ts.map +1 -0
  192. package/dist/runtime/engineBrokerTurnAccounting.js +108 -0
  193. package/dist/runtime/engineBrokerTurnRegistry.d.ts +57 -0
  194. package/dist/runtime/engineBrokerTurnRegistry.d.ts.map +1 -0
  195. package/dist/runtime/engineBrokerTurnRegistry.js +159 -0
  196. package/dist/runtime/engineDispatcher.d.ts +38 -0
  197. package/dist/runtime/engineDispatcher.d.ts.map +1 -0
  198. package/dist/runtime/engineDispatcher.js +228 -0
  199. package/dist/runtime/engineReadiness.d.ts +23 -0
  200. package/dist/runtime/engineReadiness.d.ts.map +1 -0
  201. package/dist/runtime/engineReadiness.js +222 -0
  202. package/dist/runtime/grokAuthenticationError.d.ts +8 -0
  203. package/dist/runtime/grokAuthenticationError.d.ts.map +1 -0
  204. package/dist/runtime/grokAuthenticationError.js +20 -0
  205. package/dist/runtime/grokBrokerCredentialAuthority.d.ts +23 -0
  206. package/dist/runtime/grokBrokerCredentialAuthority.d.ts.map +1 -0
  207. package/dist/runtime/grokBrokerCredentialAuthority.js +150 -0
  208. package/dist/runtime/grokBrokerCredentialReader.d.ts +6 -0
  209. package/dist/runtime/grokBrokerCredentialReader.d.ts.map +1 -0
  210. package/dist/runtime/grokBrokerCredentialReader.js +38 -0
  211. package/dist/runtime/grokBrokerModelPolicy.d.ts +23 -0
  212. package/dist/runtime/grokBrokerModelPolicy.d.ts.map +1 -0
  213. package/dist/runtime/grokBrokerModelPolicy.js +28 -0
  214. package/dist/runtime/grokBrokerProjection.d.ts +114 -0
  215. package/dist/runtime/grokBrokerProjection.d.ts.map +1 -0
  216. package/dist/runtime/grokBrokerProjection.js +101 -0
  217. package/dist/runtime/grokBrokerProviderClock.d.ts +26 -0
  218. package/dist/runtime/grokBrokerProviderClock.d.ts.map +1 -0
  219. package/dist/runtime/grokBrokerProviderClock.js +133 -0
  220. package/dist/runtime/grokBrokerProxy.d.ts +69 -0
  221. package/dist/runtime/grokBrokerProxy.d.ts.map +1 -0
  222. package/dist/runtime/grokBrokerProxy.js +326 -0
  223. package/dist/runtime/grokBrokerProxyJson.d.ts +10 -0
  224. package/dist/runtime/grokBrokerProxyJson.d.ts.map +1 -0
  225. package/dist/runtime/grokBrokerProxyJson.js +31 -0
  226. package/dist/runtime/grokBrokerProxyRequest.d.ts +30 -0
  227. package/dist/runtime/grokBrokerProxyRequest.d.ts.map +1 -0
  228. package/dist/runtime/grokBrokerProxyRequest.js +85 -0
  229. package/dist/runtime/grokBrokerRealmLease.d.ts +4 -0
  230. package/dist/runtime/grokBrokerRealmLease.d.ts.map +1 -0
  231. package/dist/runtime/grokBrokerRealmLease.js +33 -0
  232. package/dist/runtime/grokBrokerRefresh.d.ts +2 -0
  233. package/dist/runtime/grokBrokerRefresh.d.ts.map +1 -0
  234. package/dist/runtime/grokBrokerRefresh.js +15 -0
  235. package/dist/runtime/grokBrokerRunBudget.d.ts +20 -0
  236. package/dist/runtime/grokBrokerRunBudget.d.ts.map +1 -0
  237. package/dist/runtime/grokBrokerRunBudget.js +85 -0
  238. package/dist/runtime/grokBrokerSlot.d.ts +6 -0
  239. package/dist/runtime/grokBrokerSlot.d.ts.map +1 -0
  240. package/dist/runtime/grokBrokerSlot.js +21 -0
  241. package/dist/runtime/grokBrokerTaskClock.d.ts +32 -0
  242. package/dist/runtime/grokBrokerTaskClock.d.ts.map +1 -0
  243. package/dist/runtime/grokBrokerTaskClock.js +120 -0
  244. package/dist/runtime/grokBrokerTurnMeter.d.ts +180 -0
  245. package/dist/runtime/grokBrokerTurnMeter.d.ts.map +1 -0
  246. package/dist/runtime/grokBrokerTurnMeter.js +337 -0
  247. package/dist/runtime/grokBrokerWorkerConfig.d.ts +89 -0
  248. package/dist/runtime/grokBrokerWorkerConfig.d.ts.map +1 -0
  249. package/dist/runtime/grokBrokerWorkerConfig.js +154 -0
  250. package/dist/runtime/grokEngineBroker.d.ts +88 -0
  251. package/dist/runtime/grokEngineBroker.d.ts.map +1 -0
  252. package/dist/runtime/grokEngineBroker.js +202 -0
  253. package/dist/runtime/grokEngineBrokerLedger.d.ts +52 -0
  254. package/dist/runtime/grokEngineBrokerLedger.d.ts.map +1 -0
  255. package/dist/runtime/grokEngineBrokerLedger.js +114 -0
  256. package/dist/runtime/grokEngineBrokerMetering.d.ts +51 -0
  257. package/dist/runtime/grokEngineBrokerMetering.d.ts.map +1 -0
  258. package/dist/runtime/grokEngineBrokerMetering.js +34 -0
  259. package/dist/runtime/grokEngineBrokerTurn.d.ts +82 -0
  260. package/dist/runtime/grokEngineBrokerTurn.d.ts.map +1 -0
  261. package/dist/runtime/grokEngineBrokerTurn.js +348 -0
  262. package/dist/runtime/grokEngineBrokerTurnEnd.d.ts +88 -0
  263. package/dist/runtime/grokEngineBrokerTurnEnd.d.ts.map +1 -0
  264. package/dist/runtime/grokEngineBrokerTurnEnd.js +148 -0
  265. package/dist/runtime/grokInferenceClientConfig.d.ts +41 -0
  266. package/dist/runtime/grokInferenceClientConfig.d.ts.map +1 -0
  267. package/dist/runtime/grokInferenceClientConfig.js +62 -0
  268. package/dist/runtime/grokInferenceGrants.d.ts +77 -0
  269. package/dist/runtime/grokInferenceGrants.d.ts.map +1 -0
  270. package/dist/runtime/grokInferenceGrants.js +116 -0
  271. package/dist/runtime/grokInferenceProxy.d.ts +29 -0
  272. package/dist/runtime/grokInferenceProxy.d.ts.map +1 -0
  273. package/dist/runtime/grokInferenceProxy.js +85 -0
  274. package/dist/runtime/grokInferenceProxyRequest.d.ts +23 -0
  275. package/dist/runtime/grokInferenceProxyRequest.d.ts.map +1 -0
  276. package/dist/runtime/grokInferenceProxyRequest.js +63 -0
  277. package/dist/runtime/grokSlotPreflightReceipt.d.ts +70 -0
  278. package/dist/runtime/grokSlotPreflightReceipt.d.ts.map +1 -0
  279. package/dist/runtime/grokSlotPreflightReceipt.js +101 -0
  280. package/dist/runtime/grokSubscriptionRealm.d.ts +4 -0
  281. package/dist/runtime/grokSubscriptionRealm.d.ts.map +1 -0
  282. package/dist/runtime/grokSubscriptionRealm.js +435 -0
  283. package/dist/runtime/grokSubscriptionRealmTypes.d.ts +26 -0
  284. package/dist/runtime/grokSubscriptionRealmTypes.d.ts.map +1 -0
  285. package/dist/runtime/grokSubscriptionRealmTypes.js +1 -0
  286. package/dist/runtime/grokWorkerAttestation.d.ts +175 -0
  287. package/dist/runtime/grokWorkerAttestation.d.ts.map +1 -0
  288. package/dist/runtime/grokWorkerAttestation.js +266 -0
  289. package/dist/runtime/grokWorkerDenyPlacement.d.ts +80 -0
  290. package/dist/runtime/grokWorkerDenyPlacement.d.ts.map +1 -0
  291. package/dist/runtime/grokWorkerDenyPlacement.js +128 -0
  292. package/dist/runtime/grokWorkerHomeAttestation.d.ts +32 -0
  293. package/dist/runtime/grokWorkerHomeAttestation.d.ts.map +1 -0
  294. package/dist/runtime/grokWorkerHomeAttestation.js +75 -0
  295. package/dist/runtime/grokWorkerSandboxProfile.d.ts +27 -0
  296. package/dist/runtime/grokWorkerSandboxProfile.d.ts.map +1 -0
  297. package/dist/runtime/grokWorkerSandboxProfile.js +44 -0
  298. package/dist/runtime/grokWorkerTmpAttestation.d.ts +55 -0
  299. package/dist/runtime/grokWorkerTmpAttestation.d.ts.map +1 -0
  300. package/dist/runtime/grokWorkerTmpAttestation.js +63 -0
  301. package/dist/runtime/index.d.ts +31 -0
  302. package/dist/runtime/index.d.ts.map +1 -0
  303. package/dist/runtime/index.js +27 -0
  304. package/dist/runtime/inferenceUsageLedger.d.ts +38 -0
  305. package/dist/runtime/inferenceUsageLedger.d.ts.map +1 -0
  306. package/dist/runtime/inferenceUsageLedger.js +53 -0
  307. package/dist/runtime/mcpToolResult.d.ts +127 -0
  308. package/dist/runtime/mcpToolResult.d.ts.map +1 -0
  309. package/dist/runtime/mcpToolResult.js +214 -0
  310. package/dist/runtime/moltnetMachineRead.d.ts +97 -0
  311. package/dist/runtime/moltnetMachineRead.d.ts.map +1 -0
  312. package/dist/runtime/moltnetMachineRead.js +183 -0
  313. package/dist/runtime/native/daimon-engine-broker +0 -0
  314. package/dist/runtime/organizationRuntime.d.ts +168 -0
  315. package/dist/runtime/organizationRuntime.d.ts.map +1 -0
  316. package/dist/runtime/organizationRuntime.js +3 -0
  317. package/dist/runtime/organizationRuntimeAdmission.d.ts +6 -0
  318. package/dist/runtime/organizationRuntimeAdmission.d.ts.map +1 -0
  319. package/dist/runtime/organizationRuntimeAdmission.js +22 -0
  320. package/dist/runtime/organizationRuntimeControl.d.ts +51 -0
  321. package/dist/runtime/organizationRuntimeControl.d.ts.map +1 -0
  322. package/dist/runtime/organizationRuntimeControl.js +283 -0
  323. package/dist/runtime/organizationRuntimeHost.d.ts +19 -0
  324. package/dist/runtime/organizationRuntimeHost.d.ts.map +1 -0
  325. package/dist/runtime/organizationRuntimeHost.js +368 -0
  326. package/dist/runtime/organizationRuntimeParsing.d.ts +6 -0
  327. package/dist/runtime/organizationRuntimeParsing.d.ts.map +1 -0
  328. package/dist/runtime/organizationRuntimeParsing.js +373 -0
  329. package/dist/runtime/organizationRuntimeReadiness.d.ts +12 -0
  330. package/dist/runtime/organizationRuntimeReadiness.d.ts.map +1 -0
  331. package/dist/runtime/organizationRuntimeReadiness.js +67 -0
  332. package/dist/runtime/organizationRuntimeRecording.d.ts +7 -0
  333. package/dist/runtime/organizationRuntimeRecording.d.ts.map +1 -0
  334. package/dist/runtime/organizationRuntimeRecording.js +58 -0
  335. package/dist/runtime/physicalReadiness.d.ts +59 -0
  336. package/dist/runtime/physicalReadiness.d.ts.map +1 -0
  337. package/dist/runtime/physicalReadiness.js +176 -0
  338. package/dist/runtime/portableCredentialAuth.d.ts +6 -0
  339. package/dist/runtime/portableCredentialAuth.d.ts.map +1 -0
  340. package/dist/runtime/portableCredentialAuth.js +70 -0
  341. package/dist/runtime/portableCredentialMaterial.d.ts +8 -0
  342. package/dist/runtime/portableCredentialMaterial.d.ts.map +1 -0
  343. package/dist/runtime/portableCredentialMaterial.js +169 -0
  344. package/dist/runtime/productionAgentTools.d.ts +5 -0
  345. package/dist/runtime/productionAgentTools.d.ts.map +1 -0
  346. package/dist/runtime/productionAgentTools.js +336 -0
  347. package/dist/runtime/relocateRuntimeConfig.d.ts +14 -0
  348. package/dist/runtime/relocateRuntimeConfig.d.ts.map +1 -0
  349. package/dist/runtime/relocateRuntimeConfig.js +38 -0
  350. package/dist/runtime/runtimeHomeLayout.d.ts +48 -0
  351. package/dist/runtime/runtimeHomeLayout.d.ts.map +1 -0
  352. package/dist/runtime/runtimeHomeLayout.js +84 -0
  353. package/dist/runtime/schedule.d.ts +40 -0
  354. package/dist/runtime/schedule.d.ts.map +1 -0
  355. package/dist/runtime/schedule.js +376 -0
  356. package/dist/runtime/storeCoordination.d.ts +33 -0
  357. package/dist/runtime/storeCoordination.d.ts.map +1 -0
  358. package/dist/runtime/storeCoordination.js +117 -0
  359. package/dist/runtime/taskClock.d.ts +42 -0
  360. package/dist/runtime/taskClock.d.ts.map +1 -0
  361. package/dist/runtime/taskClock.js +102 -0
  362. package/dist/runtime/taskClockProcess.d.ts +17 -0
  363. package/dist/runtime/taskClockProcess.d.ts.map +1 -0
  364. package/dist/runtime/taskClockProcess.js +58 -0
  365. package/dist/runtime/toolResultSpill.d.ts +152 -0
  366. package/dist/runtime/toolResultSpill.d.ts.map +1 -0
  367. package/dist/runtime/toolResultSpill.js +351 -0
  368. package/dist/runtime/turnRequestLedger.d.ts +155 -0
  369. package/dist/runtime/turnRequestLedger.d.ts.map +1 -0
  370. package/dist/runtime/turnRequestLedger.js +251 -0
  371. package/dist/runtime/turnUsageLedger.d.ts +143 -0
  372. package/dist/runtime/turnUsageLedger.d.ts.map +1 -0
  373. package/dist/runtime/turnUsageLedger.js +203 -0
  374. package/dist/runtime/wakeAcceptanceClaimDiagnostics.d.ts +34 -0
  375. package/dist/runtime/wakeAcceptanceClaimDiagnostics.d.ts.map +1 -0
  376. package/dist/runtime/wakeAcceptanceClaimDiagnostics.js +79 -0
  377. package/dist/runtime/wakeAcceptanceIndex.d.ts +55 -0
  378. package/dist/runtime/wakeAcceptanceIndex.d.ts.map +1 -0
  379. package/dist/runtime/wakeAcceptanceIndex.js +158 -0
  380. package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts +25 -0
  381. package/dist/runtime/wakeAcceptanceProcessIdentity.d.ts.map +1 -0
  382. package/dist/runtime/wakeAcceptanceProcessIdentity.js +54 -0
  383. package/dist/runtime/wakeAcceptanceReconciliation.d.ts +211 -0
  384. package/dist/runtime/wakeAcceptanceReconciliation.d.ts.map +1 -0
  385. package/dist/runtime/wakeAcceptanceReconciliation.js +289 -0
  386. package/dist/runtime/wakeAcceptanceRecord.d.ts +25 -0
  387. package/dist/runtime/wakeAcceptanceRecord.d.ts.map +1 -0
  388. package/dist/runtime/wakeAcceptanceRecord.js +58 -0
  389. package/dist/runtime/wakeAcceptanceRetention.d.ts +36 -0
  390. package/dist/runtime/wakeAcceptanceRetention.d.ts.map +1 -0
  391. package/dist/runtime/wakeAcceptanceRetention.js +38 -0
  392. package/dist/runtime/wakeAcceptanceStore.d.ts +113 -0
  393. package/dist/runtime/wakeAcceptanceStore.d.ts.map +1 -0
  394. package/dist/runtime/wakeAcceptanceStore.js +561 -0
  395. package/dist/runtime/wakeAcceptanceTypes.d.ts +179 -0
  396. package/dist/runtime/wakeAcceptanceTypes.d.ts.map +1 -0
  397. package/dist/runtime/wakeAcceptanceTypes.js +95 -0
  398. package/dist/runtime/wakeFuse.d.ts +124 -0
  399. package/dist/runtime/wakeFuse.d.ts.map +1 -0
  400. package/dist/runtime/wakeFuse.js +466 -0
  401. package/dist/runtime/wakeMomentFs.d.ts +27 -0
  402. package/dist/runtime/wakeMomentFs.d.ts.map +1 -0
  403. package/dist/runtime/wakeMomentFs.js +223 -0
  404. package/dist/runtime/wakeMomentHistory.d.ts +26 -0
  405. package/dist/runtime/wakeMomentHistory.d.ts.map +1 -0
  406. package/dist/runtime/wakeMomentHistory.js +109 -0
  407. package/dist/runtime/wakeMomentIo.d.ts +22 -0
  408. package/dist/runtime/wakeMomentIo.d.ts.map +1 -0
  409. package/dist/runtime/wakeMomentIo.js +114 -0
  410. package/dist/runtime/wakeMomentRecorder.d.ts +33 -0
  411. package/dist/runtime/wakeMomentRecorder.d.ts.map +1 -0
  412. package/dist/runtime/wakeMomentRecorder.js +81 -0
  413. package/dist/runtime/wakeMomentRetention.d.ts +7 -0
  414. package/dist/runtime/wakeMomentRetention.d.ts.map +1 -0
  415. package/dist/runtime/wakeMomentRetention.js +143 -0
  416. package/dist/runtime/wakeMomentRows.d.ts +8 -0
  417. package/dist/runtime/wakeMomentRows.d.ts.map +1 -0
  418. package/dist/runtime/wakeMomentRows.js +66 -0
  419. package/dist/runtime/wakeMomentSnapshot.d.ts +56 -0
  420. package/dist/runtime/wakeMomentSnapshot.d.ts.map +1 -0
  421. package/dist/runtime/wakeMomentSnapshot.js +248 -0
  422. package/package.json +22 -11
@@ -0,0 +1,132 @@
1
+ import { ENGINE_BROKER_MCP_CALL_NAME, ENGINE_BROKER_MCP_OUTSTANDING_MAX, ENGINE_BROKER_MCP_REFUSAL_REASONS, ENGINE_BROKER_MCP_TUNNEL_MAX } from "./engineBrokerMcpCallLog.js";
2
+ import { TURN_USAGE_LEDGER, TURN_USAGE_MAX_IDENTIFIER_CHARS } from "./turnUsageLedger.js";
3
+ /**
4
+ * The operator-visible half of a sealed terminal turn, as a durable row.
5
+ *
6
+ * The seal itself already carries everything an operator needs to read a turn
7
+ * that stopped acting — the failure code, the worker's own redacted last words,
8
+ * and `engineBrokerMcpCallLog.ts`'s observation of the tool call the worker was
9
+ * blocked on. All of it travels in the control-protocol terminal response, and
10
+ * that response is the one artifact a *hung* turn never produces: the client is
11
+ * gone before the broker answers, the turn registry record lives in the
12
+ * broker's own `0700` turn store, and a training slot's control root is tmpfs
13
+ * that dies with the container. Six live runs reproduced the same signature and
14
+ * none of them could read the instrument built for it.
15
+ *
16
+ * What does survive a slot is the broker's ledger directory: Paideia already
17
+ * recovers `usage.jsonl` and `requests.jsonl` from it on the failure path. So
18
+ * this is a third stream beside those two, written by the broker — still the
19
+ * single sealed usage writer — from the sealed response and nothing else, at
20
+ * the moment that response is sealed.
21
+ *
22
+ * Its rules are the two ledgers' rules:
23
+ *
24
+ * - **Numbers, names, timings and closed vocabularies only.** The failure code,
25
+ * the accounting, the diagnostic's closed `status`/`stage`/`failure_class`
26
+ * and its already-redacted, already-bounded, control-character-free `reason`
27
+ * (`engineBrokerNativeClient.ts` produced it; nothing here re-derives it),
28
+ * plus tool-call names, GET-tunnel counts and elapsed milliseconds. Never a
29
+ * prompt, a body, a
30
+ * reply, a bearer, a capability or a session id — none of which the terminal
31
+ * response carries in the first place.
32
+ * - **Absence stays absence.** `mcp` is written only when the facade actually
33
+ * observed the turn, `diagnostic` only when the sealed response carried one,
34
+ * and `code` only for a failure. A turn that called no tool publishes
35
+ * `started: 0`, which is a measurement; a turn the facade never registered
36
+ * publishes no `mcp` member at all, which is not.
37
+ * - **It can never fail a turn.** The row is rendered from an
38
+ * already-validated frame and appended through `recordLedgerLines`, which
39
+ * swallows every I/O fault.
40
+ *
41
+ * A separate stream and a separate `v`, for `turnRequestLedger.ts`'s reason:
42
+ * Spawnfile's reader pins `noopolis.daimon.turn-usage.v1` and drops any other
43
+ * `v` outright, and Paideia's request reader refuses a row it cannot type. A
44
+ * row in a new file is invisible to both.
45
+ */
46
+ export const TURN_SEAL_LEDGER_VERSION = "noopolis.daimon.turn-seal.v1";
47
+ /** Default location: beside `usage.jsonl` and `requests.jsonl`, no new mount. */
48
+ export const TURN_SEAL_LEDGER = {
49
+ version: TURN_SEAL_LEDGER_VERSION,
50
+ directoryPath: TURN_USAGE_LEDGER.directoryPath,
51
+ filePath: `${TURN_USAGE_LEDGER.directoryPath}/turns.jsonl`,
52
+ rotatedFilePath: `${TURN_USAGE_LEDGER.directoryPath}/turns.jsonl.1`,
53
+ fileMode: TURN_USAGE_LEDGER.fileMode
54
+ };
55
+ /** A rendered seal line is bounded by its own contents: a 768-byte reason, 16 bounded names and 8 tunnel timings. */
56
+ export const TURN_SEAL_MAX_LINE_BYTES = 8_192;
57
+ const bounded = (value) => [...value].slice(0, TURN_USAGE_MAX_IDENTIFIER_CHARS).join("");
58
+ /**
59
+ * One newline-terminated row for one sealed terminal turn.
60
+ *
61
+ * Every member is copied from the terminal response the protocol already
62
+ * validated, so this projection cannot widen what the response admits; it is an
63
+ * allow-list rather than a spread, so a future additive member of the response
64
+ * does not silently become a ledger field.
65
+ */
66
+ export const renderBrokerTurnSealLine = (terminal, entry) => `${JSON.stringify({
67
+ v: TURN_SEAL_LEDGER_VERSION,
68
+ agent: bounded(entry.agent),
69
+ wake: bounded(entry.wake),
70
+ engine: "grok",
71
+ at: entry.at,
72
+ turn: terminal.turnId,
73
+ outcome: terminal.outcome,
74
+ requests: terminal.requests,
75
+ model: terminal.model,
76
+ limit_reason: terminal.limitReason,
77
+ ...(terminal.shellClock === undefined ? {} : { shell_clock: terminal.shellClock }),
78
+ ...(terminal.providerClock === undefined ? {} : { provider_clock: {
79
+ requests: terminal.providerClock.requests,
80
+ linesRewritten: terminal.providerClock.linesRewritten,
81
+ requestsWithoutDateLine: terminal.providerClock.requestsWithoutDateLine,
82
+ ...(terminal.providerClock.linesIgnored === undefined ? {} : { linesIgnored: terminal.providerClock.linesIgnored }),
83
+ injectedDate: terminal.providerClock.injectedDate,
84
+ taskDate: terminal.providerClock.taskDate
85
+ } }),
86
+ ...(terminal.kind === "failed" ? { code: terminal.code } : {}),
87
+ ...(terminal.kind === "failed" && terminal.diagnostic !== undefined
88
+ ? {
89
+ diagnostic: {
90
+ status: terminal.diagnostic.status,
91
+ stage: terminal.diagnostic.stage,
92
+ failure_class: terminal.diagnostic.failureClass,
93
+ exit_code: terminal.diagnostic.exitCode,
94
+ term_signal: terminal.diagnostic.termSignal,
95
+ ...(terminal.diagnostic.reason === undefined ? {} : { reason: terminal.diagnostic.reason })
96
+ }
97
+ }
98
+ : {}),
99
+ ...(terminal.kind === "failed" && terminal.mcpCalls !== undefined
100
+ ? {
101
+ mcp: {
102
+ started: terminal.mcpCalls.started,
103
+ answered: terminal.mcpCalls.answered,
104
+ undecoded: terminal.mcpCalls.undecoded,
105
+ outstanding: terminal.mcpCalls.outstanding
106
+ .slice(0, ENGINE_BROKER_MCP_OUTSTANDING_MAX)
107
+ .map((call) => ({ name: ENGINE_BROKER_MCP_CALL_NAME.test(call.name) ? call.name : "<invalid>", outstanding_ms: call.outstandingMs })),
108
+ // Every request the facade refused before it could relay it, by reason
109
+ // class. Without it a turn whose capability was spent seals as
110
+ // `answered == started, outstanding: []`, which is what a healthy turn
111
+ // seals as.
112
+ ...(terminal.mcpCalls.refusals === undefined
113
+ ? {}
114
+ : { refusals: Object.fromEntries(ENGINE_BROKER_MCP_REFUSAL_REASONS.map((reason) => [reason, terminal.mcpCalls.refusals[reason]])) }),
115
+ // The session's standalone GET tunnel, absent for a turn sealed before
116
+ // the facade observed that channel at all.
117
+ ...(terminal.mcpCalls.tunnels === undefined
118
+ ? {}
119
+ : {
120
+ tunnels: {
121
+ opened: terminal.mcpCalls.tunnels.opened,
122
+ closed: terminal.mcpCalls.tunnels.closed,
123
+ delivered: terminal.mcpCalls.tunnels.delivered,
124
+ open: terminal.mcpCalls.tunnels.open
125
+ .slice(0, ENGINE_BROKER_MCP_TUNNEL_MAX)
126
+ .map((tunnel) => ({ open_ms: tunnel.openMs, delivered: tunnel.delivered }))
127
+ }
128
+ })
129
+ }
130
+ }
131
+ : {})
132
+ })}\n`;
@@ -0,0 +1,43 @@
1
+ import { type BrokerClockObservation } from "./grokBrokerTaskClock.js";
2
+ import { type Socket } from "node:net";
3
+ import { type EngineBrokerCleanupObservation } from "./engineBrokerProtocol.js";
4
+ import type { EngineBrokerTurnAccounting, EngineBrokerTurnLimitOverrides } from "./engineBrokerTurnAccounting.js";
5
+ import { type GrokInferenceGrantIssued, type GrokInferenceGrantRequest } from "./grokInferenceGrants.js";
6
+ export interface EngineBrokerServiceEngine {
7
+ turn(agentId: string, wakeId: string, prompt: string, mcpEndpoint: string, signal?: AbortSignal, limits?: EngineBrokerTurnLimitOverrides, processClock?: string, slot?: number): Promise<Readonly<{
8
+ text: string;
9
+ workerPid: number;
10
+ workerUid: number;
11
+ workerStartTime: string;
12
+ }> & EngineBrokerTurnAccounting & BrokerClockObservation & EngineBrokerCleanupObservation>;
13
+ readiness(): Readonly<{
14
+ providerProxyPort: number;
15
+ mcpFacadePort: number;
16
+ registrations: number;
17
+ credentialStale: boolean;
18
+ realmLease: boolean;
19
+ workerIsolation: boolean;
20
+ }>;
21
+ close(): Promise<void>;
22
+ resetSlot?(slot: number): Promise<void>;
23
+ /** Evaluator inference grants; an engine without them refuses every grant request as `unavailable`. Refusals throw {@link GrokInferenceGrantRefused}. */
24
+ requestInferenceGrant?(request: GrokInferenceGrantRequest): GrokInferenceGrantIssued;
25
+ releaseInferenceGrant?(grantId: string): boolean;
26
+ }
27
+ export declare function startEngineBrokerService(broker: EngineBrokerServiceEngine, socketPath?: string): Promise<{
28
+ close: () => Promise<void>;
29
+ health: () => {
30
+ activeTurns: number;
31
+ socketPath: string;
32
+ };
33
+ }>;
34
+ export declare function startEngineBrokerServiceWithIdentity(broker: EngineBrokerServiceEngine, socketPath: string, expectedUid: number): Promise<{
35
+ close: () => Promise<void>;
36
+ health: () => {
37
+ activeTurns: number;
38
+ socketPath: string;
39
+ };
40
+ }>;
41
+ /** @internal The production connection handler, also exercised over an in-memory transport. */
42
+ export declare function serveEngineBrokerConnection(socket: Socket, broker: EngineBrokerServiceEngine, active?: Map<string, AbortController>): void;
43
+ //# sourceMappingURL=engineBrokerService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineBrokerService.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerService.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAE/F,OAAO,EAA6B,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAEqB,KAAK,8BAA8B,EAC9D,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AAGlH,OAAO,EAA6B,KAAK,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACpI,MAAM,WAAW,yBAAyB;IACxC,IAAI,CACF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EACpE,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,8BAA8B,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAClG,OAAO,CAAC,QAAQ,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAC;KAC7E,CAAC,GAAG,0BAA0B,GAAG,sBAAsB,GAAG,8BAA8B,CAAC,CAAC;IAC3F,SAAS,IAAG,QAAQ,CAAC;QAAC,iBAAiB,EAAC,MAAM,CAAC;QAAA,aAAa,EAAC,MAAM,CAAC;QAAA,aAAa,EAAC,MAAM,CAAC;QAAA,eAAe,EAAC,OAAO,CAAC;QAAA,UAAU,EAAC,OAAO,CAAC;QAAA,eAAe,EAAC,OAAO,CAAA;KAAC,CAAC,CAAC;IAC9J,KAAK,IAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,yJAAyJ;IACzJ,qBAAqB,CAAC,CAAC,OAAO,EAAC,yBAAyB,GAAE,wBAAwB,CAAC;IACnF,qBAAqB,CAAC,CAAC,OAAO,EAAC,MAAM,GAAE,OAAO,CAAC;CAChD;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAC,yBAAyB,EAAC,UAAU,SAAyC;;;;;;GAE5H;AACD,wBAAsB,oCAAoC,CAAC,MAAM,EAAC,yBAAyB,EAAC,UAAU,EAAC,MAAM,EAAC,WAAW,EAAC,MAAM;;;;;;GAU/H;AAoBD,+FAA+F;AAC/F,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,yBAAyB,EAAE,MAAM,+BAAqC,GAC7F,IAAI,CA0EN"}
@@ -0,0 +1,196 @@
1
+ import { brokerClockObservation } from "./grokBrokerTaskClock.js";
2
+ import { chmod, lstat, unlink } from "node:fs/promises";
3
+ import { createServer } from "node:net";
4
+ import { encodeEngineBrokerFrame, EngineBrokerFrameDecoder, EngineBrokerProtocolMismatch, parseEngineBrokerRequest } from "./engineBrokerProtocol.js";
5
+ import { EngineBrokerTurnFailure } from "./grokEngineBroker.js";
6
+ import { GROK_INFERENCE_PROXY_BASE_URL } from "./engineBrokerInferenceProtocol.js";
7
+ import { GrokInferenceGrantRefused } from "./grokInferenceGrants.js";
8
+ export function startEngineBrokerService(broker, socketPath = "/run/daimon-engine-broker/backend.sock") {
9
+ return startEngineBrokerServiceWithIdentity(broker, socketPath, 2100);
10
+ }
11
+ export async function startEngineBrokerServiceWithIdentity(broker, socketPath, expectedUid) {
12
+ if (process.getuid?.() !== expectedUid)
13
+ throw new Error("engine broker service requires broker identity");
14
+ await removeOwnedSocket(socketPath, expectedUid);
15
+ const active = new Map(), connections = new Set();
16
+ const server = createServer((socket) => {
17
+ connections.add(socket);
18
+ socket.once("close", () => connections.delete(socket));
19
+ serveEngineBrokerConnection(socket, broker, active);
20
+ });
21
+ await listen(server, socketPath);
22
+ try {
23
+ await chmod(socketPath, 0o600);
24
+ await verifySocket(socketPath, expectedUid);
25
+ }
26
+ catch (error) {
27
+ await closeServer(server, connections);
28
+ await unlink(socketPath).catch(() => undefined);
29
+ throw error;
30
+ }
31
+ let closed = false;
32
+ return { close: async () => { if (closed)
33
+ return; closed = true; for (const controller of active.values())
34
+ controller.abort(); const results = await Promise.allSettled([closeServer(server, connections), broker.close()]); await unlink(socketPath).catch(() => undefined); const failures = results.flatMap((result) => result.status === "rejected" ? [result.reason] : []); if (failures.length)
35
+ throw new AggregateError(failures, "engine broker service shutdown failed"); }, health: () => ({ activeTurns: active.size, socketPath }) };
36
+ }
37
+ /**
38
+ * A connection error is a client that went away, never a reason to take the
39
+ * broker down with it.
40
+ *
41
+ * Without this listener an accepted socket that emits `error` had none, and
42
+ * node turns an unhandled `error` on a stream into an uncaught exception — so a
43
+ * single departing client killed the whole service and every other in-flight
44
+ * turn with it. That is reachable from the ordinary cancellation path: the
45
+ * client destroys its socket on abort, this side aborts the turn, the engine
46
+ * rejects, and this side then writes a `failed` frame to a peer that is already
47
+ * gone. On Linux that write/read races an RST and surfaces as ECONNRESET; macOS
48
+ * closes cleanly enough that the error never arrives, which is why this was
49
+ * invisible until the suite ran in a container.
50
+ *
51
+ * Treated exactly like `close`: abort whatever turn this connection owned and
52
+ * drop the socket. The turn's own result is already unreachable — its only
53
+ * reader has disconnected.
54
+ */
55
+ function handleSocketError(socket, owned) { socket.on("error", () => { owned()?.controller.abort(); socket.destroy(); }); }
56
+ /** @internal The production connection handler, also exercised over an in-memory transport. */
57
+ export function serveEngineBrokerConnection(socket, broker, active = new Map()) {
58
+ const decoder = new EngineBrokerFrameDecoder();
59
+ let started = false;
60
+ let owned;
61
+ handleSocketError(socket, () => owned);
62
+ socket.once("close", () => owned?.controller.abort());
63
+ socket.on("data", (chunk) => {
64
+ try {
65
+ for (const value of decoder.push(chunk)) {
66
+ const request = parseEngineBrokerRequest(value);
67
+ if (request.kind === "health") {
68
+ if (started)
69
+ throw new Error();
70
+ started = true;
71
+ const ready = broker.readiness();
72
+ if (ready.providerProxyPort !== 43123 || ready.mcpFacadePort !== 43124 ||
73
+ ready.registrations < 1 || ready.credentialStale || !ready.realmLease || !ready.workerIsolation) {
74
+ throw new Error();
75
+ }
76
+ return send(socket, {
77
+ version: request.version, kind: "ready", requestId: request.requestId, brokerUid: 2100,
78
+ providerProxyPort: 43123, mcpFacadePort: 43124, registrations: ready.registrations,
79
+ credentialStale: false, realmLease: true, workerIsolation: true
80
+ });
81
+ }
82
+ if (request.kind === "cancel_turn") {
83
+ if (owned?.turnId !== request.turnId)
84
+ throw new Error("turn not owned by connection");
85
+ owned.controller.abort();
86
+ continue;
87
+ }
88
+ if (request.kind === "request_inference_grant" || request.kind === "release_inference_grant") {
89
+ if (started)
90
+ throw new Error();
91
+ started = true;
92
+ serveInferenceGrant(socket, broker, request);
93
+ continue;
94
+ }
95
+ if (request.kind === "reset_slot") {
96
+ if (started || broker.resetSlot === undefined)
97
+ throw new Error();
98
+ started = true;
99
+ void broker.resetSlot(request.slot).then(() => send(socket, {
100
+ version: request.version, kind: "slot_reset", requestId: request.requestId, slot: request.slot
101
+ }), () => socket.destroy());
102
+ continue;
103
+ }
104
+ const key = `${request.slot ?? request.agentId}:${request.turnId}`;
105
+ if (started || active.has(key))
106
+ throw new Error();
107
+ started = true;
108
+ const controller = new AbortController();
109
+ owned = { turnId: request.turnId, controller };
110
+ active.set(key, controller);
111
+ socket.write(encodeEngineBrokerFrame({
112
+ version: request.version, kind: "accepted", requestId: request.requestId, turnId: request.turnId
113
+ }));
114
+ void broker.turn(request.agentId, request.wakeId, request.prompt, request.mcpEndpoint, controller.signal, request.limits, request.processClock, request.slot).then((result) => send(socket, {
115
+ version: request.version, kind: "completed", requestId: request.requestId, turnId: request.turnId,
116
+ text: result.text, ...brokerClockObservation(result.shellClock, result.providerClock),
117
+ ...(result.cleanupDiagnostic === undefined ? {} : { cleanupDiagnostic: result.cleanupDiagnostic }),
118
+ workerPid: result.workerPid, workerUid: result.workerUid, workerStartTime: result.workerStartTime,
119
+ outcome: "completed", usage: result.usage, model: result.model, requests: result.requests, limitReason: "none"
120
+ }), (error) => failed(socket, request, error, controller.signal.aborted)).finally(() => {
121
+ if (active.get(key) === controller)
122
+ active.delete(key);
123
+ owned = undefined;
124
+ });
125
+ }
126
+ }
127
+ catch (error) {
128
+ if (error instanceof EngineBrokerProtocolMismatch && !socket.writableEnded) {
129
+ // Flush one small, closed diagnostic before FIN; destroy would lose it.
130
+ socket.pause();
131
+ socket.end(encodeEngineBrokerFrame(error.diagnostic));
132
+ }
133
+ else
134
+ socket.destroy();
135
+ }
136
+ });
137
+ }
138
+ /**
139
+ * Every failure the broker raises for a known registration carries its
140
+ * accounting (a wake that tried to raise a limit: `usage: null`, zero
141
+ * requests). A failure with no registration behind it (unknown agent, closed
142
+ * broker) has no declared model to report, so it is refused as a bare
143
+ * connection close and the client reports the broker unavailable.
144
+ */
145
+ function failed(socket, request, error, aborted) {
146
+ const accounting = error instanceof EngineBrokerTurnFailure ? error.accounting : undefined;
147
+ if (accounting === undefined) {
148
+ socket.destroy();
149
+ return;
150
+ }
151
+ const code = error instanceof EngineBrokerTurnFailure ? error.code : aborted ? "cancelled" : "engine_failed";
152
+ send(socket, {
153
+ version: request.version, kind: "failed", requestId: request.requestId, turnId: request.turnId, code,
154
+ ...(error instanceof EngineBrokerTurnFailure ? brokerClockObservation(error.shellClock, error.providerClock) : {}),
155
+ ...(error instanceof EngineBrokerTurnFailure && error.diagnostic ? { diagnostic: error.diagnostic } : {}),
156
+ ...(error instanceof EngineBrokerTurnFailure && error.mcpCalls ? { mcpCalls: error.mcpCalls } : {}),
157
+ ...(error instanceof EngineBrokerTurnFailure && error.cleanupDiagnostic ? { cleanupDiagnostic: error.cleanupDiagnostic } : {}),
158
+ outcome: "failed", usage: accounting.usage, model: accounting.model,
159
+ requests: accounting.requests, limitReason: accounting.limitReason
160
+ });
161
+ }
162
+ /** One grant verb per connection, answered and closed; any failure becomes a closed-code refusal and never touches turn state. */
163
+ function serveInferenceGrant(socket, broker, request) {
164
+ const refuse = (code) => send(socket, { version: request.version, kind: "inference_grant_refused", requestId: request.requestId, code });
165
+ try {
166
+ if (request.kind === "release_inference_grant") {
167
+ if (!broker.releaseInferenceGrant)
168
+ return refuse("unavailable");
169
+ return send(socket, { version: request.version, kind: "inference_grant_released", requestId: request.requestId, grantId: request.grantId, released: broker.releaseInferenceGrant(request.grantId) });
170
+ }
171
+ if (!broker.requestInferenceGrant)
172
+ return refuse("unavailable");
173
+ const grant = broker.requestInferenceGrant({ model: request.model, reasoningEffort: request.reasoningEffort, purpose: request.purpose });
174
+ send(socket, { version: request.version, kind: "inference_grant", requestId: request.requestId, grantId: grant.grantId, token: grant.token, baseUrl: GROK_INFERENCE_PROXY_BASE_URL, model: grant.policy.model, reasoningEffort: grant.policy.reasoningEffort, purpose: grant.purpose, expiresAt: new Date(grant.expiresAt).toISOString(), limits: grant.limits });
175
+ }
176
+ catch (error) {
177
+ refuse(error instanceof GrokInferenceGrantRefused ? error.code : "unavailable");
178
+ }
179
+ }
180
+ function send(socket, response) { if (!socket.destroyed)
181
+ socket.end(encodeEngineBrokerFrame(response)); }
182
+ async function removeOwnedSocket(file, uid) { try {
183
+ const entry = await lstat(file);
184
+ if (!entry.isSocket() || Number(entry.uid) !== uid)
185
+ throw new Error("unsafe broker socket");
186
+ await unlink(file);
187
+ }
188
+ catch (error) {
189
+ if (error.code !== "ENOENT")
190
+ throw error;
191
+ } }
192
+ async function verifySocket(file, uid) { const entry = await lstat(file); if (!entry.isSocket() || Number(entry.uid) !== uid || (Number(entry.mode) & 0o777) !== 0o600)
193
+ throw new Error("unsafe broker socket"); }
194
+ function listen(server, file) { return new Promise((resolve, reject) => { server.once("error", reject); server.listen(file, () => { server.off("error", reject); resolve(); }); }); }
195
+ function closeServer(server, connections) { for (const socket of connections)
196
+ socket.destroy(); return new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve())); }
@@ -0,0 +1,5 @@
1
+ import { parseEngineBrokerServiceConfig } from "./engineBrokerServiceConfig.js";
2
+ export { parseEngineBrokerServiceConfig };
3
+ export declare const ENGINE_BROKER_SERVICE_CONFIG = "/etc/daimon-engine-broker/service.json";
4
+ export declare function runEngineBrokerServiceCli(): Promise<void>;
5
+ //# sourceMappingURL=engineBrokerServiceCli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineBrokerServiceCli.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerServiceCli.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAGhF,OAAO,EAAE,8BAA8B,EAAE,CAAC;AAE1C,eAAO,MAAM,4BAA4B,2CAA2C,CAAC;AAGrF,wBAAsB,yBAAyB,IAAG,OAAO,CAAC,IAAI,CAAC,CAO9D"}
@@ -0,0 +1,32 @@
1
+ import { constants } from "node:fs";
2
+ import { open } from "node:fs/promises";
3
+ import { startEngineBrokerService } from "./engineBrokerService.js";
4
+ import { parseEngineBrokerServiceConfig } from "./engineBrokerServiceConfig.js";
5
+ import { startGrokEngineBroker } from "./grokEngineBroker.js";
6
+ export { parseEngineBrokerServiceConfig };
7
+ export const ENGINE_BROKER_SERVICE_CONFIG = "/etc/daimon-engine-broker/service.json";
8
+ const MAX_CONFIG_BYTES = 65_536;
9
+ export async function runEngineBrokerServiceCli() {
10
+ if (process.getuid?.() !== 2100)
11
+ throw new Error("engine broker service requires broker identity");
12
+ const config = parseEngineBrokerServiceConfig(await readRootConfig(ENGINE_BROKER_SERVICE_CONFIG));
13
+ const broker = await startGrokEngineBroker({ grokCommand: "/usr/local/bin/grok", nativeClient: "/opt/daimon/bin/daimon-engine-broker", credentialHome: config.credentialHome, turnStore: config.turnStore, registrations: config.registrations, maxRunRequests: config.maxRunRequests, runRequestStore: config.runRequestStore, ...(config.inferenceLedgerPath === undefined ? {} : { inferenceLedgerPath: config.inferenceLedgerPath }) });
14
+ const service = await startEngineBrokerService(broker);
15
+ let stopping;
16
+ const stop = () => { stopping ??= service.close(); return stopping; };
17
+ const onSignal = () => { void stop().catch(() => { process.exitCode = 1; }); };
18
+ process.once("SIGINT", onSignal);
19
+ process.once("SIGTERM", onSignal);
20
+ }
21
+ async function readRootConfig(file) { const handle = await open(file, constants.O_RDONLY | constants.O_NOFOLLOW); try {
22
+ const stat = await handle.stat();
23
+ if (!stat.isFile() || stat.uid !== 0 || stat.gid !== 2100 || (stat.mode & 0o777) !== 0o440 || stat.size < 2 || stat.size > MAX_CONFIG_BYTES)
24
+ throw new Error("unsafe engine broker service config");
25
+ const bytes = await handle.readFile();
26
+ if (bytes.length > MAX_CONFIG_BYTES)
27
+ throw new Error("unsafe engine broker service config");
28
+ return JSON.parse(bytes.toString("utf8"));
29
+ }
30
+ finally {
31
+ await handle.close();
32
+ } }
@@ -0,0 +1,55 @@
1
+ import { type EngineBrokerTurnLimits } from "./engineBrokerTurnAccounting.js";
2
+ import { type GrokBrokerModelPolicy } from "./grokBrokerModelPolicy.js";
3
+ export declare const ENGINE_BROKER_SERVICE_V1: "noopolis.daimon.engine-broker-service.v1";
4
+ export declare const ENGINE_BROKER_SERVICE_V3: "noopolis.daimon.engine-broker-service.v3";
5
+ export declare const ENGINE_BROKER_SERVICE_V2: "noopolis.daimon.engine-broker-service.v2";
6
+ /** One root-provisioned broker slot. Every field is fixed at provisioning time; a wake can only lower `limits`. */
7
+ export type EngineBrokerServiceRegistration = Readonly<{
8
+ agentId: string;
9
+ slot: number;
10
+ workerUid: number;
11
+ workspace: string;
12
+ profilePath: string;
13
+ eventsPath: string;
14
+ profileSha256: string;
15
+ /** Per-slot usage ledger the broker appends turn rows to; per-request rows go to `requests.jsonl` and per-turn seals to `turns.jsonl` beside it. */
16
+ usageLedgerPath: string;
17
+ limits: EngineBrokerTurnLimits;
18
+ model: GrokBrokerModelPolicy;
19
+ }>;
20
+ /**
21
+ * `inferenceLedgerPath` (v2, optional) is where evaluator inference grants
22
+ * append their rows (`inferenceUsageLedger.ts`). Without it the broker refuses
23
+ * every grant request. It can never be a subject ledger: not any
24
+ * registration's usage ledger or its `requests.jsonl`, and not the container
25
+ * ledger the wake fuse sums.
26
+ */
27
+ export type EngineBrokerServiceConfig = Readonly<{
28
+ credentialHome: string;
29
+ turnStore: string;
30
+ registrations: readonly EngineBrokerServiceRegistration[];
31
+ inferenceLedgerPath?: string;
32
+ maxRunRequests?: number;
33
+ runRequestStore?: string;
34
+ }>;
35
+ /** The per-request stream written beside a registration's usage ledger. */
36
+ export declare const engineBrokerRequestLedgerPathFor: (usageLedgerPath: string) => string;
37
+ /**
38
+ * The per-turn seal stream written beside the other two
39
+ * (`engineBrokerSealLedger.ts`): the operator-visible half of a sealed terminal
40
+ * response, for the turn whose response never reaches a client.
41
+ */
42
+ export declare const engineBrokerSealLedgerPathFor: (usageLedgerPath: string) => string;
43
+ /**
44
+ * Strict `service.json` parser.
45
+ *
46
+ * v3 retains seven-field registrations and binds slotPolicies by slot; agent IDs
47
+ * may repeat, while worker UIDs, slots and ledger streams must be distinct.
48
+ * v2 requires every registration to declare its usage ledger, limits and model
49
+ * (`model.id`/`model.reasoningEffort` from the closed lists); unknown keys at
50
+ * any level are refused. v1 is still accepted and receives today's defaults:
51
+ * the container ledger, {@link DEFAULT_GROK_BROKER_TURN_LIMITS}, and
52
+ * `grok-4.6`/`low`.
53
+ */
54
+ export declare function parseEngineBrokerServiceConfig(value: unknown): EngineBrokerServiceConfig;
55
+ //# sourceMappingURL=engineBrokerServiceConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineBrokerServiceConfig.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerServiceConfig.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgE,KAAK,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC5I,OAAO,EAAuF,KAAK,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAK7J,eAAO,MAAM,wBAAwB,EAAG,0CAAmD,CAAC;AAC5F,eAAO,MAAM,wBAAwB,EAAG,0CAAmD,CAAC;AAC5F,eAAO,MAAM,wBAAwB,EAAG,0CAAmD,CAAC;AAE5F,mHAAmH;AACnH,MAAM,MAAM,+BAA+B,GAAG,QAAQ,CAAC;IACrD,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IACpI,oJAAoJ;IACpJ,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,KAAK,EAAE,qBAAqB,CAAC;CAC9B,CAAC,CAAC;AACH;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAAE,cAAc,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,SAAS,+BAA+B,EAAE,CAAC;IAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAc5O,2EAA2E;AAC3E,eAAO,MAAM,gCAAgC,GAAI,iBAAiB,MAAM,KAAG,MAAgF,CAAC;AAE5J;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,GAAI,iBAAiB,MAAM,KAAG,MAA6E,CAAC;AAEtJ;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,GAAG,yBAAyB,CAwDxF"}
@@ -0,0 +1,130 @@
1
+ import path from "node:path";
2
+ import { DEFAULT_GROK_BROKER_TURN_LIMITS, parseEngineBrokerTurnLimits } from "./engineBrokerTurnAccounting.js";
3
+ import { DEFAULT_GROK_BROKER_MODEL_POLICY, GROK_BROKER_MODELS, GROK_BROKER_REASONING_EFFORTS } from "./grokBrokerModelPolicy.js";
4
+ import { grokWorkerEventsPathFor } from "./grokWorkerSandboxProfile.js";
5
+ import { TURN_REQUEST_LEDGER } from "./turnRequestLedger.js";
6
+ import { TURN_USAGE_LEDGER } from "./turnUsageLedger.js";
7
+ export const ENGINE_BROKER_SERVICE_V1 = "noopolis.daimon.engine-broker-service.v1";
8
+ export const ENGINE_BROKER_SERVICE_V3 = "noopolis.daimon.engine-broker-service.v3";
9
+ export const ENGINE_BROKER_SERVICE_V2 = "noopolis.daimon.engine-broker-service.v2";
10
+ const V1_REGISTRATION = ["agentId", "slot", "workerUid", "workspace", "profilePath", "eventsPath", "profileSha256"];
11
+ const V2_REGISTRATION = [...V1_REGISTRATION, "usageLedgerPath", "limits", "model"];
12
+ const invalid = () => new TypeError("invalid engine broker service config");
13
+ const plain = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
14
+ const exact = (value, fields) => { if (Object.keys(value).length !== fields.length || fields.some((field) => !Object.hasOwn(value, field)))
15
+ throw invalid(); };
16
+ /**
17
+ * Absolute and canonical: no `.`/`..`/empty components and no trailing slash.
18
+ * The native launcher derives HOME, GROK_HOME and TMPDIR from the registered
19
+ * home and refuses a non-canonical one, so the broker's view must match it.
20
+ */
21
+ const absolute = (item) => typeof item === "string" && item.length > 1 && item.startsWith("/") && !item.endsWith("/") && path.posix.normalize(item) === item && !item.split("/").slice(1).some((part) => part === "." || part === "..") && !item.includes("\0");
22
+ /** The per-request stream written beside a registration's usage ledger. */
23
+ export const engineBrokerRequestLedgerPathFor = (usageLedgerPath) => path.posix.join(path.posix.dirname(usageLedgerPath), "requests.jsonl");
24
+ /**
25
+ * The per-turn seal stream written beside the other two
26
+ * (`engineBrokerSealLedger.ts`): the operator-visible half of a sealed terminal
27
+ * response, for the turn whose response never reaches a client.
28
+ */
29
+ export const engineBrokerSealLedgerPathFor = (usageLedgerPath) => path.posix.join(path.posix.dirname(usageLedgerPath), "turns.jsonl");
30
+ /**
31
+ * Strict `service.json` parser.
32
+ *
33
+ * v3 retains seven-field registrations and binds slotPolicies by slot; agent IDs
34
+ * may repeat, while worker UIDs, slots and ledger streams must be distinct.
35
+ * v2 requires every registration to declare its usage ledger, limits and model
36
+ * (`model.id`/`model.reasoningEffort` from the closed lists); unknown keys at
37
+ * any level are refused. v1 is still accepted and receives today's defaults:
38
+ * the container ledger, {@link DEFAULT_GROK_BROKER_TURN_LIMITS}, and
39
+ * `grok-4.6`/`low`.
40
+ */
41
+ export function parseEngineBrokerServiceConfig(value) {
42
+ if (!plain(value))
43
+ throw invalid();
44
+ const v3 = value.version === ENGINE_BROKER_SERVICE_V3;
45
+ const v2 = v3 || value.version === ENGINE_BROKER_SERVICE_V2;
46
+ if (!v2 && value.version !== ENGINE_BROKER_SERVICE_V1)
47
+ throw invalid();
48
+ const top = ["version", "credentialHome", "turnStore", "registrations", ...(v3 ? ["slotPolicies"] : [])];
49
+ if (v3 && Object.hasOwn(value, "maxRunRequests")) {
50
+ if (!Number.isSafeInteger(value.maxRunRequests) || value.maxRunRequests < 1)
51
+ throw invalid();
52
+ top.push("maxRunRequests");
53
+ }
54
+ if (v3 && Object.hasOwn(value, "runRequestStore")) {
55
+ if (!absolute(value.runRequestStore) || value.maxRunRequests === undefined)
56
+ throw invalid();
57
+ top.push("runRequestStore");
58
+ }
59
+ exact(value, v2 && Object.hasOwn(value, "inferenceLedgerPath") ? [...top, "inferenceLedgerPath"] : top);
60
+ if (!absolute(value.credentialHome) || !absolute(value.turnStore) || !Array.isArray(value.registrations) || value.registrations.length === 0)
61
+ throw invalid();
62
+ const policies = new Map();
63
+ if (v3) {
64
+ if (!Array.isArray(value.slotPolicies) || value.slotPolicies.length !== value.registrations.length)
65
+ throw invalid();
66
+ for (const policy of value.slotPolicies) {
67
+ if (!plain(policy))
68
+ throw invalid();
69
+ exact(policy, ["slot", "usageLedgerPath", "limits", "model"]);
70
+ if (!Number.isSafeInteger(policy.slot) || policy.slot < 0 || policies.has(policy.slot))
71
+ throw invalid();
72
+ policies.set(policy.slot, policy);
73
+ }
74
+ }
75
+ const seen = new Set(), slots = new Set(), workers = new Set();
76
+ const ledgers = new Set();
77
+ const registrations = value.registrations.map((entry) => {
78
+ if (!plain(entry))
79
+ throw invalid();
80
+ exact(entry, v2 && !v3 ? V2_REGISTRATION : V1_REGISTRATION);
81
+ const { agentId, slot, workerUid, workspace, profilePath, eventsPath, profileSha256 } = entry;
82
+ if (typeof agentId !== "string" || !agentId.trim() || (!v3 && seen.has(agentId)) || !Number.isSafeInteger(slot) || slot < 0 || slots.has(slot) || !Number.isSafeInteger(workerUid) || workerUid < 2200 || workers.has(workerUid) || !absolute(workspace) || !absolute(profilePath) || !absolute(eventsPath) || typeof profileSha256 !== "string" || !/^[a-f0-9]{64}$/u.test(profileSha256) || eventsPath !== grokWorkerEventsPathFor(profilePath) || !profilePath.endsWith("/sandbox.toml"))
83
+ throw invalid();
84
+ seen.add(agentId);
85
+ slots.add(slot);
86
+ workers.add(workerUid);
87
+ const base = { agentId, slot: slot, workerUid: workerUid, workspace, profilePath, eventsPath, profileSha256 };
88
+ if (!v2)
89
+ return { ...base, usageLedgerPath: TURN_USAGE_LEDGER.filePath, limits: DEFAULT_GROK_BROKER_TURN_LIMITS, model: DEFAULT_GROK_BROKER_MODEL_POLICY };
90
+ const policy = v3 ? policies.get(slot) : entry;
91
+ if (policy === undefined)
92
+ throw invalid();
93
+ const usageLedgerPath = policy.usageLedgerPath;
94
+ if (!ledgerPath(usageLedgerPath) || usageLedgerPath === engineBrokerRequestLedgerPathFor(usageLedgerPath) || usageLedgerPath === engineBrokerSealLedgerPathFor(usageLedgerPath))
95
+ throw invalid();
96
+ const streams = [usageLedgerPath, engineBrokerRequestLedgerPathFor(usageLedgerPath), engineBrokerSealLedgerPathFor(usageLedgerPath)];
97
+ if (v3 && streams.some((file) => ledgers.has(file)))
98
+ throw invalid();
99
+ streams.forEach((file) => ledgers.add(file));
100
+ let limits;
101
+ try {
102
+ limits = parseEngineBrokerTurnLimits(policy.limits);
103
+ }
104
+ catch {
105
+ throw invalid();
106
+ }
107
+ return { ...base, usageLedgerPath, limits, model: parseServiceModel(policy.model) };
108
+ });
109
+ const base = { credentialHome: value.credentialHome, turnStore: value.turnStore, registrations,
110
+ ...(value.runRequestStore === undefined ? {} : { runRequestStore: value.runRequestStore }),
111
+ ...(value.maxRunRequests === undefined ? {} : { maxRunRequests: value.maxRunRequests }) };
112
+ if (!Object.hasOwn(value, "inferenceLedgerPath"))
113
+ return base;
114
+ const inferenceLedgerPath = value.inferenceLedgerPath;
115
+ if (!ledgerPath(inferenceLedgerPath))
116
+ throw invalid();
117
+ const subject = new Set([TURN_USAGE_LEDGER.filePath, TURN_REQUEST_LEDGER.filePath, ...registrations.flatMap((entry) => [entry.usageLedgerPath, engineBrokerRequestLedgerPathFor(entry.usageLedgerPath), engineBrokerSealLedgerPathFor(entry.usageLedgerPath)])]);
118
+ if (subject.has(inferenceLedgerPath))
119
+ throw invalid();
120
+ return { ...base, inferenceLedgerPath };
121
+ }
122
+ const ledgerPath = (item) => absolute(item) && item.endsWith(".jsonl") && path.posix.normalize(item) === item;
123
+ function parseServiceModel(value) {
124
+ if (!plain(value))
125
+ throw invalid();
126
+ exact(value, ["id", "reasoningEffort"]);
127
+ if (!GROK_BROKER_MODELS.includes(value.id) || !GROK_BROKER_REASONING_EFFORTS.includes(value.reasoningEffort))
128
+ throw invalid();
129
+ return Object.freeze({ model: value.id, reasoningEffort: value.reasoningEffort });
130
+ }
@@ -0,0 +1,13 @@
1
+ export declare class EngineBrokerSingleflight<T> {
2
+ private active;
3
+ run(operation: () => Promise<T>): Promise<T>;
4
+ }
5
+ export declare class EngineBrokerGenerationFence {
6
+ private generation;
7
+ private stale;
8
+ restore(generation: number): void;
9
+ snapshot(): number;
10
+ promote(expected: number): number;
11
+ markStale(): void;
12
+ }
13
+ //# sourceMappingURL=engineBrokerSingleflight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engineBrokerSingleflight.d.ts","sourceRoot":"","sources":["../../src/runtime/engineBrokerSingleflight.ts"],"names":[],"mappings":"AAAA,qBAAa,wBAAwB,CAAC,CAAC;IACrC,OAAO,CAAC,MAAM,CAAyB;IACvC,GAAG,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAM7C;AAED,qBAAa,2BAA2B;IACtC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,UAAU,EAAC,MAAM,GAAE,IAAI;IAC/B,QAAQ,IAAI,MAAM;IAClB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IACjC,SAAS,IAAI,IAAI;CAClB"}