@eloxiv/contracts 0.0.0-stage → 0.1.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 (537) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -2
  3. package/dist/Agent.d.ts +792 -0
  4. package/dist/Agent.d.ts.map +1 -0
  5. package/dist/Agent.js +610 -0
  6. package/dist/Agent.js.map +1 -0
  7. package/dist/Analytics.d.ts +46 -0
  8. package/dist/Analytics.d.ts.map +1 -0
  9. package/dist/Analytics.js +89 -0
  10. package/dist/Analytics.js.map +1 -0
  11. package/dist/Approval.d.ts +70 -0
  12. package/dist/Approval.d.ts.map +1 -0
  13. package/dist/Approval.js +127 -0
  14. package/dist/Approval.js.map +1 -0
  15. package/dist/Catalog.d.ts +238 -0
  16. package/dist/Catalog.d.ts.map +1 -0
  17. package/dist/Catalog.js +169 -0
  18. package/dist/Catalog.js.map +1 -0
  19. package/dist/Checklist.d.ts +99 -0
  20. package/dist/Checklist.d.ts.map +1 -0
  21. package/dist/Checklist.js +105 -0
  22. package/dist/Checklist.js.map +1 -0
  23. package/dist/Data.d.ts +107 -0
  24. package/dist/Data.d.ts.map +1 -0
  25. package/dist/Data.js +93 -0
  26. package/dist/Data.js.map +1 -0
  27. package/dist/Devices.d.ts +857 -0
  28. package/dist/Devices.d.ts.map +1 -0
  29. package/dist/Devices.js +590 -0
  30. package/dist/Devices.js.map +1 -0
  31. package/dist/Durable.d.ts +406 -0
  32. package/dist/Durable.d.ts.map +1 -0
  33. package/dist/Durable.js +203 -0
  34. package/dist/Durable.js.map +1 -0
  35. package/dist/Errors.d.ts +95 -0
  36. package/dist/Errors.d.ts.map +1 -0
  37. package/dist/Errors.js +72 -0
  38. package/dist/Errors.js.map +1 -0
  39. package/dist/JsonSchema.d.ts +355 -0
  40. package/dist/JsonSchema.d.ts.map +1 -0
  41. package/dist/JsonSchema.js +151 -0
  42. package/dist/JsonSchema.js.map +1 -0
  43. package/dist/Manifest.d.ts +353 -0
  44. package/dist/Manifest.d.ts.map +1 -0
  45. package/dist/Manifest.js +894 -0
  46. package/dist/Manifest.js.map +1 -0
  47. package/dist/Module.d.ts +447 -0
  48. package/dist/Module.d.ts.map +1 -0
  49. package/dist/Module.js +221 -0
  50. package/dist/Module.js.map +1 -0
  51. package/dist/Optimistic.d.ts +192 -0
  52. package/dist/Optimistic.d.ts.map +1 -0
  53. package/dist/Optimistic.js +319 -0
  54. package/dist/Optimistic.js.map +1 -0
  55. package/dist/Projection.d.ts +163 -0
  56. package/dist/Projection.d.ts.map +1 -0
  57. package/dist/Projection.js +158 -0
  58. package/dist/Projection.js.map +1 -0
  59. package/dist/Proposals.d.ts +103 -0
  60. package/dist/Proposals.d.ts.map +1 -0
  61. package/dist/Proposals.js +72 -0
  62. package/dist/Proposals.js.map +1 -0
  63. package/dist/Receipt.d.ts +243 -0
  64. package/dist/Receipt.d.ts.map +1 -0
  65. package/dist/Receipt.js +108 -0
  66. package/dist/Receipt.js.map +1 -0
  67. package/dist/Records.d.ts +297 -0
  68. package/dist/Records.d.ts.map +1 -0
  69. package/dist/Records.js +171 -0
  70. package/dist/Records.js.map +1 -0
  71. package/dist/Render.d.ts +207 -0
  72. package/dist/Render.d.ts.map +1 -0
  73. package/dist/Render.js +502 -0
  74. package/dist/Render.js.map +1 -0
  75. package/dist/Rpc.d.ts +115 -0
  76. package/dist/Rpc.d.ts.map +1 -0
  77. package/dist/Rpc.js +68 -0
  78. package/dist/Rpc.js.map +1 -0
  79. package/dist/SearchLanguages.d.ts +4 -0
  80. package/dist/SearchLanguages.d.ts.map +1 -0
  81. package/dist/SearchLanguages.js +33 -0
  82. package/dist/SearchLanguages.js.map +1 -0
  83. package/dist/Service.d.ts +59 -0
  84. package/dist/Service.d.ts.map +1 -0
  85. package/dist/Service.js +38 -0
  86. package/dist/Service.js.map +1 -0
  87. package/dist/Versions.d.ts +9 -0
  88. package/dist/Versions.d.ts.map +1 -0
  89. package/dist/Versions.js +78 -0
  90. package/dist/Versions.js.map +1 -0
  91. package/dist/contracts/ActionConsent.d.ts +189 -0
  92. package/dist/contracts/ActionConsent.d.ts.map +1 -0
  93. package/dist/contracts/ActionConsent.js +129 -0
  94. package/dist/contracts/ActionConsent.js.map +1 -0
  95. package/dist/contracts/ActionRegistry.d.ts +149 -0
  96. package/dist/contracts/ActionRegistry.d.ts.map +1 -0
  97. package/dist/contracts/ActionRegistry.js +37 -0
  98. package/dist/contracts/ActionRegistry.js.map +1 -0
  99. package/dist/contracts/Actor.d.ts +129 -0
  100. package/dist/contracts/Actor.d.ts.map +1 -0
  101. package/dist/contracts/Actor.js +47 -0
  102. package/dist/contracts/Actor.js.map +1 -0
  103. package/dist/contracts/AgentResources.d.ts +248 -0
  104. package/dist/contracts/AgentResources.d.ts.map +1 -0
  105. package/dist/contracts/AgentResources.js +158 -0
  106. package/dist/contracts/AgentResources.js.map +1 -0
  107. package/dist/contracts/AgentRuntime.d.ts +453 -0
  108. package/dist/contracts/AgentRuntime.d.ts.map +1 -0
  109. package/dist/contracts/AgentRuntime.js +117 -0
  110. package/dist/contracts/AgentRuntime.js.map +1 -0
  111. package/dist/contracts/Approvals.d.ts +303 -0
  112. package/dist/contracts/Approvals.d.ts.map +1 -0
  113. package/dist/contracts/Approvals.js +117 -0
  114. package/dist/contracts/Approvals.js.map +1 -0
  115. package/dist/contracts/Audit.d.ts +510 -0
  116. package/dist/contracts/Audit.d.ts.map +1 -0
  117. package/dist/contracts/Audit.js +139 -0
  118. package/dist/contracts/Audit.js.map +1 -0
  119. package/dist/contracts/CalendarProvider.d.ts +572 -0
  120. package/dist/contracts/CalendarProvider.d.ts.map +1 -0
  121. package/dist/contracts/CalendarProvider.js +203 -0
  122. package/dist/contracts/CalendarProvider.js.map +1 -0
  123. package/dist/contracts/Capability.d.ts +197 -0
  124. package/dist/contracts/Capability.d.ts.map +1 -0
  125. package/dist/contracts/Capability.js +189 -0
  126. package/dist/contracts/Capability.js.map +1 -0
  127. package/dist/contracts/ClientSDK.d.ts +250 -0
  128. package/dist/contracts/ClientSDK.d.ts.map +1 -0
  129. package/dist/contracts/ClientSDK.js +184 -0
  130. package/dist/contracts/ClientSDK.js.map +1 -0
  131. package/dist/contracts/CollabDocument.d.ts +781 -0
  132. package/dist/contracts/CollabDocument.d.ts.map +1 -0
  133. package/dist/contracts/CollabDocument.js +364 -0
  134. package/dist/contracts/CollabDocument.js.map +1 -0
  135. package/dist/contracts/Command.d.ts +183 -0
  136. package/dist/contracts/Command.d.ts.map +1 -0
  137. package/dist/contracts/Command.js +66 -0
  138. package/dist/contracts/Command.js.map +1 -0
  139. package/dist/contracts/Connections.d.ts +612 -0
  140. package/dist/contracts/Connections.d.ts.map +1 -0
  141. package/dist/contracts/Connections.js +323 -0
  142. package/dist/contracts/Connections.js.map +1 -0
  143. package/dist/contracts/ContextAccounting.d.ts +79 -0
  144. package/dist/contracts/ContextAccounting.d.ts.map +1 -0
  145. package/dist/contracts/ContextAccounting.js +32 -0
  146. package/dist/contracts/ContextAccounting.js.map +1 -0
  147. package/dist/contracts/Daemon.d.ts +486 -0
  148. package/dist/contracts/Daemon.d.ts.map +1 -0
  149. package/dist/contracts/Daemon.js +192 -0
  150. package/dist/contracts/Daemon.js.map +1 -0
  151. package/dist/contracts/DbTx.d.ts +149 -0
  152. package/dist/contracts/DbTx.d.ts.map +1 -0
  153. package/dist/contracts/DbTx.js +94 -0
  154. package/dist/contracts/DbTx.js.map +1 -0
  155. package/dist/contracts/Delegation.d.ts +121 -0
  156. package/dist/contracts/Delegation.d.ts.map +1 -0
  157. package/dist/contracts/Delegation.js +76 -0
  158. package/dist/contracts/Delegation.js.map +1 -0
  159. package/dist/contracts/DeviceControl.d.ts +293 -0
  160. package/dist/contracts/DeviceControl.d.ts.map +1 -0
  161. package/dist/contracts/DeviceControl.js +107 -0
  162. package/dist/contracts/DeviceControl.js.map +1 -0
  163. package/dist/contracts/Directory.d.ts +492 -0
  164. package/dist/contracts/Directory.d.ts.map +1 -0
  165. package/dist/contracts/Directory.js +225 -0
  166. package/dist/contracts/Directory.js.map +1 -0
  167. package/dist/contracts/DirectoryProvider.d.ts +214 -0
  168. package/dist/contracts/DirectoryProvider.d.ts.map +1 -0
  169. package/dist/contracts/DirectoryProvider.js +73 -0
  170. package/dist/contracts/DirectoryProvider.js.map +1 -0
  171. package/dist/contracts/DocumentSource.d.ts +190 -0
  172. package/dist/contracts/DocumentSource.d.ts.map +1 -0
  173. package/dist/contracts/DocumentSource.js +64 -0
  174. package/dist/contracts/DocumentSource.js.map +1 -0
  175. package/dist/contracts/Files.d.ts +762 -0
  176. package/dist/contracts/Files.d.ts.map +1 -0
  177. package/dist/contracts/Files.js +339 -0
  178. package/dist/contracts/Files.js.map +1 -0
  179. package/dist/contracts/Flags.d.ts +265 -0
  180. package/dist/contracts/Flags.d.ts.map +1 -0
  181. package/dist/contracts/Flags.js +197 -0
  182. package/dist/contracts/Flags.js.map +1 -0
  183. package/dist/contracts/Host.d.ts +320 -0
  184. package/dist/contracts/Host.d.ts.map +1 -0
  185. package/dist/contracts/Host.js +224 -0
  186. package/dist/contracts/Host.js.map +1 -0
  187. package/dist/contracts/HttpApi.d.ts +102 -0
  188. package/dist/contracts/HttpApi.d.ts.map +1 -0
  189. package/dist/contracts/HttpApi.js +89 -0
  190. package/dist/contracts/HttpApi.js.map +1 -0
  191. package/dist/contracts/Ingestion.d.ts +522 -0
  192. package/dist/contracts/Ingestion.d.ts.map +1 -0
  193. package/dist/contracts/Ingestion.js +275 -0
  194. package/dist/contracts/Ingestion.js.map +1 -0
  195. package/dist/contracts/Ingress.d.ts +132 -0
  196. package/dist/contracts/Ingress.d.ts.map +1 -0
  197. package/dist/contracts/Ingress.js +102 -0
  198. package/dist/contracts/Ingress.js.map +1 -0
  199. package/dist/contracts/Invocation.d.ts +361 -0
  200. package/dist/contracts/Invocation.d.ts.map +1 -0
  201. package/dist/contracts/Invocation.js +104 -0
  202. package/dist/contracts/Invocation.js.map +1 -0
  203. package/dist/contracts/LocalClient.d.ts +888 -0
  204. package/dist/contracts/LocalClient.d.ts.map +1 -0
  205. package/dist/contracts/LocalClient.js +429 -0
  206. package/dist/contracts/LocalClient.js.map +1 -0
  207. package/dist/contracts/Locale.d.ts +162 -0
  208. package/dist/contracts/Locale.d.ts.map +1 -0
  209. package/dist/contracts/Locale.js +123 -0
  210. package/dist/contracts/Locale.js.map +1 -0
  211. package/dist/contracts/MachineIdentity.d.ts +434 -0
  212. package/dist/contracts/MachineIdentity.d.ts.map +1 -0
  213. package/dist/contracts/MachineIdentity.js +223 -0
  214. package/dist/contracts/MachineIdentity.js.map +1 -0
  215. package/dist/contracts/MailProvider.d.ts +791 -0
  216. package/dist/contracts/MailProvider.d.ts.map +1 -0
  217. package/dist/contracts/MailProvider.js +237 -0
  218. package/dist/contracts/MailProvider.js.map +1 -0
  219. package/dist/contracts/Memory.d.ts +62 -0
  220. package/dist/contracts/Memory.d.ts.map +1 -0
  221. package/dist/contracts/Memory.js +43 -0
  222. package/dist/contracts/Memory.js.map +1 -0
  223. package/dist/contracts/Messaging.d.ts +154 -0
  224. package/dist/contracts/Messaging.d.ts.map +1 -0
  225. package/dist/contracts/Messaging.js +97 -0
  226. package/dist/contracts/Messaging.js.map +1 -0
  227. package/dist/contracts/Metering.d.ts +334 -0
  228. package/dist/contracts/Metering.d.ts.map +1 -0
  229. package/dist/contracts/Metering.js +202 -0
  230. package/dist/contracts/Metering.js.map +1 -0
  231. package/dist/contracts/ModelProvider.d.ts +142 -0
  232. package/dist/contracts/ModelProvider.d.ts.map +1 -0
  233. package/dist/contracts/ModelProvider.js +72 -0
  234. package/dist/contracts/ModelProvider.js.map +1 -0
  235. package/dist/contracts/ModuleManifest.d.ts +2519 -0
  236. package/dist/contracts/ModuleManifest.d.ts.map +1 -0
  237. package/dist/contracts/ModuleManifest.js +272 -0
  238. package/dist/contracts/ModuleManifest.js.map +1 -0
  239. package/dist/contracts/NotificationChannel.d.ts +378 -0
  240. package/dist/contracts/NotificationChannel.d.ts.map +1 -0
  241. package/dist/contracts/NotificationChannel.js +136 -0
  242. package/dist/contracts/NotificationChannel.js.map +1 -0
  243. package/dist/contracts/Notifications.d.ts +417 -0
  244. package/dist/contracts/Notifications.d.ts.map +1 -0
  245. package/dist/contracts/Notifications.js +267 -0
  246. package/dist/contracts/Notifications.js.map +1 -0
  247. package/dist/contracts/Outbox.d.ts +469 -0
  248. package/dist/contracts/Outbox.d.ts.map +1 -0
  249. package/dist/contracts/Outbox.js +215 -0
  250. package/dist/contracts/Outbox.js.map +1 -0
  251. package/dist/contracts/Privacy.d.ts +1029 -0
  252. package/dist/contracts/Privacy.d.ts.map +1 -0
  253. package/dist/contracts/Privacy.js +437 -0
  254. package/dist/contracts/Privacy.js.map +1 -0
  255. package/dist/contracts/Progress.d.ts +305 -0
  256. package/dist/contracts/Progress.d.ts.map +1 -0
  257. package/dist/contracts/Progress.js +174 -0
  258. package/dist/contracts/Progress.js.map +1 -0
  259. package/dist/contracts/QuerySurface.d.ts +231 -0
  260. package/dist/contracts/QuerySurface.d.ts.map +1 -0
  261. package/dist/contracts/QuerySurface.js +113 -0
  262. package/dist/contracts/QuerySurface.js.map +1 -0
  263. package/dist/contracts/Readiness.d.ts +105 -0
  264. package/dist/contracts/Readiness.d.ts.map +1 -0
  265. package/dist/contracts/Readiness.js +57 -0
  266. package/dist/contracts/Readiness.js.map +1 -0
  267. package/dist/contracts/Release.d.ts +295 -0
  268. package/dist/contracts/Release.d.ts.map +1 -0
  269. package/dist/contracts/Release.js +175 -0
  270. package/dist/contracts/Release.js.map +1 -0
  271. package/dist/contracts/ResultRendering.d.ts +533 -0
  272. package/dist/contracts/ResultRendering.d.ts.map +1 -0
  273. package/dist/contracts/ResultRendering.js +59 -0
  274. package/dist/contracts/ResultRendering.js.map +1 -0
  275. package/dist/contracts/Sandbox.d.ts +1164 -0
  276. package/dist/contracts/Sandbox.d.ts.map +1 -0
  277. package/dist/contracts/Sandbox.js +550 -0
  278. package/dist/contracts/Sandbox.js.map +1 -0
  279. package/dist/contracts/Scheduler.d.ts +814 -0
  280. package/dist/contracts/Scheduler.d.ts.map +1 -0
  281. package/dist/contracts/Scheduler.js +202 -0
  282. package/dist/contracts/Scheduler.js.map +1 -0
  283. package/dist/contracts/ScreenContext.d.ts +514 -0
  284. package/dist/contracts/ScreenContext.d.ts.map +1 -0
  285. package/dist/contracts/ScreenContext.js +272 -0
  286. package/dist/contracts/ScreenContext.js.map +1 -0
  287. package/dist/contracts/Search.d.ts +308 -0
  288. package/dist/contracts/Search.d.ts.map +1 -0
  289. package/dist/contracts/Search.js +107 -0
  290. package/dist/contracts/Search.js.map +1 -0
  291. package/dist/contracts/Secrets.d.ts +483 -0
  292. package/dist/contracts/Secrets.d.ts.map +1 -0
  293. package/dist/contracts/Secrets.js +136 -0
  294. package/dist/contracts/Secrets.js.map +1 -0
  295. package/dist/contracts/Settings.d.ts +221 -0
  296. package/dist/contracts/Settings.d.ts.map +1 -0
  297. package/dist/contracts/Settings.js +163 -0
  298. package/dist/contracts/Settings.js.map +1 -0
  299. package/dist/contracts/Sharing.d.ts +319 -0
  300. package/dist/contracts/Sharing.d.ts.map +1 -0
  301. package/dist/contracts/Sharing.js +172 -0
  302. package/dist/contracts/Sharing.js.map +1 -0
  303. package/dist/contracts/Slot.d.ts +162 -0
  304. package/dist/contracts/Slot.d.ts.map +1 -0
  305. package/dist/contracts/Slot.js +56 -0
  306. package/dist/contracts/Slot.js.map +1 -0
  307. package/dist/contracts/Space.d.ts +256 -0
  308. package/dist/contracts/Space.d.ts.map +1 -0
  309. package/dist/contracts/Space.js +133 -0
  310. package/dist/contracts/Space.js.map +1 -0
  311. package/dist/contracts/StorageAdapter.d.ts +124 -0
  312. package/dist/contracts/StorageAdapter.d.ts.map +1 -0
  313. package/dist/contracts/StorageAdapter.js +96 -0
  314. package/dist/contracts/StorageAdapter.js.map +1 -0
  315. package/dist/contracts/StorageBackend.d.ts +310 -0
  316. package/dist/contracts/StorageBackend.d.ts.map +1 -0
  317. package/dist/contracts/StorageBackend.js +196 -0
  318. package/dist/contracts/StorageBackend.js.map +1 -0
  319. package/dist/contracts/Sync.d.ts +286 -0
  320. package/dist/contracts/Sync.d.ts.map +1 -0
  321. package/dist/contracts/Sync.js +157 -0
  322. package/dist/contracts/Sync.js.map +1 -0
  323. package/dist/contracts/Telemetry.d.ts +183 -0
  324. package/dist/contracts/Telemetry.d.ts.map +1 -0
  325. package/dist/contracts/Telemetry.js +153 -0
  326. package/dist/contracts/Telemetry.js.map +1 -0
  327. package/dist/contracts/ThemeTokens.d.ts +212 -0
  328. package/dist/contracts/ThemeTokens.d.ts.map +1 -0
  329. package/dist/contracts/ThemeTokens.js +111 -0
  330. package/dist/contracts/ThemeTokens.js.map +1 -0
  331. package/dist/contracts/ToolSource.d.ts +135 -0
  332. package/dist/contracts/ToolSource.d.ts.map +1 -0
  333. package/dist/contracts/ToolSource.js +81 -0
  334. package/dist/contracts/ToolSource.js.map +1 -0
  335. package/dist/contracts/Versioning.d.ts +363 -0
  336. package/dist/contracts/Versioning.d.ts.map +1 -0
  337. package/dist/contracts/Versioning.js +201 -0
  338. package/dist/contracts/Versioning.js.map +1 -0
  339. package/dist/contracts/View.d.ts +232 -0
  340. package/dist/contracts/View.d.ts.map +1 -0
  341. package/dist/contracts/View.js +102 -0
  342. package/dist/contracts/View.js.map +1 -0
  343. package/dist/contracts/WorkItems.d.ts +242 -0
  344. package/dist/contracts/WorkItems.d.ts.map +1 -0
  345. package/dist/contracts/WorkItems.js +126 -0
  346. package/dist/contracts/WorkItems.js.map +1 -0
  347. package/dist/contracts/Workflow.d.ts +191 -0
  348. package/dist/contracts/Workflow.d.ts.map +1 -0
  349. package/dist/contracts/Workflow.js +63 -0
  350. package/dist/contracts/Workflow.js.map +1 -0
  351. package/dist/contracts/index.d.ts +75 -0
  352. package/dist/contracts/index.d.ts.map +1 -0
  353. package/dist/contracts/index.js +196 -0
  354. package/dist/contracts/index.js.map +1 -0
  355. package/dist/devices/module.d.ts +3777 -0
  356. package/dist/devices/module.d.ts.map +1 -0
  357. package/dist/devices/module.js +179 -0
  358. package/dist/devices/module.js.map +1 -0
  359. package/dist/drizzle/Entity.d.ts +148 -0
  360. package/dist/drizzle/Entity.d.ts.map +1 -0
  361. package/dist/drizzle/Entity.js +396 -0
  362. package/dist/drizzle/Entity.js.map +1 -0
  363. package/dist/index.d.ts +20 -0
  364. package/dist/index.d.ts.map +1 -0
  365. package/dist/index.js +20 -0
  366. package/dist/index.js.map +1 -0
  367. package/package.json +48 -3
  368. package/schema/Actor.json +46 -0
  369. package/schema/AuditRecord.json +403 -0
  370. package/schema/DaemonHealth.json +29 -0
  371. package/schema/InvocationError.json +257 -0
  372. package/schema/InvocationReceipt.json +253 -0
  373. package/schema/Lockfile.json +129 -0
  374. package/schema/OutboxEvent.json +36 -0
  375. package/schema/PairingConfirm.json +33 -0
  376. package/schema/PairingResult.json +18 -0
  377. package/schema/PairingStart.json +18 -0
  378. package/schema/ProvenanceEntry.json +110 -0
  379. package/schema/ReplayEnvelope.json +269 -0
  380. package/schema/Surface.json +17 -0
  381. package/schema/codegen/LocalClient.json +1298 -0
  382. package/schema/codegen/Sandbox.json +320 -0
  383. package/schema/contracts/ActionConsent.json +1930 -0
  384. package/schema/contracts/ActionRegistry.json +722 -0
  385. package/schema/contracts/Actor.json +451 -0
  386. package/schema/contracts/AgentResources.json +1400 -0
  387. package/schema/contracts/AgentRuntime.json +4017 -0
  388. package/schema/contracts/Approvals.json +2916 -0
  389. package/schema/contracts/Audit.json +3268 -0
  390. package/schema/contracts/CalendarProvider.json +5557 -0
  391. package/schema/contracts/ClientSDK.json +1400 -0
  392. package/schema/contracts/CollabDocument.json +4012 -0
  393. package/schema/contracts/Command.json +616 -0
  394. package/schema/contracts/Connections.json +6687 -0
  395. package/schema/contracts/ContextAccounting.json +685 -0
  396. package/schema/contracts/Daemon.json +4555 -0
  397. package/schema/contracts/DbTx.json +321 -0
  398. package/schema/contracts/Delegation.json +949 -0
  399. package/schema/contracts/DeviceControl.json +2626 -0
  400. package/schema/contracts/Directory.json +5168 -0
  401. package/schema/contracts/DirectoryProvider.json +2090 -0
  402. package/schema/contracts/DocumentSource.json +2044 -0
  403. package/schema/contracts/Files.json +4122 -0
  404. package/schema/contracts/Flags.json +1202 -0
  405. package/schema/contracts/Host.json +1769 -0
  406. package/schema/contracts/HttpApi.json +1615 -0
  407. package/schema/contracts/Ingestion.json +3211 -0
  408. package/schema/contracts/Ingress.json +819 -0
  409. package/schema/contracts/Invocation.json +2044 -0
  410. package/schema/contracts/LocalClient.json +6657 -0
  411. package/schema/contracts/Locale.json +654 -0
  412. package/schema/contracts/MachineIdentity.json +2303 -0
  413. package/schema/contracts/MailProvider.json +6663 -0
  414. package/schema/contracts/Memory.json +579 -0
  415. package/schema/contracts/Messaging.json +1764 -0
  416. package/schema/contracts/Metering.json +3060 -0
  417. package/schema/contracts/ModelProvider.json +1127 -0
  418. package/schema/contracts/ModuleManifest.json +9449 -0
  419. package/schema/contracts/NotificationChannel.json +986 -0
  420. package/schema/contracts/Notifications.json +4280 -0
  421. package/schema/contracts/Outbox.json +1451 -0
  422. package/schema/contracts/Privacy.json +4354 -0
  423. package/schema/contracts/Progress.json +1524 -0
  424. package/schema/contracts/QuerySurface.json +661 -0
  425. package/schema/contracts/Readiness.json +209 -0
  426. package/schema/contracts/Release.json +805 -0
  427. package/schema/contracts/ResultRendering.json +2859 -0
  428. package/schema/contracts/Sandbox.json +2286 -0
  429. package/schema/contracts/Scheduler.json +6138 -0
  430. package/schema/contracts/ScreenContext.json +1238 -0
  431. package/schema/contracts/Search.json +1058 -0
  432. package/schema/contracts/Secrets.json +2444 -0
  433. package/schema/contracts/Settings.json +654 -0
  434. package/schema/contracts/Sharing.json +2854 -0
  435. package/schema/contracts/Slot.json +537 -0
  436. package/schema/contracts/Space.json +892 -0
  437. package/schema/contracts/StorageAdapter.json +623 -0
  438. package/schema/contracts/StorageBackend.json +2421 -0
  439. package/schema/contracts/Sync.json +894 -0
  440. package/schema/contracts/Telemetry.json +696 -0
  441. package/schema/contracts/ThemeTokens.json +547 -0
  442. package/schema/contracts/ToolSource.json +1333 -0
  443. package/schema/contracts/Versioning.json +1481 -0
  444. package/schema/contracts/View.json +750 -0
  445. package/schema/contracts/WorkItems.json +1731 -0
  446. package/schema/contracts/Workflow.json +1242 -0
  447. package/src/Agent.ts +758 -0
  448. package/src/Analytics.ts +110 -0
  449. package/src/Approval.ts +131 -0
  450. package/src/Catalog.ts +192 -0
  451. package/src/Checklist.ts +162 -0
  452. package/src/Data.ts +109 -0
  453. package/src/Devices.ts +721 -0
  454. package/src/Durable.ts +240 -0
  455. package/src/Errors.ts +111 -0
  456. package/src/JsonSchema.ts +166 -0
  457. package/src/Manifest.ts +1147 -0
  458. package/src/Module.ts +640 -0
  459. package/src/Optimistic.ts +332 -0
  460. package/src/Projection.ts +207 -0
  461. package/src/Proposals.ts +89 -0
  462. package/src/Receipt.ts +125 -0
  463. package/src/Records.ts +197 -0
  464. package/src/Render.ts +515 -0
  465. package/src/Rpc.ts +113 -0
  466. package/src/SearchLanguages.ts +33 -0
  467. package/src/Service.ts +102 -0
  468. package/src/Versions.ts +69 -0
  469. package/src/contracts/ActionConsent.ts +150 -0
  470. package/src/contracts/ActionRegistry.ts +39 -0
  471. package/src/contracts/Actor.ts +53 -0
  472. package/src/contracts/AgentResources.ts +167 -0
  473. package/src/contracts/AgentRuntime.ts +154 -0
  474. package/src/contracts/Approvals.ts +133 -0
  475. package/src/contracts/Audit.ts +160 -0
  476. package/src/contracts/CalendarProvider.ts +241 -0
  477. package/src/contracts/Capability.ts +246 -0
  478. package/src/contracts/ClientSDK.ts +199 -0
  479. package/src/contracts/CollabDocument.ts +420 -0
  480. package/src/contracts/Command.ts +74 -0
  481. package/src/contracts/Connections.ts +360 -0
  482. package/src/contracts/ContextAccounting.ts +35 -0
  483. package/src/contracts/Daemon.ts +247 -0
  484. package/src/contracts/DbTx.ts +110 -0
  485. package/src/contracts/Delegation.ts +91 -0
  486. package/src/contracts/DeviceControl.ts +143 -0
  487. package/src/contracts/Directory.ts +384 -0
  488. package/src/contracts/DirectoryProvider.ts +82 -0
  489. package/src/contracts/DocumentSource.ts +71 -0
  490. package/src/contracts/Files.ts +395 -0
  491. package/src/contracts/Flags.ts +241 -0
  492. package/src/contracts/Host.ts +245 -0
  493. package/src/contracts/HttpApi.ts +100 -0
  494. package/src/contracts/Ingestion.ts +315 -0
  495. package/src/contracts/Ingress.ts +132 -0
  496. package/src/contracts/Invocation.ts +122 -0
  497. package/src/contracts/LocalClient.ts +620 -0
  498. package/src/contracts/Locale.ts +133 -0
  499. package/src/contracts/MachineIdentity.ts +305 -0
  500. package/src/contracts/MailProvider.ts +272 -0
  501. package/src/contracts/Memory.ts +47 -0
  502. package/src/contracts/Messaging.ts +108 -0
  503. package/src/contracts/Metering.ts +231 -0
  504. package/src/contracts/ModelProvider.ts +87 -0
  505. package/src/contracts/ModuleManifest.ts +310 -0
  506. package/src/contracts/NotificationChannel.ts +158 -0
  507. package/src/contracts/Notifications.ts +309 -0
  508. package/src/contracts/Outbox.ts +246 -0
  509. package/src/contracts/Privacy.ts +502 -0
  510. package/src/contracts/Progress.ts +196 -0
  511. package/src/contracts/QuerySurface.ts +134 -0
  512. package/src/contracts/Readiness.ts +67 -0
  513. package/src/contracts/Release.ts +199 -0
  514. package/src/contracts/ResultRendering.ts +65 -0
  515. package/src/contracts/Sandbox.ts +648 -0
  516. package/src/contracts/Scheduler.ts +237 -0
  517. package/src/contracts/ScreenContext.ts +316 -0
  518. package/src/contracts/Search.ts +126 -0
  519. package/src/contracts/Secrets.ts +162 -0
  520. package/src/contracts/Settings.ts +207 -0
  521. package/src/contracts/Sharing.ts +205 -0
  522. package/src/contracts/Slot.ts +61 -0
  523. package/src/contracts/Space.ts +157 -0
  524. package/src/contracts/StorageAdapter.ts +104 -0
  525. package/src/contracts/StorageBackend.ts +220 -0
  526. package/src/contracts/Sync.ts +180 -0
  527. package/src/contracts/Telemetry.ts +177 -0
  528. package/src/contracts/ThemeTokens.ts +136 -0
  529. package/src/contracts/ToolSource.ts +94 -0
  530. package/src/contracts/Versioning.ts +237 -0
  531. package/src/contracts/View.ts +116 -0
  532. package/src/contracts/WorkItems.ts +144 -0
  533. package/src/contracts/Workflow.ts +67 -0
  534. package/src/contracts/index.ts +205 -0
  535. package/src/devices/module.ts +201 -0
  536. package/src/drizzle/Entity.ts +524 -0
  537. package/src/index.ts +19 -0
