@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,639 @@
1
+ import { BlobValue } from "../blob.js";
2
+ import { isWarehouseRecordId } from "./warehouse-query.js";
3
+ import { Schema, SchemaTransformation } from "effect";
4
+ import { wireStruct } from "../wire.js";
5
+ import { ScopedMetricQueryReason } from "./errors.js";
6
+ import { BatchErrorDetails } from "../errors.js";
7
+ import { METRIC_QUERY_FILTER_OPERATORS, ENTITY_METRIC_QUERY_FILTER_OPERATORS, filterValuesIssue, MAXIMUM_FILTER_VALUES, } from "../metric-filters.js";
8
+ import { acceptingEarlierMetricQueryNames } from "../legacy.js";
9
+ import { isValueMatched, OntologyManifestWire, ScopeManifest } from "../manifest.js";
10
+ import { entityQuerySchemas, projectedQueryResultSchema, queryLinks, } from "../query.js";
11
+ import { ValidationIssue as RuntimeValidationIssue } from "../runtime/errors.js";
12
+ import { Edit, HistoryEntry as RuntimeHistoryEntry } from "../runtime/history.js";
13
+ export { METRIC_QUERY_FILTER_OPERATORS, METRIC_QUERY_PERIOD_UNITS, METRIC_QUERY_PERIODS, ENTITY_METRIC_QUERY_FILTER_OPERATORS, } from "../metric-filters.js";
14
+ /** `lead` → `Lead`, `pilot_request` → `PilotRequest`: component names in the OpenAPI document. */
15
+ function pascalCase(name) {
16
+ return name
17
+ .split("_")
18
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
19
+ .join("");
20
+ }
21
+ function escapeRegExp(value) {
22
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
23
+ }
24
+ /**
25
+ * A struct that rejects keys it does not declare. Decoding ignores unknown keys by default, which
26
+ * would let a misspelled option pass silently. The JSON Schema says the same through a
27
+ * `patternProperties` entry that matches every undeclared key.
28
+ */
29
+ function closedStruct(fields, unknownKey) {
30
+ const declared = Object.keys(fields).map(escapeRegExp).join("|");
31
+ const undeclared = Schema.String.check(Schema.isPattern(new RegExp(`^(?!(?:${declared})$)`)));
32
+ return Schema.StructWithRest(Schema.Struct(fields), [
33
+ Schema.Record(undeclared, Schema.Never.annotate({ message: unknownKey })),
34
+ ]);
35
+ }
36
+ const Id = Schema.String.annotate({ format: "uuid" });
37
+ const Timestamp = Schema.String.annotate({ format: "date-time" });
38
+ /** A record id in a path: a UUID. */
39
+ export const IdParam = Schema.String.check(Schema.isUUID()).annotate({
40
+ description: "The record's id.",
41
+ });
42
+ /** An observation's opaque source-key identity, returned by its find tool. */
43
+ export const WarehouseIdParam = Schema.String.check(Schema.makeFilter(isWarehouseRecordId, {
44
+ toJsonSchema: () => ({ pattern: "^wr1_[A-Za-z0-9_-]{1,12000}$" }),
45
+ })).annotate({
46
+ description: "The opaque warehouse record id returned by find.",
47
+ });
48
+ /**
49
+ * The value schema of a property in records. It keeps the type and documentation but not the checks:
50
+ * a stored value that predates a tightened check still reads. Filters come from `src/query.ts`, and
51
+ * action inputs keep the full property schema.
52
+ */
53
+ function propertyValue(definition) {
54
+ const documentation = {
55
+ ...(definition.label !== undefined ? { title: definition.label } : {}),
56
+ ...(definition.description !== undefined ? { description: definition.description } : {}),
57
+ };
58
+ switch (definition.type) {
59
+ case "text":
60
+ return Schema.String.annotate(documentation);
61
+ case "email":
62
+ return Schema.String.annotate({ ...documentation, format: "email" });
63
+ case "url":
64
+ return Schema.String.annotate({ ...documentation, format: "uri" });
65
+ case "integer":
66
+ return Schema.Int.annotate(documentation);
67
+ case "number":
68
+ return Schema.Finite.annotate(documentation);
69
+ case "boolean":
70
+ return Schema.Boolean.annotate(documentation);
71
+ case "date":
72
+ return Schema.String.annotate({ ...documentation, format: "date" });
73
+ case "timestamp":
74
+ return Schema.String.annotate({ ...documentation, format: "date-time" });
75
+ case "select": {
76
+ const options = (definition.options ?? []).map((option) => Schema.Literal(option.value).annotate({
77
+ title: option.label,
78
+ ...(option.description !== undefined ? { description: option.description } : {}),
79
+ }));
80
+ return Schema.Union(options).annotate(documentation);
81
+ }
82
+ case "json":
83
+ return Schema.Json.annotate(documentation);
84
+ case "blob":
85
+ return BlobValue.annotate(documentation);
86
+ case "list":
87
+ return Schema.Array(Schema.String).annotate(documentation);
88
+ }
89
+ }
90
+ function recordFields(entity) {
91
+ if (entity.entity.definition.source !== undefined) {
92
+ return {
93
+ id: Schema.String,
94
+ ...Object.fromEntries(entity.properties.map(({ name, definition }) => [
95
+ name,
96
+ Schema.NullOr(propertyValue(definition)),
97
+ ])),
98
+ };
99
+ }
100
+ const fields = {
101
+ id: Id.annotate({ description: "The record's id." }),
102
+ created_at: Timestamp,
103
+ updated_at: Timestamp,
104
+ created_by: Schema.NullOr(Id).annotate({
105
+ description: "The user who created the record; null when the platform wrote it.",
106
+ }),
107
+ updated_by: Schema.NullOr(Id).annotate({
108
+ description: "The user who last updated the record; null when the platform wrote it.",
109
+ }),
110
+ };
111
+ for (const { name, definition } of entity.properties) {
112
+ const value = propertyValue(definition);
113
+ fields[name] = definition.optional ? Schema.NullOr(value) : value;
114
+ }
115
+ for (const { name, relationship } of entity.relationships) {
116
+ // A value-matched relationship's reference is the property its `on` names.
117
+ if (relationship.cardinality === "one" && !isValueMatched(relationship)) {
118
+ const key = Id.annotate({ description: relationship.description });
119
+ fields[`${name}_id`] = relationship.optional ? Schema.NullOr(key) : key;
120
+ }
121
+ }
122
+ return fields;
123
+ }
124
+ function splitList(value) {
125
+ return value
126
+ .split(",")
127
+ .map((part) => part.trim())
128
+ .filter((part) => part.length > 0);
129
+ }
130
+ /** `created_at:desc,email` as URL parameter, `[{ field, direction }]` once decoded. */
131
+ function orderByParam(orderBy) {
132
+ // URL parameters are documented by their encoded side, so the description goes on the string.
133
+ const encoded = Schema.String.annotate({
134
+ description: "Comma-separated fields, each optionally followed by :asc or :desc, as in created_at:desc,email.",
135
+ });
136
+ return encoded.pipe(Schema.decodeTo(orderBy, SchemaTransformation.transform({
137
+ decode: (value) => splitList(value).map((part) => {
138
+ const [field = "", direction] = part.split(":");
139
+ return { field, direction: direction ?? "asc" };
140
+ }),
141
+ encode: (orders) => orders.map(({ field, direction }) => `${field}:${direction ?? "asc"}`).join(","),
142
+ })));
143
+ }
144
+ /** `owner,tags` as URL parameter, `{ owner: true, tags: true }` once decoded. */
145
+ function includeParam(include) {
146
+ const encoded = Schema.String.annotate({
147
+ description: "Comma-separated relationships to include in each record, as in owner,tags.",
148
+ });
149
+ return encoded.pipe(Schema.decodeTo(include, SchemaTransformation.transform({
150
+ decode: (value) => Object.fromEntries(splitList(value).map((name) => [name, true])),
151
+ encode: (relationships) => Object.keys(relationships).join(","),
152
+ })));
153
+ }
154
+ /** Comma-separated selected base fields, validated against the entity. */
155
+ function selectedFieldsParam(select) {
156
+ return Schema.String.pipe(Schema.decodeTo(select, SchemaTransformation.transform({
157
+ decode: splitList,
158
+ encode: (fields) => fields.join(","),
159
+ })));
160
+ }
161
+ /** A filter as a JSON-encoded URL parameter. */
162
+ function whereParam(where) {
163
+ const encoded = Schema.String.annotate({
164
+ description: 'A JSON-encoded filter, as in {"status":{"eq":"new"}}.',
165
+ contentMediaType: "application/json",
166
+ });
167
+ return encoded.pipe(Schema.decodeTo(where, SchemaTransformation.fromJsonString()));
168
+ }
169
+ /** A record of every entity, built once so that the document reuses them. */
170
+ function recordSchemas(plan) {
171
+ return new Map(plan.entities.map(({ name, resolved: entity }) => [
172
+ name,
173
+ Schema.Struct(recordFields(entity)).annotate({
174
+ identifier: `${pascalCase(name)}Record`,
175
+ title: entity.entity.definition.label,
176
+ description: entity.entity.definition.description,
177
+ }),
178
+ ]));
179
+ }
180
+ /**
181
+ * The record and query schemas of every entity. Queries are `src/query.ts`'s, so the service and
182
+ * the runtime accept exactly the same language.
183
+ */
184
+ export function entitySchemas(plan) {
185
+ const records = recordSchemas(plan);
186
+ return new Map(plan.entities.map((planned) => [
187
+ planned.name,
188
+ schemasOf(plan, planned, (name) => records.get(name) ?? Schema.Never),
189
+ ]));
190
+ }
191
+ function schemasOf(plan, planned, recordOf) {
192
+ const { name, resolved } = planned;
193
+ const { manifest } = plan.ontology;
194
+ const pascal = pascalCase(name);
195
+ const record = recordOf(name);
196
+ const query = entityQuerySchemas(manifest, name, true, true);
197
+ const links = queryLinks(manifest, name, true);
198
+ const includedFields = {};
199
+ for (const link of links) {
200
+ const target = recordOf(link.target);
201
+ includedFields[link.name] = Schema.optionalKey(link.cardinality === "one" ? Schema.NullOr(target) : Schema.Array(target));
202
+ }
203
+ const result = links.length === 0
204
+ ? record
205
+ : Schema.Struct({ ...recordFields(resolved), ...includedFields }).annotate({
206
+ identifier: `${pascal}Result`,
207
+ description: `A ${resolved.entity.definition.label.toLowerCase()} with the relationships the query included.`,
208
+ });
209
+ const projectedRecord = Schema.Struct({
210
+ ...Object.fromEntries(Object.entries(recordFields(resolved)).map(([field, value]) => [
211
+ field,
212
+ field === "id" ? value : Schema.optionalKey(value),
213
+ ])),
214
+ ...includedFields,
215
+ }).annotate({ identifier: `${pascal}Projection` });
216
+ return {
217
+ record,
218
+ result,
219
+ query: query.query,
220
+ queryParams: wireStruct({
221
+ where: Schema.optionalKey(whereParam(query.where)),
222
+ orderBy: Schema.optionalKey(orderByParam(query.orderBy)),
223
+ select: Schema.optionalKey(selectedFieldsParam(query.select)),
224
+ include: Schema.optionalKey(includeParam(query.include)),
225
+ after: Schema.optionalKey(query.after),
226
+ limit: Schema.optionalKey(query.limit),
227
+ }, { orderBy: "order_by" }, "Unknown parameter"),
228
+ includeParams: {
229
+ include: Schema.optionalKey(includeParam(query.include)),
230
+ },
231
+ findResult: projectedQueryResultSchema(result, projectedRecord, true).annotate({
232
+ identifier: `${pascal}PageEncoded`,
233
+ }),
234
+ };
235
+ }
236
+ const HistoryLimit = Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 200 })).annotate({
237
+ description: "The page size, at most 200.",
238
+ });
239
+ /** The query parameters of a record's history. */
240
+ export const HistoryParams = {
241
+ after: Schema.optionalKey(Schema.String.annotate({ description: "The next_cursor of the previous page." })),
242
+ limit: Schema.optionalKey(HistoryLimit),
243
+ };
244
+ export const ValidationIssue = RuntimeValidationIssue.annotate({ identifier: "ValidationIssue" });
245
+ export const Validation = Schema.Struct({
246
+ ok: Schema.Boolean,
247
+ issues: Schema.Array(ValidationIssue),
248
+ }).annotate({ identifier: "Validation" });
249
+ export const HistoryEntry = RuntimeHistoryEntry.pipe(Schema.encodeKeys({ recordId: "record_id", actionId: "action_id", principalId: "principal_id" })).annotate({
250
+ identifier: "HistoryEntry",
251
+ description: "What one action changed on the record: the previous and new value of each property, " +
252
+ "relationship key or link.",
253
+ });
254
+ export const HistoryPage = Schema.Struct({
255
+ items: Schema.Array(HistoryEntry),
256
+ nextCursor: Schema.NullOr(Schema.String),
257
+ })
258
+ .pipe(Schema.encodeKeys({ nextCursor: "next_cursor" }))
259
+ .annotate({ identifier: "HistoryPage" });
260
+ const uploadOptions = {
261
+ idempotencyKey: Schema.optionalKey(Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(128))),
262
+ createIntent: Schema.optionalKey(Schema.String.check(Schema.isUUID())),
263
+ };
264
+ const ActionOptions = wireStruct({
265
+ ...uploadOptions,
266
+ validateOnly: Schema.optionalKey(Schema.Boolean.annotate({
267
+ description: "Validate the input and report issues without a write.",
268
+ })),
269
+ }, {
270
+ validateOnly: "validate_only",
271
+ idempotencyKey: "idempotency_key",
272
+ createIntent: "create_intent",
273
+ });
274
+ /** The body of `POST /<entity>/actions/<action>`, as documented. */
275
+ export function actionRequest(input) {
276
+ return Schema.Struct({ input, options: Schema.optionalKey(ActionOptions) });
277
+ }
278
+ /** The body of `POST /<entity>/actions/<action>`, as decoded: `runAction` validates the input. */
279
+ export const ActionEnvelope = closedStruct({
280
+ input: Schema.Unknown,
281
+ options: Schema.optionalKey(wireStruct({ validateOnly: Schema.optionalKey(Schema.Boolean), ...uploadOptions }, {
282
+ validateOnly: "validate_only",
283
+ idempotencyKey: "idempotency_key",
284
+ createIntent: "create_intent",
285
+ })),
286
+ }, "Unknown key; use input and options");
287
+ export const ActionResponse = Schema.Struct({
288
+ result: Schema.Unknown.annotate({ description: "What the action returned." }),
289
+ validation: Validation,
290
+ edits: Schema.Array(Edit.annotate({ identifier: "Edit" })).annotate({
291
+ description: "The records the action changed, as their history records each change.",
292
+ }),
293
+ }).annotate({ identifier: "ActionResponse" });
294
+ export const Catalog = OntologyManifestWire.annotate({ identifier: "Catalog" });
295
+ const GraphEntity = Schema.Struct({
296
+ name: Schema.String,
297
+ label: Schema.String,
298
+ plural: Schema.String,
299
+ description: Schema.String,
300
+ });
301
+ const GraphRelationship = Schema.Struct({
302
+ from: Schema.String,
303
+ name: Schema.String,
304
+ to: Schema.String,
305
+ inverse: Schema.String,
306
+ cardinality: Schema.Literals(["one", "many"]),
307
+ /** The property pair of a relationship matched by value: one with a warehouse-backed end. */
308
+ on: Schema.optionalKey(Schema.Struct({ property: Schema.String, targetProperty: Schema.String }).pipe(Schema.encodeKeys({ targetProperty: "target_property" }))),
309
+ optional: Schema.Boolean,
310
+ phrase: Schema.Tuple([Schema.String, Schema.String]),
311
+ forward: Schema.String.annotate({ examples: ["Lead is owned by one User"] }),
312
+ backward: Schema.String.annotate({ examples: ["User owns many Leads"] }),
313
+ description: Schema.String,
314
+ });
315
+ export const Graph = Schema.Struct({
316
+ hash: Schema.String,
317
+ entities: Schema.Array(GraphEntity),
318
+ relationships: Schema.Array(GraphRelationship),
319
+ }).annotate({ identifier: "Graph" });
320
+ export const Status = Schema.Struct({
321
+ deployment: Schema.optionalKey(Schema.Struct({
322
+ target: Schema.Literals(["production", "preview"]),
323
+ deploymentId: Schema.optionalKey(Schema.String),
324
+ expiresAt: Schema.optionalKey(Schema.String),
325
+ capabilities: Schema.Struct({
326
+ warehouseRead: Schema.Boolean,
327
+ pipelineRuns: Schema.Boolean,
328
+ connections: Schema.Boolean,
329
+ agents: Schema.Boolean,
330
+ workflows: Schema.Boolean,
331
+ }),
332
+ })),
333
+ hash: Schema.String.annotate({ description: "The hash of the manifest this service serves." }),
334
+ appliedHash: Schema.NullOr(Schema.String).annotate({
335
+ description: "The manifest hash recorded by the last migration of the workspace database.",
336
+ }),
337
+ upToDate: Schema.Boolean.annotate({ description: "Whether the two hashes match." }),
338
+ })
339
+ .pipe(Schema.encodeKeys({ appliedHash: "applied_hash", upToDate: "up_to_date" }))
340
+ .annotate({ identifier: "Status" });
341
+ /** The longest address `POST /api/ontology/sign-in/check` reads; RFC 5321 allows 254. */
342
+ export const SIGN_IN_CHECK_MAX_EMAIL_LENGTH = 320;
343
+ /** `POST /api/ontology/sign-in/check`: the address a person wants to sign in with. */
344
+ export const SignInCheckRequest = Schema.Struct({
345
+ email: Schema.String.check(Schema.isMaxLength(SIGN_IN_CHECK_MAX_EMAIL_LENGTH)).annotate({
346
+ description: "The address the person typed, in any case.",
347
+ }),
348
+ }).annotate({ identifier: "SignInCheckRequest" });
349
+ /** The bounds of a model-level metric query (docs/ontology-aggregates-spec.md, "Request"). */
350
+ export const METRIC_QUERY_LIMITS = {
351
+ metrics: 30,
352
+ dimensions: 20,
353
+ filters: 50,
354
+ values: MAXIMUM_FILTER_VALUES,
355
+ orderBy: 50,
356
+ rows: 1000,
357
+ };
358
+ /**
359
+ * The granularities a date or timestamp dimension buckets by; `hour` applies to timestamps only.
360
+ */
361
+ export const METRIC_QUERY_GRANULARITIES = [
362
+ "hour",
363
+ "day",
364
+ "week",
365
+ "month",
366
+ "quarter",
367
+ "year",
368
+ ];
369
+ /** The longest `timezone` a request names. */
370
+ export const MAXIMUM_TIMEZONE_LENGTH = 64;
371
+ const MetricQueryValue = Schema.Union([Schema.String, Schema.Number, Schema.Boolean]);
372
+ /**
373
+ * A filter of either request. Which values each operator takes is checked with SegmentStream's own
374
+ * messages (`filterValuesIssue`); whether they suit the dimension's type is SegmentStream's to check.
375
+ */
376
+ function metricQueryFilter(operators, descriptions) {
377
+ const filter = closedStruct({
378
+ dimension: Schema.String.annotate({
379
+ description: "A property, or a path of to-one relationships ending in one.",
380
+ }),
381
+ operator: Schema.Literals(operators),
382
+ value: Schema.optionalKey(MetricQueryValue).annotate({ description: descriptions.value }),
383
+ values: Schema.optionalKey(Schema.Array(MetricQueryValue).check(Schema.isMaxLength(METRIC_QUERY_LIMITS.values))).annotate({ description: descriptions.values }),
384
+ }, "Unknown key; use dimension, operator, value and values");
385
+ return filter.check(Schema.makeFilter((candidate) => filterValuesIssue(candidate) ?? true));
386
+ }
387
+ const MetricQueryOrder = closedStruct({
388
+ metric: Schema.optionalKey(Schema.String),
389
+ dimension: Schema.optionalKey(Schema.String),
390
+ direction: Schema.Literals(["asc", "desc"]),
391
+ }, "Unknown key; use metric or dimension, and direction");
392
+ /** The fields both metric queries share, with their bounds. */
393
+ const metricQueryFields = {
394
+ granularity: Schema.optionalKey(Schema.Literals(METRIC_QUERY_GRANULARITIES)),
395
+ granularityOf: Schema.optionalKey(Schema.String).annotate({
396
+ description: "The requested date or timestamp dimension that granularity buckets.",
397
+ }),
398
+ timezone: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(MAXIMUM_TIMEZONE_LENGTH))).annotate({
399
+ description: "An IANA timezone, such as Europe/Moscow, or UTC. Buckets of timestamps, date bounds on " +
400
+ "timestamps and inPeriod's today follow it instead of each entity's timezone; metric " +
401
+ "conditions never do.",
402
+ }),
403
+ orderBy: Schema.optionalKey(Schema.Array(MetricQueryOrder).check(Schema.isMaxLength(METRIC_QUERY_LIMITS.orderBy))),
404
+ limit: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: METRIC_QUERY_LIMITS.rows }))).annotate({ description: "At most 1000 rows; 100 by default." }),
405
+ };
406
+ /**
407
+ * `POST /api/ontology/query_metrics`, as documented: the current names only. The service checks the
408
+ * shape and the bounds, resolves the names against its manifest and forwards the body with the
409
+ * current names; SegmentStream checks everything else.
410
+ */
411
+ export const MetricQueryBody = closedStruct({
412
+ metrics: Schema.Array(Schema.String)
413
+ .check(Schema.isMaxLength(METRIC_QUERY_LIMITS.metrics))
414
+ .annotate({
415
+ description: "<entity>.<metric>, or a metric of the model by its name, such as plan_attainment; " +
416
+ "at least one, at most 30 of both together.",
417
+ }),
418
+ dimensions: Schema.optionalKey(Schema.Array(Schema.String).check(Schema.isMaxLength(METRIC_QUERY_LIMITS.dimensions))).annotate({
419
+ description: "<entity>.<property>, or a route from a metric's entity: " +
420
+ "<entity>.<relationship>[.<relationship>].<property>.",
421
+ }),
422
+ filters: Schema.optionalKey(Schema.Array(metricQueryFilter(METRIC_QUERY_FILTER_OPERATORS, {
423
+ value: "The value of equals and notEquals; the bound of gt, gte, lt and lte; a non-empty " +
424
+ "string for contains, startsWith and endsWith; the period of inPeriod, such as " +
425
+ "last 7 days.",
426
+ values: "The values of in and notIn, or the two inclusive bounds of between.",
427
+ })).check(Schema.isMaxLength(METRIC_QUERY_LIMITS.filters))).annotate({ description: "All must hold." }),
428
+ ...metricQueryFields,
429
+ }, "Unknown key; use metrics, dimensions, filters, granularity, granularityOf, timezone, orderBy " +
430
+ "and limit").annotate({ identifier: "MetricQuery" });
431
+ /** `POST /api/ontology/query_metrics` as decoded: the documented body, or one with earlier names. */
432
+ export const MetricQuery = acceptingEarlierMetricQueryNames(MetricQueryBody);
433
+ /**
434
+ * `POST /api/ontology/<entity>/query_metrics`: SegmentStream's per-entity request, as documented. Names
435
+ * are relative to the entity (`revenue`, `product.brand`), and `dateRange` bounds a partitioned
436
+ * entity.
437
+ */
438
+ export const EntityMetricQueryBody = closedStruct({
439
+ dimensions: Schema.Array(Schema.String)
440
+ .check(Schema.isMaxLength(METRIC_QUERY_LIMITS.dimensions))
441
+ .annotate({
442
+ description: "A property, or a path of to-one relationships: product.brand.",
443
+ }),
444
+ metrics: Schema.Array(Schema.String)
445
+ .check(Schema.isMaxLength(METRIC_QUERY_LIMITS.metrics))
446
+ .annotate({ description: "The entity's metrics, at least one." }),
447
+ dateRange: Schema.optionalKey(closedStruct({
448
+ from: Schema.String.annotate({ format: "date" }),
449
+ to: Schema.String.annotate({ format: "date" }),
450
+ }, "Unknown key; use from and to")).annotate({ description: "Inclusive days of the entity's partition property." }),
451
+ filters: Schema.optionalKey(Schema.Array(metricQueryFilter(ENTITY_METRIC_QUERY_FILTER_OPERATORS, {
452
+ value: "The value of equals and notEquals; the bound of gt, gte, lt and lte; a non-empty " +
453
+ "string for contains, startsWith and endsWith.",
454
+ values: "The values of in and notIn.",
455
+ })).check(Schema.isMaxLength(METRIC_QUERY_LIMITS.filters))).annotate({ description: "All must hold." }),
456
+ ...metricQueryFields,
457
+ }, "Unknown key; use dimensions, metrics, dateRange, filters, granularity, granularityOf, " +
458
+ "timezone, orderBy and limit").annotate({ identifier: "EntityMetricQuery" });
459
+ /** `POST /api/ontology/<entity>/query_metrics` as decoded, earlier names included. */
460
+ export const EntityMetricQuery = acceptingEarlierMetricQueryNames(EntityMetricQueryBody);
461
+ /** SegmentStream's answer to a metric query, which the service forwards unchanged. */
462
+ export const MetricQueryResult = Schema.Struct({
463
+ fields: Schema.Array(Schema.Struct({
464
+ name: Schema.String.annotate({
465
+ description: "A dimension identity, <entity>.<metric>, or the name of a metric of the model.",
466
+ }),
467
+ label: Schema.String,
468
+ type: Schema.String,
469
+ unit: Schema.optionalKey(Schema.String),
470
+ format: Schema.optionalKey(Schema.String),
471
+ scope: Schema.optionalKey(Schema.Array(Schema.String)),
472
+ implicit: Schema.optionalKey(Schema.Boolean),
473
+ additive: Schema.optionalKey(Schema.Boolean).annotate({
474
+ description: "false when the metric's rows do not add up to a total.",
475
+ }),
476
+ filters: Schema.optionalKey(Schema.Array(Schema.String)).annotate({
477
+ description: "The filters the metric applied.",
478
+ }),
479
+ balanceOver: Schema.optionalKey(Schema.String).annotate({
480
+ description: "The date or timestamp dimension a balance metric was grouped by or filtered to one " +
481
+ "day of.",
482
+ }),
483
+ inputs: Schema.optionalKey(Schema.Array(Schema.String)).annotate({
484
+ description: "The entity metrics a metric of the model reads, <entity>.<metric>, in declaration " +
485
+ "order; present only on such a metric.",
486
+ }),
487
+ })),
488
+ rows: Schema.Array(Schema.Record(Schema.String, Schema.NullOr(Schema.Union([Schema.String, Schema.Boolean])))),
489
+ truncated: Schema.Boolean,
490
+ execution: Schema.Struct({
491
+ elapsedMs: Schema.Number,
492
+ bytesProcessed: Schema.optionalKey(Schema.String),
493
+ bytesBilled: Schema.optionalKey(Schema.String),
494
+ warnings: Schema.optionalKey(Schema.Array(Schema.String)).annotate({
495
+ description: "For example, a filter that did not apply to some metric's entity.",
496
+ }),
497
+ sources: Schema.optionalKey(Schema.Array(Schema.Struct({ entity: Schema.String, asOf: Schema.String }))).annotate({
498
+ // @legacy ontology.replication-verification-remnants
499
+ description: "Historical destination observations from older servers; current servers omit this field.",
500
+ }),
501
+ periods: Schema.optionalKey(Schema.Array(Schema.Struct({
502
+ dimension: Schema.String,
503
+ value: Schema.String,
504
+ from: Schema.String.annotate({ format: "date" }),
505
+ to: Schema.String.annotate({ format: "date" }),
506
+ timezone: Schema.String,
507
+ }))).annotate({ description: "The inclusive dates each inPeriod filter used, in request order." }),
508
+ }),
509
+ deploymentId: Schema.NullOr(Schema.String),
510
+ definitionDigest: Schema.String,
511
+ }).annotate({ identifier: "MetricQueryResult" });
512
+ /** Whether the address may sign in, and with a code or a link. */
513
+ export const SignInCheckResult = Schema.Union([
514
+ Schema.Struct({ allowed: Schema.Literal(false) }),
515
+ Schema.Struct({
516
+ allowed: Schema.Literal(true),
517
+ method: Schema.Literals(["code", "link"]).annotate({
518
+ description: "code: the member has a Neon Auth account and gets a six-digit code. link: they get a " +
519
+ "sign-in link, which creates the account.",
520
+ }),
521
+ }),
522
+ ]).annotate({ identifier: "SignInCheckResult" });
523
+ /** `GET /api/ontology/me`: who the caller is and what they may do, for the app to render. */
524
+ export const Me = Schema.Struct({
525
+ authentication: Schema.Struct({
526
+ kind: Schema.Literals(["member", "oauth", "runtime", "service", "workload", "unverified"]),
527
+ client: Schema.NullOr(Schema.Struct({ id: Schema.String, name: Schema.String })),
528
+ scope: Schema.NullOr(Schema.String),
529
+ }),
530
+ attribution: Schema.NullOr(Schema.String),
531
+ attribution_separator: Schema.optionalKey(Schema.String),
532
+ user: Schema.Struct({
533
+ id: Id.annotate({ description: "The caller's user id: principalId in history." }),
534
+ name: Schema.String,
535
+ email: Schema.NullOr(Schema.String).annotate({
536
+ description: "The member's sign-in address; null for services and members without one.",
537
+ }),
538
+ kind: Schema.Literals(["member", "service"]),
539
+ active: Schema.Boolean,
540
+ }),
541
+ roles: Schema.Array(Schema.String).annotate({
542
+ description: "The roles the caller holds; every member holds member.",
543
+ }),
544
+ permissions: Schema.Array(Schema.String).annotate({
545
+ description: "The permissions those roles grant in this ontology, wildcards included.",
546
+ }),
547
+ scopes: Schema.optionalKey(Schema.Array(ScopeManifest).annotate({
548
+ description: "The permissions held only for the records their where matches, as the manifest's " +
549
+ 'roles[].scopes writes them: { "$me": [...] } is the caller or a path from them. ' +
550
+ "Absent when none is scoped.",
551
+ })),
552
+ }).annotate({ identifier: "Me" });
553
+ export const AsParams = {
554
+ as: Schema.optionalKey(Schema.Literal("me").annotate({
555
+ description: "me: list only the actions the caller's permissions may run.",
556
+ })),
557
+ };
558
+ const Count = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
559
+ /** The platform limit that refused a file upload or attachment, so a caller can explain it. */
560
+ const LimitErrorWire = Schema.Union([
561
+ Schema.Struct({
562
+ kind: Schema.Literal("storage_quota"),
563
+ used_bytes: Count,
564
+ requested_bytes: Count,
565
+ quota_bytes: Count,
566
+ }),
567
+ Schema.Struct({
568
+ kind: Schema.Literal("pending_uploads"),
569
+ pending: Count,
570
+ max: Count,
571
+ uploads: Schema.optionalKey(Schema.Array(Schema.Struct({ id: Schema.String, filename: Schema.String, expires_at: Schema.String }))),
572
+ }),
573
+ Schema.Struct({ kind: Schema.Literal("member_attachments"), live: Count, max: Count }),
574
+ ]).annotate({ identifier: "LimitError" });
575
+ function errorBody(identifier, status, codes, extra = {}) {
576
+ return Schema.Struct({
577
+ error: Schema.Literals(codes),
578
+ detail: Schema.String,
579
+ requestId: Schema.String.annotate({ description: "Quote it when reporting a problem." }),
580
+ ...extra,
581
+ })
582
+ .pipe(Schema.encodeKeys({ requestId: "request_id" }))
583
+ .annotate({ identifier, httpApiStatus: status });
584
+ }
585
+ export const ErrorSchemas = {
586
+ invalidRequest: errorBody("InvalidRequest", 400, ["invalid_request", "invalid_json"], {
587
+ suggestions: Schema.optionalKey(Schema.Array(Schema.String)),
588
+ issues: Schema.optionalKey(Schema.Array(ValidationIssue)),
589
+ }),
590
+ unauthorized: errorBody("Unauthorized", 401, ["unauthorized"]),
591
+ forbidden: errorBody("Forbidden", 403, ["forbidden"], {
592
+ entity: Schema.optionalKey(Schema.String),
593
+ permission: Schema.optionalKey(Schema.String),
594
+ batch: Schema.optionalKey(BatchErrorDetails),
595
+ }),
596
+ notInvited: errorBody("NotInvited", 403, ["not_invited"]),
597
+ notFound: errorBody("NotFound", 404, ["not_found"], {
598
+ suggestions: Schema.optionalKey(Schema.Array(Schema.String)),
599
+ entity: Schema.optionalKey(Schema.String),
600
+ id: Schema.optionalKey(Schema.String),
601
+ batch: Schema.optionalKey(BatchErrorDetails),
602
+ }),
603
+ conflict: errorBody("Conflict", 409, ["conflict"], {
604
+ entity: Schema.optionalKey(Schema.String),
605
+ property: Schema.optionalKey(Schema.String),
606
+ batch: Schema.optionalKey(BatchErrorDetails),
607
+ retryable: Schema.optionalKey(Schema.Boolean),
608
+ retry_after: Schema.optionalKey(Schema.Int),
609
+ }),
610
+ unsupportedMediaType: errorBody("UnsupportedMediaType", 415, ["unsupported_media_type"]),
611
+ unprocessable: errorBody("Unprocessable", 422, ["invalid_input", "action_rejected"], {
612
+ issues: Schema.Array(ValidationIssue),
613
+ batch: Schema.optionalKey(BatchErrorDetails),
614
+ limit: Schema.optionalKey(LimitErrorWire),
615
+ }),
616
+ rateLimited: errorBody("RateLimited", 429, ["rate_limited"]),
617
+ internal: errorBody("InternalError", 500, ["internal_error"]),
618
+ unavailable: errorBody("ServiceUnavailable", 503, ["service_unavailable"]),
619
+ storageUnavailable: errorBody("StorageUnavailable", 503, ["storage_unavailable", "ontology_updating"], { retryable: Schema.Boolean }),
620
+ invalidMetricQuery: errorBody("InvalidMetricQuery", 400, ["invalid_aggregate_query"]),
621
+ readForbidden: errorBody("ReadForbidden", 403, ["forbidden", "scoped_aggregate_unavailable"], {
622
+ permissions: Schema.optionalKey(Schema.Array(Schema.String)),
623
+ entity: Schema.optionalKey(Schema.String),
624
+ // Why a scoped metric query was refused, a code for the workspace to word.
625
+ reason: Schema.optionalKey(ScopedMetricQueryReason),
626
+ }),
627
+ metricQueriesUnavailable: errorBody("MetricQueriesUnavailable", 503, ["aggregate_unavailable"], {
628
+ retryable: Schema.Boolean,
629
+ }),
630
+ warehouseReadUnavailable: errorBody("WarehouseReadUnavailable", 503, ["warehouse_read_unavailable"], {
631
+ retryable: Schema.Boolean,
632
+ }),
633
+ metricQueryUpstreamUnavailable: errorBody("MetricQueryUpstreamUnavailable", 502, ["aggregate_upstream_unavailable"], { retryable: Schema.Boolean }),
634
+ connectionRequired: errorBody("ConnectionRequired", 409, ["connection_authorization_required", "connections_not_deployed"], { connection: Schema.String }),
635
+ connectionResponseInvalid: errorBody("ConnectionResponseInvalid", 502, [
636
+ "connection_response_invalid",
637
+ ]),
638
+ connectionUnavailable: errorBody("ConnectionUnavailable", 503, ["connection_unavailable", "connection_refused"], { connection: Schema.String, retryable: Schema.Boolean }),
639
+ };
@@ -0,0 +1,21 @@
1
+ import type { Ontology } from "../ontology.js";
2
+ import { type OntologyApi } from "./api.js";
3
+ import { type OntologyServiceConfig } from "./config.js";
4
+ /** The header every response carries: the hash of the manifest the service serves. */
5
+ export declare const ONTOLOGY_HASH_HEADER = "x-ontology-hash";
6
+ /** The header every response carries: the correlation id quoted in error bodies and logs. */
7
+ export declare const REQUEST_ID_HEADER = "x-request-id";
8
+ export interface OntologyService {
9
+ /** Answers one request; what the workspace deployment's Nitro entry calls. */
10
+ readonly handler: (request: Request) => Promise<Response>;
11
+ readonly api: OntologyApi;
12
+ /** Closes the database pool and the other resources the runtime opened. */
13
+ readonly dispose: () => Promise<void>;
14
+ }
15
+ /**
16
+ * The ontology service: the derived HttpApi, the MCP server at `/mcp` and the agent's pairing routes,
17
+ * wired to the runtime, behind Neon Auth, app-token, API-key and runtime-token authentication.
18
+ * Every response carries `x-ontology-hash`
19
+ * and `x-request-id`; failures answer with a JSON error and never a stack or SQL.
20
+ */
21
+ export declare function createOntologyService(ontology: Ontology, config: OntologyServiceConfig): OntologyService;