@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,774 @@
1
+ import { CONFIRMATION_TABLE, CONFIRMATION_DDL } from "../runtime/confirmations.js";
2
+ import { isValueMatched, } from "../manifest.js";
3
+ import { FEDERATION_TABLES_DDL } from "../runtime/federation-tables.js";
4
+ /**
5
+ * The physical mapping of an ontology onto Postgres. The planner creates exactly these objects and the
6
+ * runtime reads and writes them, so every name here is part of the storage contract.
7
+ */
8
+ /** Postgres silently truncates longer identifiers; the planner refuses names that would be truncated. */
9
+ export const MAX_IDENTIFIER_LENGTH = 63;
10
+ /** The one-row table that records the applied manifest. */
11
+ export const CATALOG_TABLE = "_ontology";
12
+ /** The built-in user entity's table. System columns and history principals refer to it. */
13
+ export const USER_TABLE = "user";
14
+ /** System properties and their columns, present on every entity table. */
15
+ export const SYSTEM_COLUMNS = {
16
+ id: "id",
17
+ created_at: "created_at",
18
+ updated_at: "updated_at",
19
+ created_by: "created_by",
20
+ updated_by: "updated_by",
21
+ };
22
+ /** The kinds of change a history row records. */
23
+ export const HISTORY_KINDS = ["create", "update", "delete", "link", "unlink"];
24
+ /**
25
+ * Column types of every property type except `select`, which gets an enum type of its own, and
26
+ * `list`, which has no column: the runtime reads it from the platform's tables.
27
+ */
28
+ export const COLUMN_TYPES = {
29
+ text: "text",
30
+ email: "text",
31
+ url: "text",
32
+ integer: "bigint",
33
+ number: "double precision",
34
+ boolean: "boolean",
35
+ date: "date",
36
+ timestamp: "timestamptz",
37
+ json: "jsonb",
38
+ blob: "uuid",
39
+ };
40
+ /** Whether a property has a column: every type but `list`. */
41
+ export function isStoredProperty(property) {
42
+ return property.type !== "list";
43
+ }
44
+ /** The entity with only the properties that have a column, as storage and migrations see it. */
45
+ export function storedEntity(entity) {
46
+ return entity.properties.every(isStoredProperty)
47
+ ? entity
48
+ : { ...entity, properties: entity.properties.filter(isStoredProperty) };
49
+ }
50
+ const ON_DELETE_ACTIONS = {
51
+ setNull: "SET NULL",
52
+ cascade: "CASCADE",
53
+ restrict: "RESTRICT",
54
+ };
55
+ /** `"name"`, with embedded quotes doubled. */
56
+ export function quoteIdentifier(name) {
57
+ return `"${name.replaceAll('"', '""')}"`;
58
+ }
59
+ /** `'value'`, with embedded quotes doubled (standard_conforming_strings is on). */
60
+ export function quoteLiteral(value) {
61
+ return `'${value.replaceAll("'", "''")}'`;
62
+ }
63
+ // @legacy ontology.camelcase-member-names
64
+ /** `fitScore` → `fit_score`. New property names already use snake_case; conversion remains for historical manifests. */
65
+ export function snakeCase(name) {
66
+ return name.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
67
+ }
68
+ /** An entity's table is named after the entity: `lead`, `user`. */
69
+ export function tableName(entity) {
70
+ return entity;
71
+ }
72
+ export function historyTableName(entity) {
73
+ return `${entity}_history`;
74
+ }
75
+ /** The column of a property: `fitScore` → `fit_score`. */
76
+ export function columnName(property) {
77
+ return snakeCase(property);
78
+ }
79
+ /** The key column of a `rel.one`: `owner` → `owner_id`. */
80
+ export function relationshipColumnName(relationship) {
81
+ return `${snakeCase(relationship)}_id`;
82
+ }
83
+ /** The join table of a `rel.many`: `lead` + `tags` → `lead_tags`. */
84
+ export function joinTableName(entity, relationship) {
85
+ return `${entity}_${snakeCase(relationship)}`;
86
+ }
87
+ /**
88
+ * The two key columns of a join table: `<entity>_id` and `<target>_id`. A relationship from an entity to
89
+ * itself names the target column after the relationship instead (`lead_id`, `related_id`).
90
+ */
91
+ export function joinColumnNames(input) {
92
+ const source = `${input.entity}_id`;
93
+ const target = input.target === input.entity
94
+ ? relationshipColumnName(input.relationship)
95
+ : `${input.target}_id`;
96
+ return { source, target };
97
+ }
98
+ /** The enum type of a `select` property: `lead` + `status` → `lead_status`. */
99
+ export function enumTypeName(entity, property) {
100
+ return `${entity}_${snakeCase(property)}`;
101
+ }
102
+ /** The unique index of a `unique: true` property. */
103
+ export function uniqueIndexName(entity, property) {
104
+ return `${entity}_${snakeCase(property)}_key`;
105
+ }
106
+ /** The `CHECK` constraint holding a property's `maxLength`, `min` and `max`. */
107
+ export function checkConstraintName(entity, property) {
108
+ return `${entity}_${snakeCase(property)}_check`;
109
+ }
110
+ export function foreignKeyName(table, column) {
111
+ return `${table}_${column}_fkey`;
112
+ }
113
+ export function primaryKeyName(table) {
114
+ return `${table}_pkey`;
115
+ }
116
+ /** An index over columns: `lead` + `status, created_at` → `lead_status_created_at_idx`. */
117
+ export function indexName(table, columns) {
118
+ return `${table}_${columns.join("_")}_idx`;
119
+ }
120
+ /**
121
+ * The column of an index field: a system property (`created_at` → `created_at`), a property, or a
122
+ * stored `rel.one` (`owner` → `owner_id`). Returns undefined for anything else, value-matched
123
+ * relationships included: they have no column.
124
+ */
125
+ export function fieldColumnName(entity, field) {
126
+ // @legacy ontology.camelcase-member-names
127
+ // Applied manifests may still name system fields in camelCase.
128
+ const historical = {
129
+ createdAt: "created_at",
130
+ updatedAt: "updated_at",
131
+ createdBy: "created_by",
132
+ updatedBy: "updated_by",
133
+ };
134
+ if (Object.hasOwn(historical, field)) {
135
+ return historical[field];
136
+ }
137
+ if (Object.hasOwn(SYSTEM_COLUMNS, field)) {
138
+ return SYSTEM_COLUMNS[field];
139
+ }
140
+ if (entity.properties.some((property) => property.name === field && isStoredProperty(property))) {
141
+ return columnName(field);
142
+ }
143
+ if (entity.relationships.some((relationship) => relationship.name === field &&
144
+ relationship.cardinality === "one" &&
145
+ !isValueMatched(relationship))) {
146
+ return relationshipColumnName(field);
147
+ }
148
+ return undefined;
149
+ }
150
+ /** The SQL default of a property, or undefined when it declares none. */
151
+ export function defaultExpression(property) {
152
+ if (!("default" in property) || property.default === undefined) {
153
+ return undefined;
154
+ }
155
+ const value = property.default;
156
+ if (property.type === "json") {
157
+ return `${quoteLiteral(JSON.stringify(value))}::jsonb`;
158
+ }
159
+ if (value === null) {
160
+ return "NULL";
161
+ }
162
+ if (typeof value === "boolean" || typeof value === "number") {
163
+ return String(value);
164
+ }
165
+ return quoteLiteral(String(value));
166
+ }
167
+ /** The body of a property's `CHECK` constraint, or undefined when it has no bounds. */
168
+ export function checkExpression(property) {
169
+ const column = quoteIdentifier(columnName(property.name));
170
+ const conditions = [];
171
+ if (property.type === "text" || property.type === "email" || property.type === "url") {
172
+ if (property.maxLength !== undefined) {
173
+ conditions.push(`char_length(${column}) <= ${property.maxLength}`);
174
+ }
175
+ }
176
+ if (property.type === "integer" || property.type === "number") {
177
+ if (property.min !== undefined) {
178
+ conditions.push(`${column} >= ${property.min}`);
179
+ }
180
+ if (property.max !== undefined) {
181
+ conditions.push(`${column} <= ${property.max}`);
182
+ }
183
+ }
184
+ return conditions.length === 0 ? undefined : conditions.join(" AND ");
185
+ }
186
+ export function propertyColumn(entity, property) {
187
+ if (property.type === "list") {
188
+ throw new Error(`${entity}.${property.name} is a list, which has no column.`);
189
+ }
190
+ const type = property.type === "select"
191
+ ? quoteIdentifier(enumTypeName(entity, property.name))
192
+ : COLUMN_TYPES[property.type];
193
+ const defaultValue = defaultExpression(property);
194
+ return {
195
+ name: columnName(property.name),
196
+ type,
197
+ notNull: !property.optional,
198
+ ...(defaultValue !== undefined ? { default: defaultValue } : {}),
199
+ };
200
+ }
201
+ export function propertyCheck(entity, property) {
202
+ const expression = checkExpression(property);
203
+ if (expression === undefined) {
204
+ return undefined;
205
+ }
206
+ return {
207
+ name: checkConstraintName(entity, property.name),
208
+ kind: "check",
209
+ definition: `CHECK (${expression})`,
210
+ };
211
+ }
212
+ export function propertyEnum(entity, property) {
213
+ if (property.type !== "select") {
214
+ return undefined;
215
+ }
216
+ return {
217
+ name: enumTypeName(entity, property.name),
218
+ values: (property.options ?? []).map((option) => option.value),
219
+ };
220
+ }
221
+ function foreignKeyDefinition(input) {
222
+ const reference = `FOREIGN KEY (${quoteIdentifier(input.column)}) ` +
223
+ `REFERENCES ${quoteIdentifier(input.references)} (${quoteIdentifier(SYSTEM_COLUMNS.id)})`;
224
+ return input.onDelete === undefined ? reference : `${reference} ON DELETE ${input.onDelete}`;
225
+ }
226
+ export function blobForeignKey(entity, property) {
227
+ const column = columnName(property.name);
228
+ return {
229
+ name: foreignKeyName(entity, column),
230
+ kind: "foreignKey",
231
+ definition: foreignKeyDefinition({ column, references: "_blobs" }),
232
+ references: "_blobs",
233
+ };
234
+ }
235
+ function userReference(table, column) {
236
+ return {
237
+ name: foreignKeyName(table, column),
238
+ kind: "foreignKey",
239
+ definition: foreignKeyDefinition({ column, references: USER_TABLE }),
240
+ references: USER_TABLE,
241
+ };
242
+ }
243
+ /** The key column of a `rel.one`. */
244
+ export function relationshipColumn(relationship) {
245
+ return {
246
+ name: relationshipColumnName(relationship.name),
247
+ type: "uuid",
248
+ notNull: relationship.optional !== true,
249
+ };
250
+ }
251
+ /** The foreign key of a `rel.one`, with its `onDelete` action. */
252
+ export function relationshipForeignKey(entity, relationship) {
253
+ const column = relationshipColumnName(relationship.name);
254
+ const onDelete = ON_DELETE_ACTIONS[relationship.onDelete ?? "restrict"];
255
+ return {
256
+ name: foreignKeyName(tableName(entity), column),
257
+ kind: "foreignKey",
258
+ definition: foreignKeyDefinition({ column, references: tableName(relationship.to), onDelete }),
259
+ references: tableName(relationship.to),
260
+ };
261
+ }
262
+ /** The join table of a `rel.many`: both keys cascade, and the target key is indexed. */
263
+ export function joinTable(entity, relationship) {
264
+ const name = joinTableName(entity, relationship.name);
265
+ const keys = joinColumnNames({
266
+ entity,
267
+ relationship: relationship.name,
268
+ target: relationship.to,
269
+ });
270
+ return {
271
+ name,
272
+ columns: [
273
+ { name: keys.source, type: "uuid", notNull: true },
274
+ { name: keys.target, type: "uuid", notNull: true },
275
+ { name: SYSTEM_COLUMNS.created_at, type: "timestamptz", notNull: true, default: "now()" },
276
+ { name: SYSTEM_COLUMNS.created_by, type: "uuid", notNull: false },
277
+ ],
278
+ primaryKey: { name: primaryKeyName(name), columns: [keys.source, keys.target] },
279
+ constraints: [
280
+ {
281
+ name: foreignKeyName(name, keys.source),
282
+ kind: "foreignKey",
283
+ definition: foreignKeyDefinition({
284
+ column: keys.source,
285
+ references: tableName(entity),
286
+ onDelete: "CASCADE",
287
+ }),
288
+ references: tableName(entity),
289
+ },
290
+ {
291
+ name: foreignKeyName(name, keys.target),
292
+ kind: "foreignKey",
293
+ definition: foreignKeyDefinition({
294
+ column: keys.target,
295
+ references: tableName(relationship.to),
296
+ onDelete: "CASCADE",
297
+ }),
298
+ references: tableName(relationship.to),
299
+ },
300
+ userReference(name, SYSTEM_COLUMNS.created_by),
301
+ ],
302
+ indexes: [
303
+ {
304
+ name: indexName(name, [keys.target]),
305
+ table: name,
306
+ columns: [keys.target],
307
+ unique: false,
308
+ origin: `relationship ${entity}.${relationship.name}`,
309
+ },
310
+ ],
311
+ };
312
+ }
313
+ /** Covers rolling activity counts without reading the JSON history payloads. */
314
+ export function historyActivityIndex(entity) {
315
+ const table = historyTableName(entity);
316
+ return {
317
+ name: `${table}_activity_idx`,
318
+ table,
319
+ columns: ["at", "principal_id"],
320
+ unique: false,
321
+ origin: `activity of ${entity}`,
322
+ };
323
+ }
324
+ /** `<entity>_history`: one row per change to a record, written by the runtime. */
325
+ export function historyTable(entity) {
326
+ const name = historyTableName(entity);
327
+ const kinds = HISTORY_KINDS.map(quoteLiteral).join(", ");
328
+ return {
329
+ name,
330
+ columns: [
331
+ { name: "id", type: "uuid", notNull: true, default: "gen_random_uuid()" },
332
+ { name: "record_id", type: "uuid", notNull: true },
333
+ { name: "action", type: "text", notNull: true },
334
+ { name: "action_id", type: "uuid", notNull: true },
335
+ { name: "kind", type: "text", notNull: true },
336
+ { name: "principal_id", type: "uuid", notNull: false },
337
+ { name: "at", type: "timestamptz", notNull: true, default: "now()" },
338
+ { name: "changes", type: "jsonb", notNull: true },
339
+ ],
340
+ primaryKey: { name: primaryKeyName(name), columns: ["id"] },
341
+ constraints: [
342
+ {
343
+ name: `${name}_kind_check`,
344
+ kind: "check",
345
+ definition: `CHECK (${quoteIdentifier("kind")} IN (${kinds}))`,
346
+ },
347
+ ],
348
+ indexes: [
349
+ historyActivityIndex(entity),
350
+ {
351
+ name: indexName(name, ["record_id", "at"]),
352
+ table: name,
353
+ columns: ["record_id", "at"],
354
+ unique: false,
355
+ origin: `history of ${entity}`,
356
+ },
357
+ {
358
+ name: indexName(name, ["action_id"]),
359
+ table: name,
360
+ columns: ["action_id"],
361
+ unique: false,
362
+ origin: `history of ${entity}`,
363
+ },
364
+ ],
365
+ };
366
+ }
367
+ function systemColumns() {
368
+ return [
369
+ { name: SYSTEM_COLUMNS.id, type: "uuid", notNull: true, default: "gen_random_uuid()" },
370
+ { name: SYSTEM_COLUMNS.created_at, type: "timestamptz", notNull: true, default: "now()" },
371
+ { name: SYSTEM_COLUMNS.updated_at, type: "timestamptz", notNull: true, default: "now()" },
372
+ { name: SYSTEM_COLUMNS.created_by, type: "uuid", notNull: false },
373
+ { name: SYSTEM_COLUMNS.updated_by, type: "uuid", notNull: false },
374
+ ];
375
+ }
376
+ /**
377
+ * The indexes of an entity table: a unique index per unique property, an index per `rel.one` key and
378
+ * the declared indexes. A declared index over exactly one `rel.one` key has the key index's name and
379
+ * replaces it.
380
+ */
381
+ function entityIndexes(entity) {
382
+ const table = tableName(entity.name);
383
+ const declared = entity.indexes.map((index) => {
384
+ const columns = index.properties.map((field) => fieldColumnName(entity, field) ?? field);
385
+ return {
386
+ name: indexName(table, columns),
387
+ table,
388
+ columns,
389
+ unique: index.unique,
390
+ origin: `declared index (${index.properties.join(", ")})`,
391
+ };
392
+ });
393
+ const declaredNames = new Set(declared.map((index) => index.name));
394
+ const unique = entity.properties
395
+ .filter((property) => property.unique)
396
+ .map((property) => ({
397
+ name: uniqueIndexName(entity.name, property.name),
398
+ table,
399
+ columns: [columnName(property.name)],
400
+ unique: true,
401
+ origin: `${entity.name}.${property.name} is unique`,
402
+ }));
403
+ const keys = keyedRelationships(entity)
404
+ .map((relationship) => ({
405
+ name: indexName(table, [relationshipColumnName(relationship.name)]),
406
+ table,
407
+ columns: [relationshipColumnName(relationship.name)],
408
+ unique: false,
409
+ origin: `relationship ${entity.name}.${relationship.name}`,
410
+ }))
411
+ .filter((index) => !declaredNames.has(index.name));
412
+ return [...unique, ...keys, ...declared];
413
+ }
414
+ /**
415
+ * The `rel.one` relationships that have a key column and a foreign key: those between stored
416
+ * entities. A value-matched relationship is stored as the ordinary property its `on` names.
417
+ */
418
+ function keyedRelationships(entity) {
419
+ return entity.relationships.filter((relationship) => relationship.cardinality === "one" && !isValueMatched(relationship));
420
+ }
421
+ /** The table, history table, enum types and join tables of an entity. */
422
+ export function entityStorage(declared) {
423
+ const entity = storedEntity(declared);
424
+ const table = tableName(entity.name);
425
+ const ones = keyedRelationships(entity);
426
+ const manys = entity.relationships.filter((relationship) => relationship.cardinality === "many");
427
+ const checks = entity.properties.flatMap((property) => {
428
+ const check = propertyCheck(entity.name, property);
429
+ return check === undefined ? [] : [check];
430
+ });
431
+ return {
432
+ entity: entity.name,
433
+ table: {
434
+ name: table,
435
+ columns: [
436
+ ...systemColumns(),
437
+ ...entity.properties.map((property) => propertyColumn(entity.name, property)),
438
+ ...ones.map(relationshipColumn),
439
+ ],
440
+ primaryKey: { name: primaryKeyName(table), columns: [SYSTEM_COLUMNS.id] },
441
+ constraints: [
442
+ userReference(table, SYSTEM_COLUMNS.created_by),
443
+ userReference(table, SYSTEM_COLUMNS.updated_by),
444
+ ...checks,
445
+ ...entity.properties
446
+ .filter((property) => property.type === "blob")
447
+ .map((property) => blobForeignKey(entity.name, property)),
448
+ ...ones.map((relationship) => relationshipForeignKey(entity.name, relationship)),
449
+ ],
450
+ indexes: entityIndexes(entity),
451
+ },
452
+ history: historyTable(entity.name),
453
+ enums: entity.properties.flatMap((property) => {
454
+ const storage = propertyEnum(entity.name, property);
455
+ return storage === undefined ? [] : [storage];
456
+ }),
457
+ joins: manys.map((relationship) => joinTable(entity.name, relationship)),
458
+ };
459
+ }
460
+ /** The `_ontology` catalog table. */
461
+ export const CATALOG_TABLE_DDL = [
462
+ `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(CATALOG_TABLE)} (`,
463
+ ` "id" boolean NOT NULL DEFAULT true,`,
464
+ ` "version" integer NOT NULL,`,
465
+ ` "hash" text NOT NULL,`,
466
+ ` "manifest" jsonb NOT NULL,`,
467
+ ` "applied_at" timestamptz NOT NULL DEFAULT now(),`,
468
+ ` CONSTRAINT "${CATALOG_TABLE}_pkey" PRIMARY KEY ("id"),`,
469
+ ` CONSTRAINT "${CATALOG_TABLE}_id_check" CHECK ("id")`,
470
+ `)`,
471
+ ].join("\n");
472
+ /** Role assignments: the roles a user holds beyond the `member` every active member has. */
473
+ export const USER_ROLES_TABLE = "_user_roles";
474
+ /**
475
+ * API keys. A key is `ssk_<key id>.<secret>`: the key id is stored in clear to find the row, the
476
+ * secret only as a salted PBKDF2 hash.
477
+ */
478
+ export const API_KEYS_TABLE = "_api_keys";
479
+ /** OAuth clients that registered themselves to connect agents to the MCP server. */
480
+ export const OAUTH_CLIENTS_TABLE = "_oauth_clients";
481
+ /** Authorization requests waiting for a member's consent, for a few minutes. */
482
+ export const OAUTH_REQUESTS_TABLE = "_oauth_requests";
483
+ /** What a member allowed a client to do: revoking a grant stops its tokens. */
484
+ export const OAUTH_GRANTS_TABLE = "_oauth_grants";
485
+ /** Authorization codes, access tokens and refresh tokens, stored only as SHA-256 hashes. */
486
+ export const OAUTH_TOKENS_TABLE = "_oauth_tokens";
487
+ /** The OAuth tables, in the order they are created. */
488
+ export const OAUTH_TABLES = [
489
+ OAUTH_CLIENTS_TABLE,
490
+ OAUTH_REQUESTS_TABLE,
491
+ OAUTH_GRANTS_TABLE,
492
+ OAUTH_TOKENS_TABLE,
493
+ "_oauth_devices",
494
+ "_oauth_device_attempts",
495
+ ];
496
+ /** The OAuth tables of the MCP server's authorization server. Every statement is idempotent. */
497
+ export const OAUTH_TABLES_DDL = [
498
+ [
499
+ `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(OAUTH_CLIENTS_TABLE)} (`,
500
+ ` "id" text NOT NULL,`,
501
+ ` "name" text NOT NULL,`,
502
+ ` "redirect_uris" jsonb NOT NULL,`,
503
+ ` "auth_method" text NOT NULL,`,
504
+ ` "secret_hash" text,`,
505
+ ` "client_uri" text,`,
506
+ ` "created_at" timestamptz NOT NULL DEFAULT now(),`,
507
+ ` CONSTRAINT "${OAUTH_CLIENTS_TABLE}_pkey" PRIMARY KEY ("id")`,
508
+ `)`,
509
+ ].join("\n"),
510
+ [
511
+ `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(OAUTH_REQUESTS_TABLE)} (`,
512
+ ` "id" text NOT NULL,`,
513
+ ` "client_id" text NOT NULL,`,
514
+ ` "redirect_uri" text NOT NULL,`,
515
+ ` "state" text,`,
516
+ ` "code_challenge" text NOT NULL,`,
517
+ ` "scope" text NOT NULL,`,
518
+ ` "resource" text NOT NULL,`,
519
+ ` "expires_at" timestamptz NOT NULL,`,
520
+ ` CONSTRAINT "${OAUTH_REQUESTS_TABLE}_pkey" PRIMARY KEY ("id"),`,
521
+ ` CONSTRAINT "${OAUTH_REQUESTS_TABLE}_client_id_fkey" FOREIGN KEY ("client_id") ` +
522
+ `REFERENCES ${quoteIdentifier(OAUTH_CLIENTS_TABLE)} ("id") ON DELETE CASCADE`,
523
+ `)`,
524
+ ].join("\n"),
525
+ [
526
+ `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(OAUTH_GRANTS_TABLE)} (`,
527
+ ` "id" uuid NOT NULL,`,
528
+ ` "client_id" text NOT NULL,`,
529
+ ` "user_id" uuid NOT NULL,`,
530
+ ` "scope" text NOT NULL,`,
531
+ ` "resource" text NOT NULL,`,
532
+ ` "created_at" timestamptz NOT NULL DEFAULT now(),`,
533
+ ` "revoked_at" timestamptz,`,
534
+ ` CONSTRAINT "${OAUTH_GRANTS_TABLE}_pkey" PRIMARY KEY ("id"),`,
535
+ ` CONSTRAINT "${OAUTH_GRANTS_TABLE}_client_id_fkey" FOREIGN KEY ("client_id") ` +
536
+ `REFERENCES ${quoteIdentifier(OAUTH_CLIENTS_TABLE)} ("id") ON DELETE CASCADE,`,
537
+ ` CONSTRAINT "${OAUTH_GRANTS_TABLE}_user_id_fkey" FOREIGN KEY ("user_id") ` +
538
+ `REFERENCES ${quoteIdentifier(USER_TABLE)} ("id") ON DELETE CASCADE`,
539
+ `)`,
540
+ ].join("\n"),
541
+ `CREATE INDEX IF NOT EXISTS "${OAUTH_GRANTS_TABLE}_user_id_idx" ` +
542
+ `ON ${quoteIdentifier(OAUTH_GRANTS_TABLE)} ("user_id")`,
543
+ [
544
+ `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(OAUTH_TOKENS_TABLE)} (`,
545
+ ` "hash" text NOT NULL,`,
546
+ ` "grant_id" uuid NOT NULL,`,
547
+ ` "kind" text NOT NULL,`,
548
+ ` "redirect_uri" text,`,
549
+ ` "code_challenge" text,`,
550
+ ` "expires_at" timestamptz NOT NULL,`,
551
+ ` "used_at" timestamptz,`,
552
+ ` "created_at" timestamptz NOT NULL DEFAULT now(),`,
553
+ ` CONSTRAINT "${OAUTH_TOKENS_TABLE}_pkey" PRIMARY KEY ("hash"),`,
554
+ ` CONSTRAINT "${OAUTH_TOKENS_TABLE}_kind_check" CHECK ("kind" IN ('code', 'access', 'refresh')),`,
555
+ ` CONSTRAINT "${OAUTH_TOKENS_TABLE}_grant_id_fkey" FOREIGN KEY ("grant_id") ` +
556
+ `REFERENCES ${quoteIdentifier(OAUTH_GRANTS_TABLE)} ("id") ON DELETE CASCADE`,
557
+ `)`,
558
+ ].join("\n"),
559
+ `CREATE INDEX IF NOT EXISTS "${OAUTH_TOKENS_TABLE}_grant_id_idx" ` +
560
+ `ON ${quoteIdentifier(OAUTH_TOKENS_TABLE)} ("grant_id")`,
561
+ `ALTER TABLE "${OAUTH_GRANTS_TABLE}" ADD COLUMN IF NOT EXISTS "identity_id" uuid`,
562
+ `ALTER TABLE "_oauth_tokens" ADD COLUMN IF NOT EXISTS "replay" text`,
563
+ `ALTER TABLE "_oauth_tokens" ADD COLUMN IF NOT EXISTS "successor_hash" text`,
564
+ `CREATE TABLE IF NOT EXISTS "_oauth_devices" (
565
+ "hash" text PRIMARY KEY,
566
+ "user_code_hash" text NOT NULL UNIQUE,
567
+ "client_id" text NOT NULL REFERENCES "_oauth_clients" ("id") ON DELETE CASCADE,
568
+ "scope" text NOT NULL,
569
+ "resource" text NOT NULL,
570
+ "expires_at" timestamptz NOT NULL,
571
+ "interval" integer NOT NULL,
572
+ "next_poll_at" timestamptz NOT NULL DEFAULT now(),
573
+ "status" text NOT NULL DEFAULT 'pending',
574
+ "user_id" uuid REFERENCES "user" ("id") ON DELETE CASCADE
575
+ )`,
576
+ `CREATE TABLE IF NOT EXISTS "_oauth_device_attempts" (
577
+ "member_id" uuid PRIMARY KEY REFERENCES "user" ("id") ON DELETE CASCADE,
578
+ "window_at" timestamptz NOT NULL DEFAULT now(),
579
+ "attempts" integer NOT NULL DEFAULT 1
580
+ )`,
581
+ ];
582
+ /** Channel accounts waiting, for ten minutes, for a member to claim them with a short code. */
583
+ export const AGENT_PAIRINGS_TABLE = "_agent_pairings";
584
+ /**
585
+ * Channel accounts paired with members, as SDKs before `user_identity` read them. The built-in
586
+ * `user_identity` entity holds them now, with the same ids; this table is still written beside it
587
+ * so that an earlier SDK deployed again finds them. See docs/workspace-user-identities.md.
588
+ */
589
+ export const AGENT_IDENTITIES_TABLE = "_agent_identities";
590
+ /**
591
+ * When a provisioned channel account was last shown the first-contact notice, keyed by its
592
+ * `user_identity` id: operational state, not identity data. It has no foreign key, so that an
593
+ * earlier SDK may still drop the `user_identity` table it does not know.
594
+ */
595
+ export const IDENTITY_NOTICES_TABLE = "_identity_notices";
596
+ /** Durable fixed-window admission and turn counters. */
597
+ export const AGENT_COUNTERS_TABLE = "_agent_counters";
598
+ /** User-scoped channel lifecycle and trusted effective limits shared across entry points. */
599
+ export const CHANNEL_USERS_TABLE = "_channel_users";
600
+ export const CHANNEL_LIMITS_TABLE = "_channel_limits";
601
+ /** The agent's tables, in the order they are created. */
602
+ export const AGENT_TABLES = [
603
+ AGENT_PAIRINGS_TABLE,
604
+ AGENT_IDENTITIES_TABLE,
605
+ AGENT_COUNTERS_TABLE,
606
+ CHANNEL_USERS_TABLE,
607
+ CHANNEL_LIMITS_TABLE,
608
+ CONFIRMATION_TABLE,
609
+ IDENTITY_NOTICES_TABLE,
610
+ ];
611
+ /**
612
+ * The tables of the app's agent: pairing codes, stored only as SHA-256 hashes, the legacy channel
613
+ * identities they create, and the first-contact notices of `user_identity` channel accounts. An
614
+ * account and a member each have at most one live identity per provider. Every statement is
615
+ * idempotent.
616
+ */
617
+ export const AGENT_TABLES_DDL = [
618
+ ...CONFIRMATION_DDL,
619
+ [
620
+ `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(AGENT_PAIRINGS_TABLE)} (`,
621
+ ` "id" uuid NOT NULL,`,
622
+ ` "code_hash" text NOT NULL,`,
623
+ ` "provider" text NOT NULL,`,
624
+ ` "external_id" text NOT NULL,`,
625
+ ` "display" text,`,
626
+ ` "created_at" timestamptz NOT NULL DEFAULT now(),`,
627
+ ` "expires_at" timestamptz NOT NULL,`,
628
+ ` "consumed_at" timestamptz,`,
629
+ ` CONSTRAINT "${AGENT_PAIRINGS_TABLE}_pkey" PRIMARY KEY ("id"),`,
630
+ ` CONSTRAINT "${AGENT_PAIRINGS_TABLE}_code_hash_key" UNIQUE ("code_hash")`,
631
+ `)`,
632
+ ].join("\n"),
633
+ [
634
+ `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(AGENT_IDENTITIES_TABLE)} (`,
635
+ ` "id" uuid NOT NULL,`,
636
+ ` "provider" text NOT NULL,`,
637
+ ` "external_id" text NOT NULL,`,
638
+ ` "user_id" uuid NOT NULL,`,
639
+ ` "display" text,`,
640
+ ` "created_at" timestamptz NOT NULL DEFAULT now(),`,
641
+ ` "revoked_at" timestamptz,`,
642
+ ` CONSTRAINT "${AGENT_IDENTITIES_TABLE}_pkey" PRIMARY KEY ("id"),`,
643
+ ` CONSTRAINT "${AGENT_IDENTITIES_TABLE}_user_id_fkey" FOREIGN KEY ("user_id") ` +
644
+ `REFERENCES ${quoteIdentifier(USER_TABLE)} ("id") ON DELETE CASCADE`,
645
+ `)`,
646
+ ].join("\n"),
647
+ `ALTER TABLE "${AGENT_IDENTITIES_TABLE}" ADD COLUMN IF NOT EXISTS "origin" text NOT NULL DEFAULT 'paired'`,
648
+ `ALTER TABLE "${AGENT_IDENTITIES_TABLE}" ADD COLUMN IF NOT EXISTS "noticed_at" timestamptz`,
649
+ `ALTER TABLE "${AGENT_IDENTITIES_TABLE}" ADD COLUMN IF NOT EXISTS "notice_sha256" text`,
650
+ `CREATE TABLE IF NOT EXISTS "${AGENT_COUNTERS_TABLE}" (
651
+ "key" text NOT NULL,
652
+ "window_start" timestamptz NOT NULL,
653
+ "count" integer NOT NULL,
654
+ PRIMARY KEY ("key", "window_start")
655
+ )`,
656
+ `ALTER TABLE "${AGENT_COUNTERS_TABLE}" ADD COLUMN IF NOT EXISTS "notification_claim" uuid`,
657
+ `ALTER TABLE "${AGENT_COUNTERS_TABLE}" ADD COLUMN IF NOT EXISTS "notification_claimed_until" timestamptz`,
658
+ `ALTER TABLE "${AGENT_IDENTITIES_TABLE}" ADD COLUMN IF NOT EXISTS "username" text`,
659
+ `ALTER TABLE "${AGENT_IDENTITIES_TABLE}" ADD COLUMN IF NOT EXISTS "notice_version" text`,
660
+ `CREATE TABLE IF NOT EXISTS "${CHANNEL_USERS_TABLE}" (
661
+ "user_id" uuid PRIMARY KEY REFERENCES "${USER_TABLE}" ("id") ON DELETE CASCADE,
662
+ "created_via" text NOT NULL,
663
+ "blocked_at" timestamptz,
664
+ "on_new_user_completed_at" timestamptz
665
+ )`,
666
+ `INSERT INTO "${CHANNEL_USERS_TABLE}" ("user_id", "created_via")
667
+ SELECT DISTINCT ON ("user_id") "user_id", "provider" FROM "${AGENT_IDENTITIES_TABLE}"
668
+ WHERE "origin" = 'provisioned' ORDER BY "user_id", "created_at", "id"
669
+ ON CONFLICT ("user_id") DO NOTHING`,
670
+ `CREATE TABLE IF NOT EXISTS "${CHANNEL_LIMITS_TABLE}" (
671
+ "id" boolean PRIMARY KEY DEFAULT true CHECK ("id"),
672
+ "limits" jsonb NOT NULL
673
+ )`,
674
+ `CREATE INDEX IF NOT EXISTS "${AGENT_COUNTERS_TABLE}_window_idx" ` +
675
+ `ON "${AGENT_COUNTERS_TABLE}" ("window_start")`,
676
+ `CREATE INDEX IF NOT EXISTS "${AGENT_IDENTITIES_TABLE}_user_idx" ` +
677
+ `ON "${AGENT_IDENTITIES_TABLE}" ("user_id")`,
678
+ `CREATE UNIQUE INDEX IF NOT EXISTS "${AGENT_IDENTITIES_TABLE}_account_key" ` +
679
+ `ON ${quoteIdentifier(AGENT_IDENTITIES_TABLE)} ("provider", "external_id") ` +
680
+ `WHERE "revoked_at" IS NULL`,
681
+ `CREATE UNIQUE INDEX IF NOT EXISTS "${AGENT_IDENTITIES_TABLE}_member_key" ` +
682
+ `ON ${quoteIdentifier(AGENT_IDENTITIES_TABLE)} ("user_id", "provider") ` +
683
+ `WHERE "revoked_at" IS NULL`,
684
+ `CREATE TABLE IF NOT EXISTS "${IDENTITY_NOTICES_TABLE}" (
685
+ "identity_id" uuid PRIMARY KEY,
686
+ "noticed_at" timestamptz NOT NULL,
687
+ "notice_sha256" text,
688
+ "notice_version" text
689
+ )`,
690
+ ];
691
+ /**
692
+ * The runtime's own tables beside the catalog. They are created with it, after the entity tables
693
+ * because they refer to the built-in user table, and every statement is idempotent.
694
+ */
695
+ export const ACTION_ATTRIBUTION_TABLE = "_ontology_action_attribution";
696
+ /** Runtime audit metadata deliberately has no foreign key: deleted records retain their history. */
697
+ export const ACTION_ATTRIBUTION_DDL = [
698
+ `CREATE TABLE IF NOT EXISTS "${ACTION_ATTRIBUTION_TABLE}" (
699
+ "action_id" uuid PRIMARY KEY,
700
+ "execution" jsonb NOT NULL,
701
+ "at" timestamptz NOT NULL DEFAULT now()
702
+ )`,
703
+ ];
704
+ export const RUNTIME_TABLES_DDL = [
705
+ ...FEDERATION_TABLES_DDL,
706
+ ...ACTION_ATTRIBUTION_DDL,
707
+ [
708
+ `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(USER_ROLES_TABLE)} (`,
709
+ ` "user_id" uuid NOT NULL,`,
710
+ ` "role" text NOT NULL,`,
711
+ ` CONSTRAINT "${USER_ROLES_TABLE}_pkey" PRIMARY KEY ("user_id", "role"),`,
712
+ ` CONSTRAINT "${USER_ROLES_TABLE}_user_id_fkey" FOREIGN KEY ("user_id") ` +
713
+ `REFERENCES ${quoteIdentifier(USER_TABLE)} ("id") ON DELETE CASCADE`,
714
+ `)`,
715
+ ].join("\n"),
716
+ [
717
+ `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(API_KEYS_TABLE)} (`,
718
+ ` "id" uuid NOT NULL,`,
719
+ ` "user_id" uuid NOT NULL,`,
720
+ ` "key_id" text NOT NULL,`,
721
+ ` "salt" text NOT NULL,`,
722
+ ` "hash" text NOT NULL,`,
723
+ ` "label" text NOT NULL,`,
724
+ ` "created_at" timestamptz NOT NULL DEFAULT now(),`,
725
+ ` "revoked_at" timestamptz,`,
726
+ ` CONSTRAINT "${API_KEYS_TABLE}_pkey" PRIMARY KEY ("id"),`,
727
+ ` CONSTRAINT "${API_KEYS_TABLE}_key_id_key" UNIQUE ("key_id"),`,
728
+ ` CONSTRAINT "${API_KEYS_TABLE}_user_id_fkey" FOREIGN KEY ("user_id") ` +
729
+ `REFERENCES ${quoteIdentifier(USER_TABLE)} ("id") ON DELETE CASCADE`,
730
+ `)`,
731
+ ].join("\n"),
732
+ `CREATE INDEX IF NOT EXISTS "${API_KEYS_TABLE}_user_id_idx" ON ${quoteIdentifier(API_KEYS_TABLE)} ("user_id")`,
733
+ ...OAUTH_TABLES_DDL,
734
+ ...AGENT_TABLES_DDL,
735
+ ];
736
+ export function columnDefinition(column) {
737
+ const parts = [quoteIdentifier(column.name), column.type];
738
+ if (column.notNull) {
739
+ parts.push("NOT NULL");
740
+ }
741
+ if (column.default !== undefined) {
742
+ parts.push(`DEFAULT ${column.default}`);
743
+ }
744
+ return parts.join(" ");
745
+ }
746
+ export function constraintDefinition(constraint) {
747
+ return `CONSTRAINT ${quoteIdentifier(constraint.name)} ${constraint.definition}`;
748
+ }
749
+ /** `CREATE TABLE` with every column, the primary key and the given constraints. */
750
+ export function createTableStatement(table, constraints = table.constraints) {
751
+ const primaryKey = {
752
+ name: table.primaryKey.name,
753
+ definition: `PRIMARY KEY (${table.primaryKey.columns.map(quoteIdentifier).join(", ")})`,
754
+ };
755
+ const lines = [
756
+ ...table.columns.map(columnDefinition),
757
+ ...[primaryKey, ...constraints].map(constraintDefinition),
758
+ ];
759
+ return `CREATE TABLE ${quoteIdentifier(table.name)} (\n ${lines.join(",\n ")}\n)`;
760
+ }
761
+ export function createIndexStatement(index, options = {}) {
762
+ const unique = index.unique ? "UNIQUE " : "";
763
+ const concurrently = options.concurrently === true ? "CONCURRENTLY " : "";
764
+ const columns = index.columns.map(quoteIdentifier).join(", ");
765
+ return (`CREATE ${unique}INDEX ${concurrently}${quoteIdentifier(index.name)} ` +
766
+ `ON ${quoteIdentifier(index.table)} (${columns})`);
767
+ }
768
+ export function createEnumStatement(storage) {
769
+ const values = storage.values.map(quoteLiteral).join(", ");
770
+ return `CREATE TYPE ${quoteIdentifier(storage.name)} AS ENUM (${values})`;
771
+ }
772
+ export function addConstraintStatement(table, constraint) {
773
+ return `ALTER TABLE ${quoteIdentifier(table)} ADD ${constraintDefinition(constraint)}`;
774
+ }