@@ -0,0 +1,332 @@
1
+ /**
2
+ * Optimistic effects (decision "Data": each client keeps a policy-scoped partial replica with optimistic writes;
3
+ * criterion 6). An action may declare the change it predicts on the replica, so a client shows it before the
4
+ * server answers. The declaration is small and declarative, derived from the action's `writes` and `target`:
5
+ *
6
+ * - `insert`: a new record of the action's `writes` entity, its fields taken from the input, the acting user and
7
+ * organisation, the current time or constants. Its key is derived from a key the caller names in the input
8
+ * (`recordKey`), so the client and the kernel arrive at the same primary key and the confirmed row replaces the
9
+ * predicted one;
10
+ * - `update`: fields of the action's target record (or each of its targets) set from the input;
11
+ * - `delete`: the action's target record (or each of its targets) removed;
12
+ * - `custom`: a change the three kinds cannot describe (several rows, a computed field, a counter, a move between
13
+ * parents), predicted by the module's own code: a function in its `predictions.ts`, which `eloxiv generate` wires
14
+ * into the action's mutator. It may change only the tables of the entities the action declares (`writes`,
15
+ * `target`, `actsOn`) that sync, and runs only on the client's replica.
16
+ *
17
+ * The prediction is only a prediction. The kernel never runs it: the action's handler is the authority, through
18
+ * the one invocation path, and the replica replaces the prediction with the server's rows, or drops it when the
19
+ * call is refused. `eloxiv generate` writes each module's mutators from these declarations (`sync.gen.ts`); the
20
+ * client reaches them through `@eloxiv/client` only.
21
+ */
22
+ import { Schema } from "effect"
23
+ import type { AnyAction, AnyEntity } from "./Module.ts"
24
+
25
+ /** Where one predicted field's value comes from. */
26
+ export const OptimisticValue = Schema.Union([
27
+ /** The input field's encoded value; `default` when the caller left it out. */
28
+ Schema.Struct({ from: Schema.Literal("input"), field: Schema.String, default: Schema.optionalKey(Schema.Json) }),
29
+ /** The acting user's id or the acting organisation's. */
30
+ Schema.Struct({ from: Schema.Literal("actor"), field: Schema.Literals(["userId", "orgId"]) }),
31
+ /** The time on the client's clock, as sync carries instants (epoch milliseconds). */
32
+ Schema.Struct({ from: Schema.Literal("now") }),
33
+ /** A constant. */
34
+ Schema.Struct({ from: Schema.Literal("value"), value: Schema.Json }),
35
+ ])
36
+ export type OptimisticValue = typeof OptimisticValue.Type
37
+
38
+ /** The change an action predicts on the replica. */
39
+ export const OptimisticEffect = Schema.Union([
40
+ Schema.Struct({
41
+ kind: Schema.Literal("insert"),
42
+ /**
43
+ * The input field naming the new record's key: the record's primary key is `recordKey` of it, for the acting
44
+ * user and organisation (the kernel derives it on every surface; a caller that leaves it out gets a fresh one).
45
+ */
46
+ key: Schema.String,
47
+ /** Every synced field of the record but its primary key: where its value comes from. */
48
+ values: Schema.Record(Schema.String, OptimisticValue),
49
+ }),
50
+ /** The fields of the target record(s) the action sets. */
51
+ Schema.Struct({ kind: Schema.Literal("update"), set: Schema.Record(Schema.String, OptimisticValue) }),
52
+ Schema.Struct({ kind: Schema.Literal("delete") }),
53
+ /**
54
+ * The module predicts the change itself: its `predictions.ts` exports a function named like the action's local
55
+ * name, which may change only the synced tables of the entities the action declares (`predictedEntityNames`).
56
+ */
57
+ Schema.Struct({ kind: Schema.Literal("custom") }),
58
+ ])
59
+ export type OptimisticEffect = typeof OptimisticEffect.Type
60
+
61
+ /** Builders for an action's `optimistic` declaration. */
62
+ export const optimistic = {
63
+ /** The action inserts a record of its `writes` entity, keyed by `recordKey` of `input[key]`. */
64
+ insert: (spec: { readonly key: string; readonly values: Readonly<Record<string, OptimisticValue>> }) =>
65
+ ({ kind: "insert", key: spec.key, values: spec.values }) as const,
66
+ /** The action sets these fields of its target record(s). */
67
+ update: (spec: { readonly set: Readonly<Record<string, OptimisticValue>> }) =>
68
+ ({ kind: "update", set: spec.set }) as const,
69
+ /** The action deletes its target record(s). */
70
+ delete: () => ({ kind: "delete" }) as const,
71
+ /**
72
+ * The module predicts the change itself, for one the three kinds cannot describe: its `predictions.ts` exports a
73
+ * function named like the action (`wave` for `hello.wave`), which changes only the tables of the entities the
74
+ * action declares (`writes`, `target`, `actsOn`).
75
+ */
76
+ custom: () => ({ kind: "custom" }) as const,
77
+ /** An input field's value, or `fallback` when the caller left it out. */
78
+ input: (field: string, ...fallback: [] | [Schema.Json]): OptimisticValue =>
79
+ fallback.length === 0 ? { from: "input", field } : { from: "input", field, default: fallback[0] },
80
+ /** The acting user's or organisation's id. */
81
+ actor: (field: "userId" | "orgId"): OptimisticValue => ({ from: "actor", field }),
82
+ /** Now, in epoch milliseconds. */
83
+ now: (): OptimisticValue => ({ from: "now" }),
84
+ /** A constant. */
85
+ value: (value: Schema.Json): OptimisticValue => ({ from: "value", value }),
86
+ } as const
87
+
88
+ /**
89
+ * The entity a declarative optimistic effect changes: its `writes` entity for an insert, its target's for an update
90
+ * or a delete. A custom prediction may change several (`predictedEntityNames`), so it has none here.
91
+ */
92
+ export const optimisticEntityName = (action: AnyAction): string | undefined =>
93
+ action.optimistic === undefined || action.optimistic.kind === "custom"
94
+ ? undefined
95
+ : action.optimistic.kind === "insert"
96
+ ? action.writes
97
+ : action.target?.entity
98
+
99
+ /**
100
+ * The entities an action's prediction may change: for a custom prediction, every entity the action declares
101
+ * (`writes`, `target`, `actsOn`, once each, in that order), exactly the ones its policy reaches; for a declarative
102
+ * effect, the one it names (`optimisticEntityName`).
103
+ */
104
+ export const predictedEntityNames = (action: AnyAction): ReadonlyArray<string> => {
105
+ if (action.optimistic === undefined) return []
106
+ if (action.optimistic.kind !== "custom") {
107
+ const one = optimisticEntityName(action)
108
+ return one === undefined ? [] : [one]
109
+ }
110
+ const names = [action.writes, action.target?.entity, ...action.actsOn].filter((n): n is string => n !== undefined)
111
+ return [...new Set(names)]
112
+ }
113
+
114
+ /**
115
+ * Why an action's optimistic effect cannot be generated or would predict something other than what it says, as
116
+ * sentences naming the action (empty when it is sound): the entity it changes syncs, every field it sets is a
117
+ * synced field (never the primary key, which an insert derives and an update or delete takes from the target),
118
+ * an insert gives every field the replica cannot leave empty, and every input field it reads is in the input.
119
+ */
120
+ export const optimisticProblems = (
121
+ action: AnyAction,
122
+ entities: Readonly<Record<string, AnyEntity>>,
123
+ ): ReadonlyArray<string> => {
124
+ const effect = action.optimistic
125
+ if (effect === undefined) return []
126
+ const name = action.name
127
+ if (!Schema.is(OptimisticEffect)(effect)) {
128
+ return [`${name}: its optimistic effect is not an insert, update, delete or custom prediction`]
129
+ }
130
+ const problems: Array<string> = []
131
+ if (action.hints.readOnly) problems.push(`${name} is read-only, so it predicts no change`)
132
+ if (effect.kind === "custom") {
133
+ const declared = predictedEntityNames(action)
134
+ if (declared.length === 0) {
135
+ problems.push(
136
+ `${name} predicts a change of its own, so it must declare the entities it changes (writes, target or actsOn)`,
137
+ )
138
+ return problems
139
+ }
140
+ const known = declared.map((n) => entities[n]).filter((e): e is AnyEntity => e !== undefined)
141
+ if (known.length > 0 && known.every((e) => e.sync === false)) {
142
+ problems.push(`${name} predicts a change of its own, but none of the entities it declares syncs`)
143
+ }
144
+ return problems
145
+ }
146
+ const inputFields = (action.input as { readonly fields?: Readonly<Record<string, unknown>> }).fields
147
+ const inputHas = (field: string) => inputFields !== undefined && Object.hasOwn(inputFields, field)
148
+ const entityName = optimisticEntityName(action)
149
+ if (entityName === undefined) {
150
+ problems.push(
151
+ effect.kind === "insert"
152
+ ? `${name} predicts an insert, so it must declare the entity it writes (writes)`
153
+ : `${name} predicts ${effect.kind === "update" ? "an update" : "a delete"} of its target, so it must declare one (target)`,
154
+ )
155
+ return problems
156
+ }
157
+ const entity = entities[entityName]
158
+ if (entity === undefined) return problems
159
+ if (entity.sync === false) {
160
+ problems.push(`${name} predicts a change to ${entity.name}, which does not sync`)
161
+ return problems
162
+ }
163
+ const synced = new Set(entity.sync.fields)
164
+ const storage = entity.storage as Readonly<Record<string, AnyEntity["storage"][string]>>
165
+ const values = (record: Readonly<Record<string, OptimisticValue>>) => {
166
+ for (const [field, value] of Object.entries(record)) {
167
+ if (field === entity.primaryKey) {
168
+ problems.push(
169
+ `${name} sets ${entity.name}'s primary key ${field}, which ${effect.kind === "insert" ? "the kernel derives from the key" : "is the target"}`,
170
+ )
171
+ } else if (!synced.has(field)) {
172
+ problems.push(`${name} predicts ${entity.name} field ${field}, which ${entity.name} does not sync`)
173
+ }
174
+ if (value.from === "input" && !inputHas(value.field)) {
175
+ problems.push(`${name} predicts ${field} from input field ${value.field}, which its input does not have`)
176
+ }
177
+ if (value.from === "now" && storage[field] !== undefined && storage[field].type !== "number") {
178
+ problems.push(`${name} predicts ${field} as the time, but ${entity.name} stores it as ${storage[field].type}`)
179
+ }
180
+ }
181
+ }
182
+ if (effect.kind === "insert") {
183
+ if (!inputHas(effect.key))
184
+ problems.push(`${name}'s record key comes from input field ${effect.key}, which its input does not have`)
185
+ if (action.target !== undefined && action.target.field === effect.key) {
186
+ problems.push(`${name}'s record key ${effect.key} is also its target field`)
187
+ }
188
+ values(effect.values)
189
+ for (const field of synced) {
190
+ if (field === entity.primaryKey || Object.hasOwn(effect.values, field)) continue
191
+ if (storage[field] !== undefined && !storage[field].nullable) {
192
+ problems.push(`${name} predicts an insert without ${entity.name} field ${field}, which cannot be empty`)
193
+ }
194
+ }
195
+ } else if (effect.kind === "update") {
196
+ if (Object.keys(effect.set).length === 0) problems.push(`${name} predicts an update that sets nothing`)
197
+ values(effect.set)
198
+ }
199
+ return problems
200
+ }
201
+
202
+ /**
203
+ * What a caller may name as a record's key: 1 to 128 letters, digits, `_` or `-` (a UUID, a nanoid). The record's
204
+ * primary key is derived from it (`recordKey`), never taken from it.
205
+ */
206
+ export const RECORD_KEY_PATTERN = /^[A-Za-z0-9_-]{1,128}$/
207
+ export const isRecordKeyNonce = (value: unknown): value is string =>
208
+ typeof value === "string" && RECORD_KEY_PATTERN.test(value)
209
+
210
+ /**
211
+ * The primary key of the record an insert creates from a key the caller named: a UUID (version 8, RFC 9562) from
212
+ * SHA-256 of the acting organisation, the acting user, the entity's Cedar type and the key. The client computes it
213
+ * for its prediction and the kernel for the handler, so both arrive at the same record. A caller can never choose a
214
+ * record's key outright: the same key named by another user, in another organisation or for another entity is
215
+ * another record, so no insert can collide with (and so disclose) a record the caller did not create itself.
216
+ */
217
+ export const recordKey = (
218
+ actor: { readonly orgId: string; readonly userId: string },
219
+ cedarType: string,
220
+ nonce: string,
221
+ ): string => {
222
+ if (!isRecordKeyNonce(nonce)) {
223
+ throw new Error(`A record key must be 1 to 128 letters, digits, _ or -, not ${JSON.stringify(nonce)}`)
224
+ }
225
+ const digest = sha256Bytes(
226
+ utf8Bytes(JSON.stringify(["eloxiv.record-key.v1", actor.orgId, actor.userId, cedarType, nonce])),
227
+ )
228
+ const bytes = digest.slice(0, 16)
229
+ bytes[6] = (bytes[6]! & 0x0f) | 0x80
230
+ bytes[8] = (bytes[8]! & 0x3f) | 0x80
231
+ const hex = [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("")
232
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
233
+ }
234
+
235
+ /** A fresh key for `recordKey`: 22 random letters, digits, `_` and `-` (132 bits). */
236
+ export const newRecordKeyNonce = (): string => {
237
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
238
+ const random = new Uint8Array(22)
239
+ // Web Crypto where the runtime has it (React Native may not); a key only has to be unique, not secret.
240
+ const source = (globalThis as { crypto?: { getRandomValues?: (array: Uint8Array) => Uint8Array } }).crypto
241
+ if (typeof source?.getRandomValues === "function") source.getRandomValues(random)
242
+ else for (let i = 0; i < random.length; i++) random[i] = Math.floor(Math.random() * 256)
243
+ return [...random].map((b) => alphabet[b & 63]).join("")
244
+ }
245
+
246
+ const K = new Uint32Array([
247
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98,
248
+ 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
249
+ 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8,
250
+ 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
251
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
252
+ 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
253
+ 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7,
254
+ 0xc67178f2,
255
+ ])
256
+
257
+ /**
258
+ * A string's UTF-8 bytes, as `TextEncoder` gives them (a lone surrogate becomes U+FFFD), in plain JavaScript: the
259
+ * contracts compile and run without the DOM's or Node's globals (React Native's typecheck has no `TextEncoder`).
260
+ */
261
+ export const utf8Bytes = (text: string): Uint8Array => {
262
+ const out: Array<number> = []
263
+ for (let i = 0; i < text.length; i++) {
264
+ let code = text.charCodeAt(i)
265
+ if (code >= 0xd800 && code <= 0xdbff) {
266
+ const next = i + 1 < text.length ? text.charCodeAt(i + 1) : 0
267
+ if (next >= 0xdc00 && next <= 0xdfff) {
268
+ code = 0x10000 + ((code - 0xd800) << 10) + (next - 0xdc00)
269
+ i++
270
+ } else code = 0xfffd
271
+ } else if (code >= 0xdc00 && code <= 0xdfff) code = 0xfffd
272
+ if (code < 0x80) out.push(code)
273
+ else if (code < 0x800) out.push(0xc0 | (code >> 6), 0x80 | (code & 0x3f))
274
+ else if (code < 0x10000) out.push(0xe0 | (code >> 12), 0x80 | ((code >> 6) & 0x3f), 0x80 | (code & 0x3f))
275
+ else out.push(0xf0 | (code >> 18), 0x80 | ((code >> 12) & 0x3f), 0x80 | ((code >> 6) & 0x3f), 0x80 | (code & 0x3f))
276
+ }
277
+ return Uint8Array.from(out)
278
+ }
279
+
280
+ /**
281
+ * SHA-256 (FIPS 180-4), synchronously and in plain JavaScript: a prediction runs inside Zero's mutator on every
282
+ * runtime the client SDK supports (React Native's Hermes has no `crypto.subtle`), and must give the kernel's answer.
283
+ */
284
+ export const sha256Bytes = (message: Uint8Array): Uint8Array => {
285
+ const length = message.length
286
+ const padded = new Uint8Array(((length + 9 + 63) >> 6) << 6)
287
+ padded.set(message)
288
+ padded[length] = 0x80
289
+ const view = new DataView(padded.buffer)
290
+ view.setUint32(padded.length - 8, Math.floor(length / 0x20000000))
291
+ view.setUint32(padded.length - 4, (length << 3) >>> 0)
292
+ const h = new Uint32Array([
293
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
294
+ ])
295
+ const w = new Uint32Array(64)
296
+ const rotr = (x: number, n: number) => (x >>> n) | (x << (32 - n))
297
+ for (let offset = 0; offset < padded.length; offset += 64) {
298
+ for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4)
299
+ for (let i = 16; i < 64; i++) {
300
+ const a = w[i - 15]!
301
+ const b = w[i - 2]!
302
+ const s0 = rotr(a, 7) ^ rotr(a, 18) ^ (a >>> 3)
303
+ const s1 = rotr(b, 17) ^ rotr(b, 19) ^ (b >>> 10)
304
+ w[i] = (w[i - 16]! + s0 + w[i - 7]! + s1) >>> 0
305
+ }
306
+ let [a, b, c, d, e, f, g, hh] = h as unknown as [number, number, number, number, number, number, number, number]
307
+ for (let i = 0; i < 64; i++) {
308
+ const t1 = (hh + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + ((e & f) ^ (~e & g)) + K[i]! + w[i]!) >>> 0
309
+ const t2 = ((rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + ((a & b) ^ (a & c) ^ (b & c))) >>> 0
310
+ hh = g
311
+ g = f
312
+ f = e
313
+ e = (d + t1) >>> 0
314
+ d = c
315
+ c = b
316
+ b = a
317
+ a = (t1 + t2) >>> 0
318
+ }
319
+ h[0] = (h[0]! + a) >>> 0
320
+ h[1] = (h[1]! + b) >>> 0
321
+ h[2] = (h[2]! + c) >>> 0
322
+ h[3] = (h[3]! + d) >>> 0
323
+ h[4] = (h[4]! + e) >>> 0
324
+ h[5] = (h[5]! + f) >>> 0
325
+ h[6] = (h[6]! + g) >>> 0
326
+ h[7] = (h[7]! + hh) >>> 0
327
+ }
328
+ const out = new Uint8Array(32)
329
+ const outView = new DataView(out.buffer)
330
+ for (let i = 0; i < 8; i++) outView.setUint32(i * 4, h[i]!)
331
+ return out
332
+ }
@@ -0,0 +1,207 @@
1
+ /**
2
+ * The action registry's projection: one action definition becomes the schema
3
+ * every surface publishes (decisions.md "One action registry is the source of
4
+ * truth"). Surfaces take the action's input as raw JSON documented with this
5
+ * input schema (the invocation path decodes it), and return the result
6
+ * envelope `{ kind: "output", output } | { kind: "replay", receipt }`.
7
+ */
8
+ import { Schema } from "effect"
9
+ import { InvocationError } from "./Errors.ts"
10
+ import { toJsonSchema } from "./JsonSchema.ts"
11
+ import { toolName, type AnyAction } from "./Module.ts"
12
+ import { actionResult } from "./Receipt.ts"
13
+
14
+ /** Where the HTTP surface serves each action: `POST <prefix>/<action>`. */
15
+ export const HTTP_ACTIONS_PREFIX = "/api/actions"
16
+
17
+ /**
18
+ * The read batch (`POST /api/batch`): up to `READ_BATCH_MAX_ITEMS` read-only actions in one request, each run
19
+ * through the invocation path on its own (its own identity, policy, audit and failure), answered in order. It is a
20
+ * transport, not an action: it is no tool and appears in no catalogue.
21
+ */
22
+ export const READ_BATCH_PATH = "/api/batch"
23
+ export const READ_BATCH_MAX_ITEMS = 25
24
+
25
+ export const ReadBatchRequest = Schema.Struct({
26
+ items: Schema.Array(Schema.Struct({ action: Schema.String, input: Schema.Unknown })),
27
+ })
28
+ export type ReadBatchRequest = typeof ReadBatchRequest.Type
29
+
30
+ /** One item's answer: its result envelope, or the error and the HTTP status it would have had on its own. */
31
+ export type ReadBatchItemResult =
32
+ | { readonly ok: true; readonly result: unknown }
33
+ | {
34
+ readonly ok: false
35
+ readonly status: number
36
+ readonly error: { readonly _tag: string; readonly message?: string; readonly [field: string]: unknown }
37
+ }
38
+
39
+ /**
40
+ * WebMCP (browser agents, `navigator.modelContext`): a person's own session asks for a short-lived agent session for
41
+ * the browser agent (`session`), every call of which is the agent's on the kernel (consent, agent tool groups and
42
+ * person-only actions apply); the agent session lists the tools it reaches (`tools`, the compatibility manifest),
43
+ * each called on its HTTP route; `revoke` ends it.
44
+ */
45
+ export const WEBMCP_PATHS = {
46
+ session: "/api/webmcp/session",
47
+ revoke: "/api/webmcp/session/revoke",
48
+ tools: "/api/webmcp/tools",
49
+ } as const
50
+
51
+ /**
52
+ * The kernel's MCP server identity (`GET /.well-known/mcp.json`, public): its canonical name (what MCP hosts, the
53
+ * CLI and a settings page list it as), its endpoint and OAuth resource, and where to discover how to sign in. Every
54
+ * client that connects an MCP host reads the name from here rather than making one up.
55
+ */
56
+ export const MCP_IDENTITY_PATH = "/.well-known/mcp.json"
57
+
58
+ export interface McpServerIdentity {
59
+ readonly name: string
60
+ readonly title: string
61
+ readonly version: string
62
+ /** The streamable-HTTP endpoint. */
63
+ readonly endpoint: string
64
+ /** The OAuth resource (RFC 8707) a token for it is bound to. */
65
+ readonly resource: string
66
+ /** Its protected resource metadata (RFC 9728), which names the authorisation server. */
67
+ readonly resourceMetadata: string
68
+ readonly transport: "streamable-http"
69
+ }
70
+
71
+ /** An app's MCP server name: its name with anything but letters, digits and `._-` as `-`. */
72
+ export const mcpServerName = (appName: string) => appName.replace(/[^A-Za-z0-9._-]/g, "-")
73
+
74
+ /** One tool of the WebMCP manifest: an action an agent session reaches, called at `path`. */
75
+ export interface WebMcpToolManifest {
76
+ readonly name: string
77
+ readonly description: string
78
+ readonly inputSchema: Record<string, unknown>
79
+ readonly readOnly: boolean
80
+ readonly destructive: boolean
81
+ /** Agent calls of it are held for the person's consent (`ConsentRequired`) unless a remembered permission covers them. */
82
+ readonly consent: boolean
83
+ /** Its HTTP route (`POST`). */
84
+ readonly path: string
85
+ }
86
+
87
+ /** The HTTP status each invocation error is answered with, on its own or as a batch item. */
88
+ export const INVOCATION_ERROR_STATUS: Readonly<Record<InvocationError["_tag"], number>> = {
89
+ Unauthenticated: 401,
90
+ Forbidden: 403,
91
+ ApprovalRequired: 409,
92
+ ConsentRequired: 409,
93
+ IdempotencyConflict: 422,
94
+ InvalidInput: 400,
95
+ UnknownAction: 404,
96
+ ActionFailed: 500,
97
+ ClientOutdated: 426,
98
+ }
99
+
100
+ /** A JSON Schema document (draft 2020-12). */
101
+ export const JsonSchemaObject = Schema.Record(Schema.String, Schema.Unknown)
102
+
103
+ /** One registered action, as the registry lists it. */
104
+ export const ActionDescriptor = Schema.Struct({
105
+ name: Schema.String,
106
+ module: Schema.String,
107
+ /** What people see the action called (`ActionContract.title`). */
108
+ title: Schema.String,
109
+ description: Schema.String,
110
+ /** The action's id in its module's Cedar namespace (`<Namespace>::Action::"<id>"`). */
111
+ cedarAction: Schema.String,
112
+ /** The name MCP and agent tools use (`hello.greet` -> `hello_greet`). */
113
+ toolName: Schema.String,
114
+ writes: Schema.NullOr(Schema.String),
115
+ target: Schema.NullOr(Schema.Struct({ entity: Schema.String, field: Schema.String })),
116
+ bestEffort: Schema.Boolean,
117
+ hints: Schema.Struct({ readOnly: Schema.Boolean, destructive: Schema.Boolean, idempotent: Schema.Boolean }),
118
+ /** An agent acting for a person needs the person's consent for each call (ActionConsent). */
119
+ consent: Schema.Boolean,
120
+ /** Which surfaces offer the action: the app's agent, MCP, the API (typed client, HTTP, CLI, sync). */
121
+ exposure: Schema.Struct({ agent: Schema.Boolean, mcp: Schema.Boolean, api: Schema.Boolean }),
122
+ input: JsonSchemaObject,
123
+ output: JsonSchemaObject,
124
+ /** What every surface returns: the output envelope or a replay receipt. */
125
+ result: JsonSchemaObject,
126
+ })
127
+ export type ActionDescriptor = typeof ActionDescriptor.Type
128
+
129
+ /**
130
+ * What each surface publishes for one action. Every input schema is the action's input (MCP's wrapped in an
131
+ * object root when it has none, see `mcpToolInput`); every result the envelope.
132
+ */
133
+ export const SurfaceProjection = Schema.Struct({
134
+ rpc: Schema.Struct({
135
+ tag: Schema.String,
136
+ payload: JsonSchemaObject,
137
+ success: JsonSchemaObject,
138
+ error: JsonSchemaObject,
139
+ }),
140
+ http: Schema.Struct({
141
+ method: Schema.Literal("POST"),
142
+ path: Schema.String,
143
+ requestBody: JsonSchemaObject,
144
+ response: JsonSchemaObject,
145
+ }),
146
+ mcp: Schema.Struct({
147
+ name: Schema.String,
148
+ description: Schema.String,
149
+ inputSchema: JsonSchemaObject,
150
+ outputSchema: JsonSchemaObject,
151
+ }),
152
+ agent: Schema.Struct({ name: Schema.String, description: Schema.String, inputSchema: JsonSchemaObject }),
153
+ })
154
+ export type SurfaceProjection = typeof SurfaceProjection.Type
155
+
156
+ export const describeAction = (action: AnyAction, module: string): ActionDescriptor => ({
157
+ name: action.name,
158
+ module,
159
+ title: action.title,
160
+ description: action.description,
161
+ cedarAction: action.cedarAction,
162
+ toolName: toolName(action.name),
163
+ writes: action.writes ?? null,
164
+ target: action.target === undefined ? null : { entity: action.target.entity, field: action.target.field },
165
+ bestEffort: action.bestEffort,
166
+ hints: { ...action.hints },
167
+ consent: action.consent,
168
+ exposure: { ...action.exposure },
169
+ input: toJsonSchema(action.input),
170
+ output: toJsonSchema(action.output),
171
+ result: toJsonSchema(actionResult(action)),
172
+ })
173
+
174
+ /**
175
+ * An action's input schema as MCP tool parameters. MCP requires an object-rooted JSON Schema (tool arguments
176
+ * are always an object); an input whose schema is not (`Schema.Struct({})` emits `{ not: { type: "null" } }`)
177
+ * is wrapped as `{ type: "object", allOf: [schema] }`, so its constraints are still documented. Object-rooted
178
+ * inputs are returned unchanged.
179
+ */
180
+ export const mcpToolInput = (input: Record<string, unknown>): Record<string, unknown> => {
181
+ if (input["type"] === "object") return input
182
+ const { $schema: dialect, $defs: definitions, ...schema } = input
183
+ return {
184
+ ...(dialect === undefined ? {} : { $schema: dialect }),
185
+ type: "object",
186
+ allOf: [schema],
187
+ ...(definitions === undefined ? {} : { $defs: definitions }),
188
+ }
189
+ }
190
+
191
+ /** The schema each surface publishes for `action`, derived only from its definition. */
192
+ export const projectAction = (action: AnyAction): SurfaceProjection => {
193
+ const input = toJsonSchema(action.input)
194
+ const result = toJsonSchema(actionResult(action))
195
+ return {
196
+ rpc: { tag: action.name, payload: input, success: result, error: toJsonSchema(InvocationError) },
197
+ http: { method: "POST", path: `${HTTP_ACTIONS_PREFIX}/${action.name}`, requestBody: input, response: result },
198
+ mcp: {
199
+ name: toolName(action.name),
200
+ description: action.description,
201
+ inputSchema: mcpToolInput(input),
202
+ outputSchema: result,
203
+ },
204
+ // Object-rooted as MCP's: model providers refuse a function whose parameters are not an object.
205
+ agent: { name: toolName(action.name), description: action.description, inputSchema: mcpToolInput(input) },
206
+ }
207
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Proposals (the Approvals contract, "Proposals"; ledger A-110): grouped edits someone (a person, or their agent)
3
+ * proposes for others to review. Each item is a proposed call of one action with its input (the edit), decided on
4
+ * its own (accepted or rejected); a decision is made on an exact observed set of items at once, all or none; an
5
+ * accepted item is applied by its decider making the proposed call through the invocation path (as themselves, so
6
+ * the policy decides whether they may), under the item's key, and recorded applied only once the kernel finds that
7
+ * call's committed receipt. The review screens that present proposals are deferred (decision 12).
8
+ */
9
+ import { Schema } from "effect"
10
+
11
+ export const PROPOSALS_ACTIONS = {
12
+ create: "proposals.create",
13
+ revise: "proposals.revise",
14
+ withdraw: "proposals.withdraw",
15
+ get: "proposals.get",
16
+ decide: "proposals.decide",
17
+ applied: "proposals.applied",
18
+ } as const
19
+
20
+ export const ProposalItemStatus = Schema.Literals(["pending", "accepted", "rejected", "applied", "withdrawn"])
21
+ export type ProposalItemStatus = typeof ProposalItemStatus.Type
22
+
23
+ export const ProposalItemInput = Schema.Struct({
24
+ summary: Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(500)),
25
+ /** The action the edit is a call of (`notes.rename`). */
26
+ action: Schema.String,
27
+ /** Its input, as the action takes it (JSON). */
28
+ input: Schema.Unknown,
29
+ })
30
+ export type ProposalItemInput = typeof ProposalItemInput.Type
31
+
32
+ export const ProposalCreate = Schema.Struct({
33
+ summary: Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(500)),
34
+ items: Schema.Array(ProposalItemInput).check(Schema.isMinLength(1), Schema.isMaxLength(100)),
35
+ /** The same key from the same person in the same organisation gives back the proposal it first made. */
36
+ creationKey: Schema.optionalKey(Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(200))),
37
+ })
38
+
39
+ export const ProposalItem = Schema.Struct({
40
+ id: Schema.String,
41
+ ordinal: Schema.Number,
42
+ summary: Schema.String,
43
+ action: Schema.String,
44
+ input: Schema.Unknown,
45
+ /** Raised by every revision: a decision names the revision it saw. */
46
+ revision: Schema.Number,
47
+ status: ProposalItemStatus,
48
+ decidedBy: Schema.NullOr(Schema.String),
49
+ /** The invocation that applied it (`applied` only). */
50
+ appliedInvocation: Schema.NullOr(Schema.String),
51
+ /** The idempotency key its decider applies it under (`proposal-item:<id>:<revision>`). */
52
+ applyKey: Schema.String,
53
+ })
54
+ export type ProposalItem = typeof ProposalItem.Type
55
+
56
+ export const Proposal = Schema.Struct({
57
+ id: Schema.String,
58
+ authorId: Schema.String,
59
+ summary: Schema.String,
60
+ status: Schema.Literals(["open", "withdrawn"]),
61
+ items: Schema.Array(ProposalItem),
62
+ })
63
+ export type Proposal = typeof Proposal.Type
64
+
65
+ export const ProposalRef = Schema.Struct({ id: Schema.String })
66
+
67
+ export const ProposalRevise = Schema.Struct({
68
+ item: Schema.String,
69
+ input: Schema.Unknown,
70
+ summary: Schema.optionalKey(Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(500))),
71
+ })
72
+
73
+ export const ProposalDecide = Schema.Struct({
74
+ proposal: Schema.String,
75
+ /** The exact set decided: each item with the revision the decider saw. All are decided, or none. */
76
+ decisions: Schema.Array(
77
+ Schema.Struct({
78
+ item: Schema.String,
79
+ decision: Schema.Literals(["accept", "reject"]),
80
+ observedRevision: Schema.Number,
81
+ }),
82
+ ).check(Schema.isMinLength(1)),
83
+ })
84
+
85
+ export const ProposalApplied = Schema.Struct({ item: Schema.String })
86
+
87
+ /** The idempotency key an accepted item is applied under. */
88
+ export const proposalApplyKey = (item: { readonly id: string; readonly revision: number }) =>
89
+ `proposal-item:${item.id}:${item.revision}`