botmancers 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (389) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +5 -5
  3. package/app/.next/BUILD_ID +1 -1
  4. package/app/.next/app-path-routes-manifest.json +12 -1
  5. package/app/.next/build-manifest.json +3 -3
  6. package/app/.next/prerender-manifest.json +4 -4
  7. package/app/.next/required-server-files.json +2 -2
  8. package/app/.next/routes-manifest.json +90 -0
  9. package/app/.next/server/app/_global-error.html +1 -1
  10. package/app/.next/server/app/_global-error.rsc +1 -1
  11. package/app/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  12. package/app/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  13. package/app/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/app/.next/server/app/_not-found/page.js.nft.json +1 -1
  15. package/app/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  16. package/app/.next/server/app/_not-found.html +1 -1
  17. package/app/.next/server/app/_not-found.rsc +2 -2
  18. package/app/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  19. package/app/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
  20. package/app/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  21. package/app/.next/server/app/agents/[id]/activity/page/app-paths-manifest.json +3 -0
  22. package/app/.next/server/app/agents/[id]/activity/page/next-font-manifest.json +11 -0
  23. package/app/.next/server/app/agents/[id]/activity/page.js +14 -0
  24. package/app/.next/server/app/agents/[id]/activity/page.js.nft.json +1 -0
  25. package/app/.next/server/app/agents/[id]/activity/page_client-reference-manifest.js +3 -0
  26. package/app/.next/server/app/agents/[id]/conversations/[conversationId]/page/app-paths-manifest.json +3 -0
  27. package/app/.next/server/app/agents/[id]/conversations/[conversationId]/page/build-manifest.json +20 -0
  28. package/app/.next/server/app/agents/[id]/conversations/[conversationId]/page/next-font-manifest.json +11 -0
  29. package/app/.next/server/app/agents/[id]/conversations/[conversationId]/page/react-loadable-manifest.json +1 -0
  30. package/app/.next/server/app/agents/[id]/conversations/[conversationId]/page/server-reference-manifest.json +4 -0
  31. package/app/.next/server/app/agents/[id]/conversations/[conversationId]/page.js +14 -0
  32. package/app/.next/server/app/agents/[id]/conversations/[conversationId]/page.js.nft.json +1 -0
  33. package/app/.next/server/app/agents/[id]/conversations/[conversationId]/page_client-reference-manifest.js +3 -0
  34. package/app/.next/server/app/agents/[id]/conversations/page/app-paths-manifest.json +3 -0
  35. package/app/.next/server/app/agents/[id]/conversations/page/build-manifest.json +20 -0
  36. package/app/.next/server/app/agents/[id]/conversations/page/next-font-manifest.json +11 -0
  37. package/app/.next/server/app/agents/[id]/conversations/page/react-loadable-manifest.json +1 -0
  38. package/app/.next/server/app/agents/[id]/conversations/page/server-reference-manifest.json +4 -0
  39. package/app/.next/server/app/agents/[id]/conversations/page.js +14 -0
  40. package/app/.next/server/app/agents/[id]/conversations/page.js.nft.json +1 -0
  41. package/app/.next/server/app/agents/[id]/conversations/page_client-reference-manifest.js +3 -0
  42. package/app/.next/server/app/agents/[id]/page/app-paths-manifest.json +3 -0
  43. package/app/.next/server/app/agents/[id]/page/build-manifest.json +20 -0
  44. package/app/.next/server/app/{threads → agents}/[id]/page/next-font-manifest.json +1 -1
  45. package/app/.next/server/app/agents/[id]/page/react-loadable-manifest.json +1 -0
  46. package/app/.next/server/app/agents/[id]/page/server-reference-manifest.json +4 -0
  47. package/app/.next/server/app/{threads → agents}/[id]/page.js +6 -5
  48. package/app/.next/server/app/{threads → agents}/[id]/page.js.nft.json +1 -1
  49. package/app/.next/server/app/agents/[id]/page_client-reference-manifest.js +3 -0
  50. package/app/.next/server/app/agents/[id]/sessions/page/app-paths-manifest.json +3 -0
  51. package/app/.next/server/app/agents/[id]/sessions/page/build-manifest.json +20 -0
  52. package/app/.next/server/app/agents/[id]/sessions/page/next-font-manifest.json +11 -0
  53. package/app/.next/server/app/agents/[id]/sessions/page/react-loadable-manifest.json +1 -0
  54. package/app/.next/server/app/agents/[id]/sessions/page/server-reference-manifest.json +4 -0
  55. package/app/.next/server/app/agents/[id]/sessions/page.js +14 -0
  56. package/app/.next/server/app/agents/[id]/sessions/page.js.nft.json +1 -0
  57. package/app/.next/server/app/agents/[id]/sessions/page_client-reference-manifest.js +3 -0
  58. package/app/.next/server/app/agents/[id]/slack/page/app-paths-manifest.json +3 -0
  59. package/app/.next/server/app/agents/[id]/slack/page/build-manifest.json +20 -0
  60. package/app/.next/server/app/agents/[id]/slack/page/next-font-manifest.json +11 -0
  61. package/app/.next/server/app/agents/[id]/slack/page/react-loadable-manifest.json +1 -0
  62. package/app/.next/server/app/agents/[id]/slack/page/server-reference-manifest.json +4 -0
  63. package/app/.next/server/app/agents/[id]/slack/page.js +14 -0
  64. package/app/.next/server/app/agents/[id]/slack/page.js.nft.json +1 -0
  65. package/app/.next/server/app/agents/[id]/slack/page_client-reference-manifest.js +3 -0
  66. package/app/.next/server/app/api/bots/[id]/activity/route/app-paths-manifest.json +3 -0
  67. package/app/.next/server/app/api/bots/[id]/activity/route/build-manifest.json +12 -0
  68. package/app/.next/server/app/api/bots/[id]/activity/route/server-reference-manifest.json +4 -0
  69. package/app/.next/server/app/api/bots/[id]/activity/route.js +9 -0
  70. package/app/.next/server/app/api/bots/[id]/activity/route.js.nft.json +1 -0
  71. package/app/.next/server/app/api/bots/[id]/activity/route_client-reference-manifest.js +3 -0
  72. package/app/.next/server/app/api/bots/[id]/config/route.js +1 -1
  73. package/app/.next/server/app/api/bots/[id]/config/route.js.nft.json +1 -1
  74. package/app/.next/server/app/api/bots/[id]/conversations/[conversationId]/route/app-paths-manifest.json +3 -0
  75. package/app/.next/server/app/api/bots/[id]/conversations/[conversationId]/route/build-manifest.json +12 -0
  76. package/app/.next/server/app/api/bots/[id]/conversations/[conversationId]/route/server-reference-manifest.json +4 -0
  77. package/app/.next/server/app/api/bots/[id]/conversations/[conversationId]/route.js +12 -0
  78. package/app/.next/server/app/api/bots/[id]/conversations/[conversationId]/route.js.nft.json +1 -0
  79. package/app/.next/server/app/api/bots/[id]/conversations/[conversationId]/route_client-reference-manifest.js +3 -0
  80. package/app/.next/server/app/api/bots/[id]/conversations/route/app-paths-manifest.json +3 -0
  81. package/app/.next/server/app/api/bots/[id]/conversations/route/build-manifest.json +12 -0
  82. package/app/.next/server/app/api/bots/[id]/conversations/route/server-reference-manifest.json +4 -0
  83. package/app/.next/server/app/api/bots/[id]/conversations/route.js +12 -0
  84. package/app/.next/server/app/api/bots/[id]/conversations/route.js.nft.json +1 -0
  85. package/app/.next/server/app/api/bots/[id]/conversations/route_client-reference-manifest.js +3 -0
  86. package/app/.next/server/app/api/bots/[id]/overview/route/app-paths-manifest.json +3 -0
  87. package/app/.next/server/app/api/bots/[id]/overview/route/build-manifest.json +12 -0
  88. package/app/.next/server/app/api/bots/[id]/overview/route/server-reference-manifest.json +4 -0
  89. package/app/.next/server/app/api/bots/[id]/overview/route.js +12 -0
  90. package/app/.next/server/app/api/bots/[id]/overview/route.js.nft.json +1 -0
  91. package/app/.next/server/app/api/bots/[id]/overview/route_client-reference-manifest.js +3 -0
  92. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/pins/route.js +2 -2
  93. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/pins/route.js.nft.json +1 -1
  94. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route.js +2 -2
  95. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/route.js.nft.json +1 -1
  96. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/shares/route.js +1 -1
  97. package/app/.next/server/app/api/bots/[id]/sessions/[ref]/shares/route.js.nft.json +1 -1
  98. package/app/.next/server/app/api/bots/[id]/sessions/route.js +3 -3
  99. package/app/.next/server/app/api/bots/[id]/sessions/route.js.nft.json +1 -1
  100. package/app/.next/server/app/api/bots/[id]/sessions/sync/route/app-paths-manifest.json +3 -0
  101. package/app/.next/server/app/api/bots/[id]/sessions/sync/route/build-manifest.json +12 -0
  102. package/app/.next/server/app/api/bots/[id]/sessions/sync/route/server-reference-manifest.json +4 -0
  103. package/app/.next/server/app/api/bots/[id]/sessions/sync/route.js +11 -0
  104. package/app/.next/server/app/api/bots/[id]/sessions/sync/route.js.nft.json +1 -0
  105. package/app/.next/server/app/api/bots/[id]/sessions/sync/route_client-reference-manifest.js +3 -0
  106. package/app/.next/server/app/api/bots/[id]/share-policy/route.js +1 -1
  107. package/app/.next/server/app/api/bots/[id]/share-policy/route.js.nft.json +1 -1
  108. package/app/.next/server/app/api/bots/[id]/skill/route.js +1 -1
  109. package/app/.next/server/app/api/bots/[id]/skill/route.js.nft.json +1 -1
  110. package/app/.next/server/app/api/bots/availability/route.js.nft.json +1 -1
  111. package/app/.next/server/app/api/bots/delete-preview/route.js +1 -1
  112. package/app/.next/server/app/api/bots/delete-preview/route.js.nft.json +1 -1
  113. package/app/.next/server/app/api/bots/import/route.js +1 -1
  114. package/app/.next/server/app/api/bots/import/route.js.nft.json +1 -1
  115. package/app/.next/server/app/api/bots/manage/route.js +1 -1
  116. package/app/.next/server/app/api/bots/manage/route.js.nft.json +1 -1
  117. package/app/.next/server/app/api/bots/name-migrations/route.js +1 -1
  118. package/app/.next/server/app/api/bots/name-migrations/route.js.nft.json +1 -1
  119. package/app/.next/server/app/api/bots/route.js +5 -5
  120. package/app/.next/server/app/api/bots/route.js.nft.json +1 -1
  121. package/app/.next/server/app/api/conversations/[id]/approve/route.js.nft.json +1 -1
  122. package/app/.next/server/app/api/conversations/[id]/deny/route.js.nft.json +1 -1
  123. package/app/.next/server/app/api/conversations/[id]/draft/route.js +1 -1
  124. package/app/.next/server/app/api/conversations/[id]/draft/route.js.nft.json +1 -1
  125. package/app/.next/server/app/api/conversations/[id]/messages/[messageId]/stop/route.js.nft.json +1 -1
  126. package/app/.next/server/app/api/conversations/[id]/messages/route.js +5 -5
  127. package/app/.next/server/app/api/conversations/[id]/messages/route.js.nft.json +1 -1
  128. package/app/.next/server/app/api/conversations/[id]/route.js +1 -1
  129. package/app/.next/server/app/api/conversations/[id]/route.js.nft.json +1 -1
  130. package/app/.next/server/app/api/conversations/[id]/stop/route.js +6 -6
  131. package/app/.next/server/app/api/conversations/[id]/stop/route.js.nft.json +1 -1
  132. package/app/.next/server/app/api/conversations/route.js +1 -1
  133. package/app/.next/server/app/api/conversations/route.js.nft.json +1 -1
  134. package/app/.next/server/app/api/exchanges/[id]/cancel/route.js +1 -1
  135. package/app/.next/server/app/api/exchanges/[id]/cancel/route.js.nft.json +1 -1
  136. package/app/.next/server/app/api/exchanges/[id]/route.js +1 -1
  137. package/app/.next/server/app/api/exchanges/[id]/route.js.nft.json +1 -1
  138. package/app/.next/server/app/api/exchanges/route.js +2 -2
  139. package/app/.next/server/app/api/exchanges/route.js.nft.json +1 -1
  140. package/app/.next/server/app/api/files/[name]/route.js +1 -1
  141. package/app/.next/server/app/api/files/[name]/route.js.nft.json +1 -1
  142. package/app/.next/server/app/api/groups/route.js +1 -1
  143. package/app/.next/server/app/api/groups/route.js.nft.json +1 -1
  144. package/app/.next/server/app/api/health/route.js +1 -1
  145. package/app/.next/server/app/api/health/route.js.nft.json +1 -1
  146. package/app/.next/server/app/api/import-capabilities/route.js.nft.json +1 -1
  147. package/app/.next/server/app/api/marketplace-handoff/route.js.nft.json +1 -1
  148. package/app/.next/server/app/api/marketplace-handoff/status/route.js.nft.json +1 -1
  149. package/app/.next/server/app/api/mcp/route.js +1 -1
  150. package/app/.next/server/app/api/mcp/route.js.nft.json +1 -1
  151. package/app/.next/server/app/api/messages/[id]/between/route.js +1 -1
  152. package/app/.next/server/app/api/messages/[id]/between/route.js.nft.json +1 -1
  153. package/app/.next/server/app/api/runtime-connections/route.js +1 -1
  154. package/app/.next/server/app/api/runtime-connections/route.js.nft.json +1 -1
  155. package/app/.next/server/app/api/service-grants/route.js.nft.json +1 -1
  156. package/app/.next/server/app/api/shares/[shareRef]/revoke/route.js +1 -1
  157. package/app/.next/server/app/api/shares/[shareRef]/revoke/route.js.nft.json +1 -1
  158. package/app/.next/server/app/api/shares/route.js +1 -1
  159. package/app/.next/server/app/api/shares/route.js.nft.json +1 -1
  160. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route.js +4 -3
  161. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route.js.nft.json +1 -1
  162. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route.js +4 -3
  163. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route.js.nft.json +1 -1
  164. package/app/.next/server/app/api/v0/agents/[agentId]/messages/route.js +1 -1
  165. package/app/.next/server/app/api/v0/agents/[agentId]/messages/route.js.nft.json +1 -1
  166. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route.js +4 -3
  167. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route.js.nft.json +1 -1
  168. package/app/.next/server/app/api/v0/agents/[agentId]/route.js +4 -3
  169. package/app/.next/server/app/api/v0/agents/[agentId]/route.js.nft.json +1 -1
  170. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route.js +4 -3
  171. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route.js.nft.json +1 -1
  172. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route.js +4 -3
  173. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route.js.nft.json +1 -1
  174. package/app/.next/server/app/api/v0/agents/route.js +4 -3
  175. package/app/.next/server/app/api/v0/agents/route.js.nft.json +1 -1
  176. package/app/.next/server/app/api/v0/capabilities/route.js +4 -3
  177. package/app/.next/server/app/api/v0/capabilities/route.js.nft.json +1 -1
  178. package/app/.next/server/app/api/v0/conversations/[id]/route.js +1 -1
  179. package/app/.next/server/app/api/v0/conversations/[id]/route.js.nft.json +1 -1
  180. package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route.js +4 -3
  181. package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route.js.nft.json +1 -1
  182. package/app/.next/server/app/api/v0/exchanges/[id]/route.js +4 -3
  183. package/app/.next/server/app/api/v0/exchanges/[id]/route.js.nft.json +1 -1
  184. package/app/.next/server/app/api/v0/exchanges/route.js +4 -3
  185. package/app/.next/server/app/api/v0/exchanges/route.js.nft.json +1 -1
  186. package/app/.next/server/app/api/v0/mcp/route.js +6 -5
  187. package/app/.next/server/app/api/v0/mcp/route.js.nft.json +1 -1
  188. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route.js +4 -3
  189. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route.js.nft.json +1 -1
  190. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route.js +4 -3
  191. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route.js.nft.json +1 -1
  192. package/app/.next/server/app/api/v0/pins/[pinRef]/route.js +4 -3
  193. package/app/.next/server/app/api/v0/pins/[pinRef]/route.js.nft.json +1 -1
  194. package/app/.next/server/app/api/v0/requests/[id]/route.js +1 -1
  195. package/app/.next/server/app/api/v0/requests/[id]/route.js.nft.json +1 -1
  196. package/app/.next/server/app/api/v0/sessions/[ref]/messages/route.js +4 -3
  197. package/app/.next/server/app/api/v0/sessions/[ref]/messages/route.js.nft.json +1 -1
  198. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route.js +4 -3
  199. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route.js.nft.json +1 -1
  200. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route.js +4 -3
  201. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route.js.nft.json +1 -1
  202. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route.js +4 -3
  203. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route.js.nft.json +1 -1
  204. package/app/.next/server/app/api/v0/shares/[shareRef]/route.js +4 -3
  205. package/app/.next/server/app/api/v0/shares/[shareRef]/route.js.nft.json +1 -1
  206. package/app/.next/server/app/api/v0/shares/current/route.js +4 -3
  207. package/app/.next/server/app/api/v0/shares/current/route.js.nft.json +1 -1
  208. package/app/.next/server/app/api/v0/shares/route.js +4 -3
  209. package/app/.next/server/app/api/v0/shares/route.js.nft.json +1 -1
  210. package/app/.next/server/app/api/wake-grants/[id]/revoke/route.js +1 -1
  211. package/app/.next/server/app/api/wake-grants/[id]/revoke/route.js.nft.json +1 -1
  212. package/app/.next/server/app/api/wakes/[id]/decision/route.js +1 -1
  213. package/app/.next/server/app/api/wakes/[id]/decision/route.js.nft.json +1 -1
  214. package/app/.next/server/app/api/wakes/[id]/retry/route.js +1 -1
  215. package/app/.next/server/app/api/wakes/[id]/retry/route.js.nft.json +1 -1
  216. package/app/.next/server/app/bots/[id]/config/page.js.nft.json +1 -1
  217. package/app/.next/server/app/bots/[id]/config/page_client-reference-manifest.js +1 -1
  218. package/app/.next/server/app/exchanges/page.js.nft.json +1 -1
  219. package/app/.next/server/app/exchanges/page_client-reference-manifest.js +1 -1
  220. package/app/.next/server/app/exchanges.html +1 -1
  221. package/app/.next/server/app/exchanges.rsc +3 -3
  222. package/app/.next/server/app/exchanges.segments/_full.segment.rsc +3 -3
  223. package/app/.next/server/app/exchanges.segments/_tree.segment.rsc +2 -2
  224. package/app/.next/server/app/exchanges.segments/exchanges/__PAGE__.segment.rsc +3 -3
  225. package/app/.next/server/app/index.html +1 -1
  226. package/app/.next/server/app/index.rsc +3 -3
  227. package/app/.next/server/app/index.segments/__PAGE__.segment.rsc +3 -3
  228. package/app/.next/server/app/index.segments/_full.segment.rsc +3 -3
  229. package/app/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  230. package/app/.next/server/app/page.js.nft.json +1 -1
  231. package/app/.next/server/app/page_client-reference-manifest.js +1 -1
  232. package/app/.next/server/app/settings/page.js.nft.json +1 -1
  233. package/app/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  234. package/app/.next/server/app/settings.html +1 -1
  235. package/app/.next/server/app/settings.rsc +2 -2
  236. package/app/.next/server/app/settings.segments/_full.segment.rsc +2 -2
  237. package/app/.next/server/app/settings.segments/_tree.segment.rsc +2 -2
  238. package/app/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +2 -2
  239. package/app/.next/server/app/threads/[id]/route/app-paths-manifest.json +3 -0
  240. package/app/.next/server/app/threads/[id]/route/build-manifest.json +12 -0
  241. package/app/.next/server/app/threads/[id]/route/server-reference-manifest.json +4 -0
  242. package/app/.next/server/app/threads/[id]/route.js +10 -0
  243. package/app/.next/server/app/threads/[id]/route.js.nft.json +1 -0
  244. package/app/.next/server/app/threads/[id]/route_client-reference-manifest.js +3 -0
  245. package/app/.next/server/app-paths-manifest.json +12 -1
  246. package/app/.next/server/chunks/1oeh_server_app_api_bots_[id]_conversations_[conversationId]_route_actions_11cb2lr.js +3 -0
  247. package/app/.next/server/chunks/{[root-of-the-server]__17xl_55._.js → [root-of-the-server]__03pk_x_._.js} +1 -1
  248. package/app/.next/server/chunks/{[root-of-the-server]__0mp8bap._.js → [root-of-the-server]__05ds5md._.js} +1 -1
  249. package/app/.next/server/chunks/[root-of-the-server]__0anfwiu._.js +52 -0
  250. package/app/.next/server/chunks/{[root-of-the-server]__0-w_t2y._.js → [root-of-the-server]__0atpy-s._.js} +1 -1
  251. package/app/.next/server/chunks/[root-of-the-server]__0hhill-._.js +3 -0
  252. package/app/.next/server/chunks/{[root-of-the-server]__06w5xhe._.js → [root-of-the-server]__0hiikkz._.js} +1 -1
  253. package/app/.next/server/chunks/[root-of-the-server]__0k8wfe2._.js +3 -0
  254. package/app/.next/server/chunks/{[root-of-the-server]__1eps2a4._.js → [root-of-the-server]__0pp5x67._.js} +1 -1
  255. package/app/.next/server/chunks/[root-of-the-server]__0qqsovi._.js +3 -0
  256. package/app/.next/server/chunks/{[root-of-the-server]__1dxr858._.js → [root-of-the-server]__0thkp5l._.js} +1 -1
  257. package/app/.next/server/chunks/[root-of-the-server]__0xhwlr4._.js +3 -0
  258. package/app/.next/server/chunks/{[root-of-the-server]__0-vcyi-._.js → [root-of-the-server]__11yt1hv._.js} +1 -1
  259. package/app/.next/server/chunks/[root-of-the-server]__1280ke1._.js +46 -0
  260. package/app/.next/server/chunks/{[root-of-the-server]__0iqh5ta._.js → [root-of-the-server]__12wk406._.js} +1 -1
  261. package/app/.next/server/chunks/[root-of-the-server]__13wghn3._.js +46 -0
  262. package/app/.next/server/chunks/{[root-of-the-server]__0lwsto-._.js → [root-of-the-server]__14cwco7._.js} +3 -3
  263. package/app/.next/server/chunks/{[root-of-the-server]__1kczttr._.js → [root-of-the-server]__185i_bv._.js} +1 -1
  264. package/app/.next/server/chunks/[root-of-the-server]__1byhehl._.js +3 -0
  265. package/app/.next/server/chunks/{[root-of-the-server]__10b5-i-._.js → [root-of-the-server]__1ez_5xy._.js} +1 -1
  266. package/app/.next/server/chunks/[root-of-the-server]__1jxwu9_._.js +52 -0
  267. package/app/.next/server/chunks/{[root-of-the-server]__0o9ijih._.js → [root-of-the-server]__1mxp6z6._.js} +1 -1
  268. package/app/.next/server/chunks/{[root-of-the-server]__0ey3_2x._.js → [root-of-the-server]__1s2-vw3._.js} +1 -1
  269. package/app/.next/server/chunks/{[root-of-the-server]__1hwy3jx._.js → [root-of-the-server]__1xq61ti._.js} +1 -1
  270. package/app/.next/server/chunks/{[root-of-the-server]__04b3ml2._.js → [root-of-the-server]__20om7um._.js} +1 -1
  271. package/app/.next/server/chunks/_0061c2q._.js +1 -1
  272. package/app/.next/server/chunks/_0_b7py8._.js +3 -0
  273. package/app/.next/server/chunks/_0a2do3x._.js +1 -1
  274. package/app/.next/server/chunks/_1-5mthb._.js +1 -1
  275. package/app/.next/server/chunks/_12i5gam._.js +7 -0
  276. package/app/.next/server/chunks/_1a0er16._.js +18 -0
  277. package/app/.next/server/chunks/_1uxmsh3._.js +18 -0
  278. package/app/.next/server/chunks/_next-internal_server_app_api_bots_[id]_activity_route_actions_06oyah6.js +3 -0
  279. package/app/.next/server/chunks/_next-internal_server_app_api_bots_[id]_conversations_route_actions_0op0mjv.js +3 -0
  280. package/app/.next/server/chunks/_next-internal_server_app_api_bots_[id]_overview_route_actions_20nuetv.js +3 -0
  281. package/app/.next/server/chunks/_next-internal_server_app_api_bots_[id]_sessions_sync_route_actions_00y6n-f.js +3 -0
  282. package/app/.next/server/chunks/{ssr/_next-internal_server_app_threads_[id]_page_actions_1fte2n3.js → _next-internal_server_app_threads_[id]_route_actions_13zq3u6.js} +2 -2
  283. package/app/.next/server/chunks/lib_0-opbv7._.js +69 -55
  284. package/app/.next/server/chunks/lib_0aejojj._.js +69 -55
  285. package/app/.next/server/chunks/lib_0al5wbc._.js +330 -0
  286. package/app/.next/server/chunks/lib_0i8cm07._.js +3 -0
  287. package/app/.next/server/chunks/lib_0il0ml1._.js +69 -55
  288. package/app/.next/server/chunks/lib_0iujsdg._.js +69 -55
  289. package/app/.next/server/chunks/{lib_15adnlz._.js → lib_15a9ejf._.js} +53 -44
  290. package/app/.next/server/chunks/{lib_1zc7-gl._.js → lib_19pzc33._.js} +53 -44
  291. package/app/.next/server/chunks/lib_1a4ucxv._.js +330 -0
  292. package/app/.next/server/chunks/lib_1dehbst._.js +69 -55
  293. package/app/.next/server/chunks/lib_1z4vnh4._.js +69 -55
  294. package/app/.next/server/chunks/lib_1z7d95m._.js +2181 -0
  295. package/app/.next/server/chunks/lib_service-api-http_ts_0xzqhny._.js +1 -23
  296. package/app/.next/server/chunks/lib_service-api_ts_18eok4w._.js +25 -0
  297. package/app/.next/server/chunks/node_modules_next_1zc5q0a._.js +11 -11
  298. package/app/.next/server/chunks/ssr/1oeh_server_app_agents_[id]_conversations_[conversationId]_page_actions_08lev_i.js +3 -0
  299. package/app/.next/server/chunks/ssr/[root-of-the-server]__06s7ons._.js +3 -0
  300. package/app/.next/server/chunks/ssr/[root-of-the-server]__0r8nmcc._.js +3 -0
  301. package/app/.next/server/chunks/ssr/[root-of-the-server]__19qlmru._.js +3 -0
  302. package/app/.next/server/chunks/ssr/[root-of-the-server]__1dpye-p._.js +3 -0
  303. package/app/.next/server/chunks/ssr/[root-of-the-server]__1fxu3a8._.js +3 -0
  304. package/app/.next/server/chunks/ssr/[root-of-the-server]__1t9ljq3._.js +3 -0
  305. package/app/.next/server/chunks/ssr/_0_u9-u6._.js +3 -0
  306. package/app/.next/server/chunks/ssr/_0g3y1u9._.js +3 -0
  307. package/app/.next/server/chunks/ssr/{node_modules_next_0x3i8za._.js → _0gzxfz3._.js} +2 -2
  308. package/app/.next/server/chunks/ssr/_0rvu-il._.js +131 -0
  309. package/app/.next/server/chunks/ssr/_0u7urta._.js +5 -0
  310. package/app/.next/server/chunks/ssr/_17ngohj._.js +3 -0
  311. package/app/.next/server/chunks/ssr/_1iq-7cn._.js +3 -0
  312. package/app/.next/server/chunks/ssr/_next-internal_server_app_agents_[id]_activity_page_actions_1a_v567.js +3 -0
  313. package/app/.next/server/chunks/ssr/_next-internal_server_app_agents_[id]_conversations_page_actions_1dpbbj-.js +3 -0
  314. package/app/.next/server/chunks/ssr/_next-internal_server_app_agents_[id]_page_actions_0k__y7g.js +3 -0
  315. package/app/.next/server/chunks/ssr/_next-internal_server_app_agents_[id]_sessions_page_actions_1hft42g.js +3 -0
  316. package/app/.next/server/chunks/ssr/_next-internal_server_app_agents_[id]_slack_page_actions_0dmtbj_.js +3 -0
  317. package/app/.next/server/chunks/ssr/app_1-nwnha._.js +3 -0
  318. package/app/.next/server/chunks/ssr/app_agents_[id]_009y8_j._.js +3 -0
  319. package/app/.next/server/chunks/ssr/app_agents_[id]_0sr4fdg._.js +3 -0
  320. package/app/.next/server/chunks/ssr/app_agents_[id]_activity_AgentActivityPage_tsx_042-590._.js +3 -0
  321. package/app/.next/server/chunks/ssr/app_agents_[id]_conversations_page_tsx_15zl_c8._.js +3 -0
  322. package/app/.next/server/chunks/ssr/app_agents_[id]_sessions_page_tsx_0tfup-2._.js +10 -0
  323. package/app/.next/server/chunks/ssr/app_agents_[id]_slack_AgentSlackPage_tsx_20njhs1._.js +3 -0
  324. package/app/.next/server/chunks/ssr/app_bots_[id]_config_page_tsx_1e0uue9._.js +1 -1
  325. package/app/.next/server/chunks/ssr/app_page_tsx_0pxmutw._.js +3 -0
  326. package/app/.next/server/chunks/ssr/lib_0pfn9gs._.js +3 -0
  327. package/app/.next/server/chunks/ssr/lib_agent-registration-ui_ts_1z582mm._.js +3 -0
  328. package/app/.next/server/chunks/ssr/lib_exchange-view_ts_1a4q9ju._.js +3 -0
  329. package/app/.next/server/chunks/ssr/lib_share-view_ts_08psw5o._.js +3 -0
  330. package/app/.next/server/instrumentation.js +1 -1
  331. package/app/.next/server/middleware-build-manifest.js +3 -3
  332. package/app/.next/server/next-font-manifest.js +1 -1
  333. package/app/.next/server/next-font-manifest.json +24 -4
  334. package/app/.next/server/pages/404.html +1 -1
  335. package/app/.next/server/pages/500.html +1 -1
  336. package/app/.next/server/server-reference-manifest.js +1 -1
  337. package/app/.next/server/server-reference-manifest.json +1 -1
  338. package/app/.next/static/chunks/02q7gb87r2ca3.css +3 -0
  339. package/app/.next/static/chunks/06i_6p0-ipitj.js +1 -0
  340. package/app/.next/static/chunks/0cjh4u-f7mlwd.js +1 -0
  341. package/app/.next/static/chunks/1dhk3pcv7yvm6.js +1 -0
  342. package/app/.next/static/chunks/1ka9dp1l6c0ga.js +3 -0
  343. package/app/.next/static/chunks/1ttvnc6qdye8s.js +1 -0
  344. package/app/.next/static/chunks/1ypwptc0fsn4w.js +1 -0
  345. package/app/.next/static/chunks/2-fhbx41zyanc.js +1 -0
  346. package/app/.next/static/chunks/2cc4uzbhs_v23.js +1 -0
  347. package/app/.next/static/chunks/2n1u8a2efnt88.js +1 -0
  348. package/app/.next/static/chunks/34v8aumua0x5n.js +1 -0
  349. package/app/.next/static/chunks/3aasli1i-eiio.js +1 -0
  350. package/app/.next/static/chunks/3p_p4gnr0d2-x.js +1 -0
  351. package/app/.next/static/chunks/3s9t477v-z09o.js +1 -0
  352. package/app/.next/static/chunks/3y5bo6syunkzn.js +8 -0
  353. package/app/BUILD_INFO.json +2 -2
  354. package/app/package.json +1 -1
  355. package/app/server.js +1 -1
  356. package/package.json +1 -1
  357. package/app/.next/server/app/threads/[id]/page/app-paths-manifest.json +0 -3
  358. package/app/.next/server/app/threads/[id]/page_client-reference-manifest.js +0 -3
  359. package/app/.next/server/chunks/[root-of-the-server]__0792yb1._.js +0 -44
  360. package/app/.next/server/chunks/[root-of-the-server]__0d3fjix._.js +0 -3
  361. package/app/.next/server/chunks/[root-of-the-server]__0e_agq4._.js +0 -3
  362. package/app/.next/server/chunks/[root-of-the-server]__0qaiqut._.js +0 -44
  363. package/app/.next/server/chunks/[root-of-the-server]__17mum5-._.js +0 -3
  364. package/app/.next/server/chunks/[root-of-the-server]__1x8phwp._.js +0 -44
  365. package/app/.next/server/chunks/_0qv-4by._.js +0 -3
  366. package/app/.next/server/chunks/lib_0v6lblw._.js +0 -5
  367. package/app/.next/server/chunks/lib_agent-api_ts_0iv52-o._.js +0 -3
  368. package/app/.next/server/chunks/ssr/[root-of-the-server]__1t063pe._.js +0 -3
  369. package/app/.next/server/chunks/ssr/_0_fa0na._.js +0 -3
  370. package/app/.next/server/chunks/ssr/_0a6r_bx._.js +0 -3
  371. package/app/.next/server/chunks/ssr/_0epgorw._.js +0 -3
  372. package/app/.next/server/chunks/ssr/_1cvuhjt._.js +0 -3
  373. package/app/.next/server/chunks/ssr/_1is_iwu._.js +0 -3
  374. package/app/.next/server/chunks/ssr/_1n5mvo5._.js +0 -3
  375. package/app/.next/server/chunks/ssr/_1o94bnv._.js +0 -5
  376. package/app/.next/server/chunks/ssr/app_exchanges_page_tsx_0j-n2a1._.js +0 -3
  377. package/app/.next/static/chunks/1ouuczm-gmvxs.js +0 -1
  378. package/app/.next/static/chunks/1w72fds3-utrx.js +0 -1
  379. package/app/.next/static/chunks/2095-o17ji0fs.css +0 -3
  380. package/app/.next/static/chunks/2q-tgwkalrnms.js +0 -1
  381. package/app/.next/static/chunks/34bv9o9bjkwk0.js +0 -3
  382. package/app/.next/static/chunks/3rwwunh5sdjzg.js +0 -1
  383. package/app/.next/static/chunks/3z3mn526_3fwd.js +0 -1
  384. /package/app/.next/server/app/{threads/[id] → agents/[id]/activity}/page/build-manifest.json +0 -0
  385. /package/app/.next/server/app/{threads/[id] → agents/[id]/activity}/page/react-loadable-manifest.json +0 -0
  386. /package/app/.next/server/app/{threads/[id] → agents/[id]/activity}/page/server-reference-manifest.json +0 -0
  387. /package/app/.next/static/{A9sQnaf9i6YzjHNoPgRfU → nOdd5VXbf23ohQcBBjvHa}/_buildManifest.js +0 -0
  388. /package/app/.next/static/{A9sQnaf9i6YzjHNoPgRfU → nOdd5VXbf23ohQcBBjvHa}/_clientMiddlewareManifest.js +0 -0
  389. /package/app/.next/static/{A9sQnaf9i6YzjHNoPgRfU → nOdd5VXbf23ohQcBBjvHa}/_ssgManifest.js +0 -0
