@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,53 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { type AgentTaskResult, type AgentTaskStart, type AgentTaskStarted } from "../../agent-task-contract.js";
3
+ import type { AgentTaskStore } from "../../runtime/agent-tasks.js";
4
+ /**
5
+ * The agent's task route. The deployment routes `/eve/*` to the app's agent, and eve reserves
6
+ * `/eve/v1/*`, so the route sits beside it.
7
+ */
8
+ export declare const AGENT_TASK_ROUTE = "/eve/segmentstream/v1/tasks";
9
+ /** A new task secret: 32 random bytes, base64url. */
10
+ export declare function newTaskSecret(): string;
11
+ /** The SHA-256 of a task secret, as `_agent_tasks` stores it and its header is looked up by. */
12
+ export declare function taskSecretSha256(secret: string): string;
13
+ /** How the start step reaches the app's agent: `fetch` by default. */
14
+ export type AgentTransport = (request: Request) => Promise<Response>;
15
+ declare const AgentTaskUnanswered_base: Schema.Class<AgentTaskUnanswered, Schema.TaggedStruct<"AgentTaskUnanswered", {
16
+ readonly message: Schema.String;
17
+ readonly cause: Schema.optionalKey<Schema.Unknown>;
18
+ }>, import("effect/Cause").YieldableError>;
19
+ /** The agent did not take the task: no answer, a server error, or a refusal while pending. Retried. */
20
+ export declare class AgentTaskUnanswered extends AgentTaskUnanswered_base {
21
+ }
22
+ declare const AgentTaskRefused_base: Schema.Class<AgentTaskRefused, Schema.TaggedStruct<"AgentTaskRefused", {
23
+ readonly message: Schema.String;
24
+ }>, import("effect/Cause").YieldableError>;
25
+ /** The agent refused the task in a way a retry repeats, such as a rejected token. Not retried. */
26
+ export declare class AgentTaskRefused extends AgentTaskRefused_base {
27
+ }
28
+ export interface AgentTaskStartContext {
29
+ readonly store: AgentTaskStore;
30
+ /** The deployment's production origin; `undefined` outside production. */
31
+ readonly origin: string | undefined;
32
+ /** The service's own Vercel OIDC token; `undefined` outside a Vercel function. */
33
+ readonly identityToken: string | undefined;
34
+ /** Whether the service verifies the agent's runtime token, without which no task authenticates. */
35
+ readonly runtimeIdentity: boolean;
36
+ readonly transport: AgentTransport;
37
+ /** The workflow's wire name, whose user the task acts as. */
38
+ readonly workflow: string;
39
+ readonly runId: string;
40
+ }
41
+ /**
42
+ * `agentTask`'s start step: refuses as `busy` when 10 tasks are live, records the task under its
43
+ * hook token, mints its secret and hands it to the agent, which answers `202` once its session has
44
+ * accepted the prompt. A retried step finds the task: started or terminal, it is not handed again;
45
+ * still pending, it gets a new secret and is handed again. `404` means the deployment has no agent
46
+ * that takes tasks; no answer, `5xx` and a `409` while the task is still pending are retried.
47
+ * Outside production, or without the tokens a task needs, the agent is not called. The secret is
48
+ * sent to the agent only: it is never returned, logged or stored.
49
+ */
50
+ export declare function startAgentTask(context: AgentTaskStartContext, input: AgentTaskStart): Effect.Effect<AgentTaskStarted, AgentTaskUnanswered | AgentTaskRefused>;
51
+ /** Times a task out unless it already ended; its terminal outcome, which the workflow returns. */
52
+ export declare function expireAgentTask(store: AgentTaskStore, taskId: string): Effect.Effect<AgentTaskResult>;
53
+ export {};
@@ -0,0 +1,161 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { Effect, Schema } from "effect";
3
+ import { MAX_LIVE_AGENT_TASKS, } from "../../agent-task-contract.js";
4
+ /**
5
+ * The agent's task route. The deployment routes `/eve/*` to the app's agent, and eve reserves
6
+ * `/eve/v1/*`, so the route sits beside it.
7
+ */
8
+ export const AGENT_TASK_ROUTE = "/eve/segmentstream/v1/tasks";
9
+ /** How long the agent has to accept a task before the attempt counts as unanswered. */
10
+ const AGENT_TIMEOUT_MS = 30_000;
11
+ /** A new task secret: 32 random bytes, base64url. */
12
+ export function newTaskSecret() {
13
+ return randomBytes(32).toString("base64url");
14
+ }
15
+ /** The SHA-256 of a task secret, as `_agent_tasks` stores it and its header is looked up by. */
16
+ export function taskSecretSha256(secret) {
17
+ return createHash("sha256").update(secret).digest("hex");
18
+ }
19
+ /** The agent did not take the task: no answer, a server error, or a refusal while pending. Retried. */
20
+ export class AgentTaskUnanswered extends Schema.TaggedError()("AgentTaskUnanswered", { message: Schema.String, cause: Schema.optionalKey(Schema.Unknown) }) {
21
+ }
22
+ /** The agent refused the task in a way a retry repeats, such as a rejected token. Not retried. */
23
+ export class AgentTaskRefused extends Schema.TaggedError()("AgentTaskRefused", {
24
+ message: Schema.String,
25
+ }) {
26
+ }
27
+ const decided = (result) => ({ status: "decided", result });
28
+ const unavailable = decided({ status: "failed", reason: "agent_unavailable" });
29
+ /** The workflow waits for the task until the deadline its row fixed. */
30
+ function waiting(task) {
31
+ return {
32
+ status: "waiting",
33
+ taskId: task.id,
34
+ remainingMs: Math.max(0, task.deadlineAt.getTime() - Date.now()),
35
+ };
36
+ }
37
+ /** What a task the start step did not hand the agent now means for the workflow. */
38
+ function settled(task) {
39
+ if (task === undefined) {
40
+ return decided({ status: "timed_out" });
41
+ }
42
+ if (task.result !== undefined) {
43
+ return decided(task.result);
44
+ }
45
+ return task.status === "started" ? waiting(task) : undefined;
46
+ }
47
+ /**
48
+ * `agentTask`'s start step: refuses as `busy` when 10 tasks are live, records the task under its
49
+ * hook token, mints its secret and hands it to the agent, which answers `202` once its session has
50
+ * accepted the prompt. A retried step finds the task: started or terminal, it is not handed again;
51
+ * still pending, it gets a new secret and is handed again. `404` means the deployment has no agent
52
+ * that takes tasks; no answer, `5xx` and a `409` while the task is still pending are retried.
53
+ * Outside production, or without the tokens a task needs, the agent is not called. The secret is
54
+ * sent to the agent only: it is never returned, logged or stored.
55
+ */
56
+ export function startAgentTask(context, input) {
57
+ return Effect.gen(function* () {
58
+ const { store, origin, identityToken } = context;
59
+ if (origin === undefined || identityToken === undefined || !context.runtimeIdentity) {
60
+ return unavailable;
61
+ }
62
+ let secret = newTaskSecret();
63
+ const created = yield* store.create({
64
+ hookToken: input.hookToken,
65
+ workflow: context.workflow,
66
+ runId: context.runId,
67
+ prompt: input.prompt,
68
+ timeoutMs: input.timeoutMs,
69
+ secretSha256: taskSecretSha256(secret),
70
+ limit: MAX_LIVE_AGENT_TASKS,
71
+ });
72
+ if (created.status === "busy") {
73
+ return decided({ status: "failed", reason: "busy" });
74
+ }
75
+ const { task } = created;
76
+ if (created.status === "existing") {
77
+ const known = settled(task);
78
+ if (known !== undefined) {
79
+ return known;
80
+ }
81
+ if (task.deadlineAt.getTime() <= Date.now()) {
82
+ return yield* expired(store, task.id);
83
+ }
84
+ secret = newTaskSecret();
85
+ if (!(yield* store.rekey(task.id, taskSecretSha256(secret)))) {
86
+ return settled(yield* store.byHook(input.hookToken)) ?? unavailable;
87
+ }
88
+ }
89
+ const status = yield* handOver(context, origin, identityToken, task.id, secret);
90
+ yield* Effect.logInfo("ontology.agent_task.handed_over").pipe(Effect.annotateLogs({
91
+ taskId: task.id,
92
+ workflow: context.workflow,
93
+ workflowRunId: context.runId,
94
+ status,
95
+ }));
96
+ if (status === 202) {
97
+ return (yield* store.markStarted(task.id))
98
+ ? waiting(task)
99
+ : (settled(yield* store.byHook(input.hookToken)) ?? waiting(task));
100
+ }
101
+ if (status === 404) {
102
+ const { task: after } = yield* store.finish(task.id, {
103
+ status: "failed",
104
+ reason: "agent_unavailable",
105
+ });
106
+ return settled(after) ?? unavailable;
107
+ }
108
+ if (status === 409) {
109
+ // The agent found the task not live: it ended, timed out, or another attempt rekeyed it.
110
+ const current = yield* store.byHook(input.hookToken);
111
+ const known = settled(current);
112
+ if (known !== undefined) {
113
+ return known;
114
+ }
115
+ if (current !== undefined && current.deadlineAt.getTime() <= Date.now()) {
116
+ return yield* expired(store, current.id);
117
+ }
118
+ }
119
+ if (status === 409 || status >= 500) {
120
+ return yield* new AgentTaskUnanswered({
121
+ message: `The app's agent answered the task with HTTP ${status}; the step retries.`,
122
+ });
123
+ }
124
+ // The workflow fails, so the task ends now rather than holding a live slot until its deadline.
125
+ yield* store.finish(task.id, { status: "failed", reason: "agent_unavailable" });
126
+ return yield* new AgentTaskRefused({
127
+ message: `The app's agent refused the task with HTTP ${status}.`,
128
+ });
129
+ });
130
+ }
131
+ /** Times a task out unless it already ended; its terminal outcome, which the workflow returns. */
132
+ export function expireAgentTask(store, taskId) {
133
+ return store
134
+ .finish(taskId, { status: "timed_out" })
135
+ .pipe(Effect.map(({ task }) => task?.result ?? { status: "timed_out" }));
136
+ }
137
+ function expired(store, taskId) {
138
+ return Effect.map(expireAgentTask(store, taskId), decided);
139
+ }
140
+ /** `POST <origin>/eve/segmentstream/v1/tasks` as the deployment: the agent's status code. */
141
+ function handOver(context, origin, identityToken, taskId, secret) {
142
+ return Effect.tryPromise({
143
+ try: async () => {
144
+ const response = await context.transport(new Request(new URL(AGENT_TASK_ROUTE, origin), {
145
+ method: "POST",
146
+ headers: {
147
+ authorization: `Bearer ${identityToken}`,
148
+ "content-type": "application/json",
149
+ },
150
+ body: JSON.stringify({ task_id: taskId, secret }),
151
+ signal: AbortSignal.timeout(AGENT_TIMEOUT_MS),
152
+ }));
153
+ await response.body?.cancel().catch(() => undefined);
154
+ return response.status;
155
+ },
156
+ catch: (cause) => new AgentTaskUnanswered({
157
+ message: "The app's agent did not answer the task; the step retries.",
158
+ cause,
159
+ }),
160
+ });
161
+ }
@@ -0,0 +1,40 @@
1
+ import { Layer, Schema } from "effect";
2
+ import { HttpRouter } from "effect/unstable/http";
3
+ import { type TokenVerifier } from "../authentication.js";
4
+ import { RequestId } from "../errors.js";
5
+ import { OntologyBackend } from "../runtime-contract.js";
6
+ import { type RuntimeTokenVerifier } from "../runtime-identity.js";
7
+ import type { WorkflowEngine } from "../workflows.js";
8
+ /** The task the agent runs, as its secret names it. */
9
+ export declare const AGENT_TASK_PATH = "/api/ontology/agent/tasks/current";
10
+ /** Where the agent reports the task's outcome. */
11
+ export declare const AGENT_TASK_RESULT_PATH = "/api/ontology/agent/tasks/current/result";
12
+ /** `POST …/tasks/current/result`: the outcome of the task's turn, as the agent reports it. */
13
+ export declare const AgentTaskReport: Schema.Union<readonly [Schema.Struct<{
14
+ readonly status: Schema.Literal<"completed">;
15
+ readonly text: Schema.String;
16
+ readonly truncated: Schema.Boolean;
17
+ }>, Schema.Struct<{
18
+ readonly status: Schema.Literal<"needs_input">;
19
+ readonly text: Schema.String;
20
+ readonly truncated: Schema.Boolean;
21
+ }>, Schema.Struct<{
22
+ readonly status: Schema.Literal<"failed">;
23
+ readonly reason: Schema.Literal<"agent_failed">;
24
+ }>]>;
25
+ export interface AgentTaskRoutesOptions {
26
+ readonly verifyToken: TokenVerifier;
27
+ /** The deployment's runtime tokens; `undefined` while runtime authentication is disabled. */
28
+ readonly verifyRuntime: RuntimeTokenVerifier | undefined;
29
+ /** The workspace whose workflow users the tasks act as. */
30
+ readonly workspaceId: string;
31
+ /** Resumes the workflow waiting on a task. */
32
+ readonly engine: WorkflowEngine;
33
+ }
34
+ /**
35
+ * The routes of the tasks workflows hand the app's agent with `agentTask`. Both take only the
36
+ * deployment's runtime token with a live task's secret in `X-SegmentStream-Agent-Task`, and never
37
+ * a member named in `X-SegmentStream-Act-As`: `403` when the secret names no live task or its
38
+ * workflow user is inactive. Without the task table, it serves nothing.
39
+ */
40
+ export declare function agentTasksLayer(options: AgentTaskRoutesOptions): Layer.Layer<never, never, OntologyBackend | HttpRouter.HttpRouter | HttpRouter.Request<"Requires", RequestId>>;
@@ -0,0 +1,155 @@
1
+ import { Effect, Layer, Redacted, Result, Schema } from "effect";
2
+ import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
3
+ import { HttpApiBuilder, HttpApiSecurity } from "effect/unstable/httpapi";
4
+ import { MAX_AGENT_TASK_TEXT_LENGTH } from "../../agent-task-contract.js";
5
+ import { MEMBER_ROLE } from "../../names.js";
6
+ import { schemaIssues } from "../../runtime/validation.js";
7
+ import { BASE_PATH } from "../api.js";
8
+ import { withPrincipal } from "../authentication.js";
9
+ import { RequestId, errorBodyForWire, forbidden, internalError, toServerResponse, unauthorized, unavailable, } from "../errors.js";
10
+ import { OntologyBackend } from "../runtime-contract.js";
11
+ import { ACT_AS_HEADER, AGENT_TASK_HEADER, agentTaskSecret, logRuntimeRejection, } from "../runtime-identity.js";
12
+ import { agentTaskCaller } from "./task-caller.js";
13
+ /** The task the agent runs, as its secret names it. */
14
+ export const AGENT_TASK_PATH = `${BASE_PATH}/agent/tasks/current`;
15
+ /** Where the agent reports the task's outcome. */
16
+ export const AGENT_TASK_RESULT_PATH = `${AGENT_TASK_PATH}/result`;
17
+ const NO_STORE = { "cache-control": "no-store" };
18
+ const Text = Schema.String.check(Schema.isMaxLength(MAX_AGENT_TASK_TEXT_LENGTH)).annotate({
19
+ description: "The agent's final text, or its question; longer text is cut and marked truncated.",
20
+ });
21
+ /** `POST …/tasks/current/result`: the outcome of the task's turn, as the agent reports it. */
22
+ export const AgentTaskReport = Schema.Union([
23
+ Schema.Struct({ status: Schema.Literal("completed"), text: Text, truncated: Schema.Boolean }),
24
+ Schema.Struct({ status: Schema.Literal("needs_input"), text: Text, truncated: Schema.Boolean }),
25
+ Schema.Struct({ status: Schema.Literal("failed"), reason: Schema.Literal("agent_failed") }),
26
+ ]);
27
+ function json(body, status = 200) {
28
+ return HttpServerResponse.jsonUnsafe(body, { status, headers: NO_STORE });
29
+ }
30
+ /**
31
+ * `GET /api/ontology/agent/tasks/current`: the task, its prompt and deadline, and the user it acts
32
+ * as, from the ontology's records, never from the agent's request.
33
+ */
34
+ function currentTask(backend, { task, principal }) {
35
+ return Effect.gen(function* () {
36
+ const user = yield* backend
37
+ .get({ entity: "user", id: principal.id })
38
+ .pipe(Effect.catchTag("NotFound", () => Effect.succeed(undefined)));
39
+ return json({
40
+ id: task.id,
41
+ workflow: task.workflow,
42
+ prompt: task.prompt,
43
+ deadline_at: task.deadlineAt.toISOString(),
44
+ principal: {
45
+ id: principal.id,
46
+ name: typeof user?.name === "string" ? user.name : task.workflow,
47
+ roles: [...new Set([...principal.roles, MEMBER_ROLE])],
48
+ },
49
+ });
50
+ });
51
+ }
52
+ /**
53
+ * `POST /api/ontology/agent/tasks/current/result`: the task ends with the agent's outcome, and the
54
+ * workflow waiting on it resumes. The first outcome wins: a later report answers `409`. A workflow
55
+ * that no longer waits still answers `200`; one the engine could not resume reads the outcome at the
56
+ * task's deadline.
57
+ */
58
+ function reportResult(store, engine, request, { task }) {
59
+ return Effect.gen(function* () {
60
+ const requestId = yield* RequestId;
61
+ const text = yield* Effect.orDie(request.text);
62
+ let body;
63
+ try {
64
+ body = JSON.parse(text);
65
+ }
66
+ catch {
67
+ body = undefined;
68
+ }
69
+ const decoded = Schema.decodeUnknownResult(AgentTaskReport)(body, {
70
+ errors: "all",
71
+ onExcessProperty: "error",
72
+ });
73
+ if (Result.isFailure(decoded)) {
74
+ return HttpServerResponse.jsonUnsafe(errorBodyForWire({
75
+ error: "invalid_request",
76
+ detail: "The request body is invalid.",
77
+ requestId,
78
+ issues: schemaIssues(decoded.failure),
79
+ }), { status: 400 });
80
+ }
81
+ const result = decoded.success;
82
+ const { finished } = yield* store.finish(task.id, result);
83
+ const annotations = {
84
+ requestId,
85
+ taskId: task.id,
86
+ workflow: task.workflow,
87
+ outcome: result.status,
88
+ };
89
+ if (!finished) {
90
+ return HttpServerResponse.jsonUnsafe(errorBodyForWire({
91
+ error: "conflict",
92
+ detail: "The task already ended; the first report wins.",
93
+ requestId,
94
+ }), { status: 409 });
95
+ }
96
+ yield* Effect.logInfo("ontology.agent_task.reported").pipe(Effect.annotateLogs(annotations));
97
+ const resumed = yield* Effect.tryPromise(() => engine.resumeHook?.(task.hookToken, result) ?? Promise.resolve("not_found")).pipe(Effect.result);
98
+ if (Result.isFailure(resumed)) {
99
+ yield* Effect.logError("ontology.agent_task.resume_failed", resumed.failure).pipe(Effect.annotateLogs(annotations));
100
+ return toServerResponse(internalError(requestId));
101
+ }
102
+ return json({ accepted: true });
103
+ });
104
+ }
105
+ /**
106
+ * The routes of the tasks workflows hand the app's agent with `agentTask`. Both take only the
107
+ * deployment's runtime token with a live task's secret in `X-SegmentStream-Agent-Task`, and never
108
+ * a member named in `X-SegmentStream-Act-As`: `403` when the secret names no live task or its
109
+ * workflow user is inactive. Without the task table, it serves nothing.
110
+ */
111
+ export function agentTasksLayer(options) {
112
+ return Layer.effectDiscard(Effect.gen(function* () {
113
+ const router = yield* HttpRouter.HttpRouter;
114
+ const backend = yield* OntologyBackend;
115
+ const store = backend.agentTasks;
116
+ if (store === undefined) {
117
+ return;
118
+ }
119
+ const credential = HttpApiBuilder.securityDecode(HttpApiSecurity.bearer);
120
+ const asTask = (answer) => (request) => Effect.gen(function* () {
121
+ const requestId = yield* RequestId;
122
+ const bearer = yield* Effect.provideService(credential, HttpServerRequest.HttpServerRequest, request);
123
+ const token = Redacted.value(bearer);
124
+ const verified = options.verifyRuntime === undefined || token === ""
125
+ ? undefined
126
+ : yield* Effect.promise(() => options.verifyRuntime(token));
127
+ const refused = (detail) => toServerResponse(forbidden(requestId, detail));
128
+ switch (verified?.status) {
129
+ case "valid":
130
+ break;
131
+ case "invalid":
132
+ yield* logRuntimeRejection(verified.reason);
133
+ return toServerResponse(unauthorized(requestId, "The bearer token is invalid, expired or revoked."));
134
+ case "unavailable":
135
+ return toServerResponse(unavailable(requestId));
136
+ default:
137
+ // Any other credential is authenticated as usual, for the usual 401, then refused.
138
+ return yield* withPrincipal(bearer, options.verifyToken, backend, Effect.succeed(refused("Only the app's agent calls this route.")));
139
+ }
140
+ const secret = agentTaskSecret(request);
141
+ if (secret === undefined) {
142
+ return refused(`The app's agent presents the task's secret in ${AGENT_TASK_HEADER}.`);
143
+ }
144
+ if ((request.headers[ACT_AS_HEADER]?.trim() ?? "") !== "") {
145
+ return refused(`A request names a member in ${ACT_AS_HEADER} or a task in ${AGENT_TASK_HEADER}, not both.`);
146
+ }
147
+ const caller = yield* agentTaskCaller(secret, options.workspaceId).pipe(Effect.provideService(OntologyBackend, backend));
148
+ return caller.status === "refused"
149
+ ? refused(caller.detail)
150
+ : yield* answer(request, caller);
151
+ });
152
+ yield* router.add("GET", AGENT_TASK_PATH, asTask((_, live) => currentTask(backend, live)));
153
+ yield* router.add("POST", AGENT_TASK_RESULT_PATH, asTask((request, live) => reportResult(store, options.engine, request, live)));
154
+ }));
155
+ }
@@ -0,0 +1,50 @@
1
+ import { Layer, Schema } from "effect";
2
+ import { HttpApi, HttpApiGroup, HttpApiMiddleware } from "effect/unstable/httpapi";
3
+ import type { Ontology } from "../ontology.js";
4
+ import { RequestId } from "./errors.js";
5
+ import { type ApiPlan, type PlannedEntity } from "./plan.js";
6
+ import type { GeneratedActionsProvider } from "./runtime-contract.js";
7
+ import { type EntitySchemas } from "./schemas.js";
8
+ /** The path every ontology route lives under. */
9
+ export declare const BASE_PATH = "/api/ontology";
10
+ /** The group of the global routes. Entity names are snake_case, so it cannot clash with one. */
11
+ export declare const SERVICE_GROUP = "Ontology";
12
+ /** The API of one ontology: its groups are the entities' names and {@link SERVICE_GROUP}. */
13
+ export type OntologyApi = HttpApi.HttpApi<"ontology", HttpApiGroup.Top>;
14
+ declare const ErrorResponses_base: HttpApiMiddleware.ServiceClass<ErrorResponses, "@segmentstream/ontology/ErrorResponses", {
15
+ requires: RequestId;
16
+ provides: never;
17
+ error: readonly [Schema.Top, Schema.Top];
18
+ clientError: never;
19
+ requiredForClient: false;
20
+ security: never;
21
+ }, HttpApiMiddleware.HttpApiMiddleware<never, readonly [Schema.Top, Schema.Top], RequestId>>;
22
+ /**
23
+ * Maps every failure of a route, including input that fails its schema, to the service's error
24
+ * responses. It runs inside {@link Authentication}, so unauthenticated requests never reach it.
25
+ */
26
+ export declare class ErrorResponses extends ErrorResponses_base {
27
+ }
28
+ export declare const ErrorResponsesLive: Layer.Layer<ErrorResponses, never, never>;
29
+ /** Whether an entity declares metrics, and so has `POST /api/ontology/<entity>/query_metrics`. */
30
+ export declare function hasMetrics(planned: PlannedEntity): boolean;
31
+ /** The name of the metric query endpoints at their current paths, in the service and entity groups. */
32
+ export declare const QUERY_METRICS_ENDPOINT = "queryMetrics";
33
+ export interface BuiltApi {
34
+ readonly plan: ApiPlan;
35
+ readonly api: OntologyApi;
36
+ readonly schemas: ReadonlyMap<string, EntitySchemas>;
37
+ }
38
+ export declare function buildApi(plan: ApiPlan): BuiltApi;
39
+ export interface DeriveApiOptions {
40
+ /** The generated actions, whose routes sit beside the authored ones: the runtime's by default. */
41
+ readonly generatedActions?: GeneratedActionsProvider;
42
+ }
43
+ /**
44
+ * The HttpApi of an ontology: per entity `find`, `query`, `get`, `history`, a traversal per
45
+ * relationship and inverse, and a route per generated and authored action; and the catalog, graph,
46
+ * OpenAPI, status, caller (`me`), sign-in check, prose and metric query routes. There is no PUT, PATCH
47
+ * or DELETE: every change is an action.
48
+ */
49
+ export declare function deriveApi(ontology: Ontology, options?: DeriveApiOptions): OntologyApi;
50
+ export {};