@retinue/agentkit 0.1.0

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 (405) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +310 -0
  3. package/dist/adapters/bullmq/consumer.d.ts +33 -0
  4. package/dist/adapters/bullmq/consumer.js +41 -0
  5. package/dist/adapters/bullmq/dispatcher.d.ts +74 -0
  6. package/dist/adapters/bullmq/dispatcher.js +160 -0
  7. package/dist/adapters/bullmq/export.d.ts +31 -0
  8. package/dist/adapters/bullmq/export.js +53 -0
  9. package/dist/adapters/bullmq/extraction.d.ts +42 -0
  10. package/dist/adapters/bullmq/extraction.js +63 -0
  11. package/dist/adapters/bullmq/index.d.ts +13 -0
  12. package/dist/adapters/bullmq/index.js +13 -0
  13. package/dist/adapters/bullmq/lock.d.ts +77 -0
  14. package/dist/adapters/bullmq/lock.js +126 -0
  15. package/dist/adapters/bullmq/queue.d.ts +50 -0
  16. package/dist/adapters/bullmq/queue.js +81 -0
  17. package/dist/adapters/memory/artifact-exports.d.ts +11 -0
  18. package/dist/adapters/memory/artifact-exports.js +102 -0
  19. package/dist/adapters/memory/artifacts.d.ts +15 -0
  20. package/dist/adapters/memory/artifacts.js +134 -0
  21. package/dist/adapters/memory/blobs.d.ts +7 -0
  22. package/dist/adapters/memory/blobs.js +27 -0
  23. package/dist/adapters/memory/evaluation.d.ts +18 -0
  24. package/dist/adapters/memory/evaluation.js +148 -0
  25. package/dist/adapters/memory/files.d.ts +27 -0
  26. package/dist/adapters/memory/files.js +0 -0
  27. package/dist/adapters/memory/flows.d.ts +16 -0
  28. package/dist/adapters/memory/flows.js +117 -0
  29. package/dist/adapters/memory/hitl.d.ts +9 -0
  30. package/dist/adapters/memory/hitl.js +130 -0
  31. package/dist/adapters/memory/idempotency.d.ts +13 -0
  32. package/dist/adapters/memory/idempotency.js +32 -0
  33. package/dist/adapters/memory/index.d.ts +39 -0
  34. package/dist/adapters/memory/index.js +107 -0
  35. package/dist/adapters/memory/knowledge.d.ts +43 -0
  36. package/dist/adapters/memory/knowledge.js +248 -0
  37. package/dist/adapters/memory/mcp.d.ts +9 -0
  38. package/dist/adapters/memory/mcp.js +37 -0
  39. package/dist/adapters/memory/message-store.d.ts +17 -0
  40. package/dist/adapters/memory/message-store.js +70 -0
  41. package/dist/adapters/memory/principal-memory.d.ts +7 -0
  42. package/dist/adapters/memory/principal-memory.js +83 -0
  43. package/dist/adapters/memory/runtime.d.ts +29 -0
  44. package/dist/adapters/memory/runtime.js +0 -0
  45. package/dist/adapters/memory/sessions.d.ts +29 -0
  46. package/dist/adapters/memory/sessions.js +0 -0
  47. package/dist/adapters/memory/skills.d.ts +10 -0
  48. package/dist/adapters/memory/skills.js +41 -0
  49. package/dist/adapters/memory/thread-summary.d.ts +7 -0
  50. package/dist/adapters/memory/thread-summary.js +29 -0
  51. package/dist/adapters/memory/usage-limits.d.ts +13 -0
  52. package/dist/adapters/memory/usage-limits.js +72 -0
  53. package/dist/adapters/memory/usage.d.ts +16 -0
  54. package/dist/adapters/memory/usage.js +279 -0
  55. package/dist/adapters/otel/index.d.ts +111 -0
  56. package/dist/adapters/otel/index.js +133 -0
  57. package/dist/adapters/postgres/artifact-exports.d.ts +12 -0
  58. package/dist/adapters/postgres/artifact-exports.js +117 -0
  59. package/dist/adapters/postgres/artifacts.d.ts +16 -0
  60. package/dist/adapters/postgres/artifacts.js +172 -0
  61. package/dist/adapters/postgres/checkpoint-store.d.ts +16 -0
  62. package/dist/adapters/postgres/checkpoint-store.js +34 -0
  63. package/dist/adapters/postgres/config.d.ts +15 -0
  64. package/dist/adapters/postgres/config.js +187 -0
  65. package/dist/adapters/postgres/conversation-store.d.ts +4 -0
  66. package/dist/adapters/postgres/conversation-store.js +82 -0
  67. package/dist/adapters/postgres/evaluation.d.ts +17 -0
  68. package/dist/adapters/postgres/evaluation.js +193 -0
  69. package/dist/adapters/postgres/file-content.d.ts +30 -0
  70. package/dist/adapters/postgres/file-content.js +111 -0
  71. package/dist/adapters/postgres/files.d.ts +19 -0
  72. package/dist/adapters/postgres/files.js +209 -0
  73. package/dist/adapters/postgres/flows.d.ts +20 -0
  74. package/dist/adapters/postgres/flows.js +206 -0
  75. package/dist/adapters/postgres/hitl.d.ts +5 -0
  76. package/dist/adapters/postgres/hitl.js +247 -0
  77. package/dist/adapters/postgres/index.d.ts +35 -0
  78. package/dist/adapters/postgres/index.js +35 -0
  79. package/dist/adapters/postgres/knowledge.d.ts +48 -0
  80. package/dist/adapters/postgres/knowledge.js +255 -0
  81. package/dist/adapters/postgres/memory.d.ts +14 -0
  82. package/dist/adapters/postgres/memory.js +194 -0
  83. package/dist/adapters/postgres/message-store.d.ts +11 -0
  84. package/dist/adapters/postgres/message-store.js +145 -0
  85. package/dist/adapters/postgres/migrations.d.ts +69 -0
  86. package/dist/adapters/postgres/migrations.js +1594 -0
  87. package/dist/adapters/postgres/pg-executor.d.ts +19 -0
  88. package/dist/adapters/postgres/pg-executor.js +32 -0
  89. package/dist/adapters/postgres/retention.d.ts +26 -0
  90. package/dist/adapters/postgres/retention.js +59 -0
  91. package/dist/adapters/postgres/rollups.d.ts +17 -0
  92. package/dist/adapters/postgres/rollups.js +267 -0
  93. package/dist/adapters/postgres/run-coordinator.d.ts +5 -0
  94. package/dist/adapters/postgres/run-coordinator.js +98 -0
  95. package/dist/adapters/postgres/run-event-log.d.ts +26 -0
  96. package/dist/adapters/postgres/run-event-log.js +30 -0
  97. package/dist/adapters/postgres/run-store.d.ts +4 -0
  98. package/dist/adapters/postgres/run-store.js +199 -0
  99. package/dist/adapters/postgres/schema.d.ts +39 -0
  100. package/dist/adapters/postgres/schema.js +70 -0
  101. package/dist/adapters/postgres/session-state.d.ts +7 -0
  102. package/dist/adapters/postgres/session-state.js +99 -0
  103. package/dist/adapters/postgres/sql.d.ts +8 -0
  104. package/dist/adapters/postgres/sql.js +2 -0
  105. package/dist/adapters/postgres/transaction.d.ts +37 -0
  106. package/dist/adapters/postgres/transaction.js +93 -0
  107. package/dist/adapters/postgres/unit-of-work.d.ts +18 -0
  108. package/dist/adapters/postgres/unit-of-work.js +8 -0
  109. package/dist/adapters/postgres/usage-limits.d.ts +15 -0
  110. package/dist/adapters/postgres/usage-limits.js +136 -0
  111. package/dist/adapters/postgres/usage.d.ts +15 -0
  112. package/dist/adapters/postgres/usage.js +226 -0
  113. package/dist/adapters/redis/index.d.ts +9 -0
  114. package/dist/adapters/redis/index.js +9 -0
  115. package/dist/adapters/redis/realtime.d.ts +74 -0
  116. package/dist/adapters/redis/realtime.js +112 -0
  117. package/dist/adapters/supabase/index.d.ts +88 -0
  118. package/dist/adapters/supabase/index.js +84 -0
  119. package/dist/adapters/supabase/realtime.d.ts +30 -0
  120. package/dist/adapters/supabase/realtime.js +53 -0
  121. package/dist/adapters/supabase/rls.d.ts +99 -0
  122. package/dist/adapters/supabase/rls.js +216 -0
  123. package/dist/adapters/supabase/storage.d.ts +50 -0
  124. package/dist/adapters/supabase/storage.js +207 -0
  125. package/dist/agents/agent.d.ts +66 -0
  126. package/dist/agents/agent.js +209 -0
  127. package/dist/agents/define.d.ts +21 -0
  128. package/dist/agents/define.js +63 -0
  129. package/dist/agents/engine.d.ts +98 -0
  130. package/dist/agents/engine.js +462 -0
  131. package/dist/agents/index.d.ts +50 -0
  132. package/dist/agents/index.js +17 -0
  133. package/dist/artifacts/index.d.ts +114 -0
  134. package/dist/artifacts/index.js +219 -0
  135. package/dist/authorization/index.d.ts +76 -0
  136. package/dist/authorization/index.js +76 -0
  137. package/dist/capabilities/index.d.ts +120 -0
  138. package/dist/capabilities/index.js +167 -0
  139. package/dist/capabilities/runtime.d.ts +89 -0
  140. package/dist/capabilities/runtime.js +84 -0
  141. package/dist/citations/index.d.ts +161 -0
  142. package/dist/citations/index.js +182 -0
  143. package/dist/context/assembler.d.ts +82 -0
  144. package/dist/context/assembler.js +129 -0
  145. package/dist/context/compaction.d.ts +45 -0
  146. package/dist/context/compaction.js +55 -0
  147. package/dist/context/index.d.ts +75 -0
  148. package/dist/context/index.js +17 -0
  149. package/dist/core/content-parts.d.ts +194 -0
  150. package/dist/core/content-parts.js +23 -0
  151. package/dist/core/context.d.ts +51 -0
  152. package/dist/core/context.js +9 -0
  153. package/dist/core/env.d.ts +25 -0
  154. package/dist/core/env.js +41 -0
  155. package/dist/core/errors.d.ts +30 -0
  156. package/dist/core/errors.js +65 -0
  157. package/dist/core/events.d.ts +139 -0
  158. package/dist/core/events.js +99 -0
  159. package/dist/core/ids.d.ts +52 -0
  160. package/dist/core/ids.js +13 -0
  161. package/dist/core/index.d.ts +9 -0
  162. package/dist/core/index.js +9 -0
  163. package/dist/core/tokens.d.ts +22 -0
  164. package/dist/core/tokens.js +22 -0
  165. package/dist/core/validation.d.ts +34 -0
  166. package/dist/core/validation.js +176 -0
  167. package/dist/documents/extraction.d.ts +121 -0
  168. package/dist/documents/extraction.js +293 -0
  169. package/dist/documents/index.d.ts +199 -0
  170. package/dist/documents/index.js +65 -0
  171. package/dist/documents/parsers/pdf.d.ts +47 -0
  172. package/dist/documents/parsers/pdf.js +508 -0
  173. package/dist/documents/parsers/text.d.ts +59 -0
  174. package/dist/documents/parsers/text.js +325 -0
  175. package/dist/documents/read-tool.d.ts +52 -0
  176. package/dist/documents/read-tool.js +109 -0
  177. package/dist/documents/render.d.ts +29 -0
  178. package/dist/documents/render.js +59 -0
  179. package/dist/documents/vision.d.ts +159 -0
  180. package/dist/documents/vision.js +214 -0
  181. package/dist/entries/adapters-bullmq.d.ts +8 -0
  182. package/dist/entries/adapters-bullmq.js +8 -0
  183. package/dist/entries/adapters-otel.d.ts +13 -0
  184. package/dist/entries/adapters-otel.js +13 -0
  185. package/dist/entries/adapters-postgres.d.ts +10 -0
  186. package/dist/entries/adapters-postgres.js +10 -0
  187. package/dist/entries/adapters-redis.d.ts +3 -0
  188. package/dist/entries/adapters-redis.js +3 -0
  189. package/dist/entries/context.d.ts +20 -0
  190. package/dist/entries/context.js +20 -0
  191. package/dist/entries/flows.d.ts +15 -0
  192. package/dist/entries/flows.js +15 -0
  193. package/dist/entries/hitl.d.ts +10 -0
  194. package/dist/entries/hitl.js +10 -0
  195. package/dist/entries/knowledge.d.ts +18 -0
  196. package/dist/entries/knowledge.js +19 -0
  197. package/dist/entries/mcp.d.ts +10 -0
  198. package/dist/entries/mcp.js +10 -0
  199. package/dist/entries/observability.d.ts +14 -0
  200. package/dist/entries/observability.js +16 -0
  201. package/dist/entries/persistence.d.ts +11 -0
  202. package/dist/entries/persistence.js +11 -0
  203. package/dist/entries/providers.d.ts +14 -0
  204. package/dist/entries/providers.js +14 -0
  205. package/dist/entries/runtime.d.ts +13 -0
  206. package/dist/entries/runtime.js +13 -0
  207. package/dist/entries/server.d.ts +24 -0
  208. package/dist/entries/server.js +24 -0
  209. package/dist/entries/tools.d.ts +21 -0
  210. package/dist/entries/tools.js +21 -0
  211. package/dist/entries/usage.d.ts +10 -0
  212. package/dist/entries/usage.js +10 -0
  213. package/dist/evaluation/gate.d.ts +168 -0
  214. package/dist/evaluation/gate.js +180 -0
  215. package/dist/evaluation/graders.d.ts +125 -0
  216. package/dist/evaluation/graders.js +203 -0
  217. package/dist/evaluation/index.d.ts +120 -0
  218. package/dist/evaluation/index.js +183 -0
  219. package/dist/evaluation/judge.d.ts +75 -0
  220. package/dist/evaluation/judge.js +111 -0
  221. package/dist/export/index.d.ts +162 -0
  222. package/dist/export/index.js +363 -0
  223. package/dist/export/markdown.d.ts +19 -0
  224. package/dist/export/markdown.js +29 -0
  225. package/dist/export/pdf.d.ts +73 -0
  226. package/dist/export/pdf.js +407 -0
  227. package/dist/files/context.d.ts +97 -0
  228. package/dist/files/context.js +185 -0
  229. package/dist/files/index.d.ts +210 -0
  230. package/dist/files/index.js +338 -0
  231. package/dist/files/read-tool.d.ts +81 -0
  232. package/dist/files/read-tool.js +163 -0
  233. package/dist/files/turn-parts.d.ts +96 -0
  234. package/dist/files/turn-parts.js +171 -0
  235. package/dist/flows/index.d.ts +270 -0
  236. package/dist/flows/index.js +62 -0
  237. package/dist/flows/interpreter.d.ts +146 -0
  238. package/dist/flows/interpreter.js +426 -0
  239. package/dist/flows/runner.d.ts +145 -0
  240. package/dist/flows/runner.js +270 -0
  241. package/dist/graphql/index.d.ts +8 -0
  242. package/dist/graphql/index.js +8 -0
  243. package/dist/graphql/resolvers.d.ts +237 -0
  244. package/dist/graphql/resolvers.js +253 -0
  245. package/dist/graphql/schema.d.ts +11 -0
  246. package/dist/graphql/schema.js +258 -0
  247. package/dist/graphql/sse.d.ts +77 -0
  248. package/dist/graphql/sse.js +100 -0
  249. package/dist/hitl/approved-execution.d.ts +127 -0
  250. package/dist/hitl/approved-execution.js +177 -0
  251. package/dist/hitl/index.d.ts +79 -0
  252. package/dist/hitl/index.js +12 -0
  253. package/dist/hitl/service.d.ts +221 -0
  254. package/dist/hitl/service.js +268 -0
  255. package/dist/idempotency/index.d.ts +70 -0
  256. package/dist/idempotency/index.js +59 -0
  257. package/dist/index.d.ts +103 -0
  258. package/dist/index.js +60 -0
  259. package/dist/knowledge/chunking.d.ts +57 -0
  260. package/dist/knowledge/chunking.js +158 -0
  261. package/dist/knowledge/index.d.ts +119 -0
  262. package/dist/knowledge/index.js +166 -0
  263. package/dist/knowledge/retrieval.d.ts +146 -0
  264. package/dist/knowledge/retrieval.js +170 -0
  265. package/dist/loadtest/harness.d.ts +168 -0
  266. package/dist/loadtest/harness.js +507 -0
  267. package/dist/loadtest/index.d.ts +13 -0
  268. package/dist/loadtest/index.js +13 -0
  269. package/dist/loadtest/injection.d.ts +89 -0
  270. package/dist/loadtest/injection.js +147 -0
  271. package/dist/loadtest/metrics.d.ts +197 -0
  272. package/dist/loadtest/metrics.js +160 -0
  273. package/dist/loadtest/runbooks.d.ts +28 -0
  274. package/dist/loadtest/runbooks.js +159 -0
  275. package/dist/loadtest/scenario.d.ts +104 -0
  276. package/dist/loadtest/scenario.js +208 -0
  277. package/dist/mcp/egress.d.ts +53 -0
  278. package/dist/mcp/egress.js +115 -0
  279. package/dist/mcp/index.d.ts +93 -0
  280. package/dist/mcp/index.js +33 -0
  281. package/dist/mcp/provider.d.ts +62 -0
  282. package/dist/mcp/provider.js +0 -0
  283. package/dist/models/index.d.ts +98 -0
  284. package/dist/models/index.js +74 -0
  285. package/dist/models/pricing.d.ts +24 -0
  286. package/dist/models/pricing.js +37 -0
  287. package/dist/models/provider-factory.d.ts +31 -0
  288. package/dist/models/provider-factory.js +67 -0
  289. package/dist/models/streaming.d.ts +145 -0
  290. package/dist/models/streaming.js +272 -0
  291. package/dist/models/vision.d.ts +38 -0
  292. package/dist/models/vision.js +62 -0
  293. package/dist/persistence/index.d.ts +1654 -0
  294. package/dist/persistence/index.js +226 -0
  295. package/dist/principal-memory/index.d.ts +106 -0
  296. package/dist/principal-memory/index.js +89 -0
  297. package/dist/retention/index.d.ts +89 -0
  298. package/dist/retention/index.js +70 -0
  299. package/dist/runtime/checkpoint.d.ts +37 -0
  300. package/dist/runtime/checkpoint.js +22 -0
  301. package/dist/runtime/index.d.ts +118 -0
  302. package/dist/runtime/index.js +69 -0
  303. package/dist/runtime/retry.d.ts +95 -0
  304. package/dist/runtime/retry.js +126 -0
  305. package/dist/runtime/serialization.d.ts +85 -0
  306. package/dist/runtime/serialization.js +95 -0
  307. package/dist/runtime/streaming.d.ts +54 -0
  308. package/dist/runtime/streaming.js +115 -0
  309. package/dist/runtime/worker.d.ts +130 -0
  310. package/dist/runtime/worker.js +405 -0
  311. package/dist/security/checklist.d.ts +53 -0
  312. package/dist/security/checklist.js +204 -0
  313. package/dist/security/findings.d.ts +56 -0
  314. package/dist/security/findings.js +168 -0
  315. package/dist/security/index.d.ts +14 -0
  316. package/dist/security/index.js +14 -0
  317. package/dist/security/prompt-safety.d.ts +100 -0
  318. package/dist/security/prompt-safety.js +133 -0
  319. package/dist/server/boot.d.ts +32 -0
  320. package/dist/server/boot.js +36 -0
  321. package/dist/server/cli-worker.d.ts +37 -0
  322. package/dist/server/cli-worker.js +151 -0
  323. package/dist/server/cli.d.ts +27 -0
  324. package/dist/server/cli.js +74 -0
  325. package/dist/server/config.d.ts +42 -0
  326. package/dist/server/config.js +127 -0
  327. package/dist/server/health.d.ts +59 -0
  328. package/dist/server/health.js +90 -0
  329. package/dist/server/host.d.ts +39 -0
  330. package/dist/server/host.js +124 -0
  331. package/dist/server/index.d.ts +15 -0
  332. package/dist/server/index.js +15 -0
  333. package/dist/server/main.d.ts +16 -0
  334. package/dist/server/main.js +31 -0
  335. package/dist/server/sse-route.d.ts +21 -0
  336. package/dist/server/sse-route.js +282 -0
  337. package/dist/skills/index.d.ts +67 -0
  338. package/dist/skills/index.js +31 -0
  339. package/dist/skills/resolver.d.ts +54 -0
  340. package/dist/skills/resolver.js +121 -0
  341. package/dist/teams/index.d.ts +93 -0
  342. package/dist/teams/index.js +207 -0
  343. package/dist/telemetry/index.d.ts +157 -0
  344. package/dist/telemetry/index.js +71 -0
  345. package/dist/telemetry/instrument.d.ts +108 -0
  346. package/dist/telemetry/instrument.js +232 -0
  347. package/dist/telemetry/log-events.d.ts +17 -0
  348. package/dist/telemetry/log-events.js +58 -0
  349. package/dist/telemetry/metrics.d.ts +123 -0
  350. package/dist/telemetry/metrics.js +135 -0
  351. package/dist/telemetry/noop.d.ts +39 -0
  352. package/dist/telemetry/noop.js +143 -0
  353. package/dist/telemetry/redaction.d.ts +64 -0
  354. package/dist/telemetry/redaction.js +153 -0
  355. package/dist/telemetry/spans.d.ts +56 -0
  356. package/dist/telemetry/spans.js +78 -0
  357. package/dist/telemetry/trace-context.d.ts +55 -0
  358. package/dist/telemetry/trace-context.js +60 -0
  359. package/dist/toolkit/compute.d.ts +53 -0
  360. package/dist/toolkit/compute.js +152 -0
  361. package/dist/toolkit/data.d.ts +98 -0
  362. package/dist/toolkit/data.js +235 -0
  363. package/dist/toolkit/http.d.ts +113 -0
  364. package/dist/toolkit/http.js +205 -0
  365. package/dist/toolkit/index.d.ts +21 -0
  366. package/dist/toolkit/index.js +17 -0
  367. package/dist/toolkit/web.d.ts +107 -0
  368. package/dist/toolkit/web.js +147 -0
  369. package/dist/tools/define.d.ts +25 -0
  370. package/dist/tools/define.js +45 -0
  371. package/dist/tools/delegating.d.ts +132 -0
  372. package/dist/tools/delegating.js +211 -0
  373. package/dist/tools/index.d.ts +129 -0
  374. package/dist/tools/index.js +33 -0
  375. package/dist/tools/library/compute.d.ts +11 -0
  376. package/dist/tools/library/compute.js +46 -0
  377. package/dist/tools/library/data.d.ts +16 -0
  378. package/dist/tools/library/data.js +92 -0
  379. package/dist/tools/library/http.d.ts +28 -0
  380. package/dist/tools/library/http.js +71 -0
  381. package/dist/tools/library/index.d.ts +97 -0
  382. package/dist/tools/library/index.js +134 -0
  383. package/dist/tools/library/knowledge.d.ts +39 -0
  384. package/dist/tools/library/knowledge.js +58 -0
  385. package/dist/tools/library/web.d.ts +19 -0
  386. package/dist/tools/library/web.js +65 -0
  387. package/dist/tools/meta-tools.d.ts +19 -0
  388. package/dist/tools/meta-tools.js +36 -0
  389. package/dist/tools/registry.d.ts +146 -0
  390. package/dist/tools/registry.js +291 -0
  391. package/dist/usage/index.d.ts +105 -0
  392. package/dist/usage/index.js +20 -0
  393. package/dist/usage/quota.d.ts +258 -0
  394. package/dist/usage/quota.js +510 -0
  395. package/dist/usage/recorder.d.ts +29 -0
  396. package/dist/usage/recorder.js +96 -0
  397. package/dist/usage/rollups.d.ts +121 -0
  398. package/dist/usage/rollups.js +157 -0
  399. package/dist/worker/export.d.ts +57 -0
  400. package/dist/worker/export.js +81 -0
  401. package/dist/worker/extraction.d.ts +57 -0
  402. package/dist/worker/extraction.js +84 -0
  403. package/dist/worker/main.d.ts +103 -0
  404. package/dist/worker/main.js +159 -0
  405. package/package.json +187 -0
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Typed message parts — `docs/02-core-and-persistence.md`.
3
+ *
4
+ * Every part carries a schema version and is JSON-runtime validated. Provider-specific
5
+ * metadata may be retained in the namespaced `providerMetadata` field but cannot define
6
+ * application behaviour.
7
+ */
8
+ import type { ArtifactId, ArtifactVersionId, BlobRef, ConversationId, FileId, InteractionId, MessageId, MessagePartId, RunId, ToolCallId } from "./ids.js";
9
+ import type { PlatformError } from "./errors.js";
10
+ export declare const MESSAGE_PART_TYPES: readonly ["text", "reasoning", "tool-call", "tool-result", "question", "approval", "file", "image", "citation", "source", "artifact", "status", "error"];
11
+ export type MessagePartType = (typeof MESSAGE_PART_TYPES)[number];
12
+ type PartBase<T extends MessagePartType> = {
13
+ readonly id: MessagePartId;
14
+ readonly type: T;
15
+ /** Schema version of this part's payload. Bumped on any breaking payload change. */
16
+ readonly schemaVersion: number;
17
+ readonly createdAt: string;
18
+ /** Namespaced, non-authoritative provider detail. Never drives application behaviour. */
19
+ readonly providerMetadata?: Readonly<Record<string, unknown>>;
20
+ };
21
+ export type TextPart = PartBase<"text"> & {
22
+ readonly text: string;
23
+ };
24
+ export type ReasoningPart = PartBase<"reasoning"> & {
25
+ readonly text: string;
26
+ /** Reasoning is pruned before recent semantic turns when the budget is tight. */
27
+ readonly redacted?: boolean;
28
+ };
29
+ export type ToolCallPart = PartBase<"tool-call"> & {
30
+ readonly toolCallId: ToolCallId;
31
+ readonly toolName: string;
32
+ readonly input: unknown;
33
+ };
34
+ export type ToolResultPart = PartBase<"tool-result"> & {
35
+ readonly toolCallId: ToolCallId;
36
+ readonly toolName: string;
37
+ /** Populated for inline results. Large results are spilled and referenced instead. */
38
+ readonly output?: unknown;
39
+ /** Authorized reference to an offloaded result, read back via `read_tool_output`. */
40
+ readonly spilledOutputRef?: BlobRef;
41
+ readonly truncated: boolean;
42
+ };
43
+ /**
44
+ * An answer to one question: a single value, several, or free text.
45
+ *
46
+ * Defined in `core` because both the persistence port and the HITL service need it, and either importing the
47
+ * other would be circular — `hitl` already imports `persistence`. `core` is self-contained by rule (R6), which
48
+ * makes it the only place a shared type like this can live.
49
+ *
50
+ * `string | string[]` rather than always an array: a single-select answer being `["a"]` forces every reader to
51
+ * unwrap it, and one of them will forget.
52
+ */
53
+ export type QuestionAnswer = string | readonly string[];
54
+ export type QuestionPart = PartBase<"question"> & {
55
+ readonly interactionId: InteractionId;
56
+ readonly questions: readonly {
57
+ readonly key: string;
58
+ readonly prompt: string;
59
+ /**
60
+ * Suggested answers. Absent means free text only.
61
+ *
62
+ * `options` alone has always been here, but a client had no way to know whether it was being offered a
63
+ * *choice* or a *hint* — so it had to guess, and two clients guessed differently. The two flags below make
64
+ * that explicit.
65
+ */
66
+ readonly options?: readonly string[];
67
+ /**
68
+ * Whether more than one option may be chosen.
69
+ *
70
+ * Explicit rather than inferred, because "pick a model" and "pick the features you want" are the same shape
71
+ * on the wire and completely different in a UI. A client that guessed from the prompt text would guess wrong
72
+ * on the first ambiguous one.
73
+ */
74
+ readonly multiple?: boolean;
75
+ /**
76
+ * Whether the person may answer with something not on the list.
77
+ *
78
+ * Defaults to allowed **when there are no options**, and to *not* allowed when there are — a closed list is
79
+ * usually closed on purpose. A caller wanting "one of these, or describe your own" says so.
80
+ */
81
+ readonly allowOther?: boolean;
82
+ }[];
83
+ readonly answeredAt?: string;
84
+ };
85
+ export type ApprovalPart = PartBase<"approval"> & {
86
+ readonly interactionId: InteractionId;
87
+ readonly toolName: string;
88
+ readonly summary: string;
89
+ readonly riskCategory: string;
90
+ readonly decidedAt?: string;
91
+ };
92
+ export type FilePart = PartBase<"file"> & {
93
+ readonly fileId: FileId;
94
+ readonly filename: string;
95
+ readonly mediaType: string;
96
+ readonly byteSize: number;
97
+ };
98
+ export type ImagePart = PartBase<"image"> & {
99
+ readonly fileId: FileId;
100
+ readonly mediaType: string;
101
+ readonly width?: number;
102
+ readonly height?: number;
103
+ readonly altText?: string;
104
+ };
105
+ /**
106
+ * Where a cited passage came from (#137).
107
+ *
108
+ * A closed union with exactly two arms, and one shape for both is AC-6: the frontend renders one thing whether
109
+ * a claim came from an indexed document or from the web. Two part types would mean two renderers, two schemas,
110
+ * and eventually two behaviours for "click the citation".
111
+ *
112
+ * The arms differ in what *resolving* means — a chunk id resolves inside this platform, a URL resolves outside
113
+ * it — and that difference is real, so it is a discriminant rather than a pile of optional fields.
114
+ */
115
+ export type CitationOrigin = {
116
+ readonly kind: "retrieval";
117
+ readonly sourceType: "file" | "artifact" | "message" | "external";
118
+ readonly sourceId: string;
119
+ /** The chunk, which is what makes AC-2's "specific passage" resolvable rather than aspirational. */
120
+ readonly chunkId: string;
121
+ readonly chunkIndex: number;
122
+ /** The heading path the chunker found, when there was one. */
123
+ readonly locator?: string;
124
+ } | {
125
+ readonly kind: "web";
126
+ /**
127
+ * The URL that was **actually read**, after redirects — not the one requested.
128
+ *
129
+ * A citation must open what was read. ShareFlow's `safefetch` exists because the two differ: a public URL
130
+ * can redirect somewhere else entirely, and citing the request would cite a page nobody looked at.
131
+ */
132
+ readonly url: string;
133
+ readonly title?: string;
134
+ };
135
+ /**
136
+ * A cited passage — REQ-030, #137.
137
+ *
138
+ * **Self-contained on purpose.** `excerpt`, `title` and `retrievedAt` are stored on the part rather than
139
+ * looked up from the source, because AC-4 requires an answer given months ago to remain auditable *after the
140
+ * source is gone*: a document deleted, a URL dead, a chunk re-indexed under a different id. A citation that
141
+ * resolved by fetching would be a citation that stops being evidence the moment anything changes — which is
142
+ * exactly when someone needs it.
143
+ *
144
+ * The duplication is the feature. This is a snapshot of what was read, not a pointer to what is there now.
145
+ */
146
+ export type CitationPart = PartBase<"citation"> & {
147
+ readonly origin: CitationOrigin;
148
+ /** The exact text used. Bounded — a citation is evidence for a claim, not a copy of the source. */
149
+ readonly excerpt: string;
150
+ /** When the passage was read. A fact from last year and a fact from this morning are different claims. */
151
+ readonly retrievedAt: string;
152
+ /**
153
+ * The parts this citation grounds — AC-3.
154
+ *
155
+ * Groundedness is derived from *this graph* rather than flagged on the text, so it cannot disagree with
156
+ * itself: a text part is grounded exactly when some citation names it. A boolean on the text part would be a
157
+ * second place for the same fact, and the two would drift the first time a citation was withheld.
158
+ */
159
+ readonly supports: readonly MessagePartId[];
160
+ /** Character range within the source passage, when the producer knows it. Narrows AC-2 further. */
161
+ readonly charRange?: {
162
+ readonly start: number;
163
+ readonly end: number;
164
+ };
165
+ };
166
+ export type SourcePart = PartBase<"source"> & {
167
+ readonly sourceId: string;
168
+ readonly title: string;
169
+ readonly url?: string;
170
+ };
171
+ export type ArtifactPart = PartBase<"artifact"> & {
172
+ readonly artifactId: ArtifactId;
173
+ readonly versionId: ArtifactVersionId;
174
+ readonly title: string;
175
+ };
176
+ export type StatusPart = PartBase<"status"> & {
177
+ readonly status: string;
178
+ readonly detail?: string;
179
+ };
180
+ export type ErrorPart = PartBase<"error"> & {
181
+ readonly error: PlatformError;
182
+ };
183
+ export type MessagePart = TextPart | ReasoningPart | ToolCallPart | ToolResultPart | QuestionPart | ApprovalPart | FilePart | ImagePart | CitationPart | SourcePart | ArtifactPart | StatusPart | ErrorPart;
184
+ export type MessageRole = "system" | "user" | "assistant" | "tool";
185
+ export type Message = {
186
+ readonly id: MessageId;
187
+ readonly conversationId: ConversationId;
188
+ readonly runId?: RunId;
189
+ readonly role: MessageRole;
190
+ readonly parts: readonly MessagePart[];
191
+ readonly createdAt: string;
192
+ };
193
+ export {};
194
+ //# sourceMappingURL=content-parts.d.ts.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Typed message parts — `docs/02-core-and-persistence.md`.
3
+ *
4
+ * Every part carries a schema version and is JSON-runtime validated. Provider-specific
5
+ * metadata may be retained in the namespaced `providerMetadata` field but cannot define
6
+ * application behaviour.
7
+ */
8
+ export const MESSAGE_PART_TYPES = [
9
+ "text",
10
+ "reasoning",
11
+ "tool-call",
12
+ "tool-result",
13
+ "question",
14
+ "approval",
15
+ "file",
16
+ "image",
17
+ "citation",
18
+ "source",
19
+ "artifact",
20
+ "status",
21
+ "error",
22
+ ];
23
+ //# sourceMappingURL=content-parts.js.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Execution context — `docs/02-core-and-persistence.md`.
3
+ *
4
+ * Context identity is constructed by the host application. Model-generated input can
5
+ * never override it: nothing that originates in a tool argument, a skill body or an
6
+ * MCP tool description may reach these fields.
7
+ */
8
+ import type { ConversationId, MembershipId, PrincipalId, RequestId, RoleId, RunId, TenantId } from "./ids.js";
9
+ export type ExecutionContext = {
10
+ readonly tenantId: TenantId;
11
+ readonly principalId: PrincipalId;
12
+ readonly membershipId?: MembershipId;
13
+ readonly roleIds: readonly RoleId[];
14
+ readonly locale: string;
15
+ readonly timezone: string;
16
+ readonly conversationId?: ConversationId;
17
+ readonly runId?: RunId;
18
+ readonly requestId: RequestId;
19
+ /**
20
+ * True when this run must perform **no external write** — docs/07 and docs/08's shadow mode: *"old and
21
+ * new systems may run in shadow mode, but shadow execution performs no external writes."*
22
+ *
23
+ * On the context deliberately, and the paragraph above is the reason it is safe: shadow-ness is
24
+ * constructed by the host, exactly like `tenantId`, and **a model must never be able to clear it** —
25
+ * clearing it would turn a shadow run into a real one. A hint a model could set would not belong here;
26
+ * this is the opposite kind of field.
27
+ *
28
+ * Absent means a real run. That is the uncomfortable direction — a forgotten flag publishes rather than
29
+ * suppresses — and it is unavoidable, because defaulting to shadow would make every existing context a
30
+ * shadow context. The dangerous direction is closed in `defineDelegatingTool` instead: a run that *says*
31
+ * it is shadow and has nowhere to record the suppression is refused, not performed.
32
+ */
33
+ readonly shadow?: boolean;
34
+ };
35
+ /**
36
+ * The tenant scope every store method receives explicitly. Governing principle 1:
37
+ * unsafe APIs such as `findById(id)` are forbidden.
38
+ */
39
+ export type TenantScope = {
40
+ readonly tenantId: TenantId;
41
+ };
42
+ /** Stable cursor pagination, required of every list method. */
43
+ export type Page<T> = {
44
+ readonly items: readonly T[];
45
+ readonly nextCursor?: string;
46
+ };
47
+ export type PageRequest = {
48
+ readonly limit: number;
49
+ readonly cursor?: string;
50
+ };
51
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Execution context — `docs/02-core-and-persistence.md`.
3
+ *
4
+ * Context identity is constructed by the host application. Model-generated input can
5
+ * never override it: nothing that originates in a tool argument, a skill body or an
6
+ * MCP tool description may reach these fields.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Reading an environment variable through the rename — #192.
3
+ *
4
+ * Every variable this platform reads was `AGENTKIT_*` and is now `RETINUE_*`. A straight rename breaks every
5
+ * existing deployment and every developer's `.env` at the moment they pull, with an error that says nothing about
6
+ * why — a missing database URL looks like a missing database URL, not like a rename.
7
+ *
8
+ * So both are read, new name first, and the old one **warns**. That gives one release where a deployment keeps
9
+ * working while it is corrected, and the warning is what makes the deprecation finite rather than permanent:
10
+ * silence would mean the fallback is still load-bearing in a year and nobody knows.
11
+ *
12
+ * The library itself reads no environment — `deployment.test.ts` enforces that. This is used by the host and the
13
+ * scripts, which are entry points, and reading configuration is what an entry point is for.
14
+ */
15
+ export type EnvReader = (name: string) => string | undefined;
16
+ /**
17
+ * `RETINUE_X`, falling back to `AGENTKIT_X`.
18
+ *
19
+ * `name` is given **without** the prefix — `read(env, "DATABASE_URL")` — so a caller cannot accidentally ask for
20
+ * the legacy name directly and skip the warning.
21
+ */
22
+ export declare const readEnv: (env: Readonly<Record<string, string | undefined>>, name: string, warn?: (message: string) => void) => string | undefined;
23
+ /** For tests, which need each case to see a fresh warning rather than one suppressed by an earlier case. */
24
+ export declare const resetEnvWarnings: () => void;
25
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Reading an environment variable through the rename — #192.
3
+ *
4
+ * Every variable this platform reads was `AGENTKIT_*` and is now `RETINUE_*`. A straight rename breaks every
5
+ * existing deployment and every developer's `.env` at the moment they pull, with an error that says nothing about
6
+ * why — a missing database URL looks like a missing database URL, not like a rename.
7
+ *
8
+ * So both are read, new name first, and the old one **warns**. That gives one release where a deployment keeps
9
+ * working while it is corrected, and the warning is what makes the deprecation finite rather than permanent:
10
+ * silence would mean the fallback is still load-bearing in a year and nobody knows.
11
+ *
12
+ * The library itself reads no environment — `deployment.test.ts` enforces that. This is used by the host and the
13
+ * scripts, which are entry points, and reading configuration is what an entry point is for.
14
+ */
15
+ const LEGACY_PREFIX = "AGENTKIT_";
16
+ const PREFIX = "RETINUE_";
17
+ /** Reported once per variable, so a busy worker does not print the same line on every request. */
18
+ const warned = new Set();
19
+ /**
20
+ * `RETINUE_X`, falling back to `AGENTKIT_X`.
21
+ *
22
+ * `name` is given **without** the prefix — `read(env, "DATABASE_URL")` — so a caller cannot accidentally ask for
23
+ * the legacy name directly and skip the warning.
24
+ */
25
+ export const readEnv = (env, name, warn = (m) => console.warn(m)) => {
26
+ const current = env[`${PREFIX}${name}`];
27
+ if (current !== undefined && current !== "")
28
+ return current;
29
+ const legacy = env[`${LEGACY_PREFIX}${name}`];
30
+ if (legacy === undefined || legacy === "")
31
+ return undefined;
32
+ if (!warned.has(name)) {
33
+ warned.add(name);
34
+ warn(`${LEGACY_PREFIX}${name} is deprecated and will stop being read in the next minor release. ` +
35
+ `Rename it to ${PREFIX}${name}.`);
36
+ }
37
+ return legacy;
38
+ };
39
+ /** For tests, which need each case to see a fresh warning rather than one suppressed by an earlier case. */
40
+ export const resetEnvWarnings = () => warned.clear();
41
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Error contract — `docs/03-intelligence-runtime.md`.
3
+ *
4
+ * Errors carry a stable code, retryability and safe details. "Safe" means the payload
5
+ * is shown to a model and a user: no credentials, no connection strings, no internal
6
+ * hostnames, no raw provider stack traces.
7
+ */
8
+ export declare const ERROR_CODES: readonly ["unauthorized", "forbidden", "not_found", "invalid_input", "conflict", "rate_limited", "provider_unavailable", "provider_error", "timeout", "cancelled", "budget_exceeded", "context_overflow", "approval_required", "approval_denied", "approval_expired", "question_pending", "idempotency_conflict", "capability_unavailable", "internal"];
9
+ export type ErrorCode = (typeof ERROR_CODES)[number];
10
+ export type PlatformError = {
11
+ readonly code: ErrorCode;
12
+ readonly message: string;
13
+ readonly retryable: boolean;
14
+ /** Redacted, model- and user-safe context. */
15
+ readonly details?: Readonly<Record<string, unknown>>;
16
+ readonly retryAfterMs?: number;
17
+ };
18
+ export declare class AgentPlatformError extends Error {
19
+ readonly code: ErrorCode;
20
+ readonly retryable: boolean;
21
+ readonly details: Readonly<Record<string, unknown>> | undefined;
22
+ readonly retryAfterMs: number | undefined;
23
+ constructor(error: PlatformError, options?: {
24
+ cause?: unknown;
25
+ });
26
+ /** The wire form. Deliberately drops `cause` and the stack. */
27
+ toPlatformError(): PlatformError;
28
+ }
29
+ export declare const isAgentPlatformError: (value: unknown) => value is AgentPlatformError;
30
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Error contract — `docs/03-intelligence-runtime.md`.
3
+ *
4
+ * Errors carry a stable code, retryability and safe details. "Safe" means the payload
5
+ * is shown to a model and a user: no credentials, no connection strings, no internal
6
+ * hostnames, no raw provider stack traces.
7
+ */
8
+ export const ERROR_CODES = [
9
+ "unauthorized",
10
+ "forbidden",
11
+ "not_found",
12
+ "invalid_input",
13
+ "conflict",
14
+ "rate_limited",
15
+ "provider_unavailable",
16
+ "provider_error",
17
+ "timeout",
18
+ "cancelled",
19
+ "budget_exceeded",
20
+ "context_overflow",
21
+ "approval_required",
22
+ "approval_denied",
23
+ "approval_expired",
24
+ /**
25
+ * A tool put a question to a person and the run must park until they answer — #163.
26
+ *
27
+ * Not an error the model should work around, and deliberately not `approval_required`: an approval asks *may
28
+ * I do this* about a call the platform already holds, and this asks *which of these* about a call that has
29
+ * not been decided yet. The engine reads this code to emit `question.requested`, which is what suspends the
30
+ * run — before this, `question.requested` was in the event union and handled by the worker, and nothing in
31
+ * the platform could produce it.
32
+ *
33
+ * Carries `details.interactionId`.
34
+ */
35
+ "question_pending",
36
+ "idempotency_conflict",
37
+ "capability_unavailable",
38
+ "internal",
39
+ ];
40
+ export class AgentPlatformError extends Error {
41
+ code;
42
+ retryable;
43
+ details;
44
+ retryAfterMs;
45
+ constructor(error, options) {
46
+ super(error.message, options);
47
+ this.name = "AgentPlatformError";
48
+ this.code = error.code;
49
+ this.retryable = error.retryable;
50
+ this.details = error.details;
51
+ this.retryAfterMs = error.retryAfterMs;
52
+ }
53
+ /** The wire form. Deliberately drops `cause` and the stack. */
54
+ toPlatformError() {
55
+ return {
56
+ code: this.code,
57
+ message: this.message,
58
+ retryable: this.retryable,
59
+ ...(this.details === undefined ? {} : { details: this.details }),
60
+ ...(this.retryAfterMs === undefined ? {} : { retryAfterMs: this.retryAfterMs }),
61
+ };
62
+ }
63
+ }
64
+ export const isAgentPlatformError = (value) => value instanceof AgentPlatformError;
65
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Transport events — `docs/04-durable-runtime-and-hitl.md`.
3
+ *
4
+ * Transports map these to GraphQL subscriptions, SSE or another channel without
5
+ * changing runtime semantics. Events carry a monotonic sequence per run so a client
6
+ * can resume from a cursor after reconnecting.
7
+ */
8
+ import type { MessagePart } from "./content-parts.js";
9
+ import type { PlatformError } from "./errors.js";
10
+ import type { InteractionId, MessageId, RunId, TenantId, ToolCallId } from "./ids.js";
11
+ export declare const RUN_EVENT_TYPES: readonly ["run.queued", "run.started", "run.checkpointed", "run.completed", "run.failed", "run.cancelled", "run.retry-pending", "part.added", "part.updated", "tool.started", "tool.completed", "tool.failed", "question.requested", "question.answered", "approval.requested", "approval.decided", "usage.updated", "context.compacted"];
12
+ export type RunEventType = (typeof RUN_EVENT_TYPES)[number];
13
+ type EventBase<T extends RunEventType> = {
14
+ readonly type: T;
15
+ readonly runId: RunId;
16
+ /** Monotonic per run. Clients resume with `after: sequence`. */
17
+ readonly sequence: number;
18
+ readonly occurredAt: string;
19
+ };
20
+ export type RunLifecycleEvent = EventBase<"run.queued" | "run.started" | "run.checkpointed" | "run.completed" | "run.cancelled">;
21
+ export type RunFailedEvent = EventBase<"run.failed"> & {
22
+ readonly error: PlatformError;
23
+ };
24
+ /**
25
+ * Emitted when a transient failure triggers a retry (see docs/04 → Retry policy).
26
+ * Carries enough for a client to render "attempt 2 of 5, retrying in ~3s (rate limited)"
27
+ * rather than only showing the `retry-pending` status.
28
+ */
29
+ export type RunRetryPendingEvent = EventBase<"run.retry-pending"> & {
30
+ readonly attempt: number;
31
+ readonly maxAttempts: number;
32
+ /** When the next attempt is scheduled, honoring any `retry-after` the provider returned. */
33
+ readonly nextAttemptAt: string;
34
+ /** The transient error that triggered the retry. */
35
+ readonly error: PlatformError;
36
+ };
37
+ export type PartEvent = EventBase<"part.added" | "part.updated"> & {
38
+ readonly messageId: MessageId;
39
+ readonly part: MessagePart;
40
+ };
41
+ export type ToolEvent = EventBase<"tool.started" | "tool.completed" | "tool.failed"> & {
42
+ readonly toolCallId: ToolCallId;
43
+ readonly toolName: string;
44
+ };
45
+ export type InteractionEvent = EventBase<"question.requested" | "question.answered" | "approval.requested" | "approval.decided"> & {
46
+ readonly interactionId: InteractionId;
47
+ };
48
+ export type UsageUpdatedEvent = EventBase<"usage.updated"> & {
49
+ readonly inputTokens: number;
50
+ readonly outputTokens: number;
51
+ readonly costMinorUnits?: number;
52
+ /** When present, the worker records a durable `UsageEvent` for this realized step. */
53
+ readonly modelId?: string;
54
+ readonly cachedInputTokens?: number;
55
+ readonly reasoningTokens?: number;
56
+ /**
57
+ * Non-text input this step carried — #185 AC-4.
58
+ *
59
+ * On the event, not only in the cost, so the ledger can say *why* a step cost what it did. A multimodal turn
60
+ * and a text turn that happened to price the same are otherwise indistinguishable after the fact, which makes
61
+ * a pricing mistake invisible.
62
+ */
63
+ readonly imageCount?: number;
64
+ readonly audioSeconds?: number;
65
+ readonly currency?: string;
66
+ /** Stable per-step id so recording is idempotent across a recovery. */
67
+ readonly stepId?: string;
68
+ };
69
+ export type ContextCompactedEvent = EventBase<"context.compacted"> & {
70
+ readonly droppedParts: number;
71
+ readonly tokensReclaimed: number;
72
+ };
73
+ export type RunEvent = RunLifecycleEvent | RunFailedEvent | RunRetryPendingEvent | PartEvent | ToolEvent | InteractionEvent | UsageUpdatedEvent | ContextCompactedEvent;
74
+ /** Fan-out port. Adapters: Supabase Realtime, Redis pub/sub, in-memory for tests. */
75
+ export interface RealtimePublisher {
76
+ publish(channel: string, event: RunEvent): Promise<void>;
77
+ }
78
+ /**
79
+ * Durable, append-only per-run event log — the catch-up half of reconnect. Every event the worker
80
+ * publishes is also appended here; a reconnecting client reads everything after its cursor. Ordering
81
+ * is by the monotonic `sequence`, so replay is deterministic and gap-free. Adapters: Postgres,
82
+ * Redis list (Twenty's pattern), in-memory for tests.
83
+ */
84
+ export interface RunEventLog {
85
+ append(input: {
86
+ readonly tenantId: TenantId;
87
+ readonly event: RunEvent;
88
+ }): Promise<void>;
89
+ /** Events with `sequence > after`, ascending. `after: 0` returns the whole run. */
90
+ listAfter(input: {
91
+ readonly tenantId: TenantId;
92
+ readonly runId: RunId;
93
+ readonly after: number;
94
+ readonly limit?: number;
95
+ }): Promise<readonly RunEvent[]>;
96
+ latestSequence(input: {
97
+ readonly tenantId: TenantId;
98
+ readonly runId: RunId;
99
+ }): Promise<number>;
100
+ }
101
+ /** A tool call started but not yet resolved, tracked while projecting a run's event stream. */
102
+ export type StreamPendingToolCall = {
103
+ readonly toolCallId: ToolCallId;
104
+ readonly toolName: string;
105
+ readonly startedAt: string;
106
+ };
107
+ /**
108
+ * The deterministic projection of a run's event stream: the assistant message parts plus the
109
+ * accounting/interaction state a client needs to render. It is a pure fold over `RunEvent`s, so the
110
+ * server (worker checkpoint) and any client rebuild identical state from the same events — the
111
+ * single source of truth that makes reconnect produce no missing or duplicated parts.
112
+ */
113
+ export type RunStreamState = {
114
+ readonly parts: readonly MessagePart[];
115
+ readonly pendingToolCalls: readonly StreamPendingToolCall[];
116
+ readonly usage: {
117
+ readonly inputTokens: number;
118
+ readonly outputTokens: number;
119
+ readonly costMinorUnits: number;
120
+ };
121
+ /** Highest sequence folded in. Use as the reconnect cursor. */
122
+ readonly sequence: number;
123
+ readonly lastEventType?: RunEventType;
124
+ /** Present between retry attempts, cleared as soon as the run makes progress again. */
125
+ readonly retry?: {
126
+ readonly attempt: number;
127
+ readonly maxAttempts: number;
128
+ readonly nextAttemptAt: string;
129
+ };
130
+ readonly error?: PlatformError;
131
+ readonly terminal: boolean;
132
+ };
133
+ export declare const EMPTY_RUN_STREAM_STATE: RunStreamState;
134
+ /** Fold one event into the projection. Pure; ignores events with a sequence already folded. */
135
+ export declare const reduceRunEvent: (state: RunStreamState, event: RunEvent) => RunStreamState;
136
+ /** Project a full (or partial) event sequence into `RunStreamState`. */
137
+ export declare const reduceRunEvents: (events: Iterable<RunEvent>, initial?: RunStreamState) => RunStreamState;
138
+ export {};
139
+ //# sourceMappingURL=events.d.ts.map