agentroam-runtime-darwin-arm64 0.2.0-preview.37 → 0.2.0-preview.39

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 (203) hide show
  1. package/manifest.json +2 -2
  2. package/package.json +1 -1
  3. package/runtime/.next/BUILD_ID +1 -1
  4. package/runtime/.next/app-build-manifest.json +14 -14
  5. package/runtime/.next/app-path-routes-manifest.json +1 -1
  6. package/runtime/.next/build-manifest.json +6 -6
  7. package/runtime/.next/prerender-manifest.json +1 -1
  8. package/runtime/.next/react-loadable-manifest.json +12 -4
  9. package/runtime/.next/required-server-files.json +1 -1
  10. package/runtime/.next/routes-manifest.json +1 -1
  11. package/runtime/.next/server/app/_not-found/page.js +1 -1
  12. package/runtime/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  13. package/runtime/.next/server/app/_not-found.html +1 -1
  14. package/runtime/.next/server/app/_not-found.rsc +1 -1
  15. package/runtime/.next/server/app/api/agent/abort/route.js +1 -1
  16. package/runtime/.next/server/app/api/agent/answer/route.js +1 -1
  17. package/runtime/.next/server/app/api/agent/harness/status/route.js +1 -1
  18. package/runtime/.next/server/app/api/agent/model/route.js +1 -1
  19. package/runtime/.next/server/app/api/agent/models/route.js +1 -1
  20. package/runtime/.next/server/app/api/agent/run/route.js +3 -3
  21. package/runtime/.next/server/app/api/agent/runtime-health/route.js +1 -1
  22. package/runtime/.next/server/app/api/agent/steer/route.js +1 -1
  23. package/runtime/.next/server/app/api/agent/stream/route.js +3 -3
  24. package/runtime/.next/server/app/api/agent-workspaces/[workspaceId]/sessions/route.js +1 -1
  25. package/runtime/.next/server/app/api/agent-workspaces/route.js +1 -1
  26. package/runtime/.next/server/app/api/auth/verify/route.js +1 -1
  27. package/runtime/.next/server/app/api/business/route.js +1 -1
  28. package/runtime/.next/server/app/api/client-logs/route.js +1 -1
  29. package/runtime/.next/server/app/api/flow/v1/catalog/route.js +1 -1
  30. package/runtime/.next/server/app/api/flow/v1/runs/[runId]/cancel/route.js +1 -1
  31. package/runtime/.next/server/app/api/flow/v1/runs/[runId]/events/route.js +2 -2
  32. package/runtime/.next/server/app/api/flow/v1/runs/route.js +1 -1
  33. package/runtime/.next/server/app/api/flow-studio/config/route.js +1 -1
  34. package/runtime/.next/server/app/api/mcp/connect/route.js +1 -1
  35. package/runtime/.next/server/app/api/mcp/disconnect/route.js +1 -1
  36. package/runtime/.next/server/app/api/mcp/servers/route.js +1 -1
  37. package/runtime/.next/server/app/api/memory/[key]/route.js +1 -1
  38. package/runtime/.next/server/app/api/memory/route.js +1 -1
  39. package/runtime/.next/server/app/api/plugins/load/route.js +1 -1
  40. package/runtime/.next/server/app/api/projects/[id]/route.js +1 -1
  41. package/runtime/.next/server/app/api/projects/check/route.js +1 -1
  42. package/runtime/.next/server/app/api/projects/directories/route.js +1 -1
  43. package/runtime/.next/server/app/api/projects/roots/route.js +1 -1
  44. package/runtime/.next/server/app/api/projects/route.js +1 -1
  45. package/runtime/.next/server/app/api/push/subscribe/route.js +2 -2
  46. package/runtime/.next/server/app/api/push/unsubscribe/route.js +2 -2
  47. package/runtime/.next/server/app/api/push/vapid/route.js +2 -2
  48. package/runtime/.next/server/app/api/push/vapid.body +1 -1
  49. package/runtime/.next/server/app/api/remote-tools/register/route.js +1 -1
  50. package/runtime/.next/server/app/api/sessions/[id]/changes/route.js +2 -2
  51. package/runtime/.next/server/app/api/sessions/[id]/fork/route.js +1 -1
  52. package/runtime/.next/server/app/api/sessions/[id]/fork/route.js.nft.json +1 -1
  53. package/runtime/.next/server/app/api/sessions/[id]/fork-at/route.js +1 -0
  54. package/runtime/.next/server/app/api/sessions/[id]/fork-at/route.js.nft.json +1 -0
  55. package/runtime/.next/server/app/api/sessions/[id]/goals/route.js +1 -1
  56. package/runtime/.next/server/app/api/sessions/[id]/handoff/route.js +1 -1
  57. package/runtime/.next/server/app/api/sessions/[id]/query-index/route.js +1 -1
  58. package/runtime/.next/server/app/api/sessions/[id]/release/route.js +1 -1
  59. package/runtime/.next/server/app/api/sessions/[id]/route.js +1 -1
  60. package/runtime/.next/server/app/api/sessions/[id]/thread-goal/route.js +1 -1
  61. package/runtime/.next/server/app/api/sessions/[id]/tool-result/route.js +1 -1
  62. package/runtime/.next/server/app/api/sessions/route.js +1 -1
  63. package/runtime/.next/server/app/api/settings/route.js +1 -1
  64. package/runtime/.next/server/app/api/skills/route.js +1 -1
  65. package/runtime/.next/server/app/api/tool-policies/[policyId]/route.js +1 -1
  66. package/runtime/.next/server/app/api/tool-policies/route.js +1 -1
  67. package/runtime/.next/server/app/api/tools/route.js +1 -1
  68. package/runtime/.next/server/app/api/update/check/route.js +1 -1
  69. package/runtime/.next/server/app/api/update/install/route.js +1 -1
  70. package/runtime/.next/server/app/api/update/status/route.js +1 -1
  71. package/runtime/.next/server/app/api/web-auth/login/route.js +1 -1
  72. package/runtime/.next/server/app/api/web-auth/logout/route.js +1 -1
  73. package/runtime/.next/server/app/api/web-auth/revoke-all/route.js +1 -1
  74. package/runtime/.next/server/app/api/web-auth/setup/route.js +1 -1
  75. package/runtime/.next/server/app/api/web-auth/status/route.js +1 -1
  76. package/runtime/.next/server/app/api/web-console/bootstrap/route.js +1 -1
  77. package/runtime/.next/server/app/api/web-console/device-state/route.js +1 -1
  78. package/runtime/.next/server/app/api/web-console/history/route.js +1 -1
  79. package/runtime/.next/server/app/api/web-console/preferences/route.js +1 -1
  80. package/runtime/.next/server/app/web/page.js +2 -2
  81. package/runtime/.next/server/app/web/page_client-reference-manifest.js +1 -1
  82. package/runtime/.next/server/app-paths-manifest.json +20 -19
  83. package/runtime/.next/server/chunks/1322.js +72 -69
  84. package/runtime/.next/server/chunks/1773.js +38 -38
  85. package/runtime/.next/server/chunks/2293.js +1 -1
  86. package/runtime/.next/server/chunks/366.js +1 -0
  87. package/runtime/.next/server/chunks/5303.js +1 -1
  88. package/runtime/.next/server/chunks/8532.js +1 -1
  89. package/runtime/.next/server/middleware-build-manifest.js +1 -1
  90. package/runtime/.next/server/middleware-react-loadable-manifest.js +1 -1
  91. package/runtime/.next/server/pages/404.html +1 -1
  92. package/runtime/.next/server/pages/500.html +1 -1
  93. package/runtime/.next/server/server-reference-manifest.json +1 -1
  94. package/runtime/.next/static/chunks/326.567dcaf52a3fbf80.js +1 -0
  95. package/runtime/.next/static/chunks/693-41d7c8e27a8513d1.js +1 -0
  96. package/runtime/.next/static/chunks/784.1394d774230a5516.js +1 -0
  97. package/runtime/.next/static/chunks/834.801325c7f934eee6.js +1 -0
  98. package/runtime/.next/static/chunks/940.56137a61c838fa42.js +1 -0
  99. package/runtime/.next/static/chunks/95.ff2ef92ac2b1c909.js +1 -0
  100. package/runtime/.next/static/chunks/app/web/{error-7bdc841dab0f7345.js → error-f69dbd3718cb2107.js} +1 -1
  101. package/runtime/.next/static/chunks/app/web/layout-e0dd41d18df8ee9e.js +1 -0
  102. package/runtime/.next/static/chunks/app/web/page-f9926cbf4c1badd4.js +1 -0
  103. package/runtime/.next/static/chunks/{main-app-851d67ddcf02e2c2.js → main-app-d527fa0b25a0c755.js} +1 -1
  104. package/runtime/.next/static/chunks/webpack-d4e32619d2ce6d30.js +1 -0
  105. package/runtime/.next/static/css/e87416656ec8a57e.css +1 -0
  106. package/runtime/lib/remote-control/helper-manager.mjs +4 -1
  107. package/runtime/lib/remote-control/remote-authorization.mjs +21 -7
  108. package/runtime/native/AgentRoam Remote Desktop.app/Contents/MacOS/agentroam-remote-desktop +0 -0
  109. package/runtime/node_modules/.package-lock.json +11 -11
  110. package/runtime/node_modules/@agent/core/dist/index.js +123 -9
  111. package/runtime/node_modules/@agent/native-runtime/dist/index.js +141 -35
  112. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/bridge.mjs +77 -76
  113. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/browser-sdk.js +48 -48
  114. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/core-2haqfy07.mjs +33 -0
  115. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/core-a92dt75k.mjs +40 -0
  116. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/core.mjs +17 -17
  117. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/manifest.json +19 -25
  118. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/manifest.zst.json +23 -29
  119. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/package.json +12 -12
  120. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +53 -53
  121. package/runtime/package-lock.json +35 -35
  122. package/runtime/server.js +1 -1
  123. package/runtime/webapp/dist/assets/App-COIcZZvf.js +487 -0
  124. package/runtime/webapp/dist/assets/{App-CMOzoP5A.css → App-iUeP1CBo.css} +1 -1
  125. package/runtime/webapp/dist/assets/{abnfDiagram-VCTEODGH-CEAlrV9-.js → abnfDiagram-VCTEODGH-d4urtMQU.js} +1 -1
  126. package/runtime/webapp/dist/assets/{arc-CGetF_lO.js → arc-DiQEpEJQ.js} +1 -1
  127. package/runtime/webapp/dist/assets/{architectureDiagram-5GKGNRK7-BVksDtm9.js → architectureDiagram-5GKGNRK7-CWYKGqND.js} +1 -1
  128. package/runtime/webapp/dist/assets/{blockDiagram-I7D4REHJ-BvCo3epW.js → blockDiagram-I7D4REHJ-J2I0b5Zn.js} +1 -1
  129. package/runtime/webapp/dist/assets/{c4Diagram-7LVT6UL2-DwUEj82r.js → c4Diagram-7LVT6UL2-C-0xWeN3.js} +1 -1
  130. package/runtime/webapp/dist/assets/channel-B6S3kcST.js +1 -0
  131. package/runtime/webapp/dist/assets/{chunk-2Q5K7J3B-BQmtZUl-.js → chunk-2Q5K7J3B-CqodmK6L.js} +1 -1
  132. package/runtime/webapp/dist/assets/{chunk-5VM5RSS4-BXDY0cCC.js → chunk-5VM5RSS4-DClUnQcr.js} +1 -1
  133. package/runtime/webapp/dist/assets/{chunk-F27PBJKO-BPhfHsOp.js → chunk-F27PBJKO-CpaDg7Bg.js} +1 -1
  134. package/runtime/webapp/dist/assets/{chunk-IMKFNOWR-Dw-LyvaC.js → chunk-IMKFNOWR-CTIf9EjK.js} +1 -1
  135. package/runtime/webapp/dist/assets/{chunk-JWPE2WC7-Cdi61XTf.js → chunk-JWPE2WC7-DKalSWMm.js} +1 -1
  136. package/runtime/webapp/dist/assets/{chunk-POPQ4Y6H-eqgC5BfH.js → chunk-POPQ4Y6H-69MmeyRW.js} +1 -1
  137. package/runtime/webapp/dist/assets/{chunk-SVP7TREG-Dyzqf0xA.js → chunk-SVP7TREG-DCXWXzhU.js} +1 -1
  138. package/runtime/webapp/dist/assets/{chunk-TICWLB2K-DMy_FAyQ.js → chunk-TICWLB2K-B5nbTEng.js} +1 -1
  139. package/runtime/webapp/dist/assets/{chunk-XXDRQBXY-Dc3ya8KM.js → chunk-XXDRQBXY-DsJvkUuN.js} +1 -1
  140. package/runtime/webapp/dist/assets/classDiagram-ZZMXUADV-CyUA2YaV.js +1 -0
  141. package/runtime/webapp/dist/assets/classDiagram-v2-VYDZK3BY-CyUA2YaV.js +1 -0
  142. package/runtime/webapp/dist/assets/codeSyntax-DJH88FPL.js +5 -0
  143. package/runtime/webapp/dist/assets/{cose-bilkent-JH36ORCC-8SpbJGQ_.js → cose-bilkent-JH36ORCC-BamzQ_e_.js} +1 -1
  144. package/runtime/webapp/dist/assets/{cynefin-OW5HDTMX-DZ8NcP4L.js → cynefin-OW5HDTMX-BI_j1tbW.js} +1 -1
  145. package/runtime/webapp/dist/assets/{cynefinDiagram-5FMLGOSQ-C-g805uS.js → cynefinDiagram-5FMLGOSQ-DuxMrVM2.js} +1 -1
  146. package/runtime/webapp/dist/assets/{dagre-GXQ25YYZ-Cr8OiP_4.js → dagre-GXQ25YYZ-Y9_ne36w.js} +1 -1
  147. package/runtime/webapp/dist/assets/{diagram-S7CK7UJ4-Be71Foqh.js → diagram-S7CK7UJ4-DIIjO29m.js} +1 -1
  148. package/runtime/webapp/dist/assets/{diagram-UQ7AKVKN-CeDsu1RS.js → diagram-UQ7AKVKN-C4m2VMIy.js} +1 -1
  149. package/runtime/webapp/dist/assets/{diagram-VSXAHHWV-CObfkAwP.js → diagram-VSXAHHWV-Cw5aPZ0o.js} +1 -1
  150. package/runtime/webapp/dist/assets/{diagram-VX7I27RA-B6lAuke7.js → diagram-VX7I27RA-W8nmVcOl.js} +1 -1
  151. package/runtime/webapp/dist/assets/{diagram-Z3DM3KII-8oGhKMeq.js → diagram-Z3DM3KII-TksnHlQo.js} +1 -1
  152. package/runtime/webapp/dist/assets/{ebnfDiagram-PWID7BFC-DmiqrULj.js → ebnfDiagram-PWID7BFC-B3WM1b4a.js} +1 -1
  153. package/runtime/webapp/dist/assets/{erDiagram-RLTQ6QDP-BB_7Zdd4.js → erDiagram-RLTQ6QDP-BWctPuya.js} +1 -1
  154. package/runtime/webapp/dist/assets/{flowDiagram-HODETNUW-DbuKFxoO.js → flowDiagram-HODETNUW-BG5RMrLN.js} +1 -1
  155. package/runtime/webapp/dist/assets/{ganttDiagram-EL5Y4UJY-DAM3Gwd_.js → ganttDiagram-EL5Y4UJY-CPcR7Kn_.js} +1 -1
  156. package/runtime/webapp/dist/assets/{gitGraphDiagram-WWUBYQGX-Ci91dL5m.js → gitGraphDiagram-WWUBYQGX-Sg6KChEd.js} +1 -1
  157. package/runtime/webapp/dist/assets/{index-NmsboYZi.css → index-CtJgsVah.css} +1 -1
  158. package/runtime/webapp/dist/assets/{index-ZpxfzUdy.js → index-tQnPGo1_.js} +4 -4
  159. package/runtime/webapp/dist/assets/{infoDiagram-27XIBGKW-D717Ys7n.js → infoDiagram-27XIBGKW-BvrtvnrY.js} +1 -1
  160. package/runtime/webapp/dist/assets/{ishikawaDiagram-5VMMS53U-BF6gmyPX.js → ishikawaDiagram-5VMMS53U-Bz-dZQLJ.js} +1 -1
  161. package/runtime/webapp/dist/assets/{journeyDiagram-3NMN7TZE-B6ZY-IXx.js → journeyDiagram-3NMN7TZE-Cb4s9jRE.js} +1 -1
  162. package/runtime/webapp/dist/assets/{kanban-definition-UXKFOSKX-DH3FR2sI.js → kanban-definition-UXKFOSKX-IjMPUHg9.js} +1 -1
  163. package/runtime/webapp/dist/assets/{layout-BOnxGXiM.js → layout-DHjqr0PJ.js} +1 -1
  164. package/runtime/webapp/dist/assets/{linear-M6pkDoQ3.js → linear-COctZkFy.js} +1 -1
  165. package/runtime/webapp/dist/assets/{mermaid.core-DxK9Epxh.js → mermaid.core-BnonXfHT.js} +5 -5
  166. package/runtime/webapp/dist/assets/{mindmap-definition-YA3MSWOX-DpZ-X_Vf.js → mindmap-definition-YA3MSWOX-hxBlXJJE.js} +1 -1
  167. package/runtime/webapp/dist/assets/{pegDiagram-XKGWAZYB-ZxLpbtO1.js → pegDiagram-XKGWAZYB-D6KJ8Ftm.js} +1 -1
  168. package/runtime/webapp/dist/assets/{pieDiagram-E7YTZNPT-B26_pDmg.js → pieDiagram-E7YTZNPT-BzKWZmHN.js} +1 -1
  169. package/runtime/webapp/dist/assets/{quadrantDiagram-AXDQQJYC-C-qB9cbX.js → quadrantDiagram-AXDQQJYC-ZhiPKt96.js} +1 -1
  170. package/runtime/webapp/dist/assets/{railroadDiagram-O6MQD6OU-C54V-8Ku.js → railroadDiagram-O6MQD6OU-BtKhiOPG.js} +1 -1
  171. package/runtime/webapp/dist/assets/{requirementDiagram-BXWQKSXE-CaMYVKMk.js → requirementDiagram-BXWQKSXE-OFr_TA8V.js} +1 -1
  172. package/runtime/webapp/dist/assets/{sankeyDiagram-P5KCCOFB-DsrVKW_h.js → sankeyDiagram-P5KCCOFB-qNTDFxAX.js} +1 -1
  173. package/runtime/webapp/dist/assets/{sequenceDiagram-WJ2MYXX4-C5ImABz1.js → sequenceDiagram-WJ2MYXX4-B7s5-R4s.js} +1 -1
  174. package/runtime/webapp/dist/assets/{sizeCapture-INFHLROL-wM9HJhkr.js → sizeCapture-INFHLROL-DdFabbN6.js} +1 -1
  175. package/runtime/webapp/dist/assets/{stateDiagram-D77RDMKH-BY8hQ5ro.js → stateDiagram-D77RDMKH-CmAN4pX7.js} +1 -1
  176. package/runtime/webapp/dist/assets/stateDiagram-v2-MP3YSRHH-DsxpCqde.js +1 -0
  177. package/runtime/webapp/dist/assets/{swimlanes-42K2YHIH-OsTKRKJW.js → swimlanes-42K2YHIH-BQlIJAhf.js} +1 -1
  178. package/runtime/webapp/dist/assets/swimlanesDiagram-VR7AAH4N-tji3GZVz.js +8 -0
  179. package/runtime/webapp/dist/assets/{timeline-definition-24CTP7MA-DqyQVkVW.js → timeline-definition-24CTP7MA--Y1zJ9mc.js} +1 -1
  180. package/runtime/webapp/dist/assets/{vennDiagram-4TSXK5OY-Di3KXYdD.js → vennDiagram-4TSXK5OY-CUn6FScx.js} +1 -1
  181. package/runtime/webapp/dist/assets/{wardleyDiagram-VM6X3IG4-CnJpZdMd.js → wardleyDiagram-VM6X3IG4-Bbz-WBd5.js} +1 -1
  182. package/runtime/webapp/dist/assets/{web-BMb61xwV.js → web-DzBEnE5q.js} +1 -1
  183. package/runtime/webapp/dist/assets/{web-eq1eso0Y.js → web-harvpkJj.js} +1 -1
  184. package/runtime/webapp/dist/assets/{xychartDiagram-S5SC5T6Z-frC_Dy5B.js → xychartDiagram-S5SC5T6Z-RA9edGdQ.js} +1 -1
  185. package/runtime/webapp/dist/index.html +2 -2
  186. package/runtime/ws-server.mjs +5 -5
  187. package/runtime/.next/static/chunks/221.80fc551c3d6118e2.js +0 -1
  188. package/runtime/.next/static/chunks/326.c10c95f947d32ecb.js +0 -1
  189. package/runtime/.next/static/chunks/750-1766abd7e24fd1d6.js +0 -1
  190. package/runtime/.next/static/chunks/942.1dec0ce762e131a5.js +0 -1
  191. package/runtime/.next/static/chunks/app/web/layout-e5b1780d2961e7c0.js +0 -1
  192. package/runtime/.next/static/chunks/app/web/page-f5171cee114f2892.js +0 -1
  193. package/runtime/.next/static/chunks/webpack-3ff471b94db6b1b2.js +0 -1
  194. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/core-reghh1vn.mjs +0 -33
  195. package/runtime/node_modules/@anthropic-ai/claude-agent-sdk/core-tm6xdb2r.mjs +0 -40
  196. package/runtime/webapp/dist/assets/App-DQ5fJODJ.js +0 -476
  197. package/runtime/webapp/dist/assets/channel-BjAaNinW.js +0 -1
  198. package/runtime/webapp/dist/assets/classDiagram-ZZMXUADV-BA6foNu5.js +0 -1
  199. package/runtime/webapp/dist/assets/classDiagram-v2-VYDZK3BY-BA6foNu5.js +0 -1
  200. package/runtime/webapp/dist/assets/stateDiagram-v2-MP3YSRHH-D7wp4Sey.js +0 -1
  201. package/runtime/webapp/dist/assets/swimlanesDiagram-VR7AAH4N-Dq79H5La.js +0 -8
  202. /package/runtime/.next/static/{ENg3PaHjA_727MHwcEIkE → BmUH3xLHQfGkG3yzEK37i}/_buildManifest.js +0 -0
  203. /package/runtime/.next/static/{ENg3PaHjA_727MHwcEIkE → BmUH3xLHQfGkG3yzEK37i}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- "use strict";(()=>{var e={};e.id=5044,e.ids=[5044],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},1652:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>q,patchFetch:()=>g,requestAsyncStorage:()=>l,routeModule:()=>c,serverHooks:()=>x,staticGenerationAsyncStorage:()=>h});var s={};t.r(s),t.d(s,{GET:()=>d,dynamic:()=>p});var o=t(7786),n=t(5042),a=t(2184),i=t(1890),u=t(7519);let p="force-dynamic";async function d(){return i.NextResponse.json(u.agentHost.getHarnessStatus(),{headers:{"cache-control":"no-store"}})}let c=new o.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/agent/harness/status/route",pathname:"/api/agent/harness/status",filename:"route",bundlePath:"app/api/agent/harness/status/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-37/customer-agent/packages/server/app/api/agent/harness/status/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:l,staticGenerationAsyncStorage:h,serverHooks:x}=c,q="/api/agent/harness/status/route";function g(){return(0,a.patchFetch)({serverHooks:x,staticGenerationAsyncStorage:h})}},1489:(e,r,t)=>{t.d(r,{N:()=>u});var s=t(1322),o=t(6279),n=t(785);class a{constructor(){this.tasks=new s.vo4((0,n.kO)()),this.scheduler=new o.ST(this.tasks,e=>{this.fire(e).catch(e=>console.error("Scheduled Customer Agent run failed",e))},()=>{}),this.scheduler.start()}async fire(e){let{agentHost:r}=await t.e(7519).then(t.bind(t,7519)),{getCustomerGoalCoordinator:s}=await Promise.all([t.e(7519),t.e(732)]).then(t.bind(t,732)),o=e.sessionId;o&&await r.getSessionStore().get(o)||(o=(await r.createSession(e.label||"定时任务")).id,this.tasks.update(e.id,{sessionId:o})),await s().enqueue(o,e.prompt)}call(e,r){let t=String(r[0]||"");switch(e){case"cronList":return this.tasks.list();case"cronCreate":{if("string"!=typeof r[0]||"string"!=typeof r[1]||!r[1].trim())throw Error("cron and prompt required");let e=r[2]&&"object"==typeof r[2]?r[2]:{};return this.tasks.create({cron:r[0],prompt:r[1],recurring:!1!==e.recurring,enabled:!0,durable:!0,..."string"==typeof e.sessionId?{sessionId:e.sessionId}:{},..."string"==typeof e.label?{label:e.label}:{}})}case"cronPause":return this.tasks.pause(t);case"cronResume":return this.tasks.resume(t);case"cronDelete":return this.tasks.delete(t);case"cronDeleteAll":return this.tasks.deleteAll(),{ok:!0};default:throw Error("Unsupported schedule operation")}}}let i=globalThis;function u(){return i.__sharedCronService??=new a}}};var r=require("../../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[8375,6703,6244,1322,1773,4621,7519],()=>t(1652));module.exports=s})();
1
+ "use strict";(()=>{var e={};e.id=5044,e.ids=[5044],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},2993:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>q,patchFetch:()=>g,requestAsyncStorage:()=>l,routeModule:()=>c,serverHooks:()=>x,staticGenerationAsyncStorage:()=>h});var s={};t.r(s),t.d(s,{GET:()=>d,dynamic:()=>p});var o=t(7786),n=t(5042),a=t(2184),i=t(1890),u=t(7519);let p="force-dynamic";async function d(){return i.NextResponse.json(u.agentHost.getHarnessStatus(),{headers:{"cache-control":"no-store"}})}let c=new o.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/agent/harness/status/route",pathname:"/api/agent/harness/status",filename:"route",bundlePath:"app/api/agent/harness/status/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-39/customer-agent/packages/server/app/api/agent/harness/status/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:l,staticGenerationAsyncStorage:h,serverHooks:x}=c,q="/api/agent/harness/status/route";function g(){return(0,a.patchFetch)({serverHooks:x,staticGenerationAsyncStorage:h})}},1489:(e,r,t)=>{t.d(r,{N:()=>u});var s=t(1322),o=t(6279),n=t(785);class a{constructor(){this.tasks=new s.vo4((0,n.kO)()),this.scheduler=new o.ST(this.tasks,e=>{this.fire(e).catch(e=>console.error("Scheduled Customer Agent run failed",e))},()=>{}),this.scheduler.start()}async fire(e){let{agentHost:r}=await t.e(7519).then(t.bind(t,7519)),{getCustomerGoalCoordinator:s}=await Promise.all([t.e(7519),t.e(732)]).then(t.bind(t,732)),o=e.sessionId;o&&await r.getSessionStore().get(o)||(o=(await r.createSession(e.label||"定时任务")).id,this.tasks.update(e.id,{sessionId:o})),await s().enqueue(o,e.prompt)}call(e,r){let t=String(r[0]||"");switch(e){case"cronList":return this.tasks.list();case"cronCreate":{if("string"!=typeof r[0]||"string"!=typeof r[1]||!r[1].trim())throw Error("cron and prompt required");let e=r[2]&&"object"==typeof r[2]?r[2]:{};return this.tasks.create({cron:r[0],prompt:r[1],recurring:!1!==e.recurring,enabled:!0,durable:!0,..."string"==typeof e.sessionId?{sessionId:e.sessionId}:{},..."string"==typeof e.label?{label:e.label}:{}})}case"cronPause":return this.tasks.pause(t);case"cronResume":return this.tasks.resume(t);case"cronDelete":return this.tasks.delete(t);case"cronDeleteAll":return this.tasks.deleteAll(),{ok:!0};default:throw Error("Unsupported schedule operation")}}}let i=globalThis;function u(){return i.__sharedCronService??=new a}}};var r=require("../../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[8375,6703,6244,1322,1773,4621,7519],()=>t(2993));module.exports=s})();
@@ -1 +1 @@
1
- "use strict";(()=>{var e={};e.id=159,e.ids=[159,732],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},5206:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>y,requestAsyncStorage:()=>g,routeModule:()=>p,serverHooks:()=>w,staticGenerationAsyncStorage:()=>m});var s={};r.r(s),r.d(s,{GET:()=>h,dynamic:()=>c});var a=r(7786),i=r(5042),n=r(2184),o=r(732),u=r(1366),d=r(1890),l=r(7519);let c="force-dynamic";async function h(){return(0,o.U)(),(0,u.a)(),d.NextResponse.json({...l.agentHost.getModelConfig(),buildId:l.agentHost.getWebAppBuildId()},{headers:{"cache-control":"no-store"}})}let p=new a.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/agent/model/route",pathname:"/api/agent/model",filename:"route",bundlePath:"app/api/agent/model/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-37/customer-agent/packages/server/app/api/agent/model/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:g,staticGenerationAsyncStorage:m,serverHooks:w}=p,f="/api/agent/model/route";function y(){return(0,n.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:m})}},732:(e,t,r)=>{r.d(t,{getCustomerGoalCoordinator:()=>d,U:()=>l});var s=r(1322),a=r(7519);class i{constructor(e,t,r,s,a,i){this.store=e,this.busy=t,this.run=r,this.abort=s,this.steerRun=a,this.persist=i,this.tails=new Map,this.draining=new Set}async get(e,t=!0){let r=(0,s.E0T)((await this.require(e)).metadata);return t&&this.resume(e),r}async enqueue(e,t,r){let a=await this.mutate(e,a=>(0,s.WfK)(a,{id:crypto.randomUUID(),sessionId:e,objective:t,sourceMessageId:r,now:Date.now()}));return this.resume(e),a}async enqueueMessage(e,t,r,a){let i=await this.mutate(e,i=>[i.active,...i.queued,...i.history].some(e=>e?.sourceMessageId===r)?i:(0,s.InG)(i,{id:crypto.randomUUID(),sessionId:e,objective:t,sourceMessageId:r,messagePayload:a,now:Date.now(),activate:!1}));return this.resume(e),i}reorder(e,t,r=!1){return this.mutate(e,e=>r?(0,s.h1F)(e,t):(0,s.ZC9)(e,t))}updateMessage(e,t,r,a){return this.mutate(e,e=>(0,s.Wog)(e,t,r,a))}async cancel(e,t){let r=await this.mutate(e,r=>(r.active?.id===t&&this.draining.has(e)&&this.abort(e),(0,s.LJm)(r,t,Date.now())));return this.resume(e),r}async steer(e,t){return this.mutate(e,async r=>{let a=r.queued.find(e=>e.id===t&&"message"===e.kind);if(!a||!this.busy(e))throw Error("没有可引导的运行或排队消息");if(!await this.steerRun(e,a.objective))throw Error("运行已结束,请继续排队");return(0,s.LJm)(r,t,Date.now())})}resume(e){this.draining.has(e)||(this.draining.add(e),this.drain(e).catch(e=>console.error("Customer queue failed",e)).finally(()=>this.draining.delete(e)))}async drain(e){for(;;){let t;let r=await this.get(e,!1);if(!r.active&&!r.queued.length)return;if(this.busy(e)){await new Promise(e=>setTimeout(e,100));continue}let a=(await this.mutate(e,e=>(0,s.s_d)(e,Date.now()))).active;if(!a)continue;let i="failed";try{i=await this.run(e,a)}catch(e){if(e?.code==="SESSION_ALREADY_RUNNING")continue;t=e instanceof Error?e.message:String(e)}await this.mutate(e,e=>e.active?.id===a.id?(0,s.JXc)(e,i,Date.now(),t):e)}}async require(e){let t=await this.store.get(e);if(!t)throw Error("Session not found");return t}async mutate(e,t){let r=(this.tails.get(e)??Promise.resolve()).catch(()=>{}).then(async()=>{let r=await this.require(e),a=await t((0,s.E0T)(r.metadata));if(this.persist)this.persist(e,a);else{let t=await this.require(e);await this.store.update(e,{metadata:(0,s.eC7)(t.metadata,a)})}return a});this.tails.set(e,r);try{return await r}finally{this.tails.get(e)===r&&this.tails.delete(e)}}}var n=r(785);let o=globalThis,u=new Set;function d(){return o.__sharedCustomerQueue??=new i(a.agentHost.getSessionStore(),e=>a.agentHost.isSessionRunning(e),async(e,t)=>{u.add(e);try{return await a.agentHost.startRun(t.objective,e,t.messagePayload?.images,{agentIds:t.messagePayload?.agentIds}).completion,(await a.agentHost.getSessionStore().get(e))?.status==="completed"?"completed":"failed"}finally{u.delete(e)}},e=>{u.has(e)&&a.agentHost.abort(e)},(e,t)=>a.agentHost.steer(t,e),(e,t)=>{(0,s.N8n)((0,n.kO)()).db.prepare("UPDATE sessions SET metadata = json_set(metadata, '$.goalState', json(?)), updated = ? WHERE id = ?").run(JSON.stringify(t),new Date().toISOString(),e)})}function l(){for(let e of(0,s.N8n)((0,n.kO)()).db.prepare("SELECT id FROM sessions WHERE json_extract(metadata, '$.goalState.active') IS NOT NULL OR json_array_length(metadata, '$.goalState.queued') > 0").all())d().resume(e.id)}},1489:(e,t,r)=>{r.d(t,{N:()=>u});var s=r(1322),a=r(6279),i=r(785);class n{constructor(){this.tasks=new s.vo4((0,i.kO)()),this.scheduler=new a.ST(this.tasks,e=>{this.fire(e).catch(e=>console.error("Scheduled Customer Agent run failed",e))},()=>{}),this.scheduler.start()}async fire(e){let{agentHost:t}=await r.e(7519).then(r.bind(r,7519)),{getCustomerGoalCoordinator:s}=await Promise.all([r.e(7519),r.e(732)]).then(r.bind(r,732)),a=e.sessionId;a&&await t.getSessionStore().get(a)||(a=(await t.createSession(e.label||"定时任务")).id,this.tasks.update(e.id,{sessionId:a})),await s().enqueue(a,e.prompt)}call(e,t){let r=String(t[0]||"");switch(e){case"cronList":return this.tasks.list();case"cronCreate":{if("string"!=typeof t[0]||"string"!=typeof t[1]||!t[1].trim())throw Error("cron and prompt required");let e=t[2]&&"object"==typeof t[2]?t[2]:{};return this.tasks.create({cron:t[0],prompt:t[1],recurring:!1!==e.recurring,enabled:!0,durable:!0,..."string"==typeof e.sessionId?{sessionId:e.sessionId}:{},..."string"==typeof e.label?{label:e.label}:{}})}case"cronPause":return this.tasks.pause(r);case"cronResume":return this.tasks.resume(r);case"cronDelete":return this.tasks.delete(r);case"cronDeleteAll":return this.tasks.deleteAll(),{ok:!0};default:throw Error("Unsupported schedule operation")}}}let o=globalThis;function u(){return o.__sharedCronService??=new n}},1366:(e,t,r)=>{r.d(t,{C:()=>o,a:()=>u});var s=r(1322),a=r(7519),i=r(785);let n=globalThis;function o(){if(n.__threadGoalService)return n.__threadGoalService;let e=new s.rA9(new s.ZIW((0,i.kO)()),{isSessionRunning:e=>a.agentHost.isSessionRunning(e),startTurn:async(e,t)=>{if(a.agentHost.isSessionRunning(e))return!1;try{return a.agentHost.startRun(t,e,void 0,{source:"goal"}).completion.catch(()=>{}),!0}catch(e){if(e instanceof a.A)return!1;throw e}},steerHidden:(e,t)=>a.agentHost.steer(t,e,"__goal__"),sessionExists:async e=>!!await a.agentHost.getSessionStore().get(e)},{onUpdated:(e,t)=>a.agentHost.publishExternal(e,{type:"goal_updated",goal:t}),onCleared:e=>a.agentHost.publishExternal(e,{type:"goal_cleared",sessionId:e})});return a.agentHost.onRunSettled=t=>{e.onRunSettled({sessionId:t.sessionId,failed:t.failed,usageLimited:t.usageLimited,tokens:t.newTokens,seconds:t.durationMs/1e3}).catch(()=>{})},a.agentHost.threadGoalToolsProvider=t=>(0,s.DAt)(e,t),n.__threadGoalService=e,e}function u(){o().resumeInterrupted().catch(()=>{})}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[8375,6703,6244,1322,1773,4621,7519],()=>r(5206));module.exports=s})();
1
+ "use strict";(()=>{var e={};e.id=159,e.ids=[159,732],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},9319:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>y,requestAsyncStorage:()=>g,routeModule:()=>p,serverHooks:()=>w,staticGenerationAsyncStorage:()=>m});var s={};r.r(s),r.d(s,{GET:()=>h,dynamic:()=>c});var a=r(7786),i=r(5042),n=r(2184),o=r(732),u=r(1366),d=r(1890),l=r(7519);let c="force-dynamic";async function h(){return(0,o.U)(),(0,u.a)(),d.NextResponse.json({...l.agentHost.getModelConfig(),buildId:l.agentHost.getWebAppBuildId()},{headers:{"cache-control":"no-store"}})}let p=new a.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/agent/model/route",pathname:"/api/agent/model",filename:"route",bundlePath:"app/api/agent/model/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-39/customer-agent/packages/server/app/api/agent/model/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:g,staticGenerationAsyncStorage:m,serverHooks:w}=p,f="/api/agent/model/route";function y(){return(0,n.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:m})}},732:(e,t,r)=>{r.d(t,{getCustomerGoalCoordinator:()=>d,U:()=>l});var s=r(1322),a=r(7519);class i{constructor(e,t,r,s,a,i){this.store=e,this.busy=t,this.run=r,this.abort=s,this.steerRun=a,this.persist=i,this.tails=new Map,this.draining=new Set}async get(e,t=!0){let r=(0,s.E0T)((await this.require(e)).metadata);return t&&this.resume(e),r}async enqueue(e,t,r){let a=await this.mutate(e,a=>(0,s.WfK)(a,{id:crypto.randomUUID(),sessionId:e,objective:t,sourceMessageId:r,now:Date.now()}));return this.resume(e),a}async enqueueMessage(e,t,r,a){let i=await this.mutate(e,i=>[i.active,...i.queued,...i.history].some(e=>e?.sourceMessageId===r)?i:(0,s.InG)(i,{id:crypto.randomUUID(),sessionId:e,objective:t,sourceMessageId:r,messagePayload:a,now:Date.now(),activate:!1}));return this.resume(e),i}reorder(e,t,r=!1){return this.mutate(e,e=>r?(0,s.h1F)(e,t):(0,s.ZC9)(e,t))}updateMessage(e,t,r,a){return this.mutate(e,e=>(0,s.Wog)(e,t,r,a))}async cancel(e,t){let r=await this.mutate(e,r=>(r.active?.id===t&&this.draining.has(e)&&this.abort(e),(0,s.LJm)(r,t,Date.now())));return this.resume(e),r}async steer(e,t){return this.mutate(e,async r=>{let a=r.queued.find(e=>e.id===t&&"message"===e.kind);if(!a||!this.busy(e))throw Error("没有可引导的运行或排队消息");if(!await this.steerRun(e,a.objective))throw Error("运行已结束,请继续排队");return(0,s.LJm)(r,t,Date.now())})}resume(e){this.draining.has(e)||(this.draining.add(e),this.drain(e).catch(e=>console.error("Customer queue failed",e)).finally(()=>this.draining.delete(e)))}async drain(e){for(;;){let t;let r=await this.get(e,!1);if(!r.active&&!r.queued.length)return;if(this.busy(e)){await new Promise(e=>setTimeout(e,100));continue}let a=(await this.mutate(e,e=>(0,s.s_d)(e,Date.now()))).active;if(!a)continue;let i="failed";try{i=await this.run(e,a)}catch(e){if(e?.code==="SESSION_ALREADY_RUNNING")continue;t=e instanceof Error?e.message:String(e)}await this.mutate(e,e=>e.active?.id===a.id?(0,s.JXc)(e,i,Date.now(),t):e)}}async require(e){let t=await this.store.get(e);if(!t)throw Error("Session not found");return t}async mutate(e,t){let r=(this.tails.get(e)??Promise.resolve()).catch(()=>{}).then(async()=>{let r=await this.require(e),a=await t((0,s.E0T)(r.metadata));if(this.persist)this.persist(e,a);else{let t=await this.require(e);await this.store.update(e,{metadata:(0,s.eC7)(t.metadata,a)})}return a});this.tails.set(e,r);try{return await r}finally{this.tails.get(e)===r&&this.tails.delete(e)}}}var n=r(785);let o=globalThis,u=new Set;function d(){return o.__sharedCustomerQueue??=new i(a.agentHost.getSessionStore(),e=>a.agentHost.isSessionRunning(e),async(e,t)=>{u.add(e);try{return await a.agentHost.startRun(t.objective,e,t.messagePayload?.images,{agentIds:t.messagePayload?.agentIds}).completion,(await a.agentHost.getSessionStore().get(e))?.status==="completed"?"completed":"failed"}finally{u.delete(e)}},e=>{u.has(e)&&a.agentHost.abort(e)},(e,t)=>a.agentHost.steer(t,e),(e,t)=>{(0,s.N8n)((0,n.kO)()).db.prepare("UPDATE sessions SET metadata = json_set(metadata, '$.goalState', json(?)), updated = ? WHERE id = ?").run(JSON.stringify(t),new Date().toISOString(),e)})}function l(){for(let e of(0,s.N8n)((0,n.kO)()).db.prepare("SELECT id FROM sessions WHERE json_extract(metadata, '$.goalState.active') IS NOT NULL OR json_array_length(metadata, '$.goalState.queued') > 0").all())d().resume(e.id)}},1489:(e,t,r)=>{r.d(t,{N:()=>u});var s=r(1322),a=r(6279),i=r(785);class n{constructor(){this.tasks=new s.vo4((0,i.kO)()),this.scheduler=new a.ST(this.tasks,e=>{this.fire(e).catch(e=>console.error("Scheduled Customer Agent run failed",e))},()=>{}),this.scheduler.start()}async fire(e){let{agentHost:t}=await r.e(7519).then(r.bind(r,7519)),{getCustomerGoalCoordinator:s}=await Promise.all([r.e(7519),r.e(732)]).then(r.bind(r,732)),a=e.sessionId;a&&await t.getSessionStore().get(a)||(a=(await t.createSession(e.label||"定时任务")).id,this.tasks.update(e.id,{sessionId:a})),await s().enqueue(a,e.prompt)}call(e,t){let r=String(t[0]||"");switch(e){case"cronList":return this.tasks.list();case"cronCreate":{if("string"!=typeof t[0]||"string"!=typeof t[1]||!t[1].trim())throw Error("cron and prompt required");let e=t[2]&&"object"==typeof t[2]?t[2]:{};return this.tasks.create({cron:t[0],prompt:t[1],recurring:!1!==e.recurring,enabled:!0,durable:!0,..."string"==typeof e.sessionId?{sessionId:e.sessionId}:{},..."string"==typeof e.label?{label:e.label}:{}})}case"cronPause":return this.tasks.pause(r);case"cronResume":return this.tasks.resume(r);case"cronDelete":return this.tasks.delete(r);case"cronDeleteAll":return this.tasks.deleteAll(),{ok:!0};default:throw Error("Unsupported schedule operation")}}}let o=globalThis;function u(){return o.__sharedCronService??=new n}},1366:(e,t,r)=>{r.d(t,{C:()=>o,a:()=>u});var s=r(1322),a=r(7519),i=r(785);let n=globalThis;function o(){if(n.__threadGoalService)return n.__threadGoalService;let e=new s.rA9(new s.ZIW((0,i.kO)()),{isSessionRunning:e=>a.agentHost.isSessionRunning(e),startTurn:async(e,t)=>{if(a.agentHost.isSessionRunning(e))return!1;try{return a.agentHost.startRun(t,e,void 0,{source:"goal"}).completion.catch(()=>{}),!0}catch(e){if(e instanceof a.A)return!1;throw e}},steerHidden:(e,t)=>a.agentHost.steer(t,e,"__goal__"),sessionExists:async e=>!!await a.agentHost.getSessionStore().get(e)},{onUpdated:(e,t)=>a.agentHost.publishExternal(e,{type:"goal_updated",goal:t}),onCleared:e=>a.agentHost.publishExternal(e,{type:"goal_cleared",sessionId:e})});return a.agentHost.onRunSettled=t=>{e.onRunSettled({sessionId:t.sessionId,failed:t.failed,usageLimited:t.usageLimited,tokens:t.newTokens,seconds:t.durationMs/1e3}).catch(()=>{})},a.agentHost.threadGoalToolsProvider=t=>(0,s.DAt)(e,t),n.__threadGoalService=e,e}function u(){o().resumeInterrupted().catch(()=>{})}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[8375,6703,6244,1322,1773,4621,7519],()=>r(9319));module.exports=s})();
@@ -1 +1 @@
1
- "use strict";(()=>{var e={};e.id=7927,e.ids=[7927],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},9971:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>g,patchFetch:()=>w,requestAsyncStorage:()=>h,routeModule:()=>p,serverHooks:()=>f,staticGenerationAsyncStorage:()=>m});var n={};r.r(n),r.d(n,{GET:()=>d,dynamic:()=>c});var i=r(7786),s=r(5042),o=r(2184),a=r(1890),u=r(6279),l=r(1614);let c="force-dynamic";async function d(e){let t=new URL(e.url).searchParams.get("agentType");if("codex"!==t&&"claude-code"!==t&&"opencode"!==t)return a.NextResponse.json({error:"agentType must be codex, claude-code or opencode"},{status:400});try{let e=await (0,l.NL)().listModels(t);return a.NextResponse.json({agentType:t,models:e})}catch(e){if(e instanceof u.no&&"OPERATION_NOT_SUPPORTED"===e.code)return a.NextResponse.json({agentType:t,models:[],supported:!1});return a.NextResponse.json({error:e instanceof Error?e.message:"Failed to list models"},{status:(0,l.WW)(e)})}}let p=new i.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/agent/models/route",pathname:"/api/agent/models",filename:"route",bundlePath:"app/api/agent/models/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-37/customer-agent/packages/server/app/api/agent/models/route.ts",nextConfigOutput:"standalone",userland:n}),{requestAsyncStorage:h,staticGenerationAsyncStorage:m,serverHooks:f}=p,g="/api/agent/models/route";function w(){return(0,o.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:m})}},535:(e,t,r)=>{r.d(t,{L:()=>o});var n=r(1322),i=r(785);let s=!1;function o(){let e=(0,n.Qfc)();if(e)return e;let t=(0,n.qZ_)({dir:(0,i.ME)(),source:"server",minLevel:"info",handlers:{exitOnUncaughtException:!1}});return s||(s=!0,t.info("server logger attached",{dir:t.dir,pid:process.pid})),t}},1614:(e,t,r)=>{r.d(t,{NL:()=>O,V_:()=>P,WW:()=>T});var n=r(7561),i=r(612),s=r(9411),o=r(7718),a=r(1322);function u(e){if(!e.trim())return!1;try{return(0,n.accessSync)(e,n.constants.X_OK),!0}catch{return!1}}function l(e){try{return(0,a.wyD)((0,o.execFileSync)(e,["--version"],{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","pipe"]}))}catch{return}}function c(e){let t=[],r=process.env[e.environmentVariable]?.trim();if(r){let n=u(r);t.push({source:"pin",path:r,executable:n,version:n?l(r):void 0,error:n?void 0:`${e.environmentVariable} "${r}" is not executable`})}let n=function(e){for(let t of(process.env.PATH??"").split(s.delimiter).filter(Boolean)){let r=(0,s.resolve)(t,e);if(u(r))return r}}(e.name);return n&&n!==r&&t.push({source:"path",path:n,executable:!0,version:l(n)}),(0,a.neJ)(t,{name:e.name,minimumVersion:e.minimumVersion})}var d=r(535),p=r(6279),h=r(785);let m=globalThis;class f{constructor(e,t=async()=>[],r=process.platform){this.runtime=e,this.listProjects=t,this.platform=r,this.pendingCreations=new Map}health(){return this.runtime.health()}listModels(e){return this.runtime.listModels(e)}listWorkspaces(e,t){return this.runtime.listWorkspaces(e,t)}importWorkspace(e,t,r){if(!this.runtime.importWorkspace)throw new p.no("Native workspace import is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.importWorkspace(e,t,r)}async listWorkspaceSessions(e,t,r){let n=await this.runtime.listWorkspaceSessions(e,t,r);if(r?.cursor)return n;let i=new Set(n.data.map(e=>e.id)),s=n.data.map(e=>{let t=this.pendingCreations.get(e.id);return t?(this.pendingCreations.delete(e.id),g(e,t)):e});for(let r of this.pendingCreations.values())r.agentType!==e||r.projectId!==t||i.has(r.id)||s.unshift(r);return{...n,data:s}}async list(e){let[t,r]=await Promise.all([this.runtime.list(),this.listProjects()]);return E(this.withPendingCreations(t).map(e=>N(e,r,this.platform)),e)}async refresh(e){let[t,r]=await Promise.all([this.runtime.refresh(),this.listProjects()]);return E(this.withPendingCreations(t).map(e=>N(e,r,this.platform)),e)}async create(e){let t=N(await this.runtime.create(e),await this.listProjects(),this.platform),r=e.projectId?{...t,projectId:e.projectId}:t;return this.pendingCreations.set(r.id,r),r}async fork(e){if(!P(e))throw new p.no("Customer Agent sessions do not support native forks","OPERATION_NOT_SUPPORTED");let t=N(await this.runtime.fork(e),await this.listProjects(),this.platform);return this.pendingCreations.set(t.id,t),t}async delete(e){await this.runtime.delete(e),this.pendingCreations.delete(e)}async get(e,t){let r;try{r=await this.runtime.get(e,t)}catch(n){let r=this.pendingCreations.get(e);if(!r)throw n;return t?{...r,messages:[],events:[],history:{nextCursor:null,hasMore:!1,pageSize:0,totalItems:0}}:{...r,messages:[],events:[]}}return N(r,await this.listProjects(),this.platform)}async getQueryIndex(e){if(this.runtime.getQueryIndex)return this.runtime.getQueryIndex(e);let t=await this.runtime.get(e),{buildSessionQueryIndex:n}=await Promise.resolve().then(r.bind(r,1322));return n(e,t.messages)}getSessionToolResult(e,t){return this.runtime.getSessionToolResult(e,t)}getSessionWatchPath(e){return this.runtime.getSessionWatchPath(e)}run(e,t,r,n,i){return this.runtime.run(e,t,r,n,i)}steer(e,t){return this.runtime.steer(e,t)}abort(e){return this.runtime.abort(e)}async release(e){if(!this.runtime.release)throw new p.no("Native runtime release is unavailable","RUNTIME_UNAVAILABLE");await this.runtime.release(e)}answerQuestion(e,t){return this.runtime.answerQuestion(e,t)}async startRun(e,t,r,n="web",i){if(!this.runtime.startRun)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.startRun(e,t,r,n,i)}async subscribe(e,t,r){if(!this.runtime.subscribe)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.subscribe(e,t,r)}async snapshot(e,t=0){if(!this.runtime.snapshot)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.snapshot(e,t)}async setPermissionMode(e,t){if(!this.runtime.setPermissionMode)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.setPermissionMode(e,t)}async handoff(e,t){if(!this.runtime.handoff)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.handoff(e,t)}async getGoals(e,t="web"){if(!this.runtime.getGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.getGoals(e,t)}async enqueueGoal(e,t,r,n="web"){if(!this.runtime.enqueueGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueGoal(e,t,r,n)}async reorderGoals(e,t){if(!this.runtime.reorderGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderGoals(e,t)}async cancelGoal(e,t){if(!this.runtime.cancelGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelGoal(e,t,"web")}async enqueueMessage(e,t,r="web"){if(!this.runtime.enqueueMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueMessage(e,t,r)}async reorderMessages(e,t){if(!this.runtime.reorderMessages)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderMessages(e,t)}async updateMessage(e,t,r,n){if(!this.runtime.updateMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.updateMessage(e,t,r,n)}async cancelMessage(e,t){if(!this.runtime.cancelMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelMessage(e,t)}async steerMessage(e,t){if(!this.runtime.steerMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.steerMessage(e,t)}withPendingCreations(e){let t=new Set,r=e.map(e=>{t.add(e.id);let r=this.pendingCreations.get(e.id);return this.pendingCreations.delete(e.id),r?g(e,r):e});return[...[...this.pendingCreations.values()].filter(e=>!t.has(e.id)).sort((e,t)=>t.updated.localeCompare(e.updated)),...r]}}function g(e,t){return{...e,cwd:e.cwd||t.cwd,projectId:e.projectId??t.projectId}}function w(e,t){t.executable?delete process.env[e]:process.env[e]=t.detail}function O(){if(!m.__nativeRuntimeService){!function(){let e=[(0,s.join)((0,i.homedir)(),".local","bin"),"/opt/homebrew/bin","/usr/local/bin"],t=(process.env.PATH??"").split(s.delimiter),r=e.filter(e=>(0,n.existsSync)(e)&&!t.includes(e));r.length>0&&(process.env.PATH=[...t,...r].join(s.delimiter))}();let e=new a.XWE((0,h.kO)());m.__nativeRuntimeService=new f((0,p.v6)({runtimeFactory:e=>{let t=c({name:"codex",environmentVariable:"AGENT_CODEX_BIN",minimumVersion:a.hix}),r=c({name:"opencode",environmentVariable:"AGENT_OPENCODE_BIN"});return process.pid,w("AGENT_CODEX_RUNTIME_ERROR",t),w("AGENT_OPENCODE_RUNTIME_ERROR",r),(0,d.L)().info("native runtime host elected",{pid:process.pid,codex:t.executable??null,codexSource:t.source??null,codexDetail:t.detail,opencode:r.executable??null,opencodeDetail:r.detail}),(0,p.WH)(t.executable??"codex",e,r.executable??"opencode")}}),()=>e.list())}return m.__nativeRuntimeService}function N(e,t,r=process.platform){let{projectId:n,...i}=e;if(!e.cwd)return i;let o=v(e.cwd,r),a="win32"===r?s.win32.sep:s.sep,u=t.filter(e=>e.description).map(e=>({project:e,path:v(e.description,r)})).filter(({path:e})=>o===e||o.startsWith(`${e}${a}`)).sort((e,t)=>t.path.length-e.path.length)[0];return u?{...i,projectId:u.project.id}:i}function v(e,t=process.platform){if("win32"!==t)return(0,s.resolve)(e);let r=s.win32.resolve(e),n=s.win32.parse(r).root;return(r.length>n.length?r.replace(/[\\/]+$/,""):r).toLowerCase()}function E(e,t){return void 0===t?e:e.filter(e=>e.projectId===t)}function P(e){try{return"customer-agent"!==(0,p.Vu)(e).agentType}catch{return!1}}function T(e){if(e instanceof p.no)switch(e.code){case"SESSION_NOT_FOUND":return 404;case"SESSION_OCCUPIED":case"SESSION_ALREADY_RUNNING":case"APPROVAL_EXPIRED":case"CODEX_SESSION_VERSION_INCOMPATIBLE":case"STALE_SESSION_ANCHOR":return 409;case"RUNTIME_UNAVAILABLE":return 503;case"OPERATION_NOT_SUPPORTED":return 405;default:return 400}return 500}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),n=t.X(0,[8375,6703,6244,1322,1773],()=>r(9971));module.exports=n})();
1
+ "use strict";(()=>{var e={};e.id=7927,e.ids=[7927],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},894:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>g,patchFetch:()=>w,requestAsyncStorage:()=>h,routeModule:()=>p,serverHooks:()=>f,staticGenerationAsyncStorage:()=>m});var n={};r.r(n),r.d(n,{GET:()=>d,dynamic:()=>c});var i=r(7786),s=r(5042),o=r(2184),a=r(1890),u=r(6279),l=r(1614);let c="force-dynamic";async function d(e){let t=new URL(e.url).searchParams.get("agentType");if("codex"!==t&&"claude-code"!==t&&"opencode"!==t)return a.NextResponse.json({error:"agentType must be codex, claude-code or opencode"},{status:400});try{let e=await (0,l.NL)().listModels(t);return a.NextResponse.json({agentType:t,models:e})}catch(e){if(e instanceof u.no&&"OPERATION_NOT_SUPPORTED"===e.code)return a.NextResponse.json({agentType:t,models:[],supported:!1});return a.NextResponse.json({error:e instanceof Error?e.message:"Failed to list models"},{status:(0,l.WW)(e)})}}let p=new i.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/agent/models/route",pathname:"/api/agent/models",filename:"route",bundlePath:"app/api/agent/models/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-39/customer-agent/packages/server/app/api/agent/models/route.ts",nextConfigOutput:"standalone",userland:n}),{requestAsyncStorage:h,staticGenerationAsyncStorage:m,serverHooks:f}=p,g="/api/agent/models/route";function w(){return(0,o.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:m})}},535:(e,t,r)=>{r.d(t,{L:()=>o});var n=r(1322),i=r(785);let s=!1;function o(){let e=(0,n.Qfc)();if(e)return e;let t=(0,n.qZ_)({dir:(0,i.ME)(),source:"server",minLevel:"info",handlers:{exitOnUncaughtException:!1}});return s||(s=!0,t.info("server logger attached",{dir:t.dir,pid:process.pid})),t}},1614:(e,t,r)=>{r.d(t,{NL:()=>O,V_:()=>P,WW:()=>T});var n=r(7561),i=r(612),s=r(9411),o=r(7718),a=r(1322);function u(e){if(!e.trim())return!1;try{return(0,n.accessSync)(e,n.constants.X_OK),!0}catch{return!1}}function l(e){try{return(0,a.wyD)((0,o.execFileSync)(e,["--version"],{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","pipe"]}))}catch{return}}function c(e){let t=[],r=process.env[e.environmentVariable]?.trim();if(r){let n=u(r);t.push({source:"pin",path:r,executable:n,version:n?l(r):void 0,error:n?void 0:`${e.environmentVariable} "${r}" is not executable`})}let n=function(e){for(let t of(process.env.PATH??"").split(s.delimiter).filter(Boolean)){let r=(0,s.resolve)(t,e);if(u(r))return r}}(e.name);return n&&n!==r&&t.push({source:"path",path:n,executable:!0,version:l(n)}),(0,a.neJ)(t,{name:e.name,minimumVersion:e.minimumVersion})}var d=r(535),p=r(6279),h=r(785);let m=globalThis;class f{constructor(e,t=async()=>[],r=process.platform){this.runtime=e,this.listProjects=t,this.platform=r,this.pendingCreations=new Map}health(){return this.runtime.health()}listModels(e){return this.runtime.listModels(e)}listWorkspaces(e,t){return this.runtime.listWorkspaces(e,t)}importWorkspace(e,t,r){if(!this.runtime.importWorkspace)throw new p.no("Native workspace import is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.importWorkspace(e,t,r)}async listWorkspaceSessions(e,t,r){let n=await this.runtime.listWorkspaceSessions(e,t,r);if(r?.cursor)return n;let i=new Set(n.data.map(e=>e.id)),s=n.data.map(e=>{let t=this.pendingCreations.get(e.id);return t?(this.pendingCreations.delete(e.id),g(e,t)):e});for(let r of this.pendingCreations.values())r.agentType!==e||r.projectId!==t||i.has(r.id)||s.unshift(r);return{...n,data:s}}async list(e){let[t,r]=await Promise.all([this.runtime.list(),this.listProjects()]);return E(this.withPendingCreations(t).map(e=>N(e,r,this.platform)),e)}async refresh(e){let[t,r]=await Promise.all([this.runtime.refresh(),this.listProjects()]);return E(this.withPendingCreations(t).map(e=>N(e,r,this.platform)),e)}async create(e){let t=N(await this.runtime.create(e),await this.listProjects(),this.platform),r=e.projectId?{...t,projectId:e.projectId}:t;return this.pendingCreations.set(r.id,r),r}async fork(e,t){if(!P(e))throw new p.no("Customer Agent sessions do not support native forks","OPERATION_NOT_SUPPORTED");let r=N(t?await this.runtime.fork(e,t):await this.runtime.fork(e),await this.listProjects(),this.platform);return this.pendingCreations.set(r.id,r),r}async delete(e){await this.runtime.delete(e),this.pendingCreations.delete(e)}async get(e,t){let r;try{r=await this.runtime.get(e,t)}catch(n){let r=this.pendingCreations.get(e);if(!r)throw n;return t?{...r,messages:[],events:[],history:{nextCursor:null,hasMore:!1,pageSize:0,totalItems:0}}:{...r,messages:[],events:[]}}return N(r,await this.listProjects(),this.platform)}async getQueryIndex(e){if(this.runtime.getQueryIndex)return this.runtime.getQueryIndex(e);let t=await this.runtime.get(e),{buildSessionQueryIndex:n}=await Promise.resolve().then(r.bind(r,1322));return n(e,t.messages)}getSessionToolResult(e,t){return this.runtime.getSessionToolResult(e,t)}getSessionWatchPath(e){return this.runtime.getSessionWatchPath(e)}run(e,t,r,n,i){return this.runtime.run(e,t,r,n,i)}steer(e,t){return this.runtime.steer(e,t)}abort(e){return this.runtime.abort(e)}async release(e){if(!this.runtime.release)throw new p.no("Native runtime release is unavailable","RUNTIME_UNAVAILABLE");await this.runtime.release(e)}answerQuestion(e,t){return this.runtime.answerQuestion(e,t)}async startRun(e,t,r,n="web",i){if(!this.runtime.startRun)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.startRun(e,t,r,n,i)}async subscribe(e,t,r){if(!this.runtime.subscribe)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.subscribe(e,t,r)}async snapshot(e,t=0){if(!this.runtime.snapshot)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.snapshot(e,t)}async setPermissionMode(e,t){if(!this.runtime.setPermissionMode)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.setPermissionMode(e,t)}async handoff(e,t){if(!this.runtime.handoff)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.handoff(e,t)}async getGoals(e,t="web"){if(!this.runtime.getGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.getGoals(e,t)}async enqueueGoal(e,t,r,n="web"){if(!this.runtime.enqueueGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueGoal(e,t,r,n)}async reorderGoals(e,t){if(!this.runtime.reorderGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderGoals(e,t)}async cancelGoal(e,t){if(!this.runtime.cancelGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelGoal(e,t,"web")}async enqueueMessage(e,t,r="web"){if(!this.runtime.enqueueMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueMessage(e,t,r)}async reorderMessages(e,t){if(!this.runtime.reorderMessages)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderMessages(e,t)}async updateMessage(e,t,r,n){if(!this.runtime.updateMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.updateMessage(e,t,r,n)}async cancelMessage(e,t){if(!this.runtime.cancelMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelMessage(e,t)}async steerMessage(e,t){if(!this.runtime.steerMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.steerMessage(e,t)}withPendingCreations(e){let t=new Set,r=e.map(e=>{t.add(e.id);let r=this.pendingCreations.get(e.id);return this.pendingCreations.delete(e.id),r?g(e,r):e});return[...[...this.pendingCreations.values()].filter(e=>!t.has(e.id)).sort((e,t)=>t.updated.localeCompare(e.updated)),...r]}}function g(e,t){return{...e,cwd:e.cwd||t.cwd,projectId:e.projectId??t.projectId}}function w(e,t){t.executable?delete process.env[e]:process.env[e]=t.detail}function O(){if(!m.__nativeRuntimeService){!function(){let e=[(0,s.join)((0,i.homedir)(),".local","bin"),"/opt/homebrew/bin","/usr/local/bin"],t=(process.env.PATH??"").split(s.delimiter),r=e.filter(e=>(0,n.existsSync)(e)&&!t.includes(e));r.length>0&&(process.env.PATH=[...t,...r].join(s.delimiter))}();let e=new a.XWE((0,h.kO)());m.__nativeRuntimeService=new f((0,p.v6)({runtimeFactory:e=>{let t=c({name:"codex",environmentVariable:"AGENT_CODEX_BIN",minimumVersion:a.hix}),r=c({name:"opencode",environmentVariable:"AGENT_OPENCODE_BIN"});return process.pid,w("AGENT_CODEX_RUNTIME_ERROR",t),w("AGENT_OPENCODE_RUNTIME_ERROR",r),(0,d.L)().info("native runtime host elected",{pid:process.pid,codex:t.executable??null,codexSource:t.source??null,codexDetail:t.detail,opencode:r.executable??null,opencodeDetail:r.detail}),(0,p.WH)(t.executable??"codex",e,r.executable??"opencode")}}),()=>e.list())}return m.__nativeRuntimeService}function N(e,t,r=process.platform){let{projectId:n,...i}=e;if(!e.cwd)return i;let o=v(e.cwd,r),a="win32"===r?s.win32.sep:s.sep,u=t.filter(e=>e.description).map(e=>({project:e,path:v(e.description,r)})).filter(({path:e})=>o===e||o.startsWith(`${e}${a}`)).sort((e,t)=>t.path.length-e.path.length)[0];return u?{...i,projectId:u.project.id}:i}function v(e,t=process.platform){if("win32"!==t)return(0,s.resolve)(e);let r=s.win32.resolve(e),n=s.win32.parse(r).root;return(r.length>n.length?r.replace(/[\\/]+$/,""):r).toLowerCase()}function E(e,t){return void 0===t?e:e.filter(e=>e.projectId===t)}function P(e){try{return"customer-agent"!==(0,p.Vu)(e).agentType}catch{return!1}}function T(e){if(e instanceof p.no)switch(e.code){case"SESSION_NOT_FOUND":return 404;case"SESSION_OCCUPIED":case"SESSION_ALREADY_RUNNING":case"APPROVAL_EXPIRED":case"CODEX_SESSION_VERSION_INCOMPATIBLE":case"STALE_SESSION_ANCHOR":return 409;case"RUNTIME_UNAVAILABLE":return 503;case"OPERATION_NOT_SUPPORTED":return 405;default:return 400}return 500}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),n=t.X(0,[8375,6703,6244,1322,1773],()=>r(894));module.exports=n})();
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=2616,e.ids=[2616],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},7083:(e,t,s)=>{s.r(t),s.d(t,{originalPathname:()=>w,patchFetch:()=>N,requestAsyncStorage:()=>v,routeModule:()=>E,serverHooks:()=>T,staticGenerationAsyncStorage:()=>y});var r={};s.r(r),s.d(r,{POST:()=>I});var n=s(7786),i=s(5042),o=s(2184),a=s(1890),u=s(1322),l=s(6279),d=s(7519),c=s(1614),p=s(535),h=s(1079),m=s(4621),g=s(1982),f=s(8615);async function I(e){try{var t,s;(0,h.j)();let r=await e.json();if(!r.input)return a.NextResponse.json({error:"input is required"},{status:400});if(void 0!==r.agentIds&&(!Array.isArray(r.agentIds)||r.agentIds.length>20||r.agentIds.some(e=>"string"!=typeof e||!e.trim())))return a.NextResponse.json({error:"agentIds must contain at most 20 non-empty IDs"},{status:400});if(void 0!==r.agentId&&void 0!==r.agentIds)return a.NextResponse.json({error:"agentId and agentIds are mutually exclusive"},{status:400});if(void 0!==r.profileId&&("string"!=typeof r.profileId||!r.profileId.trim()||r.profileId.length>200))return a.NextResponse.json({error:"profileId must be a non-empty string"},{status:400});if(r.sessionId&&(0,c.V_)(r.sessionId)){let e=r.sessionId,t=(0,c.NL)(),s=await t.startRun(e,r.input,r.images,"web",{...r.nativeModel?.id?{model:r.nativeModel}:{},...r.nativeReasoningEffort?{reasoningEffort:r.nativeReasoningEffort}:{}});d.agentHost.resetExternalStream(e),d.agentHost.publishExternal(e,{type:"run_admitted",_nativeRunId:s.runId,_nativeSequence:s.snapshotRevision});let n=null,i=!1;return t.subscribe(e,0,({event:t})=>{d.agentHost.publishExternal(e,t),("done"===t.type||"error"===t.type)&&(i=!0,n?.())}).then(e=>{n=e,i&&e()}).catch(t=>{let s=t instanceof l.no?t.code:void 0;(0,p.L)().error("native run subscription failed",t,{sessionId:e,code:s}),d.agentHost.publishExternal(e,{type:"error",message:t instanceof Error?t.message:"Native run subscription failed",...s?{code:s}:{}})}),a.NextResponse.json({sessionId:e,streamUrl:`/api/agent/stream?sessionId=${e}`,runId:s.runId,snapshotRevision:s.snapshotRevision})}let n=d.agentHost.getSessionStore(),i={maxIterations:"number"!=typeof(t=r.maxIterations)||!Number.isFinite(t)||t<0?10:Math.trunc(t),maxTokens:"number"==typeof(s=r.maxTokens)&&Number.isFinite(s)?Math.min(2e6,Math.max(8e3,Math.trunc(s))):1e5},o=r.agentId??(r.agentIds?.length===1?r.agentIds[0]:void 0),I=(0,m.i)(),E=new u.R0$(n,{getAgent:e=>I.agents.get(e),getSkill:async e=>I.skills.get(e)??(await I.call("listSkills",[])).find(t=>t.name===e)??null,hasModelProfile:e=>(0,g.dp)().read().profiles.some(t=>t.id===e),getToolExecutionPolicy:e=>(0,f.cm)().get(e)},{assertAvailable:e=>{if(d.agentHost.isSessionRunning(e))throw new d.A(e)},start:e=>{let t=d.agentHost.startRun(e.message,e.sessionId,e.images,{...r.model?{model:r.model}:{},...e.modelProfileId?{profileId:e.modelProfileId}:{},...r.reasoningEffort?{reasoningEffort:r.reasoningEffort}:{},...void 0===r.maxIterations?{}:{maxIterations:i.maxIterations},...void 0===r.maxTokens?{}:{maxTokens:i.maxTokens},...r.agentIds?{agentIds:r.agentIds}:e.agent?{agentIds:[e.agent.id]}:{},...e.skill?{activatedSkills:[e.skill.name]}:{},...Object.keys(e.context).length?{context:e.context}:{},toolExecutionPolicy:e.toolExecutionPolicy});return t.completion.catch(t=>{(0,p.L)().error("agent run error",t,{sessionId:e.sessionId}),console.error("Agent run error:",t)}),{sessionId:e.sessionId,runId:t.runId,streamRef:`/api/agent/stream?sessionId=${e.sessionId}`}}}),v=await E.execute({message:r.input,...r.sessionId?{sessionId:r.sessionId}:{},...o?{agentId:o}:{},...r.skillName?{skillName:r.skillName}:{},...r.profileId?{modelProfileId:r.profileId}:{},...r.images?.length?{images:r.images}:{},...r.context?{context:r.context}:{},...r.toolPolicyId?{capabilities:{toolPolicyId:r.toolPolicyId}}:{},session:{...r.projectId?{projectId:r.projectId}:{},...r.title?{title:r.title}:{},...r.metadata?{metadata:r.metadata}:{}},source:r.source??"webapp"});return a.NextResponse.json({sessionId:v.sessionId,streamUrl:v.streamRef,runId:v.runId})}catch(i){(0,p.L)().error("agent run request failed",i,{status:i instanceof l.no?i.code:void 0});let e=i instanceof l.no?i.code:void 0,t=i instanceof d.A?i.code:void 0,s=i instanceof u.KZx?i.code:void 0,r=e??t??s,n="SESSION_OCCUPIED"===r||"SESSION_ALREADY_RUNNING"===r;return a.NextResponse.json({error:i instanceof Error?i.message:"Internal error",...r?{code:r}:{}},{status:n?409:("AGENT_NOT_FOUND"===s||"SKILL_NOT_FOUND"===s||"MODEL_PROFILE_NOT_FOUND"===s||"TOOL_POLICY_NOT_FOUND"===s?404:"SKILL_NOT_ALLOWED"===s||"TOOL_POLICY_DISABLED"===s?422:s?400:void 0)??500})}}let E=new n.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/agent/run/route",pathname:"/api/agent/run",filename:"route",bundlePath:"app/api/agent/run/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-37/customer-agent/packages/server/app/api/agent/run/route.ts",nextConfigOutput:"standalone",userland:r}),{requestAsyncStorage:v,staticGenerationAsyncStorage:y,serverHooks:T}=E,w="/api/agent/run/route";function N(){return(0,o.patchFetch)({serverHooks:T,staticGenerationAsyncStorage:y})}},1614:(e,t,s)=>{s.d(t,{NL:()=>E,V_:()=>w,WW:()=>N});var r=s(7561),n=s(612),i=s(9411),o=s(7718),a=s(1322);function u(e){if(!e.trim())return!1;try{return(0,r.accessSync)(e,r.constants.X_OK),!0}catch{return!1}}function l(e){try{return(0,a.wyD)((0,o.execFileSync)(e,["--version"],{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","pipe"]}))}catch{return}}function d(e){let t=[],s=process.env[e.environmentVariable]?.trim();if(s){let r=u(s);t.push({source:"pin",path:s,executable:r,version:r?l(s):void 0,error:r?void 0:`${e.environmentVariable} "${s}" is not executable`})}let r=function(e){for(let t of(process.env.PATH??"").split(i.delimiter).filter(Boolean)){let s=(0,i.resolve)(t,e);if(u(s))return s}}(e.name);return r&&r!==s&&t.push({source:"path",path:r,executable:!0,version:l(r)}),(0,a.neJ)(t,{name:e.name,minimumVersion:e.minimumVersion})}var c=s(535),p=s(6279),h=s(785);let m=globalThis;class g{constructor(e,t=async()=>[],s=process.platform){this.runtime=e,this.listProjects=t,this.platform=s,this.pendingCreations=new Map}health(){return this.runtime.health()}listModels(e){return this.runtime.listModels(e)}listWorkspaces(e,t){return this.runtime.listWorkspaces(e,t)}importWorkspace(e,t,s){if(!this.runtime.importWorkspace)throw new p.no("Native workspace import is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.importWorkspace(e,t,s)}async listWorkspaceSessions(e,t,s){let r=await this.runtime.listWorkspaceSessions(e,t,s);if(s?.cursor)return r;let n=new Set(r.data.map(e=>e.id)),i=r.data.map(e=>{let t=this.pendingCreations.get(e.id);return t?(this.pendingCreations.delete(e.id),f(e,t)):e});for(let s of this.pendingCreations.values())s.agentType!==e||s.projectId!==t||n.has(s.id)||i.unshift(s);return{...r,data:i}}async list(e){let[t,s]=await Promise.all([this.runtime.list(),this.listProjects()]);return T(this.withPendingCreations(t).map(e=>v(e,s,this.platform)),e)}async refresh(e){let[t,s]=await Promise.all([this.runtime.refresh(),this.listProjects()]);return T(this.withPendingCreations(t).map(e=>v(e,s,this.platform)),e)}async create(e){let t=v(await this.runtime.create(e),await this.listProjects(),this.platform),s=e.projectId?{...t,projectId:e.projectId}:t;return this.pendingCreations.set(s.id,s),s}async fork(e){if(!w(e))throw new p.no("Customer Agent sessions do not support native forks","OPERATION_NOT_SUPPORTED");let t=v(await this.runtime.fork(e),await this.listProjects(),this.platform);return this.pendingCreations.set(t.id,t),t}async delete(e){await this.runtime.delete(e),this.pendingCreations.delete(e)}async get(e,t){let s;try{s=await this.runtime.get(e,t)}catch(r){let s=this.pendingCreations.get(e);if(!s)throw r;return t?{...s,messages:[],events:[],history:{nextCursor:null,hasMore:!1,pageSize:0,totalItems:0}}:{...s,messages:[],events:[]}}return v(s,await this.listProjects(),this.platform)}async getQueryIndex(e){if(this.runtime.getQueryIndex)return this.runtime.getQueryIndex(e);let t=await this.runtime.get(e),{buildSessionQueryIndex:r}=await Promise.resolve().then(s.bind(s,1322));return r(e,t.messages)}getSessionToolResult(e,t){return this.runtime.getSessionToolResult(e,t)}getSessionWatchPath(e){return this.runtime.getSessionWatchPath(e)}run(e,t,s,r,n){return this.runtime.run(e,t,s,r,n)}steer(e,t){return this.runtime.steer(e,t)}abort(e){return this.runtime.abort(e)}async release(e){if(!this.runtime.release)throw new p.no("Native runtime release is unavailable","RUNTIME_UNAVAILABLE");await this.runtime.release(e)}answerQuestion(e,t){return this.runtime.answerQuestion(e,t)}async startRun(e,t,s,r="web",n){if(!this.runtime.startRun)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.startRun(e,t,s,r,n)}async subscribe(e,t,s){if(!this.runtime.subscribe)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.subscribe(e,t,s)}async snapshot(e,t=0){if(!this.runtime.snapshot)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.snapshot(e,t)}async setPermissionMode(e,t){if(!this.runtime.setPermissionMode)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.setPermissionMode(e,t)}async handoff(e,t){if(!this.runtime.handoff)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.handoff(e,t)}async getGoals(e,t="web"){if(!this.runtime.getGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.getGoals(e,t)}async enqueueGoal(e,t,s,r="web"){if(!this.runtime.enqueueGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueGoal(e,t,s,r)}async reorderGoals(e,t){if(!this.runtime.reorderGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderGoals(e,t)}async cancelGoal(e,t){if(!this.runtime.cancelGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelGoal(e,t,"web")}async enqueueMessage(e,t,s="web"){if(!this.runtime.enqueueMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueMessage(e,t,s)}async reorderMessages(e,t){if(!this.runtime.reorderMessages)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderMessages(e,t)}async updateMessage(e,t,s,r){if(!this.runtime.updateMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.updateMessage(e,t,s,r)}async cancelMessage(e,t){if(!this.runtime.cancelMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelMessage(e,t)}async steerMessage(e,t){if(!this.runtime.steerMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.steerMessage(e,t)}withPendingCreations(e){let t=new Set,s=e.map(e=>{t.add(e.id);let s=this.pendingCreations.get(e.id);return this.pendingCreations.delete(e.id),s?f(e,s):e});return[...[...this.pendingCreations.values()].filter(e=>!t.has(e.id)).sort((e,t)=>t.updated.localeCompare(e.updated)),...s]}}function f(e,t){return{...e,cwd:e.cwd||t.cwd,projectId:e.projectId??t.projectId}}function I(e,t){t.executable?delete process.env[e]:process.env[e]=t.detail}function E(){if(!m.__nativeRuntimeService){!function(){let e=[(0,i.join)((0,n.homedir)(),".local","bin"),"/opt/homebrew/bin","/usr/local/bin"],t=(process.env.PATH??"").split(i.delimiter),s=e.filter(e=>(0,r.existsSync)(e)&&!t.includes(e));s.length>0&&(process.env.PATH=[...t,...s].join(i.delimiter))}();let e=new a.XWE((0,h.kO)());m.__nativeRuntimeService=new g((0,p.v6)({runtimeFactory:e=>{let t=d({name:"codex",environmentVariable:"AGENT_CODEX_BIN",minimumVersion:a.hix}),s=d({name:"opencode",environmentVariable:"AGENT_OPENCODE_BIN"});return process.pid,I("AGENT_CODEX_RUNTIME_ERROR",t),I("AGENT_OPENCODE_RUNTIME_ERROR",s),(0,c.L)().info("native runtime host elected",{pid:process.pid,codex:t.executable??null,codexSource:t.source??null,codexDetail:t.detail,opencode:s.executable??null,opencodeDetail:s.detail}),(0,p.WH)(t.executable??"codex",e,s.executable??"opencode")}}),()=>e.list())}return m.__nativeRuntimeService}function v(e,t,s=process.platform){let{projectId:r,...n}=e;if(!e.cwd)return n;let o=y(e.cwd,s),a="win32"===s?i.win32.sep:i.sep,u=t.filter(e=>e.description).map(e=>({project:e,path:y(e.description,s)})).filter(({path:e})=>o===e||o.startsWith(`${e}${a}`)).sort((e,t)=>t.path.length-e.path.length)[0];return u?{...n,projectId:u.project.id}:n}function y(e,t=process.platform){if("win32"!==t)return(0,i.resolve)(e);let s=i.win32.resolve(e),r=i.win32.parse(s).root;return(s.length>r.length?s.replace(/[\\/]+$/,""):s).toLowerCase()}function T(e,t){return void 0===t?e:e.filter(e=>e.projectId===t)}function w(e){try{return"customer-agent"!==(0,p.Vu)(e).agentType}catch{return!1}}function N(e){if(e instanceof p.no)switch(e.code){case"SESSION_NOT_FOUND":return 404;case"SESSION_OCCUPIED":case"SESSION_ALREADY_RUNNING":case"APPROVAL_EXPIRED":case"CODEX_SESSION_VERSION_INCOMPATIBLE":case"STALE_SESSION_ANCHOR":return 409;case"RUNTIME_UNAVAILABLE":return 503;case"OPERATION_NOT_SUPPORTED":return 405;default:return 400}return 500}},1079:(e,t,s)=>{s.d(t,{j:()=>d});var r=s(7519),n=s(3931),i=s(535),o=s(1322),a=s(1982);let u=!1,l=new o.sSf;function d(){u||(u=!0,r.agentHost.setGlobalEventObserver((e,t,s)=>{try{if("ask_user"===t.type){(0,n.i)().notifySession({notificationId:`${e}:${t.questionId}:approval`,sessionId:e,kind:"approval",title:"需要你的审批",body:"string"==typeof t.question&&t.question.trim()?t.question.trim().slice(0,160):"会话正在等待确认",url:"/app/"});return}if("done"===t.type){if("goal"===s.source)return;let r=(0,o.mDL)((0,a.dp)().read().taskNotifications),i=s.runId?(0,o.DXW)({sessionId:e,runId:s.runId,title:"任务已完成",finalText:t.finalText,outcome:"completed",source:"user"},r):null;i&&l.accept(i.notificationId)&&(0,n.i)().notifySession({...i,url:`/app/?session=${encodeURIComponent(e)}`});return}if("goal_updated"===t.type&&"complete"===t.goal.status){let s=(0,o.mDL)((0,a.dp)().read().taskNotifications),r=(0,o.DXW)({sessionId:e,runId:`goal:${t.goal.createdAt}`,title:"目标已完成",finalText:t.goal.objective,outcome:"completed",source:"goal",goalFinished:!0},s);r&&l.accept(r.notificationId)&&(0,n.i)().notifySession({...r,url:`/app/?session=${encodeURIComponent(e)}`});return}"error"===t.type&&(0,n.i)().notifySession({notificationId:`${e}:${s.runId??"unknown"}:error`,sessionId:e,kind:"error",title:"会话出错",body:"string"==typeof t.message&&t.message.trim()?t.message.trim().slice(0,160):"运行失败",url:"/app/"})}catch(t){(0,i.L)().warn("web push notify failed",{sessionId:e,error:t instanceof Error?t.message:String(t)})}}))}},6361:(e,t,s)=>{s.d(t,{Q:()=>o,e:()=>i});var r=s(1322),n=s(7519);function i(){let e=new r.S3T;(0,r._5y)(e);let t=new r.OqQ;for(let s of(e.register(new r.Q8u(t,null)),e.register(new r.URd(t,null)),n.agentHost.getBuilder().getToolRegistry().getAll()))e.register(s);return e.register(new r.gBG(async()=>({status:"failed",agentName:"",subSessionId:"",error:"catalog listing only; dispatch runs inside a Customer Agent session"}))),e.register(new r.sBJ(async()=>({status:"failed",agentName:"",subSessionId:"",error:"catalog listing only; spawning runs inside a dynamic Customer Agent session"}))),e.register(new r.HbQ(async()=>({status:"failed",agentName:"",subSessionId:"",error:"catalog listing only; dispatch runs inside a Customer Agent session"}))),e}function o(){return i().getAll().map(e=>e.name).sort()}},1489:(e,t,s)=>{s.d(t,{N:()=>u});var r=s(1322),n=s(6279),i=s(785);class o{constructor(){this.tasks=new r.vo4((0,i.kO)()),this.scheduler=new n.ST(this.tasks,e=>{this.fire(e).catch(e=>console.error("Scheduled Customer Agent run failed",e))},()=>{}),this.scheduler.start()}async fire(e){let{agentHost:t}=await s.e(7519).then(s.bind(s,7519)),{getCustomerGoalCoordinator:r}=await Promise.all([s.e(7519),s.e(732)]).then(s.bind(s,732)),n=e.sessionId;n&&await t.getSessionStore().get(n)||(n=(await t.createSession(e.label||"定时任务")).id,this.tasks.update(e.id,{sessionId:n})),await r().enqueue(n,e.prompt)}call(e,t){let s=String(t[0]||"");switch(e){case"cronList":return this.tasks.list();case"cronCreate":{if("string"!=typeof t[0]||"string"!=typeof t[1]||!t[1].trim())throw Error("cron and prompt required");let e=t[2]&&"object"==typeof t[2]?t[2]:{};return this.tasks.create({cron:t[0],prompt:t[1],recurring:!1!==e.recurring,enabled:!0,durable:!0,..."string"==typeof e.sessionId?{sessionId:e.sessionId}:{},..."string"==typeof e.label?{label:e.label}:{}})}case"cronPause":return this.tasks.pause(s);case"cronResume":return this.tasks.resume(s);case"cronDelete":return this.tasks.delete(s);case"cronDeleteAll":return this.tasks.deleteAll(),{ok:!0};default:throw Error("Unsupported schedule operation")}}}let a=globalThis;function u(){return a.__sharedCronService??=new o}},8615:(e,t,s)=>{let r;s.d(t,{H5:()=>d,cm:()=>u,jw:()=>l});var n=s(1322),i=s(785),o=s(6361);class a{constructor(e=(0,i.kO)()){this.store=new n.RQW(e)}list(){return this.store.list()}get(e){return this.store.get(e)}async summaries(){return(await this.store.list()).filter(e=>e.enabled).map(n._0R)}save(e,t){let s=(0,n.IJh)(e,{knownTools:t,requireExecutables:!0});return this.store.save(s)}delete(e){return this.store.delete(e)}}function u(){return r??=new a}function l(){return(0,o.Q)()}function d(e){let t=e instanceof n.DlR?422:400;return Response.json({error:e instanceof Error?e.message:"Tool policy request failed",code:e instanceof n.DlR?e.code:"INVALID_TOOL_POLICY"},{status:t})}},3931:(e,t,s)=>{s.d(t,{i:()=>p});var r=s(6005),n=s(7561),i=s(9411),o=s(5890);let a=require("web-push"),u=e=>JSON.stringify(e??null);class l{constructor(e,t=Date.now){this.now=t;let s=(0,i.resolve)(e,".agentroam-auth");(0,n.mkdirSync)(s,{recursive:!0,mode:448});let r=(0,i.join)(s,"push.sqlite");this.db=new o(r),(0,n.chmodSync)(r,384),this.db.pragma("busy_timeout = 5000"),this.db.exec(`
1
+ "use strict";(()=>{var e={};e.id=2616,e.ids=[2616],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},8010:(e,t,s)=>{s.r(t),s.d(t,{originalPathname:()=>w,patchFetch:()=>N,requestAsyncStorage:()=>v,routeModule:()=>E,serverHooks:()=>T,staticGenerationAsyncStorage:()=>y});var r={};s.r(r),s.d(r,{POST:()=>I});var i=s(7786),n=s(5042),o=s(2184),a=s(1890),u=s(1322),l=s(6279),d=s(7519),c=s(1614),p=s(535),h=s(1079),m=s(4621),g=s(1982),f=s(8615);async function I(e){try{var t,s;(0,h.j)();let r=await e.json();if(!r.input)return a.NextResponse.json({error:"input is required"},{status:400});if(void 0!==r.agentIds&&(!Array.isArray(r.agentIds)||r.agentIds.length>20||r.agentIds.some(e=>"string"!=typeof e||!e.trim())))return a.NextResponse.json({error:"agentIds must contain at most 20 non-empty IDs"},{status:400});if(void 0!==r.agentId&&void 0!==r.agentIds)return a.NextResponse.json({error:"agentId and agentIds are mutually exclusive"},{status:400});if(void 0!==r.profileId&&("string"!=typeof r.profileId||!r.profileId.trim()||r.profileId.length>200))return a.NextResponse.json({error:"profileId must be a non-empty string"},{status:400});if(r.sessionId&&(0,c.V_)(r.sessionId)){let e=r.sessionId,t=(0,c.NL)(),s=await t.startRun(e,r.input,r.images,"web",{...r.nativeModel?.id?{model:r.nativeModel}:{},...r.nativeReasoningEffort?{reasoningEffort:r.nativeReasoningEffort}:{}});d.agentHost.resetExternalStream(e),d.agentHost.publishExternal(e,{type:"run_admitted",_nativeRunId:s.runId,_nativeSequence:s.snapshotRevision});let i=null,n=!1;return t.subscribe(e,0,({event:t})=>{d.agentHost.publishExternal(e,t),("done"===t.type||"error"===t.type)&&(n=!0,i?.())}).then(e=>{i=e,n&&e()}).catch(t=>{let s=t instanceof l.no?t.code:void 0;(0,p.L)().error("native run subscription failed",t,{sessionId:e,code:s}),d.agentHost.publishExternal(e,{type:"error",message:t instanceof Error?t.message:"Native run subscription failed",...s?{code:s}:{}})}),a.NextResponse.json({sessionId:e,streamUrl:`/api/agent/stream?sessionId=${e}`,runId:s.runId,snapshotRevision:s.snapshotRevision})}let i=d.agentHost.getSessionStore(),n={maxIterations:"number"!=typeof(t=r.maxIterations)||!Number.isFinite(t)||t<0?10:Math.trunc(t),maxTokens:"number"==typeof(s=r.maxTokens)&&Number.isFinite(s)?Math.min(2e6,Math.max(8e3,Math.trunc(s))):1e5},o=r.agentId??(r.agentIds?.length===1?r.agentIds[0]:void 0),I=(0,m.i)(),E=new u.R0$(i,{getAgent:e=>I.agents.get(e),getSkill:async e=>I.skills.get(e)??(await I.call("listSkills",[])).find(t=>t.name===e)??null,hasModelProfile:e=>(0,g.dp)().read().profiles.some(t=>t.id===e),getToolExecutionPolicy:e=>(0,f.cm)().get(e)},{assertAvailable:e=>{if(d.agentHost.isSessionRunning(e))throw new d.A(e)},start:e=>{let t=d.agentHost.startRun(e.message,e.sessionId,e.images,{...r.model?{model:r.model}:{},...e.modelProfileId?{profileId:e.modelProfileId}:{},...r.reasoningEffort?{reasoningEffort:r.reasoningEffort}:{},...void 0===r.maxIterations?{}:{maxIterations:n.maxIterations},...void 0===r.maxTokens?{}:{maxTokens:n.maxTokens},...r.agentIds?{agentIds:r.agentIds}:e.agent?{agentIds:[e.agent.id]}:{},...e.skill?{activatedSkills:[e.skill.name]}:{},...Object.keys(e.context).length?{context:e.context}:{},toolExecutionPolicy:e.toolExecutionPolicy});return t.completion.catch(t=>{(0,p.L)().error("agent run error",t,{sessionId:e.sessionId}),console.error("Agent run error:",t)}),{sessionId:e.sessionId,runId:t.runId,streamRef:`/api/agent/stream?sessionId=${e.sessionId}`}}}),v=await E.execute({message:r.input,...r.sessionId?{sessionId:r.sessionId}:{},...o?{agentId:o}:{},...r.skillName?{skillName:r.skillName}:{},...r.profileId?{modelProfileId:r.profileId}:{},...r.images?.length?{images:r.images}:{},...r.context?{context:r.context}:{},...r.toolPolicyId?{capabilities:{toolPolicyId:r.toolPolicyId}}:{},session:{...r.projectId?{projectId:r.projectId}:{},...r.title?{title:r.title}:{},...r.metadata?{metadata:r.metadata}:{}},source:r.source??"webapp"});return a.NextResponse.json({sessionId:v.sessionId,streamUrl:v.streamRef,runId:v.runId})}catch(n){(0,p.L)().error("agent run request failed",n,{status:n instanceof l.no?n.code:void 0});let e=n instanceof l.no?n.code:void 0,t=n instanceof d.A?n.code:void 0,s=n instanceof u.KZx?n.code:void 0,r=e??t??s,i="SESSION_OCCUPIED"===r||"SESSION_ALREADY_RUNNING"===r;return a.NextResponse.json({error:n instanceof Error?n.message:"Internal error",...r?{code:r}:{}},{status:i?409:("AGENT_NOT_FOUND"===s||"SKILL_NOT_FOUND"===s||"MODEL_PROFILE_NOT_FOUND"===s||"TOOL_POLICY_NOT_FOUND"===s?404:"SKILL_NOT_ALLOWED"===s||"TOOL_POLICY_DISABLED"===s?422:s?400:void 0)??500})}}let E=new i.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/agent/run/route",pathname:"/api/agent/run",filename:"route",bundlePath:"app/api/agent/run/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-39/customer-agent/packages/server/app/api/agent/run/route.ts",nextConfigOutput:"standalone",userland:r}),{requestAsyncStorage:v,staticGenerationAsyncStorage:y,serverHooks:T}=E,w="/api/agent/run/route";function N(){return(0,o.patchFetch)({serverHooks:T,staticGenerationAsyncStorage:y})}},1614:(e,t,s)=>{s.d(t,{NL:()=>E,V_:()=>w,WW:()=>N});var r=s(7561),i=s(612),n=s(9411),o=s(7718),a=s(1322);function u(e){if(!e.trim())return!1;try{return(0,r.accessSync)(e,r.constants.X_OK),!0}catch{return!1}}function l(e){try{return(0,a.wyD)((0,o.execFileSync)(e,["--version"],{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","pipe"]}))}catch{return}}function d(e){let t=[],s=process.env[e.environmentVariable]?.trim();if(s){let r=u(s);t.push({source:"pin",path:s,executable:r,version:r?l(s):void 0,error:r?void 0:`${e.environmentVariable} "${s}" is not executable`})}let r=function(e){for(let t of(process.env.PATH??"").split(n.delimiter).filter(Boolean)){let s=(0,n.resolve)(t,e);if(u(s))return s}}(e.name);return r&&r!==s&&t.push({source:"path",path:r,executable:!0,version:l(r)}),(0,a.neJ)(t,{name:e.name,minimumVersion:e.minimumVersion})}var c=s(535),p=s(6279),h=s(785);let m=globalThis;class g{constructor(e,t=async()=>[],s=process.platform){this.runtime=e,this.listProjects=t,this.platform=s,this.pendingCreations=new Map}health(){return this.runtime.health()}listModels(e){return this.runtime.listModels(e)}listWorkspaces(e,t){return this.runtime.listWorkspaces(e,t)}importWorkspace(e,t,s){if(!this.runtime.importWorkspace)throw new p.no("Native workspace import is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.importWorkspace(e,t,s)}async listWorkspaceSessions(e,t,s){let r=await this.runtime.listWorkspaceSessions(e,t,s);if(s?.cursor)return r;let i=new Set(r.data.map(e=>e.id)),n=r.data.map(e=>{let t=this.pendingCreations.get(e.id);return t?(this.pendingCreations.delete(e.id),f(e,t)):e});for(let s of this.pendingCreations.values())s.agentType!==e||s.projectId!==t||i.has(s.id)||n.unshift(s);return{...r,data:n}}async list(e){let[t,s]=await Promise.all([this.runtime.list(),this.listProjects()]);return T(this.withPendingCreations(t).map(e=>v(e,s,this.platform)),e)}async refresh(e){let[t,s]=await Promise.all([this.runtime.refresh(),this.listProjects()]);return T(this.withPendingCreations(t).map(e=>v(e,s,this.platform)),e)}async create(e){let t=v(await this.runtime.create(e),await this.listProjects(),this.platform),s=e.projectId?{...t,projectId:e.projectId}:t;return this.pendingCreations.set(s.id,s),s}async fork(e,t){if(!w(e))throw new p.no("Customer Agent sessions do not support native forks","OPERATION_NOT_SUPPORTED");let s=v(t?await this.runtime.fork(e,t):await this.runtime.fork(e),await this.listProjects(),this.platform);return this.pendingCreations.set(s.id,s),s}async delete(e){await this.runtime.delete(e),this.pendingCreations.delete(e)}async get(e,t){let s;try{s=await this.runtime.get(e,t)}catch(r){let s=this.pendingCreations.get(e);if(!s)throw r;return t?{...s,messages:[],events:[],history:{nextCursor:null,hasMore:!1,pageSize:0,totalItems:0}}:{...s,messages:[],events:[]}}return v(s,await this.listProjects(),this.platform)}async getQueryIndex(e){if(this.runtime.getQueryIndex)return this.runtime.getQueryIndex(e);let t=await this.runtime.get(e),{buildSessionQueryIndex:r}=await Promise.resolve().then(s.bind(s,1322));return r(e,t.messages)}getSessionToolResult(e,t){return this.runtime.getSessionToolResult(e,t)}getSessionWatchPath(e){return this.runtime.getSessionWatchPath(e)}run(e,t,s,r,i){return this.runtime.run(e,t,s,r,i)}steer(e,t){return this.runtime.steer(e,t)}abort(e){return this.runtime.abort(e)}async release(e){if(!this.runtime.release)throw new p.no("Native runtime release is unavailable","RUNTIME_UNAVAILABLE");await this.runtime.release(e)}answerQuestion(e,t){return this.runtime.answerQuestion(e,t)}async startRun(e,t,s,r="web",i){if(!this.runtime.startRun)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.startRun(e,t,s,r,i)}async subscribe(e,t,s){if(!this.runtime.subscribe)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.subscribe(e,t,s)}async snapshot(e,t=0){if(!this.runtime.snapshot)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.snapshot(e,t)}async setPermissionMode(e,t){if(!this.runtime.setPermissionMode)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.setPermissionMode(e,t)}async handoff(e,t){if(!this.runtime.handoff)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.handoff(e,t)}async getGoals(e,t="web"){if(!this.runtime.getGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.getGoals(e,t)}async enqueueGoal(e,t,s,r="web"){if(!this.runtime.enqueueGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueGoal(e,t,s,r)}async reorderGoals(e,t){if(!this.runtime.reorderGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderGoals(e,t)}async cancelGoal(e,t){if(!this.runtime.cancelGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelGoal(e,t,"web")}async enqueueMessage(e,t,s="web"){if(!this.runtime.enqueueMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueMessage(e,t,s)}async reorderMessages(e,t){if(!this.runtime.reorderMessages)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderMessages(e,t)}async updateMessage(e,t,s,r){if(!this.runtime.updateMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.updateMessage(e,t,s,r)}async cancelMessage(e,t){if(!this.runtime.cancelMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelMessage(e,t)}async steerMessage(e,t){if(!this.runtime.steerMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.steerMessage(e,t)}withPendingCreations(e){let t=new Set,s=e.map(e=>{t.add(e.id);let s=this.pendingCreations.get(e.id);return this.pendingCreations.delete(e.id),s?f(e,s):e});return[...[...this.pendingCreations.values()].filter(e=>!t.has(e.id)).sort((e,t)=>t.updated.localeCompare(e.updated)),...s]}}function f(e,t){return{...e,cwd:e.cwd||t.cwd,projectId:e.projectId??t.projectId}}function I(e,t){t.executable?delete process.env[e]:process.env[e]=t.detail}function E(){if(!m.__nativeRuntimeService){!function(){let e=[(0,n.join)((0,i.homedir)(),".local","bin"),"/opt/homebrew/bin","/usr/local/bin"],t=(process.env.PATH??"").split(n.delimiter),s=e.filter(e=>(0,r.existsSync)(e)&&!t.includes(e));s.length>0&&(process.env.PATH=[...t,...s].join(n.delimiter))}();let e=new a.XWE((0,h.kO)());m.__nativeRuntimeService=new g((0,p.v6)({runtimeFactory:e=>{let t=d({name:"codex",environmentVariable:"AGENT_CODEX_BIN",minimumVersion:a.hix}),s=d({name:"opencode",environmentVariable:"AGENT_OPENCODE_BIN"});return process.pid,I("AGENT_CODEX_RUNTIME_ERROR",t),I("AGENT_OPENCODE_RUNTIME_ERROR",s),(0,c.L)().info("native runtime host elected",{pid:process.pid,codex:t.executable??null,codexSource:t.source??null,codexDetail:t.detail,opencode:s.executable??null,opencodeDetail:s.detail}),(0,p.WH)(t.executable??"codex",e,s.executable??"opencode")}}),()=>e.list())}return m.__nativeRuntimeService}function v(e,t,s=process.platform){let{projectId:r,...i}=e;if(!e.cwd)return i;let o=y(e.cwd,s),a="win32"===s?n.win32.sep:n.sep,u=t.filter(e=>e.description).map(e=>({project:e,path:y(e.description,s)})).filter(({path:e})=>o===e||o.startsWith(`${e}${a}`)).sort((e,t)=>t.path.length-e.path.length)[0];return u?{...i,projectId:u.project.id}:i}function y(e,t=process.platform){if("win32"!==t)return(0,n.resolve)(e);let s=n.win32.resolve(e),r=n.win32.parse(s).root;return(s.length>r.length?s.replace(/[\\/]+$/,""):s).toLowerCase()}function T(e,t){return void 0===t?e:e.filter(e=>e.projectId===t)}function w(e){try{return"customer-agent"!==(0,p.Vu)(e).agentType}catch{return!1}}function N(e){if(e instanceof p.no)switch(e.code){case"SESSION_NOT_FOUND":return 404;case"SESSION_OCCUPIED":case"SESSION_ALREADY_RUNNING":case"APPROVAL_EXPIRED":case"CODEX_SESSION_VERSION_INCOMPATIBLE":case"STALE_SESSION_ANCHOR":return 409;case"RUNTIME_UNAVAILABLE":return 503;case"OPERATION_NOT_SUPPORTED":return 405;default:return 400}return 500}},1079:(e,t,s)=>{s.d(t,{j:()=>d});var r=s(7519),i=s(3931),n=s(535),o=s(1322),a=s(1982);let u=!1,l=new o.sSf;function d(){u||(u=!0,r.agentHost.setGlobalEventObserver((e,t,s)=>{try{if("ask_user"===t.type){(0,i.i)().notifySession({notificationId:`${e}:${t.questionId}:approval`,sessionId:e,kind:"approval",title:"需要你的审批",body:"string"==typeof t.question&&t.question.trim()?t.question.trim().slice(0,160):"会话正在等待确认",url:"/app/"});return}if("done"===t.type){if("goal"===s.source)return;let r=(0,o.mDL)((0,a.dp)().read().taskNotifications),n=s.runId?(0,o.DXW)({sessionId:e,runId:s.runId,title:"任务已完成",finalText:t.finalText,outcome:"completed",source:"user"},r):null;n&&l.accept(n.notificationId)&&(0,i.i)().notifySession({...n,url:`/app/?session=${encodeURIComponent(e)}`});return}if("goal_updated"===t.type&&"complete"===t.goal.status){let s=(0,o.mDL)((0,a.dp)().read().taskNotifications),r=(0,o.DXW)({sessionId:e,runId:`goal:${t.goal.createdAt}`,title:"目标已完成",finalText:t.goal.objective,outcome:"completed",source:"goal",goalFinished:!0},s);r&&l.accept(r.notificationId)&&(0,i.i)().notifySession({...r,url:`/app/?session=${encodeURIComponent(e)}`});return}"error"===t.type&&(0,i.i)().notifySession({notificationId:`${e}:${s.runId??"unknown"}:error`,sessionId:e,kind:"error",title:"会话出错",body:"string"==typeof t.message&&t.message.trim()?t.message.trim().slice(0,160):"运行失败",url:"/app/"})}catch(t){(0,n.L)().warn("web push notify failed",{sessionId:e,error:t instanceof Error?t.message:String(t)})}}))}},6361:(e,t,s)=>{s.d(t,{Q:()=>o,e:()=>n});var r=s(1322),i=s(7519);function n(){let e=new r.S3T;(0,r._5y)(e);let t=new r.OqQ;for(let s of(e.register(new r.Q8u(t,null)),e.register(new r.URd(t,null)),i.agentHost.getBuilder().getToolRegistry().getAll()))e.register(s);return e.register(new r.gBG(async()=>({status:"failed",agentName:"",subSessionId:"",error:"catalog listing only; dispatch runs inside a Customer Agent session"}))),e.register(new r.sBJ(async()=>({status:"failed",agentName:"",subSessionId:"",error:"catalog listing only; spawning runs inside a dynamic Customer Agent session"}))),e.register(new r.HbQ(async()=>({status:"failed",agentName:"",subSessionId:"",error:"catalog listing only; dispatch runs inside a Customer Agent session"}))),e}function o(){return n().getAll().map(e=>e.name).sort()}},1489:(e,t,s)=>{s.d(t,{N:()=>u});var r=s(1322),i=s(6279),n=s(785);class o{constructor(){this.tasks=new r.vo4((0,n.kO)()),this.scheduler=new i.ST(this.tasks,e=>{this.fire(e).catch(e=>console.error("Scheduled Customer Agent run failed",e))},()=>{}),this.scheduler.start()}async fire(e){let{agentHost:t}=await s.e(7519).then(s.bind(s,7519)),{getCustomerGoalCoordinator:r}=await Promise.all([s.e(7519),s.e(732)]).then(s.bind(s,732)),i=e.sessionId;i&&await t.getSessionStore().get(i)||(i=(await t.createSession(e.label||"定时任务")).id,this.tasks.update(e.id,{sessionId:i})),await r().enqueue(i,e.prompt)}call(e,t){let s=String(t[0]||"");switch(e){case"cronList":return this.tasks.list();case"cronCreate":{if("string"!=typeof t[0]||"string"!=typeof t[1]||!t[1].trim())throw Error("cron and prompt required");let e=t[2]&&"object"==typeof t[2]?t[2]:{};return this.tasks.create({cron:t[0],prompt:t[1],recurring:!1!==e.recurring,enabled:!0,durable:!0,..."string"==typeof e.sessionId?{sessionId:e.sessionId}:{},..."string"==typeof e.label?{label:e.label}:{}})}case"cronPause":return this.tasks.pause(s);case"cronResume":return this.tasks.resume(s);case"cronDelete":return this.tasks.delete(s);case"cronDeleteAll":return this.tasks.deleteAll(),{ok:!0};default:throw Error("Unsupported schedule operation")}}}let a=globalThis;function u(){return a.__sharedCronService??=new o}},8615:(e,t,s)=>{let r;s.d(t,{H5:()=>d,cm:()=>u,jw:()=>l});var i=s(1322),n=s(785),o=s(6361);class a{constructor(e=(0,n.kO)()){this.store=new i.RQW(e)}list(){return this.store.list()}get(e){return this.store.get(e)}async summaries(){return(await this.store.list()).filter(e=>e.enabled).map(i._0R)}save(e,t){let s=(0,i.IJh)(e,{knownTools:t,requireExecutables:!0});return this.store.save(s)}delete(e){return this.store.delete(e)}}function u(){return r??=new a}function l(){return(0,o.Q)()}function d(e){let t=e instanceof i.DlR?422:400;return Response.json({error:e instanceof Error?e.message:"Tool policy request failed",code:e instanceof i.DlR?e.code:"INVALID_TOOL_POLICY"},{status:t})}},3931:(e,t,s)=>{s.d(t,{i:()=>p});var r=s(6005),i=s(7561),n=s(9411),o=s(5890);let a=require("web-push"),u=e=>JSON.stringify(e??null);class l{constructor(e,t=Date.now){this.now=t;let s=(0,n.resolve)(e,".agentroam-auth");(0,i.mkdirSync)(s,{recursive:!0,mode:448});let r=(0,n.join)(s,"push.sqlite");this.db=new o(r),(0,i.chmodSync)(r,384),this.db.pragma("busy_timeout = 5000"),this.db.exec(`
2
2
  CREATE TABLE IF NOT EXISTS push_keys (id INTEGER PRIMARY KEY CHECK(id=1), public_key TEXT NOT NULL, private_key TEXT NOT NULL);
3
3
  CREATE TABLE IF NOT EXISTS push_subscriptions (
4
4
  endpoint_hash TEXT PRIMARY KEY,
@@ -8,8 +8,8 @@
8
8
  device_id TEXT,
9
9
  created INTEGER NOT NULL
10
10
  );
11
- `),this.keys=this.loadKeys(),this.delivered=new Set}loadKeys(){let e=this.db.prepare("SELECT public_key, private_key FROM push_keys WHERE id=1").get();if(e)return{publicKey:e.public_key,privateKey:e.private_key};let t=a.generateVAPIDKeys();return this.db.prepare("INSERT INTO push_keys VALUES (1, ?, ?)").run(t.publicKey,t.privateKey),{publicKey:t.publicKey,privateKey:t.privateKey}}getPublicKey(){return this.keys.publicKey}saveSubscription(e,t){let s="string"==typeof t?.endpoint?t.endpoint:"",r=t?.keys?.p256dh,n=t?.keys?.auth;if(!s.startsWith("https://")||"string"!=typeof r||!r||"string"!=typeof n||!n)throw Object.assign(Error("Invalid push subscription"),{status:400});return this.db.prepare(`
11
+ `),this.keys=this.loadKeys(),this.delivered=new Set}loadKeys(){let e=this.db.prepare("SELECT public_key, private_key FROM push_keys WHERE id=1").get();if(e)return{publicKey:e.public_key,privateKey:e.private_key};let t=a.generateVAPIDKeys();return this.db.prepare("INSERT INTO push_keys VALUES (1, ?, ?)").run(t.publicKey,t.privateKey),{publicKey:t.publicKey,privateKey:t.privateKey}}getPublicKey(){return this.keys.publicKey}saveSubscription(e,t){let s="string"==typeof t?.endpoint?t.endpoint:"",r=t?.keys?.p256dh,i=t?.keys?.auth;if(!s.startsWith("https://")||"string"!=typeof r||!r||"string"!=typeof i||!i)throw Object.assign(Error("Invalid push subscription"),{status:400});return this.db.prepare(`
12
12
  INSERT INTO push_subscriptions (endpoint_hash, endpoint, p256dh, auth, device_id, created)
13
13
  VALUES (?, ?, ?, ?, ?, ?)
14
14
  ON CONFLICT(endpoint_hash) DO UPDATE SET p256dh=excluded.p256dh, auth=excluded.auth, device_id=excluded.device_id
15
- `).run(d(s),s,r,n,"string"==typeof e?e:null,this.now()),{ok:!0}}deleteSubscription(e){if("string"!=typeof e||!e)throw Object.assign(Error("Endpoint required"),{status:400});return this.db.prepare("DELETE FROM push_subscriptions WHERE endpoint_hash=?").run(d(e)),{ok:!0}}listSubscriptions(){return this.db.prepare("SELECT endpoint, p256dh, auth, device_id FROM push_subscriptions").all().map(e=>({endpoint:e.endpoint,keys:{p256dh:e.p256dh,auth:e.auth},deviceId:e.device_id}))}notifySession({notificationId:e,sessionId:t,title:s,body:r,url:n}){let i=e||`${t}:notification`;if(!this.delivered.has(i)){for(this.delivered.add(i);this.delivered.size>500;)this.delivered.delete(this.delivered.values().next().value);this.sendToAll({notificationId:i,sessionId:t,title:s,body:r,tag:i,url:n})}}async sendToAll(e){let t=this.listSubscriptions();await Promise.allSettled(t.map(t=>this.send(t,e)))}async send(e,t){try{a.setVapidDetails("mailto:agentroam@localhost",this.keys.publicKey,this.keys.privateKey),await a.sendNotification(e,u(t),{TTL:3600})}catch(s){let t=s?.statusCode;(404===t||410===t)&&this.db.prepare("DELETE FROM push_subscriptions WHERE endpoint_hash=?").run(d(e.endpoint))}}close(){this.db.close()}}function d(e){return(0,r.createHash)("sha256").update(e).digest("hex")}let c=null;function p(e=process.env.AGENT_DATA_DIR?.trim()||process.cwd()){return c??=new l(e)}}};var t=require("../../../../webpack-runtime.js");t.C(e);var s=e=>t(t.s=e),r=t.X(0,[8375,6703,6244,1322,1773,4621,7519],()=>s(7083));module.exports=r})();
15
+ `).run(d(s),s,r,i,"string"==typeof e?e:null,this.now()),{ok:!0}}deleteSubscription(e){if("string"!=typeof e||!e)throw Object.assign(Error("Endpoint required"),{status:400});return this.db.prepare("DELETE FROM push_subscriptions WHERE endpoint_hash=?").run(d(e)),{ok:!0}}listSubscriptions(){return this.db.prepare("SELECT endpoint, p256dh, auth, device_id FROM push_subscriptions").all().map(e=>({endpoint:e.endpoint,keys:{p256dh:e.p256dh,auth:e.auth},deviceId:e.device_id}))}notifySession({notificationId:e,sessionId:t,title:s,body:r,url:i}){let n=e||`${t}:notification`;if(!this.delivered.has(n)){for(this.delivered.add(n);this.delivered.size>500;)this.delivered.delete(this.delivered.values().next().value);this.sendToAll({notificationId:n,sessionId:t,title:s,body:r,tag:n,url:i})}}async sendToAll(e){let t=this.listSubscriptions();await Promise.allSettled(t.map(t=>this.send(t,e)))}async send(e,t){try{a.setVapidDetails("mailto:agentroam@localhost",this.keys.publicKey,this.keys.privateKey),await a.sendNotification(e,u(t),{TTL:3600})}catch(s){let t=s?.statusCode;(404===t||410===t)&&this.db.prepare("DELETE FROM push_subscriptions WHERE endpoint_hash=?").run(d(e.endpoint))}}close(){this.db.close()}}function d(e){return(0,r.createHash)("sha256").update(e).digest("hex")}let c=null;function p(e=process.env.AGENT_DATA_DIR?.trim()||process.cwd()){return c??=new l(e)}}};var t=require("../../../../webpack-runtime.js");t.C(e);var s=e=>t(t.s=e),r=t.X(0,[8375,6703,6244,1322,1773,4621,7519],()=>s(8010));module.exports=r})();
@@ -1 +1 @@
1
- "use strict";(()=>{var e={};e.id=5352,e.ids=[5352],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},9543:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>g,requestAsyncStorage:()=>p,routeModule:()=>h,serverHooks:()=>m,staticGenerationAsyncStorage:()=>d});var i={};r.r(i),r.d(i,{GET:()=>c,dynamic:()=>l});var n=r(7786),s=r(5042),a=r(2184),o=r(1890),u=r(1614);let l="force-dynamic";async function c(){let e=await (0,u.NL)().health();return o.NextResponse.json([{agentType:"customer-agent",available:!0,label:"Customer Agent"},...e])}let h=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/agent/runtime-health/route",pathname:"/api/agent/runtime-health",filename:"route",bundlePath:"app/api/agent/runtime-health/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-37/customer-agent/packages/server/app/api/agent/runtime-health/route.ts",nextConfigOutput:"standalone",userland:i}),{requestAsyncStorage:p,staticGenerationAsyncStorage:d,serverHooks:m}=h,f="/api/agent/runtime-health/route";function g(){return(0,a.patchFetch)({serverHooks:m,staticGenerationAsyncStorage:d})}},535:(e,t,r)=>{r.d(t,{L:()=>a});var i=r(1322),n=r(785);let s=!1;function a(){let e=(0,i.Qfc)();if(e)return e;let t=(0,i.qZ_)({dir:(0,n.ME)(),source:"server",minLevel:"info",handlers:{exitOnUncaughtException:!1}});return s||(s=!0,t.info("server logger attached",{dir:t.dir,pid:process.pid})),t}},1614:(e,t,r)=>{r.d(t,{NL:()=>v,V_:()=>P,WW:()=>_});var i=r(7561),n=r(612),s=r(9411),a=r(7718),o=r(1322);function u(e){if(!e.trim())return!1;try{return(0,i.accessSync)(e,i.constants.X_OK),!0}catch{return!1}}function l(e){try{return(0,o.wyD)((0,a.execFileSync)(e,["--version"],{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","pipe"]}))}catch{return}}function c(e){let t=[],r=process.env[e.environmentVariable]?.trim();if(r){let i=u(r);t.push({source:"pin",path:r,executable:i,version:i?l(r):void 0,error:i?void 0:`${e.environmentVariable} "${r}" is not executable`})}let i=function(e){for(let t of(process.env.PATH??"").split(s.delimiter).filter(Boolean)){let r=(0,s.resolve)(t,e);if(u(r))return r}}(e.name);return i&&i!==r&&t.push({source:"path",path:i,executable:!0,version:l(i)}),(0,o.neJ)(t,{name:e.name,minimumVersion:e.minimumVersion})}var h=r(535),p=r(6279),d=r(785);let m=globalThis;class f{constructor(e,t=async()=>[],r=process.platform){this.runtime=e,this.listProjects=t,this.platform=r,this.pendingCreations=new Map}health(){return this.runtime.health()}listModels(e){return this.runtime.listModels(e)}listWorkspaces(e,t){return this.runtime.listWorkspaces(e,t)}importWorkspace(e,t,r){if(!this.runtime.importWorkspace)throw new p.no("Native workspace import is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.importWorkspace(e,t,r)}async listWorkspaceSessions(e,t,r){let i=await this.runtime.listWorkspaceSessions(e,t,r);if(r?.cursor)return i;let n=new Set(i.data.map(e=>e.id)),s=i.data.map(e=>{let t=this.pendingCreations.get(e.id);return t?(this.pendingCreations.delete(e.id),g(e,t)):e});for(let r of this.pendingCreations.values())r.agentType!==e||r.projectId!==t||n.has(r.id)||s.unshift(r);return{...i,data:s}}async list(e){let[t,r]=await Promise.all([this.runtime.list(),this.listProjects()]);return E(this.withPendingCreations(t).map(e=>O(e,r,this.platform)),e)}async refresh(e){let[t,r]=await Promise.all([this.runtime.refresh(),this.listProjects()]);return E(this.withPendingCreations(t).map(e=>O(e,r,this.platform)),e)}async create(e){let t=O(await this.runtime.create(e),await this.listProjects(),this.platform),r=e.projectId?{...t,projectId:e.projectId}:t;return this.pendingCreations.set(r.id,r),r}async fork(e){if(!P(e))throw new p.no("Customer Agent sessions do not support native forks","OPERATION_NOT_SUPPORTED");let t=O(await this.runtime.fork(e),await this.listProjects(),this.platform);return this.pendingCreations.set(t.id,t),t}async delete(e){await this.runtime.delete(e),this.pendingCreations.delete(e)}async get(e,t){let r;try{r=await this.runtime.get(e,t)}catch(i){let r=this.pendingCreations.get(e);if(!r)throw i;return t?{...r,messages:[],events:[],history:{nextCursor:null,hasMore:!1,pageSize:0,totalItems:0}}:{...r,messages:[],events:[]}}return O(r,await this.listProjects(),this.platform)}async getQueryIndex(e){if(this.runtime.getQueryIndex)return this.runtime.getQueryIndex(e);let t=await this.runtime.get(e),{buildSessionQueryIndex:i}=await Promise.resolve().then(r.bind(r,1322));return i(e,t.messages)}getSessionToolResult(e,t){return this.runtime.getSessionToolResult(e,t)}getSessionWatchPath(e){return this.runtime.getSessionWatchPath(e)}run(e,t,r,i,n){return this.runtime.run(e,t,r,i,n)}steer(e,t){return this.runtime.steer(e,t)}abort(e){return this.runtime.abort(e)}async release(e){if(!this.runtime.release)throw new p.no("Native runtime release is unavailable","RUNTIME_UNAVAILABLE");await this.runtime.release(e)}answerQuestion(e,t){return this.runtime.answerQuestion(e,t)}async startRun(e,t,r,i="web",n){if(!this.runtime.startRun)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.startRun(e,t,r,i,n)}async subscribe(e,t,r){if(!this.runtime.subscribe)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.subscribe(e,t,r)}async snapshot(e,t=0){if(!this.runtime.snapshot)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.snapshot(e,t)}async setPermissionMode(e,t){if(!this.runtime.setPermissionMode)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.setPermissionMode(e,t)}async handoff(e,t){if(!this.runtime.handoff)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.handoff(e,t)}async getGoals(e,t="web"){if(!this.runtime.getGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.getGoals(e,t)}async enqueueGoal(e,t,r,i="web"){if(!this.runtime.enqueueGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueGoal(e,t,r,i)}async reorderGoals(e,t){if(!this.runtime.reorderGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderGoals(e,t)}async cancelGoal(e,t){if(!this.runtime.cancelGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelGoal(e,t,"web")}async enqueueMessage(e,t,r="web"){if(!this.runtime.enqueueMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueMessage(e,t,r)}async reorderMessages(e,t){if(!this.runtime.reorderMessages)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderMessages(e,t)}async updateMessage(e,t,r,i){if(!this.runtime.updateMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.updateMessage(e,t,r,i)}async cancelMessage(e,t){if(!this.runtime.cancelMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelMessage(e,t)}async steerMessage(e,t){if(!this.runtime.steerMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.steerMessage(e,t)}withPendingCreations(e){let t=new Set,r=e.map(e=>{t.add(e.id);let r=this.pendingCreations.get(e.id);return this.pendingCreations.delete(e.id),r?g(e,r):e});return[...[...this.pendingCreations.values()].filter(e=>!t.has(e.id)).sort((e,t)=>t.updated.localeCompare(e.updated)),...r]}}function g(e,t){return{...e,cwd:e.cwd||t.cwd,projectId:e.projectId??t.projectId}}function w(e,t){t.executable?delete process.env[e]:process.env[e]=t.detail}function v(){if(!m.__nativeRuntimeService){!function(){let e=[(0,s.join)((0,n.homedir)(),".local","bin"),"/opt/homebrew/bin","/usr/local/bin"],t=(process.env.PATH??"").split(s.delimiter),r=e.filter(e=>(0,i.existsSync)(e)&&!t.includes(e));r.length>0&&(process.env.PATH=[...t,...r].join(s.delimiter))}();let e=new o.XWE((0,d.kO)());m.__nativeRuntimeService=new f((0,p.v6)({runtimeFactory:e=>{let t=c({name:"codex",environmentVariable:"AGENT_CODEX_BIN",minimumVersion:o.hix}),r=c({name:"opencode",environmentVariable:"AGENT_OPENCODE_BIN"});return process.pid,w("AGENT_CODEX_RUNTIME_ERROR",t),w("AGENT_OPENCODE_RUNTIME_ERROR",r),(0,h.L)().info("native runtime host elected",{pid:process.pid,codex:t.executable??null,codexSource:t.source??null,codexDetail:t.detail,opencode:r.executable??null,opencodeDetail:r.detail}),(0,p.WH)(t.executable??"codex",e,r.executable??"opencode")}}),()=>e.list())}return m.__nativeRuntimeService}function O(e,t,r=process.platform){let{projectId:i,...n}=e;if(!e.cwd)return n;let a=N(e.cwd,r),o="win32"===r?s.win32.sep:s.sep,u=t.filter(e=>e.description).map(e=>({project:e,path:N(e.description,r)})).filter(({path:e})=>a===e||a.startsWith(`${e}${o}`)).sort((e,t)=>t.path.length-e.path.length)[0];return u?{...n,projectId:u.project.id}:n}function N(e,t=process.platform){if("win32"!==t)return(0,s.resolve)(e);let r=s.win32.resolve(e),i=s.win32.parse(r).root;return(r.length>i.length?r.replace(/[\\/]+$/,""):r).toLowerCase()}function E(e,t){return void 0===t?e:e.filter(e=>e.projectId===t)}function P(e){try{return"customer-agent"!==(0,p.Vu)(e).agentType}catch{return!1}}function _(e){if(e instanceof p.no)switch(e.code){case"SESSION_NOT_FOUND":return 404;case"SESSION_OCCUPIED":case"SESSION_ALREADY_RUNNING":case"APPROVAL_EXPIRED":case"CODEX_SESSION_VERSION_INCOMPATIBLE":case"STALE_SESSION_ANCHOR":return 409;case"RUNTIME_UNAVAILABLE":return 503;case"OPERATION_NOT_SUPPORTED":return 405;default:return 400}return 500}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),i=t.X(0,[8375,6703,6244,1322,1773],()=>r(9543));module.exports=i})();
1
+ "use strict";(()=>{var e={};e.id=5352,e.ids=[5352],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},3103:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>g,requestAsyncStorage:()=>p,routeModule:()=>h,serverHooks:()=>m,staticGenerationAsyncStorage:()=>d});var i={};r.r(i),r.d(i,{GET:()=>c,dynamic:()=>l});var n=r(7786),s=r(5042),a=r(2184),o=r(1890),u=r(1614);let l="force-dynamic";async function c(){let e=await (0,u.NL)().health();return o.NextResponse.json([{agentType:"customer-agent",available:!0,label:"Customer Agent"},...e])}let h=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/agent/runtime-health/route",pathname:"/api/agent/runtime-health",filename:"route",bundlePath:"app/api/agent/runtime-health/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-39/customer-agent/packages/server/app/api/agent/runtime-health/route.ts",nextConfigOutput:"standalone",userland:i}),{requestAsyncStorage:p,staticGenerationAsyncStorage:d,serverHooks:m}=h,f="/api/agent/runtime-health/route";function g(){return(0,a.patchFetch)({serverHooks:m,staticGenerationAsyncStorage:d})}},535:(e,t,r)=>{r.d(t,{L:()=>a});var i=r(1322),n=r(785);let s=!1;function a(){let e=(0,i.Qfc)();if(e)return e;let t=(0,i.qZ_)({dir:(0,n.ME)(),source:"server",minLevel:"info",handlers:{exitOnUncaughtException:!1}});return s||(s=!0,t.info("server logger attached",{dir:t.dir,pid:process.pid})),t}},1614:(e,t,r)=>{r.d(t,{NL:()=>v,V_:()=>P,WW:()=>_});var i=r(7561),n=r(612),s=r(9411),a=r(7718),o=r(1322);function u(e){if(!e.trim())return!1;try{return(0,i.accessSync)(e,i.constants.X_OK),!0}catch{return!1}}function l(e){try{return(0,o.wyD)((0,a.execFileSync)(e,["--version"],{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","pipe"]}))}catch{return}}function c(e){let t=[],r=process.env[e.environmentVariable]?.trim();if(r){let i=u(r);t.push({source:"pin",path:r,executable:i,version:i?l(r):void 0,error:i?void 0:`${e.environmentVariable} "${r}" is not executable`})}let i=function(e){for(let t of(process.env.PATH??"").split(s.delimiter).filter(Boolean)){let r=(0,s.resolve)(t,e);if(u(r))return r}}(e.name);return i&&i!==r&&t.push({source:"path",path:i,executable:!0,version:l(i)}),(0,o.neJ)(t,{name:e.name,minimumVersion:e.minimumVersion})}var h=r(535),p=r(6279),d=r(785);let m=globalThis;class f{constructor(e,t=async()=>[],r=process.platform){this.runtime=e,this.listProjects=t,this.platform=r,this.pendingCreations=new Map}health(){return this.runtime.health()}listModels(e){return this.runtime.listModels(e)}listWorkspaces(e,t){return this.runtime.listWorkspaces(e,t)}importWorkspace(e,t,r){if(!this.runtime.importWorkspace)throw new p.no("Native workspace import is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.importWorkspace(e,t,r)}async listWorkspaceSessions(e,t,r){let i=await this.runtime.listWorkspaceSessions(e,t,r);if(r?.cursor)return i;let n=new Set(i.data.map(e=>e.id)),s=i.data.map(e=>{let t=this.pendingCreations.get(e.id);return t?(this.pendingCreations.delete(e.id),g(e,t)):e});for(let r of this.pendingCreations.values())r.agentType!==e||r.projectId!==t||n.has(r.id)||s.unshift(r);return{...i,data:s}}async list(e){let[t,r]=await Promise.all([this.runtime.list(),this.listProjects()]);return E(this.withPendingCreations(t).map(e=>O(e,r,this.platform)),e)}async refresh(e){let[t,r]=await Promise.all([this.runtime.refresh(),this.listProjects()]);return E(this.withPendingCreations(t).map(e=>O(e,r,this.platform)),e)}async create(e){let t=O(await this.runtime.create(e),await this.listProjects(),this.platform),r=e.projectId?{...t,projectId:e.projectId}:t;return this.pendingCreations.set(r.id,r),r}async fork(e,t){if(!P(e))throw new p.no("Customer Agent sessions do not support native forks","OPERATION_NOT_SUPPORTED");let r=O(t?await this.runtime.fork(e,t):await this.runtime.fork(e),await this.listProjects(),this.platform);return this.pendingCreations.set(r.id,r),r}async delete(e){await this.runtime.delete(e),this.pendingCreations.delete(e)}async get(e,t){let r;try{r=await this.runtime.get(e,t)}catch(i){let r=this.pendingCreations.get(e);if(!r)throw i;return t?{...r,messages:[],events:[],history:{nextCursor:null,hasMore:!1,pageSize:0,totalItems:0}}:{...r,messages:[],events:[]}}return O(r,await this.listProjects(),this.platform)}async getQueryIndex(e){if(this.runtime.getQueryIndex)return this.runtime.getQueryIndex(e);let t=await this.runtime.get(e),{buildSessionQueryIndex:i}=await Promise.resolve().then(r.bind(r,1322));return i(e,t.messages)}getSessionToolResult(e,t){return this.runtime.getSessionToolResult(e,t)}getSessionWatchPath(e){return this.runtime.getSessionWatchPath(e)}run(e,t,r,i,n){return this.runtime.run(e,t,r,i,n)}steer(e,t){return this.runtime.steer(e,t)}abort(e){return this.runtime.abort(e)}async release(e){if(!this.runtime.release)throw new p.no("Native runtime release is unavailable","RUNTIME_UNAVAILABLE");await this.runtime.release(e)}answerQuestion(e,t){return this.runtime.answerQuestion(e,t)}async startRun(e,t,r,i="web",n){if(!this.runtime.startRun)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.startRun(e,t,r,i,n)}async subscribe(e,t,r){if(!this.runtime.subscribe)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.subscribe(e,t,r)}async snapshot(e,t=0){if(!this.runtime.snapshot)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.snapshot(e,t)}async setPermissionMode(e,t){if(!this.runtime.setPermissionMode)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.setPermissionMode(e,t)}async handoff(e,t){if(!this.runtime.handoff)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.handoff(e,t)}async getGoals(e,t="web"){if(!this.runtime.getGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.getGoals(e,t)}async enqueueGoal(e,t,r,i="web"){if(!this.runtime.enqueueGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueGoal(e,t,r,i)}async reorderGoals(e,t){if(!this.runtime.reorderGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderGoals(e,t)}async cancelGoal(e,t){if(!this.runtime.cancelGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelGoal(e,t,"web")}async enqueueMessage(e,t,r="web"){if(!this.runtime.enqueueMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueMessage(e,t,r)}async reorderMessages(e,t){if(!this.runtime.reorderMessages)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderMessages(e,t)}async updateMessage(e,t,r,i){if(!this.runtime.updateMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.updateMessage(e,t,r,i)}async cancelMessage(e,t){if(!this.runtime.cancelMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelMessage(e,t)}async steerMessage(e,t){if(!this.runtime.steerMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.steerMessage(e,t)}withPendingCreations(e){let t=new Set,r=e.map(e=>{t.add(e.id);let r=this.pendingCreations.get(e.id);return this.pendingCreations.delete(e.id),r?g(e,r):e});return[...[...this.pendingCreations.values()].filter(e=>!t.has(e.id)).sort((e,t)=>t.updated.localeCompare(e.updated)),...r]}}function g(e,t){return{...e,cwd:e.cwd||t.cwd,projectId:e.projectId??t.projectId}}function w(e,t){t.executable?delete process.env[e]:process.env[e]=t.detail}function v(){if(!m.__nativeRuntimeService){!function(){let e=[(0,s.join)((0,n.homedir)(),".local","bin"),"/opt/homebrew/bin","/usr/local/bin"],t=(process.env.PATH??"").split(s.delimiter),r=e.filter(e=>(0,i.existsSync)(e)&&!t.includes(e));r.length>0&&(process.env.PATH=[...t,...r].join(s.delimiter))}();let e=new o.XWE((0,d.kO)());m.__nativeRuntimeService=new f((0,p.v6)({runtimeFactory:e=>{let t=c({name:"codex",environmentVariable:"AGENT_CODEX_BIN",minimumVersion:o.hix}),r=c({name:"opencode",environmentVariable:"AGENT_OPENCODE_BIN"});return process.pid,w("AGENT_CODEX_RUNTIME_ERROR",t),w("AGENT_OPENCODE_RUNTIME_ERROR",r),(0,h.L)().info("native runtime host elected",{pid:process.pid,codex:t.executable??null,codexSource:t.source??null,codexDetail:t.detail,opencode:r.executable??null,opencodeDetail:r.detail}),(0,p.WH)(t.executable??"codex",e,r.executable??"opencode")}}),()=>e.list())}return m.__nativeRuntimeService}function O(e,t,r=process.platform){let{projectId:i,...n}=e;if(!e.cwd)return n;let a=N(e.cwd,r),o="win32"===r?s.win32.sep:s.sep,u=t.filter(e=>e.description).map(e=>({project:e,path:N(e.description,r)})).filter(({path:e})=>a===e||a.startsWith(`${e}${o}`)).sort((e,t)=>t.path.length-e.path.length)[0];return u?{...n,projectId:u.project.id}:n}function N(e,t=process.platform){if("win32"!==t)return(0,s.resolve)(e);let r=s.win32.resolve(e),i=s.win32.parse(r).root;return(r.length>i.length?r.replace(/[\\/]+$/,""):r).toLowerCase()}function E(e,t){return void 0===t?e:e.filter(e=>e.projectId===t)}function P(e){try{return"customer-agent"!==(0,p.Vu)(e).agentType}catch{return!1}}function _(e){if(e instanceof p.no)switch(e.code){case"SESSION_NOT_FOUND":return 404;case"SESSION_OCCUPIED":case"SESSION_ALREADY_RUNNING":case"APPROVAL_EXPIRED":case"CODEX_SESSION_VERSION_INCOMPATIBLE":case"STALE_SESSION_ANCHOR":return 409;case"RUNTIME_UNAVAILABLE":return 503;case"OPERATION_NOT_SUPPORTED":return 405;default:return 400}return 500}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),i=t.X(0,[8375,6703,6244,1322,1773],()=>r(3103));module.exports=i})();
@@ -1 +1 @@
1
- "use strict";(()=>{var e={};e.id=5369,e.ids=[5369,732],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},3425:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>w,patchFetch:()=>f,requestAsyncStorage:()=>p,routeModule:()=>h,serverHooks:()=>g,staticGenerationAsyncStorage:()=>m});var s={};r.r(s),r.d(s,{POST:()=>d});var i=r(7786),n=r(5042),a=r(2184),o=r(732),u=r(1890),l=r(7519),c=r(1614);async function d(e){try{let t=await e.json();if(!t.sessionId||!t.input&&!t.messageId)return u.NextResponse.json({error:"sessionId and input or messageId are required"},{status:400});if((0,c.V_)(t.sessionId)){if(t.messageId)return u.NextResponse.json(await (0,c.NL)().steerMessage(t.sessionId,t.messageId));if(!t.input)return u.NextResponse.json({error:"input is required"},{status:400});let e=await (0,c.NL)().steer(t.sessionId,t.input);return u.NextResponse.json({steered:e})}if(t.messageId)return u.NextResponse.json({steered:!0,state:await (0,o.getCustomerGoalCoordinator)().steer(t.sessionId,t.messageId)});if(!t.input)return u.NextResponse.json({error:"input is required"},{status:400});let r=await l.agentHost.steer(t.input,t.sessionId);return u.NextResponse.json({steered:r})}catch(e){return u.NextResponse.json({error:e instanceof Error?e.message:"Internal error"},{status:(0,c.WW)(e)})}}let h=new i.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/agent/steer/route",pathname:"/api/agent/steer",filename:"route",bundlePath:"app/api/agent/steer/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-37/customer-agent/packages/server/app/api/agent/steer/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:p,staticGenerationAsyncStorage:m,serverHooks:g}=h,w="/api/agent/steer/route";function f(){return(0,a.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:m})}},732:(e,t,r)=>{r.d(t,{getCustomerGoalCoordinator:()=>l,U:()=>c});var s=r(1322),i=r(7519);class n{constructor(e,t,r,s,i,n){this.store=e,this.busy=t,this.run=r,this.abort=s,this.steerRun=i,this.persist=n,this.tails=new Map,this.draining=new Set}async get(e,t=!0){let r=(0,s.E0T)((await this.require(e)).metadata);return t&&this.resume(e),r}async enqueue(e,t,r){let i=await this.mutate(e,i=>(0,s.WfK)(i,{id:crypto.randomUUID(),sessionId:e,objective:t,sourceMessageId:r,now:Date.now()}));return this.resume(e),i}async enqueueMessage(e,t,r,i){let n=await this.mutate(e,n=>[n.active,...n.queued,...n.history].some(e=>e?.sourceMessageId===r)?n:(0,s.InG)(n,{id:crypto.randomUUID(),sessionId:e,objective:t,sourceMessageId:r,messagePayload:i,now:Date.now(),activate:!1}));return this.resume(e),n}reorder(e,t,r=!1){return this.mutate(e,e=>r?(0,s.h1F)(e,t):(0,s.ZC9)(e,t))}updateMessage(e,t,r,i){return this.mutate(e,e=>(0,s.Wog)(e,t,r,i))}async cancel(e,t){let r=await this.mutate(e,r=>(r.active?.id===t&&this.draining.has(e)&&this.abort(e),(0,s.LJm)(r,t,Date.now())));return this.resume(e),r}async steer(e,t){return this.mutate(e,async r=>{let i=r.queued.find(e=>e.id===t&&"message"===e.kind);if(!i||!this.busy(e))throw Error("没有可引导的运行或排队消息");if(!await this.steerRun(e,i.objective))throw Error("运行已结束,请继续排队");return(0,s.LJm)(r,t,Date.now())})}resume(e){this.draining.has(e)||(this.draining.add(e),this.drain(e).catch(e=>console.error("Customer queue failed",e)).finally(()=>this.draining.delete(e)))}async drain(e){for(;;){let t;let r=await this.get(e,!1);if(!r.active&&!r.queued.length)return;if(this.busy(e)){await new Promise(e=>setTimeout(e,100));continue}let i=(await this.mutate(e,e=>(0,s.s_d)(e,Date.now()))).active;if(!i)continue;let n="failed";try{n=await this.run(e,i)}catch(e){if(e?.code==="SESSION_ALREADY_RUNNING")continue;t=e instanceof Error?e.message:String(e)}await this.mutate(e,e=>e.active?.id===i.id?(0,s.JXc)(e,n,Date.now(),t):e)}}async require(e){let t=await this.store.get(e);if(!t)throw Error("Session not found");return t}async mutate(e,t){let r=(this.tails.get(e)??Promise.resolve()).catch(()=>{}).then(async()=>{let r=await this.require(e),i=await t((0,s.E0T)(r.metadata));if(this.persist)this.persist(e,i);else{let t=await this.require(e);await this.store.update(e,{metadata:(0,s.eC7)(t.metadata,i)})}return i});this.tails.set(e,r);try{return await r}finally{this.tails.get(e)===r&&this.tails.delete(e)}}}var a=r(785);let o=globalThis,u=new Set;function l(){return o.__sharedCustomerQueue??=new n(i.agentHost.getSessionStore(),e=>i.agentHost.isSessionRunning(e),async(e,t)=>{u.add(e);try{return await i.agentHost.startRun(t.objective,e,t.messagePayload?.images,{agentIds:t.messagePayload?.agentIds}).completion,(await i.agentHost.getSessionStore().get(e))?.status==="completed"?"completed":"failed"}finally{u.delete(e)}},e=>{u.has(e)&&i.agentHost.abort(e)},(e,t)=>i.agentHost.steer(t,e),(e,t)=>{(0,s.N8n)((0,a.kO)()).db.prepare("UPDATE sessions SET metadata = json_set(metadata, '$.goalState', json(?)), updated = ? WHERE id = ?").run(JSON.stringify(t),new Date().toISOString(),e)})}function c(){for(let e of(0,s.N8n)((0,a.kO)()).db.prepare("SELECT id FROM sessions WHERE json_extract(metadata, '$.goalState.active') IS NOT NULL OR json_array_length(metadata, '$.goalState.queued') > 0").all())l().resume(e.id)}},1614:(e,t,r)=>{r.d(t,{NL:()=>N,V_:()=>O,WW:()=>y});var s=r(7561),i=r(612),n=r(9411),a=r(7718),o=r(1322);function u(e){if(!e.trim())return!1;try{return(0,s.accessSync)(e,s.constants.X_OK),!0}catch{return!1}}function l(e){try{return(0,o.wyD)((0,a.execFileSync)(e,["--version"],{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","pipe"]}))}catch{return}}function c(e){let t=[],r=process.env[e.environmentVariable]?.trim();if(r){let s=u(r);t.push({source:"pin",path:r,executable:s,version:s?l(r):void 0,error:s?void 0:`${e.environmentVariable} "${r}" is not executable`})}let s=function(e){for(let t of(process.env.PATH??"").split(n.delimiter).filter(Boolean)){let r=(0,n.resolve)(t,e);if(u(r))return r}}(e.name);return s&&s!==r&&t.push({source:"path",path:s,executable:!0,version:l(s)}),(0,o.neJ)(t,{name:e.name,minimumVersion:e.minimumVersion})}var d=r(535),h=r(6279),p=r(785);let m=globalThis;class g{constructor(e,t=async()=>[],r=process.platform){this.runtime=e,this.listProjects=t,this.platform=r,this.pendingCreations=new Map}health(){return this.runtime.health()}listModels(e){return this.runtime.listModels(e)}listWorkspaces(e,t){return this.runtime.listWorkspaces(e,t)}importWorkspace(e,t,r){if(!this.runtime.importWorkspace)throw new h.no("Native workspace import is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.importWorkspace(e,t,r)}async listWorkspaceSessions(e,t,r){let s=await this.runtime.listWorkspaceSessions(e,t,r);if(r?.cursor)return s;let i=new Set(s.data.map(e=>e.id)),n=s.data.map(e=>{let t=this.pendingCreations.get(e.id);return t?(this.pendingCreations.delete(e.id),w(e,t)):e});for(let r of this.pendingCreations.values())r.agentType!==e||r.projectId!==t||i.has(r.id)||n.unshift(r);return{...s,data:n}}async list(e){let[t,r]=await Promise.all([this.runtime.list(),this.listProjects()]);return I(this.withPendingCreations(t).map(e=>E(e,r,this.platform)),e)}async refresh(e){let[t,r]=await Promise.all([this.runtime.refresh(),this.listProjects()]);return I(this.withPendingCreations(t).map(e=>E(e,r,this.platform)),e)}async create(e){let t=E(await this.runtime.create(e),await this.listProjects(),this.platform),r=e.projectId?{...t,projectId:e.projectId}:t;return this.pendingCreations.set(r.id,r),r}async fork(e){if(!O(e))throw new h.no("Customer Agent sessions do not support native forks","OPERATION_NOT_SUPPORTED");let t=E(await this.runtime.fork(e),await this.listProjects(),this.platform);return this.pendingCreations.set(t.id,t),t}async delete(e){await this.runtime.delete(e),this.pendingCreations.delete(e)}async get(e,t){let r;try{r=await this.runtime.get(e,t)}catch(s){let r=this.pendingCreations.get(e);if(!r)throw s;return t?{...r,messages:[],events:[],history:{nextCursor:null,hasMore:!1,pageSize:0,totalItems:0}}:{...r,messages:[],events:[]}}return E(r,await this.listProjects(),this.platform)}async getQueryIndex(e){if(this.runtime.getQueryIndex)return this.runtime.getQueryIndex(e);let t=await this.runtime.get(e),{buildSessionQueryIndex:s}=await Promise.resolve().then(r.bind(r,1322));return s(e,t.messages)}getSessionToolResult(e,t){return this.runtime.getSessionToolResult(e,t)}getSessionWatchPath(e){return this.runtime.getSessionWatchPath(e)}run(e,t,r,s,i){return this.runtime.run(e,t,r,s,i)}steer(e,t){return this.runtime.steer(e,t)}abort(e){return this.runtime.abort(e)}async release(e){if(!this.runtime.release)throw new h.no("Native runtime release is unavailable","RUNTIME_UNAVAILABLE");await this.runtime.release(e)}answerQuestion(e,t){return this.runtime.answerQuestion(e,t)}async startRun(e,t,r,s="web",i){if(!this.runtime.startRun)throw new h.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.startRun(e,t,r,s,i)}async subscribe(e,t,r){if(!this.runtime.subscribe)throw new h.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.subscribe(e,t,r)}async snapshot(e,t=0){if(!this.runtime.snapshot)throw new h.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.snapshot(e,t)}async setPermissionMode(e,t){if(!this.runtime.setPermissionMode)throw new h.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.setPermissionMode(e,t)}async handoff(e,t){if(!this.runtime.handoff)throw new h.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.handoff(e,t)}async getGoals(e,t="web"){if(!this.runtime.getGoals)throw new h.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.getGoals(e,t)}async enqueueGoal(e,t,r,s="web"){if(!this.runtime.enqueueGoal)throw new h.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueGoal(e,t,r,s)}async reorderGoals(e,t){if(!this.runtime.reorderGoals)throw new h.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderGoals(e,t)}async cancelGoal(e,t){if(!this.runtime.cancelGoal)throw new h.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelGoal(e,t,"web")}async enqueueMessage(e,t,r="web"){if(!this.runtime.enqueueMessage)throw new h.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueMessage(e,t,r)}async reorderMessages(e,t){if(!this.runtime.reorderMessages)throw new h.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderMessages(e,t)}async updateMessage(e,t,r,s){if(!this.runtime.updateMessage)throw new h.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.updateMessage(e,t,r,s)}async cancelMessage(e,t){if(!this.runtime.cancelMessage)throw new h.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelMessage(e,t)}async steerMessage(e,t){if(!this.runtime.steerMessage)throw new h.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.steerMessage(e,t)}withPendingCreations(e){let t=new Set,r=e.map(e=>{t.add(e.id);let r=this.pendingCreations.get(e.id);return this.pendingCreations.delete(e.id),r?w(e,r):e});return[...[...this.pendingCreations.values()].filter(e=>!t.has(e.id)).sort((e,t)=>t.updated.localeCompare(e.updated)),...r]}}function w(e,t){return{...e,cwd:e.cwd||t.cwd,projectId:e.projectId??t.projectId}}function f(e,t){t.executable?delete process.env[e]:process.env[e]=t.detail}function N(){if(!m.__nativeRuntimeService){!function(){let e=[(0,n.join)((0,i.homedir)(),".local","bin"),"/opt/homebrew/bin","/usr/local/bin"],t=(process.env.PATH??"").split(n.delimiter),r=e.filter(e=>(0,s.existsSync)(e)&&!t.includes(e));r.length>0&&(process.env.PATH=[...t,...r].join(n.delimiter))}();let e=new o.XWE((0,p.kO)());m.__nativeRuntimeService=new g((0,h.v6)({runtimeFactory:e=>{let t=c({name:"codex",environmentVariable:"AGENT_CODEX_BIN",minimumVersion:o.hix}),r=c({name:"opencode",environmentVariable:"AGENT_OPENCODE_BIN"});return process.pid,f("AGENT_CODEX_RUNTIME_ERROR",t),f("AGENT_OPENCODE_RUNTIME_ERROR",r),(0,d.L)().info("native runtime host elected",{pid:process.pid,codex:t.executable??null,codexSource:t.source??null,codexDetail:t.detail,opencode:r.executable??null,opencodeDetail:r.detail}),(0,h.WH)(t.executable??"codex",e,r.executable??"opencode")}}),()=>e.list())}return m.__nativeRuntimeService}function E(e,t,r=process.platform){let{projectId:s,...i}=e;if(!e.cwd)return i;let a=v(e.cwd,r),o="win32"===r?n.win32.sep:n.sep,u=t.filter(e=>e.description).map(e=>({project:e,path:v(e.description,r)})).filter(({path:e})=>a===e||a.startsWith(`${e}${o}`)).sort((e,t)=>t.path.length-e.path.length)[0];return u?{...i,projectId:u.project.id}:i}function v(e,t=process.platform){if("win32"!==t)return(0,n.resolve)(e);let r=n.win32.resolve(e),s=n.win32.parse(r).root;return(r.length>s.length?r.replace(/[\\/]+$/,""):r).toLowerCase()}function I(e,t){return void 0===t?e:e.filter(e=>e.projectId===t)}function O(e){try{return"customer-agent"!==(0,h.Vu)(e).agentType}catch{return!1}}function y(e){if(e instanceof h.no)switch(e.code){case"SESSION_NOT_FOUND":return 404;case"SESSION_OCCUPIED":case"SESSION_ALREADY_RUNNING":case"APPROVAL_EXPIRED":case"CODEX_SESSION_VERSION_INCOMPATIBLE":case"STALE_SESSION_ANCHOR":return 409;case"RUNTIME_UNAVAILABLE":return 503;case"OPERATION_NOT_SUPPORTED":return 405;default:return 400}return 500}},1489:(e,t,r)=>{r.d(t,{N:()=>u});var s=r(1322),i=r(6279),n=r(785);class a{constructor(){this.tasks=new s.vo4((0,n.kO)()),this.scheduler=new i.ST(this.tasks,e=>{this.fire(e).catch(e=>console.error("Scheduled Customer Agent run failed",e))},()=>{}),this.scheduler.start()}async fire(e){let{agentHost:t}=await r.e(7519).then(r.bind(r,7519)),{getCustomerGoalCoordinator:s}=await Promise.all([r.e(7519),r.e(732)]).then(r.bind(r,732)),i=e.sessionId;i&&await t.getSessionStore().get(i)||(i=(await t.createSession(e.label||"定时任务")).id,this.tasks.update(e.id,{sessionId:i})),await s().enqueue(i,e.prompt)}call(e,t){let r=String(t[0]||"");switch(e){case"cronList":return this.tasks.list();case"cronCreate":{if("string"!=typeof t[0]||"string"!=typeof t[1]||!t[1].trim())throw Error("cron and prompt required");let e=t[2]&&"object"==typeof t[2]?t[2]:{};return this.tasks.create({cron:t[0],prompt:t[1],recurring:!1!==e.recurring,enabled:!0,durable:!0,..."string"==typeof e.sessionId?{sessionId:e.sessionId}:{},..."string"==typeof e.label?{label:e.label}:{}})}case"cronPause":return this.tasks.pause(r);case"cronResume":return this.tasks.resume(r);case"cronDelete":return this.tasks.delete(r);case"cronDeleteAll":return this.tasks.deleteAll(),{ok:!0};default:throw Error("Unsupported schedule operation")}}}let o=globalThis;function u(){return o.__sharedCronService??=new a}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[8375,6703,6244,1322,1773,4621,7519],()=>r(3425));module.exports=s})();
1
+ "use strict";(()=>{var e={};e.id=5369,e.ids=[5369,732],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},2687:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>w,patchFetch:()=>f,requestAsyncStorage:()=>p,routeModule:()=>h,serverHooks:()=>g,staticGenerationAsyncStorage:()=>m});var s={};r.r(s),r.d(s,{POST:()=>d});var i=r(7786),n=r(5042),a=r(2184),o=r(732),u=r(1890),l=r(7519),c=r(1614);async function d(e){try{let t=await e.json();if(!t.sessionId||!t.input&&!t.messageId)return u.NextResponse.json({error:"sessionId and input or messageId are required"},{status:400});if((0,c.V_)(t.sessionId)){if(t.messageId)return u.NextResponse.json(await (0,c.NL)().steerMessage(t.sessionId,t.messageId));if(!t.input)return u.NextResponse.json({error:"input is required"},{status:400});let e=await (0,c.NL)().steer(t.sessionId,t.input);return u.NextResponse.json({steered:e})}if(t.messageId)return u.NextResponse.json({steered:!0,state:await (0,o.getCustomerGoalCoordinator)().steer(t.sessionId,t.messageId)});if(!t.input)return u.NextResponse.json({error:"input is required"},{status:400});let r=await l.agentHost.steer(t.input,t.sessionId);return u.NextResponse.json({steered:r})}catch(e){return u.NextResponse.json({error:e instanceof Error?e.message:"Internal error"},{status:(0,c.WW)(e)})}}let h=new i.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/agent/steer/route",pathname:"/api/agent/steer",filename:"route",bundlePath:"app/api/agent/steer/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-39/customer-agent/packages/server/app/api/agent/steer/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:p,staticGenerationAsyncStorage:m,serverHooks:g}=h,w="/api/agent/steer/route";function f(){return(0,a.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:m})}},732:(e,t,r)=>{r.d(t,{getCustomerGoalCoordinator:()=>l,U:()=>c});var s=r(1322),i=r(7519);class n{constructor(e,t,r,s,i,n){this.store=e,this.busy=t,this.run=r,this.abort=s,this.steerRun=i,this.persist=n,this.tails=new Map,this.draining=new Set}async get(e,t=!0){let r=(0,s.E0T)((await this.require(e)).metadata);return t&&this.resume(e),r}async enqueue(e,t,r){let i=await this.mutate(e,i=>(0,s.WfK)(i,{id:crypto.randomUUID(),sessionId:e,objective:t,sourceMessageId:r,now:Date.now()}));return this.resume(e),i}async enqueueMessage(e,t,r,i){let n=await this.mutate(e,n=>[n.active,...n.queued,...n.history].some(e=>e?.sourceMessageId===r)?n:(0,s.InG)(n,{id:crypto.randomUUID(),sessionId:e,objective:t,sourceMessageId:r,messagePayload:i,now:Date.now(),activate:!1}));return this.resume(e),n}reorder(e,t,r=!1){return this.mutate(e,e=>r?(0,s.h1F)(e,t):(0,s.ZC9)(e,t))}updateMessage(e,t,r,i){return this.mutate(e,e=>(0,s.Wog)(e,t,r,i))}async cancel(e,t){let r=await this.mutate(e,r=>(r.active?.id===t&&this.draining.has(e)&&this.abort(e),(0,s.LJm)(r,t,Date.now())));return this.resume(e),r}async steer(e,t){return this.mutate(e,async r=>{let i=r.queued.find(e=>e.id===t&&"message"===e.kind);if(!i||!this.busy(e))throw Error("没有可引导的运行或排队消息");if(!await this.steerRun(e,i.objective))throw Error("运行已结束,请继续排队");return(0,s.LJm)(r,t,Date.now())})}resume(e){this.draining.has(e)||(this.draining.add(e),this.drain(e).catch(e=>console.error("Customer queue failed",e)).finally(()=>this.draining.delete(e)))}async drain(e){for(;;){let t;let r=await this.get(e,!1);if(!r.active&&!r.queued.length)return;if(this.busy(e)){await new Promise(e=>setTimeout(e,100));continue}let i=(await this.mutate(e,e=>(0,s.s_d)(e,Date.now()))).active;if(!i)continue;let n="failed";try{n=await this.run(e,i)}catch(e){if(e?.code==="SESSION_ALREADY_RUNNING")continue;t=e instanceof Error?e.message:String(e)}await this.mutate(e,e=>e.active?.id===i.id?(0,s.JXc)(e,n,Date.now(),t):e)}}async require(e){let t=await this.store.get(e);if(!t)throw Error("Session not found");return t}async mutate(e,t){let r=(this.tails.get(e)??Promise.resolve()).catch(()=>{}).then(async()=>{let r=await this.require(e),i=await t((0,s.E0T)(r.metadata));if(this.persist)this.persist(e,i);else{let t=await this.require(e);await this.store.update(e,{metadata:(0,s.eC7)(t.metadata,i)})}return i});this.tails.set(e,r);try{return await r}finally{this.tails.get(e)===r&&this.tails.delete(e)}}}var a=r(785);let o=globalThis,u=new Set;function l(){return o.__sharedCustomerQueue??=new n(i.agentHost.getSessionStore(),e=>i.agentHost.isSessionRunning(e),async(e,t)=>{u.add(e);try{return await i.agentHost.startRun(t.objective,e,t.messagePayload?.images,{agentIds:t.messagePayload?.agentIds}).completion,(await i.agentHost.getSessionStore().get(e))?.status==="completed"?"completed":"failed"}finally{u.delete(e)}},e=>{u.has(e)&&i.agentHost.abort(e)},(e,t)=>i.agentHost.steer(t,e),(e,t)=>{(0,s.N8n)((0,a.kO)()).db.prepare("UPDATE sessions SET metadata = json_set(metadata, '$.goalState', json(?)), updated = ? WHERE id = ?").run(JSON.stringify(t),new Date().toISOString(),e)})}function c(){for(let e of(0,s.N8n)((0,a.kO)()).db.prepare("SELECT id FROM sessions WHERE json_extract(metadata, '$.goalState.active') IS NOT NULL OR json_array_length(metadata, '$.goalState.queued') > 0").all())l().resume(e.id)}},1614:(e,t,r)=>{r.d(t,{NL:()=>N,V_:()=>O,WW:()=>y});var s=r(7561),i=r(612),n=r(9411),a=r(7718),o=r(1322);function u(e){if(!e.trim())return!1;try{return(0,s.accessSync)(e,s.constants.X_OK),!0}catch{return!1}}function l(e){try{return(0,o.wyD)((0,a.execFileSync)(e,["--version"],{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","pipe"]}))}catch{return}}function c(e){let t=[],r=process.env[e.environmentVariable]?.trim();if(r){let s=u(r);t.push({source:"pin",path:r,executable:s,version:s?l(r):void 0,error:s?void 0:`${e.environmentVariable} "${r}" is not executable`})}let s=function(e){for(let t of(process.env.PATH??"").split(n.delimiter).filter(Boolean)){let r=(0,n.resolve)(t,e);if(u(r))return r}}(e.name);return s&&s!==r&&t.push({source:"path",path:s,executable:!0,version:l(s)}),(0,o.neJ)(t,{name:e.name,minimumVersion:e.minimumVersion})}var d=r(535),h=r(6279),p=r(785);let m=globalThis;class g{constructor(e,t=async()=>[],r=process.platform){this.runtime=e,this.listProjects=t,this.platform=r,this.pendingCreations=new Map}health(){return this.runtime.health()}listModels(e){return this.runtime.listModels(e)}listWorkspaces(e,t){return this.runtime.listWorkspaces(e,t)}importWorkspace(e,t,r){if(!this.runtime.importWorkspace)throw new h.no("Native workspace import is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.importWorkspace(e,t,r)}async listWorkspaceSessions(e,t,r){let s=await this.runtime.listWorkspaceSessions(e,t,r);if(r?.cursor)return s;let i=new Set(s.data.map(e=>e.id)),n=s.data.map(e=>{let t=this.pendingCreations.get(e.id);return t?(this.pendingCreations.delete(e.id),w(e,t)):e});for(let r of this.pendingCreations.values())r.agentType!==e||r.projectId!==t||i.has(r.id)||n.unshift(r);return{...s,data:n}}async list(e){let[t,r]=await Promise.all([this.runtime.list(),this.listProjects()]);return I(this.withPendingCreations(t).map(e=>E(e,r,this.platform)),e)}async refresh(e){let[t,r]=await Promise.all([this.runtime.refresh(),this.listProjects()]);return I(this.withPendingCreations(t).map(e=>E(e,r,this.platform)),e)}async create(e){let t=E(await this.runtime.create(e),await this.listProjects(),this.platform),r=e.projectId?{...t,projectId:e.projectId}:t;return this.pendingCreations.set(r.id,r),r}async fork(e,t){if(!O(e))throw new h.no("Customer Agent sessions do not support native forks","OPERATION_NOT_SUPPORTED");let r=E(t?await this.runtime.fork(e,t):await this.runtime.fork(e),await this.listProjects(),this.platform);return this.pendingCreations.set(r.id,r),r}async delete(e){await this.runtime.delete(e),this.pendingCreations.delete(e)}async get(e,t){let r;try{r=await this.runtime.get(e,t)}catch(s){let r=this.pendingCreations.get(e);if(!r)throw s;return t?{...r,messages:[],events:[],history:{nextCursor:null,hasMore:!1,pageSize:0,totalItems:0}}:{...r,messages:[],events:[]}}return E(r,await this.listProjects(),this.platform)}async getQueryIndex(e){if(this.runtime.getQueryIndex)return this.runtime.getQueryIndex(e);let t=await this.runtime.get(e),{buildSessionQueryIndex:s}=await Promise.resolve().then(r.bind(r,1322));return s(e,t.messages)}getSessionToolResult(e,t){return this.runtime.getSessionToolResult(e,t)}getSessionWatchPath(e){return this.runtime.getSessionWatchPath(e)}run(e,t,r,s,i){return this.runtime.run(e,t,r,s,i)}steer(e,t){return this.runtime.steer(e,t)}abort(e){return this.runtime.abort(e)}async release(e){if(!this.runtime.release)throw new h.no("Native runtime release is unavailable","RUNTIME_UNAVAILABLE");await this.runtime.release(e)}answerQuestion(e,t){return this.runtime.answerQuestion(e,t)}async startRun(e,t,r,s="web",i){if(!this.runtime.startRun)throw new h.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.startRun(e,t,r,s,i)}async subscribe(e,t,r){if(!this.runtime.subscribe)throw new h.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.subscribe(e,t,r)}async snapshot(e,t=0){if(!this.runtime.snapshot)throw new h.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.snapshot(e,t)}async setPermissionMode(e,t){if(!this.runtime.setPermissionMode)throw new h.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.setPermissionMode(e,t)}async handoff(e,t){if(!this.runtime.handoff)throw new h.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.handoff(e,t)}async getGoals(e,t="web"){if(!this.runtime.getGoals)throw new h.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.getGoals(e,t)}async enqueueGoal(e,t,r,s="web"){if(!this.runtime.enqueueGoal)throw new h.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueGoal(e,t,r,s)}async reorderGoals(e,t){if(!this.runtime.reorderGoals)throw new h.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderGoals(e,t)}async cancelGoal(e,t){if(!this.runtime.cancelGoal)throw new h.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelGoal(e,t,"web")}async enqueueMessage(e,t,r="web"){if(!this.runtime.enqueueMessage)throw new h.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueMessage(e,t,r)}async reorderMessages(e,t){if(!this.runtime.reorderMessages)throw new h.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderMessages(e,t)}async updateMessage(e,t,r,s){if(!this.runtime.updateMessage)throw new h.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.updateMessage(e,t,r,s)}async cancelMessage(e,t){if(!this.runtime.cancelMessage)throw new h.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelMessage(e,t)}async steerMessage(e,t){if(!this.runtime.steerMessage)throw new h.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.steerMessage(e,t)}withPendingCreations(e){let t=new Set,r=e.map(e=>{t.add(e.id);let r=this.pendingCreations.get(e.id);return this.pendingCreations.delete(e.id),r?w(e,r):e});return[...[...this.pendingCreations.values()].filter(e=>!t.has(e.id)).sort((e,t)=>t.updated.localeCompare(e.updated)),...r]}}function w(e,t){return{...e,cwd:e.cwd||t.cwd,projectId:e.projectId??t.projectId}}function f(e,t){t.executable?delete process.env[e]:process.env[e]=t.detail}function N(){if(!m.__nativeRuntimeService){!function(){let e=[(0,n.join)((0,i.homedir)(),".local","bin"),"/opt/homebrew/bin","/usr/local/bin"],t=(process.env.PATH??"").split(n.delimiter),r=e.filter(e=>(0,s.existsSync)(e)&&!t.includes(e));r.length>0&&(process.env.PATH=[...t,...r].join(n.delimiter))}();let e=new o.XWE((0,p.kO)());m.__nativeRuntimeService=new g((0,h.v6)({runtimeFactory:e=>{let t=c({name:"codex",environmentVariable:"AGENT_CODEX_BIN",minimumVersion:o.hix}),r=c({name:"opencode",environmentVariable:"AGENT_OPENCODE_BIN"});return process.pid,f("AGENT_CODEX_RUNTIME_ERROR",t),f("AGENT_OPENCODE_RUNTIME_ERROR",r),(0,d.L)().info("native runtime host elected",{pid:process.pid,codex:t.executable??null,codexSource:t.source??null,codexDetail:t.detail,opencode:r.executable??null,opencodeDetail:r.detail}),(0,h.WH)(t.executable??"codex",e,r.executable??"opencode")}}),()=>e.list())}return m.__nativeRuntimeService}function E(e,t,r=process.platform){let{projectId:s,...i}=e;if(!e.cwd)return i;let a=v(e.cwd,r),o="win32"===r?n.win32.sep:n.sep,u=t.filter(e=>e.description).map(e=>({project:e,path:v(e.description,r)})).filter(({path:e})=>a===e||a.startsWith(`${e}${o}`)).sort((e,t)=>t.path.length-e.path.length)[0];return u?{...i,projectId:u.project.id}:i}function v(e,t=process.platform){if("win32"!==t)return(0,n.resolve)(e);let r=n.win32.resolve(e),s=n.win32.parse(r).root;return(r.length>s.length?r.replace(/[\\/]+$/,""):r).toLowerCase()}function I(e,t){return void 0===t?e:e.filter(e=>e.projectId===t)}function O(e){try{return"customer-agent"!==(0,h.Vu)(e).agentType}catch{return!1}}function y(e){if(e instanceof h.no)switch(e.code){case"SESSION_NOT_FOUND":return 404;case"SESSION_OCCUPIED":case"SESSION_ALREADY_RUNNING":case"APPROVAL_EXPIRED":case"CODEX_SESSION_VERSION_INCOMPATIBLE":case"STALE_SESSION_ANCHOR":return 409;case"RUNTIME_UNAVAILABLE":return 503;case"OPERATION_NOT_SUPPORTED":return 405;default:return 400}return 500}},1489:(e,t,r)=>{r.d(t,{N:()=>u});var s=r(1322),i=r(6279),n=r(785);class a{constructor(){this.tasks=new s.vo4((0,n.kO)()),this.scheduler=new i.ST(this.tasks,e=>{this.fire(e).catch(e=>console.error("Scheduled Customer Agent run failed",e))},()=>{}),this.scheduler.start()}async fire(e){let{agentHost:t}=await r.e(7519).then(r.bind(r,7519)),{getCustomerGoalCoordinator:s}=await Promise.all([r.e(7519),r.e(732)]).then(r.bind(r,732)),i=e.sessionId;i&&await t.getSessionStore().get(i)||(i=(await t.createSession(e.label||"定时任务")).id,this.tasks.update(e.id,{sessionId:i})),await s().enqueue(i,e.prompt)}call(e,t){let r=String(t[0]||"");switch(e){case"cronList":return this.tasks.list();case"cronCreate":{if("string"!=typeof t[0]||"string"!=typeof t[1]||!t[1].trim())throw Error("cron and prompt required");let e=t[2]&&"object"==typeof t[2]?t[2]:{};return this.tasks.create({cron:t[0],prompt:t[1],recurring:!1!==e.recurring,enabled:!0,durable:!0,..."string"==typeof e.sessionId?{sessionId:e.sessionId}:{},..."string"==typeof e.label?{label:e.label}:{}})}case"cronPause":return this.tasks.pause(r);case"cronResume":return this.tasks.resume(r);case"cronDelete":return this.tasks.delete(r);case"cronDeleteAll":return this.tasks.deleteAll(),{ok:!0};default:throw Error("Unsupported schedule operation")}}}let o=globalThis;function u(){return o.__sharedCronService??=new a}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[8375,6703,6244,1322,1773,4621,7519],()=>r(2687));module.exports=s})();
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var e={};e.id=820,e.ids=[820],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},95:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>g,patchFetch:()=>v,requestAsyncStorage:()=>h,routeModule:()=>p,serverHooks:()=>f,staticGenerationAsyncStorage:()=>m});var n={};r.r(n),r.d(n,{GET:()=>c});var s=r(7786),i=r(5042),a=r(2184),o=r(7519),u=r(1614),l=r(1079);async function c(e){(0,l.j)();let t=new URL(e.url).searchParams.get("sessionId");if(!t)return new Response("sessionId is required",{status:400});if((0,u.V_)(t))return d(e,t);let r=!1,n=null,s=null;return new Response(new ReadableStream({start(i){let a=new TextEncoder,u=()=>{if(!r){r=!0,n?.(),n=null,s&&e.signal.removeEventListener("abort",s);try{i.close()}catch{}}},l=e=>{if(r)return!1;try{return i.enqueue(a.encode(e)),!0}catch{return u(),!1}};if(!l(": connected\n\n"))return;let c=Number.parseInt(e.headers.get("last-event-id")??"",10),d=Number.parseInt(new URL(e.url).searchParams.get("afterEventId")??"",10),p=Number.isSafeInteger(c)?c:Number.isSafeInteger(d)?d:o.agentHost.isSessionRunning(t)?0:o.agentHost.getLatestEventId(t);n=o.agentHost.subscribe(t,(e,t)=>{l(`id: ${t}
1
+ "use strict";(()=>{var e={};e.id=820,e.ids=[820],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},9432:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>g,patchFetch:()=>v,requestAsyncStorage:()=>h,routeModule:()=>p,serverHooks:()=>f,staticGenerationAsyncStorage:()=>m});var n={};r.r(n),r.d(n,{GET:()=>c});var s=r(7786),i=r(5042),a=r(2184),o=r(7519),u=r(1614),l=r(1079);async function c(e){(0,l.j)();let t=new URL(e.url).searchParams.get("sessionId");if(!t)return new Response("sessionId is required",{status:400});if((0,u.V_)(t))return d(e,t);let r=!1,n=null,s=null;return new Response(new ReadableStream({start(i){let a=new TextEncoder,u=()=>{if(!r){r=!0,n?.(),n=null,s&&e.signal.removeEventListener("abort",s);try{i.close()}catch{}}},l=e=>{if(r)return!1;try{return i.enqueue(a.encode(e)),!0}catch{return u(),!1}};if(!l(": connected\n\n"))return;let c=Number.parseInt(e.headers.get("last-event-id")??"",10),d=Number.parseInt(new URL(e.url).searchParams.get("afterEventId")??"",10),p=Number.isSafeInteger(c)?c:Number.isSafeInteger(d)?d:o.agentHost.isSessionRunning(t)?0:o.agentHost.getLatestEventId(t);n=o.agentHost.subscribe(t,(e,t)=>{l(`id: ${t}
2
2
  data: ${JSON.stringify(e)}
3
3
 
4
4
  `)&&("done"===e.type||"error"===e.type)&&u()},p),s=u,e.signal.aborted?u():e.signal.addEventListener("abort",s,{once:!0})},cancel(){r=!0,n?.(),n=null,s&&e.signal.removeEventListener("abort",s)}}),{headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})}async function d(e,t){let r=!1,n=null,s=null,i=(0,u.NL)(),a=new URL(e.url),o=Number.parseInt(a.searchParams.get("afterSequence")??"",10),l=a.searchParams.get("afterRunId"),c=e.headers.get("last-event-id");return new Response(new ReadableStream({async start(a){let u=new TextEncoder,d=()=>{if(!r){r=!0,n?.(),n=null,s&&e.signal.removeEventListener("abort",s);try{a.close()}catch{}}},p=e=>{if(r)return!1;try{return a.enqueue(u.encode(e)),!0}catch{return d(),!1}};if(p(": connected\n\n"))try{let r=await i.snapshot(t),a=function(e){if(!e)return null;let t=e.lastIndexOf(":");if(t<0){let t=Number.parseInt(e,10);return Number.isSafeInteger(t)?{runId:null,sequence:t}:null}let r=e.slice(0,t),n=Number.parseInt(e.slice(t+1),10);return r&&Number.isSafeInteger(n)?{runId:r,sequence:n}:null}(c),u=Number.isSafeInteger(o)?{runId:l,sequence:o}:null,h=a??u,m=h?h.runId&&h.runId!==r.runId?0:h.sequence:r.snapshotRevision;n=await i.subscribe(t,m,({runId:e,sequence:t,event:r})=>{let n={...r,_nativeRunId:e,_nativeSequence:t};p(`id: ${e}:${t}
@@ -7,7 +7,7 @@ data: ${JSON.stringify(n)}
7
7
  `)&&("done"===r.type||"error"===r.type)&&d()}),s=d,e.signal.aborted?d():e.signal.addEventListener("abort",s,{once:!0})}catch(e){p(`event: error
8
8
  data: ${JSON.stringify({type:"error",message:e instanceof Error?e.message:"Native stream failed"})}
9
9
 
10
- `),d()}},cancel(){r=!0,n?.(),n=null,s&&e.signal.removeEventListener("abort",s)}}),{headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})}let p=new s.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/agent/stream/route",pathname:"/api/agent/stream",filename:"route",bundlePath:"app/api/agent/stream/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-37/customer-agent/packages/server/app/api/agent/stream/route.ts",nextConfigOutput:"standalone",userland:n}),{requestAsyncStorage:h,staticGenerationAsyncStorage:m,serverHooks:f}=p,g="/api/agent/stream/route";function v(){return(0,a.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:m})}},7786:(e,t,r)=>{e.exports=r(517)},1614:(e,t,r)=>{r.d(t,{NL:()=>E,V_:()=>T,WW:()=>N});var n=r(7561),s=r(612),i=r(9411),a=r(7718),o=r(1322);function u(e){if(!e.trim())return!1;try{return(0,n.accessSync)(e,n.constants.X_OK),!0}catch{return!1}}function l(e){try{return(0,o.wyD)((0,a.execFileSync)(e,["--version"],{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","pipe"]}))}catch{return}}function c(e){let t=[],r=process.env[e.environmentVariable]?.trim();if(r){let n=u(r);t.push({source:"pin",path:r,executable:n,version:n?l(r):void 0,error:n?void 0:`${e.environmentVariable} "${r}" is not executable`})}let n=function(e){for(let t of(process.env.PATH??"").split(i.delimiter).filter(Boolean)){let r=(0,i.resolve)(t,e);if(u(r))return r}}(e.name);return n&&n!==r&&t.push({source:"path",path:n,executable:!0,version:l(n)}),(0,o.neJ)(t,{name:e.name,minimumVersion:e.minimumVersion})}var d=r(535),p=r(6279),h=r(785);let m=globalThis;class f{constructor(e,t=async()=>[],r=process.platform){this.runtime=e,this.listProjects=t,this.platform=r,this.pendingCreations=new Map}health(){return this.runtime.health()}listModels(e){return this.runtime.listModels(e)}listWorkspaces(e,t){return this.runtime.listWorkspaces(e,t)}importWorkspace(e,t,r){if(!this.runtime.importWorkspace)throw new p.no("Native workspace import is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.importWorkspace(e,t,r)}async listWorkspaceSessions(e,t,r){let n=await this.runtime.listWorkspaceSessions(e,t,r);if(r?.cursor)return n;let s=new Set(n.data.map(e=>e.id)),i=n.data.map(e=>{let t=this.pendingCreations.get(e.id);return t?(this.pendingCreations.delete(e.id),g(e,t)):e});for(let r of this.pendingCreations.values())r.agentType!==e||r.projectId!==t||s.has(r.id)||i.unshift(r);return{...n,data:i}}async list(e){let[t,r]=await Promise.all([this.runtime.list(),this.listProjects()]);return w(this.withPendingCreations(t).map(e=>b(e,r,this.platform)),e)}async refresh(e){let[t,r]=await Promise.all([this.runtime.refresh(),this.listProjects()]);return w(this.withPendingCreations(t).map(e=>b(e,r,this.platform)),e)}async create(e){let t=b(await this.runtime.create(e),await this.listProjects(),this.platform),r=e.projectId?{...t,projectId:e.projectId}:t;return this.pendingCreations.set(r.id,r),r}async fork(e){if(!T(e))throw new p.no("Customer Agent sessions do not support native forks","OPERATION_NOT_SUPPORTED");let t=b(await this.runtime.fork(e),await this.listProjects(),this.platform);return this.pendingCreations.set(t.id,t),t}async delete(e){await this.runtime.delete(e),this.pendingCreations.delete(e)}async get(e,t){let r;try{r=await this.runtime.get(e,t)}catch(n){let r=this.pendingCreations.get(e);if(!r)throw n;return t?{...r,messages:[],events:[],history:{nextCursor:null,hasMore:!1,pageSize:0,totalItems:0}}:{...r,messages:[],events:[]}}return b(r,await this.listProjects(),this.platform)}async getQueryIndex(e){if(this.runtime.getQueryIndex)return this.runtime.getQueryIndex(e);let t=await this.runtime.get(e),{buildSessionQueryIndex:n}=await Promise.resolve().then(r.bind(r,1322));return n(e,t.messages)}getSessionToolResult(e,t){return this.runtime.getSessionToolResult(e,t)}getSessionWatchPath(e){return this.runtime.getSessionWatchPath(e)}run(e,t,r,n,s){return this.runtime.run(e,t,r,n,s)}steer(e,t){return this.runtime.steer(e,t)}abort(e){return this.runtime.abort(e)}async release(e){if(!this.runtime.release)throw new p.no("Native runtime release is unavailable","RUNTIME_UNAVAILABLE");await this.runtime.release(e)}answerQuestion(e,t){return this.runtime.answerQuestion(e,t)}async startRun(e,t,r,n="web",s){if(!this.runtime.startRun)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.startRun(e,t,r,n,s)}async subscribe(e,t,r){if(!this.runtime.subscribe)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.subscribe(e,t,r)}async snapshot(e,t=0){if(!this.runtime.snapshot)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.snapshot(e,t)}async setPermissionMode(e,t){if(!this.runtime.setPermissionMode)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.setPermissionMode(e,t)}async handoff(e,t){if(!this.runtime.handoff)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.handoff(e,t)}async getGoals(e,t="web"){if(!this.runtime.getGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.getGoals(e,t)}async enqueueGoal(e,t,r,n="web"){if(!this.runtime.enqueueGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueGoal(e,t,r,n)}async reorderGoals(e,t){if(!this.runtime.reorderGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderGoals(e,t)}async cancelGoal(e,t){if(!this.runtime.cancelGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelGoal(e,t,"web")}async enqueueMessage(e,t,r="web"){if(!this.runtime.enqueueMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueMessage(e,t,r)}async reorderMessages(e,t){if(!this.runtime.reorderMessages)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderMessages(e,t)}async updateMessage(e,t,r,n){if(!this.runtime.updateMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.updateMessage(e,t,r,n)}async cancelMessage(e,t){if(!this.runtime.cancelMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelMessage(e,t)}async steerMessage(e,t){if(!this.runtime.steerMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.steerMessage(e,t)}withPendingCreations(e){let t=new Set,r=e.map(e=>{t.add(e.id);let r=this.pendingCreations.get(e.id);return this.pendingCreations.delete(e.id),r?g(e,r):e});return[...[...this.pendingCreations.values()].filter(e=>!t.has(e.id)).sort((e,t)=>t.updated.localeCompare(e.updated)),...r]}}function g(e,t){return{...e,cwd:e.cwd||t.cwd,projectId:e.projectId??t.projectId}}function v(e,t){t.executable?delete process.env[e]:process.env[e]=t.detail}function E(){if(!m.__nativeRuntimeService){!function(){let e=[(0,i.join)((0,s.homedir)(),".local","bin"),"/opt/homebrew/bin","/usr/local/bin"],t=(process.env.PATH??"").split(i.delimiter),r=e.filter(e=>(0,n.existsSync)(e)&&!t.includes(e));r.length>0&&(process.env.PATH=[...t,...r].join(i.delimiter))}();let e=new o.XWE((0,h.kO)());m.__nativeRuntimeService=new f((0,p.v6)({runtimeFactory:e=>{let t=c({name:"codex",environmentVariable:"AGENT_CODEX_BIN",minimumVersion:o.hix}),r=c({name:"opencode",environmentVariable:"AGENT_OPENCODE_BIN"});return process.pid,v("AGENT_CODEX_RUNTIME_ERROR",t),v("AGENT_OPENCODE_RUNTIME_ERROR",r),(0,d.L)().info("native runtime host elected",{pid:process.pid,codex:t.executable??null,codexSource:t.source??null,codexDetail:t.detail,opencode:r.executable??null,opencodeDetail:r.detail}),(0,p.WH)(t.executable??"codex",e,r.executable??"opencode")}}),()=>e.list())}return m.__nativeRuntimeService}function b(e,t,r=process.platform){let{projectId:n,...s}=e;if(!e.cwd)return s;let a=y(e.cwd,r),o="win32"===r?i.win32.sep:i.sep,u=t.filter(e=>e.description).map(e=>({project:e,path:y(e.description,r)})).filter(({path:e})=>a===e||a.startsWith(`${e}${o}`)).sort((e,t)=>t.path.length-e.path.length)[0];return u?{...s,projectId:u.project.id}:s}function y(e,t=process.platform){if("win32"!==t)return(0,i.resolve)(e);let r=i.win32.resolve(e),n=i.win32.parse(r).root;return(r.length>n.length?r.replace(/[\\/]+$/,""):r).toLowerCase()}function w(e,t){return void 0===t?e:e.filter(e=>e.projectId===t)}function T(e){try{return"customer-agent"!==(0,p.Vu)(e).agentType}catch{return!1}}function N(e){if(e instanceof p.no)switch(e.code){case"SESSION_NOT_FOUND":return 404;case"SESSION_OCCUPIED":case"SESSION_ALREADY_RUNNING":case"APPROVAL_EXPIRED":case"CODEX_SESSION_VERSION_INCOMPATIBLE":case"STALE_SESSION_ANCHOR":return 409;case"RUNTIME_UNAVAILABLE":return 503;case"OPERATION_NOT_SUPPORTED":return 405;default:return 400}return 500}},1079:(e,t,r)=>{r.d(t,{j:()=>c});var n=r(7519),s=r(3931),i=r(535),a=r(1322),o=r(1982);let u=!1,l=new a.sSf;function c(){u||(u=!0,n.agentHost.setGlobalEventObserver((e,t,r)=>{try{if("ask_user"===t.type){(0,s.i)().notifySession({notificationId:`${e}:${t.questionId}:approval`,sessionId:e,kind:"approval",title:"需要你的审批",body:"string"==typeof t.question&&t.question.trim()?t.question.trim().slice(0,160):"会话正在等待确认",url:"/app/"});return}if("done"===t.type){if("goal"===r.source)return;let n=(0,a.mDL)((0,o.dp)().read().taskNotifications),i=r.runId?(0,a.DXW)({sessionId:e,runId:r.runId,title:"任务已完成",finalText:t.finalText,outcome:"completed",source:"user"},n):null;i&&l.accept(i.notificationId)&&(0,s.i)().notifySession({...i,url:`/app/?session=${encodeURIComponent(e)}`});return}if("goal_updated"===t.type&&"complete"===t.goal.status){let r=(0,a.mDL)((0,o.dp)().read().taskNotifications),n=(0,a.DXW)({sessionId:e,runId:`goal:${t.goal.createdAt}`,title:"目标已完成",finalText:t.goal.objective,outcome:"completed",source:"goal",goalFinished:!0},r);n&&l.accept(n.notificationId)&&(0,s.i)().notifySession({...n,url:`/app/?session=${encodeURIComponent(e)}`});return}"error"===t.type&&(0,s.i)().notifySession({notificationId:`${e}:${r.runId??"unknown"}:error`,sessionId:e,kind:"error",title:"会话出错",body:"string"==typeof t.message&&t.message.trim()?t.message.trim().slice(0,160):"运行失败",url:"/app/"})}catch(t){(0,i.L)().warn("web push notify failed",{sessionId:e,error:t instanceof Error?t.message:String(t)})}}))}},1489:(e,t,r)=>{r.d(t,{N:()=>u});var n=r(1322),s=r(6279),i=r(785);class a{constructor(){this.tasks=new n.vo4((0,i.kO)()),this.scheduler=new s.ST(this.tasks,e=>{this.fire(e).catch(e=>console.error("Scheduled Customer Agent run failed",e))},()=>{}),this.scheduler.start()}async fire(e){let{agentHost:t}=await r.e(7519).then(r.bind(r,7519)),{getCustomerGoalCoordinator:n}=await Promise.all([r.e(7519),r.e(732)]).then(r.bind(r,732)),s=e.sessionId;s&&await t.getSessionStore().get(s)||(s=(await t.createSession(e.label||"定时任务")).id,this.tasks.update(e.id,{sessionId:s})),await n().enqueue(s,e.prompt)}call(e,t){let r=String(t[0]||"");switch(e){case"cronList":return this.tasks.list();case"cronCreate":{if("string"!=typeof t[0]||"string"!=typeof t[1]||!t[1].trim())throw Error("cron and prompt required");let e=t[2]&&"object"==typeof t[2]?t[2]:{};return this.tasks.create({cron:t[0],prompt:t[1],recurring:!1!==e.recurring,enabled:!0,durable:!0,..."string"==typeof e.sessionId?{sessionId:e.sessionId}:{},..."string"==typeof e.label?{label:e.label}:{}})}case"cronPause":return this.tasks.pause(r);case"cronResume":return this.tasks.resume(r);case"cronDelete":return this.tasks.delete(r);case"cronDeleteAll":return this.tasks.deleteAll(),{ok:!0};default:throw Error("Unsupported schedule operation")}}}let o=globalThis;function u(){return o.__sharedCronService??=new a}},3931:(e,t,r)=>{r.d(t,{i:()=>p});var n=r(6005),s=r(7561),i=r(9411),a=r(5890);let o=require("web-push"),u=e=>JSON.stringify(e??null);class l{constructor(e,t=Date.now){this.now=t;let r=(0,i.resolve)(e,".agentroam-auth");(0,s.mkdirSync)(r,{recursive:!0,mode:448});let n=(0,i.join)(r,"push.sqlite");this.db=new a(n),(0,s.chmodSync)(n,384),this.db.pragma("busy_timeout = 5000"),this.db.exec(`
10
+ `),d()}},cancel(){r=!0,n?.(),n=null,s&&e.signal.removeEventListener("abort",s)}}),{headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})}let p=new s.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/agent/stream/route",pathname:"/api/agent/stream",filename:"route",bundlePath:"app/api/agent/stream/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-39/customer-agent/packages/server/app/api/agent/stream/route.ts",nextConfigOutput:"standalone",userland:n}),{requestAsyncStorage:h,staticGenerationAsyncStorage:m,serverHooks:f}=p,g="/api/agent/stream/route";function v(){return(0,a.patchFetch)({serverHooks:f,staticGenerationAsyncStorage:m})}},7786:(e,t,r)=>{e.exports=r(517)},1614:(e,t,r)=>{r.d(t,{NL:()=>E,V_:()=>T,WW:()=>N});var n=r(7561),s=r(612),i=r(9411),a=r(7718),o=r(1322);function u(e){if(!e.trim())return!1;try{return(0,n.accessSync)(e,n.constants.X_OK),!0}catch{return!1}}function l(e){try{return(0,o.wyD)((0,a.execFileSync)(e,["--version"],{encoding:"utf8",timeout:5e3,stdio:["ignore","pipe","pipe"]}))}catch{return}}function c(e){let t=[],r=process.env[e.environmentVariable]?.trim();if(r){let n=u(r);t.push({source:"pin",path:r,executable:n,version:n?l(r):void 0,error:n?void 0:`${e.environmentVariable} "${r}" is not executable`})}let n=function(e){for(let t of(process.env.PATH??"").split(i.delimiter).filter(Boolean)){let r=(0,i.resolve)(t,e);if(u(r))return r}}(e.name);return n&&n!==r&&t.push({source:"path",path:n,executable:!0,version:l(n)}),(0,o.neJ)(t,{name:e.name,minimumVersion:e.minimumVersion})}var d=r(535),p=r(6279),h=r(785);let m=globalThis;class f{constructor(e,t=async()=>[],r=process.platform){this.runtime=e,this.listProjects=t,this.platform=r,this.pendingCreations=new Map}health(){return this.runtime.health()}listModels(e){return this.runtime.listModels(e)}listWorkspaces(e,t){return this.runtime.listWorkspaces(e,t)}importWorkspace(e,t,r){if(!this.runtime.importWorkspace)throw new p.no("Native workspace import is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.importWorkspace(e,t,r)}async listWorkspaceSessions(e,t,r){let n=await this.runtime.listWorkspaceSessions(e,t,r);if(r?.cursor)return n;let s=new Set(n.data.map(e=>e.id)),i=n.data.map(e=>{let t=this.pendingCreations.get(e.id);return t?(this.pendingCreations.delete(e.id),g(e,t)):e});for(let r of this.pendingCreations.values())r.agentType!==e||r.projectId!==t||s.has(r.id)||i.unshift(r);return{...n,data:i}}async list(e){let[t,r]=await Promise.all([this.runtime.list(),this.listProjects()]);return w(this.withPendingCreations(t).map(e=>b(e,r,this.platform)),e)}async refresh(e){let[t,r]=await Promise.all([this.runtime.refresh(),this.listProjects()]);return w(this.withPendingCreations(t).map(e=>b(e,r,this.platform)),e)}async create(e){let t=b(await this.runtime.create(e),await this.listProjects(),this.platform),r=e.projectId?{...t,projectId:e.projectId}:t;return this.pendingCreations.set(r.id,r),r}async fork(e,t){if(!T(e))throw new p.no("Customer Agent sessions do not support native forks","OPERATION_NOT_SUPPORTED");let r=b(t?await this.runtime.fork(e,t):await this.runtime.fork(e),await this.listProjects(),this.platform);return this.pendingCreations.set(r.id,r),r}async delete(e){await this.runtime.delete(e),this.pendingCreations.delete(e)}async get(e,t){let r;try{r=await this.runtime.get(e,t)}catch(n){let r=this.pendingCreations.get(e);if(!r)throw n;return t?{...r,messages:[],events:[],history:{nextCursor:null,hasMore:!1,pageSize:0,totalItems:0}}:{...r,messages:[],events:[]}}return b(r,await this.listProjects(),this.platform)}async getQueryIndex(e){if(this.runtime.getQueryIndex)return this.runtime.getQueryIndex(e);let t=await this.runtime.get(e),{buildSessionQueryIndex:n}=await Promise.resolve().then(r.bind(r,1322));return n(e,t.messages)}getSessionToolResult(e,t){return this.runtime.getSessionToolResult(e,t)}getSessionWatchPath(e){return this.runtime.getSessionWatchPath(e)}run(e,t,r,n,s){return this.runtime.run(e,t,r,n,s)}steer(e,t){return this.runtime.steer(e,t)}abort(e){return this.runtime.abort(e)}async release(e){if(!this.runtime.release)throw new p.no("Native runtime release is unavailable","RUNTIME_UNAVAILABLE");await this.runtime.release(e)}answerQuestion(e,t){return this.runtime.answerQuestion(e,t)}async startRun(e,t,r,n="web",s){if(!this.runtime.startRun)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.startRun(e,t,r,n,s)}async subscribe(e,t,r){if(!this.runtime.subscribe)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.subscribe(e,t,r)}async snapshot(e,t=0){if(!this.runtime.snapshot)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.snapshot(e,t)}async setPermissionMode(e,t){if(!this.runtime.setPermissionMode)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.setPermissionMode(e,t)}async handoff(e,t){if(!this.runtime.handoff)throw new p.no("Native runtime broker is unavailable","RUNTIME_UNAVAILABLE");return this.runtime.handoff(e,t)}async getGoals(e,t="web"){if(!this.runtime.getGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.getGoals(e,t)}async enqueueGoal(e,t,r,n="web"){if(!this.runtime.enqueueGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueGoal(e,t,r,n)}async reorderGoals(e,t){if(!this.runtime.reorderGoals)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderGoals(e,t)}async cancelGoal(e,t){if(!this.runtime.cancelGoal)throw new p.no("Goal mode is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelGoal(e,t,"web")}async enqueueMessage(e,t,r="web"){if(!this.runtime.enqueueMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.enqueueMessage(e,t,r)}async reorderMessages(e,t){if(!this.runtime.reorderMessages)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.reorderMessages(e,t)}async updateMessage(e,t,r,n){if(!this.runtime.updateMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.updateMessage(e,t,r,n)}async cancelMessage(e,t){if(!this.runtime.cancelMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.cancelMessage(e,t)}async steerMessage(e,t){if(!this.runtime.steerMessage)throw new p.no("Message queue is unavailable","OPERATION_NOT_SUPPORTED");return this.runtime.steerMessage(e,t)}withPendingCreations(e){let t=new Set,r=e.map(e=>{t.add(e.id);let r=this.pendingCreations.get(e.id);return this.pendingCreations.delete(e.id),r?g(e,r):e});return[...[...this.pendingCreations.values()].filter(e=>!t.has(e.id)).sort((e,t)=>t.updated.localeCompare(e.updated)),...r]}}function g(e,t){return{...e,cwd:e.cwd||t.cwd,projectId:e.projectId??t.projectId}}function v(e,t){t.executable?delete process.env[e]:process.env[e]=t.detail}function E(){if(!m.__nativeRuntimeService){!function(){let e=[(0,i.join)((0,s.homedir)(),".local","bin"),"/opt/homebrew/bin","/usr/local/bin"],t=(process.env.PATH??"").split(i.delimiter),r=e.filter(e=>(0,n.existsSync)(e)&&!t.includes(e));r.length>0&&(process.env.PATH=[...t,...r].join(i.delimiter))}();let e=new o.XWE((0,h.kO)());m.__nativeRuntimeService=new f((0,p.v6)({runtimeFactory:e=>{let t=c({name:"codex",environmentVariable:"AGENT_CODEX_BIN",minimumVersion:o.hix}),r=c({name:"opencode",environmentVariable:"AGENT_OPENCODE_BIN"});return process.pid,v("AGENT_CODEX_RUNTIME_ERROR",t),v("AGENT_OPENCODE_RUNTIME_ERROR",r),(0,d.L)().info("native runtime host elected",{pid:process.pid,codex:t.executable??null,codexSource:t.source??null,codexDetail:t.detail,opencode:r.executable??null,opencodeDetail:r.detail}),(0,p.WH)(t.executable??"codex",e,r.executable??"opencode")}}),()=>e.list())}return m.__nativeRuntimeService}function b(e,t,r=process.platform){let{projectId:n,...s}=e;if(!e.cwd)return s;let a=y(e.cwd,r),o="win32"===r?i.win32.sep:i.sep,u=t.filter(e=>e.description).map(e=>({project:e,path:y(e.description,r)})).filter(({path:e})=>a===e||a.startsWith(`${e}${o}`)).sort((e,t)=>t.path.length-e.path.length)[0];return u?{...s,projectId:u.project.id}:s}function y(e,t=process.platform){if("win32"!==t)return(0,i.resolve)(e);let r=i.win32.resolve(e),n=i.win32.parse(r).root;return(r.length>n.length?r.replace(/[\\/]+$/,""):r).toLowerCase()}function w(e,t){return void 0===t?e:e.filter(e=>e.projectId===t)}function T(e){try{return"customer-agent"!==(0,p.Vu)(e).agentType}catch{return!1}}function N(e){if(e instanceof p.no)switch(e.code){case"SESSION_NOT_FOUND":return 404;case"SESSION_OCCUPIED":case"SESSION_ALREADY_RUNNING":case"APPROVAL_EXPIRED":case"CODEX_SESSION_VERSION_INCOMPATIBLE":case"STALE_SESSION_ANCHOR":return 409;case"RUNTIME_UNAVAILABLE":return 503;case"OPERATION_NOT_SUPPORTED":return 405;default:return 400}return 500}},1079:(e,t,r)=>{r.d(t,{j:()=>c});var n=r(7519),s=r(3931),i=r(535),a=r(1322),o=r(1982);let u=!1,l=new a.sSf;function c(){u||(u=!0,n.agentHost.setGlobalEventObserver((e,t,r)=>{try{if("ask_user"===t.type){(0,s.i)().notifySession({notificationId:`${e}:${t.questionId}:approval`,sessionId:e,kind:"approval",title:"需要你的审批",body:"string"==typeof t.question&&t.question.trim()?t.question.trim().slice(0,160):"会话正在等待确认",url:"/app/"});return}if("done"===t.type){if("goal"===r.source)return;let n=(0,a.mDL)((0,o.dp)().read().taskNotifications),i=r.runId?(0,a.DXW)({sessionId:e,runId:r.runId,title:"任务已完成",finalText:t.finalText,outcome:"completed",source:"user"},n):null;i&&l.accept(i.notificationId)&&(0,s.i)().notifySession({...i,url:`/app/?session=${encodeURIComponent(e)}`});return}if("goal_updated"===t.type&&"complete"===t.goal.status){let r=(0,a.mDL)((0,o.dp)().read().taskNotifications),n=(0,a.DXW)({sessionId:e,runId:`goal:${t.goal.createdAt}`,title:"目标已完成",finalText:t.goal.objective,outcome:"completed",source:"goal",goalFinished:!0},r);n&&l.accept(n.notificationId)&&(0,s.i)().notifySession({...n,url:`/app/?session=${encodeURIComponent(e)}`});return}"error"===t.type&&(0,s.i)().notifySession({notificationId:`${e}:${r.runId??"unknown"}:error`,sessionId:e,kind:"error",title:"会话出错",body:"string"==typeof t.message&&t.message.trim()?t.message.trim().slice(0,160):"运行失败",url:"/app/"})}catch(t){(0,i.L)().warn("web push notify failed",{sessionId:e,error:t instanceof Error?t.message:String(t)})}}))}},1489:(e,t,r)=>{r.d(t,{N:()=>u});var n=r(1322),s=r(6279),i=r(785);class a{constructor(){this.tasks=new n.vo4((0,i.kO)()),this.scheduler=new s.ST(this.tasks,e=>{this.fire(e).catch(e=>console.error("Scheduled Customer Agent run failed",e))},()=>{}),this.scheduler.start()}async fire(e){let{agentHost:t}=await r.e(7519).then(r.bind(r,7519)),{getCustomerGoalCoordinator:n}=await Promise.all([r.e(7519),r.e(732)]).then(r.bind(r,732)),s=e.sessionId;s&&await t.getSessionStore().get(s)||(s=(await t.createSession(e.label||"定时任务")).id,this.tasks.update(e.id,{sessionId:s})),await n().enqueue(s,e.prompt)}call(e,t){let r=String(t[0]||"");switch(e){case"cronList":return this.tasks.list();case"cronCreate":{if("string"!=typeof t[0]||"string"!=typeof t[1]||!t[1].trim())throw Error("cron and prompt required");let e=t[2]&&"object"==typeof t[2]?t[2]:{};return this.tasks.create({cron:t[0],prompt:t[1],recurring:!1!==e.recurring,enabled:!0,durable:!0,..."string"==typeof e.sessionId?{sessionId:e.sessionId}:{},..."string"==typeof e.label?{label:e.label}:{}})}case"cronPause":return this.tasks.pause(r);case"cronResume":return this.tasks.resume(r);case"cronDelete":return this.tasks.delete(r);case"cronDeleteAll":return this.tasks.deleteAll(),{ok:!0};default:throw Error("Unsupported schedule operation")}}}let o=globalThis;function u(){return o.__sharedCronService??=new a}},3931:(e,t,r)=>{r.d(t,{i:()=>p});var n=r(6005),s=r(7561),i=r(9411),a=r(5890);let o=require("web-push"),u=e=>JSON.stringify(e??null);class l{constructor(e,t=Date.now){this.now=t;let r=(0,i.resolve)(e,".agentroam-auth");(0,s.mkdirSync)(r,{recursive:!0,mode:448});let n=(0,i.join)(r,"push.sqlite");this.db=new a(n),(0,s.chmodSync)(n,384),this.db.pragma("busy_timeout = 5000"),this.db.exec(`
11
11
  CREATE TABLE IF NOT EXISTS push_keys (id INTEGER PRIMARY KEY CHECK(id=1), public_key TEXT NOT NULL, private_key TEXT NOT NULL);
12
12
  CREATE TABLE IF NOT EXISTS push_subscriptions (
13
13
  endpoint_hash TEXT PRIMARY KEY,
@@ -21,4 +21,4 @@ data: ${JSON.stringify({type:"error",message:e instanceof Error?e.message:"Nativ
21
21
  INSERT INTO push_subscriptions (endpoint_hash, endpoint, p256dh, auth, device_id, created)
22
22
  VALUES (?, ?, ?, ?, ?, ?)
23
23
  ON CONFLICT(endpoint_hash) DO UPDATE SET p256dh=excluded.p256dh, auth=excluded.auth, device_id=excluded.device_id
24
- `).run(c(r),r,n,s,"string"==typeof e?e:null,this.now()),{ok:!0}}deleteSubscription(e){if("string"!=typeof e||!e)throw Object.assign(Error("Endpoint required"),{status:400});return this.db.prepare("DELETE FROM push_subscriptions WHERE endpoint_hash=?").run(c(e)),{ok:!0}}listSubscriptions(){return this.db.prepare("SELECT endpoint, p256dh, auth, device_id FROM push_subscriptions").all().map(e=>({endpoint:e.endpoint,keys:{p256dh:e.p256dh,auth:e.auth},deviceId:e.device_id}))}notifySession({notificationId:e,sessionId:t,title:r,body:n,url:s}){let i=e||`${t}:notification`;if(!this.delivered.has(i)){for(this.delivered.add(i);this.delivered.size>500;)this.delivered.delete(this.delivered.values().next().value);this.sendToAll({notificationId:i,sessionId:t,title:r,body:n,tag:i,url:s})}}async sendToAll(e){let t=this.listSubscriptions();await Promise.allSettled(t.map(t=>this.send(t,e)))}async send(e,t){try{o.setVapidDetails("mailto:agentroam@localhost",this.keys.publicKey,this.keys.privateKey),await o.sendNotification(e,u(t),{TTL:3600})}catch(r){let t=r?.statusCode;(404===t||410===t)&&this.db.prepare("DELETE FROM push_subscriptions WHERE endpoint_hash=?").run(c(e.endpoint))}}close(){this.db.close()}}function c(e){return(0,n.createHash)("sha256").update(e).digest("hex")}let d=null;function p(e=process.env.AGENT_DATA_DIR?.trim()||process.cwd()){return d??=new l(e)}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),n=t.X(0,[8375,6244,1322,1773,4621,7519],()=>r(95));module.exports=n})();
24
+ `).run(c(r),r,n,s,"string"==typeof e?e:null,this.now()),{ok:!0}}deleteSubscription(e){if("string"!=typeof e||!e)throw Object.assign(Error("Endpoint required"),{status:400});return this.db.prepare("DELETE FROM push_subscriptions WHERE endpoint_hash=?").run(c(e)),{ok:!0}}listSubscriptions(){return this.db.prepare("SELECT endpoint, p256dh, auth, device_id FROM push_subscriptions").all().map(e=>({endpoint:e.endpoint,keys:{p256dh:e.p256dh,auth:e.auth},deviceId:e.device_id}))}notifySession({notificationId:e,sessionId:t,title:r,body:n,url:s}){let i=e||`${t}:notification`;if(!this.delivered.has(i)){for(this.delivered.add(i);this.delivered.size>500;)this.delivered.delete(this.delivered.values().next().value);this.sendToAll({notificationId:i,sessionId:t,title:r,body:n,tag:i,url:s})}}async sendToAll(e){let t=this.listSubscriptions();await Promise.allSettled(t.map(t=>this.send(t,e)))}async send(e,t){try{o.setVapidDetails("mailto:agentroam@localhost",this.keys.publicKey,this.keys.privateKey),await o.sendNotification(e,u(t),{TTL:3600})}catch(r){let t=r?.statusCode;(404===t||410===t)&&this.db.prepare("DELETE FROM push_subscriptions WHERE endpoint_hash=?").run(c(e.endpoint))}}close(){this.db.close()}}function c(e){return(0,n.createHash)("sha256").update(e).digest("hex")}let d=null;function p(e=process.env.AGENT_DATA_DIR?.trim()||process.cwd()){return d??=new l(e)}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),n=t.X(0,[8375,6244,1322,1773,4621,7519],()=>r(9432));module.exports=n})();
@@ -1 +1 @@
1
- "use strict";(()=>{var e={};e.id=4612,e.ids=[4612],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},8131:(e,r,s)=>{s.r(r),s.d(r,{originalPathname:()=>k,patchFetch:()=>h,requestAsyncStorage:()=>x,routeModule:()=>m,serverHooks:()=>w,staticGenerationAsyncStorage:()=>q});var t={};s.r(t),s.d(t,{GET:()=>g});var o=s(7786),a=s(5042),n=s(2184),i=s(1890),p=s(1322),u=s(6279),d=s(7519),c=s(1614),l=s(6405);async function g(e,r){let s;let t=new URL(e.url),o=(0,l.ql)(t.searchParams.get("agentType"));if(!o)return i.NextResponse.json({error:"A valid agentType is required"},{status:400});try{let e=(0,l.MT)(t);s={cursor:e.cursor,limit:e.limit,refresh:e.refresh}}catch(e){return i.NextResponse.json({error:e instanceof Error?e.message:"Invalid query"},{status:400})}try{let e;if("customer-agent"!==o)return i.NextResponse.json(await (0,c.NL)().listWorkspaceSessions(o,r.params.workspaceId,s));let t="",a=null;if(r.params.workspaceId===l.rK){let[r,s]=await Promise.all([d.agentHost.getProjectStore().list(),d.agentHost.getSessionStore().list()]),t=new Set(r.filter(e=>e.description.trim().length>0).map(e=>e.id));e=s.filter(e=>!t.has(e.projectId))}else{let s=await d.agentHost.getProjectStore().get(r.params.workspaceId);if(!s)return i.NextResponse.json({error:"Workspace not found"},{status:404});if(!s.description.trim())return i.NextResponse.json({error:"该项目没有宿主机目录",code:"PROJECT_PATH_REQUIRED"},{status:400});t=s.description,a=s.updated,e=await d.agentHost.getSessionStore().list(s.id)}let n=e.map(({messages:e,events:s,...o})=>({...o,projectId:r.params.workspaceId,agentType:"customer-agent",nativeSessionId:o.id,cwd:t,occupancy:d.agentHost.isSessionRunning(o.id)?"owned-by-customer-agent":"available",sourceLabel:"Customer Agent",canResume:!0,canDelete:!d.agentHost.isSessionRunning(o.id),permissionMode:(0,p.NyU)(o.metadata.permissionMode)})).sort((e,r)=>r.updated.localeCompare(e.updated));return i.NextResponse.json((0,u.L)(n,s,n[0]?.updated??a))}catch(e){return i.NextResponse.json({error:e instanceof Error?e.message:"Workspace sessions failed"},{status:(0,c.WW)(e)})}}let m=new o.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/agent-workspaces/[workspaceId]/sessions/route",pathname:"/api/agent-workspaces/[workspaceId]/sessions",filename:"route",bundlePath:"app/api/agent-workspaces/[workspaceId]/sessions/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-37/customer-agent/packages/server/app/api/agent-workspaces/[workspaceId]/sessions/route.ts",nextConfigOutput:"standalone",userland:t}),{requestAsyncStorage:x,staticGenerationAsyncStorage:q,serverHooks:w}=m,k="/api/agent-workspaces/[workspaceId]/sessions/route";function h(){return(0,n.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:q})}}};var r=require("../../../../../webpack-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[8375,6703,6244,1322,1773,4621,7519,2293],()=>s(8131));module.exports=t})();
1
+ "use strict";(()=>{var e={};e.id=4612,e.ids=[4612],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},8194:(e,r,s)=>{s.r(r),s.d(r,{originalPathname:()=>k,patchFetch:()=>h,requestAsyncStorage:()=>x,routeModule:()=>m,serverHooks:()=>w,staticGenerationAsyncStorage:()=>q});var t={};s.r(t),s.d(t,{GET:()=>g});var o=s(7786),a=s(5042),n=s(2184),i=s(1890),p=s(1322),u=s(6279),d=s(7519),c=s(1614),l=s(6405);async function g(e,r){let s;let t=new URL(e.url),o=(0,l.ql)(t.searchParams.get("agentType"));if(!o)return i.NextResponse.json({error:"A valid agentType is required"},{status:400});try{let e=(0,l.MT)(t);s={cursor:e.cursor,limit:e.limit,refresh:e.refresh}}catch(e){return i.NextResponse.json({error:e instanceof Error?e.message:"Invalid query"},{status:400})}try{let e;if("customer-agent"!==o)return i.NextResponse.json(await (0,c.NL)().listWorkspaceSessions(o,r.params.workspaceId,s));let t="",a=null;if(r.params.workspaceId===l.rK){let[r,s]=await Promise.all([d.agentHost.getProjectStore().list(),d.agentHost.getSessionStore().list()]),t=new Set(r.filter(e=>e.description.trim().length>0).map(e=>e.id));e=s.filter(e=>!t.has(e.projectId))}else{let s=await d.agentHost.getProjectStore().get(r.params.workspaceId);if(!s)return i.NextResponse.json({error:"Workspace not found"},{status:404});if(!s.description.trim())return i.NextResponse.json({error:"该项目没有宿主机目录",code:"PROJECT_PATH_REQUIRED"},{status:400});t=s.description,a=s.updated,e=await d.agentHost.getSessionStore().list(s.id)}let n=e.map(({messages:e,events:s,...o})=>({...o,projectId:r.params.workspaceId,agentType:"customer-agent",nativeSessionId:o.id,cwd:t,occupancy:d.agentHost.isSessionRunning(o.id)?"owned-by-customer-agent":"available",sourceLabel:"Customer Agent",canResume:!0,canDelete:!d.agentHost.isSessionRunning(o.id),permissionMode:(0,p.NyU)(o.metadata.permissionMode)})).sort((e,r)=>r.updated.localeCompare(e.updated));return i.NextResponse.json((0,u.L)(n,s,n[0]?.updated??a))}catch(e){return i.NextResponse.json({error:e instanceof Error?e.message:"Workspace sessions failed"},{status:(0,c.WW)(e)})}}let m=new o.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/agent-workspaces/[workspaceId]/sessions/route",pathname:"/api/agent-workspaces/[workspaceId]/sessions",filename:"route",bundlePath:"app/api/agent-workspaces/[workspaceId]/sessions/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-39/customer-agent/packages/server/app/api/agent-workspaces/[workspaceId]/sessions/route.ts",nextConfigOutput:"standalone",userland:t}),{requestAsyncStorage:x,staticGenerationAsyncStorage:q,serverHooks:w}=m,k="/api/agent-workspaces/[workspaceId]/sessions/route";function h(){return(0,n.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:q})}}};var r=require("../../../../../webpack-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[8375,6703,6244,1322,1773,4621,7519,2293],()=>s(8194));module.exports=t})();
@@ -1 +1 @@
1
- "use strict";(()=>{var e={};e.id=8593,e.ids=[8593],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},6010:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>y,patchFetch:()=>f,requestAsyncStorage:()=>g,routeModule:()=>x,serverHooks:()=>w,staticGenerationAsyncStorage:()=>q});var s={};t.r(s),t.d(s,{GET:()=>h,POST:()=>m});var o=t(7786),a=t(5042),n=t(2184),i=t(1890),p=t(6279),u=t(7519),c=t(1614),d=t(556),l=t(6405);async function h(e){let r;let t=new URL(e.url),s=(0,l.ql)(t.searchParams.get("agentType"));if(!s)return i.NextResponse.json({error:"A valid agentType is required"},{status:400});try{r=(0,l.MT)(t)}catch(e){return i.NextResponse.json({error:e instanceof Error?e.message:"Invalid query"},{status:400})}try{if("customer-agent"!==s)return i.NextResponse.json(await (0,c.NL)().listWorkspaces(s,r));let e=(await u.agentHost.getProjectStore().list()).filter(e=>e.description.trim().length>0),t=[{agentType:s,workspaceId:l.rK,name:"最近",roots:[],order:-1,source:"derived",canCreateSession:!1},...e.map((e,r)=>({agentType:s,workspaceId:e.id,name:e.name,roots:e.description?[e.description]:[],order:r,updatedAt:e.updated,source:"native"}))];return i.NextResponse.json((0,p.L)(t,r,e[0]?.updated??null))}catch(e){return i.NextResponse.json({error:e instanceof Error?e.message:"Workspace discovery failed"},{status:(0,c.WW)(e)})}}async function m(e){let r;try{r=await e.json()}catch{return i.NextResponse.json({error:"A JSON body is required"},{status:400})}let t=(0,l.ql)(r.agentType??null);if(!t||!r.path?.trim())return i.NextResponse.json({error:"A valid agentType and path are required"},{status:400});try{let e=d.a.canonicalDirectory(r.path);if("customer-agent"!==t)return i.NextResponse.json(await (0,c.NL)().importWorkspace(t,e,r.name),{status:201});let s=await d.a.list(),o=await d.a.create(e,r.name);return i.NextResponse.json({workspace:{agentType:t,workspaceId:o.id,name:o.name,roots:o.description?[o.description]:[],order:Math.max(0,s.findIndex(e=>e.id===o.id)),updatedAt:o.updated,source:"native"},existing:s.some(e=>e.id===o.id)},{status:201})}catch(r){let e=(0,d.r)(r);if(500!==e.status)return i.NextResponse.json(e.body,{status:e.status});return i.NextResponse.json({error:r instanceof Error?r.message:"Workspace import failed"},{status:(0,c.WW)(r)})}}let x=new o.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/agent-workspaces/route",pathname:"/api/agent-workspaces",filename:"route",bundlePath:"app/api/agent-workspaces/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-37/customer-agent/packages/server/app/api/agent-workspaces/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:g,staticGenerationAsyncStorage:q,serverHooks:w}=x,y="/api/agent-workspaces/route";function f(){return(0,n.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:q})}},556:(e,r,t)=>{t.d(r,{r:()=>d,a:()=>c});var s=t(612),o=t(1322),a=t(785),n=t(6005),i=t(9411);class p extends Error{constructor(e,r,t){super(e),this.code=r,this.status=t,this.name="WebProjectError"}}class u{constructor(e,r){this.store=e,this.paths=r}list(){return this.store.list()}async get(e){let r=await this.store.get(e);if(!r)throw new p("项目不存在","PROJECT_NOT_FOUND",404);return r}async create(e,r){let t=this.paths.assertDirectory(e);for(let e of(await this.store.list()))try{if(this.paths.assertDirectory(e.description)===t)return e}catch{}let s=new Date().toISOString();return this.store.create({id:(0,n.randomUUID)(),name:r?.trim()||(0,i.basename)(t)||t,description:t,created:s,updated:s})}async rename(e,r){await this.get(e);let t=r.trim();if(!t)throw new p("项目名称不能为空","PROJECT_NAME_REQUIRED",400);return this.store.update(e,{name:t})}async delete(e){await this.get(e),await this.store.delete(e)}roots(){return this.paths.roots}directories(e){return this.paths.listDirectories(e)}check(e){try{return this.paths.assertDirectory(e),!0}catch{return!1}}canonicalDirectory(e){return this.paths.assertDirectory(e)}}let c=new u(new o.XWE((0,a.kO)()),o.Tpv.fromEnvironment(process.env.AGENT_WEB_ROOTS,(0,s.homedir)()));function d(e){return e instanceof p?{status:e.status,body:{error:e.message,code:e.code}}:e instanceof o.TLe?{status:400,body:{error:e.message,code:e.code}}:{status:500,body:{error:e instanceof Error?e.message:"项目操作失败",code:"PROJECT_OPERATION_FAILED"}}}}};var r=require("../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[8375,6703,6244,1322,1773,4621,7519,2293],()=>t(6010));module.exports=s})();
1
+ "use strict";(()=>{var e={};e.id=8593,e.ids=[8593],e.modules={7728:e=>{e.exports=require("@anthropic-ai/claude-agent-sdk")},5890:e=>{e.exports=require("better-sqlite3")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},1282:e=>{e.exports=require("child_process")},2048:e=>{e.exports=require("fs")},9801:e=>{e.exports=require("os")},5315:e=>{e.exports=require("path")},7718:e=>{e.exports=require("node:child_process")},6005:e=>{e.exports=require("node:crypto")},5673:e=>{e.exports=require("node:events")},7561:e=>{e.exports=require("node:fs")},3977:e=>{e.exports=require("node:fs/promises")},8849:e=>{e.exports=require("node:http")},2286:e=>{e.exports=require("node:https")},2033:e=>{e.exports=require("node:module")},7503:e=>{e.exports=require("node:net")},612:e=>{e.exports=require("node:os")},9411:e=>{e.exports=require("node:path")},1747:e=>{e.exports=require("node:readline")},4492:e=>{e.exports=require("node:stream")},6915:e=>{e.exports=require("node:string_decoder")},1041:e=>{e.exports=require("node:url")},5881:e=>{e.exports=require("node:util")},6345:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>y,patchFetch:()=>f,requestAsyncStorage:()=>g,routeModule:()=>x,serverHooks:()=>w,staticGenerationAsyncStorage:()=>q});var s={};t.r(s),t.d(s,{GET:()=>h,POST:()=>m});var o=t(7786),a=t(5042),n=t(2184),i=t(1890),p=t(6279),u=t(7519),c=t(1614),d=t(556),l=t(6405);async function h(e){let r;let t=new URL(e.url),s=(0,l.ql)(t.searchParams.get("agentType"));if(!s)return i.NextResponse.json({error:"A valid agentType is required"},{status:400});try{r=(0,l.MT)(t)}catch(e){return i.NextResponse.json({error:e instanceof Error?e.message:"Invalid query"},{status:400})}try{if("customer-agent"!==s)return i.NextResponse.json(await (0,c.NL)().listWorkspaces(s,r));let e=(await u.agentHost.getProjectStore().list()).filter(e=>e.description.trim().length>0),t=[{agentType:s,workspaceId:l.rK,name:"最近",roots:[],order:-1,source:"derived",canCreateSession:!1},...e.map((e,r)=>({agentType:s,workspaceId:e.id,name:e.name,roots:e.description?[e.description]:[],order:r,updatedAt:e.updated,source:"native"}))];return i.NextResponse.json((0,p.L)(t,r,e[0]?.updated??null))}catch(e){return i.NextResponse.json({error:e instanceof Error?e.message:"Workspace discovery failed"},{status:(0,c.WW)(e)})}}async function m(e){let r;try{r=await e.json()}catch{return i.NextResponse.json({error:"A JSON body is required"},{status:400})}let t=(0,l.ql)(r.agentType??null);if(!t||!r.path?.trim())return i.NextResponse.json({error:"A valid agentType and path are required"},{status:400});try{let e=d.a.canonicalDirectory(r.path);if("customer-agent"!==t)return i.NextResponse.json(await (0,c.NL)().importWorkspace(t,e,r.name),{status:201});let s=await d.a.list(),o=await d.a.create(e,r.name);return i.NextResponse.json({workspace:{agentType:t,workspaceId:o.id,name:o.name,roots:o.description?[o.description]:[],order:Math.max(0,s.findIndex(e=>e.id===o.id)),updatedAt:o.updated,source:"native"},existing:s.some(e=>e.id===o.id)},{status:201})}catch(r){let e=(0,d.r)(r);if(500!==e.status)return i.NextResponse.json(e.body,{status:e.status});return i.NextResponse.json({error:r instanceof Error?r.message:"Workspace import failed"},{status:(0,c.WW)(r)})}}let x=new o.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/agent-workspaces/route",pathname:"/api/agent-workspaces",filename:"route",bundlePath:"app/api/agent-workspaces/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-39/customer-agent/packages/server/app/api/agent-workspaces/route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:g,staticGenerationAsyncStorage:q,serverHooks:w}=x,y="/api/agent-workspaces/route";function f(){return(0,n.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:q})}},556:(e,r,t)=>{t.d(r,{r:()=>d,a:()=>c});var s=t(612),o=t(1322),a=t(785),n=t(6005),i=t(9411);class p extends Error{constructor(e,r,t){super(e),this.code=r,this.status=t,this.name="WebProjectError"}}class u{constructor(e,r){this.store=e,this.paths=r}list(){return this.store.list()}async get(e){let r=await this.store.get(e);if(!r)throw new p("项目不存在","PROJECT_NOT_FOUND",404);return r}async create(e,r){let t=this.paths.assertDirectory(e);for(let e of(await this.store.list()))try{if(this.paths.assertDirectory(e.description)===t)return e}catch{}let s=new Date().toISOString();return this.store.create({id:(0,n.randomUUID)(),name:r?.trim()||(0,i.basename)(t)||t,description:t,created:s,updated:s})}async rename(e,r){await this.get(e);let t=r.trim();if(!t)throw new p("项目名称不能为空","PROJECT_NAME_REQUIRED",400);return this.store.update(e,{name:t})}async delete(e){await this.get(e),await this.store.delete(e)}roots(){return this.paths.roots}directories(e){return this.paths.listDirectories(e)}check(e){try{return this.paths.assertDirectory(e),!0}catch{return!1}}canonicalDirectory(e){return this.paths.assertDirectory(e)}}let c=new u(new o.XWE((0,a.kO)()),o.Tpv.fromEnvironment(process.env.AGENT_WEB_ROOTS,(0,s.homedir)()));function d(e){return e instanceof p?{status:e.status,body:{error:e.message,code:e.code}}:e instanceof o.TLe?{status:400,body:{error:e.message,code:e.code}}:{status:500,body:{error:e instanceof Error?e.message:"项目操作失败",code:"PROJECT_OPERATION_FAILED"}}}}};var r=require("../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[8375,6703,6244,1322,1773,4621,7519,2293],()=>t(6345));module.exports=s})();
@@ -1 +1 @@
1
- "use strict";(()=>{var e={};e.id=571,e.ids=[571],e.modules={399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},5242:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>l,patchFetch:()=>h,requestAsyncStorage:()=>d,routeModule:()=>p,serverHooks:()=>v,staticGenerationAsyncStorage:()=>c});var a={};r.r(a),r.d(a,{GET:()=>u});var o=r(7786),s=r(5042),n=r(2184),i=r(1890);async function u(e){let t=e.headers.get("Authorization"),r=t?.replace("Bearer ",""),a=new URL(e.url).searchParams.get("token"),o=process.env.AGENT_SDK_TOKEN;return o?(r||a)===o?i.NextResponse.json({valid:!0,project:"default"}):i.NextResponse.json({valid:!1},{status:401}):i.NextResponse.json({valid:!0,project:"dev"})}let p=new o.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/auth/verify/route",pathname:"/api/auth/verify",filename:"route",bundlePath:"app/api/auth/verify/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-37/customer-agent/packages/server/app/api/auth/verify/route.ts",nextConfigOutput:"standalone",userland:a}),{requestAsyncStorage:d,staticGenerationAsyncStorage:c,serverHooks:v}=p,l="/api/auth/verify/route";function h(){return(0,n.patchFetch)({serverHooks:v,staticGenerationAsyncStorage:c})}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[8375,6703],()=>r(5242));module.exports=a})();
1
+ "use strict";(()=>{var e={};e.id=571,e.ids=[571],e.modules={399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},6717:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>l,patchFetch:()=>h,requestAsyncStorage:()=>d,routeModule:()=>p,serverHooks:()=>v,staticGenerationAsyncStorage:()=>c});var a={};r.r(a),r.d(a,{GET:()=>u});var o=r(7786),s=r(5042),n=r(2184),i=r(1890);async function u(e){let t=e.headers.get("Authorization"),r=t?.replace("Bearer ",""),a=new URL(e.url).searchParams.get("token"),o=process.env.AGENT_SDK_TOKEN;return o?(r||a)===o?i.NextResponse.json({valid:!0,project:"default"}):i.NextResponse.json({valid:!1},{status:401}):i.NextResponse.json({valid:!0,project:"dev"})}let p=new o.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/auth/verify/route",pathname:"/api/auth/verify",filename:"route",bundlePath:"app/api/auth/verify/route"},resolvedPagePath:"/Users/caoqu/.codex/worktrees/npm-preview-39/customer-agent/packages/server/app/api/auth/verify/route.ts",nextConfigOutput:"standalone",userland:a}),{requestAsyncStorage:d,staticGenerationAsyncStorage:c,serverHooks:v}=p,l="/api/auth/verify/route";function h(){return(0,n.patchFetch)({serverHooks:v,staticGenerationAsyncStorage:c})}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[8375,6703],()=>r(6717));module.exports=a})();