botmancers 0.4.2 → 0.6.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 (1045) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +26 -17
  3. package/app/.next/BUILD_ID +1 -1
  4. package/app/.next/app-path-routes-manifest.json +16 -0
  5. package/app/.next/build-manifest.json +3 -3
  6. package/app/.next/node_modules/@slack/socket-mode-77e8cba3b9ba4738/index.js +1 -0
  7. package/app/.next/node_modules/@slack/socket-mode-77e8cba3b9ba4738/package.json +1 -0
  8. package/app/.next/node_modules/@slack/web-api-d6dbe405b6902642/index.js +1 -0
  9. package/app/.next/node_modules/@slack/web-api-d6dbe405b6902642/package.json +1 -0
  10. package/app/.next/prerender-manifest.json +5 -5
  11. package/app/.next/required-server-files.json +8 -3
  12. package/app/.next/routes-manifest.json +122 -0
  13. package/app/.next/server/app/_global-error/page.js +1 -1
  14. package/app/.next/server/app/_global-error/page.js.nft.json +1 -1
  15. package/app/.next/server/app/_global-error.html +1 -1
  16. package/app/.next/server/app/_global-error.rsc +1 -1
  17. package/app/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  18. package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  19. package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  20. package/app/.next/server/app/_not-found/page.js +1 -1
  21. package/app/.next/server/app/_not-found/page.js.nft.json +1 -1
  22. package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  23. package/app/.next/server/app/_not-found.html +1 -1
  24. package/app/.next/server/app/_not-found.rsc +2 -2
  25. package/app/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  26. package/app/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
  27. package/app/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  28. package/app/.next/server/app/api/agent-deck/decks/route.js +3 -3
  29. package/app/.next/server/app/api/agent-deck/decks/route.js.nft.json +1 -1
  30. package/app/.next/server/app/api/agent-deck/settings/route.js +3 -3
  31. package/app/.next/server/app/api/agent-deck/settings/route.js.nft.json +1 -1
  32. package/app/.next/server/app/api/bots/[id]/config/route.js +3 -3
  33. package/app/.next/server/app/api/bots/[id]/config/route.js.nft.json +1 -1
  34. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/pins/route/app-paths-manifest.json +3 -0
  35. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/pins/route/build-manifest.json +12 -0
  36. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/pins/route/server-reference-manifest.json +4 -0
  37. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/pins/route.js +11 -0
  38. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/pins/route.js.nft.json +1 -0
  39. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/pins/route_client-reference-manifest.js +3 -0
  40. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route.js +3 -3
  41. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route.js.nft.json +1 -1
  42. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/shares/route/app-paths-manifest.json +3 -0
  43. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/shares/route/build-manifest.json +12 -0
  44. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/shares/route/server-reference-manifest.json +4 -0
  45. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/shares/route.js +11 -0
  46. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/shares/route.js.nft.json +1 -0
  47. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/shares/route_client-reference-manifest.js +3 -0
  48. package/app/.next/server/app/api/bots/[id]/sessions/route.js +6 -4
  49. package/app/.next/server/app/api/bots/[id]/sessions/route.js.nft.json +1 -1
  50. package/app/.next/server/app/api/bots/[id]/share-policy/route/app-paths-manifest.json +3 -0
  51. package/app/.next/server/app/api/bots/[id]/share-policy/route/build-manifest.json +12 -0
  52. package/app/.next/server/app/api/bots/[id]/share-policy/route/server-reference-manifest.json +4 -0
  53. package/app/.next/server/app/api/bots/[id]/share-policy/route.js +11 -0
  54. package/app/.next/server/app/api/bots/[id]/share-policy/route.js.nft.json +1 -0
  55. package/app/.next/server/app/api/bots/[id]/share-policy/route_client-reference-manifest.js +3 -0
  56. package/app/.next/server/app/api/bots/[id]/skill/route.js +3 -3
  57. package/app/.next/server/app/api/bots/[id]/skill/route.js.nft.json +1 -1
  58. package/app/.next/server/app/api/bots/availability/route.js +2 -2
  59. package/app/.next/server/app/api/bots/availability/route.js.nft.json +1 -1
  60. package/app/.next/server/app/api/bots/delete-preview/route.js +3 -3
  61. package/app/.next/server/app/api/bots/delete-preview/route.js.nft.json +1 -1
  62. package/app/.next/server/app/api/bots/import/route.js +3 -3
  63. package/app/.next/server/app/api/bots/import/route.js.nft.json +1 -1
  64. package/app/.next/server/app/api/bots/manage/route.js +3 -3
  65. package/app/.next/server/app/api/bots/manage/route.js.nft.json +1 -1
  66. package/app/.next/server/app/api/bots/name-migrations/route.js +3 -3
  67. package/app/.next/server/app/api/bots/name-migrations/route.js.nft.json +1 -1
  68. package/app/.next/server/app/api/bots/route.js +6 -6
  69. package/app/.next/server/app/api/bots/route.js.nft.json +1 -1
  70. package/app/.next/server/app/api/conversations/[id]/approve/route.js +3 -3
  71. package/app/.next/server/app/api/conversations/[id]/approve/route.js.nft.json +1 -1
  72. package/app/.next/server/app/api/conversations/[id]/deny/route.js +3 -3
  73. package/app/.next/server/app/api/conversations/[id]/deny/route.js.nft.json +1 -1
  74. package/app/.next/server/app/api/conversations/[id]/draft/route.js +3 -3
  75. package/app/.next/server/app/api/conversations/[id]/draft/route.js.nft.json +1 -1
  76. package/app/.next/server/app/api/conversations/[id]/messages/[messageId]/stop/route.js +3 -3
  77. package/app/.next/server/app/api/conversations/[id]/messages/[messageId]/stop/route.js.nft.json +1 -1
  78. package/app/.next/server/app/api/conversations/[id]/messages/route.js +6 -6
  79. package/app/.next/server/app/api/conversations/[id]/messages/route.js.nft.json +1 -1
  80. package/app/.next/server/app/api/conversations/[id]/route.js +3 -3
  81. package/app/.next/server/app/api/conversations/[id]/route.js.nft.json +1 -1
  82. package/app/.next/server/app/api/conversations/[id]/stop/route.js +6 -6
  83. package/app/.next/server/app/api/conversations/[id]/stop/route.js.nft.json +1 -1
  84. package/app/.next/server/app/api/conversations/route.js +3 -3
  85. package/app/.next/server/app/api/conversations/route.js.nft.json +1 -1
  86. package/app/.next/server/app/api/exchanges/[id]/cancel/route.js +5 -5
  87. package/app/.next/server/app/api/exchanges/[id]/cancel/route.js.nft.json +1 -1
  88. package/app/.next/server/app/api/exchanges/[id]/route.js +5 -5
  89. package/app/.next/server/app/api/exchanges/[id]/route.js.nft.json +1 -1
  90. package/app/.next/server/app/api/exchanges/route.js +5 -5
  91. package/app/.next/server/app/api/exchanges/route.js.nft.json +1 -1
  92. package/app/.next/server/app/api/files/[name]/route.js +3 -2
  93. package/app/.next/server/app/api/files/[name]/route.js.nft.json +1 -1
  94. package/app/.next/server/app/api/groups/route.js +3 -3
  95. package/app/.next/server/app/api/groups/route.js.nft.json +1 -1
  96. package/app/.next/server/app/api/health/route.js +6 -2
  97. package/app/.next/server/app/api/health/route.js.nft.json +1 -1
  98. package/app/.next/server/app/api/import-capabilities/route.js +1 -1
  99. package/app/.next/server/app/api/import-capabilities/route.js.nft.json +1 -1
  100. package/app/.next/server/app/api/marketplace-handoff/route.js +1 -1
  101. package/app/.next/server/app/api/marketplace-handoff/route.js.nft.json +1 -1
  102. package/app/.next/server/app/api/marketplace-handoff/status/route.js +1 -1
  103. package/app/.next/server/app/api/marketplace-handoff/status/route.js.nft.json +1 -1
  104. package/app/.next/server/app/api/mcp/route.js +3 -3
  105. package/app/.next/server/app/api/mcp/route.js.nft.json +1 -1
  106. package/app/.next/server/app/api/messages/[id]/between/route.js +3 -3
  107. package/app/.next/server/app/api/messages/[id]/between/route.js.nft.json +1 -1
  108. package/app/.next/server/app/api/runtime-connections/route/app-paths-manifest.json +3 -0
  109. package/app/.next/server/app/api/runtime-connections/route/build-manifest.json +12 -0
  110. package/app/.next/server/app/api/runtime-connections/route/server-reference-manifest.json +4 -0
  111. package/app/.next/server/app/api/runtime-connections/route.js +9 -0
  112. package/app/.next/server/app/api/runtime-connections/route.js.nft.json +1 -0
  113. package/app/.next/server/app/api/runtime-connections/route_client-reference-manifest.js +3 -0
  114. package/app/.next/server/app/api/service-grants/route.js +3 -3
  115. package/app/.next/server/app/api/service-grants/route.js.nft.json +1 -1
  116. package/app/.next/server/app/api/shares/[shareRef]/revoke/route/app-paths-manifest.json +3 -0
  117. package/app/.next/server/app/api/shares/[shareRef]/revoke/route/build-manifest.json +12 -0
  118. package/app/.next/server/app/api/shares/[shareRef]/revoke/route/server-reference-manifest.json +4 -0
  119. package/app/.next/server/app/api/shares/[shareRef]/revoke/route.js +11 -0
  120. package/app/.next/server/app/api/shares/[shareRef]/revoke/route.js.nft.json +1 -0
  121. package/app/.next/server/app/api/shares/[shareRef]/revoke/route_client-reference-manifest.js +3 -0
  122. package/app/.next/server/app/api/shares/route/app-paths-manifest.json +3 -0
  123. package/app/.next/server/app/api/shares/route/build-manifest.json +12 -0
  124. package/app/.next/server/app/api/shares/route/server-reference-manifest.json +4 -0
  125. package/app/.next/server/app/api/shares/route.js +11 -0
  126. package/app/.next/server/app/api/shares/route.js.nft.json +1 -0
  127. package/app/.next/server/app/api/shares/route_client-reference-manifest.js +3 -0
  128. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route.js +6 -6
  129. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route.js.nft.json +1 -1
  130. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route.js +6 -6
  131. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route.js.nft.json +1 -1
  132. package/app/.next/server/app/api/v0/agents/[agentId]/messages/route.js +5 -5
  133. package/app/.next/server/app/api/v0/agents/[agentId]/messages/route.js.nft.json +1 -1
  134. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route/app-paths-manifest.json +3 -0
  135. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route/build-manifest.json +12 -0
  136. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route/server-reference-manifest.json +4 -0
  137. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route.js +11 -0
  138. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route.js.nft.json +1 -0
  139. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route_client-reference-manifest.js +3 -0
  140. package/app/.next/server/app/api/v0/agents/[agentId]/route.js +6 -6
  141. package/app/.next/server/app/api/v0/agents/[agentId]/route.js.nft.json +1 -1
  142. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route.js +6 -6
  143. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route.js.nft.json +1 -1
  144. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route.js +6 -6
  145. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route.js.nft.json +1 -1
  146. package/app/.next/server/app/api/v0/agents/route.js +6 -6
  147. package/app/.next/server/app/api/v0/agents/route.js.nft.json +1 -1
  148. package/app/.next/server/app/api/v0/capabilities/route.js +6 -6
  149. package/app/.next/server/app/api/v0/capabilities/route.js.nft.json +1 -1
  150. package/app/.next/server/app/api/v0/conversations/[id]/route.js +5 -5
  151. package/app/.next/server/app/api/v0/conversations/[id]/route.js.nft.json +1 -1
  152. package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route.js +6 -6
  153. package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route.js.nft.json +1 -1
  154. package/app/.next/server/app/api/v0/exchanges/[id]/route.js +6 -6
  155. package/app/.next/server/app/api/v0/exchanges/[id]/route.js.nft.json +1 -1
  156. package/app/.next/server/app/api/v0/exchanges/route.js +6 -6
  157. package/app/.next/server/app/api/v0/exchanges/route.js.nft.json +1 -1
  158. package/app/.next/server/app/api/v0/mcp/route.js +6 -6
  159. package/app/.next/server/app/api/v0/mcp/route.js.nft.json +1 -1
  160. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route/app-paths-manifest.json +3 -0
  161. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route/build-manifest.json +12 -0
  162. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route/server-reference-manifest.json +4 -0
  163. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route.js +11 -0
  164. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route.js.nft.json +1 -0
  165. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route_client-reference-manifest.js +3 -0
  166. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route/app-paths-manifest.json +3 -0
  167. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route/build-manifest.json +12 -0
  168. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route/server-reference-manifest.json +4 -0
  169. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route.js +11 -0
  170. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route.js.nft.json +1 -0
  171. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route_client-reference-manifest.js +3 -0
  172. package/app/.next/server/app/api/v0/pins/[pinRef]/route/app-paths-manifest.json +3 -0
  173. package/app/.next/server/app/api/v0/pins/[pinRef]/route/build-manifest.json +12 -0
  174. package/app/.next/server/app/api/v0/pins/[pinRef]/route/server-reference-manifest.json +4 -0
  175. package/app/.next/server/app/api/v0/pins/[pinRef]/route.js +11 -0
  176. package/app/.next/server/app/api/v0/pins/[pinRef]/route.js.nft.json +1 -0
  177. package/app/.next/server/app/api/v0/pins/[pinRef]/route_client-reference-manifest.js +3 -0
  178. package/app/.next/server/app/api/v0/requests/[id]/route.js +5 -5
  179. package/app/.next/server/app/api/v0/requests/[id]/route.js.nft.json +1 -1
  180. package/app/.next/server/app/api/v0/sessions/[ref]/messages/route.js +6 -6
  181. package/app/.next/server/app/api/v0/sessions/[ref]/messages/route.js.nft.json +1 -1
  182. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route/app-paths-manifest.json +3 -0
  183. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route/build-manifest.json +12 -0
  184. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route/server-reference-manifest.json +4 -0
  185. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route.js +11 -0
  186. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route.js.nft.json +1 -0
  187. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route_client-reference-manifest.js +3 -0
  188. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route/app-paths-manifest.json +3 -0
  189. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route/build-manifest.json +12 -0
  190. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route/server-reference-manifest.json +4 -0
  191. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route.js +11 -0
  192. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route.js.nft.json +1 -0
  193. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route_client-reference-manifest.js +3 -0
  194. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route/app-paths-manifest.json +3 -0
  195. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route/build-manifest.json +12 -0
  196. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route/server-reference-manifest.json +4 -0
  197. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route.js +11 -0
  198. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route.js.nft.json +1 -0
  199. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route_client-reference-manifest.js +3 -0
  200. package/app/.next/server/app/api/v0/shares/[shareRef]/route/app-paths-manifest.json +3 -0
  201. package/app/.next/server/app/api/v0/shares/[shareRef]/route/build-manifest.json +12 -0
  202. package/app/.next/server/app/api/v0/shares/[shareRef]/route/server-reference-manifest.json +4 -0
  203. package/app/.next/server/app/api/v0/shares/[shareRef]/route.js +11 -0
  204. package/app/.next/server/app/api/v0/shares/[shareRef]/route.js.nft.json +1 -0
  205. package/app/.next/server/app/api/v0/shares/[shareRef]/route_client-reference-manifest.js +3 -0
  206. package/app/.next/server/app/api/v0/shares/current/route/app-paths-manifest.json +3 -0
  207. package/app/.next/server/app/api/v0/shares/current/route/build-manifest.json +12 -0
  208. package/app/.next/server/app/api/v0/shares/current/route/server-reference-manifest.json +4 -0
  209. package/app/.next/server/app/api/v0/shares/current/route.js +11 -0
  210. package/app/.next/server/app/api/v0/shares/current/route.js.nft.json +1 -0
  211. package/app/.next/server/app/api/v0/shares/current/route_client-reference-manifest.js +3 -0
  212. package/app/.next/server/app/api/v0/shares/route/app-paths-manifest.json +3 -0
  213. package/app/.next/server/app/api/v0/shares/route/build-manifest.json +12 -0
  214. package/app/.next/server/app/api/v0/shares/route/server-reference-manifest.json +4 -0
  215. package/app/.next/server/app/api/v0/shares/route.js +11 -0
  216. package/app/.next/server/app/api/v0/shares/route.js.nft.json +1 -0
  217. package/app/.next/server/app/api/v0/shares/route_client-reference-manifest.js +3 -0
  218. package/app/.next/server/app/api/wake-grants/[id]/revoke/route.js +5 -5
  219. package/app/.next/server/app/api/wake-grants/[id]/revoke/route.js.nft.json +1 -1
  220. package/app/.next/server/app/api/wakes/[id]/decision/route.js +5 -5
  221. package/app/.next/server/app/api/wakes/[id]/decision/route.js.nft.json +1 -1
  222. package/app/.next/server/app/api/wakes/[id]/retry/route.js +5 -5
  223. package/app/.next/server/app/api/wakes/[id]/retry/route.js.nft.json +1 -1
  224. package/app/.next/server/app/bots/[id]/config/page.js +1 -1
  225. package/app/.next/server/app/bots/[id]/config/page.js.nft.json +1 -1
  226. package/app/.next/server/app/bots/[id]/config/page_client-reference-manifest.js +1 -1
  227. package/app/.next/server/app/exchanges/page.js +1 -1
  228. package/app/.next/server/app/exchanges/page.js.nft.json +1 -1
  229. package/app/.next/server/app/exchanges/page_client-reference-manifest.js +1 -1
  230. package/app/.next/server/app/exchanges.html +1 -1
  231. package/app/.next/server/app/exchanges.rsc +3 -3
  232. package/app/.next/server/app/exchanges.segments/_full.segment.rsc +3 -3
  233. package/app/.next/server/app/exchanges.segments/_tree.segment.rsc +2 -2
  234. package/app/.next/server/app/exchanges.segments/exchanges/__PAGE__.segment.rsc +3 -3
  235. package/app/.next/server/app/index.html +1 -1
  236. package/app/.next/server/app/index.rsc +3 -3
  237. package/app/.next/server/app/index.segments/__PAGE__.segment.rsc +3 -3
  238. package/app/.next/server/app/index.segments/_full.segment.rsc +3 -3
  239. package/app/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  240. package/app/.next/server/app/page.js +1 -1
  241. package/app/.next/server/app/page.js.nft.json +1 -1
  242. package/app/.next/server/app/page_client-reference-manifest.js +1 -1
  243. package/app/.next/server/app/settings/page.js +1 -1
  244. package/app/.next/server/app/settings/page.js.nft.json +1 -1
  245. package/app/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  246. package/app/.next/server/app/settings.html +1 -1
  247. package/app/.next/server/app/settings.rsc +3 -3
  248. package/app/.next/server/app/settings.segments/_full.segment.rsc +3 -3
  249. package/app/.next/server/app/settings.segments/_tree.segment.rsc +2 -2
  250. package/app/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +3 -3
  251. package/app/.next/server/app/threads/[id]/page.js +1 -1
  252. package/app/.next/server/app/threads/[id]/page.js.nft.json +1 -1
  253. package/app/.next/server/app/threads/[id]/page_client-reference-manifest.js +1 -1
  254. package/app/.next/server/app-paths-manifest.json +16 -0
  255. package/app/.next/server/chunks/1oeh_server_app_api_bots_[id]_sessions_[ref]_pins_route_actions_0e1st6o.js +3 -0
  256. package/app/.next/server/chunks/1oeh_server_app_api_bots_[id]_sessions_[ref]_shares_route_actions_1jr6f0v.js +3 -0
  257. package/app/.next/server/chunks/[externals]_@slack_0owayck._.js +3 -0
  258. package/app/.next/server/chunks/[externals]__17bolvp._.js +3 -0
  259. package/app/.next/server/chunks/{[externals]__06lqs5i._.js → [externals]__1eaoma8._.js} +1 -1
  260. package/app/.next/server/chunks/[root-of-the-server]__0-vcyi-._.js +3 -0
  261. package/app/.next/server/chunks/[root-of-the-server]__0-w_t2y._.js +3 -0
  262. package/app/.next/server/chunks/{[root-of-the-server]__17oz13o._.js → [root-of-the-server]__029-_9t._.js} +3 -3
  263. package/app/.next/server/chunks/[root-of-the-server]__02kssr-._.js +3 -0
  264. package/app/.next/server/chunks/[root-of-the-server]__02vrtib._.js +4 -0
  265. package/app/.next/server/chunks/[root-of-the-server]__04b3ml2._.js +3 -0
  266. package/app/.next/server/chunks/[root-of-the-server]__06w5xhe._.js +3 -0
  267. package/app/.next/server/chunks/[root-of-the-server]__07q5mnr._.js +3 -0
  268. package/app/.next/server/chunks/[root-of-the-server]__0888o0_._.js +3 -0
  269. package/app/.next/server/chunks/[root-of-the-server]__0aincj4._.js +3 -0
  270. package/app/.next/server/chunks/[root-of-the-server]__0e_agq4._.js +3 -0
  271. package/app/.next/server/chunks/[root-of-the-server]__0ey3_2x._.js +3 -0
  272. package/app/.next/server/chunks/[root-of-the-server]__0fku-bw._.js +3 -0
  273. package/app/.next/server/chunks/[root-of-the-server]__0iqh5ta._.js +3 -0
  274. package/app/.next/server/chunks/[root-of-the-server]__0ivjcgs._.js +4 -0
  275. package/app/.next/server/chunks/[root-of-the-server]__0j4pjyg._.js +3 -0
  276. package/app/.next/server/chunks/[root-of-the-server]__0kgnysc._.js +3 -0
  277. package/app/.next/server/chunks/[root-of-the-server]__0lwsto-._.js +5 -0
  278. package/app/.next/server/chunks/[root-of-the-server]__0mo_kn3._.js +48 -0
  279. package/app/.next/server/chunks/[root-of-the-server]__0mp8bap._.js +3 -0
  280. package/app/.next/server/chunks/[root-of-the-server]__0o9ijih._.js +3 -0
  281. package/app/.next/server/chunks/[root-of-the-server]__0qaiqut._.js +44 -0
  282. package/app/.next/server/chunks/[root-of-the-server]__0s1enbp._.js +3 -0
  283. package/app/.next/server/chunks/[root-of-the-server]__0wg992i._.js +3 -0
  284. package/app/.next/server/chunks/[root-of-the-server]__0zrx1iz._.js +3 -0
  285. package/app/.next/server/chunks/[root-of-the-server]__10b5-i-._.js +3 -0
  286. package/app/.next/server/chunks/[root-of-the-server]__17mum5-._.js +3 -0
  287. package/app/.next/server/chunks/[root-of-the-server]__17xl_55._.js +3 -0
  288. package/app/.next/server/chunks/[root-of-the-server]__1bhzfu_._.js +7 -0
  289. package/app/.next/server/chunks/[root-of-the-server]__1dxr858._.js +3 -0
  290. package/app/.next/server/chunks/[root-of-the-server]__1eps2a4._.js +3 -0
  291. package/app/.next/server/chunks/[root-of-the-server]__1g_n99l._.js +3 -0
  292. package/app/.next/server/chunks/[root-of-the-server]__1ggmit0._.js +4 -0
  293. package/app/.next/server/chunks/[root-of-the-server]__1hwy3jx._.js +3 -0
  294. package/app/.next/server/chunks/[root-of-the-server]__1i388e2._.js +3 -0
  295. package/app/.next/server/chunks/[root-of-the-server]__1i8glt4._.js +4 -0
  296. package/app/.next/server/chunks/{[root-of-the-server]__0j0i8xz._.js → [root-of-the-server]__1igzl05._.js} +1 -1
  297. package/app/.next/server/chunks/[root-of-the-server]__1kczttr._.js +3 -0
  298. package/app/.next/server/chunks/{[root-of-the-server]__1c3e2ds._.js → [root-of-the-server]__1kik2zt._.js} +1 -1
  299. package/app/.next/server/chunks/[root-of-the-server]__1t4ybp2._.js +48 -0
  300. package/app/.next/server/chunks/[root-of-the-server]__1v3ikuo._.js +3 -0
  301. package/app/.next/server/chunks/{[root-of-the-server]__0-45blq._.js → [root-of-the-server]__1z5l5cg._.js} +2 -2
  302. package/app/.next/server/chunks/[root-of-the-server]__200ep0k._.js +3 -0
  303. package/app/.next/server/chunks/_0061c2q._.js +50 -0
  304. package/app/.next/server/chunks/_04e2bgj._.js +3 -0
  305. package/app/.next/server/chunks/_05po7b4._.js +3 -0
  306. package/app/.next/server/chunks/_06sxx0e._.js +3 -0
  307. package/app/.next/server/chunks/_0a2do3x._.js +1 -1
  308. package/app/.next/server/chunks/_0ar2ooe._.js +3 -0
  309. package/app/.next/server/chunks/_0fmotaz._.js +3 -0
  310. package/app/.next/server/chunks/_0i8_xso._.js +3 -0
  311. package/app/.next/server/chunks/_0kpfto_._.js +3 -0
  312. package/app/.next/server/chunks/_0lm6uis._.js +3 -0
  313. package/app/.next/server/chunks/_0mpu5tl._.js +3 -0
  314. package/app/.next/server/chunks/_0qv-4by._.js +3 -0
  315. package/app/.next/server/chunks/_0u9cfq9._.js +3 -0
  316. package/app/.next/server/chunks/_0ul8k7g._.js +3 -0
  317. package/app/.next/server/chunks/_1-5mthb._.js +1 -1
  318. package/app/.next/server/chunks/_1-60d3o._.js +3 -0
  319. package/app/.next/server/chunks/_11-q8k1._.js +3 -0
  320. package/app/.next/server/chunks/_133y3b0._.js +3 -0
  321. package/app/.next/server/chunks/_167960a._.js +3 -0
  322. package/app/.next/server/chunks/_17vgjlt._.js +3 -0
  323. package/app/.next/server/chunks/_1amx9_4._.js +3 -0
  324. package/app/.next/server/chunks/_1b01v-_._.js +3 -0
  325. package/app/.next/server/chunks/_1c-g4gq._.js +3 -0
  326. package/app/.next/server/chunks/_1ess5if._.js +3 -0
  327. package/app/.next/server/chunks/_1ey6l4p._.js +3 -0
  328. package/app/.next/server/chunks/_1i0zod4._.js +3 -0
  329. package/app/.next/server/chunks/_1nlg4x_._.js +3 -0
  330. package/app/.next/server/chunks/_1x4dqzv._.js +3 -0
  331. package/app/.next/server/chunks/_1z0qbzc._.js +3 -0
  332. package/app/.next/server/chunks/_next-internal_server_app_api_bots_[id]_share-policy_route_actions_0x-p250.js +3 -0
  333. package/app/.next/server/chunks/_next-internal_server_app_api_runtime-connections_route_actions_06rulng.js +3 -0
  334. package/app/.next/server/chunks/_next-internal_server_app_api_shares_[shareRef]_revoke_route_actions_1cu5kah.js +3 -0
  335. package/app/.next/server/chunks/_next-internal_server_app_api_shares_route_actions_0wk7x1r.js +3 -0
  336. package/app/.next/server/chunks/_next-internal_server_app_api_v0_agents_[agentId]_pins_route_actions_08uftk9.js +3 -0
  337. package/app/.next/server/chunks/_next-internal_server_app_api_v0_pins_[pinRef]_detach_route_actions_0nk3268.js +3 -0
  338. package/app/.next/server/chunks/_next-internal_server_app_api_v0_pins_[pinRef]_messages_route_actions_1wenu96.js +3 -0
  339. package/app/.next/server/chunks/_next-internal_server_app_api_v0_pins_[pinRef]_route_actions_0z7fu_c.js +3 -0
  340. package/app/.next/server/chunks/_next-internal_server_app_api_v0_sessions_[ref]_pins_route_actions_0y3ere3.js +3 -0
  341. package/app/.next/server/chunks/_next-internal_server_app_api_v0_sessions_[ref]_shares_route_actions_11fh--7.js +3 -0
  342. package/app/.next/server/chunks/_next-internal_server_app_api_v0_shares_[shareRef]_revoke_route_actions_00rzyj9.js +3 -0
  343. package/app/.next/server/chunks/_next-internal_server_app_api_v0_shares_[shareRef]_route_actions_0i1t5qb.js +3 -0
  344. package/app/.next/server/chunks/_next-internal_server_app_api_v0_shares_current_route_actions_1w_bpas.js +3 -0
  345. package/app/.next/server/chunks/_next-internal_server_app_api_v0_shares_route_actions_1b38was.js +3 -0
  346. package/app/.next/server/chunks/lib_0kik6bx._.js +1 -1
  347. package/app/.next/server/chunks/lib_0pe3tiv._.js +1 -1
  348. package/app/.next/server/chunks/lib_0v4d9w0._.js +339 -0
  349. package/app/.next/server/chunks/lib_0zzo6zb._.js +339 -0
  350. package/app/.next/server/chunks/lib_15adnlz._.js +2189 -0
  351. package/app/.next/server/chunks/lib_1_u7n-u._.js +339 -0
  352. package/app/.next/server/chunks/lib_1muhwn7._.js +339 -0
  353. package/app/.next/server/chunks/lib_1xnxg-q._.js +339 -0
  354. package/app/.next/server/chunks/lib_1zc7-gl._.js +2189 -0
  355. package/app/.next/server/chunks/lib_agent-api_ts_0iv52-o._.js +3 -0
  356. package/app/.next/server/chunks/lib_db_ts_1ttuckb._.js +1951 -0
  357. package/app/.next/server/chunks/lib_service-api-http_ts_0xzqhny._.js +5 -5
  358. package/app/.next/server/chunks/lib_slack-runtime_ts_0fgsejy._.js +63 -0
  359. package/app/.next/server/chunks/ssr/{[root-of-the-server]__03186rx._.js → [root-of-the-server]__1smmfpx._.js} +1 -1
  360. package/app/.next/server/chunks/ssr/_0_fa0na._.js +3 -0
  361. package/app/.next/server/chunks/ssr/_0epgorw._.js +3 -0
  362. package/app/.next/server/chunks/ssr/_1cvuhjt._.js +3 -0
  363. package/app/.next/server/chunks/ssr/_1i02yyi._.js +3 -0
  364. package/app/.next/server/chunks/ssr/_1n5mvo5._.js +3 -0
  365. package/app/.next/server/chunks/ssr/_1o94bnv._.js +1 -1
  366. package/app/.next/server/chunks/ssr/app_bots_[id]_config_page_tsx_1e0uue9._.js +1 -1
  367. package/app/.next/server/chunks/ssr/app_components_AgentDeckRuntime_tsx_024janf._.js +1 -1
  368. package/app/.next/server/chunks/ssr/app_exchanges_page_tsx_0j-n2a1._.js +3 -0
  369. package/app/.next/server/chunks/ssr/node_modules_@swc_helpers_cjs__interop_require_default_cjs_1ztp13a._.js +3 -0
  370. package/app/.next/server/instrumentation.js +4 -0
  371. package/app/.next/server/middleware-build-manifest.js +3 -3
  372. package/app/.next/server/middleware.js +1 -1
  373. package/app/.next/server/pages/404.html +1 -1
  374. package/app/.next/server/pages/500.html +1 -1
  375. package/app/.next/server/server-reference-manifest.js +1 -1
  376. package/app/.next/server/server-reference-manifest.json +1 -1
  377. package/app/.next/static/chunks/0jon21u-9j2aw.css +3 -0
  378. package/app/.next/static/chunks/14k6cvywgknx2.js +3 -0
  379. package/app/.next/static/chunks/1ku9himlsx-hn.js +1 -0
  380. package/app/.next/static/chunks/1r5tqd-7h1xjn.js +1 -0
  381. package/app/.next/static/chunks/21aqekm5z0j47.js +1 -0
  382. package/app/.next/static/chunks/22xbkclbkct3s.js +1 -0
  383. package/app/.next/static/chunks/2c953okoei6ip.js +1 -0
  384. package/app/.next/static/chunks/2t_2gf3xoxz_m.js +1 -0
  385. package/app/.next/static/chunks/34vnvo1qssbaj.js +1 -0
  386. package/app/BUILD_INFO.json +2 -2
  387. package/app/node_modules/@slack/logger/dist/index.js +94 -0
  388. package/app/node_modules/@slack/logger/package.json +43 -0
  389. package/app/node_modules/@slack/socket-mode/dist/package.json +67 -0
  390. package/app/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.js +242 -0
  391. package/app/node_modules/@slack/socket-mode/dist/src/SocketModeClient.js +363 -0
  392. package/app/node_modules/@slack/socket-mode/dist/src/UnrecoverableSocketModeStartError.js +14 -0
  393. package/app/node_modules/@slack/socket-mode/dist/src/errors.js +68 -0
  394. package/app/node_modules/@slack/socket-mode/dist/src/index.js +13 -0
  395. package/app/node_modules/@slack/socket-mode/dist/src/logger.js +26 -0
  396. package/app/node_modules/@slack/socket-mode/package.json +67 -0
  397. package/app/node_modules/@slack/types/dist/block-kit/block-elements.js +4 -0
  398. package/app/node_modules/@slack/types/dist/block-kit/blocks.js +3 -0
  399. package/app/node_modules/@slack/types/dist/block-kit/composition-objects.js +4 -0
  400. package/app/node_modules/@slack/types/dist/block-kit/extensions.js +3 -0
  401. package/app/node_modules/@slack/types/dist/calls.js +6 -0
  402. package/app/node_modules/@slack/types/dist/chunk.js +3 -0
  403. package/app/node_modules/@slack/types/dist/dialog.js +3 -0
  404. package/app/node_modules/@slack/types/dist/events/app.js +3 -0
  405. package/app/node_modules/@slack/types/dist/events/assistant.js +3 -0
  406. package/app/node_modules/@slack/types/dist/events/call.js +3 -0
  407. package/app/node_modules/@slack/types/dist/events/channel.js +3 -0
  408. package/app/node_modules/@slack/types/dist/events/dnd.js +3 -0
  409. package/app/node_modules/@slack/types/dist/events/email.js +3 -0
  410. package/app/node_modules/@slack/types/dist/events/emoji.js +3 -0
  411. package/app/node_modules/@slack/types/dist/events/file.js +4 -0
  412. package/app/node_modules/@slack/types/dist/events/function.js +3 -0
  413. package/app/node_modules/@slack/types/dist/events/grid-migration.js +3 -0
  414. package/app/node_modules/@slack/types/dist/events/group.js +3 -0
  415. package/app/node_modules/@slack/types/dist/events/im.js +3 -0
  416. package/app/node_modules/@slack/types/dist/events/index.js +43 -0
  417. package/app/node_modules/@slack/types/dist/events/invite.js +3 -0
  418. package/app/node_modules/@slack/types/dist/events/link-shared.js +3 -0
  419. package/app/node_modules/@slack/types/dist/events/member.js +3 -0
  420. package/app/node_modules/@slack/types/dist/events/message-metadata.js +3 -0
  421. package/app/node_modules/@slack/types/dist/events/message.js +3 -0
  422. package/app/node_modules/@slack/types/dist/events/pin.js +3 -0
  423. package/app/node_modules/@slack/types/dist/events/reaction.js +3 -0
  424. package/app/node_modules/@slack/types/dist/events/shared-channel.js +3 -0
  425. package/app/node_modules/@slack/types/dist/events/star.js +3 -0
  426. package/app/node_modules/@slack/types/dist/events/steps-from-apps.js +3 -0
  427. package/app/node_modules/@slack/types/dist/events/subteam.js +3 -0
  428. package/app/node_modules/@slack/types/dist/events/team.js +3 -0
  429. package/app/node_modules/@slack/types/dist/events/token.js +3 -0
  430. package/app/node_modules/@slack/types/dist/events/user.js +3 -0
  431. package/app/node_modules/@slack/types/dist/index.js +28 -0
  432. package/app/node_modules/@slack/types/dist/message-attachments.js +3 -0
  433. package/app/node_modules/@slack/types/dist/message-metadata.js +27 -0
  434. package/app/node_modules/@slack/types/dist/views.js +3 -0
  435. package/app/node_modules/@slack/types/package.json +47 -0
  436. package/app/node_modules/@slack/web-api/dist/WebClient.js +818 -0
  437. package/app/node_modules/@slack/web-api/dist/chat-stream.js +178 -0
  438. package/app/node_modules/@slack/web-api/dist/errors.js +80 -0
  439. package/app/node_modules/@slack/web-api/dist/file-upload.js +360 -0
  440. package/app/node_modules/@slack/web-api/dist/helpers.js +14 -0
  441. package/app/node_modules/@slack/web-api/dist/index.js +39 -0
  442. package/app/node_modules/@slack/web-api/dist/instrument.js +87 -0
  443. package/app/node_modules/@slack/web-api/dist/logger.js +29 -0
  444. package/app/node_modules/@slack/web-api/dist/methods.js +1647 -0
  445. package/app/node_modules/@slack/web-api/dist/retry-policies.js +34 -0
  446. package/app/node_modules/@slack/web-api/dist/types/helpers.js +3 -0
  447. package/app/node_modules/@slack/web-api/dist/types/request/admin/analytics.js +3 -0
  448. package/app/node_modules/@slack/web-api/dist/types/request/admin/apps.js +3 -0
  449. package/app/node_modules/@slack/web-api/dist/types/request/admin/auth.js +3 -0
  450. package/app/node_modules/@slack/web-api/dist/types/request/admin/barriers.js +3 -0
  451. package/app/node_modules/@slack/web-api/dist/types/request/admin/conversations.js +3 -0
  452. package/app/node_modules/@slack/web-api/dist/types/request/admin/emoji.js +3 -0
  453. package/app/node_modules/@slack/web-api/dist/types/request/admin/functions.js +3 -0
  454. package/app/node_modules/@slack/web-api/dist/types/request/admin/inviteRequests.js +3 -0
  455. package/app/node_modules/@slack/web-api/dist/types/request/admin/roles.js +3 -0
  456. package/app/node_modules/@slack/web-api/dist/types/request/admin/teams.js +3 -0
  457. package/app/node_modules/@slack/web-api/dist/types/request/admin/usergroups.js +3 -0
  458. package/app/node_modules/@slack/web-api/dist/types/request/admin/users.js +3 -0
  459. package/app/node_modules/@slack/web-api/dist/types/request/admin/workflows.js +3 -0
  460. package/app/node_modules/@slack/web-api/dist/types/request/api.js +3 -0
  461. package/app/node_modules/@slack/web-api/dist/types/request/apps.js +3 -0
  462. package/app/node_modules/@slack/web-api/dist/types/request/assistant.js +3 -0
  463. package/app/node_modules/@slack/web-api/dist/types/request/auth.js +3 -0
  464. package/app/node_modules/@slack/web-api/dist/types/request/bookmarks.js +3 -0
  465. package/app/node_modules/@slack/web-api/dist/types/request/bots.js +3 -0
  466. package/app/node_modules/@slack/web-api/dist/types/request/calls.js +3 -0
  467. package/app/node_modules/@slack/web-api/dist/types/request/canvas.js +3 -0
  468. package/app/node_modules/@slack/web-api/dist/types/request/chat.js +3 -0
  469. package/app/node_modules/@slack/web-api/dist/types/request/common.js +4 -0
  470. package/app/node_modules/@slack/web-api/dist/types/request/conversations.js +3 -0
  471. package/app/node_modules/@slack/web-api/dist/types/request/dialog.js +3 -0
  472. package/app/node_modules/@slack/web-api/dist/types/request/dnd.js +3 -0
  473. package/app/node_modules/@slack/web-api/dist/types/request/emoji.js +3 -0
  474. package/app/node_modules/@slack/web-api/dist/types/request/entity.js +3 -0
  475. package/app/node_modules/@slack/web-api/dist/types/request/files.js +3 -0
  476. package/app/node_modules/@slack/web-api/dist/types/request/functions.js +3 -0
  477. package/app/node_modules/@slack/web-api/dist/types/request/index.js +3 -0
  478. package/app/node_modules/@slack/web-api/dist/types/request/manifest.js +3 -0
  479. package/app/node_modules/@slack/web-api/dist/types/request/migration.js +3 -0
  480. package/app/node_modules/@slack/web-api/dist/types/request/oauth.js +3 -0
  481. package/app/node_modules/@slack/web-api/dist/types/request/openid.js +3 -0
  482. package/app/node_modules/@slack/web-api/dist/types/request/pins.js +3 -0
  483. package/app/node_modules/@slack/web-api/dist/types/request/reactions.js +3 -0
  484. package/app/node_modules/@slack/web-api/dist/types/request/reminders.js +3 -0
  485. package/app/node_modules/@slack/web-api/dist/types/request/rtm.js +3 -0
  486. package/app/node_modules/@slack/web-api/dist/types/request/search.js +3 -0
  487. package/app/node_modules/@slack/web-api/dist/types/request/slackLists.js +3 -0
  488. package/app/node_modules/@slack/web-api/dist/types/request/stars.js +3 -0
  489. package/app/node_modules/@slack/web-api/dist/types/request/team.js +3 -0
  490. package/app/node_modules/@slack/web-api/dist/types/request/tooling.js +3 -0
  491. package/app/node_modules/@slack/web-api/dist/types/request/usergroups.js +3 -0
  492. package/app/node_modules/@slack/web-api/dist/types/request/users.js +3 -0
  493. package/app/node_modules/@slack/web-api/dist/types/request/views.js +3 -0
  494. package/app/node_modules/@slack/web-api/dist/types/request/workflows.js +3 -0
  495. package/app/node_modules/@slack/web-api/dist/types/response/AdminAnalyticsGetFileResponse.js +3 -0
  496. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsActivitiesListResponse.js +11 -0
  497. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsApproveResponse.js +11 -0
  498. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsApprovedListResponse.js +11 -0
  499. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsClearResolutionResponse.js +11 -0
  500. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsConfigLookupResponse.js +11 -0
  501. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsConfigSetResponse.js +11 -0
  502. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsRequestsCancelResponse.js +11 -0
  503. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsRequestsListResponse.js +11 -0
  504. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsRestrictResponse.js +11 -0
  505. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsRestrictedListResponse.js +11 -0
  506. package/app/node_modules/@slack/web-api/dist/types/response/AdminAppsUninstallResponse.js +11 -0
  507. package/app/node_modules/@slack/web-api/dist/types/response/AdminAuthPolicyAssignEntitiesResponse.js +11 -0
  508. package/app/node_modules/@slack/web-api/dist/types/response/AdminAuthPolicyGetEntitiesResponse.js +11 -0
  509. package/app/node_modules/@slack/web-api/dist/types/response/AdminAuthPolicyRemoveEntitiesResponse.js +11 -0
  510. package/app/node_modules/@slack/web-api/dist/types/response/AdminBarriersCreateResponse.js +11 -0
  511. package/app/node_modules/@slack/web-api/dist/types/response/AdminBarriersDeleteResponse.js +11 -0
  512. package/app/node_modules/@slack/web-api/dist/types/response/AdminBarriersListResponse.js +11 -0
  513. package/app/node_modules/@slack/web-api/dist/types/response/AdminBarriersUpdateResponse.js +11 -0
  514. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsArchiveResponse.js +11 -0
  515. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsBulkArchiveResponse.js +11 -0
  516. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsBulkDeleteResponse.js +11 -0
  517. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsBulkMoveResponse.js +11 -0
  518. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsConvertToPrivateResponse.js +11 -0
  519. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsConvertToPublicResponse.js +11 -0
  520. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsCreateResponse.js +11 -0
  521. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsDeleteResponse.js +11 -0
  522. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsDisconnectSharedResponse.js +11 -0
  523. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsEkmListOriginalConnectedChannelInfoResponse.js +11 -0
  524. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsGetConversationPrefsResponse.js +11 -0
  525. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsGetCustomRetentionResponse.js +11 -0
  526. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsGetTeamsResponse.js +11 -0
  527. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsInviteResponse.js +11 -0
  528. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsLookupResponse.js +11 -0
  529. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsRemoveCustomRetentionResponse.js +11 -0
  530. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsRenameResponse.js +11 -0
  531. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsRestrictAccessAddGroupResponse.js +11 -0
  532. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsRestrictAccessListGroupsResponse.js +11 -0
  533. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsRestrictAccessRemoveGroupResponse.js +11 -0
  534. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsSearchResponse.js +11 -0
  535. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsSetConversationPrefsResponse.js +11 -0
  536. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsSetCustomRetentionResponse.js +11 -0
  537. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsSetTeamsResponse.js +11 -0
  538. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsUnarchiveResponse.js +11 -0
  539. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsWhitelistAddResponse.js +11 -0
  540. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsWhitelistListGroupsLinkedToChannelResponse.js +11 -0
  541. package/app/node_modules/@slack/web-api/dist/types/response/AdminConversationsWhitelistRemoveResponse.js +11 -0
  542. package/app/node_modules/@slack/web-api/dist/types/response/AdminEmojiAddAliasResponse.js +11 -0
  543. package/app/node_modules/@slack/web-api/dist/types/response/AdminEmojiAddResponse.js +11 -0
  544. package/app/node_modules/@slack/web-api/dist/types/response/AdminEmojiListResponse.js +11 -0
  545. package/app/node_modules/@slack/web-api/dist/types/response/AdminEmojiRemoveResponse.js +11 -0
  546. package/app/node_modules/@slack/web-api/dist/types/response/AdminEmojiRenameResponse.js +11 -0
  547. package/app/node_modules/@slack/web-api/dist/types/response/AdminFunctionsListResponse.js +11 -0
  548. package/app/node_modules/@slack/web-api/dist/types/response/AdminFunctionsPermissionsLookupResponse.js +11 -0
  549. package/app/node_modules/@slack/web-api/dist/types/response/AdminFunctionsPermissionsSetResponse.js +11 -0
  550. package/app/node_modules/@slack/web-api/dist/types/response/AdminInviteRequestsApproveResponse.js +11 -0
  551. package/app/node_modules/@slack/web-api/dist/types/response/AdminInviteRequestsApprovedListResponse.js +11 -0
  552. package/app/node_modules/@slack/web-api/dist/types/response/AdminInviteRequestsDeniedListResponse.js +11 -0
  553. package/app/node_modules/@slack/web-api/dist/types/response/AdminInviteRequestsDenyResponse.js +11 -0
  554. package/app/node_modules/@slack/web-api/dist/types/response/AdminInviteRequestsListResponse.js +11 -0
  555. package/app/node_modules/@slack/web-api/dist/types/response/AdminRolesAddAssignmentsResponse.js +11 -0
  556. package/app/node_modules/@slack/web-api/dist/types/response/AdminRolesListAssignmentsResponse.js +11 -0
  557. package/app/node_modules/@slack/web-api/dist/types/response/AdminRolesRemoveAssignmentsResponse.js +11 -0
  558. package/app/node_modules/@slack/web-api/dist/types/response/AdminTeamsAdminsListResponse.js +11 -0
  559. package/app/node_modules/@slack/web-api/dist/types/response/AdminTeamsCreateResponse.js +11 -0
  560. package/app/node_modules/@slack/web-api/dist/types/response/AdminTeamsListResponse.js +11 -0
  561. package/app/node_modules/@slack/web-api/dist/types/response/AdminTeamsOwnersListResponse.js +11 -0
  562. package/app/node_modules/@slack/web-api/dist/types/response/AdminTeamsSettingsInfoResponse.js +11 -0
  563. package/app/node_modules/@slack/web-api/dist/types/response/AdminTeamsSettingsSetDefaultChannelsResponse.js +11 -0
  564. package/app/node_modules/@slack/web-api/dist/types/response/AdminTeamsSettingsSetDescriptionResponse.js +11 -0
  565. package/app/node_modules/@slack/web-api/dist/types/response/AdminTeamsSettingsSetDiscoverabilityResponse.js +11 -0
  566. package/app/node_modules/@slack/web-api/dist/types/response/AdminTeamsSettingsSetIconResponse.js +11 -0
  567. package/app/node_modules/@slack/web-api/dist/types/response/AdminTeamsSettingsSetNameResponse.js +11 -0
  568. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsergroupsAddChannelsResponse.js +11 -0
  569. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsergroupsAddTeamsResponse.js +11 -0
  570. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsergroupsListChannelsResponse.js +11 -0
  571. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsergroupsRemoveChannelsResponse.js +11 -0
  572. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersAssignResponse.js +11 -0
  573. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersInviteResponse.js +11 -0
  574. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersListResponse.js +11 -0
  575. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersRemoveResponse.js +11 -0
  576. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSessionClearSettingsResponse.js +11 -0
  577. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSessionGetSettingsResponse.js +11 -0
  578. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSessionInvalidateResponse.js +11 -0
  579. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSessionListResponse.js +11 -0
  580. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSessionResetBulkResponse.js +11 -0
  581. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSessionResetResponse.js +11 -0
  582. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSessionSetSettingsResponse.js +11 -0
  583. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSetAdminResponse.js +11 -0
  584. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSetExpirationResponse.js +11 -0
  585. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSetOwnerResponse.js +11 -0
  586. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersSetRegularResponse.js +11 -0
  587. package/app/node_modules/@slack/web-api/dist/types/response/AdminUsersUnsupportedVersionsExportResponse.js +11 -0
  588. package/app/node_modules/@slack/web-api/dist/types/response/AdminWorkflowsCollaboratorsAddResponse.js +11 -0
  589. package/app/node_modules/@slack/web-api/dist/types/response/AdminWorkflowsCollaboratorsRemoveResponse.js +11 -0
  590. package/app/node_modules/@slack/web-api/dist/types/response/AdminWorkflowsPermissionsLookupResponse.js +11 -0
  591. package/app/node_modules/@slack/web-api/dist/types/response/AdminWorkflowsSearchResponse.js +11 -0
  592. package/app/node_modules/@slack/web-api/dist/types/response/AdminWorkflowsUnpublishResponse.js +11 -0
  593. package/app/node_modules/@slack/web-api/dist/types/response/ApiTestResponse.js +11 -0
  594. package/app/node_modules/@slack/web-api/dist/types/response/AppsConnectionsOpenResponse.js +11 -0
  595. package/app/node_modules/@slack/web-api/dist/types/response/AppsEventAuthorizationsListResponse.js +11 -0
  596. package/app/node_modules/@slack/web-api/dist/types/response/AppsManifestCreateResponse.js +11 -0
  597. package/app/node_modules/@slack/web-api/dist/types/response/AppsManifestDeleteResponse.js +11 -0
  598. package/app/node_modules/@slack/web-api/dist/types/response/AppsManifestExportResponse.js +11 -0
  599. package/app/node_modules/@slack/web-api/dist/types/response/AppsManifestUpdateResponse.js +11 -0
  600. package/app/node_modules/@slack/web-api/dist/types/response/AppsManifestValidateResponse.js +11 -0
  601. package/app/node_modules/@slack/web-api/dist/types/response/AppsPermissionsInfoResponse.js +11 -0
  602. package/app/node_modules/@slack/web-api/dist/types/response/AppsPermissionsRequestResponse.js +11 -0
  603. package/app/node_modules/@slack/web-api/dist/types/response/AppsPermissionsResourcesListResponse.js +11 -0
  604. package/app/node_modules/@slack/web-api/dist/types/response/AppsPermissionsScopesListResponse.js +11 -0
  605. package/app/node_modules/@slack/web-api/dist/types/response/AppsPermissionsUsersListResponse.js +11 -0
  606. package/app/node_modules/@slack/web-api/dist/types/response/AppsPermissionsUsersRequestResponse.js +11 -0
  607. package/app/node_modules/@slack/web-api/dist/types/response/AppsUninstallResponse.js +11 -0
  608. package/app/node_modules/@slack/web-api/dist/types/response/AppsUserConnectionUpdateResponse.js +11 -0
  609. package/app/node_modules/@slack/web-api/dist/types/response/AssistantThreadsSetStatusResponse.js +11 -0
  610. package/app/node_modules/@slack/web-api/dist/types/response/AssistantThreadsSetSuggestedPromptsResponse.js +11 -0
  611. package/app/node_modules/@slack/web-api/dist/types/response/AssistantThreadsSetTitleResponse.js +11 -0
  612. package/app/node_modules/@slack/web-api/dist/types/response/AuthRevokeResponse.js +11 -0
  613. package/app/node_modules/@slack/web-api/dist/types/response/AuthTeamsListResponse.js +11 -0
  614. package/app/node_modules/@slack/web-api/dist/types/response/AuthTestResponse.js +11 -0
  615. package/app/node_modules/@slack/web-api/dist/types/response/BookmarksAddResponse.js +11 -0
  616. package/app/node_modules/@slack/web-api/dist/types/response/BookmarksEditResponse.js +11 -0
  617. package/app/node_modules/@slack/web-api/dist/types/response/BookmarksListResponse.js +11 -0
  618. package/app/node_modules/@slack/web-api/dist/types/response/BookmarksRemoveResponse.js +11 -0
  619. package/app/node_modules/@slack/web-api/dist/types/response/BotsInfoResponse.js +11 -0
  620. package/app/node_modules/@slack/web-api/dist/types/response/CallsAddResponse.js +11 -0
  621. package/app/node_modules/@slack/web-api/dist/types/response/CallsEndResponse.js +11 -0
  622. package/app/node_modules/@slack/web-api/dist/types/response/CallsInfoResponse.js +11 -0
  623. package/app/node_modules/@slack/web-api/dist/types/response/CallsParticipantsAddResponse.js +11 -0
  624. package/app/node_modules/@slack/web-api/dist/types/response/CallsParticipantsRemoveResponse.js +11 -0
  625. package/app/node_modules/@slack/web-api/dist/types/response/CallsUpdateResponse.js +11 -0
  626. package/app/node_modules/@slack/web-api/dist/types/response/CanvasesAccessDeleteResponse.js +11 -0
  627. package/app/node_modules/@slack/web-api/dist/types/response/CanvasesAccessSetResponse.js +11 -0
  628. package/app/node_modules/@slack/web-api/dist/types/response/CanvasesCreateResponse.js +11 -0
  629. package/app/node_modules/@slack/web-api/dist/types/response/CanvasesDeleteResponse.js +11 -0
  630. package/app/node_modules/@slack/web-api/dist/types/response/CanvasesEditResponse.js +11 -0
  631. package/app/node_modules/@slack/web-api/dist/types/response/CanvasesSectionsLookupResponse.js +11 -0
  632. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsArchiveResponse.js +11 -0
  633. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsCreateResponse.js +11 -0
  634. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsHistoryResponse.js +11 -0
  635. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsInfoResponse.js +11 -0
  636. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsInviteResponse.js +11 -0
  637. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsJoinResponse.js +11 -0
  638. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsKickResponse.js +11 -0
  639. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsLeaveResponse.js +11 -0
  640. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsListResponse.js +11 -0
  641. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsMarkResponse.js +11 -0
  642. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsRenameResponse.js +11 -0
  643. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsRepliesResponse.js +11 -0
  644. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsSetPurposeResponse.js +11 -0
  645. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsSetTopicResponse.js +11 -0
  646. package/app/node_modules/@slack/web-api/dist/types/response/ChannelsUnarchiveResponse.js +11 -0
  647. package/app/node_modules/@slack/web-api/dist/types/response/ChatAppendStreamResponse.js +3 -0
  648. package/app/node_modules/@slack/web-api/dist/types/response/ChatDeleteResponse.js +11 -0
  649. package/app/node_modules/@slack/web-api/dist/types/response/ChatDeleteScheduledMessageResponse.js +11 -0
  650. package/app/node_modules/@slack/web-api/dist/types/response/ChatGetPermalinkResponse.js +11 -0
  651. package/app/node_modules/@slack/web-api/dist/types/response/ChatMeMessageResponse.js +11 -0
  652. package/app/node_modules/@slack/web-api/dist/types/response/ChatPostEphemeralResponse.js +11 -0
  653. package/app/node_modules/@slack/web-api/dist/types/response/ChatPostMessageResponse.js +67 -0
  654. package/app/node_modules/@slack/web-api/dist/types/response/ChatScheduleMessageResponse.js +48 -0
  655. package/app/node_modules/@slack/web-api/dist/types/response/ChatScheduledMessagesListResponse.js +11 -0
  656. package/app/node_modules/@slack/web-api/dist/types/response/ChatStartStreamResponse.js +3 -0
  657. package/app/node_modules/@slack/web-api/dist/types/response/ChatStopStreamResponse.js +3 -0
  658. package/app/node_modules/@slack/web-api/dist/types/response/ChatUnfurlResponse.js +11 -0
  659. package/app/node_modules/@slack/web-api/dist/types/response/ChatUpdateResponse.js +48 -0
  660. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsAcceptSharedInviteResponse.js +11 -0
  661. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsApproveSharedInviteResponse.js +11 -0
  662. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsArchiveResponse.js +11 -0
  663. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsCanvasesCreateResponse.js +11 -0
  664. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsCloseResponse.js +11 -0
  665. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsCreateResponse.js +11 -0
  666. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsDeclineSharedInviteResponse.js +11 -0
  667. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsExternalInvitePermissionsSetResponse.js +11 -0
  668. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsHistoryResponse.js +67 -0
  669. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsInfoResponse.js +11 -0
  670. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsInviteResponse.js +11 -0
  671. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsInviteSharedResponse.js +11 -0
  672. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsJoinResponse.js +11 -0
  673. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsKickResponse.js +11 -0
  674. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsLeaveResponse.js +11 -0
  675. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsListConnectInvitesResponse.js +11 -0
  676. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsListResponse.js +11 -0
  677. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsMarkResponse.js +11 -0
  678. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsMembersResponse.js +11 -0
  679. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsOpenResponse.js +48 -0
  680. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsRenameResponse.js +11 -0
  681. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsRepliesResponse.js +67 -0
  682. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsRequestSharedInviteApproveResponse.js +11 -0
  683. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsRequestSharedInviteDenyResponse.js +11 -0
  684. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsRequestSharedInviteListResponse.js +11 -0
  685. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsSetPurposeResponse.js +11 -0
  686. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsSetTopicResponse.js +11 -0
  687. package/app/node_modules/@slack/web-api/dist/types/response/ConversationsUnarchiveResponse.js +11 -0
  688. package/app/node_modules/@slack/web-api/dist/types/response/DialogOpenResponse.js +11 -0
  689. package/app/node_modules/@slack/web-api/dist/types/response/DndEndDndResponse.js +11 -0
  690. package/app/node_modules/@slack/web-api/dist/types/response/DndEndSnoozeResponse.js +11 -0
  691. package/app/node_modules/@slack/web-api/dist/types/response/DndInfoResponse.js +11 -0
  692. package/app/node_modules/@slack/web-api/dist/types/response/DndSetSnoozeResponse.js +11 -0
  693. package/app/node_modules/@slack/web-api/dist/types/response/DndTeamInfoResponse.js +11 -0
  694. package/app/node_modules/@slack/web-api/dist/types/response/EmojiListResponse.js +11 -0
  695. package/app/node_modules/@slack/web-api/dist/types/response/EntityPresentDetailsResponse.js +11 -0
  696. package/app/node_modules/@slack/web-api/dist/types/response/FilesCommentsAddResponse.js +11 -0
  697. package/app/node_modules/@slack/web-api/dist/types/response/FilesCommentsDeleteResponse.js +11 -0
  698. package/app/node_modules/@slack/web-api/dist/types/response/FilesCommentsEditResponse.js +11 -0
  699. package/app/node_modules/@slack/web-api/dist/types/response/FilesCompleteUploadExternalResponse.js +11 -0
  700. package/app/node_modules/@slack/web-api/dist/types/response/FilesDeleteResponse.js +11 -0
  701. package/app/node_modules/@slack/web-api/dist/types/response/FilesGetUploadURLExternalResponse.js +11 -0
  702. package/app/node_modules/@slack/web-api/dist/types/response/FilesInfoResponse.js +37 -0
  703. package/app/node_modules/@slack/web-api/dist/types/response/FilesListResponse.js +37 -0
  704. package/app/node_modules/@slack/web-api/dist/types/response/FilesRemoteAddResponse.js +37 -0
  705. package/app/node_modules/@slack/web-api/dist/types/response/FilesRemoteInfoResponse.js +37 -0
  706. package/app/node_modules/@slack/web-api/dist/types/response/FilesRemoteListResponse.js +37 -0
  707. package/app/node_modules/@slack/web-api/dist/types/response/FilesRemoteRemoveResponse.js +11 -0
  708. package/app/node_modules/@slack/web-api/dist/types/response/FilesRemoteShareResponse.js +37 -0
  709. package/app/node_modules/@slack/web-api/dist/types/response/FilesRemoteUpdateResponse.js +37 -0
  710. package/app/node_modules/@slack/web-api/dist/types/response/FilesRevokePublicURLResponse.js +37 -0
  711. package/app/node_modules/@slack/web-api/dist/types/response/FilesSharedPublicURLResponse.js +37 -0
  712. package/app/node_modules/@slack/web-api/dist/types/response/FilesUploadResponse.js +37 -0
  713. package/app/node_modules/@slack/web-api/dist/types/response/FunctionsCompleteErrorResponse.js +11 -0
  714. package/app/node_modules/@slack/web-api/dist/types/response/FunctionsCompleteSuccessResponse.js +11 -0
  715. package/app/node_modules/@slack/web-api/dist/types/response/GroupsArchiveResponse.js +11 -0
  716. package/app/node_modules/@slack/web-api/dist/types/response/GroupsCloseResponse.js +11 -0
  717. package/app/node_modules/@slack/web-api/dist/types/response/GroupsCreateChildResponse.js +11 -0
  718. package/app/node_modules/@slack/web-api/dist/types/response/GroupsCreateResponse.js +11 -0
  719. package/app/node_modules/@slack/web-api/dist/types/response/GroupsHistoryResponse.js +11 -0
  720. package/app/node_modules/@slack/web-api/dist/types/response/GroupsInfoResponse.js +11 -0
  721. package/app/node_modules/@slack/web-api/dist/types/response/GroupsInviteResponse.js +11 -0
  722. package/app/node_modules/@slack/web-api/dist/types/response/GroupsKickResponse.js +11 -0
  723. package/app/node_modules/@slack/web-api/dist/types/response/GroupsLeaveResponse.js +11 -0
  724. package/app/node_modules/@slack/web-api/dist/types/response/GroupsListResponse.js +11 -0
  725. package/app/node_modules/@slack/web-api/dist/types/response/GroupsMarkResponse.js +11 -0
  726. package/app/node_modules/@slack/web-api/dist/types/response/GroupsOpenResponse.js +11 -0
  727. package/app/node_modules/@slack/web-api/dist/types/response/GroupsRenameResponse.js +11 -0
  728. package/app/node_modules/@slack/web-api/dist/types/response/GroupsRepliesResponse.js +11 -0
  729. package/app/node_modules/@slack/web-api/dist/types/response/GroupsSetPurposeResponse.js +11 -0
  730. package/app/node_modules/@slack/web-api/dist/types/response/GroupsSetTopicResponse.js +11 -0
  731. package/app/node_modules/@slack/web-api/dist/types/response/GroupsUnarchiveResponse.js +11 -0
  732. package/app/node_modules/@slack/web-api/dist/types/response/ImCloseResponse.js +11 -0
  733. package/app/node_modules/@slack/web-api/dist/types/response/ImHistoryResponse.js +11 -0
  734. package/app/node_modules/@slack/web-api/dist/types/response/ImListResponse.js +11 -0
  735. package/app/node_modules/@slack/web-api/dist/types/response/ImMarkResponse.js +11 -0
  736. package/app/node_modules/@slack/web-api/dist/types/response/ImOpenResponse.js +11 -0
  737. package/app/node_modules/@slack/web-api/dist/types/response/ImRepliesResponse.js +11 -0
  738. package/app/node_modules/@slack/web-api/dist/types/response/MigrationExchangeResponse.js +11 -0
  739. package/app/node_modules/@slack/web-api/dist/types/response/MpimCloseResponse.js +11 -0
  740. package/app/node_modules/@slack/web-api/dist/types/response/MpimHistoryResponse.js +11 -0
  741. package/app/node_modules/@slack/web-api/dist/types/response/MpimListResponse.js +11 -0
  742. package/app/node_modules/@slack/web-api/dist/types/response/MpimMarkResponse.js +11 -0
  743. package/app/node_modules/@slack/web-api/dist/types/response/MpimOpenResponse.js +11 -0
  744. package/app/node_modules/@slack/web-api/dist/types/response/MpimRepliesResponse.js +11 -0
  745. package/app/node_modules/@slack/web-api/dist/types/response/OauthAccessResponse.js +11 -0
  746. package/app/node_modules/@slack/web-api/dist/types/response/OauthTokenResponse.js +11 -0
  747. package/app/node_modules/@slack/web-api/dist/types/response/OauthV2AccessResponse.js +11 -0
  748. package/app/node_modules/@slack/web-api/dist/types/response/OauthV2ExchangeResponse.js +11 -0
  749. package/app/node_modules/@slack/web-api/dist/types/response/OpenIDConnectTokenResponse.js +11 -0
  750. package/app/node_modules/@slack/web-api/dist/types/response/OpenIDConnectUserInfoResponse.js +11 -0
  751. package/app/node_modules/@slack/web-api/dist/types/response/PinsAddResponse.js +11 -0
  752. package/app/node_modules/@slack/web-api/dist/types/response/PinsListResponse.js +37 -0
  753. package/app/node_modules/@slack/web-api/dist/types/response/PinsRemoveResponse.js +11 -0
  754. package/app/node_modules/@slack/web-api/dist/types/response/ReactionsAddResponse.js +11 -0
  755. package/app/node_modules/@slack/web-api/dist/types/response/ReactionsGetResponse.js +48 -0
  756. package/app/node_modules/@slack/web-api/dist/types/response/ReactionsListResponse.js +67 -0
  757. package/app/node_modules/@slack/web-api/dist/types/response/ReactionsRemoveResponse.js +11 -0
  758. package/app/node_modules/@slack/web-api/dist/types/response/RemindersAddResponse.js +11 -0
  759. package/app/node_modules/@slack/web-api/dist/types/response/RemindersCompleteResponse.js +11 -0
  760. package/app/node_modules/@slack/web-api/dist/types/response/RemindersDeleteResponse.js +11 -0
  761. package/app/node_modules/@slack/web-api/dist/types/response/RemindersInfoResponse.js +11 -0
  762. package/app/node_modules/@slack/web-api/dist/types/response/RemindersListResponse.js +11 -0
  763. package/app/node_modules/@slack/web-api/dist/types/response/RtmConnectResponse.js +11 -0
  764. package/app/node_modules/@slack/web-api/dist/types/response/RtmStartResponse.js +77 -0
  765. package/app/node_modules/@slack/web-api/dist/types/response/SearchAllResponse.js +82 -0
  766. package/app/node_modules/@slack/web-api/dist/types/response/SearchFilesResponse.js +63 -0
  767. package/app/node_modules/@slack/web-api/dist/types/response/SearchMessagesResponse.js +67 -0
  768. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsAccessDeleteResponse.js +3 -0
  769. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsAccessSetResponse.js +3 -0
  770. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsCreateResponse.js +3 -0
  771. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsDownloadGetResponse.js +3 -0
  772. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsDownloadStartResponse.js +3 -0
  773. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsItemsCreateResponse.js +3 -0
  774. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsItemsDeleteMultipleResponse.js +3 -0
  775. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsItemsDeleteResponse.js +3 -0
  776. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsItemsInfoResponse.js +3 -0
  777. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsItemsListResponse.js +3 -0
  778. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsItemsUpdateResponse.js +3 -0
  779. package/app/node_modules/@slack/web-api/dist/types/response/SlackListsUpdateResponse.js +3 -0
  780. package/app/node_modules/@slack/web-api/dist/types/response/StarsAddResponse.js +11 -0
  781. package/app/node_modules/@slack/web-api/dist/types/response/StarsListResponse.js +11 -0
  782. package/app/node_modules/@slack/web-api/dist/types/response/StarsRemoveResponse.js +11 -0
  783. package/app/node_modules/@slack/web-api/dist/types/response/TeamAccessLogsResponse.js +11 -0
  784. package/app/node_modules/@slack/web-api/dist/types/response/TeamBillableInfoResponse.js +11 -0
  785. package/app/node_modules/@slack/web-api/dist/types/response/TeamBillingInfoResponse.js +11 -0
  786. package/app/node_modules/@slack/web-api/dist/types/response/TeamExternalTeamsDisconnectResponse.js +11 -0
  787. package/app/node_modules/@slack/web-api/dist/types/response/TeamExternalTeamsListResponse.js +11 -0
  788. package/app/node_modules/@slack/web-api/dist/types/response/TeamInfoResponse.js +11 -0
  789. package/app/node_modules/@slack/web-api/dist/types/response/TeamIntegrationLogsResponse.js +11 -0
  790. package/app/node_modules/@slack/web-api/dist/types/response/TeamPreferencesListResponse.js +11 -0
  791. package/app/node_modules/@slack/web-api/dist/types/response/TeamProfileGetResponse.js +11 -0
  792. package/app/node_modules/@slack/web-api/dist/types/response/ToolingTokensRotateResponse.js +11 -0
  793. package/app/node_modules/@slack/web-api/dist/types/response/UsergroupsCreateResponse.js +11 -0
  794. package/app/node_modules/@slack/web-api/dist/types/response/UsergroupsDisableResponse.js +11 -0
  795. package/app/node_modules/@slack/web-api/dist/types/response/UsergroupsEnableResponse.js +11 -0
  796. package/app/node_modules/@slack/web-api/dist/types/response/UsergroupsListResponse.js +11 -0
  797. package/app/node_modules/@slack/web-api/dist/types/response/UsergroupsUpdateResponse.js +11 -0
  798. package/app/node_modules/@slack/web-api/dist/types/response/UsergroupsUsersListResponse.js +11 -0
  799. package/app/node_modules/@slack/web-api/dist/types/response/UsergroupsUsersUpdateResponse.js +11 -0
  800. package/app/node_modules/@slack/web-api/dist/types/response/UsersConversationsResponse.js +11 -0
  801. package/app/node_modules/@slack/web-api/dist/types/response/UsersDeletePhotoResponse.js +11 -0
  802. package/app/node_modules/@slack/web-api/dist/types/response/UsersDiscoverableContactsLookupResponse.js +11 -0
  803. package/app/node_modules/@slack/web-api/dist/types/response/UsersGetPresenceResponse.js +11 -0
  804. package/app/node_modules/@slack/web-api/dist/types/response/UsersIdentityResponse.js +11 -0
  805. package/app/node_modules/@slack/web-api/dist/types/response/UsersInfoResponse.js +11 -0
  806. package/app/node_modules/@slack/web-api/dist/types/response/UsersListResponse.js +11 -0
  807. package/app/node_modules/@slack/web-api/dist/types/response/UsersLookupByEmailResponse.js +11 -0
  808. package/app/node_modules/@slack/web-api/dist/types/response/UsersProfileGetResponse.js +11 -0
  809. package/app/node_modules/@slack/web-api/dist/types/response/UsersProfileSetResponse.js +11 -0
  810. package/app/node_modules/@slack/web-api/dist/types/response/UsersSetActiveResponse.js +11 -0
  811. package/app/node_modules/@slack/web-api/dist/types/response/UsersSetPhotoResponse.js +11 -0
  812. package/app/node_modules/@slack/web-api/dist/types/response/UsersSetPresenceResponse.js +11 -0
  813. package/app/node_modules/@slack/web-api/dist/types/response/ViewsOpenResponse.js +31 -0
  814. package/app/node_modules/@slack/web-api/dist/types/response/ViewsPublishResponse.js +31 -0
  815. package/app/node_modules/@slack/web-api/dist/types/response/ViewsPushResponse.js +31 -0
  816. package/app/node_modules/@slack/web-api/dist/types/response/ViewsUpdateResponse.js +31 -0
  817. package/app/node_modules/@slack/web-api/dist/types/response/WorkflowsFeaturedAddResponse.js +3 -0
  818. package/app/node_modules/@slack/web-api/dist/types/response/WorkflowsFeaturedListResponse.js +3 -0
  819. package/app/node_modules/@slack/web-api/dist/types/response/WorkflowsFeaturedRemoveResponse.js +3 -0
  820. package/app/node_modules/@slack/web-api/dist/types/response/WorkflowsFeaturedSetResponse.js +3 -0
  821. package/app/node_modules/@slack/web-api/dist/types/response/WorkflowsStepCompletedResponse.js +11 -0
  822. package/app/node_modules/@slack/web-api/dist/types/response/WorkflowsStepFailedResponse.js +11 -0
  823. package/app/node_modules/@slack/web-api/dist/types/response/WorkflowsUpdateStepResponse.js +11 -0
  824. package/app/node_modules/@slack/web-api/dist/types/response/index.js +3 -0
  825. package/app/node_modules/@slack/web-api/package.json +75 -0
  826. package/app/node_modules/agent-base/dist/src/index.js +203 -0
  827. package/app/node_modules/agent-base/dist/src/promisify.js +18 -0
  828. package/app/node_modules/agent-base/package.json +64 -0
  829. package/app/node_modules/asynckit/index.js +6 -0
  830. package/app/node_modules/asynckit/lib/abort.js +29 -0
  831. package/app/node_modules/asynckit/lib/async.js +34 -0
  832. package/app/node_modules/asynckit/lib/defer.js +26 -0
  833. package/app/node_modules/asynckit/lib/iterate.js +75 -0
  834. package/app/node_modules/asynckit/lib/state.js +37 -0
  835. package/app/node_modules/asynckit/lib/terminator.js +29 -0
  836. package/app/node_modules/asynckit/package.json +63 -0
  837. package/app/node_modules/asynckit/parallel.js +43 -0
  838. package/app/node_modules/asynckit/serial.js +17 -0
  839. package/app/node_modules/asynckit/serialOrdered.js +75 -0
  840. package/app/node_modules/axios/dist/node/axios.cjs +6808 -0
  841. package/app/node_modules/axios/package.json +203 -0
  842. package/app/node_modules/call-bind-apply-helpers/actualApply.js +10 -0
  843. package/app/node_modules/call-bind-apply-helpers/functionApply.js +4 -0
  844. package/app/node_modules/call-bind-apply-helpers/functionCall.js +4 -0
  845. package/app/node_modules/call-bind-apply-helpers/index.js +15 -0
  846. package/app/node_modules/call-bind-apply-helpers/package.json +85 -0
  847. package/app/node_modules/call-bind-apply-helpers/reflectApply.js +4 -0
  848. package/app/node_modules/combined-stream/lib/combined_stream.js +208 -0
  849. package/app/node_modules/combined-stream/package.json +25 -0
  850. package/app/node_modules/debug/package.json +64 -0
  851. package/app/node_modules/debug/src/browser.js +272 -0
  852. package/app/node_modules/debug/src/common.js +292 -0
  853. package/app/node_modules/debug/src/index.js +10 -0
  854. package/app/node_modules/debug/src/node.js +263 -0
  855. package/app/node_modules/delayed-stream/lib/delayed_stream.js +107 -0
  856. package/app/node_modules/delayed-stream/package.json +27 -0
  857. package/app/node_modules/dunder-proto/get.js +30 -0
  858. package/app/node_modules/dunder-proto/package.json +76 -0
  859. package/app/node_modules/es-define-property/index.js +14 -0
  860. package/app/node_modules/es-define-property/package.json +81 -0
  861. package/app/node_modules/es-errors/eval.js +4 -0
  862. package/app/node_modules/es-errors/index.js +4 -0
  863. package/app/node_modules/es-errors/package.json +80 -0
  864. package/app/node_modules/es-errors/range.js +4 -0
  865. package/app/node_modules/es-errors/ref.js +4 -0
  866. package/app/node_modules/es-errors/syntax.js +4 -0
  867. package/app/node_modules/es-errors/type.js +4 -0
  868. package/app/node_modules/es-errors/uri.js +4 -0
  869. package/app/node_modules/es-object-atoms/index.js +4 -0
  870. package/app/node_modules/es-object-atoms/package.json +79 -0
  871. package/app/node_modules/es-set-tostringtag/index.js +35 -0
  872. package/app/node_modules/es-set-tostringtag/package.json +78 -0
  873. package/app/node_modules/eventemitter3/index.js +336 -0
  874. package/app/node_modules/eventemitter3/package.json +62 -0
  875. package/app/node_modules/follow-redirects/debug.js +15 -0
  876. package/app/node_modules/follow-redirects/index.js +709 -0
  877. package/app/node_modules/follow-redirects/package.json +58 -0
  878. package/app/node_modules/form-data/lib/browser.js +4 -0
  879. package/app/node_modules/form-data/lib/form_data.js +506 -0
  880. package/app/node_modules/form-data/lib/populate.js +10 -0
  881. package/app/node_modules/form-data/package.json +82 -0
  882. package/app/node_modules/function-bind/implementation.js +84 -0
  883. package/app/node_modules/function-bind/index.js +5 -0
  884. package/app/node_modules/function-bind/package.json +87 -0
  885. package/app/node_modules/get-intrinsic/index.js +378 -0
  886. package/app/node_modules/get-intrinsic/package.json +97 -0
  887. package/app/node_modules/get-proto/Object.getPrototypeOf.js +6 -0
  888. package/app/node_modules/get-proto/Reflect.getPrototypeOf.js +4 -0
  889. package/app/node_modules/get-proto/index.js +27 -0
  890. package/app/node_modules/get-proto/package.json +81 -0
  891. package/app/node_modules/gopd/gOPD.js +4 -0
  892. package/app/node_modules/gopd/index.js +15 -0
  893. package/app/node_modules/gopd/package.json +77 -0
  894. package/app/node_modules/has-flag/index.js +8 -0
  895. package/app/node_modules/has-flag/package.json +46 -0
  896. package/app/node_modules/has-symbols/index.js +14 -0
  897. package/app/node_modules/has-symbols/package.json +111 -0
  898. package/app/node_modules/has-symbols/shams.js +45 -0
  899. package/app/node_modules/has-tostringtag/package.json +108 -0
  900. package/app/node_modules/has-tostringtag/shams.js +8 -0
  901. package/app/node_modules/hasown/index.js +8 -0
  902. package/app/node_modules/hasown/package.json +91 -0
  903. package/app/node_modules/https-proxy-agent/dist/agent.js +177 -0
  904. package/app/node_modules/https-proxy-agent/dist/index.js +14 -0
  905. package/app/node_modules/https-proxy-agent/dist/parse-proxy-response.js +66 -0
  906. package/app/node_modules/https-proxy-agent/package.json +56 -0
  907. package/app/node_modules/is-electron/index.js +21 -0
  908. package/app/node_modules/is-electron/package.json +34 -0
  909. package/app/node_modules/is-stream/index.js +28 -0
  910. package/app/node_modules/is-stream/package.json +42 -0
  911. package/app/node_modules/math-intrinsics/abs.js +4 -0
  912. package/app/node_modules/math-intrinsics/floor.js +4 -0
  913. package/app/node_modules/math-intrinsics/isNaN.js +6 -0
  914. package/app/node_modules/math-intrinsics/max.js +4 -0
  915. package/app/node_modules/math-intrinsics/min.js +4 -0
  916. package/app/node_modules/math-intrinsics/package.json +86 -0
  917. package/app/node_modules/math-intrinsics/pow.js +4 -0
  918. package/app/node_modules/math-intrinsics/round.js +4 -0
  919. package/app/node_modules/math-intrinsics/sign.js +11 -0
  920. package/app/node_modules/mime-db/db.json +8519 -0
  921. package/app/node_modules/mime-db/index.js +12 -0
  922. package/app/node_modules/mime-db/package.json +60 -0
  923. package/app/node_modules/mime-types/index.js +188 -0
  924. package/app/node_modules/mime-types/package.json +44 -0
  925. package/app/node_modules/ms/index.js +162 -0
  926. package/app/node_modules/ms/package.json +38 -0
  927. package/app/node_modules/p-finally/index.js +15 -0
  928. package/app/node_modules/p-finally/package.json +42 -0
  929. package/app/node_modules/p-queue/dist/index.js +279 -0
  930. package/app/node_modules/p-queue/dist/lower-bound.js +21 -0
  931. package/app/node_modules/p-queue/dist/priority-queue.js +32 -0
  932. package/app/node_modules/p-queue/node_modules/eventemitter3/index.js +336 -0
  933. package/app/node_modules/p-queue/node_modules/eventemitter3/package.json +56 -0
  934. package/app/node_modules/p-queue/package.json +92 -0
  935. package/app/node_modules/p-retry/index.js +85 -0
  936. package/app/node_modules/p-retry/package.json +51 -0
  937. package/app/node_modules/p-timeout/index.js +57 -0
  938. package/app/node_modules/p-timeout/package.json +45 -0
  939. package/app/node_modules/retry/index.js +1 -0
  940. package/app/node_modules/retry/lib/retry.js +100 -0
  941. package/app/node_modules/retry/lib/retry_operation.js +162 -0
  942. package/app/node_modules/retry/package.json +36 -0
  943. package/app/node_modules/supports-color/index.js +135 -0
  944. package/app/node_modules/supports-color/package.json +53 -0
  945. package/app/node_modules/ws/index.js +22 -0
  946. package/app/node_modules/ws/lib/buffer-util.js +131 -0
  947. package/app/node_modules/ws/lib/constants.js +19 -0
  948. package/app/node_modules/ws/lib/event-target.js +292 -0
  949. package/app/node_modules/ws/lib/extension.js +203 -0
  950. package/app/node_modules/ws/lib/limiter.js +55 -0
  951. package/app/node_modules/ws/lib/permessage-deflate.js +530 -0
  952. package/app/node_modules/ws/lib/receiver.js +743 -0
  953. package/app/node_modules/ws/lib/sender.js +607 -0
  954. package/app/node_modules/ws/lib/stream.js +161 -0
  955. package/app/node_modules/ws/lib/subprotocol.js +62 -0
  956. package/app/node_modules/ws/lib/validation.js +152 -0
  957. package/app/node_modules/ws/lib/websocket-server.js +562 -0
  958. package/app/node_modules/ws/lib/websocket.js +1421 -0
  959. package/app/node_modules/ws/package.json +74 -0
  960. package/app/package.json +1 -1
  961. package/app/server.js +1 -1
  962. package/dist/cli.d.ts +1 -1
  963. package/dist/cli.js +7 -4
  964. package/dist/clients.js +7 -3
  965. package/dist/config.d.ts +2 -1
  966. package/dist/config.js +5 -4
  967. package/dist/contract.d.ts +1 -0
  968. package/dist/contract.js +5 -0
  969. package/dist/home.d.ts +1 -1
  970. package/dist/home.js +1 -1
  971. package/dist/index.d.ts +1 -1
  972. package/dist/index.js +1 -1
  973. package/dist/product.d.ts +8 -0
  974. package/dist/product.js +70 -4
  975. package/dist/upstream.js +2 -2
  976. package/package.json +2 -2
  977. package/schemas/botmancers.mcp.v2.tools.json +2353 -4
  978. package/skills/botmancers-collaboration/SKILL.md +25 -6
  979. package/skills/botmancers-collaboration/references/workflows.md +93 -0
  980. package/app/.next/server/chunks/[root-of-the-server]__0ab4e_k._.js +0 -3
  981. package/app/.next/server/chunks/[root-of-the-server]__0izjfmr._.js +0 -1656
  982. package/app/.next/server/chunks/[root-of-the-server]__0qozubc._.js +0 -3
  983. package/app/.next/server/chunks/[root-of-the-server]__0wtzcge._.js +0 -3
  984. package/app/.next/server/chunks/[root-of-the-server]__10m3szc._.js +0 -3
  985. package/app/.next/server/chunks/[root-of-the-server]__15hknun._.js +0 -3
  986. package/app/.next/server/chunks/[root-of-the-server]__16ikszu._.js +0 -3
  987. package/app/.next/server/chunks/[root-of-the-server]__1afl75n._.js +0 -3
  988. package/app/.next/server/chunks/[root-of-the-server]__1kvvdpx._.js +0 -7
  989. package/app/.next/server/chunks/[root-of-the-server]__1qoa704._.js +0 -7
  990. package/app/.next/server/chunks/[root-of-the-server]__1slu7d7._.js +0 -7
  991. package/app/.next/server/chunks/_06rti77._.js +0 -30
  992. package/app/.next/server/chunks/_09k38l1._.js +0 -3
  993. package/app/.next/server/chunks/_0dlg5kj._.js +0 -30
  994. package/app/.next/server/chunks/_0dyculb._.js +0 -30
  995. package/app/.next/server/chunks/_0eig2jc._.js +0 -30
  996. package/app/.next/server/chunks/_0ggf7vy._.js +0 -3
  997. package/app/.next/server/chunks/_0gtqbub._.js +0 -3
  998. package/app/.next/server/chunks/_0i7ga8c._.js +0 -3
  999. package/app/.next/server/chunks/_0kghtb6._.js +0 -3
  1000. package/app/.next/server/chunks/_0orubev._.js +0 -3
  1001. package/app/.next/server/chunks/_0sfpe9z._.js +0 -3
  1002. package/app/.next/server/chunks/_0th2j4w._.js +0 -3
  1003. package/app/.next/server/chunks/_0uz7r06._.js +0 -30
  1004. package/app/.next/server/chunks/_0x05ts4._.js +0 -3
  1005. package/app/.next/server/chunks/_0y3geoj._.js +0 -30
  1006. package/app/.next/server/chunks/_12tq5uv._.js +0 -30
  1007. package/app/.next/server/chunks/_147-4gl._.js +0 -3
  1008. package/app/.next/server/chunks/_14ky6a2._.js +0 -30
  1009. package/app/.next/server/chunks/_16kbxdt._.js +0 -30
  1010. package/app/.next/server/chunks/_1963m2f._.js +0 -30
  1011. package/app/.next/server/chunks/_1_34_h3._.js +0 -30
  1012. package/app/.next/server/chunks/_1cc-2mx._.js +0 -3
  1013. package/app/.next/server/chunks/_1ee4ej2._.js +0 -3
  1014. package/app/.next/server/chunks/_1esxu1s._.js +0 -3
  1015. package/app/.next/server/chunks/_1gn7eh7._.js +0 -3
  1016. package/app/.next/server/chunks/_1gw7qwf._.js +0 -3
  1017. package/app/.next/server/chunks/_1inyx08._.js +0 -3
  1018. package/app/.next/server/chunks/_1kjsnlr._.js +0 -3
  1019. package/app/.next/server/chunks/_1nurj3f._.js +0 -30
  1020. package/app/.next/server/chunks/_1p2rf_n._.js +0 -30
  1021. package/app/.next/server/chunks/_1p8rola._.js +0 -3
  1022. package/app/.next/server/chunks/_1u6tw78._.js +0 -30
  1023. package/app/.next/server/chunks/app_api_import-capabilities_route_ts_013w1kt._.js +0 -3
  1024. package/app/.next/server/chunks/lib_0t3s3rj._.js +0 -30
  1025. package/app/.next/server/chunks/lib_0zxi6rx._.js +0 -148
  1026. package/app/.next/server/chunks/lib_12udr7g._.js +0 -148
  1027. package/app/.next/server/chunks/lib_draft_ts_1atoius._.js +0 -3
  1028. package/app/.next/server/chunks/lib_session-catalog_ts_1i7f38f._.js +0 -30
  1029. package/app/.next/server/chunks/ssr/_00ysoah._.js +0 -3
  1030. package/app/.next/server/chunks/ssr/_157wnb_._.js +0 -3
  1031. package/app/.next/server/chunks/ssr/app_1-nwnha._.js +0 -3
  1032. package/app/.next/server/chunks/ssr/app_components_0bhuhd-._.js +0 -3
  1033. package/app/.next/server/chunks/ssr/app_components_0w2_b3t._.js +0 -3
  1034. package/app/.next/server/chunks/ssr/node_modules_next_dist_client_components_server-async-storage_0t1dato.js +0 -3
  1035. package/app/.next/static/chunks/0774d7ob6aze_.js +0 -1
  1036. package/app/.next/static/chunks/0d3ein53nlgja.js +0 -1
  1037. package/app/.next/static/chunks/1i5xroz391zkb.js +0 -1
  1038. package/app/.next/static/chunks/1vz50l951sr9e.css +0 -3
  1039. package/app/.next/static/chunks/24ggj819yt3y6.js +0 -1
  1040. package/app/.next/static/chunks/2_8lcalraul5s.js +0 -3
  1041. package/app/.next/static/chunks/30i0-l04mmdvk.js +0 -1
  1042. package/app/.next/static/chunks/3wdlh25l1vww9.js +0 -1
  1043. /package/app/.next/static/{ewp56HqU5-d9bpFog3bli → _yrIZIFsIbXA0Gaxkytjd}/_buildManifest.js +0 -0
  1044. /package/app/.next/static/{ewp56HqU5-d9bpFog3bli → _yrIZIFsIbXA0Gaxkytjd}/_clientMiddlewareManifest.js +0 -0
  1045. /package/app/.next/static/{ewp56HqU5-d9bpFog3bli → _yrIZIFsIbXA0Gaxkytjd}/_ssgManifest.js +0 -0
@@ -0,0 +1,1951 @@
1
+ module.exports=[62294,18966,64974,11626,40596,28420,35613,30098,e=>{"use strict";let t;var n=e.i(85148),i=e.i(22734),r=e.i(14747),s=e.i(54799),a=e.i(62349);let o=["direct","agent_deck"],_=["read_only","workspace_write"],d=["workspaces","sessions","all_provider_sessions"],E="This computer",u={mode:"read_only",allow_new_sessions:!0,allow_resume_with_edits:!1},c="Runtime connection is required. Pick the runtime this Agent uses.",l="Runtime connection not found.",T="Launch profile is required. Choose direct or agent_deck.",p="Invalid launch profile. Expected direct or agent_deck.",N="A direct launch profile does not use Agent Deck. Remove deck_id or choose agent_deck.",R="working_directory is an Agent Deck setting. Use default_workspace for a direct launch profile.",m="Session scope is required. Select workspaces, select sessions, or explicitly choose all_provider_sessions.",L="A session scope selects workspaces or sessions, not both.",g="Workspaces must be absolute paths (or start with ~/).",O="Launch policy is required. Choose read_only or workspace_write.",I=`Provider is required. Expected one of ${a.AGENTS.join("|")}.`;function A(e){return"string"==typeof e&&o.includes(e)}function S(e){return"string"==typeof e&&d.includes(e)}function k(e){return"string"==typeof e&&_.includes(e)}function f(e){return null==e?null:String(e).trim()||null}function v(e){return`rc-local-${e}`}function h(e){return`${a.AGENT_LABELS[e]} on ${E.toLowerCase()}`}function w(e){return e.startsWith("/")||"~"===e||e.startsWith("~/")}function C(e){return e.length>1?e.replace(/\/+$/,""):e}function q(e,t){let n=C(e),i=C(t);return n===i||i.startsWith("/"===n?"/":`${n}/`)}function y(e){if(null==e)return[];if(!Array.isArray(e))return null;let t=[];for(let n of e){if("string"!=typeof n)return null;let e=n.trim();e&&!t.includes(e)&&t.push(e)}return t}function b(e){let t=e.session_scope_kind;if(!S(t))return null;let n=[];if(e.session_scope_items)try{let t=y(JSON.parse(e.session_scope_items));if(null===t)return null;n=t}catch{return null}return"all_provider_sessions"===t?0===n.length?{kind:t,workspaces:[],sessions:[]}:null:0===n.length?null:"workspaces"===t?{kind:t,workspaces:n,sessions:[]}:{kind:t,workspaces:[],sessions:n}}function D(e){return!0===e||1===e||"1"===e}function U(e){return k(e.policy_mode)?{mode:e.policy_mode,allow_new_sessions:D(e.allow_new_sessions),allow_resume_with_edits:D(e.allow_resume_with_edits)}:null}function F(e){return A(e.launch_profile)?e.launch_profile:null}function W(e){var t;return{runtime_connection_id:e.runtime_connection_id,launch_profile:e.launch_profile,deck_id:"agent_deck"===e.launch_profile?e.deck_id:null,working_directory:"agent_deck"===e.launch_profile?e.working_directory:null,session_scope_kind:e.session_scope.kind,session_scope_items:JSON.stringify("workspaces"===(t=e.session_scope).kind?t.workspaces:"sessions"===t.kind?t.sessions:[]),default_workspace:e.default_workspace,policy_mode:e.policy.mode,allow_new_sessions:+!!e.policy.allow_new_sessions,allow_resume_with_edits:+!!e.policy.allow_resume_with_edits,home_session_id:e.home_session_id,needs_deck_selection:0}}function X(e){let t="hermes";try{t=(0,a.normalizeAgent)(e.agent)??"hermes"}catch{t="hermes"}let n=f(e.deck_id),i=D(e.needs_deck_selection),r=f(e.working_directory)??`~/.botmancers/${e.id}`;return{runtime_connection_id:v(t),provider:t,launch_profile:n&&!i?"agent_deck":null,session_scope_kind:"workspaces",session_scope_items:JSON.stringify([r]),policy_mode:u.mode,allow_new_sessions:+!!u.allow_new_sessions,allow_resume_with_edits:+!!u.allow_resume_with_edits}}let x=["runtime_connection_id","launch_profile","session_scope","default_workspace","policy","home_session_id"];function G(e){return x.some(t=>void 0!==e[t])}function H(e,t){if(null==e||"object"!=typeof e||Array.isArray(e)||void 0===e.kind||null===e.kind||""===e.kind)return t.push(m),null;if(!S(e.kind))return t.push("Invalid session scope kind. Expected workspaces, sessions, or all_provider_sessions."),null;let n=y(e.workspaces),i=y(e.sessions);if(null===n||null===i)return t.push("session_scope.workspaces and session_scope.sessions must be lists of strings."),null;let r=e.kind;return"all_provider_sessions"===r?n.length>0||i.length>0?(t.push("all_provider_sessions takes no workspace or session list."),null):{kind:r,workspaces:[],sessions:[]}:n.length>0&&i.length>0?(t.push(L),null):"workspaces"===r?i.length>0?(t.push(L),null):0===n.length?(t.push("Select at least one workspace. An empty scope is never unrestricted."),null):n.every(w)?{kind:r,workspaces:n,sessions:[]}:(t.push(g),null):n.length>0?(t.push(L),null):0===i.length?(t.push("Select at least one session. An empty scope is never unrestricted."),null):{kind:r,workspaces:[],sessions:i}}function B(e,t){if(null==e||"object"!=typeof e||Array.isArray(e)||void 0===e.mode||null===e.mode||""===e.mode)return t.push(O),null;if(!k(e.mode))return t.push("Invalid policy mode. Expected read_only or workspace_write."),null;let n=[];for(let i of["allow_new_sessions","allow_resume_with_edits"]){let r=e[i];if(void 0===r)n.push(!1);else{if("boolean"!=typeof r)return t.push("Policy flags allow_new_sessions and allow_resume_with_edits must be true or false."),null;n.push(r)}}let i={mode:e.mode,allow_new_sessions:n[0],allow_resume_with_edits:n[1]};return i.allow_resume_with_edits&&"workspace_write"!==i.mode?(t.push("allow_resume_with_edits requires the workspace_write policy mode."),null):i}function M(e,t){if(null==e)return null;if("string"!=typeof e)return t.push(g),null;let n=e.trim();return n?w(n)?n:(t.push(g),null):null}function K(e,t,n,i){"agent_deck"!==e.launch_profile||e.deck_id||i.push(a.DECK_REQUIRED_ERROR);let r=e.session_scope;"sessions"!==r.kind||r.sessions.every(e=>n.sessionBelongsTo(t,e))||i.push("A selected session does not belong to this Agent."),e.default_workspace&&"workspaces"===r.kind&&!r.workspaces.some(t=>q(t,e.default_workspace))&&i.push("default_workspace must be inside one of the selected workspaces."),e.home_session_id&&(n.sessionBelongsTo(t,e.home_session_id)?"sessions"!==r.kind||r.sessions.includes(e.home_session_id)||i.push("home_session_id must be one of the selected sessions."):i.push("home_session_id must be one of this Agent’s own sessions."))}function Y(e,t,n){let i=f(e.runtime_connection_id);if(!i)return n.push(c),null;let r=t.getConnection(i);return r?void 0!==e.agent&&null!==e.agent&&String(e.agent).trim()&&String(e.agent).trim()!==r.provider?(n.push("agent does not match the runtime connection provider."),null):r:(n.push(l),null)}function P(e,t){try{return(0,a.parseRequestDeckId)(e)}catch(e){return t.push(e instanceof Error?e.message:String(e)),null}}function $(e){return!G(e)&&void 0!==e.deck_id}function z(e){return{runtime_connection_id:f(e.runtime_connection_id),launch_profile:F(e),deck_id:f(e.deck_id),working_directory:f(e.working_directory),session_scope:b(e),default_workspace:f(e.default_workspace),policy:U(e),home_session_id:f(e.home_session_id)}}function j(e,t){let n=z(e);return{runtime_connection_id:n.runtime_connection_id,runtime_connection:t?{id:t.id,provider:t.provider,label:t.label,host:t.host}:null,launch_profile:n.launch_profile,needs_launch_profile:null===n.launch_profile,session_scope:n.session_scope,default_workspace:n.default_workspace,policy:n.policy,home_session_id:n.home_session_id}}e.s(["LOCAL_HOST",0,E,"hasRegistrationUpdate",0,G,"isLegacyCreate",0,$,"localConnectionId",0,v,"localConnectionLabel",0,h,"migrateRegistration",0,X,"readStoredPolicy",0,U,"readStoredScope",0,b,"registrationColumns",0,W,"serializeRegistration",0,j,"storedLaunchProfile",0,F,"validateConnectionInput",0,function(e){let t=[],n=null;try{(n=(0,a.normalizeAgent)(e.provider))||t.push(I)}catch(e){t.push(e instanceof Error?e.message:String(e))}let i=f(e.label);i?i.length>80&&t.push("Connection name must be 80 characters or fewer."):t.push("Connection name is required.");let r=f(e.host)??E;for(let n of(r.length>80&&t.push("Host must be 80 characters or fewer."),["token","api_key","apiKey","credentials","password","secret"]))void 0!==e[n]&&t.push("Runtime credentials stay with the runtime; a connection stores no secrets.");return!(t.length>0)&&n&&i?{errors:t,fields:{provider:n,label:i,host:r}}:{errors:[...new Set(t)],fields:null}},"validateCreateRegistration",0,function(e,t){let n=[];if($(e)){let i="hermes";try{i=(0,a.normalizeAgent)(e.agent)??"hermes"}catch(e){n.push(e instanceof Error?e.message:String(e))}let r=P(e.deck_id,n);r||0!==n.length||n.push(a.DECK_REQUIRED_ERROR);let s=f(e.working_directory);return n.length>0?{errors:n,registration:null,provider:null}:{errors:n,provider:i,registration:{runtime_connection_id:t.localConnectionFor(i),launch_profile:"agent_deck",deck_id:r,working_directory:s,session_scope:{kind:"workspaces",workspaces:s?[s]:[],sessions:[]},default_workspace:null,policy:{...u},home_session_id:null}}}let i=Y(e,t,n),r=null;void 0===e.launch_profile||null===e.launch_profile||""===e.launch_profile?n.push(T):A(e.launch_profile)?r=e.launch_profile:n.push(p);let s=null,o=null;"direct"===r?(f(e.deck_id)&&n.push(N),f(e.working_directory)&&n.push(R)):"agent_deck"===r&&(s=P(e.deck_id,n),o=f(e.working_directory));let _=H(e.session_scope,n),d=M(e.default_workspace,n),E=B(e.policy,n),c=f(e.home_session_id);if(!i||!r||!_||!E||n.length>0)return{errors:n,registration:null,provider:null};let l={runtime_connection_id:i.id,launch_profile:r,deck_id:s,working_directory:o,session_scope:_,default_workspace:d,policy:E,home_session_id:c};return K(l,null,t,n),n.length>0?{errors:n,registration:null,provider:null}:{errors:n,registration:l,provider:i.provider}},"validateUpdateRegistration",0,function(e,t,n,i){let r=[],s=z(t),o=null;if(void 0!==n.runtime_connection_id)o=Y(n,i,r);else if(void 0!==n.agent)try{let e=(0,a.normalizeAgent)(n.agent);if(e){let t=s.runtime_connection_id?i.getConnection(s.runtime_connection_id):void 0;o=t&&t.provider===e?t:i.getConnection(i.localConnectionFor(e))??null}else r.push(`Agent is required. Expected one of ${a.AGENTS.join("|")}.`)}catch(e){r.push(e instanceof Error?e.message:String(e))}else s.runtime_connection_id?(o=i.getConnection(s.runtime_connection_id)??null)||r.push(l):r.push(c);let _=s.launch_profile;void 0!==n.launch_profile?A(n.launch_profile)?_=n.launch_profile:(r.push(null===n.launch_profile||""===n.launch_profile?T:p),_=null):void 0!==n.deck_id&&"direct"!==_&&(_="agent_deck");let d=s.deck_id,E=s.working_directory;"direct"===_?(void 0!==n.deck_id&&f(n.deck_id)&&r.push(N),void 0!==n.working_directory&&f(n.working_directory)&&r.push(R),d=null,E=null):"agent_deck"===_?(void 0!==n.deck_id?d=P(n.deck_id,r):("agent_deck"!==s.launch_profile||D(t.needs_deck_selection))&&(d=null),void 0!==n.working_directory&&(E=f(n.working_directory))):0===r.length&&r.push(T);let u=void 0!==n.session_scope?H(n.session_scope,r):s.session_scope;void 0!==n.session_scope||u||r.push(m);let L=void 0!==n.default_workspace?M(n.default_workspace,r):s.default_workspace,g=void 0!==n.policy?B(n.policy,r):s.policy;void 0!==n.policy||g||r.push(O);let I=void 0!==n.home_session_id?f(n.home_session_id):s.home_session_id;if(!o||!_||!u||!g||r.length>0)return{errors:r,registration:null,provider:null};let S={runtime_connection_id:o.id,launch_profile:_,deck_id:"agent_deck"===_?d:null,working_directory:"agent_deck"===_?E:null,session_scope:u,default_workspace:L,policy:g,home_session_id:I};return K(S,e,i,r),r.length>0?{errors:r,registration:null,provider:null}:{errors:r,registration:S,provider:o.provider}},"workspaceContains",0,q],18966);var J=e.i(16979);let Q=Object.freeze(["conversation","implementation","review","revision"]),V=Object.freeze(["readonly","edit"]);Object.freeze(["ui","api","wake","continuation","exchange"]);let Z=Object.freeze({conversation:"readonly",implementation:"edit",review:"readonly",revision:"edit"});function ee(e){return"string"==typeof e&&Q.includes(e)}function et(e,t){return{ok:!1,code:e,reason:t}}function en(e){var t,n,i,r;if(!ee(e.executionKind))return et("unknown_execution_kind",`Unknown execution kind ${JSON.stringify(String(e.executionKind))}.`);let s=e.executionKind,a=(t=e.entryPoint,n=s,i=e.wakeSyntax,r=!0===e.resumesWorkRequest,"ui"===t||"api"===t?"conversation"!==n?{code:"unsupported_authority",reason:`A direct message runs as a read-only conversation turn, not ${n}.`}:"direct_message_conversation":"continuation"===t?"conversation"!==n?{code:"unsupported_authority",reason:`A coordinator continuation runs as a read-only conversation turn, not ${n}.`}:"coordinator_continuation":"exchange"===t?"conversation"!==n?{code:"unsupported_authority",reason:`A session exchange runs as a read-only conversation turn, not ${n}.`}:"session_exchange_conversation":"wake"!==t?{code:"unsupported_authority",reason:"Unknown policy entry point."}:"legacy"===i?"conversation"!==n?{code:"unsupported_authority",reason:`A legacy WAKE directive runs as a conversation turn, not ${n}.`}:"legacy_wake_conversation":"structured"!==i?{code:"unsupported_authority",reason:"Unknown Wake syntax."}:"revision"===n!==r?{code:"unsupported_authority",reason:"revision"===n?"A revision names the Work Request it resumes.":"Only a revision resumes a Work Request."}:"structured_wake");return"string"!=typeof a?et(a.code,a.reason):{ok:!0,policy:Object.freeze({policy_version:1,execution_kind:s,tool_profile:Z[s],entry_point:e.entryPoint,rule:a})}}let ei=new Set(["policy_version","execution_kind","tool_profile","entry_point","rule"]);function er(e){if(!e||"object"!=typeof e||Array.isArray(e))return et("malformed_policy","The execution policy snapshot is missing.");let t=Object.keys(e);if(t.length!==ei.size||t.some(e=>!ei.has(e)))return et("malformed_policy","The execution policy snapshot has unexpected fields.");if(1!==e.policy_version)return et("malformed_policy","Unsupported execution policy version.");if(!ee(e.execution_kind))return et("unknown_execution_kind",`Unknown execution kind ${JSON.stringify(String(e.execution_kind))}.`);if(!V.includes(e.tool_profile))return et("unsupported_authority",`Unsupported tool profile ${JSON.stringify(String(e.tool_profile))}.`);if(Z[e.execution_kind]!==e.tool_profile)return et("unsupported_authority",`Execution kind ${e.execution_kind} requires the ${Z[e.execution_kind]} tool profile.`);let n={direct_message_conversation:{entry:["ui","api"],kinds:["conversation"]},legacy_wake_conversation:{entry:["wake"],kinds:["conversation"]},coordinator_continuation:{entry:["continuation"],kinds:["conversation"]},session_exchange_conversation:{entry:["exchange"],kinds:["conversation"]},structured_wake:{entry:["wake"],kinds:[...Q]}},i="string"==typeof e.rule?n[e.rule]:void 0;return i&&i.entry.includes(e.entry_point)?i.kinds.includes(e.execution_kind)?{ok:!0,policy:Object.freeze({...e})}:et("unsupported_authority",`Rule ${e.rule} does not grant ${e.execution_kind}.`):et("malformed_policy","The execution policy rule does not match its entry point.")}e.s(["TOOL_PROFILE_FOR_KIND",0,Z,"authorizeWorkRequest",0,function(e){let t;if(!ee(e.execution_kind))return et("unknown_execution_kind",`Unknown execution kind ${JSON.stringify(String(e.execution_kind))}.`);try{t="string"==typeof e.policy_snapshot?JSON.parse(e.policy_snapshot):null}catch{return et("malformed_policy","The policy snapshot is not valid JSON.")}let n=er(t&&"object"==typeof t&&!Array.isArray(t)?t.execution_policy:void 0);return n.ok?n.policy.execution_kind!==e.execution_kind||n.policy.tool_profile!==e.tool_profile?et("unsupported_authority","The Work Request authority does not match its policy snapshot."):t.tool_profile!==e.tool_profile?et("malformed_policy","The policy snapshot tool profile does not match the Work Request."):n:n},"isExecutionKind",0,ee,"selectExecutionPolicy",0,en,"validateExecutionPolicy",0,er],64974);let es=Object.freeze({max_attempts:1,base_delay_ms:1e3,max_delay_ms:6e4,attempt_timeout_ms:null});function ea(e){if(void 0===e||!/^\d+$/.test(e.trim()))return null;let t=Number(e.trim());return Number.isSafeInteger(t)&&t>0?t:null}function eo(e=process.env){let t=ea(e.BOTMANCERS_RETRY_MAX_ATTEMPTS),n=ea(e.BOTMANCERS_RETRY_BASE_DELAY_MS)??es.base_delay_ms,i=ea(e.BOTMANCERS_RETRY_MAX_DELAY_MS)??es.max_delay_ms,r=e_({max_attempts:null===t?es.max_attempts:Math.min(t,10),base_delay_ms:n,max_delay_ms:Math.max(i,n),attempt_timeout_ms:ea(e.BOTMANCERS_ATTEMPT_TIMEOUT_MS)});return{deadlineMs:ea(e.BOTMANCERS_REQUEST_DEADLINE_MS),retryPolicy:r.ok?r.policy:{...es}}}function e_(e){if(!e||"object"!=typeof e||Array.isArray(e))return{ok:!1,reason:"A retry policy is an object."};let t=e=>"number"==typeof e&&Number.isSafeInteger(e);if(!t(e.max_attempts)||e.max_attempts<1||e.max_attempts>10)return{ok:!1,reason:"max_attempts must be an integer from 1 to 10."};if(!t(e.base_delay_ms)||e.base_delay_ms<0)return{ok:!1,reason:"base_delay_ms must be a non-negative integer."};if(!t(e.max_delay_ms)||e.max_delay_ms<e.base_delay_ms)return{ok:!1,reason:"max_delay_ms must be an integer no smaller than base_delay_ms."};let n=e.attempt_timeout_ms??null;return null!==n&&(!t(n)||n<1)?{ok:!1,reason:"attempt_timeout_ms must be a positive integer or null."}:{ok:!0,policy:{max_attempts:e.max_attempts,base_delay_ms:e.base_delay_ms,max_delay_ms:e.max_delay_ms,attempt_timeout_ms:n}}}let ed=["agent_deck_token_missing","agent_deck_unauthorized","agent_deck_forbidden"],eE={unavailable:"retryable",runtime_failed:"retryable",timed_out:"retryable",launch_failed:"terminal",unsupported_authority:"terminal",result_contract:"terminal",cancelled:"terminal",session_mismatch:"manual_attention"};e.s(["DEFAULT_RETRY_POLICY",0,es,"attemptDeadline",0,function(e,t,n){let i=null===e.attempt_timeout_ms?null:n+e.attempt_timeout_ms;return null===i?t:null===t?i:Math.min(i,t)},"classifyFailure",0,function(e,t=null){return t&&ed.includes(t)?"manual_attention":eE[e??"runtime_failed"]??"terminal"},"decideRetry",0,function(e){var t;let n;if("terminal"===e.disposition)return{action:"fail",disposition:"terminal"};let i=e.attemptCount<e.policy.max_attempts;if("manual_attention"===e.disposition)return i?{action:"attention"}:{action:"fail",disposition:"terminal"};if(!i)return{action:"exhausted"};let r=e.attemptCount,s=(t=e.policy,n=Math.max(0,r-1),Math.min(t.max_delay_ms,t.base_delay_ms*2**Math.min(n,30))),a=e.now+s;return null!==e.deadlineAt&&a>=e.deadlineAt?{action:"deadline"}:{action:"retry",nextEligibleAt:a,delayMs:s,retry:r}},"requestControlDefaultsFromEnv",0,eo,"storedRetryPolicy",0,function(e){if(!e)return{...es};try{let t=e_(JSON.parse(e));return t.ok?t.policy:{...es}}catch{return{...es}}},"validateRetryPolicy",0,e_],11626);let eu={cached_input_tokens:"cached_input_tokens",cachedInputTokens:"cached_input_tokens",cache_read_input_tokens:"cache_read_input_tokens",cacheReadInputTokens:"cache_read_input_tokens",cacheReadTokens:"cache_read_input_tokens",cache_creation_input_tokens:"cache_creation_input_tokens",cacheCreationInputTokens:"cache_creation_input_tokens",cacheWriteTokens:"cache_creation_input_tokens",reasoning_output_tokens:"reasoning_output_tokens",reasoningOutputTokens:"reasoning_output_tokens",reasoningTokens:"reasoning_output_tokens"};function ec(e){return null===e||"object"!=typeof e||Array.isArray(e)?null:e}function el(e){return"number"==typeof e&&Number.isInteger(e)&&e>=0&&e<=Number.MAX_SAFE_INTEGER?e:null}function eT(e){return"number"==typeof e&&Number.isFinite(e)&&e>=0&&e<1e9?e:null}function ep(e,t,n){for(let i of t)if(i in e){let t=n(e[i]);if(null!==t)return t}return null}function eN(e,t,n){let i=e?ep(e,["input_tokens","inputTokens"],el):null,r=e?ep(e,["output_tokens","outputTokens"],el):null;return null===i&&null===r&&null===t?null:{input_tokens:i,output_tokens:r,cost_usd:t,source:n,breakdown:e?function(e){let t={};for(let[n,i]of Object.entries(eu)){let r=el(e[n]);null!==r&&void 0===t[i]&&(t[i]=r)}return Object.keys(t).length>0?t:null}(e):null}}function eR(e){let t=ec(e);if(!t)return null;let n="string"==typeof t.type?t.type:null,i=ec(t.usage);if("turn.completed"===n)return eN(i,null,"codex.turn_completed");if("result"===n)return eN(i,ep(t,["total_cost_usd","totalCostUsd","cost_usd","costUsd"],eT),"result");if(null===n||"usage"===n){let e=i??t,n=ep(e,["cost_usd","costUsd","total_cost_usd","totalCostUsd"],eT)??(i?ep(t,["cost_usd","costUsd","total_cost_usd","totalCostUsd"],eT):null);return eN(e,n,"normalized")}return null}function em(e,t){return null===e?t:null===t?e:e+t}function eL(e){let t=ec(e);if(!t)return null;let n="codex.turn_completed"===t.source||"result"===t.source||"normalized"===t.source?t.source:"normalized",i=el(t.input_tokens),r=el(t.output_tokens),s=eT(t.cost_usd);if(null===i&&null===r&&null===s)return null;let a=ec(t.breakdown),o={};if(a)for(let e of new Set(Object.values(eu))){let t=el(a[e]);null!==t&&(o[e]=t)}return{input_tokens:i,output_tokens:r,cost_usd:s,source:n,breakdown:Object.keys(o).length>0?o:null}}function eg(e){let t=t=>{var n,i;let r=null,s=0;for(let n of e){let e=n[t];null!=e&&(s++,r=(r??0)+e)}return null!==r&&"cost_usd"===t&&(r=Math.round(1e6*r)/1e6),{sum:r,known:s,total:e.length,quality:(n=s,0===(i=e.length)||0===n?"unavailable":n===i?"complete":"partial")}};return{input_tokens:t("input_tokens"),output_tokens:t("output_tokens"),cost_usd:t("cost_usd")}}function eO(e){return!!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'usage_samples'").get()}function eI(e,t,n,i){if(!eO(e))return;let r=eL(i.usage),a=i.now??Date.now();e.prepare(`
2
+ INSERT INTO usage_samples (
3
+ id, sample_key, agent_id, attempt_id, session_ref, turn_id, provider, source,
4
+ input_tokens, output_tokens, cost_usd, breakdown, observed_at, created_at, updated_at
5
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
6
+ ON CONFLICT(sample_key) DO UPDATE SET
7
+ input_tokens = COALESCE(usage_samples.input_tokens, excluded.input_tokens),
8
+ output_tokens = COALESCE(usage_samples.output_tokens, excluded.output_tokens),
9
+ cost_usd = COALESCE(usage_samples.cost_usd, excluded.cost_usd),
10
+ breakdown = COALESCE(usage_samples.breakdown, excluded.breakdown),
11
+ source = CASE WHEN usage_samples.source = 'none' THEN excluded.source ELSE usage_samples.source END,
12
+ updated_at = CASE
13
+ WHEN (usage_samples.input_tokens IS NULL AND excluded.input_tokens IS NOT NULL)
14
+ OR (usage_samples.output_tokens IS NULL AND excluded.output_tokens IS NOT NULL)
15
+ OR (usage_samples.cost_usd IS NULL AND excluded.cost_usd IS NOT NULL)
16
+ THEN excluded.updated_at ELSE usage_samples.updated_at END
17
+ `).run((0,s.randomUUID)(),t,i.agentId,n.attemptId,n.sessionRef,n.turnId,String(i.provider).slice(0,100),r?.source??"none",r?.input_tokens??null,r?.output_tokens??null,r?.cost_usd??null,r?.breakdown?JSON.stringify(r.breakdown):null,i.observedAt,a,a)}function eA(e,t,n){eI(e,`attempt:${t}`,{attemptId:t,sessionRef:null,turnId:null},n)}function eS(e,t,n){if(!eO(e))return[];let i=null===n?"":"AND b.id = ?",r=null===n?"":"AND s.session_ref = ?";return e.prepare(`
18
+ SELECT b.id AS ref, 'attempt' AS kind, a.attempt_number, a.kind AS turn_kind, s.provider, s.source,
19
+ s.input_tokens, s.output_tokens, s.cost_usd, s.observed_at, s.sample_key
20
+ FROM session_bindings b
21
+ JOIN work_attempts a ON a.id = b.source_attempt_id
22
+ JOIN usage_samples s ON s.attempt_id = a.id
23
+ WHERE b.agent_id = ? ${i}
24
+ UNION ALL
25
+ SELECT b.id AS ref, 'attempt' AS kind, a.attempt_number, a.kind AS turn_kind, s.provider, s.source,
26
+ s.input_tokens, s.output_tokens, s.cost_usd, s.observed_at, s.sample_key
27
+ FROM session_bindings b
28
+ JOIN work_attempts a ON a.resumed_session_binding_id = b.id AND a.id IS NOT b.source_attempt_id
29
+ JOIN usage_samples s ON s.attempt_id = a.id
30
+ WHERE b.agent_id = ? ${i}
31
+ UNION ALL
32
+ SELECT s.session_ref AS ref, 'turn' AS kind, NULL AS attempt_number, t.kind AS turn_kind, s.provider, s.source,
33
+ s.input_tokens, s.output_tokens, s.cost_usd, s.observed_at, s.sample_key
34
+ FROM usage_samples s
35
+ LEFT JOIN provider_session_turns t ON t.id = s.turn_id
36
+ WHERE s.agent_id = ? AND s.turn_id IS NOT NULL ${r}
37
+ ORDER BY observed_at ASC, sample_key ASC
38
+ `).all(...null===n?[t,t,t]:[t,n,t,n,t,n])}function ek(e){return{kind:e.kind,attempt_number:e.attempt_number,turn_kind:e.turn_kind,provider:e.provider,source:e.source,input_tokens:e.input_tokens,output_tokens:e.output_tokens,cost_usd:e.cost_usd,observed_at:e.observed_at}}e.s(["aggregateUsage",0,eg,"normalizeUsage",0,eL,"usageFromEvent",0,eR,"usageFromEvents",0,function(e){if(!e)return null;let t=null,n=null,i=null,r=new Set;for(let s of e){let e=ec(s),a=e&&("number"==typeof e.seq||"string"==typeof e.id)?`${e.type}:${e.seq??e.id}`:null;if(a){if(r.has(a))continue;r.add(a)}let o=eR(s);o&&("result"===o.source?t=o:"codex.turn_completed"===o.source?n=null===n?o:{input_tokens:em(n.input_tokens,o.input_tokens),output_tokens:em(n.output_tokens,o.output_tokens),cost_usd:null,source:"codex.turn_completed",breakdown:function(e,t){if(!e)return t;if(!t)return e;let n={...e};for(let[e,i]of Object.entries(t))n[e]=(n[e]??0)+i;return n}(n.breakdown,o.breakdown)}:i=o)}return t??n??i}],40596),e.s(["agentSessionUsage",0,function(e,t){let n=new Map;for(let i of eS(e,t,null)){let e=n.get(i.ref)??[];e.push(i),n.set(i.ref,e)}return new Map([...n].map(([e,t])=>[e,eg(t)]))},"emptyUsage",0,function(){return eg([])},"recordAttemptUsageSample",0,eA,"recordTurnUsageSample",0,function(e,t,n,i){eI(e,`turn:${t}`,{attemptId:null,sessionRef:n,turnId:t},i)},"sessionUsageSamples",0,function(e,t,n){let i=eS(e,t,n);return{usage:eg(i),samples:i.map(ek)}}],28420);let ef=["queued","extracting","delivering","completed","failed","cancelled"],ev=["completed","failed","cancelled"],eh={queued:["extracting","failed","cancelled"],extracting:["delivering","completed","failed","cancelled"],delivering:["completed","failed","cancelled"],completed:[],failed:[],cancelled:[]},ew=Object.freeze({instructionChars:4e3,packetChars:16e3,packetObjectiveChars:2e3,packetListItems:20,packetItemChars:500,answerChars:16e3,replyChars:16e3,extractionOutputChars:32e3,promptChars:24e3}),eC=["queued","blocked","running","waiting","completed","failed","cancelled"],eq=["completed","failed","cancelled"],ey={queued:["running","blocked","cancelled","failed"],blocked:["queued","cancelled","failed"],running:["waiting","queued","completed","failed","cancelled"],waiting:["running","queued","cancelled","failed"],completed:[],failed:[],cancelled:[]},eb=["dispatcher","ui_message","ui_continuation"];class eD extends Error{code;constructor(e,t){super(t),this.code=e}}let eU=eq.map(e=>`'${e}'`).join(", "),eF=eC.map(e=>`'${e}'`).join(", "),eW=[{version:1,name:"core_engine_tables",up:e=>{e.exec(`
39
+ CREATE TABLE work_request_transitions (
40
+ from_state TEXT NOT NULL,
41
+ to_state TEXT NOT NULL,
42
+ PRIMARY KEY (from_state, to_state)
43
+ );
44
+
45
+ CREATE TABLE work_requests (
46
+ id TEXT PRIMARY KEY,
47
+ source_conversation_id TEXT NOT NULL,
48
+ source_event_id TEXT NOT NULL,
49
+ requester_kind TEXT NOT NULL CHECK (requester_kind IN ('person', 'bot', 'service')),
50
+ requester_id TEXT NOT NULL,
51
+ target_agent_id TEXT NOT NULL,
52
+ intent TEXT NOT NULL,
53
+ execution_kind TEXT NOT NULL CHECK (execution_kind IN ('conversation', 'implementation', 'review', 'revision')),
54
+ tool_profile TEXT NOT NULL CHECK (tool_profile IN ('readonly', 'edit')),
55
+ parent_request_id TEXT,
56
+ root_request_id TEXT NOT NULL,
57
+ wake_event_id TEXT,
58
+ depth INTEGER NOT NULL DEFAULT 0 CHECK (depth >= 0),
59
+ idempotency_key TEXT NOT NULL CHECK (length(idempotency_key) > 0),
60
+ request_hash TEXT NOT NULL,
61
+ policy_snapshot TEXT NOT NULL,
62
+ state TEXT NOT NULL CHECK (state IN (${eF})),
63
+ state_reason TEXT,
64
+ result TEXT,
65
+ error_code TEXT,
66
+ error_message TEXT,
67
+ version INTEGER NOT NULL DEFAULT 0,
68
+ legacy_agent_request_id TEXT UNIQUE,
69
+ created_at INTEGER NOT NULL,
70
+ updated_at INTEGER NOT NULL,
71
+ terminal_at INTEGER,
72
+ CHECK ((state IN (${eU})) = (terminal_at IS NOT NULL)),
73
+ FOREIGN KEY (source_conversation_id) REFERENCES conversations(id),
74
+ FOREIGN KEY (target_agent_id) REFERENCES bots(id),
75
+ FOREIGN KEY (parent_request_id) REFERENCES work_requests(id),
76
+ FOREIGN KEY (root_request_id) REFERENCES work_requests(id)
77
+ );
78
+
79
+ CREATE UNIQUE INDEX idx_work_requests_idempotency
80
+ ON work_requests(requester_kind, requester_id, idempotency_key);
81
+ CREATE INDEX idx_work_requests_conversation
82
+ ON work_requests(source_conversation_id, created_at);
83
+ CREATE INDEX idx_work_requests_state
84
+ ON work_requests(state, created_at);
85
+ CREATE INDEX idx_work_requests_parent
86
+ ON work_requests(parent_request_id) WHERE parent_request_id IS NOT NULL;
87
+
88
+ CREATE TABLE session_bindings (
89
+ id TEXT PRIMARY KEY,
90
+ agent_id TEXT NOT NULL,
91
+ adapter TEXT NOT NULL,
92
+ conversation_id TEXT,
93
+ request_id TEXT,
94
+ external_session_id TEXT NOT NULL,
95
+ source_attempt_id TEXT,
96
+ created_at INTEGER NOT NULL,
97
+ released_at INTEGER,
98
+ CHECK (conversation_id IS NOT NULL OR request_id IS NOT NULL),
99
+ FOREIGN KEY (agent_id) REFERENCES bots(id),
100
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id),
101
+ FOREIGN KEY (request_id) REFERENCES work_requests(id),
102
+ FOREIGN KEY (source_attempt_id) REFERENCES work_attempts(id)
103
+ );
104
+
105
+ CREATE UNIQUE INDEX idx_session_bindings_active
106
+ ON session_bindings(agent_id, adapter, IFNULL(conversation_id, ''), IFNULL(request_id, ''))
107
+ WHERE released_at IS NULL;
108
+
109
+ CREATE TABLE work_attempts (
110
+ id TEXT PRIMARY KEY,
111
+ request_id TEXT NOT NULL,
112
+ attempt_number INTEGER NOT NULL CHECK (attempt_number >= 1),
113
+ kind TEXT NOT NULL CHECK (kind IN ('launch', 'resume')),
114
+ adapter TEXT NOT NULL CHECK (length(adapter) > 0),
115
+ tool_profile TEXT NOT NULL CHECK (tool_profile IN ('readonly', 'edit')),
116
+ launch_snapshot TEXT NOT NULL,
117
+ launch_snapshot_hash TEXT NOT NULL,
118
+ resumed_session_binding_id TEXT,
119
+ external_run_id TEXT,
120
+ external_session_id TEXT,
121
+ outcome TEXT CHECK (outcome IN ('succeeded', 'failed', 'cancelled', 'interrupted', 'timed_out')),
122
+ error_category TEXT,
123
+ error_message TEXT,
124
+ artifacts TEXT NOT NULL DEFAULT '[]',
125
+ started_at INTEGER NOT NULL,
126
+ finished_at INTEGER,
127
+ CHECK ((outcome IS NULL) = (finished_at IS NULL)),
128
+ CHECK ((kind = 'resume') = (resumed_session_binding_id IS NOT NULL)),
129
+ UNIQUE (request_id, attempt_number),
130
+ FOREIGN KEY (request_id) REFERENCES work_requests(id),
131
+ FOREIGN KEY (resumed_session_binding_id) REFERENCES session_bindings(id)
132
+ );
133
+
134
+ CREATE UNIQUE INDEX idx_work_attempts_open
135
+ ON work_attempts(request_id) WHERE finished_at IS NULL;
136
+
137
+ CREATE TABLE engine_events (
138
+ id TEXT PRIMARY KEY,
139
+ request_id TEXT NOT NULL,
140
+ sequence INTEGER NOT NULL CHECK (sequence >= 1),
141
+ attempt_id TEXT,
142
+ type TEXT NOT NULL CHECK (length(type) > 0),
143
+ data TEXT,
144
+ created_at INTEGER NOT NULL,
145
+ UNIQUE (request_id, sequence),
146
+ FOREIGN KEY (request_id) REFERENCES work_requests(id),
147
+ FOREIGN KEY (attempt_id) REFERENCES work_attempts(id)
148
+ );
149
+
150
+ -- Foreign keys (insert/update side).
151
+ CREATE TRIGGER trg_work_requests_fk_insert BEFORE INSERT ON work_requests
152
+ BEGIN
153
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_requests.source_conversation_id')
154
+ WHERE NOT EXISTS (SELECT 1 FROM conversations WHERE id = NEW.source_conversation_id);
155
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_requests.target_agent_id')
156
+ WHERE NOT EXISTS (SELECT 1 FROM bots WHERE id = NEW.target_agent_id);
157
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_requests.parent_request_id')
158
+ WHERE NEW.parent_request_id IS NOT NULL
159
+ AND NOT EXISTS (SELECT 1 FROM work_requests WHERE id = NEW.parent_request_id);
160
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_requests.root_request_id')
161
+ WHERE NEW.root_request_id <> NEW.id
162
+ AND NOT EXISTS (SELECT 1 FROM work_requests WHERE id = NEW.root_request_id);
163
+ END;
164
+
165
+ -- Identity, lineage, and policy are fixed at intake.
166
+ CREATE TRIGGER trg_work_requests_immutable BEFORE UPDATE OF
167
+ id, source_conversation_id, source_event_id, requester_kind, requester_id,
168
+ target_agent_id, intent, execution_kind, tool_profile, parent_request_id,
169
+ root_request_id, wake_event_id, depth, idempotency_key, request_hash,
170
+ policy_snapshot, legacy_agent_request_id, created_at
171
+ ON work_requests
172
+ BEGIN
173
+ SELECT RAISE(ABORT, 'work_requests identity, lineage, and policy are immutable');
174
+ END;
175
+
176
+ CREATE TRIGGER trg_work_requests_transition BEFORE UPDATE OF state ON work_requests
177
+ WHEN NEW.state <> OLD.state
178
+ BEGIN
179
+ SELECT RAISE(ABORT, 'invalid work_requests state transition')
180
+ WHERE NOT EXISTS (
181
+ SELECT 1 FROM work_request_transitions WHERE from_state = OLD.state AND to_state = NEW.state
182
+ );
183
+ END;
184
+
185
+ CREATE TRIGGER trg_work_requests_terminal BEFORE UPDATE ON work_requests
186
+ WHEN OLD.state IN (${eU})
187
+ BEGIN
188
+ SELECT RAISE(ABORT, 'terminal work_requests are immutable');
189
+ END;
190
+
191
+ CREATE TRIGGER trg_session_bindings_fk BEFORE INSERT ON session_bindings
192
+ BEGIN
193
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_bindings.conversation_id')
194
+ WHERE NEW.conversation_id IS NOT NULL
195
+ AND NOT EXISTS (SELECT 1 FROM conversations WHERE id = NEW.conversation_id);
196
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_bindings.request_id')
197
+ WHERE NEW.request_id IS NOT NULL
198
+ AND NOT EXISTS (SELECT 1 FROM work_requests WHERE id = NEW.request_id);
199
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_bindings.source_attempt_id')
200
+ WHERE NEW.source_attempt_id IS NOT NULL
201
+ AND NOT EXISTS (SELECT 1 FROM work_attempts WHERE id = NEW.source_attempt_id);
202
+ END;
203
+
204
+ -- A binding's session value is opaque and never rewritten; only
205
+ -- release (supersession) may change.
206
+ CREATE TRIGGER trg_session_bindings_immutable BEFORE UPDATE OF
207
+ id, agent_id, adapter, conversation_id, request_id, external_session_id, source_attempt_id, created_at
208
+ ON session_bindings
209
+ BEGIN
210
+ SELECT RAISE(ABORT, 'session_bindings are immutable');
211
+ END;
212
+
213
+ CREATE TRIGGER trg_work_attempts_fk BEFORE INSERT ON work_attempts
214
+ BEGIN
215
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_attempts.request_id')
216
+ WHERE NOT EXISTS (SELECT 1 FROM work_requests WHERE id = NEW.request_id);
217
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_attempts.resumed_session_binding_id')
218
+ WHERE NEW.resumed_session_binding_id IS NOT NULL
219
+ AND NOT EXISTS (SELECT 1 FROM session_bindings WHERE id = NEW.resumed_session_binding_id);
220
+ END;
221
+
222
+ -- Launch snapshot and authority never change after insert.
223
+ CREATE TRIGGER trg_work_attempts_immutable BEFORE UPDATE OF
224
+ id, request_id, attempt_number, kind, adapter, tool_profile,
225
+ launch_snapshot, launch_snapshot_hash, resumed_session_binding_id, started_at
226
+ ON work_attempts
227
+ BEGIN
228
+ SELECT RAISE(ABORT, 'work_attempts launch fields are immutable');
229
+ END;
230
+
231
+ -- External identifiers are recorded once, never rewritten.
232
+ CREATE TRIGGER trg_work_attempts_external_ids BEFORE UPDATE OF external_run_id, external_session_id ON work_attempts
233
+ WHEN (OLD.external_run_id IS NOT NULL AND NEW.external_run_id IS NOT OLD.external_run_id)
234
+ OR (OLD.external_session_id IS NOT NULL AND NEW.external_session_id IS NOT OLD.external_session_id)
235
+ BEGIN
236
+ SELECT RAISE(ABORT, 'work_attempts external identifiers are set once');
237
+ END;
238
+
239
+ CREATE TRIGGER trg_work_attempts_finished BEFORE UPDATE ON work_attempts
240
+ WHEN OLD.finished_at IS NOT NULL
241
+ BEGIN
242
+ SELECT RAISE(ABORT, 'finished work_attempts are immutable');
243
+ END;
244
+
245
+ CREATE TRIGGER trg_engine_events_fk BEFORE INSERT ON engine_events
246
+ BEGIN
247
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: engine_events.request_id')
248
+ WHERE NOT EXISTS (SELECT 1 FROM work_requests WHERE id = NEW.request_id);
249
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: engine_events.attempt_id')
250
+ WHERE NEW.attempt_id IS NOT NULL
251
+ AND NOT EXISTS (SELECT 1 FROM work_attempts WHERE id = NEW.attempt_id AND request_id = NEW.request_id);
252
+ END;
253
+
254
+ CREATE TRIGGER trg_engine_events_append_only BEFORE UPDATE ON engine_events
255
+ BEGIN
256
+ SELECT RAISE(ABORT, 'engine_events are append-only');
257
+ END;
258
+ `);let t=e.prepare("INSERT INTO work_request_transitions (from_state, to_state) VALUES (?, ?)");for(let e of eC)for(let n of ey[e])t.run(e,n)}},{version:2,name:"core_engine_referential_integrity",up:e=>{e.exec(`
259
+ -- Foreign keys (delete side): RESTRICT. A referenced row cannot be
260
+ -- deleted while anything still points at it; deleteEngineRecords
261
+ -- removes dependants first, in one transaction.
262
+ CREATE TRIGGER trg_conversations_engine_restrict BEFORE DELETE ON conversations
263
+ BEGIN
264
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_requests.source_conversation_id')
265
+ WHERE EXISTS (SELECT 1 FROM work_requests WHERE source_conversation_id = OLD.id);
266
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_bindings.conversation_id')
267
+ WHERE EXISTS (SELECT 1 FROM session_bindings WHERE conversation_id = OLD.id);
268
+ END;
269
+
270
+ CREATE TRIGGER trg_bots_engine_restrict BEFORE DELETE ON bots
271
+ BEGIN
272
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_requests.target_agent_id')
273
+ WHERE EXISTS (SELECT 1 FROM work_requests WHERE target_agent_id = OLD.id);
274
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_bindings.agent_id')
275
+ WHERE EXISTS (SELECT 1 FROM session_bindings WHERE agent_id = OLD.id);
276
+ END;
277
+
278
+ CREATE TRIGGER trg_work_requests_restrict BEFORE DELETE ON work_requests
279
+ BEGIN
280
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_requests.parent_request_id')
281
+ WHERE EXISTS (
282
+ SELECT 1 FROM work_requests
283
+ WHERE id <> OLD.id AND (parent_request_id = OLD.id OR root_request_id = OLD.id)
284
+ );
285
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_attempts.request_id')
286
+ WHERE EXISTS (SELECT 1 FROM work_attempts WHERE request_id = OLD.id);
287
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: engine_events.request_id')
288
+ WHERE EXISTS (SELECT 1 FROM engine_events WHERE request_id = OLD.id);
289
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_bindings.request_id')
290
+ WHERE EXISTS (SELECT 1 FROM session_bindings WHERE request_id = OLD.id);
291
+ END;
292
+
293
+ CREATE TRIGGER trg_work_attempts_restrict BEFORE DELETE ON work_attempts
294
+ BEGIN
295
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: engine_events.attempt_id')
296
+ WHERE EXISTS (SELECT 1 FROM engine_events WHERE attempt_id = OLD.id);
297
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_bindings.source_attempt_id')
298
+ WHERE EXISTS (SELECT 1 FROM session_bindings WHERE source_attempt_id = OLD.id);
299
+ END;
300
+
301
+ CREATE TRIGGER trg_session_bindings_restrict BEFORE DELETE ON session_bindings
302
+ BEGIN
303
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_attempts.resumed_session_binding_id')
304
+ WHERE EXISTS (SELECT 1 FROM work_attempts WHERE resumed_session_binding_id = OLD.id);
305
+ END;
306
+
307
+ -- Session continuity: a binding belongs to one Agent and adapter in
308
+ -- one scope, and its source attempt must come from that scope.
309
+ CREATE TRIGGER trg_session_bindings_scope BEFORE INSERT ON session_bindings
310
+ BEGIN
311
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_bindings.agent_id')
312
+ WHERE NOT EXISTS (SELECT 1 FROM bots WHERE id = NEW.agent_id);
313
+ SELECT RAISE(ABORT, 'session binding does not match its work request')
314
+ WHERE NEW.request_id IS NOT NULL AND NOT EXISTS (
315
+ SELECT 1 FROM work_requests r
316
+ WHERE r.id = NEW.request_id AND r.target_agent_id = NEW.agent_id
317
+ AND (NEW.conversation_id IS NULL OR r.source_conversation_id = NEW.conversation_id)
318
+ );
319
+ SELECT RAISE(ABORT, 'session binding does not match its source attempt')
320
+ WHERE NEW.source_attempt_id IS NOT NULL AND NOT EXISTS (
321
+ SELECT 1 FROM work_attempts a JOIN work_requests r ON r.id = a.request_id
322
+ WHERE a.id = NEW.source_attempt_id AND a.adapter = NEW.adapter AND r.target_agent_id = NEW.agent_id
323
+ AND (NEW.request_id IS NULL OR a.request_id = NEW.request_id)
324
+ AND (NEW.conversation_id IS NULL OR r.source_conversation_id = NEW.conversation_id)
325
+ );
326
+ END;
327
+
328
+ -- A resume continues an active binding of the same Agent and
329
+ -- adapter, from the same conversation and request lineage.
330
+ CREATE TRIGGER trg_work_attempts_resume_scope BEFORE INSERT ON work_attempts
331
+ WHEN NEW.resumed_session_binding_id IS NOT NULL
332
+ BEGIN
333
+ SELECT RAISE(ABORT, 'resumed session binding does not match the work request')
334
+ WHERE NOT EXISTS (
335
+ SELECT 1 FROM session_bindings b
336
+ JOIN work_requests r ON r.id = NEW.request_id
337
+ LEFT JOIN work_requests br ON br.id = b.request_id
338
+ WHERE b.id = NEW.resumed_session_binding_id AND b.released_at IS NULL
339
+ AND b.agent_id = r.target_agent_id AND b.adapter = NEW.adapter
340
+ AND (b.conversation_id IS NULL OR b.conversation_id = r.source_conversation_id)
341
+ AND (b.request_id IS NULL OR br.root_request_id = r.root_request_id)
342
+ );
343
+ END;
344
+ `)}},{version:3,name:"core_engine_hardening",up:e=>{let t=eC.flatMap(e=>ey[e].map(t=>`'${e}>${t}'`)).join(", ");e.exec(`
345
+ -- The lifecycle allowlist lives in the trigger itself, so no data
346
+ -- write can widen or break it. work_request_transitions stays as a
347
+ -- readable copy and is locked against writes.
348
+ DROP TRIGGER trg_work_requests_transition;
349
+ CREATE TRIGGER trg_work_requests_transition BEFORE UPDATE OF state ON work_requests
350
+ WHEN NEW.state <> OLD.state
351
+ BEGIN
352
+ SELECT RAISE(ABORT, 'invalid work_requests state transition')
353
+ WHERE (OLD.state || '>' || NEW.state) NOT IN (${t});
354
+ END;
355
+
356
+ CREATE TRIGGER trg_work_request_transitions_insert BEFORE INSERT ON work_request_transitions
357
+ BEGIN
358
+ SELECT RAISE(ABORT, 'work_request_transitions is read-only');
359
+ END;
360
+ CREATE TRIGGER trg_work_request_transitions_update BEFORE UPDATE ON work_request_transitions
361
+ BEGIN
362
+ SELECT RAISE(ABORT, 'work_request_transitions is read-only');
363
+ END;
364
+ CREATE TRIGGER trg_work_request_transitions_delete BEFORE DELETE ON work_request_transitions
365
+ BEGIN
366
+ SELECT RAISE(ABORT, 'work_request_transitions is read-only');
367
+ END;
368
+
369
+ -- Engine events are never deleted one by one. Aggregate cleanup
370
+ -- (deleteEngineRecords) first marks the requests it removes in
371
+ -- engine_event_purges; only events of a marked request may go.
372
+ CREATE TABLE engine_event_purges (
373
+ request_id TEXT PRIMARY KEY
374
+ );
375
+ CREATE TRIGGER trg_engine_events_no_delete BEFORE DELETE ON engine_events
376
+ BEGIN
377
+ SELECT RAISE(ABORT, 'engine_events are append-only')
378
+ WHERE NOT EXISTS (SELECT 1 FROM engine_event_purges WHERE request_id = OLD.request_id);
379
+ END;
380
+
381
+ -- Foreign keys (parent-key update side): RESTRICT.
382
+ CREATE TRIGGER trg_conversations_engine_restrict_update BEFORE UPDATE OF id ON conversations
383
+ WHEN NEW.id IS NOT OLD.id
384
+ BEGIN
385
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_requests.source_conversation_id')
386
+ WHERE EXISTS (SELECT 1 FROM work_requests WHERE source_conversation_id = OLD.id);
387
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_bindings.conversation_id')
388
+ WHERE EXISTS (SELECT 1 FROM session_bindings WHERE conversation_id = OLD.id);
389
+ END;
390
+
391
+ CREATE TRIGGER trg_bots_engine_restrict_update BEFORE UPDATE OF id ON bots
392
+ WHEN NEW.id IS NOT OLD.id
393
+ BEGIN
394
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: work_requests.target_agent_id')
395
+ WHERE EXISTS (SELECT 1 FROM work_requests WHERE target_agent_id = OLD.id);
396
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_bindings.agent_id')
397
+ WHERE EXISTS (SELECT 1 FROM session_bindings WHERE agent_id = OLD.id);
398
+ END;
399
+
400
+ -- Attempt kind and continuity agree: only a resume names a binding.
401
+ -- (Fresh schemas also carry this as a CHECK.)
402
+ CREATE TRIGGER trg_work_attempts_kind BEFORE INSERT ON work_attempts
403
+ WHEN (NEW.kind = 'resume') <> (NEW.resumed_session_binding_id IS NOT NULL)
404
+ BEGIN
405
+ SELECT RAISE(ABORT, 'work_attempts kind does not match resumed_session_binding_id');
406
+ END;
407
+ `)}},{version:4,name:"engine_event_purge_authority",up:e=>{e.exec(`
408
+ -- Purge authority no longer lives in data: any writer could insert
409
+ -- an engine_event_purges row and then delete single events. The
410
+ -- guard now asks engine_event_purge_authorized(), a connection
411
+ -- function that is true only while deleteEngineRecords removes that
412
+ -- request whole. Connections without it cannot delete events.
413
+ DROP TRIGGER trg_engine_events_no_delete;
414
+ DROP TABLE engine_event_purges;
415
+ CREATE TRIGGER trg_engine_events_no_delete BEFORE DELETE ON engine_events
416
+ BEGIN
417
+ SELECT RAISE(ABORT, 'engine_events are append-only')
418
+ WHERE NOT engine_event_purge_authorized(OLD.request_id);
419
+ END;
420
+ `)}},{version:5,name:"conversation_intakes",up:e=>{e.exec(`
421
+ -- NOT-465: one row per accepted conversation message, keyed by the
422
+ -- requester's idempotency key. It names the source event (message)
423
+ -- and the Work Requests created from it, so an exact retry replays
424
+ -- the original identifiers whether or not any request was created.
425
+ CREATE TABLE conversation_intakes (
426
+ requester_kind TEXT NOT NULL CHECK (requester_kind IN ('person', 'bot', 'service')),
427
+ requester_id TEXT NOT NULL,
428
+ idempotency_key TEXT NOT NULL CHECK (length(idempotency_key) > 0),
429
+ request_hash TEXT NOT NULL,
430
+ surface TEXT NOT NULL CHECK (surface IN ('ui', 'api')),
431
+ conversation_id TEXT NOT NULL,
432
+ source_event_id TEXT NOT NULL,
433
+ work_request_ids TEXT NOT NULL DEFAULT '[]',
434
+ created_at INTEGER NOT NULL,
435
+ PRIMARY KEY (requester_kind, requester_id, idempotency_key)
436
+ );
437
+ CREATE INDEX idx_conversation_intakes_conversation ON conversation_intakes(conversation_id);
438
+ `)}},{version:6,name:"attempt_output",up:e=>{e.exec(`
439
+ -- NOT-467: the runtime output an Attempt returned, recorded with
440
+ -- its terminal outcome (null while open or when none was returned).
441
+ ALTER TABLE work_attempts ADD COLUMN output TEXT;
442
+ `)}},{version:7,name:"wakes",up:e=>{e.exec(`
443
+ -- NOT-466: one row per Wake found in an Agent reply (lib/wake-router).
444
+ -- Every Wake is kept, including ones whose target is missing or
445
+ -- whose envelope is invalid, so nothing is silently dropped. An
446
+ -- accepted or blocked Wake names its one Work Request. Lineage is
447
+ -- durable: parent/root request and root Wake, never process memory.
448
+ CREATE TABLE wakes (
449
+ id TEXT PRIMARY KEY,
450
+ idempotency_key TEXT NOT NULL UNIQUE CHECK (length(idempotency_key) > 0),
451
+ source_conversation_id TEXT NOT NULL,
452
+ source_event_id TEXT NOT NULL,
453
+ position INTEGER NOT NULL CHECK (position >= 0),
454
+ syntax TEXT NOT NULL CHECK (syntax IN ('structured', 'legacy')),
455
+ payload TEXT NOT NULL,
456
+ requester_agent_id TEXT NOT NULL,
457
+ requested_target TEXT,
458
+ target_agent_id TEXT,
459
+ target_name_snapshot TEXT,
460
+ execution_kind TEXT CHECK (execution_kind IN ('conversation', 'implementation', 'review', 'revision')),
461
+ parent_request_id TEXT,
462
+ root_request_id TEXT,
463
+ root_wake_id TEXT NOT NULL,
464
+ depth INTEGER NOT NULL CHECK (depth >= 0),
465
+ status TEXT NOT NULL CHECK (status IN ('accepted', 'blocked', 'unavailable', 'rejected')),
466
+ reason_code TEXT,
467
+ reason TEXT,
468
+ work_request_id TEXT UNIQUE,
469
+ created_at INTEGER NOT NULL,
470
+ updated_at INTEGER NOT NULL,
471
+ UNIQUE (source_event_id, position),
472
+ CHECK ((status IN ('accepted', 'blocked')) = (work_request_id IS NOT NULL)),
473
+ CHECK (status = 'accepted' OR reason_code IS NOT NULL),
474
+ FOREIGN KEY (source_conversation_id) REFERENCES conversations(id),
475
+ FOREIGN KEY (work_request_id) REFERENCES work_requests(id),
476
+ FOREIGN KEY (parent_request_id) REFERENCES work_requests(id)
477
+ );
478
+ CREATE INDEX idx_wakes_conversation ON wakes(source_conversation_id, created_at);
479
+ CREATE INDEX idx_wakes_status ON wakes(status, created_at);
480
+
481
+ CREATE TRIGGER trg_wakes_fk BEFORE INSERT ON wakes
482
+ BEGIN
483
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: wakes.source_conversation_id')
484
+ WHERE NOT EXISTS (SELECT 1 FROM conversations WHERE id = NEW.source_conversation_id);
485
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: wakes.parent_request_id')
486
+ WHERE NEW.parent_request_id IS NOT NULL
487
+ AND NOT EXISTS (SELECT 1 FROM work_requests WHERE id = NEW.parent_request_id);
488
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: wakes.work_request_id')
489
+ WHERE NEW.work_request_id IS NOT NULL
490
+ AND NOT EXISTS (SELECT 1 FROM work_requests WHERE id = NEW.work_request_id);
491
+ END;
492
+
493
+ -- Source, payload, and lineage are fixed when the Wake is recorded.
494
+ CREATE TRIGGER trg_wakes_immutable BEFORE UPDATE OF
495
+ id, idempotency_key, source_conversation_id, source_event_id, position, syntax, payload,
496
+ requester_agent_id, requested_target, execution_kind, parent_request_id,
497
+ root_wake_id, depth, created_at
498
+ ON wakes
499
+ BEGIN
500
+ SELECT RAISE(ABORT, 'wakes source, payload, and lineage are immutable');
501
+ END;
502
+
503
+ -- Recovery only moves forward: an unavailable target may resolve
504
+ -- or turn out unroutable (rejected), a blocked request may become
505
+ -- accepted. The resolved target, Work
506
+ -- Request, and root request (for a Wake without a parent, its own
507
+ -- request) are set once.
508
+ CREATE TRIGGER trg_wakes_recovery BEFORE UPDATE ON wakes
509
+ BEGIN
510
+ SELECT RAISE(ABORT, 'invalid wakes status change')
511
+ WHERE NEW.status <> OLD.status
512
+ AND (OLD.status || '>' || NEW.status) NOT IN ('unavailable>accepted', 'unavailable>blocked', 'unavailable>rejected', 'blocked>accepted');
513
+ SELECT RAISE(ABORT, 'wakes target and work request are set once')
514
+ WHERE (OLD.target_agent_id IS NOT NULL AND NEW.target_agent_id IS NOT OLD.target_agent_id)
515
+ OR (OLD.target_name_snapshot IS NOT NULL AND NEW.target_name_snapshot IS NOT OLD.target_name_snapshot)
516
+ OR (OLD.work_request_id IS NOT NULL AND NEW.work_request_id IS NOT OLD.work_request_id)
517
+ OR (OLD.root_request_id IS NOT NULL AND NEW.root_request_id IS NOT OLD.root_request_id);
518
+ END;
519
+ `)}},{version:8,name:"conversation_events",up:e=>{e.exec(`
520
+ -- NOT-470: typed conversation projection of Wake and Work Request
521
+ -- lifecycle events (lib/conversation-projection). One row per
522
+ -- projected part of one engine event; the id is derived from the
523
+ -- engine event id and part, so replay and redelivery never add a
524
+ -- row. text is the human-facing line, data the machine-readable
525
+ -- meaning. sort_at never decreases within a request, so ordering
526
+ -- by (sort_at, request_created_at, request_id, request_sequence,
527
+ -- part) keeps each request's own order while requests interleave.
528
+ CREATE TABLE conversation_events (
529
+ id TEXT PRIMARY KEY,
530
+ conversation_id TEXT NOT NULL,
531
+ engine_event_id TEXT NOT NULL,
532
+ part INTEGER NOT NULL CHECK (part >= 0),
533
+ request_id TEXT NOT NULL,
534
+ request_sequence INTEGER NOT NULL,
535
+ attempt_id TEXT,
536
+ wake_id TEXT,
537
+ kind TEXT NOT NULL CHECK (kind IN (
538
+ 'wake_accepted', 'wake_blocked', 'request_queued', 'request_blocked', 'request_running',
539
+ 'request_waiting', 'request_completed', 'request_failed', 'request_cancelled',
540
+ 'question', 'result', 'artifact'
541
+ )),
542
+ state TEXT CHECK (state IN (${eF})),
543
+ text TEXT NOT NULL,
544
+ data TEXT NOT NULL,
545
+ sort_at INTEGER NOT NULL,
546
+ request_created_at INTEGER NOT NULL,
547
+ created_at INTEGER NOT NULL,
548
+ UNIQUE (engine_event_id, part),
549
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id),
550
+ FOREIGN KEY (engine_event_id) REFERENCES engine_events(id),
551
+ FOREIGN KEY (request_id) REFERENCES work_requests(id)
552
+ );
553
+ CREATE INDEX idx_conversation_events_order
554
+ ON conversation_events(conversation_id, sort_at, request_created_at, request_id, request_sequence, part);
555
+ CREATE INDEX idx_conversation_events_request ON conversation_events(request_id);
556
+
557
+ -- Last engine event sequence the projector has read per request,
558
+ -- including events that project to nothing.
559
+ CREATE TABLE conversation_projection_cursors (
560
+ request_id TEXT PRIMARY KEY,
561
+ sequence INTEGER NOT NULL CHECK (sequence >= 0),
562
+ FOREIGN KEY (request_id) REFERENCES work_requests(id)
563
+ );
564
+
565
+ CREATE TRIGGER trg_conversation_events_immutable BEFORE UPDATE ON conversation_events
566
+ BEGIN
567
+ SELECT RAISE(ABORT, 'conversation_events are immutable');
568
+ END;
569
+ `)}},{version:9,name:"terminal_followups",up:e=>{e.exec(`
570
+ -- NOT-472: one row per canonical request that became terminal on
571
+ -- this schema, written in the same transaction as the terminal
572
+ -- transition. lib/coordinator-loop runs the follow-up (Wake
573
+ -- routing, coordinator continuation) and sets done_at; restart
574
+ -- recovery only replays rows still open. Requests that ended
575
+ -- before this migration get no row, so their replies are never
576
+ -- routed retroactively.
577
+ CREATE TABLE terminal_followups (
578
+ request_id TEXT PRIMARY KEY,
579
+ created_at INTEGER NOT NULL,
580
+ done_at INTEGER,
581
+ FOREIGN KEY (request_id) REFERENCES work_requests(id)
582
+ );
583
+ CREATE INDEX idx_terminal_followups_open ON terminal_followups(created_at) WHERE done_at IS NULL;
584
+ `)}},{version:10,name:"reviewed_git_finalization",up:e=>{e.exec(`
585
+ -- NOT-487: reviewed Git finalization through Agent Deck
586
+ -- (docs/design/2026-10-13-git-finalization-contract.md). Rows hold
587
+ -- only public Agent Deck identifiers, repository-relative paths,
588
+ -- digests, and modes: never file contents, host paths, or the
589
+ -- Agent Deck bearer.
590
+ --
591
+ -- Public baseline of a prepared edit Attempt, captured before model
592
+ -- work. Set once.
593
+ CREATE TABLE attempt_finalization_baselines (
594
+ attempt_id TEXT PRIMARY KEY,
595
+ request_id TEXT NOT NULL,
596
+ external_run_id TEXT NOT NULL,
597
+ baseline_ref TEXT NOT NULL,
598
+ baseline_digest TEXT NOT NULL,
599
+ created_at INTEGER NOT NULL,
600
+ FOREIGN KEY (attempt_id) REFERENCES work_attempts(id),
601
+ FOREIGN KEY (request_id) REFERENCES work_requests(id)
602
+ );
603
+
604
+ -- The ordered candidate manifest Agent Deck reported once the
605
+ -- prepared run was terminal: the immutable review evidence that a
606
+ -- finalization submits unchanged.
607
+ CREATE TABLE candidate_manifests (
608
+ id TEXT PRIMARY KEY,
609
+ attempt_id TEXT NOT NULL UNIQUE,
610
+ request_id TEXT NOT NULL,
611
+ conversation_id TEXT NOT NULL,
612
+ external_run_id TEXT NOT NULL,
613
+ baseline_ref TEXT NOT NULL,
614
+ baseline_digest TEXT NOT NULL,
615
+ base_commit TEXT NOT NULL,
616
+ manifest_digest TEXT NOT NULL,
617
+ files TEXT NOT NULL,
618
+ file_count INTEGER NOT NULL CHECK (file_count >= 0),
619
+ created_at INTEGER NOT NULL,
620
+ FOREIGN KEY (attempt_id) REFERENCES work_attempts(id),
621
+ FOREIGN KEY (request_id) REFERENCES work_requests(id),
622
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id)
623
+ );
624
+
625
+ -- One accepted finalization decision and its outcome. The request
626
+ -- body is exactly what was (or will be) submitted; the idempotency
627
+ -- key is derived from the explicit acceptance event, implementation
628
+ -- Attempt, review, and manifest. Replay and restart submit the same
629
+ -- request, while a later acceptance can retry a terminal non-commit.
630
+ CREATE TABLE finalizations (
631
+ id TEXT PRIMARY KEY,
632
+ idempotency_key TEXT NOT NULL UNIQUE CHECK (length(idempotency_key) > 0),
633
+ conversation_id TEXT NOT NULL,
634
+ decision_event_id TEXT NOT NULL,
635
+ decision_request_id TEXT NOT NULL,
636
+ coordinator_agent_id TEXT NOT NULL,
637
+ implementation_request_id TEXT NOT NULL,
638
+ implementation_attempt_id TEXT NOT NULL,
639
+ review_request_id TEXT NOT NULL,
640
+ review_attempt_id TEXT NOT NULL,
641
+ manifest_id TEXT NOT NULL,
642
+ external_run_id TEXT NOT NULL,
643
+ request_body TEXT NOT NULL,
644
+ request_hash TEXT NOT NULL,
645
+ state TEXT NOT NULL CHECK (state IN ('preparing', 'committed', 'blocked', 'failed', 'canceled')),
646
+ submitted_at INTEGER,
647
+ reason_code TEXT,
648
+ reason TEXT,
649
+ commit_id TEXT,
650
+ tree_id TEXT,
651
+ parent_commit TEXT,
652
+ result_manifest_digest TEXT,
653
+ file_count INTEGER,
654
+ created_at INTEGER NOT NULL,
655
+ updated_at INTEGER NOT NULL,
656
+ finished_at INTEGER,
657
+ CHECK ((state = 'preparing') = (finished_at IS NULL)),
658
+ CHECK (state <> 'committed' OR commit_id IS NOT NULL),
659
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id),
660
+ FOREIGN KEY (implementation_request_id) REFERENCES work_requests(id),
661
+ FOREIGN KEY (implementation_attempt_id) REFERENCES work_attempts(id),
662
+ FOREIGN KEY (review_request_id) REFERENCES work_requests(id),
663
+ FOREIGN KEY (manifest_id) REFERENCES candidate_manifests(id)
664
+ );
665
+ CREATE INDEX idx_finalizations_open ON finalizations(created_at) WHERE finished_at IS NULL;
666
+ CREATE INDEX idx_finalizations_attempt ON finalizations(implementation_attempt_id);
667
+
668
+ CREATE TRIGGER trg_attempt_finalization_baselines_fk BEFORE INSERT ON attempt_finalization_baselines
669
+ BEGIN
670
+ SELECT RAISE(ABORT, 'attempt finalization baseline does not match its Attempt')
671
+ WHERE NOT EXISTS (
672
+ SELECT 1 FROM work_attempts
673
+ WHERE id = NEW.attempt_id AND request_id = NEW.request_id AND external_run_id = NEW.external_run_id
674
+ );
675
+ END;
676
+ CREATE TRIGGER trg_attempt_finalization_baselines_immutable BEFORE UPDATE ON attempt_finalization_baselines
677
+ BEGIN
678
+ SELECT RAISE(ABORT, 'attempt_finalization_baselines are immutable');
679
+ END;
680
+ CREATE TRIGGER trg_candidate_manifests_fk BEFORE INSERT ON candidate_manifests
681
+ BEGIN
682
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: candidate_manifests.attempt_id')
683
+ WHERE NOT EXISTS (
684
+ SELECT 1 FROM work_attempts a
685
+ JOIN work_requests r ON r.id = a.request_id
686
+ JOIN attempt_finalization_baselines b ON b.attempt_id = a.id
687
+ WHERE a.id = NEW.attempt_id AND a.request_id = NEW.request_id
688
+ AND a.external_run_id = NEW.external_run_id
689
+ AND r.source_conversation_id = NEW.conversation_id
690
+ AND b.external_run_id = NEW.external_run_id
691
+ AND b.baseline_ref = NEW.baseline_ref AND b.baseline_digest = NEW.baseline_digest
692
+ );
693
+ END;
694
+ CREATE TRIGGER trg_candidate_manifests_immutable BEFORE UPDATE ON candidate_manifests
695
+ BEGIN
696
+ SELECT RAISE(ABORT, 'candidate_manifests are immutable');
697
+ END;
698
+ CREATE TRIGGER trg_finalizations_fk BEFORE INSERT ON finalizations
699
+ BEGIN
700
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: finalizations.manifest_id')
701
+ WHERE NOT EXISTS (
702
+ SELECT 1 FROM candidate_manifests m
703
+ JOIN work_attempts ia ON ia.id = NEW.implementation_attempt_id
704
+ JOIN work_attempts ra ON ra.id = NEW.review_attempt_id
705
+ JOIN work_requests ir ON ir.id = NEW.implementation_request_id
706
+ JOIN work_requests rr ON rr.id = NEW.review_request_id
707
+ JOIN work_requests dr ON dr.id = NEW.decision_request_id
708
+ WHERE m.id = NEW.manifest_id AND m.attempt_id = ia.id AND m.request_id = ir.id
709
+ AND m.external_run_id = NEW.external_run_id
710
+ AND ia.request_id = ir.id AND ra.request_id = rr.id
711
+ AND ir.source_conversation_id = NEW.conversation_id
712
+ AND rr.source_conversation_id = NEW.conversation_id
713
+ AND dr.source_conversation_id = NEW.conversation_id
714
+ AND dr.target_agent_id = NEW.coordinator_agent_id
715
+ );
716
+ END;
717
+ CREATE TRIGGER trg_finalizations_immutable BEFORE UPDATE OF
718
+ id, idempotency_key, conversation_id, decision_event_id, decision_request_id, coordinator_agent_id,
719
+ implementation_request_id, implementation_attempt_id, review_request_id, review_attempt_id,
720
+ manifest_id, external_run_id, request_body, request_hash, created_at
721
+ ON finalizations
722
+ BEGIN
723
+ SELECT RAISE(ABORT, 'finalizations decision and request are immutable');
724
+ END;
725
+ CREATE TRIGGER trg_finalizations_terminal BEFORE UPDATE ON finalizations
726
+ WHEN OLD.finished_at IS NOT NULL
727
+ BEGIN
728
+ SELECT RAISE(ABORT, 'finished finalizations are immutable');
729
+ END;
730
+ CREATE TRIGGER trg_finalizations_submitted BEFORE UPDATE OF submitted_at ON finalizations
731
+ WHEN OLD.submitted_at IS NOT NULL AND NEW.submitted_at IS NOT OLD.submitted_at
732
+ BEGIN
733
+ SELECT RAISE(ABORT, 'finalizations submitted_at is set once');
734
+ END;
735
+
736
+ -- Conversation projection gains the finalization lifecycle kinds.
737
+ -- SQLite cannot widen a CHECK in place, so the table is rebuilt
738
+ -- with every row kept.
739
+ CREATE TABLE conversation_events_v10 (
740
+ id TEXT PRIMARY KEY,
741
+ conversation_id TEXT NOT NULL,
742
+ engine_event_id TEXT NOT NULL,
743
+ part INTEGER NOT NULL CHECK (part >= 0),
744
+ request_id TEXT NOT NULL,
745
+ request_sequence INTEGER NOT NULL,
746
+ attempt_id TEXT,
747
+ wake_id TEXT,
748
+ kind TEXT NOT NULL CHECK (kind IN (
749
+ 'wake_accepted', 'wake_blocked', 'request_queued', 'request_blocked', 'request_running',
750
+ 'request_waiting', 'request_completed', 'request_failed', 'request_cancelled',
751
+ 'question', 'result', 'artifact',
752
+ 'finalization_preparing', 'finalization_committed', 'finalization_blocked',
753
+ 'finalization_failed', 'finalization_canceled', 'finalization_rejected'
754
+ )),
755
+ state TEXT CHECK (state IN (${eF})),
756
+ text TEXT NOT NULL,
757
+ data TEXT NOT NULL,
758
+ sort_at INTEGER NOT NULL,
759
+ request_created_at INTEGER NOT NULL,
760
+ created_at INTEGER NOT NULL,
761
+ UNIQUE (engine_event_id, part),
762
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id),
763
+ FOREIGN KEY (engine_event_id) REFERENCES engine_events(id),
764
+ FOREIGN KEY (request_id) REFERENCES work_requests(id)
765
+ );
766
+ INSERT INTO conversation_events_v10 SELECT
767
+ id, conversation_id, engine_event_id, part, request_id, request_sequence, attempt_id, wake_id,
768
+ kind, state, text, data, sort_at, request_created_at, created_at
769
+ FROM conversation_events;
770
+ DROP TABLE conversation_events;
771
+ ALTER TABLE conversation_events_v10 RENAME TO conversation_events;
772
+ CREATE INDEX idx_conversation_events_order
773
+ ON conversation_events(conversation_id, sort_at, request_created_at, request_id, request_sequence, part);
774
+ CREATE INDEX idx_conversation_events_request ON conversation_events(request_id);
775
+ CREATE TRIGGER trg_conversation_events_immutable BEFORE UPDATE ON conversation_events
776
+ BEGIN
777
+ SELECT RAISE(ABORT, 'conversation_events are immutable');
778
+ END;
779
+ `)}},{version:11,name:"leased_dispatch",up:e=>{e.exec(`
780
+ -- NOT-469: leased dispatcher (lib/dispatcher). One row per request a
781
+ -- worker owns. The token is a fencing value: heartbeat, release, and
782
+ -- every fenced commit match it, so a worker whose lease was taken
783
+ -- over can no longer write. An expired row is not free: its run may
784
+ -- still be live, so it counts toward concurrency until a worker
785
+ -- takes it over and reconciles it.
786
+ CREATE TABLE dispatch_leases (
787
+ request_id TEXT PRIMARY KEY,
788
+ target_agent_id TEXT NOT NULL,
789
+ owner TEXT NOT NULL CHECK (length(owner) > 0),
790
+ token TEXT NOT NULL UNIQUE CHECK (length(token) > 0),
791
+ acquired_at INTEGER NOT NULL,
792
+ heartbeat_at INTEGER NOT NULL,
793
+ expires_at INTEGER NOT NULL,
794
+ FOREIGN KEY (request_id) REFERENCES work_requests(id)
795
+ );
796
+ CREATE INDEX idx_dispatch_leases_target ON dispatch_leases(target_agent_id);
797
+ CREATE INDEX idx_dispatch_leases_expiry ON dispatch_leases(expires_at);
798
+
799
+ -- Launch intent, written with the Attempt before any adapter call:
800
+ -- the exact start body (or null for a transport without external
801
+ -- runs), its idempotency key, and a non-secret fingerprint of the
802
+ -- launching grant. Reconciliation re-POSTs only this body, under
803
+ -- this key, with this grant (NOT-468 decision table A).
804
+ CREATE TABLE attempt_launch_intents (
805
+ attempt_id TEXT PRIMARY KEY,
806
+ request_id TEXT NOT NULL,
807
+ transport TEXT NOT NULL CHECK (length(transport) > 0),
808
+ idempotency_key TEXT,
809
+ body TEXT,
810
+ body_hash TEXT,
811
+ grant_fingerprint TEXT,
812
+ owner TEXT NOT NULL,
813
+ created_at INTEGER NOT NULL,
814
+ CHECK ((body IS NULL) = (body_hash IS NULL)),
815
+ CHECK (body IS NULL OR idempotency_key IS NOT NULL),
816
+ FOREIGN KEY (attempt_id) REFERENCES work_attempts(id),
817
+ FOREIGN KEY (request_id) REFERENCES work_requests(id)
818
+ );
819
+ CREATE TRIGGER trg_attempt_launch_intents_fk BEFORE INSERT ON attempt_launch_intents
820
+ BEGIN
821
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: attempt_launch_intents.attempt_id')
822
+ WHERE NOT EXISTS (SELECT 1 FROM work_attempts WHERE id = NEW.attempt_id AND request_id = NEW.request_id);
823
+ END;
824
+ CREATE TRIGGER trg_attempt_launch_intents_immutable BEFORE UPDATE ON attempt_launch_intents
825
+ BEGIN
826
+ SELECT RAISE(ABORT, 'attempt_launch_intents are immutable');
827
+ END;
828
+
829
+ -- Operator-attention flag, separate from the Attempt lifecycle. While
830
+ -- one is open for a request the dispatcher makes no automatic
831
+ -- launch, re-POST, retry, or resume for it. Only an operator clears
832
+ -- it (cleared_at).
833
+ CREATE TABLE dispatch_attention (
834
+ id TEXT PRIMARY KEY,
835
+ request_id TEXT NOT NULL,
836
+ attempt_id TEXT,
837
+ reason TEXT NOT NULL CHECK (length(reason) > 0),
838
+ detail TEXT,
839
+ created_at INTEGER NOT NULL,
840
+ cleared_at INTEGER,
841
+ FOREIGN KEY (request_id) REFERENCES work_requests(id),
842
+ FOREIGN KEY (attempt_id) REFERENCES work_attempts(id)
843
+ );
844
+ CREATE UNIQUE INDEX idx_dispatch_attention_open ON dispatch_attention(request_id) WHERE cleared_at IS NULL;
845
+ `)}},{version:12,name:"request_control",up:e=>{e.exec(`
846
+ -- NOT-473: cancellation, deadlines, and bounded retries
847
+ -- (lib/work-request-control, lib/request-policy). The deadline and
848
+ -- retry policy are fixed at intake; null on older rows means no
849
+ -- deadline and one Attempt. attempt_count counts claimed Attempts
850
+ -- and never decreases; a queued retry is not claimable before
851
+ -- next_eligible_at. The cancellation intent is recorded once.
852
+ ALTER TABLE work_requests ADD COLUMN deadline_at INTEGER;
853
+ ALTER TABLE work_requests ADD COLUMN retry_policy TEXT;
854
+ ALTER TABLE work_requests ADD COLUMN attempt_count INTEGER NOT NULL DEFAULT 0 CHECK (attempt_count >= 0);
855
+ ALTER TABLE work_requests ADD COLUMN next_eligible_at INTEGER;
856
+ ALTER TABLE work_requests ADD COLUMN cancel_requested_at INTEGER;
857
+ ALTER TABLE work_requests ADD COLUMN cancel_requested_by TEXT;
858
+ ALTER TABLE work_requests ADD COLUMN cancel_reason TEXT;
859
+ CREATE INDEX idx_work_requests_deadline ON work_requests(deadline_at) WHERE deadline_at IS NOT NULL;
860
+
861
+ CREATE TRIGGER trg_work_requests_control_immutable BEFORE UPDATE OF deadline_at, retry_policy ON work_requests
862
+ WHEN NEW.deadline_at IS NOT OLD.deadline_at OR NEW.retry_policy IS NOT OLD.retry_policy
863
+ BEGIN
864
+ SELECT RAISE(ABORT, 'work_requests deadline and retry policy are immutable');
865
+ END;
866
+ CREATE TRIGGER trg_work_requests_attempt_count BEFORE UPDATE OF attempt_count ON work_requests
867
+ WHEN NEW.attempt_count < OLD.attempt_count
868
+ BEGIN
869
+ SELECT RAISE(ABORT, 'work_requests attempt_count never decreases');
870
+ END;
871
+ CREATE TRIGGER trg_work_requests_cancel_once BEFORE UPDATE OF cancel_requested_at, cancel_requested_by, cancel_reason ON work_requests
872
+ WHEN OLD.cancel_requested_at IS NOT NULL AND (
873
+ NEW.cancel_requested_at IS NOT OLD.cancel_requested_at
874
+ OR NEW.cancel_requested_by IS NOT OLD.cancel_requested_by
875
+ OR NEW.cancel_reason IS NOT OLD.cancel_reason
876
+ )
877
+ BEGIN
878
+ SELECT RAISE(ABORT, 'work_requests cancellation intent is recorded once');
879
+ END;
880
+
881
+ -- Conversation projection gains the cancellation, timeout, and
882
+ -- retry kinds (rebuilt with every row kept, as in version 10).
883
+ CREATE TABLE conversation_events_v12 (
884
+ id TEXT PRIMARY KEY,
885
+ conversation_id TEXT NOT NULL,
886
+ engine_event_id TEXT NOT NULL,
887
+ part INTEGER NOT NULL CHECK (part >= 0),
888
+ request_id TEXT NOT NULL,
889
+ request_sequence INTEGER NOT NULL,
890
+ attempt_id TEXT,
891
+ wake_id TEXT,
892
+ kind TEXT NOT NULL CHECK (kind IN (
893
+ 'wake_accepted', 'wake_blocked', 'request_queued', 'request_blocked', 'request_running',
894
+ 'request_waiting', 'request_completed', 'request_failed', 'request_cancelled',
895
+ 'question', 'result', 'artifact',
896
+ 'finalization_preparing', 'finalization_committed', 'finalization_blocked',
897
+ 'finalization_failed', 'finalization_canceled', 'finalization_rejected',
898
+ 'request_cancel_requested', 'request_timed_out', 'request_retry_scheduled', 'request_retries_exhausted'
899
+ )),
900
+ state TEXT CHECK (state IN (${eF})),
901
+ text TEXT NOT NULL,
902
+ data TEXT NOT NULL,
903
+ sort_at INTEGER NOT NULL,
904
+ request_created_at INTEGER NOT NULL,
905
+ created_at INTEGER NOT NULL,
906
+ UNIQUE (engine_event_id, part),
907
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id),
908
+ FOREIGN KEY (engine_event_id) REFERENCES engine_events(id),
909
+ FOREIGN KEY (request_id) REFERENCES work_requests(id)
910
+ );
911
+ INSERT INTO conversation_events_v12 SELECT
912
+ id, conversation_id, engine_event_id, part, request_id, request_sequence, attempt_id, wake_id,
913
+ kind, state, text, data, sort_at, request_created_at, created_at
914
+ FROM conversation_events;
915
+ DROP TABLE conversation_events;
916
+ ALTER TABLE conversation_events_v12 RENAME TO conversation_events;
917
+ CREATE INDEX idx_conversation_events_order
918
+ ON conversation_events(conversation_id, sort_at, request_created_at, request_id, request_sequence, part);
919
+ CREATE INDEX idx_conversation_events_request ON conversation_events(request_id);
920
+ CREATE TRIGGER trg_conversation_events_immutable BEFORE UPDATE ON conversation_events
921
+ BEGIN
922
+ SELECT RAISE(ABORT, 'conversation_events are immutable');
923
+ END;
924
+ `)}},{version:13,name:"wake_safety",up:e=>{e.exec(`
925
+ -- NOT-475: Wake safety (docs/design/2026-10-14-wake-safety-contract.md,
926
+ -- lib/wake-safety). Lineage columns: wake_depth counts Agent-to-Agent
927
+ -- hops from the root (a continuation runs at the depth of the Agent it
928
+ -- continues) and the root principal is whoever started the lineage.
929
+ -- Both are fixed at intake.
930
+ ALTER TABLE work_requests ADD COLUMN wake_depth INTEGER NOT NULL DEFAULT 0 CHECK (wake_depth >= 0);
931
+ ALTER TABLE work_requests ADD COLUMN root_principal_kind TEXT;
932
+ ALTER TABLE work_requests ADD COLUMN root_principal_id TEXT;
933
+
934
+ -- Owner-approved edit grants for one (caller Agent, target Agent)
935
+ -- pair. Never seeded; revoked once, never rewritten or reused.
936
+ CREATE TABLE wake_grants (
937
+ id TEXT PRIMARY KEY,
938
+ caller_agent_id TEXT NOT NULL,
939
+ target_agent_id TEXT NOT NULL,
940
+ authority TEXT NOT NULL CHECK (authority = 'edit'),
941
+ granted_by_kind TEXT NOT NULL,
942
+ granted_by_id TEXT NOT NULL,
943
+ source_wake_id TEXT,
944
+ created_at INTEGER NOT NULL,
945
+ revoked_at INTEGER,
946
+ revoked_by_kind TEXT,
947
+ revoked_by_id TEXT,
948
+ CHECK ((revoked_at IS NULL) = (revoked_by_kind IS NULL) AND (revoked_at IS NULL) = (revoked_by_id IS NULL))
949
+ );
950
+ CREATE UNIQUE INDEX idx_wake_grants_active ON wake_grants(caller_agent_id, target_agent_id, authority) WHERE revoked_at IS NULL;
951
+ CREATE TRIGGER trg_wake_grants_immutable BEFORE UPDATE ON wake_grants
952
+ BEGIN
953
+ SELECT RAISE(ABORT, 'wake_grants are immutable except for one revocation')
954
+ WHERE OLD.revoked_at IS NOT NULL
955
+ OR NEW.id IS NOT OLD.id OR NEW.caller_agent_id IS NOT OLD.caller_agent_id
956
+ OR NEW.target_agent_id IS NOT OLD.target_agent_id OR NEW.authority IS NOT OLD.authority
957
+ OR NEW.granted_by_kind IS NOT OLD.granted_by_kind OR NEW.granted_by_id IS NOT OLD.granted_by_id
958
+ OR NEW.source_wake_id IS NOT OLD.source_wake_id OR NEW.created_at IS NOT OLD.created_at;
959
+ END;
960
+
961
+ -- One append-only row per safety evaluation of a Work Request: the
962
+ -- categorized caller principal, target, decision, matched grant rule
963
+ -- and grant, and the policy snapshot used. A request is runnable
964
+ -- only while its latest decision is allowed (lib/dispatcher). A
965
+ -- later policy change (a revoked grant, new limits) adds rows for
966
+ -- later evaluations and never rewrites these.
967
+ CREATE TABLE wake_safety_decisions (
968
+ id TEXT PRIMARY KEY,
969
+ request_id TEXT NOT NULL,
970
+ sequence INTEGER NOT NULL CHECK (sequence > 0),
971
+ wake_id TEXT,
972
+ principal_type TEXT NOT NULL CHECK (principal_type IN ('human_owner', 'api_principal', 'agent_principal', 'engine')),
973
+ principal_kind TEXT NOT NULL,
974
+ principal_id TEXT NOT NULL,
975
+ target_agent_id TEXT NOT NULL,
976
+ execution_kind TEXT NOT NULL,
977
+ decision TEXT NOT NULL CHECK (decision IN ('allowed', 'blocked', 'denied')),
978
+ reason_code TEXT,
979
+ grant_rule TEXT,
980
+ grant_id TEXT,
981
+ policy_snapshot TEXT NOT NULL,
982
+ created_at INTEGER NOT NULL,
983
+ UNIQUE (request_id, sequence),
984
+ CHECK (decision <> 'allowed' OR grant_rule IS NOT NULL),
985
+ FOREIGN KEY (request_id) REFERENCES work_requests(id)
986
+ );
987
+ CREATE TRIGGER trg_wake_safety_decisions_fk BEFORE INSERT ON wake_safety_decisions
988
+ BEGIN
989
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: wake_safety_decisions.request_id')
990
+ WHERE NOT EXISTS (SELECT 1 FROM work_requests WHERE id = NEW.request_id);
991
+ END;
992
+ CREATE TRIGGER trg_wake_safety_decisions_immutable BEFORE UPDATE ON wake_safety_decisions
993
+ BEGIN
994
+ SELECT RAISE(ABORT, 'wake_safety_decisions are append-only');
995
+ END;
996
+
997
+ -- Depth and root-budget refusals name the limit and what was seen.
998
+ ALTER TABLE wakes ADD COLUMN limit_value INTEGER;
999
+ ALTER TABLE wakes ADD COLUMN observed_value INTEGER;
1000
+
1001
+ -- Rejected Wakes project from the Wake row (no Work Request, no
1002
+ -- engine event), and a stopped lineage projects as its own kind.
1003
+ CREATE TABLE conversation_events_v13 (
1004
+ id TEXT PRIMARY KEY,
1005
+ conversation_id TEXT NOT NULL,
1006
+ engine_event_id TEXT,
1007
+ part INTEGER NOT NULL CHECK (part >= 0),
1008
+ request_id TEXT,
1009
+ request_sequence INTEGER NOT NULL,
1010
+ attempt_id TEXT,
1011
+ wake_id TEXT,
1012
+ kind TEXT NOT NULL CHECK (kind IN (
1013
+ 'wake_accepted', 'wake_blocked', 'request_queued', 'request_blocked', 'request_running',
1014
+ 'request_waiting', 'request_completed', 'request_failed', 'request_cancelled',
1015
+ 'question', 'result', 'artifact',
1016
+ 'finalization_preparing', 'finalization_committed', 'finalization_blocked',
1017
+ 'finalization_failed', 'finalization_canceled', 'finalization_rejected',
1018
+ 'request_cancel_requested', 'request_timed_out', 'request_retry_scheduled', 'request_retries_exhausted',
1019
+ 'wake_rejected', 'lineage_stopped'
1020
+ )),
1021
+ state TEXT CHECK (state IN (${eF})),
1022
+ text TEXT NOT NULL,
1023
+ data TEXT NOT NULL,
1024
+ sort_at INTEGER NOT NULL,
1025
+ request_created_at INTEGER NOT NULL,
1026
+ created_at INTEGER NOT NULL,
1027
+ UNIQUE (engine_event_id, part),
1028
+ CHECK ((engine_event_id IS NULL) = (request_id IS NULL)),
1029
+ CHECK (request_id IS NOT NULL OR wake_id IS NOT NULL),
1030
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id),
1031
+ FOREIGN KEY (engine_event_id) REFERENCES engine_events(id),
1032
+ FOREIGN KEY (request_id) REFERENCES work_requests(id)
1033
+ );
1034
+ INSERT INTO conversation_events_v13 SELECT
1035
+ id, conversation_id, engine_event_id, part, request_id, request_sequence, attempt_id, wake_id,
1036
+ kind, state, text, data, sort_at, request_created_at, created_at
1037
+ FROM conversation_events;
1038
+ DROP TABLE conversation_events;
1039
+ ALTER TABLE conversation_events_v13 RENAME TO conversation_events;
1040
+ CREATE INDEX idx_conversation_events_order
1041
+ ON conversation_events(conversation_id, sort_at, request_created_at, request_id, request_sequence, part);
1042
+ CREATE INDEX idx_conversation_events_request ON conversation_events(request_id);
1043
+ CREATE INDEX idx_conversation_events_wake ON conversation_events(wake_id);
1044
+ CREATE TRIGGER trg_conversation_events_immutable BEFORE UPDATE ON conversation_events
1045
+ BEGIN
1046
+ SELECT RAISE(ABORT, 'conversation_events are immutable');
1047
+ END;
1048
+ `),function(e){let t=e.prepare(`
1049
+ SELECT id, parent_request_id, root_request_id, wake_event_id, requester_kind, requester_id, policy_snapshot, state,
1050
+ target_agent_id, execution_kind, legacy_agent_request_id, created_at
1051
+ FROM work_requests ORDER BY created_at ASC, rowid ASC
1052
+ `).all(),n=new Map(t.map(e=>[e.id,e])),i=e=>{try{let t=JSON.parse(e.policy_snapshot);return t&&"object"==typeof t&&!Array.isArray(t)?t:{}}catch{return{}}},r=new Map,a=e=>{let t=r.get(e.id);if(void 0!==t)return t;let i=[],s=new Set,a=e,o=!1;for(;a&&!s.has(a.id)&&a.root_request_id===e.root_request_id;){let t=r.get(a.id);if(void 0!==t){o=t;break}if(s.add(a.id),i.push(a),null===a.parent_request_id){o=a.id===e.root_request_id;break}a=n.get(a.parent_request_id)}for(let e of i)r.set(e.id,o);return o},o=new Map,_=e=>{let t=o.get(e.id);if(void 0!==t)return t;let r=0,s=e.parent_request_id?n.get(e.parent_request_id):void 0;if(s){let t=_(s),n=i(e);r=e.wake_event_id?t+1:"coordinator_continuation"===n.source&&"result"===n.continues?Math.max(t-1,0):t}return o.set(e.id,r),r},d=e.prepare("UPDATE work_requests SET wake_depth = ?, root_principal_kind = ?, root_principal_id = ? WHERE id = ?"),E=e.prepare(`
1053
+ INSERT INTO wake_safety_decisions (
1054
+ id, request_id, sequence, wake_id, principal_type, principal_kind, principal_id, target_agent_id, execution_kind,
1055
+ decision, reason_code, grant_rule, grant_id, policy_snapshot, created_at
1056
+ ) VALUES (?, ?, 1, ?, ?, ?, ?, ?, ?, 'allowed', NULL, 'pre_safety_migration', NULL, ?, ?)
1057
+ `);for(let r of(e.exec("DROP TRIGGER trg_work_requests_terminal"),t)){let e=n.get(r.root_request_id),t=!!e&&a(r),o=t?_(r):0,u=t&&e?{kind:e.requester_kind,id:e.requester_id}:{kind:"unknown",id:"unknown"};if(d.run(o,u.kind,u.id,r.id),null===r.legacy_agent_request_id&&["queued","running","waiting"].includes(r.state)){let e=i(r),t="wake"===e.source?"agent_principal":"coordinator_continuation"===e.source?"engine":"api"===e.surface?"api_principal":"human_owner";E.run((0,s.randomUUID)(),r.id,r.wake_event_id,t,r.requester_kind,r.requester_id,r.target_agent_id,r.execution_kind,JSON.stringify({safety_version:1,migrated:!0,root_principal:u,wake_depth:o,grant_rule:"pre_safety_migration"}),r.created_at)}}e.exec(`
1058
+ CREATE TRIGGER trg_work_requests_terminal BEFORE UPDATE ON work_requests
1059
+ WHEN OLD.state IN (${eU})
1060
+ BEGIN
1061
+ SELECT RAISE(ABORT, 'terminal work_requests are immutable');
1062
+ END;
1063
+ `)}(e),e.exec(`
1064
+ CREATE TRIGGER trg_work_requests_safety_immutable BEFORE UPDATE OF wake_depth, root_principal_kind, root_principal_id ON work_requests
1065
+ WHEN NEW.wake_depth IS NOT OLD.wake_depth
1066
+ OR NEW.root_principal_kind IS NOT OLD.root_principal_kind
1067
+ OR NEW.root_principal_id IS NOT OLD.root_principal_id
1068
+ BEGIN
1069
+ SELECT RAISE(ABORT, 'work_requests wake depth and root principal are immutable');
1070
+ END;
1071
+ `)}},{version:14,name:"retire_legacy_agent_requests",up:e=>{!function(e){let t=t=>!!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(t);if(!t("agent_requests"))return;let n=t("agent_request_events"),i=e.prepare(`
1072
+ SELECT r.*, m.content AS content FROM agent_requests r
1073
+ JOIN conversations c ON c.id = r.conversation_id
1074
+ JOIN bots b ON b.id = r.target_bot_id
1075
+ JOIN messages m ON m.id = r.accepted_message_id AND m.conversation_id = r.conversation_id
1076
+ WHERE r.state IN ('completed', 'failed', 'accepted', 'dispatched')
1077
+ AND r.principal_kind IN ('person', 'bot', 'service')
1078
+ AND NOT EXISTS (SELECT 1 FROM work_requests w WHERE w.legacy_agent_request_id = r.id)
1079
+ ORDER BY r.created_at ASC, r.rowid ASC
1080
+ `).all(),r=e.prepare("SELECT 1 FROM work_requests WHERE requester_kind = ? AND requester_id = ? AND idempotency_key = ?"),a=n?e.prepare("SELECT type, data, created_at FROM agent_request_events WHERE request_id = ? ORDER BY created_at ASC, rowid ASC"):null,o=e.prepare(`
1081
+ INSERT INTO work_requests (
1082
+ id, source_conversation_id, source_event_id, requester_kind, requester_id, target_agent_id,
1083
+ intent, execution_kind, tool_profile, parent_request_id, root_request_id, wake_event_id, depth,
1084
+ idempotency_key, request_hash, policy_snapshot, state, state_reason, result, error_code, error_message,
1085
+ version, legacy_agent_request_id, created_at, updated_at, terminal_at, root_principal_kind, root_principal_id
1086
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, 'conversation', 'readonly', NULL, ?, NULL, 0, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?, ?, ?, ?)
1087
+ `),_=e.prepare("INSERT INTO engine_events (id, request_id, sequence, attempt_id, type, data, created_at) VALUES (?, ?, ?, NULL, ?, ?, ?)"),d=Date.now();for(let e of i){if(r.get(e.principal_kind,e.principal_id,e.idempotency_key))continue;let t=(0,s.randomUUID)(),n=eB({sourceConversationId:e.conversation_id,sourceEventId:e.accepted_message_id,targetAgentId:e.target_bot_id,intent:e.content,executionKind:"conversation",toolProfile:"readonly"}),i="accepted"===e.state||"dispatched"===e.state,E=JSON.stringify({tool_profile:"readonly",source:"legacy_agent_requests",legacy_operation:e.operation,legacy_runtime:e.runtime,...i?{legacy_state:e.state}:{}}),u=i?Math.max(d,e.updated_at):e.updated_at;o.run(t,e.conversation_id,e.accepted_message_id,e.principal_kind,e.principal_id,e.target_bot_id,e.content,t,e.idempotency_key,n,E,i?"failed":e.state,i?eM:null,"completed"===e.state?JSON.stringify({reply_message_id:e.reply_message_id}):null,i?eM:"failed"===e.state?e.failure_code:null,i?eK:"failed"===e.state?e.failure_message:null,e.id,e.created_at,u,u,e.principal_kind,e.principal_id);let c=0;for(let n of a?.all(e.id)??[])_.run((0,s.randomUUID)(),t,++c,n.type,n.data,n.created_at);i&&_.run((0,s.randomUUID)(),t,++c,"state_changed",JSON.stringify({from:"accepted"===e.state?"queued":"running",to:"failed",reason:eM}),u),_.run((0,s.randomUUID)(),t,++c,"backfilled",JSON.stringify({legacy_agent_request_id:e.id}),u)}(function(e){let t=e.prepare(`
1088
+ SELECT w.id AS request_id, r.principal_kind, r.principal_id, r.idempotency_key, r.payload_hash,
1089
+ r.conversation_id, r.target_bot_id, r.accepted_message_id, r.created_at, m.content AS content
1090
+ FROM work_requests w
1091
+ JOIN agent_requests r ON r.id = w.legacy_agent_request_id
1092
+ JOIN messages m ON m.id = r.accepted_message_id
1093
+ WHERE r.operation = 'send_message'
1094
+ AND NOT EXISTS (
1095
+ SELECT 1 FROM conversation_intakes i
1096
+ WHERE i.requester_kind = r.principal_kind AND i.requester_id = r.principal_id AND i.idempotency_key = r.idempotency_key
1097
+ )
1098
+ `).all(),n=e.prepare(`
1099
+ INSERT INTO conversation_intakes (
1100
+ requester_kind, requester_id, idempotency_key, request_hash, surface,
1101
+ conversation_id, source_event_id, work_request_ids, created_at
1102
+ ) VALUES (?, ?, ?, ?, 'api', ?, ?, ?, ?)
1103
+ `);for(let e of t){let t=[e.conversation_id,null].map(t=>[e.target_bot_id,t,e.content]).find(t=>eJ(JSON.stringify(t))===e.payload_hash);t&&n.run(e.principal_kind,e.principal_id,e.idempotency_key,eJ(JSON.stringify(["api",t])),e.conversation_id,e.accepted_message_id,JSON.stringify([e.request_id]),e.created_at)}})(e),t("legacy_agent_requests_archive")?e.exec("INSERT INTO legacy_agent_requests_archive SELECT * FROM agent_requests; DROP TABLE agent_requests;"):e.exec("ALTER TABLE agent_requests RENAME TO legacy_agent_requests_archive"),n&&(t("legacy_agent_request_events_archive")?e.exec("INSERT INTO legacy_agent_request_events_archive SELECT * FROM agent_request_events; DROP TABLE agent_request_events;"):e.exec("ALTER TABLE agent_request_events RENAME TO legacy_agent_request_events_archive"))}(e)}},{version:15,name:"ui_turns_on_work_requests",up:e=>{e.exec(`
1104
+ ALTER TABLE work_requests ADD COLUMN executor TEXT NOT NULL DEFAULT 'dispatcher'
1105
+ CHECK (executor IN ('dispatcher', 'ui_message', 'ui_continuation'));
1106
+ CREATE INDEX idx_work_requests_executor ON work_requests(executor, state, created_at);
1107
+
1108
+ -- Delegation accounting for one user message in one UI thread:
1109
+ -- handoffs (depth), delegated turns (budget), Stop, and the
1110
+ -- caller frames a delegate's reply returns to. One row per
1111
+ -- (conversation, user message); a later user message starts a
1112
+ -- fresh row.
1113
+ CREATE TABLE delegation_chains (
1114
+ conversation_id TEXT NOT NULL,
1115
+ user_message_id TEXT NOT NULL,
1116
+ handoffs INTEGER NOT NULL DEFAULT 0 CHECK (handoffs >= 0),
1117
+ turns INTEGER NOT NULL DEFAULT 0 CHECK (turns >= 0),
1118
+ stopped INTEGER NOT NULL DEFAULT 0 CHECK (stopped IN (0, 1)),
1119
+ frames TEXT NOT NULL DEFAULT '[]',
1120
+ created_at INTEGER NOT NULL,
1121
+ updated_at INTEGER NOT NULL,
1122
+ PRIMARY KEY (conversation_id, user_message_id),
1123
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id)
1124
+ );
1125
+ `),function(e){let t=t=>!!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(t);if(!t("processing_queue"))return;let n=new Set(e.prepare("PRAGMA table_info(processing_queue)").all().map(e=>e.name)).has("work_request_id")?"q.work_request_id":"NULL",i=e.prepare(`
1126
+ SELECT q.id, q.conversation_id, q.bot_id, q.status, ${n} AS work_request_id, q.created_at, q.started_at, q.completed_at
1127
+ FROM processing_queue q
1128
+ JOIN conversations c ON c.id = q.conversation_id
1129
+ JOIN bots b ON b.id = q.bot_id
1130
+ ORDER BY q.created_at ASC, q.rowid ASC
1131
+ `).all(),r=e.prepare("SELECT * FROM work_requests WHERE id = ?"),a=e.prepare(`
1132
+ UPDATE work_requests SET state = ?, state_reason = ?, version = version + 1, updated_at = ?,
1133
+ error_code = ?, error_message = ?, terminal_at = ?, executor = 'ui_message'
1134
+ WHERE id = ?
1135
+ `),o=e.prepare(`
1136
+ INSERT INTO engine_events (id, request_id, sequence, attempt_id, type, data, created_at)
1137
+ SELECT ?, ?, COALESCE(MAX(sequence), 0) + 1, NULL, ?, ?, ? FROM engine_events WHERE request_id = ?
1138
+ `),_=(e,t,n,i)=>o.run((0,s.randomUUID)(),e,t,JSON.stringify(n),i,e),d=e.prepare("SELECT id FROM messages WHERE conversation_id = ? AND created_at <= ? ORDER BY created_at DESC, rowid DESC LIMIT 1"),E=e.prepare(`
1139
+ INSERT INTO work_requests (
1140
+ id, source_conversation_id, source_event_id, requester_kind, requester_id, target_agent_id,
1141
+ intent, execution_kind, tool_profile, parent_request_id, root_request_id, wake_event_id, depth,
1142
+ idempotency_key, request_hash, policy_snapshot, state, version, created_at, updated_at,
1143
+ wake_depth, root_principal_kind, root_principal_id, executor
1144
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, 'conversation', 'readonly', NULL, ?, NULL, 0, ?, ?, ?, 'queued', 0, ?, ?, 0, ?, ?, 'ui_continuation')
1145
+ `),u=eP(!1),c=0;for(let t of i){if(t.work_request_id){let n=r.get(t.work_request_id);if(!n||"queued"!==n.state)continue;let i=t.started_at??t.created_at,s=Math.max(t.completed_at??i,i);if("pending"===t.status)e.prepare("UPDATE work_requests SET executor = 'ui_message' WHERE id = ?").run(n.id);else if("completed"===t.status||"failed"===t.status)a.run("running",null,i,null,null,null,n.id),_(n.id,"state_changed",{from:"queued",to:"running",reason:null,legacy_queue_id:t.id},i),a.run(t.status,"legacy_queue_turn",s,"failed"===t.status?"ui_turn_failed":null,"failed"===t.status?"The UI turn failed in the retired processing queue.":null,s,n.id),_(n.id,"state_changed",{from:"running",to:t.status,reason:"legacy_queue_turn",legacy_queue_id:t.id},s);else{let e=Math.max(Date.now(),i);a.run("running",null,i,null,null,null,n.id),_(n.id,"state_changed",{from:"queued",to:"running",reason:null,legacy_queue_id:t.id},i),a.run("failed",e$,e,e$,ez,e,n.id),_(n.id,"state_changed",{from:"running",to:"failed",reason:e$,error_code:e$,legacy_queue_id:t.id},e)}c++;continue}if("pending"!==t.status)continue;let n=(0,s.randomUUID)(),i=d.get(t.conversation_id,t.created_at)?.id??t.conversation_id,o={source:"legacy_processing_queue",legacy_queue_id:t.id},l=eB({sourceConversationId:t.conversation_id,sourceEventId:i,targetAgentId:t.bot_id,intent:"turn",executionKind:"conversation",toolProfile:"readonly",policy:{...o,execution_policy:u}});E.run(n,t.conversation_id,i,eY.kind,eY.id,t.bot_id,"turn",n,`legacy-queue:${t.id}`,l,JSON.stringify({...o,execution_policy:u,tool_profile:"readonly"}),t.created_at,t.created_at,eY.kind,eY.id),_(n,"accepted",{state:"queued",execution_kind:"conversation",tool_profile:"readonly"},t.created_at),_(n,"backfilled",{legacy_queue_id:t.id},t.created_at),c++}c+=e.prepare(`
1146
+ UPDATE work_requests SET executor = 'ui_message'
1147
+ WHERE state = 'queued' AND executor = 'dispatcher' AND legacy_agent_request_id IS NULL
1148
+ AND parent_request_id IS NULL AND wake_event_id IS NULL
1149
+ AND (
1150
+ (json_extract(policy_snapshot, '$.source') = 'conversation_intake' AND json_extract(policy_snapshot, '$.surface') = 'ui')
1151
+ OR EXISTS (
1152
+ SELECT 1 FROM conversation_intakes i, json_each(i.work_request_ids) r
1153
+ WHERE i.surface = 'ui' AND r.value = work_requests.id
1154
+ )
1155
+ )
1156
+ `).run().changes,t("legacy_processing_queue_archive")?e.exec("INSERT INTO legacy_processing_queue_archive SELECT * FROM processing_queue; DROP TABLE processing_queue;"):e.exec("ALTER TABLE processing_queue RENAME TO legacy_processing_queue_archive")}(e)}},{version:16,name:"session_exchanges",up:e=>{let t=ef.flatMap(e=>eh[e].map(t=>`'${e}>${t}'`)).join(", "),n=ef.map(e=>`'${e}'`).join(", "),i=ev.map(e=>`'${e}'`).join(", ");e.exec(`
1157
+ -- One row per owner-requested exchange against one selected Session
1158
+ -- Binding. It names Botmancers rows only (binding, Work Requests,
1159
+ -- Attempts, messages): never a provider session id or credential.
1160
+ -- Hop Work Requests run through the dispatcher; the exchange state
1161
+ -- advances from their durable outcome.
1162
+ CREATE TABLE session_exchanges (
1163
+ id TEXT PRIMARY KEY,
1164
+ requester_kind TEXT NOT NULL CHECK (requester_kind IN ('person', 'bot', 'service')),
1165
+ requester_id TEXT NOT NULL,
1166
+ idempotency_key TEXT NOT NULL CHECK (length(idempotency_key) > 0),
1167
+ request_hash TEXT NOT NULL,
1168
+ mode TEXT NOT NULL CHECK (mode IN ('ask', 'continue')),
1169
+ origin_conversation_id TEXT NOT NULL,
1170
+ source_agent_id TEXT NOT NULL,
1171
+ source_binding_id TEXT NOT NULL,
1172
+ destination_agent_id TEXT,
1173
+ destination_conversation_id TEXT,
1174
+ destination_binding_id TEXT,
1175
+ instruction TEXT NOT NULL CHECK (length(instruction) BETWEEN 1 AND ${ew.instructionChars}),
1176
+ state TEXT NOT NULL CHECK (state IN (${n})),
1177
+ source_request_id TEXT,
1178
+ source_attempt_id TEXT,
1179
+ destination_request_id TEXT,
1180
+ destination_attempt_id TEXT,
1181
+ answer_message_id TEXT,
1182
+ packet TEXT CHECK (packet IS NULL OR length(packet) <= ${ew.packetChars}),
1183
+ failure_code TEXT,
1184
+ failure_message TEXT,
1185
+ cancel_requested_at INTEGER,
1186
+ cancel_requested_by TEXT,
1187
+ cancel_reason TEXT,
1188
+ version INTEGER NOT NULL DEFAULT 0,
1189
+ created_at INTEGER NOT NULL,
1190
+ updated_at INTEGER NOT NULL,
1191
+ terminal_at INTEGER,
1192
+ UNIQUE (requester_kind, requester_id, idempotency_key),
1193
+ CHECK ((state IN (${i})) = (terminal_at IS NOT NULL)),
1194
+ CHECK (state <> 'failed' OR failure_code IS NOT NULL),
1195
+ CHECK ((mode = 'continue') = (destination_agent_id IS NOT NULL AND destination_conversation_id IS NOT NULL)),
1196
+ CHECK (destination_agent_id IS NULL OR destination_agent_id <> source_agent_id),
1197
+ CHECK (mode = 'continue' OR (packet IS NULL AND destination_request_id IS NULL AND destination_binding_id IS NULL)),
1198
+ CHECK (mode = 'ask' OR answer_message_id IS NULL),
1199
+ CHECK (state = 'queued' OR state = 'failed' OR state = 'cancelled' OR source_request_id IS NOT NULL),
1200
+ CHECK (state <> 'delivering' OR (packet IS NOT NULL AND destination_request_id IS NOT NULL)),
1201
+ FOREIGN KEY (origin_conversation_id) REFERENCES conversations(id),
1202
+ FOREIGN KEY (source_agent_id) REFERENCES bots(id),
1203
+ FOREIGN KEY (source_binding_id) REFERENCES session_bindings(id),
1204
+ FOREIGN KEY (destination_agent_id) REFERENCES bots(id),
1205
+ FOREIGN KEY (destination_conversation_id) REFERENCES conversations(id),
1206
+ FOREIGN KEY (destination_binding_id) REFERENCES session_bindings(id),
1207
+ FOREIGN KEY (source_request_id) REFERENCES work_requests(id),
1208
+ FOREIGN KEY (source_attempt_id) REFERENCES work_attempts(id),
1209
+ FOREIGN KEY (destination_request_id) REFERENCES work_requests(id),
1210
+ FOREIGN KEY (destination_attempt_id) REFERENCES work_attempts(id),
1211
+ FOREIGN KEY (answer_message_id) REFERENCES messages(id)
1212
+ );
1213
+ CREATE INDEX idx_session_exchanges_open ON session_exchanges(created_at) WHERE terminal_at IS NULL;
1214
+ CREATE INDEX idx_session_exchanges_binding ON session_exchanges(source_binding_id);
1215
+ CREATE UNIQUE INDEX idx_session_exchanges_source_request ON session_exchanges(source_request_id) WHERE source_request_id IS NOT NULL;
1216
+ CREATE UNIQUE INDEX idx_session_exchanges_destination_request ON session_exchanges(destination_request_id) WHERE destination_request_id IS NOT NULL;
1217
+
1218
+ CREATE TABLE session_exchange_events (
1219
+ id TEXT PRIMARY KEY,
1220
+ exchange_id TEXT NOT NULL,
1221
+ sequence INTEGER NOT NULL CHECK (sequence >= 1),
1222
+ type TEXT NOT NULL CHECK (length(type) > 0),
1223
+ data TEXT,
1224
+ created_at INTEGER NOT NULL,
1225
+ UNIQUE (exchange_id, sequence),
1226
+ FOREIGN KEY (exchange_id) REFERENCES session_exchanges(id)
1227
+ );
1228
+
1229
+ CREATE TRIGGER trg_session_exchanges_fk BEFORE INSERT ON session_exchanges
1230
+ BEGIN
1231
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.origin_conversation_id')
1232
+ WHERE NOT EXISTS (SELECT 1 FROM conversations WHERE id = NEW.origin_conversation_id);
1233
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.source_agent_id')
1234
+ WHERE NOT EXISTS (SELECT 1 FROM bots WHERE id = NEW.source_agent_id);
1235
+ SELECT RAISE(ABORT, 'session exchange source binding does not belong to its source agent')
1236
+ WHERE NOT EXISTS (SELECT 1 FROM session_bindings WHERE id = NEW.source_binding_id AND agent_id = NEW.source_agent_id);
1237
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.destination_agent_id')
1238
+ WHERE NEW.destination_agent_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM bots WHERE id = NEW.destination_agent_id);
1239
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.destination_conversation_id')
1240
+ WHERE NEW.destination_conversation_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM conversations WHERE id = NEW.destination_conversation_id);
1241
+ SELECT RAISE(ABORT, 'a session exchange starts queued')
1242
+ WHERE NEW.state <> 'queued';
1243
+ END;
1244
+
1245
+ -- Identity, target, and instruction are fixed at creation.
1246
+ CREATE TRIGGER trg_session_exchanges_immutable BEFORE UPDATE OF
1247
+ id, requester_kind, requester_id, idempotency_key, request_hash, mode, origin_conversation_id,
1248
+ source_agent_id, source_binding_id, destination_agent_id, destination_conversation_id, instruction, created_at
1249
+ ON session_exchanges
1250
+ BEGIN
1251
+ SELECT RAISE(ABORT, 'session_exchanges identity and target are immutable');
1252
+ END;
1253
+
1254
+ CREATE TRIGGER trg_session_exchanges_transition BEFORE UPDATE OF state ON session_exchanges
1255
+ WHEN NEW.state <> OLD.state
1256
+ BEGIN
1257
+ SELECT RAISE(ABORT, 'invalid session_exchanges state transition')
1258
+ WHERE (OLD.state || '>' || NEW.state) NOT IN (${t})
1259
+ OR (OLD.mode = 'ask' AND NEW.state = 'delivering')
1260
+ OR (OLD.mode = 'continue' AND OLD.state = 'extracting' AND NEW.state = 'completed');
1261
+ END;
1262
+
1263
+ CREATE TRIGGER trg_session_exchanges_terminal BEFORE UPDATE ON session_exchanges
1264
+ WHEN OLD.state IN (${i})
1265
+ BEGIN
1266
+ SELECT RAISE(ABORT, 'terminal session_exchanges are immutable');
1267
+ END;
1268
+
1269
+ -- Causal references, the packet, and the cancellation intent are
1270
+ -- recorded once; a set reference must name an existing row.
1271
+ CREATE TRIGGER trg_session_exchanges_set_once BEFORE UPDATE ON session_exchanges
1272
+ BEGIN
1273
+ SELECT RAISE(ABORT, 'session_exchanges references are set once')
1274
+ WHERE (OLD.source_request_id IS NOT NULL AND NEW.source_request_id IS NOT OLD.source_request_id)
1275
+ OR (OLD.source_attempt_id IS NOT NULL AND NEW.source_attempt_id IS NOT OLD.source_attempt_id)
1276
+ OR (OLD.destination_request_id IS NOT NULL AND NEW.destination_request_id IS NOT OLD.destination_request_id)
1277
+ OR (OLD.destination_attempt_id IS NOT NULL AND NEW.destination_attempt_id IS NOT OLD.destination_attempt_id)
1278
+ OR (OLD.destination_binding_id IS NOT NULL AND NEW.destination_binding_id IS NOT OLD.destination_binding_id)
1279
+ OR (OLD.answer_message_id IS NOT NULL AND NEW.answer_message_id IS NOT OLD.answer_message_id)
1280
+ OR (OLD.packet IS NOT NULL AND NEW.packet IS NOT OLD.packet)
1281
+ OR (OLD.cancel_requested_at IS NOT NULL AND (NEW.cancel_requested_at IS NOT OLD.cancel_requested_at
1282
+ OR NEW.cancel_requested_by IS NOT OLD.cancel_requested_by OR NEW.cancel_reason IS NOT OLD.cancel_reason));
1283
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.source_request_id')
1284
+ WHERE NEW.source_request_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM work_requests WHERE id = NEW.source_request_id AND target_agent_id = NEW.source_agent_id);
1285
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.source_attempt_id')
1286
+ WHERE NEW.source_attempt_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM work_attempts WHERE id = NEW.source_attempt_id AND request_id = NEW.source_request_id);
1287
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.destination_request_id')
1288
+ WHERE NEW.destination_request_id IS NOT NULL AND NOT EXISTS (
1289
+ SELECT 1 FROM work_requests WHERE id = NEW.destination_request_id AND target_agent_id = NEW.destination_agent_id
1290
+ AND source_conversation_id = NEW.destination_conversation_id);
1291
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.destination_attempt_id')
1292
+ WHERE NEW.destination_attempt_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM work_attempts WHERE id = NEW.destination_attempt_id AND request_id = NEW.destination_request_id);
1293
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.destination_binding_id')
1294
+ WHERE NEW.destination_binding_id IS NOT NULL AND NOT EXISTS (
1295
+ SELECT 1 FROM session_bindings WHERE id = NEW.destination_binding_id AND agent_id = NEW.destination_agent_id
1296
+ AND request_id = NEW.destination_request_id AND id <> NEW.source_binding_id);
1297
+ -- The answer is the source Agent's message in the origin
1298
+ -- conversation, produced by the source hop request.
1299
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.answer_message_id')
1300
+ WHERE NEW.answer_message_id IS NOT NULL AND NOT EXISTS (
1301
+ SELECT 1 FROM messages WHERE id = NEW.answer_message_id AND conversation_id = NEW.origin_conversation_id
1302
+ AND sender_type = 'bot' AND sender_id = NEW.source_agent_id
1303
+ AND NEW.source_request_id IS NOT NULL AND request_id = NEW.source_request_id);
1304
+ END;
1305
+
1306
+ CREATE TRIGGER trg_session_exchange_events_fk BEFORE INSERT ON session_exchange_events
1307
+ BEGIN
1308
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchange_events.exchange_id')
1309
+ WHERE NOT EXISTS (SELECT 1 FROM session_exchanges WHERE id = NEW.exchange_id);
1310
+ END;
1311
+ CREATE TRIGGER trg_session_exchange_events_append_only BEFORE UPDATE ON session_exchange_events
1312
+ BEGIN
1313
+ SELECT RAISE(ABORT, 'session_exchange_events are append-only');
1314
+ END;
1315
+ -- Removed only with their exchange, by the aggregate cleanup
1316
+ -- (deleteSessionExchanges), under the same purge authority as
1317
+ -- engine events.
1318
+ CREATE TRIGGER trg_session_exchange_events_no_delete BEFORE DELETE ON session_exchange_events
1319
+ BEGIN
1320
+ SELECT RAISE(ABORT, 'session_exchange_events are append-only')
1321
+ WHERE NOT engine_event_purge_authorized(OLD.exchange_id);
1322
+ END;
1323
+ CREATE TRIGGER trg_session_exchanges_restrict BEFORE DELETE ON session_exchanges
1324
+ BEGIN
1325
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchange_events.exchange_id')
1326
+ WHERE EXISTS (SELECT 1 FROM session_exchange_events WHERE exchange_id = OLD.id);
1327
+ END;
1328
+
1329
+ -- Foreign keys (delete side): RESTRICT, as for the engine tables.
1330
+ CREATE TRIGGER trg_conversations_exchange_restrict BEFORE DELETE ON conversations
1331
+ BEGIN
1332
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.conversation')
1333
+ WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE origin_conversation_id = OLD.id OR destination_conversation_id = OLD.id);
1334
+ END;
1335
+ CREATE TRIGGER trg_bots_exchange_restrict BEFORE DELETE ON bots
1336
+ BEGIN
1337
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.agent')
1338
+ WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE source_agent_id = OLD.id OR destination_agent_id = OLD.id);
1339
+ END;
1340
+ CREATE TRIGGER trg_session_bindings_exchange_restrict BEFORE DELETE ON session_bindings
1341
+ BEGIN
1342
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.binding')
1343
+ WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE source_binding_id = OLD.id OR destination_binding_id = OLD.id);
1344
+ END;
1345
+ CREATE TRIGGER trg_work_requests_exchange_restrict BEFORE DELETE ON work_requests
1346
+ BEGIN
1347
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.request')
1348
+ WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE source_request_id = OLD.id OR destination_request_id = OLD.id);
1349
+ END;
1350
+ CREATE TRIGGER trg_messages_exchange_restrict BEFORE DELETE ON messages
1351
+ BEGIN
1352
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.answer_message_id')
1353
+ WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE answer_message_id = OLD.id);
1354
+ END;
1355
+ CREATE TRIGGER trg_work_attempts_exchange_restrict BEFORE DELETE ON work_attempts
1356
+ BEGIN
1357
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: session_exchanges.attempt')
1358
+ WHERE EXISTS (SELECT 1 FROM session_exchanges WHERE source_attempt_id = OLD.id OR destination_attempt_id = OLD.id);
1359
+ END;
1360
+ `)}},{version:17,name:"provider_sessions",up:e=>{var t;e.exec(`
1361
+ -- One row per native runtime session Botmancers knows, under a
1362
+ -- stable Botmancers reference (id). provider_session_id is private:
1363
+ -- only the owner-only local debug disclosure ever returns it. A row
1364
+ -- linked to a Session Binding uses the binding's id as its id.
1365
+ -- availability/lifecycle/resumable/busy are independent provider
1366
+ -- facts; resumable NULL means the provider was never asked.
1367
+ CREATE TABLE provider_sessions (
1368
+ id TEXT PRIMARY KEY,
1369
+ agent_id TEXT NOT NULL,
1370
+ runtime_connection_id TEXT NOT NULL,
1371
+ provider_kind TEXT NOT NULL,
1372
+ provider_session_id TEXT NOT NULL,
1373
+ binding_id TEXT UNIQUE,
1374
+ origin TEXT NOT NULL CHECK (origin IN ('binding', 'discovered', 'started')),
1375
+ title TEXT,
1376
+ workspace TEXT,
1377
+ provider_created_at INTEGER,
1378
+ provider_updated_at INTEGER,
1379
+ availability TEXT NOT NULL DEFAULT 'available' CHECK (availability IN ('available', 'missing')),
1380
+ lifecycle TEXT NOT NULL DEFAULT 'open' CHECK (lifecycle IN ('open', 'archived')),
1381
+ resumable INTEGER CHECK (resumable IS NULL OR resumable IN (0, 1)),
1382
+ busy INTEGER NOT NULL DEFAULT 0 CHECK (busy IN (0, 1)),
1383
+ capabilities TEXT,
1384
+ last_synced_at INTEGER,
1385
+ created_at INTEGER NOT NULL,
1386
+ updated_at INTEGER NOT NULL,
1387
+ CHECK (origin <> 'binding' OR binding_id = id),
1388
+ FOREIGN KEY (agent_id) REFERENCES bots(id),
1389
+ FOREIGN KEY (binding_id) REFERENCES session_bindings(id)
1390
+ );
1391
+ -- Repeated discovery is idempotent: at most one unlinked row per
1392
+ -- (Agent, connection, provider session). The same provider id on
1393
+ -- another connection or Agent is another session.
1394
+ CREATE UNIQUE INDEX idx_provider_sessions_native
1395
+ ON provider_sessions(agent_id, runtime_connection_id, provider_session_id) WHERE binding_id IS NULL;
1396
+ CREATE INDEX idx_provider_sessions_lookup
1397
+ ON provider_sessions(agent_id, runtime_connection_id, provider_session_id);
1398
+
1399
+ -- One row per provider turn Botmancers started (start or send),
1400
+ -- keyed by the requester's idempotency key. provider_turn_id is
1401
+ -- private.
1402
+ CREATE TABLE provider_session_turns (
1403
+ id TEXT PRIMARY KEY,
1404
+ session_ref TEXT NOT NULL,
1405
+ agent_id TEXT NOT NULL,
1406
+ kind TEXT NOT NULL CHECK (kind IN ('start', 'send')),
1407
+ authority TEXT NOT NULL CHECK (authority IN ('read_only', 'workspace_write')),
1408
+ requester_kind TEXT NOT NULL,
1409
+ requester_id TEXT NOT NULL,
1410
+ idempotency_key TEXT NOT NULL,
1411
+ request_hash TEXT NOT NULL,
1412
+ provider_turn_id TEXT NOT NULL,
1413
+ state TEXT NOT NULL CHECK (state IN ('running', 'completed', 'failed', 'cancelled')),
1414
+ output TEXT,
1415
+ failure_code TEXT,
1416
+ correlation TEXT NOT NULL,
1417
+ created_at INTEGER NOT NULL,
1418
+ finished_at INTEGER,
1419
+ UNIQUE (agent_id, requester_kind, requester_id, idempotency_key),
1420
+ FOREIGN KEY (session_ref) REFERENCES provider_sessions(id)
1421
+ );
1422
+ CREATE INDEX idx_provider_session_turns_session ON provider_session_turns(session_ref, created_at);
1423
+
1424
+ -- Append-only audit of registry syncs and provider turns. Names
1425
+ -- Botmancers rows only, never a provider id.
1426
+ CREATE TABLE provider_session_events (
1427
+ id TEXT PRIMARY KEY,
1428
+ agent_id TEXT NOT NULL,
1429
+ session_ref TEXT,
1430
+ turn_id TEXT,
1431
+ type TEXT NOT NULL,
1432
+ detail TEXT NOT NULL,
1433
+ created_at INTEGER NOT NULL
1434
+ );
1435
+ CREATE INDEX idx_provider_session_events_agent ON provider_session_events(agent_id, created_at);
1436
+
1437
+ CREATE TRIGGER trg_provider_sessions_fk BEFORE INSERT ON provider_sessions
1438
+ BEGIN
1439
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: provider_sessions.agent_id')
1440
+ WHERE NOT EXISTS (SELECT 1 FROM bots WHERE id = NEW.agent_id);
1441
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: provider_sessions.binding_id')
1442
+ WHERE NEW.binding_id IS NOT NULL
1443
+ AND NOT EXISTS (SELECT 1 FROM session_bindings WHERE id = NEW.binding_id AND agent_id = NEW.agent_id);
1444
+ END;
1445
+ CREATE TRIGGER trg_provider_sessions_identity BEFORE UPDATE OF
1446
+ id, agent_id, runtime_connection_id, provider_kind, provider_session_id, origin, created_at
1447
+ ON provider_sessions
1448
+ BEGIN
1449
+ SELECT RAISE(ABORT, 'provider_sessions identity is immutable');
1450
+ END;
1451
+ CREATE TRIGGER trg_provider_session_turns_fk BEFORE INSERT ON provider_session_turns
1452
+ BEGIN
1453
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: provider_session_turns.session_ref')
1454
+ WHERE NOT EXISTS (SELECT 1 FROM provider_sessions WHERE id = NEW.session_ref AND agent_id = NEW.agent_id);
1455
+ END;
1456
+ CREATE TRIGGER trg_provider_session_events_append_only BEFORE UPDATE ON provider_session_events
1457
+ BEGIN
1458
+ SELECT RAISE(ABORT, 'provider_session_events are append-only');
1459
+ END;
1460
+ -- Delete side: the Agent and binding delete paths
1461
+ -- (deleteEngineRecordsForAgent / deleteEngineRecords) remove or
1462
+ -- unlink registry rows first; the catalog joins bots, so a raw
1463
+ -- delete never surfaces an orphan.
1464
+ CREATE TRIGGER trg_provider_sessions_restrict BEFORE DELETE ON provider_sessions
1465
+ BEGIN
1466
+ SELECT RAISE(ABORT, 'FOREIGN KEY constraint failed: provider_session_turns.session_ref')
1467
+ WHERE EXISTS (SELECT 1 FROM provider_session_turns WHERE session_ref = OLD.id);
1468
+ END;
1469
+ `),(t=e).prepare(`
1470
+ INSERT INTO provider_sessions (
1471
+ id, agent_id, runtime_connection_id, provider_kind, provider_session_id, binding_id, origin,
1472
+ availability, lifecycle, resumable, busy, created_at, updated_at
1473
+ )
1474
+ SELECT b.id, b.agent_id, ${eX(t)}, b.adapter, b.external_session_id, b.id, 'binding',
1475
+ 'available', 'open', NULL, 0, b.created_at, COALESCE(b.released_at, b.created_at)
1476
+ FROM session_bindings b
1477
+ JOIN bots bot ON bot.id = b.agent_id
1478
+ WHERE NOT EXISTS (SELECT 1 FROM provider_sessions p WHERE p.binding_id = b.id)
1479
+ ORDER BY b.created_at ASC, b.id ASC
1480
+ `).run()}},{version:18,name:"usage_samples",up:e=>{e.exec(`
1481
+ -- One row per Attempt or provider turn that reached a runtime,
1482
+ -- keyed by sample_key (attempt:<id> or turn:<id>), so a replayed
1483
+ -- terminal result, a reconciled Attempt after a restart, or a late
1484
+ -- result never adds a second row. Each metric is nullable: NULL is
1485
+ -- not reported, 0 is an explicit provider zero. breakdown holds
1486
+ -- whitelisted numeric counters only. Pre-existing Attempts get no
1487
+ -- row: their usage was never reported.
1488
+ CREATE TABLE usage_samples (
1489
+ id TEXT PRIMARY KEY,
1490
+ sample_key TEXT NOT NULL UNIQUE,
1491
+ agent_id TEXT NOT NULL,
1492
+ attempt_id TEXT,
1493
+ session_ref TEXT,
1494
+ turn_id TEXT,
1495
+ provider TEXT NOT NULL,
1496
+ source TEXT NOT NULL CHECK (source IN ('codex.turn_completed', 'result', 'normalized', 'none')),
1497
+ input_tokens INTEGER CHECK (input_tokens IS NULL OR input_tokens >= 0),
1498
+ output_tokens INTEGER CHECK (output_tokens IS NULL OR output_tokens >= 0),
1499
+ cost_usd REAL CHECK (cost_usd IS NULL OR cost_usd >= 0),
1500
+ breakdown TEXT,
1501
+ observed_at INTEGER NOT NULL,
1502
+ created_at INTEGER NOT NULL,
1503
+ updated_at INTEGER NOT NULL,
1504
+ CHECK (attempt_id IS NOT NULL OR turn_id IS NOT NULL)
1505
+ );
1506
+ CREATE INDEX idx_usage_samples_attempt ON usage_samples(attempt_id);
1507
+ CREATE INDEX idx_usage_samples_session ON usage_samples(session_ref);
1508
+ CREATE INDEX idx_usage_samples_agent ON usage_samples(agent_id);
1509
+ `)}},{version:19,name:"provider_turn_usage",up:e=>{e.exec(`
1510
+ ALTER TABLE provider_session_turns ADD COLUMN input_tokens INTEGER;
1511
+ ALTER TABLE provider_session_turns ADD COLUMN output_tokens INTEGER;
1512
+ ALTER TABLE provider_session_turns ADD COLUMN total_cost_usd REAL;
1513
+ `)}},{version:20,name:"session_pins",up:e=>{e.exec(`
1514
+ -- One row per pin. session_ref never changes after insert: a switch
1515
+ -- detaches this pin and creates another. action/authority record
1516
+ -- what the caller asked for (ask = read_only, resume =
1517
+ -- workspace_write after explicit approval); resolution how the
1518
+ -- session was chosen (exact, or for a registered-Agent message the
1519
+ -- home session, the newest eligible one, or a newly started one).
1520
+ CREATE TABLE session_pins (
1521
+ id TEXT PRIMARY KEY,
1522
+ requester_kind TEXT NOT NULL CHECK (requester_kind IN ('person', 'bot', 'service')),
1523
+ requester_id TEXT NOT NULL,
1524
+ idempotency_key TEXT NOT NULL,
1525
+ request_hash TEXT NOT NULL,
1526
+ agent_id TEXT NOT NULL,
1527
+ session_ref TEXT NOT NULL,
1528
+ action TEXT NOT NULL CHECK (action IN ('ask', 'resume')),
1529
+ authority TEXT NOT NULL CHECK (authority IN ('read_only', 'workspace_write')),
1530
+ resolution TEXT NOT NULL CHECK (resolution IN ('exact', 'home', 'newest', 'started')),
1531
+ route TEXT NOT NULL CHECK (route IN ('provider', 'engine')),
1532
+ conversation_id TEXT NOT NULL,
1533
+ approved_at INTEGER,
1534
+ state TEXT NOT NULL CHECK (state IN ('attached', 'detached')),
1535
+ detach_reason TEXT CHECK (detach_reason IS NULL OR detach_reason IN ('detached', 'switched')),
1536
+ replaced_by TEXT,
1537
+ created_at INTEGER NOT NULL,
1538
+ updated_at INTEGER NOT NULL,
1539
+ detached_at INTEGER,
1540
+ CHECK (authority = CASE action WHEN 'ask' THEN 'read_only' ELSE 'workspace_write' END),
1541
+ CHECK (action = 'ask' OR approved_at IS NOT NULL),
1542
+ CHECK ((state = 'attached') = (detached_at IS NULL)),
1543
+ UNIQUE (requester_kind, requester_id, idempotency_key)
1544
+ );
1545
+ CREATE INDEX idx_session_pins_session ON session_pins(session_ref);
1546
+ CREATE INDEX idx_session_pins_agent ON session_pins(agent_id);
1547
+ CREATE TRIGGER trg_session_pins_identity BEFORE UPDATE OF
1548
+ id, requester_kind, requester_id, idempotency_key, request_hash, agent_id, session_ref, action, authority, resolution, route, created_at
1549
+ ON session_pins
1550
+ BEGIN
1551
+ SELECT RAISE(ABORT, 'session_pins identity is immutable');
1552
+ END;
1553
+
1554
+ -- One row per turn sent through a pin, in order. Exactly one of
1555
+ -- exchange_id (engine route: an Ask exchange on the binding) and
1556
+ -- provider_turn_ref (provider route) is set.
1557
+ CREATE TABLE session_pin_turns (
1558
+ id TEXT PRIMARY KEY,
1559
+ pin_id TEXT NOT NULL,
1560
+ seq INTEGER NOT NULL,
1561
+ requester_kind TEXT NOT NULL,
1562
+ requester_id TEXT NOT NULL,
1563
+ idempotency_key TEXT NOT NULL,
1564
+ request_hash TEXT NOT NULL,
1565
+ content TEXT NOT NULL,
1566
+ exchange_id TEXT,
1567
+ provider_turn_ref TEXT,
1568
+ question_message_id TEXT,
1569
+ answer_message_id TEXT,
1570
+ created_at INTEGER NOT NULL,
1571
+ CHECK ((exchange_id IS NULL) <> (provider_turn_ref IS NULL)),
1572
+ UNIQUE (pin_id, seq),
1573
+ UNIQUE (requester_kind, requester_id, idempotency_key),
1574
+ FOREIGN KEY (pin_id) REFERENCES session_pins(id)
1575
+ );
1576
+
1577
+ -- Append-only audit of every pin decision: created (with the
1578
+ -- resolution), turn sent, turn refused (with the stable code; the
1579
+ -- target never changes), detached, switched.
1580
+ CREATE TABLE session_pin_events (
1581
+ id TEXT PRIMARY KEY,
1582
+ pin_id TEXT NOT NULL,
1583
+ sequence INTEGER NOT NULL,
1584
+ type TEXT NOT NULL,
1585
+ data TEXT NOT NULL,
1586
+ created_at INTEGER NOT NULL,
1587
+ UNIQUE (pin_id, sequence)
1588
+ );
1589
+ CREATE TRIGGER trg_session_pin_events_append_only BEFORE UPDATE ON session_pin_events
1590
+ BEGIN
1591
+ SELECT RAISE(ABORT, 'session_pin_events are append-only');
1592
+ END;
1593
+ `)}}];function eX(e){return e.prepare("PRAGMA table_info(bots)").all().some(e=>"runtime_connection_id"===e.name)?"COALESCE(bot.runtime_connection_id, 'rc-local-' || b.adapter)":"'rc-local-' || b.adapter"}let ex=new WeakMap;function eG(e){let t=ex.get(e);if(!t){t=new Set,ex.set(e,t);let n=t;e.function("engine_event_purge_authorized",{deterministic:!1},e=>"string"==typeof e&&n.has(e)?1:0)}return t}function eH(e,t={}){eG(e),e.exec(`
1594
+ CREATE TABLE IF NOT EXISTS schema_migrations (
1595
+ version INTEGER PRIMARY KEY,
1596
+ name TEXT NOT NULL,
1597
+ applied_at INTEGER NOT NULL
1598
+ );
1599
+ `);let n=e.prepare("SELECT 1 FROM schema_migrations WHERE version = ?"),i=e.prepare("INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)");for(let r of eW){if(void 0!==t.through&&r.version>t.through)return;e.transaction(()=>{n.get(r.version)||(r.up(e),i.run(r.version,r.name,Date.now()))}).immediate()}}function eB(e){return eJ(JSON.stringify([e.sourceConversationId,e.sourceEventId,e.targetAgentId,e.intent,e.executionKind,e.toolProfile,e.parentRequestId??null,e.wakeEventId??null,e.policy??null]))}eW[eW.length-1].version;let eM="legacy_interrupted",eK="Accepted before NOT-465 by the retired agent_requests dispatcher; it never reached a terminal state.",eY=Object.freeze({kind:"service",id:"botmancers-ui-turns"});function eP(e){let t=en(e?{entryPoint:"wake",executionKind:"conversation",wakeSyntax:"legacy"}:{entryPoint:"ui",executionKind:"conversation"});if(!t.ok)throw new eD("invalid_input",t.reason);return t.policy}let e$="ui_turn_interrupted",ez="The UI turn was interrupted before it finished; it is not run again.";function ej(e){return"string"==typeof e&&e.trim().length>0}function eJ(e){return(0,s.createHash)("sha256").update(e).digest("hex")}function eQ(e){return null==e?null:JSON.stringify(e)}function eV(e){eG(e);let t=e.prepare("SELECT * FROM work_requests WHERE id = ?"),n=e.prepare("SELECT * FROM work_requests WHERE requester_kind = ? AND requester_id = ? AND idempotency_key = ?"),i=e.prepare("SELECT * FROM work_attempts WHERE id = ?"),r=e.prepare(`
1600
+ INSERT INTO engine_events (id, request_id, sequence, attempt_id, type, data, created_at)
1601
+ SELECT ?, ?, COALESCE(MAX(sequence), 0) + 1, ?, ?, ?, ? FROM engine_events WHERE request_id = ?
1602
+ `),a=e.prepare("SELECT * FROM engine_events WHERE id = ?"),o=e.prepare("SELECT * FROM session_bindings WHERE id = ?");function _(e){let n=t.get(e);if(!n)throw new eD("not_found",`No work request ${e}.`);return n}function d(e){let t=i.get(e);if(!t)throw new eD("not_found",`No attempt ${e}.`);return t}function E(e,t,n,i,o){let _=(0,s.randomUUID)();return r.run(_,e,i,t,eQ(n),o,e),a.get(_)}let u={transaction:t=>e.transaction(t).immediate(),createOrGetWorkRequest(i){if(!ej(i.sourceConversationId))throw new eD("invalid_input","sourceConversationId is required.");if(!ej(i.sourceEventId))throw new eD("invalid_input","sourceEventId is required.");if(!i.requester||!["person","bot","service"].includes(i.requester.kind)||!ej(i.requester.id))throw new eD("invalid_input","A requester principal is required.");if(!ej(i.targetAgentId))throw new eD("invalid_input","targetAgentId is required.");if("string"!=typeof i.intent)throw new eD("invalid_input","intent is required.");if(!ee(i.executionKind))throw new eD("invalid_input","Unknown execution kind.");if(Z[i.executionKind]!==i.toolProfile)throw new eD("invalid_input",`Execution kind ${i.executionKind} requires the ${Z[i.executionKind]} tool profile.`);if(i.policy&&Object.prototype.hasOwnProperty.call(i.policy,"execution_policy"))throw new eD("invalid_input","The execution policy is passed as executionPolicy, never inside policy.");if(void 0!==i.executionPolicy){let e=er(i.executionPolicy);if(!e.ok)throw new eD("invalid_input",e.reason);if(e.policy.execution_kind!==i.executionKind||e.policy.tool_profile!==i.toolProfile)throw new eD("invalid_input","The execution policy does not match the requested execution kind and tool profile.")}if(!ej(i.idempotencyKey))throw new eD("invalid_input","idempotencyKey is required.");if(void 0!==i.executor&&!eb.includes(i.executor))throw new eD("invalid_input","Unknown request executor.");if(i.initialState&&"queued"!==i.initialState&&"blocked"!==i.initialState)throw new eD("invalid_input","A work request starts queued or blocked.");if(void 0!==i.deadlineAt&&null!==i.deadlineAt&&!Number.isSafeInteger(i.deadlineAt))throw new eD("invalid_input","deadlineAt must be an epoch millisecond integer.");if(void 0!==i.retryPolicy){let e=e_(i.retryPolicy);if(!e.ok)throw new eD("invalid_input",e.reason)}let r=i.executionPolicy?{...i.policy??{},execution_policy:i.executionPolicy}:i.policy,a=eB({...i,policy:r});return e.transaction(()=>{let o=n.get(i.requester.kind,i.requester.id,i.idempotencyKey);if(o){if(o.request_hash!==a)throw new eD("idempotency_conflict","The idempotency key was already used with a different request.");return{request:o,created:!1}}let d=i.now??Date.now(),c=(0,s.randomUUID)(),l=c,T=0,p=0,N=i.rootPrincipal??i.requester;if(i.parentRequestId){let e=t.get(i.parentRequestId);if(!e)throw new eD("not_found","Parent work request not found.");l=e.root_request_id,T=e.depth+1,p=i.wakeEventId?e.wake_depth+1:e.wake_depth,N={kind:e.root_principal_kind??"unknown",id:e.root_principal_id??"unknown"}}void 0!==i.wakeDepth&&(p=i.wakeDepth);let R=i.initialState??"queued",m=JSON.stringify({...r??{},...i.safetySnapshot??{},tool_profile:i.toolProfile}),L=eo(),g=i.retryPolicy??L.retryPolicy,O=void 0!==i.deadlineAt?i.deadlineAt:null===L.deadlineMs?null:d+L.deadlineMs;return e.prepare(`
1603
+ INSERT INTO work_requests (
1604
+ id, source_conversation_id, source_event_id, requester_kind, requester_id, target_agent_id,
1605
+ intent, execution_kind, tool_profile, parent_request_id, root_request_id, wake_event_id, depth,
1606
+ idempotency_key, request_hash, policy_snapshot, state, state_reason, version, created_at, updated_at,
1607
+ deadline_at, retry_policy, wake_depth, root_principal_kind, root_principal_id, executor
1608
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?, ?, ?, ?, ?, ?)
1609
+ `).run(c,i.sourceConversationId,i.sourceEventId,i.requester.kind,i.requester.id,i.targetAgentId,i.intent,i.executionKind,i.toolProfile,i.parentRequestId??null,l,i.wakeEventId??null,T,i.idempotencyKey,a,m,R,i.stateReason??null,d,d,O,JSON.stringify(g),p,N.kind,N.id,i.executor??"dispatcher"),E(c,"accepted",{state:R,execution_kind:i.executionKind,tool_profile:i.toolProfile,deadline_at:O,retry_policy:g},null,d),i.executionPolicy&&E(c,"policy_selected",{...i.executionPolicy},null,d),"blocked"===R&&E(c,"state_changed",{from:"queued",to:"blocked",reason:i.stateReason??null},null,d),i.safety&&u.recordSafetyDecision(c,{...i.safety,now:i.safety.now??d}),{request:_(c),created:!0}}).immediate()},getWorkRequest:e=>t.get(e),recordSafetyDecision(t,n){if(!["human_owner","api_principal","agent_principal","engine"].includes(n.principalType))throw new eD("invalid_input","A categorized principal is required.");if(!ej(n.principal?.kind)||!ej(n.principal?.id))throw new eD("invalid_input","A principal is required.");if(!["allowed","blocked","denied"].includes(n.decision))throw new eD("invalid_input","Unknown safety decision.");if("allowed"===n.decision&&!ej(n.grantRule))throw new eD("invalid_input","An allowed decision names its grant rule.");return e.transaction(()=>{let i=_(t),r=(0,s.randomUUID)();return e.prepare(`
1610
+ INSERT INTO wake_safety_decisions (
1611
+ id, request_id, sequence, wake_id, principal_type, principal_kind, principal_id, target_agent_id, execution_kind,
1612
+ decision, reason_code, grant_rule, grant_id, policy_snapshot, created_at
1613
+ ) SELECT ?, ?, COALESCE(MAX(sequence), 0) + 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM wake_safety_decisions WHERE request_id = ?
1614
+ `).run(r,t,n.wakeId??null,n.principalType,n.principal.kind,n.principal.id,i.target_agent_id,i.execution_kind,n.decision,n.reasonCode??null,n.grantRule??null,n.grantId??null,JSON.stringify(n.snapshot),n.now??Date.now(),t),e.prepare("SELECT * FROM wake_safety_decisions WHERE id = ?").get(r)}).immediate()},listSafetyDecisions:t=>e.prepare("SELECT * FROM wake_safety_decisions WHERE request_id = ? ORDER BY sequence ASC").all(t),latestSafetyDecision:t=>e.prepare("SELECT * FROM wake_safety_decisions WHERE request_id = ? ORDER BY sequence DESC LIMIT 1").get(t),transitionWorkRequest(t,n){if(!ey[n.from]?.includes(n.to))throw new eD("invalid_transition",`Cannot move a work request from ${n.from} to ${n.to}.`);let i=eq.includes(n.to);return e.transaction(()=>{let r=_(t),s=n.now??Date.now();if(1!==e.prepare(`
1615
+ UPDATE work_requests SET
1616
+ state = ?, state_reason = ?, version = version + 1, updated_at = ?,
1617
+ result = ?, error_code = ?, error_message = ?, terminal_at = ?
1618
+ WHERE id = ? AND state = ? AND (? IS NULL OR version = ?)
1619
+ `).run(n.to,n.reason??null,s,i?eQ(n.result):null,i?n.errorCode??null:null,i?n.errorMessage??null:null,i?s:null,t,n.from,n.expectedVersion??null,n.expectedVersion??null).changes)throw new eD("stale_state",`Work request ${t} is ${r.state} at version ${r.version}, not ${n.from}${void 0===n.expectedVersion?"":` at version ${n.expectedVersion}`}.`);return E(t,"state_changed",{...n.data??{},from:n.from,to:n.to,reason:n.reason??null,...n.errorCode?{error_code:n.errorCode}:{}},null,s),i&&null===r.legacy_agent_request_id&&"dispatcher"===r.executor&&e.prepare("INSERT OR IGNORE INTO terminal_followups (request_id, created_at) VALUES (?, ?)").run(t,s),_(t)}).immediate()},reblockWorkRequest:(t,n)=>e.transaction(()=>{let i=n.now??Date.now();if(1!==e.prepare("UPDATE work_requests SET state_reason = ?, version = version + 1, updated_at = ? WHERE id = ? AND state = 'blocked'").run(n.reason,i,t).changes)throw new eD("stale_state",`Work request ${t} is not blocked.`);return E(t,n.type,n.data??{},null,i),_(t)}).immediate(),appendEvent(t,n){if(!ej(n.type))throw new eD("invalid_input","Event type is required.");return e.transaction(()=>{if(_(t),n.attemptId&&d(n.attemptId).request_id!==t)throw new eD("invalid_input","The attempt belongs to another request.");return E(t,n.type,n.data,n.attemptId??null,n.now??Date.now())}).immediate()},listEvents:t=>e.prepare("SELECT * FROM engine_events WHERE request_id = ? ORDER BY sequence ASC").all(t),createAttempt(t,n){if("launch"!==n.kind&&"resume"!==n.kind)throw new eD("invalid_input","Unknown attempt kind.");if(!ej(n.adapter))throw new eD("invalid_input","adapter is required.");if("resume"===n.kind&&!n.resumedSessionBindingId)throw new eD("invalid_input","A resume attempt names the session binding it resumes.");if("launch"===n.kind&&n.resumedSessionBindingId)throw new eD("invalid_input","A launch attempt does not resume a session binding.");let i="string"==typeof n.launchSnapshot?n.launchSnapshot:JSON.stringify(n.launchSnapshot);if("string"!=typeof i||0===i.length)throw new eD("invalid_input","A launch snapshot is required.");return e.transaction(()=>{let r=_(t);if("running"!==r.state)throw new eD("attempt_conflict",`Attempts start only on running requests (request is ${r.state}).`);if(n.toolProfile!==r.tool_profile)throw new eD("invalid_input",`The attempt tool profile must be ${r.tool_profile}.`);if(e.prepare("SELECT id FROM work_attempts WHERE request_id = ? AND finished_at IS NULL").get(t))throw new eD("attempt_conflict","The request already has an open attempt.");if(n.resumedSessionBindingId){let e=o.get(n.resumedSessionBindingId);if(!e)throw new eD("not_found","Session binding not found.");if(null!==e.released_at)throw new eD("session_mismatch","The session binding was released.");if(e.agent_id!==r.target_agent_id||e.adapter!==n.adapter)throw new eD("session_mismatch","The session binding belongs to another Agent or adapter.");if(null!==e.conversation_id&&e.conversation_id!==r.source_conversation_id)throw new eD("session_mismatch","The session binding belongs to another conversation.");if(null!==e.request_id&&_(e.request_id).root_request_id!==r.root_request_id)throw new eD("session_mismatch","The session binding belongs to an unrelated work request.")}let a=n.now??Date.now(),u=(0,s.randomUUID)(),c=e.prepare("SELECT COALESCE(MAX(attempt_number), 0) + 1 AS n FROM work_attempts WHERE request_id = ?").get(t);return e.prepare(`
1620
+ INSERT INTO work_attempts (
1621
+ id, request_id, attempt_number, kind, adapter, tool_profile, launch_snapshot, launch_snapshot_hash,
1622
+ resumed_session_binding_id, external_run_id, external_session_id, started_at
1623
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1624
+ `).run(u,t,c.n,n.kind,n.adapter,n.toolProfile,i,eJ(i),n.resumedSessionBindingId??null,n.externalRunId??null,n.externalSessionId??null,a),E(t,"attempt_started",{attempt_number:c.n,kind:n.kind,adapter:n.adapter},u,a),d(u)}).immediate()},recordAttemptExternalIds:(t,n)=>e.transaction(()=>{let i=d(t);if(null!==i.finished_at)throw new eD("attempt_conflict","The attempt is already finished.");return e.prepare("UPDATE work_attempts SET external_run_id = ?, external_session_id = ? WHERE id = ?").run(void 0===n.externalRunId?i.external_run_id:n.externalRunId,void 0===n.externalSessionId?i.external_session_id:n.externalSessionId,t),d(t)}).immediate(),finishAttempt(t,n){if(!["succeeded","failed","cancelled","interrupted","timed_out"].includes(n.outcome))throw new eD("invalid_input","Unknown attempt outcome.");return e.transaction(()=>{let i=d(t);if(null!==i.finished_at)throw new eD("attempt_conflict","The attempt is already finished.");let r=n.now??Date.now();return e.prepare(`
1625
+ UPDATE work_attempts SET outcome = ?, output = ?, error_category = ?, error_message = ?, artifacts = ?,
1626
+ external_run_id = ?, external_session_id = ?, finished_at = ?
1627
+ WHERE id = ? AND finished_at IS NULL
1628
+ `).run(n.outcome,n.output??null,n.errorCategory??null,n.errorMessage??null,JSON.stringify(n.artifacts??[]),void 0===n.externalRunId?i.external_run_id:n.externalRunId,void 0===n.externalSessionId?i.external_session_id:n.externalSessionId,r,t),E(i.request_id,"attempt_finished",{attempt_number:i.attempt_number,outcome:n.outcome,error_category:n.errorCategory??null},t,r),d(t)}).immediate()},recordAttemptUsage(t,n){let i=d(t);eA(e,t,{agentId:_(i.request_id).target_agent_id,provider:i.adapter,usage:n.usage,observedAt:n.observedAt,now:n.now})},getAttempt:e=>i.get(e),listAttempts:t=>e.prepare("SELECT * FROM work_attempts WHERE request_id = ? ORDER BY attempt_number ASC").all(t),bindSession(t){if(!ej(t.agentId))throw new eD("invalid_input","agentId is required.");if(!ej(t.adapter))throw new eD("invalid_input","adapter is required.");if(!ej(t.externalSessionId))throw new eD("invalid_input","externalSessionId is required.");if(!t.conversationId&&!t.requestId)throw new eD("invalid_input","A session binding is scoped to a conversation or work request.");return e.transaction(()=>{let n=t.now??Date.now();if(!e.prepare("SELECT 1 FROM bots WHERE id = ?").get(t.agentId))throw new eD("not_found",`No agent ${t.agentId}.`);if(t.requestId){let e=_(t.requestId);if(e.target_agent_id!==t.agentId)throw new eD("session_mismatch","The work request targets another Agent.");if(t.conversationId&&e.source_conversation_id!==t.conversationId)throw new eD("session_mismatch","The work request belongs to another conversation.")}if(t.sourceAttemptId){let e=d(t.sourceAttemptId),n=_(e.request_id);if(e.adapter!==t.adapter||n.target_agent_id!==t.agentId)throw new eD("session_mismatch","The source attempt ran another Agent or adapter.");if(t.requestId&&e.request_id!==t.requestId)throw new eD("session_mismatch","The source attempt belongs to another work request.");if(t.conversationId&&n.source_conversation_id!==t.conversationId)throw new eD("session_mismatch","The source attempt belongs to another conversation.")}e.prepare(`
1629
+ UPDATE session_bindings SET released_at = ?
1630
+ WHERE agent_id = ? AND adapter = ? AND IFNULL(conversation_id, '') = ? AND IFNULL(request_id, '') = ?
1631
+ AND released_at IS NULL
1632
+ `).run(n,t.agentId,t.adapter,t.conversationId??"",t.requestId??"");let i=(0,s.randomUUID)();return e.prepare(`
1633
+ INSERT INTO session_bindings (id, agent_id, adapter, conversation_id, request_id, external_session_id, source_attempt_id, created_at)
1634
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
1635
+ `).run(i,t.agentId,t.adapter,t.conversationId??null,t.requestId??null,t.externalSessionId,t.sourceAttemptId??null,n),e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'provider_sessions'").get()&&e.prepare(`
1636
+ INSERT INTO provider_sessions (
1637
+ id, agent_id, runtime_connection_id, provider_kind, provider_session_id, binding_id, origin,
1638
+ availability, lifecycle, resumable, busy, created_at, updated_at
1639
+ )
1640
+ SELECT b.id, b.agent_id, ${eX(e)}, b.adapter, b.external_session_id, b.id, 'binding',
1641
+ 'available', 'open', NULL, 0, b.created_at, b.created_at
1642
+ FROM session_bindings b JOIN bots bot ON bot.id = b.agent_id
1643
+ WHERE b.id = ?
1644
+ `).run(i),t.requestId&&E(t.requestId,"session_bound",{binding_id:i,adapter:t.adapter},t.sourceAttemptId??null,n),o.get(i)}).immediate()},getActiveSessionBinding:t=>e.prepare(`
1645
+ SELECT * FROM session_bindings
1646
+ WHERE agent_id = ? AND adapter = ? AND IFNULL(conversation_id, '') = ? AND IFNULL(request_id, '') = ?
1647
+ AND released_at IS NULL
1648
+ `).get(t.agentId,t.adapter,t.conversationId??"",t.requestId??"")};return u}function eZ(e,t){let n=(t,...n)=>e.prepare(t).all(...n).map(e=>e.id),i=new Set(n(t.requests,t.arg)),r=new Set,s=new Set(n(t.bindings,t.arg)),a=new Set,o=(e,t)=>{let n=!1;for(let i of t)e.has(i)||(e.add(i),n=!0);return n},_=e=>JSON.stringify([...e]),d="(SELECT value FROM json_each(?))";for(;;){let e=o(r,n(`SELECT id FROM session_exchanges WHERE (${t.exchanges})
1649
+ OR source_request_id IN ${d} OR destination_request_id IN ${d} OR source_attempt_id IN ${d}
1650
+ OR destination_attempt_id IN ${d} OR source_binding_id IN ${d} OR destination_binding_id IN ${d}`,t.arg,t.arg,_(i),_(i),_(a),_(a),_(s),_(s))),E=o(i,n(`SELECT source_request_id AS id FROM session_exchanges WHERE id IN ${d} AND source_request_id IS NOT NULL
1651
+ UNION SELECT destination_request_id AS id FROM session_exchanges WHERE id IN ${d} AND destination_request_id IS NOT NULL`,_(r),_(r))),u=o(i,n(`SELECT id FROM work_requests WHERE parent_request_id IN ${d} OR root_request_id IN ${d}`,_(i),_(i))),c=o(i,n(`SELECT request_id AS id FROM work_attempts WHERE id IN ${d}`,_(a))),l=o(a,n(`SELECT id FROM work_attempts WHERE request_id IN ${d} OR resumed_session_binding_id IN ${d}`,_(i),_(s))),T=o(s,n(`SELECT id FROM session_bindings WHERE request_id IN ${d} OR source_attempt_id IN ${d}`,_(i),_(a)));if(!e&&!E&&!u&&!c&&!l&&!T)break}(function(e,t,...n){let i=e.prepare(`SELECT id FROM session_exchanges WHERE ${t}`).all(...n).map(e=>e.id);if(0===i.length)return;let r=eG(e);for(let e of i)r.add(e);try{e.prepare("DELETE FROM session_exchange_events WHERE exchange_id IN (SELECT value FROM json_each(?))").run(JSON.stringify(i))}finally{r.clear()}e.prepare("DELETE FROM session_exchanges WHERE id IN (SELECT value FROM json_each(?))").run(JSON.stringify(i))})(e,`id IN ${d}`,_(r)),e.prepare(`DELETE FROM conversation_events WHERE request_id IN ${d}`).run(_(i)),e.prepare(`DELETE FROM finalizations WHERE implementation_request_id IN ${d} OR review_request_id IN ${d} OR decision_request_id IN ${d}`).run(_(i),_(i),_(i)),e.prepare(`DELETE FROM candidate_manifests WHERE request_id IN ${d}`).run(_(i)),e.prepare(`DELETE FROM attempt_finalization_baselines WHERE request_id IN ${d}`).run(_(i)),e.prepare(`DELETE FROM conversation_projection_cursors WHERE request_id IN ${d}`).run(_(i)),e.prepare(`DELETE FROM wake_safety_decisions WHERE request_id IN ${d}`).run(_(i)),e.prepare(`DELETE FROM dispatch_leases WHERE request_id IN ${d}`).run(_(i)),e.prepare(`DELETE FROM attempt_launch_intents WHERE request_id IN ${d}`).run(_(i)),e.prepare(`DELETE FROM dispatch_attention WHERE request_id IN ${d}`).run(_(i));let E=eG(e);for(let e of i)E.add(e);try{e.prepare(`DELETE FROM engine_events WHERE request_id IN ${d}`).run(_(i))}finally{E.clear()}for(e0(e,`origin = 'binding' AND binding_id IN ${d}`,_(s)),e.prepare(`UPDATE provider_sessions SET binding_id = NULL WHERE binding_id IN ${d}`).run(_(s)),e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'usage_samples'").get()&&e.prepare(`DELETE FROM usage_samples WHERE attempt_id IN ${d}`).run(_(a));a.size>0||s.size>0;){let t=n(`SELECT id FROM session_bindings WHERE id IN ${d}
1652
+ AND NOT EXISTS (SELECT 1 FROM work_attempts a WHERE a.resumed_session_binding_id = session_bindings.id)`,_(s));for(let n of t)e.prepare("DELETE FROM session_bindings WHERE id = ?").run(n),s.delete(n);let i=n(`SELECT id FROM work_attempts WHERE id IN ${d}
1653
+ AND NOT EXISTS (SELECT 1 FROM session_bindings b WHERE b.source_attempt_id = work_attempts.id)`,_(a));for(let t of i)e.prepare("DELETE FROM work_attempts WHERE id = ?").run(t),a.delete(t);if(0===t.length&&0===i.length)throw Error("Engine records could not be removed: unexpected attempt/binding reference cycle.")}for(let t of(e.prepare(`DELETE FROM conversation_events WHERE request_id IS NULL AND wake_id IN (SELECT id FROM wakes WHERE work_request_id IN ${d} OR parent_request_id IN ${d} OR root_request_id IN ${d})`).run(_(i),_(i),_(i)),e.prepare(`DELETE FROM wakes WHERE work_request_id IN ${d} OR parent_request_id IN ${d} OR root_request_id IN ${d}`).run(_(i),_(i),_(i)),e.prepare(`DELETE FROM terminal_followups WHERE request_id IN ${d}`).run(_(i)),n(`SELECT id FROM work_requests WHERE id IN ${d} ORDER BY depth DESC`,_(i))))e.prepare("DELETE FROM work_requests WHERE id = ?").run(t)}function e0(e,t,...n){if(!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'provider_sessions'").get())return;let i=JSON.stringify(e.prepare(`SELECT id FROM provider_sessions WHERE ${t}`).all(...n).map(e=>e.id));e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'usage_samples'").get()&&e.prepare("DELETE FROM usage_samples WHERE session_ref IN (SELECT value FROM json_each(?))").run(i),e.prepare("DELETE FROM provider_session_events WHERE session_ref IN (SELECT value FROM json_each(?))").run(i),e.prepare("DELETE FROM provider_session_turns WHERE session_ref IN (SELECT value FROM json_each(?))").run(i),e.prepare("DELETE FROM provider_sessions WHERE id IN (SELECT value FROM json_each(?))").run(i)}function e1(e,t,...n){if(!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'session_pins'").get())return;let i=JSON.stringify(e.prepare(`SELECT id FROM session_pins WHERE ${t}`).all(...n).map(e=>e.id));e.prepare("DELETE FROM session_pin_events WHERE pin_id IN (SELECT value FROM json_each(?))").run(i),e.prepare("DELETE FROM session_pin_turns WHERE pin_id IN (SELECT value FROM json_each(?))").run(i),e.prepare("DELETE FROM session_pins WHERE id IN (SELECT value FROM json_each(?))").run(i)}function e2(e,t){e.prepare("DELETE FROM conversation_intakes WHERE conversation_id = ?").run(t),e.prepare("DELETE FROM delegation_chains WHERE conversation_id = ?").run(t),e.prepare("DELETE FROM conversation_events WHERE conversation_id = ? AND request_id IS NULL").run(t),e.prepare("DELETE FROM wakes WHERE source_conversation_id = ?").run(t),e1(e,"conversation_id = ?",t),eZ(e,{requests:"SELECT id FROM work_requests WHERE source_conversation_id = ?",bindings:"SELECT id FROM session_bindings WHERE conversation_id = ?",exchanges:"origin_conversation_id = ? OR destination_conversation_id = ?",arg:t})}function e6(e,t){e.prepare(`DELETE FROM conversation_events WHERE request_id IS NULL AND wake_id IN (
1654
+ SELECT id FROM wakes WHERE target_agent_id = ? OR (requester_agent_id = ? AND work_request_id IS NULL))`).run(t,t),e.prepare("DELETE FROM wakes WHERE target_agent_id = ? OR (requester_agent_id = ? AND work_request_id IS NULL)").run(t,t),e.prepare("DELETE FROM wake_grants WHERE caller_agent_id = ? OR target_agent_id = ?").run(t,t),e1(e,"agent_id = ?",t),e0(e,"agent_id = ?",t),e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'usage_samples'").get()&&e.prepare("DELETE FROM usage_samples WHERE agent_id = ?").run(t),e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'provider_session_events'").get()&&e.prepare("DELETE FROM provider_session_events WHERE agent_id = ?").run(t),eZ(e,{requests:"SELECT id FROM work_requests WHERE target_agent_id = ?",bindings:"SELECT id FROM session_bindings WHERE agent_id = ?",exchanges:"source_agent_id = ? OR destination_agent_id = ?",arg:t})}function e4(e){if(!e)return{};try{let t=JSON.parse(e);return t&&"object"==typeof t&&!Array.isArray(t)?t:{}}catch{return{}}}function e3(e){return"string"==typeof e&&e.length>0?e:null}function e9(e,t){return t?`${e}: ${t}`:e}function e5(e,t,n,i){let r="grant_required"===t,s=r?"needs your approval for edit work":n;return{kind:"wake_blocked",attemptId:null,text:s?`Wake blocked: ${e} — ${s}`:`Wake blocked: ${e}`,data:{...i,target_name:e,reason_code:t,reason:n,actions:r?["allow","deny"]:[]}}}e.s(["EXCHANGE_LIMITS",0,ew,"EXCHANGE_STATES",0,ef,"EXCHANGE_TERMINAL_STATES",0,ev,"EXCHANGE_TRANSITIONS",0,eh,"EngineStoreError",0,eD,"TERMINAL_STATES",0,eq,"UI_TURN_INTERRUPTED",0,e$,"UI_TURN_INTERRUPTED_MESSAGE",0,ez,"UI_TURN_REQUESTER",0,eY,"createEngineStore",0,eV,"deleteEngineRecordsForAgent",0,e6,"deleteEngineRecordsForConversation",0,e2,"migrateEngineSchema",0,eH,"uiTurnExecutionPolicy",0,eP],35613);let e8=/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/,e7=/^[a-z][a-z0-9_.:-]{0,63}$/;function te(e){return null==e||""===e?null:e8.test(e)?e:"[invalid]"}function tt(e,t){return e&&e7.test(e)?e:t}let tn="agent_name_conflict";function ti(e){return String(e??"").trim()}function tr(e){return ti(e).normalize("NFC").toLowerCase().normalize("NFC")}function ts(e){return`An Agent named "${ti(e)}" already exists. Agent names must be unique, ignoring case and surrounding spaces.`}class ta extends Error{code=tn;requestedName;conflictingAgentId;constructor(e,t){super(ts(e)),this.name="AgentNameConflictError",this.requestedName=ti(e),this.conflictingAgentId=t}}function to(e){let t=[...e].sort((e,t)=>e.created_at-t.created_at||(e.id<t.id?-1:+(e.id>t.id))),n=new Map,i=[],r=[];for(let e of t){let t=tr(e.name);if(n.has(t)){i.push(e);continue}n.set(t,e.id),e.name_key!==t&&r.push({id:e.id,name:e.name,name_key:t})}let s=[];for(let e of i){let t=tr(e.name),i=ti(e.name)||"Agent",a=2;for(;n.has(tr(`${i}-${a}`));)a++;let o=`${i}-${a}`,_=tr(o);n.set(_,e.id),r.push({id:e.id,name:o,name_key:_}),s.push({bot_id:e.id,previous_name:e.name,new_name:o,name_key:t,kept_bot_id:n.get(t)})}return{updates:r,renames:s}}e.s(["AgentNameConflictError",0,ta,"agentDisplayName",0,ti,"agentNameConflictBody",0,function(e,t="name"){return{error:e.message,code:tn,field:t,name:e.requestedName,conflicting_agent_id:e.conflictingAgentId}},"agentNameConflictMessage",0,ts,"agentNameKey",0,tr,"planNameMigration",0,to],30098);let t_=(0,e.i(52036).dbPath)();":memory:"!==t_&&i.default.mkdirSync(r.default.dirname(r.default.resolve(t_)),{recursive:!0});let td=new n.default(t_);td.pragma("journal_mode = WAL"),td.exec(`
1655
+ CREATE TABLE IF NOT EXISTS bots (
1656
+ id TEXT PRIMARY KEY,
1657
+ name TEXT NOT NULL,
1658
+ title TEXT NOT NULL,
1659
+ description TEXT NOT NULL,
1660
+ avatar TEXT,
1661
+ created_at INTEGER NOT NULL
1662
+ );
1663
+
1664
+ CREATE TABLE IF NOT EXISTS groups (
1665
+ id TEXT PRIMARY KEY,
1666
+ name TEXT NOT NULL,
1667
+ created_at INTEGER NOT NULL
1668
+ );
1669
+
1670
+ CREATE TABLE IF NOT EXISTS group_members (
1671
+ group_id TEXT NOT NULL,
1672
+ bot_id TEXT NOT NULL,
1673
+ PRIMARY KEY (group_id, bot_id),
1674
+ FOREIGN KEY (group_id) REFERENCES groups(id),
1675
+ FOREIGN KEY (bot_id) REFERENCES bots(id)
1676
+ );
1677
+
1678
+ CREATE TABLE IF NOT EXISTS conversations (
1679
+ id TEXT PRIMARY KEY,
1680
+ type TEXT NOT NULL,
1681
+ bot_id TEXT,
1682
+ group_id TEXT,
1683
+ created_at INTEGER NOT NULL,
1684
+ FOREIGN KEY (bot_id) REFERENCES bots(id),
1685
+ FOREIGN KEY (group_id) REFERENCES groups(id)
1686
+ );
1687
+
1688
+ CREATE TABLE IF NOT EXISTS messages (
1689
+ id TEXT PRIMARY KEY,
1690
+ conversation_id TEXT NOT NULL,
1691
+ sender_type TEXT NOT NULL,
1692
+ sender_id TEXT,
1693
+ content TEXT NOT NULL,
1694
+ created_at INTEGER NOT NULL,
1695
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id)
1696
+ );
1697
+
1698
+ CREATE TABLE IF NOT EXISTS launch_snapshots (
1699
+ id TEXT PRIMARY KEY,
1700
+ bot_id TEXT NOT NULL,
1701
+ created_at INTEGER NOT NULL,
1702
+ hash TEXT NOT NULL,
1703
+ snapshot TEXT NOT NULL,
1704
+ FOREIGN KEY (bot_id) REFERENCES bots(id)
1705
+ );
1706
+
1707
+ CREATE INDEX IF NOT EXISTS idx_messages_conversation ON messages(conversation_id, created_at);
1708
+ CREATE INDEX IF NOT EXISTS idx_snapshots_bot ON launch_snapshots(bot_id, created_at DESC);
1709
+
1710
+ CREATE TABLE IF NOT EXISTS mcp_servers (
1711
+ id TEXT PRIMARY KEY,
1712
+ name TEXT NOT NULL,
1713
+ command TEXT NOT NULL,
1714
+ args TEXT NOT NULL,
1715
+ created_at INTEGER NOT NULL
1716
+ );
1717
+
1718
+ CREATE TABLE IF NOT EXISTS draft_actions (
1719
+ message_id TEXT PRIMARY KEY,
1720
+ status TEXT NOT NULL,
1721
+ recipient TEXT,
1722
+ acted_at INTEGER NOT NULL
1723
+ );
1724
+
1725
+ CREATE TABLE IF NOT EXISTS approvals (
1726
+ conversation_id TEXT NOT NULL,
1727
+ code TEXT NOT NULL,
1728
+ message_id TEXT,
1729
+ status TEXT NOT NULL DEFAULT 'pending',
1730
+ created_at INTEGER NOT NULL,
1731
+ resolved_at INTEGER,
1732
+ PRIMARY KEY (conversation_id, code)
1733
+ );
1734
+
1735
+ CREATE TABLE IF NOT EXISTS memories (
1736
+ id TEXT PRIMARY KEY,
1737
+ bot_id TEXT NOT NULL,
1738
+ fact TEXT NOT NULL,
1739
+ created_at INTEGER NOT NULL,
1740
+ FOREIGN KEY (bot_id) REFERENCES bots(id)
1741
+ );
1742
+
1743
+ CREATE INDEX IF NOT EXISTS idx_memories_bot ON memories(bot_id, created_at);
1744
+
1745
+ CREATE TABLE IF NOT EXISTS one_shots (
1746
+ id TEXT PRIMARY KEY,
1747
+ conversation_id TEXT NOT NULL,
1748
+ bot_id TEXT NOT NULL,
1749
+ due_at INTEGER NOT NULL,
1750
+ fired INTEGER NOT NULL DEFAULT 0,
1751
+ created_at INTEGER NOT NULL
1752
+ );
1753
+
1754
+ CREATE TABLE IF NOT EXISTS routines (
1755
+ id TEXT PRIMARY KEY,
1756
+ conversation_id TEXT NOT NULL,
1757
+ bot_id TEXT NOT NULL,
1758
+ word TEXT NOT NULL,
1759
+ next_due_at INTEGER NOT NULL,
1760
+ every_ms INTEGER NOT NULL,
1761
+ created_at INTEGER NOT NULL
1762
+ );
1763
+
1764
+ CREATE TABLE IF NOT EXISTS pending_questions (
1765
+ id TEXT PRIMARY KEY,
1766
+ conversation_id TEXT NOT NULL,
1767
+ bot_id TEXT NOT NULL,
1768
+ question TEXT NOT NULL,
1769
+ task_message_id TEXT,
1770
+ task_content TEXT,
1771
+ question_message_id TEXT,
1772
+ answer_message_id TEXT,
1773
+ answer TEXT,
1774
+ status TEXT NOT NULL DEFAULT 'asked',
1775
+ created_at INTEGER NOT NULL,
1776
+ resolved_at INTEGER,
1777
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id),
1778
+ FOREIGN KEY (bot_id) REFERENCES bots(id)
1779
+ );
1780
+
1781
+ CREATE INDEX IF NOT EXISTS idx_pending_questions_conversation
1782
+ ON pending_questions(conversation_id, status, created_at);
1783
+
1784
+ CREATE TABLE IF NOT EXISTS approval_requests (
1785
+ id TEXT PRIMARY KEY,
1786
+ conversation_id TEXT NOT NULL,
1787
+ bot_id TEXT,
1788
+ code TEXT NOT NULL,
1789
+ action_type TEXT,
1790
+ action_args TEXT,
1791
+ message_id TEXT,
1792
+ status TEXT NOT NULL DEFAULT 'pending',
1793
+ result TEXT,
1794
+ created_at INTEGER NOT NULL,
1795
+ resolved_at INTEGER,
1796
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id),
1797
+ FOREIGN KEY (bot_id) REFERENCES bots(id)
1798
+ );
1799
+
1800
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_approval_requests_conversation_code
1801
+ ON approval_requests(conversation_id, code);
1802
+ CREATE INDEX IF NOT EXISTS idx_approval_requests_conversation
1803
+ ON approval_requests(conversation_id, status, created_at);
1804
+ `);let tE=["#C6F54A","#F0A05A","#E85D75","#C9A0FF","#F2E36B"],tu="9e363764-e0d5-4fff-8ebd-ccbc46ba0ba5",tc="5fbe32c2-79cb-452e-9d9b-f8c9eb63b99b",tl=td.prepare("PRAGMA table_info(bots)").all();tl.some(e=>"color"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN color TEXT"),tl.some(e=>"pinned"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0"),tl.some(e=>"last_seen"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN last_seen INTEGER"),tl.some(e=>"unread"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN unread INTEGER NOT NULL DEFAULT 0"),tl.some(e=>"hidden"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN hidden INTEGER NOT NULL DEFAULT 0"),tl.some(e=>"source_provider"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN source_provider TEXT"),tl.some(e=>"template_id"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN template_id TEXT"),tl.some(e=>"template_url"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN template_url TEXT"),tl.some(e=>"import_schema_version"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN import_schema_version TEXT"),tl.some(e=>"import_operation_id"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN import_operation_id TEXT"),tl.some(e=>"import_timestamp"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN import_timestamp INTEGER"),tl.some(e=>"hermes_profile"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN hermes_profile TEXT"),tl.some(e=>"persistent_runtime"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN persistent_runtime TEXT NOT NULL DEFAULT 'hermes'"),tl.some(e=>"coding_runtime"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN coding_runtime TEXT"),tl.some(e=>"deck_name"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN deck_name TEXT"),tl.some(e=>"working_directory"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN working_directory TEXT"),tl.some(e=>"runtime"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN runtime TEXT"),tl.some(e=>"agent_client"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN agent_client TEXT"),tl.some(e=>"deck_id"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN deck_id TEXT"),tl.some(e=>"needs_deck_reselection"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN needs_deck_reselection INTEGER NOT NULL DEFAULT 0"),tl.some(e=>"agent"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN agent TEXT"),tl.some(e=>"needs_deck_selection"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN needs_deck_selection INTEGER NOT NULL DEFAULT 0");{let e=td.prepare("SELECT id, agent, runtime, agent_client, persistent_runtime, coding_runtime, deck_id, deck_name, working_directory, needs_deck_reselection, needs_deck_selection FROM bots WHERE agent IS NULL").all(),t=td.prepare("UPDATE bots SET agent = ?, deck_id = ?, deck_name = ?, working_directory = ?, needs_deck_selection = ? WHERE id = ?");td.transaction(e=>{for(let n of e){let e=(0,a.migrateLegacyAgentFields)(n);t.run(e.agent,e.deck_id,e.deck_name,e.working_directory,+!!e.needs_deck_selection,n.id)}})(e)}for(let[e,t]of(tl.some(e=>"avatar_color"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN avatar_color TEXT"),tl.some(e=>"avatar_eyes"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN avatar_eyes TEXT"),tl.some(e=>"avatar_hands"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN avatar_hands TEXT"),tl.some(e=>"avatar_accessory"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN avatar_accessory TEXT"),td.exec(`
1805
+ CREATE TABLE IF NOT EXISTS runtime_connections (
1806
+ id TEXT PRIMARY KEY,
1807
+ provider TEXT NOT NULL,
1808
+ label TEXT NOT NULL,
1809
+ host TEXT NOT NULL,
1810
+ created_at INTEGER NOT NULL
1811
+ );
1812
+ `),[["runtime_connection_id","TEXT"],["launch_profile","TEXT"],["session_scope_kind","TEXT"],["session_scope_items","TEXT"],["default_workspace","TEXT"],["policy_mode","TEXT"],["allow_new_sessions","INTEGER"],["allow_resume_with_edits","INTEGER"],["home_session_id","TEXT"]]))tl.some(t=>t.name===e)||td.exec(`ALTER TABLE bots ADD COLUMN ${e} ${t}`);function tT(e,t=Date.now()){let n=v(e);return td.prepare("INSERT OR IGNORE INTO runtime_connections (id, provider, label, host, created_at) VALUES (?, ?, ?, ?, ?)").run(n,e,h(e),E,t),n}for(let e of a.AGENTS)tT(e,0);td.transaction(()=>{let e=td.prepare("SELECT id, agent, deck_id, working_directory, needs_deck_selection, created_at FROM bots WHERE runtime_connection_id IS NULL").all(),t=td.prepare(`UPDATE bots SET runtime_connection_id = ?, launch_profile = ?, session_scope_kind = ?, session_scope_items = ?,
1813
+ policy_mode = ?, allow_new_sessions = ?, allow_resume_with_edits = ? WHERE id = ?`);for(let n of e){let e=X(n);tT(e.provider,n.created_at),t.run(e.runtime_connection_id,e.launch_profile,e.session_scope_kind,e.session_scope_items,e.policy_mode,e.allow_new_sessions,e.allow_resume_with_edits,n.id)}})(),tl.some(e=>"name_key"===e.name)||td.exec("ALTER TABLE bots ADD COLUMN name_key TEXT"),td.exec(`
1814
+ CREATE TABLE IF NOT EXISTS agent_name_migrations (
1815
+ id TEXT PRIMARY KEY,
1816
+ bot_id TEXT NOT NULL,
1817
+ previous_name TEXT NOT NULL,
1818
+ new_name TEXT NOT NULL,
1819
+ name_key TEXT NOT NULL,
1820
+ kept_bot_id TEXT NOT NULL,
1821
+ reason TEXT NOT NULL,
1822
+ created_at INTEGER NOT NULL
1823
+ );
1824
+ `),td.transaction(()=>{let e=to(td.prepare("SELECT id, name, created_at, name_key FROM bots").all());if(0===e.updates.length)return;let t=td.prepare("UPDATE bots SET name_key = NULL WHERE id = ?");for(let n of e.updates)t.run(n.id);let n=td.prepare("UPDATE bots SET name = ?, name_key = ? WHERE id = ?");for(let t of e.updates)n.run(t.name,t.name_key,t.id);let i=td.prepare("INSERT INTO agent_name_migrations (id, bot_id, previous_name, new_name, name_key, kept_bot_id, reason, created_at) VALUES (?, ?, ?, ?, ?, ?, 'duplicate_name', ?)"),r=Date.now();for(let t of e.renames)i.run((0,s.randomUUID)(),t.bot_id,t.previous_name,t.new_name,t.name_key,t.kept_bot_id,r),console.warn(`[botmancers] Agent ${t.bot_id} renamed "${t.previous_name}" -> "${t.new_name}": name already used by Agent ${t.kept_bot_id}.`)})(),td.exec("CREATE UNIQUE INDEX IF NOT EXISTS idx_bots_name_key ON bots(name_key)"),td.exec(`
1825
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_bots_import_operation
1826
+ ON bots(import_operation_id) WHERE import_operation_id IS NOT NULL
1827
+ `),td.prepare("UPDATE bots SET color = ? WHERE id = ?").run(tE[0],tu),td.prepare("UPDATE bots SET color = ? WHERE id = ?").run(tE[1],tc);let tp=td.prepare("SELECT id FROM bots WHERE id NOT IN (?, ?) ORDER BY created_at ASC").all(tu,tc),tN=td.prepare("UPDATE bots SET color = ? WHERE id = ?");function tR(e,t){let n=ti(e),i=tr(n),r=td.prepare("SELECT id FROM bots WHERE name_key = ?").get(i);if(r&&r.id!==t)throw new ta(n,r.id);return{name:n,name_key:i}}function tm(e,t){try{return t()}catch(t){if(t instanceof Error&&/UNIQUE constraint failed: bots\.name_key/.test(t.message)){let t=td.prepare("SELECT id FROM bots WHERE name_key = ?").get(tr(e));throw new ta(e,t?.id??null)}throw t}}function tL(){return tE[td.prepare("SELECT COUNT(*) AS n FROM bots").get().n%tE.length]}tp.forEach((e,t)=>{tN.run(tE[(t+2)%tE.length],e.id)});let tg=td.prepare("PRAGMA table_info(messages)").all();tg.some(e=>"handoff_targets"===e.name)||td.exec("ALTER TABLE messages ADD COLUMN handoff_targets TEXT"),td.prepare("PRAGMA table_info(groups)").all().some(e=>"owner_bot_id"===e.name)||td.exec("ALTER TABLE groups ADD COLUMN owner_bot_id TEXT"),td.prepare("PRAGMA table_info(launch_snapshots)").all().some(e=>"transport"===e.name)||td.exec("ALTER TABLE launch_snapshots ADD COLUMN transport TEXT NOT NULL DEFAULT 'hermes-gateway'");let tO=td.prepare("PRAGMA table_info(conversations)").all();tO.some(e=>"origin_kind"===e.name)||td.exec("ALTER TABLE conversations ADD COLUMN origin_kind TEXT"),tO.some(e=>"origin_id"===e.name)||td.exec("ALTER TABLE conversations ADD COLUMN origin_id TEXT"),tg.some(e=>"sender_kind"===e.name)||td.exec("ALTER TABLE messages ADD COLUMN sender_kind TEXT"),tg.some(e=>"request_id"===e.name)||td.exec("ALTER TABLE messages ADD COLUMN request_id TEXT"),td.exec(`
1828
+ CREATE TABLE IF NOT EXISTS conversation_participants (
1829
+ conversation_id TEXT NOT NULL,
1830
+ participant_kind TEXT NOT NULL,
1831
+ participant_id TEXT NOT NULL,
1832
+ joined_at INTEGER NOT NULL,
1833
+ PRIMARY KEY (conversation_id, participant_kind, participant_id),
1834
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id)
1835
+ );
1836
+ `),eH(td);let tI=eV(td),tA=function(e){let t=e.prepare("SELECT * FROM work_requests WHERE id = ?"),n=e.prepare("SELECT * FROM work_attempts WHERE id = ?"),i=e.prepare("SELECT * FROM engine_events WHERE request_id = ? ORDER BY sequence ASC"),r=e.prepare("SELECT sequence FROM conversation_projection_cursors WHERE request_id = ?"),s=e.prepare(`
1837
+ INSERT INTO conversation_projection_cursors (request_id, sequence) VALUES (?, ?)
1838
+ ON CONFLICT (request_id) DO UPDATE SET sequence = excluded.sequence WHERE excluded.sequence > sequence
1839
+ `),a=e.prepare(`
1840
+ INSERT OR IGNORE INTO conversation_events (
1841
+ id, conversation_id, engine_event_id, part, request_id, request_sequence, attempt_id, wake_id,
1842
+ kind, state, text, data, sort_at, request_created_at, created_at
1843
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1844
+ `);function o(e){return e?n.get(e):void 0}function _(n){return e.transaction(()=>{let e=t.get(n);if(!e)return 0;let _=r.get(n)?.sequence??0,d=i.all(n),E=d.length>0?d[d.length-1].sequence:0;if(E<=_)return 0;let u={state:null,lastFinished:null},c=0,l=0;for(let t of d){c=Math.max(c,t.created_at);let n={...u};!function(e,t){let n=e4(t.data);"accepted"===t.type&&e3(n.state)&&(e.state=n.state),"state_changed"===t.type&&e3(n.to)&&(e.state=n.to),"attempt_finished"===t.type&&t.attempt_id&&(e.lastFinished={attemptId:t.attempt_id,outcome:e3(n.outcome)})}(u,t),t.sequence<=_||null!==e.legacy_agent_request_id||(function(e,t,n){let i=e4(e.data),r=e4(t.policy_snapshot),s=null!==t.wake_event_id,a=e3(r.target_name_snapshot)??t.target_agent_id,_={target_agent_id:t.target_agent_id,execution_kind:t.execution_kind,tool_profile:t.tool_profile};switch(e.type){case"accepted":if("blocked"===i.state)return[];if(s)return[{kind:"wake_accepted",attemptId:null,text:`Wake accepted: ${a} (${t.execution_kind})`,data:{..._,target_name:a,requester_kind:t.requester_kind,requester_id:t.requester_id,parent_request_id:t.parent_request_id,depth:t.depth,wake_depth:t.wake_depth,grant_rule:e3(r.grant_rule),grant_id:e3(r.grant_id)}}];return[{kind:"request_queued",attemptId:null,text:"Queued",data:{..._,requester_kind:t.requester_kind,requester_id:t.requester_id}}];case"state_changed":{let e=e3(i.to),r=e3(i.from),d=e3(i.reason);switch(e){case"blocked":if(s&&"queued"===r&&"blocked"===n.state){let e=function(e){if(!e)return{code:null,reason:null};let t=/^([a-z_]+): ([\s\S]*)$/.exec(e);return t?{code:t[1],reason:t[2]}:{code:null,reason:e}}(d);return[e5(a,e.code,e.reason,_)]}return[{kind:"request_blocked",attemptId:null,text:e9("Blocked",d),data:{from:r,reason:d}}];case"queued":if("retry_scheduled"===d){let e="number"==typeof i.attempt_count?i.attempt_count:null,t="number"==typeof i.max_attempts?i.max_attempts:null;return[{kind:"request_retry_scheduled",attemptId:n.lastFinished?.attemptId??null,text:!0===i.manual?`Retry requested${null!==e&&null!==t?` (Attempt ${e+1} of ${t})`:""}`:`Retry scheduled${null!==e&&null!==t?` (Attempt ${e+1} of ${t})`:""}${"number"==typeof i.delay_ms?` in ${i.delay_ms} ms`:""}`,data:{from:r,reason:d,manual:!0===i.manual,attempt_count:e,max_attempts:t,next_eligible_at:i.next_eligible_at??null,delay_ms:i.delay_ms??null,category:i.category??null,outcome:n.lastFinished?.outcome??null}}]}if(s&&"blocked"===r&&("grant_approved"===d||"target_available"===d))return[{kind:"wake_accepted",attemptId:null,text:`Wake accepted: ${a} (${t.execution_kind})`,data:{..._,target_name:a,requester_kind:t.requester_kind,requester_id:t.requester_id,parent_request_id:t.parent_request_id,depth:t.depth,wake_depth:t.wake_depth,reason:d,grant_rule:i.grant_rule??null,grant_id:i.grant_id??null}}];return[{kind:"request_queued",attemptId:null,text:e9("Queued again",d),data:{from:r,reason:d}}];case"running":return[{kind:"request_running",attemptId:null,text:"Running",data:{phase:"dispatched",from:r}}];case"waiting":return[{kind:"request_waiting",attemptId:null,text:e9("Waiting",d),data:{from:r,reason:d}}];case"completed":{let e=n.lastFinished,i=e?.outcome==="succeeded",r=[{kind:"request_completed",attemptId:e?.attemptId??null,text:i?"Completed":"Completed without a successful Attempt outcome",data:{success:i,outcome:e?.outcome??null}}];if(i&&e){let n=o(e.attemptId),i=e4(t.result);r.push({kind:"result",attemptId:e.attemptId,text:n?.output??"Result recorded",data:{reply_message_id:e3(i.reply_message_id),has_output:"string"==typeof n?.output}})}return r}case"failed":case"cancelled":{let s=n.lastFinished,a=t.error_code??e3(i.error_code),o=t.error_message;if("failed"===e&&"timed_out"===d)return[{kind:"request_timed_out",attemptId:s?.attemptId??null,text:"Timed out: the request passed its deadline",data:{success:!1,error_code:a,reason:d,deadline_at:i.deadline_at??null,from:r,outcome:s?.outcome??null}}];if("failed"===e&&"retries_exhausted"===d)return[{kind:"request_retries_exhausted",attemptId:s?.attemptId??null,text:e9(`Retries exhausted after ${i.attempt_count??"?"} of ${i.max_attempts??"?"} Attempts`,o??a),data:{success:!1,error_code:a,error_message:o,reason:d,attempt_count:i.attempt_count??null,max_attempts:i.max_attempts??null,outcome:s?.outcome??null}}];return[{kind:"failed"===e?"request_failed":"request_cancelled",attemptId:s?.attemptId??null,text:"failed"===e?e9("Failed",o??a):"cancel_requested"===d?e9("Cancelled",t.cancel_reason):"grant_denied"===d?"Cancelled: owner denied edit Wake":e9("Cancelled",d??o),data:{success:!1,error_code:a,error_message:o,reason:d,outcome:s?.outcome??null}}]}default:return[]}}case"runtime_started":{let t=e3(i.adapter);return[{kind:"request_running",attemptId:e.attempt_id,text:t?`Running on ${t}`:"Running",data:{phase:"runtime_started",adapter:t,external_run_id:e3(i.external_run_id),success:!1}}]}case"wake_reblocked":return[e5(a,e3(i.reason_code),e3(i.reason),_)];case"dispatch_deferred":return[{kind:"request_queued",attemptId:null,text:"Queued: waiting for capacity",data:{waiting_for:"capacity",limit:e3(i.reason),active_global:i.active_global??null,active_target:i.active_target??null,max_global:i.max_global??null,max_per_target:i.max_per_target??null}}];case"lineage_stopped":return[{kind:"lineage_stopped",attemptId:null,text:"continuation_budget_exhausted"===i.reason?`Stopped: coordinator continuation limit ${i.limit??"?"} reached`:e9("Stopped",e3(i.reason)),data:i}];case"cancel_requested":{let e=e3(i.reason);return[{kind:"request_cancel_requested",attemptId:null,text:e9("Cancel requested",e),data:{by:e3(i.by),reason:e,state:e3(i.state)}}]}case"question":{let t=e3(i.question)??"";return[{kind:"question",attemptId:e.attempt_id,text:t,data:{question:t}}]}case"attempt_finished":{let t=o(e.attempt_id);if(!t)return[];let n=[];try{let e=JSON.parse(t.artifacts);Array.isArray(e)&&(n=e)}catch{}return n.filter(e=>!(e&&"object"==typeof e&&"candidate_manifest"===e.kind)).map(e=>{let n=e&&"object"==typeof e?e:{ref:String(e)},i=e3(n.kind)??"artifact",r=e3(n.ref)??"";return{kind:"artifact",attemptId:t.id,text:`Artifact (${i}): ${r}`,data:{artifact_kind:i,ref:r,outcome:t.outcome}}})}case"candidate_manifest_recorded":{let t=e3(i.manifest_digest),n="number"==typeof i.file_count?i.file_count:0;return[{kind:"artifact",attemptId:e.attempt_id,text:`Candidate manifest ${t}: ${n} ${1===n?"file":"files"} on base ${e3(i.base_commit)}`,data:{artifact_kind:"candidate_manifest",ref:t,...i}}]}case"candidate_manifest_unavailable":return[{kind:"finalization_blocked",attemptId:e.attempt_id,text:e9("Not finalizable",e3(i.reason_code)),data:{phase:"candidate",...i}}];case"finalization_preparing":return[{kind:"finalization_preparing",attemptId:e.attempt_id,text:`Finalization preparing: manifest ${e3(i.manifest_digest)} (${i.file_count??0} files), review ${e3(i.review_request_id)}`,data:i}];case"finalization_retry_pending":return[{kind:"finalization_preparing",attemptId:e.attempt_id,text:e9("Finalization waiting to retry",e3(i.reason_code)),data:{retry:!0,...i}}];case"finalization_committed":return[{kind:"finalization_committed",attemptId:e.attempt_id,text:`Finalization committed: commit ${e3(i.commit)} (tree ${e3(i.tree)}, manifest ${e3(i.result_manifest_digest)??e3(i.manifest_digest)})`,data:{success:!0,...i}}];case"finalization_blocked":case"finalization_failed":case"finalization_canceled":{let t="finalization_blocked"===e.type?"blocked":"finalization_failed"===e.type?"failed":"canceled";return[{kind:e.type,attemptId:e.attempt_id,text:e9(`Finalization ${t}`,e3(i.reason_code)),data:{success:!1,...i}}]}case"finalization_rejected":return[{kind:"finalization_rejected",attemptId:null,text:e9("Finalization not started",e3(i.reason_code)),data:i}];default:return[]}})(t,e,n).forEach((n,i)=>{l+=a.run(`${t.id}:${i}`,e.source_conversation_id,t.id,i,e.id,t.sequence,n.attemptId,e.wake_event_id,n.kind,u.state,n.text,JSON.stringify(n.data),c,e.created_at,t.created_at).changes})}return s.run(n,E),l}).immediate()}function d(t){return e.transaction(()=>e.prepare("SELECT id FROM work_requests WHERE source_conversation_id = ? ORDER BY created_at ASC, id ASC").all(t).reduce((e,t)=>e+_(t.id),0)+function(t){let n=e.prepare(`
1845
+ SELECT w.* FROM wakes w
1846
+ WHERE w.source_conversation_id = ? AND w.status = 'rejected'
1847
+ AND NOT EXISTS (SELECT 1 FROM conversation_events e WHERE e.id = 'wake:' || w.id || ':0')
1848
+ ORDER BY w.created_at ASC, w.position ASC
1849
+ `).all(t),i=0;for(let e of n){let t={wake_id:e.id,target_name:e.target_name_snapshot??e.requested_target,target_agent_id:e.target_agent_id,execution_kind:e.execution_kind,requester_agent_id:e.requester_agent_id,parent_request_id:e.parent_request_id,reason_code:e.reason_code,reason:e.reason,limit:e.limit_value,observed:e.observed_value,work_request_id:null};i+=a.run(`wake:${e.id}:0`,e.source_conversation_id,null,0,null,0,null,e.id,"wake_rejected",null,function(e){let t=e.target_name_snapshot??e.requested_target??"an unnamed target";switch(e.reason_code){case"untracked_lineage":return"Wake not started: its source turn is not tracked work";case"depth_exceeded":return`Wake not started: ${t} — depth limit ${e.limit_value??"?"} reached`;case"root_budget_exhausted":return`Wake not started: ${t} — this work already used ${e.observed_value??e.limit_value??"?"} Wakes`;default:return e.reason?`Wake not started: ${t} — ${e.reason}`:`Wake not started: ${t}`}}(e),JSON.stringify(t),e.updated_at,e.created_at,e.updated_at).changes}return i}(t)).immediate()}function E(t){return e.prepare(`
1850
+ SELECT * FROM conversation_events WHERE conversation_id = ?
1851
+ ORDER BY sort_at ASC, request_created_at ASC, COALESCE(request_id, wake_id) ASC, request_sequence ASC, part ASC
1852
+ `).all(t)}return{projectRequest:_,projectConversation:d,projectEvent:function(e){return _(e.request_id)},listConversationEventRows:E,listConversationEvents:function(e){return d(e),E(e).map((e,t)=>({eventId:e.id,seq:t+1,kind:e.kind,requestId:e.request_id,requestSequence:e.request_sequence,attemptId:e.attempt_id,wakeId:e.wake_id,engineEventId:e.engine_event_id,state:e.state,text:e.text,data:e4(e.data),createdAt:e.created_at}))}}}(td),tS=(td.exec(`
1853
+ CREATE TABLE IF NOT EXISTS service_audit_events (
1854
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
1855
+ at INTEGER NOT NULL,
1856
+ principal TEXT NOT NULL CHECK (length(principal) BETWEEN 1 AND 200),
1857
+ operation TEXT NOT NULL CHECK (length(operation) BETWEEN 1 AND 64),
1858
+ capability TEXT NOT NULL CHECK (length(capability) BETWEEN 1 AND 64),
1859
+ target_kind TEXT NOT NULL CHECK (target_kind IN ('grants', 'agent', 'session', 'conversation', 'exchange', 'request')),
1860
+ target_ref TEXT CHECK (target_ref IS NULL OR length(target_ref) <= 128),
1861
+ agent_id TEXT CHECK (agent_id IS NULL OR length(agent_id) <= 128),
1862
+ outcome TEXT NOT NULL CHECK (outcome IN ('allowed', 'denied', 'rejected', 'error')),
1863
+ code TEXT CHECK (code IS NULL OR length(code) <= 64)
1864
+ );
1865
+ CREATE INDEX IF NOT EXISTS idx_service_audit_principal ON service_audit_events(principal, id);
1866
+ CREATE TRIGGER IF NOT EXISTS trg_service_audit_no_update BEFORE UPDATE ON service_audit_events
1867
+ BEGIN
1868
+ SELECT RAISE(ABORT, 'service_audit_events are append-only');
1869
+ END;
1870
+ CREATE TRIGGER IF NOT EXISTS trg_service_audit_no_delete BEFORE DELETE ON service_audit_events
1871
+ BEGIN
1872
+ SELECT RAISE(ABORT, 'service_audit_events are append-only');
1873
+ END;
1874
+ `),t=td.prepare(`
1875
+ INSERT INTO service_audit_events (at, principal, operation, capability, target_kind, target_ref, agent_id, outcome, code)
1876
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
1877
+ `),{append(e){let n=`${e.principal.kind}:${te(e.principal.id)??"[invalid]"}`;t.run(e.at??Date.now(),n.slice(0,200),tt(e.operation,"unknown"),tt(e.capability,"none"),e.targetKind,te(e.targetRef),te(e.agentId),e.outcome,e.code?tt(e.code,"unknown"):null)},list(e={}){let t=Math.min(Math.max(1,e.limit??50),500);return e.principal?td.prepare("SELECT * FROM service_audit_events WHERE principal = ? ORDER BY id DESC LIMIT ?").all(e.principal,t):td.prepare("SELECT * FROM service_audit_events ORDER BY id DESC LIMIT ?").all(t)}}),tk={kind:"person",id:"local-owner"},tf=td.prepare("INSERT OR IGNORE INTO conversation_participants (conversation_id, participant_kind, participant_id, joined_at) VALUES (?, ?, ?, ?)");function tv(e,t,n){for(let i of(td.prepare("UPDATE conversations SET origin_kind = ?, origin_id = ? WHERE id = ? AND origin_kind IS NULL").run(tk.kind,tk.id,e),tf.run(e,tk.kind,tk.id,n),t))tf.run(e,"bot",i,n)}td.transaction(()=>{td.exec("UPDATE messages SET sender_kind = 'person' WHERE sender_kind IS NULL AND sender_type = 'user'"),td.exec("UPDATE messages SET sender_kind = 'bot' WHERE sender_kind IS NULL AND sender_type = 'bot'");let e=td.prepare("SELECT id, type, bot_id, group_id, created_at FROM conversations WHERE origin_kind IS NULL AND type IN ('bot', 'group')").all(),t=td.prepare("SELECT bot_id FROM group_members WHERE group_id = ?");for(let n of e){let e="bot"===n.type?n.bot_id?[n.bot_id]:[]:n.group_id?t.all(n.group_id).map(e=>e.bot_id):[];tv(n.id,e,n.created_at)}})();let th={getAll:()=>td.prepare("SELECT * FROM runtime_connections ORDER BY created_at ASC, id ASC").all(),getById:e=>{let t=td.prepare("SELECT * FROM runtime_connections WHERE id = ?").get(e);return t&&a.AGENTS.includes(t.provider)?t:void 0},create:e=>{let t={id:`rc-${(0,s.randomUUID)()}`,...e,created_at:Date.now()};return td.prepare("INSERT INTO runtime_connections (id, provider, label, host, created_at) VALUES (?, ?, ?, ?, ?)").run(t.id,t.provider,t.label,t.host,t.created_at),t},ensureLocal:e=>tT(e),agentCount:e=>td.prepare("SELECT COUNT(*) AS n FROM bots WHERE runtime_connection_id = ?").get(e).n},tw=["session_scope_kind","session_scope_items","policy_mode","allow_new_sessions","allow_resume_with_edits"],tC={create:(e,t)=>{let n=tR(e.name),i={id:t?.id||(0,s.randomUUID)(),...e,...n,color:tL(),created_at:t?.created_at??Date.now()};i.agent=i.agent||a.DEFAULT_AGENT,i.deck_id=i.deck_id||null,i.needs_deck_selection=!i.deck_id||i.needs_deck_selection?1:0;let r=X({...i,needs_deck_selection:i.needs_deck_selection});i.runtime_connection_id||(i.runtime_connection_id=tT(r.provider,i.created_at)),void 0===i.launch_profile&&(i.launch_profile=r.launch_profile),"direct"===i.launch_profile&&(i.deck_id=null,i.working_directory=null,i.needs_deck_selection=0),i.session_scope_kind||(i.session_scope_kind=r.session_scope_kind,i.session_scope_items=r.session_scope_items),i.policy_mode||(i.policy_mode=r.policy_mode,i.allow_new_sessions=r.allow_new_sessions,i.allow_resume_with_edits=r.allow_resume_with_edits),tm(i.name,()=>td.prepare(`INSERT INTO bots (id, name, name_key, title, description, avatar, color, hermes_profile, agent, deck_id, deck_name, working_directory, needs_deck_selection,
1878
+ runtime_connection_id, launch_profile, session_scope_kind, session_scope_items, default_workspace, policy_mode, allow_new_sessions, allow_resume_with_edits, home_session_id,
1879
+ avatar_color, avatar_eyes, avatar_hands, avatar_accessory, created_at)
1880
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(i.id,i.name,i.name_key,i.title,i.description,i.avatar||null,i.color,i.hermes_profile||null,i.agent,i.deck_id,i.deck_name||null,i.working_directory||null,i.needs_deck_selection,i.runtime_connection_id,i.launch_profile??null,i.session_scope_kind,i.session_scope_items??"[]",i.default_workspace||null,i.policy_mode,+!!i.allow_new_sessions,+!!i.allow_resume_with_edits,null,i.avatar_color||null,i.avatar_eyes||null,i.avatar_hands||null,i.avatar_accessory||null,i.created_at));let o=(0,s.randomUUID)();return td.prepare("INSERT INTO conversations (id, type, bot_id, created_at) VALUES (?, ?, ?, ?)").run(o,"bot",i.id,i.created_at),tv(o,[i.id],i.created_at),i},createFromImport:(e,t)=>{let n=tR(e.name),i={id:(0,s.randomUUID)(),...e,...n,color:tL(),created_at:Date.now(),agent:a.DEFAULT_AGENT,deck_id:null,deck_name:null,working_directory:null,needs_deck_selection:1,source_provider:t.source_provider,template_id:t.template_id,template_url:t.template_url,import_schema_version:t.import_schema_version,import_operation_id:t.import_operation_id,import_timestamp:t.import_timestamp},r=X(i);Object.assign(i,{runtime_connection_id:tT(r.provider,i.created_at),launch_profile:null,session_scope_kind:r.session_scope_kind,session_scope_items:r.session_scope_items,policy_mode:r.policy_mode,allow_new_sessions:r.allow_new_sessions,allow_resume_with_edits:r.allow_resume_with_edits}),tm(i.name,()=>td.prepare(`INSERT INTO bots (
1881
+ id, name, name_key, title, description, avatar, color, created_at,
1882
+ source_provider, template_id, template_url, import_schema_version,
1883
+ import_operation_id, import_timestamp,
1884
+ agent, deck_id, deck_name, working_directory,
1885
+ needs_deck_selection,
1886
+ runtime_connection_id, launch_profile, session_scope_kind, session_scope_items,
1887
+ policy_mode, allow_new_sessions, allow_resume_with_edits
1888
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(i.id,i.name,i.name_key,i.title,i.description,i.avatar||null,i.color,i.created_at,i.source_provider,i.template_id,i.template_url,i.import_schema_version,i.import_operation_id,i.import_timestamp,i.agent,i.deck_id,i.deck_name,i.working_directory,i.needs_deck_selection,i.runtime_connection_id,i.launch_profile,i.session_scope_kind,i.session_scope_items,i.policy_mode,i.allow_new_sessions,i.allow_resume_with_edits));let o=(0,s.randomUUID)();return td.prepare("INSERT INTO conversations (id, type, bot_id, created_at) VALUES (?, ?, ?, ?)").run(o,"bot",i.id,i.created_at),tv(o,[i.id],i.created_at),i},getByImportOperationId:e=>td.prepare("SELECT * FROM bots WHERE import_operation_id = ?").get(e),getAll:()=>td.prepare("SELECT * FROM bots ORDER BY created_at DESC").all(),getById:e=>td.prepare("SELECT * FROM bots WHERE id = ?").get(e),setAvatar:(e,t)=>{td.prepare("UPDATE bots SET avatar = ? WHERE id = ?").run(t,e)},getByName:e=>{let t=tr(e);if(t)return td.prepare("SELECT * FROM bots WHERE name_key = ?").get(t)},updateIdentity:(e,t,n,i)=>{let r=tR(t,e);tm(r.name,()=>td.prepare("UPDATE bots SET name = ?, name_key = ?, title = ?, description = ? WHERE id = ?").run(r.name,r.name_key,n,i,e))},setPinned:(e,t)=>{td.prepare("UPDATE bots SET pinned = ? WHERE id = ?").run(+!!t,e)},setHidden:(e,t)=>{td.prepare("UPDATE bots SET hidden = ? WHERE id = ?").run(+!!t,e)},setHermesProfile:(e,t)=>{let n=t&&t.trim()?t.trim():null;td.prepare("UPDATE bots SET hermes_profile = ? WHERE id = ?").run(n,e)},updateRegistration:(e,t,n)=>{let i=tC.getById(e);if(!i)return;let r=W(n),s="agent_deck"===n.launch_profile&&n.deck_id?null:i.deck_name??null;td.prepare(`UPDATE bots SET agent = ?, deck_name = ?, runtime_connection_id = ?, launch_profile = ?, deck_id = ?, working_directory = ?,
1889
+ session_scope_kind = ?, session_scope_items = ?, default_workspace = ?, policy_mode = ?, allow_new_sessions = ?,
1890
+ allow_resume_with_edits = ?, home_session_id = ?, needs_deck_selection = ? WHERE id = ?`).run(t,s,r.runtime_connection_id,r.launch_profile,r.deck_id,r.working_directory,r.session_scope_kind,r.session_scope_items,r.default_workspace,r.policy_mode,r.allow_new_sessions,r.allow_resume_with_edits,r.home_session_id,r.needs_deck_selection,e)},updateAgentSelection:(e,t)=>{let n=tC.getById(e);if(!n)return;let i=(0,a.applyAgentUpdate)(n,t),r=void 0!==t.deck_id?"agent_deck":n.launch_profile??null,s=n.runtime_connection_id?th.getById(n.runtime_connection_id):void 0,o=s&&s.provider===i.agent?s.id:tT(i.agent);td.prepare("UPDATE bots SET agent = ?, deck_id = ?, deck_name = ?, working_directory = ?, needs_deck_selection = ?, launch_profile = ?, runtime_connection_id = ? WHERE id = ?").run(i.agent,"direct"===r?null:i.deck_id,i.deck_name,"direct"===r?null:i.working_directory,"direct"===r?0:+!!i.needs_deck_selection,r,o,e)},updateAvatarConfig:(e,t)=>{let n=tC.getById(e);if(!n)return;let i=(e,t)=>void 0===e?t||null:e&&String(e).trim()?String(e).trim():null;td.prepare("UPDATE bots SET avatar_color = ?, avatar_eyes = ?, avatar_hands = ?, avatar_accessory = ? WHERE id = ?").run(i(t.avatar_color,n.avatar_color),i(t.avatar_eyes,n.avatar_eyes),i(t.avatar_hands,n.avatar_hands),i(t.avatar_accessory,n.avatar_accessory),e)},touchSeen:()=>{td.prepare("UPDATE bots SET last_seen = ?").run(Date.now())},markUnread:e=>{td.prepare("UPDATE bots SET unread = 1 WHERE id = ?").run(e)},markRead:e=>{td.prepare("UPDATE bots SET unread = 0 WHERE id = ?").run(e)},remove:e=>{tC.removeMany([e])},deletionPreview:e=>{var t;let n=new Set(e),i=[],r=[],s=[],a=new Set(ty());for(let t of e){let e=tC.getById(t);if(!e){r.push(t);continue}i.push({id:e.id,name:e.name}),(0,J.isChiefOfStaffName)(e.name)?s.push({id:e.id,name:e.name,reason:"chief"}):a.has(e.id)&&s.push({id:e.id,name:e.name,reason:"active"})}return{agents:i,groups:0===(t=n).size?[]:td.prepare(`SELECT DISTINCT g.id, g.name, g.owner_bot_id, g.created_at FROM groups g
1891
+ JOIN group_members gm ON gm.group_id = g.id
1892
+ WHERE gm.bot_id IN (${[...t].map(()=>"?").join(", ")})
1893
+ ORDER BY g.created_at ASC, g.id ASC`).all(...t).map(e=>{let n=td.prepare(`SELECT b.id, b.name FROM bots b JOIN group_members gm ON gm.bot_id = b.id
1894
+ WHERE gm.group_id = ? ORDER BY b.created_at ASC, b.id ASC`).all(e.id).filter(e=>!t.has(e.id));return n.length<2?{id:e.id,name:e.name,outcome:"removed",remaining:n.length,newOwner:null}:e.owner_bot_id&&t.has(e.owner_bot_id)?{id:e.id,name:e.name,outcome:"reassigned",remaining:n.length,newOwner:n[0]}:{id:e.id,name:e.name,outcome:"shrunk",remaining:n.length,newOwner:null}}),missing:r,blocked:s}},removeMany:(e,t)=>td.transaction(()=>{let n=tC.deletionPreview(e);if(n.missing.length>0||n.blocked.length>0)throw new tq(n);let i=new Set(e);for(let e of n.groups){if("removed"===e.outcome){var r=e.id;for(let e of td.prepare("SELECT id FROM conversations WHERE group_id = ?").all(r))tU(e.id);td.prepare("DELETE FROM group_members WHERE group_id = ?").run(r),td.prepare("DELETE FROM groups WHERE id = ?").run(r);continue}let t=td.prepare("SELECT id FROM conversations WHERE group_id = ?").all(e.id).map(e=>e.id);for(let n of i)for(let i of(td.prepare("DELETE FROM group_members WHERE group_id = ? AND bot_id = ?").run(e.id,n),t))td.prepare("DELETE FROM conversation_participants WHERE conversation_id = ? AND participant_kind = 'bot' AND participant_id = ?").run(i,n);e.newOwner&&td.prepare("UPDATE groups SET owner_bot_id = ? WHERE id = ?").run(e.newOwner.id,e.id)}for(let n of e){for(let e of td.prepare("SELECT id FROM conversations WHERE bot_id = ?").all(n))tU(e.id);e6(td,n),tD("bot_id",n),td.prepare("DELETE FROM launch_snapshots WHERE bot_id = ?").run(n),td.prepare("DELETE FROM group_members WHERE bot_id = ?").run(n),td.prepare("DELETE FROM conversation_participants WHERE participant_kind = 'bot' AND participant_id = ? AND conversation_id IN (SELECT id FROM conversations WHERE type = 'group')").run(n),td.prepare("DELETE FROM memories WHERE bot_id = ?").run(n),td.prepare("DELETE FROM one_shots WHERE bot_id = ?").run(n),td.prepare("DELETE FROM routines WHERE bot_id = ?").run(n),td.prepare("DELETE FROM pending_questions WHERE bot_id = ?").run(n),td.prepare("DELETE FROM approval_requests WHERE bot_id = ?").run(n),td.prepare("DELETE FROM wake_targets WHERE target_bot_id = ?").run(n),td.prepare("DELETE FROM bots WHERE id = ?").run(n),t?.onAgentDeleted?.(n)}return n})(),managementRows:()=>{let e=td.prepare("SELECT * FROM bots ORDER BY created_at DESC, id ASC").all(),t=new Set(ty()),n=new Map,i=e=>{for(let t of e)t.id&&t.at&&(n.get(t.id)??0)<t.at&&n.set(t.id,t.at)};return i(td.prepare("SELECT c.bot_id AS id, MAX(m.created_at) AS at FROM messages m JOIN conversations c ON c.id = m.conversation_id WHERE c.type = 'bot' GROUP BY c.bot_id").all()),i(td.prepare("SELECT sender_id AS id, MAX(created_at) AS at FROM messages WHERE sender_type = 'bot' AND sender_id IS NOT NULL GROUP BY sender_id").all()),e.map(e=>({bot:e,last_activity:n.get(e.id)??null,blocked:(0,J.isChiefOfStaffName)(e.name)?"chief":t.has(e.id)?"active":null}))}};class tq extends Error{preview;constructor(e){super(e.missing.length>0?"Agent not found":"Some agents cannot be deleted"),this.preview=e}}function ty(){return td.prepare(`
1895
+ SELECT DISTINCT target_agent_id AS bot_id FROM work_requests
1896
+ WHERE (executor <> 'dispatcher' AND state IN ('queued', 'running'))
1897
+ OR (executor = 'dispatcher' AND state = 'running' AND json_extract(policy_snapshot, '$.surface') = 'ui')
1898
+ `).all().map(e=>e.bot_id)}function tb(){return new Set(td.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('legacy_agent_requests_archive', 'legacy_agent_request_events_archive', 'legacy_processing_queue_archive')").all().map(e=>e.name))}function tD(e,t){tb().has("legacy_processing_queue_archive")&&td.prepare(`DELETE FROM legacy_processing_queue_archive WHERE ${e} = ?`).run(t)}function tU(e){let t;e2(td,e),td.prepare("DELETE FROM draft_actions WHERE message_id IN (SELECT id FROM messages WHERE conversation_id = ?)").run(e),t=tb(),tD("conversation_id",e),t.has("legacy_agent_request_events_archive")&&t.has("legacy_agent_requests_archive")&&td.prepare("DELETE FROM legacy_agent_request_events_archive WHERE request_id IN (SELECT id FROM legacy_agent_requests_archive WHERE conversation_id = ?)").run(e),t.has("legacy_agent_requests_archive")&&td.prepare("DELETE FROM legacy_agent_requests_archive WHERE conversation_id = ?").run(e),td.prepare("DELETE FROM messages WHERE conversation_id = ?").run(e),td.prepare("DELETE FROM pending_questions WHERE conversation_id = ?").run(e),td.prepare("DELETE FROM approvals WHERE conversation_id = ?").run(e),td.prepare("DELETE FROM approval_requests WHERE conversation_id = ?").run(e),td.prepare("DELETE FROM one_shots WHERE conversation_id = ?").run(e),td.prepare("DELETE FROM routines WHERE conversation_id = ?").run(e),td.prepare("DELETE FROM wake_targets WHERE conversation_id = ?").run(e),td.prepare("DELETE FROM conversation_participants WHERE conversation_id = ?").run(e),td.prepare("DELETE FROM conversations WHERE id = ?").run(e)}let tF={getByBotId:e=>td.prepare("SELECT * FROM conversations WHERE bot_id = ?").get(e),getByGroupId:e=>td.prepare("SELECT * FROM conversations WHERE group_id = ?").get(e),getById:e=>td.prepare("SELECT * FROM conversations WHERE id = ?").get(e),getUiById:e=>td.prepare("SELECT * FROM conversations WHERE id = ? AND type != 'agent'").get(e)},tW={create:(e,t,n,i,r)=>{let a={id:(0,s.randomUUID)(),conversation_id:e,sender_type:t,sender_id:i,sender_kind:"bot"===t?"bot":tk.kind,content:n,handoff_targets:r&&r.length>0?JSON.stringify(r):null,created_at:Date.now()};if(td.prepare("INSERT INTO messages (id, conversation_id, sender_type, sender_id, sender_kind, content, handoff_targets, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(a.id,a.conversation_id,a.sender_type,a.sender_id||null,a.sender_kind,a.content,a.handoff_targets||null,a.created_at),"bot"===t){i&&tC.markUnread(i);let t=td.prepare("SELECT bot_id FROM conversations WHERE id = ? AND type = ?").get(e,"bot");t?.bot_id&&t.bot_id!==i&&tC.markUnread(t.bot_id)}return a},getById:e=>td.prepare("SELECT * FROM messages WHERE id = ?").get(e),replaceContent:(e,t)=>{td.prepare("UPDATE messages SET content = ? WHERE id = ?").run(t,e)},getByConversation:e=>td.prepare("SELECT * FROM messages WHERE conversation_id = ? ORDER BY created_at ASC").all(e),getBetween:(e,t)=>{let n=tW.getById(e),i=tW.getById(t);if(!n||!i||n.conversation_id!==i.conversation_id)return null;let r=td.prepare("SELECT * FROM messages WHERE conversation_id = ? ORDER BY created_at ASC, rowid ASC").all(n.conversation_id),s=r.findIndex(t=>t.id===e),a=r.findIndex(e=>e.id===t);if(s<0||a<0)return null;let[o,_]=s<a?[s,a]:[a,s];return r.slice(o+1,_)},latestFromBot:e=>{let t=tF.getByBotId(e);for(let n of td.prepare(`SELECT content, conversation_id, created_at FROM messages
1899
+ WHERE sender_type = 'bot' AND sender_id = ?
1900
+ ORDER BY created_at DESC, rowid DESC
1901
+ LIMIT 20`).all(e)){if(t&&n.conversation_id!==t.id)continue;let e=td.prepare(`SELECT content FROM messages
1902
+ WHERE conversation_id = ? AND created_at < ?
1903
+ ORDER BY created_at DESC, rowid DESC
1904
+ LIMIT 1`).get(n.conversation_id,n.created_at);if(!(e&&e.content.startsWith("[From ")))return n.content}return""},priorSentenceForHandoff:e=>{if(!e.handoff_targets)return null;let t=[];try{let n=JSON.parse(e.handoff_targets);if(!Array.isArray(n))return null;t=n.map(e=>String(e))}catch{return null}let n=td.prepare(`
1905
+ SELECT m.conversation_id AS conversation_id, c.type AS type, c.bot_id AS bot_id
1906
+ FROM messages m
1907
+ JOIN conversations c ON c.id = m.conversation_id
1908
+ WHERE m.content = ? AND m.handoff_targets = ?
1909
+ ORDER BY m.created_at ASC
1910
+ `).all(e.content,e.handoff_targets).find(e=>"group"===e.type||!e.bot_id||!t.includes(e.bot_id)),i=n?.conversation_id||e.conversation_id,r=tW.getByConversation(i),s=[...r].reverse().find(t=>"user"===t.sender_type&&t.content===e.content&&t.handoff_targets===e.handoff_targets),a=s?s.created_at:e.created_at;for(let e=r.length-1;e>=0;e--){let t=r[e];if(s&&t.id===s.id||t.created_at>a||"bot"!==t.sender_type)continue;let n=(t.content||"").trim();if(n)return n}return null}},tX={get:(e,t)=>td.prepare("SELECT * FROM approvals WHERE conversation_id = ? AND code = ?").get(e,t),recordPending:(e,t,n)=>(td.prepare("INSERT OR IGNORE INTO approvals (conversation_id, code, message_id, status, created_at) VALUES (?, ?, ?, ?, ?)").run(e,t,n||null,"pending",Date.now()),tX.get(e,t)),resolve:(e,t,n)=>Number(td.prepare("UPDATE approvals SET status = ?, resolved_at = ? WHERE conversation_id = ? AND code = ? AND status = 'pending'").run(n,Date.now(),e,t).changes)>0},tx=20;function tG(e){let t=tr(e);if(!t)return{ok:!1,reason:"not_found",requested:String(e??"")};let n=td.prepare("SELECT id, name FROM bots WHERE name_key = ? LIMIT 2").all(t);return 0===n.length?{ok:!1,reason:"not_found",requested:e}:n.length>1?{ok:!1,reason:"ambiguous",requested:e}:{ok:!0,agentId:n[0].id,displayName:n[0].name}}td.exec(`
1911
+ CREATE TABLE IF NOT EXISTS wake_targets (
1912
+ id TEXT PRIMARY KEY,
1913
+ conversation_id TEXT NOT NULL,
1914
+ source_bot_id TEXT,
1915
+ source_message_id TEXT,
1916
+ requested_target TEXT NOT NULL,
1917
+ target_bot_id TEXT NOT NULL,
1918
+ target_name_snapshot TEXT NOT NULL,
1919
+ created_at INTEGER NOT NULL,
1920
+ FOREIGN KEY (conversation_id) REFERENCES conversations(id),
1921
+ FOREIGN KEY (target_bot_id) REFERENCES bots(id)
1922
+ );
1923
+
1924
+ CREATE INDEX IF NOT EXISTS idx_wake_targets_conversation
1925
+ ON wake_targets(conversation_id, created_at);
1926
+ CREATE INDEX IF NOT EXISTS idx_wake_targets_target
1927
+ ON wake_targets(target_bot_id, created_at);
1928
+ `),td.exec(`
1929
+ CREATE TABLE IF NOT EXISTS workspace_settings (
1930
+ key TEXT PRIMARY KEY,
1931
+ value TEXT NOT NULL,
1932
+ updated_at INTEGER NOT NULL
1933
+ );
1934
+ `),e.s(["BotDeletionError",0,tq,"UI_OWNER_PRINCIPAL",0,tk,"agentNameMigrations",0,{list:()=>td.prepare("SELECT * FROM agent_name_migrations ORDER BY created_at ASC, rowid ASC").all()},"approvals",0,tX,"bots",0,tC,"conversations",0,tF,"default",0,td,"draftActions",0,{get:e=>td.prepare("SELECT * FROM draft_actions WHERE message_id = ?").get(e),record:(e,t,n)=>Number(td.prepare("INSERT OR IGNORE INTO draft_actions (message_id, status, recipient, acted_at) VALUES (?, ?, ?, ?)").run(e,t,n||null,Date.now()).changes)>0},"engine",0,tI,"groups",0,{create:(e,t,n,i)=>{let r=n&&t.includes(n)?n:t[0],a={id:(0,s.randomUUID)(),name:e,owner_bot_id:r,created_at:i?.created_at??Date.now()},o=td.prepare("INSERT INTO groups (id, name, owner_bot_id, created_at) VALUES (?, ?, ?, ?)"),_=td.prepare("INSERT INTO group_members (group_id, bot_id) VALUES (?, ?)"),d=td.prepare("INSERT INTO conversations (id, type, group_id, created_at) VALUES (?, ?, ?, ?)");return td.transaction(()=>{for(let e of(o.run(a.id,a.name,a.owner_bot_id||null,a.created_at),t))_.run(a.id,e);let e=(0,s.randomUUID)();d.run(e,"group",a.id,a.created_at),tv(e,t,a.created_at)})(),a},getAll:()=>td.prepare("SELECT * FROM groups ORDER BY created_at DESC").all(),getById:e=>td.prepare("SELECT * FROM groups WHERE id = ?").get(e),rename:(e,t)=>{td.prepare("UPDATE groups SET name = ? WHERE id = ?").run(t,e)},getMembers:e=>td.prepare(`
1935
+ SELECT b.* FROM bots b
1936
+ JOIN group_members gm ON b.id = gm.bot_id
1937
+ WHERE gm.group_id = ?
1938
+ `).all(e)},"launchSnapshots",0,{record:(e,t,n,i,r="hermes-gateway")=>{td.prepare("INSERT OR IGNORE INTO launch_snapshots (id, bot_id, created_at, hash, snapshot, transport) VALUES (?, ?, ?, ?, ?, ?)").run(e,t,Date.now(),n,i,r)},listByBot:e=>td.prepare("SELECT * FROM launch_snapshots WHERE bot_id = ? ORDER BY created_at DESC, rowid DESC").all(e)},"mcpServers",0,{create:(e,t,n)=>{let i={id:(0,s.randomUUID)(),name:e,command:t,args:JSON.stringify(n),created_at:Date.now()};return td.prepare("INSERT INTO mcp_servers (id, name, command, args, created_at) VALUES (?, ?, ?, ?, ?)").run(i.id,i.name,i.command,i.args,i.created_at),i},list:()=>td.prepare("SELECT * FROM mcp_servers ORDER BY created_at ASC").all()},"memories",0,{rememberStatement:(e,t)=>{var n;let i;if(!e||!(i=t.trim())||/[??]\s*$/.test(i)||/^\[mcp\]/i.test(i)||/^\[tool (?:call|result)\]/i.test(i)||/^\[Handing off to\b/i.test(i)||/^\[From [^\]]+\]/i.test(i)||/^Peer handoff:/i.test(i)||/reply with exactly\b/i.test(i)||(n=i,/^(who|what|when|where|why|how|which|whose|whom)\b/i.test(n)?!/^(what|how|why|where|when|who)\s+i\b/i.test(n):!!(/^(do|does|did|can|could|would|will|should|shall|is|are|am|was|were|have|has)\s+(you|i|we|they|he|she|it|there|the|a|an|my|your|our)\b/i.test(n)||/^(tell me|please tell)\b/i.test(n))))return;let r=t.trim();td.prepare("INSERT INTO memories (id, bot_id, fact, created_at) VALUES (?, ?, ?, ?)").run((0,s.randomUUID)(),e,r,Date.now()),td.prepare(`
1939
+ DELETE FROM memories
1940
+ WHERE bot_id = ?
1941
+ AND id NOT IN (
1942
+ SELECT id FROM (
1943
+ SELECT id FROM memories
1944
+ WHERE bot_id = ?
1945
+ ORDER BY created_at DESC, rowid DESC
1946
+ LIMIT ?
1947
+ )
1948
+ )
1949
+ `).run(e,e,tx)},latestFacts:(e,t=tx)=>{let n=t>0?Math.min(t,tx):tx;return td.prepare("SELECT fact FROM memories WHERE bot_id = ? ORDER BY created_at DESC, rowid DESC LIMIT ?").all(e,n).map(e=>e.fact).reverse()}},"messages",0,tW,"oneShots",0,{create:(e,t,n)=>{let i={id:(0,s.randomUUID)(),conversation_id:e,bot_id:t,due_at:n,fired:0,created_at:Date.now()};return td.prepare("INSERT INTO one_shots (id, conversation_id, bot_id, due_at, fired, created_at) VALUES (?, ?, ?, ?, 0, ?)").run(i.id,i.conversation_id,i.bot_id,i.due_at,i.created_at),i},pending:e=>td.prepare("SELECT * FROM one_shots WHERE conversation_id = ? AND fired = 0 ORDER BY due_at ASC LIMIT 1").get(e),unfired:()=>td.prepare("SELECT * FROM one_shots WHERE fired = 0 ORDER BY due_at ASC").all(),claim:e=>1===td.prepare("UPDATE one_shots SET fired = 1 WHERE id = ? AND fired = 0").run(e).changes},"projector",0,tA,"registrationContext",0,{getConnection:e=>th.getById(e),localConnectionFor:e=>tT(e),sessionBelongsTo:function(e,t){return!!e&&(!!td.prepare("SELECT 1 FROM session_bindings WHERE id = ? AND agent_id = ?").get(t,e)||!!td.prepare("SELECT 1 FROM provider_sessions WHERE id = ? AND agent_id = ?").get(t,e))}},"resolveWakeTarget",0,tG,"routines",0,{create:(e,t,n,i,r)=>{let a={id:(0,s.randomUUID)(),conversation_id:e,bot_id:t,word:n,next_due_at:i,every_ms:r,created_at:Date.now()};return td.prepare("INSERT INTO routines (id, conversation_id, bot_id, word, next_due_at, every_ms, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)").run(a.id,a.conversation_id,a.bot_id,a.word,a.next_due_at,a.every_ms,a.created_at),a},forConversation:e=>td.prepare("SELECT * FROM routines WHERE conversation_id = ? ORDER BY created_at ASC LIMIT 1").get(e),all:()=>td.prepare("SELECT * FROM routines ORDER BY next_due_at ASC").all(),postIfDue:(e,t)=>td.transaction(()=>{let n=td.prepare("SELECT * FROM routines WHERE id = ?").get(e);return!!n&&!(n.next_due_at>t)&&1===td.prepare("UPDATE routines SET next_due_at = next_due_at + every_ms WHERE id = ? AND next_due_at = ?").run(e,n.next_due_at).changes&&(tW.create(n.conversation_id,"bot","[routine]\n"+n.word,n.bot_id),!0)})()},"runtimeConnections",0,th,"serializeAgent",0,function(e){let t=(0,a.serializeBot)(e);for(let e of tw)delete t[e];let n=e.runtime_connection_id?th.getById(e.runtime_connection_id):void 0;return{...t,...j(e,n),launch_profile:F(e)}},"serviceAudit",0,tS,"wakeTargets",0,{accept:e=>{let t=tG(e.requestedTarget);if(!t.ok)return t;let n={id:(0,s.randomUUID)(),conversation_id:e.conversationId,source_bot_id:e.sourceBotId??null,source_message_id:e.sourceMessageId??null,requested_target:e.requestedTarget,target_bot_id:t.agentId,target_name_snapshot:t.displayName,created_at:Date.now()};return td.prepare("INSERT INTO wake_targets (id, conversation_id, source_bot_id, source_message_id, requested_target, target_bot_id, target_name_snapshot, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run(n.id,n.conversation_id,n.source_bot_id,n.source_message_id,n.requested_target,n.target_bot_id,n.target_name_snapshot,n.created_at),{ok:!0,wake:n}},listByConversation:e=>td.prepare("SELECT * FROM wake_targets WHERE conversation_id = ? ORDER BY created_at ASC, rowid ASC").all(e)},"workspaceSettings",0,{get:e=>{let t=td.prepare("SELECT value FROM workspace_settings WHERE key = ?").get(e);return t?t.value:null},set:(e,t)=>{td.prepare("INSERT INTO workspace_settings (key, value, updated_at) VALUES (?, ?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at").run(e,t,Date.now())},clearForTests:()=>{td.prepare("DELETE FROM workspace_settings").run()}}],62294)}];
1950
+
1951
+ //# sourceMappingURL=lib_db_ts_1ttuckb._.js.map