@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,24 @@
1
+ import { Context, Effect } from "effect";
2
+ /** Verified credential provenance, never the bearer value or a client-supplied sender. */
3
+ export type VerifiedCaller = {
4
+ readonly kind: "oauth";
5
+ readonly subjectId: string;
6
+ readonly client: {
7
+ readonly id: string;
8
+ readonly name: string;
9
+ };
10
+ readonly scope: string;
11
+ } | {
12
+ readonly kind: "runtime" | "service" | "member" | "workload";
13
+ readonly subjectId: string;
14
+ };
15
+ export type CallerContext = VerifiedCaller | {
16
+ readonly kind: "unverified";
17
+ };
18
+ declare const CurrentCaller_base: Context.ServiceClass<CurrentCaller, "@segmentstream/ontology/CurrentCaller", VerifiedCaller>;
19
+ /** Provided only after authentication, alongside the independently scoped principal. */
20
+ export declare class CurrentCaller extends CurrentCaller_base {
21
+ }
22
+ /** Direct in-process operation callers have no credential provenance and cannot acquire attribution. */
23
+ export declare const currentCaller: Effect.Effect<CallerContext, never, never>;
24
+ export {};
@@ -0,0 +1,6 @@
1
+ import { Context, Effect, Option } from "effect";
2
+ /** Provided only after authentication, alongside the independently scoped principal. */
3
+ export class CurrentCaller extends Context.Service()("@segmentstream/ontology/CurrentCaller") {
4
+ }
5
+ /** Direct in-process operation callers have no credential provenance and cannot acquire attribution. */
6
+ export const currentCaller = Effect.serviceOption(CurrentCaller).pipe(Effect.map((caller) => Option.getOrElse(caller, () => ({ kind: "unverified" }))));
@@ -0,0 +1,42 @@
1
+ import { type OntologyManifest } from "../manifest.js";
2
+ /**
3
+ * The catalog for a reader: the manifest, with each entity's actions narrowed to the ones the given
4
+ * permissions may run, and only the metrics of the model whose every input entity they may read.
5
+ * Without permissions it is the manifest itself.
6
+ */
7
+ export declare function catalogFor(manifest: OntologyManifest, permissions?: ReadonlyArray<string>): OntologyManifest;
8
+ export interface GraphRelationship {
9
+ readonly from: string;
10
+ readonly name: string;
11
+ readonly to: string;
12
+ readonly inverse: string;
13
+ readonly cardinality: "one" | "many";
14
+ /** The property pair of a relationship matched by value: one with a warehouse-backed end. */
15
+ readonly on?: {
16
+ readonly property: string;
17
+ readonly targetProperty: string;
18
+ };
19
+ /**
20
+ * Whether the relationship may lead to nothing. Only a stored → stored `rel.one` can promise a
21
+ * record; a value-matched reference is never checked against its target.
22
+ */
23
+ readonly optional: boolean;
24
+ readonly phrase: readonly [string, string];
25
+ /** The relationship read from the declaring entity: "Lead is owned by one User". */
26
+ readonly forward: string;
27
+ /** The relationship read from the target: "User owns many Leads". */
28
+ readonly backward: string;
29
+ readonly description: string;
30
+ }
31
+ export interface Graph {
32
+ readonly hash: string;
33
+ readonly entities: ReadonlyArray<{
34
+ readonly name: string;
35
+ readonly label: string;
36
+ readonly plural: string;
37
+ readonly description: string;
38
+ }>;
39
+ readonly relationships: ReadonlyArray<GraphRelationship>;
40
+ }
41
+ /** The entities and both directions of every relationship, phrased. */
42
+ export declare function graphOf(manifest: OntologyManifest): Graph;
@@ -0,0 +1,66 @@
1
+ import { isValueMatched } from "../manifest.js";
2
+ import { isAllowed } from "../permissions.js";
3
+ import { actionPermission, modelMetricsFor } from "../render.js";
4
+ /**
5
+ * The catalog for a reader: the manifest, with each entity's actions narrowed to the ones the given
6
+ * permissions may run, and only the metrics of the model whose every input entity they may read.
7
+ * Without permissions it is the manifest itself.
8
+ */
9
+ export function catalogFor(manifest, permissions) {
10
+ if (permissions === undefined) {
11
+ return manifest;
12
+ }
13
+ const { metrics: declared, ...rest } = manifest;
14
+ const metrics = declared === undefined ? [] : modelMetricsFor(manifest, permissions);
15
+ return {
16
+ ...rest,
17
+ ...(metrics.length === 0 ? {} : { metrics }),
18
+ entities: manifest.entities
19
+ .filter((entity) => entity.source === undefined ||
20
+ isAllowed(entity.permissions?.read ?? `${entity.name}:read`, { permissions }))
21
+ .map((entity) => ({
22
+ ...entity,
23
+ actions: entity.actions.filter((action) => isAllowed(actionPermission(entity.name, action), { permissions })),
24
+ })),
25
+ };
26
+ }
27
+ /** The entities and both directions of every relationship, phrased. */
28
+ export function graphOf(manifest) {
29
+ const entities = new Map(manifest.entities.map((entity) => [entity.name, entity]));
30
+ return {
31
+ hash: manifest.hash,
32
+ entities: manifest.entities.map(({ name, label, plural, description }) => ({
33
+ name,
34
+ label,
35
+ plural,
36
+ description,
37
+ })),
38
+ relationships: manifest.entities.flatMap((source) => source.relationships.map((relationship) => {
39
+ const target = entities.get(relationship.to);
40
+ const targetLabel = target?.label ?? relationship.to;
41
+ // Manifests before version 5 wrote `optional` on warehouse → stored relationships too.
42
+ const valueMatched = isValueMatched(relationship) ||
43
+ source.source !== undefined ||
44
+ target?.source !== undefined;
45
+ // As describe phrases them: nothing promises a value-matched relationship a record.
46
+ const one = valueMatched ? "at most one" : "one";
47
+ const many = valueMatched ? "" : "many ";
48
+ const forwardTarget = relationship.cardinality === "one"
49
+ ? `${one} ${targetLabel}`
50
+ : `many ${target?.plural ?? relationship.to}`;
51
+ return {
52
+ from: source.name,
53
+ name: relationship.name,
54
+ to: relationship.to,
55
+ inverse: relationship.inverse,
56
+ cardinality: relationship.cardinality,
57
+ ...(relationship.on !== undefined ? { on: relationship.on } : {}),
58
+ optional: relationship.cardinality === "many" || valueMatched || relationship.optional === true,
59
+ phrase: relationship.phrase,
60
+ forward: `${source.label} ${relationship.phrase[0]} ${forwardTarget}`,
61
+ backward: `${targetLabel} ${relationship.phrase[1]} ${many}${source.plural}`,
62
+ description: relationship.description,
63
+ };
64
+ })),
65
+ };
66
+ }
@@ -0,0 +1,10 @@
1
+ import type { Effect } from "effect";
2
+ import type { ConnectionTransport } from "../../connection.js";
3
+ import type { ChannelSignInInput } from "../runtime-contract.js";
4
+ /** Verified provider facts only; admission and session issuance remain provider-independent. */
5
+ export interface ChannelAppProvider {
6
+ readonly provider: string;
7
+ readonly verify: (assertion: string, ctx: {
8
+ readonly connections: ConnectionTransport["Service"];
9
+ }) => Effect.Effect<Omit<ChannelSignInInput, "provider"> | undefined>;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { Effect } from "effect";
2
+ import type { ConnectionTransport } from "../../../connection.js";
3
+ import type { ChannelAppProvider } from "../provider.js";
4
+ import type { ChannelSignInInput } from "../../runtime-contract.js";
5
+ export declare const TELEGRAM_PRODUCTION_PUBLIC_KEY = "e7bf03a2fa4602af4580703d88dda5bb59f32ed8b02a56c187fe7d34caed242d";
6
+ export declare const INIT_DATA_MAX_AGE_SECONDS = 3600;
7
+ export declare const INIT_DATA_FUTURE_SKEW_SECONDS = 30;
8
+ /** No bot secret, browser bot ID, or unverified initDataUnsafe participates in this assertion. */
9
+ export declare function verifyTelegramInitData(input: {
10
+ readonly initData: string;
11
+ readonly botId: string;
12
+ readonly testPublicKeyHex?: string;
13
+ readonly now?: number;
14
+ }): ChannelSignInInput | undefined;
15
+ /** Bot IDs come only from the workspace's configured Telegram connection, cached for five minutes. */
16
+ export declare function telegramBotId(connection: string): (transport: ConnectionTransport["Service"]) => Effect.Effect<string, never, never>;
17
+ /** Only an explicit deployment option registers this adapter; a chat connection alone does not. */
18
+ export declare function telegramAppProvider(connection: string, testPublicKeyHex?: string): ChannelAppProvider;
@@ -0,0 +1,108 @@
1
+ import { createPublicKey, verify } from "node:crypto";
2
+ import { Effect } from "effect";
3
+ // Verified against https://core.telegram.org/bots/webapps#validating-data-for-third-party-use
4
+ export const TELEGRAM_PRODUCTION_PUBLIC_KEY = "e7bf03a2fa4602af4580703d88dda5bb59f32ed8b02a56c187fe7d34caed242d";
5
+ export const INIT_DATA_MAX_AGE_SECONDS = 3600;
6
+ export const INIT_DATA_FUTURE_SKEW_SECONDS = 30;
7
+ /** No bot secret, browser bot ID, or unverified initDataUnsafe participates in this assertion. */
8
+ export function verifyTelegramInitData(input) {
9
+ try {
10
+ if (input.initData.length === 0 || input.initData.length > 16_384) {
11
+ return undefined;
12
+ }
13
+ const params = new URLSearchParams(input.initData);
14
+ const fields = new Map();
15
+ for (const [key, value] of params) {
16
+ if (fields.has(key)) {
17
+ return undefined;
18
+ }
19
+ fields.set(key, value);
20
+ }
21
+ const signature = fields.get("signature") ?? "";
22
+ const authDate = fields.get("auth_date") ?? "";
23
+ const nowSeconds = (input.now ?? Date.now()) / 1000;
24
+ const age = nowSeconds - Number(authDate);
25
+ if (!/^[A-Za-z0-9_-]{86}(?:==)?$/.test(signature) ||
26
+ !/^[0-9]+$/.test(authDate) ||
27
+ !Number.isSafeInteger(Number(authDate)) ||
28
+ age > INIT_DATA_MAX_AGE_SECONDS ||
29
+ age < -INIT_DATA_FUTURE_SKEW_SECONDS) {
30
+ return undefined;
31
+ }
32
+ const lines = [...fields]
33
+ .filter(([key]) => key !== "hash" && key !== "signature")
34
+ .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
35
+ .map(([key, value]) => `${key}=${value}`);
36
+ const publicKey = createPublicKey({
37
+ key: Buffer.concat([
38
+ Buffer.from("302a300506032b6570032100", "hex"),
39
+ Buffer.from(input.testPublicKeyHex ?? TELEGRAM_PRODUCTION_PUBLIC_KEY, "hex"),
40
+ ]),
41
+ format: "der",
42
+ type: "spki",
43
+ });
44
+ if (!verify(null, Buffer.from(`${input.botId}:WebAppData\n${lines.join("\n")}`), publicKey, Buffer.from(signature, "base64url"))) {
45
+ return undefined;
46
+ }
47
+ const user = JSON.parse(fields.get("user") ?? "null");
48
+ if (!user || !Number.isSafeInteger(user.id) || Number(user.id) <= 0 || user.is_bot === true) {
49
+ return undefined;
50
+ }
51
+ const display = [user.first_name, user.last_name]
52
+ .filter((value) => typeof value === "string")
53
+ .join(" ")
54
+ .trim();
55
+ return {
56
+ provider: "telegram",
57
+ externalId: String(user.id),
58
+ ...(display ? { display } : {}),
59
+ ...(typeof user.username === "string" ? { username: user.username } : {}),
60
+ };
61
+ }
62
+ catch {
63
+ return undefined;
64
+ }
65
+ }
66
+ /** Bot IDs come only from the workspace's configured Telegram connection, cached for five minutes. */
67
+ export function telegramBotId(connection) {
68
+ let cached;
69
+ return (transport) => Effect.gen(function* () {
70
+ if (cached && cached.expiresAt > Date.now()) {
71
+ return cached.id;
72
+ }
73
+ const response = yield* transport.request({
74
+ connection,
75
+ api: "bot",
76
+ method: "GET",
77
+ path: "/getMe",
78
+ headers: [],
79
+ body: new Uint8Array(),
80
+ });
81
+ const body = yield* Effect.try(() => JSON.parse(new TextDecoder().decode(response.body)));
82
+ if (response.status !== 200 ||
83
+ body.ok !== true ||
84
+ body.result?.is_bot !== true ||
85
+ !Number.isSafeInteger(body.result.id) ||
86
+ Number(body.result.id) <= 0) {
87
+ const explanation = typeof body.description === "string"
88
+ ? body.description
89
+ : `Unexpected getMe response (HTTP ${response.status}).`;
90
+ return yield* Effect.die(new Error("Telegram getMe did not return a bot identity.", {
91
+ cause: new Error(explanation),
92
+ }));
93
+ }
94
+ cached = { id: String(body.result.id), expiresAt: Date.now() + 300_000 };
95
+ return cached.id;
96
+ }).pipe(Effect.orDie);
97
+ }
98
+ /** Only an explicit deployment option registers this adapter; a chat connection alone does not. */
99
+ export function telegramAppProvider(connection, testPublicKeyHex) {
100
+ const botId = telegramBotId(connection);
101
+ return {
102
+ provider: "telegram",
103
+ verify: (assertion, ctx) => Effect.gen(function* () {
104
+ const id = yield* botId(ctx.connections);
105
+ return verifyTelegramInitData({ initData: assertion, botId: id, testPublicKeyHex });
106
+ }),
107
+ };
108
+ }
@@ -0,0 +1,5 @@
1
+ export { channelCookieName } from "../../channel-session.js";
2
+ import type { OntologyServiceConfig } from "../config.js";
3
+ import { OntologyBackend } from "../runtime-contract.js";
4
+ /** Discovery and logout for workspace-owned channel sessions, outside the Neon catch-all. */
5
+ export declare function channelSessionLayer(config: OntologyServiceConfig): import("effect/Layer").Layer<never, never, OntologyBackend | import("effect/unstable/http/HttpRouter").HttpRouter>;
@@ -0,0 +1,53 @@
1
+ import { CHANNEL_LOGOUT_PATH, CHANNEL_SESSION_PATH, channelCookie, channelCookieName, } from "../../channel-session.js";
2
+ export { channelCookieName } from "../../channel-session.js";
3
+ import { Effect } from "effect";
4
+ import { HttpServerResponse } from "effect/unstable/http";
5
+ import { use as registerRoutes } from "effect/unstable/http/HttpRouter";
6
+ import { sessionMayAuthenticate } from "../authentication.js";
7
+ import { appSessionResource, publicOrigin, secretHash, sameResource, callerOfAccessToken, } from "../oauth/protocol.js";
8
+ import { OntologyBackend } from "../runtime-contract.js";
9
+ const json = (body, status = 200, headers = {}) => HttpServerResponse.jsonUnsafe(body, {
10
+ status,
11
+ headers: { "cache-control": "no-store", ...headers },
12
+ });
13
+ /** Discovery and logout for workspace-owned channel sessions, outside the Neon catch-all. */
14
+ export function channelSessionLayer(config) {
15
+ const cookieName = channelCookieName(config.workspaceId);
16
+ return registerRoutes((router) => Effect.gen(function* () {
17
+ const backend = yield* OntologyBackend;
18
+ yield* router.add("GET", CHANNEL_SESSION_PATH, (request) => Effect.gen(function* () {
19
+ const token = request.cookies[cookieName];
20
+ if (!token || !backend.oauth) {
21
+ return json({ error: "unauthorized" }, 401);
22
+ }
23
+ const resource = appSessionResource(publicOrigin(request));
24
+ const caller = yield* callerOfAccessToken(backend.oauth, token, resource);
25
+ const grant = caller ? yield* backend.oauth.findAccess(secretHash(token)) : undefined;
26
+ return caller && grant
27
+ ? json({
28
+ session: { id: grant.id, expires_at: grant.expiresAt?.toISOString() },
29
+ user: { id: caller.principal.id },
30
+ })
31
+ : json({ error: "unauthorized" }, 401);
32
+ }));
33
+ yield* router.add("POST", CHANNEL_LOGOUT_PATH, (request) => Effect.gen(function* () {
34
+ if (!sessionMayAuthenticate(request)) {
35
+ return json({ error: "cross_origin_session" }, 403);
36
+ }
37
+ // Server sign-out can forward the opaque cookie as bearer, with the same Origin check.
38
+ const authorization = request.headers.authorization;
39
+ const token = authorization?.startsWith("Bearer ")
40
+ ? authorization.slice(7)
41
+ : request.cookies[cookieName];
42
+ if (token && backend.oauth) {
43
+ const grant = yield* backend.oauth.findGrantOfToken(secretHash(token));
44
+ if (grant && sameResource(grant.resource, appSessionResource(publicOrigin(request)))) {
45
+ yield* backend.oauth.revokeGrant(grant.id);
46
+ }
47
+ }
48
+ return json({ signed_out: true }, 200, {
49
+ "set-cookie": channelCookie(cookieName, "", 0),
50
+ });
51
+ }));
52
+ }));
53
+ }
@@ -0,0 +1,7 @@
1
+ import type { ChannelAppProvider } from "./provider.js";
2
+ import type { ConnectionTransportFactory } from "../connections.js";
3
+ import type { OntologyServiceConfig } from "../config.js";
4
+ import { RequestId } from "../errors.js";
5
+ import { OntologyBackend } from "../runtime-contract.js";
6
+ /** Public assertion exchange: only an explicitly registered adapter reaches shared admission. */
7
+ export declare function channelSignInLayer(providers: readonly ChannelAppProvider[], config: OntologyServiceConfig, connections: ConnectionTransportFactory): import("effect/Layer").Layer<never, never, OntologyBackend | import("effect/unstable/http/HttpRouter").HttpRouter | import("effect/unstable/http/HttpRouter").Request<"Requires", RequestId> | import("effect/unstable/http/HttpRouter").Request<"Error", import("effect/unstable/http/HttpServerError").HttpServerError>>;
@@ -0,0 +1,78 @@
1
+ import { Effect } from "effect";
2
+ import { HttpServerResponse } from "effect/unstable/http";
3
+ import { params, use as registerRoutes } from "effect/unstable/http/HttpRouter";
4
+ import { CHANNEL_SESSION_TTL_SECONDS, channelCookie, channelCookieName, } from "../../channel-session.js";
5
+ import { sessionMayAuthenticate } from "../authentication.js";
6
+ import { RequestId } from "../errors.js";
7
+ import { appSessionResource, publicOrigin } from "../oauth/protocol.js";
8
+ import { clientAddress, fixedWindowLimiter } from "../rate-limit.js";
9
+ import { OntologyBackend } from "../runtime-contract.js";
10
+ const json = (body, status = 200, headers = {}) => HttpServerResponse.jsonUnsafe(body, {
11
+ status,
12
+ headers: { "cache-control": "no-store", ...headers },
13
+ });
14
+ /** Public assertion exchange: only an explicitly registered adapter reaches shared admission. */
15
+ export function channelSignInLayer(providers, config, connections) {
16
+ const limiter = fixedWindowLimiter({ limit: 10, windowMs: 60_000, maxKeys: 10_000 });
17
+ const cookieName = channelCookieName(config.workspaceId);
18
+ return registerRoutes((router) => Effect.gen(function* () {
19
+ const backend = yield* OntologyBackend;
20
+ yield* router.add("POST", "/api/ontology/sign-in/:provider", (request) => Effect.gen(function* () {
21
+ const requestId = yield* RequestId;
22
+ if (!sessionMayAuthenticate(request)) {
23
+ return json({ error: "cross_origin_session" }, 403);
24
+ }
25
+ const retryAfter = limiter.take(clientAddress(request));
26
+ if (retryAfter !== undefined) {
27
+ return json({ error: "rate_limited" }, 429, { "retry-after": String(retryAfter) });
28
+ }
29
+ const route = yield* params;
30
+ const provider = providers.find((candidate) => route.provider === candidate.provider);
31
+ if (!provider) {
32
+ return json({ error: "not_found" }, 404);
33
+ }
34
+ if (!backend.channelSessions) {
35
+ return json({ error: "channel_unavailable" }, 503);
36
+ }
37
+ const text = yield* request.text;
38
+ let assertion;
39
+ try {
40
+ assertion =
41
+ text.length <= 32_768
42
+ ? JSON.parse(text)?.assertion
43
+ : undefined;
44
+ }
45
+ catch {
46
+ return json({ error: "invalid_request" }, 400);
47
+ }
48
+ if (typeof assertion !== "string" || assertion.length > 16_384) {
49
+ return json({ error: "invalid_request" }, 400);
50
+ }
51
+ const identity = yield* provider.verify(assertion, {
52
+ connections: connections({
53
+ identityToken: request.headers["x-vercel-oidc-token"],
54
+ audit: { action: "channel.sign_in", principalId: "anonymous", requestId },
55
+ }),
56
+ });
57
+ if (!identity) {
58
+ return json({ error: "invalid_assertion" }, 401);
59
+ }
60
+ const session = yield* backend.channelSessions.create({
61
+ ...identity,
62
+ provider: provider.provider,
63
+ resource: appSessionResource(publicOrigin(request)),
64
+ });
65
+ if (session.status === "limited") {
66
+ return json({ error: "rate_limited" }, 429, {
67
+ "retry-after": String(session.retryAfterSeconds),
68
+ });
69
+ }
70
+ if (session.status !== "signed_in") {
71
+ return json({ error: session.status === "pairing_required" ? "not_paired" : "access_refused" }, 403);
72
+ }
73
+ return json({ signed_in: true, expires_at: session.expiresAt.toISOString() }, 200, {
74
+ "set-cookie": channelCookie(cookieName, session.token, CHANNEL_SESSION_TTL_SECONDS),
75
+ });
76
+ }));
77
+ }));
78
+ }
@@ -0,0 +1,64 @@
1
+ import { Effect, Schema } from "effect";
2
+ import type { OntologyEnvironment } from "../config.js";
3
+ import type { ConversationRequester } from "./attribution.js";
4
+ export interface DeliveryEvent {
5
+ readonly eventId: string;
6
+ readonly operationId: string;
7
+ readonly provider: string;
8
+ readonly chatId: string;
9
+ readonly chatType: "group" | "private";
10
+ readonly threadId: null;
11
+ readonly participantIds: ReadonlyArray<string>;
12
+ readonly senderId: string;
13
+ readonly senderName: string;
14
+ readonly senderIsBot: true;
15
+ readonly kind: "outbound";
16
+ readonly messageId: string | null;
17
+ readonly replyToMessageId: string | null;
18
+ readonly sessionId: string | null;
19
+ readonly turnId: null;
20
+ readonly text: string;
21
+ readonly decision: null;
22
+ readonly reason: null;
23
+ readonly toolCallId: null;
24
+ readonly toolName: null;
25
+ readonly argsSummary: string | null;
26
+ readonly status: "requested" | "sent" | "uncertain" | "failed";
27
+ readonly attachments: readonly [];
28
+ readonly requestedBy: ConversationRequester;
29
+ readonly url: string | null;
30
+ readonly at: string;
31
+ }
32
+ export interface DeliveryCommand {
33
+ readonly phase: "reserve" | "receipt";
34
+ readonly scope: string;
35
+ readonly key: string;
36
+ readonly fingerprint: string;
37
+ readonly claimId?: string;
38
+ }
39
+ export declare const DeliveryReceipt: Schema.Struct<{
40
+ readonly version: Schema.Literal<1>;
41
+ readonly claimed: Schema.Boolean;
42
+ readonly duplicate: Schema.Boolean;
43
+ readonly operationId: Schema.String;
44
+ readonly claimId: Schema.optionalKey<Schema.String>;
45
+ readonly status: Schema.Literals<readonly ["sent", "uncertain", "failed"]>;
46
+ readonly messageId: Schema.NullOr<Schema.String>;
47
+ readonly url: Schema.NullOr<Schema.String>;
48
+ readonly historyRecorded: Schema.Boolean;
49
+ }>;
50
+ export type DeliveryReceipt = typeof DeliveryReceipt.Type;
51
+ declare const DeliveryArchiveError_base: Schema.Class<DeliveryArchiveError, Schema.TaggedStruct<"DeliveryArchiveError", {
52
+ readonly diagnostic: Schema.String;
53
+ readonly cause: Schema.optionalKey<Schema.Unknown>;
54
+ }>, import("effect/Cause").YieldableError>;
55
+ export declare class DeliveryArchiveError extends DeliveryArchiveError_base {
56
+ }
57
+ export type DeliveryArchive = (input: {
58
+ readonly event: DeliveryEvent;
59
+ readonly delivery: DeliveryCommand;
60
+ readonly identityToken: string | undefined;
61
+ }) => Effect.Effect<DeliveryReceipt, DeliveryArchiveError>;
62
+ /** One append attempt only. A response without the v1 claim protocol cannot authorize a send. */
63
+ export declare function platformDeliveryArchive(environment: OntologyEnvironment, fetchImpl?: typeof fetch): DeliveryArchive;
64
+ export {};
@@ -0,0 +1,62 @@
1
+ import { Effect, Schema } from "effect";
2
+ export const DeliveryReceipt = Schema.Struct({
3
+ version: Schema.Literal(1),
4
+ claimed: Schema.Boolean,
5
+ duplicate: Schema.Boolean,
6
+ operationId: Schema.String,
7
+ claimId: Schema.optionalKey(Schema.String.check(Schema.isUUID())),
8
+ status: Schema.Literals(["sent", "uncertain", "failed"]),
9
+ messageId: Schema.NullOr(Schema.String),
10
+ url: Schema.NullOr(Schema.String),
11
+ historyRecorded: Schema.Boolean,
12
+ });
13
+ export class DeliveryArchiveError extends Schema.TaggedError()("DeliveryArchiveError", {
14
+ diagnostic: Schema.String,
15
+ cause: Schema.optionalKey(Schema.Unknown),
16
+ }) {
17
+ }
18
+ /** One append attempt only. A response without the v1 claim protocol cannot authorize a send. */
19
+ export function platformDeliveryArchive(environment, fetchImpl = fetch) {
20
+ return ({ event, delivery, identityToken }) => Effect.tryPromise({
21
+ try: async (signal) => {
22
+ if (!identityToken) {
23
+ throw new Error("The archive requires a production runtime identity.");
24
+ }
25
+ const origin = new URL(environment.segmentstreamUrl);
26
+ if (origin.username ||
27
+ origin.password ||
28
+ origin.search ||
29
+ origin.hash ||
30
+ (origin.protocol !== "https:" &&
31
+ !(origin.protocol === "http:" &&
32
+ ["127.0.0.1", "localhost", "[::1]"].includes(origin.hostname)))) {
33
+ throw new Error("The archive endpoint must use HTTPS or local loopback HTTP.");
34
+ }
35
+ const base = `${environment.segmentstreamUrl}/api/internal/v1/workspaces/` +
36
+ encodeURIComponent(environment.workspaceId);
37
+ const response = await fetchImpl(`${base}/agent/conversations/events`, {
38
+ method: "POST",
39
+ redirect: "error",
40
+ headers: {
41
+ "content-type": "application/json",
42
+ "x-segmentstream-organization-id": environment.organizationId,
43
+ "x-segmentstream-runtime-identity": identityToken,
44
+ },
45
+ body: JSON.stringify({ ...event, delivery }),
46
+ signal: AbortSignal.any([signal, AbortSignal.timeout(15_000)]),
47
+ });
48
+ if (!response.ok) {
49
+ throw new DeliveryArchiveError({
50
+ diagnostic: response.status === 409 ? "chat_archive_conflict" : "chat_archive_append_failed",
51
+ cause: new Error(`Archive HTTP ${response.status}; ` +
52
+ `request ${response.headers.get("x-request-id") ?? "unknown"}.`),
53
+ });
54
+ }
55
+ const result = Schema.decodeUnknownSync(Schema.Struct({ stored: Schema.Literal(true), delivery: DeliveryReceipt }))(await response.json());
56
+ return result.delivery;
57
+ },
58
+ catch: (cause) => cause instanceof DeliveryArchiveError
59
+ ? cause
60
+ : new DeliveryArchiveError({ diagnostic: "chat_archive_append_failed", cause }),
61
+ });
62
+ }
@@ -0,0 +1,26 @@
1
+ import type { ChatAttributionSettings } from "../../chat.js";
2
+ import { Effect } from "effect";
3
+ import { PermissionDenied } from "../../errors.js";
4
+ import type { Principal } from "../../runtime.js";
5
+ import type { CallerContext } from "../caller-context.js";
6
+ /** Display metadata identifies the registered client; it does not certify ownership of its name. */
7
+ export declare function chatAttribution(caller: CallerContext, name: string, settings?: ChatAttributionSettings): string | null;
8
+ /** The archive snapshot for posting, built exclusively from authenticated identity and stored names. */
9
+ export declare function deliveryRequester(caller: CallerContext, principal: Principal, name: string, settings?: ChatAttributionSettings): Effect.Effect<never, PermissionDenied, never> | Effect.Effect<{
10
+ id: string;
11
+ kind: "member" | "service";
12
+ name: string;
13
+ via: "oauth" | "service" | "hq";
14
+ clientId: string | null;
15
+ clientName: string | null;
16
+ attribution: string;
17
+ }, never, never>;
18
+ export interface ConversationRequester {
19
+ readonly id: string;
20
+ readonly kind: "member" | "service";
21
+ readonly name: string;
22
+ readonly via: "oauth" | "hq" | "service";
23
+ readonly clientId: string | null;
24
+ readonly clientName: string | null;
25
+ readonly attribution: string;
26
+ }
@@ -0,0 +1,28 @@
1
+ import { Effect } from "effect";
2
+ import { PermissionDenied } from "../../errors.js";
3
+ /** Display metadata identifies the registered client; it does not certify ownership of its name. */
4
+ export function chatAttribution(caller, name, settings = {}) {
5
+ if (caller.kind !== "oauth" && caller.kind !== "runtime" && caller.kind !== "service") {
6
+ return null;
7
+ }
8
+ return (settings.template ?? "{name}").replace(/\{(name|client)\}/g, (_, key) => key === "name" ? name : caller.kind === "oauth" ? caller.client.name : "");
9
+ }
10
+ /** The archive snapshot for posting, built exclusively from authenticated identity and stored names. */
11
+ export function deliveryRequester(caller, principal, name, settings = {}) {
12
+ const attribution = chatAttribution(caller, name, settings);
13
+ if ((caller.kind !== "oauth" && caller.kind !== "runtime" && caller.kind !== "service") ||
14
+ caller.subjectId !== principal.id ||
15
+ attribution === null ||
16
+ principal.kind !== (caller.kind === "service" ? "service" : "member")) {
17
+ return Effect.fail(new PermissionDenied({ message: "This credential cannot attribute a chat post." }));
18
+ }
19
+ return Effect.succeed({
20
+ id: principal.id,
21
+ kind: principal.kind,
22
+ name,
23
+ via: caller.kind === "runtime" ? "hq" : caller.kind,
24
+ clientId: caller.kind === "oauth" ? caller.client.id : null,
25
+ clientName: caller.kind === "oauth" ? caller.client.name : null,
26
+ attribution,
27
+ });
28
+ }
@@ -0,0 +1,18 @@
1
+ import { type TelegramPreviewContext } from "../../telegram.js";
2
+ import { ChatDelivery } from "../../chat.js";
3
+ import type { Ontology } from "../../ontology.js";
4
+ import type { Principal } from "../../runtime.js";
5
+ import type { CallerContext } from "../caller-context.js";
6
+ import type { ConnectionTransportFactory } from "../connections.js";
7
+ import type { OntologyBackend } from "../runtime-contract.js";
8
+ import type { DeliveryArchive } from "./archive.js";
9
+ import type { RuntimeChatEnvelope } from "./envelope.js";
10
+ export type ChatDeliveryFactory = (input: {
11
+ readonly backend: OntologyBackend["Service"];
12
+ readonly principal: Principal;
13
+ readonly caller: CallerContext;
14
+ readonly identityToken: string | undefined;
15
+ readonly requestId: string;
16
+ readonly envelope?: RuntimeChatEnvelope;
17
+ }) => ChatDelivery["Service"];
18
+ export declare function makeChatDelivery(ontology: Ontology, connections: ConnectionTransportFactory, archive: DeliveryArchive, previews?: TelegramPreviewContext): ChatDeliveryFactory;