botmancers 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (358) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +5 -5
  3. package/app/.next/BUILD_ID +1 -1
  4. package/app/.next/app-path-routes-manifest.json +11 -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 +82 -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 +2 -2
  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.js +2 -2
  101. package/app/.next/server/app/api/bots/[id]/sessions/sync/route.js.nft.json +1 -1
  102. package/app/.next/server/app/api/bots/[id]/share-policy/route.js +2 -2
  103. package/app/.next/server/app/api/bots/[id]/share-policy/route.js.nft.json +1 -1
  104. package/app/.next/server/app/api/bots/[id]/skill/route.js +1 -1
  105. package/app/.next/server/app/api/bots/[id]/skill/route.js.nft.json +1 -1
  106. package/app/.next/server/app/api/bots/availability/route.js.nft.json +1 -1
  107. package/app/.next/server/app/api/bots/delete-preview/route.js +1 -1
  108. package/app/.next/server/app/api/bots/delete-preview/route.js.nft.json +1 -1
  109. package/app/.next/server/app/api/bots/import/route.js +1 -1
  110. package/app/.next/server/app/api/bots/import/route.js.nft.json +1 -1
  111. package/app/.next/server/app/api/bots/manage/route.js +1 -1
  112. package/app/.next/server/app/api/bots/manage/route.js.nft.json +1 -1
  113. package/app/.next/server/app/api/bots/name-migrations/route.js +1 -1
  114. package/app/.next/server/app/api/bots/name-migrations/route.js.nft.json +1 -1
  115. package/app/.next/server/app/api/bots/route.js +5 -5
  116. package/app/.next/server/app/api/bots/route.js.nft.json +1 -1
  117. package/app/.next/server/app/api/conversations/[id]/approve/route.js.nft.json +1 -1
  118. package/app/.next/server/app/api/conversations/[id]/deny/route.js.nft.json +1 -1
  119. package/app/.next/server/app/api/conversations/[id]/draft/route.js +1 -1
  120. package/app/.next/server/app/api/conversations/[id]/draft/route.js.nft.json +1 -1
  121. package/app/.next/server/app/api/conversations/[id]/messages/[messageId]/stop/route.js.nft.json +1 -1
  122. package/app/.next/server/app/api/conversations/[id]/messages/route.js +5 -5
  123. package/app/.next/server/app/api/conversations/[id]/messages/route.js.nft.json +1 -1
  124. package/app/.next/server/app/api/conversations/[id]/route.js +1 -1
  125. package/app/.next/server/app/api/conversations/[id]/route.js.nft.json +1 -1
  126. package/app/.next/server/app/api/conversations/[id]/stop/route.js +6 -6
  127. package/app/.next/server/app/api/conversations/[id]/stop/route.js.nft.json +1 -1
  128. package/app/.next/server/app/api/conversations/route.js +1 -1
  129. package/app/.next/server/app/api/conversations/route.js.nft.json +1 -1
  130. package/app/.next/server/app/api/exchanges/[id]/cancel/route.js +2 -2
  131. package/app/.next/server/app/api/exchanges/[id]/cancel/route.js.nft.json +1 -1
  132. package/app/.next/server/app/api/exchanges/[id]/route.js +1 -1
  133. package/app/.next/server/app/api/exchanges/[id]/route.js.nft.json +1 -1
  134. package/app/.next/server/app/api/exchanges/route.js +1 -1
  135. package/app/.next/server/app/api/exchanges/route.js.nft.json +1 -1
  136. package/app/.next/server/app/api/files/[name]/route.js +1 -1
  137. package/app/.next/server/app/api/files/[name]/route.js.nft.json +1 -1
  138. package/app/.next/server/app/api/groups/route.js +1 -1
  139. package/app/.next/server/app/api/groups/route.js.nft.json +1 -1
  140. package/app/.next/server/app/api/health/route.js +3 -3
  141. package/app/.next/server/app/api/health/route.js.nft.json +1 -1
  142. package/app/.next/server/app/api/import-capabilities/route.js.nft.json +1 -1
  143. package/app/.next/server/app/api/marketplace-handoff/route.js.nft.json +1 -1
  144. package/app/.next/server/app/api/marketplace-handoff/status/route.js.nft.json +1 -1
  145. package/app/.next/server/app/api/mcp/route.js +1 -1
  146. package/app/.next/server/app/api/mcp/route.js.nft.json +1 -1
  147. package/app/.next/server/app/api/messages/[id]/between/route.js +1 -1
  148. package/app/.next/server/app/api/messages/[id]/between/route.js.nft.json +1 -1
  149. package/app/.next/server/app/api/runtime-connections/route.js +1 -1
  150. package/app/.next/server/app/api/runtime-connections/route.js.nft.json +1 -1
  151. package/app/.next/server/app/api/service-grants/route.js.nft.json +1 -1
  152. package/app/.next/server/app/api/shares/[shareRef]/revoke/route.js +2 -2
  153. package/app/.next/server/app/api/shares/[shareRef]/revoke/route.js.nft.json +1 -1
  154. package/app/.next/server/app/api/shares/route.js +2 -2
  155. package/app/.next/server/app/api/shares/route.js.nft.json +1 -1
  156. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route.js +4 -3
  157. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/[conversationId]/route.js.nft.json +1 -1
  158. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route.js +4 -3
  159. package/app/.next/server/app/api/v0/agents/[agentId]/conversations/route.js.nft.json +1 -1
  160. package/app/.next/server/app/api/v0/agents/[agentId]/messages/route.js +1 -1
  161. package/app/.next/server/app/api/v0/agents/[agentId]/messages/route.js.nft.json +1 -1
  162. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route.js +4 -3
  163. package/app/.next/server/app/api/v0/agents/[agentId]/pins/route.js.nft.json +1 -1
  164. package/app/.next/server/app/api/v0/agents/[agentId]/route.js +4 -3
  165. package/app/.next/server/app/api/v0/agents/[agentId]/route.js.nft.json +1 -1
  166. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route.js +4 -3
  167. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/[ref]/route.js.nft.json +1 -1
  168. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route.js +4 -3
  169. package/app/.next/server/app/api/v0/agents/[agentId]/sessions/route.js.nft.json +1 -1
  170. package/app/.next/server/app/api/v0/agents/route.js +4 -3
  171. package/app/.next/server/app/api/v0/agents/route.js.nft.json +1 -1
  172. package/app/.next/server/app/api/v0/capabilities/route.js +4 -3
  173. package/app/.next/server/app/api/v0/capabilities/route.js.nft.json +1 -1
  174. package/app/.next/server/app/api/v0/conversations/[id]/route.js +1 -1
  175. package/app/.next/server/app/api/v0/conversations/[id]/route.js.nft.json +1 -1
  176. package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route.js +4 -3
  177. package/app/.next/server/app/api/v0/exchanges/[id]/cancel/route.js.nft.json +1 -1
  178. package/app/.next/server/app/api/v0/exchanges/[id]/route.js +4 -3
  179. package/app/.next/server/app/api/v0/exchanges/[id]/route.js.nft.json +1 -1
  180. package/app/.next/server/app/api/v0/exchanges/route.js +4 -3
  181. package/app/.next/server/app/api/v0/exchanges/route.js.nft.json +1 -1
  182. package/app/.next/server/app/api/v0/mcp/route.js +6 -5
  183. package/app/.next/server/app/api/v0/mcp/route.js.nft.json +1 -1
  184. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route.js +4 -3
  185. package/app/.next/server/app/api/v0/pins/[pinRef]/detach/route.js.nft.json +1 -1
  186. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route.js +4 -3
  187. package/app/.next/server/app/api/v0/pins/[pinRef]/messages/route.js.nft.json +1 -1
  188. package/app/.next/server/app/api/v0/pins/[pinRef]/route.js +4 -3
  189. package/app/.next/server/app/api/v0/pins/[pinRef]/route.js.nft.json +1 -1
  190. package/app/.next/server/app/api/v0/requests/[id]/route.js +1 -1
  191. package/app/.next/server/app/api/v0/requests/[id]/route.js.nft.json +1 -1
  192. package/app/.next/server/app/api/v0/sessions/[ref]/messages/route.js +4 -3
  193. package/app/.next/server/app/api/v0/sessions/[ref]/messages/route.js.nft.json +1 -1
  194. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route.js +4 -3
  195. package/app/.next/server/app/api/v0/sessions/[ref]/pins/route.js.nft.json +1 -1
  196. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route.js +4 -3
  197. package/app/.next/server/app/api/v0/sessions/[ref]/shares/route.js.nft.json +1 -1
  198. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route.js +4 -3
  199. package/app/.next/server/app/api/v0/shares/[shareRef]/revoke/route.js.nft.json +1 -1
  200. package/app/.next/server/app/api/v0/shares/[shareRef]/route.js +4 -3
  201. package/app/.next/server/app/api/v0/shares/[shareRef]/route.js.nft.json +1 -1
  202. package/app/.next/server/app/api/v0/shares/current/route.js +4 -3
  203. package/app/.next/server/app/api/v0/shares/current/route.js.nft.json +1 -1
  204. package/app/.next/server/app/api/v0/shares/route.js +4 -3
  205. package/app/.next/server/app/api/v0/shares/route.js.nft.json +1 -1
  206. package/app/.next/server/app/api/wake-grants/[id]/revoke/route.js +2 -2
  207. package/app/.next/server/app/api/wake-grants/[id]/revoke/route.js.nft.json +1 -1
  208. package/app/.next/server/app/api/wakes/[id]/decision/route.js +2 -2
  209. package/app/.next/server/app/api/wakes/[id]/decision/route.js.nft.json +1 -1
  210. package/app/.next/server/app/api/wakes/[id]/retry/route.js +2 -2
  211. package/app/.next/server/app/api/wakes/[id]/retry/route.js.nft.json +1 -1
  212. package/app/.next/server/app/bots/[id]/config/page.js.nft.json +1 -1
  213. package/app/.next/server/app/bots/[id]/config/page_client-reference-manifest.js +1 -1
  214. package/app/.next/server/app/exchanges/page.js.nft.json +1 -1
  215. package/app/.next/server/app/exchanges/page_client-reference-manifest.js +1 -1
  216. package/app/.next/server/app/exchanges.html +1 -1
  217. package/app/.next/server/app/exchanges.rsc +3 -3
  218. package/app/.next/server/app/exchanges.segments/_full.segment.rsc +3 -3
  219. package/app/.next/server/app/exchanges.segments/_tree.segment.rsc +2 -2
  220. package/app/.next/server/app/exchanges.segments/exchanges/__PAGE__.segment.rsc +3 -3
  221. package/app/.next/server/app/index.html +1 -1
  222. package/app/.next/server/app/index.rsc +3 -3
  223. package/app/.next/server/app/index.segments/__PAGE__.segment.rsc +3 -3
  224. package/app/.next/server/app/index.segments/_full.segment.rsc +3 -3
  225. package/app/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  226. package/app/.next/server/app/page.js.nft.json +1 -1
  227. package/app/.next/server/app/page_client-reference-manifest.js +1 -1
  228. package/app/.next/server/app/settings/page.js.nft.json +1 -1
  229. package/app/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  230. package/app/.next/server/app/settings.html +1 -1
  231. package/app/.next/server/app/settings.rsc +2 -2
  232. package/app/.next/server/app/settings.segments/_full.segment.rsc +2 -2
  233. package/app/.next/server/app/settings.segments/_tree.segment.rsc +2 -2
  234. package/app/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +2 -2
  235. package/app/.next/server/app/threads/[id]/route/app-paths-manifest.json +3 -0
  236. package/app/.next/server/app/threads/[id]/route/build-manifest.json +12 -0
  237. package/app/.next/server/app/threads/[id]/route/server-reference-manifest.json +4 -0
  238. package/app/.next/server/app/threads/[id]/route.js +10 -0
  239. package/app/.next/server/app/threads/[id]/route.js.nft.json +1 -0
  240. package/app/.next/server/app/threads/[id]/route_client-reference-manifest.js +3 -0
  241. package/app/.next/server/app-paths-manifest.json +11 -1
  242. package/app/.next/server/chunks/1oeh_server_app_api_bots_[id]_conversations_[conversationId]_route_actions_11cb2lr.js +3 -0
  243. package/app/.next/server/chunks/{[root-of-the-server]__17xl_55._.js → [root-of-the-server]__03pk_x_._.js} +1 -1
  244. package/app/.next/server/chunks/{[root-of-the-server]__0mp8bap._.js → [root-of-the-server]__05ds5md._.js} +1 -1
  245. package/app/.next/server/chunks/[root-of-the-server]__0anfwiu._.js +52 -0
  246. package/app/.next/server/chunks/{[root-of-the-server]__0-w_t2y._.js → [root-of-the-server]__0atpy-s._.js} +1 -1
  247. package/app/.next/server/chunks/{[root-of-the-server]__06w5xhe._.js → [root-of-the-server]__0hiikkz._.js} +1 -1
  248. package/app/.next/server/chunks/{[root-of-the-server]__1eps2a4._.js → [root-of-the-server]__0pp5x67._.js} +1 -1
  249. package/app/.next/server/chunks/{[root-of-the-server]__1dxr858._.js → [root-of-the-server]__0thkp5l._.js} +1 -1
  250. package/app/.next/server/chunks/[root-of-the-server]__0xhwlr4._.js +3 -0
  251. package/app/.next/server/chunks/{[root-of-the-server]__0-vcyi-._.js → [root-of-the-server]__11yt1hv._.js} +1 -1
  252. package/app/.next/server/chunks/{[root-of-the-server]__1x8phwp._.js → [root-of-the-server]__1280ke1._.js} +8 -6
  253. package/app/.next/server/chunks/{[root-of-the-server]__0iqh5ta._.js → [root-of-the-server]__12wk406._.js} +1 -1
  254. package/app/.next/server/chunks/{[root-of-the-server]__0qaiqut._.js → [root-of-the-server]__13wghn3._.js} +8 -6
  255. package/app/.next/server/chunks/{[root-of-the-server]__0lwsto-._.js → [root-of-the-server]__14cwco7._.js} +3 -3
  256. package/app/.next/server/chunks/{[root-of-the-server]__1kczttr._.js → [root-of-the-server]__185i_bv._.js} +1 -1
  257. package/app/.next/server/chunks/[root-of-the-server]__1byhehl._.js +3 -0
  258. package/app/.next/server/chunks/{[root-of-the-server]__10b5-i-._.js → [root-of-the-server]__1ez_5xy._.js} +1 -1
  259. package/app/.next/server/chunks/[root-of-the-server]__1jxwu9_._.js +52 -0
  260. package/app/.next/server/chunks/{[root-of-the-server]__0o9ijih._.js → [root-of-the-server]__1mxp6z6._.js} +1 -1
  261. package/app/.next/server/chunks/{[root-of-the-server]__0ey3_2x._.js → [root-of-the-server]__1s2-vw3._.js} +1 -1
  262. package/app/.next/server/chunks/{[root-of-the-server]__1hwy3jx._.js → [root-of-the-server]__1xq61ti._.js} +1 -1
  263. package/app/.next/server/chunks/{[root-of-the-server]__04b3ml2._.js → [root-of-the-server]__20om7um._.js} +1 -1
  264. package/app/.next/server/chunks/_0061c2q._.js +1 -1
  265. package/app/.next/server/chunks/_1-5mthb._.js +1 -1
  266. package/app/.next/server/chunks/_12i5gam._.js +7 -0
  267. package/app/.next/server/chunks/_1a0er16._.js +18 -0
  268. package/app/.next/server/chunks/_1uxmsh3._.js +18 -0
  269. package/app/.next/server/chunks/_next-internal_server_app_api_bots_[id]_activity_route_actions_06oyah6.js +3 -0
  270. package/app/.next/server/chunks/_next-internal_server_app_api_bots_[id]_conversations_route_actions_0op0mjv.js +3 -0
  271. package/app/.next/server/chunks/_next-internal_server_app_api_bots_[id]_overview_route_actions_20nuetv.js +3 -0
  272. 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
  273. package/app/.next/server/chunks/lib_0al5wbc._.js +330 -0
  274. package/app/.next/server/chunks/lib_0i8cm07._.js +3 -0
  275. package/app/.next/server/chunks/lib_service-api-http_ts_0xzqhny._.js +1 -23
  276. package/app/.next/server/chunks/lib_service-api_ts_18eok4w._.js +25 -0
  277. package/app/.next/server/chunks/node_modules_next_1zc5q0a._.js +11 -11
  278. package/app/.next/server/chunks/ssr/1oeh_server_app_agents_[id]_conversations_[conversationId]_page_actions_08lev_i.js +3 -0
  279. package/app/.next/server/chunks/ssr/[root-of-the-server]__06s7ons._.js +3 -0
  280. package/app/.next/server/chunks/ssr/[root-of-the-server]__0r8nmcc._.js +3 -0
  281. package/app/.next/server/chunks/ssr/[root-of-the-server]__19qlmru._.js +3 -0
  282. package/app/.next/server/chunks/ssr/[root-of-the-server]__1dpye-p._.js +3 -0
  283. package/app/.next/server/chunks/ssr/[root-of-the-server]__1fxu3a8._.js +3 -0
  284. package/app/.next/server/chunks/ssr/[root-of-the-server]__1t9ljq3._.js +3 -0
  285. package/app/.next/server/chunks/ssr/_0_u9-u6._.js +3 -0
  286. package/app/.next/server/chunks/ssr/_0g3y1u9._.js +3 -0
  287. package/app/.next/server/chunks/ssr/{node_modules_next_0x3i8za._.js → _0gzxfz3._.js} +2 -2
  288. package/app/.next/server/chunks/ssr/_0rvu-il._.js +131 -0
  289. package/app/.next/server/chunks/ssr/_0u7urta._.js +5 -0
  290. package/app/.next/server/chunks/ssr/_17ngohj._.js +3 -0
  291. package/app/.next/server/chunks/ssr/_1iq-7cn._.js +3 -0
  292. package/app/.next/server/chunks/ssr/_next-internal_server_app_agents_[id]_activity_page_actions_1a_v567.js +3 -0
  293. package/app/.next/server/chunks/ssr/_next-internal_server_app_agents_[id]_conversations_page_actions_1dpbbj-.js +3 -0
  294. package/app/.next/server/chunks/ssr/_next-internal_server_app_agents_[id]_page_actions_0k__y7g.js +3 -0
  295. package/app/.next/server/chunks/ssr/_next-internal_server_app_agents_[id]_sessions_page_actions_1hft42g.js +3 -0
  296. package/app/.next/server/chunks/ssr/_next-internal_server_app_agents_[id]_slack_page_actions_0dmtbj_.js +3 -0
  297. package/app/.next/server/chunks/ssr/app_agents_[id]_009y8_j._.js +3 -0
  298. package/app/.next/server/chunks/ssr/app_agents_[id]_0sr4fdg._.js +3 -0
  299. package/app/.next/server/chunks/ssr/app_agents_[id]_activity_AgentActivityPage_tsx_042-590._.js +3 -0
  300. package/app/.next/server/chunks/ssr/app_agents_[id]_conversations_page_tsx_15zl_c8._.js +3 -0
  301. package/app/.next/server/chunks/ssr/app_agents_[id]_sessions_page_tsx_0tfup-2._.js +10 -0
  302. package/app/.next/server/chunks/ssr/app_agents_[id]_slack_AgentSlackPage_tsx_20njhs1._.js +3 -0
  303. package/app/.next/server/chunks/ssr/app_bots_[id]_config_page_tsx_1e0uue9._.js +1 -1
  304. package/app/.next/server/chunks/ssr/app_page_tsx_0pxmutw._.js +3 -0
  305. package/app/.next/server/chunks/ssr/lib_0pfn9gs._.js +3 -0
  306. package/app/.next/server/chunks/ssr/lib_agent-registration-ui_ts_1z582mm._.js +3 -0
  307. package/app/.next/server/chunks/ssr/lib_exchange-view_ts_1a4q9ju._.js +1 -1
  308. package/app/.next/server/chunks/ssr/lib_share-view_ts_08psw5o._.js +3 -0
  309. package/app/.next/server/middleware-build-manifest.js +3 -3
  310. package/app/.next/server/next-font-manifest.js +1 -1
  311. package/app/.next/server/next-font-manifest.json +24 -4
  312. package/app/.next/server/pages/404.html +1 -1
  313. package/app/.next/server/pages/500.html +1 -1
  314. package/app/.next/server/server-reference-manifest.js +1 -1
  315. package/app/.next/server/server-reference-manifest.json +1 -1
  316. package/app/.next/static/chunks/06i_6p0-ipitj.js +1 -0
  317. package/app/.next/static/chunks/0cjh4u-f7mlwd.js +1 -0
  318. package/app/.next/static/chunks/1dhk3pcv7yvm6.js +1 -0
  319. package/app/.next/static/chunks/1ka9dp1l6c0ga.js +3 -0
  320. package/app/.next/static/chunks/1ttvnc6qdye8s.js +1 -0
  321. package/app/.next/static/chunks/1ypwptc0fsn4w.js +1 -0
  322. package/app/.next/static/chunks/2-fhbx41zyanc.js +1 -0
  323. package/app/.next/static/chunks/2cc4uzbhs_v23.js +1 -0
  324. package/app/.next/static/chunks/2n1u8a2efnt88.js +1 -0
  325. package/app/.next/static/chunks/2q4c2cj6ftmp_.css +3 -0
  326. package/app/.next/static/chunks/34v8aumua0x5n.js +1 -0
  327. package/app/.next/static/chunks/3aasli1i-eiio.js +1 -0
  328. package/app/.next/static/chunks/3p_p4gnr0d2-x.js +1 -0
  329. package/app/.next/static/chunks/3s9t477v-z09o.js +1 -0
  330. package/app/.next/static/chunks/3y5bo6syunkzn.js +8 -0
  331. package/app/BUILD_INFO.json +2 -2
  332. package/app/package.json +1 -1
  333. package/app/server.js +1 -1
  334. package/package.json +1 -1
  335. package/app/.next/server/app/threads/[id]/page/app-paths-manifest.json +0 -3
  336. package/app/.next/server/app/threads/[id]/page_client-reference-manifest.js +0 -3
  337. package/app/.next/server/chunks/[root-of-the-server]__0d3fjix._.js +0 -3
  338. package/app/.next/server/chunks/lib_agent-api_ts_0iv52-o._.js +0 -3
  339. package/app/.next/server/chunks/ssr/[root-of-the-server]__1t063pe._.js +0 -3
  340. package/app/.next/server/chunks/ssr/_00ysoah._.js +0 -3
  341. package/app/.next/server/chunks/ssr/_1cvuhjt._.js +0 -3
  342. package/app/.next/server/chunks/ssr/_1lkd0ui._.js +0 -3
  343. package/app/.next/server/chunks/ssr/_1n5mvo5._.js +0 -3
  344. package/app/.next/server/chunks/ssr/_1o94bnv._.js +0 -12
  345. package/app/.next/server/chunks/ssr/_1r5kd5j._.js +0 -3
  346. package/app/.next/static/chunks/0y1ihx4vq8du3.js +0 -10
  347. package/app/.next/static/chunks/1c2dl2ga-lqcb.css +0 -3
  348. package/app/.next/static/chunks/2q-tgwkalrnms.js +0 -1
  349. package/app/.next/static/chunks/2qf-mb__71dkk.js +0 -1
  350. package/app/.next/static/chunks/399dvlpyl00wn.js +0 -1
  351. package/app/.next/static/chunks/3b7r6u9nfsjb1.js +0 -1
  352. package/app/.next/static/chunks/3f1v-zuki9k7k.js +0 -1
  353. /package/app/.next/server/app/{threads/[id] → agents/[id]/activity}/page/build-manifest.json +0 -0
  354. /package/app/.next/server/app/{threads/[id] → agents/[id]/activity}/page/react-loadable-manifest.json +0 -0
  355. /package/app/.next/server/app/{threads/[id] → agents/[id]/activity}/page/server-reference-manifest.json +0 -0
  356. /package/app/.next/static/{3rSDqQK0KGcTDI98uoZRy → k_jNwnr0zNTXiU6M6Kx5O}/_buildManifest.js +0 -0
  357. /package/app/.next/static/{3rSDqQK0KGcTDI98uoZRy → k_jNwnr0zNTXiU6M6Kx5O}/_clientMiddlewareManifest.js +0 -0
  358. /package/app/.next/static/{3rSDqQK0KGcTDI98uoZRy → k_jNwnr0zNTXiU6M6Kx5O}/_ssgManifest.js +0 -0
