@segmentstream/ontology 0.0.0-stage → 0.92.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 (483) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +2 -0
  3. package/README.md +1655 -2
  4. package/dist/action.d.ts +193 -0
  5. package/dist/action.js +41 -0
  6. package/dist/agent-chat.d.ts +44 -0
  7. package/dist/agent-chat.js +91 -0
  8. package/dist/agent-task-contract.d.ts +64 -0
  9. package/dist/agent-task-contract.js +15 -0
  10. package/dist/agent-task.d.ts +39 -0
  11. package/dist/agent-task.js +112 -0
  12. package/dist/analyze.d.ts +215 -0
  13. package/dist/analyze.js +2438 -0
  14. package/dist/app-feedback.d.ts +167 -0
  15. package/dist/app-feedback.js +176 -0
  16. package/dist/authoring-input.d.ts +3 -0
  17. package/dist/authoring-input.js +107 -0
  18. package/dist/authoring-names.d.ts +4 -0
  19. package/dist/authoring-names.js +13 -0
  20. package/dist/authoring-records.d.ts +35 -0
  21. package/dist/authoring-records.js +264 -0
  22. package/dist/authoring.d.ts +15 -0
  23. package/dist/authoring.js +331 -0
  24. package/dist/bin/check.d.ts +30 -0
  25. package/dist/bin/check.js +99 -0
  26. package/dist/bin/load.d.ts +48 -0
  27. package/dist/bin/load.js +139 -0
  28. package/dist/bin/main.d.ts +31 -0
  29. package/dist/bin/main.js +121 -0
  30. package/dist/bin/migrate.d.ts +57 -0
  31. package/dist/bin/migrate.js +170 -0
  32. package/dist/bin/output.d.ts +31 -0
  33. package/dist/bin/output.js +84 -0
  34. package/dist/bin.d.ts +2 -0
  35. package/dist/bin.js +31 -0
  36. package/dist/blob.d.ts +52 -0
  37. package/dist/blob.js +87 -0
  38. package/dist/channel-session.d.ts +16 -0
  39. package/dist/channel-session.js +16 -0
  40. package/dist/chat.d.ts +43 -0
  41. package/dist/chat.js +34 -0
  42. package/dist/confirmation.d.ts +46 -0
  43. package/dist/confirmation.js +41 -0
  44. package/dist/connection.d.ts +213 -0
  45. package/dist/connection.js +289 -0
  46. package/dist/deployment.d.ts +35 -0
  47. package/dist/deployment.js +76 -0
  48. package/dist/diagnostics.d.ts +27 -0
  49. package/dist/diagnostics.js +106 -0
  50. package/dist/emails.d.ts +70 -0
  51. package/dist/emails.js +221 -0
  52. package/dist/entity.d.ts +331 -0
  53. package/dist/entity.js +153 -0
  54. package/dist/errors.d.ts +154 -0
  55. package/dist/errors.js +109 -0
  56. package/dist/feedback-config.d.ts +24 -0
  57. package/dist/feedback-config.js +126 -0
  58. package/dist/files.d.ts +39 -0
  59. package/dist/files.js +4 -0
  60. package/dist/groups.d.ts +95 -0
  61. package/dist/groups.js +280 -0
  62. package/dist/index.d.ts +109 -0
  63. package/dist/index.js +70 -0
  64. package/dist/internal/diagnostics.js +594 -0
  65. package/dist/legacy.d.ts +160 -0
  66. package/dist/legacy.js +270 -0
  67. package/dist/manifest-compatibility.d.ts +8 -0
  68. package/dist/manifest-compatibility.js +87 -0
  69. package/dist/manifest.d.ts +3329 -0
  70. package/dist/manifest.js +757 -0
  71. package/dist/me.d.ts +46 -0
  72. package/dist/me.js +109 -0
  73. package/dist/metric-filters.d.ts +48 -0
  74. package/dist/metric-filters.js +252 -0
  75. package/dist/metric-routes.d.ts +132 -0
  76. package/dist/metric-routes.js +498 -0
  77. package/dist/metric.d.ts +172 -0
  78. package/dist/metric.js +132 -0
  79. package/dist/migrate/apply.d.ts +94 -0
  80. package/dist/migrate/apply.js +526 -0
  81. package/dist/migrate/errors.d.ts +46 -0
  82. package/dist/migrate/errors.js +38 -0
  83. package/dist/migrate/index.d.ts +10 -0
  84. package/dist/migrate/index.js +7 -0
  85. package/dist/migrate/model.d.ts +2311 -0
  86. package/dist/migrate/model.js +148 -0
  87. package/dist/migrate/plan.d.ts +51 -0
  88. package/dist/migrate/plan.js +1856 -0
  89. package/dist/migrate/preview.d.ts +13 -0
  90. package/dist/migrate/preview.js +65 -0
  91. package/dist/migrate/storage.d.ts +226 -0
  92. package/dist/migrate/storage.js +774 -0
  93. package/dist/model-metrics.d.ts +22 -0
  94. package/dist/model-metrics.js +545 -0
  95. package/dist/names.d.ts +49 -0
  96. package/dist/names.js +110 -0
  97. package/dist/navigation-artifact.d.ts +13 -0
  98. package/dist/navigation-artifact.js +11 -0
  99. package/dist/navigation-catalog.d.ts +55 -0
  100. package/dist/navigation-catalog.js +297 -0
  101. package/dist/nitro-navigation.d.ts +3 -0
  102. package/dist/nitro-navigation.js +64 -0
  103. package/dist/nitro-workflows.d.ts +108 -0
  104. package/dist/nitro-workflows.js +286 -0
  105. package/dist/nitro.d.ts +40 -0
  106. package/dist/nitro.js +50 -0
  107. package/dist/ontology.d.ts +41 -0
  108. package/dist/ontology.js +46 -0
  109. package/dist/permissions.d.ts +198 -0
  110. package/dist/permissions.js +272 -0
  111. package/dist/property.d.ts +188 -0
  112. package/dist/property.js +301 -0
  113. package/dist/query.d.ts +245 -0
  114. package/dist/query.js +615 -0
  115. package/dist/relationship.d.ts +99 -0
  116. package/dist/relationship.js +33 -0
  117. package/dist/render.d.ts +81 -0
  118. package/dist/render.js +512 -0
  119. package/dist/replication/baseline.d.ts +51 -0
  120. package/dist/replication/baseline.js +215 -0
  121. package/dist/replication/bigquery.d.ts +37 -0
  122. package/dist/replication/bigquery.js +211 -0
  123. package/dist/replication/coverage.d.ts +14 -0
  124. package/dist/replication/coverage.js +53 -0
  125. package/dist/replication/evolution.d.ts +25 -0
  126. package/dist/replication/evolution.js +184 -0
  127. package/dist/replication/identities.d.ts +6 -0
  128. package/dist/replication/identities.js +47 -0
  129. package/dist/replication/legacy-baseline.d.ts +27 -0
  130. package/dist/replication/legacy-baseline.js +109 -0
  131. package/dist/replication/legacy-store.d.ts +19 -0
  132. package/dist/replication/legacy-store.js +63 -0
  133. package/dist/replication/lineage.d.ts +36 -0
  134. package/dist/replication/lineage.js +72 -0
  135. package/dist/replication/migrate.d.ts +21 -0
  136. package/dist/replication/migrate.js +84 -0
  137. package/dist/replication/model.d.ts +52 -0
  138. package/dist/replication/model.js +99 -0
  139. package/dist/replication/scans.d.ts +34 -0
  140. package/dist/replication/scans.js +158 -0
  141. package/dist/replication/schema.d.ts +11 -0
  142. package/dist/replication/schema.js +226 -0
  143. package/dist/replication/shadow-schema.d.ts +4 -0
  144. package/dist/replication/shadow-schema.js +61 -0
  145. package/dist/replication/shadow.d.ts +127 -0
  146. package/dist/replication/shadow.js +614 -0
  147. package/dist/replication/source-replacement.d.ts +33 -0
  148. package/dist/replication/source-replacement.js +76 -0
  149. package/dist/replication/store.d.ts +36 -0
  150. package/dist/replication/store.js +382 -0
  151. package/dist/replication/transaction.d.ts +23 -0
  152. package/dist/replication/transaction.js +88 -0
  153. package/dist/role.d.ts +61 -0
  154. package/dist/role.js +76 -0
  155. package/dist/runtime/action-deadlocks.d.ts +21 -0
  156. package/dist/runtime/action-deadlocks.js +130 -0
  157. package/dist/runtime/action-transactions.d.ts +35 -0
  158. package/dist/runtime/action-transactions.js +54 -0
  159. package/dist/runtime/agent-counters.d.ts +26 -0
  160. package/dist/runtime/agent-counters.js +98 -0
  161. package/dist/runtime/agent-tasks.d.ts +63 -0
  162. package/dist/runtime/agent-tasks.js +120 -0
  163. package/dist/runtime/agents.d.ts +15 -0
  164. package/dist/runtime/agents.js +457 -0
  165. package/dist/runtime/batch-diagnostics.d.ts +22 -0
  166. package/dist/runtime/batch-diagnostics.js +89 -0
  167. package/dist/runtime/batch.d.ts +52 -0
  168. package/dist/runtime/batch.js +534 -0
  169. package/dist/runtime/channel-session-revocation.d.ts +3 -0
  170. package/dist/runtime/channel-session-revocation.js +5 -0
  171. package/dist/runtime/channel-sessions.d.ts +4 -0
  172. package/dist/runtime/channel-sessions.js +61 -0
  173. package/dist/runtime/confirmations.d.ts +29 -0
  174. package/dist/runtime/confirmations.js +57 -0
  175. package/dist/runtime/cursor.d.ts +23 -0
  176. package/dist/runtime/cursor.js +100 -0
  177. package/dist/runtime/deployment.d.ts +7 -0
  178. package/dist/runtime/deployment.js +4 -0
  179. package/dist/runtime/errors.d.ts +118 -0
  180. package/dist/runtime/errors.js +109 -0
  181. package/dist/runtime/federation-tables.d.ts +2 -0
  182. package/dist/runtime/federation-tables.js +20 -0
  183. package/dist/runtime/federation.d.ts +42 -0
  184. package/dist/runtime/federation.js +222 -0
  185. package/dist/runtime/files.d.ts +39 -0
  186. package/dist/runtime/files.js +44 -0
  187. package/dist/runtime/generated-actions.d.ts +37 -0
  188. package/dist/runtime/generated-actions.js +307 -0
  189. package/dist/runtime/history.d.ts +91 -0
  190. package/dist/runtime/history.js +77 -0
  191. package/dist/runtime/ids.d.ts +6 -0
  192. package/dist/runtime/ids.js +39 -0
  193. package/dist/runtime/member-tables.d.ts +8 -0
  194. package/dist/runtime/member-tables.js +33 -0
  195. package/dist/runtime/member-writes.d.ts +78 -0
  196. package/dist/runtime/member-writes.js +202 -0
  197. package/dist/runtime/metric-query.d.ts +19 -0
  198. package/dist/runtime/metric-query.js +411 -0
  199. package/dist/runtime/model.d.ts +67 -0
  200. package/dist/runtime/model.js +150 -0
  201. package/dist/runtime/new-user-hook.d.ts +6 -0
  202. package/dist/runtime/new-user-hook.js +37 -0
  203. package/dist/runtime/oauth.d.ts +9 -0
  204. package/dist/runtime/oauth.js +299 -0
  205. package/dist/runtime/pipeline.d.ts +155 -0
  206. package/dist/runtime/pipeline.js +597 -0
  207. package/dist/runtime/postgres-tls.d.ts +10 -0
  208. package/dist/runtime/postgres-tls.js +14 -0
  209. package/dist/runtime/principals.d.ts +302 -0
  210. package/dist/runtime/principals.js +1307 -0
  211. package/dist/runtime/reads.d.ts +55 -0
  212. package/dist/runtime/reads.js +313 -0
  213. package/dist/runtime/records.d.ts +42 -0
  214. package/dist/runtime/records.js +245 -0
  215. package/dist/runtime/resolve-agent-identity.d.ts +6 -0
  216. package/dist/runtime/resolve-agent-identity.js +181 -0
  217. package/dist/runtime/service-binding.d.ts +18 -0
  218. package/dist/runtime/service-binding.js +266 -0
  219. package/dist/runtime/sign-in-links.d.ts +68 -0
  220. package/dist/runtime/sign-in-links.js +147 -0
  221. package/dist/runtime/sql-runtime.d.ts +131 -0
  222. package/dist/runtime/sql-runtime.js +362 -0
  223. package/dist/runtime/statement.d.ts +18 -0
  224. package/dist/runtime/statement.js +31 -0
  225. package/dist/runtime/user-identities.d.ts +66 -0
  226. package/dist/runtime/user-identities.js +106 -0
  227. package/dist/runtime/user-identity-sql.d.ts +86 -0
  228. package/dist/runtime/user-identity-sql.js +297 -0
  229. package/dist/runtime/user-roles.d.ts +16 -0
  230. package/dist/runtime/user-roles.js +32 -0
  231. package/dist/runtime/validation.d.ts +16 -0
  232. package/dist/runtime/validation.js +26 -0
  233. package/dist/runtime/where.d.ts +57 -0
  234. package/dist/runtime/where.js +404 -0
  235. package/dist/runtime/workflow-admission.d.ts +49 -0
  236. package/dist/runtime/workflow-admission.js +92 -0
  237. package/dist/runtime/workflow-argument-codec.d.ts +10 -0
  238. package/dist/runtime/workflow-argument-codec.js +120 -0
  239. package/dist/runtime/workflow-arguments.d.ts +17 -0
  240. package/dist/runtime/workflow-arguments.js +99 -0
  241. package/dist/runtime/workflow-starts.d.ts +203 -0
  242. package/dist/runtime/workflow-starts.js +493 -0
  243. package/dist/runtime/workflow-users.d.ts +9 -0
  244. package/dist/runtime/workflow-users.js +17 -0
  245. package/dist/runtime/workload.d.ts +25 -0
  246. package/dist/runtime/workload.js +24 -0
  247. package/dist/runtime/writes.d.ts +108 -0
  248. package/dist/runtime/writes.js +491 -0
  249. package/dist/runtime-source.d.ts +22 -0
  250. package/dist/runtime-source.js +28 -0
  251. package/dist/runtime.d.ts +310 -0
  252. package/dist/runtime.js +31 -0
  253. package/dist/server.d.ts +23 -0
  254. package/dist/server.js +107 -0
  255. package/dist/service/agent/attachments.d.ts +33 -0
  256. package/dist/service/agent/attachments.js +228 -0
  257. package/dist/service/agent/authentication.d.ts +22 -0
  258. package/dist/service/agent/authentication.js +58 -0
  259. package/dist/service/agent/confirmations.d.ts +5 -0
  260. package/dist/service/agent/confirmations.js +73 -0
  261. package/dist/service/agent/conversation-routes.d.ts +14 -0
  262. package/dist/service/agent/conversation-routes.js +45 -0
  263. package/dist/service/agent/conversations.d.ts +40 -0
  264. package/dist/service/agent/conversations.js +69 -0
  265. package/dist/service/agent/files.d.ts +12 -0
  266. package/dist/service/agent/files.js +69 -0
  267. package/dist/service/agent/protocol.d.ts +90 -0
  268. package/dist/service/agent/protocol.js +114 -0
  269. package/dist/service/agent/server.d.ts +28 -0
  270. package/dist/service/agent/server.js +374 -0
  271. package/dist/service/agent/task-caller.d.ts +21 -0
  272. package/dist/service/agent/task-caller.js +35 -0
  273. package/dist/service/agent/task-start.d.ts +53 -0
  274. package/dist/service/agent/task-start.js +161 -0
  275. package/dist/service/agent/tasks.d.ts +40 -0
  276. package/dist/service/agent/tasks.js +155 -0
  277. package/dist/service/api.d.ts +50 -0
  278. package/dist/service/api.js +288 -0
  279. package/dist/service/authentication.d.ts +227 -0
  280. package/dist/service/authentication.js +767 -0
  281. package/dist/service/caller-context.d.ts +24 -0
  282. package/dist/service/caller-context.js +6 -0
  283. package/dist/service/catalog.d.ts +42 -0
  284. package/dist/service/catalog.js +66 -0
  285. package/dist/service/channel/provider.d.ts +10 -0
  286. package/dist/service/channel/provider.js +1 -0
  287. package/dist/service/channel/providers/telegram.d.ts +18 -0
  288. package/dist/service/channel/providers/telegram.js +108 -0
  289. package/dist/service/channel/sessions.d.ts +5 -0
  290. package/dist/service/channel/sessions.js +53 -0
  291. package/dist/service/channel/sign-in.d.ts +7 -0
  292. package/dist/service/channel/sign-in.js +78 -0
  293. package/dist/service/chat/archive.d.ts +64 -0
  294. package/dist/service/chat/archive.js +62 -0
  295. package/dist/service/chat/attribution.d.ts +26 -0
  296. package/dist/service/chat/attribution.js +28 -0
  297. package/dist/service/chat/delivery.d.ts +18 -0
  298. package/dist/service/chat/delivery.js +251 -0
  299. package/dist/service/chat/diagnostics.d.ts +2 -0
  300. package/dist/service/chat/diagnostics.js +35 -0
  301. package/dist/service/chat/envelope.d.ts +96 -0
  302. package/dist/service/chat/envelope.js +39 -0
  303. package/dist/service/chat/idempotency.d.ts +19 -0
  304. package/dist/service/chat/idempotency.js +37 -0
  305. package/dist/service/chat/providers/telegram.d.ts +36 -0
  306. package/dist/service/chat/providers/telegram.js +133 -0
  307. package/dist/service/chat/reads.d.ts +25 -0
  308. package/dist/service/chat/reads.js +75 -0
  309. package/dist/service/chat/resolve.d.ts +34 -0
  310. package/dist/service/chat/resolve.js +150 -0
  311. package/dist/service/chat/routes.d.ts +23 -0
  312. package/dist/service/chat/routes.js +75 -0
  313. package/dist/service/chat/schemas.d.ts +43 -0
  314. package/dist/service/chat/schemas.js +31 -0
  315. package/dist/service/config.d.ts +218 -0
  316. package/dist/service/config.js +265 -0
  317. package/dist/service/connection-stream.d.ts +10 -0
  318. package/dist/service/connection-stream.js +191 -0
  319. package/dist/service/connections.d.ts +60 -0
  320. package/dist/service/connections.js +271 -0
  321. package/dist/service/decisions.d.ts +35 -0
  322. package/dist/service/decisions.js +63 -0
  323. package/dist/service/descriptions.d.ts +8 -0
  324. package/dist/service/descriptions.js +20 -0
  325. package/dist/service/discovery-schemas.d.ts +92 -0
  326. package/dist/service/discovery-schemas.js +59 -0
  327. package/dist/service/discovery-search.d.ts +30 -0
  328. package/dist/service/discovery-search.js +95 -0
  329. package/dist/service/discovery.d.ts +37 -0
  330. package/dist/service/discovery.js +436 -0
  331. package/dist/service/docs.d.ts +9 -0
  332. package/dist/service/docs.js +197 -0
  333. package/dist/service/errors.d.ts +145 -0
  334. package/dist/service/errors.js +704 -0
  335. package/dist/service/federation-provider.d.ts +36 -0
  336. package/dist/service/federation-provider.js +110 -0
  337. package/dist/service/federation-server.d.ts +20 -0
  338. package/dist/service/federation-server.js +249 -0
  339. package/dist/service/federation-status.d.ts +40 -0
  340. package/dist/service/federation-status.js +151 -0
  341. package/dist/service/handlers.d.ts +18 -0
  342. package/dist/service/handlers.js +287 -0
  343. package/dist/service/mcp/confirmation.d.ts +68 -0
  344. package/dist/service/mcp/confirmation.js +178 -0
  345. package/dist/service/mcp/find-input.d.ts +12 -0
  346. package/dist/service/mcp/find-input.js +122 -0
  347. package/dist/service/mcp/input-schema.d.ts +6 -0
  348. package/dist/service/mcp/input-schema.js +126 -0
  349. package/dist/service/mcp/listing.d.ts +26 -0
  350. package/dist/service/mcp/listing.js +92 -0
  351. package/dist/service/mcp/metric-tools.d.ts +85 -0
  352. package/dist/service/mcp/metric-tools.js +258 -0
  353. package/dist/service/mcp/request-log.d.ts +5 -0
  354. package/dist/service/mcp/request-log.js +53 -0
  355. package/dist/service/mcp/runtime-policy.d.ts +27 -0
  356. package/dist/service/mcp/runtime-policy.js +62 -0
  357. package/dist/service/mcp/server.d.ts +52 -0
  358. package/dist/service/mcp/server.js +861 -0
  359. package/dist/service/mcp/tools.d.ts +99 -0
  360. package/dist/service/mcp/tools.js +938 -0
  361. package/dist/service/member-file-routes.d.ts +22 -0
  362. package/dist/service/member-file-routes.js +52 -0
  363. package/dist/service/member-files.d.ts +245 -0
  364. package/dist/service/member-files.js +258 -0
  365. package/dist/service/metric-query-platform.d.ts +77 -0
  366. package/dist/service/metric-query-platform.js +198 -0
  367. package/dist/service/metric-query-scopes.d.ts +43 -0
  368. package/dist/service/metric-query-scopes.js +147 -0
  369. package/dist/service/metric-query.d.ts +48 -0
  370. package/dist/service/metric-query.js +200 -0
  371. package/dist/service/name-suggestions.d.ts +3 -0
  372. package/dist/service/name-suggestions.js +38 -0
  373. package/dist/service/navigation-schemas.d.ts +80 -0
  374. package/dist/service/navigation-schemas.js +49 -0
  375. package/dist/service/navigation.d.ts +20 -0
  376. package/dist/service/navigation.js +165 -0
  377. package/dist/service/oauth/protocol.d.ts +70 -0
  378. package/dist/service/oauth/protocol.js +157 -0
  379. package/dist/service/oauth/refresh-replay.d.ts +2 -0
  380. package/dist/service/oauth/refresh-replay.js +20 -0
  381. package/dist/service/oauth/server.d.ts +28 -0
  382. package/dist/service/oauth/server.js +769 -0
  383. package/dist/service/operations.d.ts +170 -0
  384. package/dist/service/operations.js +392 -0
  385. package/dist/service/plan.d.ts +57 -0
  386. package/dist/service/plan.js +96 -0
  387. package/dist/service/rate-limit.d.ts +22 -0
  388. package/dist/service/rate-limit.js +52 -0
  389. package/dist/service/record-reads.d.ts +21 -0
  390. package/dist/service/record-reads.js +155 -0
  391. package/dist/service/replication.d.ts +5 -0
  392. package/dist/service/replication.js +39 -0
  393. package/dist/service/runtime-contract.d.ts +508 -0
  394. package/dist/service/runtime-contract.js +18 -0
  395. package/dist/service/runtime-identity.d.ts +71 -0
  396. package/dist/service/runtime-identity.js +122 -0
  397. package/dist/service/schemas.d.ts +961 -0
  398. package/dist/service/schemas.js +639 -0
  399. package/dist/service/service.d.ts +21 -0
  400. package/dist/service/service.js +526 -0
  401. package/dist/service/warehouse-platform.d.ts +17 -0
  402. package/dist/service/warehouse-platform.js +122 -0
  403. package/dist/service/warehouse-query.d.ts +24 -0
  404. package/dist/service/warehouse-query.js +280 -0
  405. package/dist/service/webhooks.d.ts +106 -0
  406. package/dist/service/webhooks.js +233 -0
  407. package/dist/service/workflow-admission-provider.d.ts +31 -0
  408. package/dist/service/workflow-admission-provider.js +205 -0
  409. package/dist/service/workflow-argument-serialization.d.ts +2 -0
  410. package/dist/service/workflow-argument-serialization.js +14 -0
  411. package/dist/service/workflow-callback.d.ts +22 -0
  412. package/dist/service/workflow-callback.js +75 -0
  413. package/dist/service/workflow-deployment.d.ts +8 -0
  414. package/dist/service/workflow-deployment.js +131 -0
  415. package/dist/service/workflow-diagnostics.d.ts +23 -0
  416. package/dist/service/workflow-diagnostics.js +263 -0
  417. package/dist/service/workflow-errors.d.ts +26 -0
  418. package/dist/service/workflow-errors.js +181 -0
  419. package/dist/service/workflow-logging.d.ts +2 -0
  420. package/dist/service/workflow-logging.js +50 -0
  421. package/dist/service/workflow-queue-fence.d.ts +6 -0
  422. package/dist/service/workflow-queue-fence.js +66 -0
  423. package/dist/service/workflows.d.ts +200 -0
  424. package/dist/service/workflows.js +1549 -0
  425. package/dist/sign-in.d.ts +58 -0
  426. package/dist/sign-in.js +57 -0
  427. package/dist/source.d.ts +30 -0
  428. package/dist/source.js +107 -0
  429. package/dist/start-recovery-contract.d.ts +49 -0
  430. package/dist/start-recovery-contract.js +26 -0
  431. package/dist/start-recovery.d.ts +27 -0
  432. package/dist/start-recovery.js +81 -0
  433. package/dist/storage/api.d.ts +4 -0
  434. package/dist/storage/api.js +40 -0
  435. package/dist/storage/attachments.d.ts +146 -0
  436. package/dist/storage/attachments.js +733 -0
  437. package/dist/storage/authorization.d.ts +38 -0
  438. package/dist/storage/authorization.js +83 -0
  439. package/dist/storage/file-access.d.ts +17 -0
  440. package/dist/storage/file-access.js +8 -0
  441. package/dist/storage/limits.d.ts +12 -0
  442. package/dist/storage/limits.js +17 -0
  443. package/dist/storage/maintenance-auth.d.ts +20 -0
  444. package/dist/storage/maintenance-auth.js +24 -0
  445. package/dist/storage/maintenance.d.ts +11 -0
  446. package/dist/storage/maintenance.js +67 -0
  447. package/dist/storage/neon.d.ts +4 -0
  448. package/dist/storage/neon.js +318 -0
  449. package/dist/storage/operator.d.ts +11 -0
  450. package/dist/storage/operator.js +30 -0
  451. package/dist/storage/provider.d.ts +93 -0
  452. package/dist/storage/provider.js +36 -0
  453. package/dist/storage/sessions.d.ts +184 -0
  454. package/dist/storage/sessions.js +688 -0
  455. package/dist/storage/tables.d.ts +54 -0
  456. package/dist/storage/tables.js +205 -0
  457. package/dist/storage/transfers.d.ts +16 -0
  458. package/dist/storage/transfers.js +153 -0
  459. package/dist/storage/writes.d.ts +7 -0
  460. package/dist/storage/writes.js +88 -0
  461. package/dist/telegram.d.ts +35 -0
  462. package/dist/telegram.js +173 -0
  463. package/dist/user-identity.d.ts +28 -0
  464. package/dist/user-identity.js +106 -0
  465. package/dist/user.d.ts +75 -0
  466. package/dist/user.js +111 -0
  467. package/dist/warehouse-backed.d.ts +6 -0
  468. package/dist/warehouse-backed.js +495 -0
  469. package/dist/webhook-token.d.ts +11 -0
  470. package/dist/webhook-token.js +18 -0
  471. package/dist/webhooks.d.ts +40 -0
  472. package/dist/webhooks.js +55 -0
  473. package/dist/wire.d.ts +10 -0
  474. package/dist/wire.js +35 -0
  475. package/dist/workflow-runtime.d.ts +116 -0
  476. package/dist/workflow-runtime.js +109 -0
  477. package/dist/workflow-topics.d.ts +28 -0
  478. package/dist/workflow-topics.js +28 -0
  479. package/dist/workflow.d.ts +284 -0
  480. package/dist/workflow.js +259 -0
  481. package/dist/workflows.d.ts +24 -0
  482. package/dist/workflows.js +18 -0
  483. package/package.json +127 -4
