@axhub/acp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (488) hide show
  1. package/.next/BUILD_ID +1 -0
  2. package/.next/app-path-routes-manifest.json +21 -0
  3. package/.next/build-manifest.json +22 -0
  4. package/.next/export-marker.json +6 -0
  5. package/.next/fallback-build-manifest.json +13 -0
  6. package/.next/images-manifest.json +68 -0
  7. package/.next/next-minimal-server.js.nft.json +1 -0
  8. package/.next/next-server.js.nft.json +1 -0
  9. package/.next/package.json +1 -0
  10. package/.next/prerender-manifest.json +90 -0
  11. package/.next/required-server-files.js +336 -0
  12. package/.next/required-server-files.json +336 -0
  13. package/.next/routes-manifest.json +171 -0
  14. package/.next/server/app/_global-error/page/app-paths-manifest.json +3 -0
  15. package/.next/server/app/_global-error/page/build-manifest.json +18 -0
  16. package/.next/server/app/_global-error/page/next-font-manifest.json +6 -0
  17. package/.next/server/app/_global-error/page/react-loadable-manifest.json +1 -0
  18. package/.next/server/app/_global-error/page/server-reference-manifest.json +4 -0
  19. package/.next/server/app/_global-error/page.js +10 -0
  20. package/.next/server/app/_global-error/page.js.nft.json +1 -0
  21. package/.next/server/app/_global-error/page_client-reference-manifest.js +3 -0
  22. package/.next/server/app/_global-error.html +1 -0
  23. package/.next/server/app/_global-error.meta +15 -0
  24. package/.next/server/app/_global-error.rsc +15 -0
  25. package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +5 -0
  26. package/.next/server/app/_global-error.segments/_full.segment.rsc +15 -0
  27. package/.next/server/app/_global-error.segments/_head.segment.rsc +6 -0
  28. package/.next/server/app/_global-error.segments/_index.segment.rsc +5 -0
  29. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -0
  30. package/.next/server/app/_not-found/page/app-paths-manifest.json +3 -0
  31. package/.next/server/app/_not-found/page/build-manifest.json +18 -0
  32. package/.next/server/app/_not-found/page/next-font-manifest.json +6 -0
  33. package/.next/server/app/_not-found/page/react-loadable-manifest.json +1 -0
  34. package/.next/server/app/_not-found/page/server-reference-manifest.json +4 -0
  35. package/.next/server/app/_not-found/page.js +13 -0
  36. package/.next/server/app/_not-found/page.js.nft.json +1 -0
  37. package/.next/server/app/_not-found/page_client-reference-manifest.js +3 -0
  38. package/.next/server/app/_not-found.html +1 -0
  39. package/.next/server/app/_not-found.meta +16 -0
  40. package/.next/server/app/_not-found.rsc +17 -0
  41. package/.next/server/app/_not-found.segments/_full.segment.rsc +17 -0
  42. package/.next/server/app/_not-found.segments/_head.segment.rsc +6 -0
  43. package/.next/server/app/_not-found.segments/_index.segment.rsc +6 -0
  44. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +5 -0
  45. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +5 -0
  46. package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -0
  47. package/.next/server/app/api/acp/capabilities/route/app-paths-manifest.json +3 -0
  48. package/.next/server/app/api/acp/capabilities/route/build-manifest.json +9 -0
  49. package/.next/server/app/api/acp/capabilities/route/server-reference-manifest.json +4 -0
  50. package/.next/server/app/api/acp/capabilities/route.js +9 -0
  51. package/.next/server/app/api/acp/capabilities/route.js.nft.json +1 -0
  52. package/.next/server/app/api/acp/capabilities/route_client-reference-manifest.js +3 -0
  53. package/.next/server/app/api/acp/commands/route/app-paths-manifest.json +3 -0
  54. package/.next/server/app/api/acp/commands/route/build-manifest.json +9 -0
  55. package/.next/server/app/api/acp/commands/route/server-reference-manifest.json +4 -0
  56. package/.next/server/app/api/acp/commands/route.js +6 -0
  57. package/.next/server/app/api/acp/commands/route.js.nft.json +1 -0
  58. package/.next/server/app/api/acp/commands/route_client-reference-manifest.js +3 -0
  59. package/.next/server/app/api/acp/runtime/route/app-paths-manifest.json +3 -0
  60. package/.next/server/app/api/acp/runtime/route/build-manifest.json +9 -0
  61. package/.next/server/app/api/acp/runtime/route/server-reference-manifest.json +4 -0
  62. package/.next/server/app/api/acp/runtime/route.js +6 -0
  63. package/.next/server/app/api/acp/runtime/route.js.nft.json +1 -0
  64. package/.next/server/app/api/acp/runtime/route_client-reference-manifest.js +3 -0
  65. package/.next/server/app/api/chat/route/app-paths-manifest.json +3 -0
  66. package/.next/server/app/api/chat/route/build-manifest.json +9 -0
  67. package/.next/server/app/api/chat/route/server-reference-manifest.json +4 -0
  68. package/.next/server/app/api/chat/route.js +9 -0
  69. package/.next/server/app/api/chat/route.js.nft.json +1 -0
  70. package/.next/server/app/api/chat/route_client-reference-manifest.js +3 -0
  71. package/.next/server/app/api/conversations/[threadId]/messages/route/app-paths-manifest.json +3 -0
  72. package/.next/server/app/api/conversations/[threadId]/messages/route/build-manifest.json +9 -0
  73. package/.next/server/app/api/conversations/[threadId]/messages/route/server-reference-manifest.json +4 -0
  74. package/.next/server/app/api/conversations/[threadId]/messages/route.js +8 -0
  75. package/.next/server/app/api/conversations/[threadId]/messages/route.js.nft.json +1 -0
  76. package/.next/server/app/api/conversations/[threadId]/messages/route_client-reference-manifest.js +3 -0
  77. package/.next/server/app/api/conversations/[threadId]/route/app-paths-manifest.json +3 -0
  78. package/.next/server/app/api/conversations/[threadId]/route/build-manifest.json +9 -0
  79. package/.next/server/app/api/conversations/[threadId]/route/server-reference-manifest.json +4 -0
  80. package/.next/server/app/api/conversations/[threadId]/route.js +8 -0
  81. package/.next/server/app/api/conversations/[threadId]/route.js.nft.json +1 -0
  82. package/.next/server/app/api/conversations/[threadId]/route_client-reference-manifest.js +3 -0
  83. package/.next/server/app/api/conversations/route/app-paths-manifest.json +3 -0
  84. package/.next/server/app/api/conversations/route/build-manifest.json +9 -0
  85. package/.next/server/app/api/conversations/route/server-reference-manifest.json +4 -0
  86. package/.next/server/app/api/conversations/route.js +8 -0
  87. package/.next/server/app/api/conversations/route.js.nft.json +1 -0
  88. package/.next/server/app/api/conversations/route_client-reference-manifest.js +3 -0
  89. package/.next/server/app/api/local-files/image/route/app-paths-manifest.json +3 -0
  90. package/.next/server/app/api/local-files/image/route/build-manifest.json +9 -0
  91. package/.next/server/app/api/local-files/image/route/server-reference-manifest.json +4 -0
  92. package/.next/server/app/api/local-files/image/route.js +6 -0
  93. package/.next/server/app/api/local-files/image/route.js.nft.json +1 -0
  94. package/.next/server/app/api/local-files/image/route_client-reference-manifest.js +3 -0
  95. package/.next/server/app/api/local-files/open/route/app-paths-manifest.json +3 -0
  96. package/.next/server/app/api/local-files/open/route/build-manifest.json +9 -0
  97. package/.next/server/app/api/local-files/open/route/server-reference-manifest.json +4 -0
  98. package/.next/server/app/api/local-files/open/route.js +6 -0
  99. package/.next/server/app/api/local-files/open/route.js.nft.json +1 -0
  100. package/.next/server/app/api/local-files/open/route_client-reference-manifest.js +3 -0
  101. package/.next/server/app/api/output-artifacts/workspace/route/app-paths-manifest.json +3 -0
  102. package/.next/server/app/api/output-artifacts/workspace/route/build-manifest.json +9 -0
  103. package/.next/server/app/api/output-artifacts/workspace/route/server-reference-manifest.json +4 -0
  104. package/.next/server/app/api/output-artifacts/workspace/route.js +6 -0
  105. package/.next/server/app/api/output-artifacts/workspace/route.js.nft.json +1 -0
  106. package/.next/server/app/api/output-artifacts/workspace/route_client-reference-manifest.js +3 -0
  107. package/.next/server/app/api/tools/image-generation/files/[id]/route/app-paths-manifest.json +3 -0
  108. package/.next/server/app/api/tools/image-generation/files/[id]/route/build-manifest.json +9 -0
  109. package/.next/server/app/api/tools/image-generation/files/[id]/route/server-reference-manifest.json +4 -0
  110. package/.next/server/app/api/tools/image-generation/files/[id]/route.js +7 -0
  111. package/.next/server/app/api/tools/image-generation/files/[id]/route.js.nft.json +1 -0
  112. package/.next/server/app/api/tools/image-generation/files/[id]/route_client-reference-manifest.js +3 -0
  113. package/.next/server/app/api/tools/image-generation/records/route/app-paths-manifest.json +3 -0
  114. package/.next/server/app/api/tools/image-generation/records/route/build-manifest.json +9 -0
  115. package/.next/server/app/api/tools/image-generation/records/route/server-reference-manifest.json +4 -0
  116. package/.next/server/app/api/tools/image-generation/records/route.js +7 -0
  117. package/.next/server/app/api/tools/image-generation/records/route.js.nft.json +1 -0
  118. package/.next/server/app/api/tools/image-generation/records/route_client-reference-manifest.js +3 -0
  119. package/.next/server/app/api/tools/user-choice/route/app-paths-manifest.json +3 -0
  120. package/.next/server/app/api/tools/user-choice/route/build-manifest.json +9 -0
  121. package/.next/server/app/api/tools/user-choice/route/server-reference-manifest.json +4 -0
  122. package/.next/server/app/api/tools/user-choice/route.js +6 -0
  123. package/.next/server/app/api/tools/user-choice/route.js.nft.json +1 -0
  124. package/.next/server/app/api/tools/user-choice/route_client-reference-manifest.js +3 -0
  125. package/.next/server/app/favicon.ico/route/app-paths-manifest.json +3 -0
  126. package/.next/server/app/favicon.ico/route/build-manifest.json +9 -0
  127. package/.next/server/app/favicon.ico/route.js +7 -0
  128. package/.next/server/app/favicon.ico/route.js.nft.json +1 -0
  129. package/.next/server/app/favicon.ico.body +0 -0
  130. package/.next/server/app/favicon.ico.meta +1 -0
  131. package/.next/server/app/page/app-paths-manifest.json +3 -0
  132. package/.next/server/app/page/build-manifest.json +18 -0
  133. package/.next/server/app/page/next-font-manifest.json +6 -0
  134. package/.next/server/app/page/react-loadable-manifest.json +1 -0
  135. package/.next/server/app/page/server-reference-manifest.json +4 -0
  136. package/.next/server/app/page.js +14 -0
  137. package/.next/server/app/page.js.nft.json +1 -0
  138. package/.next/server/app/page_client-reference-manifest.js +3 -0
  139. package/.next/server/app/session/[provider]/[sessionId]/page/app-paths-manifest.json +3 -0
  140. package/.next/server/app/session/[provider]/[sessionId]/page/build-manifest.json +18 -0
  141. package/.next/server/app/session/[provider]/[sessionId]/page/next-font-manifest.json +6 -0
  142. package/.next/server/app/session/[provider]/[sessionId]/page/react-loadable-manifest.json +1 -0
  143. package/.next/server/app/session/[provider]/[sessionId]/page/server-reference-manifest.json +4 -0
  144. package/.next/server/app/session/[provider]/[sessionId]/page.js +16 -0
  145. package/.next/server/app/session/[provider]/[sessionId]/page.js.nft.json +1 -0
  146. package/.next/server/app/session/[provider]/[sessionId]/page_client-reference-manifest.js +3 -0
  147. package/.next/server/app/thread/[threadId]/page/app-paths-manifest.json +3 -0
  148. package/.next/server/app/thread/[threadId]/page/build-manifest.json +18 -0
  149. package/.next/server/app/thread/[threadId]/page/next-font-manifest.json +6 -0
  150. package/.next/server/app/thread/[threadId]/page/react-loadable-manifest.json +1 -0
  151. package/.next/server/app/thread/[threadId]/page/server-reference-manifest.json +4 -0
  152. package/.next/server/app/thread/[threadId]/page.js +15 -0
  153. package/.next/server/app/thread/[threadId]/page.js.nft.json +1 -0
  154. package/.next/server/app/thread/[threadId]/page_client-reference-manifest.js +3 -0
  155. package/.next/server/app-paths-manifest.json +21 -0
  156. package/.next/server/chunks/0zjb_server_app_api_conversations_[threadId]_messages_route_actions_0poed25.js +3 -0
  157. package/.next/server/chunks/0zjb_server_app_api_tools_image-generation_files_[id]_route_actions_0-tbvpw.js +3 -0
  158. package/.next/server/chunks/0zjb_server_app_api_tools_image-generation_records_route_actions_0vu38s2.js +3 -0
  159. package/.next/server/chunks/[externals]_next_dist_0.m~pv6._.js +3 -0
  160. package/.next/server/chunks/[root-of-the-server]__04xq..~._.js +3 -0
  161. package/.next/server/chunks/[root-of-the-server]__07sxz4_._.js +3 -0
  162. package/.next/server/chunks/[root-of-the-server]__0dwg3fr._.js +178 -0
  163. package/.next/server/chunks/[root-of-the-server]__0eanzwb._.js +3 -0
  164. package/.next/server/chunks/[root-of-the-server]__0gqx~5k._.js +3 -0
  165. package/.next/server/chunks/[root-of-the-server]__0iokgmz._.js +3 -0
  166. package/.next/server/chunks/[root-of-the-server]__0j-lxr4._.js +3 -0
  167. package/.next/server/chunks/[root-of-the-server]__0ly6hop._.js +3 -0
  168. package/.next/server/chunks/[root-of-the-server]__0nil~wi._.js +3 -0
  169. package/.next/server/chunks/[root-of-the-server]__0tmhg7j._.js +3 -0
  170. package/.next/server/chunks/[root-of-the-server]__0txmfnw._.js +4 -0
  171. package/.next/server/chunks/[root-of-the-server]__0wo0b8z._.js +3 -0
  172. package/.next/server/chunks/[root-of-the-server]__0~mtsby._.js +3 -0
  173. package/.next/server/chunks/[root-of-the-server]__10-n4io._.js +3 -0
  174. package/.next/server/chunks/[root-of-the-server]__10g507v._.js +3 -0
  175. package/.next/server/chunks/[turbopack]_runtime.js +903 -0
  176. package/.next/server/chunks/_next-internal_server_app_api_acp_capabilities_route_actions_08lck.p.js +3 -0
  177. package/.next/server/chunks/_next-internal_server_app_api_acp_commands_route_actions_0as.2z6.js +3 -0
  178. package/.next/server/chunks/_next-internal_server_app_api_acp_runtime_route_actions_0o1ybkn.js +3 -0
  179. package/.next/server/chunks/_next-internal_server_app_api_chat_route_actions_0tmcf6..js +3 -0
  180. package/.next/server/chunks/_next-internal_server_app_api_conversations_[threadId]_route_actions_12yq8z_.js +3 -0
  181. package/.next/server/chunks/_next-internal_server_app_api_conversations_route_actions_131xv69.js +3 -0
  182. package/.next/server/chunks/_next-internal_server_app_api_local-files_image_route_actions_0f~10mn.js +3 -0
  183. package/.next/server/chunks/_next-internal_server_app_api_local-files_open_route_actions_026mg-2.js +3 -0
  184. package/.next/server/chunks/_next-internal_server_app_api_output-artifacts_workspace_route_actions_1239-n7.js +3 -0
  185. package/.next/server/chunks/_next-internal_server_app_api_tools_user-choice_route_actions_09xqbn_.js +3 -0
  186. package/.next/server/chunks/_next-internal_server_app_favicon_ico_route_actions_095lj93.js +3 -0
  187. package/.next/server/chunks/instrumentation_ts_0zq9-xz._.js +3 -0
  188. package/.next/server/chunks/lib_conversations_store_ts_0gzcj38._.js +7 -0
  189. package/.next/server/chunks/node_modules_@vercel_oidc_dist_token_0zdeuds.js +3 -0
  190. package/.next/server/chunks/node_modules_next_00hve1e._.js +13 -0
  191. package/.next/server/chunks/ssr/[root-of-the-server]__02qo-zr._.js +19 -0
  192. package/.next/server/chunks/ssr/[root-of-the-server]__0488vn3._.js +3 -0
  193. package/.next/server/chunks/ssr/[root-of-the-server]__08e5v4-._.js +3 -0
  194. package/.next/server/chunks/ssr/[root-of-the-server]__08iwq-u._.js +3 -0
  195. package/.next/server/chunks/ssr/[root-of-the-server]__0a1m1mq._.js +3 -0
  196. package/.next/server/chunks/ssr/[root-of-the-server]__0i9qg2.._.js +33 -0
  197. package/.next/server/chunks/ssr/[root-of-the-server]__0icm-_h._.js +3 -0
  198. package/.next/server/chunks/ssr/[root-of-the-server]__0piffp7._.js +3 -0
  199. package/.next/server/chunks/ssr/[root-of-the-server]__0xn-a8p._.js +3 -0
  200. package/.next/server/chunks/ssr/[root-of-the-server]__0~c929r._.js +33 -0
  201. package/.next/server/chunks/ssr/[turbopack]_runtime.js +903 -0
  202. package/.next/server/chunks/ssr/_0-oaqqe._.js +6 -0
  203. package/.next/server/chunks/ssr/_006q235._.js +3 -0
  204. package/.next/server/chunks/ssr/_03.pm1z._.js +108 -0
  205. package/.next/server/chunks/ssr/_0txwi90._.js +3 -0
  206. package/.next/server/chunks/ssr/_next-internal_server_app__global-error_page_actions_0k77kol.js +3 -0
  207. package/.next/server/chunks/ssr/_next-internal_server_app__not-found_page_actions_0eq97pa.js +3 -0
  208. package/.next/server/chunks/ssr/_next-internal_server_app_page_actions_09-gtaw.js +3 -0
  209. package/.next/server/chunks/ssr/_next-internal_server_app_session_[provider]_[sessionId]_page_actions_0_67qh_.js +3 -0
  210. package/.next/server/chunks/ssr/_next-internal_server_app_thread_[threadId]_page_actions_11mcypo.js +3 -0
  211. package/.next/server/chunks/ssr/lib_conversations_store_ts_0-pd6d3._.js +4 -0
  212. package/.next/server/chunks/ssr/node_modules_09w7yel._.js +33 -0
  213. package/.next/server/chunks/ssr/node_modules_0tev5qq._.js +3 -0
  214. package/.next/server/chunks/ssr/node_modules_@vercel_oidc_dist_token_0yj7kvj.js +3 -0
  215. package/.next/server/chunks/ssr/node_modules_next_dist_09jzzl8._.js +3 -0
  216. package/.next/server/chunks/ssr/node_modules_next_dist_0h9llsw._.js +6 -0
  217. package/.next/server/chunks/ssr/node_modules_next_dist_0t-hj0x._.js +3 -0
  218. package/.next/server/chunks/ssr/node_modules_next_dist_client_components_0inhx6q._.js +3 -0
  219. package/.next/server/chunks/ssr/node_modules_next_dist_client_components_builtin_forbidden_0ghu-f7.js +3 -0
  220. package/.next/server/chunks/ssr/node_modules_next_dist_client_components_builtin_global-error_0lgvd_..js +3 -0
  221. package/.next/server/chunks/ssr/node_modules_next_dist_client_components_builtin_unauthorized_0cjv-23.js +3 -0
  222. package/.next/server/chunks/ssr/node_modules_next_dist_esm_build_templates_app-page_00297nb.js +4 -0
  223. package/.next/server/chunks/ssr/node_modules_next_dist_esm_build_templates_app-page_002l7yi.js +4 -0
  224. package/.next/server/chunks/ssr/node_modules_next_dist_esm_build_templates_app-page_02suzhc.js +4 -0
  225. package/.next/server/chunks/ssr/node_modules_next_dist_esm_build_templates_app-page_04x9gct.js +4 -0
  226. package/.next/server/chunks/ssr/node_modules_next_dist_esm_build_templates_app-page_0nsg22r.js +4 -0
  227. package/.next/server/chunks/tools_image-generation_service_mjs_0k_th7-._.js +3 -0
  228. package/.next/server/edge/chunks/_0e82_ds._.js +3 -0
  229. package/.next/server/edge/chunks/turbopack-node_modules_next_dist_esm_build_templates_edge-wrapper_00ue99t.js +3 -0
  230. package/.next/server/functions-config-manifest.json +11 -0
  231. package/.next/server/instrumentation/middleware-manifest.json +12 -0
  232. package/.next/server/instrumentation.js +4 -0
  233. package/.next/server/instrumentation.js.nft.json +1 -0
  234. package/.next/server/interception-route-rewrite-manifest.js +1 -0
  235. package/.next/server/middleware-build-manifest.js +22 -0
  236. package/.next/server/middleware-manifest.json +6 -0
  237. package/.next/server/next-font-manifest.js +1 -0
  238. package/.next/server/next-font-manifest.json +6 -0
  239. package/.next/server/pages/404.html +1 -0
  240. package/.next/server/pages/500.html +1 -0
  241. package/.next/server/pages-manifest.json +4 -0
  242. package/.next/server/prefetch-hints.json +1 -0
  243. package/.next/server/server-reference-manifest.js +1 -0
  244. package/.next/server/server-reference-manifest.json +5 -0
  245. package/.next/static/chunks/01xlw8hd842-c.js +1 -0
  246. package/.next/static/chunks/03edqrb4zdj~g.js +31 -0
  247. package/.next/static/chunks/03qq5fxc~pg00.js +1 -0
  248. package/.next/static/chunks/03~yq9q893hmn.js +1 -0
  249. package/.next/static/chunks/0l-_vd.~~z2bw.js +2 -0
  250. package/.next/static/chunks/0qid5lwcbx9s0.js +1 -0
  251. package/.next/static/chunks/0t.k8~x~sghva.js +4 -0
  252. package/.next/static/chunks/0tmpufzgpw2-w.js +1 -0
  253. package/.next/static/chunks/0v_ue~msygctw.js +1 -0
  254. package/.next/static/chunks/0y2l0xgouorae.css +1 -0
  255. package/.next/static/chunks/0zftsky7gte_9.js +102 -0
  256. package/.next/static/chunks/13nvdsh0e09d0.js +1 -0
  257. package/.next/static/chunks/1610ha42i.fl~.css +1 -0
  258. package/.next/static/chunks/turbopack-0mxz-ap91rcoe.js +1 -0
  259. package/.next/static/mbk_N5Gs4ZJg3lciRL6ya/_buildManifest.js +11 -0
  260. package/.next/static/mbk_N5Gs4ZJg3lciRL6ya/_clientMiddlewareManifest.js +1 -0
  261. package/.next/static/mbk_N5Gs4ZJg3lciRL6ya/_ssgManifest.js +1 -0
  262. package/.next/static/media/favicon.0x3dzn~oxb6tn.ico +0 -0
  263. package/README.md +113 -0
  264. package/THIRD_PARTY_NOTICES.md +34 -0
  265. package/bin/acp.mjs +224 -0
  266. package/dist/app/globals.css +146 -0
  267. package/dist/components/assistant-ui/acp-command-menu.d.ts +2 -0
  268. package/dist/components/assistant-ui/acp-command-menu.mjs +176 -0
  269. package/dist/components/assistant-ui/acp-elicitation-option-list.d.ts +3 -0
  270. package/dist/components/assistant-ui/acp-elicitation-option-list.mjs +157 -0
  271. package/dist/components/assistant-ui/acp-selectors.d.ts +2 -0
  272. package/dist/components/assistant-ui/acp-selectors.mjs +301 -0
  273. package/dist/components/assistant-ui/acp-tool-content.d.ts +4 -0
  274. package/dist/components/assistant-ui/acp-tool-content.mjs +127 -0
  275. package/dist/components/assistant-ui/addons/host.d.ts +4 -0
  276. package/dist/components/assistant-ui/addons/host.mjs +85 -0
  277. package/dist/components/assistant-ui/addons/image-generation-records-section.d.ts +14 -0
  278. package/dist/components/assistant-ui/addons/image-generation-records-section.mjs +116 -0
  279. package/dist/components/assistant-ui/addons/output-artifacts-section.d.ts +9 -0
  280. package/dist/components/assistant-ui/addons/output-artifacts-section.mjs +24 -0
  281. package/dist/components/assistant-ui/addons/output-artifacts.d.ts +14 -0
  282. package/dist/components/assistant-ui/addons/output-artifacts.mjs +87 -0
  283. package/dist/components/assistant-ui/addons/plan-addon.d.ts +2 -0
  284. package/dist/components/assistant-ui/addons/plan-addon.mjs +39 -0
  285. package/dist/components/assistant-ui/addons/plan-data.d.ts +5 -0
  286. package/dist/components/assistant-ui/addons/plan-data.mjs +97 -0
  287. package/dist/components/assistant-ui/addons/registry.d.ts +2 -0
  288. package/dist/components/assistant-ui/addons/registry.mjs +8 -0
  289. package/dist/components/assistant-ui/addons/types.d.ts +13 -0
  290. package/dist/components/assistant-ui/addons/types.mjs +1 -0
  291. package/dist/components/assistant-ui/attachment.d.ts +7 -0
  292. package/dist/components/assistant-ui/attachment.mjs +88 -0
  293. package/dist/components/assistant-ui/file.d.ts +37 -0
  294. package/dist/components/assistant-ui/file.mjs +107 -0
  295. package/dist/components/assistant-ui/image-generation-settings-dialog.d.ts +4 -0
  296. package/dist/components/assistant-ui/image-generation-settings-dialog.mjs +28 -0
  297. package/dist/components/assistant-ui/image.d.ts +51 -0
  298. package/dist/components/assistant-ui/image.mjs +215 -0
  299. package/dist/components/assistant-ui/markdown-text.d.ts +2 -0
  300. package/dist/components/assistant-ui/markdown-text.mjs +208 -0
  301. package/dist/components/assistant-ui/thread/composer.d.ts +27 -0
  302. package/dist/components/assistant-ui/thread/composer.mjs +15 -0
  303. package/dist/components/assistant-ui/thread/context-chips.d.ts +2 -0
  304. package/dist/components/assistant-ui/thread/context-chips.mjs +123 -0
  305. package/dist/components/assistant-ui/thread/empty-state.d.ts +9 -0
  306. package/dist/components/assistant-ui/thread/empty-state.mjs +24 -0
  307. package/dist/components/assistant-ui/thread/index.d.ts +11 -0
  308. package/dist/components/assistant-ui/thread/index.mjs +43 -0
  309. package/dist/components/assistant-ui/thread/message-list.d.ts +3 -0
  310. package/dist/components/assistant-ui/thread/message-list.mjs +16 -0
  311. package/dist/components/assistant-ui/thread/messages.d.ts +9 -0
  312. package/dist/components/assistant-ui/thread/messages.mjs +71 -0
  313. package/dist/components/assistant-ui/thread/scroll-to-bottom.d.ts +2 -0
  314. package/dist/components/assistant-ui/thread/scroll-to-bottom.mjs +8 -0
  315. package/dist/components/assistant-ui/thread-list.d.ts +2 -0
  316. package/dist/components/assistant-ui/thread-list.mjs +31 -0
  317. package/dist/components/assistant-ui/thread.d.ts +1 -0
  318. package/dist/components/assistant-ui/thread.mjs +2 -0
  319. package/dist/components/assistant-ui/threadlist-sidebar.d.ts +6 -0
  320. package/dist/components/assistant-ui/threadlist-sidebar.mjs +32 -0
  321. package/dist/components/assistant-ui/tool-fallback.d.ts +31 -0
  322. package/dist/components/assistant-ui/tool-fallback.mjs +114 -0
  323. package/dist/components/assistant-ui/tooltip-icon-button.d.ts +7 -0
  324. package/dist/components/assistant-ui/tooltip-icon-button.mjs +23 -0
  325. package/dist/components/icons/github.d.ts +3 -0
  326. package/dist/components/icons/github.mjs +4 -0
  327. package/dist/components/theme-toggle.d.ts +1 -0
  328. package/dist/components/theme-toggle.mjs +26 -0
  329. package/dist/components/tool-ui/option-list.d.ts +34 -0
  330. package/dist/components/tool-ui/option-list.mjs +163 -0
  331. package/dist/components/ui/avatar.d.ts +11 -0
  332. package/dist/components/ui/avatar.mjs +40 -0
  333. package/dist/components/ui/button.d.ts +10 -0
  334. package/dist/components/ui/button.mjs +47 -0
  335. package/dist/components/ui/collapsible.d.ts +5 -0
  336. package/dist/components/ui/collapsible.mjs +27 -0
  337. package/dist/components/ui/dialog.d.ts +17 -0
  338. package/dist/components/ui/dialog.mjs +58 -0
  339. package/dist/components/ui/input.d.ts +3 -0
  340. package/dist/components/ui/input.mjs +18 -0
  341. package/dist/components/ui/label.d.ts +4 -0
  342. package/dist/components/ui/label.mjs +20 -0
  343. package/dist/components/ui/scroll-area.d.ts +5 -0
  344. package/dist/components/ui/scroll-area.mjs +26 -0
  345. package/dist/components/ui/select.d.ts +13 -0
  346. package/dist/components/ui/select.mjs +59 -0
  347. package/dist/components/ui/separator.d.ts +4 -0
  348. package/dist/components/ui/separator.mjs +20 -0
  349. package/dist/components/ui/sheet.d.ts +14 -0
  350. package/dist/components/ui/sheet.mjs +61 -0
  351. package/dist/components/ui/sidebar.d.ts +69 -0
  352. package/dist/components/ui/sidebar.mjs +245 -0
  353. package/dist/components/ui/skeleton.d.ts +2 -0
  354. package/dist/components/ui/skeleton.mjs +18 -0
  355. package/dist/components/ui/switch.d.ts +4 -0
  356. package/dist/components/ui/switch.mjs +20 -0
  357. package/dist/components/ui/tabs.d.ts +7 -0
  358. package/dist/components/ui/tabs.mjs +32 -0
  359. package/dist/components/ui/tooltip.d.ts +7 -0
  360. package/dist/components/ui/tooltip.mjs +32 -0
  361. package/dist/hooks/use-mobile.d.ts +1 -0
  362. package/dist/hooks/use-mobile.mjs +15 -0
  363. package/dist/lib/acp2aisdk/capabilities.d.ts +6 -0
  364. package/dist/lib/acp2aisdk/capabilities.mjs +210 -0
  365. package/dist/lib/acp2aisdk/capability-cache.d.ts +17 -0
  366. package/dist/lib/acp2aisdk/capability-cache.mjs +259 -0
  367. package/dist/lib/acp2aisdk/client-context.d.ts +38 -0
  368. package/dist/lib/acp2aisdk/client-context.mjs +247 -0
  369. package/dist/lib/acp2aisdk/commands.d.ts +11 -0
  370. package/dist/lib/acp2aisdk/commands.mjs +121 -0
  371. package/dist/lib/acp2aisdk/config-options.d.ts +3 -0
  372. package/dist/lib/acp2aisdk/config-options.mjs +86 -0
  373. package/dist/lib/acp2aisdk/context.d.ts +88 -0
  374. package/dist/lib/acp2aisdk/context.mjs +33 -0
  375. package/dist/lib/acp2aisdk/default-capabilities.d.ts +275 -0
  376. package/dist/lib/acp2aisdk/default-capabilities.mjs +421 -0
  377. package/dist/lib/acp2aisdk/elicitation.d.ts +37 -0
  378. package/dist/lib/acp2aisdk/elicitation.mjs +193 -0
  379. package/dist/lib/acp2aisdk/hitl.d.ts +25 -0
  380. package/dist/lib/acp2aisdk/hitl.mjs +134 -0
  381. package/dist/lib/acp2aisdk/index.d.ts +12 -0
  382. package/dist/lib/acp2aisdk/index.mjs +182 -0
  383. package/dist/lib/acp2aisdk/mcp-servers.d.ts +17 -0
  384. package/dist/lib/acp2aisdk/mcp-servers.mjs +153 -0
  385. package/dist/lib/acp2aisdk/model-selection.d.ts +16 -0
  386. package/dist/lib/acp2aisdk/model-selection.mjs +65 -0
  387. package/dist/lib/acp2aisdk/prompt-history.d.ts +9 -0
  388. package/dist/lib/acp2aisdk/prompt-history.mjs +168 -0
  389. package/dist/lib/acp2aisdk/provider-compat.d.ts +85 -0
  390. package/dist/lib/acp2aisdk/provider-compat.mjs +501 -0
  391. package/dist/lib/acp2aisdk/provider-registry.d.ts +15 -0
  392. package/dist/lib/acp2aisdk/provider-registry.mjs +196 -0
  393. package/dist/lib/acp2aisdk/response.d.ts +3 -0
  394. package/dist/lib/acp2aisdk/response.mjs +33 -0
  395. package/dist/lib/acp2aisdk/runtime-options.d.ts +2 -0
  396. package/dist/lib/acp2aisdk/runtime-options.mjs +10 -0
  397. package/dist/lib/acp2aisdk/session-runtime.d.ts +5 -0
  398. package/dist/lib/acp2aisdk/session-runtime.mjs +186 -0
  399. package/dist/lib/acp2aisdk/session-store.d.ts +31 -0
  400. package/dist/lib/acp2aisdk/session-store.mjs +169 -0
  401. package/dist/lib/acp2aisdk/skill-command-cache.d.ts +20 -0
  402. package/dist/lib/acp2aisdk/skill-command-cache.mjs +122 -0
  403. package/dist/lib/acp2aisdk/stream-metadata.d.ts +10 -0
  404. package/dist/lib/acp2aisdk/stream-metadata.mjs +251 -0
  405. package/dist/lib/acp2aisdk/types.d.ts +129 -0
  406. package/dist/lib/acp2aisdk/types.mjs +0 -0
  407. package/dist/lib/acp2aisdk/vendor/acp-ai-provider/index.d.ts +10 -0
  408. package/dist/lib/acp2aisdk/vendor/acp-ai-provider/index.mjs +10 -0
  409. package/dist/lib/acp2aisdk/vendor/acp-ai-provider/package/index.mjs +1945 -0
  410. package/dist/lib/api/client.d.ts +93 -0
  411. package/dist/lib/api/client.mjs +199 -0
  412. package/dist/lib/api/cors.d.ts +2 -0
  413. package/dist/lib/api/cors.mjs +47 -0
  414. package/dist/lib/conversations/client-adapter.d.ts +21 -0
  415. package/dist/lib/conversations/client-adapter.mjs +329 -0
  416. package/dist/lib/conversations/message-repository.d.ts +8 -0
  417. package/dist/lib/conversations/message-repository.mjs +87 -0
  418. package/dist/lib/conversations/store.d.ts +17 -0
  419. package/dist/lib/conversations/store.mjs +678 -0
  420. package/dist/lib/conversations/types.d.ts +92 -0
  421. package/dist/lib/conversations/types.mjs +0 -0
  422. package/dist/lib/local-image-files.d.ts +5 -0
  423. package/dist/lib/local-image-files.mjs +76 -0
  424. package/dist/lib/local-image-paths.d.ts +7 -0
  425. package/dist/lib/local-image-paths.mjs +106 -0
  426. package/dist/lib/output-artifacts/workspace.d.ts +8 -0
  427. package/dist/lib/output-artifacts/workspace.mjs +174 -0
  428. package/dist/lib/provider-history/codex.d.ts +4 -0
  429. package/dist/lib/provider-history/codex.mjs +272 -0
  430. package/dist/lib/provider-history/index.d.ts +7 -0
  431. package/dist/lib/provider-history/index.mjs +88 -0
  432. package/dist/lib/provider-history/types.d.ts +31 -0
  433. package/dist/lib/provider-history/types.mjs +0 -0
  434. package/dist/lib/server-runtime.d.ts +22 -0
  435. package/dist/lib/server-runtime.mjs +78 -0
  436. package/dist/lib/url-routing.d.ts +18 -0
  437. package/dist/lib/url-routing.mjs +59 -0
  438. package/dist/lib/utils.d.ts +2 -0
  439. package/dist/lib/utils.mjs +5 -0
  440. package/dist/lib/workspace-metadata.d.ts +2 -0
  441. package/dist/lib/workspace-metadata.mjs +20 -0
  442. package/dist/public-api/react.d.ts +14 -0
  443. package/dist/public-api/react.mjs +16 -0
  444. package/dist/public-api/runtime.d.ts +8 -0
  445. package/dist/public-api/runtime.mjs +7 -0
  446. package/dist/public-api/server.d.ts +5 -0
  447. package/dist/public-api/server.mjs +4 -0
  448. package/dist/public-api/styles.css +1 -0
  449. package/dist/public-api/ui.d.ts +13 -0
  450. package/dist/public-api/ui.mjs +13 -0
  451. package/dist/tools/client-registry.d.ts +9 -0
  452. package/dist/tools/client-registry.mjs +70 -0
  453. package/dist/tools/image-generation/client.d.ts +18 -0
  454. package/dist/tools/image-generation/client.mjs +31 -0
  455. package/dist/tools/image-generation/config.d.ts +9 -0
  456. package/dist/tools/image-generation/config.example.json +14 -0
  457. package/dist/tools/image-generation/config.mjs +11 -0
  458. package/dist/tools/image-generation/mcp-server.mjs +87 -0
  459. package/dist/tools/image-generation/registry.d.ts +13 -0
  460. package/dist/tools/image-generation/registry.mjs +30 -0
  461. package/dist/tools/image-generation/server.d.ts +6 -0
  462. package/dist/tools/image-generation/server.mjs +58 -0
  463. package/dist/tools/image-generation/service.mjs +978 -0
  464. package/dist/tools/image-generation/shared.d.ts +103 -0
  465. package/dist/tools/image-generation/shared.mjs +80 -0
  466. package/dist/tools/image-generation/storage.d.ts +22 -0
  467. package/dist/tools/image-generation/storage.mjs +8 -0
  468. package/dist/tools/image-generation/ui-detail.d.ts +26 -0
  469. package/dist/tools/image-generation/ui-detail.mjs +109 -0
  470. package/dist/tools/image-generation/ui.d.ts +8 -0
  471. package/dist/tools/image-generation/ui.mjs +121 -0
  472. package/dist/tools/registry.d.ts +32 -0
  473. package/dist/tools/registry.mjs +142 -0
  474. package/dist/tools/ui-registry.d.ts +3 -0
  475. package/dist/tools/ui-registry.mjs +20 -0
  476. package/dist/tools/user-choice/client.d.ts +10 -0
  477. package/dist/tools/user-choice/client.mjs +18 -0
  478. package/dist/tools/user-choice/registry.d.ts +12 -0
  479. package/dist/tools/user-choice/registry.mjs +21 -0
  480. package/dist/tools/user-choice/server.d.ts +6 -0
  481. package/dist/tools/user-choice/server.mjs +42 -0
  482. package/dist/tools/user-choice/shared.d.ts +79 -0
  483. package/dist/tools/user-choice/shared.mjs +56 -0
  484. package/dist/tools/user-choice/store.d.ts +19 -0
  485. package/dist/tools/user-choice/store.mjs +95 -0
  486. package/dist/tools/user-choice/ui.d.ts +3 -0
  487. package/dist/tools/user-choice/ui.mjs +396 -0
  488. package/package.json +118 -0