@@ -0,0 +1,3 @@
1
+ module.exports=[43345,e=>{"use strict";var t=e.i(62294),r=e.i(26571),n=e.i(45383);let o=["authentication_unavailable","unauthenticated","principal_mismatch","agent_not_found","conversation_not_found","request_not_found"];async function i(e,r){let i,a=null,s=!1,c=null;try{i=await e(e=>{a=e},()=>{let e=a;r&&e&&"service"===e.kind&&t.serviceAudit.append({principal:e,operation:r.operation,capability:"participant",targetKind:r.targetKind,targetRef:r.targetRef,outcome:"allowed",code:null}),s=!0})}catch(e){if(e instanceof n.AgentApiError)c=e.code,i=Response.json({error:{code:e.code,message:e.message}},{status:e.status});else console.error("Agent conversation API error:",e),c="internal_error",i=Response.json({error:{code:"internal_error",message:"The request could not be processed."}},{status:500})}let l=a;if(s&&null===c)return i;if(r&&l&&"service"===l.kind)try{t.serviceAudit.append({principal:l,operation:r.operation,capability:"participant",targetKind:r.targetKind,targetRef:r.targetRef,outcome:null===c?"allowed":"internal_error"===c?"error":o.includes(c)?"denied":"rejected",code:c})}catch(e){return console.error("Service audit append failed:",e instanceof Error?e.message:"unknown error"),Response.json({error:{code:"internal_error",message:"The request could not be processed."}},{status:500})}return i}async function a(e){let t,o=function(){try{return(0,r.serviceTokenAuthenticatorFromEnv)()}catch(e){if(e instanceof r.ServiceTokenConfigError)return console.error(`Agent API authentication disabled: ${e.message}`),null;throw e}}();if(!o)throw new n.AgentApiError("authentication_unavailable","No authenticator is configured for the agent conversation API.");try{t=await o(e)}catch{t=null}if(!t||!(0,n.isPrincipalKind)(t.kind)||"string"!=typeof t.id||!t.id.trim())throw new n.AgentApiError("unauthenticated","Authentication failed.");return{kind:t.kind,id:t.id}}async function s(e,t){return i(async(r,o)=>{var i;let s,c=await a(e);r(c);try{let t=await e.json();if(!t||"object"!=typeof t||Array.isArray(t))throw Error("not an object");s=t}catch{throw new n.AgentApiError("invalid_request","The request body must be a JSON object.")}let l=null==(i=s.principal)?null:{kind:i.kind,id:String(i.id??"")};if(l&&!(0,n.samePrincipal)(l,c))throw new n.AgentApiError("principal_mismatch","The declared principal does not match the authenticated principal.");let u=e.headers.get("idempotency-key"),d="string"==typeof s.idempotencyKey?s.idempotencyKey:null;if(u&&d&&u!==d)throw new n.AgentApiError("invalid_request","Idempotency-Key header and body idempotencyKey differ.");let p=u??d??"";if(p.toLowerCase().startsWith(n.MCP_IDEMPOTENCY_PREFIX))throw new n.AgentApiError("invalid_request",`Idempotency keys starting with "${n.MCP_IDEMPOTENCY_PREFIX}" are reserved for the MCP bridge.`);let{accepted:g,dispatched:h}=(0,n.acceptAgentMessage)(c,{agentId:t,content:"string"==typeof s.content?s.content:"",idempotencyKey:p,conversationId:"string"==typeof s.conversationId?s.conversationId:null==s.conversationId?null:""},o);return!0===s.wait?(await h,Response.json({...(0,n.getAgentRequest)(c,g.requestId),replayed:g.replayed})):Response.json(g,{status:g.replayed?200:202})},{operation:"agents.message",targetKind:"agent",targetRef:t})}async function c(e,t){return i(async r=>{let o=await a(e);return r(o),Response.json((0,n.getConversation)(o,t))},{operation:"conversations.read",targetKind:"conversation",targetRef:t})}async function l(e,t){return i(async r=>{let o=await a(e);return r(o),Response.json((0,n.getAgentRequest)(o,t))},{operation:"requests.read",targetKind:"request",targetRef:t})}e.s(["authenticate",0,a,"handleGetAgentRequest",0,l,"handleGetConversation",0,c,"handleSendAgentMessage",0,s])},86353,e=>{"use strict";let t=new Set(["127.0.0.1","localhost","[::1]"]),r=new Set(["GET","HEAD","OPTIONS"]);function n(e){let r=e?function(e){let t=e.trim().toLowerCase();if(!t)return null;if(t.startsWith("[")){let e=t.indexOf("]");if(e<0)return null;let r=t.slice(e+1);return""===r||/^:\d+$/.test(r)?t.slice(0,e+1):null}let[r,n,o]=t.split(":");return void 0===o&&(void 0===n||/^\d+$/.test(n))?r:null}(e):null;return!!r&&t.has(r)}e.s(["OWNER_ORIGIN_REQUIRED",0,"owner_origin_required","isLoopbackHost",0,n,"ownerBoundaryRefusalFor",0,function(e){let t=new URL(e.url);var o={method:e.method,host:e.headers.get("host")??t.host,origin:e.headers.get("origin"),secFetchSite:e.headers.get("sec-fetch-site"),protocol:t.protocol};if(!n(o.host))return"The request did not arrive on a loopback host.";if(r.has(o.method.toUpperCase()))return null;let i=o.secFetchSite?.trim().toLowerCase()??null;if(null!==i&&"same-origin"!==i)return"The request is not same-origin.";if(null!==o.origin){let e=`${o.protocol}//${o.host.trim().toLowerCase()}`;return o.origin.trim().toLowerCase()!==e?"The request came from another origin.":null}return"same-origin"===i?null:"The request carries no same-origin proof."}])}];
2
+
3
+ //# sourceMappingURL=lib_0i8cm07._.js.map
@@ -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(46309),d=e.i(62349),c=e.i(18966),l=e.i(35613),u=e.i(90027),_=e.i(63020),g=e.i(91253),p=e.i(93399),h=e.i(50081),f=e.i(16789),m=e.i(35034);let y={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},w=["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 v 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,h.recoveryFor)(e),this.reason=n.reason??null}get status(){return y[this.code]}get denied(){return w.includes(this.code)}}let E={pin:()=>new v("pin_not_found","No pin with that reference is visible to this principal."),share:()=>new v("share_not_found","No share with that reference is visible to this principal."),agent:()=>new v("agent_not_found","No Agent with that id is visible to this principal."),session:()=>new v("session_not_found","No session with that reference is visible to this principal."),conversation:()=>new v("conversation_not_found","No conversation with that id is visible to this principal."),exchange:()=>new v("exchange_not_found","No exchange with that id is visible to this principal.")};function S(e){let t=E[e]();return new v(t.code,t.message,{notGranted:!0})}function b(e){switch(e.code){case"exchange_not_found":return E.exchange();case"session_not_found":return E.session();case"agent_not_found":return E.agent();case"conversation_not_found":return E.conversation();case"invalid_transition":return new v("conflict","The exchange changed concurrently; read it and retry.");default:return e.code in y?new v(e.code,e.message):new v("invalid_request",e.message)}}let R=new Map;function I(e){if("service"!==e.kind)throw new v("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:R};let t=(0,g.loadServiceGrants)();if("invalid"===t.state)throw new v("grants_unavailable","The service grants are not available; the owner must fix the grants document.");return"absent"===t.state?{principal:e,mode:"narrow",agents:R}:{principal:e,mode:"granted",agents:t.grants.get(e.id)??R}}function k(e,n,i){return"string"==typeof n&&!!e.agents.get(n)?.has(i)&&!!t.bots.getById(n)}function A(e,n,i){let r=t.bots.getById(n);if(!r)throw E.agent();if(!k(e,n,i))throw S("agent");return r}let x=Object.freeze({default:20,max:100,messagesDefault:50,messagesMax:200});function C(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 v("invalid_request",`limit must be an integer from 1 to ${n}.`);return Number(e)}function T(e,t,n,i,r){try{return(0,o.paginateRows)(e,t,n,i,r)}catch(e){if(e instanceof o.InvalidPageCursorError)throw new v("invalid_request",e.message);throw e}}function q(e){let n=[...e.agents.entries()].filter(([e])=>!!t.bots.getById(e)).map(([e,t])=>({agent_id:e,capabilities:g.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:g.SERVICE_CAPABILITIES,agents:n,limits:{page:x,content_chars:l.EXCHANGE_LIMITS.instructionChars,message_content_chars:D}}}function N(e,n){let i,r=(0,d.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:g.SERVICE_CAPABILITIES.filter(e=>s.has(e)),messaging:{home_session_ref:n.home_session_id??null,new_sessions_allowed:(0,c.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 O(e,n){let i=[...e.agents.keys()].filter(t=>k(e,t,"agents:read")).map(n=>N(e,t.bots.getById(n)));return T(`agents:${e.principal.id}`,i,e=>({at:e.last_activity_at,tie:e.created_at,id:e.agent_id}),n.cursor,n.limit)}function P(e,t){return N(e,A(e,t,"agents:read"))}function L(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 K(e,n){A(e,n,"sessions:read"),await (0,f.warmAgentProvider)(t.default,n,{onlyWithSessions:!0})}function M(e,n,i){A(e,n,"sessions:read");let s=i.status??"all";if(!(0,u.isSessionFilter)(s))throw new v("invalid_request","status must be active, ended, or all.");let a=(0,p.serviceRedactor)(),o=(0,r.sessionsWithActions)(n,(0,u.listAgentSessions)(t.default,n,s)).map(e=>a.deep(L(e)));return T(`sessions:${n}:${s}`,o,e=>({at:e.last_activity_at,tie:e.created_at,id:e.ref}),i.cursor,i.limit)}function $(e,n,i){A(e,n,"sessions:read");let s=(0,u.getAgentSession)(t.default,n,i);if(!s)throw E.session();return(0,p.serviceRedactor)().deep({...L((0,r.sessionsWithActions)(n,[s])[0]),attempts:s.attempts,usage_samples:s.usage_samples.map(e=>({...e}))})}let D=16e3,F=`
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 G(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 B(e,t){return t.every(t=>"bot"===t.kind?k(e,t.id,"conversations:read"):"service"!==t.kind||t.id===e.principal.id)}function H(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 W(e,n,i){A(e,n,"conversations:read");let r=t.default.prepare(F).all(n).flatMap(t=>{let n=G(t.id);return B(e,n)?[H(t,n)]:[]});return T(`conversations:${n}`,r,e=>({at:e.last_activity_at,tie:e.created_at,id:e.conversation_id}),i.cursor,i.limit)}function j(e,n,i,r){var s;A(e,n,"conversations:read");let a=t.default.prepare(`${F} WHERE c.id = ?`).get(n,i);if(!a)throw E.conversation();let d=G(a.id);if(!B(e,d))throw S("conversation");let c=`messages:${a.id}`,l=function(e,t){try{return(0,o.decodePageCursor)(e,t)}catch(e){if(e instanceof o.InvalidPageCursorError)throw new v("invalid_request",e.message);throw e}}(c,r.cursor),u=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(a.id,l?l.at:Number.MAX_SAFE_INTEGER,r.limit+1),_=u.slice(0,r.limit).reverse(),g=(0,p.serviceRedactor)();return{...H(a,d),messages:_.map(e=>{var t,n;let i,r=g.text(e.content);return{message_id:e.id,seq:e.seq,sender:(t=e,n=a,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>D?r.slice(0,D):r,truncated:r.length>D,request_id:e.request_id,created_at:e.created_at}}),next_cursor:u.length>r.limit&&_.length>0?(s={at:_[0].seq,tie:0,id:_[0].id},(0,o.encodePageCursor)(c,s)):null}}let X=["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 V(e){return!!e&&"object"==typeof e&&!Array.isArray(e)}function J(e,t,n){for(let i of Object.keys(e))if(!t.includes(i)){if(X.includes(i))throw new v("authority_not_allowed",`${n}${i} is chosen by Botmancers from the session and the Agent's configuration; a caller cannot set it.`);throw new v("invalid_request",`${n}${i} is not a field of this request.`)}}function U(e,t,n){if("string"!=typeof e||0===e.trim().length)throw new v("invalid_request",`${t} is required.`);if(e.length>n)throw new v("invalid_request",`${t} exceeds ${n} characters.`);return e}function Y(e,t){let n=e.idempotency_key;if(void 0!==n&&"string"!=typeof n)throw new v("invalid_request","idempotency_key must be a string.");if(null!==t&&void 0!==n&&t!==n)throw new v("invalid_request","Idempotency-Key header and body idempotency_key differ.");let i=n??t??"";if(0===i.trim().length||i.length>160)throw new v("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 Q(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 Z(e){return t.default.prepare("SELECT * FROM session_bindings WHERE id = ?").get(e)}function ee(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 _.ExchangeError)throw b(e);throw e}}function et(e,t){if(!V(e))throw new v("invalid_request","The body must be a JSON object.");J(e,["content","idempotency_key"],"");let n=Y(e,t);return{content:U(e.content,"content",l.EXCHANGE_LIMITS.instructionChars),idempotencyKey:n}}function en(e,n,r,s){let o=Z(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&&k(e,i.agent_id,"sessions:message"))throw new v("session_not_resumable","This session is not reachable through session messages.");throw E.session()}if(!k(e,o.agent_id,"sessions:message"))throw S("session");let d=e.principal,c=`${g.MESSAGE_KEY_PREFIX}${r.idempotencyKey}`,{exchange:l,created:u}=ee(()=>{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??Q(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),_=(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:_}}function ei(e,t,n){return t.requester_kind===e.principal.kind&&t.requester_id===e.principal.id&&k(e,t.source_agent_id,n)&&(null===t.destination_agent_id||k(e,t.destination_agent_id,n))}function er(e,t,n){let r=i.exchanges.get(t);if(!r)throw E.exchange();if(!ei(e,r,n))throw S("exchange");return r}let es=e=>e.idempotency_key.startsWith(g.MESSAGE_KEY_PREFIX)?"session_message":"exchange";function ea(e,t){let n=t.idempotency_key.startsWith(g.MESSAGE_KEY_PREFIX)?t.idempotency_key.slice(g.MESSAGE_KEY_PREFIX.length):t.idempotency_key.startsWith(g.EXCHANGE_KEY_PREFIX)?t.idempotency_key.slice(g.EXCHANGE_KEY_PREFIX.length):t.idempotency_key;return(0,p.serviceRedactor)().deep({...e,kind:es(t),idempotency_key:n})}function eo(e){return{id:e.id,kind:es(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 ed(e,t){let n=i.exchanges.require(t);return ei(e,n,"exchanges:read")?ea((0,i.getExchangeView)(t),n):eo(n)}function ec(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=>ei(e,t,"exchanges:read")).map(eo);return T(`exchanges:${e.principal.id}`,i,e=>({at:e.updated_at,tie:e.created_at,id:e.id}),n.cursor,n.limit)}function el(e,t){let n=er(e,t,"exchanges:read");return ea((0,i.getExchangeView)(n.id),n)}let eu=["exchange_id","parent_exchange_id"];function e_(e,t){if(!V(e))throw new v("invalid_request","The body must be a JSON object.");if(eu.some(t=>t in e))throw new v("recursive_exchange","An exchange cannot be started from another exchange.");if(J(e,["mode","idempotency_key","origin_conversation_id","source","destination","instruction"],""),"ask"!==e.mode&&"continue"!==e.mode)throw new v("invalid_request",'mode must be "ask" or "continue".');if(!V(e.source))throw new v("invalid_request","source must be one object { session_ref, agent_id? }.");J(e.source,["session_ref","agent_id"],"source.");let n=null;if(void 0!==e.destination&&null!==e.destination){if(!V(e.destination))throw new v("destination_invalid","destination must be one object { agent_id, conversation_id? }.");J(e.destination,["agent_id","conversation_id"],"destination."),n=e.destination}let i=(e,t)=>null==e?null:U(e,t,200);return{mode:e.mode,idempotencyKey:Y(e,t),originConversationId:i(e.origin_conversation_id,"origin_conversation_id"),sourceAgentId:i(e.source.agent_id,"source.agent_id"),sessionRef:U(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:U(e.instruction,"instruction",l.EXCHANGE_LIMITS.instructionChars)}}function eg(e,n,r){let s=Z(n.sessionRef);if(!s||null!==n.sourceAgentId&&n.sourceAgentId!==s.agent_id)throw E.session();if(!k(e,s.agent_id,"exchanges:create"))throw S("session");if("ask"===n.mode&&(null!==n.destinationAgentId||null!==n.destinationConversationId))throw new v("destination_invalid","An Ask returns to the origin conversation and takes no destination.");if("continue"===n.mode){if(null===n.destinationAgentId)throw new v("destination_invalid","A Continue names destination.agent_id.");if(!t.bots.getById(n.destinationAgentId))throw E.agent();if(!k(e,n.destinationAgentId,"exchanges:create"))throw S("agent")}let a=e.principal,o=`${g.EXCHANGE_KEY_PREFIX}${n.idempotencyKey}`,{exchange:d,created:c}=ee(()=>{let e=Date.now(),t=z(a,o),i=n.originConversationId??t?.origin_conversation_id??Q(a,s.agent_id,e),r="continue"!==n.mode?null:n.destinationConversationId??t?.destination_conversation_id??Q(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:ed(e,d.id),created:c,dispatched:l}}function ep(e){try{return(0,_.cancelReasonFromBody)(e)}catch(e){if(e instanceof _.ExchangeError)throw b(e);throw e}}async function eh(e,t,n,r){let s=er(e,t,"exchanges:create");try{let{replayed:t}=await (0,i.cancelExchangeCommand)(s.id,e.principal,n,r);return{exchange:ed(e,s.id),replayed:t}}catch(e){if(e instanceof _.ExchangeError)throw b(e);throw e}}let ef=e=>"resume"===e?"sessions:resume":"sessions:message";function em(e){if(e instanceof r.PinError){if("session_not_found"===e.code)throw E.session();if("agent_not_found"===e.code)throw E.agent();if("pin_not_found"===e.code)throw E.pin();if("conversation_not_found"===e.code)throw E.conversation();throw new v(e.code,e.message)}if(e instanceof _.ExchangeError)throw b(e);throw e}function ey(e,t){let n;try{n=(0,r.requirePin)(e.principal,t)}catch(e){em(e)}if(!k(e,n.agent_id,ef(n.action)))throw S("pin");return n}function ew(e){return(0,p.serviceRedactor)().deep((0,r.pinView)(e))}function ev(e,t){return et(e,t)}function eE(e,t){if(!V(e))throw new v("invalid_request","The body must be a JSON object.");if(J(e,["action","approve_write","replace_pin_ref","idempotency_key"],""),"ask"!==e.action&&"resume"!==e.action)throw new v("invalid_request",'action must be "ask" or "resume".');if(void 0!==e.approve_write&&"boolean"!=typeof e.approve_write)throw new v("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:U(e.replace_pin_ref,"replace_pin_ref",200),idempotencyKey:Y(e,t)}}async function eS(e,t,n,i){A(e,t,"sessions:message");try{let s=await (0,r.messageAgent)({requester:e.principal,agentId:t,content:n.content,idempotencyKey:n.idempotencyKey,mayStart:k(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:ew(s.pin),turn:(0,p.serviceRedactor)().deep(s.turn),resolution:s.resolution,replayed:s.replayed},settled:s.settled}}catch(e){em(e)}}async function eb(e,t,n,i){let s=(0,r.sessionOwner)(t);if(!s)throw E.session();let a=ef(n.action);if(i.onTarget({agentId:s,sessionRef:t,capability:a,action:"resume"===n.action?"pins.resume":"pins.ask"}),!k(e,s,a))throw S("session");n.replacePinRef&&ey(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:ew(s),replaced_pin_ref:o?.id??null,replayed:!a}}catch(e){em(e)}}async function eR(e,t,n,i){let s=ey(e,t);i.onTarget({agentId:s.agent_id,sessionRef:s.session_ref,capability:ef(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:ew(t.pin),turn:(0,p.serviceRedactor)().deep(t.turn),replayed:t.replayed},settled:t.settled}}catch(e){em(e)}}async function eI(e,t,n){let i=ey(e,t);n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref,capability:ef(i.action),action:"pins.read"});try{let{pin:t,turns:n}=await (0,r.readPin)(e.principal,i.id);return{pin:ew(t),turns:(0,p.serviceRedactor)().deep(n)}}catch(e){em(e)}}function ek(e,t,n){let i=ey(e,t);n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref,capability:ef(i.action),action:"pins.detach"});try{let{pin:t,replayed:s}=(0,r.detachPin)(e.principal,i.id,{onCommit:()=>n.onCommit()});return{pin:ew(t),replayed:s}}catch(e){em(e)}}let eA=["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"],ex=[...new Set([...X,...eA])];function eC(e,t,n){for(let i of Object.keys(e))if(!t.includes(i)){if(ex.includes(i))throw new v("authority_not_allowed",`${n}${i} cannot select or describe a session; name it by session_ref only.`);throw new v("invalid_request",`${n}${i} is not a field of this request.`)}}function eT(e,t){if(null==e)return null;if("number"!=typeof e||!Number.isInteger(e))throw new v("invalid_request",`${t} must be an integer.`);return e}function eq(e,t){if(!V(e))throw new v("invalid_request","The body must be a JSON object.");if(eC(e,["audience","ttl_seconds","max_turns","agent_id","idempotency_key"],""),!V(e.audience))throw new v("invalid_request",'audience must be one object { kind: "slack", team_id, channel_id }.');if(eC(e.audience,["kind","team_id","channel_id"],"audience."),!(0,m.isSlackAudience)(e.audience))throw new v("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:eT(e.ttl_seconds,"ttl_seconds"),maxTurns:eT(e.max_turns,"max_turns"),agentId:void 0===e.agent_id||null===e.agent_id?null:U(e.agent_id,"agent_id",200),idempotencyKey:Y(e,t)}}function eN(e){let t;if(""!==e.trim()){try{t=JSON.parse(e)}catch{throw new v("invalid_request","The body must be empty or a JSON object.")}if(!V(t))throw new v("invalid_request","The body must be empty or a JSON object.");eC(t,["idempotency_key"],""),void 0!==t.idempotency_key&&U(t.idempotency_key,"idempotency_key",160)}}let eO=["session_ref","state","cursor","limit"],eP=["active","expired","revoked"];function eL(e){for(let t of e)if(!eO.includes(t)){if(ex.includes(t))throw new v("authority_not_allowed",`${t} cannot select a session; filter by session_ref only.`);throw new v("invalid_request",`${t} is not a parameter of this list.`)}}function eK(e){if(e instanceof m.ShareError){if("session_not_found"===e.code)throw E.session();if("share_not_found"===e.code)throw E.share();throw new v(e.code,e.message)}em(e)}function eM(e,t){let n=(0,m.shareRow)(t);if(!n)throw E.share();if(!(n.creator_kind===e.principal.kind&&n.creator_id===e.principal.id&&k(e,n.agent_id,"shares:create")))throw S("share");return n}function e$(e,t=(0,p.serviceRedactor)()){return t.deep((0,m.shareView)(e))}async function eD(e,t,n,i){let s=(0,r.sessionOwner)(t);if(i.onTarget({agentId:s,sessionRef:t}),!s)throw E.session();if(!k(e,s,"shares:create"))throw S("session");if(null!==n.agentId&&n.agentId!==s)throw E.session();try{let{share:r,created:s}=await (0,m.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:e$(r),replayed:!s}}catch(e){eK(e)}}function eF(e,t,n){let i=eM(e,t);return n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref}),{share:e$(i)}}function eG(e,t){if(null!==t.sessionRef&&(""===t.sessionRef.trim()||t.sessionRef.length>200))throw new v("invalid_request","session_ref must be one session reference.");if(null!==t.state&&!eP.includes(t.state))throw new v("invalid_request","state must be active, expired, or revoked.");let n=(0,p.serviceRedactor)(),i=(0,m.sharesCreatedBy)(e.principal,{sessionRef:t.sessionRef}).filter(t=>k(e,t.agent_id,"shares:create")).map(e=>e$(e,n)).filter(e=>null===t.state||e.state===t.state);return T(`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 eB(e,t,n){let i=eM(e,t);n.onTarget({agentId:i.agent_id,sessionRef:i.session_ref});try{let{share:e,replayed:t}=(0,m.revokeShare)(i.id,{onCommit:()=>n.onCommit()});return{share:e$(e),replayed:t}}catch(e){eK(e)}}let eH=["audience","ttl_seconds","max_turns","agent_id","idempotency_key"];function eW(e,t){if(V(e)&&Object.prototype.hasOwnProperty.call(e,"session_ref"))throw new v("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 V(e)&&eC(e,eH,""),eq(e,t)}function ej(e){if(e.kind!==s.SESSION_CONTEXT_PRINCIPAL.kind||e.id!==s.SESSION_CONTEXT_PRINCIPAL.id)throw new v("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 eX(e){return new v("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 eV(e,t,n,i){if(i.onTarget({agentId:t.agentId,sessionRef:t.sessionRef}),null!==n.agentId&&n.agentId!==t.agentId)throw E.session();try{var r,s;let{share:o,created:d}=await (0,m.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:e$(o),replayed:!d}}catch(e){eK(e)}}e.s(["AUTHORITY_FIELDS",0,X,"MESSAGE_CONTENT_LIMIT",0,D,"PAGE_LIMITS",0,x,"SHARE_SELECTOR_FIELDS",0,eA,"ServiceApiError",0,v,"cancelServiceExchange",0,eh,"capabilitiesView",0,q,"checkShareListParams",0,eL,"createCurrentSessionShare",0,eV,"createServiceExchange",0,eg,"createServiceShare",0,eD,"detachServicePin",0,ek,"getServiceAgent",0,P,"getServiceConversation",0,j,"getServiceExchange",0,el,"getServiceSession",0,$,"getServiceShare",0,eF,"holds",0,k,"listServiceAgents",0,O,"listServiceConversations",0,W,"listServiceExchanges",0,ec,"listServiceSessions",0,M,"listServiceShares",0,eG,"messageServiceAgent",0,eS,"parseAgentMessageBody",0,ev,"parseCancelBody",0,ep,"parseLimit",0,C,"parsePinBody",0,eE,"parseServiceExchangeBody",0,e_,"parseSessionMessageBody",0,et,"parseShareCreateBody",0,eq,"parseShareCurrentBody",0,eW,"parseShareRevokeBody",0,eN,"pinServiceSession",0,eb,"readServicePin",0,eI,"requireShareCurrentCaller",0,ej,"revokeServiceShare",0,eB,"sendServicePinMessage",0,eR,"sendServiceSessionMessage",0,en,"serviceContext",0,I,"sessionContextError",0,eX,"warmServiceAgent",0,K],9501);let eJ="BOTMANCERS_SERVICE_API_CALLS_PER_MINUTE",eU=new Map;async function eY(e){let t=await ez(e);try{return JSON.parse(t)}catch{throw new v("invalid_request","The body must be a JSON object.")}}async function ez(e){let t=new v("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 eQ(e,t,n,i={}){return Response.json({error:{code:t,message:n}},{status:e,headers:i})}let eZ=(e,t=200)=>({status:t,body:e});function e0(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 e4(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 v("principal_not_allowed","The granted service API accepts only service principals.");if(e.id===s.SESSION_CONTEXT_SERVICE_ID&&n.capability!==e2)throw new v("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=(eU.get(n)??[]).filter(e=>e>t-6e4),r=function(){let e=process.env[eJ];if(void 0===e||""===e.trim())return 120;let t=Number(e.trim());return Number.isInteger(t)&&t>0?t:(console.error(`${eJ} must be a positive integer; using 120.`),120)}();return i.length>=r?(eU.set(n,i),Math.max(1,Math.ceil((i[i.length-r]+6e4-t)/1e3))):(i.push(t),eU.set(n,i),null)}(e);if(null!==t)u="rate_limited",o="denied",a=e0(429,"rate_limited","Too many calls; retry later.",{"Retry-After":String(t)});else{let t=I(e);r?.(t),a=await i(t,d,()=>{c("allowed",null),l=!0}),o="allowed"}}catch(e){e instanceof v?(o=e.denied?"denied":"rejected",u=e.notGranted?"not_granted":e.code,a=e0(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=e0(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"),e0(500,"internal_error","The request could not be processed.")}return a}let e2="shares:current";async function e1(e,t){let r;try{r=await (0,n.authenticate)(e)}catch(e){if(e instanceof i.AgentApiError)return eQ(e.status,e.code,e.message);return console.error("Service API authentication error:",e instanceof Error?e.message:"unknown error"),eQ(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 e9(e){let n=t.default.prepare("SELECT agent_id FROM session_bindings WHERE id = ?").get(e);return n?.agent_id??null}function e3(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 e6(e,t,n){return{onTarget:t=>{n&&(e.targetRef=t.sessionRef),e.agentId=t.agentId},onCommit:t}}function e5(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 e8={capabilities:(e,t)=>e4(e,{operation:"capabilities.read",capability:"discovery",targetKind:"grants"},e=>eZ(q(e)),t),listAgents:(e,t,n)=>e4(e,{operation:"agents.list",capability:"agents:read",targetKind:"agent"},e=>eZ(O(e,{cursor:t.cursor,limit:C(t.limit)})),n),getAgent:(e,t,n)=>e4(e,{operation:"agents.read",capability:"agents:read",targetKind:"agent",targetRef:t,agentId:t},e=>eZ(P(e,t)),n),listSessions:(e,t,n,i)=>e4(e,{operation:"sessions.list",capability:"sessions:read",targetKind:"agent",targetRef:t,agentId:t},async e=>(await K(e,t),eZ(M(e,t,{cursor:n.cursor,limit:C(n.limit),status:n.status}))),i),getSession:(e,t,n,i)=>e4(e,{operation:"sessions.read",capability:"sessions:read",targetKind:"session",targetRef:n,agentId:t},async e=>(await K(e,t),eZ($(e,t,n))),i),listConversations:(e,t,n,i)=>e4(e,{operation:"conversations.list",capability:"conversations:read",targetKind:"agent",targetRef:t,agentId:t},e=>eZ(W(e,t,{cursor:n.cursor,limit:C(n.limit)})),i),getConversation:(e,t,n,i,r)=>e4(e,{operation:"conversations.read",capability:"conversations:read",targetKind:"conversation",targetRef:n,agentId:t},e=>eZ(j(e,t,n,{cursor:i.cursor,limit:C(i.limit,x.messagesDefault,x.messagesMax)})),r),sendSessionMessage:(e,t,n,i,r)=>e4(e,{operation:"sessions.message",capability:"sessions:message",targetKind:"session",targetRef:t},async(e,r,s)=>{t.length<=200&&(r.agentId=e9(t));let{accepted:a}=en(e,t,et(await n(),i),e=>{r.agentId=e.source_agent_id,s()});return eZ(a,a.replayed?200:202)},r),listExchanges:(e,t,n)=>e4(e,{operation:"exchanges.list",capability:"exchanges:read",targetKind:"exchange"},e=>eZ(ec(e,{cursor:t.cursor,limit:C(t.limit)})),n),createExchange:(e,t,n,i)=>e4(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?e9(a):null});let{exchange:d,created:c}=eg(e,e_(o,n),e=>{i.kind="exchange",i.targetRef=e.id,i.agentId=e.source_agent_id,r()});return eZ({exchange:d,replayed:!c},c?201:200)},i),getExchange:(e,t,n)=>e4(e,{operation:"exchanges.read",capability:"exchanges:read",targetKind:"exchange",targetRef:t},(e,n)=>{n.agentId=e5(t);let i=el(e,t);return n.agentId=i.source.agent_id,eZ(i)},n),cancelExchange:(e,t,n,i)=>e4(e,{operation:"exchanges.cancel",capability:"exchanges:create",targetKind:"exchange",targetRef:t},async(e,i,r)=>{i.agentId=e5(t);let s=await n();return eZ(await eh(e,t,s,e=>{i.agentId=e.source_agent_id,r()}))},i),messageAgent:(e,t,n,i,r)=>e4(e,{operation:"agents.message",capability:"sessions:message",targetKind:"agent",targetRef:t,agentId:t},async(e,r,s)=>{let a=ev(await n(),i),{body:o}=await eS(e,t,a,e3(r,s));return eZ(o,o.replayed?200:202)},r),pinSession:(e,t,n,i,r)=>e4(e,{operation:"pins.create",capability:"sessions:message",targetKind:"session",targetRef:t},async(e,r,s)=>{let a=eE(await n(),i),o=await eb(e,t,a,e3(r,s));return eZ(o,o.replayed?200:201)},r),readPin:(e,t,n)=>e4(e,{operation:"pins.read",capability:"sessions:message",targetKind:"session"},async(e,n)=>eZ(await eI(e,t,e3(n,()=>{}))),n),sendToPin:(e,t,n,i,r)=>e4(e,{operation:"pins.send",capability:"sessions:message",targetKind:"session"},async(e,r,s)=>{let a=ev(await n(),i),{body:o}=await eR(e,t,a,e3(r,s));return eZ(o,o.replayed?200:202)},r),detachPin:(e,t,n)=>e4(e,{operation:"pins.detach",capability:"sessions:message",targetKind:"session"},(e,n,i)=>eZ(ek(e,t,e3(n,i))),n),createShare:(e,t,n,i,s)=>e4(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=eq(await n(),i),d=await eD(e,t,o,e6(s,a,!1));return eZ(d,d.replayed?200:201)},s),getShare:(e,t,n)=>e4(e,{operation:"shares.read",capability:"shares:create",targetKind:"session",targetRef:t},(e,n)=>eZ(eF(e,t,e6(n,()=>{},!1))),n),listShares:(e,t,n)=>e4(e,{operation:"shares.list",capability:"shares:create",targetKind:"session",targetRef:t.sessionRef},(e,n)=>(eL(t.names??[]),t.sessionRef&&t.sessionRef.length<=200&&(n.agentId=(0,r.sessionOwner)(t.sessionRef)),eZ(eG(e,{cursor:t.cursor,limit:C(t.limit),sessionRef:t.sessionRef,state:t.state}))),n),revokeShare:(e,t,n,i)=>e4(e,{operation:"shares.revoke",capability:"shares:create",targetKind:"session",targetRef:t},async(e,i,r)=>(eN(await n()),eZ(eB(e,t,e6(i,r,!1)))),i),shareCurrent:(e,t,n,i,r)=>e4(e,{operation:"shares.create",capability:e2,targetKind:"session"},async(e,r,a)=>{let o=eW(await n(),i);ej(e.principal);let d=(0,s.resolveSessionContext)(t);if(!d.ok)throw eX(d);let c=await eV(e,d,o,e6(r,a,!0));return eZ(c,c.replayed?200:201)},r)};function e7(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 te(e){let t=(0,s.sessionContextHeader)(e.headers),n=e.headers.get("idempotency-key"),i=i=>e8.shareCurrent(i,t,()=>eY(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 e1(e,i)}e.s(["handleCancelExchange",0,function(e,t){return e1(e,n=>e8.cancelExchange(n,t,async()=>ep(await ez(e))))},"handleCreateExchange",0,function(e){return e1(e,t=>e8.createExchange(t,()=>eY(e),e.headers.get("idempotency-key")))},"handleCreateShare",0,function(e,t){return e1(e,n=>e8.createShare(n,t,()=>eY(e),e.headers.get("idempotency-key")))},"handleDetachPin",0,function(e,t){return e1(e,e=>e8.detachPin(e,t))},"handleGetAgent",0,function(e,t){return e1(e,e=>e8.getAgent(e,t))},"handleGetCapabilities",0,function(e){return e1(e,e=>e8.capabilities(e))},"handleGetConversation",0,function(e,t,n){return e1(e,i=>e8.getConversation(i,t,n,e7(e)))},"handleGetExchange",0,function(e,t){return e1(e,e=>e8.getExchange(e,t))},"handleGetSession",0,function(e,t,n){return e1(e,e=>e8.getSession(e,t,n))},"handleGetShare",0,function(e,t){return e1(e,e=>e8.getShare(e,t))},"handleListAgents",0,function(e){return e1(e,t=>e8.listAgents(t,e7(e)))},"handleListConversations",0,function(e,t){return e1(e,n=>e8.listConversations(n,t,e7(e)))},"handleListExchanges",0,function(e){return e1(e,t=>e8.listExchanges(t,e7(e)))},"handleListSessions",0,function(e,t){let n=e7(e);return e1(e,e=>e8.listSessions(e,t,{cursor:n.cursor,limit:n.limit,status:n.get("status")}))},"handleListShares",0,function(e){let t=e7(e);return e1(e,e=>e8.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 e1(e,n=>e8.messageAgent(n,t,()=>eY(e),e.headers.get("idempotency-key")))},"handlePinSession",0,function(e,t){return e1(e,n=>e8.pinSession(n,t,()=>eY(e),e.headers.get("idempotency-key")))},"handleReadPin",0,function(e,t){return e1(e,e=>e8.readPin(e,t))},"handleRevokeShare",0,function(e,t){return e1(e,n=>e8.revokeShare(n,t,()=>ez(e)))},"handleSendSessionMessage",0,function(e,t){return e1(e,n=>e8.sendSessionMessage(n,t,()=>eY(e),e.headers.get("idempotency-key")))},"handleSendToPin",0,function(e,t){return e1(e,n=>e8.sendToPin(n,t,()=>eY(e),e.headers.get("idempotency-key")))},"handleShareCurrent",0,te,"serviceOperations",0,e8],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