@@ -0,0 +1,757 @@
1
+ import { balancesOf, metricExpression } from "./metric.js";
2
+ import { Effect, Schema, SchemaTransformation } from "effect";
3
+ import { acceptingEarlierManifestNames, withEarlierManifestNames } from "./legacy.js";
4
+ import { humanize, MEMBER_ROLE, FEEDBACK_REPORTER_ROLE } from "./names.js";
5
+ import { PROPERTY_TYPES } from "./property.js";
6
+ import { ON_DELETE } from "./relationship.js";
7
+ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isSignInPolicy, } from "./sign-in.js";
8
+ /**
9
+ * The manifest format this SDK writes. Readers accept any version and ignore unknown fields. Version
10
+ * 2 replaced the actions' `allow` with `permission`, and added the roles' `permissions` and the
11
+ * entities' `permissions`; those fields are optional when decoding, so version 1 manifests still read.
12
+ * `signIn` came later within version 2 and is optional too, as are the actions' `connections` and the
13
+ * top-level `connections`, which are written only when an action calls a connection. Version 3 added
14
+ * warehouse sources and metrics. Version 4 writes snake_case names on the wire. Version 5 lets
15
+ * relationships target warehouse-backed entities and warehouse-backed properties declare `unique`:
16
+ * a relationship with a warehouse-backed end carries `on` and omits `optional` and `onDelete`.
17
+ * Version 6 adds the `countDistinct` metric operator and lets stored entities declare `metrics`,
18
+ * whose columns name the stored properties' replication view columns. Version 7 adds the avg, min,
19
+ * max and filtered metric operators and balanceOver on metrics. Version 8 adds the top-level
20
+ * `metrics`, the metrics of the model, written only when the ontology declares some: each combines
21
+ * metrics of entities, named `entity.metric`, with its inputs and its alignment. Version 9 adds the
22
+ * top-level `workflows`, written only when the ontology declares some: each names its role, its
23
+ * input as JSON Schema, the connections its steps call and its triggers, whose input is in wire form.
24
+ * Within version 9, a property may have the type `list` with its `items` type: only the built-in
25
+ * user's managed `roles`, which has no column.
26
+ * Within version 9, triggers may also be `action` and `webhook` triggers; readers ignore kinds they
27
+ * do not know.
28
+ * Version 10 adds the roles' `scopes`, written only when a role scopes some of its permissions: each
29
+ * names the permission and its `where` in the wire form of a query, with `me` as `{ "$me": [] }`
30
+ * and a path from it as `{ "$me": ["staff_member", "division"] }`. `permissions` still lists every
31
+ * permission the role holds, scoped or not. Version 11 adds resolved `feedback` settings and the
32
+ * reserved built-in `feedback_reporter` role, which is implicit for humans and never assignable.
33
+ * Within version 11, actions may opt in to SQL deadlock recovery with `retryOnDeadlock`; its absence
34
+ * disables retries and older readers may ignore it.
35
+ * Within version 11, the top-level `emails`, written only when the ontology declares some, holds the
36
+ * workspace's own emails by wire name: plain-text fields with `{{value}}` placeholders, which the
37
+ * platform renders when it sends a sign-in link. Older readers ignore it.
38
+ * Version 12 changes no field: it marks an SDK whose actions arm a recovery run for their triggers,
39
+ * so publication writes no sweep cron for it. For earlier versions publication keeps the
40
+ * five-minute sweep cron, which their service still needs.
41
+ * Version 13 adds optional `signIn.browser` declarations for workspace-owned browser sign-in
42
+ * methods, primary method, automatic redirect behavior, and local callback port.
43
+ * Within version 13, an entity may carry `writes: "actions"`: it has no generated writes, and its
44
+ * `permissions` hold only `read`, so readers that derive the generated actions from `permissions`
45
+ * need no change. Older readers ignore the field.
46
+ * Within version 13, an action may carry `writes`, the names of the entities its handler writes,
47
+ * which the runtime enforces; absent means it declares none. Older readers ignore the field.
48
+ * Version 14 gives metrics their current names: entities' and the model's `metrics`, and `metric`
49
+ * expression nodes (`{ op: "metric", name }`). Readers accept the earlier names, which the history
50
+ * above calls metrics too; `legacy.ts` names them and renames every document it decodes.
51
+ * Within version 14, `signIn` may carry `codeLink`, written only when declared: whether the
52
+ * platform's sign-in code emails also link to the app's sign-in page with the code filled in.
53
+ * Older readers ignore it and send the code alone.
54
+ * Version 15 changes no field this SDK writes. Ontology SDKs 0.86.0 to 0.88.0 introduced it with
55
+ * `executionCompatibility` and three workflow capabilities for a deploy guard that was withdrawn;
56
+ * readers ignore them.
57
+ */
58
+ export const MANIFEST_VERSION = 15;
59
+ /** The first version whose documents use snake_case names on the wire. */
60
+ const WIRE_MANIFEST_VERSION = 4;
61
+ /** The first version whose documents name metrics as this SDK does; earlier ones keep theirs. */
62
+ const METRICS_MANIFEST_VERSION = 14;
63
+ /** The phrase used for a direction the author did not phrase. */
64
+ export const DEFAULT_PHRASE = "has";
65
+ export const SelectOptionManifest = Schema.Struct({
66
+ value: Schema.String,
67
+ label: Schema.String,
68
+ description: Schema.String,
69
+ });
70
+ export const PropertyManifest = Schema.Struct({
71
+ column: Schema.optionalKey(Schema.String),
72
+ scope: Schema.optionalKey(Schema.Array(Schema.String)),
73
+ name: Schema.String,
74
+ type: Schema.Literals(PROPERTY_TYPES),
75
+ label: Schema.String,
76
+ description: Schema.optionalKey(Schema.String),
77
+ optional: Schema.Boolean,
78
+ unique: Schema.Boolean,
79
+ managed: Schema.Boolean,
80
+ default: Schema.optionalKey(Schema.Json),
81
+ display: Schema.optionalKey(Schema.String),
82
+ renamedFrom: Schema.optionalKey(Schema.String),
83
+ min: Schema.optionalKey(Schema.Number),
84
+ max: Schema.optionalKey(Schema.Number),
85
+ maxLength: Schema.optionalKey(Schema.Number),
86
+ accept: Schema.optionalKey(Schema.Array(Schema.String)),
87
+ maxBytes: Schema.optionalKey(Schema.Number),
88
+ options: Schema.optionalKey(Schema.Array(SelectOptionManifest)),
89
+ /** The item type of a `list`, the built-in user's `roles`, which has no column. */
90
+ items: Schema.optionalKey(Schema.Literals(PROPERTY_TYPES)),
91
+ });
92
+ /**
93
+ * A relationship as declared. The inverse is not repeated on the target entity: readers derive it
94
+ * from `to`, `inverse` and the second `phrase`.
95
+ */
96
+ export const RelationshipManifest = Schema.Struct({
97
+ /**
98
+ * The property pair of a value-matched relationship, one with a warehouse-backed end. Absent
99
+ * between stored entities, which use a `<name>_id` key instead.
100
+ */
101
+ on: Schema.optionalKey(Schema.Struct({ property: Schema.String, targetProperty: Schema.String })),
102
+ name: Schema.String,
103
+ to: Schema.String,
104
+ inverse: Schema.String,
105
+ cardinality: Schema.Literals(["one", "many"]),
106
+ /** `rel.one` between stored entities only. */
107
+ optional: Schema.optionalKey(Schema.Boolean),
108
+ /**
109
+ * `rel.one` between stored entities only. Before version 5, warehouse → stored relationships
110
+ * carried it too, as `restrict`, though nothing enforced it.
111
+ */
112
+ onDelete: Schema.optionalKey(Schema.Literals(ON_DELETE)),
113
+ /** `rel.many` only. */
114
+ ordered: Schema.optionalKey(Schema.Boolean),
115
+ /** Forward and inverse phrases; unphrased directions read "has". */
116
+ phrase: Schema.Tuple([Schema.String, Schema.String]),
117
+ description: Schema.String,
118
+ });
119
+ /**
120
+ * Whether a relationship is matched by value: either end is warehouse-backed. A value-matched
121
+ * relationship always declares `on`; a stored → stored relationship never does. It has no
122
+ * `<name>_id` column, foreign key, index or traversal route.
123
+ */
124
+ export function isValueMatched(relationship) {
125
+ return relationship.on !== undefined;
126
+ }
127
+ export const IndexManifest = Schema.Struct({
128
+ properties: Schema.Array(Schema.String),
129
+ unique: Schema.Boolean,
130
+ });
131
+ export const ActionManifest = Schema.Struct({
132
+ name: Schema.String,
133
+ description: Schema.String,
134
+ /**
135
+ * The permission a principal needs to run the action, for example `lead:changeStatus`. Always
136
+ * written; absent from version 1 manifests, where it reads as `<entity>:<action name>`.
137
+ */
138
+ permission: Schema.optionalKey(Schema.String),
139
+ /** JSON Schema (draft 2020-12) of the input object. */
140
+ input: Schema.Record(Schema.String, Schema.Json),
141
+ /** Opt-in SQL handler replay after a confirmed deadlock rollback; absent means disabled. */
142
+ retryOnDeadlock: Schema.optionalKey(Schema.Boolean),
143
+ /**
144
+ * The entities the handler writes, by name, as the action declares them; the runtime refuses any
145
+ * other write. Absent means it declares none and may write any entity; `[]` writes nothing.
146
+ */
147
+ writes: Schema.optionalKey(Schema.Array(Schema.String)),
148
+ /**
149
+ * The keys of the workspace connections the action calls before its transaction. Written only
150
+ * when there are some; absent reads as none.
151
+ */
152
+ connections: Schema.optionalKey(Schema.Array(Schema.String)),
153
+ /** File writes declared in code; absence grants preparation no staging targets. */
154
+ files: Schema.optionalKey(Schema.Array(Schema.Struct({ entity: Schema.String, property: Schema.String }))),
155
+ /**
156
+ * How the action behaves, as MCP tool annotations tell agents. Written only when the action
157
+ * declares hints; absent safety labels require agent confirmation for compatibility.
158
+ */
159
+ hints: Schema.optionalKey(Schema.Struct({
160
+ readOnly: Schema.optionalKey(Schema.Boolean),
161
+ connectionsReadOnly: Schema.optionalKey(Schema.Boolean),
162
+ destructive: Schema.optionalKey(Schema.Boolean),
163
+ irreversible: Schema.optionalKey(Schema.Boolean),
164
+ idempotent: Schema.optionalKey(Schema.Boolean),
165
+ })),
166
+ });
167
+ /**
168
+ * The permissions of an entity's reads and generated actions, so that readers need not rebuild the
169
+ * convention. The built-in user has only `read`; `link` and `unlink` exist with a `rel.many`. The
170
+ * generated `upsert_by_<property>` requires both `create` and `update`.
171
+ */
172
+ export const EntityPermissionsManifest = Schema.Struct({
173
+ read: Schema.String,
174
+ create: Schema.optionalKey(Schema.String),
175
+ update: Schema.optionalKey(Schema.String),
176
+ delete: Schema.optionalKey(Schema.String),
177
+ link: Schema.optionalKey(Schema.String),
178
+ unlink: Schema.optionalKey(Schema.String),
179
+ });
180
+ /** A metric of an entity: its metadata and the expression the platform computes. */
181
+ export const MetricManifest = Schema.Struct({
182
+ name: Schema.String,
183
+ label: Schema.String,
184
+ description: Schema.String,
185
+ unit: Schema.Literals(["number", "currency", "ratio", "percent"]),
186
+ format: Schema.Literals(["decimal", "currency", "percent"]),
187
+ expression: Schema.Json,
188
+ /**
189
+ * The column of the date or timestamp property a balance metric snapshots over; absent for
190
+ * additive metrics and in manifests before version 7. `balance_over` on the wire.
191
+ */
192
+ balanceOver: Schema.optionalKey(Schema.String),
193
+ });
194
+ /**
195
+ * A metric of the model, `defineOntology({ metrics })`. Its expression is an entity metric's
196
+ * arithmetic whose `metric` nodes name `entity.metric`, with references to other model metrics
197
+ * expanded. Names are wire names throughout.
198
+ */
199
+ export const ModelMetricManifest = Schema.Struct({
200
+ name: Schema.String,
201
+ label: Schema.String,
202
+ description: Schema.String,
203
+ unit: Schema.Literals(["number", "currency", "ratio", "percent"]),
204
+ format: Schema.Literals(["decimal", "currency", "percent"]),
205
+ expression: Schema.Json,
206
+ /** The entity metrics the expression reads, `entity.metric`, each once, in reading order. */
207
+ inputs: Schema.Array(Schema.String),
208
+ /**
209
+ * Groups of properties that stand for one another: each names every entity the metric reads,
210
+ * with a property or `null` for an entity without a counterpart.
211
+ */
212
+ align: Schema.Array(Schema.Record(Schema.String, Schema.NullOr(Schema.String))),
213
+ });
214
+ export const EntityManifest = Schema.Struct({
215
+ source: Schema.optionalKey(Schema.Struct({
216
+ asset: Schema.String,
217
+ key: Schema.Array(Schema.String),
218
+ currency: Schema.optionalKey(Schema.String),
219
+ })),
220
+ metrics: Schema.optionalKey(Schema.Array(MetricManifest)),
221
+ id: Schema.String,
222
+ name: Schema.String,
223
+ label: Schema.String,
224
+ plural: Schema.String,
225
+ title: Schema.String,
226
+ description: Schema.String,
227
+ builtIn: Schema.Boolean,
228
+ renamedFrom: Schema.optionalKey(Schema.String),
229
+ guide: Schema.optionalKey(Schema.String),
230
+ properties: Schema.Array(PropertyManifest),
231
+ relationships: Schema.Array(RelationshipManifest),
232
+ indexes: Schema.Array(IndexManifest),
233
+ actions: Schema.Array(ActionManifest),
234
+ /** Always written; absent from version 1 manifests. */
235
+ permissions: Schema.optionalKey(EntityPermissionsManifest),
236
+ /**
237
+ * `"actions"` when only the entity's authored actions write its records, so it has no generated
238
+ * writes and its `permissions` hold only `read`. Absent means the generated writes exist.
239
+ */
240
+ writes: Schema.optionalKey(Schema.Literal("actions")),
241
+ });
242
+ /**
243
+ * A scoped permission of a role: `<entity>:<verb>` and the `where` of the records it covers, in the
244
+ * wire form of a query on the entity, where `{ "$me": [...] }` stands for the caller or a path from
245
+ * them. Readers that do not enforce scopes may show the `where` or ignore it.
246
+ */
247
+ export const ScopeManifest = Schema.Struct({
248
+ permission: Schema.String,
249
+ where: Schema.Record(Schema.String, Schema.Json),
250
+ });
251
+ export const RoleManifest = Schema.Struct({
252
+ name: Schema.String,
253
+ description: Schema.String,
254
+ builtIn: Schema.Boolean,
255
+ /**
256
+ * What the role may do, wildcards included; for the built-in `member`, what every active app user
257
+ * may do. Always written; absent from version 1 manifests.
258
+ */
259
+ permissions: Schema.optionalKey(Schema.Array(Schema.String)),
260
+ /**
261
+ * The permissions the role holds only for the records their `where` matches, since version 10.
262
+ * Written only when there are some; absent reads as none.
263
+ */
264
+ scopes: Schema.optionalKey(Schema.Array(ScopeManifest)),
265
+ });
266
+ /**
267
+ * A cron trigger of a workflow: the platform writes a Vercel cron for it, whose invocation starts the
268
+ * workflow with `input`, the wire form of the workflow's input, sent as it is.
269
+ */
270
+ export const CronTriggerManifest = Schema.Struct({
271
+ kind: Schema.Literal("cron"),
272
+ name: Schema.String,
273
+ description: Schema.String,
274
+ /** Five fields, UTC. */
275
+ cron: Schema.String,
276
+ input: Schema.Json,
277
+ });
278
+ /**
279
+ * An action trigger of a workflow: the ontology service starts the workflow after an action of
280
+ * `entity` commits, `action` or, when it is absent, any of them. Wire names; the trigger's
281
+ * predicate and input mapping are code and never in the manifest.
282
+ */
283
+ export const ActionTriggerManifest = Schema.Struct({
284
+ kind: Schema.Literal("action"),
285
+ name: Schema.String,
286
+ description: Schema.String,
287
+ entity: Schema.String,
288
+ action: Schema.optionalKey(Schema.String),
289
+ });
290
+ /**
291
+ * A webhook trigger of a workflow: the ontology service starts the workflow for each genuine
292
+ * delivery to `/api/webhooks/<name>`. With `signature`, deliveries are checked with the provider's
293
+ * scheme against the named workspace secret; without it, the URL ends in a derived token.
294
+ * `verification` opts into a registration handshake; `headers` lists the request headers the
295
+ * delivery carries. Optional settings are written only when declared.
296
+ */
297
+ export const WebhookTriggerManifest = Schema.Struct({
298
+ kind: Schema.Literal("webhook"),
299
+ name: Schema.String,
300
+ description: Schema.String,
301
+ signature: Schema.optionalKey(Schema.Struct({ scheme: Schema.String, secret: Schema.String })),
302
+ verification: Schema.optionalKey(Schema.Struct({ scheme: Schema.String, verifyToken: Schema.String })),
303
+ headers: Schema.optionalKey(Schema.Array(Schema.String)),
304
+ });
305
+ /** The trigger kinds this reader knows. */
306
+ const KNOWN_TRIGGER_KINDS = ["cron", "action", "webhook"];
307
+ /**
308
+ * A trigger of a kind this reader does not know, kept as written: a manifest a later SDK built
309
+ * keeps its hash, and readers that present triggers drop it.
310
+ */
311
+ export const OtherTriggerManifest = Schema.Record(Schema.String, Schema.Json).check(Schema.makeFilter((value) => (typeof value.kind === "string" && !KNOWN_TRIGGER_KINDS.includes(value.kind)) ||
312
+ "Expected a trigger of another kind than cron, action or webhook"));
313
+ /**
314
+ * A trigger of a workflow, by `kind`: `cron`, `action`, `webhook`, or a kind this reader keeps
315
+ * without knowing.
316
+ */
317
+ export const WorkflowTriggerManifest = Schema.Union([
318
+ CronTriggerManifest,
319
+ ActionTriggerManifest,
320
+ WebhookTriggerManifest,
321
+ OtherTriggerManifest,
322
+ ]);
323
+ /** Whether a trigger is a cron trigger. */
324
+ export function isCronTrigger(trigger) {
325
+ return trigger.kind === "cron";
326
+ }
327
+ /** Whether a trigger is an action trigger. */
328
+ export function isActionTrigger(trigger) {
329
+ return trigger.kind === "action";
330
+ }
331
+ /** Whether a trigger is a webhook trigger. */
332
+ export function isWebhookTrigger(trigger) {
333
+ return trigger.kind === "webhook";
334
+ }
335
+ /**
336
+ * A workflow, `defineOntology({ workflows })`: a durable process the ontology service runs as the
337
+ * workflow's own service user holding `role`. Names are wire names; `input` is the JSON Schema of
338
+ * the workflow's input and `connections` the keys of the connections its steps call.
339
+ */
340
+ export const WorkflowManifest = Schema.Struct({
341
+ name: Schema.String,
342
+ description: Schema.String,
343
+ role: Schema.String,
344
+ input: Schema.Record(Schema.String, Schema.Json),
345
+ connections: Schema.Array(Schema.String),
346
+ triggers: Schema.Array(WorkflowTriggerManifest),
347
+ });
348
+ /** A workspace connection the ontology's actions call, by its key in `connections/connections.py`. */
349
+ export const ConnectionManifest = Schema.Struct({
350
+ key: Schema.String,
351
+ description: Schema.String,
352
+ /** Written only when the ontology sends data out through the connection. */
353
+ delivers: Schema.optionalKey(Schema.Literal(true)),
354
+ });
355
+ /**
356
+ * Who may become a member by signing in: `invited` or `open` as this SDK writes it. The policy is
357
+ * read as text, not as a closed set, because nothing is stored by it: a reader that meets a policy it
358
+ * does not know keeps the manifest and treats the policy as `invited`.
359
+ */
360
+ export const BrowserSignInManifest = Schema.Struct({
361
+ methods: Schema.Array(Schema.String),
362
+ primary: Schema.String,
363
+ autoRedirect: Schema.Boolean,
364
+ local: Schema.optionalKey(Schema.Struct({ port: Schema.Int })),
365
+ }).pipe(Schema.encodeKeys({ autoRedirect: "auto_redirect" }));
366
+ export const SignInManifest = Schema.Struct({
367
+ browser: Schema.optionalKey(BrowserSignInManifest),
368
+ policy: Schema.String,
369
+ channels: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
370
+ onNewUser: Schema.optionalKey(Schema.String),
371
+ codeLink: Schema.optionalKey(Schema.Boolean),
372
+ }).pipe(Schema.encodeKeys({ onNewUser: "on_new_user", codeLink: "code_link" }));
373
+ /** One of the workspace's emails, as `defineOntology({ emails })` declares it; see `EmailTemplate`. */
374
+ export const EmailTemplateManifest = Schema.Struct({
375
+ subject: Schema.String,
376
+ eyebrow: Schema.optionalKey(Schema.String),
377
+ heading: Schema.String,
378
+ card: Schema.optionalKey(Schema.Struct({ title: Schema.String, detail: Schema.optionalKey(Schema.String) })),
379
+ note: Schema.optionalKey(Schema.String),
380
+ paragraphs: Schema.optionalKey(Schema.Array(Schema.String)),
381
+ action: Schema.String,
382
+ footer: Schema.optionalKey(Schema.String),
383
+ replyTo: Schema.optionalKey(Schema.String),
384
+ }).pipe(Schema.encodeKeys({ replyTo: "reply_to" }));
385
+ /**
386
+ * The ontology catalog: the contract between the SDK, backend-next, the console and the CLI. Decoding
387
+ * ignores unknown fields and accepts any `version`. The closed sets (property types, cardinalities,
388
+ * `onDelete`) are validated because the migration planner must map every value to storage.
389
+ */
390
+ const OntologyManifestModel = Schema.Struct({
391
+ // @legacy ontology.feedback-unset-manifests
392
+ /** Resolved feedback settings since version 11; absence preserves historical opt-in behavior. */
393
+ feedback: Schema.optionalKey(Schema.Struct({
394
+ enabled: Schema.Boolean,
395
+ files: Schema.Boolean,
396
+ builders: Schema.Array(Schema.String),
397
+ automaticFailureReports: Schema.optionalKey(Schema.Boolean),
398
+ })),
399
+ runtimeCapabilities: Schema.optionalKey(Schema.Array(Schema.String)),
400
+ // @legacy ontology.workflow-cutover-artifacts
401
+ /** Written by ontology SDKs 0.86.0 to 0.88.0 and never read; decoded so their manifests encode back. */
402
+ executionCompatibility: Schema.optionalKey(Schema.Struct({ version: Schema.Int, hash: Schema.String })),
403
+ version: Schema.Int,
404
+ /** `sha256:` and the hex digest of the canonical JSON of the manifest without `hash`. */
405
+ hash: Schema.String,
406
+ entities: Schema.Array(EntityManifest),
407
+ roles: Schema.Array(RoleManifest),
408
+ /** Always written; absent from manifests built before sign-in policies, which read as `invited`. */
409
+ signIn: Schema.optionalKey(SignInManifest),
410
+ /** The workspace's own emails by wire name. Written only when there are some; absent reads as none. */
411
+ emails: Schema.optionalKey(Schema.Record(Schema.String, EmailTemplateManifest)),
412
+ /** The connections the actions call. Written only when there are some; absent reads as none. */
413
+ connections: Schema.optionalKey(Schema.Array(ConnectionManifest)),
414
+ chat: Schema.optionalKey(Schema.Struct({
415
+ telegram: Schema.optionalKey(Schema.Struct({ connection: Schema.String })),
416
+ attribution: Schema.optionalKey(Schema.Struct({
417
+ template: Schema.optionalKey(Schema.String),
418
+ separator: Schema.optionalKey(Schema.String),
419
+ })),
420
+ })),
421
+ /**
422
+ * The metrics of the model, since version 8. Written only when there are some; absent reads as
423
+ * none.
424
+ */
425
+ metrics: Schema.optionalKey(Schema.Array(ModelMetricManifest)),
426
+ /**
427
+ * The workflows, since version 9. Written only when there are some; absent reads as none.
428
+ */
429
+ workflows: Schema.optionalKey(Schema.Array(WorkflowManifest)),
430
+ });
431
+ /** A property in the snake_case wire spelling, for records that store definitions. */
432
+ export const PropertyManifestWire = PropertyManifest.pipe(Schema.encodeKeys({
433
+ renamedFrom: "renamed_from",
434
+ maxLength: "max_length",
435
+ maxBytes: "max_bytes",
436
+ }));
437
+ const OnDeleteWire = Schema.Literals(["set_null", "cascade", "restrict"]).pipe(Schema.decodeTo(Schema.Literals(ON_DELETE), SchemaTransformation.transform({
438
+ decode: (value) => (value === "set_null" ? "setNull" : value),
439
+ encode: (value) => (value === "setNull" ? "set_null" : value),
440
+ })));
441
+ /** A relationship in the snake_case wire spelling, for records that store definitions. */
442
+ export const RelationshipManifestWire = Schema.Struct({
443
+ ...RelationshipManifest.fields,
444
+ on: Schema.optionalKey(Schema.Struct({ property: Schema.String, targetProperty: Schema.String }).pipe(Schema.encodeKeys({ targetProperty: "target_property" }))),
445
+ onDelete: Schema.optionalKey(OnDeleteWire),
446
+ }).pipe(Schema.encodeKeys({ onDelete: "on_delete" }));
447
+ const MetricManifestWire = MetricManifest.pipe(Schema.encodeKeys({ balanceOver: "balance_over" }));
448
+ const EntityManifestWire = Schema.Struct({
449
+ ...EntityManifest.fields,
450
+ metrics: Schema.optionalKey(Schema.Array(MetricManifestWire)),
451
+ properties: Schema.Array(PropertyManifestWire),
452
+ relationships: Schema.Array(RelationshipManifestWire),
453
+ }).pipe(Schema.encodeKeys({ builtIn: "built_in", renamedFrom: "renamed_from" }));
454
+ const RoleManifestWire = RoleManifest.pipe(Schema.encodeKeys({ builtIn: "built_in" }));
455
+ /** The JSON contract written since version 4; decoded SDK models remain camelCase. */
456
+ export const OntologyManifestWire = Schema.Struct({
457
+ ...OntologyManifestModel.fields,
458
+ entities: Schema.Array(EntityManifestWire),
459
+ roles: Schema.Array(RoleManifestWire),
460
+ }).pipe(Schema.encodeKeys({ signIn: "sign_in" }));
461
+ // @legacy ontology.metric-earlier-names
462
+ /**
463
+ * Historical readers accept either metadata spelling and any manifest version, with the names of
464
+ * metrics before version 14: every decode, of the type side too, reads a document through
465
+ * `withCurrentManifestNames`.
466
+ */
467
+ export const OntologyManifest = acceptingEarlierManifestNames(Schema.Union([OntologyManifestWire, OntologyManifestModel]));
468
+ const originalDocuments = new WeakMap();
469
+ /**
470
+ * Retain the complete document when decoding a persisted or published manifest: encoding the decoded
471
+ * manifest returns it untouched, earlier names included, so its hash still verifies.
472
+ */
473
+ export const decodeManifestDocument = (value) => Schema.decodeUnknownEffect(OntologyManifest)(value).pipe(Effect.map((manifest) => {
474
+ originalDocuments.set(manifest, value);
475
+ return manifest;
476
+ }));
477
+ /** Encode only ontology-owned metadata. JSON values and JSON Schema keywords remain opaque. */
478
+ export function encodeManifest(manifest) {
479
+ const original = originalDocuments.get(manifest);
480
+ if (original !== undefined) {
481
+ return original;
482
+ }
483
+ const encoded = manifest.version < WIRE_MANIFEST_VERSION
484
+ ? manifest
485
+ : Schema.encodeSync(OntologyManifestWire)(manifest);
486
+ // A manifest keeps the names of its version, which its hash was computed over.
487
+ return manifest.version < METRICS_MANIFEST_VERSION ? withEarlierManifestNames(encoded) : encoded;
488
+ }
489
+ /**
490
+ * The sign-in policy a manifest declares. A manifest without one, or with a policy this reader does
491
+ * not know, reads as `invited`: the closed choice, so that a misread never lets strangers in.
492
+ */
493
+ export function signInPolicyOf(manifest) {
494
+ const policy = manifest.signIn?.policy;
495
+ return isSignInPolicy(policy) ? policy : DEFAULT_SIGN_IN_POLICY;
496
+ }
497
+ /** Unsupported providers and missing or unknown channel policies require invitation. */
498
+ export function channelPolicyOf(manifest, provider) {
499
+ if (!CHANNEL_PROVIDERS.some((supported) => supported === provider)) {
500
+ return DEFAULT_SIGN_IN_POLICY;
501
+ }
502
+ const policy = manifest.signIn?.channels?.[provider];
503
+ return isSignInPolicy(policy) ? policy : DEFAULT_SIGN_IN_POLICY;
504
+ }
505
+ function serialize(value, indent, depth) {
506
+ if (Array.isArray(value)) {
507
+ const items = value.map((item) => serialize(item ?? null, indent, depth + 1));
508
+ return wrap("[", "]", items, indent, depth);
509
+ }
510
+ if (typeof value === "object" && value !== null) {
511
+ const record = value;
512
+ const separator = indent === undefined ? ":" : ": ";
513
+ const entries = Object.keys(record)
514
+ .filter((key) => record[key] !== undefined)
515
+ .sort()
516
+ .map((key) => `${JSON.stringify(key)}${separator}${serialize(record[key], indent, depth + 1)}`);
517
+ return wrap("{", "}", entries, indent, depth);
518
+ }
519
+ return JSON.stringify(value) ?? "null";
520
+ }
521
+ function wrap(open, close, items, indent, depth) {
522
+ if (items.length === 0) {
523
+ return `${open}${close}`;
524
+ }
525
+ if (indent === undefined) {
526
+ return `${open}${items.join(",")}${close}`;
527
+ }
528
+ const inner = indent.repeat(depth + 1);
529
+ return `${open}\n${inner}${items.join(`,\n${inner}`)}\n${indent.repeat(depth)}${close}`;
530
+ }
531
+ /**
532
+ * Node's crypto, loaded when a hash is computed rather than when this module is imported: workflow
533
+ * files import entity declarations, and the Workflow SDK bundles what they import for a runtime
534
+ * without Node built-ins.
535
+ */
536
+ function nodeCrypto() {
537
+ return process.getBuiltinModule("node:crypto");
538
+ }
539
+ /** JSON with object keys sorted at every level and no whitespace: the input of the manifest hash. */
540
+ export function canonicalJson(value) {
541
+ return serialize(value, undefined, 0);
542
+ }
543
+ /** The manifest as a file: canonical key order, two-space indentation and a final newline. */
544
+ export function formatManifest(manifest) {
545
+ return `${serialize(encodeManifest(manifest), " ", 0)}\n`;
546
+ }
547
+ /** The hash of a manifest, computed over its canonical JSON without the `hash` field. */
548
+ export function manifestHash(manifest) {
549
+ const body = Object.fromEntries(Object.entries(manifest).filter(([key]) => key !== "hash"));
550
+ const digest = nodeCrypto()
551
+ .createHash("sha256")
552
+ .update(canonicalJson(body), "utf8")
553
+ .digest("hex");
554
+ return `sha256:${digest}`;
555
+ }
556
+ function propertyManifest({ name, definition }) {
557
+ return {
558
+ name,
559
+ type: definition.type,
560
+ ...(definition.column !== undefined ? { column: definition.column } : {}),
561
+ ...(definition.scope !== undefined ? { scope: definition.scope } : {}),
562
+ label: definition.label ?? humanize(name),
563
+ ...(definition.description !== undefined ? { description: definition.description } : {}),
564
+ optional: definition.optional,
565
+ unique: definition.unique,
566
+ managed: definition.managed,
567
+ ...("default" in definition ? { default: definition.default } : {}),
568
+ ...(definition.display !== undefined ? { display: definition.display } : {}),
569
+ ...(definition.renamedFrom !== undefined ? { renamedFrom: definition.renamedFrom } : {}),
570
+ ...(definition.min !== undefined ? { min: definition.min } : {}),
571
+ ...(definition.max !== undefined ? { max: definition.max } : {}),
572
+ ...(definition.maxLength !== undefined ? { maxLength: definition.maxLength } : {}),
573
+ ...(definition.accept !== undefined ? { accept: definition.accept } : {}),
574
+ ...(definition.maxBytes !== undefined ? { maxBytes: definition.maxBytes } : {}),
575
+ ...(definition.items !== undefined ? { items: definition.items } : {}),
576
+ ...(definition.options !== undefined
577
+ ? {
578
+ options: definition.options.map((option) => ({
579
+ value: option.value,
580
+ label: option.label,
581
+ description: option.description ?? "",
582
+ })),
583
+ }
584
+ : {}),
585
+ };
586
+ }
587
+ /**
588
+ * `stored` says whether both ends are stored: only then does a `rel.one` have a key column, and so
589
+ * an optionality and a delete rule.
590
+ */
591
+ function relationshipManifest(input) {
592
+ const { resolved, stored } = input;
593
+ const { name, relationship, target } = resolved;
594
+ const common = {
595
+ name,
596
+ to: target ?? "",
597
+ inverse: relationship.inverse,
598
+ phrase: relationship.phrase ?? [DEFAULT_PHRASE, DEFAULT_PHRASE],
599
+ description: relationship.description,
600
+ };
601
+ if (relationship.cardinality === "many") {
602
+ return { ...common, cardinality: "many", ordered: relationship.ordered };
603
+ }
604
+ return {
605
+ ...common,
606
+ cardinality: "one",
607
+ ...(stored
608
+ ? { optional: relationship.optional, onDelete: relationship.onDelete ?? "restrict" }
609
+ : {}),
610
+ ...(relationship.on === undefined
611
+ ? {}
612
+ : {
613
+ on: {
614
+ property: Object.keys(relationship.on)[0],
615
+ targetProperty: Object.values(relationship.on)[0],
616
+ },
617
+ }),
618
+ };
619
+ }
620
+ /**
621
+ * The metrics of an entity, of one that passed `check`. A warehouse-backed property's column is its
622
+ * `column`; a stored property has none, and its column in the replication view is its wire name.
623
+ * Conditions name columns too, and so does `balanceOver`, which comes from the metric's own
624
+ * aggregates, top-level or inside arithmetic: `check` lets them name one property at most.
625
+ */
626
+ export function metricsManifest(resolved) {
627
+ const columns = new Map(resolved.properties.map((property) => [
628
+ property.name,
629
+ property.definition.column ?? property.name,
630
+ ]));
631
+ return Object.entries(resolved.entity.definition.metrics ?? {}).map(([name, metric]) => {
632
+ const [balance] = balancesOf(metric);
633
+ return {
634
+ name,
635
+ label: metric.label ?? humanize(name),
636
+ description: metric.description ?? "",
637
+ unit: metric.unit ?? "number",
638
+ format: metric.format ??
639
+ (metric.unit === "currency"
640
+ ? "currency"
641
+ : metric.unit === "percent"
642
+ ? "percent"
643
+ : "decimal"),
644
+ expression: metricExpression(metric, columns),
645
+ ...(balance === undefined ? {} : { balanceOver: columns.get(balance) ?? balance }),
646
+ };
647
+ });
648
+ }
649
+ /** `warehouseBacked` names the ontology's warehouse-backed entities, which relationships may target. */
650
+ function entityManifest(input) {
651
+ const { resolved, warehouseBacked } = input;
652
+ const { definition } = resolved.entity;
653
+ const storedOwner = definition.source === undefined;
654
+ const metrics = metricsManifest(resolved);
655
+ return {
656
+ // A warehouse-backed entity always lists its metrics; a stored entity only when it has some.
657
+ ...(definition.source === undefined ? {} : { source: definition.source, metrics }),
658
+ ...(definition.source === undefined && metrics.length > 0 ? { metrics } : {}),
659
+ id: definition.id,
660
+ name: resolved.name,
661
+ label: definition.label,
662
+ plural: definition.plural,
663
+ title: definition.title,
664
+ description: definition.description,
665
+ builtIn: resolved.builtIn,
666
+ ...(definition.renamedFrom !== undefined ? { renamedFrom: definition.renamedFrom } : {}),
667
+ ...(definition.guide !== undefined ? { guide: definition.guide } : {}),
668
+ properties: resolved.properties.map(propertyManifest),
669
+ relationships: resolved.relationships.map((relationship) => relationshipManifest({
670
+ resolved: relationship,
671
+ stored: storedOwner && !warehouseBacked.has(relationship.target ?? ""),
672
+ })),
673
+ indexes: resolved.indexes.map((index) => ({
674
+ properties: [...index.properties],
675
+ unique: index.unique,
676
+ })),
677
+ actions: resolved.actions.map((action) => ({
678
+ name: action.name,
679
+ description: action.action.description,
680
+ permission: action.permission,
681
+ input: action.input ?? {},
682
+ ...(action.action.retryOnDeadlock === undefined
683
+ ? {}
684
+ : { retryOnDeadlock: action.action.retryOnDeadlock }),
685
+ ...(action.writes === undefined ? {} : { writes: [...action.writes] }),
686
+ ...(action.connections.length > 0 ? { connections: [...action.connections] } : {}),
687
+ ...(action.action.files?.length ? { files: [...action.action.files] } : {}),
688
+ ...(action.hints !== undefined ? { hints: { ...action.hints } } : {}),
689
+ })),
690
+ permissions: { ...resolved.permissions },
691
+ ...(resolved.writes === "actions" ? { writes: "actions" } : {}),
692
+ };
693
+ }
694
+ /** Builds the manifest of a resolved ontology that passed `check`. */
695
+ export function buildManifest(input) {
696
+ const connections = input.connections ?? [];
697
+ const emails = input.emails ?? {};
698
+ const metrics = input.metrics ?? [];
699
+ const workflows = input.workflows ?? [];
700
+ const warehouseBacked = new Set(input.entities
701
+ .filter((candidate) => candidate.entity.definition.source !== undefined)
702
+ .map((candidate) => candidate.name));
703
+ const body = {
704
+ ...(input.feedback === undefined ? {} : { feedback: input.feedback }),
705
+ version: MANIFEST_VERSION,
706
+ runtimeCapabilities: [
707
+ "pipeline-workload-tokens-v1",
708
+ "workspace-app-previews-v1",
709
+ "workspace-app-preview-workflows-v1",
710
+ "workspace-app-local-previews-v1",
711
+ ],
712
+ entities: input.entities.map((candidate) => entityManifest({ resolved: candidate, warehouseBacked })),
713
+ roles: input.roles.map((candidate) => ({
714
+ name: candidate.name,
715
+ description: candidate.description,
716
+ builtIn: candidate.name === MEMBER_ROLE || candidate.name === FEEDBACK_REPORTER_ROLE,
717
+ permissions: [...candidate.permissions],
718
+ ...((candidate.scopes ?? []).length > 0
719
+ ? {
720
+ scopes: (candidate.scopes ?? []).map((scope) => ({
721
+ permission: scope.permission,
722
+ where: scope.where,
723
+ })),
724
+ }
725
+ : {}),
726
+ })),
727
+ signIn: {
728
+ policy: input.signIn.policy,
729
+ ...(input.signIn.browser === undefined ? {} : { browser: input.signIn.browser }),
730
+ ...(input.signIn.onNewUser === undefined ? {} : { onNewUser: input.signIn.onNewUser }),
731
+ ...(input.signIn.codeLink === undefined ? {} : { codeLink: input.signIn.codeLink }),
732
+ ...(Object.keys(input.signIn.channels ?? {}).length > 0
733
+ ? { channels: input.signIn.channels }
734
+ : {}),
735
+ },
736
+ ...(Object.keys(emails).length > 0 ? { emails } : {}),
737
+ ...(input.chat === undefined ? {} : { chat: input.chat }),
738
+ ...(connections.length > 0
739
+ ? {
740
+ connections: connections.map((candidate) => ({
741
+ key: candidate.key,
742
+ description: candidate.description,
743
+ ...(candidate.delivers ? { delivers: true } : {}),
744
+ })),
745
+ }
746
+ : {}),
747
+ ...(metrics.length > 0 ? { metrics } : {}),
748
+ ...(workflows.length > 0 ? { workflows } : {}),
749
+ };
750
+ return { ...body, hash: manifestHash(encodeManifest({ ...body, hash: "" })) };
751
+ }
752
+ /** The keys of every connection the manifest's actions call, without duplicates. */
753
+ export function actionConnectionKeys(manifest) {
754
+ return [
755
+ ...new Set(manifest.entities.flatMap((entity) => entity.actions.flatMap((candidate) => candidate.connections ?? []))),
756
+ ];
757
+ }