@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,58 @@
1
+ /**
2
+ * Who may become a member by signing in. `invited`: only a person whose email a member row already
3
+ * holds, created by an invitation or a role grant; anyone else is refused. `open`: anyone who signs
4
+ * in becomes a member holding only `member`, as a customer-facing app wants.
5
+ */
6
+ export declare const SIGN_IN_POLICIES: readonly ["invited", "open"];
7
+ export type SignInPolicy = (typeof SIGN_IN_POLICIES)[number];
8
+ /** An internal app is closed by default: a person enters by invitation. */
9
+ export declare const DEFAULT_SIGN_IN_POLICY: SignInPolicy;
10
+ /** Channels this SDK can enforce at admission. */
11
+ export declare const CHANNEL_PROVIDERS: readonly ["telegram"];
12
+ export type ChannelProvider = (typeof CHANNEL_PROVIDERS)[number];
13
+ /** How people become members of the app. Email and channel admission are independent. */
14
+ export interface SignInOptions {
15
+ readonly policy: SignInPolicy;
16
+ readonly browser?: BrowserSignInOptions;
17
+ readonly channels?: Readonly<Partial<Record<ChannelProvider, SignInPolicy>>>;
18
+ /** Idempotent, input-free app action, run as member after channel self-registration. */
19
+ readonly onNewUser?: string;
20
+ /**
21
+ * Whether the platform's sign-in code emails also carry a link to the app's `/sign-in` page with
22
+ * the address and code in its fragment, so the person signs in without typing the code. Off when
23
+ * omitted. The page's `useSignIn()` reads the link; the app submits the code at once or asks the
24
+ * person to confirm. The link signs in whichever browser opens it.
25
+ */
26
+ readonly codeLink?: boolean;
27
+ }
28
+ /**
29
+ * How a person signs in with an address. `code`: a six-digit code, for a member who has signed in
30
+ * with Neon Auth before, so their Neon Auth account exists. `link`: an emailed sign-in link, for
31
+ * everyone else; Neon Auth sends codes only to existing accounts, and a link creates the account.
32
+ */
33
+ export declare const SIGN_IN_METHODS: readonly ["code", "link"];
34
+ export type SignInMethod = (typeof SIGN_IN_METHODS)[number];
35
+ /**
36
+ * Whether an address may sign in, and how, as `POST /api/ontology/sign-in/check` answers before the
37
+ * app sends an email. Under `invited`, only an active member's address is allowed. Under `open`,
38
+ * every address is allowed with `link`, so the answer reveals nothing about who has signed in.
39
+ */
40
+ export type SignInCheck = {
41
+ readonly allowed: false;
42
+ } | {
43
+ readonly allowed: true;
44
+ readonly method: SignInMethod;
45
+ };
46
+ export declare function isSignInPolicy(value: unknown): value is SignInPolicy;
47
+ /** Workspace-owned browser authentication policy; omission keeps legacy behavior. */
48
+ export interface BrowserSignInOptions {
49
+ readonly methods: ReadonlyArray<BrowserSignInMethod>;
50
+ readonly primary: BrowserSignInMethod;
51
+ readonly autoRedirect: boolean;
52
+ readonly local?: {
53
+ readonly port: number;
54
+ };
55
+ }
56
+ export type BrowserSignInMethod = "email" | "segmentstream";
57
+ /** Returns a stable machine code for invalid declarations. */
58
+ export declare function validateBrowserSignIn(value: unknown): string | undefined;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Who may become a member by signing in. `invited`: only a person whose email a member row already
3
+ * holds, created by an invitation or a role grant; anyone else is refused. `open`: anyone who signs
4
+ * in becomes a member holding only `member`, as a customer-facing app wants.
5
+ */
6
+ export const SIGN_IN_POLICIES = ["invited", "open"];
7
+ /** An internal app is closed by default: a person enters by invitation. */
8
+ export const DEFAULT_SIGN_IN_POLICY = "invited";
9
+ /** Channels this SDK can enforce at admission. */
10
+ export const CHANNEL_PROVIDERS = ["telegram"];
11
+ /**
12
+ * How a person signs in with an address. `code`: a six-digit code, for a member who has signed in
13
+ * with Neon Auth before, so their Neon Auth account exists. `link`: an emailed sign-in link, for
14
+ * everyone else; Neon Auth sends codes only to existing accounts, and a link creates the account.
15
+ */
16
+ export const SIGN_IN_METHODS = ["code", "link"];
17
+ export function isSignInPolicy(value) {
18
+ return SIGN_IN_POLICIES.includes(value);
19
+ }
20
+ /** Returns a stable machine code for invalid declarations. */
21
+ export function validateBrowserSignIn(value) {
22
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
23
+ return "invalid_browser";
24
+ }
25
+ const browser = value;
26
+ if (Object.keys(browser).some((key) => !["methods", "primary", "autoRedirect", "local"].includes(key))) {
27
+ return "unknown_browser_field";
28
+ }
29
+ const methods = browser.methods;
30
+ if (!Array.isArray(methods) ||
31
+ methods.length === 0 ||
32
+ new Set(methods).size !== methods.length ||
33
+ methods.some((method) => method !== "email" && method !== "segmentstream")) {
34
+ return "invalid_browser_methods";
35
+ }
36
+ if (!methods.includes(browser.primary)) {
37
+ return "invalid_browser_primary";
38
+ }
39
+ if (typeof browser.autoRedirect !== "boolean" ||
40
+ (browser.autoRedirect && (methods.length !== 1 || methods[0] !== "segmentstream"))) {
41
+ return "invalid_browser_auto_redirect";
42
+ }
43
+ if (browser.local !== undefined) {
44
+ const local = browser.local;
45
+ if (!methods.includes("segmentstream") ||
46
+ !local ||
47
+ typeof local !== "object" ||
48
+ Array.isArray(local) ||
49
+ Object.keys(local).some((key) => key !== "port") ||
50
+ !Number.isInteger(local.port) ||
51
+ Number(local.port) < 1 ||
52
+ Number(local.port) > 65535) {
53
+ return "invalid_browser_local";
54
+ }
55
+ }
56
+ return undefined;
57
+ }
@@ -0,0 +1,30 @@
1
+ import type { EntityManifest } from "./manifest.js";
2
+ /** A warehouse asset supplies a warehouse-backed entity's records. Keys name physical columns. */
3
+ export interface WarehouseSource {
4
+ readonly asset: string;
5
+ readonly key: ReadonlyArray<string>;
6
+ readonly currency?: string;
7
+ }
8
+ export declare function warehouse(asset: string, options: Omit<WarehouseSource, "asset">): WarehouseSource;
9
+ /** Normalize scalar pipeline and warehouse schema spellings without accepting nested values. */
10
+ export declare function warehouseColumnType(value: unknown): string | undefined;
11
+ export declare function compatibleWarehouseColumn(propertyType: string, field: {
12
+ readonly type?: unknown;
13
+ readonly mode?: unknown;
14
+ readonly fields?: unknown;
15
+ }): boolean;
16
+ export declare class SourceMappingError extends Error {
17
+ readonly entity: string;
18
+ readonly asset: string;
19
+ readonly column?: string | undefined;
20
+ constructor(entity: string, asset: string, column?: string | undefined);
21
+ }
22
+ /** Validate mappings against a deployment's pipeline schema, never against live warehouse values. */
23
+ export declare function validateWarehouseSource(entity: EntityManifest, assets: readonly unknown[]): {
24
+ readonly schema: readonly unknown[];
25
+ readonly partitioning: {
26
+ readonly type: string;
27
+ readonly column?: string;
28
+ readonly timezone?: string;
29
+ };
30
+ };
package/dist/source.js ADDED
@@ -0,0 +1,107 @@
1
+ export function warehouse(asset, options) {
2
+ return { asset, ...options };
3
+ }
4
+ /** Normalize scalar pipeline and warehouse schema spellings without accepting nested values. */
5
+ export function warehouseColumnType(value) {
6
+ if (typeof value !== "string") {
7
+ return undefined;
8
+ }
9
+ const type = value.replace(/^!/, "").toUpperCase();
10
+ if (/^(?:STRING|TEXT)$/.test(type)) {
11
+ return "text";
12
+ }
13
+ if (/^(?:INTEGER|INT8|INT16|INT32|INT64)$/.test(type)) {
14
+ return "integer";
15
+ }
16
+ if (/^(?:FLOAT|FLOAT32|FLOAT64|DOUBLE|NUMERIC|BIGNUMERIC|DECIMAL(?:\(\d+,\s*\d+\))?)$/.test(type)) {
17
+ return "number";
18
+ }
19
+ if (type === "BOOL" || type === "BOOLEAN") {
20
+ return "boolean";
21
+ }
22
+ if (type === "DATE") {
23
+ return "date";
24
+ }
25
+ if (type === "TIMESTAMP") {
26
+ return "timestamp";
27
+ }
28
+ return undefined;
29
+ }
30
+ export function compatibleWarehouseColumn(propertyType, field) {
31
+ if ((typeof field.mode === "string" && field.mode.toUpperCase() === "REPEATED") ||
32
+ (Array.isArray(field.fields) && field.fields.length > 0)) {
33
+ return false;
34
+ }
35
+ const type = warehouseColumnType(field.type);
36
+ return (type !== undefined &&
37
+ (type === propertyType ||
38
+ (propertyType === "select" && type === "text") ||
39
+ (propertyType === "number" && type === "integer")));
40
+ }
41
+ export class SourceMappingError extends Error {
42
+ entity;
43
+ asset;
44
+ column;
45
+ constructor(entity, asset, column) {
46
+ super(`Invalid warehouse source ${entity}: ${asset}${column ? ` (${column})` : ""}.`);
47
+ this.entity = entity;
48
+ this.asset = asset;
49
+ this.column = column;
50
+ this.name = "SourceMappingError";
51
+ }
52
+ }
53
+ /** Validate mappings against a deployment's pipeline schema, never against live warehouse values. */
54
+ export function validateWarehouseSource(entity, assets) {
55
+ const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value)
56
+ ? value
57
+ : undefined;
58
+ const source = entity.source;
59
+ const fail = (column) => {
60
+ throw new SourceMappingError(entity.name, source?.asset ?? "missing", column);
61
+ };
62
+ if (!source || !source.key.length || new Set(source.key).size !== source.key.length) {
63
+ fail();
64
+ }
65
+ const asset = assets.map(record).find((asset) => asset?.key === source.asset);
66
+ if (!asset || !Array.isArray(asset.modelSchema)) {
67
+ fail();
68
+ }
69
+ const schema = asset.modelSchema;
70
+ const columns = new Map(schema.flatMap((value) => {
71
+ const field = record(value);
72
+ return field && typeof field.name === "string" ? [[field.name, field]] : [];
73
+ }));
74
+ for (const key of source.key) {
75
+ const field = columns.get(key);
76
+ const type = warehouseColumnType(field?.type);
77
+ if (!field || !type || !compatibleWarehouseColumn(type, field)) {
78
+ fail(key);
79
+ }
80
+ }
81
+ for (const property of entity.properties) {
82
+ const field = columns.get(property.column ?? "");
83
+ if (!field || !compatibleWarehouseColumn(property.type, field)) {
84
+ fail(property.column ?? property.name);
85
+ }
86
+ }
87
+ const rawPartition = asset.partitioning;
88
+ const partition = rawPartition === undefined ? { type: "unpartitioned" } : record(rawPartition);
89
+ if (!partition || typeof partition.type !== "string") {
90
+ fail();
91
+ }
92
+ const type = partition.type;
93
+ const column = typeof partition.column === "string" ? partition.column : undefined;
94
+ if (type !== "unpartitioned" &&
95
+ (!column ||
96
+ !entity.properties.some((p) => p.column === column && ["date", "timestamp"].includes(p.type)))) {
97
+ fail(column);
98
+ }
99
+ const timezone = typeof partition.timezone === "string" ? partition.timezone : "UTC";
100
+ try {
101
+ new Intl.DateTimeFormat("en", { timeZone: timezone }).format(0);
102
+ }
103
+ catch {
104
+ fail(column);
105
+ }
106
+ return { schema, partitioning: { type, ...(column ? { column } : {}), timezone } };
107
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * What the start recovery run and the ontology service agree on. The `workflows` entry imports this
3
+ * module for the run's body and step; the service imports it for the step's implementation. It
4
+ * imports nothing and holds no I/O.
5
+ *
6
+ * An action whose triggers may fire arms a recovery run before its transaction opens. The run
7
+ * sleeps, then sweeps the pending starts of `_workflow_starts`: the rows an earlier request's
8
+ * commit left without a run id because the process died or the Workflow SDK refused the start.
9
+ * Sleeping costs nothing and touches no database, so an idle workspace is never visited.
10
+ */
11
+ /** A recovery run's first sweep, after the request that armed it has committed or failed. */
12
+ export declare const RECOVERY_FIRST_SWEEP_MS = 60000;
13
+ /**
14
+ * After an empty sweep, one more a minute later, so that every request the run covers has
15
+ * committed before the run's last look. A request is covered when its transaction deadline falls
16
+ * before the run's horizon: its first sweep plus this delay.
17
+ */
18
+ export declare const RECOVERY_CONFIRM_MS = 60000;
19
+ /** Sleeps between sweeps while starts keep failing; the last one repeats. */
20
+ export declare const RECOVERY_RETRY_MS: ReadonlyArray<number>;
21
+ /** Coverage the arming request keeps back from the run's horizon, for the start's own latency. */
22
+ export declare const RECOVERY_COVERAGE_MARGIN_MS = 5000;
23
+ /** The sweeps one run makes at most; rows still pending then are left for an operator's sweep. */
24
+ export declare const RECOVERY_MAX_SWEEPS = 32;
25
+ /** The step's input: the horizon the run answers for, from its second sweep on. */
26
+ export interface StartRecoveryInput {
27
+ /** Count as waiting only the pending rows created before this instant, ISO 8601. */
28
+ readonly before?: string;
29
+ }
30
+ /** What one sweep did and what is left. */
31
+ export interface StartRecoveryOutcome {
32
+ readonly started: number;
33
+ readonly failed: number;
34
+ /** Pending rows that failed too often; the automatic sweep skips them. */
35
+ readonly abandoned: number;
36
+ /** Pending rows an automatic sweep still takes, created before `before` when it was given. */
37
+ readonly waiting: number;
38
+ /** The database's clock at the sweep, ISO 8601 with milliseconds. */
39
+ readonly at: string;
40
+ }
41
+ /** A recovery run's result: its sweeps added up. */
42
+ export interface StartRecoveryReport {
43
+ readonly sweeps: number;
44
+ readonly started: number;
45
+ readonly failed: number;
46
+ /** Rows created before the run's horizon that were still pending when the run ended. */
47
+ readonly waiting: number;
48
+ readonly abandoned: number;
49
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * What the start recovery run and the ontology service agree on. The `workflows` entry imports this
3
+ * module for the run's body and step; the service imports it for the step's implementation. It
4
+ * imports nothing and holds no I/O.
5
+ *
6
+ * An action whose triggers may fire arms a recovery run before its transaction opens. The run
7
+ * sleeps, then sweeps the pending starts of `_workflow_starts`: the rows an earlier request's
8
+ * commit left without a run id because the process died or the Workflow SDK refused the start.
9
+ * Sleeping costs nothing and touches no database, so an idle workspace is never visited.
10
+ */
11
+ /** A recovery run's first sweep, after the request that armed it has committed or failed. */
12
+ export const RECOVERY_FIRST_SWEEP_MS = 60_000;
13
+ /**
14
+ * After an empty sweep, one more a minute later, so that every request the run covers has
15
+ * committed before the run's last look. A request is covered when its transaction deadline falls
16
+ * before the run's horizon: its first sweep plus this delay.
17
+ */
18
+ export const RECOVERY_CONFIRM_MS = 60_000;
19
+ /** Sleeps between sweeps while starts keep failing; the last one repeats. */
20
+ export const RECOVERY_RETRY_MS = [
21
+ 60_000, 120_000, 300_000, 600_000, 1_800_000, 3_600_000,
22
+ ];
23
+ /** Coverage the arming request keeps back from the run's horizon, for the start's own latency. */
24
+ export const RECOVERY_COVERAGE_MARGIN_MS = 5_000;
25
+ /** The sweeps one run makes at most; rows still pending then are left for an operator's sweep. */
26
+ export const RECOVERY_MAX_SWEEPS = 32;
@@ -0,0 +1,27 @@
1
+ import { type StartRecoveryReport } from "./start-recovery-contract.js";
2
+ export type { StartRecoveryInput, StartRecoveryOutcome, StartRecoveryReport, } from "./start-recovery-contract.js";
3
+ /**
4
+ * The start recovery run's body, for the platform workflow `ontologyWorkflows()` compiles into the
5
+ * workspace's bundle. This module is part of the `workflows` entry, which the Workflow SDK bundles
6
+ * for a runtime without Node built-ins: it imports none, and none of the SDK. Its step only calls
7
+ * the ontology service through the process's workflow binding, as `agentTask`'s steps do.
8
+ */
9
+ /** `recoverWorkflowStarts` was called outside a `"use workflow"` body. Marked fatal. */
10
+ export declare class StartRecoveryWorkflowRequired extends Error {
11
+ readonly fatal = true;
12
+ constructor();
13
+ }
14
+ /**
15
+ * Sleeps, then sweeps the pending starts until none created before the run's horizon is left, and
16
+ * answers with what it did. The horizon is the first sweep's instant plus {@link RECOVERY_CONFIRM_MS},
17
+ * read from the database's clock in the step's result so that a replay computes the same value.
18
+ * An empty sweep is confirmed by one more at the horizon; a sweep that failed starts is followed by
19
+ * another after a growing delay, until every such row is started or abandoned. Rows created after
20
+ * the horizon belong to the runs their own requests armed.
21
+ */
22
+ export declare function recoverWorkflowStarts(
23
+ /** Shorter sleeps, for tests; the generated platform workflow passes none. */
24
+ delays?: {
25
+ readonly firstSweepMs?: number;
26
+ readonly confirmMs?: number;
27
+ }): Promise<StartRecoveryReport>;
@@ -0,0 +1,81 @@
1
+ import { RECOVERY_CONFIRM_MS, RECOVERY_FIRST_SWEEP_MS, RECOVERY_MAX_SWEEPS, RECOVERY_RETRY_MS, } from "./start-recovery-contract.js";
2
+ import { boundStep } from "./workflow-runtime.js";
3
+ /**
4
+ * The start recovery run's body, for the platform workflow `ontologyWorkflows()` compiles into the
5
+ * workspace's bundle. This module is part of the `workflows` entry, which the Workflow SDK bundles
6
+ * for a runtime without Node built-ins: it imports none, and none of the SDK. Its step only calls
7
+ * the ontology service through the process's workflow binding, as `agentTask`'s steps do.
8
+ */
9
+ /** `recoverWorkflowStarts` was called outside a `"use workflow"` body. Marked fatal. */
10
+ export class StartRecoveryWorkflowRequired extends Error {
11
+ fatal = true;
12
+ constructor() {
13
+ super('recoverWorkflowStarts runs only in the "use workflow" body of the platform\'s recovery ' +
14
+ "workflow, which ontologyWorkflows() compiles.");
15
+ this.name = "StartRecoveryWorkflowRequired";
16
+ }
17
+ }
18
+ /**
19
+ * The Workflow SDK's `sleep` inside a `"use workflow"` body, read from the `globalThis` symbol its
20
+ * workflow sandbox sets; `undefined` in a step and outside a workflow.
21
+ */
22
+ function workflowSleep() {
23
+ const sleep = globalThis[Symbol.for("WORKFLOW_SLEEP")];
24
+ return typeof sleep === "function"
25
+ ? sleep
26
+ : undefined;
27
+ }
28
+ /** One sweep of the pending starts, through the service that serves this process's runs. */
29
+ async function recoverStartsStep(input) {
30
+ "use step";
31
+ const { binding, step } = boundStep();
32
+ return binding.recoverStarts(step, input);
33
+ }
34
+ function add(report, outcome) {
35
+ return {
36
+ sweeps: report.sweeps + 1,
37
+ started: report.started + outcome.started,
38
+ failed: report.failed + outcome.failed,
39
+ waiting: outcome.waiting,
40
+ abandoned: outcome.abandoned,
41
+ };
42
+ }
43
+ /**
44
+ * Sleeps, then sweeps the pending starts until none created before the run's horizon is left, and
45
+ * answers with what it did. The horizon is the first sweep's instant plus {@link RECOVERY_CONFIRM_MS},
46
+ * read from the database's clock in the step's result so that a replay computes the same value.
47
+ * An empty sweep is confirmed by one more at the horizon; a sweep that failed starts is followed by
48
+ * another after a growing delay, until every such row is started or abandoned. Rows created after
49
+ * the horizon belong to the runs their own requests armed.
50
+ */
51
+ export async function recoverWorkflowStarts(
52
+ /** Shorter sleeps, for tests; the generated platform workflow passes none. */
53
+ delays = {}) {
54
+ const sleep = workflowSleep();
55
+ if (sleep === undefined) {
56
+ throw new StartRecoveryWorkflowRequired();
57
+ }
58
+ const firstSweepMs = delays.firstSweepMs ?? RECOVERY_FIRST_SWEEP_MS;
59
+ const confirmMs = delays.confirmMs ?? RECOVERY_CONFIRM_MS;
60
+ await sleep(firstSweepMs);
61
+ const first = await recoverStartsStep({});
62
+ const before = new Date(Date.parse(first.at) + confirmMs).toISOString();
63
+ let report = add({ sweeps: 0, started: 0, failed: 0, waiting: 0, abandoned: 0 }, first);
64
+ let outcome = first;
65
+ let retries = 0;
66
+ while (report.sweeps < RECOVERY_MAX_SWEEPS) {
67
+ if (outcome.failed > 0) {
68
+ await sleep(RECOVERY_RETRY_MS[Math.min(retries, RECOVERY_RETRY_MS.length - 1)]);
69
+ retries += 1;
70
+ }
71
+ else {
72
+ await sleep(confirmMs);
73
+ }
74
+ outcome = await recoverStartsStep({ before });
75
+ report = add(report, outcome);
76
+ if (outcome.waiting === 0) {
77
+ break;
78
+ }
79
+ }
80
+ return report;
81
+ }
@@ -0,0 +1,4 @@
1
+ import { Schema } from "effect";
2
+ import { HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi";
3
+ export declare const STORAGE_GROUP = "BlobStorage";
4
+ export declare function storageGroup(authenticate: (endpoint: HttpApiEndpoint.Top) => HttpApiEndpoint.Top, errors: ReadonlyArray<Schema.Top>, maintenanceErrors: (endpoint: HttpApiEndpoint.Top) => HttpApiEndpoint.Top): HttpApiGroup.HttpApiGroup<"BlobStorage", HttpApiEndpoint.Top | HttpApiEndpoint.HttpApiEndpoint<string, import("effect/unstable/http/HttpMethod").HttpMethod, string, Schema.Top, Schema.Top, Schema.Top, Schema.Top, Schema.Top, Schema.Top, any, unknown>, false>;
@@ -0,0 +1,40 @@
1
+ import { Schema } from "effect";
2
+ import { HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi";
3
+ import { StorageMaintenanceAuthentication } from "./maintenance-auth.js";
4
+ import { BeginUpload, OpenUploads, UploadView, TransferGrant } from "./sessions.js";
5
+ export const STORAGE_GROUP = "BlobStorage";
6
+ export function storageGroup(authenticate, errors, maintenanceErrors) {
7
+ const base = "/api/ontology/uploads";
8
+ const params = { id: Schema.String.check(Schema.isUUID()) };
9
+ const endpoints = [
10
+ HttpApiEndpoint.get("list", base, { success: OpenUploads, error: errors }),
11
+ HttpApiEndpoint.post("begin", base, {
12
+ payload: BeginUpload,
13
+ success: UploadView,
14
+ error: errors,
15
+ }),
16
+ HttpApiEndpoint.get("status", `${base}/:id`, { params, success: UploadView, error: errors }),
17
+ HttpApiEndpoint.post("part", `${base}/:id/parts`, {
18
+ params,
19
+ success: TransferGrant,
20
+ error: errors,
21
+ }),
22
+ HttpApiEndpoint.post("complete", `${base}/:id/complete`, {
23
+ params,
24
+ success: UploadView,
25
+ error: errors,
26
+ }),
27
+ HttpApiEndpoint.post("cancel", `${base}/:id/cancel`, {
28
+ params,
29
+ success: UploadView,
30
+ error: errors,
31
+ }),
32
+ ];
33
+ const [first, ...rest] = endpoints.map(authenticate);
34
+ return HttpApiGroup.make(STORAGE_GROUP)
35
+ .add(first, ...rest)
36
+ .add(maintenanceErrors(HttpApiEndpoint.post("maintain", "/api/ontology/internal/storage/maintenance", {
37
+ success: Schema.Struct({ removed: Schema.Int }),
38
+ error: errors,
39
+ })).middleware(StorageMaintenanceAuthentication));
40
+ }
@@ -0,0 +1,146 @@
1
+ import { Effect, Schema } from "effect";
2
+ import type { SqlClient } from "effect/unstable/sql";
3
+ import { ActionRejected, Conflict, NotFound, type PermissionDenied } from "../errors.js";
4
+ import type { Ontology } from "../ontology.js";
5
+ import type { Principal } from "../runtime.js";
6
+ import type { BlobProvider, TransferGrant } from "./provider.js";
7
+ import { ATTACHMENT_SOURCES } from "./tables.js";
8
+ /**
9
+ * The agent's temporary attachments: a file a member sends the app's agent is stored once, as a
10
+ * `_blobs` revision in the ontology's private file storage. Group files belong to the chat's current
11
+ * members; private files belong to their sender and the agent session that first reads them.
12
+ * Nothing about it is an ontology record. It expires 24 hours after receipt; the agent may read it,
13
+ * discard it, or promote it into a record through an action, which adopts the same stored object
14
+ * without copying it. Every operation derives chat access from the caller and registry, never from
15
+ * tool input.
16
+ */
17
+ /** The largest file the agent takes: what Telegram's Bot API lets a bot download. */
18
+ export declare const MAX_ATTACHMENT_BYTES: number;
19
+ /** How long an attachment stays readable after it arrives; reads never extend it. */
20
+ export declare const ATTACHMENT_TTL_HOURS = 24;
21
+ /** Live attachments one member may hold at once, so a busy chat cannot fill the storage. */
22
+ export declare const MAX_LIVE_ATTACHMENTS = 50;
23
+ export { ATTACHMENT_SOURCES };
24
+ /** Who asks, as the agent's runtime knows it: the member, their chat and the agent session. */
25
+ export interface AttachmentCaller {
26
+ readonly principal: Principal;
27
+ /** The chat the attachment arrived in, such as `telegram:12345`. */
28
+ readonly conversation: string;
29
+ /**
30
+ * The agent session the request comes from. Private attachments stay bound to the first session
31
+ * that reads them. Group attachments are shared across authorized sessions in the same chat.
32
+ */
33
+ readonly sessionId?: string;
34
+ /** Trusted user boundary; never accepted from agent tool arguments. */
35
+ readonly access?: "member";
36
+ }
37
+ export interface ReceiveAttachment {
38
+ readonly source: (typeof ATTACHMENT_SOURCES)[number];
39
+ /** Identifies the file at its source, such as the message and attachment index; retries reuse it. */
40
+ readonly sourceRef: string;
41
+ readonly filename: string;
42
+ readonly contentType: string;
43
+ readonly size: number;
44
+ readonly sha256: string;
45
+ }
46
+ export interface AttachmentView {
47
+ readonly id: string;
48
+ readonly filename: string;
49
+ readonly contentType: string;
50
+ readonly size: number;
51
+ readonly sha256: string;
52
+ readonly state: string;
53
+ readonly createdAt: string;
54
+ readonly expiresAt: string;
55
+ readonly promotion: unknown;
56
+ readonly conversation?: string;
57
+ readonly senderId?: string;
58
+ }
59
+ export interface AttachmentSearch {
60
+ readonly conversation?: string;
61
+ readonly senderId?: string;
62
+ readonly from?: string;
63
+ readonly to?: string;
64
+ readonly before?: string;
65
+ readonly limit?: number;
66
+ }
67
+ export interface PromotionTarget {
68
+ /** The entity whose action adopts the file, such as `document`. */
69
+ readonly entity: string;
70
+ /** The action, such as `upload` or `create`. */
71
+ readonly action: string;
72
+ /** The action's input without the file; the field that takes the upload is filled in. */
73
+ readonly input: Readonly<Record<string, unknown>>;
74
+ /** The input field that takes the upload, when the action has more than one. */
75
+ readonly field?: string;
76
+ /** The record the action updates, for an action that sets the file on an existing record. */
77
+ readonly recordId?: string;
78
+ }
79
+ /** Runs the promotion's action as the caller, with the upload's options. */
80
+ export type PromotionRunner = (input: {
81
+ readonly entity: string;
82
+ readonly action: string;
83
+ readonly input: Readonly<Record<string, unknown>>;
84
+ readonly options: {
85
+ readonly idempotencyKey: string;
86
+ readonly createIntent?: string;
87
+ };
88
+ }) => Effect.Effect<{
89
+ readonly result: unknown;
90
+ readonly edits: ReadonlyArray<unknown>;
91
+ }, unknown>;
92
+ /** The fields of an action's input that take an upload, with the property each one writes. */
93
+ export declare function uploadFields(input: Schema.Top): ReadonlyArray<{
94
+ readonly field: string;
95
+ readonly entity: string;
96
+ readonly property: string;
97
+ }>;
98
+ /** Persisted phases surround every provider call; no external I/O holds a database transaction. */
99
+ export declare function attachmentRuntime(ontology: Ontology, sql: SqlClient.SqlClient, provider: BlobProvider["Service"]): {
100
+ receive: (input: ReceiveAttachment, caller: AttachmentCaller) => Effect.Effect<{
101
+ attachment: AttachmentView;
102
+ upload?: undefined;
103
+ } | {
104
+ attachment: AttachmentView;
105
+ upload: TransferGrant;
106
+ }, ActionRejected | PermissionDenied | Conflict | NotFound | import("effect/unstable/sql/SqlError").SqlError | import("./provider.js").BlobStorageError, never>;
107
+ complete: (id: string, caller: AttachmentCaller) => Effect.Effect<AttachmentView, ActionRejected | PermissionDenied | Conflict | NotFound | import("effect/unstable/sql/SqlError").SqlError | import("./provider.js").BlobStorageError, never>;
108
+ list: (caller: AttachmentCaller) => Effect.Effect<AttachmentView[], PermissionDenied | import("effect/unstable/sql/SqlError").SqlError, never>;
109
+ read: (id: string, caller: AttachmentCaller) => Effect.Effect<{
110
+ attachment: AttachmentView;
111
+ download: TransferGrant;
112
+ }, PermissionDenied | Conflict | NotFound | import("effect/unstable/sql/SqlError").SqlError | import("./provider.js").BlobStorageError, never>;
113
+ discard: (id: string, caller: AttachmentCaller) => Effect.Effect<AttachmentView, PermissionDenied | Conflict | NotFound | import("effect/unstable/sql/SqlError").SqlError, never>;
114
+ promote: (id: string, target: PromotionTarget, caller: AttachmentCaller, run: PromotionRunner) => Effect.Effect<{
115
+ attachment: AttachmentView;
116
+ deduplicated: boolean;
117
+ result: {} | null;
118
+ }, unknown, never>;
119
+ listForMember: (filters: AttachmentSearch, principal: Principal) => Effect.Effect<{
120
+ attachments: AttachmentView[];
121
+ nextCursor: string | null;
122
+ }, PermissionDenied | NotFound | import("effect/unstable/sql/SqlError").SqlError, never>;
123
+ getForMember: (id: string, principal: Principal) => Effect.Effect<AttachmentView, PermissionDenied | Conflict | NotFound | import("effect/unstable/sql/SqlError").SqlError, never>;
124
+ readForMember: (id: string, principal: Principal) => Effect.Effect<{
125
+ attachment: AttachmentView;
126
+ download: TransferGrant;
127
+ }, PermissionDenied | Conflict | NotFound | import("effect/unstable/sql/SqlError").SqlError | import("./provider.js").BlobStorageError, never>;
128
+ promoteForMember: (id: string, target: PromotionTarget, principal: Principal, run: PromotionRunner) => Effect.Effect<{
129
+ attachment: AttachmentView;
130
+ deduplicated: boolean;
131
+ result: {} | null;
132
+ }, unknown, never>;
133
+ };
134
+ export type AttachmentRuntime = ReturnType<typeof attachmentRuntime>;
135
+ export type AttachmentFailure = ActionRejected | Conflict | NotFound | PermissionDenied;
136
+ /**
137
+ * Expires attachments past their deadline and removes the bytes of every expired or discarded one
138
+ * that no record adopted. A revision a promotion ticket still points at is left to the upload
139
+ * maintenance, once the ticket is canceled. Runs from the storage maintenance schedule, so files
140
+ * expire while the agent is idle.
141
+ */
142
+ export declare function maintainAttachments(sql: SqlClient.SqlClient, provider: BlobProvider["Service"], limit?: number): Effect.Effect<{
143
+ expired: number;
144
+ removed: number;
145
+ hasMore: boolean;
146
+ }, import("effect/unstable/sql/SqlError").SqlError | import("./provider.js").BlobStorageError, never>;