@@ -0,0 +1,1945 @@
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
+
4
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/language-model.js
5
+ import { ClientSideConnection, ndJsonStream, PROTOCOL_VERSION } from "@agentclientprotocol/sdk";
6
+ import { spawn } from "node:child_process";
7
+ import process2 from "node:process";
8
+ import { Readable, Writable } from "node:stream";
9
+ import z from "zod";
10
+
11
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/format-tool-error.js
12
+ function normalizeToolResultBlocks(toolResult) {
13
+ // rawOutput can be an object when ACP agents report failed MCP tool calls.
14
+ if (!toolResult) return [];
15
+ if (Array.isArray(toolResult)) return toolResult;
16
+ if (typeof toolResult === "string") {
17
+ return [
18
+ {
19
+ type: "content",
20
+ content: {
21
+ type: "text",
22
+ text: toolResult
23
+ }
24
+ }
25
+ ];
26
+ }
27
+ const content = typeof toolResult === "object" ? toolResult.content : null;
28
+ if (Array.isArray(content)) {
29
+ return content.map((item) => {
30
+ if (item?.type === "content") return item;
31
+ if (item?.type === "text") {
32
+ return {
33
+ type: "content",
34
+ content: {
35
+ type: "text",
36
+ text: String(item.text ?? "")
37
+ }
38
+ };
39
+ }
40
+ return {
41
+ type: "content",
42
+ content: {
43
+ type: "text",
44
+ text: JSON.stringify(item)
45
+ }
46
+ };
47
+ });
48
+ }
49
+ return [
50
+ {
51
+ type: "content",
52
+ content: {
53
+ type: "text",
54
+ text: JSON.stringify(toolResult)
55
+ }
56
+ }
57
+ ];
58
+ }
59
+ function formatToolError(toolResult) {
60
+ if (!toolResult || toolResult.length === 0) return "Unknown tool error";
61
+ const parts = [];
62
+ for (const blk of toolResult) {
63
+ if (blk.type === "content") {
64
+ if (blk.content.type === "text") {
65
+ parts.push(blk.content.text);
66
+ }
67
+ }
68
+ }
69
+ return parts.join("\n");
70
+ }
71
+
72
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/tool-proxy/tool-proxy-host.js
73
+ import { createServer } from "node:net";
74
+
75
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/tool-proxy/json-rpc.js
76
+ function createResponse(id, result) {
77
+ return {
78
+ jsonrpc: "2.0",
79
+ id,
80
+ result
81
+ };
82
+ }
83
+ function createErrorResponse(id, code, message, data) {
84
+ const error = {
85
+ code,
86
+ message
87
+ };
88
+ if (data !== void 0) {
89
+ error.data = data;
90
+ }
91
+ return {
92
+ jsonrpc: "2.0",
93
+ id,
94
+ error
95
+ };
96
+ }
97
+ function parseMessage(line) {
98
+ try {
99
+ const parsed = JSON.parse(line);
100
+ if (parsed.jsonrpc !== "2.0") return null;
101
+ return parsed;
102
+ } catch {
103
+ return null;
104
+ }
105
+ }
106
+ function serializeMessage(message) {
107
+ return JSON.stringify(message);
108
+ }
109
+
110
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/tool-proxy/types.js
111
+ var JsonRpcErrorCode = {
112
+ PARSE_ERROR: -32700,
113
+ INVALID_REQUEST: -32600,
114
+ METHOD_NOT_FOUND: -32601,
115
+ INVALID_PARAMS: -32602,
116
+ INTERNAL_ERROR: -32603
117
+ };
118
+ var ProxyMethod = {
119
+ // Host -> Proxy
120
+ REGISTER_TOOLS: "registerTools",
121
+ // Proxy -> Host
122
+ CALL_HANDLER: "callHandler"
123
+ };
124
+
125
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/tool-proxy/tool-proxy-host.js
126
+ import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
127
+
128
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/tool-proxy/tool-proxy-runtime.js
129
+ var RUNTIME_CODE = `
130
+ /* MCP Protocol Version 2024-11-05 */
131
+ const isDeno=typeof Deno!=="undefined",MCP_VER="2024-11-05";
132
+ let tools=[],host=null,pending=new Map,buf="",hbuf="",rid=0;
133
+ const env=k=>isDeno?Deno.env.get(k):process.env[k];
134
+ const write=async m=>{
135
+ const s=JSON.stringify(m)+"\\n";
136
+ if(isDeno)await Deno.stdout.write(new TextEncoder().encode(s));
137
+ else process.stdout.write(s);
138
+ };
139
+ const send=(id,r,e)=>write({jsonrpc:"2.0",id,...(e?{error:e}:{result:r})});
140
+ const hostReq=(m,p)=>new Promise((res,rej)=>{
141
+ const id="r-"+ ++rid;
142
+ const s=JSON.stringify({jsonrpc:"2.0",id,method:m,params:p})+"\\n";
143
+ if(isDeno)host.write(new TextEncoder().encode(s));
144
+ else host.write(s);
145
+ const t=setTimeout(()=>{pending.delete(id);rej(new Error("timeout"))},30000);
146
+ pending.set(id,{resolve:v=>{clearTimeout(t);res(v)},reject:e=>{clearTimeout(t);rej(e)}});
147
+ });
148
+ const init=async()=>{
149
+ const p=parseInt(env("ACP_TOOL_PROXY_PORT")||"0",10);
150
+ if(p){
151
+ if(isDeno){
152
+ host=await Deno.connect({hostname:"127.0.0.1",port:p});
153
+ (async()=>{
154
+ const d=new TextDecoder(),b=new Uint8Array(65536);
155
+ while(true){const n=await host.read(b);if(!n)break;
156
+ hbuf+=d.decode(b.subarray(0,n));let ls=hbuf.split("\\n");hbuf=ls.pop();
157
+ for(let l of ls)if(l.trim())onHostMsg(l)}})();
158
+ }else{
159
+ host=require("net").createConnection({host:"127.0.0.1",port:p});
160
+ await new Promise(r=>host.on("connect",r));
161
+ host.on("data",d=>{hbuf+=d;let ls=hbuf.split("\\n");hbuf=ls.pop();
162
+ for(let l of ls)if(l.trim())onHostMsg(l)});
163
+ }
164
+ try{tools=await hostReq("getTools")}catch(e){
165
+ const m="Failed to get tools: "+e.message+"\\n";
166
+ if(isDeno)Deno.stderr.write(new TextEncoder().encode(m));
167
+ else process.stderr.write(m);
168
+ }
169
+ }
170
+ };
171
+ const onHostMsg=l=>{try{let r=JSON.parse(l),h=pending.get(r.id);
172
+ if(h){pending.delete(r.id);r.error?h.reject(new Error(r.error.message)):h.resolve(r.result)}}catch{}};
173
+ const handle=async l=>{let m;try{m=JSON.parse(l)}catch{return}if(m.jsonrpc!=="2.0")return;
174
+ if(m.method==="initialize")send(m.id,{protocolVersion:MCP_VER,capabilities:{tools:{}},serverInfo:{name:"proxy",version:"1.0"}});
175
+ else if(m.method==="notifications/initialized");
176
+ else if(m.method==="tools/list")send(m.id,{tools:tools.map(t=>({name:t.name,description:t.description,inputSchema:t.inputSchema}))});
177
+ else if(m.method==="tools/call"){let p=m.params,t=tools.find(x=>x.name===p.name);
178
+ if(!t)send(m.id,null,{code:-32601,message:"Not found"});
179
+ else try{let r=await hostReq("callHandler",{name:p.name,args:p.arguments||{}});send(m.id,r)}
180
+ catch(e){send(m.id,{content:[{type:"text",text:"Error: "+e.message}],isError:true})}}
181
+ else send(m.id,null,{code:-32601,message:"Unknown"});
182
+ };
183
+ init().then(async()=>{
184
+ if(isDeno){
185
+ const d=new TextDecoder(),b=new Uint8Array(65536);
186
+ while(true){const n=await Deno.stdin.read(b);if(!n)break;
187
+ buf+=d.decode(b.subarray(0,n));let ls=buf.split("\\n");buf=ls.pop();for(let l of ls)if(l.trim())handle(l)}
188
+ }else{
189
+ process.stdin.setEncoding("utf8");
190
+ process.stdin.on("data",c=>{buf+=c;let ls=buf.split("\\n");buf=ls.pop();for(let l of ls)if(l.trim())handle(l)});
191
+ }
192
+ });
193
+ `.trim().replace(/\n/g, "");
194
+
195
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/tool-proxy/tool-proxy-host.js
196
+ var ToolProxyHost = class {
197
+ server = null;
198
+ connections = [];
199
+ tools = /* @__PURE__ */ new Map();
200
+ serverName;
201
+ port = 0;
202
+ constructor(name = "acp-tool-proxy") {
203
+ this.serverName = name;
204
+ }
205
+ /**
206
+ * Register an AI SDK tool to be exposed through the proxy
207
+ */
208
+ registerTool(name, tool2) {
209
+ this.tools.set(name, tool2);
210
+ }
211
+ /**
212
+ * Register multiple tools at once
213
+ */
214
+ registerTools(tools) {
215
+ for (const [name, tool2] of Object.entries(tools)) {
216
+ this.registerTool(name, tool2);
217
+ }
218
+ }
219
+ /**
220
+ * Get tool definitions for the runtime
221
+ */
222
+ getToolDefinitions() {
223
+ const definitions = [];
224
+ for (const [name, tool2] of this.tools.entries()) {
225
+ definitions.push({
226
+ name,
227
+ description: tool2.description || `Tool: ${name}`,
228
+ // inputSchema from Tool can be Zod or JSON schema, cast to JSON schema format
229
+ inputSchema: tool2.inputSchema || {
230
+ type: "object",
231
+ properties: {}
232
+ }
233
+ });
234
+ }
235
+ return definitions;
236
+ }
237
+ /**
238
+ * Start TCP server and return MCP server config for ACP
239
+ */
240
+ async start() {
241
+ if (!this.server) {
242
+ await this.startServer();
243
+ }
244
+ return this.getServerConfig();
245
+ }
246
+ /**
247
+ * Get MCP server configuration
248
+ */
249
+ getServerConfig() {
250
+ return {
251
+ name: this.serverName,
252
+ command: "node",
253
+ args: [
254
+ "-e",
255
+ RUNTIME_CODE
256
+ ],
257
+ env: [
258
+ {
259
+ name: "ACP_TOOL_PROXY_PORT",
260
+ value: String(this.port)
261
+ }
262
+ ]
263
+ };
264
+ }
265
+ /**
266
+ * Start TCP server to receive tool execution requests
267
+ */
268
+ startServer() {
269
+ return new Promise((resolve, reject) => {
270
+ this.server = createServer((socket) => {
271
+ this.handleConnection(socket);
272
+ });
273
+ this.server.on("error", (err) => {
274
+ reject(err);
275
+ });
276
+ this.server.listen(0, "127.0.0.1", () => {
277
+ const address = this.server.address();
278
+ if (typeof address === "object" && address) {
279
+ this.port = address.port;
280
+ resolve();
281
+ } else {
282
+ reject(new Error("Failed to get server address"));
283
+ }
284
+ });
285
+ });
286
+ }
287
+ /**
288
+ * Handle incoming connection from runtime
289
+ */
290
+ handleConnection(socket) {
291
+ this.connections.push(socket);
292
+ let buffer = "";
293
+ socket.on("data", (data) => {
294
+ buffer += data.toString();
295
+ const lines = buffer.split("\n");
296
+ buffer = lines.pop() || "";
297
+ for (const line of lines) {
298
+ if (!line.trim()) continue;
299
+ const message = parseMessage(line);
300
+ if (!message) continue;
301
+ if ("method" in message) {
302
+ this.handleRequest(socket, message).catch((err) => console.error("[ToolProxy] Error handling request:", err));
303
+ }
304
+ }
305
+ });
306
+ socket.on("close", () => {
307
+ this.connections = this.connections.filter((c) => c !== socket);
308
+ });
309
+ socket.on("error", (err) => {
310
+ console.error("[ToolProxy] Socket error:", err);
311
+ });
312
+ }
313
+ /**
314
+ * Handle JSON-RPC request from runtime
315
+ */
316
+ async handleRequest(socket, request) {
317
+ try {
318
+ if (request.method === ProxyMethod.CALL_HANDLER) {
319
+ const params = request.params;
320
+ const tool2 = this.tools.get(params.name);
321
+ if (!tool2) {
322
+ this.sendResponse(socket, createErrorResponse(request.id, JsonRpcErrorCode.METHOD_NOT_FOUND, `Tool not found: ${params.name}`));
323
+ return;
324
+ }
325
+ if (!tool2.execute) {
326
+ const clientToolResult = {
327
+ content: [
328
+ {
329
+ type: "text",
330
+ text: JSON.stringify({
331
+ isClientTool: true,
332
+ toolName: params.name,
333
+ args: params.args
334
+ })
335
+ }
336
+ ],
337
+ isError: false
338
+ };
339
+ this.sendResponse(socket, createResponse(request.id, clientToolResult));
340
+ return;
341
+ }
342
+ const result = await tool2.execute(params.args, {
343
+ toolCallId: params.name,
344
+ messages: []
345
+ });
346
+ let toolResult;
347
+ const parseResult = CallToolResultSchema.safeParse(result);
348
+ if (parseResult.success) {
349
+ toolResult = parseResult.data;
350
+ } else {
351
+ toolResult = {
352
+ content: [
353
+ {
354
+ type: "text",
355
+ text: typeof result === "string" ? result : JSON.stringify(result)
356
+ }
357
+ ]
358
+ };
359
+ }
360
+ this.sendResponse(socket, createResponse(request.id, toolResult));
361
+ } else if (request.method === "getTools") {
362
+ const definitions = this.getToolDefinitions();
363
+ this.sendResponse(socket, createResponse(request.id, definitions));
364
+ } else {
365
+ this.sendResponse(socket, createErrorResponse(request.id, JsonRpcErrorCode.METHOD_NOT_FOUND, `Unknown method: ${request.method}`));
366
+ }
367
+ } catch (error) {
368
+ this.sendResponse(socket, createErrorResponse(request.id, JsonRpcErrorCode.INTERNAL_ERROR, error instanceof Error ? error.message : String(error)));
369
+ }
370
+ }
371
+ /**
372
+ * Send response to runtime
373
+ */
374
+ sendResponse(socket, response) {
375
+ socket.write(serializeMessage(response) + "\n");
376
+ }
377
+ /**
378
+ * Stop the TCP server
379
+ */
380
+ stop() {
381
+ for (const socket of this.connections) {
382
+ socket.destroy();
383
+ }
384
+ this.connections = [];
385
+ if (this.server) {
386
+ this.server.close();
387
+ this.server = null;
388
+ }
389
+ this.port = 0;
390
+ }
391
+ };
392
+
393
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/acp-tool.js
394
+ import { jsonSchema, tool } from "ai";
395
+ var ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME = "acp.acp_provider_agent_dynamic_tool";
396
+ var executeRegistry = /* @__PURE__ */ new Map();
397
+ function acpTools(tools) {
398
+ for (const [name, toolDef] of Object.entries(tools)) {
399
+ executeRegistry.set(name, toolDef.execute);
400
+ }
401
+ return {
402
+ ...tools,
403
+ ...getACPDynamicTool()
404
+ };
405
+ }
406
+ function getACPDynamicTool() {
407
+ return {
408
+ [ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME]: tool({
409
+ type: "provider",
410
+ id: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME,
411
+ args: {},
412
+ inputSchema: jsonSchema({})
413
+ })
414
+ };
415
+ }
416
+ function getExecuteByName(name) {
417
+ return executeRegistry.get(name);
418
+ }
419
+ function hasRegisteredExecute(name) {
420
+ return executeRegistry.has(name);
421
+ }
422
+
423
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/convert-utils.js
424
+ import { convertUint8ArrayToBase64 } from "@ai-sdk/provider-utils";
425
+
426
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/utils.js
427
+ function extractBase64Data(data) {
428
+ return data.includes(",") ? data.split(",")[1] : data;
429
+ }
430
+
431
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/convert-utils.js
432
+ import { asSchema } from "ai";
433
+ var ROLE_PREFIXES = {
434
+ system: "System: ",
435
+ assistant: "Assistant: ",
436
+ tool: "Result: "
437
+ };
438
+ function getRolePrefix(role) {
439
+ return ROLE_PREFIXES[role] || "";
440
+ }
441
+ function getMediaType(mimeType) {
442
+ if (mimeType.startsWith("image/")) return "image";
443
+ if (mimeType.startsWith("audio/")) return "audio";
444
+ return null;
445
+ }
446
+ function convertAiSdkMessagesToAcp(options, isFreshSession, jsonSchemaPrompt) {
447
+ const messages = !isFreshSession ? options.prompt.filter((m) => m.role === "user").slice(-1) : options.prompt;
448
+ const contentBlocks = [];
449
+ if (jsonSchemaPrompt) {
450
+ contentBlocks.push({
451
+ type: "text",
452
+ text: jsonSchemaPrompt
453
+ });
454
+ }
455
+ for (const msg of messages) {
456
+ const prefix = getRolePrefix(msg.role);
457
+ if (typeof msg.content === "string") {
458
+ contentBlocks.push({
459
+ type: "text",
460
+ text: `${prefix}${msg.content} `
461
+ });
462
+ continue;
463
+ }
464
+ if (!Array.isArray(msg.content)) continue;
465
+ let needsPrefix = true;
466
+ for (const part of msg.content) {
467
+ const currentPrefix = needsPrefix ? prefix : "";
468
+ if (part.type === "text") {
469
+ contentBlocks.push({
470
+ type: "text",
471
+ text: currentPrefix + part.text
472
+ });
473
+ needsPrefix = false;
474
+ }
475
+ if (part.type === "tool-call") {
476
+ const toolCallText = `[Tool Call: ${part.toolName}(${JSON.stringify(part.input)})]`;
477
+ contentBlocks.push({
478
+ type: "text",
479
+ text: currentPrefix + toolCallText
480
+ });
481
+ needsPrefix = false;
482
+ }
483
+ if (part.type === "tool-result") {
484
+ const resultData = part.result ?? part.output;
485
+ const resultText = JSON.stringify(resultData) ?? "null";
486
+ contentBlocks.push({
487
+ type: "text",
488
+ text: currentPrefix + resultText
489
+ });
490
+ needsPrefix = false;
491
+ }
492
+ if (part.type === "file") {
493
+ const mediaType = getMediaType(part.mediaType);
494
+ if (mediaType) {
495
+ let base64Data;
496
+ if (typeof part.data === "string") {
497
+ base64Data = extractBase64Data(part.data);
498
+ } else if (part.data instanceof Uint8Array) {
499
+ base64Data = convertUint8ArrayToBase64(part.data);
500
+ }
501
+ if (base64Data !== void 0) {
502
+ contentBlocks.push({
503
+ type: mediaType,
504
+ mimeType: part.mediaType,
505
+ data: base64Data
506
+ });
507
+ }
508
+ }
509
+ }
510
+ }
511
+ }
512
+ return contentBlocks;
513
+ }
514
+ function extractACPTools(tools, prepared = true) {
515
+ const acpTools2 = [];
516
+ if (!tools) {
517
+ return acpTools2;
518
+ }
519
+ const toolsArray = Array.isArray(tools) ? tools : Object.entries(tools).map(([name, tool2]) => ({
520
+ type: "function",
521
+ name,
522
+ ...tool2
523
+ }));
524
+ for (const t of toolsArray) {
525
+ if (t.type === "function") {
526
+ const toolWithSchema = t;
527
+ const toolInputSchema = toolWithSchema.inputSchema;
528
+ if (hasRegisteredExecute(t.name) && toolInputSchema) {
529
+ const execute = getExecuteByName(t.name);
530
+ acpTools2.push({
531
+ ...t,
532
+ name: t.name,
533
+ inputSchema: prepared ? toolInputSchema : asSchema(toolInputSchema).jsonSchema,
534
+ execute
535
+ });
536
+ }
537
+ }
538
+ }
539
+ return acpTools2;
540
+ }
541
+
542
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/lazy-auth.js
543
+ var ACP_AUTH_REQUIRED_ERROR_CODE = -32e3;
544
+ var ACP_AUTH_REQUIRED_MESSAGE = "authentication required";
545
+ function isAuthRequiredError(error) {
546
+ if (error && typeof error === "object" && "code" in error) {
547
+ const code = error.code;
548
+ if (code === ACP_AUTH_REQUIRED_ERROR_CODE) {
549
+ return true;
550
+ }
551
+ }
552
+ if (error && typeof error === "object" && "message" in error) {
553
+ const message = String(error.message ?? "");
554
+ return message.toLowerCase().includes(ACP_AUTH_REQUIRED_MESSAGE);
555
+ }
556
+ return false;
557
+ }
558
+
559
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/debug.js
560
+ import { appendFileSync, mkdtempSync } from "node:fs";
561
+ import { tmpdir } from "node:os";
562
+ import { join } from "node:path";
563
+ import process from "node:process";
564
+ var ACPDebugLogger = class {
565
+ agentMessageLogFilePath = null;
566
+ isEnabled() {
567
+ const value = process.env.ACP_AI_PROVIDER_DEBUG;
568
+ return value === "1" || value === "true";
569
+ }
570
+ log(...args) {
571
+ if (!this.isEnabled()) {
572
+ return;
573
+ }
574
+ console.log(...args);
575
+ }
576
+ ensureAgentMessageLogFile() {
577
+ if (this.agentMessageLogFilePath || !this.isEnabled()) {
578
+ return;
579
+ }
580
+ const debugDir = mkdtempSync(join(tmpdir(), "acp-ai-provider-"));
581
+ this.agentMessageLogFilePath = join(debugDir, "agent-messages.ndjson");
582
+ this.log(`[acp-ai-provider] Agent message log: ${this.agentMessageLogFilePath}`);
583
+ }
584
+ appendAgentMessage(notification) {
585
+ this.appendLogEntry({
586
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
587
+ kind: "notification",
588
+ notification
589
+ });
590
+ }
591
+ appendPromptResponse(response) {
592
+ this.appendLogEntry({
593
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
594
+ kind: "prompt-response",
595
+ response
596
+ });
597
+ }
598
+ appendPromptError(error) {
599
+ this.appendLogEntry({
600
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
601
+ kind: "prompt-error",
602
+ error: this.serializeError(error)
603
+ });
604
+ }
605
+ appendLogEntry(entry) {
606
+ this.ensureAgentMessageLogFile();
607
+ if (!this.agentMessageLogFilePath) {
608
+ return;
609
+ }
610
+ try {
611
+ appendFileSync(this.agentMessageLogFilePath, `${JSON.stringify(entry)}
612
+ `);
613
+ } catch {
614
+ }
615
+ }
616
+ serializeError(error) {
617
+ if (error instanceof Error) {
618
+ return {
619
+ name: error.name,
620
+ message: error.message,
621
+ stack: error.stack,
622
+ ...typeof error.code !== "undefined" ? {
623
+ code: error.code
624
+ } : {},
625
+ ...typeof error.data !== "undefined" ? {
626
+ data: error.data
627
+ } : {}
628
+ };
629
+ }
630
+ return error;
631
+ }
632
+ };
633
+
634
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/json-output.js
635
+ var OPENING_FENCE_PATTERN = /^```(?:\w+)?\s*\n/;
636
+ var CLOSING_FENCE_PATTERN = /\n?```\s*$/;
637
+ var SUFFIX_BUFFER_SIZE = 12;
638
+ function isJsonResponseFormat(responseFormat) {
639
+ return responseFormat?.type === "json";
640
+ }
641
+ function buildJsonSchemaPrompt(responseFormat) {
642
+ const parts = [];
643
+ parts.push("[Structured Output Instruction]", "You MUST respond with a single valid JSON value.", "Do NOT wrap JSON in markdown fences (no ```json blocks).", "Do NOT add explanations, comments, or any other text before or after the JSON.", "Your entire response must be ONLY the JSON value, nothing else.");
644
+ if (responseFormat.name) {
645
+ parts.push(`Output name: ${responseFormat.name}`);
646
+ }
647
+ if (responseFormat.description) {
648
+ parts.push(`Output description: ${responseFormat.description}`);
649
+ }
650
+ if (responseFormat.schema) {
651
+ parts.push("The JSON value MUST conform to this JSON Schema:", JSON.stringify(responseFormat.schema, null, 2));
652
+ }
653
+ parts.push("[End Structured Output Instruction]");
654
+ return parts.join("\n");
655
+ }
656
+ function stripMarkdownFences(text) {
657
+ const trimmed = text.trim();
658
+ const fenceMatch = trimmed.match(/^```(?:\w+)?\s*\n?([\s\S]*?)\n?\s*```\s*$/);
659
+ if (fenceMatch) {
660
+ return fenceMatch[1].trim();
661
+ }
662
+ return trimmed;
663
+ }
664
+ function emitTextDelta(controller, id, delta) {
665
+ if (!delta) {
666
+ return;
667
+ }
668
+ controller.enqueue({
669
+ type: "text-delta",
670
+ id,
671
+ delta
672
+ });
673
+ }
674
+ function finalizeBufferedText(block) {
675
+ if (block.prefixStripped) {
676
+ return block.buffer.replace(CLOSING_FENCE_PATTERN, "").trimEnd();
677
+ }
678
+ return stripMarkdownFences(block.buffer);
679
+ }
680
+ function createJsonCleanupTransform() {
681
+ const textBlocks = {};
682
+ return new TransformStream({
683
+ transform(chunk, controller) {
684
+ if (chunk.type === "text-start") {
685
+ textBlocks[chunk.id] = {
686
+ startEvent: chunk,
687
+ phase: "prefix",
688
+ buffer: "",
689
+ prefixStripped: false
690
+ };
691
+ return;
692
+ }
693
+ if (chunk.type === "text-delta") {
694
+ const block = textBlocks[chunk.id];
695
+ if (!block) {
696
+ controller.enqueue(chunk);
697
+ return;
698
+ }
699
+ block.buffer += chunk.delta;
700
+ if (block.phase === "prefix") {
701
+ if (block.buffer.length > 0 && !block.buffer.startsWith("`")) {
702
+ block.phase = "streaming";
703
+ controller.enqueue(block.startEvent);
704
+ } else if (block.buffer.startsWith("```")) {
705
+ if (block.buffer.includes("\n")) {
706
+ const prefixMatch = block.buffer.match(OPENING_FENCE_PATTERN);
707
+ block.phase = "streaming";
708
+ if (prefixMatch) {
709
+ block.buffer = block.buffer.slice(prefixMatch[0].length);
710
+ block.prefixStripped = true;
711
+ }
712
+ controller.enqueue(block.startEvent);
713
+ }
714
+ } else if (block.buffer.length >= 3 && !block.buffer.startsWith("```")) {
715
+ block.phase = "streaming";
716
+ controller.enqueue(block.startEvent);
717
+ }
718
+ }
719
+ if (block.phase === "streaming" && block.buffer.length > SUFFIX_BUFFER_SIZE) {
720
+ const toStream = block.buffer.slice(0, -SUFFIX_BUFFER_SIZE);
721
+ block.buffer = block.buffer.slice(-SUFFIX_BUFFER_SIZE);
722
+ emitTextDelta(controller, chunk.id, toStream);
723
+ }
724
+ return;
725
+ }
726
+ if (chunk.type === "text-end") {
727
+ const block = textBlocks[chunk.id];
728
+ if (!block) {
729
+ controller.enqueue(chunk);
730
+ return;
731
+ }
732
+ if (block.phase === "prefix") {
733
+ controller.enqueue(block.startEvent);
734
+ }
735
+ emitTextDelta(controller, chunk.id, finalizeBufferedText(block));
736
+ controller.enqueue(chunk);
737
+ delete textBlocks[chunk.id];
738
+ return;
739
+ }
740
+ controller.enqueue(chunk);
741
+ },
742
+ flush(controller) {
743
+ for (const [id, block] of Object.entries(textBlocks)) {
744
+ if (block.phase === "prefix") {
745
+ controller.enqueue(block.startEvent);
746
+ }
747
+ emitTextDelta(controller, id, finalizeBufferedText(block));
748
+ }
749
+ }
750
+ });
751
+ }
752
+
753
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/language-model.js
754
+ function getACPResponse(response) {
755
+ return {
756
+ acp: JSON.parse(JSON.stringify(response))
757
+ };
758
+ }
759
+ function mapACPStopReasonToAISDK(stopReason) {
760
+ switch (stopReason) {
761
+ case "end_turn":
762
+ return "stop";
763
+ case "max_tokens":
764
+ case "max_turn_requests":
765
+ return "length";
766
+ case "cancelled":
767
+ return "other";
768
+ default:
769
+ return "other";
770
+ }
771
+ }
772
+ function toCatchableError(error, stderrText) {
773
+ if (error !== null && typeof error === "object" && "code" in error && "message" in error && typeof error.code === "number" && typeof error.message === "string") {
774
+ const jsonRpcError = error;
775
+ const err2 = new Error(jsonRpcError.message);
776
+ err2.name = "ACPError";
777
+ err2.code = jsonRpcError.code;
778
+ err2.data = jsonRpcError.data;
779
+ if (stderrText) {
780
+ err2.message = `${err2.message}
781
+ [agent stderr]
782
+ ${stderrText}`;
783
+ }
784
+ return err2;
785
+ }
786
+ if (error instanceof Error) {
787
+ if (stderrText) {
788
+ error.message = `${error.message}
789
+ [agent stderr]
790
+ ${stderrText}`;
791
+ }
792
+ return error;
793
+ }
794
+ const err = new Error(String(error));
795
+ if (stderrText) {
796
+ err.message = `${err.message}
797
+ [agent stderr]
798
+ ${stderrText}`;
799
+ }
800
+ return err;
801
+ }
802
+ var ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2 = "acp.acp_provider_agent_dynamic_tool";
803
+ var providerAgentDynamicToolSchema = z.object({
804
+ toolCallId: z.string().describe("The unique ID of the tool call."),
805
+ toolName: z.string().describe("The name of the tool being called."),
806
+ args: z.record(z.unknown()).describe("The input arguments for the tool call.")
807
+ });
808
+ var ACPAISDKClient = class {
809
+ onSessionUpdateCallback;
810
+ onPermissionRequestCallback;
811
+ setSessionUpdateHandler(handler) {
812
+ this.onSessionUpdateCallback = handler;
813
+ }
814
+ setPermissionRequestHandler(handler) {
815
+ this.onPermissionRequestCallback = handler;
816
+ }
817
+ sessionUpdate(params) {
818
+ if (this.onSessionUpdateCallback) {
819
+ this.onSessionUpdateCallback(params);
820
+ }
821
+ return Promise.resolve();
822
+ }
823
+ async requestPermission(params) {
824
+ if (this.onPermissionRequestCallback) {
825
+ return await this.onPermissionRequestCallback(params);
826
+ }
827
+ return {
828
+ outcome: {
829
+ outcome: "selected",
830
+ optionId: params.options[0]?.optionId || "allow"
831
+ }
832
+ };
833
+ }
834
+ writeTextFile(_params) {
835
+ throw new Error("File operations not implemented in language model client");
836
+ }
837
+ readTextFile(_params) {
838
+ throw new Error("File operations not implemented in language model client");
839
+ }
840
+ };
841
+ var ACPLanguageModel = class {
842
+ specificationVersion = "v3";
843
+ provider = "acp";
844
+ modelId;
845
+ modeId;
846
+ supportedUrls = {};
847
+ config;
848
+ agentProcess = null;
849
+ connection = null;
850
+ sessionId = null;
851
+ sessionResponse = null;
852
+ client = null;
853
+ currentModelId = null;
854
+ currentModeId = null;
855
+ isFreshSession = true;
856
+ // Captured stderr output from the agent process.
857
+ stderrChunks = [];
858
+ // State for managing stream conversion
859
+ textBlockIndex = 0;
860
+ thinkBlockIndex = 0;
861
+ currentTextId = null;
862
+ currentThinkingId = null;
863
+ toolCallsMap = /* @__PURE__ */ new Map();
864
+ // Tool proxy for host-side tool execution
865
+ toolProxyHost = null;
866
+ // Client tool interrupt mechanism
867
+ clientToolAbort = null;
868
+ debug = new ACPDebugLogger();
869
+ availableAuthMethodIds = [];
870
+ constructor(modelId, modeId, config) {
871
+ this.modelId = modelId;
872
+ this.modeId = modeId;
873
+ this.config = config;
874
+ this.debug.ensureAgentMessageLogFile();
875
+ }
876
+ /**
877
+ * Resets the internal state used for stream conversion.
878
+ */
879
+ resetStreamState() {
880
+ this.textBlockIndex = 0;
881
+ this.thinkBlockIndex = 0;
882
+ this.currentTextId = null;
883
+ this.currentThinkingId = null;
884
+ this.toolCallsMap.clear();
885
+ this.clientToolAbort = null;
886
+ }
887
+ hasToolInput(input) {
888
+ if (input === null || input === void 0) {
889
+ return false;
890
+ }
891
+ if (typeof input === "object") {
892
+ return Object.keys(input).length > 0;
893
+ }
894
+ if (typeof input === "string") {
895
+ return input.length > 0;
896
+ }
897
+ return true;
898
+ }
899
+ normalizeToolInput(input) {
900
+ return input ?? {};
901
+ }
902
+ /**
903
+ * Parses a 'tool_call' notification update into a structured object.
904
+ * Note: We only use rawInput for tool input (content is for UI display).
905
+ */
906
+ parseToolCall(update) {
907
+ if (update.sessionUpdate !== "tool_call") {
908
+ throw new Error("Invalid update type for parseToolCall");
909
+ }
910
+ const toolCallId = update.toolCallId;
911
+ const toolName = update.title || update.toolCallId;
912
+ const toolInput = update.rawInput ?? {};
913
+ return {
914
+ toolCallId,
915
+ toolName,
916
+ toolInput
917
+ };
918
+ }
919
+ /**
920
+ * Parses a 'tool_call_update' notification update into a structured object.
921
+ * Note: We only use rawOutput for tool result here (content is for UI display).
922
+ * rawInput is handled in handleStreamNotification when emitting tool-call args.
923
+ */
924
+ parseToolResult(update) {
925
+ if (update.sessionUpdate !== "tool_call_update") {
926
+ throw new Error("Invalid update type for parseToolResult");
927
+ }
928
+ const toolCallId = update.toolCallId;
929
+ const toolName = update.title || update.toolCallId;
930
+ const toolResult = update.rawOutput ?? update.content ?? null;
931
+ const isError = update.status === "failed";
932
+ return {
933
+ toolCallId,
934
+ toolName,
935
+ toolResult,
936
+ isError,
937
+ status: update.status
938
+ };
939
+ }
940
+ /**
941
+ * Checks if a tool result is from a client-side tool (no execute function).
942
+ * Client tools return a special response with `isClientTool: true`.
943
+ * Handles both MCP format (type: "text") and ACP ToolCallContent format (type: "content").
944
+ */
945
+ isClientToolResult(toolResult) {
946
+ if (!Array.isArray(toolResult) || toolResult.length === 0) {
947
+ return {
948
+ isClientTool: false
949
+ };
950
+ }
951
+ const content = toolResult[0];
952
+ if (!content?.type) {
953
+ return {
954
+ isClientTool: false
955
+ };
956
+ }
957
+ const textContent = content.type === "text" && typeof content.text === "string" ? content.text : content.type === "content" && content.content?.type === "text" ? content.content.text : void 0;
958
+ if (!textContent) {
959
+ return {
960
+ isClientTool: false
961
+ };
962
+ }
963
+ try {
964
+ const parsed = JSON.parse(textContent);
965
+ if (parsed.isClientTool === true) {
966
+ return {
967
+ isClientTool: true,
968
+ toolName: parsed.toolName,
969
+ args: parsed.args
970
+ };
971
+ }
972
+ } catch {
973
+ }
974
+ return {
975
+ isClientTool: false
976
+ };
977
+ }
978
+ /**
979
+ * Converts AI SDK prompt messages into ACP ContentBlock objects.
980
+ * When session exists, only extracts the last user message (history is in session).
981
+ * Prefixes text with role since ACP ContentBlock has no role field.
982
+ */
983
+ /**
984
+ * Ensures the ACP agent process is running and a session is established.
985
+ * @param acpTools - Tools from streamText options to proxy
986
+ */
987
+ /**
988
+ * Connects to the ACP agent process and initializes the protocol connection.
989
+ * Does NOT start a session.
990
+ */
991
+ async connectClient() {
992
+ this.debug.ensureAgentMessageLogFile();
993
+ if (this.connection) {
994
+ return;
995
+ }
996
+ if (!this.agentProcess) {
997
+ const sessionCwd = this.config.session?.cwd || (typeof process2.cwd === "function" ? process2.cwd() : "/");
998
+ this.agentProcess = spawn(this.config.command, this.config.args ?? [], {
999
+ stdio: [
1000
+ "pipe",
1001
+ "pipe",
1002
+ "pipe"
1003
+ ],
1004
+ env: {
1005
+ ...process2.env,
1006
+ ...this.config.env
1007
+ },
1008
+ cwd: sessionCwd,
1009
+ // Windows GUI hosts (e.g. Electron, /SUBSYSTEM:WINDOWS) have no parent console.
1010
+ // `windowsHide: true` prevents CreateProcess from showing an auto-created console window.
1011
+ // Ref: https://github.com/nodejs/node/issues/21825
1012
+ ...process2.platform === "win32" ? {
1013
+ windowsHide: true
1014
+ } : {}
1015
+ });
1016
+ if (!this.agentProcess.stdout || !this.agentProcess.stdin) {
1017
+ throw new Error("Failed to spawn agent process with stdio");
1018
+ }
1019
+ this.stderrChunks = [];
1020
+ this.agentProcess.stderr?.on("data", (chunk) => {
1021
+ const text = new TextDecoder().decode(chunk);
1022
+ this.stderrChunks.push(text);
1023
+ process2.stderr.write(chunk);
1024
+ });
1025
+ const input = Writable.toWeb(this.agentProcess.stdin);
1026
+ const output = Readable.toWeb(this.agentProcess.stdout);
1027
+ this.client = new ACPAISDKClient();
1028
+ this.connection = new ClientSideConnection(() => this.client, ndJsonStream(input, output));
1029
+ }
1030
+ if (!this.connection) {
1031
+ throw new Error("Connection not initialized");
1032
+ }
1033
+ const initConfig = {
1034
+ ...this.config.initialize,
1035
+ protocolVersion: this.config.initialize?.protocolVersion ?? PROTOCOL_VERSION,
1036
+ clientCapabilities: this.config.initialize?.clientCapabilities ?? {
1037
+ fs: {
1038
+ readTextFile: false,
1039
+ writeTextFile: false
1040
+ },
1041
+ terminal: false
1042
+ }
1043
+ };
1044
+ try {
1045
+ const initResult = await this.connection.initialize(initConfig);
1046
+ const authMethods = initResult.authMethods ?? [];
1047
+ this.availableAuthMethodIds = authMethods.map((a) => a.id);
1048
+ if (authMethods.length > 0) {
1049
+ const configuredAuthMethodId = this.config.authMethodId;
1050
+ if (!configuredAuthMethodId) {
1051
+ const defaultAuthMethodId = this.availableAuthMethodIds[0];
1052
+ console.log(`[acp-ai-provider] Warning: authMethodId is not configured. Lazy auth will default to the first auth method "${defaultAuthMethodId}".`, JSON.stringify(authMethods, null, 2));
1053
+ } else if (!this.availableAuthMethodIds.includes(configuredAuthMethodId)) {
1054
+ console.log(`[acp-ai-provider] Warning: authMethodId "${configuredAuthMethodId}" is not in initialize.authMethods. Lazy auth auto-retry will be skipped unless you call authenticate() with a valid method.`, JSON.stringify(authMethods, null, 2));
1055
+ } else {
1056
+ console.log(`[acp-ai-provider] Lazy auth enabled with authMethodId="${configuredAuthMethodId}". Authentication will run only when required (code ${ACP_AUTH_REQUIRED_ERROR_CODE}).`);
1057
+ }
1058
+ }
1059
+ } catch (error) {
1060
+ throw toCatchableError(error, this.stderrChunks.join(""));
1061
+ }
1062
+ }
1063
+ /**
1064
+ * Starts a new session or updates the existing one.
1065
+ * Assumes connectClient() has been called.
1066
+ */
1067
+ async startSession(acpTools2) {
1068
+ if (!this.connection) {
1069
+ throw new Error("Not connected");
1070
+ }
1071
+ try {
1072
+ const mcpServers = [
1073
+ ...this.config.session?.mcpServers ?? []
1074
+ ];
1075
+ let toolsAdded = false;
1076
+ if (acpTools2 && acpTools2.length > 0 && !this.toolProxyHost) {
1077
+ this.debug.log("[acp-ai-provider] Setting up tool proxy for client-side tools...", acpTools2.map((t) => t.name));
1078
+ this.toolProxyHost = new ToolProxyHost("acp-ai-sdk-tools");
1079
+ for (const t of acpTools2) {
1080
+ this.toolProxyHost.registerTool(t.name, t);
1081
+ }
1082
+ toolsAdded = true;
1083
+ }
1084
+ if (this.toolProxyHost) {
1085
+ const proxyConfig = await this.toolProxyHost.start();
1086
+ mcpServers.push(proxyConfig);
1087
+ }
1088
+ if (this.sessionId && toolsAdded) {
1089
+ this.sessionResponse = await this.connection.newSession({
1090
+ ...this.config.session,
1091
+ cwd: this.config.session?.cwd ?? process2.cwd(),
1092
+ mcpServers
1093
+ });
1094
+ this.sessionId = this.sessionResponse.sessionId;
1095
+ this.isFreshSession = true;
1096
+ await this.applySessionDelay();
1097
+ return;
1098
+ }
1099
+ if (this.sessionId) {
1100
+ return;
1101
+ }
1102
+ if (this.config.existingSessionId) {
1103
+ await this.connection.loadSession({
1104
+ sessionId: this.config.existingSessionId,
1105
+ cwd: this.config.session?.cwd ?? process2.cwd(),
1106
+ mcpServers
1107
+ });
1108
+ this.sessionId = this.config.existingSessionId;
1109
+ this.sessionResponse = {
1110
+ sessionId: this.config.existingSessionId
1111
+ };
1112
+ this.isFreshSession = false;
1113
+ } else {
1114
+ this.sessionResponse = await this.connection.newSession({
1115
+ ...this.config.session,
1116
+ cwd: this.config.session?.cwd ?? process2.cwd(),
1117
+ mcpServers
1118
+ });
1119
+ this.sessionId = this.sessionResponse.sessionId;
1120
+ this.isFreshSession = true;
1121
+ }
1122
+ const { models, modes } = this.sessionResponse ?? {};
1123
+ if (models?.currentModelId) {
1124
+ this.currentModelId = models.currentModelId;
1125
+ }
1126
+ if (modes?.currentModeId) {
1127
+ this.currentModeId = modes.currentModeId;
1128
+ }
1129
+ if (this.modelId && this.modelId !== this.currentModelId) {
1130
+ await this.setModel(this.modelId);
1131
+ this.currentModelId = this.modelId;
1132
+ }
1133
+ if (this.modeId && this.modeId !== this.currentModeId) {
1134
+ await this.setMode(this.modeId);
1135
+ this.currentModeId = this.modeId;
1136
+ }
1137
+ await this.applySessionDelay();
1138
+ } catch (error) {
1139
+ throw toCatchableError(error, this.stderrChunks.join(""));
1140
+ }
1141
+ }
1142
+ async applySessionDelay() {
1143
+ if (this.config.sessionDelayMs) {
1144
+ this.debug.log(`[acp-ai-provider] Waiting ${this.config.sessionDelayMs}ms after session setup...`);
1145
+ await new Promise((resolve) => setTimeout(resolve, this.config.sessionDelayMs));
1146
+ }
1147
+ }
1148
+ /**
1149
+ * Resolves the auth method ID to use for lazy authentication.
1150
+ * Returns null if no valid method is available.
1151
+ */
1152
+ resolveLazyAuthMethodId() {
1153
+ const configured = this.config.authMethodId;
1154
+ if (!configured) {
1155
+ return this.availableAuthMethodIds[0] ?? null;
1156
+ }
1157
+ if (this.availableAuthMethodIds.length === 0) {
1158
+ return configured;
1159
+ }
1160
+ return this.availableAuthMethodIds.includes(configured) ? configured : null;
1161
+ }
1162
+ /**
1163
+ * Runs an operation with lazy auth: try once, and if an auth-required error
1164
+ * is thrown, authenticate and retry exactly once.
1165
+ */
1166
+ async withLazyAuthRetry(stage, operation) {
1167
+ try {
1168
+ return await operation();
1169
+ } catch (error) {
1170
+ if (!isAuthRequiredError(error)) {
1171
+ throw error;
1172
+ }
1173
+ const methodId = this.resolveLazyAuthMethodId();
1174
+ if (!methodId) {
1175
+ throw error;
1176
+ }
1177
+ this.debug.log(`[acp-ai-provider] Authentication required during ${stage} (code ${ACP_AUTH_REQUIRED_ERROR_CODE}). Running lazy authenticate with methodId="${methodId}" and retrying once...`);
1178
+ await this.authenticate(methodId);
1179
+ return await operation();
1180
+ }
1181
+ }
1182
+ /**
1183
+ * Ensures the ACP agent process is running and a session is established.
1184
+ *
1185
+ * Lazy auth behavior:
1186
+ * - first try connect + start session without authenticating
1187
+ * - if auth is required (ACP auth-required error), authenticate once and retry once
1188
+ *
1189
+ * @param acpTools - Tools from streamText options to proxy
1190
+ */
1191
+ async ensureConnected(acpTools2) {
1192
+ await this.withLazyAuthRetry("session setup", async () => {
1193
+ await this.connectClient();
1194
+ await this.startSession(acpTools2);
1195
+ });
1196
+ }
1197
+ /**
1198
+ * Clears connection state. Skips if persistSession is enabled.
1199
+ */
1200
+ cleanup() {
1201
+ if (this.config.persistSession) return;
1202
+ this.forceCleanup();
1203
+ }
1204
+ /**
1205
+ * Returns the current session ID.
1206
+ */
1207
+ getSessionId() {
1208
+ return this.sessionId;
1209
+ }
1210
+ /**
1211
+ * Initializes the session and returns session info (models, modes, meta).
1212
+ * Call this before prompting to discover available options.
1213
+ *
1214
+ * @param tools - Optional tools to register during session initialization.
1215
+ */
1216
+ async initSession(tools) {
1217
+ const acpTools2 = extractACPTools(tools, false);
1218
+ await this.ensureConnected(acpTools2.length > 0 ? acpTools2 : void 0);
1219
+ return this.sessionResponse;
1220
+ }
1221
+ /**
1222
+ * Triggers ACP authentication manually.
1223
+ * Useful when callers catch an auth-required error and want to authenticate then retry.
1224
+ */
1225
+ async authenticate(methodId) {
1226
+ await this.connectClient();
1227
+ if (!this.connection) {
1228
+ throw new Error("Not connected");
1229
+ }
1230
+ try {
1231
+ await this.connection.authenticate({
1232
+ methodId
1233
+ });
1234
+ } catch (error) {
1235
+ throw toCatchableError(error, this.stderrChunks.join(""));
1236
+ }
1237
+ }
1238
+ async promptWithLazyAuthRetry(request) {
1239
+ if (!this.connection) {
1240
+ throw new Error("Not connected");
1241
+ }
1242
+ try {
1243
+ const response = await this.withLazyAuthRetry("prompt", () => this.connection.prompt(request));
1244
+ this.debug.appendPromptResponse(response);
1245
+ return response;
1246
+ } catch (error) {
1247
+ this.debug.appendPromptError(error);
1248
+ throw error;
1249
+ }
1250
+ }
1251
+ /**
1252
+ * Sets the session mode (e.g., "ask", "plan").
1253
+ */
1254
+ async setMode(modeId) {
1255
+ if (!this.connection || !this.sessionId) {
1256
+ throw new Error("Not connected. Call preconnect() first.");
1257
+ }
1258
+ const availableModes = this.sessionResponse?.modes?.availableModes;
1259
+ if (availableModes) {
1260
+ const foundMode = availableModes.find((m) => m.id === modeId);
1261
+ if (!foundMode) {
1262
+ const availableList = availableModes.map((m) => m.id).join(", ");
1263
+ const currentInfo = this.sessionResponse?.modes?.currentModeId ? ` (Current: "${this.sessionResponse.modes.currentModeId}")` : "";
1264
+ throw new Error(`Mode "${modeId}" is not available${currentInfo}. Available modes: ${availableList}`);
1265
+ }
1266
+ }
1267
+ await this.connection.setSessionMode({
1268
+ sessionId: this.sessionId,
1269
+ modeId
1270
+ });
1271
+ this.currentModeId = modeId;
1272
+ }
1273
+ /**
1274
+ * Sets the session model.
1275
+ */
1276
+ async setModel(modelId) {
1277
+ if (!this.connection || !this.sessionId) {
1278
+ throw new Error("Not connected. Call preconnect() first.");
1279
+ }
1280
+ const { models } = this.sessionResponse ?? {};
1281
+ if (models?.availableModels) {
1282
+ if (!models.availableModels.some((m) => m.modelId === modelId)) {
1283
+ const availableList = models.availableModels.map((m) => m.modelId).join(", ");
1284
+ const currentInfo = this.currentModelId ? ` (Current: "${this.currentModelId}")` : "";
1285
+ throw new Error(`Model "${modelId}" is not available${currentInfo}. Available models: ${availableList}`);
1286
+ }
1287
+ }
1288
+ await this.connection.unstable_setSessionModel({
1289
+ sessionId: this.sessionId,
1290
+ modelId
1291
+ });
1292
+ this.currentModelId = modelId;
1293
+ }
1294
+ /**
1295
+ * Forces cleanup regardless of persistSession setting.
1296
+ */
1297
+ forceCleanup() {
1298
+ if (this.toolProxyHost) {
1299
+ this.toolProxyHost.stop();
1300
+ this.toolProxyHost = null;
1301
+ }
1302
+ if (this.agentProcess) {
1303
+ this.agentProcess.kill();
1304
+ this.agentProcess.stdin?.end();
1305
+ this.agentProcess.stdout?.destroy();
1306
+ this.agentProcess.stderr?.destroy();
1307
+ this.agentProcess = null;
1308
+ }
1309
+ this.connection = null;
1310
+ this.sessionId = null;
1311
+ this.sessionResponse = null;
1312
+ this.client = null;
1313
+ this.stderrChunks = [];
1314
+ this.availableAuthMethodIds = [];
1315
+ }
1316
+ /**
1317
+ * Emits raw content (plan, diffs, terminals) as raw stream parts.
1318
+ * Plan data is emitted directly, while diffs and terminals are bound to a toolCallId.
1319
+ */
1320
+ emitRawContent(controller, data) {
1321
+ if ("entries" in data) {
1322
+ controller.enqueue({
1323
+ type: "raw",
1324
+ rawValue: JSON.stringify({
1325
+ type: "plan",
1326
+ entries: data.entries
1327
+ })
1328
+ });
1329
+ return;
1330
+ }
1331
+ for (const item of data.content) {
1332
+ if (item.type === "diff" || item.type === "terminal") {
1333
+ controller.enqueue({
1334
+ type: "raw",
1335
+ rawValue: JSON.stringify({
1336
+ ...item,
1337
+ toolCallId: data.toolCallId
1338
+ })
1339
+ });
1340
+ }
1341
+ }
1342
+ }
1343
+ /**
1344
+ * Flushes any pending tool calls that haven't emitted tool-call yet.
1345
+ * This handles the case where a tool emits {} first, then the next message is a different type.
1346
+ */
1347
+ flushPendingToolCalls(controller) {
1348
+ for (const [toolCallId, toolInfo] of this.toolCallsMap.entries()) {
1349
+ if (!toolInfo.inputAvailable) {
1350
+ toolInfo.inputAvailable = true;
1351
+ controller.enqueue({
1352
+ type: "tool-call",
1353
+ toolCallId,
1354
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
1355
+ input: JSON.stringify({
1356
+ toolCallId,
1357
+ toolName: toolInfo.name,
1358
+ args: {}
1359
+ })
1360
+ });
1361
+ }
1362
+ }
1363
+ }
1364
+ /**
1365
+ * Standardized handler for converting SessionNotifications into
1366
+ * LanguageModelV3StreamPart objects, pushing them onto a stream controller.
1367
+ */
1368
+ handleStreamNotification(controller, notification) {
1369
+ this.debug.appendAgentMessage(notification);
1370
+ const update = notification.update;
1371
+ switch (update.sessionUpdate) {
1372
+ case "plan":
1373
+ this.flushPendingToolCalls(controller);
1374
+ this.emitRawContent(controller, {
1375
+ type: "plan",
1376
+ entries: update.entries
1377
+ });
1378
+ break;
1379
+ case "agent_thought_chunk":
1380
+ this.flushPendingToolCalls(controller);
1381
+ if (!this.currentThinkingId) {
1382
+ this.currentThinkingId = `reasoning - ${this.thinkBlockIndex++} `;
1383
+ controller.enqueue({
1384
+ type: "reasoning-start",
1385
+ id: this.currentThinkingId
1386
+ });
1387
+ }
1388
+ controller.enqueue({
1389
+ type: "reasoning-delta",
1390
+ id: this.currentThinkingId,
1391
+ delta: update.content.type === "text" ? update.content.text : ""
1392
+ });
1393
+ break;
1394
+ case "agent_message_chunk":
1395
+ this.flushPendingToolCalls(controller);
1396
+ if (this.currentThinkingId) {
1397
+ controller.enqueue({
1398
+ type: "reasoning-end",
1399
+ id: this.currentThinkingId
1400
+ });
1401
+ this.currentThinkingId = null;
1402
+ }
1403
+ if (update.content.type === "text") {
1404
+ const textChunk = update.content.text;
1405
+ if (!this.currentTextId) {
1406
+ this.currentTextId = `text - ${this.textBlockIndex++} `;
1407
+ controller.enqueue({
1408
+ type: "text-start",
1409
+ id: this.currentTextId
1410
+ });
1411
+ }
1412
+ controller.enqueue({
1413
+ type: "text-delta",
1414
+ id: this.currentTextId,
1415
+ delta: textChunk
1416
+ });
1417
+ }
1418
+ break;
1419
+ case "tool_call": {
1420
+ if (this.currentTextId) {
1421
+ controller.enqueue({
1422
+ type: "text-end",
1423
+ id: this.currentTextId
1424
+ });
1425
+ this.currentTextId = null;
1426
+ }
1427
+ if (this.currentThinkingId) {
1428
+ controller.enqueue({
1429
+ type: "reasoning-end",
1430
+ id: this.currentThinkingId
1431
+ });
1432
+ this.currentThinkingId = null;
1433
+ }
1434
+ const { toolCallId, toolName, toolInput } = this.parseToolCall(update);
1435
+ const existingToolCall = this.toolCallsMap.get(toolCallId);
1436
+ const hasInput = this.hasToolInput(toolInput);
1437
+ if (!existingToolCall) {
1438
+ this.toolCallsMap.set(toolCallId, {
1439
+ index: this.toolCallsMap.size,
1440
+ name: toolName,
1441
+ inputStarted: true,
1442
+ inputAvailable: !!hasInput
1443
+ });
1444
+ controller.enqueue({
1445
+ type: "tool-input-start",
1446
+ id: toolCallId,
1447
+ toolName
1448
+ });
1449
+ if (hasInput) {
1450
+ controller.enqueue({
1451
+ type: "tool-call",
1452
+ toolCallId,
1453
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
1454
+ input: JSON.stringify({
1455
+ toolCallId,
1456
+ toolName,
1457
+ args: toolInput
1458
+ })
1459
+ });
1460
+ }
1461
+ } else if (!existingToolCall.inputAvailable && hasInput) {
1462
+ existingToolCall.inputAvailable = true;
1463
+ if (update.title && existingToolCall.name !== update.title && update.title !== toolCallId) {
1464
+ existingToolCall.name = update.title;
1465
+ }
1466
+ controller.enqueue({
1467
+ type: "tool-call",
1468
+ toolCallId,
1469
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
1470
+ input: JSON.stringify({
1471
+ toolCallId,
1472
+ toolName: existingToolCall.name,
1473
+ args: toolInput
1474
+ })
1475
+ });
1476
+ }
1477
+ break;
1478
+ }
1479
+ case "tool_call_update": {
1480
+ const { toolCallId, toolName, toolResult, isError } = this.parseToolResult(update);
1481
+ const effectiveStatus = update.status ?? "in_progress";
1482
+ let toolInfo = this.toolCallsMap.get(toolCallId);
1483
+ const updateInput = this.normalizeToolInput("rawInput" in update ? update.rawInput : void 0);
1484
+ if (effectiveStatus === "in_progress") {
1485
+ if (!toolInfo) {
1486
+ toolInfo = {
1487
+ index: this.toolCallsMap.size,
1488
+ name: toolName,
1489
+ inputStarted: true,
1490
+ inputAvailable: false
1491
+ };
1492
+ this.toolCallsMap.set(toolCallId, toolInfo);
1493
+ controller.enqueue({
1494
+ type: "tool-input-start",
1495
+ id: toolCallId,
1496
+ toolName
1497
+ });
1498
+ }
1499
+ const hasNewInput = this.hasToolInput(updateInput);
1500
+ if (!toolInfo.inputAvailable || hasNewInput) {
1501
+ toolInfo.inputAvailable = true;
1502
+ if (update.title && toolInfo.name !== update.title && update.title !== toolCallId) {
1503
+ toolInfo.name = update.title;
1504
+ }
1505
+ controller.enqueue({
1506
+ type: "tool-call",
1507
+ toolCallId,
1508
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
1509
+ input: JSON.stringify({
1510
+ toolCallId,
1511
+ toolName: toolInfo.name,
1512
+ args: updateInput
1513
+ })
1514
+ });
1515
+ }
1516
+ const content2 = update.content ?? [];
1517
+ if (content2.length > 0) {
1518
+ this.emitRawContent(controller, {
1519
+ content: content2,
1520
+ toolCallId
1521
+ });
1522
+ }
1523
+ break;
1524
+ }
1525
+ if (![
1526
+ "completed",
1527
+ "failed"
1528
+ ].includes(effectiveStatus)) {
1529
+ break;
1530
+ }
1531
+ if (!toolInfo) {
1532
+ toolInfo = {
1533
+ index: this.toolCallsMap.size,
1534
+ name: toolName,
1535
+ inputAvailable: true
1536
+ };
1537
+ this.toolCallsMap.set(toolCallId, toolInfo);
1538
+ controller.enqueue({
1539
+ type: "tool-call",
1540
+ toolCallId,
1541
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
1542
+ input: JSON.stringify({
1543
+ toolCallId,
1544
+ toolName,
1545
+ args: updateInput
1546
+ })
1547
+ });
1548
+ } else {
1549
+ const hasNewInput = this.hasToolInput(updateInput);
1550
+ if (!toolInfo.inputAvailable || hasNewInput) {
1551
+ toolInfo.inputAvailable = true;
1552
+ if (update.title && toolInfo.name !== update.title && update.title !== toolCallId) {
1553
+ toolInfo.name = update.title;
1554
+ }
1555
+ controller.enqueue({
1556
+ type: "tool-call",
1557
+ toolCallId,
1558
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
1559
+ input: JSON.stringify({
1560
+ toolCallId,
1561
+ toolName: toolInfo.name,
1562
+ args: updateInput
1563
+ })
1564
+ });
1565
+ }
1566
+ }
1567
+ const clientToolInfo = this.isClientToolResult(toolResult);
1568
+ if (clientToolInfo.isClientTool) {
1569
+ this.debug.log(`[acp-ai-provider] Detected client tool: ${clientToolInfo.toolName}, stopping stream`);
1570
+ const content2 = update.content ?? [];
1571
+ if (content2.length > 0) {
1572
+ this.emitRawContent(controller, {
1573
+ content: content2,
1574
+ toolCallId
1575
+ });
1576
+ }
1577
+ if (this.clientToolAbort) {
1578
+ controller.enqueue({
1579
+ type: "finish",
1580
+ finishReason: {
1581
+ unified: "tool-calls",
1582
+ raw: void 0
1583
+ },
1584
+ usage: {
1585
+ inputTokens: {
1586
+ total: void 0,
1587
+ noCache: void 0,
1588
+ cacheRead: void 0,
1589
+ cacheWrite: void 0
1590
+ },
1591
+ outputTokens: {
1592
+ total: void 0,
1593
+ text: void 0,
1594
+ reasoning: void 0
1595
+ }
1596
+ }
1597
+ });
1598
+ controller.close();
1599
+ this.clientToolAbort.resolve();
1600
+ this.cleanup();
1601
+ }
1602
+ break;
1603
+ }
1604
+ controller.enqueue({
1605
+ type: "tool-result",
1606
+ toolCallId,
1607
+ toolName: ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2,
1608
+ result: toolResult,
1609
+ // https://github.com/vercel/ai/blob/282f062922cb59167dd3a11e3af67cfa0b75f317/packages/ai/src/generate-text/run-tools-transformation.ts#L316
1610
+ ...isError && {
1611
+ isError: true,
1612
+ result: new Error(formatToolError(normalizeToolResultBlocks(toolResult)))
1613
+ }
1614
+ });
1615
+ const content = update.content ?? [];
1616
+ if (content.length > 0) {
1617
+ this.emitRawContent(controller, {
1618
+ content,
1619
+ toolCallId
1620
+ });
1621
+ }
1622
+ break;
1623
+ }
1624
+ }
1625
+ }
1626
+ /**
1627
+ * Implements the non-streaming generation method.
1628
+ */
1629
+ async doGenerate(options) {
1630
+ try {
1631
+ const jsonResponseFormat = isJsonResponseFormat(options.responseFormat) ? options.responseFormat : null;
1632
+ const jsonSchemaPrompt = jsonResponseFormat ? buildJsonSchemaPrompt(jsonResponseFormat) : void 0;
1633
+ await this.ensureConnected();
1634
+ const promptContent = convertAiSdkMessagesToAcp(options, this.isFreshSession, jsonSchemaPrompt);
1635
+ this.isFreshSession = false;
1636
+ let accumulatedText = "";
1637
+ const toolCalls = [];
1638
+ const toolResults = /* @__PURE__ */ new Map();
1639
+ const mockController = {
1640
+ enqueue: (part) => {
1641
+ switch (part.type) {
1642
+ case "text-delta":
1643
+ accumulatedText += part.delta;
1644
+ break;
1645
+ case "tool-call": {
1646
+ const inputData = JSON.parse(part.input);
1647
+ toolCalls.push({
1648
+ id: part.toolCallId,
1649
+ name: inputData.toolName,
1650
+ input: inputData.args
1651
+ });
1652
+ break;
1653
+ }
1654
+ case "tool-result": {
1655
+ const matchingToolCall = toolCalls.find((tc) => tc.id === part.toolCallId);
1656
+ toolResults.set(part.toolCallId, {
1657
+ name: matchingToolCall?.name || part.toolCallId,
1658
+ result: part.result,
1659
+ isError: part.isError
1660
+ });
1661
+ break;
1662
+ }
1663
+ // Other stream parts (reasoning, start/end blocks, etc.)
1664
+ // are ignored in non-streaming mode
1665
+ default:
1666
+ break;
1667
+ }
1668
+ }
1669
+ };
1670
+ const streamHandler = this.handleStreamNotification.bind(this);
1671
+ this.resetStreamState();
1672
+ if (this.client) {
1673
+ this.client.setSessionUpdateHandler((notification) => {
1674
+ streamHandler(mockController, notification);
1675
+ });
1676
+ }
1677
+ const response = await this.promptWithLazyAuthRetry({
1678
+ sessionId: this.sessionId,
1679
+ prompt: promptContent
1680
+ });
1681
+ const content = [];
1682
+ const finalText = jsonResponseFormat ? stripMarkdownFences(accumulatedText) : accumulatedText;
1683
+ if (finalText.trim()) {
1684
+ content.push({
1685
+ type: "text",
1686
+ text: finalText
1687
+ });
1688
+ }
1689
+ for (const toolCall of toolCalls) {
1690
+ content.push({
1691
+ type: "tool-call",
1692
+ toolCallId: toolCall.id,
1693
+ toolName: toolCall.name,
1694
+ args: JSON.stringify(toolCall.input),
1695
+ input: toolCall.input,
1696
+ output: toolResults.get(toolCall.id)?.result
1697
+ });
1698
+ }
1699
+ const result = {
1700
+ content,
1701
+ finishReason: {
1702
+ unified: mapACPStopReasonToAISDK(response.stopReason),
1703
+ raw: response.stopReason
1704
+ },
1705
+ providerMetadata: getACPResponse(response),
1706
+ usage: {
1707
+ inputTokens: {
1708
+ total: void 0,
1709
+ noCache: void 0,
1710
+ cacheRead: void 0,
1711
+ cacheWrite: void 0
1712
+ },
1713
+ outputTokens: {
1714
+ total: void 0,
1715
+ text: void 0,
1716
+ reasoning: void 0
1717
+ }
1718
+ },
1719
+ warnings: []
1720
+ };
1721
+ this.cleanup();
1722
+ return result;
1723
+ } catch (error) {
1724
+ this.cleanup();
1725
+ throw error;
1726
+ }
1727
+ }
1728
+ /**
1729
+ * Implements the streaming generation method.
1730
+ */
1731
+ async doStream(options) {
1732
+ const acpTools2 = extractACPTools(options.tools);
1733
+ const jsonResponseFormat = isJsonResponseFormat(options.responseFormat) ? options.responseFormat : null;
1734
+ const jsonSchemaPrompt = jsonResponseFormat ? buildJsonSchemaPrompt(jsonResponseFormat) : void 0;
1735
+ try {
1736
+ await this.ensureConnected(acpTools2.length > 0 ? acpTools2 : void 0);
1737
+ } catch (error) {
1738
+ this.forceCleanup();
1739
+ throw error;
1740
+ }
1741
+ const promptContent = convertAiSdkMessagesToAcp(options, this.isFreshSession, jsonSchemaPrompt);
1742
+ this.isFreshSession = false;
1743
+ const sessionId = this.sessionId;
1744
+ const client = this.client;
1745
+ const cleanup = () => this.cleanup();
1746
+ const streamHandler = this.handleStreamNotification.bind(this);
1747
+ const stream = new ReadableStream({
1748
+ start: async (controller) => {
1749
+ controller.enqueue({
1750
+ type: "stream-start",
1751
+ warnings: []
1752
+ });
1753
+ this.resetStreamState();
1754
+ const clientToolPromise = new Promise((resolve) => {
1755
+ this.clientToolAbort = {
1756
+ controller,
1757
+ resolve
1758
+ };
1759
+ });
1760
+ try {
1761
+ if (client) {
1762
+ client.setSessionUpdateHandler((notification) => {
1763
+ streamHandler(controller, notification);
1764
+ });
1765
+ }
1766
+ const promptPromise = this.promptWithLazyAuthRetry({
1767
+ sessionId,
1768
+ prompt: promptContent
1769
+ });
1770
+ const result = await Promise.race([
1771
+ promptPromise.then((response2) => ({
1772
+ type: "response",
1773
+ response: response2
1774
+ })),
1775
+ clientToolPromise.then(() => ({
1776
+ type: "client-tool"
1777
+ }))
1778
+ ]);
1779
+ if (result.type === "client-tool") {
1780
+ return;
1781
+ }
1782
+ const response = result.response;
1783
+ controller.enqueue({
1784
+ type: "finish",
1785
+ finishReason: {
1786
+ unified: mapACPStopReasonToAISDK(response.stopReason),
1787
+ raw: response.stopReason
1788
+ },
1789
+ providerMetadata: getACPResponse(response),
1790
+ usage: {
1791
+ inputTokens: {
1792
+ total: void 0,
1793
+ noCache: void 0,
1794
+ cacheRead: void 0,
1795
+ cacheWrite: void 0
1796
+ },
1797
+ outputTokens: {
1798
+ total: void 0,
1799
+ text: void 0,
1800
+ reasoning: void 0
1801
+ }
1802
+ }
1803
+ });
1804
+ controller.close();
1805
+ cleanup();
1806
+ } catch (error) {
1807
+ cleanup();
1808
+ controller.enqueue({
1809
+ type: "error",
1810
+ error: toCatchableError(error, this.stderrChunks.join(""))
1811
+ });
1812
+ }
1813
+ },
1814
+ cancel: () => {
1815
+ cleanup();
1816
+ }
1817
+ });
1818
+ const outputStream = jsonResponseFormat ? stream.pipeThrough(createJsonCleanupTransform()) : stream;
1819
+ return {
1820
+ stream: outputStream,
1821
+ warnings: void 0
1822
+ };
1823
+ }
1824
+ get tools() {
1825
+ return getACPDynamicTool();
1826
+ }
1827
+ };
1828
+
1829
+ // __mcpc__acp-ai-provider_latest/node_modules/@mcpc/acp-ai-provider/src/provider.js
1830
+ var ACPProvider = class {
1831
+ config;
1832
+ model = null;
1833
+ constructor(config) {
1834
+ this.config = config;
1835
+ }
1836
+ /**
1837
+ * Create a language model instance for a specific ACP agent
1838
+ *
1839
+ * @returns A LanguageModelV2 instance
1840
+ */
1841
+ languageModel(modelId, modeId) {
1842
+ if (!this.model) {
1843
+ this.model = new ACPLanguageModel(modelId, modeId, this.config);
1844
+ }
1845
+ if (modelId) {
1846
+ this.model.modelId = modelId;
1847
+ }
1848
+ if (modeId) {
1849
+ this.model.modeId = modeId;
1850
+ }
1851
+ return this.model;
1852
+ }
1853
+ /**
1854
+ * Shorthand for creating a language model
1855
+ */
1856
+ call() {
1857
+ return this.languageModel();
1858
+ }
1859
+ /**
1860
+ * Provider tools - includes the agent dynamic tool
1861
+ */
1862
+ get tools() {
1863
+ return this.model?.tools;
1864
+ }
1865
+ /**
1866
+ * Returns the current session ID if one is active.
1867
+ * Useful when `persistSession` is enabled and you need to reference the session later.
1868
+ */
1869
+ getSessionId() {
1870
+ return this.model?.getSessionId() ?? null;
1871
+ }
1872
+ /**
1873
+ * Initializes the session and returns session info (models, modes, meta).
1874
+ * Call this before prompting to discover available options.
1875
+ */
1876
+ initSession(tools) {
1877
+ if (!this.model) {
1878
+ this.languageModel();
1879
+ }
1880
+ return this.model.initSession(tools);
1881
+ }
1882
+ /**
1883
+ * Initializes the connection to the agent process without starting a session.
1884
+ * Useful if you need to reduce the time to the first token.
1885
+ */
1886
+ connect() {
1887
+ if (!this.model) {
1888
+ this.languageModel();
1889
+ }
1890
+ return this.model.connectClient();
1891
+ }
1892
+ /**
1893
+ * Runs authentication manually.
1894
+ *
1895
+ * If `methodId` is omitted, falls back to `config.authMethodId`.
1896
+ */
1897
+ authenticate(methodId) {
1898
+ if (!this.model) {
1899
+ this.languageModel();
1900
+ }
1901
+ const resolvedMethodId = methodId ?? this.config.authMethodId;
1902
+ if (!resolvedMethodId) {
1903
+ throw new Error("No auth method configured. Pass methodId or set authMethodId in ACPProviderSettings.");
1904
+ }
1905
+ return this.model.authenticate(resolvedMethodId);
1906
+ }
1907
+ /**
1908
+ * Sets the session mode (e.g., "ask", "plan").
1909
+ */
1910
+ setMode(modeId) {
1911
+ if (!this.model) {
1912
+ throw new Error("No model initialized. Call languageModel() first.");
1913
+ }
1914
+ return this.model.setMode(modeId);
1915
+ }
1916
+ /**
1917
+ * Sets the session model.
1918
+ */
1919
+ setModel(modelId) {
1920
+ if (!this.model) {
1921
+ throw new Error("No model initialized. Call languageModel() first.");
1922
+ }
1923
+ return this.model.setModel(modelId);
1924
+ }
1925
+ /**
1926
+ * Forces cleanup of the connection and session.
1927
+ * Call this when you're done with the provider instance, especially when using `persistSession`.
1928
+ */
1929
+ cleanup() {
1930
+ this.model?.forceCleanup();
1931
+ }
1932
+ };
1933
+ function createACPProvider(config) {
1934
+ return new ACPProvider(config);
1935
+ }
1936
+ export {
1937
+ ACPLanguageModel,
1938
+ ACPProvider,
1939
+ ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME2 as ACP_PROVIDER_AGENT_DYNAMIC_TOOL_NAME,
1940
+ acpTools,
1941
+ createACPProvider,
1942
+ getExecuteByName,
1943
+ hasRegisteredExecute,
1944
+ providerAgentDynamicToolSchema
1945
+ };