@@ -1,25 +1,3 @@
1
- module.exports=[69936,9501,e=>{"use strict";var t=e.i(62294),n=e.i(43345),i=e.i(45383),r=e.i(674),s=e.i(81449),a=e.i(54799),o=e.i(62349),d=e.i(18966),c=e.i(35613),l=e.i(90027),u=e.i(63020),_=e.i(91253),g=e.i(93399),p=e.i(50081),h=e.i(16789),f=e.i(35034);let m={invalid_request:400,unsupported_field:400,authority_not_allowed:403,principal_not_allowed:403,grant_required:403,grants_unavailable:503,agent_not_found:404,session_not_found:404,conversation_not_found:404,exchange_not_found:404,session_ended:409,session_not_resumable:409,source_session_busy:409,agent_unavailable:409,destination_invalid:400,recursive_exchange:403,idempotency_conflict:409,exchange_terminal:409,conflict:409,payload_too_large:413,rate_limited:429,internal_error:500,pin_not_found:404,pin_detached:409,workspace_required:409,no_eligible_session:409,session_missing:410,action_unavailable:409,approval_required:403,provider_failed:502,share_not_found:404,share_expired:410,share_revoked:410,share_turn_in_progress:409,share_turn_limit:409,audience_not_allowed:403,session_context_required:409},y=["principal_not_allowed","grant_required","grants_unavailable","agent_not_found","session_not_found","conversation_not_found","exchange_not_found","rate_limited","pin_not_found","share_not_found","audience_not_allowed"];class w extends Error{code;notGranted;fields;recovery;reason;constructor(e,t,n={}){super(t),this.name="ServiceApiError",this.code=e,this.notGranted=!0===n.notGranted,this.fields=n.fields,this.recovery=(0,p.recoveryFor)(e),this.reason=n.reason??null}get status(){return m[this.code]}get denied(){return y.includes(this.code)}}let v={pin:()=>new w("pin_not_found","No pin with that reference is visible to this principal."),share:()=>new w("share_not_found","No share with that reference is visible to this principal."),agent:()=>new w("agent_not_found","No Agent with that id is visible to this principal."),session:()=>new w("session_not_found","No session with that reference is visible to this principal."),conversation:()=>new w("conversation_not_found","No conversation with that id is visible to this principal."),exchange:()=>new w("exchange_not_found","No exchange with that id is visible to this principal.")};function E(e){let t=v[e]();return new w(t.code,t.message,{notGranted:!0})}function S(e){switch(e.code){case"exchange_not_found":return v.exchange();case"session_not_found":return v.session();case"agent_not_found":return v.agent();case"conversation_not_found":return v.conversation();case"invalid_transition":return new w("conflict","The exchange changed concurrently; read it and retry.");default:return e.code in m?new w(e.code,e.message):new w("invalid_request",e.message)}}let b=new Map;function R(e){if("service"!==e.kind)throw new w("principal_not_allowed","The granted service API accepts only service principals.");if(e.id===s.SESSION_CONTEXT_SERVICE_ID)return{principal:e,mode:"narrow",agents:b};let t=(0,_.loadServiceGrants)();if("invalid"===t.state)throw new w("grants_unavailable","The service grants are not available; the owner must fix the grants document.");return"absent"===t.state?{principal:e,mode:"narrow",agents:b}:{principal:e,mode:"granted",agents:t.grants.get(e.id)??b}}function I(e,n,i){return"string"==typeof n&&!!e.agents.get(n)?.has(i)&&!!t.bots.getById(n)}function k(e,n,i){let r=t.bots.getById(n);if(!r)throw v.agent();if(!I(e,n,i))throw E("agent");return r}let x=Object.freeze({default:20,max:100,messagesDefault:50,messagesMax:200});function A(e,t){return t.at-e.at||t.tie-e.tie||(e.id<t.id?-1:+(e.id>t.id))}function C(e,t){return Buffer.from(JSON.stringify({s:e,a:t.at,t:t.tie,i:t.id}),"utf8").toString("base64url")}function T(e,t){let n;if(null===t||""===t)return null;let i=new w("invalid_request","cursor is not a cursor of this list.");if(t.length>1024)throw i;try{n=JSON.parse(Buffer.from(t,"base64url").toString("utf8"))}catch{throw i}if(!n||n.s!==e||"number"!=typeof n.a||"number"!=typeof n.t||"string"!=typeof n.i)throw i;return{at:n.a,tie:n.t,id:n.i}}function q(e,t=x.default,n=x.max){if(null===e||""===e)return t;if(!/^\d+$/.test(e)||1>Number(e)||Number(e)>n)throw new w("invalid_request",`limit must be an integer from 1 to ${n}.`);return Number(e)}function N(e,t,n,i,r){let s=T(e,i),a=[...t].sort((e,t)=>A(n(e),n(t))),o=s?a.filter(e=>A(n(e),s)>0):a,d=o.slice(0,r),c=o.length>r?C(e,n(d[d.length-1])):null;return{items:d,next_cursor:c}}function O(e){let n=[...e.agents.entries()].filter(([e])=>!!t.bots.getById(e)).map(([e,t])=>({agent_id:e,capabilities:_.SERVICE_CAPABILITIES.filter(e=>t.has(e))})).sort((e,t)=>e.agent_id<t.agent_id?-1:+(e.agent_id>t.agent_id));return{principal:{kind:e.principal.kind,id:e.principal.id},mode:e.mode,vocabulary:_.SERVICE_CAPABILITIES,agents:n,limits:{page:x,content_chars:c.EXCHANGE_LIMITS.instructionChars,message_content_chars:B}}}function P(e,n){let i,r=(0,o.resolveAgent)(n),s=e.agents.get(n.id)??new Set;return{agent_id:n.id,name:n.name,title:n.title,runtime:r.agent,available:r.launchable,capabilities:_.SERVICE_CAPABILITIES.filter(e=>s.has(e)),messaging:{home_session_ref:n.home_session_id??null,new_sessions_allowed:(0,d.readStoredPolicy)(n)?.allow_new_sessions===!0,default_workspace_set:!!n.default_workspace},created_at:n.created_at,last_activity_at:(i=t.default.prepare(`
2
- SELECT MAX(m.created_at) AS at FROM messages m
3
- JOIN conversation_participants p ON p.conversation_id = m.conversation_id AND p.participant_kind = 'bot' AND p.participant_id = ?
4
- `).get(n.id),Math.max(n.created_at,i.at??0))}}function L(e,n){let i=[...e.agents.keys()].filter(t=>I(e,t,"agents:read")).map(n=>P(e,t.bots.getById(n)));return N(`agents:${e.principal.id}`,i,e=>({at:e.last_activity_at,tie:e.created_at,id:e.agent_id}),n.cursor,n.limit)}function K(e,t){return P(e,k(e,t,"agents:read"))}function M(e){let t=e.origin.conversation;return{ref:e.ref,agent:{...e.agent},title:e.title,status:e.status,resumable:e.resumable,source:e.source,state:{...e.state},created_at:e.created_at,ended_at:e.ended_at,last_activity_at:e.last_activity_at,origin:{conversation:t?{id:t.id,kind:t.kind,label:t.label}:null,work_request:e.origin.work_request},usage:{input_tokens:{...e.usage.input_tokens},output_tokens:{...e.usage.output_tokens},cost_usd:{...e.usage.cost_usd}},home:e.home,actions:e.actions}}async function $(e,n){k(e,n,"sessions:read"),await (0,h.warmAgentProvider)(t.default,n,{onlyWithSessions:!0})}function D(e,n,i){k(e,n,"sessions:read");let s=i.status??"all";if(!(0,l.isSessionFilter)(s))throw new w("invalid_request","status must be active, ended, or all.");let a=(0,g.serviceRedactor)(),o=(0,r.sessionsWithActions)(n,(0,l.listAgentSessions)(t.default,n,s)).map(e=>a.deep(M(e)));return N(`sessions:${n}:${s}`,o,e=>({at:e.last_activity_at,tie:e.created_at,id:e.ref}),i.cursor,i.limit)}function F(e,n,i){k(e,n,"sessions:read");let s=(0,l.getAgentSession)(t.default,n,i);if(!s)throw v.session();return(0,g.serviceRedactor)().deep({...M((0,r.sessionsWithActions)(n,[s])[0]),attempts:s.attempts,usage_samples:s.usage_samples.map(e=>({...e}))})}let B=16e3,G=`
5
- SELECT c.id, c.type, c.bot_id, c.group_id, c.origin_kind, c.origin_id, c.created_at,
6
- COALESCE((SELECT MAX(m.created_at) FROM messages m WHERE m.conversation_id = c.id), c.created_at) AS last_activity_at,
7
- (SELECT COUNT(*) FROM messages m WHERE m.conversation_id = c.id) AS message_count,
8
- b.name AS bot_name, g.name AS group_name
9
- FROM conversations c
10
- JOIN conversation_participants p ON p.conversation_id = c.id AND p.participant_kind = 'bot' AND p.participant_id = ?
11
- LEFT JOIN bots b ON b.id = c.bot_id
12
- LEFT JOIN groups g ON g.id = c.group_id
13
- `;function H(e){return t.default.prepare("SELECT participant_kind AS kind, participant_id AS id FROM conversation_participants WHERE conversation_id = ? ORDER BY joined_at ASC, rowid ASC").all(e)}function W(e,t){return t.every(t=>"bot"===t.kind?I(e,t.id,"conversations:read"):"service"!==t.kind||t.id===e.principal.id)}function j(e,t){let n="bot"===e.type?"direct":"group"===e.type?"group":"agent",i="direct"===n?`${e.bot_name??"Agent"} thread`:"group"===n?e.group_name?`Group ${e.group_name}`:"Group thread":"Agent API conversation";return{conversation_id:e.id,type:n,label:i,participants:t,message_count:e.message_count,created_at:e.created_at,last_activity_at:e.last_activity_at}}function X(e,n,i){k(e,n,"conversations:read");let r=t.default.prepare(G).all(n).flatMap(t=>{let n=H(t.id);return W(e,n)?[j(t,n)]:[]});return N(`conversations:${n}`,r,e=>({at:e.last_activity_at,tie:e.created_at,id:e.conversation_id}),i.cursor,i.limit)}function V(e,n,i,r){k(e,n,"conversations:read");let s=t.default.prepare(`${G} WHERE c.id = ?`).get(n,i);if(!s)throw v.conversation();let a=H(s.id);if(!W(e,a))throw E("conversation");let o=`messages:${s.id}`,d=T(o,r.cursor),c=t.default.prepare(`
14
- SELECT * FROM (
15
- SELECT m.id, m.sender_type, m.sender_id, m.sender_kind, m.request_id, m.content, m.created_at,
16
- ROW_NUMBER() OVER (ORDER BY m.rowid ASC) AS seq
17
- FROM messages m WHERE m.conversation_id = ?
18
- ) WHERE seq < ? ORDER BY seq DESC LIMIT ?
19
- `).all(s.id,d?d.at:Number.MAX_SAFE_INTEGER,r.limit+1),l=c.slice(0,r.limit).reverse(),u=(0,g.serviceRedactor)();return{...j(s,a),messages:l.map(e=>{var t,n;let i,r=u.text(e.content);return{message_id:e.id,seq:e.seq,sender:(t=e,n=s,i=t.sender_kind??("bot"===t.sender_type?"bot":"person"),t.sender_id?{kind:i,id:t.sender_id}:"bot"!==i&&n.origin_kind===i&&n.origin_id?{kind:i,id:n.origin_id}:{kind:i,id:"unknown"}),content:r.length>B?r.slice(0,B):r,truncated:r.length>B,request_id:e.request_id,created_at:e.created_at}}),next_cursor:c.length>r.limit&&l.length>0?C(o,{at:l[0].seq,tie:0,id:l[0].id}):null}}let J=["deck","deck_id","deckId","deck_name","runtime","agent","adapter","transport","model","tool_profile","toolProfile","execution_kind","executionKind","permissions","provider_session_id","external_session_id","externalSessionId","session_id","sessionId","resume","resume_session","fresh_session","external_run_id","run_id","cwd","working_directory","workspace","grant","grants","capability","capabilities","principal","requester","owner"];function U(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function Y(e,t,n){for(let i of Object.keys(e))if(!t.includes(i)){if(J.includes(i))throw new w("authority_not_allowed",`${n}${i} is chosen by Botmancers from the session and the Agent's configuration; a caller cannot set it.`);throw new w("invalid_request",`${n}${i} is not a field of this request.`)}}function z(e,t,n){if("string"!=typeof e||0===e.trim().length)throw new w("invalid_request",`${t} is required.`);if(e.length>n)throw new w("invalid_request",`${t} exceeds ${n} characters.`);return e}function Q(e,t){let n=e.idempotency_key;if(void 0!==n&&"string"!=typeof n)throw new w("invalid_request","idempotency_key must be a string.");if(null!==t&&void 0!==n&&t!==n)throw new w("invalid_request","Idempotency-Key header and body idempotency_key differ.");let i=n??t??"";if(0===i.trim().length||i.length>160)throw new w("invalid_request","An idempotency key (1-160 characters) is required.");return i}function Z(e,n){return t.default.prepare("SELECT * FROM session_exchanges WHERE requester_kind = ? AND requester_id = ? AND idempotency_key = ?").get(e.kind,e.id,n)}function ee(e,n,i){let r=(0,a.randomUUID)();t.default.prepare("INSERT INTO conversations (id, type, origin_kind, origin_id, created_at) VALUES (?, ?, ?, ?, ?)").run(r,"agent",e.kind,e.id,i);let s=t.default.prepare("INSERT OR IGNORE INTO conversation_participants (conversation_id, participant_kind, participant_id, joined_at) VALUES (?, ?, ?, ?)");return s.run(r,e.kind,e.id,i),s.run(r,"bot",n,i),r}function et(e){return t.default.prepare("SELECT * FROM session_bindings WHERE id = ?").get(e)}function en(e,n){try{return t.default.transaction(()=>{let{input:t,afterCreate:r}=e(),s=i.exchanges.create(t);return s.created&&r&&r(s.exchange),n?.(s.exchange),s}).immediate()}catch(e){if(e instanceof u.ExchangeError)throw S(e);throw e}}function ei(e,t){if(!U(e))throw new w("invalid_request","The body must be a JSON object.");Y(e,["content","idempotency_key"],"");let n=Q(e,t);return{content:z(e.content,"content",c.EXCHANGE_LIMITS.instructionChars),idempotencyKey:n}}function er(e,n,r,s){let o=et(n);if(!o){let i=t.default.prepare("SELECT agent_id FROM provider_sessions WHERE id = ? AND binding_id IS NULL").get(n);if(i&&I(e,i.agent_id,"sessions:message"))throw new w("session_not_resumable","This session is not reachable through session messages.");throw v.session()}if(!I(e,o.agent_id,"sessions:message"))throw E("session");let d=e.principal,c=`${_.MESSAGE_KEY_PREFIX}${r.idempotencyKey}`,{exchange:l,created:u}=en(()=>{let e=Date.now(),n=Z(d,c),i=t.default.prepare(`
20
- SELECT origin_conversation_id FROM session_exchanges
21
- WHERE requester_kind = ? AND requester_id = ? AND source_binding_id = ? AND mode = 'ask' AND idempotency_key LIKE 'message:%'
22
- ORDER BY created_at ASC, id ASC LIMIT 1
23
- `).get(d.kind,d.id,o.id),s=n?.origin_conversation_id??i?.origin_conversation_id??ee(d,o.agent_id,e);return{input:{requester:d,serviceGrant:!0,idempotencyKey:c,mode:"ask",originConversationId:s,sourceAgentId:o.agent_id,sessionRef:o.id,instruction:r.content,now:e},afterCreate:n=>{t.default.prepare("INSERT INTO messages (id, conversation_id, sender_type, sender_id, sender_kind, request_id, content, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run((0,a.randomUUID)(),n.origin_conversation_id,"user",d.id,d.kind,n.source_request_id,r.content,e)}}},s),g=(0,i.dispatchExchange)(l.id),p=l.source_request_id?t.default.prepare("SELECT state FROM work_requests WHERE id = ?").get(l.source_request_id):void 0,h=t.default.prepare("SELECT id FROM messages WHERE conversation_id = ? AND request_id = ? AND sender_kind = ? ORDER BY rowid ASC LIMIT 1").get(l.origin_conversation_id,l.source_request_id,d.kind);return{accepted:{session_ref:o.id,agent_id:o.agent_id,exchange_id:l.id,request_id:l.source_request_id,conversation_id:l.origin_conversation_id,message_id:h?.id??null,state:p?(0,i.apiStateOf)(p.state):"accepted",replayed:!u},dispatched:g}}function es(e,t,n){return t.requester_kind===e.principal.kind&&t.requester_id===e.principal.id&&I(e,t.source_agent_id,n)&&(null===t.destination_agent_id||I(e,t.destination_agent_id,n))}function ea(e,t,n){let r=i.exchanges.get(t);if(!r)throw v.exchange();if(!es(e,r,n))throw E("exchange");return r}let eo=e=>e.idempotency_key.startsWith(_.MESSAGE_KEY_PREFIX)?"session_message":"exchange";function ed(e,t){let n=t.idempotency_key.startsWith(_.MESSAGE_KEY_PREFIX)?t.idempotency_key.slice(_.MESSAGE_KEY_PREFIX.length):t.idempotency_key.startsWith(_.EXCHANGE_KEY_PREFIX)?t.idempotency_key.slice(_.EXCHANGE_KEY_PREFIX.length):t.idempotency_key;return(0,g.serviceRedactor)().deep({...e,kind:eo(t),idempotency_key:n})}function ec(e){return{id:e.id,kind:eo(e),mode:e.mode,state:e.state,source:{agent_id:e.source_agent_id,session_ref:e.source_binding_id},destination:e.destination_agent_id?{agent_id:e.destination_agent_id,session_ref:e.destination_binding_id}:null,failure:"failed"===e.state?{code:e.failure_code??"failed"}:null,created_at:e.created_at,updated_at:e.updated_at,terminal_at:e.terminal_at}}function el(e,t){let n=i.exchanges.require(t);return es(e,n,"exchanges:read")?ed((0,i.getExchangeView)(t),n):ec(n)}function eu(e,n){let i=t.default.prepare("SELECT * FROM session_exchanges WHERE requester_kind = ? AND requester_id = ?").all(e.principal.kind,e.principal.id).filter(t=>es(e,t,"exchanges:read")).map(ec);return N(`exchanges:${e.principal.id}`,i,e=>({at:e.updated_at,tie:e.created_at,id:e.id}),n.cursor,n.limit)}function e_(e,t){let n=ea(e,t,"exchanges:read");return ed((0,i.getExchangeView)(n.id),n)}let eg=["exchange_id","parent_exchange_id"];function ep(e,t){if(!U(e))throw new w("invalid_request","The body must be a JSON object.");if(eg.some(t=>t in e))throw new w("recursive_exchange","An exchange cannot be started from another exchange.");if(Y(e,["mode","idempotency_key","origin_conversation_id","source","destination","instruction"],""),"ask"!==e.mode&&"continue"!==e.mode)throw new w("invalid_request",'mode must be "ask" or "continue".');if(!U(e.source))throw new w("invalid_request","source must be one object { session_ref, agent_id? }.");Y(e.source,["session_ref","agent_id"],"source.");let n=null;if(void 0!==e.destination&&null!==e.destination){if(!U(e.destination))throw new w("destination_invalid","destination must be one object { agent_id, conversation_id? }.");Y(e.destination,["agent_id","conversation_id"],"destination."),n=e.destination}let i=(e,t)=>null==e?null:z(e,t,200);return{mode:e.mode,idempotencyKey:Q(e,t),originConversationId:i(e.origin_conversation_id,"origin_conversation_id"),sourceAgentId:i(e.source.agent_id,"source.agent_id"),sessionRef:z(e.source.session_ref,"source.session_ref",200),destinationAgentId:n?i(n.agent_id,"destination.agent_id"):null,destinationConversationId:n?i(n.conversation_id,"destination.conversation_id"):null,instruction:z(e.instruction,"instruction",c.EXCHANGE_LIMITS.instructionChars)}}function eh(e,n,r){let s=et(n.sessionRef);if(!s||null!==n.sourceAgentId&&n.sourceAgentId!==s.agent_id)throw v.session();if(!I(e,s.agent_id,"exchanges:create"))throw E("session");if("ask"===n.mode&&(null!==n.destinationAgentId||null!==n.destinationConversationId))throw new w("destination_invalid","An Ask returns to the origin conversation and takes no destination.");if("continue"===n.mode){if(null===n.destinationAgentId)throw new w("destination_invalid","A Continue names destination.agent_id.");if(!t.bots.getById(n.destinationAgentId))throw v.agent();if(!I(e,n.destinationAgentId,"exchanges:create"))throw E("agent")}let a=e.principal,o=`${_.EXCHANGE_KEY_PREFIX}${n.idempotencyKey}`,{exchange:d,created:c}=en(()=>{let e=Date.now(),t=Z(a,o),i=n.originConversationId??t?.origin_conversation_id??ee(a,s.agent_id,e),r="continue"!==n.mode?null:n.destinationConversationId??t?.destination_conversation_id??ee(a,n.destinationAgentId,e);return{input:{requester:a,serviceGrant:!0,idempotencyKey:o,mode:n.mode,originConversationId:i,sourceAgentId:s.agent_id,sessionRef:s.id,destinationAgentId:n.destinationAgentId,destinationConversationId:r,instruction:n.instruction,now:e}}},r),l=(0,i.dispatchExchange)(d.id);return{exchange:el(e,d.id),created:c,dispatched:l}}function ef(e){try{return(0,u.cancelReasonFromBody)(e)}catch(e){if(e instanceof u.ExchangeError)throw S(e);throw e}}async function em(e,t,n,r){let s=ea(e,t,"exchanges:create");try{let{replayed:t}=await (0,i.cancelExchangeCommand)(s.id,e.principal,n,r);return{exchange:el(e,s.id),replayed:t}}catch(e){if(e instanceof u.ExchangeError)throw S(e);throw e}}let ey=e=>"resume"===e?"sessions:resume":"sessions:message";function ew(e){if(e instanceof r.PinError){if("session_not_found"===e.code)throw v.session();if("agent_not_found"===e.code)throw v.agent();if("pin_not_found"===e.code)throw v.pin();if("conversation_not_found"===e.code)throw v.conversation();throw new w(e.code,e.message)}if(e instanceof u.ExchangeError)throw S(e);throw e}function ev(e,t){let n;try{n=(0,r.requirePin)(e.principal,t)}catch(e){ew(e)}if(!I(e,n.agent_id,ey(n.action)))throw E("pin");return n}function eE(e){return(0,g.serviceRedactor)().deep((0,r.pinView)(e))}function eS(e,t){return ei(e,t)}function eb(e,t){if(!U(e))throw new w("invalid_request","The body must be a JSON object.");if(Y(e,["action","approve_write","replace_pin_ref","idempotency_key"],""),"ask"!==e.action&&"resume"!==e.action)throw new w("invalid_request",'action must be "ask" or "resume".');if(void 0!==e.approve_write&&"boolean"!=typeof e.approve_write)throw new w("invalid_request","approve_write must be true or false.");return{action:e.action,approveWrite:!0===e.approve_write,replacePinRef:void 0===e.replace_pin_ref||null===e.replace_pin_ref?null:z(e.replace_pin_ref,"replace_pin_ref",200),idempotencyKey:Q(e,t)}}async function eR(e,t,n,i){k(e,t,"sessions:message");try{let s=await (0,r.messageAgent)({requester:e.principal,agentId:t,content:n.content,idempotencyKey:n.idempotencyKey,mayStart:I(e,t,"sessions:start"),onResolved:e=>i.onTarget({agentId:e.agentId,sessionRef:e.sessionRef,capability:"started"===e.resolution?"sessions:start":"sessions:message",action:"started"===e.resolution?"agents.message.start":"agents.message"}),onCommit:()=>i.onCommit()});return{body:{pin:eE(s.pin),turn:(0,g.serviceRedactor)().deep(s.turn),resolution:s.resolution,replayed:s.replayed},settled:s.settled}}catch(e){ew(e)}}async function eI(e,t,n,i){let s=(0,r.sessionOwner)(t);if(!s)throw v.session();let a=ey(n.action);if(i.onTarget({agentId:s,sessionRef:t,capability:a,action:"resume"===n.action?"pins.resume":"pins.ask"}),!I(e,s,a))throw E("session");n.replacePinRef&&ev(e,n.replacePinRef);try{let{pin:s,created:a,replaced:o}=await (0,r.createPin)({requester:e.principal,sessionRef:t,action:n.action,approveWrite:n.approveWrite,idempotencyKey:n.idempotencyKey,replacePinRef:n.replacePinRef,onCommit:()=>i.onCommit()});return{pin:eE(s),replaced_pin_ref:o?.id??null,replayed:!a}}catch(e){ew(e)}}async function ek(e,t,n,i){let s=ev(e,t);i.onTarget({agentId:s.agent_id,sessionRef:s.session_ref,capability:ey(s.action),action:"pins.send"});try{let t=await (0,r.sendPinTurn)({requester:e.principal,pinRef:s.id,content:n.content,idempotencyKey:n.idempotencyKey,onCommit:()=>i.onCommit()});return{body:{pin:eE(t.pin),turn:(0,g.serviceRedactor)().deep(t.turn),replayed:t.replayed},settled:t.settled}}catch(e){ew(e)}}async function ex(e,t,n){let i=ev(e,t);n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref,capability:ey(i.action),action:"pins.read"});try{let{pin:t,turns:n}=await (0,r.readPin)(e.principal,i.id);return{pin:eE(t),turns:(0,g.serviceRedactor)().deep(n)}}catch(e){ew(e)}}function eA(e,t,n){let i=ev(e,t);n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref,capability:ey(i.action),action:"pins.detach"});try{let{pin:t,replayed:s}=(0,r.detachPin)(e.principal,i.id,{onCommit:()=>n.onCommit()});return{pin:eE(t),replayed:s}}catch(e){ew(e)}}let eC=["provider_session_id","external_session_id","claude_session_id","codex_thread_id","cursor_chat_id","thread_id","chat_id","cwd","workspace","latest","most_recent","title","title_match","active_since"],eT=[...new Set([...J,...eC])];function eq(e,t,n){for(let i of Object.keys(e))if(!t.includes(i)){if(eT.includes(i))throw new w("authority_not_allowed",`${n}${i} cannot select or describe a session; name it by session_ref only.`);throw new w("invalid_request",`${n}${i} is not a field of this request.`)}}function eN(e,t){if(null==e)return null;if("number"!=typeof e||!Number.isInteger(e))throw new w("invalid_request",`${t} must be an integer.`);return e}function eO(e,t){if(!U(e))throw new w("invalid_request","The body must be a JSON object.");if(eq(e,["audience","ttl_seconds","max_turns","agent_id","idempotency_key"],""),!U(e.audience))throw new w("invalid_request",'audience must be one object { kind: "slack", team_id, channel_id }.');if(eq(e.audience,["kind","team_id","channel_id"],"audience."),!(0,f.isSlackAudience)(e.audience))throw new w("invalid_request",'audience must be { kind: "slack", team_id: "T…", channel_id: "C…" } with exact Slack ids.');return{audience:{kind:"slack",team_id:e.audience.team_id,channel_id:e.audience.channel_id},ttlSeconds:eN(e.ttl_seconds,"ttl_seconds"),maxTurns:eN(e.max_turns,"max_turns"),agentId:void 0===e.agent_id||null===e.agent_id?null:z(e.agent_id,"agent_id",200),idempotencyKey:Q(e,t)}}function eP(e){let t;if(""!==e.trim()){try{t=JSON.parse(e)}catch{throw new w("invalid_request","The body must be empty or a JSON object.")}if(!U(t))throw new w("invalid_request","The body must be empty or a JSON object.");eq(t,["idempotency_key"],""),void 0!==t.idempotency_key&&z(t.idempotency_key,"idempotency_key",160)}}let eL=["session_ref","state","cursor","limit"],eK=["active","expired","revoked"];function eM(e){for(let t of e)if(!eL.includes(t)){if(eT.includes(t))throw new w("authority_not_allowed",`${t} cannot select a session; filter by session_ref only.`);throw new w("invalid_request",`${t} is not a parameter of this list.`)}}function e$(e){if(e instanceof f.ShareError){if("session_not_found"===e.code)throw v.session();if("share_not_found"===e.code)throw v.share();throw new w(e.code,e.message)}ew(e)}function eD(e,t){let n=(0,f.shareRow)(t);if(!n)throw v.share();if(!(n.creator_kind===e.principal.kind&&n.creator_id===e.principal.id&&I(e,n.agent_id,"shares:create")))throw E("share");return n}function eF(e,t=(0,g.serviceRedactor)()){return t.deep((0,f.shareView)(e))}async function eB(e,t,n,i){let s=(0,r.sessionOwner)(t);if(i.onTarget({agentId:s,sessionRef:t}),!s)throw v.session();if(!I(e,s,"shares:create"))throw E("session");if(null!==n.agentId&&n.agentId!==s)throw v.session();try{let{share:r,created:s}=await (0,f.createShare)({creator:e.principal,sessionRef:t,agentId:n.agentId,audience:n.audience,ttlSeconds:n.ttlSeconds,maxTurns:n.maxTurns,idempotencyKey:n.idempotencyKey,createdVia:"session_ref",onCommit:()=>i.onCommit()});return{share:eF(r),replayed:!s}}catch(e){e$(e)}}function eG(e,t,n){let i=eD(e,t);return n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref}),{share:eF(i)}}function eH(e,t){if(null!==t.sessionRef&&(""===t.sessionRef.trim()||t.sessionRef.length>200))throw new w("invalid_request","session_ref must be one session reference.");if(null!==t.state&&!eK.includes(t.state))throw new w("invalid_request","state must be active, expired, or revoked.");let n=(0,g.serviceRedactor)(),i=(0,f.sharesCreatedBy)(e.principal,{sessionRef:t.sessionRef}).filter(t=>I(e,t.agent_id,"shares:create")).map(e=>eF(e,n)).filter(e=>null===t.state||e.state===t.state);return N(`shares:${e.principal.id}:${t.sessionRef??""}:${t.state??""}`,i,e=>({at:e.created_at,tie:e.created_at,id:e.share_ref}),t.cursor,t.limit)}function eW(e,t,n){let i=eD(e,t);n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref});try{let{share:e,replayed:t}=(0,f.revokeShare)(i.id,{onCommit:()=>n.onCommit()});return{share:eF(e),replayed:t}}catch(e){e$(e)}}let ej=["audience","ttl_seconds","max_turns","agent_id","idempotency_key"];function eX(e,t){if(U(e)&&Object.prototype.hasOwnProperty.call(e,"session_ref"))throw new w("invalid_request","Share-current takes no session_ref: its session is the one this launch is bound to. To share another session, use its session_ref with create-share.");return U(e)&&eq(e,ej,""),eO(e,t)}function eV(e){if(e.kind!==s.SESSION_CONTEXT_PRINCIPAL.kind||e.id!==s.SESSION_CONTEXT_PRINCIPAL.id)throw new w("invalid_request","Share-current is only available inside a Botmancers-launched session, authenticated by its session context, not a service token. Pass session_ref to create-share instead.")}function eJ(e){return new w("session_context_required","This caller has no exact session context; share a session explicitly by its session_ref (botmancers_list_sessions).",{reason:e.reason})}async function eU(e,t,n,i){if(i.onTarget({agentId:t.agentId,sessionRef:t.sessionRef}),null!==n.agentId&&n.agentId!==t.agentId)throw v.session();try{var r,s;let{share:o,created:d}=await (0,f.createShare)({creator:e.principal,sessionRef:t.sessionRef,agentId:t.agentId,audience:n.audience,ttlSeconds:n.ttlSeconds,maxTurns:n.maxTurns,idempotencyKey:(r=t.sessionRef,s=n.idempotencyKey,`current:${(0,a.createHash)("sha256").update(r).digest("hex").slice(0,24)}:${s}`),createdVia:"current_session",onCommit:()=>i.onCommit()});return{share:eF(o),replayed:!d}}catch(e){e$(e)}}e.s(["AUTHORITY_FIELDS",0,J,"MESSAGE_CONTENT_LIMIT",0,B,"PAGE_LIMITS",0,x,"SHARE_SELECTOR_FIELDS",0,eC,"ServiceApiError",0,w,"cancelServiceExchange",0,em,"capabilitiesView",0,O,"checkShareListParams",0,eM,"createCurrentSessionShare",0,eU,"createServiceExchange",0,eh,"createServiceShare",0,eB,"detachServicePin",0,eA,"getServiceAgent",0,K,"getServiceConversation",0,V,"getServiceExchange",0,e_,"getServiceSession",0,F,"getServiceShare",0,eG,"holds",0,I,"listServiceAgents",0,L,"listServiceConversations",0,X,"listServiceExchanges",0,eu,"listServiceSessions",0,D,"listServiceShares",0,eH,"messageServiceAgent",0,eR,"parseAgentMessageBody",0,eS,"parseCancelBody",0,ef,"parseLimit",0,q,"parsePinBody",0,eb,"parseServiceExchangeBody",0,ep,"parseSessionMessageBody",0,ei,"parseShareCreateBody",0,eO,"parseShareCurrentBody",0,eX,"parseShareRevokeBody",0,eP,"pinServiceSession",0,eI,"readServicePin",0,ex,"requireShareCurrentCaller",0,eV,"revokeServiceShare",0,eW,"sendServicePinMessage",0,ek,"sendServiceSessionMessage",0,er,"serviceContext",0,R,"sessionContextError",0,eJ,"warmServiceAgent",0,$],9501);let eY="BOTMANCERS_SERVICE_API_CALLS_PER_MINUTE",ez=new Map;async function eQ(e){let t=await eZ(e);try{return JSON.parse(t)}catch{throw new w("invalid_request","The body must be a JSON object.")}}async function eZ(e){let t=new w("payload_too_large","The request body is too large."),n=e.headers.get("content-length");if(null!==n&&!(/^\d+$/.test(n.trim())&&65536>=Number(n)))throw t;if(!e.body)return"";let i=e.body.getReader(),r=[],s=0;for(;;){let{done:e,value:n}=await i.read();if(e)break;if((s+=n.byteLength)>65536)throw await i.cancel().catch(()=>{}),t;r.push(n)}return Buffer.concat(r).toString("utf8")}function e0(e,t,n,i={}){return Response.json({error:{code:t,message:n}},{status:e,headers:i})}let e4=(e,t=200)=>({status:t,body:e});function e2(e,t,n,i={},r,s,a){return{status:e,body:{error:{code:t,message:n,...r?{fields:r}:{},...a?{reason:a}:{},...s?{recovery:s}:{}}},headers:i}}async function e1(e,n,i,r){let a,o,d={kind:n.targetKind,targetRef:n.targetRef??null,agentId:n.agentId??null},c=(i,r)=>t.serviceAudit.append({principal:e,operation:d.operation??n.operation,capability:d.capability??n.capability,targetKind:d.kind,targetRef:d.targetRef,agentId:d.agentId,outcome:i,code:r}),l=!1,u=null;try{if("service"!==e.kind)throw new w("principal_not_allowed","The granted service API accepts only service principals.");if(e.id===s.SESSION_CONTEXT_SERVICE_ID&&n.capability!==e9)throw new w("principal_not_allowed","A session context can only share its own session (share-current).");let t=function(e,t=Date.now()){let n=`${e.kind}:${e.id}`,i=(ez.get(n)??[]).filter(e=>e>t-6e4),r=function(){let e=process.env[eY];if(void 0===e||""===e.trim())return 120;let t=Number(e.trim());return Number.isInteger(t)&&t>0?t:(console.error(`${eY} must be a positive integer; using 120.`),120)}();return i.length>=r?(ez.set(n,i),Math.max(1,Math.ceil((i[i.length-r]+6e4-t)/1e3))):(i.push(t),ez.set(n,i),null)}(e);if(null!==t)u="rate_limited",o="denied",a=e2(429,"rate_limited","Too many calls; retry later.",{"Retry-After":String(t)});else{let t=R(e);r?.(t),a=await i(t,d,()=>{c("allowed",null),l=!0}),o="allowed"}}catch(e){e instanceof w?(o=e.denied?"denied":"rejected",u=e.notGranted?"not_granted":e.code,a=e2(e.status,e.code,e.message,{},e.fields,e.recovery,e.reason)):(console.error("Service API error:",e instanceof Error?e.message:"unknown error"),o="error",u="internal_error",a=e2(500,"internal_error","The request could not be processed."))}if(l&&"allowed"===o)return a;try{c(o,u)}catch(e){return console.error("Service audit append failed:",e instanceof Error?e.message:"unknown error"),e2(500,"internal_error","The request could not be processed.")}return a}let e9="shares:current";async function e3(e,t){let r;try{r=await (0,n.authenticate)(e)}catch(e){if(e instanceof i.AgentApiError)return e0(e.status,e.code,e.message);return console.error("Service API authentication error:",e instanceof Error?e.message:"unknown error"),e0(500,"internal_error","The request could not be processed.")}let s=await t(r);return Response.json(s.body,{status:s.status,headers:s.headers??{}})}function e6(e){let n=t.default.prepare("SELECT agent_id FROM session_bindings WHERE id = ?").get(e);return n?.agent_id??null}function e5(e,t){return{onTarget:t=>{e.kind=t.sessionRef?"session":"agent",e.targetRef=t.sessionRef??t.agentId,e.agentId=t.agentId,e.capability=t.capability,e.operation=t.action},onCommit:t}}function e8(e,t,n){return{onTarget:t=>{n&&(e.targetRef=t.sessionRef),e.agentId=t.agentId},onCommit:t}}function e7(e){if(e.length>200)return null;let n=t.default.prepare("SELECT source_agent_id FROM session_exchanges WHERE id = ?").get(e);return n?.source_agent_id??null}let te={capabilities:(e,t)=>e1(e,{operation:"capabilities.read",capability:"discovery",targetKind:"grants"},e=>e4(O(e)),t),listAgents:(e,t,n)=>e1(e,{operation:"agents.list",capability:"agents:read",targetKind:"agent"},e=>e4(L(e,{cursor:t.cursor,limit:q(t.limit)})),n),getAgent:(e,t,n)=>e1(e,{operation:"agents.read",capability:"agents:read",targetKind:"agent",targetRef:t,agentId:t},e=>e4(K(e,t)),n),listSessions:(e,t,n,i)=>e1(e,{operation:"sessions.list",capability:"sessions:read",targetKind:"agent",targetRef:t,agentId:t},async e=>(await $(e,t),e4(D(e,t,{cursor:n.cursor,limit:q(n.limit),status:n.status}))),i),getSession:(e,t,n,i)=>e1(e,{operation:"sessions.read",capability:"sessions:read",targetKind:"session",targetRef:n,agentId:t},async e=>(await $(e,t),e4(F(e,t,n))),i),listConversations:(e,t,n,i)=>e1(e,{operation:"conversations.list",capability:"conversations:read",targetKind:"agent",targetRef:t,agentId:t},e=>e4(X(e,t,{cursor:n.cursor,limit:q(n.limit)})),i),getConversation:(e,t,n,i,r)=>e1(e,{operation:"conversations.read",capability:"conversations:read",targetKind:"conversation",targetRef:n,agentId:t},e=>e4(V(e,t,n,{cursor:i.cursor,limit:q(i.limit,x.messagesDefault,x.messagesMax)})),r),sendSessionMessage:(e,t,n,i,r)=>e1(e,{operation:"sessions.message",capability:"sessions:message",targetKind:"session",targetRef:t},async(e,r,s)=>{t.length<=200&&(r.agentId=e6(t));let{accepted:a}=er(e,t,ei(await n(),i),e=>{r.agentId=e.source_agent_id,s()});return e4(a,a.replayed?200:202)},r),listExchanges:(e,t,n)=>e1(e,{operation:"exchanges.list",capability:"exchanges:read",targetKind:"exchange"},e=>e4(eu(e,{cursor:t.cursor,limit:q(t.limit)})),n),createExchange:(e,t,n,i)=>e1(e,{operation:"exchanges.create",capability:"exchanges:create",targetKind:"session"},async(e,i,r)=>{let s,a,o=await t();Object.assign(i,"string"!=typeof(a=(s=o&&"object"==typeof o?o.source:void 0)&&"object"==typeof s?s.session_ref:void 0)||0===a.length?{}:{targetRef:a,agentId:a.length<=200?e6(a):null});let{exchange:d,created:c}=eh(e,ep(o,n),e=>{i.kind="exchange",i.targetRef=e.id,i.agentId=e.source_agent_id,r()});return e4({exchange:d,replayed:!c},c?201:200)},i),getExchange:(e,t,n)=>e1(e,{operation:"exchanges.read",capability:"exchanges:read",targetKind:"exchange",targetRef:t},(e,n)=>{n.agentId=e7(t);let i=e_(e,t);return n.agentId=i.source.agent_id,e4(i)},n),cancelExchange:(e,t,n,i)=>e1(e,{operation:"exchanges.cancel",capability:"exchanges:create",targetKind:"exchange",targetRef:t},async(e,i,r)=>{i.agentId=e7(t);let s=await n();return e4(await em(e,t,s,e=>{i.agentId=e.source_agent_id,r()}))},i),messageAgent:(e,t,n,i,r)=>e1(e,{operation:"agents.message",capability:"sessions:message",targetKind:"agent",targetRef:t,agentId:t},async(e,r,s)=>{let a=eS(await n(),i),{body:o}=await eR(e,t,a,e5(r,s));return e4(o,o.replayed?200:202)},r),pinSession:(e,t,n,i,r)=>e1(e,{operation:"pins.create",capability:"sessions:message",targetKind:"session",targetRef:t},async(e,r,s)=>{let a=eb(await n(),i),o=await eI(e,t,a,e5(r,s));return e4(o,o.replayed?200:201)},r),readPin:(e,t,n)=>e1(e,{operation:"pins.read",capability:"sessions:message",targetKind:"session"},async(e,n)=>e4(await ex(e,t,e5(n,()=>{}))),n),sendToPin:(e,t,n,i,r)=>e1(e,{operation:"pins.send",capability:"sessions:message",targetKind:"session"},async(e,r,s)=>{let a=eS(await n(),i),{body:o}=await ek(e,t,a,e5(r,s));return e4(o,o.replayed?200:202)},r),detachPin:(e,t,n)=>e1(e,{operation:"pins.detach",capability:"sessions:message",targetKind:"session"},(e,n,i)=>e4(eA(e,t,e5(n,i))),n),createShare:(e,t,n,i,s)=>e1(e,{operation:"shares.create",capability:"shares:create",targetKind:"session",targetRef:t},async(e,s,a)=>{t.length<=200&&(s.agentId=(0,r.sessionOwner)(t));let o=eO(await n(),i),d=await eB(e,t,o,e8(s,a,!1));return e4(d,d.replayed?200:201)},s),getShare:(e,t,n)=>e1(e,{operation:"shares.read",capability:"shares:create",targetKind:"session",targetRef:t},(e,n)=>e4(eG(e,t,e8(n,()=>{},!1))),n),listShares:(e,t,n)=>e1(e,{operation:"shares.list",capability:"shares:create",targetKind:"session",targetRef:t.sessionRef},(e,n)=>(eM(t.names??[]),t.sessionRef&&t.sessionRef.length<=200&&(n.agentId=(0,r.sessionOwner)(t.sessionRef)),e4(eH(e,{cursor:t.cursor,limit:q(t.limit),sessionRef:t.sessionRef,state:t.state}))),n),revokeShare:(e,t,n,i)=>e1(e,{operation:"shares.revoke",capability:"shares:create",targetKind:"session",targetRef:t},async(e,i,r)=>(eP(await n()),e4(eW(e,t,e8(i,r,!1)))),i),shareCurrent:(e,t,n,i,r)=>e1(e,{operation:"shares.create",capability:e9,targetKind:"session"},async(e,r,a)=>{let o=eX(await n(),i);eV(e.principal);let d=(0,s.resolveSessionContext)(t);if(!d.ok)throw eJ(d);let c=await eU(e,d,o,e8(r,a,!0));return e4(c,c.replayed?200:201)},r)};function tt(e){let t=new URL(e.url).searchParams;return{cursor:t.get("cursor"),limit:t.get("limit"),get:e=>t.get(e),names:[...new Set(t.keys())]}}async function tn(e){let t=(0,s.sessionContextHeader)(e.headers),n=e.headers.get("idempotency-key"),i=i=>te.shareCurrent(i,t,()=>eQ(e),n);if(null===e.headers.get("authorization")){let e=await i(s.SESSION_CONTEXT_PRINCIPAL);return Response.json(e.body,{status:e.status,headers:e.headers??{}})}return e3(e,i)}e.s(["handleCancelExchange",0,function(e,t){return e3(e,n=>te.cancelExchange(n,t,async()=>ef(await eZ(e))))},"handleCreateExchange",0,function(e){return e3(e,t=>te.createExchange(t,()=>eQ(e),e.headers.get("idempotency-key")))},"handleCreateShare",0,function(e,t){return e3(e,n=>te.createShare(n,t,()=>eQ(e),e.headers.get("idempotency-key")))},"handleDetachPin",0,function(e,t){return e3(e,e=>te.detachPin(e,t))},"handleGetAgent",0,function(e,t){return e3(e,e=>te.getAgent(e,t))},"handleGetCapabilities",0,function(e){return e3(e,e=>te.capabilities(e))},"handleGetConversation",0,function(e,t,n){return e3(e,i=>te.getConversation(i,t,n,tt(e)))},"handleGetExchange",0,function(e,t){return e3(e,e=>te.getExchange(e,t))},"handleGetSession",0,function(e,t,n){return e3(e,e=>te.getSession(e,t,n))},"handleGetShare",0,function(e,t){return e3(e,e=>te.getShare(e,t))},"handleListAgents",0,function(e){return e3(e,t=>te.listAgents(t,tt(e)))},"handleListConversations",0,function(e,t){return e3(e,n=>te.listConversations(n,t,tt(e)))},"handleListExchanges",0,function(e){return e3(e,t=>te.listExchanges(t,tt(e)))},"handleListSessions",0,function(e,t){let n=tt(e);return e3(e,e=>te.listSessions(e,t,{cursor:n.cursor,limit:n.limit,status:n.get("status")}))},"handleListShares",0,function(e){let t=tt(e);return e3(e,e=>te.listShares(e,{cursor:t.cursor,limit:t.limit,sessionRef:t.get("session_ref"),state:t.get("state"),names:t.names}))},"handleMessageAgent",0,function(e,t){return e3(e,n=>te.messageAgent(n,t,()=>eQ(e),e.headers.get("idempotency-key")))},"handlePinSession",0,function(e,t){return e3(e,n=>te.pinSession(n,t,()=>eQ(e),e.headers.get("idempotency-key")))},"handleReadPin",0,function(e,t){return e3(e,e=>te.readPin(e,t))},"handleRevokeShare",0,function(e,t){return e3(e,n=>te.revokeShare(n,t,()=>eZ(e)))},"handleSendSessionMessage",0,function(e,t){return e3(e,n=>te.sendSessionMessage(n,t,()=>eQ(e),e.headers.get("idempotency-key")))},"handleSendToPin",0,function(e,t){return e3(e,n=>te.sendToPin(n,t,()=>eQ(e),e.headers.get("idempotency-key")))},"handleShareCurrent",0,tn,"serviceOperations",0,te],69936)}];
1
+ module.exports=[69936,e=>{"use strict";var t=e.i(62294),r=e.i(43345),n=e.i(45383),a=e.i(674),s=e.i(81449),i=e.i(9501);let o="BOTMANCERS_SERVICE_API_CALLS_PER_MINUTE",c=new Map;async function l(e){let t=await g(e);try{return JSON.parse(t)}catch{throw new i.ServiceApiError("invalid_request","The body must be a JSON object.")}}async function g(e){let t=new i.ServiceApiError("payload_too_large","The request body is too large."),r=e.headers.get("content-length");if(null!==r&&!(/^\d+$/.test(r.trim())&&65536>=Number(r)))throw t;if(!e.body)return"";let n=e.body.getReader(),a=[],s=0;for(;;){let{done:e,value:r}=await n.read();if(e)break;if((s+=r.byteLength)>65536)throw await n.cancel().catch(()=>{}),t;a.push(r)}return Buffer.concat(a).toString("utf8")}function d(e,t,r,n={}){return Response.json({error:{code:t,message:r}},{status:e,headers:n})}let u=(e,t=200)=>({status:t,body:e});function h(e,t,r,n={},a,s,i){return{status:e,body:{error:{code:t,message:r,...a?{fields:a}:{},...i?{reason:i}:{},...s?{recovery:s}:{}}},headers:n}}async function p(e,r,n,a){let l,g,d={kind:r.targetKind,targetRef:r.targetRef??null,agentId:r.agentId??null},u=(n,a)=>t.serviceAudit.append({principal:e,operation:d.operation??r.operation,capability:d.capability??r.capability,targetKind:d.kind,targetRef:d.targetRef,agentId:d.agentId,outcome:n,code:a}),p=!1,f=null;try{if("service"!==e.kind)throw new i.ServiceApiError("principal_not_allowed","The granted service API accepts only service principals.");if(e.id===s.SESSION_CONTEXT_SERVICE_ID&&r.capability!==y)throw new i.ServiceApiError("principal_not_allowed","A session context can only share its own session (share-current).");let t=function(e,t=Date.now()){let r=`${e.kind}:${e.id}`,n=(c.get(r)??[]).filter(e=>e>t-6e4),a=function(){let e=process.env[o];if(void 0===e||""===e.trim())return 120;let t=Number(e.trim());return Number.isInteger(t)&&t>0?t:(console.error(`${o} must be a positive integer; using 120.`),120)}();return n.length>=a?(c.set(r,n),Math.max(1,Math.ceil((n[n.length-a]+6e4-t)/1e3))):(n.push(t),c.set(r,n),null)}(e);if(null!==t)f="rate_limited",g="denied",l=h(429,"rate_limited","Too many calls; retry later.",{"Retry-After":String(t)});else{let t=(0,i.serviceContext)(e);a?.(t),l=await n(t,d,()=>{u("allowed",null),p=!0}),g="allowed"}}catch(e){e instanceof i.ServiceApiError?(g=e.denied?"denied":"rejected",f=e.notGranted?"not_granted":e.code,l=h(e.status,e.code,e.message,{},e.fields,e.recovery,e.reason)):(console.error("Service API error:",e instanceof Error?e.message:"unknown error"),g="error",f="internal_error",l=h(500,"internal_error","The request could not be processed."))}if(p&&"allowed"===g)return l;try{u(g,f)}catch(e){return console.error("Service audit append failed:",e instanceof Error?e.message:"unknown error"),h(500,"internal_error","The request could not be processed.")}return l}let y="shares:current";async function f(e,t){let a;try{a=await (0,r.authenticate)(e)}catch(e){if(e instanceof n.AgentApiError)return d(e.status,e.code,e.message);return console.error("Service API authentication error:",e instanceof Error?e.message:"unknown error"),d(500,"internal_error","The request could not be processed.")}let s=await t(a);return Response.json(s.body,{status:s.status,headers:s.headers??{}})}function S(e){let r=t.default.prepare("SELECT agent_id FROM session_bindings WHERE id = ?").get(e);return r?.agent_id??null}function m(e,t){return{onTarget:t=>{e.kind=t.sessionRef?"session":"agent",e.targetRef=t.sessionRef??t.agentId,e.agentId=t.agentId,e.capability=t.capability,e.operation=t.action},onCommit:t}}function v(e,t,r){return{onTarget:t=>{r&&(e.targetRef=t.sessionRef),e.agentId=t.agentId},onCommit:t}}function b(e){if(e.length>200)return null;let r=t.default.prepare("SELECT source_agent_id FROM session_exchanges WHERE id = ?").get(e);return r?.source_agent_id??null}let w={capabilities:(e,t)=>p(e,{operation:"capabilities.read",capability:"discovery",targetKind:"grants"},e=>u((0,i.capabilitiesView)(e)),t),listAgents:(e,t,r)=>p(e,{operation:"agents.list",capability:"agents:read",targetKind:"agent"},e=>u((0,i.listServiceAgents)(e,{cursor:t.cursor,limit:(0,i.parseLimit)(t.limit)})),r),getAgent:(e,t,r)=>p(e,{operation:"agents.read",capability:"agents:read",targetKind:"agent",targetRef:t,agentId:t},e=>u((0,i.getServiceAgent)(e,t)),r),listSessions:(e,t,r,n)=>p(e,{operation:"sessions.list",capability:"sessions:read",targetKind:"agent",targetRef:t,agentId:t},async e=>(await (0,i.warmServiceAgent)(e,t),u((0,i.listServiceSessions)(e,t,{cursor:r.cursor,limit:(0,i.parseLimit)(r.limit),status:r.status}))),n),getSession:(e,t,r,n)=>p(e,{operation:"sessions.read",capability:"sessions:read",targetKind:"session",targetRef:r,agentId:t},async e=>(await (0,i.warmServiceAgent)(e,t),u((0,i.getServiceSession)(e,t,r))),n),listConversations:(e,t,r,n)=>p(e,{operation:"conversations.list",capability:"conversations:read",targetKind:"agent",targetRef:t,agentId:t},e=>u((0,i.listServiceConversations)(e,t,{cursor:r.cursor,limit:(0,i.parseLimit)(r.limit)})),n),getConversation:(e,t,r,n,a)=>p(e,{operation:"conversations.read",capability:"conversations:read",targetKind:"conversation",targetRef:r,agentId:t},e=>u((0,i.getServiceConversation)(e,t,r,{cursor:n.cursor,limit:(0,i.parseLimit)(n.limit,i.PAGE_LIMITS.messagesDefault,i.PAGE_LIMITS.messagesMax)})),a),sendSessionMessage:(e,t,r,n,a)=>p(e,{operation:"sessions.message",capability:"sessions:message",targetKind:"session",targetRef:t},async(e,a,s)=>{t.length<=200&&(a.agentId=S(t));let o=(0,i.parseSessionMessageBody)(await r(),n),{accepted:c}=(0,i.sendServiceSessionMessage)(e,t,o,e=>{a.agentId=e.source_agent_id,s()});return u(c,c.replayed?200:202)},a),listExchanges:(e,t,r)=>p(e,{operation:"exchanges.list",capability:"exchanges:read",targetKind:"exchange"},e=>u((0,i.listServiceExchanges)(e,{cursor:t.cursor,limit:(0,i.parseLimit)(t.limit)})),r),createExchange:(e,t,r,n)=>p(e,{operation:"exchanges.create",capability:"exchanges:create",targetKind:"session"},async(e,n,a)=>{let s,o,c=await t();Object.assign(n,"string"!=typeof(o=(s=c&&"object"==typeof c?c.source:void 0)&&"object"==typeof s?s.session_ref:void 0)||0===o.length?{}:{targetRef:o,agentId:o.length<=200?S(o):null});let l=(0,i.parseServiceExchangeBody)(c,r),{exchange:g,created:d}=(0,i.createServiceExchange)(e,l,e=>{n.kind="exchange",n.targetRef=e.id,n.agentId=e.source_agent_id,a()});return u({exchange:g,replayed:!d},d?201:200)},n),getExchange:(e,t,r)=>p(e,{operation:"exchanges.read",capability:"exchanges:read",targetKind:"exchange",targetRef:t},(e,r)=>{r.agentId=b(t);let n=(0,i.getServiceExchange)(e,t);return r.agentId=n.source.agent_id,u(n)},r),cancelExchange:(e,t,r,n)=>p(e,{operation:"exchanges.cancel",capability:"exchanges:create",targetKind:"exchange",targetRef:t},async(e,n,a)=>{n.agentId=b(t);let s=await r();return u(await (0,i.cancelServiceExchange)(e,t,s,e=>{n.agentId=e.source_agent_id,a()}))},n),messageAgent:(e,t,r,n,a)=>p(e,{operation:"agents.message",capability:"sessions:message",targetKind:"agent",targetRef:t,agentId:t},async(e,a,s)=>{let o=(0,i.parseAgentMessageBody)(await r(),n),{body:c}=await (0,i.messageServiceAgent)(e,t,o,m(a,s));return u(c,c.replayed?200:202)},a),pinSession:(e,t,r,n,a)=>p(e,{operation:"pins.create",capability:"sessions:message",targetKind:"session",targetRef:t},async(e,a,s)=>{let o=(0,i.parsePinBody)(await r(),n),c=await (0,i.pinServiceSession)(e,t,o,m(a,s));return u(c,c.replayed?200:201)},a),readPin:(e,t,r)=>p(e,{operation:"pins.read",capability:"sessions:message",targetKind:"session"},async(e,r)=>u(await (0,i.readServicePin)(e,t,m(r,()=>{}))),r),sendToPin:(e,t,r,n,a)=>p(e,{operation:"pins.send",capability:"sessions:message",targetKind:"session"},async(e,a,s)=>{let o=(0,i.parseAgentMessageBody)(await r(),n),{body:c}=await (0,i.sendServicePinMessage)(e,t,o,m(a,s));return u(c,c.replayed?200:202)},a),detachPin:(e,t,r)=>p(e,{operation:"pins.detach",capability:"sessions:message",targetKind:"session"},(e,r,n)=>u((0,i.detachServicePin)(e,t,m(r,n))),r),createShare:(e,t,r,n,s)=>p(e,{operation:"shares.create",capability:"shares:create",targetKind:"session",targetRef:t},async(e,s,o)=>{t.length<=200&&(s.agentId=(0,a.sessionOwner)(t));let c=(0,i.parseShareCreateBody)(await r(),n),l=await (0,i.createServiceShare)(e,t,c,v(s,o,!1));return u(l,l.replayed?200:201)},s),getShare:(e,t,r)=>p(e,{operation:"shares.read",capability:"shares:create",targetKind:"session",targetRef:t},(e,r)=>u((0,i.getServiceShare)(e,t,v(r,()=>{},!1))),r),listShares:(e,t,r)=>p(e,{operation:"shares.list",capability:"shares:create",targetKind:"session",targetRef:t.sessionRef},(e,r)=>((0,i.checkShareListParams)(t.names??[]),t.sessionRef&&t.sessionRef.length<=200&&(r.agentId=(0,a.sessionOwner)(t.sessionRef)),u((0,i.listServiceShares)(e,{cursor:t.cursor,limit:(0,i.parseLimit)(t.limit),sessionRef:t.sessionRef,state:t.state}))),r),revokeShare:(e,t,r,n)=>p(e,{operation:"shares.revoke",capability:"shares:create",targetKind:"session",targetRef:t},async(e,n,a)=>((0,i.parseShareRevokeBody)(await r()),u((0,i.revokeServiceShare)(e,t,v(n,a,!1)))),n),shareCurrent:(e,t,r,n,a)=>p(e,{operation:"shares.create",capability:y,targetKind:"session"},async(e,a,o)=>{let c=(0,i.parseShareCurrentBody)(await r(),n);(0,i.requireShareCurrentCaller)(e.principal);let l=(0,s.resolveSessionContext)(t);if(!l.ok)throw(0,i.sessionContextError)(l);let g=await (0,i.createCurrentSessionShare)(e,l,c,v(a,o,!0));return u(g,g.replayed?200:201)},a)};function R(e){let t=new URL(e.url).searchParams;return{cursor:t.get("cursor"),limit:t.get("limit"),get:e=>t.get(e),names:[...new Set(t.keys())]}}async function E(e){let t=(0,s.sessionContextHeader)(e.headers),r=e.headers.get("idempotency-key"),n=n=>w.shareCurrent(n,t,()=>l(e),r);if(null===e.headers.get("authorization")){let e=await n(s.SESSION_CONTEXT_PRINCIPAL);return Response.json(e.body,{status:e.status,headers:e.headers??{}})}return f(e,n)}e.s(["handleCancelExchange",0,function(e,t){return f(e,r=>w.cancelExchange(r,t,async()=>(0,i.parseCancelBody)(await g(e))))},"handleCreateExchange",0,function(e){return f(e,t=>w.createExchange(t,()=>l(e),e.headers.get("idempotency-key")))},"handleCreateShare",0,function(e,t){return f(e,r=>w.createShare(r,t,()=>l(e),e.headers.get("idempotency-key")))},"handleDetachPin",0,function(e,t){return f(e,e=>w.detachPin(e,t))},"handleGetAgent",0,function(e,t){return f(e,e=>w.getAgent(e,t))},"handleGetCapabilities",0,function(e){return f(e,e=>w.capabilities(e))},"handleGetConversation",0,function(e,t,r){return f(e,n=>w.getConversation(n,t,r,R(e)))},"handleGetExchange",0,function(e,t){return f(e,e=>w.getExchange(e,t))},"handleGetSession",0,function(e,t,r){return f(e,e=>w.getSession(e,t,r))},"handleGetShare",0,function(e,t){return f(e,e=>w.getShare(e,t))},"handleListAgents",0,function(e){return f(e,t=>w.listAgents(t,R(e)))},"handleListConversations",0,function(e,t){return f(e,r=>w.listConversations(r,t,R(e)))},"handleListExchanges",0,function(e){return f(e,t=>w.listExchanges(t,R(e)))},"handleListSessions",0,function(e,t){let r=R(e);return f(e,e=>w.listSessions(e,t,{cursor:r.cursor,limit:r.limit,status:r.get("status")}))},"handleListShares",0,function(e){let t=R(e);return f(e,e=>w.listShares(e,{cursor:t.cursor,limit:t.limit,sessionRef:t.get("session_ref"),state:t.get("state"),names:t.names}))},"handleMessageAgent",0,function(e,t){return f(e,r=>w.messageAgent(r,t,()=>l(e),e.headers.get("idempotency-key")))},"handlePinSession",0,function(e,t){return f(e,r=>w.pinSession(r,t,()=>l(e),e.headers.get("idempotency-key")))},"handleReadPin",0,function(e,t){return f(e,e=>w.readPin(e,t))},"handleRevokeShare",0,function(e,t){return f(e,r=>w.revokeShare(r,t,()=>g(e)))},"handleSendSessionMessage",0,function(e,t){return f(e,r=>w.sendSessionMessage(r,t,()=>l(e),e.headers.get("idempotency-key")))},"handleSendToPin",0,function(e,t){return f(e,r=>w.sendToPin(r,t,()=>l(e),e.headers.get("idempotency-key")))},"handleShareCurrent",0,E,"serviceOperations",0,w])}];
24
2
 
25
3
  //# sourceMappingURL=lib_service-api-http_ts_0xzqhny._.js.map
@@ -0,0 +1,25 @@
1
+ module.exports=[9501,e=>{"use strict";var t=e.i(54799),n=e.i(46309),i=e.i(62294),r=e.i(62349),s=e.i(18966),a=e.i(35613),o=e.i(90027),d=e.i(63020),c=e.i(45383),_=e.i(91253),u=e.i(93399),l=e.i(50081),p=e.i(16789),g=e.i(81449),f=e.i(35034),h=e.i(674);let m={invalid_request:400,unsupported_field:400,authority_not_allowed:403,principal_not_allowed:403,grant_required:403,grants_unavailable:503,agent_not_found:404,session_not_found:404,conversation_not_found:404,exchange_not_found:404,session_ended:409,session_not_resumable:409,source_session_busy:409,agent_unavailable:409,destination_invalid:400,recursive_exchange:403,idempotency_conflict:409,exchange_terminal:409,conflict:409,payload_too_large:413,rate_limited:429,internal_error:500,pin_not_found:404,pin_detached:409,workspace_required:409,no_eligible_session:409,session_missing:410,action_unavailable:409,approval_required:403,provider_failed:502,share_not_found:404,share_expired:410,share_revoked:410,share_turn_in_progress:409,share_turn_limit:409,audience_not_allowed:403,session_context_required:409},v=["principal_not_allowed","grant_required","grants_unavailable","agent_not_found","session_not_found","conversation_not_found","exchange_not_found","rate_limited","pin_not_found","share_not_found","audience_not_allowed"];class w extends Error{code;notGranted;fields;recovery;reason;constructor(e,t,n={}){super(t),this.name="ServiceApiError",this.code=e,this.notGranted=!0===n.notGranted,this.fields=n.fields,this.recovery=(0,l.recoveryFor)(e),this.reason=n.reason??null}get status(){return m[this.code]}get denied(){return v.includes(this.code)}}let y={pin:()=>new w("pin_not_found","No pin with that reference is visible to this principal."),share:()=>new w("share_not_found","No share with that reference is visible to this principal."),agent:()=>new w("agent_not_found","No Agent with that id is visible to this principal."),session:()=>new w("session_not_found","No session with that reference is visible to this principal."),conversation:()=>new w("conversation_not_found","No conversation with that id is visible to this principal."),exchange:()=>new w("exchange_not_found","No exchange with that id is visible to this principal.")};function E(e){let t=y[e]();return new w(t.code,t.message,{notGranted:!0})}function S(e){switch(e.code){case"exchange_not_found":return y.exchange();case"session_not_found":return y.session();case"agent_not_found":return y.agent();case"conversation_not_found":return y.conversation();case"invalid_transition":return new w("conflict","The exchange changed concurrently; read it and retry.");default:return e.code in m?new w(e.code,e.message):new w("invalid_request",e.message)}}let b=new Map;function I(e,t,n){return"string"==typeof t&&!!e.agents.get(t)?.has(n)&&!!i.bots.getById(t)}function k(e,t,n){let r=i.bots.getById(t);if(!r)throw y.agent();if(!I(e,t,n))throw E("agent");return r}let R=Object.freeze({default:20,max:100,messagesDefault:50,messagesMax:200});function A(e,t,i,r,s){try{return(0,n.paginateRows)(e,t,i,r,s)}catch(e){if(e instanceof n.InvalidPageCursorError)throw new w("invalid_request",e.message);throw e}}function x(e){return{home_session_ref:e.home_session_id??null,new_sessions_allowed:(0,s.readStoredPolicy)(e)?.allow_new_sessions===!0,default_workspace_set:!!e.default_workspace}}function C(e,t){let n,s=(0,r.resolveAgent)(t),a=e.agents.get(t.id)??new Set;return{agent_id:t.id,name:t.name,title:t.title,runtime:s.agent,available:s.launchable,capabilities:_.SERVICE_CAPABILITIES.filter(e=>a.has(e)),messaging:x(t),created_at:t.created_at,last_activity_at:(n=i.default.prepare(`
2
+ SELECT MAX(m.created_at) AS at FROM messages m
3
+ JOIN conversation_participants p ON p.conversation_id = m.conversation_id AND p.participant_kind = 'bot' AND p.participant_id = ?
4
+ `).get(t.id),Math.max(t.created_at,n.at??0))}}function q(e){let t=e.origin.conversation;return{ref:e.ref,agent:{...e.agent},title:e.title,status:e.status,resumable:e.resumable,source:e.source,state:{...e.state},created_at:e.created_at,ended_at:e.ended_at,last_activity_at:e.last_activity_at,origin:{conversation:t?{id:t.id,kind:t.kind,label:t.label}:null,work_request:e.origin.work_request?{id:e.origin.work_request.id,execution_kind:e.origin.work_request.execution_kind,state:e.origin.work_request.state}:null},usage:{input_tokens:{...e.usage.input_tokens},output_tokens:{...e.usage.output_tokens},cost_usd:{...e.usage.cost_usd}},home:e.home,actions:e.actions}}async function T(e,t){k(e,t,"sessions:read"),await (0,p.warmAgentProvider)(i.default,t,{onlyWithSessions:!0})}let N=`
5
+ SELECT c.id, c.type, c.bot_id, c.group_id, c.origin_kind, c.origin_id, c.created_at,
6
+ COALESCE((SELECT MAX(m.created_at) FROM messages m WHERE m.conversation_id = c.id), c.created_at) AS last_activity_at,
7
+ (SELECT COUNT(*) FROM messages m WHERE m.conversation_id = c.id) AS message_count,
8
+ b.name AS bot_name, g.name AS group_name
9
+ FROM conversations c
10
+ JOIN conversation_participants p ON p.conversation_id = c.id AND p.participant_kind = 'bot' AND p.participant_id = ?
11
+ LEFT JOIN bots b ON b.id = c.bot_id
12
+ LEFT JOIN groups g ON g.id = c.group_id
13
+ `;function O(e){return i.default.prepare("SELECT participant_kind AS kind, participant_id AS id FROM conversation_participants WHERE conversation_id = ? ORDER BY joined_at ASC, rowid ASC").all(e)}function P(e,t){return t.every(t=>"bot"===t.kind?I(e,t.id,"conversations:read"):"service"!==t.kind||t.id===e.principal.id)}function L(e,t){let n="bot"===e.type?"direct":"group"===e.type?"group":"agent",i="direct"===n?`${e.bot_name??"Agent"} thread`:"group"===n?e.group_name?`Group ${e.group_name}`:"Group thread":"Agent API conversation";return{conversation_id:e.id,type:n,label:i,participants:t,message_count:e.message_count,created_at:e.created_at,last_activity_at:e.last_activity_at}}let M=["deck","deck_id","deckId","deck_name","runtime","agent","adapter","transport","model","tool_profile","toolProfile","execution_kind","executionKind","permissions","provider_session_id","external_session_id","externalSessionId","session_id","sessionId","resume","resume_session","fresh_session","external_run_id","run_id","cwd","working_directory","workspace","grant","grants","capability","capabilities","principal","requester","owner"];function $(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function F(e,t,n){for(let i of Object.keys(e))if(!t.includes(i)){if(M.includes(i))throw new w("authority_not_allowed",`${n}${i} is chosen by Botmancers from the session and the Agent's configuration; a caller cannot set it.`);throw new w("invalid_request",`${n}${i} is not a field of this request.`)}}function D(e,t,n){if("string"!=typeof e||0===e.trim().length)throw new w("invalid_request",`${t} is required.`);if(e.length>n)throw new w("invalid_request",`${t} exceeds ${n} characters.`);return e}function K(e,t){let n=e.idempotency_key;if(void 0!==n&&"string"!=typeof n)throw new w("invalid_request","idempotency_key must be a string.");if(null!==t&&void 0!==n&&t!==n)throw new w("invalid_request","Idempotency-Key header and body idempotency_key differ.");let i=n??t??"";if(0===i.trim().length||i.length>160)throw new w("invalid_request","An idempotency key (1-160 characters) is required.");return i}function B(e,t){return i.default.prepare("SELECT * FROM session_exchanges WHERE requester_kind = ? AND requester_id = ? AND idempotency_key = ?").get(e.kind,e.id,t)}function G(e,n,r){let s=(0,t.randomUUID)();i.default.prepare("INSERT INTO conversations (id, type, origin_kind, origin_id, created_at) VALUES (?, ?, ?, ?, ?)").run(s,"agent",e.kind,e.id,r);let a=i.default.prepare("INSERT OR IGNORE INTO conversation_participants (conversation_id, participant_kind, participant_id, joined_at) VALUES (?, ?, ?, ?)");return a.run(s,e.kind,e.id,r),a.run(s,"bot",n,r),s}function W(e){return i.default.prepare("SELECT * FROM session_bindings WHERE id = ?").get(e)}function H(e,t){try{return i.default.transaction(()=>{let{input:n,afterCreate:i}=e(),r=c.exchanges.create(n);return r.created&&i&&i(r.exchange),t?.(r.exchange),r}).immediate()}catch(e){if(e instanceof d.ExchangeError)throw S(e);throw e}}function X(e,t){if(!$(e))throw new w("invalid_request","The body must be a JSON object.");F(e,["content","idempotency_key"],"");let n=K(e,t);return{content:D(e.content,"content",a.EXCHANGE_LIMITS.instructionChars),idempotencyKey:n}}function j(e,t,n){return t.requester_kind===e.principal.kind&&t.requester_id===e.principal.id&&I(e,t.source_agent_id,n)&&(null===t.destination_agent_id||I(e,t.destination_agent_id,n))}function V(e,t,n){let i=c.exchanges.get(t);if(!i)throw y.exchange();if(!j(e,i,n))throw E("exchange");return i}let Y=e=>e.idempotency_key.startsWith(_.MESSAGE_KEY_PREFIX)?"session_message":"exchange";function J(e,t){let n=t.idempotency_key.startsWith(_.MESSAGE_KEY_PREFIX)?t.idempotency_key.slice(_.MESSAGE_KEY_PREFIX.length):t.idempotency_key.startsWith(_.EXCHANGE_KEY_PREFIX)?t.idempotency_key.slice(_.EXCHANGE_KEY_PREFIX.length):t.idempotency_key;return(0,u.serviceRedactor)().deep({...e,kind:Y(t),idempotency_key:n})}function U(e){return{id:e.id,kind:Y(e),mode:e.mode,state:e.state,source:{agent_id:e.source_agent_id,session_ref:e.source_binding_id},destination:e.destination_agent_id?{agent_id:e.destination_agent_id,session_ref:e.destination_binding_id}:null,failure:"failed"===e.state?{code:e.failure_code??"failed"}:null,created_at:e.created_at,updated_at:e.updated_at,terminal_at:e.terminal_at}}function z(e,t){let n=c.exchanges.require(t);return j(e,n,"exchanges:read")?J((0,c.getExchangeView)(t),n):U(n)}let Q=["exchange_id","parent_exchange_id"];async function Z(e,t,n,i){let r=V(e,t,"exchanges:create");try{let{replayed:t}=await (0,c.cancelExchangeCommand)(r.id,e.principal,n,i);return{exchange:z(e,r.id),replayed:t}}catch(e){if(e instanceof d.ExchangeError)throw S(e);throw e}}let ee=e=>"resume"===e?"sessions:resume":"sessions:message";function et(e){if(e instanceof h.PinError){if("session_not_found"===e.code)throw y.session();if("agent_not_found"===e.code)throw y.agent();if("pin_not_found"===e.code)throw y.pin();if("conversation_not_found"===e.code)throw y.conversation();throw new w(e.code,e.message)}if(e instanceof d.ExchangeError)throw S(e);throw e}function en(e,t){let n;try{n=(0,h.requirePin)(e.principal,t)}catch(e){et(e)}if(!I(e,n.agent_id,ee(n.action)))throw E("pin");return n}function ei(e){return(0,u.serviceRedactor)().deep((0,h.pinView)(e))}async function er(e,t,n,i){k(e,t,"sessions:message");try{let r=await (0,h.messageAgent)({requester:e.principal,agentId:t,content:n.content,idempotencyKey:n.idempotencyKey,mayStart:I(e,t,"sessions:start"),onResolved:e=>i.onTarget({agentId:e.agentId,sessionRef:e.sessionRef,capability:"started"===e.resolution?"sessions:start":"sessions:message",action:"started"===e.resolution?"agents.message.start":"agents.message"}),onCommit:()=>i.onCommit()});return{body:{pin:ei(r.pin),turn:(0,u.serviceRedactor)().deep(r.turn),resolution:r.resolution,replayed:r.replayed},settled:r.settled}}catch(e){et(e)}}async function es(e,t,n,i){let r=(0,h.sessionOwner)(t);if(!r)throw y.session();let s=ee(n.action);if(i.onTarget({agentId:r,sessionRef:t,capability:s,action:"resume"===n.action?"pins.resume":"pins.ask"}),!I(e,r,s))throw E("session");n.replacePinRef&&en(e,n.replacePinRef);try{let{pin:r,created:s,replaced:a}=await (0,h.createPin)({requester:e.principal,sessionRef:t,action:n.action,approveWrite:n.approveWrite,idempotencyKey:n.idempotencyKey,replacePinRef:n.replacePinRef,onCommit:()=>i.onCommit()});return{pin:ei(r),replaced_pin_ref:a?.id??null,replayed:!s}}catch(e){et(e)}}async function ea(e,t,n,i){let r=en(e,t);i.onTarget({agentId:r.agent_id,sessionRef:r.session_ref,capability:ee(r.action),action:"pins.send"});try{let t=await (0,h.sendPinTurn)({requester:e.principal,pinRef:r.id,content:n.content,idempotencyKey:n.idempotencyKey,onCommit:()=>i.onCommit()});return{body:{pin:ei(t.pin),turn:(0,u.serviceRedactor)().deep(t.turn),replayed:t.replayed},settled:t.settled}}catch(e){et(e)}}async function eo(e,t,n){let i=en(e,t);n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref,capability:ee(i.action),action:"pins.read"});try{let{pin:t,turns:n}=await (0,h.readPin)(e.principal,i.id);return{pin:ei(t),turns:(0,u.serviceRedactor)().deep(n)}}catch(e){et(e)}}let ed=["provider_session_id","external_session_id","claude_session_id","codex_thread_id","cursor_chat_id","thread_id","chat_id","cwd","workspace","latest","most_recent","title","title_match","active_since"],ec=[...new Set([...M,...ed])];function e_(e,t,n){for(let i of Object.keys(e))if(!t.includes(i)){if(ec.includes(i))throw new w("authority_not_allowed",`${n}${i} cannot select or describe a session; name it by session_ref only.`);throw new w("invalid_request",`${n}${i} is not a field of this request.`)}}function eu(e,t){if(null==e)return null;if("number"!=typeof e||!Number.isInteger(e))throw new w("invalid_request",`${t} must be an integer.`);return e}function el(e,t){if(!$(e))throw new w("invalid_request","The body must be a JSON object.");if(e_(e,["audience","ttl_seconds","max_turns","agent_id","idempotency_key"],""),!$(e.audience))throw new w("invalid_request",'audience must be one object { kind: "slack", team_id, channel_id }.');if(e_(e.audience,["kind","team_id","channel_id"],"audience."),!(0,f.isSlackAudience)(e.audience))throw new w("invalid_request",'audience must be { kind: "slack", team_id: "T…", channel_id: "C…" } with exact Slack ids.');return{audience:{kind:"slack",team_id:e.audience.team_id,channel_id:e.audience.channel_id},ttlSeconds:eu(e.ttl_seconds,"ttl_seconds"),maxTurns:eu(e.max_turns,"max_turns"),agentId:void 0===e.agent_id||null===e.agent_id?null:D(e.agent_id,"agent_id",200),idempotencyKey:K(e,t)}}let ep=["session_ref","state","cursor","limit"],eg=["active","expired","revoked"];function ef(e){if(e instanceof f.ShareError){if("session_not_found"===e.code)throw y.session();if("share_not_found"===e.code)throw y.share();throw new w(e.code,e.message)}et(e)}function eh(e,t){let n=(0,f.shareRow)(t);if(!n)throw y.share();if(!(n.creator_kind===e.principal.kind&&n.creator_id===e.principal.id&&I(e,n.agent_id,"shares:create")))throw E("share");return n}function em(e,t=(0,u.serviceRedactor)()){return t.deep((0,f.shareView)(e))}async function ev(e,t,n,i){let r=(0,h.sessionOwner)(t);if(i.onTarget({agentId:r,sessionRef:t}),!r)throw y.session();if(!I(e,r,"shares:create"))throw E("session");if(null!==n.agentId&&n.agentId!==r)throw y.session();try{let{share:r,created:s}=await (0,f.createShare)({creator:e.principal,sessionRef:t,agentId:n.agentId,audience:n.audience,ttlSeconds:n.ttlSeconds,maxTurns:n.maxTurns,idempotencyKey:n.idempotencyKey,createdVia:"session_ref",onCommit:()=>i.onCommit()});return{share:em(r),replayed:!s}}catch(e){ef(e)}}let ew=["audience","ttl_seconds","max_turns","agent_id","idempotency_key"];async function ey(e,n,i,r){if(r.onTarget({agentId:n.agentId,sessionRef:n.sessionRef}),null!==i.agentId&&i.agentId!==n.agentId)throw y.session();try{var s,a;let{share:o,created:d}=await (0,f.createShare)({creator:e.principal,sessionRef:n.sessionRef,agentId:n.agentId,audience:i.audience,ttlSeconds:i.ttlSeconds,maxTurns:i.maxTurns,idempotencyKey:(s=n.sessionRef,a=i.idempotencyKey,`current:${(0,t.createHash)("sha256").update(s).digest("hex").slice(0,24)}:${a}`),createdVia:"current_session",onCommit:()=>r.onCommit()});return{share:em(o),replayed:!d}}catch(e){ef(e)}}e.s(["AUTHORITY_FIELDS",0,M,"MESSAGE_CONTENT_LIMIT",0,16e3,"PAGE_LIMITS",0,R,"SHARE_SELECTOR_FIELDS",0,ed,"ServiceApiError",0,w,"agentMessagingReadiness",0,x,"cancelServiceExchange",0,Z,"capabilitiesView",0,function(e){let t=[...e.agents.entries()].filter(([e])=>!!i.bots.getById(e)).map(([e,t])=>({agent_id:e,capabilities:_.SERVICE_CAPABILITIES.filter(e=>t.has(e))})).sort((e,t)=>e.agent_id<t.agent_id?-1:+(e.agent_id>t.agent_id));return{principal:{kind:e.principal.kind,id:e.principal.id},mode:e.mode,vocabulary:_.SERVICE_CAPABILITIES,agents:t,limits:{page:R,content_chars:a.EXCHANGE_LIMITS.instructionChars,message_content_chars:16e3}}},"checkShareListParams",0,function(e){for(let t of e)if(!ep.includes(t)){if(ec.includes(t))throw new w("authority_not_allowed",`${t} cannot select a session; filter by session_ref only.`);throw new w("invalid_request",`${t} is not a parameter of this list.`)}},"createCurrentSessionShare",0,ey,"createServiceExchange",0,function(e,t,n){let r=W(t.sessionRef);if(!r||null!==t.sourceAgentId&&t.sourceAgentId!==r.agent_id)throw y.session();if(!I(e,r.agent_id,"exchanges:create"))throw E("session");if("ask"===t.mode&&(null!==t.destinationAgentId||null!==t.destinationConversationId))throw new w("destination_invalid","An Ask returns to the origin conversation and takes no destination.");if("continue"===t.mode){if(null===t.destinationAgentId)throw new w("destination_invalid","A Continue names destination.agent_id.");if(!i.bots.getById(t.destinationAgentId))throw y.agent();if(!I(e,t.destinationAgentId,"exchanges:create"))throw E("agent")}let s=e.principal,a=`${_.EXCHANGE_KEY_PREFIX}${t.idempotencyKey}`,{exchange:o,created:d}=H(()=>{let e=Date.now(),n=B(s,a),i=t.originConversationId??n?.origin_conversation_id??G(s,r.agent_id,e),o="continue"!==t.mode?null:t.destinationConversationId??n?.destination_conversation_id??G(s,t.destinationAgentId,e);return{input:{requester:s,serviceGrant:!0,idempotencyKey:a,mode:t.mode,originConversationId:i,sourceAgentId:r.agent_id,sessionRef:r.id,destinationAgentId:t.destinationAgentId,destinationConversationId:o,instruction:t.instruction,now:e}}},n),u=(0,c.dispatchExchange)(o.id);return{exchange:z(e,o.id),created:d,dispatched:u}},"createServiceShare",0,ev,"detachServicePin",0,function(e,t,n){let i=en(e,t);n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref,capability:ee(i.action),action:"pins.detach"});try{let{pin:t,replayed:r}=(0,h.detachPin)(e.principal,i.id,{onCommit:()=>n.onCommit()});return{pin:ei(t),replayed:r}}catch(e){et(e)}},"getServiceAgent",0,function(e,t){return C(e,k(e,t,"agents:read"))},"getServiceConversation",0,function(e,t,r,s){var a;k(e,t,"conversations:read");let o=i.default.prepare(`${N} WHERE c.id = ?`).get(t,r);if(!o)throw y.conversation();let d=O(o.id);if(!P(e,d))throw E("conversation");let c=`messages:${o.id}`,_=function(e,t){try{return(0,n.decodePageCursor)(e,t)}catch(e){if(e instanceof n.InvalidPageCursorError)throw new w("invalid_request",e.message);throw e}}(c,s.cursor),l=i.default.prepare(`
14
+ SELECT * FROM (
15
+ SELECT m.id, m.sender_type, m.sender_id, m.sender_kind, m.request_id, m.content, m.created_at,
16
+ ROW_NUMBER() OVER (ORDER BY m.rowid ASC) AS seq
17
+ FROM messages m WHERE m.conversation_id = ?
18
+ ) WHERE seq < ? ORDER BY seq DESC LIMIT ?
19
+ `).all(o.id,_?_.at:Number.MAX_SAFE_INTEGER,s.limit+1),p=l.slice(0,s.limit).reverse(),g=(0,u.serviceRedactor)();return{...L(o,d),messages:p.map(e=>{var t,n;let i,r=g.text(e.content);return{message_id:e.id,seq:e.seq,sender:(t=e,n=o,i=t.sender_kind??("bot"===t.sender_type?"bot":"person"),t.sender_id?{kind:i,id:t.sender_id}:"bot"!==i&&n.origin_kind===i&&n.origin_id?{kind:i,id:n.origin_id}:{kind:i,id:"unknown"}),content:r.length>16e3?r.slice(0,16e3):r,truncated:r.length>16e3,request_id:e.request_id,created_at:e.created_at}}),next_cursor:l.length>s.limit&&p.length>0?(a={at:p[0].seq,tie:0,id:p[0].id},(0,n.encodePageCursor)(c,a)):null}},"getServiceExchange",0,function(e,t){let n=V(e,t,"exchanges:read");return J((0,c.getExchangeView)(n.id),n)},"getServiceSession",0,function(e,t,n){k(e,t,"sessions:read");let r=(0,o.getAgentSession)(i.default,t,n);if(!r)throw y.session();return(0,u.serviceRedactor)().deep({...q((0,h.sessionsWithActions)(t,[r])[0]),attempts:r.attempts,usage_samples:r.usage_samples.map(e=>({...e}))})},"getServiceShare",0,function(e,t,n){let i=eh(e,t);return n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref}),{share:em(i)}},"holds",0,I,"listServiceAgents",0,function(e,t){let n=[...e.agents.keys()].filter(t=>I(e,t,"agents:read")).map(t=>C(e,i.bots.getById(t)));return A(`agents:${e.principal.id}`,n,e=>({at:e.last_activity_at,tie:e.created_at,id:e.agent_id}),t.cursor,t.limit)},"listServiceConversations",0,function(e,t,n){k(e,t,"conversations:read");let r=i.default.prepare(N).all(t).flatMap(t=>{let n=O(t.id);return P(e,n)?[L(t,n)]:[]});return A(`conversations:${t}`,r,e=>({at:e.last_activity_at,tie:e.created_at,id:e.conversation_id}),n.cursor,n.limit)},"listServiceExchanges",0,function(e,t){let n=i.default.prepare("SELECT * FROM session_exchanges WHERE requester_kind = ? AND requester_id = ?").all(e.principal.kind,e.principal.id).filter(t=>j(e,t,"exchanges:read")).map(U);return A(`exchanges:${e.principal.id}`,n,e=>({at:e.updated_at,tie:e.created_at,id:e.id}),t.cursor,t.limit)},"listServiceSessions",0,function(e,t,n){k(e,t,"sessions:read");let r=n.status??"all";if(!(0,o.isSessionFilter)(r))throw new w("invalid_request","status must be active, ended, or all.");let s=(0,u.serviceRedactor)(),a=(0,h.sessionsWithActions)(t,(0,o.listAgentSessions)(i.default,t,r)).map(e=>s.deep(q(e)));return A(`sessions:${t}:${r}`,a,e=>({at:e.last_activity_at,tie:e.created_at,id:e.ref}),n.cursor,n.limit)},"listServiceShares",0,function(e,t){if(null!==t.sessionRef&&(""===t.sessionRef.trim()||t.sessionRef.length>200))throw new w("invalid_request","session_ref must be one session reference.");if(null!==t.state&&!eg.includes(t.state))throw new w("invalid_request","state must be active, expired, or revoked.");let n=(0,u.serviceRedactor)(),i=(0,f.sharesCreatedBy)(e.principal,{sessionRef:t.sessionRef}).filter(t=>I(e,t.agent_id,"shares:create")).map(e=>em(e,n)).filter(e=>null===t.state||e.state===t.state);return A(`shares:${e.principal.id}:${t.sessionRef??""}:${t.state??""}`,i,e=>({at:e.created_at,tie:e.created_at,id:e.share_ref}),t.cursor,t.limit)},"messageServiceAgent",0,er,"parseAgentMessageBody",0,function(e,t){return X(e,t)},"parseCancelBody",0,function(e){try{return(0,d.cancelReasonFromBody)(e)}catch(e){if(e instanceof d.ExchangeError)throw S(e);throw e}},"parseLimit",0,function(e,t=R.default,n=R.max){if(null===e||""===e)return t;if(!/^\d+$/.test(e)||1>Number(e)||Number(e)>n)throw new w("invalid_request",`limit must be an integer from 1 to ${n}.`);return Number(e)},"parsePinBody",0,function(e,t){if(!$(e))throw new w("invalid_request","The body must be a JSON object.");if(F(e,["action","approve_write","replace_pin_ref","idempotency_key"],""),"ask"!==e.action&&"resume"!==e.action)throw new w("invalid_request",'action must be "ask" or "resume".');if(void 0!==e.approve_write&&"boolean"!=typeof e.approve_write)throw new w("invalid_request","approve_write must be true or false.");return{action:e.action,approveWrite:!0===e.approve_write,replacePinRef:void 0===e.replace_pin_ref||null===e.replace_pin_ref?null:D(e.replace_pin_ref,"replace_pin_ref",200),idempotencyKey:K(e,t)}},"parseServiceExchangeBody",0,function(e,t){if(!$(e))throw new w("invalid_request","The body must be a JSON object.");if(Q.some(t=>t in e))throw new w("recursive_exchange","An exchange cannot be started from another exchange.");if(F(e,["mode","idempotency_key","origin_conversation_id","source","destination","instruction"],""),"ask"!==e.mode&&"continue"!==e.mode)throw new w("invalid_request",'mode must be "ask" or "continue".');if(!$(e.source))throw new w("invalid_request","source must be one object { session_ref, agent_id? }.");F(e.source,["session_ref","agent_id"],"source.");let n=null;if(void 0!==e.destination&&null!==e.destination){if(!$(e.destination))throw new w("destination_invalid","destination must be one object { agent_id, conversation_id? }.");F(e.destination,["agent_id","conversation_id"],"destination."),n=e.destination}let i=(e,t)=>null==e?null:D(e,t,200);return{mode:e.mode,idempotencyKey:K(e,t),originConversationId:i(e.origin_conversation_id,"origin_conversation_id"),sourceAgentId:i(e.source.agent_id,"source.agent_id"),sessionRef:D(e.source.session_ref,"source.session_ref",200),destinationAgentId:n?i(n.agent_id,"destination.agent_id"):null,destinationConversationId:n?i(n.conversation_id,"destination.conversation_id"):null,instruction:D(e.instruction,"instruction",a.EXCHANGE_LIMITS.instructionChars)}},"parseSessionMessageBody",0,X,"parseShareCreateBody",0,el,"parseShareCurrentBody",0,function(e,t){if($(e)&&Object.prototype.hasOwnProperty.call(e,"session_ref"))throw new w("invalid_request","Share-current takes no session_ref: its session is the one this launch is bound to. To share another session, use its session_ref with create-share.");return $(e)&&e_(e,ew,""),el(e,t)},"parseShareRevokeBody",0,function(e){let t;if(""!==e.trim()){try{t=JSON.parse(e)}catch{throw new w("invalid_request","The body must be empty or a JSON object.")}if(!$(t))throw new w("invalid_request","The body must be empty or a JSON object.");e_(t,["idempotency_key"],""),void 0!==t.idempotency_key&&D(t.idempotency_key,"idempotency_key",160)}},"pinServiceSession",0,es,"readServicePin",0,eo,"requireShareCurrentCaller",0,function(e){if(e.kind!==g.SESSION_CONTEXT_PRINCIPAL.kind||e.id!==g.SESSION_CONTEXT_PRINCIPAL.id)throw new w("invalid_request","Share-current is only available inside a Botmancers-launched session, authenticated by its session context, not a service token. Pass session_ref to create-share instead.")},"revokeServiceShare",0,function(e,t,n){let i=eh(e,t);n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref});try{let{share:e,replayed:t}=(0,f.revokeShare)(i.id,{onCommit:()=>n.onCommit()});return{share:em(e),replayed:t}}catch(e){ef(e)}},"sendServicePinMessage",0,ea,"sendServiceSessionMessage",0,function(e,n,r,s){let a=W(n);if(!a){let t=i.default.prepare("SELECT agent_id FROM provider_sessions WHERE id = ? AND binding_id IS NULL").get(n);if(t&&I(e,t.agent_id,"sessions:message"))throw new w("session_not_resumable","This session is not reachable through session messages.");throw y.session()}if(!I(e,a.agent_id,"sessions:message"))throw E("session");let o=e.principal,d=`${_.MESSAGE_KEY_PREFIX}${r.idempotencyKey}`,{exchange:u,created:l}=H(()=>{let e=Date.now(),n=B(o,d),s=i.default.prepare(`
20
+ SELECT origin_conversation_id FROM session_exchanges
21
+ WHERE requester_kind = ? AND requester_id = ? AND source_binding_id = ? AND mode = 'ask' AND idempotency_key LIKE 'message:%'
22
+ ORDER BY created_at ASC, id ASC LIMIT 1
23
+ `).get(o.kind,o.id,a.id),c=n?.origin_conversation_id??s?.origin_conversation_id??G(o,a.agent_id,e);return{input:{requester:o,serviceGrant:!0,idempotencyKey:d,mode:"ask",originConversationId:c,sourceAgentId:a.agent_id,sessionRef:a.id,instruction:r.content,now:e},afterCreate:n=>{i.default.prepare("INSERT INTO messages (id, conversation_id, sender_type, sender_id, sender_kind, request_id, content, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)").run((0,t.randomUUID)(),n.origin_conversation_id,"user",o.id,o.kind,n.source_request_id,r.content,e)}}},s),p=(0,c.dispatchExchange)(u.id),g=u.source_request_id?i.default.prepare("SELECT state FROM work_requests WHERE id = ?").get(u.source_request_id):void 0,f=i.default.prepare("SELECT id FROM messages WHERE conversation_id = ? AND request_id = ? AND sender_kind = ? ORDER BY rowid ASC LIMIT 1").get(u.origin_conversation_id,u.source_request_id,o.kind);return{accepted:{session_ref:a.id,agent_id:a.agent_id,exchange_id:u.id,request_id:u.source_request_id,conversation_id:u.origin_conversation_id,message_id:f?.id??null,state:g?(0,c.apiStateOf)(g.state):"accepted",replayed:!l},dispatched:p}},"serviceContext",0,function(e){if("service"!==e.kind)throw new w("principal_not_allowed","The granted service API accepts only service principals.");if(e.id===g.SESSION_CONTEXT_SERVICE_ID)return{principal:e,mode:"narrow",agents:b};let t=(0,_.loadServiceGrants)();if("invalid"===t.state)throw new w("grants_unavailable","The service grants are not available; the owner must fix the grants document.");return"absent"===t.state?{principal:e,mode:"narrow",agents:b}:{principal:e,mode:"granted",agents:t.grants.get(e.id)??b}},"sessionContextError",0,function(e){return new w("session_context_required","This caller has no exact session context; share a session explicitly by its session_ref (botmancers_list_sessions).",{reason:e.reason})},"warmServiceAgent",0,T])}];
24
+
25
+ //# sourceMappingURL=lib_service-api_ts_18eok4w._.js.map